author | Claus Gittinger <cg@exept.de> |
Tue, 22 Oct 1996 17:58:43 +0200 | |
changeset 257 | 0acd4525d53e |
parent 239 | a0e97ba3d7f4 |
child 269 | 167651794a77 |
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 |
||
49 | 13 |
SimpleView subclass:#ImageView |
161 | 14 |
instanceVariableNames:'image adjust' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Views-Misc' |
|
1 | 18 |
! |
19 |
||
257 | 20 |
!ImageView class methodsFor:'documentation'! |
26 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
25 |
All Rights Reserved |
|
26 |
||
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
This View knows how to display an image (or form). |
|
39 |
||
40 |
You can display an image with: |
|
41 |
||
42 |
ImageView openOn:anImageFileName |
|
43 |
or: |
|
47 | 44 |
ImageView openOnImage:anImage |
45 |
or: |
|
26 | 46 |
ImageView new image:anImage |
47 |
||
48 |
i.e. |
|
49 |
||
50 |
ImageView openOn:'bitmaps/garfield.gif' |
|
51 |
ImageView openOn:'bitmaps/SBrowser.xbm' |
|
52 |
||
47 | 53 |
ImageView openOnImage:(Image fromFile:'bitmaps/garfield.gif') |
54 |
ImageView openOnImage:(Form fromFile:'SBrowser.xbm') |
|
26 | 55 |
" |
56 |
! ! |
|
57 |
||
257 | 58 |
!ImageView class methodsFor:'startup'! |
1 | 59 |
|
11 | 60 |
openOn:aFileName |
47 | 61 |
"startup an image viewer on an image read from a file" |
62 |
||
69 | 63 |
|top img e| |
47 | 64 |
|
65 |
img := Image fromFile:aFileName. |
|
66 |
img isNil ifTrue:[ |
|
69 | 67 |
aFileName asFilename exists ifTrue:[ |
77 | 68 |
e := 'unknown/unsupported image format' |
69 | 69 |
] ifFalse:[ |
70 |
e := 'no such image'. |
|
71 |
]. |
|
72 |
self warn:e. |
|
47 | 73 |
^ nil |
74 |
]. |
|
75 |
top := self openOnImage:img. |
|
76 |
||
77 |
top label:aFileName. |
|
78 |
top iconLabel:aFileName asFilename baseName. |
|
79 |
||
80 |
^ top |
|
1 | 81 |
|
47 | 82 |
" |
83 |
ImageView openOn:'bitmaps/garfield.gif' |
|
84 |
ImageView openOn:'/phys/porty/tmp/img.pcx' |
|
85 |
" |
|
86 |
! |
|
87 |
||
88 |
openOnImage:anImage |
|
89 |
"startup an image viewer on an image" |
|
1 | 90 |
|
64 | 91 |
|top v imageView icnW icnH iconView magX magY mag lbl| |
47 | 92 |
|
93 |
anImage isImage ifTrue:[ |
|
94 |
lbl := 'an Image' |
|
95 |
] ifFalse:[ |
|
96 |
lbl := 'a Form' |
|
97 |
]. |
|
98 |
top := StandardSystemView label:lbl. |
|
1 | 99 |
|
100 |
v := HVScrollableView for:self in:top. |
|
101 |
v origin:0@0 extent:1.0@1.0. |
|
102 |
imageView := v scrolledView. |
|
103 |
||
47 | 104 |
anImage notNil ifTrue:[ |
105 |
imageView image:anImage. |
|
7 | 106 |
|
26 | 107 |
"define an icon view showing a little version of image. |
24 | 108 |
Since some window managers cannot handle this correctly (twm), |
109 |
this is only done when running on an IRIS" |
|
7 | 110 |
|
26 | 111 |
(true "(OperatingSystem getSystemType = 'iris')" |
63 | 112 |
and:[StyleSheet name == #iris]) ifTrue:[ |
26 | 113 |
iconView := self new. |
7 | 114 |
|
24 | 115 |
"for now; should somehow get access to preferred iconview extent ..." |
116 |
icnW := 86. |
|
26 | 117 |
icnH := 68. |
7 | 118 |
|
47 | 119 |
((anImage width <= icnW) and:[anImage height <= icnH]) ifTrue:[ |
120 |
iconView extent:(anImage width @ anImage height). |
|
24 | 121 |
mag := 1 @ 1 |
122 |
] ifFalse:[ |
|
47 | 123 |
magX := icnW / anImage width. |
124 |
magY := icnH / anImage height. |
|
7 | 125 |
|
24 | 126 |
"scale image" |
7 | 127 |
" |
24 | 128 |
mag := magX @ magY. |
7 | 129 |
" |
24 | 130 |
"preserve ratio" |
7 | 131 |
" |
24 | 132 |
mag := (magX min:magY) asPoint. |
7 | 133 |
" |
134 |
" " |
|
24 | 135 |
mag := (magX max:magY) asPoint. |
7 | 136 |
" " |
137 |
||
47 | 138 |
iconView extent:((anImage width @ anImage height) * mag) rounded. |
24 | 139 |
]. |
7 | 140 |
|
26 | 141 |
top iconView:iconView. |
24 | 142 |
]. |
7 | 143 |
]. |
144 |
||
145 |
top open. |
|
146 |
||
26 | 147 |
iconView notNil ifTrue:[ |
148 |
top windowGroup addView:iconView. |
|
24 | 149 |
[ |
47 | 150 |
iconView image:(anImage magnifyBy:mag). |
24 | 151 |
] forkAt:4 |
7 | 152 |
]. |
47 | 153 |
^ top |
1 | 154 |
|
26 | 155 |
" |
47 | 156 |
ImageView openOnImage:(Image fromFile:'bitmaps/garfield.gif') |
157 |
ImageView openOnImage:(Image fromFile:'bitmaps/SBrowser.xbm') |
|
158 |
ImageView openOnImage:(Form fromFile:'bitmaps/SBrowser.xbm') |
|
26 | 159 |
" |
1 | 160 |
! ! |
161 |
||
161 | 162 |
!ImageView methodsFor:'accessing'! |
163 |
||
164 |
adjust:layoutSymbol |
|
165 |
"set the adjust (how the image is displayed); |
|
166 |
currently, only support #topLeft and #center" |
|
167 |
||
168 |
adjust := layoutSymbol |
|
169 |
! |
|
170 |
||
171 |
image |
|
172 |
"return the image" |
|
173 |
||
174 |
^ image |
|
175 |
! |
|
176 |
||
177 |
image:anImage |
|
178 |
"set the image - show a wait cursor, since image dithering may take a while" |
|
1 | 179 |
|
161 | 180 |
image := anImage. |
181 |
anImage notNil ifTrue:[ |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
182 |
self cursor:Cursor wait. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
183 |
shown ifTrue:[ |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
184 |
self invalidate |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
185 |
]. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
186 |
self contentsChanged. |
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
187 |
self cursor:(Cursor normal). |
161 | 188 |
]. |
189 |
||
190 |
" |
|
191 |
ImageView new realize image:(Image fromFile:'bitmaps/claus.gif') |
|
192 |
||
193 |
|f| |
|
194 |
f := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
195 |
f colorMap:(Array with:Color red with:Color yellow). |
|
196 |
ImageView new realize image:f |
|
197 |
" |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
198 |
|
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
199 |
"Modified: 11.7.1996 / 21:03:19 / cg" |
1 | 200 |
! ! |
201 |
||
202 |
!ImageView methodsFor:'drawing'! |
|
203 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
204 |
redrawX:x y:y width:w height:h |
257 | 205 |
|xI yI depth ext| |
11 | 206 |
|
1 | 207 |
image notNil ifTrue:[ |
239
a0e97ba3d7f4
clear background when image has a mask; show waitCursor.
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
208 |
image device ~~ device ifTrue:[ |
a0e97ba3d7f4
clear background when image has a mask; show waitCursor.
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
209 |
self withWaitCursorDo:[ |
a0e97ba3d7f4
clear background when image has a mask; show waitCursor.
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
210 |
image := image on:device. |
a0e97ba3d7f4
clear background when image has a mask; show waitCursor.
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
211 |
] |
a0e97ba3d7f4
clear background when image has a mask; show waitCursor.
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
212 |
]. |
a0e97ba3d7f4
clear background when image has a mask; show waitCursor.
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
213 |
|
257 | 214 |
((depth := image depth) == 1) ifTrue:[ |
205
96f80d06fe5a
oops - care for d1 images colors
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
215 |
self paint:(image colorFromValue:1) |
96f80d06fe5a
oops - care for d1 images colors
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
216 |
on:(image colorFromValue:0). |
96f80d06fe5a
oops - care for d1 images colors
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
217 |
]. |
96f80d06fe5a
oops - care for d1 images colors
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
218 |
adjust == #center ifTrue:[ |
257 | 219 |
ext := image extent. |
220 |
xI := (width - (margin * 2) - (ext x)) // 2. |
|
221 |
yI := (height - (margin * 2) - (ext y)) // 2. |
|
205
96f80d06fe5a
oops - care for d1 images colors
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
222 |
] ifFalse:[ |
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
223 |
xI := yI := margin |
205
96f80d06fe5a
oops - care for d1 images colors
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
224 |
]. |
257 | 225 |
|
226 |
(depth ~~ 1 |
|
207
ded60344752c
care for images mask (for now: only handled if not magnified)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
227 |
and:[image mask notNil]) ifTrue:[ |
239
a0e97ba3d7f4
clear background when image has a mask; show waitCursor.
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
228 |
self clearRectangleX:x y:y width:w height:h. |
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
229 |
self displayForm:image x:xI y:yI |
207
ded60344752c
care for images mask (for now: only handled if not magnified)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
230 |
] ifFalse:[ |
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
231 |
self displayOpaqueForm:image x:xI y:yI |
207
ded60344752c
care for images mask (for now: only handled if not magnified)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
232 |
] |
1 | 233 |
] |
89 | 234 |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
235 |
"Created: 11.7.1996 / 21:02:12 / cg" |
239
a0e97ba3d7f4
clear background when image has a mask; show waitCursor.
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
236 |
"Modified: 5.9.1996 / 11:55:19 / cg" |
1 | 237 |
! ! |
238 |
||
161 | 239 |
!ImageView methodsFor:'queries'! |
24 | 240 |
|
161 | 241 |
heightOfContents |
242 |
"return the images height - scrollbar needs this info" |
|
1 | 243 |
|
161 | 244 |
image isNil ifTrue:[^ 0]. |
245 |
^ image height |
|
89 | 246 |
! |
247 |
||
1 | 248 |
widthOfContents |
249 |
"return the images width - scrollbar needs this info" |
|
250 |
||
251 |
image isNil ifTrue:[^ 0]. |
|
252 |
^ image width |
|
161 | 253 |
! ! |
254 |
||
255 |
!ImageView methodsFor:'release'! |
|
1 | 256 |
|
161 | 257 |
destroy |
258 |
image := nil. |
|
259 |
super destroy. |
|
260 |
! ! |
|
1 | 261 |
|
257 | 262 |
!ImageView class methodsFor:'documentation'! |
161 | 263 |
|
264 |
version |
|
257 | 265 |
^ '$Header: /cvs/stx/stx/libwidg2/ImageView.st,v 1.24 1996-10-22 15:58:43 cg Exp $' |
1 | 266 |
! ! |