Article View: comp.windows.news
Article #28Debuggind Mouse Tracking
From: Liam R. E. Quin
Date: Mon, 10 Aug 1992 23:28
Date: Mon, 10 Aug 1992 23:28
353 lines
7764 bytes
7764 bytes
I'm trying to debug a little NeWS program that does mouse tracking.
Unfortunately, when it goes wrong in the middle of hendling the /TrackStop
message, my mouse pointer stops working (I can move it, but clicks are
ineffective) and I have to restart the server.
Is there a way to get my clicks to work again?
For anyone feeling brave, I append the faulty NeWS code.
[Beware of my .signature on the end!]
Lee
#! /usr/openwin/bin/psh -i
%!PS
/NeWS 3 0 findpackage beginpackage
/TNTCore 3 0 findpackage beginpackage
/TNT 3 0 findpackage beginpackage
%% Random distributions
/MAX 0 def
/MIN 0 def
% min max random
/X currenttime 1 get 12 mul 211 div def
/theSeed X def
/random { % random number-between-0-and-1
% see Knuth _Art of Computer Programming_ vol 2 p. 156
/X 32573 X mul 6883 add cvi def
/X X 32768 mod def
X 32768 div % the result
} bind readonly def
/srand { /X exch def /theSeed X def } bind readonly def
/newrand {
currenttime srand
} bind readonly def
/randomBetween {
/MAX exch 1 add def
/MIN exch def
random MAX MIN sub mul MIN add cvi
} readonly def
/expRandomBetween {
/MAX exch 1 add def
/MIN exch def
/E 1 def
{ /E E random mul def } repeat E MAX MIN sub mul MIN add cvi
} readonly def
/nexty { 0 canvasHeight randomBetween} readonly def
/nextx { 0 canvasWidth randomBetween} readonly def
/Hex3DDict 12 dict def
/Hex3DInnerDict 12 dict def
/HexDWidth 20 def
/HexHWidth 30 def
/HexDHeight 30 def
/HexWidth HexDWidth 2 mul HexHWidth add def
/HexHeight HexDHeight 2 mul def
/MakeHex {
Hex3DDict begin
/p0y exch def
/p0x exch def
/p1x 20 p0x add def /p1y 30 p0y add def
/p2x 30 p1x add def /p2y p1y def
/p3x 20 p2x add def /p3y p0y def
/p4x p2x def /p4y p0y 30 sub def
/p5x p1x def /p5y p4y def
end
} bind def
% /FindHex { x y FindHex -> x y of p0
% 12 dict begin
% /y exch def
% /x exch def
% % find the least column
% /LeastCol x HexDWidth sub HexDWidth HexHWidth add dev cvi def
% % NOTDONE
% end
% } def
/Draw2DHex {
Hex3DDict begin
0 setlinewidth
newpath p0x p0y moveto
p1x p1y lineto
p2x p2y lineto
p3x p3y lineto
p4x p4y lineto
p5x p5y lineto
gsave
BG2 setcolor fill
grestore
end
} def
/Draw3DHex {
Hex3DDict begin
0 setlinewidth
newpath p0x p0y moveto
p1x p1y lineto
p2x p2y lineto
p3x p3y lineto
p4x p4y lineto
p5x p5y lineto
gsave
BG setcolor fill
grestore
gsave
clip
newpath
6 setlinewidth
p0x p0y moveto
p1x p1y lineto
p2x p2y lineto
BG0 setcolor stroke
p2x p2y moveto
p3x p3y lineto
p5x p5y moveto
p0x p0y lineto
BG2 setcolor stroke
p3x p3y moveto
p4x p4y lineto
p5x p5y lineto
BG3 setcolor stroke
grestore
% gsave
% 0 setlinewidth
% FG setcolor stroke
% grestore
end
} bind def
/DrawBoard { % width height DrawBoard -
6 dict begin
/BoardHeight exch def
/BoardWidth exch def
/x HexWidth 2 div neg def
/y HexHeight 2 div neg def
/Indent 0 def
0 HexDWidth HexHWidth add BoardWidth {
pop
/y Indent def
x HexDWidth HexHWidth add div cvi (col %d) sprintf () /setfooter window1 send
0 HexHeight BoardHeight {
pop
x y MakeHex
random 0.3 lt {
Draw2DHex
} {
Draw3DHex
} ifelse
/y y HexHeight add def
} for
/x x HexDWidth HexHWidth add add def
Indent 0 eq {
/Indent HexDHeight neg def
} {
/Indent 0 def
} ifelse
} for
end
} bind def
/HexCanvas ClassCanvas
dictbegin
/canvasWidth 800 def
/canvasHeight 800 def
%% Properties dialogue
% not done yet
dictend
classbegin
%% default window size
/preferredsize {
HexDWidth HexHWidth add 7 mul
HexDHeight 2 mul 6 mul
} def
/StepGingerly {
(Stepping Gingerly) pstack pop
2 copy
self setcanvas MakeHex Draw2DHex
/Palatino-Italic findfont 22 scalefont setfont
moveto (X) show
} readonly def
/TrackStart {
dup /E exch def begin
self setcanvas
XLocation YLocation (TrackStart at %d %d) sprintf () /setfooter window1 send
Name (LeftMouseButton) eq {
[/TrackMotion /TrackStop] true
} {
Name (NOTDONEMiddleMouseButton) eq {
% NOTDONE ShowObviousSpaces
% [/TrackMotion /TrackStop] true
false
} {
false
} ifelse
} ifelse
end
E /TrackStart super send
} def
/TrackMotion {
dup begin
XLocation YLocation (TrackMotion at %d %d) sprintf () /setfooter window1 send
end
/MotionTrack super send
} def
/TrackStop {
/z mark def
/E exch def
self setcanvas
E begin
XLocation YLocation (TrackStop at %d %d) sprintf () /setfooter window1 send
end
E /Name get (LeftMouseButton) eq {
E /Coordinates get aload pop
StepGingerly
} {
E /Name get (NOTDONEMiddleMouseButton) eq {
% NOTDONE ShowObviousSpaces
} {
} ifelse
} ifelse
E /TrackStop super send
z cleartomark
} def
/TrackCancel {
dup begin
XLocation YLocation (TrackCancel at %d %d) sprintf () /setfooter window1 send
end
/TrackCancel super send
} def
%% Input events (key presses):
/StandardKeyUp {
/E exch def
E /Name get {
12 18 { % control-L, control-R --> redraw
/PaintAll self send
}
17 81 113 { % ^Q, Q, q --> quit
currentprocess killprocess
}
32 { % space --> StepGingerly
E /XLocation get
E /YLocation get
% E /Coordinates get pstack aload pop
pstack
MakeHex Draw2DHex
}
/Default {
beep
}
} case
} def
/FunctionKeyUp {
/Name get /FunctionL3 eq {
% Props. I wish I got a "Properties" event instead, though
/showprops self send
} if
} def
/KeyStart { [ /StandardKeyUp /FunctionKeyUp ] true} def
/bad-path {
0 300 moveto % 0
200 300 rlineto % 1
500 0 rlineto % 2
900 0 moveto
-200 -300 rlineto
-500 0 rlineto
closepath
} def
%% Startup code:
/NewInit {
/NewInit super send
% Arrange to be allowed focus:
true setkeyable
true settrackable
} def
%% The hexes...
/Paint {
(Drawing...) ( ) /setfooter window1 send
/Busy /setvisualstate window1 send
gsave
clippath BG2 setcolor fill
grestore
% canvas size -- TNT 3.0 Ref. p. 49
canvasHeight canvasWidth DrawBoard
( ) ( ) /setfooter window1 send
/Active /setvisualstate window1 send
} def
classend def
/canvas1 framebuffer /new HexCanvas send def
/window1 canvas1 framebuffer /new ClassBaseWindow send def
(HexSweeper 1.0) /setlabel window1 send
{
/PaintIcon {
0 30 MakeHex Draw3DHex
} def
} window1 send
/new ClassEventMgr send dup /ProcessName (Hex) put
(hexsweeper.info:maincanvas) /sethelpkeyword canvas1 send
true /sethelpable canvas1 send
/activate window1 send
window1 /Retained true put
/place window1 send
/map window1 send
--
Liam Quin, lee@sq.com, SoftQuad, Toronto, 416 239-4801; the barefoot programmer
lq-text (Unix text retrieval pacakge) mailing list: lq-text-request@sq.com
latest released version: 1.10; ftp: ftp.cs.toronto.edu in directory: pub
If Adultery is for Adults, is Juvenal for Juveniles?
Technical Details
Message-ID:
<1992Aug10.232817.16351@sq.sq.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!wildcan!sq!leeShow Full Headers
Complete Article Headers
Newsgroups: comp.windows.news Path: arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!wildcan!sq!lee From: lee@sq.sq.com (Liam R. E. Quin) Subject: Debuggind Mouse Tracking Message-ID: <1992Aug10.232817.16351@sq.sq.com> Organization: SoftQuad Inc., Toronto, Canada X-Feet: bare Date: Mon, 10 Aug 92 23:28:17 GMT Lines: 353