[Freeciv-Dev] (PR#2708) patch: backing rectangle for city descriptions i
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=2708 >
Here is an updated (now much simpler) patch for the "better" citybar.
-jason
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.211
diff -u -r1.211 mapview_common.c
--- client/mapview_common.c 11 Mar 2005 07:46:01 -0000 1.211
+++ client/mapview_common.c 11 Mar 2005 07:53:04 -0000
@@ -1276,23 +1276,36 @@
city's tile).
****************************************************************************/
static void show_city_desc(struct canvas *pcanvas,
- int canvas_x, int canvas_y,
+ const int canvas_xx, const int canvas_yy,
struct city *pcity, int *width, int *height)
{
+ const bool draw_city_prod = (draw_city_productions
+ && pcity->owner == game.player_idx);
+ const bool multi = (draw_city_prod && draw_city_names);
static char name[512], growth[32], prod[512];
- enum color_std growth_color;
+ enum color_std growth_color, owner_color;
struct {
int x, y, w, h;
} name_rect = {0, 0, 0, 0}, growth_rect = {0, 0, 0, 0},
- prod_rect = {0, 0, 0, 0};
- int extra_width = 0, total_width, total_height;
+ prod_rect = {0, 0, 0, 0};
+ int width1 = 0, width2 = 0, height1 = 0, height2 = 0;
+ struct Sprite *sprite = sprites.mask.worked_tile; /* FIXME */
+ int sprite_w, sprite_h, x, y;
+ const int canvas_x = canvas_xx + NORMAL_TILE_WIDTH / 2;
+ const int canvas_y = canvas_yy + NORMAL_TILE_HEIGHT;
+ const int border = 6;
+ get_sprite_dimensions(sprite, &sprite_w, &sprite_h);
*width = *height = 0;
- canvas_x += NORMAL_TILE_WIDTH / 2;
- canvas_y += NORMAL_TILE_HEIGHT;
+ if (!draw_city_names && !draw_city_prod) {
+ return;
+ }
+ /* First: calculate rect dimensions (but not positioning). */
if (draw_city_names) {
+ int extra_width = 0;
+
get_city_mapview_name_and_growth(pcity, name, sizeof(name),
growth, sizeof(growth), &growth_color);
@@ -1300,38 +1313,83 @@
if (growth[0] != '\0') {
get_text_size(&growth_rect.w, &growth_rect.h, FONT_CITY_PROD, growth);
- /* HACK: put a character's worth of space between the two strings. */
- get_text_size(&extra_width, NULL, FONT_CITY_NAME, "M");
+ extra_width = border;
}
- total_width = name_rect.w + extra_width + growth_rect.w;
- total_height = MAX(name_rect.h, growth_rect.h);
- canvas_put_text(pcanvas,
- canvas_x - total_width / 2, canvas_y,
- FONT_CITY_NAME, COLOR_STD_WHITE, name);
- if (growth[0] != '\0') {
- canvas_put_text(pcanvas,
- canvas_x - total_width / 2 + name_rect.w + extra_width,
- canvas_y + total_height - growth_rect.h,
- FONT_CITY_PROD, growth_color, growth);
- }
- canvas_y += total_height + 3;
-
- *width = MAX(*width, total_width);
- *height += total_height + 3;
+ width1 = name_rect.w + extra_width + growth_rect.w;
+ height1 = MAX(name_rect.h, growth_rect.h);
}
- if (draw_city_productions && pcity->owner == game.player_idx) {
+ if (draw_city_prod) {
get_city_mapview_production(pcity, prod, sizeof(prod));
get_text_size(&prod_rect.w, &prod_rect.h, FONT_CITY_PROD, prod);
- total_width = prod_rect.w;
- total_height = prod_rect.h;
+ width2 = prod_rect.w;
+ height2 = prod_rect.h;
+ }
- canvas_put_text(pcanvas, canvas_x - total_width / 2, canvas_y,
- FONT_CITY_PROD, COLOR_STD_WHITE, prod);
+ *width = MAX(width1, width2) + border;
+ *height = border + height1 + height2 + (multi ? border : 0);
- canvas_y += total_height;
- *width = MAX(*width, total_width);
- *height += total_height;
+ /* Next fill in X and Y locations. */
+ if (draw_city_names) {
+ int growth_w = 0;
+
+ if (growth[0] != '\0') {
+ growth_rect.x
+ = canvas_x + (MAX(width1, width2) + 1) / 2 - growth_rect.w;
+ growth_rect.y = canvas_y + border / 2 + (height1 - growth_rect.h) / 2;
+ growth_w = growth_rect.w + border;
+ }
+
+ name_rect.x = canvas_x - (name_rect.w + growth_w) / 2;
+ name_rect.y = canvas_y + border / 2;
+ }
+ if (draw_city_prod) {
+ prod_rect.x = canvas_x - width2 / 2;
+ prod_rect.y = canvas_y + border / 2
+ + (draw_city_names ? border + height1 : 0);
+ }
+
+ /* Now draw. */
+ for (x = 0; x < *width; x += sprite_w) {
+ for (y = 0; y < *height; y += sprite_h) {
+ canvas_put_sprite(pcanvas, canvas_x - *width / 2 + x,
+ canvas_y + y,
+ sprite,
+ 0, 0, *width - x, *height - y);
+ }
+ }
+ owner_color = player_color(city_owner(pcity));
+ canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
+ canvas_x - *width / 2, canvas_y,
+ *width, 0);
+ canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
+ canvas_x - *width / 2, canvas_y,
+ 0, *height);
+ canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
+ canvas_x - *width / 2, canvas_y + *height,
+ *width, 0);
+ canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
+ canvas_x - *width / 2 + *width, canvas_y,
+ 0, *height);
+ if (draw_city_names) {
+ canvas_put_text(pcanvas, name_rect.x, name_rect.y,
+ FONT_CITY_NAME, COLOR_STD_WHITE, name);
+ if (growth[0] != '\0') {
+ canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
+ growth_rect.x - border / 2, canvas_y,
+ 0, height1 + border);
+ canvas_put_text(pcanvas, growth_rect.x, growth_rect.y,
+ FONT_CITY_PROD, growth_color, growth);
+ }
+ }
+ if (draw_city_prod) {
+ if (draw_city_names) {
+ canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
+ canvas_x - *width / 2, canvas_y + height1 + border,
+ *width, 0);
+ }
+ canvas_put_text(pcanvas, prod_rect.x, prod_rect.y,
+ FONT_CITY_PROD, COLOR_STD_WHITE, prod);
}
}
@@ -1367,7 +1425,7 @@
*/
gui_rect_iterate(mapview.gui_x0 + canvas_x - dx / 2,
mapview.gui_y0 + canvas_y - dy,
- width + dx, height + dy - NORMAL_TILE_HEIGHT,
+ width + dx, height + dy,
ptile, pedge, pcorner, gui_x, gui_y) {
const int canvas_x = gui_x - mapview.gui_x0;
const int canvas_y = gui_y - mapview.gui_y0;
- [Freeciv-Dev] Re: (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, (continued)
- [Freeciv-Dev] Re: (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, Per I. Mathisen, 2005/03/09
- [Freeciv-Dev] Re: (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, Jason Short, 2005/03/09
- [Freeciv-Dev] Re: (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, Jason Short, 2005/03/09
- [Freeciv-Dev] Re: (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, Per I. Mathisen, 2005/03/10
- [Freeciv-Dev] Re: (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, Christian Knoke, 2005/03/10
- [Freeciv-Dev] (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, Guest, 2005/03/10
- [Freeciv-Dev] (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, Guest, 2005/03/10
- [Freeciv-Dev] Re: (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, Christian Knoke, 2005/03/10
- [Freeciv-Dev] (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, Guest, 2005/03/10
- [Freeciv-Dev] Re: (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, Christian Knoke, 2005/03/10
- [Freeciv-Dev] (PR#2708) patch: backing rectangle for city descriptions in gtk2 client,
Jason Short <=
- [Freeciv-Dev] Re: (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, Jason Short, 2005/03/13
- [Freeciv-Dev] (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, Jason Short, 2005/03/19
- [Freeciv-Dev] (PR#2708) patch: backing rectangle for city descriptions in gtk2 client, Jason Short, 2005/03/31
|
|