Author: ilor
Date: Sat Jul 26 15:23:06 2008
New Revision: 28218

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28218&view=rev
Log:
editor2: selection tool

Modified:
    trunk/src/editor2/editor_controller.cpp
    trunk/src/editor2/editor_display.hpp
    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=28218&r1=28217&r2=28218&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Sat Jul 26 15:23:06 2008
@@ -64,6 +64,7 @@
        
        mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_PAINT, 
new mouse_action_paint(*this)));
        mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_FILL, 
new mouse_action_fill(*this)));
+       mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_SELECT, 
new mouse_action_select(*this)));
        hotkey_set_mouse_action(hotkey::HOTKEY_EDITOR_TOOL_PAINT);      
        
        cursor::set(cursor::NORMAL);
@@ -310,11 +311,9 @@
        switch (command) {
                case HOTKEY_EDITOR_TOOL_PAINT:
                case HOTKEY_EDITOR_TOOL_FILL:
+               case HOTKEY_EDITOR_TOOL_SELECT:
+//             case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
                        return is_mouse_action_set(command) ? ACTION_ON : 
ACTION_OFF;
-               case HOTKEY_EDITOR_TOOL_SELECT:
-                       //return get_mouse_action() == mouse_actions_["select"] 
? ACTION_ON : ACTION_OFF;
-               case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
-                       //return get_mouse_action() == 
mouse_actions_["startingposition"] ? ACTION_ON : ACTION_OFF;
                default:
                        return command_executor::get_action_state(command);
        }
@@ -336,7 +335,7 @@
                        return true;
                case HOTKEY_EDITOR_TOOL_PAINT:
                case HOTKEY_EDITOR_TOOL_FILL:
-//             case HOTKEY_EDITOR_TOOL_SELECT:
+               case HOTKEY_EDITOR_TOOL_SELECT:
 //             case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
                        hotkey_set_mouse_action(command);
                        return true;

Modified: trunk/src/editor2/editor_display.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_display.hpp?rev=28218&r1=28217&r2=28218&view=diff
==============================================================================
--- trunk/src/editor2/editor_display.hpp (original)
+++ trunk/src/editor2/editor_display.hpp Sat Jul 26 15:23:06 2008
@@ -31,9 +31,9 @@
        void set_brush_locs(const std::set<gamemap::location>& hexes); 
        void clear_brush_locs();
        void remove_brush_loc(const gamemap::location& hex);
+       const editor_map& map() const { return static_cast<const 
editor_map&>(map_); }
 
 protected:
-       const editor_map& map() { return static_cast<const editor_map&>(map_); }
        void pre_draw();
        /**
        * The editor uses different rules for terrain highligting (e.g. 
selections)

Modified: trunk/src/editor2/mouse_action.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.cpp?rev=28218&r1=28217&r2=28218&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.cpp (original)
+++ trunk/src/editor2/mouse_action.cpp Sat Jul 26 15:23:06 2008
@@ -38,42 +38,67 @@
        return NULL;
 }
 
-void mouse_action_paint::move(editor_display& disp, int x, int y)
+
+void brush_drag_mouse_action::move(editor_display& disp, int x, int y)
 {
        if (mode_.get_brush() != NULL) {
                
disp.set_brush_locs(mode_.get_brush()->project(disp.hex_clicked_on(x,y)));
        }
 }
 
-editor_action* mouse_action_paint::click(editor_display& disp, int x, int y)
+editor_action* brush_drag_mouse_action::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();
-       editor_action* a;
-       if (mode_.get_brush() != NULL) {
-               a = new 
editor_action_paint_area(mode_.get_brush()->project(hex), terrain);
-       } else {
-               a = new editor_action_paint_hex(hex, terrain);
-       }
        previous_hex_ = hex;
-       return a;
+       return click_perform(disp, hex);
 }
 
-editor_action* mouse_action_paint::drag(editor_display& disp, int x, int y, 
bool& partial, editor_action* last_undo)
+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);
        if (hex != previous_hex_) {
-               return click(disp, x, y);
+               return click_perform(disp, hex);
        } else {
                return NULL;
        }
 }
        
-editor_action* mouse_action_paint::drag_end(editor_display& disp, int x, int y)
+editor_action* brush_drag_mouse_action::drag_end(editor_display& disp, int x, 
int y)
 {
        return NULL;
 }
+
+editor_action* mouse_action_paint::click_perform(editor_display& disp, const 
gamemap::location& hex)
+{
+       t_translation::t_terrain terrain = mode_.get_foreground_terrain();
+       if (mode_.get_brush() != NULL) {
+               return new 
editor_action_paint_area(mode_.get_brush()->project(hex), terrain);
+       } else {
+               return new editor_action_paint_hex(hex, terrain);
+       }
+}
+
+editor_action* mouse_action_select::click(editor_display& disp, int x, int y)
+{
+       gamemap::location hex = disp.hex_clicked_on(x, y);
+       selecting_ = !disp.map().in_selection(hex);
+       return brush_drag_mouse_action::click(disp, x, y);
+}
+
+editor_action* mouse_action_select::click_perform(editor_display& disp, const 
gamemap::location& hex)
+{
+       editor_action* a(NULL);
+       if (mode_.get_brush() != NULL) {
+               if (selecting_) {
+                       a = new 
editor_action_select(mode_.get_brush()->project(hex));
+               } else {
+                       a = new 
editor_action_deselect(mode_.get_brush()->project(hex));
+               }
+       }
+       return a;
+}
+
 
 void mouse_action_fill::move(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=28218&r1=28217&r2=28218&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.hpp (original)
+++ trunk/src/editor2/mouse_action.hpp Sat Jul 26 15:23:06 2008
@@ -61,17 +61,41 @@
        gamemap::location previous_hex_;
 };
 
-class mouse_action_paint : public mouse_action
+class brush_drag_mouse_action : public mouse_action
 {
 public:
-       mouse_action_paint(editor_mode& mode)
+       brush_drag_mouse_action(editor_mode& mode)
        : mouse_action(mode)
        {
        }
        void move(editor_display& disp, int x, int y);
        editor_action* click(editor_display& disp, int x, int y);
+       virtual editor_action* click_perform(editor_display& disp, const 
gamemap::location& hex) = 0;
        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);    
+};
+
+class mouse_action_paint : public brush_drag_mouse_action
+{
+public:
+       mouse_action_paint(editor_mode& mode)
+       : brush_drag_mouse_action(mode)
+       {
+       }
+       editor_action* click_perform(editor_display& disp, const 
gamemap::location& hex);
+};
+
+class mouse_action_select : public brush_drag_mouse_action
+{
+public:
+       mouse_action_select(editor_mode& mode)
+       : brush_drag_mouse_action(mode), selecting_(true)
+       {
+       }
+       editor_action* click(editor_display& disp, int x, int y);
+       editor_action* click_perform(editor_display& disp, const 
gamemap::location& hex);
+protected:
+       bool selecting_;
 };
 
 class mouse_action_fill : public mouse_action


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to