nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@3: #include nuclear@0: #include nuclear@4: #include "goatkit.h" nuclear@0: nuclear@0: static bool init(); nuclear@0: static void cleanup(); nuclear@0: static void disp(); nuclear@3: static void idle(); nuclear@0: static void reshape(int x, int y); nuclear@0: static void keypress(unsigned char key, int x, int y); nuclear@0: static void keyrelease(unsigned char key, int x, int y); nuclear@0: static void skeypress(int key, int x, int y); nuclear@0: static void skeyrelease(int key, int x, int y); nuclear@0: static void mouse(int bn, int st, int x, int y); nuclear@0: static void motion(int x, int y); nuclear@0: nuclear@4: static std::vector widgets; nuclear@3: nuclear@0: int main(int argc, char **argv) nuclear@0: { nuclear@0: glutInitWindowSize(800, 600); nuclear@0: glutInit(&argc, argv); nuclear@0: glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); nuclear@4: glutCreateWindow("goatkit test"); nuclear@0: nuclear@0: glutDisplayFunc(disp); nuclear@3: glutIdleFunc(idle); nuclear@0: glutReshapeFunc(reshape); nuclear@0: glutKeyboardFunc(keypress); nuclear@0: glutKeyboardUpFunc(keyrelease); nuclear@0: glutSpecialFunc(skeypress); nuclear@0: glutSpecialUpFunc(skeyrelease); nuclear@0: glutMouseFunc(mouse); nuclear@0: glutMotionFunc(motion); nuclear@0: glutPassiveMotionFunc(motion); nuclear@0: nuclear@0: if(!init()) { nuclear@0: return 1; nuclear@0: } nuclear@0: atexit(cleanup); nuclear@0: nuclear@0: glutMainLoop(); nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: static bool init() nuclear@0: { nuclear@4: goatkit::Button *button = new goatkit::Button; nuclear@3: button->set_position(350, 280); nuclear@3: button->set_size(100, 40); nuclear@3: widgets.push_back(button); nuclear@3: nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: static void cleanup() nuclear@0: { nuclear@3: for(size_t i=0; idraw(); nuclear@3: } nuclear@3: nuclear@0: glutSwapBuffers(); nuclear@0: assert(glGetError() == GL_NO_ERROR); nuclear@0: } nuclear@0: nuclear@3: static void idle() nuclear@3: { nuclear@3: glutPostRedisplay(); nuclear@3: } nuclear@3: nuclear@0: static void reshape(int x, int y) nuclear@0: { nuclear@0: glViewport(0, 0, x, y); nuclear@0: glMatrixMode(GL_PROJECTION); nuclear@0: glLoadIdentity(); nuclear@3: glOrtho(0, x, 0, y, -1, 1); nuclear@0: } nuclear@0: nuclear@0: static void keypress(unsigned char key, int x, int y) nuclear@0: { nuclear@0: if(key == 27) { nuclear@0: exit(0); nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: static void keyrelease(unsigned char key, int x, int y) nuclear@0: { nuclear@0: } nuclear@0: nuclear@0: static void skeypress(int key, int x, int y) nuclear@0: { nuclear@0: } nuclear@0: nuclear@0: static void skeyrelease(int key, int x, int y) nuclear@0: { nuclear@0: } nuclear@0: nuclear@0: static void mouse(int bn, int st, int x, int y) nuclear@0: { nuclear@3: int bidx = bn - GLUT_LEFT_BUTTON; nuclear@3: bool down = st == GLUT_DOWN; nuclear@3: nuclear@3: for(size_t i=0; ihit_test(goatkit::Vec2(x, y))) { nuclear@4: goatkit::Event ev; nuclear@4: ev.type = goatkit::EV_MOUSE_BUTTON; nuclear@3: ev.button.button = bidx; nuclear@3: ev.button.press = down; nuclear@4: ev.button.pos = goatkit::Vec2(x, y); nuclear@3: w->handle_event(ev); nuclear@3: } nuclear@3: } nuclear@0: } nuclear@0: nuclear@0: static void motion(int x, int y) nuclear@0: { nuclear@4: static goatkit::Widget *active; nuclear@3: nuclear@4: if(active && !active->hit_test(goatkit::Vec2(x, y))) { nuclear@4: goatkit::Event ev; nuclear@4: ev.type = goatkit::EV_MOUSE_FOCUS; nuclear@3: ev.focus.enter = false; nuclear@3: active->handle_event(ev); nuclear@3: active = 0; nuclear@3: } nuclear@3: nuclear@3: for(size_t i=0; ihit_test(goatkit::Vec2(x, y))) { nuclear@3: if(active != w) { nuclear@4: goatkit::Event ev; nuclear@4: ev.type = goatkit::EV_MOUSE_FOCUS; nuclear@3: ev.focus.enter = true; nuclear@3: w->handle_event(ev); nuclear@3: active = w; nuclear@3: } nuclear@3: } nuclear@3: } nuclear@0: }