Several smaller updates

Windows version of ReWindow now compiling
Added to gitignore
This commit is contained in:
orange bowler hat
2024-05-13 13:40:11 +01:00
parent d3a971d598
commit 664d213c04
5 changed files with 34 additions and 59 deletions

4
.gitignore vendored
View File

@@ -1,4 +1,4 @@
/cmake-build-debug /cmake-build-debug
/.idea /.idea
build/CMakeCache.txt build/*
build/CMakeCache.txt .vscode/*

View File

@@ -25,7 +25,7 @@ namespace ReWindow
RightSide = XC_right_side, RightSide = XC_right_side,
Pencil = XC_pencil Pencil = XC_pencil
}; };
class CursorStyle { class CursorStyle {
public: public:
X11CursorStyle X11Cursor; X11CursorStyle X11Cursor;
@@ -51,7 +51,7 @@ namespace ReWindow
} }
#else #else
// https://learn.microsoft.com/en-us/windows/win32/menurc/about-cursors // https://learn.microsoft.com/en-us/windows/win32/menurc/about-cursors
enum class WindowsCursorStyle { enum WindowsCursorStyle {
Arrow, Arrow,
IBeam, IBeam,
Wait, Wait,
@@ -65,6 +65,5 @@ namespace ReWindow
WindowsCursorStyle WindowsCursor; WindowsCursorStyle WindowsCursor;
CursorStyle (WindowsCursorStyle style): WindowsCursor(style) {} CursorStyle (WindowsCursorStyle style): WindowsCursor(style) {}
}; };
#endif #endif
} }

View File

@@ -19,9 +19,9 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glx.h> #include <GL/glx.h>
#include <rewindow/types/cursors.h>
#endif #endif
#include <rewindow/types/cursors.h>
using namespace std::chrono_literals; using namespace std::chrono_literals;
using precision_clock = std::chrono::high_resolution_clock; using precision_clock = std::chrono::high_resolution_clock;
@@ -179,6 +179,8 @@ namespace ReWindow
OnKeyDown(eventData); OnKeyDown(eventData);
} }
#ifndef __linux___ #ifndef __linux___
RWindow(HINSTANCE hInst);
void setRect (int nx, int ny, int nw, int nh) { void setRect (int nx, int ny, int nw, int nh) {
setPos(nx, ny); setPos(nx, ny);
width = nw; width = nw;
@@ -253,16 +255,12 @@ namespace ReWindow
RenderingAPI renderer; RenderingAPI renderer;
bool open = false; bool open = false;
bool resizable; bool resizable;
//You can't do this because you can't initialize a static member inside the class constructor.
//static RWindow* singleton;
}; };
class WindowsImplementationRWindow : public RWindow { class WindowsImplementationRWindow: public RWindow {
}; };
class X11ImplementationRWindow : public RWindow { class X11ImplementationRWindow: public RWindow {
}; };
} }

View File

@@ -81,44 +81,15 @@ int main() {
#include <windows.h> #include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
{ auto* window = new ReWindow::RWindow(hInstance);
auto* window = new RWindow(); window->setTitle ("Sample Window");
window->init(RenderingAPI::OPENGL, "mame", 100, 100); window->raise ();
window->setFlag
// Register the window class. while (window->pollEvents ()) {
const wchar_t CLASS_NAME[] = L"Sample Window Class";
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// Create the window.
HWND hwnd = CreateWindowEx(
0,
CLASS_NAME,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, // Parent Window
NULL, // Menu
hInstance, // Instancehandle
NULL
);
if (hwnd == NULL)
return 0;
ShowWindow(hwnd, nCmdShow);
// Run the message loop
MSG msg = {};
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} }
return 0; return 0;
} }

View File

@@ -117,12 +117,14 @@ static DEVMODEA mode;
ReWindow::RWindow::RWindow() { ReWindow::RWindow::RWindow() {
if (!reClass) { if (!reClass) {
WNDCLASSA rewc = { HINSTANCE module = GetModuleHandleA (NULL);
ReWindowProc, 0, 0, NULL, NULL, , NULL, NULL,
GetStockObject (BLACK_BRUSH), NULL, "ReWindowClass" WNDCLASS rewc = {CS_HREDRAW | CS_VREDRAW,
ReWindowProc, 0, 0, module, NULL, LoadCursor (NULL, IDC_ARROW),
(HBRUSH) GetStockObject (BLACK_BRUSH), NULL, "ReWindowClass"
}; };
reClass = RegisterClassA (&rewc); reClass = RegisterClass (&rewc);
} }
hwnd = CreateWindowA ("ReWindowClass", "ReWindow", WS_TILEDWINDOW, hwnd = CreateWindowA ("ReWindowClass", "ReWindow", WS_TILEDWINDOW,
@@ -198,13 +200,18 @@ void ReWindow::RWindow::refresh() {
} }
} }
void ReWindow::RWindow::pollEvents() { bool ReWindow::RWindow::pollEvents() {
MSG msg; MSG msg;
while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) {
return FALSE;
}
TranslateMessage (&msg); TranslateMessage (&msg);
DispatchMessage (&msg); DispatchMessage (&msg);
} }
return TRUE;
} }
// Might make the window go off the screen on some window managers. // Might make the window go off the screen on some window managers.
@@ -280,13 +287,13 @@ void ReWindow::RWindow::refresh() {
screen.dmPelsHeight = height; screen.dmPelsHeight = height;
screen.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; screen.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings (&screen, 0) == DISP_CHANGE_SUCCESSFUL) { if (ChangeDisplaySettingsA (&screen, 0) == DISP_CHANGE_SUCCESSFUL) {
fullscreenmode = true; fullscreenmode = true;
} }
} }
void ReWindow::RWindow::restoreFromFullscreen() { void ReWindow::RWindow::restoreFromFullscreen() {
if (ChangeDisplaySettings (&mode, 0) == DISP_CHANGE_SUCCESSFUL) { if (ChangeDisplaySettingsA (&mode, 0) == DISP_CHANGE_SUCCESSFUL) {
fullscreenmode = false; fullscreenmode = false;
} }
} }
@@ -302,8 +309,8 @@ void ReWindow::RWindow::refresh() {
} }
void ReWindow::RWindow::setCursorStyle (CursorStyle style) const { void ReWindow::RWindow::setCursorStyle (CursorStyle style) const {
uint ids = [IDC_ARROW, IDC_IBEAM, IDC_WAIT, IDC_CROSS, IDC_HAND, IDC_APPSTARTING]; LPWSTR ids[] ={IDC_ARROW, IDC_IBEAM, IDC_WAIT, IDC_CROSS, IDC_HAND, IDC_APPSTARTING};
SetClassLongPtr (hwnd, GCLIP_HCURSOR, LoadCursor (NULL, ids[style])); SetClassLongPtr (hwnd, GCLP_HCURSOR, (LONG_PTR) LoadCursor (NULL, ids[style.WindowsCursor]));
} }
void ReWindow::RWindow::Open() { void ReWindow::RWindow::Open() {
@@ -325,7 +332,7 @@ void ReWindow::RWindow::refresh() {
if (glrc) { if (glrc) {
wglMakeCurrent (hdc, glrc); wglMakeCurrent (hdc, glrc);
EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &mode); EnumDisplaySettingsA (NULL, ENUM_CURRENT_SETTINGS, &mode);
open = true; open = true;
} }
} }
@@ -342,8 +349,8 @@ void ReWindow::RWindow::refresh() {
} }
bool ReWindow::RWindow::isKeyDown (Key key) const { bool ReWindow::RWindow::isKeyDown (Key key) const {
return currentKeyboard.PressedKeys.contains(key) ? return currentKeyboard.PressedKeys.contains (key) ?
currentKeyboard.PressedKeys.at(key) : false; currentKeyboard.PressedKeys.at (key) : false;
} }
// TODO: Implement MouseButton map // TODO: Implement MouseButton map