diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-25 16:19:21 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-25 16:19:21 +0200 |
commit | a00ac8b5fed9d03cb2b3eafb4cd7d04546e341b1 (patch) | |
tree | 18bfeda1abd43a2a0b81f2ad4b909c30b9bfb419 /floormat | |
parent | 45f2533113a0dfe4cf8a7723a1c76099d0a6d091 (diff) |
move some headers around
Diffstat (limited to 'floormat')
-rw-r--r-- | floormat/app.hpp | 49 | ||||
-rw-r--r-- | floormat/events.hpp | 56 | ||||
-rw-r--r-- | floormat/main.hpp | 48 | ||||
-rw-r--r-- | floormat/settings.hpp | 35 |
4 files changed, 188 insertions, 0 deletions
diff --git a/floormat/app.hpp b/floormat/app.hpp new file mode 100644 index 00000000..60ecc52c --- /dev/null +++ b/floormat/app.hpp @@ -0,0 +1,49 @@ +#pragma once + +namespace Magnum::Math { template<typename T> class Vector2; } + +namespace floormat { + +struct mouse_move_event; +struct mouse_button_event; +struct mouse_scroll_event; +struct key_event; +struct text_input_event; +struct text_editing_event; +struct any_event; + +struct chunk_coords; +struct chunk; + +struct floormat_app +{ + explicit floormat_app() noexcept; + virtual ~floormat_app() noexcept; + + floormat_app(const floormat_app&) = delete; + floormat_app& operator=(const floormat_app&) = delete; + [[deprecated]] floormat_app(floormat_app&&) = default; + [[deprecated]] floormat_app& operator=(floormat_app&&) = default; + + virtual void update(float dt) = 0; + virtual void maybe_initialize_chunk(const chunk_coords& pos, chunk& c) = 0; + virtual void draw_msaa(); + virtual void draw() = 0; + + virtual void on_mouse_move(const mouse_move_event& event) noexcept = 0; + virtual void on_mouse_up_down(const mouse_button_event& event, bool is_down) noexcept = 0; + virtual void on_mouse_scroll(const mouse_scroll_event& event) noexcept = 0; + virtual void on_key_up_down(const key_event& event, bool is_down) noexcept = 0; + virtual void on_text_input_event(const text_input_event& event) noexcept = 0; + //virtual bool on_text_editing_event(const text_editing_event& event) noexcept = 0; + virtual void on_viewport_event(const Magnum::Math::Vector2<int>& size) noexcept = 0; + virtual void on_any_event(const any_event& event) noexcept = 0; + virtual void on_focus_in() noexcept = 0; + virtual void on_focus_out() noexcept = 0; + virtual void on_mouse_leave() noexcept = 0; + virtual void on_mouse_enter() noexcept = 0; +}; + +inline void floormat_app::draw_msaa() {} + +} // namespace floormat diff --git a/floormat/events.hpp b/floormat/events.hpp new file mode 100644 index 00000000..97c5f171 --- /dev/null +++ b/floormat/events.hpp @@ -0,0 +1,56 @@ +#pragma once +#include <Magnum/Math/Vector2.h> +#include <SDL_keycode.h> +#include <SDL_mouse.h> +#include <SDL_events.h> + +namespace floormat { + +enum mouse_button : std::uint8_t { + mouse_button_none = 0, + mouse_button_left = SDL_BUTTON_LMASK, + mouse_button_middle = SDL_BUTTON_MMASK, + mouse_button_right = SDL_BUTTON_RMASK, + mouse_button_x1 = SDL_BUTTON_X1MASK, + mouse_button_x2 = SDL_BUTTON_X2MASK, +}; + +struct mouse_button_event final { + Vector2i position; + SDL_Keymod mods = KMOD_NONE; + mouse_button button = mouse_button_none; + std::uint8_t click_count = 0; +}; + +struct mouse_move_event final { + Vector2i position, relative_position; + mouse_button buttons = mouse_button_none; + SDL_Keymod mods = KMOD_NONE; +}; + +struct mouse_scroll_event final { + Magnum::Vector2 offset; + Vector2i position; + SDL_Keymod mods = KMOD_NONE; +}; + +struct text_input_event final { + Containers::StringView text; +}; + +struct text_editing_event final { + Containers::StringView text; + std::int32_t start = 0, length = 0; +}; + +struct key_event final { + SDL_Keycode key = SDLK_UNKNOWN; + SDL_Keymod mods = KMOD_NONE; + std::uint8_t is_repeated = false; +}; + +struct any_event final { + SDL_Event event = {}; +}; + +} // namespace floormat diff --git a/floormat/main.hpp b/floormat/main.hpp new file mode 100644 index 00000000..6ba3b4c8 --- /dev/null +++ b/floormat/main.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include "src/global-coords.hpp" +#include <Magnum/Math/Vector2.h> + +struct SDL_Window; + +namespace floormat { + +struct fm_settings; +struct floormat_app; +struct tile_shader; +struct world; + +struct floormat_main +{ + floormat_main() noexcept; + virtual ~floormat_main() noexcept; + + fm_DECLARE_DELETED_COPY_ASSIGNMENT(floormat_main); + fm_DECLARE_DEPRECATED_MOVE_ASSIGNMENT(floormat_main); + + virtual int exec() = 0; + virtual void quit(int status) = 0; + + virtual Magnum::Math::Vector2<int> window_size() const noexcept = 0; + virtual tile_shader& shader() noexcept = 0; + virtual const tile_shader& shader() const noexcept = 0; + constexpr float smoothed_dt() const noexcept { return _frame_time; } + virtual fm_settings& settings() noexcept = 0; + virtual const fm_settings& settings() const noexcept = 0; + + virtual bool is_text_input_active() const noexcept = 0; + virtual void start_text_input() noexcept = 0; + virtual void stop_text_input() noexcept = 0; + + virtual global_coords pixel_to_tile(Vector2d position) const noexcept = 0; + + virtual world& world() noexcept = 0; + virtual SDL_Window* window() noexcept = 0; + + [[nodiscard]] static floormat_main* create(floormat_app& app, fm_settings&& options); + +protected: + float _frame_time = 0; +}; + +} // namespace floormat diff --git a/floormat/settings.hpp b/floormat/settings.hpp new file mode 100644 index 00000000..0a526478 --- /dev/null +++ b/floormat/settings.hpp @@ -0,0 +1,35 @@ +#pragma once +#include "compat/defs.hpp" +#include <cstdint> +#include <Corrade/Containers/String.h> +#include <Magnum/Math/Vector2.h> + +namespace floormat { + +enum class fm_gpu_debug : char { no_error = 1, off, on, robust, }; +enum class fm_tristate : char { maybe = -1, on, off }; +enum class fm_log_level : unsigned char { quiet, normal, verbose, }; + +struct fm_settings +{ + inline fm_settings() noexcept = default; + virtual ~fm_settings() noexcept; + fm_DECLARE_DEPRECATED_COPY_ASSIGNMENT(fm_settings); + fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT_(fm_settings); + + Magnum::Math::Vector2<int> resolution{1024, 768}; + Corrade::Containers::String title{"Test"}; + Corrade::Containers::String disabled_extensions; // TODO + std::uint8_t msaa_samples = 16; + fm_tristate vsync = fm_tristate::maybe; + fm_gpu_debug gpu_debug = fm_gpu_debug::on; + fm_log_level log_level = fm_log_level::normal; + std::uint8_t resizable : 1 = true, + fullscreen : 1 = false, + fullscreen_desktop : 1 = false, + borderless : 1 = false, + maximized : 1 = false, + msaa : 1 = true; +}; + +} // namespace floormat |