home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / tcl / tkstep0.3b3 / tkstep0 / tkstep / tk3d.c.diff < prev    next >
Encoding:
Text File  |  1996-07-08  |  12.4 KB  |  412 lines

  1. --- ../tk4.1/generic/tk3d.c    Fri Feb 16 22:31:04 1996
  2. +++ tk3d.c    Mon Jul  8 19:24:09 1996
  3. @@ -12,6 +12,10 @@
  4.   *
  5.   * SCCS: @(#) tk3d.c 1.52 96/02/15 18:51:30
  6.   */
  7. +/*
  8. + * TkSTEP modifications Copyright by
  9. + * Alfredo K. Kojima
  10. + */
  11.  
  12.  #include "tkPort.h"
  13.  #include "tkInt.h"
  14. @@ -55,6 +59,9 @@
  15.      GC lightGC;            /* Used to draw lighter parts of
  16.                   * the border. None means the shadow colors
  17.                   * haven't been allocated yet. */
  18. +    GC dark2GC;            /* Used to draw even darker part of shadows
  19. +                 * (black)
  20. +                 */
  21.      Tcl_HashEntry *hashPtr;    /* Entry in borderTable (needed in
  22.                   * order to delete structure). */
  23.  } Border;
  24. @@ -166,6 +173,7 @@
  25.      borderPtr->shadow = None;
  26.      borderPtr->bgGC = None;
  27.      borderPtr->darkGC = None;
  28. +    borderPtr->dark2GC = None;
  29.      borderPtr->lightGC = None;
  30.      borderPtr->hashPtr = hashPtr;
  31.      Tcl_SetHashValue(hashPtr, borderPtr);
  32. @@ -235,21 +243,52 @@
  33.      Border *borderPtr = (Border *) border;
  34.      GC left, right;
  35.      Display *display = Tk_Display(tkwin);
  36. -
  37. +    int half;
  38. +    
  39. +    
  40.      if ((borderPtr->lightGC == None) && (relief != TK_RELIEF_FLAT)) {
  41.      GetShadows(borderPtr, tkwin);
  42.      }
  43. +    
  44.      if (relief == TK_RELIEF_RAISED) {
  45. -    XFillRectangle(display, drawable, 
  46. -        (leftBevel) ? borderPtr->lightGC : borderPtr->darkGC,
  47. -        x, y, (unsigned) width, (unsigned) height);
  48. +    if (width > 1) {
  49. +        if (leftBevel) {
  50. +            left = borderPtr->lightGC;
  51. +            right = borderPtr->bgGC;
  52. +        } else {
  53. +            left = borderPtr->darkGC;
  54. +            right = borderPtr->dark2GC;
  55. +        }
  56. +        half = width/2;
  57. +        XFillRectangle(display, drawable, left,
  58. +         x, y, (unsigned) half, (unsigned) height);
  59. +        XFillRectangle(display, drawable, right,
  60. +        x+half, y, (unsigned) (width - half), (unsigned) height);
  61. +    } else {
  62. +        left = (leftBevel) ? borderPtr->lightGC : borderPtr->dark2GC;
  63. +        XFillRectangle(display, drawable, left,
  64. +         x, y, (unsigned) width, (unsigned) height);    
  65. +     }
  66.      } else if (relief == TK_RELIEF_SUNKEN) {
  67. -    XFillRectangle(display, drawable, 
  68. -        (leftBevel) ? borderPtr->darkGC : borderPtr->lightGC,
  69. -        x, y, (unsigned) width, (unsigned) height);
  70. +    if (width > 1) {
  71. +        if (leftBevel) {
  72. +            left = borderPtr->darkGC;
  73. +            right = borderPtr->dark2GC;        
  74. +        } else {
  75. +            left = borderPtr->bgGC;
  76. +           right = borderPtr->lightGC;
  77. +        }
  78. +        half = width/2;
  79. +        XFillRectangle(display, drawable, left, 
  80. +        x, y, (unsigned) half, (unsigned) height);
  81. +        XFillRectangle(display, drawable, right, 
  82. +        x + half, y, (unsigned) (width - half), (unsigned) height);
  83. +        } else {
  84. +        left = (leftBevel) ? borderPtr->dark2GC : borderPtr->lightGC;
  85. +        XFillRectangle(display, drawable, left,
  86. +         x, y, (unsigned) width, (unsigned) height);
  87. +        }
  88.      } else if (relief == TK_RELIEF_RIDGE) {
  89. -    int half;
  90. -
  91.      left = borderPtr->lightGC;
  92.      right = borderPtr->darkGC;
  93.      ridgeGroove:
  94. @@ -333,12 +372,20 @@
  95.  
  96.      switch (relief) {
  97.      case TK_RELIEF_RAISED:
  98. -        topGC = bottomGC =
  99. -            (topBevel) ? borderPtr->lightGC : borderPtr->darkGC;
  100. +        if (height==1) {
  101. +            topGC = (topBevel) ? borderPtr->lightGC : borderPtr->dark2GC;
  102. +        } else {
  103. +        topGC = (topBevel) ? borderPtr->lightGC : borderPtr->darkGC;
  104. +            bottomGC = (topBevel) ? borderPtr->bgGC : borderPtr->dark2GC;
  105. +        }    
  106.          break;
  107.      case TK_RELIEF_SUNKEN:
  108. -        topGC = bottomGC =
  109. -            (topBevel) ? borderPtr->darkGC : borderPtr->lightGC;
  110. +        if (height==1) {
  111. +        topGC = (topBevel) ? borderPtr->dark2GC : borderPtr->lightGC;
  112. +        } else {
  113. +        topGC = (topBevel) ? borderPtr->darkGC : borderPtr->bgGC;
  114. +            bottomGC = (topBevel) ? borderPtr->dark2GC : borderPtr->lightGC;
  115. +        }
  116.          break;
  117.      case TK_RELIEF_RIDGE:
  118.          topGC = borderPtr->lightGC;
  119. @@ -359,11 +406,11 @@
  120.  
  121.      x1 = x;
  122.      if (!leftIn) {
  123. -    x1 += height;
  124. +    x1 += height-1;
  125.      }
  126.      x2 = x+width;
  127.      if (!rightIn) {
  128. -    x2 -= height;
  129. +    x2 -= height-1;
  130.      }
  131.      x1Delta = (leftIn) ? 1 : -1;
  132.      x2Delta = (rightIn) ? -1 : 1;
  133. @@ -373,24 +420,33 @@
  134.      }
  135.      bottom = y + height;
  136.  
  137. -    /*
  138. -     * Draw one line for each y-coordinate covered by the bevel.
  139. +    /* 
  140. +     * if borderwidth is 1 just draw the line and get out
  141.       */
  142. -
  143. -    for ( ; y < bottom; y++) {
  144. -    /*
  145. -     * In some weird cases (such as large border widths for skinny
  146. -     * rectangles) x1 can be >= x2.  Don't draw the lines
  147. -     * in these cases.
  148. -     */
  149. -
  150. +    if (height==1) {
  151.      if (x1 < x2) {
  152.          XFillRectangle(display, drawable,
  153. +        topGC, x1, y, (unsigned) (x2-x1-topBevel), (unsigned) 1);
  154. +    }
  155. +    } else {
  156. +        /*
  157. +         * Draw one line for each y-coordinate covered by the bevel.
  158. +         */
  159. +         for ( ; y < bottom; y++) {
  160. +        /*
  161. +         * In some weird cases (such as large border widths for skinny
  162. +         * rectangles) x1 can be >= x2.  Don't draw the lines
  163. +         * in these cases.
  164. +         */
  165. +
  166. +           if (x1 < x2) {
  167. +        XFillRectangle(display, drawable,
  168.          (y < halfway) ? topGC : bottomGC, x1, y,
  169. -        (unsigned) (x2-x1), (unsigned) 1);
  170. +        (unsigned) (x2-x1-topBevel), (unsigned) 1);
  171. +        }
  172. +        x1 += x1Delta;
  173. +        x2 += x2Delta;
  174.      }
  175. -    x1 += x1Delta;
  176. -    x2 += x2Delta;
  177.      }
  178.  }
  179.  
  180. @@ -436,10 +492,11 @@
  181.          1, relief);
  182.      Tk_3DVerticalBevel(tkwin, drawable, border, x+width-borderWidth, y,
  183.          borderWidth, height, 0, relief);
  184. +    
  185.      Tk_3DHorizontalBevel(tkwin, drawable, border, x, y, width, borderWidth,
  186.          1, 1, 1, relief);
  187.      Tk_3DHorizontalBevel(tkwin, drawable, border, x, y+height-borderWidth,
  188. -        width, borderWidth, 0, 0, 0, relief);
  189. +        width, borderWidth, 0, 0, 0, relief);    
  190.  }
  191.  
  192.  /*
  193. @@ -527,7 +584,9 @@
  194.      return borderPtr->lightGC;
  195.      } else if (which == TK_3D_DARK_GC){
  196.      return borderPtr->darkGC;
  197. -    }
  198. +    } else if (which == TK_3D_DARK2_GC) {
  199. +    return borderPtr->dark2GC;
  200. +    }    
  201.      panic("bogus \"which\" value in Tk_3DBorderGC");
  202.  
  203.      /*
  204. @@ -587,6 +646,9 @@
  205.      if (borderPtr->lightGC != None) {
  206.          Tk_FreeGC(display, borderPtr->lightGC);
  207.      }
  208. +    if (borderPtr->dark2GC != None) {
  209. +        Tk_FreeGC(display, borderPtr->dark2GC);
  210. +    }
  211.      Tcl_DeleteHashEntry(borderPtr->hashPtr);
  212.      ckfree((char *) borderPtr);
  213.      }
  214. @@ -662,7 +724,7 @@
  215.      } else if ((c == 's') && (strncmp(name, "sunken", length) == 0)) {
  216.      *reliefPtr = TK_RELIEF_SUNKEN;
  217.      } else {
  218. -    sprintf(interp->result, "bad relief type \"%.50s\": must be %s",
  219. +    sprintf(interp->result, "bad relief type \"%.50s\":  must be %s",
  220.          name, "flat, groove, raised, ridge, or sunken");
  221.      return TCL_ERROR;
  222.      }
  223. @@ -1203,6 +1265,7 @@
  224.   * Side effects:
  225.   *    The lightGC and darkGC fields in borderPtr get filled in,
  226.   *    if they weren't already.
  227. + * 
  228.   *
  229.   *----------------------------------------------------------------------
  230.   */
  231. @@ -1240,40 +1303,27 @@
  232.       * to white, whichever is greater (the first approach works
  233.       * better for unsaturated colors, the second for saturated ones).
  234.       */
  235. -
  236. +    
  237.      darkColor.red = (60 * (int) borderPtr->bgColorPtr->red)/100;
  238.      darkColor.green = (60 * (int) borderPtr->bgColorPtr->green)/100;
  239.      darkColor.blue = (60 * (int) borderPtr->bgColorPtr->blue)/100;
  240. +    
  241.      borderPtr->darkColorPtr = Tk_GetColorByValue(tkwin, &darkColor);
  242.      gcValues.foreground = borderPtr->darkColorPtr->pixel;
  243.      borderPtr->darkGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
  244.  
  245. +
  246. +    /*
  247. +     * dark2 color is always black 
  248. +     */
  249. +    gcValues.foreground = BlackPixelOfScreen(borderPtr->screen);
  250. +    borderPtr->dark2GC = Tk_GetGC(tkwin, GCForeground, &gcValues);
  251. +
  252.      /*
  253. -     * Compute the colors using integers, not using lightColor.red
  254. -     * etc.: these are shorts and may have problems with integer
  255. -     * overflow.
  256. +     * light color is always white     
  257.       */
  258.  
  259. -    tmp1 = (14 * (int) borderPtr->bgColorPtr->red)/10;
  260. -    if (tmp1 > MAX_INTENSITY) {
  261. -        tmp1 = MAX_INTENSITY;
  262. -    }
  263. -    tmp2 = (MAX_INTENSITY + (int) borderPtr->bgColorPtr->red)/2;
  264. -    lightColor.red = (tmp1 > tmp2) ? tmp1 : tmp2;
  265. -    tmp1 = (14 * (int) borderPtr->bgColorPtr->green)/10;
  266. -    if (tmp1 > MAX_INTENSITY) {
  267. -        tmp1 = MAX_INTENSITY;
  268. -    }
  269. -    tmp2 = (MAX_INTENSITY + (int) borderPtr->bgColorPtr->green)/2;
  270. -    lightColor.green = (tmp1 > tmp2) ? tmp1 : tmp2;
  271. -    tmp1 = (14 * (int) borderPtr->bgColorPtr->blue)/10;
  272. -    if (tmp1 > MAX_INTENSITY) {
  273. -        tmp1 = MAX_INTENSITY;
  274. -    }
  275. -    tmp2 = (MAX_INTENSITY + (int) borderPtr->bgColorPtr->blue)/2;
  276. -    lightColor.blue = (tmp1 > tmp2) ? tmp1 : tmp2;
  277. -    borderPtr->lightColorPtr = Tk_GetColorByValue(tkwin, &lightColor);
  278. -    gcValues.foreground = borderPtr->lightColorPtr->pixel;
  279. +    gcValues.foreground = WhitePixelOfScreen(borderPtr->screen);
  280.      borderPtr->lightGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
  281.      return;
  282.      }
  283. @@ -1302,6 +1352,10 @@
  284.      gcValues.background = WhitePixelOfScreen(borderPtr->screen);
  285.      borderPtr->lightGC = Tk_GetGC(tkwin,
  286.          GCForeground|GCBackground|GCStipple|GCFillStyle, &gcValues);
  287. +    
  288. +    gcValues.foreground = gcValues.background;
  289. +    borderPtr->dark2GC = Tk_GetGC(tkwin,
  290. +        GCForeground|GCBackground, &gcValues);
  291.      return;
  292.      }
  293.  
  294. @@ -1314,6 +1368,7 @@
  295.      gcValues.foreground = WhitePixelOfScreen(borderPtr->screen);
  296.      gcValues.background = BlackPixelOfScreen(borderPtr->screen);
  297.      gcValues.stipple = borderPtr->shadow;
  298. +
  299.      gcValues.fill_style = FillOpaqueStippled;
  300.      borderPtr->lightGC = Tk_GetGC(tkwin,
  301.          GCForeground|GCBackground|GCStipple|GCFillStyle, &gcValues);
  302. @@ -1325,4 +1380,109 @@
  303.      borderPtr->darkGC = borderPtr->lightGC;
  304.      borderPtr->lightGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
  305.      }
  306. +
  307. +
  308. +    gcValues.foreground = gcValues.background;
  309. +    borderPtr->dark2GC = Tk_GetGC(tkwin,
  310. +        GCForeground|GCBackground, &gcValues);
  311. +}
  312. +
  313. +
  314. +
  315. +/*
  316. + *---------------------------------------------------------------------- 
  317. + * 
  318. + * Draw3DCircle --
  319. + *     Draws a beveled circle
  320. + * 
  321. + * TODO: Fix circle code
  322. + *---------------------------------------------------------------------- 
  323. + */
  324. +void Tk_Draw3DCircle(display, tkwin, d, x, y, wid, rad, relief, border)
  325. +    Display *display;
  326. +    Tk_Window tkwin;
  327. +    Drawable d;
  328. +    int x, y;                      /* position in d */
  329. +    int wid;                /* border width */
  330. +    int rad;
  331. +    int relief;
  332. +    Tk_3DBorder border;
  333. +{
  334. +    GC lightGC, darkGC, dark2GC, bgGC;
  335. +    int half, i;
  336. +    
  337. +    if (relief==TK_RELIEF_SUNKEN) {    
  338. +    lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC);
  339. +    darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);
  340. +    dark2GC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK2_GC);
  341. +    bgGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
  342. +    } else {
  343. +    darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC);
  344. +    lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);
  345. +    bgGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK2_GC);
  346. +    dark2GC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
  347. +    }    
  348. +    half = wid/2;
  349. +    if (half>1) {
  350. +    XSetLineAttributes(display, darkGC, half, LineSolid, CapButt,
  351. +        JoinMiter);
  352. +    XSetLineAttributes(display, lightGC, half, LineSolid, CapButt,
  353. +        JoinMiter);
  354. +    XSetLineAttributes(display, dark2GC, half, LineSolid, CapButt,
  355. +        JoinMiter);
  356. +    XSetLineAttributes(display, bgGC, half, LineSolid, CapButt, 
  357. +        JoinMiter);
  358. +    } 
  359. +    /*
  360. +     * These coords are based on trial and error
  361. +     */
  362. +    XDrawArc(display, d, dark2GC, x, y, rad*2-half, rad*2-half, 
  363. +    60*64, 150*64);
  364. +    XDrawArc(display, d, darkGC, x, y, rad*2, rad*2, 55*64, 160*64);
  365. +    XDrawArc(display, d, lightGC, x, y, rad*2, rad*2, 35*64, -160*64);
  366. +    XDrawArc(display, d, dark2GC, x+half, y+half, rad*2-half, 
  367. +    rad*2-half, 60*64, 150*64);    
  368. +    XDrawArc(display, d, bgGC, x, y, rad*2-half, rad*2-half, 
  369. +    30*64, -150*64);
  370. +    if (half>1) {
  371. +    XSetLineAttributes(display, dark2GC, 0, LineSolid, CapButt,
  372. +        JoinMiter);
  373. +    XSetLineAttributes(display, lightGC, 0, LineSolid, CapButt,
  374. +        JoinMiter);
  375. +    XSetLineAttributes(display, darkGC, 0, LineSolid, CapButt,
  376. +        JoinMiter);
  377. +    XSetLineAttributes(display, bgGC, 0, LineSolid, CapButt,
  378. +        JoinMiter);
  379. +    }
  380.  }
  381. +
  382. +
  383. +
  384. +/*
  385. + *----------------------------------------------------------------------
  386. + * 
  387. + * DrawCheckMark --
  388. + *     
  389. + *     Draws a 3D check mark on the drawable
  390. + * 
  391. + *----------------------------------------------------------------------
  392. + */
  393. +void Tk_DrawCheckMark(display, tkwin, d, x, y, border)
  394. +    Display *display;
  395. +    Tk_Window tkwin;
  396. +    Drawable d;
  397. +    int x, y;                      /* position in d */
  398. +    Tk_3DBorder border;
  399. +{
  400. +    GC lightGC, darkGC, dark2GC;
  401. +    
  402. +    lightGC = Tk_3DBorderGC(tkwin,border,TK_3D_LIGHT_GC);
  403. +    darkGC = Tk_3DBorderGC(tkwin,border,TK_3D_DARK_GC);
  404. +    dark2GC = Tk_3DBorderGC(tkwin,border,TK_3D_DARK2_GC);
  405. +    XDrawLine(display, d, dark2GC, x+1, y+3, x+1, y+6); 
  406. +    XDrawLine(display, d, lightGC, x, y+3, x, y+8);     
  407. +    XDrawLine(display, d, lightGC, x, y+8, x+8, y);
  408. +    XDrawLine(display, d, dark2GC, x, y+9, x+8, y+1);
  409. +    XDrawLine(display, d, darkGC, x+1, y+9, x+8, y+2);
  410. +}
  411. +
  412.