Main Page | Class Hierarchy | Class List | File List | Class Members

aedWidget.h

00001 
00002 /*
00003  * The aedWidget class
00004  * The "visible widgets" base class
00005  * Initial design by Eduardo B. Fonseca <ebf@aedsolucoes.com.br>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library General Public
00018  * License along with this library; if not, write to the Free
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 
00023 #ifndef AEDWIDGET_H
00024 #define AEDWIDGET_H
00025 
00026 #include "aedObject.h"
00027 #include "aedRect.h"
00028 #include "aedColor.h"
00029 #include "aedFont.h"
00030 #include "aedTheme.h"
00031 #include "aedApp.h"
00032 
00033 #define sgn(x) ((x<0)?-1:((x>0)?1:0))
00034 
00035 #define TAKEOVERX -1
00036 #define TAKEOVERY -1
00037 #define CENTERX -2
00038 #define CENTERY -2
00039 #define FULLX -3
00040 #define FULLY -3
00041 #define TAKEOVERPARENT TAKEOVERX, TAKEOVERY
00042 
00044 // TODO: we need to change this to a real event class... one we can use
00045 // on the aedEventManager and on the aedSignal class.
00046 struct aedKeyEvent
00047 {
00048     Uint16 sym;
00049     Uint16 unicode;
00050 };
00051 
00052 // Justifications
00053 enum aedJusts
00054 {
00055     AED_JUST_LEFT = 1,
00056     AED_JUST_CENTER,
00057     AED_JUST_RIGHT
00058 };
00059 
00060 // Border types
00061 enum
00062 {
00063     AED_BORDER_NONE = 0,
00064     AED_BORDER_ROUND = 1,
00065     AED_BORDER_SQUARED = 2
00066 };
00067 
00068 const Uint16 cPad = 3;
00069 
00070 class DLLEXPORT aedWidget:public aedObject
00071 {
00072   public:
00073     aedWidget();
00074     virtual ~ aedWidget();
00075 
00076     // The root constructor
00077     aedWidget(Uint16 screenWidth, Uint16 screenHeight, bool takeOverScreen =
00078               true);
00079 
00080     // The CREATE function
00081     virtual void create(aedWidget * parent = NULL, aedRect pos =
00082                         aedDEFAULTPOSITION, std::string caption = "");
00083 
00084     // Basic Functions
00085     void setStatic(bool value)
00086     {
00087         m_IsStatic = value;
00088     }
00089 
00090     virtual void enable(bool value)
00091     {
00092         m_IsEnabled = value;
00093         setRenderState(true);
00094     }
00095 
00096     void show(void)
00097     {
00098         m_ShowWidget = true;
00099         setRenderState(true);
00100     }
00101     void hide(void)
00102     {
00103         m_ShowWidget = false;
00104         if(getParent())
00105             getParent()->setRenderState(true);
00106     }
00107     bool isVisible(void) const
00108     {
00109         return m_ShowWidget;
00110     }
00111     bool isLPressed(void) const
00112     {
00113         return m_isLPressed;
00114     }
00115     bool isRPressed(void) const
00116     {
00117         return m_isRPressed;
00118     }
00119     void bringToTop(void);
00120     bool hasFocus() const;
00121     aedWidget *getTopMostWidget();
00122 
00123     // Coords
00124     Uint16 getScreenWidth(void) const
00125     {
00126         return m_ScreenWidth;
00127     }
00128     Uint16 getScreenHeight(void) const
00129     {
00130         return m_ScreenHeight;
00131     }
00132     void setPos(Sint16 x, Sint16 y);
00133     void setSize(Sint16 w, Sint16 h);
00134 
00135     void screenToClient(Uint16 & x, Uint16 & y);
00136     Uint16 clientxToScreen(Uint16 x = 0);
00137     Uint16 clientyToScreen(Uint16 y = 0);
00138     Sint32 clientwToScreen(Sint32 w = 0);
00139     Sint32 clienthToScreen(Sint32 h = 0);
00140 
00141     aedRect getPositionOffset(void);
00142     aedRect getPos(void);
00143     aedRect getPosition(void);
00144     aedRect getMyTranslatedPosition(void);
00145     aedRect getRealPos(void)
00146     {
00147         return getMyPosition();
00148     }
00149 
00150     // Drawing Functions
00151     bool getRenderState(void) const
00152     {
00153         return m_ReRender;
00154     }
00155     void setRenderState(bool status)
00156     {
00157         m_ReRender = status;
00158         if(m_ReRender)
00159             makeAllDirty();
00160     }
00161 
00162     void renderAll(SDL_Surface * screen = NULL);
00163 
00164     virtual void render(void);
00165     aedColor getBGColor(void) const
00166     {
00167         return m_BGColor;
00168     }
00169 
00170     void setBGColor(aedColor color)
00171     {
00172         m_BGColor = color;
00173     }
00174     void setActiveBorder(bool value)
00175     {
00176         m_HasActiveBorder = value;
00177     }
00178     bool getActiveBorder(void) const
00179     {
00180         return m_HasActiveBorder;
00181     }
00182 
00183     void setAlphaValue(Uint8 alpha);
00184     Uint8 getAlphaValue(void) const
00185     {
00186         return m_AlphaValue;
00187     }
00188 
00189     bool isMouseOver(void);
00190 
00191     // Caption Functions
00192     virtual void setCaption(const std::string & caption)
00193     {
00194         m_Caption = caption;
00195     }
00196     virtual std::string getCaption(void) const
00197     {
00198         return m_Caption;
00199     }
00200 
00201     // Border stuff
00202     int getBorder() const
00203     {
00204         return m_Border;
00205     }
00206     void setBorder(int border)
00207     {
00208         if(m_Border != border)
00209         {
00210             m_Border = border;
00211             setRenderState(true);
00212         }
00213     }
00214 
00215     aedColor getBorderColor() const
00216     {
00217         return m_BorderColor;
00218     }
00219     void setBorderColor(aedColor color)
00220     {
00221         m_BorderColor = color;
00222         setRenderState(true);
00223     }
00224 
00225     void setFont(aedFont * font)
00226     {
00227         m_Font = font;
00228         setRenderState(true);
00229     }
00230     aedFont *getFont() const
00231     {
00232         return m_Font;
00233     }
00234 
00235     void setTheme(aedTheme * Theme);
00236 
00237     aedTheme *getTheme() const
00238     {
00239         return m_Theme;
00240     }
00241 
00242     aedWidget *findWidget(const std::string & id);
00243     aedWidget *findWidget(aedWidget * pointer);
00244     virtual bool addWidget(aedWidget * win);
00245     virtual bool removeWidget(aedWidget * win);
00246     aedWidget *getParent() const
00247     {
00248         return m_Parent;
00249     }
00250 
00251     // Messages
00252     virtual int wm_paint(SDL_Surface * screen = NULL, Uint16 x = 0, Uint16 y =
00253                          0, Uint16 w = 0, Uint16 h = 0);
00254     virtual int wm_lbuttondown(Uint16 x, Uint16 y);
00255     virtual int wm_lbuttonup(Uint16 x, Uint16 y);
00256     virtual int wm_rbuttondown(Uint16 x, Uint16 y);
00257     virtual int wm_rbuttonup(Uint16 x, Uint16 y);
00258     virtual int wm_sizechanged(Uint16 screenWidth, Uint16 screenHeight);
00259     virtual int wm_keydown(aedKeyEvent & event);
00260     virtual int wm_update(Uint32 msdelta);
00261     virtual int wm_gotfocus()
00262     {
00263         return 0;
00264     }
00265     virtual int wm_lostfocus()
00266     {
00267         return 0;
00268     }
00269     virtual int wm_mouseenter()
00270     {
00271         return 0;
00272     }
00273     virtual int wm_mouseleave()
00274     {
00275         return 0;
00276     }
00277     virtual int wm_mousemove(Uint16 x, Uint16 y, Uint16 dx, Uint16 dy)
00278     {
00279         return 0;
00280     }
00281 
00282     bool isEnabled() const
00283     {
00284         if(getParent())
00285             return m_IsEnabled && getParent()->isEnabled();
00286         return m_IsEnabled;
00287     }
00288     bool canFocus() const
00289     {
00290         return m_CanFocus && isEnabled();
00291     }
00292 
00293     void update();
00294 
00295     void setId(const std::string & id);
00296 
00297     const std::string & getId() const
00298     {
00299         return m_Id;
00300     }
00301 
00302     void setUserData(void *userdata)
00303     {
00304         m_userdata = userdata;
00305     }
00306 
00307     void *getUserData()
00308     {
00309         return m_userdata;
00310     }
00311 
00312     bool pollEvent(SDL_Event * event);
00313 
00314   protected:
00315     aedRect getMyPosition(void);
00316     void init(void);
00317 
00318   private:
00319     void processEvent(SDL_Event * event);
00320     aedWidget *findChildAtCoord(Uint16 x, Uint16 y, Uint8 flags = 0);
00321     void makeAllDirty(void);
00322     void updateAllChildren(Uint32 msdelta);
00323     bool tabFocus();
00324     bool tabFocusChildren();
00325     void tabFocusParent();
00326 
00327   protected:
00328     std::string m_Caption;
00329     bool m_IsEnabled:1;
00330     bool m_IsStatic:1;
00331     bool m_CanFocus:1;
00332     bool m_IsWidget:1;
00333     bool m_ShowWidget:1;
00334     bool m_ReRender:1;
00335     bool m_HasActiveBorder:1;
00336     int m_Border;
00337     aedColor m_BorderColor;
00338     aedColor m_BGColor;
00339 
00340     aedFont *m_Font;
00341     aedTheme *m_Theme;
00342 
00343     // The widget's drawing surface.
00344     SDL_Surface *m_Surface;
00345 
00346     Uint8 m_AlphaValue;
00347     Uint8 m_Flags;
00348 
00349     // The widget position, in aedGUI Virtual Units (AVU)
00350     aedRect m_Pos;
00351 
00352     // Here we "cache" the widget position in pixel values
00353     aedRect m_PixelPos;
00354 
00355     // Position Offset
00356     aedRect m_PositionOffset;
00357     bool m_isLPressed;
00358     bool m_isRPressed;
00359 
00360   private:
00361     std::string m_Id;
00362     void *m_userdata;
00363     aedWidget *m_Parent;
00364 
00365     std::vector < aedWidget * >m_Children;
00366     Uint32 m_CurTicks, m_LastTicks;
00367 
00368     Uint16 m_ScreenWidth, m_ScreenHeight;
00369 };
00370 
00371 #if defined(_MSC_VER)
00372 DLLEXTERN template DLLEXPORT aedFunctor1Arg < stub, aedWidget >;
00373 #endif
00374 
00375 #endif

Generated on Mon Mar 1 19:56:18 2004 for aedGUI by doxygen 1.3.6