[Freeciv-Dev] (PR#12593) Graphic errors in the FTWL client
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12593 >
> [i-freeciv-lists@xxxxxxxxxxxxx - Tue Mar 22 21:47:24 2005]:
>
> > The attached screenshot shows the FTWL client in iso mode. As you see
> > there are two kind of errors. The one at the top also appears also in
> > the non-iso mode.
>
> One fixed. One still to go. On
> http://www.freeciv.org/~rfalke/fs2005-03-22_iso_pics/ are pics of the
> iso mode and also of the graphic error.
Here is a fix.
Index: utility/ftwl/common_types.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/common_types.c,v
retrieving revision 1.3
diff -u -r1.3 common_types.c
--- utility/ftwl/common_types.c 22 Jan 2005 19:45:45 -0000 1.3
+++ utility/ftwl/common_types.c 23 Mar 2005 23:00:07 -0000
@@ -328,19 +328,43 @@
}
/*************************************************************************
+ Normalize a rectangle by checking for a negative width or height.
+*************************************************************************/
+static void ct_normalize_rect(struct ct_rect *rect)
+{
+ if (rect->width < 0) {
+ rect->x += rect->width;
+ rect->width = -rect->width;
+ }
+ if (rect->height < 0) {
+ rect->y += rect->height;
+ rect->height = -rect->height;
+ }
+}
+
+/*************************************************************************
...
*************************************************************************/
void ct_clip_rect(struct ct_rect *to_draw, const struct ct_rect *available)
{
- struct ct_point p1 = { to_draw->x, to_draw->y };
- struct ct_point p2 =
- { to_draw->x + to_draw->width-1, to_draw->y + to_draw->height-1 };
-
- ct_clip_point(&p1, available);
- ct_clip_point(&p2, available);
+ struct ct_rect avail = *available;
+ int x0, y0, x1, y1;
- ct_rect_fill_on_2_points(to_draw, &p1, &p2);
- assert(ct_rect_in_rect(to_draw, available));
+ /* We have to normalize the rectangles first since the operations are
+ * not symmetric. */
+ ct_normalize_rect(to_draw);
+ ct_normalize_rect(&avail);
+
+ x0 = MAX(to_draw->x, avail.x);
+ y0 = MAX(to_draw->y, avail.y);
+ x1 = MIN(to_draw->x + to_draw->width - 1, avail.x + avail.width - 1);
+ y1 = MIN(to_draw->y + to_draw->height - 1, avail.y + avail.height - 1);
+
+ to_draw->x = x0;
+ to_draw->y = y0;
+ to_draw->width = MAX(x1 - x0 + 1, 0);
+ to_draw->height = MAX(y1 - y0 + 1, 0);
+ /* Note the resultant rectangle may have 0 width/height. */
}
/*************************************************************************
|
|