imtk

changeset 7:6d35e6c7b2ca

reorganization finished
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 14 Apr 2011 23:04:07 +0300
parents 38609a9f7586
children 10604ff95527
files src/imtk.c src/imtk.h src/progress.c src/slider.c src/state.c test.c
diffstat 6 files changed, 79 insertions(+), 51 deletions(-) [+]
line diff
     1.1 --- a/src/imtk.c	Thu Apr 14 14:22:42 2011 +0300
     1.2 +++ b/src/imtk.c	Thu Apr 14 23:04:07 2011 +0300
     1.3 @@ -10,18 +10,20 @@
     1.4  #include <GLUT/glut.h>
     1.5  #endif
     1.6  #include "imtk.h"
     1.7 -
     1.8 -
     1.9 -static void draw_progress(int id, float pos, int x, int y);
    1.10 +#include "state.h"
    1.11  
    1.12  
    1.13  void imtk_begin(void)
    1.14  {
    1.15 +	int width, height;
    1.16 +
    1.17 +	imtk_get_viewport(&width, &height);
    1.18 +
    1.19  	glMatrixMode(GL_PROJECTION);
    1.20  	glPushMatrix();
    1.21  	glLoadIdentity();
    1.22  	glTranslatef(-1, 1, 0);
    1.23 -	glScalef(2.0 / scr_width, -2.0 / scr_height, 1.0);
    1.24 +	glScalef(2.0 / width, -2.0 / height, 1.0);
    1.25  
    1.26  	glMatrixMode(GL_MODELVIEW);
    1.27  	glPushMatrix();
    1.28 @@ -50,13 +52,7 @@
    1.29  }
    1.30  
    1.31  
    1.32 -
    1.33 -void imtk_progress(int id, float pos, int x, int y)
    1.34 -{
    1.35 -	draw_progress(id, pos, x, y);
    1.36 -}
    1.37 -
    1.38 -int imtk_listbox(int id, const char *list, int sel, int x, int y)
    1.39 +/*int imtk_listbox(int id, const char *list, int sel, int x, int y)
    1.40  {
    1.41  	int i;
    1.42  	assert(id >= 0);
    1.43 @@ -128,35 +124,4 @@
    1.44  void imtk_free_list(char *list)
    1.45  {
    1.46  	free(list);
    1.47 -}
    1.48 -
    1.49 -
    1.50 -static void draw_progress(int id, float pos, int x, int y)
    1.51 -{
    1.52 -	int bar_size = SLIDER_SIZE * pos;
    1.53 -
    1.54 -	if(pos < 0.0) pos = 0.0;
    1.55 -	if(pos > 1.0) pos = 1.0;
    1.56 -
    1.57 -	/* through */
    1.58 -	glBegin(GL_QUADS);
    1.59 -	glColor3fv(colors[IMTK_BASE_COLOR]);
    1.60 -	glVertex2f(x - 1, y - 1);
    1.61 -	glVertex2f(x + SLIDER_SIZE + 1, y - 1);
    1.62 -	glVertex2f(x + SLIDER_SIZE + 1, y + 17);
    1.63 -	glVertex2f(x - 1, y + 17);
    1.64 -	glEnd();
    1.65 -	draw_frame(x - 1, y - 1, SLIDER_SIZE + 2, 17, FRAME_INSET);
    1.66 -
    1.67 -	if(pos > 0.0) {
    1.68 -		/* bar */
    1.69 -		glBegin(GL_QUADS);
    1.70 -		glColor3fv(colors[IMTK_BASE_COLOR]);
    1.71 -		glVertex2f(x, y);
    1.72 -		glVertex2f(x + bar_size, y);
    1.73 -		glVertex2f(x + bar_size, y + 15);
    1.74 -		glVertex2f(x, y + 15);
    1.75 -		glEnd();
    1.76 -		draw_frame(x, y, bar_size, 15, FRAME_OUTSET);
    1.77 -	}
    1.78 -}
    1.79 +}*/
     2.1 --- a/src/imtk.h	Thu Apr 14 14:22:42 2011 +0300
     2.2 +++ b/src/imtk.h	Thu Apr 14 23:04:07 2011 +0300
     2.3 @@ -20,10 +20,18 @@
     2.4  	IMTK_RIGHT_BUTTON
     2.5  };
     2.6  
     2.7 +
     2.8 +#ifdef __cplusplus
     2.9 +extern "C" {
    2.10 +#endif
    2.11 +
    2.12 +
    2.13  void imtk_inp_key(int key, int state);
    2.14  void imtk_inp_mouse(int bn, int state);
    2.15  void imtk_inp_motion(int x, int y);
    2.16 -void imtk_inp_reshape(int x, int y);
    2.17 +
    2.18 +void imtk_set_viewport(int x, int y);
    2.19 +void imtk_get_viewport(int *width, int *height);
    2.20  
    2.21  void imtk_post_redisplay(void);
    2.22  
    2.23 @@ -35,11 +43,19 @@
    2.24  void imtk_textbox(int id, char *textbuf, size_t buf_sz, int x, int y);
    2.25  float imtk_slider(int id, float pos, float min, float max, int x, int y);
    2.26  void imtk_progress(int id, float pos, int x, int y);
    2.27 +/*
    2.28  int imtk_listbox(int id, const char *list, int sel, int x, int y);
    2.29  int imtk_combobox(int id, char *textbuf, size_t buf_sz, const char *list, int sel, int x, int y);
    2.30 +*/
    2.31  
    2.32  /* helper functions to create and destroy item lists for listboxes and comboboxes */
    2.33 +/*
    2.34  char *imtk_create_list(const char *first, ...);
    2.35  void imtk_free_list(char *list);
    2.36 +*/
    2.37 +
    2.38 +#ifdef __cplusplus
    2.39 +}
    2.40 +#endif
    2.41  
    2.42  #endif	/* IMTK_H_ */
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/progress.c	Thu Apr 14 23:04:07 2011 +0300
     3.3 @@ -0,0 +1,41 @@
     3.4 +#include "imtk.h"
     3.5 +#include "draw.h"
     3.6 +
     3.7 +#define SLIDER_SIZE             100
     3.8 +
     3.9 +static void draw_progress(int id, float pos, int x, int y);
    3.10 +
    3.11 +void imtk_progress(int id, float pos, int x, int y)
    3.12 +{
    3.13 +	draw_progress(id, pos, x, y);
    3.14 +}
    3.15 +
    3.16 +static void draw_progress(int id, float pos, int x, int y)
    3.17 +{
    3.18 +	int bar_size = SLIDER_SIZE * pos;
    3.19 +
    3.20 +	if(pos < 0.0) pos = 0.0;
    3.21 +	if(pos > 1.0) pos = 1.0;
    3.22 +
    3.23 +	/* through */
    3.24 +	glBegin(GL_QUADS);
    3.25 +	glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
    3.26 +	glVertex2f(x - 1, y - 1);
    3.27 +	glVertex2f(x + SLIDER_SIZE + 1, y - 1);
    3.28 +	glVertex2f(x + SLIDER_SIZE + 1, y + 17);
    3.29 +	glVertex2f(x - 1, y + 17);
    3.30 +	glEnd();
    3.31 +	imtk_draw_frame(x - 1, y - 1, SLIDER_SIZE + 2, 17, FRAME_INSET);
    3.32 +
    3.33 +	if(pos > 0.0) {
    3.34 +		/* bar */
    3.35 +		glBegin(GL_QUADS);
    3.36 +		glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
    3.37 +		glVertex2f(x, y);
    3.38 +		glVertex2f(x + bar_size, y);
    3.39 +		glVertex2f(x + bar_size, y + 15);
    3.40 +		glVertex2f(x, y + 15);
    3.41 +		glEnd();
    3.42 +		imtk_draw_frame(x, y, bar_size, 15, FRAME_OUTSET);
    3.43 +	}
    3.44 +}
     4.1 --- a/src/slider.c	Thu Apr 14 14:22:42 2011 +0300
     4.2 +++ b/src/slider.c	Thu Apr 14 23:04:07 2011 +0300
     4.3 @@ -52,7 +52,7 @@
     4.4  
     4.5  		dx = (float)(mousex - prevx) / (float)SLIDER_SIZE;
     4.6  		pos += dx;
     4.7 -		prevx = mousex;
     4.8 +		imtk_set_prev_mouse(mousex, mousey);
     4.9  
    4.10  		if(pos < 0.0) pos = 0.0;
    4.11  		if(pos > 1.0) pos = 1.0;
     5.1 --- a/src/state.c	Thu Apr 14 14:22:42 2011 +0300
     5.2 +++ b/src/state.c	Thu Apr 14 23:04:07 2011 +0300
     5.3 @@ -57,12 +57,18 @@
     5.4  	imtk_post_redisplay();
     5.5  }
     5.6  
     5.7 -void imtk_inp_reshape(int x, int y)
     5.8 +void imtk_set_viewport(int x, int y)
     5.9  {
    5.10  	st.scr_width = x;
    5.11  	st.scr_height = y;
    5.12  }
    5.13  
    5.14 +void imtk_get_viewport(int *width, int *height)
    5.15 +{
    5.16 +	if(width) *width = st.scr_width;
    5.17 +	if(height) *height = st.scr_height;
    5.18 +}
    5.19 +
    5.20  
    5.21  void imtk_set_active(int id)
    5.22  {
     6.1 --- a/test.c	Thu Apr 14 14:22:42 2011 +0300
     6.2 +++ b/test.c	Thu Apr 14 23:04:07 2011 +0300
     6.3 @@ -94,7 +94,7 @@
     6.4  
     6.5  
     6.6  	glViewport(0, 0, 200, ysz);
     6.7 -	imtk_inp_reshape(200, ysz);
     6.8 +	imtk_set_viewport(200, ysz);
     6.9  
    6.10  	gui();
    6.11  
    6.12 @@ -108,8 +108,8 @@
    6.13  	static char textbuf[256];
    6.14  	static char textbuf2[256];
    6.15  	static float val;
    6.16 -	static int prev_sel;
    6.17 -	char *itemlist;
    6.18 +	/*static int prev_sel;
    6.19 +	char *itemlist;*/
    6.20  
    6.21  	imtk_begin();
    6.22  
    6.23 @@ -132,12 +132,12 @@
    6.24  		glutPostRedisplay();
    6.25  	}
    6.26  
    6.27 -	itemlist = imtk_create_list("teapot", "torus", "sphere", NULL);
    6.28 +	/*itemlist = imtk_create_list("teapot", "torus", "sphere", NULL);
    6.29  	if((objsel = imtk_listbox(IMUID, itemlist, prev_sel, 30, 120)) != prev_sel) {
    6.30  		prev_sel = objsel;
    6.31  		glutPostRedisplay();
    6.32  	}
    6.33 -	imtk_free_list(itemlist);
    6.34 +	imtk_free_list(itemlist);*/
    6.35  
    6.36  	imtk_textbox(IMUID, textbuf, sizeof textbuf, 30, 200);
    6.37  	imtk_textbox(IMUID, textbuf2, sizeof textbuf2, 30, 250);