1 ///////////////////////////////////////// 2 // 3 // OpenLieroX 4 // 5 // code under LGPL, based on JasonBs work, 6 // enhanced by Dark Charlie and Albert Zeyer 7 // 8 // 9 ///////////////////////////////////////// 10 11 12 // Widget class 13 // Created 30/5/02 14 // Jason Boettcher 15 16 17 #ifndef __CWIDGET_H__DEPRECATED_GUI__ 18 #define __CWIDGET_H__DEPRECATED_GUI__ 19 20 #include "InputEvents.h" 21 #include "types.h" 22 #ifdef WIN32 23 #include "windows.h" 24 #endif //WIN32 25 #include "SmartPointer.h" 26 27 namespace DeprecatedGUI { 28 29 // Widget messages 30 enum { WDM_SETENABLE = -1 }; 31 32 // Widget types 33 enum WidgetType_t { 34 wid_None=-1, 35 wid_Button=0, 36 wid_Label, 37 wid_Listview, 38 wid_Scrollbar, 39 wid_Slider, 40 wid_Textbox, 41 wid_Titlebutton, 42 wid_Textbutton, 43 wid_Checkbox, 44 wid_Inputbox, 45 wid_Combobox, 46 wid_Image, 47 wid_Frame, 48 wid_Animation, 49 wid_GuiLayout, 50 }; 51 52 class CGuiLayoutBase; 53 54 class CWidget { 55 public: 56 // Constructor CWidget()57 CWidget() { 58 iID = -1; 59 60 iType = wid_None; 61 iX = iY = 0; 62 iWidth = iHeight = 1; 63 bFocused = false; 64 bEnabled = true; 65 bRedrawMenu = true; 66 bCanLoseFocus = true; 67 iKeyboardNavigationOrder = 0; 68 } 69 CWidget(const CWidget &)70 CWidget(const CWidget&) { assert(false); } 71 ~CWidget()72 virtual ~CWidget() 73 { 74 } 75 76 protected: 77 // Attributes 78 79 int iX, iY; 80 int iWidth, iHeight; 81 bool bFocused; 82 WidgetType_t iType; 83 bool bRedrawMenu; 84 bool bCanLoseFocus; 85 86 87 private: 88 int iID; 89 bool bEnabled; 90 int iKeyboardNavigationOrder; 91 92 CGuiLayoutBase *cParent; 93 94 95 public: 96 // Methods 97 98 99 // Widget functions 100 void Setup(int id, int x, int y, int w, int h); 101 bool InBox(int x, int y); 102 103 void redrawBuffer(); 104 getID()105 int getID() { return iID; } setID(int _i)106 void setID(int _i) { iID = _i; } getType()107 WidgetType_t getType() { return iType; } 108 setFocused(bool _f)109 void setFocused(bool _f) { bFocused = _f; } getFocused()110 bool getFocused() { return bFocused; } 111 getEnabled()112 bool getEnabled() { return bEnabled; } setEnabled(bool _e)113 void setEnabled(bool _e) { bEnabled = _e; } 114 getRedrawMenu()115 bool getRedrawMenu() { return bRedrawMenu; } setRedrawMenu(bool _r)116 void setRedrawMenu(bool _r) { bRedrawMenu = _r; } 117 getX()118 int getX() { return iX; } getY()119 int getY() { return iY; } getWidth()120 int getWidth() { return iWidth; } getHeight()121 int getHeight() { return iHeight; } 122 getParent()123 CGuiLayoutBase *getParent() { return cParent; } setParent(CGuiLayoutBase * l)124 void setParent(CGuiLayoutBase *l) { cParent = l; } 125 getKeyboardNavigationOrder()126 int getKeyboardNavigationOrder() const { return iKeyboardNavigationOrder; } 127 // Default order is 0, positive value - widget will be the last, negative value - widget will be the first to be selected, range is between -120 and 120 setKeyboardNavigationOrder(int i)128 void setKeyboardNavigationOrder(int i) { iKeyboardNavigationOrder = i; } 129 CanLoseFocus()130 bool CanLoseFocus() { return bCanLoseFocus; } setLoseFocus(bool _f)131 void setLoseFocus(bool _f) { bCanLoseFocus = _f; } 132 133 134 // Virtual functions 135 virtual void Create() = 0; 136 virtual void Destroy() = 0; 137 138 //These events return an event id, otherwise they return -1 139 virtual int MouseOver(mouse_t *tMouse) = 0; MouseClicked(mouse_t * tMouse,int nDown)140 virtual int MouseClicked(mouse_t *tMouse, int nDown ) { return -1; } 141 virtual int MouseUp(mouse_t *tMouse, int nDown ) = 0; 142 virtual int MouseDown(mouse_t *tMouse, int nDown) = 0; 143 virtual int MouseWheelUp(mouse_t *tMouse ) = 0; 144 virtual int MouseWheelDown(mouse_t *tMouse) = 0; 145 virtual int KeyDown(UnicodeChar c, int keysym, const ModifiersState& modstate) = 0; 146 virtual int KeyUp(UnicodeChar c, int keysym, const ModifiersState& modstate) = 0; 147 148 virtual void Draw(SDL_Surface * bmpDest) = 0; 149 150 virtual DWORD SendMessage(int iMsg, DWORD Param1, DWORD Param2) = 0; 151 virtual DWORD SendMessage(int iMsg, const std::string& sStr, DWORD Param) = 0; 152 virtual DWORD SendMessage(int iMsg, std::string *sStr, DWORD Param) = 0; 153 }; 154 155 // Base class for CGuiLayout and CGuiSkinnedLayout 156 class CGuiLayoutBase 157 { 158 public: ~CGuiLayoutBase()159 virtual ~CGuiLayoutBase() { }; 160 virtual void Add(CWidget *widget, int id, int x, int y, int w, int h) = 0; 161 // Add more functions here if needed 162 }; 163 164 } // namespace DeprecatedGUI 165 166 #endif // __CWIDGET_H__DEPRECATED_GUI__ 167