author | Claus Gittinger <cg@exept.de> |
Wed, 19 Apr 2000 13:18:21 +0200 | |
changeset 1764 | 3dd553f8d9f0 |
parent 1763 | 7d6d64622ee4 |
child 1970 | b7cf91b688d1 |
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 |
" |
|
12 |
||
1763
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
13 |
"{ Package: 'stx:libwidg2' }" |
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
14 |
|
296 | 15 |
View subclass:#ImageView |
1694 | 16 |
instanceVariableNames:'image adjust imageChannel' |
161 | 17 |
classVariableNames:'' |
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 |
" |
|
40 |
This View knows how to display an image (or form). |
|
41 |
||
42 |
You can display an image with: |
|
43 |
||
296 | 44 |
ImageView openOn:anImageFileName |
26 | 45 |
or: |
296 | 46 |
ImageView openOnImage:anImage |
47 | 47 |
or: |
296 | 48 |
ImageView new image:anImage |
26 | 49 |
|
50 |
i.e. |
|
51 |
||
353 | 52 |
ImageView openOn:'bitmaps/gifImages/garfield.gif' |
296 | 53 |
ImageView openOn:'bitmaps/SBrowser.xbm' |
54 |
||
353 | 55 |
ImageView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif') |
296 | 56 |
ImageView openOnImage:(Image fromFile:'bitmaps/SBrowser.xbm') |
26 | 57 |
|
296 | 58 |
[author:] |
59 |
Claus Gittinger |
|
60 |
||
61 |
[see also:] |
|
62 |
Image Form |
|
26 | 63 |
" |
64 |
! ! |
|
65 |
||
1694 | 66 |
!ImageView class methodsFor:'queries - plugin'! |
67 |
||
68 |
aspectSelectors |
|
69 |
^ #( imageChannel ) |
|
70 |
||
71 |
"Created: / 11.2.2000 / 00:37:33 / cg" |
|
72 |
! ! |
|
73 |
||
257 | 74 |
!ImageView class methodsFor:'startup'! |
1 | 75 |
|
11 | 76 |
openOn:aFileName |
47 | 77 |
"startup an image viewer on an image read from a file" |
78 |
||
353 | 79 |
|imageView img e| |
47 | 80 |
|
81 |
img := Image fromFile:aFileName. |
|
82 |
img isNil ifTrue:[ |
|
348 | 83 |
aFileName asFilename exists ifTrue:[ |
84 |
e := 'unknown/unsupported image format' |
|
85 |
] ifFalse:[ |
|
86 |
e := 'no such image'. |
|
87 |
]. |
|
88 |
self warn:e. |
|
89 |
^ nil |
|
47 | 90 |
]. |
353 | 91 |
imageView := self openOnImage:img. |
47 | 92 |
|
599 | 93 |
imageView topView label:aFileName iconLabel:(aFileName asFilename baseName). |
47 | 94 |
|
353 | 95 |
^ imageView |
1 | 96 |
|
47 | 97 |
" |
353 | 98 |
ImageView openOn:'bitmaps/gifImages/garfield.gif' |
99 |
ImageView openOn:'bitmaps/xpmBitmaps/BOOK.xpm' |
|
47 | 100 |
" |
348 | 101 |
|
599 | 102 |
"Modified: / 31.10.1997 / 16:17:52 / cg" |
47 | 103 |
! |
104 |
||
105 |
openOnImage:anImage |
|
106 |
"startup an image viewer on an image" |
|
1 | 107 |
|
635 | 108 |
|top v imageView icnW icnH iconView magX magY mag lbl imgWidth imgHeight| |
47 | 109 |
|
110 |
anImage isImage ifTrue:[ |
|
353 | 111 |
lbl := 'an Image' |
47 | 112 |
] ifFalse:[ |
353 | 113 |
lbl := 'a Form' |
47 | 114 |
]. |
115 |
top := StandardSystemView label:lbl. |
|
1 | 116 |
|
117 |
v := HVScrollableView for:self in:top. |
|
118 |
v origin:0@0 extent:1.0@1.0. |
|
119 |
imageView := v scrolledView. |
|
120 |
||
47 | 121 |
anImage notNil ifTrue:[ |
353 | 122 |
imageView image:anImage. |
7 | 123 |
|
353 | 124 |
"define an icon view showing a little version of image. |
125 |
Since some window managers cannot handle this correctly (twm), |
|
126 |
this is only done when running on an IRIS" |
|
7 | 127 |
|
353 | 128 |
(true "(OperatingSystem getSystemType = 'iris')" |
129 |
and:[StyleSheet name == #iris]) ifTrue:[ |
|
599 | 130 |
iconView := ImageView new. |
7 | 131 |
|
353 | 132 |
"for now; should somehow get access to preferred iconview extent ..." |
133 |
icnW := 86. |
|
599 | 134 |
icnH := 68. |
7 | 135 |
|
635 | 136 |
imgWidth := anImage width. |
137 |
imgHeight := anImage height. |
|
138 |
||
139 |
((imgWidth <= icnW) and:[imgHeight <= icnH]) ifTrue:[ |
|
140 |
iconView extent:(imgWidth @ imgHeight). |
|
353 | 141 |
mag := 1 @ 1 |
142 |
] ifFalse:[ |
|
635 | 143 |
magX := icnW / imgWidth. |
144 |
magY := icnH / imgHeight. |
|
7 | 145 |
|
353 | 146 |
"scale image" |
7 | 147 |
" |
353 | 148 |
mag := magX @ magY. |
7 | 149 |
" |
353 | 150 |
"preserve ratio" |
7 | 151 |
" |
353 | 152 |
mag := (magX min:magY) asPoint. |
7 | 153 |
" |
154 |
" " |
|
353 | 155 |
mag := (magX max:magY) asPoint. |
7 | 156 |
" " |
157 |
||
353 | 158 |
iconView extent:((anImage width @ anImage height) * mag) rounded. |
159 |
]. |
|
7 | 160 |
|
353 | 161 |
top iconView:iconView. |
162 |
]. |
|
7 | 163 |
]. |
164 |
||
165 |
top open. |
|
166 |
||
26 | 167 |
iconView notNil ifTrue:[ |
353 | 168 |
top windowGroup addView:iconView. |
169 |
[ |
|
170 |
iconView image:(anImage magnifyBy:mag). |
|
171 |
] forkAt:4 |
|
7 | 172 |
]. |
353 | 173 |
^ imageView |
1 | 174 |
|
26 | 175 |
" |
353 | 176 |
ImageView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif') |
47 | 177 |
ImageView openOnImage:(Image fromFile:'bitmaps/SBrowser.xbm') |
26 | 178 |
" |
353 | 179 |
|
635 | 180 |
"Modified: / 18.12.1997 / 11:46:19 / cg" |
1 | 181 |
! ! |
182 |
||
161 | 183 |
!ImageView methodsFor:'accessing'! |
184 |
||
185 |
adjust:layoutSymbol |
|
186 |
"set the adjust (how the image is displayed); |
|
187 |
currently, only support #topLeft and #center" |
|
188 |
||
189 |
adjust := layoutSymbol |
|
190 |
! |
|
191 |
||
192 |
image |
|
193 |
"return the image" |
|
194 |
||
195 |
^ image |
|
196 |
! |
|
197 |
||
198 |
image:anImage |
|
199 |
"set the image - show a wait cursor, since image dithering may take a while" |
|
1 | 200 |
|
1763
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
201 |
|oldSize newSize devImage| |
1694 | 202 |
|
203 |
image ~= anImage ifTrue:[ |
|
204 |
oldSize := image ifNil:[0@0] ifNotNil:[image extent]. |
|
205 |
||
206 |
image := anImage. |
|
207 |
||
208 |
newSize := image ifNil:[0@0] ifNotNil:[image extent]. |
|
209 |
oldSize ~= newSize ifTrue:[ |
|
210 |
self contentsChanged. |
|
211 |
]. |
|
212 |
||
213 |
shown ifTrue:[ |
|
214 |
self withWaitCursorDo:[ |
|
215 |
(image notNil and: [image device ~~ device]) ifTrue:[ |
|
1763
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
216 |
devImage := image on:device. |
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
217 |
devImage ~~ image ifTrue:[ |
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
218 |
image := devImage. |
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
219 |
]. |
1694 | 220 |
]. |
221 |
self clear. |
|
222 |
self invalidate |
|
223 |
]. |
|
224 |
]. |
|
1763
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
225 |
self changed:#image. |
1694 | 226 |
] |
227 |
||
228 |
"Modified: / 10.2.2000 / 23:25:51 / cg" |
|
229 |
! ! |
|
230 |
||
231 |
!ImageView methodsFor:'accessing channels'! |
|
1510
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
232 |
|
1694 | 233 |
imageChannel |
234 |
imageChannel isNil ifTrue:[ |
|
235 |
imageChannel := ValueHolder new. |
|
236 |
imageChannel addDependent:self. |
|
237 |
]. |
|
238 |
^ imageChannel |
|
239 |
||
240 |
"Created: / 11.2.2000 / 00:34:44 / cg" |
|
241 |
! |
|
242 |
||
243 |
imageChannel:aValueHolder |
|
244 |
imageChannel notNil ifTrue:[ |
|
245 |
imageChannel removeDependent:self. |
|
161 | 246 |
]. |
1694 | 247 |
imageChannel := aValueHolder. |
248 |
imageChannel notNil ifTrue:[ |
|
249 |
imageChannel addDependent:self. |
|
250 |
]. |
|
251 |
||
252 |
"Created: / 11.2.2000 / 00:34:33 / cg" |
|
253 |
! ! |
|
1135
75101bf02c5b
send contentsChanged notifications before, to avoid
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
254 |
|
1694 | 255 |
!ImageView methodsFor:'change & update'! |
256 |
||
257 |
update:something with:aParameter from:changedObject |
|
258 |
something == imageChannel ifTrue:[ |
|
259 |
self image:(imageChannel value). |
|
260 |
^ self |
|
261 |
]. |
|
262 |
super update:something with:aParameter from:changedObject |
|
263 |
||
264 |
"Created: / 11.2.2000 / 00:37:02 / cg" |
|
1 | 265 |
! ! |
266 |
||
267 |
!ImageView methodsFor:'drawing'! |
|
268 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
269 |
redrawX:x y:y width:w height:h |
1763
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
270 |
|xI yI depth ext imgWidth imgHeight right bott devImage| |
11 | 271 |
|
1 | 272 |
image notNil ifTrue:[ |
635 | 273 |
imgWidth := image width. |
274 |
imgHeight := image height. |
|
275 |
||
414 | 276 |
adjust == #center ifTrue:[ |
635 | 277 |
xI := (width - (margin * 2) - imgWidth) // 2. |
278 |
yI := (height - (margin * 2) - imgHeight) // 2. |
|
414 | 279 |
] ifFalse:[ |
280 |
xI := yI := margin |
|
281 |
]. |
|
282 |
||
283 |
((depth := image depth) == 1) ifTrue:[ |
|
284 |
self paint:(image colorFromValue:1) |
|
285 |
on:(image colorFromValue:0). |
|
286 |
]. |
|
287 |
||
1510
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
288 |
Object errorSignal handle:[:ex | |
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
289 |
Transcript showCR:'cannot convert image'. |
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
290 |
^ self. |
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
291 |
] do:[ |
1763
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
292 |
devImage := image onDevice:device. |
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
293 |
devImage ~~ image ifTrue:[ |
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
294 |
image := devImage. |
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
295 |
self changed:#image. |
7d6d64622ee4
change & updates fixed (monochrome bitmaps)
Claus Gittinger <cg@exept.de>
parents:
1694
diff
changeset
|
296 |
]. |
1510
fd0cd6065dc6
catch image conversion errors.
Claus Gittinger <cg@exept.de>
parents:
1327
diff
changeset
|
297 |
]. |
1071
981c97fe54de
generate device image before clearing in redraw
Claus Gittinger <cg@exept.de>
parents:
677
diff
changeset
|
298 |
|
677 | 299 |
(depth == 1 |
300 |
and:[image mask isNil]) ifFalse:[ |
|
414 | 301 |
self clearRectangleX:x y:y width:w height:h. |
302 |
self displayForm:image x:xI y:yI |
|
677 | 303 |
] ifTrue:[ |
414 | 304 |
self displayOpaqueForm:image x:xI y:yI |
430 | 305 |
]. |
306 |
||
307 |
"/ right of image ? |
|
635 | 308 |
right := x + w - 1. |
309 |
right > (xI + imgWidth) ifTrue:[ |
|
310 |
self clearRectangleX:(xI + imgWidth) |
|
430 | 311 |
y:y |
635 | 312 |
width:(right - imgWidth - xI) |
430 | 313 |
height:h |
314 |
]. |
|
315 |
"/ below of image ? |
|
635 | 316 |
bott := y + h - 1. |
317 |
bott > (yI + imgHeight) ifTrue:[ |
|
430 | 318 |
self clearRectangleX:margin |
635 | 319 |
y:(yI + imgHeight) |
430 | 320 |
width:w |
635 | 321 |
height:(bott - imgHeight - yI) |
430 | 322 |
]. |
1 | 323 |
] |
89 | 324 |
|
635 | 325 |
"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
|
326 |
"Modified: / 12.8.1998 / 14:02:28 / cg" |
1 | 327 |
! ! |
328 |
||
1327 | 329 |
!ImageView methodsFor:'initialize / release'! |
330 |
||
331 |
destroy |
|
332 |
image := nil. |
|
333 |
super destroy. |
|
334 |
! ! |
|
335 |
||
161 | 336 |
!ImageView methodsFor:'queries'! |
24 | 337 |
|
161 | 338 |
heightOfContents |
339 |
"return the images height - scrollbar needs this info" |
|
1 | 340 |
|
161 | 341 |
image isNil ifTrue:[^ 0]. |
342 |
^ image height |
|
89 | 343 |
! |
344 |
||
1 | 345 |
widthOfContents |
346 |
"return the images width - scrollbar needs this info" |
|
347 |
||
348 |
image isNil ifTrue:[^ 0]. |
|
349 |
^ image width |
|
161 | 350 |
! ! |
351 |
||
257 | 352 |
!ImageView class methodsFor:'documentation'! |
161 | 353 |
|
354 |
version |
|
1764 | 355 |
^ '$Header: /cvs/stx/stx/libwidg2/ImageView.st,v 1.42 2000-04-19 11:18:03 cg Exp $' |
1 | 356 |
! ! |