All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIOverlay.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Nate Koenig
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef _GUI_OVERLAY_HH_
19 #define _GUI_OVERLAY_HH_
20 
21 #include <string>
22 #include <map>
23 #include <vector>
24 
25 #include "rendering/cegui.h"
26 #include "common/MouseEvent.hh"
27 #include "common/Events.hh"
28 
29 #include "math/MathTypes.hh"
30 
31 #include "rendering/RenderTypes.hh"
32 #include "msgs/MessageTypes.hh"
34 
35 namespace Ogre
36 {
37  class RenderTarget;
38 }
39 
40 #ifdef HAVE_CEGUI
41 namespace CEGUI
42 {
43  class OgreRenderer;
44  class Window;
45 }
46 #endif
47 
48 namespace gazebo
49 {
50  namespace rendering
51  {
54 
57  class GUIOverlay
58  {
60  public: GUIOverlay();
61 
63  public: virtual ~GUIOverlay();
64 
68  public: void Init(Ogre::RenderTarget *_renderTarget);
69 
71  public: void Hide();
72 
74  public: void Show();
75 
77  public: void Update();
78 
81  public: bool IsInitialized();
82 
91  public: void CreateWindow(const std::string &_type,
92  const std::string &_name,
93  const std::string &_parent,
94  const math::Vector2d &_position,
95  const math::Vector2d &_size,
96  const std::string &_text);
97 
101  public: bool HandleMouseEvent(const common::MouseEvent &_evt);
102 
106  public: bool HandleKeyPressEvent(const std::string &_key);
107 
111  public: bool HandleKeyReleaseEvent(const std::string &_key);
112 
115  public: void LoadLayout(const std::string &_filename);
116 
123  public: bool AttachCameraToImage(CameraPtr &_camera,
124  const std::string &_windowName);
125 
133  public: bool AttachCameraToImage(DepthCameraPtr &_camera,
134  const std::string &_windowName);
135 
137  public: void Resize(unsigned int _width, unsigned int _height);
138 
140  private: void PreRender();
141 
148  public: template<typename T>
149  void ButtonCallback(const std::string &_buttonName,
150  void (T::*_fp)(), T *_obj)
151  {
152 #ifdef HAVE_CEGUI
153  CEGUI::Window *buttonWindow;
154  buttonWindow =
155  CEGUI::WindowManager::getSingletonPtr()->getWindow(
156  _buttonName);
157  buttonWindow->subscribeEvent(CEGUI::PushButton::EventClicked,
158  CEGUI::Event::Subscriber(&GUIOverlay::OnButtonClicked, this));
159 
160  this->callbacks[_buttonName] = boost::bind(_fp, _obj);
161 #endif
162  }
163 
164 #ifdef HAVE_CEGUI
165 
166 
167 
168  public: CEGUI::Window *GetWindow(const std::string &_name);
169 
173  private: CEGUI::Window *LoadLayoutImpl(const std::string &_filename);
174 
178  private: bool OnButtonClicked(const CEGUI::EventArgs &_e);
179 
183  private: int GetKeyCode(const std::string &_unicode);
184 
186  private: CEGUI::OgreRenderer *guiRenderer;
187 #endif
188 
190  private: std::vector<event::ConnectionPtr> connections;
191 
193  private: std::string layoutFilename;
194 
196  private: std::map<std::string, boost::function<void()> > callbacks;
197 
200  private: unsigned int rttImageSetCount;
201 
203  private: bool initialized;
204  };
206  }
207 }
208 #endif