This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <rewindow/types/inputdevice.hpp>
|
#include <rewindow/types/inputdevice.hpp>
|
||||||
#include <rewindow/types/scancode.h>
|
#include "rewindow/data/scancode.h"
|
||||||
#include <Event.h>
|
#include <Event.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
@@ -15,275 +15,16 @@
|
|||||||
#include <rewindow/types/key.h>
|
#include <rewindow/types/key.h>
|
||||||
#include <Event.h>
|
#include <Event.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <rewindow/types/scancode.h>
|
#include "rewindow/data/scancode.h"
|
||||||
#include <rewindow/types/inputdevice.hpp>
|
#include <rewindow/types/inputdevice.hpp>
|
||||||
//#include <rewindow/types/keyboard.h>
|
//#include <rewindow/types/keyboard.h>
|
||||||
//#include <rewindow/types/gamepad.h>
|
//#include <rewindow/types/gamepad.h>
|
||||||
|
|
||||||
namespace ReWindow
|
namespace ReWindow
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
enum class ReScanCodeIndex : unsigned int {
|
|
||||||
Unimplemented = 0,
|
|
||||||
|
|
||||||
MLeft = 1,
|
|
||||||
MRight = 2,
|
|
||||||
MMiddle = 3,
|
|
||||||
MWheel_Up = 4,
|
|
||||||
MWheel_Down = 5,
|
|
||||||
MSide_A = 8,
|
|
||||||
MSide_B = 9,
|
|
||||||
|
|
||||||
KP_0 = 90,
|
|
||||||
KP_1 = 87,
|
|
||||||
KP_2 = 88,
|
|
||||||
KP_3 = 89,
|
|
||||||
KP_4 = 83,
|
|
||||||
KP_5 = 84,
|
|
||||||
KP_6 = 85,
|
|
||||||
KP_7 = 79,
|
|
||||||
KP_8 = 80,
|
|
||||||
KP_9 = 81,
|
|
||||||
KP_PERIOD = 91,
|
|
||||||
KP_RETURN = 104,
|
|
||||||
KP_PLUS = 86,
|
|
||||||
KP_MINUS = 82,
|
|
||||||
KP_ASTERISK = 63,
|
|
||||||
KP_SLASH = 106,
|
|
||||||
KP_NUMLOCK = 77,
|
|
||||||
PAGEUP = 112,
|
|
||||||
PAGEDOWN = 117,
|
|
||||||
HOME = 110,
|
|
||||||
MENU = 135,
|
|
||||||
END = 115,
|
|
||||||
INSERT = 118,
|
|
||||||
DEL = 119,
|
|
||||||
UP = 111,
|
|
||||||
DOWN = 116,
|
|
||||||
LEFT = 113,
|
|
||||||
RIGHT = 114,
|
|
||||||
BACKSPACE = 22,
|
|
||||||
EQUALS = 21,
|
|
||||||
MINUS = 20,
|
|
||||||
ZERO = 19,
|
|
||||||
NINE = 18,
|
|
||||||
EIGHT = 17,
|
|
||||||
SEVEN = 16,
|
|
||||||
SIX = 15,
|
|
||||||
FIVE = 14,
|
|
||||||
FOUR = 13,
|
|
||||||
THREE = 12,
|
|
||||||
TWO = 11,
|
|
||||||
ONE = 10,
|
|
||||||
GRAVE = 49,
|
|
||||||
BACKSLASH = 51,
|
|
||||||
CLOSING_SQUARE_BRACKET = 35,
|
|
||||||
OPENING_SQUARE_BRACKET = 34,
|
|
||||||
P = 33,
|
|
||||||
O = 32,
|
|
||||||
I = 31,
|
|
||||||
U = 30,
|
|
||||||
Y = 29,
|
|
||||||
T = 28,
|
|
||||||
R = 27,
|
|
||||||
E = 26,
|
|
||||||
W = 25,
|
|
||||||
Q = 24,
|
|
||||||
TAB = 23,
|
|
||||||
RETURN = 36,
|
|
||||||
SINGLEQUOTE = 48,
|
|
||||||
SEMICOLON = 47,
|
|
||||||
L = 46,
|
|
||||||
K = 45,
|
|
||||||
J = 44,
|
|
||||||
H = 43,
|
|
||||||
G = 42,
|
|
||||||
F = 41,
|
|
||||||
D = 40,
|
|
||||||
S = 39,
|
|
||||||
A = 38,
|
|
||||||
CAPSLOCK = 66,
|
|
||||||
RIGHT_SHIFT = 62,
|
|
||||||
SLASH = 61,
|
|
||||||
PERIOD = 60,
|
|
||||||
COMMA = 59,
|
|
||||||
M = 58,
|
|
||||||
N = 57,
|
|
||||||
B = 56,
|
|
||||||
V = 55,
|
|
||||||
C = 54,
|
|
||||||
X = 53,
|
|
||||||
Z = 52,
|
|
||||||
LEFT_SHIFT = 50,
|
|
||||||
RIGHT_CONTROL = 105,
|
|
||||||
RIGHT_ALT = 108,
|
|
||||||
SPACE = 65,
|
|
||||||
LEFT_ALT = 64,
|
|
||||||
SUPER = 133,
|
|
||||||
LEFT_CTRL = 37,
|
|
||||||
ESCAPE = 9,
|
|
||||||
F1 = 67,
|
|
||||||
F2 = 68,
|
|
||||||
F3 = 69,
|
|
||||||
F4 = 70,
|
|
||||||
F5 = 71,
|
|
||||||
F6 = 72,
|
|
||||||
F7 = 73,
|
|
||||||
F8 = 74,
|
|
||||||
F9 = 75,
|
|
||||||
F10 = 76,
|
|
||||||
F11 = 95,
|
|
||||||
F12 = 96,
|
|
||||||
PRINT = 107,
|
|
||||||
SCROLL_LOCK = 78,
|
|
||||||
BREAK = 127,
|
|
||||||
};
|
|
||||||
|
|
||||||
class ReScanCode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string Mnemonic;
|
|
||||||
unsigned int Sindex;
|
|
||||||
|
|
||||||
ReScanCode() = default;
|
|
||||||
explicit ReScanCode(const std::string& string, ReScanCodeIndex sindex);
|
|
||||||
explicit ReScanCode(const std::string& string, unsigned int sindex);
|
|
||||||
bool operator == (const ReScanCode& rs) const;
|
|
||||||
bool operator<(const ReScanCode& rhs) const;
|
|
||||||
ReScanCode(const ReScanCode&) = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace ReScanCodes {
|
|
||||||
static const ReScanCode Unimplemented ("?", 0);
|
|
||||||
|
|
||||||
static const ReScanCode MouseButtonLeft ("ML", ReScanCodeIndex::MLeft);
|
|
||||||
static const ReScanCode MouseButtonRight ("MR", ReScanCodeIndex::MRight);
|
|
||||||
static const ReScanCode MouseButtonMiddle ("MM", ReScanCodeIndex::MMiddle);
|
|
||||||
static const ReScanCode MouseButtonSideA ("M4", ReScanCodeIndex::MSide_A);
|
|
||||||
static const ReScanCode MouseButtonSideB ("M5", ReScanCodeIndex::MSide_B);
|
|
||||||
/// NOTE: IsMouseButtonDown will not return correctly for the mouse-wheel-buttons, because the action is effectively instantaneous.
|
|
||||||
static const ReScanCode MWheelUp ("MWU", ReScanCodeIndex::MWheel_Up);
|
|
||||||
/// NOTE: IsMouseButtonDown will not return correctly for the mouse-wheel-buttons, because the action is effectively instantaneous.
|
|
||||||
static const ReScanCode MWheelDown ("MWD", ReScanCodeIndex::MWheel_Down);
|
|
||||||
|
|
||||||
// TODO: Encode both Uppercase and Lowercase version for each keymap
|
|
||||||
static const ReScanCode Escape ("ESC", ReScanCodeIndex::ESCAPE);
|
|
||||||
static const ReScanCode F1 ("F1", ReScanCodeIndex::F1);
|
|
||||||
static const ReScanCode F2 ("F2", ReScanCodeIndex::F2);
|
|
||||||
static const ReScanCode F3 ("F3", ReScanCodeIndex::F3);
|
|
||||||
static const ReScanCode F4 ("F4", ReScanCodeIndex::F4);
|
|
||||||
static const ReScanCode F5 {"F5", ReScanCodeIndex::F5};
|
|
||||||
static const ReScanCode F6 {"F6", ReScanCodeIndex::F6};
|
|
||||||
static const ReScanCode F7 {"F7", ReScanCodeIndex::F7};
|
|
||||||
static const ReScanCode F8 {"F8", ReScanCodeIndex::F8};
|
|
||||||
static const ReScanCode F9 {"F9", ReScanCodeIndex::F9};
|
|
||||||
static const ReScanCode F10 {"F10", ReScanCodeIndex::F10};
|
|
||||||
static const ReScanCode F11 {"F11", ReScanCodeIndex::F11};
|
|
||||||
static const ReScanCode F12 {"F12", ReScanCodeIndex::F12};
|
|
||||||
static const ReScanCode Print {"PRINT", ReScanCodeIndex::PRINT};
|
|
||||||
static const ReScanCode ScrollLock {"SCROLL_LOCK", ReScanCodeIndex::SCROLL_LOCK};
|
|
||||||
static const ReScanCode Break {"BREAK", ReScanCodeIndex::BREAK};
|
|
||||||
|
|
||||||
//TODO On Windows, Return & KP_RETURN are the same thing.
|
|
||||||
static const ReScanCode NumPadReturn {"KP_↵", ReScanCodeIndex::KP_RETURN};
|
|
||||||
static const ReScanCode NumPadPlus {"KP_+", ReScanCodeIndex::KP_PLUS};
|
|
||||||
static const ReScanCode NumPadMinus {"KP_-", ReScanCodeIndex::KP_MINUS};
|
|
||||||
static const ReScanCode NumPadAsterisk {"KP_*", ReScanCodeIndex::KP_ASTERISK};
|
|
||||||
static const ReScanCode NumPadForwardSlash {"KP_/", ReScanCodeIndex::KP_SLASH};
|
|
||||||
static const ReScanCode NumPadPeriod {"KP_.", ReScanCodeIndex::KP_PERIOD};
|
|
||||||
static const ReScanCode NumPadNumLock {"KP_NUMLOCK", ReScanCodeIndex::KP_NUMLOCK};
|
|
||||||
|
|
||||||
static const ReScanCode NumPad1 {"KP_1", ReScanCodeIndex::KP_1};
|
|
||||||
static const ReScanCode NumPad2 {"KP_2", ReScanCodeIndex::KP_2};
|
|
||||||
static const ReScanCode NumPad3 {"KP_3", ReScanCodeIndex::KP_3};
|
|
||||||
static const ReScanCode NumPad4 {"KP_4", ReScanCodeIndex::KP_4};
|
|
||||||
static const ReScanCode NumPad5 {"KP_5", ReScanCodeIndex::KP_5};
|
|
||||||
static const ReScanCode NumPad6 {"KP_6", ReScanCodeIndex::KP_6};
|
|
||||||
static const ReScanCode NumPad7 {"KP_7", ReScanCodeIndex::KP_7};
|
|
||||||
static const ReScanCode NumPad8 {"kP_8", ReScanCodeIndex::KP_8};
|
|
||||||
static const ReScanCode NumPad9 {"KP_9", ReScanCodeIndex::KP_9};
|
|
||||||
static const ReScanCode NumPad0 {"KP_0", ReScanCodeIndex::KP_0};
|
|
||||||
|
|
||||||
static const ReScanCode Grave {"`", ReScanCodeIndex::GRAVE};
|
|
||||||
static const ReScanCode One {"1", ReScanCodeIndex::ONE};
|
|
||||||
static const ReScanCode Two {"2", ReScanCodeIndex::TWO};
|
|
||||||
static const ReScanCode Three {"3", ReScanCodeIndex::THREE};
|
|
||||||
static const ReScanCode Four {"4", ReScanCodeIndex::FOUR};
|
|
||||||
static const ReScanCode Five {"5", ReScanCodeIndex::FIVE};
|
|
||||||
static const ReScanCode Six {"6", ReScanCodeIndex::SIX};
|
|
||||||
static const ReScanCode Seven {"7", ReScanCodeIndex::SEVEN};
|
|
||||||
static const ReScanCode Eight {"8", ReScanCodeIndex::EIGHT};
|
|
||||||
static const ReScanCode Nine {"9", ReScanCodeIndex::NINE};
|
|
||||||
static const ReScanCode Zero {"0", ReScanCodeIndex::ZERO};
|
|
||||||
static const ReScanCode Minus {"-", ReScanCodeIndex::MINUS};
|
|
||||||
static const ReScanCode Equals {"+", ReScanCodeIndex::EQUALS};
|
|
||||||
static const ReScanCode Backspace {"⌫", ReScanCodeIndex::BACKSPACE};
|
|
||||||
|
|
||||||
static const ReScanCode Tab {"⇥", ReScanCodeIndex::TAB};
|
|
||||||
static const ReScanCode Q {"Q", ReScanCodeIndex::Q};
|
|
||||||
static const ReScanCode W {"W", ReScanCodeIndex::W};
|
|
||||||
static const ReScanCode E {"E", ReScanCodeIndex::E};
|
|
||||||
static const ReScanCode R {"R", ReScanCodeIndex::R};
|
|
||||||
static const ReScanCode T {"T", ReScanCodeIndex::T};
|
|
||||||
static const ReScanCode Y {"Y", ReScanCodeIndex::Y};
|
|
||||||
static const ReScanCode U {"U", ReScanCodeIndex::U};
|
|
||||||
static const ReScanCode I {"I", ReScanCodeIndex::I};
|
|
||||||
static const ReScanCode O {"O", ReScanCodeIndex::O};
|
|
||||||
static const ReScanCode P {"P", ReScanCodeIndex::P};
|
|
||||||
static const ReScanCode LeftBracket {"[", ReScanCodeIndex::OPENING_SQUARE_BRACKET};
|
|
||||||
static const ReScanCode RightBracket {"]", ReScanCodeIndex::CLOSING_SQUARE_BRACKET};
|
|
||||||
static const ReScanCode BackSlash {"\\", ReScanCodeIndex::BACKSLASH};
|
|
||||||
|
|
||||||
static const ReScanCode CapsLock {"CAPS", ReScanCodeIndex::CAPSLOCK};
|
|
||||||
static const ReScanCode A {"A", ReScanCodeIndex::A};
|
|
||||||
static const ReScanCode S {"S", ReScanCodeIndex::S};
|
|
||||||
static const ReScanCode D {"D", ReScanCodeIndex::D};
|
|
||||||
static const ReScanCode F {"F", ReScanCodeIndex::F};
|
|
||||||
static const ReScanCode G {"G", ReScanCodeIndex::G};
|
|
||||||
static const ReScanCode H {"H", ReScanCodeIndex::H};
|
|
||||||
static const ReScanCode J {"J", ReScanCodeIndex::J};
|
|
||||||
static const ReScanCode K {"K", ReScanCodeIndex::K};
|
|
||||||
static const ReScanCode L {"L", ReScanCodeIndex::L};
|
|
||||||
static const ReScanCode Semicolon {";", ReScanCodeIndex::SEMICOLON};
|
|
||||||
static const ReScanCode SingeQuote {"\'", ReScanCodeIndex::SINGLEQUOTE};
|
|
||||||
static const ReScanCode Return {"↵", ReScanCodeIndex::RETURN};
|
|
||||||
|
|
||||||
static const ReScanCode LeftShift {"⇧", ReScanCodeIndex::LEFT_SHIFT};
|
|
||||||
static const ReScanCode Z {"Z", ReScanCodeIndex::Z};
|
|
||||||
static const ReScanCode X {"X", ReScanCodeIndex::X};
|
|
||||||
static const ReScanCode C {"C", ReScanCodeIndex::C};
|
|
||||||
static const ReScanCode V {"V", ReScanCodeIndex::V};
|
|
||||||
static const ReScanCode B {"B", ReScanCodeIndex::B};
|
|
||||||
static const ReScanCode N {"N", ReScanCodeIndex::N};
|
|
||||||
static const ReScanCode M {"M", ReScanCodeIndex::M};
|
|
||||||
static const ReScanCode Comma {",", ReScanCodeIndex::COMMA};
|
|
||||||
static const ReScanCode Period {".", ReScanCodeIndex::PERIOD};
|
|
||||||
static const ReScanCode ForwardSlash {"/", ReScanCodeIndex::SLASH};
|
|
||||||
|
|
||||||
static const ReScanCode LeftControl {"LCTRL", ReScanCodeIndex::LEFT_CTRL};
|
|
||||||
static const ReScanCode Super {"❖", ReScanCodeIndex::SUPER};
|
|
||||||
static const ReScanCode LeftAlt {"🄰", ReScanCodeIndex::LEFT_ALT};
|
|
||||||
static const ReScanCode Space {" ", ReScanCodeIndex::SPACE};
|
|
||||||
static const ReScanCode RightAlt {"R🄰", ReScanCodeIndex::RIGHT_ALT};
|
|
||||||
static const ReScanCode Menu {"▤", ReScanCodeIndex::MENU};
|
|
||||||
static const ReScanCode RightControl {"RCTRL", ReScanCodeIndex::RIGHT_CONTROL};
|
|
||||||
static const ReScanCode RightShift {"R⇧", ReScanCodeIndex::RIGHT_SHIFT};
|
|
||||||
|
|
||||||
static const ReScanCode Insert {"INSERT", ReScanCodeIndex::INSERT};
|
|
||||||
static const ReScanCode Home {"HOME", ReScanCodeIndex::HOME};
|
|
||||||
static const ReScanCode PageUp {"PAGEUP", ReScanCodeIndex::PAGEUP};
|
|
||||||
static const ReScanCode Delete {"DELETE", ReScanCodeIndex::DEL};
|
|
||||||
static const ReScanCode End {"End", ReScanCodeIndex::END};
|
|
||||||
static const ReScanCode PageDown {"PAGEDOWN", ReScanCodeIndex::PAGEDOWN};
|
|
||||||
|
|
||||||
static const ReScanCode UpArrow {("↑"), ReScanCodeIndex::UP};
|
|
||||||
static const ReScanCode DownArrow {("↓"), ReScanCodeIndex::DOWN};
|
|
||||||
static const ReScanCode LeftArrow {("←"), ReScanCodeIndex::LEFT};
|
|
||||||
static const ReScanCode RightArrow {("→"), ReScanCodeIndex::RIGHT};
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//using Key = ReScanCode;
|
//using Key = ReScanCode;
|
||||||
|
|
||||||
using Button = ReScanCode;
|
using Button = ReScanCode;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -338,6 +79,61 @@ namespace ReWindow
|
|||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*class MouseState {
|
||||||
|
public:
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
bool LMB = false;
|
||||||
|
bool RMB = false;
|
||||||
|
bool MMB = false;
|
||||||
|
bool SideButton1 = false;
|
||||||
|
bool SideButton2 = false;
|
||||||
|
bool MWheelUp = false;
|
||||||
|
bool MWheelDown = false;
|
||||||
|
} Buttons;
|
||||||
|
|
||||||
|
|
||||||
|
Vector2 Position;
|
||||||
|
int Wheel = 0;
|
||||||
|
|
||||||
|
[[nodiscard]] bool IsDown(const MouseButton& btn) const
|
||||||
|
{
|
||||||
|
if (btn == MouseButtons::Left) return Buttons.LMB;
|
||||||
|
if (btn == MouseButtons::Right) return Buttons.RMB;
|
||||||
|
if (btn == MouseButtons::Middle) return Buttons.MMB;
|
||||||
|
if (btn == MouseButtons::Mouse4) return Buttons.SideButton1;
|
||||||
|
if (btn == MouseButtons::Mouse5) return Buttons.SideButton2;
|
||||||
|
//if (btn == MouseButtons::MWheelUp) return Buttons.MWheelUp;
|
||||||
|
//if (btn == MouseButtons::MWheelDown) return Buttons.MWheelDown;
|
||||||
|
|
||||||
|
return false; // Unknown button?
|
||||||
|
}
|
||||||
|
|
||||||
|
void Set(const MouseButton& btn, bool state)
|
||||||
|
{
|
||||||
|
if (btn == MouseButtons::Left) Buttons.LMB = state;
|
||||||
|
if (btn == MouseButtons::Right) Buttons.RMB = state;
|
||||||
|
if (btn == MouseButtons::Middle) Buttons.MMB = state;
|
||||||
|
if (btn == MouseButtons::Mouse4) Buttons.SideButton1 = state;
|
||||||
|
if (btn == MouseButtons::Mouse5) Buttons.SideButton2 = state;
|
||||||
|
//if (btn == MouseButtons::MWheelUp) Buttons.MWheelUp = state;
|
||||||
|
//if (btn == MouseButtons::MWheelDown) Buttons.MWheelDown = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool& operator[](const MouseButton& btn)
|
||||||
|
{
|
||||||
|
if (btn == MouseButtons::Left) return Buttons.LMB;
|
||||||
|
if (btn == MouseButtons::Right) return Buttons.RMB;
|
||||||
|
if (btn == MouseButtons::Middle) return Buttons.MMB;
|
||||||
|
if (btn == MouseButtons::Mouse4) return Buttons.SideButton1;
|
||||||
|
if (btn == MouseButtons::Mouse5) return Buttons.SideButton2;
|
||||||
|
//if (btn == MouseButtons::MWheelUp) return Buttons.MWheelUp;
|
||||||
|
//if (btn == MouseButtons::MWheelDown) return Buttons.MWheelDown;
|
||||||
|
|
||||||
|
throw std::runtime_error("Attempted to handle unmapped mouse button");
|
||||||
|
}
|
||||||
|
};*/
|
||||||
|
|
||||||
struct MouseState
|
struct MouseState
|
||||||
{
|
{
|
||||||
ButtonState Left;
|
ButtonState Left;
|
||||||
|
@@ -8,9 +8,11 @@
|
|||||||
#include <rewindow/types/cursors.h>
|
#include <rewindow/types/cursors.h>
|
||||||
#include <rewindow/types/mousebutton.h>
|
#include <rewindow/types/mousebutton.h>
|
||||||
#include <rewindow/types/gamepadbutton.h>
|
#include <rewindow/types/gamepadbutton.h>
|
||||||
#include <J3ML/LinearAlgebra.hpp>
|
|
||||||
#include <rewindow/types/mouse.h>
|
#include <rewindow/types/mouse.h>
|
||||||
#include <rewindow/types/WindowEvents.hpp>
|
#include <rewindow/types/WindowEvents.hpp>
|
||||||
|
#include <rewindow/types/keyboard.h>
|
||||||
|
#include <rewindow/types/gamepad.h>
|
||||||
|
#include <J3ML/LinearAlgebra.hpp>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
|
||||||
enum class RWindowFlags: uint8_t {
|
enum class RWindowFlags: uint8_t {
|
||||||
@@ -34,71 +36,6 @@ namespace ReWindow
|
|||||||
{
|
{
|
||||||
using J3ML::LinearAlgebra::Vector2;
|
using J3ML::LinearAlgebra::Vector2;
|
||||||
|
|
||||||
//class KeyboardState {
|
|
||||||
//public:
|
|
||||||
// std::map<Key, bool> PressedKeys;
|
|
||||||
//};
|
|
||||||
|
|
||||||
//class GamepadState {
|
|
||||||
//public:
|
|
||||||
// std::map<GamepadButton, bool> PressedButtons;
|
|
||||||
//};
|
|
||||||
|
|
||||||
/*class MouseState {
|
|
||||||
public:
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
bool LMB = false;
|
|
||||||
bool RMB = false;
|
|
||||||
bool MMB = false;
|
|
||||||
bool SideButton1 = false;
|
|
||||||
bool SideButton2 = false;
|
|
||||||
bool MWheelUp = false;
|
|
||||||
bool MWheelDown = false;
|
|
||||||
} Buttons;
|
|
||||||
|
|
||||||
|
|
||||||
Vector2 Position;
|
|
||||||
int Wheel = 0;
|
|
||||||
|
|
||||||
[[nodiscard]] bool IsDown(const MouseButton& btn) const
|
|
||||||
{
|
|
||||||
if (btn == MouseButtons::Left) return Buttons.LMB;
|
|
||||||
if (btn == MouseButtons::Right) return Buttons.RMB;
|
|
||||||
if (btn == MouseButtons::Middle) return Buttons.MMB;
|
|
||||||
if (btn == MouseButtons::Mouse4) return Buttons.SideButton1;
|
|
||||||
if (btn == MouseButtons::Mouse5) return Buttons.SideButton2;
|
|
||||||
//if (btn == MouseButtons::MWheelUp) return Buttons.MWheelUp;
|
|
||||||
//if (btn == MouseButtons::MWheelDown) return Buttons.MWheelDown;
|
|
||||||
|
|
||||||
return false; // Unknown button?
|
|
||||||
}
|
|
||||||
|
|
||||||
void Set(const MouseButton& btn, bool state)
|
|
||||||
{
|
|
||||||
if (btn == MouseButtons::Left) Buttons.LMB = state;
|
|
||||||
if (btn == MouseButtons::Right) Buttons.RMB = state;
|
|
||||||
if (btn == MouseButtons::Middle) Buttons.MMB = state;
|
|
||||||
if (btn == MouseButtons::Mouse4) Buttons.SideButton1 = state;
|
|
||||||
if (btn == MouseButtons::Mouse5) Buttons.SideButton2 = state;
|
|
||||||
//if (btn == MouseButtons::MWheelUp) Buttons.MWheelUp = state;
|
|
||||||
//if (btn == MouseButtons::MWheelDown) Buttons.MWheelDown = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool& operator[](const MouseButton& btn)
|
|
||||||
{
|
|
||||||
if (btn == MouseButtons::Left) return Buttons.LMB;
|
|
||||||
if (btn == MouseButtons::Right) return Buttons.RMB;
|
|
||||||
if (btn == MouseButtons::Middle) return Buttons.MMB;
|
|
||||||
if (btn == MouseButtons::Mouse4) return Buttons.SideButton1;
|
|
||||||
if (btn == MouseButtons::Mouse5) return Buttons.SideButton2;
|
|
||||||
//if (btn == MouseButtons::MWheelUp) return Buttons.MWheelUp;
|
|
||||||
//if (btn == MouseButtons::MWheelDown) return Buttons.MWheelDown;
|
|
||||||
|
|
||||||
throw std::runtime_error("Attempted to handle unmapped mouse button");
|
|
||||||
}
|
|
||||||
};*/
|
|
||||||
|
|
||||||
/// RWindow is a class implementation of a platform-independent window abstraction.
|
/// 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.
|
/// This library also provides abstractions for user-input devices, and their interaction with the window.
|
||||||
class RWindow {
|
class RWindow {
|
||||||
@@ -127,6 +64,8 @@ namespace ReWindow
|
|||||||
Event<MouseButtonDownEvent> OnMouseButtonDownEvent;
|
Event<MouseButtonDownEvent> OnMouseButtonDownEvent;
|
||||||
Event<MouseButtonUpEvent> OnMouseButtonUpEvent;
|
Event<MouseButtonUpEvent> OnMouseButtonUpEvent;
|
||||||
Event<MouseWheelEvent> OnMouseWheelEvent;
|
Event<MouseWheelEvent> OnMouseWheelEvent;
|
||||||
|
|
||||||
|
Event<InputDevice*, InputEvent> OnInputDeviceEvent;
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
/// These methods can also be overridden in derived classes.
|
/// These methods can also be overridden in derived classes.
|
||||||
@@ -157,6 +96,7 @@ namespace ReWindow
|
|||||||
Mouse* GetMouse();
|
Mouse* GetMouse();
|
||||||
Keyboard* GetKeyboard();
|
Keyboard* GetKeyboard();
|
||||||
|
|
||||||
|
#pragma region Input Helpers
|
||||||
/// Returns a Vector2 representing mouse coordinates relative to the top-left corner of the window.
|
/// Returns a Vector2 representing mouse coordinates relative to the top-left corner of the window.
|
||||||
/// This result is cached from the operating-system, and as such may be out-of-date.
|
/// This result is cached from the operating-system, and as such may be out-of-date.
|
||||||
/// @see GetAccurateMouseCoordinates().
|
/// @see GetAccurateMouseCoordinates().
|
||||||
@@ -164,6 +104,26 @@ namespace ReWindow
|
|||||||
|
|
||||||
int GetMouseWheelPersistent() const { return currentMouse.Wheel;}
|
int GetMouseWheelPersistent() const { return currentMouse.Wheel;}
|
||||||
|
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#pragma region Cursor Modifiers
|
||||||
|
void SetCursorStyle(CursorStyle style) const;
|
||||||
|
|
||||||
|
void SetCursorCustomIcon() const;
|
||||||
|
|
||||||
|
void SetCursorLocked();
|
||||||
|
|
||||||
|
void SetCursorCenter();
|
||||||
|
|
||||||
|
void RestoreCursorFromLastCenter(); // Feels nicer for users
|
||||||
|
|
||||||
|
/// Hides the cursor when it's inside of our window. Useful for 3D game camera.
|
||||||
|
void SetCursorVisible(bool cursor_enable);
|
||||||
|
|
||||||
|
bool GetCursorVisible();
|
||||||
|
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
/// Sets which rendering API is to be used with this window.
|
/// Sets which rendering API is to be used with this window.
|
||||||
void SetRenderer(RenderingAPI api);
|
void SetRenderer(RenderingAPI api);
|
||||||
|
|
||||||
@@ -267,7 +227,7 @@ namespace ReWindow
|
|||||||
Vector2 GetSize() const;
|
Vector2 GetSize() const;
|
||||||
|
|
||||||
/// Returns the position of the "renderable area" of the window relative to it's top left corner.
|
/// Returns the position of the "renderable area" of the window relative to it's top left corner.
|
||||||
/// (used to account for the width or the border & title bar).
|
/// (used to account for the width of the border & title bar).
|
||||||
Vector2 GetPositionOfRenderableArea() const;
|
Vector2 GetPositionOfRenderableArea() const;
|
||||||
|
|
||||||
/// Requests the operating system to move the window to the specified coordinates on the display.
|
/// Requests the operating system to move the window to the specified coordinates on the display.
|
||||||
@@ -286,20 +246,6 @@ namespace ReWindow
|
|||||||
/// NOTE: The implementation is defined per-OS, and thus there is no guarantee of it always working.
|
/// NOTE: The implementation is defined per-OS, and thus there is no guarantee of it always working.
|
||||||
void Lower() const;
|
void Lower() const;
|
||||||
|
|
||||||
void SetCursorStyle(CursorStyle style) const;
|
|
||||||
|
|
||||||
void SetCursorCustomIcon() const;
|
|
||||||
|
|
||||||
void SetCursorLocked();
|
|
||||||
|
|
||||||
void SetCursorCenter();
|
|
||||||
|
|
||||||
void RestoreCursorFromLastCenter(); // Feels nicer for users
|
|
||||||
|
|
||||||
/// Hides the cursor when it's inside of our window. Useful for 3D game camera.
|
|
||||||
void SetCursorVisible(bool cursor_enable);
|
|
||||||
|
|
||||||
bool GetCursorVisible();
|
|
||||||
|
|
||||||
/// Calls OpenGL's SwapBuffers routine.
|
/// Calls OpenGL's SwapBuffers routine.
|
||||||
/// NOTE: This is only used when the underlying rendering API is set to OpenGL.
|
/// NOTE: This is only used when the underlying rendering API is set to OpenGL.
|
||||||
@@ -330,6 +276,10 @@ namespace ReWindow
|
|||||||
/// Requests the operating system to take the window out of fullscreen mode. Previously saved window size is restored, if possible.
|
/// Requests the operating system to take the window out of fullscreen mode. Previously saved window size is restored, if possible.
|
||||||
void RestoreFromFullscreen();
|
void RestoreFromFullscreen();
|
||||||
|
|
||||||
|
bool DetectsMouse();
|
||||||
|
bool DetectsKeyboard();
|
||||||
|
bool DetectsGamepad();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#pragma region Data
|
#pragma region Data
|
||||||
|
|
||||||
@@ -348,14 +298,12 @@ namespace ReWindow
|
|||||||
bool flags[5];
|
bool flags[5];
|
||||||
std::vector<RWindowEvent> eventLog;
|
std::vector<RWindowEvent> eventLog;
|
||||||
|
|
||||||
|
/// Input Devices;
|
||||||
Mouse* mouse;
|
Mouse* mouse;
|
||||||
//Keyboard* keyboard;
|
Keyboard* keyboard;
|
||||||
|
Gamepad* gamepad;
|
||||||
//KeyboardState currentKeyboard; // Current Frame's Keyboard State
|
|
||||||
//KeyboardState previousKeyboard; // Previous Frame's Keyboard State
|
|
||||||
//MouseState currentMouse;
|
|
||||||
//MouseState previousMouse;
|
|
||||||
|
|
||||||
|
std::vector<InputDevice*> input_devices;
|
||||||
|
|
||||||
|
|
||||||
RenderingAPI renderer = RenderingAPI::OPENGL;
|
RenderingAPI renderer = RenderingAPI::OPENGL;
|
||||||
|
@@ -17,13 +17,35 @@ std::string RWindowFlagToStr(RWindowFlags flag) {
|
|||||||
|
|
||||||
using namespace ReWindow;
|
using namespace ReWindow;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RWindow::RWindow() {
|
RWindow::RWindow() {
|
||||||
title = "ReWindow Application";
|
title = "ReWindow Application";
|
||||||
width = 640;
|
width = 640;
|
||||||
height = 480;
|
height = 480;
|
||||||
|
|
||||||
keyboard = new Keyboard();
|
if (DetectsKeyboard())
|
||||||
mouse = new Mouse();
|
{
|
||||||
|
keyboard = new Keyboard();
|
||||||
|
input_devices.push_back(keyboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DetectsMouse())
|
||||||
|
{
|
||||||
|
mouse = new Mouse();
|
||||||
|
input_devices.push_back(mouse);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DetectsGamepad())
|
||||||
|
{
|
||||||
|
gamepad = new Gamepad();
|
||||||
|
input_devices.push_back(gamepad);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//RWindow::singleton = this;
|
//RWindow::singleton = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user