Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2003:
[Freeciv-Dev] (PR#3529) Map Control patch
Home

[Freeciv-Dev] (PR#3529) Map Control patch

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: arnstein.lindgard@xxxxxxx
Cc:
Subject: [Freeciv-Dev] (PR#3529) Map Control patch
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 2 Mar 2003 01:41:50 -0800
Reply-to: rt@xxxxxxxxxxxxxx

[ali - Wed Feb 26 16:32:22 2003]:

> REQUIRES:         Freeciv-cvs-Feb-25
>                 + Graphics Patch v5 (2 marker sprites needed).
> 
> IS REQUIRED BY:   Mass Orders Patch v5.
>                   Battlegroups Patch v5.
> 
> APPLIES TO:       GTK 1 client
> 
> CONTAINS:
> 
> 1. Area Selection on-map.
> 2. On-map Copy & Paste city production.
> 3. Quickselect units, bypassing popups.
> 4. New access keys.
> 
> The patch loads up mapctrl_common.c, and puts easily
> portable GTK-specifics into mapctrl.c.

This patch contains several largely unrelated features.  It would be
good to separate them into smaller patches that can be handled separately.

One of the small features is the keyboard map scrolling.  A few thoughts
on that:

+void scroll_map(int dir)

This whole function should go into mapctrl_common (this is possible
now).  And the dir parameter should be an enum direction8 instead of an int.

+  gdk_window_get_size(map_canvas->window, &width, &height);

This information can now be accessed through the mapview_canvas variable
(see mapview_common.h).

+  width /= UNIT_TILE_WIDTH;
+  height /= UNIT_TILE_HEIGHT;
+
+  if (is_isometric)  {
+    switch (dir)  {
+      case  DIR8_EAST:  pos_x += width/2;
+                        pos_y -= height/2;
+                        break;
+      case  DIR8_WEST:  pos_x -= width/2;
+                        pos_y += height/2;
+                        break;
+      case  DIR8_NORTH: pos_y -= height/2;
+                        pos_x -= width/2;
+                        break;
+      case  DIR8_SOUTH: pos_y += height/2;
+                        pos_x += width/2;
+                        break;
+    }
+  } else  {
+    switch (dir)  {
+      case  DIR8_EAST:  pos_x += width/2;
+                        break;
+      case  DIR8_WEST:  pos_x -= width/2;
+                        break;
+      case  DIR8_NORTH: pos_y -= height/2;
+                        break;
+      case  DIR8_SOUTH: pos_y += height/2;
+                        break;
+    }
+  }
+  center_tile_mapcanvas(pos_x, pos_y);
+  update_rect_at_mouse_pos();
+}

Seems like this would be more easily done in pixel coordinates. 
Something like:

  get_center_tile_mapcanvas(&map_x, &map_y);
  map_to_canvas_pos(&canvas_x, &canvas_y, map_x, map_y);
  canvas_x += DIR_DX[dir] * mapview_canvas.width / 2;
  canvas_y += DIR_DY[dir] * mapview_canvas.height / 2;
  canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y);
  center_tile_mapcanvas(map_x, map_y);

which will work properly for both iso and non-iso view, and will also
work for non-cardinal directions.  The only drawback is that isometric
scrolling may not be perfectly aligned (but this will be fixed when/if
we get center_pixel_mapcanvas :-).

I'd give feedback on the other features as well, but I think this would
be much easier to do if you'd split the patch up.  Doing that would also
make it easier to provide support for other GUIs (which can be done on a
case-by-case basis, usually easily), and would reduce the number of
patch dependencies that you have (since most features, I think, are
orthogonal).

jason



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