refactor input.h and related

This commit is contained in:
A-lex-Ra
2024-02-23 18:49:15 +06:00
parent 9c31c6c8b7
commit 8bb1045e34
12 changed files with 236 additions and 254 deletions
+2 -2
View File
@@ -205,7 +205,7 @@ bool SlotView::isHighlighted() const {
return highlighted;
}
void SlotView::clicked(gui::GUI* gui, int button) {
void SlotView::clicked(gui::GUI* gui, mousecode button) {
if (bound == nullptr)
return;
@@ -260,7 +260,7 @@ void SlotView::clicked(gui::GUI* gui, int button) {
}
void SlotView::focus(gui::GUI* gui) {
clicked(gui, 0);
clicked(gui, mousecode::BUTTON_1);
}
void SlotView::bind(
+1 -1
View File
@@ -72,7 +72,7 @@ public:
void setHighlighted(bool flag);
bool isHighlighted() const;
virtual void clicked(gui::GUI*, int) override;
virtual void clicked(gui::GUI*, mousecode) override;
virtual void focus(gui::GUI*) override;
void bind(
+4 -4
View File
@@ -71,10 +71,10 @@ void GUI::actMouse(float delta) {
pressed = nullptr;
}
if (hover) {
for (int i = mousecode::BUTTON_1; i < mousecode::BUTTON_1+12; i++) {
if (hover) {//WTF?! FIXME
for (int i = static_cast<int>(mousecode::BUTTON_1); i < static_cast<int>(mousecode::BUTTON_1)+12; i++) {
if (Events::jclicked(i)) {
hover->clicked(this, i);
hover->clicked(this, static_cast<mousecode>(i));
}
}
}
@@ -101,7 +101,7 @@ void GUI::act(float delta) {
focus->typed(codepoint);
}
for (auto key : Events::pressedKeys) {
focus->keyPressed(key);
focus->keyPressed(static_cast<keycode>(key)); // temporary solution
}
if (!Events::_cursor_locked) {
+3 -2
View File
@@ -7,6 +7,7 @@
#include <string>
#include <functional>
#include "../../delegates.h"
#include "../../window/input.h"
class GfxContext;
class Assets;
@@ -85,7 +86,7 @@ namespace gui {
virtual void focus(GUI*) {focused = true;}
virtual void click(GUI*, int x, int y);
virtual void clicked(GUI*, int button) {}
virtual void clicked(GUI*, mousecode button) {}
virtual void mouseMove(GUI*, int x, int y) {};
virtual void mouseRelease(GUI*, int x, int y);
virtual void scrolled(int value);
@@ -98,7 +99,7 @@ namespace gui {
virtual bool isFocuskeeper() const {return false;}
virtual void typed(unsigned int codepoint) {};
virtual void keyPressed(int key) {};
virtual void keyPressed(keycode key) {};
/** Check if screen position is inside of the element
* @param pos screen position */
+5 -7
View File
@@ -441,7 +441,7 @@ void TextBox::mouseMove(GUI*, int x, int y) {
extendSelection(index);
}
void TextBox::keyPressed(int key) {
void TextBox::keyPressed(keycode key) {
bool shiftPressed = Events::pressed(keycode::LEFT_SHIFT);
uint previousCaret = caret;
if (key == keycode::BACKSPACE) {
@@ -624,16 +624,14 @@ void InputBindBox::drawBackground(const GfxContext* pctx, Assets* assets) {
label->setText(util::str2wstr_utf8(binding.text()));
}
void InputBindBox::clicked(GUI*, int button) {
binding.type = inputtype::mouse;
binding.code = button;
void InputBindBox::clicked(GUI*, mousecode button) {
binding.reset(button);
defocus();
}
void InputBindBox::keyPressed(int key) {
void InputBindBox::keyPressed(keycode key) {
if (key != keycode::ESCAPE) {
binding.type = inputtype::keyboard;
binding.code = key;
binding.reset(key);
}
defocus();
}
+3 -3
View File
@@ -139,7 +139,7 @@ namespace gui {
virtual void draw(const GfxContext* pctx, Assets* assets) override;
virtual void drawBackground(const GfxContext* pctx, Assets* assets) override;
virtual void typed(unsigned int codepoint) override;
virtual void keyPressed(int key) override;
virtual void keyPressed(keycode key) override;
virtual void setTextSupplier(wstringsupplier supplier);
virtual void setTextConsumer(wstringconsumer consumer);
virtual void setTextValidator(wstringchecker validator);
@@ -178,8 +178,8 @@ namespace gui {
InputBindBox(Binding& binding, glm::vec4 padding=glm::vec4(6.0f));
virtual void drawBackground(const GfxContext* pctx, Assets* assets) override;
virtual void clicked(GUI*, int button) override;
virtual void keyPressed(int key) override;
virtual void clicked(GUI*, mousecode button) override;
virtual void keyPressed(keycode key) override;
virtual bool isFocuskeeper() const override {return true;}
};
+2 -2
View File
@@ -386,9 +386,9 @@ void Hud::update(bool visible) {
hotbarView->setVisible(visible);
if (!gui->isFocusCaught() && !pause) {
for (int i = keycode::NUM_1; i <= keycode::NUM_9; i++) {
for (int i = static_cast<int>(keycode::NUM_1); i <= static_cast<int>(keycode::NUM_9); i++) {
if (Events::jpressed(i)) {
player->setChosenSlot(i - keycode::NUM_1);
player->setChosenSlot(i - static_cast<int>(keycode::NUM_1));
}
}
if (Events::jpressed(keycode::NUM_0)) {