GG: GUI.h Source File

GG

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

GUI.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /* GG is a GUI for SDL and OpenGL.
3 Copyright (C) 2003-2008 T. Zachary Laine
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License
7 as published by the Free Software Foundation; either version 2.1
8 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA
19
20 If you do not wish to comply with the terms of the LGPL please
21 contact the author as other terms are available for a fee.
22
23 Zach Laine
24 whatwasthataddress@gmail.com */
25
29 #ifndef _GG_GUI_h_
30 #define _GG_GUI_h_
31
32 #include <GG/Font.h>
33 #include <GG/WndEvent.h>
34
35
36 namespace boost { namespace archive {
37 class xml_oarchive;
38 class xml_iarchive;
39 } }
40
41 namespace GG {
42
43 class Cursor;
44 class Wnd;
45 class EventPumpBase;
46 class ModalEventPump;
47 class PluginInterface;
48 class StyleFactory;
49 class Texture;
50 class Timer;
51 struct GUIImpl;
52
116 class GG_API GUI
117 {
118 private:
119 struct OrCombiner
120 {
121 typedef bool result_type;
122 template<class InIt> bool operator()(InIt first, InIt last) const;
123 };
124
125 public:
127
130 typedef boost::signal<bool (), OrCombiner> AcceleratorSignalType;
132
135 enum EventType {
136 IDLE,
137 KEYPRESS,
138 KEYRELEASE,
139 LPRESS,
140 MPRESS,
141 RPRESS,
142 LRELEASE,
143 MRELEASE,
144 RRELEASE,
145 MOUSEMOVE,
146 MOUSEWHEEL
147 };
148
151 typedef std::set<std::pair<Key, Flags<ModKey> > >::iterator accel_iterator;
152
155 typedef std::set<std::pair<Key, Flags<ModKey> > >::const_iterator const_accel_iterator;
156
158 virtual ~GUI();
159
160
162 const std::string&
163 AppName() const;
164 Wnd* FocusWnd() const;
165 Wnd* GetWindowUnder(const Pt& pt) const;
166 unsigned int DeltaT() const;
167 virtual unsigned int
168 Ticks() const = 0;
169 bool RenderingDragDropWnds() const;
170 bool FPSEnabled() const;
171 double FPS() const;
172 std::string FPSString() const;
173 double MaxFPS() const;
174 virtual X AppWidth() const = 0;
175 virtual Y AppHeight() const = 0;
176 unsigned int ButtonDownRepeatDelay() const;
177 unsigned int ButtonDownRepeatInterval() const;
178 unsigned int DoubleClickInterval() const;
179 unsigned int MinDragTime() const;
180 unsigned int MinDragDistance() const;
181 bool DragDropWnd(const Wnd* wnd) const;
182 bool AcceptedDragDropWnd(const Wnd* wnd) const;
183 bool MouseButtonDown(unsigned int bn) const;
184 Pt MousePosition() const;
185 Pt MouseMovement() const;
186 Flags<ModKey> ModKeys() const;
187 bool MouseLRSwapped() const;
188 const std::map<Key, Key>&
189 KeyMap() const;
190
196 virtual std::set<std::pair<CPSize, CPSize> > FindWords(const std::string& str) const;
197
198 const boost::shared_ptr<StyleFactory>& GetStyleFactory() const;
199
200 bool RenderCursor() const;
201 const boost::shared_ptr<Cursor>& GetCursor() const;
202
204 const_accel_iterator accel_begin() const;
205
207 const_accel_iterator accel_end() const;
208
210 AcceleratorSignalType& AcceleratorSignal(Key key, Flags<ModKey> mod_keys = MOD_KEY_NONE) const;
211
215 void SaveWndAsPNG(const Wnd* wnd, const std::string& filename) const;
217
219 void operator()();
220 virtual void Exit(int code) = 0;
221
225 virtual void HandleSystemEvents() = 0;
226 void HandleGGEvent(EventType event, Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys, const Pt& pos, const Pt& rel);
227
228 void SetFocusWnd(Wnd* wnd);
229 virtual void Wait(unsigned int ms);
230 void Register(Wnd* wnd);
231 void RegisterModal(Wnd* wnd);
232 void Remove(Wnd* wnd);
233 void WndDying(Wnd* wnd);
234 void MoveUp(Wnd* wnd);
235 void MoveDown(Wnd* wnd);
236
237 virtual boost::shared_ptr<ModalEventPump>
238 CreateModalEventPump(bool& done);
239
246 void RegisterDragDropWnd(Wnd* wnd, const Pt& offset, Wnd* originating_wnd);
247 void CancelDragDrop();
248
249 void RegisterTimer(Timer& timer);
250 void RemoveTimer(Timer& timer);
251
252 virtual void Enter2DMode() = 0;
253 virtual void Exit2DMode() = 0;
254 void EnableFPS(bool b = true);
255 void SetMaxFPS(double max);
256 void EnableMouseButtonDownRepeat(unsigned int delay, unsigned int interval);
257 void SetDoubleClickInterval(unsigned int interval);
258 void SetMinDragTime(unsigned int time);
259 void SetMinDragDistance(unsigned int distance);
260
262 accel_iterator accel_begin();
263
265 accel_iterator accel_end();
266
269 void SetAccelerator(Key key, Flags<ModKey> mod_keys = MOD_KEY_NONE);
270
273 void RemoveAccelerator(Key key, Flags<ModKey> mod_keys = MOD_KEY_NONE);
274
276 void RemoveAccelerator(accel_iterator it);
277
279 void SetMouseLRSwapped(bool swapped = true);
280
282 void SetKeyMap(const std::map<Key, Key>& key_map);
283
286 boost::shared_ptr<Font> GetFont(const std::string& font_filename, unsigned int pts);
287
290 boost::shared_ptr<Font> GetFont(const std::string& font_filename, unsigned int pts,
291 const std::vector<unsigned char>& file_contents);
292
295 template <class CharSetIter>
296 boost::shared_ptr<Font> GetFont(const std::string& font_filename, unsigned int pts,
297 CharSetIter first, CharSetIter last);
298
302 template <class CharSetIter>
303 boost::shared_ptr<Font> GetFont(const std::string& font_filename, unsigned int pts,
304 const std::vector<unsigned char>& file_contents,
305 CharSetIter first, CharSetIter last);
306
308 boost::shared_ptr<Font> GetFont(const boost::shared_ptr<Font>& font, unsigned int pts);
309
312 void FreeFont(const std::string& font_filename, unsigned int pts);
313
317 boost::shared_ptr<Texture> StoreTexture(Texture* texture, const std::string& texture_name);
318
319 boost::shared_ptr<Texture> StoreTexture(const boost::shared_ptr<Texture> &texture, const std::string& texture_name);
320 boost::shared_ptr<Texture> GetTexture(const std::string& name, bool mipmap = false);
321 void FreeTexture(const std::string& name);
322
323 void SetStyleFactory(const boost::shared_ptr<StyleFactory>& factory);
324
325 void RenderCursor(bool render);
326 void SetCursor(const boost::shared_ptr<Cursor>& cursor);
327
328
329 static GUI* GetGUI();
330 static void RenderWindow(Wnd* wnd);
331
333
334 GG_ABSTRACT_EXCEPTION(Exception);
335
338 GG_CONCRETE_EXCEPTION(BadFunctionPointer, GG::GUI, Exception);
340
341 protected:
343 GUI(const std::string& app_name);
344
345
347 void ProcessBrowseInfo();
348 virtual void RenderBegin() = 0;
349 virtual void Render();
350 virtual void RenderEnd() = 0;
351
352 // EventPumpBase interface
353 void SetFPS(double FPS);
354 void SetDeltaT(unsigned int delta_t);
355
356
357 virtual void Run() = 0;
358
359 private:
360 bool ProcessBrowseInfoImpl(Wnd* wnd);
361 Wnd* ModalWindow() const; // returns the current modal window, if any
362
363 // Returns the window under \a pt, sending Mouse{Enter|Leave} or
364 // DragDrop{Enter|Leave} as appropriate
365 Wnd* CheckedGetWindowUnder(const Pt& pt, Flags<ModKey> mod_keys);
366
367 static GUI* s_gui;
368 static boost::shared_ptr<GUIImpl> s_impl;
369
370 friend class EventPumpBase;
371 friend struct GUIImpl;
372 };
373
374
376 GG_API bool MatchesOrContains(const Wnd* lwnd, const Wnd* rwnd);
377
378
379 // template implementations
380 template<class InIt>
381 bool GUI::OrCombiner::operator()(InIt first, InIt last) const
382 {
383 bool retval = false;
384 while (first != last)
385 retval |= static_cast<bool>(*first++);
386 return retval;
387 }
388
389 template <class CharSetIter>
390 boost::shared_ptr<Font> GUI::GetFont(const std::string& font_filename, unsigned int pts,
391 CharSetIter first, CharSetIter last)
392 { return GetFontManager().GetFont(font_filename, pts, first, last); }
393
394 template <class CharSetIter>
395 boost::shared_ptr<Font> GUI::GetFont(const std::string& font_filename, unsigned int pts,
396 const std::vector<unsigned char>& file_contents,
397 CharSetIter first, CharSetIter last)
398 { return GetFontManager().GetFont(font_filename, pts, file_contents, first, last); }
399
400 } // namespace GG
401
402 #endif