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:  */
 28: int XiFrameColors(PetscDraw_X* XiWin,XiDecoration *Rgn,char *Hi,char *Lo)
 29: {
 31:   Rgn->Hi = XiGetColor(XiWin,Hi,1);
 32:   Rgn->Lo = XiGetColor(XiWin,Lo,1);
 33:   Rgn->HasColor = Rgn->Hi != Rgn->Lo;
 34:   return(0);
 35: }

 39: int XiDrawFrame(PetscDraw_X *XiWin,XiDecoration *Rgn)
 40: {
 41:   int    xl = Rgn->Box.x,yl = Rgn->Box.y,xh = Rgn->Box.xh,yh = Rgn->Box.yh,
 42:          o = Rgn->width;
 43:   XPoint high[7],low[7];
 44:   PixVal Hi,Lo;

 47:   /* High polygon */
 48:   high[0].x = xl;            high[0].y = yh;
 49:   high[1].x = xl + o;        high[1].y = yh - o;
 50:   high[2].x = xh - o;        high[2].y = yh - o;
 51:   high[3].x = xh - o;        high[3].y = yl + o;
 52:   high[4].x = xh;            high[4].y = yl;
 53:   high[5].x = xh;            high[5].y = yh;
 54:   high[6].x = xl;            high[6].y = yh;     /* close path */

 56:   low[0].x  = xl;            low[0].y = yh;
 57:   low[1].x  = xl;            low[1].y = yl;
 58:   low[2].x  = xh;            low[2].y = yl;
 59:   low[3].x  = xh - o;        low[3].y = yl + o;
 60:   low[4].x  = xl + o;        low[4].y = yl + o;
 61:   low[5].x  = xl + o;        low[5].y = yh - o;
 62:   low[6].x  = xl;            low[6].y = yh;      /* close path */

 64:   if (Rgn->HasColor) {
 65:     if (Rgn->Hi) Hi = Rgn->Hi;
 66:     else         Hi = HiPix;
 67:     if (Rgn->Lo) Lo = Rgn->Lo;
 68:     else         Lo = LoPix;
 69:     XiSetPixVal(XiWin,(Rgn->is_in !=0) ? Hi : Lo);
 70:     if (o <= 1)
 71:         XDrawLines(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
 72:                    high,7,CoordModeOrigin);
 73:     else
 74:         XFillPolygon(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
 75:                       high,7,Nonconvex,CoordModeOrigin);
 76:     XiSetPixVal(XiWin,(Rgn->is_in !=0) ? Lo : Hi);
 77:     if (o <= 1)
 78:         XDrawLines(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
 79:                     low,7,CoordModeOrigin);
 80:     else
 81:         XFillPolygon(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
 82:                       low,7,Nonconvex,CoordModeOrigin);
 83:     /* We could use additional highlights here,such as lines drawn
 84:        connecting the mitred edges. */
 85:   }
 86:   else {
 87:     if (!grey50)
 88:         grey50 = XCreatePixmapFromBitmapData(XiWin->disp,XiWin->win,
 89:                                              (char *)cboard50_bits,
 90:                                              cboard50_width,
 91:                                              cboard50_height,1,0,1);
 92:     XiSetPixVal(XiWin,Rgn->Hi);
 93:     XFillPolygon(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
 94:                  high,7,Nonconvex,CoordModeOrigin);
 95:     /* This can actually be done by using a stipple effect */
 96:     XSetFillStyle(XiWin->disp,XiWin->gc.set,FillStippled);
 97:     XSetStipple(XiWin->disp,XiWin->gc.set,grey50);
 98:     XFillPolygon(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
 99:                  low,7,Nonconvex,CoordModeOrigin);
100:     XSetFillStyle(XiWin->disp,XiWin->gc.set,FillSolid);
101:   }
102:   return(0);
103: }


106: /*
107:    Set the colors for the highlights by name 
108:  */
111: int XiFrameColorsByName(PetscDraw_X* XiWin,char *Hi,char *Lo)
112: {
114:   if (XiWin->numcolors > 2) {
115:     HiPix = XiGetColor(XiWin,Hi,1);
116:     LoPix = XiGetColor(XiWin,Lo,1);
117:   }
118:   return(0);
119: }