21 COPYRIGHT (c) 1991 by Claus Gittinger |
21 COPYRIGHT (c) 1991 by Claus Gittinger |
22 All Rights Reserved |
22 All Rights Reserved |
23 |
23 |
24 a Ruler for page layout. |
24 a Ruler for page layout. |
25 |
25 |
26 $Header: /cvs/stx/stx/libwidg2/Ruler.st,v 1.8 1994-11-17 14:42:26 claus Exp $ |
26 $Header: /cvs/stx/stx/libwidg2/Ruler.st,v 1.9 1994-11-21 16:49:32 claus Exp $ |
27 |
27 |
28 written oct 91 by claus |
28 written oct 91 by claus |
29 '! |
29 '! |
30 |
30 |
31 !Ruler methodsFor:'accessing'! |
31 !Ruler methodsFor:'accessing'! |
71 ! |
71 ! |
72 |
72 |
73 viewOrigin:origin |
73 viewOrigin:origin |
74 super setViewOrigin:origin. |
74 super setViewOrigin:origin. |
75 self redraw |
75 self redraw |
|
76 ! |
|
77 |
|
78 widthOfContents |
|
79 ^ (device horizontalPixelPerInch * paperWidth) rounded |
|
80 ! |
|
81 |
|
82 heightOfContents |
|
83 ^ (device verticalPixelPerInch * paperHeight) rounded |
76 ! ! |
84 ! ! |
77 |
85 |
78 !Ruler methodsFor:'redrawing'! |
86 !Ruler methodsFor:'redrawing'! |
79 |
87 |
80 redraw |
88 redraw |
81 "redraw scale" |
89 "redraw the scale" |
82 |
90 |
83 |x pixelPerMM pixelPerInch mod pos shortLen veryShortLen longLen charY |
91 |x pixelPerMM pixelPerInch mod pos shortLen veryShortLen longLen charY |
84 top paperWidthMM paperWidthPixel xOrigin labelRight stringRight marg| |
92 top paperWidthMM paperWidthPixel xOrigin labelRight stringRight marg| |
85 |
93 |
86 shown ifFalse:[^ self]. |
94 shown ifFalse:[^ self]. |
87 |
95 |
88 "/ self fill:viewBackground. |
|
89 self clear. |
96 self clear. |
90 |
97 |
91 xOrigin := self viewOrigin x. |
98 xOrigin := self viewOrigin x. |
92 |
99 |
93 paperWidthPixel := ((self inchToPixel:paperWidth) * scale) rounded. |
100 paperWidthPixel := ((self inchToPixel:paperWidth) * scale) rounded. |
114 "centimeter - long blibs every centimeter; short ones every half" |
121 "centimeter - long blibs every centimeter; short ones every half" |
115 |
122 |
116 paperWidthMM := self inchToMillimeter:paperWidth. |
123 paperWidthMM := self inchToMillimeter:paperWidth. |
117 pixelPerMM := (self millimeterToPixel:1) * scale. |
124 pixelPerMM := (self millimeterToPixel:1) * scale. |
118 pos := 5. |
125 pos := 5. |
119 labelRight := stringRight := marg + (font widthOf:'cm'). |
126 labelRight := stringRight := marg + (font widthOf:'cm') + 3. |
120 |
127 |
121 x := (pixelPerMM * pos - xOrigin) rounded. |
128 x := (pixelPerMM * pos - xOrigin) rounded. |
122 [(x < width) and:[pos <= paperWidthMM]] whileTrue:[ |
129 [(x < width) and:[pos <= paperWidthMM]] whileTrue:[ |
123 |l| |
130 |l| |
124 |
131 |
125 (mod == 1) ifTrue:[ |
132 l := shortLen. |
126 self displayLineFromX:x y:top |
133 (mod ~~ 1) ifTrue:[ |
127 toX:x y:(top + shortLen) |
134 x < stringRight ifFalse:[ |
128 ] ifFalse:[ |
|
129 x < stringRight ifTrue:[ |
|
130 l := shortLen |
|
131 ] ifFalse:[ |
|
132 l := longLen |
135 l := longLen |
133 ]. |
136 ]. |
134 self displayLineFromX:x y:top |
137 ]. |
135 toX:x y:(top + l). |
138 self displayLineFromX:x y:top |
136 |
139 toX:x y:(top + l). |
137 x < stringRight ifFalse:[ |
140 |
138 self displayString:(pos // 10) printString |
141 ((x < stringRight) or:[mod == 1]) ifFalse:[ |
139 x:(x + marg) |
142 self displayString:(pos // 10) printString |
140 y:charY. |
143 x:(x + marg) |
141 stringRight := x + marg |
144 y:charY. |
142 + (font widthOf:(pos // 10) printString) |
145 stringRight := x + marg |
143 ] |
146 + (font widthOf:(pos // 10) printString) |
144 ]. |
147 ]. |
145 mod := (mod + 1) \\ 2. |
148 mod := (mod + 1) \\ 2. |
146 pos := pos + 5. |
149 pos := pos + 5. |
147 x := (pixelPerMM * pos - xOrigin) rounded |
150 x := (pixelPerMM * pos - xOrigin) rounded |
148 ]. |
151 ]. |
152 "inches - long blibs every inch; short ones every half; very |
155 "inches - long blibs every inch; short ones every half; very |
153 short ones every quarter" |
156 short ones every quarter" |
154 |
157 |
155 pixelPerInch := (self inchToPixel:1) * scale. |
158 pixelPerInch := (self inchToPixel:1) * scale. |
156 pos := 0.25. |
159 pos := 0.25. |
157 labelRight := marg + (font widthOf:'inch'). |
160 labelRight := marg + (font widthOf:'inch') + 3. |
158 |
161 |
159 x := (pixelPerInch * pos - xOrigin) rounded. |
162 x := (pixelPerInch * pos - xOrigin) rounded. |
160 veryShortLen := longLen // 4. |
163 veryShortLen := longLen // 4. |
161 [(x < width) and:[pos <= paperWidth]] whileTrue:[ |
164 [(x < width) and:[pos <= paperWidth]] whileTrue:[ |
|
165 |l| |
|
166 |
|
167 l := shortLen. |
162 (mod == 0) ifTrue:[ |
168 (mod == 0) ifTrue:[ |
163 x < labelRight ifFalse:[ |
169 x < labelRight ifFalse:[ |
164 self displayLineFromX:x y:top |
170 l := longLen |
165 toX:x y:(top + longLen). |
|
166 self displayString:pos asInteger printString |
|
167 x:(x + marg) |
|
168 y:charY |
|
169 ] |
171 ] |
170 ] ifFalse:[ |
172 ] ifFalse:[ |
171 (mod == 2) ifTrue:[ |
173 (mod == 2) ifFalse:[ |
172 self displayLineFromX:x y:top |
174 l := veryShortLen |
173 toX:x y:(top + shortLen) |
|
174 ] ifFalse:[ |
|
175 self displayLineFromX:x y:top |
|
176 toX:x y:(top + veryShortLen) |
|
177 ] |
175 ] |
|
176 ]. |
|
177 self displayLineFromX:x y:top |
|
178 toX:x y:(top + l). |
|
179 |
|
180 (mod == 0 and:[x >= labelRight]) ifTrue:[ |
|
181 self displayString:pos asInteger printString |
|
182 x:(x + marg) |
|
183 y:charY |
178 ]. |
184 ]. |
179 mod := (mod + 1) \\ 4. |
185 mod := (mod + 1) \\ 4. |
180 pos := pos + 0.25. |
186 pos := pos + 0.25. |
181 x := (pixelPerInch * pos - xOrigin) rounded |
187 x := (pixelPerInch * pos - xOrigin) rounded |
182 ]. |
188 ]. |