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 (C) 2012-2014 Open Source Robotics Foundation
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 
25 
26 #include "gazebo/math/Vector2d.hh"
27 
28 #include "gazebo/rendering/cegui.h"
30 
31 namespace Ogre
32 {
33  class RenderTarget;
34 }
35 
36 #ifdef HAVE_CEGUI
37 namespace CEGUI
38 {
39  class OgreRenderer;
40  class Window;
41 }
42 #endif
43 
44 namespace gazebo
45 {
46  namespace rendering
47  {
48  class GUIOverlayPrivate;
49 
52 
55  class GUIOverlay
56  {
58  public: GUIOverlay();
59 
61  public: virtual ~GUIOverlay();
62 
66  public: void Init(Ogre::RenderTarget *_renderTarget);
67 
69  public: void Hide();
70 
72  public: void Show();
73 
75  public: void Update();
76 
79  public: bool IsInitialized();
80 
89  public: void CreateWindow(const std::string &_type,
90  const std::string &_name,
91  const std::string &_parent,
92  const math::Vector2d &_position,
93  const math::Vector2d &_size,
94  const std::string &_text);
95 
99  public: bool HandleMouseEvent(const common::MouseEvent &_evt);
100 
104  public: bool HandleKeyPressEvent(const std::string &_key);
105 
109  public: bool HandleKeyReleaseEvent(const std::string &_key);
110 
113  public: void LoadLayout(const std::string &_filename);
114 
121  public: bool AttachCameraToImage(CameraPtr &_camera,
122  const std::string &_windowName);
123 
131  public: bool AttachCameraToImage(DepthCameraPtr &_camera,
132  const std::string &_windowName);
133 
135  public: void Resize(unsigned int _width, unsigned int _height);
136 
138  private: void PreRender();
139 
143  private: int GetKeyCode(const std::string &_unicode);
144 
145 #ifdef HAVE_CEGUI
146  public: CEGUI::Window *GetWindow(const std::string &_name);
150 
154  private: CEGUI::Window *LoadLayoutImpl(const std::string &_filename);
155 
159  private: bool OnButtonClicked(const CEGUI::EventArgs &_e);
160 #endif
161 
168  public: template<typename T>
169  void ButtonCallback(const std::string &_buttonName,
170  void (T::*_fp)(), T *_obj)
171  {
172 #ifdef HAVE_CEGUI
173  CEGUI::Window *buttonWindow;
174  buttonWindow =
175  CEGUI::WindowManager::getSingletonPtr()->getWindow(
176  _buttonName);
177  buttonWindow->subscribeEvent(CEGUI::PushButton::EventClicked,
178  CEGUI::Event::Subscriber(&GUIOverlay::OnButtonClicked, this));
179 
180  this->callbacks[_buttonName] = boost::bind(_fp, _obj);
181 #else
182  if (_buttonName && _fp && _obj)
183  {
184  gzerr << "CEGUI not installed." << std::endl;
185  }
186 #endif
187  }
188 
190  public: std::map<std::string, boost::function<void()> > callbacks;
191 
194  private: GUIOverlayPrivate *dataPtr;
195  };
197  }
198 }
199 #endif