Mercurial > hg > dmlib
comparison tools/auval.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 |
comparison
equal
deleted
inserted
replaced
1326:a265982662cd | 1327:59e9ad13b50e |
---|---|
1 #include "dmlib.h" | 1 #include "dmlib.h" |
2 #include "libgutil.h" | |
2 #include "dmargs.h" | 3 #include "dmargs.h" |
3 #include "dmeval.h" | 4 #include "dmeval.h" |
4 #include "dmtext.h" | 5 #include "dmtext.h" |
5 #include <math.h> | 6 #include <math.h> |
7 | |
6 | 8 |
7 #define AUVAL_NAME "AuVal" | 9 #define AUVAL_NAME "AuVal" |
8 #define AUVAL_VERSION "0.6" | 10 #define AUVAL_VERSION "0.6" |
9 #define AUVAL_TMPBUF_SIZE (4096) | 11 #define AUVAL_TMPBUF_SIZE (4096) |
10 #define AUVAL_HISTORY_FILE "history.txt" | 12 #define AUVAL_HISTORY_FILE "history.txt" |
313 buf->pos = 0; | 315 buf->pos = 0; |
314 else if (pos >= buf->len) | 316 else if (pos >= buf->len) |
315 buf->pos = buf->len; | 317 buf->pos = buf->len; |
316 else | 318 else |
317 buf->pos = pos; | 319 buf->pos = pos; |
318 } | |
319 | |
320 | |
321 void dmFillRect(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 col) | |
322 { | |
323 SDL_Rect rc; | |
324 rc.x = x0; | |
325 rc.y = y0; | |
326 rc.w = x1 - x0 + 1; | |
327 rc.h = y1 - y0 + 1; | |
328 SDL_FillRect(screen, &rc, col); | |
329 } | |
330 | |
331 | |
332 void dmDrawHLine(SDL_Surface *screen, int x0, int x1, int yc, const Uint32 col) | |
333 { | |
334 const int bpp = screen->format->BytesPerPixel, | |
335 cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y, | |
336 cx1 = screen->clip_rect.x + screen->clip_rect.w - 1, | |
337 cy1 = screen->clip_rect.y + screen->clip_rect.h - 1; | |
338 | |
339 DM_SWAP(int, x0, x1); | |
340 if (yc < cy0|| yc > cy1 || x1 < cx0 || x0 > cx1) return; | |
341 if (x0 < cx0) x0 = cx0; | |
342 if (x1 > cx1) x1 = cx1; | |
343 | |
344 int x = x1 - x0 + 1; | |
345 Uint8 *pix = ((Uint8 *) screen->pixels) + yc * screen->pitch + (x0 * bpp); | |
346 switch (screen->format->BitsPerPixel) | |
347 { | |
348 case 8: | |
349 while (x--) | |
350 *pix++ = col; | |
351 break; | |
352 | |
353 case 32: | |
354 { | |
355 Uint32 *p = (Uint32 *) pix; | |
356 while (x--) | |
357 *p++ = col; | |
358 } | |
359 break; | |
360 } | |
361 } | |
362 | |
363 | |
364 void dmDrawVLine(SDL_Surface *screen, int y0, int y1, int xc, const Uint32 col) | |
365 { | |
366 const int bpp = screen->format->BytesPerPixel, | |
367 pitch = screen->pitch / bpp, | |
368 cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y, | |
369 cx1 = screen->clip_rect.x + screen->clip_rect.w - 1, | |
370 cy1 = screen->clip_rect.y + screen->clip_rect.h - 1; | |
371 | |
372 DM_SWAP(int, y0, y1); | |
373 if (xc < cx0 || xc > cx1 || y1 < cy0 || y0 > cy1) return; | |
374 if (y0 < cy0) y0 = cy0; | |
375 if (y1 > cy1) y1 = cy1; | |
376 | |
377 int y = y1 - y0 + 1; | |
378 Uint8 *pix = ((Uint8 *) screen->pixels) + y0 * screen->pitch + (xc * bpp); | |
379 switch (screen->format->BitsPerPixel) | |
380 { | |
381 case 8: | |
382 while (y--) | |
383 { | |
384 *pix = col; | |
385 pix += pitch; | |
386 } | |
387 break; | |
388 | |
389 case 32: | |
390 { | |
391 Uint32 *p = (Uint32 *) pix; | |
392 while (y--) | |
393 { | |
394 *p = col; | |
395 p += pitch; | |
396 } | |
397 } | |
398 break; | |
399 } | |
400 } | |
401 | |
402 | |
403 void dmDrawBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 ucol, Uint32 dcol) | |
404 { | |
405 dmDrawHLine(screen, x0 , x1 - 1, y0, ucol); | |
406 dmDrawHLine(screen, x0 + 1, x1 , y1, dcol); | |
407 | |
408 dmDrawVLine(screen, y0 , y1 - 1, x0, ucol); | |
409 dmDrawVLine(screen, y0 + 1, y1 , x1, dcol); | |
410 } | |
411 | |
412 | |
413 void dmFillBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 bgcol, Uint32 ucol, Uint32 dcol) | |
414 { | |
415 SDL_Rect rc; | |
416 | |
417 rc.x = x0 + 1; | |
418 rc.y = y0 + 1; | |
419 rc.w = x1 - x0 - 1; | |
420 rc.h = y1 - y0 - 1; | |
421 SDL_FillRect(screen, &rc, bgcol); | |
422 | |
423 dmDrawBox3D(screen, x0, y0, x1, y1, ucol, dcol); | |
424 } | 320 } |
425 | 321 |
426 | 322 |
427 BOOL au_init_video(SDL_Surface **screen) | 323 BOOL au_init_video(SDL_Surface **screen) |
428 { | 324 { |