Main MRPT website > C++ reference for MRPT 1.5.7
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-2017, 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 
15 
16 using namespace mrpt::graphslam;
17 
19  m_showing_help(false),
20  m_hiding_help(false)
21 {
22  m_help_msg = "User options:\n"
23  " - h/H: Toggle help message\n"
24  " - Alt+Enter: Toggle fullscreen\n"
25  " - Mouse click: Set camera manually\n"
26  " - Ctrl+c: Halt program execution";
27 
28  // register the default keystrokes
29  m_key_codes_to_pressed["h"] = false;
30  m_key_codes_to_pressed["Alt+Enter"] = false;
31  m_key_codes_to_pressed["Ctrl+c"] = false;
32  m_key_codes_to_pressed["mouse_clicked"] = false;
33 
34  std::cout << "WindowObserver initialized." << std::endl;
35 }
36 
37 
39  std::map<std::string, bool>* codes_to_pressed,
40  bool reset_keypresses /*= true */) {
41  *codes_to_pressed = m_key_codes_to_pressed;
42 
43  // reset the code flags
44  if (reset_keypresses) {
46  map_it = m_key_codes_to_pressed.begin();
47  map_it != m_key_codes_to_pressed.end();
48  ++map_it ) {
49  map_it->second = false;
50  }
51 }
52 }
53 
55  const std::string key_str,
56  const std::string key_desc) {
57  m_help_msg += std::string("\n") + " - " +
58  key_str + "/" + mrpt::system::upperCase(key_str) +
59  ": " + key_desc;
60 
61  m_key_codes_to_pressed[key_str] = false;
62 }
63 
67  static_cast<const mrpt::utils::mrptEventOnDestroy &>(e);
69  std::cout << "Event received: mrptEventOnDestroy" << std::endl;
70  }
73  static_cast<const mrpt::gui::mrptEventWindowResize &>(e);
74  std::cout << "Resize event received from: " << ev.source_object
75  << ", new size: " << ev.new_width << " x " << ev.new_height << std::endl;
76  }
79  static_cast<const mrpt::gui::mrptEventWindowChar &>(e);
80  std::cout << "Char event received from: " << ev.source_object
81  << ". Char code: " << ev.char_code << " modif: " << ev.key_modifiers << std::endl;;
82 
83  switch (ev.char_code)
84  {
85  case 'h':
86  case 'H':
87  if (!m_showing_help) {
88  m_showing_help = true;
89  std::cout << "h/H was pressed!" << std::endl;
90  }
91  else {
92  m_showing_help = false;
93  m_hiding_help = true;
94  }
95  m_key_codes_to_pressed["h"] = true;
96  break;
97  case 'c':
98  case 'C':
99  //case 3: // <C-c>
100  if (ev.key_modifiers == 8192) {
101  std::cout << "Pressed C-c inside CDisplayWindow3D" << std::endl;
102  m_key_codes_to_pressed["Ctrl+c"] = true;
103  }
104  break;
105 
106  default:
107  // just raise the corresponding flag. Let the class which actually
108  // cares translate the character to its corresponding meaning.
109  // Pressed letter is stored in lower case form only to make it easier
110  // to check afterwards
113  break;
114  }
115 
116  } // end of e.isOftype<mrptEventWindowChar>
118  const mrpt::gui::mrptEventWindowClosed &ev = static_cast<const mrpt::gui::mrptEventWindowClosed &>(e);
119  std::cout << "Window closed event received from: "
120  << ev.source_object<< "\n";
121  }
122  else if (e.isOfType<mrpt::gui::mrptEventMouseDown>()) {
123  const mrpt::gui::mrptEventMouseDown &ev = static_cast<const mrpt::gui::mrptEventMouseDown&>(e);
124  m_key_codes_to_pressed["mouse_clicked"] = true;
125 
126  std::cout << "Mouse down event received from: "
127  << ev.source_object<< "pt: " <<ev.coords.x << "," << ev.coords.y << "\n";
128  }
130  /*
131  * An event sent by an mrpt::opengl::COpenGLViewport AFTER calling the
132  * SCENE OPENGL DRAWING PRIMITIVES and before doing a glSwapBuffers.
133  */
134 
135  //std::cout << "mrpt::opengl::mrpptEventGLPostRender received." << std::endl;
136 
138  0.70f, 0.05f, // x,y (in screen "ratios")
139  0.25f, 0.09f, // width, height (in screen "ratios")
140  "Press 'h' for help",
141  0.02f // text size
142  );
143 
144  // Also showing help?
145  if (m_showing_help || m_hiding_help) {
146  //std::cout << "In the m_showing_help ... if-clause" << std::endl;
147  static const double TRANSP_ANIMATION_TIME_SEC = 0.5;
148 
149  const double show_tim = m_tim_show_start.Tac();
150  const double hide_tim = m_tim_show_end.Tac();
151 
152  const double tranparency = m_hiding_help ?
153  1.0-std::min(1.0,hide_tim/TRANSP_ANIMATION_TIME_SEC)
154  :
155  std::min(1.0,show_tim/TRANSP_ANIMATION_TIME_SEC);
156 
158  0.25f, 0.25f, // x,y (in screen "ratios")
159  0.50f, 0.50f, // width, height (in screen "ratios")
160  m_help_msg.c_str(),
161  0.02f, // text size
162  mrpt::utils::TColor(190,190,190, 200*tranparency), // background
163  mrpt::utils::TColor(0,0,0, 200*tranparency), // border
164  mrpt::utils::TColor(200,0,0, 150*tranparency), // text
165  6.0f, // border width
166  "serif", // text font
167  mrpt::opengl::NICE // text style
168  );
169 
170  if (hide_tim > TRANSP_ANIMATION_TIME_SEC && m_hiding_help) {
171  m_hiding_help = false;
172  }
173  }
174 
175  }
176  else {
177  //std::cout << "Unregistered mrptEvent received\n";
178  }
179 }
180 
181 
An event sent by a window upon resize.
void OPENGL_IMPEXP 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::utils::TColor &back_col=mrpt::utils::TColor(0, 0, 50, 150), const mrpt::utils::TColor &border_col=mrpt::utils::TColor(0, 0, 0, 140), const mrpt::utils::TColor &text_col=mrpt::utils::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:358
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates. ...
void OnEvent(const mrpt::utils::mrptEvent &e)
This virtual function will be called upon receive of any event after starting listening at any CObser...
#define min(a, b)
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:34
Scalar * iterator
Definition: eigen_plugins.h:23
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 programat...
SLAM methods related to graphs of pose constraints.
mrpt::utils::TPixelCoord coords
bool isOfType() const
Definition: mrptEvent.h:43
std::string BASE_IMPEXP lowerCase(const std::string &str)
Returns an lower-case version of a string.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
A RGB color - 8bit.
Definition: TColor.h:26
mrpt::utils::CTicTac m_tim_show_start
An event sent by a window upon a char pressed by the user.
GLsizei const GLchar ** string
Definition: glext.h:3919
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition: mrptEvent.h:58
mrpt::utils::CTicTac m_tim_show_end
mrptKeyModifier key_modifiers
Modifiers (Shift, Control, etc...)
An event sent by an mrpt::opengl::COpenGLViewport after calling the scene OpenGL drawing primitives a...
std::string BASE_IMPEXP 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:40
double Tac()
Stops the stopwatch.
Definition: CTicTac.cpp:92
int char_code
The virtual key code, as defined in <mrpt/gui/keycodes.h> (a replication of wxWidgets key codes)...



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019