[Freeciv-Dev] (PR#8973) build citydlg canvas sizes on demand
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] (PR#8973) build citydlg canvas sizes on demand |
From: |
"Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx> |
Date: |
Mon, 14 Jun 2004 18:04:59 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8973 >
> [jdorje - Sun Jun 13 07:49:11 2004]:
>
> This is a preliminary patch to determine the citydlg size at runtime.
And here's an updated patch. This one should be ready.
jason
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.36
diff -u -r1.36 citydlg_common.c
--- client/citydlg_common.c 13 Jun 2004 16:53:34 -0000 1.36
+++ client/citydlg_common.c 15 Jun 2004 01:04:31 -0000
@@ -31,16 +31,14 @@
#include "options.h" /* for concise_city_production */
#include "tilespec.h" /* for is_isometric */
+static int citydlg_width, citydlg_height;
+
/**************************************************************************
Return the width of the city dialog canvas.
**************************************************************************/
int get_citydlg_canvas_width(void)
{
- if (is_isometric) {
- return (CITY_MAP_SIZE - 1) * NORMAL_TILE_WIDTH;
- } else {
- return CITY_MAP_SIZE * NORMAL_TILE_WIDTH;
- }
+ return citydlg_width;
}
/**************************************************************************
@@ -48,11 +46,32 @@
**************************************************************************/
int get_citydlg_canvas_height(void)
{
- if (is_isometric) {
- return (CITY_MAP_SIZE - 1) * NORMAL_TILE_HEIGHT;
- } else {
- return CITY_MAP_SIZE * NORMAL_TILE_HEIGHT;
- }
+ return citydlg_height;
+}
+
+/**************************************************************************
+ Calculate the citydlg width and height.
+**************************************************************************/
+void generate_citydlg_dimensions(void)
+{
+ int min_x = 0, max_x = 0, min_y = 0, max_y = 0;
+
+ citydlg_width = citydlg_height = 0;
+ city_map_iterate(city_x, city_y) {
+ int canvas_x, canvas_y;
+
+ if (!city_to_canvas_pos(&canvas_x, &canvas_y, city_x, city_y)) {
+ assert(0);
+ }
+
+ min_x = MIN(canvas_x, min_x);
+ max_x = MAX(canvas_x, max_x);
+ min_y = MIN(canvas_y, min_y);
+ max_y = MAX(canvas_y, max_y);
+ } city_map_iterate_end;
+
+ citydlg_width = max_x - min_x + NORMAL_TILE_WIDTH;
+ citydlg_height = max_y - min_y + NORMAL_TILE_HEIGHT;
}
/**************************************************************************
@@ -83,27 +102,33 @@
bool canvas_to_city_pos(int *city_x, int *city_y, int canvas_x, int canvas_y)
{
int orig_canvas_x = canvas_x, orig_canvas_y = canvas_y;
+ const int width = get_citydlg_canvas_width();
+ const int height = get_citydlg_canvas_height();
+
+ canvas_x -= (width - NORMAL_TILE_WIDTH) / 2;
+ canvas_y -= (height - NORMAL_TILE_HEIGHT) / 2;
if (is_isometric) {
const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
- /* Shift the tile right so the top corner of tile (-2,2) is at
+ /* Shift the tile left so the top corner of the origin tile is at
canvas position (0,0). */
- canvas_y += H / 2;
+ canvas_x -= W / 2;
/* Perform a pi/4 rotation, with scaling. See canvas_pos_to_map_pos
for a full explanation. */
*city_x = DIVIDE(canvas_x * H + canvas_y * W, W * H);
*city_y = DIVIDE(canvas_y * W - canvas_x * H, W * H);
-
- /* Add on the offset of the top-left corner to get the final
- * coordinates (like in canvas_to_map_pos). */
- *city_x -= CITY_MAP_RADIUS;
- *city_y += CITY_MAP_RADIUS;
} else {
- *city_x = canvas_x / NORMAL_TILE_WIDTH;
- *city_y = canvas_y / NORMAL_TILE_HEIGHT;
+ *city_x = DIVIDE(canvas_x, NORMAL_TILE_WIDTH);
+ *city_y = DIVIDE(canvas_y, NORMAL_TILE_HEIGHT);
}
+
+ /* Add on the offset of the top-left corner to get the final
+ * coordinates (like in canvas_to_map_pos). */
+ *city_x += CITY_MAP_RADIUS;
+ *city_y += CITY_MAP_RADIUS;
+
freelog(LOG_DEBUG, "canvas_to_city_pos(pos=(%d,%d))=(%d,%d)",
orig_canvas_x, orig_canvas_y, *city_x, *city_y);
Index: client/citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.20
diff -u -r1.20 citydlg_common.h
--- client/citydlg_common.h 4 Apr 2004 14:49:10 -0000 1.20
+++ client/citydlg_common.h 15 Jun 2004 01:04:31 -0000
@@ -36,6 +36,7 @@
int get_citydlg_canvas_width(void);
int get_citydlg_canvas_height(void);
+void generate_citydlg_dimensions(void);
bool city_to_canvas_pos(int *canvas_x, int *canvas_y,
int city_x, int city_y);
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.380
diff -u -r1.380 packhand.c
--- client/packhand.c 12 Jun 2004 17:42:27 -0000 1.380
+++ client/packhand.c 15 Jun 2004 01:04:31 -0000
@@ -1318,6 +1318,8 @@
map_allocate();
init_client_goto();
+ generate_citydlg_dimensions();
+
set_overview_dimensions(map.xsize, map.ysize);
}
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.174
diff -u -r1.174 tilespec.c
--- client/tilespec.c 6 Jun 2004 06:09:46 -0000 1.174
+++ client/tilespec.c 15 Jun 2004 01:04:32 -0000
@@ -419,6 +419,7 @@
we don't want/need to redraw. */
return;
}
+ generate_citydlg_dimensions();
tileset_changed();
center_tile_mapcanvas(center_x, center_y);
}
|
|