/* test_text_in.c test inputting text in OpenGL textbox */ /* uses text_in.c which uses GLUT */ #include #include #include static int getting_text = 0; static char * the_text; static void (*text_entered)(); static char user_input[100] = ""; static color_file_entry_window = 0; static char more_input[20] = ""; static char position_text[100] = "init"; static void open_a_file(char filename[]) { printf("open a file named %s\n", filename); color_file_entry_window = 0; } static void convert_int(char user_text[]) { int i; i = atoi(user_text); printf("user text converted to integer i=%d\n", i); } static void clear_text(char msg[]) { msg[0]='\0'; } static void get_text(char msg[], void (*call_with_text)()) { getting_text = 1; the_text = msg; text_entered = call_with_text; } static int add_text(unsigned char key) { char msg[] = "x"; int len; if(!getting_text) return 0; if(key==8) /* backspace */ { len = strlen(the_text); the_text[len-1] = '\0'; } else if(key==13 || key==9) { getting_text = 0; text_entered(the_text); } else { msg[0] = key; strcat(the_text, msg); } glutPostRedisplay(); return 1; } static void stop_text(char msg[]) { getting_text = 0; } static void show_text(GLfloat x, GLfloat y, char msg[]) { int len, i; glPushMatrix(); glRasterPos2f(x, y); len = strlen(msg); for (i = 0; i