00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 #include <set>
00034
00035 enum {
00036 TAKEOVERX = -1,
00037 TAKEOVERY = -1,
00038 CENTERX = -2,
00039 CENTERY = -2,
00040 FULLX = -3,
00041 FULLY = -3
00042 };
00043
00044 #define TAKEOVERPARENT TAKEOVERX, TAKEOVERY
00045
00046 typedef void(*widget_deleted_callback_t)(class aedWidget*);
00047
00049
00050
00051 struct aedKeyEvent
00052 {
00053 Uint16 sym;
00054 Uint16 unicode;
00055 };
00056
00057
00058 enum aedJusts
00059 {
00060 AED_JUST_LEFT = 1,
00061 AED_JUST_CENTER,
00062 AED_JUST_RIGHT
00063 };
00064
00065
00066 enum
00067 {
00068 AED_BORDER_NONE = 0,
00069 AED_BORDER_ROUND = 1,
00070 AED_BORDER_SQUARED = 2
00071 };
00072
00073 const Uint16 cPad = 3;
00074
00075 class DLLEXPORT aedWidget:public aedObject
00076 {
00077 typedef std::set<aedWidget*> ChildContainer;
00078
00079 public:
00080 aedWidget();
00081 virtual ~ aedWidget();
00082
00083
00084 aedWidget(Uint16 screenWidth, Uint16 screenHeight, bool takeOverScreen =
00085 true);
00086
00087
00088 virtual void create(aedWidget * parent = NULL, aedRect pos =
00089 aedDEFAULTPOSITION, std::string caption = "");
00090
00091
00092
00093 static bool m_NeedsReRender;
00094 static class aedWidget *last;
00095
00096 void setStatic(bool value)
00097 {
00098 m_IsStatic = value;
00099 }
00100
00101 virtual void enable(bool value)
00102 {
00103 m_IsEnabled = value;
00104 setRenderState(true);
00105 }
00106
00107 void show(void)
00108 {
00109 m_ShowWidget = true;
00110 setRenderState(true);
00111 }
00112 void hide(void)
00113 {
00114 m_ShowWidget = false;
00115 if(getParent())
00116 getParent()->setRenderState(true);
00117 }
00118 bool isVisible(void) const
00119 {
00120 return m_ShowWidget;
00121 }
00122 bool isLPressed(void) const
00123 {
00124 return m_isLPressed;
00125 }
00126 bool isRPressed(void) const
00127 {
00128 return m_isRPressed;
00129 }
00130 void bringToTop(void);
00131 bool hasFocus() const;
00132 aedWidget *getTopMostWidget();
00133
00134
00135 Uint16 getScreenWidth(void) const
00136 {
00137 return m_ScreenWidth;
00138 }
00139 Uint16 getScreenHeight(void) const
00140 {
00141 return m_ScreenHeight;
00142 }
00143 void setPos(Sint16 x, Sint16 y);
00144 void setSize(Sint16 w, Sint16 h);
00145
00146 void screenToClient(Uint16 & x, Uint16 & y);
00147 Uint16 clientxToScreen(Uint16 x = 0);
00148 Uint16 clientyToScreen(Uint16 y = 0);
00149 Sint32 clientwToScreen(Sint32 w = 0);
00150 Sint32 clienthToScreen(Sint32 h = 0);
00151
00152 aedRect getPositionOffset(void);
00153 aedRect getPos(void);
00154 aedRect getPosition(void);
00155 aedRect getMyTranslatedPosition(void);
00156 aedRect getRealPos(void)
00157 {
00158 return getMyPosition();
00159 }
00160
00161 void setFakeOffset(aedRect fakeOffset);
00162 aedRect getFakeOffset(void);
00163
00164
00165 bool getRenderState(void) const
00166 {
00167 return m_ReRender;
00168 }
00169 void setRenderState(bool status)
00170 {
00171 m_ReRender = status;
00172 if(m_ReRender)
00173 {
00174 makeAllDirty();
00175 aedWidget::m_NeedsReRender = true;
00176 }
00177 }
00178
00179 static bool GetReRender()
00180 {
00181 return aedWidget::m_NeedsReRender;
00182 }
00183
00184 static void ClearReRender()
00185 {
00186 aedWidget::m_NeedsReRender = false;
00187 }
00188
00189 static widget_deleted_callback_t m_WidgetDeletedCallback;
00190
00191 static void setWidgetDeletedFun(widget_deleted_callback_t callback)
00192 {
00193 aedWidget::m_WidgetDeletedCallback = callback;
00194 }
00195
00196 void renderAll(SDL_Surface * screen = NULL);
00197
00198 virtual void render(void);
00199 aedColor getBGColor(void) const
00200 {
00201 return m_BGColor;
00202 }
00203
00204 void setBGColor(aedColor color)
00205 {
00206 m_BGColor = color;
00207 }
00208
00209 void setSolidRender(bool solid)
00210 {
00211 m_SolidRender = solid;
00212 if (m_Surface)
00213 {
00214 SDL_FreeSurface(m_Surface);
00215 m_Surface = NULL;
00216 }
00217 }
00218
00219 void setColorKey(Uint32 color)
00220 {
00221 setSolidRender(true);
00222 m_ColorKeyColor = color;
00223 m_ColorKey = true;
00224 }
00225
00226 void setActiveBorder(bool value)
00227 {
00228 m_HasActiveBorder = value;
00229 }
00230 bool getActiveBorder(void) const
00231 {
00232 return m_HasActiveBorder;
00233 }
00234
00235 void setAlphaValue(Uint8 alpha);
00236 Uint8 getAlphaValue(void) const
00237 {
00238 return m_AlphaValue;
00239 }
00240
00241 bool isMouseOver(void);
00242
00243
00244 virtual void setCaption(const std::string & caption)
00245 {
00246 m_Caption = caption;
00247 }
00248 virtual std::string getCaption(void) const
00249 {
00250 return m_Caption;
00251 }
00252
00253
00254 int getBorder() const
00255 {
00256 return m_Border;
00257 }
00258 void setBorder(int border)
00259 {
00260 if(m_Border != border)
00261 {
00262 m_Border = border;
00263 setRenderState(true);
00264 }
00265 }
00266
00267 aedColor getBorderColor() const
00268 {
00269 return m_BorderColor;
00270 }
00271 void setBorderColor(aedColor color)
00272 {
00273 m_BorderColor = color;
00274 setRenderState(true);
00275 }
00276
00277 void setFont(aedFont * font)
00278 {
00279 m_Font = font;
00280 setRenderState(true);
00281 }
00282 aedFont *getFont() const
00283 {
00284 return m_Font;
00285 }
00286
00287 void setTheme(aedTheme * Theme);
00288
00289 aedTheme *getTheme() const
00290 {
00291 return m_Theme;
00292 }
00293
00294 aedWidget *findWidget(const std::string & id);
00295 aedWidget *findWidget(aedWidget * pointer);
00296 virtual bool addWidget(aedWidget * win);
00297 virtual bool removeWidget(aedWidget * win);
00298 aedWidget *getParent() const
00299 {
00300 return m_Parent;
00301 }
00302
00303
00304 virtual int wm_paint(SDL_Surface * screen = NULL, Uint16 x = 0, Uint16 y =
00305 0, Uint16 w = 0, Uint16 h = 0);
00306 virtual int wm_lbuttondown(Uint16 x, Uint16 y);
00307 virtual int wm_lbuttonup(Uint16 x, Uint16 y);
00308 virtual int wm_rbuttondown(Uint16 x, Uint16 y);
00309 virtual int wm_rbuttonup(Uint16 x, Uint16 y);
00310 virtual int wm_sizechanged(Uint16 screenWidth, Uint16 screenHeight);
00311 virtual int wm_keydown(aedKeyEvent & event);
00312 virtual int wm_update(Uint32 msdelta);
00313 virtual int wm_gotfocus()
00314 {
00315 return 0;
00316 }
00317 virtual int wm_lostfocus()
00318 {
00319 return 0;
00320 }
00321 virtual int wm_mouseenter()
00322 {
00323 return 0;
00324 }
00325 virtual int wm_mouseleave()
00326 {
00327 return 0;
00328 }
00329 virtual int wm_mousemove(Uint16 x, Uint16 y, Uint16 dx, Uint16 dy)
00330 {
00331 return 0;
00332 }
00333
00334 bool isEnabled() const
00335 {
00336 if(getParent())
00337 return m_IsEnabled && getParent()->isEnabled();
00338 return m_IsEnabled;
00339 }
00340 bool canFocus() const
00341 {
00342 return m_CanFocus && isEnabled();
00343 }
00344
00345 void update();
00346
00347 void setId(const std::string & id);
00348
00349 const std::string & getId() const
00350 {
00351 return m_Id;
00352 }
00353
00354 void setUserData(void *userdata)
00355 {
00356 m_userdata = userdata;
00357 }
00358
00359 void *getUserData()
00360 {
00361 return m_userdata;
00362 }
00363
00364 bool pollEvent(SDL_Event * event);
00365 void processEvent(SDL_Event * event);
00366
00367 protected:
00368 aedRect getMyPosition(void);
00369 void init(void);
00370
00371 private:
00372 aedWidget *findChildAtCoord(Uint16 x, Uint16 y, Uint8 flags = 0);
00373 void makeAllDirty(void);
00374 void updateAllChildren(Uint32 msdelta);
00375 bool tabFocus();
00376 bool tabFocusChildren();
00377 void tabFocusParent();
00378
00379
00380 public:
00381 std::string m_Caption;
00382 bool m_IsEnabled:1;
00383 bool m_IsStatic:1;
00384 bool m_CanFocus:1;
00385 bool m_IsWidget:1;
00386 bool m_ShowWidget:1;
00387 bool m_ReRender:1;
00388 bool m_HasActiveBorder:1;
00389 int m_Border;
00390 aedColor m_BorderColor;
00391 aedColor m_BGColor;
00392
00393 aedFont *m_Font;
00394 aedTheme *m_Theme;
00395
00396
00397 SDL_Surface *m_Surface;
00398 bool m_SolidRender;
00399 Uint32 m_ColorKeyColor;
00400 bool m_ColorKey;
00401
00402 Uint8 m_AlphaValue;
00403 Uint8 m_Flags;
00404
00405
00406 aedRect m_Pos;
00407
00408
00409 aedRect m_PixelPos;
00410
00411
00412 aedRect m_PositionOffset;
00413 aedRect m_FakeOffset;
00414 bool m_isLPressed;
00415 bool m_isRPressed;
00416
00417 private:
00418 std::string m_Id;
00419 void *m_userdata;
00420 aedWidget *m_Parent;
00421
00422 ChildContainer m_Children;
00423 Uint32 m_CurTicks, m_LastTicks;
00424
00425 Uint16 m_ScreenWidth, m_ScreenHeight;
00426 };
00427
00428 #if defined(_MSC_VER)
00429 DLLEXTERN template DLLEXPORT aedFunctor1Arg < stub, aedWidget >;
00430 #endif
00431
00432 #endif