static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h) { XTransform transform; Picture windowPicture; Picture primaryPicture; XRenderPictureAttributes pa; XRenderPictFormat* picFormat; double xScalingFactor; double yScalingFactor; int x2; int y2; if (xfc->scaledWidth <= 0 || xfc->scaledHeight <= 0) { WLog_ERR(TAG, "the current window dimensions are invalid"); return; } if (xfc->sessionWidth <= 0 || xfc->sessionHeight <= 0) { WLog_ERR(TAG, "the window dimensions are invalid"); return; } xScalingFactor = xfc->sessionWidth / (double)xfc->scaledWidth; yScalingFactor = xfc->sessionHeight / (double)xfc->scaledHeight; XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, 0); /* Black out possible space between desktop and window borders */ { XRectangle box1 = { 0, 0, xfc->window->width, xfc->window->height }; XRectangle box2 = { xfc->offset_x, xfc->offset_y, xfc->scaledWidth, xfc->scaledHeight }; Region reg1 = XCreateRegion(); Region reg2 = XCreateRegion(); XUnionRectWithRegion(&box1, reg1, reg1); XUnionRectWithRegion(&box2, reg2, reg2); if (XSubtractRegion(reg1, reg2, reg1) && !XEmptyRegion(reg1)) { XSetRegion(xfc->display, xfc->gc, reg1); XFillRectangle(xfc->display, xfc->window->handle, xfc->gc, 0, 0, xfc->window->width, xfc->window->height); XSetClipMask(xfc->display, xfc->gc, None); } XDestroyRegion(reg1); XDestroyRegion(reg2); } picFormat = XRenderFindVisualFormat(xfc->display, xfc->visual); pa.subwindow_mode = IncludeInferiors; primaryPicture = XRenderCreatePicture(xfc->display, xfc->primary, picFormat, CPSubwindowMode, &pa); windowPicture = XRenderCreatePicture(xfc->display, xfc->window->handle, picFormat, CPSubwindowMode, &pa); XRenderSetPictureFilter(xfc->display, primaryPicture, FilterBilinear, 0, 0); transform.matrix[0][0] = XDoubleToFixed(xScalingFactor); transform.matrix[0][1] = XDoubleToFixed(0.0); transform.matrix[0][2] = XDoubleToFixed(0.0); transform.matrix[1][0] = XDoubleToFixed(0.0); transform.matrix[1][1] = XDoubleToFixed(yScalingFactor); transform.matrix[1][2] = XDoubleToFixed(0.0); transform.matrix[2][0] = XDoubleToFixed(0.0); transform.matrix[2][1] = XDoubleToFixed(0.0); transform.matrix[2][2] = XDoubleToFixed(1.0); /* calculate and fix up scaled coordinates */ x2 = x + w; y2 = y + h; x = floor(x / xScalingFactor) - 1; y = floor(y / yScalingFactor) - 1; w = ceil(x2 / xScalingFactor) + 1 - x; h = ceil(y2 / yScalingFactor) + 1 - y; XRenderSetPictureTransform(xfc->display, primaryPicture, &transform); XRenderComposite(xfc->display, PictOpSrc, primaryPicture, 0, windowPicture, x, y, 0, 0, xfc->offset_x + x, xfc->offset_y + y, w, h); XRenderFreePicture(xfc->display, primaryPicture); XRenderFreePicture(xfc->display, windowPicture); }
int main(){ //Pontos iniciais Ponto P1, P2, P3, P4, P5, P6, P7, P8; float se, co, tz, cpz; //Pontos rotacionados Ponto *rP1, *rP2, *rP3, *rP4, *rP5, *rP6, *rP7, *rP8; //Pontos Projetados perspectivamente Ponto *iP1, *iP2, *iP3, *iP4, *iP5, *iP6, *iP7, *iP8; //Declaração da matriz de rotação struct matriz4x4 mRotaciona; int RXmin,RXmax,RYmin,RYmax,a,b; Window win; Display *display; int width = 256, height = 256, x = 0, y = 0, i, tx, ty,ref,rot; GC gc; unsigned long valuemask = 0; XGCValues values; XColor cor; P1.x = 30; P1.y = -10; P1.z = 10; P1.W = 1; P2.x = 30; P2.y = -10; P2.z = -10; P2.W = 1; P3.x = 30; P3.y = 10; P3.z = 10; P3.W = 1; P4.x = 30; P4.y = 10; P4.z = -10; P4.W = 1; P5.x = -30; P5.y = -10; P5.z = 10; P5.W = 1; P6.x = -30; P6.y = -10; P6.z = -10; P6.W = 1; P7.x = -30; P7.y = 10; P7.z = 10; P7.W = 1; P8.x = -30; P8.y = 10; P8.z = -10; P8.W = 1; //Variaveis para calculo do seno e cosseno do angulo de rotacao se = sin(90*PI/180); co = cos(90*PI/180); //Inicializacao da matriz de Rotacao em relacao ao eixo z mRotaciona.a11 = co; mRotaciona.a12 = -se; mRotaciona.a13 = 0; mRotaciona.a14 = 0; mRotaciona.a21 = se; mRotaciona.a22 = co; mRotaciona.a23 = 0; mRotaciona.a24 = 0; mRotaciona.a31 = 0; mRotaciona.a32 = 0; mRotaciona.a33 = 1; mRotaciona.a34 = 0; mRotaciona.a41 = 0; mRotaciona.a42 = 0; mRotaciona.a43 = 0; mRotaciona.a44 = 1; //************************************** (a) ********************************************** //Estou utilizando a regra da mão direita //Chamada da funcao que rotaciona o ponto rP1 = rotaciona(&mRotaciona, &P1); rP2 = rotaciona(&mRotaciona, &P2); rP3 = rotaciona(&mRotaciona, &P3); rP4 = rotaciona(&mRotaciona, &P4); rP5 = rotaciona(&mRotaciona, &P5); rP6 = rotaciona(&mRotaciona, &P6); rP7 = rotaciona(&mRotaciona, &P7); rP8 = rotaciona(&mRotaciona, &P8); //************************************** (b) ********************************************** //Projeção Perspectiva printf("\n\nDigite o valor Tz: \n"); scanf("%f",&tz); printf("\nDigite o valor Cpz: \n"); scanf("%f",&cpz); iP1 = Projeta(tz, cpz, rP1); iP2 = Projeta(tz, cpz, rP2); iP3 = Projeta(tz, cpz, rP3); iP4 = Projeta(tz, cpz, rP4); iP5 = Projeta(tz, cpz, rP5); iP6 = Projeta(tz, cpz, rP6); iP7 = Projeta(tz, cpz, rP7); iP8 = Projeta(tz, cpz, rP8); //************************************** (c) ********************************************** //Entrada dos valores do retangulo de visualizacao printf("\n\nDigite o valor do RXmin: \n"); scanf("%f",&RXmin); printf("\nDigite o valor RXmax: \n"); scanf("%f",&RXmax); printf("\n\nDigite o valor do RYmin: \n"); scanf("%f",&RYmin); printf("\nDigite o valor RYmax: \n"); scanf("%f",&RYmax); //width = modulo(RXmin) + modulo(RXmax); //height = modulo(RYmin) + modulo(RYmax); win = XCreateSimpleWindow(display, RootWindow(display, DefaultScreen(display)), x, y, width, height, 4, BlackPixel(display, DefaultScreen(display)), WhitePixel(display, DefaultScreen(display))); XMapWindow(display, win); gc = XCreateGC(display, win, valuemask, &values); XSync(display, False); XSetForeground(display, gc, WhitePixel(display, DefaultScreen(display))); XSetBackground(display, gc, BlackPixel(display, DefaultScreen(display))); XAllocNamedColor(display, XDefaultColormap(display, DefaultScreen(display)),"black", &cor, &cor); XSetForeground(display, gc, cor.pixel); //Desenhando os pontos a = iP1->x; b = iP1->y; XDrawPoint(display, win, gc, a, b); a = iP2->x; b = iP2->y; XDrawPoint(display, win, gc, a, b); a = iP1->x; b = iP1->y; XDrawPoint(display, win, gc, a, b); a = iP1->x; b = iP1->y; XDrawPoint(display, win, gc, a, b); a = iP1->x; b = iP1->y; XDrawPoint(display, win, gc, a, b); a = iP1->x; b = iP1->y; XDrawPoint(display, win, gc, a, b); a = iP1->x; b = iP1->y; XDrawPoint(display, win, gc, a, b); a = iP1->x; b = iP1->y; XDrawPoint(display, win, gc, a, b); //Desenhando as 12 retas reta(&win, &gc, display,iP1->x,iP2->x,iP1->y,iP2->y); reta(&win, &gc, display,iP2->x,iP4->x,iP2->y,iP4->y); reta(&win, &gc, display,iP4->x,iP3->x,iP4->y,iP3->y); reta(&win, &gc, display,iP3->x,iP1->x,iP3->y,iP1->y); reta(&win, &gc, display,iP1->x,iP5->x,iP1->y,iP5->y); reta(&win, &gc, display,iP2->x,iP6->x,iP2->y,iP6->y); reta(&win, &gc, display,iP3->x,iP7->x,iP3->y,iP7->y); reta(&win, &gc, display,iP4->x,iP8->x,iP4->y,iP8->y); reta(&win, &gc, display,iP5->x,iP6->x,iP5->y,iP6->y); reta(&win, &gc, display,iP6->x,iP8->x,iP6->y,iP8->y); reta(&win, &gc, display,iP8->x,iP7->x,iP8->y,iP7->y); reta(&win, &gc, display,iP7->x,iP5->x,iP7->y,iP5->y); XFlush(display); sleep(30); XFreeGC(display, gc); XCloseDisplay(display); return 0; }
int get_pen(XColor desired_col) { XSetForeground(dpy, gc, desired_col.pixel); // Tell the GC we draw using the desired color return(0); }
void xf_gdi_polyline(rdpContext* context, POLYLINE_ORDER* polyline) { int i; int x, y; int x1, y1; int x2, y2; int npoints; UINT32 color; XPoint* points; int width, height; xfContext* xfc = (xfContext*) context; xf_lock_x11(xfc, FALSE); xf_set_rop2(xfc, polyline->bRop2); color = freerdp_convert_gdi_order_color(polyline->penColor, context->settings->ColorDepth, xfc->format, xfc->palette); color = xf_gdi_get_color(xfc, color); XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, color); npoints = polyline->numPoints + 1; points = malloc(sizeof(XPoint) * npoints); points[0].x = polyline->xStart; points[0].y = polyline->yStart; for (i = 0; i < polyline->numPoints; i++) { points[i + 1].x = polyline->points[i].x; points[i + 1].y = polyline->points[i].y; } XDrawLines(xfc->display, xfc->drawing, xfc->gc, points, npoints, CoordModePrevious); if (xfc->drawing == xfc->primary) { if (!xfc->remote_app) { XDrawLines(xfc->display, xfc->drawable, xfc->gc, points, npoints, CoordModePrevious); } x1 = points[0].x; y1 = points[0].y; for (i = 1; i < npoints; i++) { x2 = points[i].x + x1; y2 = points[i].y + y1; x = (x2 < x1) ? x2 : x1; width = (x2 > x1) ? x2 - x1 : x1 - x2; y = (y2 < y1) ? y2 : y1; height = (y2 > y1) ? y2 - y1 : y1 - y2; x1 = x2; y1 = y2; gdi_InvalidateRegion(xfc->hdc, x, y, width, height); } } XSetFunction(xfc->display, xfc->gc, GXcopy); free(points); xf_unlock_x11(xfc, FALSE); }
void xf_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb) { int i, npoints; XPoint* points; Pixmap pattern; rdpBrush* brush; UINT32 foreColor; UINT32 backColor; xfContext* xfc = (xfContext*) context; xf_lock_x11(xfc, FALSE); brush = &(polygon_cb->brush); xf_set_rop2(xfc, polygon_cb->bRop2); foreColor = freerdp_convert_gdi_order_color(polygon_cb->foreColor, context->settings->ColorDepth, xfc->format, xfc->palette); foreColor = xf_gdi_get_color(xfc, foreColor); backColor = freerdp_convert_gdi_order_color(polygon_cb->backColor, context->settings->ColorDepth, xfc->format, xfc->palette); backColor = xf_gdi_get_color(xfc, backColor); npoints = polygon_cb->numPoints + 1; points = malloc(sizeof(XPoint) * npoints); points[0].x = polygon_cb->xStart; points[0].y = polygon_cb->yStart; for (i = 0; i < polygon_cb->numPoints; i++) { points[i + 1].x = polygon_cb->points[i].x; points[i + 1].y = polygon_cb->points[i].y; } switch (polygon_cb->fillMode) { case GDI_FILL_ALTERNATE: /* alternate */ XSetFillRule(xfc->display, xfc->gc, EvenOddRule); break; case GDI_FILL_WINDING: /* winding */ XSetFillRule(xfc->display, xfc->gc, WindingRule); break; default: WLog_ERR(TAG, "PolygonCB unknown fillMode: %d", polygon_cb->fillMode); break; } if (brush->style == GDI_BS_PATTERN) { if (brush->bpp > 1) { pattern = xf_brush_new(xfc, 8, 8, brush->bpp, brush->data); XSetFillStyle(xfc->display, xfc->gc, FillTiled); XSetTile(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); XFillPolygon(xfc->display, xfc->drawing, xfc->gc, points, npoints, Complex, CoordModePrevious); if (xfc->drawing == xfc->primary) { XFillPolygon(xfc->display, xfc->drawable, xfc->gc, points, npoints, Complex, CoordModePrevious); } XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetTSOrigin(xfc->display, xfc->gc, 0, 0); XFreePixmap(xfc->display, pattern); } else { pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data); XSetForeground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, foreColor); if (polygon_cb->backMode == BACKMODE_TRANSPARENT) XSetFillStyle(xfc->display, xfc->gc, FillStippled); else if (polygon_cb->backMode == BACKMODE_OPAQUE) XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetStipple(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); XFillPolygon(xfc->display, xfc->drawing, xfc->gc, points, npoints, Complex, CoordModePrevious); if (xfc->drawing == xfc->primary) { XFillPolygon(xfc->display, xfc->drawable, xfc->gc, points, npoints, Complex, CoordModePrevious); } XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetTSOrigin(xfc->display, xfc->gc, 0, 0); XFreePixmap(xfc->display, pattern); } } else { WLog_ERR(TAG, "PolygonCB unimplemented brush style:%d", brush->style); } XSetFunction(xfc->display, xfc->gc, GXcopy); free(points); xf_unlock_x11(xfc, FALSE); }
static struct throbber * make_throbber (struct state *st, Drawable d, int w, int h, unsigned long pixel) { XGCValues gcv; unsigned long flags; struct throbber *t = (struct throbber *) malloc (sizeof (*t)); t->x = w / 2; t->y = h / 2; t->max_size = (w > h ? w : h); t->speed = get_integer_resource (st->dpy, "speed", "Speed"); t->fuse = 1 + (random() % 4); t->thickness = get_integer_resource (st->dpy, "thickness", "Thickness"); if (st->xgwa.width > 2560) t->thickness *= 3; /* Retina displays */ if (t->speed < 0) t->speed = -t->speed; t->speed += (((random() % t->speed) / 2) - (t->speed / 2)); if (t->speed > 0) t->speed = -t->speed; flags = GCForeground; # ifndef HAVE_JWXYZ if (st->transparent_p) { gcv.foreground = ~0L; gcv.plane_mask = st->base_pixel | st->plane_masks[random() % st->nplanes]; flags |= GCPlaneMask; } else # endif /* !HAVE_JWXYZ */ { gcv.foreground = pixel; } gcv.line_width = t->thickness; gcv.cap_style = CapProjecting; gcv.join_style = JoinMiter; flags |= (GCLineWidth | GCCapStyle | GCJoinStyle); t->gc = XCreateGC (st->dpy, d, flags, &gcv); # ifdef HAVE_JWXYZ if (st->transparent_p) { /* give a non-opaque alpha to the color */ unsigned long pixel = gcv.foreground; unsigned long amask = BlackPixelOfScreen (st->xgwa.screen); unsigned long a = (0xCCCCCCCC & amask); pixel = (pixel & (~amask)) | a; jwxyz_XSetAlphaAllowed (st->dpy, t->gc, True); XSetForeground (st->dpy, t->gc, pixel); } # endif /* HAVE_JWXYZ */ switch (random() % 11) { case 0: case 1: case 2: case 3: t->draw = draw_star; break; case 4: case 5: case 6: case 7: t->draw = draw_circle; break; case 8: t->draw = draw_hlines; break; case 9: t->draw = draw_vlines; break; case 10: t->draw = draw_corners; break; default: abort(); break; } if (t->draw == draw_circle) t->max_size *= 1.5; if (random() % 4) t->size = t->max_size; else t->size = t->thickness, t->speed = -t->speed; return t; }
void XPlatformWindow::set_color(int c) { XSetForeground (_display, _gc, c); }
/***** * Name: drawBalloonShaped * Return Type: void * Description: pops up the balloon widget as a shaped window * In: * w: XmBalloon Widget id; * x: absolute x popup position; * y: absolute y popup position; * width: desired widget width; * Returns: * nothing * Note: * This routine composes a *clipmask* for the widget to use when * it is displayed. The clipmask is initially empty and gets filled * according to the selected options. Once it is filled, the text * is rendered in the selected color. *****/ static void drawBalloonShaped(Widget w, Position x, Position y, int width) { BALLOON = (XmBalloonWidget)w; XGCValues xgc; int face_width, face_height, x_offset, y_offset; Dimension bwidth, bheight; Pixmap shape_mask; Display *dpy = XtDisplay(w); Window win = XtWindow(w); /* horizontal offset for text rendering */ x_offset = ATTR(margin_width) + ATTR(font_width); y_offset = 0.25 * ATTR(font_height); bwidth = 2*ATTR(margin_width) + width + 2*x_offset; bheight = 2*ATTR(margin_height) + ATTR(font_height) + 2*y_offset; /* resize to fit */ XtResizeWidget(w, bwidth, bheight, balloon->core.border_width); /* compute desired border size */ setTransform(&ATTR(maskt), 0, bwidth, bheight, 0, -1.0, 1.0, -1.0, 1.0); face_width = abs(Xwidth(BORDER_SIZE(balloon), BORDER_SIZE(balloon), &(ATTR(maskt)))); face_height = abs(Xheight(BORDER_SIZE(balloon), BORDER_SIZE(balloon), &(ATTR(maskt)))); setTransform(&ATTR(t), face_width, bwidth - face_width, bheight - face_height, face_height, -WINDOW_WIDTH(balloon)/2, WINDOW_WIDTH(balloon)/2, -WINDOW_HEIGHT(balloon)/2, WINDOW_HEIGHT(balloon)/2); /* Free up previous clipmask if the size differs */ if(ATTR(shape_mask) && ATTR(shape_width) != w->core.width && ATTR(shape_height) != w->core.height) { XFreePixmap(dpy, ATTR(shape_mask)); ATTR(shape_mask) = None; } /* allocate a clipmask (bitmap of depth one) */ if(!(ATTR(shape_mask))) { ATTR(shape_mask) = XCreatePixmap(dpy, win, bwidth, bheight, 1); ATTR(shape_width) = bwidth; ATTR(shape_height) = bheight; } shape_mask = ATTR(shape_mask); /* simple gc */ if(!(ATTR(shape_gc))) ATTR(shape_gc) = XCreateGC(dpy, shape_mask, 0, &xgc); /* make it fully transparent */ XSetForeground(dpy, ATTR(shape_gc), 0); XFillRectangle(dpy, shape_mask, ATTR(shape_gc), 0, 0, bwidth, bheight); XSetForeground(dpy, ATTR(shape_gc), 1); /***** * Fill in the border bits if we have a border. If we aren't transparent * a filled arc is created. *****/ if(ATTR(border_size) > 0.0 || !ATTR(transparent)) { FillArc(dpy, shape_mask, ATTR(shape_gc), &(ATTR(maskt)), -1.0, -1.0, 2.0, 2.0, 0, 360*64); } /***** * if we are being transparent, erase the inner part of the disk * and fill the bits for the text. If we aren't transparent we don't * have to do this 'cause the bits set for the disk already cover the * bits that cover the text. *****/ if(ATTR(transparent)) { if(ATTR(border_size) > 0.0) { XSetForeground(dpy, ATTR(shape_gc), 0); FillArc(dpy, shape_mask, ATTR(shape_gc), &(ATTR(maskt)), -WINDOW_WIDTH(balloon)/2, -WINDOW_HEIGHT(balloon)/2, WINDOW_WIDTH(balloon), WINDOW_HEIGHT(balloon), 0, 360*64); XSetForeground(dpy, ATTR(shape_gc), 1); } drawText(dpy, balloon, shape_mask, ATTR(shape_gc), x_offset, y_offset); } /* the highest enclosing widget is the widget itself */ XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, shape_mask, ShapeSet); /* erase clipmask */ XSetForeground(dpy, ATTR(shape_gc), 0); XFillRectangle(dpy, shape_mask, ATTR(shape_gc), 0, 0, bwidth, bheight); XSetForeground(dpy, ATTR(shape_gc), 1); /* draw clip shape */ if(ATTR(transparent)) { drawText(dpy, balloon, shape_mask, ATTR(shape_gc), x_offset, y_offset); } else { FillArc(dpy, shape_mask, ATTR(shape_gc), &(ATTR(t)), -WINDOW_WIDTH(balloon)/2, -WINDOW_HEIGHT(balloon)/2, WINDOW_WIDTH(balloon), WINDOW_HEIGHT(balloon), 0, 360*64); } /* compose final clipmask */ XShapeCombineMask(dpy, win, ShapeClip, 0, 0, shape_mask, ShapeSet); /* move to correct location */ XtMoveWidget((Widget)balloon, x + 4, y + 4); /***** * pop it up. * Note that the label can change when the widget is already popped. *****/ if(!ATTR(popped)) XtPopup((Widget)balloon, XtGrabNone); ATTR(popped) = True; /* draw the text */ drawText(dpy, balloon, win, ATTR(gc), x_offset, y_offset); /* if we have got a popdown timeout, add it */ if(ATTR(popdown_delay)) { ATTR(popdown_id) = XtAppAddTimeOut(ATTR(context), ATTR(popdown_delay), popdownBalloon, (XtPointer)balloon); } }
void x_drawable_rep::set_color (color c) { cur_fg= c; XSetForeground (dpy, gc, CONVERT (blend (cur_fg, cur_bg))); }
/*Convenience function for making buttons with icons on them*/ Window make_unmapped_icon_window(Window root, int x, int y, int width, int height, int bw, int icx, int icy, unsigned char *icdata) { Window win = make_plain_unmapped_window(root, x, y, width, height, bw); Pixmap pmap = XCreatePixmap(display, root, width, height, DefaultDepth(display, DefaultScreen(display))); Colormap cmap = DefaultColormap(display, DefaultScreen(display)); if (UserGradients == 1) { draw_gradient(pmap, width, height); } else { XColor bcolor; XParseColor(display, cmap, UserWhite, &bcolor); XAllocColor(display, cmap, &bcolor); XSetForeground(display, gc, bcolor.pixel); XDrawRectangle(display, pmap, gc, 0, 0, width, height); } int z = 0, row = 0, col = 0; if (icdata != NULL) { XColor diffcol; XParseColor(display, cmap, UserBlack, &diffcol); XAllocColor(display, cmap, &diffcol); XSetForeground(display, gc, diffcol.pixel); unsigned char *ps = icdata; int intstack[8]; col = 0; row = -1; z = 0; while (row < height) { col = 0; row++; while (1) { bin_prnt_byte(*ps, intstack); ps++; int q = 0; for (q = 0; q < 8; q++) /*8 bits per byte*/ { if (col >= width) { /*myint[z] = 0;*/ } else { if (intstack[q] == 1) { XDrawPoint(display, pmap, gc, col, row); } } z++; col++; } if (col >= width) { break; } } } } XSetWindowBackgroundPixmap(display, win, pmap); XFreePixmap(display, pmap); return win; }
/************************************************************************ * Description: This function creates a vertical color color bar. * * * * Input: display - pointer to Display information * * pixmap - Drawable * * gc - graphics context * * left_pixel - leftmost pixel for color bar/labels * * top_scanl - topmost scanline for color bar/labels * * height - height (scanlines) for color bar/labels * * width - width (pixels) for color bar/labels * * box_width - width (pixels) of a color bar element * * flag - flag to indicate last color range folding * * (1). Set to 0 for no special processing * * Output: NONE * * Return: NONE * ************************************************************************/ void hci_display_color_bar ( Display *display, /* The window Display */ Drawable pixmap, /* The drawable. */ GC gc, /* The graphics context */ int left_pixel, /* The leftmost pixel boundary for the color bar and text labels. */ int top_scanl, /* The topmost scanline boundary for the color bar and text labels. */ int height, /* The height (scanlines) for the color bar and labels. */ int width, /* The width (pixels) for the color bar and labels. */ int box_width, /* The width of a color bar box element. */ int flag /* Flag to indicate last color RF (1). Set to 0 for no special processing. */ ) { int i; int ii; int scanl; float xheight; int box_height; int start_index; int stop_index; int color_step; int fg_color; int product_colors [PRODUCT_COLORS]; int product_code; int num_levels; int RDA_config_code = -1; /* Get the product code of the currently open product. */ product_code = hci_product_code(); /* If the product has not been openned or the product code * * does not at least match the first product, do nothing. */ if (product_code < 16) { return; } /* Clear the area where the color bar is to be displayed. */ XSetForeground (display, gc, hci_get_read_color (BACKGROUND_COLOR1)); XFillRectangle (display, pixmap, gc, left_pixel, top_scanl, width, height); /* Get the product colors associated with the current product. */ hci_get_product_colors (product_code, product_colors); /* Define the color step and box intervals. */ if (hci_product_attribute_num_data_levels() > PRODUCT_COLORS) num_levels = PRODUCT_COLORS; else num_levels = hci_product_attribute_num_data_levels(); xheight = height/(1.5*num_levels); box_height = (xheight+1) * num_levels / num_levels; color_step = 1; if (hci_product_attribute_num_data_levels() == 8) color_step = 2; start_index = 0; /* If this is the CFC product (product_code == 34), then we need to display the color bar differently. */ if( product_code == 34 ) { /* Check RDA configuration. Legend display will differ depending on whether RDA is legacy or ORDA. */ RDA_config_code = ORPGRDA_get_rda_config ( NULL ); if( RDA_config_code == ORPGRDA_LEGACY_CONFIG ) { /* If RDA configuration is legacy... */ xheight = height/(1.5*16); box_height = (xheight+1) * 16 / 16; XSetForeground (display, gc, hci_get_read_color (BLACK)); scanl = top_scanl+20 + xheight; XDrawString (display, pixmap, gc, left_pixel+5, scanl+5, "DISABLE FILTER", 14); scanl = scanl + xheight; XDrawString (display, pixmap, gc, left_pixel+5, scanl+5, "(OP SEL CODE 0)", 15); scanl = scanl + xheight; XSetForeground (display, gc, product_colors [0]); XFillRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (WHITE)); XDrawRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (BLACK)); XDrawString (display, pixmap, gc, left_pixel+8+box_width, scanl+15, "FILTER OFF", 10); scanl = scanl + 3*xheight; XDrawString (display, pixmap, gc, left_pixel+5, scanl+5, "BYP MAP IN CTRL", 15); scanl = scanl + xheight; XDrawString (display, pixmap, gc, left_pixel+5, scanl+5, "(OP SEL CODE 1)", 15); scanl = scanl + xheight; XSetForeground (display, gc, product_colors [1]); XFillRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (BLACK)); XDrawRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XDrawString (display, pixmap, gc, left_pixel+8+box_width, scanl+15, "NO CLUTTER", 10); scanl = scanl + xheight; XSetForeground (display, gc, product_colors [2]); XFillRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (BLACK)); XDrawRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XDrawString (display, pixmap, gc, left_pixel+8+box_width, scanl+15, "LOW (1)", 11); scanl = scanl + xheight; XSetForeground (display, gc, product_colors [3]); XFillRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (BLACK)); XDrawRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XDrawString (display, pixmap, gc, left_pixel+8+box_width, scanl+15, "MEDIUM (2)", 11); scanl = scanl + xheight; XSetForeground (display, gc, product_colors [4]); XFillRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (BLACK)); XDrawRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XDrawString (display, pixmap, gc, left_pixel+8+box_width, scanl+15, "HIGH (3)", 11); scanl = scanl + 3*xheight; XDrawString (display, pixmap, gc, left_pixel+5, scanl+5, "FORCE FILTER", 12); scanl = scanl + xheight; XDrawString (display, pixmap, gc, left_pixel+5, scanl+5, "(OP SEL CODE 2)", 15); scanl = scanl + xheight; XSetForeground (display, gc, product_colors [5]); XFillRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (BLACK)); XDrawRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XDrawString (display, pixmap, gc, left_pixel+8+box_width, scanl+15, "LOW (1)", 11); scanl = scanl + xheight; XSetForeground (display, gc, product_colors [6]); XFillRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (BLACK)); XDrawRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XDrawString (display, pixmap, gc, left_pixel+8+box_width, scanl+15, "MEDIUM (2)", 11); scanl = scanl + xheight; XSetForeground (display, gc, product_colors [7]); XFillRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (BLACK)); XDrawRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XDrawString (display, pixmap, gc, left_pixel+8+box_width, scanl+15, "HIGH (3)", 11); } else { /* If RDA configuration is ORDA... */ xheight = height/(1.5*16); box_height = (xheight+1) * 16 / 16; XSetForeground (display, gc, hci_get_read_color (BLACK)); scanl = top_scanl+20 + xheight; XDrawString (display, pixmap, gc, left_pixel+5, scanl+5, "DISABLE FILTER", 14); scanl = scanl + xheight; XDrawString (display, pixmap, gc, left_pixel+5, scanl+5, "(OP SEL CODE 0)", 15); scanl = scanl + xheight; XSetForeground (display, gc, product_colors [0]); XFillRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (WHITE)); XDrawRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (BLACK)); XDrawString (display, pixmap, gc, left_pixel+8+box_width, scanl+15, "FILTER OFF", 10); scanl = scanl + 3*xheight; XDrawString (display, pixmap, gc, left_pixel+5, scanl+5, "BYP MAP IN CTRL", 15); scanl = scanl + xheight; XDrawString (display, pixmap, gc, left_pixel+5, scanl+5, "(OP SEL CODE 1)", 15); scanl = scanl + xheight; XSetForeground (display, gc, product_colors [1]); XFillRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (BLACK)); XDrawRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XDrawString (display, pixmap, gc, left_pixel+8+box_width, scanl+15, "NO CLUTTER", 10); scanl = scanl + xheight; XSetForeground (display, gc, product_colors [4]); XFillRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (BLACK)); XDrawRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XDrawString (display, pixmap, gc, left_pixel+8+box_width, scanl+15, "CLUTTER", 7); scanl = scanl + 3*xheight; XDrawString (display, pixmap, gc, left_pixel+5, scanl+5, "FORCE FILTER", 12); scanl = scanl + xheight; XDrawString (display, pixmap, gc, left_pixel+5, scanl+5, "(OP SEL CODE 2)", 15); scanl = scanl + xheight; XSetForeground (display, gc, product_colors [7]); XFillRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XSetForeground (display, gc, hci_get_read_color (BLACK)); XDrawRectangle (display, pixmap, gc, left_pixel+5, scanl, box_width, box_height); XDrawString (display, pixmap, gc, left_pixel+8+box_width, scanl+15, "FORCE FILTER", 12); } } else { /* If the input flag is set, we want to add an extra color and * * set it purple. It is intended to be used to denote RF but * * can be used otherwise. */ stop_index = num_levels*color_step; /* Define the foreground color to be used for text labels. */ fg_color = hci_get_read_color (BLACK); ii = start_index; /* for each color index, display a color box and label. */ for (i=start_index;i<stop_index;i=i+color_step) { scanl = top_scanl+20 + xheight*(i-start_index)/color_step; if ((i == (stop_index-1)) && (flag != 0)) { XSetForeground (display, gc, hci_get_read_color (PURPLE)); XFillRectangle (display, pixmap, gc, (left_pixel+40), scanl, box_width, box_height); if (hci_product_attribute_data_level (ii) != NULL) { XSetForeground (display, gc, fg_color); XDrawString (display, pixmap, gc, left_pixel, (scanl+5), " RF", 6); } } else { XSetForeground (display, gc, product_colors [i]); XFillRectangle (display, pixmap, gc, (left_pixel+40), scanl, box_width, box_height); if (hci_product_attribute_data_level (ii) != NULL) { XSetForeground (display, gc, fg_color); XDrawString (display, pixmap, gc, left_pixel, (scanl+5), (char *) hci_product_attribute_data_level (ii), strlen ((char *) hci_product_attribute_data_level (ii))); } ii++; } } /* Draw a rectangle around the perimeter of the color bar. */ XSetForeground (display, gc, fg_color); XDrawRectangle (display, pixmap, gc, (left_pixel+40), top_scanl+20, box_width, (int) (height/1.5)); /* Display the units text to the top right of the color bar */ if (hci_product_attribute_units () != NULL) { XDrawString (display, pixmap, gc, (left_pixel + 55), (top_scanl+25), hci_product_attribute_units (), strlen (hci_product_attribute_units ())); } } }
/** * paint adds a new layer of multicolored rectangles within a grid of * randomly generated size. Each row of rectangles is the same color, * but colors vary slightly from row to row. Each rectangle is placed * within a regularly-sized cell, but each rectangle is sized and * placed randomly within that cell. * * @param g the Graphics coordinate in which to draw * @see #genNewColor **/ static void paint(struct state *st) { int i; int cellsWide, cellsHigh, cellWidth, cellHeight; int width = st->xgwa.width; int height = st->xgwa.height; /* How many cells wide the grid is (equal to gridSize +/- (gridSize / 2)) */ cellsWide = c_tweak(st, st->gridSize, st->gridSize / 2); /* How many cells high the grid is (equal to gridSize +/- (gridSize / 2)) */ cellsHigh = c_tweak(st, st->gridSize, st->gridSize / 2); /* How wide each cell in the grid is */ cellWidth = width / cellsWide; /* How tall each cell in the grid is */ cellHeight = height / cellsHigh; /* Ensure that each cell is above a certain minimum size */ if (cellWidth < MINCELLSIZE) { cellWidth = MINCELLSIZE; cellsWide = width / cellWidth; } if (cellHeight < MINCELLSIZE) { cellHeight = MINCELLSIZE; cellsHigh = width / cellWidth; } /* fill the grid with randomly-generated cells */ for(i = 0; i < cellsHigh; i++) { int j; /* Each row is a different color, randomly generated (but constrained) */ if (!mono_p) { int c = genNewColor(st); XSetForeground(st->dpy, st->fg_gc, st->colors[c].pixel); # ifndef DO_STIPPLE if (st->colors2) XSetForeground(st->dpy, st->shadow_gc, st->colors2[c].pixel); # endif } for(j = 0; j < cellsWide; j++) { int curWidth, curHeight, curX, curY; /* Generate a random height for a rectangle and make sure that */ /* it's above a certain minimum size */ curHeight = random() % (cellHeight - st->shadowWidth); if (curHeight < MINRECTSIZE) curHeight = MINRECTSIZE; /* Generate a random width for a rectangle and make sure that it's above a certain minimum size */ curWidth = random() % (cellWidth - st->shadowWidth); if (curWidth < MINRECTSIZE) curWidth = MINRECTSIZE; /* Figure out a random place to locate the rectangle within the cell */ curY = (i * cellHeight) + (random() % ((cellHeight - curHeight) - st->shadowWidth)); curX = (j * cellWidth) + (random() % ((cellWidth - curWidth) - st->shadowWidth)); /* Draw the shadow */ if (st->elevation > 0) XFillRectangle(st->dpy, st->window, st->shadow_gc, curX + st->elevation, curY + st->elevation, curWidth, curHeight); /* Draw the edge */ if (st->shadowWidth > 0) XFillRectangle(st->dpy, st->window, st->bg_gc, curX + st->shadowWidth, curY + st->shadowWidth, curWidth, curHeight); XFillRectangle(st->dpy, st->window, st->fg_gc, curX, curY, curWidth, curHeight); /* Draw a 1-pixel black border around the rectangle */ XDrawRectangle(st->dpy, st->window, st->bg_gc, curX, curY, curWidth, curHeight); } } }
void xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) { Pixmap pattern; rdpBrush* brush; UINT32 foreColor; UINT32 backColor; xfContext* context_ = (xfContext*) context; xfInfo* xfi = context_->xfi; xf_lock_x11(xfi, FALSE); brush = &patblt->brush; xf_set_rop3(xfi, gdi_rop3_code(patblt->bRop)); foreColor = freerdp_color_convert_var(patblt->foreColor, context_->settings->ColorDepth, xfi->bpp, xfi->clrconv); backColor = freerdp_color_convert_var(patblt->backColor, context_->settings->ColorDepth, xfi->bpp, xfi->clrconv); if (brush->style == GDI_BS_SOLID) { XSetFillStyle(xfi->display, xfi->gc, FillSolid); XSetForeground(xfi->display, xfi->gc, foreColor); XFillRectangle(xfi->display, xfi->drawing, xfi->gc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); } else if (brush->style == GDI_BS_HATCHED) { pattern = xf_mono_bitmap_new(xfi, 8, 8, GDI_BS_HATCHED_PATTERNS + 8 * brush->hatch); XSetForeground(xfi->display, xfi->gc, backColor); XSetBackground(xfi->display, xfi->gc, foreColor); XSetFillStyle(xfi->display, xfi->gc, FillOpaqueStippled); XSetStipple(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); XFreePixmap(xfi->display, pattern); } else if (brush->style == GDI_BS_PATTERN) { if (brush->bpp > 1) { pattern = xf_brush_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); XFreePixmap(xfi->display, pattern); } 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); XSetStipple(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); XFreePixmap(xfi->display, pattern); } } else { fprintf(stderr, "unimplemented brush style:%d\n", brush->style); } if (xfi->drawing == xfi->primary) { gdi_InvalidateRegion(xfi->hdc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); } XSetFunction(xfi->display, xfi->gc, GXcopy); xf_unlock_x11(xfi, FALSE); }
BOOL xf_create_window(xfContext* xfc) { XGCValues gcv; XEvent xevent; int width, height; char* windowTitle; rdpSettings* settings = xfc->settings; ZeroMemory(&xevent, sizeof(xevent)); width = xfc->sessionWidth; height = xfc->sessionHeight; if (!xfc->hdc) if (!(xfc->hdc = gdi_CreateDC(CLRBUF_32BPP, xfc->bpp))) return FALSE; if (!xfc->remote_app) { xfc->attribs.background_pixel = BlackPixelOfScreen(xfc->screen); xfc->attribs.border_pixel = WhitePixelOfScreen(xfc->screen); xfc->attribs.backing_store = xfc->primary ? NotUseful : Always; xfc->attribs.override_redirect = False; xfc->attribs.colormap = xfc->colormap; xfc->attribs.bit_gravity = NorthWestGravity; xfc->attribs.win_gravity = NorthWestGravity; #ifdef WITH_XRENDER xfc->offset_x = 0; xfc->offset_y = 0; #endif if (settings->WindowTitle) { windowTitle = _strdup(settings->WindowTitle); } else if (settings->ServerPort == 3389) { windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen(settings->ServerHostname)); sprintf(windowTitle, "FreeRDP: %s", settings->ServerHostname); } else { windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen(settings->ServerHostname) + sizeof(":00000")); sprintf(windowTitle, "FreeRDP: %s:%i", settings->ServerHostname, settings->ServerPort); } #ifdef WITH_XRENDER if (settings->SmartSizing && !xfc->fullscreen) { if (settings->SmartSizingWidth) width = settings->SmartSizingWidth; if (settings->SmartSizingHeight) height = settings->SmartSizingHeight; xfc->scaledWidth = width; xfc->scaledHeight = height; } #endif xfc->window = xf_CreateDesktopWindow(xfc, windowTitle, width, height); free(windowTitle); if (xfc->fullscreen) xf_SetWindowFullscreen(xfc, xfc->window, xfc->fullscreen); xfc->unobscured = (xevent.xvisibility.state == VisibilityUnobscured); XSetWMProtocols(xfc->display, xfc->window->handle, &(xfc->WM_DELETE_WINDOW), 1); xfc->drawable = xfc->window->handle; } else { xfc->drawable = DefaultRootWindow(xfc->display); } ZeroMemory(&gcv, sizeof(gcv)); if (xfc->modifierMap) XFreeModifiermap(xfc->modifierMap); xfc->modifierMap = XGetModifierMapping(xfc->display); if (!xfc->gc); xfc->gc = XCreateGC(xfc->display, xfc->drawable, GCGraphicsExposures, &gcv); if (!xfc->primary); xfc->primary = XCreatePixmap(xfc->display, xfc->drawable, xfc->sessionWidth, xfc->sessionHeight, xfc->depth); xfc->drawing = xfc->primary; if (!xfc->bitmap_mono); xfc->bitmap_mono = XCreatePixmap(xfc->display, xfc->drawable, 8, 8, 1); if (!xfc->gc_mono); xfc->gc_mono = XCreateGC(xfc->display, xfc->bitmap_mono, GCGraphicsExposures, &gcv); XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, BlackPixelOfScreen(xfc->screen)); XFillRectangle(xfc->display, xfc->primary, xfc->gc, 0, 0, xfc->sessionWidth, xfc->sessionHeight); XFlush(xfc->display); if (!xfc->image); xfc->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, (char*) xfc->primary_buffer, xfc->sessionWidth, xfc->sessionHeight, xfc->scanline_pad, 0); return TRUE; }
void do_setcustompalette (XColor * inpal) { int i, n, me = 0, flag[256], vid; int depth; long unsigned int plane_masks[3]; XColor pal[256]; int writeable_p; display.cmap = XDefaultColormap (display.dpy, display.screen); depth = DefaultDepth (display.dpy, display.screen); /* Decide, if the colormap is writable */ { Visual *visual = DefaultVisual (display.dpy, display.screen); #if defined(__cplusplus) || defined(c_plusplus) int visual_class = visual->c_class; #else int visual_class = visual->class; #endif writeable_p = (visual_class == PseudoColor || visual_class == GrayScale); } if (writeable_p) { if (XAllocColorCells (display.dpy, display.cmap, 0 ,plane_masks, 0, colour_table, 256) == 0) { me = (*DefaultVisual (display.dpy, display.screen)).map_entries; vid = (*DefaultVisual (display.dpy, display.screen)).visualid; display.cmap = XCreateColormap (display.dpy, display.win ,DefaultVisual (display.dpy, display.screen) /* ,PseudoColor */ ,AllocNone); if (me == 256 && depth != 24) { if (XAllocColorCells (display.dpy, display.cmap, 0 ,plane_masks, 0, colour_table, 256) != 0) { /* printf ("Allocated 256 cells\n"); */ } else { printf ("Couldn't allocate 256 cells\n"); } } else for (i = 0; i < 256; i++) colour_table[i] = i; } if (!display.cmap) HandleError ("No default colour map", FATAL); } for (i = 0; i < 256; i++) flag[i] = 0; for (n = 0; n < 256; n++) { pal[n].red = inpal[n].red << 10; pal[n].green = inpal[n].green << 10; pal[n].blue = inpal[n].blue << 10; pal[n].flags = DoRed | DoGreen | DoBlue; if (writeable_p) pal[n].pixel = colour_table[n]; else { if (XAllocColor (display.dpy ,display.cmap, &(pal[n])) == 0) HandleError ("alloc colour failed" ,FATAL); colour_table[n] = pal[n].pixel; XSetForeground (display.dpy ,display.pixcolour_gc[n] ,colour_table[n]); } flag[n] = 1; } if (writeable_p) { XStoreColors (display.dpy, display.cmap, pal, 256); XFlush (display.dpy); } XSetWindowColormap (display.dpy, display.win, display.cmap); }
void ui_highlight_move(int from, int to) { (void) XSetForeground(ui_display, ui_gcontext, UI_COL_HIGHLIGHT_SQUARE); (void) XSetLineAttributes(ui_display, ui_gcontext, UI_SIZE_HIGHLIGHT_LINE_WIDTH, LineSolid, CapNotLast, JoinMiter); int xfrom = 0; int yfrom = 0; ui_board_pos_to_pixel(from, &xfrom, &yfrom); int xto = 0; int yto = 0; ui_board_pos_to_pixel(to, &xto, &yto); if ( xfrom == xto ) { /* vertical */ xto += UI_SIZE_SQUARE_WIDTH / 2; if ( yfrom > yto ) { yto += UI_SIZE_SQUARE_HEIGHT; } } else if ( yfrom == yto ) { /* horizontal */ yto += UI_SIZE_SQUARE_HEIGHT / 2; if ( xfrom > xto ) { xto += UI_SIZE_SQUARE_WIDTH; } } else if ( abs(xto - xfrom) == abs(yto - yfrom) ) { /* diagonal */ if ( xto < xfrom ) { xto += UI_SIZE_SQUARE_WIDTH; } if ( yto < yfrom ) { yto += UI_SIZE_SQUARE_HEIGHT; } } else { /* knight */ if ( abs(xto - xfrom) > abs(yto - yfrom) ) { if ( yto > yfrom ) { yto += UI_SIZE_SQUARE_HEIGHT / 3; } else { yto += (2 * UI_SIZE_SQUARE_HEIGHT) / 3; } if ( xfrom > xto ) { xto += UI_SIZE_SQUARE_WIDTH; } } else { if ( xto > xfrom ) { xto += UI_SIZE_SQUARE_WIDTH / 3; } else { xto += (2 * UI_SIZE_SQUARE_WIDTH) / 3; } if ( yfrom > yto ) { yto += UI_SIZE_SQUARE_HEIGHT; } } } xfrom += UI_SIZE_SQUARE_WIDTH / 2; yfrom += UI_SIZE_SQUARE_HEIGHT / 2; XDrawLine(ui_display, ui_backbuf, ui_gcontext, xfrom, yfrom, xto, yto); ui_draw_arrowhead(xfrom, yfrom, xto, yto); }
void Create_Window (char *geometry) { short q; Visual *vid; XSetWindowAttributes xswa; XSizeHints sizehint; XWMHints wmhints; int depth; unsigned char wname[256]; /* Window Name */ unsigned long vmask = CWEventMask | CWBackPixel | CWBackingStore; depth = DefaultDepth (display.dpy, display.screen); xswa.event_mask = 0; xswa.background_pixel = display.bg; xswa.backing_store = WhenMapped; printf ("DefaultVisual id=%d bp-rgb=%d map-entries=%d\n" ,(int) (*DefaultVisual (display.dpy, display.screen)).visualid ,(*DefaultVisual (display.dpy, display.screen)).bits_per_rgb ,(*DefaultVisual (display.dpy, display.screen)).map_entries); vid = DefaultVisual (display.dpy, display.screen); display.cmap = XDefaultColormap (display.dpy, display.screen); display.win = XCreateWindow (display.dpy, display.root, winX, winY, display.winW, display.winH, 0, depth, InputOutput, /* vid , */ DefaultVisual (display.dpy, display.screen), /* PseudoColor, */ vmask, &xswa); sizehint.x = winX - 100; sizehint.y = winY; sizehint.width = display.winW; sizehint.height = display.winH; sizehint.min_width = display.winW; sizehint.min_height = display.winH; sizehint.max_width = display.winW; sizehint.max_height = display.winH; /* GCS FIX: Be careful about resizing the opening screen */ /* WCK: Fixed. We lock it now, and unlock it after the opening screen. not gorgeous, but it works for now. Still need to clean up.*/ #define NO_RESIZABLE_WINDOWS 1 if (geometry != NULL) { #if defined (NO_RESIZABLE_WINDOWS) sizehint.flags = USPosition | USSize | PMinSize | PMaxSize; #else sizehint.flags = USPosition | USSize | PMinSize; #endif } else { #if defined (NO_RESIZABLE_WINDOWS) sizehint.flags = PPosition | PSize | PMinSize | PMaxSize; #else sizehint.flags = PPosition | PSize | PMinSize; #endif } XSetNormalHints (display.dpy, display.win, &sizehint); display.protocol_atom = XInternAtom (display.dpy, "WM_PROTOCOLS", False); display.kill_atom = XInternAtom (display.dpy, "WM_DELETE_WINDOW", False); /* Title */ sprintf ((char *) wname, _("xlincity, Version %s, " "(Copyright) IJ Peters - copying policy GNU GPL"), VERSION); XChangeProperty (display.dpy, display.win, XA_WM_NAME, XA_STRING, 8, PropModeReplace, wname, strlen ((char *) wname)); /* Window Manager Hints (This is supposed to make input work.) */ wmhints.flags = InputHint; wmhints.input = True; XSetWMHints (display.dpy, display.win, &wmhints); XMapWindow (display.dpy, display.win); XSelectInput (display.dpy, display.win, KeyPressMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | StructureNotifyMask); for (q = 0; q < 256; q++) { display.pixcolour_gc[q] = XCreateGC (display.dpy ,display.win, 0, NULL); XSetForeground (display.dpy, display.pixcolour_gc[q], q); XSetBackground (display.dpy, display.pixcolour_gc[q] ,display.bg); XSetGraphicsExposures (display.dpy, display.pixcolour_gc[q] ,False); } }
static Bool drawlisa(ModeInfo * mi, lisas * loop) { XPoint *np; XPoint *lp = loop->lastpoint; lisacons *lc = &Lisa[MI_SCREEN(mi)]; lisafuncs **lf = loop->function; int phase = lc->loopcount % loop->nsteps; int pctr, fctr, xctr, yctr, extra_points; double xprod, yprod, xsum, ysum; /* why carry this around in the struct when we can calculate it on demand? */ extra_points = loop->cstep - (loop->nsteps % loop->cstep); /* Allocate the np (new point) array (with padding) */ if ((np = (XPoint *) calloc(loop->nsteps+extra_points, sizeof (XPoint))) == NULL) { free_lisa(lc); return False; } /* Update the center */ loop->center.x += loop->dx; loop->center.y += loop->dy; CHECK_RADIUS(loop, lc); /* check for overlaps -- where the figure might go off the screen */ if ((loop->center.x - loop->radius) <= 0) { loop->center.x = loop->radius; loop->dx = NRAND(XVMAX); } else if ((loop->center.x + loop->radius) >= lc->width) { loop->center.x = lc->width - loop->radius; loop->dx = -NRAND(XVMAX); }; if ((loop->center.y - loop->radius) <= 0) { loop->center.y = loop->radius; loop->dy = NRAND(YVMAX); } else if ((loop->center.y + loop->radius) >= lc->height) { loop->center.y = lc->height - loop->radius; loop->dy = -NRAND(YVMAX); }; /* Now draw the points, and erase the ones from the last cycle */ for (pctr = 0; pctr < loop->nsteps; pctr++) { fctr = loop->nfuncs; loop->phi = (double) (pctr - phase) * loop->pistep; loop->theta = (double) (pctr + phase) * loop->pistep; xsum = ysum = 0; while (fctr--) { xctr = lf[fctr]->nx; yctr = lf[fctr]->ny; if (additive) { xprod = yprod = 0.0; while (xctr--) xprod += sin(lf[fctr]->xcoeff[xctr] * loop->theta); while (yctr--) yprod += sin(lf[fctr]->ycoeff[yctr] * loop->phi); if (loop->melting) { if (fctr) { xsum += xprod * (double) (loop->nsteps - loop->melting) / (double) loop->nsteps; ysum += yprod * (double) (loop->nsteps - loop->melting) / (double) loop->nsteps; } else { xsum += xprod * (double) loop->melting / (double) loop->nsteps; ysum += yprod * (double) loop->melting / (double) loop->nsteps; } } else { xsum = xprod; ysum = yprod; } if (!fctr) { xsum = xsum * (double) loop->radius / (double) lf[fctr]->nx; ysum = ysum * (double) loop->radius / (double) lf[fctr]->ny; } } else { if (loop->melting) { if (fctr) { yprod = xprod = (double) loop->radius * (double) (loop->nsteps - loop->melting) / (double) (loop->nsteps); } else { yprod = xprod = (double) loop->radius * (double) (loop->melting) / (double) (loop->nsteps); } } else { xprod = yprod = (double) loop->radius; } while (xctr--) xprod *= sin(lf[fctr]->xcoeff[xctr] * loop->theta); while (yctr--) yprod *= sin(lf[fctr]->ycoeff[yctr] * loop->phi); xsum += xprod; ysum += yprod; } } if ((loop->nfuncs > 1) && (!loop->melting)) { xsum /= (double) loop->nfuncs; ysum /= (double) loop->nfuncs; } xsum += (double) loop->center.x; ysum += (double) loop->center.y; np[pctr].x = (int) ceil(xsum); np[pctr].y = (int) ceil(ysum); } /* fill in extra points */ for (pctr=loop->nsteps; pctr < loop->nsteps+extra_points; pctr++) { np[pctr].x = np[pctr - loop->nsteps].x; np[pctr].y = np[pctr - loop->nsteps].y; } if (loop->melting) { if (!--loop->melting) { loop->nfuncs = 1; loop->function[0] = loop->function[1]; } } /* reset starting color each time to prevent ass-like appearance */ loop->color = STARTCOLOR; if (loop->cstep < xMaxLines) { /* printf("Drawing dashes\n"); */ for (pctr = 0; pctr < loop->nsteps; pctr+=loop->cstep) { #if defined DRAWLINES XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), loop->linewidth, LINESTYLE, LINECAP, LINEJOIN); /* erase the last cycle's point */ XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi)); XDrawLines(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), &lp[pctr], loop->cstep, CoordModeOrigin); /* Set the new color */ SET_COLOR(); /* plot this cycle's point */ XDrawLines(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), &np[pctr], loop->cstep, CoordModeOrigin); XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), 1, LINESTYLE, LINECAP, LINEJOIN); #else /* erase the last cycle's point */ XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi)); XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), &lp[pctr], loop->cstep, CoordModeOrigin); /* Set the new color */ SET_COLOR(); /* plot this cycle's point */ XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), &np[pctr], loop->cstep, CoordModeOrigin); #endif } } else { /* on my system, cstep is larger than 65532/2 if we get here */ for (pctr = 0; pctr < loop->nsteps; pctr++) { #if defined DRAWLINES XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), loop->linewidth, LINESTYLE, LINECAP, LINEJOIN); /* erase the last cycle's point */ XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi)); XDrawLine(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), lp[pctr].x, lp[pctr].y, lp[(pctr + 1) % loop->nsteps].x, lp[(pctr + 1) % loop->nsteps].y); /* Set the new color */ SET_COLOR(); /* plot this cycle's point */ XDrawLine(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), np[pctr].x, np[pctr].y, np[(pctr + 1) % loop->nsteps].x, np[(pctr + 1) % loop->nsteps].y); XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), 1, LINESTYLE, LINECAP, LINEJOIN); #else /* DRAWLINES */ /* erase the last cycle's point */ XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi)); XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), lp[pctr].x, lp[pctr].y); /* Set the new color */ SET_COLOR(); /* plot this cycle's point */ XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), np[pctr].x, np[pctr].y); #endif /* DRAWLINES */ } } (void) free((void *) lp); loop->lastpoint = np; return True; }
XColor *xGetXColor(Display *display, Colormap cmap, x_color_list_index_t *list_index, const char *colorname) { int pixval; int get_next; x_color_list_t *new_entry, *this_entry; if (list_index->n_entries == 0) { new_entry = (x_color_list_t *) umalloc (sizeof(x_color_list_t)); list_index->first_entry = new_entry; } else { this_entry = list_index->first_entry; get_next = TRUE; while (get_next) { if (!strcmp(colorname, this_entry->colorname)) return(&this_entry->x_color); if (this_entry->next == NULL) { get_next = FALSE; } else { this_entry = this_entry->next; } } /* while */ new_entry = (x_color_list_t *) umalloc (sizeof(x_color_list_t)); this_entry->next = new_entry; } /* if (list_index ..... */ list_index->n_entries++; new_entry->next = NULL; new_entry->duplicate = FALSE; new_entry->colorname = (char *) umalloc (strlen(colorname) + 1); strcpy(new_entry->colorname, colorname); if (XParseColor(display, cmap, colorname, &new_entry->x_color) == 0) { fprintf(stderr, "ERROR - xGetXColor\n"); fprintf(stderr, "Cannot match color '%s'\n", colorname); return(NULL); } XAllocColor(display, cmap, &new_entry->x_color); new_entry->gc = XCreateGC(display, DefaultRootWindow(display), 0, 0); XSetForeground(display, new_entry->gc, new_entry->x_color.pixel); /* * search through the list to check whether the same pixel value has * been allocated to a previous entry - this sometimes happens * if the server has run out of color cells. If there is a duplicate * entry, set the duplicate flag in the new entry */ pixval = new_entry->x_color.pixel; this_entry = list_index->first_entry; while (this_entry->next != NULL) { if (this_entry->x_color.pixel == pixval) { new_entry->duplicate = TRUE; break; } this_entry = this_entry->next; } /* while */ return(&new_entry->x_color); }
int main(int argc, char *argv[]){ FILE *fp; char buff[1000]; int ch, i, j, x, y; int line_count = 0; count = -1; count_intersect = 0; k = 0; fp = fopen(argv[1], "r"); if (fp == NULL){ printf("There's no input file.\n"); exit(0); } else{ if( (display = XOpenDisplay(display_name)) == NULL ){ printf("Could not open display. \n"); exit(-1); } printf("Connected to X server %s\n", XDisplayName(display_name) ); screen_num = DefaultScreen(display); screen = DefaultScreenOfDisplay(display); colormap = XDefaultColormap(display, screen_num); display_width = DisplayWidth(display, screen_num); display_height = DisplayHeight(display, screen_num); //obtaining line count while(!feof(fp)){ ch = fgetc(fp); if (ch == '\n'){ line_count++; } } rewind(fp); } //int m[line_count][6]; int m[line_count+1][6]; //Creating window border_width = 10; win_x = 0; win_y = 0; win_width = display_width/2; win_height = display_height * 0.8; //win_height = (int)(win_width/1.7); //rectangular window printf("window width: %d\n window height: %d\n", display_width, display_height); //win = XCreateSimpleWindow(display, RootWindow(display, 0), 1, 1, win_width, win_height, 10, WhitePixel (display, 0), WhitePixel (display, 0)); win = XCreateSimpleWindow(display, RootWindow(display, screen_num), win_x, win_y, win_width, win_height, border_width, BlackPixel(display, screen_num), WhitePixel(display, screen_num)); //Maps window on screen size_hints = XAllocSizeHints(); wm_hints = XAllocWMHints(); class_hints = XAllocClassHint(); if (size_hints == NULL || wm_hints == NULL || class_hints == NULL){ printf("Error allocating memory for hints\n"); exit(-1); } size_hints -> flags = PPosition | PSize | PMinSize; size_hints -> min_width = 60; size_hints -> min_height = 60; XStringListToTextProperty(&win_name_string, 1, &win_name); XStringListToTextProperty(&icon_name_string, 1, &icon_name); wm_hints -> flags = StateHint | InputHint; wm_hints -> initial_state = NormalState; wm_hints -> input = False; class_hints -> res_name = "x_use_example"; class_hints -> res_class = "homework1"; XSetWMProperties(display, win, &win_name, &icon_name, argv, argc, size_hints, wm_hints, class_hints ); XSelectInput(display, win, ExposureMask | KeyPressMask | ButtonPressMask); // put on screen XMapWindow(display, win); XFlush(display); //graphics setup green_gc = XCreateGC(display, win, 0, 0); XParseColor(display, colormap, green, &green_col); if (XAllocColor(display, colormap, &green_col) == 0){ printf("Failed to get color green\n"); exit(-1); } else{ printf("Success green!\n"); XSetForeground(display, green_gc, green_col.pixel); } red_gc = XCreateGC(display, win, 0, 0); XParseColor(display, colormap, red, &red_col); if (XAllocColor(display, colormap, &red_col) == 0){ printf("Failed to get color red\n"); exit(-1); } else{ printf("Success red!\n"); XSetForeground(display, red_gc, red_col.pixel); } black_gc = XCreateGC(display, win, 0, 0); XParseColor(display, colormap, black, &black_col); if (XAllocColor(display, colormap, &black_col) == 0){ printf("Failed to get color black\n"); exit(-1); } else{ printf("Success black!\n"); XSetForeground(display, black_gc, black_col.pixel); } light_purple_gc = XCreateGC(display, win, 0, 0); XParseColor(display, colormap, light_purple, &light_purple_col); if (XAllocColor(display, colormap, &light_purple_col) == 0){ printf("Failed to get color light purple\n"); exit(-1); } else{ printf("Success light purple!\n"); XSetForeground(display, light_purple_gc, light_purple_col.pixel); } white_gc = XCreateGC(display, win, 0, 0); XParseColor(display, colormap, white, &white_col); if (XAllocColor(display, colormap, &white_col) == 0){ printf("Failed to get color white\n"); exit(-1); } else{ printf("Success white!\n"); XSetForeground(display, white_gc, white_col.pixel); } while(1){ XNextEvent(display, &report); switch(report.type){ case Expose: { for (i = 0; i <= line_count; i++){ fscanf(fp, "%*s ( %d, %d) ( %d, %d) (%d, %d)", &m[i][0], &m[i][1], &m[i][2], &m[i][3], &m[i][4], &m[i][5]); } m[line_count+1][0] = -5; for (i = 0; i <= line_count ; i++){ for (j=0; j<6; j+=2){ m[i][j] = m[i][j] + 100; m[i][j+1] = m[i][j+1] + 100; } } for (i = 0; i <=line_count; i++){ //Draw the triangles XDrawLine(display, win, green_gc, m[i][0], m[i][1], m[i][2], m[i][3]); XDrawLine(display, win, green_gc, m[i][2], m[i][3], m[i][4], m[i][5]); XDrawLine(display, win, green_gc, m[i][4], m[i][5], m[i][0], m[i][1]); } rewind(fp); if (valid_vertex[0][0] != 0.0){ for (i= 0; i<k; i++){ if (valid_vertex[i][6] == 0.0 || valid_vertex[i][6] == -4.0){ printf("from (%d, %d) to (%d, %d) length: %f and path length: %f\n", (int)valid_vertex[i][0], (int)valid_vertex[i][1], (int)valid_vertex[i][2], (int)valid_vertex[i][3], valid_vertex[i][4], valid_vertex[i][5]); XDrawLine(display, win, light_purple_gc, valid_vertex[i][0], valid_vertex[i][1], valid_vertex[i][2], valid_vertex[i][3]); } } XFillArc( display, win, black_gc, start_x, start_y, win_width/200, win_width/200, 0, 360*64); XFillArc( display, win, black_gc, target_x, target_y, win_width/200, win_width/200, 0, 360*64); } else{} //printf("exposed\n"); XFlush(display); break; } case ButtonPress: { //printf("Button press %d, %d.\n",report.xbutton.x, report.xbutton.y); double distance1; x = report.xbutton.x; y = report.xbutton.y; int inTriangle; if (report.xbutton.button == Button1){ /* left click */ count++; inTriangle = check_if_in_triangle(line_count, m, x, y); if (inTriangle == 0){ XFillArc( display, win, black_gc, x, y, win_width/200, win_width/200, 0, 360*64); } } else{ printf("Closing Window.\n"); XDestroyWindow(display, win); XCloseDisplay(display); exit(1); } //printf("count: %d\n", count); if (count == 0){ reset(m, line_count); start_x = x; start_y = y; if (inTriangle == 1){ count = -1; } } else if (count == 1){ if (inTriangle == 0){ target_x = x; target_y = y; printf("\n\nStarting point: (%d, %d)\nTarget point: (%d, %d)\n", start_x, start_y, target_x, target_y); int vertex[line_count][6]; int * nearest_triangles; int * result_line_seg; for(i=0;i<=line_count;i++){ //store formatted input file in array m fscanf(fp, "%*s ( %d, %d) ( %d, %d) (%d, %d)", &vertex[i][0], &vertex[i][1], &vertex[i][2], &vertex[i][3], &vertex[i][4], &vertex[i][5]); } rewind(fp); printf("Total triangles: %d\n", line_count+1); for (i = 0; i <= line_count ; i++){ for (j=0; j<6; j+=2){ vertex[i][j] = vertex[i][j] + 100; vertex[i][j+1] = vertex[i][j+1] + 100; } } start_graph(line_count, vertex, start_x, start_y, target_x, target_y); printf("Applied start_graph()\n"); shortest_path(); printf("Applied shortest_path()\n"); organize(); printf("The shortest path: \n"); for (i= 0; i<k; i++){ if (valid_vertex[i][6] == 0.0 || valid_vertex[i][6] == -4.0){ printf("from (%d, %d) to (%d, %d) length: %f and path length: %f\n", (int)valid_vertex[i][0], (int)valid_vertex[i][1], (int)valid_vertex[i][2], (int)valid_vertex[i][3], valid_vertex[i][4], valid_vertex[i][5]); XDrawLine(display, win, light_purple_gc, valid_vertex[i][0], valid_vertex[i][1], valid_vertex[i][2], valid_vertex[i][3]); } } printf("DONE\n"); count = -1; } } XFlush(display); break; } default: break; } } fclose(fp); return 0; }
void xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) { Pixmap pattern; rdpBrush* brush; UINT32 foreColor; UINT32 backColor; xfContext* xfc = (xfContext*) context; xf_lock_x11(xfc, FALSE); brush = &patblt->brush; xf_set_rop3(xfc, gdi_rop3_code(patblt->bRop)); foreColor = freerdp_convert_gdi_order_color(patblt->foreColor, context->settings->ColorDepth, xfc->format, xfc->palette); foreColor = xf_gdi_get_color(xfc, foreColor); backColor = freerdp_convert_gdi_order_color(patblt->backColor, context->settings->ColorDepth, xfc->format, xfc->palette); backColor = xf_gdi_get_color(xfc, backColor); if (brush->style == GDI_BS_SOLID) { XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, foreColor); XFillRectangle(xfc->display, xfc->drawing, xfc->gc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); } else if (brush->style == GDI_BS_HATCHED) { pattern = xf_mono_bitmap_new(xfc, 8, 8, GDI_BS_HATCHED_PATTERNS + 8 * brush->hatch); XSetForeground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, foreColor); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetStipple(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); XFillRectangle(xfc->display, xfc->drawing, xfc->gc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); XFreePixmap(xfc->display, pattern); } else if (brush->style == GDI_BS_PATTERN) { if (brush->bpp > 1) { pattern = xf_brush_new(xfc, 8, 8, brush->bpp, brush->data); XSetFillStyle(xfc->display, xfc->gc, FillTiled); XSetTile(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); XFillRectangle(xfc->display, xfc->drawing, xfc->gc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); XSetTile(xfc->display, xfc->gc, xfc->primary); XFreePixmap(xfc->display, pattern); } else { pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data); XSetForeground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, foreColor); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetStipple(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); XFillRectangle(xfc->display, xfc->drawing, xfc->gc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); XFreePixmap(xfc->display, pattern); } } else { WLog_ERR(TAG, "unimplemented brush style:%d", brush->style); } if (xfc->drawing == xfc->primary) { XSetFunction(xfc->display, xfc->gc, GXcopy); if (!xfc->remote_app) { XCopyArea(xfc->display, xfc->primary, xfc->drawable, xfc->gc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight, patblt->nLeftRect, patblt->nTopRect); } gdi_InvalidateRegion(xfc->hdc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight); } XSetFunction(xfc->display, xfc->gc, GXcopy); xf_unlock_x11(xfc, FALSE); }
static void worm_doit(ModeInfo * mi, int which, unsigned long color) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); wormstruct *wp = &worms[MI_SCREEN(mi)]; wormstuff *ws = &wp->worm[which]; int x, y, z; int diff; ws->tail++; if (ws->tail == wp->wormlength) ws->tail = 0; x = ws->circ[ws->tail].x; y = ws->circ[ws->tail].y; if (MI_WIN_IS_USE3D(mi)) { diff = ws->diffcirc[ws->tail]; if (MI_WIN_IS_INSTALL(mi)) { XSetForeground(display, gc, MI_NONE_COLOR(mi)); XFillRectangle(display, window, gc, x - diff, y, wp->circsize, wp->circsize); XFillRectangle(display, window, gc, x + diff, y, wp->circsize, wp->circsize); } else { XClearArea(display, window, x - diff, y, wp->circsize, wp->circsize, False); XClearArea(display, window, x + diff, y, wp->circsize, wp->circsize, False); } } else XClearArea(display, window, x, y, wp->circsize, wp->circsize, False); if (LRAND() & 1) ws->dir = (ws->dir + 1) % SEGMENTS; else ws->dir = (ws->dir + SEGMENTS - 1) % SEGMENTS; x = (ws->x + IRINT((float) wp->circsize * costab[ws->dir]) + wp->xsize) % wp->xsize; y = (ws->y + IRINT((float) wp->circsize * sintab[ws->dir]) + wp->ysize) % wp->ysize; ws->circ[ws->tail].x = x; ws->circ[ws->tail].y = y; ws->x = x; ws->y = y; if (MI_WIN_IS_USE3D(mi)) { if (LRAND() & 1) ws->dir2 = (ws->dir2 + 1) % SEGMENTS; else ws->dir2 = (ws->dir2 + SEGMENTS - 1) % SEGMENTS; /* for the z-axis the wrap-around looks bad, so worms should just turn around. */ z = (int) (ws->z + wp->circsize * sintab[ws->dir2]); if (z < 0 || z >= wp->zsize) z = (int) (ws->z - wp->circsize * sintab[ws->dir2]); diff = (int) (GETZDIFF(z) + 0.5); /* ROUND */ ws->diffcirc[ws->tail] = diff; ws->z = z; /* right eye */ color = 0; wp->rects[color * wp->maxsize + wp->size[color]].x = x + diff; wp->rects[color * wp->maxsize + wp->size[color]].y = y; wp->size[color]++; /* left eye */ color = 1; wp->rects[color * wp->maxsize + wp->size[color]].x = x - diff; wp->rects[color * wp->maxsize + wp->size[color]].y = y; wp->size[color]++; #if 0 if (ws->redrawing) { /* Too hard for now */ int j; for (j = 0; j < REDRAWSTEP; j++) { int k = (ws->tail - ws->redrawpos + wp->wormlength) % wp->wormlength; color = 0; wp->rects[color * wp->maxsize + wp->size[color]].x = ws->circ[k].x + ws->diffcirc[k]; wp->rects[color * wp->maxsize + wp->size[color]].y = ws->circ[k].y; wp->size[color]++; color = 1; wp->rects[color * wp->maxsize + wp->size[color]].x = ws->circ[k].x - ws->diffcirc[k]; wp->rects[color * wp->maxsize + wp->size[color]].y = ws->circ[k].y; wp->size[color]++; if (++(ws->redrawpos) >= wp->wormlength) { ws->redrawing = 0; break; } } } #endif } else { wp->rects[color * wp->maxsize + wp->size[color]].x = x; wp->rects[color * wp->maxsize + wp->size[color]].y = y; wp->size[color]++; if (ws->redrawing) { int j; ws->redrawpos++; /* Compensates for the changed ws->tail since the last callback. */ for (j = 0; j < REDRAWSTEP; j++) { int k = (ws->tail - ws->redrawpos + wp->wormlength) % wp->wormlength; wp->rects[color * wp->maxsize + wp->size[color]].x = ws->circ[k].x; wp->rects[color * wp->maxsize + wp->size[color]].y = ws->circ[k].y; wp->size[color]++; if (++(ws->redrawpos) >= wp->wormlength) { ws->redrawing = 0; break; } } } } }
void xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) { rdpBrush* brush; xfBitmap* bitmap; UINT32 foreColor; UINT32 backColor; Pixmap pattern = 0; xfContext* xfc = (xfContext*) context; xf_lock_x11(xfc, FALSE); brush = &mem3blt->brush; bitmap = (xfBitmap*) mem3blt->bitmap; xf_set_rop3(xfc, gdi_rop3_code(mem3blt->bRop)); foreColor = freerdp_convert_gdi_order_color(mem3blt->foreColor, context->settings->ColorDepth, xfc->format, xfc->palette); foreColor = xf_gdi_get_color(xfc, foreColor); backColor = freerdp_convert_gdi_order_color(mem3blt->backColor, context->settings->ColorDepth, xfc->format, xfc->palette); backColor = xf_gdi_get_color(xfc, backColor); if (brush->style == GDI_BS_PATTERN) { if (brush->bpp > 1) { pattern = xf_brush_new(xfc, 8, 8, brush->bpp, brush->data); XSetFillStyle(xfc->display, xfc->gc, FillTiled); XSetTile(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); } else { pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data); XSetForeground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, foreColor); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XSetStipple(xfc->display, xfc->gc, pattern); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); } } else if (brush->style == GDI_BS_SOLID) { XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, backColor); XSetBackground(xfc->display, xfc->gc, foreColor); XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y); } else { WLog_ERR(TAG, "Mem3Blt unimplemented brush style:%d", brush->style); } XCopyArea(xfc->display, bitmap->pixmap, xfc->drawing, xfc->gc, mem3blt->nXSrc, mem3blt->nYSrc, mem3blt->nWidth, mem3blt->nHeight, mem3blt->nLeftRect, mem3blt->nTopRect); if (xfc->drawing == xfc->primary) { if (!xfc->remote_app) { XCopyArea(xfc->display, bitmap->pixmap, xfc->drawable, xfc->gc, mem3blt->nXSrc, mem3blt->nYSrc, mem3blt->nWidth, mem3blt->nHeight, mem3blt->nLeftRect, mem3blt->nTopRect); } gdi_InvalidateRegion(xfc->hdc, mem3blt->nLeftRect, mem3blt->nTopRect, mem3blt->nWidth, mem3blt->nHeight); } XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetTSOrigin(xfc->display, xfc->gc, 0, 0); if (pattern != 0) XFreePixmap(xfc->display, pattern); XSetFunction(xfc->display, xfc->gc, GXcopy); xf_unlock_x11(xfc, FALSE); }
ENTRYPOINT void init_worm (ModeInfo * mi) { wormstruct *wp; int size = MI_SIZE(mi); int i, j; if (worms == NULL) { if ((worms = (wormstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (wormstruct))) == NULL) return; } wp = &worms[MI_SCREEN(mi)]; if (MI_NPIXELS(mi) <= 2 || MI_WIN_IS_USE3D(mi)) wp->nc = 2; else wp->nc = MI_NPIXELS(mi); if (wp->nc > NUMCOLORS) wp->nc = NUMCOLORS; free_worms(wp); wp->nw = MI_BATCHCOUNT(mi); if (wp->nw < -MINWORMS) wp->nw = NRAND(-wp->nw - MINWORMS + 1) + MINWORMS; else if (wp->nw < MINWORMS) wp->nw = MINWORMS; if (!wp->worm) wp->worm = (wormstuff *) malloc(wp->nw * sizeof (wormstuff)); if (!wp->size) wp->size = (int *) malloc(NUMCOLORS * sizeof (int)); wp->maxsize = (REDRAWSTEP + 1) * wp->nw; /* / wp->nc + 1; */ if (!wp->rects) wp->rects = (XRectangle *) malloc(wp->maxsize * NUMCOLORS * sizeof (XRectangle)); if (!init_table) { init_table = 1; for (i = 0; i < SEGMENTS; i++) { sintab[i] = SINF(i * 2.0 * M_PI / SEGMENTS); costab[i] = COSF(i * 2.0 * M_PI / SEGMENTS); } } wp->xsize = MI_WIN_WIDTH(mi); wp->ysize = MI_WIN_HEIGHT(mi); wp->zsize = MAXZ - MINZ + 1; if (MI_NPIXELS(mi) > 2) wp->chromo = NRAND(MI_NPIXELS(mi)); if (size < -MINSIZE) wp->circsize = NRAND(-size - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) wp->circsize = MINSIZE; else wp->circsize = size; for (i = 0; i < wp->nc; i++) { for (j = 0; j < wp->maxsize; j++) { wp->rects[i * wp->maxsize + j].width = wp->circsize; wp->rects[i * wp->maxsize + j].height = wp->circsize; } } (void) memset((char *) wp->size, 0, wp->nc * sizeof (int)); wp->wormlength = (int) sqrt(wp->xsize + wp->ysize) * MI_CYCLES(mi) / 8; /* Fudge this to something reasonable */ for (i = 0; i < wp->nw; i++) { wp->worm[i].circ = (XPoint *) malloc(wp->wormlength * sizeof (XPoint)); wp->worm[i].diffcirc = (int *) malloc(wp->wormlength * sizeof (int)); for (j = 0; j < wp->wormlength; j++) { wp->worm[i].circ[j].x = wp->xsize / 2; wp->worm[i].circ[j].y = wp->ysize / 2; if (MI_WIN_IS_USE3D(mi)) wp->worm[i].diffcirc[j] = 0; } wp->worm[i].dir = NRAND(SEGMENTS); wp->worm[i].dir2 = NRAND(SEGMENTS); wp->worm[i].tail = 0; wp->worm[i].x = wp->xsize / 2; wp->worm[i].y = wp->ysize / 2; wp->worm[i].z = SCREENZ - MINZ; wp->worm[i].redrawing = 0; } if (MI_WIN_IS_INSTALL(mi) && MI_WIN_IS_USE3D(mi)) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_NONE_COLOR(mi)); XFillRectangle(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), 0, 0, wp->xsize, wp->ysize); } else XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi)); }
int main( int argc, char * argv[] ) { Window win; int x, y; unsigned int width, height; unsigned int border_width; char * window_name = "Hello, X Window System!"; char * icon_name = "HelloX"; char * display_name = NULL; unsigned int display_width, display_height; XSizeHints * size_hints; XWMHints * wm_hints; XClassHint * class_hints; XTextProperty windowName, iconName; XEvent report; XFontStruct * font_info; XGCValues values; GC gc; appname = argv[0]; if ( !( size_hints = XAllocSizeHints() ) || !( wm_hints = XAllocWMHints() ) || !( class_hints = XAllocClassHint() ) ) { fprintf(stderr, "%s: couldn't allocate memory.\n", appname); exit(EXIT_FAILURE); } if ( (display = XOpenDisplay(display_name)) == NULL ) { fprintf(stderr, "%s: couldn't connect to X server %s\n", appname, display_name); exit(EXIT_FAILURE); } screen_num = DefaultScreen(display); display_width = DisplayWidth(display, screen_num); display_height = DisplayHeight(display, screen_num); x = y = 0; width = display_width / 3; height = display_width / 3; win = XCreateSimpleWindow(display, RootWindow(display, screen_num), x, y, width, height, border_width, BlackPixel(display, screen_num), WhitePixel(display, screen_num)); if ( XStringListToTextProperty(&window_name, 1, &windowName) == 0 ) { fprintf(stderr, "%s: structure allocation for windowName failed.\n", appname); exit(EXIT_FAILURE); } if ( XStringListToTextProperty(&icon_name, 1, &iconName) == 0 ) { fprintf(stderr, "%s: structure allocation for iconName failed.\n", appname); exit(EXIT_FAILURE); } size_hints->flags = PPosition | PSize | PMinSize; size_hints->min_width = 200; size_hints->min_height = 100; wm_hints->flags = StateHint | InputHint; wm_hints->initial_state = NormalState; wm_hints->input = True; class_hints->res_name = appname; class_hints->res_class = "hellox"; XSetWMProperties(display, win, &windowName, &iconName, argv, argc, size_hints, wm_hints, class_hints); XSelectInput(display, win, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask); if ( (font_info = XLoadQueryFont(display, "9x15")) == NULL ) { fprintf(stderr, "%s: cannot open 9x15 font.\n", appname); exit(EXIT_FAILURE); } gc = XCreateGC(display, win, 0, &values); XSetFont(display, gc, font_info->fid); XSetForeground(display, gc, BlackPixel(display, screen_num)); XMapWindow(display, win); while ( 1 ) { static char * message = "Hello, X Window System!"; //static int length; static int font_height; //static int msg_x, msg_y; static int msg_y = 0; XNextEvent(display, &report); switch ( report.type ) { case Expose: if ( report.xexpose.count != 0 ) break; { /*length = XTextWidth(font_info, message, strlen(message)); msg_x = (width - length) / 2;*/ msg_y = 0; QStringList list = stat(); for (int i = 0; i < list.size(); i++) { font_height = font_info->ascent + font_info->descent; msg_y += font_height + 2; XDrawString(display, win, gc, 10, msg_y, list.at(i).toStdString().c_str(), list.at(i).length()); } } break; case ConfigureNotify: width = report.xconfigure.width; height = report.xconfigure.height; break; case DestroyNotify: XUnloadFont(display, font_info->fid); XFreeGC(display, gc); XCloseDisplay(display); exit(EXIT_SUCCESS); } } return 0; }
void maitre(int argc, char ** argv) { int i, j; int ecran; XEvent evenement; unsigned long masque_valeur; XGCValues valeurs_gc; XSizeHints indic; char caractere[10]; KeySym touche; int encore; char rep; unsigned int xe, ye; /* coordonnees de l'ecran */ unsigned int c; /* couleur */ complexe_t x; /* --------------------------------------------------------- */ /* Connexion au serveur X */ /* --------------------------------------------------------- */ display = XOpenDisplay(NULL); if (!display) { fprintf(stderr, "Impossible d'ouvrir le display.\n"); fprintf(stderr, "Assurez-vous que la variable DISPLAY est initialisee.\n"); fprintf(stderr, "Elle doit contenir, par exemple : \"termx:0\"\n"); } /* --------------------------------------------------------- */ /* Consultation de certaines caracteristiques du serveur X. */ /* --------------------------------------------------------- */ ecran = DefaultScreen(display); blanc = WhitePixel(display,ecran); noir = BlackPixel(display,ecran); /* --------------------------------------------------------- */ /* Allocation des couelurs */ /* --------------------------------------------------------- */ depth_def = DefaultDepth(display, ecran); cmap = DefaultColormap(display,ecran); /* allocation de couleurs rouge, vert, bleu */ if (XAllocNamedColor(display, cmap, "indian red", &couleur, &exact)) val_pixels[0] = couleur.pixel; else val_pixels[0] = noir; if (XAllocNamedColor(display, cmap, "navy blue", &couleur, &exact)) val_pixels[1] = couleur.pixel; else val_pixels[1] = blanc; if (XAllocNamedColor(display, cmap, "forest green", &couleur, &exact)) val_pixels[2] = couleur.pixel; else val_pixels[2] = noir; /* --------------------------------------------------------- */ /* Creation de la fenetre top-niveau du nom de "Newton" */ /* --------------------------------------------------------- */ indic.x = 200; indic.y = 300; indic.width = dimx; indic.height = dimy; indic.flags = PPosition | PSize; racine = XCreateSimpleWindow(display, DefaultRootWindow(display), indic.x, indic.y, indic.width, indic.height, 1, noir, blanc); /* Definition des proprietes standards de la fenetre top-niveau a l'intention du gestionnaire de fenetres */ XSetStandardProperties(display, racine, tit_racine, tit_racine, None, argv, argc, &indic); /* Selection des evenements interessants pour la fenetre top-niveau */ XSelectInput(display, racine, KeyPressMask | ButtonPressMask | ExposureMask | StructureNotifyMask); /* --------------------------------------------------------- */ /* Creation d'un contexte graphique dessin */ /* --------------------------------------------------------- */ valeurs_gc.foreground = noir; valeurs_gc.background = blanc; valeurs_gc.line_width = 1; valeurs_gc.function = GXcopy; masque_valeur = GCForeground | GCBackground | GCLineWidth | GCFunction; cg_cp = XCreateGC(display, racine, masque_valeur, &valeurs_gc); XMapRaised(display, racine); /* Creation de l'image */ image=XCreatePixmap(display,racine,dimx,dimy,depth_def); XSetForeground(display,cg_cp,blanc); XFillRectangle(display,image,cg_cp,0,0,dimx,dimy); // allocation of the return variable ret = (int **)malloc(sizeof(int*)*dimx); for (i=0; i<dimx; i++) { ret[i] = (int*) malloc(sizeof(int)*dimy); } puts("Pressez la touche fin pour terminer"); encore = 1; while (encore) { XNextEvent(display, &evenement); switch (evenement.type) { case KeyPress : i = XLookupString(&(evenement.xkey), caractere, 10, &touche, 0); if (touche == XK_End) encore = 0; break; case Expose : if (evenement.xexpose.count==0) { if (flag_cal == 0) { // calc paralNewton(); // print results for (xe=0; xe<dimx; xe++) for (ye=0; ye<dimy; ye++) { c = val_pixels[ret[xe][ye]]; XSetForeground(display, cg_cp, c); XDrawPoint(display, racine, cg_cp, xe,ye); XDrawPoint(display, image, cg_cp, xe,ye); } flag_cal = 1; } else XCopyArea(display,image,racine,cg_cp,0,0,dimx,dimy,0,0); } break; case ConfigureNotify : if (evenement.xconfigure.window == racine) { if ((dimy != evenement.xconfigure.height) || (dimx != evenement.xconfigure.width)) { for (i=0; i<dimx; i++) { free(ret[i]); } free(ret); dimy=indic.height = evenement.xconfigure.height; dimx=indic.width = evenement.xconfigure.width; // allocation of the return variable ret = (int **)malloc(sizeof(int*)*dimx); for (i=0; i<dimx; i++) { ret[i] = (int*) malloc(sizeof(int)*dimy); } XFreePixmap(display,image); image=XCreatePixmap(display,racine,dimx, dimy,depth_def); XSetForeground(display,cg_cp,blanc); XFillRectangle(display,image,cg_cp,0,0,dimx,dimy); printf("maitre : dimx=%d, dimy=%d\n",dimx,dimy); // calc paralNewton(); // print results for (xe=0; xe<dimx; xe++) for (ye=0; ye<dimy; ye++) { c = val_pixels[ret[xe][ye]]; XSetForeground(display, cg_cp, c); XDrawPoint(display, racine, cg_cp, xe,ye); XDrawPoint(display, image, cg_cp, xe,ye); } /* flag_cal = 1;*/ } } } } XDestroyWindow(display,racine); XFreeGC(display, cg_cp); XFreePixmap(display,image); XCloseDisplay(display); }
void win_open(win_t *win) { int c, i, j, n; long parent; win_env_t *e; XClassHint classhint; unsigned long *icon_data; XColor col; Cursor *cnone = &cursors[CURSOR_NONE].icon; char none_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; Pixmap none; int gmask; XSizeHints sizehints; Bool fullscreen = options->fullscreen && fs_support; e = &win->env; parent = options->embed != 0 ? options->embed : RootWindow(e->dpy, e->scr); sizehints.flags = PWinGravity; sizehints.win_gravity = NorthWestGravity; /* determine window offsets, width & height */ if (options->geometry == NULL) gmask = 0; else gmask = XParseGeometry(options->geometry, &win->x, &win->y, &win->w, &win->h); if ((gmask & WidthValue) != 0) sizehints.flags |= USSize; else win->w = WIN_WIDTH; if ((gmask & HeightValue) != 0) sizehints.flags |= USSize; else win->h = WIN_HEIGHT; if ((gmask & XValue) != 0) { if ((gmask & XNegative) != 0) { win->x += e->scrw - win->w; sizehints.win_gravity = NorthEastGravity; } sizehints.flags |= USPosition; } else { win->x = 0; } if ((gmask & YValue) != 0) { if ((gmask & YNegative) != 0) { win->y += e->scrh - win->h; sizehints.win_gravity = sizehints.win_gravity == NorthEastGravity ? SouthEastGravity : SouthWestGravity; } sizehints.flags |= USPosition; } else { win->y = 0; } win->xwin = XCreateWindow(e->dpy, parent, win->x, win->y, win->w, win->h, 0, e->depth, InputOutput, e->vis, 0, NULL); if (win->xwin == None) error(EXIT_FAILURE, 0, "Error creating X window"); XSelectInput(e->dpy, win->xwin, ButtonReleaseMask | ButtonPressMask | KeyPressMask | PointerMotionMask | StructureNotifyMask); for (i = 0; i < ARRLEN(cursors); i++) { if (i != CURSOR_NONE) cursors[i].icon = XCreateFontCursor(e->dpy, cursors[i].name); } if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), "black", &col, &col) == 0) { error(EXIT_FAILURE, 0, "Error allocating color 'black'"); } none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8); *cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0); gc = XCreateGC(e->dpy, win->xwin, 0, None); n = icons[ARRLEN(icons)-1].size; icon_data = emalloc((n * n + 2) * sizeof(*icon_data)); for (i = 0; i < ARRLEN(icons); i++) { n = 0; icon_data[n++] = icons[i].size; icon_data[n++] = icons[i].size; for (j = 0; j < icons[i].cnt; j++) { for (c = icons[i].data[j] >> 4; c >= 0; c--) icon_data[n++] = icon_colors[icons[i].data[j] & 0x0F]; } XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_ICON], XA_CARDINAL, 32, i == 0 ? PropModeReplace : PropModeAppend, (unsigned char *) icon_data, n); } free(icon_data); win_set_title(win, "sxiv"); classhint.res_class = RES_CLASS; classhint.res_name = options->res_name != NULL ? options->res_name : "sxiv"; XSetClassHint(e->dpy, win->xwin, &classhint); XSetWMProtocols(e->dpy, win->xwin, &atoms[ATOM_WM_DELETE_WINDOW], 1); sizehints.width = win->w; sizehints.height = win->h; sizehints.x = win->x; sizehints.y = win->y; XSetWMNormalHints(win->env.dpy, win->xwin, &sizehints); win->h -= win->bar.h; win->buf.w = e->scrw; win->buf.h = e->scrh; win->buf.pm = XCreatePixmap(e->dpy, win->xwin, win->buf.w, win->buf.h, e->depth); XSetForeground(e->dpy, gc, fullscreen ? win->black.pixel : win->bg.pixel); XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h); XSetWindowBackgroundPixmap(e->dpy, win->xwin, win->buf.pm); XMapWindow(e->dpy, win->xwin); XFlush(e->dpy); if (fullscreen) win_toggle_fullscreen(win); }
void StartDrag(Widget searchWidget, XEvent *event) { Arg args[8]; Cardinal n; Atom exportList[1]; Widget sourceIcon; UpdateTask * pt; int textWidth, maxWidth, maxHeight, fontHeight, ascent; unsigned long fg, bg; XButtonEvent * xbutton; XGCValues gcValues; unsigned long gcValueMask; DisplayInfo * displayInfo; static char *channelNames[MAX(MAX_PENS,MAX_TRACES)][2]; Pixmap sourcePixmap = (Pixmap)NULL; static GC gc = NULL; /* a nice sized font */ #define FONT_TABLE_INDEX 6 /* move the text over... */ #define X_SHIFT 8 #define MARGIN 2 /* (MDA) since widget doing drag could be toggleButton or optionMenu button * (which has more than just flat, single parent), * find the widget that has a parent that is the drawing area and * search based on that * (since that is what is rooted in the display) * - NB if drawing areas as children of the main drawing area are allowed * as parents of controllers/monitors, this logic must change... */ if (XtClass(searchWidget) == xmDrawingAreaWidgetClass && strcmp(XtName(searchWidget),stripChartWidgetName) !=0 ) { /* starting search from a DrawingArea which is not a StripChart * (i.e., DL_Display) therefore lookup "graphic" (non-widget) elements ; * get UpdateTask data from position knowledge */ displayInfo = dmGetDisplayInfoFromWidget(searchWidget); xbutton = (XButtonEvent *)event; pt = getUpdateTaskFromPosition(displayInfo, xbutton->x,xbutton->y); } else { WidgetUserData * userData; /* get UpdateTask data from widget's userData resource */ while (XtClass(XtParent(searchWidget)) != xmDrawingAreaWidgetClass) searchWidget = XtParent(searchWidget); XtVaGetValues (searchWidget, XmNuserData, &userData, NULL); if (userData) pt = userData->updateTask; else { pt = getUpdateTaskFromWidget(searchWidget); INFORM_INTERNAL_ERROR(); } } #define MAX_COL 4 if (pt) { char * name[MAX_PENS*MAX_COL]; short severity[MAX_PENS*MAX_COL]; int count = 1; int column; int row; if (pt->name == NULL) return; else (*pt->name)(pt->clientData, name, severity, &count); /* T. Straumann: copy the names to the clipboard * * NOTE: we must copy the name strings, because we * cannot be 100% sure the updateTask still * exists at the time the PRIMARY selection * is requested. */ if ( count > 0 ) { int i; clipbdStart(); clipbdAdd(name[0]); /* count > 100 means count/100 columns (see dm2kCartesianPlot.c !?!) */ for ( i=1; i < (count%100); i++) { clipbdAdd("\n"); clipbdAdd(name[i]); } clipbdHold(); } column = count / 100; if (column == 0) column = 1; if (column > MAX_COL) column = MAX_COL; count = count % 100; row = 0; bg = BlackPixel(display,screenNum); fg = WhitePixel(display,screenNum); ascent = fontTable[FONT_TABLE_INDEX]->ascent; fontHeight = ascent + fontTable[FONT_TABLE_INDEX]->descent; if (count == 0) { channelName = NULL; return; } else { int i, j; int x, y; i = 0; j = 0; textWidth = 0; while (i < count) { if (name[i]) { register int tmp = XTextWidth(fontTable[FONT_TABLE_INDEX],name[i],STRLEN(name[i])); textWidth = MAX(textWidth,tmp); } j++; if (j >= column) { j = 0; row++; } i++; } maxWidth = X_SHIFT + (textWidth + MARGIN) * column; maxHeight = row*fontHeight + 2*MARGIN; sourcePixmap = XCreatePixmap(display, RootWindow(display, screenNum), maxWidth,maxHeight, DefaultDepth(display,screenNum)); if (gc == NULL) gc = XCreateGC(display,sourcePixmap,0,NULL); gcValueMask = GCForeground|GCBackground|GCFunction|GCFont; gcValues.foreground = bg; gcValues.background = bg; gcValues.function = GXcopy; gcValues.font = fontTable[FONT_TABLE_INDEX]->fid; XChangeGC(display,gc,gcValueMask,&gcValues); XFillRectangle(display,sourcePixmap,gc,0,0,maxWidth,maxHeight); i = j = 0; x = X_SHIFT; y = ascent + MARGIN; while (i < count) { if (name[i]) { XSetForeground(display,gc,alarmColorPixel[severity[i]]); XDrawString(display,sourcePixmap,gc,x,y,name[i],STRLEN(name[i])); channelName = name[i]; } j++; if (j < column) { x += textWidth + MARGIN; } else { j = 0; x = X_SHIFT; y += fontHeight; } i++; } } } if (sourcePixmap != (Pixmap)NULL) { /* use source widget as parent - can inherit visual attributes that way */ n = 0; XtSetArg(args[n],XmNpixmap,sourcePixmap); n++; XtSetArg(args[n],XmNwidth,maxWidth); n++; XtSetArg(args[n],XmNheight,maxHeight); n++; XtSetArg(args[n],XmNdepth,DefaultDepth(display,screenNum)); n++; sourceIcon = XmCreateDragIcon(XtParent(searchWidget),"sourceIcon",args,n); /* establish list of valid target types */ exportList[0] = COMPOUND_TEXT; n = 0; XtSetArg(args[n],XmNexportTargets, exportList); n++; XtSetArg(args[n],XmNnumExportTargets, 1); n++; XtSetArg(args[n],XmNdragOperations, XmDROP_COPY); n++; XtSetArg(args[n],XmNconvertProc, DragConvertProc); n++; XtSetArg(args[n],XmNsourcePixmapIcon, sourceIcon); n++; XtSetArg(args[n],XmNcursorForeground, fg); n++; XtSetArg(args[n],XmNcursorBackground, bg); n++; XtSetArg(args[n],XmNdragDropFinishCallback, dragDropFinishCB); n++; XmDragStart(searchWidget,event,args,n); } }
void whiteOutTitleBar(Display *display, Drawable window, GC gc, XWindowAttributes attr){ XSetForeground(display, gc, white); XFillRectangle(display, window, gc, 1, 1, attr.width - 3, TITLEBAR_THICKNESS - 2); }
void CNFGClearFrame() { XGetWindowAttributes( CNFGDisplay, CNFGWindow, &CNFGWinAtt ); XSetForeground(CNFGDisplay, CNFGGC, CNFGColor(CNFGBGColor) ); XFillRectangle(CNFGDisplay, CNFGPixmap, CNFGGC, 0, 0, CNFGWinAtt.width, CNFGWinAtt.height ); }