/*ARGSUSED*/ static Boolean XawScrollbarSetValues(Widget current, Widget request, Widget desired, ArgList args, Cardinal *num_args) { ScrollbarWidget w = (ScrollbarWidget)current; ScrollbarWidget dw = (ScrollbarWidget)desired; Boolean redraw = False; /* * If these values are outside the acceptable range ignore them... */ if (dw->scrollbar.top < 0.0 || dw->scrollbar.top > 1.0) dw->scrollbar.top = w->scrollbar.top; if (dw->scrollbar.shown < 0.0 || dw->scrollbar.shown > 1.0) dw->scrollbar.shown = w->scrollbar.shown; if (XtIsRealized (desired)) { if (w->scrollbar.foreground != dw->scrollbar.foreground || w->core.background_pixel != dw->core.background_pixel || w->scrollbar.thumb != dw->scrollbar.thumb) { XtReleaseGC((Widget)dw, w->scrollbar.gc); CreateGC((Widget)dw); redraw = True; } if (w->scrollbar.top != dw->scrollbar.top || w->scrollbar.shown != dw->scrollbar.shown) redraw = True; } return (redraw); }
static void InitializeEvalGraph() { pens[PEN_BLACK] = CreateGC(1, "black", "black", LineSolid); pens[PEN_DOTTED] = CreateGC(1, "#A0A0A0", "#A0A0A0", LineOnOffDash); pens[PEN_BLUEDOTTED] = CreateGC(1, "#0000FF", "#0000FF", LineOnOffDash); pens[PEN_BOLD] = CreateGC(3, crWhite, crWhite, LineSolid); pens[PEN_BOLD+1] = CreateGC(3, crBlack, crBlack, LineSolid); hbrHist[0] = CreateGC(3, crWhite, crWhite, LineSolid); hbrHist[1] = CreateGC(3, crBlack, crBlack, LineSolid); hbrHist[2] = CreateGC(3, "#E0E0F0", "#E0E0F0", LineSolid);; // background (a bit blueish, for contrst with yellow curve) }
static GCPtr miDCMakeGC(WindowPtr pWin) { GCPtr pGC; int status; XID gcvals[2]; gcvals[0] = IncludeInferiors; gcvals[1] = FALSE; pGC = CreateGC((DrawablePtr)pWin, GCSubwindowMode|GCGraphicsExposures, gcvals, &status, (XID)0, serverClient); return pGC; }
/*ARGSUSED*/ static void XawStripChartInitialize(Widget greq, Widget gnew, ArgList args, Cardinal *num_args) { StripChartWidget w = (StripChartWidget)gnew; if (w->strip_chart.update > 0) w->strip_chart.interval_id = XtAppAddTimeOut(XtWidgetToApplicationContext(gnew), w->strip_chart.update * MS_PER_SEC, draw_it, (XtPointer)gnew); CreateGC(w, ALL_GCS); w->strip_chart.scale = w->strip_chart.min_scale; w->strip_chart.interval = 0; w->strip_chart.max_value = 0.0; w->strip_chart.points = NULL; XawStripChartResize(gnew); }
static Bool cwCreateBackingGC(GCPtr pGC, DrawablePtr pDrawable) { cwGCRec *pPriv = getCwGC(pGC); int status, x_off, y_off; XID noexpose = xFalse; DrawablePtr pBackingDrawable; pBackingDrawable = cwGetBackingDrawable(pDrawable, &x_off, &y_off); pPriv->pBackingGC = CreateGC(pBackingDrawable, GCGraphicsExposures, &noexpose, &status, (XID)0, serverClient); if (status != Success) return FALSE; pPriv->serialNumber = 0; pPriv->stateChanges = GCAllBits; return TRUE; }
/* ARGSUSED */ static void XawScrollbarInitialize(Widget request, Widget cnew, ArgList args, Cardinal *num_args) { ScrollbarWidget w = (ScrollbarWidget)cnew; CreateGC(cnew); if (XtWidth(w) == 0) XtWidth(w) = w->scrollbar.orientation == XtorientVertical ? w->scrollbar.thickness : w->scrollbar.length; if (XtHeight(w) == 0) XtHeight(w) = w->scrollbar.orientation == XtorientHorizontal ? w->scrollbar.thickness : w->scrollbar.length; SetDimensions(w); w->scrollbar.direction = 0; w->scrollbar.topLoc = 0; w->scrollbar.shownLength = w->scrollbar.min_thumb; }
main(int argc, char *argv[]) { Display *display; Window rootwindow, window; int screen, x, y, width, height, count; Visual *visual = CopyFromParent; GC gc; XEvent event; display = ConnectToServer(NULL, &screen, &rootwindow); x = y = 10; width = height = 300; window = OpenWindow(display, rootwindow, x, y, width, height, BlackPixel(display, screen), WhitePixel(display, screen), ExposureMask, visual); SetStandardHints(display, window, argv[0], argv[0], x, y, width, height); gc = CreateGC(display, window, BlackPixel(display, screen), WhitePixel(display, screen)); XMapRaised(display, window); XFlush(display); count = 0; while (count < 20) { XNextEvent(display, &event); if (event.type == Expose) { Redraw(display, window, gc); count++; } } XCloseDisplay(display); }
void Container::OpenAnimation(MotifUI *obj) { if (!_update || !_w || !XtIsRealized(_w)) return; Dimension w, h, w2, h2; int x0, y0, x1, y1, x2, y2, x_inc1, y_inc1, x_inc2, y_inc2, n; Window window, area; Widget widget; GC gc; if (_clipWidget) widget = _clipWidget; else widget = _w; XtVaGetValues(widget, XmNwidth, &w, XmNheight, &h, NULL); XtVaGetValues(obj->BaseWidget(), XmNwidth, &w2, XmNheight, &h2, NULL); area = XtWindow(widget); x1 = (int)w2 / 2; y1 = (int)h2 / 2; XTranslateCoordinates(display, XtWindow(obj->BaseWidget()), area, x1, y1, &x0, &y0, &window); n = 8; x_inc1 = -x0 / n; if (x_inc1 == 0) x_inc1 = -1; y_inc1 = -y0 / n; if (y_inc1 == 0) y_inc1 = -1; x_inc2 = (int)(w - x0) / n; if (x_inc2 == 0) x_inc2 = 1; y_inc2 = (int)(h - y0) / n; if (y_inc2 == 0) y_inc2 = 1; x1 = x0 + x_inc1; y1 = y0 + y_inc1; x2 = x0 + x_inc2; y2 = y0 + y_inc2; gc = CreateGC(widget); while (--n) { XDrawRectangle(display, area, gc, x1, y1, x2 - x1, y2 - y1); XFlush(display); x1 += x_inc1; y1 += y_inc1; x2 += x_inc2; y2 += y_inc2; MicroSleep(OPEN_TIME); } n = 8; x1 = x0 + x_inc1; y1 = y0 + y_inc1; x2 = x0 + x_inc2; y2 = y0 + y_inc2; while (--n) { XDrawRectangle(display, area, gc, x1, y1, x2 - x1, y2 - y1); XFlush(display); x1 += x_inc1; y1 += y_inc1; x2 += x_inc2; y2 += y_inc2; MicroSleep(OPEN_TIME); } XtReleaseGC(widget, gc); }
// main routine main(int argc, char **argv) { char string[BUFSIZ]; // connect to x-server int screen; Window rootwindow; Display *display = ConnectToServer(NULL, screen, rootwindow); if (display == NULL) { ERROR("connect to server failed.", EINVAL); return(2); } // get basic colors black = BlackPixel(display, screen); white = WhitePixel(display, screen); // create a window Visual *visual = CopyFromParent; int x = 10; int y = 10; int width = 300; int height = 300; Window window = OpenWindow(display, rootwindow, x, y, width, height, black, white, EVENT_MASK, visual); // set hints for window SetStandardHints(display, window, argv[0], argv[0], x, y, width, height); // create GC for drawing GC gc = CreateGC(display, window, black, white); // load a font XFontStruct *font_struct = LoadFont(display, FONT_NAME, FALLBACK_FONT_NAME); // set up gc with font structure XSetFont(display, gc, font_struct->fid); // map window XMapRaised(display, window); XFlush(display); // event loop: max of 20 events, then exit. KeySym keysym; XEvent event; for (int done = False; done != True; ) { XNextEvent(display, &event); switch (event.type) { case Expose: cout << "Expose: <x, y, w, h> = <"; cout << event.xexpose.x << ","; cout << event.xexpose.y << ","; cout << event.xexpose.width << ","; cout << event.xexpose.height; cout << ">" << endl; if (event.xexpose.count == 0) { cout << "last expose event." << endl; } break; case MapNotify: cout << "MapNotify: window was mapped." << endl; break; case ButtonPress: cout << "ButtonPress: "; cout << ButtonIds[event.xbutton.button]; cout << " at <"; cout << event.xbutton.x << ","; cout << event.xbutton.y << ">" << endl; AppendKeyStateMessage(event.xbutton.state); break; case EnterNotify: cout << "EnterNotify: pointer enters window" << endl; break; case LeaveNotify: cout << "LeaveNotify: pointer enters window" << endl; break; case ButtonRelease: cout << "ButtonRelease: "; cout << ButtonIds[event.xbutton.button]; cout << " at <"; cout << event.xbutton.x << ","; cout << event.xbutton.y << ">" << endl; AppendKeyStateMessage(event.xbutton.state); break; case KeyPress: done = DecodeKeyPress(&event.xkey, &keysym, string); HandleKeyPress(&event.xkey, keysym, string); break; case ConfigureNotify: cout << "ConfigureNotify: <x, y, w, h> = <"; cout << event.xconfigure.x << ","; cout << event.xconfigure.y << ","; cout << event.xconfigure.width << ","; cout << event.xconfigure.height; cout << ">" << endl; break; } // redraw for all events. if ( ! done) redraw(display, window, gc); } // close connection XFreeFont(display, font_struct); XCloseDisplay(display); // all done return(0); }
// main entry point main(int argc, char **argv) { // get command line options int nextarg; if (cmdopts(argc, argv, nextarg) != OK) { fprintf(stderr, "invalid command line option [%s].\n", argv[nextarg]); return(2); } // get data if (getdata(argc, argv, nextarg) != OK) { fprintf(stderr, "unable to get data."); return(2); } // connect to server Display *xdisplay = NULL; if (OpenDisplay(display, xdisplay) != OK) { fprintf(stderr, "unable to open display to server %s.\n", XDisplayName(display)); return(2); } // get physical screen attributes int xscreen; unsigned int display_width, display_height; if (GetDisplayAttributes(xdisplay, xscreen, display_width, display_height) != OK) { fprintf(stderr, "unable to get display attributes.\n"); CloseDisplay(xdisplay); return(2); } // determine window geometry and location int window_width, window_height, window_x, window_y; if (GetWindowGeometry(display_width, display_height, window_width, window_height, window_x, window_y) != OK) { fprintf(stderr, "unable to get window geometry.\n"); CloseDisplay(xdisplay); return(2); } // default black and white pixels unsigned long black = BlackPixel(xdisplay, xscreen); unsigned long white = WhitePixel(xdisplay, xscreen); // get pseudo-color display, if any int window_depth; Visual *window_visual; if (GetPseudoColorVisual(xdisplay, xscreen, window_visual, window_depth) != OK) { fprintf(stderr, "unable to get a color visual.\n"); CloseDisplay(xdisplay); return(2); } // create a window unsigned int window_border_width = 4; Window root_window = RootWindow(xdisplay, xscreen); window_visual=CopyFromParent; window_depth=CopyFromParent; Window window = CreateWindow( xdisplay, root_window, window_x, window_y, window_width, window_height, black, white, EventMask, window_visual, window_border_width, window_depth); // set size hints if (SetSizeHints(xdisplay, window, window_x, window_y, window_width, window_height) != OK) { fprintf(stderr, "unable to set window size hints.\n"); CloseDisplay(xdisplay); return(2); } // set window name if (SetWindowName(xdisplay, window, title) != OK) { fprintf(stderr, "unable to set window title.\n"); CloseDisplay(xdisplay); return(2); } // set class hints if (SetClassHints(xdisplay, window, argv[0], argv[0]) != OK) { fprintf(stderr, "unable to set class hints.\n"); CloseDisplay(xdisplay); return(2); } // set other window manager hints int initstate = (strcmp(iconic, "YES") == 0) ? IconicState : NormalState; if (SetWMHints(xdisplay, window, initstate) != OK) { fprintf(stderr, "unable to set WM hints.\n"); CloseDisplay(xdisplay); return(2); } // set up color map for window Colormap window_colormap; if (SetUpColorMap(xdisplay, xscreen, window, window_visual, window_colormap) != OK) { fprintf(stderr, "unable to set up a color map.\n"); CloseDisplay(xdisplay); return(2); } // allocate colors for background and foreground unsigned long window_background = AllocateColorByName(xdisplay, window_colormap, background, white); unsigned long window_foreground = AllocateColorByName(xdisplay, window_colormap, foreground, black); // get font for writing XFontStruct *xfont = LoadFont(xdisplay, font, "fixed"); if (xfont == NULL) { fprintf(stderr, "unable to load font.\n"); CloseDisplay(xdisplay); return(2); } // create GC for drawing GC gc = CreateGC(xdisplay, window, xfont, window_foreground, window_background); GC xor_gc = CreateXorGC(xdisplay, window, xfont, window_foreground, window_background); // map window XMapRaised(xdisplay, window); XFlush(xdisplay); // event loop int start_x = -1; int start_y = -1; int last_x = -1; int last_y = -1; XEvent event; KeySym keysym; char string[BUFSIZ]; for (int done = 0; !done; ) { XNextEvent(xdisplay, &event); switch (event.type) { case Expose: if (event.xexpose.count == 0) { redraw(xdisplay, window, gc, xfont, window_width, window_height); } break; case ConfigureNotify: window_x = event.xconfigure.x; window_y = event.xconfigure.y; window_width = event.xconfigure.width; window_height = event.xconfigure.height; break; case KeyPress: done = DecodeKeyPress(&event.xkey, &keysym, string); break; case MappingNotify: XRefreshKeyboardMapping(&event.xmapping); break; case ButtonPress: if (event.xbutton.button == Button1) { start_x = event.xbutton.x; start_y = event.xbutton.y; last_x = start_x; last_y = start_y; DrawBox(xdisplay, window, xor_gc, start_x, start_y, last_x, last_y); XFlush(xdisplay); } break; case ButtonRelease: if (event.xbutton.button == Button1) { if (start_x != last_x && start_y != last_y) { DrawBox(xdisplay, window, xor_gc, start_x, start_y, last_x, last_y); XFlush(xdisplay); UpdateLimits(start_x, start_y, last_x, last_y, window_width, window_height); XClearWindow(xdisplay, window); XFlush(xdisplay); redraw(xdisplay, window, gc, xfont, window_width, window_height); XFlush(xdisplay); } start_x = -1; start_y = -1; last_x = -1; last_y = -1; } else { // reset to original values. rminxval = reset_rminxval; rmaxxval = reset_rmaxxval; rminyval = reset_rminyval; rmaxyval = reset_rmaxyval; XClearWindow(xdisplay, window); XFlush(xdisplay); redraw(xdisplay, window, gc, xfont, window_width, window_height); XFlush(xdisplay); } break; case MotionNotify: if (event.xbutton.button == Button1) { DrawBox(xdisplay, window, xor_gc, start_x, start_y, last_x, last_y); last_x = event.xmotion.x; last_y = event.xmotion.y; DrawBox(xdisplay, window, xor_gc, start_x, start_y, last_x, last_y); XFlush(xdisplay); } break; } } // close display CloseDisplay(xdisplay); // all done return(0); }
CONDITION InitializeX(int ncolors) { unsigned long valuemask; XSetWindowAttributes attributes; int width, height; /* * DICOMXDISP_DWM ("DICOMXDISP_InitializeX: Initialize X system\n", * DIAG_INFORM); */ /* * Connect the client to the X server...the default display is the * contents of the DISPLAY environment variable */ if ((G_display = XOpenDisplay(display_name)) == NULL) { COND_PushCondition(DICOMXDISP_NOSERVER, "DICOMXDISP: Cannot connect to X server"); return (DICOMXDISP_NOSERVER); } G_screen = DefaultScreen(G_display); height = DisplayHeight(G_display, G_screen); width = DisplayWidth(G_display, G_screen); if ((G_display_height > height) || (G_display_height < 0)) G_display_height = height; if ((G_display_width > width) || (G_display_width < 0)) G_display_width = width; G_visual = DefaultVisual(G_display, G_screen); G_cmap = DefaultColormap(G_display, G_screen); /* create the graphics context */ if ((CreateGC()) != DICOMXDISP_NORMAL) { COND_PushCondition(DICOMXDISP_NOGRAPHICS, "%s", "DICOMXDISP: Cannot get graphics context"); return (DICOMXDISP_NOGRAPHICS); } /* * Allocate a gray-scale colormap */ if (LoadGrayMap(ncolors) != DICOMXDISP_NORMAL) { COND_PushCondition(DICOMXDISP_NOCOLORS, "%s", "DICOMXDISP: Cannot get enough colors"); return (DICOMXDISP_NOCOLORS); } /* * G_ncolors now contains the number of colors we acually got! */ valuemask = CWBackPixel; attributes.background_pixel = graylut[G_ncolors / 2]; G_big_window = XCreateWindow(G_display, RootWindow(G_display, G_screen), 0, 0, G_display_width, G_display_height, 0, CopyFromParent, InputOutput, CopyFromParent, valuemask, &attributes); XSelectInput(G_display, G_big_window, ButtonPressMask | SubstructureNotifyMask | ExposureMask | StructureNotifyMask); XMapWindow(G_display, G_big_window); XFlush(G_display); return (DICOMXDISP_NORMAL); }