Esempio n. 1
0
        private void ExecuteCopyPaste(CopyPasteCommand command)
        {
            var cCopyPaste = GetCopyPasteComponents().FirstOrDefault(x => x.Overrides(command));

            if (cCopyPaste == null || !cCopyPaste.CanExecute(command))
            {
                return;
            }
            cCopyPaste.Execute(command);
            undoRedoService.OnChange();
        }
Esempio n. 2
0
        private bool TryHandleMouseEvent(IMouseEvent eventArgs)
        {
            var pixelPos    = eventArgs.Viewport.GetPixelPos(entity);
            var pixelDelta  = eventArgs.State.Position - pixelPos;
            var radianDelta = (Vector2)pixelDelta / 50f;
            var rotation    = (eventArgs.KeyModifiers & KeyModifiers.Shift) == 0
                ? Quaternion.RotationX(-radianDelta.Y) * Quaternion.RotationY(-radianDelta.X)
                : Quaternion.RotationZ(radianDelta.X) * Quaternion.RotationY(-radianDelta.Y);
            var newTransform = new Transform
            {
                Scale    = initialLocalTransform.Scale,
                Offset   = initialLocalTransform.Offset,
                Rotation = initialLocalTransform.Rotation * rotation
            };

            if (eventArgs.ComplexEventType == MouseEventType.Click && eventArgs.EventButtons == MouseButtons.Left)
            {
                entity.Transform = initialLocalTransform;
                entity.Transform = newTransform;
                undoRedo.OnChange();
                done = true;
                toolService.CurrentTool = null;
            }
            else
            {
                entity.Transform = newTransform;
            }

            return(false);
        }
 private void OnGroupNameChanged(object sender, EventArgs e)
 {
     if (boundComponent == null)
     {
         return;
     }
     boundComponent.GroupName = cGroupName.Text;
     undoRedo.OnChange();
 }
Esempio n. 4
0
 private void OnNameTextChanged(object sender, EventArgs eventArgs)
 {
     if (boundNode == null)
     {
         return;
     }
     boundNode.Name = cName.Text;
     undoRedo.OnChange();
 }
        private void OnDefaultAdaptiveStyleChanged(object sender, EventArgs eventArgs)
        {
            if (boundComponent == null)
            {
                return;
            }
            var type = typeDict[(string)cDefaultAdaptiveStyle.SelectedValue];

            boundComponent.StartLayoutType = type;
            undoRedo.OnChange();
        }
 private void OnChanged(object sender, EventArgs eventArgs)
 {
     if (boundComponent == null)
     {
         return;
     }
     boundComponent.Width         = (int)widthControl.Value;
     boundComponent.Height        = (int)heightControl.Value;
     boundComponent.LevelSetScale = (int)levelSetScaleControl.Value;
     boundComponent.CellSize      = (float)(cellSizeControl.Value / 10f);
     boundComponent.SurfaceType   = (FluidSurfaceType)surfaceTypeDropDown.SelectedValue;
     undoRedo.OnChange();
 }
        private void OnAddNewButtonClick(object sender, EventArgs eventArgs)
        {
            var aspectAlias = (string)aspectTypesControl.SelectedValue;

            switch (aspectAlias)
            {
            case "RotateOnDC":
            {
                var component = AmFactory.Create <RotateOnceComponent>();
                boundNode.Components.Add(component);
                undoRedo.OnChange();
                break;
            }

            case "ManipOnPresent":
            {
                var component = AmFactory.Create <ManipulateInPresentationComponent>();
                boundNode.Components.Add(component);
                undoRedo.OnChange();
                break;
            }

            case "WarpScroll":
            {
                var component = AmFactory.Create <WarpScrollComponent>();
                boundNode.Components.Add(component);
                undoRedo.OnChange();
                break;
            }

            case "HighlightOnMouseOver":
            {
                var component = AmFactory.Create <HighlightOnMouseComponent>();
                boundNode.Components.Add(component);
                undoRedo.OnChange();
                break;
            }
            }
        }
Esempio n. 8
0
        private bool TryHandleMouseEvent(IMouseEvent eventArgs)
        {
            var viewport   = eventArgs.Viewport;
            var cPlacement = entity.PresentationInfra().Placement;

            if (cPlacement == null)
            {
                return(false);
            }

            var globalRay = viewport.GetGlobalRayForPixelPos(eventArgs.State.Position);

            if (!cPlacement.PlacementSurface3D.TryFindPlace(globalRay, out var placementTransform))
            {
                return(false);
            }

            var delta       = (placementTransform.Offset - cTransformable.LocalBoundingSphere.Center * entity.Transform).Length();
            var modelRadius = cTransformable.LocalBoundingSphere.Radius;
            var scale       = delta / modelRadius;

            var newTransform = new Transform
            {
                Rotation = initialLocalTransform.Rotation,
                Offset   = initialLocalTransform.Offset,
                Scale    = scale
            };

            entity.Transform = newTransform;

            if (eventArgs.ComplexEventType == MouseEventType.Click && eventArgs.EventButtons == MouseButtons.Left)
            {
                entity.Transform = initialLocalTransform;
                entity.Transform = newTransform;
                undoRedo.OnChange();
                done = true;
                toolService.CurrentTool = null;
            }
            else
            {
                entity.Transform = newTransform;
            }

            return(false);
        }
Esempio n. 9
0
        private void AdjustRectangleAndSetCurve()
        {
            var entityRect        = rectangleAspect.Rectangle;
            var layoutBasedPoints = curve
                                    .Select(xy => entityRect.Center + new Vector2(xy.X * entityRect.HalfWidth, xy.Y * entityRect.HalfHeight))
                                    .ToArray();
            float minX = float.MaxValue;
            float minY = float.MaxValue;
            float maxX = float.MinValue;
            float maxY = float.MinValue;

            foreach (var point in layoutBasedPoints)
            {
                if (point.X < minX)
                {
                    minX = point.X;
                }
                if (point.X > maxX)
                {
                    maxX = point.X;
                }
                if (point.Y < minY)
                {
                    minY = point.Y;
                }
                if (point.Y > maxY)
                {
                    maxY = point.Y;
                }
            }
            var newRect       = new AaRectangle2(new Vector2(minX, minY), new Vector2(maxX, maxY));
            var adjustedCurve = layoutBasedPoints.Select(xy =>
            {
                var result = xy - newRect.Center;
                result.X  /= newRect.HalfWidth;
                result.Y  /= newRect.HalfHeight;
                return(result);
            }).ToArray();

            rectangleAspect.Rectangle        = newRect;
            richTextAspect.BorderCurve       = adjustedCurve;
            richTextAspect.VisualBorderCurve = adjustedCurve;
            undoRedo.OnChange();
        }
Esempio n. 10
0
        private bool TryHandleMouseEvent(IMouseEvent eventArgs)
        {
            var viewport      = eventArgs.Viewport;
            var placementNode = (viewport.View as IFocusableView)?.FocusNode;
            var cPlacement    = placementNode?.SearchComponent <IPlacementComponent>();

            if (cPlacement == null)
            {
                entity.Deparent();
                return(false);
            }
            var globalRay = viewport.GetGlobalRayForPixelPos(eventArgs.State.Position);

            if (!cPlacement.PlacementSurface3D.TryFindPlace(globalRay, out var placementTransform))
            {
                entity.Deparent();
                return(false);
            }

            var newTransform = new Transform
            {
                Scale    = isNew ? placementTransform.Scale : initialLocalTransform.Scale,
                Rotation = isNew ? placementTransform.Rotation : initialLocalTransform.Rotation,
                Offset   = placementTransform.Offset
            };

            entity.Transform = newTransform;
            if (!entity.IsDescendantOf(placementNode))
            {
                entity.Deparent();
                placementNode.ChildNodes.Add(entity);
            }

            if (eventArgs.ComplexEventType == MouseEventType.Click && eventArgs.EventButtons == MouseButtons.Left)
            {
                undoRedo.OnChange();
                done = true;
                toolService.CurrentTool = null;
            }

            return(false);
        }
        private InputEventProcessResult ProcessMouseEvent(IMouseEvent args)
        {
            if ((args.State.Buttons & MouseButtons.Left) == 0)
            {
                nodeRectAspect.Node.GetComponent <IRectangleComponent>().Rectangle = nodeRectAspect.Rectangle;
                undoRedo.OnChange();
                return(InputEventProcessResult.ReleaseLock);
            }
            if (!args.IsOfType(MouseEventType.Move))
            {
                return(InputEventProcessResult.DontCare);
            }
            var globalRay = args.Viewport.GetGlobalRayForPixelPos(args.State.Position);

            if (!space.TryFindPoint2D(globalRay, out var pos2D))
            {
                return(InputEventProcessResult.StopPropagating);
            }
            var minCorner = pos2D - anchorPointOnRect;
            var maxCorner = minCorner + new Vector2(originalRect.Width, originalRect.Height);

            nodeRectAspect.Rectangle = new AaRectangle2(minCorner, maxCorner);
            return(InputEventProcessResult.StopPropagating);
        }
        private bool TryHandleKeyEvent(IKeyEvent args)
        {
            if (!args.HasFocus)
            {
                return(false);
            }

            var editor  = HeadlessEditor;
            var textBox = cText.TextBox;
            var layout  = textBox.Layout;

            if (args.ComplexEventType == KeyEventType.TextInput)
            {
                editor.InputString(args.Text);
                undoRedo.OnChange();
                return(true);
            }

            if (args.ComplexEventType == KeyEventType.Down)
            {
                switch (args.EventKey)
                {
                case Key.Left:
                {
                    editor.MoveCursorSafe(editor.CursorPos - 1, args.KeyModifiers.HasFlag(KeyModifiers.Shift));
                    return(true);
                }

                case Key.Right:
                {
                    editor.MoveCursorSafe(editor.CursorPos + 1, args.KeyModifiers.HasFlag(KeyModifiers.Shift));
                    return(true);
                }

                case Key.Up:
                {
                    if (!layout.TryGetUp(editor.CursorPos, out var newPos))
                    {
                        newPos = editor.CursorPos;
                    }
                    editor.MoveCursor(newPos, args.KeyModifiers.HasFlag(KeyModifiers.Shift));
                    return(true);
                }

                case Key.Down:
                {
                    if (!layout.TryGetDown(editor.CursorPos, out var newPos))
                    {
                        newPos = editor.CursorPos;
                    }
                    editor.MoveCursor(newPos, args.KeyModifiers.HasFlag(KeyModifiers.Shift));
                    return(true);
                }

                case Key.Enter:
                {
                    editor.InputString("\n");
                    undoRedo.OnChange();
                    return(true);
                }

                case Key.Backspace:
                {
                    editor.Erase();
                    undoRedo.OnChange();
                    return(true);
                }

                case Key.Tab:
                    if (args.KeyModifiers == KeyModifiers.None)
                    {
                        editor.Tab();
                    }
                    else if (args.KeyModifiers == KeyModifiers.Shift)
                    {
                        editor.ShiftTab();
                    }
                    return(true);
                }
            }
            return(false);
        }
        private InputEventProcessResult ProcessMouseEvent(IMouseEvent args)
        {
            if ((args.State.Buttons & MouseButtons.Left) == 0)
            {
                nodeRectAspect.Node.GetComponent <IRectangleComponent>().Rectangle = nodeRectAspect.Rectangle;
                undoRedo.OnChange();
                return(InputEventProcessResult.ReleaseLock);
            }
            if (!args.IsOfType(MouseEventType.Move))
            {
                return(InputEventProcessResult.DontCare);
            }
            var globalRay = args.Viewport.GetGlobalRayForPixelPos(args.State.Position);

            if (!space.TryFindPoint2D(globalRay, out var pos2D))
            {
                return(InputEventProcessResult.StopPropagating);
            }
            var or  = originalRect;
            var asp = originalRect.Width / originalRect.Height;
            var converseAspectRatio = (args.KeyModifiers & KeyModifiers.Shift) != 0;

            switch (place)
            {
            case ResizeRectangleGizmoPlace.Left:
                nodeRectAspect.Rectangle = NewRect(pos2D.X, or.MinY, or.MaxX, or.MaxY);
                break;

            case ResizeRectangleGizmoPlace.Right:
                nodeRectAspect.Rectangle = NewRect(or.MinX, or.MinY, pos2D.X, or.MaxY);
                break;

            case ResizeRectangleGizmoPlace.Bottom:
                nodeRectAspect.Rectangle = NewRect(or.MinX, pos2D.Y, or.MaxX, or.MaxY);
                break;

            case ResizeRectangleGizmoPlace.Top:
                nodeRectAspect.Rectangle = NewRect(or.MinX, or.MinY, or.MaxX, pos2D.Y);
                break;

            case ResizeRectangleGizmoPlace.BottomLeft:
            {
                var left = converseAspectRatio ? or.MaxX - asp * (or.MaxY - pos2D.Y) : pos2D.X;
                nodeRectAspect.Rectangle = NewRect(left, pos2D.Y, or.MaxX, or.MaxY);
                break;
            }

            case ResizeRectangleGizmoPlace.BottomRight:
            {
                var right = converseAspectRatio ? or.MinX + asp * (or.MaxY - pos2D.Y) : pos2D.X;
                nodeRectAspect.Rectangle = NewRect(or.MinX, pos2D.Y, right, or.MaxY);
                break;
            }

            case ResizeRectangleGizmoPlace.TopLeft:
            {
                var left = converseAspectRatio ? or.MaxX - asp * (pos2D.Y - or.MinY) : pos2D.X;
                nodeRectAspect.Rectangle = NewRect(left, or.MinY, or.MaxX, pos2D.Y);
                break;
            }

            case ResizeRectangleGizmoPlace.TopRight:
            {
                var right = converseAspectRatio ? or.MinX + asp * (pos2D.Y - or.MinY) : pos2D.X;
                nodeRectAspect.Rectangle = NewRect(or.MinX, or.MinY, right, pos2D.Y);
                break;
            }
            }
            return(InputEventProcessResult.StopPropagating);
        }
Esempio n. 14
0
        public FluentGuiService(IViewService viewService, IRenderLoopDispatcher renderLoopDispatcher,
                                IAssetService assetService, IUndoRedoService undoRedo, IEmbeddedResources embeddedResources,
                                IReadOnlyList <IStoryLayout> storyLayouts,
                                // todo: refactor away from using these services
                                IStoryService storyService, IWorldTreeService worldTreeService)
        {
            this.viewService  = viewService;
            this.assetService = assetService;
            this.undoRedo     = undoRedo;

            var mainPanel = new FluentPanel <ISceneNode>(() => selectedSceneNode, x => x != null)
            {
                Width = 300
            };
            var builder = mainPanel.Build().Table();

            {
                var mainGroupBox = builder.Row().GroupBox("common", x => x, x => true).Table();
                mainGroupBox.Row().Label(x => x.Id.ToString());
                mainGroupBox.Row().TextBox(x => x.Name);
            }
            {
                var sceneGroupBox = builder.Row().GroupBox("Scene", x => x.AmParent as IScene, x => x != null).Table();
                var colorRow      = sceneGroupBox.Row();
                colorRow.Label("Bgnd Color");
                colorRow.ColorPicker(x => x.BackgroundColor);
                var skyboxRow = sceneGroupBox.Row();
                skyboxRow.Label("Skybox");
                skyboxRow.DropDown(x => x.Skybox, new Dictionary <string, ISkybox>
                {
                    { "None", null },
                    { "Storm", embeddedResources.Skybox("Skyboxes/storm.skybox") },
                    { "Stars", embeddedResources.Skybox("Skyboxes/stars.skybox") }
                });
            }
            {
                var storyRootGroupBox = builder.Row().GroupBox("Story Root", x => x.SearchComponent <IStoryComponent>(), x => x != null && x.IsLayoutRoot).Table();
                var layoutTypeRow     = storyRootGroupBox.Row();
                layoutTypeRow.Label("LayoutType");
                layoutTypeRow.DropDown(x => x.StartLayoutType, storyLayouts.ToDictionary(x => x.UserFriendlyName, x => x.Type));
                var auxRow12 = storyRootGroupBox.Row();
                auxRow12.CheckBox("Aux 1", x => x.ShowAux1);
                auxRow12.CheckBox("Aux 2", x => x.ShowAux2);
                var auxRow34 = storyRootGroupBox.Row();
                auxRow34.CheckBox("Aux 3", x => x.ShowAux3);
                auxRow34.CheckBox("Aux 4", x => x.ShowAux4);
            }
            {
                var storyNodeGroupBox = builder.Row().GroupBox("Story Node", x => x.SearchComponent <IStoryComponent>(), x => x != null).Table();
                var firstRow          = storyNodeGroupBox.Row();
                firstRow.CheckBox("Instant transition", x => x.InstantTransition);
                firstRow.CheckBox("Skip", x => x.SkipOrder);
                for (var i = 0; i < 4; i++)
                {
                    var iLoc = i;
                    var row  = storyNodeGroupBox.Row();
                    row.Label(x => storyService.GlobalGraph.Next.TryGetValue(x.Node.Id, out var nextList) && iLoc < nextList.Count
                        ? worldTreeService.GetById(nextList[iLoc]).Name
                        : "-");
                    row.Button("X", x => storyService.RemoveEdge(x.Node.Id, storyService.GlobalGraph.Next[x.Node.Id][iLoc]));
                }
            }
            {
                var modelComponentBuilder = builder.Row().GroupBox("Model", x => x.SearchComponent <IModelComponent>(), x => x != null).Table();
                var colorRow = modelComponentBuilder.Row();
                colorRow.CheckBox("SingleColor", x => x.SingleColor);
                colorRow.ColorPicker(x => x.Color);
                var textureRow = modelComponentBuilder.Row();
                textureRow.Label("Image");
                textureRow.Button("Load", OnLoadTextureClicked);
                var checkBoxRow1 = modelComponentBuilder.Row();
                checkBoxRow1.CheckBox("Ignore Lighting", x => x.IgnoreLighting);
                checkBoxRow1.CheckBox("No Specular", x => x.NoSpecular);
                var checkBoxRow2 = modelComponentBuilder.Row();
                checkBoxRow2.CheckBox("Don't cull", x => x.DontCull);
                checkBoxRow2.CheckBox("Ortho", x => x.Ortho);
                modelComponentBuilder.Row().Button("Export", OnExportClick);
            }
            {
                var spherePackingComponentBuilder = builder.Row().GroupBox("Sphere Packing", x => x.SearchComponent <SpherePackingComponent>(), x => x != null).Table();
                var row = spherePackingComponentBuilder.Row();
                row.Label("Radius");
                row.TextBox(x => x.Radius);
                row = spherePackingComponentBuilder.Row();
                row.Label("Color");
                row.ColorPicker(x => x.Color);
            }
            {
                var rectGroupBox  = builder.Row().GroupBox("Rectangle", x => x, x => x.HasComponent <IRectangleComponent>()).Table();
                var commonRectRow = rectGroupBox.Row().Panel(x => x.SearchComponent <IRectangleComponent>(), x => x != null).Table().Row();
                commonRectRow.CheckBox("DragBorders", x => x.DragByBorders);
                var colorRow = rectGroupBox.Row().Panel(x => x.SearchComponent <ColorRectangleComponent>(), x => x != null).Table().Row();
                colorRow.Label("Color");
                colorRow.ColorPicker(x => x.Color);
                // todo: change image
            }
            {
                var viewModel    = new RichTextViewModel(() => selectedSceneNode.SearchComponent <IRichTextComponent>());
                var textGroupBox = builder.Row().GroupBox("Rich Text", x => viewModel, x => x.Valid).Table();
                var bgndModeRow  = textGroupBox.Row();
                bgndModeRow.Label("Bgnd Mode");
                bgndModeRow.DropDown(x => x.BackgroundMode, new Dictionary <string, RtTransparencyMode>
                {
                    ["Opaque"] = RtTransparencyMode.Opaque,
                    ["Native"] = RtTransparencyMode.Native,
                    ["White is transparent"] = RtTransparencyMode.WhiteIsTransparent,
                    ["Black is transparent"] = RtTransparencyMode.BlackIsTransparent,
                });
                var bgndColorRow = textGroupBox.Row();
                bgndColorRow.Label("Bgnd Color");
                bgndColorRow.ColorPicker(x => x.BackgroundColor);
                var bgndOpacityRow = textGroupBox.Row();
                bgndOpacityRow.Label("Bgnd Opacity");
                bgndOpacityRow.Slider(x => x.BackgroundOpacity, 0, 1, 256);

                var alignmentRow = textGroupBox.Row();
                alignmentRow.Label("Alignment");
                alignmentRow.DropDown(x => x.Alignment, new Dictionary <string, RtParagraphAlignment>
                {
                    ["Left"]    = RtParagraphAlignment.Left,
                    ["Center"]  = RtParagraphAlignment.Center,
                    ["Right"]   = RtParagraphAlignment.Right,
                    ["Justify"] = RtParagraphAlignment.Justify,
                });
                var directionRow = textGroupBox.Row();
                directionRow.Label("Direction");
                directionRow.DropDown(x => x.Direction, new Dictionary <string, RtParagraphDirection>
                {
                    ["LeftToRight"] = RtParagraphDirection.LeftToRight,
                    ["RightToLeft"] = RtParagraphDirection.RightToLeft,
                });
                var tabsRow = textGroupBox.Row();
                tabsRow.Label("Tabs");
                tabsRow.NumericUpDown(x => x.Tabs, 0, 16);
                var marginUpRow = textGroupBox.Row();
                marginUpRow.Label("MarginUp");
                marginUpRow.NumericUpDown(x => x.MarginUp, 0, 1000);

                var fontRow = textGroupBox.Row();
                fontRow.Label("Font");
                fontRow.DropDown(x => x.FontFamily, Fonts.AvailableFontFamilies
                                 .Select(x => x.Name)
                                 .OrderBy(r => r)
                                 .ToDictionary(x => x));
                var sizeRow = textGroupBox.Row();
                sizeRow.Label("Size");
                sizeRow.NumericUpDown(x => x.Size, 1, 200);
                var colorRow = textGroupBox.Row();
                colorRow.Label("Color");
                colorRow.ColorPicker(x => x.Color);
                var decorationRow1 = textGroupBox.Row();
                decorationRow1.CheckBox("Bold", x => x.Bold);
                decorationRow1.CheckBox("Italic", x => x.Italic);
                var decorationRow2 = textGroupBox.Row();
                decorationRow2.CheckBox("Underline", x => x.Underline);
                decorationRow2.CheckBox("Strikethrough", x => x.Strikethrough);
                var highlightGroupRow = textGroupBox.Row();
                highlightGroupRow.Label("Highlight Group");
                highlightGroupRow.TextBox(x => x.HighlightGroup);

                var formulaRow = textGroupBox.Row();
                formulaRow.Button("Insert Formula", vm => vm.InsertFormula());
            }
            {
                var highlightOnMouseGroupBox = builder.Row().GroupBox("Highlight on Mouse", x => x.SearchComponent <HighlightOnMouseComponent>(), x => x != null).Table();
                var row = highlightOnMouseGroupBox.Row();
                row.Label("Group Name");
                row.TextBox(x => x.GroupName, x => x ?? "", x => string.IsNullOrEmpty(x) ? null : x);
            }
            {
                var circlePackingGroupBox = builder.Row().GroupBox("Circle Packing", x => x.SearchComponent <ICirclePackingComponent>(), x => x != null).Table();
                var shapeRow = circlePackingGroupBox.Row();
                shapeRow.Label("Shape");
                shapeRow.DropDown(x => x.ShapeName, new[] { "Square", "Circle", "Ellipse" }.ToDictionary(x => x));
                var radiusRow = circlePackingGroupBox.Row();
                radiusRow.Label("Radius");
                radiusRow.TextBox(x => x.CircleRadius);
                var maxCircles = circlePackingGroupBox.Row();
                maxCircles.Label("Max Circles");
                maxCircles.TextBox(x => x.MaxInitialCircles);
                var movementRateRow = circlePackingGroupBox.Row();
                movementRateRow.Label("Smoothness");
                movementRateRow.Slider(x => x.MovementRate, 0, 1, 32);
                var quakeRow = circlePackingGroupBox.Row();
                quakeRow.Label("Quake");
                quakeRow.Slider(x => x.RandomFactor, 0, 1, 32);
                var areaRow = circlePackingGroupBox.Row();
                areaRow.Label("Area");
                areaRow.Label(x => x.Area.ToString(CultureInfo.InvariantCulture));
                var numCirclesRow = circlePackingGroupBox.Row();
                numCirclesRow.Label(x => "Num Circles: " + x.CurrentNumCircles);
                numCirclesRow.Label(x => "Uppber Bound: " + x.MaxCircles);
                var iterPerBreakRow = circlePackingGroupBox.Row();
                iterPerBreakRow.Label("Iteractions per Display");
                iterPerBreakRow.TextBox(x => x.NumIterationPerBreak);
                var batchSizeRow = circlePackingGroupBox.Row();
                batchSizeRow.Label("Batch Size");
                batchSizeRow.TextBox(x => x.BatchSize);
                var resetRow = circlePackingGroupBox.Row();
                resetRow.Label("");
                resetRow.Button("Reset Circles", x => x.ResetPacker());
                var optimizeStepRow = circlePackingGroupBox.Row();
                optimizeStepRow.Label("");
                optimizeStepRow.Button("Optimize Step", x => x.OptimizeStep());
                var runOptimizeRow = circlePackingGroupBox.Row();
                runOptimizeRow.Label("");
                runOptimizeRow.Button("Run Optimization", x => x.RunOptimization());
                var stopOptimizeRow = circlePackingGroupBox.Row();
                stopOptimizeRow.Label("");
                stopOptimizeRow.Button("Stop Optimization", x => x.StopOptimization());
                var deleteCircleRow = circlePackingGroupBox.Row();
                deleteCircleRow.Label("");
                deleteCircleRow.Button("Delete Circle", x => x.DeleteCircle());
                var fillHodeRow = circlePackingGroupBox.Row();
                fillHodeRow.Button("Fill Hole (E)", x => x.TryFillHole(true));
                fillHodeRow.Button("Fill Hole (N)", x => x.TryFillHole(false));
            }
            {
                var circlePackingGroupBox = builder.Row().GroupBox("Circle Packing", x => x.SearchComponent <ICirclePackingAutoComponent>(), x => x != null).Table();
                var shapeRow = circlePackingGroupBox.Row();
                shapeRow.Label("Shape");
                shapeRow.DropDown(x => x.ShapeName, new[] { "Square", "Circle", "Ellipse" }.ToDictionary(x => x));
                var radiusRow = circlePackingGroupBox.Row();
                radiusRow.Label("Radius");
                radiusRow.TextBox(x => x.CircleRadius);
                var numCirclesRow = circlePackingGroupBox.Row();
                numCirclesRow.Label(x => "Num Circles: " + x.NumCircles);
                //numCirclesRow.Label(x => "Uppber Bound: " + x.MaxCircles);
                var attemptsPerDisplayRow = circlePackingGroupBox.Row();
                attemptsPerDisplayRow.Label("Attempts per Display");
                attemptsPerDisplayRow.TextBox(x => x.AttemptsPerRefresh);
                var statsRow = circlePackingGroupBox.Row();
                statsRow.Label(x => $"Seconds: {x.SecondsSinceLastSuccess:F} Attempts: {x.AttemptsSinceLastSuccess}");
                var resetRow = circlePackingGroupBox.Row();
                resetRow.Label("");
                resetRow.Button("Reset", x => x.Reset());
                var runOptimizeRow = circlePackingGroupBox.Row();
                runOptimizeRow.Label("");
                runOptimizeRow.Button("Run", x => x.Run());
                var stopOptimizeRow = circlePackingGroupBox.Row();
                stopOptimizeRow.Label("");
                stopOptimizeRow.Button("Stop", x => x.Stop());
                var deleteCircleRow = circlePackingGroupBox.Row();
            }
            {
                var componentsBuilder = builder.Row().GroupBox("Components", x => x, x => x != null).Table();
                // todo: to ArrayTable
                var componentsCache       = (IEnumerable <ISceneNodeComponent>)null;
                var componentsStringCache = "";
                componentsBuilder.Row().Label(n =>
                {
                    if (n.Components != componentsCache)
                    {
                        componentsCache       = n.Components;
                        componentsStringCache = string.Join("\n", n.Components.Select(c => c.AmInterface.Name));
                    }
                    return(componentsStringCache);
                });

                var newComponentViewModel    = new NewComponentViewModel(() => selectedSceneNode);
                var newComponentPanelBuilder = componentsBuilder.Row().Panel(x => newComponentViewModel, x => true).Table();
                var newComponentRow          = newComponentPanelBuilder.Row();
                newComponentRow.DropDown(x => x.ComponentType, new Dictionary <string, Type>
                {
                    ["Rotate Once"]        = typeof(RotateOnceComponent),
                    ["Highlight on Mouse"] = typeof(HighlightOnMouseComponent),
                    ["Warp Scrolling"]     = typeof(WarpScrollComponent),
                });
                newComponentRow.Button("Add", x =>
                {
                    componentsCache = null;
                    ISceneNodeComponent component;
                    if (x.ComponentType == typeof(RotateOnceComponent))
                    {
                        component = AmFactory.Create <RotateOnceComponent>();
                    }
                    else if (x.ComponentType == typeof(HighlightOnMouseComponent))
                    {
                        component = AmFactory.Create <HighlightOnMouseComponent>();
                    }
                    else if (x.ComponentType == typeof(WarpScrollComponent))
                    {
                        component = AmFactory.Create <WarpScrollComponent>();
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    newComponentViewModel.GetNode().Components.Add(component);
                    undoRedo.OnChange();
                });
            }
            builder.Row().Panel(x => x, x => true);

            rootControl = mainPanel;
            renderLoopDispatcher.AfterUpdate += Update;
        }
Esempio n. 15
0
        private bool TryHandleMouseEvent(IMouseEvent eventArgs)
        {
            void AdjustForAspectRatio(ref Vector2 sp)
            {
                if (!preserveAspectRatio)
                {
                    return;
                }
                sp.X = firstPoint.X > sp.X
                    ? firstPoint.X - aspectRatio * Math.Abs(firstPoint.Y - sp.Y)
                    : firstPoint.X + aspectRatio * Math.Abs(firstPoint.Y - sp.Y);
            }

            switch (state)
            {
            case State.Ready:
                if (eventArgs.EventButtons == MouseButtons.Left)
                {
                    if (!TryGetPoint(eventArgs, out _, out firstPoint))
                    {
                        entity.Deparent();
                        return(false);
                    }
                    state = State.Began;
                }
                return(true);

            case State.Began:
                if ((eventArgs.State.Buttons & MouseButtons.Left) == 0)
                {
                    state = State.Ready;
                }
                else if (eventArgs.IsOfType(MouseEventType.Move))
                {
                    if (!TryGetPoint(eventArgs, out var placementNode, out var secondPoint))
                    {
                        entity.Deparent();
                        return(false);
                    }
                    AdjustForAspectRatio(ref secondPoint);
                    rectangleComponent.Rectangle = new AaRectangle2(firstPoint, secondPoint);
                    placementNode.ChildNodes.AddUnique(entity);
                    state = State.Expanding;
                }
                return(true);

            case State.Expanding:
                if ((eventArgs.State.Buttons & MouseButtons.Left) == 0)
                {
                    if (!TryGetPoint(eventArgs, out var placementNode, out var secondPoint))
                    {
                        entity.Deparent();
                        state = State.Ready;
                        return(false);
                    }
                    AdjustForAspectRatio(ref secondPoint);
                    rectangleComponent.Rectangle = new AaRectangle2(firstPoint, secondPoint);
                    entity.Deparent();
                    placementNode.ChildNodes.Add(entity);
                    undoRedo.OnChange();
                    state = State.Finished;
                    toolService.CurrentTool = null;
                }
                else if (eventArgs.IsOfType(MouseEventType.Move))
                {
                    if (!TryGetPoint(eventArgs, out _, out var secondPoint))
                    {
                        entity.Deparent();
                        return(false);
                    }
                    AdjustForAspectRatio(ref secondPoint);
                    rectangleComponent.Rectangle = new AaRectangle2(firstPoint, secondPoint);
                }
                return(true);

            case State.Finished:
                throw new InvalidOperationException("Tryng to reuse a tool.");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }