The Range Slider: JRangeSlider

Derived from: public BView

Declared in: <JRangeSlider.h>

Important note! This is not a BeBook File. I borrowed the titles because they are well known to Be programmers and gives good stamina for a class description. May someone at Be flame me for borrowing the look and feel of the BeBook, but I think this makes it easier for programmers to quickly find the information he/she wants.


Overview

JRangeSlider is an object that displays an knob in a container, similar to s BSrollBar. The difference is that this gadget provides buttons within the knob to change the size as well as the position.


The Function

The slider functions in a quite intuitive fashion, but with some small additions for more functionality. The behaviour when using the primary mouse button is what you expect from the BScrollBar, with the addition that when dragging the small extra buttons on the top and bottom of the knob, it resizes. The secondary mouse button adds some more functionlity. When pressing SMB on the arrows up and down, you fine adjust the upper or lower position of the knob, whether you press the pair above or below the slider. Using SMB on the container makes the upper or lower position jump to the mouse depending on if you press above or below the knob. You can also move the whole knob with pressing the resize buttons with SMB. That is handy if the knob is so small that the drag area has disappeared.


The Update Mechanism

The slider calls one of three hook functions when the user moves the knob: UpperPositionChanged(), LowerPositionChanged() or BothUpperAndLowerPositionsChanged(). The names reveal the structure of this knob. In constrast to the BScrollBar, the it is not defined by position and size but rather an Upper Position and a Lower Position. These are realative values of the positions of the knob within the container. 1 means the top (or right in B_HORIZONTAL mode) and 0 means bottom (or left).

NOTE! This object does not support any archiving or targeting!


The Appearance

The standard look of this slider is 'Be-like' although it's not a copy of the looks of the Be GUI. If somebody would like to change the appearance of the slider, there's three hook functions that render the slider: DrawInRect(), DrawOutRect() and DrawArrowIn(). They provide a way to customly design your own look.

There's also a few colors defined used to draw the boxes, creating an illusion of 3D. These are public and can be changed to whatever colors you want. Email me if you want the detalis on what color's used where.


Hook Functions

  • UpperPositionChanged()

    This function is calles when only the upper position has been changed.

  • LowerPositionChanged()

    This function is calles when only the lower position has been changed.

  • BothUpperAndLowerPositionsChanged()

    This function is calles when both the upper and lower position has been changed.


  • Constructor and Destructor


    JRangeSlider()

    
          JRangeSlider(BRect frame,
          	const char *name, float UpperPosition,
             float LowerPosition, orientation posture, 
             float SmallStep = 0.005)
    
    
    

    Initializes the JRangeSlider. It will be a horizontal slider if posture is B_HORIZONTAL and a vertical slider if posture is B_VERTICAL.

    The upper and lower position is given by UpperPosition and LowerPosition. These values should be in the range of [0,1]. If they are not, they will be limited to that region. If the constructor cannot work out the appearance from the parameters (it does some effort to squeeze it in) it will fail by throwing an exception.

    The SmallStep argument, gives the increment with which the slider moves when using the arrows.

    The other arguments, frame and name, are the same as for other BViews:

    The frame rectangle locates the slider within its parent view. For consistency in the user interface, a horizontal scroll bar should be B_H_SCROLL_BAR_HEIGHT coordinate units high, and a vertical scroll bar should be B_V_SCROLL_BAR_WIDTH units wide.

    The JRangeSlider name identifies it and permits it to be located by the FindView() function. It can be NULL.


    Member Functions

    bool	SetUpperPosition( float NewUpperPosition )	
    bool	SetLowerPosition( float NewLowerPosition )	
    

    These functions sets the upper and lower position of the knob. They are bounded into the interval [0,1]. These functions does not call UpperPositionChanged() and LowerPositioChanged() respectively. It does call the Draw() function to redraw the applicable parts of the slider.


    void	SetSmallStep( float NewSmallStep )		
    void	SetLargeStep( float NewLargeStep )		
    

    These set the variables SmallStep and LargeStep respectively. (LargeStep is currently not implemented to control any parameter. I may be removed in future releases.)


    virtual void		DrawInRect(	BRect argRect, bool	argActivated);
    virtual void		DrawOutRect(BRect argRect, bool argActivated);
    virtual void		DrawArrowIn(BRect argRect, int32 argDirection, bool argActivated); 
    
    DrawInRect() and DrawOutRect() draws rectangles with a 3D illusion. The appear to be 'in' or 'out' of the desktop. They can be reimplemented in a derived class to change the looks of the slider. DrawArrowIn() draws the arrows in the specified rectangle. Can also be reimplemented.

    The argRect parameter is the rectangle which contain the area to be drawn.

    The argActivated parameter is to indicate to draw the activated version of the area. If it is true, the user has just activated the area and the slider wants to redraw it in the activated fashion. This is done calling these functions with this parameter true.

    Implementation detail: When an arrow-button is pressed, the rectangle is drawn first by a call to DrawOutRect, THEN the arrow is drawn by the DrawArrowIn() function.


    virtual void		UpperPositionChanged( float argNewUpperPosition );
    virtual	void		LowerPositionChanged( float argNewLowerPosition );
    virtual void		BothUpperAndLowerPositionsChanged( float argNewUpperPosition, float argNewLowerPosition  );
    
    These virtual functions are called whenever the upper or lower positions are changed.

    Legal Stuff

    This is NOT an official Be product, and I am not affiliated with Be in any way. Neither do I take any responsibility for the consequences, direct or indirect, of the use of this product. I leave no warranties of its functionality and do not guarantee that it works to 100% as stated in this document. This product is free to use, but it IS copyrighted. If you decide to include it in your product (commercial or of other type) I want you to send me a note that you did so, containing a short description of the product. This is not a requirement for the use, but I would appreciate it. If you ask nicely, you may even have the source. :-) <thoan@ifm.liu.se>

    Copyright © 1997 Thorbjörn Jemander. All rights reserved.

    Last change made the 24 October, 1997.

    Be is a registered trademark; BeOS, BeBox, BeWare, GeekPort, the Be logo, and the BeOS logo are trademarks of Be, Inc.