Slider.st
author claus
Wed, 13 Oct 1993 03:49:40 +0100
changeset 4 e1e3fbe98999
parent 2 ab6002adaee1
child 8 91035a03b4cf
permissions -rw-r--r--
(none)

"
 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.
"

Scroller subclass:#Slider
       instanceVariableNames:'sliderHeight'
       classVariableNames:   ''
       poolDictionaries:''
       category:'Views-Interactors'
!

Slider comment:'

COPYRIGHT (c) 1992 by Claus Gittinger
              All Rights Reserved

this class implements sliders - which are simply scrollers
with a constant thumbHeight and a sligthly different way of
drawing.

Instance variables:

$Header: /cvs/stx/stx/libwidg2/Slider.st,v 1.3 1993-10-13 02:49:35 claus Exp $

written summer 92 by claus
'!

!Slider methodsFor:'initialization'!

initialize
    sliderHeight := (self verticalPixelPerMillimeter:10) rounded.
    super initialize.
    thumbHeight := 0
! !

!Slider methodsFor:'accessing'!

thumbHeight
    "redefined since a slider has no height - just origin"

    ^ nil
! !

!Slider methodsFor:'private'!

absFromPercent:percent
    "given a percentage, compute number of pixels"

    ^ ((percent * (height - sliderHeight - (margin * 2))) / 100) rounded
!

percentFromAbs:absValue
    "given a number of pixels, compute percentage"

    |val|

    val := absValue / (height - 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.
    ny := (self absFromPercent:thumbOrigin) + margin.
    nh := sliderHeight.
    self is3D ifTrue:[
        nx := margin.     
        nw := width - (2 * margin)
    ] ifFalse:[
        nx := inset.
        nw := width - (inset * 2)
    ].
    "
     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
! !

!Slider methodsFor:'drawing'!

drawThumb
    "draw the thumb"

    |markX markY l t w h sep|

    l := thumbFrame left.
    t := thumbFrame top.
    w := thumbFrame width.
    h := thumbFrame height.
    sep := thumbLevel.
    self paint:thumbColor.
    self fillRectangleX:l y:t width:w height:h.

    markX := l + sep.
    markY := t + ((h - 2) // 2).

    self is3D ifTrue:[
        self drawEdgesForX:l y:t width:w height:h level:thumbLevel
                    shadow:thumbShadowColor light:thumbLightColor
                    halfShadow:thumbHalfShadowColor halfLight:thumbHalfLightColor.

        self paint:thumbShadowColor.
        self displayLineFromX:markX y:markY toX:(w - sep) y:markY.
        markY := markY + 1.
        self paint:thumbLightColor.
        self displayLineFromX:markX y:markY toX:(w - sep) y:markY
    ] ifFalse:[
        self paint:thumbFrameColor.
        self drawRectangle:thumbFrame.
        self paint:Black.
        self displayLineFromX:markX y:markY toX:(w - sep + 1) y:markY.
        markY := markY + 1.
        self displayLineFromX:markX y:markY toX:(w - sep + 1) y:markY
    ]
! !