Beispiel #1
0
 void PlaceResizeVisuals(IPositionalElement element)
 {
     FirstResizeVisual.Offset  = element.Layout.Location.ToWinVector();
     SecondResizeVisual.Offset = Vector.Add(element.Layout.Location.ToWinVector(),
                                            new Vector(element.Layout.Orientation == Orientation.Horizontal ? element.Layout.Size : 0.0,
                                                       element.Layout.Orientation == Orientation.Vertical ? element.Layout.Size : 0.0));
 }
        public static void LoadPositionalElement(this IPositionalElement positionalElement, Node node)
        {
            node.SetWorldPosition(positionalElement.WorldPosition.ToUrhoVector3());

            var quaternion = positionalElement.WorldRotation.ToQuaternion();

            node.SetWorldRotation(quaternion);
        }
Beispiel #3
0
        private void HighlightElement(IPositionalElement element)
        {
            highlighted.Add(element);
            HighlightBoxVisuals[element].Opacity = 1.0;

            PlaceResizeVisuals(element);
            FirstResizeVisual.IsVisible  = true;
            SecondResizeVisual.IsVisible = true;
        }
        public void OnMouseDown(Point mousePosition, EditorOperationHitTest hitTest, IEditorOperationalContext context)
        {
            if (hitTest.ResizeHandle == null || element == null)
            {
                // Not resizing
                element = null;
                return;
            }

            Log.LogInformation($"Starting resize on {hitTest.ResizeHandle.Value} handle");

            initialMousePosition = mousePosition;
            initialLocation      = element.Layout.Location;
            initialSize          = element.Layout.Size;
            mode       = hitTest.ResizeHandle.Value;
            isResizing = true;
        }
Beispiel #5
0
        private void ReadLayout(IPositionalElement positionalElement, XElement element, ReaderContext context)
        {
            int?        x           = element.GetIntAttribute("x", context);
            int?        y           = element.GetIntAttribute("y", context);
            int?        size        = element.GetIntAttribute("sz", context);
            bool?       flipped     = element.GetBoolAttribute("flp", context);
            Orientation?orientation = element.GetComponentOrientationAttribute("o", context);

            if (!x.HasValue || !y.HasValue)
            {
                return;
            }

            positionalElement.Layout.Location    = positionalElement.Layout.Location.WithNewX(x.Value);
            positionalElement.Layout.Location    = positionalElement.Layout.Location.WithNewY(y.Value);
            positionalElement.Layout.Size        = size ?? 0;
            positionalElement.Layout.IsFlipped   = flipped ?? false;
            positionalElement.Layout.Orientation = orientation ?? Orientation.Horizontal;
        }
        public bool OnMouseMove(Point mousePosition, EditorOperationHitTest hitTest, IEditorOperationalContext context)
        {
            if (!isResizing)
            {
                if (hitTest.Element == null && hitTest.ResizeHandle == null)
                {
                    // Nothing under the cursor

                    if (element != null)
                    {
                        Log.LogInformation("Nothing prepared for resize");
                        element = null;
                    }
                    return(false);
                }

                if (element == null && hitTest.Element != null)
                {
                    Log.LogInformation($"{hitTest.Element} prepared for resize");

                    // Mouse is over an element - resize it later
                    element = hitTest.Element;
                    return(false);
                }

                if (hitTest.ResizeHandle != null)
                {
                    context.Cursor = Cursors.SizeNS;
                }

                return(false);
            }

            // Resizing in progress

            var offset = new Vector(mousePosition.X - initialMousePosition.X, mousePosition.Y - initialMousePosition.Y);

            double diff = element.Layout.Orientation == Orientation.Horizontal ? offset.X : offset.Y;

            if (mode == ResizeHandle.Begin)
            {
                diff = -diff;
            }

            diff = SnapToGrid(diff, context.GridSize);

            element.Layout.Size = initialSize + diff;

            if (mode == ResizeHandle.Begin && element.Layout.Orientation == Orientation.Horizontal)
            {
                element.Layout.Location = element.Layout.Location.WithNewX(initialLocation.X - diff);
            }
            else if (mode == ResizeHandle.Begin)
            {
                element.Layout.Location = element.Layout.Location.WithNewY(initialLocation.Y - diff);
            }

            context.UpdateElementPosition(element);
            context.ReRenderElement(element);

            return(true);
        }
 public void Abort()
 {
     isResizing = false;
     element    = null;
 }
Beispiel #8
0
 void IEditorOperationalContext.ReRenderElement(IPositionalElement element)
 {
     ElementVisuals[element].UpdateVisual();
     HighlightBoxVisuals[element].UpdateVisual();
     RenderConnections();
 }
Beispiel #9
0
 void IEditorOperationalContext.UpdateElementPosition(IPositionalElement element)
 {
     ElementVisuals[element].Offset      = element.Layout.Location.ToWinVector();
     HighlightBoxVisuals[element].Offset = element.Layout.Location.ToWinVector();
     RenderConnections();
 }
Beispiel #10
0
 void IEditorOperationalContext.AddElement(IPositionalElement element)
 {
     Circuit.Elements.Add(element);
     RenderCircuit();
 }