+ if (!needs_update) {
+ start_update = obj->start;
+ end_update = obj->end;
+ needs_update = true;
+ return;
+ }
+ if (obj->start.x < start_update.x)
+ start_update.x = obj->start.x;
+ if (obj->start.y < start_update.y)
+ start_update.y = obj->start.y;
+ if (obj->end.x > end_update.x)
+ end_update.x = obj->end.x;
+ if (obj->end.y > end_update.y)
+ end_update.y = obj->end.y;
+}
+
+static void destroy_object(struct object *object)
+{
+ list_del(&object->list);
+ add_update(object);
+}
+
+static void add_object(struct list_head *list,
+ struct object *obj,
+ unsigned int startx, unsigned int starty,
+ unsigned int width, unsigned int height,
+ void (*redraw)(SDL_Surface *s, struct object *me))
+{
+ list_add_tail(list, &obj->list);
+ obj->start.x = startx;
+ obj->start.y = starty;
+ obj->end.x = startx + width;
+ obj->end.y = starty + height;
+ obj->redraw = redraw;
+ add_update(obj);
+}
+
+static void redraw_line(SDL_Surface *s, struct object *me)
+{
+ struct line_segment *l = container_of(me, struct line_segment, object);
+
+ thick_line(s, l, 0);
+}
+
+static int destroy_line(struct line_segment *l)
+{
+ list_del(&l->list);
+ destroy_object(&l->object);
+ return 0;
+}
+
+static void line_object_setup(struct list_head *lines,
+ struct list_head *objects,
+ struct line_segment *l)
+{
+ unsigned int tmp, startx, endx, starty, endy;
+
+ list_add_tail(lines, &l->list);
+
+ startx = l->start.x;
+ starty = l->start.y;
+ endx = l->end.x;
+ endy = l->end.y;
+
+ /* Find bounding box */
+ if (startx > endx) {
+ tmp = endx;
+ endx = startx;
+ startx = tmp;
+ }
+ if (starty > endy) {
+ tmp = endy;
+ endy = starty;
+ starty = tmp;
+ }
+ /* Padding for thick lines (beware underflow) */
+ if (startx > 0)
+ startx--;
+ if (starty > 0)
+ starty--;
+ endx++;
+ endy++;
+
+ add_object(objects, &l->object, startx, starty,
+ endx - startx, endy - starty, redraw_line);
+}
+
+static void add_line(struct list_head *lines,
+ unsigned int startx, unsigned int starty,
+ unsigned int endx, unsigned int endy,
+ const struct coord calib[])
+{
+ struct line_segment *l = talloc(NULL, struct line_segment);
+ struct timeval now;