home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / colorwin.c < prev    next >
C/C++ Source or Header  |  1993-10-14  |  4KB  |  132 lines

  1. /*
  2.  * File......: COLORWIN.C
  3.  * Author....: Ian 'UnNamedDude' Day (L&W Computer Services Ltd.)
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Ian Day
  7.  * Date......: 02-25-92
  8.  * Revision..: 1.0
  9.  * Log file..: N/A
  10.  *
  11.  * This is an original work by Ian Day and is placed in the
  12.  * public domain.
  13.  *
  14.  * Modification history:
  15.  * ---------------------
  16.  *
  17.  * 04-30-93
  18.  * Initial Release
  19.  */
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *     GT_COLORWIN()
  24.  *  $CATEGORY$
  25.  *     Video
  26.  *  $ONELINER$
  27.  *     Colours an area of the screen.
  28.  *  $SYNTAX$
  29.  *     GT_ColorWin(<nTop>, <nBottom>, <nLeft>, <nRight>,;
  30.  *              <cNewColor>|<nNewColor>, [<cOldColor>|<nOldColor>]) --> NIL
  31.  *  $ARGUMENTS$
  32.  *     <nTop> Top of box
  33.  *
  34.  *     <nLeft> Left of box
  35.  *
  36.  *     <nBottom> Bottom of box
  37.  *
  38.  *     <nRight> Right of box
  39.  *
  40.  *     <cNewColor>|<nNewColor> Can be a clipper colour string or an integer
  41.  *     attribute to paint the area with.
  42.  *
  43.  *     <cOldColor>|<nOldColor> Can be a clipper colour string or an integer
  44.  *     attribute to indicate which colour to paint over.
  45.  *  $RETURNS$
  46.  *     NIL
  47.  *  $DESCRIPTION$
  48.  *     Paints an area of the screen in a specified colour, optionally
  49.  *     only over a specified colour.
  50.  *
  51.  *     Note: The module also includes a C/ASM callable function equivelant
  52.  *           in the form of:
  53.  *
  54.  *              void gt_Colorwin (unsigned t, unsigned l, unsigned b,;
  55.  *                                unsigned r, int c1, int c2);
  56.  *  $EXAMPLES$
  57.  *     // This example will draw a box in two colours and the paint the box
  58.  *     // lines in white on red by replacing only the white on blue
  59.  *     SetColor("W+/B")
  60.  *     @ 10, 20 TO 16, 60 DOUBLE
  61.  *     SetColor("GR+/B")
  62.  *     @ 11, 21 CLEAR TO 15, 59
  63.  *     GT_ColorWin(10, 20, 16, 60, "W+/R", "W+/B")
  64.  *
  65.  *     // This will paint the whole box in one colour
  66.  *     GT_ColorWin(10, 20, 16, 60, "W+/G")
  67.  *  $SEEALSO$
  68.  *     GT_CSHADOW()
  69.  *  $INCLUDE$
  70.  *
  71.  *  $END$
  72.  */
  73.  
  74. #include "extend.h"
  75.  
  76. void gt_Colorwin (unsigned t, unsigned l, unsigned b, unsigned r, int c1, int c2);
  77. static void ColorwinConv (char * string, unsigned size, int c1, int c2);
  78.  
  79. /*╒═════════╤════════════════════════════════════════════════════════════════╕
  80.   │Function │gt_ColorWin(<nTop>, <nLeft>, <nBottom>, <nRight>, ;             │
  81.   │         │  <cNewColor>|<nNewColor>, <cColorToReplace>|<nColorToReplace>) │
  82.   │Purpose  │Change colour of area on screen                                 │
  83.   │Author   │Ian Day                                                         │
  84.   │Date&Time│04-30-93 05:15pm                                                │
  85.   ╘═════════╧════════════════════════════════════════════════════════════════╛*/
  86. CLIPPER gt_colorwi()
  87. {
  88.    int colour1, colour2;
  89.  
  90.    if (ISNUM(1) && ISNUM(2) && ISNUM(3) && ISNUM(4) && (ISNUM(5) || ISCHAR(5))) {
  91.       if (ISNUM(5))
  92.          colour1 = _parni (5);
  93.       else
  94.          colour1 = ColorToN (_parc (5));
  95.  
  96.       if (ISNUM(6))
  97.          colour2 = _parni (6);
  98.       else if (ISCHAR(6))
  99.          colour2 = ColorToN (_parc (6));
  100.       else
  101.          colour2 = -1;
  102.  
  103.       gt_Colorwin (_parni (1), _parni (2), _parni (3), _parni (4), colour1, colour2);
  104.    }
  105.  
  106.    _ret ();
  107. }
  108.  
  109. void gt_Colorwin (unsigned t, unsigned l, unsigned b, unsigned r, int c1, int c2)
  110. {
  111.    char * string;
  112.    unsigned size = (((r - l + 1) * (b - t + 1)) * 2);
  113.  
  114.    string = _xgrab (size);   /* Maximum we're ever likely to need */
  115.  
  116.    _gtSave (t, l, b, r, string);
  117.    ColorwinConv (string, size, c1, c2);
  118.    _gtRest (t, l, b, r, string);
  119.  
  120.    _xfree (string);
  121. }
  122.  
  123. static void ColorwinConv (char * string, unsigned size, int c1, int c2)
  124. {
  125.    register unsigned loop;
  126.  
  127.    for (loop = 1; loop < size; loop += 2) {
  128.       if (c2 == -1 || string[loop] == (char)c2)
  129.          string[loop] = (char)c1;
  130.    }
  131. }
  132.