Main Page   Class Hierarchy   Compound List   File List   Compound Members  

imnode.h

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 #ifndef KYRA_IMAGE_NODE_INCLUDED
00070 #define KYRA_IMAGE_NODE_INCLUDED
00071 
00072 #include "../util/glinsidelist.h"
00073 #include "../util/gldynarray.h"
00074 #include "SDL.h"
00075 #include "krmath.h"
00076 #include "color.h"
00077 #include "kyrabuild.h"
00078 
00079 // Disable the no-exception handling warning.
00080 #pragma warning( disable : 4530 )
00081 #pragma warning( disable : 4786 )
00082 #include <string>
00083 
00084 
00085 class KrEngine;
00086 struct KrRect;
00087 class KrImage;
00088 class KrSprite;
00089 class KrTile;
00090 class KrCanvas;
00091 class KrTextBox;
00092 class KrBox;
00093 class KrWidget;
00094 
00095 
00096 const int KR_ALL_WINDOWS = -1;
00097 
00105 class KrImNode
00106 {
00107         friend class KrImageTree;
00108 
00109   public:
00110         // The nodes:
00111         // Not really methods, not really data members. Here
00112         // but not to be used.
00113         GlInsideNode<KrImNode*> treeNode;       // We are in someone else's child list.
00114 
00115   public:
00116         KrImNode();
00117         virtual ~KrImNode()                             {}
00118 
00131         int  ZDepth()                                   { return depth; }
00132 
00134         void SetZDepth( int z );
00135 
00137         int X( int window=0 )                   {       GLASSERT( ( xTransform[window].x.v & 0xffff ) == 0 );
00138                                                                                 return xTransform[window].x.ToInt(); }
00140         int Y( int window=0 )                   {       GLASSERT( ( xTransform[window].y.v & 0xffff ) == 0 );
00141                                                                                 return xTransform[window].y.ToInt(); }
00142 
00144         GlFixed XScale( int window=0 )                          { return xTransform[window].xScale; }
00146         GlFixed YScale( int window=0 )                          { return xTransform[window].yScale; }
00147 
00149         const KrMatrix2& Transform( int window=0 )      { return xTransform[window]; }
00150 
00159         void SetPos( int x, int y, int window=KR_ALL_WINDOWS );
00160 
00162         void SetScale( GlFixed xScale, GlFixed yScale, int window=KR_ALL_WINDOWS );
00163 
00165         void SetTransform( KrMatrix2& xForm, int window=KR_ALL_WINDOWS );
00166 
00173         void SetQuality( int quality, int window=KR_ALL_WINDOWS );
00174 
00176         void DeltaPos( int deltaX, int deltaY, int window=KR_ALL_WINDOWS )              { SetPos( X() + deltaX, Y() + deltaY, window ); }
00177 
00180         const KrColorTransform& CTransform( int window=0 )                      { return cTransform[window]; }
00181 
00185         virtual void SetColor( const KrColorTransform& color, int window=KR_ALL_WINDOWS );
00186 
00187         virtual KrImage*  ToImage()             { return 0; }   
00188         virtual KrSprite* ToSprite()    { return 0; }   
00189         virtual KrTile*   ToTile()              { return 0; }   
00190         virtual KrCanvas* ToCanvas()    { return 0; }   
00191         virtual KrTextBox*ToTextBox()   { return 0; }   
00192         virtual KrBox*    ToBox()               { return 0; }   
00193         virtual KrWidget* ToWidget()    { return 0; }   
00194 
00204         virtual KrImNode* ToExtended( const std::string& type ) { return 0; }
00205 
00206 //      /** Support for GUI Widgets.
00207 //              A widget can interact with its immediate children on the tree.
00208 //              So if a node's parent is a widget, then that widget is related, but
00209 //              any non-widget parent will break the relation. This function returns
00210 //              the highest related parent widget. It will never return 'this'.
00211 //      */
00212 //      KrWidget* TopWidget();
00213 //
00214 //      /** Support for GUI Widgets.
00215 //              Return this if it is a widget, or its parent if that is a widget.
00216 //              Otherwise returns null. Effectively returns the lowest level widget
00217 //              this node is associated with. (The opposite behavior of TopWidget() ).
00218 //      */
00219 //      KrWidget* GetWidget();
00220 
00229         const std::string& NodeName()           { return nodeName; }
00230 
00239         int                NodeId()                     { return nodeId; }
00240 
00245         void SetNodeName( const std::string& name );
00246 
00251         void SetNodeId( int id );       
00252         
00254         GlInsideNodeIt<KrImNode*> ChildTreeIterator()   { return GlInsideNodeIt<KrImNode*>( child ); }
00255 
00257         virtual bool HitTest( int x, int y, int flags, GlDynArray<KrImage*>* results, int window )  { return false; }
00258         
00262         bool IsVisible( int window=0 );
00263 
00267         bool IsThisVisible( int window=0 )              { return visible[window]; }
00268 
00274         virtual void SetVisible( bool visible, int window=KR_ALL_WINDOWS );
00275 
00281         void ScreenToObject( int x, int y, KrVector2T< GlFixed >* object, int window=0 );
00282 
00284         void SetUserData( void* data )                          { userData = data; }
00286         void SetUserDataU32( U32 data )                         { userData = (void*) data; }
00287 
00289         void* GetUserData()                                                     { return userData; }
00291         U32   GetUserDataU32()                                          { return (U32) userData; }
00292 
00297         virtual KrImNode* Clone();
00298 
00299         // -- internal -- //
00300         // Will be true if this needs to be repainted.
00301         bool IsInvalid( int window )    {       GLASSERT( window >= 0 && window < KR_MAX_WINDOWS );
00302                                                                                 return invalid[ window ]; }
00303 
00304         // Adds the invalid rectangles of this node the the 
00305         // engine's DR list and removes the node from the
00306         // start list. Called, with CalcTransform and
00307         // AddToDrawLists, by KrImageTree::Walk.
00308         // This relies on the current "bounds" for the invalid
00309         // rect, so it must be called before CalcTransform.
00310         //
00311         // If "cache" is true, no rectangle is sent, but it is stored.
00312         // Used to pair up overlapping rectangles.
00313         virtual void FlushInvalid( int window, bool cache )     {}
00314 
00315         // Calculate the:
00316         //      - Transformation, both color and spacial.
00317         //      - Bounds.
00318         // Note that the transformation will depend on the parent
00319         // already having been transformed, unless transformFromRoot
00320         // is true.
00321         virtual void CalcTransform( int win );
00322 
00323         // The node has been added to the tree: its links are valid.
00324         virtual void AddedtoTree();
00325         // The node is being removed from the tree.
00326         virtual void LeavingTree();
00327 
00328         void Invalidate( int window );
00329 
00330         // Properties of the node.
00331         // Were protected...but are sometimes useful to get to.
00332         // The transformation matrix, expressed as such.
00333         const KrMatrix2&                XTransform( int window )                        { return xTransform[window]; }
00334         // The composite (calculated absolute) transformation matrix.
00335         const KrMatrix2&                CompositeXForm( int window )            { return compositeXForm[window]; }
00336         // The composite (calculated absolute) color transformation.
00337         const KrColorTransform& CompositeCForm( int window )            { return compositeCForm[window]; }
00338         // The composite (calculated absolute) quality for scaling setting.
00339         int                                             CompositeQuality( int window )          { return compositeQuality[window]; } 
00340         // The composite (calculated absolute) bounds. May be invalid.
00341         const KrRect&                   CompositeBounds( int window )           { return compositeBounds[window]; }
00342 
00343         // The bounds for this object; may be invalid.
00344         const KrRect&   Bounds( int window )                                            { return bounds[window]; }
00345         // Get the child sentinel.
00346         GlInsideNode<KrImNode*>* Child() { return &child; }
00347 
00349         KrImNode* Parent()                                                              { return parent; }
00351         KrEngine* Engine()                                                              { return engine; }
00352 
00353   protected:
00354         // depth used by opengl
00355         int TreeDepth()                                                                 { return treeDepth; }
00356 
00357         void ClearInvalid( int window )                                 { invalid[window] = false; }
00358 
00362         void Resort( KrImNode* resortMe );
00363 
00364         // Sentinel for our child nodes
00365         GlInsideNode<KrImNode*> child;
00366 
00367         // Anything that can be drawn has bounds. Bounds are
00368         // calulated in the CalcTransform call.
00369         KrRect                          bounds[KR_MAX_WINDOWS];
00370 
00371   private:
00372 
00373         int                     depth;          // user-specified depth
00374         int                     treeDepth;      // used by opengl drawing
00375 
00376         KrMatrix2                       xTransform[KR_MAX_WINDOWS];             // (x,y) relative to parent (set)
00377         KrMatrix2                       compositeXForm[KR_MAX_WINDOWS]; // (x,y) world (calculated)
00378         KrColorTransform        cTransform[KR_MAX_WINDOWS];             // color relative to parent
00379         KrColorTransform        compositeCForm[KR_MAX_WINDOWS]; // color world (calculated)
00380         int                                     quality[KR_MAX_WINDOWS];
00381         int                                     compositeQuality[KR_MAX_WINDOWS];
00382         KrRect                          compositeBounds[KR_MAX_WINDOWS];
00383 
00384         KrImNode*       parent;                 // The parent in the ImageTree, only null for the root.
00385         KrEngine*       engine;                 // The engine this Image is attached to.
00386         bool            invalid[KR_MAX_WINDOWS];                // Does this need be drawn?
00387 
00388         std::string nodeName;
00389         int         nodeId;
00390         bool            visible[KR_MAX_WINDOWS];
00391         void*           userData;
00392 };
00393 
00394 
00395 #endif
00396 

Generated on Mon Sep 15 12:01:11 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001