|
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 |
|
23 |
|
24 a VerticalRuler for page layout. |
|
25 |
|
26 $Header: /cvs/stx/stx/libwidg2/VerticalRuler.st,v 1.1 1994-11-17 14:42:58 claus Exp $ |
|
27 |
|
28 written oct 91 by claus |
|
29 '! |
|
30 |
|
31 !VerticalRuler methodsFor:'accessing'! |
|
32 |
|
33 paperHeightInch:inches |
|
34 "set the width of the document" |
|
35 |
|
36 paperHeight := inches. |
|
37 shown ifTrue:[ |
|
38 self redraw |
|
39 ] |
|
40 ! |
|
41 |
|
42 paperHeightMM:millis |
|
43 "set the width of the document" |
|
44 |
|
45 paperHeight := self millimeterToInch:millis. |
|
46 shown ifTrue:[ |
|
47 self redraw |
|
48 ] |
|
49 ! ! |
|
50 |
|
51 !VerticalRuler methodsFor:'redrawing'! |
|
52 |
|
53 redraw |
|
54 "redraw scale" |
|
55 |
|
56 |y pixelPerMM pixelPerInch mod pos shortLen veryShortLen longLen charX |
|
57 left paperHeightMM paperHeightPixel yOrigin labelBot marg fontHeight| |
|
58 |
|
59 shown ifFalse:[^ self]. |
|
60 |
|
61 "/ self fill:viewBackground. |
|
62 self clear. |
|
63 |
|
64 yOrigin := self viewOrigin y. |
|
65 |
|
66 paperHeightPixel := ((self inchToPixel:paperHeight) * scale) rounded. |
|
67 |
|
68 (yOrigin + height > paperHeightPixel) ifTrue:[ |
|
69 self paint:(Color darkGrey). |
|
70 self fillRectangleX:0 y:paperHeightPixel - yOrigin |
|
71 width:width |
|
72 height:(height - (paperHeightPixel - yOrigin)). |
|
73 self paint:fgColor. |
|
74 self displayLineFromX:0 y:paperHeightPixel - yOrigin |
|
75 toX:width y:paperHeightPixel - yOrigin |
|
76 ]. |
|
77 |
|
78 self paint:fgColor. |
|
79 |
|
80 left := 0. "width - (font widthOf:'WW')" |
|
81 longLen := font widthOf:'WW'. |
|
82 shortLen := longLen // 2. |
|
83 charX := left + shortLen. |
|
84 mod := 1. |
|
85 marg := 3. "character shift" |
|
86 fontHeight := font height. |
|
87 |
|
88 (metric == #mm) ifTrue:[ |
|
89 "centimeter - long blibs every centimeter; short ones every half" |
|
90 |
|
91 paperHeightMM := self inchToMillimeter:paperHeight. |
|
92 pixelPerMM := (self millimeterToPixel:1) * scale. |
|
93 pos := 5. |
|
94 labelBot := marg + font height + font ascent. |
|
95 |
|
96 y := (pixelPerMM * pos - yOrigin) rounded. |
|
97 [(y < height) and:[pos <= paperHeightMM]] whileTrue:[ |
|
98 (mod == 1) ifTrue:[ |
|
99 self displayLineFromX:left y:y |
|
100 toX:(left + shortLen) y:y |
|
101 ] ifFalse:[ |
|
102 y < labelBot ifFalse:[ |
|
103 self displayLineFromX:left y:y |
|
104 toX:(left + longLen) y:y. |
|
105 self displayString:(pos // 10) printString |
|
106 x:charX |
|
107 y:(y + marg + fontHeight) |
|
108 ] |
|
109 ]. |
|
110 mod := (mod + 1) \\ 2. |
|
111 pos := pos + 5. |
|
112 y := (pixelPerMM * pos - yOrigin) rounded |
|
113 ]. |
|
114 self displayString:'cm ' x:charX y:marg + fontHeight. |
|
115 ]. |
|
116 (metric == #inch) ifTrue:[ |
|
117 "inches - long blibs every inch; short ones every half; very |
|
118 short ones every quarter" |
|
119 |
|
120 pixelPerInch := (self inchToPixel:1) * scale. |
|
121 pos := 0.25. |
|
122 labelBot := marg + (font height + font ascent). |
|
123 |
|
124 y := (pixelPerInch * pos - yOrigin) rounded. |
|
125 veryShortLen := longLen // 4. |
|
126 [(y < height) and:[pos <= paperHeight]] whileTrue:[ |
|
127 (mod == 0) ifTrue:[ |
|
128 y < labelBot ifFalse:[ |
|
129 self displayLineFromX:left y:y |
|
130 toX:(left + longLen) y:y. |
|
131 self displayString:pos asInteger printString |
|
132 x:charX |
|
133 y:(y + marg + fontHeight) |
|
134 ] |
|
135 ] ifFalse:[ |
|
136 (mod == 2) ifTrue:[ |
|
137 self displayLineFromX:left y:y |
|
138 toX:(left + shortLen) y:y |
|
139 ] ifFalse:[ |
|
140 self displayLineFromX:left y:y |
|
141 toX:(left + veryShortLen) y:y |
|
142 ] |
|
143 ]. |
|
144 mod := (mod + 1) \\ 4. |
|
145 pos := pos + 0.25. |
|
146 y := (pixelPerInch * pos - yOrigin) rounded |
|
147 ]. |
|
148 self displayString:'inch ' x:charX y:marg + fontHeight. |
|
149 ]. |
|
150 self redrawEdges |
|
151 ! ! |
|
152 |
|
153 !VerticalRuler methodsFor:'initialization'! |
|
154 |
|
155 initialize |
|
156 super initialize. |
|
157 |
|
158 self width:(font widthOf:'inch'). |
|
159 |
|
160 " |
|
161 VerticalRuler new open |
|
162 " |
|
163 ! ! |
|
164 |