Actual source code: frame.c

      1: #define PETSC_DLL
      2: /*
      3:    This file contains routines to draw a 3-d like frame about a given
      4:    box with a given width.  Note that we might like to use a high/low
      5:    color for highlights.

      7:    The region has 6 parameters.  These are the dimensions of the actual frame.
      8:  */

     10:  #include src/sys/src/draw/impls/x/ximpl.h

     12: EXTERN PixVal XiGetColor(PetscDraw_X *,char *,int);

     14: /* 50% grey stipple pattern */
     15: static Pixmap grey50 = (Pixmap)0;
     16: #define cboard50_width 8
     17: #define cboard50_height 8
     18: static unsigned char cboard50_bits[] = {
     19:    0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa};

     21: static PixVal HiPix=0,LoPix=0;
     22: /*
     23:    Set the colors for the highlights by name
     24:  */
     27: PetscErrorCode XiFrameColors(PetscDraw_X* XiWin,XiDecoration *Rgn,char *Hi,char *Lo)
     28: {
     30:   Rgn->Hi = XiGetColor(XiWin,Hi,1);
     31:   Rgn->Lo = XiGetColor(XiWin,Lo,1);
     32:   Rgn->HasColor = Rgn->Hi != Rgn->Lo;
     33:   return(0);
     34: }

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

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

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

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

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