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 |
|
24
|
24 |
$Header: /cvs/stx/stx/libwidg2/ImageView.st,v 1.5 1994-10-10 03:13:21 claus Exp $
|
1
|
25 |
'!
|
|
26 |
|
|
27 |
!ImageView class methodsFor:'startup'!
|
|
28 |
|
11
|
29 |
openOn:aFileName
|
1
|
30 |
"startup an image viewer"
|
|
31 |
|
7
|
32 |
|top v imageView img icnW icnH icn magX magY mag wg|
|
1
|
33 |
|
|
34 |
top := StandardSystemView label:aFileName.
|
7
|
35 |
top iconLabel:aFileName asFilename baseName.
|
1
|
36 |
|
|
37 |
v := HVScrollableView for:self in:top.
|
|
38 |
v origin:0@0 extent:1.0@1.0.
|
|
39 |
imageView := v scrolledView.
|
|
40 |
|
7
|
41 |
img := Image fromFile:aFileName.
|
|
42 |
img notNil ifTrue:[
|
24
|
43 |
imageView image:img.
|
7
|
44 |
|
24
|
45 |
"define an icon view showing little version of image.
|
|
46 |
Since some window managers cannot handle this correctly (twm),
|
|
47 |
this is only done when running on an IRIS"
|
7
|
48 |
|
24
|
49 |
(true "(OperatingSystem getSystemType = 'iris')" and:[self defaultStyle == #iris]) ifTrue:[
|
|
50 |
icn := self new.
|
7
|
51 |
|
24
|
52 |
"for now; should somehow get access to preferred iconview extent ..."
|
|
53 |
icnW := 86.
|
|
54 |
icnH := 68.
|
7
|
55 |
|
24
|
56 |
((img width <= icnW) and:[img height <= icnH]) ifTrue:[
|
|
57 |
icn extent:(img width @ img height).
|
|
58 |
mag := 1 @ 1
|
|
59 |
] ifFalse:[
|
|
60 |
magX := icnW / img width.
|
|
61 |
magY := icnH / img height.
|
7
|
62 |
|
24
|
63 |
"scale image"
|
7
|
64 |
"
|
24
|
65 |
mag := magX @ magY.
|
7
|
66 |
"
|
24
|
67 |
"preserve ratio"
|
7
|
68 |
"
|
24
|
69 |
mag := (magX min:magY) asPoint.
|
7
|
70 |
"
|
|
71 |
" "
|
24
|
72 |
mag := (magX max:magY) asPoint.
|
7
|
73 |
" "
|
|
74 |
|
24
|
75 |
icn extent:((img width @ img height) * mag) rounded.
|
|
76 |
].
|
|
77 |
"start icon as a low prio bg process -
|
|
78 |
so magnification and color allocation will not hurt us ..."
|
7
|
79 |
|
24
|
80 |
ProcessorScheduler isPureEventDriven ifFalse:[
|
|
81 |
wg := WindowGroup new.
|
|
82 |
icn windowGroup:wg.
|
|
83 |
wg addTopView:icn.
|
|
84 |
wg startup.
|
|
85 |
wg process priority:4.
|
|
86 |
].
|
|
87 |
top iconView:icn.
|
|
88 |
].
|
7
|
89 |
].
|
|
90 |
|
|
91 |
top open.
|
|
92 |
|
|
93 |
icn notNil ifTrue:[
|
24
|
94 |
[
|
|
95 |
icn image:(img magnifyBy:mag).
|
|
96 |
] forkAt:4
|
7
|
97 |
].
|
1
|
98 |
|
11
|
99 |
"ImageView openOn:'bitmaps/garfield.gif'"
|
1
|
100 |
! !
|
|
101 |
|
|
102 |
!ImageView class methodsFor:'documentation'!
|
|
103 |
|
|
104 |
documentation
|
|
105 |
"
|
|
106 |
This View knows how to display an image (or form).
|
|
107 |
|
|
108 |
You can display an image with:
|
|
109 |
|
24
|
110 |
(ImageView new image:anImage) realize
|
1
|
111 |
|
24
|
112 |
i.e.
|
1
|
113 |
|
24
|
114 |
(ImageView new image:(Image fromFile:''bitmaps/garfield.gif'')) realize
|
|
115 |
(ImageView new image:(Image fromFile:''bitmaps/dano.tiff'')) realize
|
|
116 |
(ImageView new image:(Form fromFile:''SBrowser.xbm'')) realize
|
1
|
117 |
|
24
|
118 |
or simply by:
|
1
|
119 |
|
24
|
120 |
ImageView startOn:''bitmaps/garfield.gif''
|
1
|
121 |
|
|
122 |
"
|
|
123 |
! !
|
|
124 |
|
|
125 |
!ImageView methodsFor:'release'!
|
|
126 |
|
|
127 |
destroy
|
|
128 |
image := nil.
|
|
129 |
super destroy.
|
|
130 |
! !
|
|
131 |
|
|
132 |
!ImageView methodsFor:'drawing'!
|
|
133 |
|
|
134 |
redraw
|
11
|
135 |
|clrMap|
|
|
136 |
|
1
|
137 |
image notNil ifTrue:[
|
24
|
138 |
image := image on:device.
|
|
139 |
self clear.
|
|
140 |
(image depth == 1) ifTrue:[
|
|
141 |
clrMap := image colorMap.
|
|
142 |
clrMap notNil ifTrue:[
|
|
143 |
self paint:(clrMap at:2) on:(clrMap at:1).
|
|
144 |
] ifFalse:[
|
|
145 |
self paint:Color black on:Color white.
|
|
146 |
]
|
|
147 |
].
|
|
148 |
self displayOpaqueForm:image x:(0 - viewOrigin x) y:(0 - viewOrigin y)
|
1
|
149 |
]
|
|
150 |
! !
|
|
151 |
|
|
152 |
!ImageView methodsFor:'accessing'!
|
|
153 |
|
|
154 |
image:anImage
|
|
155 |
"set the image - show a wait cursor, since image dithering may take a while"
|
|
156 |
|
|
157 |
image := anImage.
|
7
|
158 |
anImage notNil ifTrue:[
|
24
|
159 |
self cursor:Cursor wait.
|
|
160 |
shown ifTrue:[
|
|
161 |
self redraw
|
|
162 |
].
|
|
163 |
self contentsChanged.
|
|
164 |
self cursor:(Cursor normal).
|
1
|
165 |
].
|
|
166 |
|
24
|
167 |
"
|
|
168 |
ImageView new realize image:(Image fromFile:'bitmaps/claus.gif')
|
|
169 |
|
|
170 |
|f|
|
|
171 |
f := Image fromFile:'bitmaps/SBrowser.xbm'.
|
|
172 |
f colorMap:(Array with:Color red with:Color yellow).
|
|
173 |
ImageView new realize image:f
|
|
174 |
"
|
1
|
175 |
!
|
|
176 |
|
|
177 |
image
|
|
178 |
"return the image"
|
|
179 |
|
|
180 |
^ image
|
|
181 |
! !
|
|
182 |
|
|
183 |
!ImageView methodsFor:'queries'!
|
|
184 |
|
|
185 |
widthOfContents
|
|
186 |
"return the images width - scrollbar needs this info"
|
|
187 |
|
|
188 |
image isNil ifTrue:[^ 0].
|
|
189 |
^ image width
|
|
190 |
!
|
|
191 |
|
|
192 |
heightOfContents
|
|
193 |
"return the images height - scrollbar needs this info"
|
|
194 |
|
|
195 |
image isNil ifTrue:[^ 0].
|
|
196 |
^ image height
|
|
197 |
! !
|