PolyWinCore.cpp 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  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. #include "PolyWinCore.h"
  20. #include "PolyGLHeaders.h"
  21. #include "PolyCoreInput.h"
  22. #include "PolyCoreServices.h"
  23. #include "PolyInputEvent.h"
  24. #include "PolyGLRenderer.h"
  25. #include "PolyGLSLShaderModule.h"
  26. #include "PolyLogger.h"
  27. #include "PolyThreaded.h"
  28. #include <direct.h>
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <Shlobj.h>
  32. #include <Shellapi.h>
  33. #include <Commdlg.h>
  34. #include <GL/gl.h>
  35. #include <GL/glext.h>
  36. #ifndef _MINGW
  37. #include <GL/wglext.h>
  38. #endif
  39. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
  40. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = NULL;
  41. using namespace Polycode;
  42. long getThreadID() {
  43. return 0;
  44. }
  45. extern Win32Core *core;
  46. void ClientResize(HWND hWnd, int nWidth, int nHeight)
  47. {
  48. RECT rcClient, rcWindow;
  49. POINT ptDiff;
  50. GetClientRect(hWnd, &rcClient);
  51. GetWindowRect(hWnd, &rcWindow);
  52. ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right;
  53. ptDiff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom;
  54. MoveWindow(hWnd,rcWindow.left, rcWindow.top, nWidth + ptDiff.x, nHeight + ptDiff.y, TRUE);
  55. }
  56. void Core::getScreenInfo(int *width, int *height, int *hz) {
  57. DEVMODE mode = {}; // Zero initialize
  58. mode.dmSize = sizeof(DEVMODE);
  59. EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &mode);
  60. // Store the current display settings.
  61. if (width) *width = mode.dmPelsWidth;
  62. if (height) *height = mode.dmPelsHeight;
  63. if (hz) *hz = mode.dmDisplayFrequency;
  64. }
  65. Win32Core::Win32Core(PolycodeViewBase *view, int _xRes, int _yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex)
  66. : Core(_xRes, _yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate, monitorIndex) {
  67. hWnd = *((HWND*)view->windowData);
  68. core = this;
  69. char *buffer = _getcwd(NULL, 0);
  70. defaultWorkingDirectory = String(buffer);
  71. free(buffer);
  72. WCHAR path[MAX_PATH];
  73. if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, path))) {
  74. userHomeDirectory = String(path);
  75. }
  76. initKeymap();
  77. initGamepad();
  78. initTouch();
  79. hDC = NULL;
  80. hRC = NULL;
  81. PixelFormat = 0;
  82. this->aaLevel = 999;
  83. lastMouseX = -1;
  84. lastMouseY = -1;
  85. eventMutex = createMutex();
  86. isFullScreen = fullScreen;
  87. renderer = new OpenGLRenderer();
  88. services->setRenderer(renderer);
  89. setVideoMode(xRes, yRes, fullScreen, vSync, aaLevel, anisotropyLevel);
  90. WSADATA WsaData;
  91. if(WSAStartup( MAKEWORD(2,2), &WsaData ) != NO_ERROR ){
  92. Logger::log("Error initializing sockets!\n");
  93. }
  94. ((OpenGLRenderer*)renderer)->initOSSpecific();
  95. wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress("wglSwapIntervalEXT");
  96. wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC) wglGetProcAddress("wglGetSwapIntervalEXT");
  97. setVSync(vSync);
  98. CoreServices::getInstance()->installModule(new GLSLShaderModule());
  99. }
  100. Win32Core::~Win32Core() {
  101. shutdownGamepad();
  102. destroyContext();
  103. }
  104. void Win32Core::enableMouse(bool newval) {
  105. ShowCursor(newval);
  106. }
  107. void Win32Core::warpCursor(int x, int y) {
  108. POINT point;
  109. point.x = x;
  110. point.y = y;
  111. ClientToScreen(hWnd, &point);
  112. SetCursorPos(point.x,point.y);
  113. lastMouseX = x;
  114. lastMouseY = y;
  115. }
  116. unsigned int Win32Core::getTicks() {
  117. return GetTickCount();
  118. }
  119. bool Win32Core::Update() {
  120. if(!running)
  121. return false;
  122. checkEvents();
  123. Gamepad_processEvents();
  124. renderer->BeginRender();
  125. updateCore();
  126. renderer->EndRender();
  127. SwapBuffers(hDC);
  128. doSleep();
  129. return running;
  130. }
  131. void Win32Core::setVSync(bool vSyncVal) {
  132. if(wglSwapIntervalEXT) {
  133. if(vSyncVal) {
  134. wglSwapIntervalEXT(1);
  135. } else {
  136. wglSwapIntervalEXT(0);
  137. }
  138. }
  139. }
  140. void Win32Core::setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel) {
  141. bool resetContext = false;
  142. if(aaLevel != this->aaLevel) {
  143. resetContext = true;
  144. }
  145. this->xRes = xRes;
  146. this->yRes = yRes;
  147. this->fullScreen = fullScreen;
  148. this->aaLevel = aaLevel;
  149. if(fullScreen) {
  150. SetWindowLong(hWnd, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP);
  151. ShowWindow(hWnd, SW_SHOW);
  152. DEVMODE dmScreenSettings; // Device Mode
  153. memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
  154. dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
  155. dmScreenSettings.dmPelsWidth = xRes; // Selected Screen Width
  156. dmScreenSettings.dmPelsHeight = yRes; // Selected Screen Height
  157. dmScreenSettings.dmBitsPerPel = 32; // Selected Bits Per Pixel
  158. dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
  159. ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN);
  160. SetWindowPos(hWnd, NULL, 0, 0, xRes, yRes, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  161. } else {
  162. // SetWindowLong(hWnd, GWL_STYLE, WS_OVERLAPPED|WS_SYSMENU);
  163. // ShowWindow(hWnd, SW_SHOW);
  164. ClientResize(hWnd, xRes, yRes);
  165. }
  166. isFullScreen = fullScreen;
  167. if(resetContext) {
  168. initContext(false, 0);
  169. if(aaLevel > 0) {
  170. initMultisample(aaLevel);
  171. }
  172. }
  173. setVSync(vSync);
  174. renderer->setAnisotropyAmount(anisotropyLevel);
  175. renderer->Resize(xRes, yRes);
  176. core->dispatchEvent(new Event(), Core::EVENT_CORE_RESIZE);
  177. }
  178. void Win32Core::initContext(bool usePixelFormat, unsigned int pixelFormat) {
  179. destroyContext();
  180. memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)) ;
  181. pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  182. pfd.nVersion = 1 ;
  183. pfd.dwFlags = PFD_DOUBLEBUFFER |
  184. PFD_SUPPORT_OPENGL |
  185. PFD_DRAW_TO_WINDOW ;
  186. pfd.iPixelType = PFD_TYPE_RGBA ;
  187. pfd.cColorBits = 24;
  188. pfd.cDepthBits = 16;
  189. pfd.cAccumBlueBits = 8;
  190. pfd.cAccumRedBits = 8;
  191. pfd.cAccumGreenBits = 8;
  192. pfd.cAccumAlphaBits = 8;
  193. pfd.cAccumBits = 24;
  194. pfd.iLayerType = PFD_MAIN_PLANE ;
  195. if (!(hDC=GetDC(hWnd))) // Did We Get A Device Context?
  196. {
  197. Logger::log("Can't Create A GL Device Context.\n");
  198. return; // Return FALSE
  199. }
  200. if(usePixelFormat) {
  201. PixelFormat = pixelFormat;
  202. } else {
  203. if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format?
  204. {
  205. Logger::log("Can't Find A Suitable PixelFormat.\n");
  206. return; // Return FALSE
  207. }
  208. }
  209. Logger::log("Setting format: %d\n", PixelFormat);
  210. if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format?
  211. {
  212. Logger::log("Can't Set The PixelFormat: %d.\n", PixelFormat);
  213. return; // Return FALSE
  214. }
  215. if (!(hRC=wglCreateContext(hDC))) // Are We Able To Get A Rendering Context?
  216. {
  217. Logger::log("Can't Create A GL Rendering Context.\n");
  218. return; // Return FALSE
  219. }
  220. if(!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context
  221. {
  222. Logger::log("Can't Activate The GL Rendering Context.\n");
  223. return; // Return FALSE
  224. }
  225. }
  226. void Win32Core::destroyContext() {
  227. if(hDC == NULL)
  228. return;
  229. wglMakeCurrent (hDC, 0);
  230. wglDeleteContext(hRC);
  231. hRC = 0;
  232. ReleaseDC (hWnd, hDC);
  233. hDC = 0;
  234. if (isFullScreen)
  235. ChangeDisplaySettings (NULL,0);
  236. }
  237. void Win32Core::initMultisample(int numSamples) {
  238. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB =
  239. (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
  240. if (!wglChoosePixelFormatARB) {
  241. Logger::log("Multisampling not supported!\n");
  242. return;
  243. }
  244. int pixelFormat;
  245. UINT numFormats;
  246. float fAttributes[] = {0,0};
  247. int iAttributes[] = { WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
  248. WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
  249. WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
  250. WGL_COLOR_BITS_ARB,24,
  251. WGL_DEPTH_BITS_ARB,24,
  252. WGL_DOUBLE_BUFFER_ARB,GL_TRUE,
  253. WGL_ACCUM_GREEN_BITS_ARB, 8,
  254. WGL_ACCUM_RED_BITS_ARB, 8,
  255. WGL_ACCUM_BLUE_BITS_ARB, 8,
  256. WGL_ACCUM_ALPHA_BITS_ARB, 8,
  257. WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
  258. WGL_SAMPLES_ARB, numSamples ,
  259. 0,0};
  260. if(!wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats)) {
  261. Logger::log("Invalid pixel format chosen\n");
  262. return;
  263. }
  264. // initContext(true, pixelFormat);
  265. glEnable(GL_MULTISAMPLE_ARB);
  266. }
  267. void Win32Core::initKeymap() {
  268. for (int i=0; i<1024; ++i )
  269. keyMap[i] = KEY_UNKNOWN;
  270. keyMap[VK_BACK] = KEY_BACKSPACE;
  271. keyMap[VK_TAB] = KEY_TAB;
  272. keyMap[VK_CLEAR] = KEY_CLEAR;
  273. keyMap[VK_RETURN] = KEY_RETURN;
  274. keyMap[VK_PAUSE] = KEY_PAUSE;
  275. keyMap[VK_ESCAPE] = KEY_ESCAPE;
  276. keyMap[VK_SPACE] = KEY_SPACE;
  277. keyMap[VK_APOSTROPHE] = KEY_QUOTE;
  278. keyMap[VK_COMMA] = KEY_COMMA;
  279. keyMap[VK_MINUS] = KEY_MINUS;
  280. keyMap[VK_PERIOD] = KEY_PERIOD;
  281. keyMap[VK_SLASH] = KEY_SLASH;
  282. keyMap[VK_0] = KEY_0;
  283. keyMap[VK_1] = KEY_1;
  284. keyMap[VK_2] = KEY_2;
  285. keyMap[VK_3] = KEY_3;
  286. keyMap[VK_4] = KEY_4;
  287. keyMap[VK_5] = KEY_5;
  288. keyMap[VK_6] = KEY_6;
  289. keyMap[VK_7] = KEY_7;
  290. keyMap[VK_8] = KEY_8;
  291. keyMap[VK_9] = KEY_9;
  292. keyMap[VK_SEMICOLON] = KEY_SEMICOLON;
  293. keyMap[VK_EQUALS] = KEY_EQUALS;
  294. keyMap[VK_LBRACKET] = KEY_LEFTBRACKET;
  295. keyMap[VK_BACKSLASH] = KEY_BACKSLASH;
  296. keyMap[VK_OEM_102] = KEY_LESS;
  297. keyMap[VK_RBRACKET] = KEY_RIGHTBRACKET;
  298. keyMap[VK_GRAVE] = KEY_BACKQUOTE;
  299. keyMap[VK_BACKTICK] = KEY_BACKQUOTE;
  300. keyMap[VK_A] = KEY_a;
  301. keyMap[VK_B] = KEY_b;
  302. keyMap[VK_C] = KEY_c;
  303. keyMap[VK_D] = KEY_d;
  304. keyMap[VK_E] = KEY_e;
  305. keyMap[VK_F] = KEY_f;
  306. keyMap[VK_G] = KEY_g;
  307. keyMap[VK_H] = KEY_h;
  308. keyMap[VK_I] = KEY_i;
  309. keyMap[VK_J] = KEY_j;
  310. keyMap[VK_K] = KEY_k;
  311. keyMap[VK_L] = KEY_l;
  312. keyMap[VK_M] = KEY_m;
  313. keyMap[VK_N] = KEY_n;
  314. keyMap[VK_O] = KEY_o;
  315. keyMap[VK_P] = KEY_p;
  316. keyMap[VK_Q] = KEY_q;
  317. keyMap[VK_R] = KEY_r;
  318. keyMap[VK_S] = KEY_s;
  319. keyMap[VK_T] = KEY_t;
  320. keyMap[VK_U] = KEY_u;
  321. keyMap[VK_V] = KEY_v;
  322. keyMap[VK_W] = KEY_w;
  323. keyMap[VK_X] = KEY_x;
  324. keyMap[VK_Y] = KEY_y;
  325. keyMap[VK_Z] = KEY_z;
  326. keyMap[VK_DELETE] = KEY_DELETE;
  327. keyMap[VK_NUMPAD0] = KEY_KP0;
  328. keyMap[VK_NUMPAD1] = KEY_KP1;
  329. keyMap[VK_NUMPAD2] = KEY_KP2;
  330. keyMap[VK_NUMPAD3] = KEY_KP3;
  331. keyMap[VK_NUMPAD4] = KEY_KP4;
  332. keyMap[VK_NUMPAD5] = KEY_KP5;
  333. keyMap[VK_NUMPAD6] = KEY_KP6;
  334. keyMap[VK_NUMPAD7] = KEY_KP7;
  335. keyMap[VK_NUMPAD8] = KEY_KP8;
  336. keyMap[VK_NUMPAD9] = KEY_KP9;
  337. keyMap[VK_DECIMAL] = KEY_KP_PERIOD;
  338. keyMap[VK_DIVIDE] = KEY_KP_DIVIDE;
  339. keyMap[VK_MULTIPLY] = KEY_KP_MULTIPLY;
  340. keyMap[VK_SUBTRACT] = KEY_KP_MINUS;
  341. keyMap[VK_ADD] = KEY_KP_PLUS;
  342. keyMap[VK_UP] = KEY_UP;
  343. keyMap[VK_DOWN] = KEY_DOWN;
  344. keyMap[VK_RIGHT] = KEY_RIGHT;
  345. keyMap[VK_LEFT] = KEY_LEFT;
  346. keyMap[VK_INSERT] = KEY_INSERT;
  347. keyMap[VK_HOME] = KEY_HOME;
  348. keyMap[VK_END] = KEY_END;
  349. keyMap[VK_PRIOR] = KEY_PAGEUP;
  350. keyMap[VK_NEXT] = KEY_PAGEDOWN;
  351. keyMap[VK_F1] = KEY_F1;
  352. keyMap[VK_F2] = KEY_F2;
  353. keyMap[VK_F3] = KEY_F3;
  354. keyMap[VK_F4] = KEY_F4;
  355. keyMap[VK_F5] = KEY_F5;
  356. keyMap[VK_F6] = KEY_F6;
  357. keyMap[VK_F7] = KEY_F7;
  358. keyMap[VK_F8] = KEY_F8;
  359. keyMap[VK_F9] = KEY_F9;
  360. keyMap[VK_F10] = KEY_F10;
  361. keyMap[VK_F11] = KEY_F11;
  362. keyMap[VK_F12] = KEY_F12;
  363. keyMap[VK_F13] = KEY_F13;
  364. keyMap[VK_F14] = KEY_F14;
  365. keyMap[VK_F15] = KEY_F15;
  366. keyMap[VK_NUMLOCK] = KEY_NUMLOCK;
  367. keyMap[VK_CAPITAL] = KEY_CAPSLOCK;
  368. keyMap[VK_SCROLL] = KEY_SCROLLOCK;
  369. keyMap[VK_RSHIFT] = KEY_RSHIFT;
  370. keyMap[VK_LSHIFT] = KEY_LSHIFT;
  371. keyMap[VK_RCONTROL] = KEY_RCTRL;
  372. keyMap[VK_LCONTROL] = KEY_LCTRL;
  373. keyMap[VK_RMENU] = KEY_RALT;
  374. keyMap[VK_LMENU] = KEY_LALT;
  375. keyMap[VK_RWIN] = KEY_RSUPER;
  376. keyMap[VK_LWIN] = KEY_LSUPER;
  377. keyMap[VK_HELP] = KEY_HELP;
  378. keyMap[VK_SNAPSHOT] = KEY_PRINT;
  379. keyMap[VK_CANCEL] = KEY_BREAK;
  380. keyMap[VK_APPS] = KEY_MENU;
  381. }
  382. void Win32Core::handleViewResize(int width, int height) {
  383. this->xRes = width;
  384. this->yRes = height;
  385. renderer->Resize(width, height);
  386. dispatchEvent(new Event(), EVENT_CORE_RESIZE);
  387. }
  388. PolyKEY Win32Core::mapKey(LPARAM lParam, WPARAM wParam) {
  389. switch (wParam) {
  390. case VK_CONTROL:
  391. if ( lParam&EXTENDED_KEYMASK )
  392. wParam = VK_RCONTROL;
  393. else
  394. wParam = VK_LCONTROL;
  395. break;
  396. case 33:
  397. if ( lParam&EXTENDED_KEYMASK )
  398. wParam = VK_RMENU;
  399. else
  400. wParam = VK_LMENU;
  401. break;
  402. }
  403. return keyMap[(unsigned int)wParam];
  404. }
  405. void Win32Core::handleKeyDown(LPARAM lParam, WPARAM wParam, wchar_t unicodeChar) {
  406. lockMutex(eventMutex);
  407. Win32Event newEvent;
  408. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  409. newEvent.eventCode = InputEvent::EVENT_KEYDOWN;
  410. newEvent.keyCode = mapKey(lParam, wParam);
  411. newEvent.unicodeChar = unicodeChar;
  412. win32Events.push_back(newEvent);
  413. unlockMutex(eventMutex);
  414. }
  415. void Win32Core::handleKeyUp(LPARAM lParam, WPARAM wParam) {
  416. lockMutex(eventMutex);
  417. Win32Event newEvent;
  418. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  419. newEvent.eventCode = InputEvent::EVENT_KEYUP;
  420. newEvent.keyCode = mapKey(lParam, wParam);
  421. newEvent.unicodeChar = 0;
  422. win32Events.push_back(newEvent);
  423. unlockMutex(eventMutex);
  424. }
  425. #ifndef NO_TOUCH_API
  426. void Win32Core::handleTouchEvent(LPARAM lParam, WPARAM wParam) {
  427. // Bail out now if multitouch is not available on this system
  428. if ( hasMultiTouch == false )
  429. {
  430. return;
  431. }
  432. lockMutex(eventMutex);
  433. int iNumContacts = LOWORD(wParam);
  434. HTOUCHINPUT hInput = (HTOUCHINPUT)lParam;
  435. TOUCHINPUT *pInputs = new TOUCHINPUT[iNumContacts];
  436. if(pInputs != NULL) {
  437. if(GetTouchInputInfoFunc(hInput, iNumContacts, pInputs, sizeof(TOUCHINPUT))) {
  438. std::vector<TouchInfo> touches;
  439. for(int i = 0; i < iNumContacts; i++) {
  440. TOUCHINPUT ti = pInputs[i];
  441. TouchInfo touchInfo;
  442. touchInfo.id = (int) ti.dwID;
  443. POINT pt;
  444. pt.x = TOUCH_COORD_TO_PIXEL(ti.x);
  445. pt.y = TOUCH_COORD_TO_PIXEL(ti.y);
  446. ScreenToClient(hWnd, &pt);
  447. touchInfo.position.x = pt.x;
  448. touchInfo.position.y = pt.y;
  449. touches.push_back(touchInfo);
  450. }
  451. for(int i = 0; i < iNumContacts; i++) {
  452. TOUCHINPUT ti = pInputs[i];
  453. if (ti.dwFlags & TOUCHEVENTF_UP) {
  454. Win32Event newEvent;
  455. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  456. newEvent.eventCode = InputEvent::EVENT_TOUCHES_ENDED;
  457. newEvent.touches = touches;
  458. newEvent.touch = touches[i];
  459. win32Events.push_back(newEvent);
  460. } else if(ti.dwFlags & TOUCHEVENTF_MOVE) {
  461. Win32Event newEvent;
  462. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  463. newEvent.eventCode = InputEvent::EVENT_TOUCHES_MOVED;
  464. newEvent.touches = touches;
  465. newEvent.touch = touches[i];
  466. win32Events.push_back(newEvent);
  467. } else if(ti.dwFlags & TOUCHEVENTF_DOWN) {
  468. Win32Event newEvent;
  469. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  470. newEvent.eventCode = InputEvent::EVENT_TOUCHES_BEGAN;
  471. newEvent.touches = touches;
  472. newEvent.touch = touches[i];
  473. win32Events.push_back(newEvent);
  474. }
  475. }
  476. }
  477. }
  478. unlockMutex(eventMutex);
  479. }
  480. #endif
  481. void Win32Core::handleMouseMove(LPARAM lParam, WPARAM wParam) {
  482. lockMutex(eventMutex);
  483. Win32Event newEvent;
  484. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  485. newEvent.eventCode = InputEvent::EVENT_MOUSEMOVE;
  486. newEvent.mouseX = GET_X_LPARAM(lParam);
  487. newEvent.mouseY = GET_Y_LPARAM(lParam);
  488. win32Events.push_back(newEvent);
  489. unlockMutex(eventMutex);
  490. }
  491. void Win32Core::handleMouseWheel(LPARAM lParam, WPARAM wParam) {
  492. lockMutex(eventMutex);
  493. Win32Event newEvent;
  494. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  495. newEvent.mouseX = GET_X_LPARAM(lParam);
  496. newEvent.mouseY = GET_Y_LPARAM(lParam);
  497. int zDelta = GET_WHEEL_DELTA_WPARAM(wParam);
  498. if(zDelta < 0)
  499. newEvent.eventCode = InputEvent::EVENT_MOUSEWHEEL_DOWN;
  500. else
  501. newEvent.eventCode = InputEvent::EVENT_MOUSEWHEEL_UP;
  502. win32Events.push_back(newEvent);
  503. unlockMutex(eventMutex);
  504. }
  505. void Win32Core::handleMouseDown(int mouseCode,LPARAM lParam, WPARAM wParam) {
  506. lockMutex(eventMutex);
  507. Win32Event newEvent;
  508. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  509. newEvent.mouseX = GET_X_LPARAM(lParam);
  510. newEvent.mouseY = GET_Y_LPARAM(lParam);
  511. newEvent.eventCode = InputEvent::EVENT_MOUSEDOWN;
  512. newEvent.mouseButton = mouseCode;
  513. win32Events.push_back(newEvent);
  514. unlockMutex(eventMutex);
  515. }
  516. void Win32Core::handleMouseUp(int mouseCode,LPARAM lParam, WPARAM wParam) {
  517. lockMutex(eventMutex);
  518. Win32Event newEvent;
  519. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  520. newEvent.mouseX = GET_X_LPARAM(lParam);
  521. newEvent.mouseY = GET_Y_LPARAM(lParam);
  522. newEvent.eventCode = InputEvent::EVENT_MOUSEUP;
  523. newEvent.mouseButton = mouseCode;
  524. win32Events.push_back(newEvent);
  525. unlockMutex(eventMutex);
  526. }
  527. void Win32Core::checkEvents() {
  528. lockMutex(eventMutex);
  529. Win32Event event;
  530. for(int i=0; i < win32Events.size(); i++) {
  531. event = win32Events[i];
  532. switch(event.eventGroup) {
  533. case Win32Event::INPUT_EVENT:
  534. switch(event.eventCode) {
  535. case InputEvent::EVENT_TOUCHES_BEGAN:
  536. input->touchesBegan(event.touch, event.touches, getTicks());
  537. break;
  538. case InputEvent::EVENT_TOUCHES_ENDED:
  539. input->touchesEnded(event.touch, event.touches, getTicks());
  540. break;
  541. case InputEvent::EVENT_TOUCHES_MOVED:
  542. input->touchesMoved(event.touch, event.touches, getTicks());
  543. break;
  544. case InputEvent::EVENT_MOUSEMOVE:
  545. input->setDeltaPosition(event.mouseX - lastMouseX , event.mouseY - lastMouseY);
  546. lastMouseX = event.mouseX;
  547. lastMouseY = event.mouseY;
  548. input->setMousePosition(event.mouseX, event.mouseY, getTicks());
  549. break;
  550. case InputEvent::EVENT_MOUSEDOWN:
  551. input->setMouseButtonState(event.mouseButton, true, getTicks());
  552. break;
  553. case InputEvent::EVENT_MOUSEUP:
  554. input->setMouseButtonState(event.mouseButton, false, getTicks());
  555. break;
  556. case InputEvent::EVENT_KEYDOWN:
  557. input->setKeyState(event.keyCode, (char)event.unicodeChar, true, getTicks());
  558. break;
  559. case InputEvent::EVENT_KEYUP:
  560. input->setKeyState(event.keyCode, (char)event.unicodeChar, false, getTicks());
  561. break;
  562. }
  563. break;
  564. }
  565. }
  566. win32Events.clear();
  567. unlockMutex(eventMutex);
  568. }
  569. void Win32Core::handleAxisChange(GamepadDeviceEntry * device, int axisIndex, DWORD value) {
  570. if (axisIndex < 0 || axisIndex >= (int) device->numAxes) {
  571. return;
  572. }
  573. Gamepad_devicePrivate *devicePrivate = device->privateData;
  574. float floatVal = (value - devicePrivate->axisRanges[axisIndex][0]) / (float) (devicePrivate->axisRanges[axisIndex][1] - devicePrivate->axisRanges[axisIndex][0]) * 2.0f - 1.0f;
  575. input->joystickAxisMoved(axisIndex, floatVal, device->deviceID);
  576. }
  577. void Win32Core::handleButtonChange(GamepadDeviceEntry * device, DWORD lastValue, DWORD value) {
  578. Gamepad_devicePrivate *devicePrivate = device->privateData;
  579. unsigned int buttonIndex;
  580. for (buttonIndex = 0; buttonIndex < device->numButtons; buttonIndex++) {
  581. if ((lastValue ^ value) & (1 << buttonIndex)) {
  582. if(!!(value & (1 << buttonIndex))) {
  583. input->joystickButtonDown(buttonIndex, device->deviceID);
  584. } else {
  585. input->joystickButtonUp(buttonIndex, device->deviceID);
  586. }
  587. }
  588. }
  589. }
  590. static void povToXY(DWORD pov, int * outX, int * outY) {
  591. if (pov == JOY_POVCENTERED) {
  592. *outX = *outY = 0;
  593. } else {
  594. if (pov > JOY_POVFORWARD && pov < JOY_POVBACKWARD) {
  595. *outX = 1;
  596. } else if (pov > JOY_POVBACKWARD) {
  597. *outX = -1;
  598. } else {
  599. *outX = 0;
  600. }
  601. if (pov > JOY_POVLEFT || pov < JOY_POVRIGHT) {
  602. *outY = -1;
  603. } else if (pov > JOY_POVRIGHT && pov < JOY_POVLEFT) {
  604. *outY = 1;
  605. } else {
  606. *outY = 0;
  607. }
  608. }
  609. }
  610. void Win32Core::handlePOVChange(GamepadDeviceEntry * device, DWORD lastValue, DWORD value) {
  611. Gamepad_devicePrivate *devicePrivate = device->privateData;
  612. int lastX, lastY, newX, newY;
  613. if (devicePrivate->povXAxisIndex == -1 || devicePrivate->povYAxisIndex == -1) {
  614. return;
  615. }
  616. povToXY(lastValue, &lastX, &lastY);
  617. povToXY(value, &newX, &newY);
  618. if (newX != lastX) {
  619. input->joystickAxisMoved(devicePrivate->povXAxisIndex, newX, device->deviceID);
  620. }
  621. if (newY != lastY) {
  622. input->joystickAxisMoved(devicePrivate->povYAxisIndex, newY, device->deviceID);
  623. }
  624. }
  625. void Win32Core::Gamepad_processEvents() {
  626. if(getTicks() > lastGamepadDetect + 3000) {
  627. detectGamepads();
  628. }
  629. unsigned int deviceIndex;
  630. JOYINFOEX info;
  631. MMRESULT result;
  632. GamepadDeviceEntry * device;
  633. Gamepad_devicePrivate * devicePrivate;
  634. for (deviceIndex = 0; deviceIndex < gamepads.size(); deviceIndex++) {
  635. device = gamepads[deviceIndex];
  636. devicePrivate = device->privateData;
  637. info.dwSize = sizeof(info);
  638. info.dwFlags = JOY_RETURNALL;
  639. result = joyGetPosEx(devicePrivate->joystickID, &info);
  640. if (result == JOYERR_UNPLUGGED) {
  641. input->removeJoystick(device->deviceID);
  642. gamepads.erase(gamepads.begin() + deviceIndex);
  643. } else if (result == JOYERR_NOERROR) {
  644. if (info.dwXpos != devicePrivate->lastState.dwXpos) {
  645. handleAxisChange(device, devicePrivate->xAxisIndex, info.dwXpos);
  646. }
  647. if (info.dwYpos != devicePrivate->lastState.dwYpos) {
  648. handleAxisChange(device, devicePrivate->yAxisIndex, info.dwYpos);
  649. }
  650. if (info.dwZpos != devicePrivate->lastState.dwZpos) {
  651. handleAxisChange(device, devicePrivate->zAxisIndex, info.dwZpos);
  652. }
  653. if (info.dwRpos != devicePrivate->lastState.dwRpos) {
  654. handleAxisChange(device, devicePrivate->rAxisIndex, info.dwRpos);
  655. }
  656. if (info.dwUpos != devicePrivate->lastState.dwUpos) {
  657. handleAxisChange(device, devicePrivate->uAxisIndex, info.dwUpos);
  658. }
  659. if (info.dwVpos != devicePrivate->lastState.dwVpos) {
  660. handleAxisChange(device, devicePrivate->vAxisIndex, info.dwVpos);
  661. }
  662. if (info.dwPOV != devicePrivate->lastState.dwPOV) {
  663. handlePOVChange(device, devicePrivate->lastState.dwPOV, info.dwPOV);
  664. }
  665. if (info.dwButtons != devicePrivate->lastState.dwButtons) {
  666. handleButtonChange(device, devicePrivate->lastState.dwButtons, info.dwButtons);
  667. }
  668. devicePrivate->lastState = info;
  669. }
  670. }
  671. }
  672. void Win32Core::detectGamepads() {
  673. lastGamepadDetect = getTicks();
  674. unsigned int numPadsSupported;
  675. unsigned int deviceIndex, deviceIndex2;
  676. JOYINFOEX info;
  677. JOYCAPS caps;
  678. bool duplicate;
  679. Gamepad_devicePrivate * deviceRecordPrivate;
  680. UINT joystickID;
  681. int axisIndex;
  682. numPadsSupported = joyGetNumDevs();
  683. for (deviceIndex = 0; deviceIndex < numPadsSupported; deviceIndex++) {
  684. info.dwSize = sizeof(info);
  685. info.dwFlags = JOY_RETURNALL;
  686. joystickID = JOYSTICKID1 + deviceIndex;
  687. if (joyGetPosEx(joystickID, &info) == JOYERR_NOERROR &&
  688. joyGetDevCaps(joystickID, &caps, sizeof(JOYCAPS)) == JOYERR_NOERROR) {
  689. duplicate = false;
  690. for (deviceIndex2 = 0; deviceIndex2 < gamepads.size(); deviceIndex2++) {
  691. if (((Gamepad_devicePrivate *) gamepads[deviceIndex2]->privateData)->joystickID == joystickID) {
  692. duplicate = true;
  693. break;
  694. }
  695. }
  696. if (duplicate) {
  697. continue;
  698. }
  699. GamepadDeviceEntry *deviceRecord = new GamepadDeviceEntry();
  700. deviceRecord->deviceID = nextDeviceID++;
  701. // deviceRecord->description = getDeviceDescription(joystickID, caps);
  702. // deviceRecord->vendorID = caps.wMid;
  703. // deviceRecord->productID = caps.wPid;
  704. deviceRecord->numAxes = caps.wNumAxes + ((caps.wCaps & JOYCAPS_HASPOV) ? 2 : 0);
  705. deviceRecord->numButtons = caps.wNumButtons;
  706. // deviceRecord->axisStates = calloc(sizeof(float), deviceRecord->numAxes);
  707. // deviceRecord->buttonStates = calloc(sizeof(bool), deviceRecord->numButtons);
  708. // deviceRecord->eventDispatcher = EventDispatcher_create(deviceRecord);
  709. // devices = realloc(devices, sizeof(struct Gamepad_device *) * (numDevices + 1));
  710. gamepads.push_back(deviceRecord);
  711. deviceRecordPrivate = new Gamepad_devicePrivate();
  712. deviceRecordPrivate->joystickID = joystickID;
  713. deviceRecordPrivate->lastState = info;
  714. deviceRecordPrivate->xAxisIndex = 0;
  715. deviceRecordPrivate->yAxisIndex = 1;
  716. axisIndex = 2;
  717. deviceRecordPrivate->zAxisIndex = (caps.wCaps & JOYCAPS_HASZ) ? axisIndex++ : -1;
  718. deviceRecordPrivate->rAxisIndex = (caps.wCaps & JOYCAPS_HASR) ? axisIndex++ : -1;
  719. deviceRecordPrivate->uAxisIndex = (caps.wCaps & JOYCAPS_HASU) ? axisIndex++ : -1;
  720. deviceRecordPrivate->vAxisIndex = (caps.wCaps & JOYCAPS_HASV) ? axisIndex++ : -1;
  721. deviceRecordPrivate->axisRanges = (UINT (*)[2]) malloc(sizeof(UINT[2]) * axisIndex);
  722. deviceRecordPrivate->axisRanges[0][0] = caps.wXmin;
  723. deviceRecordPrivate->axisRanges[0][1] = caps.wXmax;
  724. deviceRecordPrivate->axisRanges[1][0] = caps.wYmin;
  725. deviceRecordPrivate->axisRanges[1][1] = caps.wYmax;
  726. if (deviceRecordPrivate->zAxisIndex != -1) {
  727. deviceRecordPrivate->axisRanges[deviceRecordPrivate->zAxisIndex][0] = caps.wZmin;
  728. deviceRecordPrivate->axisRanges[deviceRecordPrivate->zAxisIndex][1] = caps.wZmax;
  729. }
  730. if (deviceRecordPrivate->rAxisIndex != -1) {
  731. deviceRecordPrivate->axisRanges[deviceRecordPrivate->rAxisIndex][0] = caps.wRmin;
  732. deviceRecordPrivate->axisRanges[deviceRecordPrivate->rAxisIndex][1] = caps.wRmax;
  733. }
  734. if (deviceRecordPrivate->uAxisIndex != -1) {
  735. deviceRecordPrivate->axisRanges[deviceRecordPrivate->uAxisIndex][0] = caps.wUmin;
  736. deviceRecordPrivate->axisRanges[deviceRecordPrivate->uAxisIndex][1] = caps.wUmax;
  737. }
  738. if (deviceRecordPrivate->vAxisIndex != -1) {
  739. deviceRecordPrivate->axisRanges[deviceRecordPrivate->vAxisIndex][0] = caps.wVmin;
  740. deviceRecordPrivate->axisRanges[deviceRecordPrivate->vAxisIndex][1] = caps.wVmax;
  741. }
  742. deviceRecordPrivate->povXAxisIndex = (caps.wCaps & JOYCAPS_HASPOV) ? axisIndex++ : -1;
  743. deviceRecordPrivate->povYAxisIndex = (caps.wCaps & JOYCAPS_HASPOV) ? axisIndex++ : -1;
  744. deviceRecord->privateData = deviceRecordPrivate;
  745. input->addJoystick(deviceRecord->deviceID);
  746. }
  747. }
  748. }
  749. void Win32Core::initGamepad() {
  750. nextDeviceID = 0;
  751. detectGamepads();
  752. }
  753. void Win32Core::shutdownGamepad() {
  754. }
  755. void Win32Core::initTouch() {
  756. #ifdef NO_TOUCH_API
  757. hasMultiTouch = false;
  758. #else
  759. // Check for windows multitouch support at runtime
  760. // This could be done easily during preprocessing but would require building
  761. // multiple releases of polycode for both winxp/vista and win7
  762. GetTouchInputInfoFunc = (GetTouchInputInfoType) GetProcAddress(GetModuleHandle(TEXT("user32")), "GetTouchInputInfo");
  763. // If the above multitouch functions were found, then set a flag so we don't
  764. // have to check again later
  765. hasMultiTouch = ( GetTouchInputInfoFunc == NULL ) ? false : true;
  766. if(hasMultiTouch) {
  767. RegisterTouchWindow(hWnd, 0);
  768. }
  769. #endif
  770. }
  771. DWORD WINAPI Win32LaunchThread(LPVOID data) {
  772. Threaded *threaded = (Threaded*)data;
  773. threaded->runThread();
  774. return 1;
  775. }
  776. void Win32Core::createThread(Threaded *target) {
  777. DWORD dwGenericThread;
  778. HANDLE handle = CreateThread(NULL,0,Win32LaunchThread,target,0,&dwGenericThread);
  779. }
  780. void Win32Core::lockMutex(CoreMutex *mutex) {
  781. WaitForSingleObject(((Win32Mutex*)mutex)->winMutex,INFINITE);
  782. }
  783. void Win32Core::unlockMutex(CoreMutex *mutex) {
  784. ReleaseMutex(((Win32Mutex*)mutex)->winMutex);
  785. }
  786. void Win32Core::platformSleep(int msecs) {
  787. Sleep(msecs);
  788. }
  789. CoreMutex *Win32Core::createMutex() {
  790. Win32Mutex *newMutex = new Win32Mutex();
  791. newMutex->winMutex = CreateMutex( NULL, FALSE, NULL);
  792. return newMutex;
  793. }
  794. std::vector<Polycode::Rectangle> Win32Core::getVideoModes() {
  795. std::vector<Polycode::Rectangle> retVector;
  796. return retVector;
  797. }
  798. String Win32Core::executeExternalCommand(String command, String args, String inDirectory) {
  799. String execInDirectory = inDirectory;
  800. if(inDirectory == "") {
  801. execInDirectory = defaultWorkingDirectory;
  802. }
  803. SHELLEXECUTEINFO lpExecInfo;
  804. lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
  805. lpExecInfo.lpFile = command.getWDataWithEncoding(String::ENCODING_UTF8);
  806. lpExecInfo.fMask=SEE_MASK_DOENVSUBST|SEE_MASK_NOCLOSEPROCESS ;
  807. lpExecInfo.hwnd = NULL;
  808. lpExecInfo.lpVerb = L"open"; // to open program
  809. lpExecInfo.lpParameters = args.getWDataWithEncoding(String::ENCODING_UTF8); // file name as an argument
  810. lpExecInfo.lpDirectory = execInDirectory.getWDataWithEncoding(String::ENCODING_UTF8);
  811. lpExecInfo.nShow = SW_SHOW ; // show command prompt with normal window size
  812. lpExecInfo.hInstApp = (HINSTANCE) SE_ERR_DDEFAIL ; //WINSHELLAPI BOOL WINAPI result;
  813. ShellExecuteEx(&lpExecInfo);
  814. //wait until a file is finished printing
  815. if(lpExecInfo.hProcess !=NULL)
  816. {
  817. ::WaitForSingleObject(lpExecInfo.hProcess, INFINITE);
  818. ::CloseHandle(lpExecInfo.hProcess);
  819. }
  820. return "";
  821. }
  822. std::vector<String> Win32Core::openFilePicker(std::vector<CoreFileExtension> extensions, bool allowMultiple) {
  823. OPENFILENAME ofn;
  824. wchar_t fBuffer[2048];
  825. wchar_t filterString[2048];
  826. ZeroMemory(&ofn, sizeof(OPENFILENAME));
  827. ofn.lStructSize = sizeof ( ofn );
  828. ofn.hwndOwner = hWnd ;
  829. ofn.lpstrFile = fBuffer;
  830. ofn.lpstrFile[0] = '\0';
  831. ofn.nMaxFile = sizeof( fBuffer );
  832. if(extensions.size() > 0) {
  833. int offset = 0;
  834. for(int i =0; i < extensions.size(); i++) {
  835. // filterString += extensions[i].description+"\0*."+extensions[i].extension+"\0";
  836. memcpy(filterString+offset, extensions[i].description.getWDataWithEncoding(String::ENCODING_UTF8), extensions[i].description.length() * sizeof(wchar_t));
  837. offset += extensions[i].description.length();
  838. filterString[offset] = '\0';
  839. offset++;
  840. filterString[offset] = '*';
  841. offset++;
  842. filterString[offset] = '.';
  843. offset++;
  844. memcpy(filterString+offset, extensions[i].extension.getWDataWithEncoding(String::ENCODING_UTF8), extensions[i].extension.length() * sizeof(wchar_t));
  845. offset += extensions[i].extension.length();
  846. filterString[offset] = '\0';
  847. offset++;
  848. }
  849. filterString[offset] = '\0';
  850. ofn.lpstrFilter = filterString;
  851. ofn.nFilterIndex = 1;
  852. } else {
  853. ofn.lpstrFilter = NULL;
  854. }
  855. ofn.lpstrFileTitle = NULL;
  856. ofn.nMaxFileTitle = 0;
  857. ofn.lpstrInitialDir=NULL;
  858. if(allowMultiple) {
  859. ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_EXPLORER;
  860. } else {
  861. ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT|OFN_EXPLORER;
  862. }
  863. std::vector<String> retVec;
  864. if(GetOpenFileName(&ofn)) {
  865. if(allowMultiple) {
  866. } else {
  867. retVec.push_back(String(fBuffer));
  868. }
  869. }
  870. SetCurrentDirectory(defaultWorkingDirectory.getWDataWithEncoding(String::ENCODING_UTF8));
  871. for(int i=0; i < retVec.size(); i++) {
  872. retVec[i] = retVec[i].replace("\\", "/");
  873. }
  874. return retVec;
  875. }
  876. void Win32Core::createFolder(const String& folderPath) {
  877. String path = folderPath;
  878. CreateDirectory(path.getWDataWithEncoding(String::ENCODING_UTF8), NULL);
  879. }
  880. void Win32Core::openURL(String url) {
  881. ShellExecute(NULL, L"open", url.getWDataWithEncoding(String::ENCODING_UTF8), NULL, NULL, SW_SHOWNORMAL);
  882. }