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