imtk

changeset 19:11da537aeba6

blah
author John Tsiombikas <nuclear@siggraph.org>
date Tue, 26 Apr 2011 22:53:21 +0300
parents 737e9047d9c9
children c7a7ddbe7714
files src/draw.c src/draw.h src/listbox.c
diffstat 3 files changed, 93 insertions(+), 43 deletions(-) [+]
line diff
     1.1 --- a/src/draw.c	Mon Apr 25 08:54:05 2011 +0300
     1.2 +++ b/src/draw.c	Tue Apr 26 22:53:21 2011 +0300
     1.3 @@ -116,45 +116,6 @@
     1.4  	glEnd();
     1.5  }
     1.6  
     1.7 -void imtk_draw_disc(int x, int y, float rad, int subdiv, float *ctop, float *cbot)
     1.8 -{
     1.9 -	int i;
    1.10 -	float t, dtheta, theta = 0.0;
    1.11 -	float color[4];
    1.12 -	float cx = (float)x;
    1.13 -	float cy = (float)y;
    1.14 -
    1.15 -	subdiv += 3;
    1.16 -	dtheta = 2.0 * M_PI / subdiv;
    1.17 -
    1.18 -	color[0] = (ctop[0] + cbot[0]) * 0.5;
    1.19 -	color[1] = (ctop[1] + cbot[1]) * 0.5;
    1.20 -	color[2] = (ctop[2] + cbot[2]) * 0.5;
    1.21 -	color[3] = (ctop[3] + cbot[3]) * 0.5;
    1.22 -
    1.23 -	glBegin(GL_TRIANGLE_FAN);
    1.24 -	glColor4fv(color);
    1.25 -	glVertex2f(cx, cy);
    1.26 -
    1.27 -	for(i=0; i<=subdiv; i++) {
    1.28 -		float vx, vy;
    1.29 -
    1.30 -		vx = cx + cos(theta) * rad;
    1.31 -		vy = cy + sin(theta) * rad;
    1.32 -		theta += dtheta;
    1.33 -
    1.34 -		t = (vy - (cy - rad)) / (2.0 * rad);
    1.35 -		color[0] = ctop[0] + (cbot[0] - ctop[0]) * t;
    1.36 -		color[1] = ctop[1] + (cbot[1] - ctop[1]) * t;
    1.37 -		color[2] = ctop[2] + (cbot[2] - ctop[2]) * t;
    1.38 -		color[3] = ctop[3] + (cbot[3] - ctop[3]) * t;
    1.39 -
    1.40 -		glColor4fv(color);
    1.41 -		glVertex2f(vx, vy);
    1.42 -	}
    1.43 -	glEnd();
    1.44 -}
    1.45 -
    1.46  void imtk_draw_frame(int x, int y, int w, int h, int style)
    1.47  {
    1.48  	float tcol[4], bcol[4];
    1.49 @@ -206,6 +167,93 @@
    1.50  	glEnd();
    1.51  }
    1.52  
    1.53 +void imtk_draw_disc(int x, int y, float rad, int subdiv, float *ctop, float *cbot)
    1.54 +{
    1.55 +	int i;
    1.56 +	float t, dtheta, theta = 0.0;
    1.57 +	float color[4];
    1.58 +	float cx = (float)x;
    1.59 +	float cy = (float)y;
    1.60 +
    1.61 +	subdiv += 3;
    1.62 +	dtheta = 2.0 * M_PI / subdiv;
    1.63 +
    1.64 +	color[0] = (ctop[0] + cbot[0]) * 0.5;
    1.65 +	color[1] = (ctop[1] + cbot[1]) * 0.5;
    1.66 +	color[2] = (ctop[2] + cbot[2]) * 0.5;
    1.67 +	color[3] = (ctop[3] + cbot[3]) * 0.5;
    1.68 +
    1.69 +	glBegin(GL_TRIANGLE_FAN);
    1.70 +	glColor4fv(color);
    1.71 +	glVertex2f(cx, cy);
    1.72 +
    1.73 +	for(i=0; i<=subdiv; i++) {
    1.74 +		float vx, vy;
    1.75 +
    1.76 +		vx = cos(theta);
    1.77 +		vy = sin(theta);
    1.78 +		theta += dtheta;
    1.79 +
    1.80 +		t = (vy + 1.0) / 2.0;
    1.81 +		color[0] = ctop[0] + (cbot[0] - ctop[0]) * t;
    1.82 +		color[1] = ctop[1] + (cbot[1] - ctop[1]) * t;
    1.83 +		color[2] = ctop[2] + (cbot[2] - ctop[2]) * t;
    1.84 +		color[3] = ctop[3] + (cbot[3] - ctop[3]) * t;
    1.85 +
    1.86 +		glColor4fv(color);
    1.87 +		glVertex2f(cx + vx * rad, cy + vy * rad);
    1.88 +	}
    1.89 +	glEnd();
    1.90 +}
    1.91 +
    1.92 +void imtk_draw_disc_frame(int x, int y, float inner, float outer, int subdiv, int style)
    1.93 +{
    1.94 +	int i;
    1.95 +	float t, dtheta, theta = 0.0;
    1.96 +	float color[4], tcol[4], bcol[4];
    1.97 +	float cx = (float)x;
    1.98 +	float cy = (float)y;
    1.99 +
   1.100 +	switch(style) {
   1.101 +	case FRAME_INSET:
   1.102 +		memcpy(tcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof tcol);
   1.103 +		memcpy(bcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof bcol);
   1.104 +		break;
   1.105 +
   1.106 +	case FRAME_OUTSET:
   1.107 +	default:
   1.108 +		memcpy(tcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof tcol);
   1.109 +		memcpy(bcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof bcol);
   1.110 +	}
   1.111 +
   1.112 +	subdiv += 3;
   1.113 +	dtheta = 2.0 * M_PI / subdiv;
   1.114 +
   1.115 +	glBegin(GL_QUAD_STRIP);
   1.116 +
   1.117 +	for(i=0; i<=subdiv; i++) {
   1.118 +		float vx, vy;
   1.119 +
   1.120 +		vx = cos(theta);
   1.121 +		vy = sin(theta);
   1.122 +
   1.123 +		t = (vy + 1.0) / 2.0;
   1.124 +		color[0] = tcol[0] + (bcol[0] - tcol[0]) * t;
   1.125 +		color[1] = tcol[1] + (bcol[1] - tcol[1]) * t;
   1.126 +		color[2] = tcol[2] + (bcol[2] - tcol[2]) * t;
   1.127 +		color[3] = tcol[3] + (bcol[3] - tcol[3]) * t;
   1.128 +
   1.129 +		vx = cos(theta - M_PI / 4.0);
   1.130 +		vy = sin(theta - M_PI / 4.0);
   1.131 +		theta += dtheta;
   1.132 +
   1.133 +		glColor4fv(color);
   1.134 +		glVertex2f(cx + vx * inner, cy + vy * inner);
   1.135 +		glVertex2f(cx + vx * outer, cy + vy * outer);
   1.136 +	}
   1.137 +	glEnd();
   1.138 +}
   1.139 +
   1.140  void imtk_draw_string(int x, int y, const char *str)
   1.141  {
   1.142  	glRasterPos2i(x, y);
     2.1 --- a/src/draw.h	Mon Apr 25 08:54:05 2011 +0300
     2.2 +++ b/src/draw.h	Tue Apr 26 22:53:21 2011 +0300
     2.3 @@ -14,9 +14,9 @@
     2.4  };
     2.5  
     2.6  void imtk_draw_rect(int x, int y, int w, int h, float *ctop, float *cbot);
     2.7 +void imtk_draw_frame(int x, int y, int w, int h, int style);
     2.8  void imtk_draw_disc(int x, int y, float rad, int subdiv, float *ctop, float *cbot);
     2.9 -
    2.10 -void imtk_draw_frame(int x, int y, int w, int h, int style);
    2.11 +void imtk_draw_disc_frame(int x, int y, float inner, float outer, int subdiv, int style);
    2.12  void imtk_draw_string(int x, int y, const char *str);
    2.13  int imtk_string_size(const char *str);
    2.14  
     3.1 --- a/src/listbox.c	Mon Apr 25 08:54:05 2011 +0300
     3.2 +++ b/src/listbox.c	Tue Apr 26 22:53:21 2011 +0300
     3.3 @@ -155,15 +155,17 @@
     3.4  			attr |= IMTK_FOCUS_BIT;
     3.5  		}
     3.6  
     3.7 +		imtk_draw_disc_frame(x + rad, item_y + rad, rad * 0.9, rad * 0.75, 5, FRAME_INSET);
     3.8 +
     3.9  		memcpy(tcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof tcol);
    3.10  		memcpy(bcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof bcol);
    3.11 -
    3.12 -		imtk_draw_disc(x + rad, item_y + rad, rad * 0.8, 5, tcol, bcol);
    3.13 +		imtk_draw_disc(x + rad, item_y + rad, rad * 0.75, 5, tcol, bcol);
    3.14  
    3.15  		if(i == sel) {
    3.16  			attr |= IMTK_SEL_BIT;
    3.17  			memcpy(tcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof tcol);
    3.18  			memcpy(bcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof bcol);
    3.19 +
    3.20  			imtk_draw_disc(x + rad, item_y + ITEM_HEIGHT / 2, rad * 0.6, 5, tcol, bcol);
    3.21  		}
    3.22