summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-31 22:43:31 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-10-31 22:43:31 +0100
commit6995e12e188f9a76b680f685a5ff4b6a4c2792e6 (patch)
tree1439adbccb2878885d9ccb9fc1c56b27e711f948
parentbfa3e9a66d28e028fdf69efb79df1b2e47d62bec (diff)
a
-rw-r--r--editor/editor.cpp11
-rw-r--r--editor/events.cpp50
2 files changed, 39 insertions, 22 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 04727679..eb0d0f86 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -245,14 +245,11 @@ const tile_editor* editor::current() const noexcept
{
switch (_mode)
{
- case editor_mode::none:
- return nullptr;
case editor_mode::floor:
return &_floor;
case editor_mode::walls:
return &_wall; // todo
default:
- fm_warn_once("invalid editor mode '%u'", (unsigned)_mode);
return nullptr;
}
}
@@ -269,10 +266,11 @@ void editor::on_release()
auto editor::get_snap_value(snap_mode snap, int mods) const -> snap_mode
{
- if (snap != snap_mode::none)
- return snap;
- else if (const auto* mode = current(); mode != nullptr)
+
+ if (const auto* mode = current(); mode != nullptr)
return mode->check_snap(mods);
+ else if (snap != snap_mode::none)
+ return snap;
else
return snap_mode::none;
}
@@ -289,7 +287,6 @@ void editor::on_mouse_move(world& world, global_coords& pos, int mods)
switch (snap)
{
default:
- case snap_mode::none:
break;
case snap_mode::horizontal:
pos.y = last_pos.coord.y;
diff --git a/editor/events.cpp b/editor/events.cpp
index f9a4dccb..96b8ba8a 100644
--- a/editor/events.cpp
+++ b/editor/events.cpp
@@ -109,21 +109,41 @@ void app::on_key_up_down(const key_event& event, bool is_down) noexcept
const auto mods = fixup_mods(event.mods);
- const key x = fm_begin(switch (auto k = event.key | mods) {
- default: return key_COUNT;
- case SDLK_w: return key_camera_up;
- case SDLK_a: return key_camera_left;
- case SDLK_s: return key_camera_down;
- case SDLK_d: return key_camera_right;
- case SDLK_HOME: return key_camera_reset;
- case SDLK_r: return key_rotate_tile;
- case SDLK_1: return key_mode_none;
- case SDLK_2: return key_mode_floor;
- case SDLK_3: return key_mode_walls;
- case SDLK_F5: return key_quicksave;
- case SDLK_F9: return key_quickload;
- case SDLK_q | CTRL: return key_quit;
- });
+ const key x = fm_begin(
+ int k = event.key | mods;
+ constexpr kmod list[] = { kmod_none, kmod_super, kmod_alt, kmod_shift, kmod_ctrl, };
+ int last = ~0;
+ for (kmod mod1 : list)
+ {
+ k &= ~mod1;
+ for (int k2 = k; kmod mod2 : list)
+ {
+ k2 &= ~mod2;
+ if (k2 == last)
+ continue;
+ last = k2;
+ switch (k2)
+ {
+ case SDLK_w: return key_camera_up;
+ case SDLK_a: return key_camera_left;
+ case SDLK_s: return key_camera_down;
+ case SDLK_d: return key_camera_right;
+ case SDLK_HOME: return key_camera_reset;
+ case SDLK_r: return key_rotate_tile;
+ case SDLK_1: return key_mode_none;
+ case SDLK_2: return key_mode_floor;
+ case SDLK_3: return key_mode_walls;
+ case SDLK_F5: return key_quicksave;
+ case SDLK_F9: return key_quickload;
+ case SDLK_q | CTRL: return key_quit;
+ default: break;
+ }
+ }
+ }
+
+
+ return key_COUNT;
+ );
if (x == key_COUNT)
void();