MWCCrosshairTool.h

Classes

MWCCrosshairTool -- Base class for MultiWorldCanvas event-based crosshair tools. (full description)

class MWCCrosshairTool : public MultiWCTool, public DTVisible

Interface

Public Members
MWCCrosshairTool(Display::KeySym keysym = Display::K_Pointer_Button1, const Bool persistent = True)
virtual ~MWCCrosshairTool()
virtual void get(Int &x, Int &y) const
virtual void disable()
virtual void reset(Bool skipRefresh=False)
virtual void handleEvent(DisplayEvent& ev)
Protected Members
virtual void keyPressed(const WCPositionEvent &ev)
virtual void keyReleased(const WCPositionEvent &ev)
virtual void otherKeyPressed(const WCPositionEvent &ev)
virtual void moved(const WCMotionEvent &ev)
virtual void draw(const WCRefreshEvent&)
virtual void crosshairReady(const String& evtype)
Private Members
virtual void set(Int x, Int y)

Description

Review Status

Date Reviewed:
yyyy/mm/dd

  • WCTool

    Etymology

    MWCCrosshairTool stands for MultiWorldCanvas Crosshair Tool.

    Synopsis

    This class adds to its base MWCTool to provide a tool for placing and moving a crosshair on a WorldCanvas. While MWCCrosshairTool is not abstract, it performs no useful function. The programmer should derive from this class, and override the crosshairReady function, which is called when the mouse button is pressed, moved, or released within a WC draw area where events are handled. The get() function then retrieves the crosshair position in screen pixels.

    The crosshair will track the mouse as long as it is within the WC draw area and the button is pressed. The persistent parameter determines whether the crosshair remains visible once the button is released. The crosshair is removed when it is dragged off the draw area or the Esc key is pressed within the WC.

    Example

    Motivation

    Many activities on the WorldCanvas will be based on the user causing some action by placing or moving a crosshair. Emitted positions are to be caught by some external process or method.

    To Do

    Member Description

    MWCCrosshairTool(Display::KeySym keysym = Display::K_Pointer_Button1, const Bool persistent = True)

    Constructor specifies the button to respond to, and whether the crosshair should remain on screen after the button is released. Base class methods must also be called to register event handling for the desired WorldCanvas[es].

    virtual ~MWCCrosshairTool()

    Destructor.

    virtual void get(Int &x, Int &y) const

    Retrieve the crosshair position in pixels. A derived crosshairReady() routine would use this.

    virtual void disable()

    Switch the tool off: this calls the base class disable to turn off event handling, and then erases the crosshair if necessary.

    virtual void reset(Bool skipRefresh=False)

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

    virtual void handleEvent(DisplayEvent& ev)

    handle events, via new-style interface. Currently just for reset event.

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

    Functions called by the base class mouse/kbd event handling operators-- and normally only those. This is the input that controls the crosshair's action. When the crosshair is ready (positioned on the draw area) the crosshairReady() routine is called.

    virtual void draw(const WCRefreshEvent&)

    draw the crosshair 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.

    virtual void crosshairReady(const String& evtype)

    Called when the crosshair position has been chosen. Override to handle the crosshair-position-ready 'event'. evtype is "down" "move" or "up" depending on the state of the mouse leading to this event.

    virtual void set(Int x, Int y)

    Set the current position from pixel coordinates. To do: reset the tool when the WC CS (linToWorld) transformation changes. (There is a WorldCoordinateChange RefreshReason, but it is not currently used when WC CS/Coordinatehandlers are set/changed).