aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/window.hpp41
-rw-r--r--src/main.cpp2
-rw-r--r--src/utils.cpp3
-rw-r--r--src/window.cpp14
4 files changed, 49 insertions, 11 deletions
diff --git a/include/window.hpp b/include/window.hpp
index 66bd0eb..45d27a8 100644
--- a/include/window.hpp
+++ b/include/window.hpp
@@ -32,6 +32,7 @@ class vkrenderer;
// BUTTON5 = 4096,
// };
+// TODO improve this
#if defined(WINDOWS)
enum KEYS: uint32_t {
SHIFT = 0x10,
@@ -65,6 +66,43 @@ enum KEYS: uint32_t {
Z,
MAX_KEYS = 255
};
+#else
+enum KEYS: uint32_t {
+ A = 0x61,
+ B,
+ C,
+ D,
+ E,
+ F,
+ G,
+ H,
+ I,
+ J,
+ K,
+ L,
+ M,
+ N,
+ O,
+ P,
+ Q,
+ R,
+ S,
+ T,
+ U,
+ V,
+ W,
+ X,
+ Y,
+ Z,
+ LSHIFT = 65505,
+ RSHIFT,
+ LCTRL,
+ RCTRL,
+ LALT = 65513,
+ RALT,
+ MAX_KEYS = 0xffff
+};
+#endif
enum BUTTONS: uint32_t {
LEFT,
@@ -72,7 +110,6 @@ enum BUTTONS: uint32_t {
MIDDLE,
MAX_BUTTONS = 255
};
-#endif
enum EVENT_TYPES: int32_t {
QUIT,
@@ -89,8 +126,6 @@ struct event {
uint32_t height;
KEYS key;
BUTTONS button;
- // uint32_t modifiers;
- // uint32_t keycode;
int32_t x;
int32_t y;
EVENT_TYPES type;
diff --git a/src/main.cpp b/src/main.cpp
index 774429d..a91e9e5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -81,7 +81,7 @@ int main() {
}
case EVENT_TYPES::KEY_PRESS: {
auto move_speed = 0.01f * delta_time;
- if (wnd.keyboard[KEYS::SHIFT]) {
+ if (wnd.keyboard[KEYS::LSHIFT] || wnd.keyboard[KEYS::RSHIFT]) {
move_speed *= 2.f;
}
diff --git a/src/utils.cpp b/src/utils.cpp
index 1c6fac1..3416714 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -91,8 +91,7 @@ void random_scene(sphere *world) {
struct input_data create_inputs(uint32_t width, uint32_t height) {
// Image dimensions
- // const float aspect_ratio = 16.0 / 9.0;
- const float aspect_ratio = 1;
+ const float aspect_ratio = (float)width / (float) height;
const uint32_t samples_per_pixel = 1;
const uint32_t max_depth = 2;
diff --git a/src/window.cpp b/src/window.cpp
index 840d570..a353809 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -119,12 +119,16 @@ void window::poll_events() {
}
case XCB_KEY_RELEASE:
case XCB_KEY_PRESS: {
- auto key_press_event = (xcb_key_press_event_t*)event;
- auto keysym = xkb_state_key_get_one_sym(keyboard_state, key_press_event->detail);
+ auto key_press_event = (xcb_key_press_event_t*)event;
+ auto keysym = xkb_state_key_get_one_sym(keyboard_state, key_press_event->detail);
+ auto isKeyPress = event->response_type == XCB_KEY_PRESS;
+ auto key = (KEYS)keysym;
+
+ keyboard[key] = isKeyPress;
+
struct event new_event = {
- .type = event->response_type == XCB_KEY_PRESS ? EVENT_TYPES::KEY_PRESS :EVENT_TYPES::KEY_RELEASE
- .modifiers = key_press_event->state;
- .keycode = keysym;
+ .key = key,
+ .type = isKeyPress ? EVENT_TYPES::KEY_PRESS :EVENT_TYPES::KEY_RELEASE
};
events.push_back(new_event);