Use editor_toolkit& instead of mouse_action** in palettes

This goes along with the principle of using references when a pointer
cannot be null. It's also better for data encapsulation to not give
someone the address of one of your private data members.
This commit is contained in:
JaMiT 2016-09-04 22:19:57 -05:00
parent ee03df92ab
commit a422e657a4
14 changed files with 61 additions and 40 deletions

View file

@ -23,7 +23,7 @@
#include "filesystem.hpp"
#include "units/types.hpp"
#include "editor/action/mouse/mouse_action.hpp"
#include "editor/toolkit/editor_toolkit.hpp"
#include "wml_separators.hpp"
@ -306,8 +306,7 @@ template bool editor_palette<overlay>::is_selected_bg_item(const std::string& id
template<class Item>
void editor_palette<Item>::draw_contents()
{
if (*active_mouse_action_)
(*active_mouse_action_)->set_mouse_overlay(gui_);
toolkit_.set_mouseover_overlay(gui_);
std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button("menu-editor-terrain");
if (palette_menu_button) {

View file

@ -20,13 +20,16 @@
#include "tristate_button.hpp"
namespace editor {
class editor_toolkit;
template<class Item>
class editor_palette : public tristate_palette {
public:
editor_palette(editor_display &gui, const config& /*cfg*/
, size_t item_size, size_t item_width, mouse_action** active_mouse_action)
, size_t item_size, size_t item_width, editor_toolkit &toolkit)
: tristate_palette(gui)
, groups_()
, gui_(gui)
@ -45,7 +48,7 @@ public:
, active_group_()
, selected_fg_item_()
, selected_bg_item_()
, active_mouse_action_(active_mouse_action)
, toolkit_(toolkit)
, buttons_()
, help_handle_(-1)
{
@ -183,7 +186,7 @@ private:
std::string selected_fg_item_;
std::string selected_bg_item_;
mouse_action** active_mouse_action_;
editor_toolkit& toolkit_;
std::vector<gui::tristate_button> buttons_;
int help_handle_;

View file

@ -86,9 +86,9 @@ void item_palette::draw_item(const overlay& item, surface& image, std::stringstr
}
item_palette::item_palette(editor_display &gui, const config& cfg,
mouse_action** active_mouse_action)
editor_toolkit &toolkit)
//TODO avoid magic numbers
: editor_palette<overlay>(gui, cfg, 36, 4, active_mouse_action)
: editor_palette<overlay>(gui, cfg, 36, 4, toolkit)
{
}

View file

@ -24,6 +24,8 @@
namespace editor {
class editor_toolkit;
//std::string get_selected_terrain();
/** Palette where the terrain to be drawn can be selected. */
@ -31,8 +33,8 @@ class item_palette : public editor_palette<overlay> {
public:
item_palette(editor_display &gui,
const config& cfg,
mouse_action** active_mouse_action);
const config& cfg,
editor_toolkit &toolkit);
virtual void setup(const config& cfg);

View file

@ -20,7 +20,7 @@
#include "marked-up_text.hpp"
#include "tooltips.hpp"
#include "editor/action/mouse/mouse_action.hpp"
#include "editor/toolkit/editor_toolkit.hpp"
#include "gui/dialogs/edit_text.hpp"
#include "wml_separators.hpp"
@ -150,7 +150,8 @@ protected:
};
namespace editor {
location_palette::location_palette(editor_display &gui, const config& /*cfg*/, mouse_action** active_mouse_action)
location_palette::location_palette(editor_display &gui, const config& /*cfg*/,
editor_toolkit &toolkit)
: common_palette(gui)
, gui_(gui)
, item_size_(20)
@ -161,7 +162,7 @@ location_palette::location_palette(editor_display &gui, const config& /*cfg*/, m
, items_start_(0)
, selected_item_()
, items_()
, active_mouse_action_(active_mouse_action)
, toolkit_(toolkit)
, buttons_()
, button_add_()
, button_delete_()
@ -248,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&>(**active_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);
@ -302,8 +303,7 @@ bool location_palette::is_selected_item(const std::string& id)
void location_palette::draw_contents()
{
if (*active_mouse_action_)
(*active_mouse_action_)->set_mouse_overlay(gui_);
toolkit_.set_mouseover_overlay(gui_);
int y = palette_y_;
const int x = palette_x_;
const int starting = items_start_;
@ -331,7 +331,7 @@ void location_palette::draw_contents()
tile.hide(true);
if (i >= ending) {
//We want to hide all follwing buttons to we cannot use break here.
//We want to hide all following buttons so we cannot use break here.
continue;
}

View file

@ -23,11 +23,14 @@ class location_palette_button;
namespace editor {
class editor_toolkit;
class location_palette : public common_palette {
public:
location_palette(editor_display &gui, const config& /*cfg*/, mouse_action** active_mouse_action);
location_palette(editor_display &gui, const config& /*cfg*/,
editor_toolkit &toolkit);
virtual sdl_handler_vector handler_members() override;
@ -109,7 +112,7 @@ protected:
private:
std::string selected_item_;
std::vector<std::string> items_;
mouse_action** active_mouse_action_;
editor_toolkit& toolkit_;
boost::ptr_vector<location_palette_item> buttons_;
std::unique_ptr<location_palette_button> button_add_;
std::unique_ptr<location_palette_button> button_delete_;

View file

@ -18,21 +18,21 @@
#include "widgets/widget.hpp"
#include "tooltips.hpp"
#include "editor/action/mouse/mouse_action.hpp"
#include "editor/toolkit/editor_toolkit.hpp"
namespace editor {
palette_manager::palette_manager(editor_display& gui, const config& cfg
, mouse_action** active_mouse_action)
, editor_toolkit& toolkit)
: gui::widget(gui.video()),
gui_(gui),
palette_start_(0),
mouse_action_(active_mouse_action),
terrain_palette_(new terrain_palette(gui, cfg, active_mouse_action)),
unit_palette_(new unit_palette(gui, cfg, active_mouse_action)),
toolkit_(toolkit),
terrain_palette_(new terrain_palette(gui, cfg, toolkit)),
unit_palette_(new unit_palette(gui, cfg, toolkit)),
empty_palette_(new empty_palette(gui)),
item_palette_(new item_palette(gui, cfg, active_mouse_action))
, location_palette_(new location_palette(gui, cfg, active_mouse_action))
item_palette_(new item_palette(gui, cfg, toolkit))
, location_palette_(new location_palette(gui, cfg, toolkit))
{
unit_palette_->setup(cfg);
terrain_palette_->setup(cfg);
@ -107,7 +107,7 @@ void palette_manager::resrote_palete_bg(bool scroll_top)
common_palette& palette_manager::active_palette()
{
return (*mouse_action_)->get_palette();
return toolkit_.get_palette();
}
void palette_manager::scroll_bottom()

View file

@ -29,13 +29,15 @@
namespace editor {
class editor_toolkit;
/** Empty palette */
class palette_manager : public gui::widget {
public:
palette_manager(editor_display &gui, const config& cfg
, mouse_action** active_mouse_action);
, editor_toolkit &toolkit);
void set_group(size_t index);
@ -76,7 +78,7 @@ private:
editor_display& gui_;
int palette_start_;
mouse_action** mouse_action_;
editor_toolkit& toolkit_;
public:

View file

@ -204,9 +204,9 @@ void terrain_palette::draw_item(const t_translation::t_terrain& terrain,
}
terrain_palette::terrain_palette(editor_display &gui, const config& cfg,
mouse_action** active_mouse_action)
editor_toolkit &toolkit)
//TODO avoid magic numbers
: editor_palette<t_translation::t_terrain>(gui, cfg, 36, 4, active_mouse_action)
: editor_palette<t_translation::t_terrain>(gui, cfg, 36, 4, toolkit)
{
}

View file

@ -24,6 +24,8 @@
namespace editor {
class editor_toolkit;
const t_translation::t_terrain& get_selected_fg_terrain();
const t_translation::t_terrain& get_selected_bg_terrain();
@ -33,7 +35,7 @@ class terrain_palette : public editor_palette<t_translation::t_terrain> {
public:
terrain_palette(editor_display &gui, const config& cfg,
mouse_action** active_mouse_action);
editor_toolkit &toolkit);
const gamemap& map() const { return gui_.get_map(); }

View file

@ -103,9 +103,9 @@ void unit_palette::draw_item(const unit_type& u, surface& image, std::stringstre
}
unit_palette::unit_palette(editor_display &gui, const config& cfg,
mouse_action** active_mouse_action)
editor_toolkit &toolkit)
//TODO avoid magic numbers
: editor_palette<unit_type>(gui, cfg, 36, 4, active_mouse_action),
: editor_palette<unit_type>(gui, cfg, 36, 4, toolkit),
selected_bg_items_()
{
}

View file

@ -25,6 +25,8 @@
namespace editor {
class editor_toolkit;
//std::string get_selected_terrain();
/** Palette where the terrain to be drawn can be selected. */
@ -32,8 +34,8 @@ class unit_palette : public editor_palette<unit_type> {
public:
unit_palette(editor_display &gui,
const config& cfg,
mouse_action** active_mouse_action);
const config& cfg,
editor_toolkit &toolkit);
virtual void setup(const config& cfg);

View file

@ -60,7 +60,7 @@ void editor_toolkit::init_brushes(const config& game_config)
void editor_toolkit::init_sidebar(const config& game_config)
{
palette_manager_.reset(new palette_manager(gui_, game_config, &mouse_action_));
palette_manager_.reset(new palette_manager(gui_, game_config, *this));
}
void editor_toolkit::init_mouse_actions(context_manager& cmanager)
@ -123,6 +123,11 @@ bool editor_toolkit::is_mouse_action_set(hotkey::HOTKEY_COMMAND command) const
return (i != mouse_actions_.end()) && (i->second.get() == mouse_action_);
}
common_palette& editor_toolkit::get_palette()
{
return get_mouse_action()->get_palette();
}
void editor_toolkit::update_mouse_action_highlights()
{
DBG_ED << __func__ << "\n";
@ -132,9 +137,9 @@ void editor_toolkit::update_mouse_action_highlights()
get_mouse_action()->update_brush_highlights(gui_, hex_clicked);
}
void editor_toolkit::set_mouseover_overlay()
void editor_toolkit::set_mouseover_overlay(editor_display& gui)
{
mouse_action_->set_mouse_overlay(gui_);
mouse_action_->set_mouse_overlay(gui);
}
void editor_toolkit::clear_mouseover_overlay()

View file

@ -49,7 +49,8 @@ private:
void init_mouse_actions(context_manager& c_manager);
public:
void set_mouseover_overlay();
void set_mouseover_overlay(editor_display& gui);
void set_mouseover_overlay() { set_mouseover_overlay(gui_); }
void clear_mouseover_overlay();
/**
@ -65,6 +66,8 @@ public:
/** Get the current mouse action */
mouse_action* get_mouse_action() { return mouse_action_; }
/** Get the current palette */
common_palette& get_palette();
// Brush related methods