MWCPolylineTool.h

Classes

MWCPolylineTool -- Base class for WorldCanvas event-based polyline tools (full description)

class MWCPolylineTool : public MultiWCTool, public DTVisible

Types

enum AdjustMode

Off
Def
Nothing exists yet
Ready
defining initial polyline
Move
polyline finished, no current activity
Resize
moving entire polyline

Interface

Public Members
MWCPolylineTool(Display::KeySym keysym = Display::K_Pointer_Button1, const Bool persistent = False)
virtual ~MWCPolylineTool()
virtual void disable()
virtual void reset(Bool skipRefresh=False)
Protected Members
virtual void keyPressed(const WCPositionEvent &ev)
virtual void moved(const WCMotionEvent &ev)
virtual void keyReleased(const WCPositionEvent &ev)
virtual void otherKeyPressed(const WCPositionEvent &ev)
virtual void draw(const WCRefreshEvent&)
virtual void doubleInside()
virtual void doubleOutside()
virtual void polylineReady()
virtual void get(Vector<Int> &x, Vector<Int> &y) const
virtual void get(Int &x, Int &y, const Int pt) const
void getLinear(Vector<Float> &x, Vector<Float> &y) const
Private Members
virtual void set(const Vector<Int> &x, const Vector<Int> &y)
virtual void set(const Int x, const Int y, const Int pt)
void pushPoint(Int x1, Int y1)
void popPoint()
Bool inPolyline(const Int &x, const Int &y) const
Bool inHandle(const Int &pt, const Int &x, const Int &y) const

Description

Review Status

Date Reviewed:
yyyy/mm/dd

  • WCTool

    Etymology

    MWCPolylineTool stands for Multi-WorldCanvas Polyline Tool

    Synopsis

    This class adds to its base MWCTool to provide a tool for drawing, reshaping and moving polylines on a WorldCanvas. While MWCPolylineTool is not abstract, it performs no useful function. The programmer should derive from this class and override the functions doubleInside and doubleOutside at the very least. These are called when the user double-clicks a particular key or mouse button inside or outside an existing polyline respectively. It is up to the programmer to decide what these events mean, but it is recommended that an internal double- click correspond to the main action of the tool, eg. emitting the polyline vertices to the application, and that an external double-click correspond to a secondary action of the tool, if indeed there are additional actions suitable to the tool.

    The polyline is drawn by clicking at each of the vertices, and clicking again on the last to complete the polyline. Once drawn, the vertices can be moved by dragging their handles, and the entire polyline relocated by dragging inside the polyline. The polyline is removed from the display when the Esc key is pressed.

    Example

    Motivation

    Many activities on the WorldCanvas will be based on the user drawing a polyline and using the polyline in some operation.

    To Do

    Member Description

    MWCPolylineTool(Display::KeySym keysym = Display::K_Pointer_Button1, const Bool persistent = False)

    Constructor

    virtual ~MWCPolylineTool()

    Destructor

    virtual void disable()

    Switch the tool off - this calls the base class disable, and then erases the polyline if it's around

    virtual void reset(Bool skipRefresh=False)

    reset to non-existent, non-active polyline. Refreshes if necessary to erase (unless skipRefresh==True). (Does not unregister from WCs or disable future event handling).

    virtual void keyPressed(const WCPositionEvent &ev)
    virtual void moved(const WCMotionEvent &ev)
    virtual void keyReleased(const WCPositionEvent &ev)
    virtual void otherKeyPressed(const WCPositionEvent &ev)

    Functions called by the base class event handling operators--and normally only those. This is the input that controls the polyline's appearance and action. When the polyline is ready and double-click is received, the doubleInside/Outside routine is invoked.

    virtual void draw(const WCRefreshEvent&)

    draw the polyline (if any) on the object's currently active WC. Only to be called by the base class refresh event handler. Derived objects should use refresh() if they need to redraw, but even that is normally handled automatically by this class.

    virtual void doubleInside()
    virtual void doubleOutside()

    Output callback functions--to be overridden in derived class as needed. Called when there is a double click inside/outside the polyline

    virtual void polylineReady()

    Function called when the polyline is ready and not being edited. (Useful for e.g. slicing).

    virtual void get(Vector<Int> &x, Vector<Int> &y) const
    virtual void get(Int &x, Int &y, const Int pt) const
    void getLinear(Vector<Float> &x, Vector<Float> &y) const

    Retrieve polyline vertices, or a single vertex, in screen pixels. Valid results during the callback functions; to be used by them, as well as internally.

    virtual void set(const Vector<Int> &x, const Vector<Int> &y)

    Set the polyline vertices. itsNPoints should already be set, and x and y must contain (at least) this many points.

    virtual void set(const Int x, const Int y, const Int pt)

    replace a single vertex.

    void pushPoint(Int x1, Int y1)
    void popPoint()

    push/pop last vertex

    Bool inPolyline(const Int &x, const Int &y) const

    are we inside the polyline?

    Bool inHandle(const Int &pt, const Int &x, const Int &y) const

    are we within the specified handle?

    enum AdjustMode

    state of the polyline tool