Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

392 lines
10 KiB

  1. /*
  2. * (c) Copyright 1993, Silicon Graphics, Inc.
  3. * ALL RIGHTS RESERVED
  4. * Permission to use, copy, modify, and distribute this software for
  5. * any purpose and without fee is hereby granted, provided that the above
  6. * copyright notice appear in all copies and that both the copyright notice
  7. * and this permission notice appear in supporting documentation, and that
  8. * the name of Silicon Graphics, Inc. not be used in advertising
  9. * or publicity pertaining to distribution of the software without specific,
  10. * written prior permission.
  11. *
  12. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  16. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  21. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24. *
  25. * US Government Users Restricted Rights
  26. * Use, duplication, or disclosure by the Government is subject to
  27. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29. * clause at DFARS 252.227-7013 and/or in similar or successor
  30. * clauses in the FAR or the DOD or NASA FAR Supplement.
  31. * Unpublished-- rights reserved under the copyright laws of the
  32. * United States. Contractor/manufacturer is Silicon Graphics,
  33. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  34. *
  35. * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36. */
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <windows.h>
  41. #include <GL/gl.h>
  42. #include <gl/glaux.h>
  43. #include "tk.h"
  44. #define static
  45. #if defined(__cplusplus) || defined(c_plusplus)
  46. #define class c_class
  47. #endif
  48. static struct {
  49. int keyField;
  50. void (*KeyFunc)(void);
  51. } keyTable[200];
  52. static struct {
  53. int mouseField;
  54. void (*MouseFunc)(AUX_EVENTREC *);
  55. } mouseDownTable[20], mouseUpTable[20], mouseLocTable[20];
  56. static int keyTableCount = 0;
  57. static int mouseDownTableCount = 0;
  58. static int mouseUpTableCount = 0;
  59. static int mouseLocTableCount = 0;
  60. static GLenum displayModeType = 0;
  61. GLenum APIENTRY auxInitWindowAW(LPCSTR title, BOOL bUnicode);
  62. static void DefaultHandleReshape(GLsizei w, GLsizei h)
  63. {
  64. glViewport(0, 0, w, h);
  65. glMatrixMode(GL_PROJECTION);
  66. glLoadIdentity();
  67. glOrtho((GLdouble)0.0, (GLdouble)w, (GLdouble)0.0, (GLdouble)h, (GLdouble)-1.0, (GLdouble)1.0);
  68. glMatrixMode(GL_MODELVIEW);
  69. glLoadIdentity();
  70. }
  71. static void DefaultHandleExpose(GLsizei w, GLsizei h)
  72. {
  73. }
  74. static GLenum MouseLoc(int x, int y, GLenum button)
  75. {
  76. AUX_EVENTREC info;
  77. GLenum flag;
  78. int i;
  79. flag = GL_FALSE;
  80. for (i = 0; i < mouseLocTableCount; i++) {
  81. if ((int)(button & AUX_LEFTBUTTON) == mouseLocTable[i].mouseField) {
  82. info.event = AUX_MOUSELOC;
  83. info.data[AUX_MOUSEX] = x;
  84. info.data[AUX_MOUSEY] = y;
  85. info.data[AUX_MOUSESTATUS] = AUX_LEFTBUTTON;
  86. (*mouseLocTable[i].MouseFunc)(&info);
  87. flag |= GL_TRUE;
  88. }
  89. if ((int)(button & AUX_RIGHTBUTTON) == mouseLocTable[i].mouseField) {
  90. info.event = AUX_MOUSELOC;
  91. info.data[AUX_MOUSEX] = x;
  92. info.data[AUX_MOUSEY] = y;
  93. info.data[AUX_MOUSESTATUS] = AUX_RIGHTBUTTON;
  94. (*mouseLocTable[i].MouseFunc)(&info);
  95. flag |= GL_TRUE;
  96. }
  97. if ((int)(button & AUX_MIDDLEBUTTON) == mouseLocTable[i].mouseField) {
  98. info.event = AUX_MOUSELOC;
  99. info.data[AUX_MOUSEX] = x;
  100. info.data[AUX_MOUSEY] = y;
  101. info.data[AUX_MOUSESTATUS] = AUX_MIDDLEBUTTON;
  102. (*mouseLocTable[i].MouseFunc)(&info);
  103. flag |= GL_TRUE;
  104. }
  105. }
  106. return flag;
  107. }
  108. static GLenum MouseUp(int x, int y, GLenum button)
  109. {
  110. AUX_EVENTREC info;
  111. GLenum flag;
  112. int i;
  113. flag = GL_FALSE;
  114. for (i = 0; i < mouseUpTableCount; i++) {
  115. if ((int)(button & AUX_LEFTBUTTON) == mouseUpTable[i].mouseField) {
  116. info.event = AUX_MOUSEUP;
  117. info.data[AUX_MOUSEX] = x;
  118. info.data[AUX_MOUSEY] = y;
  119. info.data[AUX_MOUSESTATUS] = AUX_LEFTBUTTON;
  120. (*mouseUpTable[i].MouseFunc)(&info);
  121. flag |= GL_TRUE;
  122. }
  123. if ((int)(button & AUX_RIGHTBUTTON) == mouseUpTable[i].mouseField) {
  124. info.event = AUX_MOUSEUP;
  125. info.data[AUX_MOUSEX] = x;
  126. info.data[AUX_MOUSEY] = y;
  127. info.data[AUX_MOUSESTATUS] = AUX_RIGHTBUTTON;
  128. (*mouseUpTable[i].MouseFunc)(&info);
  129. flag |= GL_TRUE;
  130. }
  131. if ((int)(button & AUX_MIDDLEBUTTON) == mouseUpTable[i].mouseField) {
  132. info.event = AUX_MOUSEUP;
  133. info.data[AUX_MOUSEX] = x;
  134. info.data[AUX_MOUSEY] = y;
  135. info.data[AUX_MOUSESTATUS] = AUX_MIDDLEBUTTON;
  136. (*mouseUpTable[i].MouseFunc)(&info);
  137. flag |= GL_TRUE;
  138. }
  139. }
  140. return flag;
  141. }
  142. static GLenum MouseDown(int x, int y, GLenum button)
  143. {
  144. AUX_EVENTREC info;
  145. GLenum flag;
  146. int i;
  147. flag = GL_FALSE;
  148. for (i = 0; i < mouseDownTableCount; i++) {
  149. if ((int)(button & AUX_LEFTBUTTON) == mouseDownTable[i].mouseField) {
  150. info.event = AUX_MOUSEDOWN;
  151. info.data[AUX_MOUSEX] = x;
  152. info.data[AUX_MOUSEY] = y;
  153. info.data[AUX_MOUSESTATUS] = AUX_LEFTBUTTON;
  154. (*mouseDownTable[i].MouseFunc)(&info);
  155. flag |= GL_TRUE;
  156. }
  157. if ((int)(button & AUX_RIGHTBUTTON) == mouseDownTable[i].mouseField) {
  158. info.event = AUX_MOUSEDOWN;
  159. info.data[AUX_MOUSEX] = x;
  160. info.data[AUX_MOUSEY] = y;
  161. info.data[AUX_MOUSESTATUS] = AUX_RIGHTBUTTON;
  162. (*mouseDownTable[i].MouseFunc)(&info);
  163. flag |= GL_TRUE;
  164. }
  165. if ((int)(button & AUX_MIDDLEBUTTON) == mouseDownTable[i].mouseField) {
  166. info.event = AUX_MOUSEDOWN;
  167. info.data[AUX_MOUSEX] = x;
  168. info.data[AUX_MOUSEY] = y;
  169. info.data[AUX_MOUSESTATUS] = AUX_MIDDLEBUTTON;
  170. (*mouseDownTable[i].MouseFunc)(&info);
  171. flag |= GL_TRUE;
  172. }
  173. }
  174. return flag;
  175. }
  176. static GLenum KeyDown(int key, GLenum status)
  177. {
  178. GLenum flag;
  179. int i;
  180. flag = GL_FALSE;
  181. if (keyTableCount) {
  182. for (i = 0; i < keyTableCount; i++) {
  183. if (key == keyTable[i].keyField) {
  184. (*keyTable[i].KeyFunc)();
  185. flag |= GL_TRUE;
  186. }
  187. }
  188. }
  189. return flag;
  190. }
  191. void auxExposeFunc(AUXEXPOSEPROC Func)
  192. {
  193. tkExposeFunc(Func);
  194. }
  195. void auxReshapeFunc(AUXRESHAPEPROC Func)
  196. {
  197. tkExposeFunc((void (*)(int, int))Func);
  198. tkReshapeFunc((void (*)(int, int))Func);
  199. }
  200. void auxIdleFunc(AUXIDLEPROC Func)
  201. {
  202. tkIdleFunc(Func);
  203. }
  204. void auxKeyFunc(int key, AUXKEYPROC Func)
  205. {
  206. keyTable[keyTableCount].keyField = key;
  207. keyTable[keyTableCount++].KeyFunc = Func;
  208. }
  209. void auxMouseFunc(int mouse, int mode, AUXMOUSEPROC Func)
  210. {
  211. if (mode == AUX_MOUSEDOWN) {
  212. mouseDownTable[mouseDownTableCount].mouseField = mouse;
  213. mouseDownTable[mouseDownTableCount++].MouseFunc = Func;
  214. } else if (mode == AUX_MOUSEUP) {
  215. mouseUpTable[mouseUpTableCount].mouseField = mouse;
  216. mouseUpTable[mouseUpTableCount++].MouseFunc = Func;
  217. } else if (mode == AUX_MOUSELOC) {
  218. mouseLocTable[mouseLocTableCount].mouseField = mouse;
  219. mouseLocTable[mouseLocTableCount++].MouseFunc = Func;
  220. }
  221. }
  222. void auxMainLoop(AUXMAINPROC Func)
  223. {
  224. tkDisplayFunc(Func);
  225. tkExec();
  226. }
  227. void auxInitPosition(int x, int y, int width, int height)
  228. {
  229. tkInitPosition(x, y, width, height);
  230. }
  231. void auxInitDisplayMode(GLenum type)
  232. {
  233. displayModeType = type;
  234. tkInitDisplayMode(type);
  235. }
  236. void auxInitDisplayModePolicy(GLenum type)
  237. {
  238. tkInitDisplayModePolicy(type);
  239. }
  240. GLenum auxInitDisplayModeID(GLint id)
  241. {
  242. return tkInitDisplayModeID(id);
  243. }
  244. GLenum APIENTRY auxInitWindowA(LPCSTR title)
  245. {
  246. return auxInitWindowAW(title,FALSE);
  247. }
  248. GLenum APIENTRY auxInitWindowW(LPCWSTR title)
  249. {
  250. return auxInitWindowAW((LPCSTR)title,TRUE);
  251. }
  252. GLenum APIENTRY auxInitWindowAW(LPCSTR title, BOOL bUnicode)
  253. {
  254. int useDoubleAsSingle = 0;
  255. if (tkInitWindowAW((char *)title, bUnicode) == GL_FALSE) {
  256. if (AUX_WIND_IS_SINGLE(displayModeType)) {
  257. tkInitDisplayMode(displayModeType | AUX_DOUBLE);
  258. if (tkInitWindowAW((char *)title, bUnicode) == GL_FALSE) {
  259. return GL_FALSE; /* curses, foiled again */
  260. }
  261. MESSAGEBOX(GetFocus(), "Can't initialize a single buffer visual. "
  262. "Will use a double buffer visual instead, "
  263. "only drawing into the front buffer.",
  264. "Warning", MB_OK);
  265. displayModeType = displayModeType | AUX_DOUBLE;
  266. useDoubleAsSingle = 1;
  267. }
  268. }
  269. tkReshapeFunc((void (*)(int, int))DefaultHandleReshape);
  270. tkExposeFunc((void (*)(int, int))DefaultHandleExpose);
  271. tkMouseUpFunc(MouseUp);
  272. tkMouseDownFunc(MouseDown);
  273. tkMouseMoveFunc(MouseLoc);
  274. tkKeyDownFunc(KeyDown);
  275. auxKeyFunc(AUX_ESCAPE, auxQuit);
  276. glClearColor((GLclampf)0.0, (GLclampf)0.0, (GLclampf)0.0, (GLclampf)1.0);
  277. glClearIndex((GLfloat)0.0);
  278. glLoadIdentity();
  279. if (useDoubleAsSingle)
  280. glDrawBuffer(GL_FRONT);
  281. return GL_TRUE;
  282. }
  283. void auxCloseWindow(void)
  284. {
  285. tkCloseWindow();
  286. keyTableCount = 0;
  287. mouseDownTableCount = 0;
  288. mouseUpTableCount = 0;
  289. mouseLocTableCount = 0;
  290. }
  291. void auxQuit(void)
  292. {
  293. tkQuit();
  294. }
  295. void auxSwapBuffers(void)
  296. {
  297. tkSwapBuffers();
  298. }
  299. HWND auxGetHWND(void)
  300. {
  301. return tkGetHWND();
  302. }
  303. HDC auxGetHDC(void)
  304. {
  305. return tkGetHDC();
  306. }
  307. HGLRC auxGetHGLRC(void)
  308. {
  309. return tkGetHRC();
  310. }
  311. GLenum auxGetDisplayModePolicy(void)
  312. {
  313. return tkGetDisplayModePolicy();
  314. }
  315. GLint auxGetDisplayModeID(void)
  316. {
  317. return tkGetDisplayModeID();
  318. }
  319. GLenum auxGetDisplayMode(void)
  320. {
  321. return tkGetDisplayMode();
  322. }
  323. void auxSetOneColor(int index, float r, float g, float b)
  324. {
  325. tkSetOneColor(index, r, g, b);
  326. }
  327. void auxSetFogRamp(int density, int startIndex)
  328. {
  329. tkSetFogRamp(density, startIndex);
  330. }
  331. void auxSetGreyRamp(void)
  332. {
  333. tkSetGreyRamp();
  334. }
  335. void auxSetRGBMap(int size, float *rgb)
  336. {
  337. tkSetRGBMap(size, rgb);
  338. }
  339. int auxGetColorMapSize(void)
  340. {
  341. return tkGetColorMapSize();
  342. }
  343. void auxGetMouseLoc(int *x, int *y)
  344. {
  345. tkGetMouseLoc(x, y);
  346. }