-
Notifications
You must be signed in to change notification settings - Fork 3
/
Morphic-Widgets-Extras.pck.st
1428 lines (1178 loc) · 47.8 KB
/
Morphic-Widgets-Extras.pck.st
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
'From Cuis7.1 [latest update: #6715] on 12 September 2024 at 12:33:44 pm'!
'Description Various useful widgets'!
!provides: 'Morphic-Widgets-Extras' 1 45!
!requires: 'Cuis-Base' 60 6114 nil!
SystemOrganization addCategory: #'Morphic-Widgets-Extras'!
SystemOrganization addCategory: #'Morphic-Widgets-Extras-Tests'!
!classDefinition: #LimitedHeightTextMorph category: #'Morphic-Widgets-Extras'!
TextModelMorph subclass: #LimitedHeightTextMorph
instanceVariableNames: 'maxHeight'
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Widgets-Extras'!
!classDefinition: 'LimitedHeightTextMorph class' category: #'Morphic-Widgets-Extras'!
LimitedHeightTextMorph class
instanceVariableNames: ''!
!classDefinition: #DragAndDropAreaMorph category: #'Morphic-Widgets-Extras'!
BorderedBoxMorph subclass: #DragAndDropAreaMorph
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Widgets-Extras'!
!classDefinition: 'DragAndDropAreaMorph class' category: #'Morphic-Widgets-Extras'!
DragAndDropAreaMorph class
instanceVariableNames: ''!
!classDefinition: #PartsBinMorph category: #'Morphic-Widgets-Extras'!
DragAndDropAreaMorph subclass: #PartsBinMorph
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Widgets-Extras'!
!classDefinition: 'PartsBinMorph class' category: #'Morphic-Widgets-Extras'!
PartsBinMorph class
instanceVariableNames: ''!
!classDefinition: #EllipseMorph category: #'Morphic-Widgets-Extras'!
BorderedBoxMorph subclass: #EllipseMorph
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Widgets-Extras'!
!classDefinition: 'EllipseMorph class' category: #'Morphic-Widgets-Extras'!
EllipseMorph class
instanceVariableNames: ''!
!classDefinition: #HandleMorph category: #'Morphic-Widgets-Extras'!
EllipseMorph subclass: #HandleMorph
instanceVariableNames: 'pointBlock'
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Widgets-Extras'!
!classDefinition: 'HandleMorph class' category: #'Morphic-Widgets-Extras'!
HandleMorph class
instanceVariableNames: ''!
!classDefinition: #FrameRateMorph category: #'Morphic-Widgets-Extras'!
BorderedBoxMorph subclass: #FrameRateMorph
instanceVariableNames: 'lastStepDelta meanStepDelta'
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Widgets-Extras'!
!classDefinition: 'FrameRateMorph class' category: #'Morphic-Widgets-Extras'!
FrameRateMorph class
instanceVariableNames: ''!
!classDefinition: #FunctionGraphMorph category: #'Morphic-Widgets-Extras'!
BorderedBoxMorph subclass: #FunctionGraphMorph
instanceVariableNames: 'xMin xMax yMin yMax functions colors yRangeInvalid'
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Widgets-Extras'!
!classDefinition: 'FunctionGraphMorph class' category: #'Morphic-Widgets-Extras'!
FunctionGraphMorph class
instanceVariableNames: ''!
!classDefinition: #MagnifierMorph category: #'Morphic-Widgets-Extras'!
BorderedBoxMorph subclass: #MagnifierMorph
instanceVariableNames: 'magnification trackPointer lastPos srcExtent auxCanvas magnifiedForm'
classVariableNames: 'RecursionLock'
poolDictionaries: ''
category: 'Morphic-Widgets-Extras'!
!classDefinition: 'MagnifierMorph class' category: #'Morphic-Widgets-Extras'!
MagnifierMorph class
instanceVariableNames: ''!
!classDefinition: #MinimalStringMorph category: #'Morphic-Widgets-Extras'!
BorderedBoxMorph subclass: #MinimalStringMorph
instanceVariableNames: 'font emphasis contents'
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Widgets-Extras'!
!classDefinition: 'MinimalStringMorph class' category: #'Morphic-Widgets-Extras'!
MinimalStringMorph class
instanceVariableNames: ''!
!classDefinition: #OneLineEditorMorph category: #'Morphic-Widgets-Extras'!
BorderedBoxMorph subclass: #OneLineEditorMorph
instanceVariableNames: 'font emphasis contents editor showTextCursor pauseBlinking textCursorRect keyboardFocusWatcher crAction'
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Widgets-Extras'!
!classDefinition: 'OneLineEditorMorph class' category: #'Morphic-Widgets-Extras'!
OneLineEditorMorph class
instanceVariableNames: ''!
!classDefinition: #SamplePlotterMorph category: #'Morphic-Widgets-Extras'!
BorderedBoxMorph subclass: #SamplePlotterMorph
instanceVariableNames: 'domain sampleSequences colors yMax yMin'
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Widgets-Extras'!
!classDefinition: 'SamplePlotterMorph class' category: #'Morphic-Widgets-Extras'!
SamplePlotterMorph class
instanceVariableNames: ''!
!classDefinition: #TextEditorTest category: #'Morphic-Widgets-Extras-Tests'!
TestCase subclass: #TextEditorTest
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Widgets-Extras-Tests'!
!classDefinition: 'TextEditorTest class' category: #'Morphic-Widgets-Extras-Tests'!
TextEditorTest class
instanceVariableNames: ''!
!LimitedHeightTextMorph commentStamp: '<historical>' prior: 0!
A TextMorph that will expand and contract vertically to adjust for the contents, but limited to a specific max height. If contents are larger, a scrollbar will be used.
LimitedHeightTextMorph new
maxHeight: 48;
model: (TextModel new contents: 'This is some text to test the morph.');
openInWorld!
!DragAndDropAreaMorph commentStamp: 'jmv 9/12/2024 12:32:47' prior: 0!
A simple morph that allows dragging submorphs, and dropping other morphs on it. It is provided as an example, and also as a reference of the methods you might need to implement in your morphs to handle drag and drop.
| m |
m _ DragAndDropAreaMorph new.
m openInWorld.
m addMorph: BoxMorph new.
m morphExtent: 320@240!
!PartsBinMorph commentStamp: '<historical>' prior: 0!
Like DragAndDropAreaMorph, but when submorphs are dragged, get a copy and not the original one.
| m |
m _ PartsBinMorph new.
m openInWorld.
m addMorph: EllipseMorph new.
m morphExtent: 120@240!
!EllipseMorph commentStamp: '<historical>' prior: 0!
A round bordered Morph. Supports borderWidth and borderColor.
EllipseMorph new borderWidth:10; borderColor: Color green; openInWorld.
!
!HandleMorph commentStamp: '<historical>' prior: 0!
A HandleMorph provides mouse-up control behavior.!
!FrameRateMorph commentStamp: 'jmv 6/11/2012 10:14' prior: 0!
A very simple morph to demo stepping, and for knowing about stepping (and world update) frame rates.
FrameRateMorph new openInHand!
!FunctionGraphMorph commentStamp: 'jmv 4/21/2020 20:52:08' prior: 0!
For continuous functions on a real domain.
| g d |
d _ -1.
g _ FunctionGraphMorph new.
g domain: (-4 to: 4).
g addFunction: [ :x | x \\ d ] color: Color green.
g addFunction: [ :x | x // d ] color: Color red.
(g embeddedInMorphicWindowLabeled: 'graph') openInWorld
| g d |
d _ -1.
g _ FunctionGraphMorph new.
g domain: (-4 to: 4).
g addFunction: [ :x | x rem: d ] color: Color green.
g addFunction: [ :x | x quo: d ] color: Color red.
g openInWorld
| g d |
d _ -1.
g _ FunctionGraphMorph new.
g domain: (-4 to: 4).
g addFunction: [ :x | x mod: d ] color: Color green.
g addFunction: [ :x | x div: d ] color: Color red.
g openInWorld
| g |
g _ FunctionGraphMorph new.
g domain: (-30 to: 30 count: 2000).
g domain: (-30 to: 30).
g yRange: (-200 to: 200).
g addFunction: [ :x | ((3* x *x)) / (x+2) ] color: Color red.
g addFunction: [ :x | ((3* x *x*x) - (6*x*x)) / (x squared -4) ] color: Color green.
(g embeddedInMorphicWindowLabeled: 'graph') openInWorld.
!
!MagnifierMorph commentStamp: '<historical>' prior: 0!
Provides a magnifying glass. Magnifies the morphs below (if grabbed) or the area around the mouse pointer.!
!MinimalStringMorph commentStamp: 'jmv 4/1/2009 21:43' prior: 0!
A greatly reduced StringMorph. May be of some use.!
!OneLineEditorMorph commentStamp: '<historical>' prior: 0!
A plain text editor for Morphic. Handles only one line. Does not handle fonts/styles, alignment, Smalltalk utilities and any other advanced stuff in TextModelMorph. Just a simple text editor.
Can optionally include a crAction: a zero argument closure, to be evaluated on Cr keystroke.!
!SamplePlotterMorph commentStamp: '<historical>' prior: 0!
| h r p |
h _ Histogram binCount: 200 minValue: -10.0 maxValue: 10.0.
r _ NormalProbabilityDistribution new.
10000 timesRepeat: [ h addValue: r nextRandomNumber ].
h plot.
h domain.
p _ SamplePlotterMorph new.
p domain: h domain.
p addSamples: h counts color: Color green.
(p embeddedInMorphicWindowLabeled: 'graph') openInWorld.
Would be cool to add other interpolators. So far, we only have Nearest Neighbor.
Check SignalProcessing.pck.st for other 1D interpolators: Linear, Cubic, Splines, Beziers, Lanczos...
!
!LimitedHeightTextMorph methodsFor: 'initialization' stamp: 'jmv 8/21/2012 21:59'!
initialize
super initialize.
extent _ 200 @ 120! !
!LimitedHeightTextMorph methodsFor: 'geometry' stamp: 'jmv 12/12/2011 14:20'!
innerHeight: aNumber
"Adjust height and scrollbar to the new contents height."
self morphHeight: (aNumber + 10 min: maxHeight)! !
!LimitedHeightTextMorph methodsFor: 'geometry' stamp: 'jmv 7/20/2014 10:12'!
privateExtent: aPoint
^ (super privateExtent: aPoint)
ifTrue: [
maxHeight _ extent y ]; yourself! !
!LimitedHeightTextMorph methodsFor: 'accessing' stamp: 'jmv 11/14/2011 16:32'!
maxHeight: aNumber
maxHeight _ aNumber! !
!LimitedHeightTextMorph class methodsFor: 'instance creation' stamp: 'jmv 11/14/2011 16:32'!
initializedInstance
^self new
maxHeight: 48;
model: (TextModel new contents: 'This is some text to test the morph.')! !
!DragAndDropAreaMorph methodsFor: 'drag and drop us' stamp: 'jmv 1/24/2013 22:53'!
aboutToBeGrabbedBy: aHand
"The receiver is being grabbed by a hand.
Perform necessary adjustments (if any) and return the actual morph
that should be added to the hand.
Answer nil to reject the drag."
"This message is sent to the dragged morph, not to the owner.
It is included here just for reference."
^self "Grab me"! !
!DragAndDropAreaMorph methodsFor: 'drag and drop us' stamp: 'jmv 1/24/2013 22:53'!
justDroppedInto: newOwnerMorph event: anEvent
"This message is sent to a dropped morph after it has been dropped on -- and been accepted by -- a drop-sensitive morph"
"This message is sent to the dragged morph, not to the owner.
It is included here just for reference."
^super justDroppedInto: newOwnerMorph event: anEvent ! !
!DragAndDropAreaMorph methodsFor: 'drag and drop us' stamp: 'jmv 1/24/2013 22:53'!
justGrabbedFrom: formerOwner
"The receiver was just grabbed from its former owner and is now attached to the hand."
"This message is sent to the dragged morph, not to the owner.
It is included here just for reference."! !
!DragAndDropAreaMorph methodsFor: 'drag and drop us' stamp: 'jmv 1/24/2013 22:53'!
wantsToBeDroppedInto: aMorph
"Return true if it's okay to drop the receiver into aMorph. This check is symmetric to #wantsDroppedMorph:event: to give both parties a chance of figuring out whether they like each other."
"This message is sent to the dragged morph, not to the owner.
It is included here just for reference."
^true! !
!DragAndDropAreaMorph methodsFor: 'drag and drop other morphs' stamp: 'jmv 1/24/2013 22:52'!
allowsMorphDrop
"Answer whether we accept dropping morphs. Redefined to answer true."
^ true! !
!DragAndDropAreaMorph methodsFor: 'drag and drop other morphs' stamp: 'jmv 1/24/2013 22:52'!
allowsSubmorphDrag
"Answer whether our morphs can just be grabbed with the hand, instead of requiring the use of the halo. Redefined to answer true."
^ true! !
!DragAndDropAreaMorph methodsFor: 'drag and drop other morphs' stamp: 'jmv 1/24/2013 22:52'!
wantsDroppedMorph: aMorph event: evt
"Return true if the receiver wishes to accept the given morph, which is being dropped by a hand in response to the given event. Note that for a successful drop operation both parties need to agree. The symmetric check is done automatically via aMorph wantsToBeDroppedInto: self.
This method just answers super. It is included here to say it is relevant to D&D behavior."
^super wantsDroppedMorph: aMorph event: evt! !
!PartsBinMorph methodsFor: 'dropping/grabbing' stamp: 'jmv 2/22/2013 12:49'!
aboutToGrab: aMorph
"submorph is being grabbed by a hand.
Perform necessary adjustments (if any) and return the actual morph
that should be added to the hand.
Answer nil to reject the drag."
^aMorph copy! !
!EllipseMorph methodsFor: 'drawing' stamp: 'KenD 11/9/2022 11:58:57'!
drawOn: aCanvas
| rx ry |
rx _ extent x //2.
ry _ extent y // 2.
aCanvas ellipseCenter: extent // 2 radius: rx @ ry borderWidth: borderWidth borderColor: borderColor fillColor: color! !
!EllipseMorph methodsFor: 'geometry testing' stamp: 'KenD 2/8/2022 17:32:49'!
knowsOwnLocalBounds
^false! !
!EllipseMorph methodsFor: 'geometry testing' stamp: 'jmv 3/30/2023 15:16:49'!
requiresVectorCanvas
^true! !
!EllipseMorph methodsFor: 'initialization' stamp: 'dgd 2/14/2003 22:37'!
defaultBorderWidth
"answer the default border width for the receiver"
^ 1! !
!EllipseMorph methodsFor: 'visual properties' stamp: 'jmv 3/10/2018 22:24:29'!
defaultColor
"Return the default fill style for the receiver"
^ `Color yellow`! !
!EllipseMorph class methodsFor: 'new-morph participation' stamp: 'pb 6/8/2017 23:50:14'!
categoryInNewMorphMenu
^ 'Basic'! !
!EllipseMorph class methodsFor: 'examples' stamp: 'KenD 12/20/2021 10:57:45'!
example1
"
EllipseMorph example1 openInWorld
"
^ self new morphExtent: 50@20! !
!EllipseMorph class methodsFor: 'examples' stamp: 'KenD 12/20/2021 10:58:03'!
example2
"
EllipseMorph example2 openInWorld
"
^ self new morphExtent: 50@80;
borderWidth: 4;
borderColor: Color red muchDarker;
color: Color red;
morphPosition: 0@0! !
!HandleMorph methodsFor: 'events' stamp: 'jmv 3/12/2018 15:51:54'!
keyStroke: aKeyboardEvent
"Check for cursor keys"
| keyValue |
(owner is: #HandMorph) ifFalse: [ ^self ].
keyValue _ aKeyboardEvent keyValue.
keyValue = 28 ifTrue: [ ^self morphPosition: self morphPosition - `1@0` ].
keyValue = 29 ifTrue: [ ^self morphPosition: self morphPosition + `1@0` ].
keyValue = 30 ifTrue: [ ^self morphPosition: self morphPosition - `0@1` ].
keyValue = 31 ifTrue: [ ^self morphPosition: self morphPosition + `0@1` ].
"Special case for return"
aKeyboardEvent isReturnKey ifTrue:[
"Drop the receiver and be done"
self flag: #arNote. "Probably unnecessary"
owner releaseKeyboardFocus: self.
self delete ]! !
!HandleMorph methodsFor: 'initialization' stamp: 'di 11/3/97 16:34'!
forEachPointDo: aBlock
pointBlock _ aBlock! !
!HandleMorph methodsFor: 'initialization' stamp: 'jmv 3/12/2018 15:51:51'!
initialize
"initialize the state of the receiver"
super initialize.
extent _ `12@12`! !
!HandleMorph methodsFor: 'stepping and presenter' stamp: 'jmv 7/22/2020 23:08:01'!
stepAt: millisecondSinceLast
pointBlock value: self displayBounds center! !
!HandleMorph methodsFor: 'testing' stamp: 'jmv 6/11/2012 23:32'!
stepTime
"Update very often. Very short steptimes should only be used for morphs that are not stepping all the time!!"
^ 20! !
!HandleMorph class methodsFor: 'new-morph participation' stamp: 'jmv 4/3/2011 22:43'!
includeInNewMorphMenu
"Return true for all classes that can be instantiated from the menu"
^ false! !
!FrameRateMorph methodsFor: 'drawing' stamp: 'jmv 6/11/2020 16:49:32'!
drawOn: aCanvas
super drawOn: aCanvas.
meanStepDelta ifNotNil: [
aCanvas drawString: lastStepDelta rounded printString at: 0@0 font: FontFamily defaultFamilyAndPointSize color: Color black.
aCanvas drawString: meanStepDelta rounded printString at: 0@14 font: FontFamily defaultFamilyAndPointSize color: Color black.
"aCanvas drawString: lastStepStamp printString at: bounds topLeft + (0@28) font: FontFamily defaultFamilyAndPointSize color: Color black "
]! !
!FrameRateMorph methodsFor: 'stepping' stamp: 'jmv 2/27/2016 19:52'!
stepAt: millisecondSinceLast
| n |
lastStepDelta _ millisecondSinceLast.
"This factor is a damper, to show a sort of mean of the n latest step deltas"
meanStepDelta
ifNil: [ meanStepDelta _ 0. n _ 0 ]
ifNotNil: [
" n _ (meanStepDelta / lastStepDelta between: 0.5 and: 2)
ifTrue: [ 10 ]
ifFalse: [10 ]."
n _ 20 ].
meanStepDelta _ meanStepDelta * n + lastStepDelta / (n+1).
self redrawNeeded! !
!FrameRateMorph methodsFor: 'stepping' stamp: 'jmv 6/11/2012 23:34'!
stepTime
^20! !
!FrameRateMorph methodsFor: 'stepping' stamp: 'jmv 6/11/2012 09:20'!
wantsSteps
"Return true if the receiver wants to its #step or #stepAt: methods be run"
^true! !
!FunctionGraphMorph methodsFor: 'accessing' stamp: 'jmv 11/18/2014 08:52'!
addFunction: aOneArgBlock color: aColor
functions add: aOneArgBlock.
colors add: aColor! !
!FunctionGraphMorph methodsFor: 'accessing' stamp: 'jmv 3/9/2018 16:06:11'!
domain: anInterval
xMin _ anInterval first asFloat.
xMax _ anInterval last asFloat.
yMin _ nil.
yMax _ nil.! !
!FunctionGraphMorph methodsFor: 'accessing' stamp: 'jmv 4/21/2020 20:44:35'!
yRange: anInterval
yMin _ anInterval first asFloat.
yMax _ anInterval last asFloat.
yRangeInvalid := false.! !
!FunctionGraphMorph methodsFor: 'drawing' stamp: 'jmv 6/11/2020 16:49:39'!
drawOn: aCanvas
"
| g |
g _ FunctionGraphMorph new.
g domain: (-4 to: 4).
g addFunction: [ :x | x mod: 1 ] color: Color green.
g addFunction: [ :x | x div: 1 ] color: Color red.
g openInWorld
"
| r fontToUse xtra p prevP |
yRangeInvalid ifTrue: [
yMin _ Float infinity.
yMax _ Float negativeInfinity.
self iterate: [ :x :y :c |
y notNil ifTrue: [
yMin _ yMin min: y.
yMax _ yMax max: y ]].
yMax = yMin ifTrue: [
yMin _ yMin min: 0.
yMax _ yMax max: 0 ].
xtra _ yMax-yMin/50.
yMin _ yMin - xtra.
yMax _ yMax + xtra.
yRangeInvalid := false.
].
r _ 40@0 corner: extent - (0@20).
aCanvas
frameAndFillRectangle: r fillColor: (Color gray: 0.9)
borderWidth: 0.05 borderColor: Color white.
(0 between: xMin and: xMax) ifTrue: [
aCanvas line: (self toMorphic:0@yMin)-(0@2) to: (self toMorphic: 0 @ yMax)+(0@2) width: 2 color: Color darkGray ].
(0 between: yMin and: yMax) ifTrue: [
aCanvas line: (self toMorphic: xMin@0)+(2@0) to: (self toMorphic: xMax@0)-(2@0) width: 2 color: Color darkGray ].
"To plot lines"
functions with: colors do: [ :f :c |
prevP _ nil.
xMin asFloat to: xMax count: extent x do: [ :x | | y |
y _ [ f value: x ] on: Error do: [].
(y notNil and: [
p _ (self xToMorphic: x)@(self yToMorphic: y).
(r containsPoint: p) ])
ifFalse: [
prevP _ nil]
ifTrue: [
prevP notNil ifTrue: [
aCanvas line: prevP to: p width: 2 color: c ].
prevP _ p ]]].
"To plot just the points"
"self iterate: [ :x :y :c |
(y between: yMin and: yMax) ifTrue: [
r2 _ (self xToMorphic: x)@(self yToMorphic: y) extent: 2.5.
(r containsRect: r2) ifTrue: [
aCanvas
fillRectangle: r2
color: c ]]]."
fontToUse _ FontFamily defaultFamilyAndPointSize.
aCanvas drawString: xMin printString at: 40@(extent y - 16) font: fontToUse color: Color black.
aCanvas drawString: xMax printString at: extent -(32@16) font: fontToUse color: Color black.
aCanvas drawString: yMin printString at: 4@(extent y - 32) font: fontToUse color: Color black.
aCanvas drawString: yMax printString at: 4@4 font: fontToUse color: Color black.! !
!FunctionGraphMorph methodsFor: 'drawing' stamp: 'jmv 4/21/2020 20:25:25'!
iterate: aBlock
| y |
functions with: colors do: [ :f :c |
xMin asFloat to: xMax count: extent x do: [ :x |
y _ [ f value: x ] on: Error do: [].
aBlock value: x value: y asFloat value: c ]]! !
!FunctionGraphMorph methodsFor: 'initialization' stamp: 'pb 5/27/2019 18:19:57'!
initialize
super initialize.
extent _ 320@240.
functions _ OrderedCollection new.
colors _ OrderedCollection new.
yRangeInvalid := true! !
!FunctionGraphMorph methodsFor: 'initialization' stamp: 'pb 5/27/2019 18:19:17'!
invalidateYRange
yRangeInvalid := true! !
!FunctionGraphMorph methodsFor: 'geometry' stamp: 'jmv 5/17/2015 09:20'!
toMorphic: aPoint
^(self xToMorphic: aPoint x) @ (self yToMorphic: aPoint y)! !
!FunctionGraphMorph methodsFor: 'geometry' stamp: 'jmv 11/25/2016 11:03:22'!
xToMorphic: x
^x - xMin / (xMax - xMin ) * (extent x-40)+40! !
!FunctionGraphMorph methodsFor: 'geometry' stamp: 'jmv 11/25/2016 11:03:27'!
yToMorphic: y
^yMax - y / (yMax - yMin ) * (extent y-20)! !
!FunctionGraphMorph class methodsFor: 'instance creation' stamp: 'jmv 7/20/2016 10:00:31'!
initializedInstance
"
self initializedInstance openInWorld
"
| g |
g _ FunctionGraphMorph new.
g domain: (-4 to: 4).
g addFunction: [ :x | x cos ] color: Color green.
g addFunction: [ :x | (x + 1) squared - 3 ] color: Color red. "parabola with vertex at (-1,-3)"
^ g! !
!MagnifierMorph methodsFor: 'menu' stamp: 'di 9/28/1999 23:06'!
addCustomMenuItems: aCustomMenu hand: aHandMorph
super addCustomMenuItems: aCustomMenu hand: aHandMorph.
aCustomMenu
addLine;
add: 'magnification...' action: #chooseMagnification;
addUpdating: #trackingPointerString action: #toggleTrackingPointer;
addUpdating: #toggleRoundString action: #toggleRoundness.! !
!MagnifierMorph methodsFor: 'menu' stamp: 'jmv 8/21/2012 21:53'!
chooseMagnification
| result |
result _ (SelectionMenu selections: #(1.5 2 4 8))
startUpWithCaption: 'Choose magnification
(currently ', magnification printString, ')'.
(result == nil or: [ result = magnification ]) ifTrue: [ ^ self ].
magnification _ result.
self morphExtent: extent. "round to new magnification"
self redrawNeeded. "redraw even if extent wasn't changed"! !
!MagnifierMorph methodsFor: 'menu' stamp: 'jmv 9/22/2012 15:35'!
chooseMagnification: evt
| handle origin aHand currentMag |
currentMag _ magnification.
aHand _ evt ifNil: [ self world activeHand ] ifNotNil: [evt hand].
origin _ aHand morphPosition y.
handle _ HandleMorph new forEachPointDo:
[ :newPoint | self magnification: (newPoint y - origin) / 8.0 + currentMag ].
aHand attachMorph: handle.
handle startStepping.
self redrawNeeded. ! !
!MagnifierMorph methodsFor: 'menu' stamp: 'bf 9/20/1999 15:48'!
toggleTrackingPointer
trackPointer _ trackPointer not! !
!MagnifierMorph methodsFor: 'menu' stamp: 'bf 9/20/1999 15:49'!
trackingPointerString
^trackPointer
ifTrue: ['stop tracking pointer']
ifFalse: ['start tracking pointer']! !
!MagnifierMorph methodsFor: 'geometry' stamp: 'jmv 8/28/2021 19:34:31'!
borderWidth: anInteger
"Grow outwards preserving innerBounds"
super borderWidth: anInteger.
self morphExtent: self defaultExtent.! !
!MagnifierMorph methodsFor: 'geometry' stamp: 'bf 9/21/1999 09:22'!
defaultExtent
^(srcExtent * magnification) truncated + (2 * borderWidth)! !
!MagnifierMorph methodsFor: 'geometry' stamp: 'jmv 6/6/2014 18:06'!
privateExtent: aPoint
"Round to multiples of magnification"
srcExtent _ (aPoint - (2 * borderWidth)) // magnification.
^ super privateExtent: self defaultExtent! !
!MagnifierMorph methodsFor: 'initialization' stamp: 'jmv 12/2/2011 10:20'!
defaultBorderWidth
"answer the default border width for the receiver"
^ 1! !
!MagnifierMorph methodsFor: 'initialization' stamp: 'jmv 9/13/2013 10:02'!
initialize
super initialize.
trackPointer _ true.
magnification _ 2.
self morphExtent: 128@128! !
!MagnifierMorph methodsFor: 'drawing' stamp: 'jmv 10/15/2020 15:44:41'!
drawOn: aCanvas
RecursionLock == self ifFalse: [
super drawOn: aCanvas. "border and fill"
self magnifiedForm ifNotNil: [ :f |
aCanvas image: f at: borderWidth@borderWidth ]]! !
!MagnifierMorph methodsFor: 'event handling testing' stamp: 'jmv 1/17/2013 17:27'!
handlesMouseDown: aMouseButtonEvent
^aMouseButtonEvent mouseButton2Pressed! !
!MagnifierMorph methodsFor: 'round view' stamp: 'jmv 12/10/2010 09:25'!
isRound
^ "owner isMemberOf: ScreeningMorph" false! !
!MagnifierMorph methodsFor: 'round view' stamp: 'di 9/28/1999 23:17'!
toggleRoundString
^ self isRound
ifTrue: ['be square']
ifFalse: ['be round']! !
!MagnifierMorph methodsFor: 'round view' stamp: 'jmv 12/11/2011 23:35'!
toggleRoundness
| |
" w _ self world.
self isRound
ifTrue: [owner delete.
w addMorph: self]
ifFalse: [sm _ ScreeningMorph new position: self zzposition.
sm addMorph: self.
sm addMorph: (EllipseMorph newBounds: self bounds).
w addMorph: sm]
"! !
!MagnifierMorph methodsFor: 'magnifying' stamp: 'jmv 8/28/2021 19:34:57'!
magnification: aNumber
magnification _ aNumber min: 8 max: 0.5.
magnification _ magnification roundTo:
(magnification < 3 ifTrue: [0.5] ifFalse: [1]).
srcExtent _ srcExtent min: (512@512) // magnification. "to prevent accidents"
self morphExtent: self defaultExtent.! !
!MagnifierMorph methodsFor: 'magnifying' stamp: 'jmv 8/26/2021 17:39:10'!
magnifiedForm
| srcRect form neededExtent |
self displayBounds ifNil: [ ^nil ].
lastPos _ self sourcePoint.
srcRect _ self sourceRectFrom: lastPos.
((srcRect intersects: self displayBounds) and: [ RecursionLock == nil ])
ifTrue: [
RecursionLock _ self.
"try to reuse form if appropriate"
auxCanvas _ (auxCanvas notNil and: [ auxCanvas extent = srcExtent ])
ifTrue: [
"Just in case we go out of the Display"
srcRect origin > (0@0) ifFalse: [
auxCanvas form fillBlack ].
BitBltCanvas onForm: auxCanvas form over: srcRect ]
ifFalse: [ BitBltCanvas depth: 32 over: srcRect ].
auxCanvas fullDraw: self world.
form _ auxCanvas form.
RecursionLock _ nil]
ifFalse: [
"cheaper method if the source is not occluded"
form _ Display copy: srcRect].
"smooth if non-integer scale"
neededExtent _ (srcExtent * magnification ) truncated.
(magnifiedForm isNil or: [ magnifiedForm extent ~= neededExtent ])
ifTrue: [ magnifiedForm _ Form extent: neededExtent depth: 32 ].
(WarpBlt toForm: magnifiedForm)
sourceForm: form;
colorMap: (form colormapIfNeededFor: magnifiedForm);
cellSize: (magnification isInteger ifTrue: [1] ifFalse: [2]); "installs a new colormap if cellSize > 1"
combinationRule: 3;
copyQuad: form boundingBox innerCorners toRect: magnifiedForm boundingBox.
^magnifiedForm.! !
!MagnifierMorph methodsFor: 'magnifying' stamp: 'jmv 10/15/2020 15:40:20'!
sourcePoint
"If we are being dragged use our center, otherwise use pointer position"
(trackPointer not or: [owner notNil and: [owner is: #HandMorph]])
ifTrue: [ self displayBounds ifNotNil: [ :r | ^r center ]].
^self world activeHand morphPosition! !
!MagnifierMorph methodsFor: 'magnifying' stamp: 'jmv 8/4/2012 16:41'!
sourceRect
"world global coordinates, etc"
self flag: #jmvVer2.
^self sourceRectFrom: self sourcePoint! !
!MagnifierMorph methodsFor: 'magnifying' stamp: 'jmv 8/17/2012 18:52'!
sourceRectFrom: aPoint
^ (aPoint extent: srcExtent) translatedBy: (srcExtent // -2) + 1.
! !
!MagnifierMorph methodsFor: 'events' stamp: 'jmv 1/14/2013 22:45'!
mouseButton2Down: aMouseButtonEvent localPosition: localEventPosition
self chooseMagnification: aMouseButtonEvent! !
!MagnifierMorph methodsFor: 'stepping' stamp: 'jmv 2/27/2016 19:53'!
stepAt: millisecondSinceLast
self redrawNeeded! !
!MagnifierMorph methodsFor: 'stepping' stamp: 'jmv 6/11/2012 23:32'!
stepTime
"Update very often. Very short steptimes should only be used for morphs that are not stepping all the time!!"
^ 20! !
!MagnifierMorph methodsFor: 'stepping' stamp: 'jmv 6/11/2012 09:58'!
wantsSteps
"Return true if the receiver wants to its #step or #stepAt: methods be run ALL THE TIME.
Morphs that send #startStepping and #stopStepping at appropriate times (i.e. when they are already in the world!!) don't need to answer true to this message"
^true! !
!MinimalStringMorph methodsFor: 'accessing' stamp: 'jmv 6/6/2014 10:58'!
contents: newContents
contents _ (newContents is: #Text)
ifTrue: [
emphasis := newContents emphasisAt: 1.
newContents string]
ifFalse: [
contents = newContents ifTrue: [^self]. "no substantive change"
newContents].
self fitContents.
self redrawNeeded! !
!MinimalStringMorph methodsFor: 'accessing' stamp: 'jmv 1/1/2015 21:16'!
fitContents
"Measures contents later at #minimumExtent"
self morphExtent: 0@0! !
!MinimalStringMorph methodsFor: 'accessing' stamp: 'jmv 6/11/2020 16:49:55'!
fontToUse
| fontToUse |
fontToUse := font ifNil: [FontFamily defaultFamilyAndPointSize].
^(emphasis isNil or: [emphasis = 0])
ifTrue: [fontToUse]
ifFalse: [fontToUse emphasized: emphasis]! !
!MinimalStringMorph methodsFor: 'accessing' stamp: 'jmv 4/25/2019 10:09:59'!
measureContents
| f |
f _ self fontToUse.
^(((f widthOfString: contents) max: 3) @ f lineSpacing).! !
!MinimalStringMorph methodsFor: 'initialization' stamp: 'cbr 12/3/2010 23:29'!
defaultColor
"answer the default color/fill style for the receiver"
^ Theme current text! !
!MinimalStringMorph methodsFor: 'initialization' stamp: 'jmv 9/10/2010 22:55'!
initWithContents: aString font: aFont emphasis: emphasisCode
self initialize.
font _ aFont.
emphasis _ emphasisCode.
self contents: aString! !
!MinimalStringMorph methodsFor: 'initialization' stamp: 'jmv 9/10/2010 22:55'!
initialize
super initialize.
font _ nil.
emphasis _ 0! !
!MinimalStringMorph methodsFor: 'drawing' stamp: 'jmv 7/10/2014 22:41'!
drawOn: aCanvas
aCanvas drawString: contents at: 0@0 font: self fontToUse color: color! !
!MinimalStringMorph class methodsFor: 'instance creation' stamp: 'jmv 4/3/2011 22:34'!
contents: aString
" 'StringMorph contents: str' is faster than 'StringMorph new contents: str'
(MinimalStringMorph contents: 'Some string') openInWorld
"
^ self contents: aString font: nil! !
!MinimalStringMorph class methodsFor: 'instance creation' stamp: 'jmv 11/4/2008 12:56'!
contents: aString font: aFont
^ self basicNew initWithContents: aString font: aFont emphasis: 0! !
!MinimalStringMorph class methodsFor: 'instance creation' stamp: 'jmv 11/4/2008 12:56'!
contents: aString font: aFont emphasis: emphasisCode
^ self basicNew initWithContents: aString font: aFont emphasis: emphasisCode! !
!MinimalStringMorph class methodsFor: 'instance creation' stamp: 'jmv 4/3/2011 22:34'!
new
^self contents: 'some string'! !
!OneLineEditorMorph methodsFor: 'accessing' stamp: 'jmv 6/11/2020 16:50:03'!
baseFont
font ifNil: [ font _ FontFamily defaultFamilyAndPointSize ].
^font! !
!OneLineEditorMorph methodsFor: 'accessing' stamp: 'jmv 3/16/2011 10:34'!
contents
^contents! !
!OneLineEditorMorph methodsFor: 'accessing' stamp: 'jmv 3/16/2011 10:41'!
contents: newContents
contents _ (newContents is: #Text)
ifTrue: [
emphasis := newContents emphasisAt: 1.
newContents string]
ifFalse: [
contents = newContents ifTrue: [^self]. "no substantive change"
newContents].
editor _ nil.
self fitContents.
self redrawNeeded! !
!OneLineEditorMorph methodsFor: 'accessing' stamp: 'jmv 1/5/2013 14:23'!
crAction
"Answer the optional Cr action"
^crAction! !
!OneLineEditorMorph methodsFor: 'accessing' stamp: 'jmv 1/5/2013 14:24'!
crAction: aBlock
crAction := aBlock! !
!OneLineEditorMorph methodsFor: 'accessing' stamp: 'jmv 9/6/2017 10:02:09'!
disableEditing
self setProperty: #disablesEditing toValue: true.
self stopBlinking! !
!OneLineEditorMorph methodsFor: 'accessing' stamp: 'jmv 12/4/2011 22:25'!
editor
"Return my current editor, or install a new one."
editor ifNil: [ self installEditor ].
^editor! !
!OneLineEditorMorph methodsFor: 'accessing' stamp: 'jmv 1/1/2015 21:16'!
fitContents
"Measures contents later at #minimumExtent"
self morphExtent: 0@0! !
!OneLineEditorMorph methodsFor: 'accessing' stamp: 'jmv 11/5/2008 13:18'!
fontToUse
^ (emphasis isNil or: [emphasis = 0])
ifTrue: [ self baseFont ]
ifFalse: [ self baseFont emphasized: emphasis ]! !
!OneLineEditorMorph methodsFor: 'accessing' stamp: 'jmv 3/17/2011 07:58'!
keyboardFocusWatcher: aMorph
"We are usually used as a part of a bigger morph.
Usually, that morph would be interested in us changing keyboard focus.
An alternative implementation would be to define a new type of event, but:
- I (jmv) prefer explicit message sends to registering in events.
- There are too many evens already defined. It would be good to reduce that."
keyboardFocusWatcher _ aMorph! !
!OneLineEditorMorph methodsFor: 'accessing' stamp: 'jmv 4/25/2019 10:10:16'!
measureContents
| f |
f _ self fontToUse.
^((f widthOfString: contents) max: 3) @ f lineSpacing.! !
!OneLineEditorMorph methodsFor: 'drawing' stamp: 'KenD 12/7/2023 09:06:36'!
characterIndexAtPoint: aPoint
| line block f |
f := self fontToUse.
line := TextLine
start: 1
stop: contents size
internalSpaces: 0
paddingWidth: 0.
line
rectangle: (0@0 extent: extent);
lineHeight: f lineSpacing baseline: f ascent.
block := (CharacterBlockScanner new text: (contents asText font: f))
defaultFont: f;
characterBlockAtPoint: aPoint in: line forCursorPosition: false.
^ block stringIndex! !
!OneLineEditorMorph methodsFor: 'drawing' stamp: 'jmv 10/16/2013 22:37'!
displayTextCursorAtX: x top: top bottom: bottom emphasis: anEmphasis on: aCanvas
| textCursorColor x1 isBold isItalic x0 h w halfW r d |
isBold _ anEmphasis allMask: 1.
isItalic _ anEmphasis allMask: 2.
textCursorColor _ Theme current textCursor.
h _ bottom - top.
w _ isBold
ifTrue: [ h // 25 + 2 ]
ifFalse: [ h // 30 + 1 ].
halfW _ w // 2.
isItalic
ifTrue: [
"Keep tweaking if needed!!"
d _ isBold ifTrue: [ 3 ] ifFalse: [ h // 24].
x0 _ x- (h*5//24) + d.
x1 _ x + d ]
ifFalse: [
x0 _ x.
x1 _ x].
x0 < halfW ifTrue: [
x1 _ x1 - x0 + halfW.
x0 _ halfW ].
r _ extent x-halfW-1.
r < x1 ifTrue: [
x0 _ x0 + r - x1.
x1 _ r ].
textCursorRect _ x0-halfW-1@ top corner: x1+halfW+1+1 @ bottom.
aCanvas
line: x0+halfW@bottom to: x1+halfW@(top+w)
width: w color: textCursorColor! !
!OneLineEditorMorph methodsFor: 'drawing' stamp: 'KenD 10/23/2020 13:50:33'!
drawOn: aCanvas
self hasSelection ifTrue: [ self drawSelectionOn: aCanvas ].
self hasTextCursor ifTrue: [ self drawTextCursorOn: aCanvas ].
aCanvas
drawString: contents
at: 0@0 + borderWidth
font: self fontToUse
color: color.
(borderWidth > 0) ifTrue: [
aCanvas
frameRectangle: (0@0 extent: extent)
color: borderColor
borderWidth: borderWidth
borderStyleSymbol: #simple ]! !
!OneLineEditorMorph methodsFor: 'drawing' stamp: 'jmv 4/25/2019 10:07:24'!
drawSelectionOn: aCanvas
| rightX leftX bottom |
bottom _ self baseFont lineSpacing.
leftX _ self fontToUse widthOfString: contents from: 1 to: editor startIndex-1.
leftX _ leftX min: extent x.