File: calctool.ps

package info (click to toggle)
calctool 2.4.9-10
  • links: PTS
  • area: non-free
  • in suites: hamm, slink
  • size: 432 kB
  • ctags: 1,165
  • sloc: ansic: 5,130; makefile: 613; sh: 22
file content (271 lines) | stat: -rw-r--r-- 6,058 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

%  These are the NeWS dependent graphics routines used by calctool.
%  They make use of the tnt toolkit distributed with OpenWindows.
%
%  Copyright (c) Rich Burridge - Sun Microsystems, Australia.
%                                All rights reserved.
%
%  @(#)calctool.ps 1.5 89/12/21
%
%  Permission is given to distribute these sources, as long as the
%  copyright messages are not removed, and no monies are exchanged.
%
%  No responsibility is taken for any errors or inaccuracies inherent
%  either to the comments or the code of this program, but if
%  reported to me then an attempt will be made to fix them.
%

%  Define a class for the main calctool window. The following events
%  are handled:
%
%  Left mouse button (down and up).
%  Middle mouse button (down and up).
%  Right mouse button (down and up).
%  Keyboard press.
%  Window damage.
%
%  For each of these events, an appropriate tag is sent back to the C code.

/KeyClass ClassCanvas []
classbegin
  /PaintCanvas
  {
    CFRAME_REPAINT typedprint
  } def

  /MakeInterests
  {
    /MakeInterests super send
    LeftMouseButton   {LEFT_DOWN SendEvent}   /DownTransition self MakeInterest
    MiddleMouseButton {MIDDLE_DOWN SendEvent} /DownTransition self MakeInterest
    LeftMouseButton   {LEFT_UP SendEvent}     /UpTransition   self MakeInterest
    MiddleMouseButton {MIDDLE_UP SendEvent}   /UpTransition   self MakeInterest
    {KbdEvent} Canvas /defaultkeys ClassKeysInterest send
  } def
classend def


%  Define a class for the memory register window.
%  Handle window damage in the same way as the main calctool window.

/RegClass ClassCanvas []
classbegin
  /PaintCanvas
  {
    RFRAME_REPAINT typedprint
  } def
classend def


%  Clear the whole of either the main calctool canvas or the memory
%  register canvas to a specific color.

/PSClearCanvas      % color canvas => -
{
  dup setcanvas
  ColorTable 3 -1 roll get
  /fillcanvas 3 -1 roll send
} def


%  Close the main calctool window and unmap the memory register window.

/PSCloseFrame      % - => -
{
  /flipiconic KFrame send
  /unmap RFrame send
} def


%  Color a rectangular area in the main calctool window.

/PSColorArea    % color x width height y => -
{
  KC setcanvas
  KCHeight exch sub exch dup 3 1 roll sub 3 1 roll rectpath
  ColorTable exch get setcolor
  fill
} def


%  Draw a line in the main calctool window.

/PSDrawLine           % x1 x2 y1 y2 => -
{
  KCHeight exch sub
  exch KCHeight exch sub 3 1 roll
  KC setcanvas
  newpath
    moveto lineto
    0 setgray
  stroke
} def


%  Draw (map) the memory register window.

/PSDrawRegs
{
  /map RFrame send
} def


%  Load the small, normal and bold fonts used by calctool.

/PSInitFonts     % - => -
{
  /SFont /Courier findfont 10 scalefont def
  /NFont /Courier-Bold findfont 14 scalefont def
  /BFont /Courier-Bold findfont 18 scalefont def
} def


%  Set up the various tags that are passed back to the C code.
%  Note that at present, some of these tags are not used.

/PSInitialise   % - => -
{
  /CFRAME_REPAINT  100 def
  /RFRAME_REPAINT  101 def
  /ENTER_WINDOW    102 def
  /EXIT_WINDOW     103 def
  /KEYBOARD        104 def
  /LEFT_DOWN       105 def
  /LEFT_UP         106 def
  /MIDDLE_DOWN     107 def
  /MIDDLE_UP       108 def
  /RIGHT_DOWN      109 def
  /RIGHT_UP        110 def
  /TAKE_FROM_SHELF 111 def
  /PUT_ON_SHELF    112 def
} def


%  Test if calctool is running on a color framebuffer.

/PSIsColor      % - => iscolorscreen
{
  /Color? framebuffer /Color get def
  Color? {1} {0} ifelse typedprint
} def


%  Load a red green blue triplet into the appropriate entry in the colortable.

/PSLoadColor       % index blue green red => -
{
  255 div
  exch 255 div
  3 -1 roll 255 div
  rgbcolor
  ColorTable 3 1 roll put
} def


%  Create an array big enough for all the colors used by calctool.

/PSMakeColorTable  % size => -
{
  /ColorTable exch array def
} def


/KbdEvent
{
  begin
    Action /DownTransition eq
      {
        KEYBOARD typedprint Name SendEvent
      } if
  end
} def


/SendEvent
{
  KC setcanvas
  typedprint
  currentcursorlocation KCHeight exch sub exch
  typedprint typedprint
} def


/PaintIcon 
{
  clippath pathbbox
  scale pop pop
  0 setgray
  false calctoolIcon imagemaskcanvas
} def

 
%  Create the main calctool frame and the memory registers property sheet.
%  Set the size of these items, and place the open frame and icon at the
%  correct place.

/PSMakeFrames      % wx wy width height ix iy iconic => -
{
  [ /IsIcon /IconY /IconX /KCHeight /KCWidth /KCY /KCX ]
  { exch def } forall

%  /ScreenHeight /size framebuffer send exch def pop
  /ScreenHeight 900 def

  /KFrame [KeyClass] [/Footer false /Label false]
    framebuffer /new OpenLookBaseFrame send def
  /KC /client KFrame send def
  KCWidth KCHeight /lockminsize KC send 
  calctoolIcon /seticon KFrame send
%  IconX
%  ScreenHeight FrameHeight sub IconY sub
%  42 64 /reshape /Icon /sendsubframe KFrame send

  /preferredsize KFrame send /FrameHeight exch def
                             /FrameWidth  exch def

  KCX
  ScreenHeight FrameHeight sub KCY sub
  FrameWidth FrameHeight /reshape KFrame send

  /RFrame [RegClass] framebuffer /new OpenLookPropertyFrame send def
  /RC /client RFrame send def 
  /RCHeight 200 def
  KCWidth RCHeight /lockminsize RC send

  /activate KFrame send

% /map IsIcon 1 eq {/Icon /subframes KFrame send get} {KFrame} ifelse send
% IsIcon 1 eq {/close KFrame send} if

  /map KFrame send

  /activate RFrame send
  /place RFrame send
} def


%  Place a colored text string in the appropriate font at the given
%  x,y position in either the main calctool window or the memory
%  register window.

/PSMakeText    % string x canvasheight y font color canvas => -
{
  setcanvas
  ColorTable exch get setcolor
  setfont
  sub moveto show
} def


/PSSetCursor   % type => -
{
} def


%  Depending upon the current setting, either show (map) or remove
%  (unmap) the memory register window.

/PSToggleRegCanvas   % state => -
{
  1 eq { /map RFrame send} { /unmap RFrame send} ifelse
} def