ASPiK SDK
copenglview.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #ifndef __copenglview__
6 #define __copenglview__
7 
8 #include "cview.h"
9 #include "iscalefactorchangedlistener.h"
10 #include "platform/iplatformopenglview.h"
11 
12 #if VSTGUI_OPENGL_SUPPORT
13 
14 namespace VSTGUI {
15 
16 /*
17 TODO: Documentation
18 
19  To setup OpenGL for a normal 2D matrix use this to setup the OpenGL context:
20 
21  CRect r (getViewSize ());
22  glViewport (0, 0, r.getWidth (), r.getHeight ());
23  gluOrtho2D (r.left, r.right, r.bottom, r.top);
24  glTranslated (r.left, r.top, 0);
25 
26 */
27 //-----------------------------------------------------------------------------
28 // COpenGLView Declaration
31 //-----------------------------------------------------------------------------
32 class COpenGLView : public CView, public IOpenGLView, public IScaleFactorChangedListener
33 {
34 public:
35  explicit COpenGLView (const CRect& size);
36  ~COpenGLView () noexcept override;
37 
38  // IOpenGLView
39  void drawOpenGL (const CRect& updateRect) override = 0;
40  void reshape () override;
41 
42  // CView
43  void setViewSize (const CRect& rect, bool invalid = true) override;
44  void parentSizeChanged () override;
45  bool removed (CView* parent) override;
46  bool attached (CView* parent) override;
47  void invalidRect (const CRect& rect) override;
48  void setVisible (bool state) override;
49 
50  // IScaleFactorChangedListener
51  void onScaleFactorChanged (CFrame* frame, double newScaleFactor) override;
52 
53  CLASS_METHODS_NOCOPY (COpenGLView, CView)
54 protected:
55  //-----------------------------------------------------------------------------
57  //-----------------------------------------------------------------------------
59  virtual void platformOpenGLViewCreated () {}
60  virtual void platformOpenGLViewWillDestroy () {}
61  virtual void platformOpenGLViewSizeChanged () {}
62  virtual PixelFormat* getPixelFormat () { return 0; }
63  IPlatformOpenGLView* getPlatformOpenGLView () const { return platformOpenGLView; }
65 
66 private:
67  void updatePlatformOpenGLViewSize ();
68  bool createPlatformOpenGLView ();
69  bool destroyPlatformOpenGLView ();
70 
71  double scaleFactor {1.};
72 
73  SharedPointer<IPlatformOpenGLView> platformOpenGLView;
74 };
75 
76 } // namespace
77 
78 #endif // VSTGUI_OPENGL_SUPPORT
79 #endif // __copenglview__
virtual void platformOpenGLViewWillDestroy()
will be called before the platform opengl view will be destroyed
Definition: copenglview.h:60
Rect structure.
Definition: crect.h:17
void parentSizeChanged() override
notification that one of the views parent has changed its size
Definition: copenglview.cpp:97
virtual void platformOpenGLViewSizeChanged()
will be called whenever the platform opengl view size has changed
Definition: copenglview.h:61
void setVisible(bool state) override
set visibility state
Definition: copenglview.cpp:140
Definition: customcontrols.cpp:8
Base Class of all view objects.
Definition: cview.h:44
void drawOpenGL(const CRect &updateRect) override=0
will be called when the view was marked invalid or the view was resized
void setViewSize(const CRect &rect, bool invalid=true) override
set views size
Definition: copenglview.cpp:83
Definition: iscalefactorchangedlistener.h:13
bool removed(CView *parent) override
view is removed from parent view
Definition: copenglview.cpp:133
a subview which uses OpenGL for drawing
Definition: copenglview.h:32
virtual void invalid()
mark whole view as invalid
Definition: cview.h:63
The CFrame is the parent container of all views.
Definition: cframe.h:32
virtual void platformOpenGLViewCreated()
will be called after the platform opengl view was created
Definition: copenglview.h:59
bool attached(CView *parent) override
view is attached to a parent view
Definition: copenglview.cpp:123
virtual PixelFormat * getPixelFormat()
subclasses should return a pixelformat here if they don&#39;t want to use the default one ...
Definition: copenglview.h:62
void invalidRect(const CRect &rect) override
mark rect as invalid
Definition: copenglview.cpp:160