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