Refactoring
This commit is contained in:
@@ -40,7 +40,9 @@ endif()
|
||||
include_directories("include")
|
||||
add_library(ReWindowLibrary SHARED ${SOURCES}
|
||||
include/rewindow/data/X11Scancodes.h
|
||||
include/rewindow/types/key.h)
|
||||
include/rewindow/types/key.h
|
||||
include/rewindow/data/WindowsScancodes.h
|
||||
)
|
||||
# Why god???
|
||||
set_target_properties(ReWindowLibrary PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
|
95
include/rewindow/data/WindowsScancodes.h
Normal file
95
include/rewindow/data/WindowsScancodes.h
Normal file
@@ -0,0 +1,95 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
enum class WindowsScancode {
|
||||
Nothing = 0,
|
||||
ESCAPE = 0x01,
|
||||
ONE = 0x02,
|
||||
TWO = 0x03,
|
||||
THREE = 0x04,
|
||||
FOUR = 0x05,
|
||||
FIVE = 0x06,
|
||||
SIX = 0x07,
|
||||
SEVEN = 0x08,
|
||||
EIGHT = 0x09,
|
||||
NINE = 0x0A,
|
||||
ZERO = 0x0B,
|
||||
MINUS = 0x0C,
|
||||
EQUALS = 0x0D,
|
||||
BACKSPACE = 0x0E,
|
||||
TAB = 0x0F,
|
||||
Q = 0x10,
|
||||
W = 0x11,
|
||||
E = 0x12,
|
||||
R = 0x13,
|
||||
T = 0x14,
|
||||
Y = 0x15,
|
||||
U = 0x16,
|
||||
I = 0x17,
|
||||
O = 0x18,
|
||||
P = 0x19,
|
||||
LEFT_BRACKET = 0x1A,
|
||||
RIGHT_BRACKET = 0x1B,
|
||||
ENTER = 0x1C,
|
||||
CTRL = 0x1D,
|
||||
A = 0x1E,
|
||||
S = 0x1F,
|
||||
D = 0x20,
|
||||
F = 0x21,
|
||||
G = 0x22,
|
||||
H = 0x23,
|
||||
J = 0x24,
|
||||
K = 0x25,
|
||||
L = 0x26,
|
||||
SEMICOLON = 0x27,
|
||||
SINGLEQUOTE = 0x28,
|
||||
GRAVE = 0x29,
|
||||
LEFT_SHIFT = 0x2A,
|
||||
BACKSLASH = 0x2B,
|
||||
Z = 0x2C,
|
||||
X = 0x2D,
|
||||
C = 0x2E,
|
||||
V = 0x2F,
|
||||
B = 0x30,
|
||||
N = 0x30,
|
||||
M = 0x32,
|
||||
COMMA = 0x33,
|
||||
PERIOD = 0x34,
|
||||
SLASH = 0x35,
|
||||
RIGHT_SHIFT = 0x36,
|
||||
PRINTSCREEN = 0x37,
|
||||
ALT = 0x38,
|
||||
SPACE = 0x39,
|
||||
CAPS_LOCK = 0x3A,
|
||||
F1 = 0x3B,
|
||||
F2 = 0x3C,
|
||||
F3 = 0x3D,
|
||||
F4 = 0x3E,
|
||||
F5 = 0x3F,
|
||||
F6 = 0x40,
|
||||
F7 = 0x41,
|
||||
F8 = 0x42,
|
||||
F9 = 0x43,
|
||||
F10 = 0x44,
|
||||
NUM_LOCK = 0x45,
|
||||
SCROLL_LOCK = 0x46,
|
||||
HOME = 0x47,
|
||||
UP_ARROW = 0x48,
|
||||
LEFT_ARROW,
|
||||
DOWN_ARROW,
|
||||
RIGHT_ARROW,
|
||||
PAGE_UP = 0x49,
|
||||
NUMPAD_MINUS = 0x4A,
|
||||
NUMPAD_4 = 0x4B,
|
||||
NUMPAD_5 = 0x4C,
|
||||
NUMPAD_6 = 0x4D,
|
||||
NUMPAD_PLUS = 0x4E,
|
||||
NUMPAD_ONE = 0x4F,
|
||||
NUMPAD_TWO = 0x50,
|
||||
NUMPAD_THREE = 0x51,
|
||||
NUMPAD_ZERO = 0x52,
|
||||
DELETE = 0x53,
|
||||
F11 = 0x85,
|
||||
F12 = 0x86, // FIX
|
||||
|
||||
};
|
@@ -1,3 +1,6 @@
|
||||
// @file X11Scancodes.h
|
||||
// @
|
||||
|
||||
#pragma once
|
||||
|
||||
enum class X11Scancode {
|
||||
@@ -104,98 +107,3 @@ enum class X11Scancode {
|
||||
SCROLL_LOCK = 78,
|
||||
BREAK = 127,
|
||||
};
|
||||
|
||||
enum class WindowsScancode {
|
||||
Nothing = 0,
|
||||
ESCAPE = 0x01,
|
||||
ONE = 0x02,
|
||||
TWO = 0x03,
|
||||
THREE = 0x04,
|
||||
FOUR = 0x05,
|
||||
FIVE = 0x06,
|
||||
SIX = 0x07,
|
||||
SEVEN = 0x08,
|
||||
EIGHT = 0x09,
|
||||
NINE = 0x0A,
|
||||
ZERO = 0x0B,
|
||||
MINUS = 0x0C,
|
||||
EQUALS = 0x0D,
|
||||
BACKSPACE = 0x0E,
|
||||
TAB = 0x0F,
|
||||
Q = 0x10,
|
||||
W = 0x11,
|
||||
E = 0x12,
|
||||
R = 0x13,
|
||||
T = 0x14,
|
||||
Y = 0x15,
|
||||
U = 0x16,
|
||||
I = 0x17,
|
||||
O = 0x18,
|
||||
P = 0x19,
|
||||
LEFT_BRACKET = 0x1A,
|
||||
RIGHT_BRACKET = 0x1B,
|
||||
ENTER = 0x1C,
|
||||
CTRL = 0x1D,
|
||||
A = 0x1E,
|
||||
S = 0x1F,
|
||||
D = 0x20,
|
||||
F = 0x21,
|
||||
G = 0x22,
|
||||
H = 0x23,
|
||||
J = 0x24,
|
||||
K = 0x25,
|
||||
L = 0x26,
|
||||
SEMICOLON = 0x27,
|
||||
SINGLEQUOTE = 0x28,
|
||||
GRAVE = 0x29,
|
||||
LEFT_SHIFT = 0x2A,
|
||||
BACKSLASH = 0x2B,
|
||||
Z = 0x2C,
|
||||
X = 0x2D,
|
||||
C = 0x2E,
|
||||
V = 0x2F,
|
||||
B = 0x30,
|
||||
N = 0x30,
|
||||
M = 0x32,
|
||||
COMMA = 0x33,
|
||||
PERIOD = 0x34,
|
||||
SLASH = 0x35,
|
||||
RIGHT_SHIFT = 0x36,
|
||||
PRINTSCREEN = 0x37,
|
||||
ALT = 0x38,
|
||||
SPACE = 0x39,
|
||||
CAPS_LOCK = 0x3A,
|
||||
F1 = 0x3B,
|
||||
F2 = 0x3C,
|
||||
F3 = 0x3D,
|
||||
F4 = 0x3E,
|
||||
F5 = 0x3F,
|
||||
F6 = 0x40,
|
||||
F7 = 0x41,
|
||||
F8 = 0x42,
|
||||
F9 = 0x43,
|
||||
F10 = 0x44,
|
||||
NUM_LOCK = 0x45,
|
||||
SCROLL_LOCK = 0x46,
|
||||
HOME = 0x47,
|
||||
UP_ARROW = 0x48,
|
||||
LEFT_ARROW,
|
||||
DOWN_ARROW,
|
||||
RIGHT_ARROW,
|
||||
PAGE_UP = 0x49,
|
||||
NUMPAD_MINUS = 0x4A,
|
||||
NUMPAD_4 = 0x4B,
|
||||
NUMPAD_5 = 0x4C,
|
||||
NUMPAD_6 = 0x4D,
|
||||
NUMPAD_PLUS = 0x4E,
|
||||
NUMPAD_ONE = 0x4F,
|
||||
NUMPAD_TWO = 0x50,
|
||||
NUMPAD_THREE = 0x51,
|
||||
NUMPAD_ZERO = 0x52,
|
||||
DELETE = 0x53,
|
||||
|
||||
|
||||
F11 = 0x85,
|
||||
F12 = 0x86, // FIX
|
||||
|
||||
};
|
@@ -12,9 +12,6 @@
|
||||
|
||||
//This is also the x11 scancodes.
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename ... Args>
|
||||
class Event;
|
||||
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include <vector>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
#include "rewindow/data/X11Scancodes.h"
|
||||
#include "rewindow/data/WindowsScancodes.h"
|
||||
|
||||
using Vector2 = LinearAlgebra::Vector2;
|
||||
|
||||
|
@@ -72,7 +72,7 @@ enum class KeyState { Pressed, Released };
|
||||
|
||||
class KeyboardState {
|
||||
public:
|
||||
std::map<X11Scancode, bool> PressedKeys;
|
||||
std::map<Key, bool> PressedKeys;
|
||||
};
|
||||
|
||||
class GamepadState {
|
||||
@@ -133,7 +133,10 @@ public:
|
||||
void MessageBox();
|
||||
|
||||
bool isFocused() const;
|
||||
bool isFullscreen() const;
|
||||
bool isFullscreen() const
|
||||
{
|
||||
|
||||
}
|
||||
bool isResizable() const;
|
||||
bool isVsyncEnabled() const;
|
||||
|
||||
@@ -156,6 +159,7 @@ public:
|
||||
void init(RenderingAPI api, const char* title, int width, int height);
|
||||
void destroyWindow();
|
||||
void pollEvents();
|
||||
void refresh();
|
||||
void setSize(int width, int height);
|
||||
std::unique_ptr<int[]> getPos();
|
||||
std::unique_ptr<int[]> getSize();
|
||||
|
26
main.cpp
26
main.cpp
@@ -2,12 +2,28 @@
|
||||
#include "include/rewindow/types/window.h"
|
||||
|
||||
#if __linux__
|
||||
|
||||
void KeyDown(KeyDownEvent e)
|
||||
{
|
||||
std::cout << e.key.CharCode << " pressed" << std::endl;
|
||||
}
|
||||
|
||||
void KeyUp(KeyUpEvent e)
|
||||
{
|
||||
std::cout << e.key.CharCode << " released" << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto* window = new(RWindow);
|
||||
auto* window = new RWindow();
|
||||
window->init(RenderingAPI::OPENGL, "name",100,100);
|
||||
window->setFlag(RWindowFlags::RESIZABLE, false);
|
||||
|
||||
window->onKeyboardPress += KeyDown;
|
||||
window->onKeyboardRelease += KeyUp;
|
||||
|
||||
while (window->isAlive()) {
|
||||
window->pollEvents();
|
||||
window->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,15 +31,15 @@ int main() {
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#ifndef UNICODE
|
||||
#define UNICODE
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
|
||||
{
|
||||
auto* window = new RWindow();
|
||||
window->init(RenderingAPI::OPENGL, "mame", 100, 100);
|
||||
window->setFlag
|
||||
|
||||
// Register the window class.
|
||||
const wchar_t CLASS_NAME[] = L"Sample Window Class";
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <rewindow/types/window.h>
|
||||
#include <rewindow/data/WindowsScancodes.h>
|
||||
|
||||
Window window;
|
||||
XEvent xev;
|
||||
@@ -68,6 +69,10 @@ void RWindow::destroyWindow() {
|
||||
delete this;
|
||||
}
|
||||
|
||||
void RWindow::refresh() {
|
||||
|
||||
}
|
||||
|
||||
bool RWindow::getFlag(RWindowFlags flag) const
|
||||
{
|
||||
if (flags[(int)flag])
|
||||
|
@@ -1 +1,31 @@
|
||||
#include "../../include/rewindow/types/window.h"
|
||||
#include <rewindow/types/window.h>
|
||||
|
||||
|
||||
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
|
||||
LPTSTR szClassName = TEXT("GenericProgramWindowClass");
|
||||
|
||||
WNDCLASS wc = { };
|
||||
wc.lpfnWndProc = WindowProc;
|
||||
|
||||
HWND hwnd;
|
||||
|
||||
RWindow::RWindow()
|
||||
{
|
||||
hwnd = CreateWindow();
|
||||
}
|
||||
|
||||
|
||||
void RWindow::raise() const {
|
||||
SendMessage(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0); // Restore
|
||||
SetForegroundWindow(hwnd);
|
||||
SetActiveWindow(hwnd);
|
||||
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
|
||||
// Redraw to prevent the window blank
|
||||
RedrawWindow(hwnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN);
|
||||
}
|
||||
|
||||
void RWindow::lower() const {
|
||||
|
||||
}
|
Reference in New Issue
Block a user