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