Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
prism/platforms/windows/windows.cpp

92 lines
2.1 KiB
C++
Raw Normal View History

2020-08-11 12:07:21 -04:00
#include "platform.hpp"
#include <tchar.h>
#include <windows.h>
#include <winuser.h>
#include <thread>
#include <map>
std::map<InputButton, int> inputToKeyCode = { {
{InputButton::C, 67},
{InputButton::V, 86},
{InputButton::X, 58},
{InputButton::Y, 59},
{InputButton::Z, 60},
{InputButton::Backspace, 8},
{InputButton::Enter, 4},
{InputButton::Space, 20},
{InputButton::Ctrl, 17},
{InputButton::Shift, 10},
{InputButton::A, 65},
{InputButton::W, 87},
{InputButton::S, 83},
{InputButton::D, 68},
{InputButton::Escape, 27},
{InputButton::Tab, 9}
}};
const char* platform::get_name() {
return "Windows";
}
bool platform::get_key_down(const InputButton key) {
if (inputToKeyCode.count(key)) {
return (GetKeyState(inputToKeyCode[key]) & 0x8000) != 0;
}
}
int platform::get_keycode(const InputButton key) {
return inputToKeyCode[key];
}
2020-08-13 07:48:50 -04:00
void platform::open_dialog(const bool existing, const std::function<void(std::string)> returnFunction, const bool openDirectory) {
2020-08-11 12:07:21 -04:00
const auto openDialog = [returnFunction] {
const int BUFSIZE = 1024;
char buffer[BUFSIZE] = { 0 };
OPENFILENAME ofns = { 0 };
ofns.lStructSize = sizeof(ofns);
ofns.lpstrFile = buffer;
ofns.nMaxFile = BUFSIZE;
ofns.lpstrTitle = "Open File";
if (GetOpenFileName(&ofns))
returnFunction(buffer);
};
std::thread* ot = new std::thread(openDialog);
}
void platform::save_dialog(const std::function<void(std::string)> returnFunction) {
const auto saveDialog = [returnFunction] {
const int BUFSIZE = 1024;
char buffer[BUFSIZE] = { 0 };
OPENFILENAME ofns = { 0 };
ofns.lStructSize = sizeof(ofns);
ofns.lpstrFile = buffer;
ofns.nMaxFile = BUFSIZE;
ofns.lpstrTitle = "Save File";
if (GetSaveFileName(&ofns))
returnFunction(buffer);
};
std::thread* ot = new std::thread(saveDialog);
}
char* platform::translate_keycode(const unsigned int keycode) {
char* uc = new char[5];
BYTE kb[256];
GetKeyboardState(kb);
ToUnicode(keycode, 0, kb, (LPWSTR)uc, 4, 0);
return uc;
}
void platform::mute_output() {
}
void platform::unmute_output() {
}