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 PuglFocusFunc focusFunc; 41 PuglFileSelectedFunc fileSelectedFunc; 42 43 PuglInternals* impl; 44 45 int width; 46 int height; 47 int min_width; 48 int min_height; 49 int mods; 50 bool mouse_in_view; 51 bool ignoreKeyRepeat; 52 bool redisplay; 53 bool user_resizable; 54 bool set_window_hints; 55 bool ontop; 56 bool resize; 57 uint32_t event_timestamp_ms; 58 }; 59 60 void 61 puglSetHandle(PuglView* view, PuglHandle handle) 62 { 63 view->handle = handle; 64 } 65 66 PuglHandle 67 puglGetHandle(PuglView* view) 68 { 69 return view->handle; 70 } 71 72 uint32_t 73 puglGetEventTimestamp(PuglView* view) 74 { 75 return view->event_timestamp_ms; 76 } 77 78 int 79 puglGetModifiers(PuglView* view) 80 { 81 return view->mods; 82 } 83 84 static void 85 puglDefaultReshape(PuglView* view, int width, int height) 86 { 87 glViewport(0, 0, width, height); 88 glMatrixMode(GL_PROJECTION); 89 glLoadIdentity(); 90 glOrtho (-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); 91 glClear (GL_COLOR_BUFFER_BIT); 92 93 glMatrixMode(GL_MODELVIEW); 94 glLoadIdentity(); 95 } 96 97 void 98 puglIgnoreKeyRepeat(PuglView* view, bool ignore) 99 { 100 view->ignoreKeyRepeat = ignore; 101 } 102 103 void 104 puglSetCloseFunc(PuglView* view, PuglCloseFunc closeFunc) 105 { 106 view->closeFunc = closeFunc; 107 } 108 109 void 110 puglSetDisplayFunc(PuglView* view, PuglDisplayFunc displayFunc) 111 { 112 view->displayFunc = displayFunc; 113 } 114 115 void 116 puglSetKeyboardFunc(PuglView* view, PuglKeyboardFunc keyboardFunc) 117 { 118 view->keyboardFunc = keyboardFunc; 119 } 120 121 void 122 puglSetMotionFunc(PuglView* view, PuglMotionFunc motionFunc) 123 { 124 view->motionFunc = motionFunc; 125 } 126 127 void 128 puglSetMouseFunc(PuglView* view, PuglMouseFunc mouseFunc) 129 { 130 view->mouseFunc = mouseFunc; 131 } 132 133 void 134 puglSetReshapeFunc(PuglView* view, PuglReshapeFunc reshapeFunc) 135 { 136 view->reshapeFunc = reshapeFunc; 137 } 138 139 void 140 puglSetResizeFunc(PuglView* view, PuglResizeFunc resizeFunc) 141 { 142 view->resizeFunc = resizeFunc; 143 } 144 145 void 146 puglSetScrollFunc(PuglView* view, PuglScrollFunc scrollFunc) 147 { 148 view->scrollFunc = scrollFunc; 149 } 150 151 void 152 puglSetSpecialFunc(PuglView* view, PuglSpecialFunc specialFunc) 153 { 154 view->specialFunc = specialFunc; 155 } 156 157 void 158 puglSetFocusFunc(PuglView* view, PuglFocusFunc focusFunc) 159 { 160 view->focusFunc = focusFunc; 161 } 162 163 void 164 puglSetFileSelectedFunc(PuglView* view, PuglFileSelectedFunc fileSelectedFunc) 165 { 166 view->fileSelectedFunc = fileSelectedFunc; 167 } 168