/// <summary> /// Gets the appropriate form adapter for the supplied component /// </summary> /// <param name="component"></param> /// <returns></returns> public static IFormAdapter GetAdapter(Component component) { Type type = component.GetType(); if (!Adapters.ContainsKey(type)) { Debug.LogWarning("Unknown form adapter for: " + component.GetType()); return(null); } return(Adapters[type]); }
private static void OnMouseUp(Event e) { SystemEventDispatcher.Instance.RemoveEventListener(MouseEvent.MOUSE_UP, OnMouseUp); SystemEventDispatcher.Instance.RemoveEventListener(MouseEvent.MOUSE_DRAG, OnMouseDrag); ChangeCursorTo(CursorType.Normal); MouseEvent me = (MouseEvent)e; bool dropAccepted = null != _acceptedTarget; //_proxy.Visible = false; _overlay.Visible = false; var newBounds = dropAccepted ? Rectangle.FromPositionAndSize(me.GlobalPosition, new Point(0, 0)) : _dragInitiator.Transform.GlobalBounds; DragProxyTween tween = new DragProxyTween(_proxy, _proxy.Bounds, newBounds) { Callback = delegate(IAnimation anim) { //Debug.Log("*** Finished"); Component proxy = (Component)anim.Target; proxy.Visible = false; DragDropStage.Instance.RemoveChild(proxy); } }; tween.Play(_proxy); RemoveCursor(); if (null != _acceptedTarget) { #if DEBUG if (DebugMode) { Debug.Log("DragEvent.DRAG_DROP: " + _acceptedTarget.GetType().Name); } #endif DragEvent de = BuildEvent(DragEvent.DRAG_DROP); _acceptedTarget.DispatchEvent(de); } DragEvent dragCompleteEvent = BuildEvent(DragEvent.DRAG_COMPLETE); _dragInitiator.DispatchEvent(dragCompleteEvent); _acceptedTarget = null; _lastDragOverComponent = null; _dragging = false; _dragInitiator = null; _dragOverComponent = null; }
/// <summary> /// Instantiates /// </summary> /// <param name="childAdapter"></param> /// <param name="register"></param> public virtual void DoInstantiate(ComponentAdapter childAdapter, bool register) { if (!childAdapter.Instantiated) { childAdapter.DoInstantiate(register); } var container = Component as IContentChildList; if (null == container) { Debug.LogError(Component.GetType().Name + " cannot host children"); return; } container.AddContentChild(childAdapter.Component); }
private static void OnMouseDrag(Event e) { #if DEBUG if (DebugMode) Debug.Log("DragDropManager.OnMouseDrag: " + _dragInitiator); #endif MouseEvent input = (MouseEvent)e; DragEvent de; /** * 1) Check for drag start * */ if (!_dragging) // if not yet dragging { _dragOverComponent = null; _dragging = true; // we're dragging now if (null != _dragInitiator) // if dragging something { #if DEBUG if (DebugMode) Debug.Log("DragEvent.DRAG_START: " + _dragInitiator); #endif de = BuildEvent(DragEvent.DRAG_START); _dragInitiator.DispatchEvent(de); } return; } _dragOverComponent = CoordinateProcessor.GetComponentUnderCoordinatesOnAllStages(input.GlobalPosition, delegate(DisplayListMember dlm) { Component component = dlm as Component; return null != component && component.MouseEnabled; // && !(component is Stage); // commented 20130307 }, true, true) as Component; // stopOnDisabled, stopOnInvisible bool isDragEnter = null != _dragOverComponent && _dragOverComponent != _lastDragOverComponent && _dragInitiator != null && _dragInitiator != _dragOverComponent; /** * 2) Check for drag enter * */ if (isDragEnter) { // nullify accepted target, and allow the user to react on DRAG_ENTER event (to call AcceptDragDrop) _acceptedTarget = null; _action = Action.None; //Debug.Log("DragEvent.DRAG_ENTER: " + _dragOverComponent.GetType().Name); #if DEBUG if (DebugMode) Debug.Log("DragEvent.DRAG_ENTER: " + _dragOverComponent.GetType().Name); #endif // dispatch DragEvent.DRAG_EXIT on _lastDragOverComponent if (null != _lastDragOverComponent) { de = BuildEvent(DragEvent.DRAG_EXIT); _lastDragOverComponent.DispatchEvent(de); } // dispatch DragEvent.DRAG_ENTER on _dragOverComponent de = BuildEvent(DragEvent.DRAG_ENTER); _dragOverComponent.DispatchEvent(de); // set _lastDragOverComponent _lastDragOverComponent = _dragOverComponent; } /** * 3) Handle feedback to the user * By this point, if the user was subscribed to DragEvent.DRAG_ENTER, he could have react with AcceptDragDrop() and (optionally) ShowFeedback() * */ // check if the user has accepted drag and drop if (null != _acceptedTarget) { // if drop is accepted, show overlay, and show CursorType.AcceptDrop cursor Overlay.Visible = _overlayShouldBeVisible; //_overlay.SetBounds(_acceptedTarget.GlobalBounds); // fix? .MoveBy(new Point(-1, 0)), //Overlay.Bounds = (Rectangle)_acceptedTarget.Transform.GlobalBounds.Clone(); // consider cloning bounds 20120415 if (_feedbackShouldBeVisible) { if (Action.None == _action) ChangeCursorTo(CursorType.AcceptDrop); else ProcessFeedback(_action); } else ChangeCursorTo(CursorType.Normal); } else { // if drop is rejected (meaning not accepted by developer), hide overlay, and show CursorType.RejectDrop cursor Overlay.Visible = false; if (_feedbackShouldBeVisible) ChangeCursorTo(CursorType.RejectDrop); else ChangeCursorTo(CursorType.Normal); } /** * 4) Move proxy * */ _proxy.X = input.GlobalPosition.X + Offset.X; _proxy.Y = input.GlobalPosition.Y + Offset.Y; _proxy.ValidateNow(); }
private static void OnMouseDrag(Event e) { #if DEBUG if (DebugMode) { Debug.Log("DragDropManager.OnMouseDrag: " + _dragInitiator); } #endif MouseEvent input = (MouseEvent)e; DragEvent de; /** * 1) Check for drag start * */ if (!_dragging) // if not yet dragging { _dragOverComponent = null; _dragging = true; // we're dragging now if (null != _dragInitiator) // if dragging something { #if DEBUG if (DebugMode) { Debug.Log("DragEvent.DRAG_START: " + _dragInitiator); } #endif de = BuildEvent(DragEvent.DRAG_START); _dragInitiator.DispatchEvent(de); } return; } _dragOverComponent = CoordinateProcessor.GetComponentUnderCoordinatesOnAllStages(input.GlobalPosition, delegate(DisplayListMember dlm) { Component component = dlm as Component; return(null != component && component.MouseEnabled); // && !(component is Stage); // commented 20130307 }, true, true) as Component; // stopOnDisabled, stopOnInvisible bool isDragEnter = null != _dragOverComponent && _dragOverComponent != _lastDragOverComponent && _dragInitiator != null && _dragInitiator != _dragOverComponent; /** * 2) Check for drag enter * */ if (isDragEnter) { // nullify accepted target, and allow the user to react on DRAG_ENTER event (to call AcceptDragDrop) _acceptedTarget = null; _action = Action.None; //Debug.Log("DragEvent.DRAG_ENTER: " + _dragOverComponent.GetType().Name); #if DEBUG if (DebugMode) { Debug.Log("DragEvent.DRAG_ENTER: " + _dragOverComponent.GetType().Name); } #endif // dispatch DragEvent.DRAG_EXIT on _lastDragOverComponent if (null != _lastDragOverComponent) { de = BuildEvent(DragEvent.DRAG_EXIT); _lastDragOverComponent.DispatchEvent(de); } // dispatch DragEvent.DRAG_ENTER on _dragOverComponent de = BuildEvent(DragEvent.DRAG_ENTER); _dragOverComponent.DispatchEvent(de); // set _lastDragOverComponent _lastDragOverComponent = _dragOverComponent; } /** * 3) Handle feedback to the user * By this point, if the user was subscribed to DragEvent.DRAG_ENTER, he could have react with AcceptDragDrop() and (optionally) ShowFeedback() * */ // check if the user has accepted drag and drop if (null != _acceptedTarget) { // if drop is accepted, show overlay, and show CursorType.AcceptDrop cursor Overlay.Visible = _overlayShouldBeVisible; //_overlay.SetBounds(_acceptedTarget.GlobalBounds); // fix? .MoveBy(new Point(-1, 0)), //Overlay.Bounds = (Rectangle)_acceptedTarget.Transform.GlobalBounds.Clone(); // consider cloning bounds 20120415 if (_feedbackShouldBeVisible) { if (Action.None == _action) { ChangeCursorTo(CursorType.AcceptDrop); } else { ProcessFeedback(_action); } } else { ChangeCursorTo(CursorType.Normal); } } else { // if drop is rejected (meaning not accepted by developer), hide overlay, and show CursorType.RejectDrop cursor Overlay.Visible = false; if (_feedbackShouldBeVisible) { ChangeCursorTo(CursorType.RejectDrop); } else { ChangeCursorTo(CursorType.Normal); } } /** * 4) Move proxy * */ _proxy.X = input.GlobalPosition.X + Offset.X; _proxy.Y = input.GlobalPosition.Y + Offset.Y; _proxy.ValidateNow(); }
/// <summary> /// Gets the appropriate form adapter for the supplied component /// </summary> /// <param name="component"></param> /// <returns></returns> public static IFormAdapter GetAdapter(Component component) { Type type = component.GetType(); if (!Adapters.ContainsKey(type)) { Debug.LogWarning("Unknown form adapter for: " + component.GetType()); return null; } return Adapters[type]; }