MRPT  2.0.4
CWindowObserver.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 // Implementation file for CWindowObserver class
11 #include "graphslam-precomp.h" // Precompiled headers
12 
16 
17 using namespace mrpt::graphslam;
18 
20 {
21  m_help_msg =
22  "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 
36  std::map<std::string, bool>* codes_to_pressed,
37  bool reset_keypresses /*= true */)
38 {
39  *codes_to_pressed = m_key_codes_to_pressed;
40 
41  // reset the code flags
42  if (reset_keypresses)
43  {
44  for (auto& map_it : m_key_codes_to_pressed)
45  {
46  map_it.second = false;
47  }
48  }
49 }
50 
52  const std::string key_str, const std::string key_desc)
53 {
54  m_help_msg += std::string("\n") + " - " + key_str + "/" +
55  mrpt::system::upperCase(key_str) + ": " + key_desc;
56 
57  m_key_codes_to_pressed[key_str] = false;
58 }
59 
61 {
63  {
64  const auto& ev =
65  dynamic_cast<const mrpt::system::mrptEventOnDestroy&>(e);
66  (void)ev;
67  std::cout << "Event received: mrptEventOnDestroy" << std::endl;
68  }
70  {
71  const auto& ev =
72  static_cast<const mrpt::gui::mrptEventWindowResize&>(e);
73  std::cout << "Resize event received from: " << ev.source_object
74  << ", new size: " << ev.new_width << " x " << ev.new_height
75  << std::endl;
76  }
78  {
79  const auto& ev = dynamic_cast<const mrpt::gui::mrptEventWindowChar&>(e);
80  std::cout << "Char event received from: " << ev.source_object
81  << ". Char code: " << ev.char_code
82  << " modif: " << ev.key_modifiers << std::endl;
83  ;
84 
85  switch (ev.char_code)
86  {
87  case 'h':
88  case 'H':
89  m_key_codes_to_pressed["h"] = true;
90  break;
91  case 'c':
92  case 'C':
93  // case 3: // <C-c>
94  if (ev.key_modifiers == 8192)
95  {
96  std::cout << "Pressed C-c inside CDisplayWindow3D"
97  << std::endl;
98  m_key_codes_to_pressed["Ctrl+c"] = true;
99  }
100  break;
101 
102  default:
103  // just raise the corresponding flag. Let the class which
104  // actually
105  // cares translate the character to its corresponding meaning.
106  // Pressed letter is stored in lower case form only to make it
107  // easier
108  // to check afterwards
110  std::string(1, ev.char_code))] = true;
111  break;
112  }
113 
114  } // end of e.isOftype<mrptEventWindowChar>
116  {
117  const auto& ev =
118  dynamic_cast<const mrpt::gui::mrptEventWindowClosed&>(e);
119  std::cout << "Window closed event received from: " << ev.source_object
120  << "\n";
121  }
123  {
124  const auto& ev = dynamic_cast<const mrpt::gui::mrptEventMouseDown&>(e);
125  m_key_codes_to_pressed["mouse_clicked"] = true;
126 
127  std::cout << "Mouse down event received from: " << ev.source_object
128  << "pt: " << ev.coords.x << "," << ev.coords.y << "\n";
129  }
131  {
132  /*
133  * An event sent by an mrpt::opengl::COpenGLViewport AFTER calling
134  * the
135  * SCENE OPENGL DRAWING PRIMITIVES and before doing a glSwapBuffers.
136  */
137 
138  // was: show m_help_msg.c_str()
139  }
140 }
An event sent by a window upon resize.
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates. ...
void OnEvent(const mrpt::system::mrptEvent &e) override
This virtual function will be called upon receive of any event after starting listening at any CObser...
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:31
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.
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...



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020