--- a/Ruler.st Fri Oct 28 04:28:34 1994 +0100
+++ b/Ruler.st Thu Nov 17 15:42:28 1994 +0100
@@ -11,10 +11,10 @@
"
View subclass:#Ruler
- instanceVariableNames:'fgColor metric paperWidth paperHeight'
+ instanceVariableNames:'fgColor metric paperWidth paperHeight scale'
classVariableNames:''
poolDictionaries:''
- category:'Views-Interactors'
+ category:'Views-Misc'
!
Ruler comment:'
@@ -23,7 +23,7 @@
a Ruler for page layout.
-$Header: /cvs/stx/stx/libwidg2/Ruler.st,v 1.7 1994-10-10 03:13:35 claus Exp $
+$Header: /cvs/stx/stx/libwidg2/Ruler.st,v 1.8 1994-11-17 14:42:26 claus Exp $
written oct 91 by claus
'!
@@ -41,6 +41,17 @@
]
!
+scale:aFactor
+ "set the scale factor. 1 is identity."
+
+ aFactor ~= scale ifTrue:[
+ scale := aFactor.
+ shown ifTrue:[
+ self redraw
+ ]
+ ]
+!
+
paperWidthInch:inches
"set the width of the document"
@@ -57,6 +68,11 @@
shown ifTrue:[
self redraw
]
+!
+
+viewOrigin:origin
+ super setViewOrigin:origin.
+ self redraw
! !
!Ruler methodsFor:'redrawing'!
@@ -65,16 +81,17 @@
"redraw scale"
|x pixelPerMM pixelPerInch mod pos shortLen veryShortLen longLen charY
- top paperWidthMM paperWidthPixel xOrigin labelRight marg|
+ top paperWidthMM paperWidthPixel xOrigin labelRight stringRight marg|
shown ifFalse:[^ self].
"/ self fill:viewBackground.
self clear.
- xOrigin := viewOrigin x.
+ xOrigin := self viewOrigin x.
- paperWidthPixel := (self inchToPixel:paperWidth) rounded.
+ paperWidthPixel := ((self inchToPixel:paperWidth) * scale) rounded.
+
(xOrigin + width > paperWidthPixel) ifTrue:[
self paint:(Color darkGrey).
self fillRectangleX:paperWidthPixel - xOrigin y:0
@@ -97,22 +114,32 @@
"centimeter - long blibs every centimeter; short ones every half"
paperWidthMM := self inchToMillimeter:paperWidth.
- pixelPerMM := self millimeterToPixel:1.
+ pixelPerMM := (self millimeterToPixel:1) * scale.
pos := 5.
- labelRight := marg + (font widthOf:'cm').
+ labelRight := stringRight := marg + (font widthOf:'cm').
x := (pixelPerMM * pos - xOrigin) rounded.
[(x < width) and:[pos <= paperWidthMM]] whileTrue:[
+ |l|
+
(mod == 1) ifTrue:[
self displayLineFromX:x y:top
toX:x y:(top + shortLen)
] ifFalse:[
- x < labelRight ifFalse:[
- self displayLineFromX:x y:top
- toX:x y:(top + longLen).
+ x < stringRight ifTrue:[
+ l := shortLen
+ ] ifFalse:[
+ l := longLen
+ ].
+ self displayLineFromX:x y:top
+ toX:x y:(top + l).
+
+ x < stringRight ifFalse:[
self displayString:(pos // 10) printString
x:(x + marg)
- y:charY
+ y:charY.
+ stringRight := x + marg
+ + (font widthOf:(pos // 10) printString)
]
].
mod := (mod + 1) \\ 2.
@@ -125,7 +152,7 @@
"inches - long blibs every inch; short ones every half; very
short ones every quarter"
- pixelPerInch := self inchToPixel:1.
+ pixelPerInch := (self inchToPixel:1) * scale.
pos := 0.25.
labelRight := marg + (font widthOf:'inch').
@@ -156,7 +183,6 @@
self displayString:'inch ' x:marg y:charY.
].
self redrawEdges
-
! !
!Ruler methodsFor:'initialization'!
@@ -165,12 +191,16 @@
super initialize.
fgColor := Black.
+ bitGravity := #NorthWest.
+
self height:(font height + font descent + font descent).
(Language == #english) ifTrue:[
metric := #inch
] ifFalse:[
metric := #mm
].
+ scale := 1.
+
paperWidth := 8.5.
paperHeight := 11.