author | mawalch |
Thu, 15 Mar 2018 12:28:33 +0100 | |
changeset 5723 | 3019347d6f76 |
parent 5721 | 601f7686ccdb |
child 5741 | 75e825820538 |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
24 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1763
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
12 |
"{ Package: 'stx:libwidg2' }" |
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
13 |
|
4732 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
296 | 16 |
View subclass:#ImageView |
5610 | 17 |
instanceVariableNames:'image magnifiedImage smoothMagnifiedImage adjust |
18 |
explicitMagnificationFactor magnificationFactor tileMode |
|
19 |
tileOffset lastMousePoint adjustHolder imageEditAction |
|
20 |
forceSmoothingHolder smoothingProcess' |
|
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
21 |
classVariableNames:'DoNotMagnifyQuery' |
161 | 22 |
poolDictionaries:'' |
23 |
category:'Views-Misc' |
|
1 | 24 |
! |
25 |
||
257 | 26 |
!ImageView class methodsFor:'documentation'! |
26 | 27 |
|
28 |
copyright |
|
29 |
" |
|
30 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
31 |
All Rights Reserved |
|
32 |
||
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
! |
|
41 |
||
42 |
documentation |
|
43 |
" |
|
2747 | 44 |
This View knows how to display a (bitmap-)image (or form). |
26 | 45 |
|
46 |
You can display an image with: |
|
47 |
||
2747 | 48 |
ImageView openOn:anImageFileName |
26 | 49 |
or: |
2747 | 50 |
ImageView openOnImage:anImage |
47 | 51 |
or: |
2747 | 52 |
ImageView new image:anImage |
26 | 53 |
|
54 |
i.e. |
|
55 |
||
2748 | 56 |
ImageView openOn:'../../goodies/bitmaps/gifImages/garfield.gif' |
57 |
ImageView openOn:'../../goodies/bitmaps/SBrowser.xbm' |
|
296 | 58 |
|
2748 | 59 |
ImageView openOnImage:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') |
60 |
ImageView openOnImage:(Image fromFile:'../../goodies/bitmaps/SBrowser.xbm') |
|
26 | 61 |
|
5226 | 62 |
adjust: |
2747 | 63 |
controls how images are displayed; |
64 |
can be one of: |
|
65 |
#topLeft - image is displayed as usual |
|
66 |
#center - image is shown centered |
|
67 |
#fitBig - big images are shrunk to make it fit the view |
|
68 |
#fitSmall - small images are magnified to make it fit the view, |
|
69 |
#fit - all images are magnified to fit the view |
|
2158 | 70 |
|
296 | 71 |
[author:] |
2747 | 72 |
Claus Gittinger |
296 | 73 |
|
74 |
[see also:] |
|
2747 | 75 |
Image Form |
26 | 76 |
" |
3683 | 77 |
! |
78 |
||
79 |
examples |
|
80 |
" |
|
81 |
|top imgView scrView| |
|
82 |
||
83 |
top := StandardSystemView new. |
|
84 |
top extent:300@300. |
|
85 |
||
86 |
imgView := ImageView new. |
|
87 |
imgView image:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'). |
|
88 |
||
89 |
scrView := HVScrollableView forView:imgView. |
|
90 |
scrView origin:0@0 corner:1.0@1.0. |
|
91 |
top add:scrView. |
|
92 |
||
93 |
top open. |
|
94 |
" |
|
26 | 95 |
! ! |
96 |
||
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
97 |
!ImageView class methodsFor:'initialization'! |
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
98 |
|
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
99 |
initialize |
4912 | 100 |
DoNotMagnifyQuery isNil ifTrue:[ |
101 |
DoNotMagnifyQuery := QuerySignal new defaultAnswer:false. |
|
102 |
]. |
|
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
103 |
! ! |
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
104 |
|
4245 | 105 |
!ImageView class methodsFor:'menu specs'! |
106 |
||
107 |
middleButtonMenu |
|
108 |
"This resource specification was automatically generated |
|
109 |
by the MenuEditor of ST/X." |
|
110 |
||
111 |
"Do not manually edit this!! If it is corrupted, |
|
112 |
the MenuEditor may not be able to read the specification." |
|
113 |
||
114 |
||
115 |
" |
|
116 |
MenuEditor new openOnClass:ImageView andSelector:#middleButtonMenu |
|
117 |
(Menu new fromLiteralArrayEncoding:(ImageView middleButtonMenu)) startUp |
|
118 |
" |
|
119 |
||
120 |
<resource: #menu> |
|
121 |
||
122 |
^ |
|
123 |
#(Menu |
|
124 |
( |
|
125 |
(MenuItem |
|
126 |
label: 'Size to Fit' |
|
5403 | 127 |
choice: adjustHolder |
5599 | 128 |
choiceValue: fitBig |
5597 | 129 |
) |
130 |
(MenuItem |
|
131 |
label: 'Size to Fit (smooth)' |
|
132 |
choice: adjustHolder |
|
5599 | 133 |
choiceValue: smoothFitBig |
4245 | 134 |
) |
135 |
(MenuItem |
|
136 |
label: 'Original Size' |
|
5403 | 137 |
choice: adjustHolder |
5599 | 138 |
choiceValue: topLeft |
139 |
) |
|
140 |
(MenuItem |
|
141 |
label: 'Magnify' |
|
142 |
submenu: |
|
143 |
(Menu |
|
144 |
( |
|
145 |
(MenuItem |
|
146 |
label: '* 2' |
|
147 |
itemValue: magnifyBy: |
|
148 |
argument: 2 |
|
149 |
) |
|
150 |
(MenuItem |
|
151 |
label: '* 4' |
|
152 |
itemValue: magnifyBy: |
|
153 |
argument: 4 |
|
154 |
) |
|
5610 | 155 |
(MenuItem |
156 |
label: '-' |
|
157 |
) |
|
158 |
(MenuItem |
|
159 |
label: 'Smoothing' |
|
160 |
indication: forceSmoothingHolder |
|
161 |
) |
|
5599 | 162 |
) |
163 |
nil |
|
164 |
nil |
|
165 |
) |
|
4245 | 166 |
) |
5482 | 167 |
(MenuItem |
168 |
label: '-' |
|
5610 | 169 |
isVisible: selfIsNotImageEditor |
5482 | 170 |
) |
171 |
(MenuItem |
|
172 |
label: 'Edit' |
|
173 |
itemValue: editImage |
|
5532 | 174 |
isVisible: selfIsNotImageEditor |
5482 | 175 |
) |
4245 | 176 |
) |
177 |
nil |
|
178 |
nil |
|
179 |
) |
|
180 |
! ! |
|
181 |
||
2511 | 182 |
!ImageView class methodsFor:'queries-plugin'! |
1694 | 183 |
|
184 |
aspectSelectors |
|
185 |
^ #( imageChannel ) |
|
186 |
||
187 |
"Created: / 11.2.2000 / 00:37:33 / cg" |
|
188 |
! ! |
|
189 |
||
257 | 190 |
!ImageView class methodsFor:'startup'! |
1 | 191 |
|
4192 | 192 |
openOn:anImageOrFileName |
5467 | 193 |
"startup an image viewer on an image or |
194 |
an image read from a file. |
|
195 |
Return the imageView (not the topView)" |
|
4192 | 196 |
|
197 |
anImageOrFileName isImage ifTrue:[ |
|
198 |
^ self openOnImage:anImageOrFileName |
|
199 |
]. |
|
200 |
^ self openOnFile:anImageOrFileName |
|
201 |
||
202 |
" |
|
203 |
ImageView openOn:'bitmaps/gifImages/garfield.gif' |
|
204 |
ImageView openOn:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' |
|
205 |
" |
|
206 |
||
5467 | 207 |
"Modified: / 31-10-1997 / 16:17:52 / cg" |
208 |
"Modified (comment): / 13-02-2017 / 10:13:13 / cg" |
|
4192 | 209 |
! |
210 |
||
211 |
openOnFile:aFileName |
|
5467 | 212 |
"startup an image viewer on an image read from a file. |
213 |
Return the imageView (not the topView)" |
|
47 | 214 |
|
1970 | 215 |
|fn imageView img e| |
216 |
||
217 |
fn := aFileName asFilename. |
|
47 | 218 |
|
1970 | 219 |
img := Image fromFile:fn. |
47 | 220 |
img isNil ifTrue:[ |
2747 | 221 |
fn exists ifTrue:[ |
222 |
e := 'Unknown or unsupported image format.' |
|
223 |
] ifFalse:[ |
|
224 |
e := 'No such image file.'. |
|
225 |
]. |
|
226 |
self warn:(self resources string:e). |
|
227 |
^ nil |
|
47 | 228 |
]. |
353 | 229 |
imageView := self openOnImage:img. |
3733 | 230 |
imageView topView label:(fn pathName) iconLabel:(fn baseName). |
353 | 231 |
^ imageView |
1 | 232 |
|
47 | 233 |
" |
4558 | 234 |
ImageView openOnFile:'../../goodies/bitmaps/gifImages/garfield.gif' |
235 |
ImageView openOnFile:'../../goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' |
|
47 | 236 |
" |
348 | 237 |
|
5467 | 238 |
"Modified: / 31-10-1997 / 16:17:52 / cg" |
239 |
"Modified (comment): / 13-02-2017 / 10:12:53 / cg" |
|
47 | 240 |
! |
241 |
||
242 |
openOnImage:anImage |
|
5467 | 243 |
"startup an image viewer on an image. |
244 |
Return the imageView (not the topView)" |
|
1 | 245 |
|
4558 | 246 |
|lbl| |
47 | 247 |
|
248 |
anImage isImage ifTrue:[ |
|
3733 | 249 |
lbl := anImage fileName ? 'an Image' |
47 | 250 |
] ifFalse:[ |
3904 | 251 |
anImage isNil ifTrue:[ |
252 |
lbl := 'an Image' |
|
253 |
] ifFalse:[ |
|
254 |
lbl := 'a Form' |
|
255 |
] |
|
47 | 256 |
]. |
4558 | 257 |
^ self openOnImage:anImage title:lbl |
258 |
||
259 |
" |
|
260 |
ImageView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif') title:'garfield' |
|
261 |
ImageView openOnImage:(Image fromFile:'../../libtool/bitmaps/SBrowser.xbm') title:'old browser icon' |
|
262 |
" |
|
5467 | 263 |
|
264 |
"Modified (comment): / 13-02-2017 / 10:12:43 / cg" |
|
4558 | 265 |
! |
266 |
||
267 |
openOnImage:anImage title:aString |
|
5467 | 268 |
"startup an image viewer on an image. |
269 |
Return the imageView (not the topView)" |
|
4558 | 270 |
|
271 |
|top v imageView icnW icnH iconView magX magY mag imgWidth imgHeight| |
|
272 |
||
273 |
top := StandardSystemView label:aString. |
|
1 | 274 |
|
275 |
v := HVScrollableView for:self in:top. |
|
5226 | 276 |
v origin:0@0 extent:1.0@1.0. |
1 | 277 |
imageView := v scrolledView. |
278 |
||
47 | 279 |
anImage notNil ifTrue:[ |
3733 | 280 |
imageView image:anImage. |
7 | 281 |
|
3733 | 282 |
"define an icon view showing a little version of image. |
283 |
Since some window managers cannot handle this correctly (twm), |
|
284 |
this is only done when running on an IRIS" |
|
7 | 285 |
|
5226 | 286 |
(true "(OperatingSystem getSystemType = 'iris')" |
3733 | 287 |
and:[StyleSheet name == #iris]) ifTrue:[ |
288 |
iconView := ImageView new. |
|
7 | 289 |
|
3733 | 290 |
"for now; should somehow get access to preferred iconview extent ..." |
291 |
icnW := 86. |
|
292 |
icnH := 68. |
|
7 | 293 |
|
3733 | 294 |
imgWidth := anImage width. |
295 |
imgHeight := anImage height. |
|
635 | 296 |
|
3733 | 297 |
((imgWidth <= icnW) and:[imgHeight <= icnH]) ifTrue:[ |
298 |
iconView extent:(imgWidth @ imgHeight). |
|
299 |
mag := 1 @ 1 |
|
300 |
] ifFalse:[ |
|
301 |
magX := icnW / imgWidth. |
|
302 |
magY := icnH / imgHeight. |
|
7 | 303 |
|
3733 | 304 |
"scale image" |
7 | 305 |
" |
3733 | 306 |
mag := magX @ magY. |
7 | 307 |
" |
3733 | 308 |
"preserve ratio" |
5226 | 309 |
" |
3733 | 310 |
mag := (magX min:magY) asPoint. |
5226 | 311 |
" |
3733 | 312 |
mag := (magX max:magY) asPoint. |
313 |
iconView extent:((anImage width @ anImage height) * mag) rounded. |
|
314 |
]. |
|
7 | 315 |
|
3733 | 316 |
top iconView:iconView. |
317 |
]. |
|
7 | 318 |
]. |
319 |
||
320 |
top open. |
|
321 |
||
26 | 322 |
iconView notNil ifTrue:[ |
3733 | 323 |
top windowGroup addView:iconView. |
5226 | 324 |
[ |
3733 | 325 |
iconView image:(anImage magnifiedBy:mag). |
326 |
] forkAt:4 |
|
7 | 327 |
]. |
353 | 328 |
^ imageView |
1 | 329 |
|
26 | 330 |
" |
4558 | 331 |
ImageView openOnImage:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') title:'garfield' |
332 |
ImageView openOnImage:(Image fromFile:'../../libtool/bitmaps/SBrowser.xbm') |
|
26 | 333 |
" |
353 | 334 |
|
3904 | 335 |
"Modified: / 01-06-2010 / 18:31:14 / cg" |
5467 | 336 |
"Modified (comment): / 13-02-2017 / 10:12:35 / cg" |
1 | 337 |
! ! |
338 |
||
161 | 339 |
!ImageView methodsFor:'accessing'! |
340 |
||
5387 | 341 |
adjust |
342 |
"get the adjust (how the image is displayed); |
|
5597 | 343 |
currently, support #topLeft, #center, #fitBig, #fitSmall and #fit: |
5387 | 344 |
#topLeft - image is displayed as usual |
345 |
#center - image is shown centered |
|
346 |
#fitBig - big images are shrunk to make it fit the view |
|
347 |
#fitSmall - small images are magnified to make it fit the view, |
|
348 |
#fit - all images are magnified to fit the view |
|
5597 | 349 |
#smoothFitBig - fitBig with smoothing |
350 |
#smoothFitSmall - fitSmall with smoothing |
|
351 |
#smoothFit - fit with smoothing |
|
5387 | 352 |
" |
353 |
||
354 |
^ adjust ? #topLeft |
|
5597 | 355 |
|
356 |
"Modified (comment): / 10-09-2017 / 17:06:16 / cg" |
|
5387 | 357 |
! |
358 |
||
161 | 359 |
adjust:layoutSymbol |
360 |
"set the adjust (how the image is displayed); |
|
5597 | 361 |
currently, support #topLeft, #center, #fitBig, #fitSmall and #fit: |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
362 |
#topLeft - image is displayed as usual |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
363 |
#center - image is shown centered |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
364 |
#fitBig - big images are shrunk to make it fit the view |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
365 |
#fitSmall - small images are magnified to make it fit the view, |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
366 |
#fit - all images are magnified to fit the view |
5403 | 367 |
#topLeftNoZoom - image is displayed as usual, and magnification is reset |
5597 | 368 |
#smoothFitBig - fitBig with smoothing |
369 |
#smoothFitSmall - fitSmall with smoothing |
|
370 |
#smoothFit - fit with smoothing |
|
2375 | 371 |
" |
2158 | 372 |
|
5403 | 373 |
|layoutUsed| |
374 |
||
375 |
layoutUsed := layoutSymbol. |
|
376 |
layoutUsed == #topLeftNoZoom ifTrue:[ |
|
377 |
layoutUsed := #topLeft |
|
378 |
]. |
|
379 |
self magnificationFactor ~= 1 ifTrue:[ |
|
5597 | 380 |
explicitMagnificationFactor := magnificationFactor := 1. |
5403 | 381 |
self magnificationFactor:1 |
382 |
]. |
|
383 |
||
384 |
adjust ~= layoutUsed ifTrue:[ |
|
385 |
adjust := layoutUsed. |
|
5402 | 386 |
adjustHolder notNil ifTrue:[ |
5403 | 387 |
adjustHolder value:layoutUsed withoutNotifying:self |
5402 | 388 |
]. |
161 | 389 |
|
5610 | 390 |
magnifiedImage := smoothMagnifiedImage := nil. |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
391 |
shown ifTrue:[ |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
392 |
image notNil ifTrue:[ |
5597 | 393 |
"/ self magnificationFactor ~= 1 ifTrue:[ |
5403 | 394 |
self generateMagnifiedImage. |
5597 | 395 |
"/ ]. |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
396 |
self clear. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
397 |
self scrollToTopLeft. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
398 |
self invalidate. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
399 |
self contentsChanged. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
400 |
] |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
401 |
]. |
2158 | 402 |
]. |
5597 | 403 |
|
5610 | 404 |
"Modified: / 28-09-2017 / 18:20:55 / cg" |
161 | 405 |
! |
406 |
||
5403 | 407 |
adjustHolder |
408 |
"get a valeHolder for the adjust (how the image is displayed); |
|
5597 | 409 |
currently, support #topLeft, #center, #fitBig, #fitSmall and #fit: |
5403 | 410 |
#topLeft - image is displayed as usual |
411 |
#center - image is shown centered |
|
412 |
#fitBig - big images are shrunk to make it fit the view |
|
413 |
#fitSmall - small images are magnified to make it fit the view, |
|
414 |
#fit - all images are magnified to fit the view |
|
5597 | 415 |
#smoothFitBig - fitBig with smoothing |
416 |
#smoothFitSmall - fitSmall with smoothing |
|
417 |
#smoothFit - fit with smoothing |
|
5403 | 418 |
" |
419 |
||
420 |
adjustHolder isNil ifTrue:[ |
|
421 |
adjustHolder := self adjust asValue. |
|
422 |
adjustHolder |
|
423 |
onChangeEvaluate:[ |
|
424 |
self adjust:(adjustHolder value). |
|
425 |
] |
|
426 |
]. |
|
427 |
^ adjustHolder |
|
5597 | 428 |
|
429 |
"Modified (comment): / 10-09-2017 / 17:06:23 / cg" |
|
5403 | 430 |
! |
431 |
||
5610 | 432 |
forceSmoothing |
433 |
^ self forceSmoothingHolder value |
|
434 |
||
435 |
"Created: / 28-09-2017 / 17:52:38 / cg" |
|
436 |
! |
|
437 |
||
438 |
forceSmoothing:aBoolean |
|
5611 | 439 |
self forceSmoothingHolder value:aBoolean. |
5610 | 440 |
|
441 |
"Created: / 28-09-2017 / 17:52:30 / cg" |
|
5611 | 442 |
"Modified: / 29-09-2017 / 10:30:32 / cg" |
5610 | 443 |
! |
444 |
||
445 |
forceSmoothingHolder |
|
446 |
forceSmoothingHolder isNil ifTrue:[ |
|
5611 | 447 |
forceSmoothingHolder := false asValue. |
448 |
forceSmoothingHolder |
|
449 |
onChangeEvaluate:[ |
|
450 |
smoothMagnifiedImage := nil. |
|
451 |
self invalidate. |
|
452 |
]. |
|
5610 | 453 |
]. |
454 |
^ forceSmoothingHolder |
|
455 |
||
456 |
"Created: / 28-09-2017 / 17:55:51 / cg" |
|
5611 | 457 |
"Modified: / 29-09-2017 / 10:30:57 / cg" |
5610 | 458 |
! |
459 |
||
161 | 460 |
image |
461 |
"return the image" |
|
462 |
||
463 |
^ image |
|
464 |
! |
|
465 |
||
466 |
image:anImage |
|
5398 | 467 |
"set the image scrolls as set by adjust |
468 |
- may show a wait cursor, if image dithering may take a while" |
|
1 | 469 |
|
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
470 |
self image:anImage scroll:true |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
471 |
! |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
472 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
473 |
image:anImage scroll:doScroll |
5398 | 474 |
"set the image possibly scroll as set by adjust |
475 |
- may show a wait cursor, if image dithering may take a while" |
|
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
476 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
477 |
self setImage:anImage scroll:doScroll |
1993 | 478 |
! |
479 |
||
3705 | 480 |
image:anImage scroll:doScroll invalidate:doInvalidate |
5398 | 481 |
"set the image possibly scroll as set by adjust |
482 |
- may show a wait cursor, if image dithering may take a while" |
|
3705 | 483 |
|
484 |
self setImage:anImage scroll:doScroll invalidate:doInvalidate |
|
485 |
! |
|
486 |
||
5488 | 487 |
imageEditAction:aOneArgBlockOrNil |
488 |
"if nonNil, aOneArgBlockOrNil will be called to open |
|
489 |
the image editor (as by the 'Edit Image' menu action). |
|
5487 | 490 |
If never set, the default ImageEditor is opened." |
491 |
||
5488 | 492 |
imageEditAction := aOneArgBlockOrNil. |
5487 | 493 |
|
5488 | 494 |
"Created: / 19-02-2017 / 22:58:14 / cg" |
5487 | 495 |
! |
496 |
||
3408 | 497 |
magnification |
498 |
magnifiedImage isNil ifTrue:[^ 1@1]. |
|
499 |
^ magnifiedImage extent / image extent |
|
500 |
! |
|
501 |
||
5387 | 502 |
magnificationFactor |
503 |
^ magnificationFactor ? 1 |
|
504 |
! |
|
505 |
||
506 |
magnificationFactor:aNumber |
|
5614 | 507 |
true "explicitMagnificationFactor ~= aNumber" ifTrue:[ |
5596 | 508 |
magnificationFactor := explicitMagnificationFactor := aNumber. |
5403 | 509 |
"/ magnificationFactor fractionPart < 0.1 ifTrue:[ |
510 |
"/ "magnifying by integer factor is faster" |
|
511 |
"/ magnificationFactor := magnificationFactor truncated. |
|
512 |
"/ ]. |
|
5614 | 513 |
self synchronized:[ |
514 |
smoothingProcess notNil ifTrue:[ |
|
515 |
smoothingProcess terminate. |
|
516 |
smoothMagnifiedImage := nil. |
|
517 |
]. |
|
518 |
]. |
|
5610 | 519 |
magnifiedImage := smoothMagnifiedImage := nil. |
5398 | 520 |
magnificationFactor = 1 ifTrue:[ |
521 |
self contentsChanged. |
|
522 |
]. |
|
523 |
self invalidate. |
|
524 |
]. |
|
5596 | 525 |
|
526 |
"Modified: / 06-09-2017 / 12:51:28 / Maren" |
|
5614 | 527 |
"Modified: / 04-10-2017 / 16:40:00 / cg" |
5387 | 528 |
! |
529 |
||
4066 | 530 |
model:aValueHolder |
531 |
super model:aValueHolder. |
|
532 |
self updateFromModel. |
|
533 |
||
534 |
"Created: / 25-07-2011 / 15:32:10 / cg" |
|
535 |
! |
|
536 |
||
1993 | 537 |
setImage:anImage |
538 |
"set the image - show a wait cursor, since image dithering may take a while" |
|
539 |
||
4966 | 540 |
self setImage:anImage scroll:true invalidate:true |
1694 | 541 |
|
542 |
"Modified: / 10.2.2000 / 23:25:51 / cg" |
|
2089 | 543 |
! |
544 |
||
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
545 |
setImage:anImage scroll:doScroll |
5398 | 546 |
"set the image - may show a wait cursor, if image dithering may take a while" |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
547 |
|
3710
162a45c5ce34
invalidate when image changes
Claus Gittinger <cg@exept.de>
parents:
3705
diff
changeset
|
548 |
self setImage:anImage scroll:doScroll invalidate:true |
3705 | 549 |
! |
550 |
||
551 |
setImage:anImage scroll:doScroll invalidate:doInvalidate |
|
5398 | 552 |
"set the image - may show a wait cursor, if image dithering may take a while" |
3705 | 553 |
|
4966 | 554 |
|oldSize newSize newImageIsSmaller| |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
555 |
|
5688 | 556 |
self assert:(anImage isImageOrForm or:[anImage isNil]). |
5430 | 557 |
|
5226 | 558 |
oldSize := image isNil ifTrue:[0@0] ifFalse:[image extent]. |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
559 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
560 |
image := anImage. |
5610 | 561 |
magnifiedImage := smoothMagnifiedImage := nil. |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
562 |
self generateMagnifiedImage. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
563 |
|
5226 | 564 |
newSize := image isNil ifTrue:[0@0] ifFalse:[(magnifiedImage ? image) extent]. |
4966 | 565 |
newImageIsSmaller := ((oldSize x > newSize x) or:[oldSize y > newSize y]). |
5226 | 566 |
|
5227 | 567 |
(newImageIsSmaller and:[ doInvalidate ]) ifTrue:[ self invalidate ]. |
568 |
doScroll ifTrue:[ self scrollToTopLeft ]. |
|
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
569 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
570 |
oldSize ~= newSize ifTrue:[ |
3705 | 571 |
"/ avoid endless loop in case of a resize happening due |
572 |
"/ to scrollBar visibility changes. |
|
5226 | 573 |
"/ that QuerySignal suppresses another magnification in sizeChanged: |
5688 | 574 |
DoNotMagnifyQuery answer:true do:[ self contentsChanged ] |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
575 |
]. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
576 |
|
3705 | 577 |
(shown and:[doInvalidate]) ifTrue:[ |
5268 | 578 |
"/ (anImage isNil "or:[newImageIsSmaller]") ifTrue:[ |
579 |
"/ self clear. |
|
580 |
"/ ]. |
|
3705 | 581 |
self invalidate |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
582 |
]. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
583 |
self changed:#image. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
584 |
|
5610 | 585 |
"Modified: / 28-09-2017 / 18:21:07 / cg" |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
586 |
! |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
587 |
|
4245 | 588 |
sizeToFit:aBoolean |
589 |
aBoolean ifTrue:[ |
|
590 |
self adjust:#fitBig |
|
591 |
] ifFalse:[ |
|
5597 | 592 |
explicitMagnificationFactor := magnificationFactor := 1. |
4245 | 593 |
self adjust:nil. |
594 |
] |
|
5597 | 595 |
|
596 |
"Modified: / 10-09-2017 / 17:54:49 / cg" |
|
4245 | 597 |
! |
598 |
||
2089 | 599 |
tileMode:aBoolean tileOffset:aPoint |
600 |
||
601 |
tileMode := aBoolean. |
|
602 |
tileOffset := aPoint |
|
1694 | 603 |
! ! |
604 |
||
2404 | 605 |
!ImageView methodsFor:'accessing-channels'! |
1510
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
606 |
|
1694 | 607 |
imageChannel |
4031 | 608 |
^ self model |
1694 | 609 |
|
4031 | 610 |
"Modified: / 31-03-2011 / 10:45:58 / cg" |
1694 | 611 |
! |
612 |
||
613 |
imageChannel:aValueHolder |
|
4031 | 614 |
self model:aValueHolder. |
1694 | 615 |
|
4031 | 616 |
"Created: / 11-02-2000 / 00:34:33 / cg" |
617 |
"Modified: / 31-03-2011 / 10:46:07 / cg" |
|
5503 | 618 |
! |
619 |
||
620 |
mousePointHolder |
|
621 |
^ lastMousePoint |
|
622 |
||
623 |
"Created: / 25-02-2017 / 22:36:02 / cg" |
|
1694 | 624 |
! ! |
1135
75101bf02c5b
send contentsChanged notifications before, to avoid
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
625 |
|
1694 | 626 |
!ImageView methodsFor:'change & update'! |
627 |
||
628 |
update:something with:aParameter from:changedObject |
|
4031 | 629 |
changedObject == model ifTrue:[ |
4561 | 630 |
self updateFromModel. |
2786
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
631 |
^ self |
1694 | 632 |
]. |
633 |
super update:something with:aParameter from:changedObject |
|
634 |
||
4031 | 635 |
"Created: / 11-02-2000 / 00:37:02 / cg" |
636 |
"Modified: / 31-03-2011 / 10:46:16 / cg" |
|
2786
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
637 |
! |
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
638 |
|
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
639 |
updateFromModel |
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
640 |
"the model changes, set my image" |
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
641 |
|
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
642 |
self image:model value. |
1 | 643 |
! ! |
644 |
||
645 |
!ImageView methodsFor:'drawing'! |
|
646 |
||
2158 | 647 |
generateMagnifiedImage |
5597 | 648 |
|adj smooth doFit innerWidth innerHeight imgWidth imgHeight| |
2158 | 649 |
|
2358 | 650 |
image isNil ifTrue:[ |
4124 | 651 |
^ self |
2358 | 652 |
]. |
2158 | 653 |
|
5610 | 654 |
smoothMagnifiedImage notNil ifTrue:[ |
655 |
^ self |
|
656 |
]. |
|
657 |
||
5597 | 658 |
adj := adjust. |
659 |
smooth := false. |
|
660 |
(adjust notNil and:[adjust startsWith:#smooth]) ifTrue:[ |
|
661 |
adj := (adjust copyFrom:'smooth' size+1) asLowercaseFirst asSymbol. |
|
662 |
smooth := true. |
|
663 |
]. |
|
5610 | 664 |
self forceSmoothing ifTrue:[smooth := true]. |
665 |
||
666 |
magnifiedImage isNil ifTrue:[ |
|
667 |
doFit := false. |
|
668 |
||
669 |
innerWidth := self innerWidth. |
|
670 |
innerHeight := self innerHeight. |
|
5596 | 671 |
|
5610 | 672 |
imgWidth := image width. |
673 |
imgHeight := image height. |
|
674 |
||
675 |
((adj == #fit) or:[adj == #fitBig or:[adj == #fitSmall]]) ifTrue:[ |
|
676 |
magnificationFactor := explicitMagnificationFactor. |
|
677 |
]. |
|
678 |
||
679 |
tileMode ~~ true ifTrue:[ |
|
680 |
((imgWidth > innerWidth) |
|
681 |
or:[imgHeight > innerHeight]) ifTrue:[ |
|
682 |
((adj == #fit) or:[adj == #fitBig]) ifTrue:[ |
|
4124 | 683 |
doFit := true |
684 |
]. |
|
5610 | 685 |
] ifFalse:[ |
686 |
((imgWidth < innerWidth) |
|
687 |
or:[imgHeight < innerHeight]) ifTrue:[ |
|
688 |
((adj == #fit) or:[adj == #fitSmall]) ifTrue:[ |
|
689 |
doFit := true |
|
690 |
]. |
|
691 |
] |
|
692 |
]. |
|
4124 | 693 |
]. |
5610 | 694 |
|
695 |
doFit ifTrue:[ |
|
696 |
magnifiedImage := image magnifiedPreservingRatioTo:(innerWidth @ innerHeight) smooth:false "smooth". |
|
697 |
magnificationFactor := magnifiedImage width / imgWidth. |
|
698 |
] ifFalse:[ |
|
699 |
(magnificationFactor notNil and:[magnificationFactor ~= 1]) ifTrue:[ |
|
700 |
magnifiedImage := image magnifiedBy:magnificationFactor smooth:false "smooth". |
|
701 |
] ifFalse:[ |
|
702 |
magnifiedImage := image. |
|
703 |
]. |
|
704 |
]. |
|
705 |
||
706 |
(magnifiedImage width == 0 or:[magnifiedImage height == 0]) ifTrue:[ |
|
707 |
magnifiedImage := nil. |
|
708 |
]. |
|
709 |
||
710 |
smooth ifTrue:[ |
|
711 |
smoothMagnifiedImage := nil. |
|
712 |
] ifFalse:[ |
|
713 |
smoothMagnifiedImage := magnifiedImage. |
|
714 |
]. |
|
715 |
||
716 |
self contentsChanged. |
|
2158 | 717 |
]. |
5597 | 718 |
|
5610 | 719 |
smooth ifTrue:[ |
720 |
magnifiedImage extent = image extent ifTrue:[ |
|
721 |
smoothMagnifiedImage := magnifiedImage |
|
722 |
] ifFalse:[ |
|
723 |
smoothMagnifiedImage := nil. |
|
724 |
||
725 |
self synchronized:[ |
|
726 |
smoothingProcess notNil ifTrue:[ |
|
727 |
smoothingProcess terminate. |
|
728 |
smoothMagnifiedImage := nil. |
|
729 |
]. |
|
730 |
smoothingProcess := |
|
731 |
[ |
|
5615 | 732 |
|i| |
733 |
||
734 |
(i := magnifiedImage) notNil ifTrue:[ |
|
735 |
smoothMagnifiedImage := image magnifiedTo:(i extent) smooth:true. |
|
736 |
self invalidate. |
|
737 |
] |
|
5610 | 738 |
] fork. |
739 |
]. |
|
740 |
]. |
|
2158 | 741 |
]. |
4124 | 742 |
|
5596 | 743 |
"Modified: / 06-09-2017 / 12:52:19 / Maren" |
5615 | 744 |
"Modified: / 04-10-2017 / 16:43:44 / cg" |
2158 | 745 |
! |
746 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
747 |
redrawX:x y:y width:w height:h |
5227 | 748 |
|xI yI depth shownImage imgWidth imgHeight right bott "rectRight rectBelow"| |
11 | 749 |
|
1 | 750 |
image notNil ifTrue:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
751 |
self generateMagnifiedImage. |
2158 | 752 |
|
5610 | 753 |
shownImage := smoothMagnifiedImage ? magnifiedImage ? image. |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
754 |
imgWidth := shownImage width. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
755 |
imgHeight := shownImage height. |
635 | 756 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
757 |
adjust == #center ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
758 |
xI := (width - (margin * 2) - imgWidth) // 2. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
759 |
yI := (height - (margin * 2) - imgHeight) // 2. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
760 |
] ifFalse:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
761 |
xI := yI := margin |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
762 |
]. |
414 | 763 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
764 |
((depth := shownImage depth) == 1) ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
765 |
self paint:(shownImage colorFromValue:1) |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
766 |
on:(shownImage colorFromValue:0). |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
767 |
]. |
1071
981c97fe54de
generate device image before clearing in redraw
Claus Gittinger <cg@exept.de>
parents:
677
diff
changeset
|
768 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
769 |
tileMode == true ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
770 |
(tileOffset y > 0 and:[tileOffset x > 0]) ifTrue:[ |
5022 | 771 |
(false "depth ~~ 1" |
772 |
or:[shownImage mask notNil]) ifTrue:[ |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
773 |
self clearRectangleX:x y:y width:w height:h. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
774 |
0 to:y+h by:tileOffset y do:[:oY | |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
775 |
0 to:x+w by:tileOffset x do:[:oX | |
5530 | 776 |
gc displayForm:image x:oX y:oY |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
777 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
778 |
]. |
5022 | 779 |
] ifFalse:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
780 |
0 to:y+h by:tileOffset y do:[:oY | |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
781 |
0 to:x+w by:tileOffset x do:[:oX | |
5530 | 782 |
gc displayOpaqueForm:image x:oX y:oY |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
783 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
784 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
785 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
786 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
787 |
] ifFalse:[ |
5227 | 788 |
"/rectRight := (shownImage width @ 0) corner:(width @ shownImage height). |
789 |
"/rectBelow := 0 @ (shownImage height) corner:(shownImage height @ height). |
|
790 |
"/(rectRight width > 0 and:[rectRight height > 0]) ifTrue:[ self clearRectangle:rectRight ]. |
|
791 |
"/(rectBelow width > 0 and:[rectBelow height > 0]) ifTrue:[ self clearRectangle:rectBelow ]. |
|
792 |
||
3726 | 793 |
xI > (x+w) ifTrue:[^ self]. "/ no need to draw |
794 |
yI > (y+h) ifTrue:[^ self]. "/ no need to draw |
|
795 |
(xI+imgWidth) < x ifTrue:[^ self]. "/ no need to draw |
|
796 |
(yI+imgHeight) < y ifTrue:[^ self]. "/ no need to draw |
|
797 |
||
5022 | 798 |
(false "depth ~~ 1" |
3726 | 799 |
or:[shownImage mask notNil]) ifTrue:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
800 |
self clearRectangleX:x y:y width:w height:h. |
3726 | 801 |
shownImage displayOn:self x:xI y:yI. |
5226 | 802 |
"/ self displayForm:shownImage x:xI y:yI |
3726 | 803 |
] ifFalse:[ |
5699 | 804 |
(shownImage depth == 32 and:[ shownImage hasAlphaChannel ]) ifTrue:[ |
805 |
"/ now, we support at least some 32rgba images... |
|
5530 | 806 |
true "device supportsAlphaChannel" ifTrue:[ |
807 |
self clearRectangleX:x y:y width:w height:h. |
|
5699 | 808 |
self displayForm:shownImage x:xI y:yI |
5530 | 809 |
] ifFalse:[ |
5699 | 810 |
"/ hack: currently 32bit+alpha is not supported by Displays. |
811 |
"/ make it a masked d24 image and draw that. |
|
812 |
||
5530 | 813 |
|d24Image| |
814 |
||
815 |
d24Image := Depth24Image fromImage:shownImage. |
|
816 |
d24Image mask:(ImageMask fromAlphaInImage:shownImage). |
|
817 |
self clearRectangleX:x y:y width:w height:h. |
|
818 |
d24Image displayOn:self x:xI y:yI. |
|
819 |
] |
|
5529 | 820 |
] ifFalse:[ |
5530 | 821 |
gc displayOpaqueForm:shownImage x:xI y:yI |
5529 | 822 |
]. |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
823 |
]. |
430 | 824 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
825 |
"/ right of image ? |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
826 |
right := x + w - 1. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
827 |
right > (xI + imgWidth) ifTrue:[ |
5022 | 828 |
self clearRectangleX:(xI + imgWidth) y:y |
5595 | 829 |
width:(right - imgWidth - xI) height:h |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
830 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
831 |
"/ below of image ? |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
832 |
bott := y + h - 1. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
833 |
bott > (yI + imgHeight) ifTrue:[ |
5022 | 834 |
self clearRectangleX:margin y:(yI + imgHeight) |
5595 | 835 |
width:w height:(bott - imgHeight - yI) |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
836 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
837 |
]. |
5268 | 838 |
] ifFalse:[ |
839 |
self clearRectangleX:x y:y width:w height:h. |
|
5529 | 840 |
]. |
89 | 841 |
|
5529 | 842 |
"Created: / 11-07-1996 / 21:02:12 / cg" |
5610 | 843 |
"Modified: / 28-09-2017 / 18:19:01 / cg" |
1 | 844 |
! ! |
845 |
||
2158 | 846 |
!ImageView methodsFor:'event handling'! |
847 |
||
3618 | 848 |
buttonMotion:state x:x y:y |
5503 | 849 |
|delta mousePoint lastPoint| |
3618 | 850 |
|
5616 | 851 |
(state ~~ 0 and:[(lastPoint := lastMousePoint value) notNil]) ifTrue:[ |
3618 | 852 |
mousePoint := (x@y). |
5503 | 853 |
delta := mousePoint - lastPoint. |
3618 | 854 |
delta ~= (0@0) ifTrue:[ |
5616 | 855 |
"/ lastMousePoint value:mousePoint. |
856 |
self scrollTo:(self viewOrigin - delta) "/ waitForDrawingFinished:true. |
|
3618 | 857 |
] |
858 |
] ifFalse:[ |
|
859 |
super buttonMotion:state x:x y:y |
|
860 |
] |
|
5503 | 861 |
|
5616 | 862 |
"Modified: / 05-10-2017 / 13:54:48 / cg" |
3618 | 863 |
! |
864 |
||
865 |
buttonPress:button x:x y:y |
|
866 |
button == 1 ifTrue:[ |
|
4124 | 867 |
"self cursor:(Cursor handGrab). " |
5503 | 868 |
lastMousePoint value:( x@y ). |
5616 | 869 |
"/ self sensor compressMotionEvents:true. |
3618 | 870 |
]. |
871 |
super buttonPress:button x:x y:y |
|
4124 | 872 |
|
5616 | 873 |
"Modified: / 05-10-2017 / 13:56:06 / cg" |
3618 | 874 |
! |
875 |
||
876 |
buttonRelease:button x:x y:y |
|
877 |
button == 1 ifTrue:[ |
|
5503 | 878 |
lastMousePoint value: nil |
3618 | 879 |
]. |
880 |
super buttonRelease:button x:x y:y |
|
5503 | 881 |
|
882 |
"Modified: / 25-02-2017 / 22:35:20 / cg" |
|
3618 | 883 |
! |
884 |
||
4124 | 885 |
mouseWheelZoom:amount |
886 |
"CTRL-wheel action" |
|
887 |
||
888 |
|mul| |
|
889 |
||
890 |
amount > 0 ifTrue:[ |
|
891 |
mul := 1.2. |
|
892 |
] ifFalse:[ |
|
893 |
mul := 0.8. |
|
894 |
]. |
|
5387 | 895 |
self magnificationFactor:((magnificationFactor ? 1) * mul). |
4124 | 896 |
|
897 |
"Created: / 06-05-2012 / 12:18:06 / cg" |
|
898 |
! |
|
899 |
||
2158 | 900 |
sizeChanged:how |
5597 | 901 |
(#(fit fitBig fitSmall smoothFit smoothFitBig smoothFitSmall) includes:adjust) ifTrue:[ |
2911
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
902 |
magnifiedImage notNil ifTrue:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
903 |
DoNotMagnifyQuery query ifFalse:[ |
5387 | 904 |
self pushEvent:#updateImageAfterSizeChange. |
2911
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
905 |
] |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
906 |
]. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
907 |
] ifFalse:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
908 |
adjust == #center ifTrue:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
909 |
self clear. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
910 |
self invalidate. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
911 |
]. |
2158 | 912 |
]. |
913 |
super sizeChanged:how |
|
5597 | 914 |
|
915 |
"Modified: / 10-09-2017 / 17:11:08 / cg" |
|
5387 | 916 |
! |
917 |
||
918 |
updateImageAfterSizeChange |
|
5399 | 919 |
|oldMagnifiedImage| |
920 |
||
921 |
oldMagnifiedImage := magnifiedImage. |
|
5610 | 922 |
smoothMagnifiedImage := magnifiedImage := nil. |
923 |
||
5387 | 924 |
self generateMagnifiedImage. |
5610 | 925 |
|
5400 | 926 |
(oldMagnifiedImage isNil |
927 |
or:[ magnifiedImage isNil |
|
928 |
or:[ oldMagnifiedImage extent ~= magnifiedImage extent ]] |
|
929 |
) ifTrue:[ |
|
930 |
"/ self clear. |
|
5399 | 931 |
self invalidate. |
932 |
]. |
|
5610 | 933 |
|
934 |
"Modified (format): / 28-09-2017 / 18:20:32 / cg" |
|
2158 | 935 |
! ! |
936 |
||
2501 | 937 |
!ImageView methodsFor:'initialization & release'! |
1327 | 938 |
|
939 |
destroy |
|
5610 | 940 |
magnifiedImage := smoothMagnifiedImage := nil. |
5404 | 941 |
"/ image := nil. |
1327 | 942 |
super destroy. |
5610 | 943 |
|
944 |
"Modified: / 28-09-2017 / 18:20:44 / cg" |
|
5503 | 945 |
! |
946 |
||
947 |
initialize |
|
948 |
super initialize. |
|
949 |
||
950 |
lastMousePoint := nil asValue. |
|
951 |
||
952 |
"Created: / 25-02-2017 / 22:33:27 / cg" |
|
1327 | 953 |
! ! |
954 |
||
4245 | 955 |
!ImageView methodsFor:'menu'! |
956 |
||
5482 | 957 |
editImage |
5488 | 958 |
|img| |
959 |
||
960 |
img := self image. |
|
961 |
imageEditAction notNil ifTrue:[ |
|
962 |
imageEditAction value:img |
|
963 |
] ifFalse:[ |
|
964 |
ImageEditor openOnImage:img. |
|
965 |
]. |
|
5482 | 966 |
|
967 |
"Created: / 16-02-2017 / 19:01:41 / cg" |
|
5488 | 968 |
"Modified: / 19-02-2017 / 23:01:14 / cg" |
5482 | 969 |
! |
970 |
||
5599 | 971 |
magnifyBy:scale |
972 |
self adjustHolder value:#Mag. |
|
973 |
self adjust:#topLeft. |
|
974 |
self magnificationFactor:scale. |
|
975 |
||
976 |
"Created: / 13-09-2017 / 09:43:11 / cg" |
|
977 |
! |
|
978 |
||
4245 | 979 |
middleButtonMenu |
4263 | 980 |
menuHolder notNil ifTrue:[^ super middleButtonMenu]. |
4245 | 981 |
^ self class middleButtonMenu |
982 |
! ! |
|
983 |
||
161 | 984 |
!ImageView methodsFor:'queries'! |
24 | 985 |
|
161 | 986 |
heightOfContents |
5387 | 987 |
"return the image's height - scrollbar needs this info" |
1 | 988 |
|
161 | 989 |
image isNil ifTrue:[^ 0]. |
2158 | 990 |
^ (magnifiedImage ? image) height |
89 | 991 |
! |
992 |
||
5482 | 993 |
selfIsNotImageEditor |
994 |
"for the menu; to hide edit item" |
|
995 |
||
996 |
^ self class == ImageView |
|
997 |
||
998 |
"Created: / 16-02-2017 / 19:00:59 / cg" |
|
999 |
! |
|
1000 |
||
1 | 1001 |
widthOfContents |
5387 | 1002 |
"return the image's width - scrollbar needs this info" |
1 | 1003 |
|
1004 |
image isNil ifTrue:[^ 0]. |
|
2158 | 1005 |
^ (magnifiedImage ? image) width |
161 | 1006 |
! ! |
1007 |
||
3408 | 1008 |
!ImageView methodsFor:'scrolling'! |
1009 |
||
5555 | 1010 |
scrollToMakeRectangleVisible:aRectangle |
1011 |
"try to arrange for aRectangle to be visible (at the center, if possible)" |
|
1012 |
||
1013 |
self scrollToMakeVisible:(aRectangle center). |
|
1014 |
self scrollToMakeVisible:(aRectangle corner). |
|
1015 |
self scrollToMakeVisible:(aRectangle origin). |
|
1016 |
||
1017 |
" |
|
1018 |
|v| |
|
1019 |
v := ImageView new image:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'). |
|
1020 |
v openAndWait. |
|
1021 |
v inspect. |
|
1022 |
v scrollToMakeRectangleVisible:((300@100) corner:(320@120)). |
|
1023 |
" |
|
1024 |
||
1025 |
"Created: / 20-07-2017 / 13:45:29 / cg" |
|
1026 |
! |
|
1027 |
||
3408 | 1028 |
scrollToMakeVisible:aPoint |
5555 | 1029 |
"try to arrange for aPoint (in logical image coordinates) |
1030 |
to be visible (at the center, if possible)" |
|
3408 | 1031 |
|
5693 | 1032 |
|mag magPos imgExtent newOffset| |
1033 |
||
1034 |
imgExtent := 0@0. |
|
5721 | 1035 |
image notNil ifTrue:[ |
5693 | 1036 |
imgExtent := image extent. |
1037 |
]. |
|
3408 | 1038 |
|
1039 |
mag := self magnification. |
|
5555 | 1040 |
magPos := aPoint * mag. |
1041 |
||
1042 |
((self bounds + self viewOrigin) containsPoint:magPos) ifFalse:[ |
|
1043 |
newOffset := magPos - (self extent / 2). |
|
1044 |
newOffset := newOffset max:(0@0). |
|
5693 | 1045 |
newOffset := newOffset min:((imgExtent * mag) - (self extent / 2)). |
5721 | 1046 |
newOffset := newOffset rounded. |
5556 | 1047 |
self scrollTo:newOffset waitForDrawingFinished:true. |
5507 | 1048 |
]. |
1049 |
||
1050 |
" |
|
1051 |
|v| |
|
1052 |
v := ImageView new image:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'). |
|
1053 |
v openAndWait. |
|
1054 |
v inspect. |
|
1055 |
v scrollToMakeVisible:(300@100). |
|
1056 |
" |
|
1057 |
||
5556 | 1058 |
"Modified: / 20-07-2017 / 14:37:11 / cg" |
3408 | 1059 |
! ! |
1060 |
||
257 | 1061 |
!ImageView class methodsFor:'documentation'! |
161 | 1062 |
|
1063 |
version |
|
4912 | 1064 |
^ '$Header$' |
3884 | 1065 |
! |
1066 |
||
1067 |
version_CVS |
|
4912 | 1068 |
^ '$Header$' |
1 | 1069 |
! ! |
2358 | 1070 |
|
4192 | 1071 |
|
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
1072 |
ImageView initialize! |