NeWS interface help needed

Kenneth Josiah Harris kj at sgi.com
Tue Jun 5 07:43:35 AEST 1990


In article <9006012133.AA16991 at lri.uwo.ca> jd at lri.uwo.ca (J. Davis) writes:
>I am interested in writing an application program having a
>Sunview-like user interface (buttons, sliders, etc.). I found the 
>itemdemo postscript file which has all kinds of slick stuff, but my 
>problem is interfacing with my main C program. So far, the documentation
>found in the 4Sight programmer's guide has proven too sketchy to be of 
>much use to me. What I need is a pair of simple programs (.cps, .c)   
>which will show how to use PostScript to set up a window with, say, 
>a button, and pass the button value back to the calling C routine.
>Thanks for any help.



# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by kj on Mon Jun  4 14:42:24 PDT 1990
# Contents:  item.c item.cps makefile
 
echo x - item.c
sed 's/^@//' > "item.c" <<'@//E*O*F item.c//'
/* a simple items/cps program -- kj 1989 */

#include <psio.h>
#include "item.h"

#define	FORALL(i,n)	for(i=0;i<n;i++)
#define DEBUG(variable,type)	printf(" variable = %type",variable)

#define	DIM(x)	(sizeof(x)/sizeof(x[0]))

main()
{
	float value;

	if (ps_open_PostScript() == 0 ) {
		fprintf(stderr,"Cannot connect to NeWS server\n");
		exit(1);
	}
	ps_initialize();
	while (!psio_error(PostScriptInput)) {
		if (ps_notify(&value)) {
			DEBUG(value,f);
			printf("\n");
		} else if (psio_eof(PostScriptInput)) {
			break;
		} else {
			printf ("Strange stuff\n");
			break;
		}
	}
	ps_close_PostScript();
	printf ("bye\n");
}
@//E*O*F item.c//
chmod u=rw,g=r,o=r item.c
 
echo x - item.cps
sed 's/^@//' > "item.cps" <<'@//E*O*F item.cps//'
#define NOTIFY_TAG	69

cdef ps_initialize()

systemdict /Item known not { (NeWS/liteitem.ps) run } if

/win {
    /FrameLabel (Item Test) def
    /PaintClient {items paintitems} def
} makewindowfromuser def
/can win /ClientCanvas get def

/notify { % def
	NOTIFY_TAG tagprint ItemValue typedprint
} def

/items 50 dict dup begin
	/message
		(Message:) (yo!) /Right {} can 500 0 /new MessageItem send
		10 10 /move
		3 index send
	def
	/button
		(Button) /notify can 0 0 /new ButtonItem send
        	10 50 /move
		3 index send
	def
	/text
		(Text:) (Godzilla) /Right /notify can 220 0
		/new TextItem send
		20 150 /move
		3 index send
	def
	/slider
		(Slider:) [-10 +10 0] /Right /notify can 220 20
    		/new SliderItem send
		20 110 /move
		3 index send
	def
	/cycle
		(Cycle:)
		[
			(Look! I can have icons..)
			/panel_text
			(..and drawings..)
			/yosemite
			(..in cycles!)
		] /Right /notify can 0 0 /new CycleItem send
		100 50 /move
		3 index send
	def
	/array
		(Array)
		[
			[(One) (Two) /panel_text]
			[(Four) /rat (Six)]
		]
		/Bottom /notify can 0 0
		/new ArrayItem send
		300 50 /move
		3 index send
	def
end def

/p items forkitems def

cdef ps_notify(float value) => NOTIFY_TAG(value)
@//E*O*F item.cps//
chmod u=rw,g=r,o=r item.cps
 
echo x - makefile
sed 's/^@//' > "makefile" <<'@//E*O*F makefile//'
CFLAGS = -G 0
LDFLAGS = -lcps -lbsd -lc_s

item:	item.h item.c
	$(CC) $(CFLAGS) $@.c $(LDFLAGS) -o $@

item.h: item.cps
	cps item.cps

clean:
	rm item.h item
@//E*O*F makefile//
chmod u=rw,g=r,o=r makefile
 
exit 0
--
Ken J. Harris -- kj at sgi.com or {decwrl,pyramid,ucbvax}!sgi!kj



More information about the Comp.sys.sgi mailing list