comparison tools/ppl.c @ 1327:59e9ad13b50e

Move common functions to libgutil.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 22 Aug 2017 13:18:21 +0300
parents 2260ed90ab6b
children 2603f6ca632e
comparison
equal deleted inserted replaced
1326:a265982662cd 1327:59e9ad13b50e
3 * Programmed and designed by Matti 'ccr' Hamalainen 3 * Programmed and designed by Matti 'ccr' Hamalainen
4 * (C) Copyright 2012-2015 Tecnic Software productions (TNSP) 4 * (C) Copyright 2012-2015 Tecnic Software productions (TNSP)
5 * 5 *
6 * Please read file 'COPYING' for information on license and distribution. 6 * Please read file 'COPYING' for information on license and distribution.
7 */ 7 */
8 #include <SDL.h>
9 #include "dmlib.h" 8 #include "dmlib.h"
9 #include "libgutil.h"
10 10
11 #include "jss.h" 11 #include "jss.h"
12 #include "jssmod.h" 12 #include "jssmod.h"
13 #include "jssmix.h" 13 #include "jssmix.h"
14 #include "jssplr.h" 14 #include "jssplr.h"
173 173
174 return TRUE; 174 return TRUE;
175 } 175 }
176 176
177 177
178 void dmFillRect(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 col) 178 static inline Uint32 dmCol(const float r, const float g, const float b)
179 {
180 SDL_Rect rc;
181 rc.x = x0;
182 rc.y = y0;
183 rc.w = x1 - x0 + 1;
184 rc.h = y1 - y0 + 1;
185 SDL_FillRect(screen, &rc, col);
186 }
187
188
189 void dmDrawHLine(SDL_Surface *screen, int x0, int x1, int yc, const Uint32 col)
190 {
191 const int bpp = screen->format->BytesPerPixel,
192 cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y,
193 cx1 = screen->clip_rect.x + screen->clip_rect.w - 1,
194 cy1 = screen->clip_rect.y + screen->clip_rect.h - 1;
195
196 DM_SWAP(int, x0, x1);
197 if (yc < cy0|| yc > cy1 || x1 < cx0 || x0 > cx1) return;
198 if (x0 < cx0) x0 = cx0;
199 if (x1 > cx1) x1 = cx1;
200
201 int x = x1 - x0 + 1;
202 Uint8 *pix = ((Uint8 *) screen->pixels) + yc * screen->pitch + (x0 * bpp);
203 switch (screen->format->BitsPerPixel)
204 {
205 case 8:
206 while (x--)
207 *pix++ = col;
208 break;
209
210 case 32:
211 {
212 Uint32 *p = (Uint32 *) pix;
213 while (x--)
214 *p++ = col;
215 }
216 break;
217 }
218 }
219
220
221 void dmDrawVLine(SDL_Surface *screen, int y0, int y1, int xc, const Uint32 col)
222 {
223 const int bpp = screen->format->BytesPerPixel,
224 pitch = screen->pitch / bpp,
225 cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y,
226 cx1 = screen->clip_rect.x + screen->clip_rect.w - 1,
227 cy1 = screen->clip_rect.y + screen->clip_rect.h - 1;
228
229 DM_SWAP(int, y0, y1);
230 if (xc < cx0 || xc > cx1 || y1 < cy0 || y0 > cy1) return;
231 if (y0 < cy0) y0 = cy0;
232 if (y1 > cy1) y1 = cy1;
233
234 int y = y1 - y0 + 1;
235 Uint8 *pix = ((Uint8 *) screen->pixels) + y0 * screen->pitch + (xc * bpp);
236 switch (screen->format->BitsPerPixel)
237 {
238 case 8:
239 while (y--)
240 {
241 *pix = col;
242 pix += pitch;
243 }
244 break;
245
246 case 32:
247 {
248 Uint32 *p = (Uint32 *) pix;
249 while (y--)
250 {
251 *p = col;
252 p += pitch;
253 }
254 }
255 break;
256 }
257 }
258
259
260 void dmDrawBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 ucol, Uint32 dcol)
261 {
262 dmDrawHLine(screen, x0 , x1 - 1, y0, ucol);
263 dmDrawHLine(screen, x0 + 1, x1 , y1, dcol);
264
265 dmDrawVLine(screen, y0 , y1 - 1, x0, ucol);
266 dmDrawVLine(screen, y0 + 1, y1 , x1, dcol);
267 }
268
269
270 void dmFillBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 bgcol, Uint32 ucol, Uint32 dcol)
271 {
272 SDL_Rect rc;
273
274 rc.x = x0 + 1;
275 rc.y = y0 + 1;
276 rc.w = x1 - x0 - 1;
277 rc.h = y1 - y0 - 1;
278 SDL_FillRect(screen, &rc, bgcol);
279
280 dmDrawBox3D(screen, x0, y0, x1, y1, ucol, dcol);
281 }
282
283
284 void dmDrawBMTextConstQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt)
285 {
286 const char *ptr = fmt;
287 DMUnscaledBlitFunc blit = NULL;
288
289 while (*ptr)
290 {
291 int ch = toupper(*ptr++);
292 SDL_Surface *glyph;
293
294 if (ch == '_')
295 {
296 xc += 4;
297 continue;
298 }
299
300 if (ch >= 0 && ch < font->nglyphs && (glyph = font->glyphs[ch]) != NULL)
301 {
302 if (blit == NULL)
303 blit = dmGetUnscaledBlitFunc(glyph->format, screen->format, mode);
304
305 blit(glyph, xc, yc, screen);
306 xc += font->width;
307 }
308 else
309 xc += font->width;
310 }
311 }
312
313
314 void dmDrawBMTextVAQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, va_list ap)
315 {
316 char tmp[512];
317 vsnprintf(tmp, sizeof(tmp), fmt, ap);
318 dmDrawBMTextConstQ(screen, font, mode, xc, yc, tmp);
319 }
320
321
322 void dmDrawBMTextQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, ...)
323 {
324 va_list ap;
325
326 va_start(ap, fmt);
327 dmDrawBMTextVAQ(screen, font, mode, xc, yc, fmt, ap);
328 va_end(ap);
329 }
330
331
332 Uint32 dmCol(float r, float g, float b)
333 { 179 {
334 return dmMapRGB(engine.screen, 255.0f * r, 255.0f * g, 255.0f * b); 180 return dmMapRGB(engine.screen, 255.0f * r, 255.0f * g, 255.0f * b);
335 } 181 }
336 182
337 183
359 205
360 return TRUE; 206 return TRUE;
361 } 207 }
362 208
363 209
210 //
211 // XXX TODO: To display actual continuous sample data for channel,
212 // we would need to have separate "FIFO" buffers for each, updating
213 // them with new data from incoming channel data.
214 //
364 void dmDisplayChn(SDL_Surface *screen, int x0, int y0, int x1, int y1, int nchannel, JSSChannel *chn) 215 void dmDisplayChn(SDL_Surface *screen, int x0, int y0, int x1, int y1, int nchannel, JSSChannel *chn)
365 { 216 {
366 int yh = y1 - y0 - 2; 217 int yh = y1 - y0 - 2;
367 if (yh < 10 || chn == NULL) 218 if (yh < 10 || chn == NULL)
368 return; 219 return;
470 321
471 static inline char dmHexVal(int v) 322 static inline char dmHexVal(int v)
472 { 323 {
473 return jmpHexTab[v & 15]; 324 return jmpHexTab[v & 15];
474 } 325 }
326
475 327
476 void dmPrintNote(SDL_Surface *screen, int xc, int yc, JSSNote *n) 328 void dmPrintNote(SDL_Surface *screen, int xc, int yc, JSSNote *n)
477 { 329 {
478 char text[32]; 330 char text[32];
479 char *ptr = text; 331 char *ptr = text;
654 { 506 {
655 int i; 507 int i;
656 for (i = 0; i < engine.mod->nchannels; i++) 508 for (i = 0; i < engine.mod->nchannels; i++)
657 jvmMute(engine.dev, i, mute); 509 jvmMute(engine.dev, i, mute);
658 } 510 }
511
659 512
660 int main(int argc, char *argv[]) 513 int main(int argc, char *argv[])
661 { 514 {
662 BOOL initSDL = FALSE, audioInit = FALSE; 515 BOOL initSDL = FALSE, audioInit = FALSE;
663 DMResource *file = NULL; 516 DMResource *file = NULL;