wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src unit_display.cpp


From: Guillaume Melquiond
Subject: [Wesnoth-cvs-commits] wesnoth/src unit_display.cpp
Date: Sat, 18 Sep 2004 07:01:01 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Guillaume Melquiond <address@hidden>    04/09/18 10:40:29

Modified files:
        src            : unit_display.cpp 

Log message:
        Factor and cleanup map-follow-unit code

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_display.cpp.diff?tr1=1.31&tr2=1.32&r1=text&r2=text

Patches:
Index: wesnoth/src/unit_display.cpp
diff -u wesnoth/src/unit_display.cpp:1.31 wesnoth/src/unit_display.cpp:1.32
--- wesnoth/src/unit_display.cpp:1.31   Sat Sep 18 10:06:57 2004
+++ wesnoth/src/unit_display.cpp        Sat Sep 18 10:40:29 2004
@@ -13,6 +13,28 @@
 namespace
 {
 
+// ensure the map position is sufficiently centered on the acting rectangle
+void adjust_map_position(display& disp, int x, int y, int w, int h)
+{
+       const int side_threshold = 80;
+       int border;
+       SDL_Rect area = disp.map_area();
+
+       border = area.x + side_threshold;
+       if (x < border) disp.scroll(x - border, 0);
+
+       border = area.y + side_threshold;
+       if (y < border) disp.scroll(0, y - border);
+
+       x += w;
+       border = area.x + area.w - side_threshold;
+       if (x > border) disp.scroll(x - border, 0);
+
+       y += h;
+       border = area.y + area.h - side_threshold;
+       if (y > border) disp.scroll(0, y - border);
+}
+
 void move_unit_between(display& disp, const gamemap& map, const 
gamemap::location& a, const gamemap::location& b, const unit& u)
 {
        if(disp.update_locked() || disp.fogged(a.x,a.y) && 
disp.fogged(b.x,b.y)) {
@@ -21,8 +43,6 @@
 
        const bool face_left = u.facing_left();
 
-       const int side_threshhold = 80;
-
        int xsrc = disp.get_location_x(a);
        int ysrc = disp.get_location_y(a);
        int xdst = disp.get_location_x(b);
@@ -79,21 +99,7 @@
                //we try to scroll the map if the unit is at the edge.
                //keep track of the old position, and if the map moves at all,
                //then recenter it on the unit
-               if(xloc < side_threshhold) {
-                       disp.scroll(xloc - side_threshhold,0);
-               }
-
-               if(yloc < side_threshhold) {
-                       disp.scroll(0,yloc - side_threshhold);
-               }
-
-               if(xloc + double(image->w) > disp.mapx() - side_threshhold) {
-                       disp.scroll(((xloc + image->w) - (disp.mapx() - 
side_threshhold)),0);
-               }
-
-               if(yloc + double(image->h) > disp.y() - side_threshhold) {
-                       disp.scroll(0,((yloc + image->h) - (disp.y() - 
side_threshhold)));
-               }
+               adjust_map_position(disp, xloc, yloc, image->w, image->h);
 
                if(xsrc != disp.get_location_x(a) || ysrc != 
disp.get_location_y(a)) {
                        disp.scroll_to_tile(b.x,b.y,display::WARP);
@@ -117,8 +123,8 @@
                const int height_adjust = src_height_adjust + 
(dst_height_adjust-src_height_adjust)*(i/nsteps);
                const double submerge = src_submerge + 
(dst_submerge-src_submerge)*(double(i)/double(nsteps));
 
-               const int xpos = static_cast<int>(xloc);
-               const int ypos = static_cast<int>(yloc) - height_adjust;
+               const int xpos = xloc;
+               const int ypos = yloc - height_adjust;
 
                // disp.invalidate_animations();
                disp.draw(false);
@@ -539,8 +545,6 @@
                          || preferences::show_combat() == false;
 
        if(!hide) {
-               const int side_threshhold = 80;
-
                int xloc = disp.get_location_x(a);
                int yloc = disp.get_location_y(a);
 
@@ -549,21 +553,7 @@
                //we try to scroll the map if the unit is at the edge.
                //keep track of the old position, and if the map moves at all,
                //then recenter it on the unit
-               if(xloc < area.x + side_threshhold) {
-                       disp.scroll(xloc - side_threshhold - 
disp.map_area().x,0);
-               }
-
-               if(yloc < area.y + side_threshhold) {
-                       disp.scroll(0,yloc - side_threshhold - area.y);
-               }
-
-               if(xloc + disp.hex_size() > area.x + area.w - side_threshhold) {
-                       disp.scroll(((xloc + disp.hex_size()) - (area.x + 
area.w - side_threshhold)),0);
-               }
-
-               if(yloc + disp.hex_size() > area.y + area.h - side_threshhold) {
-                       disp.scroll(0,((yloc + disp.hex_size()) - (area.y + 
area.h - side_threshhold)));
-               }
+               adjust_map_position(disp, xloc, yloc, disp.hex_size(), 
disp.hex_size());
 
                if(xloc != disp.get_location_x(a) || yloc != 
disp.get_location_y(a)) {
                        disp.scroll_to_tile(a.x,a.y,display::WARP);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]