# HG changeset patch # User John Tsiombikas # Date 1302811447 -10800 # Node ID 6d35e6c7b2ca1cedc49f1b2cf492c641e849de0f # Parent 38609a9f75865b06dd58583b6014b5422cf8d499 reorganization finished diff -r 38609a9f7586 -r 6d35e6c7b2ca src/imtk.c --- a/src/imtk.c Thu Apr 14 14:22:42 2011 +0300 +++ b/src/imtk.c Thu Apr 14 23:04:07 2011 +0300 @@ -10,18 +10,20 @@ #include #endif #include "imtk.h" - - -static void draw_progress(int id, float pos, int x, int y); +#include "state.h" void imtk_begin(void) { + int width, height; + + imtk_get_viewport(&width, &height); + glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glTranslatef(-1, 1, 0); - glScalef(2.0 / scr_width, -2.0 / scr_height, 1.0); + glScalef(2.0 / width, -2.0 / height, 1.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); @@ -50,13 +52,7 @@ } - -void imtk_progress(int id, float pos, int x, int y) -{ - draw_progress(id, pos, x, y); -} - -int imtk_listbox(int id, const char *list, int sel, int x, int y) +/*int imtk_listbox(int id, const char *list, int sel, int x, int y) { int i; assert(id >= 0); @@ -128,35 +124,4 @@ void imtk_free_list(char *list) { free(list); -} - - -static void draw_progress(int id, float pos, int x, int y) -{ - int bar_size = SLIDER_SIZE * pos; - - if(pos < 0.0) pos = 0.0; - if(pos > 1.0) pos = 1.0; - - /* through */ - glBegin(GL_QUADS); - glColor3fv(colors[IMTK_BASE_COLOR]); - glVertex2f(x - 1, y - 1); - glVertex2f(x + SLIDER_SIZE + 1, y - 1); - glVertex2f(x + SLIDER_SIZE + 1, y + 17); - glVertex2f(x - 1, y + 17); - glEnd(); - draw_frame(x - 1, y - 1, SLIDER_SIZE + 2, 17, FRAME_INSET); - - if(pos > 0.0) { - /* bar */ - glBegin(GL_QUADS); - glColor3fv(colors[IMTK_BASE_COLOR]); - glVertex2f(x, y); - glVertex2f(x + bar_size, y); - glVertex2f(x + bar_size, y + 15); - glVertex2f(x, y + 15); - glEnd(); - draw_frame(x, y, bar_size, 15, FRAME_OUTSET); - } -} +}*/ diff -r 38609a9f7586 -r 6d35e6c7b2ca src/imtk.h --- a/src/imtk.h Thu Apr 14 14:22:42 2011 +0300 +++ b/src/imtk.h Thu Apr 14 23:04:07 2011 +0300 @@ -20,10 +20,18 @@ IMTK_RIGHT_BUTTON }; + +#ifdef __cplusplus +extern "C" { +#endif + + void imtk_inp_key(int key, int state); void imtk_inp_mouse(int bn, int state); void imtk_inp_motion(int x, int y); -void imtk_inp_reshape(int x, int y); + +void imtk_set_viewport(int x, int y); +void imtk_get_viewport(int *width, int *height); void imtk_post_redisplay(void); @@ -35,11 +43,19 @@ void imtk_textbox(int id, char *textbuf, size_t buf_sz, int x, int y); 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); +*/ /* helper functions to create and destroy item lists for listboxes and comboboxes */ +/* char *imtk_create_list(const char *first, ...); void imtk_free_list(char *list); +*/ + +#ifdef __cplusplus +} +#endif #endif /* IMTK_H_ */ diff -r 38609a9f7586 -r 6d35e6c7b2ca src/progress.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/progress.c Thu Apr 14 23:04:07 2011 +0300 @@ -0,0 +1,41 @@ +#include "imtk.h" +#include "draw.h" + +#define SLIDER_SIZE 100 + +static void draw_progress(int id, float pos, int x, int y); + +void imtk_progress(int id, float pos, int x, int y) +{ + draw_progress(id, pos, x, y); +} + +static void draw_progress(int id, float pos, int x, int y) +{ + int bar_size = SLIDER_SIZE * pos; + + if(pos < 0.0) pos = 0.0; + if(pos > 1.0) pos = 1.0; + + /* through */ + glBegin(GL_QUADS); + glColor4fv(imtk_get_color(IMTK_BASE_COLOR)); + glVertex2f(x - 1, y - 1); + glVertex2f(x + SLIDER_SIZE + 1, y - 1); + glVertex2f(x + SLIDER_SIZE + 1, y + 17); + glVertex2f(x - 1, y + 17); + glEnd(); + imtk_draw_frame(x - 1, y - 1, SLIDER_SIZE + 2, 17, FRAME_INSET); + + if(pos > 0.0) { + /* bar */ + glBegin(GL_QUADS); + glColor4fv(imtk_get_color(IMTK_BASE_COLOR)); + glVertex2f(x, y); + glVertex2f(x + bar_size, y); + glVertex2f(x + bar_size, y + 15); + glVertex2f(x, y + 15); + glEnd(); + imtk_draw_frame(x, y, bar_size, 15, FRAME_OUTSET); + } +} diff -r 38609a9f7586 -r 6d35e6c7b2ca src/slider.c --- a/src/slider.c Thu Apr 14 14:22:42 2011 +0300 +++ b/src/slider.c Thu Apr 14 23:04:07 2011 +0300 @@ -52,7 +52,7 @@ dx = (float)(mousex - prevx) / (float)SLIDER_SIZE; pos += dx; - prevx = mousex; + imtk_set_prev_mouse(mousex, mousey); if(pos < 0.0) pos = 0.0; if(pos > 1.0) pos = 1.0; diff -r 38609a9f7586 -r 6d35e6c7b2ca src/state.c --- a/src/state.c Thu Apr 14 14:22:42 2011 +0300 +++ b/src/state.c Thu Apr 14 23:04:07 2011 +0300 @@ -57,12 +57,18 @@ imtk_post_redisplay(); } -void imtk_inp_reshape(int x, int y) +void imtk_set_viewport(int x, int y) { st.scr_width = x; st.scr_height = y; } +void imtk_get_viewport(int *width, int *height) +{ + if(width) *width = st.scr_width; + if(height) *height = st.scr_height; +} + void imtk_set_active(int id) { diff -r 38609a9f7586 -r 6d35e6c7b2ca test.c --- a/test.c Thu Apr 14 14:22:42 2011 +0300 +++ b/test.c Thu Apr 14 23:04:07 2011 +0300 @@ -94,7 +94,7 @@ glViewport(0, 0, 200, ysz); - imtk_inp_reshape(200, ysz); + imtk_set_viewport(200, ysz); gui(); @@ -108,8 +108,8 @@ static char textbuf[256]; static char textbuf2[256]; static float val; - static int prev_sel; - char *itemlist; + /*static int prev_sel; + char *itemlist;*/ imtk_begin(); @@ -132,12 +132,12 @@ glutPostRedisplay(); } - itemlist = imtk_create_list("teapot", "torus", "sphere", NULL); + /*itemlist = imtk_create_list("teapot", "torus", "sphere", NULL); if((objsel = imtk_listbox(IMUID, itemlist, prev_sel, 30, 120)) != prev_sel) { prev_sel = objsel; glutPostRedisplay(); } - imtk_free_list(itemlist); + imtk_free_list(itemlist);*/ imtk_textbox(IMUID, textbuf, sizeof textbuf, 30, 200); imtk_textbox(IMUID, textbuf2, sizeof textbuf2, 30, 250);