# HG changeset patch # User Matti Hamalainen # Date 1503397101 -10800 # Node ID 59e9ad13b50e4a709e8a0c7216bb95751a36d0c1 # Parent a265982662cd7dbb79ebe89a8ded72bc4823d6f0 Move common functions to libgutil. diff -r a265982662cd -r 59e9ad13b50e Makefile.gen --- a/Makefile.gen Tue Aug 22 02:05:40 2017 +0300 +++ b/Makefile.gen Tue Aug 22 13:18:21 2017 +0300 @@ -497,7 +497,7 @@ @echo " LINK $+" @$(CC) -o $@ $(filter %.o %.a,$+) $(DM_LDFLAGS) $(TOOL_LDFLAGS) $(DM_ZLIB_LDFLAGS) -$(TOOL_BINPATH)ppl$(EXEEXT): $(DMLIBSRC)setupfont.h $(OBJPATH)ppl.o $(DMLIB_A) +$(TOOL_BINPATH)ppl$(EXEEXT): $(DMLIBSRC)setupfont.h $(OBJPATH)ppl.o $(OBJPATH)libgutil.o $(DMLIB_A) @echo " LINK $+" @$(CC) -o $@ $(filter %.o %.a,$+) $(DM_LDFLAGS) $(DM_ZLIB_LDFLAGS) $(SDL_LDFLAGS) -lm @@ -517,7 +517,7 @@ @echo " LINK $+" @$(CC) -o $@ $(filter %.o %.a,$+) $(DM_LDFLAGS) $(TOOL_LDFLAGS) -lm -$(TOOL_BINPATH)auval$(EXEEXT): $(OBJPATH)auval.o $(OBJPATH)dmeval.o $(OBJPATH)dmevalw.o $(DMLIB_A) +$(TOOL_BINPATH)auval$(EXEEXT): $(OBJPATH)auval.o $(OBJPATH)dmeval.o $(OBJPATH)dmevalw.o $(OBJPATH)libgutil.o $(DMLIB_A) @echo " LINK $+" @$(CC) -o $@ $(filter %.o %.a,$+) $(DM_LDFLAGS) $(SDL_LDFLAGS) $(SDL_TTF_LDFLAGS) -lm diff -r a265982662cd -r 59e9ad13b50e tools/auval.c --- a/tools/auval.c Tue Aug 22 02:05:40 2017 +0300 +++ b/tools/auval.c Tue Aug 22 13:18:21 2017 +0300 @@ -1,9 +1,11 @@ #include "dmlib.h" +#include "libgutil.h" #include "dmargs.h" #include "dmeval.h" #include "dmtext.h" #include + #define AUVAL_NAME "AuVal" #define AUVAL_VERSION "0.6" #define AUVAL_TMPBUF_SIZE (4096) @@ -318,112 +320,6 @@ } -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); diff -r a265982662cd -r 59e9ad13b50e tools/libgutil.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libgutil.c Tue Aug 22 13:18:21 2017 +0300 @@ -0,0 +1,162 @@ +/* + * Common graphics utility functions for tools + * Programmed and designed by Matti 'ccr' Hamalainen + * (C) Copyright 2012-2015 Tecnic Software productions (TNSP) + * + * Please read file 'COPYING' for information on license and distribution. + */ +#include "libgutil.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); +} + + +void dmDrawBMTextConstQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt) +{ + const char *ptr = fmt; + DMUnscaledBlitFunc blit = NULL; + + while (*ptr) + { + int ch = toupper(*ptr++); + SDL_Surface *glyph; + + if (ch == '_') + { + xc += 4; + continue; + } + + if (ch >= 0 && ch < font->nglyphs && (glyph = font->glyphs[ch]) != NULL) + { + if (blit == NULL) + blit = dmGetUnscaledBlitFunc(glyph->format, screen->format, mode); + + blit(glyph, xc, yc, screen); + xc += font->width; + } + else + xc += font->width; + } +} + + +void dmDrawBMTextVAQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, va_list ap) +{ + char tmp[512]; + vsnprintf(tmp, sizeof(tmp), fmt, ap); + dmDrawBMTextConstQ(screen, font, mode, xc, yc, tmp); +} + + +void dmDrawBMTextQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + dmDrawBMTextVAQ(screen, font, mode, xc, yc, fmt, ap); + va_end(ap); +} diff -r a265982662cd -r 59e9ad13b50e tools/libgutil.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libgutil.h Tue Aug 22 13:18:21 2017 +0300 @@ -0,0 +1,32 @@ +/* + * Common graphics utility functions for tools + * Programmed and designed by Matti 'ccr' Hamalainen + * (C) Copyright 2012-2015 Tecnic Software productions (TNSP) + * + * Please read file 'COPYING' for information on license and distribution. + */ +#ifndef LIBGUTIL_H +#define LIBGUTIL_H 1 + +#include "dmlib.h" +#include "dmtext.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void dmFillRect(SDL_Surface *screen, int x0, int y0, int x1, int y1, 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); +void dmDrawBMTextConstQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt); +void dmDrawBMTextVAQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, va_list ap); +void dmDrawBMTextQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, ...); + + +#ifdef __cplusplus +} +#endif + +#endif // LIBGUTIL_H diff -r a265982662cd -r 59e9ad13b50e tools/ppl.c --- a/tools/ppl.c Tue Aug 22 02:05:40 2017 +0300 +++ b/tools/ppl.c Tue Aug 22 13:18:21 2017 +0300 @@ -5,8 +5,8 @@ * * Please read file 'COPYING' for information on license and distribution. */ -#include #include "dmlib.h" +#include "libgutil.h" #include "jss.h" #include "jssmod.h" @@ -175,161 +175,7 @@ } -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; - DMUnscaledBlitFunc blit = NULL; - - while (*ptr) - { - int ch = toupper(*ptr++); - SDL_Surface *glyph; - - if (ch == '_') - { - xc += 4; - continue; - } - - if (ch >= 0 && ch < font->nglyphs && (glyph = font->glyphs[ch]) != NULL) - { - if (blit == NULL) - blit = dmGetUnscaledBlitFunc(glyph->format, screen->format, mode); - - blit(glyph, xc, yc, screen); - xc += font->width; - } - else - xc += font->width; - } -} - - -void dmDrawBMTextVAQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, va_list ap) -{ - char tmp[512]; - vsnprintf(tmp, sizeof(tmp), fmt, ap); - dmDrawBMTextConstQ(screen, font, mode, xc, yc, tmp); -} - - -void dmDrawBMTextQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - dmDrawBMTextVAQ(screen, font, mode, xc, yc, fmt, ap); - va_end(ap); -} - - -Uint32 dmCol(float r, float g, float b) +static inline Uint32 dmCol(const float r, const float g, const float b) { return dmMapRGB(engine.screen, 255.0f * r, 255.0f * g, 255.0f * b); } @@ -361,6 +207,11 @@ } +// +// XXX TODO: To display actual continuous sample data for channel, +// we would need to have separate "FIFO" buffers for each, updating +// them with new data from incoming channel data. +// void dmDisplayChn(SDL_Surface *screen, int x0, int y0, int x1, int y1, int nchannel, JSSChannel *chn) { int yh = y1 - y0 - 2; @@ -473,6 +324,7 @@ return jmpHexTab[v & 15]; } + void dmPrintNote(SDL_Surface *screen, int xc, int yc, JSSNote *n) { char text[32]; @@ -657,6 +509,7 @@ jvmMute(engine.dev, i, mute); } + int main(int argc, char *argv[]) { BOOL initSDL = FALSE, audioInit = FALSE;