-
Notifications
You must be signed in to change notification settings - Fork 2
/
INTRFACE.SC
1445 lines (1156 loc) · 26.2 KB
/
INTRFACE.SC
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;;;
;;;; INTRFACE.SC
;;;; (c) Sierra On-Line, Inc, 1988
;;;;
;;;; Author: Bob Heitman
;;;;
;;;; Classes which implement the user interface of SCI.
;;;;
;;;; Classes:
;;;; MenuBar
;;;; Dialog
;;;; Item
;;;; DItem
;;;; DText
;;;; DIcon
;;;; DButton
;;;; DEdit
;;;; DSelector
;;;; Controls
;;;;
;;;; Procedures:
;;;; Print
;;;; ShowView
;;;; GetInput
;;;; GetNumber
;;;; Printf
;;;; StillDown
(script# INTRFACE)
(procedure
Print
ShowView
GetInput
GetNumber
Printf
StillDown
MousedOn
)
(public
Print 0
ShowView 1
GetInput 2
GetNumber 3
Printf 4
MousedOn 5
)
(procedure (StillDown &tmp event ret)
;;; Return true if there is no mouse up in queue.
(= event (Event new:))
(= ret (!= (event type?) mouseUp))
(event dispose:)
(return ret)
)
(procedure (MousedOn obj event theMods distance)
(return
(cond
((or
(!= (event type) mouseDown)
(and
(obj respondsTo:#signal)
(& (obj signal?) actorHidden)
)
)
FALSE
)
((and
(>= argc 3)
theMods
(== (& (event modifiers) theMods) 0)
)
FALSE
)
((obj respondsTo:#nsLeft)
(InRect
(obj nsLeft?) (obj nsTop?) (obj nsRight?) (obj nsBottom?)
event
)
)
; ((obj respondsTo:#x)
; (<=
; (GetDistance
; (event x?)
; (event y?)
; (obj x?)
; (- (obj y?) (obj z?)) ;apparent y-coordinate
; )
; (if (>= argc 4) distance else 10)
; )
; )
)
)
)
(class MenuBar kindof Object
;;; The menubar is a two dimensional array maintained solely by the kernel.
;;; This class, along with some explicit kernel calls, implements an
;;; interface to the kernel menubar.
(properties
name 0 ;we don't want to waste storage on this object's name
state 0 ;is the menu bar enabled?
)
(methods
draw ;draw the menubar
hide ;hide the menubar
handleEvent ;send an Event to the menubar
add ;add a menu to the menubar
)
(method (draw)
;; Draw the menubar as it currently exists.
(= state TRUE)
(DrawMenuBar TRUE)
)
(method (hide)
;; Hide the area of the menu.
(DrawMenuBar FALSE)
)
(method (add)
;; Add a menu to menu bar.
(AddMenu &rest)
)
(method (handleEvent event &tmp retVal oldRepeat)
;; Respond to user events (if enabled).
(= retVal 0)
(if state
(= oldRepeat (Joystick JoyRepeat 30))
(= retVal (MenuSelect event &rest))
(Joystick JoyRepeat oldRepeat)
)
(return retVal)
)
)
(class DItem kindof Object
;;; The superclass of all items of control in the user interface.
(properties
name 0 ; don't waste storage on a name string
type 0 ; the type of this control
state 0 ; defined by each subclass
nsTop 0 ; visible rectangle
nsLeft 0 ; in LOCAL coords
nsBottom 0 ; used to select
nsRight 0 ; control via a mouse click
key 0 ; key code associated with control
said 0 ; said spec associated with control
value 0 ; for programmers use
)
(methods
enable ; set/reset active bit in state
select ; set/reset selected bit in state
handleEvent ; determine if user input is yours
check ; check event x/y in rectangle
track ; select confirmation
doit ; instantiated for each subclass/control
setSize ; instantiated in each type of item
move ; relative move
moveTo ; absolute move
draw ; draw self in proper manner
setMark ; set default marking
isType ; return equality of type and argument
checkState ; do a bit test of argument
cycle ; do something cyclic
)
(method (enable bool)
;; Enable/disable this control.
(if bool
(|= state dActive)
else
(&= state (~ dActive))
)
)
(method (select bool)
;; Select/deselect this control.
(if bool
(|= state dSelected)
else
(&= state (~ dSelected))
)
(self draw:)
)
(method (handleEvent event &tmp ret evtType evt)
;; Return ID if this event is yours, else 0.
(if (event claimed?) (return 0))
; default to not selected
(= ret 0)
(if (& state dActive)
; slight speed up effort
(= evtType (event type?))
(if
(or
; said your name
(and (== evtType saidEvent) (Said said))
; pressed your key
(and (== evtType keyDown) (== (event message?) key))
; clicked in box
(and (== evtType mouseDown) (self check: event))
)
; this was us
(event claimed: TRUE)
(= ret (self track: event))
)
)
; return the result of our tests
(return ret)
)
(method (check event)
;; Return true if x/y/ in your rectangle.
(return
(and
(>= (event x?) nsLeft)
(>= (event y?) nsTop)
(< (event x?) nsRight)
(< (event y?) nsBottom)
)
)
)
(method (track event &tmp in lastIn)
;; Track control to confirm selection.
;; NOTE: Only a mouseDown requires a mouse track.
(if (== mouseDown (event type?))
(= lastIn 0)
(repeat
(= event (Event new: leaveIt))
(GlobalToLocal event)
(= in (self check: event))
(if (!= in lastIn)
(HiliteControl self)
(= lastIn in)
)
(event dispose:)
(breakif (not (StillDown)))
)
(if in
(HiliteControl self)
)
(return in)
else
(return self)
)
)
(method (isType theType)
;; Return TRUE if this DItem is of type theType.
(return (== type theType))
)
(method (checkState bit)
(return (& state bit))
)
(method (doit)
;; Default method is to return value.
;; Will be superceded by user's instances.
(return value)
)
(method (setSize)
;; Set the item's rectangle. Responsibility of subclasses.
)
(method (move h v)
;; Move item BY h v.
(+= nsRight h)
(+= nsLeft h)
(+= nsTop v)
(+= nsBottom v)
)
(method (moveTo h v)
;; Move item TO h v.
(self move: (- h nsLeft) (- v nsTop))
)
(method (draw)
;; Draw self per kernel definition.
(DrawControl self)
)
; do something on each cycle through the dialog's doit
(method (cycle)
)
)
(class DText kindof DItem
;;; A non-editable, generally non-selectable text field.
(properties
type:dText
text:0 ;the text in the field
font:USERFONT ;font to use for print text
mode:teJustLeft ;possible alignment of text
; teJustLeft left justified
; teJustRight right justified
; teJustCenter center each line
)
(method (new &tmp newText)
(return ((super new:) font: userFont, yourself:))
)
(method (setSize w &tmp [r 4])
;; If w arg is present it is the fixed width of the text rectangle.
(TextSize @[r 0] text font (if argc w else 0))
(= nsBottom (+ nsTop [r 2]))
(= nsRight (+ nsLeft [r 3]))
)
)
(class DIcon kindof DItem
;;; Icons are simply a view/loop/cel combination created by the view
;;; editor VE. They are generally not selectable.
(properties
type:dIcon
view:0 ; view number
loop:0 ; loop number
cel:0 ; cel number
)
(method (setSize &tmp [r 4])
(= nsRight (+ nsLeft (CelWide view loop cel)))
(= nsBottom (+ nsTop (CelHigh view loop cel)))
)
)
(class DButton kindof DItem
;;; Buttons are selectable items which a user clicks in with the mouse
;;; or selects with the TAB key and ENTER in order to execute an action.
(properties
type:dButton
state: (| dActive dExit)
text:0 ;text displayed inside button
font:SYSFONT ;should usally be left as the system font
)
(method (setSize &tmp [r 4])
(define BMOD 16) ; width equalizer for buttons
(TextSize @[r 0] text font)
; a button box is one pixel larger all around
(+= [r 2] 2)
(+= [r 3] 2)
(= nsBottom (+ nsTop [r 2]))
(= [r 3] (* (/ (+ [r 3] (- BMOD 1)) BMOD) BMOD))
(= nsRight (+ [r 3] nsLeft))
)
)
(class DEdit kindof DItem
;;; A text field which is editable by the user.
(properties
type:dEdit
state: dActive
text:0 ;default text when the edit item is drawn
font:SYSFONT ;this is often changed to a user font
max:0 ;maximum number of characters allowed in field
cursor:0 ;cursor position in field
)
(method (track evt)
(EditControl self evt)
(return self) ;used to return 0, see Corey
)
(method (setSize &tmp [r 4])
;; Size and set cursor position to the end of the text.
; box is as sized by max * width of an "M"
(TextSize @[r 0] {M} font)
(= nsBottom (+ nsTop [r 2]))
(= nsRight (+ nsLeft (/ (* [r 3] max 3) 4)))
(= cursor (StrLen text))
)
)
(class DSelector kindof DItem
;;; Selectors are a list of text items which can be scrolled. The user
;;; selects one of the items either by clicking directly on the item
;;; or by scrolling a high-lighted bar to the selection.
(properties
type dSelector
state 0
font 0
x 20 ; width of text item (in characters)
y 6 ; number of items displayed in selector
text 0 ; the text items to be selected from
cursor 0 ; the currently selected item
lsTop 0 ; first line of text shown
mark 0 ; the LINE of selector that is selected
)
(methods
indexOf ; return index of this string
at ; return ptr to this index
advance ; move selector bar up
retreat ; move selector bar up
)
(method (indexOf what &tmp ptr i)
;; Return index of this string OR -1.
(= ptr text)
(for ((= i 0)) (< i 300) ((++ i))
; check for end of data
(if (== 0 (StrLen ptr))
(return -1)
)
(if (not (StrCmp what ptr))
(return i)
)
(+= ptr x)
)
)
(method (at what)
;; Return pointer to this index OR 0.
(return (+ text (* x what)))
)
(method (setSize &tmp [r 4])
(TextSize @[r 0] {M} font)
(= nsBottom (+ nsTop 20 (* [r 2] y)))
(= nsRight (+ nsLeft (/ (* [r 3] x 3) 4)))
(= lsTop (= cursor text))
(= mark 0)
)
(method (retreat lines &tmp redraw)
;; Retreat requested (or to top) lines.
(= redraw FALSE)
(while lines
; are we at top?
(if (!= cursor text)
(= redraw TRUE)
(-= cursor x)
; do we scroll up?
(if mark
(-- mark)
else
(-= lsTop x)
)
(-- lines)
else
(break)
)
)
(if redraw
(self draw:)
)
)
(method (advance lines &tmp redraw)
;; Advance requested (or to end) lines.
(= redraw FALSE)
(while lines
; is there another line?
(if (StrAt cursor x)
(= redraw TRUE)
(+= cursor x)
; do we scroll?
(if (< (+ mark 1) y)
(++ mark)
else
(+= lsTop x)
)
(-- lines)
else
(break)
)
)
(if redraw
(self draw:)
)
)
(method (handleEvent event &tmp ret evtType evt newEvt i [r 4])
;; Selectors are not really active so they always return 0,
;; but they may claim the event.
(if (event claimed?) (return 0))
; remap some directions into arrows
(if (== direction (event type?))
(event type:keyDown)
(switch (event message?)
(dirS
(event message:DOWNARROW)
)
(dirN
(event message:UPARROW)
)
(else
(event type:direction)
)
)
)
(= ret 0)
(switch (event type?)
(keyDown
(event claimed:TRUE)
(switch (event message?)
(HOMEKEY
(self retreat: 50)
)
(ENDKEY
(self advance: 50)
)
(PAGEDOWN
(self advance: (- y 1))
)
(PAGEUP
(self retreat: (- y 1))
)
(DOWNARROW
(self advance: 1)
)
(UPARROW
(self retreat: 1)
)
(else
(event claimed:FALSE)
)
)
)
(mouseDown
(if (self check: event)
(event claimed:TRUE)
; determine sub part
(cond
; top bar
((< (event y?) (+ nsTop 10))
(repeat
(self retreat: 1)
(breakif (not (StillDown)))
)
)
; bottom bar
((> (event y?) (- nsBottom 10))
(repeat
(self advance: 1)
(breakif (not (StillDown)))
)
)
; it is in the center
(else
; determine line height
(TextSize @[r 0] {M} font)
(= i (/ (- (event y?) (+ nsTop 10)) [r 2]))
(if (> i mark)
; need to advance
(self advance: (- i mark))
else
; need to retreat
(self retreat: (- mark i))
)
)
)
)
)
)
(return (if (and (event claimed?) (& state dExit)) self else 0))
)
)
(class Dialog kindof List
;;; ACTIVE controls can be selected, INACTIVE ones can't.
;;; EXIT controls return ID when selected. NON-EXIT controls invoke DOIT.
;;; All controls will show VISUAL evidence of selection.
;;; Selection via a mouse click requires a track.
(properties
text 0 ; title
elements 0 ; list of items
window 0 ; pointer to open window
theItem 0 ; objID of "current" item
nsTop 0
nsLeft 0
nsBottom 0
nsRight 0
time 0
busy 0 ; timer dispose lockout
;; properties below allow us to do without timers. --Pablo
seconds 0 ;the number of seconds to wait before changing state
lastSeconds 0 ;private variable
)
(methods
new ; get one of me
open ; get a window to live in
draw ; actually show on screen
doit ; get user input to me
cue ; respond to time expiration
dispose ; close dialog
advance ; advance to next in list
retreat ; retreat to previous in list
move ; relative move from current position
moveTo ; go to absolute position (upper/left)
center ; center in screen
setSize ; make me big enough
handleEvent ; respond to an event
check ; cue if time is up
)
(method (open wtype pri)
;; Get a new window for this dialog.
(if (and (PicNotValid) cast)
(Animate (cast elements?) FALSE)
)
; operate with a clone of provided window
(= window (window new:))
(window
top: nsTop,
left:nsLeft,
bottom: nsBottom,
right: nsRight,
title: text,
type: wtype,
priority: pri,
open:,
)
(= seconds time)
;;(if time
;; (Timer setReal: self time)
;;)
; draw the items
(self draw:)
)
(method (draw)
;;; Draw contents of dialog.
(self eachElementDo: #draw:)
)
(method (doit def &tmp done event ret eatMice lastTick)
;; Do this dialog with default obj for RETURN.
;; If there are NO active items then ANY event exits.
;; Pressing ESC returns 0.
;; Only ACTIVE items may be SELECTED.
;; Only EXIT items are reported to caller.
;; Pressing ENTER returns the currently SELECTED object IF it is EXIT.
;; Pressing TAB advances to next ACTIVE item.
;; Pressing SHIFT/TAB advances to previous ACTIVE item.
(= done 0)
; tell the timer we are busy
(= busy 1)
(self eachElementDo: #init:)
; if def is not passed or zero, we pick first active item
; unmark last default
(if theItem
(theItem select:FALSE)
)
(= theItem
(if (and argc def)
def
else
(self firstTrue: #checkState: dActive)
)
)
; mark this item (if not NULL)
(if theItem
(theItem select:TRUE)
)
; if no active items we eat mouseDown for a one half second
(if (not theItem)
(= eatMice 60)
(= lastTick (GetTime))
else
(= eatMice 0)
)
; get events and act upon them
( = ret 0)
(while (not ret)
; call everyones cycler
(self eachElementDo: #cycle:)
; get an event and give everyone a shot at it
(GlobalToLocal (= event (Event new:)))
(if eatMice
(-- eatMice)
(if (== (event type?) mouseDown)
(event type:0)
)
(while (== lastTick (GetTime))
(continue)
)
(= lastTick (GetTime))
)
(= ret (self handleEvent: event))
; get rid of the event we got
(event dispose:)
(self check:) ;see if our time is up, if so dispose (maybe)
; this is ESC or INACTIVE or TIMER said get unbusy
(if (or (== ret -1) (not busy))
(= ret 0)
(EditControl theItem 0)
(break)
)
(Wait 1)
)
; tell the timer we can be killed
(= busy 0)
(return ret)
)
(method (check &tmp thisSeconds)
;;following code replaces timer
;;invoked from dialog doit for normal dialogs
;;or from game doit for modelessDialogs
;;--Pablo
(if seconds
(= thisSeconds (GetTime 1))
(if (!= lastSeconds thisSeconds)
(= lastSeconds thisSeconds)
(if (not (-- seconds))
(self cue:)
)
)
)
)
(method (cue)
(if (not busy)
(self dispose:)
else
(= busy 0)
)
)
(method (dispose)
;; Dispose of dialog and its window.
;; set system global to zero if it is us
(if (== self modelessDialog)
(SetPort modelessPort)
(= modelessDialog 0)
(= modelessPort 0)
)
(if window
(window dispose:)
)
(= window 0)
;; dispose of any timer we might have
;;(if timer
;; (timer dispose:, delete:)
;;)
;; clear the currently selected item
(= theItem 0)
(super dispose:)
)
(method (advance &tmp obj node)
;; Private. Move to next ACTIVE item in list.
(if theItem
;; clear this one
(theItem select: FALSE)
;; we need the node value that we are
(= node (self contains: theItem))
(repeat
(if (not (= node (self next: node)))
(= node (self first:))
)
(= theItem (NodeValue node))
; we break on next active item
(if (& (theItem state?) dActive)
(break)
)
)
(theItem select: TRUE)
)
)
(method (retreat &tmp obj node)
;; Private. Move back one ACTIVE item.
(if theItem
; clear this one
(theItem select: FALSE)
; we need the node value that we are
(= node (self contains: theItem))
(repeat
(if (not (= node (self prev: node)))
(= node (self last:))
)
(= theItem (NodeValue node))
; we break on next active item
(if (& (theItem state?) dActive)
(break)
)
)
(theItem select: TRUE)
)
)
(method (handleEvent event &tmp ret)
;; Respond to the passed event with ID or null.
; is it unclaimed or NOT mine?
(if
(or
(event claimed?)
(== (event type?) nullEvt)
(and
(!= mouseDown (event type?))
(!= keyDown (event type?))
(!= direction (event type?))
(!= joyDown (event type?))
)
)
(EditControl theItem event)
(return 0)
)
; does this event belong to any in the list
(if (= ret (self firstTrue: #handleEvent: event))
(EditControl theItem 0)
; If NOT marked EXIT we doit: and advance to next
(if (not (ret checkState: dExit))
(if theItem
(theItem select:FALSE)
)
((= theItem ret) select:TRUE)
; Send "doit" to object to perform any subclass-specific stuff
(ret doit:)
; don't report it
(= ret 0)
)
else
; check standard conventions
(= ret 0)
(cond
; return KEY pressed and theItem is active
((and
(or
(== (event type?) joyDown)
(and
(== keyDown (event type?))
(== ENTER (event message?))
)
)
theItem
(theItem checkState: dActive)
)
(= ret theItem)
(EditControl theItem 0)
(event claimed:TRUE)
)
; ESC or any key or click exits if no active items
((or
(and