summaryrefslogtreecommitdiff
path: root/src/gfx.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-04-18 14:56:05 +0000
committerfrosch <frosch@openttd.org>2010-04-18 14:56:05 +0000
commit2e90f7f8b975d380c3d544995ef6db9d6c8a86d8 (patch)
tree90fb0852bd31229b016ca998a8e6c0ce44d699dd /src/gfx.cpp
parent2330851d1dc0650335bc73ec4cfd010f08c55742 (diff)
downloadopenttd-2e90f7f8b975d380c3d544995ef6db9d6c8a86d8.tar.xz
(svn r19670) -Codechange: Add CeilDiv() and RoundDiv() to simplify integer divisions with rounding.
Diffstat (limited to 'src/gfx.cpp')
-rw-r--r--src/gfx.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp
index c8e9229f2..4c5177f21 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -550,8 +550,7 @@ static int DrawString(int left, int right, int top, char *str, const char *last,
break;
case SA_CENTER:
- /* The second + 1 is to round to the closest number */
- left = (initial_right + 1 + initial_left - w + 1) / 2;
+ left = RoundDiv(initial_right + 1 + initial_left - w, 2);
/* right + 1 = left + w */
right = left + w - 1;
break;
@@ -824,7 +823,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str,
total_height = (num + 1) * mt;
}
- int y = (align == SA_CENTER) ? (bottom + top - total_height + 1) / 2 : top;
+ int y = (align == SA_CENTER) ? RoundDiv(bottom + top - total_height, 2) : top;
const char *src = buffer;
for (;;) {
@@ -1324,8 +1323,8 @@ byte GetDigitWidth(FontSize size)
void ScreenSizeChanged()
{
- _dirty_bytes_per_line = (_screen.width + DIRTY_BLOCK_WIDTH - 1) / DIRTY_BLOCK_WIDTH;
- _dirty_blocks = ReallocT<byte>(_dirty_blocks, _dirty_bytes_per_line * ((_screen.height + DIRTY_BLOCK_HEIGHT - 1) / DIRTY_BLOCK_HEIGHT));
+ _dirty_bytes_per_line = CeilDiv(_screen.width, DIRTY_BLOCK_WIDTH);
+ _dirty_blocks = ReallocT<byte>(_dirty_blocks, _dirty_bytes_per_line * CeilDiv(_screen.height, DIRTY_BLOCK_HEIGHT));
/* check the dirty rect */
if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width;