diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-13 05:20:17 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-13 05:20:17 +0100 |
commit | 728d34aaaa4c993d4b1f2c0f508f3a33aa069cb0 (patch) | |
tree | 6a2cde51ddce3ba2d7a563c06b10b83f2361708e /editor | |
parent | ff1c79d87ba99a2cd3fe97f7047b892445d69191 (diff) |
dw
Diffstat (limited to 'editor')
-rw-r--r-- | editor/app.cpp | 9 | ||||
-rw-r--r-- | editor/app.hpp | 16 | ||||
-rw-r--r-- | editor/camera.cpp | 1 | ||||
-rw-r--r-- | editor/editor-enums.hpp | 2 | ||||
-rw-r--r-- | editor/editor.cpp | 1 | ||||
-rw-r--r-- | editor/editor.hpp | 59 |
6 files changed, 49 insertions, 39 deletions
diff --git a/editor/app.cpp b/editor/app.cpp index c6c298b3..7cb0075a 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -8,6 +8,8 @@ #include "floormat/settings.hpp" #include "loader/loader.hpp" #include "draw/wireframe-meshes.hpp" +#include "editor.hpp" + #include <cstdlib> #include <cstring> #include <algorithm> @@ -32,7 +34,8 @@ const cursor_state& app::cursor_state() { return cursor; } app::app(fm_settings&& opts) : M{floormat_main::create(*this, Utility::move(opts))}, _wireframe{InPlaceInit}, - _tests{tests_data_::make()} + _tests{tests_data_::make()}, + _editor{InPlaceInit, this} { reset_world(); auto& w = M->world(); @@ -99,8 +102,8 @@ void app::reset_world(struct world&& w_) if (!M) return; - _editor.on_release(); - _editor.clear_selection(); + _editor->on_release(); + _editor->clear_selection(); kill_popups(true); tested_light_chunk = {}; tests_reset_mode(); diff --git a/editor/app.hpp b/editor/app.hpp index 9eb61d86..8e76a9dd 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -1,15 +1,18 @@ #pragma once #include "compat/defs.hpp" #include "compat/enum-bitset.hpp" -#include "editor.hpp" #include "floormat/app.hpp" #include "keys.hpp" +#include "src/global-coords.hpp" #include "src/object-id.hpp" +#include "editor-enums.hpp" #include "tests.hpp" #include <memory> #include <array> +#include <vector> // todo try removing? #include <Corrade/Containers/Pointer.h> #include <Corrade/Containers/Optional.h> +#include <Magnum/Math/Vector2.h> namespace Magnum::GL { template<UnsignedInt dimensions> class Texture; @@ -25,15 +28,18 @@ struct meshes; namespace floormat { -struct chunk; +struct fm_settings; struct floormat_main; +struct world; +struct chunk; class ground_atlas; -struct fm_settings; class anim_atlas; struct critter; struct point; +class editor; -struct cursor_state final { +struct cursor_state final +{ Optional<Vector2i> pixel; Optional<global_coords> tile; Optional<Vector2b> subpixel; @@ -169,8 +175,8 @@ private: Pointer<ImGuiIntegration::Context> _imgui; Pointer<floormat::wireframe::meshes> _wireframe; Pointer<tests_data_> _tests; + Pointer<editor> _editor; - editor _editor{this}; key_set keys; std::array<int, key_set::COUNT> key_modifiers = {}; std::vector<popup_target> inspectors; diff --git a/editor/camera.cpp b/editor/camera.cpp index 674c5e23..b74b048a 100644 --- a/editor/camera.cpp +++ b/editor/camera.cpp @@ -3,6 +3,7 @@ #include "shaders/shader.hpp" #include "floormat/main.hpp" #include "src/RTree-search.hpp" +#include "src/object.hpp" #include "src/world.hpp" #include "src/camera-offset.hpp" #include <algorithm> diff --git a/editor/editor-enums.hpp b/editor/editor-enums.hpp index a1b13487..980d2595 100644 --- a/editor/editor-enums.hpp +++ b/editor/editor-enums.hpp @@ -12,4 +12,6 @@ enum class editor_snap_mode : unsigned char { vertical = 1 << 1, }; +enum class editor_button : unsigned char { none, place, remove, }; + } // namespace floormat diff --git a/editor/editor.cpp b/editor/editor.cpp index 86a180b5..53776ebe 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -27,7 +27,6 @@ void editor::clear_selection() auto editor::get_snap_value(snap_mode snap, int mods) const -> snap_mode { - if (const auto* mode = current_ground_editor()) return mode->check_snap(mods); else if (const auto* mode = current_wall_editor()) diff --git a/editor/editor.hpp b/editor/editor.hpp index fae85c2f..07f5e332 100644 --- a/editor/editor.hpp +++ b/editor/editor.hpp @@ -19,8 +19,33 @@ class anim_atlas; class ground_atlas; struct app; -struct editor final +class editor final { + editor_snap_mode get_snap_value(editor_snap_mode snap, int mods) const; + static global_coords apply_snap(global_coords pos, global_coords last, editor_snap_mode snap) noexcept; + + app* _app; + + ground_editor _floor; + wall_editor _wall; + scenery_editor _scenery; + vobj_editor _vobj; + + struct drag_pos final { + global_coords coord, draw_coord; + editor_snap_mode snap = editor_snap_mode::none; + editor_button btn; + }; + Optional<drag_pos> _last_pos; + editor_mode _mode = editor_mode::none; + bool _dirty = false; + +public: + fm_DECLARE_DELETED_COPY_ASSIGNMENT(editor); + editor(app* a); + editor(editor&&) noexcept = default; + editor& operator=(editor&&) noexcept = default; + [[nodiscard]] bool dirty() const noexcept { return _dirty; } void set_dirty(bool value) noexcept { _dirty = value; } [[nodiscard]] editor_mode mode() const noexcept { return _mode; } @@ -35,41 +60,15 @@ struct editor final vobj_editor* current_vobj_editor() noexcept; const vobj_editor* current_vobj_editor() const noexcept; - enum class button : unsigned char { none, place, remove, }; - - void on_click(world& world, global_coords pos, int mods, button b); - void on_click_(world& world, global_coords pos, button b); + void on_click(world& world, global_coords pos, int mods, editor_button b); + void on_click_(world& world, global_coords pos, editor_button b); void on_mouse_move(world& world, global_coords& pos, int modifiers); void on_release(); void clear_selection(); Optional<global_coords> mouse_drag_pos(); - editor(app* a); - editor(editor&&) noexcept = default; - editor& operator=(editor&&) noexcept = default; - fm_DECLARE_DELETED_COPY_ASSIGNMENT(editor); - using snap_mode = editor_snap_mode; - -private: - snap_mode get_snap_value(snap_mode snap, int mods) const; - static global_coords apply_snap(global_coords pos, global_coords last, snap_mode snap) noexcept; - - app* _app; - - ground_editor _floor; - wall_editor _wall; - scenery_editor _scenery; - vobj_editor _vobj; - - struct drag_pos final { - global_coords coord, draw_coord; - snap_mode snap = snap_mode::none; - button btn; - }; - Optional<drag_pos> _last_pos; - editor_mode _mode = editor_mode::none; - bool _dirty = false; + using button = enum editor_button; }; } // namespace floormat |