WMSplitView *WMCreateSplitView(WMWidget * parent) { WMSplitView *sPtr; sPtr = wmalloc(sizeof(WMSplitView)); sPtr->widgetClass = WC_SplitView; sPtr->view = W_CreateView(W_VIEW(parent)); if (!sPtr->view) { wfree(sPtr); return NULL; } sPtr->view->self = sPtr; WMSetViewNotifySizeChanges(sPtr->view, True); WMCreateEventHandler(sPtr->view, ExposureMask | StructureNotifyMask | ClientMessageMask, handleEvents, sPtr); WMCreateEventHandler(sPtr->view, ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask, handleActionEvents, sPtr); WMAddNotificationObserver(handleViewResized, sPtr, WMViewSizeDidChangeNotification, sPtr->view); sPtr->subviews = WMCreateArrayWithDestructor(8, wfree); return sPtr; }
void WMSetViewExpandsToParent(WMView * view, int leftOffs, int topOffs, int rightOffs, int bottomOffs) { WMSize size = view->parent->size; view->topOffs = topOffs; view->bottomOffs = bottomOffs; view->leftOffs = leftOffs; view->rightOffs = rightOffs; WMAddNotificationObserver(resizedParent, view, WMViewSizeDidChangeNotification, view->parent); WMSetViewNotifySizeChanges(view->parent, True); W_MoveView(view, leftOffs, topOffs); W_ResizeView(view, size.width - (leftOffs + rightOffs), size.height - (topOffs + bottomOffs)); }
int main(int argc, char **argv) { Display *dpy; WMScreen *scr; int x, y, i; WMInitializeApplication("Puzzle", &argc, argv); dpy = XOpenDisplay(""); if (!dpy) { printf("could not open display\n"); exit(1); } scr = WMCreateScreen(dpy, DefaultScreen(dpy)); win = WMCreateWindow(scr, "puzzle"); WMResizeWidget(win, WinSize, WinSize); WMSetWindowTitle(win, "zuPzel"); WMSetWindowMinSize(win, 80, 80); WMSetWindowAspectRatio(win, 2, 2, 2, 2); WMSetWindowResizeIncrements(win, Size, Size); WMSetViewNotifySizeChanges(WMWidgetView(win), True); WMAddNotificationObserver(resizeObserver, NULL, WMViewSizeDidChangeNotification, WMWidgetView(win)); for (i = y = 0; y < Size && i < Size*Size-1; y++) { for (x = 0; x < Size && i < Size*Size-1; x++) { char buf[32]; WMColor *color; RColor col; RHSVColor hsv; hsv.hue = i*360/(Size*Size-1); hsv.saturation = 120; hsv.value = 200; RHSVtoRGB(&hsv, &col); color = WMCreateRGBColor(scr, col.red<<8, col.green<<8, col.blue<<8, False); MAP(x,y) = i; Button[i] = WMCreateButton(win, WBTMomentaryLight); WMSetWidgetBackgroundColor(Button[i], color); WMReleaseColor(color); WMSetButtonAction(Button[i], buttonClick, (void*)i); WMResizeWidget(Button[i], WinSize/Size, WinSize/Size); WMMoveWidget(Button[i], x*(WinSize/Size), y*(WinSize/Size)); sprintf(buf, "%i", i+1); WMSetButtonText(Button[i], buf); WMSetButtonTextAlignment(Button[i], WACenter); i++; } } WMMapSubwidgets(win); WMMapWidget(win); WMRealizeWidget(win); ResetGame(); WMScreenMainLoop(scr); return 0; }
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; }