PolyWinCore.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolycodeView.h"
  21. #include "PolyGlobals.h"
  22. #include "PolyCore.h"
  23. #include "PolyGLRenderer.h"
  24. #include "PolyGLSLShaderModule.h"
  25. #include <windows.h>
  26. #include <windowsx.h>
  27. #include <WinUser.h>
  28. #include "PolyRectangle.h"
  29. #include <GL/wglext.h>
  30. #include <vector>
  31. using std::vector;
  32. #ifndef VK_0
  33. #define VK_0 '0'
  34. #define VK_1 '1'
  35. #define VK_2 '2'
  36. #define VK_3 '3'
  37. #define VK_4 '4'
  38. #define VK_5 '5'
  39. #define VK_6 '6'
  40. #define VK_7 '7'
  41. #define VK_8 '8'
  42. #define VK_9 '9'
  43. #define VK_A 'A'
  44. #define VK_B 'B'
  45. #define VK_C 'C'
  46. #define VK_D 'D'
  47. #define VK_E 'E'
  48. #define VK_F 'F'
  49. #define VK_G 'G'
  50. #define VK_H 'H'
  51. #define VK_I 'I'
  52. #define VK_J 'J'
  53. #define VK_K 'K'
  54. #define VK_L 'L'
  55. #define VK_M 'M'
  56. #define VK_N 'N'
  57. #define VK_O 'O'
  58. #define VK_P 'P'
  59. #define VK_Q 'Q'
  60. #define VK_R 'R'
  61. #define VK_S 'S'
  62. #define VK_T 'T'
  63. #define VK_U 'U'
  64. #define VK_V 'V'
  65. #define VK_W 'W'
  66. #define VK_X 'X'
  67. #define VK_Y 'Y'
  68. #define VK_Z 'Z'
  69. #endif /* VK_0 */
  70. /* These keys haven't been defined, but were experimentally determined */
  71. #define VK_SEMICOLON 0xBA
  72. #define VK_EQUALS 0xBB
  73. #define VK_COMMA 0xBC
  74. #define VK_MINUS 0xBD
  75. #define VK_PERIOD 0xBE
  76. #define VK_SLASH 0xBF
  77. #define VK_GRAVE 0xC0
  78. #define VK_LBRACKET 0xDB
  79. #define VK_BACKSLASH 0xDC
  80. #define VK_RBRACKET 0xDD
  81. #define VK_APOSTROPHE 0xDE
  82. #define VK_BACKTICK 0xDF
  83. #define VK_OEM_102 0xE2
  84. #define EXTENDED_KEYMASK (1<<24)
  85. namespace Polycode {
  86. class _PolyExport Win32Mutex : public CoreMutex {
  87. public:
  88. HANDLE winMutex;
  89. };
  90. class _PolyExport Win32Event {
  91. public:
  92. int eventGroup;
  93. int eventCode;
  94. int mouseX;
  95. int mouseY;
  96. PolyKEY keyCode;
  97. wchar_t unicodeChar;
  98. char mouseButton;
  99. static const int INPUT_EVENT = 0;
  100. };
  101. class _PolyExport Win32Core : public Core {
  102. public:
  103. Win32Core(PolycodeViewBase *view, int xRes, int yRes, bool fullScreen, int aaLevel,int frameRate);
  104. ~Win32Core();
  105. void enableMouse(bool newval);
  106. unsigned int getTicks();
  107. bool Update();
  108. void handleKeyDown(LPARAM lParam, WPARAM wParam);
  109. void handleKeyUp(LPARAM lParam, WPARAM wParam);
  110. void handleMouseMove(LPARAM lParam, WPARAM wParam);
  111. void handleMouseWheel(LPARAM lParam, WPARAM wParam);
  112. void handleMouseDown(int mouseCode,LPARAM lParam, WPARAM wParam);
  113. void handleMouseUp(int mouseCode,LPARAM lParam, WPARAM wParam);
  114. void setVideoMode(int xRes, int yRes, bool fullScreen, int aaLevel);
  115. void initContext(bool usePixelFormat, unsigned int pixelFormat);
  116. void destroyContext();
  117. void createThread(Threaded *target);
  118. PolyKEY mapKey(LPARAM lParam, WPARAM wParam);
  119. void lockMutex(CoreMutex *mutex);
  120. void unlockMutex(CoreMutex *mutex);
  121. CoreMutex *createMutex();
  122. void checkEvents();
  123. void initKeymap();
  124. void platformSleep(int msecs);
  125. vector<Polycode::Rectangle> getVideoModes();
  126. // NEED TO IMPLEMENT:
  127. void setCursor(int cursorType){ }
  128. void copyStringToClipboard(const String& str) { }
  129. String getClipboardString() { return ""; }
  130. void createFolder(const String& folderPath) {}
  131. void copyDiskItem(const String& itemPath, const String& destItemPath) {}
  132. void moveDiskItem(const String& itemPath, const String& destItemPath) {}
  133. String openFolderPicker() { return "";}
  134. void removeDiskItem(const String& itemPath) {}
  135. vector<string> openFilePicker(vector<CoreFileExtension> extensions, bool allowMultiple) { vector<string> ret; return ret;}
  136. void resizeTo(int xRes, int yRes) { }
  137. private:
  138. PolyKEY keyMap[1024];
  139. CoreMutex *eventMutex;
  140. vector<Win32Event> win32Events;
  141. void initMultisample(int numSamples);
  142. HWND hWnd;
  143. int lastMouseX;
  144. int lastMouseY;
  145. bool isFullScreen;
  146. HDC hDC;
  147. HGLRC hRC;
  148. unsigned int PixelFormat;
  149. PIXELFORMATDESCRIPTOR pfd;
  150. };
  151. }