mail[Wesnoth-commits] r20655 - in /trunk: data/themes/editor.cfg src/editor/editor.cpp src/editor/editor.hpp src/hotkeys.cpp src/hotkeys.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by alinktomine on September 22, 2007 - 02:13:
Author: alink
Date: Sat Sep 22 02:12:41 2007
New Revision: 20655

URL: http://svn.gna.org/viewcvs/wesnoth?rev=20655&view=rev
Log:
New "rotate selection" feature for the editor (very old FR, bug #3870) 
- Use the cursor as center of rotation, if not on map then use "center of 
mass"
- Use hotkey shift+r, as Gimp. (ctrl+r is reserved by recruit, old hotkey bug)
- copy/paste instead of moving, not sure about that but seems more useful
(if wanted you can overwrite on the current selection and then cut/paste)
Because the main use is probably to help create map like Hexcake, but rotate
after a select-all allow to rotate the whole map (with cropping of corners)

Modified:
    trunk/data/themes/editor.cfg
    trunk/src/editor/editor.cpp
    trunk/src/editor/editor.hpp
    trunk/src/hotkeys.cpp
    trunk/src/hotkeys.hpp

Modified: trunk/data/themes/editor.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/themes/editor.cfg?rev=20655&r1=20654&r2=20655&view=diff
==============================================================================
--- trunk/data/themes/editor.cfg (original)
+++ trunk/data/themes/editor.cfg Sat Sep 22 02:12:41 2007
@@ -133,6 +133,14 @@
     [/hotkey]
 
     [hotkey]
+        command="editrotateselection"
+        key="r"
+        cmd=no
+        alt=no
+        shift=yes
+    [/hotkey]
+
+    [hotkey]
         command="editcut"
         key="x"
         cmd=yes
@@ -363,6 +371,14 @@
         ctrl=no
         alt=yes
         shift=no
+    [/hotkey]
+
+    [hotkey]
+        command="editrotateselection"
+        key="r"
+        ctrl=no
+        alt=no
+        shift=yes
     [/hotkey]
 
     [hotkey]
@@ -531,7 +547,7 @@
         [menu]
             title=_"Edit"
             image=lite
-            
items=undo,redo,editcut,editcopy,editpaste,editselectall,editfillselection,editresize,editflip,editrefresh,editupdate,
+            
items=undo,redo,editcut,editcopy,editpaste,editselectall,editfillselection,editrotateselection,editresize,editflip,editrefresh,editupdate,
             rect=107,1,207,22
         [/menu]
 

Modified: trunk/src/editor/editor.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor/editor.cpp?rev=20655&r1=20654&r2=20655&view=diff
==============================================================================
--- trunk/src/editor/editor.cpp (original)
+++ trunk/src/editor/editor.cpp Sat Sep 22 02:12:41 2007
@@ -657,6 +657,46 @@
        left_button_func_changed(PASTE);
 }
 
+void map_editor::edit_rotate_selection()
+{
+       if (selected_hexes_.empty()) {return;}
+
+       // we use the selected hex as center
+       gamemap::location center = selected_hex_;
+       if (!center.valid()) {
+               // except if invalid (e.g the mouse is in menu)
+               // then we search the "center of mass" 
+               center = gamemap::location(0,0);
+               std::set<gamemap::location>::const_iterator it;
+               for(it = selected_hexes_.begin(); it != 
selected_hexes_.end(); it++) {
+                       center = center + *it;
+               }
+               center.x = center.x / selected_hexes_.size();
+               center.y = center.y / selected_hexes_.size();
+       }
+
+       map_buffer buf;
+       copy_buffer(buf, selected_hexes_, center);
+
+       std::vector<buffer_item>::iterator it;
+       for(it = buf.begin(); it != buf.end(); it++) {
+               gamemap::location l(0,0);
+               int x = it->offset.x;
+               int y = it->offset.y;
+               // rotate the X-Y axes to SOUTH/SOUTH_EAST - SOUTH_WEST axes
+               // but if x is odd, simply using x/2 + x/2 will lack a step
+               l = l.get_direction(gamemap::location::SOUTH, 
(x+is_odd(x))/2);
+               l = l.get_direction(gamemap::location::SOUTH_EAST, 
(x-is_odd(x))/2 );
+               l = l.get_direction(gamemap::location::SOUTH_WEST, y);
+               it->offset = l;
+       }
+
+       map_undo_action undo_action;
+       terrain_changed(selected_hexes_);
+       paste_buffer(buf, center, undo_action);
+       save_undo_action(undo_action);
+}
+
 void map_editor::edit_revert() {
        std::string new_map = read_file(filename_);
        bool scenario;
@@ -847,6 +887,7 @@
        case hotkey::HOTKEY_EDIT_LOAD_MAP:
        case hotkey::HOTKEY_EDIT_FLOOD_FILL:
        case hotkey::HOTKEY_EDIT_FILL_SELECTION:
+       case hotkey::HOTKEY_EDIT_ROTATE_SELECTION:
        case hotkey::HOTKEY_EDIT_COPY:
        case hotkey::HOTKEY_EDIT_CUT:
        case hotkey::HOTKEY_EDIT_PASTE:

Modified: trunk/src/editor/editor.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor/editor.hpp?rev=20655&r1=20654&r2=20655&view=diff
==============================================================================
--- trunk/src/editor/editor.hpp (original)
+++ trunk/src/editor/editor.hpp Sat Sep 22 02:12:41 2007
@@ -116,6 +116,7 @@
        virtual void edit_set_start_pos();
        virtual void edit_flood_fill();
        virtual void edit_fill_selection();
+       virtual void edit_rotate_selection();
        virtual void edit_cut();
        virtual void edit_copy();
        virtual void edit_paste();

Modified: trunk/src/hotkeys.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/hotkeys.cpp?rev=20655&r1=20654&r2=20655&view=diff
==============================================================================
--- trunk/src/hotkeys.cpp (original)
+++ trunk/src/hotkeys.cpp Sat Sep 22 02:12:41 2007
@@ -109,6 +109,7 @@
        { hotkey::HOTKEY_EDIT_SET_START_POS, "editsetstartpos", N_("Set 
Player's keep"),true },
        { hotkey::HOTKEY_EDIT_FLOOD_FILL, "editfloodfill", N_("Flood 
Fill"),true },
        { hotkey::HOTKEY_EDIT_FILL_SELECTION, "editfillselection", N_("Fill 
Selection"),true },
+       { hotkey::HOTKEY_EDIT_ROTATE_SELECTION, "editrotateselection", 
N_("Rotate Selection"),true },
        { hotkey::HOTKEY_EDIT_CUT, "editcut", N_("Cut"),true },
        { hotkey::HOTKEY_EDIT_COPY, "editcopy", N_("Copy"),true },
        { hotkey::HOTKEY_EDIT_PASTE, "editpaste", N_("Paste"),true },
@@ -677,6 +678,9 @@
                        break;
                 case HOTKEY_EDIT_FILL_SELECTION:
                        edit_fill_selection();
+                       break;
+                case HOTKEY_EDIT_ROTATE_SELECTION:
+                       edit_rotate_selection();
                        break;
                 case HOTKEY_EDIT_CUT:
                        edit_cut();

Modified: trunk/src/hotkeys.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/hotkeys.hpp?rev=20655&r1=20654&r2=20655&view=diff
==============================================================================
--- trunk/src/hotkeys.hpp (original)
+++ trunk/src/hotkeys.hpp Sat Sep 22 02:12:41 2007
@@ -54,7 +54,7 @@
        HOTKEY_EDIT_QUIT, HOTKEY_EDIT_SAVE_MAP,
        HOTKEY_EDIT_SAVE_AS, HOTKEY_EDIT_SET_START_POS,
        HOTKEY_EDIT_NEW_MAP, HOTKEY_EDIT_LOAD_MAP, HOTKEY_EDIT_FLOOD_FILL,
-       HOTKEY_EDIT_FILL_SELECTION, HOTKEY_EDIT_CUT, HOTKEY_EDIT_COPY,
+       HOTKEY_EDIT_FILL_SELECTION, HOTKEY_EDIT_ROTATE_SELECTION, 
HOTKEY_EDIT_CUT, HOTKEY_EDIT_COPY,
        HOTKEY_EDIT_PASTE, HOTKEY_EDIT_REVERT, HOTKEY_EDIT_RESIZE,
        HOTKEY_EDIT_FLIP, HOTKEY_EDIT_SELECT_ALL, HOTKEY_EDIT_DRAW,
        HOTKEY_EDIT_REFRESH, HOTKEY_EDIT_UPDATE, HOTKEY_EDIT_AUTO_UPDATE,
@@ -222,6 +222,7 @@
        virtual void edit_set_start_pos() {}
        virtual void edit_flood_fill() {}
        virtual void edit_fill_selection() {}
+       virtual void edit_rotate_selection() {}
        virtual void edit_cut() {}
        virtual void edit_copy() {}
        virtual void edit_paste() {}




Related Messages


Powered by MHonArc, Updated Sat Sep 22 03:00:46 2007