fix cmake & vsync

This commit is contained in:
Redacted
2024-04-30 14:45:43 -07:00
parent 124cbedf4d
commit a7b7de93dd
5 changed files with 60 additions and 77 deletions

View File

@@ -10,10 +10,6 @@ endif()
set(CMAKE_CXX_STANDARD 20)
if (WIN32)
set(CMAKE_CXX_FLAGS "-municode")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
@@ -46,9 +42,7 @@ if(WIN32)
endif()
include_directories("include")
add_library(ReWindowLibrary SHARED ${SOURCES}
include/rewindow/types/cursors.h
)
add_library(ReWindowLibrary SHARED ${SOURCES})
target_include_directories(ReWindowLibrary PUBLIC ${Event_SOURCE_DIR}/include)
@@ -69,4 +63,9 @@ if(UNIX AND NOT APPLE)
endif()
if(WIN32)
target_link_libraries(ReWindowLibrary PUBLIC ${OPENGL_LIBRARIES})
target_link_libraries(ReWindowLibrary PUBLIC J3ML)
target_link_libraries(ReWindowLibrary PUBLIC Event)
add_executable(ReWindowLibraryDemo main.cpp)
target_link_libraries(ReWindowLibraryDemo PUBLIC ReWindowLibrary)
endif()

View File

@@ -5,16 +5,20 @@
#include <Event.h>
#include <functional>
#include <map>
#include <thread>
#include <rewindow/types/key.h>
#if WIN32
#include <windows.h>
#include <wingdi.h>
#endif
#if __linux__
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <GL/gl.h>
#include <GL/glx.h>
#include "cursors.h"
#include <cursors.h>
#endif
@@ -210,7 +214,7 @@ namespace ReWindow
Vector2 getCursorPos() const;
void raise() const;
void lower() const;
void setCursorStyle(CursorStyle style) const;
//void setCursorStyle(CursorStyle style) const;
void setCursorCustomIcon() const;
static void glSwapBuffers();

View File

@@ -1,23 +0,0 @@
project ('ReWindow', 'cpp', version: '0.1.0')
sources = ['spng.c', 'nx/nxObject.m', 'nx/nxApp.m', 'nx/nxWindow.m', 'nx/nxUtil.m', 'nx/nxClipboard.m', 'nx/nxMultiTouch.m', 'nx/nxNav.m', 'State.m', 'Geom.m', 'Surface.m', 'Chunk.m', 'Resource.m', 'gx.m', 'gxMath.c', 'gxTile.m', 'Heap.c', 'uiMenu.m', 'uiFrame.m', 'uiSplit.m', 'uiTool.m', 'main.m', 'Section.m', 'Track.m', 'Plan.m', 'Profile.m', 'Book.m', 'Elevate.m']
includes = include_directories ('/usr/include/gtk-3.0', '/usr/include/libevdev-1.0')
libs = [
dependency ('gio-2.0', version: '>= 2.50'),
dependency ('gdk-3.0', version: '>= 3.20'),
dependency ('gtk+-3.0', version: '>= 3.22'),
dependency ('cairo', version: '>= 1.00'),
compiler.find_library ('m'),
compiler.find_library ('GL'),
compiler.find_library ('objc'),
compiler.find_library ('jpeg'),
compiler.find_library ('evdev'),
]
verse = executable ('verse', [sources, resource],
include_directories: includes,
dependencies: libs,
install: true
)

View File

@@ -10,6 +10,8 @@
#include <cstring>
#include <thread>
#include "rewindow/types/cursors.h"
#include "../../include/rewindow/types/window.h"
// TODO: Move all "global" members to be instantiated class members of Window
// Doing this would break the intended "Platform-Specific" Encapsulation
@@ -401,6 +403,4 @@ namespace ReWindow {
}
// TODO: Implement ControllerButton map
}

View File

@@ -1,4 +1,8 @@
#include <rewindow/types/window.h>
#include <rewindow/types/cursors.h>
#include <GL/gl.h>
typedef BOOL (APIENTRY* PFNWGLSWAPINTERVALEXTPROC)(int interval);
LRESULT CALLBACK ReWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
@@ -7,14 +11,14 @@ LRESULT CALLBACK ReWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPara
break;
case WM_SETFOCUS: {
RWindowEvent event {};
ReWindow::RWindowEvent event {};
OnFocusGain (event);
setFlag (RWindowFlags::IN_FOCUS, true);
break;
}
case WM_FOCUSLOST: {
RWindowEvent event {};
ReWindow::RWindowEvent event {};
OnFocusLost (event);
setFlag (RWindowFlags::IN_FOCUS, false);
break;
@@ -110,7 +114,7 @@ static ATOM reClass = 0;
static HGLRC glrc = NULL;
static DEVMODEA mode;
RWindow::RWindow() {
ReWindow::RWindow::RWindow() {
if (!reClass) {
WNDCLASSA rewc = {
ReWindowProc, 0, 0, NULL, NULL, , NULL, NULL,
@@ -125,20 +129,20 @@ RWindow::RWindow() {
NULL, NULL, , 0);
}
void RWindow::raise() const {
void ReWindow::RWindow::raise() const {
SetForegroundWindow (hwnd);
SetActiveWindow (hwnd);
SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
ShowWindow (hwnd, SW_SHOW)
ShowWindow (hwnd, SW_SHOW);
// Redraw to prevent the window blank
RedrawWindow (hwnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN);
}
void RWindow::lower() const {
void ReWindow::RWindow::lower() const {
ShowWindow (hwnd, SW_MINIMIZE);
}
void RWindow::destroyWindow() {
void ReWindow::RWindow::destroyWindow() {
if (hwnd) {
if (hdc) {
if (glrc) {
@@ -155,7 +159,7 @@ void RWindow::destroyWindow() {
delete this;
}
void RWindow::refresh() {
void ReWindow::RWindow::refresh() {
// TODO: Implement refresh time keeping
OnRefresh (0.f);
@@ -168,11 +172,11 @@ void RWindow::refresh() {
std::this_thread::sleep_for(1ms);
}
bool RWindow::getFlag (RWindowFlags flag) const {
bool ReWindow::RWindow::getFlag (RWindowFlags flag) const {
return (flags[(int) flag]);
}
void RWindow::setFlag (RWindowFlags flag, bool state) {
void ReWindow::RWindow::setFlag (RWindowFlags flag, bool state) {
XGetWindowAttributes(display,window,&windowAttributes);
flags[(int) flag] = state;
@@ -184,7 +188,7 @@ void RWindow::refresh() {
}
}
void RWindow::pollEvents() {
void ReWindow::RWindow::pollEvents() {
MSG msg;
while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
@@ -194,21 +198,21 @@ void RWindow::refresh() {
}
// Might make the window go off the screen on some window managers.
void RWindow::setSize (int newWidth, int newHeight) {
void ReWindow::RWindow::setSize (int newWidth, int newHeight) {
if (!getFlag(RWindowFlags::RESIZABLE)) return;
width = newWidth;
height = newHeight;
MoveWindow (hwnd, x, y, width, height, TRUE);
}
void RWindow::setSize(const Vector2& size)
void ReWindow::RWindow::setSize(const Vector2& size)
if (!getFlag(RWindowFlags::RESIZABLE)) return;
width = size.x;
height = size.y;
MoveWindow (hwnd, x, y, width, height, TRUE);
}
Vector2 RWindow::getCursorPos() const {
Vector2 ReWindow::RWindow::getCursorPos() const {
POINT pos;
GetCursorPos (&pos);
@@ -222,55 +226,55 @@ void RWindow::refresh() {
}
// TODO: implement integer vector2/3 types
Vector2 RWindow::getSize() const {
Vector2 ReWindow::RWindow::getSize() const {
RECT area;
GetClientRect (hwnd, &area);
return {(float) area.right, (float) area.bottom};
}
// TODO: implement integer vector2/3 types
Vector2 RWindow::getPos() const {
Vector2 ReWindow::RWindow::getPos() const {
XGetWindowAttributes(display,window,&windowAttributes);
return {(float)windowAttributes.x, (float)windowAttributes.y};
}
void RWindow::setPos(int newx, int newy) {
void ReWindow::RWindow::setPos(int newx, int newy) {
x = newx;
y = newy;
MoveWindow (hwnd, x, y, width, height, TRUE);
}
void RWindow::setPos(const Vector2& pos) {
void ReWindow::RWindow::setPos(const Vector2& pos) {
this->setPos(pos.x, pos.y);
}
void RWindow::glSwapBuffers() {
void ReWindow::RWindow::glSwapBuffers() {
SwapBuffers (hdc);
}
bool RWindow::isResizable() const {
bool ReWindow::RWindow::isResizable() const {
return this->getFlag (RWindowFlags::RESIZABLE);
}
bool RWindow::isAlive() const {
bool ReWindow::RWindow::isAlive() const {
return true;
}
void RWindow::setResizable(bool resizable) {
void ReWindow::RWindow::setResizable(bool resizable) {
this->resizable = resizable;
this->setFlag(RWindowFlags::RESIZABLE, resizable);
}
void RWindow::setFullscreen(bool fs) {
void ReWindow::RWindow::setFullscreen(bool fs) {
if (fs) {
fullscreen();
}
else restoreFromFullscreen();
}
void RWindow::fullscreen() {
void ReWindow::RWindow::fullscreen() {
DEVMODEA screen = {sizeof (DEVMODEA)};
screen.dmBitsPerPixel = 32;
screen.dmBitsPerPel = 32;
screen.dmPelsWidth = width;
screen.dmPelsHeight = height;
screen.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
@@ -280,33 +284,33 @@ void RWindow::refresh() {
}
}
void RWindow::restoreFromFullscreen() {
void ReWindow::RWindow::restoreFromFullscreen() {
if (ChangeDisplaySettings (&mode, 0) == DISP_CHANGE_SUCCESSFUL) {
fullscreenmode = false;
}
}
void RWindow::setVsyncEnabled (bool b) {
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT");
glXSwapIntervalEXT(display, window, b);
void ReWindow::RWindow::setVsyncEnabled (bool b) {
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
wglSwapIntervalEXT(b);
}
bool RWindow::isFullscreen() const {
bool ReWindow::RWindow::isFullscreen() const {
return fullscreenmode;
}
void RWindow::setCursorStyle (CursorStyle style) const {
void ReWindow::RWindow::setCursorStyle (CursorStyle style) const {
u32 x11_cursor_resolved_enum = static_cast<u32>(style.X11Cursor);
Cursor c = XCreateFontCursor(display, x11_cursor_resolved_enum);
XDefineCursor(display, window, c);
}
void RWindow::Open() {
void ReWindow::RWindow::Open() {
if (hwnd) {
hdc = GetDC (hwnd);
PIXELFORMATDESCRIPTIOR pfd = {
PIXELFORMATDESCRIPTIOR pfd = {
sizeof (PIXELFORMATDESCRIPTIOR),
1, PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW,
PFD_TYPE_RGBA, 24, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 32,
@@ -319,7 +323,7 @@ void RWindow::refresh() {
SetPixelFormat (hdc, ipf, &pfd);
glrc = wglCreateContext (hdc);
if (hglrc) {
if (glrc) {
wglMakeCurrent (hdc, glrc);
EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &mode);
open = true;
@@ -328,26 +332,25 @@ void RWindow::refresh() {
}
}
void RWindow::setTitle (const std::string &title) {
void ReWindow::RWindow::setTitle (const std::string &title) {
this->title = title;
SetWindowTextA (hwnd, title.c_str ());
}
std::string RWindow::getTitle () const {
std::string ReWindow::RWindow::getTitle () const {
return this->title;
}
bool RWindow::isKeyDown (Key key) const {
bool ReWindow::RWindow::isKeyDown (Key key) const {
return currentKeyboard.PressedKeys.contains(key) ?
currentKeyboard.PressedKeys.at(key) : false;
}
// TODO: Implement MouseButton map
bool RWindow::isMouseButtonDown(MouseButton button) const {
bool ReWindow::RWindow::isMouseButtonDown(MouseButton button) const {
return false;
}
void RWindow::setRenderer (RenderingAPI api) {
void ReWindow::RWindow::setRenderer (RenderingAPI api) {
renderer = api;
}
}
}