author | mawalch |
Tue, 30 Aug 2016 14:14:09 +0200 | |
changeset 5226 | 24916b8eff22 |
parent 5022 | c2e58c679b8e |
child 5227 | 14206c682961 |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
24 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1763
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
12 |
"{ Package: 'stx:libwidg2' }" |
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
13 |
|
4732 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
296 | 16 |
View subclass:#ImageView |
4124 | 17 |
instanceVariableNames:'image magnifiedImage adjust magnificationFactor tileMode |
18 |
tileOffset lastMousePoint' |
|
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
19 |
classVariableNames:'DoNotMagnifyQuery' |
161 | 20 |
poolDictionaries:'' |
21 |
category:'Views-Misc' |
|
1 | 22 |
! |
23 |
||
257 | 24 |
!ImageView class methodsFor:'documentation'! |
26 | 25 |
|
26 |
copyright |
|
27 |
" |
|
28 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
2747 | 42 |
This View knows how to display a (bitmap-)image (or form). |
26 | 43 |
|
44 |
You can display an image with: |
|
45 |
||
2747 | 46 |
ImageView openOn:anImageFileName |
26 | 47 |
or: |
2747 | 48 |
ImageView openOnImage:anImage |
47 | 49 |
or: |
2747 | 50 |
ImageView new image:anImage |
26 | 51 |
|
52 |
i.e. |
|
53 |
||
2748 | 54 |
ImageView openOn:'../../goodies/bitmaps/gifImages/garfield.gif' |
55 |
ImageView openOn:'../../goodies/bitmaps/SBrowser.xbm' |
|
296 | 56 |
|
2748 | 57 |
ImageView openOnImage:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') |
58 |
ImageView openOnImage:(Image fromFile:'../../goodies/bitmaps/SBrowser.xbm') |
|
26 | 59 |
|
5226 | 60 |
adjust: |
2747 | 61 |
controls how images are displayed; |
62 |
can be one of: |
|
63 |
#topLeft - image is displayed as usual |
|
64 |
#center - image is shown centered |
|
65 |
#fitBig - big images are shrunk to make it fit the view |
|
66 |
#fitSmall - small images are magnified to make it fit the view, |
|
67 |
#fit - all images are magnified to fit the view |
|
2158 | 68 |
|
296 | 69 |
[author:] |
2747 | 70 |
Claus Gittinger |
296 | 71 |
|
72 |
[see also:] |
|
2747 | 73 |
Image Form |
26 | 74 |
" |
3683 | 75 |
! |
76 |
||
77 |
examples |
|
78 |
" |
|
79 |
|top imgView scrView| |
|
80 |
||
81 |
top := StandardSystemView new. |
|
82 |
top extent:300@300. |
|
83 |
||
84 |
imgView := ImageView new. |
|
85 |
imgView image:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'). |
|
86 |
||
87 |
scrView := HVScrollableView forView:imgView. |
|
88 |
scrView origin:0@0 corner:1.0@1.0. |
|
89 |
top add:scrView. |
|
90 |
||
91 |
top open. |
|
92 |
" |
|
26 | 93 |
! ! |
94 |
||
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
95 |
!ImageView class methodsFor:'initialization'! |
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
96 |
|
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
97 |
initialize |
4912 | 98 |
DoNotMagnifyQuery isNil ifTrue:[ |
99 |
DoNotMagnifyQuery := QuerySignal new defaultAnswer:false. |
|
100 |
]. |
|
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
101 |
! ! |
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
102 |
|
4245 | 103 |
!ImageView class methodsFor:'menu specs'! |
104 |
||
105 |
middleButtonMenu |
|
106 |
"This resource specification was automatically generated |
|
107 |
by the MenuEditor of ST/X." |
|
108 |
||
109 |
"Do not manually edit this!! If it is corrupted, |
|
110 |
the MenuEditor may not be able to read the specification." |
|
111 |
||
112 |
||
113 |
" |
|
114 |
MenuEditor new openOnClass:ImageView andSelector:#middleButtonMenu |
|
115 |
(Menu new fromLiteralArrayEncoding:(ImageView middleButtonMenu)) startUp |
|
116 |
" |
|
117 |
||
118 |
<resource: #menu> |
|
119 |
||
120 |
^ |
|
121 |
#(Menu |
|
122 |
( |
|
123 |
(MenuItem |
|
124 |
label: 'Size to Fit' |
|
125 |
itemValue: adjust: |
|
126 |
argument: fitBig |
|
127 |
) |
|
128 |
(MenuItem |
|
129 |
label: 'Original Size' |
|
130 |
itemValue: adjust: |
|
131 |
argument: 'nil' |
|
132 |
) |
|
133 |
) |
|
134 |
nil |
|
135 |
nil |
|
136 |
) |
|
137 |
! ! |
|
138 |
||
2511 | 139 |
!ImageView class methodsFor:'queries-plugin'! |
1694 | 140 |
|
141 |
aspectSelectors |
|
142 |
^ #( imageChannel ) |
|
143 |
||
144 |
"Created: / 11.2.2000 / 00:37:33 / cg" |
|
145 |
! ! |
|
146 |
||
257 | 147 |
!ImageView class methodsFor:'startup'! |
1 | 148 |
|
4192 | 149 |
openOn:anImageOrFileName |
150 |
"startup an image viewer on an image read from a file" |
|
151 |
||
152 |
anImageOrFileName isImage ifTrue:[ |
|
153 |
^ self openOnImage:anImageOrFileName |
|
154 |
]. |
|
155 |
^ self openOnFile:anImageOrFileName |
|
156 |
||
157 |
" |
|
158 |
ImageView openOn:'bitmaps/gifImages/garfield.gif' |
|
159 |
ImageView openOn:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' |
|
160 |
" |
|
161 |
||
162 |
"Modified: / 31.10.1997 / 16:17:52 / cg" |
|
163 |
! |
|
164 |
||
165 |
openOnFile:aFileName |
|
47 | 166 |
"startup an image viewer on an image read from a file" |
167 |
||
1970 | 168 |
|fn imageView img e| |
169 |
||
170 |
fn := aFileName asFilename. |
|
47 | 171 |
|
1970 | 172 |
img := Image fromFile:fn. |
47 | 173 |
img isNil ifTrue:[ |
2747 | 174 |
fn exists ifTrue:[ |
175 |
e := 'Unknown or unsupported image format.' |
|
176 |
] ifFalse:[ |
|
177 |
e := 'No such image file.'. |
|
178 |
]. |
|
179 |
self warn:(self resources string:e). |
|
180 |
^ nil |
|
47 | 181 |
]. |
353 | 182 |
imageView := self openOnImage:img. |
3733 | 183 |
imageView topView label:(fn pathName) iconLabel:(fn baseName). |
353 | 184 |
^ imageView |
1 | 185 |
|
47 | 186 |
" |
4558 | 187 |
ImageView openOnFile:'../../goodies/bitmaps/gifImages/garfield.gif' |
188 |
ImageView openOnFile:'../../goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' |
|
47 | 189 |
" |
348 | 190 |
|
599 | 191 |
"Modified: / 31.10.1997 / 16:17:52 / cg" |
47 | 192 |
! |
193 |
||
194 |
openOnImage:anImage |
|
195 |
"startup an image viewer on an image" |
|
1 | 196 |
|
4558 | 197 |
|lbl| |
47 | 198 |
|
199 |
anImage isImage ifTrue:[ |
|
3733 | 200 |
lbl := anImage fileName ? 'an Image' |
47 | 201 |
] ifFalse:[ |
3904 | 202 |
anImage isNil ifTrue:[ |
203 |
lbl := 'an Image' |
|
204 |
] ifFalse:[ |
|
205 |
lbl := 'a Form' |
|
206 |
] |
|
47 | 207 |
]. |
4558 | 208 |
^ self openOnImage:anImage title:lbl |
209 |
||
210 |
" |
|
211 |
ImageView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif') title:'garfield' |
|
212 |
ImageView openOnImage:(Image fromFile:'../../libtool/bitmaps/SBrowser.xbm') title:'old browser icon' |
|
213 |
" |
|
214 |
! |
|
215 |
||
216 |
openOnImage:anImage title:aString |
|
217 |
"startup an image viewer on an image" |
|
218 |
||
219 |
|top v imageView icnW icnH iconView magX magY mag imgWidth imgHeight| |
|
220 |
||
221 |
top := StandardSystemView label:aString. |
|
1 | 222 |
|
223 |
v := HVScrollableView for:self in:top. |
|
5226 | 224 |
v origin:0@0 extent:1.0@1.0. |
1 | 225 |
imageView := v scrolledView. |
226 |
||
47 | 227 |
anImage notNil ifTrue:[ |
3733 | 228 |
imageView image:anImage. |
7 | 229 |
|
3733 | 230 |
"define an icon view showing a little version of image. |
231 |
Since some window managers cannot handle this correctly (twm), |
|
232 |
this is only done when running on an IRIS" |
|
7 | 233 |
|
5226 | 234 |
(true "(OperatingSystem getSystemType = 'iris')" |
3733 | 235 |
and:[StyleSheet name == #iris]) ifTrue:[ |
236 |
iconView := ImageView new. |
|
7 | 237 |
|
3733 | 238 |
"for now; should somehow get access to preferred iconview extent ..." |
239 |
icnW := 86. |
|
240 |
icnH := 68. |
|
7 | 241 |
|
3733 | 242 |
imgWidth := anImage width. |
243 |
imgHeight := anImage height. |
|
635 | 244 |
|
3733 | 245 |
((imgWidth <= icnW) and:[imgHeight <= icnH]) ifTrue:[ |
246 |
iconView extent:(imgWidth @ imgHeight). |
|
247 |
mag := 1 @ 1 |
|
248 |
] ifFalse:[ |
|
249 |
magX := icnW / imgWidth. |
|
250 |
magY := icnH / imgHeight. |
|
7 | 251 |
|
3733 | 252 |
"scale image" |
7 | 253 |
" |
3733 | 254 |
mag := magX @ magY. |
7 | 255 |
" |
3733 | 256 |
"preserve ratio" |
5226 | 257 |
" |
3733 | 258 |
mag := (magX min:magY) asPoint. |
5226 | 259 |
" |
7 | 260 |
" " |
3733 | 261 |
mag := (magX max:magY) asPoint. |
7 | 262 |
" " |
263 |
||
3733 | 264 |
iconView extent:((anImage width @ anImage height) * mag) rounded. |
265 |
]. |
|
7 | 266 |
|
3733 | 267 |
top iconView:iconView. |
268 |
]. |
|
7 | 269 |
]. |
270 |
||
271 |
top open. |
|
272 |
||
26 | 273 |
iconView notNil ifTrue:[ |
3733 | 274 |
top windowGroup addView:iconView. |
5226 | 275 |
[ |
3733 | 276 |
iconView image:(anImage magnifiedBy:mag). |
277 |
] forkAt:4 |
|
7 | 278 |
]. |
353 | 279 |
^ imageView |
1 | 280 |
|
26 | 281 |
" |
4558 | 282 |
ImageView openOnImage:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') title:'garfield' |
283 |
ImageView openOnImage:(Image fromFile:'../../libtool/bitmaps/SBrowser.xbm') |
|
26 | 284 |
" |
353 | 285 |
|
3904 | 286 |
"Modified: / 01-06-2010 / 18:31:14 / cg" |
1 | 287 |
! ! |
288 |
||
161 | 289 |
!ImageView methodsFor:'accessing'! |
290 |
||
291 |
adjust:layoutSymbol |
|
292 |
"set the adjust (how the image is displayed); |
|
2375 | 293 |
currently, only support #topLeft, #center, #fitBig, #fitSmall and #fit: |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
294 |
#topLeft - image is displayed as usual |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
295 |
#center - image is shown centered |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
296 |
#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
|
297 |
#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
|
298 |
#fit - all images are magnified to fit the view |
2375 | 299 |
" |
2158 | 300 |
|
2164 | 301 |
adjust ~= layoutSymbol ifTrue:[ |
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
302 |
adjust := layoutSymbol. |
161 | 303 |
|
2659
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
304 |
magnifiedImage := nil. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
305 |
shown ifTrue:[ |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
306 |
image notNil ifTrue:[ |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
307 |
self generateMagnifiedImage. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
308 |
self clear. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
309 |
self scrollToTopLeft. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
310 |
self invalidate. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
311 |
self contentsChanged. |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
312 |
] |
3af857eb52fb
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2650
diff
changeset
|
313 |
]. |
2158 | 314 |
]. |
161 | 315 |
! |
316 |
||
317 |
image |
|
318 |
"return the image" |
|
319 |
||
320 |
^ image |
|
321 |
! |
|
322 |
||
323 |
image:anImage |
|
3710
162a45c5ce34
invalidate when image changes
Claus Gittinger <cg@exept.de>
parents:
3705
diff
changeset
|
324 |
"set the image" |
1 | 325 |
|
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
326 |
self image:anImage scroll:true |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
327 |
! |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
328 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
329 |
image:anImage scroll:doScroll |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
330 |
"set the image - show a wait cursor, since image dithering may take a while" |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
331 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
332 |
self setImage:anImage scroll:doScroll |
1993 | 333 |
! |
334 |
||
3705 | 335 |
image:anImage scroll:doScroll invalidate:doInvalidate |
336 |
"set the image - show a wait cursor, since image dithering may take a while" |
|
337 |
||
338 |
self setImage:anImage scroll:doScroll invalidate:doInvalidate |
|
339 |
! |
|
340 |
||
3408 | 341 |
magnification |
342 |
magnifiedImage isNil ifTrue:[^ 1@1]. |
|
343 |
^ magnifiedImage extent / image extent |
|
344 |
! |
|
345 |
||
4066 | 346 |
model:aValueHolder |
347 |
super model:aValueHolder. |
|
348 |
self updateFromModel. |
|
349 |
||
350 |
"Created: / 25-07-2011 / 15:32:10 / cg" |
|
351 |
! |
|
352 |
||
1993 | 353 |
setImage:anImage |
354 |
"set the image - show a wait cursor, since image dithering may take a while" |
|
355 |
||
4966 | 356 |
self setImage:anImage scroll:true invalidate:true |
1694 | 357 |
|
358 |
"Modified: / 10.2.2000 / 23:25:51 / cg" |
|
2089 | 359 |
! |
360 |
||
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
361 |
setImage:anImage scroll:doScroll |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
362 |
"set the image - show a wait cursor, since image dithering may take a while" |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
363 |
|
3710
162a45c5ce34
invalidate when image changes
Claus Gittinger <cg@exept.de>
parents:
3705
diff
changeset
|
364 |
self setImage:anImage scroll:doScroll invalidate:true |
3705 | 365 |
! |
366 |
||
367 |
setImage:anImage scroll:doScroll invalidate:doInvalidate |
|
368 |
"set the image - show a wait cursor, since image dithering may take a while" |
|
369 |
||
4966 | 370 |
|oldSize newSize newImageIsSmaller| |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
371 |
|
5226 | 372 |
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
|
373 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
374 |
image := anImage. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
375 |
magnifiedImage := nil. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
376 |
self generateMagnifiedImage. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
377 |
|
5226 | 378 |
newSize := image isNil ifTrue:[0@0] ifFalse:[(magnifiedImage ? image) extent]. |
4966 | 379 |
newImageIsSmaller := ((oldSize x > newSize x) or:[oldSize y > newSize y]). |
5226 | 380 |
|
4966 | 381 |
(doScroll or:[newImageIsSmaller]) ifTrue:[ |
382 |
(doInvalidate and:[newImageIsSmaller]) ifTrue:[ self clear ]. |
|
3705 | 383 |
self scrollToTopLeft. |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
384 |
]. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
385 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
386 |
oldSize ~= newSize ifTrue:[ |
3705 | 387 |
"/ avoid endless loop in case of a resize happening due |
388 |
"/ to scrollBar visibility changes. |
|
5226 | 389 |
"/ that QuerySignal suppresses another magnification in sizeChanged: |
390 |
DoNotMagnifyQuery |
|
4966 | 391 |
answer:true |
392 |
do:[ |
|
393 |
self contentsChanged. |
|
394 |
] |
|
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
395 |
]. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
396 |
|
3705 | 397 |
(shown and:[doInvalidate]) ifTrue:[ |
4966 | 398 |
"/ newImageIsSmaller ifTrue:[ |
399 |
"/ self clear. |
|
5226 | 400 |
"/ ]. |
3705 | 401 |
self invalidate |
2544
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
402 |
]. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
403 |
self changed:#image. |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
404 |
|
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
405 |
"Modified: / 10.2.2000 / 23:25:51 / cg" |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
406 |
! |
bcae3dbd3ccd
do not scroll, when crobbing
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
407 |
|
4245 | 408 |
sizeToFit:aBoolean |
409 |
aBoolean ifTrue:[ |
|
410 |
self adjust:#fitBig |
|
411 |
] ifFalse:[ |
|
412 |
self adjust:nil. |
|
413 |
] |
|
414 |
! |
|
415 |
||
2089 | 416 |
tileMode:aBoolean tileOffset:aPoint |
417 |
||
418 |
tileMode := aBoolean. |
|
419 |
tileOffset := aPoint |
|
1694 | 420 |
! ! |
421 |
||
2404 | 422 |
!ImageView methodsFor:'accessing-channels'! |
1510
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
423 |
|
1694 | 424 |
imageChannel |
4031 | 425 |
^ self model |
1694 | 426 |
|
4031 | 427 |
"Modified: / 31-03-2011 / 10:45:58 / cg" |
1694 | 428 |
! |
429 |
||
430 |
imageChannel:aValueHolder |
|
4031 | 431 |
self model:aValueHolder. |
1694 | 432 |
|
4031 | 433 |
"Created: / 11-02-2000 / 00:34:33 / cg" |
434 |
"Modified: / 31-03-2011 / 10:46:07 / cg" |
|
1694 | 435 |
! ! |
1135
75101bf02c5b
send contentsChanged notifications before, to avoid
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
436 |
|
1694 | 437 |
!ImageView methodsFor:'change & update'! |
438 |
||
439 |
update:something with:aParameter from:changedObject |
|
4031 | 440 |
changedObject == model ifTrue:[ |
4561 | 441 |
self updateFromModel. |
2786
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
442 |
^ self |
1694 | 443 |
]. |
444 |
super update:something with:aParameter from:changedObject |
|
445 |
||
4031 | 446 |
"Created: / 11-02-2000 / 00:37:02 / cg" |
447 |
"Modified: / 31-03-2011 / 10:46:16 / cg" |
|
2786
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
448 |
! |
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
449 |
|
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
450 |
updateFromModel |
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
451 |
"the model changes, set my image" |
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
452 |
|
d3b6171aec01
React to changes of imageChannel.
Stefan Vogel <sv@exept.de>
parents:
2748
diff
changeset
|
453 |
self image:model value. |
1 | 454 |
! ! |
455 |
||
456 |
!ImageView methodsFor:'drawing'! |
|
457 |
||
2158 | 458 |
generateMagnifiedImage |
459 |
|doFit innerWidth innerHeight imgWidth imgHeight| |
|
460 |
||
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
461 |
magnifiedImage notNil ifTrue:[ |
4124 | 462 |
^ self |
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
463 |
]. |
2358 | 464 |
image isNil ifTrue:[ |
4124 | 465 |
^ self |
2358 | 466 |
]. |
2158 | 467 |
doFit := false. |
468 |
||
469 |
innerWidth := self innerWidth. |
|
470 |
innerHeight := self innerHeight. |
|
471 |
||
472 |
imgWidth := image width. |
|
473 |
imgHeight := image height. |
|
474 |
||
475 |
tileMode ~~ true ifTrue:[ |
|
4124 | 476 |
((imgWidth > innerWidth) |
477 |
or:[imgHeight > innerHeight]) ifTrue:[ |
|
478 |
((adjust == #fit) or:[adjust == #fitBig]) ifTrue:[ |
|
479 |
doFit := true |
|
480 |
]. |
|
481 |
] ifFalse:[ |
|
482 |
((imgWidth < innerWidth) |
|
483 |
or:[imgHeight < innerHeight]) ifTrue:[ |
|
484 |
((adjust == #fit) or:[adjust == #fitSmall]) ifTrue:[ |
|
485 |
doFit := true |
|
486 |
]. |
|
487 |
] |
|
488 |
]. |
|
2158 | 489 |
]. |
490 |
doFit ifTrue:[ |
|
4124 | 491 |
magnifiedImage := image magnifiedPreservingRatioTo:(innerWidth @ innerHeight). |
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
492 |
"/ self contentsChanged. |
2164 | 493 |
] ifFalse:[ |
4124 | 494 |
(magnificationFactor notNil and:[magnificationFactor ~= 1]) ifTrue:[ |
495 |
magnifiedImage := image magnifiedBy:magnificationFactor. |
|
496 |
] ifFalse:[ |
|
497 |
magnifiedImage := image |
|
498 |
]. |
|
2158 | 499 |
]. |
4124 | 500 |
|
501 |
"Modified: / 06-05-2012 / 12:17:23 / cg" |
|
2158 | 502 |
! |
503 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
504 |
redrawX:x y:y width:w height:h |
2158 | 505 |
|xI yI depth shownImage imgWidth imgHeight right bott| |
11 | 506 |
|
1 | 507 |
image notNil ifTrue:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
508 |
self generateMagnifiedImage. |
2158 | 509 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
510 |
shownImage := magnifiedImage ? image. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
511 |
imgWidth := shownImage width. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
512 |
imgHeight := shownImage height. |
635 | 513 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
514 |
adjust == #center ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
515 |
xI := (width - (margin * 2) - imgWidth) // 2. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
516 |
yI := (height - (margin * 2) - imgHeight) // 2. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
517 |
] ifFalse:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
518 |
xI := yI := margin |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
519 |
]. |
414 | 520 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
521 |
((depth := shownImage depth) == 1) ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
522 |
self paint:(shownImage colorFromValue:1) |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
523 |
on:(shownImage colorFromValue:0). |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
524 |
]. |
1071
981c97fe54de
generate device image before clearing in redraw
Claus Gittinger <cg@exept.de>
parents:
677
diff
changeset
|
525 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
526 |
tileMode == true ifTrue:[ |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
527 |
(tileOffset y > 0 and:[tileOffset x > 0]) ifTrue:[ |
5022 | 528 |
(false "depth ~~ 1" |
529 |
or:[shownImage mask notNil]) ifTrue:[ |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
530 |
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
|
531 |
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
|
532 |
0 to:x+w by:tileOffset x do:[:oX | |
5226 | 533 |
self displayForm:image x:oX y:oY |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
534 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
535 |
]. |
5022 | 536 |
] ifFalse:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
537 |
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
|
538 |
0 to:x+w by:tileOffset x do:[:oX | |
5226 | 539 |
self displayOpaqueForm:image x:oX y:oY |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
540 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
541 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
542 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
543 |
] |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
544 |
] ifFalse:[ |
3726 | 545 |
xI > (x+w) ifTrue:[^ self]. "/ no need to draw |
546 |
yI > (y+h) ifTrue:[^ self]. "/ no need to draw |
|
547 |
(xI+imgWidth) < x ifTrue:[^ self]. "/ no need to draw |
|
548 |
(yI+imgHeight) < y ifTrue:[^ self]. "/ no need to draw |
|
549 |
||
5022 | 550 |
(false "depth ~~ 1" |
3726 | 551 |
or:[shownImage mask notNil]) ifTrue:[ |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
552 |
self clearRectangleX:x y:y width:w height:h. |
3726 | 553 |
shownImage displayOn:self x:xI y:yI. |
5226 | 554 |
"/ self displayForm:shownImage x:xI y:yI |
3726 | 555 |
] ifFalse:[ |
5226 | 556 |
self displayOpaqueForm:shownImage x:xI y:yI |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
557 |
]. |
430 | 558 |
|
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
559 |
"/ right of image ? |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
560 |
right := x + w - 1. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
561 |
right > (xI + imgWidth) ifTrue:[ |
5022 | 562 |
self clearRectangleX:(xI + imgWidth) y:y |
5226 | 563 |
width:(right - imgWidth - xI) height:h |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
564 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
565 |
"/ below of image ? |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
566 |
bott := y + h - 1. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
567 |
bott > (yI + imgHeight) ifTrue:[ |
5022 | 568 |
self clearRectangleX:margin y:(yI + imgHeight) |
5226 | 569 |
width:w height:(bott - imgHeight - yI) |
3659
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
570 |
]. |
53ec00df6b6c
care for zero-sized image when tiling
Claus Gittinger <cg@exept.de>
parents:
3618
diff
changeset
|
571 |
]. |
1 | 572 |
] |
89 | 573 |
|
635 | 574 |
"Created: / 11.7.1996 / 21:02:12 / cg" |
1071
981c97fe54de
generate device image before clearing in redraw
Claus Gittinger <cg@exept.de>
parents:
677
diff
changeset
|
575 |
"Modified: / 12.8.1998 / 14:02:28 / cg" |
1 | 576 |
! ! |
577 |
||
2158 | 578 |
!ImageView methodsFor:'event handling'! |
579 |
||
3618 | 580 |
buttonMotion:state x:x y:y |
581 |
|delta mousePoint| |
|
582 |
||
583 |
lastMousePoint notNil ifTrue:[ |
|
584 |
mousePoint := (x@y). |
|
585 |
delta := mousePoint - lastMousePoint. |
|
586 |
delta ~= (0@0) ifTrue:[ |
|
587 |
self scrollTo:(self viewOrigin - delta). |
|
588 |
lastMousePoint := mousePoint. |
|
589 |
] |
|
590 |
] ifFalse:[ |
|
591 |
super buttonMotion:state x:x y:y |
|
592 |
] |
|
593 |
! |
|
594 |
||
595 |
buttonPress:button x:x y:y |
|
596 |
button == 1 ifTrue:[ |
|
4124 | 597 |
"self cursor:(Cursor handGrab). " |
3618 | 598 |
lastMousePoint := x@y. |
599 |
]. |
|
600 |
super buttonPress:button x:x y:y |
|
4124 | 601 |
|
602 |
"Modified: / 06-05-2012 / 12:19:39 / cg" |
|
3618 | 603 |
! |
604 |
||
605 |
buttonRelease:button x:x y:y |
|
606 |
button == 1 ifTrue:[ |
|
607 |
lastMousePoint := nil |
|
608 |
]. |
|
609 |
super buttonRelease:button x:x y:y |
|
610 |
! |
|
611 |
||
4124 | 612 |
mouseWheelZoom:amount |
613 |
"CTRL-wheel action" |
|
614 |
||
615 |
|mul| |
|
616 |
||
617 |
amount > 0 ifTrue:[ |
|
618 |
mul := 1.2. |
|
619 |
] ifFalse:[ |
|
620 |
mul := 0.8. |
|
621 |
]. |
|
622 |
||
4732 | 623 |
magnificationFactor := ((magnificationFactor ? 1) * mul). |
624 |
magnificationFactor fractionPart < 0.1 ifTrue:[ |
|
5226 | 625 |
"magnifying by integer factor is faster" |
4732 | 626 |
magnificationFactor := magnificationFactor truncated. |
627 |
]. |
|
4124 | 628 |
magnifiedImage := nil. |
629 |
self invalidate. |
|
630 |
||
631 |
"Created: / 06-05-2012 / 12:18:06 / cg" |
|
632 |
! |
|
633 |
||
2158 | 634 |
sizeChanged:how |
2911
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
635 |
(#(fit fitBig fitSmall) includes:adjust) ifTrue:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
636 |
magnifiedImage notNil ifTrue:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
637 |
DoNotMagnifyQuery query ifFalse:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
638 |
magnifiedImage := nil. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
639 |
self generateMagnifiedImage. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
640 |
self clear. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
641 |
self invalidate. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
642 |
] |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
643 |
]. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
644 |
] ifFalse:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
645 |
adjust == #center ifTrue:[ |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
646 |
self clear. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
647 |
self invalidate. |
b350e90e9a5b
avoid flickern when resizing
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
648 |
]. |
2158 | 649 |
]. |
650 |
super sizeChanged:how |
|
651 |
! ! |
|
652 |
||
2501 | 653 |
!ImageView methodsFor:'initialization & release'! |
1327 | 654 |
|
655 |
destroy |
|
3884 | 656 |
image := magnifiedImage := nil. |
1327 | 657 |
super destroy. |
658 |
! ! |
|
659 |
||
4245 | 660 |
!ImageView methodsFor:'menu'! |
661 |
||
662 |
middleButtonMenu |
|
4263 | 663 |
menuHolder notNil ifTrue:[^ super middleButtonMenu]. |
4245 | 664 |
^ self class middleButtonMenu |
665 |
! ! |
|
666 |
||
161 | 667 |
!ImageView methodsFor:'queries'! |
24 | 668 |
|
161 | 669 |
heightOfContents |
670 |
"return the images height - scrollbar needs this info" |
|
1 | 671 |
|
161 | 672 |
image isNil ifTrue:[^ 0]. |
2158 | 673 |
^ (magnifiedImage ? image) height |
89 | 674 |
! |
675 |
||
1 | 676 |
widthOfContents |
677 |
"return the images width - scrollbar needs this info" |
|
678 |
||
679 |
image isNil ifTrue:[^ 0]. |
|
2158 | 680 |
^ (magnifiedImage ? image) width |
161 | 681 |
! ! |
682 |
||
3408 | 683 |
!ImageView methodsFor:'scrolling'! |
684 |
||
685 |
scrollToMakeVisible:aPoint |
|
686 |
"try to arrange for aPoint to be visible (at the center, if possible)" |
|
687 |
||
688 |
|mag pos| |
|
689 |
||
690 |
mag := self magnification. |
|
691 |
pos := aPoint * mag. |
|
3705 | 692 |
self scrollTo:(pos - (self extent / 2)) rounded. |
3408 | 693 |
! ! |
694 |
||
257 | 695 |
!ImageView class methodsFor:'documentation'! |
161 | 696 |
|
697 |
version |
|
4912 | 698 |
^ '$Header$' |
3884 | 699 |
! |
700 |
||
701 |
version_CVS |
|
4912 | 702 |
^ '$Header$' |
1 | 703 |
! ! |
2358 | 704 |
|
4192 | 705 |
|
2160
4c15f05f8bc6
somewhat complicated: under win32 style, a magnify leads to scrollbars
Claus Gittinger <cg@exept.de>
parents:
2158
diff
changeset
|
706 |
ImageView initialize! |