Mercurial > hg > dmlib
changeset 1323:2260ed90ab6b
Remove dmgfx and move the functions used to PPL and Auval.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 22 Aug 2017 00:51:45 +0300 |
parents | c2000337ac3f |
children | fc530d2e3a31 |
files | src/dmgfx.c src/dmlib.h tools/auval.c tools/ppl.c |
diffstat | 4 files changed, 222 insertions(+), 126 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dmgfx.c Mon Aug 21 15:46:21 2017 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -#include "dmlib.h" - - -void dmFillRect(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 col) -{ - SDL_Rect rc; - rc.x = x0; - rc.y = y0; - rc.w = x1 - x0 + 1; - rc.h = y1 - y0 + 1; - SDL_FillRect(screen, &rc, col); -} - - -void dmDrawHLine(SDL_Surface *screen, int x0, int x1, int yc, const Uint32 col) -{ - const int bpp = screen->format->BytesPerPixel, - cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y, - cx1 = screen->clip_rect.x + screen->clip_rect.w - 1, - cy1 = screen->clip_rect.y + screen->clip_rect.h - 1; - - DM_SWAP(int, x0, x1); - if (yc < cy0|| yc > cy1 || x1 < cx0 || x0 > cx1) return; - if (x0 < cx0) x0 = cx0; - if (x1 > cx1) x1 = cx1; - - int x = x1 - x0 + 1; - Uint8 *pix = ((Uint8 *) screen->pixels) + yc * screen->pitch + (x0 * bpp); - switch (screen->format->BitsPerPixel) - { - case 8: - while (x--) - *pix++ = col; - break; - - case 32: - { - Uint32 *p = (Uint32 *) pix; - while (x--) - *p++ = col; - } - break; - } -} - - -void dmDrawVLine(SDL_Surface *screen, int y0, int y1, int xc, const Uint32 col) -{ - const int bpp = screen->format->BytesPerPixel, - pitch = screen->pitch / bpp, - cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y, - cx1 = screen->clip_rect.x + screen->clip_rect.w - 1, - cy1 = screen->clip_rect.y + screen->clip_rect.h - 1; - - DM_SWAP(int, y0, y1); - if (xc < cx0 || xc > cx1 || y1 < cy0 || y0 > cy1) return; - if (y0 < cy0) y0 = cy0; - if (y1 > cy1) y1 = cy1; - - int y = y1 - y0 + 1; - Uint8 *pix = ((Uint8 *) screen->pixels) + y0 * screen->pitch + (xc * bpp); - switch (screen->format->BitsPerPixel) - { - case 8: - while (y--) - { - *pix = col; - pix += pitch; - } - break; - - case 32: - { - Uint32 *p = (Uint32 *) pix; - while (y--) - { - *p = col; - p += pitch; - } - } - break; - } -} - - -void dmDrawBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 ucol, Uint32 dcol) -{ - dmDrawHLine(screen, x0 , x1 - 1, y0, ucol); - dmDrawHLine(screen, x0 + 1, x1 , y1, dcol); - - dmDrawVLine(screen, y0 , y1 - 1, x0, ucol); - dmDrawVLine(screen, y0 + 1, y1 , x1, dcol); -} - - -void dmFillBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 bgcol, Uint32 ucol, Uint32 dcol) -{ - SDL_Rect rc; - - rc.x = x0 + 1; - rc.y = y0 + 1; - rc.w = x1 - x0 - 1; - rc.h = y1 - y0 - 1; - SDL_FillRect(screen, &rc, bgcol); - - dmDrawBox3D(screen, x0, y0, x1, y1, ucol, dcol); -}
--- a/src/dmlib.h Mon Aug 21 15:46:21 2017 +0300 +++ b/src/dmlib.h Tue Aug 22 00:51:45 2017 +0300 @@ -318,20 +318,6 @@ #endif // DM_GFX_BLITS -/* Misc functions - */ -#ifdef DM_GFX_MISC - -void dmFillRect(SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col); -void dmDrawHLine(SDL_Surface *screen, int x0, int x1, int yc, const Uint32 col); -void dmDrawVLine(SDL_Surface *screen, int y0, int y1, int xc, const Uint32 col); - -void dmDrawBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 ucol, Uint32 dcol); -void dmFillBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 bgcol, Uint32 ucol, Uint32 dcol); - -#endif // DM_GFX_MISC - - static inline void dmClearSurface(SDL_Surface *screen, const Uint32 col) { SDL_FillRect(screen, NULL, col);
--- a/tools/auval.c Mon Aug 21 15:46:21 2017 +0300 +++ b/tools/auval.c Tue Aug 22 00:51:45 2017 +0300 @@ -176,11 +176,12 @@ if (pos < 0) return -1; - else if (pos >= buf->len) { + else + if (pos >= buf->len) buf->data[buf->len++] = ch; - } else { + else buf->data[pos] = ch; - } + buf->dirty = TRUE; return 0; } @@ -194,7 +195,9 @@ return -1; else if (pos >= buf->len) { buf->data[buf->len] = ch; - } else { + } + else + { memmove(&(buf->data[pos+1]), &(buf->data[pos]), buf->len - pos + 1); buf->data[pos] = ch; } @@ -208,7 +211,9 @@ { if (pos < 0) return -1; - else if (pos < buf->len) { + else + if (pos < buf->len) + { memmove(&(buf->data[pos]), &(buf->data[pos+1]), buf->len - pos); buf->len--; buf->dirty = TRUE; @@ -313,6 +318,112 @@ } +void dmFillRect(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 col) +{ + SDL_Rect rc; + rc.x = x0; + rc.y = y0; + rc.w = x1 - x0 + 1; + rc.h = y1 - y0 + 1; + SDL_FillRect(screen, &rc, col); +} + + +void dmDrawHLine(SDL_Surface *screen, int x0, int x1, int yc, const Uint32 col) +{ + const int bpp = screen->format->BytesPerPixel, + cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y, + cx1 = screen->clip_rect.x + screen->clip_rect.w - 1, + cy1 = screen->clip_rect.y + screen->clip_rect.h - 1; + + DM_SWAP(int, x0, x1); + if (yc < cy0|| yc > cy1 || x1 < cx0 || x0 > cx1) return; + if (x0 < cx0) x0 = cx0; + if (x1 > cx1) x1 = cx1; + + int x = x1 - x0 + 1; + Uint8 *pix = ((Uint8 *) screen->pixels) + yc * screen->pitch + (x0 * bpp); + switch (screen->format->BitsPerPixel) + { + case 8: + while (x--) + *pix++ = col; + break; + + case 32: + { + Uint32 *p = (Uint32 *) pix; + while (x--) + *p++ = col; + } + break; + } +} + + +void dmDrawVLine(SDL_Surface *screen, int y0, int y1, int xc, const Uint32 col) +{ + const int bpp = screen->format->BytesPerPixel, + pitch = screen->pitch / bpp, + cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y, + cx1 = screen->clip_rect.x + screen->clip_rect.w - 1, + cy1 = screen->clip_rect.y + screen->clip_rect.h - 1; + + DM_SWAP(int, y0, y1); + if (xc < cx0 || xc > cx1 || y1 < cy0 || y0 > cy1) return; + if (y0 < cy0) y0 = cy0; + if (y1 > cy1) y1 = cy1; + + int y = y1 - y0 + 1; + Uint8 *pix = ((Uint8 *) screen->pixels) + y0 * screen->pitch + (xc * bpp); + switch (screen->format->BitsPerPixel) + { + case 8: + while (y--) + { + *pix = col; + pix += pitch; + } + break; + + case 32: + { + Uint32 *p = (Uint32 *) pix; + while (y--) + { + *p = col; + p += pitch; + } + } + break; + } +} + + +void dmDrawBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 ucol, Uint32 dcol) +{ + dmDrawHLine(screen, x0 , x1 - 1, y0, ucol); + dmDrawHLine(screen, x0 + 1, x1 , y1, dcol); + + dmDrawVLine(screen, y0 , y1 - 1, x0, ucol); + dmDrawVLine(screen, y0 + 1, y1 , x1, dcol); +} + + +void dmFillBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 bgcol, Uint32 ucol, Uint32 dcol) +{ + SDL_Rect rc; + + rc.x = x0 + 1; + rc.y = y0 + 1; + rc.w = x1 - x0 - 1; + rc.h = y1 - y0 - 1; + SDL_FillRect(screen, &rc, bgcol); + + dmDrawBox3D(screen, x0, y0, x1, y1, ucol, dcol); +} + + BOOL au_init_video(SDL_Surface **screen) { *screen = SDL_SetVideoMode(optScrWidth, optScrHeight, optScrDepth, optVFlags | SDL_RESIZABLE);
--- a/tools/ppl.c Mon Aug 21 15:46:21 2017 +0300 +++ b/tools/ppl.c Tue Aug 22 00:51:45 2017 +0300 @@ -175,6 +175,112 @@ } +void dmFillRect(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 col) +{ + SDL_Rect rc; + rc.x = x0; + rc.y = y0; + rc.w = x1 - x0 + 1; + rc.h = y1 - y0 + 1; + SDL_FillRect(screen, &rc, col); +} + + +void dmDrawHLine(SDL_Surface *screen, int x0, int x1, int yc, const Uint32 col) +{ + const int bpp = screen->format->BytesPerPixel, + cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y, + cx1 = screen->clip_rect.x + screen->clip_rect.w - 1, + cy1 = screen->clip_rect.y + screen->clip_rect.h - 1; + + DM_SWAP(int, x0, x1); + if (yc < cy0|| yc > cy1 || x1 < cx0 || x0 > cx1) return; + if (x0 < cx0) x0 = cx0; + if (x1 > cx1) x1 = cx1; + + int x = x1 - x0 + 1; + Uint8 *pix = ((Uint8 *) screen->pixels) + yc * screen->pitch + (x0 * bpp); + switch (screen->format->BitsPerPixel) + { + case 8: + while (x--) + *pix++ = col; + break; + + case 32: + { + Uint32 *p = (Uint32 *) pix; + while (x--) + *p++ = col; + } + break; + } +} + + +void dmDrawVLine(SDL_Surface *screen, int y0, int y1, int xc, const Uint32 col) +{ + const int bpp = screen->format->BytesPerPixel, + pitch = screen->pitch / bpp, + cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y, + cx1 = screen->clip_rect.x + screen->clip_rect.w - 1, + cy1 = screen->clip_rect.y + screen->clip_rect.h - 1; + + DM_SWAP(int, y0, y1); + if (xc < cx0 || xc > cx1 || y1 < cy0 || y0 > cy1) return; + if (y0 < cy0) y0 = cy0; + if (y1 > cy1) y1 = cy1; + + int y = y1 - y0 + 1; + Uint8 *pix = ((Uint8 *) screen->pixels) + y0 * screen->pitch + (xc * bpp); + switch (screen->format->BitsPerPixel) + { + case 8: + while (y--) + { + *pix = col; + pix += pitch; + } + break; + + case 32: + { + Uint32 *p = (Uint32 *) pix; + while (y--) + { + *p = col; + p += pitch; + } + } + break; + } +} + + +void dmDrawBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 ucol, Uint32 dcol) +{ + dmDrawHLine(screen, x0 , x1 - 1, y0, ucol); + dmDrawHLine(screen, x0 + 1, x1 , y1, dcol); + + dmDrawVLine(screen, y0 , y1 - 1, x0, ucol); + dmDrawVLine(screen, y0 + 1, y1 , x1, dcol); +} + + +void dmFillBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 bgcol, Uint32 ucol, Uint32 dcol) +{ + SDL_Rect rc; + + rc.x = x0 + 1; + rc.y = y0 + 1; + rc.w = x1 - x0 - 1; + rc.h = y1 - y0 - 1; + SDL_FillRect(screen, &rc, bgcol); + + dmDrawBox3D(screen, x0, y0, x1, y1, ucol, dcol); +} + + void dmDrawBMTextConstQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt) { const char *ptr = fmt;