2 // Copyright (C) 2008 by Martin Moracek
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <boost/signal.hpp>
29 #include <boost/utility.hpp>
30 #include <boost/smart_ptr.hpp>
35 # include <unordered_map>
36 #else /* PLATFORM_MSVC */
37 # include <tr1/unordered_map>
38 #endif /* PLATFORM_MSVC */
40 #include "math/volumes.h"
41 #include "input/input.h"
57 typedef boost::shared_ptr
<GuiSkin
> GuiSkinPtr
;
58 typedef boost::shared_ptr
<Canvas
> CanvasPtr
;
59 typedef boost::shared_ptr
<CursorSet
> CursorSetPtr
;
61 typedef boost::shared_ptr
<Gui
> GuiPtr
;
62 typedef boost::weak_ptr
<Gui
> GuiRef
;
66 GuiPtr
CreateInstance(Application
& app
, const CanvasPtr
& canvas
,
67 const std::string
& filename
, const std::string
& skin
);
70 class Gui
: private boost::noncopyable
{
72 static GuiFactory
& Factory(void)
74 static GuiFactory fac
;
81 typedef bool result_type
;
83 template<typename InputIterator
>
84 bool operator () (InputIterator first
, InputIterator last
) const
86 while(first
!= last
) {
97 boost::signal
<void (uint
)> buttonOn
;
98 boost::signal
<void (uint
)> buttonOff
;
99 boost::signal
<bool (char chr
, KeySym sym
), EventCombiner
> keyOn
;
100 boost::signal
<bool (char chr
, KeySym sym
), EventCombiner
> keyOff
;
101 boost::signal
<void (const Vector2f
&)> mouseMove
;
104 Gui(Application
& app
, const CanvasPtr
& cnv
);
107 Application
& GetApplication(void) {return app_
;}
110 Vector2f
GetSize(void) const {return size_
;}
111 Vector2f
GetScaleFactor(void) const;
113 void SetCanvas(const CanvasPtr
& cnv
);
115 const GuiSkinPtr
& GetSkin(void) const {return skin_
;}
116 const Vector3f
GetMousePosition(void) const
117 {return mousePos_
.GetWPosition();};
120 const Widget
* GetRootWidget(void) const {return rootWdg_
;}
121 Widget
* GetRootWidget(void) {return rootWdg_
;}
123 const Widget
* FindWidget(const std::string
& name
) const;
124 Widget
* FindWidget(const std::string
& name
);
126 bool RegisterWidget(Widget
* wdg
, const std::string
& name
);
127 void UnregisterWidget(const std::string
& name
);
130 bool UseSkin(const std::string
& filename
);
131 void ResetSkin(void);
133 // cursor manipulation
134 void ShowCursor(bool on
);
135 void SetCursor(const std::string
& name
);
138 void MouseMove(const Vector2f
& abs
, const Vector2f
& rel
);
139 bool ProcessInput(const InputEvent
& event
);
141 // draws recursively the entire gui
144 void LoadFromFile(const std::string
& filename
);
146 // TODO: drag & drop - StartDrag(dragwidget)
149 typedef std::tr1::unordered_map
<std::string
, Widget
*> WidgetMap
;
155 // dimensions & scaling
156 bool scale_
; /// gui scales to fit the canvas, keeping it's proportions
160 // widget templates & cursor set
162 CursorSetPtr cursors_
;
169 Transformf mousePos_
;
175 const Cursor
* actCursor_
;
176 std::string curName_
;
180 WidgetMap wdgRegistry_
;