author | Claus Gittinger <cg@exept.de> |
Thu, 27 Apr 2017 14:09:50 +0200 | |
changeset 5534 | 4806c4eec412 |
parent 5532 | bdc0ef74e9f4 |
child 5555 | ce5b5e4a359b |
permissions | -rw-r--r-- |
5532 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
4 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
24 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
1763
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
14 |
"{ Package: 'stx:libwidg2' }" |
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
15 |
|
4732 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
296 | 18 |
View subclass:#ImageView |
4124 | 19 |
instanceVariableNames:'image magnifiedImage adjust magnificationFactor tileMode |
5488 | 20 |
tileOffset lastMousePoint adjustHolder imageEditAction' |
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 |
5402 | 128 |
choiceValue: fitBig |
4245 | 129 |
) |
130 |
(MenuItem |
|
131 |
label: 'Original Size' |
|
5403 | 132 |
choice: adjustHolder |
133 |
choiceValue: #topLeft |
|
4245 | 134 |
) |
5482 | 135 |
(MenuItem |
136 |
label: '-' |
|
137 |
isVisible: selfIsNotImageEitor |
|
138 |
) |
|
139 |
(MenuItem |
|
140 |
label: 'Edit' |
|
141 |
itemValue: editImage |
|
5532 | 142 |
isVisible: selfIsNotImageEditor |
5482 | 143 |
) |
4245 | 144 |
) |
145 |
nil |
|
146 |
nil |
|
147 |
) |
|
5482 | 148 |
|
149 |
"Modified: / 16-02-2017 / 18:59:23 / cg" |
|
4245 | 150 |
! ! |
151 |
||
2511 | 152 |
!ImageView class methodsFor:'queries-plugin'! |
1694 | 153 |
|
154 |
aspectSelectors |
|
155 |
^ #( imageChannel ) |
|
156 |
||
157 |
"Created: / 11.2.2000 / 00:37:33 / cg" |
|
158 |
! ! |
|
159 |
||
257 | 160 |
!ImageView class methodsFor:'startup'! |
1 | 161 |
|
4192 | 162 |
openOn:anImageOrFileName |
5467 | 163 |
"startup an image viewer on an image or |
164 |
an image read from a file. |
|
165 |
Return the imageView (not the topView)" |
|
4192 | 166 |
|
167 |
anImageOrFileName isImage ifTrue:[ |
|
168 |
^ self openOnImage:anImageOrFileName |
|
169 |
]. |
|
170 |
^ self openOnFile:anImageOrFileName |
|
171 |
||
172 |
" |
|
173 |
ImageView openOn:'bitmaps/gifImages/garfield.gif' |
|
174 |
ImageView openOn:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' |
|
175 |
" |
|
176 |
||
5467 | 177 |
"Modified: / 31-10-1997 / 16:17:52 / cg" |
178 |
"Modified (comment): / 13-02-2017 / 10:13:13 / cg" |
|
4192 | 179 |
! |
180 |
||
181 |
openOnFile:aFileName |
|
5467 | 182 |
"startup an image viewer on an image read from a file. |
183 |
Return the imageView (not the topView)" |
|
47 | 184 |
|
1970 | 185 |
|fn imageView img e| |
186 |
||
187 |
fn := aFileName asFilename. |
|
47 | 188 |
|
1970 | 189 |
img := Image fromFile:fn. |
47 | 190 |
img isNil ifTrue:[ |
2747 | 191 |
fn exists ifTrue:[ |
192 |
e := 'Unknown or unsupported image format.' |
|
193 |
] ifFalse:[ |
|
194 |
e := 'No such image file.'. |
|
195 |
]. |
|
196 |
self warn:(self resources string:e). |
|
197 |
^ nil |
|
47 | 198 |
]. |
353 | 199 |
imageView := self openOnImage:img. |
3733 | 200 |
imageView topView label:(fn pathName) iconLabel:(fn baseName). |
353 | 201 |
^ imageView |
1 | 202 |
|
47 | 203 |
" |
4558 | 204 |
ImageView openOnFile:'../../goodies/bitmaps/gifImages/garfield.gif' |
205 |
ImageView openOnFile:'../../goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' |
|
47 | 206 |
" |
348 | 207 |
|
5467 | 208 |
"Modified: / 31-10-1997 / 16:17:52 / cg" |
209 |
"Modified (comment): / 13-02-2017 / 10:12:53 / cg" |
|
47 | 210 |
! |
211 |
||
212 |
openOnImage:anImage |
|
5467 | 213 |
"startup an image viewer on an image. |
214 |
Return the imageView (not the topView)" |
|
1 | 215 |
|
4558 | 216 |
|lbl| |
47 | 217 |
|
218 |
anImage isImage ifTrue:[ |
|
3733 | 219 |
lbl := anImage fileName ? 'an Image' |
47 | 220 |
] ifFalse:[ |
3904 | 221 |
anImage isNil ifTrue:[ |
222 |
lbl := 'an Image' |
|
223 |
] ifFalse:[ |
|
224 |
lbl := 'a Form' |
|
225 |
] |
|
47 | 226 |
]. |
4558 | 227 |
^ self openOnImage:anImage title:lbl |
228 |
||
229 |
" |
|
230 |
ImageView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif') title:'garfield' |
|
231 |
ImageView openOnImage:(Image fromFile:'../../libtool/bitmaps/SBrowser.xbm') title:'old browser icon' |
|
232 |
" |
|
5467 | 233 |
|
234 |
"Modified (comment): / 13-02-2017 / 10:12:43 / cg" |
|
4558 | 235 |
! |
236 |
||
237 |
openOnImage:anImage title:aString |
|
5467 | 238 |
"startup an image viewer on an image. |
239 |
Return the imageView (not the topView)" |
|
4558 | 240 |
|
241 |
|top v imageView icnW icnH iconView magX magY mag imgWidth imgHeight| |
|
242 |
||
243 |
top := StandardSystemView label:aString. |
|
1 | 244 |
|
245 |
v := HVScrollableView for:self in:top. |
|
5226 | 246 |
v origin:0@0 extent:1.0@1.0. |
1 | 247 |
imageView := v scrolledView. |
248 |
||
47 | 249 |
anImage notNil ifTrue:[ |
3733 | 250 |
imageView image:anImage. |
7 | 251 |
|
3733 | 252 |
"define an icon view showing a little version of image. |
253 |
Since some window managers cannot handle this correctly (twm), |
|
254 |
this is only done when running on an IRIS" |
|
7 | 255 |
|
5226 | 256 |
(true "(OperatingSystem getSystemType = 'iris')" |
3733 | 257 |
and:[StyleSheet name == #iris]) ifTrue:[ |
258 |
iconView := ImageView new. |
|
7 | 259 |
|
3733 | 260 |
"for now; should somehow get access to preferred iconview extent ..." |
261 |
icnW := 86. |
|
262 |
icnH := 68. |
|
7 | 263 |
|
3733 | 264 |
imgWidth := anImage width. |
265 |
imgHeight := anImage height. |
|
635 | 266 |
|
3733 | 267 |
((imgWidth <= icnW) and:[imgHeight <= icnH]) ifTrue:[ |
268 |
iconView extent:(imgWidth @ imgHeight). |
|
269 |
mag := 1 @ 1 |
|
270 |
] ifFalse:[ |
|
271 |
magX := icnW / imgWidth. |
|
272 |
magY := icnH / imgHeight. |
|
7 | 273 |
|
3733 | 274 |
"scale image" |
7 | 275 |
" |
3733 | 276 |
mag := magX @ magY. |
7 | 277 |
" |
3733 | 278 |
"preserve ratio" |
5226 | 279 |
" |
3733 | 280 |
mag := (magX min:magY) asPoint. |
5226 | 281 |
" |
3733 | 282 |
mag := (magX max:magY) asPoint. |
283 |
iconView extent:((anImage width @ anImage height) * mag) rounded. |
|
284 |
]. |
|
7 | 285 |
|
3733 | 286 |
top iconView:iconView. |
287 |
]. |
|
7 | 288 |
]. |
289 |
||
290 |
top open. |
|
291 |
||
26 | 292 |
iconView notNil ifTrue:[ |
3733 | 293 |
top windowGroup addView:iconView. |
5226 | 294 |
[ |
3733 | 295 |
iconView image:(anImage magnifiedBy:mag). |
296 |
] forkAt:4 |
|
7 | 297 |
]. |
353 | 298 |
^ imageView |
1 | 299 |
|
26 | 300 |
" |
4558 | 301 |
ImageView openOnImage:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') title:'garfield' |
302 |
ImageView openOnImage:(Image fromFile:'../../libtool/bitmaps/SBrowser.xbm') |
|
26 | 303 |
" |
353 | 304 |
|
3904 | 305 |
"Modified: / 01-06-2010 / 18:31:14 / cg" |
5467 | 306 |
"Modified (comment): / 13-02-2017 / 10:12:35 / cg" |
1 | 307 |
! ! |
308 |
||
161 | 309 |
!ImageView methodsFor:'accessing'! |
310 |
||
5387 | 311 |
adjust |
312 |
"get the adjust (how the image is displayed); |
|
313 |
currently, only support #topLeft, #center, #fitBig, #fitSmall and #fit: |
|
314 |
#topLeft - image is displayed as usual |
|
315 |
#center - image is shown centered |
|
316 |
#fitBig - big images are shrunk to make it fit the view |
|
317 |
#fitSmall - small images are magnified to make it fit the view, |
|
318 |
#fit - all images are magnified to fit the view |
|
319 |
" |
|
320 |
||
321 |
^ adjust ? #topLeft |
|
322 |
! |
|
323 |
||
161 | 324 |
adjust:layoutSymbol |
325 |
"set the adjust (how the image is displayed); |
|
2375 | 326 |
currently, only support #topLeft, #center, #fitBig, #fitSmall and #fit: |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
327 |
#topLeft - image is displayed as usual |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
328 |
#center - image is shown centered |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
329 |
#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
|
330 |
#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
|
331 |
#fit - all images are magnified to fit the view |
5403 | 332 |
#topLeftNoZoom - image is displayed as usual, and magnification is reset |
2375 | 333 |
" |
2158 | 334 |
|
5403 | 335 |
|layoutUsed| |
336 |
||
337 |
layoutUsed := layoutSymbol. |
|
338 |
layoutUsed == #topLeftNoZoom ifTrue:[ |
|
339 |
layoutUsed := #topLeft |
|
340 |
]. |
|
341 |
self magnificationFactor ~= 1 ifTrue:[ |
|
342 |
self magnificationFactor:1 |
|
343 |
]. |
|
344 |
||
345 |
adjust ~= layoutUsed ifTrue:[ |
|
346 |
adjust := layoutUsed. |
|
5402 | 347 |
adjustHolder notNil ifTrue:[ |
5403 | 348 |
adjustHolder value:layoutUsed withoutNotifying:self |
5402 | 349 |
]. |
161 | 350 |
|
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
351 |
magnifiedImage := nil. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
352 |
shown ifTrue:[ |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
353 |
image notNil ifTrue:[ |
5403 | 354 |
self magnificationFactor ~= 1 ifTrue:[ |
355 |
self generateMagnifiedImage. |
|
356 |
]. |
|
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
357 |
self clear. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
358 |
self scrollToTopLeft. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
359 |
self invalidate. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
360 |
self contentsChanged. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
361 |
] |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
362 |
]. |
2158 | 363 |
]. |
161 | 364 |
! |
365 |
||
5403 | 366 |
adjustHolder |
367 |
"get a valeHolder for the adjust (how the image is displayed); |
|
368 |
currently, only support #topLeft, #center, #fitBig, #fitSmall and #fit: |
|
369 |
#topLeft - image is displayed as usual |
|
370 |
#center - image is shown centered |
|
371 |
#fitBig - big images are shrunk to make it fit the view |
|
372 |
#fitSmall - small images are magnified to make it fit the view, |
|
373 |
#fit - all images are magnified to fit the view |
|
374 |
" |
|
375 |
||
376 |
adjustHolder isNil ifTrue:[ |
|
377 |
adjustHolder := self adjust asValue. |
|
378 |
adjustHolder |
|
379 |
onChangeEvaluate:[ |
|
380 |
self adjust:(adjustHolder value). |
|
381 |
] |
|
382 |
]. |
|
383 |
^ adjustHolder |
|
384 |
! |
|
385 |
||
161 | 386 |
image |
387 |
"return the image" |
|
388 |
||
389 |
^ image |
|
390 |
! |
|
391 |
||
392 |
image:anImage |
|
5398 | 393 |
"set the image scrolls as set by adjust |
394 |
- may show a wait cursor, if image dithering may take a while" |
|
1 | 395 |
|
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
396 |
self image:anImage scroll:true |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
397 |
! |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
398 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
399 |
image:anImage scroll:doScroll |
5398 | 400 |
"set the image possibly scroll as set by adjust |
401 |
- 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
|
402 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
403 |
self setImage:anImage scroll:doScroll |
1993 | 404 |
! |
405 |
||
3705 | 406 |
image:anImage scroll:doScroll invalidate:doInvalidate |
5398 | 407 |
"set the image possibly scroll as set by adjust |
408 |
- may show a wait cursor, if image dithering may take a while" |
|
3705 | 409 |
|
410 |
self setImage:anImage scroll:doScroll invalidate:doInvalidate |
|
411 |
! |
|
412 |
||
5488 | 413 |
imageEditAction:aOneArgBlockOrNil |
414 |
"if nonNil, aOneArgBlockOrNil will be called to open |
|
415 |
the image editor (as by the 'Edit Image' menu action). |
|
5487 | 416 |
If never set, the default ImageEditor is opened." |
417 |
||
5488 | 418 |
imageEditAction := aOneArgBlockOrNil. |
5487 | 419 |
|
5488 | 420 |
"Created: / 19-02-2017 / 22:58:14 / cg" |
5487 | 421 |
! |
422 |
||
3408 | 423 |
magnification |
424 |
magnifiedImage isNil ifTrue:[^ 1@1]. |
|
425 |
^ magnifiedImage extent / image extent |
|
426 |
! |
|
427 |
||
5387 | 428 |
magnificationFactor |
429 |
^ magnificationFactor ? 1 |
|
430 |
! |
|
431 |
||
432 |
magnificationFactor:aNumber |
|
5398 | 433 |
magnificationFactor ~= aNumber ifTrue:[ |
434 |
magnificationFactor := aNumber. |
|
5403 | 435 |
"/ magnificationFactor fractionPart < 0.1 ifTrue:[ |
436 |
"/ "magnifying by integer factor is faster" |
|
437 |
"/ magnificationFactor := magnificationFactor truncated. |
|
438 |
"/ ]. |
|
5398 | 439 |
magnifiedImage := nil. |
440 |
magnificationFactor = 1 ifTrue:[ |
|
441 |
self contentsChanged. |
|
442 |
]. |
|
443 |
self invalidate. |
|
444 |
]. |
|
5387 | 445 |
! |
446 |
||
4066 | 447 |
model:aValueHolder |
448 |
super model:aValueHolder. |
|
449 |
self updateFromModel. |
|
450 |
||
451 |
"Created: / 25-07-2011 / 15:32:10 / cg" |
|
452 |
! |
|
453 |
||
1993 | 454 |
setImage:anImage |
455 |
"set the image - show a wait cursor, since image dithering may take a while" |
|
456 |
||
4966 | 457 |
self setImage:anImage scroll:true invalidate:true |
1694 | 458 |
|
459 |
"Modified: / 10.2.2000 / 23:25:51 / cg" |
|
2089 | 460 |
! |
461 |
||
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
462 |
setImage:anImage scroll:doScroll |
5398 | 463 |
"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
|
464 |
|
3710
162a45c5ce34
invalidate when image changes
Claus Gittinger <cg@exept.de>
parents:
3705
diff
changeset
|
465 |
self setImage:anImage scroll:doScroll invalidate:true |
3705 | 466 |
! |
467 |
||
468 |
setImage:anImage scroll:doScroll invalidate:doInvalidate |
|
5398 | 469 |
"set the image - may show a wait cursor, if image dithering may take a while" |
3705 | 470 |
|
4966 | 471 |
|oldSize newSize newImageIsSmaller| |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
472 |
|
5534 | 473 |
self assert:(anImage isImage or:[anImage isForm or:[anImage isNil]]). |
5430 | 474 |
|
5226 | 475 |
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
|
476 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
477 |
image := anImage. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
478 |
magnifiedImage := nil. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
479 |
self generateMagnifiedImage. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
480 |
|
5226 | 481 |
newSize := image isNil ifTrue:[0@0] ifFalse:[(magnifiedImage ? image) extent]. |
4966 | 482 |
newImageIsSmaller := ((oldSize x > newSize x) or:[oldSize y > newSize y]). |
5226 | 483 |
|
5227 | 484 |
(newImageIsSmaller and:[ doInvalidate ]) ifTrue:[ self invalidate ]. |
485 |
doScroll ifTrue:[ self scrollToTopLeft ]. |
|
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
486 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
487 |
oldSize ~= newSize ifTrue:[ |
3705 | 488 |
"/ avoid endless loop in case of a resize happening due |
489 |
"/ to scrollBar visibility changes. |
|
5226 | 490 |
"/ that QuerySignal suppresses another magnification in sizeChanged: |
491 |
DoNotMagnifyQuery |
|
4966 | 492 |
answer:true |
493 |
do:[ |
|
494 |
self contentsChanged. |
|
495 |
] |
|
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
496 |
]. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
497 |
|
3705 | 498 |
(shown and:[doInvalidate]) ifTrue:[ |
5268 | 499 |
"/ (anImage isNil "or:[newImageIsSmaller]") ifTrue:[ |
500 |
"/ self clear. |
|
501 |
"/ ]. |
|
3705 | 502 |
self invalidate |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
503 |
]. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
504 |
self changed:#image. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
505 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
506 |
"Modified: / 10.2.2000 / 23:25:51 / cg" |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
507 |
! |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
508 |
|
4245 | 509 |
sizeToFit:aBoolean |
510 |
aBoolean ifTrue:[ |
|
511 |
self adjust:#fitBig |
|
512 |
] ifFalse:[ |
|
513 |
self adjust:nil. |
|
514 |
] |
|
515 |
! |
|
516 |
||
2089 | 517 |
tileMode:aBoolean tileOffset:aPoint |
518 |
||
519 |
tileMode := aBoolean. |
|
520 |
tileOffset := aPoint |
|
1694 | 521 |
! ! |
522 |
||
2404 | 523 |
!ImageView methodsFor:'accessing-channels'! |
1510
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
524 |
|
1694 | 525 |
imageChannel |
4031 | 526 |
^ self model |
1694 | 527 |
|
4031 | 528 |
"Modified: / 31-03-2011 / 10:45:58 / cg" |
1694 | 529 |
! |
530 |
||
531 |
imageChannel:aValueHolder |
|
4031 | 532 |
self model:aValueHolder. |
1694 | 533 |
|
4031 | 534 |
"Created: / 11-02-2000 / 00:34:33 / cg" |
535 |
"Modified: / 31-03-2011 / 10:46:07 / cg" |
|
5503 | 536 |
! |
537 |
||
538 |
mousePointHolder |
|
539 |
^ lastMousePoint |
|
540 |
||
541 |
"Created: / 25-02-2017 / 22:36:02 / cg" |
|
1694 | 542 |
! ! |
1135
75101bf02c5b
send contentsChanged notifications before, to avoid
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
543 |
|
1694 | 544 |
!ImageView methodsFor:'change & update'! |
545 |
||
546 |
update:something with:aParameter from:changedObject |
|
4031 | 547 |
changedObject == model ifTrue:[ |
4561 | 548 |
self updateFromModel. |
2786
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
549 |
^ self |
1694 | 550 |
]. |
551 |
super update:something with:aParameter from:changedObject |
|
552 |
||
4031 | 553 |
"Created: / 11-02-2000 / 00:37:02 / cg" |
554 |
"Modified: / 31-03-2011 / 10:46:16 / cg" |
|
2786
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
555 |
! |
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
556 |
|
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
557 |
updateFromModel |
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
558 |
"the model changes, set my image" |
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
559 |
|
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
560 |
self image:model value. |
1 | 561 |
! ! |
562 |
||
563 |
!ImageView methodsFor:'drawing'! |
|
564 |
||
2158 | 565 |
generateMagnifiedImage |
566 |
|doFit innerWidth innerHeight imgWidth imgHeight| |
|
567 |
||
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
568 |
magnifiedImage notNil ifTrue:[ |
4124 | 569 |
^ self |
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
570 |
]. |
2358 | 571 |
image isNil ifTrue:[ |
4124 | 572 |
^ self |
2358 | 573 |
]. |
2158 | 574 |
doFit := false. |
575 |
||
576 |
innerWidth := self innerWidth. |
|
577 |
innerHeight := self innerHeight. |
|
578 |
||
579 |
imgWidth := image width. |
|
580 |
imgHeight := image height. |
|
5430 | 581 |
|
2158 | 582 |
tileMode ~~ true ifTrue:[ |
4124 | 583 |
((imgWidth > innerWidth) |
584 |
or:[imgHeight > innerHeight]) ifTrue:[ |
|
585 |
((adjust == #fit) or:[adjust == #fitBig]) ifTrue:[ |
|
586 |
doFit := true |
|
587 |
]. |
|
588 |
] ifFalse:[ |
|
589 |
((imgWidth < innerWidth) |
|
590 |
or:[imgHeight < innerHeight]) ifTrue:[ |
|
591 |
((adjust == #fit) or:[adjust == #fitSmall]) ifTrue:[ |
|
592 |
doFit := true |
|
593 |
]. |
|
594 |
] |
|
595 |
]. |
|
2158 | 596 |
]. |
597 |
doFit ifTrue:[ |
|
4124 | 598 |
magnifiedImage := image magnifiedPreservingRatioTo:(innerWidth @ innerHeight). |
5479 | 599 |
magnificationFactor := magnifiedImage width / imgWidth. |
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
600 |
"/ self contentsChanged. |
2164 | 601 |
] ifFalse:[ |
4124 | 602 |
(magnificationFactor notNil and:[magnificationFactor ~= 1]) ifTrue:[ |
603 |
magnifiedImage := image magnifiedBy:magnificationFactor. |
|
604 |
] ifFalse:[ |
|
605 |
magnifiedImage := image |
|
606 |
]. |
|
2158 | 607 |
]. |
5387 | 608 |
self contentsChanged. |
4124 | 609 |
|
5479 | 610 |
"Modified: / 16-02-2017 / 01:27:05 / cg" |
2158 | 611 |
! |
612 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
613 |
redrawX:x y:y width:w height:h |
5227 | 614 |
|xI yI depth shownImage imgWidth imgHeight right bott "rectRight rectBelow"| |
11 | 615 |
|
1 | 616 |
image notNil ifTrue:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
617 |
self generateMagnifiedImage. |
2158 | 618 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
619 |
shownImage := magnifiedImage ? image. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
620 |
imgWidth := shownImage width. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
621 |
imgHeight := shownImage height. |
635 | 622 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
623 |
adjust == #center ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
624 |
xI := (width - (margin * 2) - imgWidth) // 2. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
625 |
yI := (height - (margin * 2) - imgHeight) // 2. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
626 |
] ifFalse:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
627 |
xI := yI := margin |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
628 |
]. |
414 | 629 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
630 |
((depth := shownImage depth) == 1) ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
631 |
self paint:(shownImage colorFromValue:1) |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
632 |
on:(shownImage colorFromValue:0). |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
633 |
]. |
1071
981c97fe54de
generate device image before clearing in redraw
Claus Gittinger <cg@exept.de>
parents:
677
diff
changeset
|
634 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
635 |
tileMode == true ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
636 |
(tileOffset y > 0 and:[tileOffset x > 0]) ifTrue:[ |
5022 | 637 |
(false "depth ~~ 1" |
638 |
or:[shownImage mask notNil]) ifTrue:[ |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
639 |
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
|
640 |
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
|
641 |
0 to:x+w by:tileOffset x do:[:oX | |
5530 | 642 |
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
|
643 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
644 |
]. |
5022 | 645 |
] ifFalse:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
646 |
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
|
647 |
0 to:x+w by:tileOffset x do:[:oX | |
5530 | 648 |
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
|
649 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
650 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
651 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
652 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
653 |
] ifFalse:[ |
5227 | 654 |
"/rectRight := (shownImage width @ 0) corner:(width @ shownImage height). |
655 |
"/rectBelow := 0 @ (shownImage height) corner:(shownImage height @ height). |
|
656 |
"/(rectRight width > 0 and:[rectRight height > 0]) ifTrue:[ self clearRectangle:rectRight ]. |
|
657 |
"/(rectBelow width > 0 and:[rectBelow height > 0]) ifTrue:[ self clearRectangle:rectBelow ]. |
|
658 |
||
3726 | 659 |
xI > (x+w) ifTrue:[^ self]. "/ no need to draw |
660 |
yI > (y+h) ifTrue:[^ self]. "/ no need to draw |
|
661 |
(xI+imgWidth) < x ifTrue:[^ self]. "/ no need to draw |
|
662 |
(yI+imgHeight) < y ifTrue:[^ self]. "/ no need to draw |
|
663 |
||
5022 | 664 |
(false "depth ~~ 1" |
3726 | 665 |
or:[shownImage mask notNil]) ifTrue:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
666 |
self clearRectangleX:x y:y width:w height:h. |
3726 | 667 |
shownImage displayOn:self x:xI y:yI. |
5226 | 668 |
"/ self displayForm:shownImage x:xI y:yI |
3726 | 669 |
] ifFalse:[ |
5529 | 670 |
"/ hack: currently 32bit+alpha is not supported by Displays. |
671 |
"/ make it a masked d24 iamge and draw that. |
|
5530 | 672 |
(shownImage depth == 32 and:[ shownImage photometric == #rgba ]) ifTrue:[ |
673 |
true "device supportsAlphaChannel" ifTrue:[ |
|
674 |
self clearRectangleX:x y:y width:w height:h. |
|
675 |
gc displayForm:shownImage x:xI y:yI |
|
676 |
] ifFalse:[ |
|
677 |
|d24Image| |
|
678 |
||
679 |
d24Image := Depth24Image fromImage:shownImage. |
|
680 |
d24Image mask:(ImageMask fromAlphaInImage:shownImage). |
|
681 |
self clearRectangleX:x y:y width:w height:h. |
|
682 |
d24Image displayOn:self x:xI y:yI. |
|
683 |
] |
|
5529 | 684 |
] ifFalse:[ |
5530 | 685 |
gc displayOpaqueForm:shownImage x:xI y:yI |
5529 | 686 |
]. |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
687 |
]. |
430 | 688 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
689 |
"/ right of image ? |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
690 |
right := x + w - 1. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
691 |
right > (xI + imgWidth) ifTrue:[ |
5022 | 692 |
self clearRectangleX:(xI + imgWidth) y:y |
5226 | 693 |
width:(right - imgWidth - xI) height:h |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
694 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
695 |
"/ below of image ? |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
696 |
bott := y + h - 1. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
697 |
bott > (yI + imgHeight) ifTrue:[ |
5022 | 698 |
self clearRectangleX:margin y:(yI + imgHeight) |
5226 | 699 |
width:w height:(bott - imgHeight - yI) |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
700 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
701 |
]. |
5268 | 702 |
] ifFalse:[ |
703 |
self clearRectangleX:x y:y width:w height:h. |
|
5529 | 704 |
]. |
89 | 705 |
|
5529 | 706 |
"Created: / 11-07-1996 / 21:02:12 / cg" |
5530 | 707 |
"Modified: / 11-04-2017 / 21:05:13 / cg" |
1 | 708 |
! ! |
709 |
||
2158 | 710 |
!ImageView methodsFor:'event handling'! |
711 |
||
3618 | 712 |
buttonMotion:state x:x y:y |
5503 | 713 |
|delta mousePoint lastPoint| |
3618 | 714 |
|
5503 | 715 |
(lastPoint := lastMousePoint value) notNil ifTrue:[ |
3618 | 716 |
mousePoint := (x@y). |
5503 | 717 |
delta := mousePoint - lastPoint. |
3618 | 718 |
delta ~= (0@0) ifTrue:[ |
719 |
self scrollTo:(self viewOrigin - delta). |
|
5503 | 720 |
lastMousePoint value:mousePoint. |
3618 | 721 |
] |
722 |
] ifFalse:[ |
|
723 |
super buttonMotion:state x:x y:y |
|
724 |
] |
|
5503 | 725 |
|
726 |
"Modified: / 25-02-2017 / 22:34:51 / cg" |
|
3618 | 727 |
! |
728 |
||
729 |
buttonPress:button x:x y:y |
|
730 |
button == 1 ifTrue:[ |
|
4124 | 731 |
"self cursor:(Cursor handGrab). " |
5503 | 732 |
lastMousePoint value:( x@y ). |
3618 | 733 |
]. |
734 |
super buttonPress:button x:x y:y |
|
4124 | 735 |
|
5503 | 736 |
"Modified: / 25-02-2017 / 22:35:12 / cg" |
3618 | 737 |
! |
738 |
||
739 |
buttonRelease:button x:x y:y |
|
740 |
button == 1 ifTrue:[ |
|
5503 | 741 |
lastMousePoint value: nil |
3618 | 742 |
]. |
743 |
super buttonRelease:button x:x y:y |
|
5503 | 744 |
|
745 |
"Modified: / 25-02-2017 / 22:35:20 / cg" |
|
3618 | 746 |
! |
747 |
||
4124 | 748 |
mouseWheelZoom:amount |
749 |
"CTRL-wheel action" |
|
750 |
||
751 |
|mul| |
|
752 |
||
753 |
amount > 0 ifTrue:[ |
|
754 |
mul := 1.2. |
|
755 |
] ifFalse:[ |
|
756 |
mul := 0.8. |
|
757 |
]. |
|
5387 | 758 |
self magnificationFactor:((magnificationFactor ? 1) * mul). |
4124 | 759 |
|
760 |
"Created: / 06-05-2012 / 12:18:06 / cg" |
|
761 |
! |
|
762 |
||
2158 | 763 |
sizeChanged:how |
2911
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
764 |
(#(fit fitBig fitSmall) includes:adjust) ifTrue:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
765 |
magnifiedImage notNil ifTrue:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
766 |
DoNotMagnifyQuery query ifFalse:[ |
5387 | 767 |
self pushEvent:#updateImageAfterSizeChange. |
2911
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
768 |
] |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
769 |
]. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
770 |
] ifFalse:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
771 |
adjust == #center ifTrue:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
772 |
self clear. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
773 |
self invalidate. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
774 |
]. |
2158 | 775 |
]. |
776 |
super sizeChanged:how |
|
5387 | 777 |
! |
778 |
||
779 |
updateImageAfterSizeChange |
|
5399 | 780 |
|oldMagnifiedImage| |
781 |
||
782 |
oldMagnifiedImage := magnifiedImage. |
|
5387 | 783 |
magnifiedImage := nil. |
784 |
self generateMagnifiedImage. |
|
5400 | 785 |
(oldMagnifiedImage isNil |
786 |
or:[ magnifiedImage isNil |
|
787 |
or:[ oldMagnifiedImage extent ~= magnifiedImage extent ]] |
|
788 |
) ifTrue:[ |
|
789 |
"/ self clear. |
|
5399 | 790 |
self invalidate. |
791 |
]. |
|
2158 | 792 |
! ! |
793 |
||
2501 | 794 |
!ImageView methodsFor:'initialization & release'! |
1327 | 795 |
|
796 |
destroy |
|
5404 | 797 |
magnifiedImage := nil. |
798 |
"/ image := nil. |
|
1327 | 799 |
super destroy. |
5503 | 800 |
! |
801 |
||
802 |
initialize |
|
803 |
super initialize. |
|
804 |
||
805 |
lastMousePoint := nil asValue. |
|
806 |
||
807 |
"Created: / 25-02-2017 / 22:33:27 / cg" |
|
1327 | 808 |
! ! |
809 |
||
4245 | 810 |
!ImageView methodsFor:'menu'! |
811 |
||
5482 | 812 |
editImage |
5488 | 813 |
|img| |
814 |
||
815 |
img := self image. |
|
816 |
imageEditAction notNil ifTrue:[ |
|
817 |
imageEditAction value:img |
|
818 |
] ifFalse:[ |
|
819 |
ImageEditor openOnImage:img. |
|
820 |
]. |
|
5482 | 821 |
|
822 |
"Created: / 16-02-2017 / 19:01:41 / cg" |
|
5488 | 823 |
"Modified: / 19-02-2017 / 23:01:14 / cg" |
5482 | 824 |
! |
825 |
||
4245 | 826 |
middleButtonMenu |
4263 | 827 |
menuHolder notNil ifTrue:[^ super middleButtonMenu]. |
4245 | 828 |
^ self class middleButtonMenu |
829 |
! ! |
|
830 |
||
161 | 831 |
!ImageView methodsFor:'queries'! |
24 | 832 |
|
161 | 833 |
heightOfContents |
5387 | 834 |
"return the image's height - scrollbar needs this info" |
1 | 835 |
|
161 | 836 |
image isNil ifTrue:[^ 0]. |
2158 | 837 |
^ (magnifiedImage ? image) height |
89 | 838 |
! |
839 |
||
5482 | 840 |
selfIsNotImageEditor |
841 |
"for the menu; to hide edit item" |
|
842 |
||
843 |
^ self class == ImageView |
|
844 |
||
845 |
"Created: / 16-02-2017 / 19:00:59 / cg" |
|
846 |
! |
|
847 |
||
1 | 848 |
widthOfContents |
5387 | 849 |
"return the image's width - scrollbar needs this info" |
1 | 850 |
|
851 |
image isNil ifTrue:[^ 0]. |
|
2158 | 852 |
^ (magnifiedImage ? image) width |
161 | 853 |
! ! |
854 |
||
3408 | 855 |
!ImageView methodsFor:'scrolling'! |
856 |
||
857 |
scrollToMakeVisible:aPoint |
|
858 |
"try to arrange for aPoint to be visible (at the center, if possible)" |
|
859 |
||
860 |
|mag pos| |
|
861 |
||
862 |
mag := self magnification. |
|
863 |
pos := aPoint * mag. |
|
5507 | 864 |
(self bounds containsPoint:aPoint) ifFalse:[ |
865 |
pos := (pos min:(image extent - self extent)) max:0@0. |
|
866 |
self scrollTo:(pos - (self extent / 2)) rounded. |
|
867 |
]. |
|
868 |
||
869 |
" |
|
870 |
|v| |
|
871 |
v := ImageView new image:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'). |
|
872 |
v openAndWait. |
|
873 |
v inspect. |
|
874 |
v scrollToMakeVisible:(300@100). |
|
875 |
" |
|
876 |
||
877 |
"Modified: / 27-02-2017 / 16:05:49 / cg" |
|
878 |
"Modified (comment): / 27-02-2017 / 23:41:45 / cg" |
|
3408 | 879 |
! ! |
880 |
||
257 | 881 |
!ImageView class methodsFor:'documentation'! |
161 | 882 |
|
883 |
version |
|
4912 | 884 |
^ '$Header$' |
3884 | 885 |
! |
886 |
||
887 |
version_CVS |
|
4912 | 888 |
^ '$Header$' |
1 | 889 |
! ! |
2358 | 890 |
|
4192 | 891 |
|
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
892 |
ImageView initialize! |