home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xtici.zip / xtici / patch.c < prev    next >
C/C++ Source or Header  |  1991-08-28  |  6KB  |  249 lines

  1. /*
  2.  * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
  3.  *     All Rights Reserved
  4.  * 
  5.  * This file is a component of an X Window System client which uses the Xcms 
  6.  * Color Management System.  TekColor is a trademark of Tektronix, Inc.  The
  7.  * TekColor Editor is the subject of U.S. and foreign patents pending.  The
  8.  * term "TekHVC" designates a particular color space that is the subject of
  9.  * U.S. Patent No. 4,985,853 (equivalent foreign patents pending).
  10.  * Permission is hereby granted to use, copy, modify, sell, and otherwise
  11.  * distribute this software and its documentation for the X Window System
  12.  * environment, for any purpose and without fee, provided that:
  13.  * 
  14.  * 1.    The code and documentation are only used to implement a 
  15.  *      TekColor Editor in an X Window System environment; and
  16.  * 2.    This copyright and permission notice is reproduced in all copies
  17.  *     of the code and in supporting documentation.
  18.  * 
  19.  * Permission is granted to modify this code as required to allow it to
  20.  * be compiled on any host computer, provided that the functionality of
  21.  * the TekColor Editor is not modified in any way.  A description of any 
  22.  * modifications must be sent to Tektronix, Inc.  Contact 
  23.  * Tektronix Inc., P.O. Box 1000, Mail Station 60-850, 
  24.  * Network Displays Division Engineering, Wilsonville, OR 97070.
  25.  *
  26.  * Tektronix makes no representation about the suitability of this software
  27.  * for any purpose.  It is provided "as is" and with all faults.
  28.  * 
  29.  * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
  30.  * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  31.  * PARTICULAR PURPOSE.  IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
  32.  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  33.  * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
  34.  * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  35.  * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
  36.  * 
  37.  *    NAME
  38.  *        patch - create and manage patch widgets
  39.  *
  40.  *    DESCRIPTION
  41.  *        The patch widget displays the current color and the index
  42.  *        of the current color cell.  When in shading mode, it splits 
  43.  *        and shows color cells on each end of the shading range.
  44.  *        Create, manage and respond to user input in the patch.
  45.  */
  46. #ifndef LINT
  47. static char *copy_notice = "Copyright 1991 Tektronix, Inc.";
  48. #ifdef RCS_ID
  49. static char *rcsid=  "$Header: patch.c,v 1.2 91/08/22 11:34:12 adamsc Exp $";
  50. #endif /* RCS_ID */
  51. #endif /* LINT */
  52.  
  53. /*
  54.  *      EXTERNAL INCLUDES
  55.  */
  56.  
  57.  
  58. /*
  59.  *      INTERNAL INCLUDES
  60.  */
  61. #include <X11/StringDefs.h>
  62. #include <X11/IntrinsicP.h>
  63. #include <X11/CoreP.h>
  64. #include <X11/Xaw/AsciiTextP.h>
  65. #include <X11/Xaw/Box.h>
  66. #include <X11/Xaw/Form.h>
  67. #include <X11/Xaw/Text.h>
  68.  
  69. #include "xtici.h"
  70. #include "patch.h"
  71. #include "widgets/xticiSD.h"
  72.  
  73. /*
  74.  *      EXTERNS
  75.  */
  76.  
  77.  
  78. /*
  79.  *      GLOBALS
  80.  */
  81. #ifdef DEC
  82. #  define GLOBAL    global
  83. #else
  84. #  define GLOBAL
  85. #endif
  86.  
  87. /*
  88.  * The index to the current cell
  89.  */
  90. GLOBAL Pixel currentIndex = 0;
  91.  
  92. /*
  93.  *      LOCAL DEFINES
  94.  */
  95. #define WidgetCt    PatchMaxCt
  96.  
  97. /*
  98.  *      LOCAL TYPEDEFS
  99.  */
  100.  
  101.  
  102. /*
  103.  *      LOCALS VARIABLES
  104.  */
  105. #ifdef DEBUG
  106. #  define STATIC
  107. #else
  108. #  define STATIC        static
  109. #endif
  110.  
  111. STATIC Widget wlist[WidgetCt];
  112.  
  113. STATIC Arg textArgs[] = {
  114.     {XtNeditType, (XtArgVal)XawtextEdit},
  115.     {XtNlength, 3},
  116.     {XtNresize, (XtArgVal)XawtextResizeBoth},
  117.     {XtNstring, (XtArgVal)"0"},
  118.     {XtNuseStringInPlace, False},
  119.     {XtNwidth, 50},
  120.     {XtNheight, 30},
  121.     {XtNtop, (XtArgVal)XawChainTop},
  122.     {XtNleft, (XtArgVal)XawChainLeft},
  123. };
  124. STATIC Arg boxArgs[] = {
  125.     {XtNwidth, 203},
  126.     {XtNheight, 79},
  127.     {XtNtop, (XtArgVal)XawChainTop},
  128.     {XtNbottom, (XtArgVal)XawChainBottom},
  129.     {XtNleft, (XtArgVal)XawChainLeft},
  130.     {XtNright, (XtArgVal)XawChainRight},
  131. };
  132.  
  133.  
  134. /************************************************************************
  135.  *                                    *
  136.  *            PRIVATE ROUTINES                *
  137.  *                                    *
  138.  ************************************************************************/
  139. #define BUFLEN 5
  140. /* ARGSUSED */
  141. STATIC void setIndexGesture(wid, source, call)
  142. Widget wid;
  143. XtPointer source;
  144. XtPointer call;
  145. {
  146.     gesture = GestureCell0;
  147. }
  148.  
  149. /************************************************************************
  150.  *                                    *
  151.  *            PUBLIC ROUTINES                    *
  152.  *                                    *
  153.  ************************************************************************/
  154. Widget CreatePatch(parent)
  155. Widget parent;
  156. {
  157.     Widget self = XtCreateManagedWidget("patch", formWidgetClass, parent,
  158.                      NULL, 0);
  159.     Widget asw;
  160.     XtTranslations mytrans;
  161.     STATIC char defaults[] = "#augment\n\
  162.            <Leave>:   leave()";
  163.  
  164.     wlist[0] = XtCreateManagedWidget("patchtext", 
  165.                  asciiTextWidgetClass, self, textArgs, XtNumber(textArgs));
  166.     mytrans = XtParseTranslationTable(defaults);
  167.     XtAugmentTranslations (wlist[0], mytrans);
  168.     asw = XawTextGetSource(wlist[0]);
  169.     XtAddCallback(asw, XtNcallback, setIndexGesture, (XtPointer)NULL);
  170.  
  171.     wlist[1] = XtCreateManagedWidget("patcharea", boxWidgetClass, self,
  172.                       boxArgs, XtNumber(boxArgs));
  173.  
  174.     return(self);
  175. }
  176.  
  177. /*
  178.  * return the list of index that are being displayed in the interface, ie,
  179.  * that could be edited or interpolated.
  180.  */
  181. Pixel *EditingIndexes(cnt)
  182. int *cnt;
  183. {
  184.     *cnt = 1;
  185.  
  186.     return(clist);
  187. }
  188.  
  189. /* ARGSUSED */
  190. Pixel GetPatchIndex(patch)
  191. int patch;
  192. {
  193.     AsciiWidget tw = (AsciiWidget) wlist[0];
  194.     Arg    args[1];
  195.     String new;
  196.     int       val;
  197.  
  198.     XtSetArg (args[0], XtNstring, &new);
  199.     XtGetValues ((Widget)tw, args, 1);
  200.     val = atoi(new);
  201.  
  202.     return(ConstrainIndex((Pixel)val));
  203. }
  204.  
  205. /* void NewPatch(new, where)
  206.  * int new;
  207.  * int where;
  208.  * {
  209.  *     currentPatch = new;
  210.  * 
  211.  *     NewIndex((int)clist[new], where);
  212.  * }
  213.  */
  214. void PatchDraw (wid, pix)
  215. Widget wid;
  216. Pixel pix;
  217. {
  218.     Display *dpy = XtDisplayOfObject(wid);
  219.     Window  win = XtWindowOfObject(wid);
  220.     Arg args[1];
  221.  
  222.     XtSetArg (args[0], XtNbackground, pix);
  223.     XtSetValues (wid, args, 1);
  224.  
  225.     /* if no window, must not yet be realized */
  226.     if (!dpy || !win)
  227.     return;
  228.  
  229.     XSetWindowBackground (dpy, win, pix);
  230.     XClearWindow (dpy, win);
  231. }
  232.  
  233. void UpdatePatchWidget(where)
  234. int where;
  235. {
  236.     Arg  args[1];
  237.     Widget source;
  238.     char buf[BUFLEN];
  239.  
  240.     if (where != PatchWidget) {
  241.         bzero(buf, BUFLEN);
  242.     source = XawTextGetSource(wlist[0]);
  243.     sprintf(buf, "%d", currentIndex);
  244.     XtSetArg (args[0], XtNstring, (XtPointer)buf);
  245.     XtSetValues (source, args, 1);
  246.     }
  247.     PatchDraw (wlist[1], currentIndex);
  248. }
  249.