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 / leaf.c < prev    next >
C/C++ Source or Header  |  1991-08-28  |  7KB  |  260 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.  *        leaf - deal with the hue leaf widget
  39.  *
  40.  *    DESCRIPTION
  41.  *        Create, update and respond to user input in the leaf widget.
  42.  */
  43. #ifndef LINT
  44. static char *copy_notice = "Copyright 1991 Tektronix, Inc.";
  45. #ifdef RCS_ID
  46. static char *rcsid=  "$Header: leaf.c,v 1.2 91/08/22 11:33:53 adamsc Exp $";
  47. #endif /* RCS_ID */
  48. #endif /* LINT */
  49.  
  50. /*
  51.  *      EXTERNAL INCLUDES
  52.  */
  53.  
  54.  
  55. /*
  56.  *      INTERNAL INCLUDES
  57.  */
  58. #include "xtici.h"
  59. #include "widgets/HvcleafP.h"
  60. #include "widgets/Hueleaf.h"
  61.  
  62. /*
  63.  *      EXTERNS
  64.  */
  65.  
  66. /*
  67.  *      GLOBALS
  68.  */
  69. #ifdef DEC
  70. #  define GLOBAL    global
  71. #else
  72. #  define GLOBAL
  73. #endif
  74.  
  75. /*
  76.  *      LOCAL DEFINES
  77.  */
  78.  
  79. /*
  80.  *      LOCAL TYPEDEFS
  81.  */
  82.  
  83.  
  84. /*
  85.  *      LOCALS VARIABLES
  86.  */
  87. #ifdef DEBUG
  88. #  define STATIC
  89. #else
  90. #  define STATIC        static
  91. #endif
  92.  
  93.  
  94. STATIC Widget leafGraph;
  95.  
  96. STATIC XcmsFloat valueInc = 1.0;
  97. STATIC XcmsFloat chromaInc = 1.0;
  98.  
  99.  
  100. /************************************************************************
  101.  *                                    *
  102.  *            PRIVATE ROUTINES                *
  103.  *                                    *
  104.  ************************************************************************/
  105.  
  106. /* ARGSUSED */
  107. STATIC void leafInc(w, pdirection, pcall)
  108. Widget w;
  109. XtPointer pdirection;
  110. XtPointer pcall;
  111. {
  112.     int direction = (int)pdirection;
  113.     ScaleCallbackStruct *call = (ScaleCallbackStruct *)pcall;
  114.     XcmsColor new;
  115.     int what;
  116.  
  117.     /* just indicates change-of-gesture; don't change hvc */
  118.     if (call->reason == CR_DISARM) {
  119.     EndColor(LeafWidget);
  120.     return;
  121.     }
  122.     if (call->reason == CR_ARM) {
  123.     BeginGesture(GestureMouse);
  124.     return;
  125.     }
  126.  
  127.     new.pixel = currentHvc.pixel;
  128.     new.format = XcmsTekHVCFormat;
  129.     new.spec.TekHVC.H = currentHvc.spec.TekHVC.H;
  130.     new.spec.TekHVC.V = currentHvc.spec.TekHVC.V;
  131.     new.spec.TekHVC.C = currentHvc.spec.TekHVC.C;
  132.  
  133.     switch (direction) {
  134.     case RightArrow:
  135.     new.spec.TekHVC.C += chromaInc;
  136.     what = ChromaChange;
  137.     break;
  138.     case LeftArrow:
  139.     new.spec.TekHVC.C -= chromaInc;
  140.     what = ChromaChange;
  141.     break;
  142.     case UpArrow:
  143.     new.spec.TekHVC.V += valueInc;
  144.     what = ValueChange;
  145.     break;
  146.     case DownArrow:
  147.     new.spec.TekHVC.V -= valueInc;
  148.     what = ValueChange;
  149.     break;
  150.     }
  151.  
  152.     NewHvc(&new, NoWidget, what);    /* force leaf redraw */
  153. }
  154.  
  155. /* ARGSUSED */
  156. STATIC void leafInput(w, client, pcall)
  157. Widget w;
  158. XtPointer client;
  159. XtPointer pcall;
  160. {
  161.     HvcCallbackStruct *call = (HvcCallbackStruct *)pcall;
  162.     XcmsColor new;
  163.  
  164.     /* this just indicates end-of-gesture; don't change hvc */
  165.     if (call->reason == CR_DISARM) {
  166.     EndColor(LeafWidget);
  167.     call->hvc->spec.TekHVC.V = currentHvc.spec.TekHVC.V;
  168.     call->hvc->spec.TekHVC.C = currentHvc.spec.TekHVC.C;
  169.     return;
  170.     }
  171.  
  172.     if (call->reason == CR_ARM) {
  173.     BeginGesture(GestureMouse);
  174.     }
  175.  
  176.     new.pixel = currentIndex;
  177.     new.spec.TekHVC.H = currentHvc.spec.TekHVC.H;
  178.     new.spec.TekHVC.V = call->hvc->spec.TekHVC.V;
  179.     new.spec.TekHVC.C = call->hvc->spec.TekHVC.C;
  180.     NewHvc(&new, LeafWidget, ValueChromaChange);
  181.  
  182.     call->hvc->spec.TekHVC.V = currentHvc.spec.TekHVC.V;
  183.     call->hvc->spec.TekHVC.C = currentHvc.spec.TekHVC.C;
  184. }
  185.  
  186.  
  187. /************************************************************************
  188.  *                                    *
  189.  *            PUBLIC ROUTINES                    *
  190.  *                                    *
  191.  ************************************************************************/
  192. Widget CreateLeafForm(parent, name)
  193. Widget parent;
  194. char *name;
  195. {
  196.     Arg  args[1];
  197.     Pixel base;
  198.     XcmsColor hvc;
  199.     Widget self;
  200.     Widget arw;
  201.     int cnt = 0;
  202.  
  203.     bcopy ((char *)¤tHvc, (char *)&hvc, sizeof (XcmsColor));
  204.     XtSetArg(args[0], XtNhvc, &hvc);                       cnt++;
  205.     self = XtCreateManagedWidget(name, hvcleafWidgetClass, parent, args, cnt);
  206.     XtAddCallback(self, XtNactivateCallback, leafInput, (XtPointer)NULL);
  207.     leafGraph = ((HvcleafWidget)self)->hvcleaf.wlist[HueLeaf];
  208.  
  209.     arw = ((HvcleafWidget)self)->hvcleaf.wlist[UpArrow];
  210.     XtAddCallback(arw, XtNarmCallback, leafInc, (XtPointer)UpArrow);
  211.     XtAddCallback(arw, XtNdisarmCallback, leafInc, (XtPointer)UpArrow);
  212.     XtAddCallback(arw, XtNactivateCallback, leafInc, (XtPointer)UpArrow);
  213.  
  214.     arw = ((HvcleafWidget)self)->hvcleaf.wlist[DownArrow];
  215.     XtAddCallback(arw, XtNarmCallback, leafInc, (XtPointer)DownArrow);
  216.     XtAddCallback(arw, XtNdisarmCallback, leafInc, (XtPointer)DownArrow);
  217.     XtAddCallback(arw, XtNactivateCallback, leafInc, (XtPointer)DownArrow);
  218.  
  219.     arw = ((HvcleafWidget)self)->hvcleaf.wlist[LeftArrow];
  220.     XtAddCallback(arw, XtNarmCallback, leafInc, (XtPointer)LeftArrow);
  221.     XtAddCallback(arw, XtNdisarmCallback, leafInc, (XtPointer)LeftArrow);
  222.     XtAddCallback(arw, XtNactivateCallback, leafInc, (XtPointer)LeftArrow);
  223.  
  224.     arw = ((HvcleafWidget)self)->hvcleaf.wlist[RightArrow];
  225.     XtAddCallback(arw, XtNarmCallback, leafInc, (XtPointer)RightArrow);
  226.     XtAddCallback(arw, XtNdisarmCallback, leafInc, (XtPointer)RightArrow);
  227.     XtAddCallback(arw, XtNactivateCallback, leafInc, (XtPointer)RightArrow);
  228.     
  229.     if (leafState & LeafFilled) {
  230.     LeafRangeSave((Pixel *)&base);
  231.     SetLeafBase(base);
  232.     }
  233.  
  234.     return((Widget)self);
  235. }
  236.  
  237. /* This cannot be done until the window for the widget is created */
  238. void LeafRealize()
  239. {
  240.     XDefineCursor(dpy, XtWindow(leafGraph), hvcCursor);
  241. }
  242.  
  243. void SetLeafBase(base)
  244. Pixel base;
  245. {
  246.     HueleafSetBase((HueleafWidget)leafGraph, base);
  247. }
  248.  
  249. void UpdateLeafWidget()
  250. {
  251.     XcmsColor hvc;
  252.     Arg arg;
  253.  
  254.     hvc.spec.TekHVC.H = currentHvc.spec.TekHVC.H;
  255.     hvc.spec.TekHVC.V = currentHvc.spec.TekHVC.V;
  256.     hvc.spec.TekHVC.C = currentHvc.spec.TekHVC.C;
  257.     XtSetArg(arg, XtNhvc, &hvc);
  258.     XtSetValues(leafGraph, &arg, 1);
  259. }
  260.