Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields

widget.h

00001 /***************************************************************************
00002                           widget.h  -  description
00003                              -------------------
00004     begin                : Thu Aug 28 2003
00005     copyright            : (C) 2003 by Gabor Torok
00006     email                : cctorok@yahoo.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef WIDGET_H
00019 #define WIDGET_H
00020 
00021 #include "../constants.h"
00022 
00027 class SDLHandler;
00028 
00029 class Widget {
00030  protected:
00031   int x, y, w, h;
00032   bool visible;
00033   Color color;
00034   Color background;
00035   Color selColor;
00036   Color borderColor;
00037   Color borderColor2;
00038   Color focusColor;
00039   bool focus;
00040   float alpha, alphaInc;
00041   GLint lastTick;
00042   char tooltip[255];
00043   GLuint tooltipTicks;
00044   bool tooltipShowing;
00045 
00046  public: 
00047   Widget(int x, int y, int w, int h);
00048   virtual ~Widget();
00049   virtual void draw(Widget *parent);
00050 
00051   virtual inline int getX() { return x; }
00052   virtual inline int getY() { return y; }
00053   virtual inline int getWidth() { return w; }
00054   virtual inline int getHeight() { return h; }
00055 
00056   virtual inline void move(int x, int y) { this->x = x; this->y = y; }
00057   virtual inline void resize(int w, int h) { this->w = w; this->h = h; }
00058 
00059   virtual inline void setVisible(bool b) { visible = b; }
00060   virtual inline bool isVisible() { return visible; }
00061 
00062   virtual void drawWidget(Widget *parent) = 0;
00063 
00064   virtual inline bool hasFocus() { return focus; }
00065   virtual inline void setFocus(bool b) { focus = b; }
00066   virtual inline bool canGetFocus() { return isVisible(); }
00067 
00068 
00069   // color
00070   inline void setColor( float r, float g, float b, float a=1.0f ) { this->color.r = r; this->color.g = g; this->color.b = b; this->color.a = a; }
00071   inline void setBorderColor( float r, float g, float b, float a=1.0f ) { this->borderColor.r = r; this->borderColor.g = g; this->borderColor.b = b; this->borderColor.a = a; }
00072   inline void setHighlightedBorderColor( float r, float g, float b, float a=1.0f ) { this->borderColor2.r = r; this->borderColor2.g = g; this->borderColor2.b = b; this->borderColor2.a = a; }
00073   inline void setBackground(float r, float g, float b, float a=1.0f) { background.r = r; background.g = g; background.b = b; background.a = a; }
00074   inline void setSelectionColor(float r, float g, float b, float a=1.0f) { selColor.r = r; selColor.g = g; selColor.b = b; selColor.a=a; }
00075   inline void setColor( Color *c ) { this->color.r = c->r; this->color.g = c->g; this->color.b = c->b; this->color.a = c->a; }
00076   inline void setBorderColor( Color *c ) { this->borderColor.r = c->r; this->borderColor.g = c->g; this->borderColor.b = c->b; this->borderColor.a = c->a; }
00077   inline void setBackground( Color *c) { background.r = c->r; background.g = c->g; background.b = c->b; background.a = c->a; }
00078   inline void setSelectionColor( Color *c ) { selColor.r = c->r; selColor.g = c->g; selColor.b = c->b; selColor.a=c->a; }
00079   inline void setFocusColor( float r, float g, float b, float a=1.0f ) { this->focusColor.r = r; this->focusColor.g = g; this->focusColor.b = b; this->focusColor.a = a; }
00080   inline void setFocusColor( Color *c ) { focusColor.r = c->r; focusColor.g = c->g; focusColor.b = c->b; focusColor.a=c->a; }
00081 
00082   inline void applyColor() { glColor4f( color.r, color.g, color.b, color.a ); }
00083   inline void applyBorderColor() { glColor4f(borderColor.r, borderColor.g, borderColor.b, borderColor.a); }
00084   inline void applyHighlightedBorderColor() { glColor4f(borderColor2.r, borderColor2.g, borderColor2.b, borderColor2.a); }
00085   inline void applyBackgroundColor(bool opaque=false) { glColor4f( background.r, background.g, background.b, (opaque ? 1.0f : 0.85f) ); }
00086   inline void applySelectionColor() { glColor4f( selColor.r, selColor.g, selColor.b, selColor.a ); }
00087   inline void applyFocusColor() { glColor4f( focusColor.r, focusColor.g, focusColor.b, focusColor.a ); }
00088 
00089   inline Color *getColor() { return &color; }
00090   inline Color *getBorderColor() { return &borderColor; }
00091   inline Color *getHighlightedBorderColor() { return &borderColor2; }
00092   inline Color *getBackgroundColor() { return &background; }
00093   inline Color * getSelectionColor() { return &selColor; }
00094 
00095   inline bool isTranslucent() { return (background.a < 1.0f); }
00096 
00102   virtual bool handleEvent(Widget *parent, SDL_Event *event, int x, int y);
00103 
00107   virtual void removeEffects(Widget *parent);
00108   virtual bool isInside(int x, int y);
00109 
00110         inline void setDebug(bool d) { debug = d; }
00111 
00115   virtual inline int getEventType() { return 0; }
00116 
00117   virtual inline bool hasSound() { return true; }
00118 
00119   inline void setTooltip( char *s ) { strncpy( tooltip, ( s ? s : "" ), 255); tooltip[254] = '\0'; }
00120   inline char *getTooltip() { return tooltip; }
00121 
00122   void drawTooltip( Widget *parent );
00123 
00124  protected:
00125   bool debug;
00126   virtual void drawButton( Widget *parent, int x, int y, int x2, int y2, 
00127                            bool toggle, bool selected, bool inverse, 
00128                            bool glowing, bool inside );
00129   void breakText( char *text, int lineWidth, vector<string> *lines );
00130 };
00131 
00132 #endif
00133 

Generated on Thu Jun 16 21:50:43 2005 for scourge by  doxygen 1.4.0