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