This commit is contained in:
@@ -42,6 +42,7 @@ file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
|
||||
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" )
|
||||
endif()
|
||||
|
||||
|
@@ -11,8 +11,8 @@ A library which allows easily creating and managing a window and it's events ac
|
||||
Install dependencies
|
||||
|
||||
```bash
|
||||
dnf install cmake make gcc-g++ libX11 libX11-devel
|
||||
apt-get install cmake make gcc g++ libx11-6 libx11-dev libgl-dev libxrandr-dev
|
||||
Fedora/RHEL: dnf install cmake make gcc-g++ libX11 libX11-devel mesa-libGL-devel
|
||||
Ubuntu/Debian: apt-get install cmake make gcc g++ libx11-6 libx11-dev libgl-dev libxrandr-dev
|
||||
```
|
||||
|
||||
Clone the repository
|
||||
|
@@ -140,8 +140,8 @@ namespace ReWindow
|
||||
#pragma region Callbacks
|
||||
/// Bindable Non-intrusive event handlers
|
||||
/// Use these when you can't override the base window class
|
||||
Event<int> OnOpenEvent;
|
||||
Event<int> OnClosingEvent;
|
||||
Event<> OnOpenEvent;
|
||||
Event<> OnClosingEvent;
|
||||
Event<RWindowEvent> OnFocusLostEvent;
|
||||
Event<RWindowEvent> OnFocusGainEvent;
|
||||
Event<float> OnRefreshEvent;
|
||||
@@ -295,15 +295,25 @@ namespace ReWindow
|
||||
bool open = false;
|
||||
bool resizable;
|
||||
|
||||
Vector2 mouse_coords = {0, 0};
|
||||
Vector2 last_mouse_coords = {0, 0};
|
||||
|
||||
float delta_time;
|
||||
float refresh_rate;
|
||||
int refresh_count;
|
||||
|
||||
/// Executes event handlers for keyboard release events.
|
||||
/// Returns the most accurate and recent available mouse coordinates.
|
||||
/// @note Call this version at most **once** per-frame. It polls the X-Window server and therefore is quite slow.
|
||||
/// @see getCursorPos();
|
||||
Vector2 GetAccurateMouseCoordinates() const;
|
||||
|
||||
/// Executes event handlers for keyboard rele;ase events.
|
||||
void processKeyRelease (Key key);
|
||||
/// Executes event handlers for keyboard press events.
|
||||
void processKeyPress (Key key);
|
||||
/// Executes event handlers for mouse press events.
|
||||
void processOnClose();
|
||||
void processOnOpen();
|
||||
/// Executes event handlers for mouse press events.
|
||||
void processMousePress(MouseButton btn);
|
||||
/// Executes event handlers for mouse release events.
|
||||
void processMouseRelease(MouseButton btn);
|
||||
@@ -311,5 +321,7 @@ namespace ReWindow
|
||||
void processFocusIn();
|
||||
/// Executes event handlers for window unfocus events.
|
||||
void processFocusOut();
|
||||
|
||||
void processMouseMove(Vector2 last_pos, Vector2 new_pos);
|
||||
};
|
||||
}
|
@@ -34,7 +34,7 @@ Cursor invisible_cursor = 0;
|
||||
Vector2 render_area_position = {0, 0};
|
||||
Vector2 position = {0, 0};
|
||||
bool should_poll_x_for_mouse_pos = true;
|
||||
Vector2 cursor_position_this_frame = {0, 0};
|
||||
|
||||
|
||||
using namespace ReWindow;
|
||||
|
||||
@@ -68,15 +68,14 @@ void RWindow::refresh() {
|
||||
|
||||
|
||||
OnRefresh(delta_time);
|
||||
should_poll_x_for_mouse_pos = true;
|
||||
Vector2 mouse_coords = getCursorPos();
|
||||
should_poll_x_for_mouse_pos = false;
|
||||
|
||||
if (mouse_coords != cursor_position_this_frame) {
|
||||
cursor_position_this_frame = mouse_coords;
|
||||
auto eventData = MouseMoveEvent(mouse_coords);
|
||||
OnMouseMove(eventData);
|
||||
OnMouseMoveEvent(eventData);
|
||||
// Only call once and cache the result.
|
||||
mouse_coords = GetAccurateMouseCoordinates();
|
||||
|
||||
/// TODO: Implement optional minimum epsilon to trigger a Mouse Update.
|
||||
if (mouse_coords != last_mouse_coords) {
|
||||
processMouseMove(last_mouse_coords, mouse_coords);
|
||||
last_mouse_coords = mouse_coords;
|
||||
}
|
||||
|
||||
auto end_frame = std::chrono::high_resolution_clock::now();
|
||||
@@ -134,6 +133,8 @@ void RWindow::pollEvents() {
|
||||
Logger::Debug(std::format("Recieved event '{}'", "ClientMessage"));
|
||||
|
||||
if (xev.xclient.message_type == XInternAtom(display, "WM_PROTOCOLS", False) && static_cast<Atom>(xev.xclient.data.l[0]) == wmDeleteWindow) {
|
||||
|
||||
|
||||
destroyWindow();
|
||||
system("xset r on");
|
||||
exit(0);
|
||||
@@ -240,11 +241,7 @@ void RWindow::setSize(int newWidth, int newHeight) {
|
||||
Logger::Debug(std::format("Set size for window '{}'. width={} height={}", this->title, newWidth, newHeight));
|
||||
}
|
||||
|
||||
Vector2 RWindow::getCursorPos() const {
|
||||
/* If we've already gotten it for this frame
|
||||
* don't ask X11 again because it's slow */
|
||||
if (!should_poll_x_for_mouse_pos)
|
||||
return cursor_position_this_frame;
|
||||
Vector2 RWindow::GetAccurateMouseCoordinates() const {
|
||||
|
||||
Window root_return, child_return;
|
||||
int root_x_ret, root_y_ret;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include <rewindow/types/window.h>
|
||||
#include <rewindow/types/window.h>
|
||||
#include "rewindow/logger/logger.h"
|
||||
std::string RWindowFlagToStr(RWindowFlags flag) {
|
||||
switch (flag) {
|
||||
@@ -33,7 +33,7 @@ RWindow::RWindow(const std::string& title, int width, int height, RenderingAPI r
|
||||
title(title), width(width), height(height), renderer(renderer) {}
|
||||
|
||||
Vector2 RWindow::GetMouseCoordinates() const {
|
||||
return getCursorPos();
|
||||
return mouse_coords;
|
||||
}
|
||||
|
||||
bool RWindow::getFlag(RWindowFlags flag) const {
|
||||
@@ -77,6 +77,13 @@ void RWindow::processMousePress(MouseButton btn)
|
||||
OnMouseButtonDown(eventData);
|
||||
}
|
||||
|
||||
void RWindow::processMouseMove(Vector2 last_pos, Vector2 new_pos)
|
||||
{
|
||||
auto eventData = MouseMoveEvent(new_pos);
|
||||
OnMouseMove(eventData);
|
||||
OnMouseMoveEvent(eventData);
|
||||
}
|
||||
|
||||
void RWindow::processMouseRelease(MouseButton btn)
|
||||
{
|
||||
auto eventData = MouseButtonUpEvent(btn);
|
||||
@@ -146,5 +153,17 @@ void RWindow::processKeyPress(Key key) {
|
||||
OnKeyDownEvent(key);
|
||||
}
|
||||
|
||||
void RWindow::processOnClose()
|
||||
{
|
||||
OnClosing();
|
||||
OnClosingEvent();
|
||||
}
|
||||
|
||||
void RWindow::processOnOpen()
|
||||
{
|
||||
OnOpen();
|
||||
OnOpenEvent();
|
||||
}
|
||||
|
||||
|
||||
void RWindow::Close() {}
|
Reference in New Issue
Block a user