Actual source code: frame.c
1: /*
2: This file contains routines to draw a 3-d like frame about a given
3: box with a given width. Note that we might like to use a high/low
4: color for highlights.
6: The region has 6 parameters. These are the dimensions of the actual frame.
7: */
9: #include src/sys/src/draw/impls/x/ximpl.h
11: EXTERN PixVal XiGetColor(PetscDraw_X *,char *,int);
13: /* 50% grey stipple pattern */
14: static Pixmap grey50 = (Pixmap)0;
15: #define cboard50_width 8
16: #define cboard50_height 8
17: static unsigned char cboard50_bits[] = {
18: 0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa};
20: static PixVal HiPix=0,LoPix=0;
21: /*
22: Set the colors for the highlights by name
23: */
26: PetscErrorCode XiFrameColors(PetscDraw_X* XiWin,XiDecoration *Rgn,char *Hi,char *Lo)
27: {
29: Rgn->Hi = XiGetColor(XiWin,Hi,1);
30: Rgn->Lo = XiGetColor(XiWin,Lo,1);
31: Rgn->HasColor = Rgn->Hi != Rgn->Lo;
32: return(0);
33: }
37: PetscErrorCode XiDrawFrame(PetscDraw_X *XiWin,XiDecoration *Rgn)
38: {
39: int xl = Rgn->Box.x,yl = Rgn->Box.y,xh = Rgn->Box.xh,yh = Rgn->Box.yh,
40: o = Rgn->width;
41: XPoint high[7],low[7];
42: PixVal Hi,Lo;
45: /* High polygon */
46: high[0].x = xl; high[0].y = yh;
47: high[1].x = xl + o; high[1].y = yh - o;
48: high[2].x = xh - o; high[2].y = yh - o;
49: high[3].x = xh - o; high[3].y = yl + o;
50: high[4].x = xh; high[4].y = yl;
51: high[5].x = xh; high[5].y = yh;
52: high[6].x = xl; high[6].y = yh; /* close path */
54: low[0].x = xl; low[0].y = yh;
55: low[1].x = xl; low[1].y = yl;
56: low[2].x = xh; low[2].y = yl;
57: low[3].x = xh - o; low[3].y = yl + o;
58: low[4].x = xl + o; low[4].y = yl + o;
59: low[5].x = xl + o; low[5].y = yh - o;
60: low[6].x = xl; low[6].y = yh; /* close path */
62: if (Rgn->HasColor) {
63: if (Rgn->Hi) Hi = Rgn->Hi;
64: else Hi = HiPix;
65: if (Rgn->Lo) Lo = Rgn->Lo;
66: else Lo = LoPix;
67: XiSetPixVal(XiWin,(Rgn->is_in !=0) ? Hi : Lo);
68: if (o <= 1)
69: XDrawLines(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
70: high,7,CoordModeOrigin);
71: else
72: XFillPolygon(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
73: high,7,Nonconvex,CoordModeOrigin);
74: XiSetPixVal(XiWin,(Rgn->is_in !=0) ? Lo : Hi);
75: if (o <= 1)
76: XDrawLines(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
77: low,7,CoordModeOrigin);
78: else
79: XFillPolygon(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
80: low,7,Nonconvex,CoordModeOrigin);
81: /* We could use additional highlights here,such as lines drawn
82: connecting the mitred edges. */
83: }
84: else {
85: if (!grey50)
86: grey50 = XCreatePixmapFromBitmapData(XiWin->disp,XiWin->win,
87: (char *)cboard50_bits,
88: cboard50_width,
89: cboard50_height,1,0,1);
90: XiSetPixVal(XiWin,Rgn->Hi);
91: XFillPolygon(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
92: high,7,Nonconvex,CoordModeOrigin);
93: /* This can actually be done by using a stipple effect */
94: XSetFillStyle(XiWin->disp,XiWin->gc.set,FillStippled);
95: XSetStipple(XiWin->disp,XiWin->gc.set,grey50);
96: XFillPolygon(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
97: low,7,Nonconvex,CoordModeOrigin);
98: XSetFillStyle(XiWin->disp,XiWin->gc.set,FillSolid);
99: }
100: return(0);
101: }
104: /*
105: Set the colors for the highlights by name
106: */
109: PetscErrorCode XiFrameColorsByName(PetscDraw_X* XiWin,char *Hi,char *Lo)
110: {
112: if (XiWin->numcolors > 2) {
113: HiPix = XiGetColor(XiWin,Hi,1);
114: LoPix = XiGetColor(XiWin,Lo,1);
115: }
116: return(0);
117: }