Merge pull request 'brokenbullshit' (#12) from brokenbullshit into main
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m56s

Reviewed-on: #12
This commit is contained in:
maxine
2024-08-23 11:01:00 -04:00
10 changed files with 65 additions and 43 deletions

View File

@@ -18,17 +18,17 @@ include(cmake/CPM.cmake)
CPMAddPackage(
NAME J3ML
URL https://git.redacted.cc/josh/j3ml/archive/Release-3.0.zip
URL https://git.redacted.cc/josh/j3ml/archive/Release-3.1.zip
)
CPMAddPackage(
NAME Event
URL https://git.redacted.cc/josh/Event/archive/Release-6.zip
URL https://git.redacted.cc/josh/Event/archive/Release-10.zip
)
CPMAddPackage(
NAME jlog
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-12.zip
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-15.zip
)
find_package(OpenGL REQUIRED)
@@ -39,12 +39,14 @@ include_directories(${jlog_SOURCE_DIR}/include)
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")
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/linux/*.cpp" "src/platform/shared/*.cpp" "src/logger/*.cpp" )
endif()
if(WIN32)
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/windows/*.cpp" "src/platform/shared/*.cpp")
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/windows/*.cpp" "src/platform/shared/*.cpp" "src/logger/*.cpp")
endif()
include_directories("include")

View File

@@ -12,7 +12,7 @@ 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
apt-get install cmake make gcc g++ libx11-6 libx11-dev libgl-dev libxrandr-dev
```
Clone the repository

View File

@@ -0,0 +1,10 @@
#pragma once
#include "jlog/Logger.hpp"
namespace ReWindow::Logger {
using namespace jlog;
extern GenericLogger Fatal;
extern GenericLogger Debug;
}

View File

@@ -2,6 +2,7 @@
#include <cstdint>
#include <vector>
#include <Event.h>
#include <EventConnection.h> // TODO: Fix this shit to where we don't need to include both files they should just be bundled together
#include <map>
#include <thread>
#include <rewindow/types/key.h>
@@ -139,13 +140,13 @@ namespace ReWindow
#pragma region Callbacks
/// Bindable Non-intrusive event handlers
/// Use these when you can't override the base window class
Event<> OnOpenEvent;
Event<> OnClosingEvent;
Event<int> OnOpenEvent;
Event<int> OnClosingEvent;
Event<RWindowEvent> OnFocusLostEvent;
Event<RWindowEvent> OnFocusGainEvent;
Event<float> OnRefreshEvent;
Event<WindowResizeRequestEvent> OnResizeRequestEvent;
Event<KeyDownEvent> OnKeyDownEvent;
Event<KeyDownEvent> OnKeyDownEvent;
Event<KeyUpEvent> OnKeyUpEvent;
Event<MouseMoveEvent> OnMouseMoveEvent;
Event<MouseButtonDownEvent> OnMouseButtonDownEvent;

View File

@@ -1,7 +1,7 @@
#include <iostream>
#include <rewindow/types/window.h>
#include <rewindow/types/display.h>
#include <jlog/jlog.hpp>
#include <rewindow/logger/logger.h>
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Windows :/
#if _WIN32
@@ -43,17 +43,17 @@ class MyWindow : public ReWindow::RWindow {
int main() {
auto* window = new MyWindow("Test Window", 600, 480);
DEBUG(std::format("New window '{}' created. width={} height={}", window->getTitle(), window->getWidth(), window->getHeight()));
jlog::Debug(std::format("New window '{}' created. width={} height={}", window->getTitle(), window->getWidth(), window->getHeight()));
window->setRenderer(RenderingAPI::OPENGL);
DEBUG(std::format("Rendering API OPENGL set for window '{}'", window->getTitle()));
jlog::Debug(std::format("Rendering API OPENGL set for window '{}'", window->getTitle()));
window->Open();
DEBUG(std::format("Opened window '{}'", window->getTitle()));
jlog::Debug(std::format("Opened window '{}'", window->getTitle()));
// TODO: Cannot set flags until after window is open
// Make this work somehow
DEBUG("TODO: Cannot set flags until after window is open")
jlog::Debug("TODO: Cannot set flags until after window is open");
window->setFullscreen(false);
window->setVsyncEnabled(true);
window->setResizable(true);
@@ -82,7 +82,7 @@ int main() {
}
}
DEBUG(std::format("Window '{}' flags: IN_FOCUS={} FULLSCREEN={} RESIZEABLE={} VSYNC={} QUIT={}",
ReWindow::Logger::Debug(std::format("Window '{}' flags: IN_FOCUS={} FULLSCREEN={} RESIZEABLE={} VSYNC={} QUIT={}",
window->getTitle(),
window->getFlag(RWindowFlags::IN_FOCUS),
window->getFlag(RWindowFlags::FULLSCREEN),
@@ -90,12 +90,14 @@ int main() {
window->getFlag(RWindowFlags::VSYNC),
window->getFlag(RWindowFlags::QUIT)));
window->OnKeyDownEvent += [&] (ReWindow::KeyDownEvent e) {
DEBUG(e.key.CharCode);
jlog::Debug(e.key.CharCode);
};
window->OnMouseButtonDownEvent += [&] (ReWindow::MouseButtonDownEvent e) {
DEBUG(e.Button.CharCode);
jlog::Debug(e.Button.CharCode);
};
while (window->isAlive()) {

7
src/logger/logger.cpp Normal file
View File

@@ -0,0 +1,7 @@
#include "rewindow/logger/logger.h"
namespace ReWindow::Logger {
using namespace jlog;
GenericLogger Fatal {"ReWindow::fatal", GlobalLogFile, Colors::Reds::Crimson, Colors::Gray, Colors::Gray, Colors::Reds::Crimson, Colors::White};
GenericLogger Debug {"ReWindow::debug", GlobalLogFile, Colors::Purples::Purple, Colors::Gray, Colors::Gray, Colors::Purples::Purple, Colors::White};
}

View File

@@ -8,7 +8,7 @@
#include <rewindow/types/window.h>
#include <rewindow/types/cursors.h>
#include <J3ML/J3ML.hpp>
#include <jlog/jlog.hpp>
#include "rewindow/logger/logger.h"
@@ -35,20 +35,20 @@ Cursor invisible_cursor = 0;
using namespace ReWindow;
void RWindow::raise() const {
DEBUG(std::format("Raising window '{}'", this->title));
Logger::Debug(std::format("Raising window '{}'", this->title));
XRaiseWindow(display, window);
}
void RWindow::lower() const
{
DEBUG(std::format("Lowering window '{}'", this->title));
Logger::Debug(std::format("Lowering window '{}'", this->title));
XLowerWindow(display, window);
}
void RWindow::destroyWindow() {
DEBUG(std::format("Destroying window '{}'", this->title));
Logger::Debug(std::format("Destroying window '{}'", this->title));
XDestroySubwindows(display, window);
DEBUG(std::format("Destroyed window '{}'", this->title));
Logger::Debug(std::format("Destroyed window '{}'", this->title));
XDestroyWindow(display, window);
delete this;
}
@@ -88,13 +88,13 @@ void RWindow::setFlag(RWindowFlags flag, bool state) {
flags[(int) flag] = state;
//Once you've done this you cannot make it resizable again.
if (flag == RWindowFlags::RESIZABLE && !state) {
DEBUG("Once you've done this you cannot make it resizable again.");
Logger::Debug("Once you've done this you cannot make it resizable again.");
hints.flags = PMinSize | PMaxSize;
hints.min_width = hints.max_width = windowAttributes.width;
hints.min_height = hints.max_height = windowAttributes.height;
XSetWMNormalHints(display, window, &hints);
}
DEBUG(std::format("Set flag '{}' to state '{}' for window '{}'", RWindowFlagToStr(flag), state, this->title));
Logger::Debug(std::format("Set flag '{}' to state '{}' for window '{}'", RWindowFlagToStr(flag), state, this->title));
}
void RWindow::pollEvents() {
@@ -102,7 +102,7 @@ void RWindow::pollEvents() {
XNextEvent(display, &xev);
if (xev.type == ClientMessage)
DEBUG(std::format("Recieved event '{}'", "ClientMessage"));
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();
@@ -111,7 +111,7 @@ void RWindow::pollEvents() {
}
if (xev.type == FocusIn) {
DEBUG(std::format("Recieved event '{}'", "FocusIn"));
Logger::Debug(std::format("Recieved event '{}'", "FocusIn"));
XAutoRepeatOff(display);
//focusGained.Invoke();
RWindowEvent event {};
@@ -124,7 +124,7 @@ void RWindow::pollEvents() {
}
if (xev.type == FocusOut) {
DEBUG(std::format("Recieved event '{}'", "FocusOut"));
Logger::Debug(std::format("Recieved event '{}'", "FocusOut"));
XAutoRepeatOn(display);
//focusLost.Invoke();
RWindowEvent event {};
@@ -137,7 +137,7 @@ void RWindow::pollEvents() {
}
if (xev.type == KeyRelease) {
DEBUG(std::format("Recieved event '{}'", "KeyRelease"));
Logger::Debug(std::format("Recieved event '{}'", "KeyRelease"));
auto scancode = (X11Scancode) xev.xkey.keycode;
auto key = GetKeyFromX11Scancode(scancode);
OnKeyUpEvent(key);
@@ -146,7 +146,7 @@ void RWindow::pollEvents() {
}
if (xev.type == KeyPress) {
DEBUG(std::format("Recieved event '{}'", "KeyPress"));
Logger::Debug(std::format("Recieved event '{}'", "KeyPress"));
auto scancode = (X11Scancode) xev.xkey.keycode;
auto key = GetKeyFromX11Scancode(scancode);
OnKeyDownEvent(key);
@@ -156,7 +156,7 @@ void RWindow::pollEvents() {
}
if (xev.type == ButtonRelease) {
DEBUG(std::format("Recieved event '{}'", "ButtonRelease"));
Logger::Debug(std::format("Recieved event '{}'", "ButtonRelease"));
MouseButton button = GetMouseButtonFromXButton(xev.xbutton.button);
auto eventData = MouseButtonUpEvent();
eventData.Button = button;
@@ -166,7 +166,7 @@ void RWindow::pollEvents() {
}
if (xev.type == ButtonPress) {
DEBUG(std::format("Recieved event '{}'", "ButtonPress"));
Logger::Debug(std::format("Recieved event '{}'", "ButtonPress"));
MouseButton button = GetMouseButtonFromXButton(xev.xbutton.button);
auto eventData = MouseButtonDownEvent(button);
eventData.Button = button;
@@ -177,17 +177,17 @@ void RWindow::pollEvents() {
if (xev.type == Expose)
{
DEBUG(std::format("Recieved event '{}'", "Expose"));
Logger::Debug(std::format("Recieved event '{}'", "Expose"));
}
// NOTE: This event is functionally useless, as it only informs of the very beginning and end of a mouse movement.
if (xev.type == MotionNotify)
{
DEBUG(std::format("Recieved event '{}'", "MotionNotify"));
Logger::Debug(std::format("Recieved event '{}'", "MotionNotify"));
}
if (xev.type == ResizeRequest) {
DEBUG(std::format("Recieved event '{}'", "ResizeRequest"));
Logger::Debug(std::format("Recieved event '{}'", "ResizeRequest"));
this->width = xev.xresizerequest.width;
this->height = xev.xresizerequest.height;
auto eventData = WindowResizeRequestEvent();
@@ -211,7 +211,7 @@ void RWindow::setSize(int newWidth, int newHeight) {
XResizeWindow(display, window, newWidth, newHeight);
XFlush(display);
glViewport(0, 0, width, height);
DEBUG(std::format("Set size for window '{}'. width={} height={}", this->title, newWidth, newHeight));
Logger::Debug(std::format("Set size for window '{}'. width={} height={}", this->title, newWidth, newHeight));
}
Vector2 RWindow::getCursorPos() const {
@@ -276,7 +276,7 @@ bool RWindow::isResizable() const {
}
void RWindow::fullscreen() {
DEBUG(std::format("Fullscreening window '{}'", this->title));
Logger::Debug(std::format("Fullscreening window '{}'", this->title));
fullscreenmode = true;
XEvent xev;
@@ -293,11 +293,11 @@ void RWindow::fullscreen() {
xev.xclient.data.l[1] = fullscreenmode;
xev.xclient.data.l[2] = 0;
XSendEvent(display, DefaultRootWindow(display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
DEBUG(std::format("Fullscreened window '{}'", this->title));
Logger::Debug(std::format("Fullscreened window '{}'", this->title));
}
void RWindow::restoreFromFullscreen() {
DEBUG(std::format("Restoring window '{}' from fullscreen", this->title));
Logger::Debug(std::format("Restoring window '{}' from fullscreen", this->title));
fullscreenmode = false;
XEvent xev;
Atom wm_state = XInternAtom(display, "_NET_WM_STATE", False);
@@ -311,7 +311,7 @@ void RWindow::restoreFromFullscreen() {
xev.xclient.data.l[1] = fullscreenmode;
xev.xclient.data.l[2] = 0;
XSendEvent(display, DefaultRootWindow(display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
DEBUG(std::format("Restored window '{}' from fullscreen", this->title));
Logger::Debug(std::format("Restored window '{}' from fullscreen", this->title));
}
void RWindow::setVsyncEnabled(bool b) {

View File

@@ -1,5 +1,5 @@
#include <rewindow/types/window.h>
#include <jlog/jlog.hpp>
#include "rewindow/logger/logger.h"
std::string RWindowFlagToStr(RWindowFlags flag) {
switch (flag) {
case RWindowFlags::IN_FOCUS: return "IN_FOCUS";

View File

@@ -1,5 +1,5 @@
#include <rewindow/types/key.h>
#include <jlog/jlog.hpp>
//#include <rewindow/logger.h>
//std::vector<Key> Key::keyboard = {};
std::vector<Key> Key::GetKeyboard() { return keyboard; }

View File

@@ -1,6 +1,6 @@
#include <rewindow/types/mousebutton.h>
#include <string>
#include <jlog/jlog.hpp>
#include "rewindow/logger/logger.h"
MouseButton::MouseButton() {
}
@@ -26,7 +26,7 @@ MouseButton GetMouseButtonFromXButton(unsigned int button) {
case 8: return MouseButtons::Mouse4;
case 9: return MouseButtons::Mouse5;
default: {
FATAL("Undefined XButtonCode: " + std::to_string((int) button));
ReWindow::Logger::Fatal("Undefined XButtonCode: " + std::to_string((int) button));
return MouseButtons::Unimplemented;
}
}