Return mouse_action by reference instead of a not-null pointer
Plus the implementation of a previously-declared wrapper function to get said mouse_action.
This commit is contained in:
parent
a422e657a4
commit
a6d23581e1
5 changed files with 25 additions and 24 deletions
|
@ -347,7 +347,7 @@ bool editor_controller::can_execute_command(const hotkey::hotkey_command& cmd, i
|
|||
case HOTKEY_EDITOR_BRUSH_3:
|
||||
case HOTKEY_EDITOR_BRUSH_NW_SE:
|
||||
case HOTKEY_EDITOR_BRUSH_SW_NE:
|
||||
return toolkit_->get_mouse_action()->supports_brushes();
|
||||
return get_mouse_action().supports_brushes();
|
||||
|
||||
case HOTKEY_EDITOR_TOOL_NEXT:
|
||||
return true;
|
||||
|
@ -693,17 +693,17 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i
|
|||
case HOTKEY_ZOOM_IN:
|
||||
gui_->set_zoom(zoom_amount);
|
||||
context_manager_->get_map_context().get_labels().recalculate_labels();
|
||||
toolkit_->get_mouse_action()->set_mouse_overlay(*gui_);
|
||||
toolkit_->set_mouseover_overlay(*gui_);
|
||||
return true;
|
||||
case HOTKEY_ZOOM_OUT:
|
||||
gui_->set_zoom(-zoom_amount);
|
||||
context_manager_->get_map_context().get_labels().recalculate_labels();
|
||||
toolkit_->get_mouse_action()->set_mouse_overlay(*gui_);
|
||||
toolkit_->set_mouseover_overlay(*gui_);
|
||||
return true;
|
||||
case HOTKEY_ZOOM_DEFAULT:
|
||||
gui_->set_default_zoom();
|
||||
context_manager_->get_map_context().get_labels().recalculate_labels();
|
||||
toolkit_->get_mouse_action()->set_mouse_overlay(*gui_);
|
||||
toolkit_->set_mouseover_overlay(*gui_);
|
||||
return true;
|
||||
|
||||
//Palette
|
||||
|
@ -1248,10 +1248,10 @@ void editor_controller::mouse_motion(int x, int y, const bool /*browse*/,
|
|||
editor_action* last_undo = context_manager_->get_map_context().last_undo_action();
|
||||
if (dragging_left_ && (SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(1)) != 0) {
|
||||
if (!context_manager_->get_map().on_board_with_border(hex_clicked)) return;
|
||||
a = toolkit_->get_mouse_action()->drag_left(*gui_, x, y, partial, last_undo);
|
||||
a = get_mouse_action().drag_left(*gui_, x, y, partial, last_undo);
|
||||
} else if (dragging_right_ && (SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(3)) != 0) {
|
||||
if (!context_manager_->get_map().on_board_with_border(hex_clicked)) return;
|
||||
a = toolkit_->get_mouse_action()->drag_right(*gui_, x, y, partial, last_undo);
|
||||
a = get_mouse_action().drag_right(*gui_, x, y, partial, last_undo);
|
||||
}
|
||||
//Partial means that the mouse action has modified the
|
||||
//last undo action and the controller shouldn't add
|
||||
|
@ -1266,7 +1266,7 @@ void editor_controller::mouse_motion(int x, int y, const bool /*browse*/,
|
|||
context_manager_->refresh_after_action(true);
|
||||
}
|
||||
} else {
|
||||
toolkit_->get_mouse_action()->move(*gui_, hex_clicked);
|
||||
get_mouse_action().move(*gui_, hex_clicked);
|
||||
}
|
||||
gui().highlight_hex(hex_clicked);
|
||||
}
|
||||
|
@ -1278,7 +1278,7 @@ bool editor_controller::allow_mouse_wheel_scroll(int x, int y)
|
|||
|
||||
bool editor_controller::right_click_show_menu(int /*x*/, int /*y*/, const bool /*browse*/)
|
||||
{
|
||||
return toolkit_->get_mouse_action()->has_context_menu();
|
||||
return get_mouse_action().has_context_menu();
|
||||
}
|
||||
|
||||
bool editor_controller::left_click(int x, int y, const bool browse)
|
||||
|
@ -1293,7 +1293,7 @@ bool editor_controller::left_click(int x, int y, const bool browse)
|
|||
return true;
|
||||
|
||||
LOG_ED << "Left click action " << hex_clicked.x << " " << hex_clicked.y << "\n";
|
||||
editor_action* a = toolkit_->get_mouse_action()->click_left(*gui_, x, y);
|
||||
editor_action* a = get_mouse_action().click_left(*gui_, x, y);
|
||||
perform_refresh_delete(a, true);
|
||||
if (a) set_button_state();
|
||||
|
||||
|
@ -1302,13 +1302,13 @@ bool editor_controller::left_click(int x, int y, const bool browse)
|
|||
|
||||
void editor_controller::left_drag_end(int x, int y, const bool /*browse*/)
|
||||
{
|
||||
editor_action* a = toolkit_->get_mouse_action()->drag_end_left(*gui_, x, y);
|
||||
editor_action* a = get_mouse_action().drag_end_left(*gui_, x, y);
|
||||
perform_delete(a);
|
||||
}
|
||||
|
||||
void editor_controller::left_mouse_up(int x, int y, const bool /*browse*/)
|
||||
{
|
||||
editor_action* a = toolkit_->get_mouse_action()->up_left(*gui_, x, y);
|
||||
editor_action* a = get_mouse_action().up_left(*gui_, x, y);
|
||||
perform_delete(a);
|
||||
if (a) set_button_state();
|
||||
toolkit_->set_mouseover_overlay();
|
||||
|
@ -1316,7 +1316,7 @@ void editor_controller::left_mouse_up(int x, int y, const bool /*browse*/)
|
|||
if (s && s->value_change()) {
|
||||
if (gui_->set_zoom(s->value(), true)) {
|
||||
context_manager_->get_map_context().get_labels().recalculate_labels();
|
||||
toolkit_->get_mouse_action()->set_mouse_overlay(*gui_);
|
||||
toolkit_->set_mouseover_overlay(*gui_);
|
||||
set_button_state();
|
||||
}
|
||||
}
|
||||
|
@ -1331,7 +1331,7 @@ bool editor_controller::right_click(int x, int y, const bool browse)
|
|||
map_location hex_clicked = gui().hex_clicked_on(x, y);
|
||||
if (!context_manager_->get_map().on_board_with_border(hex_clicked)) return true;
|
||||
LOG_ED << "Right click action " << hex_clicked.x << " " << hex_clicked.y << "\n";
|
||||
editor_action* a = toolkit_->get_mouse_action()->click_right(*gui_, x, y);
|
||||
editor_action* a = get_mouse_action().click_right(*gui_, x, y);
|
||||
perform_refresh_delete(a, true);
|
||||
if (a) set_button_state();
|
||||
return false;
|
||||
|
@ -1339,13 +1339,13 @@ bool editor_controller::right_click(int x, int y, const bool browse)
|
|||
|
||||
void editor_controller::right_drag_end(int x, int y, const bool /*browse*/)
|
||||
{
|
||||
editor_action* a = toolkit_->get_mouse_action()->drag_end_right(*gui_, x, y);
|
||||
editor_action* a = get_mouse_action().drag_end_right(*gui_, x, y);
|
||||
perform_delete(a);
|
||||
}
|
||||
|
||||
void editor_controller::right_mouse_up(int x, int y, const bool /*browse*/)
|
||||
{
|
||||
editor_action* a = toolkit_->get_mouse_action()->up_right(*gui_, x, y);
|
||||
editor_action* a = get_mouse_action().up_right(*gui_, x, y);
|
||||
perform_delete(a);
|
||||
if (a) set_button_state();
|
||||
toolkit_->set_mouseover_overlay();
|
||||
|
@ -1364,7 +1364,7 @@ void editor_controller::terrain_description()
|
|||
|
||||
void editor_controller::process_keyup_event(const SDL_Event& event)
|
||||
{
|
||||
editor_action* a = toolkit_->get_mouse_action()->key_event(gui(), event);
|
||||
editor_action* a = get_mouse_action().key_event(gui(), event);
|
||||
perform_refresh_delete(a);
|
||||
toolkit_->set_mouseover_overlay();
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ class editor_controller : public controller_base,
|
|||
editor_display& get_display() override { return *gui_; }
|
||||
|
||||
/** Get the current mouse action */
|
||||
mouse_action* get_mouse_action();
|
||||
mouse_action& get_mouse_action() const { return toolkit_->get_mouse_action(); }
|
||||
|
||||
/**
|
||||
* Perform an action, then delete the action object.
|
||||
|
|
|
@ -249,7 +249,7 @@ void location_palette::adjust_size(const SDL_Rect& target)
|
|||
button_goto_.reset();
|
||||
|
||||
button_goto_.reset(new location_palette_button(video(), SDL_Rect{ target.x , bottom -= button_height, target.w - 10, button_height }, _("Go To"), [this]() {
|
||||
//static_cast<mouse_action_starting_position*>(toolkit_.get_mouse_action())-> ??
|
||||
//static_cast<mouse_action_starting_position&>(toolkit_.get_mouse_action()). ??
|
||||
map_location pos = disp_.get_map().special_location(selected_item_);
|
||||
if (pos.valid()) {
|
||||
disp_.scroll_to_tile(pos, display::WARP);
|
||||
|
|
|
@ -29,7 +29,7 @@ editor_toolkit::editor_toolkit(editor_display& gui, const CKey& key,
|
|||
: gui_(gui)
|
||||
, key_(key)
|
||||
, palette_manager_()
|
||||
, mouse_action_(nullptr)
|
||||
, mouse_action_(nullptr) // Will be set before this constructor ends.
|
||||
, mouse_actions_()
|
||||
, brush_(nullptr)
|
||||
, brushes_()
|
||||
|
@ -125,7 +125,7 @@ bool editor_toolkit::is_mouse_action_set(hotkey::HOTKEY_COMMAND command) const
|
|||
|
||||
common_palette& editor_toolkit::get_palette()
|
||||
{
|
||||
return get_mouse_action()->get_palette();
|
||||
return get_mouse_action().get_palette();
|
||||
}
|
||||
|
||||
void editor_toolkit::update_mouse_action_highlights()
|
||||
|
@ -134,12 +134,12 @@ void editor_toolkit::update_mouse_action_highlights()
|
|||
int x, y;
|
||||
SDL_GetMouseState(&x, &y);
|
||||
map_location hex_clicked = gui_.hex_clicked_on(x,y);
|
||||
get_mouse_action()->update_brush_highlights(gui_, hex_clicked);
|
||||
get_mouse_action().update_brush_highlights(gui_, hex_clicked);
|
||||
}
|
||||
|
||||
void editor_toolkit::set_mouseover_overlay(editor_display& gui)
|
||||
{
|
||||
mouse_action_->set_mouse_overlay(gui);
|
||||
get_mouse_action().set_mouse_overlay(gui);
|
||||
}
|
||||
|
||||
void editor_toolkit::clear_mouseover_overlay()
|
||||
|
|
|
@ -65,7 +65,8 @@ public:
|
|||
|
||||
|
||||
/** Get the current mouse action */
|
||||
mouse_action* get_mouse_action() { return mouse_action_; }
|
||||
mouse_action& get_mouse_action() { return *mouse_action_; }
|
||||
const mouse_action& get_mouse_action() const { return *mouse_action_; }
|
||||
/** Get the current palette */
|
||||
common_palette& get_palette();
|
||||
|
||||
|
@ -93,7 +94,7 @@ private:
|
|||
//Tools
|
||||
|
||||
/** The current mouse action */
|
||||
mouse_action* mouse_action_;
|
||||
mouse_action* mouse_action_; // Never null (outside the constructor).
|
||||
|
||||
/** The mouse actions */
|
||||
typedef std::map<hotkey::HOTKEY_COMMAND, std::shared_ptr<mouse_action> > mouse_action_map;
|
||||
|
|
Loading…
Add table
Reference in a new issue