imtk

diff src/slider.c @ 14:df2bc9406561

added gradients
author John Tsiombikas <nuclear@siggraph.org>
date Tue, 19 Apr 2011 03:01:46 +0300
parents 10604ff95527
children c7a7ddbe7714
line diff
     1.1 --- a/src/slider.c	Mon Apr 18 06:15:46 2011 +0300
     1.2 +++ b/src/slider.c	Tue Apr 19 03:01:46 2011 +0300
     1.3 @@ -1,4 +1,5 @@
     1.4  #include <stdio.h>
     1.5 +#include <string.h>
     1.6  #include <assert.h>
     1.7  #include "imtk.h"
     1.8  #include "state.h"
     1.9 @@ -8,7 +9,7 @@
    1.10  #define THUMB_WIDTH		10
    1.11  #define THUMB_HEIGHT	20
    1.12  
    1.13 -static void draw_slider(int id, float pos, float min, float max, int x, int y);
    1.14 +static void draw_slider(int id, float pos, float min, float max, int x, int y, int over);
    1.15  
    1.16  float imtk_slider(int id, float pos, float min, float max, int x, int y)
    1.17  {
    1.18 @@ -58,32 +59,40 @@
    1.19  		if(pos > 1.0) pos = 1.0;
    1.20  	}
    1.21  
    1.22 -	draw_slider(id, pos, min, max, x, y);
    1.23 +	draw_slider(id, pos, min, max, x, y, over);
    1.24  	return pos * range + min;
    1.25  }
    1.26  
    1.27  
    1.28 -static void draw_slider(int id, float pos, float min, float max, int x, int y)
    1.29 +static void draw_slider(int id, float pos, float min, float max, int x, int y, int over)
    1.30  {
    1.31  	float range = max - min;
    1.32  	int thumb_x, thumb_y;
    1.33  	char buf[32];
    1.34 +	float tcol[4], bcol[4];
    1.35 +	unsigned int attr = 0;
    1.36  
    1.37  	thumb_x = x + SLIDER_SIZE * pos - THUMB_WIDTH / 2;
    1.38  	thumb_y = y - THUMB_HEIGHT / 2;
    1.39  
    1.40 +	memcpy(tcol, imtk_get_color(IMTK_BOTTOM_COLOR), sizeof tcol);
    1.41 +	memcpy(bcol, imtk_get_color(IMTK_TOP_COLOR), sizeof bcol);
    1.42 +
    1.43  	/* draw trough */
    1.44 -	imtk_draw_rect(x, y - 2, SLIDER_SIZE, 4, imtk_get_color(IMTK_BASE_COLOR));
    1.45 -	imtk_draw_frame(x, y - 2, SLIDER_SIZE, 4, FRAME_INSET);
    1.46 +	imtk_draw_rect(x, y - 2, SLIDER_SIZE, 5, tcol, bcol);
    1.47 +	imtk_draw_frame(x, y - 2, SLIDER_SIZE, 5, FRAME_INSET);
    1.48  
    1.49 -	if(imtk_hit_test(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT)) {
    1.50 -		glColor4fv(imtk_get_color(IMTK_FOCUS_COLOR));
    1.51 -	} else {
    1.52 -		glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
    1.53 +	if(over) {
    1.54 +		attr |= IMTK_FOCUS_BIT;
    1.55  	}
    1.56 +	if(imtk_is_active(id)) {
    1.57 +		attr |= IMTK_PRESS_BIT;
    1.58 +	}
    1.59 +	memcpy(tcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof tcol);
    1.60 +	memcpy(bcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof bcol);
    1.61  
    1.62  	/* draw handle */
    1.63 -	imtk_draw_rect(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT, 0);
    1.64 +	imtk_draw_rect(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT, tcol, bcol);
    1.65  	imtk_draw_frame(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT, FRAME_OUTSET);
    1.66  
    1.67  	/* draw display */