World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
Win.cpp
См. документацию.
1 #include "Platform/Win/Win.h"
2 
3 #include <cstdio>
4 #include <string>
5 #include <vector>
6 
7 #include "src/Application/Game.h"
8 
9 #include "Platform/Api.h"
10 
11 #pragma comment(lib, "winmm.lib")
12 
13 void OS_MsgBox(const char *msg, const char *title) {
14  MessageBoxA(nullptr, msg, title, 0);
15 }
16 
17 unsigned int OS_GetTime() { return GetTickCount(); }
18 
19 unsigned __int64 OS_GetPrecisionTime() { return timeGetTime(); }
20 
21 bool OS_IfShiftPressed() { return GetAsyncKeyState(VK_SHIFT); }
22 
23 bool OS_IfCtrlPressed() { return GetAsyncKeyState(VK_CONTROL); }
24 
25 void OS_ShowCursor(bool show) { ShowCursor(show ? 1 : 0); }
26 
27 void OS_WaitMessage() { WaitMessage(); }
28 
29 void OS_Sleep(int ms) { Sleep(ms); }
30 
32  POINT pt;
33  GetCursorPos(&pt);
34 
35  return Point(pt.x, pt.y);
36 }
37 
39  if (AllocConsole()) {
40  freopen("conin$", "r", stdin);
41  freopen("conout$", "w", stdout);
42  freopen("conout$", "w", stderr);
43 
44  return true;
45  }
46 
47  return false;
48 }
49 
50 std::vector<std::string> OS_FindFiles(const std::string &folder, const std::string &mask) {
51  std::vector<std::string> result;
52 
53  std::string path = folder + "\\" + mask;
54 
55  WIN32_FIND_DATAA ffd = { 0 };
56  HANDLE hFind = FindFirstFileA(path.c_str(), &ffd);
57  if (INVALID_HANDLE_VALUE == hFind) {
58  return result;
59  }
60 
61  do {
62  if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
63  result.push_back(ffd.cFileName);
64  }
65  } while (FindNextFileA(hFind, &ffd) != 0);
66 
67  FindClose(hFind);
68 
69  return result;
70 }
OS_FindFiles
std::vector< std::string > OS_FindFiles(const std::string &folder, const std::string &mask)
Definition: Win.cpp:50
OS_MsgBox
void OS_MsgBox(const char *msg, const char *title)
Definition: Win.cpp:13
mask
GLenum GLint GLuint mask
Definition: SDL_opengl_glext.h:660
Game.h
OS_GetTime
unsigned int OS_GetTime()
Definition: Win.cpp:17
path
GLsizei const GLchar *const * path
Definition: SDL_opengl_glext.h:3733
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9435
GetAsyncKeyState
int GetAsyncKeyState(int vKey)
Definition: Keyboard.cpp:8
OS_Sleep
void OS_Sleep(int ms)
Definition: Win.cpp:29
OS_IfCtrlPressed
bool OS_IfCtrlPressed()
Definition: Win.cpp:23
OS_OpenConsole
bool OS_OpenConsole()
Definition: Win.cpp:38
OS_ShowCursor
void OS_ShowCursor(bool show)
Definition: Win.cpp:25
OS_GetPrecisionTime
unsigned __int64 OS_GetPrecisionTime()
Definition: Win.cpp:19
OS_IfShiftPressed
bool OS_IfShiftPressed()
Definition: Win.cpp:21
string
GLsizei const GLchar *const * string
Definition: SDL_opengl_glext.h:691
Point
Definition: Point.h:3
Win.h
OS_WaitMessage
void OS_WaitMessage()
Definition: Win.cpp:27
OS_GetMouseCursorPos
Point OS_GetMouseCursorPos()
Definition: Win.cpp:31
Api.h