MRPT  1.9.9
CWindowObserver.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 // Implementation file for CWindowObserver class
11 #include "graphslam-precomp.h" // Precompiled headers
12 
16 #include <mrpt/opengl/gl_utils.h>
17 
18 using namespace mrpt::graphslam;
19 
20 CWindowObserver::CWindowObserver() : m_showing_help(false), m_hiding_help(false)
21 {
22  m_help_msg =
23  "User options:\n"
24  " - h/H: Toggle help message\n"
25  " - Alt+Enter: Toggle fullscreen\n"
26  " - Mouse click: Set camera manually\n"
27  " - Ctrl+c: Halt program execution";
28 
29  // register the default keystrokes
30  m_key_codes_to_pressed["h"] = false;
31  m_key_codes_to_pressed["Alt+Enter"] = false;
32  m_key_codes_to_pressed["Ctrl+c"] = false;
33  m_key_codes_to_pressed["mouse_clicked"] = false;
34 
35  std::cout << "WindowObserver initialized." << std::endl;
36 }
37 
39  std::map<std::string, bool>* codes_to_pressed,
40  bool reset_keypresses /*= true */)
41 {
42  *codes_to_pressed = m_key_codes_to_pressed;
43 
44  // reset the code flags
45  if (reset_keypresses)
46  {
48  m_key_codes_to_pressed.begin();
49  map_it != m_key_codes_to_pressed.end(); ++map_it)
50  {
51  map_it->second = false;
52  }
53  }
54 }
55 
57  const std::string key_str, const std::string key_desc)
58 {
59  m_help_msg += std::string("\n") + " - " + key_str + "/" +
60  mrpt::system::upperCase(key_str) + ": " + key_desc;
61 
62  m_key_codes_to_pressed[key_str] = false;
63 }
64 
66 {
68  {
70  static_cast<const mrpt::system::mrptEventOnDestroy&>(e);
72  std::cout << "Event received: mrptEventOnDestroy" << std::endl;
73  }
75  {
77  static_cast<const mrpt::gui::mrptEventWindowResize&>(e);
78  std::cout << "Resize event received from: " << ev.source_object
79  << ", new size: " << ev.new_width << " x " << ev.new_height
80  << std::endl;
81  }
83  {
85  static_cast<const mrpt::gui::mrptEventWindowChar&>(e);
86  std::cout << "Char event received from: " << ev.source_object
87  << ". Char code: " << ev.char_code
88  << " modif: " << ev.key_modifiers << std::endl;
89  ;
90 
91  switch (ev.char_code)
92  {
93  case 'h':
94  case 'H':
95  if (!m_showing_help)
96  {
97  m_showing_help = true;
98  std::cout << "h/H was pressed!" << std::endl;
99  }
100  else
101  {
102  m_showing_help = false;
103  m_hiding_help = true;
104  }
105  m_key_codes_to_pressed["h"] = true;
106  break;
107  case 'c':
108  case 'C':
109  // case 3: // <C-c>
110  if (ev.key_modifiers == 8192)
111  {
112  std::cout << "Pressed C-c inside CDisplayWindow3D"
113  << std::endl;
114  m_key_codes_to_pressed["Ctrl+c"] = true;
115  }
116  break;
117 
118  default:
119  // just raise the corresponding flag. Let the class which
120  // actually
121  // cares translate the character to its corresponding meaning.
122  // Pressed letter is stored in lower case form only to make it
123  // easier
124  // to check afterwards
126  std::string(1, ev.char_code))] = true;
127  break;
128  }
129 
130  } // end of e.isOftype<mrptEventWindowChar>
132  {
134  static_cast<const mrpt::gui::mrptEventWindowClosed&>(e);
135  std::cout << "Window closed event received from: " << ev.source_object
136  << "\n";
137  }
139  {
141  static_cast<const mrpt::gui::mrptEventMouseDown&>(e);
142  m_key_codes_to_pressed["mouse_clicked"] = true;
143 
144  std::cout << "Mouse down event received from: " << ev.source_object
145  << "pt: " << ev.coords.x << "," << ev.coords.y << "\n";
146  }
148  {
149  /*
150  * An event sent by an mrpt::opengl::COpenGLViewport AFTER calling
151  * the
152  * SCENE OPENGL DRAWING PRIMITIVES and before doing a glSwapBuffers.
153  */
154 
155  // std::cout << "mrpt::opengl::mrpptEventGLPostRender received." <<
156  // std::endl;
157 
159  0.70f, 0.05f, // x,y (in screen "ratios")
160  0.25f, 0.09f, // width, height (in screen "ratios")
161  "Press 'h' for help",
162  0.02f // text size
163  );
164 
165  // Also showing help?
167  {
168  // std::cout << "In the m_showing_help ... if-clause" << std::endl;
169  static const double TRANSP_ANIMATION_TIME_SEC = 0.5;
170 
171  const double show_tim = m_tim_show_start.Tac();
172  const double hide_tim = m_tim_show_end.Tac();
173 
174  const double tranparency =
176  ? 1.0 - std::min(1.0, hide_tim / TRANSP_ANIMATION_TIME_SEC)
177  : std::min(1.0, show_tim / TRANSP_ANIMATION_TIME_SEC);
178 
180  0.25f, 0.25f, // x,y (in screen "ratios")
181  0.50f, 0.50f, // width, height (in screen "ratios")
182  m_help_msg.c_str(),
183  0.02f, // text size
185  190, 190, 190, 200 * tranparency), // background
186  mrpt::img::TColor(0, 0, 0, 200 * tranparency), // border
187  mrpt::img::TColor(200, 0, 0, 150 * tranparency), // text
188  6.0f, // border width
189  "serif", // text font
190  mrpt::opengl::NICE // text style
191  );
192 
193  if (hide_tim > TRANSP_ANIMATION_TIME_SEC && m_hiding_help)
194  {
195  m_hiding_help = false;
196  }
197  }
198  }
199  else
200  {
201  // std::cout << "Unregistered mrptEvent received\n";
202  }
203 }
An event sent by a window upon resize.
void OnEvent(const mrpt::system::mrptEvent &e)
This virtual function will be called upon receive of any event after starting listening at any CObser...
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:90
Scalar * iterator
Definition: eigen_plugins.h:26
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates. ...
#define min(a, b)
mrpt::system::CTicTac m_tim_show_end
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:32
void returnEventsStruct(std::map< std::string, bool > *codes_to_pressed, bool reset_keypresses=true)
Return a map of key code to a boolean indicating whether it was pressed since the previous time the c...
void registerKeystroke(const std::string key_str, const std::string key_desc)
Make new keystrokes available in the help message box.
An event sent by a window upon when it&#39;s about to be closed, either manually by the user or programma...
SLAM methods related to graphs of pose constraints.
std::string lowerCase(const std::string &str)
Returns an lower-case version of a string.
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition: mrptEvent.h:66
An event sent by a window upon a char pressed by the user.
mrpt::system::CTicTac m_tim_show_start
GLsizei const GLchar ** string
Definition: glext.h:4101
void renderMessageBox(const float msg_x, const float msg_y, const float msg_w, const float msg_h, const std::string &text, float text_scale, const mrpt::img::TColor &back_col=mrpt::img::TColor(0, 0, 50, 150), const mrpt::img::TColor &border_col=mrpt::img::TColor(0, 0, 0, 140), const mrpt::img::TColor &text_col=mrpt::img::TColor(255, 255, 255, 220), const float border_width=4.0f, const std::string &text_font=std::string("sans"), mrpt::opengl::TOpenGLFontStyle text_style=mrpt::opengl::FILL, const double text_spacing=1.5, const double text_kerning=0.1)
Draws a message box with a centered (possibly multi-lined) text.
Definition: gl_utils.cpp:387
mrptKeyModifier key_modifiers
Modifiers (Shift, Control, etc...)
bool isOfType() const
Definition: mrptEvent.h:41
An event sent by an mrpt::opengl::COpenGLViewport after calling the scene OpenGL drawing primitives a...
std::string upperCase(const std::string &str)
Returns a upper-case version of a string.
std::map< std::string, bool > m_key_codes_to_pressed
Map from registered char_code (std::string to support <C-c>) to boolean true/false indicating whether...
renders glyphs filled with antialiased outlines
Definition: opengl_fonts.h:38
A RGB color - 8bit.
Definition: TColor.h:20
mrpt::img::TPixelCoord coords
int char_code
The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes)...
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020