void W_SetViewCursor(W_View * view, Cursor cursor) { view->cursor = cursor; if (W_VIEW_REALIZED(view)) { XDefineCursor(W_VIEW_DISPLAY(view), W_VIEW_DRAWABLE(view), cursor); } else { view->attribFlags |= CWCursor; view->attribs.cursor = cursor; } }
WMPoint WMGetViewScreenPosition(WMView * view) { WMScreen *scr = W_VIEW_SCREEN(view); Window foo; int x, y, topX, topY; unsigned int bar; WMView *topView; topView = view; while (topView->parent && topView->parent != scr->rootView) topView = topView->parent; if (!XGetGeometry(scr->display, W_VIEW_DRAWABLE(topView), &foo, &topX, &topY, &bar, &bar, &bar, &bar)) { topX = topY = 0; } XTranslateCoordinates(scr->display, W_VIEW_DRAWABLE(view), scr->rootWin, 0, 0, &x, &y, &foo); return wmkpoint(x - topX, y - topY); }
int main (int argc, char **argv){ int i,j; WMColor *color; WMWindow * win; RImage *image; struct _pict pict; Drawable de; RColor one, two={0xaf, 0x0f,0xff,0x33}; one.red=247; one.green=251; one.blue=107; one.alpha=0xff; WMInitializeApplication("DrawWin", &argc, argv); display = XOpenDisplay(""); screen = WMCreateScreen(display, DefaultScreen(display)); win = WMCreateWindow(screen, ""); WMResizeWidget(win, WINWIDTH, WINHEIGHT); WMSetWindowCloseAction(win, closeAction, NULL); WMSetWindowTitle(win,"Graphics"); color = WMCreateRGBColor(screen,124<<9,206<<8,162<<8, False); WMSetWidgetBackgroundColor((WMWidget *)win, color); /* end setup main window */ image=RCreateImage( 100,100,0.5); RFillImage(image, &two); RDrawLine(image, 50,10,90,90,&one); RDrawLine(image, 10,90,50,10,&one); RDrawLine(image, 10,90,90,90,&one); g3=WMColorGC(screen->gray); XSetLineAttributes(display,g3,3,LineSolid,CapButt,JoinMiter); pict.segments[1].x1= pict.segments[0].x1=HOFF; pict.segments[0].x2=HOFF; pict.segments[0].y1=VOFF; pict.segments[1].y2= pict.segments[0].y2=VOFF; pict.segments[1].x2= HOFF+10; pict.segments[1].y1=VOFF+10; pict.seglen=2; for (i=9;i>0;i--){ j=2*(10-i); pict.segments[j+1].x1= pict.segments[j].x1=HOFF; pict.segments[j+1].y2= pict.segments[j].y2=VOFF; pict.segments[j].x2= i+pict.segments[j-1].x2; pict.segments[j].y1=i+pict.segments[j-1].y1; pict.segments[j+1].x2= i+pict.segments[j].x2; pict.segments[j+1].y1=i+pict.segments[j].y1; pict.seglen+=2; }; WMRealizeWidget(win); pict.dwin=W_VIEW_DRAWABLE(WMWidgetView(win)); pixmap=WMCreatePixmapFromRImage(screen, image,1); WMCreateEventHandler(WMWidgetView(win), ExposureMask,drawProcedure,&pict); WMMapWidget(win); WMScreenMainLoop(screen); }
void W_LowerView(W_View * view) { if (W_VIEW_REALIZED(view)) XLowerWindow(W_VIEW_DISPLAY(view), W_VIEW_DRAWABLE(view)); }
void W_RaiseView(W_View * view) { if (W_VIEW_REALIZED(view)) XRaiseWindow(W_VIEW_DISPLAY(view), W_VIEW_DRAWABLE(view)); }
int main (int argc, char **argv){ WMFrame *glframe; WMScreen *screen; WMWindow *window; WMButton *Button; /* Xlib and glX variables */ Window win; XVisualInfo *xvVisualInfo; Colormap cmColorMap; XSetWindowAttributes winAttr; GLXContext glXContext; getargs(argc,argv); WMInitializeApplication("GLWindow", &argc, argv); display = XOpenDisplay(""); screen = WMCreateScreen(display, DefaultScreen(display)); if(!glXQueryExtension(display, NULL, NULL)){wwarning("X server does not have GLX\n"); return 0; } window = WMCreateWindow(screen, "Main"); WMResizeWidget(window, CONTENTW+2*CONTENTMARGIN, CONTENTH+2*CONTENTMARGIN*CONTENTH/CONTENTW); WMSetWindowAspectRatio(window, CONTENTW,CONTENTH,CONTENTW,CONTENTH); WMSetWindowCloseAction(window, closeAll, NULL); WMSetWindowTitle(window,"GL Frame"); WMRealizeWidget(window); datacouple.window=window; WMSetViewNotifySizeChanges(WMWidgetView(window), True); WMAddNotificationObserver(resizeHandler, &datacouple, WMViewSizeDidChangeNotification, WMWidgetView(window)); glframe = WMCreateFrame(window); datacouple.frame=glframe; WMResizeWidget(glframe, CONTENTW, CONTENTH); WMMoveWidget(glframe, CONTENTMARGIN,CONTENTMARGIN); WMRealizeWidget(glframe); Button=WMCreateButton(window, WBTMomentaryPush); WMSetButtonAction(Button, DoRotate,&win); WMSetButtonText(Button,"Turn"); WMMoveWidget(Button, CONTENTMARGIN,2); WMRealizeWidget(Button); WMMapWidget(Button); /* get the frame's X window value */ win =W_VIEW_DRAWABLE(WMWidgetView(glframe)); WMCreateEventHandler(WMWidgetView(glframe), ExposureMask|StructureNotifyMask,redo,&win); xvVisualInfo = glXChooseVisual(display, DefaultScreen(display), Attr); if(xvVisualInfo == NULL) {wwarning("No visualinfo\n");return 0;} cmColorMap = XCreateColormap(display,RootWindow(display, DefaultScreen(display)), xvVisualInfo->visual, AllocNone); winAttr.colormap = cmColorMap; winAttr.border_pixel = 0; winAttr.background_pixel = 0; winAttr.event_mask = ExposureMask | ButtonPressMask |StructureNotifyMask| KeyPressMask; XChangeWindowAttributes(display,win,CWBorderPixel | CWColormap | CWEventMask,&winAttr); glXContext = glXCreateContext(display, xvVisualInfo, None, True); if(!glXContext) {wwarning("glX cannot create rendering context\n");return 0;} glXMakeCurrent(display, win, glXContext); WMMapWidget(glframe); init(); setsize(CONTENTW,CONTENTH); WMMapWidget(window); WMScreenMainLoop(screen); return 0; }