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