Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_GUI_BASICOBJECT_H__
00009 #define __SP_GUI_BASICOBJECT_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #ifdef SP_COMPILE_WITH_GUI
00015
00016
00017 #include "RenderSystem/spRenderSystem.hpp"
00018
00019 #include <boost/function.hpp>
00020
00021
00022 namespace sp
00023 {
00024 namespace gui
00025 {
00026
00027
00028 class GUIWindow;
00029 class GUIMenuItem;
00030 class GUIController;
00031 class GUIGadget;
00032
00033 enum EGUIEventObjects
00034 {
00035 EVENT_WINDOW,
00036 EVENT_GADGET,
00037 EVENT_MENUITEM,
00038 };
00039
00040 enum EGUIEventTypes
00041 {
00042
00043 EVENT_ACTIVATE,
00044 EVENT_FOCUS,
00045 EVENT_LOSTFOCUS,
00046 EVENT_LEFTCLICK,
00047 EVENT_LEFTDOUBLECLICK,
00048 EVENT_RIGHTCLICK,
00049 EVENT_RIGHTDOUBLECLICK,
00050 EVENT_KEYPRESS,
00051 EVENT_MOUSEWHEEL,
00052
00053
00054 EVENT_MINIMIZE,
00055 EVENT_MAXIMIZE,
00056 EVENT_MOVE,
00057 EVENT_RESIZE,
00058 EVENT_CLOSE,
00059 };
00060
00061 struct SGUIEvent
00062 {
00063 SGUIEvent() :
00064 Object (EVENT_WINDOW ),
00065 Type (EVENT_ACTIVATE ),
00066 Window (0 ),
00067 MenuItem(0 ),
00068 SubData (0 ),
00069 KeyCode (io::KEY_RETURN )
00070 {
00071 }
00072 ~SGUIEvent()
00073 {
00074 }
00075
00076
00077
00078 EGUIEventObjects Object;
00079 EGUIEventTypes Type;
00080
00081 GUIWindow* Window;
00082 GUIGadget* Gadget;
00083 GUIMenuItem* MenuItem;
00084
00085 void* SubData;
00086
00087 io::EKeyCodes KeyCode;
00088 };
00089
00090 typedef boost::function<void (const SGUIEvent &Event)> GUIEventCallback;
00091
00092
00093 class SP_EXPORT GUIBaseObject
00094 {
00095
00096 public:
00097
00098 virtual ~GUIBaseObject();
00099
00100
00101
00102 virtual void setFont(video::Font* TextFont);
00103
00104
00105
00106 inline void setID(u32 ID)
00107 {
00108 ID_ = ID;
00109 }
00110 inline u32 getID() const
00111 {
00112 return ID_;
00113 }
00114
00115 inline void setText(const io::stringc &Text)
00116 {
00117 Text_ = Text;
00118 }
00119 inline io::stringc getText() const
00120 {
00121 return Text_;
00122 }
00123
00124 inline void setColor(const video::color &Color)
00125 {
00126 Color_ = Color;
00127 }
00128 inline video::color getColor() const
00129 {
00130 return Color_;
00131 }
00132
00133 inline void setEnable(bool isEnabled)
00134 {
00135 isEnabled_ = isEnabled;
00136 }
00137 inline bool getEnable() const
00138 {
00139 return isEnabled_;
00140 }
00141
00142 inline video::Font* getFont() const
00143 {
00144 return Font_;
00145 }
00146
00147 protected:
00148
00149 friend class GUIManager;
00150
00151
00152
00153 enum EDrawTextFlags
00154 {
00155 DRAWTEXT_CENTER = 0x01,
00156 DRAWTEXT_VCENTER = 0x02,
00157 DRAWTEXT_RIGHT = 0x04,
00158 DRAWTEXT_3D = 0x08,
00159 };
00160
00161
00162
00163 GUIBaseObject();
00164
00165 void drawFrame(
00166 const dim::rect2di &Rect, const video::color &Color, bool isFrame3D
00167 );
00168 void drawFrame(
00169 const dim::rect2di &Rect,
00170 const video::color &ColorA, const video::color &ColorB,
00171 const video::color &ColorC, const video::color &ColorD
00172 );
00173 void drawText(
00174 dim::point2di Pos, const io::stringc &Text, const video::color &Color = 255, s32 Flags = DRAWTEXT_3D
00175 );
00176 void drawButton(
00177 const dim::rect2di &Rect, const video::color &Color = 255, bool isMouseOver = false
00178 );
00179
00180 void drawHatchedFace(const dim::rect2di &Rect);
00181
00182 bool mouseOver(const dim::rect2di &Rect) const;
00183 bool mouseLeft() const;
00184 bool mouseRight() const;
00185 bool mouseLeftUp() const;
00186 bool mouseRightUp() const;
00187 bool mouseLeftDown() const;
00188 bool mouseRightDown() const;
00189
00190 void sendEvent(const EGUIEventObjects ObjectType, const EGUIEventTypes EventType);
00191 void sendEvent(const SGUIEvent &Event);
00192
00193
00194
00195 u32 ID_;
00196
00197 io::stringc Text_;
00198 video::color Color_;
00199 video::Font* Font_;
00200
00201 bool isEnabled_;
00202
00203 };
00204
00205
00206 }
00207
00208 }
00209
00210
00211 #endif
00212
00213 #endif
00214
00215
00216
00217