aboutsummaryrefslogtreecommitdiff
path: root/common/rect.h
diff options
context:
space:
mode:
authorMatthew Hoops2012-03-20 13:44:20 -0400
committerMatthew Hoops2012-03-20 13:44:20 -0400
commit3c3576a224b92c703b4e8ea20008ac8a069980dd (patch)
treee187a4b31970b99bc27d2958b1586010758db0ba /common/rect.h
parente79f0bf717c31fb599a28ffb3e210ba7b0a300b0 (diff)
downloadscummvm-rg350-3c3576a224b92c703b4e8ea20008ac8a069980dd.tar.gz
scummvm-rg350-3c3576a224b92c703b4e8ea20008ac8a069980dd.tar.bz2
scummvm-rg350-3c3576a224b92c703b4e8ea20008ac8a069980dd.zip
COMMON: Make Rect::center() work properly with odd dimensions
Diffstat (limited to 'common/rect.h')
-rw-r--r--common/rect.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/common/rect.h b/common/rect.h
index 768d1ebbb9..50ef0201dd 100644
--- a/common/rect.h
+++ b/common/rect.h
@@ -244,11 +244,12 @@ struct Rect {
/**
* Create a rectangle around the given center.
+ * @note the center point is rounded up and left when given an odd width and height
*/
static Rect center(int16 cx, int16 cy, int16 w, int16 h) {
- w /= 2;
- h /= 2;
- return Rect(cx - w, cy - h, cx + w, cy + h);
+ int dx = w / 2;
+ int dy = h / 2;
+ return Rect(cx - dx, cy - dy, cx + dx + (w & 1), cy + dy + (h & 1));
}
};