Author: ilor
Date: Wed Aug 13 15:58:19 2008
New Revision: 28546
URL: http://svn.gna.org/viewcvs/wesnoth?rev=28546&view=rev
Log:
editor2: mouse actions cleanup and doc comments
Modified:
trunk/src/editor2/editor_controller.cpp
trunk/src/editor2/mouse_action.cpp
trunk/src/editor2/mouse_action.hpp
Modified: trunk/src/editor2/editor_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28546&r1=28545&r2=28546&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Wed Aug 13 15:58:19 2008
@@ -855,7 +855,7 @@
refresh_after_action(true);
}
} else {
- get_mouse_action()->move(*gui_, x, y);
+ get_mouse_action()->move(*gui_, hex_clicked);
}
gui().highlight_hex(hex_clicked);
}
Modified: trunk/src/editor2/mouse_action.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.cpp?rev=28546&r1=28545&r2=28546&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.cpp (original)
+++ trunk/src/editor2/mouse_action.cpp Wed Aug 13 15:58:19 2008
@@ -25,43 +25,36 @@
namespace editor2 {
-void mouse_action::move(editor_display& disp, int x, int y)
-{
- previous_move_hex_ = disp.hex_clicked_on(x, y);
-}
-
-editor_action* mouse_action::drag(editor_display& disp, int x, int y, bool&
partial, editor_action* last_undo)
-{
- return NULL;
-}
-
-editor_action* mouse_action::drag_end(editor_display& disp, int x, int y)
-{
- return NULL;
-}
-
-editor_action* mouse_action::key_event(editor_display& disp, const SDL_Event&
e)
-{
- return NULL;
-}
-
-
-void brush_drag_mouse_action::move(editor_display& disp, int x, int y)
-{
- gamemap::location hex = disp.hex_clicked_on(x, y);
- move(disp, hex);
-}
-
-void brush_drag_mouse_action::move(editor_display& disp, const
gamemap::location& hex)
-{
- LOG_ED << "Move" << hex << previous_move_hex_ << "\n";
+void mouse_action::move(editor_display& disp, const gamemap::location& hex)
+{
if (hex != previous_move_hex_) {
- LOG_ED << "setMove\n";
disp.set_brush_locs(affected_hexes(disp, hex));
previous_move_hex_ = hex;
}
}
+std::set<gamemap::location> mouse_action::affected_hexes(editor_display& disp,
const gamemap::location& hex)
+{
+ std::set<gamemap::location> res;
+ res.insert(hex);
+ return res;
+}
+
+editor_action* mouse_action::drag(editor_display& disp, int x, int y, bool&
partial, editor_action* last_undo)
+{
+ return NULL;
+}
+
+editor_action* mouse_action::drag_end(editor_display& disp, int x, int y)
+{
+ return NULL;
+}
+
+editor_action* mouse_action::key_event(editor_display& disp, const SDL_Event&
e)
+{
+ return NULL;
+}
+
std::set<gamemap::location> brush_drag_mouse_action::affected_hexes(
editor_display& disp, const gamemap::location& hex)
{
@@ -77,8 +70,8 @@
editor_action* brush_drag_mouse_action::drag(editor_display& disp, int x, int
y, bool& partial, editor_action* last_undo)
{
- move(disp, x, y);
- gamemap::location hex = disp.hex_clicked_on(x, y);
+ gamemap::location hex = disp.hex_clicked_on(x, y);
+ move(disp, hex);
if (hex != previous_drag_hex_) {
editor_action* a = click_perform(disp, affected_hexes(disp,
hex));
previous_drag_hex_ = hex;
@@ -107,6 +100,7 @@
return new editor_action_paint_area(hexes, terrain_, one_layer);
}
+
editor_action* mouse_action_select::click(editor_display& disp, int x, int y)
{
gamemap::location hex = disp.hex_clicked_on(x, y);
@@ -145,11 +139,10 @@
}
-void mouse_action_paste::move(editor_display& disp, int x, int y)
-{
- gamemap::location hex = disp.hex_clicked_on(x, y);
- std::set<gamemap::location> affected = paste_.get_offset_area(hex);
- disp.set_brush_locs(affected);
+std::set<gamemap::location> mouse_action_paste::affected_hexes(
+ editor_display& disp, const gamemap::location& hex)
+{
+ return paste_.get_offset_area(hex);
}
editor_action* mouse_action_paste::click(editor_display& disp, int x, int y)
@@ -160,11 +153,10 @@
}
-void mouse_action_fill::move(editor_display& disp, int x, int y)
-{
- std::set<gamemap::location> affected =
- disp.map().get_contigious_terrain_tiles(disp.hex_clicked_on(x,
y));
- disp.set_brush_locs(affected);
+std::set<gamemap::location> mouse_action_fill::affected_hexes(
+ editor_display& disp, const gamemap::location& hex)
+{
+ return disp.map().get_contigious_terrain_tiles(hex);
}
editor_action* mouse_action_fill::click(editor_display& disp, int x, int y)
@@ -177,16 +169,6 @@
return a;
}
-
-void mouse_action_starting_position::move(editor_display& disp, int x, int y)
-{
- gamemap::location hex = disp.hex_clicked_on(x, y);
- if (hex != previous_move_hex_) {
- disp.clear_brush_locs();
- disp.add_brush_loc(disp.hex_clicked_on(x, y));
- previous_move_hex_ = disp.hex_clicked_on(x, y);
- }
-}
editor_action* mouse_action_starting_position::click(editor_display& disp, int
x, int y)
{
Modified: trunk/src/editor2/mouse_action.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.hpp?rev=28546&r1=28545&r2=28546&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.hpp (original)
+++ trunk/src/editor2/mouse_action.hpp Wed Aug 13 15:58:19 2008
@@ -24,11 +24,12 @@
namespace editor2 {
-
/**
* A mouse action receives events from the controller, and responds to them by
creating
* an appropriate editor_action object. Mouse actions may store some temporary
data
- * such as the last clicked hex for better handling of click-drag.
+ * such as the last clicked hex for better handling of click-drag. They should
*not* modify
+ * the map or trigger refreshes, but may set brush locations and similar
overlays that
+ * should be visible around the mouse cursor, hence the display references are
not const.
*/
class mouse_action
{
@@ -40,36 +41,63 @@
virtual ~mouse_action() {}
- virtual void move(editor_display& disp, int x, int y);
-
- /**
- * A click, possibly the beginning of a drag
+ /**
+ * Mouse move (not a drag). Never changes anything (other than
temporary highlihts and similar)
+ */
+ void move(editor_display& disp, const gamemap::location& hex);
+
+ /**
+ * Locations that would be affected by a click, used by move to update
highlights. Defauts to higlight the mouseover hex.
+ * Maybe also used for actually performing the action in click() or
drag().
+ */
+ virtual std::set<gamemap::location> affected_hexes(editor_display&
disp, const gamemap::location& hex);
+
+ /**
+ * A click, possibly the beginning of a drag. Must be overriden.
*/
virtual editor_action* click(editor_display& disp, int x, int y) = 0;
/**
- * Drag operation. A click should have occured earlier.
+ * Drag operation. A click should have occured earlier. Defaults to no
action.
*/
virtual editor_action* drag(editor_display& disp, int x, int y, bool&
partial, editor_action* last_undo);
/**
- * The end of dragging.
+ * The end of dragging. Defaults to no action.
*/
virtual editor_action* drag_end(editor_display& disp, int x, int y);
+ /**
+ * Function called by the controller on a key event for the current
mouse action.
+ * Defaults to no action.
+ */
virtual editor_action* key_event(editor_display& disp, const SDL_Event&
e);
+ /**
+ * Helper variable setter and getter - pointer to a toolbar menu/button
used for highlighting
+ * the current action. Should always be NULL or point to a valid menu.
+ */
void set_toolbar_button(const theme::menu* value) { toolbar_button_ =
value; }
const theme::menu* toolbar_button() const { return toolbar_button_; }
protected:
+ /**
+ * The hex previously used in move operations
+ */
gamemap::location previous_move_hex_;
+
+ /**
+ * Key presses, used for modifiers (alt, shift) in some operations
+ */
const CKey& key_;
private:
const theme::menu* toolbar_button_;
};
+/**
+ * A brush-drag mouse action base class which adds brush and drag processing
to a basic mouse action
+ */
class brush_drag_mouse_action : public mouse_action
{
public:
@@ -77,20 +105,49 @@
: mouse_action(key), brush_(brush)
{
}
- void move(editor_display& disp, int x, int y);
- void move(editor_display& disp, const gamemap::location& hex);
- virtual std::set<gamemap::location> affected_hexes(editor_display&
disp, const gamemap::location& hex);
- editor_action* click(editor_display& disp, int x, int y);
+
+ /**
+ * The affected hexes of a brush action are the result of projecting
the current brush on the mouseover hex
+ */
+ std::set<gamemap::location> affected_hexes(editor_display& disp, const
gamemap::location& hex);
+
+ /**
+ * The actual action function which is called by click() and drag().
Derived classes override this instead of click() and drag().
+ */
virtual editor_action* click_perform(editor_display& disp, const
std::set<gamemap::location>& hexes) = 0;
+
+ /**
+ * Calls click_perform()
+ */
+ editor_action* click(editor_display& disp, int x, int y);
+
+ /**
+ * Calls click_perform() for every new hex the mouse is dragged into.
+ * @todo partial actions support and merging of many drag actions into
one
+ */
editor_action* drag(editor_display& disp, int x, int y, bool& partial,
editor_action* last_undo);
+
editor_action* drag_end(editor_display& disp, int x, int y);
-protected:
+
+protected:
+ /** Brush accessor */
const brush& get_brush();
+
+ /**
+ * The previous hex dragged into.
+ * @todo keep a set of all "visited" locations to reduce action count
in long drags that hit the same hexes multiple times?
+ */
gamemap::location previous_drag_hex_;
private:
+ /**
+ * Current brush handle
+ */
const brush* const * const brush_;
};
+/**
+ * Brush paint mouse action. Uses keyboard modifiers for one-layer painting.
+ */
class mouse_action_paint : public brush_drag_mouse_action
{
public:
@@ -98,11 +155,18 @@
: brush_drag_mouse_action(brush, key), terrain_(terrain)
{
}
+
+ /**
+ * Create an appropriate editor_action and return it
+ */
editor_action* click_perform(editor_display& disp, const
std::set<gamemap::location>& hexes);
protected:
const t_translation::t_terrain& terrain_;
};
+/**
+ * Select (and deselect) action, by brush or "magic wand" (via keyboard
modifier)
+ */
class mouse_action_select : public brush_drag_mouse_action
{
public:
@@ -110,14 +174,36 @@
: brush_drag_mouse_action(brush, key), selecting_(true)
{
}
+
+ /**
+ * Overriden to allow special behaviour based on modifier keys
+ */
std::set<gamemap::location> affected_hexes(editor_display& disp, const
gamemap::location& hex);
+
+ /**
+ * Force a fake "move" event to update brush overkay on key event
+ */
editor_action* key_event(editor_display& disp, const SDL_Event& e);
- editor_action* click(editor_display& disp, int x, int y);
+
+ /**
+ * Click is overriden to set selecting_ according to the whether the
mouseover hex is selecte, and call base class' click*()
+ */
+ editor_action* click(editor_display& disp, int x, int y);
+
+ /**
+ * Return a select or deselect action based on the state of selecting_
flag
+ */
editor_action* click_perform(editor_display& disp, const
std::set<gamemap::location>& hexes);
protected:
+ /**
+ * Selecting (true) or deselecting (false) flag used in dragging
+ */
bool selecting_;
};
+/**
+ * Paste action. No dragging capabilities.
+ */
class mouse_action_paste : public mouse_action
{
public:
@@ -125,12 +211,15 @@
: mouse_action(key), paste_(paste)
{
}
- void move(editor_display& disp, int x, int y);
+ std::set<gamemap::location> affected_hexes(editor_display& disp, const
gamemap::location& hex);
editor_action* click(editor_display& disp, int x, int y);
protected:
const map_fragment& paste_;
};
+/**
+ * Fill action. No dragging capabilities. Uses keyboard modifiers for
one-layer painting.
+ */
class mouse_action_fill : public mouse_action
{
public:
@@ -138,12 +227,15 @@
: mouse_action(key), terrain_(terrain)
{
}
- void move(editor_display& disp, int x, int y);
+ std::set<gamemap::location> affected_hexes(editor_display& disp, const
gamemap::location& hex);
editor_action* click(editor_display& disp, int x, int y);
protected:
const t_translation::t_terrain& terrain_;
};
+/**
+ * Set starting position action.
+ */
class mouse_action_starting_position : public mouse_action
{
public:
@@ -151,8 +243,15 @@
: mouse_action(key)
{
}
+
+ /**
+ * Allows setting/clearing the starting positions in the mouseover
hexes via keyboard
+ */
editor_action* key_event(editor_display& disp, const SDL_Event& e);
- void move(editor_display& disp, int x, int y);
+
+ /**
+ * Click displays a player-number-selector dialog and then creates an
action (or not, if cancel was pressed).
+ */
editor_action* click(editor_display& disp, int x, int y);
};
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits