author | Claus Gittinger <cg@exept.de> |
Thu, 10 Jan 2019 19:20:23 +0100 | |
changeset 5986 | 328725b4e760 |
parent 5881 | 34608d309383 |
child 6030 | 9e4e79cbc322 |
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. |
|
5783 | 458 |
adjustHolder addDependent:self. |
5403 | 459 |
]. |
460 |
^ adjustHolder |
|
5597 | 461 |
|
462 |
"Modified (comment): / 10-09-2017 / 17:06:23 / cg" |
|
5783 | 463 |
"Modified: / 02-06-2018 / 07:31:26 / Claus Gittinger" |
5403 | 464 |
! |
465 |
||
5610 | 466 |
forceSmoothing |
467 |
^ self forceSmoothingHolder value |
|
468 |
||
469 |
"Created: / 28-09-2017 / 17:52:38 / cg" |
|
470 |
! |
|
471 |
||
472 |
forceSmoothing:aBoolean |
|
5611 | 473 |
self forceSmoothingHolder value:aBoolean. |
5610 | 474 |
|
475 |
"Created: / 28-09-2017 / 17:52:30 / cg" |
|
5611 | 476 |
"Modified: / 29-09-2017 / 10:30:32 / cg" |
5610 | 477 |
! |
478 |
||
479 |
forceSmoothingHolder |
|
480 |
forceSmoothingHolder isNil ifTrue:[ |
|
5611 | 481 |
forceSmoothingHolder := false asValue. |
482 |
forceSmoothingHolder |
|
483 |
onChangeEvaluate:[ |
|
484 |
smoothMagnifiedImage := nil. |
|
485 |
self invalidate. |
|
486 |
]. |
|
5610 | 487 |
]. |
488 |
^ forceSmoothingHolder |
|
489 |
||
490 |
"Created: / 28-09-2017 / 17:55:51 / cg" |
|
5611 | 491 |
"Modified: / 29-09-2017 / 10:30:57 / cg" |
5610 | 492 |
! |
493 |
||
161 | 494 |
image |
495 |
"return the image" |
|
496 |
||
497 |
^ image |
|
498 |
! |
|
499 |
||
500 |
image:anImage |
|
5398 | 501 |
"set the image scrolls as set by adjust |
502 |
- may show a wait cursor, if image dithering may take a while" |
|
1 | 503 |
|
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
504 |
self image:anImage scroll:true |
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 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
507 |
image:anImage scroll:doScroll |
5398 | 508 |
"set the image possibly scroll as set by adjust |
509 |
- 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
|
510 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
511 |
self setImage:anImage scroll:doScroll |
1993 | 512 |
! |
513 |
||
3705 | 514 |
image:anImage scroll:doScroll invalidate:doInvalidate |
5398 | 515 |
"set the image possibly scroll as set by adjust |
516 |
- may show a wait cursor, if image dithering may take a while" |
|
3705 | 517 |
|
518 |
self setImage:anImage scroll:doScroll invalidate:doInvalidate |
|
519 |
! |
|
520 |
||
5488 | 521 |
imageEditAction:aOneArgBlockOrNil |
522 |
"if nonNil, aOneArgBlockOrNil will be called to open |
|
523 |
the image editor (as by the 'Edit Image' menu action). |
|
5487 | 524 |
If never set, the default ImageEditor is opened." |
525 |
||
5488 | 526 |
imageEditAction := aOneArgBlockOrNil. |
5487 | 527 |
|
5488 | 528 |
"Created: / 19-02-2017 / 22:58:14 / cg" |
5487 | 529 |
! |
530 |
||
3408 | 531 |
magnification |
532 |
magnifiedImage isNil ifTrue:[^ 1@1]. |
|
533 |
^ magnifiedImage extent / image extent |
|
534 |
! |
|
535 |
||
5387 | 536 |
magnificationFactor |
537 |
^ magnificationFactor ? 1 |
|
538 |
! |
|
539 |
||
540 |
magnificationFactor:aNumber |
|
5614 | 541 |
true "explicitMagnificationFactor ~= aNumber" ifTrue:[ |
5596 | 542 |
magnificationFactor := explicitMagnificationFactor := aNumber. |
5403 | 543 |
"/ magnificationFactor fractionPart < 0.1 ifTrue:[ |
544 |
"/ "magnifying by integer factor is faster" |
|
545 |
"/ magnificationFactor := magnificationFactor truncated. |
|
546 |
"/ ]. |
|
5614 | 547 |
self synchronized:[ |
548 |
smoothingProcess notNil ifTrue:[ |
|
549 |
smoothingProcess terminate. |
|
550 |
smoothMagnifiedImage := nil. |
|
551 |
]. |
|
552 |
]. |
|
5610 | 553 |
magnifiedImage := smoothMagnifiedImage := nil. |
5398 | 554 |
magnificationFactor = 1 ifTrue:[ |
555 |
self contentsChanged. |
|
5777 | 556 |
]. |
5780 | 557 |
(self adjust includesString:'fit' caseSensitive:false) ifTrue:[ |
5777 | 558 |
adjust := #topLeft. |
559 |
]. |
|
5398 | 560 |
self invalidate. |
561 |
]. |
|
5596 | 562 |
|
563 |
"Modified: / 06-09-2017 / 12:51:28 / Maren" |
|
5614 | 564 |
"Modified: / 04-10-2017 / 16:40:00 / cg" |
5777 | 565 |
"Modified: / 28-05-2018 / 14:11:50 / Claus Gittinger" |
5387 | 566 |
! |
567 |
||
4066 | 568 |
model:aValueHolder |
569 |
super model:aValueHolder. |
|
570 |
self updateFromModel. |
|
571 |
||
572 |
"Created: / 25-07-2011 / 15:32:10 / cg" |
|
573 |
! |
|
574 |
||
1993 | 575 |
setImage:anImage |
576 |
"set the image - show a wait cursor, since image dithering may take a while" |
|
577 |
||
4966 | 578 |
self setImage:anImage scroll:true invalidate:true |
1694 | 579 |
|
580 |
"Modified: / 10.2.2000 / 23:25:51 / cg" |
|
2089 | 581 |
! |
582 |
||
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
583 |
setImage:anImage scroll:doScroll |
5398 | 584 |
"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
|
585 |
|
3710
162a45c5ce34
invalidate when image changes
Claus Gittinger <cg@exept.de>
parents:
3705
diff
changeset
|
586 |
self setImage:anImage scroll:doScroll invalidate:true |
3705 | 587 |
! |
588 |
||
589 |
setImage:anImage scroll:doScroll invalidate:doInvalidate |
|
5398 | 590 |
"set the image - may show a wait cursor, if image dithering may take a while" |
3705 | 591 |
|
4966 | 592 |
|oldSize newSize newImageIsSmaller| |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
593 |
|
5688 | 594 |
self assert:(anImage isImageOrForm or:[anImage isNil]). |
5430 | 595 |
|
5226 | 596 |
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
|
597 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
598 |
image := anImage. |
5610 | 599 |
magnifiedImage := smoothMagnifiedImage := nil. |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
600 |
self generateMagnifiedImage. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
601 |
|
5226 | 602 |
newSize := image isNil ifTrue:[0@0] ifFalse:[(magnifiedImage ? image) extent]. |
4966 | 603 |
newImageIsSmaller := ((oldSize x > newSize x) or:[oldSize y > newSize y]). |
5226 | 604 |
|
5227 | 605 |
(newImageIsSmaller and:[ doInvalidate ]) ifTrue:[ self invalidate ]. |
606 |
doScroll ifTrue:[ self scrollToTopLeft ]. |
|
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
607 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
608 |
oldSize ~= newSize ifTrue:[ |
3705 | 609 |
"/ avoid endless loop in case of a resize happening due |
610 |
"/ to scrollBar visibility changes. |
|
5226 | 611 |
"/ that QuerySignal suppresses another magnification in sizeChanged: |
5688 | 612 |
DoNotMagnifyQuery answer:true do:[ self contentsChanged ] |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
613 |
]. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
614 |
|
3705 | 615 |
(shown and:[doInvalidate]) ifTrue:[ |
5268 | 616 |
"/ (anImage isNil "or:[newImageIsSmaller]") ifTrue:[ |
617 |
"/ self clear. |
|
618 |
"/ ]. |
|
3705 | 619 |
self invalidate |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
620 |
]. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
621 |
self changed:#image. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
622 |
|
5610 | 623 |
"Modified: / 28-09-2017 / 18:21:07 / cg" |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
624 |
! |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
625 |
|
4245 | 626 |
sizeToFit:aBoolean |
627 |
aBoolean ifTrue:[ |
|
628 |
self adjust:#fitBig |
|
629 |
] ifFalse:[ |
|
5597 | 630 |
explicitMagnificationFactor := magnificationFactor := 1. |
4245 | 631 |
self adjust:nil. |
632 |
] |
|
5597 | 633 |
|
634 |
"Modified: / 10-09-2017 / 17:54:49 / cg" |
|
4245 | 635 |
! |
636 |
||
2089 | 637 |
tileMode:aBoolean tileOffset:aPoint |
638 |
||
639 |
tileMode := aBoolean. |
|
640 |
tileOffset := aPoint |
|
1694 | 641 |
! ! |
642 |
||
2404 | 643 |
!ImageView methodsFor:'accessing-channels'! |
1510
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
644 |
|
1694 | 645 |
imageChannel |
4031 | 646 |
^ self model |
1694 | 647 |
|
4031 | 648 |
"Modified: / 31-03-2011 / 10:45:58 / cg" |
1694 | 649 |
! |
650 |
||
651 |
imageChannel:aValueHolder |
|
4031 | 652 |
self model:aValueHolder. |
1694 | 653 |
|
4031 | 654 |
"Created: / 11-02-2000 / 00:34:33 / cg" |
655 |
"Modified: / 31-03-2011 / 10:46:07 / cg" |
|
5503 | 656 |
! |
657 |
||
658 |
mousePointHolder |
|
659 |
^ lastMousePoint |
|
660 |
||
661 |
"Created: / 25-02-2017 / 22:36:02 / cg" |
|
1694 | 662 |
! ! |
1135
75101bf02c5b
send contentsChanged notifications before, to avoid
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
663 |
|
1694 | 664 |
!ImageView methodsFor:'change & update'! |
665 |
||
666 |
update:something with:aParameter from:changedObject |
|
5783 | 667 |
changedObject == adjustHolder ifTrue:[ |
668 |
self adjust:(adjustHolder value). |
|
669 |
^ self |
|
670 |
]. |
|
671 |
||
4031 | 672 |
changedObject == model ifTrue:[ |
4561 | 673 |
self updateFromModel. |
2786
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
674 |
^ self |
1694 | 675 |
]. |
676 |
super update:something with:aParameter from:changedObject |
|
677 |
||
4031 | 678 |
"Created: / 11-02-2000 / 00:37:02 / cg" |
679 |
"Modified: / 31-03-2011 / 10:46:16 / cg" |
|
5783 | 680 |
"Modified: / 02-06-2018 / 07:31:13 / Claus Gittinger" |
2786
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 |
|
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
683 |
updateFromModel |
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
684 |
"the model changes, set my image" |
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
685 |
|
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
686 |
self image:model value. |
1 | 687 |
! ! |
688 |
||
689 |
!ImageView methodsFor:'drawing'! |
|
690 |
||
2158 | 691 |
generateMagnifiedImage |
5597 | 692 |
|adj smooth doFit innerWidth innerHeight imgWidth imgHeight| |
2158 | 693 |
|
5741 | 694 |
image isNil ifTrue:[^ self]. |
695 |
smoothMagnifiedImage notNil ifTrue:[^ self]. |
|
5610 | 696 |
|
5597 | 697 |
adj := adjust. |
698 |
smooth := false. |
|
699 |
(adjust notNil and:[adjust startsWith:#smooth]) ifTrue:[ |
|
700 |
adj := (adjust copyFrom:'smooth' size+1) asLowercaseFirst asSymbol. |
|
701 |
smooth := true. |
|
702 |
]. |
|
5610 | 703 |
self forceSmoothing ifTrue:[smooth := true]. |
704 |
||
705 |
magnifiedImage isNil ifTrue:[ |
|
706 |
doFit := false. |
|
707 |
||
708 |
innerWidth := self innerWidth. |
|
709 |
innerHeight := self innerHeight. |
|
5596 | 710 |
|
5610 | 711 |
imgWidth := image width. |
712 |
imgHeight := image height. |
|
713 |
||
5778 | 714 |
(#(fit fitBig fitSmall) includes:adj) ifTrue:[ |
5610 | 715 |
magnificationFactor := explicitMagnificationFactor. |
716 |
]. |
|
717 |
||
718 |
tileMode ~~ true ifTrue:[ |
|
719 |
((imgWidth > innerWidth) |
|
720 |
or:[imgHeight > innerHeight]) ifTrue:[ |
|
721 |
((adj == #fit) or:[adj == #fitBig]) ifTrue:[ |
|
4124 | 722 |
doFit := true |
723 |
]. |
|
5610 | 724 |
] ifFalse:[ |
725 |
((imgWidth < innerWidth) |
|
726 |
or:[imgHeight < innerHeight]) ifTrue:[ |
|
727 |
((adj == #fit) or:[adj == #fitSmall]) ifTrue:[ |
|
728 |
doFit := true |
|
729 |
]. |
|
730 |
] |
|
731 |
]. |
|
4124 | 732 |
]. |
5610 | 733 |
|
734 |
doFit ifTrue:[ |
|
735 |
magnifiedImage := image magnifiedPreservingRatioTo:(innerWidth @ innerHeight) smooth:false "smooth". |
|
736 |
magnificationFactor := magnifiedImage width / imgWidth. |
|
737 |
] ifFalse:[ |
|
738 |
(magnificationFactor notNil and:[magnificationFactor ~= 1]) ifTrue:[ |
|
739 |
magnifiedImage := image magnifiedBy:magnificationFactor smooth:false "smooth". |
|
740 |
] ifFalse:[ |
|
741 |
magnifiedImage := image. |
|
742 |
]. |
|
743 |
]. |
|
744 |
||
745 |
(magnifiedImage width == 0 or:[magnifiedImage height == 0]) ifTrue:[ |
|
746 |
magnifiedImage := nil. |
|
747 |
]. |
|
748 |
||
749 |
smooth ifTrue:[ |
|
750 |
smoothMagnifiedImage := nil. |
|
751 |
] ifFalse:[ |
|
752 |
smoothMagnifiedImage := magnifiedImage. |
|
753 |
]. |
|
754 |
||
755 |
self contentsChanged. |
|
2158 | 756 |
]. |
5597 | 757 |
|
5881 | 758 |
(smooth and:[magnifiedImage notNil]) ifTrue:[ |
5610 | 759 |
magnifiedImage extent = image extent ifTrue:[ |
760 |
smoothMagnifiedImage := magnifiedImage |
|
761 |
] ifFalse:[ |
|
762 |
smoothMagnifiedImage := nil. |
|
763 |
||
764 |
self synchronized:[ |
|
765 |
smoothingProcess notNil ifTrue:[ |
|
766 |
smoothingProcess terminate. |
|
767 |
smoothMagnifiedImage := nil. |
|
768 |
]. |
|
769 |
smoothingProcess := |
|
770 |
[ |
|
5615 | 771 |
|i| |
772 |
||
773 |
(i := magnifiedImage) notNil ifTrue:[ |
|
774 |
smoothMagnifiedImage := image magnifiedTo:(i extent) smooth:true. |
|
775 |
self invalidate. |
|
776 |
] |
|
5610 | 777 |
] fork. |
778 |
]. |
|
779 |
]. |
|
2158 | 780 |
]. |
4124 | 781 |
|
5596 | 782 |
"Modified: / 06-09-2017 / 12:52:19 / Maren" |
5615 | 783 |
"Modified: / 04-10-2017 / 16:43:44 / cg" |
5881 | 784 |
"Modified: / 10-08-2018 / 12:07:31 / Claus Gittinger" |
2158 | 785 |
! |
786 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
787 |
redrawX:x y:y width:w height:h |
5227 | 788 |
|xI yI depth shownImage imgWidth imgHeight right bott "rectRight rectBelow"| |
11 | 789 |
|
5741 | 790 |
self generateMagnifiedImage. |
2158 | 791 |
|
5741 | 792 |
shownImage := smoothMagnifiedImage ? magnifiedImage ? image. |
793 |
shownImage notNil ifTrue:[ |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
794 |
imgWidth := shownImage width. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
795 |
imgHeight := shownImage height. |
635 | 796 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
797 |
adjust == #center ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
798 |
xI := (width - (margin * 2) - imgWidth) // 2. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
799 |
yI := (height - (margin * 2) - imgHeight) // 2. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
800 |
] ifFalse:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
801 |
xI := yI := margin |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
802 |
]. |
414 | 803 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
804 |
((depth := shownImage depth) == 1) ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
805 |
self paint:(shownImage colorFromValue:1) |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
806 |
on:(shownImage colorFromValue:0). |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
807 |
]. |
1071
981c97fe54de
generate device image before clearing in redraw
Claus Gittinger <cg@exept.de>
parents:
677
diff
changeset
|
808 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
809 |
tileMode == true ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
810 |
(tileOffset y > 0 and:[tileOffset x > 0]) ifTrue:[ |
5022 | 811 |
(false "depth ~~ 1" |
812 |
or:[shownImage mask notNil]) ifTrue:[ |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
813 |
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
|
814 |
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
|
815 |
0 to:x+w by:tileOffset x do:[:oX | |
5530 | 816 |
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
|
817 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
818 |
]. |
5022 | 819 |
] ifFalse:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
820 |
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
|
821 |
0 to:x+w by:tileOffset x do:[:oX | |
5530 | 822 |
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
|
823 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
824 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
825 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
826 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
827 |
] ifFalse:[ |
5227 | 828 |
"/rectRight := (shownImage width @ 0) corner:(width @ shownImage height). |
829 |
"/rectBelow := 0 @ (shownImage height) corner:(shownImage height @ height). |
|
830 |
"/(rectRight width > 0 and:[rectRight height > 0]) ifTrue:[ self clearRectangle:rectRight ]. |
|
831 |
"/(rectBelow width > 0 and:[rectBelow height > 0]) ifTrue:[ self clearRectangle:rectBelow ]. |
|
832 |
||
3726 | 833 |
xI > (x+w) ifTrue:[^ self]. "/ no need to draw |
834 |
yI > (y+h) ifTrue:[^ self]. "/ no need to draw |
|
835 |
(xI+imgWidth) < x ifTrue:[^ self]. "/ no need to draw |
|
836 |
(yI+imgHeight) < y ifTrue:[^ self]. "/ no need to draw |
|
837 |
||
5022 | 838 |
(false "depth ~~ 1" |
3726 | 839 |
or:[shownImage mask notNil]) ifTrue:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
840 |
self clearRectangleX:x y:y width:w height:h. |
3726 | 841 |
shownImage displayOn:self x:xI y:yI. |
5226 | 842 |
"/ self displayForm:shownImage x:xI y:yI |
3726 | 843 |
] ifFalse:[ |
5699 | 844 |
(shownImage depth == 32 and:[ shownImage hasAlphaChannel ]) ifTrue:[ |
5986 | 845 |
|showNonAlpha| |
846 |
||
847 |
showNonAlpha := false. |
|
5699 | 848 |
"/ now, we support at least some 32rgba images... |
5530 | 849 |
true "device supportsAlphaChannel" ifTrue:[ |
850 |
self clearRectangleX:x y:y width:w height:h. |
|
5986 | 851 |
[ |
852 |
self displayForm:shownImage x:xI y:yI |
|
853 |
] on:Error do:[ |
|
854 |
showNonAlpha := true |
|
855 |
]. |
|
856 |
]. |
|
857 |
showNonAlpha ifTrue:[ |
|
5699 | 858 |
"/ hack: currently 32bit+alpha is not supported by Displays. |
859 |
"/ make it a masked d24 image and draw that. |
|
860 |
||
5530 | 861 |
|d24Image| |
862 |
||
863 |
d24Image := Depth24Image fromImage:shownImage. |
|
864 |
d24Image mask:(ImageMask fromAlphaInImage:shownImage). |
|
865 |
self clearRectangleX:x y:y width:w height:h. |
|
866 |
d24Image displayOn:self x:xI y:yI. |
|
867 |
] |
|
5529 | 868 |
] ifFalse:[ |
5530 | 869 |
gc displayOpaqueForm:shownImage x:xI y:yI |
5529 | 870 |
]. |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
871 |
]. |
430 | 872 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
873 |
"/ right of image ? |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
874 |
right := x + w - 1. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
875 |
right > (xI + imgWidth) ifTrue:[ |
5022 | 876 |
self clearRectangleX:(xI + imgWidth) y:y |
5595 | 877 |
width:(right - imgWidth - xI) height:h |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
878 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
879 |
"/ below of image ? |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
880 |
bott := y + h - 1. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
881 |
bott > (yI + imgHeight) ifTrue:[ |
5022 | 882 |
self clearRectangleX:margin y:(yI + imgHeight) |
5595 | 883 |
width:w height:(bott - imgHeight - yI) |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
884 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
885 |
]. |
5268 | 886 |
] ifFalse:[ |
887 |
self clearRectangleX:x y:y width:w height:h. |
|
5529 | 888 |
]. |
89 | 889 |
|
5529 | 890 |
"Created: / 11-07-1996 / 21:02:12 / cg" |
5610 | 891 |
"Modified: / 28-09-2017 / 18:19:01 / cg" |
5986 | 892 |
"Modified: / 10-01-2019 / 19:07:15 / Claus Gittinger" |
1 | 893 |
! ! |
894 |
||
2158 | 895 |
!ImageView methodsFor:'event handling'! |
896 |
||
3618 | 897 |
buttonMotion:state x:x y:y |
5503 | 898 |
|delta mousePoint lastPoint| |
3618 | 899 |
|
5616 | 900 |
(state ~~ 0 and:[(lastPoint := lastMousePoint value) notNil]) ifTrue:[ |
3618 | 901 |
mousePoint := (x@y). |
5503 | 902 |
delta := mousePoint - lastPoint. |
3618 | 903 |
delta ~= (0@0) ifTrue:[ |
5616 | 904 |
"/ lastMousePoint value:mousePoint. |
905 |
self scrollTo:(self viewOrigin - delta) "/ waitForDrawingFinished:true. |
|
3618 | 906 |
] |
907 |
] ifFalse:[ |
|
908 |
super buttonMotion:state x:x y:y |
|
909 |
] |
|
5503 | 910 |
|
5616 | 911 |
"Modified: / 05-10-2017 / 13:54:48 / cg" |
3618 | 912 |
! |
913 |
||
914 |
buttonPress:button x:x y:y |
|
915 |
button == 1 ifTrue:[ |
|
4124 | 916 |
"self cursor:(Cursor handGrab). " |
5503 | 917 |
lastMousePoint value:( x@y ). |
5616 | 918 |
"/ self sensor compressMotionEvents:true. |
3618 | 919 |
]. |
920 |
super buttonPress:button x:x y:y |
|
4124 | 921 |
|
5616 | 922 |
"Modified: / 05-10-2017 / 13:56:06 / cg" |
3618 | 923 |
! |
924 |
||
925 |
buttonRelease:button x:x y:y |
|
926 |
button == 1 ifTrue:[ |
|
5503 | 927 |
lastMousePoint value: nil |
3618 | 928 |
]. |
929 |
super buttonRelease:button x:x y:y |
|
5503 | 930 |
|
931 |
"Modified: / 25-02-2017 / 22:35:20 / cg" |
|
3618 | 932 |
! |
933 |
||
4124 | 934 |
mouseWheelZoom:amount |
935 |
"CTRL-wheel action" |
|
936 |
||
937 |
|mul| |
|
938 |
||
939 |
amount > 0 ifTrue:[ |
|
940 |
mul := 1.2. |
|
941 |
] ifFalse:[ |
|
942 |
mul := 0.8. |
|
943 |
]. |
|
5387 | 944 |
self magnificationFactor:((magnificationFactor ? 1) * mul). |
4124 | 945 |
|
946 |
"Created: / 06-05-2012 / 12:18:06 / cg" |
|
947 |
! |
|
948 |
||
2158 | 949 |
sizeChanged:how |
5597 | 950 |
(#(fit fitBig fitSmall smoothFit smoothFitBig smoothFitSmall) includes:adjust) ifTrue:[ |
2911
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
951 |
magnifiedImage notNil ifTrue:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
952 |
DoNotMagnifyQuery query ifFalse:[ |
5387 | 953 |
self pushEvent:#updateImageAfterSizeChange. |
2911
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
954 |
] |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
955 |
]. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
956 |
] ifFalse:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
957 |
adjust == #center ifTrue:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
958 |
self clear. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
959 |
self invalidate. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
960 |
]. |
2158 | 961 |
]. |
962 |
super sizeChanged:how |
|
5597 | 963 |
|
964 |
"Modified: / 10-09-2017 / 17:11:08 / cg" |
|
5387 | 965 |
! |
966 |
||
967 |
updateImageAfterSizeChange |
|
5399 | 968 |
|oldMagnifiedImage| |
969 |
||
970 |
oldMagnifiedImage := magnifiedImage. |
|
5610 | 971 |
smoothMagnifiedImage := magnifiedImage := nil. |
972 |
||
5387 | 973 |
self generateMagnifiedImage. |
5610 | 974 |
|
5400 | 975 |
(oldMagnifiedImage isNil |
976 |
or:[ magnifiedImage isNil |
|
977 |
or:[ oldMagnifiedImage extent ~= magnifiedImage extent ]] |
|
978 |
) ifTrue:[ |
|
979 |
"/ self clear. |
|
5399 | 980 |
self invalidate. |
981 |
]. |
|
5610 | 982 |
|
983 |
"Modified (format): / 28-09-2017 / 18:20:32 / cg" |
|
2158 | 984 |
! ! |
985 |
||
2501 | 986 |
!ImageView methodsFor:'initialization & release'! |
1327 | 987 |
|
988 |
destroy |
|
5610 | 989 |
magnifiedImage := smoothMagnifiedImage := nil. |
5404 | 990 |
"/ image := nil. |
1327 | 991 |
super destroy. |
5610 | 992 |
|
993 |
"Modified: / 28-09-2017 / 18:20:44 / cg" |
|
5503 | 994 |
! |
995 |
||
996 |
initialize |
|
997 |
super initialize. |
|
998 |
||
999 |
lastMousePoint := nil asValue. |
|
1000 |
||
1001 |
"Created: / 25-02-2017 / 22:33:27 / cg" |
|
1327 | 1002 |
! ! |
1003 |
||
4245 | 1004 |
!ImageView methodsFor:'menu'! |
1005 |
||
5482 | 1006 |
editImage |
5488 | 1007 |
|img| |
1008 |
||
1009 |
img := self image. |
|
1010 |
imageEditAction notNil ifTrue:[ |
|
1011 |
imageEditAction value:img |
|
1012 |
] ifFalse:[ |
|
1013 |
ImageEditor openOnImage:img. |
|
1014 |
]. |
|
5482 | 1015 |
|
1016 |
"Created: / 16-02-2017 / 19:01:41 / cg" |
|
5488 | 1017 |
"Modified: / 19-02-2017 / 23:01:14 / cg" |
5482 | 1018 |
! |
1019 |
||
5760 | 1020 |
fitBigMenuItemVisible |
1021 |
^ true |
|
1022 |
! |
|
1023 |
||
5599 | 1024 |
magnifyBy:scale |
5783 | 1025 |
self adjustHolder value:#Mag withoutNotifying:self. |
5599 | 1026 |
self adjust:#topLeft. |
5783 | 1027 |
"/ set again, so the menu shows nothing |
1028 |
self adjustHolder value:#Mag withoutNotifying:self. |
|
5599 | 1029 |
self magnificationFactor:scale. |
1030 |
||
1031 |
"Created: / 13-09-2017 / 09:43:11 / cg" |
|
5783 | 1032 |
"Modified: / 02-06-2018 / 07:33:15 / Claus Gittinger" |
5599 | 1033 |
! |
1034 |
||
4245 | 1035 |
middleButtonMenu |
4263 | 1036 |
menuHolder notNil ifTrue:[^ super middleButtonMenu]. |
5751 | 1037 |
^ [ self class middleButtonMenu ] |
1038 |
! |
|
1039 |
||
1040 |
middleButtonMenuExtraSlice |
|
1041 |
^ [ self class middleButtonMenuExtraSlice ] |
|
1042 |
! |
|
1043 |
||
1044 |
saveImageAs |
|
1045 |
|imageFilename| |
|
1046 |
||
1047 |
imageFilename := Dialog |
|
1048 |
requestFileName:(resources string:'Save Image As') |
|
1049 |
default:'image.png' |
|
1050 |
pattern:'*.png' |
|
1051 |
fromDirectory:Filename currentDirectory. |
|
1052 |
||
1053 |
imageFilename notNil ifTrue:[ |
|
1054 |
self saveImageAs:imageFilename |
|
1055 |
]. |
|
1056 |
! |
|
1057 |
||
1058 |
saveImageAs:filename |
|
1059 |
PNGReader save:image onFile:filename |
|
5760 | 1060 |
! |
1061 |
||
1062 |
smoothFitBigMenuItemVisible |
|
1063 |
^ true |
|
1064 |
! |
|
1065 |
||
1066 |
smoothingMenuItemVisible |
|
1067 |
^ true |
|
4245 | 1068 |
! ! |
1069 |
||
161 | 1070 |
!ImageView methodsFor:'queries'! |
24 | 1071 |
|
161 | 1072 |
heightOfContents |
5387 | 1073 |
"return the image's height - scrollbar needs this info" |
1 | 1074 |
|
161 | 1075 |
image isNil ifTrue:[^ 0]. |
2158 | 1076 |
^ (magnifiedImage ? image) height |
89 | 1077 |
! |
1078 |
||
5482 | 1079 |
selfIsNotImageEditor |
1080 |
"for the menu; to hide edit item" |
|
1081 |
||
5751 | 1082 |
^ true |
5482 | 1083 |
|
1084 |
"Created: / 16-02-2017 / 19:00:59 / cg" |
|
1085 |
! |
|
1086 |
||
1 | 1087 |
widthOfContents |
5387 | 1088 |
"return the image's width - scrollbar needs this info" |
1 | 1089 |
|
1090 |
image isNil ifTrue:[^ 0]. |
|
2158 | 1091 |
^ (magnifiedImage ? image) width |
161 | 1092 |
! ! |
1093 |
||
3408 | 1094 |
!ImageView methodsFor:'scrolling'! |
1095 |
||
5555 | 1096 |
scrollToMakeRectangleVisible:aRectangle |
1097 |
"try to arrange for aRectangle to be visible (at the center, if possible)" |
|
1098 |
||
1099 |
self scrollToMakeVisible:(aRectangle center). |
|
1100 |
self scrollToMakeVisible:(aRectangle corner). |
|
1101 |
self scrollToMakeVisible:(aRectangle origin). |
|
1102 |
||
1103 |
" |
|
1104 |
|v| |
|
1105 |
v := ImageView new image:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'). |
|
1106 |
v openAndWait. |
|
1107 |
v inspect. |
|
1108 |
v scrollToMakeRectangleVisible:((300@100) corner:(320@120)). |
|
1109 |
" |
|
1110 |
||
1111 |
"Created: / 20-07-2017 / 13:45:29 / cg" |
|
1112 |
! |
|
1113 |
||
3408 | 1114 |
scrollToMakeVisible:aPoint |
5555 | 1115 |
"try to arrange for aPoint (in logical image coordinates) |
1116 |
to be visible (at the center, if possible)" |
|
3408 | 1117 |
|
5693 | 1118 |
|mag magPos imgExtent newOffset| |
1119 |
||
1120 |
imgExtent := 0@0. |
|
5721 | 1121 |
image notNil ifTrue:[ |
5693 | 1122 |
imgExtent := image extent. |
1123 |
]. |
|
3408 | 1124 |
|
1125 |
mag := self magnification. |
|
5555 | 1126 |
magPos := aPoint * mag. |
1127 |
||
1128 |
((self bounds + self viewOrigin) containsPoint:magPos) ifFalse:[ |
|
1129 |
newOffset := magPos - (self extent / 2). |
|
1130 |
newOffset := newOffset max:(0@0). |
|
5693 | 1131 |
newOffset := newOffset min:((imgExtent * mag) - (self extent / 2)). |
5721 | 1132 |
newOffset := newOffset rounded. |
5556 | 1133 |
self scrollTo:newOffset waitForDrawingFinished:true. |
5507 | 1134 |
]. |
1135 |
||
1136 |
" |
|
1137 |
|v| |
|
1138 |
v := ImageView new image:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'). |
|
1139 |
v openAndWait. |
|
1140 |
v inspect. |
|
1141 |
v scrollToMakeVisible:(300@100). |
|
1142 |
" |
|
1143 |
||
5556 | 1144 |
"Modified: / 20-07-2017 / 14:37:11 / cg" |
3408 | 1145 |
! ! |
1146 |
||
257 | 1147 |
!ImageView class methodsFor:'documentation'! |
161 | 1148 |
|
1149 |
version |
|
4912 | 1150 |
^ '$Header$' |
3884 | 1151 |
! |
1152 |
||
1153 |
version_CVS |
|
4912 | 1154 |
^ '$Header$' |
1 | 1155 |
! ! |
2358 | 1156 |
|
4192 | 1157 |
|
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
1158 |
ImageView initialize! |