imnode.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 #ifndef KYRA_IMAGE_NODE_INCLUDED
00033 #define KYRA_IMAGE_NODE_INCLUDED
00034 
00035 #include "../util/glinsidelist.h"
00036 #include "SDL.h"
00037 #include "krmath.h"
00038 #include "color.h"
00039 #include "kyrabuild.h"
00040 #include "../../grinliz/glgeometry.h"
00041 
00042 #ifdef _MSC_VER
00043 // Disable the no-exception handling warning.
00044 #pragma warning( disable : 4530 )
00045 #pragma warning( disable : 4786 )
00046 #endif
00047 
00048 #include <string>
00049 #include <vector>
00050 
00051 
00052 class KrEngine;
00053 class KrImage;
00054 class KrSprite;
00055 class KrTile;
00056 class KrCanvas;
00057 class KrTextBox;
00058 class KrBox;
00059 class KrWidget;
00060 
00061 
00062 const int KR_ALL_WINDOWS = -1;
00063 
00071 class KrImNode
00072 {
00073         friend class KrImageTree;
00074 
00075   public:
00076         // The nodes:
00077         // Not really methods, not really data members. Here
00078         // but not to be used.
00079         GlInsideNode<KrImNode*> treeNode;       // We are in someone else's child list.
00080 
00081   public:
00082         KrImNode();
00083         virtual ~KrImNode()                             {}
00084 
00097         int  ZDepth()                                   { return depth; }
00098 
00100         void SetZDepth( int z );
00101 
00103         int X( int window=0 )                   {       GLASSERT( ( xTransform[window].x.v & 0xffff ) == 0 );
00104                                                                                 return xTransform[window].x.ToInt(); }
00106         int Y( int window=0 )                   {       GLASSERT( ( xTransform[window].y.v & 0xffff ) == 0 );
00107                                                                                 return xTransform[window].y.ToInt(); }
00108 
00110         GlFixed XScale( int window=0 )                          { return xTransform[window].xScale; }
00112         GlFixed YScale( int window=0 )                          { return xTransform[window].yScale; }
00113 
00115         const KrMatrix2& Transform( int window=0 )      { return xTransform[window]; }
00116 
00125         void SetPos( int x, int y, int window=KR_ALL_WINDOWS );
00126 
00128         void SetScale( GlFixed xScale, GlFixed yScale, int window=KR_ALL_WINDOWS );
00129 
00131         void SetTransform( KrMatrix2& xForm, int window=KR_ALL_WINDOWS );
00132 
00139         void SetQuality( int quality, int window=KR_ALL_WINDOWS );
00140 
00142         void DeltaPos( int deltaX, int deltaY, int window=KR_ALL_WINDOWS )              { SetPos( X() + deltaX, Y() + deltaY, window ); }
00143 
00146         const KrColorTransform& CTransform( int window=0 )                      { return cTransform[window]; }
00147 
00151         virtual void SetColor( const KrColorTransform& color, int window=KR_ALL_WINDOWS );
00152 
00153         virtual KrImage*  ToImage()             { return 0; }   
00154         virtual KrSprite* ToSprite()    { return 0; }   
00155         virtual KrTile*   ToTile()              { return 0; }   
00156         virtual KrCanvas* ToCanvas()    { return 0; }   
00157         virtual KrTextBox*ToTextBox()   { return 0; }   
00158         virtual KrBox*    ToBox()               { return 0; }   
00159         virtual KrWidget* ToWidget()    { return 0; }   
00160 
00170         virtual KrImNode* ToExtended( const std::string& type ) { return 0; }
00171 
00180         const std::string& NodeName()           { return nodeName; }
00181 
00190         int                NodeId()                     { return nodeId; }
00191 
00196         void SetNodeName( const std::string& name );
00197 
00204         void SetNodeId( int id );       
00205         
00207         GlInsideNodeIt<KrImNode*> ChildTreeIterator()   { return GlInsideNodeIt<KrImNode*>( child ); }
00208 
00210         virtual bool HitTest( int x, int y, int flags, std::vector<KrImage*>* results, int window )  { return false; }
00211         
00215         bool IsVisible( int window=0 );
00216 
00220         bool IsThisVisible( int window=0 )              { return visible[window]; }
00221 
00227         virtual void SetVisible( bool visible, int window=KR_ALL_WINDOWS );
00228 
00234         void ScreenToObject( int x, int y, grinliz::Vector2< GlFixed >* object, int window=0 );
00235 
00237         void SetUserData( void* data )                          { userData = data; }
00238 
00240         void* GetUserData()                                                     { return userData; }
00241 
00246         virtual KrImNode* Clone();
00247 
00248         // -- internal -- //
00249         // Will be true if this needs to be repainted.
00250         bool IsInvalid( int window )    {       GLASSERT( window >= 0 && window < KR_MAX_WINDOWS );
00251                                                                                 return invalid[ window ]; }
00252 
00253         // Adds the invalid rectangles of this node the the 
00254         // engine's DR list and removes the node from the
00255         // start list. Called, with CalcTransform and
00256         // AddToDrawLists, by KrImageTree::Walk.
00257         // This relies on the current "bounds" for the invalid
00258         // rect, so it must be called before CalcTransform.
00259         //
00260         // If "cache" is true, no rectangle is sent, but it is stored.
00261         // Used to pair up overlapping rectangles.
00262         virtual void FlushInvalid( int window, bool cache )     {}
00263 
00264         // Calculate the:
00265         //      - Transformation, both color and spacial.
00266         //      - Bounds.
00267         // Note that the transformation will depend on the parent
00268         // already having been transformed, unless transformFromRoot
00269         // is true.
00270         virtual void CalcTransform( int win );
00271 
00272         // The node has been added to the tree: its links are valid.
00273         virtual void AddedtoTree();
00274         // The node is being removed from the tree.
00275         virtual void LeavingTree();
00276 
00277         void Invalidate( int window );
00278 
00279         // Properties of the node.
00280         // Were protected...but are sometimes useful to get to.
00281         // The transformation matrix, expressed as such.
00282         const KrMatrix2&                XTransform( int window )                        { return xTransform[window]; }
00283         // The composite (calculated absolute) transformation matrix.
00284         const KrMatrix2&                CompositeXForm( int window )            { return compositeXForm[window]; }
00285         // The composite (calculated absolute) color transformation.
00286         const KrColorTransform& CompositeCForm( int window )            { return compositeCForm[window]; }
00287         // The composite (calculated absolute) quality for scaling setting.
00288         int                                             CompositeQuality( int window )          { return compositeQuality[window]; } 
00289         // The composite (calculated absolute) bounds. May be invalid.
00290         const grinliz::Rectangle2I&     CompositeBounds( int window )           { return compositeBounds[window]; }
00291 
00292         // The bounds for this object; may be invalid.
00293         const grinliz::Rectangle2I&     Bounds( int window )                                            { return bounds[window]; }
00294         // Get the child sentinel.
00295         GlInsideNode<KrImNode*>* Child() { return &child; }
00296 
00298         KrImNode* Parent()                                                              { return parent; }
00300         KrEngine* Engine()                                                              { return engine; }
00301 
00302   protected:
00303         void ClearInvalid( int window )                                 { invalid[window] = false; }
00304 
00308         void Resort( KrImNode* resortMe );
00309 
00310         // Sentinel for our child nodes
00311         GlInsideNode<KrImNode*> child;
00312 
00313         // Anything that can be drawn has bounds. Bounds are
00314         // calulated in the CalcTransform call.
00315         grinliz::Rectangle2I    bounds[KR_MAX_WINDOWS];
00316 
00317   private:
00318 
00319         int                     depth;          // user-specified depth
00320 
00321         KrMatrix2                       xTransform[KR_MAX_WINDOWS];             // (x,y) relative to parent (set)
00322         KrMatrix2                       compositeXForm[KR_MAX_WINDOWS]; // (x,y) world (calculated)
00323         KrColorTransform        cTransform[KR_MAX_WINDOWS];             // color relative to parent
00324         KrColorTransform        compositeCForm[KR_MAX_WINDOWS]; // color world (calculated)
00325         int                                     quality[KR_MAX_WINDOWS];
00326         int                                     compositeQuality[KR_MAX_WINDOWS];
00327         grinliz::Rectangle2I compositeBounds[KR_MAX_WINDOWS];
00328 
00329         KrImNode*       parent;                 // The parent in the ImageTree, only null for the root.
00330         KrEngine*       engine;                 // The engine this Image is attached to.
00331         bool            invalid[KR_MAX_WINDOWS];                // Does this need be drawn?
00332 
00333         std::string nodeName;
00334         int         nodeId;
00335         bool            visible[KR_MAX_WINDOWS];
00336         void*           userData;
00337 };
00338 
00339 
00340 #endif
00341 

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