diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-24 00:32:37 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-24 00:32:37 +0200 |
| commit | a638d66ab02c544590b007ca288137b80a5c1239 (patch) | |
| tree | deb1350138ac17565194ad559bb6219cf38c5a8b /editor | |
| parent | f5e4bbb151282861e3bd5ca7755c9d1a97534e3a (diff) | |
a
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/app.hpp | 22 | ||||
| -rw-r--r-- | editor/draw.cpp | 50 | ||||
| -rw-r--r-- | editor/events.cpp | 42 |
3 files changed, 91 insertions, 23 deletions
diff --git a/editor/app.hpp b/editor/app.hpp index b5a22f28..f3c95d6f 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -39,13 +39,12 @@ struct app final : floormat_app void draw_msaa() override; void draw() override; - bool on_mouse_move(const mouse_move_event& event) noexcept override; - bool on_mouse_up_down(const mouse_button_event& event, bool is_down) noexcept override; - bool on_mouse_scroll(const mouse_scroll_event& event) noexcept override; - bool on_key_up_down(const key_event& event, bool is_down) noexcept override; - - bool on_text_input_event(const text_input_event& event) noexcept override; - bool on_text_editing_event(const text_editing_event& event) noexcept override; + void on_mouse_move(const mouse_move_event& event) noexcept override; + void on_mouse_up_down(const mouse_button_event& event, bool is_down) noexcept override; + void on_mouse_scroll(const mouse_scroll_event& event) noexcept override; + void on_key_up_down(const key_event& event, bool is_down) noexcept override; + void on_text_input_event(const text_input_event& event) noexcept override; + //bool on_text_editing_event(const text_editing_event& event) noexcept override; void on_viewport_event(const Magnum::Math::Vector2<int>& size) noexcept override; void on_any_event(const any_event& event) noexcept override; void on_focus_in() noexcept override; @@ -74,14 +73,15 @@ private: void recalc_cursor_tile(); void init_imgui(Vector2i size); - void draw_cursor_tile(); - void draw_wireframe_quad(global_coords pt); - void draw_wireframe_box(global_coords pt); void draw_ui(); float draw_main_menu(); void draw_editor_pane(tile_editor& type, float main_menu_height); void draw_fps(); - void draw_cursor_coord(); + void draw_cursor_tile(); + void render_menu(); + + void draw_wireframe_quad(global_coords pt); + void draw_wireframe_box(global_coords pt); Containers::Pointer<floormat_main> M; [[maybe_unused]] void* _dummy; diff --git a/editor/draw.cpp b/editor/draw.cpp new file mode 100644 index 00000000..33188573 --- /dev/null +++ b/editor/draw.cpp @@ -0,0 +1,50 @@ +#include "app.hpp" +#include "main/floormat-main.hpp" +#include "shaders/tile-shader.hpp" + +namespace floormat { + +void app::draw_wireframe_quad(global_coords pos) +{ + constexpr float LINE_WIDTH = 2; + const auto pt = pos.to_signed(); + auto& shader = M->shader(); + + //if (const auto& [c, tile] = _world[pos]; tile.ground_image) + { + const Vector3 center{pt[0]*TILE_SIZE[0], pt[1]*TILE_SIZE[1], 0}; + shader.set_tint({1, 0, 0, 1}); + _wireframe_quad.draw(shader, {center, {TILE_SIZE[0], TILE_SIZE[1]}, LINE_WIDTH}); + } +} + +void app::draw_wireframe_box(global_coords pos) +{ + constexpr float LINE_WIDTH = 1.5; + auto& shader = M->shader(); + + constexpr auto X = TILE_SIZE[0], Y = TILE_SIZE[1], Z = TILE_SIZE[2]; + constexpr Vector3 size{X, Y, Z}; + const auto pt = pos.to_signed(); + const Vector3 center{pt[0]*TILE_SIZE[0], pt[1]*TILE_SIZE[1], 0}; + shader.set_tint({0, 1, 0, 1}); + _wireframe_box.draw(shader, {center, size, LINE_WIDTH}); +} + +void app::draw_cursor_tile() +{ + if (cursor.tile && !cursor.in_imgui) + draw_wireframe_quad(*cursor.tile); +} + +void app::draw_msaa() +{ + draw_cursor_tile(); +} + +void app::draw() +{ + render_menu(); +} + +} // namespace floormat diff --git a/editor/events.cpp b/editor/events.cpp index 7bffda19..67a3c63c 100644 --- a/editor/events.cpp +++ b/editor/events.cpp @@ -8,10 +8,14 @@ namespace floormat { +void app::on_focus_in() noexcept {} +void app::on_mouse_enter() noexcept {} +void app::on_any_event(const floormat::any_event& event) noexcept {} + #define accessor(type, name) \ type m_##name = {}; auto name() const noexcept { return m_##name; } -bool app::on_mouse_move(const mouse_move_event& event) noexcept +void app::on_mouse_move(const mouse_move_event& event) noexcept { struct { accessor(Vector2i, position) @@ -27,11 +31,9 @@ bool app::on_mouse_move(const mouse_move_event& event) noexcept if (cursor.tile) _editor.on_mouse_move(M->world(), *cursor.tile); - - return true; } -bool app::on_mouse_up_down(const mouse_button_event& event, bool is_down) noexcept +void app::on_mouse_up_down(const mouse_button_event& event, bool is_down) noexcept { enum class Button : std::underlying_type_t<mouse_button> { Left = mouse_button_left, @@ -58,21 +60,18 @@ bool app::on_mouse_up_down(const mouse_button_event& event, bool is_down) noexce _editor.on_release(); } } - - return true; } -bool app::on_mouse_scroll(const mouse_scroll_event& event) noexcept +void app::on_mouse_scroll(const mouse_scroll_event& event) noexcept { struct { accessor(Vector2, offset) accessor(Vector2i, position) } e = {event.offset, event.position}; _imgui.handleMouseScrollEvent(e); - return true; } -bool app::on_key_up_down(const floormat::key_event& event, bool is_down) noexcept +void app::on_key_up_down(const floormat::key_event& event, bool is_down) noexcept { using KeyEvent = Platform::Sdl2Application::KeyEvent; struct Ev final { @@ -82,6 +81,7 @@ bool app::on_key_up_down(const floormat::key_event& event, bool is_down) noexcep accessor(Key, key) accessor(Modifiers, modifiers) } e = {Ev::Key(event.key), Ev::Modifier(event.mods)}; + if (!(is_down ? _imgui.handleKeyPressEvent(e) : _imgui.handleKeyReleaseEvent(e))) { // todo put it into a separate function @@ -100,17 +100,35 @@ bool app::on_key_up_down(const floormat::key_event& event, bool is_down) noexcep if (x != key::COUNT) _keys[x] = is_down && !event.is_repeated; } - return true; + else + _keys = {}; } -bool app::on_text_input_event(const floormat::text_input_event& event) noexcept +void app::on_text_input_event(const floormat::text_input_event& event) noexcept { struct { accessor(Containers::StringView, text) } e = {event.text}; if (_imgui.handleTextInputEvent(e)) _keys = {}; - return true; +} + +void app::on_viewport_event(const Math::Vector2<int>& size) noexcept +{ + init_imgui(size); +} + +void app::on_focus_out() noexcept +{ + cursor.pixel = std::nullopt; + recalc_cursor_tile(); + _keys = {}; +} + +void app::on_mouse_leave() noexcept +{ + cursor.pixel = std::nullopt; + recalc_cursor_tile(); } } // namespace floormat |
