00001 /*--License: 00002 Kyra Sprite Engine 00003 Copyright Lee Thomason (Grinning Lizard Software) 2001-2002 00004 www.grinninglizard.com/kyra 00005 www.sourceforge.net/projects/kyra 00006 00007 Kyra is provided under 2 licenses: 00008 00009 - The GPL, with no additional restrictions. 00010 - The LGPL, provided you display the Kyra splash screen, described below. 00011 00012 00013 --- GPL License -- 00014 This program is free software; you can redistribute it and/or 00015 modify it under the terms of the GNU General Public License 00016 as published by the Free Software Foundation; either version 2 00017 of the License, or (at your option) any later version. 00018 00019 This program is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License 00025 along with this program; if not, write to the Free Software 00026 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00027 00028 The full text of the license can be found in license.txt 00029 00030 00031 --- LGPL License -- 00032 **Provided you kindly display the Kyra splash screen (details below), 00033 you may use the LGPL license:** 00034 00035 This library is free software; you can redistribute it and/or 00036 modify it under the terms of the GNU Lesser General Public 00037 License as published by the Free Software Foundation; either 00038 version 2.1 of the License, or (at your option) any later version. 00039 00040 This library is distributed in the hope that it will be useful, 00041 but WITHOUT ANY WARRANTY; without even the implied warranty of 00042 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00043 Lesser General Public License for more details. 00044 00045 You should have received a copy of the GNU Lesser General Public 00046 License along with this library; if not, write to the Free Software 00047 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00048 00049 The full text of the license can be found in lgpl.txt 00050 00051 00052 --- Kyra Splash Screen. 00053 00054 It would be appreciate if you display the Kyra splash screen when using 00055 either license, however it is only required for the LGPL. All the 00056 resources for the splash are compiled into the library, and it can be 00057 accessed through the following API: 00058 00059 KrEngine::StartSplash 00060 KrEngine::UpdateSplash 00061 KrEngine::EndSplash 00062 00063 Full documentation is provided with the KrEngine class. The splash screen 00064 should be displayed for 2 seconds. 00065 00066 Thank you. 00067 */ 00068 00069 00070 #ifndef KYRA_RENDER_INCLUDED 00071 #define KYRA_RENDER_INCLUDED 00072 00073 #include "../util/gllist.h" 00074 #include "SDL.h" 00075 #include "../engine/krmath.h" 00076 #include "../util/glmap.h" 00077 00078 // Include the other image headers, so clients just need 00079 // to #include "image.h" 00080 00081 #include "sprite.h" 00082 00083 class KrEngine; 00084 class KrMappedRect; 00085 00086 00089 class KrImageTree 00090 { 00091 public: 00092 /* The tree has to live in an engine in order 00093 to get to dirty rectangles and StartLists. 00094 */ 00095 KrImageTree( KrEngine* engine ); 00096 ~KrImageTree(); 00097 00099 KrImNode* Root() { return offsetRoot; } 00100 00111 void AddNode( KrImNode* parent, KrImNode* addMe ); 00112 00121 bool DeleteNode( KrImNode* removeMe ); 00122 00124 KrImNode* FindNodeById( int id ); 00126 KrImNode* FindNodeByName( const std::string& name ); 00127 00139 void HitTest( int x, int y, int flags, 00140 GlDynArray<KrImage*>* outputArray, 00141 int *windowIndex ); 00142 00149 bool CheckSiblingCollision( KrImNode* checkThis, 00150 GlDynArray<KrImage*>* outputArray, int window = 0 ); 00151 00162 bool CheckChildCollision( KrImNode* checkThis, KrImNode* parent, 00163 GlDynArray<KrImage*>* outputArray, int window = 0 ); 00164 00171 bool CheckAllCollision( KrImNode* checkThis, GlDynArray<KrImage*>* outputArray, int window = 0 ); 00172 00173 enum 00174 { 00176 ALWAYS_INSIDE_BOX = 0x01, 00178 GET_ALL_HITS = 0x04, 00179 }; 00180 00182 void Walk(); 00183 00184 void DrawWalk( const KrRect& dr, KrPaintInfo* info, int window ); 00185 00186 // The tree maintains a look up table to the objects in it. 00187 // These methods are called by the KrImNodes. 00188 void AddNodeNameHash( const std::string& name, KrImNode* node ); 00189 void RemoveNodeNameHash( const std::string& name ); 00190 void RemoveNodeIdHash( int id ); 00191 void AddNodeIdHash( int id, KrImNode* node ); 00192 00193 #ifdef DEBUG 00194 void ValidateTree( KrImNode* root ); 00195 #endif 00196 00197 private: 00198 // Used to unroll recursion. 00199 struct StackContext 00200 { 00201 KrImNode* node; 00202 bool invalid; 00203 //GlInsideNode<KrImNode>* childNode; 00204 }; 00205 00206 void CheckAllCollisionWalk( bool* hit, KrImNode* parent, KrImage* checkThis, GlDynArray<KrImage*>* outputArray, int window ); 00207 00208 // Before a draw, walk the tree and do necessary pre-processing. 00209 void Walk( KrImNode* node, 00210 bool invalid, // once something in the tree is invalid, all of its children are invalid. 00211 bool visible, // once something is invisible, all children are invisible 00212 int window ); 00213 00214 // Walk and call the draw routines. 00215 void DrawWalk( const KrRect& dr, KrImNode* node, KrPaintInfo*, int window ); 00216 00217 void Clear( KrImNode* root ); // delete the entire tree 00218 00219 // Recursive hit test walk. 00220 bool KrImageTree::HitTestRec( KrImNode* node, int x, int y, int flags, GlDynArray<KrImage*>* outputArray, int windowIndex ); 00221 00222 KrImNode* root; // The root to position the window 00223 KrImNode* offsetRoot; // The root as returned to the client 00224 KrEngine* engine; 00225 00226 GlMap< U32, KrImNode*, GlNumberHash<U32> > idMap; 00227 GlMap< std::string, KrImNode*, GlStringHash > nameMap; 00228 00229 int treeDepth; // a z-depth used for opengl drawing 00230 }; 00231 00232 00233 #endif