imtk

diff src/draw.c @ 18:737e9047d9c9

added radio group
author John Tsiombikas <nuclear@siggraph.org>
date Mon, 25 Apr 2011 08:54:05 +0300
parents 6893b4dca5a3
children 11da537aeba6
line diff
     1.1 --- a/src/draw.c	Tue Apr 19 08:36:23 2011 +0300
     1.2 +++ b/src/draw.c	Mon Apr 25 08:54:05 2011 +0300
     1.3 @@ -1,4 +1,5 @@
     1.4  #include <string.h>
     1.5 +#include <math.h>
     1.6  #include <assert.h>
     1.7  #include "draw.h"
     1.8  #include "imtk.h"
     1.9 @@ -115,6 +116,45 @@
    1.10  	glEnd();
    1.11  }
    1.12  
    1.13 +void imtk_draw_disc(int x, int y, float rad, int subdiv, float *ctop, float *cbot)
    1.14 +{
    1.15 +	int i;
    1.16 +	float t, dtheta, theta = 0.0;
    1.17 +	float color[4];
    1.18 +	float cx = (float)x;
    1.19 +	float cy = (float)y;
    1.20 +
    1.21 +	subdiv += 3;
    1.22 +	dtheta = 2.0 * M_PI / subdiv;
    1.23 +
    1.24 +	color[0] = (ctop[0] + cbot[0]) * 0.5;
    1.25 +	color[1] = (ctop[1] + cbot[1]) * 0.5;
    1.26 +	color[2] = (ctop[2] + cbot[2]) * 0.5;
    1.27 +	color[3] = (ctop[3] + cbot[3]) * 0.5;
    1.28 +
    1.29 +	glBegin(GL_TRIANGLE_FAN);
    1.30 +	glColor4fv(color);
    1.31 +	glVertex2f(cx, cy);
    1.32 +
    1.33 +	for(i=0; i<=subdiv; i++) {
    1.34 +		float vx, vy;
    1.35 +
    1.36 +		vx = cx + cos(theta) * rad;
    1.37 +		vy = cy + sin(theta) * rad;
    1.38 +		theta += dtheta;
    1.39 +
    1.40 +		t = (vy - (cy - rad)) / (2.0 * rad);
    1.41 +		color[0] = ctop[0] + (cbot[0] - ctop[0]) * t;
    1.42 +		color[1] = ctop[1] + (cbot[1] - ctop[1]) * t;
    1.43 +		color[2] = ctop[2] + (cbot[2] - ctop[2]) * t;
    1.44 +		color[3] = ctop[3] + (cbot[3] - ctop[3]) * t;
    1.45 +
    1.46 +		glColor4fv(color);
    1.47 +		glVertex2f(vx, vy);
    1.48 +	}
    1.49 +	glEnd();
    1.50 +}
    1.51 +
    1.52  void imtk_draw_frame(int x, int y, int w, int h, int style)
    1.53  {
    1.54  	float tcol[4], bcol[4];