author | tz |
Fri, 23 Jan 1998 14:21:15 +0100 | |
changeset 677 | 5ad4237e7686 |
parent 675 | 2e07033e9972 |
child 1071 | 981c97fe54de |
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 |
|
599 | 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 |
|
599 | 92 |
"Modified: / 31.10.1997 / 16:17:52 / cg" |
47 | 93 |
! |
94 |
||
95 |
openOnImage:anImage |
|
96 |
"startup an image viewer on an image" |
|
1 | 97 |
|
635 | 98 |
|top v imageView icnW icnH iconView magX magY mag lbl imgWidth imgHeight| |
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:[ |
|
599 | 120 |
iconView := ImageView new. |
7 | 121 |
|
353 | 122 |
"for now; should somehow get access to preferred iconview extent ..." |
123 |
icnW := 86. |
|
599 | 124 |
icnH := 68. |
7 | 125 |
|
635 | 126 |
imgWidth := anImage width. |
127 |
imgHeight := anImage height. |
|
128 |
||
129 |
((imgWidth <= icnW) and:[imgHeight <= icnH]) ifTrue:[ |
|
130 |
iconView extent:(imgWidth @ imgHeight). |
|
353 | 131 |
mag := 1 @ 1 |
132 |
] ifFalse:[ |
|
635 | 133 |
magX := icnW / imgWidth. |
134 |
magY := icnH / imgHeight. |
|
7 | 135 |
|
353 | 136 |
"scale image" |
7 | 137 |
" |
353 | 138 |
mag := magX @ magY. |
7 | 139 |
" |
353 | 140 |
"preserve ratio" |
7 | 141 |
" |
353 | 142 |
mag := (magX min:magY) asPoint. |
7 | 143 |
" |
144 |
" " |
|
353 | 145 |
mag := (magX max:magY) asPoint. |
7 | 146 |
" " |
147 |
||
353 | 148 |
iconView extent:((anImage width @ anImage height) * mag) rounded. |
149 |
]. |
|
7 | 150 |
|
353 | 151 |
top iconView:iconView. |
152 |
]. |
|
7 | 153 |
]. |
154 |
||
155 |
top open. |
|
156 |
||
26 | 157 |
iconView notNil ifTrue:[ |
353 | 158 |
top windowGroup addView:iconView. |
159 |
[ |
|
160 |
iconView image:(anImage magnifyBy:mag). |
|
161 |
] forkAt:4 |
|
7 | 162 |
]. |
353 | 163 |
^ imageView |
1 | 164 |
|
26 | 165 |
" |
353 | 166 |
ImageView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif') |
47 | 167 |
ImageView openOnImage:(Image fromFile:'bitmaps/SBrowser.xbm') |
26 | 168 |
" |
353 | 169 |
|
635 | 170 |
"Modified: / 18.12.1997 / 11:46:19 / cg" |
1 | 171 |
! ! |
172 |
||
161 | 173 |
!ImageView methodsFor:'accessing'! |
174 |
||
175 |
adjust:layoutSymbol |
|
176 |
"set the adjust (how the image is displayed); |
|
177 |
currently, only support #topLeft and #center" |
|
178 |
||
179 |
adjust := layoutSymbol |
|
180 |
! |
|
181 |
||
182 |
image |
|
183 |
"return the image" |
|
184 |
||
185 |
^ image |
|
186 |
! |
|
187 |
||
188 |
image:anImage |
|
189 |
"set the image - show a wait cursor, since image dithering may take a while" |
|
1 | 190 |
|
161 | 191 |
image := anImage. |
675 | 192 |
self cursor:Cursor wait. |
677 | 193 |
(image notNil and: [image device ~~ device]) |
194 |
ifTrue: |
|
195 |
[ |
|
196 |
image := image on:device |
|
197 |
]. |
|
198 |
shown |
|
199 |
ifTrue: |
|
200 |
[ |
|
675 | 201 |
self clear. |
202 |
self invalidate |
|
161 | 203 |
]. |
675 | 204 |
self contentsChanged. |
677 | 205 |
self cursor: Cursor normal |
1 | 206 |
! ! |
207 |
||
208 |
!ImageView methodsFor:'drawing'! |
|
209 |
||
210
1a3b06d71a03
faster redraw; care for margins
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
210 |
redrawX:x y:y width:w height:h |
635 | 211 |
|xI yI depth ext imgWidth imgHeight right bott| |
11 | 212 |
|
1 | 213 |
image notNil ifTrue:[ |
635 | 214 |
imgWidth := image width. |
215 |
imgHeight := image height. |
|
216 |
||
414 | 217 |
adjust == #center ifTrue:[ |
635 | 218 |
xI := (width - (margin * 2) - imgWidth) // 2. |
219 |
yI := (height - (margin * 2) - imgHeight) // 2. |
|
414 | 220 |
] ifFalse:[ |
221 |
xI := yI := margin |
|
222 |
]. |
|
223 |
||
224 |
((depth := image depth) == 1) ifTrue:[ |
|
225 |
self paint:(image colorFromValue:1) |
|
226 |
on:(image colorFromValue:0). |
|
227 |
]. |
|
228 |
||
677 | 229 |
(depth == 1 |
230 |
and:[image mask isNil]) ifFalse:[ |
|
414 | 231 |
self clearRectangleX:x y:y width:w height:h. |
232 |
self displayForm:image x:xI y:yI |
|
677 | 233 |
] ifTrue:[ |
414 | 234 |
self displayOpaqueForm:image x:xI y:yI |
430 | 235 |
]. |
236 |
||
237 |
"/ right of image ? |
|
635 | 238 |
right := x + w - 1. |
239 |
right > (xI + imgWidth) ifTrue:[ |
|
240 |
self clearRectangleX:(xI + imgWidth) |
|
430 | 241 |
y:y |
635 | 242 |
width:(right - imgWidth - xI) |
430 | 243 |
height:h |
244 |
]. |
|
245 |
"/ below of image ? |
|
635 | 246 |
bott := y + h - 1. |
247 |
bott > (yI + imgHeight) ifTrue:[ |
|
430 | 248 |
self clearRectangleX:margin |
635 | 249 |
y:(yI + imgHeight) |
430 | 250 |
width:w |
635 | 251 |
height:(bott - imgHeight - yI) |
430 | 252 |
]. |
1 | 253 |
] |
89 | 254 |
|
635 | 255 |
"Created: / 11.7.1996 / 21:02:12 / cg" |
256 |
"Modified: / 18.12.1997 / 10:29:21 / cg" |
|
1 | 257 |
! ! |
258 |
||
161 | 259 |
!ImageView methodsFor:'queries'! |
24 | 260 |
|
161 | 261 |
heightOfContents |
262 |
"return the images height - scrollbar needs this info" |
|
1 | 263 |
|
161 | 264 |
image isNil ifTrue:[^ 0]. |
265 |
^ image height |
|
89 | 266 |
! |
267 |
||
1 | 268 |
widthOfContents |
269 |
"return the images width - scrollbar needs this info" |
|
270 |
||
271 |
image isNil ifTrue:[^ 0]. |
|
272 |
^ image width |
|
161 | 273 |
! ! |
274 |
||
275 |
!ImageView methodsFor:'release'! |
|
1 | 276 |
|
161 | 277 |
destroy |
278 |
image := nil. |
|
279 |
super destroy. |
|
280 |
! ! |
|
1 | 281 |
|
257 | 282 |
!ImageView class methodsFor:'documentation'! |
161 | 283 |
|
284 |
version |
|
677 | 285 |
^ '$Header: /cvs/stx/stx/libwidg2/ImageView.st,v 1.35 1998-01-23 13:21:15 tz Exp $' |
1 | 286 |
! ! |