//========================================= // prepare when ready //----------------------------------------- void prepare (void) { int count; char disp[80] = ""; if (displayname != NULL) { sprintf(disp,"DISPLAY=%s",displayname); putenv (disp); } //========================================= // start windowmanager... //----------------------------------------- wmpid = fork(); switch(wmpid) { case -1: perror("fork"); exit(1); break; case 0: execl(FVWM,"fvwm2","-f",FVWMRC,NULL); break; default: waitpid ( wmpid, NULL, WNOHANG | WUNTRACED ); } //========================================= // enable accessX... //----------------------------------------- XAccess(dpy,displayname); //========================================= // set the fashion style for all displays // including Xinerama handling here... //------------------------------------------ CountScreens (dpy); for (count = 0;count < scr_count; count++) { int bannerpid; int current_screen = scr[count]; Window root = RootWindow(dpy, current_screen); int depth = DefaultDepth(dpy,current_screen); char* display = (char*)malloc(sizeof(char)*128); char* dspstr = (char*)malloc(sizeof(char)*128); char* color = (char*)malloc(sizeof(char)*128); char screenStr [255] = ""; char x [128] = ""; char y [128] = ""; int x1,y1,width,height; GC mgc = DefaultGC(dpy,current_screen); Cursor cursor; //========================================= // set the background to darkSlateBlue //----------------------------------------- sprintf(color,"MidnightBlue"); if (blank) { sprintf(color,"black"); } XSetWindowBackground( dpy, root, NameToPixel( color,BlackPixel(dpy,current_screen),dpy,current_screen ) ); XClearWindow(dpy,root); XSetCloseDownMode(dpy, RetainPermanent); usleep (1000); if (blank) { XFlush(dpy); } //========================================= // set the corner marks //----------------------------------------- if (! blank) { setCorner ("10x15-0-0",dpy,current_screen); setCorner ("10x15-0+0",dpy,current_screen); setCorner ("10x15+0-0",dpy,current_screen); setCorner ("10x15+0+0",dpy,current_screen); //========================================= // set the bounding rectangle //----------------------------------------- setBounding (dpy,current_screen); //========================================= // set the SuSE Linux banner //----------------------------------------- if (DisplayPlanes (dpy, current_screen) >= 8) { sprintf(dspstr,"%s",displayname); dspstr = strtok (dspstr,"."); sprintf(display,"%s.%d",dspstr,current_screen); sprintf(x,"%d",DisplayWidth (dpy,current_screen) - 150); sprintf(y,"%d",DisplayHeight (dpy,current_screen) - 80); bannerpid = fork(); switch(bannerpid) { case -1: perror("fork"); exit(1); break; case 0: execl ( XBanner,"xbanner", "-file",XBannerFile,"-display",display, "-px",x,"-py",y,NULL ); break; default: waitpid ( bannerpid, NULL, 0 ); } //=================================================== // create a xlook banner on all non primary screen // pointing out, that this screen is not the one // the configuration program is running on //--------------------------------------------------- if (current_screen > 0) { int HasRender; sprintf(screenStr,"%s %d. %s 1.", gettext("Display"),count+1, gettext("Configuration on display") ); HasRender = XTestRender (dpy); if (! HasRender) { break; } img = setText ( dpy,current_screen,screenStr,&imgx,&imgy ); } //========================================= // set save area of the root window to be // restored on demand //----------------------------------------- x1 = DisplayWidth (dpy,current_screen) - 380; y1 = DisplayHeight (dpy,current_screen) - 120; width = 380; height = 120; save[current_screen].width = width; save[current_screen].height = height; save[current_screen].x1 = x1; save[current_screen].y1 = y1; save[current_screen].bg = XCreatePixmap ( dpy,root,width,height,depth ); XCopyArea ( dpy,root,save[current_screen].bg,mgc,x1,y1,width,height,0,0 ); } //========================================= // set the cursor look and feel //----------------------------------------- cursor = CreateCursorFromName(dpy,current_screen,"top_left_arrow"); if (cursor) { XDefineCursor (dpy,root,cursor); XFreeCursor (dpy,cursor); } } } //========================================= // Enter main loop, restore and redraw //----------------------------------------- if (! blank) { looppid = fork(); switch (looppid) { case -1: perror("fork"); exit(1); break; case 0: while(1) { usleep (50000); RedrawWindow(); } break; } } }
/*******************************************************************************\ |* copyXBMArea *| \*******************************************************************************/ void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy) { XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); }
static unsigned long wander_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; int i; if (st->eraser) { st->eraser = erase_window (st->dpy, st->window, st->eraser); goto END; } for (i = 0; i < 2000; i++) { if (NRAND (st->density)) { st->x = st->last_x; st->y = st->last_y; } else { st->last_x = st->x; st->last_y = st->y; st->x += st->width_1 + NRAND (3); while (st->x >= st->width) st->x -= st->width; st->y += st->height_1 + NRAND (3); while (st->y >= st->height) st->y -= st->height; } if (NRAND (st->length_limit) == 0) { if (st->advance == 0) { st->color_index = NRAND (st->color_count); } else { st->color_index = (st->color_index + st->advance) % st->color_count; } st->color = st->colors [st->color_index].pixel; XSetForeground (st->dpy, st->context, st->color); if (st->circles) { XFillArc (st->dpy, st->pixmap, st->context, 0, 0, st->size, st->size, 0, 360 * 64); } } if (st->reset_p || NRAND (st->reset_limit) == 0) { st->reset_p = 0; st->eraser = erase_window (st->dpy, st->window, st->eraser); st->color = st->colors [NRAND (st->color_count)].pixel; st->x = NRAND (st->width); st->y = NRAND (st->height); st->last_x = st->x; st->last_y = st->y; if (st->circles) { XFillArc (st->dpy, st->pixmap, st->context, 0, 0, st->size, st->size, 0, 360*64); } } if (st->size == 1) { XDrawPoint (st->dpy, st->window, st->context, st->x, st->y); } else { if (st->circles) { XCopyArea (st->dpy, st->pixmap, st->window, st->context, 0, 0, st->size, st->size, st->x * st->size, st->y * st->size); } else { XFillRectangle (st->dpy, st->window, st->context, st->x * st->size, st->y * st->size, st->size, st->size); } } } END: return st->delay; }
static void redrawKrt() { XCopyArea(display, krtImage[scale - 1], win, gc, 0, 0, lineWidth * 8 * scale, lines * scale, start_x, start_y); }
void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset) { Q_D(QRasterWindowSurface); // Not ready for painting yet, bail out. This can happen in // QWidget::create_sys() if (!d->image || rgn.rectCount() == 0) return; #ifdef Q_WS_WIN QRect br = rgn.boundingRect(); #ifndef Q_WS_WINCE if (!qt_widget_private(window())->isOpaque && window()->testAttribute(Qt::WA_TranslucentBackground) && (qt_widget_private(window())->data.window_flags & Qt::FramelessWindowHint)) { QRect r = window()->frameGeometry(); QPoint frameOffset = qt_widget_private(window())->frameStrut().topLeft(); QRect dirtyRect = br.translated(offset + frameOffset); SIZE size = {r.width(), r.height()}; POINT ptDst = {r.x(), r.y()}; POINT ptSrc = {0, 0}; BLENDFUNCTION blend = {AC_SRC_OVER, 0, (int)(255.0 * window()->windowOpacity()), Q_AC_SRC_ALPHA}; RECT dirty = {dirtyRect.x(), dirtyRect.y(), dirtyRect.x() + dirtyRect.width(), dirtyRect.y() + dirtyRect.height()}; Q_UPDATELAYEREDWINDOWINFO info = {sizeof(info), NULL, &ptDst, &size, d->image->hdc, &ptSrc, 0, &blend, Q_ULW_ALPHA, &dirty}; ptrUpdateLayeredWindowIndirect(window()->internalWinId(), &info); } else #endif { QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft(); HDC widget_dc = widget->getDC(); QRect wbr = br.translated(-wOffset); BitBlt(widget_dc, wbr.x(), wbr.y(), wbr.width(), wbr.height(), d->image->hdc, br.x() + offset.x(), br.y() + offset.y(), SRCCOPY); widget->releaseDC(widget_dc); } #ifndef QT_NO_DEBUG static bool flush = !qgetenv("QT_FLUSH_WINDOWSURFACE").isEmpty(); if (flush) { SelectObject(qt_win_display_dc(), GetStockObject(BLACK_BRUSH)); Rectangle(qt_win_display_dc(), 0, 0, d->image->width() + 2, d->image->height() + 2); BitBlt(qt_win_display_dc(), 1, 1, d->image->width(), d->image->height(), d->image->hdc, 0, 0, SRCCOPY); } #endif #endif #ifdef Q_WS_X11 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(); if (widget->window() != window()) { XFreeGC(X11->display, d_ptr->gc); d_ptr->gc = XCreateGC(X11->display, widget->handle(), 0, 0); } QRegion wrgn(rgn); if (!wOffset.isNull()) wrgn.translate(-wOffset); QRect wbr = wrgn.boundingRect(); if (wrgn.rectCount() != 1) { int num; XRectangle *rects = (XRectangle *)qt_getClipRects(wrgn, num); XSetClipRectangles(X11->display, d_ptr->gc, 0, 0, rects, num, YXBanded); } QRect br = rgn.boundingRect().translated(offset); #ifndef QT_NO_MITSHM if (d_ptr->image->xshmpm) { XCopyArea(X11->display, d_ptr->image->xshmpm, widget->handle(), d_ptr->gc, br.x(), br.y(), br.width(), br.height(), wbr.x(), wbr.y()); XSync(X11->display, False); } else if (d_ptr->image->xshmimg) { const QImage &src = d->image->image; br = br.intersected(src.rect()); XShmPutImage(X11->display, widget->handle(), d_ptr->gc, d_ptr->image->xshmimg, br.x(), br.y(), wbr.x(), wbr.y(), br.width(), br.height(), False); XSync(X11->display, False); } else #endif { const QImage &src = d->image->image; br = br.intersected(src.rect()); if (src.format() != QImage::Format_RGB32 || widget->x11Info().depth() < 24) { Q_ASSERT(src.depth() >= 16); const QImage sub_src(src.scanLine(br.y()) + br.x() * (uint(src.depth()) / 8), br.width(), br.height(), src.bytesPerLine(), src.format()); QX11PixmapData *data = new QX11PixmapData(QPixmapData::PixmapType); data->xinfo = widget->x11Info(); data->fromImage(sub_src, Qt::NoOpaqueDetection); QPixmap pm = QPixmap(data); XCopyArea(X11->display, pm.handle(), widget->handle(), d_ptr->gc, 0 , 0 , br.width(), br.height(), wbr.x(), wbr.y()); } else { // qpaintengine_x11.cpp extern void qt_x11_drawImage(const QRect &rect, const QPoint &pos, const QImage &image, Drawable hd, GC gc, Display *dpy, Visual *visual, int depth); qt_x11_drawImage(br, wbr.topLeft(), src, widget->handle(), d_ptr->gc, X11->display, (Visual *)widget->x11Info().visual(), widget->x11Info().depth()); } } if (wrgn.rectCount() != 1) XSetClipMask(X11->display, d_ptr->gc, XNone); #endif // FALCON #ifdef Q_WS_MAC // qDebug() << "Flushing" << widget << rgn << offset; // d->image->image.save("flush.png"); Q_UNUSED(offset); // Get a context for the widget. #ifndef QT_MAC_USE_COCOA CGContextRef context; CGrafPtr port = GetWindowPort(qt_mac_window_for(widget)); QDBeginCGContext(port, &context); #else extern CGContextRef qt_mac_graphicsContextFor(QWidget *); CGContextRef context = qt_mac_graphicsContextFor(widget); #endif CGContextSaveGState(context); // Flip context. CGContextTranslateCTM(context, 0, widget->height()); CGContextScaleCTM(context, 1, -1); // Clip to region. const QVector<QRect> &rects = rgn.rects(); for (int i = 0; i < rects.size(); ++i) { const QRect &rect = rects.at(i); CGContextAddRect(context, CGRectMake(rect.x(), rect.y(), rect.width(), rect.height())); } CGContextClip(context); QRect r = rgn.boundingRect(); const CGRect area = CGRectMake(r.x(), r.y(), r.width(), r.height()); CGImageRef image = CGBitmapContextCreateImage(d->image->cg); CGImageRef subImage = CGImageCreateWithImageInRect(image, area); qt_mac_drawCGImage(context, &area, subImage); CGImageRelease(subImage); CGImageRelease(image); // CGSize size = { d->image->image.width(), d->image->image.height() }; // CGLayerRef layer = CGLayerCreateWithContext(d->image->cg, size, 0); // CGPoint pt = { 0, 0 }; // CGContextDrawLayerAtPoint(context, pt, layer); // CGLayerRelease(layer); // Restore context. CGContextRestoreGState(context); #ifndef QT_MAC_USE_COCOA QDEndCGContext(port, &context); #endif #endif // Q_WS_MAC #ifdef Q_OS_SYMBIAN Q_UNUSED(widget); Q_UNUSED(rgn); Q_UNUSED(offset); #endif }
int UISymbolEdit (DBObjTable *symbols,int symbolType) { int symNum; static int changed, save; static Widget dShell = NULL; XmString string; UISymbol **editSymbols; DBObjRecord *symRecord; if (dShell == NULL) { char symString [20]; int depth; Pixel foreground, background; XGCValues xgcv; GC gc; Widget mainForm, scrolledW, list, label, button, text, foreMenu, backMenu, rowCol, symMenu; Pixmap markerPixmap, labelPixmap; dShell = UIDialogForm ((char *) "Symbol Edit"); mainForm = UIDialogFormGetMainForm (dShell); scrolledW = XtVaCreateManagedWidget ("UISymScrolledWindow",xmScrolledWindowWidgetClass,mainForm, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL); list = XtVaCreateManagedWidget (UISymListName + 1,xmListWidgetClass,scrolledW, XmNvisibleItemCount, 6, XmNselectionPolicy, XmBROWSE_SELECT, XmNscrollBarDisplayPolicy, XmSTATIC, NULL); XtAddCallback (list,XmNbrowseSelectionCallback,(XtCallbackProc) _UISymbolListSelectCBK,dShell); string = XmStringCreate ((char *) "Symbol",UICharSetNormal); label = XtVaCreateManagedWidget ("UISymbolLabel",xmLabelWidgetClass,mainForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, scrolledW, XmNleftAttachment, XmATTACH_FORM, XmNlabelString, string, NULL); XmStringFree (string); string = XmStringCreate ((char *) "Load Names",UICharSetNormal); button = XtVaCreateManagedWidget (UISymLoadNamesButtonName + 1,xmPushButtonWidgetClass,mainForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, label, XmNrightAttachment, XmATTACH_FORM, XmNlabelString, string, NULL); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _UISymbolLoadNamesCBK,list); XmStringFree (string); text = XtVaCreateManagedWidget (UISymTextFieldName + 1,xmTextFieldWidgetClass,mainForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, label, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, button, XmNrightOffset, 5, NULL); XtAddCallback (text,XmNvalueChangedCallback,(XtCallbackProc) _UISymbolTextValueChangedCBK,list); XtAddCallback (text,XmNvalueChangedCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&changed); foreMenu = XmCreatePulldownMenu (mainForm,(char *) "UISymForegroundMenuPane",NULL,0); backMenu = XmCreatePulldownMenu (mainForm,(char *) "UISymBackgroundMenuPane",NULL,0); for (symNum = 0;symNum < UIColorNum (UIColorStandard);symNum++) { foreground = UIColor (UIColorStandard,symNum); _UISymSetButtonString (symString,symNum); string = XmStringCreate (UIStandardColorName(symNum),UICharSetNormal); button = XtVaCreateManagedWidget (symString + 1,xmPushButtonWidgetClass,foreMenu, XmNuserData, symNum, XmNforeground, foreground, XmNlabelString, string, NULL); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _UISymbolSetForegroundCBK,text); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&changed); button = XtVaCreateManagedWidget (symString + 1,xmPushButtonWidgetClass,backMenu, XmNuserData, symNum, XmNforeground, foreground, XmNlabelString, string, NULL); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _UISymbolSetBackgroundCBK,text); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&changed); XmStringFree (string); } string = XmStringCreate ((char *) "Foreground:",UICharSetNormal); foreMenu = XtVaCreateManagedWidget (UISymForegroundMenuName + 1,xmRowColumnWidgetClass,mainForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, text, XmNrightAttachment, XmATTACH_FORM, XmNsubMenuId, foreMenu, XmNlabelString, string, XmNrowColumnType, XmMENU_OPTION, XmNtraversalOn, false, NULL); XmStringFree (string); string = XmStringCreate ((char *) "Background:",UICharSetNormal); backMenu = XtVaCreateManagedWidget (UISymBackgroundMenuName + 1,xmRowColumnWidgetClass,mainForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, foreMenu, XmNrightAttachment, XmATTACH_FORM, XmNsubMenuId, backMenu, XmNlabelString, string, XmNrowColumnType, XmMENU_OPTION, XmNtraversalOn, false, NULL); rowCol = XtVaCreateManagedWidget ("UISymbolRowCol",xmRowColumnWidgetClass,mainForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, backMenu, XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, NULL); XtVaGetValues (mainForm,XmNforeground, &foreground,XmNbackground, &background,NULL); xgcv.foreground = foreground; xgcv.background = background; xgcv.fill_style = FillTiled; gc = XCreateGC (XtDisplay (UITopLevel ()),XtWindow (UITopLevel ()),GCForeground | GCBackground | GCFillStyle,&xgcv); symMenu = XmCreatePulldownMenu (rowCol,(char *) "UISymShadeMenuPane",NULL,0); depth = DefaultDepth (XtDisplay (UITopLevel ()),DefaultScreen (XtDisplay (UITopLevel ()))); for (symNum = 0;(xgcv.tile = UIPattern (symNum,foreground,background)) != (Pixmap) NULL;symNum++) { labelPixmap = XCreatePixmap (XtDisplay (UITopLevel ()),XtWindow (UITopLevel ()),96,24,depth); XChangeGC (XtDisplay (UITopLevel ()),gc,GCTile,&xgcv); XFillRectangle (XtDisplay (UITopLevel ()),labelPixmap,gc,0,0,96,24); XFreePixmap (XtDisplay (UITopLevel ()),xgcv.tile); _UISymSetButtonString(symString,symNum); button = XtVaCreateManagedWidget (symString + 1,xmPushButtonGadgetClass,symMenu, XmNuserData, symNum, XmNlabelType, XmPIXMAP, XmNlabelPixmap, labelPixmap, NULL); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _UISymbolSetStyleCBK,text); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&changed); } string = XmStringCreate ((char *) "Shade:",UICharSetNormal); symMenu = XtVaCreateWidget (UISymShadeMenuName + 1,xmRowColumnWidgetClass,rowCol, XmNsubMenuId, symMenu, XmNlabelString, string, XmNrowColumnType, XmMENU_OPTION, XmNtraversalOn, false, NULL); XmStringFree (string); xgcv.foreground = background; xgcv.fill_style = FillSolid; XChangeGC (XtDisplay (UITopLevel ()),gc,GCForeground | GCFillStyle,&xgcv); symMenu = XmCreatePulldownMenu (rowCol,(char *) "UISymMarkerMenuPane",NULL,0); depth = DefaultDepth (XtDisplay (UITopLevel ()),DefaultScreen (XtDisplay (UITopLevel ()))); for (symNum = 0;(markerPixmap = UIMarker (symNum,foreground,background)) != (Pixmap) NULL;symNum++) { labelPixmap = XCreatePixmap (XtDisplay (UITopLevel ()),XtWindow (UITopLevel ()),96,24,depth); XFillRectangle (XtDisplay (UITopLevel ()),labelPixmap,gc,0,0,96,24); XCopyArea (XtDisplay (UITopLevel ()),markerPixmap,labelPixmap,gc,0,0,11,11,42,6); XFreePixmap (XtDisplay (UITopLevel ()),markerPixmap); _UISymSetButtonString(symString,symNum); button = XtVaCreateManagedWidget (symString + 1,xmPushButtonGadgetClass,symMenu, XmNuserData, symNum, XmNlabelType, XmPIXMAP, XmNlabelPixmap, labelPixmap, NULL); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _UISymbolSetStyleCBK,text); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&changed); } string = XmStringCreate ((char *) "Marker:",UICharSetNormal); symMenu = XtVaCreateWidget (UISymMarkerMenuName + 1,xmRowColumnWidgetClass,rowCol, XmNsubMenuId, symMenu, XmNlabelString, string, XmNrowColumnType, XmMENU_OPTION, XmNtraversalOn, false, NULL); XmStringFree (string); symMenu = XmCreatePulldownMenu (rowCol,(char *) "UISymLineMenuPane",NULL,0); depth = DefaultDepth (XtDisplay (UITopLevel ()),DefaultScreen (XtDisplay (UITopLevel ()))); for (symNum = 0;symNum < 12;symNum++) { labelPixmap = XCreatePixmap (XtDisplay (UITopLevel ()),XtWindow (UITopLevel ()),96,24,depth); xgcv.foreground = background; xgcv.fill_style = FillSolid; XChangeGC (XtDisplay (UITopLevel ()),gc,GCForeground | GCFillStyle,&xgcv); XFillRectangle (XtDisplay (UITopLevel ()),labelPixmap,gc,0,0,96,24); xgcv.line_width = symNum & 0x03; switch (symNum >> 0x02) { case 0: xgcv.line_style = LineSolid; break; case 1: xgcv.line_style = LineOnOffDash; break; case 2: xgcv.line_style = LineDoubleDash; break; } xgcv.foreground = foreground; xgcv.background = UIColor (UIColorStandard,0); XChangeGC (XtDisplay (UITopLevel ()),gc,GCForeground | GCBackground | GCLineWidth | GCLineStyle,&xgcv); XDrawLine (XtDisplay (UITopLevel ()),labelPixmap,gc,0,12,96,12); _UISymSetButtonString(symString,symNum); button = XtVaCreateManagedWidget (symString + 1,xmPushButtonGadgetClass,symMenu, XmNuserData, symNum, XmNlabelType, XmPIXMAP, XmNlabelPixmap, labelPixmap, NULL); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _UISymbolSetStyleCBK,text); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&changed); } string = XmStringCreate ((char *) "Line:",UICharSetNormal); symMenu = XtVaCreateWidget (UISymLineMenuName + 1,xmRowColumnWidgetClass,rowCol, XmNsubMenuId, symMenu, XmNlabelString, string, XmNrowColumnType, XmMENU_OPTION, XmNtraversalOn, false, NULL); XmStringFree (string); XtAddCallback (UIDialogFormGetOkButton (dShell),XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&save); }
void Clear() { XFillRectangle(dpy, pixmap, Data_GC[0], 0, 0, width, height); XCopyArea(dpy, pixmap, canvas, Data_GC[0], 0, 0, width, height, 0, 0); }
void draw_marquee(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); char *space = (char *) " "; unsigned char *ch; marqueestruct *mp = &marquees[MI_SCREEN(mi)]; if (marquees == NULL) return; mp = &marquees[MI_SCREEN(mi)]; if (mp->gc == None && mode_font != None) return; MI_IS_DRAWN(mi) = True; ch = (unsigned char*) mp->words; if (isRibbon()) { ch = (unsigned char*) mp->words; switch (*ch) { case '\0': if (add_blanks(mp)) { init_marquee(mi); return; } break; case '\b': case '\r': case '\n': case '\t': case '\v': case '\f': add_letter(mp, " "); mp->words++; break; default: add_letter(mp, (char *) ch); mp->words++; } if (MI_NPIXELS(mi) > 2) { XSetForeground(display, mp->gc, MI_PIXEL(mi, mp->color)); if (++mp->color == MI_NPIXELS(mi)) mp->color = 0; } else XSetForeground(display, mp->gc, MI_WHITE_PIXEL(mi)); (void) XDrawImageString(display, MI_WINDOW(mi), mp->gc, mp->x, mp->y + mp->ascent, mp->modwords, mp->t + 2); } else { switch (*ch) { case '\0': if (++mp->time > 16) init_marquee(mi); return; case '\b': if (mp->t) { /* see note in text_font_width */ mp->t--; mp->x -= char_width[(int) (' ')]; } break; case '\v': case '\f': case '\n': mp->x = mp->startx; mp->t = 0; mp->y += mp->height; if (mp->y + mp->height > mp->win_height) { XCopyArea(display, window, window, mp->gc, 0, mp->height, mp->win_width, mp->y - mp->height, 0, 0); XSetForeground(display, mp->gc, MI_BLACK_PIXEL(mi)); mp->y -= mp->height; XFillRectangle(display, window, mp->gc, 0, mp->y, mp->win_width, mp->height); } break; case '\t': (void) XDrawString(display, window, mp->gc, mp->x, mp->y + mp->ascent, space, 8 - (mp->t % 8)); mp->x += char_width[(int) (' ')] * (8 - (mp->t % 8)); mp->t = ((mp->t + 8) / 8) * 8; break; case '\r': break; default: if (MI_NPIXELS(mi) > 2) { XSetForeground(display, mp->gc, MI_PIXEL(mi, mp->color)); if (++mp->color == MI_NPIXELS(mi)) mp->color = 0; } else XSetForeground(display, mp->gc, MI_WHITE_PIXEL(mi)); if (is_char_back_char((char *) ch)) { int xmid = mp->x + (char_back_char_width((char *) ch) + 1) / 2; (void) XDrawString(display, window, mp->gc, xmid - char_width[(int) (const char) *ch] / 2, mp->y + mp->ascent, (char *) ch, 1); (void) XDrawString(display, window, mp->gc, xmid - char_width[(int) (const char) *(ch + 2)] / 2, mp->y + mp->ascent, (char *) ch + 2, 1); mp->x += char_back_char_width((char *) ch); mp->words += 2; } else { int mb = charBytes(*ch); (void) XDrawString(display, window, mp->gc, mp->x, mp->y + mp->ascent, (char *) ch, mb); mp->x += charWidth((char *) ch); } mp->t++; } mp->words += charBytes(*ch); } }
/* EXTPROTO */ int rxvt_scrollbar_show_next(rxvt_t *r, int update, int last_top, int last_bot, int scroller_len) { int height; Drawable s; int page = ATAB(r); height = r->scrollBar.end + NEXT_SB_TBTN_HEIGHT + NEXT_SB_PAD; if (PVTS(r, page)->nscrolled == 0 || !update) { XClearArea (r->Xdisplay, r->scrollBar.win, 0, 0, SB_WIDTH_NEXT + 1, height, False); CHOOSE_GC_FG(r, r->scrollBar.next_fg); XDrawRectangle(r->Xdisplay, r->scrollBar.win, r->scrollBar.gc, 0, NEXT_SB_BD_WIDTH, SB_WIDTH_NEXT, height + NEXT_SB_BD_WIDTH); # ifdef TRANSPARENT /* set background color when there's no transparent */ if (!((r->Options & Opt_transparent) && (r->Options & Opt_transparent_scrollbar))) # endif #ifdef BACKGROUND_IMAGE /* set background color when there's no bg image */ if (None == r->scrollBar.pixmap) #endif XFillRectangle(r->Xdisplay, r->scrollBar.win, TILEGC, NEXT_SB_LPAD, 0, NEXT_SB_BTN_WIDTH, height); } if (PVTS(r, page)->nscrolled) { if (last_top < r->scrollBar.top || !update) { /* ** Area above the scroller */ # ifdef TRANSPARENT /* clear background when there's transparent */ if ((r->Options & Opt_transparent) && (r->Options & Opt_transparent_scrollbar)) XClearArea (r->Xdisplay, r->scrollBar.win, NEXT_SB_LPAD, NEXT_SB_PAD + last_top, NEXT_SB_BTN_WIDTH, r->scrollBar.top - last_top, False); else # endif # ifdef BACKGROUND_IMAGE /* clear background when there's bg image */ if (None != r->scrollBar.pixmap) XClearArea (r->Xdisplay, r->scrollBar.win, NEXT_SB_LPAD, NEXT_SB_PAD + last_top, NEXT_SB_BTN_WIDTH, r->scrollBar.top - last_top, False); else # endif XFillRectangle(r->Xdisplay, r->scrollBar.win, TILEGC, NEXT_SB_LPAD, NEXT_SB_PAD + last_top, NEXT_SB_BTN_WIDTH, r->scrollBar.top - last_top); } if (r->scrollBar.bot < last_bot || !update) { /* ** Area above the buttons but below the scroller */ # ifdef TRANSPARENT /* clear background when there's transparent */ if ((r->Options & Opt_transparent) && (r->Options & Opt_transparent_scrollbar)) XClearArea(r->Xdisplay, r->scrollBar.win, NEXT_SB_LPAD, r->scrollBar.bot + NEXT_SB_PAD, NEXT_SB_BTN_WIDTH, (last_bot - r->scrollBar.bot), False); else # endif # ifdef BACKGROUND_IMAGE /* clear background when there's bg image */ if (None != r->scrollBar.pixmap) XClearArea (r->Xdisplay, r->scrollBar.win, NEXT_SB_LPAD, r->scrollBar.bot + NEXT_SB_PAD, NEXT_SB_BTN_WIDTH, (last_bot - r->scrollBar.bot), False); else # endif XFillRectangle(r->Xdisplay, r->scrollBar.win, TILEGC, NEXT_SB_LPAD, r->scrollBar.bot + NEXT_SB_PAD, NEXT_SB_BTN_WIDTH, (last_bot - r->scrollBar.bot)); } /* ** Area of the scroller */ # ifdef TRANSPARENT /* clear background when there's transparent */ if ((r->Options & Opt_transparent) && (r->Options & Opt_transparent_scrollbar)) XClearArea (r->Xdisplay, r->scrollBar.win, NEXT_SB_LPAD, r->scrollBar.top + NEXT_SB_PAD, NEXT_SB_BTN_WIDTH, scroller_len/*-NEXT_SB_BTN_HEIGHT*/, False); else # endif # ifdef BACKGROUND_IMAGE /* clear background when there's bg image */ if (None != r->scrollBar.pixmap) XClearArea (r->Xdisplay, r->scrollBar.win, NEXT_SB_LPAD, r->scrollBar.top + NEXT_SB_PAD, NEXT_SB_BTN_WIDTH, scroller_len/*-NEXT_SB_BTN_HEIGHT*/, False); else # endif { CHOOSE_GC_FG(r, r->scrollBar.next_bg); XFillRectangle(r->Xdisplay, r->scrollBar.win, r->scrollBar.gc, NEXT_SB_LPAD, r->scrollBar.top + NEXT_SB_PAD, NEXT_SB_BTN_WIDTH, scroller_len/*-NEXT_SB_BTN_HEIGHT*/); } /* ** Here comes the dimple in the scroller */ CHOOSE_GC_FG(r, r->scrollBar.next_white); XCopyArea(r->Xdisplay, DIMPLE, r->scrollBar.win, r->scrollBar.gc, 0, 0, DIMPLE_WIDTH, DIMPLE_HEIGHT, (SB_WIDTH_NEXT - DIMPLE_WIDTH) / 2, r->scrollBar.top + NEXT_BEVEL_ULEFT_WIDTH + (scroller_len - DIMPLE_HEIGHT) / 2); /* ** Bevel around the scroller */ next_draw_bevel(r, r->scrollBar.win, NEXT_BEVEL_X, r->scrollBar.top + NEXT_SB_PAD, NEXT_SB_BTN_WIDTH, scroller_len); /* ** Bevel around the buttons */ next_draw_bevel(r, r->scrollBar.win, NEXT_BEVEL_X, height - NEXT_SB_DBTN_HEIGHT, NEXT_SB_BTN_WIDTH, NEXT_SB_BTN_HEIGHT); next_draw_bevel(r, r->scrollBar.win, NEXT_BEVEL_X, height - NEXT_SB_SBTN_HEIGHT, NEXT_SB_BTN_WIDTH, NEXT_SB_BTN_HEIGHT); /* ** Top button */ CHOOSE_GC_FG(r, r->scrollBar.next_white); s = (scrollbar_isUp()) ? HIUPARROW : UPARROW; XCopyArea(r->Xdisplay, s, r->scrollBar.win, r->scrollBar.gc, 0, 0, ARROW_WIDTH, ARROW_HEIGHT, NEXT_BTN_FACE_X, height-NEXT_SB_DBTN_HEIGHT+NEXT_BEVEL_ULEFT_WIDTH); /* ** Bottom button */ s = (scrollbar_isDn()) ? HIDNARROW : DNARROW; XCopyArea(r->Xdisplay, s, r->scrollBar.win, r->scrollBar.gc, 0, 0, ARROW_WIDTH, ARROW_HEIGHT, NEXT_BTN_FACE_X, height-NEXT_SB_SBTN_HEIGHT+NEXT_BEVEL_ULEFT_WIDTH); } return 1; }
/* Main method runs initialize() and update() */ int main(int argc, char **argv) { /* get num bodies from the command line */ int num_bodies; num_bodies = (argc == 2) ? atoi(argv[1]) : DEF_NUM_BODIES; printf("Universe has %d bodies.\n", num_bodies); /* set up the universe */ time_t cur_time; time(&cur_time); srand48((long)cur_time); // seed the RNG used in create_world struct world *world = create_world(num_bodies); /* set up graphics using Xlib */ Display *disp = XOpenDisplay(NULL); int scr = DefaultScreen(disp); Window win = XCreateSimpleWindow( disp, RootWindow(disp, scr), 0, 0, WIDTH, HEIGHT, 0, BlackPixel(disp, scr), WhitePixel(disp, scr)); XStoreName(disp, win, "N-Body Simulator"); Pixmap back_buf = XCreatePixmap(disp, RootWindow(disp, scr), WIDTH, HEIGHT, DefaultDepth(disp, scr)); GC gc = XCreateGC(disp, back_buf, 0, 0); // Make sure we're only looking for messages about closing the window Atom del_window = XInternAtom(disp, "WM_DELETE_WINDOW", 0); XSetWMProtocols(disp, win, &del_window, 1); XSelectInput(disp, win, StructureNotifyMask); XMapWindow(disp, win); XEvent event; // wait until window is mapped while (1) { XNextEvent(disp, &event); if (event.type == MapNotify) { break; } } struct timespec delay={0, 1000000000 / 60}; // for 60 FPS struct timespec remaining; int frame_num = 0; while (1) { // check if the window has been closed if (XCheckTypedEvent(disp, ClientMessage, &event)) { break; } // we first draw to the back buffer then copy it to the front (`win`) draw_world(disp, back_buf, gc, world); XCopyArea(disp, back_buf, win, gc, 0, 0, WIDTH, HEIGHT, 0, 0); step_world(world, 0.1); frame_num++; nanosleep(&delay, &remaining); } XFreeGC(disp, gc); XFreePixmap(disp, back_buf); XDestroyWindow(disp, win); XCloseDisplay(disp); return 0; }
static unsigned long whirlygig_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; int wcount; /* wcount is a counter incremented for every whirly take note of internal_time before you mess with it */ int change_time = 4000; if (st->explaining == 1) { XClearWindow (st->dpy, st->window); draw_explain_string(st, st->xmode, st->info->half_height-100, st->dpy, st->window, st->fgc); st->explaining++; return 3000000; } else if (st->explaining == 2) { XClearWindow (st->dpy, st->window); st->explaining = 0; } if (! strcmp (st->xmode_str, "change") && ! strcmp (st->ymode_str, "change")) { if ((st->current_time - st->start_time) > change_time) { st->start_time = st->current_time; st->xmode = 1 + (random() % 4); st->ymode = 1 + (random() % 4); } } else if (! strcmp (st->xmode_str, "change")) { if ((st->current_time - st->start_time) > change_time) { st->start_time = st->current_time; st->xmode = 1 + (random() % 4); } } else if (! strcmp (st->ymode_str, "change")) { if ((st->current_time - st->start_time) > change_time) { st->start_time = st->current_time; st->ymode = 1 + (random() % 3); printf("Changing ymode to %d\n", st->ymode); } } if (++st->current_color >= NCOLORS) st->current_color = 0; for (wcount = 0; wcount < st->info->whirlies; wcount++) { int lcount; /* lcount is a counter for every line -- take note of the offsets changing */ int internal_time = st->current_time; int color_offset = (st->current_color + (st->info->color_modifier * wcount)) % NCOLORS; if (st->current_time == 0) internal_time = 0; else /* I want the distance between whirlies to increase more each whirly */ internal_time = st->current_time + (10 * wcount) + (wcount * wcount); switch (st->xmode) { /* All these functions expect an int time, the struct info, a pointer to an array of positions, and the index that the the function will fill of the array */ case spin_mode: spin(st, internal_time, st->info, st->pos, 0); break; case funky_mode: funky(st, internal_time, st->info, st->pos, 0); break; case circle_mode: circle(st, internal_time, st->info, st->pos, 0); break; case linear_mode: linear(st, internal_time, st->info, st->pos, 0); break; case fun_mode: fun(st, internal_time, st->info, st->pos, 0); break; case test_mode: test(st, internal_time, st->info, st->pos, 0); break; case innie_mode: innie(st, internal_time, st->info, st->pos, 0, st->modifier); break; case lissajous_mode: lissajous(st, internal_time, st->info, st->pos, 0); break; default: spin(st, internal_time, st->info, st->pos, 0); break; } /* End of the switch for the x position*/ switch (st->ymode) { case spin_mode: spin(st, internal_time, st->info, st->pos, 1); break; case funky_mode: funky(st, internal_time, st->info, st->pos, 1); break; case circle_mode: circle(st, internal_time, st->info, st->pos, 1); break; case linear_mode: linear(st, internal_time, st->info, st->pos, 1); break; case fun_mode: fun(st, internal_time, st->info, st->pos, 1); break; case test_mode: test(st, internal_time, st->info, st->pos, 1); break; case innie_mode: innie(st, internal_time, st->info, st->pos, 1, st->modifier); break; case lissajous_mode: lissajous(st, internal_time, st->info, st->pos, 1); break; default: spin(st, internal_time, st->info, st->pos, 1); break; } /* End of the switch for the y position*/ for (lcount = 0; lcount < st->info->nlines; lcount++) { double arg = (double)((internal_time * st->info->offset_period) / 90.0); double line_offset = 20.0 * (double)lcount * sin(arg); int size; size = (int)(15.0 + 5.0 * sin((double)internal_time / 180.0)); /* First delete the old circle... */ if (!st->info->trail #ifdef HAVE_DOUBLE_BUFFER_EXTENSION && ( !st->dbeclear_p || !st->backb) #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ ) { XSetForeground(st->dpy, st->bgc, BlackPixel(st->dpy, st->screen)); XFillArc(st->dpy, st->b, st->bgc, st->last_x[wcount][lcount], st->last_y[wcount][lcount], st->last_size[wcount][lcount], st->last_size[wcount][lcount], START_ARC, END_ARC); } /* Now, lets draw in the new circle */ { /* Starting new scope for local x_pos and y_pos */ int xpos, ypos; if (st->wrap) { xpos = preen((int)(st->info->xoffset*line_offset)+st->pos[0], st->info->half_width * 2); ypos = preen((int)(st->info->yoffset*line_offset)+st->pos[1], st->info->half_height * 2); } else { xpos = (int)(st->info->xoffset*line_offset)+st->pos[0]; ypos = (int)(st->info->yoffset*line_offset)+st->pos[1]; } if (st->start_time == st->current_time) { /* smoothen should move from one mode to another prettily... */ /* Note: smoothen has not been modified to take the double buffering code into account, and needs to be hacked on before uncommenting. */ /* smoothen(xpos, last_x[wcount][lcount], ypos, last_y[wcount][lcount], size, color_offset, colors, dpy, window, bgc, screen, info); */ } st->last_x[wcount][lcount] = xpos; st->last_y[wcount][lcount] = ypos; st->last_size[wcount][lcount] = size; XSetForeground(st->dpy, st->bgc, st->colors[color_offset].pixel); XFillArc(st->dpy, st->b, st->bgc, xpos, ypos, size, size, START_ARC, END_ARC); } /* End of my temporary scope for xpos and ypos */ } /* End of the for each line in nlines */ } /* End of the for each whirly in whirlies */ #ifdef HAVE_DOUBLE_BUFFER_EXTENSION if (st->backb) { XdbeSwapInfo info[1]; info[0].swap_window = st->window; info[0].swap_action = (st->dbeclear_p ? XdbeBackground : XdbeUndefined); XdbeSwapBuffers (st->dpy, info, 1); } else #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ if (st->dbuf) { XCopyArea (st->dpy, st->b, st->window, st->bgc, 0, 0, st->xgwa.width, st->xgwa.height, 0, 0); } if (st->current_time == FULL_CYCLE) st->current_time = 1; else st->current_time = st->current_time + st->info->speed; return 10000; }
void xf_sw_end_paint(rdpContext* context) { rdpGdi* gdi; xfInfo* xfi; sint32 x, y; uint32 w, h; xfi = ((xfContext*) context)->xfi; gdi = context->gdi; if (xfi->remote_app != true) { if (xfi->complex_regions != true) { if (gdi->primary->hdc->hwnd->invalid->null) return; x = gdi->primary->hdc->hwnd->invalid->x; y = gdi->primary->hdc->hwnd->invalid->y; w = gdi->primary->hdc->hwnd->invalid->w; h = gdi->primary->hdc->hwnd->invalid->h; XPutImage(xfi->display, xfi->primary, xfi->gc, xfi->image, x, y, x, y, w, h); XCopyArea(xfi->display, xfi->primary, xfi->window->handle, xfi->gc, x, y, w, h, x, y); } else { int i; int ninvalid; HGDI_RGN cinvalid; if (gdi->primary->hdc->hwnd->ninvalid < 1) return; ninvalid = gdi->primary->hdc->hwnd->ninvalid; cinvalid = gdi->primary->hdc->hwnd->cinvalid; for (i = 0; i < ninvalid; i++) { x = cinvalid[i].x; y = cinvalid[i].y; w = cinvalid[i].w; h = cinvalid[i].h; XPutImage(xfi->display, xfi->primary, xfi->gc, xfi->image, x, y, x, y, w, h); XCopyArea(xfi->display, xfi->primary, xfi->window->handle, xfi->gc, x, y, w, h, x, y); } XFlush(xfi->display); } } else { if (gdi->primary->hdc->hwnd->invalid->null) return; x = gdi->primary->hdc->hwnd->invalid->x; y = gdi->primary->hdc->hwnd->invalid->y; w = gdi->primary->hdc->hwnd->invalid->w; h = gdi->primary->hdc->hwnd->invalid->h; xf_rail_paint(xfi, context->rail, x, y, x + w - 1, y + h - 1); } }
void TkpDisplayMenuButton( ClientData clientData) /* Information about widget. */ { register TkMenuButton *mbPtr = (TkMenuButton *) clientData; GC gc; Tk_3DBorder border; Pixmap pixmap; int x = 0; /* Initialization needed only to stop compiler * warning. */ int y = 0; register Tk_Window tkwin = mbPtr->tkwin; int fullWidth, fullHeight; int textXOffset, textYOffset; int imageWidth, imageHeight; int imageXOffset, imageYOffset; int width = 0, height = 0; /* Image information that will be used to * restrict disabled pixmap as well */ int haveImage = 0, haveText = 0; mbPtr->flags &= ~REDRAW_PENDING; if ((mbPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { return; } if ((mbPtr->state == STATE_DISABLED) && (mbPtr->disabledFg != NULL)) { gc = mbPtr->disabledGC; border = mbPtr->normalBorder; } else if ((mbPtr->state == STATE_ACTIVE) && !Tk_StrictMotif(mbPtr->tkwin)) { gc = mbPtr->activeTextGC; border = mbPtr->activeBorder; } else { gc = mbPtr->normalTextGC; border = mbPtr->normalBorder; } if (mbPtr->image != None) { Tk_SizeOfImage(mbPtr->image, &width, &height); haveImage = 1; } else if (mbPtr->bitmap != None) { Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height); haveImage = 1; } imageWidth = width; imageHeight = height; haveText = (mbPtr->textWidth != 0 && mbPtr->textHeight != 0); /* * In order to avoid screen flashes, this function redraws the menu button * in a pixmap, then copies the pixmap to the screen in a single * operation. This means that there's no point in time where the on-sreen * image has been cleared. */ pixmap = Tk_GetPixmap(mbPtr->display, Tk_WindowId(tkwin), Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); Tk_Fill3DRectangle(tkwin, pixmap, border, 0, 0, Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT); imageXOffset = 0; imageYOffset = 0; textXOffset = 0; textYOffset = 0; fullWidth = 0; fullHeight = 0; if (mbPtr->compound != COMPOUND_NONE && haveImage && haveText) { switch ((enum compound) mbPtr->compound) { case COMPOUND_TOP: case COMPOUND_BOTTOM: /* * Image is above or below text. */ if (mbPtr->compound == COMPOUND_TOP) { textYOffset = height + mbPtr->padY; } else { imageYOffset = mbPtr->textHeight + mbPtr->padY; } fullHeight = height + mbPtr->textHeight + mbPtr->padY; fullWidth = (width > mbPtr->textWidth ? width : mbPtr->textWidth); textXOffset = (fullWidth - mbPtr->textWidth)/2; imageXOffset = (fullWidth - width)/2; break; case COMPOUND_LEFT: case COMPOUND_RIGHT: /* * Image is left or right of text. */ if (mbPtr->compound == COMPOUND_LEFT) { textXOffset = width + mbPtr->padX; } else { imageXOffset = mbPtr->textWidth + mbPtr->padX; } fullWidth = mbPtr->textWidth + mbPtr->padX + width; fullHeight = (height > mbPtr->textHeight ? height : mbPtr->textHeight); textYOffset = (fullHeight - mbPtr->textHeight)/2; imageYOffset = (fullHeight - height)/2; break; case COMPOUND_CENTER: /* * Image and text are superimposed. */ fullWidth = (width > mbPtr->textWidth ? width : mbPtr->textWidth); fullHeight = (height > mbPtr->textHeight ? height : mbPtr->textHeight); textXOffset = (fullWidth - mbPtr->textWidth)/2; imageXOffset = (fullWidth - width)/2; textYOffset = (fullHeight - mbPtr->textHeight)/2; imageYOffset = (fullHeight - height)/2; break; case COMPOUND_NONE: break; } TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0, mbPtr->indicatorWidth + fullWidth, fullHeight, &x, &y); imageXOffset += x; imageYOffset += y; if (mbPtr->image != NULL) { Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap, imageXOffset, imageYOffset); } else if (mbPtr->bitmap != None) { XSetClipOrigin(mbPtr->display, gc, imageXOffset, imageYOffset); XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap, gc, 0, 0, (unsigned) width, (unsigned) height, imageXOffset, imageYOffset, 1); XSetClipOrigin(mbPtr->display, gc, 0, 0); } Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, x + textXOffset, y + textYOffset, 0, -1); Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, x + textXOffset, y + textYOffset, mbPtr->underline); } else if (haveImage) { TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0, width + mbPtr->indicatorWidth, height, &x, &y); imageXOffset += x; imageYOffset += y; if (mbPtr->image != NULL) { Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap, imageXOffset, imageYOffset); } else if (mbPtr->bitmap != None) { XSetClipOrigin(mbPtr->display, gc, x, y); XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap, gc, 0, 0, (unsigned) width, (unsigned) height, x, y, 1); XSetClipOrigin(mbPtr->display, gc, 0, 0); } } else { TkComputeAnchor(mbPtr->anchor, tkwin, mbPtr->padX, mbPtr->padY, mbPtr->textWidth + mbPtr->indicatorWidth, mbPtr->textHeight, &x, &y); Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, x + textXOffset, y + textYOffset, 0, -1); Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, x + textXOffset, y + textYOffset, mbPtr->underline); } /* * If the menu button is disabled with a stipple rather than a special * foreground color, generate the stippled effect. */ if ((mbPtr->state == STATE_DISABLED) && ((mbPtr->disabledFg == NULL) || (mbPtr->image != NULL))) { /* * Stipple the whole button if no disabledFg was specified, otherwise * restrict stippling only to displayed image */ if (mbPtr->disabledFg == NULL) { XFillRectangle(mbPtr->display, pixmap, mbPtr->stippleGC, mbPtr->inset, mbPtr->inset, (unsigned) (Tk_Width(tkwin) - 2*mbPtr->inset), (unsigned) (Tk_Height(tkwin) - 2*mbPtr->inset)); } else { XFillRectangle(mbPtr->display, pixmap, mbPtr->stippleGC, imageXOffset, imageYOffset, (unsigned) imageWidth, (unsigned) imageHeight); } } /* * Draw the cascade indicator for the menu button on the right side of the * window, if desired. */ if (mbPtr->indicatorOn) { int borderWidth; borderWidth = (mbPtr->indicatorHeight+1)/3; if (borderWidth < 1) { borderWidth = 1; } /*y += mbPtr->textHeight / 2;*/ Tk_Fill3DRectangle(tkwin, pixmap, border, Tk_Width(tkwin) - mbPtr->inset - mbPtr->indicatorWidth + mbPtr->indicatorHeight, ((int) (Tk_Height(tkwin) - mbPtr->indicatorHeight))/2, mbPtr->indicatorWidth - 2*mbPtr->indicatorHeight, mbPtr->indicatorHeight, borderWidth, TK_RELIEF_RAISED); } /* * Draw the border and traversal highlight last. This way, if the menu * button's contents overflow onto the border they'll be covered up by the * border. */ if (mbPtr->relief != TK_RELIEF_FLAT) { Tk_Draw3DRectangle(tkwin, pixmap, border, mbPtr->highlightWidth, mbPtr->highlightWidth, Tk_Width(tkwin) - 2*mbPtr->highlightWidth, Tk_Height(tkwin) - 2*mbPtr->highlightWidth, mbPtr->borderWidth, mbPtr->relief); } if (mbPtr->highlightWidth != 0) { GC gc; if (mbPtr->flags & GOT_FOCUS) { gc = Tk_GCForColor(mbPtr->highlightColorPtr, pixmap); } else { gc = Tk_GCForColor(mbPtr->highlightBgColorPtr, pixmap); } Tk_DrawFocusHighlight(tkwin, gc, mbPtr->highlightWidth, pixmap); } /* * Copy the information from the off-screen pixmap onto the screen, then * delete the pixmap. */ XCopyArea(mbPtr->display, pixmap, Tk_WindowId(tkwin), mbPtr->normalTextGC, 0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin), 0, 0); Tk_FreePixmap(mbPtr->display, pixmap); }
void GraphicWindow::repaint() { XCopyArea(display, _ppm, win, xgc, 0, 0, DEF_WIDTH, DEF_HEIGHT, 0, 0); }
static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * dstrect) { X11_RenderData *data = (X11_RenderData *) renderer->driverdata; X11_TextureData *texturedata = (X11_TextureData *) texture->driverdata; if (data->makedirty) { SDL_AddDirtyRect(&data->dirty, dstrect); } if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) { #ifndef NO_SHARED_MEMORY if (texturedata->shminfo.shmaddr) { XShmPutImage(data->display, data->drawable, data->gc, texturedata->image, srcrect->x, srcrect->y, dstrect->x, dstrect->y, srcrect->w, srcrect->h, False); } else #endif if (texturedata->pixels) { XPutImage(data->display, data->drawable, data->gc, texturedata->image, srcrect->x, srcrect->y, dstrect->x, dstrect->y, srcrect->w, srcrect->h); } else { XCopyArea(data->display, texturedata->pixmap, data->drawable, data->gc, srcrect->x, srcrect->y, dstrect->w, dstrect->h, dstrect->x, dstrect->y); } } else if (texturedata->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) { SDL_Surface src, dst; SDL_PixelFormat fmt; SDL_Rect rect; XImage *image = texturedata->scaling_image; if (!image) { int depth; void *pixels; int pitch; pitch = dstrect->w * SDL_BYTESPERPIXEL(texturedata->format); pixels = SDL_malloc(dstrect->h * pitch); if (!pixels) { SDL_OutOfMemory(); return -1; } image = XCreateImage(data->display, data->visual, data->depth, ZPixmap, 0, pixels, dstrect->w, dstrect->h, SDL_BYTESPERPIXEL(texturedata->format) * 8, pitch); if (!image) { SDL_SetError("XCreateImage() failed"); return -1; } texturedata->scaling_image = image; } else if (image->width != dstrect->w || image->height != dstrect->h || !image->data) { image->width = dstrect->w; image->height = dstrect->h; image->bytes_per_line = image->width * SDL_BYTESPERPIXEL(texturedata->format); image->data = (char *) SDL_realloc(image->data, image->height * image->bytes_per_line); if (!image->data) { SDL_OutOfMemory(); return -1; } } /* Set up fake surfaces for SDL_SoftStretch() */ SDL_zero(src); src.format = &fmt; src.w = texture->w; src.h = texture->h; #ifndef NO_SHARED_MEMORY if (texturedata->shminfo.shmaddr) { src.pixels = texturedata->shminfo.shmaddr; } else #endif src.pixels = texturedata->pixels; src.pitch = texturedata->pitch; SDL_zero(dst); dst.format = &fmt; dst.w = image->width; dst.h = image->height; dst.pixels = image->data; dst.pitch = image->bytes_per_line; fmt.BytesPerPixel = SDL_BYTESPERPIXEL(texturedata->format); rect.x = 0; rect.y = 0; rect.w = dstrect->w; rect.h = dstrect->h; if (SDL_SoftStretch(&src, srcrect, &dst, &rect) < 0) { return -1; } XPutImage(data->display, data->drawable, data->gc, image, 0, 0, dstrect->x, dstrect->y, dstrect->w, dstrect->h); } else { XCopyArea(data->display, texturedata->pixmap, data->drawable, data->gc, srcrect->x, srcrect->y, dstrect->w, dstrect->h, srcrect->x, srcrect->y); } return 0; }
void TkpDisplayScale( ClientData clientData) /* Widget record for scale. */ { TkScale *scalePtr = (TkScale *) clientData; Tk_Window tkwin = scalePtr->tkwin; Tcl_Interp *interp = scalePtr->interp; Pixmap pixmap; int result; char string[TCL_DOUBLE_SPACE]; XRectangle drawnArea; Tcl_DString buf; scalePtr->flags &= ~REDRAW_PENDING; if ((scalePtr->tkwin == NULL) || !Tk_IsMapped(scalePtr->tkwin)) { goto done; } /* * Invoke the scale's command if needed. */ Tcl_Preserve(scalePtr); if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) { Tcl_Preserve(interp); sprintf(string, scalePtr->format, scalePtr->value); Tcl_DStringInit(&buf); Tcl_DStringAppend(&buf, scalePtr->command, -1); Tcl_DStringAppend(&buf, " ", -1); Tcl_DStringAppend(&buf, string, -1); result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0); Tcl_DStringFree(&buf); if (result != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (command executed by scale)"); Tcl_BackgroundException(interp, result); } Tcl_Release(interp); } scalePtr->flags &= ~INVOKE_COMMAND; if (scalePtr->flags & SCALE_DELETED) { Tcl_Release(scalePtr); return; } Tcl_Release(scalePtr); #ifndef TK_NO_DOUBLE_BUFFERING /* * In order to avoid screen flashes, this function redraws the scale in a * pixmap, then copies the pixmap to the screen in a single operation. * This means that there's no point in time where the on-sreen image has * been cleared. */ pixmap = Tk_GetPixmap(scalePtr->display, Tk_WindowId(tkwin), Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); #else pixmap = Tk_WindowId(tkwin); #endif /* TK_NO_DOUBLE_BUFFERING */ drawnArea.x = 0; drawnArea.y = 0; drawnArea.width = Tk_Width(tkwin); drawnArea.height = Tk_Height(tkwin); /* * Much of the redisplay is done totally differently for horizontal and * vertical scales. Handle the part that's different. */ if (scalePtr->orient == ORIENT_VERTICAL) { DisplayVerticalScale(scalePtr, pixmap, &drawnArea); } else { DisplayHorizontalScale(scalePtr, pixmap, &drawnArea); } /* * Now handle the part of redisplay that is the same for horizontal and * vertical scales: border and traversal highlight. */ if (scalePtr->flags & REDRAW_OTHER) { if (scalePtr->relief != TK_RELIEF_FLAT) { Tk_Draw3DRectangle(tkwin, pixmap, scalePtr->bgBorder, scalePtr->highlightWidth, scalePtr->highlightWidth, Tk_Width(tkwin) - 2*scalePtr->highlightWidth, Tk_Height(tkwin) - 2*scalePtr->highlightWidth, scalePtr->borderWidth, scalePtr->relief); } if (scalePtr->highlightWidth != 0) { GC gc; if (scalePtr->flags & GOT_FOCUS) { gc = Tk_GCForColor(scalePtr->highlightColorPtr, pixmap); } else { gc = Tk_GCForColor( Tk_3DBorderColor(scalePtr->highlightBorder), pixmap); } Tk_DrawFocusHighlight(tkwin, gc, scalePtr->highlightWidth, pixmap); } } #ifndef TK_NO_DOUBLE_BUFFERING /* * Copy the information from the off-screen pixmap onto the screen, then * delete the pixmap. */ XCopyArea(scalePtr->display, pixmap, Tk_WindowId(tkwin), scalePtr->copyGC, drawnArea.x, drawnArea.y, drawnArea.width, drawnArea.height, drawnArea.x, drawnArea.y); Tk_FreePixmap(scalePtr->display, pixmap); #endif /* TK_NO_DOUBLE_BUFFERING */ done: scalePtr->flags &= ~REDRAW_ALL; }
static BOOL xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) { const rdpBrush* brush; xfBitmap* bitmap; XColor foreColor; XColor backColor; Pixmap pattern = 0; xfContext* xfc = (xfContext*) context; BOOL ret = FALSE; if (!xfc->display || !xfc->drawing) return FALSE; if (!xf_decode_color(xfc, mem3blt->foreColor, &foreColor)) return FALSE; if (!xf_decode_color(xfc, mem3blt->backColor, &backColor)) return FALSE; xf_lock_x11(xfc, FALSE); brush = &mem3blt->brush; bitmap = (xfBitmap*) mem3blt->bitmap; if (!xf_set_rop3(xfc, gdi_rop3_code(mem3blt->bRop))) goto fail; switch (brush->style) { case GDI_BS_PATTERN: if (brush->bpp > 1) { pattern = xf_brush_new(xfc, 8, 8, brush->bpp, brush->data); XSetFillStyle(xfc->display, xfc->gc, FillTiled); XSetTile(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); } else { pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data); XSetBackground(xfc->display, xfc->gc, backColor.pixel); XSetForeground(xfc->display, xfc->gc, foreColor.pixel); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetStipple(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); } break; case GDI_BS_SOLID: XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetBackground(xfc->display, xfc->gc, backColor.pixel); XSetForeground(xfc->display, xfc->gc, foreColor.pixel); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); break; default: WLog_ERR(TAG, "Mem3Blt unimplemented brush style:%"PRIu32"", brush->style); goto fail; } XCopyArea(xfc->display, bitmap->pixmap, xfc->drawing, xfc->gc, mem3blt->nXSrc, mem3blt->nYSrc, mem3blt->nWidth, mem3blt->nHeight, mem3blt->nLeftRect, mem3blt->nTopRect); ret = TRUE; if (xfc->drawing == xfc->primary) ret = gdi_InvalidateRegion(xfc->hdc, mem3blt->nLeftRect, mem3blt->nTopRect, mem3blt->nWidth, mem3blt->nHeight); XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetTSOrigin(xfc->display, xfc->gc, 0, 0); if (pattern != 0) XFreePixmap(xfc->display, pattern); fail: XSetFunction(xfc->display, xfc->gc, GXcopy); xf_unlock_x11(xfc, FALSE); return ret; }
void ui_loop(int full_throttle){ Window root_return,*children_return,parent; unsigned int n_children; XEvent ev; event_t *v_event; int i; XWindowAttributes winattr,wa; int x,y; int propagate; char keydown[16]; KeySym keysym_ret; XComposeStatus status_in_out; symbol_x11 data; vkey key=ANY; if(full_throttle){ send_empty_event(win); } XColor reds,redx; XAllocNamedColor(dpy, DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy)), "red", &reds, &redx); while(running){ XNextEvent(dpy,&ev); switch(ev.type){ case ButtonRelease: lastMX=ev.xbutton.x; lastMY=ev.xbutton.y; onclick(lastMX,lastMY); refresh(); break; case KeyRelease: uk_log("KeyRelease %i",ev.xkey.keycode); // FIXME what should index be? currently at 0, also this function is deprecated data.ks=XKeycodeToKeysym(dpy,ev.xkey.keycode,0); data.modifier=0; data.keycode=ev.xkey.keycode; log_platformspecific(&data); if(ev.xkey.keycode==22) key=BACKSPACE; else if(ev.xkey.keycode==36) key=ENTER; else key=ANY; XLookupString(&ev,keydown,16,&keysym_ret,&status_in_out); onrelease(keydown,&propagate,key,(void *)&data); uk_log("propagate = %i",propagate); if(!propagate) break; uk_log("event propagated"); v_event=_get_event_from_keycode(ev.xkey.keycode); onevent(v_event); refresh(); XFlush(dpy); break; case DestroyNotify: uk_log("destroy window"); // Destroy notify here makes the program close whenever you open // A new window on my machine. Wonder why? // running=0; break; case ClientMessage: if(ev.xclient.data.l[0]!=0x42 || ! full_throttle) break; send_empty_event(win); case Expose: exposes++; if((exposes%10)==0) uk_log("eps=%i",1000*exposes/(get_msec()-start_time)); onrender(); reset_clip(); __x11_frame++; XCopyArea(dpy,double_buffer,win,gc,0,0,WIDTH,HEIGHT,0,0); // XFlush(dpy); break; case ReparentNotify: uk_log("Reparent win=%x par=%x",ev.xreparent.window,ev.xreparent.parent); if(ev.xreparent.parent!=0){ win_parent=ev.xreparent.parent; } break; case ConfigureNotify: get_win_pos(win,&lastX,&lastY); // Let's start out with window /* i=0; for(Window cwin=win; cwin != 0; cwin=parent){ // I'm sure this is cheating! winX=ev.xconfigure.x; winY=ev.xconfigure.y; XQueryTree(dpy,cwin,&root_return,&parent,&children_return,&n_children); // Don't ask. This is pure magic! // Probably it only works on Ubuntu // there are for some 2 windows around my window // until I can see the actual position of the window. // Milage may vary. if(i == 2){ XWindowAttributes attr; XGetWindowAttributes(dpy,cwin,&attr); lastX=attr.x; lastY=attr.y; uk_log("windows moved to (%i,%i)",lastX,lastY); } i++; } */ break; } } uk_log("ui_loop end!"); // writestate(STATE_FILE,lastX,lastY); veta_exit(); }
/* EXTPROTO */ void rxvt_resize_pixmap(rxvt_t *r, int page) { XGCValues gcvalue; GC gc; unsigned int width = VT_WIDTH(r); unsigned int height = VT_HEIGHT(r); if (IS_PIXMAP(PVTS(r, page)->pixmap)) XFreePixmap(r->Xdisplay, PVTS(r, page)->pixmap); if (NOT_PIXMAP(PVTS(r, page)->bg.pixmap)) /* So be it: I'm not using pixmaps */ return; gcvalue.foreground = r->pixColorsFocus[Color_bg]; gc = XCreateGC(r->Xdisplay, PVTS(r, page)->vt, GCForeground, &gcvalue); if (IS_GC(gc) && IS_PIXMAP(PVTS(r, page)->bg.pixmap)) { /* we have a specified pixmap */ unsigned int w = PVTS(r, page)->bg.w; unsigned int h = PVTS(r, page)->bg.h; unsigned int x = PVTS(r, page)->bg.x; unsigned int y = PVTS(r, page)->bg.y; unsigned int xpmh = PVTS(r, page)->xpm_attr.height; unsigned int xpmw = PVTS(r, page)->xpm_attr.width; unsigned int pixmapw, pixmaph; /* * don't zoom pixmap too much nor expand really small pixmaps */ if (w > 1000 || h > 1000) w = 1; else if (width > (10 * xpmw) || height > (10 * xpmh)) w = 0; /* tile */ if (w == 0) { /* basic X tiling - let the X server do it */ PVTS(r, page)->pixmap = XCreatePixmap(r->Xdisplay, PVTS(r, page)->vt, xpmw, xpmh, (unsigned int)XDEPTH); XCopyArea(r->Xdisplay, PVTS(r, page)->bg.pixmap, PVTS(r, page)->pixmap, gc, 0, 0, xpmw, xpmh, 0, 0); pixmapw = xpmw; pixmaph = xpmh; } else { float incr, p; Pixmap tmp; PVTS(r, page)->pixmap = XCreatePixmap(r->Xdisplay, PVTS(r, page)->vt, width, height, (unsigned int)XDEPTH); /* horizontal scaling */ rxvt_pixmap_incr(&w, &x, &incr, &p, width, xpmw); tmp = XCreatePixmap(r->Xdisplay, PVTS(r, page)->vt, width, xpmh, (unsigned int)XDEPTH); XFillRectangle(r->Xdisplay, tmp, gc, 0, 0, width, xpmh); for ( /*nil */ ; x < w; x++, p += incr) { if (p >= xpmw) p = 0; /* copy one column from the original pixmap to the ** tmp pixmap */ XCopyArea(r->Xdisplay, PVTS(r, page)->bg.pixmap, tmp, gc, (int)p, 0, 1, xpmh, (int)x, 0); } /* vertical scaling */ rxvt_pixmap_incr(&h, &y, &incr, &p, height, xpmh); if (y > 0) XFillRectangle(r->Xdisplay, PVTS(r, page)->pixmap, gc, 0, 0, width, y); if (h < height) XFillRectangle(r->Xdisplay, PVTS(r, page)->pixmap, gc, 0, (int)h, width, height - h + 1); for ( /*nil */ ; y < h; y++, p += incr) { if (p >= xpmh) p = 0; /* copy one row from the tmp pixmap to the main ** pixmap */ XCopyArea(r->Xdisplay, tmp, PVTS(r, page)->pixmap, gc, 0, (int)p, width, 1, 0, (int)y); } XFreePixmap(r->Xdisplay, tmp); pixmapw = width; pixmaph = height; } #ifdef TINTING_SUPPORT # ifdef HAVE_LIBXRENDER xrenderShadeParentPixmap( r, PVTS(r, page)->pixmap, 0, 0, pixmapw, pixmaph, False); # else rxvt_shade_pixmap( r, PVTS(r, page)->pixmap, 0, 0, pixmapw, pixmaph); # endif #endif /* TINTING_SUPPORT */ /* Free gc */ XFreeGC(r->Xdisplay, gc); } XSetWindowBackgroundPixmap(r->Xdisplay, PVTS(r, page)->vt, PVTS(r, page)->pixmap); # ifdef TRANSPARENT r->h->am_transparent = 0; r->h->am_pixmap_trans = 0; # endif XClearWindow(r->Xdisplay, PVTS(r, page)->vt); XSync(r->Xdisplay, False); }
void draw_tiger_map (Widget w, char *filenm, int destination_pixmap, int nocache) { // For future implementation of a "refresh cached map" option char file[MAX_FILENAME]; // Complete path/name of image file char short_filenm[MAX_FILENAME]; FILE *f; // Filehandle of image file char fileimg[MAX_FILENAME]; // Ascii name of image file, read from GEO file char tigertmp[MAX_FILENAME*2]; // Used for putting together the tigermap query int width, height; tiepoint tp[2]; // Calibration points for map, read in from .geo file register long map_c_T, map_c_L; // map delta NW edge coordinates, DNN: these should be signed register long tp_c_dx, tp_c_dy; // tiepoint coordinate differences unsigned long c_x_min, c_y_min;// top left coordinates of map inside screen unsigned long c_y_max; // bottom right coordinates of map inside screen double c_x; // Xastir coordinates 1/100 sec, 0 = 180°W double c_y; // Xastir coordinates 1/100 sec, 0 = 90°N long map_y_0; // map pixel pointer prior to TM adjustment register long map_x, map_y; // map pixel pointers, DNN: this was a float, chg to long long map_x_min, map_x_max; // map boundaries for in screen part of map long map_y_min, map_y_max; // long map_x_ctr; // half map width in pixel long map_y_ctr; // half map height in pixel int map_seen = 0; int map_act; int map_done; long map_c_yc; // map center, vert coordinate long map_c_xc; // map center, hor coordinate double map_c_dx, map_c_dy; // map coordinates increment (pixel width) double c_dx; // adjusted map pixel width long scr_x, scr_y; // screen pixel plot positions long scr_xp, scr_yp; // previous screen plot positions int scr_dx, scr_dy; // increments in screen plot positions long scr_x_mc; // map center in screen units long scr_c_xr; long scale_xa; // adjusted for topo maps double scale_x_nm; // nm per Xastir coordinate unit long scale_x0; // at widest map area char local_filename[MAX_FILENAME]; ExceptionInfo exception; Image *image; ImageInfo *image_info; PixelPacket *pixel_pack; PixelPacket temp_pack; IndexPacket *index_pack; int l; XColor my_colors[256]; double left, right, top, bottom, map_width, map_height; double lat_center = 0; double long_center = 0; char map_it[MAX_FILENAME]; char tmpstr[100]; int geo_image_width; // Image width from GEO file int geo_image_height; // Image height from GEO file // initialize this local_filename[0]='\0'; // Create a shorter filename for display (one that fits the // status line more closely). Subtract the length of the // "Indexing " and/or "Loading " strings as well. if (strlen(filenm) > (41 - 9)) { int avail = 41 - 11; int new_len = strlen(filenm) - avail; xastir_snprintf(short_filenm, sizeof(short_filenm), "..%s", &filenm[new_len]); } else { xastir_snprintf(short_filenm, sizeof(short_filenm), "%s", filenm); } xastir_snprintf(map_it, sizeof(map_it), langcode ("BBARSTA028"), short_filenm); statusline(map_it,0); // Loading ... // Check whether we're indexing or drawing the map if ( (destination_pixmap == INDEX_CHECK_TIMESTAMPS) || (destination_pixmap == INDEX_NO_TIMESTAMPS) ) { // We're indexing only. Save the extents in the index. // Force the extents to the edges of the earth for the // index file. index_update_xastir(filenm, // Filename only 64800000l, // Bottom 0l, // Top 0l, // Left 129600000l, // Right 0); // Default Map Level // Update statusline xastir_snprintf(map_it, sizeof(map_it), langcode ("BBARSTA039"), short_filenm); statusline(map_it,0); // Loading/Indexing ... return; // Done indexing this file } // Tiepoint for upper left screen corner // tp[0].img_x = 0; // Pixel Coordinates tp[0].img_y = 0; // Pixel Coordinates tp[0].x_long = NW_corner_longitude; // Xastir Coordinates tp[0].y_lat = NW_corner_latitude; // Xastir Coordinates // Tiepoint for lower right screen corner // tp[1].img_x = screen_width - 1; // Pixel Coordinates tp[1].img_y = screen_height - 1; // Pixel Coordinates tp[1].x_long = SE_corner_longitude; // Xastir Coordinates tp[1].y_lat = SE_corner_latitude; // Xastir Coordinates left = (double)((NW_corner_longitude - 64800000l )/360000.0); // Lat/long Coordinates top = (double)(-((NW_corner_latitude - 32400000l )/360000.0)); // Lat/long Coordinates right = (double)((SE_corner_longitude - 64800000l)/360000.0);//Lat/long Coordinates bottom = (double)(-((SE_corner_latitude - 32400000l)/360000.0));//Lat/long Coordinates map_width = right - left; // Lat/long Coordinates map_height = top - bottom; // Lat/long Coordinates geo_image_width = screen_width; geo_image_height = screen_height; long_center = (left + right)/2.0l; lat_center = (top + bottom)/2.0l; // Example query to the census map server.... /* xastir_snprintf(fileimg, sizeof(fileimg), "\'http://tiger.census.gov/cgi-bin/mapper/map.gif?on=CITIES&on=GRID&on=counties&on=majroads&on=places&&on=interstate&on=states&on=ushwy&on=statehwy&lat=%f\046lon=%f\046wid=%f\046ht=%f\046iwd=%i\046iht=%i\'",\ lat_center, long_center, map_width, map_height, tp[1].img_x + 1, tp[1].img_y + 1); */ xastir_snprintf(tigertmp, sizeof(tigertmp), "http://tiger.census.gov/cgi-bin/mapper/map.gif?"); if (tiger_show_grid) strncat(tigertmp, "&on=GRID", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=GRID", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_counties) strncat(tigertmp, "&on=counties", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=counties", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_cities) strncat(tigertmp, "&on=CITIES", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=CITIES", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_places) strncat(tigertmp, "&on=places", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=places", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_majroads) strncat(tigertmp, "&on=majroads", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=majroads", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_streets) strncat(tigertmp, "&on=streets", sizeof(tigertmp) - 1 - strlen(tigertmp)); // Don't turn streets off since this will automagically show up as you zoom in. if (tiger_show_railroad) strncat(tigertmp, "&on=railroad", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=railroad", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_states) strncat(tigertmp, "&on=states", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=states", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_interstate) strncat(tigertmp, "&on=interstate", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=interstate", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_ushwy) strncat(tigertmp, "&on=ushwy", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=ushwy", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_statehwy) strncat(tigertmp, "&on=statehwy", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=statehwy", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_water) strncat(tigertmp, "&on=water", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=water", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_lakes) strncat(tigertmp, "&on=shorelin", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=shorelin", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_misc) strncat(tigertmp, "&on=miscell", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=miscell", sizeof(tigertmp) - 1 - strlen(tigertmp)); xastir_snprintf(tmpstr, sizeof(tmpstr), "&lat=%f\046lon=%f\046", lat_center, long_center); strncat (tigertmp, tmpstr, sizeof(tigertmp) - 1 - strlen(tigertmp)); xastir_snprintf(tmpstr, sizeof(tmpstr), "wid=%f\046ht=%f\046", map_width, map_height); strncat (tigertmp, tmpstr, sizeof(tigertmp) - 1 - strlen(tigertmp)); xastir_snprintf(tmpstr, sizeof(tmpstr), "iwd=%i\046iht=%i", tp[1].img_x + 1, tp[1].img_y + 1); strncat (tigertmp, tmpstr, sizeof(tigertmp) - 1 - strlen(tigertmp)); xastir_snprintf(fileimg, sizeof(fileimg), "%s", tigertmp); if (debug_level & 512) { fprintf(stderr,"left side is %f\n", left); fprintf(stderr,"right side is %f\n", right); fprintf(stderr,"top is %f\n", top); fprintf(stderr,"bottom is %f\n", bottom); fprintf(stderr,"lat center is %f\n", lat_center); fprintf(stderr,"long center is %f\n", long_center); fprintf(stderr,"screen width is %li\n", screen_width); fprintf(stderr,"screen height is %li\n", screen_height); fprintf(stderr,"map width is %f\n", map_width); fprintf(stderr,"map height is %f\n", map_height); fprintf(stderr,"fileimg is %s\n", fileimg); fprintf(stderr,"ftp or http file: %s\n", fileimg); } // Hopefully this will eventually allow us to get maps in the background // while (sometimeout !=0 && local_filename[0]==NULL){ if (local_filename[0]=='\0' ){ if (debug_level & 512 ) { fprintf(stderr,"tiger_local_file=<%s>\n",local_filename); } HandlePendingEvents(app_context); if (interrupt_drawing_now) { // Update to screen (void)XCopyArea(XtDisplay(da), pixmap, XtWindow(da), gc, 0, 0, (unsigned int)screen_width, (unsigned int)screen_height, 0, 0); return; } get_tiger_local_file(local_filename,fileimg); } // whackadoodle // Tell ImageMagick where to find it xastir_snprintf(file, sizeof(file), "%s", local_filename); GetExceptionInfo(&exception); image_info=CloneImageInfo((ImageInfo *) NULL); xastir_snprintf(image_info->filename, sizeof(image_info->filename), "%s", file); if (debug_level & 512) { fprintf(stderr,"Copied %s into image info.\n", file); fprintf(stderr,"image_info got: %s\n", image_info->filename); fprintf(stderr,"Entered ImageMagick code.\n"); fprintf(stderr,"Attempting to open: %s\n", image_info->filename); } // We do a test read first to see if the file exists, so we // don't kill Xastir in the ReadImage routine. f = fopen (image_info->filename, "r"); if (f == NULL) { if (debug_level & 512) fprintf(stderr,"File could not be read\n"); #ifdef USE_MAP_CACHE // clear from cache if bad if (map_cache_del(fileimg)) { if (debug_level & 512) { fprintf(stderr,"Couldn't delete unreadable map from cache\n"); } } #endif if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } (void)fclose (f); image = ReadImage(image_info, &exception); if (image == (Image *) NULL) { MagickWarning(exception.severity, exception.reason, exception.description); //fprintf(stderr,"MagickWarning\n"); #ifdef USE_MAP_CACHE // clear from cache if bad if (map_cache_del(fileimg)) { if (debug_level & 512) { fprintf(stderr,"Couldn't delete map from cache\n"); } } #endif if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } if (debug_level & 512) fprintf(stderr,"Color depth is %i \n", (int)image->depth); if (image->colorspace != RGBColorspace) { fprintf(stderr,"TBD: I don't think we can deal with colorspace != RGB"); if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } width = image->columns; height = image->rows; // Code to mute the image so it's not as bright. /* if (raster_map_intensity < 1.0) { char tempstr[30]; if (debug_level & 512) fprintf(stderr,"level=%s\n", tempstr); xastir_snprintf(tempstr, sizeof(tempstr), "%d, 100, 100", (int)(raster_map_intensity * 100.0)); ModulateImage(image, tempstr); } */ // If were are drawing to a low bpp display (typically < 8bpp) // try to reduce the number of colors in an image. // This may take some time, so it would be best to do ahead of // time if it is a static image. #if (MagickLibVersion < 0x0540) if (visual_type == NOT_TRUE_NOR_DIRECT && GetNumberColors(image, NULL) > 128) { #else // MagickLib >= 540 if (visual_type == NOT_TRUE_NOR_DIRECT && GetNumberColors(image, NULL, &exception) > 128) { #endif // MagickLib Version if (image->storage_class == PseudoClass) { #if (MagickLibVersion < 0x0549) CompressColormap(image); // Remove duplicate colors #else // MagickLib >= 0x0549 CompressImageColormap(image); // Remove duplicate colors #endif // MagickLibVersion < 0x0549 } // Quantize down to 128 will go here... } pixel_pack = GetImagePixels(image, 0, 0, image->columns, image->rows); if (!pixel_pack) { fprintf(stderr,"pixel_pack == NULL!!!"); if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } index_pack = GetIndexes(image); if (image->storage_class == PseudoClass && !index_pack) { fprintf(stderr,"PseudoClass && index_pack == NULL!!!"); if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } if (image->storage_class == PseudoClass && image->colors <= 256) { for (l = 0; l < (int)image->colors; l++) { // Need to check how to do this for ANY image, as ImageMagick can read in all sorts // of image files temp_pack = image->colormap[l]; if (debug_level & 512) fprintf(stderr,"Colormap color is %i %i %i \n", temp_pack.red, temp_pack.green, temp_pack.blue); // Here's a tricky bit: PixelPacket entries are defined as Quantum's. Quantum // is defined in /usr/include/magick/image.h as either an unsigned short or an // unsigned char, depending on what "configure" decided when ImageMagick was installed. // We can determine which by looking at MaxRGB or QuantumDepth. // if (QuantumDepth == 16) { // Defined in /usr/include/magick/image.h if (debug_level & 512) fprintf(stderr,"Color quantum is [0..65535]\n"); my_colors[l].red = temp_pack.red * raster_map_intensity; my_colors[l].green = temp_pack.green * raster_map_intensity; my_colors[l].blue = temp_pack.blue * raster_map_intensity; } else { // QuantumDepth = 8 if (debug_level & 512) fprintf(stderr,"Color quantum is [0..255]\n"); my_colors[l].red = (temp_pack.red << 8) * raster_map_intensity; my_colors[l].green = (temp_pack.green << 8) * raster_map_intensity; my_colors[l].blue = (temp_pack.blue << 8) * raster_map_intensity; } // Get the color allocated on < 8bpp displays. pixel color is written to my_colors.pixel if (visual_type == NOT_TRUE_NOR_DIRECT) { // XFreeColors(XtDisplay(w), cmap, &(my_colors[l].pixel),1,0); XAllocColor(XtDisplay(w), cmap, &my_colors[l]); } else { pack_pixel_bits(my_colors[l].red, my_colors[l].green, my_colors[l].blue, &my_colors[l].pixel); } if (debug_level & 512) fprintf(stderr,"Color allocated is %li %i %i %i \n", my_colors[l].pixel, my_colors[l].red, my_colors[l].blue, my_colors[l].green); } } /* * Here are the corners of our viewport, using the Xastir * coordinate system. Notice that Y is upside down: * * left edge of view = NW_corner_longitude * right edge of view = SE_corner_longitude * top edge of view = NW_corner_latitude * bottom edge of view = SE_corner_latitude * * The corners of our map will soon be (after translating the * tiepoints to the corners if they're not already there): * * left edge of map = tp[0].x_long in Xastir format * right edge of map = tp[1].x_long * top edge of map = tp[0].y_lat * bottom edge of map = tp[1].y_lat * */ map_c_L = tp[0].x_long - NW_corner_longitude; // map left coordinate map_c_T = tp[0].y_lat - NW_corner_latitude; // map top coordinate tp_c_dx = (long)(tp[1].x_long - tp[0].x_long);// Width between tiepoints tp_c_dy = (long)(tp[1].y_lat - tp[0].y_lat); // Height between tiepoints // Check for tiepoints being in wrong relation to one another if (tp_c_dx < 0) tp_c_dx = -tp_c_dx; // New width between tiepoints if (tp_c_dy < 0) tp_c_dy = -tp_c_dy; // New height between tiepoints // Calculate step size per pixel map_c_dx = ((double) tp_c_dx / abs(tp[1].img_x - tp[0].img_x)); map_c_dy = ((double) tp_c_dy / abs(tp[1].img_y - tp[0].img_y)); // Scaled screen step size for use with XFillRectangle below scr_dx = (int) (map_c_dx / scale_x) + 1; scr_dy = (int) (map_c_dy / scale_y) + 1; // calculate top left map corner from tiepoints if (tp[0].img_x != 0) { tp[0].x_long -= (tp[0].img_x * map_c_dx); // map left edge longitude map_c_L = tp[0].x_long - NW_corner_longitude; // delta ?? tp[0].img_x = 0; if (debug_level & 512) fprintf(stderr,"Translated tiepoint_0 x: %d\t%lu\n", tp[0].img_x, tp[0].x_long); } if (tp[0].img_y != 0) { tp[0].y_lat -= (tp[0].img_y * map_c_dy); // map top edge latitude map_c_T = tp[0].y_lat - NW_corner_latitude; tp[0].img_y = 0; if (debug_level & 512) fprintf(stderr,"Translated tiepoint_0 y: %d\t%lu\n", tp[0].img_y, tp[0].y_lat); } // calculate bottom right map corner from tiepoints // map size is geo_image_width / geo_image_height if (tp[1].img_x != (geo_image_width - 1) ) { tp[1].img_x = geo_image_width - 1; tp[1].x_long = tp[0].x_long + (tp[1].img_x * map_c_dx); // right if (debug_level & 512) fprintf(stderr,"Translated tiepoint_1 x: %d\t%lu\n", tp[1].img_x, tp[1].x_long); } if (tp[1].img_y != (geo_image_height - 1) ) { tp[1].img_y = geo_image_height - 1; tp[1].y_lat = tp[0].y_lat + (tp[1].img_y * map_c_dy); // bottom if (debug_level & 512) fprintf(stderr,"Translated tiepoint_1 y: %d\t%lu\n", tp[1].img_y, tp[1].y_lat); } if (debug_level & 512) { fprintf(stderr,"X tiepoint width: %ld\n", tp_c_dx); fprintf(stderr,"Y tiepoint width: %ld\n", tp_c_dy); fprintf(stderr,"Loading imagemap: %s\n", file); fprintf(stderr,"\nImage: %s\n", file); fprintf(stderr,"Image size %d %d\n", geo_image_width, geo_image_height); fprintf(stderr,"XX: %ld YY:%ld Sx %f %d Sy %f %d\n", map_c_L, map_c_T, map_c_dx,(int) (map_c_dx / scale_x), map_c_dy, (int) (map_c_dy / scale_y)); fprintf(stderr,"Image size %d %d\n", width, height); #if (MagickLibVersion < 0x0540) fprintf(stderr,"Unique colors = %d\n", GetNumberColors(image, NULL)); #else // MagickLib < 540 fprintf(stderr,"Unique colors = %ld\n", GetNumberColors(image, NULL, &exception)); #endif // MagickLib < 540 fprintf(stderr,"XX: %ld YY:%ld Sx %f %d Sy %f %d\n", map_c_L, map_c_T, map_c_dx,(int) (map_c_dx / scale_x), map_c_dy, (int) (map_c_dy / scale_y)); fprintf(stderr,"image matte is %i\n", image->matte); } // debug_level & 512 // draw the image from the file out to the map screen // Get the border values for the X and Y for loops used // for the XFillRectangle call later. map_c_yc = (tp[0].y_lat + tp[1].y_lat) / 2; // vert center of map as reference map_y_ctr = (long)(height / 2 +0.499); scale_x0 = get_x_scale(0,map_c_yc,scale_y); // reference scaling at vert map center map_c_xc = (tp[0].x_long + tp[1].x_long) / 2; // hor center of map as reference map_x_ctr = (long)(width / 2 +0.499); scr_x_mc = (map_c_xc - NW_corner_longitude) / scale_x; // screen coordinates of map center // calculate map pixel range in y direction that falls into screen area c_y_max = 0ul; map_y_min = map_y_max = 0l; for (map_y_0 = 0, c_y = tp[0].y_lat; map_y_0 < (long)height; map_y_0++, c_y += map_c_dy) { scr_y = (c_y - NW_corner_latitude) / scale_y; // current screen position if (scr_y > 0) { if (scr_y < screen_height) { map_y_max = map_y_0; // update last map pixel in y c_y_max = (unsigned long)c_y;// bottom map inside screen coordinate } else break; // done, reached bottom screen border } else { // pixel is above screen map_y_min = map_y_0; // update first map pixel in y } } c_y_min = (unsigned long)(tp[0].y_lat + map_y_min * map_c_dy); // top map inside screen coordinate map_x_min = map_x_max = 0l; for (map_x = 0, c_x = tp[0].x_long; map_x < (long)width; map_x++, c_x += map_c_dx) { scr_x = (c_x - NW_corner_longitude)/ scale_x; // current screen position if (scr_x > 0) { if (scr_x < screen_width) map_x_max = map_x; // update last map pixel in x else break; // done, reached right screen border } else { // pixel is left from screen map_x_min = map_x; // update first map pixel in x } } c_x_min = (unsigned long)(tp[0].x_long + map_x_min * map_c_dx); // left map inside screen coordinate scr_yp = -1; scr_c_xr = SE_corner_longitude; c_dx = map_c_dx; // map pixel width scale_xa = scale_x0; // the compiler likes it ;-) map_done = 0; map_act = 0; map_seen = 0; scr_y = screen_height - 1; // loop over map pixel rows for (map_y_0 = map_y_min, c_y = (double)c_y_min; (map_y_0 <= map_y_max); map_y_0++, c_y += map_c_dy) { HandlePendingEvents(app_context); if (interrupt_drawing_now) { if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); // Update to screen (void)XCopyArea(XtDisplay(da), pixmap, XtWindow(da), gc, 0, 0, (unsigned int)screen_width, (unsigned int)screen_height, 0, 0); DestroyExceptionInfo(&exception); return; } scr_y = (c_y - NW_corner_latitude) / scale_y; if (scr_y != scr_yp) { // don't do a row twice scr_yp = scr_y; // remember as previous y scr_xp = -1; // loop over map pixel columns map_act = 0; scale_x_nm = calc_dscale_x(0,(long)c_y) / 1852.0; // nm per Xastir coordinate for (map_x = map_x_min, c_x = (double)c_x_min; map_x <= map_x_max; map_x++, c_x += c_dx) { scr_x = (c_x - NW_corner_longitude) / scale_x; if (scr_x != scr_xp) { // don't do a pixel twice scr_xp = scr_x; // remember as previous x map_y = map_y_0; if (map_y >= 0 && map_y <= tp[1].img_y) { // check map boundaries in y direction map_seen = 1; map_act = 1; // detects blank screen rows (end of map) // now copy a pixel from the map image to the screen l = map_x + map_y * image->columns; if (image->storage_class == PseudoClass) { XSetForeground(XtDisplay(w), gc, my_colors[index_pack[l]].pixel); } else { // It is not safe to assume that the red/green/blue // elements of pixel_pack of type Quantum are the // same as the red/green/blue of an XColor! if (QuantumDepth==16) { my_colors[0].red=pixel_pack[l].red; my_colors[0].green=pixel_pack[l].green; my_colors[0].blue=pixel_pack[l].blue; } else { // QuantumDepth=8 // shift the bits of the 8-bit quantity so that // they become the high bigs of my_colors.* my_colors[0].red=pixel_pack[l].red<<8; my_colors[0].green=pixel_pack[l].green<<8; my_colors[0].blue=pixel_pack[l].blue<<8; } // NOW my_colors has the right r,g,b range for // pack_pixel_bits pack_pixel_bits(my_colors[0].red * raster_map_intensity, my_colors[0].green * raster_map_intensity, my_colors[0].blue * raster_map_intensity, &my_colors[0].pixel); XSetForeground(XtDisplay(w), gc, my_colors[0].pixel); } (void)XFillRectangle (XtDisplay (w),pixmap,gc,scr_x,scr_y,scr_dx,scr_dy); } // check map boundaries in y direction } } // loop over map pixel columns if (map_seen && !map_act) map_done = 1; } } // loop over map pixel rows if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); }
static void draw_scope(double *values) { static int32 call_cnt; int offset, expose; XEvent e; char pixels[SCOPE_HEIGHT*32]; double work[SCOPE_HEIGHT]; int nze; char *mname; KeySym k; make_logspectrogram(values, work); set_draw_pixel(work, pixels); expose = 0; nze = 0; while(QLength(disp) || XPending(disp)) { XNextEvent(disp, &e); switch(e.type) { case Expose: expose++; break; case KeyPress: k = xlookup_key(&e.xkey); switch(k) { #ifdef XK_Down case XK_Up: #endif /* XK_Up */ #ifdef XK_KP_Up case XK_KP_Up: #endif /* XK_KP_Up */ nze++; break; #ifdef XK_Down case XK_Down: #endif /* XK_Down */ #ifdef XK_KP_Down case XK_KP_Down: #endif /* XK_KP_Down */ nze--; break; #ifdef XK_Left case XK_Left: #endif /* XK_Left */ #ifdef XK_KP_Left case XK_KP_Left: #endif /* XK_KP_Left */ soundspec_update_interval = (int32)(soundspec_update_interval*1.1); break; #ifdef XK_Right case XK_Right: #endif /* XK_Right */ #ifdef XK_KP_Right case XK_KP_Right: #endif /* XK_KP_Right */ soundspec_update_interval = (int32)(soundspec_update_interval/1.1); if(soundspec_update_interval < 0.01 * play_mode->rate) soundspec_update_interval = (int32)(0.01 * play_mode->rate); break; } break; case ClientMessage: if(wm_delete_window == e.xclient.data.l[0]) { mname = XGetAtomName(disp, e.xclient.message_type); if(mname != NULL && strcmp(mname, "WM_PROTOCOLS") == 0) { /* Delete message from WM */ ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "Sound Spectrogram Window is closed"); close_soundspec(); XCloseDisplay(disp); disp = NULL; return; } } break; } } offset = call_cnt % SCROLL_THRESHOLD; if(offset == 0) { XCopyArea(disp, offscr, offscr, gc, SCROLL_THRESHOLD, 0, SCOPE_WIDTH - SCROLL_THRESHOLD, SCOPE_HEIGHT, 0, 0); XSetForeground(disp, gc, BlackPixel(disp, DefaultScreen(disp))); XFillRectangle(disp, offscr, gc, SCOPE_WIDTH - SCROLL_THRESHOLD, 0, SCROLL_THRESHOLD, SCOPE_HEIGHT); XCopyArea(disp, offscr, win, gc, 0, 0, SCOPE_WIDTH, SCOPE_HEIGHT, 0, 0); } img->data = (char *)pixels; XPutImage(disp, offscr, gc, img, 0, 0, SCOPE_WIDTH - SCROLL_THRESHOLD + offset, 0, 1, SCOPE_HEIGHT); if(!expose) XCopyArea(disp, offscr, win, gc, SCOPE_WIDTH - SCROLL_THRESHOLD + offset, 0, 1, SCOPE_HEIGHT, SCOPE_WIDTH - SCROLL_THRESHOLD + offset, 0); else { XCopyArea(disp, offscr, win, gc, 0, 0, SCOPE_WIDTH, SCOPE_HEIGHT, 0, 0); } XSync(disp, False); if(nze) initialize_exp_hz_table(soundspec_zoom - 4 * nze); call_cnt++; }
void video_frame(uint32_t id, uint8_t *img_data, uint16_t width, uint16_t height, _Bool resize) { if (!video_win[id]) { debug("frame for null window %u\n", id); return; } if (resize) { XWindowChanges changes = { .width = width, .height = height }; XConfigureWindow(display, video_win[id], CWWidth | CWHeight, &changes); } XWindowAttributes attrs; XGetWindowAttributes(display, video_win[id], &attrs); XImage image = { .width = attrs.width, .height = attrs.height, .depth = 24, .bits_per_pixel = 32, .format = ZPixmap, .byte_order = LSBFirst, .bitmap_unit = 8, .bitmap_bit_order = LSBFirst, .bytes_per_line = attrs.width * 4, .red_mask = 0xFF0000, .green_mask = 0xFF00, .blue_mask = 0xFF, .data = (char*)img_data }; /* scale image if needed */ uint8_t *new_data = malloc(attrs.width * attrs.height * 4); if (new_data && (attrs.width != width || attrs.height != height)) { scale_rgbx_image(img_data, width, height, new_data, attrs.width, attrs.height); image.data = (char*)new_data; } GC default_gc = DefaultGC(display, screen); Pixmap pixmap = XCreatePixmap(display, window, attrs.width, attrs.height, depth); XPutImage(display, pixmap, default_gc, &image, 0, 0, 0, 0, attrs.width, attrs.height); XCopyArea(display, pixmap, video_win[id], default_gc, 0, 0, attrs.width, attrs.height, 0, 0); XFreePixmap(display, pixmap); free(new_data); } void video_begin(uint32_t id, char_t *name, STRING_IDX name_length, uint16_t width, uint16_t height) { Window *win = &video_win[id]; if(*win) { return; } *win = XCreateSimpleWindow(display, RootWindow(display, screen), 0, 0, width, height, 0, BlackPixel(display, screen), WhitePixel(display, screen)); // Fallback name in ISO8859-1. XStoreName(display, *win, "Video Preview"); // UTF-8 name for those WMs that can display it. XChangeProperty(display, *win, XA_NET_NAME, XA_UTF8_STRING, 8, PropModeReplace, name, name_length); XSetWMProtocols(display, *win, &wm_delete_window, 1); /* set WM_CLASS */ XClassHint hint = { .res_name = "utoxvideo", .res_class = "utoxvideo" }; XSetClassHint(display, *win, &hint); XMapWindow(display, *win); debug("new window %u\n", id); } void video_end(uint32_t id) { if(!video_win[id]) { return; } XDestroyWindow(display, video_win[id]); video_win[id] = None; debug("killed window %u\n", id); } Display *deskdisplay; int deskscreen; XShmSegmentInfo shminfo; void initshm(void) { deskdisplay = XOpenDisplay(NULL); deskscreen = DefaultScreen(deskdisplay); debug("desktop: %u %u\n", scr->width, scr->height); max_video_width = scr->width; max_video_height = scr->height; }
/********************************************************************** TransferProc: Called by UTM whenever a conversion routine completes a conversion that was initiated by an XmTransferValue call. **********************************************************************/ void TransferProc(Widget w, XtPointer ignore, XtPointer call_data) { XmSelectionCallbackStruct *scs = (XmSelectionCallbackStruct *) call_data; Atom TARGETS = XInternAtom(XtDisplay(w), "TARGETS", False); Atom _MOTIF_EXPORT_TARGETS = XInternAtom(XtDisplay(w), "_MOTIF_EXPORT_TARGETS", False); Atom PIXMAP = XInternAtom(XtDisplay(w), "PIXMAP", False); Atom *targets = (Atom *)scs->value; int PIXMAP_is_supported = 0; unsigned long n; Widget Label2; printf("\n\nNow in TransferProc.\n"); printf("The source has converted: "); OutputAnAtomName(w, scs->target); if ((scs->target == _MOTIF_EXPORT_TARGETS) && (scs->type == XA_ATOM)) { printf("TransferProc: target is TARGETS.\n"); printf("Number of supported targets is %ld\n", scs->length); ListAllTheTargets(w, targets, scs->length); for (n=0; n<=scs->length; n++) { /* Look through list of returned TARGETS to see if PIXMAP is there. */ if (targets[n] == PIXMAP) { printf("The source knows how to convert PIXMAP.\n"); PIXMAP_is_supported = 1; } } if (PIXMAP_is_supported) { printf("TransferProc: Asking for PIXMAP.\n"); XmTransferValue(scs->transfer_id, PIXMAP, (XtCallbackProc)TransferProc, NULL, XtLastTimestampProcessed(XtDisplay(w))); } } if ((scs->target == PIXMAP)) { Pixmap transferred_pixmap = *(Pixmap*) scs->value; Pixmap copy_of_transferred_pixmap; Window root_return; int x, y; unsigned int width, height; unsigned int border_width, depth; GC gc; XtGCMask valueMask; XGCValues values; printf("TransferProc: source has transferred the PIXMAP.\n"); printf("We need to paste it into the DrawingArea.\n"); /* It is better to display a copy of the returned pixmap than to display the returned pixmap itself. The following code creates the copy. */ XGetGeometry(XtDisplay(w), (Drawable)transferred_pixmap, &root_return, &x, &y, &width, &height, &border_width, &depth); copy_of_transferred_pixmap = XCreatePixmap(XtDisplay(w), XtWindow(w), width, height, depth); valueMask = GCFunction; values.function = GXcopy; gc = XtGetGC(w, valueMask, &values); XCopyArea(XtDisplay(w), transferred_pixmap, copy_of_transferred_pixmap, gc, x, y, width, height, x, y); Label2 = XtVaCreateManagedWidget("Label2", xmLabelWidgetClass, w, XmNlabelType, XmPIXMAP, XmNlabelPixmap, copy_of_transferred_pixmap, NULL); XtReleaseGC(w, gc); XmTransferDone(scs->transfer_id, XmTRANSFER_DONE_SUCCEED); } }
static void paintTabView(TabView * tPtr) { Pixmap buffer; WMScreen *scr = W_VIEW(tPtr)->screen; Display *dpy = scr->display; GC white = WMColorGC(scr->white); int i; if (tPtr->flags.type == WTTopTabsBevelBorder) { int count = tPtr->visibleTabs; int first = tPtr->firstVisible; int moreAtLeft; int moreAtRight; int selectedIsVisible; int ty; int twidth, theight; ty = 2; theight = tPtr->tabHeight; buffer = XCreatePixmap(dpy, W_VIEW(tPtr)->window, W_VIEW(tPtr)->size.width, theight, W_VIEW(tPtr)->screen->depth); XFillRectangle(dpy, buffer, WMColorGC(W_VIEW(tPtr)->backColor), 0, 0, W_VIEW(tPtr)->size.width, tPtr->tabHeight); if (tPtr->flags.dontFitAll) { moreAtLeft = first > 0; moreAtRight = (first + count) < tPtr->itemCount; if (tPtr->selectedItem >= first && tPtr->selectedItem < first + count) selectedIsVisible = 1; else selectedIsVisible = 0; } else { moreAtLeft = 0; moreAtRight = 0; selectedIsVisible = 1; } if (moreAtRight) { drawTab(tPtr, buffer, positionOfTab(tPtr, first + count), 0, W_VIEW_WIDTH(tPtr->view), theight, False); } for (i = first + count - 1; i >= first; i--) { if (!selectedIsVisible || i != tPtr->selectedItem) { twidth = W_TabViewItemTabWidth(tPtr->items[i]); drawTab(tPtr, buffer, positionOfTab(tPtr, i), 0, twidth, theight, False); } } if (moreAtLeft) { drawTab(tPtr, buffer, positionOfTab(tPtr, 0) - 2 * BUTTONED_SIDE_OFFSET, 0, BUTTONED_SIDE_OFFSET * 4, theight, False); } if (selectedIsVisible) { int idx = tPtr->selectedItem; drawTab(tPtr, buffer, positionOfTab(tPtr, idx), 0, W_TabViewItemTabWidth(tPtr->items[idx]), theight, True); XDrawLine(dpy, buffer, white, 0, theight - 1, positionOfTab(tPtr, idx), theight - 1); XDrawLine(dpy, buffer, white, positionOfTab(tPtr, idx) + W_TabViewItemTabWidth(tPtr->items[idx]), tPtr->tabHeight - 1, W_VIEW_WIDTH(tPtr->view) - 1, tPtr->tabHeight - 1); } else { XDrawLine(dpy, buffer, white, 0, theight - 1, W_VIEW_WIDTH(tPtr->view), theight - 1); } for (i = 0; i < count; i++) { WMRect rect; rect.pos.x = 15 + positionOfTab(tPtr, first + i); rect.pos.y = ty; rect.size.width = W_TabViewItemTabWidth(tPtr->items[first + i]); rect.size.height = theight; W_DrawLabel(tPtr->items[first + i], buffer, rect, tPtr->flags.enabled && tPtr->items[first + i]->flags.enabled); } if (moreAtLeft) { paintDot(tPtr, buffer, 4, 10); paintDot(tPtr, buffer, 7, 10); paintDot(tPtr, buffer, 10, 10); } if (moreAtRight) { int x; x = positionOfTab(tPtr, tPtr->firstVisible + tPtr->visibleTabs); x = x + (W_VIEW_WIDTH(tPtr->view) - x) / 2; paintDot(tPtr, buffer, x + 5, 10); paintDot(tPtr, buffer, x + 8, 10); paintDot(tPtr, buffer, x + 11, 10); } XCopyArea(dpy, buffer, W_VIEW(tPtr)->window, scr->copyGC, 0, 0, W_VIEW_WIDTH(tPtr->view), theight, 0, 0); XFreePixmap(dpy, buffer); } switch (tPtr->flags.type) { case WTTopTabsBevelBorder: drawRelief(scr, W_VIEW(tPtr)->window, 0, tPtr->tabHeight - 1, W_VIEW(tPtr)->size.width, W_VIEW(tPtr)->size.height - tPtr->tabHeight + 1); break; case WTNoTabsBevelBorder: W_DrawRelief(scr, W_VIEW(tPtr)->window, 0, 0, W_VIEW(tPtr)->size.width, W_VIEW(tPtr)->size.height, WRRaised); break; case WTNoTabsLineBorder: W_DrawRelief(scr, W_VIEW(tPtr)->window, 0, 0, W_VIEW(tPtr)->size.width, W_VIEW(tPtr)->size.height, WRSimple); break; case WTNoTabsNoBorder: break; } }
static void x_unhilight_line(int line) { drawtext(dzen.slave_win.tbuf[line + dzen.slave_win.first_line_vis], 0, line, dzen.slave_win.alignment); XCopyArea(dzen.dpy, dzen.slave_win.drawable[line], dzen.slave_win.line[line], dzen.rgc, 0, 0, dzen.slave_win.width, dzen.line_height, 0, 0); }
/* * Function main (argc, ) * * Starts all the fun! * */ int main(int argc, char *argv[]) { obex_object_t *object; int ret; unsigned height,width; int i; DAParseArguments(argc, argv, options, sizeof(options)/sizeof(DAProgramOption), "CapShare Document Management Dock Applet\nBen Moore [email protected]\n", VERSION); DAInitialize(displayName, "wmcapshare", 60,60, argc, argv); DAMakePixmapFromData(lcdchars2_xpm, &char_buf, &char_mask, &height, &width); DAMakePixmapFromData(lcdnums_xpm, &num_buf, &num_mask, &height, &width); DAMakePixmapFromData(base_xpm, &pixmap, &mask, &height, &width); DAMakePixmapFromData(tstatfld_xpm, &tstatfld_buf, &tstatfld_mask, &height, &width); DAMakePixmapFromData(tstatfld_xpm, &blank_buf, &blank_mask, &height, &width); DAMakePixmapFromData(capshare_xpm, &capshare_pic, &capshare_mask, &height, &width); DAMakePixmapFromData(transfering_xpm, &transfer_pic, &transfer_mask, &height, &width); DAMakePixmapFromData(connected_xpm, &connect_pic, &connect_mask, &height, &width); DAMakePixmapFromData(disconnected_xpm, &disconnect_pic, &disconnect_mask, &height, &width); DAMakePixmapFromData( plane00_xpm, &plane_anim[0], &plane_animmask[1], &height, &width); DAMakePixmapFromData( plane01_xpm, &plane_anim[1], &plane_animmask[2], &height, &width); DAMakePixmapFromData( plane02_xpm, &plane_anim[2], &plane_animmask[3], &height, &width); DAMakePixmapFromData( plane03_xpm, &plane_anim[3], &plane_animmask[4], &height, &width); DAMakePixmapFromData( plane04_xpm, &plane_anim[4], &plane_animmask[5], &height, &width); DAMakePixmapFromData( plane05_xpm, &plane_anim[5], &plane_animmask[6], &height, &width); DAMakePixmapFromData( plane06_xpm, &plane_anim[6], &plane_animmask[6], &height, &width); DAMakePixmapFromData( plane07_xpm, &plane_anim[7], &plane_animmask[7], &height, &width); DAMakePixmapFromData( plane08_xpm, &plane_anim[8], &plane_animmask[8], &height, &width); DAMakePixmapFromData( plane09_xpm, &plane_anim[9], &plane_animmask[9], &height, &width); DAMakePixmapFromData( plane10_xpm, &plane_anim[10], &plane_animmask[10], &height, &width); DAMakePixmapFromData( plane11_xpm, &plane_anim[11], &plane_animmask[11], &height, &width); DAMakePixmapFromData( plane12_xpm, &plane_anim[12], &plane_animmask[12], &height, &width); DAMakePixmapFromData( plane13_xpm, &plane_anim[13], &plane_animmask[13], &height, &width); DAMakePixmapFromData( plane14_xpm, &plane_anim[14], &plane_animmask[14], &height, &width); DAMakePixmapFromData( plane15_xpm, &plane_anim[15], &plane_animmask[15], &height, &width); DAMakePixmapFromData( plane16_xpm, &plane_anim[16], &plane_animmask[16], &height, &width); DAMakePixmapFromData( plane17_xpm, &plane_anim[17], &plane_animmask[17], &height, &width); DAMakePixmapFromData( plane18_xpm, &plane_anim[18], &plane_animmask[18], &height, &width); DAMakePixmapFromData( plane19_xpm, &plane_anim[19], &plane_animmask[19], &height, &width); gc = DefaultGC(DADisplay, DefaultScreen(DADisplay)); /* string2pixmap("recieve", &tstatfld_buf); XCopyArea(DADisplay, plane_pic, pixmap, gc, 0, 0, 60, 29, 0, 15); XCopyArea(DADisplay, tstatfld_buf, pixmap, gc, 0, 0, 42, 8, 16, 48); DASetPixmap(pixmap); XCopyArea(DADisplay, connect_pic, pixmap, gc, 0, 0, 14, 15, 0, 45); DASetPixmap(pixmap); */ XCopyArea(DADisplay, capshare_pic, pixmap, gc, 0, 0, 60, 29, 0, 15); DAShow(); while(1) { handle = OBEX_Init(OBEX_TRANS_IRDA, obex_event, 0); printf("Waiting for files\n"); OBEX_ServerRegister(handle, "OBEX"); while (!finished) { updateDisplay(); OBEX_HandleInput(handle, 1); } finished = FALSE; } 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); } }
static unsigned long zoom_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; unsigned x, y, i, j; long now; if (st->img_loader) /* still loading */ { st->img_loader = load_image_async_simple (st->img_loader, 0, 0, 0, 0, 0); if (! st->img_loader) { /* just finished */ XClearWindow (st->dpy, st->window); st->start_time = time ((time_t) 0); if (!st->lenses) { st->orig_map = XGetImage(st->dpy, st->pm, 0, 0, st->sizex, st->sizey, ~0L, ZPixmap); /* XFreePixmap(st->dpy, st->pm); st->pm = 0;*/ } } return st->delay; } if (!st->img_loader && st->start_time + st->duration < time ((time_t) 0)) { st->img_loader = load_image_async_simple (0, st->screen, st->window, st->pm, 0, 0); return st->delay; } #define nrnd(x) (random() % (x)) now = currentTimeInMs(st); now += st->sinusoid_offset; /* don't run multiple screens in lock-step */ /* find new x,y */ st->tlx = ((1. + sin(((double)now) / X_PERIOD * 2. * M_PI))/2.0) * (st->sizex - st->s/2) /* -s/4 */ + MINX; st->tly = ((1. + sin(((double)now) / Y_PERIOD * 2. * M_PI))/2.0) * (st->sizey - st->s/2) /* -s/4 */ + MINY; if (st->lenses) { for (x = i = 0; x < st->sizex; x += (st->pixwidth + st->pixspacex), ++i) for (y = j = 0; y < st->sizey; y += (st->pixheight + st->pixspacey), ++j) { XCopyArea(st->dpy, st->pm /* src */, st->window /* dest */, st->window_gc, st->tlx + i * st->lensoffsetx /* src_x */, st->tly + j * st->lensoffsety /* src_y */, st->pixwidth, st->pixheight, x /* dest_x */, y /* dest_y */); } } else { for (x = i = 0; x < st->sizex; x += (st->pixwidth + st->pixspacex), ++i) for (y = j = 0; y < st->sizey; y += (st->pixheight + st->pixspacey), ++j) { XSetForeground(st->dpy, st->window_gc, XGetPixel(st->orig_map, st->tlx+i, st->tly+j)); XFillRectangle(st->dpy, st->window, st->window_gc, i * (st->pixwidth + st->pixspacex), j * (st->pixheight + st->pixspacey), st->pixwidth, st->pixheight); } } return st->delay; }
void textbox_draw(textbox *tb) { int i; XGlyphInfo extents; GC context = XCreateGC(display, tb->window, 0, 0); Pixmap canvas = XCreatePixmap(display, tb->window, tb->w, tb->h, DefaultDepth(display, DefaultScreen(display))); XftDraw *draw = XftDrawCreate(display, canvas, DefaultVisual(display, DefaultScreen(display)), DefaultColormap(display, DefaultScreen(display))); // clear canvas XftDrawRect(draw, &tb->color_bg, 0, 0, tb->w, tb->h); char *line = tb->text, *text = tb->text ? tb->text: "", *prompt = tb->prompt ? tb->prompt: ""; int text_len = strlen(text); int length = text_len; int line_height = tb->font->ascent + tb->font->descent; int cursor_x = 0; int cursor_offset = 0; int cursor_width = MAX(2, line_height/10); if (tb->flags & TB_EDITABLE) { int prompt_len = strlen(prompt); length = text_len + prompt_len; cursor_offset = MIN(tb->cursor + prompt_len, length); char eline[length + 10]; line = eline; sprintf(line, "%s%s", prompt, text); // replace spaces so XftTextExtents8 includes their width for (i = 0; i < length; i++) if (isspace(line[i])) line[i] = '_'; // calc cursor position XftTextExtents8(display, tb->font, (unsigned char*)line, cursor_offset, &extents); cursor_x = extents.width; // restore correct text string with spaces sprintf(line, "%s%s", prompt, text); } // calc full input text width XftTextExtents8(display, tb->font, (unsigned char*)line, length, &extents); int line_width = extents.width; int x = 0, y = tb->font->ascent; if (tb->flags & TB_RIGHT) x = tb->w - line_width; if (tb->flags & TB_CENTER) x = MAX(0, (tb->w - line_width) / 2); // draw the text, including any prompt in edit mode XftDrawString8(draw, &tb->color_fg, tb->font, x, y, (unsigned char*)line, length); // draw the cursor if (tb->flags & TB_EDITABLE) XftDrawRect(draw, &tb->color_fg, cursor_x, 2, cursor_width, line_height-4); // flip canvas to window XCopyArea(display, canvas, tb->window, context, 0, 0, tb->w, tb->h, 0, 0); XFreeGC(display, context); XftDrawDestroy(draw); XFreePixmap(display, canvas); }
void ts_eject( int i ) { XCopyArea( xskin_d, xskin_cbuttons, xskin_w, xskin_gc, EJECT_SX(i), EJECT_SY(i), EJECT_W, EJECT_H, EJECT_DX, EJECT_DY ); return; }