MRPT  1.9.9
CDisplayWindowGUI.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 #include "gui-precomp.h" // Precompiled headers
11 
12 #include <mrpt/core/exceptions.h>
15 
16 using namespace mrpt::gui;
17 
18 #if MRPT_HAS_NANOGUI
19 
21  const std::string& caption, unsigned int width, unsigned int height,
22  const CDisplayWindowGUI_Params& p)
23  : nanogui::Screen(
24  Eigen::Vector2i(width, height), caption, p.resizable, p.fullscreen,
25  p.colorBits, p.alphaBits, p.depthBits, p.stencilBits, p.nSamples,
26  p.glMajor, p.glMinor, p.maximized)
27 {
28  // Set MRPT icon:
29  GLFWimage images;
30  images.width = 64;
31  images.height = 64;
32  images.pixels = default_mrpt_glfw_icon();
33 
34 // glfwSetWindowIcon added in glfw 3.2
35 #if GLFW_VERSION_MAJOR > 3 || \
36  (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 2)
37  glfwSetWindowIcon(screen()->glfwWindow(), 1, &images);
38 #endif
39 }
40 
42 {
43  // Close window:
44  nanogui::Screen::setVisible(false);
45 }
46 
48  int key, int scancode, int action, int modifiers)
49 {
50  if (Screen::keyboardEvent(key, scancode, action, modifiers)) return true;
51  // Process special key events?
52  return false;
53 }
54 
56 {
57  // If provided, call the user loop code:
59 
60  // Optional: render background scene.
61  std::lock_guard<std::mutex> lck(background_scene_mtx);
62  if (!background_scene) return;
63 
64  try
65  {
66  // We need the size of the viewport:
67  GLint win_dims[4];
68  glGetIntegerv(GL_VIEWPORT, win_dims);
69 
70  // Set the camera params in the scene:
72  background_scene->getViewport("main");
73  if (!view)
75  "Fatal error: there is no 'main' viewport in the 3D scene!");
76  mrpt::opengl::CCamera& cam = view->getCamera();
78 
79  for (const auto& m_viewport : background_scene->viewports())
80  m_viewport->render(
81  win_dims[2], win_dims[3], win_dims[0], win_dims[1]);
82  }
83  catch (const std::exception& e)
84  {
85  std::cerr << "[CDisplayWindowGUI::drawContents] Exception:\n"
87  }
88 }
89 
90 void CDisplayWindowGUI::resize(unsigned int width, unsigned int height)
91 {
92  Screen::setSize({width, height});
93 }
94 
95 void CDisplayWindowGUI::setPos(int x, int y) { Screen::setPosition({x, y}); }
96 
97 void CDisplayWindowGUI::setWindowTitle(const std::string& str)
98 {
99  Screen::setCaption(str);
100 }
101 
103  const nanogui::Vector2i& p, int button, bool down, int modifiers)
104 {
105  if (!Screen::mouseButtonEvent(p, button, down, modifiers))
106  m_background_canvas.mouseButtonEvent(p, button, down, modifiers);
107 
108  return true;
109 }
110 
112  const nanogui::Vector2i& p, const nanogui::Vector2i& rel, int button,
113  int modifiers)
114 {
115  if (!Screen::mouseMotionEvent(p, rel, button, modifiers))
116  m_background_canvas.mouseMotionEvent(p, rel, button, modifiers);
117 
118  return true;
119 }
120 
122  const nanogui::Vector2i& p, const nanogui::Vector2f& rel)
123 {
124  if (!Screen::scrollEvent(p, rel)) m_background_canvas.scrollEvent(p, rel);
125 
126  return true;
127 }
128 
129 #endif // MRPT_HAS_NANOGUI
virtual bool mouseMotionEvent(const nanogui::Vector2i &p, const nanogui::Vector2i &rel, int button, int modifiers) override
std::function< void(void)> m_loopCallback
mrpt::vision::TCalibrationStereoImageList images
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
void scrollEvent(const nanogui::Vector2i &p, const nanogui::Vector2f &rel)
void resize(unsigned int width, unsigned int height)
Resizes the window.
virtual ~CDisplayWindowGUI() override
void setWindowTitle(const std::string &str)
Changes the window title.
CDisplayWindowGUI(const std::string &caption=std::string(), unsigned int width=400, unsigned int height=300, const CDisplayWindowGUI_Params &p=CDisplayWindowGUI_Params())
void render(const RenderContext &rc) const override
Render does nothing here.
Definition: CCamera.h:93
virtual bool scrollEvent(const nanogui::Vector2i &p, const nanogui::Vector2f &rel) override
internal::NanoGUICanvasHeadless m_background_canvas
Used to keep track of mouse events on the camera.
void setPos(int x, int y)
Changes the position of the window on the screen.
mrpt::opengl::COpenGLScene::Ptr background_scene
void mouseButtonEvent(const nanogui::Vector2i &p, int button, bool down, int modifiers)
virtual void drawContents() override
Additional parameters to change the window behavior and OpenGL context.
virtual bool keyboardEvent(int key, int scancode, int action, int modifiers) override
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Definition: exceptions.cpp:59
unsigned char * default_mrpt_glfw_icon()
Returns the default MRPT icon data, as a 64x64 RGBA (32 bit/pixel) image, compatible with GLFW...
virtual bool mouseButtonEvent(const nanogui::Vector2i &p, int button, bool down, int modifiers) override
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:14
A camera: if added to a scene, the viewpoint defined by this camera will be used instead of the camer...
Definition: CCamera.h:33
void mouseMotionEvent(const nanogui::Vector2i &p, const nanogui::Vector2i &rel, int button, int modifiers)
mrpt::opengl::CCamera & updateCameraParams(mrpt::opengl::CCamera &cam) const
This function gets a reference to mrpt::opengl::CCamera and updates the camera parameters(pointing, zoom, azimuth, elevation, IsProjective, FOV)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 3a26b90fd Wed Mar 25 20:17:03 2020 +0100 at miƩ mar 25 23:05:41 CET 2020