class CCL::Scale

Overview

A Scale is used to scale data for display on a pixel-oriented canvas with scroll and zoom support. More…

#include <scale.h>

class Scale:
    public CCL::Object,
    public CCL::IScale,
    public CCL::IParamObserver
{
public:
    // fields

    IndependentResolution maxZoom;
    CLASS_INTERFACE2 (IScale, IParamObserver, Object) protected double unitsPerPixel;
    Coord visibleLength;
    Coord offset;
    ScrollParam* scrollParam;
    FloatParam* zoomParam;
    bool reversed;
    double previousScrollPosition;

    // construction

    Scale (
        Unit numUnits = 100,
        double unitsPerPixel = 1.,
        Coord visibleLength = 1,
        Coord offset = 0,
        bool reversed = false,
        Orientation orientation = kVertical
    );

    // methods

    DECLARE_CLASS (Scale, Object);
    PROPERTY_VARIABLE (Orientation, orientation, Orientation);
    IndependentResolution PROPERTY_VARIABLE (float, minZoom, MinZoom);
    IndependentResolution MaxZoom void setNumUnits (int units);
    void setReversed (bool _reversed);
    void setTotalLength (Coord newLength);
    Coord getTotalLength () const;
    void setOffset (Coord newOffset);
    Coord getOffset () const;
    Coord getMaxOffset () const;
    float getOffsetNormalized () const;
    void setOffsetNormalized (float newNormOffset);
    void setVisibleLength (Coord newLength);
    Coord getVisibleLength () const;
    void getVisibleUnits (Unit& start, Unit& end);
    void setVisibleStartUnit (Unit start);
    void setVisibleEndUnit (Unit end);
    void makeUnitVisible (Unit unit);
    void setUnitsPerPixel (double newUnitsPerPixel);
    double getUnitsPerPixel () const;
    void setPixelPerUnit (Coord pixelPerUnit);
    Coord getPixelPerUnit () const;
    void getMinMaxUnitsPerPixel (double& minUnitsPerPixel, double& maxUnitsPerPixel) const;
    void setZoomFactor (float newZoom);
    float getZoomFactor () const;
    void center (int unit, Coord pixelOffset = 0);
    int getCenter () const;
    void applyMouseWheel (const MouseWheelEvent& event);
    IParameter* getScrollParam ();
    IParameter* getZoomParam ();
    virtual tbool CCL_API paramChanged (IParameter* param);
    virtual void CCL_API paramEdit (IParameter* param, tbool begin);
    virtual Coord unitToPixel (Unit value) const;
    virtual Unit pixelToUnit (Coord position) const;

    virtual void getExtent (
        Unit start,
        Unit end,
        Coord& startCoord,
        Coord& endCoord
    ) const;

    virtual Unit getNumUnits () const;
    virtual bool isReversed () const;
    virtual IFormatter* createFormatter () const;
    virtual void storeSettings (Attributes& attr) const;
    virtual void restoreSettings (Attributes& attr);
    Coord boundOffset (Coord newOffset) const;
};

Inherited Members

public:
    // typedefs

    typedef CStringRef MemberID;
    typedef int Unit;

    // methods

    virtual tresult CCL_API queryInterface (UIDRef iid, void** ptr) = 0;
    virtual unsigned int CCL_API retain () = 0;
    virtual unsigned int CCL_API release () = 0;
    Unknown& operator = (const Unknown&);
    unsigned int getRetainCount () const;
    virtual Object*CCL_API revealObject (const void* moduleAddress) = 0;
    virtual void CCL_API addObserver (IObserver* observer) = 0;
    virtual void CCL_API removeObserver (IObserver* observer) = 0;
    virtual void CCL_API signal (MessageRef msg) = 0;
    virtual void CCL_API deferSignal (IMessage* msg) = 0;
    static ISubject void addObserver (IUnknown* unknown, IObserver* observer);
    static void removeObserver (IUnknown* unknown, IObserver* observer);
    virtual void CCL_API notify (ISubject* subject, MessageRef msg) = 0;

    static IObserver void notify (
        IUnknown* unknown,
        ISubject* subject,
        MessageRef msg
    );

    virtual const ITypeInfo&CCL_API getTypeInfo () const = 0;
    virtual tbool CCL_API getProperty (Variant& var, MemberID propertyId) const = 0;
    virtual tbool CCL_API setProperty (MemberID propertyId, const Variant& var) = 0;
    virtual tbool CCL_API getPropertyNames (IPropertyCollector& collector) const = 0;
    virtual tbool CCL_API invokeMethod (Variant& returnValue, MessageRef msg) = 0;
    DECLARE_BASE_CLASS (Object);
    virtual void CCL_API removeObserver (IObserver* observer);
    virtual void CCL_API signal (MessageRef msg);
    virtual void CCL_API deferSignal (IMessage* msg);
    virtual void deferChanged ();
    virtual void CCL_API notify (ISubject* subject, MessageRef msg);
    virtual bool equals (const Object& obj) const;
    virtual int compare (const Object& obj) const;
    virtual bool load (const Storage& storage);
    virtual bool save (const Storage& storage) const;
    virtual bool save (const OutputStorage& storage) const;
    virtual bool toString (String& string, int flags = 0) const;
    virtual int getHashCode (int size) const;
    IUnknown* asUnknown ();
    static void addGarbageCollected (Object* obj, bool globalScope = true);
    static void deferDestruction (Object* obj);
    static const void* getModuleAddress ();
    virtual Coord unitToPixel (Unit value) const = 0;
    virtual Unit pixelToUnit (Coord position) const = 0;

    virtual void getExtent (
        Unit start,
        Unit end,
        Coord& startCoord,
        Coord& endCoord
    ) const = 0;

    virtual Unit getNumUnits () const = 0;
    virtual bool isReversed () const = 0;
    virtual IFormatter* createFormatter () const = 0;
    virtual tbool CCL_API paramChanged (IParameter* param) = 0;
    virtual void CCL_API paramEdit (IParameter* param, tbool begin) = 0;

Detailed Documentation

A Scale is used to scale data for display on a pixel-oriented canvas with scroll and zoom support.

Fields

CLASS_INTERFACE2 (IScale, IParamObserver, Object) protected double unitsPerPixel

< number of total data units

data units per pixel

Coord visibleLength

visible length in pixels

Coord offset

offset in pixels

ScrollParam* scrollParam

scroll parameter

FloatParam* zoomParam

zoom parameter

bool reversed

scale is reversed

double previousScrollPosition

used to keep scroll position stable when numUnits changes

Methods

IndependentResolution PROPERTY_VARIABLE (float, minZoom, MinZoom)

< true if resolution should not be bound to visible length

IndependentResolution MaxZoom void setNumUnits (int units)

< max zoom in unit per pixels

void setTotalLength (Coord newLength)

make full data range visible

Coord getTotalLength () const

returns full length in pixels

void setOffset (Coord newOffset)

offset is bound to its maximum

Coord getOffset () const

returns current offset in pixels

Coord getMaxOffset () const

returns maximum offset in pixels

float getOffsetNormalized () const

returns normalized offset (0..1)

void setOffsetNormalized (float newNormOffset)

set offset from normalized float

void setVisibleLength (Coord newLength)

offset and/or resolution are adjusted if necessary

Coord getVisibleLength () const

returns currently visible length in pixels

void getVisibleUnits (Unit& start, Unit& end)

returns currently visible range in units

void setVisibleStartUnit (Unit start)

make visible range start at given unit

void setVisibleEndUnit (Unit end)

make visible range end at given unit

void setUnitsPerPixel (double newUnitsPerPixel)

set new resolution

double getUnitsPerPixel () const

returns current resolution

void setPixelPerUnit (Coord pixelPerUnit)

inverse of setUnitsPerPixel

Coord getPixelPerUnit () const

inverse of getUnitsPerPixel

void getMinMaxUnitsPerPixel (double& minUnitsPerPixel, double& maxUnitsPerPixel) const

unitsPerPixel for zoom 0 and zoom 1

void setZoomFactor (float newZoom)

zoom is normalized (0..1)

float getZoomFactor () const

returns normalized zoom factor

void center (int unit, Coord pixelOffset = 0)

center the scale around the supplied unit, optional adding pixels for exact placement

void applyMouseWheel (const MouseWheelEvent& event)

view implementation helper

virtual tbool CCL_API paramChanged (IParameter* param)

The given parameter changed its value, usually caused by user interaction.

virtual void CCL_API paramEdit (IParameter* param, tbool begin)

The user started or ended editing the value.

virtual Coord unitToPixel (Unit value) const

Convert from data unit to pixel position.

virtual Unit pixelToUnit (Coord position) const

Convert pixel position to data unit.

virtual void getExtent (
    Unit start,
    Unit end,
    Coord& startCoord,
    Coord& endCoord
) const

Get pixel extent from data units.

virtual Unit getNumUnits () const

Get number of total data units.

virtual bool isReversed () const

Check if scale is reversed (unit counting from max down to zero).

virtual IFormatter* createFormatter () const

Create a formatter for values of this scale (optional).