1 /*
2   Copyright 2012-2015 David Robillard <http://drobilla.net>
3 
4   Permission to use, copy, modify, and/or distribute this software for any
5   purpose with or without fee is hereby granted, provided that the above
6   copyright notice and this permission notice appear in all copies.
7 
8   THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16 
17 /**
18    @file pugl.hpp C++ API for Pugl, a minimal portable API for OpenGL.
19 */
20 
21 #ifndef PUGL_HPP_INCLUDED
22 #define PUGL_HPP_INCLUDED
23 
24 #include "pugl/pugl.h"
25 
26 /**
27    @defgroup puglmm Puglmm
28    C++ API wrapper for Pugl.
29    @{
30 */
31 
32 namespace pugl {
33 
34 class View {
35 public:
View(int * pargc,char ** argv)36 	View(int* pargc, char** argv)
37 		: _view(puglInit(pargc, argv))
38 	{
39 		puglSetHandle(_view, this);
40 		puglSetEventFunc(_view, _onEvent);
41 	}
42 
~View()43 	virtual ~View() { puglDestroy(_view); }
44 
initWindowParent(PuglNativeWindow parent)45 	virtual void initWindowParent(PuglNativeWindow parent) {
46 		puglInitWindowParent(_view, parent);
47 	}
48 
initWindowSize(int width,int height)49 	virtual void initWindowSize(int width, int height) {
50 		puglInitWindowSize(_view, width, height);
51 	}
52 
initWindowMinSize(int width,int height)53 	virtual void initWindowMinSize(int width, int height) {
54 		puglInitWindowMinSize(_view, width, height);
55 	}
56 
initWindowAspectRatio(int min_x,int min_y,int max_x,int max_y)57 	virtual void initWindowAspectRatio(int min_x, int min_y, int max_x, int max_y) {
58 		puglInitWindowAspectRatio(_view, min_x, min_y, max_x, max_y);
59 	}
60 
initResizable(bool resizable)61 	virtual void initResizable(bool resizable) {
62 		puglInitResizable(_view, resizable);
63 	}
64 
initTransientFor(uintptr_t parent)65 	virtual void initTransientFor(uintptr_t parent) {
66 		puglInitTransientFor(_view, parent);
67 	}
68 
initContextType(PuglContextType type)69 	virtual void initContextType(PuglContextType type) {
70 		puglInitContextType(_view, type);
71 	}
72 
createWindow(const char * title)73 	virtual void createWindow(const char* title) {
74 		puglCreateWindow(_view, title);
75 	}
76 
showWindow()77 	virtual void             showWindow()      { puglShowWindow(_view); }
hideWindow()78 	virtual void             hideWindow()      { puglHideWindow(_view); }
getNativeWindow()79 	virtual PuglNativeWindow getNativeWindow() { return puglGetNativeWindow(_view); }
80 
81 	virtual void onEvent(const PuglEvent* event) = 0;
82 
getContext()83 	virtual void*      getContext()                 { return puglGetContext(_view); }
ignoreKeyRepeat(bool ignore)84 	virtual void       ignoreKeyRepeat(bool ignore) { puglIgnoreKeyRepeat(_view, ignore); }
grabFocus()85 	virtual void       grabFocus()                  { puglGrabFocus(_view); }
copyToClipboard(char * selection)86 	virtual void       copyToClipboard(char* selection) { puglCopyToClipboard(_view, selection); }
pasteFromClipboard()87 	virtual const char* pasteFromClipboard()        { return puglPasteFromClipboard(_view); }
waitForEvent()88 	virtual PuglStatus waitForEvent()               { return puglWaitForEvent(_view); }
processEvents()89 	virtual PuglStatus processEvents()              { return puglProcessEvents(_view); }
postRedisplay()90 	virtual void       postRedisplay()              { puglPostRedisplay(_view); }
91 
cobj()92 	PuglView* cobj() { return _view; }
93 
94 private:
_onEvent(PuglView * view,const PuglEvent * event)95 	static void _onEvent(PuglView* view, const PuglEvent* event) {
96 		((View*)puglGetHandle(view))->onEvent(event);
97 	}
98 
99 	PuglView* _view;
100 };
101 
102 }  // namespace pugl
103 
104 /**
105    @}
106 */
107 
108 #endif  /* PUGL_HPP_INCLUDED */
109