Skip to content

Commit

Permalink
Revert "Remove an unnecessary layer of indirection"
Browse files Browse the repository at this point in the history
This reverts commit cdec9b2. This commit broke selection of different
brushes in the Editor. Using a single pointer means changes to the brush pointer in editor_toolkit aren't
reflected in the action objects.

The double pointer isn't the cleanest code, but I'm not sure how to improve it.
  • Loading branch information
Vultraz committed Nov 12, 2017
1 parent 61c33f9 commit a2327fa
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/editor/action/mouse/mouse_action.cpp
Expand Up @@ -253,7 +253,8 @@ editor_action* brush_drag_mouse_action::drag_generic(editor_display& disp, int x
const brush& brush_drag_mouse_action::get_brush()
{
assert(brush_);
return *brush_;
assert(*brush_);
return **brush_;
}


Expand Down
8 changes: 4 additions & 4 deletions src/editor/action/mouse/mouse_action.hpp
Expand Up @@ -165,7 +165,7 @@ class mouse_action
class brush_drag_mouse_action : public mouse_action
{
public:
brush_drag_mouse_action(common_palette& palette, const brush* brush, const CKey& key)
brush_drag_mouse_action(common_palette& palette, const brush* const * const brush, const CKey& key)
: mouse_action(palette, key)
, previous_drag_hex_()
, brush_(brush)
Expand Down Expand Up @@ -235,12 +235,12 @@ class brush_drag_mouse_action : public mouse_action
editor_action* drag_generic(editor_display& disp, int x, int y, bool& partial, editor_action* last_undo);

/**
* Current brush handle. Currently pointer to brush with full constness.
* Current brush handle. Currently a pointer-to-pointer with full constness.
* The mouse action does not modify the brush, does not modify the pointer
* to the current brush, and we allow setting this pointr only once, hence
* the three "consts".
*/
const brush* const brush_;
const brush* const * const brush_;
};

/**
Expand All @@ -250,7 +250,7 @@ class mouse_action_paint : public brush_drag_mouse_action
{
public:
mouse_action_paint(
const brush* brush, const CKey& key, terrain_palette& palette)
const brush* const * const brush, const CKey& key, terrain_palette& palette)
: brush_drag_mouse_action(palette, brush, key)
, terrain_palette_(palette)
{
Expand Down
2 changes: 1 addition & 1 deletion src/editor/action/mouse/mouse_action_select.hpp
Expand Up @@ -27,7 +27,7 @@ namespace editor {
class mouse_action_select : public brush_drag_mouse_action
{
public:
mouse_action_select(const brush* brush, const CKey& key, empty_palette& palette)
mouse_action_select(const brush* const * const brush, const CKey& key, empty_palette& palette)
: brush_drag_mouse_action(palette, brush, key)
{
}
Expand Down
6 changes: 3 additions & 3 deletions src/editor/toolkit/editor_toolkit.cpp
Expand Up @@ -31,7 +31,7 @@ editor_toolkit::editor_toolkit(editor_display& gui, const CKey& key,
, palette_manager_()
, mouse_action_(nullptr) // Will be set before this constructor ends.
, mouse_actions_()
, brush_(nullptr) // Will be set before this constructor ends.
, brush_(nullptr)
, brushes_()
{
init_brushes(game_config);
Expand Down Expand Up @@ -62,11 +62,11 @@ void editor_toolkit::init_sidebar(const config& game_config)
void editor_toolkit::init_mouse_actions(context_manager& cmanager)
{
mouse_actions_.emplace(hotkey::HOTKEY_EDITOR_TOOL_PAINT,
std::make_shared<mouse_action_paint>(brush_, key_, *palette_manager_->terrain_palette_.get()));
std::make_shared<mouse_action_paint>(&brush_, key_, *palette_manager_->terrain_palette_.get()));
mouse_actions_.emplace(hotkey::HOTKEY_EDITOR_TOOL_FILL,
std::make_shared<mouse_action_fill>(key_, *palette_manager_->terrain_palette_.get()));
mouse_actions_.emplace(hotkey::HOTKEY_EDITOR_TOOL_SELECT,
std::make_shared<mouse_action_select>(brush_, key_, *palette_manager_->empty_palette_.get()));
std::make_shared<mouse_action_select>(&brush_, key_, *palette_manager_->empty_palette_.get()));
mouse_actions_.emplace(hotkey::HOTKEY_EDITOR_TOOL_STARTING_POSITION,
std::make_shared<mouse_action_starting_position>(key_, *palette_manager_->location_palette_.get()));
mouse_actions_.emplace(hotkey::HOTKEY_EDITOR_TOOL_LABEL,
Expand Down

0 comments on commit a2327fa

Please sign in to comment.