imtk

annotate src/progress.c @ 23:4c2b3e281409

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