OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gl_canvas.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_GUI_GL_CANVAS_HH
20 #define OST_GUI_GL_CANVAS_HH
21 
22 #include <ost/gfx/glwin_base.hh>
23 #include <ost/gui/tools/tool.hh>
24 #include <ost/gfx/input.hh>
25 
26 // Qt includes must come last
27 #include <QOpenGLWindow>
28 #include <QSurfaceFormat>
29 
30 // forward declaration
31 class QResizeEvent;
32 class QOpenGLFramebufferObject;
33 class QOpenGLContext;
34 class QOffscreenSurface;
35 
36 namespace ost { namespace gui {
37 
38 class GLCanvas : public QOpenGLWindow, public gfx::GLWinBase {
39  Q_OBJECT;
40 
41 public:
42  GLCanvas();
43  virtual ~GLCanvas();
44 
45  // gfx::GLWinBase interface
46  virtual void MakeActive();
47  virtual void DoRefresh() {this->update(); }
48  virtual void StatusMessage(const String& m);
49  virtual bool HasStereo() const {return format().stereo();};
50  virtual bool HasMultisample() const {return format().samples() > 1;}
51 
52  // QSurfaceFormat for GL context setup
53  void SetDefaultFormat();
54  void SetStereoFormat();
55 
56  // central point for sending input to the gfx layer
57  void OnTransform(gfx::InputCommand, int indx,
59 
60  void SetTestMode(bool f);
61 
62  // Grab images from framebuffer and dump to disk
63  virtual void Export(const String& fname, unsigned int width,
64  unsigned int height, bool transparent);
65 
66  virtual void Export(const String& fname, unsigned int width,
67  unsigned int height, int max_samples, bool transparent);
68 
69  virtual void Export(const String& fname, bool transparent);
70 
71 signals:
72  void CustomContextMenuRequested(const QPoint& point);
73 
74 protected:
75 
76  // QOpenGLWindow interface
77  virtual void initializeGL();
78  virtual void paintGL();
79  virtual void resizeGL(int w, int h);
80 
81  // event handling
82  virtual void mouseMoveEvent(QMouseEvent* event);
83  virtual void mousePressEvent(QMouseEvent* event);
84  virtual void mouseReleaseEvent(QMouseEvent* event);
85  virtual void mouseDoubleClickEvent(QMouseEvent* event);
86 
87  virtual void keyPressEvent(QKeyEvent* event);
88  virtual void keyReleaseEvent(QKeyEvent* event);
89  virtual void wheelEvent(QWheelEvent* event);
90  virtual bool event(QEvent* event);
91 
92 private:
93 
94  bool IsToolEvent(QInputEvent* event) const;
95  MouseEvent::Buttons TranslateButtons(Qt::MouseButtons buttons) const;
96  void HandleMousePressEvent(QMouseEvent* event);
97  void HandleMouseReleaseEvent(QMouseEvent* event);
98  void HandleMouseMoveEvent(QMouseEvent* event);
99 
100  QPoint last_pos_;
101  bool show_beacon_;
102  bool bench_flag_;
103 
104  // for image export
105  bool offscreen_flag_;
106  QOpenGLContext* offscreen_context_;
107  QOffscreenSurface* offscreen_surface_;
108  QOpenGLFramebufferObject* offscreen_fbo_;
109 };
110 
111 }} // ns
112 
113 #endif
virtual void MakeActive()
virtual void mouseDoubleClickEvent(QMouseEvent *event)
virtual bool HasMultisample() const
Definition: gl_canvas.hh:50
std::string String
Definition: base.hh:54
float Real
Definition: base.hh:44
virtual void keyPressEvent(QKeyEvent *event)
virtual void keyReleaseEvent(QKeyEvent *event)
virtual void mouseReleaseEvent(QMouseEvent *event)
virtual bool event(QEvent *event)
virtual void mousePressEvent(QMouseEvent *event)
virtual void mouseMoveEvent(QMouseEvent *event)
void SetTestMode(bool f)
virtual void DoRefresh()
Definition: gl_canvas.hh:47
virtual void wheelEvent(QWheelEvent *event)
void CustomContextMenuRequested(const QPoint &point)
TransformTarget
Definition: input.hh:57
virtual void paintGL()
virtual void initializeGL()
virtual void resizeGL(int w, int h)
virtual bool HasStereo() const
Definition: gl_canvas.hh:49
virtual void StatusMessage(const String &m)
InputCommand
Definition: input.hh:39
void OnTransform(gfx::InputCommand, int indx, gfx::TransformTarget, Real val)
virtual void Export(const String &fname, unsigned int width, unsigned int height, bool transparent)