Commit 66608b0e authored by Colomban Wendling's avatar Colomban Wendling
Browse files

GTK client: bring procedural tiles back (not complete yet)

Procedural tiles are still disabled by default and misses some details,
but the basics are back.
parent c92bebae
......@@ -144,7 +144,27 @@ load_tile (OVCCTileID id)
return pixbuf;
}
#if 0
static void
draw_polygon (GdkDrawable *d,
GdkGC *gc,
gboolean fill,
gdouble scale,
const GdkPoint *points,
gint n_points)
{
static GdkPoint pts[4] = {0};
gint i;
g_return_if_fail (n_points <= G_N_ELEMENTS (pts));
for (i = 0; i < n_points; i++) {
pts[i].x = (gint)(points[i].x * scale);
pts[i].y = (gint)(points[i].y * scale);
}
gdk_draw_polygon (d, gc, fill, pts, n_points);
}
static GdkPixbuf *
tile_get_procedural (const OVCCTile *tile,
gint size)
......@@ -152,119 +172,79 @@ tile_get_procedural (const OVCCTile *tile,
GdkColormap *colormap;
GdkPixbuf *pixbuf;
GdkPixmap *pixmap;
OVCCTileSide *side;
GdkPoint points[3];
GdkPoint points_sub[3];
GdkGC *gc;
GdkGC *gc_sub;
GdkColor city = { 0, 52428, 0, 0 };
GdkColor field = { 0, 29555, 53970, 5654 };
GdkColor path = { 0, 49601, 32125, 4369 };
GdkColor monastery = { 0, 60606, 54484, 0 };
GdkColor unknown = { 0, 11822, 13364, 13878 };
GdkColor background = { 0, 47802, 48573, 46774 };
gint i = 0;
GdkPoint points_top_left[] = { { 0, 0 }, { 1, 0 }, { 1, 1 } };
GdkPoint points_top_center[] = { { 1, 0 }, { 2, 0 }, { 2, 1 }, { 1, 1 } };
GdkPoint points_top_right[] = { { 2, 0 }, { 3, 0 }, { 2, 1 } };
GdkPoint points_right_left[] = { { 3, 0 }, { 3, 1 }, { 2, 1 } };
GdkPoint points_right_center[] = { { 3, 1 }, { 3, 2 }, { 2, 2 }, { 2, 1 } };
GdkPoint points_right_right[] = { { 3, 2 }, { 3, 3 }, { 2, 2 } };
GdkPoint points_bottom_left[] = { { 2, 3 }, { 3, 3 }, { 2, 2 } };
GdkPoint points_bottom_center[] = { { 1, 3 }, { 2, 3 }, { 2, 2 }, { 1, 2 } };
GdkPoint points_bottom_right[] = { { 0, 3 }, { 1, 3 }, { 1, 2 } };
GdkPoint points_left_left[] = { { 0, 3 }, { 0, 2 }, { 1, 2 } };
GdkPoint points_left_center[] = { { 0, 2 }, { 0, 1 }, { 1, 1 }, { 1, 2 } };
GdkPoint points_left_right[] = { { 0, 1 }, { 0, 0 }, { 1, 1 } };
GSList *objects;
colormap = gdk_colormap_get_system ();
pixmap = gdk_pixmap_new (NULL, size, size,
gdk_colormap_get_visual (colormap)->depth);
gc = gdk_gc_new (GDK_DRAWABLE (pixmap));
gc_sub = gdk_gc_new (GDK_DRAWABLE (pixmap));
/*gdk_gc_set_line_attributes (gc, 3, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL);*/
for (i = 0; i < OVCC_TILE_SIDE_NUM; i++) {
side = ovcc_tile_get_side (tile, i);
switch (i) {
case OVCC_TILE_SIDE_POS_LEFT:
points[0].x = 0;
points[0].y = 0;
points[1].x = 0;
points[1].y = size;
points[2].x = size / 2;
points[2].y = size / 2;
points_sub[0].x = 0;
points_sub[0].y = size/3;
points_sub[1].x = 0;
points_sub[1].y = 2*(size/3);
points_sub[2].x = size / 2;
points_sub[2].y = size / 2;
break;
case OVCC_TILE_SIDE_POS_TOP:
points[0].x = 0;
points[0].y = 0;
points[1].x = size;
points[1].y = 0;
points[2].x = size / 2;
points[2].y = size / 2;
points_sub[0].x = size/3;
points_sub[0].y = 0;
points_sub[1].x = 2*(size/3);
points_sub[1].y = 0;
points_sub[2].x = size / 2;
points_sub[2].y = size / 2;
break;
case OVCC_TILE_SIDE_POS_RIGHT:
points[0].x = size;
points[0].y = 0;
points[1].x = size;
points[1].y = size;
points[2].x = size / 2;
points[2].y = size / 2;
points_sub[0].x = size;
points_sub[0].y = size/3;
points_sub[1].x = size;
points_sub[1].y = 2*(size/3);
points_sub[2].x = size / 2;
points_sub[2].y = size / 2;
break;
case OVCC_TILE_SIDE_POS_BOTTOM:
points[0].x = 0;
points[0].y = size;
points[1].x = size;
points[1].y = size;
points[2].x = size / 2;
points[2].y = size / 2;
points_sub[0].x = size/3;
points_sub[0].y = size;
points_sub[1].x = 2*(size/3);
points_sub[1].y = size;
points_sub[2].x = size / 2;
points_sub[2].y = size / 2;
break;
}
switch (ovcc_tile_side_get_content_type (side)) {
case OVCC_TILE_CONTENT_TYPE_CITY: gdk_gc_set_rgb_fg_color (gc, &city);
gdk_gc_set_rgb_fg_color (gc_sub, &city); break;
case OVCC_TILE_CONTENT_TYPE_FIELD: gdk_gc_set_rgb_fg_color (gc, &field);
gdk_gc_set_rgb_fg_color (gc_sub, &field); break;
case OVCC_TILE_CONTENT_TYPE_PATH: gdk_gc_set_rgb_fg_color (gc, &path);
gdk_gc_set_rgb_fg_color (gc_sub, &field); break;
default: gdk_gc_set_rgb_fg_color (gc, &unknown);
gdk_gc_set_rgb_fg_color (gc_sub, &unknown);
/* fill with BG */
gdk_gc_set_rgb_fg_color (gc, &background);
gdk_draw_rectangle (GDK_DRAWABLE (pixmap), gc, TRUE, 0, 0, size, size);
/* draw object links */
/* FIXME: objects without links are not rendered yet */
/* FIXME: links themselves are not rendered yet, only sides */
for (objects = ovcc_tile_get_objects (tile); objects; objects = objects->next) {
OVCCTileObject *obj = objects->data;
OVCCTileObjectLinks links = ovcc_tile_object_get_links (obj);
switch (ovcc_tile_object_get_otype (obj)) {
case OVCC_TILE_OBJECT_TYPE_CITY: gdk_gc_set_rgb_fg_color (gc, &city); break;
case OVCC_TILE_OBJECT_TYPE_FIELD: gdk_gc_set_rgb_fg_color (gc, &field); break;
case OVCC_TILE_OBJECT_TYPE_PATH: gdk_gc_set_rgb_fg_color (gc, &path); break;
case OVCC_TILE_OBJECT_TYPE_MONASTERY: gdk_gc_set_rgb_fg_color (gc, &monastery); break;
default: gdk_gc_set_rgb_fg_color (gc, &unknown);
}
gdk_draw_polygon (GDK_DRAWABLE (pixmap), gc_sub, TRUE,
points, G_N_ELEMENTS (points));
gdk_draw_polygon (GDK_DRAWABLE (pixmap), gc, TRUE,
points_sub, G_N_ELEMENTS (points_sub));
gdk_gc_set_rgb_fg_color (gc, &background);
gdk_draw_rectangle (GDK_DRAWABLE (pixmap), gc, TRUE,
size/4, size/4, size/2, size/2);
}
if (ovcc_tile_get_center_type (tile) == OVCC_TILE_CONTENT_TYPE_MONASTERY) {
gdk_gc_set_rgb_fg_color (gc, &monastery);
gdk_draw_arc (GDK_DRAWABLE (pixmap), gc, TRUE,
size / 3, size / 3, size / 3, size / 3, 0, 64 * 360);
#define HANDLE_LINK(l, p) \
G_STMT_START { if (links & l) { \
draw_polygon (GDK_DRAWABLE (pixmap), gc, TRUE, (size / 3.0), p, G_N_ELEMENTS (p)); \
} } G_STMT_END
HANDLE_LINK (OVCC_TILE_OBJECT_LINKS_TOP_LEFT, points_top_left);
HANDLE_LINK (OVCC_TILE_OBJECT_LINKS_TOP_CENTER, points_top_center);
HANDLE_LINK (OVCC_TILE_OBJECT_LINKS_TOP_RIGHT, points_top_right);
HANDLE_LINK (OVCC_TILE_OBJECT_LINKS_RIGHT_LEFT, points_right_left);
HANDLE_LINK (OVCC_TILE_OBJECT_LINKS_RIGHT_CENTER, points_right_center);
HANDLE_LINK (OVCC_TILE_OBJECT_LINKS_RIGHT_RIGHT, points_right_right);
HANDLE_LINK (OVCC_TILE_OBJECT_LINKS_BOTTOM_LEFT, points_bottom_left);
HANDLE_LINK (OVCC_TILE_OBJECT_LINKS_BOTTOM_CENTER, points_bottom_center);
HANDLE_LINK (OVCC_TILE_OBJECT_LINKS_BOTTOM_RIGHT, points_bottom_right);
HANDLE_LINK (OVCC_TILE_OBJECT_LINKS_LEFT_LEFT, points_left_left);
HANDLE_LINK (OVCC_TILE_OBJECT_LINKS_LEFT_CENTER, points_left_center);
HANDLE_LINK (OVCC_TILE_OBJECT_LINKS_LEFT_RIGHT, points_left_right);
#undef HANDLE_LINK
}
pixbuf = gdk_pixbuf_get_from_drawable (NULL, GDK_DRAWABLE (pixmap), colormap,
0, 0, 0, 0, size, size);
g_object_unref (pixmap);
gdk_gc_unref (gc_sub);
gdk_gc_unref (gc);
return pixbuf;
}
#endif
/**
......@@ -316,7 +296,7 @@ tile_get_pixbuf (OVCCTile *tile,
gint size)
{
GdkPixbuf *pix;
gint rotation = ovcc_tile_get_rotation (tile);
guint rotation = ovcc_tile_get_rotation (tile);
#if 0
pix = tile_get_procedural (tile, size > 0 ? size : TILE_SIZE);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment