1 /*
2 (C) 2001 by Argonne National Laboratory.
3 See COPYRIGHT in top-level directory.
4 */
5 /*
6 This file contains routines to draw a 3-d like frame about a given
7 box with a given width. Note that we might like to use a high/low
8 color for highlights.
9
10 The region has 6 parameters. These are the dimensions of the actual frame.
11 */
12
13 #include "mpe_graphics_conf.h"
14 #include "mpetools.h"
15 #include "basex11.h"
16
17
18 /* 50% grey stipple pattern */
19 static Pixmap grey50 = (Pixmap)0;
20 #define cboard50_width 8
21 #define cboard50_height 8
22 static unsigned char cboard50_bits[] = {
23 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa};
24
25 static PixVal HiPix=0, LoPix=0;
26 /*
27 Set the colors for the highlights by name
28 */
XBFrameColors(XBWin,Rgn,Hi,Lo)29 int XBFrameColors( XBWin, Rgn, Hi, Lo )
30 XBWindow *XBWin;
31 XBDecoration *Rgn;
32 char *Hi, *Lo;
33 {
34 Rgn->Hi = XBGetColor( XBWin, Hi, 1 );
35 Rgn->Lo = XBGetColor( XBWin, Lo, 1 );
36 Rgn->HasColor = Rgn->Hi != Rgn->Lo;
37
38 return 0;
39 }
40
XBDrawFrame(XBWin,Rgn)41 int XBDrawFrame( XBWin, Rgn )
42 XBWindow *XBWin;
43 XBDecoration *Rgn;
44 {
45 int xl = Rgn->Box.x, yl = Rgn->Box.y,
46 xh = Rgn->Box.xh, yh = Rgn->Box.yh,
47 o = Rgn->width;
48 XPoint high[7], low[7];
49 PixVal Hi, Lo;
50
51 /* High polygon */
52 high[0].x = xl; high[0].y = yh;
53 high[1].x = xl + o; high[1].y = yh - o;
54 high[2].x = xh - o; high[2].y = yh - o;
55 high[3].x = xh - o; high[3].y = yl + o;
56 high[4].x = xh; high[4].y = yl;
57 high[5].x = xh; high[5].y = yh;
58 high[6].x = xl; high[6].y = yh; /* close path */
59
60 low[0].x = xl; low[0].y = yh;
61 low[1].x = xl; low[1].y = yl;
62 low[2].x = xh; low[2].y = yl;
63 low[3].x = xh - o; low[3].y = yl + o;
64 low[4].x = xl + o; low[4].y = yl + o;
65 low[5].x = xl + o; low[5].y = yh - o;
66 low[6].x = xl; low[6].y = yh; /* close path */
67
68 if (Rgn->HasColor) {
69 if (Rgn->Hi) Hi = Rgn->Hi;
70 else Hi = HiPix;
71 if (Rgn->Lo) Lo = Rgn->Lo;
72 else Lo = LoPix;
73 XBSetPixVal( XBWin, Rgn->is_in ? Hi : Lo );
74 if ( o <= 1 )
75 XDrawLines( XBWin->disp, XBDrawable(XBWin), XBWin->gc.set,
76 high, 7, CoordModeOrigin );
77 else
78 XFillPolygon( XBWin->disp, XBDrawable(XBWin), XBWin->gc.set,
79 high, 7, Nonconvex, CoordModeOrigin);
80 XBSetPixVal( XBWin, Rgn->is_in ? Lo : Hi );
81 if ( o <= 1 )
82 XDrawLines( XBWin->disp, XBDrawable(XBWin), XBWin->gc.set,
83 low, 7, CoordModeOrigin );
84 else
85 XFillPolygon( XBWin->disp, XBDrawable(XBWin), XBWin->gc.set,
86 low, 7, Nonconvex, CoordModeOrigin);
87 /* We could use additional highlights here, such as lines drawn
88 connecting the mitred edges. */
89 }
90 else {
91 if (!grey50)
92 grey50 = XCreatePixmapFromBitmapData(XBWin->disp, XBWin->win,
93 (char *)cboard50_bits,
94 cboard50_width,
95 cboard50_height, 1, 0, 1);
96 XBSetPixVal( XBWin, Rgn->Hi );
97 XFillPolygon( XBWin->disp, XBDrawable(XBWin), XBWin->gc.set,
98 high, 7, Nonconvex, CoordModeOrigin);
99 /* This can actually be done by using a stipple effect */
100 XSetFillStyle( XBWin->disp, XBWin->gc.set, FillStippled );
101 XSetStipple( XBWin->disp, XBWin->gc.set, grey50 );
102 XFillPolygon( XBWin->disp, XBDrawable(XBWin), XBWin->gc.set,
103 low, 7, Nonconvex, CoordModeOrigin);
104 XSetFillStyle( XBWin->disp, XBWin->gc.set, FillSolid );
105 }
106 return 0;
107 }
108
109 /*
110 XBClearWindow - Clear a region in a window
111
112 Input parameters:
113 . XBWin - window
114 . x,y - upper left corner of region to clear
115 . w,h - width and height of region to clear
116 */
XBClearWindow(XBWin,x,y,w,h)117 void XBClearWindow( XBWin, x, y, w, h )
118 XBWindow *XBWin;
119 int x, y, w, h;
120 {
121 XBSetPixVal(XBWin, XBWin->background );
122 XFillRectangle( XBWin->disp, XBDrawable(XBWin), XBWin->gc.set,
123 x, y, w, h );
124 }
125
126 /*
127 Set the colors for the highlights by name
128 */
XBFrameColorsByName(XBWin,Hi,Lo)129 void XBFrameColorsByName( XBWin, Hi, Lo )
130 XBWindow *XBWin;
131 char *Hi, *Lo;
132 {
133 if (XBWin->numcolors > 2) {
134 HiPix = XBGetColor( XBWin, Hi, 1 );
135 LoPix = XBGetColor( XBWin, Lo, 1 );
136 /* HasColor = 1; */
137 }
138 }
139