Author: martinxyz
Date: Sat Apr 21 09:17:51 2007
New Revision: 16949

URL: http://svn.gna.org/viewcvs/wesnoth?rev=16949&view=rev
Log:
Scrolling review:
* fights should now always be fully on-screen (before, only the rectangle
  between the upper left corners was moved on-screen)
* checking map bounds before scrolling now: if the scrolling speed is
  set slow(!) enough, there will be no more direction changes
* center the tile center instead of the tile upper left bbox corner

Modified:
    trunk/changelog
    trunk/src/display.cpp
    trunk/src/display.hpp

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=16949&r1=16948&r2=16949&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Sat Apr 21 09:17:51 2007
@@ -42,6 +42,7 @@
      * added animated windmill, fancy and damaged tents, icepack, and shipwreck
    * fix problems with colour cursor in fullscreen (slow speed, bug #7555 and 
bug #6052).
    * new color cursors
+   * fixed some scrolling corner cases (eg. fights happening partially 
offscreen)
  * sound
    * new or improved sounds: hatchet
    * sounds for user interface events

Modified: trunk/src/display.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.cpp?rev=16949&r1=16948&r2=16949&view=diff
==============================================================================
--- trunk/src/display.cpp (original)
+++ trunk/src/display.cpp Sat Apr 21 09:17:51 2007
@@ -557,34 +557,54 @@
                return;
        }
 
-       const int xpos = get_location_x(loc);
-       const int ypos = get_location_y(loc);
-       if ((scroll_type == ONSCREEN) && !outside_area(map_area(),xpos,ypos)) {
+       // current position of target (upper left tile corner) in screen 
coordinates
+       const int screenxpos = get_location_x(loc);
+       const int screenypos = get_location_y(loc);
+
+       if (scroll_type == ONSCREEN) {
+               // the tile must be fully visible
+               SDL_Rect r = map_area();
+               r.w -= hex_width();
+               r.h -= zoom_;
+
+               if (!outside_area(r,screenxpos,screenypos)) {
+                       return;
+               }
+       }
+
+       const SDL_Rect area = map_area();
+       const int xmove_expected = (screenxpos + hex_width()/2) - (area.x + 
area.w/2 - zoom_/2);
+       const int ymove_expected = (screenypos + zoom_/2)       - (area.y + 
area.h/2 - zoom_/2);
+
+       int xpos = xpos_ + xmove_expected;
+       int ypos = ypos_ + ymove_expected;
+       bounds_check_position(xpos, ypos);
+       int xmove = xpos - xpos_;
+       int ymove = ypos - ypos_;
+
+       const int speed = preferences::scroll_speed()*2;
+       
+       int num_moves = (int)hypot(xmove, ymove)/speed;
+
+       if(scroll_type == WARP || turbo() || num_moves == 0) {
+               scroll(xmove,ymove);
+               draw();
                return;
        }
 
-       const int speed = preferences::scroll_speed()*2;
-
-       const SDL_Rect& area = map_area();
-       const int desiredxpos = area.w/2 - zoom_/2;
-       const int desiredypos = area.h/2 - zoom_/2;
-
-       const int xmove = xpos - desiredxpos;
-       const int ymove = ypos - desiredypos;
-
-       int num_moves = (abs(xmove) > abs(ymove) ? abs(xmove):abs(ymove))/speed;
-
-       if(scroll_type == WARP || turbo() || num_moves == 0) {
-               num_moves = 1;
-       }
-
-       for(int i = 0; i != num_moves; ++i) {
+       while (num_moves > 0) {
                events::pump();
 
-               scroll(xmove/num_moves,ymove/num_moves);
+               int dx = xmove / num_moves;
+               int dy = ymove / num_moves;
+
+               scroll(dx, dy);
+               xmove -= dx;
+               ymove -= dy;
+               num_moves--;
 
                //accelerate scroll rate if either shift key is held down
-               if((i%4) != 0 && i != num_moves-1 && turbo()) {
+               if((num_moves%4) != 0 && num_moves != 0 && turbo()) {
                        continue;
                }
 
@@ -602,9 +622,9 @@
        const int ypos2 = get_location_y(loc2);;
 
        const int minx = minimum<int>(xpos1,xpos2);
-       const int maxx = maximum<int>(xpos1,xpos2);
+       const int maxx = maximum<int>(xpos1,xpos2) + hex_width();
        const int miny = minimum<int>(ypos1,ypos2);
-       const int maxy = maximum<int>(ypos1,ypos2);
+       const int maxy = maximum<int>(ypos1,ypos2) + zoom_;
        const int diffx = maxx - minx;
        const int diffy = maxy - miny;
 
@@ -652,29 +672,34 @@
                zoom_ = MaxZoom;
        }
 
+       bounds_check_position(xpos_, ypos_);
+
+       if(zoom_ != orig_zoom) {
+               image::set_zoom(zoom_);
+       }
+}
+
+void display::bounds_check_position(int& xpos, int& ypos)
+{
        const int tile_width = hex_width();
 
        const int xend = tile_width*map_.x() + tile_width/3;
        const int yend = zoom_*map_.y() + zoom_/2;
 
-       if(xpos_ > xend - map_area().w) {
-               xpos_ = xend - map_area().w;
-       }
-
-       if(ypos_ > yend - map_area().h) {
-               ypos_ = yend - map_area().h;
-       }
-
-       if(xpos_ < 0) {
-               xpos_ = 0;
-       }
-
-       if(ypos_ < 0) {
-               ypos_ = 0;
-       }
-
-       if(zoom_ != orig_zoom) {
-               image::set_zoom(zoom_);
+       if(xpos > xend - map_area().w) {
+               xpos = xend - map_area().w;
+       }
+
+       if(ypos > yend - map_area().h) {
+               ypos = yend - map_area().h;
+       }
+
+       if(xpos < 0) {
+               xpos = 0;
+       }
+
+       if(ypos < 0) {
+               ypos = 0;
        }
 }
 

Modified: trunk/src/display.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.hpp?rev=16949&r1=16948&r2=16949&view=diff
==============================================================================
--- trunk/src/display.hpp (original)
+++ trunk/src/display.hpp Sat Apr 21 09:17:51 2007
@@ -433,6 +433,7 @@
        reports::report reports_[reports::NUM_REPORTS];
 
        void bounds_check_position();
+       void bounds_check_position(int& xpos, int& ypos);
 
        // std::vector<surface> getAdjacentTerrain(int x, int y, image::TYPE 
type, ADJACENT_TERRAIN_TYPE terrain_type);
        std::vector<surface> get_terrain_images(int x, int y, image::TYPE type, 
ADJACENT_TERRAIN_TYPE terrain_type);


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

Reply via email to