author | Claus Gittinger <cg@exept.de> |
Wed, 04 Oct 2017 16:44:14 +0200 | |
changeset 5615 | 38692913900c |
parent 5614 | eb3741274c29 |
child 5616 | 4ff2c28c261c |
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 |
|
5534 | 556 |
self assert:(anImage isImage or:[anImage isForm 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: |
574 |
DoNotMagnifyQuery |
|
4966 | 575 |
answer:true |
576 |
do:[ |
|
577 |
self contentsChanged. |
|
578 |
] |
|
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
579 |
]. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
580 |
|
3705 | 581 |
(shown and:[doInvalidate]) ifTrue:[ |
5268 | 582 |
"/ (anImage isNil "or:[newImageIsSmaller]") ifTrue:[ |
583 |
"/ self clear. |
|
584 |
"/ ]. |
|
3705 | 585 |
self invalidate |
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 |
self changed:#image. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
588 |
|
5610 | 589 |
"Modified: / 28-09-2017 / 18:21:07 / cg" |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
590 |
! |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
591 |
|
4245 | 592 |
sizeToFit:aBoolean |
593 |
aBoolean ifTrue:[ |
|
594 |
self adjust:#fitBig |
|
595 |
] ifFalse:[ |
|
5597 | 596 |
explicitMagnificationFactor := magnificationFactor := 1. |
4245 | 597 |
self adjust:nil. |
598 |
] |
|
5597 | 599 |
|
600 |
"Modified: / 10-09-2017 / 17:54:49 / cg" |
|
4245 | 601 |
! |
602 |
||
2089 | 603 |
tileMode:aBoolean tileOffset:aPoint |
604 |
||
605 |
tileMode := aBoolean. |
|
606 |
tileOffset := aPoint |
|
1694 | 607 |
! ! |
608 |
||
2404 | 609 |
!ImageView methodsFor:'accessing-channels'! |
1510
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
610 |
|
1694 | 611 |
imageChannel |
4031 | 612 |
^ self model |
1694 | 613 |
|
4031 | 614 |
"Modified: / 31-03-2011 / 10:45:58 / cg" |
1694 | 615 |
! |
616 |
||
617 |
imageChannel:aValueHolder |
|
4031 | 618 |
self model:aValueHolder. |
1694 | 619 |
|
4031 | 620 |
"Created: / 11-02-2000 / 00:34:33 / cg" |
621 |
"Modified: / 31-03-2011 / 10:46:07 / cg" |
|
5503 | 622 |
! |
623 |
||
624 |
mousePointHolder |
|
625 |
^ lastMousePoint |
|
626 |
||
627 |
"Created: / 25-02-2017 / 22:36:02 / cg" |
|
1694 | 628 |
! ! |
1135
75101bf02c5b
send contentsChanged notifications before, to avoid
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
629 |
|
1694 | 630 |
!ImageView methodsFor:'change & update'! |
631 |
||
632 |
update:something with:aParameter from:changedObject |
|
4031 | 633 |
changedObject == model ifTrue:[ |
4561 | 634 |
self updateFromModel. |
2786
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
635 |
^ self |
1694 | 636 |
]. |
637 |
super update:something with:aParameter from:changedObject |
|
638 |
||
4031 | 639 |
"Created: / 11-02-2000 / 00:37:02 / cg" |
640 |
"Modified: / 31-03-2011 / 10:46:16 / cg" |
|
2786
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 |
|
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
643 |
updateFromModel |
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
644 |
"the model changes, set my image" |
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
645 |
|
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
646 |
self image:model value. |
1 | 647 |
! ! |
648 |
||
649 |
!ImageView methodsFor:'drawing'! |
|
650 |
||
2158 | 651 |
generateMagnifiedImage |
5597 | 652 |
|adj smooth doFit innerWidth innerHeight imgWidth imgHeight| |
2158 | 653 |
|
2358 | 654 |
image isNil ifTrue:[ |
4124 | 655 |
^ self |
2358 | 656 |
]. |
2158 | 657 |
|
5610 | 658 |
smoothMagnifiedImage notNil ifTrue:[ |
659 |
^ self |
|
660 |
]. |
|
661 |
||
5597 | 662 |
adj := adjust. |
663 |
smooth := false. |
|
664 |
(adjust notNil and:[adjust startsWith:#smooth]) ifTrue:[ |
|
665 |
adj := (adjust copyFrom:'smooth' size+1) asLowercaseFirst asSymbol. |
|
666 |
smooth := true. |
|
667 |
]. |
|
5610 | 668 |
self forceSmoothing ifTrue:[smooth := true]. |
669 |
||
670 |
magnifiedImage isNil ifTrue:[ |
|
671 |
doFit := false. |
|
672 |
||
673 |
innerWidth := self innerWidth. |
|
674 |
innerHeight := self innerHeight. |
|
5596 | 675 |
|
5610 | 676 |
imgWidth := image width. |
677 |
imgHeight := image height. |
|
678 |
||
679 |
((adj == #fit) or:[adj == #fitBig or:[adj == #fitSmall]]) ifTrue:[ |
|
680 |
magnificationFactor := explicitMagnificationFactor. |
|
681 |
]. |
|
682 |
||
683 |
tileMode ~~ true ifTrue:[ |
|
684 |
((imgWidth > innerWidth) |
|
685 |
or:[imgHeight > innerHeight]) ifTrue:[ |
|
686 |
((adj == #fit) or:[adj == #fitBig]) ifTrue:[ |
|
4124 | 687 |
doFit := true |
688 |
]. |
|
5610 | 689 |
] ifFalse:[ |
690 |
((imgWidth < innerWidth) |
|
691 |
or:[imgHeight < innerHeight]) ifTrue:[ |
|
692 |
((adj == #fit) or:[adj == #fitSmall]) ifTrue:[ |
|
693 |
doFit := true |
|
694 |
]. |
|
695 |
] |
|
696 |
]. |
|
4124 | 697 |
]. |
5610 | 698 |
|
699 |
doFit ifTrue:[ |
|
700 |
magnifiedImage := image magnifiedPreservingRatioTo:(innerWidth @ innerHeight) smooth:false "smooth". |
|
701 |
magnificationFactor := magnifiedImage width / imgWidth. |
|
702 |
] ifFalse:[ |
|
703 |
(magnificationFactor notNil and:[magnificationFactor ~= 1]) ifTrue:[ |
|
704 |
magnifiedImage := image magnifiedBy:magnificationFactor smooth:false "smooth". |
|
705 |
] ifFalse:[ |
|
706 |
magnifiedImage := image. |
|
707 |
]. |
|
708 |
]. |
|
709 |
||
710 |
(magnifiedImage width == 0 or:[magnifiedImage height == 0]) ifTrue:[ |
|
711 |
magnifiedImage := nil. |
|
712 |
]. |
|
713 |
||
714 |
smooth ifTrue:[ |
|
715 |
smoothMagnifiedImage := nil. |
|
716 |
] ifFalse:[ |
|
717 |
smoothMagnifiedImage := magnifiedImage. |
|
718 |
]. |
|
719 |
||
720 |
self contentsChanged. |
|
2158 | 721 |
]. |
5597 | 722 |
|
5610 | 723 |
smooth ifTrue:[ |
724 |
magnifiedImage extent = image extent ifTrue:[ |
|
725 |
smoothMagnifiedImage := magnifiedImage |
|
726 |
] ifFalse:[ |
|
727 |
smoothMagnifiedImage := nil. |
|
728 |
||
729 |
self synchronized:[ |
|
730 |
smoothingProcess notNil ifTrue:[ |
|
731 |
smoothingProcess terminate. |
|
732 |
smoothMagnifiedImage := nil. |
|
733 |
]. |
|
734 |
smoothingProcess := |
|
735 |
[ |
|
5615 | 736 |
|i| |
737 |
||
738 |
(i := magnifiedImage) notNil ifTrue:[ |
|
739 |
smoothMagnifiedImage := image magnifiedTo:(i extent) smooth:true. |
|
740 |
self invalidate. |
|
741 |
] |
|
5610 | 742 |
] fork. |
743 |
]. |
|
744 |
]. |
|
2158 | 745 |
]. |
4124 | 746 |
|
5596 | 747 |
"Modified: / 06-09-2017 / 12:52:19 / Maren" |
5615 | 748 |
"Modified: / 04-10-2017 / 16:43:44 / cg" |
2158 | 749 |
! |
750 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
751 |
redrawX:x y:y width:w height:h |
5227 | 752 |
|xI yI depth shownImage imgWidth imgHeight right bott "rectRight rectBelow"| |
11 | 753 |
|
1 | 754 |
image notNil ifTrue:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
755 |
self generateMagnifiedImage. |
2158 | 756 |
|
5610 | 757 |
shownImage := smoothMagnifiedImage ? magnifiedImage ? image. |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
758 |
imgWidth := shownImage width. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
759 |
imgHeight := shownImage height. |
635 | 760 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
761 |
adjust == #center ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
762 |
xI := (width - (margin * 2) - imgWidth) // 2. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
763 |
yI := (height - (margin * 2) - imgHeight) // 2. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
764 |
] ifFalse:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
765 |
xI := yI := margin |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
766 |
]. |
414 | 767 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
768 |
((depth := shownImage depth) == 1) ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
769 |
self paint:(shownImage colorFromValue:1) |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
770 |
on:(shownImage colorFromValue:0). |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
771 |
]. |
1071
981c97fe54de
generate device image before clearing in redraw
Claus Gittinger <cg@exept.de>
parents:
677
diff
changeset
|
772 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
773 |
tileMode == true ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
774 |
(tileOffset y > 0 and:[tileOffset x > 0]) ifTrue:[ |
5022 | 775 |
(false "depth ~~ 1" |
776 |
or:[shownImage mask notNil]) ifTrue:[ |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
777 |
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
|
778 |
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
|
779 |
0 to:x+w by:tileOffset x do:[:oX | |
5530 | 780 |
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
|
781 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
782 |
]. |
5022 | 783 |
] ifFalse:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
784 |
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
|
785 |
0 to:x+w by:tileOffset x do:[:oX | |
5530 | 786 |
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
|
787 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
788 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
789 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
790 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
791 |
] ifFalse:[ |
5227 | 792 |
"/rectRight := (shownImage width @ 0) corner:(width @ shownImage height). |
793 |
"/rectBelow := 0 @ (shownImage height) corner:(shownImage height @ height). |
|
794 |
"/(rectRight width > 0 and:[rectRight height > 0]) ifTrue:[ self clearRectangle:rectRight ]. |
|
795 |
"/(rectBelow width > 0 and:[rectBelow height > 0]) ifTrue:[ self clearRectangle:rectBelow ]. |
|
796 |
||
3726 | 797 |
xI > (x+w) ifTrue:[^ self]. "/ no need to draw |
798 |
yI > (y+h) ifTrue:[^ self]. "/ no need to draw |
|
799 |
(xI+imgWidth) < x ifTrue:[^ self]. "/ no need to draw |
|
800 |
(yI+imgHeight) < y ifTrue:[^ self]. "/ no need to draw |
|
801 |
||
5022 | 802 |
(false "depth ~~ 1" |
3726 | 803 |
or:[shownImage mask notNil]) ifTrue:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
804 |
self clearRectangleX:x y:y width:w height:h. |
3726 | 805 |
shownImage displayOn:self x:xI y:yI. |
5226 | 806 |
"/ self displayForm:shownImage x:xI y:yI |
3726 | 807 |
] ifFalse:[ |
5529 | 808 |
"/ hack: currently 32bit+alpha is not supported by Displays. |
809 |
"/ make it a masked d24 iamge and draw that. |
|
5530 | 810 |
(shownImage depth == 32 and:[ shownImage photometric == #rgba ]) ifTrue:[ |
811 |
true "device supportsAlphaChannel" ifTrue:[ |
|
812 |
self clearRectangleX:x y:y width:w height:h. |
|
813 |
gc displayForm:shownImage x:xI y:yI |
|
814 |
] ifFalse:[ |
|
815 |
|d24Image| |
|
816 |
||
817 |
d24Image := Depth24Image fromImage:shownImage. |
|
818 |
d24Image mask:(ImageMask fromAlphaInImage:shownImage). |
|
819 |
self clearRectangleX:x y:y width:w height:h. |
|
820 |
d24Image displayOn:self x:xI y:yI. |
|
821 |
] |
|
5529 | 822 |
] ifFalse:[ |
5530 | 823 |
gc displayOpaqueForm:shownImage x:xI y:yI |
5529 | 824 |
]. |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
825 |
]. |
430 | 826 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
827 |
"/ right of image ? |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
828 |
right := x + w - 1. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
829 |
right > (xI + imgWidth) ifTrue:[ |
5022 | 830 |
self clearRectangleX:(xI + imgWidth) y:y |
5595 | 831 |
width:(right - imgWidth - xI) height:h |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
832 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
833 |
"/ below of image ? |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
834 |
bott := y + h - 1. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
835 |
bott > (yI + imgHeight) ifTrue:[ |
5022 | 836 |
self clearRectangleX:margin y:(yI + imgHeight) |
5595 | 837 |
width:w height:(bott - imgHeight - yI) |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
838 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
839 |
]. |
5268 | 840 |
] ifFalse:[ |
841 |
self clearRectangleX:x y:y width:w height:h. |
|
5529 | 842 |
]. |
89 | 843 |
|
5529 | 844 |
"Created: / 11-07-1996 / 21:02:12 / cg" |
5610 | 845 |
"Modified: / 28-09-2017 / 18:19:01 / cg" |
1 | 846 |
! ! |
847 |
||
2158 | 848 |
!ImageView methodsFor:'event handling'! |
849 |
||
3618 | 850 |
buttonMotion:state x:x y:y |
5503 | 851 |
|delta mousePoint lastPoint| |
3618 | 852 |
|
5503 | 853 |
(lastPoint := lastMousePoint value) notNil ifTrue:[ |
3618 | 854 |
mousePoint := (x@y). |
5503 | 855 |
delta := mousePoint - lastPoint. |
3618 | 856 |
delta ~= (0@0) ifTrue:[ |
857 |
self scrollTo:(self viewOrigin - delta). |
|
5503 | 858 |
lastMousePoint value:mousePoint. |
3618 | 859 |
] |
860 |
] ifFalse:[ |
|
861 |
super buttonMotion:state x:x y:y |
|
862 |
] |
|
5503 | 863 |
|
864 |
"Modified: / 25-02-2017 / 22:34:51 / cg" |
|
3618 | 865 |
! |
866 |
||
867 |
buttonPress:button x:x y:y |
|
868 |
button == 1 ifTrue:[ |
|
4124 | 869 |
"self cursor:(Cursor handGrab). " |
5503 | 870 |
lastMousePoint value:( x@y ). |
3618 | 871 |
]. |
872 |
super buttonPress:button x:x y:y |
|
4124 | 873 |
|
5503 | 874 |
"Modified: / 25-02-2017 / 22:35:12 / cg" |
3618 | 875 |
! |
876 |
||
877 |
buttonRelease:button x:x y:y |
|
878 |
button == 1 ifTrue:[ |
|
5503 | 879 |
lastMousePoint value: nil |
3618 | 880 |
]. |
881 |
super buttonRelease:button x:x y:y |
|
5503 | 882 |
|
883 |
"Modified: / 25-02-2017 / 22:35:20 / cg" |
|
3618 | 884 |
! |
885 |
||
4124 | 886 |
mouseWheelZoom:amount |
887 |
"CTRL-wheel action" |
|
888 |
||
889 |
|mul| |
|
890 |
||
891 |
amount > 0 ifTrue:[ |
|
892 |
mul := 1.2. |
|
893 |
] ifFalse:[ |
|
894 |
mul := 0.8. |
|
895 |
]. |
|
5387 | 896 |
self magnificationFactor:((magnificationFactor ? 1) * mul). |
4124 | 897 |
|
898 |
"Created: / 06-05-2012 / 12:18:06 / cg" |
|
899 |
! |
|
900 |
||
2158 | 901 |
sizeChanged:how |
5597 | 902 |
(#(fit fitBig fitSmall smoothFit smoothFitBig smoothFitSmall) includes:adjust) ifTrue:[ |
2911
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
903 |
magnifiedImage notNil ifTrue:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
904 |
DoNotMagnifyQuery query ifFalse:[ |
5387 | 905 |
self pushEvent:#updateImageAfterSizeChange. |
2911
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 |
]. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
908 |
] ifFalse:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
909 |
adjust == #center ifTrue:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
910 |
self clear. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
911 |
self invalidate. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
912 |
]. |
2158 | 913 |
]. |
914 |
super sizeChanged:how |
|
5597 | 915 |
|
916 |
"Modified: / 10-09-2017 / 17:11:08 / cg" |
|
5387 | 917 |
! |
918 |
||
919 |
updateImageAfterSizeChange |
|
5399 | 920 |
|oldMagnifiedImage| |
921 |
||
922 |
oldMagnifiedImage := magnifiedImage. |
|
5610 | 923 |
smoothMagnifiedImage := magnifiedImage := nil. |
924 |
||
5387 | 925 |
self generateMagnifiedImage. |
5610 | 926 |
|
5400 | 927 |
(oldMagnifiedImage isNil |
928 |
or:[ magnifiedImage isNil |
|
929 |
or:[ oldMagnifiedImage extent ~= magnifiedImage extent ]] |
|
930 |
) ifTrue:[ |
|
931 |
"/ self clear. |
|
5399 | 932 |
self invalidate. |
933 |
]. |
|
5610 | 934 |
|
935 |
"Modified (format): / 28-09-2017 / 18:20:32 / cg" |
|
2158 | 936 |
! ! |
937 |
||
2501 | 938 |
!ImageView methodsFor:'initialization & release'! |
1327 | 939 |
|
940 |
destroy |
|
5610 | 941 |
magnifiedImage := smoothMagnifiedImage := nil. |
5404 | 942 |
"/ image := nil. |
1327 | 943 |
super destroy. |
5610 | 944 |
|
945 |
"Modified: / 28-09-2017 / 18:20:44 / cg" |
|
5503 | 946 |
! |
947 |
||
948 |
initialize |
|
949 |
super initialize. |
|
950 |
||
951 |
lastMousePoint := nil asValue. |
|
952 |
||
953 |
"Created: / 25-02-2017 / 22:33:27 / cg" |
|
1327 | 954 |
! ! |
955 |
||
4245 | 956 |
!ImageView methodsFor:'menu'! |
957 |
||
5482 | 958 |
editImage |
5488 | 959 |
|img| |
960 |
||
961 |
img := self image. |
|
962 |
imageEditAction notNil ifTrue:[ |
|
963 |
imageEditAction value:img |
|
964 |
] ifFalse:[ |
|
965 |
ImageEditor openOnImage:img. |
|
966 |
]. |
|
5482 | 967 |
|
968 |
"Created: / 16-02-2017 / 19:01:41 / cg" |
|
5488 | 969 |
"Modified: / 19-02-2017 / 23:01:14 / cg" |
5482 | 970 |
! |
971 |
||
5599 | 972 |
magnifyBy:scale |
973 |
self adjustHolder value:#Mag. |
|
974 |
self adjust:#topLeft. |
|
975 |
self magnificationFactor:scale. |
|
976 |
||
977 |
"Created: / 13-09-2017 / 09:43:11 / cg" |
|
978 |
! |
|
979 |
||
4245 | 980 |
middleButtonMenu |
4263 | 981 |
menuHolder notNil ifTrue:[^ super middleButtonMenu]. |
4245 | 982 |
^ self class middleButtonMenu |
983 |
! ! |
|
984 |
||
161 | 985 |
!ImageView methodsFor:'queries'! |
24 | 986 |
|
161 | 987 |
heightOfContents |
5387 | 988 |
"return the image's height - scrollbar needs this info" |
1 | 989 |
|
161 | 990 |
image isNil ifTrue:[^ 0]. |
2158 | 991 |
^ (magnifiedImage ? image) height |
89 | 992 |
! |
993 |
||
5482 | 994 |
selfIsNotImageEditor |
995 |
"for the menu; to hide edit item" |
|
996 |
||
997 |
^ self class == ImageView |
|
998 |
||
999 |
"Created: / 16-02-2017 / 19:00:59 / cg" |
|
1000 |
! |
|
1001 |
||
1 | 1002 |
widthOfContents |
5387 | 1003 |
"return the image's width - scrollbar needs this info" |
1 | 1004 |
|
1005 |
image isNil ifTrue:[^ 0]. |
|
2158 | 1006 |
^ (magnifiedImage ? image) width |
161 | 1007 |
! ! |
1008 |
||
3408 | 1009 |
!ImageView methodsFor:'scrolling'! |
1010 |
||
5555 | 1011 |
scrollToMakeRectangleVisible:aRectangle |
1012 |
"try to arrange for aRectangle to be visible (at the center, if possible)" |
|
1013 |
||
1014 |
self scrollToMakeVisible:(aRectangle center). |
|
1015 |
self scrollToMakeVisible:(aRectangle corner). |
|
1016 |
self scrollToMakeVisible:(aRectangle origin). |
|
1017 |
||
1018 |
" |
|
1019 |
|v| |
|
1020 |
v := ImageView new image:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'). |
|
1021 |
v openAndWait. |
|
1022 |
v inspect. |
|
1023 |
v scrollToMakeRectangleVisible:((300@100) corner:(320@120)). |
|
1024 |
" |
|
1025 |
||
1026 |
"Created: / 20-07-2017 / 13:45:29 / cg" |
|
1027 |
! |
|
1028 |
||
3408 | 1029 |
scrollToMakeVisible:aPoint |
5555 | 1030 |
"try to arrange for aPoint (in logical image coordinates) |
1031 |
to be visible (at the center, if possible)" |
|
3408 | 1032 |
|
5555 | 1033 |
|mag magPos newOffset| |
3408 | 1034 |
|
1035 |
mag := self magnification. |
|
5555 | 1036 |
magPos := aPoint * mag. |
1037 |
||
1038 |
((self bounds + self viewOrigin) containsPoint:magPos) ifFalse:[ |
|
1039 |
newOffset := magPos - (self extent / 2). |
|
1040 |
newOffset := newOffset max:(0@0). |
|
1041 |
newOffset := newOffset min:((image extent * mag) - (self extent / 2)). |
|
1042 |
newOffset := newOffset rounded. |
|
5556 | 1043 |
self scrollTo:newOffset waitForDrawingFinished:true. |
5507 | 1044 |
]. |
1045 |
||
1046 |
" |
|
1047 |
|v| |
|
1048 |
v := ImageView new image:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'). |
|
1049 |
v openAndWait. |
|
1050 |
v inspect. |
|
1051 |
v scrollToMakeVisible:(300@100). |
|
1052 |
" |
|
1053 |
||
5556 | 1054 |
"Modified: / 20-07-2017 / 14:37:11 / cg" |
3408 | 1055 |
! ! |
1056 |
||
257 | 1057 |
!ImageView class methodsFor:'documentation'! |
161 | 1058 |
|
1059 |
version |
|
4912 | 1060 |
^ '$Header$' |
3884 | 1061 |
! |
1062 |
||
1063 |
version_CVS |
|
4912 | 1064 |
^ '$Header$' |
1 | 1065 |
! ! |
2358 | 1066 |
|
4192 | 1067 |
|
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
1068 |
ImageView initialize! |