00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __CAUGUI_TOOLS__
00011 #define __CAUGUI_TOOLS__
00012
00013 #define kCAUGuiSchemeMaxPatterns 16
00014
00015
00016 #include <Carbon/Carbon.h>
00017
00018 #include "CAUGuiConfig.h"
00019
00031 typedef enum
00032 {
00033 kCAUGui_noType = 0,
00034 kCAUGui_PNG = 'cPNG',
00035 kCAUGui_RSRC = 'cRSC',
00036 kCAUGui_Graphic = 'cAgr',
00037 kCAUGui_SpinImage = 'cAsi',
00038 kCAUGui_Pane = 'cApn',
00039 kCAUGui_LayeredPane = 'cAlp',
00040 kCAUGui_Knob = 'cAkb',
00041 kCAUGui_Slider = 'cAsr',
00042 kCAUGui_Selector = 'cAst',
00043 kCAUGui_Display = 'cAdy',
00044 kCAUGui_Meter = 'cAmt',
00045 kCAUGui_Label = 'cAlb'
00046
00047
00048 } CAUGuiType;
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00066 typedef enum
00067 {
00068 kNone = 0,
00069
00070 kVOutside = 1,
00071
00072 kNorth = 2,
00073 kSouth = 4,
00074 kMiddle = 6,
00075
00076 kHOutside = 8,
00077
00078 kWest = 16,
00079 kEast = 32,
00080 kCenter = 48,
00081
00082
00083 k_NW = kNorth + kWest,
00084 k_NC = kNorth + kCenter,
00085 k_NE = kNorth + kEast,
00086 k_ME = kMiddle + kEast,
00087 k_SE = kSouth + kEast,
00088 k_SC = kSouth + kCenter,
00089 k_SW = kSouth + kWest,
00090 k_MW = kMiddle + kWest,
00091
00092
00093
00094 k_oNW = kNorth + kWest + kVOutside,
00095 k_oNC = kNorth + kCenter + kVOutside,
00096 k_oNE = kNorth + kEast + kVOutside,
00097 k_oSE = kSouth + kEast + kVOutside,
00098 k_oSC = kSouth + kCenter + kVOutside,
00099 k_oSW = kSouth + kWest + kVOutside,
00100
00101
00102
00103 k_NWo = kNorth + kWest + kHOutside,
00104 k_NEo = kNorth + kEast + kHOutside,
00105 k_MEo = kMiddle + kEast + kHOutside,
00106 k_SEo = kSouth + kEast + kHOutside,
00107 k_SWo = kSouth + kWest + kHOutside,
00108 k_MWo = kMiddle + kWest + kHOutside,
00109
00110
00111
00112 k_oNWo = kNorth + kWest + kVOutside + kVOutside,
00113 k_oNCo = kNorth + kCenter + kVOutside + kVOutside,
00114 k_oNEo = kNorth + kEast + kVOutside + kVOutside,
00115 k_oMEo = kMiddle + kEast + kVOutside + kVOutside,
00116 k_oSEo = kSouth + kEast + kVOutside + kVOutside,
00117 k_oSCo = kSouth + kCenter + kVOutside + kVOutside,
00118 k_oSWo = kSouth + kWest + kVOutside + kVOutside,
00119 k_oMWo = kMiddle + kWest + kVOutside + kVOutside,
00120
00121
00122
00123 k_v1 = kNorth + kVOutside,
00124 k_v2 = kNorth,
00125 k_v3 = kMiddle,
00126 k_v4 = kSouth,
00127 k_v5 = kSouth + kVOutside,
00129 k_h1 = kWest + kHOutside,
00130 k_h2 = kWest,
00131 k_h3 = kCenter,
00132 k_h4 = kEast,
00133 k_h5 = kEast + kHOutside
00136 } CAUGuiAlign;
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00156 class eRect
00157 {
00158 public:
00159
00161 eRect () { x = y = w = h = 0; }
00162
00171 eRect ( SInt32 a, SInt32 b, SInt32 c, SInt32 d ) { x = a; y = b; w = c; h = d; }
00172
00174 void offset ( SInt32 a, SInt32 b ) { x += a; y += b; }
00175
00177 void at ( SInt32 a, SInt32 b ) { x = a; y = b; }
00178
00180 void size ( SInt32 c, SInt32 d ) { w = c; h = d; }
00181
00183 void grow ( SInt32 a, SInt32 b ) { x -= a; y -= b; w += a*2; h += b*2; }
00184
00186 void grow ( SInt32 a, SInt32 b, SInt32 c, SInt32 d) { x -= a; y -= b; w += a + c; h += b + d; }
00187
00189 void align ( CAUGuiAlign align );
00190
00192 void align ( eRect* r, CAUGuiAlign align );
00193
00195 void set ( eRect* from ) { x = from->x; y = from->y; w = from->w; h = from->h; }
00196
00198 void set ( SInt32 X, SInt32 Y, SInt32 W, SInt32 H ) { x = X; y = Y; w = W; h = H; }
00199
00201 void to ( Rect* r ) { r->left = x; r->top = y; r->right = x + w; r->bottom = y + h; }
00202
00204 void to ( CGRect* r, UInt32 winH )
00205 {
00206 r->origin.x = x;
00207 r->origin.y = winH - y - h;
00208 r->size.width = w;
00209 r->size.height = h;
00210 }
00211
00212 SInt32 x;
00213 SInt32 y;
00214 SInt32 w;
00215 SInt32 h;
00217 };
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00243 class CAUGuiItem
00244 {
00245 public:
00246
00247 CAUGuiItem()
00248 {
00249 this->type = kCAUGui_noType;
00250 this->id = 0;
00251 this->prev = NULL;
00252 this->next = NULL;
00253
00254
00255 }
00256
00258 virtual ~CAUGuiItem()
00259 {
00260
00261 if ( this->next != NULL ) delete ( next );
00262
00263
00264 }
00265
00266 CAUGuiItem* getByID ( UInt32 theID )
00267 {
00268 if ( id == theID ) return (this);
00269
00270 if ( next == NULL ) return (NULL);
00271 else return (next->getByID ( theID ));
00272 }
00273
00283 void append ( CAUGuiItem* nextItem )
00284 {
00285 if ( next == NULL )
00286 {
00287 next = nextItem;
00288 nextItem->setPrev( this );
00289 }
00290 else
00291 next->append( nextItem );
00292 }
00293
00294 CAUGuiItem* getNext () { return ( next ); }
00295 CAUGuiItem* getPrev () { return ( prev ); }
00296 void setPrev ( CAUGuiItem* thePrev ) { prev = thePrev; }
00297 UInt32 getID() { return id; }
00298 void setID( UInt32 theID ) { id = theID; }
00299 CAUGuiType getType() { return type; }
00300 void setType( CAUGuiType theType) { type = theType; }
00301
00302 private:
00303 CAUGuiType type;
00304 UInt32 id;
00305 CAUGuiItem* prev;
00306 CAUGuiItem* next;
00307
00308 };
00309
00310
00311
00312
00313
00314
00315
00316
00317
00326 class CAUGuiImage : public CAUGuiItem
00327 {
00328 public:
00329 CAUGuiImage ( char* pngFileName );
00330
00331 virtual ~CAUGuiImage ()
00332 {
00333 if ( this->Image != NULL )
00334 CGImageRelease( this->Image );
00335 this->Image = NULL;
00336
00337
00338 }
00339
00340 virtual CGImageRef getImage() { return Image; }
00341
00342 virtual bool isPNG ( char* pngFileName );
00343 virtual bool isRSRC ( int res ) { return ( res == resourceID );}
00344
00345
00346 private:
00347
00348 void loadImagePNG ( char* pngFileName );
00349
00350 char fileName[ 64 ];
00351 int resourceID;
00352
00353 CGImageRef Image;
00354
00355 };
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00378 class CAUGuiGraphic : public CAUGuiItem
00379 {
00380 public:
00381
00383 CAUGuiGraphic ( char* pngFileName );
00384
00386 CAUGuiGraphic ( char* pngFileName, UInt32 numFrames );
00387
00389 virtual ~CAUGuiGraphic ()
00390 {
00391 if ( this->Image != NULL )
00392 CGImageRelease( this->Image );
00393 this->Image = NULL;
00394
00395
00396 }
00397
00398
00399
00400
00402 virtual bool isAnim() { return ( Frames == 1 ? false : true ); }
00403
00405 virtual CGImageRef getImage() { return Image; }
00406
00408 virtual SInt32 getFrames () { return (SInt32)Frames; }
00409
00411 virtual SInt32 getWidth();
00412
00414 virtual SInt32 getHeight();
00415
00416
00417
00425 virtual void draw( CGContextRef context, UInt32 portHeight, eRect* rect, float value );
00426
00427 private:
00428
00429 void loadImagePNG ( char* pngFileName );
00430
00431 CGImageRef Image;
00432 UInt32 Frames;
00433 SInt32 FrameHeight;
00434
00435 };
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00456 class CAUGuiLabel : public CAUGuiItem
00457 {
00458 public:
00459 CAUGuiLabel ( CAUGuiGraphic* theGraphic, eRect* theBounds );
00460
00461 virtual ~CAUGuiLabel ()
00462 {
00463 this->Graphic = NULL;
00464
00465
00466 }
00467
00468 virtual SInt32 getWidth() {return Graphic->getWidth();}
00469
00470 virtual SInt32 getHeight() {return Graphic->getHeight();}
00471
00472 virtual void draw( CGContextRef context, UInt32 portHeight, eRect* rect, float value );
00473
00474 private:
00475
00476 CAUGuiGraphic* Graphic;
00477
00478 eRect Bounds;
00479
00480 };
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00504 class CAUGuiScheme
00505 {
00506 public:
00507 CAUGuiScheme ();
00508
00509 void add( eRect* r, CAUGuiAlign align );
00510
00511 void reset();
00512
00513 void at ( SInt32 x, SInt32 y );
00514
00515 eRect* get();
00516 eRect* getS( SInt32 w, SInt32 h );
00517
00518
00519 private:
00520 eRect resulting;
00521 eRect rects[ kCAUGuiSchemeMaxPatterns ];
00522 CAUGuiAlign aligns[ kCAUGuiSchemeMaxPatterns ];
00523 UInt32 patternLength;
00524 UInt32 currentIteration;
00525 UInt32 currentPattern;
00526 bool notAligned;
00527 SInt32 X;
00528 SInt32 Y;
00529 SInt32 startX;
00530 SInt32 startY;
00531 SInt32 offsetX;
00532 SInt32 offsetY;
00533
00534 };
00535
00536
00537
00538 #endif