📄 ggiglut.c
字号:
static void mousemove(void){ GGIGLUTDPRINT_CORE("mousemove() called\n"); if (mouse_moved) { if (__glut_motion && mouse_down) { __glut_motion(mousex,mousey); } if (__glut_passive_motion && (!mouse_down)) { __glut_passive_motion(mousex,mousey); } if (__glut_menuactive) updatemouse(); mouse_moved=GL_FALSE; }}static void button(ggi_event *ev){ int i; int btn[4] = { 0, GLUT_LEFT_BUTTON, GLUT_RIGHT_BUTTON, GLUT_MIDDLE_BUTTON }; GGIGLUTDPRINT_CORE("button() called\n"); mousemove(); if (ev->pbutton.button <= 3) { /* GGI can have >3 buttons ! */ char state = ev->any.type == evPtrButtonPress ? GLUT_DOWN : GLUT_UP; if (__glut_menuactive) { if (state == GLUT_UP && clickmenu()) { glutPostRedisplay(); __glut_menuactive = GL_FALSE; } } else if (btn[ev->pbutton.button] == __glut_menubutton) { __glut_menuactive = GL_TRUE; activemenu = mainmenu; showmenu(); } else if (__glut_mouse) { __glut_mouse(btn[ev->pbutton.button], state, mousex, mousey); } if (state == GLUT_DOWN) { mouse_down |= (1 << (ev->pbutton.button - 1)); } else mouse_down &= ~( 1 << (ev->pbutton.button - 1)); }}void glutMainLoop(void){ ggi_event ev; ggi_event_mask evmask = (emKeyPress | emKeyRepeat | emPtrMove | emPtrButton); GGIGLUTDPRINT_CORE("glutMainLoop() called\n"); ggiSetEventMask(__glut_vis, evmask); glutPostRedisplay(); if (__glut_visibility) __glut_visibility(GLUT_VISIBLE); while (1) { if (!__glut_menuactive) { if (__glut_idle) __glut_idle(); if (__glut_redisplay && __glut_display) { __glut_redisplay = GL_FALSE; __glut_display(); } } while (1) { struct timeval t = {0, 0}; if (ggiEventPoll(__glut_vis, evmask, &t) == 0) break; ggiEventRead(__glut_vis, &ev, evmask); switch (ev.any.type) { case evKeyPress: case evKeyRepeat: keyboard(&ev); break; case evPtrAbsolute: mouseabs(&ev); break; case evPtrRelative: mouse(&ev); break; case evPtrButtonPress: case evPtrButtonRelease: button(&ev); break; } } mousemove(); }}static void showmenu(){ int y,i; ggi_color col = { 0xffff, 0xffff, 0xffff }; GGIGLUTDPRINT_CORE("showmenu() called\n"); ggiSetGCForeground(__glut_vis,ggiMapColor(__glut_vis,&col)); ggiSetOrigin(__glut_vis,0,0); for (y = i = 0; i < activemenu->num_entries; i++, y += 8) { ggiPuts(__glut_vis, 0, y, activemenu->label[i]); } drawmouse();}static int clickmenu(void){ int i; int w, h; GGIGLUTDPRINT_CORE("clickmenu() called\n"); i = mousey / 8; if (i >= activemenu->num_entries) return GL_TRUE; if (mousex >= 8 * strlen(activemenu->label[i])) return GL_TRUE; if (activemenu->submenu[i]) { ggi_color col={0,0,0}; ggiSetGCForeground(__glut_vis,ggiMapColor(__glut_vis,&col)); h=activemenu->num_entries*8; w=activemenu->max_strlen*8; ggiDrawBox(__glut_vis,0,0,w,h); activemenu=activemenu->submenu[i]; showmenu(); return GL_FALSE; } curmenu=activemenu; activemenu->func(activemenu->value[i]); return GL_TRUE;}static int oldx=-1;static int oldy=-1;static char buffer[16*16*4];static void updatemouse(){ GGIGLUTDPRINT_CORE("updatemouse() called\n"); ggiPutBox(__glut_vis,oldx,oldy,16,16,buffer); drawmouse();}static void drawmouse(){ int x,y; GGIGLUTDPRINT_CORE("drawmouse() called\n"); x=mousex-8; if (x<0) x=0; y=mousey-8; if (y<0) y=0; ggiGetBox(__glut_vis,x,y,16,16,buffer); ggiDrawLine(__glut_vis,mousex-2,mousey,mousex+2,mousey); ggiDrawLine(__glut_vis,mousex,mousey-2,mousex,mousey+2); oldx=x; oldy=y;}int glutCreateMenu(void(*func)(int)){ menu_t *m; GGIGLUTDPRINT_CORE("glutCreateMenu() called\n"); m=malloc(sizeof(menu_t)); memset(m,0,sizeof(menu_t)); curmenu=m; curmenu->func=func; return (int)curmenu;}static void addEntry(const char *label,int value,menu_t *submenu){ int i=curmenu->num_entries; GGIGLUTDPRINT_CORE("addEntry() called\n"); /* printf("%i %i %s %p\n",i,value,label,submenu); */ if (i<MAX_ENTRIES) { curmenu->label[i]=strdup(label); curmenu->value[i]=value; curmenu->submenu[i]=submenu; if (strlen(label)>curmenu->max_strlen) curmenu->max_strlen=strlen(label); curmenu->num_entries++; }}void glutAddMenuEntry(const char *label,int value){ GGIGLUTDPRINT_CORE("glutAddMenuEntry() called\n"); addEntry(label,value,NULL);}void glutAddSubMenu(const char *label,int submenu){ char text[100]; GGIGLUTDPRINT_CORE("glutAddSubMenu() called\n"); if (!curmenu) return; strncpy(text,label,98); text[98]=0; text[strlen(text)+1]=0; text[strlen(text)]='>'; addEntry(text,0,(menu_t *) submenu);}void glutAttachMenu(int button){ GGIGLUTDPRINT_CORE("glutAttachMenu() called\n"); mainmenu=curmenu; __glut_menubutton=button;}void glutDetachMenu(int button){ GGIGLUTDPRINT_CORE("glutDetachMenu() called\n");}void glutVisibilityFunc(void (*func)(int state)){ GGIGLUTDPRINT_CORE("glutVisibilityFunc() called\n"); __glut_visibility=func;}void glutMouseFunc(void (*mouse)(int, int, int, int)){ GGIGLUTDPRINT_CORE("glutMouseFunc() called\n"); __glut_mouse=mouse; }void glutMotionFunc(void (*motion)(int,int)){ GGIGLUTDPRINT_CORE("glutMotionFunc() called\n"); __glut_motion=motion;}void glutPassiveMotionFunc(void (*motion)(int,int)){ GGIGLUTDPRINT_CORE("glutPassiveMotionFunc() called\n"); __glut_passive_motion=motion;}void glutSetWindowTitle(const char *title){ GGIGLUTDPRINT_CORE("glutSetWindowTitle() called\n");}void glutSetIconTitle(const char *title){ GGIGLUTDPRINT_CORE("glutSetIconTitle() called\n");}void glutChangeToMenuEntry(int item,const char *label,int value){ GGIGLUTDPRINT_CORE("glutChangeToMenuEntry() called\n"); if (item>0 && item<=curmenu->num_entries) { item--; free(curmenu->label[item]); curmenu->label[item]=strdup(label); curmenu->value[item]=value; curmenu->submenu[item]=NULL; }}void glutChangeToSubMenu(int item,const char *label,int submenu){ GGIGLUTDPRINT_CORE("glutChengeToSubMenu() called\n"); if (item>0 && item<=curmenu->num_entries) { item--; free(curmenu->label[item]); curmenu->label[item]=strdup(label); curmenu->value[item]=0; curmenu->submenu[item]=(menu_t *)submenu; }}void glutDestroyMenu(int menu){ menu_t *m=(menu_t *)menu; int i; GGIGLUTDPRINT_CORE("glutDestroyMenu() called\n"); for (i=0;i<m->num_entries;i++) { free(m->label[i]); } free(m);}int glutCreateSubWindow(int win,int x,int y,int w,int h){ GGIGLUTDPRINT_CORE("glutCreateSubWindow() called\n"); return 0;}void glutDestroyWindow(int win){ GGIGLUTDPRINT_CORE("glutDestroyWindow() called\n");}int glutGetWindow(void){ GGIGLUTDPRINT_CORE("glutGetWindow() called\n"); return 0;}void glutSetWindow(int win){ GGIGLUTDPRINT_CORE("glutSetWindow() called\n");}void glutPositionWindow(int x,int y){ GGIGLUTDPRINT_CORE("glutPositionWindow() called\n");}void glutReshapeWindow(int x,int y){ GGIGLUTDPRINT_CORE("glutReshapeWindow() called\n");}void glutPushWindow(void){ GGIGLUTDPRINT_CORE("glutPushWindow() called\n");}void glutPopWindow(void){ GGIGLUTDPRINT_CORE("glutPopWindow() called\n");}void glutIconifyWindow(void){ GGIGLUTDPRINT_CORE("glutIconifyWindow() called\n");}void glutShowWindow(){ GGIGLUTDPRINT_CORE("glutShowWindow() called\n");}void glutHideWindow(){ GGIGLUTDPRINT_CORE("glutHideWindow() called\n");}void glutSetCursor(int cursor){ GGIGLUTDPRINT_CORE("glutSetCursor() called\n");}void glutWarpPointer(int x,int y){ GGIGLUTDPRINT_CORE("glutWarpPointer() called\n");}void glutEstablishOverlay(void){ GGIGLUTDPRINT_CORE("glutEstablishOverlay() called\n");}void glutRemoveOverlay(void){ GGIGLUTDPRINT_CORE("glutRemoveOverlay() called\n");}void glutUseLayer(GLenum layer){ GGIGLUTDPRINT_CORE("glutUseLayer() called\n");}int glutLayerGet(GLenum type){ GGIGLUTDPRINT_CORE("glutLayerGet() called\n"); return 0;}void glutPostOverlayRedisplay(void){ GGIGLUTDPRINT_CORE("glutPostOverlayRedisplay() called\n");}void glutPostWindowOverlayRedisplay(int w){ GGIGLUTDPRINT_CORE("glutPostWindowOverlayRedisplay() called\n");}void glutShowOverlay(void){ GGIGLUTDPRINT_CORE("glutShowOverlay() called\n");}void glutHideOverlay(void){ GGIGLUTDPRINT_CORE("glutHideOverlay() called\n");}int glutGetMenu(void){ GGIGLUTDPRINT_CORE("glutGetMenu() called\n"); return 0;}void glutSetMenu(int menu){ GGIGLUTDPRINT_CORE("glutSetMenu() called\n");}void glutRemoveMenuItem(int item){ GGIGLUTDPRINT_CORE("glutRemoveMenuItem() called\n");}void glutSpaceBallMotionFunc(void (*func)(int key,int x,int y)){ GGIGLUTDPRINT_CORE("glutSpaceBallMotionFunc() called\n");}void glutSpaceBallRotateFunc(void (*func)(int x,int y,int z)){ GGIGLUTDPRINT_CORE("glutSpaceBallRotateFunc() called\n");}void glutSpaceBallButtonFunc(void (*func)(int button,int state)){ GGIGLUTDPRINT_CORE("glutSpaceBallButtonFunc() called\n");}void glutCopyColormap(int win){ GGIGLUTDPRINT_CORE("glutCopyColormap() called\n");}int glutDeviceGet(GLenum param){ GGIGLUTDPRINT_CORE("glutDeviceGet() called\n"); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -