This commit is contained in:
2024-06-28 19:32:45 -04:00
parent 8f8eabfe47
commit 68a1f52515
5 changed files with 59 additions and 89 deletions

View File

@@ -3,17 +3,12 @@
#pragma once
#include <vector>
#include <J3ML/LinearAlgebra/Vector2.h>
#include <jlog/jlog.hpp>
#include <stdexcept>
#include <iostream>
#if __linux__
#include <X11/X.h>
#endif
#include <string>
#include <rewindow/data/X11Scancodes.h>
#include <rewindow/data/WindowsScancodes.h>
#include <J3ML/LinearAlgebra/Vector2.h>
using J3ML::LinearAlgebra::Vector2;
@@ -169,42 +164,6 @@ namespace MouseButtons
static const MouseButton Unimplemented {"u"};
}
#if __linux__
static MouseButton GetMouseButtonFromXButton(unsigned int button) {
switch(button) {
case Button1: return MouseButtons::Left;
case Button2: return MouseButtons::Middle;
case Button3: return MouseButtons::Right;
case Button4: return MouseButtons::MWheelUp;
case Button5: return MouseButtons::MWheelDown;
//For *whatever* reason. These aren't in X.h
case 8: return MouseButtons::Mouse4;
case 9: return MouseButtons::Mouse5;
default: {
FATAL("Undefined XButtonCode: " + std::to_string((int) button))
return MouseButtons::Unimplemented;
break;
}
}
}
static Key GetKeyFromX11Scancode(X11Scancode code) {
for (auto& key : Key::GetKeyboard())
if (key.x11ScanCode == code)
return key;
std::cout << "Unavaliable Scancode: " + std::to_string((int)code) << std::endl;
return Keys::Space;
}
#endif
#if _WIN32
static Key GetKeyFromWindowsScancode(WindowsScancode code) {
for (const auto& key : Key::GetKeyboard())
if (key.winScanCode == code)
return key;
std::cout << "Unavaliable Scancode: " + std::to_string((int) code) << std::endl;
return Keys::Space;
}
#endif
MouseButton GetMouseButtonFromXButton(unsigned int button);
Key GetKeyFromX11Scancode(X11Scancode code);
Key GetKeyFromWindowsScancode(WindowsScancode code);

View File

@@ -6,20 +6,6 @@
#include <map>
#include <thread>
#include <rewindow/types/key.h>
#if WIN32
#include <windows.h>
#include <windowsx.h>
#include <wingdi.h>
#endif
#if __linux__
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <GL/gl.h>
#include <GL/glx.h>
#endif
#include <rewindow/types/cursors.h>
using namespace std::chrono_literals;
@@ -181,13 +167,6 @@ namespace ReWindow
auto eventData = KeyDownEvent(key);
OnKeyDown(eventData);
}
#ifndef __linux___
void setRect (int nx, int ny, int nw, int nh) {
setPos(nx, ny);
width = nw;
height = nh;
}
#endif
void setRenderer(RenderingAPI api);
void Open();
void Close();
@@ -248,10 +227,6 @@ namespace ReWindow
KeyboardState previousKeyboard; // Previous Frame's Keyboard State
bool fullscreenmode = false;
std::string title;
#ifndef __linux__
int x;
int y;
#endif
int width;
int height;
RenderingAPI renderer;

View File

@@ -1,13 +1,13 @@
#include <rewindow/types/window.h>
#include <rewindow/types/cursors.h>
#include <J3ML/J3ML.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <GL/glx.h>
#include <cstdlib>
#include <cstring>
#include <thread>
#include <rewindow/types/window.h>
#include <rewindow/types/cursors.h>
#include <J3ML/J3ML.h>
#include <jlog/jlog.hpp>
@@ -31,19 +31,6 @@ Atom windowTypeUtilityAtom;
XSizeHints hints;
GLXContext glContext;
std::string RWindowFlagToStr(RWindowFlags flag)
{
switch (flag)
{
case RWindowFlags::IN_FOCUS: return "IN_FOCUS";
case RWindowFlags::FULLSCREEN: return "FULLSCREEN";
case RWindowFlags::RESIZABLE: return "RESIZEABLE";
case RWindowFlags::VSYNC: return "VSYNC";
case RWindowFlags::QUIT: return "QUIT";
case RWindowFlags::MAX_FLAG: return "MAX_FLAG";
}
};
using namespace ReWindow;
void RWindow::raise() const {

View File

@@ -1,4 +1,18 @@
#include <rewindow/types/window.h>
#include <jlog/jlog.hpp>
std::string RWindowFlagToStr(RWindowFlags flag) {
switch (flag) {
case RWindowFlags::IN_FOCUS: return "IN_FOCUS";
case RWindowFlags::FULLSCREEN: return "FULLSCREEN";
case RWindowFlags::RESIZABLE: return "RESIZEABLE";
case RWindowFlags::VSYNC: return "VSYNC";
case RWindowFlags::QUIT: return "QUIT";
case RWindowFlags::MAX_FLAG: return "MAX_FLAG";
default:
FATAL("")
return "unimplemented flag";
}
};
using namespace ReWindow;

View File

@@ -1,5 +1,6 @@
#include <X11/X.h>
#include <rewindow/types/key.h>
#include <memory>
#include <jlog/jlog.hpp>
//std::vector<Key> Key::keyboard = {};
std::vector<Key> Key::GetKeyboard() { return keyboard; }
@@ -29,4 +30,38 @@ bool Key::operator==(const Key &rhs) const {
bool Key::operator<(const Key &rhs) const {
return (this->CharCode < rhs.CharCode);
}
}
MouseButton GetMouseButtonFromXButton(unsigned int button) {
switch(button) {
case Button1: return MouseButtons::Left;
case Button2: return MouseButtons::Middle;
case Button3: return MouseButtons::Right;
case Button4: return MouseButtons::MWheelUp;
case Button5: return MouseButtons::MWheelDown;
//For *whatever* reason. These aren't in X.h
case 8: return MouseButtons::Mouse4;
case 9: return MouseButtons::Mouse5;
default: {
FATAL("Undefined XButtonCode: " + std::to_string((int) button));
return MouseButtons::Unimplemented;
}
}
}
Key GetKeyFromX11Scancode(X11Scancode code) {
for (auto& key : Key::GetKeyboard())
if (key.x11ScanCode == code)
return key;
std::cout << "Unavaliable Scancode: " + std::to_string((int)code) << std::endl;
return Keys::Space;
}
Key GetKeyFromWindowsScancode(WindowsScancode code) {
for (const auto& key : Key::GetKeyboard())
if (key.winScanCode == code)
return key;
std::cout << "Unavaliable Scancode: " + std::to_string((int) code) << std::endl;
return Keys::Space;
}