WIN_XY.CPP 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. // win_xy.c -- windows specific xy view code
  19. #include "stdafx.h"
  20. #include "qe3.h"
  21. static HDC s_hdcXY;
  22. static HGLRC s_hglrcXY;
  23. static unsigned s_stipple[32] =
  24. {
  25. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  26. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  27. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  28. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  29. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  30. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  31. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  32. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  33. };
  34. /*
  35. ============
  36. WXY_WndProc
  37. ============
  38. */
  39. LONG WINAPI XYWndProc (
  40. HWND hWnd,
  41. UINT uMsg,
  42. WPARAM wParam,
  43. LPARAM lParam)
  44. {
  45. int fwKeys, xPos, yPos;
  46. RECT rect;
  47. GetClientRect(hWnd, &rect);
  48. switch (uMsg)
  49. {
  50. case WM_CREATE:
  51. s_hdcXY = GetDC(hWnd);
  52. QEW_SetupPixelFormat(s_hdcXY, false);
  53. if ( ( s_hglrcXY = wglCreateContext( s_hdcXY ) ) == 0 )
  54. Error( "wglCreateContext in WXY_WndProc failed" );
  55. if (!wglMakeCurrent( s_hdcXY, s_hglrcXY ))
  56. Error ("wglMakeCurrent failed");
  57. if (!wglShareLists( g_qeglobals.d_hglrcBase, s_hglrcXY ) )
  58. Error( "wglShareLists in WXY_WndProc failed" );
  59. glPolygonStipple ((unsigned char *)s_stipple);
  60. glLineStipple (3, 0xaaaa);
  61. return 0;
  62. case WM_DESTROY:
  63. QEW_StopGL( hWnd, s_hglrcXY, s_hdcXY );
  64. return 0;
  65. case WM_PAINT:
  66. {
  67. PAINTSTRUCT ps;
  68. BeginPaint(hWnd, &ps);
  69. if (!wglMakeCurrent( s_hdcXY, s_hglrcXY ))
  70. Error ("wglMakeCurrent failed");
  71. QE_CheckOpenGLForErrors();
  72. XY_Draw ();
  73. QE_CheckOpenGLForErrors();
  74. SwapBuffers(s_hdcXY);
  75. EndPaint(hWnd, &ps);
  76. }
  77. return 0;
  78. case WM_KEYDOWN:
  79. return QE_KeyDown (wParam);
  80. case WM_MBUTTONDOWN:
  81. case WM_RBUTTONDOWN:
  82. case WM_LBUTTONDOWN:
  83. if ( GetTopWindow( g_qeglobals.d_hwndMain ) != hWnd)
  84. BringWindowToTop(hWnd);
  85. SetFocus( g_qeglobals.d_hwndXY );
  86. SetCapture( g_qeglobals.d_hwndXY );
  87. fwKeys = wParam; // key flags
  88. xPos = (short)LOWORD(lParam); // horizontal position of cursor
  89. yPos = (short)HIWORD(lParam); // vertical position of cursor
  90. yPos = (int)rect.bottom - 1 - yPos;
  91. XY_MouseDown (xPos, yPos, fwKeys);
  92. return 0;
  93. case WM_MBUTTONUP:
  94. case WM_RBUTTONUP:
  95. case WM_LBUTTONUP:
  96. fwKeys = wParam; // key flags
  97. xPos = (short)LOWORD(lParam); // horizontal position of cursor
  98. yPos = (short)HIWORD(lParam); // vertical position of cursor
  99. yPos = (int)rect.bottom - 1 - yPos;
  100. XY_MouseUp (xPos, yPos, fwKeys);
  101. if (! (fwKeys & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  102. ReleaseCapture ();
  103. return 0;
  104. case WM_MOUSEMOVE:
  105. if (::GetFocus() != hWnd)
  106. ::SetFocus(hWnd);
  107. fwKeys = wParam; // key flags
  108. xPos = (short)LOWORD(lParam); // horizontal position of cursor
  109. yPos = (short)HIWORD(lParam); // vertical position of cursor
  110. yPos = (int)rect.bottom - 1 - yPos;
  111. XY_MouseMoved (xPos, yPos, fwKeys);
  112. return 0;
  113. case WM_SIZE:
  114. g_qeglobals.d_xy.width = rect.right;
  115. g_qeglobals.d_xy.height = rect.bottom - 16;
  116. InvalidateRect( g_qeglobals.d_hwndXY, NULL, false);
  117. return 0;
  118. case WM_NCCALCSIZE:// don't let windows copy pixels
  119. DefWindowProc (hWnd, uMsg, wParam, lParam);
  120. return WVR_REDRAW;
  121. case WM_KILLFOCUS:
  122. case WM_SETFOCUS:
  123. SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
  124. return 0;
  125. case WM_CLOSE:
  126. DestroyWindow (hWnd);
  127. return 0;
  128. }
  129. return DefWindowProc (hWnd, uMsg, wParam, lParam);
  130. }
  131. /*
  132. ==============
  133. WXY_Create
  134. ==============
  135. */
  136. void WXY_Create (HINSTANCE hInstance)
  137. {
  138. ASSERT(0);
  139. #if 0
  140. WNDCLASS wc;
  141. /* Register the camera class */
  142. memset (&wc, 0, sizeof(wc));
  143. wc.style = CS_NOCLOSE;
  144. wc.lpfnWndProc = (WNDPROC)WXY_WndProc;
  145. wc.cbClsExtra = 0;
  146. wc.cbWndExtra = 0;
  147. wc.hInstance = hInstance;
  148. wc.hIcon = 0;
  149. wc.hCursor = LoadCursor (NULL,IDC_ARROW);
  150. wc.hbrBackground = NULL; //(HBRUSH)(COLOR_WINDOW+1);
  151. wc.lpszMenuName = NULL;
  152. wc.lpszClassName = XY_WINDOW_CLASS;
  153. if (!RegisterClass (&wc) )
  154. Error ("RegisterClass: failed");
  155. g_qeglobals.d_hwndXY = CreateWindow (XY_WINDOW_CLASS ,
  156. "XY View",
  157. QE3_STYLE ,
  158. ZWIN_WIDTH,
  159. (int)(screen_height*CWIN_SIZE)-20,
  160. screen_width-ZWIN_WIDTH,
  161. (int)(screen_height*(1.0-CWIN_SIZE)-38), // size
  162. g_qeglobals.d_hwndMain, // parent
  163. 0, // no menu
  164. hInstance,
  165. NULL);
  166. if (!g_qeglobals.d_hwndXY )
  167. Error ("Couldn't create XY View");
  168. LoadWindowState(g_qeglobals.d_hwndXY, "xywindow");
  169. ShowWindow(g_qeglobals.d_hwndXY, SW_SHOWDEFAULT);
  170. #endif
  171. }
  172. static void WXY_InitPixelFormat( PIXELFORMATDESCRIPTOR *pPFD )
  173. {
  174. memset( pPFD, 0, sizeof( *pPFD ) );
  175. pPFD->nSize = sizeof( PIXELFORMATDESCRIPTOR );
  176. pPFD->nVersion = 1;
  177. pPFD->dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
  178. pPFD->iPixelType = PFD_TYPE_RGBA;
  179. pPFD->cColorBits = 24;
  180. pPFD->cDepthBits = 32;
  181. pPFD->iLayerType = PFD_MAIN_PLANE;
  182. }
  183. void WXY_Print( void )
  184. {
  185. DOCINFO di;
  186. PRINTDLG pd;
  187. /*
  188. ** initialize the PRINTDLG struct and execute it
  189. */
  190. memset( &pd, 0, sizeof( pd ) );
  191. pd.lStructSize = sizeof( pd );
  192. pd.hwndOwner = g_qeglobals.d_hwndXY;
  193. pd.Flags = PD_RETURNDC;
  194. pd.hInstance = 0;
  195. if ( !PrintDlg( &pd ) || !pd.hDC )
  196. {
  197. MessageBox( g_qeglobals.d_hwndMain, "Could not PrintDlg()", "QE4 Print Error", MB_OK | MB_ICONERROR );
  198. return;
  199. }
  200. /*
  201. ** StartDoc
  202. */
  203. memset( &di, 0, sizeof( di ) );
  204. di.cbSize = sizeof( di );
  205. di.lpszDocName = "QE4";
  206. if ( StartDoc( pd.hDC, &di ) <= 0 )
  207. {
  208. MessageBox( g_qeglobals.d_hwndMain, "Could not StartDoc()", "QE4 Print Error", MB_OK | MB_ICONERROR );
  209. return;
  210. }
  211. /*
  212. ** StartPage
  213. */
  214. if ( StartPage( pd.hDC ) <= 0 )
  215. {
  216. MessageBox( g_qeglobals.d_hwndMain, "Could not StartPage()", "QE4 Print Error", MB_OK | MB_ICONERROR );
  217. return;
  218. }
  219. /*
  220. ** read pixels from the XY window
  221. */
  222. {
  223. int bmwidth = 320, bmheight = 320;
  224. int pwidth, pheight;
  225. RECT r;
  226. GetWindowRect( g_qeglobals.d_hwndXY, &r );
  227. bmwidth = r.right - r.left;
  228. bmheight = r.bottom - r.top;
  229. pwidth = GetDeviceCaps( pd.hDC, PHYSICALWIDTH ) - GetDeviceCaps( pd.hDC, PHYSICALOFFSETX );
  230. pheight = GetDeviceCaps( pd.hDC, PHYSICALHEIGHT ) - GetDeviceCaps( pd.hDC, PHYSICALOFFSETY );
  231. StretchBlt( pd.hDC,
  232. 0, 0,
  233. pwidth, pheight,
  234. s_hdcXY,
  235. 0, 0,
  236. bmwidth, bmheight,
  237. SRCCOPY );
  238. }
  239. /*
  240. ** EndPage and EndDoc
  241. */
  242. if ( EndPage( pd.hDC ) <= 0 )
  243. {
  244. MessageBox( g_qeglobals.d_hwndMain, "QE4 Print Error", "Could not EndPage()", MB_OK | MB_ICONERROR );
  245. return;
  246. }
  247. if ( EndDoc( pd.hDC ) <= 0 )
  248. {
  249. MessageBox( g_qeglobals.d_hwndMain, "QE4 Print Error", "Could not EndDoc()", MB_OK | MB_ICONERROR );
  250. return;
  251. }
  252. }