Author: ilor
Date: Tue Jul 15 16:02:23 2008
New Revision: 28042
URL: http://svn.gna.org/viewcvs/wesnoth?rev=28042&view=rev
Log:
make mouse actions use brush locations instead of highlight, misc changes, todo
code for drag as one action support
Modified:
trunk/src/editor2/action.hpp
trunk/src/editor2/editor_controller.cpp
trunk/src/editor2/editor_controller.hpp
trunk/src/editor2/mouse_action.cpp
trunk/src/editor2/mouse_action.hpp
Modified: trunk/src/editor2/action.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.hpp?rev=28042&r1=28041&r2=28042&view=diff
==============================================================================
--- trunk/src/editor2/action.hpp (original)
+++ trunk/src/editor2/action.hpp Tue Jul 15 16:02:23 2008
@@ -61,35 +61,6 @@
std::vector<editor_action*> actions_;
};
-//class editor_action_chain_whole_map : public editor_action_chain
-//{
-// public:
-// explicit
editor_action_chain_whole_map(std::vector<editor_action*> actions)
-// : editor_action_chain(actions)
-// {
-// }
-// editor_action_whole_map* perform(editor_map& m)
-// {
-// editor_action_whole_map* undo = new
editor_action_whole_map(m);
-// perform_without_undo(m);
-// return undo;
-// }
-//
-//};
-
-//class editor_action_undo_wrapper : public editor_action
-//{
-// public:
-// editor_action_undo_wrapper(editor_action* undo, editor_action*
redo)
-// : undo_(undo)
-// , redo_(redo)
-// {
-// }
-// ~editor_action_undo_wrapper();
-// protected:
-//
-//};
-
//common base classes for actions with common behaviour
//actions which act on a specified location (and possibly on other locations
@@ -138,7 +109,7 @@
class editor_action_paint_hex : public editor_action_location_terrain
{
public:
- editor_action_paint_hex(gamemap::location loc,
t_translation::t_terrain t)
+ editor_action_paint_hex(const gamemap::location& loc,
t_translation::t_terrain t)
: editor_action_location_terrain(loc, t)
{
}
@@ -149,13 +120,14 @@
class editor_action_paint_area : public editor_action
{
public:
- editor_action_paint_area(std::set<gamemap::location> area,
+ editor_action_paint_area(const std::set<gamemap::location>& area,
t_translation::t_terrain t)
: area_(area), t_(t)
{
}
editor_action_paste* perform(editor_map& map) const;
void perform_without_undo(editor_map& map) const;
+ void add_location(const gamemap::location& loc);
protected:
std::set<gamemap::location> area_;
t_translation::t_terrain t_;
Modified: trunk/src/editor2/editor_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28042&r1=28041&r2=28042&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Tue Jul 15 16:02:23 2008
@@ -198,14 +198,23 @@
void editor_controller::perform_action(const editor_action& action)
{
SCOPE_ED;
+ LOG_ED << "Performing action " << action.get_id() << ", actions count
is " << action.get_instance_count() << "\n";
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_);
refresh_after_action(action);
}
+void editor_controller::perform_partial_action(const editor_action& action)
+{
+ SCOPE_ED;
+ LOG_ED << "Performing (partial) action " << action.get_id() << ",
actions count is " << action.get_instance_count() << "\n";
+ action.perform_without_undo(map_);
+ clear_stack(redo_stack_);
+ refresh_after_action(action);
+}
+
void editor_controller::refresh_after_action(const editor_action& /*action*/)
{
//TODO rebuild and ivalidate only what's really needed
@@ -266,13 +275,27 @@
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);
+ editor_action* last_undo ;
+ if (undo_stack_.empty()) {
+ LOG_ED << __FUNCTION__ << ": Empty undo stack
in drag\n";
+ last_undo = NULL;
+ } else {
+ last_undo = undo_stack_.back();
+ }
+ bool partial = false;
+ editor_action* a = get_mouse_action()->drag(*gui_, x,
y, partial, last_undo);
+ //Partial means that the mouse action has modified the
last undo action and the controller shouldn't add
+ //anything to the undo stack (hence a diferent perform_
call
if (a != NULL) {
- perform_action(*a);
+ if (partial) {
+ perform_partial_action(*a);
+ } else {
+ perform_action(*a);
+ }
delete a;
}
} else {
- LOG_ED << __FUNCTION__ << ": There is no mouse action
active!\n";
+ WRN_ED << __FUNCTION__ << ": There is no mouse action
active!\n";
}
} else {
if (get_mouse_action() != NULL) {
Modified: trunk/src/editor2/editor_controller.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=28042&r1=28041&r2=28042&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Tue Jul 15 16:02:23 2008
@@ -73,6 +73,8 @@
*/
void perform_action(const editor_action& action);
+ void perform_partial_action(const editor_action& action);
+
void refresh_after_action(const editor_action& action);
/**
Modified: trunk/src/editor2/mouse_action.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.cpp?rev=28042&r1=28041&r2=28042&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.cpp (original)
+++ trunk/src/editor2/mouse_action.cpp Tue Jul 15 16:02:23 2008
@@ -28,7 +28,7 @@
{
}
-editor_action* mouse_action::drag(editor_display& disp, int x, int y)
+editor_action* mouse_action::drag(editor_display& disp, int x, int y, bool&
partial, editor_action* last_undo)
{
return NULL;
}
@@ -40,12 +40,8 @@
void mouse_action_paint::move(editor_display& disp, int x, int y)
{
- SCOPE_ED;
- disp.clear_highlighted_locs();
if (mode_.get_brush() != NULL) {
- foreach (gamemap::location loc,
mode_.get_brush()->project(disp.hex_clicked_on(x,y))) {
- disp.add_highlighted_loc(loc);
- }
+
disp.set_brush_locs(mode_.get_brush()->project(disp.hex_clicked_on(x,y)));
}
}
@@ -63,7 +59,7 @@
return a;
}
-editor_action* mouse_action_paint::drag(editor_display& disp, int x, int y)
+editor_action* mouse_action_paint::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);
@@ -76,18 +72,15 @@
editor_action* mouse_action_paint::drag_end(editor_display& disp, int x, int y)
{
- return drag(disp, x, y);
+ return NULL;
}
void mouse_action_fill::move(editor_display& disp, int x, int y)
{
- disp.clear_highlighted_locs();
std::set<gamemap::location> affected =
dynamic_cast<const editor_map&>(disp.get_map()).
get_contigious_terrain_tiles(disp.hex_clicked_on(x, y));
- foreach (gamemap::location loc, affected) {
- disp.add_highlighted_loc(loc);
- }
+ disp.set_brush_locs(affected);
}
editor_action* mouse_action_fill::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=28042&r1=28041&r2=28042&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.hpp (original)
+++ trunk/src/editor2/mouse_action.hpp Tue Jul 15 16:02:23 2008
@@ -49,7 +49,7 @@
/**
* Drag operation. A click should have occured earlier.
*/
- virtual editor_action* drag(editor_display& disp, int x, int y);
+ virtual editor_action* drag(editor_display& disp, int x, int y, bool&
partial, editor_action* last_undo);
/**
* The end of dragging.
@@ -70,7 +70,7 @@
}
void move(editor_display& disp, int x, int y);
editor_action* click(editor_display& disp, int x, int y);
- editor_action* drag(editor_display& disp, int x, int y);
+ 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);
};
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits