Compare commits

...

3 Commits

Author SHA1 Message Date
426b02b3ea Migrate to latest J3ML 2024-02-20 03:52:24 -05:00
227ecdb64c Implementing Window::GetSize() 2024-02-14 20:38:26 -05:00
089b110b87 Implementing more of the Windows/X11 KeyMap 2024-02-13 20:24:06 -05:00
6 changed files with 81 additions and 24 deletions

View File

@@ -22,7 +22,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
CPMAddPackage(
NAME J3ML
URL https://git.redacted.cc/josh/j3ml/archive/Prerelease-14.zip
URL https://git.redacted.cc/josh/j3ml/archive/Prerelease-18.zip
)
find_package(OpenGL REQUIRED)

View File

@@ -101,9 +101,10 @@ enum class X11Scancode {
F8 = 74,
F9 = 75,
F10 = 76,
F11 = 77,
F12 = 78,
F11 = 95,
F12 = 96,
PRINT = 107,
SCROLL_LOCK = 78,
BREAK = 127,
};

View File

@@ -7,6 +7,7 @@
#include <J3ML/LinearAlgebra/Vector2.h>
#include <stdexcept>
#include <iostream>
#if __linux__
#include <X11/X.h>
@@ -15,7 +16,7 @@
#include "rewindow/data/X11Scancodes.h"
#include "rewindow/data/WindowsScancodes.h"
using Vector2 = LinearAlgebra::Vector2;
using J3ML::LinearAlgebra::Vector2;
class Key
{
@@ -35,6 +36,7 @@ public:
};
namespace Keys {
// TODO: Encode both Uppercase and Lowercase version for each keymap
static const Key Escape {'\b', X11Scancode::ESCAPE, WindowsScancode::ESCAPE};
static const Key F1 {'\u000f', X11Scancode::F1, WindowsScancode::F1};
static const Key F2 {'\u000f', X11Scancode::F2, WindowsScancode::F2};
@@ -49,16 +51,27 @@ namespace Keys {
static const Key F11 {'\u000f', X11Scancode::F11, WindowsScancode::F11};
static const Key F12 {'\u000f', X11Scancode::F12, WindowsScancode::F12};
static const Key NumPad1 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad2 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad3 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad4 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad5 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad6 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad7 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad8 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad9 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad0 {'\b', X11Scancode::ONE, WindowsScancode::NUMPAD_ONE};
static const Key NumPad1 {'\b', X11Scancode::KP_1, WindowsScancode::NUMPAD_ONE};
static const Key NumPad2 {'\b', X11Scancode::KP_2, WindowsScancode::NUMPAD_ONE};
static const Key NumPad3 {'\b', X11Scancode::KP_3, WindowsScancode::NUMPAD_ONE};
static const Key NumPad4 {'\b', X11Scancode::KP_4, WindowsScancode::NUMPAD_ONE};
static const Key NumPad5 {'\b', X11Scancode::KP_5, WindowsScancode::NUMPAD_ONE};
static const Key NumPad6 {'\b', X11Scancode::KP_6, WindowsScancode::NUMPAD_ONE};
static const Key NumPad7 {'\b', X11Scancode::KP_7, WindowsScancode::NUMPAD_ONE};
static const Key NumPad8 {'\b', X11Scancode::KP_8, WindowsScancode::NUMPAD_ONE};
static const Key NumPad9 {'\b', X11Scancode::KP_9, WindowsScancode::NUMPAD_ONE};
static const Key NumPad0 {'\b', X11Scancode::KP_0, WindowsScancode::NUMPAD_ONE};
static const Key One {'1', X11Scancode::ONE, WindowsScancode::ONE};
static const Key Two {'2', X11Scancode::TWO, WindowsScancode::TWO};
static const Key Three {'3', X11Scancode::THREE, WindowsScancode::THREE};
static const Key Four {'4', X11Scancode::FOUR, WindowsScancode::FOUR};
static const Key Five {'5', X11Scancode::FIVE, WindowsScancode::FIVE};
static const Key Six {'6', X11Scancode::SIX, WindowsScancode::SIX};
static const Key Seven {'7', X11Scancode::SEVEN, WindowsScancode::SEVEN};
static const Key Eight {'8', X11Scancode::EIGHT, WindowsScancode::EIGHT};
static const Key Nine {'9', X11Scancode::NINE, WindowsScancode::NINE};
static const Key Zero {'0', X11Scancode::ZERO, WindowsScancode::ZERO};
static const Key Q {'Q', X11Scancode::Q, WindowsScancode::Q};
static const Key W {'W', X11Scancode::W, WindowsScancode::W};
@@ -96,19 +109,35 @@ namespace Keys {
static const Key Period {'.', X11Scancode::PERIOD, WindowsScancode::PERIOD};
static const Key ForwardSlash {'/', X11Scancode::SLASH, WindowsScancode::SLASH};
static const Key BackSlash {'\\', X11Scancode::BACKSLASH, WindowsScancode::BACKSLASH};
static const Key LShift;
static const Key RShift;
static const Key Space {' ', X11Scancode::SPACE, WindowsScancode::SPACE};
static const Key LControl {'\\', X11Scancode::LEFT_CTRL, WindowsScancode::CTRL};
static const Key RControl {'\\', X11Scancode::RIGHT_CONTROL, WindowsScancode::CTRL};
static const Key LAlt {'\\', X11Scancode::LEFT_ALT, WindowsScancode::ALT};
static const Key RAlt {'\\', X11Scancode::RIGHT_ALT, WindowsScancode::ALT};
static const Key LShift {'\\', X11Scancode::LEFT, WindowsScancode::LEFT_ARROW};
static const Key RShift {'\\', X11Scancode::RIGHT, WindowsScancode::RIGHT_ARROW};
// TODO: Get the right character codes for these
static const Key UpArrow {'\u000a', X11Scancode::UP, WindowsScancode::UP_ARROW};
static const Key DownArrow {'\u000a', X11Scancode::DOWN, WindowsScancode::DOWN_ARROW};
static const Key LeftArrow {'\u000a', X11Scancode::LEFT, WindowsScancode::LEFT_ARROW};
static const Key RightArrow {'\u000a', X11Scancode::RIGHT, WindowsScancode::RIGHT_ARROW};
static const Key Super {'\000a', X11Scancode::SUPER, WindowsScancode::Nothing};
static const Key Backspace {'\b', X11Scancode::BACKSPACE, WindowsScancode::BACKSPACE};
static const Key LeftBracket {'[', X11Scancode::OPENING_SQUARE_BRACKET, WindowsScancode::LEFT_BRACKET};
static const Key RightBracket {']', X11Scancode::CLOSING_SQUARE_BRACKET, WindowsScancode::RIGHT_BRACKET};
}
class GamepadButton {};
class MouseButton {};
using J3ML::LinearAlgebra::Vector2;
class InputService {
public:
@@ -157,7 +186,8 @@ static Key GetKeyFromX11Scancode(X11Scancode code)
if (key.x11ScanCode == code)
return key;
}
throw std::runtime_error("Unavaliable Scancode: " + std::to_string((int)code));
std::cout << "Unavaliable Scancode: " + std::to_string((int)code) << std::endl;
return Keys::Space;
}
static Key GetKeyFromWindowsScancode(WindowsScancode code)
{
@@ -165,5 +195,6 @@ static Key GetKeyFromWindowsScancode(WindowsScancode code)
if (key.winScanCode == code)
return key;
}
throw std::runtime_error("Unavaliable Scancode: " + std::to_string((int)code));
std::cout << "Unavaliable Scancode: " + std::to_string((int)code) << std::endl;
return Keys::Space;
}

View File

@@ -55,7 +55,7 @@ enum class KeyState { Pressed, Released };
namespace ReWindow
{
using LinearAlgebra::Vector2;
using J3ML::LinearAlgebra::Vector2;
class TimestampedEvent {
private:
@@ -129,6 +129,12 @@ namespace ReWindow
public:
MouseButton Button;
};
class WindowResizeRequestEvent : public RWindowEvent
{
public:
Vector2 Size;
};
}
using namespace WindowEvents;
@@ -136,6 +142,7 @@ namespace ReWindow
class RWindow {
private:
Vector2 lastKnownWindowSize {0, 0};
bool flags[4];
std::vector<RWindowEvent> eventLog;
KeyboardState currentKeyboard; // Current Frame's Keyboard State
@@ -155,7 +162,7 @@ namespace ReWindow
virtual void OnFocusGain(const RWindowEvent& e) {}
virtual void OnRefresh(float elapsed) {}
virtual void OnResizeSuccess() {}
virtual bool OnResizeRequest() {}
virtual bool OnResizeRequest(const WindowResizeRequestEvent& e) {}
virtual void OnKeyDownEvent(const KeyDownEvent&) {}
virtual void OnKeyUpEvent(const KeyUpEvent&) {}
virtual void OnMouseMove(const MouseMoveEvent&) {}
@@ -164,6 +171,10 @@ namespace ReWindow
RWindow();
Vector2 GetSize() const
{
}
// TODO: Must be implemented from scratch as a Motif Window in x11
void MessageBox();

View File

@@ -5,7 +5,7 @@
void KeyDown(const ReWindow::WindowEvents::KeyDownEvent& e)
{
std::cout << e.key.CharCode << " pressed" << std::endl;
//std::cout << e.key.CharCode << " pressed" << std::endl;
}
Vector2 mouse_pos;
@@ -21,18 +21,23 @@ class MyWindow : public ReWindow::RWindow
public:
void OnMouseMove(const ReWindow::MouseMoveEvent& e) override
{
std::cout << "Mouse Moved: " << e.Position << " @ " << std::endl;
//std::cout << "Mouse Moved: " << e.Position << " @ " << std::endl;
}
void OnRefresh(float elapsed) override
{
glSwapBuffers();
}
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent& e) override
{
std::cout << "resized to " << e.Size.x << ", " << e.Size.y << std::endl;
return true;
}
};
int main() {
auto* window = new MyWindow();
window->init(RenderingAPI::OPENGL, "name",100,100, true);
window->setFlag(RWindowFlags::RESIZABLE, false);
window->setFlag(RWindowFlags::RESIZABLE, true);
window->onKeyboardPress += KeyDown;
window->onKeyboardRelease += [&](ReWindow::WindowEvents::KeyUpEvent e)

View File

@@ -55,7 +55,7 @@ namespace ReWindow {
ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
PointerMotionMask |
PointerMotionHintMask | FocusChangeMask | StructureNotifyMask | SubstructureRedirectMask |
SubstructureNotifyMask | CWColormap);
SubstructureNotifyMask | CWColormap | ResizeRequest | ResizeRedirectMask);
XMapWindow(display, window);
XStoreName(display, window, title);
wmDeleteWindow = XInternAtom(display, "WM_DELETE_WINDOW", False);
@@ -196,6 +196,15 @@ namespace ReWindow {
//OnMouseMove(eventData);
}
if (xev.type == ResizeRequest)
{
auto eventData = WindowResizeRequestEvent();
lastKnownWindowSize = eventData.Size;
eventData.Size = {(float)xev.xresizerequest.width, (float)xev.xresizerequest.height};
lastKnownWindowSize = eventData.Size;
OnResizeRequest(eventData);
}
}
previousKeyboard = currentKeyboard;