rayfract

diff src/imtk/progress.c @ 10:1496aae2e7d4

- simplified build by including dependences in the source tree - added make dep tracking - added mingw cross-build rules - added readme & licence
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 31 Jul 2023 18:58:56 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/imtk/progress.c	Mon Jul 31 18:58:56 2023 +0300
     1.3 @@ -0,0 +1,44 @@
     1.4 +#include <string.h>
     1.5 +#include "imtk.h"
     1.6 +#include "draw.h"
     1.7 +
     1.8 +#define PROGR_SIZE             100
     1.9 +#define PROGR_HEIGHT			15
    1.10 +
    1.11 +static void draw_progress(int id, float pos, int x, int y);
    1.12 +
    1.13 +void imtk_progress(int id, float pos, int x, int y)
    1.14 +{
    1.15 +	if(x == IMTK_AUTO || y == IMTK_AUTO) {
    1.16 +		imtk_layout_get_pos(&x, &y);
    1.17 +	}
    1.18 +
    1.19 +	draw_progress(id, pos, x, y);
    1.20 +	imtk_layout_advance(PROGR_SIZE, PROGR_HEIGHT);
    1.21 +}
    1.22 +
    1.23 +static void draw_progress(int id, float pos, int x, int y)
    1.24 +{
    1.25 +	int bar_size = PROGR_SIZE * pos;
    1.26 +	float b = imtk_get_bevel_width();
    1.27 +	float tcol[4], bcol[4];
    1.28 +
    1.29 +	if(pos < 0.0) pos = 0.0;
    1.30 +	if(pos > 1.0) pos = 1.0;
    1.31 +
    1.32 +	memcpy(tcol, imtk_get_color(IMTK_BOTTOM_COLOR), sizeof tcol);
    1.33 +	memcpy(bcol, imtk_get_color(IMTK_TOP_COLOR), sizeof bcol);
    1.34 +
    1.35 +	/* trough */
    1.36 +	imtk_draw_rect(x - b, y - b, PROGR_SIZE + b * 2, PROGR_HEIGHT + b * 2, tcol, bcol);
    1.37 +	imtk_draw_frame(x - b, y - b, PROGR_SIZE + b * 2, PROGR_HEIGHT + b * 2, FRAME_INSET);
    1.38 +
    1.39 +	/* bar */
    1.40 +	if(pos > 0.0) {
    1.41 +		memcpy(tcol, imtk_get_color(IMTK_TOP_COLOR), sizeof tcol);
    1.42 +		memcpy(bcol, imtk_get_color(IMTK_BOTTOM_COLOR), sizeof bcol);
    1.43 +
    1.44 +		imtk_draw_rect(x, y, bar_size, PROGR_HEIGHT, tcol, bcol);
    1.45 +		imtk_draw_frame(x, y, bar_size, PROGR_HEIGHT, FRAME_OUTSET);
    1.46 +	}
    1.47 +}