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