mirror of https://github.com/OpenTTD/OpenTTD
(svn r2518) Small cleanup
parent
5fb14350a0
commit
42d086b212
197
gfx.c
197
gfx.c
|
@ -35,16 +35,16 @@ void memcpy_pitch(void *d, void *s, int w, int h, int spitch, int dpitch)
|
|||
}
|
||||
|
||||
|
||||
void GfxScroll(int left, int top, int width, int height, int xo, int yo) {
|
||||
byte *src, *dst;
|
||||
void GfxScroll(int left, int top, int width, int height, int xo, int yo)
|
||||
{
|
||||
byte *src;
|
||||
byte *dst;
|
||||
int p;
|
||||
int ht;
|
||||
|
||||
if (xo == 0 && yo == 0)
|
||||
return;
|
||||
if (xo == 0 && yo == 0) return;
|
||||
|
||||
if (_cursor.visible)
|
||||
UndrawMouseCursor();
|
||||
if (_cursor.visible) UndrawMouseCursor();
|
||||
UndrawTextMessage();
|
||||
|
||||
p = _screen.pitch;
|
||||
|
@ -106,23 +106,17 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo) {
|
|||
}
|
||||
|
||||
|
||||
void GfxFillRect(int left, int top, int right, int bottom, int color) {
|
||||
void GfxFillRect(int left, int top, int right, int bottom, int color)
|
||||
{
|
||||
DrawPixelInfo *dpi = _cur_dpi;
|
||||
byte *dst;
|
||||
const int otop = top;
|
||||
const int oleft = left;
|
||||
|
||||
if (dpi->zoom != 0)
|
||||
return;
|
||||
|
||||
if (left > right || top > bottom)
|
||||
return;
|
||||
|
||||
if (right < dpi->left || left >= dpi->left + dpi->width)
|
||||
return;
|
||||
|
||||
if (bottom < dpi->top || top >= dpi->top + dpi->height)
|
||||
return;
|
||||
if (dpi->zoom != 0) return;
|
||||
if (left > right || top > bottom) return;
|
||||
if (right < dpi->left || left >= dpi->left + dpi->width) return;
|
||||
if (bottom < dpi->top || top >= dpi->top + dpi->height) return;
|
||||
|
||||
if ( (left -= dpi->left) < 0) left = 0;
|
||||
right = right - dpi->left + 1;
|
||||
|
@ -176,7 +170,8 @@ void GfxDrawLine(int x, int y, int x2, int y2, int color)
|
|||
{
|
||||
int dy;
|
||||
int dx;
|
||||
int stepx, stepy;
|
||||
int stepx;
|
||||
int stepy;
|
||||
int frac;
|
||||
|
||||
// Check clipping first
|
||||
|
@ -184,26 +179,32 @@ void GfxDrawLine(int x, int y, int x2, int y2, int color)
|
|||
DrawPixelInfo *dpi = _cur_dpi;
|
||||
int t;
|
||||
|
||||
if (x < dpi->left && x2 < dpi->left)
|
||||
return;
|
||||
if (x < dpi->left && x2 < dpi->left) return;
|
||||
|
||||
if (y < dpi->top && y2 < dpi->top)
|
||||
return;
|
||||
if (y < dpi->top && y2 < dpi->top) return;
|
||||
|
||||
t = dpi->left + dpi->width;
|
||||
if (x > t && x2 > t)
|
||||
return;
|
||||
if (x > t && x2 > t) return;
|
||||
|
||||
t = dpi->top + dpi->height;
|
||||
if (y > t && y2 > t)
|
||||
return;
|
||||
if (y > t && y2 > t) return;
|
||||
}
|
||||
|
||||
dy = (y2 - y) * 2;
|
||||
if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; }
|
||||
if (dy < 0) {
|
||||
dy = -dy;
|
||||
stepy = -1;
|
||||
} else {
|
||||
stepy = 1;
|
||||
}
|
||||
|
||||
dx = (x2 - x) * 2;
|
||||
if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; }
|
||||
if (dx < 0) {
|
||||
dx = -dx;
|
||||
stepx = -1;
|
||||
} else {
|
||||
stepx = 1;
|
||||
}
|
||||
|
||||
GfxSetPixel(x, y, color);
|
||||
if (dx > dy) {
|
||||
|
@ -381,7 +382,8 @@ void DrawStringMultiCenter(int x, int y, uint16 str, int maxw)
|
|||
}
|
||||
}
|
||||
|
||||
void DrawStringMultiLine(int x, int y, uint16 str, int maxw) {
|
||||
void DrawStringMultiLine(int x, int y, uint16 str, int maxw)
|
||||
{
|
||||
char buffer[512];
|
||||
uint32 tmp;
|
||||
int num, w, mt, t;
|
||||
|
@ -442,7 +444,8 @@ int GetStringWidth(const char *str)
|
|||
return w;
|
||||
}
|
||||
|
||||
void DrawFrameRect(int left, int top, int right, int bottom, int ctab, int flags) {
|
||||
void DrawFrameRect(int left, int top, int right, int bottom, int ctab, int flags)
|
||||
{
|
||||
byte color_2 = _color_list[ctab].window_color_1a;
|
||||
byte color_interior = _color_list[ctab].window_color_bga;
|
||||
byte color_3 = _color_list[ctab].window_color_bgb;
|
||||
|
@ -554,7 +557,8 @@ skip_cont:;
|
|||
}
|
||||
}
|
||||
|
||||
void DrawSprite(uint32 img, int x, int y) {
|
||||
void DrawSprite(uint32 img, int x, int y)
|
||||
{
|
||||
if (img & 0x8000) {
|
||||
_color_remap_ptr = GetNonSprite(img >> 16) + 1;
|
||||
GfxMainBlitter(GetSprite(img & 0x3FFF), x, y, 1);
|
||||
|
@ -573,7 +577,8 @@ typedef struct BlitterParams {
|
|||
byte *dst;
|
||||
int mode;
|
||||
int width, height;
|
||||
int width_org, height_org;
|
||||
int width_org;
|
||||
int height_org;
|
||||
int pitch;
|
||||
byte info;
|
||||
} BlitterParams;
|
||||
|
@ -605,16 +610,14 @@ static void GfxBlitTileZoomIn(BlitterParams *bp)
|
|||
} else {
|
||||
src -= skip;
|
||||
num += skip;
|
||||
if (num <= 0)
|
||||
continue;
|
||||
if (num <= 0) continue;
|
||||
skip = 0;
|
||||
}
|
||||
|
||||
skip = skip + num - bp->width;
|
||||
if (skip > 0) {
|
||||
num -= skip;
|
||||
if (num <= 0)
|
||||
continue;
|
||||
if (num <= 0) continue;
|
||||
}
|
||||
|
||||
ctab = _color_remap_ptr;
|
||||
|
@ -631,7 +634,7 @@ static void GfxBlitTileZoomIn(BlitterParams *bp)
|
|||
} while (!(done & 0x80));
|
||||
|
||||
bp->dst += bp->pitch;
|
||||
} while (--bp->height);
|
||||
} while (--bp->height != 0);
|
||||
} else if (bp->mode & 2) {
|
||||
src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
|
||||
do {
|
||||
|
@ -647,16 +650,14 @@ static void GfxBlitTileZoomIn(BlitterParams *bp)
|
|||
dst += skip;
|
||||
} else {
|
||||
num += skip;
|
||||
if (num <= 0)
|
||||
continue;
|
||||
if (num <= 0) continue;
|
||||
skip = 0;
|
||||
}
|
||||
|
||||
skip = skip + num - bp->width;
|
||||
if (skip > 0) {
|
||||
num -= skip;
|
||||
if (num <= 0)
|
||||
continue;
|
||||
if (num <= 0) continue;
|
||||
}
|
||||
|
||||
ctab = _color_remap_ptr;
|
||||
|
@ -667,8 +668,7 @@ static void GfxBlitTileZoomIn(BlitterParams *bp)
|
|||
} while (!(done & 0x80));
|
||||
|
||||
bp->dst += bp->pitch;
|
||||
} while (--bp->height);
|
||||
|
||||
} while (--bp->height != 0);
|
||||
} else {
|
||||
src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
|
||||
do {
|
||||
|
@ -686,16 +686,14 @@ static void GfxBlitTileZoomIn(BlitterParams *bp)
|
|||
} else {
|
||||
src -= skip;
|
||||
num += skip;
|
||||
if (num <= 0)
|
||||
continue;
|
||||
if (num <= 0) continue;
|
||||
skip = 0;
|
||||
}
|
||||
|
||||
skip = skip + num - bp->width;
|
||||
if (skip > 0) {
|
||||
num -= skip;
|
||||
if (num <= 0)
|
||||
continue;
|
||||
if (num <= 0) continue;
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
if (num & 1) *dst++ = *src++;
|
||||
|
@ -705,7 +703,7 @@ static void GfxBlitTileZoomIn(BlitterParams *bp)
|
|||
*(uint32*)dst = *(uint32*)src;
|
||||
dst += 4;
|
||||
src += 4;
|
||||
} while (--num);
|
||||
} while (--num != 0);
|
||||
}
|
||||
#else
|
||||
memcpy(dst, src, num);
|
||||
|
@ -713,7 +711,7 @@ static void GfxBlitTileZoomIn(BlitterParams *bp)
|
|||
} while (!(done & 0x80));
|
||||
|
||||
bp->dst += bp->pitch;
|
||||
} while (--bp->height);
|
||||
} while (--bp->height != 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -740,7 +738,7 @@ static void GfxBlitZoomInUncomp(BlitterParams *bp)
|
|||
}
|
||||
src += bp->width_org;
|
||||
dst += bp->pitch;
|
||||
} while (--height);
|
||||
} while (--height != 0);
|
||||
}
|
||||
} else if (bp->mode & 2) {
|
||||
if (bp->info & 1) {
|
||||
|
@ -751,7 +749,7 @@ static void GfxBlitZoomInUncomp(BlitterParams *bp)
|
|||
if (src[i] != 0) dst[i] = ctab[dst[i]];
|
||||
src += bp->width_org;
|
||||
dst += bp->pitch;
|
||||
} while (--height);
|
||||
} while (--height != 0);
|
||||
}
|
||||
} else {
|
||||
if (!(bp->info & 1)) {
|
||||
|
@ -759,7 +757,7 @@ static void GfxBlitZoomInUncomp(BlitterParams *bp)
|
|||
memcpy(dst, src, width);
|
||||
src += bp->width_org;
|
||||
dst += bp->pitch;
|
||||
} while (--height);
|
||||
} while (--height != 0);
|
||||
} else {
|
||||
do {
|
||||
int n = width;
|
||||
|
@ -782,7 +780,7 @@ static void GfxBlitZoomInUncomp(BlitterParams *bp)
|
|||
|
||||
src += bp->width_org - width;
|
||||
dst += bp->pitch - width;
|
||||
} while (--height);
|
||||
} while (--height != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -819,16 +817,14 @@ static void GfxBlitTileZoomMedium(BlitterParams *bp)
|
|||
} else {
|
||||
src -= skip;
|
||||
num += skip;
|
||||
if (num <= 0)
|
||||
continue;
|
||||
if (num <= 0) continue;
|
||||
skip = 0;
|
||||
}
|
||||
|
||||
skip = skip + num - bp->width;
|
||||
if (skip > 0) {
|
||||
num -= skip;
|
||||
if (num <= 0)
|
||||
continue;
|
||||
if (num <= 0) continue;
|
||||
}
|
||||
|
||||
ctab = _color_remap_ptr;
|
||||
|
@ -846,7 +842,7 @@ static void GfxBlitTileZoomMedium(BlitterParams *bp)
|
|||
done = src_o[0];
|
||||
src_o += (done & 0x7F) + 2;
|
||||
} while (!(done & 0x80));
|
||||
} while (--bp->height);
|
||||
} while (--bp->height != 0);
|
||||
} else if (bp->mode & 2) {
|
||||
src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
|
||||
do {
|
||||
|
@ -867,16 +863,14 @@ static void GfxBlitTileZoomMedium(BlitterParams *bp)
|
|||
dst += skip >> 1;
|
||||
} else {
|
||||
num += skip;
|
||||
if (num <= 0)
|
||||
continue;
|
||||
if (num <= 0) continue;
|
||||
skip = 0;
|
||||
}
|
||||
|
||||
skip = skip + num - bp->width;
|
||||
if (skip > 0) {
|
||||
num -= skip;
|
||||
if (num <= 0)
|
||||
continue;
|
||||
if (num <= 0) continue;
|
||||
}
|
||||
|
||||
ctab = _color_remap_ptr;
|
||||
|
@ -893,8 +887,7 @@ static void GfxBlitTileZoomMedium(BlitterParams *bp)
|
|||
done = src_o[0];
|
||||
src_o += (done & 0x7F) + 2;
|
||||
} while (!(done & 0x80));
|
||||
} while (--bp->height);
|
||||
|
||||
} while (--bp->height != 0);
|
||||
} else {
|
||||
src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
|
||||
do {
|
||||
|
@ -918,16 +911,14 @@ static void GfxBlitTileZoomMedium(BlitterParams *bp)
|
|||
} else {
|
||||
src -= skip;
|
||||
num += skip;
|
||||
if (num <= 0)
|
||||
continue;
|
||||
if (num <= 0) continue;
|
||||
skip = 0;
|
||||
}
|
||||
|
||||
skip = skip + num - bp->width;
|
||||
if (skip > 0) {
|
||||
num -= skip;
|
||||
if (num <= 0)
|
||||
continue;
|
||||
if (num <= 0) continue;
|
||||
}
|
||||
|
||||
num = (num + 1) >> 1;
|
||||
|
@ -947,8 +938,7 @@ static void GfxBlitTileZoomMedium(BlitterParams *bp)
|
|||
done = src_o[0];
|
||||
src_o += (done & 0x7F) + 2;
|
||||
} while (!(done & 0x80));
|
||||
|
||||
} while (--bp->height);
|
||||
} while (--bp->height != 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1608,27 +1598,35 @@ void UndrawMouseCursor(void)
|
|||
|
||||
void DrawMouseCursor(void)
|
||||
{
|
||||
int x,y,w,h;
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
// Don't draw the mouse cursor if it's already drawn
|
||||
if (_cursor.visible) {
|
||||
if (!_cursor.dirty)
|
||||
return;
|
||||
if (!_cursor.dirty) return;
|
||||
UndrawMouseCursor();
|
||||
}
|
||||
|
||||
w = _cursor.size.x;
|
||||
x = _cursor.pos.x + _cursor.offs.x;
|
||||
if (x < 0) { w += x; x=0; }
|
||||
if (w>_screen.width-x) { w = _screen.width-x; }
|
||||
if (x < 0) {
|
||||
w += x;
|
||||
x = 0;
|
||||
}
|
||||
if (w > _screen.width - x) w = _screen.width - x;
|
||||
if (w <= 0) return;
|
||||
_cursor.draw_pos.x = x;
|
||||
_cursor.draw_size.x = w;
|
||||
|
||||
h = _cursor.size.y;
|
||||
y = _cursor.pos.y + _cursor.offs.y;
|
||||
if (y < 0) { h += y; y=0; }
|
||||
if (h>_screen.height-y) { h = _screen.height-y; }
|
||||
if (y < 0) {
|
||||
h += y;
|
||||
y = 0;
|
||||
}
|
||||
if (h > _screen.height - y) h = _screen.height - y;
|
||||
if (h <= 0) return;
|
||||
_cursor.draw_pos.y = y;
|
||||
_cursor.draw_size.y = h;
|
||||
|
@ -1654,7 +1652,8 @@ void DrawMouseCursor(void)
|
|||
#if defined(_DEBUG)
|
||||
static void DbgScreenRect(int left, int top, int right, int bottom)
|
||||
{
|
||||
DrawPixelInfo dp,*old;
|
||||
DrawPixelInfo dp;
|
||||
DrawPixelInfo* old;
|
||||
|
||||
old = _cur_dpi;
|
||||
_cur_dpi = &dp;
|
||||
|
@ -1692,7 +1691,8 @@ void RedrawScreenRect(int left, int top, int right, int bottom)
|
|||
void DrawDirtyBlocks(void)
|
||||
{
|
||||
byte *b = _dirty_blocks;
|
||||
int x=0,y=0;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
const int w = (_screen.width + 63) & ~63;
|
||||
const int h = (_screen.height + 7) & ~7;
|
||||
|
||||
|
@ -1762,15 +1762,15 @@ void DrawDirtyBlocks(void)
|
|||
void SetDirtyBlocks(int left, int top, int right, int bottom)
|
||||
{
|
||||
byte *b;
|
||||
int width,height,i;
|
||||
int width;
|
||||
int height;
|
||||
|
||||
if (left < 0) left = 0;
|
||||
if (top < 0) top = 0;
|
||||
if (right > _screen.width) right = _screen.width;
|
||||
if (bottom > _screen.height) bottom = _screen.height;
|
||||
|
||||
if (left >= right || top >= bottom)
|
||||
return;
|
||||
if (left >= right || top >= bottom) return;
|
||||
|
||||
if (left < _invalid_rect.left ) _invalid_rect.left = left;
|
||||
if (top < _invalid_rect.top ) _invalid_rect.top = top;
|
||||
|
@ -1788,11 +1788,12 @@ void SetDirtyBlocks(int left, int top, int right, int bottom)
|
|||
assert(width > 0 && height > 0);
|
||||
|
||||
do {
|
||||
i=width;
|
||||
int i = width;
|
||||
|
||||
do b[--i] = 0xFF; while (i);
|
||||
|
||||
b += DIRTY_BYTES_PER_LINE;
|
||||
} while (--height);
|
||||
} while (--height != 0);
|
||||
}
|
||||
|
||||
void MarkWholeScreenDirty(void)
|
||||
|
@ -1804,8 +1805,7 @@ bool FillDrawPixelInfo(DrawPixelInfo *n, DrawPixelInfo *o, int left, int top, in
|
|||
{
|
||||
int t;
|
||||
|
||||
if (o == NULL)
|
||||
o = _cur_dpi;
|
||||
if (o == NULL) o = _cur_dpi;
|
||||
|
||||
n->zoom = 0;
|
||||
|
||||
|
@ -1814,22 +1814,22 @@ bool FillDrawPixelInfo(DrawPixelInfo *n, DrawPixelInfo *o, int left, int top, in
|
|||
|
||||
n->left = 0;
|
||||
if ((left -= o->left) < 0) {
|
||||
if ((width += left) < 0)
|
||||
return false;
|
||||
width += left;
|
||||
if (width < 0) return false;
|
||||
n->left = -left;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
if ((t=width + left - o->width) > 0) {
|
||||
if ((width -= t) < 0)
|
||||
return false;
|
||||
width -= t;
|
||||
if (width < 0) return false;
|
||||
}
|
||||
n->width = width;
|
||||
|
||||
n->top = 0;
|
||||
if ((top -= o->top) < 0) {
|
||||
if ((height += top) < 0)
|
||||
return false;
|
||||
height += top;
|
||||
if (height < 0) return false;
|
||||
n->top = -top;
|
||||
top = 0;
|
||||
}
|
||||
|
@ -1837,12 +1837,11 @@ bool FillDrawPixelInfo(DrawPixelInfo *n, DrawPixelInfo *o, int left, int top, in
|
|||
n->dst_ptr = o->dst_ptr + left + top * (n->pitch = o->pitch);
|
||||
|
||||
if ((t=height + top - o->height) > 0) {
|
||||
if ((height-=t) < 0)
|
||||
return false;
|
||||
height -= t;
|
||||
if (height < 0) return false;
|
||||
}
|
||||
n->height = height;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1851,8 +1850,7 @@ static void SetCursorSprite(CursorID cursor)
|
|||
CursorVars *cv = &_cursor;
|
||||
const Sprite *p;
|
||||
|
||||
if (cv->sprite == cursor)
|
||||
return;
|
||||
if (cv->sprite == cursor) return;
|
||||
|
||||
p = GetSprite(cursor & 0x3FFF);
|
||||
cv->sprite = cursor;
|
||||
|
@ -1882,8 +1880,7 @@ static void SwitchAnimatedCursor(void)
|
|||
|
||||
void CursorTick(void)
|
||||
{
|
||||
CursorVars *cv = &_cursor;
|
||||
if (cv->animate_timeout && !--cv->animate_timeout)
|
||||
if (_cursor.animate_timeout != 0 && --_cursor.animate_timeout == 0)
|
||||
SwitchAnimatedCursor();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue