1 /*********************************************************** 2 * Copyright (C) 1997, Be Inc. Copyright (C) 1999, Jake Hamby. 3 * 4 * This program is freely distributable without licensing fees 5 * and is provided without guarantee or warrantee expressed or 6 * implied. This program is -not- in the public domain. 7 * 8 * 9 * FILE: glutCallback.cpp 10 * 11 * DESCRIPTION: put all the callback setting routines in 12 * one place 13 ***********************************************************/ 14 15 /*********************************************************** 16 * Headers 17 ***********************************************************/ 18 #include <GL/glut.h> 19 #include "glutint.h" 20 #include "glutState.h" 21 22 /*********************************************************** 23 * Window related callbacks 24 ***********************************************************/ 25 void APIENTRY glutDisplayFunc(GLUTdisplayCB displayFunc)26glutDisplayFunc(GLUTdisplayCB displayFunc) 27 { 28 /* XXX Remove the warning after GLUT 3.0. */ 29 if (!displayFunc) 30 __glutFatalError("NULL display callback not allowed in GLUT 3.0; update your code."); 31 gState.currentWindow->display = displayFunc; 32 } 33 34 void APIENTRY glutKeyboardFunc(GLUTkeyboardCB keyboardFunc)35glutKeyboardFunc(GLUTkeyboardCB keyboardFunc) 36 { 37 gState.currentWindow->keyboard = keyboardFunc; 38 } 39 40 void APIENTRY glutKeyboardUpFunc(GLUTkeyboardCB keyboardUpFunc)41glutKeyboardUpFunc(GLUTkeyboardCB keyboardUpFunc) 42 { 43 gState.currentWindow->keyboardUp = keyboardUpFunc; 44 } 45 46 void APIENTRY glutSpecialFunc(GLUTspecialCB specialFunc)47glutSpecialFunc(GLUTspecialCB specialFunc) 48 { 49 gState.currentWindow->special = specialFunc; 50 } 51 52 void APIENTRY glutSpecialUpFunc(GLUTspecialCB specialUpFunc)53glutSpecialUpFunc(GLUTspecialCB specialUpFunc) 54 { 55 gState.currentWindow->specialUp = specialUpFunc; 56 } 57 58 void APIENTRY glutMouseFunc(GLUTmouseCB mouseFunc)59glutMouseFunc(GLUTmouseCB mouseFunc) 60 { 61 gState.currentWindow->mouse = mouseFunc; 62 } 63 64 void APIENTRY glutMotionFunc(GLUTmotionCB motionFunc)65glutMotionFunc(GLUTmotionCB motionFunc) 66 { 67 gState.currentWindow->motion = motionFunc; 68 } 69 70 void APIENTRY glutPassiveMotionFunc(GLUTpassiveCB passiveMotionFunc)71glutPassiveMotionFunc(GLUTpassiveCB passiveMotionFunc) 72 { 73 gState.currentWindow->passive = passiveMotionFunc; 74 } 75 76 void APIENTRY glutEntryFunc(GLUTentryCB entryFunc)77glutEntryFunc(GLUTentryCB entryFunc) 78 { 79 gState.currentWindow->entry = entryFunc; 80 if (!entryFunc) { 81 gState.currentWindow->entryState = -1; 82 } 83 } 84 85 void APIENTRY glutWindowStatusFunc(GLUTwindowStatusCB windowStatusFunc)86glutWindowStatusFunc(GLUTwindowStatusCB windowStatusFunc) 87 { 88 gState.currentWindow->windowStatus = windowStatusFunc; 89 } 90 91 static void visibilityHelper(int status)92visibilityHelper(int status) 93 { 94 if (status == GLUT_HIDDEN || status == GLUT_FULLY_COVERED) 95 gState.currentWindow->visibility(GLUT_NOT_VISIBLE); 96 else 97 gState.currentWindow->visibility(GLUT_VISIBLE); 98 } 99 100 void APIENTRY glutVisibilityFunc(GLUTvisibilityCB visibilityFunc)101glutVisibilityFunc(GLUTvisibilityCB visibilityFunc) 102 { 103 gState.currentWindow->visibility = visibilityFunc; 104 if (visibilityFunc) 105 glutWindowStatusFunc(visibilityHelper); 106 else 107 glutWindowStatusFunc(NULL); 108 } 109 110 void APIENTRY glutReshapeFunc(GLUTreshapeCB reshapeFunc)111glutReshapeFunc(GLUTreshapeCB reshapeFunc) 112 { 113 if (reshapeFunc) { 114 gState.currentWindow->reshape = reshapeFunc; 115 } else { 116 gState.currentWindow->reshape = __glutDefaultReshape; 117 } 118 } 119 120 /*********************************************************** 121 * General callbacks (timer callback in glutEvent.cpp) 122 ***********************************************************/ 123 /* DEPRICATED, use glutMenuStatusFunc instead. */ 124 void APIENTRY glutMenuStateFunc(GLUTmenuStateCB menuStateFunc)125glutMenuStateFunc(GLUTmenuStateCB menuStateFunc) 126 { 127 gState.menuStatus = (GLUTmenuStatusCB) menuStateFunc; 128 } 129 130 void APIENTRY glutMenuStatusFunc(GLUTmenuStatusCB menuStatusFunc)131glutMenuStatusFunc(GLUTmenuStatusCB menuStatusFunc) 132 { 133 gState.menuStatus = menuStatusFunc; 134 } 135 136 void APIENTRY glutIdleFunc(GLUTidleCB idleFunc)137glutIdleFunc(GLUTidleCB idleFunc) 138 { 139 gState.idle = idleFunc; 140 } 141 142 /*********************************************************** 143 * Unsupported callbacks 144 ***********************************************************/ 145 void APIENTRY glutOverlayDisplayFunc(GLUTdisplayCB displayFunc)146glutOverlayDisplayFunc(GLUTdisplayCB displayFunc) 147 { 148 } 149 150 void APIENTRY glutJoystickFunc(GLUTjoystickCB joystickFunc,int pollInterval)151glutJoystickFunc(GLUTjoystickCB joystickFunc, int pollInterval) 152 { 153 } 154 155 void APIENTRY glutSpaceballMotionFunc(GLUTspaceMotionCB spaceMotionFunc)156glutSpaceballMotionFunc(GLUTspaceMotionCB spaceMotionFunc) 157 { 158 } 159 160 void APIENTRY glutSpaceballRotateFunc(GLUTspaceRotateCB spaceRotateFunc)161glutSpaceballRotateFunc(GLUTspaceRotateCB spaceRotateFunc) 162 { 163 } 164 165 void APIENTRY glutSpaceballButtonFunc(GLUTspaceButtonCB spaceButtonFunc)166glutSpaceballButtonFunc(GLUTspaceButtonCB spaceButtonFunc) 167 { 168 } 169 170 void APIENTRY glutButtonBoxFunc(GLUTbuttonBoxCB buttonBoxFunc)171glutButtonBoxFunc(GLUTbuttonBoxCB buttonBoxFunc) 172 { 173 } 174 175 void APIENTRY glutDialsFunc(GLUTdialsCB dialsFunc)176glutDialsFunc(GLUTdialsCB dialsFunc) 177 { 178 } 179 180 void APIENTRY glutTabletMotionFunc(GLUTtabletMotionCB tabletMotionFunc)181glutTabletMotionFunc(GLUTtabletMotionCB tabletMotionFunc) 182 { 183 } 184 185 void APIENTRY glutTabletButtonFunc(GLUTtabletButtonCB tabletButtonFunc)186glutTabletButtonFunc(GLUTtabletButtonCB tabletButtonFunc) 187 { 188 } 189