🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
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.

810 lines
18 KiB

  1. #ifdef _WIN32
  2. /*
  3. Copyright (c) 2012 Advanced Micro Devices, Inc.
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. //Originally written by Erwin Coumans
  14. #include "Win32Window.h"
  15. #include "OpenGLInclude.h"
  16. #include <wchar.h>
  17. static InternalData2* sData = 0;
  18. #include "Win32InternalWindowData.h"
  19. enum
  20. {
  21. INTERNAL_SHIFT_MODIFIER=1,
  22. INTERNAL_ALT_MODIFIER=2,
  23. INTERNAL_CONTROL_MODIFIER=4,
  24. };
  25. void Win32Window::pumpMessage()
  26. {
  27. MSG msg;
  28. // check for messages
  29. //'if' instead of 'while' can make mainloop smoother.
  30. //@todo: use separate threads for input and rendering
  31. while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
  32. {
  33. // handle or dispatch messages
  34. if ( msg.message == WM_QUIT )
  35. {
  36. m_data->m_quit = TRUE;
  37. }
  38. else
  39. {
  40. TranslateMessage( &msg );
  41. DispatchMessage( &msg );
  42. }
  43. // gDemoApplication->displayCallback();
  44. };
  45. }
  46. int getSpecialKeyFromVirtualKeycode(int virtualKeyCode)
  47. {
  48. int keycode = -1;
  49. if (virtualKeyCode >= 'A' && virtualKeyCode <= 'Z')
  50. {
  51. return virtualKeyCode+32;//todo: fix the ascii A vs a input
  52. }
  53. switch (virtualKeyCode)
  54. {
  55. case VK_RETURN: {keycode = B3G_RETURN; break; };
  56. case VK_F1: {keycode = B3G_F1; break;}
  57. case VK_F2: {keycode = B3G_F2; break;}
  58. case VK_F3: {keycode = B3G_F3; break;}
  59. case VK_F4: {keycode = B3G_F4; break;}
  60. case VK_F5: {keycode = B3G_F5; break;}
  61. case VK_F6: {keycode = B3G_F6; break;}
  62. case VK_F7: {keycode = B3G_F7; break;}
  63. case VK_F8: {keycode = B3G_F8; break;}
  64. case VK_F9: {keycode = B3G_F9; break;}
  65. case VK_F10: {keycode= B3G_F10; break;}
  66. //case VK_SPACE: {keycode= ' '; break;}
  67. case VK_NEXT: {keycode= B3G_PAGE_DOWN; break;}
  68. case VK_PRIOR: {keycode= B3G_PAGE_UP; break;}
  69. case VK_INSERT: {keycode= B3G_INSERT; break;}
  70. case VK_BACK: {keycode= B3G_BACKSPACE; break;}
  71. case VK_DELETE: {keycode= B3G_DELETE; break;}
  72. case VK_END:{keycode= B3G_END; break;}
  73. case VK_HOME:{keycode= B3G_HOME; break;}
  74. case VK_LEFT:{keycode= B3G_LEFT_ARROW; break;}
  75. case VK_UP:{keycode= B3G_UP_ARROW; break;}
  76. case VK_RIGHT:{keycode= B3G_RIGHT_ARROW; break;}
  77. case VK_DOWN:{keycode= B3G_DOWN_ARROW; break;}
  78. case VK_SHIFT:{keycode=B3G_SHIFT;break;}
  79. case VK_MENU:{keycode=B3G_ALT;break;}
  80. case VK_CONTROL:{keycode=B3G_CONTROL;break;}
  81. default:
  82. {
  83. //keycode = MapVirtualKey( virtualKeyCode, MAPVK_VK_TO_CHAR ) & 0x0000FFFF;
  84. }
  85. };
  86. return keycode;
  87. }
  88. int getAsciiCodeFromVirtualKeycode(int virtualKeyCode)
  89. {
  90. int keycode = 0xffffffff;
  91. if (virtualKeyCode >= 'a' && virtualKeyCode <= 'z')
  92. {
  93. return virtualKeyCode;
  94. }
  95. if (virtualKeyCode >= 'A' && virtualKeyCode <= 'Z')
  96. {
  97. return virtualKeyCode+32;//todo: fix the ascii A vs a input
  98. }
  99. return keycode;
  100. }
  101. bool Win32Window::isModifierKeyPressed(int key)
  102. {
  103. bool isPressed = false;
  104. switch (key)
  105. {
  106. case B3G_ALT:
  107. {
  108. isPressed = ((sData->m_internalKeyModifierFlags&INTERNAL_ALT_MODIFIER)!=0);
  109. break;
  110. };
  111. case B3G_SHIFT:
  112. {
  113. isPressed = ((sData->m_internalKeyModifierFlags&INTERNAL_SHIFT_MODIFIER)!=0);
  114. break;
  115. };
  116. case B3G_CONTROL:
  117. {
  118. isPressed = ((sData->m_internalKeyModifierFlags&INTERNAL_CONTROL_MODIFIER)!=0);
  119. break;
  120. };
  121. default:
  122. {
  123. }
  124. };
  125. return isPressed;//m_internalKeyModifierFlags
  126. }
  127. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  128. {
  129. //printf("msg = %d\n", message);
  130. switch (message)
  131. {
  132. case WM_PAINT:
  133. {
  134. PAINTSTRUCT ps;
  135. BeginPaint(hWnd, &ps);
  136. EndPaint(hWnd, &ps);
  137. }
  138. return 1;
  139. case WM_ERASEBKGND:
  140. return 1;
  141. case WM_CLOSE:
  142. if (sData)
  143. sData->m_quit = true;
  144. //PostQuitMessage(0);
  145. return 1;
  146. case WM_DESTROY:
  147. if (sData)
  148. sData->m_quit = true;
  149. //PostQuitMessage(0);
  150. return 1;
  151. case WM_SYSKEYUP:
  152. case WM_KEYUP:
  153. {
  154. int keycode = getSpecialKeyFromVirtualKeycode(wParam);
  155. switch (keycode)
  156. {
  157. case B3G_ALT:
  158. {
  159. sData->m_internalKeyModifierFlags&=~INTERNAL_ALT_MODIFIER;
  160. break;
  161. };
  162. case B3G_SHIFT:
  163. {
  164. sData->m_internalKeyModifierFlags &= ~INTERNAL_SHIFT_MODIFIER;
  165. break;
  166. };
  167. case B3G_CONTROL:
  168. {
  169. sData->m_internalKeyModifierFlags &=~INTERNAL_CONTROL_MODIFIER;
  170. break;
  171. };
  172. }
  173. if (keycode>=0 && sData && sData->m_keyboardCallback )
  174. {
  175. int state=0;
  176. (*sData->m_keyboardCallback)(keycode,state);
  177. }
  178. return 0;
  179. }
  180. case WM_CHAR:
  181. {
  182. //skip 'enter' key, it is processed in WM_KEYUP/WM_KEYDOWN
  183. int keycode = getAsciiCodeFromVirtualKeycode(wParam);
  184. if (keycode < 0)
  185. {
  186. if (sData && sData->m_keyboardCallback && ((HIWORD(lParam) & KF_REPEAT) == 0))
  187. {
  188. int state = 1;
  189. (*sData->m_keyboardCallback)(wParam, state);
  190. }
  191. }
  192. return 0;
  193. }
  194. case WM_SYSKEYDOWN:
  195. case WM_KEYDOWN:
  196. {
  197. int keycode = getSpecialKeyFromVirtualKeycode(wParam);
  198. switch (keycode)
  199. {
  200. case B3G_ALT:
  201. {
  202. sData->m_internalKeyModifierFlags|=INTERNAL_ALT_MODIFIER;
  203. break;
  204. };
  205. case B3G_SHIFT:
  206. {
  207. sData->m_internalKeyModifierFlags |= INTERNAL_SHIFT_MODIFIER;
  208. break;
  209. };
  210. case B3G_CONTROL:
  211. {
  212. sData->m_internalKeyModifierFlags |=INTERNAL_CONTROL_MODIFIER;
  213. break;
  214. };
  215. }
  216. if (keycode>=0 && sData && sData->m_keyboardCallback)// && ((HIWORD(lParam) & KF_REPEAT) == 0))
  217. {
  218. int state = 1;
  219. (*sData->m_keyboardCallback)(keycode,state);
  220. return 1;
  221. }
  222. return 0;
  223. }
  224. case WM_MBUTTONUP:
  225. {
  226. int xPos = LOWORD(lParam);
  227. int yPos = HIWORD(lParam);
  228. if (sData)
  229. {
  230. sData->m_mouseMButton=0;
  231. sData->m_mouseXpos = xPos;
  232. sData->m_mouseYpos = yPos;
  233. if (sData && sData->m_mouseButtonCallback)
  234. (*sData->m_mouseButtonCallback)(1,0,xPos,yPos);
  235. }
  236. break;
  237. }
  238. case WM_MBUTTONDOWN:
  239. {
  240. int xPos = LOWORD(lParam);
  241. int yPos = HIWORD(lParam);
  242. if (sData)
  243. {
  244. sData->m_mouseMButton=1;
  245. sData->m_mouseXpos = xPos;
  246. sData->m_mouseYpos = yPos;
  247. if (sData && sData->m_mouseButtonCallback)
  248. (*sData->m_mouseButtonCallback)(1,1,xPos,yPos);
  249. }
  250. break;
  251. }
  252. case WM_LBUTTONUP:
  253. {
  254. int xPos = LOWORD(lParam);
  255. int yPos = HIWORD(lParam);
  256. if (sData)
  257. {
  258. sData->m_mouseLButton=0;
  259. sData->m_mouseXpos = xPos;
  260. sData->m_mouseYpos = yPos;
  261. if (sData && sData->m_mouseButtonCallback)
  262. (*sData->m_mouseButtonCallback)(0,0,xPos,yPos);
  263. }
  264. // gDemoApplication->mouseFunc(0,1,xPos,yPos);
  265. break;
  266. }
  267. case WM_LBUTTONDOWN:
  268. {
  269. int xPos = LOWORD(lParam);
  270. int yPos = HIWORD(lParam);
  271. if (sData)
  272. {
  273. sData->m_mouseLButton=1;
  274. sData->m_mouseXpos = xPos;
  275. sData->m_mouseYpos = yPos;
  276. if (sData && sData->m_mouseButtonCallback)
  277. (*sData->m_mouseButtonCallback)(0,1,xPos,yPos);
  278. }
  279. break;
  280. }
  281. case 0x020e://WM_MOUSEWHEEL_LEFT_RIGHT
  282. {
  283. int zDelta = (short)HIWORD(wParam);
  284. int xPos = LOWORD(lParam);
  285. int yPos = HIWORD(lParam);
  286. //m_cameraDistance -= zDelta*0.01;
  287. if (sData && sData->m_wheelCallback)
  288. (*sData->m_wheelCallback)(-float(zDelta)*0.05f,0);
  289. return 1;
  290. break;
  291. }
  292. case 0x020A://WM_MOUSEWHEEL:
  293. {
  294. int zDelta = (short)HIWORD(wParam);
  295. int xPos = LOWORD(lParam);
  296. int yPos = HIWORD(lParam);
  297. //m_cameraDistance -= zDelta*0.01;
  298. if (sData && sData->m_wheelCallback)
  299. (*sData->m_wheelCallback)(0,float(zDelta)*0.05f);
  300. return 1;
  301. break;
  302. }
  303. case WM_MOUSEMOVE:
  304. {
  305. int xPos = LOWORD(lParam);
  306. int yPos = HIWORD(lParam);
  307. sData->m_mouseXpos = xPos;
  308. sData->m_mouseYpos = yPos;
  309. if (sData && sData->m_mouseMoveCallback)
  310. (*sData->m_mouseMoveCallback)(xPos,yPos);
  311. break;
  312. }
  313. case WM_RBUTTONUP:
  314. {
  315. int xPos = LOWORD(lParam);
  316. int yPos = HIWORD(lParam);
  317. sData->m_mouseRButton = 1;
  318. if (sData && sData->m_mouseButtonCallback)
  319. (*sData->m_mouseButtonCallback)(2,0,sData->m_mouseXpos,sData->m_mouseYpos);
  320. //gDemoApplication->mouseFunc(2,1,xPos,yPos);
  321. break;
  322. }
  323. case WM_RBUTTONDOWN:
  324. {
  325. int xPos = LOWORD(lParam);
  326. int yPos = HIWORD(lParam);
  327. sData->m_mouseRButton = 0;
  328. if (sData && sData->m_mouseButtonCallback)
  329. (*sData->m_mouseButtonCallback)(2,1,sData->m_mouseXpos,sData->m_mouseYpos);
  330. break;
  331. }
  332. case WM_QUIT:
  333. {
  334. return 0;
  335. break;
  336. }
  337. case WM_SIZE: // Size Action Has Taken Place
  338. RECT clientRect;
  339. GetClientRect(hWnd,&clientRect);
  340. switch (wParam) // Evaluate Size Action
  341. {
  342. case SIZE_MINIMIZED: // Was Window Minimized?
  343. return 0; // Return
  344. case SIZE_MAXIMIZED: // Was Window Maximized?
  345. case SIZE_RESTORED: // Was Window Restored?
  346. RECT wr;
  347. GetWindowRect(hWnd,&wr);
  348. sData->m_fullWindowWidth = wr.right-wr.left;
  349. sData->m_fullWindowHeight = wr.bottom-wr.top;//LOWORD (lParam) HIWORD (lParam);
  350. sData->m_openglViewportWidth = clientRect.right;
  351. sData->m_openglViewportHeight = clientRect.bottom;
  352. glViewport(0, 0, sData->m_openglViewportWidth, sData->m_openglViewportHeight);
  353. if (sData->m_resizeCallback)
  354. (*sData->m_resizeCallback)(sData->m_openglViewportWidth,sData->m_openglViewportHeight);
  355. //if (sOpenGLInitialized)
  356. //{
  357. // //gDemoApplication->reshape(sWidth,sHeight);
  358. //}
  359. return 0; // Return
  360. }
  361. break;
  362. default:{
  363. }
  364. };
  365. return DefWindowProc(hWnd, message, wParam, lParam);
  366. }
  367. void Win32Window::setWindowTitle(const char* titleChar)
  368. {
  369. wchar_t windowTitle[1024];
  370. swprintf(windowTitle, 1024, L"%hs", titleChar);
  371. DWORD dwResult;
  372. #ifdef _WIN64
  373. SetWindowTextW(m_data->m_hWnd, windowTitle);
  374. #else
  375. SendMessageTimeoutW(m_data->m_hWnd, WM_SETTEXT, 0,
  376. reinterpret_cast<LPARAM>(windowTitle),
  377. SMTO_ABORTIFHUNG, 2000, &dwResult);
  378. #endif
  379. }
  380. void Win32Window::createWindow(const b3gWindowConstructionInfo& ci)
  381. {
  382. int oglViewportWidth = ci.m_width;
  383. int oglViewportHeight = ci.m_height;
  384. bool fullscreen = ci.m_fullscreen;
  385. int colorBitsPerPixel = ci.m_colorBitsPerPixel;
  386. void* windowHandle = ci.m_windowHandle;
  387. // get handle to exe file
  388. HINSTANCE hInstance = GetModuleHandle(0);
  389. // create the window if we need to and we do not use the null device
  390. if (!windowHandle)
  391. {
  392. #ifdef UNICODE
  393. const wchar_t * ClassName = L"DeviceWin32";
  394. const wchar_t* emptyString= L"";
  395. #else
  396. const char* ClassName = "DeviceWin32";
  397. const char* emptyString = "";
  398. #endif
  399. // Register Class
  400. WNDCLASSEX wcex;
  401. wcex.cbSize = sizeof(WNDCLASSEX);
  402. wcex.style = CS_HREDRAW | CS_VREDRAW;
  403. wcex.lpfnWndProc = WndProc;
  404. wcex.cbClsExtra = 0;
  405. wcex.cbWndExtra = 0;
  406. wcex.hInstance = hInstance;
  407. wcex.hIcon = LoadIcon( NULL, IDI_APPLICATION ); //(HICON)LoadImage(hInstance, "bullet_ico.ico", IMAGE_ICON, 0,0, LR_LOADTRANSPARENT);//LR_LOADFROMFILE);
  408. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  409. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  410. wcex.lpszMenuName = 0;
  411. wcex.lpszClassName = ClassName;
  412. wcex.hIconSm = 0;
  413. // if there is an icon, load it
  414. // wcex.hIcon = (HICON)LoadImage(hInstance, "bullet.ico", IMAGE_ICON, 0,0, LR_LOADFROMFILE);
  415. RegisterClassEx(&wcex);
  416. // calculate client size
  417. RECT clientSize;
  418. clientSize.top = 0;
  419. clientSize.left = 0;
  420. clientSize.right = oglViewportWidth;
  421. clientSize.bottom = oglViewportHeight;
  422. DWORD style = WS_POPUP;
  423. if (!fullscreen)
  424. style = WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX;
  425. AdjustWindowRect(&clientSize, style, false);
  426. m_data->m_fullWindowWidth = clientSize.right - clientSize.left;
  427. m_data->m_fullWindowHeight = clientSize.bottom - clientSize.top;
  428. int windowLeft = (GetSystemMetrics(SM_CXSCREEN) - m_data->m_fullWindowWidth) / 2;
  429. int windowTop = (GetSystemMetrics(SM_CYSCREEN) - m_data->m_fullWindowHeight) / 2;
  430. if (fullscreen)
  431. {
  432. windowLeft = 0;
  433. windowTop = 0;
  434. }
  435. // create window
  436. m_data->m_hWnd = CreateWindow( ClassName, emptyString, style, windowLeft, windowTop,
  437. m_data->m_fullWindowWidth, m_data->m_fullWindowHeight,NULL, NULL, hInstance, NULL);
  438. RECT clientRect;
  439. GetClientRect(m_data->m_hWnd,&clientRect);
  440. ShowWindow(m_data->m_hWnd, SW_SHOW);
  441. UpdateWindow(m_data->m_hWnd);
  442. MoveWindow(m_data->m_hWnd, windowLeft, windowTop, m_data->m_fullWindowWidth, m_data->m_fullWindowHeight, TRUE);
  443. GetClientRect(m_data->m_hWnd,&clientRect);
  444. int w = clientRect.right-clientRect.left;
  445. int h = clientRect.bottom-clientRect.top;
  446. // printf("actual client OpenGL viewport width / height = %d, %d\n",w,h);
  447. m_data->m_openglViewportHeight = h;
  448. m_data->m_openglViewportWidth = w;
  449. }
  450. else if (windowHandle)
  451. {
  452. // attach external window
  453. m_data->m_hWnd = static_cast<HWND>(windowHandle);
  454. RECT r;
  455. GetWindowRect(m_data->m_hWnd, &r);
  456. m_data->m_fullWindowWidth = r.right - r.left;
  457. m_data->m_fullWindowHeight= r.bottom - r.top;
  458. //sFullScreen = false;
  459. //sExternalWindow = true;
  460. }
  461. if (fullscreen)
  462. {
  463. DEVMODE dm;
  464. memset(&dm, 0, sizeof(dm));
  465. dm.dmSize = sizeof(dm);
  466. // use default values from current setting
  467. EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
  468. m_data->m_oldScreenWidth = dm.dmPelsWidth;
  469. m_data->m_oldHeight = dm.dmPelsHeight;
  470. m_data->m_oldBitsPerPel = dm.dmBitsPerPel;
  471. dm.dmPelsWidth = oglViewportWidth;
  472. dm.dmPelsHeight = oglViewportHeight;
  473. if (colorBitsPerPixel)
  474. {
  475. dm.dmBitsPerPel = colorBitsPerPixel;
  476. }
  477. dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
  478. LONG res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
  479. if (res != DISP_CHANGE_SUCCESSFUL)
  480. { // try again without forcing display frequency
  481. dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
  482. res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
  483. }
  484. }
  485. }
  486. void Win32Window::switchFullScreen(bool fullscreen,int width,int height,int colorBitsPerPixel)
  487. {
  488. LONG res;
  489. DEVMODE dm;
  490. memset(&dm, 0, sizeof(dm));
  491. dm.dmSize = sizeof(dm);
  492. // use default values from current setting
  493. EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
  494. dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
  495. if (fullscreen && !m_data->m_oldScreenWidth)
  496. {
  497. m_data->m_oldScreenWidth = dm.dmPelsWidth;
  498. m_data->m_oldHeight = dm.dmPelsHeight;
  499. m_data->m_oldBitsPerPel = dm.dmBitsPerPel;
  500. if (width && height)
  501. {
  502. dm.dmPelsWidth = width;
  503. dm.dmPelsHeight = height;
  504. } else
  505. {
  506. dm.dmPelsWidth = m_data->m_fullWindowWidth;
  507. dm.dmPelsHeight = m_data->m_fullWindowHeight;
  508. }
  509. if (colorBitsPerPixel)
  510. {
  511. dm.dmBitsPerPel = colorBitsPerPixel;
  512. }
  513. } else
  514. {
  515. if (m_data->m_oldScreenWidth)
  516. {
  517. dm.dmPelsWidth = m_data->m_oldScreenWidth;
  518. dm.dmPelsHeight= m_data->m_oldHeight;
  519. dm.dmBitsPerPel = m_data->m_oldBitsPerPel;
  520. }
  521. }
  522. if (fullscreen)
  523. {
  524. res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
  525. if (!res)
  526. {
  527. dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
  528. res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
  529. }
  530. DWORD style = WS_POPUP;
  531. SetWindowLong(m_data->m_hWnd, GWL_STYLE, style);
  532. MoveWindow(m_data->m_hWnd, 0, 0, m_data->m_fullWindowWidth, m_data->m_fullWindowHeight, TRUE);
  533. SetWindowPos(m_data->m_hWnd, NULL,0,0, (int)width, (int)height,
  534. SWP_FRAMECHANGED |SWP_SHOWWINDOW);//|SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_NOZORDER);
  535. } else
  536. {
  537. res = ChangeDisplaySettings(&dm, 0);
  538. DWORD style = WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX;
  539. SetWindowLong(m_data->m_hWnd, GWL_STYLE, style);
  540. SetWindowPos(m_data->m_hWnd, NULL,0,0, (int)width, (int)height,
  541. SWP_FRAMECHANGED |SWP_SHOWWINDOW);
  542. //|SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_NOZORDER);
  543. }
  544. }
  545. Win32Window::Win32Window()
  546. {
  547. m_data = new InternalData2();
  548. sData = m_data;
  549. }
  550. Win32Window::~Win32Window()
  551. {
  552. setKeyboardCallback(0);
  553. setMouseMoveCallback(0);
  554. setMouseButtonCallback(0);
  555. setWheelCallback(0);
  556. setResizeCallback(0);
  557. sData = 0;
  558. delete m_data;
  559. }
  560. void Win32Window::setRenderCallback( b3RenderCallback renderCallback)
  561. {
  562. }
  563. void Win32Window::closeWindow()
  564. {
  565. setKeyboardCallback(0);
  566. setMouseMoveCallback(0);
  567. setMouseButtonCallback(0);
  568. setWheelCallback(0);
  569. setResizeCallback(0);
  570. setRenderCallback(0);
  571. DestroyWindow(this->m_data->m_hWnd);
  572. }
  573. void Win32Window::getMouseCoordinates(int& x, int& y)
  574. {
  575. x = m_data->m_mouseXpos;
  576. y = m_data->m_mouseYpos;
  577. }
  578. void Win32Window::runMainLoop()
  579. {
  580. }
  581. void Win32Window::startRendering()
  582. {
  583. pumpMessage();
  584. // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //clear buffers
  585. //glCullFace(GL_BACK);
  586. //glFrontFace(GL_CCW);
  587. // glEnable(GL_DEPTH_TEST);
  588. }
  589. void Win32Window::renderAllObjects()
  590. {
  591. }
  592. void Win32Window::endRendering()
  593. {
  594. SwapBuffers( m_data->m_hDC );
  595. }
  596. float Win32Window::getTimeInSeconds()
  597. {
  598. return 0.f;
  599. }
  600. void Win32Window::setDebugMessage(int x,int y,const char* message)
  601. {
  602. }
  603. void Win32Window::setRequestExit()
  604. {
  605. m_data->m_quit = true;
  606. }
  607. bool Win32Window::requestedExit() const
  608. {
  609. return m_data->m_quit;
  610. }
  611. void Win32Window::setWheelCallback(b3WheelCallback wheelCallback)
  612. {
  613. m_data->m_wheelCallback = wheelCallback;
  614. }
  615. void Win32Window::setMouseMoveCallback(b3MouseMoveCallback mouseCallback)
  616. {
  617. m_data->m_mouseMoveCallback = mouseCallback;
  618. }
  619. void Win32Window::setMouseButtonCallback(b3MouseButtonCallback mouseCallback)
  620. {
  621. m_data->m_mouseButtonCallback = mouseCallback;
  622. }
  623. void Win32Window::setResizeCallback(b3ResizeCallback resizeCallback)
  624. {
  625. m_data->m_resizeCallback = resizeCallback;
  626. if (m_data->m_resizeCallback)
  627. (*m_data->m_resizeCallback)(m_data->m_openglViewportWidth,m_data->m_openglViewportHeight);
  628. }
  629. void Win32Window::setKeyboardCallback( b3KeyboardCallback keyboardCallback)
  630. {
  631. m_data->m_keyboardCallback = keyboardCallback;
  632. }
  633. b3KeyboardCallback Win32Window::getKeyboardCallback()
  634. {
  635. return m_data->m_keyboardCallback;
  636. }
  637. b3MouseMoveCallback Win32Window::getMouseMoveCallback()
  638. {
  639. return m_data->m_mouseMoveCallback;
  640. }
  641. b3MouseButtonCallback Win32Window::getMouseButtonCallback()
  642. {
  643. return m_data->m_mouseButtonCallback;
  644. }
  645. b3ResizeCallback Win32Window::getResizeCallback()
  646. {
  647. return m_data->m_resizeCallback;
  648. }
  649. b3WheelCallback Win32Window::getWheelCallback()
  650. {
  651. return m_data->m_wheelCallback;
  652. }
  653. #endif