/* Returns an XImage structure containing the string rendered in the font. This XImage will be 32 bits per pixel, 8 each per R, G, and B, with the extra byte set to 0xFF. Foregroune and background are GL-style color specifiers: 4 floats from 0.0-1.0. */ XImage * text_to_ximage (Screen *screen, Visual *visual, const char *font, const char *text_lines, GLfloat *texture_fg, GLfloat *texture_bg) { Display *dpy = DisplayOfScreen (screen); int width, height; XFontStruct *f; Pixmap bitmap; f = XLoadQueryFont(dpy, font); if (!f) { f = XLoadQueryFont(dpy, "fixed"); if (f) fprintf (stderr, "%s: unable to load font \"%s\"; using \"fixed\".\n", progname, font); else { fprintf (stderr, "%s: unable to load fonts \"%s\" or \"fixed\"!\n", progname, font); exit (1); } } /* Parse the text, and render it to `bitmap' */ { char *text, *text2, *line, *token; int lines; XCharStruct overall; XGCValues gcv; GC gc; int margin = 2; int fg = 1; int bg = 0; int xoff, yoff; text = strdup (text_lines); while (*text && (text[strlen(text)-1] == '\r' || text[strlen(text)-1] == '\n')) text[strlen(text)-1] = 0; text2 = strdup (text); memset(&overall, 0, sizeof(overall)); token = text; lines = 0; while ((line = strtok (token, "\r\n"))) { XCharStruct o2; int ascent, descent, direction; token = 0; XTextExtents (f, line, strlen(line), &direction, &ascent, &descent, &o2); overall.lbearing = MAX(overall.lbearing, o2.lbearing); overall.rbearing = MAX(overall.rbearing, o2.rbearing); lines++; } free (text); text = 0; width = overall.lbearing + overall.rbearing + margin + margin + 1; height = ((f->ascent + f->descent) * lines) + margin + margin; /* GL texture sizes must be powers of two. */ { int w2 = to_pow2(width); int h2 = to_pow2(height); xoff = (w2 - width) / 2; yoff = (h2 - height) / 2; width = w2; height = h2; } bitmap = XCreatePixmap(dpy, RootWindowOfScreen (screen), width, height, 1); gcv.font = f->fid; gcv.foreground = bg; gc = XCreateGC (dpy, bitmap, (GCFont | GCForeground), &gcv); XFillRectangle(dpy, bitmap, gc, 0, 0, width, height); XSetForeground(dpy, gc, fg); token = text2; lines = 0; while ((line = strtok(token, "\r\n"))) { XCharStruct o2; int ascent, descent, direction; token = 0; XTextExtents(f, line, strlen(line), &direction, &ascent, &descent, &o2); XDrawString(dpy, bitmap, gc, overall.lbearing + margin + xoff, ((f->ascent * (lines + 1)) + (f->descent * lines) + margin + yoff), line, strlen(line)); lines++; } free(text2); XUnloadFont(dpy, f->fid); XFree((XPointer) f); XFreeGC(dpy, gc); } /* Convert the server-side Pixmap to a client-side GL-ordered XImage. */ { XImage *ximage1, *ximage2; unsigned long fg, bg; int x, y; ximage1 = XGetImage (dpy, bitmap, 0, 0, width, height, ~0L, ZPixmap); XFreePixmap(dpy, bitmap); ximage2 = XCreateImage (dpy, visual, 32, ZPixmap, 0, 0, width, height, 32, 0); ximage2->data = (char *) malloc (height * ximage2->bytes_per_line); /* Translate the 1-bit image to a deep image: first figure out what the colors are. */ { int rpos, gpos, bpos, apos; /* bitfield positions */ /* Note that unlike X, which is endianness-agnostic (since any XImage can have its own specific bit ordering, with the server reversing things as necessary) OpenGL pretends everything is client-side, so we need to pack things in the right order for the client machine. */ #if 0 /* #### Cherub says that the little-endian case must be taken on MacOSX, or else the colors/alpha are the wrong way around. How can that be the case? */ if (bigendian()) rpos = 24, gpos = 16, bpos = 8, apos = 0; else #endif rpos = 0, gpos = 8, bpos = 16, apos = 24; fg = (((unsigned long) (texture_fg[0] * 255.0) << rpos) | ((unsigned long) (texture_fg[1] * 255.0) << gpos) | ((unsigned long) (texture_fg[2] * 255.0) << bpos) | ((unsigned long) (texture_fg[3] * 255.0) << apos)); bg = (((unsigned long) (texture_bg[0] * 255.0) << rpos) | ((unsigned long) (texture_bg[1] * 255.0) << gpos) | ((unsigned long) (texture_bg[2] * 255.0) << bpos) | ((unsigned long) (texture_bg[3] * 255.0) << apos)); } for (y = 0; y < height; y++) { int y2 = (height-1-y); /* Texture maps are upside down. */ for (x = 0; x < width; x++) XPutPixel (ximage2, x, y, XGetPixel (ximage1, x, y2) ? fg : bg); } XDestroyImage (ximage1); #if 0 for (y = 0; y < height; y++) { int y2 = (height-1-y); /* Texture maps are upside down. */ for (x = 0; x < width; x++) fputc ((XGetPixel (ximage2, x, y2) == fg ? '#' : ' '), stdout); fputc ('\n', stdout); } fputc ('\n', stdout); #endif /* 0 */ return ximage2; } }
/* * Draws the 4 confidence values produced by Solexa in their +/- log-odds * encoding. * * NB: Only works when trace editing hasn't been performed */ void trace_draw_confidence4(DNATrace *t, Display *d, Pixmap p, int x0, int xn, int height) { int ind, x1, fw, cfh, cfw; char b[5]; double pos; if (!p || t->Ned <= 0) return; x1 = x0 + xn < t->read->NPoints ? x0+xn : t->read->NPoints - 1; x1 = t->tracePos[x1] + 1; if (x1 >= t->read->NBases) x1--; x1 = t->read->basePos[x1]; ind = t->tracePosE[x0]; /* Index of first base on screen */ fw = t->font_width/2 + 1; cfh = t->conf_font_height; cfw = t->conf_font_width; while (ind < t->read->NBases && (pos = trace_get_pos(t, ind)) <= x1) { int conf; int edind; double xoff; /* Called confidence value */ conf = (signed char)(t->edConf[ind]); if (conf < 100) sprintf(b, "%02d", conf); else strcpy(b, "XX"); xoff = 0; switch (t->read->base[ind]) { case 'A': case 'a': xoff = 0.00; break; case 'C': case 'c': xoff = 0.15; break; case 'G': case 'g': xoff = 0.30; break; case 'T': case 't': xoff = 0.45; break; } Tk_DrawChars(d, p, t->ConfGC, t->conf_font, b, 2, point_to_pixel(t, pos + xoff)-fw, cfh); /* Graphics bars for 4 confidence values */ edind = t->edPos[ind]; pos = point_to_pixel(t, pos); if (edind) { int i; for (i = 0; i < 4; i++, pos += .15 * t->scale_x) { int v; switch(i) { case 0: v = t->read->prob_A[ind]; break; case 1: v = t->read->prob_C[ind]; break; case 2: v = t->read->prob_G[ind]; break; case 3: v = t->read->prob_T[ind]; break; } if (v >= 0) XFillRectangle(d, p, t->ConfGC, pos-fw, cfh+30-v, cfw, v); else XFillRectangle(d, p, t->ConfNegGC, pos, cfh+30, 3, -v); /* if (v >= 0) XFillRectangle(d, p, t->ConfGC, pos-1, cfh, 5, v); else XFillRectangle(d, p, t->ConfNegGC, pos, cfh, 3, -v); */ } } ind++; } }
/* * Draw the edited seq. from pixel coordinates (x,y) to (x+width, y+height). */ void trace_draw_edits(DNATrace *t, Display *d, Pixmap p, int x0, int xn, int yoff, int height) { int ind, pos, x1, fw, fh; if( !p || !t || !t->read || (t->read->NBases==0) ) return; x0 -= 4; if (x0 < 0) x0 = 0; xn += 8; x1 = x0 + xn < t->read->NPoints ? x0+xn : t->read->NPoints - 1; x1 = t->tracePos[x1] + 1; if (x1 >= t->read->NBases) x1--; x1 = t->read->basePos[x1]; ind = t->tracePosE[x0]; /* Index of first base on screen */ fw = t->font_width/2 + 1; fh = t->fm.ascent + yoff; while (ind < t->Ned && (pos = trace_get_pos(t, ind)) <= x1) { char base; GC gc; base = t->edBases[ind]; switch (base) { case 'A': case 'a': gc = t->Agc; break; case 'C': case 'c': gc = t->Cgc; break; case 'G': case 'g': gc = t->Ggc; break; case 'T': case 't': gc = t->Tgc; break; default: gc = t->CursorGC; } /* XDrawString(d, p, gc, point_to_pixel(t, pos) - fw, fh, &base, 1); */ Tk_DrawChars(d, p, gc, t->font, &base, 1, point_to_pixel(t, pos) - fw, fh); ind++; } /* Cursor */ if (t->cursor_pos > 0) pos = trace_get_pos(t, t->cursor_pos-1); else pos = 0; XFillRectangle(d, p, t->CursorGC, point_to_pixel(t, pos)+4, t->fm.linespace-3, 8, 3); }
int radium_main(char *arg){ struct Tracker_Windows *window; #if 0 // Seems to be some kind of problem when running givertcap? Try to uncomment and // see if you can start radium without segfaulting. I can't. -Kjetil. system("/usr/bin/givertcap"); #endif x11_display=XOpenDisplay(NULL); if(x11_display==NULL){ fprintf(stderr, "Unable to open display \"%s\"\n",XDisplayName(NULL)); return 1; } XSetIOErrorHandler (MySysErrorHandler); x11_screen=DefaultScreen(x11_display); printf("arg: -%s-\n",arg); printf("Width/Height: %d/%d\n",DisplayWidth(x11_display,x11_screen),DisplayHeight(x11_display,x11_screen)); X11_init_keyboard(); X11_StartBlockSelector(); X11_StartMidiProperties(); StartGuiThread(); posix_InitPlayer(); if(InitProgram()==true){ /* Here: More inits, receive events, other things. */ bool notend=true; printf("Inited\n"); XFlush(x11_display); // DrawUpTrackerWindow(root->song->tracker_windows); //XFlush(x11_display); window=root->song->tracker_windows; //GFX_StartFileRequester(); X11_StartQtStuff(); BS_UpdateBlockList(); BS_UpdatePlayList(); BS_SelectBlock(root->song->blocks); BS_SelectPlaylistPos(0); if(strlen(arg)>0) Load(arg); lockGUI(); while(notend==true){ int fd; fd_set fdset; XFlush(x11_display); fd=ConnectionNumber(x11_display); FD_ZERO(&fdset); FD_SET(fd,&fdset); unlockGUI(); while((fd=select(fd+1,&fdset,NULL,NULL,NULL)==-1)){ if(errno!=EINTR) break; } lockGUI(); while(XPending(x11_display)) { XEvent event; XNextEvent(x11_display, &event); //XNextEvent (x11_display, &event); window=root->song->tracker_windows; //P2MUpdateSongPosCallBack(); switch(event.type){ case KeyPress: if(X11_KeyPress((XKeyEvent *)&event,window)==1){ notend=false; } break; case KeyRelease: X11_KeyRelease((XKeyEvent *)&event,window); break; case ButtonPress: //printf("%d %d %d\n",((XButtonEvent *)&event)->x,((XButtonEvent *)&event)->y,((XButtonEvent *)&event)->button); switch(((XButtonEvent *)&event)->button){ case 1: tevent.ID=TR_LEFTMOUSEDOWN; break; case 2: tevent.ID=TR_MIDDLEMOUSEDOWN; break; case 3: tevent.ID=TR_RIGHTMOUSEDOWN; break; case 4: tevent.ID=TR_KEYBOARD; tevent.SubID=EVENT_UPARROW; break; case 5: tevent.ID=TR_KEYBOARD; tevent.SubID=EVENT_DOWNARROW; break; default: tevent.ID=TR_LEFTMOUSEDOWN; } tevent.x=((XButtonEvent *)&event)->x; tevent.y=((XButtonEvent *)&event)->y; EventReciever(&tevent,window); break; case ButtonRelease: //printf("%d %d %d\n",((XButtonEvent *)&event)->x,((XButtonEvent *)&event)->y,((XButtonEvent *)&event)->button); switch(((XButtonEvent *)&event)->button){ case 1: tevent.ID=TR_LEFTMOUSEUP; break; case 2: tevent.ID=TR_MIDDLEMOUSEUP; break; case 3: tevent.ID=TR_RIGHTMOUSEUP; break; default: tevent.ID=TR_LEFTMOUSEUP; } tevent.x=((XButtonEvent *)&event)->x; tevent.y=((XButtonEvent *)&event)->y; EventReciever(&tevent,window); break; case EnterNotify: case LeaveNotify: X11_ResetKeysUpDowns(); break; case MotionNotify: // printf("%d %d %d\n",((XMotionEvent *)&event)->x,((XMotionEvent *)&event)->y,((XMotionEvent *)&event)->state); tevent.ID=TR_MOUSEMOVE; tevent.x=((XButtonEvent *)&event)->x; tevent.y=((XButtonEvent *)&event)->y; EventReciever(&tevent,window); break; //case VisibilityNotify: // case ConfigureNotify: case ConfigureNotify: if( window->width!=((XConfigureEvent *)&event)->width || window->height!=((XConfigureEvent *)&event)->height ) { #if 0 fprintf(stderr,"Resized %d %d\n", ((XConfigureEvent *)&event)->width, ((XConfigureEvent *)&event)->height ); #endif XFreePixmap( x11_display, window->os_visual->pixmap ); XFreePixmap( x11_display, window->os_visual->cursorpixmap ); window->os_visual->pixmap=XCreatePixmap(x11_display, window->os_visual->window, ((XConfigureEvent *)&event)->width, ((XConfigureEvent *)&event)->height, (unsigned int)(DefaultDepth(x11_display,x11_screen)) ); XFillRectangle( x11_display, window->os_visual->pixmap, window->os_visual->gcs[0], 0, 0, ((XConfigureEvent *)&event)->width,((XConfigureEvent *)&event)->height ); window->os_visual->cursorpixmap=XCreatePixmap(x11_display, window->os_visual->window, ((XConfigureEvent *)&event)->width, ((XConfigureEvent *)&event)->height, (unsigned int)(DefaultDepth(x11_display,x11_screen)) ); XFillRectangle( x11_display, window->os_visual->cursorpixmap, window->os_visual->gcs[0], 0, 0, ((XConfigureEvent *)&event)->width, ((XConfigureEvent *)&event)->height ); Resize_resized( window, ((XConfigureEvent *)&event)->width-1, ((XConfigureEvent *)&event)->height-1, true ); } break; case Expose: printf("Expose\n"); //GFX_FilledBox(window,0,0,0,window->width,window->height); //DrawUpTrackerWindow(root->song->tracker_windows); Resize_resized(window,window->width,window->height,false); //XFlush(x11_display); break; case NoExpose: break; case GraphicsExpose: printf("GRaphicsExpose event.\n"); break; case ClientMessage: X11Event_ClientMessage((XClientMessageEvent *)&event,window); // printf("Received \"%s\"\n",((XClientMessageEvent *)&event)->data.b); break; default: printf("Unknown xevent %d\n",event.type); break; } } } EndProgram(); } posix_EndPlayer(); unlockGUI(); EndGuiThread(); XCloseDisplay(x11_display); return 0; }
/* draw pixels for one frame in hires */ static void draw_hires(void) { int psize, x, y, i; BYTE *p = ram + dma_addr; /* set color or grayscale from lower nibble in graphics format */ i = format & 0x0f; if (format & 16) XSetForeground(display, gc, colors[i].pixel); else XSetForeground(display, gc, grays[i].pixel); if (format & 32) { /* 2048 bytes memory */ psize = size / 128; /* size of one pixel for 128x128 */ for (y = 0; y < 64; y += 2) { for (x = 0; x < 64;) { if (*p & 1) XFillRectangle(display, pixmap, gc, x * psize, y * psize, psize, psize); if (*p & 2) XFillRectangle(display, pixmap, gc, (x+1) * psize, y * psize, psize, psize); if (*p & 4) XFillRectangle(display, pixmap, gc, x * psize, (y+1) * psize, psize, psize); if (*p & 8) XFillRectangle(display, pixmap, gc, (x+1) * psize, (y+1) * psize, psize, psize); if (*p & 16) XFillRectangle(display, pixmap, gc, (x+2) * psize, y * psize, psize, psize); if (*p & 32) XFillRectangle(display, pixmap, gc, (x+3) * psize, y * psize, psize, psize); if (*p & 64) XFillRectangle(display, pixmap, gc, (x+2) * psize, (y+1) * psize, psize, psize); if (*p & 128) XFillRectangle(display, pixmap, gc, (x+3) * psize, (y+1) * psize, psize, psize); x += 4; p++; } } for (y = 0; y < 64; y += 2) { for (x = 64; x < 128;) { if (*p & 1) XFillRectangle(display, pixmap, gc, x * psize, y * psize, psize, psize); if (*p & 2) XFillRectangle(display, pixmap, gc, (x+1) * psize, y * psize, psize, psize); if (*p & 4) XFillRectangle(display, pixmap, gc, x * psize, (y+1) * psize, psize, psize); if (*p & 8) XFillRectangle(display, pixmap, gc, (x+1) * psize, (y+1) * psize, psize, psize); if (*p & 16) XFillRectangle(display, pixmap, gc, (x+2) * psize, y * psize, psize, psize); if (*p & 32) XFillRectangle(display, pixmap, gc, (x+3) * psize, y * psize, psize, psize); if (*p & 64) XFillRectangle(display, pixmap, gc, (x+2) * psize, (y+1) * psize, psize, psize); if (*p & 128) XFillRectangle(display, pixmap, gc, (x+3) * psize, (y+1) * psize, psize, psize); x += 4; p++; } } for (y = 64; y < 128; y += 2) { for (x = 0; x < 64;) { if (*p & 1) XFillRectangle(display, pixmap, gc, x * psize, y * psize, psize, psize); if (*p & 2) XFillRectangle(display, pixmap, gc, (x+1) * psize, y * psize, psize, psize); if (*p & 4) XFillRectangle(display, pixmap, gc, x * psize, (y+1) * psize, psize, psize); if (*p & 8) XFillRectangle(display, pixmap, gc, (x+1) * psize, (y+1) * psize, psize, psize); if (*p & 16) XFillRectangle(display, pixmap, gc, (x+2) * psize, y * psize, psize, psize); if (*p & 32) XFillRectangle(display, pixmap, gc, (x+3) * psize, y * psize, psize, psize); if (*p & 64) XFillRectangle(display, pixmap, gc, (x+2) * psize, (y+1) * psize, psize, psize); if (*p & 128) XFillRectangle(display, pixmap, gc, (x+3) * psize, (y+1) * psize, psize, psize); x += 4; p++; } } for (y = 64; y < 128; y += 2) { for (x = 64; x < 128;) { if (*p & 1) XFillRectangle(display, pixmap, gc, x * psize, y * psize, psize, psize); if (*p & 2) XFillRectangle(display, pixmap, gc, (x+1) * psize, y * psize, psize, psize); if (*p & 4) XFillRectangle(display, pixmap, gc, x * psize, (y+1) * psize, psize, psize); if (*p & 8) XFillRectangle(display, pixmap, gc, (x+1) * psize, (y+1) * psize, psize, psize); if (*p & 16) XFillRectangle(display, pixmap, gc, (x+2) * psize, y * psize, psize, psize); if (*p & 32) XFillRectangle(display, pixmap, gc, (x+3) * psize, y * psize, psize, psize); if (*p & 64) XFillRectangle(display, pixmap, gc, (x+2) * psize, (y+1) * psize, psize, psize); if (*p & 128) XFillRectangle(display, pixmap, gc, (x+3) * psize, (y+1) * psize, psize, psize); x += 4; p++; } } } else { /* 512 bytes memory */ psize = size / 64; /* size of one pixel for 64x64 */ for (y = 0; y < 64; y += 2) { for (x = 0; x < 64;) { if (*p & 1) XFillRectangle(display, pixmap, gc, x * psize, y * psize, psize, psize); if (*p & 2) XFillRectangle(display, pixmap, gc, (x+1) * psize, y * psize, psize, psize); if (*p & 4) XFillRectangle(display, pixmap, gc, x * psize, (y+1) * psize, psize, psize); if (*p & 8) XFillRectangle(display, pixmap, gc, (x+1) * psize, (y+1) * psize, psize, psize); if (*p & 16) XFillRectangle(display, pixmap, gc, (x+2) * psize, y * psize, psize, psize); if (*p & 32) XFillRectangle(display, pixmap, gc, (x+3) * psize, y * psize, psize, psize); if (*p & 64) XFillRectangle(display, pixmap, gc, (x+2) * psize, (y+1) * psize, psize, psize); if (*p & 128) XFillRectangle(display, pixmap, gc, (x+3) * psize, (y+1) * psize, psize, psize); x += 4; p++; } } } }
/* text field drawing */ void DrawTextField(struct XObj *xobj) { int x1,y1; int x2,l; int desc,dir,asc; XCharStruct struc; int nl=0; int right=0; l=strlen(xobj->title); if (xobj->value>l) xobj->value=l; if (xobj->value2>l) xobj->value2=l; DrawReliefRect(0,0,xobj->width,xobj->height,xobj,shad,hili); XClearArea(dpy,xobj->win,2,2,xobj->width-4,xobj->height-4,False); XSetForeground(dpy,xobj->gc,xobj->TabColor[fore]); XTextExtents(xobj->xfont,"lp",strlen("lp"),&dir,&y1,&desc,&struc); /* calcul du premier caractere visible */ /* computation of the first visible character */ while (l-nl >= 1 && XTextWidth(xobj->xfont,xobj->title + nl, xobj->value - nl) > (xobj->width-10)) { nl++; } if (nl>xobj->value3) { xobj->value3 = nl; } else if (xobj->value3>xobj->value) { xobj->value3--; } /* calcul de la longueur du titre visible */ /* computation of the length of the visible title */ while ( l-xobj->value3-right >= 1 && XTextWidth(xobj->xfont,xobj->title + xobj->value3, l - xobj->value3 - right) > (xobj->width-10)) { right++; } #ifdef I18N_MB XmbDrawString(dpy,xobj->win,xobj->xfontset,xobj->gc,5,y1+5, xobj->title + xobj->value3, strlen(xobj->title) - xobj->value3-right); #else XDrawString(dpy,xobj->win,xobj->gc,5,y1+5,xobj->title+xobj->value3, strlen(xobj->title) - xobj->value3-right); #endif /* Dessin de la zone selectionnee */ /* selected zone drawing */ XSetFunction(dpy,xobj->gc,GXinvert); if (xobj->value2>xobj->value) /* Curseur avant la souris */ { x1=XTextWidth(xobj->xfont,&xobj->title[xobj->value3], xobj->value - xobj->value3); x2=XTextWidth(xobj->xfont,&xobj->title[xobj->value], xobj->value2 - xobj->value); } else /* Curseur apres la souris / cursor after the mouse */ { x1=XTextWidth(xobj->xfont,&xobj->title[xobj->value3], xobj->value2 - xobj->value3); x2=XTextWidth(xobj->xfont,&xobj->title[xobj->value2], xobj->value - xobj->value2); } XTextExtents(xobj->xfont,"lp",strlen("lp"),&dir,&asc,&desc,&struc); XFillRectangle(dpy,xobj->win,xobj->gc,x1+5,7,x2,y1+desc-2); XSetFunction(dpy,xobj->gc,GXcopy); /* Dessin du point d'insertion */ /* insertion point drawing */ DrawPointTxt(xobj,xobj->TabColor[fore]); }
static void init_map (struct state *st) { XGCValues gcv; XGetWindowAttributes (st->dpy, st->window, &st->xgwa); st->cmap = st->xgwa.colormap; st->flip_x = (random() % 2); st->flip_xy = (random() % 2); if (mono_p) st->flip_xy = 0; else if (st->colors) { free_colors (st->xgwa.screen, st->cmap, st->colors, st->ncolors); free (st->colors); } st->colors = 0; st->ncolors = get_integer_resource (st->dpy, "ncolors", "Integer"); st->delay = get_integer_resource (st->dpy, "delay", "Integer"); st->delay2 = get_integer_resource (st->dpy, "delay2", "Integer"); st->iterations = get_integer_resource (st->dpy, "iterations", "Integer"); if (st->iterations < 0) st->iterations = 0; else if (st->iterations > 7) st->iterations = 7; if (st->ncolors <= 2) st->ncolors = 0; if (st->ncolors == 0) mono_p = True; if (st->ncolors > 255) st->ncolors = 255; /* too many look bad */ if (!st->gc) st->gc = XCreateGC (st->dpy, st->window, 0, &gcv); if (!st->gc2) st->gc2 = XCreateGC (st->dpy, st->window, 0, &gcv); if (mono_p) st->extra_krinkly_p = !(random() % 15); else st->extra_krinkly_p = !(random() % 5); if (!mono_p) { if (st->ncolors < 1) st->ncolors = 1; if (st->colors) free (st->colors); st->colors = (XColor *) malloc (st->ncolors * sizeof(*st->colors)); make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->cmap, st->colors, &st->ncolors, True, 0, False); if (st->ncolors <= 2) mono_p = 1; } if (mono_p) { int i; unsigned long fg_pixel = get_pixel_resource (st->dpy, st->xgwa.colormap, "foreground", "Foreground"); unsigned long bg_pixel = get_pixel_resource (st->dpy, st->xgwa.colormap, "background", "Background"); if (!st->colors) { st->ncolors = 50; st->colors = (XColor *) calloc (st->ncolors, sizeof(*st->colors)); } st->colors[0].pixel = fg_pixel; for (i = 1; i < st->ncolors; i++) st->colors[i].pixel = bg_pixel; } XSetForeground (st->dpy, st->gc, st->colors[1].pixel); XFillRectangle (st->dpy, st->window, st->gc, 0, 0, st->xgwa.width, st->xgwa.height); if (st->flip_xy) { st->xmax = st->xgwa.height; st->ymax = st->xgwa.width; } else { st->xmax = st->xgwa.width; st->ymax = st->xgwa.height; } if (st->cell) free (st->cell); st->cell = (signed char *) calloc (st->xmax * st->ymax, 1); CELL (0, 0) = 0; st->xstep = COUNT; st->ystep = COUNT; st->iteration = 0; st->cx = 0; }
static bool resize(struct vo *vo) { struct priv *p = vo->priv; struct vo_x11_state *x11 = vo->x11; for (int i = 0; i < 2; i++) freeMyXImage(p, i); vo_get_src_dst_rects(vo, &p->src, &p->dst, &p->osd); p->src_w = p->src.x1 - p->src.x0; p->src_h = p->src.y1 - p->src.y0; p->dst_w = p->dst.x1 - p->dst.x0; p->dst_h = p->dst.y1 - p->dst.y0; // p->osd contains the parameters assuming OSD rendering in window // coordinates, but OSD can only be rendered in the intersection // between window and video rectangle (i.e. not into panscan borders). p->osd.w = p->dst_w; p->osd.h = p->dst_h; p->osd.mt = MPMIN(0, p->osd.mt); p->osd.mb = MPMIN(0, p->osd.mb); p->osd.mr = MPMIN(0, p->osd.mr); p->osd.ml = MPMIN(0, p->osd.ml); mp_input_set_mouse_transform(vo->input_ctx, &p->dst, NULL); p->image_width = (p->dst_w + 7) & (~7); p->image_height = p->dst_h; for (int i = 0; i < 2; i++) { if (!getMyXImage(p, i)) return -1; } const struct fmt_entry *fmte = mp_to_x_fmt; while (fmte->mpfmt) { if (fmte->depth == p->myximage[0]->bits_per_pixel && fmte->byte_order == p->myximage[0]->byte_order && fmte->red_mask == p->myximage[0]->red_mask && fmte->green_mask == p->myximage[0]->green_mask && fmte->blue_mask == p->myximage[0]->blue_mask) break; fmte++; } if (!fmte->mpfmt) { MP_ERR(vo, "X server image format not supported, use another VO.\n"); return -1; } mp_sws_set_from_cmdline(p->sws, vo->opts->sws_opts); p->sws->dst = (struct mp_image_params) { .imgfmt = fmte->mpfmt, .w = p->dst_w, .h = p->dst_h, .p_w = 1, .p_h = 1, }; mp_image_params_guess_csp(&p->sws->dst); if (mp_sws_reinit(p->sws) < 0) return false; XFillRectangle(x11->display, x11->window, p->gc, 0, 0, vo->dwidth, vo->dheight); vo->want_redraw = true; return true; } static void Display_Image(struct priv *p, XImage *myximage) { struct vo *vo = p->vo; XImage *x_image = p->myximage[p->current_buf]; #if HAVE_SHM && HAVE_XEXT if (p->Shmem_Flag) { XShmPutImage(vo->x11->display, vo->x11->window, p->gc, x_image, 0, 0, p->dst.x0, p->dst.y0, p->dst_w, p->dst_h, True); vo->x11->ShmCompletionWaitCount++; } else #endif { XPutImage(vo->x11->display, vo->x11->window, p->gc, x_image, 0, 0, p->dst.x0, p->dst.y0, p->dst_w, p->dst_h); } } static struct mp_image get_x_buffer(struct priv *p, int buf_index) { struct mp_image img = {0}; mp_image_set_params(&img, &p->sws->dst); img.planes[0] = p->myximage[buf_index]->data; img.stride[0] = p->image_width * ((p->myximage[buf_index]->bits_per_pixel + 7) / 8); return img; } static void wait_for_completion(struct vo *vo, int max_outstanding) { #if HAVE_SHM && HAVE_XEXT struct priv *ctx = vo->priv; struct vo_x11_state *x11 = vo->x11; if (ctx->Shmem_Flag) { while (x11->ShmCompletionWaitCount > max_outstanding) { if (!ctx->Shm_Warned_Slow) { MP_WARN(vo, "can't keep up! Waiting" " for XShm completion events...\n"); ctx->Shm_Warned_Slow = 1; } mp_sleep_us(1000); vo_x11_check_events(vo); } } #endif } static void flip_page(struct vo *vo) { struct priv *p = vo->priv; Display_Image(p, p->myximage[p->current_buf]); p->current_buf = (p->current_buf + 1) % 2; } // Note: REDRAW_FRAME can call this with NULL. static void draw_image(struct vo *vo, mp_image_t *mpi) { struct priv *p = vo->priv; wait_for_completion(vo, 1); struct mp_image img = get_x_buffer(p, p->current_buf); if (mpi) { struct mp_image src = *mpi; struct mp_rect src_rc = p->src; src_rc.x0 = MP_ALIGN_DOWN(src_rc.x0, src.fmt.align_x); src_rc.y0 = MP_ALIGN_DOWN(src_rc.y0, src.fmt.align_y); mp_image_crop_rc(&src, src_rc); mp_sws_scale(p->sws, &img, &src); } else { mp_image_clear(&img, 0, 0, img.w, img.h); } osd_draw_on_image(vo->osd, p->osd, mpi ? mpi->pts : 0, 0, &img); if (mpi != p->original_image) { talloc_free(p->original_image); p->original_image = mpi; } } static int query_format(struct vo *vo, int format) { if (sws_isSupportedInput(imgfmt2pixfmt(format))) return 1; return 0; } static void uninit(struct vo *vo) { struct priv *p = vo->priv; if (p->myximage[0]) freeMyXImage(p, 0); if (p->myximage[1]) freeMyXImage(p, 1); if (p->gc) XFreeGC(vo->x11->display, p->gc); talloc_free(p->original_image); vo_x11_uninit(vo); } static int preinit(struct vo *vo) { struct priv *p = vo->priv; p->vo = vo; p->sws = mp_sws_alloc(vo); if (!vo_x11_init(vo)) goto error; struct vo_x11_state *x11 = vo->x11; XWindowAttributes attribs; XGetWindowAttributes(x11->display, x11->rootwin, &attribs); p->depth = attribs.depth; if (!XMatchVisualInfo(x11->display, x11->screen, p->depth, TrueColor, &p->vinfo)) goto error; MP_VERBOSE(vo, "selected visual: %d\n", (int)p->vinfo.visualid); if (!vo_x11_create_vo_window(vo, &p->vinfo, "x11")) goto error; p->gc = XCreateGC(x11->display, x11->window, 0, NULL); MP_WARN(vo, "Warning: this legacy VO has bad performance. Consider fixing " "your graphics drivers, or not forcing the x11 VO.\n"); return 0; error: uninit(vo); return -1; } static int control(struct vo *vo, uint32_t request, void *data) { struct priv *p = vo->priv; switch (request) { case VOCTRL_SET_PANSCAN: if (vo->config_ok) resize(vo); return VO_TRUE; case VOCTRL_REDRAW_FRAME: draw_image(vo, p->original_image); return true; } int events = 0; int r = vo_x11_control(vo, &events, request, data); if (vo->config_ok && (events & (VO_EVENT_EXPOSE | VO_EVENT_RESIZE))) resize(vo); vo_event(vo, events); return r; } const struct vo_driver video_out_x11 = { .description = "X11 (slow, old crap)", .name = "x11", .priv_size = sizeof(struct priv), .preinit = preinit, .query_format = query_format, .reconfig = reconfig, .control = control, .draw_image = draw_image, .flip_page = flip_page, .wakeup = vo_x11_wakeup, .wait_events = vo_x11_wait_events, .uninit = uninit, };
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text) { char buf[1024]; int tx, ty, th; Extnts tex; XftDraw *d = NULL; Fnt *curfont, *nextfont; size_t i, len; int utf8strlen, utf8charlen, render; long utf8codepoint = 0; const char *utf8str; FcCharSet *fccharset; FcPattern *fcpattern; FcPattern *match; XftResult result; int charexists = 0; if (!drw->scheme || !drw->fontcount) return 0; if (!(render = x || y || w || h)) { w = ~w; } else { XSetForeground(drw->dpy, drw->gc, drw->scheme->bg->pix); XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); d = XftDrawCreate(drw->dpy, drw->drawable, DefaultVisual(drw->dpy, drw->screen), DefaultColormap(drw->dpy, drw->screen)); } curfont = drw->fonts[0]; while (1) { utf8strlen = 0; utf8str = text; nextfont = NULL; while (*text) { utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ); for (i = 0; i < drw->fontcount; i++) { charexists = charexists || XftCharExists(drw->dpy, drw->fonts[i]->xfont, utf8codepoint); if (charexists) { if (drw->fonts[i] == curfont) { utf8strlen += utf8charlen; text += utf8charlen; } else { nextfont = drw->fonts[i]; } break; } } if (!charexists || (nextfont && nextfont != curfont)) break; else charexists = 0; } if (utf8strlen) { drw_font_getexts(curfont, utf8str, utf8strlen, &tex); /* shorten text if necessary */ for (len = MIN(utf8strlen, (sizeof buf) - 1); len && (tex.w > w - drw->fonts[0]->h || w < drw->fonts[0]->h); len--) drw_font_getexts(curfont, utf8str, len, &tex); if (len) { memcpy(buf, utf8str, len); buf[len] = '\0'; if (len < utf8strlen) for (i = len; i && i > len - 3; buf[--i] = '.'); if (render) { th = curfont->ascent + curfont->descent; ty = y + (h / 2) - (th / 2) + curfont->ascent; tx = x + (h / 2); XftDrawStringUtf8(d, &drw->scheme->fg->rgb, curfont->xfont, tx, ty, (XftChar8 *)buf, len); } x += tex.w; w -= tex.w; } } if (!*text) { break; } else if (nextfont) { charexists = 0; curfont = nextfont; } else { /* Regardless of whether or not a fallback font is found, the * character must be drawn. */ charexists = 1; if (drw->fontcount >= DRW_FONT_CACHE_SIZE) continue; fccharset = FcCharSetCreate(); FcCharSetAddChar(fccharset, utf8codepoint); if (!drw->fonts[0]->pattern) { /* Refer to the comment in drw_font_xcreate for more * information. */ die("the first font in the cache must be loaded from a font string.\n"); } fcpattern = FcPatternDuplicate(drw->fonts[0]->pattern); FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset); FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue); FcConfigSubstitute(NULL, fcpattern, FcMatchPattern); FcDefaultSubstitute(fcpattern); match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result); FcCharSetDestroy(fccharset); FcPatternDestroy(fcpattern); if (match) { curfont = drw_font_xcreate(drw, NULL, match); if (curfont && XftCharExists(drw->dpy, curfont->xfont, utf8codepoint)) { drw->fonts[drw->fontcount++] = curfont; } else { drw_font_free(curfont); curfont = drw->fonts[0]; } } } } if (d) XftDrawDestroy(d); return x; }
void XImlib2Background::SetMultiImage(Imlib_Image image) { Pixmap pmap = None, mask = None; GC gc; XGCValues gcv; XColor xcolor; int w, h, x, y, widthOfScreen, heightOfScreen, screen, depth; char *bgcolor = NULL; Colormap colormap; Display* display; Window rootWindow; string mode; DesktopConfig * dConfig = dynamic_cast<DesktopConfig *>(config); XDesktopContainer * xContainer = dynamic_cast<XDesktopContainer *>(container); display = xContainer->getDisplay(); rootWindow = xContainer->getRootWindow(); screen = DefaultScreen(display); depth = DefaultDepth(display, screen); colormap = DefaultColormap(display, screen); widthOfScreen = xContainer->widthOfScreen(); heightOfScreen = xContainer->heightOfScreen(); mode = dConfig->getModeBackground(); pixmap = XCreatePixmap(display, rootWindow , widthOfScreen, heightOfScreen, depth); string color = dConfig->getColorBackground(); if(color != "None"){ gcv.foreground = gcv.background = BlackPixel(display, screen); bgcolor = (char*)dConfig->getColorBackground().c_str(); if (bgcolor && XParseColor(display, colormap , bgcolor, &xcolor) && XAllocColor(display, colormap, &xcolor)) { gcv.foreground = gcv.background = xcolor.pixel; } } gc = XCreateGC(display, pixmap, (GCForeground | GCBackground), &gcv); if(image){ imlib_context_set_image(image); if (mode == "SCALE") { w = widthOfScreen; h = heightOfScreen; } else if (mode == "MIRROR") { w = imlib_image_get_width() * 2; h = imlib_image_get_height() * 2; } else if (mode == "FIT") { double x_ratio, y_ratio; x_ratio = ((double) widthOfScreen) / ((double) imlib_image_get_width()); y_ratio = ((double) heightOfScreen) / ((double) imlib_image_get_height()); if (x_ratio > y_ratio) { x_ratio = y_ratio; } w = (int) (imlib_image_get_width() * x_ratio); h = (int) (imlib_image_get_height() * x_ratio); } else { w = imlib_image_get_width(); h = imlib_image_get_height(); } if (mode == "SCALE") { XFillRectangle(display, pixmap, gc, 0, 0, w, h); } if (mode == "CENTER" || mode == "FIT") { XFillRectangle(display, pixmap, gc, 0, 0, widthOfScreen, heightOfScreen); x = (widthOfScreen - w) >> 1; y = (heightOfScreen - h) >> 1; } else {
void bar3d(int left, int top, int right, int bottom, int depth, int topflag) { int X; int Y; int temp; int width; int height; XPoint *points; XPoint *xptr; int i; if (left > right) { /* Turbo C corrects for badly ordered corners */ temp = left; left = right; right = temp; } if (bottom < top) { temp = bottom; bottom = top; top = temp; } X = left + VPorigin.x; Y = top + VPorigin.y; width = right - left + 1; height = bottom - top + 1; XFillRectangle(dpy, drawable, fill_gc, X, Y, width + 1, height + 1); if (visual_page == active_page) XFillRectangle(dpy, window, fill_gc, X, Y, width + 1, height + 1); XDrawRectangle(dpy, drawable, gc, X, Y, width, height); if (visual_page == active_page) XDrawRectangle(dpy, window, gc, X, Y, width, height); points = (XPoint *) malloc(4 * sizeof(XPoint)); /* 4 per lozenge */ for (i = 0, xptr = points; i < 4; i++, xptr++) { switch (i) { case 0: xptr->x = right + VPorigin.x; xptr->y = bottom + VPorigin.y; break; case 1: xptr->x = depth; xptr->y = -depth; break; case 2: xptr->x = 0; xptr->y = -height; break; case 3: xptr->x = -depth; xptr->y = depth; break; default: break; } } XDrawLines(dpy, drawable, gc, points, 4, CoordModePrevious); if (visual_page == active_page) XDrawLines(dpy, window, gc, points, 4, CoordModePrevious); free(points); if (topflag) { points = (XPoint *) malloc(3 * sizeof(XPoint)); for (i = 0, xptr = points; i < 3; i++, xptr++) { switch (i) { case 0: xptr->x = left + VPorigin.x; xptr->y = top + VPorigin.y; break; case 1: xptr->x = depth; xptr->y = -depth; break; case 2: xptr->x = width; xptr->y = 0; break; default: break; } } XDrawLines(dpy, drawable, gc, points, 3, CoordModePrevious); if (visual_page == active_page) XDrawLines(dpy, window, gc, points, 3, CoordModePrevious); free(points); } XFlush(dpy); }
int video_set(PLOT *plot) { struct videodata *plotdata = (struct videodata *)plot->plotdata; GROUP *group = plot->group; Display *dpy = XtDisplay(plot->plot_widget); Widget w = (Widget)plot->plot_widget; Dimension height, width; Window root_return; int x_return, y_return; unsigned int pixwidth, pixheight, border_width_return, depth_return; unsigned long long ntime; int haschanged = 0; /* ** We do this here because the window must be realized to grab the mouse ** it isn't realized during the call to video_open(). */ if (plotdata->butgrabbed == FALSE) { XGrabButton(dpy, AnyButton, AnyModifier, XtWindow(w), TRUE, ButtonPressMask | ButtonReleaseMask | Button2MotionMask, GrabModeAsync, GrabModeAsync, XtWindow(w), XCreateFontCursor(dpy, XC_crosshair)); plotdata->butgrabbed = TRUE; } /* ** Retrieve the window size ** ** The check here for height > 65000 is a workaround for a Motif bug. ** When I select 2 files and draw a video for each, then the second one ** gets a size of 65518 - which is presumably an error */ XtVaGetValues(w, XmNheight, &height, XmNwidth, &width, NULL); if ((height > 65000) || (height < 10)) return SUCCESS; plot->width = width; plot->height = height; /* ** If the window size has changed, we need to reallocate the ** pixmap. */ XGetGeometry(dpy, plotdata->pixmap, &root_return, &x_return, &y_return, &pixwidth, &pixheight, &border_width_return, &depth_return); if ((pixheight != height) || (pixwidth != width)) { if (plotdata->pixmapalloced) XFreePixmap(dpy, plotdata->pixmap); plotdata->pixmap = XCreatePixmap(dpy, DefaultRootWindow(dpy), width, height, plot->depth); plotdata->pixmapalloced = TRUE; haschanged++; } XFillRectangle(dpy, plotdata->pixmap, plotdata->inverse_GC, 0, 0, width, height); /* ** Clear any marks */ plot->playmark = -1; plot->markx1 = -1; plot->markx2 = -1; /* ** Load the desired frame */ if (plotdata->framenum != plotdata->loadedframenum) { if (vid_read(group->vidfp, plotdata->framenum, plotdata->framedata, &ntime) != 0) { fprintf(stderr, "Error reading frame #%d for file '%s'\n", plotdata->framenum, group->loadedfilename); } plotdata->loadedframenum = plotdata->framenum; haschanged++; } /* ** Do the rendering to an off-screen pixmap, then copy to the window. */ if (haschanged) { cursor_set_busy(toplevel); XPutImage(dpy, plotdata->pixmap, plotdata->drawing_GC, plotdata->image, 0, 0, 0, 0, width, height); XCopyArea(dpy, plotdata->pixmap, XtWindow(w), plotdata->drawing_GC, 0, 0, width, height, 0, 0); cursor_unset_busy(toplevel); } return SUCCESS; }
/********************************************************************************** * FUNCTIONS **********************************************************************************/ int video_open(PLOT *plot) { struct videodata *plotdata; Display *dpy; Screen *scr; Widget w, mw, m0, m1, m2, m3; int status = SUCCESS; Dimension width, height; int depth; XGCValues values; unsigned long foreground, background; XmString xmstr, xmstr1; Arg args[10]; int n; plot->plotdata = (void *)calloc(1, sizeof(struct videodata)); plotdata = (struct videodata *)plot->plotdata; plotdata->image = (XImage *)calloc(sizeof(XImage), 1); plotdata->framedata = NULL; plotdata->width = 0; plotdata->height = 0; plotdata->ncomps = 0; plotdata->microsecs_per_frame = 0; plotdata->colormap = defaults.colormap; plotdata->framenum = 0; plotdata->loadedframenum = -1; plot->plot_widget = XtVaCreateManagedWidget("video", xmDrawingAreaWidgetClass, plot->panel->panel_container, XmNheight, defaults.video_height, XmNwidth, defaults.width, XmNmarginHeight, 0, XmNmarginWidth, 0, NULL); XtAddCallback(plot->plot_widget, XmNexposeCallback, video_expose_callback, (XtPointer)plot); XtAddCallback(plot->plot_widget, XmNresizeCallback, video_resize_callback, (XtPointer)plot); w = (Widget)plot->plot_widget; dpy = XtDisplay(w); scr = XtScreen(w); XtVaGetValues(w, XmNheight, &height, XmNwidth, &width, XmNdepth, &depth, XmNforeground, &foreground, XmNbackground, &background, NULL); /* ** Get the font; also, calculate the margins for the axes (this depends on the font size!). ** Store these margins for use later (we might start off without axes, and turn them on later. */ plot->ticklblfont = XmFontListCopy(_XmGetDefaultFontList(w, XmLABEL_FONTLIST)); plot->minoffx = 6 + XmStringWidth(plot->ticklblfont, xmstr = XmStringCreateSimple("-32768")); XmStringFree(xmstr); plot->minoffx2 = 0; plot->minoffy = 0; plot->minoffy2 = 6 + XmStringHeight(plot->ticklblfont, xmstr = XmStringCreateSimple("1")); XmStringFree(xmstr); plot->offx = 0; plot->offy = 0; plot->offx2 = 0; plot->offy2 = 0; plot->width = width; plot->height = height; plot->depth = depth; /* ** Allocate our colors. We use the XCC code that is: ** Copyright 1994,1995 John L. Cwikla ** This allows us to work on any visual, etc. The danger is that ** we may not get the exact colors we ask for... meaning that things ** may not really be as we see them. This is unfortunate, but the ** alternative is to not run at all (the old code crashed). So... */ plotdata->ncolors = MIN(SONO_DEFAULT_MAX_COLORS, MIN(XDisplayCells(dpy, XDefaultScreen(dpy)), MAXCOLORS - RESERVED_COLORS)); plotdata->xcc = XCCCreate(dpy, DefaultVisual(dpy, DefaultScreen(dpy)), TRUE, TRUE, XA_RGB_GRAY_MAP, &(plotdata->cmap)); if (XCCGetNumColors(plotdata->xcc) < plotdata->ncolors) { plotdata->ncolors = XCCGetNumColors(plotdata->xcc); printf("Warning. Using only %d colors.\n", plotdata->ncolors); } (*((colormap[plotdata->colormap]).cmap))(dpy, plotdata->ncolors, plotdata->colors, NULL); /* ** Create the Graphics contexts. ** drawing_GC is for the picture itself. inverse_GC is for erasing. mark_GC is for the subregion marks. */ values.font = getFontStruct(plot->ticklblfont)->fid; values.function = GXcopy; values.plane_mask = AllPlanes; values.foreground = foreground; values.background = background; plotdata->drawing_GC = XtGetGC(w, GCFunction | GCPlaneMask | GCForeground | GCBackground | GCFont, &values); values.foreground = background; values.background = background; plotdata->inverse_GC = XtGetGC(w, GCForeground | GCBackground, &values); values.function = GXxor; values.plane_mask = foreground ^ background; values.foreground = 0xffffffff; values.background = 0x0; values.line_style = LineSolid; plotdata->mark_GC = XtGetGC(w, GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineStyle, &values); plotdata->pixmap = XCreatePixmap(dpy, DefaultRootWindow(dpy), width, height, depth); plotdata->pixmapalloced = TRUE; XFillRectangle(dpy, plotdata->pixmap, plotdata->inverse_GC, 0, 0, width, height); /* ** Create the popup menu ** */ n = 0; XtSetArg(args[n], XmNmenuPost, "<Btn3Down>"); n++; mw = plot->plot_popupmenu_widget = XmCreatePopupMenu(w, "popupmenu", args, n); m0 = XtVaCreateManagedWidget("m0", xmLabelGadgetClass, mw, XmNlabelString, xmstr1 = XmStringCreateSimple("Options"), NULL); XmStringFree(xmstr1); m1 = XtVaCreateManagedWidget("m1", xmSeparatorGadgetClass, mw, NULL); CreateMenuButton(m2, mw, "save", "Save", "Save"); CreateMenuButton(m3, mw, "print", "Print EPS", "Print EPS"); /* ** Register an event handler */ XtAddEventHandler(w, KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask | Button2MotionMask, FALSE, (XtEventHandler) video_event_handler, (XtPointer)plot); plot->plot_display = video_display; plot->plot_set = video_set; plot->plot_close = video_close; plot->plot_print = video_print; plot->plot_playmarker = NULL; plot->plot_showvideoframe = video_showvideoframe; plot->plot_clearmarks = NULL; plot->plot_drawstartmark = NULL; plot->plot_drawstopmark = NULL; plot->plot_conv_pixel_to_time = NULL; plot->plot_save = video_save; plot->plot_event_handler = video_event_handler; plot->plot_play = video_play; plotdata->butgrabbed = FALSE; plot->playmark = -1; plot->markx1 = -1; plot->markx2 = -1; plot->group->needpcm = 1; return status; }
static void * whirlygig_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); st->dpy = dpy; st->window = window; st->ncolors = NCOLORS; st->dbuf = get_boolean_resource (st->dpy, "doubleBuffer", "Boolean"); # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ st->dbuf = False; # endif st->start_time = st->current_time; st->info = (struct info *)malloc(sizeof(struct info)); st->screen = DefaultScreen(st->dpy); XGetWindowAttributes (st->dpy, st->window, &st->xgwa); if (st->dbuf) { #ifdef HAVE_DOUBLE_BUFFER_EXTENSION if (get_boolean_resource(st->dpy,"useDBE","Boolean")) { st->dbeclear_p = get_boolean_resource (st->dpy, "useDBEClear", "Boolean"); if (st->dbeclear_p) st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeBackground); else st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeUndefined); st->backb = st->b; } #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ if (!st->b) { st->ba = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height,st->xgwa.depth); st->b = st->ba; } } else { st->b = st->window; } st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap, "foreground", "Foreground"); st->fgc = XCreateGC (st->dpy, st->b, GCForeground, &st->gcv); st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap, "background", "Background"); st->bgc = XCreateGC (st->dpy, st->b, GCForeground, &st->gcv); #ifdef HAVE_COCOA /* #### should turn off double-buffering instead */ jwxyz_XSetAntiAliasing (dpy, st->fgc, False); jwxyz_XSetAntiAliasing (dpy, st->bgc, False); #endif { Bool writable_p = False; make_uniform_colormap (st->dpy, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, True, &writable_p, True); } if (st->ba) XFillRectangle (st->dpy, st->ba, st->bgc, 0, 0, st->xgwa.width, st->xgwa.height); /* info is a structure holding all the random pieces of information I may want to pass to my baby functions -- much of it I may never use, but it is nice to have around just in case I want it to make a funky function funkier */ /* info->writable = get_boolean_resource (dpy, "cycle", "Boolean"); */ st->info->xspeed = get_float_resource(st->dpy, "xspeed" , "Float"); st->info->yspeed = get_float_resource(st->dpy, "yspeed" , "Float"); st->info->xamplitude = get_float_resource(st->dpy, "xamplitude", "Float"); st->info->yamplitude = get_float_resource(st->dpy, "yamplitude", "Float"); st->info->offset_period = get_float_resource(st->dpy, "offset_period", "Float"); st->info->whirlies = get_integer_resource(st->dpy, "whirlies", "Integer"); st->info->nlines = get_integer_resource(st->dpy, "nlines", "Integer"); st->info->half_width = st->xgwa.width / 2; st->info->half_height = st->xgwa.height / 2; st->info->speed = get_integer_resource(st->dpy, "speed" , "Integer"); st->info->trail = get_boolean_resource(st->dpy, "trail", "Integer"); st->info->color_modifier = get_integer_resource(st->dpy, "color_modifier", "Integer"); st->info->xoffset = get_float_resource(st->dpy, "xoffset", "Float"); st->info->yoffset = get_float_resource(st->dpy, "yoffset", "Float"); st->xmode_str = get_string_resource(st->dpy, "xmode", "Mode"); st->ymode_str = get_string_resource(st->dpy, "ymode", "Mode"); st->wrap = get_boolean_resource(st->dpy, "wrap", "Boolean"); st->modifier = 3000.0 + frand(1500.0); if (! st->xmode_str) st->xmode = spin_mode; else if (! strcmp (st->xmode_str, "spin")) st->xmode = spin_mode; else if (! strcmp (st->xmode_str, "funky")) st->xmode = funky_mode; else if (! strcmp (st->xmode_str, "circle")) st->xmode = circle_mode; else if (! strcmp (st->xmode_str, "linear")) st->xmode = linear_mode; else if (! strcmp (st->xmode_str, "test")) st->xmode = test_mode; else if (! strcmp (st->xmode_str, "fun")) st->xmode = fun_mode; else if (! strcmp (st->xmode_str, "innie")) st->xmode = innie_mode; else if (! strcmp (st->xmode_str, "lissajous")) st->xmode = lissajous_mode; else { st->xmode = random() % (int) lissajous_mode; } if (! st->ymode_str) st->ymode = spin_mode; else if (! strcmp (st->ymode_str, "spin")) st->ymode = spin_mode; else if (! strcmp (st->ymode_str, "funky")) st->ymode = funky_mode; else if (! strcmp (st->ymode_str, "circle")) st->ymode = circle_mode; else if (! strcmp (st->ymode_str, "linear")) st->ymode = linear_mode; else if (! strcmp (st->ymode_str, "test")) st->ymode = test_mode; else if (! strcmp (st->ymode_str, "fun")) st->ymode = fun_mode; else if (! strcmp (st->ymode_str, "innie")) st->ymode = innie_mode; else if (! strcmp (st->ymode_str, "lissajous")) st->ymode = lissajous_mode; else { st->ymode = random() % (int) lissajous_mode; } if (get_integer_resource(st->dpy, "start_time", "Integer") == -1) st->current_time = (unsigned long int)(random()); else st->current_time = get_integer_resource(st->dpy, "start_time", "Integer"); if (st->info->whirlies == -1) st->info->whirlies = 1 + (random() % 15); if (st->info->nlines == -1) st->info->nlines = 1 + (random() % 5); if (st->info->color_modifier == -1) st->info->color_modifier = 1 + (random() % 25); if (get_boolean_resource(st->dpy, "explain", "Integer")) st->explaining = 1; st->current_color = 1 + (random() % NCOLORS); return st; }
void scrollbar_draw_anchor(unsigned char image_state, unsigned char force_modes) { D_SCROLLBAR(("scrollbar_draw_anchor(%u, 0x%02x)\n", (unsigned int) image_state, (unsigned int) force_modes)); if (image_state != IMAGE_STATE_CURRENT) { if ((image_state == IMAGE_STATE_NORMAL) && (images[image_sa].current != images[image_sa].norm)) { images[image_sa].current = images[image_sa].norm; force_modes = MODE_MASK; } else if ((image_state == IMAGE_STATE_SELECTED) && (images[image_sa].current != images[image_sa].selected)) { images[image_sa].current = images[image_sa].selected; force_modes = MODE_MASK; } else if ((image_state == IMAGE_STATE_CLICKED) && (images[image_sa].current != images[image_sa].clicked)) { images[image_sa].current = images[image_sa].clicked; force_modes = MODE_MASK; } else if ((image_state == IMAGE_STATE_DISABLED) && (images[image_sa].current != images[image_sa].disabled)) { images[image_sa].current = images[image_sa].disabled; force_modes = MODE_MASK; } if ((image_state == IMAGE_STATE_NORMAL) && (images[image_st].current != images[image_st].norm)) { images[image_st].current = images[image_st].norm; force_modes = MODE_MASK; } else if ((image_state == IMAGE_STATE_SELECTED) && (images[image_st].current != images[image_st].selected)) { images[image_st].current = images[image_st].selected; force_modes = MODE_MASK; } else if ((image_state == IMAGE_STATE_CLICKED) && (images[image_st].current != images[image_st].clicked)) { images[image_st].current = images[image_st].clicked; force_modes = MODE_MASK; } else if ((image_state == IMAGE_STATE_DISABLED) && (images[image_st].current != images[image_st].disabled)) { images[image_st].current = images[image_st].disabled; force_modes = MODE_MASK; } } if (!image_mode_is(image_sa, MODE_MASK)) { /* Solid mode. Redraw every time since it's cheap. */ #ifdef XTERM_SCROLLBAR if (scrollbar.type == SCROLLBAR_XTERM) { int x = ((BITFIELD_IS_SET(eterm_options, ETERM_OPTIONS_SCROLLBAR_RIGHT)) ? 1 : 0); XSetForeground(Xdisplay, gc_stipple, images[image_sa].current->bg); XFillRectangle(Xdisplay, scrollbar.sa_win, gc_stipple, x + 1, 0, scrollbar_anchor_width() - x - 1, scrollbar_anchor_height()); XClearWindow(Xdisplay, scrollbar.sa_win); } #endif /* XTERM_SCROLLBAR */ #if defined(MOTIF_SCROLLBAR) || defined(NEXT_SCROLLBAR) if (scrollbar.type == SCROLLBAR_MOTIF || scrollbar.type == SCROLLBAR_NEXT) { if (BITFIELD_IS_SET(eterm_options, ETERM_OPTIONS_SCROLLBAR_FLOATING)) { XSetWindowBackground(Xdisplay, scrollbar.sa_win, PixColors[bgColor]); XClearWindow(Xdisplay, scrollbar.sa_win); } else { XSetForeground(Xdisplay, gc_scrollbar, images[image_sa].current->bg); XFillRectangle(Xdisplay, scrollbar.sa_win, gc_scrollbar, 0, 0, scrollbar_anchor_width(), scrollbar_anchor_height()); } XSetForeground(Xdisplay, gc_top, get_top_shadow_color(images[image_sa].current->bg, "")); XSetForeground(Xdisplay, gc_bottom, get_bottom_shadow_color(images[image_sa].current->bg, "")); if (scrollbar_anchor_is_pressed()) { draw_shadow(scrollbar.sa_win, gc_bottom, gc_top, 0, 0, scrollbar_anchor_width(), scrollbar_anchor_height(), scrollbar_get_shadow()); } else { draw_shadow(scrollbar.sa_win, gc_top, gc_bottom, 0, 0, scrollbar_anchor_width(), scrollbar_anchor_height(), scrollbar_get_shadow()); } } #endif return; } if (!((images[image_sa].mode & MODE_MASK) & (force_modes))) { return; } if (scrollbar_anchor_height() > 1) { unsigned char thumb; Pixmap pmap; thumb = (images[image_st].current->iml) ? 1 : 0; render_simage(images[image_sa].current, scrollbar.sa_win, scrollbar_anchor_width(), scrollbar_anchor_height(), image_sa, thumb); pmap = images[image_sa].current->pmap->pixmap; /* Draw the thumb if there is one. */ if (thumb) { unsigned short tw = 0, th = 0; imlib_t *iml = images[image_st].current->iml, *siml = images[image_sa].current->iml; if (image_mode_is(image_st, MODE_IMAGE) && iml->im) { #ifdef PIXMAP_SUPPORT imlib_context_set_image(iml->im); tw = imlib_image_get_width(); th = imlib_image_get_height(); #endif } else if (siml->bevel) { tw = scrollbar_anchor_width() - (siml->bevel->edges->left + siml->bevel->edges->right); th = scrollbar_anchor_width() - (siml->bevel->edges->top + siml->bevel->edges->bottom); } else if (siml->border) { tw = scrollbar_anchor_width() - (siml->border->left + siml->border->right); th = scrollbar_anchor_width() - (siml->border->top + siml->border->bottom); } else if (iml->bevel) { tw = iml->bevel->edges->left + iml->bevel->edges->right + 4; th = iml->bevel->edges->top + iml->bevel->edges->bottom + 4; } UPPER_BOUND(tw, scrollbar_anchor_width()); UPPER_BOUND(th, scrollbar_anchor_height() >> 1); D_SCROLLBAR(("Thumb width/height has been calculated at %hux%hu.\n", tw, th)); if ((tw > 0) && (th > 0)) { paste_simage(images[image_st].current, image_st, scrollbar.sa_win, pmap, (scrollbar_anchor_width() - tw) >> 1, (scrollbar_anchor_height() - th) >> 1, tw, th); XSetWindowBackgroundPixmap(Xdisplay, scrollbar.sa_win, pmap); XClearWindow(Xdisplay, scrollbar.sa_win); IMLIB_FREE_PIXMAP(pmap); images[image_sa].current->pmap->pixmap = None; } }
void TkpDisplayMenuButton( ClientData clientData) /* Information about widget. */ { TkMenuButton *mbPtr = (TkMenuButton *) clientData; GC gc; Tk_3DBorder border; int x = 0; /* Initialization needed only to stop * compiler warning. */ int y; Tk_Window tkwin = mbPtr->tkwin; int width, height; MacMenuButton * macMBPtr = (MacMenuButton *) mbPtr; GWorldPtr destPort; CGrafPtr saveWorld; GDHandle saveDevice; MacDrawable *macDraw; mbPtr->flags &= ~REDRAW_PENDING; if ((mbPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { return; } GetGWorld(&saveWorld, &saveDevice); destPort = TkMacGetDrawablePort(Tk_WindowId(tkwin)); SetGWorld(destPort, NULL); macDraw = (MacDrawable *) Tk_WindowId(tkwin); if ((mbPtr->state == tkDisabledUid) && (mbPtr->disabledFg != NULL)) { gc = mbPtr->disabledGC; } else if ((mbPtr->state == tkActiveUid) && !Tk_StrictMotif(mbPtr->tkwin)) { gc = mbPtr->activeTextGC; } else { gc = mbPtr->normalTextGC; } border = mbPtr->normalBorder; /* * In order to avoid screen flashes, this procedure 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. */ Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), border, 0, 0, Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT); /* * Display image or bitmap or text for button. */ if (mbPtr->image != None) { Tk_SizeOfImage(mbPtr->image, &width, &height); imageOrBitmap: TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0, width + mbPtr->indicatorWidth, height, &x, &y); if (mbPtr->image != NULL) { Tk_RedrawImage(mbPtr->image, 0, 0, width, height, Tk_WindowId(tkwin), x, y); } else { XCopyPlane(mbPtr->display, mbPtr->bitmap, Tk_WindowId(tkwin), gc, 0, 0, (unsigned) width, (unsigned) height, x, y, 1); } } else if (mbPtr->bitmap != None) { Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height); goto imageOrBitmap; } else { TkComputeAnchor(mbPtr->anchor, tkwin, mbPtr->padX, mbPtr->padY, mbPtr->textWidth + mbPtr->indicatorWidth, mbPtr->textHeight, &x, &y); Tk_DrawTextLayout(mbPtr->display, Tk_WindowId(tkwin), gc, mbPtr->textLayout, x, y, 0, -1); } /* * If the menu button is disabled with a stipple rather than a special * foreground color, generate the stippled effect. */ if ((mbPtr->state == tkDisabledUid) && ((mbPtr->disabledFg == NULL) || (mbPtr->image != NULL))) { XFillRectangle(mbPtr->display, Tk_WindowId(tkwin), mbPtr->disabledGC, mbPtr->inset, mbPtr->inset, (unsigned) (Tk_Width(tkwin) - 2*mbPtr->inset), (unsigned) (Tk_Height(tkwin) - 2*mbPtr->inset)); } /* * Draw the cascade indicator for the menu button on the * right side of the window, if desired. */ if (mbPtr->indicatorOn) { int w, h, i; Rect r; r.left = macDraw->xOff + Tk_Width(tkwin) - mbPtr->inset - mbPtr->indicatorWidth; r.top = macDraw->yOff + Tk_Height(tkwin)/2 - mbPtr->indicatorHeight/2; r.right = macDraw->xOff + Tk_Width(tkwin) - mbPtr->inset - kTriangleMargin; r.bottom = macDraw->yOff + Tk_Height(tkwin)/2 + mbPtr->indicatorHeight/2; h = mbPtr->indicatorHeight; w = mbPtr->indicatorWidth - 1 - kTriangleMargin; for (i = 0; i < h; i++) { MoveTo(r.left + i, r.top + i); LineTo(r.left + i + w, r.top + i); w -= 2; } } /* * 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. */ TkMacSetUpClippingRgn(Tk_WindowId(tkwin)); if (mbPtr->borderWidth > 0) { Rect r; r.left = macDraw->xOff + mbPtr->highlightWidth + mbPtr->borderWidth; r.top = macDraw->yOff + mbPtr->highlightWidth + mbPtr->borderWidth; r.right = macDraw->xOff + Tk_Width(tkwin) - mbPtr->highlightWidth - mbPtr->borderWidth; r.bottom = macDraw->yOff + Tk_Height(tkwin) - mbPtr->highlightWidth - mbPtr->borderWidth; FrameRect(&r); PenSize(mbPtr->borderWidth - 1, mbPtr->borderWidth - 1); MoveTo(r.right, r.top + kShadowOffset); LineTo(r.right, r.bottom); LineTo(r.left + kShadowOffset, r.bottom); } if (mbPtr->state == tkDisabledUid) { } if (mbPtr->highlightWidth != 0) { GC gc; if (mbPtr->flags & GOT_FOCUS) { gc = Tk_GCForColor(mbPtr->highlightColorPtr, Tk_WindowId(tkwin)); } else { gc = Tk_GCForColor(mbPtr->highlightBgColorPtr, Tk_WindowId(tkwin)); } Tk_DrawFocusHighlight(tkwin, gc, mbPtr->highlightWidth, Tk_WindowId(tkwin)); } SetGWorld(saveWorld, saveDevice); }
static void DisplayRectOval( Tk_Canvas canvas, /* Canvas that contains item. */ Tk_Item *itemPtr, /* Item to be displayed. */ Display *display, /* Display on which to draw item. */ Drawable drawable, /* Pixmap or window in which to draw item. */ int x, int y, int width, int height) /* Describes region of canvas that must be * redisplayed (not used). */ { RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr; short x1, y1, x2, y2; Pixmap fillStipple; Tk_State state = itemPtr->state; /* * Compute the screen coordinates of the bounding box for the item. Make * sure that the bbox is at least one pixel large, since some X servers * will die if it isn't. */ Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[0],rectOvalPtr->bbox[1], &x1, &y1); Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[2],rectOvalPtr->bbox[3], &x2, &y2); if (x2 <= x1) { x2 = x1+1; } if (y2 <= y1) { y2 = y1+1; } /* * Display filled part first (if wanted), then outline. If we're * stippling, then modify the stipple offset in the GC. Be sure to reset * the offset when done, since the GC is supposed to be read-only. */ if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } fillStipple = rectOvalPtr->fillStipple; if (Canvas(canvas)->currentItemPtr == (Tk_Item *) rectOvalPtr) { if (rectOvalPtr->activeFillStipple != None) { fillStipple = rectOvalPtr->activeFillStipple; } } else if (state == TK_STATE_DISABLED) { if (rectOvalPtr->disabledFillStipple != None) { fillStipple = rectOvalPtr->disabledFillStipple; } } if (rectOvalPtr->fillGC != None) { if (fillStipple != None) { Tk_TSOffset *tsoffset; int w = 0, h = 0; tsoffset = &rectOvalPtr->tsoffset; if (tsoffset) { int flags = tsoffset->flags; if (flags & (TK_OFFSET_CENTER|TK_OFFSET_MIDDLE)) { Tk_SizeOfBitmap(display, fillStipple, &w, &h); if (flags & TK_OFFSET_CENTER) { w /= 2; } else { w = 0; } if (flags & TK_OFFSET_MIDDLE) { h /= 2; } else { h = 0; } } tsoffset->xoffset -= w; tsoffset->yoffset -= h; } Tk_CanvasSetOffset(canvas, rectOvalPtr->fillGC, tsoffset); if (tsoffset) { tsoffset->xoffset += w; tsoffset->yoffset += h; } } if (rectOvalPtr->header.typePtr == &tkRectangleType) { XFillRectangle(display, drawable, rectOvalPtr->fillGC, x1, y1, (unsigned int) (x2-x1), (unsigned int) (y2-y1)); } else { XFillArc(display, drawable, rectOvalPtr->fillGC, x1, y1, (unsigned) (x2-x1), (unsigned) (y2-y1), 0, 360*64); } if (fillStipple != None) { XSetTSOrigin(display, rectOvalPtr->fillGC, 0, 0); } } if (rectOvalPtr->outline.gc != None) { Tk_ChangeOutlineGC(canvas, itemPtr, &(rectOvalPtr->outline)); if (rectOvalPtr->header.typePtr == &tkRectangleType) { XDrawRectangle(display, drawable, rectOvalPtr->outline.gc, x1, y1, (unsigned) (x2-x1), (unsigned) (y2-y1)); } else { XDrawArc(display, drawable, rectOvalPtr->outline.gc, x1, y1, (unsigned) (x2-x1), (unsigned) (y2-y1), 0, 360*64); } Tk_ResetOutlineGC(canvas, itemPtr, &(rectOvalPtr->outline)); } }
void xf_gdi_patblt(rdpUpdate* update, PATBLT_ORDER* patblt) { BRUSH* brush; Pixmap pattern; uint32 foreColor; uint32 backColor; xfInfo* xfi = GET_XFI(update); brush = &patblt->brush; xf_set_rop3(xfi, gdi_rop3_code(patblt->bRop)); foreColor = freerdp_color_convert(patblt->foreColor, xfi->srcBpp, 32, xfi->clrconv); backColor = freerdp_color_convert(patblt->backColor, xfi->srcBpp, 32, xfi->clrconv); if (brush->style & CACHED_BRUSH) { brush->data = brush_get(xfi->cache->brush, brush->index, &brush->bpp); brush->style = GDI_BS_PATTERN; } if (brush->style == GDI_BS_SOLID) { XSetFillStyle(xfi->display, xfi->gc, FillSolid); XSetForeground(xfi->display, xfi->gc, patblt->foreColor); XFillRectangle(xfi->display, xfi->drawing, xfi->gc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); } else if (brush->style == GDI_BS_PATTERN) { if (brush->bpp > 1) { pattern = xf_bitmap_new(xfi, 8, 8, brush->bpp, brush->data); XSetFillStyle(xfi->display, xfi->gc, FillTiled); XSetTile(xfi->display, xfi->gc, pattern); XSetTSOrigin(xfi->display, xfi->gc, brush->x, brush->y); XFillRectangle(xfi->display, xfi->drawing, xfi->gc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); XSetTile(xfi->display, xfi->gc, xfi->primary); } else { pattern = xf_mono_bitmap_new(xfi, 8, 8, brush->data); XSetForeground(xfi->display, xfi->gc, backColor); XSetBackground(xfi->display, xfi->gc, foreColor); XSetFillStyle(xfi->display, xfi->gc, FillOpaqueStippled); XSetTSOrigin(xfi->display, xfi->gc, brush->x, brush->y); XFillRectangle(xfi->display, xfi->drawing, xfi->gc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); XSetStipple(xfi->display, xfi->gc_mono, pattern); } } else { printf("unimplemented brush style:%d\n", brush->style); } if (xfi->drawing == xfi->primary) { XSetFunction(xfi->display, xfi->gc, GXcopy); if (xfi->remote_app != True) { XCopyArea(xfi->display, xfi->primary, xfi->drawable, xfi->gc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight, patblt->nLeftRect, patblt->nTopRect); } gdi_InvalidateRegion(xfi->hdc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); } }
void EvtKeyTextField(struct XObj *xobj,XKeyEvent *EvtKey) { int i,x2; char car[11]; char* carks2; char* carks = NULL; KeySym ks; int Size; int NewPos; /* Recherche du charactere */ i=XLookupString(EvtKey,car,10,&ks,NULL); NewPos=xobj->value; car[i]='\0'; carks2=XKeysymToString(ks); if (carks2!=NULL) { carks=(char*)calloc(sizeof(char),30); sprintf(carks,"%s",carks2); if (strcmp(carks,"Right")==0) { NewPos++; if (NewPos>strlen(xobj->title)) NewPos=strlen(xobj->title); } else if (strcmp(carks,"Left")==0) { NewPos--; if (NewPos<0) NewPos=0; } else if (strcmp(carks,"Return")==0) { ; } else if ((strcmp(carks,"Delete")==0)||(strcmp(carks,"BackSpace")==0)) { if (NewPos>0) { Size=strlen(xobj->title); memmove(&xobj->title[NewPos-1],&xobj->title[NewPos], Size-NewPos+1); xobj->title=(char*)realloc(xobj->title,(Size)*sizeof(char)); NewPos--; SendMsg(xobj,SingleClic); } } else if (i!=0) /* Cas d'un caractere normal */ { /* Insertion du caractere dans le titre */ /* a normal character: insertion in the title */ Size=strlen(xobj->title); xobj->title=(char*)realloc(xobj->title,(2+Size)*sizeof(char)); memmove(&xobj->title[NewPos+1],&xobj->title[NewPos], Size-NewPos+1); xobj->title[NewPos]=car[0]; NewPos++; SendMsg(xobj,SingleClic); } } if ((xobj->value!=NewPos)||(xobj->value2!=NewPos)) { XSetForeground(dpy,xobj->gc,xobj->TabColor[back]); x2=XTextWidth(xobj->xfont,xobj->title,strlen(xobj->title)); XFillRectangle(dpy,xobj->win,xobj->gc,x2+4,4,xobj->width-x2-8, xobj->height-8); xobj->value=NewPos; xobj->value2=NewPos; DrawPointTxt(xobj,xobj->TabColor[fore]); DrawTextField(xobj); } free(carks); }
void xf_gdi_fast_index(rdpUpdate* update, FAST_INDEX_ORDER* fast_index) { int i, j; int x, y; int w, h; Pixmap bmp; Pixmap* bmps; uint32 fgcolor; uint32 bgcolor; GLYPH_DATA* glyph; GLYPH_DATA** glyphs; GLYPH_FRAGMENT* fragment; xfInfo* xfi = GET_XFI(update); fgcolor = freerdp_color_convert(fast_index->foreColor, xfi->srcBpp, 32, xfi->clrconv); bgcolor = freerdp_color_convert(fast_index->backColor, xfi->srcBpp, 32, xfi->clrconv); XSetFunction(xfi->display, xfi->gc, GXcopy); XSetForeground(xfi->display, xfi->gc, bgcolor); XSetBackground(xfi->display, xfi->gc, fgcolor); if (fast_index->opaqueRect) { XSetFillStyle(xfi->display, xfi->gc, FillSolid); x = fast_index->opLeft; y = fast_index->opTop; w = fast_index->opRight - fast_index->opLeft + 1; h = fast_index->opBottom - fast_index->opTop + 1; XFillRectangle(xfi->display, xfi->drawing, xfi->gc, x, y, w, h); if (xfi->drawing == xfi->primary) { if (xfi->remote_app != True) { XFillRectangle(xfi->display, xfi->drawable, xfi->gc, x, y, w, h); } gdi_InvalidateRegion(xfi->hdc, x, y, w, h); } } x = fast_index->bkLeft; y = fast_index->y; XSetFillStyle(xfi->display, xfi->gc, FillStippled); for (i = 0; i < fast_index->nfragments; i++) { fragment = &fast_index->fragments[i]; if (fragment->operation == GLYPH_FRAGMENT_USE) { fragment->indices = (GLYPH_FRAGMENT_INDEX*) glyph_fragment_get(xfi->cache->glyph, fragment->index, &fragment->nindices, (void**) &bmps); glyphs = (GLYPH_DATA**) xmalloc(sizeof(GLYPH_DATA*) * fragment->nindices); for (j = 0; j < fragment->nindices; j++) { glyphs[j] = glyph_get(xfi->cache->glyph, fast_index->cacheId, fragment->indices[j].index, (void**) &bmps[j]); } } else { bmps = (Pixmap*) xmalloc(sizeof(Pixmap*) * fragment->nindices); glyphs = (GLYPH_DATA**) xmalloc(sizeof(GLYPH_DATA*) * fragment->nindices); for (j = 0; j < fragment->nindices; j++) { glyphs[j] = glyph_get(xfi->cache->glyph, fast_index->cacheId, fragment->indices[j].index, (void**) &bmps[j]); } } for (j = 0; j < fragment->nindices; j++) { bmp = bmps[j]; glyph = glyphs[j]; XSetStipple(xfi->display, xfi->gc, bmp); XSetTSOrigin(xfi->display, xfi->gc, glyph->x + x, glyph->y + y); XFillRectangle(xfi->display, xfi->drawing, xfi->gc, glyph->x + x, glyph->y + y, glyph->cx, glyph->cy); XSetStipple(xfi->display, xfi->gc, xfi->bitmap_mono); if ((j + 1) < fragment->nindices) { if (!(fast_index->flAccel & SO_CHAR_INC_EQUAL_BM_BASE)) { if (fast_index->flAccel & SO_VERTICAL) { y += fragment->indices[j + 1].delta; } else { x += fragment->indices[j + 1].delta; } } else { x += glyph->cx; } } } if (fragment->operation == GLYPH_FRAGMENT_ADD) { glyph_fragment_put(xfi->cache->glyph, fragment->index, fragment->nindices, (void*) fragment->indices, (void*) bmps); } } if (xfi->drawing == xfi->primary) { if (xfi->remote_app != True) { XCopyArea(xfi->display, xfi->primary, xfi->drawable, xfi->gc, fast_index->bkLeft, fast_index->bkTop, fast_index->bkRight - fast_index->bkLeft + 1, fast_index->bkBottom - fast_index->bkTop + 1, fast_index->bkLeft, fast_index->bkTop); } gdi_InvalidateRegion(xfi->hdc, fast_index->bkLeft, fast_index->bkTop, fast_index->bkRight - fast_index->bkLeft + 1, fast_index->bkBottom - fast_index->bkTop + 1); } }
int GFX_CreateVisual(struct Tracker_Windows *tvisual){ static char *xcolornames[NUM_COLORS]={"grey70","grey0","grey100","blue","yellow","red","orange","green"}; Window window; Colormap colormap; XSetWindowAttributes attr; int lokke; static bool X11_XShmInitialized=false; tvisual->os_visual=(struct OS_visual *)calloc(1,sizeof(struct OS_visual)); tvisual->os_visual->gcs=(GC *)malloc(sizeof(GC)*NUM_COLORS); for(lokke=0;lokke<NUM_COLORS;lokke++){ tvisual->os_visual->xpoints[lokke]=calloc(sizeof(XPoint),NUM_XPOINTS); } // tvisual->os_visual=(struct OS_visual *)talloc_atomic(sizeof(struct OS_visual)); //tvisual->os_visual->gcs=(GC *)talloc_atomic(sizeof(GC)*NUM_COLORS); tvisual->fontheight=17; tvisual->fontwidth=13; tvisual->org_fontheight=tvisual->fontheight; attr.event_mask = KeyPressMask | KeyReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | ExposureMask; attr.background_pixmap=None; // attr.background_pixel=BlackPixel(x11_display,x11_screen); // attr.border_pixel=BlackPixel(x11_display,x11_screen); #if 1 window=tvisual->os_visual->window=XCreateWindow( x11_display, RootWindow(x11_display,x11_screen), 10,10, 800,600, 2, 0, InputOutput, (Visual *)CopyFromParent, (CWBackPixel | CWBorderPixel | CWEventMask), &attr ); #endif printf("Made window with id %d\n",(int)window); #if 0 XSetStandardProperties (x11_display, window, "gakk", NULL, (Pixmap) 0, argv, argc, &hints); #endif colormap = DefaultColormap(x11_display,x11_screen); for(lokke=0;lokke<NUM_COLORS;lokke++){ XParseColor(x11_display,colormap,xcolornames[lokke],&xcolors[lokke]); XAllocColor(x11_display,colormap,&xcolors[lokke]); tvisual->os_visual->gcs[lokke]=XCreateGC(x11_display,window, 0, 0); XSetForeground(x11_display, tvisual->os_visual->gcs[lokke],xcolors[lokke].pixel); } if(X11_UseXShm==true){ if(X11_XShmInitialized==false){ X11_InitXShm(); } tvisual->os_visual->pixmap=XShmCreatePixmap( x11_display, window, X11_shminfo->shmaddr, X11_shminfo, 800, 600, (unsigned int)(DefaultDepth(x11_display,x11_screen)) ); }else{ tvisual->os_visual->pixmap=XCreatePixmap(x11_display, window, 800, 600, (unsigned int)(DefaultDepth(x11_display,x11_screen)) ); } XFillRectangle( x11_display, tvisual->os_visual->pixmap, tvisual->os_visual->gcs[0], 0, 0, 800, 600 ); tvisual->os_visual->cursorpixmap=XCreatePixmap(x11_display, window, 800, 600, (unsigned int)(DefaultDepth(x11_display,x11_screen)) ); XFillRectangle( x11_display, tvisual->os_visual->cursorpixmap, tvisual->os_visual->gcs[0], 0, 0, 800, 600 ); printf("Depth: %d\n",DefaultDepth(x11_display,x11_screen)); XMapWindow(x11_display,window); XFlush(x11_display); XStoreName(x11_display,window,"gakk"); XFlush(x11_display); XFillRectangle( x11_display, window, tvisual->os_visual->gcs[0], 0, 0, 800, 600 ); XFlush(x11_display); tvisual->x=10; tvisual->y=10; tvisual->width=750; tvisual->height=550; BS_SetX11Window((int)window); X11_MidiProperties_SetX11Window((int)window); return 0; }
static Bool GradientLoader(XawParams *params, Screen *screen, Colormap colormap, int depth, Pixmap *pixmap_return, Pixmap *mask_return, Dimension *width_return, Dimension *height_return) { double ired, igreen, iblue, red, green, blue; XColor start, end, color; XGCValues values; GC gc; double i, inc, x, y, xend, yend; Pixmap pixmap; XawArgVal *argval; int orientation, dimension, steps; char *value; if (XmuCompareISOLatin1(params->name, "vertical") == 0) orientation = VERTICAL; else if (XmuCompareISOLatin1(params->name, "horizontal") == 0) orientation = HORIZONTAL; else return (False); if ((argval = XawFindArgVal(params, "dimension")) != NULL && argval->value) { dimension = atoi(argval->value); if (dimension <= 0) return (False); } else dimension = 50; if ((argval = XawFindArgVal(params, "steps")) != NULL && argval->value) { steps = atoi(argval->value); if (steps <= 0) return (False); } else steps = dimension; steps = XawMin(steps, dimension); value = NULL; if ((argval = XawFindArgVal(params, "start")) != NULL) value = argval->value; if (value && !XAllocNamedColor(DisplayOfScreen(screen), colormap, value, &start, &color)) return (False); else if (!value) { start.pixel = WhitePixelOfScreen(screen); XQueryColor(DisplayOfScreen(screen), colormap, &start); } value = NULL; if ((argval = XawFindArgVal(params, "end")) != NULL) value = argval->value; if (value && !XAllocNamedColor(DisplayOfScreen(screen), colormap, value, &end, &color)) return (False); else if (!value) { end.pixel = BlackPixelOfScreen(screen); XQueryColor(DisplayOfScreen(screen), colormap, &end); } if ((pixmap = XCreatePixmap(DisplayOfScreen(screen), RootWindowOfScreen(screen), orientation == VERTICAL ? 1 : dimension, orientation == VERTICAL ? dimension : 1, depth)) == 0) return (False); ired = (double)(end.red - start.red) / (double)steps; igreen = (double)(end.green - start.green) / (double)steps; iblue = (double)(end.blue - start.blue) / (double)steps; red = color.red = start.red; green = color.green = start.green; blue = color.blue = start.blue; inc = (double)dimension / (double)steps; gc = XCreateGC(DisplayOfScreen(screen), pixmap, 0, &values); x = y = 0.0; if (orientation == VERTICAL) { xend = 1; yend = 0; } else { xend = 0; yend = 1; } color.flags = DoRed | DoGreen | DoBlue; XSetForeground(DisplayOfScreen(screen), gc, start.pixel); for (i = 0.0; i < dimension; i += inc) { if ((int)color.red != (int)red || (int)color.green != (int)green || (int)color.blue != (int)blue) { XFillRectangle(DisplayOfScreen(screen), pixmap, gc, (int)x, (int)y, (unsigned int)xend, (unsigned int)yend); color.red = (unsigned short)red; color.green = (unsigned short)green; color.blue = (unsigned short)blue; if (!XAllocColor(DisplayOfScreen(screen), colormap, &color)) { XFreePixmap(DisplayOfScreen(screen), pixmap); return (False); } XSetForeground(DisplayOfScreen(screen), gc, color.pixel); if (orientation == VERTICAL) y = yend; else x = xend; } red += ired; green += igreen; blue += iblue; if (orientation == VERTICAL) yend += inc; else xend += inc; } XFillRectangle(DisplayOfScreen(screen), pixmap, gc, (int)x, (int)y, (unsigned int)xend, (unsigned int)yend); *pixmap_return = pixmap; *mask_return = None; *width_return = orientation == VERTICAL ? 1 : dimension; *height_return = orientation == VERTICAL ? dimension : 1; XFreeGC(DisplayOfScreen(screen), gc); return (True); }
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 _DtTermPrimRefreshText(Widget w, short startColumn, short startRow, short endColumn, short endRow) { DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w; struct termData *tpd = tw->term.tpd; TermBuffer tBuffer = tpd->termBuffer; int lineWidth; unsigned char *linePtr; TermFont termFont; int currentColorPair = 0; int currentVideo = 0; short chunkStartColumn; short chunkWidth; enhValues enhancements; int i; int lineNum; unsigned long valueMask; GC gc; XGCValues values; TermEnhInfoRec enhInfo; Boolean checkSelection = False; int selectionEnd; Pixel tmpPixel; XmTextPosition begin, end; DebugF('t', 0, fprintf(stderr, ">>_DtTermPrimRefreshText() starting\n")); DebugF('t', 0, fprintf(stderr, ">>_DtTermPrimRefreshText() startCol=%hd startRow=%hd endCol=%hd endRow=%hd\n", startColumn, startRow, endColumn, endRow)); if (tpd->mbCurMax > 1) { _DtTermPrimRefreshTextWc(w, startColumn, startRow, endColumn, endRow); return; } /* clip start/end x/y... */ if (startColumn <= 0) startColumn = 0; if (startRow <= 0) startRow = 0; if (endColumn >= tw->term.columns) endColumn = tw->term.columns - 1; if (endRow >= tw->term.rows) endRow = tw->term.rows - 1; /* ** don't display if we are in jump scroll and in the process ** of scrolling and inside the scroll region... */ if (tw->term.jumpScroll && tpd->scroll.jump.scrolled) { /* set all the scrollRefreshRows flags... */ for (; startRow <= endRow; startRow++) { tpd->scrollRefreshRows[startRow] = True; } DebugF('t', 0, fprintf(stderr, ">>_DtTermPrimRefreshText() jump scroll in progress, no render\n")); return; } if (!tpd->renderGC.gc) { /* get a drawImageString GC... */ int i; XGCValues values; /*********************************************************** * renderGC... */ /* set the GC fg and bg... */ values.foreground = tw->term.reverseVideo ? tw->core.background_pixel : tw->primitive.foreground; values.background = tw->term.reverseVideo ? tw->primitive.foreground : tw->core.background_pixel; tpd->renderGC.gc = XCreateGC(XtDisplay(w), XtWindow(w), GCForeground | GCBackground, &values); /* set the GC cache values... */ tpd->renderGC.foreground = values.foreground; tpd->renderGC.background = values.background; tpd->renderGC.fid = (Font) 0; /*********************************************************** * renderReverseGC... */ values.foreground = tw->term.reverseVideo ? tw->primitive.foreground : tw->core.background_pixel; values.background = tw->term.reverseVideo ? tw->core.background_pixel : tw->primitive.foreground; tpd->renderReverseGC.gc = XCreateGC(XtDisplay(w), XtWindow(w), GCForeground | GCBackground, &values); /* set the GC cache values... */ tpd->renderReverseGC.foreground = values.foreground; tpd->renderReverseGC.background = values.background; tpd->renderReverseGC.fid = (Font) 0; /*********************************************************** * clearGC... */ values.foreground = tw->term.reverseVideo ? tw->primitive.foreground : tw->core.background_pixel; values.background = tw->term.reverseVideo ? tw->core.background_pixel : tw->primitive.foreground; tpd->clearGC.gc = XCreateGC(XtDisplay(w), XtWindow(w), GCForeground | GCBackground, &values); /* set the GC cache values... */ tpd->clearGC.foreground = values.foreground; tpd->clearGC.background = values.background; tpd->clearGC.fid = (Font) 0; } #ifdef SUN_MOTIF_PERF /* use the clear GC... */ gc = tpd->clearGC.gc; valueMask = (unsigned long) 0; if (tpd->clearGC.foreground != tw->term.reverseVideo ? tw->core.background_pixel : tw->primitive.foreground) { values.foreground = tw->term.reverseVideo ? tw->primitive.foreground : tw->core.background_pixel; tpd->clearGC.foreground = values.foreground; valueMask |= GCForeground; } if (tpd->clearGC.background != tw->term.reverseVideo ? tw->primitive.foreground : tw->core.background_pixel) { values.background = tw->term.reverseVideo ? tw->core.background_pixel : tw->primitive.foreground; tpd->clearGC.background = values.background; valueMask |= GCBackground; } if (valueMask) { (void) XChangeGC(XtDisplay(w), tpd->clearGC.gc, valueMask, &values); } (void) XFillRectangle(XtDisplay(w), /* Display */ XtWindow(w), /* Drawable */ gc, /* GC */ startColumn * tpd->cellWidth + tpd->offsetX, /* x */ startRow * tpd->cellHeight + tpd->offsetY, /* y */ (endColumn - startColumn + 1) * tpd->cellWidth, /* width */ (endRow - startRow + 1) * tpd->cellHeight); /* height */ #endif /* SUN_MOTIF_PERF */ for (; startRow <= endRow; startRow++) { /* if we are refreshing a full line, then we can clear the * scrollRefreshRows flag for this line... */ if ((startColumn == 0) && (endColumn >= tw->term.columns - 1)) { tpd->scrollRefreshRows[startRow] = False; } lineNum = startRow + tpd->topRow; if (!tw->term.jumpScroll && tpd->scroll.nojump.pendingScroll) { if (lineNum != tpd->scrollLockBottomRow) { lineNum -= tpd->scroll.nojump.pendingScrollLines; } } /* are we in the selected area?... */ if (tpd->useHistoryBuffer) { if (_DtTermPrimSelectGetSelection(w, &begin, &end) && (begin < end) && (lineNum >= (begin / (tpd->selectInfo->columns + 1)) - tpd->lastUsedHistoryRow) && (lineNum <= (end / (tpd->selectInfo->columns + 1)) - tpd->lastUsedHistoryRow)) { checkSelection = True; } else { checkSelection = False; } } else { if (_DtTermPrimSelectGetSelection(w, &begin, &end) && (begin < end) && (lineNum >= (begin / (tpd->selectInfo->columns + 1))) && (lineNum <= (end / (tpd->selectInfo->columns + 1)))) { checkSelection = True; } else { checkSelection = False; } } chunkStartColumn = startColumn; if (startColumn > endColumn) { /* nothing to render on this line... */ continue; } if (lineNum >= tpd->lastUsedRow) { /* we are pointing to empty screen space below the last used * line of the display... */ lineWidth = 0; linePtr = NULL; } else if (lineNum < 0) { if ((tpd->useHistoryBuffer) && (-lineNum <= tpd->lastUsedHistoryRow)) { /* get a line out of the history buffer... */ lineWidth = MAX(0, MIN(endColumn - startColumn + 1, _DtTermPrimBufferGetLineWidth(tpd->historyBuffer, tpd->lastUsedHistoryRow + lineNum) - startColumn)); linePtr = _DtTermPrimBufferGetCharacterPointer(tpd->historyBuffer, tpd->lastUsedHistoryRow + lineNum, startColumn); } else { /* we are above the history buffer. Should not happen, but... */ lineWidth = 0; linePtr = NULL; } } else { /* get the line width and a pointer to the data... */ lineWidth = MAX(0, MIN(endColumn - startColumn + 1, _DtTermPrimBufferGetLineWidth(tBuffer, lineNum) - startColumn)); linePtr = _DtTermPrimBufferGetCharacterPointer(tBuffer, lineNum, startColumn); } while (lineWidth > 0) { /* get the enhancement values for the first chunk of the * string... */ if (lineNum >= 0) { (void) _DtTermPrimBufferGetEnhancement(tBuffer, /* TermBuffer */ lineNum, /* row */ chunkStartColumn, /* col */ &enhancements, /* enhancements */ &chunkWidth, /* width */ countAll); /* countWhich */ } else { /* get it from the history buffer... */ (void) _DtTermPrimBufferGetEnhancement(tpd->historyBuffer, /* TermBuffer */ tpd->lastUsedHistoryRow + lineNum, /* row */ chunkStartColumn, /* col */ &enhancements, /* enhancements */ &chunkWidth, /* width */ countAll); /* countWhich */ } /* clip chunkWidth... */ if (chunkWidth > lineWidth) chunkWidth = lineWidth; /* set reasonable defaults for our render info... */ enhInfo.fg = tw->primitive.foreground; enhInfo.bg = tw->core.background_pixel; enhInfo.font = tpd->defaultTermFont; enhInfo.flags = (unsigned long) 0; /* set our font and color from the enhancements... */ if (ENH_PROC(tBuffer)) { (void) (*(ENH_PROC(tBuffer)))(w, enhancements, &enhInfo); } /* if we are in reverse video mode... */ if (tw->term.reverseVideo) { /* flip fg and bg... */ tmpPixel = enhInfo.fg; enhInfo.fg = enhInfo.bg; enhInfo.bg = tmpPixel; } /* are we in the selection area?... */ if (checkSelection && _DtTermPrimSelectIsInSelection(w, lineNum, chunkStartColumn, chunkWidth, &chunkWidth)) { /* flip fg and bg... */ tmpPixel = enhInfo.fg; enhInfo.fg = enhInfo.bg; enhInfo.bg = tmpPixel; } /* if secure, we will use a XFillRectangle, and we need * foreground set to the background... */ if (TermIS_SECURE(enhInfo.flags)) { /* render secure video locally... */ /* set the renderReverseGC... */ valueMask = (unsigned long) 0; if (tpd->renderReverseGC.foreground != enhInfo.bg) { tpd->renderReverseGC.foreground = enhInfo.bg; values.foreground = enhInfo.bg; valueMask |= GCForeground; } if (valueMask) { (void) XChangeGC(XtDisplay(w), tpd->renderReverseGC.gc, valueMask, &values); } (void) XFillRectangle(XtDisplay(w), XtWindow(w), tpd->renderReverseGC.gc, chunkStartColumn * tpd->cellWidth + tpd->offsetX, startRow * tpd->cellHeight + tpd->offsetY, tpd->cellWidth * chunkWidth, tpd->cellHeight); /* underline as well... */ if (TermIS_UNDERLINE(enhInfo.flags)) { valueMask = (unsigned long) 0; if (tpd->renderGC.foreground != enhInfo.fg) { tpd->renderGC.foreground = enhInfo.fg; values.foreground = enhInfo.fg; valueMask |= GCForeground; } if (valueMask) { (void) XChangeGC(XtDisplay(w), tpd->renderGC.gc, valueMask, &values); } (void) XDrawLine(XtDisplay(w), /* Display */ XtWindow(w), /* Drawable */ tpd->renderGC.gc, /* GC */ chunkStartColumn * tpd->cellWidth + tpd->offsetX, /* X1 */ startRow * tpd->cellHeight + tpd->offsetY + tpd->cellHeight - 1, /* Y1 */ (chunkStartColumn + chunkWidth) * tpd->cellWidth + tpd->offsetX, /* X2 */ startRow * tpd->cellHeight + tpd->offsetY + tpd->cellHeight - 1); /* Y2 */ } } else { (void) _DtTermPrimRenderText( w, /* Widget */ enhInfo.font, /* TermFont */ enhInfo.fg, /* fg Pixel */ enhInfo.bg, /* bg Pixel */ enhInfo.flags, /* flags */ chunkStartColumn * tpd->cellWidth + tpd->offsetX, /* x */ startRow * tpd->cellHeight + tpd->offsetY, /* y */ linePtr, /* string */ chunkWidth); /* width */ } chunkStartColumn += chunkWidth; lineWidth -= chunkWidth; linePtr += chunkWidth; } /* clear any extra space in the line. chunkStartColumn now points to * the end of the line, and lineWidth == 0... */ while (endColumn - chunkStartColumn >= 0) { chunkWidth = endColumn - chunkStartColumn + 1; if (checkSelection && _DtTermPrimSelectIsInSelection(w, lineNum, chunkStartColumn, chunkWidth, &chunkWidth)) { /* use the render gc set to the fg color... */ gc = tpd->renderReverseGC.gc; valueMask = (unsigned long) 0; if (tpd->renderReverseGC.foreground != tw->term.reverseVideo ? tw->core.background_pixel : tw->primitive.foreground) { values.foreground = tw->term.reverseVideo ? tw->core.background_pixel : tw->primitive.foreground; tpd->renderReverseGC.foreground = values.foreground; valueMask |= GCForeground; } if (valueMask) { (void) XChangeGC(XtDisplay(w), tpd->renderReverseGC.gc, valueMask, &values); } #ifndef SUN_MOTIF_PERF } else { /* use the clear GC... */ gc = tpd->clearGC.gc; valueMask = (unsigned long) 0; if (tpd->clearGC.foreground != tw->term.reverseVideo ? tw->core.background_pixel : tw->primitive.foreground) { values.foreground = tw->term.reverseVideo ? tw->primitive.foreground : tw->core.background_pixel; tpd->clearGC.foreground = values.foreground; valueMask |= GCForeground; } if (tpd->clearGC.background != tw->term.reverseVideo ? tw->primitive.foreground : tw->core.background_pixel) { values.background = tw->term.reverseVideo ? tw->core.background_pixel : tw->primitive.foreground; tpd->clearGC.background = values.background; valueMask |= GCBackground; } if (valueMask) { (void) XChangeGC(XtDisplay(w), tpd->clearGC.gc, valueMask, &values); } } #endif /* not SUN_MOTIF_PERF */ if (isDebugFSet('t', 1)) { #ifdef BBA #pragma BBA_IGNORE #endif /*BBA*/ /* Fill in the clear area so we can see what is going to * be displayed... */ (void) XFillRectangle(XtDisplay(w), XtWindow(w), tpd->renderGC.gc, chunkStartColumn * tpd->cellWidth + tpd->offsetX, startRow * tpd->cellHeight + tpd->offsetY, chunkWidth * tpd->cellWidth, tpd->cellHeight); (void) XSync(XtDisplay(w), False); (void) shortSleep(100000); } (void) XFillRectangle(XtDisplay(w), /* Display */ XtWindow(w), /* Drawable */ gc, /* GC */ chunkStartColumn * tpd->cellWidth + tpd->offsetX, /* x */ startRow * tpd->cellHeight + tpd->offsetY, /* y */ chunkWidth * tpd->cellWidth, /* width */ tpd->cellHeight); /* height */ #ifdef SUN_MOTIF_PERF } #endif /* SUN_MOTIF_PERF */ chunkStartColumn += chunkWidth; } }
/* draw pixels for one frame in lowres */ static void draw_lowres(void) { int psize, x, y, i; BYTE *p = ram + dma_addr; /* get size of DMA memory and draw the pixels */ if (format & 32) { /* 2048 bytes memory */ psize = size / 64; /* size of one pixel for 64x64 */ for (y = 0; y < 32; y++) { for (x = 0; x < 32;) { i = *p & 0x0f; if (format & 16) XSetForeground(display, gc, colors[i].pixel); else XSetForeground(display, gc, grays[i].pixel); XFillRectangle(display, pixmap, gc, x * psize, y * psize, psize, psize); x++; i = (*p & 0xf0) >> 4; if (format & 16) XSetForeground(display, gc, colors[i].pixel); else XSetForeground(display, gc, grays[i].pixel); XFillRectangle(display, pixmap, gc, x * psize, y * psize, psize, psize); x++; p++; } } for (y = 0; y < 32; y++) { for (x = 32; x < 64;) { i = *p & 0x0f; if (format & 16) XSetForeground(display, gc, colors[i].pixel); else XSetForeground(display, gc, grays[i].pixel); XFillRectangle(display, pixmap, gc, x * psize, y * psize, psize, psize); x++; i = (*p & 0xf0) >> 4; if (format & 16) XSetForeground(display, gc, colors[i].pixel); else XSetForeground(display, gc, grays[i].pixel); XFillRectangle(display, pixmap, gc, x * psize, y * psize, psize, psize); x++; p++; } } for (y = 32; y < 64; y++) { for (x = 0; x < 32;) { i = *p & 0x0f; if (format & 16) XSetForeground(display, gc, colors[i].pixel); else XSetForeground(display, gc, grays[i].pixel); XFillRectangle(display, pixmap, gc, x * psize, y * psize, psize, psize); x++; i = (*p & 0xf0) >> 4; if (format & 16) XSetForeground(display, gc, colors[i].pixel); else XSetForeground(display, gc, grays[i].pixel); XFillRectangle(display, pixmap, gc, x * psize, y * psize, psize, psize); x++; p++; } } for (y = 32; y < 64; y++) { for (x = 32; x < 64;) { i = *p & 0x0f; if (format & 16) XSetForeground(display, gc, colors[i].pixel); else XSetForeground(display, gc, grays[i].pixel); XFillRectangle(display, pixmap, gc, x * psize, y * psize, psize, psize); x++; i = (*p & 0xf0) >> 4; if (format & 16) XSetForeground(display, gc, colors[i].pixel); else XSetForeground(display, gc, grays[i].pixel); XFillRectangle(display, pixmap, gc, x * psize, y * psize, psize, psize); x++; p++; } } } else { /* 512 bytes memory */
static void talk (struct state *st, int force_erase) { int width = 0, height, Z, total = 0; register char *p, *p2; char args[MAXLINES][LINELEN]; /* clear what we've written */ if (st->talking || force_erase) { if (!st->talking) return; XFillRectangle(st->dpy, st->window, st->bg_gc, st->s_rect.x - 5, st->s_rect.y - 5, st->s_rect.width + 10, st->s_rect.height + 10); st->talking = 0; if (!force_erase) st->next_fn = move; st->interval = 0; { /* might as well check the st->window for size changes now... */ XWindowAttributes xgwa; XGetWindowAttributes (st->dpy, st->window, &xgwa); st->Width = xgwa.width + 2; st->Height = xgwa.height + 2; } return; } p = st->words; /* If there is actually no words, just return */ if (!*p) { st->talking = 0; return; } st->talking = 1; walk(st, FRONT); for (p2 = p; *p2; p2++) if (*p2 == '\t') *p2 = ' '; if (!(p2 = strchr(p, '\n')) || !p2[1]) { total = strlen (st->words); strncpy (args[0], st->words, LINELEN); args[0][LINELEN - 1] = 0; width = XTextWidth(st->font, st->words, total); height = 0; } else /* p2 now points to the first '\n' */ for (height = 0; p; height++) { int w; *p2 = 0; if ((w = XTextWidth(st->font, p, p2 - p)) > width) width = w; total += p2 - p; /* total chars; count to determine reading * time */ (void) strncpy(args[height], p, LINELEN); args[height][LINELEN - 1] = 0; if (height == MAXLINES - 1) { /* puts("Message too long!"); */ break; } p = p2 + 1; if (!(p2 = strchr(p, '\n'))) break; } height++; /* * Figure out the height and width in pixels (height, width) extend the * new box by 15 pixels on the sides (30 total) top and bottom. */ st->s_rect.width = width + 30; st->s_rect.height = height * font_height(st->font) + 30; if (st->x - st->s_rect.width - 10 < 5) st->s_rect.x = 5; else if ((st->s_rect.x = st->x + 32 - (st->s_rect.width + 15) / 2) + st->s_rect.width + 15 > st->Width - 5) st->s_rect.x = st->Width - 15 - st->s_rect.width; if (st->y - st->s_rect.height - 10 < 5) st->s_rect.y = st->y + 64 + 5; else st->s_rect.y = st->y - 5 - st->s_rect.height; XFillRectangle(st->dpy, st->window, st->text_bg_gc, st->s_rect.x, st->s_rect.y, st->s_rect.width, st->s_rect.height); /* make a box that's 5 pixels thick. Then add a thin box inside it */ XSetLineAttributes(st->dpy, st->text_fg_gc, 5, 0, 0, 0); XDrawRectangle(st->dpy, st->window, st->text_fg_gc, st->s_rect.x, st->s_rect.y, st->s_rect.width - 1, st->s_rect.height - 1); XSetLineAttributes(st->dpy, st->text_fg_gc, 0, 0, 0, 0); XDrawRectangle(st->dpy, st->window, st->text_fg_gc, st->s_rect.x + 7, st->s_rect.y + 7, st->s_rect.width - 15, st->s_rect.height - 15); st->X = 15; st->Y = 15 + font_height(st->font); /* now print each string in reverse order (start at bottom of box) */ for (Z = 0; Z < height; Z++) { int L = strlen(args[Z]); /* If there are continuous new lines, L can be 0 */ if (L && (args[Z][L-1] == '\r' || args[Z][L-1] == '\n')) args[Z][--L] = 0; XDrawString(st->dpy, st->window, st->text_fg_gc, st->s_rect.x + st->X, st->s_rect.y + st->Y, args[Z], L); st->Y += font_height(st->font); } st->interval = (total / 15) * 1000; if (st->interval < 2000) st->interval = 2000; st->next_fn = talk_1; *st->words = 0; st->lines = 0; }
/* * Draw a trace from pixel coordinates (x0,0) to (x0+xn, height). */ void trace_draw_trace(DNATrace *t, Display *d, Pixmap p, int x0, int xn, int yoff, int height) { double yscale; int m = t->read->maxTraceVal; if (x0 < 0) { xn += x0; x0 = 0; if (xn <= 0) return; } if (x0 + xn > t->read->NPoints) xn = t->read->NPoints - x0; trace_update_extents(t, &x0, &xn); if (xn <= 0) return; if (t->show_conf) { if (t->style == STYLE_STICK) trace_draw_confidence4(t, d, p, x0, xn, height); else trace_draw_confidence(t, d, p, x0, xn, height); } if (t->read->traceA == 0 || p == 0) return; if (t->read->maxTraceVal) { int c = (t->show_conf && t->style == STYLE_STICK) ? 20 : 0; yscale = (double)(t->scale_y * (height-1-c)) / (double)(t->trace_scale ? t->trace_scale : t->read->maxTraceVal); } else { yscale = 0; } switch (t->style) { case STYLE_CHROMA: trace_draw2(t, &t->read->traceA[x0], d, p, m, t->Agc, x0, xn, yoff, height, yscale, t->read->baseline, 1); trace_draw2(t, &t->read->traceC[x0], d, p, m, t->Cgc, x0, xn, yoff, height, yscale, t->read->baseline, 1); trace_draw2(t, &t->read->traceG[x0], d, p, m, t->Ggc, x0, xn, yoff, height, yscale, t->read->baseline, 1); trace_draw2(t, &t->read->traceT[x0], d, p, m, t->Tgc, x0, xn, yoff, height, yscale, t->read->baseline, 1); break; #if 0 case STYLE_FILLED: trace_draw2filled(t, d, p, m, x0, xn, height, yscale, t->read->baseline); break; #endif case STYLE_PYRO: trace_draw_hist(t, &t->read->traceA[x0], d, p, m, t->Agc, x0, xn, yoff, height, yscale, t->read->baseline); trace_draw_hist(t, &t->read->traceC[x0], d, p, m, t->Cgc, x0, xn, yoff, height, yscale, t->read->baseline); trace_draw_hist(t, &t->read->traceG[x0], d, p, m, t->Ggc, x0, xn, yoff, height, yscale, t->read->baseline); trace_draw_hist(t, &t->read->traceT[x0], d, p, m, t->Tgc, x0, xn, yoff, height, yscale, t->read->baseline); break; case STYLE_STICK: trace_draw_hist(t, &t->read->traceA[x0], d, p, m, t->Agc, x0, xn, yoff, height, yscale, t->read->baseline); trace_draw_hist(t, &t->read->traceC[x0], d, p, m, t->Cgc, x0+.15, xn, yoff, height, yscale, t->read->baseline); trace_draw_hist(t, &t->read->traceG[x0], d, p, m, t->Ggc, x0+.3, xn, yoff, height, yscale, t->read->baseline); trace_draw_hist(t, &t->read->traceT[x0], d, p, m, t->Tgc, x0+.45, xn, yoff, height, yscale, t->read->baseline); /* trace_draw_pyro(t, d, p, x0, xn, yoff, height, yscale); */ break; } if (t->yticks) trace_draw_yticks(t, d, p, t->CursorGC, x0, xn, yoff, height, yscale, t->read->baseline); if (t->show_edits == 0) { int pos; pos = point_to_pixel(t, trace_get_pos(t, t->cursor_pos)); XFillRectangle(d, p, t->CursorGC, pos-1, yoff, 1, height); } }
static void drawcell(ModeInfo * mi, int col, int row, unsigned long color, int bitmap, Bool firstChange) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); dilemmastruct *dp = &dilemmas[MI_SCREEN(mi)]; unsigned long colour = (MI_NPIXELS(mi) >= COLORS) ? color : MI_WHITE_PIXEL(mi); XSetForeground(display, gc, colour); if (dp->neighbors == 6) { int ccol = 2 * col + !(row & 1), crow = 2 * row; if (dp->vertical) { dp->shape.hexagon[0].x = dp->xb + ccol * dp->xs; dp->shape.hexagon[0].y = dp->yb + crow * dp->ys; } else { dp->shape.hexagon[0].y = dp->xb + ccol * dp->xs; dp->shape.hexagon[0].x = dp->yb + crow * dp->ys; } if (dp->xs == 1 && dp->ys == 1) XDrawPoint(display, window, gc, dp->shape.hexagon[0].x, dp->shape.hexagon[0].y); else if (bitmap == BITMAPS - 1) XFillPolygon(display, window, gc, dp->shape.hexagon, 6, Convex, CoordModePrevious); else { int ix = 0, iy = 0, sx, sy; if (firstChange) { XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillPolygon(display, window, gc, dp->shape.hexagon, 6, Convex, CoordModePrevious); XSetForeground(display, gc, colour); } if (dp->vertical) { dp->shape.hexagon[0].x -= dp->xs; dp->shape.hexagon[0].y += dp->ys / 4; sx = 2 * dp->xs - 6; sy = 2 * dp->ys - 2; if (dp->xs <= 6 || dp->ys <= 2) { ix = 3; iy = 1; } else ix = 5; } else { dp->shape.hexagon[0].y -= dp->xs; dp->shape.hexagon[0].x += dp->ys / 4; sy = 2 * dp->xs - 6; sx = 2 * dp->ys - 2; if (dp->xs <= 6 || dp->ys <= 2) { iy = 3; ix = 1; } else iy = 5; } if (dp->xs <= 6 || dp->ys <= 2) XFillRectangle(display, window, gc, dp->shape.hexagon[0].x + ix, dp->shape.hexagon[0].y + iy, dp->xs, dp->ys); else XFillArc(display, window, gc, dp->shape.hexagon[0].x + ix, dp->shape.hexagon[0].y + iy, sy, sy, 0, 23040); } } else if (dp->neighbors == 4 || dp->neighbors == 8) { if (dp->pixelmode) { if (bitmap == BITMAPS - 1 || (dp->xs <= 2 || dp->ys <= 2)) XFillRectangle(display, window, gc, dp->xb + dp->xs * col, dp->yb + dp->ys * row, dp->xs - (dp->xs > 3), dp->ys - (dp->ys > 3)); else { if (firstChange) { XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillRectangle(display, window, gc, dp->xb + dp->xs * col, dp->yb + dp->ys * row, dp->xs, dp->ys); XSetForeground(display, gc, colour); } XFillArc(display, window, gc, dp->xb + dp->xs * col, dp->yb + dp->ys * row, dp->xs - 1, dp->ys - 1, 0, 23040); } } else (void) XPutImage(display, window, gc, &logo[bitmap], 0, 0, dp->xb + dp->xs * col, dp->yb + dp->ys * row, icon_width, icon_height); } else { /* TRI */ int orient = (col + row) % 2; /* O left 1 right */ Bool small = (dp->xs <= 3 || dp->ys <= 3); int ix = 0, iy = 0; if (dp->vertical) { dp->shape.triangle[orient][0].x = dp->xb + col * dp->xs; dp->shape.triangle[orient][0].y = dp->yb + row * dp->ys; if (small) dp->shape.triangle[orient][0].x += ((orient) ? -1 : 1); else dp->shape.triangle[orient][0].x += (dp->xs / 2 - 1) * ((orient) ? 1 : -1); ix = ((orient) ? -dp->xs / 2 : dp->xs / 2); } else { dp->shape.triangle[orient][0].y = dp->xb + col * dp->xs; dp->shape.triangle[orient][0].x = dp->yb + row * dp->ys; if (small) dp->shape.triangle[orient][0].y += ((orient) ? -1 : 1); else dp->shape.triangle[orient][0].y += (dp->xs / 2 - 1) * ((orient) ? 1 : -1); iy = ((orient) ? -dp->xs / 2 : dp->xs / 2); } if (small) XDrawPoint(display, window, gc, dp->shape.triangle[orient][0].x, dp->shape.triangle[orient][0].y); else { if (bitmap == BITMAPS - 1) { XFillPolygon(display, window, gc, dp->shape.triangle[orient], 3, Convex, CoordModePrevious); XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XDrawLines(display, window, gc, dp->shape.triangle[orient], 4, CoordModePrevious); } else { if (firstChange) { XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillPolygon(display, window, gc, dp->shape.triangle[orient], 3, Convex, CoordModePrevious); XSetForeground(display, gc, colour); } if (dp->vertical) { dp->shape.triangle[orient][0].x += -4 * dp->xs / 5 + ((orient) ? dp->xs / 3 : 3 * dp->xs / 5); dp->shape.triangle[orient][0].y += -dp->ys / 2 + 1; ix = ((orient) ? -dp->xs / 2 : dp->xs / 2); } else { dp->shape.triangle[orient][0].y += -4 * dp->xs / 5 + ((orient) ? dp->xs / 3 : 3 * dp->xs / 5); dp->shape.triangle[orient][0].x += -dp->ys / 2 + 1; iy = ((orient) ? -dp->xs / 2 : dp->xs / 2); } XFillArc(display, window, gc, dp->shape.triangle[orient][0].x + ix, dp->shape.triangle[orient][0].y + iy, dp->ys - 3, dp->ys - 3, 0, 23040); } } } }
static void displayDTIcon(DTIconRec *dticon) { XGCValues xgcv; GC shapeGC; Window shellwin; XmString labelstr; Dimension labelwidth, labelheight, togglewidth, toggleheight; Dimension tgl_offs_x, lbl_offs_x, lbl_offs_y; Atom targets[2]; Boolean is_file = False; int i; targets[0] = dragAtoms.file; targets[1] = dragAtoms.filelist; drop_args[0].value = (XtArgVal) targets; dticon->app.form = XtVaCreateManagedWidget("form", xmFormWidgetClass, dticon->cont, XmNtranslations, XtParseTranslationTable(form_translations), XmNbackground, resources.dticon_color, XmNforeground, resources.label_color, XmNborderWidth, 0, XmNshadowThickness, 0, XmNhighlightThickness, 0, XmNx, 0, XmNy, 0, NULL); if (dticon->app.fname[0]) { char path[MAXPATHLEN]; struct stat stats; int errfl = 0; if (dticon->app.directory[0]) { strcpy(path, dticon->app.directory); fnexpand(path); errfl = chdir(path); } else errfl = chdir(user.home); if (!errfl && !(stat(dticon->app.fname, &stats)) && S_ISREG(stats.st_mode)) is_file = True; } if (is_file) { for (i=0; i < XtNumber(file_popup_menu); i++) file_popup_menu[i].callback_data = dticon; dticon->popup = BuildMenu(dticon->app.form, XmMENU_POPUP, "Button Actions", 0, False, file_popup_menu); if (resources.auto_save) XtVaSetValues(file_popup_menu[5].object, XmNsensitive, False, NULL); } else { for (i=0; i < XtNumber(file_popup_menu); i++) popup_menu[i].callback_data = dticon; dticon->popup = BuildMenu(dticon->app.form, XmMENU_POPUP, "Button Actions", 0, False, popup_menu); if (resources.auto_save) XtVaSetValues(popup_menu[3].object, XmNsensitive, False, NULL); } labelstr = XmStringCreateLocalized(dticon->app.name); labelwidth = XmStringWidth((XmFontList) resources.icon_font, labelstr) + 2; togglewidth = dticon->app.icon_pm.width; toggleheight = dticon->app.icon_pm.height; if (labelwidth > togglewidth) { tgl_offs_x = (labelwidth - togglewidth) / 2; lbl_offs_x = 0; } else { tgl_offs_x = 0; lbl_offs_x = (togglewidth - labelwidth) / 2; } lbl_offs_y = dticon->app.icon_pm.height + 2; dticon->app.toggle = XtVaCreateManagedWidget("picture", xmLabelWidgetClass, dticon->app.form, XmNlabelType, XmPIXMAP, XmNlabelPixmap, dticon->app.icon_pm.bm, XmNtranslations, trans, XmNborderWidth, 0, XmNhighlightThickness, 0, XmNbackground, resources.dticon_color, XmNforeground, resources.label_color, XmNx, tgl_offs_x, XmNy, 0, NULL); /* RBW - 2001/08/15 */ XtInsertEventHandler(dticon->app.toggle, EnterWindowMask|LeaveWindowMask, False, (XtEventHandler)CatchEntryLeave2, (XtPointer)0, XtListHead); dticon->app.label = XtVaCreateManagedWidget("label", xmLabelWidgetClass, dticon->app.form, XmNlabelString, labelstr, XmNfontList, resources.icon_font, XmNtranslations, trans, XmNbackground, resources.dticon_color, XmNforeground, resources.label_color, XmNborderWidth, 0, XmNhighlightThickness, 0, XmNx, lbl_offs_x, XmNy, lbl_offs_y, NULL); /* RBW - 2001/08/15 */ XtInsertEventHandler(dticon->app.label, EnterWindowMask|LeaveWindowMask, False, (XtEventHandler)CatchEntryLeave2, (XtPointer)0, XtListHead); XmStringFree(labelstr); XtRealizeWidget(dticon->shell); shellwin = XtWindow(dticon->shell); XtVaGetValues(dticon->app.label, XmNwidth, &labelwidth, XmNwidth, &labelheight, NULL); labelheight += 2; dticon->label_mask = XCreatePixmap(dpy, shellwin, labelwidth, labelheight, 1); shapeGC = XCreateGC(dpy, dticon->label_mask, 0, &xgcv); XSetForeground(dpy, shapeGC, 1); XFillRectangle(dpy, dticon->label_mask, shapeGC, 0, 0, labelwidth, labelheight); XFreeGC(dpy, shapeGC); if (dticon->app.icon_pm.mask == None) { dticon->app.icon_pm.mask = XCreatePixmap(dpy, shellwin, dticon->app.icon_pm.width, dticon->app.icon_pm.height, 1); shapeGC = XCreateGC(dpy, dticon->app.icon_pm.mask, 0, &xgcv); XSetForeground(dpy, shapeGC, 1); XFillRectangle(dpy, dticon->app.icon_pm.mask, shapeGC, 0, 0, togglewidth, toggleheight); XFreeGC(dpy, shapeGC); } XShapeCombineMask(dpy, shellwin, ShapeBounding, tgl_offs_x + 2, 2, dticon->app.icon_pm.mask, ShapeSet); XShapeCombineMask(dpy, shellwin, ShapeBounding, lbl_offs_x + 2, lbl_offs_y + 2, dticon->label_mask, ShapeUnion); XShapeCombineMask(dpy, XtWindow(dticon->app.form), ShapeClip, tgl_offs_x + 2, 2, dticon->app.icon_pm.mask, ShapeSet); XShapeCombineMask(dpy, XtWindow(dticon->app.form), ShapeClip, lbl_offs_x + 2, lbl_offs_y + 2, dticon->label_mask, ShapeUnion); XShapeCombineMask(dpy, XtWindow(dticon->app.toggle), ShapeClip, 2, 2, dticon->app.icon_pm.mask, ShapeSet); XtVaGetValues(dticon->shell, XmNwidth, &dticon->width, XmNheight, &dticon->height, NULL); dticon->drop_pixmap = XCreatePixmap(dpy, shellwin, dticon->width, dticon->height, DefaultDepth(dpy, DefaultScreen(dpy))); shapeGC = XCreateGC(dpy, dticon->drop_pixmap, 0, &xgcv); XSetForeground(dpy, shapeGC, resources.drop_color); XFillRectangle(dpy, dticon->drop_pixmap, shapeGC, 0, 0, dticon->width, dticon->height); XFreeGC(dpy, shapeGC); drop_args[4].value = (XtArgVal) dticon->drop_pixmap; if (dticon->app.drop_action[0]) XmDropSiteRegister(dticon->app.form, drop_args, XtNumber(drop_args)); }
static void draw_splash_window (saver_info *si) { splash_dialog_data *sp = si->sp_data; XGCValues gcv; GC gc1, gc2; int hspacing, vspacing, height; int x1, x2, x3, y1, y2; int sw; #ifdef PREFS_BUTTON int nbuttons = 3; #else /* !PREFS_BUTTON */ int nbuttons = 2; #endif /* !PREFS_BUTTON */ height = (sp->heading_font->ascent + sp->heading_font->descent + sp->body_font->ascent + sp->body_font->descent + sp->body_font->ascent + sp->body_font->descent + sp->button_font->ascent + sp->button_font->descent); vspacing = ((sp->height - (4 * sp->shadow_width) - (2 * sp->internal_border) - height) / 5); if (vspacing < 0) vspacing = 0; if (vspacing > (sp->heading_font->ascent * 2)) vspacing = (sp->heading_font->ascent * 2); gcv.foreground = sp->foreground; gc1 = XCreateGC (si->dpy, si->splash_dialog, GCForeground, &gcv); gc2 = XCreateGC (si->dpy, si->splash_dialog, GCForeground, &gcv); x1 = sp->logo_width; x3 = sp->width - (sp->shadow_width * 2); y1 = sp->internal_border; /* top heading */ XSetFont (si->dpy, gc1, sp->heading_font->fid); sw = string_width (sp->heading_font, sp->heading_label); x2 = (x1 + ((x3 - x1 - sw) / 2)); y1 += sp->heading_font->ascent; XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1, sp->heading_label, strlen(sp->heading_label)); y1 += sp->heading_font->descent; /* text below top heading */ XSetFont (si->dpy, gc1, sp->body_font->fid); y1 += vspacing + sp->body_font->ascent; sw = string_width (sp->body_font, sp->body_label); x2 = (x1 + ((x3 - x1 - sw) / 2)); XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1, sp->body_label, strlen(sp->body_label)); y1 += sp->body_font->descent; y1 += sp->body_font->ascent; sw = string_width (sp->body_font, sp->body2_label); x2 = (x1 + ((x3 - x1 - sw) / 2)); XDrawString (si->dpy, si->splash_dialog, gc1, x2, y1, sp->body2_label, strlen(sp->body2_label)); y1 += sp->body_font->descent; /* The buttons */ XSetForeground (si->dpy, gc1, sp->button_foreground); XSetForeground (si->dpy, gc2, sp->button_background); /* y1 += (vspacing * 2);*/ y1 = sp->height - sp->internal_border - sp->button_height; x1 += sp->internal_border; y2 = (y1 + ((sp->button_height - (sp->button_font->ascent + sp->button_font->descent)) / 2) + sp->button_font->ascent); hspacing = ((sp->width - x1 - (sp->shadow_width * 2) - sp->internal_border - (sp->button_width * nbuttons)) / 2); x2 = x1 + ((sp->button_width - string_width(sp->button_font, sp->demo_label)) / 2); XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1, sp->button_width, sp->button_height); XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2, sp->demo_label, strlen(sp->demo_label)); sp->demo_button_x = x1; sp->demo_button_y = y1; #ifdef PREFS_BUTTON x1 += hspacing + sp->button_width; x2 = x1 + ((sp->button_width - string_width(sp->button_font,sp->prefs_label)) / 2); XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1, sp->button_width, sp->button_height); XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2, sp->prefs_label, strlen(sp->prefs_label)); sp->prefs_button_x = x1; sp->prefs_button_y = y1; #endif /* PREFS_BUTTON */ #ifdef PREFS_BUTTON x1 += hspacing + sp->button_width; #else /* !PREFS_BUTTON */ x1 = (sp->width - sp->button_width - sp->internal_border - (sp->shadow_width * 2)); #endif /* !PREFS_BUTTON */ x2 = x1 + ((sp->button_width - string_width(sp->button_font,sp->help_label)) / 2); XFillRectangle (si->dpy, si->splash_dialog, gc2, x1, y1, sp->button_width, sp->button_height); XDrawString (si->dpy, si->splash_dialog, gc1, x2, y2, sp->help_label, strlen(sp->help_label)); sp->help_button_x = x1; sp->help_button_y = y1; /* The logo */ x1 = sp->shadow_width * 6; y1 = sp->shadow_width * 6; x2 = sp->logo_width - (sp->shadow_width * 12); y2 = sp->logo_height - (sp->shadow_width * 12); if (sp->logo_pixmap) { Window root; int x, y; unsigned int w, h, bw, d; XGetGeometry (si->dpy, sp->logo_pixmap, &root, &x, &y, &w, &h, &bw, &d); XSetForeground (si->dpy, gc1, sp->foreground); XSetBackground (si->dpy, gc1, sp->background); XSetClipMask (si->dpy, gc1, sp->logo_clipmask); XSetClipOrigin (si->dpy, gc1, x1 + ((x2 - (int)w) /2), y1 + ((y2 - (int)h) / 2)); if (d == 1) XCopyPlane (si->dpy, sp->logo_pixmap, si->splash_dialog, gc1, 0, 0, w, h, x1 + ((x2 - (int)w) / 2), y1 + ((y2 - (int)h) / 2), 1); else XCopyArea (si->dpy, sp->logo_pixmap, si->splash_dialog, gc1, 0, 0, w, h, x1 + ((x2 - (int)w) / 2), y1 + ((y2 - (int)h) / 2)); } /* Solid border inside the logo box. */ #if 0 XSetForeground (si->dpy, gc1, sp->foreground); XDrawRectangle (si->dpy, si->splash_dialog, gc1, x1, y1, x2-1, y2-1); #endif /* The shadow around the logo */ draw_shaded_rectangle (si->dpy, si->splash_dialog, sp->shadow_width * 4, sp->shadow_width * 4, sp->logo_width - (sp->shadow_width * 8), sp->logo_height - (sp->shadow_width * 8), sp->shadow_width, sp->shadow_bottom, sp->shadow_top); /* The shadow around the whole window */ draw_shaded_rectangle (si->dpy, si->splash_dialog, 0, 0, sp->width, sp->height, sp->shadow_width, sp->shadow_top, sp->shadow_bottom); XFreeGC (si->dpy, gc1); XFreeGC (si->dpy, gc2); update_splash_window (si); }