aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorFilippos Karapetis2009-03-16 15:36:09 +0000
committerFilippos Karapetis2009-03-16 15:36:09 +0000
commit0e8dfe09c98d2e326a6317f8826530a6f9913907 (patch)
treedf34162cb2c0795eb490b1eee84ff0c86a270000 /engines
parent99bd2b4d4040f09c9b48183c01d216cd34ecea48 (diff)
downloadscummvm-rg350-0e8dfe09c98d2e326a6317f8826530a6f9913907.tar.gz
scummvm-rg350-0e8dfe09c98d2e326a6317f8826530a6f9913907.tar.bz2
scummvm-rg350-0e8dfe09c98d2e326a6317f8826530a6f9913907.zip
Replaced some rect_t operations with our common ones. For now, two helper functions are used to easily change types between Common::Rect and rect_t, until rect_t is removed
svn-id: r39449
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/gfx/gfx_system.h70
-rw-r--r--engines/sci/gfx/gfx_widgets.cpp20
-rw-r--r--engines/sci/gfx/operations.cpp14
3 files changed, 32 insertions, 72 deletions
diff --git a/engines/sci/gfx/gfx_system.h b/engines/sci/gfx/gfx_system.h
index 13ffc7342f..13da623215 100644
--- a/engines/sci/gfx/gfx_system.h
+++ b/engines/sci/gfx/gfx_system.h
@@ -113,7 +113,6 @@ struct rect_t {
int width, height; /* width, height: (x,y,width,height)=(5,5,1,1) occupies 1 pixel */
};
-
/* Generates a rect_t from index data
** Parameters: (int x int) x,y: Upper left point of the rectangle
** (int x int) width, height: Horizontal and vertical extension of the rectangle
@@ -130,6 +129,15 @@ static inline rect_t gfx_rect(int x, int y, int width, int height) {
return rect;
}
+// Temporary helper functions to ease the transition from rect_t to Common::Rect
+static rect_t toSCIRect(Common::Rect in) {
+ return gfx_rect(in.left, in.top, in.width(), in.height());
+}
+
+static Common::Rect toCommonRect(rect_t in) {
+ return Common::Rect(in.x, in.y, in.x + in.width, in.y + in.height);
+}
+
#define GFX_PRINT_RECT(rect) (rect).x, (rect).y, (rect).width, (rect).height
#define OVERLAP(a, b, z, zl) (a.z >= b.z && a.z < (b.z + b.zl))
@@ -144,69 +152,9 @@ static inline int gfx_rects_overlap(rect_t a, rect_t b) {
#undef OVERLAP
-#define MERGE_PARTIAL(z, zl) \
-if (a.z < b.z) SUBMERGE_PARTIAL(a, b, z, zl) \
-else SUBMERGE_PARTIAL(b, a, z, zl)
-
-#define SUBMERGE_PARTIAL(a, b, z, zl) \
-{ \
- retval.z = a.z; \
- retval.zl = a.zl; \
- if (b.z + b.zl > a.z + a.zl) \
- retval.zl = (b.z + b.zl - a.z); \
-}
-
-
-
-#define RECT(a) a.x, a.y, a.width, a.height
-
-/* Merges two rects
-** Parameters: (rect_t x rect_t) a,b: The two rects to merge
-** Returns : (rect_t) The smallest rect containing both a and b
-*/
-static inline rect_t gfx_rects_merge(rect_t a, rect_t b) {
- rect_t retval;
- MERGE_PARTIAL(x, width);
- MERGE_PARTIAL(y, height);
- return retval;
-}
-#undef MERGE_PARTIAL
-#undef SUBMERGE_PARTIAL
-
-
-/* Subset predicate for rectangles
-** Parameters: (rect_t) a, b: The two rects to compare
-** Returns : non-zero iff for each pixel p in a the following holds: p is in b.
-*/
-static inline int gfx_rect_subset(rect_t a, rect_t b) {
- return ((a.x >= b.x) && (a.y >= b.y) && ((a.x + a.width) <= (b.x + b.width)) && ((a.y + a.height) <= (b.y + b.height)));
-}
-
-
-/* Equality predicate for rects
-** Parameters: (rect_t) a, b
-** Returns : (int) gfx_rect_subset(a,b) AND gfx_rect_subset(b,a)
-*/
-static inline int gfx_rect_equals(rect_t a, rect_t b) {
- return (a.x == b.x && a.width == b.width && a.y == b.y && a.height == b.height);
-}
-
-
/* gfx_rect_fullscreen is declared in gfx/gfx_tools.c */
extern rect_t gfx_rect_fullscreen;
-/* Translation operation for rects
-** Parameters: (rect_t) rect: The rect to translate
-** (Common::Point) offset: The offset to translate it by
-** Returns : (rect_t) The translated rect
-*/
-static inline rect_t gfx_rect_translate(rect_t rect, Common::Point offset) {
- rect.x += offset.x;
- rect.y += offset.y;
-
- return rect;
-}
-
#define GFX_RESID_NONE -1
#define GFX_PIC_COLORS 256
diff --git a/engines/sci/gfx/gfx_widgets.cpp b/engines/sci/gfx/gfx_widgets.cpp
index 81126019bd..e4103d46ff 100644
--- a/engines/sci/gfx/gfx_widgets.cpp
+++ b/engines/sci/gfx/gfx_widgets.cpp
@@ -411,7 +411,7 @@ static int _gfxwop_box_superarea_of(gfxw_widget_t *widget, gfxw_widget_t *other)
if (box->shade_type != GFX_BOX_SHADE_FLAT && box->color2.alpha)
return 0;
- if (!gfx_rect_subset(other->bounds, box->bounds))
+ if (!toCommonRect(box->bounds).contains(toCommonRect(other->bounds)))
return 0;
return 1;
@@ -424,7 +424,7 @@ static int _gfxwop_box_equals(gfxw_widget_t *widget, gfxw_widget_t *other) {
obox = (gfxw_box_t *) other;
- if (!gfx_rect_equals(wbox->bounds, obox->bounds))
+ if (!toCommonRect(wbox->bounds).equals(toCommonRect(obox->bounds)))
return 0;
if (!_color_equals(wbox->color1, obox->color1))
@@ -491,7 +491,7 @@ static int _gfxwop_primitive_equals(gfxw_widget_t *widget, gfxw_widget_t *other)
oprim = (gfxw_primitive_t *) other;
- if (!gfx_rect_equals(wprim->bounds, oprim->bounds))
+ if (!toCommonRect(wprim->bounds).equals(toCommonRect(oprim->bounds)))
return 0;
if (!_color_equals(wprim->color, oprim->color))
@@ -1972,7 +1972,8 @@ int gfxw_widget_matches_snapshot(gfxw_snapshot_t *snapshot, gfxw_widget_t *widge
bounds.y += widget->parent->bounds.y;
}
- return ((widget->serial >= free_above_eq || widget->serial < free_below) && gfx_rect_subset(bounds, snapshot->area));
+ return ((widget->serial >= free_above_eq || widget->serial < free_below) &&
+ toCommonRect(snapshot->area).contains(toCommonRect(bounds)));
}
#define MAGIC_FREE_NUMBER -42
@@ -2074,7 +2075,7 @@ static int gfxw_check_chrono_overlaps(gfxw_port_t *chrono, gfxw_widget_t *widget
gfxw_widget_t *seeker = GFXWC(chrono->contents)->contents;
while (seeker) {
- if (gfx_rect_equals(seeker->bounds, widget->bounds)) {
+ if (toCommonRect(seeker->bounds).equals(toCommonRect(widget->bounds))) {
gfxw_annihilate(GFXW(seeker));
return 1;
}
@@ -2106,7 +2107,9 @@ static gfxw_widget_t *gfxw_widget_intersects_chrono(gfxw_list_t *tw, gfxw_widget
bounds = widget->bounds;
origin.x = seeker->parent->zone.x;
origin.y = seeker->parent->zone.y;
- gfx_rect_translate(bounds, origin);
+ Common::Rect tmp = toCommonRect(bounds);
+ tmp.translate(origin.x, origin.y);
+ bounds = toSCIRect(tmp);
if (gfx_rects_overlap(bounds, seeker->bounds))
return seeker;
@@ -2134,7 +2137,10 @@ void gfxw_widget_reparent_chrono(gfxw_visual_t *visual, gfxw_widget_t *view, gfx
gfxw_remove_widget_from_container(GFXWC(chrono->parent), GFXW(chrono));
gfxw_annihilate(GFXW(chrono));
- gfx_rect_translate(tw->zone, origin);
+ Common::Rect tmp = toCommonRect(tw->zone);
+ tmp.translate(origin.x, origin.y);
+ tw->zone = toSCIRect(tmp);
+
target->add(GFXWC(target), GFXW(tw));
}
}
diff --git a/engines/sci/gfx/operations.cpp b/engines/sci/gfx/operations.cpp
index ae385cd483..585e380e0d 100644
--- a/engines/sci/gfx/operations.cpp
+++ b/engines/sci/gfx/operations.cpp
@@ -335,10 +335,13 @@ gfx_dirty_rect_t *gfxdr_add_dirty(gfx_dirty_rect_t *base, rect_t box, int strate
switch (strategy) {
case GFXOP_DIRTY_FRAMES_ONE:
- if (base)
- base->rect = gfx_rects_merge(box, base->rect);
- else
+ if (base) {
+ Common::Rect tmp = toCommonRect(box);
+ tmp.extend(toCommonRect(base->rect));
+ base->rect = toSCIRect(tmp);
+ } else {
base = _rect_create(box);
+ }
break;
case GFXOP_DIRTY_FRAMES_CLUSTERS: {
@@ -347,7 +350,10 @@ gfx_dirty_rect_t *gfxdr_add_dirty(gfx_dirty_rect_t *base, rect_t box, int strate
while (*rectp) {
if (gfx_rects_overlap((*rectp)->rect, box)) {
gfx_dirty_rect_t *next = (*rectp)->next;
- box = gfx_rects_merge((*rectp)->rect, box);
+ Common::Rect tmp = toCommonRect((*rectp)->rect);
+ tmp.extend(toCommonRect(box));
+ box = toSCIRect(tmp);
+
free(*rectp);
*rectp = next;
} else