Example #1
0
        private void OnImageMouseDown(object sender, MouseButtonEventArgs e)
        {
            Point ptMouse = e.GetPosition((IInputElement)sender);

            if (e.ChangedButton == MouseButton.Left)
            {
                m_dragState = DragState.LeftStarted;

                BeeImg.StartRect.Left   = ptMouse.X;
                BeeImg.StartRect.Top    = ptMouse.Y;
                BeeImg.StartRect.Width  = 1;
                BeeImg.StartRect.Height = 1;
                BeeImg.Edited           = true;
            }
            else
            {
                m_dragState = DragState.RightStarted;

                BeeImg.EndRect.Left   = ptMouse.X;
                BeeImg.EndRect.Top    = ptMouse.Y;
                BeeImg.EndRect.Width  = 1;
                BeeImg.EndRect.Height = 1;
                BeeImg.Edited         = true;
            }
        }
Example #2
0
        private void ShowEraseDuringDrag(DragState state, MSet <LLShape> adorners, IEnumerable <Shape> eraseSet, List <PointT> simplified, bool cancel)
        {
            DiagramControl.EraseLineStyle.LineColor = Color.FromArgb(128, Control.BackColor);
            var eraseLine = new LLPolyline(DiagramControl.EraseLineStyle, simplified);

            adorners.Add(eraseLine);

            if (cancel)
            {
                eraseLine.Style = Control.LineStyle;
                Control.BeginRemoveAnimation(adorners);
                adorners.Clear();
                state.IsComplete = true;
            }
            else
            {
                // Show which shapes are erased by drawing them in the background color
                foreach (Shape s in eraseSet)
                {
                    Shape s_ = s.Clone();
                    s_.Style           = (DiagramDrawStyle)s.Style.Clone();
                    s_.Style.FillColor = s_.Style.LineColor = s_.Style.TextColor = Color.FromArgb(192, Control.BackColor);
                    // avoid an outline artifact, in which color from the edges of the
                    // original shape bleeds through by a variable amount that depends
                    // on subpixel offsets.
                    s_.Style.LineWidth++;
                    s_.AddLLShapesTo(adorners);
                }
            }
        }
Example #3
0
        /// <inheritdoc/>
        protected override void OnPreviewMouseMove(MouseEventArgs e)
        {
            base.OnPreviewMouseMove(e);

            Point position = e.GetPosition(this);

            if (AllowMouseDrag && dragState == DragState.Starting && e.LeftButton == MouseButtonState.Pressed)
            {
                double dx = Math.Abs(position.X - mouseDownPosition.X);
                double dy = Math.Abs(position.Y - mouseDownPosition.Y);
                dragOrientation = dx >= dy ? Orientation.Horizontal : Orientation.Vertical;

                if (dx > SystemParameters.MinimumHorizontalDragDistance || dy > SystemParameters.MinimumVerticalDragDistance)
                {
                    var root = this.FindVisualRoot() as FrameworkElement;
                    if (root != null)
                    {
                        root.IsKeyboardFocusWithinChanged += RootParentIsKeyboardFocusWithinChanged;
                    }

                    dragState = DragState.Dragging;
                    e.MouseDevice.Capture(this);
                    var handler = DragStarted;
                    if (handler != null)
                    {
                        handler(this, new DragStartedEventArgs(mouseDownPosition.X, mouseDownPosition.Y));
                    }

                    SelectAll();
                    if (adorner != null)
                    {
                        adorner.SetOrientation(dragOrientation);
                    }
                }
            }

            if (dragState == DragState.Dragging)
            {
                double delta;

                if (dragOrientation == Orientation.Horizontal)
                {
                    delta = position.X - mouseDownPosition.X;
                }
                else
                {
                    delta = mouseDownPosition.Y - position.Y;
                }

                var newValue = Value + delta * SmallChange;

                SetCurrentValue(ValueProperty, newValue);

                if (MouseValidationTrigger == MouseValidationTrigger.OnMouseMove)
                {
                    Validate();
                }
                NativeHelper.SetCursorPos(PointToScreen(mouseDownPosition));
            }
        }
Example #4
0
        protected override void OnMouseUp(MouseEventArgs ea)
        {
            if (!SafeToRender)
            {
                return;
            }
            mouseWorldPos = WindowToWorld(ea.X, ea.Y);

            if (dragState == DragState.Panning)
            {
                dragState = DragState.None;
                Capture   = false;
            }
            else if (dragState == DragState.RotateScale)
            {
                dragState = DragState.None;
                Capture   = false;
            }
            else if (dragState == DragState.Dragging && ea.Button == MouseButtons.Left)
            {
                dragState = DragState.None;
                Capture   = false;
                UpdateHover(WindowToScreen(ea.X, ea.Y));
            }
        }
Example #5
0
        /// <inheritdoc/>
        protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseUp(e);

            if (ReferenceEquals(e.MouseDevice.Captured, this))
            {
                e.MouseDevice.Capture(null);
            }

            if (dragState == DragState.Starting)
            {
                Select(0, Text.Length);
                if (!IsFocused)
                {
                    Keyboard.Focus(this);
                }
            }
            else if (dragState == DragState.Dragging && AllowMouseDrag)
            {
                if (adorner != null)
                {
                    var adornerLayer = AdornerLayer.GetAdornerLayer(this);
                    if (adornerLayer != null)
                    {
                        adornerLayer.Remove(adorner);
                        adorner = null;
                    }
                }
                Validate();
            }

            Mouse.OverrideCursor = null;
            dragState            = DragState.None;
        }
Example #6
0
        void DropPanelOnCurrentForm(MainForm formPanelIsDroppedOn)
        {
            dragState = DragState.Drop;
            parentForm.IOController.OpenPanelInCurrentForm(panelBeingRelocated, formPanelIsDroppedOn);

            FinishLayout();
        }
Example #7
0
        private Shape DetectNewShapeDuringDrag(DragState state, MSet <LLShape> adorners, out bool potentialSelection)
        {
            potentialSelection = false;
            Shape newShape = null;

            adorners.Add(new LLPolyline(DiagramControl.MouseLineStyle, state.Points.Select(p => p.Point).AsList())
            {
                ZOrder = 0x100
            });

            if (state.Points.Count == 1)
            {
                newShape = new Marker(Control.BoxStyle, state.FirstPoint, Control.MarkerRadius, Control.MarkerType);
            }
            else if (state.MousePoints.Count > 1)
            {
#if DEBUG
                List <Section> ss = BreakIntoSections(state);
                EliminateTinySections(ss, 10 + (int)(ss.Sum(s => s.LengthPx) * 0.05));
                foreach (Section s in ss)
                {
                    adorners.Add(new LLMarker(new DrawStyle {
                        LineColor = Color.Gainsboro, FillColor = Color.Gray
                    }, s.StartSS, 5, MarkerPolygon.Circle));
                }
#endif

                newShape = RecognizeBoxOrLines(state, out potentialSelection);
            }
            return(newShape);
        }
Example #8
0
        protected TileControlCore()
        {
            m_dragState = DragState.None;

            this.MinHeight = 64;
            this.MinWidth = 64;
        }
Example #9
0
            public override void Update(Transform _transform, Transform _target, DragState _dragState)
            {
                if (Input.GetMouseButton(0))
                {
                    if (_dragState.valid)
                    {
                        Vector3    _delta = Input.mousePosition - _dragState.startMousePos;
                        Quaternion _q1    = Quaternion.AngleAxis(Mathf.Floor(0.5f * _delta.x), Vector3.up);
                        Quaternion _q2    = Quaternion.AngleAxis(Mathf.Floor(-0.5f * _delta.y), Vector3.right);

                        _transform.rotation = _dragState.startRotate * _q2 * _q1;

                        Control.UpdatePosition(_transform, _target, _dragState.startDist);
                    }
                    else
                    {
                        _dragState.startMousePos = Input.mousePosition;
                        _dragState.startRotate   = _transform.rotation;
                        _dragState.startDist     = (_transform.position - _target.position).magnitude;
                        _dragState.valid         = true;
                    }
                }
                else
                {
                    if (_dragState.valid)
                    {
                        //on mouse up
                    }
                    _dragState.valid = false;
                }
            }
        /// <inheritdoc />
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            // We have to release the mouse first, in case Validate triggers a Detach of this behavior.
            ReleaseMouseCapture();
            if (dragState == DragState.Starting)
            {
                AssociatedObject.Select(0, AssociatedObject.Text.Length);
                if (!AssociatedObject.IsFocused)
                {
                    Keyboard.Focus(AssociatedObject);
                }
            }
            else if (dragState == DragState.Dragging && AssociatedObject.AllowMouseDrag)
            {
                if (adorner != null)
                {
                    var adornerLayer = AdornerLayer.GetAdornerLayer(AssociatedObject);
                    if (adornerLayer != null)
                    {
                        adornerLayer.Remove(adorner);
                        adorner = null;
                    }
                }
                AssociatedObject.Validate();
            }

            e.Handled            = true;
            Mouse.OverrideCursor = null;
            dragState            = DragState.None;
        }
Example #11
0
        private void glControl1_MouseDown(object sender, MouseEventArgs e)
        {
            switch (e.Button)
            {
            case MouseButtons.Left:
                drag = DragState.Pan;
                break;

            case MouseButtons.None:
                drag = DragState.None;
                break;

            case MouseButtons.Right:
                drag = DragState.Zoom;
                break;

            case MouseButtons.Middle:
                drag = DragState.Rotate;
                break;

            default:
                break;
            }
            startDrag = e.Location;
        }
Example #12
0
        private void SetDragBegin(PointerEventData eventData)
        {
            if (this.preferences.draggable == false)
            {
                return;
            }
            if (this.dragState != DragState.None)
            {
                return;
            }
            if (eventData.pointerCurrentRaycast.gameObject == null)
            {
                return;
            }

            this.dragTempParent.Clear();
            eventData.pointerCurrentRaycast.gameObject.GetComponentsInParent <WindowLayoutElement>(includeInactive: true, results: this.dragTempParent);

            if (this.dragTempParent.Count > 0)
            {
                var layoutElement = this.dragTempParent[0];
                if (this.preferences.dragTag == LayoutTag.None || this.preferences.dragTag == layoutElement.tag)
                {
                    this.dragState = DragState.Begin;

                    this.OnMoveBegin(eventData);
                }
            }
        }
Example #13
0
        Shape RecognizeBoxOrLines(DragState state, out bool potentialSelection)
        {
            // Okay so this is a rectangular recognizer that only sees things at
            // 45-degree angles.
            List <Section> sections1 = BreakIntoSections(state);
            List <Section> sections2 = new List <Section>(sections1);

            // Figure out if a box or a line string is a better interpretation
            EliminateTinySections(sections1, 10);
            LineOrArrow line  = InterpretAsPolyline(state, sections1);
            Shape       shape = line;

            // Conditions to detect a box:
            // 0. If both endpoints are anchored, a box cannot be formed.
            // continued below...
            EliminateTinySections(sections2, 10 + (int)(sections1.Sum(s => s.LengthPx) * 0.05));
            if (line.ToAnchor == null || line.FromAnchor == null || line.FromAnchor.Equals(line.ToAnchor))
            {
                shape = (Shape)TryInterpretAsBox(sections2, (line.FromAnchor ?? line.ToAnchor) != null, out potentialSelection) ?? line;
            }
            else
            {
                potentialSelection = false;
            }
            return(shape);
        }
Example #14
0
 private void EndAllDrag()
 {
     _dragState     = DragState.Normal;
     Cursor         = Cursors.Default;
     _mouseDownMark = null;
     //Invalidate();
 }
Example #15
0
    public void OnBeginDrag(PointerEventData eventData)
    {
        var clickPosition = isOverlayCanvas
                        ? (Vector3)eventData.position
                        : mainCamera.ScreenToWorldPoint(eventData.position);

        passDragEvents = Math.Abs(eventData.delta.x) < Math.Abs(eventData.delta.y);

        if (passDragEvents)
        {
            PassDragEvents <IBeginDragHandler>(x => x.OnBeginDrag(eventData));
        }
        else
        {
            dragStartPosition   = clickPosition;
            dragStartMinValue01 = GetValue01(minHandle.position.x);
            dragStartMaxValue01 = GetValue01(maxHandle.position.x);

            // set drag state
            if (dragStartPosition.x < minHandle.position.x || IsWithinRect(minHandle, dragStartPosition))
            {
                dragState = DragState.Min;
                minHandle.SetAsLastSibling();
            }
            else if (dragStartPosition.x > maxHandle.position.x || IsWithinRect(maxHandle, dragStartPosition))
            {
                dragState = DragState.Max;
                maxHandle.SetAsLastSibling();
            }
            else
            {
                dragState = DragState.Both;
            }
        }
    }
    //Mouse is over object and left mouse has been clicked so set state to drag mode
    public void StartDrag()
    {
        Vector3 diff = objectTransform.position - Camera.main.ScreenToWorldPoint(Input.mousePosition);

        offset    = new Vector3(diff.x, diff.y, 0f);
        dragState = DragState.Held;
    }
    // Update is called once per frame
    void Update()
    {
        switch (dragState)
        {
        case DragState.Released:
            //Code here has moved to StartDrag function and ray cast section of Input Manager update function
            break;

        case DragState.Held:
            //If object is held set position to mouse position (within bounds of area) above all other objects in area
            Vector2 mousePosition  = mainCamera.ScreenToWorldPoint(Input.mousePosition) + offset;
            Vector3 objectPosition = new Vector3(Mathf.Clamp(mousePosition.x, minX, maxX), Mathf.Clamp(mousePosition.y, minY, maxY), -1f);
            objectTransform.localPosition = objectPosition;

            //If left mouse is released set state to not being held
            if (Input.GetMouseButtonUp(0))
            {
                objectTransform.localPosition = new Vector3(objectTransform.position.x, objectTransform.position.y, 0f);
                dragState = DragState.Released;
            }
            break;

        default:
            break;
        }
    }
Example #18
0
    public void OnEndDrag(PointerEventData eventData)
    {
        CalculateSwipeDirection(deltaValue.x);

        if (dragState == DragState.RIGHT)
        {
            //MoveToRightWithDownAnimation();
            onRightCompleted.Invoke();
            return;
        }
        else if (dragState == DragState.LEFT)
        {
            //MoveToLeftWithDownAnimation();
            onLeftCompleted.Invoke();
            return;
        }
        else if (dragState == DragState.MIDDLE)
        {
            onMiddleCompleted.Invoke();
        }

        endDragPos = eventData.position;

        deltaValue = Vector2.zero;

        dragState = DragState.NONE;
    }
Example #19
0
        /// <inheritdoc/>
        protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseDown(e);

            if (!IsContentHostPart(e.OriginalSource))
            {
                return;
            }

            if (AllowMouseDrag && IsReadOnly == false && IsFocused == false)
            {
                dragState = DragState.Starting;

                if (adorner == null)
                {
                    adorner = new DragDirectionAdorner(this, contentHost.ActualWidth);
                    var adornerLayer = AdornerLayer.GetAdornerLayer(this);
                    if (adornerLayer != null)
                    {
                        adornerLayer.Add(adorner);
                    }
                }

                mouseDownPosition = e.GetPosition(this);

                Mouse.OverrideCursor = Cursors.None;
                e.Handled            = true;
            }
        }
        public MinMaxSlider(float minValue, float maxValue, float minLimit, float maxLimit)
        {
            m_DragState = DragState.NoThumb;

            Add(new VisualElement() { name = "TrackElement" });

            dragElement = new VisualElement() { name = "DragElement" };
            dragElement.RegisterCallback<GeometryChangedEvent>(UpdateDragElementPosition);
            Add(dragElement);

            // For a better handling of the cursor style, children elements are created so that the style is automatic with the uss.
            dragMinThumb = new VisualElement();
            dragMaxThumb = new VisualElement();
            dragMinThumb.AddToClassList("thumbelement");
            dragMaxThumb.AddToClassList("thumbelement");
            dragElement.Add(dragMinThumb);
            dragElement.Add(dragMaxThumb);

            clampedDragger = new ClampedDragger<float>(null, SetSliderValueFromClick, SetSliderValueFromDrag);
            this.AddManipulator(clampedDragger);


            m_MinLimit = minLimit;
            m_MaxLimit = maxLimit;
            m_Value = ClampValues(new Vector2(minValue, maxValue));
            UpdateDragElementPosition();
        }
Example #21
0
    protected override void OnUpdate()
    {
        DragState state =
            Input.GetMouseButtonDown(0)   ?       DragState.Start         :
            Input.GetMouseButtonUp(0)             ?       DragState.Finish        :
            Input.GetMouseButton(0)               ?       DragState.Continue      :
            DragState.None
        ;

        switch (state)
        {
        case DragState.Start:           DragStart();            break;

        case DragState.Continue:        DragContinue();         break;

        case DragState.Finish:
            DragContinue();
            DragFinish();
            break;

        default:
            return;
        }

        _mouseDragLast_w = Utilities.Mouse_w;
    }
    void OnMouseOver()
    {
        if (!canStartDrag())
        {
            CursorManager.giveUpCursorFocus(this);
            return;
        }

        if (Input.GetMouseButton(0))
        {
            CursorManager.takeCursorFocus(this, downCursor, Vector2.zero);
        }
        else
        {
            CursorManager.takeCursorFocus(this, upCursor, Vector2.zero);
        }

        // If mouse is pressed
        if (state != DragState.DRAG && Input.GetMouseButtonDown(0))
        {
            state             = DragState.DRAG;
            dragStartMousePos = Input.mousePosition;

            initDrag(dragStartMousePos);

            foreach (DragModifier m in modifiers())
            {
                m.startDrag();
            }
        }
    }
Example #23
0
 private void WaitForDragMove(Point gridLocation)
 {
     // begin the dragging process -- calculate a area outside which a drag (move) starts
     _dragState      = DragState.Waiting;
     _ignoreDragArea = new Rectangle(gridLocation.X - DragThreshold, gridLocation.Y - DragThreshold, DragThreshold * 2,
                                     DragThreshold * 2);
 }
Example #24
0
        public override void DragStart(OpenGLControlWrapper w, MouseEventArgs e)
        {
            _lastLocation  = e.Location;
            _startPosition = _eye - _lookat;
            var circleDistance = 0.4d * Math.Min(w.Width, w.Height);
            var dx             = e.X - w.Width / 2;
            var dy             = e.Y - w.Height / 2;
            var d = Math.Sqrt(dx * dx + dy * dy);

            if (d > circleDistance)
            {
                _dragging = DragState.RotatingUp;
            }
            else
            {
                switch (e.Button)
                {
                case MouseButtons.Left:
                    _dragging = DragState.ArcBalling;
                    break;

                case MouseButtons.Right:
                    _dragging = DragState.Scaling;
                    break;

                default:
                    _dragging = DragState.Idle;
                    break;
                }
            }
        }
Example #25
0
 private void BeginDragMove(Point location)
 {
     _dragState      = DragState.Moving;
     _ignoreDragArea = Rectangle.Empty;
     Cursor          = Cursors.Hand;
     BeginMoveResizeMarks(location);
 }
Example #26
0
        protected TileControlCore()
        {
            m_dragState = DragState.None;

            this.MinHeight = 64;
            this.MinWidth  = 64;
        }
Example #27
0
        /// <summary>Raises the <see cref="E:System.Windows.Forms.Control.MouseUp" /> event.</summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data. </param>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (_dragState == null)
            {
                return;
            }

            int dx = Math.Abs(e.Location.X - _dragState.Location.X);
            int dy = Math.Abs(e.Location.Y - _dragState.Location.Y);

            var link = _dragState.Link;

            _dragState = null;

            if (link == null)
            {
                return;
            }

            if (dx <= SystemInformation.DragSize.Width && dy <= SystemInformation.DragSize.Height)
            {
                var linkClickEventArgs = new LinkClickEventArgs(link);
                HandleLinkClick(linkClickEventArgs);
            }
        }
Example #28
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (m_dragState == DragState.None)
            {
                base.OnMouseMove(e);
                return;
            }

            Point pos = e.GetPosition(this);

            if (m_dragState == DragState.Captured)
            {
                if ((pos - m_dragStartPos).Length < 2)
                {
                    e.Handled = true;
                    return;
                }

                m_dragState = DragState.Dragging;

                if (this.DragStarted != null)
                {
                    this.DragStarted(m_dragStartPos);
                }
            }

            if (this.Dragging != null)
            {
                this.Dragging(pos);
            }

            e.Handled = true;
        }
Example #29
0
        private void HandleMouseUpForLinks(MouseEventArgs e)
        {
            if (_dragState == null)
            {
                return;
            }

            int dx = Math.Abs(e.Location.X - _dragState.Location.X);
            int dy = Math.Abs(e.Location.Y - _dragState.Location.Y);

            var link = _dragState.Link;

            _dragState = null;

            if (link == null)
            {
                return;
            }

            if (dx <= SystemInformation.DragSize.Width && dy <= SystemInformation.DragSize.Height)
            {
                var linkClickEventArgs = new LinkClickEventArgs(link);
                HandleLinkClick(linkClickEventArgs);
            }
        }
        /// <inheritdoc />
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            if (!IsContentHostPart(e.OriginalSource))
            {
                return;
            }

            if (!AssociatedObject.AllowMouseDrag || AssociatedObject.IsReadOnly || AssociatedObject.IsFocused)
            {
                return;
            }

            e.Handled = true;
            CaptureMouse();

            dragState            = DragState.Starting;
            Mouse.OverrideCursor = Cursors.None;
            mouseDownPosition    = e.GetPosition(AssociatedObject);

            if (adorner == null)
            {
                adorner = new DragDirectionAdorner(AssociatedObject, AssociatedObject.contentHost.ActualWidth);
                var adornerLayer = AdornerLayer.GetAdornerLayer(AssociatedObject);
                adornerLayer?.Add(adorner);
            }
        }
Example #31
0
        static List <Section> BreakIntoSections(DragState state)
        {
            var list = new List <Section>();
            var pts = state.MousePoints;
            int i = 1, j;

            for (; i < pts.Count; i = j)
            {
                int   angleMod8 = pts[i].AngleMod8;
                float length    = pts[i - 1].Point.To(pts[i].Point).Length();
                for (j = i + 1; j < pts.Count; j++)
                {
                    if (pts[j].AngleMod8 != angleMod8)
                    {
                        break;
                    }
                    length += pts[j - 1].Point.To(pts[j].Point).Length();
                }
                var startPt = pts[i - 1].Point;
                var endPt   = pts[j - 1].Point;
                list.Add(new Section
                {
                    AngleMod8 = angleMod8,
                    StartSS   = state._inputTransform.Transform(startPt),
                    EndSS     = state._inputTransform.Transform(endPt),
                    iStart    = i - 1,
                    iEnd      = j - 1,
                    LengthPx  = length
                });
            }
            return(list);
        }
Example #32
0
        public Draggable(Rectangle staticPosition)
        {
            currentPosition = staticPosition;
            this.staticPosition = staticPosition;
            dragState = DragState.Idle;

            Redraggable = true;
        }
	void OnEnable()
	{
		t = ((InteractivePrimitive)target);
		if(!t.sizing) return;
		t.GetComponent<Renderer>().enabled = false;
		dragState = DragState.None;

		Tools.current = Tool.Move;
	}
Example #34
0
        public void Reset()
        {
            if (_obj != null)
            {
                _obj.IsSelected = false;
                _obj.IsMoving = false;
            }

            _obj = null;
            _state = DragState.None;
            _pane = null;
        }
    private void endDrag()
    {
        int newSnapToIndex = initSnap();
        if (isActive)
            snapToIndex = newSnapToIndex;

        state = DragState.SNAP;
        foreach (DragModifier m in modifiers()) {
            m.endDrag();
            m.startSnap();
        }

        if (gameStateKey != null) {
            GameState.getInstance().put(gameStateKey, snapToIndex);
        }
    }
Example #36
0
 public bool AttemptBeginDrag(Point mousePosition)
 {
     if (dragState == DragState.Idle)
     {
         if (currentPosition.Contains(mousePosition))
         {
             dragState = DragState.Dragging;
             currentPosition.X = mousePosition.X - (int)(draggingTexture.Width / 2.0f);
             currentPosition.Y = mousePosition.Y - (int)(draggingTexture.Height / 2.0f);
             currentPosition.Width = draggingTexture.Width;
             currentPosition.Height = draggingTexture.Height;
             return true;
         }
         else
         {
             return false;
         }
     }
     else
     {
         return false;
     }
 }
Example #37
0
        public void circuitInkCanvas_StylusUp(object sender, StylusEventArgs e)
        {
            if (IsPieMenuVisible)
            {
                PieMenuHitTestEventArgs hitargs = new PieMenuHitTestEventArgs(e.GetPosition(this), e, PieMenuHitTestEventArgs.EventType.Up);
                hitPieMenuHandler(this, hitargs);
            }

            //Make Pie Menu Invisible
            PieMenuEventArgs args = new PieMenuEventArgs(false);
            triggerPieMenuHandler(this, args);

            Point mp2 = e.GetPosition(circuitInkCanvas);

            foreach (UIElement gate in circuitInkCanvas.Children)
            {
                if (gate is Gate)
                {
                    Gate g = gate as Gate;
                    Rect grect = new Rect(g.Margin.Left - 10, g.Margin.Top - 10, g.Width + 10, g.Height + 10);

                    bool condition = false;
                    condition = grect.Contains(mp2);
                    if (condition)
                    {
                        uigate_StylusUp(g ,e);
                        break;
                    }
                }else if(gate is ConnectedWire)
                {
                    HitTestResult result = VisualTreeHelper.HitTest(gate, mp2);
                    if(result != null)
                    {
                        Debug.WriteLine("Hit Test Wire circuitInkCanvas_StylusUp");
                        //Image stroke starts from one terminal and stop at this wire
                        //1. through this wire, create new wire to connect existing wire's 
                        //if stroke starts from input terminal from one gate, then search for input terminal from existing wire.
                        //otherwise stroke starts from the output termianl from one gate, then search for output terminal from existing wire. 
                        ConnectedWire myWire = gate as ConnectedWire;

                        //new wire's destination is mp2; new wire's orignal is ???
                        if (onGateStroke)
                        { 
                            //start the stroke from gate terminal
                            Gate.TerminalID tid = myWire.OriginTerminalID;

                            Gates.Terminal origin = null, dest = null;

                            if (tid.isInput && dragging == DragState.CONNECT_FROM &&
                                !wires.ContainsKey(new Gates.Terminal(tid.ID, tid.abgate)))
                            {
                                origin = new Gates.Terminal(beginTID.ID, beginTID.abgate);
                                dest = new Gates.Terminal(tid.ID, tid.abgate);
                            }


                            if (!tid.isInput && dragging == DragState.CONNECT_TO)
                            {
                                origin = new Gates.Terminal(tid.ID, tid.abgate);
                                dest = new Gates.Terminal(beginTID.ID, beginTID.abgate);

                            }

                            if (origin != null)
                            {
                                c[dest] = origin;
                                UndoRedo.ConnectWire cw = new UndoRedo.ConnectWire(c, origin, dest);

                                if (UndoProvider != null)
                                    UndoProvider.Add(cw);
                            }
                        }
                        break;
                    }
                }
            }

            dragging = DragState.NONE;
            //dragSelect.Width = 0;
            //dragSelect.Height = 0;
            //dragSelect.Margin = new Thickness(0, 0, 0, 0);
            //dragSelect.Visibility = Visibility.Hidden;

            dragWire.Destination = new Point(0, 0);
            dragWire.Origin = new Point(0, 0);

            // unhightlight all
            foreach (Gates.AbstractGate ag in gates.Keys)
            {

                for (int i = 0; i < ag.Output.Length; i++)
                {
                    gates[ag].FindTerminal(false, i).t.Highlight = false;
                }

                for (int i = 0; i < ag.NumberOfInputs; i++)
                {
                    gates[ag].FindTerminal(true, i).t.Highlight = false;
                }
            }

            if (UndoProvider != null && moves != null && moves.Count > 0)
                UndoProvider.Add(moves);
            moves = null;

            ReadyToSelect = false;
        }
Example #38
0
        void uigate_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Point mp2 = e.GetPosition(circuitInkCanvas);

            if (IsReadOnly)
                return;

            Gate tg = (Gate)sender;
            // to avoid sticking on other gates, move this one to the top
            circuitInkCanvas.Children.Remove(tg);
            circuitInkCanvas.Children.Add(tg);

            if (!tg.Selected)
            {
                selected.Add(tg);
                ((GateLocation)tg.Tag).x = tg.Margin.Left;
                ((GateLocation)tg.Tag).y = tg.Margin.Top;
                tg.Selected = true;
            }

            Rect gRect = new Rect(tg.Margin.Left, tg.Margin.Top, tg.Width, tg.Height);
            
            foreach (Gate.TerminalID tid in tg)
            {
                Rect tRect = GetTerminalBounds(tg, gRect, tid);
                
                bool condition = tRect.Contains(mp2);
                // if (tid.t.IsMouseOver)
                //if (mp2.X >= tRect.Value.Left - 10 && mp2.X <= tRect.Value.Right + 10 
                //   && mp2.Y >= tRect.Value.Top - 10 && mp2.Y <= tRect.Value.Bottom + 10)
                if(condition)
                {
                    // ok, so are we connecting to or from
                    // is this an input or output?
                    if (tid.isInput)
                    {
                        // can only connect from an input
                        // if there is no other connection here
                        if (wires.ContainsKey(new Gates.Terminal(tid.ID, tid.abgate)))
                            continue;

                        dragging = DragState.CONNECT_TO;
                        dragWire.Value = false;

                        // highlight all terminals which provide output
                        foreach (Gates.AbstractGate ag in gates.Keys)
                        {
                            for (int i = 0; i < ag.Output.Length; i++)
                            {
                                gates[ag].FindTerminal(false, i).t.Highlight = true;
                            }
                        }
                    }
                    else
                    {
                        dragging = DragState.CONNECT_FROM;
                        // TODO: if the value of the output changes
                        // while being dragged, this won't update
                        dragWire.Value = tid.abgate.Output[tid.ID];


                        // highlight all terminals which accept input
                        // note this is all inputs NOT already connected
                        foreach (Gates.AbstractGate ag in gates.Keys)
                        {
                            for (int i = 0; i < ag.NumberOfInputs; i++)
                            {
                                if (c.GetSource(new Gates.Terminal(i, ag)) == null)
                                    gates[ag].FindTerminal(true, i).t.Highlight = true;
                            }
                        }
                    }
                    beginTID = tid;

                    dragWire.Destination = tid.t.TranslatePoint(new Point(5, 5), circuitInkCanvas);
                    dragWire.Origin = tid.t.TranslatePoint(new Point(5, 5), circuitInkCanvas);

                    e.Handled = true;
                    return;

                }
            }

            dragging = DragState.MOVE;

            moves = new UndoRedo.Transaction(
                            (e.LeftButton == MouseButtonState.Pressed ?
                            "Move" : "Rotate") + " " +
                            (selected.Count == 1 ?
                            "Gate" : selected.Count.ToString() + " Gates"));
            
            e.Handled = true;
        }
Example #39
0
        /*
        void circuitInkCanvas_StylusMove(object sender, StylusEventArgs e)
        {
            if (IsReadOnly)
                return;

            TimeSpan ts = _stopWatch.Elapsed;
            if (ts.TotalSeconds - _lastElapsedSecs> 2)
            {
                _stopWatch.Stop();
                _stopWatch = Stopwatch.StartNew();
                MessageBox.Show("Popup");
            }

            Point mp2 = e.GetPosition(circuitInkCanvas);

            circuitInkCanvas.BringIntoView(new Rect(new Point(mp2.X - 10, mp2.Y - 10),
                new Point(mp2.X + 10, mp2.Y + 10)));

            switch (dragging)
            {
                case DragState.CONNECT_FROM:
                    dragWire.Destination = mp2;
                    break;
                case DragState.CONNECT_TO:
                    dragWire.Origin = mp2;
                    break;
                case DragState.MOVE:
                    #region DragState is Move
                    foreach (Gate g in selected)
                    {
                        //g.RenderTransform = new TranslateTransform(mp2.X, mp2.Y);
                        //Direct Move
                        
                            double dx = mp2.X - mp.X;
                            double dy = mp2.Y - mp.Y;
                            ((GateLocation)g.Tag).x = ((GateLocation)g.Tag).x + dx;
                            ((GateLocation)g.Tag).y = ((GateLocation)g.Tag).y + dy;
                            double cx = ((GateLocation)g.Tag).x % GRID_SIZE;
                            double cy = ((GateLocation)g.Tag).y % GRID_SIZE;

                            Point op = new Point(g.Margin.Left, g.Margin.Top);

                            if ((Math.Abs(cx) < DELTA_SNAP || Math.Abs(GRID_SIZE - cx) < DELTA_SNAP) &&
                                (Math.Abs(cy) < DELTA_SNAP || Math.Abs(GRID_SIZE - cy) < DELTA_SNAP))
                            {
                                g.Margin = new Thickness(Math.Round(g.Margin.Left / GRID_SIZE) * GRID_SIZE,
                                    Math.Round(g.Margin.Top / GRID_SIZE) * GRID_SIZE, 0, 0);

                            }
                            else
                            {
                                g.Margin = new Thickness(((GateLocation)g.Tag).x, ((GateLocation)g.Tag).y, 0, 0);
                            }

                            Point np = new Point(g.Margin.Left, g.Margin.Top);
                            if (op != np)
                                moves.Add(new UndoRedo.MoveGate(g, this, op, np));

                            SizeCanvas();
                            g.BringIntoView(); // still needed because gate larger than 20px block

                    }

                    UpdateWireConnections();
                    break;
                    #endregion
                case DragState.NONE:
                    #region Drag State is None
                    // not dragging
                    // creating a selection rectangle
                    if (ReadyToSelect)
                    {
                        double x1 = Math.Min(mp2.X, sp.X);
                        double width = Math.Abs(mp2.X - sp.X);

                        double y1 = Math.Min(mp2.Y, sp.Y);
                        double height = Math.Abs(mp2.Y - sp.Y);

                        dragSelect.Margin = new Thickness(x1, y1, 0, 0);
                        dragSelect.Width = width;
                        dragSelect.Height = height;
                        dragSelect.Visibility = Visibility.Visible;

                        // select any gates inside the rectangle
                        Rect select = new Rect(x1, y1, width, height);
                        foreach (Gate g in gates.Values)
                        {
                            Rect grect = new Rect(g.Margin.Left, g.Margin.Top, g.Width, g.Height);
                            if (select.IntersectsWith(grect) && !g.Selected)
                            {
                                g.Selected = true;
                                selected.Add(g);
                            }

                            // this is not the same as just "not" or else the above
                            if (!select.IntersectsWith(grect) && g.Selected)
                            {
                                g.Selected = false;
                                selected.Remove(g);
                            }
                        }
                    }
                    break;
                    #endregion
            }
            mp = mp2;
        }
         * 
         * */
        
        /*
        void circuitInkCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (IsReadOnly)
                return;

            TimeSpan ts = _stopWatch.Elapsed;
            if (ts.TotalSeconds - _lastElapsedSecs > 2)
            {
                MessageBox.Show("Popup");
            }

            Point mp2 = e.GetPosition(circuitInkCanvas);

            circuitInkCanvas.BringIntoView(new Rect(new Point(mp2.X - 10, mp2.Y - 10),
                new Point(mp2.X + 10, mp2.Y + 10)));

            switch (dragging)
            {
                case DragState.CONNECT_FROM:
                    dragWire.Destination = mp2;
                    break;
                case DragState.CONNECT_TO:
                    dragWire.Origin = mp2;
                    break;
                case DragState.MOVE:
                    #region DragState is Move
                    foreach (Gate g in selected)
                    {
                        //g.RenderTransform = new TranslateTransform(mp2.X, mp2.Y);
                        //Direct Move
                        if (e.LeftButton == MouseButtonState.Pressed)
                        {
                            double dx = mp2.X - mp.X;
                            double dy = mp2.Y - mp.Y;
                            ((GateLocation)g.Tag).x = ((GateLocation)g.Tag).x + dx;
                            ((GateLocation)g.Tag).y = ((GateLocation)g.Tag).y + dy;
                            double cx = ((GateLocation)g.Tag).x % GRID_SIZE;
                            double cy = ((GateLocation)g.Tag).y % GRID_SIZE;

                            Point op = new Point(g.Margin.Left, g.Margin.Top);

                            if ((Math.Abs(cx) < DELTA_SNAP || Math.Abs(GRID_SIZE - cx) < DELTA_SNAP) &&
                                (Math.Abs(cy) < DELTA_SNAP || Math.Abs(GRID_SIZE - cy) < DELTA_SNAP))
                            {
                                g.Margin = new Thickness(Math.Round(g.Margin.Left / GRID_SIZE) * GRID_SIZE,
                                    Math.Round(g.Margin.Top / GRID_SIZE) * GRID_SIZE, 0, 0);

                            }
                            else
                            {
                                g.Margin = new Thickness(((GateLocation)g.Tag).x, ((GateLocation)g.Tag).y, 0, 0);
                            }

                            Point np = new Point(g.Margin.Left, g.Margin.Top);
                            if (op != np)
                                moves.Add(new UndoRedo.MoveGate(g, this, op, np));

                            SizeCanvas();
                            g.BringIntoView(); // still needed because gate larger than 20px block

                        }
                                               
                    }

                    UpdateWireConnections();
                    break;
                    #endregion
                case DragState.NONE:
                    #region Drag State is None
                        // not dragging
                        // creating a selection rectangle
                        if (ReadyToSelect)
                        {
                            double x1 = Math.Min(mp2.X, sp.X);
                            double width = Math.Abs(mp2.X - sp.X);

                            double y1 = Math.Min(mp2.Y, sp.Y);
                            double height = Math.Abs(mp2.Y - sp.Y);

                            dragSelect.Margin = new Thickness(x1, y1, 0, 0);
                            dragSelect.Width = width;
                            dragSelect.Height = height;
                            dragSelect.Visibility = Visibility.Visible;

                            // select any gates inside the rectangle
                            Rect select = new Rect(x1, y1, width, height);
                            foreach (Gate g in gates.Values)
                            {
                                Rect grect = new Rect(g.Margin.Left, g.Margin.Top, g.Width, g.Height);
                                if (select.IntersectsWith(grect) && !g.Selected)
                                {
                                    g.Selected = true;
                                    selected.Add(g);
                                }

                                // this is not the same as just "not" or else the above
                                if (!select.IntersectsWith(grect) && g.Selected)
                                {
                                    g.Selected = false;
                                    selected.Remove(g);
                                }
                            }
                        }
                        break;
                        #endregion 
            }
            mp = mp2;
        }
         * */

        /*
       void circuitInkCanvas_PreviewStylusDown(object sender, StylusDownEventArgs e)
       {
           if (EditingMode.currentEditingMode != EditingMode.EditingModeType.SketchLogicGate)
           {
               MessageBox.Show("Please Check Sketch Logic Diagram Radio Button", "TIP");
               return;
           }

           _lastElapsedSecs = _stopWatch.Elapsed.TotalSeconds;

           // only come here if the uigate doesn't handle it
           ClearSelection();

           Point mp2 = e.GetPosition(circuitInkCanvas);

           sp = new Point(mp2.X, mp2.Y);

           ReadyToSelect = true;

           onGateStroke = false;

           foreach (UIElement gate in circuitInkCanvas.Children)
           {
               if (gate is Gate)
               {
                   Gate g = gate as Gate;
                   Rect grect = new Rect(g.Margin.Left, g.Margin.Top, g.Width, g.Height);
                   if (mp2.X >= grect.Left && mp2.X <= grect.Right
                       && mp2.Y >= grect.Top && mp2.Y <= grect.Bottom)
                   {
                       onGateStroke = true;
                       uigate_MouseDown(g, e);

                       if (dragging == DragState.MOVE)
                       {
                           if (g is UIGates.UserInput)
                           {
                               UIGates.UserInput temp = g as UIGates.UserInput;
                               temp.r_MouseDown(this, e);
                           }
                       }
                       break;
                   }
               }
           }

           e.Handled = true;
       }
       */


        #endregion

        public void circuitInkCanvas_PreviewStylusMove(object sender, StylusEventArgs e)
        {
            if (IsReadOnly)
                return;

            Point mp2 = e.GetPosition(circuitInkCanvas);

            if (sender is ConnectedWire)
            {
                #region connectedWire Object

                onWireMoveStroke = true;

                ConnectedWire myWire = sender as ConnectedWire;

                Gate.TerminalID tid = myWire.OriginTerminalID;

                // ok, so are we connecting to or from
                // is this an input or output?
                if (tid.isInput)
                {
                    // can only connect from an input
                    // if there is no other connection here
                    //if (wires.ContainsKey(new Gates.Terminal(tid.ID, tid.abgate)))

                    dragging = DragState.CONNECT_TO;
                    dragWire.Value = false;

                    // highlight all terminals which provide output
                    foreach (Gates.AbstractGate ag in gates.Keys)
                    {
                        for (int i = 0; i < ag.Output.Length; i++)
                        {
                            gates[ag].FindTerminal(false, i).t.Highlight = true;
                        }
                    }
                }
                else
                {
                    dragging = DragState.CONNECT_FROM;
                    // TODO: if the value of the output changes
                    // while being dragged, this won't update
                    dragWire.Value = tid.abgate.Output[tid.ID];


                    // highlight all terminals which accept input
                    // note this is all inputs NOT already connected
                    foreach (Gates.AbstractGate ag in gates.Keys)
                    {
                        for (int i = 0; i < ag.NumberOfInputs; i++)
                        {
                            if (c.GetSource(new Gates.Terminal(i, ag)) == null)
                                gates[ag].FindTerminal(true, i).t.Highlight = true;
                        }
                    }
                }
                beginTID = tid;

                dragWire.Destination = tid.t.TranslatePoint(new Point(5, 5), circuitInkCanvas);
                dragWire.Origin = tid.t.TranslatePoint(new Point(5, 5), circuitInkCanvas);

                //if (dragging == DragState.MOVE)
                //{
                //    if (g is UIGates.UserInput)
                //    {
                //        UIGates.UserInput temp = g as UIGates.UserInput;
                //        temp.r_MouseDown(this, e);
                //    }
                //}
                //break;

                return;

                #endregion
            }

            circuitInkCanvas.BringIntoView(new Rect(new Point(mp2.X - 10, mp2.Y - 10),
                new Point(mp2.X + 10, mp2.Y + 10)));

            switch (dragging)
            {
                case DragState.CONNECT_FROM:

                    foreach (UIElement gate in circuitInkCanvas.Children)
                    {
                        if (gate is Gate)
                        {
                            Gate g = gate as Gate;
                            foreach (Gate.TerminalID tid in g)
                            {
                                tid.t.Background = Brushes.Transparent;
                            }
                         }
                    }
                   
                    // gate termination indication
                    foreach (UIElement gate in circuitInkCanvas.Children)
                    {
                        if (gate is Gate)
                        {
                            Gate g = gate as Gate;
                            Rect grect = new Rect(g.Margin.Left - 10, g.Margin.Top - 10, g.Width + 10, g.Height + 10);

                            bool condition = false;
                            condition = grect.Contains(mp2);
                            if (condition)
                            {
                                Rect gRect = new Rect(g.Margin.Left, g.Margin.Top, g.Width, g.Height);

                                foreach (Gate.TerminalID tid in g)
                                {
                                    Rect tRect = GetTerminalBounds(g, grect, tid);
                                    condition = tRect.Contains(mp2);
                                    if (condition)
                                    {
                                        tid.t.Background = Brushes.Yellow;
                                    }else
                                    {
                                        tid.t.Background = Brushes.Transparent;
                                    }
                                }
                            }
                        }
                    }
                    dragWire.Destination = mp2;
                    break;
                case DragState.CONNECT_TO:
                     foreach (UIElement gate in circuitInkCanvas.Children)
                    {
                        if (gate is Gate)
                        {
                            Gate g = gate as Gate;
                            foreach (Gate.TerminalID tid in g)
                            {
                                tid.t.Background = Brushes.Transparent;
                            }
                         }
                    }
                   
                    // gate termination indication
                    foreach (UIElement gate in circuitInkCanvas.Children)
                    {
                        if (gate is Gate)
                        {
                            Gate g = gate as Gate;
                            Rect grect = new Rect(g.Margin.Left - 10, g.Margin.Top - 10, g.Width + 10, g.Height + 10);

                            bool condition = false;
                            condition = grect.Contains(mp2);
                            if (condition)
                            {
                                Rect gRect = new Rect(g.Margin.Left, g.Margin.Top, g.Width, g.Height);

                                foreach (Gate.TerminalID tid in g)
                                {
                                    Rect tRect = GetTerminalBounds(g, grect, tid);
                                    condition = tRect.Contains(mp2);
                                    if (condition)
                                    {
                                        tid.t.Background = Brushes.Yellow;
                                    }else
                                    {
                                        tid.t.Background = Brushes.Transparent;
                                    }
                                }
                            }
                        }
                    }
                    dragWire.Origin = mp2;
                    break;
                case DragState.MOVE:
                    #region DragState is Move

                    foreach (Gate g in selected)
                    {
                        //g.RenderTransform = new TranslateTransform(mp2.X, mp2.Y);
                        //Direct Move

                        double dx = mp2.X - mp.X;
                        double dy = mp2.Y - mp.Y;
                        ((GateLocation)g.Tag).x = ((GateLocation)g.Tag).x + dx;
                        ((GateLocation)g.Tag).y = ((GateLocation)g.Tag).y + dy;
                        double cx = ((GateLocation)g.Tag).x % GRID_SIZE;
                        double cy = ((GateLocation)g.Tag).y % GRID_SIZE;

                        Point op = new Point(g.Margin.Left, g.Margin.Top);

                        if ((Math.Abs(cx) < DELTA_SNAP || Math.Abs(GRID_SIZE - cx) < DELTA_SNAP) &&
                            (Math.Abs(cy) < DELTA_SNAP || Math.Abs(GRID_SIZE - cy) < DELTA_SNAP))
                        {
                            g.Margin = new Thickness(Math.Round(g.Margin.Left / GRID_SIZE) * GRID_SIZE,
                                Math.Round(g.Margin.Top / GRID_SIZE) * GRID_SIZE, 0, 0);

                        }
                        else
                        {
                            g.Margin = new Thickness(((GateLocation)g.Tag).x, ((GateLocation)g.Tag).y, 0, 0);
                        }

                        Point np = new Point(g.Margin.Left, g.Margin.Top);
                        if (op != np)
                            moves.Add(new UndoRedo.MoveGate(g, this, op, np));

                        SizeCanvas();
                        g.BringIntoView(); // still needed because gate larger than 20px block

                    }

                    UpdateWireConnections();
                    break;
                    #endregion
                case DragState.NONE:
                    #region Drag State is None
                    // not dragging
                    // creating a selection rectangle
                    if (ReadyToSelect)
                    {
                        double x1 = Math.Min(mp2.X, sp.X);
                        double width = Math.Abs(mp2.X - sp.X);

                        double y1 = Math.Min(mp2.Y, sp.Y);
                        double height = Math.Abs(mp2.Y - sp.Y);

                        //dragSelect.Margin = new Thickness(x1, y1, 0, 0);
                        //dragSelect.Width = width;
                        //dragSelect.Height = height;
                        //dragSelect.Visibility = Visibility.Visible;

                        // select any gates inside the rectangle
                        Rect select = new Rect(x1, y1, width, height);
                        foreach (Gate g in gates.Values)
                        {
                            Rect grect = new Rect(g.Margin.Left, g.Margin.Top, g.Width, g.Height);
                            if (select.IntersectsWith(grect) && !g.Selected)
                            {
                                g.Selected = true;
                                selected.Add(g);
                            }

                            // this is not the same as just "not" or else the above
                            if (!select.IntersectsWith(grect) && g.Selected)
                            {
                                g.Selected = false;
                                selected.Remove(g);
                            }
                        }
                    }
                    break;
                    #endregion
            }

            mp = mp2;
        }
Example #40
0
    /// <summary>
    /// Surveillance des événements souris : lorsqu'un bouton est relâché
    /// </summary>
    /// <param name="e">descripteur de l'événement</param>
    protected override void OnMouseUp( MouseEventArgs e ) {
      DragState oldState = dragState;
      try {
        if ( IsDesignMode ) return;

        if ( e.Button != MouseButtons.Left ) return;
        dragState = DragState.None;
      }
      finally {
        if ( oldState != dragState ) Invalidate();
        base.OnMouseUp( e );
        if ( oldState == DragState.Dragging ) OnSelectedControlEndDrag();
      }
    }
Example #41
0
			public void Reset ()
			{
				State = DragState.None;
				Data = null;
				SupportedTypes = null;
				WillAccept = false;
			}
Example #42
0
 /// <summary>
 /// Surveillance des événements souris : lorsque la souris sort
 /// </summary>
 /// <param name="e">descripteur de l'événement</param>
 protected override void OnMouseLeave( EventArgs e ) {
   dragState = DragState.None;
   base.OnMouseLeave( e );
 }
Example #43
0
        /**
         * Updates the input handler.
         * This is called every frame by StateHandler.
         */
        public void UpdateInput()
        {
            if (timeCurve != null && timeCurve.length > 0)
            {
                float timeIndex = Time.time - changeTimeStart;
                if (timeCurve [timeCurve.length -1].time < timeIndex)
                {
                    SetTimeScale (timeCurve [timeCurve.length -1].time);
                    timeCurve = null;
                }
                else
                {
                    SetTimeScale (timeCurve.Evaluate (timeIndex));
                }
            }

            if (clickTime > 0f)
            {
                clickTime -= 4f * GetDeltaTime ();
            }
            if (clickTime < 0f)
            {
                clickTime = 0f;
            }

            if (doubleClickTime > 0f)
            {
                doubleClickTime -= 4f * GetDeltaTime ();
            }
            if (doubleClickTime < 0f)
            {
                doubleClickTime = 0f;
            }

            if (skipMovieKey != "" && InputGetButtonDown (skipMovieKey))
            {
                skipMovieKey = "";
            }

            if (KickStarter.stateHandler && KickStarter.settingsManager)
            {
                if (InputGetButtonDown ("ToggleCursor") && KickStarter.stateHandler.gameState == GameState.Normal)
                {
                    ToggleCursor ();
                }

                if (KickStarter.stateHandler.gameState == GameState.Cutscene && InputGetButtonDown ("EndCutscene"))
                {
                    KickStarter.actionListManager.EndCutscene ();
                }

                #if UNITY_EDITOR
                if (KickStarter.settingsManager.inputMethod == InputMethod.MouseAndKeyboard || KickStarter.settingsManager.inputMethod == InputMethod.TouchScreen)
                #else
                if (KickStarter.settingsManager.inputMethod == InputMethod.MouseAndKeyboard)
                #endif
                {
                    // Cursor position
                    bool shouldLockCursor = UnityVersionHandler.CursorLock;

                    if (!cursorIsLocked || KickStarter.stateHandler.gameState == AC.GameState.Paused || KickStarter.stateHandler.gameState == AC.GameState.DialogOptions || (freeAimLock && KickStarter.settingsManager.IsInFirstPerson ()))
                    {
                        if (shouldLockCursor)
                        {
                            shouldLockCursor = false;
                        }
                        mousePosition = InputMousePosition ();
                        freeAim = Vector2.zero;
                    }
                    else if (dragObject != null && KickStarter.settingsManager.IsInFirstPerson () && KickStarter.settingsManager.disableFreeAimWhenDragging)
                    {
                        if (shouldLockCursor)
                        {
                            shouldLockCursor = false;
                        }
                        mousePosition = InputMousePosition ();
                        freeAim = Vector2.zero;
                    }
                    else if (cursorIsLocked && KickStarter.stateHandler.gameState == GameState.Normal)
                    {
                        if (!shouldLockCursor && dragObject == null && KickStarter.settingsManager.IsInFirstPerson ())
                        {
                            shouldLockCursor = true;
                        }
                        mousePosition = new Vector2 (Screen.width / 2, Screen.height / 2);
                        freeAim = new Vector2 (InputGetAxis ("CursorHorizontal"), InputGetAxis ("CursorVertical"));
                    }

                    UnityVersionHandler.CursorLock = shouldLockCursor;

                    // Cursor state
                    if (mouseState == MouseState.Normal)
                    {
                        dragState = DragState.None;
                    }

                    if (InputGetMouseButtonDown (0) || InputGetButtonDown ("InteractionA"))
                    {
                        if (mouseState == MouseState.Normal)
                        {
                            if (CanDoubleClick ())
                            {
                                mouseState = MouseState.DoubleClick;
                                ResetClick ();
                            }
                            else if (CanClick ())
                            {
                                dragStartPosition = GetInvertedMouse ();
                                mouseState = MouseState.SingleClick;
                                ResetClick ();
                                ResetDoubleClick ();
                            }
                        }
                    }
                    else if (InputGetMouseButtonDown (1) || InputGetButtonDown ("InteractionB"))
                    {
                        mouseState = MouseState.RightClick;
                    }
                    else if (InputGetMouseButton (0) || InputGetButton ("InteractionA"))
                    {
                        mouseState = MouseState.HeldDown;
                        SetDragState ();
                    }
                    else
                    {
                        if (mouseState == MouseState.HeldDown && dragState == DragState.None && CanClick ())
                        {
                            mouseState = MouseState.LetGo;
                        }
                        else
                        {
                            ResetMouseClick ();
                        }
                    }

                    SetDoubleClickState ();

                    if (KickStarter.settingsManager.inputMethod == InputMethod.TouchScreen)
                    {
                        if (dragState == DragState.Player)
                        {
                            if (KickStarter.settingsManager.IsFirstPersonDragMovement ())
                            {
                                freeAim = new Vector2 (dragVector.x * KickStarter.settingsManager.freeAimTouchSpeed, 0f);
                            }
                            else
                            {
                                freeAim = new Vector2 (dragVector.x * KickStarter.settingsManager.freeAimTouchSpeed, -dragVector.y * KickStarter.settingsManager.freeAimTouchSpeed);
                            }
                        }
                        else
                        {
                            freeAim = Vector2.zero;
                        }
                    }
                }
                else if (KickStarter.settingsManager.inputMethod == InputMethod.TouchScreen)
                {
                    int touchCount = Input.touchCount;

                    // Cursor position
                    if (cursorIsLocked)
                    {
                        mousePosition = new Vector2 (Screen.width / 2f, Screen.height / 2f);
                    }
                    else if (touchCount > 0)
                    {
                        if (KickStarter.settingsManager.CanDragCursor ())
                        {
                            if (touchTime > touchThreshold)
                            {
                                Touch t = Input.GetTouch (0);
                                if (t.phase == TouchPhase.Moved && touchCount == 1)
                                {
                                    if (KickStarter.stateHandler.gameState == GameState.Paused)
                                    {
                                        mousePosition += t.deltaPosition * 1.7f;
                                    }
                                    else
                                    {
                                        mousePosition += t.deltaPosition * Time.deltaTime / t.deltaTime;
                                    }

                                    if (mousePosition.x < 0f)
                                    {
                                        mousePosition.x = 0f;
                                    }
                                    else if (mousePosition.x > Screen.width)
                                    {
                                        mousePosition.x = Screen.width;
                                    }
                                    if (mousePosition.y < 0f)
                                    {
                                        mousePosition.y = 0f;
                                    }
                                    else if (mousePosition.y > Screen.height)
                                    {
                                        mousePosition.y = Screen.height;
                                    }
                                }
                            }
                        }
                        else
                        {
                            mousePosition = Input.GetTouch (0).position;
                        }
                    }

                    // Cursor state
                    if (mouseState == MouseState.Normal)
                    {
                        dragState = DragState.None;
                    }

                    if (touchTime > 0f && touchTime < touchThreshold)
                        dragStartPosition = GetInvertedMouse ();

                    if ((touchCount == 1 && KickStarter.stateHandler.gameState == GameState.Cutscene && Input.GetTouch (0).phase == TouchPhase.Began)
                        || (touchCount == 1 && !KickStarter.settingsManager.CanDragCursor () && Input.GetTouch (0).phase == TouchPhase.Began)
                        || touchTime == -1f)
                    {
                        if (mouseState == MouseState.Normal)
                        {
                            dragStartPosition = GetInvertedMouse (); //

                            if (CanDoubleClick ())
                            {
                                mouseState = MouseState.DoubleClick;
                                ResetClick ();
                            }
                            else if (CanClick ())
                            {
                                dragStartPosition = GetInvertedMouse ();

                                mouseState = MouseState.SingleClick;
                                ResetClick ();
                                ResetDoubleClick ();
                            }
                        }
                    }
                    else if (touchCount == 2 && Input.GetTouch (1).phase == TouchPhase.Began)
                    {
                        mouseState = MouseState.RightClick;

                        if (KickStarter.settingsManager.IsFirstPersonDragComplex ())
                        {
                            dragStartPosition = GetInvertedMouse ();
                        }
                    }
                    else if (touchCount == 1 && (Input.GetTouch (0).phase == TouchPhase.Stationary || Input.GetTouch (0).phase == TouchPhase.Moved))
                    {
                        mouseState = MouseState.HeldDown;
                        SetDragState ();
                    }
                    else if (touchCount == 2 && (Input.GetTouch (0).phase == TouchPhase.Stationary || Input.GetTouch (0).phase == TouchPhase.Moved) && KickStarter.settingsManager.IsFirstPersonDragComplex ())
                    {
                        mouseState = MouseState.HeldDown;
                        SetDragStateTouchScreen ();
                    }
                    else
                    {
                        if (mouseState == MouseState.HeldDown && dragState == DragState.None && CanClick ())
                        {
                            mouseState = MouseState.LetGo;
                        }
                        else
                        {
                            ResetMouseClick ();
                        }
                    }

                    SetDoubleClickState ();

                    if (KickStarter.settingsManager.CanDragCursor ())
                    {
                        if (touchCount > 0)
                        {
                            touchTime += GetDeltaTime ();
                        }
                        else
                        {
                            if (touchTime > 0f && touchTime < touchThreshold)
                            {
                                touchTime = -1f;
                            }
                            else
                            {
                                touchTime = 0f;
                            }
                        }
                    }

                    if (dragState == DragState.Player)
                    {
                        if (KickStarter.settingsManager.IsFirstPersonDragMovement ())
                        {
                            freeAim = new Vector2 (dragVector.x * KickStarter.settingsManager.freeAimTouchSpeed, 0f);
                        }
                        else
                        {
                            freeAim = new Vector2 (dragVector.x * KickStarter.settingsManager.freeAimTouchSpeed, -dragVector.y * KickStarter.settingsManager.freeAimTouchSpeed);
                        }
                    }
                    else
                    {
                        freeAim = Vector2.zero; //
                    }
                }
                else if (KickStarter.settingsManager.inputMethod == InputMethod.KeyboardOrController)
                {
                    // Cursor position
                    if (cursorIsLocked && KickStarter.stateHandler.gameState == GameState.Normal)
                    {
                        mousePosition = new Vector2 (Screen.width / 2, Screen.height / 2);
                        freeAim = new Vector2 (InputGetAxis ("CursorHorizontal") * 50f, InputGetAxis ("CursorVertical") * 50f);
                    }
                    else
                    {
                        xboxCursor.x += InputGetAxis ("CursorHorizontal") * cursorMoveSpeed / Screen.width * 5000f;
                        xboxCursor.y += InputGetAxis ("CursorVertical") * cursorMoveSpeed / Screen.height * 5000f;

                        xboxCursor.x = Mathf.Clamp (xboxCursor.x, 0f, Screen.width);
                        xboxCursor.y = Mathf.Clamp (xboxCursor.y, 0f, Screen.height);

                        mousePosition = xboxCursor;
                        freeAim = Vector2.zero;
                    }

                    // Cursor state
                    if (mouseState == MouseState.Normal)
                    {
                        dragState = DragState.None;
                    }

                    if (InputGetButtonDown ("InteractionA"))
                    {
                        if (mouseState == MouseState.Normal)
                        {
                            if (CanDoubleClick ())
                            {
                                mouseState = MouseState.DoubleClick;
                                ResetClick ();
                            }
                            else if (CanClick ())
                            {
                                dragStartPosition = GetInvertedMouse ();

                                mouseState = MouseState.SingleClick;
                                ResetClick ();
                                ResetDoubleClick ();
                            }
                        }
                    }
                    else if (InputGetButtonDown ("InteractionB"))
                    {
                        mouseState = MouseState.RightClick;
                    }
                    else if (InputGetButton ("InteractionA"))
                    {
                        mouseState = MouseState.HeldDown;
                        SetDragState ();
                    }
                    else
                    {
                        ResetMouseClick ();
                    }

                    SetDoubleClickState ();

                    // Menu option changing
                    if (KickStarter.stateHandler.gameState == GameState.DialogOptions || KickStarter.stateHandler.gameState == GameState.Paused)
                    {
                        if (!scrollingLocked)
                        {
                            if (InputGetAxisRaw ("Vertical") > 0.1 || InputGetAxisRaw ("Horizontal") < -0.1)
                            {
                                // Up / Left
                                scrollingLocked = true;
                                selected_option --;
                            }
                            else if (InputGetAxisRaw ("Vertical") < -0.1 || InputGetAxisRaw ("Horizontal") > 0.1)
                            {
                                // Down / Right
                                scrollingLocked = true;
                                selected_option ++;
                            }
                        }
                        else if (InputGetAxisRaw ("Vertical") < 0.05 && InputGetAxisRaw ("Vertical") > -0.05 && InputGetAxisRaw ("Horizontal") < 0.05 && InputGetAxisRaw ("Horizontal") > -0.05)
                        {
                            scrollingLocked = false;
                        }
                    }
                }

                if (KickStarter.playerInteraction.GetHotspotMovingTo () != null)
                {
                    freeAim = Vector2.zero;
                }

                if (KickStarter.stateHandler.gameState == GameState.Normal)
                {
                    DetectCursorInputs ();
                }

                if (KickStarter.settingsManager.SelectInteractionMethod () == SelectInteractions.CyclingMenuAndClickingHotspot && KickStarter.playerMenus.IsInteractionMenuOn ())
                {
                    if (InputGetButtonDown ("CycleInteractionsRight"))
                    {
                        KickStarter.playerInteraction.SetNextInteraction ();
                    }
                    else if (InputGetButtonDown ("CycleInteractionsLeft"))
                    {
                        KickStarter.playerInteraction.SetPreviousInteraction ();
                    }
                    else if (InputGetAxis ("CycleInteractions") > 0.1f)
                    {
                        KickStarter.playerInteraction.SetNextInteraction ();
                    }
                    else if (InputGetAxis ("CycleInteractions") < -0.1f)
                    {
                        KickStarter.playerInteraction.SetPreviousInteraction ();
                    }
                }

                mousePosition = KickStarter.mainCamera.LimitToAspect (mousePosition);

                if (mouseState == MouseState.Normal && !hasUnclickedSinceClick)
                {
                    hasUnclickedSinceClick = true;
                }

                if (mouseState == MouseState.Normal)
                {
                    canDragMoveable = true;
                }

                UpdateDrag ();

                if (dragState != DragState.None)
                {
                    dragVector = GetInvertedMouse () - dragStartPosition;
                    dragSpeed = dragVector.magnitude;
                }
                else
                {
                    dragVector = Vector2.zero;
                    dragSpeed = 0f;
                }

                UpdateActiveInputs ();

                if (mousePosition.x < 0f || mousePosition.x > Screen.width || mousePosition.y < 0f || mousePosition.y > Screen.height)
                {
                    mouseIsOnScreen = false;
                }
                else
                {
                    mouseIsOnScreen = true;
                }
            }
        }
    void Update()
    {
        if (!Input.GetMouseButton(0) && state == DragState.DRAG) {
            endDrag();
            CursorManager.giveUpCursorFocus(this);
        }

        if (state == DragState.DRAG) {
            CursorManager.takeCursorFocus(this, downCursor, Vector2.zero);
            DragEvent e = new DragEvent(DragState.DRAG);

            doDrag(e, dragStartMousePos, Input.mousePosition);

            foreach (DragModifier m in modifiers())
                    m.handleDragEvent(e);

        } else if (state == DragState.SNAP) {
            DragEvent e = new DragEvent(DragState.SNAP);
            bool isSnapDone = doSnap(e, snapToIndex);
            foreach (DragModifier m in modifiers())
                    m.handleDragEvent(e);
            if (isSnapDone) {
                state = DragState.NONE;
                foreach (DragModifier m in modifiers())
                    m.endSnap();
            }
        }

        if (!isActive)
            setVisualState(snapToIndex);
    }
Example #45
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            _dragState = null;

            if (_cachedLink != null)
            {
                _dragState = new DragState
                {
                    Link = _cachedLink,
                    Location = e.Location
                };
            }
        }
Example #46
0
 /// <summary>
 /// Assistance sur événment <see cref="Control.MouseDown"/>
 /// </summary>
 /// <param name="e">descripteur de l'événement <see cref="Control.MouseDown"/> original</param>
 public void WhenMouseDown( MouseEventArgs e ) {
   dragState = DragState.Detecting;
   Location = e.Location;
   Button = e.Button;
   Size dragSize = SystemInformation.DragSize;
   dragArea = new Rectangle( new Point( e.X - (dragSize.Width / 2), e.Y - (dragSize.Height / 2) ), dragSize );
 }
Example #47
0
        private void GateCanvas_MouseUp(object sender, MouseButtonEventArgs e)
        {
            dragging = DragState.NONE;
            dragSelect.Width = 0;
            dragSelect.Height = 0;
            dragSelect.Margin = new Thickness(0, 0, 0, 0);
            dragSelect.Visibility = Visibility.Hidden;

            dragWire.Destination = new Point(0, 0);
            dragWire.Origin = new Point(0, 0);

            // unhightlight all
            foreach (Gates.AbstractGate ag in gates.Keys)
            {
                
                for (int i = 0; i < ag.Output.Length; i++)
                {
                    gates[ag].FindTerminal(false, i).t.Highlight = false;
                }

                for (int i = 0; i < ag.NumberOfInputs; i++)
                {
                    gates[ag].FindTerminal(true, i).t.Highlight = false;
                }
            }

            if (UndoProvider != null && moves != null && moves.Count > 0)
                UndoProvider.Add(moves);
            moves = null;

            ReadyToSelect = false;
        }
Example #48
0
 /// <summary>
 /// Bascule d'assistant dans l'état <see cref="DragState.Dragging"/>
 /// </summary>
 public void DragStart() {
   dragState = DragState.Dragging;
 }
Example #49
0
 private void SetDragStateTouchScreen()
 {
     if (KickStarter.runtimeInventory.selectedItem != null && KickStarter.settingsManager.inventoryDragDrop && (KickStarter.stateHandler.gameState == GameState.Normal || KickStarter.stateHandler.gameState == GameState.Paused))
     {}
     else if (activeDragElement != null && (KickStarter.stateHandler.gameState == GameState.Normal || KickStarter.stateHandler.gameState == GameState.Paused))
     {}
     else if (activeArrows != null && KickStarter.settingsManager.inputMethod == InputMethod.TouchScreen)
     {}
     else if (dragObject != null)
     {}
     else if (KickStarter.mainCamera.attachedCamera && KickStarter.mainCamera.attachedCamera.isDragControlled)
     {}
     else if ((KickStarter.settingsManager.movementMethod == MovementMethod.Drag || KickStarter.settingsManager.movementMethod == MovementMethod.StraightToCursor ||
               (KickStarter.settingsManager.movementMethod != MovementMethod.PointAndClick && KickStarter.settingsManager.inputMethod == InputMethod.TouchScreen))
              && KickStarter.settingsManager.movementMethod != MovementMethod.None && KickStarter.stateHandler.gameState == GameState.Normal)
     {
         if (!KickStarter.playerMenus.IsMouseOverMenu () && !KickStarter.playerMenus.IsInteractionMenuOn ())
         {
             if (KickStarter.playerInteraction.IsMouseOverHotspot ())
             {}
             else
             {
                 dragState = DragState.Player;
             }
         }
     }
     else
     {
         dragState = DragState.None;
     }
 }
Example #50
0
 private void SetDragState()
 {
     if (KickStarter.runtimeInventory.selectedItem != null && KickStarter.settingsManager.inventoryDragDrop && (KickStarter.stateHandler.gameState == GameState.Normal || KickStarter.stateHandler.gameState == GameState.Paused))
     {
         if (dragVector.magnitude >= KickStarter.settingsManager.dragDropThreshold)
         {
             dragState = DragState.Inventory;
         }
         else
         {
             dragState = DragState.PreInventory;
         }
     }
     else if (activeDragElement != null && (KickStarter.stateHandler.gameState == GameState.Normal || KickStarter.stateHandler.gameState == GameState.Paused))
     {
         dragState = DragState.Menu;
     }
     else if (activeArrows != null && KickStarter.settingsManager.inputMethod == InputMethod.TouchScreen)
     {
         dragState = DragState.ScreenArrows;
     }
     else if (dragObject != null)
     {
         dragState = DragState.Moveable;
     }
     else if (KickStarter.mainCamera.attachedCamera && KickStarter.mainCamera.attachedCamera.isDragControlled)
     {
         if (!KickStarter.playerInteraction.IsMouseOverHotspot ())
         {
             dragState = DragState._Camera;
             if (deltaDragMouse.magnitude * Time.deltaTime <= 1f && (GetInvertedMouse () - dragStartPosition).magnitude < 10f)
             {
                 dragState = DragState.None;
             }
         }
     }
     else if ((KickStarter.settingsManager.movementMethod == MovementMethod.Drag || KickStarter.settingsManager.movementMethod == MovementMethod.StraightToCursor ||
               (KickStarter.settingsManager.movementMethod != MovementMethod.PointAndClick && KickStarter.settingsManager.inputMethod == InputMethod.TouchScreen))
              && KickStarter.settingsManager.movementMethod != MovementMethod.None && KickStarter.stateHandler.gameState == GameState.Normal)
     {
         if (!KickStarter.playerMenus.IsMouseOverMenu () && !KickStarter.playerMenus.IsInteractionMenuOn ())
         {
             if (KickStarter.playerInteraction.IsMouseOverHotspot ())
             {}
             else
             {
                 dragState = DragState.Player;
             }
         }
     }
     else
     {
         dragState = DragState.None;
     }
 }
Example #51
0
        public void circuitInkCanvas_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            // only come here if the uigate doesn't handle it
            ClearSelection();

            Point mp2 = e.GetPosition(circuitInkCanvas);
            sp = new Point(mp2.X, mp2.Y);

            ReadyToSelect = true;
            onGateStroke = false;
        
            foreach (UIElement gate in circuitInkCanvas.Children)
            {
                if (gate is Gate)
                {
                    Gate g = gate as Gate;
                    Rect grect = new Rect(g.Margin.Left - 10, g.Margin.Top - 10, g.Width + 10, g.Height + 10);
                    bool condition = false;
                    condition = grect.Contains(mp2);
                    if (condition)
                    {
                        onGateStroke = true;

                        uigate_MouseDown(g, e);

                        if (dragging == DragState.MOVE)
                        {
                            if (g is UIGates.UserInput)
                            {
                                UIGates.UserInput temp = g as UIGates.UserInput;
                                temp.r_MouseDown(this, e);
                            }
                        }
                        break;
                    }
                }

            }

            if (sender is ConnectedWire)
            {
                onWireStroke = true;
                //Debug.WriteLine("HitTest Wire start at " + mp2.ToString());

                ConnectedWire myWire = sender as ConnectedWire;

                Gate.TerminalID tid = myWire.OriginTerminalID;

                // ok, so are we connecting to or from
                // is this an input or output?
                if (tid.isInput)
                {
                    // can only connect from an input
                    // if there is no other connection here
                    //if (wires.ContainsKey(new Gates.Terminal(tid.ID, tid.abgate)))
                    
                    dragging = DragState.CONNECT_TO;
                    dragWire.Value = false;

                    // highlight all terminals which provide output
                    foreach (Gates.AbstractGate ag in gates.Keys)
                    {
                        for (int i = 0; i < ag.Output.Length; i++)
                        {
                            gates[ag].FindTerminal(false, i).t.Highlight = true;
                        }
                    }
                }
                else
                {
                    dragging = DragState.CONNECT_FROM;
                    // TODO: if the value of the output changes
                    // while being dragged, this won't update
                    dragWire.Value = tid.abgate.Output[tid.ID];


                    // highlight all terminals which accept input
                    // note this is all inputs NOT already connected
                    foreach (Gates.AbstractGate ag in gates.Keys)
                    {
                        for (int i = 0; i < ag.NumberOfInputs; i++)
                        {
                            if (c.GetSource(new Gates.Terminal(i, ag)) == null)
                                gates[ag].FindTerminal(true, i).t.Highlight = true;
                        }
                    }
                }
                beginTID = tid;

                dragWire.Destination = tid.t.TranslatePoint(new Point(5, 5), circuitInkCanvas);
                dragWire.Origin = tid.t.TranslatePoint(new Point(5, 5), circuitInkCanvas);

                //if (dragging == DragState.MOVE)
                //{
                //    if (g is UIGates.UserInput)
                //    {
                //        UIGates.UserInput temp = g as UIGates.UserInput;
                //        temp.r_MouseDown(this, e);
                //    }
                //}
                //break;
            }

            e.Handled = true;
        }
Example #52
0
        /// <inheritdoc/>
        protected override void OnPreviewMouseMove(MouseEventArgs e)
        {
            base.OnPreviewMouseMove(e);

            Point position = e.GetPosition(this);

            if (AllowMouseDrag && dragState == DragState.Starting && e.LeftButton == MouseButtonState.Pressed)
            {
                double dx = Math.Abs(position.X - mouseDownPosition.X);
                double dy = Math.Abs(position.Y - mouseDownPosition.Y);
                dragOrientation = dx >= dy ? Orientation.Horizontal : Orientation.Vertical;

                if (dx > SystemParameters.MinimumHorizontalDragDistance || dy > SystemParameters.MinimumVerticalDragDistance)
                {
                    var root = this.FindVisualRoot() as FrameworkElement;
                    if (root != null)
                        root.IsKeyboardFocusWithinChanged += RootParentIsKeyboardFocusWithinChanged;

                    mouseDownPosition = position;
                    mouseMoveDelta = 0;
                    dragState = DragState.Dragging;
                    
                    e.MouseDevice.Capture(this);
                    var handler = DragStarted;
                    if (handler != null)
                    {
                        handler(this, new DragStartedEventArgs(mouseDownPosition.X, mouseDownPosition.Y));
                    }
                    SelectAll();
                    if (adorner != null)
                        adorner.SetOrientation(dragOrientation);
                }
            }

            if (dragState == DragState.Dragging)
            {
                if (dragOrientation == Orientation.Horizontal)
                    mouseMoveDelta += position.X - mouseDownPosition.X;
                else
                    mouseMoveDelta += mouseDownPosition.Y - position.Y;

                var deltaUsed = Math.Floor(mouseMoveDelta / DragSpeed);
                mouseMoveDelta -= deltaUsed;
                var newValue = Value + deltaUsed * SmallChange;

                SetCurrentValue(ValueProperty, newValue);

                if (MouseValidationTrigger == MouseValidationTrigger.OnMouseMove)
                {
                    Validate();
                }
                NativeHelper.SetCursorPos(PointToScreen(mouseDownPosition));
            }
        }
Example #53
0
    /// <summary>
    /// Surveillance des événements souris : impact souris
    /// </summary>
    /// <param name="e">descripteur de l'événement</param>
    protected override void OnMouseDown( MouseEventArgs e ) {
      DragState oldState = dragState;
      try {
        if ( IsDesignMode ) return;

        SelectedControl = GetChildAtPoint( e.Location );

        if ( !autoDrag || e.Button != MouseButtons.Left ) return;
        dragState = DragState.Watching;
        dragHitLocation = e.Location;
      }
      finally {
        if ( oldState != dragState ) Invalidate();
        base.OnMouseDown( e );
      }
    }
Example #54
0
        private void uigate_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (IsReadOnly)
                return;

            Gate tg = (Gate)sender;
            // to avoid sticking on other gates, move this one to the top
            GC.Children.Remove(tg);
            GC.Children.Add(tg);

            if (!tg.Selected)
            {
                // can use ctrl or alt to multi-select
                if (Keyboard.Modifiers == ModifierKeys.None)
                    ClearSelection();

                selected.Add(tg);
                ((GateLocation)tg.Tag).x = tg.Margin.Left;
                ((GateLocation)tg.Tag).y = tg.Margin.Top;
                tg.Selected = true;
            }

            foreach (Gate.TerminalID tid in tg)
            {
                if (tid.t.IsMouseOver)
                {
                    // ok, so are we connecting to or from
                    // is this an input or output?
                    if (tid.isInput)
                    {
                        // can only connect from an input
                        // if there is no other connection here
                        if (wires.ContainsKey(new Gates.Terminal(tid.ID, tid.abgate)))
                            continue;

                        dragging = DragState.CONNECT_TO;
                        dragWire.Value = false;

                        // highlight all terminals which provide output
                        foreach (Gates.AbstractGate ag in gates.Keys)
                        {
                            for (int i = 0; i < ag.Output.Length; i++)
                            {
                                gates[ag].FindTerminal(false, i).t.Highlight = true;
                            }
                        }
                    }
                    else
                    {
                        dragging = DragState.CONNECT_FROM;
                        // TODO: if the value of the output changes
                        // while being dragged, this won't update
                        dragWire.Value = tid.abgate.Output[tid.ID];


                        // highlight all terminals which accept input
                        // note this is all inputs NOT already connected
                        foreach (Gates.AbstractGate ag in gates.Keys)
                        {
                            for (int i = 0; i < ag.NumberOfInputs; i++)
                            {
                                if (c.GetSource(new Gates.Terminal(i, ag)) == null)
                                    gates[ag].FindTerminal(true, i).t.Highlight = true;
                            }
                        }
                    }
                    beginTID = tid;

                    dragWire.Destination = tid.t.TranslatePoint(new Point(5, 5), GC);
                    dragWire.Origin = tid.t.TranslatePoint(new Point(5, 5), GC);
                    e.Handled = true;
                    return;

                }
            }

            dragging = DragState.MOVE;

            moves = new UndoRedo.Transaction(
                            (e.LeftButton == MouseButtonState.Pressed ?
                            "Move" : "Rotate") + " " +
                            (selected.Count == 1 ?
                            "Gate" : selected.Count.ToString() + " Gates"));

            e.Handled = true;

        }
Example #55
0
        /// <inheritdoc/>
        protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseUp(e);

            if (ReferenceEquals(e.MouseDevice.Captured, this))
                e.MouseDevice.Capture(null);

            if (dragState == DragState.Starting)
            {
                Select(0, Text.Length);
                if (!IsFocused)
                {
                    Keyboard.Focus(this);
                }
            }
            else if (dragState == DragState.Dragging && AllowMouseDrag)
            {                
                if (adorner != null)
                {
                    var adornerLayer = AdornerLayer.GetAdornerLayer(this);
                    if (adornerLayer != null)
                    {
                        adornerLayer.Remove(adorner);
                        adorner = null;
                    }
                }
                Validate();

                var handler = DragCompleted;
                if (handler != null)
                {
                    Point position = e.GetPosition(this);
                    double dx = Math.Abs(position.X - mouseDownPosition.X);
                    double dy = Math.Abs(position.Y - mouseDownPosition.Y);
                    handler(this, new DragCompletedEventArgs(dx, dy, false));
                }
            }

            Mouse.OverrideCursor = null;
            dragState = DragState.None;
        }
Example #56
0
 /// <summary>
 /// Bascule d'assistant dans l'état <see cref="DragState.Quiet"/>
 /// </summary>
 public void DragTerminate() {
   dragState = DragState.Quiet;
   Button = MouseButtons.None;
   dragArea = Rectangle.Empty;
 }
Example #57
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (_dragState == null)
                return;

            int dx = Math.Abs(e.Location.X - _dragState.Location.X);
            int dy = Math.Abs(e.Location.Y - _dragState.Location.Y);

            var link = _dragState.Link;
            _dragState = null;

            if (link == null)
                return;

            if (dx <= SystemInformation.DragSize.Width && dy <= SystemInformation.DragSize.Height)
            {
                if (link.TargetPage.HasValue)
                    Page = link.TargetPage.Value;

                if (link.Uri != null)
                {
                    try
                    {
                        Process.Start(link.Uri);
                    }
                    catch
                    {
                        // Some browsers (Firefox) will cause an exception to
                        // be thrown (when it auto-updates).
                    }
                }
            }
        }
    void OnMouseOver()
    {
        if (!canStartDrag()) {
            CursorManager.giveUpCursorFocus(this);
            return;
        }

        if (Input.GetMouseButton(0)) {
            CursorManager.takeCursorFocus(this, downCursor, Vector2.zero);
        } else {
            CursorManager.takeCursorFocus(this, upCursor, Vector2.zero);
        }

        // If mouse is pressed
        if (state != DragState.DRAG && Input.GetMouseButtonDown(0)) {
            state = DragState.DRAG;
            dragStartMousePos = Input.mousePosition;

            initDrag(dragStartMousePos);

            foreach (DragModifier m in modifiers())
                m.startDrag();
        }
    }
Example #59
0
 public DragEvent(DragState state)
 {
     this.state = state;
 }
Example #60
0
    /// <summary>
    /// Surveillance des événements souris : lorsque la souris est déplacée
    /// </summary>
    /// <param name="e">descripteur de l'événement</param>
    protected override void OnMouseMove( MouseEventArgs e ) {
      DragState oldState = dragState;
      try {
        switch ( dragState ) {

          // surveillance de détection d'une amorce de glissement
          case DragState.Watching:
            Rectangle dragDetect = new Rectangle( Point.Subtract( dragHitLocation, new Size( DragDetectArea, DragDetectArea ) ), new Size( 2 * DragDetectArea, 2 * DragDetectArea ) );
            if ( dragDetect.Contains( e.Location ) ) return;

            dragState = DragState.None;
            Control control = GetChildAtPoint( dragHitLocation );
            if ( control == null ) return;
            SelectedControl = control;
            dragHitDelta = new Size( control.Location.X - dragHitLocation.X, control.Location.Y - dragHitLocation.Y );
            dragHitArea = AreaEnumOf( dragHitLocation );
            dragLastLocation = dragHitLocation;
            dragState = DragState.Dragging;
            OnDragDetect( new DragDetectEventArgs( e.Location, dragHitLocation, dragHitArea, dragHitDelta, control ) );
            break;

          // glissement ou redimensionnement en cours
          case DragState.Dragging:
            PerformDrag( e.Location );
            break;
        }
      }
      finally {
        DoUpdateCursor( e.Location, e.Button );
        if ( oldState != dragState ) Invalidate();
        base.OnMouseMove( e );
      }
    }