author | Claus Gittinger <cg@exept.de> |
Wed, 22 Aug 2018 12:58:11 +0200 | |
changeset 8451 | 6eafe0433763 |
parent 8439 | 2e6fff05e9d7 |
child 8611 | 02dd0ea7a038 |
permissions | -rw-r--r-- |
8439 | 1 |
"{ Encoding: utf8 }" |
2 |
||
732 | 3 |
" |
4 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
3275 | 14 |
"{ Package: 'stx:libview' }" |
15 |
||
6746
e63784ff3863
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6711
diff
changeset
|
16 |
"{ NameSpace: Smalltalk }" |
e63784ff3863
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6711
diff
changeset
|
17 |
|
732 | 18 |
GraphicsContext subclass:#DeviceGraphicsContext |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
19 |
instanceVariableNames:'drawableId gcId deviceFont foreground background drawableType |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
20 |
parentId' |
7443 | 21 |
classVariableNames:'CachedScaledForms CachedScales' |
732 | 22 |
poolDictionaries:'' |
23 |
category:'Graphics-Support' |
|
24 |
! |
|
25 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
26 |
DeviceHandle subclass:#DevicePixmapGCHandle |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
27 |
instanceVariableNames:'' |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
28 |
classVariableNames:'' |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
29 |
poolDictionaries:'' |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
30 |
privateIn:DeviceGraphicsContext |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
31 |
! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
32 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
33 |
DeviceHandle subclass:#DeviceWindowGCHandle |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
34 |
instanceVariableNames:'parentId' |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
35 |
classVariableNames:'' |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
36 |
poolDictionaries:'' |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
37 |
privateIn:DeviceGraphicsContext |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
38 |
! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
39 |
|
1085
3513a4cae87b
handle depth1-images with a mask
Claus Gittinger <cg@exept.de>
parents:
1064
diff
changeset
|
40 |
!DeviceGraphicsContext class methodsFor:'documentation'! |
732 | 41 |
|
42 |
copyright |
|
43 |
" |
|
44 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
45 |
All Rights Reserved |
|
46 |
||
47 |
This software is furnished under a license and may be used |
|
48 |
only in accordance with the terms of that license and with the |
|
49 |
inclusion of the above copyright notice. This software may not |
|
50 |
be provided or otherwise made available to, or used by, any |
|
51 |
other person. No title to or ownership of the software is |
|
52 |
hereby transferred. |
|
53 |
" |
|
54 |
! |
|
55 |
||
56 |
documentation |
|
57 |
" |
|
58 |
I provide the common protocol for a graphicsContext which is associated with a particular |
|
6292 | 59 |
device (i.e. Bitmaps, Pixmaps, RootWindow and Windows in Xs world, but also postscript |
732 | 60 |
printer pages or fax pages). |
61 |
||
62 |
My instance variables are mainly caching device-related stuff (such as font- and color-Ids) |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
63 |
to avoid needless message traffic. |
732 | 64 |
All real work is done by my device, which is accessed via the device instance variable. |
6292 | 65 |
Most drawing requests are simply forwarded to it, others are simulated by using more basic |
732 | 66 |
drawing functions (see GraphicsContext drawing vs. basic drawing category). |
67 |
||
6292 | 68 |
The added variables foreground/background are the drawing colors actually |
732 | 69 |
used; these are the real (i.e. non dithered) colors supported by the device. |
6292 | 70 |
Direct access to fg/bg is discouraged, since in the future, these may be |
71 |
totally replaced by paint/bgPaint |
|
72 |
(there are some operations and special cases, for which a direct access to |
|
732 | 73 |
fg/bg makes sense) |
74 |
||
75 |
[Instance variables:] |
|
76 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
77 |
drawableId <SmallInteger> my drawableId on the device (a device handle) |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
78 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
79 |
gcId <SmallInteger> my gc's ID on the device (a device handle) |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
80 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
81 |
deviceFont <Font> the actual font, currently set in the device |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
82 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
83 |
foreground <Color> the device foreground color used for drawing |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
84 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
85 |
background <Color> the device background color used for drawing |
732 | 86 |
|
87 |
[see also:] |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
88 |
DeviceWorkstation |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
89 |
Color Font Cursor |
732 | 90 |
|
91 |
[author:] |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
92 |
Claus Gittinger |
732 | 93 |
|
94 |
" |
|
95 |
! ! |
|
96 |
||
1085
3513a4cae87b
handle depth1-images with a mask
Claus Gittinger <cg@exept.de>
parents:
1064
diff
changeset
|
97 |
!DeviceGraphicsContext class methodsFor:'instance creation'! |
732 | 98 |
|
99 |
new |
|
100 |
"create a new drawable - take the current display as |
|
101 |
its device (for now, this may be changed until the view is |
|
102 |
physically created)" |
|
103 |
||
104 |
" |
|
105 |
'Warning: DeviceGraphicsContext (' print. self name print. ') should not be created with new' printNL. |
|
106 |
" |
|
6290
b6886e346ae9
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6273
diff
changeset
|
107 |
|device| |
b6886e346ae9
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6273
diff
changeset
|
108 |
|
b6886e346ae9
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6273
diff
changeset
|
109 |
device := Screen current. |
b6886e346ae9
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6273
diff
changeset
|
110 |
device isNil ifTrue:[ |
8312 | 111 |
(self class name,' [warning]: no Display') infoPrintCR. |
112 |
device := Smalltalk lateOpenDisplay. |
|
113 |
device isNil ifTrue:[ |
|
114 |
Screen deviceOpenErrorSignal raiseErrorString:'no screen device'. |
|
115 |
] |
|
6290
b6886e346ae9
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6273
diff
changeset
|
116 |
]. |
6926 | 117 |
^ self onDevice:device |
8312 | 118 |
|
119 |
"Modified: / 20-03-2018 / 12:46:25 / stefan" |
|
732 | 120 |
! |
121 |
||
122 |
on:aDevice |
|
123 |
"create a new drawable on aDevice" |
|
124 |
||
3429 | 125 |
<resource:#obsolete> |
126 |
||
1741 | 127 |
"/ send out a warning: #on: is typically used to create a view |
128 |
"/ operating on a model. |
|
129 |
"/ Please use #onDevice: to avoid confusion. |
|
130 |
||
1255 | 131 |
self obsoleteMethodWarning:'use #onDevice:'. |
732 | 132 |
^ self onDevice:aDevice |
1255 | 133 |
|
1741 | 134 |
"Modified: 5.6.1997 / 21:04:16 / cg" |
732 | 135 |
! |
136 |
||
137 |
onDevice:aDevice |
|
138 |
"create a new drawable on aDevice" |
|
139 |
||
140 |
|newDrawable| |
|
141 |
||
142 |
newDrawable := self basicNew. |
|
143 |
||
144 |
" |
|
6292 | 145 |
set display before its initialized |
732 | 146 |
- so it can do something useful (i.e. get font sizes etc.) in its |
8027 | 147 |
initialize method(s) |
732 | 148 |
" |
149 |
newDrawable device:aDevice. |
|
150 |
newDrawable initialize. |
|
151 |
^ newDrawable |
|
1517
ac751bb3dfdf
no need for registration here;
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
152 |
|
8027 | 153 |
"Modified: / 02-04-1997 / 19:19:35 / cg" |
154 |
"Modified (comment): / 17-05-2017 / 15:13:23 / mawalch" |
|
732 | 155 |
! ! |
156 |
||
1085
3513a4cae87b
handle depth1-images with a mask
Claus Gittinger <cg@exept.de>
parents:
1064
diff
changeset
|
157 |
!DeviceGraphicsContext class methodsFor:'cleanup'! |
732 | 158 |
|
159 |
lowSpaceCleanup |
|
160 |
CachedScaledForms := CachedScales := nil |
|
161 |
! ! |
|
162 |
||
163 |
!DeviceGraphicsContext methodsFor:'accessing'! |
|
164 |
||
165 |
at:aPoint |
|
166 |
"return the pixel at the coordinate given by aPoint" |
|
167 |
||
3160 | 168 |
^ self atX:aPoint x y:aPoint y |
169 |
||
170 |
"Modified: / 29.1.2000 / 12:17:42 / cg" |
|
732 | 171 |
! |
172 |
||
4204 | 173 |
at:aPoint put:aPixelColor |
732 | 174 |
"set a pixel" |
175 |
||
4204 | 176 |
^ self atX:aPoint x y:aPoint y put:aPixelColor |
177 |
||
178 |
" |
|
179 |
Display rootView at:(0@0) put:(Color red). |
|
180 |
Display rootView at:(1@1) put:(Color red). |
|
181 |
Display rootView at:(2@2) put:(Color red). |
|
182 |
Display rootView at:(3@3) put:(Color red). |
|
183 |
Display rootView at:(4@4) put:(Color red). |
|
184 |
Display rootView at:(5@5) put:(Color red). |
|
185 |
" |
|
732 | 186 |
! |
187 |
||
188 |
atX:x y:y |
|
189 |
"return the pixel at the coordinate given by x/y" |
|
190 |
||
2714
e5d16e41cbab
need gcId-argument in getPixel
Claus Gittinger <cg@exept.de>
parents:
2680
diff
changeset
|
191 |
^ device getPixelX:x y:y from:drawableId with:gcId |
e5d16e41cbab
need gcId-argument in getPixel
Claus Gittinger <cg@exept.de>
parents:
2680
diff
changeset
|
192 |
|
e5d16e41cbab
need gcId-argument in getPixel
Claus Gittinger <cg@exept.de>
parents:
2680
diff
changeset
|
193 |
"Modified: / 22.5.1999 / 01:40:23 / cg" |
732 | 194 |
! |
195 |
||
4204 | 196 |
atX:x y:y put:aPixelColor |
732 | 197 |
"set a pixel" |
198 |
||
199 |
|oldFg| |
|
200 |
||
201 |
oldFg := foreground. |
|
4204 | 202 |
self foreground:aPixelColor. |
732 | 203 |
self displayPointX:x y:y. |
204 |
self foreground:oldFg |
|
205 |
! |
|
206 |
||
207 |
backgroundPaint:aColor |
|
208 |
"set the background-paint color; this is used in opaque-draw |
|
209 |
operations" |
|
210 |
||
211 |
(aColor ~~ bgPaint) ifTrue:[ |
|
6292 | 212 |
aColor notNil ifTrue:[ |
213 |
bgPaint := aColor. |
|
214 |
gcId notNil ifTrue:[ |
|
215 |
bgPaint isColor ifTrue:[ |
|
216 |
bgPaint := aColor onDevice:device. |
|
217 |
bgPaint colorId notNil ifTrue:[ |
|
218 |
background := bgPaint. |
|
219 |
gcId notNil ifTrue:[ |
|
220 |
device setBackground:(bgPaint colorId) in:gcId. |
|
221 |
]. |
|
222 |
^ self |
|
223 |
] |
|
224 |
]. |
|
225 |
self paint:paint on:aColor |
|
226 |
] |
|
227 |
] |
|
732 | 228 |
]. |
229 |
! |
|
230 |
||
231 |
basicFont:aFont |
|
7560 | 232 |
"compatibility with GraphicsMedium" |
233 |
||
234 |
self font:aFont. |
|
732 | 235 |
! |
236 |
||
237 |
capStyle:aSymbol |
|
238 |
"set the style in which the endpoints of lines |
|
239 |
are drawn - aSymbol may be #notLast, #butt, #round, #projecting" |
|
240 |
||
241 |
|s| |
|
242 |
||
243 |
(s := aSymbol) isNil ifTrue:[ |
|
1029
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
244 |
s := #butt. |
732 | 245 |
|
246 |
]. |
|
247 |
(s ~~ capStyle) ifTrue:[ |
|
1029
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
248 |
capStyle := s. |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
249 |
gcId notNil ifTrue:[ |
6292 | 250 |
device setLineWidth:lineWidth |
1029
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
251 |
style:lineStyle |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
252 |
cap:s |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
253 |
join:joinStyle |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
254 |
in:gcId |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
255 |
] |
732 | 256 |
] |
257 |
||
258 |
"Modified: 12.5.1996 / 22:23:03 / cg" |
|
259 |
! |
|
260 |
||
950 | 261 |
clippedByChildren:aBoolean |
262 |
"turn on/off drawing over children. |
|
263 |
If on, a superview may draw 'over' its children. |
|
264 |
If off (the default), drawing is 'under' its children. |
|
265 |
Only useful for the rootView, to draw over any visible views. |
|
266 |
(for example, when dragging a rubber-line)" |
|
267 |
||
268 |
gcId isNil ifTrue:[ |
|
6292 | 269 |
self initGC |
950 | 270 |
]. |
1715 | 271 |
device noClipIn:drawableId gc:gcId. |
272 |
device setClipByChildren:aBoolean in:drawableId gc:gcId. |
|
950 | 273 |
|
274 |
"Created: 17.7.1996 / 13:25:16 / cg" |
|
1680
f47862c358fb
pass both drawableId & gcID to setClipByChildren
Claus Gittinger <cg@exept.de>
parents:
1649
diff
changeset
|
275 |
"Modified: 29.4.1997 / 15:33:55 / dq" |
950 | 276 |
! |
277 |
||
6215 | 278 |
clippingBounds:aRectangleOrNil |
732 | 279 |
"set the clipping rectangle for drawing (in logical coordinates); |
280 |
a nil argument turn off clipping (i.e. whole view is drawable)" |
|
281 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
282 |
|x y w h newBounds| |
7066 | 283 |
|
284 |
aRectangleOrNil isNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
285 |
clipRect isNil ifTrue:[^ self]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
286 |
gcId notNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
287 |
device noClipIn:drawableId gc:gcId |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
288 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
289 |
clipRect := nil. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
290 |
^ self. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
291 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
292 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
293 |
x := aRectangleOrNil left. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
294 |
y := aRectangleOrNil top. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
295 |
w := aRectangleOrNil width. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
296 |
h := aRectangleOrNil height. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
297 |
transformation notNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
298 |
x := transformation applyToX:x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
299 |
y := transformation applyToY:y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
300 |
w := transformation applyScaleX:w. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
301 |
h := transformation applyScaleY:h. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
302 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
303 |
(x class == SmallInteger) ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
304 |
w := w + (x - x truncated). |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
305 |
x := x truncated |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
306 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
307 |
(y class == SmallInteger) ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
308 |
h := h + (y - y truncated). |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
309 |
y := y truncated |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
310 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
311 |
(w class == SmallInteger) ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
312 |
w := w truncated + 1 |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
313 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
314 |
(h class == SmallInteger) ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
315 |
h := h truncated + 1 |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
316 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
317 |
w := w max:0. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
318 |
h := h max:0. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
319 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
320 |
newBounds := Rectangle left:x top:y width:w height:h. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
321 |
(clipRect notNil and:[clipRect = newBounds]) ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
322 |
^ self |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
323 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
324 |
clipRect := newBounds. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
325 |
gcId notNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
326 |
device setClipX:x y:y width:w height:h in:drawableId gc:gcId. |
6222 | 327 |
]. |
328 |
||
329 |
"Created: / 28.5.1996 / 19:40:20 / cg" |
|
330 |
"Modified: / 16.5.1999 / 19:40:37 / cg" |
|
331 |
! |
|
332 |
||
1842 | 333 |
colorAt:aPoint |
334 |
"return the color of the pixel at the coordinate given by x@y" |
|
335 |
||
336 |
^ self colorAtX:(aPoint x) y:(aPoint y) |
|
337 |
||
338 |
"Modified: 1.8.1997 / 20:01:58 / cg" |
|
339 |
! |
|
340 |
||
341 |
colorAtX:x y:y |
|
342 |
"return the color of the pixel at the coordinate given by aPoint" |
|
343 |
||
344 |
|pixel| |
|
345 |
||
346 |
pixel := self atX:x y:y. |
|
347 |
device getScaledRGBFrom:pixel into:[:r :g :b | |
|
6292 | 348 |
^ Color scaledRed:r scaledGreen:g scaledBlue:b |
1842 | 349 |
]. |
350 |
||
351 |
"Created: 1.8.1997 / 20:01:32 / cg" |
|
352 |
! |
|
353 |
||
4199 | 354 |
container |
355 |
"return my container - for protocol compatibility" |
|
356 |
||
357 |
^ nil |
|
358 |
! |
|
359 |
||
786 | 360 |
dashStyle:aDashList offset:dashOffset |
361 |
"define dashes. Each element of the dashList specifies the length |
|
362 |
of a corresponding dash. For example, setting it to [4 4] |
|
6292 | 363 |
defines 4on-4off dashing; |
786 | 364 |
Setting it to [1 2 4 2] defines 1on-2off-4on-2off dashes. |
365 |
The dashOffset specifies where in the dashList the dashing starts. |
|
366 |
This may not be supported by all graphics devices." |
|
367 |
||
368 |
gcId notNil ifTrue:[ |
|
1029
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
369 |
device setDashes:(ByteArray withAll:aDashList) |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
370 |
dashOffset:dashOffset |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
371 |
in:gcId |
786 | 372 |
] |
373 |
||
374 |
"Modified: 4.6.1996 / 19:03:06 / cg" |
|
375 |
! |
|
376 |
||
732 | 377 |
device |
378 |
"return the device, the receiver is associated with" |
|
379 |
||
380 |
^ device |
|
381 |
! |
|
382 |
||
383 |
device:aDevice |
|
384 |
"set the device" |
|
385 |
||
7443 | 386 |
device == aDevice ifTrue:[ |
387 |
^ self. |
|
388 |
]. |
|
389 |
device notNil ifTrue:[ |
|
390 |
"change of device of an already existing GraphicsContext" |
|
391 |
drawableId notNil ifTrue:[ |
|
392 |
device unregisterGraphicsContext:self. |
|
393 |
]. |
|
394 |
device := aDevice. |
|
395 |
self recreate. |
|
396 |
^ self. |
|
397 |
]. |
|
398 |
||
399 |
"set device of a new GraphicsContext" |
|
732 | 400 |
device := aDevice |
401 |
! |
|
402 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
403 |
deviceClippingBounds:aRectangleOrNil |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
404 |
"set the clipping rectangle for drawing (in device coordinates); |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
405 |
a nil argument turns off clipping (i.e. whole view is drawable - incl. margins)" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
406 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
407 |
clipRect = aRectangleOrNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
408 |
^ self |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
409 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
410 |
clipRect := aRectangleOrNil. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
411 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
412 |
gcId isNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
413 |
^ self. |
7060 | 414 |
]. |
415 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
416 |
aRectangleOrNil isNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
417 |
device noClipIn:drawableId gc:gcId |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
418 |
] ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
419 |
device setClipX:aRectangleOrNil left |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
420 |
y:aRectangleOrNil top |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
421 |
width:aRectangleOrNil width |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
422 |
height:aRectangleOrNil height |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
423 |
in:drawableId |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
424 |
gc:gcId |
7060 | 425 |
]. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
426 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
427 |
"Modified: / 22.5.1996 / 13:12:07 / cg" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
428 |
"Created: / 14.9.1998 / 18:50:31 / cg" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
429 |
! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
430 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
431 |
deviceClippingBoundsOrNil |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
432 |
"get the clipping rectangle for drawing (in device coordinates); |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
433 |
a nil clipping rectangle means: no clipping (i.e. whole view is drawable - incl. margins)" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
434 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
435 |
^ clipRect |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
436 |
! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
437 |
|
7502 | 438 |
deviceFont |
439 |
"return the font for drawing - here, a device font is returned if |
|
440 |
the GC is realized." |
|
441 |
||
442 |
(device notNil and:[font notNil]) ifTrue:[ |
|
443 |
font := font onDevice:device |
|
444 |
]. |
|
445 |
^ font |
|
446 |
! |
|
447 |
||
6222 | 448 |
drawableId |
449 |
"return the id of the drawable on the device" |
|
450 |
||
451 |
^ drawableId |
|
452 |
! |
|
453 |
||
2918
1e777dc8588a
#font answers device font if possible (cg)
Stefan Vogel <sv@exept.de>
parents:
2913
diff
changeset
|
454 |
font |
1e777dc8588a
#font answers device font if possible (cg)
Stefan Vogel <sv@exept.de>
parents:
2913
diff
changeset
|
455 |
"return the font for drawing - here, a device font is returned if |
1e777dc8588a
#font answers device font if possible (cg)
Stefan Vogel <sv@exept.de>
parents:
2913
diff
changeset
|
456 |
the GC is realized." |
1e777dc8588a
#font answers device font if possible (cg)
Stefan Vogel <sv@exept.de>
parents:
2913
diff
changeset
|
457 |
|
7218 | 458 |
(device notNil and:[font notNil]) ifTrue:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
459 |
font := font onDevice:device |
2918
1e777dc8588a
#font answers device font if possible (cg)
Stefan Vogel <sv@exept.de>
parents:
2913
diff
changeset
|
460 |
]. |
1e777dc8588a
#font answers device font if possible (cg)
Stefan Vogel <sv@exept.de>
parents:
2913
diff
changeset
|
461 |
^ font |
1e777dc8588a
#font answers device font if possible (cg)
Stefan Vogel <sv@exept.de>
parents:
2913
diff
changeset
|
462 |
! |
1e777dc8588a
#font answers device font if possible (cg)
Stefan Vogel <sv@exept.de>
parents:
2913
diff
changeset
|
463 |
|
732 | 464 |
font:aFont |
7560 | 465 |
"set the font for drawing if it has changed. |
466 |
This is a low level entry, which is not to be redefined |
|
467 |
(i.e. it must not imply a redraw operation)" |
|
468 |
||
469 |
|id| |
|
470 |
||
471 |
(aFont notNil and:[aFont ~~ font]) ifTrue:[ |
|
472 |
font := aFont. |
|
473 |
device notNil ifTrue:[ |
|
474 |
font := font onDevice:device. |
|
475 |
gcId notNil ifTrue:[ |
|
476 |
id := font fontId. |
|
477 |
id notNil ifTrue:[ |
|
478 |
deviceFont := font. |
|
479 |
device setFont:id in:gcId |
|
480 |
] |
|
481 |
] |
|
482 |
] |
|
732 | 483 |
] |
484 |
||
7560 | 485 |
"Created: / 23-02-1996 / 17:16:51 / cg" |
486 |
"Modified: / 22-10-2006 / 14:11:37 / cg" |
|
732 | 487 |
! |
488 |
||
8296 | 489 |
function:functionSymbol |
490 |
"set the drawing function if it has changed. |
|
491 |
functionSymbol is one of: |
|
492 |
#copy,#copyInverted,#xor,#and,#andReverse |
|
493 |
#andInverted,#or,#orReverse,#orInverted |
|
494 |
#invert,#clear,#set,#noop,#equiv,#nand. |
|
495 |
Notice: not all graphicMedia support all functions" |
|
496 |
||
497 |
(functionSymbol ~~ function) ifTrue:[ |
|
498 |
function := functionSymbol. |
|
499 |
gcId notNil ifTrue:[ |
|
500 |
device setFunction:functionSymbol in:gcId |
|
501 |
] |
|
732 | 502 |
] |
503 |
! |
|
504 |
||
505 |
gcId |
|
7237 | 506 |
"return the receiver's graphic context id on the device" |
732 | 507 |
|
508 |
^ gcId |
|
509 |
! |
|
510 |
||
511 |
id |
|
6222 | 512 |
"return the id of the drawable on the device" |
732 | 513 |
|
514 |
^ drawableId |
|
515 |
! |
|
516 |
||
517 |
joinStyle:aSymbol |
|
518 |
"set the style in which 2 lines are connected in polygons - |
|
519 |
aSymbol may be #miter, #bevel, #round" |
|
520 |
||
521 |
|s| |
|
522 |
||
523 |
(s := aSymbol) isNil ifTrue:[ |
|
1029
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
524 |
s := #miter |
732 | 525 |
]. |
526 |
(s ~~ joinStyle) ifTrue:[ |
|
1029
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
527 |
joinStyle := s. |
6292 | 528 |
|
1029
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
529 |
gcId notNil ifTrue:[ |
6292 | 530 |
device setLineWidth:lineWidth |
1029
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
531 |
style:lineStyle |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
532 |
cap:capStyle |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
533 |
join:s |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
534 |
in:gcId |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
535 |
] |
732 | 536 |
] |
537 |
||
538 |
"Modified: 12.5.1996 / 22:20:43 / cg" |
|
539 |
! |
|
540 |
||
541 |
lineStyle:aSymbol |
|
542 |
"set the style in which lines are drawn - |
|
2360 | 543 |
aSymbol may be #solid, #dashed, #doubleDashed, |
544 |
#dotted, #dashDot or #dashDotDot." |
|
732 | 545 |
|
546 |
|s| |
|
547 |
||
548 |
(s := aSymbol) isNil ifTrue:[ |
|
6292 | 549 |
s := #solid |
732 | 550 |
]. |
551 |
(s ~~ lineStyle) ifTrue:[ |
|
6292 | 552 |
lineStyle := s. |
553 |
gcId notNil ifTrue:[ |
|
554 |
device setLineWidth:lineWidth |
|
555 |
style:s |
|
556 |
cap:capStyle |
|
557 |
join:joinStyle |
|
558 |
in:gcId |
|
559 |
] |
|
732 | 560 |
] |
561 |
||
562 |
"Modified: 12.5.1996 / 22:21:25 / cg" |
|
563 |
! |
|
564 |
||
565 |
lineWidth:aNumber |
|
566 |
"set the line width for drawing if it has changed" |
|
567 |
||
568 |
|n| |
|
569 |
||
570 |
(aNumber ~~ lineWidth) ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
571 |
lineWidth := aNumber. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
572 |
transformation isNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
573 |
n := aNumber. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
574 |
] ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
575 |
n := transformation applyScaleX:aNumber. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
576 |
n := n rounded |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
577 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
578 |
gcId notNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
579 |
device setLineWidth:n style:lineStyle cap:capStyle join:joinStyle in:gcId |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
580 |
] |
732 | 581 |
] |
582 |
! |
|
583 |
||
584 |
mask:aForm |
|
585 |
"set the mask form for drawing" |
|
586 |
||
587 |
|id| |
|
588 |
||
589 |
(aForm ~~ mask) ifTrue:[ |
|
7629 | 590 |
mask := aForm. |
591 |
gcId notNil ifTrue:[ |
|
7799 | 592 |
mask isNil ifTrue:[ |
7629 | 593 |
device setBitmapMask:nil in:gcId |
594 |
] ifFalse:[ |
|
595 |
mask := mask asFormOn:device. |
|
596 |
id := mask drawableId. |
|
597 |
(mask depth == 1) ifTrue:[ |
|
598 |
device setBitmapMask:id in:gcId |
|
599 |
] ifFalse:[ |
|
600 |
device setPixmapMask:id in:gcId |
|
601 |
] |
|
602 |
] |
|
603 |
] |
|
732 | 604 |
] |
605 |
! |
|
606 |
||
2018 | 607 |
maskOrigin:aPoint |
608 |
"set the origin of the mask-pattern" |
|
609 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
610 |
|x y pO| |
2018 | 611 |
|
612 |
x := aPoint x. |
|
613 |
y := aPoint y. |
|
614 |
||
615 |
(maskOrigin isNil or:[ |
|
616 |
((x ~= maskOrigin x) or:[y ~= maskOrigin y]) ]) ifTrue:[ |
|
617 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
618 |
maskOrigin := aPoint. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
619 |
|
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
620 |
transformation notNil ifTrue:[ |
6711
2b50385f7257
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6691
diff
changeset
|
621 |
pO := transformation transformPoint:aPoint. |
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
622 |
x:= pO x. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
623 |
y := pO y. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
624 |
]. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
625 |
|
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
626 |
gcId notNil ifTrue:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
627 |
device setMaskOriginX:x rounded y:y rounded in:gcId |
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
628 |
] |
2018 | 629 |
] |
630 |
||
631 |
"Created: / 26.1.1998 / 19:03:02 / cg" |
|
632 |
! |
|
633 |
||
2016 | 634 |
maskOriginX:orgX y:orgY |
635 |
"set the origin of the pattern" |
|
636 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
637 |
self maskOrigin:(orgX @ orgY) |
2016 | 638 |
! |
639 |
||
732 | 640 |
paint:aColor |
641 |
"set the drawing color, which may be a real color, a dithered one |
|
642 |
or even an image." |
|
643 |
||
644 |
(aColor ~~ paint) ifTrue:[ |
|
1029
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
645 |
aColor notNil ifTrue:[ |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
646 |
paint := aColor. |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
647 |
self setGCForPaint. |
0b03a4f98dcd
pass srcGC to bitBlitter (req'd for WINDOWS)
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
648 |
] |
732 | 649 |
] |
650 |
||
651 |
"Modified: 16.5.1996 / 15:35:57 / cg" |
|
652 |
! |
|
653 |
||
654 |
paint:fgColor on:bgColor |
|
6292 | 655 |
"set the paint and background-paint color. |
732 | 656 |
The bg-paint is used in opaque-draw operations" |
657 |
||
658 |
|fgId bgId| |
|
659 |
||
660 |
((fgColor ~~ paint) or:[bgColor ~~ bgPaint]) ifTrue:[ |
|
6292 | 661 |
fgColor notNil ifTrue:[ |
662 |
paint := fgColor |
|
663 |
]. |
|
664 |
bgColor notNil ifTrue:[ |
|
665 |
bgPaint := bgColor |
|
666 |
]. |
|
667 |
gcId notNil ifTrue:[ |
|
668 |
paint isColor ifTrue:[ |
|
669 |
paint := paint onDevice:device. |
|
670 |
]. |
|
671 |
paint isColor ifTrue:[ |
|
672 |
fgId := paint colorId. |
|
673 |
fgId notNil ifTrue:[ |
|
674 |
mask notNil ifTrue:[ |
|
675 |
mask := nil. |
|
676 |
device setBitmapMask:nil in:gcId |
|
677 |
]. |
|
678 |
bgPaint isColor ifTrue:[ |
|
679 |
bgPaint := bgPaint onDevice:device. |
|
680 |
]. |
|
681 |
bgPaint isColor ifTrue:[ |
|
682 |
bgId := bgPaint colorId. |
|
683 |
bgId notNil ifTrue:[ |
|
684 |
"the common case, both are real colors" |
|
685 |
(paint ~~ foreground) ifTrue:[ |
|
686 |
foreground := paint. |
|
687 |
(bgPaint ~~ background) ifTrue:[ |
|
688 |
background := bgPaint. |
|
689 |
device setForeground:fgId background:bgId in:gcId. |
|
690 |
^ self |
|
691 |
]. |
|
692 |
device setForeground:fgId in:gcId. |
|
693 |
^ self |
|
694 |
]. |
|
695 |
(bgPaint ~~ background) ifTrue:[ |
|
696 |
background := bgPaint. |
|
697 |
device setBackground:bgId in:gcId. |
|
698 |
]. |
|
699 |
^ self |
|
700 |
]. |
|
701 |
"bgPaint is dithered, setup paint here, leave bgPaint |
|
702 |
till next opaque draw comes around." |
|
703 |
||
704 |
(paint ~~ foreground) ifTrue:[ |
|
705 |
foreground := paint. |
|
706 |
device setForeground:fgId in:gcId |
|
707 |
]. |
|
708 |
^ self |
|
709 |
] |
|
710 |
] |
|
711 |
]. |
|
712 |
"either paint or bgPaint (or both) are dithered colors, |
|
713 |
setup for paint, leave bg-problem till next opaque draw |
|
714 |
comes around. |
|
715 |
" |
|
716 |
self setGCForPaint. |
|
717 |
] |
|
732 | 718 |
] |
719 |
||
4797 | 720 |
"Modified: / 31-08-2007 / 10:56:49 / cg" |
732 | 721 |
! |
722 |
||
723 |
paint:fgColor on:bgColor function:f |
|
724 |
"set paint, background-paint and function" |
|
725 |
||
726 |
self paint:fgColor on:bgColor. |
|
727 |
self function:f |
|
728 |
||
729 |
"Modified: 16.5.1996 / 15:36:35 / cg" |
|
730 |
! |
|
731 |
||
6266 | 732 |
setClippingBounds:aRectangleOrNil |
6501
ef63b2302cba
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6497
diff
changeset
|
733 |
"set the clipping rectangle for drawing (in logical coordinates). |
6266 | 734 |
Only set the variable, do not change the gc" |
735 |
||
736 |
clipRect := aRectangleOrNil |
|
737 |
! |
|
738 |
||
8372 | 739 |
setDeviceLineWidth:aNumber |
740 |
"set the untransformed line width. |
|
741 |
This ignores any transformation and sets the lineWidth to the given number of |
|
742 |
pixels." |
|
743 |
||
744 |
device setLineWidth:aNumber style:lineStyle cap:capStyle join:joinStyle in:gcId |
|
745 |
||
746 |
"Created: / 24-05-2018 / 08:03:25 / Claus Gittinger" |
|
747 |
! |
|
748 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
749 |
setDeviceMaskOriginX:x y:y |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
750 |
"set the origin of the mask-pattern" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
751 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
752 |
gcId notNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
753 |
device setMaskOriginX:x rounded y:y rounded in:gcId |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
754 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
755 |
! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
756 |
|
732 | 757 |
setGraphicsExposures:aBoolean |
7651 | 758 |
"want to if aBoolean is true - or don't want to be notified |
732 | 759 |
of graphics exposures" |
760 |
||
761 |
gcId notNil ifTrue:[ |
|
7651 | 762 |
device setGraphicsExposures:aBoolean in:gcId |
732 | 763 |
] |
6266 | 764 |
! |
765 |
||
766 |
setPaint:fgColor on:bgColor |
|
6292 | 767 |
"set the paint and background-paint color. |
6266 | 768 |
The bg-paint is used in opaque-draw operations. |
769 |
Only set the variables, but do not send it to the device, |
|
770 |
Used on initialization." |
|
771 |
||
772 |
fgColor notNil ifTrue:[ |
|
6292 | 773 |
foreground := paint := fgColor |
6266 | 774 |
]. |
775 |
bgColor notNil ifTrue:[ |
|
6292 | 776 |
background := bgPaint := bgColor |
6266 | 777 |
]. |
732 | 778 |
! ! |
779 |
||
1092 | 780 |
!DeviceGraphicsContext methodsFor:'accessing-internals'! |
732 | 781 |
|
782 |
background |
|
6266 | 783 |
<resource: #obsolete> |
732 | 784 |
"return the current background drawing color. |
785 |
OBSOLETE: use #paint: / #backgroundPaint: / #paint:on:" |
|
786 |
||
787 |
^ background |
|
788 |
||
789 |
"Modified: 12.5.1996 / 22:28:09 / cg" |
|
790 |
! |
|
791 |
||
792 |
background:aColor |
|
6266 | 793 |
<resource: #obsolete> |
732 | 794 |
"set the internal background color for drawing - aColor must be a real color. |
795 |
OBSOLETE: this method will vanish; use #paint: / #backgroundPaint: / #paint:on:" |
|
796 |
||
797 |
|bgId| |
|
798 |
||
799 |
(aColor ~~ background) ifTrue:[ |
|
6292 | 800 |
aColor notNil ifTrue:[ |
801 |
background := aColor. |
|
802 |
gcId notNil ifTrue:[ |
|
803 |
background := background onDevice:device. |
|
804 |
bgId := background colorId. |
|
805 |
||
806 |
" |
|
807 |
mhmh the following is a kludge .... |
|
808 |
" |
|
809 |
bgId isNil ifTrue:[ |
|
810 |
(background grayIntensity >= 50) ifTrue:[ |
|
811 |
bgId := device whitepixel |
|
812 |
] ifFalse:[ |
|
813 |
bgId := device blackpixel |
|
814 |
] |
|
815 |
]. |
|
816 |
device setBackground:bgId in:gcId |
|
817 |
] |
|
818 |
] |
|
732 | 819 |
] |
820 |
||
745 | 821 |
"Modified: 28.5.1996 / 20:44:55 / cg" |
732 | 822 |
! |
823 |
||
824 |
foreground |
|
6266 | 825 |
<resource: #obsolete> |
732 | 826 |
"return the current foreground drawing color. |
827 |
OBSOLETE: use #paint: / #paint:on:" |
|
828 |
||
829 |
^ foreground |
|
830 |
||
831 |
"Modified: 12.5.1996 / 22:28:03 / cg" |
|
832 |
! |
|
833 |
||
834 |
foreground:aColor |
|
6266 | 835 |
<resource: #obsolete> |
732 | 836 |
"set the internal foreground color for drawing - aColor must be a real color. |
837 |
OBSOLETE: this method will vanish; use #paint: / #paint:on:" |
|
838 |
||
839 |
|fgId| |
|
840 |
||
841 |
(aColor ~~ foreground) ifTrue:[ |
|
6292 | 842 |
aColor notNil ifTrue:[ |
843 |
foreground := aColor. |
|
844 |
gcId notNil ifTrue:[ |
|
845 |
(foreground class == SmallInteger) ifTrue:[ |
|
846 |
fgId := foreground |
|
847 |
] ifFalse:[ |
|
848 |
foreground := foreground onDevice:device. |
|
849 |
fgId := foreground colorId. |
|
850 |
]. |
|
851 |
||
852 |
"mhmh the following is a kludge ...." |
|
853 |
fgId isNil ifTrue:[ |
|
854 |
(foreground grayIntensity >= 50) ifTrue:[ |
|
855 |
fgId := device whitepixel |
|
856 |
] ifFalse:[ |
|
857 |
fgId := device blackpixel |
|
858 |
] |
|
859 |
]. |
|
860 |
device setForeground:fgId in:gcId. |
|
861 |
paint := foreground |
|
862 |
] |
|
863 |
] |
|
732 | 864 |
] |
865 |
||
745 | 866 |
"Modified: 28.5.1996 / 20:45:02 / cg" |
732 | 867 |
! |
868 |
||
869 |
foreground:fgColor background:bgColor |
|
6266 | 870 |
<resource: #obsolete> |
6292 | 871 |
"set both internal foreground and internal background colors |
732 | 872 |
- these must be real colors. |
873 |
OBSOLETE: this method will vanish; use #paint: / #paint:on:" |
|
874 |
||
875 |
|fgPixel bgPixel| |
|
876 |
||
877 |
((fgColor ~~ foreground) or:[bgColor ~~ background]) ifTrue:[ |
|
6292 | 878 |
fgColor notNil ifTrue:[ |
879 |
foreground := fgColor |
|
880 |
]. |
|
881 |
bgColor notNil ifTrue:[ |
|
882 |
background := bgColor |
|
883 |
]. |
|
884 |
gcId notNil ifTrue:[ |
|
885 |
foreground := foreground onDevice:device. |
|
886 |
background := background onDevice:device. |
|
887 |
fgPixel := foreground colorId. |
|
888 |
bgPixel := background colorId. |
|
889 |
||
890 |
"mhmh the following is a kludge ...." |
|
891 |
fgPixel isNil ifTrue:[ |
|
892 |
(foreground grayIntensity >= 50) ifTrue:[ |
|
893 |
fgPixel := device whitepixel |
|
894 |
] ifFalse:[ |
|
895 |
fgPixel := device blackpixel |
|
896 |
] |
|
897 |
]. |
|
898 |
bgPixel isNil ifTrue:[ |
|
899 |
(background grayIntensity >= 50) ifTrue:[ |
|
900 |
bgPixel := device whitepixel |
|
901 |
] ifFalse:[ |
|
902 |
bgPixel := device blackpixel |
|
903 |
] |
|
904 |
]. |
|
905 |
device setForeground:fgPixel background:bgPixel in:gcId. |
|
906 |
paint := foreground |
|
907 |
] |
|
732 | 908 |
] |
909 |
||
745 | 910 |
"Modified: 28.5.1996 / 20:45:27 / cg" |
732 | 911 |
! |
912 |
||
913 |
foreground:aColor function:fun |
|
6266 | 914 |
<resource: #obsolete> |
732 | 915 |
"set the foreground color and function for drawing. |
916 |
OBSOLETE: this method will vanish; use #paint: / #paint:on:" |
|
917 |
||
918 |
|fgPixel| |
|
919 |
||
920 |
((aColor ~~ foreground) or:[fun ~~ function]) ifTrue:[ |
|
6292 | 921 |
foreground := aColor. |
922 |
function := fun. |
|
923 |
gcId notNil ifTrue:[ |
|
924 |
foreground := foreground onDevice:device. |
|
925 |
fgPixel := foreground colorId. |
|
926 |
||
927 |
"mhmh the following is a kludge ...." |
|
928 |
fgPixel isNil ifTrue:[ |
|
929 |
(foreground grayIntensity >= 50) ifTrue:[ |
|
930 |
fgPixel := device whitepixel |
|
931 |
] ifFalse:[ |
|
932 |
fgPixel := device blackpixel |
|
933 |
] |
|
934 |
]. |
|
935 |
device setForeground:fgPixel in:gcId. |
|
936 |
device setFunction:fun in:gcId. |
|
937 |
paint := foreground |
|
938 |
] |
|
732 | 939 |
] |
940 |
||
745 | 941 |
"Modified: 28.5.1996 / 20:45:09 / cg" |
732 | 942 |
! ! |
943 |
||
944 |
!DeviceGraphicsContext methodsFor:'bit blitting'! |
|
945 |
||
2016 | 946 |
copyBitsFrom:aByteArray bitsPerPixel:bpp depth:depth padding:pad width:srcW height:srcH x:srcX y:srcY toX:dstX y:dstY |
947 |
"copy bits from a smalltalk byteArray. |
|
948 |
The bits found there are supposed to be in the devices native format (i.e. |
|
949 |
translated to allocated color indices on pseudoColor devices and padded as required. |
|
6292 | 950 |
The byteOrder is MSB and will be converted as appropriate by the underlying devices |
2016 | 951 |
method to whatever the device needs." |
952 |
||
953 |
device |
|
6292 | 954 |
drawBits:aByteArray |
955 |
bitsPerPixel:bpp |
|
956 |
depth:depth |
|
2016 | 957 |
padding:pad |
6292 | 958 |
width:srcW height:srcH |
959 |
x:srcX y:srcY |
|
960 |
into:drawableId |
|
961 |
x:dstX y:dstY |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
962 |
width:srcW height:srcH "all senders set srcW/srcH to self width / self height" |
6292 | 963 |
with:gcId. |
2016 | 964 |
! |
965 |
||
7456 | 966 |
copyFrom:aGC x:srcX y:srcY toX:dstX y:dstY width:w height:h depth:depth |
1291 | 967 |
"copy from aDrawable into the receiver; |
968 |
the source may be the receiver as well - in this case its a scroll. |
|
7749 | 969 |
All coordinates are in device coordinates." |
1291 | 970 |
|
7456 | 971 |
|srcGCId srcDrawableId| |
732 | 972 |
|
973 |
gcId isNil ifTrue:[ |
|
7456 | 974 |
self initGC |
732 | 975 |
]. |
976 |
||
7749 | 977 |
srcGCId := aGC initGC. |
7456 | 978 |
srcDrawableId := aGC drawableId. |
979 |
||
980 |
((depth == 1) and:[device depth ~~ 1]) ifTrue:[ |
|
981 |
aGC isPixmap ifTrue:[ |
|
982 |
device |
|
983 |
copyPlaneFromPixmapId:srcDrawableId |
|
984 |
x:srcX |
|
985 |
y:srcY |
|
986 |
gc:srcGCId |
|
987 |
to:drawableId |
|
988 |
x:dstX |
|
989 |
y:dstY |
|
990 |
gc:gcId |
|
991 |
width:w |
|
992 |
height:h |
|
993 |
] ifFalse:[ |
|
994 |
device |
|
995 |
copyPlaneFromId:srcDrawableId |
|
996 |
x:srcX |
|
997 |
y:srcY |
|
998 |
gc:srcGCId |
|
999 |
to:drawableId |
|
1000 |
x:dstX |
|
1001 |
y:dstY |
|
1002 |
gc:gcId |
|
1003 |
width:w |
|
1004 |
height:h |
|
1005 |
] |
|
732 | 1006 |
] ifFalse:[ |
7456 | 1007 |
aGC isPixmap ifTrue:[ |
1008 |
device |
|
1009 |
copyFromPixmapId:srcDrawableId |
|
1010 |
x:srcX |
|
1011 |
y:srcY |
|
1012 |
gc:srcGCId |
|
1013 |
to:drawableId |
|
1014 |
x:dstX |
|
1015 |
y:dstY |
|
1016 |
gc:gcId |
|
1017 |
width:w |
|
1018 |
height:h |
|
1019 |
] ifFalse:[ |
|
1020 |
device |
|
1021 |
copyFromId:srcDrawableId |
|
1022 |
x:srcX |
|
1023 |
y:srcY |
|
1024 |
gc:srcGCId |
|
1025 |
to:drawableId |
|
1026 |
x:dstX |
|
1027 |
y:dstY |
|
1028 |
gc:gcId |
|
1029 |
width:w |
|
1030 |
height:h. |
|
1031 |
] |
|
1032 |
]. |
|
732 | 1033 |
! |
1034 |
||
7456 | 1035 |
copyPlaneFrom:aGC x:srcX y:srcY toX:dstX y:dstY width:w height:h |
732 | 1036 |
"copy one plane from aDrawable into the receiver. 0's are drawn in |
1037 |
background, while 1's are drawn with foreground color. |
|
1038 |
The depth of aDrawable must (should) be 1. |
|
1039 |
The drawable must have been allocated on the same device. |
|
1040 |
All coordinates are in device coordinates." |
|
1041 |
||
7456 | 1042 |
|srcGCId srcDrawableId| |
732 | 1043 |
|
1044 |
gcId isNil ifTrue:[ |
|
7456 | 1045 |
self initGC |
732 | 1046 |
]. |
1047 |
||
7749 | 1048 |
srcGCId := aGC initGC. |
7456 | 1049 |
srcDrawableId := aGC drawableId. |
1050 |
||
1051 |
aGC isPixmap ifTrue:[ |
|
1052 |
device |
|
1053 |
copyPlaneFromPixmapId:srcDrawableId |
|
1054 |
x:srcX |
|
1055 |
y:srcY |
|
1056 |
gc:srcGCId |
|
1057 |
to:drawableId |
|
1058 |
x:dstX |
|
1059 |
y:dstY |
|
1060 |
gc:gcId |
|
1061 |
width:w |
|
1062 |
height:h |
|
1249
5224bb7a97bf
use new copy interface, to avoid useless noExpose events
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
1063 |
] ifFalse:[ |
7456 | 1064 |
device |
1065 |
copyPlaneFromId:srcDrawableId |
|
1066 |
x:srcX |
|
1067 |
y:srcY |
|
1068 |
gc:srcGCId |
|
1069 |
to:drawableId |
|
1070 |
x:dstX |
|
1071 |
y:dstY |
|
1072 |
gc:gcId |
|
1073 |
width:w |
|
1074 |
height:h |
|
1249
5224bb7a97bf
use new copy interface, to avoid useless noExpose events
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
1075 |
] |
5224bb7a97bf
use new copy interface, to avoid useless noExpose events
Claus Gittinger <cg@exept.de>
parents:
1237
diff
changeset
|
1076 |
|
2271
46b68ae54cbc
win32 needs source-gc to be initialized in a bitBlt.
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
1077 |
"Modified: / 22.8.1998 / 15:15:52 / cg" |
732 | 1078 |
! ! |
1079 |
||
1080 |
!DeviceGraphicsContext methodsFor:'copying'! |
|
1081 |
||
1082 |
postCopy |
|
1083 |
"this may not be enough to allow copying of views ..." |
|
1084 |
||
7851 | 1085 |
<modifier: #super> "must be called if redefined" |
1086 |
||
1087 |
"/ super postCopy. |
|
732 | 1088 |
device := drawableId := gcId := nil. |
1089 |
self recreate |
|
7851 | 1090 |
|
1091 |
"Modified: / 08-02-2017 / 01:07:46 / cg" |
|
4403 | 1092 |
! |
1093 |
||
1094 |
postDeepCopy |
|
1095 |
device := drawableId := gcId := nil. |
|
732 | 1096 |
! ! |
1097 |
||
1098 |
!DeviceGraphicsContext methodsFor:'drawing'! |
|
1099 |
||
1100 |
displayArcX:x y:y width:w height:h from:startAngle angle:angle |
|
1101 |
"draw an arc; apply transformation if nonNil" |
|
1102 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1103 |
|pX pY nW nH sA a pO pC| |
732 | 1104 |
|
1105 |
gcId isNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1106 |
self initGC |
732 | 1107 |
]. |
1108 |
transformation notNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1109 |
pO := transformation transformPoint:x@y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1110 |
pC := transformation transformPoint:(x+w-1)@(y+h-1). |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1111 |
pX := pO x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1112 |
pY := pO y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1113 |
nW := pC x - pX + 1. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1114 |
nH := pC y - pY + 1. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1115 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1116 |
nW < 0 ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1117 |
nW := nW abs. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1118 |
pX := pX - nW. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1119 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1120 |
nH < 0 ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1121 |
nH := nH abs. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1122 |
pY := pY - nH. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1123 |
]. |
732 | 1124 |
] ifFalse:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1125 |
pX := x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1126 |
pY := y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1127 |
nW := w. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1128 |
nH := h. |
732 | 1129 |
]. |
1130 |
||
1131 |
pX := pX rounded. |
|
1132 |
pY := pY rounded. |
|
1133 |
nW := nW rounded. |
|
1134 |
nH := nH rounded. |
|
1135 |
||
2268
1a774fc02c83
fixed non-float (i.e. fraction) args to fillArc/ displayArc
Claus Gittinger <cg@exept.de>
parents:
2259
diff
changeset
|
1136 |
sA := startAngle. |
1a774fc02c83
fixed non-float (i.e. fraction) args to fillArc/ displayArc
Claus Gittinger <cg@exept.de>
parents:
2259
diff
changeset
|
1137 |
sA isInteger ifFalse:[sA := sA asFloat]. |
1a774fc02c83
fixed non-float (i.e. fraction) args to fillArc/ displayArc
Claus Gittinger <cg@exept.de>
parents:
2259
diff
changeset
|
1138 |
a := angle. |
1a774fc02c83
fixed non-float (i.e. fraction) args to fillArc/ displayArc
Claus Gittinger <cg@exept.de>
parents:
2259
diff
changeset
|
1139 |
a isInteger ifFalse:[a := a asFloat]. |
1a774fc02c83
fixed non-float (i.e. fraction) args to fillArc/ displayArc
Claus Gittinger <cg@exept.de>
parents:
2259
diff
changeset
|
1140 |
|
732 | 1141 |
device |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1142 |
displayArcX:pX |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1143 |
y:pY |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1144 |
width:nW |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1145 |
height:nH |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1146 |
from:sA |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1147 |
angle:a |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1148 |
in:drawableId |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1149 |
with:gcId |
732 | 1150 |
|
1151 |
"Created: 8.5.1996 / 08:31:30 / cg" |
|
784 | 1152 |
"Modified: 4.6.1996 / 17:59:28 / cg" |
732 | 1153 |
! |
1154 |
||
8281 | 1155 |
displayForm:formOrImageToDraw x:x y:y |
6292 | 1156 |
"draw a form or image non opaque; |
7882 | 1157 |
if it's a 1-plane bitmap, 1-bits are drawn in the |
732 | 1158 |
current paint-color, leaving pixels with 0-bits unchanged |
1159 |
(i.e. only 1-bits are drawn from the form). |
|
7882 | 1160 |
If it's a deep form (i.e. a pixmap) the current paint |
6292 | 1161 |
settings are ignored and the form is drawn as-is. |
1162 |
Care must be taken, that the paint color is correctly allocated |
|
732 | 1163 |
(by sending #on: to the color) before doing so. |
1164 |
Using functions other than #copy only makes sense if you are |
|
1165 |
certain, that the colors are real colors (actually, only for |
|
1166 |
noColor or allColor)." |
|
1167 |
||
8281 | 1168 |
|realFormOrImage pX pY w h nW nH pO pC| |
1169 |
||
1170 |
realFormOrImage := formOrImageToDraw. |
|
732 | 1171 |
|
1172 |
transformation notNil ifTrue:[ |
|
7882 | 1173 |
pO := transformation transformPoint:x@y. |
1174 |
pX := pO x. |
|
1175 |
pY := pO y. |
|
1176 |
||
1177 |
transformation isNoScale ifFalse:[ |
|
8281 | 1178 |
w := formOrImageToDraw width. |
1179 |
h := formOrImageToDraw height. |
|
7882 | 1180 |
pC := transformation applyTo:(x+w-1)@(y+h-1). |
1181 |
nW := pC x - pX + 1. |
|
1182 |
nH := pC y - pY + 1. |
|
1183 |
"/ nW := (transformation applyScaleX:w) rounded. |
|
1184 |
"/ nH := (transformation applyScaleY:h) rounded. |
|
1185 |
||
1186 |
((nW ~= w) or:[nH ~= h]) ifTrue:[ |
|
1187 |
"/ |
|
1188 |
"/ hard case - someone is drawing forms with scaling in effect |
|
1189 |
"/ look if we have a scaled version in our pocket ... |
|
1190 |
"/ |
|
8281 | 1191 |
realFormOrImage := nil. |
7882 | 1192 |
CachedScaledForms notNil ifTrue:[ |
8281 | 1193 |
(CachedScales at:formOrImageToDraw ifAbsent:nil) = transformation scale ifTrue:[ |
1194 |
realFormOrImage := CachedScaledForms at:formOrImageToDraw ifAbsent:nil. |
|
7882 | 1195 |
] |
1196 |
]. |
|
8281 | 1197 |
realFormOrImage isNil ifTrue:[ |
7882 | 1198 |
"/ |
1199 |
"/ nope - must do the work ... |
|
1200 |
"/ |
|
8281 | 1201 |
realFormOrImage := formOrImageToDraw magnifiedBy:(nW / w) @ (nH / h). |
7882 | 1202 |
CachedScaledForms isNil ifTrue:[ |
1203 |
CachedScaledForms := WeakIdentityDictionary new. |
|
1204 |
CachedScales := WeakIdentityDictionary new. |
|
1205 |
]. |
|
8281 | 1206 |
CachedScaledForms at:formOrImageToDraw put:realFormOrImage. |
1207 |
CachedScales at:formOrImageToDraw put:transformation scale. |
|
7882 | 1208 |
] |
1209 |
] |
|
1210 |
] |
|
732 | 1211 |
] ifFalse:[ |
7882 | 1212 |
pX := x. |
1213 |
pY := y. |
|
732 | 1214 |
]. |
1215 |
||
8281 | 1216 |
self displayDeviceForm:realFormOrImage x:pX y:pY |
732 | 1217 |
|
7882 | 1218 |
"Modified: / 12-04-1997 / 12:47:29 / cg" |
1219 |
"Modified (comment): / 13-02-2017 / 20:00:13 / cg" |
|
732 | 1220 |
! |
1221 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1222 |
displayLineFrom:p0 to:p1 |
732 | 1223 |
"draw a line (with current paint-color); apply transformation if nonNil" |
1224 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1225 |
|pX0 pY0 pX1 pY1 easy fgId bgId tp0 tp1| |
732 | 1226 |
|
1227 |
gcId isNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1228 |
self initGC |
732 | 1229 |
]. |
1230 |
||
1231 |
lineStyle == #doubleDashed ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1232 |
" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1233 |
if bgPaint or paint is not a real color, we have to do it the hard way ... |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1234 |
" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1235 |
easy := true. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1236 |
paint isColor ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1237 |
easy := false |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1238 |
] ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1239 |
fgId := paint colorId. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1240 |
fgId isNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1241 |
easy := false |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1242 |
] |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1243 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1244 |
bgPaint isColor ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1245 |
easy := false |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1246 |
] ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1247 |
bgId := bgPaint colorId. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1248 |
bgId isNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1249 |
easy := false |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1250 |
] |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1251 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1252 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1253 |
easy ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1254 |
((foreground ~~ paint) or:[background ~~ bgPaint]) ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1255 |
device setForeground:fgId background:bgId in:gcId. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1256 |
foreground := paint. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1257 |
background := bgPaint. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1258 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1259 |
] ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1260 |
'DeviceGraphicsContext [warning]: cannot draw dashes with dithered colors' errorPrintCR |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1261 |
]. |
732 | 1262 |
]. |
1263 |
||
1264 |
transformation notNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1265 |
tp0 := transformation transformPoint:p0. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1266 |
tp1 := transformation transformPoint:p1. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1267 |
pX0 := tp0 x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1268 |
pY0 := tp0 y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1269 |
pX1 := tp1 x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1270 |
pY1 := tp1 y. |
732 | 1271 |
] ifFalse:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1272 |
pX0 := p0 x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1273 |
pY0 := p0 y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1274 |
pX1 := p1 x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1275 |
pY1 := p1 y |
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1276 |
]. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1277 |
|
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1278 |
pX0 := pX0 rounded. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1279 |
pY0 := pY0 rounded. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1280 |
pX1 := pX1 rounded. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1281 |
pY1 := pY1 rounded. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1282 |
|
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1283 |
device displayLineFromX:pX0 y:pY0 toX:pX1 y:pY1 in:drawableId with:gcId |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1284 |
! |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1285 |
|
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1286 |
displayLineFromX:x0 y:y0 toX:x1 y:y1 |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1287 |
"draw a line (with current paint-color); apply transformation if nonNil" |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1288 |
|
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1289 |
|pX0 pY0 pX1 pY1 easy fgId bgId p0 p1| |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1290 |
|
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1291 |
gcId isNil ifTrue:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1292 |
self initGC |
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1293 |
]. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1294 |
|
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1295 |
lineStyle == #doubleDashed ifTrue:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1296 |
" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1297 |
if bgPaint or paint is not a real color, we have to do it the hard way ... |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1298 |
" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1299 |
easy := true. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1300 |
paint isColor ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1301 |
easy := false |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1302 |
] ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1303 |
fgId := paint colorId. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1304 |
fgId isNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1305 |
easy := false |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1306 |
] |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1307 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1308 |
bgPaint isColor ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1309 |
easy := false |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1310 |
] ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1311 |
bgId := bgPaint colorId. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1312 |
bgId isNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1313 |
easy := false |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1314 |
] |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1315 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1316 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1317 |
easy ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1318 |
((foreground ~~ paint) or:[background ~~ bgPaint]) ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1319 |
device setForeground:fgId background:bgId in:gcId. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1320 |
foreground := paint. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1321 |
background := bgPaint. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1322 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1323 |
] ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1324 |
'DeviceGraphicsContext [warning]: cannot draw dashes with dithered colors' errorPrintCR |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1325 |
]. |
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1326 |
]. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1327 |
|
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1328 |
transformation notNil ifTrue:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1329 |
p0 := transformation transformPoint:x0@y0. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1330 |
p1 := transformation transformPoint:x1@y1. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1331 |
pX0 := p0 x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1332 |
pY0 := p0 y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1333 |
pX1 := p1 x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1334 |
pY1 := p1 y. |
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1335 |
] ifFalse:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1336 |
pX0 := x0. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1337 |
pY0 := y0. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1338 |
pX1 := x1. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1339 |
pY1 := y1 |
732 | 1340 |
]. |
1341 |
||
1342 |
pX0 := pX0 rounded. |
|
1343 |
pY0 := pY0 rounded. |
|
1344 |
pX1 := pX1 rounded. |
|
1345 |
pY1 := pY1 rounded. |
|
1346 |
||
1347 |
device displayLineFromX:pX0 y:pY0 toX:pX1 y:pY1 in:drawableId with:gcId |
|
1348 |
||
1177
e89408c15bb5
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
1349 |
"Modified: 10.1.1997 / 17:46:32 / cg" |
732 | 1350 |
! |
1351 |
||
1352 |
displayOpaqueForm:formToDraw x:x y:y |
|
8154 | 1353 |
"draw a form or image opaque. |
1354 |
Somewhat backward compatible hacky: |
|
1355 |
||
1356 |
if it's a 1-plane form, |
|
1357 |
1-bits are drawn in the current paint-color and |
|
1358 |
0-bits in the bgPaint color. |
|
1359 |
||
1360 |
If it's a deep form (i.e. a pixmap) or an image, |
|
1361 |
the current paint/bgPaint settings are ignored and the image is drawn as-is. |
|
1362 |
||
6292 | 1363 |
In the 1-plane case, special care must be taken if paint and/or bgPaint |
1364 |
dithered colors or patterns, since are that the colors are correctly allocated |
|
732 | 1365 |
(by sending #on: to the colors) before doing so. |
1366 |
If there is a transformation, the image is scaled as appropiate." |
|
1367 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1368 |
|w h realForm pX pY nW nH pO pC| |
732 | 1369 |
|
1370 |
bgPaint isNil ifTrue:[ |
|
7882 | 1371 |
"/ |
1372 |
"/ actually not an opaque draw |
|
1373 |
"/ |
|
1374 |
self displayForm:formToDraw x:x y:y. |
|
1375 |
^ self |
|
732 | 1376 |
]. |
1377 |
||
1378 |
realForm := formToDraw. |
|
1379 |
||
1380 |
transformation notNil ifTrue:[ |
|
7882 | 1381 |
pO := transformation transformPoint:x@y. |
1382 |
pX := pO x. |
|
1383 |
pY := pO y. |
|
1384 |
"/ pX := transformation applyToX:x. |
|
1385 |
"/ pY := transformation applyToY:y. |
|
1386 |
||
1387 |
transformation isNoScale ifFalse:[ |
|
1388 |
w := formToDraw width. |
|
1389 |
h := formToDraw height. |
|
1390 |
pC := transformation applyTo:(x+w-1)@(y+h-1). |
|
1391 |
nW := pX - x + 1. |
|
1392 |
nH := pY - y + 1. |
|
1393 |
"/ nW := (transformation applyScaleX:w) rounded. |
|
1394 |
"/ nH := (transformation applyScaleY:h) rounded. |
|
1395 |
||
1396 |
((nW ~= w) or:[nH ~= h]) ifTrue:[ |
|
1397 |
"/ |
|
1398 |
"/ hard case - someone is drawing forms with scaling in effect |
|
1399 |
"/ look if we have a scaled version in our pocket ... |
|
1400 |
"/ |
|
1401 |
realForm := nil. |
|
1402 |
CachedScaledForms notNil ifTrue:[ |
|
1403 |
(CachedScales at:formToDraw ifAbsent:nil) = transformation scale ifTrue:[ |
|
1404 |
realForm := CachedScaledForms at:formToDraw ifAbsent:nil. |
|
1405 |
] |
|
1406 |
]. |
|
1407 |
realForm isNil ifTrue:[ |
|
1408 |
"/ |
|
1409 |
"/ nope - must do the work ... |
|
1410 |
"/ |
|
1411 |
realForm := formToDraw magnifiedBy:(nW / w) @ (nH / h). |
|
1412 |
CachedScaledForms isNil ifTrue:[ |
|
1413 |
CachedScaledForms := WeakIdentityDictionary new. |
|
1414 |
CachedScales := WeakIdentityDictionary new. |
|
1415 |
]. |
|
1416 |
CachedScaledForms at:formToDraw put:realForm. |
|
1417 |
CachedScales at:formToDraw put:transformation scale. |
|
1418 |
] |
|
1419 |
] |
|
1420 |
] |
|
732 | 1421 |
] ifFalse:[ |
7882 | 1422 |
pX := x. |
1423 |
pY := y. |
|
732 | 1424 |
]. |
1425 |
||
1426 |
self displayDeviceOpaqueForm:realForm x:pX y:pY |
|
1427 |
||
7882 | 1428 |
"Modified: / 12-04-1997 / 12:49:02 / cg" |
8154 | 1429 |
"Modified (comment): / 31-08-2017 / 19:28:22 / cg" |
732 | 1430 |
! |
1431 |
||
1432 |
displayOpaqueString:aString from:index1 to:index2 x:x y:y |
|
1433 |
"draw a substring at the coordinate x/y - draw foreground pixels in |
|
1434 |
paint-color and background pixels in bgPaint-color. |
|
6292 | 1435 |
If the transformation involves scaling, |
7345 | 1436 |
the font's point-size is scaled as appropriate. |
732 | 1437 |
Assuming that device can only draw in device colors, we have to handle |
1438 |
the case where paint and/or bgPaint are dithered colors" |
|
1439 |
||
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1440 |
self displayString:aString from:index1 to:index2 x:x y:y opaque:true |
732 | 1441 |
! |
1442 |
||
1443 |
displayOpaqueString:aString x:x y:y |
|
1444 |
"draw a string at the coordinate x/y - draw foreground pixels in paint-color, |
|
6292 | 1445 |
background pixels in bgPaint color. If the transformation involves scaling, |
7345 | 1446 |
the font's point-size is scaled as appropriate. |
732 | 1447 |
Assuming that device can only draw in device colors, we have to handle |
1448 |
the case where paint and/or bgPaint are dithered colors or images." |
|
1449 |
||
7064 | 1450 |
aString isPlainString ifFalse:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1451 |
" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1452 |
hook for non-strings (i.e. attributed text) |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1453 |
that 'thing' should know how to display itself ... |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1454 |
" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1455 |
aString displayOpaqueOn:self x:x y:y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1456 |
^ self |
732 | 1457 |
]. |
1458 |
||
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1459 |
self displayOpaqueString:aString from:1 to:(aString size) x:x y:y |
732 | 1460 |
! |
1461 |
||
1462 |
displayPointX:x y:y |
|
1463 |
"draw a point (with current paint-color); apply transformation if nonNil" |
|
1464 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1465 |
|pX pY pO| |
732 | 1466 |
|
1467 |
gcId isNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1468 |
self initGC |
732 | 1469 |
]. |
1470 |
transformation notNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1471 |
pO := transformation transformPoint:x@y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1472 |
pX := pO x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1473 |
pY := pO y. |
732 | 1474 |
] ifFalse:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1475 |
pX := x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1476 |
pY := y |
732 | 1477 |
]. |
1478 |
pX := pX rounded. |
|
1479 |
pY := pY rounded. |
|
1480 |
||
1481 |
device displayPointX:pX y:pY in:drawableId with:gcId |
|
1482 |
! |
|
1483 |
||
1484 |
displayPolygon:aPolygon |
|
1485 |
"draw (the outline of) a polygon (with current paint-color). |
|
1486 |
Apply transformation if nonNil" |
|
1487 |
||
1488 |
|newPolygon| |
|
1489 |
||
1490 |
gcId isNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1491 |
self initGC |
732 | 1492 |
]. |
1493 |
transformation notNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1494 |
newPolygon := aPolygon collect:[:point | transformation transformPoint:point]. |
732 | 1495 |
] ifFalse:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1496 |
newPolygon := aPolygon |
732 | 1497 |
]. |
6645
6066dcf16c20
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6626
diff
changeset
|
1498 |
(newPolygon contains:[:p | |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1499 |
(p isPoint not |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1500 |
or:[(p x class ~~ SmallInteger) |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1501 |
or:[(p y class ~~ SmallInteger)]]) |
6645
6066dcf16c20
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6626
diff
changeset
|
1502 |
]) ifTrue:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1503 |
newPolygon := newPolygon collect:[:p | p asPoint rounded] |
732 | 1504 |
]. |
6292 | 1505 |
|
732 | 1506 |
device displayPolygon:newPolygon in:drawableId with:gcId |
1507 |
! |
|
1508 |
||
1509 |
displayRectangleX:x y:y width:w height:h |
|
1510 |
"draw a rectangle (with current paint-color). |
|
1511 |
If transformation is nonNil, drawing is in logical coordinates." |
|
1512 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1513 |
|pX pY nW nH easy fgId bgId pO pC| |
732 | 1514 |
|
1515 |
gcId isNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1516 |
self initGC |
732 | 1517 |
]. |
1518 |
||
1519 |
lineStyle == #doubleDashed ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1520 |
" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1521 |
if bgPaint or paint is not a real color, we have to do it the hard way ... |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1522 |
" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1523 |
easy := true. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1524 |
paint isColor ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1525 |
easy := false |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1526 |
] ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1527 |
fgId := paint colorId. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1528 |
fgId isNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1529 |
easy := false |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1530 |
] |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1531 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1532 |
bgPaint isColor ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1533 |
easy := false |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1534 |
] ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1535 |
bgId := bgPaint colorId. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1536 |
bgId isNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1537 |
easy := false |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1538 |
] |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1539 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1540 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1541 |
easy ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1542 |
((foreground ~~ paint) or:[background ~~ bgPaint]) ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1543 |
device setForeground:fgId background:bgId in:gcId. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1544 |
foreground := paint. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1545 |
background := bgPaint. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1546 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1547 |
] ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1548 |
'DeviceGraphicsContext [warning]: cannot draw dashes with dithered colors' errorPrintCR |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1549 |
]. |
732 | 1550 |
]. |
1551 |
||
1552 |
transformation notNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1553 |
pO := transformation transformPoint:x@y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1554 |
pC := transformation transformPoint:(x+w-1)@(y+h-1). |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1555 |
pX := pO x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1556 |
pY := pO y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1557 |
nW := pC x - pX + 1. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1558 |
nH := pC y - pY + 1. |
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1559 |
"/ pX := transformation applyToX:x. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1560 |
"/ pY := transformation applyToY:y. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1561 |
"/ nW := transformation applyScaleX:w. |
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1562 |
"/ nH := transformation applyScaleY:h. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1563 |
nW < 0 ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1564 |
nW := nW abs. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1565 |
pX := pX - nW. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1566 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1567 |
nH < 0 ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1568 |
nH := nH abs. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1569 |
pY := pY - nH. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1570 |
]. |
732 | 1571 |
] ifFalse:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1572 |
pX := x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1573 |
pY := y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1574 |
nW := w. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1575 |
nH := h |
732 | 1576 |
]. |
1577 |
||
1578 |
pX := pX rounded. |
|
1579 |
pY := pY rounded. |
|
1580 |
nW := nW rounded. |
|
1581 |
nH := nH rounded. |
|
1582 |
||
1583 |
"I asked myself many times if we should draw w/h or (w-1)/(h-1) bits - |
|
1584 |
this one seems mathematically incorrect but allows to draw and fill |
|
1585 |
a rectangle using the same extents. |
|
1586 |
I'm not certain if is the right thing to do ... |
|
1587 |
" |
|
6292 | 1588 |
device displayRectangleX:pX |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1589 |
y:pY |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1590 |
width:(nW - 1) |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1591 |
height:(nH - 1) |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1592 |
in:drawableId with:gcId |
1177
e89408c15bb5
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
1593 |
|
e89408c15bb5
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1138
diff
changeset
|
1594 |
"Modified: 10.1.1997 / 17:46:41 / cg" |
732 | 1595 |
! |
1596 |
||
1597 |
displayString:aString from:index1 to:index2 x:x y:y |
|
6292 | 1598 |
"draw a substring at the coordinate x/y - |
1599 |
draw foreground-pixels only (in current paint-color), |
|
732 | 1600 |
leaving background as-is. If the transformation involves scaling, |
7345 | 1601 |
the font's point-size is scaled as appropriate." |
732 | 1602 |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1603 |
self displayString:aString from:index1 to:index2 x:x y:y opaque:false maxWidth:nil. |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1604 |
! |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1605 |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1606 |
displayString:aString from:index1 to:index2 x:x y:y opaque:opaque |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1607 |
"draw part of a string with both fg and bg at x/y in current font" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1608 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1609 |
^ self displayString:aString from:index1 to:index2 x:x y:y opaque:opaque maxWidth:nil |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1610 |
! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1611 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1612 |
displayString:aStringArg from:index1Arg to:index2Arg x:x y:y opaque:opaqueArg maxWidth:maxWidth |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1613 |
"draw a substring at the coordinate x/y - draw foreground pixels in |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1614 |
paint-color and (if opaque is true), background pixels in bgPaint-color. |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1615 |
If the transformation involves scaling, the font's point-size is scaled as appropriate. |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1616 |
Assuming that device can only draw in device colors, we have to handle |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1617 |
the case where paint and/or bgPaint are dithered colors. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1618 |
maxWidth is the maximum width of the string in pixels or nil if unknown." |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1619 |
|
7443 | 1620 |
|opaque index1 index2 easy w h savedPaint fgId bgId pX pY fontUsed fontsEncoding sz aString |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1621 |
nSkipLeft nChars wString wSkipLeft index2Guess| |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1622 |
|
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1623 |
index1 := index1Arg. |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1624 |
index2 := index2Arg. |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1625 |
opaque := opaqueArg. |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1626 |
|
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1627 |
" |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1628 |
if backgroundPaint color is nil, we assume |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1629 |
this is a non-opaque draw |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1630 |
" |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1631 |
bgPaint isNil ifTrue:[ |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1632 |
opaque := false. |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1633 |
]. |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1634 |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1635 |
gcId isNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1636 |
self initGC |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1637 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1638 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1639 |
aStringArg isPlainString ifFalse:[ |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1640 |
" |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1641 |
hook for non-strings (i.e. attributed text) |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1642 |
that 'thing' should know how to display itself ... |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1643 |
" |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1644 |
aStringArg displayOn:self x:x y:y from:index1 to:index2 opaque:opaque. |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1645 |
^ self |
732 | 1646 |
]. |
1647 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1648 |
"/ transcode the string into the fonts encoding... |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1649 |
aString := aStringArg. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1650 |
fontsEncoding := font encoding. |
4056 | 1651 |
(characterEncoding ~~ fontsEncoding) ifTrue:[ |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1652 |
[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1653 |
aString := CharacterEncoder encodeString:aString from:characterEncoding into:fontsEncoding. |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1654 |
] on:CharacterEncoderError do:[:ex| |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1655 |
"substitute a default value for codes that cannot be represented |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1656 |
in the new character set" |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1657 |
ex proceedWith:ex defaultValue. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1658 |
]. |
4026
882de378f763
no longer as string for its encoding;
Claus Gittinger <cg@exept.de>
parents:
3943
diff
changeset
|
1659 |
]. |
732 | 1660 |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1661 |
fontUsed := font. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1662 |
transformation notNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1663 |
pX := transformation applyToX:x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1664 |
pY := transformation applyToY:y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1665 |
transformation noScale ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1666 |
sz := font size. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1667 |
sz notNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1668 |
fontUsed := font asSize:(transformation applyScaleY:sz) rounded. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1669 |
] |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1670 |
] |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1671 |
] ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1672 |
pX := x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1673 |
pY := y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1674 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1675 |
|
7063 | 1676 |
fontUsed isAlienFont ifTrue:[ |
1677 |
" |
|
1678 |
hook for alien fonts |
|
1679 |
that 'font' should know how to display the string... |
|
1680 |
" |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1681 |
fontUsed displayString:aString from:index1 to:index2 x:x rounded y:y rounded in:self opaque:opaque maxWidth:maxWidth. |
7063 | 1682 |
^ self |
1683 |
]. |
|
1684 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1685 |
pX := pX rounded. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1686 |
pY := pY rounded. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1687 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1688 |
fontUsed := fontUsed onDevice:device. |
7443 | 1689 |
deviceFont ~~ fontUsed ifTrue:[ |
1690 |
(fontUsed installInDeviceForGCId:gcId) isNil ifTrue:[ |
|
1691 |
"error - no such font" |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1692 |
^ self. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1693 |
]. |
7443 | 1694 |
deviceFont := fontUsed. |
7064 | 1695 |
]. |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1696 |
|
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1697 |
" |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1698 |
if bgPaint or paint is not a real Color (aka a pattern), we have to do it the hard way ... |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1699 |
" |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1700 |
paint isColor ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1701 |
easy := true. |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1702 |
fgId := paint colorId. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1703 |
fgId isNil ifTrue:[ |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1704 |
easy := false |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1705 |
] |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1706 |
] ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1707 |
easy := false |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1708 |
]. |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1709 |
opaque ifTrue:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1710 |
bgPaint isColor ifTrue:[ |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1711 |
bgId := bgPaint colorId. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1712 |
bgId isNil ifTrue:[ |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1713 |
easy := false |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1714 |
] |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1715 |
] ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1716 |
easy := false |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1717 |
]. |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1718 |
]. |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1719 |
|
7064 | 1720 |
pX := pX rounded. |
1721 |
pY := pY rounded. |
|
732 | 1722 |
|
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1723 |
"/ check if this string is too long and cut it into a managable size. |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1724 |
"/ this is due to win32 limitations which seems to be unable to handle strings |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1725 |
"/ which are drawn longer than 32k pixels. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1726 |
nChars := 500. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1727 |
(maxWidth notNil and:[(index2 - index1) > nChars]) ifTrue:[ |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1728 |
nSkipLeft := wSkipLeft := 0. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1729 |
|
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1730 |
"/ if the draw starts to the left of the window start, |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1731 |
"/ skip some characters at the beginning... |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1732 |
pX < 0 ifTrue:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1733 |
"/ ('x=%d wMax=%d l=%d i1=%d i2=%d' printfWith:x with:maxWidth with:aString size with:index1 with:index2) printCR. |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1734 |
nSkipLeft := (pX negated // font width) min:index2. "/ estimate |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1735 |
wSkipLeft := fontUsed widthOf:aString from:index1 to:index1+nSkipLeft-1. "/ actual number of pixels |
8283 | 1736 |
[ ((pX+wSkipLeft) > 0) and:[nSkipLeft > 0]] whileTrue:[ "/ too many |
1737 |
nSkipLeft := (nSkipLeft * 0.9) truncated. "/ truncate, to avoid endless loop (4 * 0.9) rounded = 4 |
|
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1738 |
wSkipLeft := fontUsed widthOf:aString from:index1 to:index1+nSkipLeft-1. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1739 |
]. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1740 |
index1 := index1 + nSkipLeft. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1741 |
pX := pX + wSkipLeft. |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1742 |
"/ ('skip %d w=%d x=%d' printfWith:nSkipLeft with:wSkipLeft with:x) printCR. |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1743 |
]. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1744 |
|
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1745 |
"/ ('n=%d w=%d' printfWith:nChars with:wString) printCR. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1746 |
[ |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1747 |
index2Guess := (index1+nChars-1) min:index2. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1748 |
wString := fontUsed widthOf:aString from:index1 to:index2Guess. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1749 |
((pX+wString) < maxWidth) and:[ index2Guess < index2] |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1750 |
] whileTrue:[ "/ not enough... |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1751 |
nChars := (nChars * 1.1) rounded. |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1752 |
]. |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1753 |
"/ ('n=%d w=%d' printfWith:nChars with:wString) printCR. |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1754 |
index2 := index2Guess. |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1755 |
]. |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1756 |
|
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1757 |
easy ifTrue:[ |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1758 |
opaque ifTrue:[ |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1759 |
device setForeground:fgId background:bgId in:gcId. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1760 |
background := bgPaint. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1761 |
] ifFalse:[ |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1762 |
device setForeground:fgId in:gcId. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1763 |
]. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1764 |
foreground := paint. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1765 |
self displayDeviceString:aString from:index1 to:index2 x:pX y:pY opaque:opaque. |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1766 |
^ self |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1767 |
]. |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1768 |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1769 |
"/ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1770 |
"/ do it the hard way - either forground or background is not a plain color, |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1771 |
"/ but dithered or a pattern |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1772 |
"/ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1773 |
w := fontUsed widthOf:aString from:index1 to:index2. |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1774 |
h := fontUsed height. |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1775 |
|
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1776 |
(fgId notNil and:[function == #copy]) ifTrue:[ |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1777 |
" |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1778 |
only bg is dithered or a pattern; fill with bg first ... |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1779 |
" |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1780 |
savedPaint := paint. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1781 |
self paint:bgPaint. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1782 |
self fillDeviceRectangleX:pX y:(pY - fontUsed ascent) width:w height:h. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1783 |
self paint:savedPaint. |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1784 |
|
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1785 |
" |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1786 |
then draw using fgPaint (which is a real color) |
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1787 |
" |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1788 |
self displayDeviceString:aString from:index1 to:index2 x:pX y:pY opaque:false. |
6626
4afe1d3883b4
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6612
diff
changeset
|
1789 |
^ self |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1790 |
]. |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1791 |
|
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1792 |
"/ the very hard case (fg-dither) |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1793 |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1794 |
self displayDeviceOpaqueString:aString from:index1 to:index2 in:fontUsed x:pX y:pY. |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
1795 |
|
5742
3edcdffa74ec
changed: #displayString:from:to:x:y:opaque:
Stefan Vogel <sv@exept.de>
parents:
5406
diff
changeset
|
1796 |
"Modified: / 30-06-1997 / 15:06:15 / cg" |
3edcdffa74ec
changed: #displayString:from:to:x:y:opaque:
Stefan Vogel <sv@exept.de>
parents:
5406
diff
changeset
|
1797 |
"Modified: / 14-04-2011 / 11:11:00 / Stefan Vogel <sv@exept.de>" |
8283 | 1798 |
"Modified (comment): / 31-01-2018 / 22:26:36 / stefan" |
732 | 1799 |
! |
1800 |
||
1801 |
displayString:aString x:x y:y |
|
6292 | 1802 |
"draw a string at the coordinate x/y - |
1803 |
draw foreground-pixels only (in current paint-color), |
|
1804 |
leaving background as-is. If the transformation involves scaling, |
|
7345 | 1805 |
the font's point-size is scaled as appropriate." |
732 | 1806 |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1807 |
self displayString:aString from:1 to:aString size x:x y:y opaque:false maxWidth:nil. |
732 | 1808 |
! |
1809 |
||
1810 |
displayUnscaledForm:formToDraw x:x y:y |
|
6292 | 1811 |
"draw a form or image non opaque and unscaled; |
7882 | 1812 |
if it's a 1-plane bitmap, 1-bits are drawn in the |
732 | 1813 |
current paint-color, leaving pixels with 0-bits unchanged |
1814 |
(i.e. only 1-bits are drawn from the form). |
|
7882 | 1815 |
If it's a deep form (i.e. a pixmap) the current paint |
6292 | 1816 |
settings are ignored and the form is drawn as-is. |
1817 |
Care must be taken, that the paint color is correctly allocated |
|
732 | 1818 |
(by sending #on: to the color) before doing so. |
1819 |
Using functions other than #copy only makes sense if you are |
|
1820 |
certain, that the colors are real colors (actually, only for |
|
1821 |
noColor or allColor). |
|
1822 |
The origins coordinate is transformed, but the image itself is unscaled." |
|
1823 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1824 |
|pX pY pO| |
732 | 1825 |
|
1826 |
transformation notNil ifTrue:[ |
|
7882 | 1827 |
pO := transformation transformPoint:(x@y). |
1828 |
pX := pO x. |
|
1829 |
pY := pO y. |
|
732 | 1830 |
] ifFalse:[ |
7882 | 1831 |
pX := x. |
1832 |
pY := y. |
|
732 | 1833 |
]. |
1834 |
||
1835 |
self displayDeviceForm:formToDraw x:pX y:pY |
|
1592
7ec770f2047a
faster image drawing if masked pixels are known
Claus Gittinger <cg@exept.de>
parents:
1517
diff
changeset
|
1836 |
|
7882 | 1837 |
"Modified: / 12-04-1997 / 12:48:04 / cg" |
1838 |
"Modified (comment): / 13-02-2017 / 20:00:22 / cg" |
|
732 | 1839 |
! |
1840 |
||
1841 |
displayUnscaledOpaqueForm:formToDraw x:x y:y |
|
6292 | 1842 |
"draw a form or image opaque and unscaled; |
7882 | 1843 |
if it's a 1-plane bitmap, 1-bits are drawn in the |
732 | 1844 |
current paint-color, 0 bits in background color. |
7882 | 1845 |
If it's a deep form (i.e. a pixmap) the current paint |
6292 | 1846 |
settings are ignored and the form is drawn as-is (opaque). |
732 | 1847 |
The origins coordinate is transformed, but the image itself is unscaled." |
1848 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1849 |
|pX pY pO| |
732 | 1850 |
|
1851 |
transformation notNil ifTrue:[ |
|
7882 | 1852 |
pO := transformation transformPoint:(x@y). |
1853 |
pX := pO x. |
|
1854 |
pY := pO y. |
|
732 | 1855 |
] ifFalse:[ |
7882 | 1856 |
pX := x. |
1857 |
pY := y. |
|
732 | 1858 |
]. |
1859 |
||
1860 |
self displayDeviceOpaqueForm:formToDraw x:pX y:pY |
|
1592
7ec770f2047a
faster image drawing if masked pixels are known
Claus Gittinger <cg@exept.de>
parents:
1517
diff
changeset
|
1861 |
|
7882 | 1862 |
"Modified: / 12-04-1997 / 12:49:21 / cg" |
1863 |
"Modified (comment): / 13-02-2017 / 20:00:28 / cg" |
|
732 | 1864 |
! |
1865 |
||
1866 |
displayUnscaledOpaqueString:aString from:index1 to:index2 x:x y:y |
|
1867 |
"draw a substring at the transformed coordinate x/y but do not scale the font. |
|
1868 |
Draw foreground pixels in paint-color, background pixels in bgPaint color." |
|
1869 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1870 |
|pX pY pO| |
732 | 1871 |
|
1872 |
transformation notNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1873 |
pO := transformation transformPoint:(x@y). |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1874 |
pX := pO x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1875 |
pY := pO y. |
732 | 1876 |
] ifFalse:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1877 |
pX := x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1878 |
pY := y. |
732 | 1879 |
]. |
1880 |
self displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:pX y:pY |
|
1881 |
! |
|
1882 |
||
1883 |
displayUnscaledOpaqueString:aString x:x y:y |
|
1884 |
"draw a string at the transformed coordinate x/y but do not scale the font. |
|
1885 |
Draw foreground pixels in paint-color, background pixels in bgPaint color." |
|
1886 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1887 |
|pX pY pO| |
732 | 1888 |
|
1889 |
transformation notNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1890 |
pO := transformation transformPoint:(x@y). |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1891 |
pX := pO x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1892 |
pY := pO y. |
732 | 1893 |
] ifFalse:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1894 |
pX := x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1895 |
pY := y. |
732 | 1896 |
]. |
1897 |
self displayDeviceOpaqueString:aString from:1 to:(aString size) in:font x:pX y:pY |
|
1898 |
! |
|
1899 |
||
1900 |
displayUnscaledString:aString from:index1 to:index2 x:x y:y |
|
1901 |
"draw a substring at the transformed coordinate x/y but do not scale the font. |
|
1902 |
draw foreground-pixels only (in current paint-color), leaving background as-is." |
|
1903 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1904 |
|pX pY pO| |
732 | 1905 |
|
1906 |
transformation notNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1907 |
pO := transformation transformPoint:(x@y). |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1908 |
pX := pO x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1909 |
pY := pO y. |
732 | 1910 |
] ifFalse:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1911 |
pX := x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1912 |
pY := y. |
732 | 1913 |
]. |
1914 |
self displayDeviceString:aString from:index1 to:index2 in:font x:pX y:pY |
|
1915 |
! |
|
1916 |
||
1917 |
displayUnscaledString:aString x:x y:y |
|
1918 |
"draw a string at the transformed coordinate x/y but do not scale the font. |
|
1919 |
draw foreground-pixels only (in current paint-color), leaving background as-is." |
|
1920 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
1921 |
|pX pY pO| |
732 | 1922 |
|
1923 |
transformation notNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1924 |
pO := transformation transformPoint:(x@y). |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1925 |
pX := pO x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1926 |
pY := pO y. |
732 | 1927 |
] ifFalse:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1928 |
pX := x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
1929 |
pY := y. |
732 | 1930 |
]. |
1931 |
self displayDeviceString:aString from:1 to:(aString size) in:font x:pX y:pY |
|
1932 |
! ! |
|
1933 |
||
1934 |
!DeviceGraphicsContext methodsFor:'drawing in device coordinates'! |
|
1935 |
||
8005 | 1936 |
displayDeviceForm:aFormOrImage x:x y:y |
6292 | 1937 |
"draw a form or image non opaque (i.e. only foreground color is drawn); |
7882 | 1938 |
If it's a 1-plane bitmap, 1-bits are drawn in the |
732 | 1939 |
current paint-color, leaving pixels with 0-bits unchanged |
1940 |
(i.e. only 1-bits are drawn from the form). |
|
8005 | 1941 |
|
1942 |
If it's a deep form (i.e. a pixmap) the current paint |
|
1943 |
settings are ignored and the form is drawn as-is; |
|
1944 |
however, the mask is applied if present. |
|
1945 |
||
1946 |
The form should have been allocated on the same device, |
|
1947 |
otherwise it's converted here, which slows down the draw. |
|
1948 |
No transformation or scaling is done. |
|
1949 |
Care must be taken, that the paint color is correctly allocated |
|
1950 |
(by sending #on: to the color) before doing so. |
|
1951 |
Using functions other than #copy only makes sense if you are |
|
1952 |
certain, that the colors are real colors (actually, only for |
|
1953 |
noColor or allColor)." |
|
1954 |
||
8281 | 1955 |
(aFormOrImage isImage and:[aFormOrImage hasAlphaChannel]) ifTrue:[ |
8005 | 1956 |
Error handle:[:ex | |
8010 | 1957 |
Logger error:'error when drawing alpha: %1' with:ex description. |
8005 | 1958 |
] do:[ |
1959 |
self displayDeviceFormWithAlpha:aFormOrImage x:x y:y. |
|
1960 |
]. |
|
8281 | 1961 |
^ self. |
8005 | 1962 |
]. |
1963 |
self displayDeviceFormNoAlpha:aFormOrImage x:x y:y. |
|
1964 |
||
1965 |
"Modified: / 11-04-2017 / 18:29:56 / cg" |
|
8315 | 1966 |
"Modified: / 20-03-2018 / 17:25:40 / stefan" |
8005 | 1967 |
! |
1968 |
||
1969 |
displayDeviceFormNoAlpha:aForm x:x y:y |
|
1970 |
"draw a form or image non opaque (i.e. only foreground color is drawn); |
|
1971 |
If it's a 1-plane bitmap, 1-bits are drawn in the |
|
1972 |
current paint-color, leaving pixels with 0-bits unchanged |
|
1973 |
(i.e. only 1-bits are drawn from the form). |
|
1974 |
||
7882 | 1975 |
If it's a deep form (i.e. a pixmap) the current paint |
6292 | 1976 |
settings are ignored and the form is drawn as-is; |
1592
7ec770f2047a
faster image drawing if masked pixels are known
Claus Gittinger <cg@exept.de>
parents:
1517
diff
changeset
|
1977 |
however, the mask is applied if present. |
7ec770f2047a
faster image drawing if masked pixels are known
Claus Gittinger <cg@exept.de>
parents:
1517
diff
changeset
|
1978 |
|
7752 | 1979 |
The form should have been allocated on the same device, |
7882 | 1980 |
otherwise it's converted here, which slows down the draw. |
732 | 1981 |
No transformation or scaling is done. |
6292 | 1982 |
Care must be taken, that the paint color is correctly allocated |
732 | 1983 |
(by sending #on: to the color) before doing so. |
1984 |
Using functions other than #copy only makes sense if you are |
|
1985 |
certain, that the colors are real colors (actually, only for |
|
1986 |
noColor or allColor)." |
|
1987 |
||
6497
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
1988 |
|id w h easy paintDither depth tmpForm tmpId tmpGCId |
6292 | 1989 |
fgId noColor allColor allBits pX pY |
7752 | 1990 |
mask maskId deviceForm deviceFormGCId deviceMask deviceMaskGcId colorMap| |
732 | 1991 |
|
1992 |
w := aForm width. |
|
1993 |
h := aForm height. |
|
6612
5c05ccaf6275
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6514
diff
changeset
|
1994 |
(w = 0 or:[h = 0]) ifTrue:[^ self]. |
732 | 1995 |
|
1996 |
pX := x rounded. |
|
1997 |
pY := y rounded. |
|
1998 |
||
1034 | 1999 |
deviceForm := aForm asFormOn:device. |
2192
01f76f23f03f
handle case when no deviceForms can be created,
Claus Gittinger <cg@exept.de>
parents:
2065
diff
changeset
|
2000 |
deviceForm isNil ifTrue:[ |
7629 | 2001 |
Logger warning:'cannot create device-form'. |
6484 | 2002 |
^self |
2192
01f76f23f03f
handle case when no deviceForms can be created,
Claus Gittinger <cg@exept.de>
parents:
2065
diff
changeset
|
2003 |
]. |
7629 | 2004 |
id := deviceForm drawableId. |
7752 | 2005 |
"temporary ... what the heck is this??" |
7629 | 2006 |
(id isNil |
2007 |
or:[aForm graphicsDevice ~~ device]) ifTrue:[ |
|
2008 |
deviceForm := deviceForm asFormOn:device. |
|
2009 |
id := deviceForm drawableId. |
|
2010 |
id isNil ifTrue:[ |
|
2011 |
Logger warning:'invalid form draw - ignored'. |
|
2012 |
^ self |
|
2013 |
]. |
|
732 | 2014 |
]. |
7629 | 2015 |
|
732 | 2016 |
gcId isNil ifTrue:[ |
6484 | 2017 |
self initGC |
732 | 2018 |
]. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2019 |
"/ device needGCForBitmapSource - i.e. WIN32 |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2020 |
device isWindowsPlatform ifTrue:[ |
7749 | 2021 |
deviceFormGCId := deviceForm initGC. |
2865
a97dc9f1e21a
no need to create a GC for source bitmap under X
Claus Gittinger <cg@exept.de>
parents:
2835
diff
changeset
|
2022 |
]. |
732 | 2023 |
|
2024 |
" |
|
2025 |
a deep form ignores paint/bgPaint settings |
|
2026 |
" |
|
1085
3513a4cae87b
handle depth1-images with a mask
Claus Gittinger <cg@exept.de>
parents:
1064
diff
changeset
|
2027 |
mask := aForm mask. |
6497
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2028 |
depth := aForm depth. |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2029 |
|
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2030 |
(mask notNil or:[depth ~~ 1]) ifTrue:[ |
6484 | 2031 |
mask notNil ifTrue:[ |
2032 |
mask depth ~~ 1 ifTrue:[ |
|
7980 | 2033 |
'DeviceGraphicsContext [info]: alpha channel not yet supported' errorPrintCR. |
6484 | 2034 |
] ifFalse:[ |
2035 |
deviceMask := mask asFormOn:device. |
|
2036 |
deviceMask isNil ifTrue:[ |
|
2037 |
'DeviceGraphicsContext [warning]: cannot create device-mask' errorPrintCR. |
|
2038 |
^self |
|
2039 |
]. |
|
7629 | 2040 |
maskId := deviceMask drawableId. |
6484 | 2041 |
maskId notNil ifTrue:[ |
7752 | 2042 |
deviceMaskGcId := deviceMask initGC. |
6484 | 2043 |
allColor := Color allColor. |
2044 |
allBits := allColor colorId. |
|
2045 |
||
6497
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2046 |
(aForm maskedPixelsAre0 |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2047 |
and:[depth == 1 or:[deviceForm depth == device depth]]) ifTrue:[ |
6484 | 2048 |
"/ can do it without a temporary pixmap: |
2049 |
"/ or-in the form into the inverse stamped-out area |
|
2050 |
"/ of the destination. |
|
2051 |
"/ Oring is of course only possible if we know that |
|
2052 |
"/ masked pixels are already zero in the form. |
|
2053 |
||
2054 |
"/ stamp out using mask |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2055 |
device |
8005 | 2056 |
setForeground:0 background:allBits function:#and in:gcId; |
6484 | 2057 |
copyPlaneFromPixmapId:maskId |
7980 | 2058 |
x:0 y:0 gc:deviceMaskGcId |
6497
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2059 |
to:drawableId |
7980 | 2060 |
x:pX y:pY gc:gcId |
2061 |
width:w height:h. |
|
6497
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2062 |
|
6484 | 2063 |
"/ or-in the form |
2064 |
device setFunction:#or in:gcId. |
|
6497
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2065 |
depth == 1 ifTrue:[ |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2066 |
(colorMap := deviceForm colorMap) notNil ifTrue:[ |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2067 |
colorMap size < 2 ifTrue:[ |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2068 |
device |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2069 |
setForegroundColor:(colorMap at:1) |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2070 |
backgroundColor:(Color noColor) |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2071 |
in:gcId. |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2072 |
] ifFalse:[ |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2073 |
device |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2074 |
setForegroundColor:(colorMap at:2) |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2075 |
backgroundColor:(colorMap at:1) |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2076 |
in:gcId. |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2077 |
] |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2078 |
]. |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2079 |
device |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2080 |
copyPlaneFromPixmapId:id |
7980 | 2081 |
x:0 y:0 gc:deviceFormGCId |
6497
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2082 |
to:drawableId |
7980 | 2083 |
x:pX y:pY gc:gcId |
2084 |
width:w height:h. |
|
6497
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2085 |
] ifFalse:[ |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2086 |
device |
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2087 |
copyFromPixmapId:id |
7980 | 2088 |
x:0 y:0 gc:deviceFormGCId |
6497
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2089 |
to:drawableId |
7980 | 2090 |
x:pX y:pY gc:gcId |
2091 |
width:w height:h. |
|
6497
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2092 |
]. |
6484 | 2093 |
] ifFalse:[ |
2094 |
"/ must do it slow, using a temporary form .. |
|
2095 |
||
8005 | 2096 |
"/ create temp-form; |
6484 | 2097 |
tmpForm := Form width:w height:h depth:device depth onDevice:device. |
2098 |
tmpForm isNil ifTrue:[ |
|
2099 |
'DeviceGraphicsContext [warning]: cannot create temp form' errorPrintCR. |
|
6497
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2100 |
^ self |
6484 | 2101 |
]. |
7629 | 2102 |
tmpId := tmpForm drawableId. |
7752 | 2103 |
tmpGCId := tmpForm initGC. |
6484 | 2104 |
|
8005 | 2105 |
"/ fill tempform with image |
6497
8edaeadf6658
Sending of Image>>#clearMaskedPixels moved to Image >> #asFormOnDevice:
Stefan Vogel <sv@exept.de>
parents:
6484
diff
changeset
|
2106 |
depth == 1 ifTrue:[ |
6484 | 2107 |
(colorMap := deviceForm colorMap) notNil ifTrue:[ |
2108 |
colorMap size < 2 ifTrue:[ |
|
8005 | 2109 |
device setForegroundColor:(colorMap at:1) in:tmpGCId. |
6484 | 2110 |
] ifFalse:[ |
2111 |
device |
|
2112 |
setForegroundColor:(colorMap at:2) |
|
2113 |
backgroundColor:(colorMap at:1) |
|
2114 |
in:tmpGCId. |
|
2115 |
] |
|
2116 |
]. |
|
2117 |
device |
|
2118 |
copyPlaneFromPixmapId:id |
|
7980 | 2119 |
x:0 y:0 gc:deviceFormGCId |
8005 | 2120 |
to:tmpId x:0 y:0 gc:tmpGCId |
7980 | 2121 |
width:w height:h. |
6484 | 2122 |
] ifFalse:[ |
2123 |
device |
|
2124 |
copyFromPixmapId:id |
|
7980 | 2125 |
x:0 y:0 gc:deviceFormGCId |
8005 | 2126 |
to:tmpId x:0 y:0 gc:tmpGCId |
7980 | 2127 |
width:w height:h. |
6484 | 2128 |
]. |
2129 |
||
8005 | 2130 |
"/ stamp out mask in temp form |
2131 |
"/ set unmasked pixels to allBits and masked pixels to 0 |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2132 |
device |
8005 | 2133 |
setForeground:allBits background:0 function:#and in:tmpGCId; |
6484 | 2134 |
copyPlaneFromPixmapId:maskId |
7980 | 2135 |
x:0 y:0 gc:deviceMaskGcId |
8005 | 2136 |
to:tmpId x:0 y:0 gc:tmpGCId |
7980 | 2137 |
width:w height:h. |
8005 | 2138 |
|
2139 |
"/ stamp out mask in destination |
|
2140 |
"/ set unmasked pixels to 0 and masked pixels to allBits |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2141 |
device |
8005 | 2142 |
setForeground:0 background:allBits function:#and in:gcId; |
6484 | 2143 |
copyPlaneFromPixmapId:maskId |
7980 | 2144 |
x:0 y:0 gc:deviceMaskGcId |
8005 | 2145 |
to:drawableId x:pX y:pY gc:gcId |
7980 | 2146 |
width:w height:h. |
6484 | 2147 |
|
8005 | 2148 |
"/ or-in tempform-bits ... |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2149 |
device |
8005 | 2150 |
setForeground:0 background:0 function:#or in:gcId; |
6484 | 2151 |
copyFromPixmapId:tmpId |
7980 | 2152 |
x:0 y:0 gc:tmpGCId |
8005 | 2153 |
to:drawableId x:pX y:pY gc:gcId |
7980 | 2154 |
width:w height:h. |
6484 | 2155 |
|
8005 | 2156 |
"/ release tempForm immediately |
2157 |
"/ (although GC will eventually do it, |
|
2158 |
"/ this creates less stress to the Xserver in the meanwhile ...) |
|
6484 | 2159 |
tmpForm destroy. |
2160 |
]. |
|
2161 |
||
2162 |
"/ restore GC |
|
2163 |
foreground notNil ifTrue:[ |
|
2164 |
device setForegroundColor:foreground in:gcId. |
|
2165 |
]. |
|
2166 |
background notNil ifTrue:[ |
|
2167 |
device setBackgroundColor:background in:gcId |
|
2168 |
]. |
|
2169 |
device setFunction:function in:gcId. |
|
2170 |
^ self |
|
2171 |
] |
|
2172 |
] |
|
2173 |
]. |
|
2174 |
device |
|
2175 |
copyFromPixmapId:id |
|
7980 | 2176 |
x:0 y:0 gc:deviceFormGCId |
6484 | 2177 |
to:drawableId |
7980 | 2178 |
x:pX y:pY gc:gcId |
2179 |
width:w height:h. |
|
6484 | 2180 |
^ self |
732 | 2181 |
]. |
2182 |
||
8005 | 2183 |
"/ the following code is somewhat complicated, since it has to deal |
2184 |
"/ with dithered paint colors, which cannot be done directly on most |
|
2185 |
"/ devices (actually, a test for the device's capabilities has to be added here) |
|
2186 |
"/ (just assume drawing a bitmap with dithered paint color ... sigh) |
|
1507 | 2187 |
easy := (function == #copy). |
2188 |
||
8005 | 2189 |
"/ if paint is not a real color, we have to do it the hard way ... |
732 | 2190 |
easy ifTrue:[ |
6484 | 2191 |
paint isColor ifTrue:[ |
2192 |
paintDither := paint ditherForm. |
|
2193 |
paintDither notNil ifTrue:[ |
|
2194 |
easy := false. |
|
2195 |
] |
|
2196 |
] ifFalse:[ |
|
2197 |
paintDither := paint. |
|
2198 |
easy := false |
|
2199 |
]. |
|
732 | 2200 |
]. |
2201 |
||
2202 |
allColor := Color allColor. |
|
2203 |
allBits := allColor colorId. |
|
2204 |
||
2205 |
easy ifTrue:[ |
|
8005 | 2206 |
"/ paint is a real color |
2207 |
||
2208 |
"/ if paint color is all-0 or all-1's, we can do it in one operation ... |
|
6484 | 2209 |
fgId := paint colorId. |
2210 |
||
2211 |
((fgId ~~ ((1 bitShift:device depth)-1)) |
|
2212 |
and:[fgId ~~ allBits]) ifTrue:[ |
|
8005 | 2213 |
"/ clear fg-bits ... |
2214 |
device setForeground:0 background:allBits function:#and in:gcId. |
|
6484 | 2215 |
device |
2216 |
copyPlaneFromPixmapId:id |
|
7980 | 2217 |
x:0 y:0 gc:deviceFormGCId |
6484 | 2218 |
to:drawableId |
7980 | 2219 |
x:pX y:pY gc:gcId |
2220 |
width:w height:h. |
|
6484 | 2221 |
]. |
2222 |
||
2223 |
fgId ~~ 0 ifTrue:[ |
|
8005 | 2224 |
"/ or-in fg-bits ... |
2225 |
device setForeground:fgId background:0 function:#or in:gcId. |
|
6484 | 2226 |
device |
2227 |
copyPlaneFromPixmapId:id |
|
7980 | 2228 |
x:0 y:0 gc:deviceFormGCId |
6484 | 2229 |
to:drawableId |
7980 | 2230 |
x:pX y:pY gc:gcId |
2231 |
width:w height:h |
|
6484 | 2232 |
]. |
8005 | 2233 |
"/ flush foreground/background cache |
7980 | 2234 |
device setForegroundColor:foreground backgroundColor:background in:gcId. |
6484 | 2235 |
device setFunction:function in:gcId. |
2236 |
^ self |
|
732 | 2237 |
]. |
2238 |
||
1507 | 2239 |
function == #or ifTrue:[ |
6484 | 2240 |
easy := paint notNil |
2241 |
and:[paint isColor |
|
2242 |
and:[paint ditherForm isNil]]. |
|
2243 |
easy ifTrue:[ |
|
2244 |
easy := bgPaint isNil |
|
2245 |
or:[bgPaint isColor |
|
2246 |
and:[bgPaint colorId == 0]] |
|
2247 |
]. |
|
2248 |
easy ifTrue:[ |
|
2249 |
fgId := paint colorId. |
|
2250 |
||
2251 |
fgId ~~ 0 ifTrue:[ |
|
8005 | 2252 |
"/ or-in fg-bits ... |
6484 | 2253 |
device setForeground:fgId background:0 in:gcId. |
2254 |
device |
|
2255 |
copyPlaneFromPixmapId:id |
|
7980 | 2256 |
x:0 y:0 gc:deviceFormGCId |
6484 | 2257 |
to:drawableId |
7980 | 2258 |
x:pX y:pY gc:gcId |
2259 |
width:w height:h |
|
6484 | 2260 |
]. |
8005 | 2261 |
"/ flush foreground/background cache |
6484 | 2262 |
foreground := nil. |
2263 |
background := nil. |
|
2264 |
^ self |
|
2265 |
]. |
|
1507 | 2266 |
]. |
732 | 2267 |
|
8005 | 2268 |
"/ hard case; paint is a dithered color |
732 | 2269 |
noColor := Color noColor. |
2270 |
||
8005 | 2271 |
"/ create temp-form; |
4756
dd597f8839cb
changed #displayDeviceForm:x:y:
Claus Gittinger <cg@exept.de>
parents:
4752
diff
changeset
|
2272 |
tmpForm := Form width:w height:h depth:device depth onDevice:device. |
2192
01f76f23f03f
handle case when no deviceForms can be created,
Claus Gittinger <cg@exept.de>
parents:
2065
diff
changeset
|
2273 |
tmpForm isNil ifTrue:[ |
6484 | 2274 |
'DeviceGraphicsContext [warning]: cannot create temp form' errorPrintCR. |
2275 |
^self |
|
2192
01f76f23f03f
handle case when no deviceForms can be created,
Claus Gittinger <cg@exept.de>
parents:
2065
diff
changeset
|
2276 |
]. |
8005 | 2277 |
|
2278 |
"/ fill tempform |
|
2279 |
tmpForm paint:paint; fillRectangleX:0 y:0 width:w height:h. |
|
2280 |
||
2281 |
"/ stamp out background |
|
2282 |
tmpForm paint:allColor on:noColor; function:#and. |
|
976 | 2283 |
tmpForm displayOpaqueForm:deviceForm x:0 y:0. |
8005 | 2284 |
|
2285 |
"/ stamp out foreground from destination |
|
2286 |
device setForeground:0 background:allBits function:#and in:gcId. |
|
732 | 2287 |
device |
6484 | 2288 |
copyPlaneFromPixmapId:id |
8005 | 2289 |
x:0 y:0 |
6484 | 2290 |
gc:deviceFormGCId |
8005 | 2291 |
to:drawableId x:pX y:pY |
2292 |
gc:gcId width:w height:h. |
|
2293 |
||
2294 |
"/ or-in temp into destination |
|
2295 |
device setForeground:allBits background:0 function:#or in:gcId. |
|
732 | 2296 |
|
2297 |
device |
|
7629 | 2298 |
copyFromPixmapId:tmpForm drawableId |
8005 | 2299 |
x:0 y:0 |
6484 | 2300 |
gc:tmpForm gcId |
8005 | 2301 |
to:drawableId x:pX y:pY |
2302 |
gc:gcId width:w height:h. |
|
2303 |
||
2304 |
"/ release tempForm immediately |
|
2305 |
"/ (although GC will eventually do it, |
|
2306 |
"/ this creates less stress to the Xserver in the meanwhile ...) |
|
1637
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
2307 |
|
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
2308 |
tmpForm destroy. |
8005 | 2309 |
|
2310 |
"/ flush foreground/background cache |
|
732 | 2311 |
foreground := nil. |
2312 |
background := nil. |
|
2313 |
device setFunction:function in:gcId. |
|
768 | 2314 |
|
8005 | 2315 |
"Created: / 11-04-2017 / 16:45:18 / cg" |
2316 |
! |
|
2317 |
||
2318 |
displayDeviceFormWithAlpha:anImage x:x y:y |
|
8008 | 2319 |
"draw a form or image non opaque; |
2320 |
The current paint settings are ignored and the image is drawn as-is; |
|
8143 | 2321 |
however, the alpha channel is taken care of. |
8008 | 2322 |
This is a (slow) fallback helper for displays which do not support alpha blending" |
8005 | 2323 |
|
8281 | 2324 |
|bytesPerLine orgDstData |
2325 |
dstBytes imgBytes info w h pX pY bppDrawable |
|
8005 | 2326 |
dstBytesPerRow "{Class: SmallInteger}" |
2327 |
imgBytesPerRow "{Class: SmallInteger}" |
|
2328 |
dstIndex "{Class: SmallInteger}" |
|
2329 |
imgIndex "{Class: SmallInteger}" |
|
2330 |
dstRowIndex "{Class: SmallInteger}" |
|
8010 | 2331 |
imgRowIndex "{Class: SmallInteger}" |
2332 |
oB "{Class: SmallInteger}" |
|
2333 |
oR "{Class: SmallInteger}" |
|
8281 | 2334 |
oG "{Class: SmallInteger}" |
2335 |
iR "{Class: SmallInteger}" |
|
2336 |
iG "{Class: SmallInteger}" |
|
2337 |
iB "{Class: SmallInteger}" |
|
2338 |
iA "{Class: SmallInteger}" |
|
2339 |
try | |
|
2340 |
||
2341 |
device flush. |
|
8005 | 2342 |
device sync. |
2343 |
||
2344 |
w := anImage width. |
|
2345 |
h := anImage height. |
|
2346 |
(w = 0 or:[h = 0]) ifTrue:[^ self]. |
|
2347 |
||
2348 |
pX := x rounded. |
|
2349 |
pY := y rounded. |
|
2350 |
||
2351 |
"/ give it more than enough bytes |
|
2352 |
bytesPerLine := (w * 32 + 31) // 32 * 4. |
|
8281 | 2353 |
dstBytes := ByteArray uninitializedNew:(bytesPerLine * h). |
2354 |
||
2355 |
"/ OSX XQuartz bug workaround |
|
2356 |
"/ if I do this, the Inspector can read the window's bits |
|
2357 |
"/ (sometimes after a retry) |
|
2358 |
"/ however, the imageEditor stil has problems to show the image |
|
2359 |
"/ in its lower left preview area. |
|
2360 |
"/ This should really really not be required!!!!!! |
|
2361 |
try := 1. |
|
2362 |
Error handle:[:ex | |
|
2363 |
try < 5 ifTrue:[ |
|
2364 |
try := try + 1. |
|
2365 |
device flush. |
|
2366 |
device sync. |
|
2367 |
Delay waitForMilliseconds:20. |
|
2368 |
device flush. |
|
2369 |
device sync. |
|
2370 |
ex restart. |
|
2371 |
]. |
|
2372 |
ex reject |
|
2373 |
] do:[ |
|
2374 |
drawableType == #pixmap ifTrue:[ |
|
2375 |
info := device getBitsFromPixmapId:(self drawableId) x:pX y:pY width:w height:h into:dstBytes. |
|
2376 |
] ifFalse:[ |
|
2377 |
info := device getBitsFromViewId:(self drawableId) x:pX y:pY width:w height:h into:dstBytes. |
|
2378 |
]. |
|
8005 | 2379 |
]. |
2380 |
dstBytesPerRow := info at:#bytesPerLine. |
|
2381 |
imgBytesPerRow := anImage bytesPerRow. |
|
2382 |
||
8281 | 2383 |
imgBytes := anImage bits. |
2384 |
orgDstData := dstBytes copy. |
|
2385 |
||
2386 |
iR := 0. |
|
2387 |
iG := 1. |
|
2388 |
iB := 2. |
|
2389 |
iA := 3. |
|
2390 |
anImage photometric == #argb ifTrue:[ |
|
2391 |
iA := 0. |
|
2392 |
iR := 1. |
|
2393 |
iG := 2. |
|
2394 |
iB := 3. |
|
2395 |
]. |
|
2396 |
||
2397 |
"/ TODO: the following code is a nr1 candidate for inline c-code |
|
8005 | 2398 |
bppDrawable := info at:#bitsPerPixel. |
2399 |
bppDrawable == 32 ifTrue:[ |
|
2400 |
"/ data is coming as bytes in r,g,b,a order |
|
2401 |
dstRowIndex := 1. |
|
2402 |
imgRowIndex := 1. |
|
2403 |
||
8010 | 2404 |
oR := 2. |
2405 |
oG := 1. |
|
2406 |
oB := 0. |
|
2407 |
||
8005 | 2408 |
"/ draw "by hand" here |
2409 |
0 to:h-1 do:[:y | |
|
2410 |
dstIndex := dstRowIndex. |
|
2411 |
imgIndex := imgRowIndex. |
|
2412 |
0 to:w-1 do:[:x | |
|
2413 |
|rD "{Class: SmallInteger}" |
|
2414 |
gD "{Class: SmallInteger}" |
|
2415 |
bD "{Class: SmallInteger}" |
|
2416 |
rI "{Class: SmallInteger}" |
|
2417 |
gI "{Class: SmallInteger}" |
|
2418 |
bI "{Class: SmallInteger}" |
|
2419 |
aI "{Class: SmallInteger}" |
|
2420 |
aD "{Class: SmallInteger}" |
|
2421 |
nR "{Class: SmallInteger}" |
|
2422 |
nG "{Class: SmallInteger}" |
|
2423 |
nB "{Class: SmallInteger}"| |
|
2424 |
||
8281 | 2425 |
rD := dstBytes at:(dstIndex+oR). |
2426 |
gD := dstBytes at:(dstIndex+oG). |
|
2427 |
bD := dstBytes at:(dstIndex+oB). |
|
2428 |
||
2429 |
rI := imgBytes at:(imgIndex+iR). |
|
2430 |
gI := imgBytes at:(imgIndex+iG). |
|
2431 |
bI := imgBytes at:(imgIndex+iB). |
|
2432 |
aI := imgBytes at:(imgIndex+iA). |
|
8005 | 2433 |
|
2434 |
aI == 255 ifTrue:[ |
|
2435 |
nR := rI. |
|
2436 |
nG := gI. |
|
2437 |
nB := bI. |
|
2438 |
] ifFalse:[ |
|
2439 |
aI == 0 ifTrue:[ |
|
2440 |
nR := rD. |
|
2441 |
nG := gD. |
|
2442 |
nB := bD. |
|
2443 |
] ifFalse:[ |
|
2444 |
aD := 255 - aI. |
|
2445 |
||
2446 |
nR := (((rI * aI)+(rD * aD)) // 255). |
|
2447 |
nG := (((gI * aI)+(gD * aD)) // 255). |
|
2448 |
nB := (((bI * aI)+(bD * aD)) // 255). |
|
2449 |
]. |
|
2450 |
]. |
|
8281 | 2451 |
"/ dstBytes at:(dstIndex) put:255. |
2452 |
dstBytes at:(dstIndex+1) put:nR. |
|
2453 |
dstBytes at:(dstIndex+2) put:nG. |
|
2454 |
dstBytes at:(dstIndex+3) put:nB. |
|
8005 | 2455 |
|
2456 |
dstIndex := dstIndex + 4. |
|
2457 |
imgIndex := imgIndex + 4. |
|
2458 |
]. |
|
2459 |
dstRowIndex := dstRowIndex + dstBytesPerRow. |
|
2460 |
imgRowIndex := imgRowIndex + imgBytesPerRow. |
|
2461 |
]. |
|
2462 |
"/ draw the pixels (always MSB) |
|
2463 |
device |
|
8281 | 2464 |
drawBits:dstBytes bitsPerPixel:32 depth:24 padding:32 |
8009 | 2465 |
width:w height:h x:0 y:0 |
2466 |
into:(self drawableId) x:pX y:pY width:w height:h with:gcId. |
|
8281 | 2467 |
|
2468 |
device flush. |
|
2469 |
device sync. |
|
8009 | 2470 |
^ self. |
2471 |
]. |
|
8281 | 2472 |
|
8009 | 2473 |
bppDrawable == 24 ifTrue:[ |
2474 |
"/ data is coming as bytes in r,g,b order |
|
2475 |
dstRowIndex := 1. |
|
2476 |
imgRowIndex := 1. |
|
2477 |
||
8010 | 2478 |
(info at:#byteOrder) == #lsbFirst ifTrue:[ |
8143 | 2479 |
oR := 0. oG := 1. oB := 2. |
8010 | 2480 |
] ifFalse:[ |
8143 | 2481 |
oR := 2. oG := 1. oB := 0. |
8010 | 2482 |
]. |
2483 |
||
8009 | 2484 |
"/ draw "by hand" here |
2485 |
0 to:h-1 do:[:y | |
|
2486 |
dstIndex := dstRowIndex. |
|
2487 |
imgIndex := imgRowIndex. |
|
2488 |
0 to:w-1 do:[:x | |
|
2489 |
|rD "{Class: SmallInteger}" |
|
2490 |
gD "{Class: SmallInteger}" |
|
2491 |
bD "{Class: SmallInteger}" |
|
2492 |
rI "{Class: SmallInteger}" |
|
2493 |
gI "{Class: SmallInteger}" |
|
2494 |
bI "{Class: SmallInteger}" |
|
2495 |
aI "{Class: SmallInteger}" |
|
2496 |
aD "{Class: SmallInteger}" |
|
2497 |
nR "{Class: SmallInteger}" |
|
2498 |
nG "{Class: SmallInteger}" |
|
2499 |
nB "{Class: SmallInteger}"| |
|
2500 |
||
8281 | 2501 |
rD := dstBytes at:(dstIndex+oR). |
2502 |
gD := dstBytes at:(dstIndex+oG). |
|
2503 |
bD := dstBytes at:(dstIndex+oB). |
|
2504 |
||
2505 |
rI := imgBytes at:(imgIndex+iR). |
|
2506 |
gI := imgBytes at:(imgIndex+iG). |
|
2507 |
bI := imgBytes at:(imgIndex+iB). |
|
2508 |
aI := imgBytes at:(imgIndex+iA). |
|
8009 | 2509 |
|
2510 |
aI == 255 ifTrue:[ |
|
2511 |
nR := rI. |
|
2512 |
nG := gI. |
|
2513 |
nB := bI. |
|
2514 |
] ifFalse:[ |
|
2515 |
aI == 0 ifTrue:[ |
|
2516 |
nR := rD. |
|
2517 |
nG := gD. |
|
2518 |
nB := bD. |
|
2519 |
] ifFalse:[ |
|
2520 |
aD := 255 - aI. |
|
2521 |
||
2522 |
nR := (((rI * aI)+(rD * aD)) // 255). |
|
2523 |
nG := (((gI * aI)+(gD * aD)) // 255). |
|
2524 |
nB := (((bI * aI)+(bD * aD)) // 255). |
|
2525 |
]. |
|
2526 |
]. |
|
8281 | 2527 |
dstBytes at:(dstIndex+2) put:nR. |
2528 |
dstBytes at:(dstIndex+1) put:nG. |
|
2529 |
dstBytes at:(dstIndex+0) put:nB. |
|
8009 | 2530 |
|
2531 |
dstIndex := dstIndex + 3. |
|
2532 |
imgIndex := imgIndex + 4. |
|
2533 |
]. |
|
2534 |
dstRowIndex := dstRowIndex + dstBytesPerRow. |
|
2535 |
imgRowIndex := imgRowIndex + imgBytesPerRow. |
|
2536 |
]. |
|
2537 |
"/ draw the pixels (always MSB) |
|
2538 |
device |
|
8281 | 2539 |
drawBits:dstBytes bitsPerPixel:24 depth:24 padding:32 |
8005 | 2540 |
width:w height:h x:0 y:0 |
2541 |
into:(self drawableId) x:pX y:pY width:w height:h with:gcId. |
|
8281 | 2542 |
|
2543 |
device flush. |
|
2544 |
device sync. |
|
8005 | 2545 |
^ self. |
2546 |
]. |
|
8281 | 2547 |
|
2548 |
Logger info:'(X11GC): drawing alpha into non24, non-32 displays is currently not supported'. |
|
2549 |
self displayDeviceFormNoAlpha:anImage x:x y:y. |
|
8005 | 2550 |
|
2551 |
"Created: / 11-04-2017 / 16:45:39 / cg" |
|
8008 | 2552 |
"Modified: / 12-04-2017 / 10:38:52 / cg" |
732 | 2553 |
! |
2554 |
||
2555 |
displayDeviceLineFromX:x0 y:y0 toX:x1 y:y1 |
|
2556 |
"draw a line (with current paint-color) in device coordinate space. |
|
2557 |
This ignores any transformations. The coordinates must be integers." |
|
2558 |
||
2559 |
gcId isNil ifTrue:[ |
|
2560 |
self initGC |
|
2561 |
]. |
|
2562 |
device displayLineFromX:x0 y:y0 toX:x1 y:y1 in:drawableId with:gcId |
|
2563 |
! |
|
2564 |
||
8154 | 2565 |
displayDeviceOpaqueForm:aFormOrImage x:x y:y |
2566 |
"draw a form or image opaque (i.e. both fg and bg is drawn) |
|
2567 |
Somewhat backward compatible hacky: |
|
2568 |
||
2569 |
if it's a 1-plane form, |
|
2570 |
1-bits are drawn in the current paint-color and |
|
2571 |
0-bits in the bgPaint color. |
|
2572 |
||
2573 |
If it's a deep form (i.e. a pixmap) or an image, |
|
2574 |
the current paint/bgPaint settings are ignored and the image is drawn as-is. |
|
2575 |
||
6292 | 2576 |
In the 1-plane case, special care must be taken if paint and/or bgPaint |
732 | 2577 |
dithered colors or patterns, since are that the colors are correctly allocated (by sending #on: |
2578 |
to the colors) before doing so. |
|
1592
7ec770f2047a
faster image drawing if masked pixels are known
Claus Gittinger <cg@exept.de>
parents:
1517
diff
changeset
|
2579 |
The form should have been allocated on the same device; otherwise, |
7ec770f2047a
faster image drawing if masked pixels are known
Claus Gittinger <cg@exept.de>
parents:
1517
diff
changeset
|
2580 |
its converted here, which slows down the draw. |
732 | 2581 |
Drawing is in device coordinates; no scaling is done." |
2582 |
||
6292 | 2583 |
|id w h easy savedPaint bgForm fgForm tmpForm |
732 | 2584 |
fgId bgId noColor allColor allBits dx dy |
8315 | 2585 |
pX pY deviceDepth deviceForm deviceFormGCId map paintClr bgPaintClr| |
2586 |
||
2587 |
(aFormOrImage isImage and:[aFormOrImage hasAlphaChannel]) ifTrue:[ |
|
2588 |
"Drawing opaque with alpha-channel does not really make sense. |
|
2589 |
Draw non-opaque." |
|
2590 |
Error handle:[:ex | |
|
2591 |
Logger error:'error when drawing alpha: %1' with:ex description. |
|
2592 |
] do:[ |
|
2593 |
self displayDeviceFormWithAlpha:aFormOrImage x:x y:y. |
|
2594 |
]. |
|
2595 |
^ self. |
|
2596 |
]. |
|
732 | 2597 |
|
8154 | 2598 |
deviceForm := aFormOrImage asFormOn:device. |
8174 | 2599 |
deviceForm isNil ifTrue:[ |
2600 |
Logger warning:'invalid form draw (no device form) - ignored'. |
|
2601 |
^ self |
|
2602 |
]. |
|
7629 | 2603 |
id := deviceForm drawableId. |
732 | 2604 |
|
2605 |
"temporary ..." |
|
8154 | 2606 |
(id isNil or:[aFormOrImage graphicsDevice ~~ device]) ifTrue:[ |
7629 | 2607 |
deviceForm := deviceForm asFormOn:device. |
2608 |
id := deviceForm drawableId. |
|
2609 |
id isNil ifTrue:[ |
|
2610 |
Logger warning:'invalid form draw (opaque) - ignored'. |
|
2611 |
^ self |
|
2612 |
]. |
|
732 | 2613 |
]. |
2614 |
||
2615 |
gcId isNil ifTrue:[ |
|
7629 | 2616 |
self initGC |
732 | 2617 |
]. |
2618 |
||
8154 | 2619 |
w := aFormOrImage width. |
2620 |
h := aFormOrImage height. |
|
1592
7ec770f2047a
faster image drawing if masked pixels are known
Claus Gittinger <cg@exept.de>
parents:
1517
diff
changeset
|
2621 |
|
7ec770f2047a
faster image drawing if masked pixels are known
Claus Gittinger <cg@exept.de>
parents:
1517
diff
changeset
|
2622 |
pX := x rounded. |
7ec770f2047a
faster image drawing if masked pixels are known
Claus Gittinger <cg@exept.de>
parents:
1517
diff
changeset
|
2623 |
pY := y rounded. |
7ec770f2047a
faster image drawing if masked pixels are known
Claus Gittinger <cg@exept.de>
parents:
1517
diff
changeset
|
2624 |
|
8315 | 2625 |
deviceForm isForm ifTrue:[ |
2626 |
deviceFormGCId := deviceForm initGC. |
|
2627 |
]. |
|
902 | 2628 |
" |
2629 |
a deep form ignores paint/bgPaint settings |
|
2630 |
and is always drawn opaque. |
|
2631 |
" |
|
8154 | 2632 |
(aFormOrImage depth ~~ 1) ifTrue:[ |
7629 | 2633 |
device |
2634 |
copyFromPixmapId:id |
|
7980 | 2635 |
x:0 y:0 gc:deviceFormGCId |
7629 | 2636 |
to:drawableId |
7980 | 2637 |
x:pX y:pY gc:gcId |
2638 |
width:w height:h. |
|
7629 | 2639 |
^ self |
902 | 2640 |
]. |
7980 | 2641 |
|
2642 |
paintClr := paint. |
|
2643 |
bgPaintClr := bgPaint. |
|
8154 | 2644 |
|
2645 |
"/ images are always drawn with its own colors |
|
2646 |
aFormOrImage isImage ifTrue:[ |
|
2647 |
paintClr := aFormOrImage colorFromValue:1. |
|
2648 |
bgPaintClr := aFormOrImage colorFromValue:0. |
|
2649 |
] ifFalse:[ |
|
2650 |
"/ a form is drawn in the current paint/bgPaint, |
|
2651 |
"/ it has an explicit colormap |
|
2652 |
map := aFormOrImage colorMap. |
|
2653 |
map notNil ifTrue:[ |
|
2654 |
paintClr := map at:2. |
|
2655 |
bgPaintClr := map at:1. |
|
2656 |
]. |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2657 |
]. |
902 | 2658 |
|
2659 |
"/ if no bgPaint is set, this is a non-opaque draw |
|
7980 | 2660 |
bgPaintClr isNil ifTrue:[ |
8154 | 2661 |
self displayDeviceForm:aFormOrImage x:x y:y. |
7629 | 2662 |
^ self |
902 | 2663 |
]. |
2664 |
||
732 | 2665 |
"the following code is somewhat complicated, since it has to deal |
2666 |
with dithered fg/bg colors, which cannot be done directly on most |
|
2667 |
devices (actually, a test for the devices capabilities has to be added here) |
|
2668 |
(just assume drawing a bitmap with dithered fg/bg colors ... sigh) |
|
2669 |
" |
|
2670 |
||
2671 |
" |
|
2672 |
if bgPaint or paint is not a real color, we have to do it the hard way ... |
|
2673 |
" |
|
2674 |
easy := true. |
|
7980 | 2675 |
paintClr isColor ifFalse:[ |
7629 | 2676 |
easy := false |
732 | 2677 |
] ifTrue:[ |
7980 | 2678 |
fgId := paintClr colorId. |
7629 | 2679 |
fgId isNil ifTrue:[ |
2680 |
easy := false |
|
2681 |
] |
|
732 | 2682 |
]. |
7980 | 2683 |
bgPaintClr isColor ifFalse:[ |
7629 | 2684 |
easy := false |
732 | 2685 |
] ifTrue:[ |
7980 | 2686 |
bgId := bgPaintClr colorId. |
7629 | 2687 |
bgId isNil ifTrue:[ |
2688 |
easy := false |
|
2689 |
] |
|
732 | 2690 |
]. |
2691 |
||
2692 |
easy ifTrue:[ |
|
7629 | 2693 |
" |
2694 |
easy: both paint and bgPaint are real colors |
|
2695 |
" |
|
7980 | 2696 |
((foreground ~~ paintClr) or:[background ~~ bgPaintClr]) ifTrue:[ |
7629 | 2697 |
device setForeground:fgId background:bgId in:gcId. |
7980 | 2698 |
"/ foreground := paint. |
2699 |
"/ background := bgPaint. |
|
7629 | 2700 |
]. |
2701 |
device |
|
7980 | 2702 |
copyPlaneFromPixmapId:id x:0 y:0 gc:deviceFormGCId |
2703 |
to:drawableId x:pX y:pY gc:gcId |
|
2704 |
width:w height:h. |
|
2705 |
||
8154 | 2706 |
"/ restore |
2707 |
foreground notNil ifTrue:[ device setForegroundColor:foreground in:gcId ]. |
|
2708 |
background notNil ifTrue:[ device setBackgroundColor:background in:gcId ]. |
|
7629 | 2709 |
^ self |
732 | 2710 |
]. |
2711 |
||
2712 |
" |
|
2713 |
hard case: paint and/or bgPaint are dithered or patterns |
|
2714 |
" |
|
2715 |
allColor := Color allColor. |
|
2716 |
allBits := allColor colorId. |
|
2717 |
deviceDepth := device depth. |
|
2718 |
||
2719 |
(fgId notNil and:[function == #copy]) ifTrue:[ |
|
7629 | 2720 |
" |
2721 |
only bg is dithered; fill with bg first ... |
|
2722 |
" |
|
2723 |
savedPaint := paint. |
|
7980 | 2724 |
self paint:bgPaintClr. |
7629 | 2725 |
self fillDeviceRectangleX:pX y:pY width:w height:h. |
2726 |
self paint:savedPaint. |
|
2727 |
||
2728 |
" |
|
2729 |
if paint color is all-0 or all-1's, we can do it in one |
|
2730 |
operation ... |
|
2731 |
" |
|
2732 |
((fgId ~~ ((1 bitShift:deviceDepth)-1)) |
|
2733 |
and:[fgId ~~ allBits]) ifTrue:[ |
|
2734 |
" |
|
2735 |
clear fg-bits ... |
|
2736 |
" |
|
2737 |
device setForeground:0 background:allBits in:gcId. |
|
2738 |
device setFunction:#and in:gcId. |
|
2739 |
device |
|
2740 |
copyPlaneFromPixmapId:id |
|
2741 |
x:0 |
|
2742 |
y:0 |
|
7749 | 2743 |
gc:deviceFormGCId |
7629 | 2744 |
to:drawableId |
2745 |
x:pX |
|
2746 |
y:pY |
|
2747 |
gc:gcId |
|
2748 |
width:w |
|
2749 |
height:h |
|
2750 |
]. |
|
2751 |
||
2752 |
fgId ~~ 0 ifTrue:[ |
|
2753 |
" |
|
2754 |
or-in fg-bits ... |
|
2755 |
" |
|
2756 |
device setForeground:fgId background:0 in:gcId. |
|
2757 |
device setFunction:#or in:gcId. |
|
2758 |
device |
|
2759 |
copyPlaneFromPixmapId:id |
|
2760 |
x:0 |
|
2761 |
y:0 |
|
7749 | 2762 |
gc:deviceFormGCId |
7629 | 2763 |
to:drawableId |
2764 |
x:pX |
|
2765 |
y:pY |
|
2766 |
gc:gcId |
|
2767 |
width:w |
|
2768 |
height:h |
|
2769 |
]. |
|
2770 |
" |
|
2771 |
flush foreground/background cache |
|
2772 |
" |
|
7980 | 2773 |
"/ foreground := nil. |
2774 |
"/ background := nil. |
|
2775 |
device setForegroundColor:foreground backgroundColor:background in:gcId. |
|
7629 | 2776 |
device setFunction:function in:gcId. |
2777 |
^ self |
|
732 | 2778 |
]. |
2779 |
||
2780 |
(bgId notNil and:[function == #copy]) ifTrue:[ |
|
7629 | 2781 |
" |
2782 |
only fg is dithered; fill with fg first ... |
|
2783 |
" |
|
2784 |
self fillDeviceRectangleX:pX y:pY width:w height:h. |
|
2785 |
||
2786 |
" |
|
2787 |
if paint color is all-0 or all-1's, we can do it in one |
|
2788 |
operation ... |
|
2789 |
" |
|
2790 |
((bgId ~~ ((1 bitShift:deviceDepth)-1)) |
|
2791 |
and:[bgId ~~ allBits]) ifTrue:[ |
|
2792 |
" |
|
2793 |
clear bg-bits ... |
|
2794 |
" |
|
2795 |
device setForeground:allBits background:0 in:gcId. |
|
2796 |
device setFunction:#and in:gcId. |
|
2797 |
device |
|
2798 |
copyPlaneFromPixmapId:id |
|
2799 |
x:0 |
|
2800 |
y:0 |
|
7749 | 2801 |
gc:deviceFormGCId |
7629 | 2802 |
to:drawableId |
2803 |
x:pX |
|
2804 |
y:pY |
|
2805 |
gc:gcId |
|
2806 |
width:w |
|
2807 |
height:h |
|
2808 |
]. |
|
2809 |
||
2810 |
" |
|
2811 |
or-in bg-bits ... |
|
2812 |
" |
|
2813 |
bgId ~~ 0 ifTrue:[ |
|
2814 |
device setForeground:0 background:bgId in:gcId. |
|
2815 |
device setFunction:#or in:gcId. |
|
2816 |
device |
|
2817 |
copyPlaneFromPixmapId:id |
|
2818 |
x:0 |
|
2819 |
y:0 |
|
7749 | 2820 |
gc:deviceFormGCId |
7629 | 2821 |
to:drawableId |
2822 |
x:pX |
|
2823 |
y:pY |
|
2824 |
gc:gcId |
|
2825 |
width:w |
|
2826 |
height:h |
|
2827 |
]. |
|
2828 |
" |
|
2829 |
flush foreground/background cache |
|
2830 |
" |
|
2831 |
foreground := nil. |
|
2832 |
background := nil. |
|
2833 |
device setFunction:function in:gcId. |
|
2834 |
^ self |
|
732 | 2835 |
]. |
2836 |
||
2837 |
" |
|
2838 |
very hard case; both fg and bg are dithered colors |
|
2839 |
" |
|
2840 |
noColor := Color noColor. |
|
2841 |
||
2842 |
" |
|
2843 |
create temp-forms; |
|
2844 |
" |
|
4781
7f2473db5652
Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents:
4756
diff
changeset
|
2845 |
bgForm := Form width:w height:h depth:deviceDepth onDevice:device. |
7f2473db5652
Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents:
4756
diff
changeset
|
2846 |
fgForm := Form width:w height:h depth:deviceDepth onDevice:device. |
7f2473db5652
Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents:
4756
diff
changeset
|
2847 |
tmpForm := Form width:w height:h depth:deviceDepth onDevice:device. |
732 | 2848 |
|
2849 |
" |
|
2850 |
fill |
|
2851 |
" |
|
2852 |
dx := dy := 0. |
|
2853 |
maskOrigin notNil ifTrue:[ |
|
7629 | 2854 |
dx := maskOrigin x. |
2855 |
dy := maskOrigin y |
|
732 | 2856 |
]. |
2857 |
||
2858 |
bgForm paint:bgPaint. |
|
4983
14c28ec55880
Replace usage of obsolete methods
Stefan Vogel <sv@exept.de>
parents:
4914
diff
changeset
|
2859 |
bgForm maskOriginX:(x negated + dx) y:(y negated + dy). |
732 | 2860 |
bgForm fillRectangleX:0 y:0 width:w height:h. |
2861 |
fgForm paint:paint. |
|
4983
14c28ec55880
Replace usage of obsolete methods
Stefan Vogel <sv@exept.de>
parents:
4914
diff
changeset
|
2862 |
fgForm maskOriginX:(x negated + dx) y:(y negated + dy). |
732 | 2863 |
fgForm fillRectangleX:0 y:0 width:w height:h. |
2864 |
||
2865 |
" |
|
2866 |
stamp-out background |
|
2867 |
" |
|
2868 |
bgForm paint:noColor on:allColor. |
|
2869 |
bgForm function:#and. |
|
976 | 2870 |
bgForm displayOpaqueForm:deviceForm x:0 y:0. |
732 | 2871 |
|
2872 |
" |
|
2873 |
stamp-out foreground |
|
2874 |
" |
|
2875 |
fgForm paint:allColor on:noColor. |
|
2876 |
fgForm function:#and. |
|
976 | 2877 |
fgForm displayOpaqueForm:deviceForm x:0 y:0. |
732 | 2878 |
|
2879 |
" |
|
2880 |
clear tempform |
|
2881 |
" |
|
2882 |
tmpForm paint:noColor. |
|
2883 |
tmpForm fillRectangleX:0 y:0 width:w height:h. |
|
2884 |
||
2885 |
" |
|
2886 |
merge fg-temp and bg-temp into tmp |
|
2887 |
" |
|
2888 |
tmpForm function:#or. |
|
2889 |
tmpForm paint:noColor on:allColor. |
|
2890 |
tmpForm copyFrom:fgForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
2891 |
tmpForm copyFrom:bgForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
2892 |
||
2893 |
" |
|
2894 |
finally, draw it |
|
2895 |
" |
|
2896 |
device setForeground:0 background:allBits in:gcId. |
|
2897 |
device |
|
7629 | 2898 |
copyFromPixmapId:tmpForm drawableId |
2899 |
x:0 |
|
2900 |
y:0 |
|
2901 |
gc:tmpForm gcId |
|
2902 |
to:drawableId |
|
2903 |
x:pX |
|
2904 |
y:pY |
|
2905 |
gc:gcId |
|
2906 |
width:w |
|
2907 |
height:h. |
|
1637
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
2908 |
|
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
2909 |
" |
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
2910 |
release tempForms immediately |
6292 | 2911 |
(although GC will eventually do it, |
1637
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
2912 |
this creates less stress to the Xserver in the meanwhile ...) |
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
2913 |
" |
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
2914 |
fgForm destroy. |
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
2915 |
bgForm destroy. |
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
2916 |
tmpForm destroy. |
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
2917 |
|
732 | 2918 |
" |
2919 |
flush foreground/background cache |
|
2920 |
" |
|
2921 |
foreground := nil. |
|
2922 |
background := nil. |
|
868 | 2923 |
|
8154 | 2924 |
"Modified: / 31-08-2017 / 19:35:55 / cg" |
8174 | 2925 |
"Modified: / 06-09-2017 / 12:31:45 / Maren" |
8315 | 2926 |
"Modified: / 20-03-2018 / 17:27:14 / stefan" |
732 | 2927 |
! |
2928 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2929 |
displayDeviceOpaqueString:aStringArg from:index1 to:index2 in:fontArg x:x y:y |
732 | 2930 |
"draw a substring at the coordinate x/y - draw foreground pixels in |
2931 |
paint-color and background pixels in bgPaint-color. |
|
2932 |
Assuming that device can only draw in device colors, we have to handle |
|
2933 |
the case where paint and/or bgPaint are dithered colors. |
|
2934 |
No translation or scaling is done." |
|
2935 |
||
7443 | 2936 |
|easy w h savedPaint fgId bgId allColor allBits noColor bgForm fgForm tmpForm maskForm dx dy pX pY fontUsed aString |
4026
882de378f763
no longer as string for its encoding;
Claus Gittinger <cg@exept.de>
parents:
3943
diff
changeset
|
2937 |
deviceDepth fontsEncoding ascent| |
732 | 2938 |
|
2939 |
" |
|
2940 |
if backgroundPaint color is nil, we assume |
|
2941 |
this is a non-opaque draw |
|
2942 |
" |
|
2943 |
bgPaint isNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2944 |
self displayDeviceString:aString from:index1 to:index2 in:font x:x y:y. |
7064 | 2945 |
^ self |
732 | 2946 |
]. |
2947 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2948 |
gcId isNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2949 |
self initGC |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2950 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2951 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2952 |
fontUsed := fontArg onDevice:device. |
7443 | 2953 |
deviceFont ~~ fontUsed ifTrue:[ |
2954 |
(fontUsed installInDeviceForGCId:gcId) isNil ifTrue:[ |
|
2955 |
"error - no such font" |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2956 |
^ self. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2957 |
]. |
7443 | 2958 |
deviceFont := fontUsed. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2959 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2960 |
|
7510 | 2961 |
(aString notNil |
2962 |
and:[aString isPlainString not]) ifTrue:[ |
|
7064 | 2963 |
" |
2964 |
hook for non-strings (i.e. attributed text) |
|
2965 |
that 'thing' should know how to display itself ... |
|
2966 |
" |
|
2967 |
aString displayOpaqueOn:self x:x y:y from:index1 to:index2. |
|
2968 |
^ self |
|
732 | 2969 |
]. |
6210 | 2970 |
|
2971 |
pX := x rounded. |
|
2972 |
pY := y rounded. |
|
2973 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2974 |
aString := aStringArg. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2975 |
|
4026
882de378f763
no longer as string for its encoding;
Claus Gittinger <cg@exept.de>
parents:
3943
diff
changeset
|
2976 |
fontsEncoding := fontUsed encoding. |
7288 | 2977 |
"/ This is now obsolete, as we are always using unicode internally. |
2978 |
"/ so the next line should be changed to fontsEncoding ~~ #unicode |
|
4056 | 2979 |
(characterEncoding ~~ fontsEncoding) ifTrue:[ |
7064 | 2980 |
[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2981 |
aString := CharacterEncoder encodeString:aString from:characterEncoding into:fontsEncoding. |
7064 | 2982 |
] on:CharacterEncoderError do:[:ex| |
2983 |
"substitute a default value for codes that cannot be represented |
|
2984 |
in the new character set" |
|
2985 |
ex proceedWith:ex defaultValue. |
|
2986 |
]. |
|
4026
882de378f763
no longer as string for its encoding;
Claus Gittinger <cg@exept.de>
parents:
3943
diff
changeset
|
2987 |
]. |
732 | 2988 |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2989 |
fontUsed isAlienFont ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2990 |
" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2991 |
hook for alien fonts |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2992 |
that 'font' should know how to display the string ... |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2993 |
" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
2994 |
fontUsed displayOpaqueString:aString from:index1 to:index2 x:pX y:pY in:self. |
7064 | 2995 |
^ self |
732 | 2996 |
]. |
2997 |
||
2998 |
" |
|
2999 |
if bgPaint or paint is not a real Color, we have to do it the hard way ... |
|
3000 |
" |
|
3001 |
easy := true. |
|
3002 |
paint isColor ifFalse:[ |
|
7064 | 3003 |
easy := false |
732 | 3004 |
] ifTrue:[ |
7064 | 3005 |
fgId := paint colorId. |
3006 |
fgId isNil ifTrue:[ |
|
3007 |
easy := false |
|
3008 |
] |
|
732 | 3009 |
]. |
3010 |
bgPaint isColor ifFalse:[ |
|
7064 | 3011 |
easy := false |
732 | 3012 |
] ifTrue:[ |
7064 | 3013 |
bgId := bgPaint colorId. |
3014 |
bgId isNil ifTrue:[ |
|
3015 |
easy := false |
|
3016 |
] |
|
732 | 3017 |
]. |
3018 |
||
3019 |
easy ifTrue:[ |
|
7064 | 3020 |
device setForeground:fgId background:bgId in:gcId. |
3021 |
foreground := paint. |
|
3022 |
background := bgPaint. |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3023 |
self displayDeviceString:aString from:index1 to:index2 x:pX y:pY opaque:true. |
7064 | 3024 |
^ self |
732 | 3025 |
]. |
3026 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3027 |
w := fontUsed widthOf:aString from:index1 to:index2. |
732 | 3028 |
h := fontUsed height. |
3666
01d7bf1d2333
fixed Text drawing in displayString
Michael Beyl <mb@exept.de>
parents:
3630
diff
changeset
|
3029 |
ascent := fontUsed ascent. |
732 | 3030 |
|
3031 |
(fgId notNil and:[function == #copy]) ifTrue:[ |
|
7064 | 3032 |
" |
3033 |
only bg is dithered; fill with bg first ... |
|
3034 |
" |
|
3035 |
savedPaint := paint. |
|
3036 |
self paint:bgPaint. |
|
3037 |
self fillRectangleX:pX y:(pY - ascent) width:w height:h. |
|
3038 |
self paint:savedPaint. |
|
3039 |
||
3040 |
" |
|
3041 |
then draw using fgPaint (which is a real color) |
|
3042 |
" |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3043 |
self displayDeviceString:aString from:index1 to:index2 x:pX y:pY opaque:false. |
7064 | 3044 |
^ self |
732 | 3045 |
]. |
3046 |
||
3047 |
allColor := Color allColor. |
|
3048 |
allBits := allColor colorId. |
|
3049 |
||
3050 |
deviceDepth := device depth. |
|
3051 |
||
3052 |
" |
|
3053 |
the code below is correct, but some (all?) implementations of the |
|
3054 |
X Window system seem to not support ALU-functions when drawing opaque strings. |
|
3055 |
Therefore we use the slower code below. |
|
3056 |
" |
|
3057 |
||
3058 |
"/ (bgId notNil and:[function == #copy]) ifTrue:[ |
|
3059 |
"/ " |
|
3060 |
"/ only fg is dithered; fill with fg first ... |
|
3061 |
"/ " |
|
3062 |
"/ self fillRectangleX:pX y:(pY - fontUsed ascent) width:w height:h. |
|
3063 |
"/ |
|
3064 |
"/ " |
|
3065 |
"/ if bgPaint color is all-0 or all-1's, we can do it in one |
|
3066 |
"/ operation ... |
|
3067 |
"/ " |
|
3068 |
"/ ((bgId ~~ ((1 bitShift:deviceDepth)-1)) |
|
3069 |
"/ and:[bgId ~~ allBits]) ifTrue:[ |
|
3070 |
"/ " |
|
3071 |
"/ clear bg bits ... |
|
3072 |
"/ " |
|
3073 |
"/ device setForeground:allBits background:0 in:gcId. |
|
3074 |
"/ device setFunction:#and in:gcId. |
|
6292 | 3075 |
"/ device displayOpaqueString:s |
732 | 3076 |
"/ from:index1 to:index2 |
6292 | 3077 |
"/ x:pX y:pY |
732 | 3078 |
"/ in:drawableId with:gcId. |
3079 |
"/ ]. |
|
3080 |
"/ |
|
3081 |
"/ " |
|
3082 |
"/ or-in bg bits ... |
|
3083 |
"/ " |
|
3084 |
"/ bgId ~~ 0 ifTrue:[ |
|
3085 |
"/ device setForeground:0 background:bgId in:gcId. |
|
3086 |
"/ device setFunction:#or in:gcId. |
|
6292 | 3087 |
"/ device displayOpaqueString:s |
732 | 3088 |
"/ from:index1 to:index2 |
6292 | 3089 |
"/ x:pX y:pY |
732 | 3090 |
"/ in:drawableId with:gcId. |
3091 |
"/ ]. |
|
3092 |
"/ " |
|
3093 |
"/ flush foreground/background cache |
|
3094 |
"/ " |
|
3095 |
"/ foreground := nil. |
|
3096 |
"/ background := nil. |
|
3097 |
"/ device setFunction:function in:gcId. |
|
3098 |
"/ ^ self |
|
3099 |
"/ ]. |
|
3100 |
||
768 | 3101 |
(bgId notNil and:[function == #copy]) ifTrue:[ |
7064 | 3102 |
" |
3103 |
only fg is dithered; fill with bg first ... |
|
3104 |
" |
|
3105 |
device setForeground:bgId in:gcId. |
|
3106 |
device setFunction:#copy in:gcId. |
|
3107 |
device setBitmapMask:nil in:gcId. |
|
3108 |
self fillRectangleX:pX y:(pY - ascent) width:w height:h. |
|
3109 |
||
3110 |
mask notNil ifTrue:[ |
|
3111 |
"/ draw fg dithered |
|
3112 |
(mask depth == 1) ifTrue:[ |
|
7629 | 3113 |
device setBitmapMask:mask drawableId in:gcId. |
7064 | 3114 |
device setForegroundColor:foreground backgroundColor:background in:gcId. |
3115 |
] ifFalse:[ |
|
7629 | 3116 |
device setPixmapMask:mask drawableId in:gcId |
7064 | 3117 |
]. |
3118 |
]. |
|
3119 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3120 |
self displayString:aString from:index1 to:index2 x:pX y:pY opaque:false. |
7064 | 3121 |
^ self. |
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3122 |
]. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3123 |
|
732 | 3124 |
" |
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3125 |
very hard case, both fg and bg are dithered colors/images |
732 | 3126 |
" |
3127 |
noColor := Color noColor. |
|
4026
882de378f763
no longer as string for its encoding;
Claus Gittinger <cg@exept.de>
parents:
3943
diff
changeset
|
3128 |
|
732 | 3129 |
" |
3130 |
create temp-forms; |
|
3131 |
" |
|
4781
7f2473db5652
Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents:
4756
diff
changeset
|
3132 |
bgForm := Form width:w height:h depth:deviceDepth onDevice:device. |
7f2473db5652
Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents:
4756
diff
changeset
|
3133 |
fgForm := Form width:w height:h depth:deviceDepth onDevice:device. |
7f2473db5652
Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents:
4756
diff
changeset
|
3134 |
tmpForm := Form width:w height:h depth:deviceDepth onDevice:device. |
7f2473db5652
Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents:
4756
diff
changeset
|
3135 |
maskForm := Form width:w height:h depth:deviceDepth onDevice:device. |
732 | 3136 |
|
3137 |
" |
|
3138 |
fill |
|
3139 |
" |
|
3140 |
dx := 0. |
|
3666
01d7bf1d2333
fixed Text drawing in displayString
Michael Beyl <mb@exept.de>
parents:
3630
diff
changeset
|
3141 |
dy := ascent. |
732 | 3142 |
maskOrigin notNil ifTrue:[ |
7064 | 3143 |
dx := maskOrigin x. |
3144 |
dy := dy + maskOrigin y |
|
732 | 3145 |
]. |
3146 |
||
3147 |
bgForm paint:bgPaint. |
|
4983
14c28ec55880
Replace usage of obsolete methods
Stefan Vogel <sv@exept.de>
parents:
4914
diff
changeset
|
3148 |
bgForm maskOriginX:(pX negated + dx) y:(pY negated + dy). |
732 | 3149 |
bgForm fillRectangleX:0 y:0 width:w height:h. |
3150 |
||
3151 |
fgForm paint:paint. |
|
4983
14c28ec55880
Replace usage of obsolete methods
Stefan Vogel <sv@exept.de>
parents:
4914
diff
changeset
|
3152 |
fgForm maskOriginX:(pX negated + dx) y:(pY negated + dy). |
732 | 3153 |
fgForm fillRectangleX:0 y:0 width:w height:h. |
3154 |
||
3155 |
" |
|
3156 |
stamp-out background (have now bg-bits with fg=0 in bgForm) |
|
3157 |
" |
|
3158 |
bgForm font:fontUsed. |
|
3159 |
bgForm paint:noColor on:allColor. |
|
3160 |
bgForm function:#and. |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3161 |
bgForm displayString:aString from:index1 to:index2 x:0 y:ascent. |
732 | 3162 |
|
3163 |
" |
|
3164 |
stamp-out foreground |
|
3165 |
" |
|
3166 |
maskForm font:fontUsed. |
|
3167 |
maskForm paint:allColor on:noColor. |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3168 |
maskForm displayString:aString from:index1 to:index2 x:0 y:ascent opaque:true. |
732 | 3169 |
|
3170 |
fgForm function:#and. |
|
3171 |
fgForm copyFrom:maskForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
3172 |
||
3173 |
" |
|
3174 |
clear tempform |
|
3175 |
" |
|
3176 |
tmpForm paint:noColor. |
|
3177 |
tmpForm fillRectangleX:0 y:0 width:w height:h. |
|
3178 |
||
3179 |
" |
|
3180 |
merge fg-temp and bg-temp into tmp |
|
3181 |
" |
|
3182 |
tmpForm function:#or. |
|
3183 |
tmpForm paint:noColor on:allColor. |
|
3184 |
tmpForm copyFrom:fgForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
3185 |
tmpForm copyFrom:bgForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
3186 |
" |
|
3187 |
finally, draw it |
|
3188 |
" |
|
3189 |
device setForeground:0 background:allBits in:gcId. |
|
3190 |
device |
|
7629 | 3191 |
copyFromId:tmpForm drawableId |
7064 | 3192 |
x:0 y:0 gc:tmpForm gcId |
3193 |
to:drawableId |
|
3194 |
x:pX y:(pY-ascent) gc:gcId |
|
3195 |
width:w height:h. |
|
1637
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
3196 |
|
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
3197 |
" |
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
3198 |
release tempForms immediately |
6292 | 3199 |
(although GC will eventually do it, |
1637
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
3200 |
this creates less stress to the Xserver in the meanwhile ...) |
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
3201 |
" |
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
3202 |
tmpForm destroy. |
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
3203 |
fgForm destroy. |
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
3204 |
bgForm destroy. |
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
3205 |
maskForm destroy. |
4e6372dce15d
release temporary forms early
Claus Gittinger <cg@exept.de>
parents:
1599
diff
changeset
|
3206 |
|
732 | 3207 |
" |
3208 |
flush foreground/background cache |
|
3209 |
" |
|
3210 |
foreground := nil. |
|
3211 |
background := nil. |
|
3212 |
||
1805
532a11ba8458
tuned-out another send if encoding is wrong in display-string
Claus Gittinger <cg@exept.de>
parents:
1797
diff
changeset
|
3213 |
"Modified: 1.7.1997 / 17:08:46 / cg" |
732 | 3214 |
! |
3215 |
||
3216 |
displayDeviceOpaqueString:aString from:index1 to:index2 x:x y:y |
|
3217 |
"draw a substring at the coordinate x/y - draw foreground pixels in |
|
3218 |
paint-color and background pixels in bgPaint-color. |
|
3219 |
Assuming that device can only draw in device colors, we have to handle |
|
3220 |
the case where paint and/or bgPaint are dithered colors. |
|
3221 |
No translation or scaling is done." |
|
3222 |
||
3223 |
self displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y |
|
3224 |
! |
|
3225 |
||
3226 |
displayDeviceOpaqueString:aString x:x y:y |
|
3227 |
"draw a string at the coordinate x/y - draw foreground pixels in |
|
3228 |
paint-color and background pixels in bgPaint-color. |
|
3229 |
No translation or scaling is done" |
|
3230 |
||
3231 |
self displayDeviceOpaqueString:aString from:1 to:(aString size) in:font x:x y:y |
|
3232 |
! |
|
3233 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3234 |
displayDeviceString:aStringArg from:index1 to:index2 in:fontArg x:x y:y |
6292 | 3235 |
"draw a substring at the coordinate x/y - |
732 | 3236 |
draw foreground-pixels only (in current paint-color), leaving background as-is. |
3237 |
No translation or scaling is done" |
|
3238 |
||
7443 | 3239 |
|fontUsed aString fontsEncoding| |
732 | 3240 |
|
3241 |
" |
|
3242 |
hook for non-strings (i.e. attributed text) |
|
3243 |
" |
|
7064 | 3244 |
aString isPlainString ifFalse:[ |
3245 |
^ aString displayOn:self x:x y:y from:index1 to:index2 |
|
732 | 3246 |
]. |
6210 | 3247 |
|
732 | 3248 |
gcId isNil ifTrue:[ |
7064 | 3249 |
self initGC |
732 | 3250 |
]. |
3251 |
||
7443 | 3252 |
fontUsed := fontArg onDevice:device. |
3253 |
deviceFont ~~ fontUsed ifTrue:[ |
|
3254 |
(fontUsed installInDeviceForGCId:gcId) isNil ifTrue:[ |
|
3255 |
"error - no such font" |
|
3256 |
^ self. |
|
3257 |
]. |
|
3258 |
deviceFont := fontUsed. |
|
3259 |
]. |
|
3260 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3261 |
aString := aStringArg. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3262 |
|
7443 | 3263 |
fontsEncoding := fontUsed encoding. |
4056 | 3264 |
(characterEncoding ~~ fontsEncoding) ifTrue:[ |
7064 | 3265 |
[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3266 |
aString := CharacterEncoder encodeString:aString from:characterEncoding into:fontsEncoding. |
7064 | 3267 |
] on:CharacterEncoderError do:[:ex| |
3268 |
"substitute a default value for codes that cannot be represented |
|
3269 |
in the new character set" |
|
3270 |
ex proceedWith:ex defaultValue. |
|
3271 |
]. |
|
4026
882de378f763
no longer as string for its encoding;
Claus Gittinger <cg@exept.de>
parents:
3943
diff
changeset
|
3272 |
]. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3273 |
fontUsed isAlienFont ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3274 |
" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3275 |
hook for alien fonts |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3276 |
that 'font' should know how to display the string ... |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3277 |
" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3278 |
fontUsed displayString:aString from:index1 to:index2 x:x rounded y:y rounded in:self. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3279 |
^ self |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3280 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3281 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3282 |
self displayDeviceString:aString from:index1 to:index2 x:x y:y opaque:false. |
732 | 3283 |
|
1805
532a11ba8458
tuned-out another send if encoding is wrong in display-string
Claus Gittinger <cg@exept.de>
parents:
1797
diff
changeset
|
3284 |
"Modified: 1.7.1997 / 17:08:48 / cg" |
732 | 3285 |
! |
3286 |
||
3287 |
displayDeviceString:aString from:index1 to:index2 x:x y:y |
|
6292 | 3288 |
"draw a substring at the coordinate x/y - |
732 | 3289 |
draw foreground-pixels only (in current paint-color), leaving background as-is. |
3290 |
No translation or scaling is done" |
|
3291 |
||
3292 |
self displayDeviceString:aString from:index1 to:index2 in:font x:x y:y |
|
3293 |
! |
|
3294 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3295 |
displayDeviceString:aString from:index1 to:index2 x:x y:y opaque:opaque |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3296 |
"draw a substring at the coordinate x/y - |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3297 |
draw foreground-pixels only (in current paint-color), leaving background as-is. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3298 |
No translation or scaling is done" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3299 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3300 |
gcId isNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3301 |
self initGC |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3302 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3303 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3304 |
device displayString:aString from:index1 to:index2 x:x rounded y:y rounded in:drawableId with:gcId opaque:opaque. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3305 |
! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3306 |
|
732 | 3307 |
displayDeviceString:aString x:x y:y |
6292 | 3308 |
"draw a string at the coordinate x/y - |
732 | 3309 |
draw foreground-pixels only (in current paint-color), leaving background as-is. |
3310 |
No translation or scaling is done" |
|
3311 |
||
3312 |
self displayDeviceString:aString from:1 to:(aString size) in:font x:x y:y |
|
3313 |
! |
|
3314 |
||
8439 | 3315 |
fillDevicePolygon:aCollectionOfPoints |
3316 |
"draw a filled polygon in device coordinates" |
|
3317 |
||
3318 |
gcId isNil ifTrue:[ |
|
3319 |
self initGC |
|
3320 |
]. |
|
3321 |
device fillPolygon:aCollectionOfPoints in:drawableId with:gcId |
|
3322 |
||
3323 |
"Created: / 04-08-2018 / 14:31:03 / Claus Gittinger" |
|
3324 |
! |
|
3325 |
||
732 | 3326 |
fillDeviceRectangleX:x y:y width:w height:h |
3327 |
"draw a filled rectangle in device coordinate space. |
|
3328 |
This ignores any transformations. The coordinates must be integers." |
|
3329 |
||
3330 |
gcId isNil ifTrue:[ |
|
7746 | 3331 |
self initGC |
732 | 3332 |
]. |
3333 |
device |
|
7746 | 3334 |
fillRectangleX:x y:y |
3335 |
width:w height:h |
|
3336 |
in:drawableId with:gcId |
|
732 | 3337 |
! ! |
3338 |
||
3339 |
!DeviceGraphicsContext methodsFor:'evaluating in another context'! |
|
3340 |
||
3341 |
reverseDo:aBlock |
|
3342 |
"evaluate aBlock with foreground and background interchanged. |
|
3343 |
This can be reimplemented here in a faster way." |
|
3344 |
||
3345 |
|oldFg oldBg| |
|
3346 |
||
2835 | 3347 |
oldFg := foreground. |
3348 |
oldBg := background. |
|
732 | 3349 |
self foreground:background background:foreground. |
3350 |
aBlock value. |
|
3351 |
self foreground:oldFg background:oldBg |
|
3352 |
! |
|
3353 |
||
3354 |
withBackground:fgColor do:aBlock |
|
3355 |
"evaluate aBlock with changed background." |
|
3356 |
||
3357 |
|oldBg| |
|
3358 |
||
3359 |
oldBg := background. |
|
3360 |
self background:fgColor. |
|
3361 |
aBlock value. |
|
3362 |
self background:oldBg |
|
3363 |
! |
|
3364 |
||
3365 |
withForeground:fgColor background:bgColor do:aBlock |
|
3366 |
"evaluate aBlock with changed foreground and background." |
|
3367 |
||
3368 |
|oldFg oldBg| |
|
3369 |
||
3370 |
oldFg := foreground. |
|
3371 |
oldBg := background. |
|
3372 |
self foreground:fgColor background:bgColor. |
|
3373 |
aBlock value. |
|
3374 |
self foreground:oldFg background:oldBg |
|
3375 |
! |
|
3376 |
||
3377 |
withForeground:fgColor background:bgColor function:aFunction do:aBlock |
|
3378 |
"evaluate aBlock with foreground, background and function" |
|
3379 |
||
3380 |
|oldFg oldBg oldFun| |
|
3381 |
||
3382 |
oldFg := foreground. |
|
3383 |
oldBg := background. |
|
3384 |
oldFun := function. |
|
3385 |
self foreground:fgColor background:bgColor function:aFunction. |
|
3386 |
aBlock value. |
|
3387 |
self foreground:oldFg background:oldBg function:oldFun |
|
3388 |
! |
|
3389 |
||
3390 |
withForeground:fgColor background:bgColor mask:aMask do:aBlock |
|
3391 |
"evaluate aBlock with foreground, background and mask" |
|
3392 |
||
3393 |
|oldFg oldBg oldMask| |
|
3394 |
||
3395 |
oldFg := foreground. |
|
3396 |
oldBg := background. |
|
3397 |
oldMask := mask. |
|
3398 |
self foreground:fgColor background:bgColor. |
|
3399 |
self mask:aMask. |
|
3400 |
aBlock value. |
|
3401 |
self foreground:oldFg background:oldBg. |
|
3402 |
self mask:oldMask |
|
3403 |
! |
|
3404 |
||
3405 |
withForeground:fgColor do:aBlock |
|
3406 |
"evaluate aBlock with changed foreground." |
|
3407 |
||
3408 |
|oldFg| |
|
3409 |
||
3410 |
oldFg := foreground. |
|
3411 |
self foreground:fgColor. |
|
3412 |
aBlock value. |
|
3413 |
self foreground:oldFg |
|
3414 |
! |
|
3415 |
||
3416 |
withForeground:fgColor function:aFunction do:aBlock |
|
3417 |
"evaluate aBlock with changed foreground and function." |
|
3418 |
||
3419 |
|oldFg oldFun| |
|
3420 |
||
3421 |
oldFg := foreground. |
|
3422 |
oldFun := function. |
|
3423 |
self foreground:fgColor background:background function:aFunction. |
|
3424 |
aBlock value. |
|
3425 |
self foreground:oldFg background:background function:oldFun |
|
3426 |
! |
|
3427 |
||
7759 | 3428 |
withPaint:aColor do:aBlock |
3429 |
"evaluate aBlock with changed paint color." |
|
3430 |
||
3431 |
|oldPaint| |
|
3432 |
||
3433 |
oldPaint := paint. |
|
3434 |
self paint:aColor. |
|
3435 |
aBlock value. |
|
3436 |
self paint:oldPaint |
|
3437 |
! |
|
3438 |
||
732 | 3439 |
xoring:aBlock |
3440 |
"evaluate aBlock with function xoring" |
|
3441 |
||
3442 |
|fgPixel bgPixel oldFunction| |
|
3443 |
||
2322 | 3444 |
fgPixel := device blackpixel. |
3445 |
bgPixel := device whitepixel. |
|
732 | 3446 |
|
3447 |
gcId isNil ifTrue:[ |
|
6292 | 3448 |
self initGC |
732 | 3449 |
]. |
3450 |
oldFunction := function. |
|
3451 |
device setForeground:(fgPixel bitXor:bgPixel) |
|
6292 | 3452 |
background:bgPixel |
3453 |
in:gcId. |
|
732 | 3454 |
device setFunction:#xor in:gcId. |
3455 |
aBlock value. |
|
2322 | 3456 |
|
2879 | 3457 |
paint := bgPaint := nil. "invalidate" |
6292 | 3458 |
foreground := device blackColor. |
1199
f113f6a4c04a
use new device black/whiteColor interface
Claus Gittinger <cg@exept.de>
parents:
1177
diff
changeset
|
3459 |
background := device whiteColor. |
2322 | 3460 |
device setForeground:fgPixel background:bgPixel in:gcId. |
732 | 3461 |
device setFunction:oldFunction in:gcId. |
3462 |
function := oldFunction |
|
1199
f113f6a4c04a
use new device black/whiteColor interface
Claus Gittinger <cg@exept.de>
parents:
1177
diff
changeset
|
3463 |
|
2322 | 3464 |
"Modified: / 10.9.1998 / 12:17:39 / cg" |
732 | 3465 |
! ! |
3466 |
||
3467 |
!DeviceGraphicsContext methodsFor:'filling'! |
|
3468 |
||
5837
28301409379c
added: #clearDeviceRectangleX:y:width:height:
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
3469 |
clearDeviceRectangleX:x y:y width:w height:h |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3470 |
"clear a rectangular area to background" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3471 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3472 |
|oldPaint| |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3473 |
|
5837
28301409379c
added: #clearDeviceRectangleX:y:width:height:
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
3474 |
oldPaint := paint. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3475 |
self paint:bgPaint. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3476 |
self fillDeviceRectangleX:x y:y width:w height:h. |
5837
28301409379c
added: #clearDeviceRectangleX:y:width:height:
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
3477 |
self paint:oldPaint |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3478 |
! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3479 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3480 |
clearRectangleX:left y:top width:w height:h |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3481 |
"clear the rectangular area in the receiver to background" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3482 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3483 |
|oldPaint| |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3484 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3485 |
oldPaint := paint. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3486 |
self paint:bgPaint. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3487 |
self fillRectangleX:left y:top width:w height:h. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3488 |
self paint:oldPaint |
5837
28301409379c
added: #clearDeviceRectangleX:y:width:height:
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
3489 |
! |
28301409379c
added: #clearDeviceRectangleX:y:width:height:
Claus Gittinger <cg@exept.de>
parents:
5742
diff
changeset
|
3490 |
|
732 | 3491 |
fillArcX:x y:y width:w height:h from:startAngle angle:angle |
3492 |
"draw a filled arc; apply transformation if nonNil" |
|
3493 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
3494 |
|pX pY nW nH sA a pO pC| |
732 | 3495 |
|
3496 |
gcId isNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3497 |
self initGC |
732 | 3498 |
]. |
3499 |
transformation notNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3500 |
pO := transformation transformPoint:x@y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3501 |
pC := transformation transformPoint:(x+w-1)@(y+h-1). |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3502 |
pX := pO x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3503 |
pY := pO y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3504 |
nW := pC x - pX + 1. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3505 |
nH := pC y - pY + 1. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3506 |
nW < 0 ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3507 |
nW := nW abs. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3508 |
pX := pX - nW. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3509 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3510 |
nH < 0 ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3511 |
nH := nH abs. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3512 |
pY := pY - nH. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3513 |
]. |
732 | 3514 |
] ifFalse:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3515 |
pX := x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3516 |
pY := y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3517 |
nW := w. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3518 |
nH := h. |
732 | 3519 |
]. |
3520 |
||
3521 |
pX := pX rounded. |
|
3522 |
pY := pY rounded. |
|
3523 |
nW := nW rounded. |
|
3524 |
nH := nH rounded. |
|
3525 |
||
2268
1a774fc02c83
fixed non-float (i.e. fraction) args to fillArc/ displayArc
Claus Gittinger <cg@exept.de>
parents:
2259
diff
changeset
|
3526 |
sA := startAngle. |
1a774fc02c83
fixed non-float (i.e. fraction) args to fillArc/ displayArc
Claus Gittinger <cg@exept.de>
parents:
2259
diff
changeset
|
3527 |
sA isInteger ifFalse:[sA := sA asFloat]. |
1a774fc02c83
fixed non-float (i.e. fraction) args to fillArc/ displayArc
Claus Gittinger <cg@exept.de>
parents:
2259
diff
changeset
|
3528 |
a := angle. |
1a774fc02c83
fixed non-float (i.e. fraction) args to fillArc/ displayArc
Claus Gittinger <cg@exept.de>
parents:
2259
diff
changeset
|
3529 |
a isInteger ifFalse:[a := a asFloat]. |
1a774fc02c83
fixed non-float (i.e. fraction) args to fillArc/ displayArc
Claus Gittinger <cg@exept.de>
parents:
2259
diff
changeset
|
3530 |
|
732 | 3531 |
device |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3532 |
fillArcX:pX |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3533 |
y:pY |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3534 |
width:nW |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3535 |
height:nH |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3536 |
from:sA |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3537 |
angle:a |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3538 |
in:drawableId |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3539 |
with:gcId |
732 | 3540 |
|
3541 |
"Created: 8.5.1996 / 08:29:45 / cg" |
|
784 | 3542 |
"Modified: 4.6.1996 / 17:58:21 / cg" |
732 | 3543 |
! |
3544 |
||
8439 | 3545 |
fillPolygon:aCollectionOfPoints |
732 | 3546 |
"draw a filled polygon; apply transformation if nonNil" |
3547 |
||
3548 |
|newPolygon| |
|
3549 |
||
3550 |
gcId isNil ifTrue:[ |
|
8439 | 3551 |
self initGC |
732 | 3552 |
]. |
3553 |
transformation notNil ifTrue:[ |
|
8439 | 3554 |
newPolygon := aCollectionOfPoints collect:[:point | transformation transformPoint:point]. |
732 | 3555 |
] ifFalse:[ |
8439 | 3556 |
newPolygon := aCollectionOfPoints |
732 | 3557 |
]. |
6292 | 3558 |
(newPolygon contains:[:p | |
8439 | 3559 |
(p isPoint not |
3560 |
or:[(p x class ~~ SmallInteger) |
|
3561 |
or:[(p y class ~~ SmallInteger)]]) |
|
4521 | 3562 |
]) ifTrue:[ |
8439 | 3563 |
newPolygon := newPolygon collect:[:p | p asPoint rounded] |
732 | 3564 |
]. |
8439 | 3565 |
device fillPolygon:newPolygon in:drawableId with:gcId |
3566 |
||
3567 |
"Modified (format): / 04-08-2018 / 14:31:25 / Claus Gittinger" |
|
732 | 3568 |
! |
3569 |
||
3570 |
fillRectangleX:x y:y width:w height:h |
|
3571 |
"draw a filled rectangle; apply transformation if nonNil" |
|
3572 |
||
6691
d044fff3447c
class: DeviceGraphicsContext
Claus Gittinger <cg@exept.de>
parents:
6645
diff
changeset
|
3573 |
|pX pY nW nH pO pC| |
732 | 3574 |
|
3575 |
gcId isNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3576 |
self initGC |
732 | 3577 |
]. |
3578 |
transformation notNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3579 |
pO := transformation transformPoint:x@y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3580 |
pC := transformation transformPoint:(x+w-1)@(y+h-1). |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3581 |
pX := pO x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3582 |
pY := pO y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3583 |
nW := pC x - pX + 1. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3584 |
nH := pC y - pY + 1. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3585 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3586 |
nW < 0 ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3587 |
nW := nW abs. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3588 |
pX := pX - nW. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3589 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3590 |
nH < 0 ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3591 |
nH := nH abs. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3592 |
pY := pY - nH. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3593 |
]. |
732 | 3594 |
] ifFalse:[ |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3595 |
pX := x. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3596 |
pY := y. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3597 |
nW := w. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3598 |
nH := h. |
732 | 3599 |
]. |
3600 |
pX := pX rounded. |
|
3601 |
pY := pY rounded. |
|
3602 |
nW := nW rounded. |
|
3603 |
nH := nH rounded. |
|
3604 |
||
3605 |
device |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3606 |
fillRectangleX:pX |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3607 |
y:pY |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3608 |
width:nW |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3609 |
height:nH |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3610 |
in:drawableId with:gcId |
784 | 3611 |
|
3612 |
"Modified: 4.6.1996 / 17:58:49 / cg" |
|
732 | 3613 |
! ! |
3614 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3615 |
!DeviceGraphicsContext methodsFor:'finalization'! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3616 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3617 |
executor |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3618 |
drawableType == #window ifTrue:[ |
7752 | 3619 |
^ DeviceWindowGCHandle basicNew |
3620 |
setDevice:device id:drawableId gcId:gcId parentId:parentId. |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3621 |
] ifFalse:[ |
7752 | 3622 |
^ DevicePixmapGCHandle basicNew |
3623 |
setDevice:device id:drawableId gcId:gcId. |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3624 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3625 |
! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3626 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3627 |
finalizationLobby |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3628 |
"answer the registry used for finalization. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3629 |
DeviceGraphicContexts have their own Registry" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3630 |
|
7443 | 3631 |
^ device graphicsContexts |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3632 |
! ! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3633 |
|
3883 | 3634 |
!DeviceGraphicsContext methodsFor:'initialization & release'! |
732 | 3635 |
|
1517
ac751bb3dfdf
no need for registration here;
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
3636 |
close |
ac751bb3dfdf
no need for registration here;
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
3637 |
"same as destroy - for ST-80 compatibility" |
ac751bb3dfdf
no need for registration here;
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
3638 |
|
ac751bb3dfdf
no need for registration here;
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
3639 |
self destroy |
ac751bb3dfdf
no need for registration here;
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
3640 |
|
ac751bb3dfdf
no need for registration here;
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
3641 |
"Created: 2.4.1997 / 19:31:27 / cg" |
ac751bb3dfdf
no need for registration here;
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
3642 |
! |
ac751bb3dfdf
no need for registration here;
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
3643 |
|
732 | 3644 |
createGC |
1453
e93293618275
only fetch id's once in displayForm.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3645 |
"physically create a device GC. |
e93293618275
only fetch id's once in displayForm.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3646 |
Since we do not need a gc-object for the drawable until something is |
e93293618275
only fetch id's once in displayForm.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3647 |
really drawn, none is created up to the first draw. |
732 | 3648 |
This method is sent, when the first drawing happens" |
3649 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3650 |
drawableType == #pixmap ifTrue:[ |
7443 | 3651 |
gcId := device gcForBitmap:drawableId. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3652 |
] ifFalse:[ |
7443 | 3653 |
gcId := device gcFor:drawableId. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3654 |
]. |
7443 | 3655 |
device registerGraphicsContext:self. "this is a registerChange:" |
1453
e93293618275
only fetch id's once in displayForm.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3656 |
|
e93293618275
only fetch id's once in displayForm.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3657 |
"Modified: 19.3.1997 / 11:07:52 / cg" |
1138
4a2b3b407cae
need separate createGC method for bitmaps (for WIN)
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
3658 |
! |
4a2b3b407cae
need separate createGC method for bitmaps (for WIN)
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
3659 |
|
4a2b3b407cae
need separate createGC method for bitmaps (for WIN)
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
3660 |
destroy |
6222 | 3661 |
|id| |
3662 |
||
3663 |
id := gcId. |
|
3664 |
id notNil ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3665 |
gcId := nil. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3666 |
device destroyGC:id. |
6222 | 3667 |
]. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3668 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3669 |
id := drawableId. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3670 |
id notNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3671 |
drawableId := nil. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3672 |
drawableType == #window ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3673 |
device destroyView:nil withId:id. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3674 |
] ifFalse:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3675 |
device destroyPixmap:id. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3676 |
]. |
7443 | 3677 |
device unregisterGraphicsContext:self. |
6266 | 3678 |
]. |
3679 |
! |
|
3680 |
||
1138
4a2b3b407cae
need separate createGC method for bitmaps (for WIN)
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
3681 |
initGC |
4a2b3b407cae
need separate createGC method for bitmaps (for WIN)
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
3682 |
"since we do not need a gc-object for the drawable until something is |
4a2b3b407cae
need separate createGC method for bitmaps (for WIN)
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
3683 |
really drawn, none is created. |
7749 | 3684 |
This method is sent, when the first drawing happens. |
3685 |
Answer the gcId." |
|
1138
4a2b3b407cae
need separate createGC method for bitmaps (for WIN)
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
3686 |
|
4135 | 3687 |
|fgId bgId p fontId| |
732 | 3688 |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3689 |
gcId notNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3690 |
"already initialized" |
7749 | 3691 |
^ gcId |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3692 |
]. |
1514
7c2a921ae46b
better error report when drawing on closed view.
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
3693 |
drawableId isNil ifTrue:[ |
7406 | 3694 |
"/ |
3695 |
"/ the drawable has been closed (or was never open) |
|
3696 |
"/ no drawing is possible. |
|
3697 |
"/ |
|
3698 |
^ DrawingOnClosedDrawableSignal raiseRequest |
|
1514
7c2a921ae46b
better error report when drawing on closed view.
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
3699 |
]. |
1138
4a2b3b407cae
need separate createGC method for bitmaps (for WIN)
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
3700 |
self createGC. |
732 | 3701 |
|
1199
f113f6a4c04a
use new device black/whiteColor interface
Claus Gittinger <cg@exept.de>
parents:
1177
diff
changeset
|
3702 |
foreground isNil ifTrue:[foreground := device blackColor]. |
f113f6a4c04a
use new device black/whiteColor interface
Claus Gittinger <cg@exept.de>
parents:
1177
diff
changeset
|
3703 |
background isNil ifTrue:[background := device whiteColor]. |
732 | 3704 |
|
3705 |
foreground isColor ifTrue:[ |
|
7406 | 3706 |
"get device colors from the device indep. colors" |
3707 |
foreground := foreground onDevice:device. |
|
3708 |
fgId := foreground colorId. |
|
3709 |
fgId isNil ifTrue:[ |
|
3710 |
(foreground grayIntensity >= 50) ifTrue:[ |
|
3711 |
fgId := device whitepixel |
|
3712 |
] ifFalse:[ |
|
3713 |
fgId := device blackpixel |
|
3714 |
] |
|
3715 |
]. |
|
732 | 3716 |
] ifFalse:[ |
7406 | 3717 |
fgId := device blackpixel. |
732 | 3718 |
]. |
3719 |
||
3720 |
background isColor ifTrue:[ |
|
7406 | 3721 |
background := background onDevice:device. |
3722 |
bgId := background colorId. |
|
3723 |
bgId isNil ifTrue:[ |
|
3724 |
(background grayIntensity >= 50) ifTrue:[ |
|
3725 |
bgId := device whitepixel |
|
3726 |
] ifFalse:[ |
|
3727 |
bgId := device blackpixel |
|
3728 |
] |
|
3729 |
]. |
|
732 | 3730 |
] ifFalse:[ |
7406 | 3731 |
bgId := device whitepixel |
732 | 3732 |
]. |
3733 |
||
3734 |
"now, this is something the device can work with ..." |
|
3735 |
device setForeground:fgId background:bgId in:gcId. |
|
3736 |
||
3737 |
"switch to paint" |
|
3738 |
p := paint. |
|
3739 |
paint := nil. |
|
3740 |
self paint:p. |
|
3741 |
||
6292 | 3742 |
((lineWidth ~~ 0) |
3743 |
or:[(lineStyle ~~ #solid) |
|
732 | 3744 |
or:[(capStyle ~~ #butt) |
3745 |
or:[joinStyle ~~ #miter]]]) ifTrue:[ |
|
7406 | 3746 |
device setLineWidth:lineWidth |
3747 |
style:lineStyle |
|
3748 |
cap:capStyle |
|
3749 |
join:joinStyle |
|
3750 |
in:gcId |
|
732 | 3751 |
]. |
3752 |
||
3753 |
mask notNil ifTrue:[ |
|
7406 | 3754 |
(mask depth == 1) ifTrue:[ |
7629 | 3755 |
device setBitmapMask:(mask drawableId) in:gcId |
7406 | 3756 |
] ifFalse:[ |
7629 | 3757 |
device setPixmapMask:(mask drawableId) in:gcId |
7406 | 3758 |
]. |
3759 |
maskOrigin notNil ifTrue:[ |
|
3760 |
device setMaskOriginX:maskOrigin x y:maskOrigin y in:gcId |
|
3761 |
] |
|
732 | 3762 |
]. |
3763 |
(function ~~ #copy) ifTrue:[device setFunction:function in:gcId]. |
|
3764 |
||
6292 | 3765 |
"defer the getting of a device font |
732 | 3766 |
- this is now done when the first drawstring occurs, |
3767 |
since many views (layout-views) will never draw strings and |
|
7406 | 3768 |
therefore, the overhead of acquiring a font can be avoided. |
732 | 3769 |
" |
1138
4a2b3b407cae
need separate createGC method for bitmaps (for WIN)
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
3770 |
"/ font := font on:device. |
4a2b3b407cae
need separate createGC method for bitmaps (for WIN)
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
3771 |
"/ id := font fontId. |
4a2b3b407cae
need separate createGC method for bitmaps (for WIN)
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
3772 |
"/ id notNil ifTrue:[ |
4a2b3b407cae
need separate createGC method for bitmaps (for WIN)
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
3773 |
"/ device setFont:id in:gcId |
4a2b3b407cae
need separate createGC method for bitmaps (for WIN)
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
3774 |
"/ ] |
1199
f113f6a4c04a
use new device black/whiteColor interface
Claus Gittinger <cg@exept.de>
parents:
1177
diff
changeset
|
3775 |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3776 |
(font notNil |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3777 |
and:[font graphicsDevice == device |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3778 |
and:[(fontId := font fontId) notNil]]) ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3779 |
deviceFont := font. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3780 |
device setFont:fontId in:gcId |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
3781 |
]. |
7749 | 3782 |
^ gcId. |
4664
02d160974029
fix remembering deviceFont everywhere.
Claus Gittinger <cg@exept.de>
parents:
4657
diff
changeset
|
3783 |
|
02d160974029
fix remembering deviceFont everywhere.
Claus Gittinger <cg@exept.de>
parents:
4657
diff
changeset
|
3784 |
"Modified: / 22-10-2006 / 14:10:53 / cg" |
4291 | 3785 |
! |
3786 |
||
3787 |
initialize |
|
3788 |
"setup everything for later use; actual work is done in |
|
3789 |
initColors and initFont, which are usually redefined." |
|
3790 |
||
3791 |
super initialize. |
|
3792 |
||
3793 |
"/ just in case, someone redefined new without setting device |
|
6234 | 3794 |
(device isNil and:[Screen notNil]) ifTrue:[device := Screen current]. |
4291 | 3795 |
|
6273 | 3796 |
foreground isNil ifTrue:[foreground := self blackColor]. |
3797 |
background isNil ifTrue:[background := self whiteColor]. |
|
4291 | 3798 |
|
3799 |
"Modified: 10.1.1997 / 17:46:51 / cg" |
|
3800 |
! |
|
3801 |
||
3802 |
prepareForReinit |
|
6292 | 3803 |
"kludge - clear drawableId and gcId |
4291 | 3804 |
needed after snapin" |
3805 |
||
3806 |
gcId := nil. |
|
7443 | 3807 |
drawableId := parentId := nil. |
4291 | 3808 |
deviceFont := nil |
3809 |
! |
|
3810 |
||
3811 |
recreate |
|
3812 |
"sent after a snapin or a migration, reinit draw stuff for new device" |
|
3813 |
||
3814 |
gcId := nil. |
|
7443 | 3815 |
drawableId := parentId := nil. |
4291 | 3816 |
foreground notNil ifTrue:[ |
7443 | 3817 |
foreground := foreground onDevice:device |
4291 | 3818 |
]. |
3819 |
background notNil ifTrue:[ |
|
7443 | 3820 |
background := background onDevice:device |
4291 | 3821 |
]. |
3822 |
paint notNil ifTrue:[ |
|
7443 | 3823 |
paint := paint onDevice:device |
4291 | 3824 |
]. |
3825 |
bgPaint notNil ifTrue:[ |
|
7443 | 3826 |
bgPaint := bgPaint onDevice:device |
4291 | 3827 |
]. |
3828 |
font notNil ifTrue:[ |
|
7443 | 3829 |
font := deviceFont := font onDevice:device |
4291 | 3830 |
] |
3831 |
||
3832 |
"Modified: 28.10.1996 / 13:25:02 / cg" |
|
3833 |
! |
|
3834 |
||
3835 |
releaseGC |
|
6292 | 3836 |
"destroy the associated device GC resource - can be done to be nice to the |
4291 | 3837 |
display if you know that you are done with a drawable." |
3838 |
||
3839 |
|id| |
|
3840 |
||
3841 |
foreground := background := paint := bgPaint := nil. |
|
3842 |
||
3843 |
id := gcId. |
|
3844 |
id notNil ifTrue:[ |
|
7443 | 3845 |
gcId := nil. |
3846 |
device destroyGC:id. |
|
3847 |
device unregisterGraphicsContext:self. |
|
4291 | 3848 |
]. |
3849 |
||
3850 |
"Created: 11.6.1996 / 22:07:30 / cg" |
|
3851 |
"Modified: 2.4.1997 / 19:36:30 / cg" |
|
732 | 3852 |
! ! |
3853 |
||
3854 |
!DeviceGraphicsContext methodsFor:'private'! |
|
3855 |
||
3856 |
setDevice:aDevice id:aDrawbleId gcId:aGCId |
|
3857 |
"private" |
|
3858 |
||
7443 | 3859 |
self device:aDevice. |
3860 |
drawableId := aDrawbleId. |
|
732 | 3861 |
gcId := aGCId. |
7445 | 3862 |
(aDrawbleId notNil and:[aDevice notNil]) ifTrue:[ |
3863 |
aDevice registerGraphicsContext:self. |
|
3864 |
]. |
|
732 | 3865 |
! |
3866 |
||
3867 |
setGCForPaint |
|
3868 |
"private; given a complex color (i.e. a pixmap or dithered color, |
|
3869 |
setup the GC to draw in this color. |
|
3870 |
A helper for paint and paint:on:" |
|
3871 |
||
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3872 |
|dither map pixelId p fg bg vOrg ditherDepth deviceDepth| |
732 | 3873 |
|
3874 |
gcId notNil ifTrue:[ |
|
7423 | 3875 |
paint isSymbol ifTrue:[ |
3876 |
"map symbols to colors" |
|
3877 |
paint := Color perform:paint ifNotUnderstood:[Color yellow]. |
|
3878 |
]. |
|
3879 |
p := paint. |
|
3880 |
||
3881 |
p isColor ifTrue:[ |
|
3882 |
paint := p := p onDevice:device. |
|
3883 |
pixelId := p colorId. |
|
3884 |
pixelId notNil ifTrue:[ |
|
3885 |
" |
|
3886 |
a real (undithered) color |
|
3887 |
" |
|
3888 |
mask notNil ifTrue:[ |
|
3889 |
mask := nil. |
|
3890 |
device setBitmapMask:nil in:gcId |
|
3891 |
]. |
|
3892 |
(p ~~ foreground) ifTrue:[ |
|
3893 |
foreground := paint. |
|
3894 |
device setForeground:pixelId in:gcId |
|
3895 |
]. |
|
3896 |
^ self |
|
3897 |
]. |
|
3898 |
"a dithered color" |
|
3899 |
dither := paint ditherForm. |
|
3900 |
] ifFalse:[ |
|
3901 |
"mhmh - seems to be some kind of form ..." |
|
3902 |
paint := paint onDevice:device. |
|
3903 |
dither := paint. |
|
3904 |
]. |
|
3905 |
" |
|
3906 |
a dithered color or image |
|
3907 |
" |
|
3908 |
(ditherDepth := dither depth) == 1 ifTrue:[ |
|
3909 |
"a simple 0/1 bitmap" |
|
3910 |
map := dither colorMap. |
|
3911 |
"temporary (kludgy) fix for destroyed paint" |
|
3912 |
p := paint. |
|
3913 |
map isNil ifTrue:[ |
|
3914 |
fg := self blackColor. |
|
3915 |
bg := self whiteColor. |
|
3916 |
] ifFalse:[ |
|
3917 |
fg := map at:2. |
|
3918 |
bg := map at:1. |
|
3919 |
]. |
|
3920 |
self foreground:fg background:bg. |
|
3921 |
paint := p |
|
3922 |
] ifFalse:[ |
|
3923 |
deviceDepth := device depth. |
|
3924 |
(ditherDepth ~~ deviceDepth) ifTrue:[ |
|
3925 |
dither := dither asFormOn:device. |
|
3926 |
ditherDepth := dither depth. |
|
3927 |
(dither isNil or:[ditherDepth ~~ deviceDepth]) ifTrue:[ |
|
3928 |
self error:'bad dither'. |
|
3929 |
^ self |
|
3930 |
] |
|
3931 |
] |
|
3932 |
]. |
|
3933 |
self mask:dither. |
|
3934 |
vOrg := self viewOrigin. |
|
3935 |
self maskOriginX:vOrg x negated y:vOrg y negated. |
|
732 | 3936 |
] |
3937 |
||
3938 |
"Created: 16.5.1996 / 15:35:51 / cg" |
|
1742 | 3939 |
"Modified: 6.6.1997 / 12:55:38 / cg" |
2049 | 3940 |
! |
3941 |
||
7445 | 3942 |
setId:aDrawableId |
2049 | 3943 |
"private" |
3944 |
||
7445 | 3945 |
drawableId := aDrawableId |
2049 | 3946 |
|
3947 |
"Created: / 6.2.1998 / 12:44:45 / cg" |
|
732 | 3948 |
! ! |
3949 |
||
3950 |
!DeviceGraphicsContext methodsFor:'queries'! |
|
3951 |
||
3952 |
horizontalIntegerPixelPerMillimeter |
|
3953 |
"return the (rounded) number of pixels per millimeter" |
|
3954 |
||
3955 |
^ device horizontalPixelPerMillimeter rounded |
|
3956 |
! |
|
3957 |
||
3958 |
horizontalPixelPerInch |
|
3959 |
"return the number of horizontal pixels per inch of the display" |
|
3960 |
||
3961 |
^ device horizontalPixelPerMillimeter * 25.4 |
|
3962 |
! |
|
3963 |
||
3964 |
horizontalPixelPerMillimeter |
|
3965 |
"return the number of pixels per millimeter (not rounded)" |
|
3966 |
||
3967 |
^ device horizontalPixelPerMillimeter |
|
3968 |
! |
|
3969 |
||
3970 |
horizontalPixelPerMillimeter:millis |
|
3971 |
"return the number of pixels (not rounded) for millis millimeter" |
|
3972 |
||
3973 |
^ device horizontalPixelPerMillimeter * millis |
|
3974 |
! |
|
3975 |
||
784 | 3976 |
resolution |
3977 |
"return a point consisting of pixel-per-inch horizontally and vertically." |
|
3978 |
||
3979 |
^ device resolution |
|
3980 |
||
3981 |
"Created: 4.6.1996 / 15:23:55 / cg" |
|
3982 |
! |
|
3983 |
||
732 | 3984 |
verticalIntegerPixelPerMillimeter |
3985 |
"return the (rounded) number of pixels per millimeter" |
|
3986 |
||
3987 |
^ device verticalPixelPerMillimeter rounded |
|
3988 |
! |
|
3989 |
||
3990 |
verticalPixelPerInch |
|
3991 |
"return the number of vertical pixels per inch of the display" |
|
3992 |
||
3993 |
^ device verticalPixelPerMillimeter * 25.4 |
|
3994 |
! |
|
3995 |
||
3996 |
verticalPixelPerMillimeter |
|
3997 |
"return the number of pixels per millimeter (not rounded)" |
|
3998 |
||
3999 |
^ device verticalPixelPerMillimeter |
|
4000 |
! |
|
4001 |
||
4002 |
verticalPixelPerMillimeter:millis |
|
4003 |
"return the number of pixels (not rounded) for millis millimeter" |
|
4004 |
||
4005 |
^ device verticalPixelPerMillimeter * millis |
|
4006 |
! ! |
|
4007 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4008 |
!DeviceGraphicsContext methodsFor:'testing'! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4009 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4010 |
isPixmap |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4011 |
^ drawableType == #pixmap |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4012 |
! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4013 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4014 |
isWindow |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4015 |
^ drawableType == #window |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4016 |
! ! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4017 |
|
6225 | 4018 |
!DeviceGraphicsContext methodsFor:'view creation'! |
4019 |
||
4020 |
createBitmapFromArray:data width:width height:height |
|
4021 |
"create a bitmap from data and set the drawableId" |
|
6292 | 4022 |
|
7443 | 4023 |
drawableType := #pixmap. |
6225 | 4024 |
drawableId := device createBitmapFromArray:data width:width height:height. |
7443 | 4025 |
device registerGraphicsContext:self. "this is a registerChange:" |
6225 | 4026 |
! |
4027 |
||
4028 |
createPixmapWidth:w height:h depth:d |
|
4029 |
"create a pixmap and set the drawableId" |
|
6292 | 4030 |
|
6225 | 4031 |
drawableId := device createPixmapWidth:w height:h depth:d. |
7356 | 4032 |
drawableId isNil ifTrue:[ |
7443 | 4033 |
"/ creation failed |
7588 | 4034 |
('[GC] warning: pixmap creation failed: ',((OperatingSystem lastErrorString) ? 'unknown error')) errorPrintCR. |
7443 | 4035 |
^ GraphicsDevice::GraphicResourceAllocationFailure query |
7356 | 4036 |
]. |
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4037 |
drawableType := #pixmap. |
7443 | 4038 |
device registerGraphicsContext:self. "this is a registerChange:" |
6225 | 4039 |
! |
4040 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4041 |
createRootWindowFor:aView |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4042 |
drawableId := device rootWindowFor:aView. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4043 |
drawableType := #window. |
6234 | 4044 |
! |
4045 |
||
6292 | 4046 |
createWindowFor:aView type:typeSymbol origin:org extent:ext minExtent:minE maxExtent:maxE borderWidth:bw subViewOf:sv style:styleSymbol inputOnly:inp label:label owner:owner icon:icn iconMask:icnM iconView:icnV |
6225 | 4047 |
"create a window and set the drawableId" |
6292 | 4048 |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4049 |
|container| |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4050 |
|
6292 | 4051 |
drawableId := device |
7443 | 4052 |
createWindowFor:aView |
4053 |
type:typeSymbol |
|
4054 |
origin:org |
|
4055 |
extent:ext |
|
4056 |
minExtent:minE |
|
4057 |
maxExtent:maxE |
|
4058 |
borderWidth:bw |
|
4059 |
subViewOf:sv |
|
4060 |
style:styleSymbol |
|
4061 |
inputOnly:inp |
|
4062 |
label:label |
|
4063 |
owner:owner |
|
4064 |
icon:icn |
|
4065 |
iconMask:icnM |
|
4066 |
iconView:icnV. |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4067 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4068 |
drawableType := #window. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4069 |
container := aView container. |
7629 | 4070 |
container notNil ifTrue:[ parentId := container drawableId]. |
7443 | 4071 |
device registerGraphicsContext:self. "this is a registerChange:" |
6225 | 4072 |
! ! |
4073 |
||
4074 |
!DeviceGraphicsContext methodsFor:'view properties'! |
|
4075 |
||
4076 |
backingStore:how |
|
4077 |
"turn on/off backingStore (saving my pixels) |
|
4078 |
how may true/false, but also #always, #whenMapped or #never." |
|
4079 |
||
4080 |
drawableId notNil ifTrue:[ |
|
6292 | 4081 |
device setBackingStore:how in:drawableId |
6225 | 4082 |
] |
4083 |
! |
|
4084 |
||
4085 |
bitGravity:gravity |
|
7582 | 4086 |
"set the bitGravity |
4087 |
- that's the direction where the contents will move when the view is resized." |
|
6225 | 4088 |
|
4089 |
drawableId notNil ifTrue:[ |
|
7582 | 4090 |
device setBitGravity:gravity in:drawableId |
6225 | 4091 |
] |
4092 |
! |
|
4093 |
||
4094 |
saveUnder:aBoolean |
|
4095 |
"turn on/off saveUnder (saving pixels under myself) |
|
4096 |
- used for temporary views (i.e. PopUps and ModalBoxes)" |
|
4097 |
||
4098 |
drawableId notNil ifTrue:[ |
|
6292 | 4099 |
device setSaveUnder:aBoolean in:drawableId |
6225 | 4100 |
] |
4101 |
! |
|
4102 |
||
4103 |
setCursorId:id |
|
4104 |
drawableId notNil ifTrue:[ |
|
6292 | 4105 |
device setCursor:id in:drawableId. |
6225 | 4106 |
] |
4107 |
! |
|
4108 |
||
4109 |
setWindowPid: pid |
|
4110 |
"Sets the _NET_WM_PID property for the window. |
|
4111 |
This may be used by the window manager to group windows. |
|
4112 |
If anIntegerOrNil is nil, then PID of currently running |
|
4113 |
Smalltalk is used" |
|
4114 |
||
4115 |
drawableId notNil ifTrue:[ |
|
6292 | 4116 |
device setWindowPid:pid in:drawableId. |
6225 | 4117 |
]. |
4118 |
! |
|
4119 |
||
4120 |
viewGravity:gravity |
|
7582 | 4121 |
"set the viewGravity |
4122 |
- that's the direction where the view will move when the superView is resized." |
|
6225 | 4123 |
|
4124 |
drawableId notNil ifTrue:[ |
|
7582 | 4125 |
device setWindowGravity:gravity in:drawableId |
6225 | 4126 |
]. |
4127 |
! |
|
4128 |
||
4129 |
windowBorderShape:aForm |
|
4130 |
"set the windows border shape" |
|
4131 |
||
4132 |
drawableId notNil ifTrue:[ |
|
7629 | 4133 |
device setWindowBorderShape:(aForm drawableId) in:drawableId |
6225 | 4134 |
]. |
4135 |
! |
|
4136 |
||
4137 |
windowClass:windowClassNameString name:nameString |
|
4138 |
"define class and name of a window. |
|
4139 |
This may be used by the window manager to |
|
4140 |
select client specific resources." |
|
4141 |
||
4142 |
drawableId notNil ifTrue:[ |
|
6292 | 4143 |
device setWindowClass:windowClassNameString name:nameString in:drawableId. |
6225 | 4144 |
]. |
4145 |
! |
|
4146 |
||
4147 |
windowName:aString |
|
7697 | 4148 |
"define the view's name in the window's title area." |
6225 | 4149 |
|
4150 |
drawableId notNil ifTrue: [ |
|
7697 | 4151 |
device setWindowName:aString in:drawableId. |
6225 | 4152 |
] |
4153 |
! |
|
4154 |
||
4155 |
windowShape:aForm |
|
4156 |
"set the windows shape. |
|
4157 |
Returns false, if the display does not support the |
|
4158 |
X shape extension." |
|
4159 |
||
4160 |
drawableId notNil ifTrue:[ |
|
7629 | 4161 |
^ device setWindowShape:(aForm drawableId) in:drawableId |
6225 | 4162 |
]. |
4163 |
^ false. |
|
4164 |
! ! |
|
4165 |
||
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4166 |
!DeviceGraphicsContext::DevicePixmapGCHandle methodsFor:'accessing'! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4167 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4168 |
parentId |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4169 |
"pixmaps do not have a parent" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4170 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4171 |
^ nil |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4172 |
! ! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4173 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4174 |
!DeviceGraphicsContext::DevicePixmapGCHandle methodsFor:'finalization'! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4175 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4176 |
finalize |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4177 |
"the Form for which I am a handle has been collected - tell it to the x-server" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4178 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4179 |
|id| |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4180 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4181 |
drawableId notNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4182 |
(id := gcId) notNil ifTrue:[ |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4183 |
gcId := nil. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4184 |
device destroyGC:id. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4185 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4186 |
id := drawableId. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4187 |
drawableId := nil. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4188 |
device destroyPixmap:id. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4189 |
] |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4190 |
! ! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4191 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4192 |
!DeviceGraphicsContext::DeviceWindowGCHandle methodsFor:'accessing'! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4193 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4194 |
parentId |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4195 |
^ parentId |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4196 |
! ! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4197 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4198 |
!DeviceGraphicsContext::DeviceWindowGCHandle methodsFor:'finalization'! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4199 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4200 |
finalize |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4201 |
"the view for which I am a handle was collected |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4202 |
- release system resources" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4203 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4204 |
drawableId notNil ifTrue:[ |
7443 | 4205 |
[ |
4206 |
(device viewIdKnown:drawableId) ifTrue:[ |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4207 |
"/ 'Display [info]: recycled view (' infoPrint. v infoPrint. ') not destroyed: ' infoPrint. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4208 |
"/ drawableId displayString infoPrintCR. |
7443 | 4209 |
drawableId := nil. |
4210 |
] ifFalse:[ |
|
4211 |
|id| |
|
4212 |
||
4213 |
(id := gcId) notNil ifTrue:[ |
|
4214 |
gcId := nil. |
|
4215 |
device deviceIOErrorSignal handle:[:ex | |
|
4216 |
] do:[ |
|
4217 |
device destroyGC:id. |
|
4218 |
] |
|
4219 |
]. |
|
4220 |
||
4221 |
id := drawableId. |
|
4222 |
drawableId := nil. |
|
4223 |
device deviceIOErrorSignal handle:[:ex | |
|
4224 |
] do:[ |
|
4225 |
device destroyView:nil withId:id. |
|
4226 |
]. |
|
4227 |
||
7920 | 4228 |
"When a window is destroyed, all its subwindows are also destroyed. |
7443 | 4229 |
Unregister all the subwindows, to avoid destroying of reused windowIds |
4230 |
later." |
|
7476 | 4231 |
device cleanupLobbyForChildrenOfViewWithId:id. |
7443 | 4232 |
] |
4233 |
] valueUninterruptably. |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4234 |
]. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4235 |
|
7920 | 4236 |
"Created: / 25-09-1997 / 10:01:46 / stefan" |
4237 |
"Modified: / 15-11-2001 / 14:17:12 / cg" |
|
4238 |
"Modified (comment): / 21-02-2017 / 14:23:18 / mawalch" |
|
7416
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4239 |
! ! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4240 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4241 |
!DeviceGraphicsContext::DeviceWindowGCHandle methodsFor:'private-accessing'! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4242 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4243 |
setDevice:aDevice id:aDrawableId gcId:aGCId parentId:parentIdArg |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4244 |
"set the handles contents" |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4245 |
|
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4246 |
device := aDevice. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4247 |
drawableId := aDrawableId. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4248 |
gcId := aGCId. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4249 |
parentId := parentIdArg. |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4250 |
! ! |
bd3b9e9edd9e
Delegate GraphicsContext objects
Stefan Vogel <sv@exept.de>
parents:
7406
diff
changeset
|
4251 |
|
1085
3513a4cae87b
handle depth1-images with a mask
Claus Gittinger <cg@exept.de>
parents:
1064
diff
changeset
|
4252 |
!DeviceGraphicsContext class methodsFor:'documentation'! |
732 | 4253 |
|
4254 |
version |
|
6926 | 4255 |
^ '$Header$' |
5360
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
4256 |
! |
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
4257 |
|
878079de94f0
added: #displayString:from:to:x:y:opaque:
Claus Gittinger <cg@exept.de>
parents:
5242
diff
changeset
|
4258 |
version_CVS |
6926 | 4259 |
^ '$Header$' |
732 | 4260 |
! ! |
3880 | 4261 |