summaryrefslogtreecommitdiffhomepage
path: root/editor/editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor.cpp')
-rw-r--r--editor/editor.cpp70
1 files changed, 43 insertions, 27 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 1ac4a887..3400f5af 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -11,11 +11,6 @@
namespace floormat {
-tile_editor* editor::current_tile_editor() noexcept
-{
- return const_cast<tile_editor*>(static_cast<const editor&>(*this).current_tile_editor());
-}
-
void editor::on_release()
{
_last_pos = NullOpt;
@@ -50,32 +45,37 @@ global_coords editor::apply_snap(global_coords pos, global_coords last, snap_mod
void editor::on_mouse_move(world& world, global_coords& pos, int mods)
{
- if (auto* mode = current_tile_editor(); mode && _last_pos && _last_pos->btn != button::none)
+ if (auto* mode = current_tile_editor())
{
- auto& last = *_last_pos;
- const Vector2i offset = pos - last.coord;
- const snap_mode snap = get_snap_value(last.snap, mods);
- const global_coords draw_coord = apply_snap(last.draw_coord + offset, last.draw_coord, snap);
- if (draw_coord != last.draw_coord)
+ if (_last_pos && _last_pos->btn != button::none)
{
- const auto draw_offset = draw_coord - last.draw_coord;
- if (!!draw_offset[0] ^ !!draw_offset[1] && std::abs(draw_offset.sum()) > 1)
+ auto& last = *_last_pos;
+ const Vector2i offset = pos - last.coord;
+ const snap_mode snap = get_snap_value(last.snap, mods);
+ const global_coords draw_coord = apply_snap(last.draw_coord + offset, last.draw_coord, snap);
+ if (draw_coord != last.draw_coord)
{
- const auto [minx, maxx] = std::minmax(draw_coord.x, last.draw_coord.x);
- const auto [miny, maxy] = std::minmax(draw_coord.y, last.draw_coord.y);
- if (draw_offset[0])
- for (std::uint32_t i = minx; i <= maxx; i++)
- on_click_(world, { i, draw_coord.y }, last.btn);
+ const auto draw_offset = draw_coord - last.draw_coord;
+ if (!!draw_offset[0] ^ !!draw_offset[1] && std::abs(draw_offset.sum()) > 1)
+ {
+ const auto [minx, maxx] = std::minmax(draw_coord.x, last.draw_coord.x);
+ const auto [miny, maxy] = std::minmax(draw_coord.y, last.draw_coord.y);
+ if (draw_offset[0])
+ for (std::uint32_t i = minx; i <= maxx; i++)
+ on_click_(world, { i, draw_coord.y }, last.btn);
+ else
+ for (std::uint32_t j = miny; j <= maxy; j++)
+ on_click_(world, { draw_coord.x, j }, last.btn);
+ }
else
- for (std::uint32_t j = miny; j <= maxy; j++)
- on_click_(world, { draw_coord.x, j }, last.btn);
+ on_click_(world, draw_coord, last.btn);
+ _last_pos = { InPlaceInit, pos, draw_coord, snap, last.btn };
}
- else
- on_click_(world, draw_coord, last.btn);
- _last_pos = { InPlaceInit, pos, draw_coord, snap, last.btn };
+ pos = draw_coord;
}
- pos = draw_coord;
}
+ else
+ on_release();
}
void editor::on_click_(world& world, global_coords pos, button b)
@@ -102,9 +102,7 @@ void editor::on_click(world& world, global_coords pos, int mods, button b)
}
}
-editor::editor()
-{
-}
+editor::editor() = default;
void editor::set_mode(editor_mode mode)
{
@@ -125,4 +123,22 @@ const tile_editor* editor::current_tile_editor() const noexcept
}
}
+const scenery_editor* editor::current_scenery_editor() const noexcept
+{
+ if (_mode == editor_mode::scenery)
+ return &_scenery;
+ else
+ return nullptr;
+}
+
+tile_editor* editor::current_tile_editor() noexcept
+{
+ return const_cast<tile_editor*>(static_cast<const editor&>(*this).current_tile_editor());
+}
+
+scenery_editor* editor::current_scenery_editor() noexcept
+{
+ return const_cast<scenery_editor*>(static_cast<const editor&>(*this).current_scenery_editor());
+}
+
} // namespace floormat