Fix window resize on windows
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
enum class WindowsScancode {
|
||||
Nothing = 0,
|
||||
Nothing = 0,
|
||||
ESCAPE = 0x1B, // VK_ESCAPE
|
||||
ONE = 0x31, // '1'
|
||||
TWO = 0x32, // '2'
|
||||
@@ -43,7 +43,7 @@ enum class WindowsScancode {
|
||||
SEMICOLON = 0xBA, // VK_OEM_1
|
||||
SINGLEQUOTE = 0xDE, // VK_OEM_7
|
||||
GRAVE = 0xC0, // VK_OEM_3
|
||||
LEFT_SHIFT = 0xA0, // VK_LSHIFT
|
||||
LEFT_SHIFT = 0x10, // VK_LSHIFT
|
||||
BACKSLASH = 0xDC, // VK_OEM_5
|
||||
Z = 0x5A, // 'Z'
|
||||
X = 0x58, // 'X'
|
||||
@@ -52,7 +52,6 @@ enum class WindowsScancode {
|
||||
B = 0x42, // 'B'
|
||||
N = 0x4E, // 'N'
|
||||
M = 0x4D, // 'M'
|
||||
COMMA = 0xBC, // VK_OEM_COMMA
|
||||
PERIOD = 0xBE, // VK_OEM_PERIOD
|
||||
SLASH = 0xBF, // VK_OEM_2
|
||||
RIGHT_SHIFT = 0xA1, // VK_RSHIFT
|
||||
@@ -98,5 +97,11 @@ enum class WindowsScancode {
|
||||
NUMPAD_PLUS = 0x6B, // VK_ADD
|
||||
NUMPAD_MINUS = 0x6D, // VK_SUBTRACT
|
||||
NUMPAD_DECIMAL = 0x6E, // VK_DECIMAL
|
||||
NUMPAD_ENTER = 0x0D // VK_RETURN
|
||||
NUMPAD_ENTER = 0x0D, // VK_RETURN
|
||||
SUPER = 0x5B,
|
||||
|
||||
TILDE = 192,
|
||||
COMMA = 0xBC,
|
||||
MENU = 93,
|
||||
|
||||
};
|
@@ -33,30 +33,31 @@ public:
|
||||
namespace Keys {
|
||||
// TODO: Encode both Uppercase and Lowercase version for each keymap
|
||||
static const Key Escape {"\b", X11Scancode::ESCAPE, WindowsScancode::ESCAPE};
|
||||
static const Key F1 {"\u000f", X11Scancode::F1, WindowsScancode::F1};
|
||||
static const Key F2 {"\u000f", X11Scancode::F2, WindowsScancode::F2};
|
||||
static const Key F3 {"\u000f", X11Scancode::F3, WindowsScancode::F3};
|
||||
static const Key F4 {"\u000f", X11Scancode::F4, WindowsScancode::F4};
|
||||
static const Key F5 {"\u000f", X11Scancode::F5, WindowsScancode::F5};
|
||||
static const Key F6 {"\u000f", X11Scancode::F6, WindowsScancode::F6};
|
||||
static const Key F7 {"\u000f", X11Scancode::F7, WindowsScancode::F7};
|
||||
static const Key F8 {"\u000f", X11Scancode::F8, WindowsScancode::F8};
|
||||
static const Key F9 {"\u000f", X11Scancode::F9, WindowsScancode::F9};
|
||||
static const Key F10 {"\u000f", X11Scancode::F10, WindowsScancode::F10};
|
||||
static const Key F11 {"\u000f", X11Scancode::F11, WindowsScancode::F11};
|
||||
static const Key F12 {"\u000f", X11Scancode::F12, WindowsScancode::F12};
|
||||
static const Key F1 {"F1", X11Scancode::F1, WindowsScancode::F1};
|
||||
static const Key F2 {"F2", X11Scancode::F2, WindowsScancode::F2};
|
||||
static const Key F3 {"F3", X11Scancode::F3, WindowsScancode::F3};
|
||||
static const Key F4 {"F4", X11Scancode::F4, WindowsScancode::F4};
|
||||
static const Key F5 {"F5", X11Scancode::F5, WindowsScancode::F5};
|
||||
static const Key F6 {"F6", X11Scancode::F6, WindowsScancode::F6};
|
||||
static const Key F7 {"F7", X11Scancode::F7, WindowsScancode::F7};
|
||||
static const Key F8 {"F8", X11Scancode::F8, WindowsScancode::F8};
|
||||
static const Key F9 {"F9", X11Scancode::F9, WindowsScancode::F9};
|
||||
static const Key F10 {"F10", X11Scancode::F10, WindowsScancode::F10};
|
||||
static const Key F11 {"F11", X11Scancode::F11, WindowsScancode::F11};
|
||||
static const Key F12 {"F12", X11Scancode::F12, WindowsScancode::F12};
|
||||
|
||||
static const Key NumPad1 {"\b", X11Scancode::KP_1, WindowsScancode::NUMPAD_ONE};
|
||||
static const Key NumPad2 {"\b", X11Scancode::KP_2, WindowsScancode::NUMPAD_TWO};
|
||||
static const Key NumPad3 {"\b", X11Scancode::KP_3, WindowsScancode::NUMPAD_THREE};
|
||||
static const Key NumPad4 {"\b", X11Scancode::KP_4, WindowsScancode::NUMPAD_FOUR};
|
||||
static const Key NumPad5 {"\b", X11Scancode::KP_5, WindowsScancode::NUMPAD_FIVE};
|
||||
static const Key NumPad6 {"\b", X11Scancode::KP_6, WindowsScancode::NUMPAD_SIX};
|
||||
static const Key NumPad7 {"\b", X11Scancode::KP_7, WindowsScancode::NUMPAD_SEVEN};
|
||||
static const Key NumPad8 {"\b", X11Scancode::KP_8, WindowsScancode::NUMPAD_EIGHT};
|
||||
static const Key NumPad9 {"\b", X11Scancode::KP_9, WindowsScancode::NUMPAD_NINE};
|
||||
static const Key NumPad0 {"\b", X11Scancode::KP_0, WindowsScancode::NUMPAD_ZERO};
|
||||
static const Key NumPad1 {"KP1", X11Scancode::KP_1, WindowsScancode::NUMPAD_ONE};
|
||||
static const Key NumPad2 {"KP2", X11Scancode::KP_2, WindowsScancode::NUMPAD_TWO};
|
||||
static const Key NumPad3 {"KP3", X11Scancode::KP_3, WindowsScancode::NUMPAD_THREE};
|
||||
static const Key NumPad4 {"KP4", X11Scancode::KP_4, WindowsScancode::NUMPAD_FOUR};
|
||||
static const Key NumPad5 {"KP5", X11Scancode::KP_5, WindowsScancode::NUMPAD_FIVE};
|
||||
static const Key NumPad6 {"KP6", X11Scancode::KP_6, WindowsScancode::NUMPAD_SIX};
|
||||
static const Key NumPad7 {"KP7", X11Scancode::KP_7, WindowsScancode::NUMPAD_SEVEN};
|
||||
static const Key NumPad8 {"kP8", X11Scancode::KP_8, WindowsScancode::NUMPAD_EIGHT};
|
||||
static const Key NumPad9 {"KP9", X11Scancode::KP_9, WindowsScancode::NUMPAD_NINE};
|
||||
static const Key NumPad0 {"KP0", X11Scancode::KP_0, WindowsScancode::NUMPAD_ZERO};
|
||||
|
||||
//static const Key Tilde {"~", X11Scancode::TILDE, WindowsScancode::TILDE};
|
||||
static const Key One {"1", X11Scancode::ONE, WindowsScancode::ONE};
|
||||
static const Key Two {"2", X11Scancode::TWO, WindowsScancode::TWO};
|
||||
static const Key Three {"3", X11Scancode::THREE, WindowsScancode::THREE};
|
||||
@@ -89,7 +90,7 @@ namespace Keys {
|
||||
static const Key L {"L", X11Scancode::L, WindowsScancode::L};
|
||||
static const Key Semicolon {";", X11Scancode::SEMICOLON, WindowsScancode::SEMICOLON};
|
||||
static const Key SingeQuote {"\"", X11Scancode::SINGLEQUOTE, WindowsScancode::SINGLEQUOTE};
|
||||
static const Key Enter {"\n", X11Scancode::RETURN, WindowsScancode::ENTER};
|
||||
static const Key Enter {"↵", X11Scancode::RETURN, WindowsScancode::ENTER};
|
||||
//static const Key KeyPadEnter {"\n", X11Scancode::KP_RETURN};
|
||||
static const Key Minus {"-", X11Scancode::MINUS, WindowsScancode::MINUS};
|
||||
//static const Key KeyPadMinus {"-", X11Scancode::KP_MINUS};
|
||||
@@ -110,20 +111,23 @@ namespace Keys {
|
||||
static const Key LControl {"\\", X11Scancode::LEFT_CTRL, WindowsScancode::CTRL};
|
||||
static const Key RControl {"\\", X11Scancode::RIGHT_CONTROL, WindowsScancode::CTRL};
|
||||
|
||||
static const Key LAlt {"\\", X11Scancode::LEFT_ALT, WindowsScancode::ALT};
|
||||
static const Key RAlt {"\\", X11Scancode::RIGHT_ALT, WindowsScancode::ALT};
|
||||
static const Key LAlt {"🄰", X11Scancode::LEFT_ALT, WindowsScancode::ALT};
|
||||
static const Key RAlt {"R🄰", X11Scancode::RIGHT_ALT, WindowsScancode::ALT};
|
||||
|
||||
static const Key LShift {"\\", X11Scancode::LEFT_SHIFT, WindowsScancode::LEFT_SHIFT};
|
||||
static const Key RShift {"\\", X11Scancode::RIGHT_SHIFT, WindowsScancode::RIGHT_SHIFT};
|
||||
static const Key LShift {"⇧", X11Scancode::LEFT_SHIFT, WindowsScancode::LEFT_SHIFT};
|
||||
static const Key RShift {"R⇧", X11Scancode::RIGHT_SHIFT, WindowsScancode::RIGHT_SHIFT};
|
||||
|
||||
static const Key UpArrow {reinterpret_cast<const char*>(u8"↑"), X11Scancode::UP, WindowsScancode::UP_ARROW};
|
||||
static const Key DownArrow {reinterpret_cast<const char*>(u8"↓"), X11Scancode::DOWN, WindowsScancode::DOWN_ARROW};
|
||||
static const Key LeftArrow {reinterpret_cast<const char*>(u8"←"), X11Scancode::LEFT, WindowsScancode::LEFT_ARROW};
|
||||
static const Key RightArrow {reinterpret_cast<const char*>(u8"→"), X11Scancode::RIGHT, WindowsScancode::RIGHT_ARROW};
|
||||
|
||||
static const Key Super {"\000a", X11Scancode::SUPER, WindowsScancode::Nothing};
|
||||
static const Key Backspace {"\b", X11Scancode::BACKSPACE, WindowsScancode::BACKSPACE};
|
||||
|
||||
//static const Key Menu = {"▤", X11Scancode::MENU, WindowsScancode::MENU};
|
||||
static const Key Comma = {",", X11Scancode::COMMA, WindowsScancode::COMMA};
|
||||
static const Key Super {"❖", X11Scancode::SUPER, WindowsScancode::SUPER};
|
||||
static const Key CapsLock = {"CAPS", X11Scancode::CAPSLOCK, WindowsScancode::CAPS_LOCK};
|
||||
static const Key Backspace {"⌫", X11Scancode::BACKSPACE, WindowsScancode::BACKSPACE};
|
||||
static const Key Tab {"⇥", X11Scancode::TAB, WindowsScancode::TAB};
|
||||
static const Key LeftBracket {"[", X11Scancode::OPENING_SQUARE_BRACKET, WindowsScancode::LEFT_BRACKET};
|
||||
static const Key RightBracket {"]", X11Scancode::CLOSING_SQUARE_BRACKET, WindowsScancode::RIGHT_BRACKET};
|
||||
}
|
||||
|
2
main.cpp
2
main.cpp
@@ -45,7 +45,7 @@ int main() {
|
||||
DEBUG("TODO: Cannot set flags until after window is open")
|
||||
window->setFullscreen(false);
|
||||
window->setVsyncEnabled(false);
|
||||
window->setResizable(false);
|
||||
window->setResizable(true);
|
||||
DEBUG(std::format("Window '{}' flags: IN_FOCUS={} FULLSCREEN={} RESIZEABLE={} VSYNC={} QUIT={}",
|
||||
window->getTitle(),
|
||||
window->getFlag(RWindowFlags::IN_FOCUS),
|
||||
|
@@ -19,7 +19,9 @@ void RWindow::setFlag(RWindowFlags flag, bool state) {
|
||||
if (flag == RWindowFlags::RESIZABLE && !state) {
|
||||
RECT rect;
|
||||
GetWindowRect(hwnd, &rect);
|
||||
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_THICKFRAME);
|
||||
LONG style = GetWindowLong(hwnd, GWL_STYLE);
|
||||
style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
|
||||
SetWindowLong(hwnd, GWL_STYLE, style);
|
||||
SetWindowPos(hwnd, nullptr, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
|
||||
}
|
||||
}
|
||||
@@ -34,7 +36,6 @@ void RWindow::pollEvents() {
|
||||
|
||||
void RWindow::setSize(int newWidth, int newHeight) {
|
||||
if (!getFlag(RWindowFlags::RESIZABLE)) return;
|
||||
|
||||
this->width = newWidth;
|
||||
this->height = newHeight;
|
||||
SetWindowPos(hwnd, nullptr, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
|
||||
|
Reference in New Issue
Block a user