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