author | Claus Gittinger <cg@exept.de> |
Thu, 10 Apr 1997 17:51:10 +0200 | |
changeset 353 | 0442fc169b82 |
parent 348 | 58d52a823cca |
child 414 | 0347d494cd61 |
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 |
||
296 | 13 |
View 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 |
||
296 | 42 |
ImageView openOn:anImageFileName |
26 | 43 |
or: |
296 | 44 |
ImageView openOnImage:anImage |
47 | 45 |
or: |
296 | 46 |
ImageView new image:anImage |
26 | 47 |
|
48 |
i.e. |
|
49 |
||
353 | 50 |
ImageView openOn:'bitmaps/gifImages/garfield.gif' |
296 | 51 |
ImageView openOn:'bitmaps/SBrowser.xbm' |
52 |
||
353 | 53 |
ImageView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif') |
296 | 54 |
ImageView openOnImage:(Image fromFile:'bitmaps/SBrowser.xbm') |
26 | 55 |
|
296 | 56 |
[author:] |
57 |
Claus Gittinger |
|
58 |
||
59 |
[see also:] |
|
60 |
Image Form |
|
26 | 61 |
" |
62 |
! ! |
|
63 |
||
257 | 64 |
!ImageView class methodsFor:'startup'! |
1 | 65 |
|
11 | 66 |
openOn:aFileName |
47 | 67 |
"startup an image viewer on an image read from a file" |
68 |
||
353 | 69 |
|imageView img e| |
47 | 70 |
|
71 |
img := Image fromFile:aFileName. |
|
72 |
img isNil ifTrue:[ |
|
348 | 73 |
aFileName asFilename exists ifTrue:[ |
74 |
e := 'unknown/unsupported image format' |
|
75 |
] ifFalse:[ |
|
76 |
e := 'no such image'. |
|
77 |
]. |
|
78 |
self warn:e. |
|
79 |
^ nil |
|
47 | 80 |
]. |
353 | 81 |
imageView := self openOnImage:img. |
47 | 82 |
|
353 | 83 |
imageView topView label:aFileName iconLabel:aFileName asFilename baseName. |
47 | 84 |
|
353 | 85 |
^ imageView |
1 | 86 |
|
47 | 87 |
" |
353 | 88 |
ImageView openOn:'bitmaps/gifImages/garfield.gif' |
89 |
ImageView openOn:'bitmaps/xpmBitmaps/BOOK.xpm' |
|
47 | 90 |
" |
348 | 91 |
|
353 | 92 |
"Modified: 10.4.1997 / 17:29:11 / cg" |
47 | 93 |
! |
94 |
||
95 |
openOnImage:anImage |
|
96 |
"startup an image viewer on an image" |
|
1 | 97 |
|
64 | 98 |
|top v imageView icnW icnH iconView magX magY mag lbl| |
47 | 99 |
|
100 |
anImage isImage ifTrue:[ |
|
353 | 101 |
lbl := 'an Image' |
47 | 102 |
] ifFalse:[ |
353 | 103 |
lbl := 'a Form' |
47 | 104 |
]. |
105 |
top := StandardSystemView label:lbl. |
|
1 | 106 |
|
107 |
v := HVScrollableView for:self in:top. |
|
108 |
v origin:0@0 extent:1.0@1.0. |
|
109 |
imageView := v scrolledView. |
|
110 |
||
47 | 111 |
anImage notNil ifTrue:[ |
353 | 112 |
imageView image:anImage. |
7 | 113 |
|
353 | 114 |
"define an icon view showing a little version of image. |
115 |
Since some window managers cannot handle this correctly (twm), |
|
116 |
this is only done when running on an IRIS" |
|
7 | 117 |
|
353 | 118 |
(true "(OperatingSystem getSystemType = 'iris')" |
119 |
and:[StyleSheet name == #iris]) ifTrue:[ |
|
120 |
iconView := self new. |
|
7 | 121 |
|
353 | 122 |
"for now; should somehow get access to preferred iconview extent ..." |
123 |
icnW := 86. |
|
124 |
icnH := 68. |
|
7 | 125 |
|
353 | 126 |
((anImage width <= icnW) and:[anImage height <= icnH]) ifTrue:[ |
127 |
iconView extent:(anImage width @ anImage height). |
|
128 |
mag := 1 @ 1 |
|
129 |
] ifFalse:[ |
|
130 |
magX := icnW / anImage width. |
|
131 |
magY := icnH / anImage height. |
|
7 | 132 |
|
353 | 133 |
"scale image" |
7 | 134 |
" |
353 | 135 |
mag := magX @ magY. |
7 | 136 |
" |
353 | 137 |
"preserve ratio" |
7 | 138 |
" |
353 | 139 |
mag := (magX min:magY) asPoint. |
7 | 140 |
" |
141 |
" " |
|
353 | 142 |
mag := (magX max:magY) asPoint. |
7 | 143 |
" " |
144 |
||
353 | 145 |
iconView extent:((anImage width @ anImage height) * mag) rounded. |
146 |
]. |
|
7 | 147 |
|
353 | 148 |
top iconView:iconView. |
149 |
]. |
|
7 | 150 |
]. |
151 |
||
152 |
top open. |
|
153 |
||
26 | 154 |
iconView notNil ifTrue:[ |
353 | 155 |
top windowGroup addView:iconView. |
156 |
[ |
|
157 |
iconView image:(anImage magnifyBy:mag). |
|
158 |
] forkAt:4 |
|
7 | 159 |
]. |
353 | 160 |
^ imageView |
1 | 161 |
|
26 | 162 |
" |
353 | 163 |
ImageView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif') |
47 | 164 |
ImageView openOnImage:(Image fromFile:'bitmaps/SBrowser.xbm') |
26 | 165 |
" |
353 | 166 |
|
167 |
"Modified: 10.4.1997 / 17:30:02 / cg" |
|
1 | 168 |
! ! |
169 |
||
161 | 170 |
!ImageView methodsFor:'accessing'! |
171 |
||
172 |
adjust:layoutSymbol |
|
173 |
"set the adjust (how the image is displayed); |
|
174 |
currently, only support #topLeft and #center" |
|
175 |
||
176 |
adjust := layoutSymbol |
|
177 |
! |
|
178 |
||
179 |
image |
|
180 |
"return the image" |
|
181 |
||
182 |
^ image |
|
183 |
! |
|
184 |
||
185 |
image:anImage |
|
186 |
"set the image - show a wait cursor, since image dithering may take a while" |
|
1 | 187 |
|
161 | 188 |
image := anImage. |
189 |
anImage notNil ifTrue:[ |
|
324
993b24b769ef
clear when displaying new image
Claus Gittinger <cg@exept.de>
parents:
296
diff
changeset
|
190 |
self cursor:Cursor wait. |
993b24b769ef
clear when displaying new image
Claus Gittinger <cg@exept.de>
parents:
296
diff
changeset
|
191 |
shown ifTrue:[ |
993b24b769ef
clear when displaying new image
Claus Gittinger <cg@exept.de>
parents:
296
diff
changeset
|
192 |
self clear. |
993b24b769ef
clear when displaying new image
Claus Gittinger <cg@exept.de>
parents:
296
diff
changeset
|
193 |
self invalidate |
993b24b769ef
clear when displaying new image
Claus Gittinger <cg@exept.de>
parents:
296
diff
changeset
|
194 |
]. |
993b24b769ef
clear when displaying new image
Claus Gittinger <cg@exept.de>
parents:
296
diff
changeset
|
195 |
self contentsChanged. |
993b24b769ef
clear when displaying new image
Claus Gittinger <cg@exept.de>
parents:
296
diff
changeset
|
196 |
self cursor:(Cursor normal). |
161 | 197 |
]. |
198 |
||
199 |
" |
|
200 |
ImageView new realize image:(Image fromFile:'bitmaps/claus.gif') |
|
201 |
||
202 |
|f| |
|
203 |
f := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
204 |
f colorMap:(Array with:Color red with:Color yellow). |
|
205 |
ImageView new realize image:f |
|
206 |
" |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
207 |
|
324
993b24b769ef
clear when displaying new image
Claus Gittinger <cg@exept.de>
parents:
296
diff
changeset
|
208 |
"Modified: 17.3.1997 / 12:13:30 / cg" |
1 | 209 |
! ! |
210 |
||
211 |
!ImageView methodsFor:'drawing'! |
|
212 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
213 |
redrawX:x y:y width:w height:h |
257 | 214 |
|xI yI depth ext| |
11 | 215 |
|
1 | 216 |
image notNil ifTrue:[ |
269 | 217 |
image device ~~ device ifTrue:[ |
218 |
self withWaitCursorDo:[ |
|
219 |
image := image on:device. |
|
220 |
] |
|
221 |
]. |
|
239
a0e97ba3d7f4
clear background when image has a mask; show waitCursor.
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
222 |
|
269 | 223 |
((depth := image depth) == 1) ifTrue:[ |
224 |
self paint:(image colorFromValue:1) |
|
225 |
on:(image colorFromValue:0). |
|
226 |
]. |
|
227 |
adjust == #center ifTrue:[ |
|
228 |
ext := image extent. |
|
229 |
xI := (width - (margin * 2) - (ext x)) // 2. |
|
230 |
yI := (height - (margin * 2) - (ext y)) // 2. |
|
231 |
] ifFalse:[ |
|
232 |
xI := yI := margin |
|
233 |
]. |
|
257 | 234 |
|
269 | 235 |
(depth ~~ 1 |
236 |
and:[image mask notNil]) ifTrue:[ |
|
237 |
self clearRectangleX:x y:y width:w height:h. |
|
238 |
self displayForm:image x:xI y:yI |
|
239 |
] ifFalse:[ |
|
240 |
self displayOpaqueForm:image x:xI y:yI |
|
241 |
] |
|
1 | 242 |
] |
89 | 243 |
|
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
244 |
"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
|
245 |
"Modified: 5.9.1996 / 11:55:19 / cg" |
1 | 246 |
! ! |
247 |
||
161 | 248 |
!ImageView methodsFor:'queries'! |
24 | 249 |
|
161 | 250 |
heightOfContents |
251 |
"return the images height - scrollbar needs this info" |
|
1 | 252 |
|
161 | 253 |
image isNil ifTrue:[^ 0]. |
254 |
^ image height |
|
89 | 255 |
! |
256 |
||
1 | 257 |
widthOfContents |
258 |
"return the images width - scrollbar needs this info" |
|
259 |
||
260 |
image isNil ifTrue:[^ 0]. |
|
261 |
^ image width |
|
161 | 262 |
! ! |
263 |
||
264 |
!ImageView methodsFor:'release'! |
|
1 | 265 |
|
161 | 266 |
destroy |
267 |
image := nil. |
|
268 |
super destroy. |
|
269 |
! ! |
|
1 | 270 |
|
257 | 271 |
!ImageView class methodsFor:'documentation'! |
161 | 272 |
|
273 |
version |
|
353 | 274 |
^ '$Header: /cvs/stx/stx/libwidg2/ImageView.st,v 1.29 1997-04-10 15:50:58 cg Exp $' |
1 | 275 |
! ! |