1 " |
1 " |
2 COPYRIGHT (c) 1991 by Claus Gittinger |
2 COPYRIGHT (c) 1991 by Claus Gittinger |
3 All Rights Reserved |
3 All Rights Reserved |
4 |
4 |
5 This software is furnished under a license and may be used |
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 |
6 only in accordance with the terms of that license and with the |
7 inclusion of the above copyright notice. This software may not |
7 inclusion of the above copyright notice. This software may not |
8 be provided or otherwise made available to, or used by, any |
8 be provided or otherwise made available to, or used by, any |
9 other person. No title to or ownership of the software is |
9 other person. No title to or ownership of the software is |
10 hereby transferred. |
10 hereby transferred. |
11 " |
11 " |
12 |
12 |
13 View subclass:#Ruler |
13 View subclass:#Ruler |
14 instanceVariableNames:'fgColor metric paperWidth paperHeight' |
14 instanceVariableNames:'fgColor metric paperWidth paperHeight' |
15 classVariableNames:'' |
15 classVariableNames:'' |
16 poolDictionaries:'' |
16 poolDictionaries:'' |
17 category:'Views-Interactors' |
17 category:'Views-Interactors' |
18 ! |
18 ! |
19 |
19 |
20 Ruler comment:' |
20 Ruler comment:' |
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.6 1994-08-05 01:24:05 claus Exp $ |
26 $Header: /cvs/stx/stx/libwidg2/Ruler.st,v 1.7 1994-10-10 03:13:35 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'! |
32 |
32 |
33 metric:aSymbol |
33 metric:aSymbol |
34 "set the metric" |
34 "set the metric. The argument may be either #inch or #mm" |
35 |
35 |
36 metric := aSymbol. |
36 aSymbol ~~ metric ifTrue:[ |
|
37 metric := aSymbol. |
|
38 shown ifTrue:[ |
|
39 self redraw |
|
40 ] |
|
41 ] |
|
42 ! |
|
43 |
|
44 paperWidthInch:inches |
|
45 "set the width of the document" |
|
46 |
|
47 paperWidth := inches. |
37 shown ifTrue:[ |
48 shown ifTrue:[ |
38 self redraw |
49 self redraw |
|
50 ] |
|
51 ! |
|
52 |
|
53 paperWidthMM:millis |
|
54 "set the width of the document" |
|
55 |
|
56 paperWidth := self millimeterToInch:millis. |
|
57 shown ifTrue:[ |
|
58 self redraw |
39 ] |
59 ] |
40 ! ! |
60 ! ! |
41 |
61 |
42 !Ruler methodsFor:'redrawing'! |
62 !Ruler methodsFor:'redrawing'! |
43 |
63 |
45 "redraw scale" |
65 "redraw scale" |
46 |
66 |
47 |x pixelPerMM pixelPerInch mod pos shortLen veryShortLen longLen charY |
67 |x pixelPerMM pixelPerInch mod pos shortLen veryShortLen longLen charY |
48 top paperWidthMM paperWidthPixel xOrigin labelRight marg| |
68 top paperWidthMM paperWidthPixel xOrigin labelRight marg| |
49 |
69 |
50 self fill:viewBackground. |
70 shown ifFalse:[^ self]. |
|
71 |
|
72 "/ self fill:viewBackground. |
|
73 self clear. |
51 |
74 |
52 xOrigin := viewOrigin x. |
75 xOrigin := viewOrigin x. |
53 |
76 |
54 paperWidthPixel := (self inchToPixel:paperWidth) rounded. |
77 paperWidthPixel := (self inchToPixel:paperWidth) rounded. |
55 (xOrigin + width > paperWidthPixel) ifTrue:[ |
78 (xOrigin + width > paperWidthPixel) ifTrue:[ |
56 self paint:(Color darkGrey). |
79 self paint:(Color darkGrey). |
57 self fillRectangleX:paperWidthPixel - xOrigin y:0 |
80 self fillRectangleX:paperWidthPixel - xOrigin y:0 |
58 width:(width - (paperWidthPixel - xOrigin)) height:height. |
81 width:(width - (paperWidthPixel - xOrigin)) height:height. |
59 self paint:fgColor. |
82 self paint:fgColor. |
60 self displayLineFromX:paperWidthPixel - xOrigin y:0 |
83 self displayLineFromX:paperWidthPixel - xOrigin y:0 |
61 toX:paperWidthPixel - xOrigin y:height |
84 toX:paperWidthPixel - xOrigin y:height |
62 ]. |
85 ]. |
63 |
86 |
64 self paint:fgColor. |
87 self paint:fgColor. |
65 |
88 |
66 top := height - font height - font ascent. |
89 top := height - font height - font ascent. |
69 charY := top + (font ascent) + shortLen. |
92 charY := top + (font ascent) + shortLen. |
70 mod := 1. |
93 mod := 1. |
71 marg := 3. "character shift" |
94 marg := 3. "character shift" |
72 |
95 |
73 (metric == #mm) ifTrue:[ |
96 (metric == #mm) ifTrue:[ |
74 "centimeter - long blibs every centimeter; short ones every half" |
97 "centimeter - long blibs every centimeter; short ones every half" |
75 |
98 |
76 paperWidthMM := self inchToMillimeter:paperWidth. |
99 paperWidthMM := self inchToMillimeter:paperWidth. |
77 pixelPerMM := self millimeterToPixel:1. |
100 pixelPerMM := self millimeterToPixel:1. |
78 pos := 5. |
101 pos := 5. |
79 labelRight := marg + (font widthOf:'cm'). |
102 labelRight := marg + (font widthOf:'cm'). |
80 |
103 |
81 x := (pixelPerMM * pos - xOrigin) rounded. |
104 x := (pixelPerMM * pos - xOrigin) rounded. |
82 [(x < width) and:[pos <= paperWidthMM]] whileTrue:[ |
105 [(x < width) and:[pos <= paperWidthMM]] whileTrue:[ |
83 (mod == 1) ifTrue:[ |
106 (mod == 1) ifTrue:[ |
84 self displayLineFromX:x y:top |
107 self displayLineFromX:x y:top |
85 toX:x y:(top + shortLen) |
108 toX:x y:(top + shortLen) |
86 ] ifFalse:[ |
109 ] ifFalse:[ |
87 x < labelRight ifFalse:[ |
110 x < labelRight ifFalse:[ |
88 self displayLineFromX:x y:top |
111 self displayLineFromX:x y:top |
89 toX:x y:(top + longLen). |
112 toX:x y:(top + longLen). |
90 self displayString:(pos // 10) printString |
113 self displayString:(pos // 10) printString |
91 x:(x + marg) |
114 x:(x + marg) |
92 y:charY |
115 y:charY |
93 ] |
116 ] |
94 ]. |
117 ]. |
95 mod := (mod + 1) \\ 2. |
118 mod := (mod + 1) \\ 2. |
96 pos := pos + 5. |
119 pos := pos + 5. |
97 x := (pixelPerMM * pos - xOrigin) rounded |
120 x := (pixelPerMM * pos - xOrigin) rounded |
98 ]. |
121 ]. |
99 self displayString:'cm ' x:marg y:charY. |
122 self displayString:'cm ' x:marg y:charY. |
100 ]. |
123 ]. |
101 (metric == #inch) ifTrue:[ |
124 (metric == #inch) ifTrue:[ |
102 "inches - long blibs every inch; short ones every half; very |
125 "inches - long blibs every inch; short ones every half; very |
103 short ones every quarter" |
126 short ones every quarter" |
104 |
127 |
105 pixelPerInch := self inchToPixel:1. |
128 pixelPerInch := self inchToPixel:1. |
106 pos := 0.25. |
129 pos := 0.25. |
107 labelRight := marg + (font widthOf:'inch'). |
130 labelRight := marg + (font widthOf:'inch'). |
108 |
131 |
109 x := (pixelPerInch * pos - xOrigin) rounded. |
132 x := (pixelPerInch * pos - xOrigin) rounded. |
110 veryShortLen := longLen // 4. |
133 veryShortLen := longLen // 4. |
111 [(x < width) and:[pos <= paperWidth]] whileTrue:[ |
134 [(x < width) and:[pos <= paperWidth]] whileTrue:[ |
112 (mod == 0) ifTrue:[ |
135 (mod == 0) ifTrue:[ |
113 x < labelRight ifFalse:[ |
136 x < labelRight ifFalse:[ |
114 self displayLineFromX:x y:top |
137 self displayLineFromX:x y:top |
115 toX:x y:(top + longLen). |
138 toX:x y:(top + longLen). |
116 self displayString:pos asInteger printString |
139 self displayString:pos asInteger printString |
117 x:(x + marg) |
140 x:(x + marg) |
118 y:charY |
141 y:charY |
119 ] |
142 ] |
120 ] ifFalse:[ |
143 ] ifFalse:[ |
121 (mod == 2) ifTrue:[ |
144 (mod == 2) ifTrue:[ |
122 self displayLineFromX:x y:top |
145 self displayLineFromX:x y:top |
123 toX:x y:(top + shortLen) |
146 toX:x y:(top + shortLen) |
124 ] ifFalse:[ |
147 ] ifFalse:[ |
125 self displayLineFromX:x y:top |
148 self displayLineFromX:x y:top |
126 toX:x y:(top + veryShortLen) |
149 toX:x y:(top + veryShortLen) |
127 ] |
150 ] |
128 ]. |
151 ]. |
129 mod := (mod + 1) \\ 4. |
152 mod := (mod + 1) \\ 4. |
130 pos := pos + 0.25. |
153 pos := pos + 0.25. |
131 x := (pixelPerInch * pos - xOrigin) rounded |
154 x := (pixelPerInch * pos - xOrigin) rounded |
132 ]. |
155 ]. |
133 self displayString:'inch ' x:marg y:charY. |
156 self displayString:'inch ' x:marg y:charY. |
134 ]. |
157 ]. |
135 self redrawEdges |
158 self redrawEdges |
136 |
159 |
137 ! ! |
160 ! ! |
138 |
161 |