ClickManager class
class ClickManager { static final Property<ClickManager> _clickManagerProperty = new Property<ClickManager>("_clickManager"); static final Property<bool> _isClickableProperty = new Property<bool>("isClickable", false); static final AttachedEvent<ElementMouseEventArgs> _clickEvent = new AttachedEvent<ElementMouseEventArgs>('clickEvent'); static final AttachedEvent<ElementMouseEventArgs> _mouseDownEvent = new AttachedEvent<ElementMouseEventArgs>('mouseDown'); static final AttachedEvent<ElementMouseEventArgs> _mouseUpEvent = new AttachedEvent<ElementMouseEventArgs>('mouseUp'); static final AttachedEvent<ElementMouseEventArgs> _mouseMoveEvent = new AttachedEvent<ElementMouseEventArgs>('mouseMove'); static final AttachedEvent _mouseOutEvent = new AttachedEvent('mouseOut'); final Stage _stage; PElement _mouseDownElement; factory ClickManager(Stage stage) { requireArgumentNotNull(stage, 'stage'); return _clickManagerProperty.get(stage, (s) { return new ClickManager._internal(s); }); } ClickManager._internal(this._stage) { assert(!_clickManagerProperty.isSet(this._stage)); _stage._canvas.on.mouseMove.add(_mouseMove); _stage._canvas.on.mouseOut.add(_mouseOut); _stage._canvas.on.mouseUp.add(_mouseUp); _stage._canvas.on.mouseDown.add(_mouseDown); } static void setClickable(PElement element, bool value) { assert(element != null); assert(value != null); if(value) { _isClickableProperty.set(element, true); } else { _isClickableProperty.clear(element); } } static bool getClickable(PElement element) { assert(element != null); return _isClickableProperty.get(element); } static GlobalId addHandler(PElement element, Action1<ElementMouseEventArgs> handler) { return _clickEvent.addHandler(element, handler); } static bool removeHandler(PElement obj, GlobalId handlerId) { return _clickEvent.removeHandler(obj, handlerId); } static GlobalId addMouseMoveHandler(PElement obj, Action1<ElementMouseEventArgs> handler) { return _mouseMoveEvent.addHandler(obj, handler); } static bool removeMouseMoveHandler(PElement obj, GlobalId handlerId) { return _mouseMoveEvent.removeHandler(obj, handlerId); } static GlobalId addMouseUpHandler(PElement obj, Action1<ElementMouseEventArgs> handler) { return _mouseUpEvent.addHandler(obj, handler); } static bool removeMouseUpHandler(PElement obj, GlobalId handlerId) { return _mouseUpEvent.removeHandler(obj, handlerId); } static GlobalId addMouseDownHandler(PElement obj, Action1<ElementMouseEventArgs> handler) { return _mouseDownEvent.addHandler(obj, handler); } static bool removeMouseDownHandler(PElement obj, GlobalId handlerId) { return _mouseDownEvent.removeHandler(obj, handlerId); } static GlobalId addMouseOutHandler(Stage obj, Action1<ElementMouseEventArgs> handler) { return _mouseOutEvent.addHandler(obj, handler); } static bool removeMouseOutHandler(Stage obj, GlobalId handlerId) { return _mouseOutEvent.removeHandler(obj, handlerId); } void _mouseMove(MouseEvent e) { final items = _updateMouseLocation(getMouseEventCoordinate(e)); if(items.length > 0) { final args = new ElementMouseEventArgs(items[0], e); items.forEach((e) => _mouseMoveEvent.fireEvent(e, args)); } } void _mouseOut(MouseEvent e) { _updateMouseLocation(null); _mouseOutEvent.fireEvent(_stage, EventArgs.empty); } void _mouseUp(MouseEvent e) { // TODO: this does not handle the case where: // 1) the mouse left the element // 2) mouse up // 3) mouse down (outside the element) // 4) mouse up on the down element // Weird edge case, but important for comeletness :-/ // Mouse capture anyone? final hits = _updateMouseLocation(getMouseEventCoordinate(e)); final upElement = $(hits).firstOrDefault((e) { return _isClickableProperty.get(e); }); if(upElement != null) { _doMouseUp(upElement, e); // handle click if(upElement == _mouseDownElement) { _doClick(upElement, e); } _mouseDownElement = null; } } void _mouseDown(MouseEvent e) { final coord = getMouseEventCoordinate(e); final hits = _updateMouseLocation(coord); _mouseDownElement = $(hits).firstOrDefault((e) { return _isClickableProperty.get(e); }); if(_mouseDownElement != null) { _doMouseDown(_mouseDownElement, e); } } List<PElement> _updateMouseLocation(Coordinate value) { return Mouse.markMouseOver(_stage, value); } void _doMouseDown(PElement element, MouseEvent e) { assert(element != null); final args = new ElementMouseEventArgs(element, e); _mouseDownEvent.fireEvent(element, args); } void _doMouseUp(PElement element, MouseEvent e) { assert(element != null); final args = new ElementMouseEventArgs(element, e); _mouseUpEvent.fireEvent(element, args); } void _doClick(PElement element, MouseEvent e) { assert(element != null); final args = new ElementMouseEventArgs(element, e); _clickEvent.fireEvent(element, args); } }
Constructors
factory ClickManager(Stage stage) #
factory ClickManager(Stage stage) { requireArgumentNotNull(stage, 'stage'); return _clickManagerProperty.get(stage, (s) { return new ClickManager._internal(s); }); }
new ClickManager._internal(Stage _stage) #
ClickManager._internal(this._stage) { assert(!_clickManagerProperty.isSet(this._stage)); _stage._canvas.on.mouseMove.add(_mouseMove); _stage._canvas.on.mouseOut.add(_mouseOut); _stage._canvas.on.mouseUp.add(_mouseUp); _stage._canvas.on.mouseDown.add(_mouseDown); }
Static Methods
void setClickable(PElement element, bool value) #
static void setClickable(PElement element, bool value) { assert(element != null); assert(value != null); if(value) { _isClickableProperty.set(element, true); } else { _isClickableProperty.clear(element); } }
bool getClickable(PElement element) #
static bool getClickable(PElement element) { assert(element != null); return _isClickableProperty.get(element); }
GlobalId addHandler(PElement element, Action1 handler) #
static GlobalId addHandler(PElement element, Action1<ElementMouseEventArgs> handler) { return _clickEvent.addHandler(element, handler); }
bool removeHandler(PElement obj, GlobalId handlerId) #
static bool removeHandler(PElement obj, GlobalId handlerId) { return _clickEvent.removeHandler(obj, handlerId); }
GlobalId addMouseMoveHandler(PElement obj, Action1 handler) #
static GlobalId addMouseMoveHandler(PElement obj, Action1<ElementMouseEventArgs> handler) { return _mouseMoveEvent.addHandler(obj, handler); }
bool removeMouseMoveHandler(PElement obj, GlobalId handlerId) #
static bool removeMouseMoveHandler(PElement obj, GlobalId handlerId) { return _mouseMoveEvent.removeHandler(obj, handlerId); }
GlobalId addMouseUpHandler(PElement obj, Action1 handler) #
static GlobalId addMouseUpHandler(PElement obj, Action1<ElementMouseEventArgs> handler) { return _mouseUpEvent.addHandler(obj, handler); }
bool removeMouseUpHandler(PElement obj, GlobalId handlerId) #
static bool removeMouseUpHandler(PElement obj, GlobalId handlerId) { return _mouseUpEvent.removeHandler(obj, handlerId); }
GlobalId addMouseDownHandler(PElement obj, Action1 handler) #
static GlobalId addMouseDownHandler(PElement obj, Action1<ElementMouseEventArgs> handler) { return _mouseDownEvent.addHandler(obj, handler); }
bool removeMouseDownHandler(PElement obj, GlobalId handlerId) #
static bool removeMouseDownHandler(PElement obj, GlobalId handlerId) { return _mouseDownEvent.removeHandler(obj, handlerId); }
Properties
final Type runtimeType #
A representation of the runtime type of the object.
external Type get runtimeType;
Operators
bool operator ==(other) #
The equality operator.
The default behavior for all Object
s is to return true if and
only if this
and
other are the same object.
If a subclass overrides the equality operator it should override
the hashCode
method as well to maintain consistency.
bool operator ==(other) => identical(this, other);
Methods
factory ClickManager(Stage stage) #
factory ClickManager(Stage stage) { requireArgumentNotNull(stage, 'stage'); return _clickManagerProperty.get(stage, (s) { return new ClickManager._internal(s); }); }
new ClickManager._internal(Stage _stage) #
ClickManager._internal(this._stage) { assert(!_clickManagerProperty.isSet(this._stage)); _stage._canvas.on.mouseMove.add(_mouseMove); _stage._canvas.on.mouseOut.add(_mouseOut); _stage._canvas.on.mouseUp.add(_mouseUp); _stage._canvas.on.mouseDown.add(_mouseDown); }
int hashCode() #
Get a hash code for this object.
All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator ==
. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.
If a subclass overrides hashCode
it should override the
equality operator as well to maintain consistency.
external int hashCode();
noSuchMethod(String name, List args) #
noSuchMethod
is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to noSuchMethod
. If noSuchMethod
returns a value, that value becomes the result of the original
invocation.
The default behavior of noSuchMethod
is to throw a
noSuchMethodError
.
external Dynamic noSuchMethod(String name, List args);
const Object() #
Creates a new Object
instance.
Object
instances have no meaningful state, and are only useful
through their identity. An Object
instance is equal to itself
only.
const Object();
String toString() #
Returns a string representation of this object.
external String toString();