27
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
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 |
Ruler subclass:#VerticalRuler
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Misc'
|
|
18 |
!
|
|
19 |
|
|
20 |
VerticalRuler comment:'
|
|
21 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
|
22 |
All Rights Reserved
|
33
|
23 |
'!
|
27
|
24 |
|
33
|
25 |
!VerticalRuler class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
30 |
All Rights Reserved
|
27
|
31 |
|
33
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
27
|
40 |
|
33
|
41 |
version
|
|
42 |
"
|
|
43 |
$Header: /cvs/stx/stx/libwidg2/VerticalRuler.st,v 1.3 1994-12-21 19:25:09 claus Exp $
|
|
44 |
"
|
|
45 |
!
|
|
46 |
|
|
47 |
documentation
|
|
48 |
"
|
|
49 |
like a Ruler, but vertical.
|
|
50 |
see documentation in Ruler
|
|
51 |
"
|
|
52 |
! !
|
27
|
53 |
|
|
54 |
!VerticalRuler methodsFor:'accessing'!
|
|
55 |
|
|
56 |
paperHeightInch:inches
|
|
57 |
"set the width of the document"
|
|
58 |
|
|
59 |
paperHeight := inches.
|
|
60 |
shown ifTrue:[
|
|
61 |
self redraw
|
|
62 |
]
|
|
63 |
!
|
|
64 |
|
|
65 |
paperHeightMM:millis
|
|
66 |
"set the width of the document"
|
|
67 |
|
|
68 |
paperHeight := self millimeterToInch:millis.
|
|
69 |
shown ifTrue:[
|
|
70 |
self redraw
|
|
71 |
]
|
|
72 |
! !
|
|
73 |
|
|
74 |
!VerticalRuler methodsFor:'redrawing'!
|
|
75 |
|
|
76 |
redraw
|
28
|
77 |
"redraw the scale"
|
27
|
78 |
|
|
79 |
|y pixelPerMM pixelPerInch mod pos shortLen veryShortLen longLen charX
|
|
80 |
left paperHeightMM paperHeightPixel yOrigin labelBot marg fontHeight|
|
|
81 |
|
|
82 |
shown ifFalse:[^ self].
|
|
83 |
|
|
84 |
self clear.
|
|
85 |
|
|
86 |
yOrigin := self viewOrigin y.
|
|
87 |
|
|
88 |
paperHeightPixel := ((self inchToPixel:paperHeight) * scale) rounded.
|
|
89 |
|
|
90 |
(yOrigin + height > paperHeightPixel) ifTrue:[
|
|
91 |
self paint:(Color darkGrey).
|
|
92 |
self fillRectangleX:0 y:paperHeightPixel - yOrigin
|
|
93 |
width:width
|
|
94 |
height:(height - (paperHeightPixel - yOrigin)).
|
|
95 |
self paint:fgColor.
|
|
96 |
self displayLineFromX:0 y:paperHeightPixel - yOrigin
|
|
97 |
toX:width y:paperHeightPixel - yOrigin
|
|
98 |
].
|
|
99 |
|
|
100 |
self paint:fgColor.
|
|
101 |
|
|
102 |
left := 0. "width - (font widthOf:'WW')"
|
|
103 |
longLen := font widthOf:'WW'.
|
|
104 |
shortLen := longLen // 2.
|
|
105 |
charX := left + shortLen.
|
|
106 |
mod := 1.
|
|
107 |
marg := 3. "character shift"
|
|
108 |
fontHeight := font height.
|
|
109 |
|
|
110 |
(metric == #mm) ifTrue:[
|
|
111 |
"centimeter - long blibs every centimeter; short ones every half"
|
|
112 |
|
|
113 |
paperHeightMM := self inchToMillimeter:paperHeight.
|
|
114 |
pixelPerMM := (self millimeterToPixel:1) * scale.
|
|
115 |
pos := 5.
|
33
|
116 |
showUnit ifTrue:[
|
|
117 |
labelBot := marg + font height + font ascent.
|
|
118 |
] ifFalse:[
|
|
119 |
labelBot := 0
|
|
120 |
].
|
27
|
121 |
y := (pixelPerMM * pos - yOrigin) rounded.
|
|
122 |
[(y < height) and:[pos <= paperHeightMM]] whileTrue:[
|
28
|
123 |
|l|
|
|
124 |
|
|
125 |
l := shortLen.
|
|
126 |
(mod ~~ 1) ifTrue:[
|
27
|
127 |
y < labelBot ifFalse:[
|
28
|
128 |
l := longLen
|
27
|
129 |
]
|
|
130 |
].
|
28
|
131 |
self displayLineFromX:left y:y toX:(left + l) y:y.
|
|
132 |
|
|
133 |
(mod ~~ 1 and:[y >= labelBot]) ifTrue:[
|
|
134 |
self displayString:(pos // 10) printString
|
|
135 |
x:charX
|
|
136 |
y:(y + marg + fontHeight)
|
|
137 |
].
|
27
|
138 |
mod := (mod + 1) \\ 2.
|
|
139 |
pos := pos + 5.
|
|
140 |
y := (pixelPerMM * pos - yOrigin) rounded
|
|
141 |
].
|
33
|
142 |
showUnit ifTrue:[
|
|
143 |
self displayString:'cm ' x:charX y:marg + fontHeight.
|
|
144 |
]
|
27
|
145 |
].
|
|
146 |
(metric == #inch) ifTrue:[
|
|
147 |
"inches - long blibs every inch; short ones every half; very
|
|
148 |
short ones every quarter"
|
|
149 |
|
|
150 |
pixelPerInch := (self inchToPixel:1) * scale.
|
|
151 |
pos := 0.25.
|
33
|
152 |
showUnit ifTrue:[
|
|
153 |
labelBot := marg + (font height + font ascent).
|
|
154 |
] ifFalse:[
|
|
155 |
labelBot := 0
|
|
156 |
].
|
27
|
157 |
|
|
158 |
y := (pixelPerInch * pos - yOrigin) rounded.
|
|
159 |
veryShortLen := longLen // 4.
|
|
160 |
[(y < height) and:[pos <= paperHeight]] whileTrue:[
|
28
|
161 |
|l|
|
|
162 |
|
|
163 |
l := shortLen.
|
27
|
164 |
(mod == 0) ifTrue:[
|
|
165 |
y < labelBot ifFalse:[
|
28
|
166 |
l := longLen.
|
|
167 |
]
|
|
168 |
] ifFalse:[
|
|
169 |
(mod == 2) ifFalse:[
|
|
170 |
l := veryShortLen
|
|
171 |
]
|
|
172 |
].
|
|
173 |
self displayLineFromX:left y:y toX:(left + l) y:y.
|
|
174 |
|
|
175 |
(mod == 0) ifTrue:[
|
|
176 |
y < labelBot ifFalse:[
|
27
|
177 |
self displayString:pos asInteger printString
|
|
178 |
x:charX
|
|
179 |
y:(y + marg + fontHeight)
|
|
180 |
]
|
|
181 |
].
|
|
182 |
mod := (mod + 1) \\ 4.
|
|
183 |
pos := pos + 0.25.
|
|
184 |
y := (pixelPerInch * pos - yOrigin) rounded
|
|
185 |
].
|
33
|
186 |
showUnit ifTrue:[
|
|
187 |
self displayString:'inch ' x:charX y:marg + fontHeight.
|
|
188 |
]
|
27
|
189 |
].
|
|
190 |
self redrawEdges
|
|
191 |
! !
|
|
192 |
|
|
193 |
!VerticalRuler methodsFor:'initialization'!
|
|
194 |
|
|
195 |
initialize
|
|
196 |
super initialize.
|
|
197 |
|
|
198 |
self width:(font widthOf:'inch').
|
|
199 |
|
|
200 |
"
|
|
201 |
VerticalRuler new open
|
|
202 |
"
|
|
203 |
! !
|
|
204 |
|