Path: utzoo!attcan!uunet!samsung!brutus.cs.uiuc.edu!rpi!netserv2!deven From: deven@rpi.edu (Deven T. Corzine) Newsgroups: comp.windows.news Subject: Re: Need a quick hack... Message-ID: Date: 26 Nov 89 22:09:20 GMT References: <1989Nov18.223114.4523@world.std.com> Organization: Rensselaer Polytechnic Institute, Troy, NY Lines: 152 In-Reply-To: bzs@world.std.com's message of 18 Nov 89 22:31:14 GMT On 18 Nov 89 22:31:14 GMT, bzs@world.std.com (Barry Shein) said: bzs> The program I need is very simple: Simple enough. bzs> create a window, put "Hello World" into it (reasonably centered), bzs> on mouse-down (any button, or a particular button, doesn't bzs> matter) the text changes to "Goodbye World" (clear and redraw bzs> text is fine), when the button is released the program exits. The following NeWS PostScript program will do exactly that, using the left mouse button for activation. bzs> It shouldn't use any toolkits or tools, just straight, hand-coded bzs> NeWS/Postscript. That's what this is, based on popmsg in init.ps, modified and simplified, and I also commented it. bzs> Short and exemplary is much better than, oh, dealing with detail bzs> issues of color screens (you can assume mono if it makes it bzs> simpler) or whatever. Its only purpose is to say "here's what a bzs> very simple program that actually does some input/output looks bzs> like in each system". In this case, color's only a couple more lines. (but I can't test it) bzs> Thanks. Welcome. Run through psh to execute: (remove through this line, and remove the .signature.) { % start procedure block for process % fork (execution does not yet begin) 20 dict begin % create new dictionary for local use newprocessgroup % start new process group /hello (Hello, world!) def % define "Hello, world!" string /goodbye (Goodbye, world!) % "Goodbye, world!" string def % define framebuffer setcanvas % set current canvas to full screen clippath pathbbox % returns screen position and size 2 div /y exch def % use half screen-height as y position 2 div /x exch def % use half screen-width as x position pop pop % toss screen "position" /Times-Roman findfont % find Times-Roman font 24 scalefont % scale to 24 points setfont % set as current font 0 setgray % set current color to black /width % going to define variable "width" /hellowidth % going to define variable "hellowidth" hello stringwidth pop % get width of "hello" string % (stringwidth returns y "width" also % -- y offset after showing string; % that is, zero.) def % define hellowidth /goodbyewidth % going to define variable "goodbyewidth" goodbye stringwidth pop % get width of "goodbye" string also def % define goodbyewidth hellowidth goodbyewidth % retrieve both values max def % define "width" to be the max of them /height 30 def % height of text is 30 (24 points plus % some whitespace) /y y height 2 div add % adjust y by height of text 25 sub def % and space for border /xcenter x def % save original (center) value of x /x x width 2 div sub def % adjust x by width of hello text /x0 x 10 sub def % find x coordinate of upper-left-hand % corner of enclosing rectangle /y0 y 25 add def % find y coordinate of upper-left-hand % corner of enclosing rectangle /x1 x0 width add 20 add def % x coordinate of lower-right-hand % corner of enclosing rectangle /y1 y0 height 5 add sub def % y coordinate of lower-right-hand % corner of enclosing rectangle x0 y0 10 sub moveto % move to upper-left-hand corner x0 y1 x1 y1 10 arcto % draw left edge and lower-left corner x1 y1 x1 y0 10 arcto % draw lower edge and lower-right % corner x1 y0 x0 y0 10 arcto % draw right edge and upper-right % corner x0 y0 x0 y1 10 arcto % draw top edge and upper-left corner closepath % close off the path /canvas % going to define variable "canvas" framebuffer newcanvas def % create a new canvas as child of % framebuffer (root canvas) and define canvas reshapecanvas % define the shape of the canvas canvas setcanvas % set current canvas canvas /SaveBehind true put % save screen behind the canvas canvas /Mapped true put % make canvas visible clippath 0 setgray fill % fill canvas with black /x0 x0 2 add def % adjust coordinates of corners /y0 y0 2 sub def /x1 x1 2 sub def /y1 y1 2 add def x0 y0 10 sub moveto % redraw (create new path) rounded x0 y1 x1 y1 10 arcto % rectangle (slightly smaller) x1 y1 x1 y0 10 arcto x1 y0 x0 y0 10 arcto x0 y0 x0 y1 10 arcto clear % dump anything left on stack gsave % save graphics state 1 setgray fill % fill canvas (within clipping path) % with white ColorDisplay? % true if display is color { 1 .5 .5 sethsbcolor } % if so, set color { 0 setgray } ifelse % otherwise, set black xcenter hellowidth 2 div sub % get x coordinate of text starting % position y moveto % push y and move to starting position hello show % show hello string damagepath newpath % clear damagepath createevent begin % create a new input event and push % onto dictionary stack /Canvas currentcanvas def % define canvas for input event /Name /LeftMouseButton % Want to watch for left mouse button def % define currentdict % put current dictionary (the newly % created input event) on stack end % pop dictionary stack expressinterest % express interest in that event type awaitevent % wait for such an event grestore % restore saved graphics state 1 setgray fill % clear the "window" ColorDisplay? % true if display is color { 1 .5 .5 sethsbcolor } % if so, set color { 0 setgray } ifelse % otherwise, set black xcenter goodbyewidth 2 div % get x coordinate of text starting sub % position y moveto % push y and move to text starting % position goodbye show % show goodbye text awaitevent % wait for another left mouse button % event canvas /Mapped false put % unmap canvas (makes the "window" % disappear) end % pop dictionary stack } % end definition of procedure block fork % start just-defined procedure as a % seperate process in NeWS server pause % explicitly give other NeWS processes % a chance to run Deven -- Deven T. Corzine Internet: deven@rpi.edu, shadow@pawl.rpi.edu Snail: 2151 12th St. Apt. 4, Troy, NY 12180 Phone: (518) 274-0327 Bitnet: deven@rpitsmts, userfxb6@rpitsmts UUCP: uunet!rpi!deven Simple things should be simple and complex things should be possible.