00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00029 #ifndef _GG_GUI_h_
00030 #define _GG_GUI_h_
00031
00032 #include <GG/Font.h>
00033 #include <GG/WndEvent.h>
00034
00035
00036 namespace boost { namespace archive {
00037 class xml_oarchive;
00038 class xml_iarchive;
00039 } }
00040
00041 namespace GG {
00042
00043 class Cursor;
00044 class Wnd;
00045 class EventPumpBase;
00046 class ModalEventPump;
00047 class PluginInterface;
00048 class StyleFactory;
00049 class Texture;
00050 class Timer;
00051 struct GUIImpl;
00052
00116 class GG_API GUI
00117 {
00118 private:
00119 struct OrCombiner
00120 {
00121 typedef bool result_type;
00122 template<class InIt> bool operator()(InIt first, InIt last) const;
00123 };
00124
00125 public:
00127
00130 typedef boost::signal<bool (), OrCombiner> AcceleratorSignalType;
00132
00135 enum EventType {
00136 IDLE,
00137 KEYPRESS,
00138 KEYRELEASE,
00139 LPRESS,
00140 MPRESS,
00141 RPRESS,
00142 LRELEASE,
00143 MRELEASE,
00144 RRELEASE,
00145 MOUSEMOVE,
00146 MOUSEWHEEL
00147 };
00148
00151 typedef std::set<std::pair<Key, Flags<ModKey> > >::iterator accel_iterator;
00152
00155 typedef std::set<std::pair<Key, Flags<ModKey> > >::const_iterator const_accel_iterator;
00156
00158 typedef void (*SaveWndFn)(const Wnd* wnd, const std::string& name, boost::archive::xml_oarchive& ar);
00159
00161 typedef void (*LoadWndFn)(Wnd*& wnd, const std::string& name, boost::archive::xml_iarchive& ar);
00162
00164 virtual ~GUI();
00165
00166
00168 const std::string&
00169 AppName() const;
00170 Wnd* FocusWnd() const;
00171 Wnd* GetWindowUnder(const Pt& pt) const;
00172 unsigned int DeltaT() const;
00173 virtual unsigned int
00174 Ticks() const = 0;
00175 bool RenderingDragDropWnds() const;
00176 bool FPSEnabled() const;
00177 double FPS() const;
00178 std::string FPSString() const;
00179 double MaxFPS() const;
00180 virtual X AppWidth() const = 0;
00181 virtual Y AppHeight() const = 0;
00182 unsigned int ButtonDownRepeatDelay() const;
00183 unsigned int ButtonDownRepeatInterval() const;
00184 unsigned int DoubleClickInterval() const;
00185 unsigned int MinDragTime() const;
00186 unsigned int MinDragDistance() const;
00187 bool DragDropWnd(const Wnd* wnd) const;
00188 bool AcceptedDragDropWnd(const Wnd* wnd) const;
00189 bool MouseButtonDown(unsigned int bn) const;
00190 Pt MousePosition() const;
00191 Pt MouseMovement() const;
00192 Flags<ModKey> ModKeys() const;
00193
00199 virtual std::set<std::pair<CPSize, CPSize> > FindWords(const std::string& str) const;
00200
00201 const boost::shared_ptr<StyleFactory>& GetStyleFactory() const;
00202
00203 bool RenderCursor() const;
00204 const boost::shared_ptr<Cursor>& GetCursor() const;
00205
00207 const_accel_iterator accel_begin() const;
00208
00210 const_accel_iterator accel_end() const;
00211
00213 AcceleratorSignalType& AcceleratorSignal(Key key, Flags<ModKey> mod_keys = MOD_KEY_NONE) const;
00215
00217 void operator()();
00218 virtual void Exit(int code) = 0;
00219
00223 virtual void HandleSystemEvents() = 0;
00224 void HandleGGEvent(EventType event, Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys, const Pt& pos, const Pt& rel);
00225
00226 void SetFocusWnd(Wnd* wnd);
00227 virtual void Wait(unsigned int ms);
00228 void Register(Wnd* wnd);
00229 void RegisterModal(Wnd* wnd);
00230 void Remove(Wnd* wnd);
00231 void WndDying(Wnd* wnd);
00232 void MoveUp(Wnd* wnd);
00233 void MoveDown(Wnd* wnd);
00234
00235 virtual boost::shared_ptr<ModalEventPump>
00236 CreateModalEventPump(bool& done);
00237
00244 void RegisterDragDropWnd(Wnd* wnd, const Pt& offset, Wnd* originating_wnd);
00245 void CancelDragDrop();
00246
00247 void RegisterTimer(Timer& timer);
00248 void RemoveTimer(Timer& timer);
00249
00250 virtual void Enter2DMode() = 0;
00251 virtual void Exit2DMode() = 0;
00252 void EnableFPS(bool b = true);
00253 void SetMaxFPS(double max);
00254 void EnableMouseButtonDownRepeat(unsigned int delay, unsigned int interval);
00255 void SetDoubleClickInterval(unsigned int interval);
00256 void SetMinDragTime(unsigned int time);
00257 void SetMinDragDistance(unsigned int distance);
00258
00260 accel_iterator accel_begin();
00261
00263 accel_iterator accel_end();
00264
00267 void SetAccelerator(Key key, Flags<ModKey> mod_keys = MOD_KEY_NONE);
00268
00271 void RemoveAccelerator(Key key, Flags<ModKey> mod_keys = MOD_KEY_NONE);
00272
00274 void RemoveAccelerator(accel_iterator it);
00275
00278 boost::shared_ptr<Font> GetFont(const std::string& font_filename, unsigned int pts);
00279
00282 boost::shared_ptr<Font> GetFont(const std::string& font_filename, unsigned int pts,
00283 const std::vector<unsigned char>& file_contents);
00284
00287 template <class CharSetIter>
00288 boost::shared_ptr<Font> GetFont(const std::string& font_filename, unsigned int pts,
00289 CharSetIter first, CharSetIter last);
00290
00294 template <class CharSetIter>
00295 boost::shared_ptr<Font> GetFont(const std::string& font_filename, unsigned int pts,
00296 const std::vector<unsigned char>& file_contents,
00297 CharSetIter first, CharSetIter last);
00298
00300 boost::shared_ptr<Font> GetFont(const boost::shared_ptr<Font>& font, unsigned int pts);
00301
00304 void FreeFont(const std::string& font_filename, unsigned int pts);
00305
00309 boost::shared_ptr<Texture> StoreTexture(Texture* texture, const std::string& texture_name);
00310
00311 boost::shared_ptr<Texture> StoreTexture(const boost::shared_ptr<Texture> &texture, const std::string& texture_name);
00312 boost::shared_ptr<Texture> GetTexture(const std::string& name, bool mipmap = false);
00313 void FreeTexture(const std::string& name);
00314
00315 void SetStyleFactory(const boost::shared_ptr<StyleFactory>& factory);
00316
00317 void RenderCursor(bool render);
00318 void SetCursor(const boost::shared_ptr<Cursor>& cursor);
00319
00324 void SaveWnd(const Wnd* wnd, const std::string& name, boost::archive::xml_oarchive& ar);
00325
00330 void LoadWnd(Wnd*& wnd, const std::string& name, boost::archive::xml_iarchive& ar);
00331
00335 template <class T>
00336 void LoadWnd(T*& wnd, const std::string& name, boost::archive::xml_iarchive& ar);
00337
00338 void SetSaveWndFunction(SaveWndFn fn);
00339 void SetLoadWndFunction(LoadWndFn fn);
00340
00343 void SetSaveLoadFunctions(const PluginInterface& interface);
00345
00346 static GUI* GetGUI();
00347 static void RenderWindow(Wnd* wnd);
00348
00350
00351 GG_ABSTRACT_EXCEPTION(Exception);
00352
00355 GG_CONCRETE_EXCEPTION(BadFunctionPointer, GG::GUI, Exception);
00357
00358 protected:
00360 GUI(const std::string& app_name);
00361
00362
00364 void ProcessBrowseInfo();
00365 virtual void RenderBegin() = 0;
00366 virtual void Render();
00367 virtual void RenderEnd() = 0;
00368
00369
00370 void SetFPS(double FPS);
00371 void SetDeltaT(unsigned int delta_t);
00372
00373
00374 virtual void Run() = 0;
00375
00376 private:
00377 bool ProcessBrowseInfoImpl(Wnd* wnd);
00378 Wnd* ModalWindow() const;
00379
00380
00381
00382 Wnd* CheckedGetWindowUnder(const Pt& pt, Flags<ModKey> mod_keys);
00383
00384 static GUI* s_gui;
00385 static boost::shared_ptr<GUIImpl> s_impl;
00386
00387 friend class EventPumpBase;
00388 friend struct GUIImpl;
00389 };
00390
00391
00393 GG_API bool MatchesOrContains(const Wnd* lwnd, const Wnd* rwnd);
00394
00395
00396
00397 template<class InIt>
00398 bool GUI::OrCombiner::operator()(InIt first, InIt last) const
00399 {
00400 bool retval = false;
00401 while (first != last)
00402 retval |= static_cast<bool>(*first++);
00403 return retval;
00404 }
00405
00406 template <class CharSetIter>
00407 boost::shared_ptr<Font> GUI::GetFont(const std::string& font_filename, unsigned int pts,
00408 CharSetIter first, CharSetIter last)
00409 { return GetFontManager().GetFont(font_filename, pts, first, last); }
00410
00411 template <class CharSetIter>
00412 boost::shared_ptr<Font> GUI::GetFont(const std::string& font_filename, unsigned int pts,
00413 const std::vector<unsigned char>& file_contents,
00414 CharSetIter first, CharSetIter last)
00415 { return GetFontManager().GetFont(font_filename, pts, file_contents, first, last); }
00416
00417 template <class T>
00418 void GUI::LoadWnd(T*& wnd, const std::string& name, boost::archive::xml_iarchive& ar)
00419 {
00420 Wnd* wnd_as_base = wnd;
00421 LoadWnd(wnd_as_base, name, ar);
00422 wnd = dynamic_cast<T*>(wnd_as_base);
00423 assert(wnd || !wnd_as_base);
00424 }
00425
00426 }
00427
00428 #endif // _GG_GUI_h_