diff --git a/.gitignore b/.gitignore index 79a9d42..706ecda 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /cmake-build-debug /.idea -build/CMakeCache.txt -build/CMakeCache.txt +build/* +.vscode/* diff --git a/include/rewindow/types/cursors.h b/include/rewindow/types/cursors.h index 025329c..f4cb7ff 100644 --- a/include/rewindow/types/cursors.h +++ b/include/rewindow/types/cursors.h @@ -25,7 +25,7 @@ namespace ReWindow RightSide = XC_right_side, Pencil = XC_pencil }; - + class CursorStyle { public: X11CursorStyle X11Cursor; @@ -51,7 +51,7 @@ namespace ReWindow } #else // https://learn.microsoft.com/en-us/windows/win32/menurc/about-cursors - enum class WindowsCursorStyle { + enum WindowsCursorStyle { Arrow, IBeam, Wait, @@ -65,6 +65,5 @@ namespace ReWindow WindowsCursorStyle WindowsCursor; CursorStyle (WindowsCursorStyle style): WindowsCursor(style) {} }; - #endif } \ No newline at end of file diff --git a/include/rewindow/types/window.h b/include/rewindow/types/window.h index fb35d88..37fc07b 100644 --- a/include/rewindow/types/window.h +++ b/include/rewindow/types/window.h @@ -19,9 +19,9 @@ #include #include #include -#include #endif +#include using namespace std::chrono_literals; using precision_clock = std::chrono::high_resolution_clock; @@ -179,6 +179,8 @@ namespace ReWindow OnKeyDown(eventData); } #ifndef __linux___ + RWindow(HINSTANCE hInst); + void setRect (int nx, int ny, int nw, int nh) { setPos(nx, ny); width = nw; @@ -253,16 +255,12 @@ namespace ReWindow RenderingAPI renderer; bool open = false; 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 { }; } \ No newline at end of file diff --git a/main.cpp b/main.cpp index f9fd297..1865d7d 100644 --- a/main.cpp +++ b/main.cpp @@ -81,44 +81,15 @@ int main() { #include 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 +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) { + auto* window = new ReWindow::RWindow(hInstance); + window->setTitle ("Sample Window"); + window->raise (); - // Register the window class. - const wchar_t CLASS_NAME[] = L"Sample Window Class"; + while (window->pollEvents ()) { - 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; } diff --git a/src/windows/window.cpp b/src/windows/window.cpp index 7122a9f..5bf4282 100644 --- a/src/windows/window.cpp +++ b/src/windows/window.cpp @@ -117,12 +117,14 @@ static DEVMODEA mode; ReWindow::RWindow::RWindow() { if (!reClass) { - WNDCLASSA rewc = { - ReWindowProc, 0, 0, NULL, NULL, , NULL, NULL, - GetStockObject (BLACK_BRUSH), NULL, "ReWindowClass" + HINSTANCE module = GetModuleHandleA (NULL); + + 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, @@ -198,13 +200,18 @@ void ReWindow::RWindow::refresh() { } } - void ReWindow::RWindow::pollEvents() { + bool ReWindow::RWindow::pollEvents() { MSG msg; while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { + if (msg.message == WM_QUIT) { + return FALSE; + } TranslateMessage (&msg); DispatchMessage (&msg); } + + return TRUE; } // Might make the window go off the screen on some window managers. @@ -280,13 +287,13 @@ void ReWindow::RWindow::refresh() { screen.dmPelsHeight = height; screen.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; - if (ChangeDisplaySettings (&screen, 0) == DISP_CHANGE_SUCCESSFUL) { + if (ChangeDisplaySettingsA (&screen, 0) == DISP_CHANGE_SUCCESSFUL) { fullscreenmode = true; } } void ReWindow::RWindow::restoreFromFullscreen() { - if (ChangeDisplaySettings (&mode, 0) == DISP_CHANGE_SUCCESSFUL) { + if (ChangeDisplaySettingsA (&mode, 0) == DISP_CHANGE_SUCCESSFUL) { fullscreenmode = false; } } @@ -302,8 +309,8 @@ void ReWindow::RWindow::refresh() { } void ReWindow::RWindow::setCursorStyle (CursorStyle style) const { - uint ids = [IDC_ARROW, IDC_IBEAM, IDC_WAIT, IDC_CROSS, IDC_HAND, IDC_APPSTARTING]; - SetClassLongPtr (hwnd, GCLIP_HCURSOR, LoadCursor (NULL, ids[style])); + LPWSTR ids[] ={IDC_ARROW, IDC_IBEAM, IDC_WAIT, IDC_CROSS, IDC_HAND, IDC_APPSTARTING}; + SetClassLongPtr (hwnd, GCLP_HCURSOR, (LONG_PTR) LoadCursor (NULL, ids[style.WindowsCursor])); } void ReWindow::RWindow::Open() { @@ -325,7 +332,7 @@ void ReWindow::RWindow::refresh() { if (glrc) { wglMakeCurrent (hdc, glrc); - EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &mode); + EnumDisplaySettingsA (NULL, ENUM_CURRENT_SETTINGS, &mode); open = true; } } @@ -342,8 +349,8 @@ void ReWindow::RWindow::refresh() { } bool ReWindow::RWindow::isKeyDown (Key key) const { - return currentKeyboard.PressedKeys.contains(key) ? - currentKeyboard.PressedKeys.at(key) : false; + return currentKeyboard.PressedKeys.contains (key) ? + currentKeyboard.PressedKeys.at (key) : false; } // TODO: Implement MouseButton map