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
|
24
|
14 |
instanceVariableNames:'image'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Misc'
|
1
|
18 |
!
|
|
19 |
|
26
|
20 |
!ImageView class methodsFor:'documentation'!
|
|
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 |
|
1
|
58 |
!ImageView class methodsFor:'startup'!
|
|
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:[
|
|
68 |
e := 'unknown image format'
|
|
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 |
|
|
162 |
!ImageView methodsFor:'release'!
|
|
163 |
|
|
164 |
destroy
|
|
165 |
image := nil.
|
|
166 |
super destroy.
|
|
167 |
! !
|
|
168 |
|
|
169 |
!ImageView methodsFor:'drawing'!
|
|
170 |
|
|
171 |
redraw
|
11
|
172 |
|clrMap|
|
|
173 |
|
1
|
174 |
image notNil ifTrue:[
|
24
|
175 |
image := image on:device.
|
|
176 |
self clear.
|
|
177 |
(image depth == 1) ifTrue:[
|
|
178 |
clrMap := image colorMap.
|
|
179 |
clrMap notNil ifTrue:[
|
|
180 |
self paint:(clrMap at:2) on:(clrMap at:1).
|
|
181 |
] ifFalse:[
|
|
182 |
self paint:Color black on:Color white.
|
|
183 |
]
|
|
184 |
].
|
46
|
185 |
self displayOpaqueForm:image x:0 y:0
|
1
|
186 |
]
|
|
187 |
! !
|
|
188 |
|
|
189 |
!ImageView methodsFor:'accessing'!
|
|
190 |
|
|
191 |
image:anImage
|
|
192 |
"set the image - show a wait cursor, since image dithering may take a while"
|
|
193 |
|
|
194 |
image := anImage.
|
7
|
195 |
anImage notNil ifTrue:[
|
24
|
196 |
self cursor:Cursor wait.
|
|
197 |
shown ifTrue:[
|
|
198 |
self redraw
|
|
199 |
].
|
|
200 |
self contentsChanged.
|
|
201 |
self cursor:(Cursor normal).
|
1
|
202 |
].
|
|
203 |
|
24
|
204 |
"
|
|
205 |
ImageView new realize image:(Image fromFile:'bitmaps/claus.gif')
|
|
206 |
|
|
207 |
|f|
|
|
208 |
f := Image fromFile:'bitmaps/SBrowser.xbm'.
|
|
209 |
f colorMap:(Array with:Color red with:Color yellow).
|
|
210 |
ImageView new realize image:f
|
|
211 |
"
|
1
|
212 |
!
|
|
213 |
|
|
214 |
image
|
|
215 |
"return the image"
|
|
216 |
|
|
217 |
^ image
|
|
218 |
! !
|
|
219 |
|
|
220 |
!ImageView methodsFor:'queries'!
|
|
221 |
|
|
222 |
widthOfContents
|
|
223 |
"return the images width - scrollbar needs this info"
|
|
224 |
|
|
225 |
image isNil ifTrue:[^ 0].
|
|
226 |
^ image width
|
|
227 |
!
|
|
228 |
|
|
229 |
heightOfContents
|
|
230 |
"return the images height - scrollbar needs this info"
|
|
231 |
|
|
232 |
image isNil ifTrue:[^ 0].
|
|
233 |
^ image height
|
|
234 |
! !
|