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