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
/
show.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-28
|
14KB
|
527 lines
/*
* Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
* All Rights Reserved
*
* This file is a component of an X Window System client which uses the Xcms
* Color Management System. TekColor is a trademark of Tektronix, Inc. The
* TekColor Editor is the subject of U.S. and foreign patents pending. The
* term "TekHVC" designates a particular color space that is the subject of
* U.S. Patent No. 4,985,853 (equivalent foreign patents pending).
* Permission is hereby granted to use, copy, modify, sell, and otherwise
* distribute this software and its documentation for the X Window System
* environment, for any purpose and without fee, provided that:
*
* 1. The code and documentation are only used to implement a
* TekColor Editor in an X Window System environment; and
* 2. This copyright and permission notice is reproduced in all copies
* of the code and in supporting documentation.
*
* Permission is granted to modify this code as required to allow it to
* be compiled on any host computer, provided that the functionality of
* the TekColor Editor is not modified in any way. A description of any
* modifications must be sent to Tektronix, Inc. Contact
* Tektronix Inc., P.O. Box 1000, Mail Station 60-850,
* Network Displays Division Engineering, Wilsonville, OR 97070.
*
* Tektronix makes no representation about the suitability of this software
* for any purpose. It is provided "as is" and with all faults.
*
* TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
* INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
*
* NAME
* show - create and manage coordinate display widgets
*
* DESCRIPTION
* Create and manage all coordinate displays.
* Respond to user inputs.
*/
#ifndef LINT
static char *copy_notice = "Copyright 1991 Tektronix, Inc.";
#ifdef RCS_ID
static char *rcsid= "$Header: show.c,v 1.3 91/08/28 10:03:42 adamsc Exp $";
#endif /* RCS_ID */
#endif /* LINT */
/*
* EXTERNAL INCLUDES
*/
/*
* INTERNAL INCLUDES
*/
#include "xtici.h"
#include <X11/Xaw/Form.h>
#include "widgets/TriText.h"
#include "patch.h"
/*
* EXTERNS
*/
extern void AllowFloat();
extern void AllowInt();
/*
* GLOBALS
*/
#ifdef DEC
# define GLOBAL global
#else
# define GLOBAL
#endif
GLOBAL int showMask = (1 << HvcWidget);
/*
* LOCAL DEFINES
*/
#define ConstrainRgb(c) {if ((c) > 255) (c) = 255;}
#define MaxShort 0xffff
/*
* LOCAL TYPEDEFS
*/
/*
* LOCALS VARIABLES
*/
#ifdef DEBUG
# define STATIC
#else
# define STATIC static
#endif
STATIC int lastFocus = GestureNone;
/*
* All are initially attached to upper right of form simply to insure
* proper sizes are created. These default attachments are overridden
* when managed.
*/
STATIC Arg hvcArgs[] = {
{XtNlabelList, NULL},
{XtNfloatList, NULL},
{XtNformat, (XtArgVal)"%.1f"},
{XtNlength, 5},
};
STATIC Arg uvyArgs[] = {
{XtNlabelList, NULL},
{XtNfromHoriz, NULL},
{XtNformat, (XtArgVal)"%.3f"},
{XtNfloatList, NULL},
{XtNlength, 5},
};
STATIC Arg rgbArgs[] = {
{XtNlabelList, NULL},
{XtNfromHoriz, NULL},
{XtNformat, (XtArgVal)"%.0f"}, /* TODO: display from 0 to 1.0 ? */
{XtNfloatList, NULL},
{XtNlength, 3},
};
/************************************************************************
* *
* PRIVATE ROUTINES *
* *
************************************************************************/
/* ARGSUSED */
STATIC void setShowGesture(wid, psource, pcall)
Widget wid;
XtPointer psource;
XtPointer pcall;
{
Widget source = (Widget)psource;
TriCallbackStruct *call = (TriCallbackStruct *)pcall;
if (source == hvcShow) {
switch (call->index) {
case 0:
gesture = GestureHue;
break;
case 1:
gesture = GestureValue;
break;
case 2:
gesture = GestureChroma;
break;
default:
gesture = GestureNone;
return;
}
} else if (source == uvyShow) {
switch (call->index) {
case 0:
gesture = GestureUprime;
break;
case 1:
gesture = GestureVprime;
break;
case 2:
gesture = GestureCapY;
break;
default:
gesture = GestureNone;
return;
}
} else if (source == rgbShow) {
switch (call->index) {
case 0:
gesture = GestureRed;
break;
case 1:
gesture = GestureGreen;
break;
case 2:
gesture = GestureBlue;
break;
default:
gesture = GestureNone;
return;
}
} else {
gesture = GestureNone;
}
}
/*
* This routine is not needed for the local client, because its text
* widgets detect a premature change in focus.
*/
/* ARGSUSED */
STATIC void showFocus(w, pgestureCode, pcall)
Widget w;
XtPointer pgestureCode;
XtPointer pcall;
{
int gestureCode = (int)pgestureCode;
TriCallbackStruct *call = (TriCallbackStruct *)pcall;
int code = gestureCode + call->index;
/*
* Detect when the focus is moved from another text widget with
* an active gesture. However,
* focus is lost and gained when application looses/gains focus,
* so check if the gesture truly is a change (from another text widget)
* before reacting as if it is a new gesture.
*
* lastFocus tracks exactly which text widget has the focus.
* This allows detecting changes within the TriText widget.
* So use lastFocus, not gesture.
*/
if ( (gesture > GestureMouse) && (lastFocus != code) )
TerminateGesture();
lastFocus = code;
}
/************************************************************************
* *
* PUBLIC ROUTINES *
* *
************************************************************************/
STATIC String hvcLabels[] = {
"HUE:",
"VALUE:",
"CHROMA:"
};
STATIC String uvYLabels[] = {
"u':",
"v':",
"Y:"
};
STATIC String rgbLabels[] = {
"RED:",
"GREEN:",
"BLUE:"
};
/*
* Create these so that the tab ordering is natural.
* Displayed in order (patch) - HVC - u'v'Y - RGB - (form)
*/
Widget CreateShowWidgets(parent)
Widget parent;
{
Widget self = XtCreateWidget ("show", formWidgetClass, parent, NULL, 0);
XtTranslations mytrans;
STATIC char defaults[] = "#augment\n\
<Leave>: leave()";
/*
* only one coordinate system is displayed initially, HVC.
*/
XtSetArg(hvcArgs[0], XtNlabelList, hvcLabels);
XtSetArg(hvcArgs[1], XtNfloatList, ¤tHvc.spec.TekHVC);
hvcShow = XtCreateManagedWidget("hvc", triTextWidgetClass, self,
hvcArgs, XtNumber(hvcArgs));
XtAddCallback(hvcShow, XtNactivateCallback, setShowGesture,
(XtPointer)hvcShow);
XtAddCallback(hvcShow, XtNfocusCallback, showFocus,
(XtPointer)GestureHue);
XtAddCallback(hvcShow, XtNmodifyVerifyCallback, AllowFloat,
(XtPointer)GestureHue);
mytrans = XtParseTranslationTable(defaults);
XtAugmentTranslations (hvcShow, mytrans);
XtSetArg(uvyArgs[0], XtNlabelList, uvYLabels);
XtSetArg(uvyArgs[1], XtNfromHoriz, hvcShow);
/*********************************************************************
* Since this widget is only used when selected from the
* Coordinates menu it is only managed when needed.
*********************************************************************/
uvyShow = XtCreateWidget("uvy", triTextWidgetClass, self,
uvyArgs, XtNumber(uvyArgs));
XtAddCallback(uvyShow, XtNactivateCallback, setShowGesture,
(XtPointer)uvyShow);
XtAddCallback(uvyShow, XtNfocusCallback, showFocus,
(XtPointer)GestureUprime);
XtAddCallback(uvyShow, XtNmodifyVerifyCallback, AllowFloat,
(XtPointer)GestureUprime);
XtAugmentTranslations (uvyShow, mytrans);
XtSetArg(rgbArgs[0], XtNlabelList, rgbLabels);
XtSetArg(rgbArgs[1], XtNfromHoriz, uvyShow);
/*********************************************************************
* Since this widget is only used when selected from the
* Coordinates menu it is only managed when needed.
*********************************************************************/
rgbShow = XtCreateWidget("rgb", triTextWidgetClass, self,
rgbArgs, XtNumber(rgbArgs));
XtAddCallback(rgbShow, XtNactivateCallback, setShowGesture,
(XtPointer)rgbShow);
XtAddCallback(rgbShow, XtNfocusCallback, showFocus,
(XtPointer)GestureRed);
XtAddCallback(rgbShow, XtNmodifyVerifyCallback, AllowInt,
(XtPointer)GestureRed);
XtAugmentTranslations (rgbShow, mytrans);
XtManageChild(self);
return(self);
}
/*
* Change which show widgets are displayed
*/
void ChangeShowed(which)
int which;
{
int flag;
Widget left, target, right;
Arg leftArgs[2], targetArgs[2];
Boolean show; /* if true, manage; if false, unmanage */
/* set show to False to turn off and True to turn on */
switch (which) {
case RgbWidget:
target = rgbShow;
if (UvyShowing)
left = uvyShow;
else
left = NULL;
right = hvcShow;
flag = 1 << RgbWidget;
if (RgbShowing)
show = False;
else
show = True;
break;
case UvyWidget:
target = uvyShow;
left = NULL;
if (RgbShowing)
right = rgbShow;
else
right = hvcShow;
flag = 1 << UvyWidget;
if (UvyShowing)
show = False;
else
show = True;
break;
}
if (show) {
XtSetArg(targetArgs[0], XtNfromHoriz, left);
XtSetValues(target, targetArgs, 1);
XtSetArg(leftArgs[0], XtNfromHoriz, target);
XtSetValues(right, leftArgs, 1);
XtManageChild(target);
showMask |= flag;
} else {
XtSetArg(leftArgs[0], XtNfromHoriz, left);
XtSetValues(right, leftArgs, 1);
XtUnmanageChild(target);
showMask &= ~flag;
}
}
void GetShowHvc(hvc)
XcmsColor *hvc;
{
XcmsFloat list[3];
TriTextGetList((TriTextWidget)hvcShow, list);
hvc->spec.TekHVC.H = list[0];
hvc->spec.TekHVC.V = list[1];
hvc->spec.TekHVC.C = list[2];
hvc->format = XcmsTekHVCFormat;
}
void GetShowRgb(rgb)
XColor *rgb;
{
XcmsFloat list[3];
TriTextGetList((TriTextWidget)rgbShow, list);
rgb->red = (unsigned short)list[0] << 8;
rgb->green = (unsigned short)list[1] << 8;
rgb->blue = (unsigned short)list[2] << 8;
}
void GetShowUvy(uvy)
XcmsCIEuvY *uvy;
{
XcmsFloat list[3];
TriTextGetList((TriTextWidget)uvyShow, list);
uvy->u_prime = list[0];
uvy->v_prime = list[1];
uvy->Y = list[2];
}
void NewRgb(which, newPiece, where)
int which; /* identifies component */
unsigned short newPiece;
int where;
{
XcmsColor color;
if (newPiece > MaxShort)
newPiece = MaxShort;
switch (which) {
case RedChange:
if (newPiece == currentRgb.red)
return;
currentRgb.red = newPiece;
break;
case GreenChange:
if (newPiece == currentRgb.green)
return;
currentRgb.green = newPiece;
break;
case BlueChange:
if (newPiece == currentRgb.blue)
return;
currentRgb.blue = newPiece;
break;
}
EditRgbCells(¤tRgb, 1);
/* update the interface */
bcopy((char *)¤tMap[currentIndex],(char *)&color,sizeof(XcmsColor));
/* don't know how a change in a RGB component affects HVC */
NewColor(&color, where, UnknownChange);
}
void NewUvy(which, newPiece, where)
int which; /* identifies component */
XcmsFloat newPiece;
int where;
{
XcmsColor uvy;
XcmsColor color;
switch (which) {
case UprimeChange:
if (newPiece == currentUvy.u_prime)
return;
currentUvy.u_prime = newPiece;
break;
case VprimeChange:
if (newPiece == currentUvy.v_prime)
return;
currentUvy.v_prime = newPiece;
break;
case CapYChange:
if (newPiece == currentUvy.Y)
return;
currentUvy.Y = newPiece;
break;
}
uvy.pixel = currentIndex;
uvy.format = XcmsCIEuvYFormat;
uvy.spec.CIEuvY = currentUvy;
EditUvyCells(&uvy, 1);
/* update the interface */
bcopy((char *)¤tMap[currentIndex],(char *)&color,sizeof(XcmsColor));
/* don't know how a change in a uvY component affects HVC */
NewColor(&color, where, UnknownChange);
}
/* Set displayed coordinates to current values */
void UpdateShowWidget(which)
int which;
{
Widget w;
XcmsFloat showFloat[3], *XcmsFloatp;
XcmsColor uvy;
switch (which) {
case HvcWidget:
w = hvcShow;
XcmsFloatp = (XcmsFloat *)¤tHvc.spec.TekHVC;
break;
case RgbWidget:
w = rgbShow;
currentRgb.pixel = currentIndex;
XQueryColor(dpy, cmap, ¤tRgb);
/* scale to 0-255; unsigned shift should not propogate sign bit */
showFloat[0] = (XcmsFloat)(currentRgb.red >> 8);
showFloat[1] = (XcmsFloat)(currentRgb.green >> 8);
showFloat[2] = (XcmsFloat)(currentRgb.blue >> 8);
XcmsFloatp = showFloat;
break;
case UvyWidget:
w = uvyShow;
uvy.pixel = currentIndex;
uvy.format = XcmsCIEuvYFormat;
if (XcmsQueryColor(dpy, cmap, &uvy, XcmsCIEuvYFormat) == XcmsFailure) {
#ifdef XDEBUG
fprintf (stderr, "Warning: XcmsQueryColor failed in UpdateShowWidget\n");
#endif
break;
}
currentUvy = uvy.spec.CIEuvY;
showFloat[0] = currentUvy.u_prime;
showFloat[1] = currentUvy.v_prime;
showFloat[2] = currentUvy.Y;
XcmsFloatp = showFloat;
break;
default:
return;
}
/* HACK: mark that program is changing text */
textProgramInput++;
TriTextSetList((TriTextWidget)w, XcmsFloatp);
--textProgramInput;
}