VerticalRuler.st
changeset 27 12e5a38bf0a8
child 28 ca403f4c5b86
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VerticalRuler.st	Thu Nov 17 15:42:58 1994 +0100
@@ -0,0 +1,164 @@
+"
+ COPYRIGHT (c) 1994 by Claus Gittinger
+	      All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+Ruler subclass:#VerticalRuler
+	 instanceVariableNames:''
+	 classVariableNames:''
+	 poolDictionaries:''
+	 category:'Views-Misc'
+!
+
+VerticalRuler comment:'
+COPYRIGHT (c) 1991 by Claus Gittinger
+	      All Rights Reserved
+
+a VerticalRuler for page layout.
+
+$Header: /cvs/stx/stx/libwidg2/VerticalRuler.st,v 1.1 1994-11-17 14:42:58 claus Exp $
+
+written oct 91 by claus
+'!
+
+!VerticalRuler methodsFor:'accessing'!
+
+paperHeightInch:inches
+    "set the width of the document"
+
+    paperHeight := inches.
+    shown ifTrue:[
+	self redraw
+    ]
+!
+
+paperHeightMM:millis
+    "set the width of the document"
+
+    paperHeight := self millimeterToInch:millis.
+    shown ifTrue:[
+	self redraw
+    ]
+! !
+
+!VerticalRuler methodsFor:'redrawing'!
+
+redraw
+    "redraw scale"
+
+    |y pixelPerMM pixelPerInch mod pos shortLen veryShortLen longLen charX
+     left paperHeightMM paperHeightPixel yOrigin labelBot marg fontHeight|
+
+    shown ifFalse:[^ self].
+
+"/    self fill:viewBackground.
+    self clear.
+
+    yOrigin := self viewOrigin y.
+
+    paperHeightPixel := ((self inchToPixel:paperHeight) * scale) rounded.
+
+    (yOrigin + height > paperHeightPixel) ifTrue:[
+	self paint:(Color darkGrey).
+	self fillRectangleX:0 y:paperHeightPixel - yOrigin
+		      width:width
+		      height:(height - (paperHeightPixel - yOrigin)).
+	self paint:fgColor.
+	self displayLineFromX:0 y:paperHeightPixel - yOrigin
+			  toX:width y:paperHeightPixel - yOrigin
+    ].
+
+    self paint:fgColor.
+
+    left := 0. "width - (font widthOf:'WW')"
+    longLen := font widthOf:'WW'.
+    shortLen := longLen // 2.
+    charX := left + shortLen.
+    mod := 1.
+    marg := 3. "character shift"
+    fontHeight := font height.
+
+    (metric == #mm) ifTrue:[
+	"centimeter - long blibs every centimeter; short ones every half"
+
+	paperHeightMM := self inchToMillimeter:paperHeight.
+	pixelPerMM := (self millimeterToPixel:1) * scale.
+	pos := 5.
+	labelBot := marg + font height + font ascent.
+
+	y := (pixelPerMM * pos - yOrigin) rounded.
+	[(y < height) and:[pos <= paperHeightMM]] whileTrue:[
+	    (mod == 1) ifTrue:[
+		self displayLineFromX:left y:y
+				  toX:(left + shortLen) y:y
+	    ] ifFalse:[
+		y < labelBot ifFalse:[
+		    self displayLineFromX:left y:y
+				      toX:(left + longLen) y:y.
+		    self displayString:(pos // 10) printString
+				     x:charX
+				     y:(y + marg + fontHeight)
+		]
+	    ].
+	    mod := (mod + 1) \\ 2.
+	    pos := pos + 5.
+	    y := (pixelPerMM * pos - yOrigin) rounded 
+	].
+	self displayString:'cm ' x:charX y:marg + fontHeight.
+    ].
+    (metric == #inch) ifTrue:[
+	"inches - long blibs every inch; short ones every half; very
+	 short ones every quarter"
+
+	pixelPerInch := (self inchToPixel:1) * scale.
+	pos := 0.25.
+	labelBot := marg + (font height + font ascent).
+
+	y := (pixelPerInch * pos - yOrigin) rounded.
+	veryShortLen := longLen // 4.
+	[(y < height) and:[pos <= paperHeight]] whileTrue:[
+	    (mod == 0) ifTrue:[
+		y < labelBot ifFalse:[
+		    self displayLineFromX:left y:y
+				      toX:(left + longLen) y:y.
+		    self displayString:pos asInteger printString
+				     x:charX
+				     y:(y + marg + fontHeight)
+		]
+	    ] ifFalse:[
+		(mod == 2) ifTrue:[
+		    self displayLineFromX:left y:y
+				      toX:(left + shortLen) y:y
+		] ifFalse:[
+		    self displayLineFromX:left y:y
+				      toX:(left + veryShortLen) y:y
+		]
+	    ].
+	    mod := (mod + 1) \\ 4.
+	    pos := pos + 0.25.
+	    y := (pixelPerInch * pos - yOrigin) rounded
+	].
+	self displayString:'inch ' x:charX y:marg + fontHeight.
+    ].
+    self redrawEdges
+! !
+
+!VerticalRuler methodsFor:'initialization'!
+
+initialize
+    super initialize.
+
+    self width:(font widthOf:'inch').
+
+    "
+     VerticalRuler new open
+    "
+! !
+