# HG changeset patch # User John Tsiombikas # Date 1303710845 -10800 # Node ID 737e9047d9c90249040c641d5b34bc18625240c5 # Parent ac2a8d8fca9ad442b69d33832e394f9d1066ee9f added radio group diff -r ac2a8d8fca9a -r 737e9047d9c9 Makefile --- a/Makefile Tue Apr 19 08:36:23 2011 +0300 +++ b/Makefile Mon Apr 25 08:54:05 2011 +0300 @@ -5,7 +5,7 @@ CC = gcc CFLAGS = -pedantic -Wall -g -Isrc -LDFLAGS = $(libgl) +LDFLAGS = $(libgl) -lm ifeq ($(shell uname -s), Darwin) libgl = -framework OpenGL -framework GLUT diff -r ac2a8d8fca9a -r 737e9047d9c9 src/draw.c --- a/src/draw.c Tue Apr 19 08:36:23 2011 +0300 +++ b/src/draw.c Mon Apr 25 08:54:05 2011 +0300 @@ -1,4 +1,5 @@ #include +#include #include #include "draw.h" #include "imtk.h" @@ -115,6 +116,45 @@ glEnd(); } +void imtk_draw_disc(int x, int y, float rad, int subdiv, float *ctop, float *cbot) +{ + int i; + float t, dtheta, theta = 0.0; + float color[4]; + float cx = (float)x; + float cy = (float)y; + + subdiv += 3; + dtheta = 2.0 * M_PI / subdiv; + + color[0] = (ctop[0] + cbot[0]) * 0.5; + color[1] = (ctop[1] + cbot[1]) * 0.5; + color[2] = (ctop[2] + cbot[2]) * 0.5; + color[3] = (ctop[3] + cbot[3]) * 0.5; + + glBegin(GL_TRIANGLE_FAN); + glColor4fv(color); + glVertex2f(cx, cy); + + for(i=0; i<=subdiv; i++) { + float vx, vy; + + vx = cx + cos(theta) * rad; + vy = cy + sin(theta) * rad; + theta += dtheta; + + t = (vy - (cy - rad)) / (2.0 * rad); + color[0] = ctop[0] + (cbot[0] - ctop[0]) * t; + color[1] = ctop[1] + (cbot[1] - ctop[1]) * t; + color[2] = ctop[2] + (cbot[2] - ctop[2]) * t; + color[3] = ctop[3] + (cbot[3] - ctop[3]) * t; + + glColor4fv(color); + glVertex2f(vx, vy); + } + glEnd(); +} + void imtk_draw_frame(int x, int y, int w, int h, int style) { float tcol[4], bcol[4]; diff -r ac2a8d8fca9a -r 737e9047d9c9 src/draw.h --- a/src/draw.h Tue Apr 19 08:36:23 2011 +0300 +++ b/src/draw.h Mon Apr 25 08:54:05 2011 +0300 @@ -14,6 +14,8 @@ }; void imtk_draw_rect(int x, int y, int w, int h, float *ctop, float *cbot); +void imtk_draw_disc(int x, int y, float rad, int subdiv, float *ctop, float *cbot); + void imtk_draw_frame(int x, int y, int w, int h, int style); void imtk_draw_string(int x, int y, const char *str); int imtk_string_size(const char *str); diff -r ac2a8d8fca9a -r 737e9047d9c9 src/imtk.h --- a/src/imtk.h Tue Apr 19 08:36:23 2011 +0300 +++ b/src/imtk.h Mon Apr 25 08:54:05 2011 +0300 @@ -60,9 +60,7 @@ float imtk_slider(int id, float pos, float min, float max, int x, int y); void imtk_progress(int id, float pos, int x, int y); int imtk_listbox(int id, const char *list, int sel, int x, int y); -/* -int imtk_combobox(int id, char *textbuf, size_t buf_sz, const char *list, int sel, int x, int y); -*/ +int imtk_radiogroup(int id, const char *list, int sel, int x, int y); /* helper functions to create and destroy item lists for listboxes and comboboxes */ char *imtk_create_list(const char *first, ...); diff -r ac2a8d8fca9a -r 737e9047d9c9 src/listbox.c --- a/src/listbox.c Tue Apr 19 08:36:23 2011 +0300 +++ b/src/listbox.c Mon Apr 25 08:54:05 2011 +0300 @@ -8,10 +8,22 @@ #define ITEM_HEIGHT 18 #define PAD 3 +static int list_radio(int id, const char *list, int sel, int x, int y, void (*draw)()); static void draw_listbox(int id, const char *list, int sel, int x, int y, int width, int nitems, int over); +static void draw_radio(int id, const char *list, int sel, int x, int y, int width, int nitems, int over); int imtk_listbox(int id, const char *list, int sel, int x, int y) { + return list_radio(id, list, sel, x, y, draw_listbox); +} + +int imtk_radiogroup(int id, const char *list, int sel, int x, int y) +{ + return list_radio(id, list, sel, x, y, draw_radio); +} + +static int list_radio(int id, const char *list, int sel, int x, int y, void (*draw)()) +{ int i, max_width, nitems, over; const char *ptr; @@ -48,7 +60,7 @@ } } - draw_listbox(id, list, sel, x, y, max_width, nitems, over); + draw(id, list, sel, x, y, max_width, nitems, over); return sel; } @@ -127,3 +139,36 @@ imtk_draw_frame(x, y, width, ITEM_HEIGHT * nitems, FRAME_INSET); } + +static void draw_radio(int id, const char *list, int sel, int x, int y, int width, int nitems, int over) +{ + int i; + const char *item = list; + float rad = ITEM_HEIGHT * 0.5; + + for(i=0; i