HorizontalSlider.st
changeset 17 bda821037847
child 24 6704fad5eb7d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HorizontalSlider.st	Fri Aug 12 01:53:54 1994 +0200
@@ -0,0 +1,123 @@
+"
+ COPYRIGHT (c) 1992 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.
+"
+
+HorizontalScroller subclass:#HorizontalSlider
+       instanceVariableNames:'sliderHeight'
+       classVariableNames:   ''
+       poolDictionaries:''
+       category:'Views-Interactors'
+!
+
+HorizontalSlider comment:'
+COPYRIGHT (c) 1992 by Claus Gittinger
+              All Rights Reserved
+
+$Header: /cvs/stx/stx/libwidg2/HorizontalSlider.st,v 1.1 1994-08-11 23:53:54 claus Exp $
+'!
+
+!HorizontalSlider class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1992 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.
+"
+!
+
+version
+"
+$Header: /cvs/stx/stx/libwidg2/HorizontalSlider.st,v 1.1 1994-08-11 23:53:54 claus Exp $
+"
+!
+
+documentation
+"
+    this class implements horizontal sliders.
+"
+! !
+
+!HorizontalSlider methodsFor:'initialization'!
+
+initialize
+    sliderHeight := (self verticalPixelPerMillimeter:10) rounded.
+    super initialize.
+    thumbHeight := 0
+!
+
+initStyle
+    super initStyle.
+    tallyMarks := 1.
+    style == #iris ifTrue:[
+        tallyLevel := 1.
+    ] ifFalse:[
+        tallyLevel := -1.
+    ]
+! !
+
+!HorizontalSlider methodsFor:'accessing'!
+
+thumbHeight
+    "redefined since a slider has no height - just origin"
+
+    ^ nil
+! !
+
+!HorizontalSlider methodsFor:'private'!
+
+absFromPercent:percent
+    "given a percentage, compute number of pixels"
+
+    ^ ((percent * (width - sliderHeight - (margin * 2))) / 100) rounded 
+!
+
+percentFromAbs:absValue
+    "given a number of pixels, compute percentage"
+
+    |val|
+
+    val := absValue / (width - sliderHeight - (margin * 2)) * 100.
+    val < 0 ifTrue:[^ 0].
+    val > 100 ifTrue:[^ 100].
+    ^ val
+!
+
+computeThumbFrame
+    "redefined, since the thumb-height stays constant"
+
+    |nh nw ny nx|
+
+    thumbHeight := 0.
+    nx := (self absFromPercent:thumbOrigin) + margin.
+    nw := sliderHeight.
+    ny := margin + inset.     
+    nh := height - (2 * ny).
+    "
+     do not create new Rectangle if its the same anyway
+    "
+    thumbFrame notNil ifTrue:[
+        (ny == thumbFrame top) ifTrue:[
+          (nx == thumbFrame left) ifTrue:[
+            (nh == thumbFrame height) ifTrue:[
+              (nw == thumbFrame width) ifTrue:[ ^ self]
+            ]
+          ]
+        ]
+    ].
+    thumbFrame := Rectangle left:nx top:ny width:nw height:nh
+! !