Author: ilor
Date: Wed Jul 9 16:59:44 2008
New Revision: 27873
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27873&view=rev
Log:
Editor2: basic click-drag support, some debugging aids, small changes in
mouse_handler_base to better faciliate the click-dragging
Modified:
trunk/src/editor2/action.cpp
trunk/src/editor2/action_base.hpp
trunk/src/editor2/editor_controller.cpp
trunk/src/editor2/editor_controller.hpp
trunk/src/editor2/editor_mode.hpp
trunk/src/editor2/mouse_action.cpp
trunk/src/editor2/mouse_action.hpp
trunk/src/mouse_events.cpp
trunk/src/mouse_events.hpp
trunk/src/mouse_handler_base.cpp
trunk/src/mouse_handler_base.hpp
Modified: trunk/src/editor2/action.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.cpp?rev=27873&r1=27872&r2=27873&view=diff
==============================================================================
--- trunk/src/editor2/action.cpp (original)
+++ trunk/src/editor2/action.cpp Wed Jul 9 16:59:44 2008
@@ -20,6 +20,14 @@
#include "../foreach.hpp"
namespace editor2 {
+
+int editor_action::next_id_ = 1;
+int editor_action::instance_count_ = 0;
+
+std::string editor_action::get_description()
+{
+ return "Unknown action";
+}
editor_action_whole_map* editor_action_whole_map::perform(editor_map& m) const
{
editor_action_whole_map* undo = new editor_action_whole_map(m);
@@ -71,7 +79,6 @@
}
void editor_action_paint_hex::perform_without_undo(editor_map& map) const
{
- SCOPE_ED;
map.set_terrain(loc_, t_);
}
Modified: trunk/src/editor2/action_base.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action_base.hpp?rev=27873&r1=27872&r2=27873&view=diff
==============================================================================
--- trunk/src/editor2/action_base.hpp (original)
+++ trunk/src/editor2/action_base.hpp Wed Jul 9 16:59:44 2008
@@ -26,6 +26,7 @@
#define EDITOR2_ACTION_BASE_HPP_INCLUDED
#include "editor_common.hpp"
+#include <string>
namespace editor2 {
@@ -34,13 +35,48 @@
{
public:
editor_action()
+ : id_(next_id_++)
{
+ instance_count_++;
}
+
virtual ~editor_action()
{
- }
- virtual editor_action* perform(editor_map&) const = 0;
- virtual void perform_without_undo(editor_map&) const = 0;
+ instance_count_--;
+ }
+
+ /**
+ * Perform the action, returning an undo action that, when
performed, will reverse any effects of this action.
+ * The undo action object is owned by the caller.
+ */
+ virtual editor_action* perform(editor_map&) const = 0;
+
+ /**
+ * Perform the action without creating an undo action.
+ */
+ virtual void perform_without_undo(editor_map&) const = 0;
+
+ /**
+ * A textual description of the action. For use e.g. in the
undo menu, to have
+ * a "Undo: Fill with Grassland" item rather than just "Undo".
Should be overriden
+ * by derived Actions, defaults to a debug message.
+ */
+ virtual std::string get_description();
+
+ /**
+ * Debugging aid. Return an unique identifier of this Action.
+ */
+ int get_id() const { return id_; }
+
+ /**
+ * Debugging aid. Return number of existing instances of
Actions.
+ */
+ static int get_instance_count() { return instance_count_; }
+
+ private:
+ static int next_id_;
+ static int instance_count_;
+ const int id_;
};
Modified: trunk/src/editor2/editor_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=27873&r1=27872&r2=27873&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Wed Jul 9 16:59:44 2008
@@ -84,6 +84,7 @@
{
SCOPE_ED;
editor_action* undo = action.perform(map_);
+ LOG_ED << "Performing action " << action.get_id() << ", actions count
is " << action.get_instance_count() << "\n";
undo_stack_.push_back(undo);
trim_stack(undo_stack_);
clear_stack(redo_stack_);
@@ -137,26 +138,52 @@
trim_stack(to);
}
-void editor_controller::mouse_motion(int x, int y, const bool /*browse*/, bool
update)
+void editor_controller::mouse_motion(int x, int y, const bool browse, bool
update)
{
if (mouse_handler_base::mouse_motion_default(x, y, update)) return;
+ if (dragging_) {
+ if (get_mouse_action() != NULL) {
+ editor_action* a = get_mouse_action()->drag(*gui_, x,
y);
+ if (a != NULL) {
+ perform_action(*a);
+ delete a;
+ }
+ } else {
+ LOG_ED << __FUNCTION__ << ": There is no mouse action
active!\n";
+ }
+ }
const gamemap::location new_hex = gui().hex_clicked_on(x,y);
gui().highlight_hex(new_hex);
}
-bool editor_controller::left_click(const SDL_MouseButtonEvent& event, const
bool browse)
+bool editor_controller::left_click(int x, int y, const bool browse)
{
- if (mouse_handler_base::left_click(event, browse)) return true;
+ if (mouse_handler_base::left_click(x, y, browse)) return true;
LOG_ED << "Left click, after generic handling\n";
if (get_mouse_action() != NULL) {
- editor_action* a = get_mouse_action()->click(*gui_, event.x,
event.y);
- perform_action(*a);
- delete a;
+ editor_action* a = get_mouse_action()->click(*gui_, x, y);
+ if (a != NULL) {
+ perform_action(*a);
+ delete a;
+ }
return true;
} else {
- LOG_ED << "There is no mouse action active!\n";
+ LOG_ED << __FUNCTION__ << ": There is no mouse action
active!\n";
return false;
}
+}
+
+void editor_controller::left_drag_end(int x, int y, const bool browse)
+{
+ if (get_mouse_action() != NULL) {
+ editor_action* a = get_mouse_action()->drag_end(*gui_, x, y);
+ if (a != NULL) {
+ perform_action(*a);
+ delete a;
+ }
+ } else {
+ LOG_ED << __FUNCTION__ << ": There is no mouse action
active!\n";
+ }
}
Modified: trunk/src/editor2/editor_controller.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=27873&r1=27872&r2=27873&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Wed Jul 9 16:59:44 2008
@@ -48,7 +48,9 @@
void mouse_motion(int x, int y, const bool browse, bool update);
editor_display& gui() { return *gui_; }
const editor_display& gui() const { return *gui_; }
- bool left_click(const SDL_MouseButtonEvent& event, const bool
browse);
+ bool left_click(int x, int y, const bool browse);
+ void left_drag_end(int x, int y, const bool browse);
+
protected:
mouse_handler_base& get_mouse_handler_base();
editor_display& get_display();
Modified: trunk/src/editor2/editor_mode.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_mode.hpp?rev=27873&r1=27872&r2=27873&view=diff
==============================================================================
--- trunk/src/editor2/editor_mode.hpp (original)
+++ trunk/src/editor2/editor_mode.hpp Wed Jul 9 16:59:44 2008
@@ -36,10 +36,10 @@
, mouse_action_(NULL)
{
}
- const t_translation::t_terrain& get_foreground_terrain() { return
foreground_terrain_; }
- const t_translation::t_terrain& get_background_terrain() { return
background_terrain_; }
- const brush* get_brush() { return brush_; }
- const mouse_action* get_mouse_action() { return mouse_action_; }
+ const t_translation::t_terrain& get_foreground_terrain() const { return
foreground_terrain_; }
+ const t_translation::t_terrain& get_background_terrain() const { return
background_terrain_; }
+ const brush* get_brush() const { return brush_; }
+ mouse_action* get_mouse_action() { return mouse_action_; }
protected:
void set_foreground_terrain(t_translation::t_terrain t) {
foreground_terrain_ = t; }
void set_background_terrain(t_translation::t_terrain t) {
background_terrain_ = t; }
Modified: trunk/src/editor2/mouse_action.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.cpp?rev=27873&r1=27872&r2=27873&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.cpp (original)
+++ trunk/src/editor2/mouse_action.cpp Wed Jul 9 16:59:44 2008
@@ -22,15 +22,38 @@
namespace editor2 {
-editor_action* mouse_action_paint::click(editor_display& disp, int mousex, int
mousey) const
+editor_action* mouse_action::drag(editor_display& disp, int x, int y)
{
- gamemap::location hex = disp.hex_clicked_on(mousex, mousey);
+ return NULL;
+}
+
+editor_action* mouse_action::drag_end(editor_display& disp, int x, int y)
+{
+ return NULL;
+}
+
+editor_action* mouse_action_paint::click(editor_display& disp, int x, int y)
+{
+ gamemap::location hex = disp.hex_clicked_on(x, y);
t_translation::t_terrain terrain = mode_.get_foreground_terrain();
- LOG_ED << disp.get_map().get_terrain_string(terrain) << "\n";
- LOG_ED << disp.get_map().get_terrain_string(t_translation::MOUNTAIN) <<
"\n";
- LOG_ED << disp.get_map().get_terrain_string(t_translation::DEEP_WATER)
<< "\n";
editor_action_paint_hex* a = new editor_action_paint_hex(hex, terrain);
+ previous_hex_ = hex;
return a;
}
+
+editor_action* mouse_action_paint::drag(editor_display& disp, int x, int y)
+{
+ gamemap::location hex = disp.hex_clicked_on(x, y);
+ if (hex != previous_hex_) {
+ return click(disp, x, y);
+ } else {
+ return NULL;
+ }
+}
+editor_action* mouse_action_paint::drag_end(editor_display& disp, int x, int y)
+{
+ return drag(disp, x, y);
+}
+
} //end namespace editor2
Modified: trunk/src/editor2/mouse_action.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.hpp?rev=27873&r1=27872&r2=27873&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.hpp (original)
+++ trunk/src/editor2/mouse_action.hpp Wed Jul 9 16:59:44 2008
@@ -30,7 +30,9 @@
: mode_(mode)
{
}
- virtual editor_action* click(editor_display& disp, int mousex, int
mousey) const = 0;
+ virtual editor_action* click(editor_display& disp, int x, int y) = 0;
+ virtual editor_action* drag(editor_display& disp, int x, int y);
+ virtual editor_action* drag_end(editor_display& disp, int x, int y);
// virtual void drag_start();
// virtual void drag_through();
// virtual void drag_end();
@@ -45,7 +47,11 @@
: mouse_action(mode)
{
}
- editor_action* click(editor_display& disp, int mousex, int mousey)
const;
+ editor_action* click(editor_display& disp, int x, int y);
+ editor_action* drag(editor_display& disp, int x, int y);
+ editor_action* drag_end(editor_display& disp, int x, int y);
+protected:
+ gamemap::location previous_hex_;
};
Modified: trunk/src/mouse_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.cpp?rev=27873&r1=27872&r2=27873&view=diff
==============================================================================
--- trunk/src/mouse_events.cpp (original)
+++ trunk/src/mouse_events.cpp Wed Jul 9 16:59:44 2008
@@ -324,7 +324,7 @@
mouse_handler_base::mouse_press(event, browse);
}
-bool mouse_handler::right_click_before_menu(const SDL_MouseButtonEvent& /*
event */, const bool browse)
+bool mouse_handler::right_click_before_menu(int /*x*/, int /*y*/, const bool
browse)
{
if (selected_hex_.valid() && find_unit(selected_hex_) != units_.end()) {
select_hex(gamemap::location(), browse);
@@ -334,10 +334,10 @@
}
}
-bool mouse_handler::left_click(const SDL_MouseButtonEvent& event, const bool
browse)
+bool mouse_handler::left_click(int x, int y, const bool browse)
{
undo_ = false;
- if (mouse_handler_base::left_click(event, browse)) return true;
+ if (mouse_handler_base::left_click(x, y, browse)) return true;
bool check_shroud = teams_[team_num_ - 1].auto_shroud_updates();
Modified: trunk/src/mouse_events.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.hpp?rev=27873&r1=27872&r2=27873&view=diff
==============================================================================
--- trunk/src/mouse_events.hpp (original)
+++ trunk/src/mouse_events.hpp Wed Jul 9 16:59:44 2008
@@ -74,8 +74,8 @@
* Use update to force an update of the mouse state.
*/
void mouse_motion(int x, int y, const bool browse, bool update=false);
- bool right_click_before_menu(const SDL_MouseButtonEvent& event, const
bool browse);
- bool left_click(const SDL_MouseButtonEvent& event, const bool browse);
+ bool right_click_before_menu(int x, int y, const bool browse);
+ bool left_click(int x, int y, const bool browse);
void select_hex(const gamemap::location& hex, const bool browse);
void clear_undo_stack();
bool move_unit_along_current_route(bool check_shroud, bool
attackmove=false);
Modified: trunk/src/mouse_handler_base.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_handler_base.cpp?rev=27873&r1=27872&r2=27873&view=diff
==============================================================================
--- trunk/src/mouse_handler_base.cpp (original)
+++ trunk/src/mouse_handler_base.cpp Wed Jul 9 16:59:44 2008
@@ -110,13 +110,13 @@
dragging_ = false;
cursor::set_dragging(false);
if (dragging_started_ && !browse && !commands_disabled) {
- left_click(event, browse);
+ left_drag_end(event.x, event.y, browse);
}
dragging_started_= false;
} else if(is_middle_click(event) && event.state == SDL_RELEASED) {
minimap_scrolling_ = false;
} else if(is_left_click(event) && event.state == SDL_PRESSED) {
- left_click(event, browse);
+ left_click(event.x, event.y, browse);
if (!browse && !commands_disabled) {
dragging_ = true;
dragging_started_ = false;
@@ -128,7 +128,7 @@
dragging_ = false;
dragging_started_ = false;
cursor::set_dragging(false);
- if (right_click_before_menu(event, browse)) {
+ if (right_click_before_menu(event.x, event.y, browse)) {
gui().draw(); // redraw highlight (and maybe some more)
const theme::menu* const m =
gui().get_theme().context_menu();
if (m != NULL)
@@ -185,19 +185,19 @@
return event.button == SDL_BUTTON_RIGHT || (event.button ==
SDL_BUTTON_LEFT && command_active());
}
-bool mouse_handler_base::right_click_before_menu(const SDL_MouseButtonEvent&
/*event*/, const bool /*browse*/)
+bool mouse_handler_base::right_click_before_menu(int /*x*/, int /*y*/, const
bool /*browse*/)
{
return true;
}
-bool mouse_handler_base::left_click(const SDL_MouseButtonEvent& event, const
bool /*browse*/)
+bool mouse_handler_base::left_click(int x, int y, const bool /*browse*/)
{
dragging_ = false;
dragging_started_ = false;
cursor::set_dragging(false);
// clicked on a hex on the minimap? then initiate minimap scrolling
- const gamemap::location& loc =
gui().minimap_location_on(event.x,event.y);
+ const gamemap::location& loc = gui().minimap_location_on(x, y);
minimap_scrolling_ = false;
if(loc.valid()) {
minimap_scrolling_ = true;
@@ -208,7 +208,13 @@
return false;
}
-bool mouse_handler_base::right_click(const SDL_MouseButtonEvent& /*event*/,
const bool /*browse*/)
+void mouse_handler_base::left_drag_end(int x, int y, const bool browse)
+{
+ left_click(x, y, browse);
+}
+
+
+bool mouse_handler_base::right_click(int /*x*/, int /*y*/, const bool
/*browse*/)
{
return false;
}
Modified: trunk/src/mouse_handler_base.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_handler_base.hpp?rev=27873&r1=27872&r2=27873&view=diff
==============================================================================
--- trunk/src/mouse_handler_base.hpp (original)
+++ trunk/src/mouse_handler_base.hpp Wed Jul 9 16:59:44 2008
@@ -65,16 +65,18 @@
/**
* @returns true when the (child) caller should not process the event
further
*/
- virtual bool left_click(const SDL_MouseButtonEvent& event, const bool
browse);
+ virtual bool left_click(int x, int y, const bool browse);
- virtual bool right_click(const SDL_MouseButtonEvent& event, const bool
browse);
+ virtual void left_drag_end(int x, int y, const bool browse);
+
+ virtual bool right_click(int x, int y, const bool browse);
/**
* Called in right_click when the context menu is about to be shown,
can be
* used for preprocessing and preventing the menu from being displayed.
* @returns true when the menu should be displayed and false otherwise
*/
- virtual bool right_click_before_menu(const SDL_MouseButtonEvent& event,
const bool browse);
+ virtual bool right_click_before_menu(int x, int y, const bool browse);
protected:
bool minimap_scrolling_;
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits