imagetree.h

00001 /*--License:
00002         Kyra Sprite Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2005
00004         www.grinninglizard.com/kyra
00005         www.sourceforge.net/projects/kyra
00006 
00007         Kyra is provided under the LGPL. 
00008         
00009         I kindly request you display a splash screen (provided in the HTML documentation)
00010         to promote Kyra and acknowledge the software and everyone who has contributed to it, 
00011         but it is not required by the license.
00012 
00013 --- LGPL License --
00014 
00015     This library is free software; you can redistribute it and/or
00016     modify it under the terms of the GNU Lesser General Public
00017     License as published by the Free Software Foundation; either
00018     version 2.1 of the License, or (at your option) any later version.
00019 
00020     This library is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00023     Lesser General Public License for more details.
00024 
00025     You should have received a copy of the GNU Lesser General Public
00026     License along with this library; if not, write to the Free Software
00027     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 
00029         The full text of the license can be found in lgpl.txt
00030 */
00031 
00032 
00033 #ifndef KYRA_RENDER_INCLUDED
00034 #define KYRA_RENDER_INCLUDED
00035 
00036 #ifdef _MSC_VER
00037 // Disable the no-exception handling warning.
00038 #pragma warning( disable : 4530 )
00039 #pragma warning( disable : 4786 )
00040 #endif
00041 
00042 #include "../util/gllist.h"
00043 #include "SDL.h"
00044 #include "../engine/krmath.h"
00045 //#include "../util/glmap.h"
00046 
00047 // Include the other image headers, so clients just need
00048 // to #include "image.h"
00049 
00050 #include "sprite.h"
00051 
00052 class KrEngine;
00053 class KrMappedRect;
00054 
00055 
00058 class KrImageTree
00059 {
00060   public:
00061         /*  The tree has to live in an engine in order
00062                 to get to dirty rectangles and StartLists.
00063         */
00064         KrImageTree( KrEngine* engine );
00065         ~KrImageTree();
00066 
00068         KrImNode* Root()        { return offsetRoot; }
00069 
00080         void    AddNode( KrImNode* parent, KrImNode* addMe );
00081         
00090         bool    DeleteNode( KrImNode* removeMe );
00091 
00093         KrImNode*       FindNodeById( int id );
00095         KrImNode*       FindNodeByName( const std::string& name );
00096 
00111         void   HitTest( int x, int y, KrImNode* startHere,
00112                                         int flags,
00113                                         std::vector<KrImage*>* outputArray,
00114                                         int *windowIndex );
00115 
00122         bool CheckSiblingCollision( KrImNode* checkThis,
00123                                                                 std::vector<KrImage*>* outputArray, int window = 0 );
00124 
00135         bool CheckChildCollision( KrImNode* checkThis, KrImNode* parent,
00136                                                           std::vector<KrImage*>* outputArray, int window = 0 );
00137 
00144         bool CheckAllCollision( KrImNode* checkThis, std::vector<KrImage*>* outputArray, int window = 0 );
00145         
00146         enum 
00147         {
00149                 ALWAYS_INSIDE_BOX                       = 0x01,
00151                 GET_ALL_HITS                            = 0x04,
00152         };
00153 
00155         void Walk();
00156 
00157         void DrawWalk( const grinliz::Rectangle2I& dr, KrPaintInfo* info, int window );
00158 
00159         // The tree maintains a look up table to the objects in it.
00160         // These methods are called by the KrImNodes.
00161         void AddNodeNameHash( const std::string& name, KrImNode* node );
00162         void RemoveNodeNameHash( const std::string& name );
00163         void RemoveNodeIdHash( int id );
00164         void AddNodeIdHash( int id, KrImNode* node );
00165 
00166         #ifdef DEBUG
00167         void ValidateTree( KrImNode* root );
00168         #endif
00169 
00170   private:
00171         // Used to unroll recursion.
00172         struct StackContext
00173         {
00174                 KrImNode*                               node;
00175                 bool                                    invalid;
00176                 //GlInsideNode<KrImNode>*       childNode;
00177         };
00178         
00179         void CheckAllCollisionWalk( bool* hit, KrImNode* parent, KrImage* checkThis, std::vector<KrImage*>* outputArray, int window );
00180 
00181         // Before a draw, walk the tree and do necessary pre-processing.
00182         void Walk(      KrImNode* node, 
00183                                 bool invalid,   // once something in the tree is invalid, all of its children are invalid.
00184                                 bool visible,   // once something is invisible, all children are invisible
00185                                 int window );
00186 
00187         // Walk and call the draw routines.
00188         void DrawWalk( const grinliz::Rectangle2I& dr, KrImNode* node, KrPaintInfo*, int window );
00189 
00190         void Clear( KrImNode* root );   // delete the entire tree
00191 
00192         // Recursive hit test walk.
00193         bool KrImageTree::HitTestRec( KrImNode* node, int x, int y, int flags, std::vector<KrImage*>* outputArray, int windowIndex );
00194 
00195         KrImNode*  root;                        // The root to position the window
00196         KrImNode*  offsetRoot;          // The root as returned to the client
00197         KrEngine*  engine;
00198 
00199         std::map< U32, KrImNode* >                      idMap;
00200         std::map< std::string, KrImNode* >      nameMap;
00201 
00202         int treeDepth;                          // a z-depth used for opengl drawing
00203 };
00204 
00205 
00206 #endif

Generated on Thu Jul 20 20:45:32 2006 for Kyra by  doxygen 1.4.7