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 / huebar.c < prev    next >
C/C++ Source or Header  |  1991-08-28  |  5KB  |  175 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.  *        huebar - a widget to select and display hues
  39.  *
  40.  *    DESCRIPTION
  41.  *        The huebar displays the current hue.
  42.  *    Users can interact with it to select new hues.
  43.  *    The bar can be filled to display the range of fully saturated colors
  44.  *    the monitor can display or a range of colors with the same value and
  45.  *    chroma as the current color.
  46.  *    This package creates, updates and responds to user input in the huebar.
  47.  */
  48. #ifndef LINT
  49. static char *copy_notice = "Copyright 1991 Tektronix, Inc.";
  50. #ifdef RCS_ID
  51. static char *rcsid=  "$Header: huebar.c,v 1.2 91/08/22 11:33:39 adamsc Exp $";
  52. #endif /* RCS_ID */
  53. #endif /* LINT */
  54.  
  55. /*
  56.  *      EXTERNAL INCLUDES
  57.  */
  58.  
  59.  
  60. /*
  61.  *      INTERNAL INCLUDES
  62.  */
  63. #include "xtici.h"
  64. #include "widgets/ColorS.h"
  65.  
  66. /*
  67.  *      EXTERNS
  68.  */
  69.  
  70. /*
  71.  *      GLOBALS
  72.  */
  73. #ifdef DEC
  74. #  define GLOBAL    global
  75. #else /* DEC */
  76. #  define GLOBAL
  77. #endif
  78.  
  79.  
  80. /*
  81.  *      LOCAL DEFINES
  82.  */
  83.  
  84. /*
  85.  *      LOCAL TYPEDEFS
  86.  *
  87.  */
  88.  
  89. /*
  90.  *      LOCALS VARIABLES
  91.  */
  92. #ifdef DEBUG
  93. #  define STATIC
  94. #else
  95. #  define STATIC        static
  96. #endif
  97.  
  98.  
  99.  
  100. /************************************************************************
  101.  *                                    *
  102.  *            PRIVATE ROUTINES                *
  103.  *                                    *
  104.  ************************************************************************/
  105.  
  106. /* ARGSUSED */
  107. STATIC void ChangedHue(w, pwhich, pcall)
  108. Widget w;
  109. XtPointer pwhich;
  110. XtPointer pcall;
  111. {
  112.     int which = (int)pwhich;
  113.     ScaleCallbackStruct *call = (ScaleCallbackStruct *)pcall;
  114.     XcmsColor new;
  115.  
  116.     switch (call->reason) {
  117.     /* Just end of gesture, don't change any values */
  118.     case CR_DISARM:
  119.     EndColor(which);
  120.     return;
  121.     /* First event of gesture */
  122.     case CR_ARM:
  123.     BeginGesture(GestureMouse);
  124.     return;
  125.     /* Gesture is a single event; so record the gesture as completed */
  126.     case CR_SINGLE_SELECT:
  127.     BeginGesture(GestureNone);
  128.     break;
  129.     case CR_DRAG:
  130.     case CR_VALUE_CHANGED:
  131.     break;
  132.     }
  133.  
  134.     new.spec.TekHVC.H = (XcmsFloat)call->value / 10.0;
  135.     new.spec.TekHVC.V = currentHvc.spec.TekHVC.V;
  136.     new.spec.TekHVC.C = currentHvc.spec.TekHVC.C;
  137.     new.pixel = currentHvc.pixel;
  138.     new.format = XcmsTekHVCFormat;
  139.     NewHvc(&new, which, HueChange);
  140.  
  141.     call->value = (int)(new.spec.TekHVC.H * 10.0);
  142. }
  143.  
  144.  
  145. /************************************************************************
  146.  *                                    *
  147.  *            PUBLIC ROUTINES                    *
  148.  *                                    *
  149.  ************************************************************************/
  150. Widget CreateHueForm(parent, name, args, count)
  151. Widget parent;
  152. char *name;
  153. Arg *args;
  154. Cardinal count;
  155. {
  156.     Widget hue_form = XtCreateManagedWidget(name, colorScaleWidgetClass, 
  157.                             parent, args, count);
  158.     XtAddCallback(hue_form, XtNvalueChangedCallback, ChangedHue,
  159.           (XtPointer)HuebarWidget);
  160.     return(hue_form);
  161. }
  162.  
  163. void UpdateHueWidget()
  164. {
  165.     int adjusted;
  166.     Arg arg;
  167.  
  168.     adjusted = (int)(currentHvc.spec.TekHVC.H * 10.0 + 0.5);
  169.     /* rounding may put hue over 359.9 */
  170.     if (adjusted >= 3600)
  171.     adjusted -= 3600;
  172.     XtSetArg(arg, XtNvalue, adjusted);
  173.     XtSetValues(huebar, &arg, 1);
  174. }
  175.