[Freeciv-Dev] (PR#13559) scale supported/present units in citydlg
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13559 >
Per requested that since the city dialog citymap is scaled, the
present/supported units list should be scaled too.
This patch does that by introducing scaling directly into gtkpixcomm.
If the pixcomm is scaled then all drawing operations will be done
scaled. The scaling level is the same as that used for the citymap
itself so everything in the citydlg should be on the same scale.
See http://freeciv.org/~jdorje/citydlg.png (I'll also upload this
screenshot to the ticket).
-jason
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/citydlg.c,v
retrieving revision 1.135
diff -p -u -r1.135 citydlg.c
--- client/gui-gtk-2.0/citydlg.c 26 Jul 2005 16:35:57 -0000 1.135
+++ client/gui-gtk-2.0/citydlg.c 28 Jul 2005 20:08:24 -0000
@@ -61,6 +61,7 @@
#define CITYMAP_WIDTH MIN(300, canvas_width)
#define CITYMAP_HEIGHT (CITYMAP_WIDTH * canvas_height / canvas_width)
+#define CITYMAP_SCALE ((double)CITYMAP_WIDTH / (double)canvas_width)
struct city_dialog;
@@ -1669,7 +1670,11 @@ static void city_dialog_update_supported
gtk_widget_add_events(cmd,
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
- pix = gtk_pixcomm_new(tileset_full_tile_width(tileset), unit_height);
+ pix = gtk_pixcomm_new(CITYMAP_SCALE * tileset_full_tile_width(tileset),
+ CITYMAP_SCALE * unit_height);
+ if (CITYMAP_WIDTH != canvas_width) {
+ gtk_pixcomm_set_scale(GTK_PIXCOMM(pix), CITYMAP_SCALE);
+ }
node.pix = pix;
gtk_container_add(GTK_CONTAINER(cmd), pix);
@@ -1782,7 +1787,11 @@ static void city_dialog_update_present_u
gtk_widget_add_events(cmd,
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
- pix = gtk_pixcomm_new(tileset_full_tile_width(tileset),
tileset_full_tile_height(tileset));
+ pix = gtk_pixcomm_new(CITYMAP_SCALE * tileset_full_tile_width(tileset),
+ CITYMAP_SCALE * tileset_full_tile_height(tileset));
+ if (CITYMAP_WIDTH != canvas_width) {
+ gtk_pixcomm_set_scale(GTK_PIXCOMM(pix), CITYMAP_SCALE);
+ }
node.pix = pix;
gtk_container_add(GTK_CONTAINER(cmd), pix);
Index: client/gui-gtk-2.0/gtkpixcomm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gtkpixcomm.c,v
retrieving revision 1.17
diff -p -u -r1.17 gtkpixcomm.c
--- client/gui-gtk-2.0/gtkpixcomm.c 28 Mar 2005 16:59:14 -0000 1.17
+++ client/gui-gtk-2.0/gtkpixcomm.c 28 Jul 2005 20:08:24 -0000
@@ -145,6 +145,9 @@ gtk_pixcomm_new(gint width, gint height)
p = g_object_new(gtk_pixcomm_get_type(), NULL);
p->w = width; p->h = height;
+ p->is_scaled = FALSE;
+ p->scale = 1.0;
+
p->actions = g_array_new(FALSE, FALSE, sizeof(struct op));
GTK_WIDGET(p)->requisition.width = p->w + GTK_MISC(p)->xpad * 2;
@@ -153,6 +156,25 @@ gtk_pixcomm_new(gint width, gint height)
return GTK_WIDGET(p);
}
+/****************************************************************************
+ Set the scaling on the pixcomm. All operations drawn on the pixcomm
+ (before or after this function is called) will simply be scaled
+ by this amount.
+****************************************************************************/
+void gtk_pixcomm_set_scale(GtkPixcomm *pixcomm, gdouble scale)
+{
+ g_return_if_fail(GTK_IS_PIXCOMM(pixcomm));
+ g_return_if_fail(scale > 0.0);
+
+ if (scale == 1.0) {
+ pixcomm->is_scaled = FALSE;
+ pixcomm->scale = 1.0;
+ } else {
+ pixcomm->is_scaled = TRUE;
+ pixcomm->scale = scale;
+ }
+}
+
static void
refresh(GtkPixcomm *p)
{
@@ -247,7 +269,20 @@ gtk_pixcomm_expose(GtkWidget *widget, Gd
break;
case OP_COPY:
- if (rop->src->pixmap) {
+ if (p->is_scaled) {
+ int w = rop->src->width * p->scale;
+ int h = rop->src->height * p->scale;
+ int ox = rop->x * p->scale + 0.5;
+ int oy = rop->y * p->scale + 0.5;
+ GdkPixbuf *pixbuf = sprite_get_pixbuf(rop->src);
+ GdkPixbuf *scaled
+ = gdk_pixbuf_scale_simple(pixbuf, w, h, GDK_INTERP_BILINEAR);
+
+ gdk_draw_pixbuf(widget->window, civ_gc,
+ scaled, 0, 0, x + ox, y + oy,
+ w, h, GDK_RGB_DITHER_NONE, 0, 0);
+ g_object_unref(scaled);
+ } else if (rop->src->pixmap) {
if (rop->src->mask) {
gdk_gc_set_clip_mask(civ_gc, rop->src->mask);
gdk_gc_set_clip_origin(civ_gc, x + rop->x, y + rop->y);
Index: client/gui-gtk-2.0/gtkpixcomm.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gtkpixcomm.h,v
retrieving revision 1.7
diff -p -u -r1.7 gtkpixcomm.h
--- client/gui-gtk-2.0/gtkpixcomm.h 28 Mar 2005 16:59:14 -0000 1.7
+++ client/gui-gtk-2.0/gtkpixcomm.h 28 Jul 2005 20:08:24 -0000
@@ -55,6 +55,9 @@ struct _GtkPixcomm
gint w, h;
GArray *actions;
+
+ gboolean is_scaled;
+ gdouble scale;
};
struct _GtkPixcommClass
@@ -65,6 +68,7 @@ struct _GtkPixcommClass
GType gtk_pixcomm_get_type (void) G_GNUC_CONST;
GtkWidget *gtk_pixcomm_new (gint width, gint height);
+void gtk_pixcomm_set_scale(GtkPixcomm *pixcomm, gdouble scale);
void gtk_pixcomm_copyto(GtkPixcomm *pixcomm, struct sprite *src,
gint x, gint y);
void gtk_pixcomm_clear (GtkPixcomm *pixcomm);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#13559) scale supported/present units in citydlg,
Jason Short <=
|
|