Ejemplo n.º 1
0
        public void AddEditorUI(string id, ITreeNodeView view, InspectorProperty property)
        {
            _property = property;
            var           label   = view.TreeItem;
            AGSTextConfig config  = new AGSTextConfig(autoFit: AutoFit.LabelShouldFitText);
            var           textbox = _factory.GetTextBox(id,
                                                        label.X, label.Y, label.TreeNode.Parent,
                                                        "", config, width: 100f, height: 20f);

            textbox.Text = property.Value;
            textbox.TextBackgroundVisible = false;
            _textbox            = textbox;
            textbox.RenderLayer = label.RenderLayer;
            textbox.Z           = label.Z;
            HoverEffect.Add(textbox, Colors.Transparent, Colors.DarkSlateBlue);
            textbox.OnPressingKey.Subscribe(args =>
            {
                if (args.PressedKey != Key.Enter)
                {
                    return;
                }
                args.ShouldCancel = true;
                textbox.IsFocused = false;
                property.Prop.SetValue(property.Object, textbox.Text);
            });
        }
Ejemplo n.º 2
0
        public void AddEditorUI(string id, ITreeNodeView view, InspectorProperty property)
        {
            _property = property;
            var label   = view.TreeItem;
            var config  = _enabled ? GameViewColors.TextConfig : GameViewColors.ReadonlyTextConfig;
            var textbox = _factory.UI.GetTextBox(id,
                                                 label.X, label.Y, label.TreeNode.Parent,
                                                 "", config, width: 100f, height: 20f);

            textbox.Text = property.Value;
            textbox.TextBackgroundVisible = false;
            textbox.Enabled = _enabled;
            if (_enabled)
            {
                GameViewColors.AddHoverEffect(textbox);
            }
            _textbox            = textbox;
            textbox.RenderLayer = label.RenderLayer;
            textbox.Z           = label.Z;
            HoverEffect.Add(textbox, Colors.Transparent, Colors.DarkSlateBlue);
            textbox.OnPressingKey.Subscribe(args =>
            {
                if (args.PressedKey != Key.Enter)
                {
                    return;
                }
                args.ShouldCancel = true;
                textbox.IsFocused = false;
                property.Prop.SetValue(property.Object, textbox.Text);
            });
            textbox.LostFocus.Subscribe(args => {
                property.Prop.SetValue(property.Object, textbox.Text);
            });
        }
Ejemplo n.º 3
0
        public IScrollbar GetScrollbar(string idPrefix, SliderDirection direction,
                                       IObject parent = null, float width = 15f, float height = 15f, float step = 10f, float buttonBorderWidth = 1f)
        {
            var slider = GetSlider($"{idPrefix}_{direction}Slider", null, null, 0f, 0f, 0f, parent);

            slider.ShouldClampValuesWhenChangingMinMax = false;
            slider.Direction             = direction;
            slider.HandleGraphics.Pivot  = slider.IsHorizontal() ? new PointF(1f, 0f) : new PointF(0f, 1f);
            slider.Graphics.Pivot        = new PointF(0f, 0f);
            slider.Graphics.Border       = _borders.SolidColor(Colors.DarkGray, 0.5f, true);
            slider.HandleGraphics.Border = _borders.SolidColor(Colors.White, 0.5f, true);
            float gutterSize = slider.IsHorizontal() ? height : width;

            HoverEffect.Add(slider.Graphics, Colors.Gray, Colors.LightGray);
            HoverEffect.Add(slider.HandleGraphics, Colors.DarkGray, Colors.WhiteSmoke);

            (var up, var down) = slider.IsHorizontal() ? (ArrowDirection.Left, ArrowDirection.Right) : (ArrowDirection.Up, ArrowDirection.Down);
            PointF pivot = slider.IsHorizontal() ? (1f, 0f) : (0f, 1f);

            (var upX, var upY) = slider.IsHorizontal() ? (0f, buttonBorderWidth / 2f) : (buttonBorderWidth / 2f, height - gutterSize * 2f);
            (var idle, var hovered, var pushed) = getArrowButtonAnimations(up, buttonBorderWidth);
            var upButton = GetButton($"{idPrefix}_Scroll{up}Button", idle, hovered, pushed, upX, upY, slider, width: gutterSize - buttonBorderWidth, height: gutterSize - buttonBorderWidth);

            upButton.Pivot = pivot;
            upButton.MouseClicked.Subscribe(args =>
            {
                if (direction == SliderDirection.TopToBottom || direction == SliderDirection.LeftToRight)
                {
                    slider.Decrease(step);
                }
                else
                {
                    slider.Increase(step);
                }
                _focus.HasKeyboardFocus = slider;
            });

            (var downX, var downY)  = slider.IsHorizontal() ? (width - gutterSize * 2f, buttonBorderWidth / 2f) : (buttonBorderWidth / 2f, 0f);
            (idle, hovered, pushed) = getArrowButtonAnimations(down, buttonBorderWidth);
            var downButton = GetButton($"{idPrefix}_Scroll{down}Button", idle, hovered, pushed, downX, downY, slider, width: gutterSize - buttonBorderWidth, height: gutterSize - buttonBorderWidth);

            downButton.Pivot = pivot;
            downButton.MouseClicked.Subscribe(args =>
            {
                if (direction == SliderDirection.TopToBottom || direction == SliderDirection.LeftToRight)
                {
                    slider.Increase(step);
                }
                else
                {
                    slider.Decrease(step);
                }
                _focus.HasKeyboardFocus = slider;
            });

            var scrollbar = new AGSScrollbar(upButton, downButton, slider);

            scrollbar.Step = step;
            return(scrollbar);
        }
Ejemplo n.º 4
0
        public IPanel CreateScrollingPanel(IPanel panel, float gutterSize = 15f)
        {
            var contentsPanel = GetPanel($"{panel.ID}_Contents", panel.Width, panel.Height, 0f, 0f, panel);

            contentsPanel.Opacity = 0;

            contentsPanel.RenderLayer = panel.RenderLayer;

            contentsPanel.AddComponent <ICropChildrenComponent>();
            var box = contentsPanel.AddComponent <IBoundingBoxWithChildrenComponent>();
            IScrollingComponent scroll = contentsPanel.AddComponent <IScrollingComponent>();

            var horizSlider = GetSlider($"{panel.ID}_HorizontalSlider", null, null, 0f, 0f, 0f, panel);

            horizSlider.HandleGraphics.Pivot  = new PointF(0f, 0f);
            horizSlider.Direction             = SliderDirection.LeftToRight;
            horizSlider.Graphics.Pivot        = new PointF(0f, 0f);
            horizSlider.Graphics.Border       = AGSBorders.SolidColor(Colors.DarkGray, 0.5f, true);
            horizSlider.HandleGraphics.Border = AGSBorders.SolidColor(Colors.White, 0.5f, true);
            HoverEffect.Add(horizSlider.Graphics, Colors.Gray, Colors.LightGray);
            HoverEffect.Add(horizSlider.HandleGraphics, Colors.DarkGray, Colors.WhiteSmoke);

            var verSlider = GetSlider($"{panel.ID}_VerticalSlider", null, null, 0f, 0f, 0f, panel);

            verSlider.HandleGraphics.Pivot  = new PointF(0f, 0f);
            verSlider.Direction             = SliderDirection.TopToBottom;
            verSlider.Graphics.Pivot        = new PointF(0f, 0f);
            verSlider.Graphics.Border       = AGSBorders.SolidColor(Colors.DarkGray, 0.5f, true);
            verSlider.HandleGraphics.Border = AGSBorders.SolidColor(Colors.White, 0.5f, true);
            verSlider.MaxHandleOffset       = gutterSize;
            HoverEffect.Add(verSlider.Graphics, Colors.Gray, Colors.LightGray);
            HoverEffect.Add(verSlider.HandleGraphics, Colors.DarkGray, Colors.WhiteSmoke);

            (var idle, var hovered, var pushed) = getArrowButtonAnimations(ArrowDirection.Up, 1f);
            var upButton = GetButton($"{panel.ID}_ScrollUpButton", idle, hovered, pushed, 0f, panel.Height - gutterSize * 2f, verSlider, width: gutterSize, height: gutterSize);

            upButton.Pivot = new PointF(0f, 1f);
            upButton.MouseClicked.Subscribe(args => verSlider.Value--);

            (idle, hovered, pushed) = getArrowButtonAnimations(ArrowDirection.Down, 1f);
            var downButton = GetButton($"{panel.ID}_ScrollDownButton", idle, hovered, pushed, 0f, 0f, verSlider, width: gutterSize, height: gutterSize);

            downButton.Pivot = new PointF(0f, 1f);
            downButton.MouseClicked.Subscribe(args => verSlider.Value++);

            (idle, hovered, pushed) = getArrowButtonAnimations(ArrowDirection.Left, 1f);
            var leftButton = GetButton($"{panel.ID}_ScrollUpLeft", idle, hovered, pushed, 0f, 0f, horizSlider, width: gutterSize, height: gutterSize);

            leftButton.Pivot = new PointF(1f, 0f);
            leftButton.MouseClicked.Subscribe(args => horizSlider.Value--);

            (idle, hovered, pushed) = getArrowButtonAnimations(ArrowDirection.Right, 1f);
            var rightButton = GetButton($"{panel.ID}_ScrollDownRight", idle, hovered, pushed, panel.Width - gutterSize * 2f, 0f, horizSlider, width: gutterSize, height: gutterSize);

            rightButton.Pivot = new PointF(0f, 0f);
            rightButton.MouseClicked.Subscribe(args => horizSlider.Value++);

            PropertyChangedEventHandler resize = (_, args) =>
            {
                if (args.PropertyName != nameof(IScaleComponent.Width) && args.PropertyName != nameof(IScaleComponent.Height))
                {
                    return;
                }
                panel.BaseSize                   = new SizeF(contentsPanel.Width + gutterSize, contentsPanel.Height + gutterSize);
                horizSlider.Graphics.Image       = new EmptyImage(panel.Width - gutterSize * 2f, gutterSize);
                horizSlider.HandleGraphics.Image = new EmptyImage(gutterSize, gutterSize);
                verSlider.Graphics.Image         = new EmptyImage(gutterSize, panel.Height - gutterSize * 3f);
                verSlider.HandleGraphics.Image   = new EmptyImage(gutterSize, gutterSize);
                horizSlider.X   = -panel.Width * panel.Pivot.X + gutterSize;
                verSlider.X     = panel.Width - gutterSize;
                verSlider.Y     = gutterSize * 2f;
                upButton.Y      = panel.Height - gutterSize * 2f;
                rightButton.X   = panel.Width - gutterSize * 2f;
                contentsPanel.Y = gutterSize;
            };

            resize(this, new PropertyChangedEventArgs(nameof(IScaleComponent.Width)));
            scroll.HorizontalScrollBar = horizSlider;
            scroll.VerticalScrollBar   = verSlider;

            contentsPanel.Bind <IScaleComponent>(c => c.PropertyChanged += resize, c => c.PropertyChanged -= resize);

            return(contentsPanel);
        }
Ejemplo n.º 5
0
        public void CreateScrollingPanel(IPanel panel)
        {
            panel.AddComponent <ICropChildrenComponent>();
            var box = panel.AddComponent <IBoundingBoxWithChildrenComponent>();
            IScrollingComponent scroll = panel.AddComponent <IScrollingComponent>();

            var horizSlider = GetSlider($"{panel.ID}_HorizontalSlider", null, null, 0f, 0f, 0f, panel);

            horizSlider.HandleGraphics.Pivot  = new PointF(0f, 0.5f);
            horizSlider.Direction             = SliderDirection.LeftToRight;
            horizSlider.Graphics.Pivot        = new PointF(0f, 0.5f);
            horizSlider.Graphics.Border       = AGSBorders.SolidColor(Colors.DarkGray, 0.5f, true);
            horizSlider.HandleGraphics.Border = AGSBorders.SolidColor(Colors.White, 0.5f, true);
            HoverEffect.Add(horizSlider.Graphics, Colors.Gray, Colors.LightGray);
            HoverEffect.Add(horizSlider.HandleGraphics, Colors.DarkGray, Colors.WhiteSmoke);

            var verSlider = GetSlider($"{panel.ID}_VerticalSlider", null, null, 0f, 0f, 0f, panel);

            verSlider.HandleGraphics.Pivot  = new PointF(0.5f, 0f);
            verSlider.Direction             = SliderDirection.TopToBottom;
            verSlider.Graphics.Pivot        = new PointF(0.5f, 0f);
            verSlider.Graphics.Border       = AGSBorders.SolidColor(Colors.DarkGray, 0.5f, true);
            verSlider.HandleGraphics.Border = AGSBorders.SolidColor(Colors.White, 0.5f, true);
            HoverEffect.Add(verSlider.Graphics, Colors.Gray, Colors.LightGray);
            HoverEffect.Add(verSlider.HandleGraphics, Colors.DarkGray, Colors.WhiteSmoke);

            box.EntitiesToSkip.AddRange(new List <string> {
                horizSlider.ID, horizSlider.HandleGraphics.ID, horizSlider.Graphics.ID,
                verSlider.ID, verSlider.HandleGraphics.ID, verSlider.Graphics.ID
            });

            PropertyChangedEventHandler resize = (_, args) =>
            {
                if (args.PropertyName != nameof(IScaleComponent.Width) && args.PropertyName != nameof(IScaleComponent.Height))
                {
                    return;
                }
                const float widthFactor  = 25f;
                const float heightFactor = 25f;
                float       widthUnit    = panel.Width / widthFactor;
                float       heightUnit   = panel.Height / heightFactor;
                horizSlider.Graphics.Image       = new EmptyImage(panel.Width - widthUnit * 2f, heightUnit / 2f);
                horizSlider.HandleGraphics.Image = new EmptyImage(widthUnit, heightUnit);
                verSlider.Graphics.Image         = new EmptyImage(widthUnit / 2f, panel.Height - heightUnit * 4f);
                verSlider.HandleGraphics.Image   = new EmptyImage(widthUnit, heightUnit);
                horizSlider.X = -panel.Width * panel.Pivot.X + widthUnit;
                horizSlider.Y = heightUnit;
                verSlider.X   = panel.Width - widthUnit;
                verSlider.Y   = heightUnit * 2f;
            };

            panel.Bind <IStackLayoutComponent>(
                c => c.EntitiesToIgnore.AddRange(new List <string> {
                verSlider.ID, horizSlider.ID
            }), _ => {});

            resize(this, new PropertyChangedEventArgs(nameof(IScaleComponent.Width)));
            scroll.HorizontalScrollBar = horizSlider;
            scroll.VerticalScrollBar   = verSlider;

            panel.Bind <IScaleComponent>(c => c.PropertyChanged += resize, c => c.PropertyChanged -= resize);
        }