00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
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
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
00111
00112
00113 GlInsideNode<KrImNode*> treeNode;
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
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
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
00300
00301 bool IsInvalid( int window ) { GLASSERT( window >= 0 && window < KR_MAX_WINDOWS );
00302 return invalid[ window ]; }
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 virtual void FlushInvalid( int window, bool cache ) {}
00314
00315
00316
00317
00318
00319
00320
00321 virtual void CalcTransform( int win );
00322
00323
00324 virtual void AddedtoTree();
00325
00326 virtual void LeavingTree();
00327
00328 void Invalidate( int window );
00329
00330
00331
00332
00333 const KrMatrix2& XTransform( int window ) { return xTransform[window]; }
00334
00335 const KrMatrix2& CompositeXForm( int window ) { return compositeXForm[window]; }
00336
00337 const KrColorTransform& CompositeCForm( int window ) { return compositeCForm[window]; }
00338
00339 int CompositeQuality( int window ) { return compositeQuality[window]; }
00340
00341 const KrRect& CompositeBounds( int window ) { return compositeBounds[window]; }
00342
00343
00344 const KrRect& Bounds( int window ) { return bounds[window]; }
00345
00346 GlInsideNode<KrImNode*>* Child() { return &child; }
00347
00349 KrImNode* Parent() { return parent; }
00351 KrEngine* Engine() { return engine; }
00352
00353 protected:
00354
00355 int TreeDepth() { return treeDepth; }
00356
00357 void ClearInvalid( int window ) { invalid[window] = false; }
00358
00362 void Resort( KrImNode* resortMe );
00363
00364
00365 GlInsideNode<KrImNode*> child;
00366
00367
00368
00369 KrRect bounds[KR_MAX_WINDOWS];
00370
00371 private:
00372
00373 int depth;
00374 int treeDepth;
00375
00376 KrMatrix2 xTransform[KR_MAX_WINDOWS];
00377 KrMatrix2 compositeXForm[KR_MAX_WINDOWS];
00378 KrColorTransform cTransform[KR_MAX_WINDOWS];
00379 KrColorTransform compositeCForm[KR_MAX_WINDOWS];
00380 int quality[KR_MAX_WINDOWS];
00381 int compositeQuality[KR_MAX_WINDOWS];
00382 KrRect compositeBounds[KR_MAX_WINDOWS];
00383
00384 KrImNode* parent;
00385 KrEngine* engine;
00386 bool invalid[KR_MAX_WINDOWS];
00387
00388 std::string nodeName;
00389 int nodeId;
00390 bool visible[KR_MAX_WINDOWS];
00391 void* userData;
00392 };
00393
00394
00395 #endif
00396