expo: Separate dimensions from the bounding box
At present each object has a width and height and the bounding box is
implicit in that.
This is not flexible enough to handle objects which are larger than
their contents might need. For example, when centring a text object we
might want to have it stretch across the whole width of the display even
if the text itself does not need that much space.
Create a new 'dimensions' field and convert the existing width/height
into x1/y1 coordinates.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/boot/scene.c b/boot/scene.c
index 49dac90..325dd23 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -206,12 +206,17 @@
int scene_obj_set_pos(struct scene *scn, uint id, int x, int y)
{
struct scene_obj *obj;
+ int w, h;
obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
if (!obj)
return log_msg_ret("find", -ENOENT);
+ w = obj->bbox.x1 - obj->bbox.x0;
+ h = obj->bbox.y1 - obj->bbox.y0;
obj->bbox.x0 = x;
obj->bbox.y0 = y;
+ obj->bbox.x1 = obj->bbox.x0 + w;
+ obj->bbox.y1 = obj->bbox.y0 + h;
return 0;
}
@@ -223,8 +228,9 @@
obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
if (!obj)
return log_msg_ret("find", -ENOENT);
- obj->bbox.w = w;
- obj->bbox.h = h;
+ obj->bbox.x1 = obj->bbox.x0 + w;
+ obj->bbox.y1 = obj->bbox.y0 + h;
+ obj->flags |= SCENEOF_SIZE_VALID;
return 0;
}
@@ -419,8 +425,8 @@
if (obj->flags & SCENEOF_POINT) {
vidconsole_push_colour(cons, fore, back, &old);
video_fill_part(dev, x - theme->menu_inset, y,
- x + obj->bbox.w,
- y + obj->bbox.h,
+ obj->bbox.x1,
+ obj->bbox.y1,
vid_priv->colour_bg);
}
vidconsole_set_cursor_pos(cons, x, y);
@@ -765,8 +771,13 @@
ret = scene_obj_get_hw(scn, obj->id, &width);
if (ret < 0)
return log_msg_ret("get", ret);
- obj->bbox.w = width;
- obj->bbox.h = ret;
+ obj->dims.x = width;
+ obj->dims.y = ret;
+ if (!(obj->flags & SCENEOF_SIZE_VALID)) {
+ obj->bbox.x1 = obj->bbox.x0 + width;
+ obj->bbox.y1 = obj->bbox.y0 + ret;
+ obj->flags |= SCENEOF_SIZE_VALID;
+ }
}
break;
}
@@ -917,13 +928,13 @@
if (bbox->valid) {
bbox->x0 = min(bbox->x0, obj->bbox.x0 - inset);
bbox->y0 = min(bbox->y0, obj->bbox.y0);
- bbox->x1 = max(bbox->x1, obj->bbox.x0 + obj->bbox.w + inset);
- bbox->y1 = max(bbox->y1, obj->bbox.y0 + obj->bbox.h);
+ bbox->x1 = max(bbox->x1, obj->bbox.x1 + inset);
+ bbox->y1 = max(bbox->y1, obj->bbox.y1);
} else {
bbox->x0 = obj->bbox.x0 - inset;
bbox->y0 = obj->bbox.y0;
- bbox->x1 = obj->bbox.x0 + obj->bbox.w + inset;
- bbox->y1 = obj->bbox.y0 + obj->bbox.h;
+ bbox->x1 = obj->bbox.x1 + inset;
+ bbox->y1 = obj->bbox.y1;
bbox->valid = true;
}