Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2004:
[Freeciv-Dev] Re: (PR#8299) wrapping GUI coordinates
Home

[Freeciv-Dev] Re: (PR#8299) wrapping GUI coordinates

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#8299) wrapping GUI coordinates
From: "rwetmore@xxxxxxxxxxxx" <rwetmore@xxxxxxxxxxxx>
Date: Thu, 25 Mar 2004 19:54:01 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8299 >


Jason Short wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=8299 >
> 
> rwetmore@xxxxxxxxxxxx wrote:
[...]
>>It is likely to be the most extensible for doing odd GUI stuff, and
>>the most robust (single source wrapping code never touched).
> 
> It may be the most robust but it is not the most extensible.

Why not? What blocks do you see against extensibility?

[...]
> There are at least two other GUI topology problems.
> 
> 1.  The overview viewrect is inaccurate.  If you play an iso-map with 
> iso-view and scroll to the left, the viewrect will zig-zag.  Pretty 

Problem thoroughly understood and native bugfix is trivial. Why haven't
you applied it?

> mediocre.  However we can preserve pixel granularity with the following 
> operation:
> 
>    int gui_to_overview_pos(*ovr_x, *ovr_y, gui_x, gui_y)
>    {
>      int guinat_x, guinat_y;
>      const int size = NORMAL_TILE_WIDTH * NORMAL_TILE_HEIGHT;
> 
>      gui_to_guinat_x(&guinat_x, &guinat_y, gui_x, gui_y);
>      *ovr_x = guinat_x * OVERVIEW_TILE_WIDTH / size;
>      *ovr_y = guinat_y * OVERVIEW_TILE_HEIGHT / size;
>    }
> 
> AFAICT there is no way to achieve a similar result without the use of 
> gui-native position.  This is the reason I said in my second e-mail that 
> I prefered the gui-native solution.

I don't know what you are saying here or what your problem is. What
are you trying to do that is so stuffed up it has to be done in one
way only?

> 2.  With a sliding mapview (see PR#8210) we need a gui_distance_vector 
> function.  This can be implemented via gui-native coordinates or via a 
> conversion to map coordinates.  The former is nearly identical to 
> map_distance_vector:

What is a gui_distance vector used for? At what granularity does it
measure? Why?  Maybe the example will clarify what concept is not
clear or being overloaded incorrectly.

Gui coordinates should only be used in the mapview windows which are
fixed FlatEarth rectangles with no wraps. A backing store is drawn
into a similar but not necessarily the same sized rectangle depending
on how you want to cache extra tiles around the current view to limit
the number of backing store redraws. The full 3x3 map space is an
upper bound on how big this FlatEarth would ever be.

>    int gui_distance_vector(*dx, *dy, gui_x0, gui_y0, gui_x1, gui_y1)
>    {
>      const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
>      const int xsize = map.xsize * W * H, ysize = map.ysize * W * H;
> 
>      gui_to_guinat_pos(&gui_x0, &gui_y0, gui_x0, gui_y0);
>      gui_to_guinat_pos(&gui_x1, &gui_y1, gui_x1, gui_y1);
> 
>      /* Find the native distance vector. */
>      *dx = gui_x1 - gui_x0;
>      *dy = gui_y1 - gui_y0;
>      if (topo_has_flag(TF_WRAPX)) {
>        *dx = FC_WRAP(*dx + xsize / 2, xsize) - xsize / 2;
>      }
>      if (topo_has_flag(TF_WRAPY)) {
>        *dy = FC_WRAP(*dy + ysize / 2, ysize) - ysize / 2;
>      }
> 
>      gui_x1 = gui_x0 + *dx;
>      gui_y1 = gui_y0 + *dy;
>      guinat_to_gui_pos(&gui_x0, &gui_y0, gui_x0, gui_y0);
>      guinat_to_gui_pos(&gui_x1, &gui_y1, gui_x1, gui_y1);
> 
>      *dx = gui_x1 - gui_x0;
>      *dy = gui_y1 - gui_y0;
>    }
> 
> while the latter is uglier on its own but doesn't require gui-native 
> positions.  It may also be inaccurate by very small (half-tile) amounts:
> 
>    /* Similar to conversion in map_to_gui_pos.  This function has other
>     * users; see move_unit_map_canvas. */
>    int map_to_gui_vector(*gui_dx, *gui_dy, map_dx, map_dy)
>    {
>      if (is_isometric) {
>        *gui_dx = (map_dx - map_dy) * NORMAL_TILE_WIDTH / 2;
>        *gui_dy = (map_dx + map_dy) * NORMAL_TILE_HEIGHT / 2;
>      } else {
>        *gui_dx = map_dx * NORMAL_TILE_HEIGHT;
>        *gui_dy = map_dy * NORMAL_TILE_WIDTH;
>      }
>    }
> 
>    int gui_distance_vector(*dx, *dy, gui_x0, gui_y0, gui_x1, gui_y1)
>    {
>      int map_x0, map_y0, map_dx0, map_dy0;
>      int map_x1, map_y1, map_dx1, map_dy1;
>      int gui_x, gui_y, map_dx, map_dy;
> 
>      gui_to_map_pos(&map_x0, &map_y0, gui_x0, gui_y0);
>      map_to_gui_pos(&gui_x, &gui_y, map_x0, map_y0);
>      map_dx0 = gui_x0 - gui_x;
>      map_dy0 = gui_y0 - gui_y;
> 
>      gui_to_map_pos(&map_x1, &map_y1, gui_x1, gui_y1);
>      map_to_gui_pos(&gui_x, &gui_y, map_x1, map_y1);
>      map_dx1 = gui_x1 - gui_x;
>      map_dy1 = gui_y1 - gui_y;
> 
>      map_distance_vector(&map_dx, &map_dy,
>                          map_x0, map_y0, map_x1, map_y1);
>      map_to_gui_vector(dx, dy, map_dx, map_dy);
>      *dx += (map_dx1 - map_dx0);
>      *dy += (map_dy1 - map_dy0);
>    }
> 
> jason

Cheers,
RossW
=====




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