/
VMWorldRenderer.class.st
201 lines (144 loc) · 5.09 KB
/
VMWorldRenderer.class.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
"
I know how to render the world using the VM backend.
"
Class {
#name : #VMWorldRenderer,
#superclass : #AbstractWorldRenderer,
#instVars : [
'display',
'canvas'
],
#category : #'Morphic-Core-Worlds'
}
{ #category : #accessing }
VMWorldRenderer class >> isApplicableFor: aWorld [
^ Smalltalk isHeadless not
]
{ #category : #accessing }
VMWorldRenderer class >> priority [
^ 1
]
{ #category : #operations }
VMWorldRenderer >> activateCursor: aCursor withMask: maskForm [
aCursor beCursorWithMask: maskForm
]
{ #category : #accessing }
VMWorldRenderer >> actualScreenSize [
<primitive: 106>
self primitiveFailed
]
{ #category : #'display box access' }
VMWorldRenderer >> assuredCanvas [
(self canvas isNil
or: [ self canvas extent ~= self viewBox extent
or: [ self canvas form depth ~= Display depth ] ])
ifTrue:
[ "allocate a new offscreen canvas the size of the window"
self canvas: (Display defaultCanvasClass extent: self viewBox extent) ].
^ self canvas
]
{ #category : #accessing }
VMWorldRenderer >> canvas [
^ canvas
]
{ #category : #accessing }
VMWorldRenderer >> canvas: x [
canvas := x
]
{ #category : #'display box access' }
VMWorldRenderer >> checkForNewScreenSize [
"Check whether the screen size has changed and if so take appropriate actions"
Display extent = DisplayScreen actualScreenSize ifTrue: [^ Display].
Display setExtent: self actualScreenSize depth: 32.
Display beDisplay.
world restoreMorphicDisplay.
]
{ #category : #activation }
VMWorldRenderer >> deactivate [
InputEventSensor default shutDown.
Display shutDown.
InputEventFetcher default shutDown.
]
{ #category : #operations }
VMWorldRenderer >> deferUpdates: aValue [
^ Display deferUpdates: aValue
]
{ #category : #operations }
VMWorldRenderer >> displayWorldState: aWorldState ofWorld: aWorld submorphs: submorphs [
"Update this world's display."
| deferredUpdateMode handsToDraw allDamage |
submorphs do: [ :m | m fullBounds ]. "force re-layout if needed"
aWorldState checkIfUpdateNeeded
ifFalse: [ ^ self ]. "display is already up-to-date"
deferredUpdateMode := self doDeferredUpdatingFor: aWorld.
deferredUpdateMode
ifFalse: [ self assuredCanvas ].
self canvas
ifNotNil: [
self canvas
roundCornersOf: aWorld
during: [ | worldDamageRects handDamageRects |
worldDamageRects := aWorldState drawWorld: aWorld submorphs: submorphs invalidAreasOn: self canvas. "repair world's damage on canvas"
"self handsDo:[:h| h noticeDamageRects: worldDamageRects]."
handsToDraw := aWorldState selectHandsToDrawForDamage: worldDamageRects.
handDamageRects := handsToDraw collect: [ :h | h savePatchFrom: self canvas ].
allDamage := worldDamageRects , handDamageRects.
handsToDraw reverseDo: [ :h | "draw hands onto world canvas" self canvas fullDrawMorph: h ] ] ].
"*make this true to flash damaged areas for testing*"
aWorldState class debugShowDamage
ifTrue: [ aWorld flashRects: allDamage color: Color black ].
"Check that the canvas is not already freed when we want to finish it"
self canvas ifNotNil: [ :c | c finish ].
"quickly copy altered rects of canvas to Display:"
deferredUpdateMode
ifTrue: [ self forceDamageToScreen: allDamage ]
ifFalse: [ self canvas showAt: aWorld viewBox origin invalidRects: allDamage ].
handsToDraw do: [ :h | h restoreSavedPatchOn: self canvas ]. "restore world canvas under hands"
self
deferUpdates: false;
forceDisplayUpdate
]
{ #category : #activation }
VMWorldRenderer >> doActivate [
InputEventFetcher default startUp.
InputEventSensor installMouseDecodeTable.
InputEventSensor default startUp.
Display setExtent: self actualScreenSize depth: 32.
Display beDisplay.
canvas := nil.
display := nil.
self assuredCanvas.
DisplayScreen refreshHostWindowTitle.
Display forceDisplayUpdate.
world displayWorld.
]
{ #category : #operations }
VMWorldRenderer >> doDeferredUpdatingFor: aWorld [
"If this platform supports deferred updates, then make my canvas be the Display (or a rectangular portion of it), set the Display to deferred update mode, and answer true. Otherwise, do nothing and answer false. One can set the class variable DisableDeferredUpdates to true to completely disable the deferred updating feature."
(Display deferUpdates: true) ifNil: [^ false]. "deferred updates not supported"
(self canvas notNil and: [self canvas form == Display]) ifFalse: [
aWorld viewBox: self viewBox. "do first since it may clear canvas"
self canvas: (Display getCanvas copyClipRect: Display boundingBox)].
^ true
]
{ #category : #operations }
VMWorldRenderer >> forceDamageToScreen: allDamage [
^ Display forceDamageToScreen: allDamage.
]
{ #category : #operations }
VMWorldRenderer >> forceDisplayUpdate [
^ Display forceDisplayUpdate
]
{ #category : #operations }
VMWorldRenderer >> fullscreenMode: aValue [
Display fullscreenMode: aValue.
self checkForNewScreenSize.
]
{ #category : #'display box access' }
VMWorldRenderer >> usableArea [
^ Display usableArea
]
{ #category : #'display box access' }
VMWorldRenderer >> viewBox [
^ Display boundingBox
]