Skip to content

Commit 4177405

Browse files
committed
Add button to switch between tile and object mode
1 parent 36d126b commit 4177405

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/editor/button_widget.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,17 @@ ButtonWidget::on_mouse_motion(const SDL_MouseMotionEvent& motion)
121121
}
122122
}
123123

124+
void
125+
ButtonWidget::set_sprite(SpritePtr sprite)
126+
{
127+
m_sprite = std::move(sprite);
128+
m_rect.set_size(sprite->get_width() * 1.0f, sprite->get_height() * 1.0f);
129+
}
130+
131+
void
132+
ButtonWidget::set_sprite(const std::string& path)
133+
{
134+
set_sprite(SpriteManager::current()->create(path));
135+
}
136+
124137
/* EOF */

src/editor/button_widget.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class ButtonWidget : public Widget
4545
virtual bool on_mouse_button_down(const SDL_MouseButtonEvent& button) override;
4646
virtual bool on_mouse_motion(const SDL_MouseMotionEvent& motion) override;
4747

48+
void set_sprite(const std::string& path);
49+
void set_sprite(SpritePtr sprite);
50+
4851
private:
4952
SpritePtr m_sprite;
5053
Rectf m_rect;

src/editor/editor.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ static const float CAMERA_ZOOM_FOCUS_PROGRESSION = 8.f;
8282

8383
bool Editor::s_resaving_in_progress = false;
8484

85+
using InputType = EditorTilebox::InputType;
86+
8587
bool
8688
Editor::is_active()
8789
{
@@ -178,6 +180,18 @@ Editor::Editor() :
178180
m_save_widget = save_button.get();
179181

180182
m_widgets.insert(m_widgets.begin() + 4, std::move(save_button));
183+
184+
auto mode_button = std::make_unique<ButtonWidget>("images/engine/editor/tilemap.png",
185+
Vector(160, 0), [this] {
186+
auto& tilebox = m_toolbox_widget->get_tilebox();
187+
const auto& input_type = tilebox.get_input_type();
188+
if (input_type == InputType::OBJECT)
189+
select_tilegroup(0);
190+
else
191+
select_objectgroup(0);
192+
});
193+
194+
m_widgets.insert(m_widgets.begin() + 5, std::move(mode_button));
181195
}
182196

183197
Editor::~Editor()

0 commit comments

Comments
 (0)