Adobe Open Source
   Home     Projects     Source     Documentation     Forums    About
Welcome Guest | Sign In
 

Gumbo FxTrackBase - Functional and Design Specification



Glossary


position - The position of the thumb is defined in the units of the subclasses of FxTrackBase (i.e pixels, radians, etc...). It is converted back and forth from the actual value of FxTrackBase.

logical track, logical thumb - The logical track is the range of positions determined in the units of the subclass. The logical thumb can move through the entire range of positions from end to end.

visual track, visual thumb - The visual track and visual thumb are the actual track and thumb that is rendered. They may need to be offset from the logical track and thumb to provide the correct look.

Example:FxHSlider

position = x value in pixels
logical track = from 0 to the track's width minus the thumb width
visual track = depending on the thumb, the visual track may be drawn across the entire track's width for round thumbs or with some offset (maybe half the thumb width) for pointed thumbs.

Example:CircularSlider

position = radians which is then converted in positionThumb() to a point based on the width/height of the track SkinPart.
logical track = from 0 to 2pi radians.

These concepts of logical and visual track separate the layout of the track from the functional part of the track.

Summary and Background


The FxTrackBase class subclasses FxRange and introduces the concepts of a thumb and a track for the thumb to move along. It also provides the basic functions to map values to positions in subclasses. FxTrackBase also provides simple thumb dragging functionality for classes such as FxSlider and FxScrollBar, both of which subclass FxTrackBase.

Usage Scenarios


Detailed Description


SkinParts

FxTrackBase consists of 2 SkinParts.

  • The track SkinPart is the button which represents the logical track which the thumb moves along. The skin of the track determines the visual track.
  • The thumb SkinPart is a button which represents the logical thumb which moves through the range of positions along the track. The skin of the thumb determines the visual thumb.
Inherited Properties (from FxRange)

value, valueInterval, minimum, maximum - See FxRange.

stepSize - The equivalent of the Halo snapInterval. Dragging the thumb or stepping with the keyboard will always force the value to be a multiple of stepSize. See FxRange.

New Properties

trackSize, thumbSize - The trackSize is the size of the logical track in the units used by the subclass. The thumbSize is the size of the logical thumb along it. trackSize is read-only and should be overridden by the subclass. The default thumbSize is 0 (representing a point thumb).

clickOffset - The clickOffset is the point (local to the thumb) where the thumb was last pressed. This is used to perform thumb dragging.

Behavior and Methods

pointToPosition() - Takes a point local to the component and converts it to a position in the units of the subclass. This method must be overridden by a subclass.

positionThumb() - Takes a position in the units of the subclass and moves the visual thumb to the corresponding coordinates. This method must be overridden by a subclass.

sizeThumb() - Takes a size in the units of the subclass and sizes the visual thumb. This method must be overridden by a subclass.

positionToValue(), valueToPosition() - takes a position and converts it to a value and vice versa. These don't need to be overridden.

The value is converted to the position and vice versa using the following formulas:

// Position and value conversions are done using a ratio of the logical track size
// and the size of the range.
position = (value - minimum) * ((trackSize - thumbSize) / (maximum - minimum))
value = minimum + position * ((maximum - minimum) / (trackSize - thumbSize))

calculateThumbSize() - Should be overridden by subclasses to produce the correct size of the thumb.

calculateNewValue() - Takes the current value and a MouseEvent and returns a new value based on where the MouseEvent took place. This method assumes that the mouseDown handler has stored the difference between where the thumb was clicked vs. the origin of the thumb. The value returned is restricted and bounded using roundValue() to the nearest dragSize.

Events

Whenever the value changes, a "valueCommit" event is dispatched (inherited from FxRange).
Whenever the value changes because of user interaction, a "change" event is dispatched.

Additional Items to be considered
  • Is there a way we could map positions to values (in the subclasses) such that the value corresponds to the center of the thumb, but the visuals fit within the bounds of the track and thumb skins? (Affects FxSlider, but doesn't really affect FxScrollBar)
  • events dispatched from the thumb (thumbPress/Drag/Release)
  • "updateComplete" event of the track is handled. This is because the sizing is not properly done until after the skin's updateDisplayList() has been called.

API Description


package mx.components.baseClasses
{

import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;

/**
 *  Dispatched when the value of the control changes
 *  as a result of user interaction.
 *
 *  @eventType mx.events.Event
 */
[Event(name="change", type="mx.events.Event")]

/**
 *  FxTrackBase is a base class for components with a track
 *  and one or more thumbs such as FxSlider and FxScrollBar. It
 *  declares two required SkinParts, <code>thumb</code> and
 *  <code>track</code>. FxTrackBase also provides the code for
 *  thumb dragging which is shared by FxSlider and FxScrollBar.
 * 
 *  @see mx.components.baseClasses.FxRange
 *  @see mx.components.baseClasses.FxSlider
 *  @see mx.components.baseClasses.FxScrollBar
 */
public class FxTrackBase extends FxRange
{
    include "../core/Version.as";

    //--------------------------------------------------------------------------
    //
    //  Constructor
    //
    //--------------------------------------------------------------------------

    /**
     *  Constructor. 
     */
    public function FxTrackBase():void;

    //--------------------------------------------------------------------------
    //
    // Skins
    //
    //--------------------------------------------------------------------------

    [SkinPart]
    
    /**
     *  <code>thumb</code> is a SkinPart that defines a button
     *  that can be dragged along the track to increase or
     *  decrease the slider's <code>value</code> property.
     *  Updates to the <code>value</code> through other means
     *  will automatically update the position of the thumb
     *  with respect to the track.
     */
    public var thumb:FxButton;
    
    [SkinPart]
    
    /**
     *  <code>track</code> is a SkinPart that defines a button
     *  that, when  pressed, will set the <code>value</code>
     *  to the value corresponding with that position.
     */
    public var track:FxButton;

    //--------------------------------------------------------------------------
    //
    //  Overridden properties: UIComponent, FxRange
    //
    //--------------------------------------------------------------------------
    
    /**
     *  Enable/disable this component. This also enables/disables any of the 
     *  skin parts for this component.
     */
    override public function set enabled(value:Boolean):void;
    
    override public function set maximum(value:Number):void;

    override public function set minimum(value:Number):void;
    
    override public function set value(newValue:Number):void;
    
    //--------------------------------------------------------------------------
    //
    // Properties
    //
    //--------------------------------------------------------------------------

    //---------------------------------
    // clickOffset
    //---------------------------------

    /**
     *  The clickOffset is the point in the local coordinates of 
     *  the thumb where the last mouse down event occurred. This
     *  is used by calculateNewValue() to determine what value
     *  the thumb has been dragged to.
     */
    protected function get clickOffset():Point;

    //---------------------------------
    // trackSize
    //---------------------------------
    
    /**
     *  This method returns the size of the logical track. 
     *  Subclasses need to override this method to return 
     *  an appropriate value. Note that this number can 
     *  represent any system of units, but those units must 
     *  be consistent with the values returned by
     *  pointToPosition, thumbSize, and valueToPosition.
     */
    protected function get trackSize():Number;
    
    //---------------------------------
    // thumbSize
    //---------------------------------
    
    /**
     *  The size of the thumb on the logical track in the 
     *  units of the subclass, which must be consistent with 
     *  trackSize, pointToPosition and valueToPosition. The 
     *  default thumbSize on the logical track is 0.
     * 
     *  @default 0
     */
    protected function get thumbSize():Number;
    
    protected function set thumbSize(value:Number):void;
    
    //--------------------------------------------------------------------------
    //
    // Methods
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     */
    override protected function updateDisplayList(unscaledWidth:Number, 
                                                  unscaledHeight:Number):void;

    /**
     *  Adds an eventListener for the updateComplete event so
     *  that FxTrackBase will correctly position the thumb.
     */
    override protected function attachBehaviors():void;
    
    /**
     *  Removes the updateComplete event handler.
     */
    override protected function removeBehaviors():void;
    /**
     *  Adds event handlers to the track and thumb for mouse events.
     */
    override protected function partAdded(partName:String, instance:*):void;

    /**
     *  Remove event handlers from skin parts.
     */
    override protected function partRemoved(partName:String, instance:*):void;

    /**
     *  Make the skins reflect the enabled state of FxTrackBase
     */
    protected function enableSkinParts(value:Boolean):void;
    
    /**
     *  Utility method which returns the FxRange value for a given
     *  position on the track. The FxRange value is calculated by
     *  finding what fraction of the logical track the position
     *  represents and then multiplying that by the FxRange.
     */
    protected function positionToValue(position:Number):Number;
    
    /**
     *  Utility function to calculate the thumb's position
     *  corresponding to the given value. The thumb position
     *  is calculated by finding what fraction of the range
     *  the value represents, and then multiplying that by
     *  the logical track size minus the logical thumb size.
     */
    protected function valueToPosition(value:Number):Number;
    
    /**
     *  This function returns a position on the slider relative to its
     *  orientation and shape. The <code>localX</code> and <code>localY</code>
     *  values represent the location in the local coordinate system of the
     *  track. Subclasses must override this method and return the
     *  appropriate value for their situation. Values should not be clamped to
     *  the ends of the track, as that clamping will happen later, prior
     *  to setting the thumb position.
     */
    protected function pointToPosition(localX:Number, localY:Number):Number;

    /**
     *  This method positions the thumb button correctly, given
     *  the position. Subclasses should override this method to position 
     *  the thumb appropriately for their situation.
     */
    protected function positionThumb(thumbPos:Number):void {};
    
    /**
     *  This method sizes the thumb button correctly, given
     *  the thumbSize. Subclasses should override this method to size 
     *  the thumb appropriately for their situation.
     */
    protected function sizeThumb(thumbSize:Number):void {};

    /**
     *  This utility method calculates an appropriate size for the thumb
     *  button, given the current range, pageSize, and trackSize settings.
     *  Subclasses should override this to calculate the correct size in
     *  the units of position.
     * 
     *  @default 0
     */
    protected function calculateThumbSize():Number;

    /**
     *  Given a MouseEvent that contains where the thumb was dragged to and
     *  the previous value of the thumb, calculateNewValue() returns a new
     *  value based on the difference calculated in the mouseDown handler
     *  and the new position. The value is also restricted to the allowed
     *  values here. This method usually should not be overridden.
     */
    protected function calculateNewValue(prevValue:Number, event:MouseEvent):Number;

    //--------------------------------------------------------------------------
    // 
    // Event Handlers
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     *  Force the component to set itself up correctly now that the
     *  track is completely loaded.
     */
    protected function track_updateCompleteHandler(event:Event):void;

    //---------------------------------
    // Thumb dragging handlers
    //---------------------------------
    
    /**
     *  Handle mouse-down events on the scroll thumb. Records 
     *  the mouse down point in clickOffset.
     */
    protected function thumb_mouseDownHandler(event:MouseEvent):void;

    /**
     *  Capture mouse-move events anywhere on or off the stage.
     *  First, we calculate the new value based on the new position
     *  using calculateNewValue(). Then, we move the thumb to 
     *  the new value's position. Last, we set the value and
     *  dispatch a "change" event if the value changes. 
     */
    protected function system_mouseMoveHandler(event:MouseEvent):void;

    /**
     *  Handle mouse-up events anywhere on or off the stage.
     */
    protected function system_mouseUpHandler(event:MouseEvent):void;

    //---------------------------------
    // Track down handlers
    //---------------------------------
    
    /**
     *  Handle mouse-down events for the scroll track. Subclasses
     *  should override this method if they want the track to
     *  recognize mouse clicks on the track.
     */
    protected function track_mouseDownHandler(event:MouseEvent):void {};
}

}

B Features


Additional Implementation Details


none

Prototype Work


Compiler Work


none

Web Tier Compiler Impact


none

Flex Feature Dependencies


  • Depends on FxRange.

Backwards Compatibility


Syntax changes

None - New Class

Behavior

None

Warnings/Deprecation

None

Accessibility


Support Halo equivalent.

Performance


none.

Globalization


none

Localization


Compiler Features

none.

QA


Yes.


Flex SDK Project
Home
About
Versions
Downloads
Source
Bug Database
Submitting a Patch
Developer Documentation
Forums
License

Pages
Comments

Other Projects
BlazeDS
Cairngorm
Corelib
FlexUnit

More related projects ›
More Adobe projects ›
You must be logged in to comment.

 
Last Modified: 2008-10-28 12:56:04.0
Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki.

Company | Online Privacy Policy | Terms of Use | Contact Us | Accessibility | Report Piracy | Permissions & Trademarks

Copyright @ 2008 Adobe Systems Incorporated.
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.
Search powered by Google