panel01/06

David A. Tristram dat at ORVILLE.NAS.NASA.GOV
Fri Aug 19 07:20:00 AEST 1988


#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
# This is part 1 of a multipart archive                                    
# do not concatenate these parts, unpack them in order with /bin/sh        
#
#	Run the following text with /bin/sh to create:
#	  Makefile
#	  README
#	  VERSION
#	  button.c
#	  colormod.c
#	  demo.c
#	  demo10.c
#	  demo11.c
#	  demo12.c
#	  demo13.c
#	  demo14.c
#	  demo15.c
#	  demo16.c
#	  demo17.c
#	  demo18.c
#	  demo19.c
#	  demo2.c
#	  demo20.c
#	  demo21.c
#	  demo22.c
#	  demo23.c
#	  demo24.c
#	  demo25.c
#	  demo26.c
#	  demo3.c
#	  demo4.c
#	  demo5.c
#	  demo6.c
#	  demo7.c
#	  demo8.c
#	  demo9.c
#	  dial.c
#	  ep.c
#	  epslideroid.c
#	  eric.c
#	  fade.c
#	  g_gets.c
#	  gets.c
#	  mouse.c
#	  palette.c
#	  panel.c
#	  panel.h
#	  puck.c
#	  script.c
#	  slider.c
#	  slideroid.c
#	  stoa.c
#	  strip.c
#	  typein.c
#	  typeout.c
#
if test -r s2_seq_.tmp
then echo "Must unpack archives in sequence!"
     next=`cat s2_seq_.tmp`; echo "Please unpack part $next next"
     exit 1; fi
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
X#
X#   IRIS_4D flags
X#
X#CFLAGS= -g -DDEBUG -DIRIS_4D
X#CFLAGS= -g -DIRIS_4D
X#CFLAGS= -g -DIRIS_4D
X#ARFLAGS= rsv
X#RANLIB= ar ts
X#
X#   IRIS_GT flags
X#
XCFLAGS= -g -DDEBUG -DIRIS_4D -DIRIS_NEWS -DIRIS_GT
XCFLAGS= -g -DIRIS_4D -DIRIS_NEWS -DIRIS_GT
XARFLAGS= rsv
XRANLIB= ar ts
X#
X#   IRIS_3000 flags
X#
X#CFLAGS= -g -DDEBUG
X#CFLAGS= -g
X#ARFLAGS= rv
X#RANLIB= ranlib
X#
X#
X#   installation destinations
X#
XINCLUDEDIR= /usr/local/include
XLIBDIR= /usr/local/lib
X#
X#   products
X#
XINCLUDE= panel.h
XLIB= libpanel.a
X#
X#   compilation control
X#
XINCLUDES= -I.
XLIBS= -lgl -lm
XLIBOBJS= ${LIB}(panel.o) ${LIB}(puck.o) ${LIB}(slider.o) ${LIB}(g_gets.o) \
X	 ${LIB}(strip.o) ${LIB}(button.o) ${LIB}(typein.o) ${LIB}(typeout.o) \
X	 ${LIB}(mouse.o) ${LIB}(slideroid.o) ${LIB}(palette.o) \
X	 ${LIB}(dial.o)
X
XDEMOSO= demo.o demo2.o demo3.o demo4.o demo5.o \
X	demo6.o demo7.o demo8.o demo9.o demo10.o \
X	demo11.o demo12.o demo13.o demo14.o demo15.o \
X	demo16.o demo17.o demo18.o demo19.o demo20.o demo21.o \
X	demo22.o demo23.o demo24.o demo25.o demo26.o
XDEMOSO= demo25.o demo26.o
XAPPS=	ep stoa
X
XDEMOS= ${DEMOSO:.o=}
X
Xall:	${LIB} ${DEMOS} ${APPS}
X
X${APPS}:	panel.h
X
X.PRECIOUS:  ${LIB}
X
X${LIB}:	${LIBOBJS} panel.h
X	${RANLIB} ${LIB}
X
X${LIBOBJS}:
X	${CC} -c ${CFLAGS} $<
X	${LD} -r $*.o
X	/bin/mv a.out $*.o
X	${AR} ${ARFLAGS} $@ $*.o
X
X${DEMOS}: ${LIB}
X	${CC} -c ${CFLAGS} $@.c
X	${CC} ${CFLAGS} ${LDFLAGS} $@.o -o $@ ${LIB} ${LIBS}
X
X${DEMOSO}:   panel.h
X
X.o:	${LIB}
X	${CC} ${CFLAGS} ${LDFLAGS} $@.o -o $@ ${LIB} ${LIBS}
X
Xep:	ep.o script.o colormod.o fade.o ${LIB} panel.h
X	cc -o ep ep.o colormod.o fade.o script.o libpanel.a -lgl -lm
X
X#ep:	ep.u colormod.o fade.o ${LIB} panel.h
X#	cc -O3 -p -o ep ep.u colormod.o fade.o libpanel.a -lgl -lm
X#
X#ep.u:	ep.c
X#	${CC} -O3 ${INCLUDES} -j ep.c
X#	${CC} ${CFLAGS} -DDEBUG ${INCLUDES} -c ep.c
X
X.c.o:
X	cc ${CFLAGS} -c $< ${INCLUDES}
X
Xstoa:	stoa.o ${LIB} panel.h
X	cc -o stoa stoa.o libpanel.a -lgl -lm
X
Xclean:
X	-rm -f *.o
X
Xclobber:	clean
X	-rm ${DEMOS} ${LIB} ep stoa
X
Xinstall:
X	cp ${LIB} ${LIBDIR}
X	${RANLIB} ${LIBDIR}/${LIB}
X	cp ${INCLUDE} ${INCLUDEDIR}
X
SHAR_EOF
chmod 0644 Makefile || echo "restore of Makefile fails"
sed 's/^X//' << 'SHAR_EOF' > README &&
XThis is the panel library, a set of routines used for building "control
Xpanel" interfaces to interactive graphic applications.  These routines
Xlet you assemble "actuators" like sliders, buttons, stripcharts, and 
Xtypeouts into control panels that live on separate mex windows.  As the
Xuser mouses the actuators, values accessable to the applications programmer,
X(THAT'S YOU!) appear in predefined structures.  You can also set the values
Xand watch the positions or states of the actuators change.  You can 
Xcustomize the actuators in many ways because alot of their properties are
Xcontrolled by indirect functions that you can replace with your own.  In
Xfact, you can add new actuators without changing any of the panel library
Xcode because the initialization function is one of these indirect guys!
XSomeday all this will be nicely documented, but until then, hopefully you
Xcan get something out of the 20 or so demo programs.  Try ep, the
Xpsychedelic electro-paint program.  Have fun.
X
X	 David A Tristram
X	 NASA  Ames Research Center
X	 Numerical Aerodynamic Simulation Systems Division
X	 Moffett Field, CA  94035
X	 415-694-4404
X	 dat at ames-nas.ARPA
X
Xps: g_gets.c is useful in its own right, get strings from a graphics
X    program, thanks for preliminary work by Diana Choi.
X
XOperating Notes:
X
XTo see the panels, run the sgi utility makemap to load reasonable
Xvalues into the color map.  The colors can be changed either by
Xbashing the entries that are used, or changing the global variables
Xpnl_normal_color, pnl_highlight_color, pnl_other_color, etc.
X
X
XAdding Your Own Actuators.
X
XTo add your own actuators, you only have to support a couple of
Xfunctional interfaces.  The basic functions are drawX and my_X.
XDrawX draws the actuator in a standard 2D coordinate system, and my_X
Xis initialization code.  If your actuator is going to be mouse
Xsensitive, it also needs a newvalX function.  In this and the
Xfollowing discussion, X stands for the name of your new actuator, and
Xmy_ is a short prefix intended to help avoid collisions in a user's
Xname space.
X
XAdditional functions you may need for your actuator are addX, which
Xgetes executed when the actuator is added to a panel, ie., after the
Xuser has had an opportunity to customize its properties, and fixX,
Xwhich is used to bring an actuator's internal state up-to-date with
Xrespect to its environment.
X
XSo, to add an actuator type you would do something like this:
X
XStart a new source file beginning with 
X
X#include <gl.h>
X#include <panel.h>
X
Xthat is called <actuator>.c where <actuator> is the name or some
Xshortened form of the generic type of actuator you are adding.  For
Xexample, let's say you are adding an actuator called a dial consisting
Xof a circular pointer that you can turn with the mouse.  Your source
Xfile might be called dial.c
X
XIn your source file you need to support the following functions:
X
Xvoid drawdial(a, p)
XActuator *a;
XPanel *p;
X{
X/* The actuator's drawfunc gets called by dopanel() after normal mouse
X * event handling has be performed if the actuators dirtycnt is
X * non-zero.  The dirtycnt gets set automatically whenever an actuator
X * is selected, and may also be set by the user.  Fixact() also sets
X * the dirtycnt. */
X
X/* In drawdial goes code to actually draw the dial.  In the panel
X * library it is assumed that all actuators are rectangular, so you
X * might want to make some kind of background rectangle to indicate
X * the mouseable region.  On the iris it looks better to put an
X * outline around things.  Look at the code for the other actuators
X * for the names of the colors to use.  The actuators that come with
X * the panel library are drawn using a coordinate system that is
X * supposed to make it easier for the user to lay out control
X * panels.  Sliders, for example, are just under one unit wide and six
X * units high.  This allows the user to plunk his sliders down at
X * integer grid points and have the panel look okay.  There are some
X * manifest constants for the dimensions of the little spaces that
X * show up between actuators.  Use the val field of the Actuator
X * structure you get the pointer to when drawdial() is called to
X * determine what position to draw the dial in.  If your actuator
X * allows labels add a line like
X
X    if (a->label) drawlabel(a, p);
X
X * at the end of the function.
X */
X}
X
Xvoid my_dial(a)
XActuator *a;
X{
X/* this is initialization code that converts a generic actuator
X * structure to one that implements your kind of actuator.  You have
X * to tie all your functions to the actuator here. */
X
X    a->type=MY_DIAL;		/* an integer for your dials > PNL_MAXACT */
X
X    a->w=MY_DIAL_WIDTH;		/* like maybe 2.0-PNL_DIM_1 */
X    a->h=MY_DIAL_HEIGHT;	/* these are default dimensions, that
X				   the user can bash */
X
X/* you may want to do other initialization here, for example, you can
X * set the labeltype to one of the five predefined types.  If your
X * actuator has a special internal data structure, space for it should
X * be allocated for it here.
X */
X
X/* if you have other functions then they go here. like maybe: */
X/*  a->newvalfunc=newvaldial; */
X/*  a->addfunc=adddial; */
X    a->drawfunc=drawdial;
X}
X
X
Xvoid newvaldial(a,p,sx,sy)
XActuator *a;
XPanel *p;
XScreencoord sx,sy;
X{
X/* the newvalfunc for an actuator if first called when the mouse
X * button goes down and the mouse is within the rectangular region
X * defined by the actuator's x, y, w, and h.   It is then called
X * repeatedly while the mouse button remains down.  When the mouse
X * button goes up, the newvalfunc is called once again. */
X
X/* Sx and sy are screen (pixel) coordinates of the mouse relative to
X * the origin of the panel.  To get floating point coordinates
X * relative to the origin of your actuator, use: */
X
X    mapw2(p->vobj,sx,sy,&wx,&wy);
X    wx-=a->x;
X    wy-=a->y;
X
X/* Now you have to come up with some way to map the wx and wy to a new
X * value for your actuator.  Sliders, for example, take wy and scale
X * it to a fraction of the total height of the slider, and then
X * interpolate minval and maxval to come up with val.  For a dial you
X * might add the step of determining the angular distance from some
X * index mark, and use that as your interpolation fraction.  You will
X * notice that this is the inverse of the mapping that you made for
X * drawdial.
X */
X
X/* some actuators (toggle buttons, for example) have different
X * behavior when first moused.  You can examine the panel library
X * global variables pnl_justup and pnl_justdown to discriminate these
X * states. */
X}
X
Xvoid
Xadddial(a, p)
XActuator *a;
XPanel *p;
X{
X/* Dial actuators don't need an addfunc, but some actuators do special
X * processing when they are added to a panel.  Stripcharts, for
X * example, malloc space to store their histories.  If the user
X * desires, the storage capacity of a stripchart may be increased by
X * bumping the value of one of the fields in the stripchart's data
X * area.  Then, when the stripchart is added to a panel, its addfunc
X * is called which does the malloc.  Another example is the radio
X * button.  When it is added to a panel, its address is added to a
X * list of radio buttons that are forming a group.  The list is a
X * field called group in the actuator structure and you can use that
X * field to provide special interaction among a set of like actuators.
X */
X}
X
X
XTo use the new actuator, my_dial has to be declared as an external
Xreference.  When the user calls mkact() the argument to mkact
Xis a pointer to this my_dial.  The other functions are all scoped
Xlocally to dial.c and need not appear in the user code.
SHAR_EOF
chmod 0644 README || echo "restore of README fails"
sed 's/^X//' << 'SHAR_EOF' > VERSION &&
X7
SHAR_EOF
chmod 0644 VERSION || echo "restore of VERSION fails"
sed 's/^X//' << 'SHAR_EOF' > button.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat at orville.nas.nasa.gov
X */
X#include <gl.h>
X#include "panel.h"
X
Xvoid _newvalbutton(a,p,sx,sy)
XActuator *a;
XPanel *p;
XScreencoord sx,sy;
X{
X    a->val=pnl_mousedown;
X}
X
Xvoid _newvaltogglebutton(a,p,sx,sy)
XActuator *a;
XPanel *p;
XScreencoord sx,sy;
X{
X    if (pnl_justdown) a->val=(a->val!=0.0)?0.0:1.0;
X}
X
Xvoid _newvalradiobutton(a,p,sx,sy)
XActuator *a;
XPanel *p;
XScreencoord sx,sy;
X{
XActuator *b;
X
X    if (pnl_justdown) a->val=1.0;
X    for (b=a->group;(b!=a);b=b->group) {
X	b->val=0.0;
X	b->dirtycnt=2;
X    }
X}
X
Xvoid
X_addradiobutton(a, p)
XActuator *a;
XPanel *p;
X{
X    addtogroup(a, p);
X}
X
Xvoid
X_drawbutton(a, p)
XActuator *a;
XPanel *p;
X{
X    if (a->active) {
X	color(pnl_highlight_color);
X    } else {
X	color(pnl_normal_color);
X    }
X    rectf(a->x,a->y,a->x+a->w,a->y+a->h);
X    color(pnl_outline_color);
X    rect(a->x,a->y,a->x+a->w,a->y+a->h);
X    if (a->label) drawlabel(a, p);
X}
X
Xvoid
X_drawtogglebutton(a, p)
XActuator *a;
XPanel *p;
X{
X    if (a->val!=0.0) {
X	color(pnl_highlight_color);
X    } else {
X	color(pnl_normal_color);
X    }
X    rectf(a->x,a->y,a->x+a->w,a->y+a->h);
X    color(pnl_outline_color);
X    rect(a->x,a->y,a->x+a->w,a->y+a->h);
X    if (a->val!=0.0) {
X	move2(a->x,a->y);
X	draw2(a->x+a->w,a->y+a->h);
X	move2(a->x,a->y+a->h);
X	draw2(a->x+a->w,a->y);
X    }
X    if (a->label) drawlabel(a, p);
X}
X
Xvoid
X_drawwidebuttonshape(a, p, style)
XActuator *a;
XPanel *p;
Xint style;
X{
X  if (style==PNL_FILLED) {
X    move2(0.0,0.0);
X    rpmv2(PNL_DIM_2, 0.0);
X    rpdr2(a->w-2.0*PNL_DIM_2, 0.0);
X    rpdr2(PNL_DIM_2, PNL_DIM_2);
X    rpdr2(0.0, a->h-2.0*PNL_DIM_2);
X    rpdr2(-PNL_DIM_2, PNL_DIM_2);
X    rpdr2(-(a->w-2.0*PNL_DIM_2), 0.0);
X    rpdr2(-PNL_DIM_2, -PNL_DIM_2);
X    rpdr2(0.0, -(a->h-2.0*PNL_DIM_2));
X    pclos();
X  } else {
X    move2(0.0,0.0);
X    rmv2(PNL_DIM_2, 0.0);
X    rdr2(a->w-2.0*PNL_DIM_2, 0.0);
X    rdr2(PNL_DIM_2, PNL_DIM_2);
X    rdr2(0.0, a->h-2.0*PNL_DIM_2);
X    rdr2(-PNL_DIM_2, PNL_DIM_2);
X    rdr2(-(a->w-2.0*PNL_DIM_2), 0.0);
X    rdr2(-PNL_DIM_2, -PNL_DIM_2);
X    rdr2(0.0, -(a->h-2.0*PNL_DIM_2));
X    rdr2(PNL_DIM_2, -PNL_DIM_2);
X  }
X}
X
Xvoid
X_drawwidebutton(a, p)
XActuator *a;
XPanel *p;
X{
X  pushmatrix();
X  translate(a->x,a->y,0.0);
X  
X  if (!a->active)
X    color(pnl_normal_color);
X  else
X    color(pnl_highlight_color);
X
X  _drawwidebuttonshape(a, p, PNL_FILLED);
X  color(pnl_outline_color);
X  _drawwidebuttonshape(a, p, PNL_OPEN);
X
X  if (a->label&&(p->ppu>pnl_char_threshold)) {
X    if (!a->active)
X	color(pnl_outline_color);
X    else
X	color(pnl_normal_color);
X    cmov2(a->lx,a->ly+a->ld);
X    charstr(a->label);
X  }
X
X  popmatrix();
X}
X
Xvoid
Xpnl_button(a)
XActuator *a;
X{
X    a->type=PNL_BUTTON;
X
X    a->w=PNL_BUTTON_EDGE;
X    a->h=PNL_BUTTON_EDGE;
X    a->labeltype=PNL_LABEL_RIGHT;
X    a->newvalfunc=_newvalbutton;
X    a->drawfunc=_drawbutton;
X}
X
Xvoid
Xpnl_radio_button(a)
XActuator *a;
X{
X    a->type=PNL_RADIO_BUTTON;
X
X    a->w=PNL_BUTTON_EDGE;
X    a->h=PNL_BUTTON_EDGE;
X    a->labeltype=PNL_LABEL_RIGHT;
X    a->addfunc=_addradiobutton;
X    a->newvalfunc=_newvalradiobutton;
X    a->drawfunc=_drawtogglebutton;
X}
X
Xvoid
Xpnl_toggle_button(a)
XActuator *a;
X{
X    a->type=PNL_TOGGLE_BUTTON;
X
X    a->w=PNL_BUTTON_EDGE;
X    a->h=PNL_BUTTON_EDGE;
X    a->labeltype=PNL_LABEL_RIGHT;
X    a->newvalfunc=_newvaltogglebutton;
X    a->drawfunc=_drawtogglebutton;
X}
X
Xvoid
Xpnl_wide_button(a)
XActuator *a;
X{
X    a->type=PNL_WIDE_BUTTON;
X
X    a->w=PNL_WIDE_BUTTON_WIDTH;
X    a->h=PNL_WIDE_BUTTON_HEIGHT;
X    a->labeltype=PNL_LABEL_CENTER;
X    a->newvalfunc=_newvalbutton;
X    a->drawfunc=_drawwidebutton;
X}
X
SHAR_EOF
chmod 0644 button.c || echo "restore of button.c fails"
sed 's/^X//' << 'SHAR_EOF' > colormod.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat at orville.nas.nasa.gov
X */
X/*
X *	colormod -
X *		Define some transforms between different color models.
X *
X *
X *		   Henry Moreton and Paul Haeberli - 1984
X */
X#include "math.h"
X#include "stdio.h"
X
X/*
X *	Defines for colors used by window manager tools
X *
X *			Paul Haeberli - 1984
X *
X * (a subset, dat)
X */
X
X#define COLORSYS_RGB	1
X#define COLORSYS_CMY	2
X#define COLORSYS_HSV	3
X#define COLORSYS_HLS	4
X#define COLORSYS_YIQ	5
X
X#define max(x,y) ((x) > (y) ? (x) : (y))
X#define min(x,y) ((x) < (y) ? (x) : (y))
X
Xint rgb_to_rgb();
X
Xstatic int (*tofunc)() = rgb_to_rgb;
Xstatic int (*fromfunc)() = rgb_to_rgb;
Xstatic int colorsys = COLORSYS_RGB;
X
X/*
X *	Convert FROM various formats TO rgb.
X *
X *
X */
Xirgb_to_rgb( ir, ig, ib, r, g, b)
Xint ir, ig, ib;
Xfloat *r, *g, *b;
X{
X    *r = ir / 255.0;
X    *g = ig / 255.0;
X    *b = ib / 255.0;
X}
X
Xcmy_to_rgb ( c, m, y, r, g, b)
Xfloat c, m, y;
Xfloat *r, *g, *b;
X{
X    *r = 1.0 - c;
X    *g = 1.0 - m;
X    *b = 1.0 - y;
X}
X
Xstatic float value(n1, n2, hue)
Xfloat n1, n2, hue;
X{
X    if (hue > 360)
X	hue -= 360;
X    if (hue < 0)
X	hue += 360;
X    if (hue < 60)
X	return(n1 + (n2 - n1)*(hue/60.0));
X    if (hue < 180)
X	return(n2);
X    if (hue < 240)
X	return(n1 + (n2 - n1)*((240 - hue)/60.0));
X    return(n1);
X}
X
Xhls_to_rgb (h, l, s, r, g, b)
Xfloat	h, l, s;
Xfloat	*r, *g, *b;
X{
X    float	m1, m2;
X
X    h *= 360.0;
X    if (l <= 0.5)
X	m2 = l * (1 + s);
X    else
X	m2 = l + s - l*s;
X    m1 = 2*l - m2;
X    if (s == 0)
X	*r = *g = *b = l;
X    else {
X	*r = value(m1, m2, h + 120.0);
X	*g = value(m1, m2, h);
X	*b = value(m1, m2, h - 120.0);
X    }
X}
X
Xhsv_to_rgb( h, s, v, r, g, b)
Xfloat	h, s, v;
Xfloat	*r, *g, *b;
X{
X    int 	i;
X    float	f, p, q, t;
X
X    h *= 360.0;
X    if (s == 0) {
X	*r = v;
X	*g = v;
X	*b = v;
X    } else {
X	if (h == 360) 
X	    h = 0;
X	h /= 60;
X	i = (int) floor(h);
X	f = h - i;
X	p = v*(1 - s);
X	q = v*(1 - (s*f));
X	t = v*(1 - (s*(1 - f)));
X	switch (i) {
X	    case 0 : 
X		*r = v;
X		*g = t;
X		*b = p;
X		break;
X	    case 1 : 
X		*r = q;
X		*g = v;
X		*b = p;
X		break;
X	    case 2 : 
X		*r = p;
X		*g = v;
X		*b = t;
X		break;
X	    case 3 : 
X		*r = p;
X		*g = q;
X		*b = v;
X		break;
X	    case 4 : 
X		*r = t;
X		*g = p;
X		*b = v;
X		break;
X	    case 5 : 
X		*r = v;
X		*g = p;
X		*b = q;
X		break;
X	}
X    }
X}
X
Xyiq_to_rgb (y, i, q, r, g, b)
Xfloat	y, i, q;
Xfloat	*r, *g, *b;
X{
X/*
X    i = (i * 1.2) - 0.6;
X    q = (q * 1.04) - 0.52;
X    */
X    *r = 1.0 * y + 0.948262 * i + 0.624013 * q;
X    *g = 1.0 * y + -0.276066 * i + -0.63981 * q;
X    *b = 1.0 * y + -1.10545 * i + 1.72986 * q;
X
X}
X
X/*
X *	Convert FROM rgb TO rgb.
X *
X *
X */
Xrgb_to_rgb( fr, fg, fb, tr, tg, tb)
Xfloat fr, fg, fb;
Xfloat *tr, *tg, *tb;
X{
X    *tr = fr;
X    *tg = fg;
X    *tb = fb;
X}
X
X/*
X *	Convert TO various formats FROM rgb.
X *
X *
X */
Xrgb_to_cmy( r, g, b, c, m, y)
Xfloat r, g, b;
Xfloat *c, *m, *y;
X{
X    *c = 1.0 - r;
X    *m = 1.0 - g;
X    *y = 1.0 - b;
X}
X
Xrgb_to_irgb( r, g, b, ir, ig, ib)
Xfloat r, g, b;
Xint *ir, *ig, *ib;
X{
X    *ir = (int) (r * 255.0);
X    *ig = (int) (g * 255.0);
X    *ib = (int) (b * 255.0);
X}
X
Xrgb_to_hls( r, g, b, h, l, s)
Xfloat r, g, b;
Xfloat *h, *l, *s;
X{
X    float rc, gc, bc;
X    float maxcol, mincol;
X
X    maxcol = max( r, max( g, b));
X    mincol = min( r, min( g, b));
X    *l = (mincol + maxcol) / 2;		/* lightness */
X    if (maxcol == mincol) {		/* achromatic case */
X	*s = 0;		/* *h is undefined in the achromatic case */
X	*h = 0;
X    } else {
X	if (*l <= 0.5)
X	    *s = (maxcol - mincol) / (maxcol + mincol);
X	else
X	    *s = (maxcol - mincol) / (2 - maxcol - mincol);
X	
X	/* find hue */
X	rc = (maxcol - r) / (maxcol - mincol);
X	gc = (maxcol - g) / (maxcol - mincol);
X	bc = (maxcol - b) / (maxcol - mincol);
X	if (r == maxcol)
X	    *h = bc - gc;
X	else if (g == maxcol)
X	    *h = 2 + rc - bc;
X	else 
X	    *h = 4 + gc - rc;
X	
X	*h *= 60.0;
X	if ( *h < 0.0)
X	    *h += 360.0;
X	*h /= 360.0;
X    }
X}
X
Xrgb_to_hsv (r, g, b, lh, ls, lv)
Xfloat r, g, b;
Xfloat *lh, *ls, *lv;
X{
X    float h, s, v;
X    float cmax, cmin;
X    float rc, gc, bc;
X
X    /* find the cmax and cmin of r g b */
X    cmax = r; cmin = r;
X    cmax = (g > cmax ? g : cmax);
X    cmin = (g < cmin ? g : cmin);
X    cmax = (b > cmax ? b : cmax);
X    cmin = (b < cmin ? b : cmin);
X    v = cmax;		/* value */
X    if (cmax != 0)
X	s = (cmax - cmin) / cmax;
X    else {
X	s = 0;
X	h = 0;
X    }
X
X    if (s == 0)
X	h = -1;
X    else {
X	rc = (cmax - r)/(cmax - cmin);
X	gc = (cmax - g)/(cmax - cmin);
X	bc = (cmax - b)/(cmax - cmin);
X	if (r == cmax)
X	    h = bc - gc;
X	else
X	    if (g == cmax)
X		h = 2.0 + rc - bc;
X	    else
X		h = 4.0 + gc - rc;
X	h = h * 60.0;
X	if (h < 0.0)
X	    h += 360.0;
X    }
X    *ls = s;
X    *lh = h/360.0;
X    *lv = v;
X}
X
Xrgb_to_yiq (r, g, b, y, i, q)
Xfloat	r, g, b;
Xfloat	*y, *i, *q;
X{
X    *y = (0.3 * r + 0.59 * g + 0.11 * b);
X    *i = ((0.6 * r + -0.28 * g + -0.32 * b));
X    *q = ((0.21 * r + -0.52 * g + 0.31 * b));
X}
X
Xsetcolorsys(sys)
X{
X    switch(sys) {
X	case COLORSYS_RGB: tofunc = rgb_to_rgb;
X		  fromfunc = rgb_to_rgb;
X		  colorsys = sys;
X		  break;
X	case COLORSYS_CMY: tofunc = cmy_to_rgb;
X		  fromfunc = rgb_to_cmy;
X		  colorsys = sys;
X		  break;
X	case COLORSYS_HSV: tofunc = hsv_to_rgb;
X		  fromfunc = rgb_to_hsv;
X		  colorsys = sys;
X		  break;
X	case COLORSYS_HLS: tofunc = hls_to_rgb;
X		  fromfunc = rgb_to_hls;
X		  colorsys = sys;
X		  break;
X	case COLORSYS_YIQ: tofunc = yiq_to_rgb;
X		  fromfunc = rgb_to_yiq;
X		  colorsys = sys;
X		  break;
X 	default:  fprintf(stderr,"bad color system no %d\n",sys);
X		  break;
X    }
X}
X
Xgetcolorsys(sys)
X{
X    return colorsys;
X}
X
Xtorgb(r,g,b,tr,tg,tb)
Xfloat r, g, b;
Xfloat *tr, *tg, *tb;
X{
X    tofunc(r,g,b,tr,tg,tb);
X}
X
Xfromrgb(r,g,b,tr,tg,tb)
Xfloat r, g, b;
Xfloat *tr, *tg, *tb;
X{
X    fromfunc(r,g,b,tr,tg,tb);
X}
X
SHAR_EOF
chmod 0644 colormod.c || echo "restore of colormod.c fails"
sed 's/^X//' << 'SHAR_EOF' > demo.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat at orville.nas.nasa.gov
X */
X#include <gl.h>
X#include <device.h>
X#include "panel.h"
X
XActuator *s1, *s2, *b1, *b2, *b3;
X
XPanel
X*defpanel();
X
Xmain() 
X{
XActuator *a;
XPanel *panel;
X
X    foreground();
X    winopen("demo");
X
X    doublebuffer();
X    gconfig();
X
X    ortho2(-1.0,1.0,-1.0,1.0);
X
X    panel=defpanel();
X
X    for (;;) {
X        a=dopanel();
X	if (a==b1) {
X	    exit(0);
X	}
X
X	if (a==b2) {
X	    b3->val=b2->val;
X	    b3->dirtycnt=2;
X	}
X
X	pushmatrix();
X	translate(s1->val,s2->val,0.0);
X	color(BLACK);
X	clear();
X	color(WHITE);
X	drawit();
X	swapbuffers();
X	popmatrix();
X    }
X}
X
X
Xdrawit()
X{
X    rectf(-.10,-.10,.10,.10);
X}
X
X
XPanel
X*defpanel()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="demo";
X    panel->ppu=50.0;
X
X    s1=mkact(pnl_hslider);
X    s1->label="y position";
X    s1->x=1.0;
X    s1->y=0.0;
X    s1->minval= -1.0;
X    s1->maxval=1.0;
X    addact(s1, panel);
X
X    s2=mkact(pnl_vslider);
X    s2->label="x position";
X    s2->x=0.0;
X    s2->y=0.0;
X    s2->minval= -1.0;
X    s2->maxval=1.0;
X    addact(s2, panel);
X
X    b1=mkact(pnl_button);
X    b1->label="exit";
X    b1->x=1.0;
X    b1->y=1.0;
X    addact(b1, panel);
X
X    b2=mkact(pnl_toggle_button);
X    b2->label="push me";
X    b2->x=1.0;
X    b2->y=1.5;
X    addact(b2, panel);
X
X    b3=mkact(pnl_toggle_button);
X    b3->label="I push myself";
X    b3->x=1.0;
X    b3->y=2.0;
X    addact(b3, panel);
X
X    return panel;
X}
X
SHAR_EOF
chmod 0644 demo.c || echo "restore of demo.c fails"
sed 's/^X//' << 'SHAR_EOF' > demo10.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat at orville.nas.nasa.gov
X */
X/*
X * Stepmap -> A simple program which draws an empty window and then
X *            uses a control panel with a pair of radio buttons, a
X *            button, and a slider, to control which color the
X *            background is drawn it.
X */
X
X#include <stdio.h>
X#include <gl.h>
X#include <device.h>
X#include "panel.h"
X
X#define MIN_COLOR 0		/* Limit the range of the background */
X#define MAX_COLOR 1023
X#define MIN_RGB 0
X#define MAX_RGB 255
X
X#define METER_SIZE 2.0
X
Xint Next_Color = 0;		/* Color to draw the background in */
Xint Delta = 1;			/* 1 if Up pushed, -1 if Down pushed */
Xchar Amount[5];			/* Label for color slider */
X
XPanel *My_Panel;
XActuator *Color_Slider;		/* Pointer to color slider */
XActuator *Toggle_Button;	/* Pointer to animate toggle */
XActuator *Red_Meter;		/* Pointer to meter structure */
XActuator *Green_Meter;
XActuator *Blue_Meter;
XActuator *Red_Strip;
XActuator *Blue_Strip;
XActuator *Green_Strip;
X#define STRIP "                   "
Xchar Red_Label[20] = "Red=xxx";
Xchar Blue_Label[20] = "Blue=xxx";
Xchar Green_Label[20] = "Green=xxx";
Xchar Red_S_Label[20] = STRIP;
Xchar Blue_S_Label[20] = STRIP;
Xchar Green_S_Label[20] = STRIP;
X
Xvoid My_Draw()			/* Simply erase in the background color */
X{
X  color(Next_Color);
X  clear();
X  swapbuffers();
X}
X
Xvoid Set_Meters()
X{
X  short red, green, blue;
X  getmcolor(Next_Color,&red,&green,&blue);
X  Red_Meter->val = red;
X  Red_Meter->dirtycnt = 2;
X  Blue_Meter->val = blue;
X  Blue_Meter->dirtycnt = 2;
X  Green_Meter->val = green;
X  Green_Meter->dirtycnt = 2;
X
X  Red_Strip->val=red;	    fixact(Red_Strip);
X  Green_Strip->val=green;   fixact(Green_Strip);
X  Blue_Strip->val=blue;	    fixact(Blue_Strip);
X
X  sprintf(Red_Label,"Red=%d",red);
X  sprintf(Green_Label,"Green=%d",green);
X  sprintf(Blue_Label,"Blue=%d",blue);
X  sprintf(Red_S_Label,"Red=(%d,%d)",
X	  (int)Red_Strip->minval, (int)Red_Strip->maxval);
X  sprintf(Green_S_Label,"Green=(%d,%d)",
X	  (int)Green_Strip->minval, (int)Green_Strip->maxval);
X  sprintf(Blue_S_Label,"Blue=(%d,%d)",
X	  (int)Blue_Strip->minval, (int)Blue_Strip->maxval);
X}
X
Xvoid Eraser()			/* Pick the color to erase */
X{				/* Called indirectly by STEP button */
X
X  Next_Color += Delta;		/* Go to next color */
X
X  if (Next_Color < MIN_COLOR)	/* Make sure it is in range */
X    Next_Color = MAX_COLOR;
X  if (Next_Color > MAX_COLOR)
X    Next_Color = MIN_COLOR;
X
X  Color_Slider->val = Next_Color; /* Update the slider */
X  Color_Slider->dirtycnt = 2;
X  Set_Meters();
X  sprintf(Amount,"%4d",Next_Color); /* And its label */
X}
X
Xvoid setup()			/* Cause STEP to step up */
X{				/* Called by Up radio button */
X  Delta = 1;
X}
X
Xvoid setdown()
X{				/* Cause STEP to step down */
X  Delta = -1;			/* Called by Down radio button */
X}
X
Xvoid Slider_Color()
X{
X  Next_Color = Color_Slider->val;
X  Set_Meters();
X  sprintf(Amount,"%4d",Next_Color);
X}
X
Xvoid My_Exit()			/* Clean up and Exit */
X{				/* Called by Exit button */
X  exit(0);
X}
X
XPanel *Make_Panel()		/* Prepare the control panel */
X{
X  Panel *p;
X  Actuator *a;
X
X  My_Panel = p = mkpanel();	/* Control Panel */
X  p->label="Map Stepper";
X
X  a = mkact(pnl_wide_button);	/* Exit button */
X  a->label = "exit";
X  a->x = 11.4;
X  a->y = 0.0;
X  a->downfunc=My_Exit;
X  addact(a, p);
X
X  Color_Slider = mkact(pnl_vslider); /* Color Slider */
X  sprintf(Amount,"%4d",Next_Color);
X  Color_Slider->label = Amount;
X  Color_Slider->x = 0.0;
X  Color_Slider->y = 0.0;
X  Color_Slider->minval = MIN_COLOR;
X  Color_Slider->maxval = MAX_COLOR;
X  Color_Slider->val = 0.0;
X  Color_Slider->activefunc = Slider_Color;
X  addact(Color_Slider, p);
X
X  Red_Meter = a = mkact(pnl_analog_bar); /* Red Analog meter */
X  a->label  = Red_Label;
X  a->x = 1.0;
X  a->y = 0.0;
X  a->minval = MIN_RGB;
X  a->maxval = MAX_RGB;
X  addact(a, p);
X
X  Blue_Meter = a = mkact(pnl_meter); /* Blue Analog Meter */
X  a->label  = Blue_Label;
X  a->x = 1.0;
X  a->y = 4.2;
X  a->minval = MIN_RGB;
X  a->maxval = MAX_RGB;
X  addact(a, p);
X
X  Green_Meter = a = mkact(pnl_meter); /* Green Analog Meter */
X  a->label  = Green_Label;
X  a->x = 1.0;
X  a->y = 2.1;
X  a->minval = MIN_RGB;
X  a->maxval = MAX_RGB;
X  addact(a, p);
X
X  Red_Strip = a = mkact(pnl_scale_chart);
X  a->label = Red_S_Label;
X  a->x = 4.0;
X  a->y = 0.0;
X  a->minval = MIN_RGB;
X  a->maxval = MAX_RGB;
X  addact(a, p);
X
X  Blue_Strip = a = mkact(pnl_scale_chart);
X  a->label = Blue_S_Label;
X  a->x = 4.0;
X  a->y = 4.2;
X  ((Stripchart *)a->data)->Bind_Low = TRUE;
X  addact(a, p);
X
X  Green_Strip = a = mkact(pnl_strip_chart);
X  a->label = Green_S_Label;
X  a->x = 4.0;
X  a->y = 2.1;
X  a->minval = MIN_RGB;
X  a->maxval = MAX_RGB;
X  addact(a, p);
X
X  a= mkact(pnl_button);		/* Step button */
X  a->label = "Step";
X  a->x = 11.4;
X  a->y = 1.0;
X  a->activefunc=Eraser;
X  addact(a, p);
X
X  Toggle_Button = mkact(pnl_toggle_button);
X  Toggle_Button->label = "Animate";
X  Toggle_Button->x = 11.4;
X  Toggle_Button->y = 0.5;
X  addact(Toggle_Button, p);
X
X  a=mkact(pnl_radio_button);	/* UP button */
X  a->label = "UP";
X  a->val = 1.0;
X  a->x = 11.4;
X  a->y = 2.5;
X  a->downfunc = setup;
X  setup();
X  addact(a, p);
X
X  a=mkact(pnl_radio_button);	/* Down button */
X  a->label = "DOWN";
X  a->x = 11.4;
X  a->y = 2.0;
X  a->downfunc = setdown;
X  addact(a, p);
X
X  endgroup(p);			/* Finish up, jack */
X  Set_Meters();
X}
X
X#define Draw_Twice My_Draw(); My_Draw();
X
Xmain()
X{
X  foreground();			/* Only for debugging */
X  keepaspect(1,1);
X  winopen("My Panel");		/* Window to draw in */
X  doublebuffer();		/* Run double buffered */
X  gconfig();
X
X  Make_Panel();			/* Initiate the panel */
X  needredraw();			/* Force it to be drawn */
X
X  ortho2(0.0,1.0,0.0,1.0);
X  Draw_Twice;			/* Initial draw of my output */
X  while (1) {			/* Classic busy loop */
X    if (Toggle_Button->val == 1.0) {
X      Eraser();
X    }
X    if (dopanel()) {		/* Some panel activity occured */
X      do {
X	My_Draw();		/* Redraw with new parameters */
X      } while (dopanel());	/* As long as panel activity occurs */
X      My_Draw();		/* Redraw with new parameters */
X      drawpanel();		/* Redraw the panel */
X      My_Draw();
X    }
X    if (userredraw()) {		/* Moved or reshaped my window */
X      reshapeviewport();
X      ortho2(0.0,1.0,0.0,1.0);
X      Draw_Twice;
X    }
X    My_Draw();
X  }
X}
SHAR_EOF
chmod 0644 demo10.c || echo "restore of demo10.c fails"
sed 's/^X//' << 'SHAR_EOF' > demo11.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat at orville.nas.nasa.gov
X */
X#include <gl.h>
X#include "panel.h"
X
Xmain()
X{
Xint i;
Xchar *s;
X
X    foreground();
X    winopen();
X    doublebuffer();
X    gconfig();
X    drawit();
X    for (;;) {
X	cmov2i(100,100);
X	s=g_getstring(WHITE, BLUE, RED, "Edit this string", 30);
X	printf("s=%x  ",s);
X	for (i=0;i<10;i++) printf("[%3d] ",s[i]); 
X	printf("\n");
X        if (s) printf("%s\n",s);
X	drawit();
X    }
X}
X
Xdrawit()
X{
X    color(BLACK);
X    clear();
X    cmov2i(100,100);
X    color(RED);
X    charstr("Edit this string");
X    swapbuffers();
X}
SHAR_EOF
chmod 0644 demo11.c || echo "restore of demo11.c fails"
sed 's/^X//' << 'SHAR_EOF' > demo12.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat at orville.nas.nasa.gov
X */
X#include <gl.h>
X#include <device.h>
X#include "panel.h"
X
XActuator *s1, *s2, *b1, *b2, *b3, *b4, *rb1, *rb2, *rb3;
X
XPanel
X*defpanel1(), *defpanel2(), *defpanel3();
X
Xmain() 
X{
XActuator *a;
XPanel *panel1;
XPanel *panel2;
Xshort col=RED;
X
X    foreground();
X    winopen("demo");
X    doublebuffer();
X    gconfig();
X
X    ortho2(-1.0,1.0,-1.0,1.0);
X
X    defpanel1();
X    defpanel2();
X    defpanel3();
X
X    for (;;) {
X        a=dopanel();
X	if (a==b1) exit(0);
X	if (a==b4) dumppanel();
X	if (a==b2) {
X	    b3->val=b2->val;
X	    b3->dirtycnt=2;
X	}
X	if (a==rb1) col=CYAN;
X	if (a==rb2) col=GREEN;
X	if (a==rb3) col=RED;
X
X	pushmatrix();
X	translate(s1->val,s2->val,0.0);
X	color(BLACK);
X	clear();
X	color(col);
X	drawit();
X	swapbuffers();
X	popmatrix();
X    }
X}
X
X
Xdrawit()
X{
X    rectf(-.10,-.10,.10,.10);
X}
X
X
XPanel
X*defpanel1()
X{
XActuator *a;
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel one";
X    panel->ppu=50.0;
X
X    s1=mkact(pnl_hslider);
X    s1->label="y position";
X    s1->x=1.0;
X    s1->y=0.0;
X    s1->minval= -1.0;
X    s1->maxval=1.0;
X    addact(s1, panel);
X
X    b2=mkact(pnl_toggle_button);
X    b2->label="push me";
X    b2->x=1.0;
X    b2->y=1.5;
X    addact(b2, panel);
X
X    b3=mkact(pnl_toggle_button);
X    b3->label="I push myself";
X    b3->x=1.0;
X    b3->y=2.0;
X    addact(b3, panel);
X
X    a=mkact(pnl_typein);
X    a->x=4.0;
X    a->y=2.0;
X    a->labeltype=PNL_LABEL_TOP;
X    a->label="a typein window";
X    PNL_ACCESS(Typein,a,str)="Edit This String";
X    addact(a,panel);
X
X    return panel;
X}
X
XPanel
X*defpanel2()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel two";
X    panel->ppu=50.0;
X
X    s2=mkact(pnl_vslider);
X    s2->label="x position";
X    s2->x=0.0;
X    s2->y=0.0;
X    s2->minval= -1.0;
X    s2->maxval=1.0;
X    addact(s2, panel);
X
X    b4=mkact(pnl_button);
X    b4->label="dumppanel";
X    b4->x=1.0;
X    b4->y=1.5;
X    addact(b4, panel);
X
X    b1=mkact(pnl_button);
X    b1->label="exit";
X    b1->x=1.0;
X    b1->y=1.0;
X    addact(b1, panel);
X
X    return panel;
X}
X
XPanel
X*defpanel3()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel three";
X    panel->ppu=50.0;
X
X    rb3=mkact(pnl_radio_button);
X    rb3->label="red";
X    rb3->x=1.0;
X    rb3->y=2.0;
X    rb3->val=1.0;
X    addact(rb3, panel);
X
X    rb2=mkact(pnl_radio_button);
X    rb2->label="green";
X    rb2->x=1.0;
X    rb2->y=1.5;
X    addact(rb2, panel);
X
X    rb1=mkact(pnl_radio_button);
X    rb1->label="cyan";
X    rb1->x=1.0;
X    rb1->y=1.0;
X    addact(rb1, panel);
X
X    return panel;
X}
X
SHAR_EOF
chmod 0644 demo12.c || echo "restore of demo12.c fails"
sed 's/^X//' << 'SHAR_EOF' > demo13.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat at orville.nas.nasa.gov
X */
X#include <gl.h>
X#include <device.h>
X#include "panel.h"
X
XActuator *s1, *s2, *b1, *b2, *b3, *b4, *rb1, *rb2, *rb3;
X
XPanel
X*defpanel1(), *defpanel2(), *defpanel3();
X
Xmain() 
X{
XActuator *a;
XPanel *panel1;
XPanel *panel2;
Xshort col=RED;
X
X    foreground();
X    winopen("demo");
X    doublebuffer();
X    gconfig();
X
X    ortho2(-1.0,1.0,-1.0,1.0);
X
X    defpanel1();
X    defpanel2();
X    defpanel3();
X
X    for (;;) {
X        a=dopanel();
X	if (a==b1) exit(0);
X	if (a==b4) dumppanel();
X	if (a==b2) {
X	    b3->val=b2->val;
X	    b3->dirtycnt=2;
X	}
X	if (a==rb1) col=CYAN;
X	if (a==rb2) col=GREEN;
X	if (a==rb3) col=RED;
X
X	pushmatrix();
X	translate(s1->val,s2->val,0.0);
X	color(BLACK);
X	clear();
X	color(col);
X	drawit();
X	swapbuffers();
X	popmatrix();
X    }
X}
X
X
Xdrawit()
X{
X    rectf(-.10,-.10,.10,.10);
X}
X
X
XPanel
X*defpanel1()
X{
XActuator *a;
XPanel *panel;
X
X    panel=mkpanel();
X    panel->ppu=40.0;
X
X    s1=mkact(pnl_filled_hslider);
X    s1->label="y position";
X    s1->x=1.0;
X    s1->y=0.0;
X    s1->minval= -1.0;
X    s1->maxval=1.0;
X    addact(s1, panel);
X
X    b2=mkact(pnl_toggle_button);
X    b2->label="push me";
X    b2->x=1.0;
X    b2->y=1.5;
X    addact(b2, panel);
X
X    b3=mkact(pnl_toggle_button);
X    b3->label="I push myself";
X    b3->x=1.0;
X    b3->y=2.0;
X    addact(b3, panel);
X
X    a=mkact(pnl_typein);
X    a->x=4.0;
X    a->y=2.0;
X    PNL_ACCESS(Typein,a,str)="Edit This String";
X    addact(a,panel);
X
X    return panel;
X}
X
XPanel
X*defpanel2()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel two";
X    panel->ppu=50.0;
X
X    s2=mkact(pnl_filled_vslider);
X    s2->label="x position";
X    s2->x=0.0;
X    s2->y=0.0;
X    s2->minval= -1.0;
X    s2->maxval=1.0;
X    addact(s2, panel);
X
X    b4=mkact(pnl_button);
X    b4->label="dumppanel";
X    b4->x=1.0;
X    b4->y=1.5;
X    addact(b4, panel);
X
X    b1=mkact(pnl_button);
X    b1->label="exit";
X    b1->x=1.0;
X    b1->y=1.0;
X    addact(b1, panel);
X
X    return panel;
X}
X
XPanel
X*defpanel3()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel three";
X    panel->ppu=50.0;
X
X    rb3=mkact(pnl_radio_button);
X    rb3->label="red";
X    rb3->x=1.0;
X    rb3->y=2.0;
X    rb3->val=1.0;
X    addact(rb3, panel);
X
X    rb2=mkact(pnl_radio_button);
X    rb2->label="green";
X    rb2->x=1.0;
X    rb2->y=1.5;
X    addact(rb2, panel);
X
X    rb1=mkact(pnl_radio_button);
X    rb1->label="cyan";
X    rb1->x=1.0;
X    rb1->y=1.0;
X    addact(rb1, panel);
X
X    return panel;
X}
X
SHAR_EOF
chmod 0644 demo13.c || echo "restore of demo13.c fails"
sed 's/^X//' << 'SHAR_EOF' > demo14.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat at orville.nas.nasa.gov
X */
X#include <gl.h>
X#include <device.h>
X#include "panel.h"
X
XActuator *s1, *s2, *b1, *b2, *b3, *b4, *rb1, *rb2, *rb3;
X
XPanel
X*defpanel1(), *defpanel2(), *defpanel3();
X
Xmain() 
X{
XActuator *a;
XPanel *panel1;
XPanel *panel2;
Xshort col=RED;
X
X    foreground();
X    winopen("demo");
X    doublebuffer();
X    gconfig();
X
X    ortho2(-1.0,1.0,-1.0,1.0);
X
X    defpanel1();
X    defpanel2();
X    defpanel3();
X
X    for (;;) {
X        a=dopanel();
X	if (a==b1) exit(0);
X	if (a==b4) dumppanel();
X	if (a==b2) {
X	    b3->val=b2->val;
X	    b3->dirtycnt=2;
X	}
X	if (a==rb1) col=CYAN;
X	if (a==rb2) col=GREEN;
X	if (a==rb3) col=RED;
X
X	pushmatrix();
X	translate(PNL_ACCESS(Puck, s1, x),PNL_ACCESS(Puck, s1, y),0.0);
X	color(BLACK);
X	clear();
X	color(col);
X	drawit();
X	swapbuffers();
X	popmatrix();
X    }
X}
X
X
Xdrawit()
X{
X    rectf(-.10,-.10,.10,.10);
X}
X
X
XPanel
X*defpanel1()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel one";
X    panel->ppu=50.0;
X
X    s1=mkact(pnl_puck);
X    s1->label="position";
X    s1->x=4.0;
X    s1->y=0.0;
X    s1->minval= -1.0;
X    s1->maxval=1.0;
X    addact(s1, panel);
X
X    b2=mkact(pnl_toggle_button);
X    b2->label="push me";
X    b2->x=1.0;
X    b2->y=1.5;
X    addact(b2, panel);
X
X    b3=mkact(pnl_toggle_button);
X    b3->label="I push myself";
X    b3->x=1.0;
X    b3->y=2.0;
X    addact(b3, panel);
X
X    return panel;
X}
X
XPanel
X*defpanel2()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel two";
X    panel->ppu=50.0;
X
X    b4=mkact(pnl_button);
X    b4->label="dumppanel";
X    b4->x=1.0;
X    b4->y=1.5;
X    addact(b4, panel);
X
X    b1=mkact(pnl_button);
X    b1->label="exit";
X    b1->x=1.0;
X    b1->y=1.0;
X    addact(b1, panel);
X
X    return panel;
X}
X
XPanel
X*defpanel3()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel three";
X    panel->ppu=50.0;
X
X    rb3=mkact(pnl_radio_button);
X    rb3->label="red";
X    rb3->x=1.0;
X    rb3->y=2.0;
X    rb3->val=1.0;
X    addact(rb3, panel);
X
X    rb2=mkact(pnl_radio_button);
X    rb2->label="green";
X    rb2->x=1.0;
X    rb2->y=1.5;
X    addact(rb2, panel);
X
X    rb1=mkact(pnl_radio_button);
X    rb1->label="cyan";
X    rb1->x=1.0;
X    rb1->y=1.0;
X    addact(rb1, panel);
X
X    return panel;
X}
X
SHAR_EOF
chmod 0644 demo14.c || echo "restore of demo14.c fails"
sed 's/^X//' << 'SHAR_EOF' > demo15.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat at orville.nas.nasa.gov
X */
X#include <gl.h>
X#include <device.h>
X#include "panel.h"
X
XActuator *s1, *s2, *b1, *b2, *b3, *b4, *rb1, *rb2, *rb3;
X
XPanel
X*defpanel1(), *defpanel2(), *defpanel3();
X
XCoord posx=0.0, posy=0.0, savx=0.0, savy=0.0;
X
Xmain() 
X{
XActuator *a;
XPanel *panel1;
XPanel *panel2;
Xshort col=RED;
X
X    foreground();
X    winopen("demo");
X    doublebuffer();
X    gconfig();
X
X    ortho2(-1.0,1.0,-1.0,1.0);
X
X    defpanel1();
X    defpanel2();
X    defpanel3();
X
X    for (;;) {
X        a=dopanel();
X	if (a==b1) exit(0);
X	if (a==b4) dumppanel();
X	if (a==b2) {
X	    b3->val=b2->val;
X	    b3->dirtycnt=2;
X	}
X	if (a==rb1) col=CYAN;
X	if (a==rb2) col=GREEN;
X	if (a==rb3) col=RED;
X
X	pushmatrix();
X	translate(posx, posy, 0.0);
X	color(BLACK);
X	clear();
X	color(col);
X	drawit();
X	swapbuffers();
X	popmatrix();
X    }
X}
X
X
Xdrawit()
X{
X    rectf(-.10,-.10,.10,.10);
X}
X
X
Xvoid
Xdeltapos(a)
XActuator *a;
X{
X    posx=savx+PNL_ACCESS(Puck, a, x);
X    posy=savy+PNL_ACCESS(Puck, a, y);
X}
X
Xvoid
Xbakepos(a)
XActuator *a;
X{
X    savx=posx;
X    savy=posy;
X}
X
XPanel
X*defpanel1()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel one";
X    panel->ppu=50.0;
X
X    s1=mkact(pnl_floating_puck);
X    s1->label="position";
X    s1->x=4.0;
X    s1->y=0.0;
X    s1->minval= -1.0;
X    s1->maxval=1.0;
X    s1->activefunc=deltapos;
X    s1->upfunc=bakepos;
X    addact(s1, panel);
X
X    b2=mkact(pnl_toggle_button);
X    b2->label="push me";
X    b2->x=1.0;
X    b2->y=1.5;
X    addact(b2, panel);
X
X    b3=mkact(pnl_toggle_button);
X    b3->label="I push myself";
X    b3->x=1.0;
X    b3->y=2.0;
X    addact(b3, panel);
X
X    return panel;
X}
X
XPanel
X*defpanel2()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel two";
X    panel->ppu=50.0;
X
X    b4=mkact(pnl_button);
X    b4->label="dumppanel";
X    b4->x=1.0;
X    b4->y=1.5;
X    addact(b4, panel);
X
X    b1=mkact(pnl_button);
X    b1->label="exit";
X    b1->x=1.0;
X    b1->y=1.0;
X    addact(b1, panel);
X
X    return panel;
X}
X
XPanel
X*defpanel3()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel three";
X    panel->ppu=50.0;
X
X    rb3=mkact(pnl_radio_button);
X    rb3->label="red";
X    rb3->x=1.0;
X    rb3->y=2.0;
X    rb3->val=1.0;
X    addact(rb3, panel);
X
X    rb2=mkact(pnl_radio_button);
X    rb2->label="green";
X    rb2->x=1.0;
X    rb2->y=1.5;
X    addact(rb2, panel);
X
X    rb1=mkact(pnl_radio_button);
X    rb1->label="cyan";
X    rb1->x=1.0;
X    rb1->y=1.0;
X    addact(rb1, panel);
X
X    return panel;
X}
X
SHAR_EOF
chmod 0644 demo15.c || echo "restore of demo15.c fails"
sed 's/^X//' << 'SHAR_EOF' > demo16.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat at orville.nas.nasa.gov
X */
X#include <gl.h>
X#include <device.h>
X#include "panel.h"
X
XActuator *s1, *s2, *b1, *b2, *b3, *b4, *rb1, *rb2, *rb3;
X
XPanel
X*defpanel1(), *defpanel2(), *defpanel3();
X
XCoord posx=0.0, posy=0.0, savx=0.0, savy=0.0;
X
Xmain() 
X{
XActuator *a;
XPanel *panel1;
XPanel *panel2;
Xshort col=RED;
X
X    foreground();
X    winopen("demo");
X    doublebuffer();
X    gconfig();
X
X    ortho2(-1.0,1.0,-1.0,1.0);
X
X    defpanel1();
X    defpanel2();
X    defpanel3();
X
X    for (;;) {
X        a=dopanel();
X	if (a==b1) exit(0);
X	if (a==b4) dumppanel();
X	if (a==b2) {
X	    b3->val=b2->val;
X	    b3->dirtycnt=2;
X	}
X	if (a==rb1) col=CYAN;
X	if (a==rb2) col=GREEN;
X	if (a==rb3) col=RED;
X
X	pushmatrix();
X	translate(posx, posy, 0.0);
X	color(BLACK);
X	clear();
X	color(col);
X	drawit();
X	swapbuffers();
X	popmatrix();
X    }
X}
X
X
Xdrawit()
X{
X    rectf(-.10,-.10,.10,.10);
X}
X
X
Xvoid
Xdeltapos(a)
XActuator *a;
X{
X    posx=savx+PNL_ACCESS(Puck, a, x);
X    posy=savy+PNL_ACCESS(Puck, a, y);
X}
X
Xvoid
Xbakepos(a)
XActuator *a;
X{
X    savx=posx;
X    savy=posy;
X}
X
XPanel
X*defpanel1()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel one";
X    panel->ppu=50.0;
X
X    s1=mkact(pnl_rubber_puck);
X    s1->label="position";
X    s1->x=4.0;
X    s1->y=0.0;
X    s1->minval= -1.0;
X    s1->maxval=1.0;
X    s1->activefunc=deltapos;
X    s1->upfunc=bakepos;
X    addact(s1, panel);
X
X    b2=mkact(pnl_toggle_button);
X    b2->label="push me";
X    b2->x=1.0;
X    b2->y=1.5;
X    addact(b2, panel);
X
X    b3=mkact(pnl_toggle_button);
X    b3->label="I push myself";
X    b3->x=1.0;
X    b3->y=2.0;
X    addact(b3, panel);
X
X    return panel;
X}
X
XPanel
X*defpanel2()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel two";
X    panel->ppu=50.0;
X
X    b4=mkact(pnl_button);
X    b4->label="dumppanel";
X    b4->x=1.0;
X    b4->y=1.5;
X    addact(b4, panel);
X
X    b1=mkact(pnl_button);
X    b1->label="exit";
X    b1->x=1.0;
X    b1->y=1.0;
X    addact(b1, panel);
X
X    return panel;
X}
X
XPanel
X*defpanel3()
X{
XPanel *panel;
X
X    panel=mkpanel();
X    panel->label="panel three";
X    panel->ppu=50.0;
X
X    rb3=mkact(pnl_radio_button);
X    rb3->label="red";
X    rb3->x=1.0;
X    rb3->y=2.0;
X    rb3->val=1.0;
X    addact(rb3, panel);
X
X    rb2=mkact(pnl_radio_button);
X    rb2->label="green";
X    rb2->x=1.0;
X    rb2->y=1.5;
X    addact(rb2, panel);
X
X    rb1=mkact(pnl_radio_button);
X    rb1->label="cyan";
X    rb1->x=1.0;
X    rb1->y=1.0;
X    addact(rb1, panel);
X
X    return panel;
X}
X
SHAR_EOF
chmod 0644 demo16.c || echo "restore of demo16.c fails"
sed 's/^X//' << 'SHAR_EOF' > demo17.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat at orville.nas.nasa.gov
X */
X#include <gl.h>
X#include "panel.h"
X
XActuator *poemwindow;
XPanel *defpanel();
X
X#define POEM_WINDOW_BUFSIZ  16386
X#define POEM \
X"Mary had a little spam.\n\
XIt felt as good as gold.\n\
XAnd when she left it out at night,\n\
XIt shivered in the cold."
X
X
Xmain() 
X{
X    foreground();
X    noport();
X    winopen("typeout demo");
X    winconstraints();
X    winconstraints();
X    doublebuffer();
X    gconfig();
X
X    defpanel();
X
X    for (;;) {
X        dopanel();
X	swapbuffers();
X    }
X}
X
Xvoid
Xcleanexit()
X{
X    exit(0);
X}
X
Xvoid
Xaddtext(a)
XActuator *a;
X{
X    strcat(PNL_ACCESS(Typeout, poemwindow, buf), "\n");
X    strcat(PNL_ACCESS(Typeout, poemwindow, buf),
X	   PNL_ACCESS(Typein, a, str));
X
X    fixact(poemwindow);
X}
X
XPanel
X*defpanel()
X{
XActuator *a;
XPanel *p;
X
X    p=mkpanel();
X    p->label="typeout demo";
X    p->x=200;
X    p->y=100;
X
X    a=mkact(pnl_wide_button);
X    a->x=1.5;
X    a->y= -2.0;
X    a->label="exit";
X    a->upfunc=cleanexit;
X    addact(a,p);
X
X    a=mkact(pnl_typein);
X    a->x=1.0;
X    a->y=0.0;
X    a->upfunc=addtext;
X    a->label="a typein actuator";
X    PNL_ACCESS(Typein,a,len)=60;
X    PNL_ACCESS(Typein,a,str)="Edit This String";
X
X    addact(a,p);
X
X    poemwindow=mkact(pnl_typeout);
X    poemwindow->x=1.0;
X    poemwindow->y=1.0;
X    poemwindow->labeltype=PNL_LABEL_TOP;
X    poemwindow->label="a typeout actuator";
X    PNL_ACCESS(Typeout,poemwindow,size)=POEM_WINDOW_BUFSIZ;
X    addact(poemwindow,p); /* addact does the malloc */
X    strcpy(PNL_ACCESS(Typeout,poemwindow,buf), POEM);
X    fixact(poemwindow);	    /* bake in the string */
X}
X
SHAR_EOF
chmod 0644 demo17.c || echo "restore of demo17.c fails"
sed 's/^X//' << 'SHAR_EOF' > demo18.c &&
X/*
X *	this software is in the public domain, it may not be resold
X *	or relicensed.  Do not remove this notice.  Send modifications
X *	and requests for most recent version to:
X *
X *	Author:  David A. Tristram
X *		 NASA  Ames Research Center
X *		 MS 258-5
X *		 Moffett Field, CA  94035
X *		 415-694-4404
X *		 dat at orville.nas.nasa.gov
X */
X#include <stdio.h>
X#include <gl.h>
X#include "panel.h"
X
XActuator *filewindow;
XPanel *defpanel();
X
X#define FILE_WINDOW_BUFSIZ  16386
X
Xmain() 
X{
X    foreground();
X    noport();
X    winopen("typeout demo");
X    winconstraints();
X    winconstraints();
X
X    doublebuffer();
X    gconfig();
X
X    defpanel();
X
X    for (;;) {
X        dopanel();
X	swapbuffers();
X    }
X}
X
Xvoid
Xcleanexit()
X{
X    exit(0);
X}
X
Xvoid
Xgetfile(a)
XActuator *a;
X{
XFILE *stream;
Xint n=0;
XTypein *adin=(Typein *)a->data;
XTypeout *adout=(Typeout *)filewindow->data;
Xchar *p=adout->buf;
X    
X    stream=fopen(adin->str, "r");
X    if (!stream) {
X	strcpy(adout->buf,"can't open file");
X	goto end;
X    }
X
X    do {
X	n=fread(p,sizeof(char),
X	    FILE_WINDOW_BUFSIZ-(p-adout->buf),stream);
X    	p+=n;
X    } while (n>0);
X    *p='\0';	/* mark the end */
X    fclose(stream);
X
Xend:
X    adout->start=0;
X    adout->dot=0;
X    fixact(filewindow);		    /* bake changes, mark dirty */
X}
X
XPanel
X*defpanel()
X{
XActuator *a;
XPanel *p;
X
X    p=mkpanel();
X    p->label="file viewer";
X    p->x=200;
X    p->y=100;
X
X    a=mkact(pnl_wide_button);
X    a->x=6.0;
X    a->y=0.0;
X    a->label="exit";
X    a->upfunc=cleanexit;
X    addact(a,p);
SHAR_EOF
echo "End of part 1, continue with part 2"
echo "2" > s2_seq_.tmp
exit 0



More information about the Comp.sys.sgi mailing list