Compare commits

...

8 Commits

Author SHA1 Message Date
e39881f2dc update RWindow::Open
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 2m0s
Create the OpenGL Context without the debug flag if the system supports it (big performance gain)
2025-01-18 13:06:15 -05:00
830dd954a2 Fix for Windows.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m52s
2025-01-15 22:58:20 -05:00
e764dcf5b8 Update to latest J3ML
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m34s
2025-01-10 19:54:16 -05:00
4b8479f1d3 Remove unused include
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m58s
2025-01-10 19:52:03 -05:00
f79164f89b Boilerplate clipboardservice namespace.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 5m50s
2025-01-09 01:12:22 -05:00
a2ef397bdb Merge remote-tracking branch 'origin/main'
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m57s
2025-01-07 18:03:27 -05:00
6fd30ff25b Fixed subtle error with MouseButtonDownEvent. 2025-01-07 18:03:21 -05:00
8d8e14ef40 Refactor InputService to separate header file.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m32s
2024-12-11 15:16:21 -06:00
13 changed files with 167 additions and 82 deletions

View File

@@ -18,7 +18,7 @@ include(cmake/CPM.cmake)
CPMAddPackage(
NAME J3ML
URL https://git.redacted.cc/josh/j3ml/archive/Release-3.2.zip
URL https://git.redacted.cc/josh/j3ml/archive/3.4.5.zip
)
CPMAddPackage(
@@ -43,11 +43,11 @@ file(GLOB_RECURSE HEADERS "include/logger/*.h" "include/logger/*.hpp")
if(UNIX AND NOT APPLE)
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/linux/*.cpp" "src/platform/shared/*.cpp" "src/logger/*.cpp" )
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/linux/*.cpp" "src/platform/shared/*.cpp" "src/logger/*.cpp" "src/rewindow/*.cpp" )
endif()
if(WIN32)
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/windows/*.cpp" "src/platform/shared/*.cpp" "src/logger/*.cpp")
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/windows/*.cpp" "src/platform/shared/*.cpp" "src/logger/*.cpp" "src/rewindow/*.cpp")
endif()
include_directories("include")

View File

@@ -0,0 +1,10 @@
#pragma once
/// X11 Clipboard API looked unhinged. So fuck it, use this system for now.
namespace ClipboardService
{
std::string GetClipboard(int historyIndex = 0);
void SetClipboard(const std::string& str, bool overwrites_last = false);
unsigned int GetClipboardHistorySize();
unsigned int GetClipboardHistoryMax();
}

View File

@@ -1,5 +1,23 @@
#pragma once
namespace InputService {
#include <Event.h>
#include <rewindow/types/WindowEvents.hpp>
namespace InputService {
using namespace ReWindow;
inline Event<KeyboardEvent> OnKeyboardEvent;
inline Event<KeyboardEvent> OnKeyEvent;
inline Event<KeyDownEvent> OnKeyDown;
inline Event<KeyUpEvent> OnKeyUp;
inline Event<MouseMoveEvent> OnMouseEvent;
inline Event<MouseButtonEvent> OnMouseButtonEvent;
inline Event<MouseMoveEvent> OnMouseMove;
inline Event<MouseButtonDownEvent> OnMouseDown;
inline Event<MouseButtonUpEvent> OnMouseUp;
inline Event<MouseWheelEvent> OnMouseWheel;
bool IsKeyDown(const Key& key);
bool IsMouseButtonDown(const MouseButton& button);
Vector2 GetMousePosition();
Vector2 GetWindowSize();
};

View File

@@ -3,6 +3,7 @@
#include <chrono>
#include <rewindow/types/key.h>
#include <rewindow/types/mousebutton.h>
#include <J3ML/LinearAlgebra/Vector2.hpp>
namespace ReWindow {
@@ -48,17 +49,15 @@ namespace ReWindow {
class MouseButtonDownEvent : public MouseButtonEvent {
public:
MouseButton Button;
MouseButtonDownEvent() = default;
MouseButtonDownEvent(const MouseButton& button) : MouseButtonEvent(button, true) {}
explicit MouseButtonDownEvent(const MouseButton& button) : MouseButtonEvent(button, true) {}
};
class MouseButtonUpEvent : public MouseButtonEvent {
public:
MouseButtonUpEvent() = default;
MouseButtonUpEvent(const MouseButton& button) : MouseButtonEvent(button, true) {}
explicit MouseButtonUpEvent(const MouseButton& button) : MouseButtonEvent(button, false) {}
};
class MouseMoveEvent : public MouseEvent {

View File

@@ -8,7 +8,6 @@
#include <string>
#include <rewindow/data/X11Scancodes.h>
#include <rewindow/data/WindowsScancodes.h>
#include <J3ML/LinearAlgebra.hpp>
class Key

View File

@@ -10,7 +10,6 @@
#include <rewindow/types/gamepadbutton.h>
#include <J3ML/LinearAlgebra.hpp>
#include <rewindow/types/WindowEvents.hpp>
#include <format>
#include <queue>
@@ -118,24 +117,6 @@ namespace ReWindow
// Temporary static input service namespace, TODO: this will be refactored as part of ReInput later.
namespace Input {
inline Event<KeyboardEvent> OnKeyboardEvent;
inline Event<KeyboardEvent> OnKeyEvent;
inline Event<KeyDownEvent> OnKeyDown;
inline Event<KeyUpEvent> OnKeyUp;
inline Event<MouseMoveEvent> OnMouseEvent;
inline Event<MouseButtonEvent> OnMouseButtonEvent;
inline Event<MouseMoveEvent> OnMouseMove;
inline Event<MouseButtonDownEvent> OnMouseDown;
inline Event<MouseButtonUpEvent> OnMouseUp;
inline Event<MouseWheelEvent> OnMouseWheel;
bool IsKeyDown(const Key& key);
bool IsMouseButtonDown(const MouseButton& button);
Vector2 GetMousePosition();
Vector2 GetWindowSize();
}
/// RWindow is a class implementation of a platform-independent window abstraction.
/// This library also provides abstractions for user-input devices, and their interaction with the window.
class RWindow {

View File

@@ -1,8 +1,11 @@
#include <iostream>
#include <rewindow/types/window.h>
#include <rewindow/types/display.h>
#include <rewindow/logger/logger.h>
#include <stdio.h>
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Windows :/
#if _WIN32
#include <windows.h>
@@ -26,7 +29,7 @@ class MyWindow : public ReWindow::RWindow {
void OnKeyDown(const ReWindow::KeyDownEvent& e) override {}
void OnRefresh(float elapsed) override {
glClearColor(255, 0, 0, 255);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
GLSwapBuffers();
auto pos = GetMouseCoordinates();

View File

@@ -34,6 +34,7 @@ Cursor invisible_cursor = 0;
Vector2 render_area_position = {0, 0};
Vector2 position = {0, 0};
bool should_poll_x_for_mouse_pos = true;
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
using namespace ReWindow;
@@ -349,43 +350,78 @@ void RWindow::Open() {
xSetWindowAttributes.background_pixel = BlackPixel(display, defaultScreen);
xSetWindowAttributes.override_redirect = True;
xSetWindowAttributes.event_mask = ExposureMask;
//SetVsyncEnabled(vsync);
if (renderer == RenderingAPI::OPENGL) {
GLint glAttributes[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
visual = glXChooseVisual(display, defaultScreen, glAttributes);
glContext = glXCreateContext(display, visual, nullptr, GL_TRUE);
auto glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB");
XVisualInfo* vi = nullptr;
// Fallback to the old way if you somehow don't have this.
if (!glXCreateContextAttribsARB) {
GLint glAttributes[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
visual = glXChooseVisual(display, defaultScreen, glAttributes);
glContext = glXCreateContext(display, visual, nullptr, GL_TRUE);
window = XCreateWindow(display, RootWindow(display, defaultScreen), 0, 0, width, height, 0, visual->depth,
InputOutput, visual->visual, CWBackPixel | CWColormap | CWBorderPixel | NoEventMask, &xSetWindowAttributes);
ReWindow::Logger::Debug("Created OpenGL Context with glXCreateContext.");
}
else {
static int visual_attributes[]
{
GLX_X_RENDERABLE, True, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8,
GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8,
GLX_DOUBLEBUFFER, True, None
};
int fb_count;
GLXFBConfig *fb_configurations = glXChooseFBConfig(display, defaultScreen, visual_attributes, &fb_count);
if (!fb_configurations || fb_count == 0)
throw std::runtime_error("Couldn't get framebuffer configuration.");
GLXFBConfig best_fbc = fb_configurations[0];
vi = glXGetVisualFromFBConfig(display, best_fbc);
if (!vi)
throw std::runtime_error("Couldn't visual info from framebuffer configuration.");
xSetWindowAttributes.colormap = XCreateColormap(display, RootWindow(display, vi->screen), vi->visual, AllocNone);
window = XCreateWindow(display, RootWindow(display, vi->screen), 0, 0, width, height, 0, vi->depth, InputOutput,
vi->visual, CWBackPixel | CWColormap | CWBorderPixel, &xSetWindowAttributes);
// TODO allow the user to specify what OpenGL version they want.
int context_attributes[] { GLX_CONTEXT_MAJOR_VERSION_ARB, 2, GLX_CONTEXT_MINOR_VERSION_ARB, 1, None };
glContext = glXCreateContextAttribsARB(display, best_fbc, nullptr, True, context_attributes);
XFree(fb_configurations);
}
if (!glContext)
throw std::runtime_error("Couldn't create the OpenGL context.");
if (!glXMakeCurrent(display, window, glContext))
throw std::runtime_error("Couldn't change OpenGL context to current.");
if (vi)
XFree(vi);
ReWindow::Logger::Debug("Created OpenGL Context with glXCreateContextAttribsARB");
}
xSetWindowAttributes.colormap = XCreateColormap(display, RootWindow(display, defaultScreen), visual->visual, AllocNone);
window = XCreateWindow(display, RootWindow(display, defaultScreen), 0, 0, width, height, 0, visual->depth,
InputOutput, visual->visual, CWBackPixel | CWColormap | CWBorderPixel | NoEventMask,
&xSetWindowAttributes);
// Set window to floating because fucking tiling WMs
windowTypeAtom = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
windowTypeUtilityAtom = XInternAtom(display, "_NET_WM_WINDOW_TYPE_UTILITY", False);
XChangeProperty(display, window, windowTypeAtom, XA_ATOM, 32, PropModeReplace,
(unsigned char *)&windowTypeUtilityAtom, 1);
//
XSelectInput(display, window,
ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
PointerMotionMask |
PointerMotionHintMask | FocusChangeMask | StructureNotifyMask | SubstructureRedirectMask |
SubstructureNotifyMask | CWColormap );
XSelectInput(display, window, ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
PointerMotionHintMask | FocusChangeMask | StructureNotifyMask | SubstructureRedirectMask | SubstructureNotifyMask | CWColormap );
XMapWindow(display, window);
XStoreName(display, window, title.c_str());
windowTypeAtom = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
windowTypeUtilityAtom = XInternAtom(display, "_NET_WM_WINDOW_TYPE_UTILITY", False);
XChangeProperty(display, window, windowTypeAtom, XA_ATOM, 32, PropModeReplace, (unsigned char*)&windowTypeUtilityAtom, 1);
wmDeleteWindow = XInternAtom(display, "WM_DELETE_WINDOW", False);
XSetWMProtocols(display, window, &wmDeleteWindow, 1);
if (renderer == RenderingAPI::OPENGL)
glXMakeCurrent(display, window, glContext);
// Get the position of the renderable area relative to the rest of the window.
XGetWindowAttributes(display, window, &windowAttributes);
render_area_position = { (float) windowAttributes.x, (float) windowAttributes.y };
render_area_position = {(float)windowAttributes.x, (float)windowAttributes.y};
open = true;
processOnOpen();
}

View File

@@ -1,4 +1,5 @@
#include <rewindow/types/window.h>
#include <rewindow/inputservice.hpp>
#include "rewindow/logger/logger.h"
std::string RWindowFlagToStr(RWindowFlags flag) {
switch (flag) {
@@ -73,8 +74,8 @@ void RWindow::processMousePress(const MouseButton& btn)
auto event = MouseButtonDownEvent(btn);
OnMouseButtonDown(event);
OnMouseButtonDownEvent(event);
Input::OnMouseButtonEvent(MouseButtonEvent(btn, true));
Input::OnMouseDown(event);
InputService::OnMouseButtonEvent(MouseButtonEvent(btn, true));
InputService::OnMouseDown(event);
LogEvent(event);
}
@@ -84,7 +85,7 @@ void RWindow::processMouseMove(Vector2 last_pos, Vector2 new_pos)
auto event = MouseMoveEvent(new_pos);
OnMouseMove(event);
OnMouseMoveEvent(event);
Input::OnMouseMove(event);
InputService::OnMouseMove(event);
LogEvent(event);
}
@@ -94,8 +95,8 @@ void RWindow::processMouseRelease(const MouseButton& btn)
auto event = MouseButtonUpEvent(btn);
OnMouseButtonUp(event);
OnMouseButtonUpEvent(event);
Input::OnMouseButtonEvent(MouseButtonEvent(btn, false));
Input::OnMouseUp(event);
InputService::OnMouseButtonEvent(MouseButtonEvent(btn, false));
InputService::OnMouseUp(event);
LogEvent(event);
}
@@ -105,9 +106,9 @@ void RWindow::processKeyRelease(Key key) {
auto event = KeyUpEvent(key);
OnKeyUp(event);
OnKeyUpEvent(event);
Input::OnKeyboardEvent(KeyboardEvent(key, KeyState::Released));
Input::OnKeyEvent(KeyboardEvent(key, KeyState::Released));
Input::OnKeyUp(event);
InputService::OnKeyboardEvent(KeyboardEvent(key, KeyState::Released));
InputService::OnKeyEvent(KeyboardEvent(key, KeyState::Released));
InputService::OnKeyUp(event);
LogEvent(event);
}
@@ -116,9 +117,9 @@ void RWindow::processKeyPress(Key key) {
auto event = KeyDownEvent(key);
OnKeyDown(event);
OnKeyDownEvent(event);
Input::OnKeyDown(event);
Input::OnKeyboardEvent(KeyboardEvent(key, KeyState::Pressed));
Input::OnKeyEvent(KeyboardEvent(key, KeyState::Pressed));
InputService::OnKeyDown(event);
InputService::OnKeyboardEvent(KeyboardEvent(key, KeyState::Pressed));
InputService::OnKeyEvent(KeyboardEvent(key, KeyState::Pressed));
LogEvent(event);
}
@@ -297,18 +298,7 @@ bool RWindow::IsFocused() const {
}
bool Input::IsKeyDown(const Key &key) {
return extant->IsKeyDown(key);
}
bool Input::IsMouseButtonDown(const MouseButton &button) {
return extant->IsMouseButtonDown(button);
}
Vector2 Input::GetMousePosition() {
return extant->GetMouseCoordinates();
}
Vector2 Input::GetWindowSize() {
return extant->GetSize();
}

View File

@@ -24,7 +24,8 @@ void RWindow::SetFlag(RWindowFlags flag, bool state) {
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);
}
}wasd
}
void RWindow::SetResizable(bool resizable) {
SetFlag(RWindowFlags::RESIZABLE, resizable);;
}
@@ -300,3 +301,7 @@ void RWindow::GLSwapBuffers() {
std::string RWindow::getGraphicsDriverVendor() {
return std::string(reinterpret_cast<const char*>(glGetString(GL_VENDOR)));
}
void RWindow::DestroyOSWindowHandle() {
DestroyWindow(hwnd);
}

View File

@@ -0,0 +1,28 @@
#include <string>
#include <vector>
#include <rewindow/clipboardservice.hpp>
std::vector<std::string> clipboard_history;
std::string clipboard;
namespace ClipboardService {
std::string GetClipboard(int historyIndex) {
if (historyIndex > 0) {
return clipboard_history[historyIndex - 1];
}
return clipboard;
}
void SetClipboard(const std::string& str, bool overwrites_last) {
if (!overwrites_last) {
clipboard_history.push_back(clipboard);
}
clipboard = str;
}
}

View File

@@ -0,0 +1,17 @@
#include <rewindow/inputservice.hpp>
#include <rewindow/types/window.h>
namespace InputService
{
bool IsKeyDown(const Key &key) {
return RWindow::GetExtant()->IsKeyDown(key);
}
bool IsMouseButtonDown(const MouseButton &button) {
return RWindow::GetExtant()->IsMouseButtonDown(button);
}
Vector2 GetMousePosition() {
return RWindow::GetExtant()->GetMouseCoordinates();
}
Vector2 GetWindowSize() {
return RWindow::GetExtant()->GetSize();
}
}

View File

@@ -1,7 +1,6 @@
#include <rewindow/types/mousebutton.h>
#include <string>
#include <X11/X.h>
#include "rewindow/logger/logger.h"
#include <rewindow/logger/logger.h>
MouseButton::MouseButton(const std::string& charcode, unsigned int index) {