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