void MCScreenDC::create_stipple() { graystipple = XCreatePixmap(dpy, getroot(), 32, 32, 1); gc1 = XCreateGC(dpy, graystipple, 0, NULL); XSetGraphicsExposures(dpy, gc1, False); XSetForeground(dpy, gc1, 1); XSetBackground(dpy, gc1, 0); Boolean oldshm = MCshm; MCBitmap *im = createimage(1, 64, 64, False, 0x0, True, False); int2 i; uint4 *dptr = (uint4 *)im->data; for (i = 0 ; i < 16 ; i++) { *dptr++ = 0xAAAAAAAA; *dptr++ = 0xAAAAAAAA; *dptr++ = 0x55555555; *dptr++ = 0x55555555; } putimage(graystipple, im, 0, 0, 0, 0, 32, 32); XSync(dpy, False); if (oldshm != MCshm) putimage(graystipple, im, 0, 0, 0, 0, 32, 32); destroyimage(im); }
QPixmap QX11WindowSurface::grabWidget(const QWidget *widget, const QRect& rect) const { if (!widget || d_ptr->device.isNull()) return QPixmap(); QRect srcRect; // make sure the rect is inside the widget & clip to widget's rect if (!rect.isEmpty()) srcRect = rect & widget->rect(); else srcRect = widget->rect(); if (srcRect.isEmpty()) return QPixmap(); // If it's a child widget we have to translate the coordinates if (widget != window()) srcRect.translate(widget->mapTo(window(), QPoint(0, 0))); QPixmap::x11SetDefaultScreen(widget->x11Info().screen()); QPixmap px(srcRect.width(), srcRect.height()); GC tmpGc = XCreateGC(X11->display, d_ptr->device.handle(), 0, 0); // Copy srcRect from the backing store to the new pixmap XSetGraphicsExposures(X11->display, tmpGc, False); XCopyArea(X11->display, d_ptr->device.handle(), px.handle(), tmpGc, srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height(), 0, 0); XFreeGC(X11->display, tmpGc); return px; }
/** Open a connection to the X server. */ void OpenConnection(void) { display = JXOpenDisplay(displayString); if(JUNLIKELY(!display)) { if(displayString) { printf("error: could not open display %s\n", displayString); } else { printf("error: could not open display\n"); } DoExit(1); } rootScreen = DefaultScreen(display); rootWindow = RootWindow(display, rootScreen); rootWidth = DisplayWidth(display, rootScreen); rootHeight = DisplayHeight(display, rootScreen); rootDepth = DefaultDepth(display, rootScreen); rootVisual = DefaultVisual(display, rootScreen); rootColormap = DefaultColormap(display, rootScreen); rootGC = DefaultGC(display, rootScreen); colormapCount = MaxCmapsOfScreen(ScreenOfDisplay(display, rootScreen)); XSetGraphicsExposures(display, rootGC, False); }
void QX11WindowSurface::setGeometry(const QRect &rect) { QWindowSurface::setGeometry(rect); const QSize size = rect.size(); if (d_ptr->device.size() == size || size.width() <= 0 || size.height() <= 0) return; #ifndef QT_NO_XRENDER if (d_ptr->translucentBackground) { QX11PixmapData *data = new QX11PixmapData(QPixmapData::PixmapType); data->xinfo = d_ptr->widget->x11Info(); data->resize(size.width(), size.height()); d_ptr->device = QPixmap(data); } else #endif { QPixmap::x11SetDefaultScreen(d_ptr->widget->x11Info().screen()); QX11PixmapData *oldData = static_cast<QX11PixmapData *>(d_ptr->device.pixmapData()); if (oldData && !(oldData->flags & QX11PixmapData::Uninitialized) && hasStaticContents()) { // Copy the content of the old pixmap into the new one. QX11PixmapData *newData = new QX11PixmapData(QPixmapData::PixmapType); newData->resize(size.width(), size.height()); Q_ASSERT(oldData->d == newData->d); QRegion staticRegion(staticContents()); // Make sure we're inside the boundaries of the old pixmap. staticRegion &= QRect(0, 0, oldData->w, oldData->h); const QRect boundingRect(staticRegion.boundingRect()); const int dx = boundingRect.x(); const int dy = boundingRect.y(); int num; XRectangle *rects = (XRectangle *)qt_getClipRects(staticRegion, num); GC tmpGc = XCreateGC(X11->display, oldData->hd, 0, 0); XSetClipRectangles(X11->display, tmpGc, 0, 0, rects, num, YXBanded); XCopyArea(X11->display, oldData->hd, newData->hd, tmpGc, dx, dy, qMin(boundingRect.width(), size.width()), qMin(boundingRect.height(), size.height()), dx, dy); XFreeGC(X11->display, tmpGc); newData->flags &= ~QX11PixmapData::Uninitialized; d_ptr->device = QPixmap(newData); } else { d_ptr->device = QPixmap(size); } } if (gc) { XFreeGC(X11->display, gc); gc = 0; } if (!d_ptr->device.isNull()) { gc = XCreateGC(X11->display, d_ptr->device.handle(), 0, 0); XSetGraphicsExposures(X11->display, gc, False); } }
void MCScreenDC::create_stipple() { graystipple = XCreatePixmap(dpy, getroot(), 32, 32, 1); gc1 = XCreateGC(dpy, graystipple, 0, NULL); XSetGraphicsExposures(dpy, gc1, False); XSetForeground(dpy, gc1, 1); XSetBackground(dpy, gc1, 0); }
void initHistory(Display *display, Window window, int canvas_width, int canvas_height){ int i; bottom=0; top=0; next=0; width=canvas_width; height=canvas_height; dis=display; win=window; // 履歴用ピックスマップ作成 for(i=0;i<MAX_HISTORY;i++){ history_pix[i] = XCreatePixmap( dis, win, width, height, DefaultDepth(dis,0) ); history_mask_pix[i] = XCreatePixmap( dis, win, width, height, 1 ); } hcopy_gc = XCreateGC( dis, DefaultRootWindow(dis), 0, 0 ); // GCの標準設定 XSetForeground( dis, hcopy_gc, GetColor( dis, "white") ); hmask_gc = XCreateGC( dis, history_mask_pix[0], 0, 0 ); // GCの標準設定 //XSetForeground( dis, hmask_gc, 1 ); for(i=0;i<MAX_HISTORY;i++){ XFillRectangle( dis, history_pix[i], hcopy_gc, 0, 0, width, height ); XFillRectangle( dis, history_mask_pix[i], hmask_gc, 0, 0, width, height ); } XSetGraphicsExposures( dis, hcopy_gc, False ); //これがないとコピー先にイベントマスクに //関係なくNoExposeイベントが送られてしまい、 //正常なイベント処理を妨げる。 XSetGraphicsExposures( dis, hmask_gc, False ); // 最終履歴用ピックスマップ作成 for(i=0;i<MAX_LAYER;i++){ last_pix[i] = XCreatePixmap( dis, win, width, height, DefaultDepth(dis,0) ); last_mask_pix[i] = XCreatePixmap( dis, win, width, height, 1 ); XFillRectangle( dis, last_pix[i], hcopy_gc, 0, 0, width, height ); XFillRectangle( dis, last_mask_pix[i], hmask_gc, 0, 0, width, height ); } }
void init_galaxy(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); unistruct *gp; if (universes == NULL) { if ((universes = (unistruct *) calloc(MI_NUM_SCREENS(mi), sizeof (unistruct))) == NULL) return; } gp = &universes[MI_SCREEN(mi)]; gp->f_hititerations = MI_CYCLES(mi); gp->clip.left = 0; gp->clip.top = 0; gp->clip.right = MI_WIDTH(mi); gp->clip.bottom = MI_HEIGHT(mi); gp->scale = (double) (gp->clip.right + gp->clip.bottom) / 8.0; gp->midx = gp->clip.right / 2; gp->midy = gp->clip.bottom / 2; if (MI_IS_FULLRANDOM(mi)) { gp->fisheye = !(NRAND(3)); if (!gp->fisheye) gp->tracks = (Bool) (LRAND() & 1); } else { gp->fisheye = fisheye; gp->tracks = tracks; } if (!startover(mi)) return; if (gp->fisheye) { if (gp->pixmap != None) XFreePixmap(display, gp->pixmap); if ((gp->pixmap = XCreatePixmap(display, MI_WINDOW(mi), MI_WIDTH(mi), MI_HEIGHT(mi), MI_DEPTH(mi))) == None) { gp->fisheye = False; } } if (gp->fisheye) { XSetGraphicsExposures(display, MI_GC(mi), False); gp->scale *= Z_OFFSET; gp->star_scale_Z = (gp->scale * .005); /* don't want any exposure events from XCopyPlane */ } }
static X11DRV_PDEVICE *create_x11_physdev( Drawable drawable ) { X11DRV_PDEVICE *physDev; InitOnceExecuteOnce( &init_once, device_init, NULL, NULL ); if (!(physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physDev) ))) return NULL; physDev->drawable = drawable; physDev->gc = XCreateGC( gdi_display, drawable, 0, NULL ); XSetGraphicsExposures( gdi_display, physDev->gc, False ); XSetSubwindowMode( gdi_display, physDev->gc, IncludeInferiors ); XFlush( gdi_display ); return physDev; }
static void CanvasCB(Widget canvas, XtPointer client, XEvent *ev, Boolean *cont) { Display *dpy = XtDisplay(canvas) ; Window win = XtWindow(canvas) ; int x0,y0 ; if( !canvas_init ) { Colormap cmap ; XColor y,b, dummy ; XtVaGetValues(canvas, XtNcolormap, &cmap, 0) ; canvasGc = XCreateGC(dpy,win, 0,NULL) ; XSetLineAttributes(dpy, canvasGc, 8, LineSolid, CapButt, JoinRound); XSetGraphicsExposures(dpy, canvasGc, True) ; XAllocNamedColor(dpy, cmap, "yellow", &y, &dummy) ; yellow = y.pixel ; XAllocNamedColor(dpy, cmap, "black", &b, &dummy) ; black = b.pixel ; canvas_init = True ; } switch( ev->type ) { case GraphicsExpose: case Expose: x0 = MwRulerValue2Position(topRuler, 1.) ; y0 = MwRulerValue2Position(leftRuler, 1.) - 100 ; XSetForeground(dpy,canvasGc, yellow) ; XFillArc(dpy,win,canvasGc, x0,y0, 100,100, 0,360*64) ; XSetForeground(dpy,canvasGc, black) ; XDrawArc(dpy,win,canvasGc, x0,y0, 100,100, 0,360*64) ; XFillArc(dpy,win,canvasGc, x0+30,y0+30, 10,10, 0,360*64) ; XFillArc(dpy,win,canvasGc, x0+60,y0+30, 10,10, 0,360*64) ; XDrawArc(dpy,win,canvasGc, x0+20,y0+20, 60,60, 225*64,90*64) ; break ; case EnterNotify: MwRulerShowPointer(leftRuler, True) ; MwRulerShowPointer(topRuler, True) ; break ; case LeaveNotify: MwRulerShowPointer(leftRuler, False) ; MwRulerShowPointer(topRuler, False) ; break ; case MotionNotify: MwRulerSetIValue(leftRuler, ev->xmotion.y) ; MwRulerSetIValue(topRuler, ev->xmotion.x) ; break ; } }
static PyObject * PaxGC_SetGraphicsExposures(PaxGCObject *self, PyObject*args) { int arg1; if (self->shared) { PyErr_SetString(PyExc_TypeError, "can't modify shared GC"); return NULL; } if (!PyArg_ParseTuple(args, "i", &arg1)) return NULL; XSetGraphicsExposures(self->display, self->gc, (Bool)arg1); Py_INCREF(Py_None); return Py_None; }
void QX11WindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset) { if (d_ptr->device.isNull()) return; #ifndef Q_FLATTEN_EXPOSE extern void *qt_getClipRects(const QRegion &r, int &num); // in qpaintengine_x11.cpp extern QWidgetData* qt_widget_data(QWidget *); QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft(); GC gc = XCreateGC(X11->display, d_ptr->device.handle(), 0, 0); QRegion wrgn(rgn); QRect br = rgn.boundingRect(); if (!wOffset.isNull()) wrgn.translate(-wOffset); QRect wbr = wrgn.boundingRect(); // #### why dirty widget here? should be up to date already // if (br.right() + offset.x() >= d_ptr->device.size().width() || br.bottom() + offset.y() >= d_ptr->device.size().height()) { // // QRegion dirty = rgn - QRect(-offset, d_ptr->device.size()); // // qDebug() << dirty; // widget->d_func()->dirtyWidget_sys(rgn - QRect(-offset, d_ptr->device.size())); // } int num; XRectangle *rects = (XRectangle *)qt_getClipRects(wrgn, num); // qDebug() << "XSetClipRectangles"; // for (int i = 0; i < num; ++i) // qDebug() << " " << i << rects[i].x << rects[i].x << rects[i].y << rects[i].width << rects[i].height; XSetClipRectangles(X11->display, gc, 0, 0, rects, num, YXBanded); #else Q_UNUSED(rgn); XGCValues values; values.subwindow_mode = IncludeInferiors; GC gc = XCreateGC(X11->display, d_ptr->device.handle(), GCSubwindowMode, &values); #endif XSetGraphicsExposures(X11->display, gc, False); // XFillRectangle(X11->display, widget->handle(), gc, 0, 0, widget->width(), widget->height()); #ifndef Q_FLATTEN_EXPOSE XCopyArea(X11->display, d_ptr->device.handle(), widget->handle(), gc, br.x() + offset.x(), br.y() + offset.y(), br.width(), br.height(), wbr.x(), wbr.y()); #else Q_ASSERT(widget->isWindow()); XCopyArea(X11->display, d_ptr->device.handle(), widget->handle(), gc, offset.x(), offset.y(), widget->width(), widget->height(), 0, 0); #endif XFreeGC(X11->display, gc); }
QPixmap QX11GLWindowSurface::grabWidget(const QWidget *widget, const QRect& rect) const { if (!widget || m_backBuffer.isNull()) return QPixmap(); QRect srcRect; // make sure the rect is inside the widget & clip to widget's rect if (!rect.isEmpty()) srcRect = rect & widget->rect(); else srcRect = widget->rect(); if (srcRect.isEmpty()) return QPixmap(); // If it's a child widget we have to translate the coordinates if (widget != window()) srcRect.translate(widget->mapTo(window(), QPoint(0, 0))); QPixmap::x11SetDefaultScreen(widget->x11Info().screen()); QX11PixmapData *pmd = new QX11PixmapData(QPixmapData::PixmapType); pmd->resize(srcRect.width(), srcRect.height()); QPixmap px(pmd); GC tmpGc = XCreateGC(X11->display, m_backBuffer.handle(), 0, 0); // Make sure all GL rendering is complete before copying the window QGLContext* ctx = static_cast<QX11GLPixmapData*>(m_backBuffer.pixmapData())->context(); if (QGLContext::currentContext() != ctx && ctx && ctx->isValid()) ctx->makeCurrent(); eglWaitClient(); // Copy srcRect from the backing store to the new pixmap XSetGraphicsExposures(X11->display, tmpGc, False); XCopyArea(X11->display, m_backBuffer.handle(), px.handle(), tmpGc, srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height(), 0, 0); XFreeGC(X11->display, tmpGc); // Wait until the copy has finised before allowing more rendering into the back buffer eglWaitNative(EGL_CORE_NATIVE_ENGINE); return px; }
/********************************************************************** * X11DRV_CreateDC */ BOOL X11DRV_CreateDC( HDC hdc, X11DRV_PDEVICE **pdev, LPCWSTR driver, LPCWSTR device, LPCWSTR output, const DEVMODEW* initData ) { X11DRV_PDEVICE *physDev; if (!device_init_done) device_init(); physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physDev) ); if (!physDev) return FALSE; *pdev = physDev; physDev->hdc = hdc; if (GetObjectType( hdc ) == OBJ_MEMDC) { if (!BITMAP_stock_phys_bitmap.hbitmap) BITMAP_stock_phys_bitmap.hbitmap = GetCurrentObject( hdc, OBJ_BITMAP ); physDev->bitmap = &BITMAP_stock_phys_bitmap; physDev->drawable = BITMAP_stock_phys_bitmap.pixmap; physDev->depth = 1; SetRect( &physDev->drawable_rect, 0, 0, 1, 1 ); physDev->dc_rect = physDev->drawable_rect; } else { physDev->bitmap = NULL; physDev->drawable = root_window; physDev->depth = screen_depth; physDev->drawable_rect = virtual_screen_rect; SetRect( &physDev->dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left, virtual_screen_rect.bottom - virtual_screen_rect.top ); } physDev->region = CreateRectRgn( 0, 0, 0, 0 ); wine_tsx11_lock(); physDev->gc = XCreateGC( gdi_display, physDev->drawable, 0, NULL ); XSetGraphicsExposures( gdi_display, physDev->gc, False ); XSetSubwindowMode( gdi_display, physDev->gc, IncludeInferiors ); XFlush( gdi_display ); wine_tsx11_unlock(); return TRUE; }
QPixmap QX11WindowSurface::grabWidget(const QWidget *widget, const QRect& rect) const { if (d_ptr->device.isNull()) return QPixmap(); QRect br = rect; QRect wbr(widget->geometry()); if (wbr.isNull()) return QPixmap(); int w = qMin(rect.size().width(), wbr.size().width()); if (!w) w = qMax(rect.size().width(), wbr.size().width()); int h = qMin(rect.size().height(), wbr.size().height()); if (!h) h = qMax(rect.size().height(), wbr.size().height()); if (br.isNull()) br = wbr; QPixmap::x11SetDefaultScreen(widget->x11Info().screen()); QPixmap px(w, h); GC gc = XCreateGC(X11->display, d_ptr->device.handle(), 0, 0); XRectangle xrect; xrect.x = short(wbr.x()); xrect.y = short(wbr.y()); xrect.width = ushort(wbr.width()); xrect.height = ushort(wbr.height()); XSetClipRectangles(X11->display, gc, 0, 0, &xrect, 1, YXBanded); XSetGraphicsExposures(X11->display, gc, False); XCopyArea(X11->display, d_ptr->device.handle(), px.handle(), gc, br.x(), br.y(), br.width(), br.height(), 0, 0); XFreeGC(X11->display, gc); return px; }
static void * rocks_init (Display *d, Window w) { struct state *st = (struct state *) calloc (1, sizeof(*st)); int i; XGCValues gcv; Colormap cmap; XWindowAttributes xgwa; unsigned int bg; st->dpy = d; st->window = w; XGetWindowAttributes (st->dpy, st->window, &xgwa); st->width = xgwa.width; st->height = xgwa.height; st->midx = st->width/2; st->midy = st->height/2; cmap = xgwa.colormap; st->delay = get_integer_resource (st->dpy, "delay", "Integer"); if (st->delay < 0) st->delay = 0; st->speed = get_integer_resource (st->dpy, "speed", "Integer"); if (st->speed < 1) st->speed = 1; if (st->speed > 100) st->speed = 100; st->rotate_p = get_boolean_resource (st->dpy, "rotate", "Boolean"); st->move_p = get_boolean_resource (st->dpy, "move", "Boolean"); if (mono_p) st->ncolors = 2; else st->ncolors = get_integer_resource (st->dpy, "colors", "Colors"); if (st->ncolors < 2) { st->ncolors = 2; mono_p = True; } st->colors = (XColor *) malloc(st->ncolors * sizeof(*st->colors)); st->draw_gcs = (GC *) malloc(st->ncolors * sizeof(*st->draw_gcs)); bg = get_pixel_resource (st->dpy, cmap, "background", "Background"); st->colors[0].pixel = bg; st->colors[0].flags = DoRed|DoGreen|DoBlue; XQueryColor(st->dpy, cmap, &st->colors[0]); st->ncolors--; make_random_colormap(xgwa.screen, xgwa.visual, cmap, st->colors+1, &st->ncolors, True, True, 0, True); st->ncolors++; if (st->ncolors < 2) { st->ncolors = 2; mono_p = True; } if (mono_p) { unsigned int fg = get_pixel_resource(st->dpy, cmap, "foreground", "Foreground"); st->colors[1].pixel = fg; st->colors[1].flags = DoRed|DoGreen|DoBlue; XQueryColor(st->dpy, cmap, &st->colors[1]); gcv.foreground = fg; gcv.background = bg; st->draw_gcs[0] = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcv); st->draw_gcs[1] = st->draw_gcs[0]; } else for( i = 0; i < st->ncolors; i++ ) { gcv.foreground = st->colors[i].pixel; gcv.background = bg; st->draw_gcs[i] = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcv); } gcv.foreground = bg; st->erase_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcv); st->max_dep = (st->move_p ? MAX_DEP : 0); for (i = 0; i < SIN_RESOLUTION; i++) { st->sins [i] = sin ((((double) i) / (SIN_RESOLUTION / 2)) * M_PI); st->coss [i] = cos ((((double) i) / (SIN_RESOLUTION / 2)) * M_PI); } /* we actually only need i/speed of these, but wtf */ for (i = 1; i < (sizeof (st->depths) / sizeof (st->depths[0])); i++) st->depths [i] = atan (((double) 0.5) / (((double) i) / DEPTH_SCALE)); st->depths [0] = M_PI/2; /* avoid division by 0 */ st->threed = get_boolean_resource(st->dpy, "use3d", "Boolean"); if (st->threed) { gcv.background = bg; gcv.foreground = get_pixel_resource (st->dpy, cmap, "left3d", "Foreground"); st->threed_left_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground,&gcv); gcv.foreground = get_pixel_resource (st->dpy, cmap, "right3d", "Foreground"); st->threed_right_gc = XCreateGC (st->dpy, st->window,GCForeground|GCBackground,&gcv); st->threed_delta = get_float_resource(st->dpy, "delta3d", "Integer"); } /* don't want any exposure events from XCopyPlane */ for( i = 0; i < st->ncolors; i++) XSetGraphicsExposures (st->dpy, st->draw_gcs[i], False); XSetGraphicsExposures (st->dpy, st->erase_gc, False); st->nrocks = get_integer_resource (st->dpy, "count", "Count"); if (st->nrocks < 1) st->nrocks = 1; st->rocks = (struct rock *) calloc (st->nrocks, sizeof (struct rock)); init_pixmaps (st); XClearWindow (st->dpy, st->window); return st; }
static int initGraphics(struct state *st) { XGCValues xgcv; XWindowAttributes xgwa; /* XSetWindowAttributes xswa;*/ Colormap cmap; XColor color; int n, i; initCMap(st); XGetWindowAttributes(st->dpy,st->win,&xgwa); cmap=xgwa.colormap; /* xswa.backing_store=Always; XChangeWindowAttributes(st->dpy,st->win,CWBackingStore,&xswa);*/ xgcv.function=GXcopy; st->delay = get_integer_resource(st->dpy, "delay","Integer"); xgcv.foreground=get_pixel_resource (st->dpy, cmap, "background", "Background"); st->fgc[0]=XCreateGC(st->dpy, st->win, GCForeground|GCFunction,&xgcv); #ifdef HAVE_JWXYZ jwxyz_XSetAntiAliasing (st->dpy, st->fgc[0], False); #endif n=0; if (mono_p) { xgcv.foreground=get_pixel_resource (st->dpy, cmap, "foreground", "Foreground"); st->fgc[1]=XCreateGC(st->dpy,st->win,GCForeground|GCFunction,&xgcv); #ifdef HAVE_JWXYZ jwxyz_XSetAntiAliasing (st->dpy, st->fgc[1], False); #endif for (i=0;i<st->numColors;i+=2) st->fgc[i]=st->fgc[0]; for (i=1;i<st->numColors;i+=2) st->fgc[i]=st->fgc[1]; } else { for (i = 0; i < st->numColors; i++) { color.red=st->colors[n++]<<8; color.green=st->colors[n++]<<8; color.blue=st->colors[n++]<<8; color.flags=DoRed|DoGreen|DoBlue; XAllocColor(st->dpy,cmap,&color); xgcv.foreground=color.pixel; st->fgc[i] = XCreateGC(st->dpy, st->win, GCForeground | GCFunction,&xgcv); #ifdef HAVE_JWXYZ jwxyz_XSetAntiAliasing (st->dpy, st->fgc[i], False); #endif } } st->cgc = XCreateGC(st->dpy,st->win,GCForeground|GCFunction,&xgcv); XSetGraphicsExposures(st->dpy,st->cgc,False); #ifdef HAVE_JWXYZ jwxyz_XSetAntiAliasing (st->dpy, st->cgc, False); #endif st->xsize = xgwa.width; st->ysize = xgwa.height; st->xc = st->xsize >> 1; st->yc = st->ysize >> 1; st->maxx = 1.0; st->maxy = st->ysize/(float)st->xsize; if (st->colorScheme < 0) st->colorScheme = random()%NUM_SCHEMES; return True; }
void init_window(int argc, char *argv[]) { unsigned long get_color_pix(char *color_name); screen = DefaultScreen(display); #if defined(HAVE_BZERO) && !defined(HAVE_MEMSET) bzero(&xsh, sizeof(xsh)); #else memset(&xsh, 0, sizeof(xsh)); #endif if (geometry) { int bitmask; bitmask = XGeometry(display, screen, geometry, NULL, bwidth, 1, 1, 1, 1, &(xsh.x), &(xsh.y), &(xsh.width), &(xsh.height)); if (bitmask & (XValue | YValue)) { xsh.flags |= USPosition; } if (bitmask & (WidthValue | HeightValue)) { xsh.flags |= USSize; } } else { xsh.flags = USPosition | PSize; if (!landscape) { xsh.width = XLENG / shrink; xsh.height = YLENG / shrink; xsh.x = X0; xsh.y = Y0; } else { xsh.width = YLENG / shrink; xsh.height = XLENG / shrink; xsh.x = X0_LAND; xsh.y = Y0; } } /** Color **/ #ifdef COLOR_BUG reverse = 1; #endif if (DisplayPlanes(display, screen) >= 3) { c_flg = 1; if (!reverse) { forepix = get_color_pix(fore_color); backpix = get_color_pix(back_color); highpix = get_color_pix(high_color); brdrpix = get_color_pix(brdr_color); mouspix = get_color_pix(mous_color); } else { forepix = get_color_pix(back_color); backpix = get_color_pix(fore_color); highpix = get_color_pix(high_color); brdrpix = get_color_pix(brdr_color); mouspix = get_color_pix(mous_color); } } else { if (!reverse) { forepix = BlackPixel(display, screen); highpix = BlackPixel(display, screen); backpix = WhitePixel(display, screen); brdrpix = BlackPixel(display, screen); mouspix = BlackPixel(display, screen); } else { forepix = WhitePixel(display, screen); highpix = WhitePixel(display, screen); backpix = BlackPixel(display, screen); brdrpix = WhitePixel(display, screen); mouspix = WhitePixel(display, screen); } } /** Generate Window **/ main_window = XCreateSimpleWindow(display, DefaultRootWindow(display), xsh.x, xsh.y, xsh.width, xsh.height, bwidth, brdrpix, backpix); XSetStandardProperties(display, main_window, windowtitle, windowtitle, None, argv, argc, &xsh); /* winatt.bit_gravity = SouthWestGravity; */ XChangeWindowAttributes(display, main_window, CWBitGravity, &winatt); /** Map Window **/ XSelectInput(display, main_window, StructureNotifyMask); XMapWindow(display, main_window); for (;;) { XNextEvent(display, &ev); if (ev.type == MapNotify) break; } XSelectInput(display, main_window, ButtonPressMask | PointerMotionMask | KeyPressMask | ExposureMask); /* KeyReleaseMask|ExposureMask|StructureNotifyMask); */ /** Cursor **/ watch_cur = XCreateFontCursor(display, XC_watch); XDefineCursor(display, main_window, watch_cur); /** GC **/ gcval.line_width = 1; gc = XCreateGC(display, main_window, GCLineWidth, &gcval); XSetFunction(display, gc, GXcopy); XSetGraphicsExposures(display, gc, False); XSetForeground(display, gc, forepix); XSetBackground(display, gc, backpix); font = XLoadFont(display, f_name[fno]); XSetFont(display, gc, font); }
void init_puzzle(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); puzzlestruct *pp; int x, y; XPoint size; if (puzzles == NULL) { if ((puzzles = (puzzlestruct *) calloc(MI_NUM_SCREENS(mi), sizeof (puzzlestruct))) == NULL) return; } pp = &puzzles[MI_SCREEN(mi)]; if (pp->painted && pp->windowsize.x == MI_WIDTH(mi) && pp->windowsize.y == MI_HEIGHT(mi)) return; /* Debounce since refresh_puzzle is init_puzzle */ #ifdef HAVE_XPM if (pp->graphics_format >= IS_XPM) { /* This is needed when another program changes the colormap. */ free_puzzle(display, pp); } #endif if (!init_stuff(mi)) return; pp->excount = MI_COUNT(mi); if (pp->excount < 0) { if (pp->fixbuff != NULL) { free(pp->fixbuff); pp->fixbuff = (int *) NULL; } pp->excount = NRAND(-pp->excount) + 1; } pp->lastbox = -1; pp->moves = 0; pp->movingBox = False; pp->windowsize.x = MI_WIDTH(mi); pp->windowsize.y = MI_HEIGHT(mi); if (pp->windowsize.x < 7) pp->windowsize.x = 7; if (pp->windowsize.y < 7) pp->windowsize.y = 7; pp->forward = 1; pp->prev = 0; /* don't want any exposure events from XCopyArea */ XSetGraphicsExposures(display, pp->backGC, False); MI_CLEARWINDOWCOLORMAP(mi, pp->backGC, pp->black); if (pp->logo) { size.x = (pp->logo->width < pp->windowsize.x) ? pp->logo->width : pp->windowsize.x; size.y = (pp->logo->height < pp->windowsize.y) ? pp->logo->height : pp->windowsize.y; } else { size.x = pp->windowsize.x; size.y = pp->windowsize.y; } pp->boxsize.y = NRAND(1 + size.y / 4) + 6; pp->boxsize.x = NRAND(1 + size.x / 4) + 6; if ((pp->boxsize.x > 4 * pp->boxsize.y) || pp->boxsize.y > 4 * pp->boxsize.x) pp->boxsize.x = pp->boxsize.y = 2 * MIN(pp->boxsize.x, pp->boxsize.y); pp->count.x = size.x / pp->boxsize.x; pp->count.y = size.y / pp->boxsize.y; if (pp->bufferBox != None) { XFreePixmap(display, pp->bufferBox); pp->bufferBox = None; } pp->usablewindow.x = pp->count.x * pp->boxsize.x; pp->usablewindow.y = pp->count.y * pp->boxsize.y; pp->offsetwindow.x = (pp->windowsize.x - pp->usablewindow.x) / 2; pp->offsetwindow.y = (pp->windowsize.y - pp->usablewindow.y) / 2; pp->incrementOfMove = MIN(pp->usablewindow.x, pp->usablewindow.y) / 20; pp->incrementOfMove = MAX(pp->incrementOfMove, 1); if (pp->logo) { pp->randompos.x = NRAND(MAX((pp->windowsize.x - pp->logo->width), 2 * pp->offsetwindow.x + 1)); pp->randompos.y = NRAND(MAX((pp->windowsize.y - pp->logo->height), 2 * pp->offsetwindow.y + 1)); if (MI_NPIXELS(mi) <= 2) XSetForeground(display, pp->backGC, MI_WHITE_PIXEL(mi)); else XSetForeground(display, pp->backGC, MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)))); (void) XPutImage(display, window, pp->backGC, pp->logo, (int) (NRAND(MAX(1, (pp->logo->width - pp->usablewindow.x)))), (int) (NRAND(MAX(1, (pp->logo->height - pp->usablewindow.y)))), pp->randompos.x, pp->randompos.y, pp->usablewindow.x, pp->usablewindow.y); XSetForeground(display, pp->backGC, pp->black); for (x = 0; x <= pp->count.x; x++) { int tempx = x * pp->boxsize.x; XDrawLine(display, window, pp->backGC, tempx + pp->randompos.x, pp->randompos.y, tempx + pp->randompos.x, pp->usablewindow.y + pp->randompos.y); XDrawLine(display, window, pp->backGC, tempx + pp->randompos.x - 1, pp->randompos.y, tempx + pp->randompos.x - 1, pp->usablewindow.y + pp->randompos.y); } for (y = 0; y <= pp->count.y; y++) { int tempy = y * pp->boxsize.y; XDrawLine(display, window, pp->backGC, pp->randompos.x, tempy + pp->randompos.y, pp->usablewindow.x + pp->randompos.x, tempy + pp->randompos.y); XDrawLine(display, window, pp->backGC, pp->randompos.x, tempy + pp->randompos.y - 1, pp->usablewindow.x + pp->randompos.x, tempy + pp->randompos.y - 1); } } #ifdef NUMBERED else { if (pp->image) (void) XDestroyImage(pp->image); pp->randompos.x = pp->offsetwindow.x; pp->randompos.y = pp->offsetwindow.y; if (!NumberScreen(mi)) { release_puzzles(mi); return; } if ((pp->image = XGetImage(display, window, pp->offsetwindow.x, pp->offsetwindow.y, pp->usablewindow.x, pp->usablewindow.y, AllPlanes, (MI_NPIXELS(mi) <= 2) ? XYPixmap : ZPixmap)) == None) { free_puzzle(display, pp); return; } } pp->row = pp->count.y - 1; pp->col = pp->count.x - 1; #else pp->row = NRAND(pp->count.y); pp->col = NRAND(pp->count.x); #endif if ((pp->excount) && (pp->fixbuff == NULL)) if ((pp->fixbuff = (int *) calloc(pp->excount, sizeof (int))) == NULL) { free_puzzle(display, pp); return; } pp->painted = True; }
void init_eyes(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); EyeScrInfo *ep; int i; /*- * Initialization that only needs to be done once. If the * release hook is called, this stuff may be freed and this * function will have to allocate it again next time the * init hook is called. */ if (eye_info == NULL) { if ((eye_info = (EyeScrInfo *) calloc(MI_NUM_SCREENS(mi), sizeof (EyeScrInfo))) == NULL) return; } ep = &eye_info[MI_SCREEN(mi)]; if (ep->flypix == None) { getPixmap(mi, window, FLY_WIDTH, FLY_HEIGHT, FLY_BITS, &(ep->flywidth), &(ep->flyheight), &(ep->flypix), &(ep->graphics_format)); if (ep->flypix == None) { free_eyes(display, ep); return; } #ifdef XBM_GRELB if (ep->graphics_format == IS_XBM) { ep->graphics_format =0; getPixmap(mi, window, FLY2_WIDTH, FLY2_HEIGHT, FLY2_BITS, &(ep->fly2width), &(ep->fly2height), &(ep->fly2pix), &(ep->graphics_format)); if (ep->fly2pix == None) { free_eyes(display, ep); return; } } #endif } if (ep->flyGC == None) { XGCValues gcv; gcv.foreground = MI_BLACK_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); if ((ep->flyGC = XCreateGC(display, window, GCForeground | GCBackground, &gcv)) == None) { free_eyes(display, ep); return; } } if (ep->eyeGC == None) { if ((ep->eyeGC = XCreateGC(display, window, (unsigned long) 0, (XGCValues *) NULL)) == None) { free_eyes(display, ep); return; } } ep->time = 0; /* don't want any exposure events from XCopyArea */ XSetGraphicsExposures(display, ep->eyeGC, False); freePairsOfEyes(display, ep); if (MI_IS_ICONIC(mi)) ep->num_eyes = 1; else { ep->num_eyes = MI_COUNT(mi); /* MAX_EYES is used or one may quickly run out of memory */ if (ep->num_eyes > MAX_EYES) ep->num_eyes = MAX_EYES; if (ep->num_eyes < 0) { if (ep->num_eyes < -MAX_EYES) ep->num_eyes = NRAND(MAX_EYES) + 1; else ep->num_eyes = NRAND(-ep->num_eyes) + 1; /* Add 1 so its not too boring */ } } if (!ep->eyes) { if ((ep->eyes = (Eyes *) calloc(ep->num_eyes, sizeof (Eyes))) == NULL) { free_eyes(display, ep); return; } } for (i = 0; i < ep->num_eyes; i++) { /* place each eye pair */ /* don't assume None == 0 */ ep->eyes[i].pixmap = None; create_eyes(mi, &(ep->eyes[i]), ep->eyes, ep->num_eyes); } init_fly(mi, &(ep->fly)); /* init the bouncer */ if (trackmouse && !ep->cursor) { /* Create an invisible cursor */ Pixmap bit; XColor black; black.red = 0; black.green = 0; black.blue = 0; black.flags = DoRed | DoGreen | DoBlue; if ((bit = XCreatePixmapFromBitmapData(display, window, (char *) "\000", 1, 1, MI_BLACK_PIXEL(mi), MI_BLACK_PIXEL(mi), 1)) == None) { free_eyes(display, ep); return; } if ((ep->cursor = XCreatePixmapCursor(display, bit, bit, &black, &black, 0, 0)) == None) { free_eyes(display, ep); return; } XFreePixmap(display, bit); } XDefineCursor(display, window, ep->cursor); MI_CLEARWINDOW(mi); }
/********************************************************************** * ExtEscape (X11DRV.@) */ static INT X11DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data, INT out_count, LPVOID out_data ) { X11DRV_PDEVICE *physDev = get_x11drv_dev( dev ); switch(escape) { case QUERYESCSUPPORT: if (in_data && in_count >= sizeof(DWORD)) { switch (*(const INT *)in_data) { case X11DRV_ESCAPE: return TRUE; } } break; case X11DRV_ESCAPE: if (in_data && in_count >= sizeof(enum x11drv_escape_codes)) { switch(*(const enum x11drv_escape_codes *)in_data) { case X11DRV_SET_DRAWABLE: if (in_count >= sizeof(struct x11drv_escape_set_drawable)) { const struct x11drv_escape_set_drawable *data = in_data; physDev->dc_rect = data->dc_rect; physDev->drawable = data->drawable; XFreeGC( gdi_display, physDev->gc ); physDev->gc = XCreateGC( gdi_display, physDev->drawable, 0, NULL ); XSetGraphicsExposures( gdi_display, physDev->gc, False ); XSetSubwindowMode( gdi_display, physDev->gc, data->mode ); TRACE( "SET_DRAWABLE hdc %p drawable %lx dc_rect %s\n", dev->hdc, physDev->drawable, wine_dbgstr_rect(&physDev->dc_rect) ); return TRUE; } break; case X11DRV_GET_DRAWABLE: if (out_count >= sizeof(struct x11drv_escape_get_drawable)) { struct x11drv_escape_get_drawable *data = out_data; data->drawable = physDev->drawable; data->dc_rect = physDev->dc_rect; return TRUE; } break; case X11DRV_FLUSH_GL_DRAWABLE: if (in_count >= sizeof(struct x11drv_escape_flush_gl_drawable)) { const struct x11drv_escape_flush_gl_drawable *data = in_data; RECT rect = physDev->dc_rect; OffsetRect( &rect, -physDev->dc_rect.left, -physDev->dc_rect.top ); /* The GL drawable may be lagged behind if we don't flush first, so * flush the display make sure we copy up-to-date data */ XFlush( gdi_display ); XSetFunction( gdi_display, physDev->gc, GXcopy ); XCopyArea( gdi_display, data->gl_drawable, physDev->drawable, physDev->gc, 0, 0, rect.right, rect.bottom, physDev->dc_rect.left, physDev->dc_rect.top ); add_device_bounds( physDev, &rect ); return TRUE; } break; case X11DRV_START_EXPOSURES: XSetGraphicsExposures( gdi_display, physDev->gc, True ); physDev->exposures = 0; return TRUE; case X11DRV_END_EXPOSURES: if (out_count >= sizeof(HRGN)) { HRGN hrgn = 0, tmp = 0; XSetGraphicsExposures( gdi_display, physDev->gc, False ); if (physDev->exposures) { for (;;) { XEvent event; XWindowEvent( gdi_display, physDev->drawable, ~0, &event ); if (event.type == NoExpose) break; if (event.type == GraphicsExpose) { RECT rect; rect.left = event.xgraphicsexpose.x - physDev->dc_rect.left; rect.top = event.xgraphicsexpose.y - physDev->dc_rect.top; rect.right = rect.left + event.xgraphicsexpose.width; rect.bottom = rect.top + event.xgraphicsexpose.height; if (GetLayout( dev->hdc ) & LAYOUT_RTL) mirror_rect( &physDev->dc_rect, &rect ); TRACE( "got %s count %d\n", wine_dbgstr_rect(&rect), event.xgraphicsexpose.count ); if (!tmp) tmp = CreateRectRgnIndirect( &rect ); else SetRectRgn( tmp, rect.left, rect.top, rect.right, rect.bottom ); if (hrgn) CombineRgn( hrgn, hrgn, tmp, RGN_OR ); else { hrgn = tmp; tmp = 0; } if (!event.xgraphicsexpose.count) break; } else { ERR( "got unexpected event %d\n", event.type ); break; } } if (tmp) DeleteObject( tmp ); } *(HRGN *)out_data = hrgn; return TRUE; } break; default: break; } } break; } return 0; }
/********************************************************************** * ExtEscape (X11DRV.@) */ static INT X11DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data, INT out_count, LPVOID out_data ) { X11DRV_PDEVICE *physDev = get_x11drv_dev( dev ); switch(escape) { case QUERYESCSUPPORT: if (in_data) { switch (*(const INT *)in_data) { case DCICOMMAND: return DD_HAL_VERSION; case X11DRV_ESCAPE: return TRUE; } } break; case X11DRV_ESCAPE: if (in_data && in_count >= sizeof(enum x11drv_escape_codes)) { switch(*(const enum x11drv_escape_codes *)in_data) { case X11DRV_SET_DRAWABLE: if (in_count >= sizeof(struct x11drv_escape_set_drawable)) { const struct x11drv_escape_set_drawable *data = in_data; physDev->dc_rect = data->dc_rect; physDev->drawable = data->drawable; wine_tsx11_lock(); XSetSubwindowMode( gdi_display, physDev->gc, data->mode ); wine_tsx11_unlock(); TRACE( "SET_DRAWABLE hdc %p drawable %lx dc_rect %s\n", dev->hdc, physDev->drawable, wine_dbgstr_rect(&physDev->dc_rect) ); return TRUE; } break; case X11DRV_GET_DRAWABLE: if (out_count >= sizeof(struct x11drv_escape_get_drawable)) { struct x11drv_escape_get_drawable *data = out_data; data->drawable = physDev->drawable; return TRUE; } break; case X11DRV_START_EXPOSURES: wine_tsx11_lock(); XSetGraphicsExposures( gdi_display, physDev->gc, True ); wine_tsx11_unlock(); physDev->exposures = 0; return TRUE; case X11DRV_END_EXPOSURES: if (out_count >= sizeof(HRGN)) { HRGN hrgn = 0, tmp = 0; wine_tsx11_lock(); XSetGraphicsExposures( gdi_display, physDev->gc, False ); wine_tsx11_unlock(); if (physDev->exposures) { for (;;) { XEvent event; wine_tsx11_lock(); XWindowEvent( gdi_display, physDev->drawable, ~0, &event ); wine_tsx11_unlock(); if (event.type == NoExpose) break; if (event.type == GraphicsExpose) { RECT rect; rect.left = event.xgraphicsexpose.x - physDev->dc_rect.left; rect.top = event.xgraphicsexpose.y - physDev->dc_rect.top; rect.right = rect.left + event.xgraphicsexpose.width; rect.bottom = rect.top + event.xgraphicsexpose.height; if (GetLayout( dev->hdc ) & LAYOUT_RTL) mirror_rect( &physDev->dc_rect, &rect ); TRACE( "got %s count %d\n", wine_dbgstr_rect(&rect), event.xgraphicsexpose.count ); if (!tmp) tmp = CreateRectRgnIndirect( &rect ); else SetRectRgn( tmp, rect.left, rect.top, rect.right, rect.bottom ); if (hrgn) CombineRgn( hrgn, hrgn, tmp, RGN_OR ); else { hrgn = tmp; tmp = 0; } if (!event.xgraphicsexpose.count) break; } else { ERR( "got unexpected event %d\n", event.type ); break; } } if (tmp) DeleteObject( tmp ); } *(HRGN *)out_data = hrgn; return TRUE; } break; default: break; } } break; } return 0; }
void XmLPixmapDraw(Widget w, Pixmap pixmap, Pixmap pixmask, int pixmapWidth, int pixmapHeight, unsigned char alignment, GC gc, XRectangle *rect, XRectangle *clipRect) { Display *dpy; Window win; int px, py, x, y, width, height, drawType; if (pixmap == XmUNSPECIFIED_PIXMAP) return; dpy = XtDisplay(w); win = XtWindow(w); width = pixmapWidth; height = pixmapHeight; if (!width || !height) { alignment = XmALIGNMENT_TOP_LEFT; width = clipRect->width - 4; height = clipRect->height - 4; } drawType = XmLDrawCalc(w, width, height, alignment, rect, clipRect, &x, &y); if (drawType == XmLDrawNODRAW) return; px = 0; py = 0; /* clip top */ if (clipRect->y > y && clipRect->y < y + height - 1) { py = clipRect->y - y; y += py; height -= py; } /* clip bottom */ if (clipRect->y + (int)clipRect->height - 1 >= y && clipRect->y + (int)clipRect->height - 1 <= y + height - 1) height = clipRect->y + clipRect->height - y; /* clip left */ if (clipRect->x > x && clipRect->x < x + width - 1) { px = clipRect->x - x; x += px; width -= px; } /* clip right */ if (clipRect->x + (int)clipRect->width - 1 >= x && clipRect->x + (int)clipRect->width - 1 <= x + width - 1) width = clipRect->x + clipRect->width - x; if (pixmask != XmUNSPECIFIED_PIXMAP) { XSetClipMask(dpy, gc, pixmask); XSetClipOrigin(dpy, gc, x - px, y - py); } XSetGraphicsExposures(dpy, gc, False); XCopyArea(dpy, pixmap, win, gc, px, py, width, height, x, y); XSetGraphicsExposures(dpy, gc, True); if (pixmask != XmUNSPECIFIED_PIXMAP) { XSetClipMask(dpy, gc, None); XSetClipOrigin(dpy, gc, 0, 0); } }
void medmInit(char *displayFont) { XmFontListEntry entry; int i; char dashList[2]; Boolean useDefaultFont; char *sizePosition; #if 0 /* KE: This doesn't appear in the Motif documentation. * Assume it is not needed any more. */ XmRegisterConverters(); #endif #if 0 /* Register action table */ XtAppAddActions(appContext,actions,XtNumber(actions)); #endif /* Register a warning handler */ XtSetWarningHandler((XtErrorHandler)trapExtraneousWarningsHandler); /* Initialize alarm color array */ alarmColorPixel[NO_ALARM]=getPixelFromColormapByString(display, screenNum,cmap,alarmColorString[NO_ALARM]); alarmColorPixel[MINOR_ALARM]=getPixelFromColormapByString(display, screenNum,cmap,alarmColorString[MINOR_ALARM]); alarmColorPixel[MAJOR_ALARM]=getPixelFromColormapByString(display, screenNum,cmap,alarmColorString[MAJOR_ALARM]); alarmColorPixel[INVALID_ALARM]=getPixelFromColormapByString(display, screenNum,cmap,alarmColorString[INVALID_ALARM]); alarmColorPixel[ALARM_MAX-1]=getPixelFromColormapByString(display, screenNum,cmap,alarmColorString[ALARM_MAX-1]); /* Initialize Channel Access */ medmCAInitialize(); /* Initialize DisplayInfo structures list */ displayInfoListHead = (DisplayInfo *)malloc(sizeof(DisplayInfo)); displayInfoListHead->next = NULL; displayInfoListTail = displayInfoListHead; /* Initialize DisplayInfoSave structures list */ displayInfoSaveListHead = (DisplayInfo *)malloc(sizeof(DisplayInfo)); displayInfoSaveListHead->next = NULL; displayInfoSaveListTail = displayInfoSaveListHead; /* Initialize common XmStrings */ dlXmStringMoreToComeSymbol = XmStringCreateLocalized(MORE_TO_COME_SYMBOL); /* Create the highlight GC */ highlightGC = XCreateGC(display,rootWindow,0,NULL); /* Eliminate events that we do not handle anyway */ XSetGraphicsExposures(display,highlightGC,False); /* Set the function to invert */ XSetFunction(display,highlightGC,GXinvert); /* Pick a color which XOR-ing with makes reasonable sense for most colors */ /* KE: Forground is irrelevant for GXinvert */ XSetForeground(display,highlightGC,WhitePixel(display,screenNum)); #if 0 XSetForeground(display,highlightGC,getPixelFromColormapByString(display, screenNum,cmap,"grey50")); #endif XSetLineAttributes(display,highlightGC,HIGHLIGHT_LINE_THICKNESS, LineOnOffDash,CapButt,JoinMiter); dashList[0] = 3; dashList[1] = 3; XSetDashes(display,highlightGC,0,dashList,2); /* Initialize the execute popup menu stuff for all shells. Must be consistent with medmWidget.h definitions. */ executePopupMenuButtonType[0] = XmPUSHBUTTON; executePopupMenuButtons[0] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_PRINT); executePopupMenuButtonType[1] = XmPUSHBUTTON; executePopupMenuButtons[1] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_CLOSE); executePopupMenuButtonType[2] = XmPUSHBUTTON; executePopupMenuButtons[2] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_PVINFO); executePopupMenuButtonType[3] = XmPUSHBUTTON; executePopupMenuButtons[3] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_PVLIMITS); executePopupMenuButtonType[4] = XmPUSHBUTTON; executePopupMenuButtons[4] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_MAIN); executePopupMenuButtonType[5] = XmPUSHBUTTON; executePopupMenuButtons[5] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_DISPLAY_LIST); executePopupMenuButtonType[6] = XmPUSHBUTTON; executePopupMenuButtons[6] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_FLASH_HIDDEN); executePopupMenuButtonType[7] = XmPUSHBUTTON; executePopupMenuButtons[7] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_REFRESH); executePopupMenuButtonType[8] = XmPUSHBUTTON; executePopupMenuButtons[8] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_RETRY); /* Note that the Execute Menu is a cascade button */ executePopupMenuButtonType[9] = XmCASCADEBUTTON; executePopupMenuButtons[9] = XmStringCreateLocalized(EXECUTE_POPUP_MENU_EXECUTE); /* Load font and fontList tables (but only once) */ if(!strcmp(displayFont,FONT_ALIASES_STRING)) { /* Use the ALIAS fonts if possible */ strcpy(displayFont,ALIAS_FONT_PREFIX); sizePosition = strstr(displayFont,"_"); printf("\n%s: Loading aliased fonts.",MEDM_VERSION_STRING); for(i = 0; i < MAX_FONTS; i++) { sprintf(sizePosition,"_%d",fontSizeTable[i]); fontTable[i] = XLoadQueryFont(display,displayFont); printf("."); if(fontTable[i] == NULL) { medmPrintf(1,"\nmedmInit: Unable to load font %s\n" " Trying default (fixed) instead\n", displayFont); /* one last attempt: try a common default font */ fontTable[i] = XLoadQueryFont(display,LAST_CHANCE_FONT); if(fontTable[i] == NULL) { medmCATerminate(); dmTerminateX(); exit(-1); } } /* Load the XmFontList table for Motif font sizing */ entry = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG, XmFONT_IS_FONT, (XtPointer)fontTable[i]); fontListTable[i] = XmFontListAppendEntry(NULL, entry); XmFontListEntryFree(&entry); } } else { /* Try using scalable font - either default or passed in one */ /* User requested default scalable, copy that name into string and proceed */ if(!strcmp(displayFont,DEFAULT_SCALABLE_STRING)) strcpy(displayFont,DEFAULT_SCALABLE_DISPLAY_FONT); useDefaultFont = !isScalableFont(displayFont); if(useDefaultFont) { /* This name wasn't in XLFD format */ medmPrintf(1,"\nmedmInit:" " Invalid scalable display font selected (Not in XLFD format)\n" " font: %s\n" " Using fixed font\n",displayFont); } else { printf("\n%s: Loading scalable fonts.",MEDM_VERSION_STRING); } for(i = 0; i < MAX_FONTS; i++) { if(!useDefaultFont) { fontTable[i] = loadQueryScalableFont(display, screenNum, displayFont, fontSizeTable[i]); printf("."); } else { fontTable[i] = XLoadQueryFont(display,LAST_CHANCE_FONT); } if(fontTable[i] == NULL) { medmCATerminate(); dmTerminateX(); exit(-1); } /* Load the XmFontList table for Motif font sizing */ entry = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG, XmFONT_IS_FONT, (XtPointer)fontTable[i]); fontListTable[i] = XmFontListAppendEntry(NULL, entry); XmFontListEntryFree(&entry); } } printf("\n"); }
static Bool InitializeAll(struct state *st) { XGCValues xgcv; XWindowAttributes xgwa; /* XSetWindowAttributes xswa;*/ Colormap cmap; XColor color; int n,i; double rspeed; st->cosilines = True; XGetWindowAttributes(st->dpy,st->win[0],&xgwa); cmap=xgwa.colormap; /* xswa.backing_store=Always; XChangeWindowAttributes(st->dpy,st->win[0],CWBackingStore,&xswa);*/ xgcv.function=GXcopy; xgcv.foreground=get_pixel_resource (st->dpy, cmap, "background", "Background"); st->fgc[32]=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); n=0; if (mono_p) { st->fgc[0]=st->fgc[32]; xgcv.foreground=get_pixel_resource (st->dpy, cmap, "foreground", "Foreground"); st->fgc[1]=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); for (i=0;i<32;i+=2) st->fgc[i]=st->fgc[0]; for (i=1;i<32;i+=2) st->fgc[i]=st->fgc[1]; } else for (i=0;i<32;i++) { color.red=colors[n++]<<8; color.green=colors[n++]<<8; color.blue=colors[n++]<<8; color.flags=DoRed|DoGreen|DoBlue; XAllocColor(st->dpy,cmap,&color); xgcv.foreground=color.pixel; st->fgc[i]=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); } st->cgc=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); XSetGraphicsExposures(st->dpy,st->cgc,False); st->cosilines = get_boolean_resource(st->dpy, "random","Boolean"); #ifdef HAVE_DOUBLE_BUFFER_EXTENSION if (get_boolean_resource (st->dpy, "useDBE", "Boolean")) st->usedouble = True; st->win[1] = xdbe_get_backbuffer (st->dpy, st->win[0], XdbeUndefined); if (!st->win[1]) { st->usedouble = False; st->win[1] = st->win[0]; } #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ st->delay=get_integer_resource(st->dpy, "delay","Integer"); rspeed=get_float_resource(st->dpy, "speed","Float"); if (rspeed<0.0001 || rspeed>0.2) { fprintf(stderr,"Speed not in valid range! (0.0001 - 0.2), using 0.1 \n"); rspeed=0.1; } st->sizx=xgwa.width; st->sizy=xgwa.height; st->midx=st->sizx>>1; st->midy=st->sizy>>1; st->stateX=0; st->stateY=0; if (!make_rots(st,rspeed,rspeed)) { fprintf(stderr,"Not enough memory for tables!\n"); return False; } return True; }
ENTRYPOINT void init_flow (ModeInfo * mi) { flowstruct *sp; char *name; if (flows == NULL) { if ((flows = (flowstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (flowstruct))) == NULL) return; } sp = &flows[MI_SCREEN(mi)]; sp->count2 = 0; sp->taillen = MI_SIZE(mi); if (sp->taillen < -MINTRAIL) { /* Change by sqrt so it seems more variable */ sp->taillen = NRAND((int)sqrt((double) (-sp->taillen - MINTRAIL + 1))); sp->taillen = sp->taillen * sp->taillen + MINTRAIL; } else if (sp->taillen < MINTRAIL) { sp->taillen = MINTRAIL; } if(!rotatep && !ridep) rotatep = True; /* We need at least one viewpoint */ /* Start camera at Orbit or Bee */ if(rotatep) { sp->chaseto = ORBIT; } else { sp->chaseto = BEE; } sp->chasetime = 1; /* Go directly to target */ sp->lyap = 0; sp->yperiod = 0; sp->step2 = INITIALSTEP; /* Zero parameter set */ memset(sp->par2, 0, N_PARS * sizeof(dvector)); /* Set up standard examples */ switch (NRAND((periodicp) ? 5 : 3)) { case 0: /* x' = a(y - x) y' = x(b - z) - y z' = xy - cz */ name = "Lorentz"; sp->par2[Y].x = 10 + balance_rand(5*0); /* a */ sp->par2[X].x = - sp->par2[Y].x; /* -a */ sp->par2[X].y = 28 + balance_rand(5*0); /* b */ sp->par2[XZ].y = -1; sp->par2[Y].y = -1; sp->par2[XY].z = 1; sp->par2[Z].z = - 2 + balance_rand(1*0); /* -c */ break; case 1: /* x' = -(y + az) y' = x + by z' = c + z(x - 5.7) */ name = "Rossler"; sp->par2[Y].x = -1; sp->par2[Z].x = -2 + balance_rand(1); /* a */ sp->par2[X].y = 1; sp->par2[Y].y = 0.2 + balance_rand(0.1); /* b */ sp->par2[C].z = 0.2 + balance_rand(0.1); /* c */ sp->par2[XZ].z = 1; sp->par2[Z].z = -5.7; break; case 2: /* x' = -(y + az) y' = x + by - cz^2 z' = 0.2 + z(x - 5.7) */ name = "RosslerCone"; sp->par2[Y].x = -1; sp->par2[Z].x = -2; /* a */ sp->par2[X].y = 1; sp->par2[Y].y = 0.2; /* b */ sp->par2[ZZ].y = -0.331 + balance_rand(0.01); /* c */ sp->par2[C].z = 0.2; sp->par2[XZ].z = 1; sp->par2[Z].z = -5.7; break; case 3: /* x' = -z + b sin(y) y' = c z' = 0.7x + az(0.1 - x^2) */ name = "Birkhoff"; sp->par2[Z].x = -1; sp->par2[SINY].x = 0.35 + balance_rand(0.25); /* b */ sp->par2[C].y = 1.57; /* c */ sp->par2[X].z = 0.7; sp->par2[Z].z = 1 + balance_rand(0.5); /* a/10 */ sp->par2[XXZ].z = -10 * sp->par2[Z].z; /* -a */ sp->yperiod = 2 * M_PI; break; default: /* x' = -ax - z/2 - z^3/8 + b sin(y) y' = c z' = 2x */ name = "Duffing"; sp->par2[X].x = -0.2 + balance_rand(0.1); /* a */ sp->par2[Z].x = -0.5; sp->par2[ZZZ].x = -0.125; sp->par2[SINY].x = 27.0 + balance_rand(3.0); /* b */ sp->par2[C].y = 1.33; /* c */ sp->par2[X].z = 2; sp->yperiod = 2 * M_PI; break; } sp->range.x = 5; sp->range.z = 5; if(sp->yperiod > 0) { sp->ODE = Periodic; /* periodic flows show either uniform distribution or a snapshot on the 'time' axis */ sp->range.y = NRAND(2)? sp->yperiod : 0; } else { sp->range.y = 5; sp->ODE = Cubic; } /* Run discoverer to set up bounding box, etc. Lyapunov will probably be innaccurate, since we're only running it once, but we're using known strange attractors so it should be ok. */ discover(mi); if(MI_IS_VERBOSE(mi)) fprintf(stdout, "flow: Lyapunov exponent: %g, step: %g, size: %g (%s)\n", sp->lyap2, sp->step2, sp->size2, name); /* Install new params */ sp->lyap = sp->lyap2; sp->size = sp->size2; sp->mid = sp->mid2; sp->step = sp->step2; memcpy(sp->par, sp->par2, sizeof(sp->par2)); sp->count2 = 0; /* Reset search */ free_flow(sp); sp->beecount = MI_COUNT(mi); if (sp->beecount < 0) { /* random variations */ sp->beecount = NRAND(-sp->beecount) + 1; /* Minimum 1 */ } # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ dbufp = False; # endif if(dbufp) { /* Set up double buffer */ if (sp->buffer != None) XFreePixmap(MI_DISPLAY(mi), sp->buffer); sp->buffer = XCreatePixmap(MI_DISPLAY(mi), MI_WINDOW(mi), MI_WIDTH(mi), MI_HEIGHT(mi), MI_DEPTH(mi)); } else { sp->buffer = MI_WINDOW(mi); } /* no "NoExpose" events from XCopyArea wanted */ XSetGraphicsExposures(MI_DISPLAY(mi), MI_GC(mi), False); /* Make sure we're using 'thin' lines */ XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), 0, LineSolid, CapNotLast, JoinMiter); /* Clear the background (may be slow depending on user prefs). */ MI_CLEARWINDOW(mi); /* Allocate memory. */ if (sp->csegs == NULL) { allocate(sp->csegs, XSegment, (sp->beecount + BOX_L) * MI_NPIXELS(mi) * sp->taillen); allocate(sp->cnsegs, int, MI_NPIXELS(mi)); allocate(sp->old_segs, XSegment, sp->beecount * sp->taillen); allocate(sp->p, dvector, sp->beecount * sp->taillen); }
int initsystem(void) /* retourne 1 si initialisation reussie */ { int i; int windowW; int windowH; XSetWindowAttributes xswa; XGCValues xgcv; XSizeHints xsh; windowW=WIDTH*RATIO; windowH=HEIGHT*RATIO; display=XOpenDisplay(0); if (!display) return(0); else { mousek=0; XAutoRepeatOff(display); timestart=last=systime(); screen=XDefaultScreenOfDisplay(display); rdepth=sdepth=XDefaultDepthOfScreen(screen); if (emulmono) sdepth=1; XSynchronize(display,0); black=XBlackPixelOfScreen(screen); white=XWhitePixelOfScreen(screen); colormap=XDefaultColormapOfScreen(screen); visual=XDefaultVisualOfScreen(screen); xswa.event_mask=VisibilityChangeMask; xswa.background_pixel=black; xswa.border_pixel=white; xswa.override_redirect=0; xswa.backing_store=Always; xswa.bit_gravity=StaticGravity; xswa.win_gravity=CenterGravity; window=XCreateWindow(display,XRootWindowOfScreen(screen), randval(50),randval(100),windowW,windowH,0, XDefaultDepthOfScreen(screen),InputOutput, XDefaultVisualOfScreen(screen), CWWinGravity|CWBitGravity|CWBackingStore|CWEventMask| CWBackPixel|CWOverrideRedirect|CWBorderPixel,&xswa); if (sdepth!=1) xcolormap=XCreateColormap(display,window, visual,AllocAll); xgcv.foreground = white; xgcv.background = black; gc=XCreateGC(display,window,GCForeground | GCBackground,&xgcv); XSetGraphicsExposures(display,gc,False); /* CAPITAL!!! : evite d'accumuler sans cesse des expose events */ xsh.x=0; xsh.y=0; xsh.width=windowW; xsh.height=windowH; xsh.min_width=windowW; xsh.max_width=windowW; xsh.min_height=windowH; xsh.max_height=windowH; xsh.flags=PPosition|PSize|PMinSize|PMaxSize; XSetNormalHints(display, window, &xsh); XStoreName(display,window,""); XMapWindow(display, window); XSelectInput(display,window,PointerMotionMask|ButtonPressMask| ButtonReleaseMask|KeyPressMask|KeyReleaseMask); XFlush(display); XSync(display,0); for (i=0; i<(NBCOLORS+2); i++) { if (i&1) pixels[i]=white; else pixels[i]=black; if (i==NBCOLORS) pixels[i]=0; if (i==(NBCOLORS+1)) pixels[i]=(1<<rdepth)-1; xgcv.foreground=pixels[i]; xgcv.background=black; gctab[i]=XCreateGC(display,window, GCForeground|GCBackground,&xgcv); XSetFunction(display,gctab[i],GXcopy); XSetFillStyle(display,gctab[i],FillSolid); } ecran[0]=XCreatePixmap(display,window,windowW,windowH,rdepth); ecran[1]=XCreatePixmap(display,window,windowW,windowH,rdepth); for(i=0; i<9; i++) graypixmap[i]=XCreatePixmapFromBitmapData(display,window, &graypat[i][0],8,8,white,black,rdepth); setpalette(egapal); cls(); swap(); cls(); empty(); waitdelay(500); return(1); } }
ENTRYPOINT void init_strange(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); #ifndef NO_DBUF Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); #endif ATTRACTOR *Attractor; if (Root == NULL) { if ((Root = (ATTRACTOR *) calloc(MI_NUM_SCREENS(mi), sizeof (ATTRACTOR))) == NULL) return; } Attractor = &Root[MI_SCREEN(mi)]; if (Attractor->Fold == NULL) { int i; if ((Attractor->Fold = (PRM *) calloc(UNIT2 + 1, sizeof (PRM))) == NULL) { free_strange(display, Attractor); return; } for (i = 0; i <= UNIT2; ++i) { DBL x; /* x = ( DBL )(i)/UNIT2; */ /* x = sin( M_PI/2.0*x ); */ /* x = sqrt( x ); */ /* x = x*x; */ /* x = x*(1.0-x)*4.0; */ x = (DBL) (i) / UNIT; x = sin(x); Attractor->Fold[i] = DBL_To_PRM(x); } } if (Attractor->Buffer1 == NULL) if ((Attractor->Buffer1 = (XPoint *) calloc(MAX_POINTS, sizeof (XPoint))) == NULL) { free_strange(display, Attractor); return; } if (Attractor->Buffer2 == NULL) if ((Attractor->Buffer2 = (XPoint *) calloc(MAX_POINTS, sizeof (XPoint))) == NULL) { free_strange(display, Attractor); return; } Attractor->Max_Pt = MAX_POINTS; Attractor->Width = MI_WIDTH(mi); Attractor->Height = MI_HEIGHT(mi); Attractor->Cur_Pt = 0; Attractor->Count = 0; Attractor->Col = NRAND(MI_NPIXELS(mi)); Attractor->Speed = 4; Attractor->Iterate = Funcs[NRAND(2)]; Random_Prm(Attractor->Prm1); Random_Prm(Attractor->Prm2); #ifndef NO_DBUF if (Attractor->dbuf != None) XFreePixmap(display, Attractor->dbuf); Attractor->dbuf = XCreatePixmap(display, window, Attractor->Width, Attractor->Height, 1); /* Allocation checked */ if (Attractor->dbuf != None) { XGCValues gcv; gcv.foreground = 0; gcv.background = 0; #ifndef HAVE_COCOA gcv.graphics_exposures = False; #endif /* HAVE_COCOA */ gcv.function = GXcopy; if (Attractor->dbuf_gc != None) XFreeGC(display, Attractor->dbuf_gc); if ((Attractor->dbuf_gc = XCreateGC(display, Attractor->dbuf, #ifndef HAVE_COCOA GCGraphicsExposures | #endif /* HAVE_COCOA */ GCFunction | GCForeground | GCBackground, &gcv)) == None) { XFreePixmap(display, Attractor->dbuf); Attractor->dbuf = None; } else { XFillRectangle(display, Attractor->dbuf, Attractor->dbuf_gc, 0, 0, Attractor->Width, Attractor->Height); XSetBackground(display, gc, MI_BLACK_PIXEL(mi)); XSetFunction(display, gc, GXcopy); } } #endif MI_CLEARWINDOW(mi); /* Do not want any exposure events from XCopyPlane */ XSetGraphicsExposures(display, MI_GC(mi), False); }
void Create_Window (char *geometry) { short q; Visual *vid; XSetWindowAttributes xswa; XSizeHints sizehint; XWMHints wmhints; int depth; unsigned char wname[256]; /* Window Name */ unsigned long vmask = CWEventMask | CWBackPixel | CWBackingStore; depth = DefaultDepth (display.dpy, display.screen); xswa.event_mask = 0; xswa.background_pixel = display.bg; xswa.backing_store = Always; printf ("DefaultVisual id=%d bp-rgb=%d map-entries=%d\n" ,(int) (*DefaultVisual (display.dpy, display.screen)).visualid ,(*DefaultVisual (display.dpy, display.screen)).bits_per_rgb ,(*DefaultVisual (display.dpy, display.screen)).map_entries); vid = DefaultVisual (display.dpy, display.screen); display.cmap = XDefaultColormap (display.dpy, display.screen); display.win = XCreateWindow (display.dpy, display.root, winX, winY, display.winW, display.winH, 0, depth, InputOutput, /* vid , */ DefaultVisual (display.dpy, display.screen), /* PseudoColor, */ vmask, &xswa); sizehint.x = winX - 100; sizehint.y = winY; sizehint.width = display.winW; sizehint.height = display.winH; sizehint.min_width = display.winW; sizehint.min_height = display.winH; sizehint.max_width = display.winW; sizehint.max_height = display.winH; /* GCS FIX: Be careful about resizing the opening screen */ /* WCK: Fixed. We lock it now, and unlock it after the opening screen. not gorgeous, but it works for now. Still need to clean up.*/ #define NO_RESIZABLE_WINDOWS 1 if (geometry != NULL) { #if defined (NO_RESIZABLE_WINDOWS) sizehint.flags = USPosition | USSize | PMinSize | PMaxSize; #else sizehint.flags = USPosition | USSize | PMinSize; #endif } else { #if defined (NO_RESIZABLE_WINDOWS) sizehint.flags = PPosition | PSize | PMinSize | PMaxSize; #else sizehint.flags = PPosition | PSize | PMinSize; #endif } XSetNormalHints (display.dpy, display.win, &sizehint); display.protocol_atom = XInternAtom (display.dpy, "WM_PROTOCOLS", False); display.kill_atom = XInternAtom (display.dpy, "WM_DELETE_WINDOW", False); /* Title */ sprintf ((char *) wname, _("xlincity, Version %s, " "(Copyright) IJ Peters - copying policy GNU GPL"), VERSION); XChangeProperty (display.dpy, display.win, XA_WM_NAME, XA_STRING, 8, PropModeReplace, wname, strlen ((char *) wname)); /* Window Manager Hints (This is supposed to make input work.) */ wmhints.flags = InputHint; wmhints.input = True; XSetWMHints (display.dpy, display.win, &wmhints); XMapWindow (display.dpy, display.win); XSelectInput (display.dpy, display.win, KeyPressMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | StructureNotifyMask); for (q = 0; q < 256; q++) { display.pixcolour_gc[q] = XCreateGC (display.dpy ,display.win, 0, NULL); XSetForeground (display.dpy, display.pixcolour_gc[q], q); XSetBackground (display.dpy, display.pixcolour_gc[q] ,display.bg); XSetGraphicsExposures (display.dpy, display.pixcolour_gc[q] ,False); } }
void Thumbnail::onResize() { Image* oldImage = _image; if (_image) { XftDrawDestroy(_xftDraw); XFreeGC(_dpy, _gc); } _image = new Image(_dpy, _width, _height); _gc = XCreateGC(_dpy, _image->pixmap(), 0, 0); XSetGraphicsExposures(_dpy, _gc, false); _xftDraw = XftDrawCreate(_dpy, _image->pixmap(), XTools::rgbaVisual()->visual, DefaultColormap(_dpy, DefaultScreen(_dpy))); XWindowAttributes attrs; XGetWindowAttributes(_dpy, _clientWindow, &attrs); _clientWidth = attrs.width; _clientHeight= attrs.height; #ifdef MAEMO4 _clientDecoX = attrs.x; _clientDecoY = attrs.y; #endif int borderWidth = Settings::instance()->borderWidth(); int headerHeight = Resources::instance()->headerMiddle()->height(); int oldClientScaledWidth = _clientScaledWidth; int oldClientScaledHeight= _clientScaledHeight; _clientScaledWidth = _width - 2 * borderWidth; _clientScaledHeight = _height - headerHeight - borderWidth; double scale = _clientScaledWidth; scale /= _clientWidth; _clientDecoXScaled = (int)round(scale * _clientDecoX); _clientDecoYScaled = (int)round(scale * _clientDecoY); _clientOffsetX = borderWidth; _clientOffsetY = headerHeight; XTransform xform = {{ { XDoubleToFixed(1.0/scale), XDoubleToFixed(0), XDoubleToFixed(0) }, { XDoubleToFixed(0), XDoubleToFixed(1.0/scale), XDoubleToFixed(0) }, { XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1) }, } }; XRenderSetPictureTransform(_dpy, _clientPict, &xform); if (_minimized && oldImage != 0) { // Workaround for corner case: if this function is called when // client is minimized, we need to rescale cached pixmap, because // can't grab new picture from window // Yes, this function MAY be called when client is minimised - for // example when thumbnail needs to be resized because number of // windows changed Image* temp = new Image(_dpy, _clientScaledWidth, _clientScaledHeight, 32); XTransform xform = {{ { XDoubleToFixed(((double)oldClientScaledWidth)/_clientScaledWidth), XDoubleToFixed(0), XDoubleToFixed(0) }, { XDoubleToFixed(0), XDoubleToFixed(((double)oldClientScaledHeight)/_clientScaledHeight), XDoubleToFixed(0) }, { XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1) } } }; XRenderSetPictureTransform(_dpy, oldImage->picture(), &xform); XRenderComposite(_dpy, PictOpSrc, oldImage->picture(), 0, temp->picture(), _clientOffsetX*_clientScaledWidth/oldClientScaledWidth, _clientOffsetY*_clientScaledHeight/oldClientScaledHeight, 0, 0, 0, 0, _clientScaledWidth, _clientScaledHeight ); XCopyArea(_dpy, temp->pixmap(), _image->pixmap(), _gc, 0, 0, _clientScaledWidth, _clientScaledHeight, _clientOffsetX, _clientOffsetY ); delete temp; } _previewValid = false; delete oldImage; redraw(); }
/*-------------------------------------------------------------------------- ** Purpose: Windows thread. ** ** Parameters: Name Description. ** ** Returns: Nothing. ** **------------------------------------------------------------------------*/ void *windowThread(void *param) { GC gc; KeySym key; KeySym modList[2]; Pixmap pixmap; XEvent event; XWMHints wmhints; int screen, depth; char text[30]; unsigned long fg, bg; int len; XWindowAttributes a; XColor b,c; static int refreshCount = 0; char str[2] = " "; DispList *curr; DispList *end; u8 oldFont = 0; Atom targetProperty; Atom retAtom; Atom wmDeleteWindow; int retFormat; int retStatus; unsigned long retRemaining; unsigned long retLength; int usageDisplayCount = 0; /* ** Open the X11 display. */ disp = XOpenDisplay(0); if (disp == (Display *) NULL) { fprintf(stderr, "Could not open display\n"); exit(1); } screen = DefaultScreen(disp); /* ** Create a window using the following hints. */ width = 1100; height = 750; bg = BlackPixel(disp, screen); fg = WhitePixel(disp, screen); window = XCreateSimpleWindow (disp, DefaultRootWindow(disp), 10, 10, width, height, 5, fg, bg); /* ** Create a pixmap for background image generation. */ depth = DefaultDepth (disp, screen); pixmap = XCreatePixmap (disp, window, width, height, depth); /* ** Set window and icon titles. */ XSetStandardProperties (disp, window, DtCyberVersion " - " DtCyberCopyright " - " DtCyberLicense, DtCyberVersion, None, NULL, 0, NULL); /* ** Create the graphics contexts for window and pixmap. */ gc = XCreateGC (disp, window, 0, 0); /* ** We don't want to get Expose events, otherwise every XCopyArea will generate one, ** and the event queue will fill up. This application will discard them anyway, but ** it is better not to generate them in the first place. */ XSetGraphicsExposures(disp, gc, FALSE); /* ** Load three Cyber fonts. */ hSmallFont = XLoadFont(disp, "-*-lucidatypewriter-medium-*-*-*-10-*-*-*-*-*-*-*\0"); hMediumFont = XLoadFont(disp, "-*-lucidatypewriter-medium-*-*-*-14-*-*-*-*-*-*-*\0"); hLargeFont = XLoadFont(disp, "-*-lucidatypewriter-medium-*-*-*-24-*-*-*-*-*-*-*\0"); /* ** Setup fore- and back-ground colors. */ XGetWindowAttributes(disp,window,&a); XAllocNamedColor(disp, a.colormap,"green",&b,&c); fg=b.pixel; bg = BlackPixel(disp, screen); XSetBackground(disp, gc, bg); XSetForeground(disp, gc, fg); /* ** Create mappings of some ALT-key combinations to strings. */ modList[0] = XK_Meta_L; XRebindKeysym(disp, '0', modList, 1, (u8 *)"$0", 2); XRebindKeysym(disp, '1', modList, 1, (u8 *)"$1", 2); XRebindKeysym(disp, '2', modList, 1, (u8 *)"$2", 2); XRebindKeysym(disp, '3', modList, 1, (u8 *)"$3", 2); XRebindKeysym(disp, '4', modList, 1, (u8 *)"$4", 2); XRebindKeysym(disp, '5', modList, 1, (u8 *)"$5", 2); XRebindKeysym(disp, '6', modList, 1, (u8 *)"$6", 2); XRebindKeysym(disp, '7', modList, 1, (u8 *)"$7", 2); XRebindKeysym(disp, '8', modList, 1, (u8 *)"$8", 2); XRebindKeysym(disp, '9', modList, 1, (u8 *)"$9", 2); XRebindKeysym(disp, 'c', modList, 1, (u8 *)"$c", 2); XRebindKeysym(disp, 'C', modList, 1, (u8 *)"$c", 2); XRebindKeysym(disp, 'e', modList, 1, (u8 *)"$e", 2); XRebindKeysym(disp, 'E', modList, 1, (u8 *)"$e", 2); XRebindKeysym(disp, 'x', modList, 1, (u8 *)"$x", 2); XRebindKeysym(disp, 'X', modList, 1, (u8 *)"$x", 2); XRebindKeysym(disp, 'p', modList, 1, (u8 *)"$p", 2); XRebindKeysym(disp, 'P', modList, 1, (u8 *)"$p", 2); /* ** Initialise input. */ wmhints.flags = InputHint; wmhints.input = True; XSetWMHints(disp, window, &wmhints); XSelectInput (disp, window, KeyPressMask | KeyReleaseMask | StructureNotifyMask); /* ** We like to be on top. */ XMapRaised (disp, window); /* ** Create atom for paste operations, */ targetProperty = XInternAtom(disp, "DtCYBER", False); /* ** Create atom for delete message and set window manager. */ wmDeleteWindow = XInternAtom(disp, "WM_DELETE_WINDOW", False); XSetWMProtocols(disp, window, &wmDeleteWindow, 1); /* ** Window thread loop. */ displayActive = TRUE; while(displayActive) { /* ** Process paste buffer one character a time. */ if (lpClipToKeyboardPtr != NULL) { if (clipToKeyboardDelay != 0) { /* ** Delay after CR. */ clipToKeyboardDelay -= 1; } else { ppKeyIn = *lpClipToKeyboardPtr++; if (ppKeyIn == 0) { /* ** All paste data has been processed - clean up. */ XFree(lpClipToKeyboard); lpClipToKeyboard = NULL; lpClipToKeyboardPtr = NULL; } else if (ppKeyIn == '\n') { /* ** Substitute to a CR to be able to handle DOS/Windows or UNIX style ** line terminators. */ ppKeyIn = '\r'; /* ** Short delay to allow PP program to process the line. This may ** require customisation. */ clipToKeyboardDelay = 30; } else if (ppKeyIn == '\r') { /* ** Ignore CR. */ ppKeyIn = 0; } } } /* ** Process any X11 events. */ while (XEventsQueued(disp, QueuedAfterReading)) { XNextEvent(disp, &event); switch (event.type) { case ClientMessage: if (event.xclient.data.l[0] == wmDeleteWindow) { /* ** Initiate display of usage note because user attempts to close the window. */ usageDisplayCount = 5 * FramesPerSecond; } break; case MappingNotify: XRefreshKeyboardMapping ((XMappingEvent *)&event); refresh = TRUE; break; case ConfigureNotify: if (event.xconfigure.width > width || event.xconfigure.height > height) { /* ** Reallocate pixmap only if it has grown. */ width = event.xconfigure.width; height = event.xconfigure.height; XFreePixmap (disp, pixmap); pixmap = XCreatePixmap (disp, window, width, height, depth); } XFillRectangle (disp, pixmap, gc, 0, 0, width, height); refresh = TRUE; break; case KeyPress: len = XLookupString ((XKeyEvent *)&event, text, 10, &key, 0); if (len == 1) { ppKeyIn = text[0]; usleep(5000); } else if (len == 2 && text[0] == '$') { switch (text[1]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': traceMask ^= (1 << (text[1] - '0')); break; case 'c': traceMask ^= (1 << 14); break; case 'e': traceMask ^= (1 << 15); break; case 'x': if (traceMask == 0) { traceMask = ~0; } else { traceMask = 0; } break; case 'p': if (lpClipToKeyboardPtr != NULL) { /* ** Ignore paste request when a previous one is still executing. */ break; } if (targetProperty == None) { /* ** The paste operation atom has not been created. This is bad, but ** not fatal, so we silently ignore paste requests. */ break; } /* ** Request the server to send an event to the present owner of the selection, ** asking the owner to convert the data in the selection to the required type. */ XConvertSelection(disp, XA_PRIMARY, XA_STRING, targetProperty, window, event.xbutton.time); break; } } break; case KeyRelease: len = XLookupString((XKeyEvent *)&event, text, 10, &key, 0); if (len == 1) { switch (text[0]) { default: break; } } break; case SelectionNotify: /* ** The present owner of the selection has replied. */ if (event.xselection.property != targetProperty) { /* ** The current selection is not a string, so we ignore it. */ break; } /* ** Fetch up to 1 kb from the selection. */ retStatus = XGetWindowProperty(disp, window, event.xselection.property, 0L, 1024, False, AnyPropertyType, &retAtom, &retFormat, &retLength, &retRemaining, &lpClipToKeyboard); if (retStatus == Success) { lpClipToKeyboardPtr = lpClipToKeyboard; } else { lpClipToKeyboard = NULL; lpClipToKeyboardPtr = NULL; } break; } } /* ** Process any refresh request. */ XSetForeground (disp, gc, fg); XSetFont(disp, gc, hSmallFont); oldFont = FontSmall; #if CcCycleTime { extern double cycleTime; char buf[80]; sprintf(buf, "Cycle time: %.3f", cycleTime); XDrawString(disp, pixmap, gc, 0, 10, buf, strlen(buf)); } #endif #if CcDebug == 1 { char buf[160]; /* ** Display P registers of PPUs and CPU and current trace mask. */ sprintf(buf, "Refresh: %-10d PP P-reg: %04o %04o %04o %04o %04o %04o %04o %04o %04o %04o CPU P-reg: %06o", refreshCount++, ppu[0].regP, ppu[1].regP, ppu[2].regP, ppu[3].regP, ppu[4].regP, ppu[5].regP, ppu[6].regP, ppu[7].regP, ppu[8].regP, ppu[9].regP, cpu.regP); sprintf(buf + strlen(buf), " Trace: %c%c%c%c%c%c%c%c%c%c%c%c", (traceMask >> 0) & 1 ? '0' : '_', (traceMask >> 1) & 1 ? '1' : '_', (traceMask >> 2) & 1 ? '2' : '_', (traceMask >> 3) & 1 ? '3' : '_', (traceMask >> 4) & 1 ? '4' : '_', (traceMask >> 5) & 1 ? '5' : '_', (traceMask >> 6) & 1 ? '6' : '_', (traceMask >> 7) & 1 ? '7' : '_', (traceMask >> 8) & 1 ? '8' : '_', (traceMask >> 9) & 1 ? '9' : '_', (traceMask >> 14) & 1 ? 'C' : '_', (traceMask >> 15) & 1 ? 'E' : '_'); XDrawString(disp, pixmap, gc, 0, 10, buf, strlen(buf)); } #endif if (opActive) { /* ** Display pause message. */ static char opMessage[] = "Emulation paused"; XSetFont(disp, gc, hLargeFont); oldFont = FontLarge; XDrawString(disp, pixmap, gc, 20, 256, opMessage, strlen(opMessage)); } /* ** Protect display list. */ pthread_mutex_lock(&mutexDisplay); if (usageDisplayCount != 0) { /* ** Display usage note when user attempts to close window. */ static char usageMessage1[] = "Please don't just close the window, but instead first cleanly halt the operating system and"; static char usageMessage2[] = "then use the 'shutdown' command in the operator interface to terminate the emulation."; XSetFont(disp, gc, hMediumFont); oldFont = FontMedium; XDrawString(disp, pixmap, gc, 20, 256, usageMessage1, strlen(usageMessage1)); XDrawString(disp, pixmap, gc, 20, 275, usageMessage2, strlen(usageMessage2)); listEnd = 0; usageDisplayCount -= 1; } /* ** Draw display list in pixmap. */ curr = display; end = display + listEnd; for (curr = display; curr < end; curr++) { /* ** Setup new font if necessary. */ if (oldFont != curr->fontSize) { oldFont = curr->fontSize; switch (oldFont) { case FontSmall: XSetFont(disp, gc, hSmallFont); break; case FontMedium: XSetFont(disp, gc, hMediumFont); break; case FontLarge: XSetFont(disp, gc, hLargeFont); break; } } /* ** Draw dot or character. */ if (curr->fontSize == FontDot) { XDrawPoint(disp, pixmap, gc, curr->xPos, (curr->yPos * 14) / 10 + 20); } else { str[0] = curr->ch; XDrawString(disp, pixmap, gc, curr->xPos, (curr->yPos * 14) / 10 + 20, str, 1); } } listEnd = 0; currentX = -1; currentY = -1; refresh = FALSE; /* ** Release display list. */ pthread_mutex_unlock (&mutexDisplay); /* ** Update display from pixmap. */ XCopyArea(disp, pixmap, window, gc, 0, 0, width, height, 0, 0); /* ** Erase pixmap for next round. */ XSetForeground (disp, gc, bg); XFillRectangle (disp, pixmap, gc, 0, 0, width, height); /* ** Make sure the updates make it to the X11 server. */ XSync(disp, 0); /* ** Give other threads a chance to run. This may require customisation. */ usleep(FrameTime); } XSync(disp, 0); XFreeGC (disp, gc); XFreePixmap (disp, pixmap); XDestroyWindow (disp, window); XCloseDisplay (disp); pthread_exit(NULL); }