rayfract

annotate 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
rev   line source
nuclear@10 1 #include <string.h>
nuclear@10 2 #include "imtk.h"
nuclear@10 3 #include "draw.h"
nuclear@10 4
nuclear@10 5 #define PROGR_SIZE 100
nuclear@10 6 #define PROGR_HEIGHT 15
nuclear@10 7
nuclear@10 8 static void draw_progress(int id, float pos, int x, int y);
nuclear@10 9
nuclear@10 10 void imtk_progress(int id, float pos, int x, int y)
nuclear@10 11 {
nuclear@10 12 if(x == IMTK_AUTO || y == IMTK_AUTO) {
nuclear@10 13 imtk_layout_get_pos(&x, &y);
nuclear@10 14 }
nuclear@10 15
nuclear@10 16 draw_progress(id, pos, x, y);
nuclear@10 17 imtk_layout_advance(PROGR_SIZE, PROGR_HEIGHT);
nuclear@10 18 }
nuclear@10 19
nuclear@10 20 static void draw_progress(int id, float pos, int x, int y)
nuclear@10 21 {
nuclear@10 22 int bar_size = PROGR_SIZE * pos;
nuclear@10 23 float b = imtk_get_bevel_width();
nuclear@10 24 float tcol[4], bcol[4];
nuclear@10 25
nuclear@10 26 if(pos < 0.0) pos = 0.0;
nuclear@10 27 if(pos > 1.0) pos = 1.0;
nuclear@10 28
nuclear@10 29 memcpy(tcol, imtk_get_color(IMTK_BOTTOM_COLOR), sizeof tcol);
nuclear@10 30 memcpy(bcol, imtk_get_color(IMTK_TOP_COLOR), sizeof bcol);
nuclear@10 31
nuclear@10 32 /* trough */
nuclear@10 33 imtk_draw_rect(x - b, y - b, PROGR_SIZE + b * 2, PROGR_HEIGHT + b * 2, tcol, bcol);
nuclear@10 34 imtk_draw_frame(x - b, y - b, PROGR_SIZE + b * 2, PROGR_HEIGHT + b * 2, FRAME_INSET);
nuclear@10 35
nuclear@10 36 /* bar */
nuclear@10 37 if(pos > 0.0) {
nuclear@10 38 memcpy(tcol, imtk_get_color(IMTK_TOP_COLOR), sizeof tcol);
nuclear@10 39 memcpy(bcol, imtk_get_color(IMTK_BOTTOM_COLOR), sizeof bcol);
nuclear@10 40
nuclear@10 41 imtk_draw_rect(x, y, bar_size, PROGR_HEIGHT, tcol, bcol);
nuclear@10 42 imtk_draw_frame(x, y, bar_size, PROGR_HEIGHT, FRAME_OUTSET);
nuclear@10 43 }
nuclear@10 44 }