00001
00002
00003
00004
00005
00006
00007
00009
00018 #ifndef __GUI_HEADER__
00019 #define __GUI_HEADER__
00020
00021 #include "defs.h"
00022 #include "utils.h"
00023 #include "screen_rect.h"
00024 #include "image.h"
00025 #include "text.h"
00026
00027 namespace hoa_video {
00028
00029 namespace private_video {
00030
00032 const uint32 FPS_SAMPLES = 250;
00033
00035 const uint32 MAX_FTIME_DIFF = 5;
00036
00038 const uint32 FPS_CATCHUP = 20;
00039
00041 extern GUISupervisor* GUIManager;
00042
00047 class GUIElement {
00048 public:
00049 GUIElement();
00050
00052 virtual ~GUIElement()
00053 {}
00054
00056 virtual void Draw() = 0;
00057
00061 virtual void Update(uint32 frame_time) = 0;
00062
00069 virtual bool IsInitialized(std::string &errors) = 0;
00070
00076 void SetPosition(float x, float y)
00077 { _x_position = x; _y_position = y; }
00078
00083 void SetAlignment(int32 xalign, int32 yalign);
00084
00090 void GetPosition(float &x, float &y) const
00091 { x = _x_position; y = _y_position; }
00092
00097 void GetAlignment(int32 &xalign, int32 &yalign) const
00098 { xalign = _xalign; yalign = _yalign; }
00099
00109 virtual void CalculateAlignedRect(float &left, float &right, float &bottom, float &top);
00110
00111 protected:
00113 int32 _xalign, _yalign;
00114
00116 float _x_position, _y_position;
00117
00120 bool _initialized;
00121
00123 std::string _initialization_errors;
00124 };
00125
00126
00132 class GUIControl : public GUIElement {
00133 public:
00134 GUIControl()
00135 { _owner = NULL; }
00136
00137 virtual ~GUIControl()
00138 {}
00139
00148 virtual void SetOwner(MenuWindow *owner_window)
00149 { _owner = owner_window; }
00150
00151 protected:
00156 MenuWindow *_owner;
00157
00167 virtual void CalculateAlignedRect(float &left, float &right, float &bottom, float &top);
00168 };
00169
00170
00179 class GUISupervisor : public hoa_utils::Singleton<GUISupervisor> {
00180 friend class hoa_utils::Singleton<GUISupervisor>;
00181 public:
00182 GUISupervisor();
00183 ~GUISupervisor();
00184 bool SingletonInitialize();
00185
00204 bool LoadMenuSkin(std::string skin_name, std::string border_image, std::string background_image = "",
00205 Color top_left = Color::clear, Color top_right = Color::clear, Color bottom_left = Color::clear,
00206 Color bottom_right = Color::clear, bool make_default = false);
00207
00217 void DeleteMenuSkin(std::string& skin_name);
00218
00220 MenuSkin* GetDefaultMenuSkin() const
00221 { return _default_skin; }
00222
00227 MenuSkin* GetMenuSkin(std::string& skin_name)
00228 { if (_menu_skins.find(skin_name) == _menu_skins.end()) return NULL; else return &(_menu_skins[skin_name]); }
00229
00237 void SetDefaultMenuSkin(std::string& skin_name);
00238
00243 uint32 GetNextMenuWindowID()
00244 { _next_window_id++; return (_next_window_id - 1); }
00245
00250 void AddMenuWindow(MenuWindow* new_window);
00251
00256 void RemoveMenuWindow(MenuWindow* old_window);
00257
00265 void DrawFPS(uint32 frame_time);
00266
00267 private:
00273 std::map<std::string, MenuSkin> _menu_skins;
00274
00280 std::map<uint32, MenuWindow*> _menu_windows;
00281
00286 MenuSkin* _default_skin;
00287
00289 uint32 _next_window_id;
00290
00292 uint32 _fps_samples[FPS_SAMPLES];
00293
00297 uint32 _fps_sum;
00298
00300 uint32 _current_sample;
00301
00307 uint32 _number_samples;
00308 };
00309
00310 }
00311
00312 }
00313
00314 #endif // __GUI_HEADER__