aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-03 10:54:32 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-03 10:54:32 +0100
commitc2d177ad974a7dd7fda89f70e2c30077deb68a96 (patch)
tree33ae548c9000ab98673cd342f1a7fa021a3b6288
parent8d525bc1c3506f15a5f68672245f845cebe18eef (diff)
Use event structure in poll_event
m---------depends/mgl0
-rw-r--r--include/mglpp/window/Event.hpp105
-rw-r--r--include/mglpp/window/Keyboard.hpp4
-rw-r--r--include/mglpp/window/Mouse.hpp9
-rw-r--r--src/graphics/Text.cpp10
-rw-r--r--src/window/Window.cpp5
6 files changed, 32 insertions, 101 deletions
diff --git a/depends/mgl b/depends/mgl
-Subproject 275e851e8a2b11c2efe7c39787bf331dd3b7527
+Subproject def772cc0efd7c22c6154c6d9f73df1a08fa267
diff --git a/include/mglpp/window/Event.hpp b/include/mglpp/window/Event.hpp
index 47718ff..4c99379 100644
--- a/include/mglpp/window/Event.hpp
+++ b/include/mglpp/window/Event.hpp
@@ -5,119 +5,52 @@
#include "Mouse.hpp"
#include <stdint.h>
+/* These have to match the same structures in mgl event */
+
namespace mgl {
class Event {
public:
struct SizeEvent {
- unsigned int width;
- unsigned int height;
+ int width;
+ int height;
};
struct KeyEvent {
Keyboard::Key code;
- bool alt;
- bool control;
- bool shift;
- bool system;
- };
-
- struct TextEvent {
- uint32_t unicode;
+ bool alt;
+ bool control;
+ bool shift;
+ bool system;
};
struct MouseMoveEvent {
- int x;
- int y;
+ int x; /* relative to left of the window */
+ int y; /* relative to the top of the window */
};
struct MouseButtonEvent {
Mouse::Button button;
- int x;
- int y;
- };
-
- struct MouseWheelEvent {
- int delta;
- int x;
- int y;
- };
-
- struct MouseWheelScrollEvent {
- Mouse::Wheel wheel;
- float delta;
- int x;
- int y;
- };
-
- struct JoystickConnectEvent {
- unsigned int joystick_id;
- };
-
- struct JoystickMoveEvent {
- unsigned int joystick_id;
- /*Joystick::Axis axis;*/
- float position;
- };
-
- struct JoystickButtonEvent {
- unsigned int joystick_id;
- unsigned int button;
- };
-
- struct TouchEvent {
- unsigned int finger;
- int x;
- int y;
- };
-
- struct SensorEvent {
- /*Sensor::Type type;*/
- float x;
- float y;
- float z;
+ int x; /* relative to left of the window */
+ int y; /* relative to top of the window */
};
- enum EventType {
- Closed,
+ enum EventType : int {
+ Unknown,
Resized,
- LostFocus,
- GainedFocus,
- TextEntered,
KeyPressed,
KeyReleased,
- MouseWheelMoved,
- MouseWheelScrolled,
MouseButtonPressed,
MouseButtonReleased,
- MouseMoved,
- MouseEntered,
- MouseLeft,
- JoystickButtonPressed,
- JoystickButtonReleased,
- JoystickMoved,
- JoystickConnected,
- JoystickDisconnected,
- TouchBegan,
- TouchMoved,
- TouchEnded,
- SensorChanged
+ MouseMoved
};
EventType type;
union {
- SizeEvent size;
- KeyEvent key;
- TextEvent text;
- MouseMoveEvent mouse_move;
- MouseButtonEvent mouse_button;
- MouseWheelEvent mouse_wheel;
- MouseWheelScrollEvent mouse_wheel_scroll;
- JoystickMoveEvent joystick_move;
- JoystickButtonEvent joystick_button;
- JoystickConnectEvent joystick_connect;
- TouchEvent touch;
- SensorEvent sensor;
+ SizeEvent size;
+ KeyEvent key;
+ MouseButtonEvent mouse_button;
+ MouseMoveEvent mouse_move;
};
};
}
diff --git a/include/mglpp/window/Keyboard.hpp b/include/mglpp/window/Keyboard.hpp
index 2757871..b744143 100644
--- a/include/mglpp/window/Keyboard.hpp
+++ b/include/mglpp/window/Keyboard.hpp
@@ -4,7 +4,9 @@
namespace mgl {
class Keyboard {
public:
- enum Key {
+ /* Has to match mgl_key */
+ enum Key : int {
+ Unknown,
A,
B,
C,
diff --git a/include/mglpp/window/Mouse.hpp b/include/mglpp/window/Mouse.hpp
index d77659a..c53f076 100644
--- a/include/mglpp/window/Mouse.hpp
+++ b/include/mglpp/window/Mouse.hpp
@@ -4,18 +4,15 @@
namespace mgl {
class Mouse {
public:
- enum Button {
+ /* Has to match mgl_mouse_button */
+ enum Button : int {
+ Unknown,
Left,
Right,
Middle,
XButton1,
XButton2
};
-
- enum Wheel {
- VerticalWheel,
- HorizontalWheel
- };
};
}
diff --git a/src/graphics/Text.cpp b/src/graphics/Text.cpp
index dbaa7c1..b3a32da 100644
--- a/src/graphics/Text.cpp
+++ b/src/graphics/Text.cpp
@@ -7,18 +7,20 @@ extern "C" {
namespace mgl {
Text::Text() : font(nullptr) {
- mgl_text_init(&text, nullptr, nullptr, 0.0f, 0.0f);
+ mgl_text_init(&text, nullptr, nullptr, 0, nullptr);
}
Text::Text(std::string str, Font &font) : Text(std::move(str), vec2f(0.0f, 0.0f), font) {}
Text::Text(std::string str, vec2f position, Font &font) : font(&font), str(std::move(str)) {
- mgl_text_init(&text, font.internal_font(), this->str.c_str(), position.x, position.y);
+ mgl_text_init(&text, font.internal_font(), this->str.c_str(), this->str.size(), nullptr);
+ mgl_text_set_position(&text, { position.x, position.y });
}
Text::Text(const Text &other) {
font = other.font;
- mgl_text_init(&text, font ? font->internal_font() : nullptr, other.str.c_str(), other.text.position.x, other.text.position.y);
+ mgl_text_init(&text, font ? font->internal_font() : nullptr, other.str.c_str(), other.str.size(), nullptr);
+ mgl_text_set_position(&text, { other.text.position.x, other.text.position.y });
}
Text::~Text() {
@@ -44,7 +46,7 @@ namespace mgl {
void Text::set_string(std::string str) {
this->str = std::move(str);
- mgl_text_set_string(&text, this->str.c_str());
+ mgl_text_set_string(&text, this->str.c_str(), this->str.size());
}
const std::string& Text::get_string() const {
diff --git a/src/window/Window.cpp b/src/window/Window.cpp
index 9e1fb75..580737d 100644
--- a/src/window/Window.cpp
+++ b/src/window/Window.cpp
@@ -33,10 +33,7 @@ namespace mgl {
bool Window::poll_event(Event &event) {
if(!window.window)
return false;
-
- /* TODO: Convert c_event to |event| */
- mgl_event c_event;
- return mgl_window_poll_event(&window, &c_event);
+ return mgl_window_poll_event(&window, (mgl_event*)&event);
}
void Window::clear(Color color) {