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