⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glwin.c

📁 Delaunay三角形的网格剖分程序
💻 C
📖 第 1 页 / 共 5 页
字号:
      case GrayScale:      case PseudoColor:	for (i = 0; i < w->vInfoMain->colormap_size; i++) {	    intensity = (float)i / (float)w->vInfoMain->colormap_size *			65535.0 + 0.5;	    c[i].pixel = i;	    c[i].red = (unsigned short)intensity;	    c[i].green = (unsigned short)intensity;	    c[i].blue = (unsigned short)intensity;	    c[i].flags = DoRed | DoGreen | DoBlue;	}	XStoreColors(w->display, w->cMapMain, c, w->vInfoMain->colormap_size);	break;    }    XSync(w->display, 0);}/******************************************************************************/void glwSetOneColor(glWindow w,int index, float r, float g, float b){    XColor c;    int rShift, gShift, bShift;    switch (w->vInfoMainClass) {      case DirectColor:	rShift = ffs((unsigned int)w->vInfoMain->red_mask) - 1;	gShift = ffs((unsigned int)w->vInfoMain->green_mask) - 1;	bShift = ffs((unsigned int)w->vInfoMain->blue_mask) - 1;	c.pixel = ((index << rShift) & w->vInfoMain->red_mask) |		  ((index << gShift) & w->vInfoMain->green_mask) |		  ((index << bShift) & w->vInfoMain->blue_mask);	c.red = (unsigned short)(r * 65535.0 + 0.5);	c.green = (unsigned short)(g * 65535.0 + 0.5);	c.blue = (unsigned short)(b * 65535.0 + 0.5);	c.flags = DoRed | DoGreen | DoBlue;	XStoreColor(w->display, w->cMapMain, &c);	break;      case GrayScale:      case PseudoColor:	if (index < w->vInfoMain->colormap_size) {	    c.pixel = index;	    c.red = (unsigned short)(r * 65535.0 + 0.5);	    c.green = (unsigned short)(g * 65535.0 + 0.5);	    c.blue = (unsigned short)(b * 65535.0 + 0.5);	    c.flags = DoRed | DoGreen | DoBlue;	    XStoreColor(w->display, w->cMapMain, &c);	}	break;    }    XSync(w->display, 0);}/******************************************************************************/void glwSetOverlayMap(glWindow w, int size, float *rgb){    XColor c;    unsigned long *buf;    int max, i;    if (w->vInfoMainClass == PseudoColor) {	max = (size > w->vInfoOverlay->colormap_size) ?	      w->vInfoOverlay->colormap_size : size;	buf = (unsigned long *)calloc(max, sizeof(unsigned long));	XAllocColorCells(w->display, w->cMapOverlay, True, NULL, 0, buf, max-1);	for (i = 1; i < max; i++) {	    c.pixel = i;	    c.red = (unsigned short)(rgb[i] * 65535.0 + 0.5);	    c.green = (unsigned short)(rgb[size+i] * 65535.0 + 0.5);	    c.blue = (unsigned short)(rgb[size*2+i] * 65535.0 + 0.5);	    c.flags = DoRed | DoGreen | DoBlue;	    XStoreColor(w->display, w->cMapOverlay, &c);	}	free(buf);    }    XSync(w->display, 0);}/******************************************************************************/void glwSetRGBMap(glWindow w,int size, float *rgb){    XColor c;    int rShift, gShift, bShift, max, i;    switch (w->vInfoMainClass) {      case DirectColor:	max = (size > w->vInfoMain->colormap_size) ? w->vInfoMain->colormap_size						  : size;	for (i = 0; i < max; i++) {	    rShift = ffs((unsigned int)w->vInfoMain->red_mask) - 1;	    gShift = ffs((unsigned int)w->vInfoMain->green_mask) - 1;	    bShift = ffs((unsigned int)w->vInfoMain->blue_mask) - 1;	    c.pixel = ((i << rShift) & w->vInfoMain->red_mask) |		      ((i << gShift) & w->vInfoMain->green_mask) |		      ((i << bShift) & w->vInfoMain->blue_mask);	    c.red = (unsigned short)(rgb[i] * 65535.0 + 0.5);	    c.green = (unsigned short)(rgb[size+i] * 65535.0 + 0.5);	    c.blue = (unsigned short)(rgb[size*2+i] * 65535.0 + 0.5);	    c.flags = DoRed | DoGreen | DoBlue;	    XStoreColor(w->display, w->cMapMain, &c);	}	break;      case GrayScale:      case PseudoColor:	max = (size > w->vInfoMain->colormap_size) ? w->vInfoMain->colormap_size						  : size;	for (i = 0; i < max; i++) {	    c.pixel = i;	    c.red = (unsigned short)(rgb[i] * 65535.0 + 0.5);	    c.green = (unsigned short)(rgb[size+i] * 65535.0 + 0.5);	    c.blue = (unsigned short)(rgb[size*2+i] * 65535.0 + 0.5);	    c.flags = DoRed | DoGreen | DoBlue;	    XStoreColor(w->display, w->cMapMain, &c);	}	break;    }    XSync(w->display, 0);}/******************************************************************************/GLenum glwSetWindowLevel(glWindow w,GLenum level){    switch (level) {      case GLW_OVERLAY:	if (GLW_HAS_OVERLAY(w->type)) {	    if (!glXMakeCurrent(w->display, w->wOverlay, w->cOverlay)) {		return GL_FALSE;	    }	} else {	    return GL_FALSE;	}	break;      case GLW_RGB:      case GLW_INDEX:	if (!glXMakeCurrent(w->display, w->wMain, w->cMain)) {	    return GL_FALSE;	}	break;    default:	break;    }    return GL_TRUE;}void glwQuit(glWindow w){ w->process=0;}/******************************************************************************/static GLenum DoNextEvent(glWindow w){    XEvent current, ahead;    char buf[1000];    KeySym ks;    int key;    XNextEvent(w->display, &current);    switch (current.type) {      case MappingNotify:	XRefreshKeyboardMapping((XMappingEvent *)&current);	w->lastEventType = MappingNotify;	return GL_FALSE;      case MapNotify:	w->lastEventType = MapNotify;	w->drawAllowFlag = GL_TRUE;	return GL_FALSE;      case UnmapNotify:	w->lastEventType = UnmapNotify;	w->drawAllowFlag = GL_FALSE;	return GL_FALSE;            case ClientMessage:	w->lastEventType = ClientMessage;	if (current.xclient.data.l[0] == w->deleteWindowAtom) {	    exit(0);	}	return GL_FALSE;      case Expose:	while (XEventsQueued(current.xexpose.display, QueuedAfterReading) > 0) {	    XPeekEvent(current.xexpose.display, &ahead);	    if (ahead.xexpose.window != current.xexpose.window ||		ahead.type != Expose) {		break;	    }	    XNextEvent(w->display, &current);	}	if (current.xexpose.count == 0) {	    if (w->ExposeFunc) {#ifdef DEC /* bug fixes */		(*ExposeFunc)(w.w, w.h);		if (lastEventType == ConfigureNotify 			&& drawAllowFlag == GL_TRUE) {		    /* the last event must have generated a draw */		    lastEventType = Expose;		    return GL_FALSE;		} else {		    drawAllowFlag = GL_TRUE;		    lastEventType = Expose;		    return GL_TRUE;		}#else /* not DEC */		w->drawAllowFlag = GL_TRUE;		w->lastEventType = Expose;		(*w->ExposeFunc)(w,w->info,w->w, w->h);		if (w->lastEventType == ConfigureNotify) {		    return GL_FALSE;		} else {		    return GL_TRUE;		}#endif /* not DEC */	    }	}	return GL_FALSE;      case ConfigureNotify:	w->lastEventType = ConfigureNotify;	w->w = current.xconfigure.width;	w->h = current.xconfigure.height;	glwSetFontSize(w, w->font_size);	if (w->ReshapeFunc) {	    (*w->ReshapeFunc)(w,w->info,w->w, w->h);	    return GL_TRUE;	} else {	    return GL_FALSE;	}      case MotionNotify:	w->lastEventType = MotionNotify;	if (w->MouseMoveFunc) {	    GLenum mask;	    mask = (GLenum)0;	    if (current.xmotion.state & Button1Mask)  mask |= GLW_LEFTBUTTON;	    if (current.xmotion.state & Button2Mask)  mask |= GLW_MIDDLEBUTTON;	    if (current.xmotion.state & Button3Mask)  mask |= GLW_RIGHTBUTTON;	    if (current.xmotion.state & ShiftMask)    mask |= GLW_SHIFT;	    if (current.xmotion.state & ControlMask)  mask |= GLW_CONTROL;	    if (current.xmotion.state & Mod1Mask)     mask |= GLW_MOD1;	    if (current.xkey.state & LockMask)        mask |= GLW_LOCK;	    	    	    return (*w->MouseMoveFunc)(w,w->info,current.xmotion.x, current.xmotion.y, mask);	} else {	    return GL_FALSE;	}      case ButtonPress:	w->lastEventType = ButtonPress;	if (w->MouseDownFunc) {	    GLenum mask;	    mask = (GLenum)0;	    if (current.xbutton.button==1)  mask |= GLW_LEFTBUTTON;	    if (current.xbutton.button==2)  mask |= GLW_MIDDLEBUTTON;	    if (current.xbutton.button==3)  mask |= GLW_RIGHTBUTTON;	    if (current.xbutton.state & ShiftMask)    mask |= GLW_SHIFT;	    if (current.xbutton.state & ControlMask)  mask |= GLW_CONTROL;	    if (current.xmotion.state & Mod1Mask)     mask |= GLW_MOD1;	    return (*w->MouseDownFunc)(w,w->info,current.xbutton.x, current.xbutton.y, mask);	} else {	    return GL_FALSE;	}      case ButtonRelease:        w->lastEventType = ButtonRelease;        if (w->MouseUpFunc) {            GLenum mask;            mask = (GLenum) 0;            if (current.xbutton.button==1)  mask |= GLW_LEFTBUTTON;            if (current.xbutton.button==2)  mask |= GLW_MIDDLEBUTTON;            if (current.xbutton.button==3)  mask |= GLW_RIGHTBUTTON;            if (current.xbutton.state & ShiftMask)    mask |= GLW_SHIFT;            if (current.xbutton.state & ControlMask)  mask |= GLW_CONTROL;	    if (current.xmotion.state & Mod1Mask)     mask |= GLW_MOD1;            return (*w->MouseUpFunc)(w,w->info,current.xbutton.x, current.xbutton.y, mask);        } else {            return GL_FALSE;        }      case KeyPress:        w->lastEventType = KeyPress;        XLookupString(&current.xkey, buf, sizeof(buf), &ks, 0);        switch (ks) {#define CaseKS(sym) case XK_##sym: key=GLW_##sym; break	  CaseKS(0);          CaseKS(1);          CaseKS(2);          CaseKS(3);          CaseKS(4);          CaseKS(5);          CaseKS(6);          CaseKS(7);          CaseKS(8);          CaseKS(9);          CaseKS(A);          CaseKS(B);          CaseKS(C);          CaseKS(D);          CaseKS(E);          CaseKS(F);          CaseKS(G);          CaseKS(H);          CaseKS(I);          CaseKS(J);          CaseKS(K);          CaseKS(L);          CaseKS(M);          CaseKS(N);          CaseKS(O);          CaseKS(P);          CaseKS(Q);          CaseKS(R);          CaseKS(S);          CaseKS(T);          CaseKS(U);          CaseKS(V);          CaseKS(W);          CaseKS(X);          CaseKS(Y);          CaseKS(Z);          CaseKS(a);          CaseKS(b);          CaseKS(c);          CaseKS(d);          CaseKS(e);          CaseKS(f);          CaseKS(g);          CaseKS(h);          CaseKS(i);          CaseKS(j);          CaseKS(k);          CaseKS(l);          CaseKS(m);          CaseKS(n);          CaseKS(o);          CaseKS(p);          CaseKS(q);          CaseKS(r);          CaseKS(s);          CaseKS(t);          CaseKS(u);          CaseKS(v);          CaseKS(w);          CaseKS(x);          CaseKS(y);          CaseKS(z);	  CaseKS(space);	  CaseKS(exclam);	  CaseKS(quotedbl);	  CaseKS(numbersign);	  CaseKS(dollar);	  CaseKS(percent);	  CaseKS(ampersand);	  CaseKS(apostrophe);	  CaseKS(parenleft);	  CaseKS(parenright);	  CaseKS(asterisk);	  CaseKS(plus);	  CaseKS(comma);	  CaseKS(minus);	  CaseKS(period);	  CaseKS(slash);	  CaseKS(colon);	  CaseKS(semicolon);	  CaseKS(less);	  CaseKS(equal);	  CaseKS(greater);	  CaseKS(question);	  CaseKS(at);	  CaseKS(bracketleft);	  CaseKS(bracketright);	  CaseKS(asciicircum);	  CaseKS(underscore);	  CaseKS(grave);	  CaseKS(braceleft);	  CaseKS(bar);	  CaseKS(braceright);	  CaseKS(asciitilde);	  CaseKS(Return);	  CaseKS(BackSpace);	  CaseKS(Escape);	  CaseKS(Left);	  CaseKS(Up);	  CaseKS(Right);	  CaseKS(Down);	  CaseKS(KP_Enter);	  CaseKS(KP_Home);	  CaseKS(KP_Left);	  CaseKS(KP_Up);	  CaseKS(KP_Right);	  CaseKS(KP_Down);	  CaseKS(KP_Page_Up);	  CaseKS(KP_Page_Down);	  CaseKS(KP_End);	  CaseKS(KP_Begin);	  CaseKS(KP_Insert);	  CaseKS(KP_Delete);	  CaseKS(KP_Divide);	  CaseKS(KP_Multiply);	  CaseKS(KP_Add);	  CaseKS(KP_Subtract);	  CaseKS(KP_Decimal);	  CaseKS(KP_0);	  CaseKS(KP_1);	  CaseKS(KP_2);	  CaseKS(KP_3);	  CaseKS(KP_4);	  CaseKS(KP_5);	  CaseKS(KP_6);	  CaseKS(KP_7);	  CaseKS(KP_8);	  CaseKS(KP_9);	  CaseKS(F1);	  CaseKS(F2);	  CaseKS(F3);	  CaseKS(F4);	  CaseKS(F5);	  CaseKS(F6);	  CaseKS(F7);	  CaseKS(F8);	  CaseKS(F9);	  CaseKS(F10);	  CaseKS(F11);	  CaseKS(F12);	  CaseKS(Page_Up);	  CaseKS(Page_Down);	  CaseKS(Tab);	  CaseKS(Home);	  CaseKS(End);	  CaseKS(Insert);	  CaseKS(Delete);	  CaseKS(Print);	  CaseKS(Pause);	  CaseKS(Scroll_Lock);          default:              key = GL_FALSE;         break;        }	if (key && w->KeyDownFunc) {	    GLenum mask;	    mask = (GLenum)0;	    if (current.xkey.state & ShiftMask)    mask |= GLW_SHIFT;	    if (current.xkey.state & ControlMask)  mask |= GLW_CONTROL;	    if (current.xkey.state & Mod1Mask)     mask |= GLW_MOD1;	    return (*w->KeyDownFunc)(w,w->info,key, mask);	} else {	    return GL_FALSE;	}    }    return GL_FALSE;}void glwSwapBuffers(glWindow w){  if (!w->offscreen)    glXSwapBuffers(w->display, w->wMain);      if (w->recording && (w->frame_num%w->skip==0))    {      glwGrabPPM(w,w->moviepipe);      w->recorded_frame_num++;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -