forked from dbmcclain/vmath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretro.lisp
More file actions
1909 lines (1647 loc) · 58.5 KB
/
retro.lisp
File metadata and controls
1909 lines (1647 loc) · 58.5 KB
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
;; -------------------------------------------------------------
;; Higher Level (more abstract) Retro Gear Interface
(in-package "USER")
(eval-when (:compile-toplevel :load-toplevel :execute)
(fli:define-foreign-function (%read-nonmasked-bitmap
"lpReadNonmaskedBM")
((fname :pointer))
:result-type (:pointer :void)
:module sg::*plotter-dll*
:calling-convention :cdecl)
(defun read-nonmasked-bitmap (fname)
(fli:with-foreign-string (fstr len blen) fname
(declare (ignore len blen))
(%read-nonmasked-bitmap fstr)))
(fli:define-foreign-function (%read-masked-bitmap
"lpReadMaskedBM")
((fname :pointer)
(trans :int))
:result-type (:pointer :void)
:module sg::*plotter-dll*
:calling-convention :cdecl)
(defun rgb-quad (red green blue)
(+ (ash blue 16)
(ash green 8)
red))
(defun read-masked-bitmap (fname trans)
;; fname should be the ASCII string filename for the bitmap
;; and trans should be an RGBQUAD color for the transparent part.
(fli:with-foreign-string (fstr len blen) fname
(declare (ignore len blen))
(%read-masked-bitmap fstr trans))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defparameter $x-org 0)
(defparameter $y-org 0))
(fli:define-foreign-function (%draw-nonmasked
"lpDrawNonmasked")
((pbm (:pointer :void))
(ulc_x :int)
(ulc_y :int)
(bm_ulc_x :int)
(bm_ulc_y :int)
(bm_wd :int)
(bm_ht :int))
:result-type :void
:module sg::*plotter-dll*
:calling-convention :cdecl)
(defun draw-nonmasked (pbm ulc-x ulc-y bm-ulc-x bm-ulc-y bm-wd bm-ht)
(%draw-nonmasked pbm
(+ ulc-x $x-org)
(+ ulc-y $y-org)
bm-ulc-x bm-ulc-y
bm-wd bm-ht))
(fli:define-foreign-function (%draw-masked
"lpDrawMasked")
((pbm (:pointer :void))
(ulc_x :int)
(ulc_y :int)
(bm_ulc_x :int)
(bm_ulc_y :int)
(bm_wd :int)
(bm_ht :int))
:result-type :void
:module sg::*plotter-dll*
:calling-convention :cdecl)
(defun draw-masked (pbm ulc-x ulc-y bm-ulc-x bm-ulc-y bm-wd bm-ht)
(%draw-masked pbm
(+ ulc-x $x-org)
(+ ulc-y $y-org)
bm-ulc-x bm-ulc-y
bm-wd bm-ht))
(fli:define-foreign-function (%tile-bg
"lpTileBG")
((pbm (:pointer :void))
(ulc_x :int)
(ulc_y :int)
(wd :int)
(ht :int)
(bm_ulc_x :int)
(bm_ulc_y :int)
(bm_wd :int)
(bm_ht :int))
:result-type :void
:module sg::*plotter-dll*
:calling-convention :cdecl)
(defun tile-bg (pbm ulc-x ulc-y wd ht bm-ulc-x bm-ulc-y bm-wd bm-ht)
(%tile-bg pbm
(+ ulc-x $x-org)
(+ ulc-y $y-org)
wd ht
bm-ulc-x bm-ulc-y
bm-wd bm-ht))
(fli:define-foreign-function (%clip-drawing "lpClipDrawing")
((r_left :int)
(r_top :int)
(r_width :int)
(r_height :int))
:result-type :pointer
:module sg::*plotter-dll*
:calling-convention :cdecl)
(defun clip-drawing (r-left r-top r-width r-height)
(%clip-drawing (+ r-left $x-org)
(+ r-top $y-org)
r-width r-height))
(fli:define-foreign-function (unclip-drawing "lpUnclipDrawing")
((sav :pointer))
:result-type :void
:module sg::*plotter-dll*
:calling-convention :cdecl)
(fli:define-foreign-function (lock-drawing "lpLockDrawing")
()
:result-type :void
:module sg::*plotter-dll*
:calling-convention :cdecl)
(fli:define-foreign-function (unlock-drawing "lpUnlockDrawing")
()
:result-type :void
:module sg::*plotter-dll*
:calling-convention :cdecl)
(fli:define-foreign-function (%get-image-bits "lpGetImageBits")
((left :int)
(top :int)
(wd :int)
(ht :int))
:result-type :pointer
:module sg::*plotter-dll*
:calling-convention :cdecl)
(defun get-image-bits (left top wd ht)
(%get-image-bits (+ left $x-org)
(+ top $y-org)
wd ht))
(fli:define-foreign-function (%set-image-bits "lpSetImageBits")
((bits :pointer)
(left :int)
(top :int)
(wd :int)
(ht :int))
:result-type :void
:module sg::*plotter-dll*
:calling-convention :cdecl)
(defun set-image-bits (bits left top wd ht)
(%set-image-bits bits
(+ left $x-org)
(+ top $y-org)
wd ht))
(fli:define-foreign-function (discard-image-bits "lpDiscardImageBits")
((bits :pointer))
:result-type :void
:module sg::*plotter-dll*
:calling-convention :cdecl)
;; --------------------------------------------------------------
;;
#| |#
(eval-when (:compile-toplevel :load-toplevel :execute)
(defparameter $bg-file "d:/projects/bitmap/bmbkgrnd.bmp")
(defparameter $knob-file "d:/projects/bitmap/bmwidget.bmp")
(defparameter $frame-file "d:/projects/bitmap/bmframe.bmp")
(defparameter $transparent-color (rgb-quad 255 0 255)) ;; magenta
(defvar $bg-bmps nil)
(defvar $knob-bmps nil)
(defvar $frame-bmps nil)
(defun init-bmps ()
(setf $bg-bmps (read-nonmasked-bitmap $bg-file)
$knob-bmps (read-masked-bitmap $knob-file
$transparent-color)
$frame-bmps (read-masked-bitmap $frame-file
$transparent-color)))
(unless $bg-bmps
(init-bmps)))
;; ---------------------------------------------------------------
;; Background handling
(defclass bg-finish ()
((bg-bmp :accessor bg-bmp :initarg :bmp)
(bg-ulc-x :accessor bg-ulc-x :initarg :ulc-x)
(bg-ulc-y :accessor bg-ulc-y :initarg :ulc-y)
(bg-wd :accessor bg-wd :initarg :wd)
(bg-ht :accessor bg-ht :initarg :ht)))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defparameter $brushed-aluminum
(make-instance 'bg-finish
:bmp $bg-bmps
:ulc-x 0
:ulc-y 0
:wd 256
:ht 256))
(defparameter $wrinkled-vinyl
(make-instance 'bg-finish
:bmp $bg-bmps
:ulc-x 256
:ulc-y 0
:wd 100
:ht 160)))
(defmethod tile ((bg bg-finish) left top width height)
(tile-bg (bg-bmp bg)
left top width height
(bg-ulc-x bg) (bg-ulc-y bg)
(bg-wd bg) (bg-ht bg)))
(defmethod tile :after ((bg (eql $brushed-aluminum))
left top width height)
;; we need to smooth the top and bottom edges of this background
;; the smoothing constants are located in the frames bitmap
(tile-bg $frame-bmps
left top width 2
3 91 24 2)
(tile-bg $frame-bmps
left (+ top height -3) width 3
15 248 2 3))
(defmethod repair ((bg bg-finish) left top width height)
;; same as tile, but avoids edging when present
(tile-bg (bg-bmp bg)
left top width height
(bg-ulc-x bg) (bg-ulc-y bg)
(bg-wd bg) (bg-ht bg)))
(defclass chassis ()
((chassis-bg :accessor chassis-bg
:initarg :bg
:initform $wrinkled-vinyl)
(chassis-panels :accessor chassis-panels
:initarg :panels
:initform (make-array 10))))
(defmacro with-origin ((x y) &body body)
`(let (($x-org (+ $x-org ,x))
($y-org (+ $y-org ,y)))
,@body))
(defmethod draw ((chassis chassis))
(tile (chassis-bg chassis)
0 0 1600 1600)
(map nil
#'(lambda (lst)
(dolist (panel lst)
(with-origin ((panel-left panel)
(panel-top panel))
(draw panel))))
(chassis-panels chassis)))
(defmethod add-panel ((chassis chassis) panel &key (row 1))
(let* ((rowm1 (1- (min 10 (max row 1))))
(offy (reduce #'+
(mapcar #'panel-width
(aref (chassis-panels chassis)
rowm1)))))
(setf (panel-chassis panel) chassis
(panel-left panel) offy
(panel-top panel) (* 160 rowm1)
(panel-height panel) 160)
(push panel (aref (chassis-panels chassis) rowm1))))
(defmethod find-panel ((chassis chassis) name)
(let* ((arr (chassis-panels chassis))
(nrows (array-total-size arr)))
(labels
((find-in-row (ix)
(if (< ix nrows)
(or (find name (aref arr ix)
:key #'panel-name)
(find-in-row (1+ ix))))))
(let ((panel (find-in-row 0)))
(unless panel
(error "panel not found: ~S" name))
panel))))
;; ---------------------------------------------------------
;; Panel management
(defclass panel ()
((panel-chassis :accessor panel-chassis :initarg :chassis)
(panel-name :accessor panel-name :initarg :name)
(panel-left :accessor panel-left :initarg :left)
(panel-top :accessor panel-top :initarg :top)
(panel-width :accessor panel-width :initarg :width)
(panel-height :accessor panel-height :initarg :height)
(panel-bg :accessor panel-bg :initarg :bg
:initform $brushed-aluminum)
(panel-items :accessor panel-items :initarg :items
:initform nil)
(panel-backing :accessor panel-backing
:initform nil)
(panel-origin :accessor panel-origin)
))
(defmethod cleanup-pointers (x)
nil)
(defmethod cleanup-pointers ((it panel))
(let ((bits (panel-backing it)))
(if bits
(discard-image-bits bits))
(setf (panel-backing it) nil)))
(defmethod initialize-instance :after ((it panel) &rest args)
(declare (ignore args))
(hcl::add-special-free-action 'cleanup-pointers)
(hcl::flag-special-free-action it))
(defmacro with-clipped-drawing ((left top width height) &body body)
;; use for drawing composite items
;; locks the bitmap so partial screen restoration won't happen
(let ((sav (gensym)))
`(let ((,sav (clip-drawing ,left ,top ,width ,height)))
(unwind-protect
(progn
,@body)
(unclip-drawing ,sav)))
))
(defmethod draw ((panel panel))
(let ((wd (panel-width panel))
(ht (panel-height panel)))
;; remember our location in case we have to repair anything
(setf (panel-origin panel) (list $x-org $y-org))
(with-clipped-drawing (0 0 wd ht)
(tile (panel-bg panel) 0 0 wd ht)
(if (panel-backing panel)
(repair-panel panel)
(progn
(dolist (item (panel-items panel))
(with-origin ((decoration-left item)
(decoration-top item))
(instantiate item)))
(setf (panel-backing panel)
(get-image-bits 0 0 wd ht))))
(dolist (item (panel-items panel))
(with-origin ((decoration-left item)
(decoration-top item))
(draw item)))
)))
(defmethod repair-panel ((panel panel))
(let ((bits (panel-backing panel))
(org (panel-origin panel)))
(let (($x-org (first org))
($y-org (second org)))
(if bits
(set-image-bits bits
0 0
(panel-width panel)
(panel-height panel))
(repair (panel-bg panel)
0 0
(panel-width panel)
(panel-height panel)))
)))
(defmethod repair-panel-subrect ((panel panel) left top width height)
(with-clipped-drawing (left top width height)
(repair-panel panel)))
(defmethod add-item ((panel panel) item)
(setf (decoration-panel item) panel)
(push item (panel-items panel)))
(defmethod find-item ((panel panel) name)
(let ((item (find name (panel-items panel)
:key #'decoration-name)))
(unless item
(error "can't find item: ~S" name))
item))
;; ---------------------------------------------------------
;; Frame decorations
(defclass decoration ()
((decoration-panel :accessor decoration-panel :initarg :panel)
(decoration-name :accessor decoration-name :initarg :name
:initform "")
(decoration-left :accessor decoration-left :initarg :left)
(decoration-top :accessor decoration-top :initarg :top)
(decoration-kind :accessor decoration-kind :initarg :kind)))
(defmethod instantiate ((d decoration))
(draw-single-item (decoration-kind d)))
(defmethod draw ((d decoration))
nil)
(defmethod redraw ((d decoration))
(let ((panel (decoration-panel d)))
(with-origin ((panel-left panel)
(panel-top panel))
(with-origin ((decoration-left d)
(decoration-top d))
(draw d)))
))
;; --------------------------------------------------------
;; Label decorations
(defclass label (decoration)
((label-text :accessor label-text :initarg :text)
(label-anchor :accessor label-anchor :initarg :anchor
:initform :sw)))
(defmethod instantiate ((lbl label))
(draw-string (decoration-kind lbl)
(label-text lbl)
(label-anchor lbl)))
;; ---------------------------------------------------------
;; Indicators -- actually anything that is displayed in a panel
(defclass indicator (decoration)
((indicator-value :accessor indicator-value :initarg :value
:initform 0)))
(defmethod indicator-display-value ((indi indicator))
;; By default, just the indicator-value itself.
(indicator-value indi))
(defmethod instantiate ((it indicator))
nil)
(defmethod draw ((indi indicator))
(draw-multi-item (decoration-kind indi)
(indicator-display-value indi)))
(defmethod set-value ((indi indicator) val)
;; Stores a new indicator value and redisplays the
;; indicator on screen.
(unless (eql val (indicator-value indi))
(setf (indicator-value indi) val)
(redraw indi)))
;; -------------------------------------------------------------
;; Actuators -- widgets that respond to the mouse
(defclass actuator (indicator)
())
;; -------------------------------------------------------------
;; Bitmap widgets
(defclass bmp-owner-item ()
((bmp-item-bmp :accessor bmp-item-bmp :initarg :bmp
:initform $knob-bmps)
(bmp-item-y0 :accessor bmp-item-y0 :initarg :y0)
(bmp-item-height :accessor bmp-item-height :initarg :height)))
(defclass masked-mixin ()
())
(defmethod draw-bmp ((item masked-mixin) x0 y0 wd ht)
(draw-masked (bmp-item-bmp item) 0 0 x0 y0 wd ht))
(defclass nonmasked-mixin ()
())
(defmethod draw-bmp ((item nonmasked-mixin) x0 y0 wd ht)
(draw-nonmasked (bmp-item-bmp item) 0 0 x0 y0 wd ht))
;; ------------------------------------------------------------
;; String management
(defclass font-item (bmp-owner-item masked-mixin)
((font-starts :accessor font-starts :initarg :starts)
(font-extras :accessor font-extras :initarg :extras)
(font-space-width :accessor font-space-width :initarg :space-wd)))
(defun lookup-char (starts ix)
;; starts is a table of x offsets for each character
(let ((start (aref starts ix))
(end (aref starts (1+ ix))))
(values start (- end start))))
(defun lookup-extra (starts ch)
;; starts is an alist of (char . (xoffset width))
;; first cell is the default char info
(let ((info (or (assoc ch starts)
(first starts))))
(values (second info) (third info))))
(defmethod lookup-char-starts ((item font-item) ch)
(cond
((and (char>= ch #\A)
(char<= ch #\Z))
(lookup-char
(font-starts item)
(- (char-code ch) #.(char-code #\A))))
((and (char>= ch #\a)
(char<= ch #\z))
(lookup-char
(font-starts item)
(+ 26 (- (char-code ch) #.(char-code #\a)))))
((and (char>= ch #\1)
(char<= ch #\9))
(lookup-char
(font-starts item)
(+ 52 (- (char-code ch) #.(char-code #\1)))))
((char= ch #\0)
(lookup-char
(font-starts item)
61))
(t (lookup-extra (font-extras item) ch))))
(defmethod draw-char ((item font-item) off-x ch)
(multiple-value-bind (x0 wd)
(lookup-char-starts item ch)
(with-origin (off-x 0)
(draw-bmp item
x0 (bmp-item-y0 item)
wd (bmp-item-height item)))
wd))
(defmethod size-char ((item font-item) ch)
(multiple-value-bind (x0 wd)
(lookup-char-starts item ch)
(declare (ignore x0))
wd))
(defmethod size-string ((item font-item) str)
(let ((pos 0))
(map nil #'(lambda (ch)
(if (char= ch #\Space)
(incf pos (font-space-width item))
(incf pos (size-char item ch))))
str)
(values pos (bmp-item-height item))))
(defmacro with-locked-drawing (&body body)
`(progn
(lock-drawing)
(unwind-protect
(progn
,@body)
(unlock-drawing))))
(defmethod draw-string ((item font-item) str anchor)
(multiple-value-bind (wd ht)
(size-string item str)
(multiple-value-bind (lf tp)
(ecase anchor
( :sw (values 0 (- ht)))
( :w (values 0 (- (truncate ht 2))))
( :nw (values 0 0))
( :se (values (- wd) (- ht)))
( :e (values (- wd) (- (truncate ht 2))))
( :ne (values (- wd) 0))
( :n (values (- (truncate wd 2)) 0))
( :s (values (- (truncate wd 2)) (- ht)))
( :ctr (values (- (truncate wd 2))
(- (truncate ht 2)))))
(with-origin (lf tp)
(with-locked-drawing
(let ((pos 0))
(map nil #'(lambda (ch)
(if (char= ch #\Space)
(incf pos (font-space-width item))
(incf pos (draw-char item pos ch))))
str))))
)))
(defmethod draw-string-at ((item font-item) left top str anchor)
(with-origin (left top)
(draw-string item str anchor)))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defparameter $small-font-extras
`((#\? 85 4) ;; default char
(#\. 399 2)
(#\, 401 3)))
(defparameter $small-font-starts
#( 89 ;; #\A
94
99
104
109
114
119
124
129
134
139
144
149
154
159
164
169
174
179
184
189
194
199
204
209
214 ;; #\Z
219 ;; #\a
224
229
234
239
244
249
254
259
264
269
275
279
284
289
294
299
304
309
314
319
324
329
334
339
344 ;; #\z
349 ;; #\1
354 ;; #\2
359
364
369
374 ;; #\6
379
384
389 ;; #\9
394 ;; #\0
399)) ;; next beyond #\0
(defparameter $large-font-extras
'((#\/ 220 5)
(#\- 569 6)
(#\+ 574 7)
(#\. 579 3)
(#\, 582 4)
(#\_ 585 5)))
(defparameter $large-font-starts
#(225 ;; #\A
231
237
243
249
254
259
266
272
274
279
285
290
298
304
312
318
326
332
338
344
350
356
366
372
378 ;; #\Z
383 ;; #\a
388
393
399
403
408
413
417
422
424
427
432
434
442
447
452
457
462
467
472
476
481
487
495
501
507 ;; #\z
512 ;; #\1
515 ;; #\2
521 ;; #\3
527
533
539 ;; #\6
545
551
557 ;; #\9
563 ;; #\0
569)) ;; next beyond #\0
(defparameter $large-font-item
(make-instance 'font-item
:bmp $knob-bmps
:starts $large-font-starts
:extras $large-font-extras
:space-wd 5
:y0 636
:height 11))
(defparameter $large-font-embossed-gray-item
(make-instance 'font-item
:bmp $knob-bmps
:starts $large-font-starts
:extras $large-font-extras
:space-wd 5
:y0 624
:height 11))
(defparameter $large-font-embossed-white-item
(make-instance 'font-item
:bmp $knob-bmps
:starts $large-font-starts
:extras $large-font-extras
:space-wd 5
:y0 648
:height 11))
(defparameter $small-font-item
(make-instance 'font-item
:bmp $knob-bmps
:starts $small-font-starts
:extras $small-font-extras
:space-wd 3
:y0 555
:height 5)))
;; --------------------------------------------------------------
;; Widget management
(defclass bmp-item (bmp-owner-item)
((bmp-item-x0 :accessor bmp-item-x0 :initarg :x0)
(bmp-item-width :accessor bmp-item-width :initarg :width)))
(defmethod draw-single-item ((item bmp-item))
(draw-bmp item
(bmp-item-x0 item)
(bmp-item-y0 item)
(bmp-item-width item)
(bmp-item-height item)))
(defclass multi-bmp-item (bmp-item)
((bmp-item-count :accessor bmp-item-count :initarg :count)
(bmp-item-mod :accessor bmp-item-mod :initarg :mod)))
(defmethod draw-multi-item ((item multi-bmp-item) val)
(let ((val (max 0 (min (round val)
(1- (bmp-item-count item)))
)))
(multiple-value-bind (quot rem)
(truncate val (bmp-item-mod item))
(draw-bmp item
(+ (bmp-item-x0 item)
(* rem (bmp-item-width item)))
(+ (bmp-item-y0 item)
(* quot (bmp-item-height item)))
(bmp-item-width item)
(bmp-item-height item)))
))
(defclass odometer-item (multi-bmp-item nonmasked-mixin)
())
(defclass meter-face-item (bmp-item masked-mixin)
())
(defclass meter-needle-item (multi-bmp-item nonmasked-mixin)
())
(defmethod draw-multi-item :around ((item meter-needle-item) val)
;; The meter needle movements are just bitmaps that are copied
;; over the face of the meter, and so they need to be offset
;; from the ULC of the meter face.
(with-origin (11 14)
(call-next-method)))
(defclass led-item (multi-bmp-item masked-mixin)
())
(defclass lever-switch-item (multi-bmp-item masked-mixin)
((label-x :accessor label-x :initarg :label-x
:initform nil)
(label-y :accessor label-y :initarg :label-y
:initform nil)))
(defmethod draw-labels ((it lever-switch-item) labels)
(let ((x0 (label-x it))
(y0 (1- (bmp-item-height it))))
(map nil
#'(lambda (offy lbl)
(with-origin (x0 (- y0 offy))
(draw-string $small-font-item lbl :e)))
(label-y it) labels)))
(defclass push-button-item (multi-bmp-item masked-mixin)
())
(defclass knob-item (multi-bmp-item masked-mixin)
())
(defclass rotary-switch-item (knob-item)
((label-x :accessor label-x :initarg :label-x
:initform nil)
(label-y :accessor label-y :initarg :label-y
:initform nil)
(label-anchors :accessor label-anchors :initarg :anchor
:initform nil)))
(defmethod draw-labels ((it rotary-switch-item) labels)
(let ((y0 (1- (bmp-item-height it))))
(map nil
#'(lambda (offx offy lbl anchor)
(with-origin (offx (- y0 offy))
(draw-string $small-font-item lbl anchor)))
(label-x it) (label-y it) labels (label-anchors it))))
(defclass tristate-push-button-item (multi-bmp-item masked-mixin)
())
(defclass masked-decoration-item (bmp-item masked-mixin)
())
(defclass blob-item (bmp-item masked-mixin)
())
(defclass slider-slot-item (bmp-item nonmasked-mixin)
())
(defclass slider-knob-item (multi-bmp-item nonmasked-mixin)
())
(defclass slider-scale-item (bmp-item masked-mixin)
())
(eval-when (:compile-toplevel :load-toplevel :execute)
(defparameter $meter-face-item
(make-instance 'meter-face-item
:bmp $knob-bmps
:count 1
:mod 1
:x0 0
:width 84
:y0 478
:height 84))
(defparameter $meter-needle-item
(make-instance 'meter-needle-item
:bmp $knob-bmps
:count 32
:mod 14
:x0 0
:y0 310
:width 56
:height 56))
(defparameter $red-led-item
(make-instance 'led-item
:bmp $knob-bmps
:count 2
:mod 2
:x0 721
:y0 249
:width 13
:height 13))
(defparameter $green-led-item
(make-instance 'led-item
:bmp $knob-bmps
:count 2
:mod 2
:x0 721
:y0 262
:width 13
:height 13))
(defparameter $yellow-led-item
(make-instance 'led-item
:bmp $knob-bmps
:count 2
:mod 2
:x0 721
:y0 275
:width 13
:height 13))
(defparameter $green-triangular-led-item
(make-instance 'led-item
:bmp $knob-bmps
:count 2
:mod 1
:x0 553
:y0 438
:width 11
:height 11))
(defparameter $toggle-switch-item
(make-instance 'lever-switch-item
:bmp $knob-bmps
:count 3
:mod 3
:x0 627
:y0 423
:width 36
:height 46))
(defparameter $push-button-item
(make-instance 'push-button-item
:bmp $knob-bmps
:count 2
:mod 1
:x0 748
:y0 249
:width 34
:height 21))
(defparameter $large-knob-item
(make-instance 'knob-item
:bmp $knob-bmps
:count 64
:mod 13
:x0 0