1 /*
2   Copyright 2012 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_internal.h Private platform-independent definitions.
19 
20    Note this file contains function definitions, so it must be compiled into
21    the final binary exactly once.  Each platform specific implementation file
22    including it once should achieve this.
23 */
24 
25 #include "pugl.h"
26 
27 typedef struct PuglInternalsImpl PuglInternals;
28 
29 struct PuglViewImpl {
30 	PuglHandle       handle;
31 	PuglCloseFunc    closeFunc;
32 	PuglDisplayFunc  displayFunc;
33 	PuglKeyboardFunc keyboardFunc;
34 	PuglMotionFunc   motionFunc;
35 	PuglMouseFunc    mouseFunc;
36 	PuglReshapeFunc  reshapeFunc;
37 	PuglResizeFunc   resizeFunc;
38 	PuglScrollFunc   scrollFunc;
39 	PuglSpecialFunc  specialFunc;
40 	PuglFileSelectedFunc fileSelectedFunc;
41 
42 	PuglInternals* impl;
43 
44 	int      width;
45 	int      height;
46 	int      min_width;
47 	int      min_height;
48 	int      mods;
49 	bool     mouse_in_view;
50 	bool     ignoreKeyRepeat;
51 	bool     redisplay;
52 	bool     user_resizable;
53 	bool     set_window_hints;
54 	bool     ontop;
55 	bool     resize;
56 	uint32_t event_timestamp_ms;
57 };
58 
59 void
puglSetHandle(PuglView * view,PuglHandle handle)60 puglSetHandle(PuglView* view, PuglHandle handle)
61 {
62 	view->handle = handle;
63 }
64 
65 PuglHandle
puglGetHandle(PuglView * view)66 puglGetHandle(PuglView* view)
67 {
68 	return view->handle;
69 }
70 
71 uint32_t
puglGetEventTimestamp(PuglView * view)72 puglGetEventTimestamp(PuglView* view)
73 {
74 	return view->event_timestamp_ms;
75 }
76 
77 int
puglGetModifiers(PuglView * view)78 puglGetModifiers(PuglView* view)
79 {
80 	return view->mods;
81 }
82 
83 static void
puglDefaultReshape(PuglView * view,int width,int height)84 puglDefaultReshape(PuglView* view, int width, int height)
85 {
86 	glViewport(0, 0, width, height);
87 	glMatrixMode(GL_PROJECTION);
88 	glLoadIdentity();
89 	glOrtho (-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
90 	glClear (GL_COLOR_BUFFER_BIT);
91 
92 	glMatrixMode(GL_MODELVIEW);
93 	glLoadIdentity();
94 }
95 
96 void
puglIgnoreKeyRepeat(PuglView * view,bool ignore)97 puglIgnoreKeyRepeat(PuglView* view, bool ignore)
98 {
99 	view->ignoreKeyRepeat = ignore;
100 }
101 
102 void
puglSetCloseFunc(PuglView * view,PuglCloseFunc closeFunc)103 puglSetCloseFunc(PuglView* view, PuglCloseFunc closeFunc)
104 {
105 	view->closeFunc = closeFunc;
106 }
107 
108 void
puglSetDisplayFunc(PuglView * view,PuglDisplayFunc displayFunc)109 puglSetDisplayFunc(PuglView* view, PuglDisplayFunc displayFunc)
110 {
111 	view->displayFunc = displayFunc;
112 }
113 
114 void
puglSetKeyboardFunc(PuglView * view,PuglKeyboardFunc keyboardFunc)115 puglSetKeyboardFunc(PuglView* view, PuglKeyboardFunc keyboardFunc)
116 {
117 	view->keyboardFunc = keyboardFunc;
118 }
119 
120 void
puglSetMotionFunc(PuglView * view,PuglMotionFunc motionFunc)121 puglSetMotionFunc(PuglView* view, PuglMotionFunc motionFunc)
122 {
123 	view->motionFunc = motionFunc;
124 }
125 
126 void
puglSetMouseFunc(PuglView * view,PuglMouseFunc mouseFunc)127 puglSetMouseFunc(PuglView* view, PuglMouseFunc mouseFunc)
128 {
129 	view->mouseFunc = mouseFunc;
130 }
131 
132 void
puglSetReshapeFunc(PuglView * view,PuglReshapeFunc reshapeFunc)133 puglSetReshapeFunc(PuglView* view, PuglReshapeFunc reshapeFunc)
134 {
135 	view->reshapeFunc = reshapeFunc;
136 }
137 
138 void
puglSetResizeFunc(PuglView * view,PuglResizeFunc resizeFunc)139 puglSetResizeFunc(PuglView* view, PuglResizeFunc resizeFunc)
140 {
141 	view->resizeFunc = resizeFunc;
142 }
143 
144 void
puglSetScrollFunc(PuglView * view,PuglScrollFunc scrollFunc)145 puglSetScrollFunc(PuglView* view, PuglScrollFunc scrollFunc)
146 {
147 	view->scrollFunc = scrollFunc;
148 }
149 
150 void
puglSetSpecialFunc(PuglView * view,PuglSpecialFunc specialFunc)151 puglSetSpecialFunc(PuglView* view, PuglSpecialFunc specialFunc)
152 {
153 	view->specialFunc = specialFunc;
154 }
155 
156 void
puglSetFileSelectedFunc(PuglView * view,PuglFileSelectedFunc fileSelectedFunc)157 puglSetFileSelectedFunc(PuglView* view, PuglFileSelectedFunc fileSelectedFunc)
158 {
159 	view->fileSelectedFunc = fileSelectedFunc;
160 }
161