Compare commits
8 Commits
Prerelease
...
Prerelease
Author | SHA1 | Date | |
---|---|---|---|
e39881f2dc | |||
830dd954a2 | |||
e764dcf5b8 | |||
4b8479f1d3 | |||
f79164f89b | |||
a2ef397bdb | |||
6fd30ff25b | |||
8d8e14ef40 |
@@ -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")
|
||||
|
10
include/rewindow/clipboardservice.hpp
Normal file
10
include/rewindow/clipboardservice.hpp
Normal 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();
|
||||
}
|
@@ -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();
|
||||
};
|
@@ -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 {
|
||||
|
@@ -8,7 +8,6 @@
|
||||
#include <string>
|
||||
#include <rewindow/data/X11Scancodes.h>
|
||||
#include <rewindow/data/WindowsScancodes.h>
|
||||
#include <J3ML/LinearAlgebra.hpp>
|
||||
|
||||
|
||||
class Key
|
||||
|
@@ -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 {
|
||||
|
7
main.cpp
7
main.cpp
@@ -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();
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
28
src/rewindow/clipboardservice.cpp
Normal file
28
src/rewindow/clipboardservice.cpp
Normal 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;
|
||||
}
|
||||
|
||||
}
|
17
src/rewindow/inputservice.cpp
Normal file
17
src/rewindow/inputservice.cpp
Normal 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();
|
||||
}
|
||||
}
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user