Exemplo n.º 1
0
        static IControl Create(IProperty <bool> enabled, Points circleRadius, Points additionalWidth)
        {
            double outlineThickness  = 1;
            Points backgroundPadding = 1;

            var enabledValue = enabled.Select(isEnabled => isEnabled ? 1.0 : 0.0).LowPass(0.3);

            var circleSize   = Size.Create(circleRadius);
            var cornerRadius = Observable.Return(new CornerRadius(circleRadius / 2.5));
            var circle       = Shapes.Circle(
                Stroke.Create(1.0, Theme.SwitchThumbStroke),
                Theme.SwitchThumbFill)
                               .WithSize(circleSize);

            var foreground = circle.WithPadding(
                enabledValue.Select(v => Thickness.Create <Points>(v * additionalWidth, 0, (1 - v) * additionalWidth, 0)));

            var backgroundStroke = Stroke.Create(
                Observable.Return(outlineThickness),
                Theme.SwitchInactiveStroke.Mix(Theme.SwitchActiveStroke, enabledValue),
                Observable.Return(StrokeDashArray.Solid));
            var backgroundBrush = Theme.SwitchInactiveBackground.Mix(Theme.SwitchActiveBackground, enabledValue);
            var background      = Shapes.Rectangle(
                backgroundStroke,
                backgroundBrush,
                cornerRadius);

            var content = foreground
                          .WithBackground((background.WithPadding(new Thickness <Points>(backgroundPadding))));

            return(Button.Create(
                       clicked: enabled.Toggle(),
                       content: buttonStates => content));
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            this.InitializeComponent();

            this.Loaded += (sender, args) =>
            {
                Animate animate = new Animate((sys, extents) =>
                {
                    Behavior <double> time = sys.Time;
                    double t0                    = time.Sample();
                    double ballRadius            = 15;
                    double leftWall              = -extents.X + ballRadius;
                    double rightWall             = extents.X - ballRadius;
                    double floor                 = -extents.Y + ballRadius;
                    double roof                  = extents.Y - ballRadius;
                    Signal gravity               = new Signal(t0, 0, 0, -1200);
                    StreamLoop <Signal> sBounceX = new StreamLoop <Signal>();
                    StreamLoop <Signal> sBounceY = new StreamLoop <Signal>();
                    Cell <Signal> velx           = sBounceX.Hold(new Signal(t0, 0, 0, 350));
                    Cell <Signal> vely           = sBounceY.Hold(gravity.Integrate(0));
                    Cell <Signal> posx           = Signal.Integrate(velx, leftWall);
                    Cell <Signal> posy           = Signal.Integrate(vely, roof);
                    sBounceX.Loop(BounceAt(sys, velx, posx, leftWall).OrElse(BounceAt(sys, velx, posx, rightWall)));
                    sBounceY.Loop(BounceAt(sys, vely, posy, floor));
                    return(Shapes.Translate(Shapes.Scale(Shapes.Circle(Colors.Red), Behavior.Constant(ballRadius)), time.Lift(posx.AsBehavior(), posy.AsBehavior(), (t, x, y) => new Point(x.ValueAt(t), y.ValueAt(t)))));
                }, this.Placeholder.RenderSize);
                this.Placeholder.Children.Add(animate);
                animate.Start();
            };
        }
Exemplo n.º 3
0
        public MainWindow()
        {
            this.InitializeComponent();

            this.Loaded += (sender, args) =>
            {
                Animate animate = new Animate((sys, extents) =>
                {
                    Behavior <double> time   = sys.Time;
                    double maxSize           = 105;
                    Behavior <double> offset = time.Map(t =>
                    {
                        double frac = t - Math.Floor(t);
                        return((frac < 0.5 ? frac - 0.25 : 0.75 - frac) * 4.0 * maxSize);
                    });
                    Behavior <double> fifty = Behavior.Constant(50.0);
                    Behavior <DrawableDelegate> greenBall = Shapes.Translate(
                        Shapes.Scale(Shapes.Circle(Colors.Green), fifty),
                        offset.Map(x => new Point(x, 0.0)));
                    Behavior <DrawableDelegate> blueBall = Shapes.Translate(
                        Shapes.Scale(Shapes.Circle(Colors.Blue), fifty),
                        offset.Map(y => new Point(0.0, y)));
                    return(Shapes.Over(greenBall, blueBall));
                }, this.Placeholder.RenderSize);
                this.Placeholder.Children.Add(animate);
                animate.Start();
            };
        }
Exemplo n.º 4
0
        public void Circle_CheckCalculationArea()
        {
            double radius   = 5;
            double expected = Math.PI * Math.Pow(radius, 2);

            ICircle circle = Shapes.Circle(radius);

            Assert.AreEqual(expected, circle.Area, "Площадь круга вычисляется некорректно");
        }
Exemplo n.º 5
0
        static IControl Pane(string name, IEditorFactory editorFactory, Func <IEditorFactory, IControl> content, bool lazy, IProperty <bool> expanded)
        {
            var attributes = new AttributeIntercepter(editorFactory);

            var labelColor = lazy
                                ? Theme.DefaultText
                                : attributes.AllReadOnly
                             .Select(r => r ? Theme.DisabledText : Theme.DefaultText)
                             .Switch();

            var height = new Points(31);

            var label = Label.Create(name, font: Theme.DefaultFontBold, color: labelColor)
                        .CenterVertically();

            var expandedArrow  = Arrow.WithoutShaft(RectangleEdge.Bottom, SymbolSize.Small);
            var collapsedArrow = Arrow.WithoutShaft(RectangleEdge.Right, SymbolSize.Small);

            var arrow = expanded
                        .Select(expanded1 => expanded1 ? expandedArrow : collapsedArrow)
                        .Switch()
                        .Center()
                        .WithSize(Size.Create <Points>(13, 13))
                        .OnMouse(pressed: expanded.Toggle())
                        .CenterVertically();

            var circle = Shapes.Circle(fill: Theme.Active)
                         .WithSize(Spacer.Small.DesiredSize)
                         .CenterVertically()
                         .ShowWhen(attributes.AnyHasValue);

            return(Layout.StackFromTop(
                       Button.Create(
                           clicked: expanded.Toggle(),
                           content: s =>
                           Layout.Dock()
                           .Left(label)
                           .Left(Spacer.Small)
                           .Left(
                               circle
                               .WithHeight(height)
                               .MakeCollapsable(RectangleEdge.Top, expanded.IsFalse(), lazy: false)
                               .DockBottom())
                           .Right(arrow)
                           .Fill()
                           .WithHeight(height)
                           .WithInspectorPadding()),
                       Separator.Medium,
                       Layout.StackFromTop(
                           content(attributes),
                           Separator.Medium)
                       .MakeCollapsable(RectangleEdge.Bottom, expanded, lazy: lazy, unrootWhenCollapsed: lazy)));
        }
Exemplo n.º 6
0
        public void Circle_CheckRadius_ShouldThrowArgumentException()
        {
            double radius = -5;

            try
            {
                Assert.ThrowsException <ArgumentOutOfRangeException>(() => Shapes.Circle(radius));
            }
            catch (AssertFailedException e)
            {
                Assert.Fail($"Не получили ArgumentOutOfRangeException при вызове Shapes.Circle({radius}).", e);
            }
        }
Exemplo n.º 7
0
        internal static IControl Create(
            IProperty <string> property,
            IObservable <AbsoluteDirectoryPath> projectRoot,
            FileFilter[] fileFilters,
            Text dialogCaption)
        {
            var browseCommand = Command.Enabled(() => Task.Run(
                                                    async() =>
            {
                var root = await projectRoot.FirstAsync();
                var fn   = await FileDialog.OpenFile(new FileDialogOptions(await dialogCaption.FirstAsync() ?? "Open", root, fileFilters));
                fn.Do(
                    fdr =>
                {
                    // Have tested that RelativeTo works on Windows for paths on different
                    // drives; in that case it just gives us back the absolute path
                    var relPath = fdr.Path.RelativeTo(root).NativeRelativePath;

                    // Replace backslash on Windows to make the path valid across platforms
                    if (Path.DirectorySeparatorChar == '\\')
                    {
                        relPath = relPath.Replace('\\', '/');
                    }
                    property.Write(relPath, true);
                });
            }));

            var arrowBrush          = property.IsReadOnly.Select(ro => ro ? Theme.FieldStroke.Brush : Theme.Active).Switch();
            var browseButtonCircles =
                Layout.StackFromLeft(
                    Enumerable.Range(0, 3).Select(
                        i => Shapes.Circle(fill: arrowBrush)
                        .WithSize(new Size <Points>(2, 2))
                        .WithPadding(new Thickness <Points>(1))))
                .WithPadding(new Thickness <Points>(3));

            return(browseButtonCircles
                   .Center()
                   .WithWidth(21)
                   .WithBackground(Theme.PanelBackground)
                   .OnMouse(pressed: browseCommand));
        }
Exemplo n.º 8
0
    //takes in patterInfo and calls all relevant shape calls
    public static Vector3[] CreatePattern(PatternCreator.PatternInfo p)
    {
        switch (p.shape)
        {
        case SpawnShape.CIRCLE:
            return(Shapes.Circle(p.radius, p.angleOffset, p.circlePoints));

        case SpawnShape.STAR:
            return(Shapes.Star(p.radius, p.radiusSecond, p.fillerAmount));

        case SpawnShape.X:
            return(Shapes.Cross(p.radius, p.angleOffset, p.fillerAmount));

        case SpawnShape.CheckMark:
            return(Shapes.CheckMark(p.radius, p.radiusSecond, p.angleOffset, p.fillerAmount));

        default:
            return(Shapes.Simple(p.shape, p.radius, p.angleOffset, p.fillerAmount));
        }
    }
Exemplo n.º 9
0
        public static IControl Create(IObservable <Optional <Point <IObservable <Points> > > > hoverIndicator)
        {
            var color = Color.FromBytes(94, 184, 205);

            var indicator = Layout.Dock()
                            .Left(Shapes.Circle(Stroke.Create(2, color))
                                  .WithHeight(6).WithWidth(6))
                            .Fill(Shapes.Rectangle(fill: color)
                                  .WithHeight(2).CenterVertically());

            return(indicator
                   .WithPadding(
                       left: hoverIndicator.NotNone().Select(v => v.X.Sub(indicator.DesiredSize.Width).Sub(2)).Switch(),
                       top: hoverIndicator.NotNone().Select(v => v.Y).Switch().Sub(indicator.DesiredSize.Height.Div(2)))
                   .DockTop()
                   .ShowWhen(hoverIndicator
                             .Select(i => i.HasValue)
                             .DistinctUntilChanged()
                             .Throttle(TimeSpan.FromSeconds(1.0 / 100.0))
                             .ObserveOn(Application.MainThread)));
        }
Exemplo n.º 10
0
        public MainWindow()
        {
            this.InitializeComponent();

            this.Loaded += (sender, args) =>
            {
                Animate animate = new Animate((sys, extents) =>
                {
                    Cell <double> time = sys.Time;
                    double maxSize     = 200.0;
                    return(Shapes.Scale(
                               Shapes.Circle(Colors.Green),
                               time.Map(t =>
                    {
                        double frac = t - Math.Floor(t);
                        return (frac < 0.5 ? frac : 1.0 - frac) * maxSize;
                    })));
                }, this.Placeholder.RenderSize);
                this.Placeholder.Children.Add(animate);
                animate.Start();
            };
        }
Exemplo n.º 11
0
 static IControl CreateHeaderTitle(string title, IObservable <bool> isActive, IObservable <bool> unread, Action pressed)
 {
     isActive = isActive.StartWith(false);
     return
         (Button.Create(Command.Enabled(pressed),
                        content: states =>
                        Layout.StackFromLeft(
                            Label.Create(
                                title,
                                font: Font.SystemDefault(Observable.Return(13.0), isActive),
                                color: isActive.Select(active => active ? Theme.DefaultText : Theme.DisabledText).Switch()),
                            unread.StartWith(false).Select(b => b == false
                                                         ? Control.Empty
                                                         : Shapes.Circle(fill: Theme.NotificationBrush)
                                                           .WithSize(new Size <Points>(10, 10))
                                                           .WithPadding(new Thickness <Points>(10, 0, 0, 0))
                                                           .Center())
                            .Switch()
                            )
                        .WithPadding(new Thickness <Points>(30, 0))
                        .CenterVertically()));
 }
Exemplo n.º 12
0
        public static IControl CreateButton <T>(IObservable <object> elementChanged, IAttribute <T> property, IPopover popover)
        {
            return(popover.CreatePopover(
                       RectangleEdge.Bottom,
                       content: state =>
                       Button.Create(clicked: state.IsVisible.Toggle(), content: button =>
            {
                var circleColor = Observable.CombineLatest(
                    button.IsHovered,
                    state.IsVisible,
                    (hovering, visible) =>
                    visible
                                                                                        ? Theme.Active
                                                                                        : (hovering ? Theme.Active : Theme.FieldFocusStroke.Brush))
                                  .Switch();

                return Layout.StackFromTop(
                    Enumerable.Range(0, 3).Select(
                        i => Shapes.Circle(fill: circleColor)
                        .WithSize(new Size <Points>(2, 2))
                        .WithPadding(new Thickness <Points>(1))))
                .WithPadding(new Thickness <Points>(3));
            }),
                       popover: state =>
            {
                var result = Layout.Dock()
                             .Bottom(Button.Create(state.IsVisible.Update(false), bs =>
                                                   Layout.Dock()
                                                   .Left(Icons.Confirm(Theme.Active).CenterVertically())
                                                   .Left(Spacer.Small)
                                                   .Fill(Theme.Header("Done"))
                                                   .Center()
                                                   .WithHeight(30)))
                             .Bottom(Separator.Medium)
                             .Top(Spacer.Medium)
                             .Top(Label.Create(
                                      text: "Expression Editor",
                                      textAlignment: TextAlignment.Center,
                                      font: Theme.DefaultFont,
                                      color: Theme.DefaultText))
                             .Top(Spacer.Small)
                             .Top(Label.Create(
                                      text: "You can write expressions here instead \n of using an explicit value",
                                      textAlignment: TextAlignment.Center,
                                      font: Theme.DescriptorFont,
                                      color: Theme.DescriptorText))
                             .Top(Spacer.Medium)
                             .Left(Spacer.Medium)
                             .Right(Spacer.Medium)
                             .Bottom(Spacer.Medium)
                             .Fill(
                    TextBox.Create(
                        text: property.StringValue.Deferred(),
                        foregroundColor: Theme.DefaultText,
                        doWrap: true)
                    .WithPadding(new Thickness <Points>(1))
                    .WithBackground(Theme.FieldBackground)
                    .WithOverlay(Shapes.Rectangle(stroke: Theme.FieldStroke))
                    .WithHeight(74))
                             .WithWidth(279);

                elementChanged.ConnectWhile(result.IsRooted).Subscribe(id => state.IsVisible.OnNext(false));

                return result;
            })
                   .CenterVertically());
        }
Exemplo n.º 13
0
 public static IEnumerable <GalleryItem> RegressionList() =>
 new[]
 {
     new GalleryItem("Circle", "literally just a circle.  Most simple diagram conceivable.", () => Shapes.Circle(0.5M, Coordinate.Origin())),
     new GalleryItem("Circle", "Testing a ranging of styling", () => Shapes.Circle(0.5M, Coordinate.Origin()).WithFill(Color.Red))
 };
Exemplo n.º 14
0
        //spawn units one on each frame...
        IEnumerator SpawnUnits(int levelIndex, SO_LevelPattern levelPatterns)
        {
            //int length = levelPatterns.patterns[levelPatterns.patternIndex[levelIndex]].points.Length;

            //calculate points from PatternInfo
            PatternCreator.PatternInfo p = levelPatterns.container.GetValues()[levelPatterns.patternIndex[levelIndex]];

            //calculate points for each pattern info
            Vector3[]      points    = new Vector3[0];
            Vector3[]      normals   = new Vector3[0];
            Vector3        direction = map.position - map.TransformDirection(p.relativePosition);
            List <Vector3> list;

            //call correct shape function
            switch (p.shape)
            {
            case SpawnShape.CIRCLE:
                list = new List <Vector3>(Shapes.Circle(p.radius, p.angleOffset, p.fillerAmount));
                break;

            case SpawnShape.STAR:
                list = new List <Vector3>(Shapes.Star(p.radius, p.radius / 2f, p.fillerAmount));
                break;

            default:
                list = new List <Vector3>(Shapes.Simple(p.shape, p.radius, p.angleOffset, p.fillerAmount));
                break;
            }
            //List<Vector3> list = new List<Vector3>(PatternCreator.Shapes.GetShape(p.shape, p.fillerAmount, p.radius, p.angleOffset));
            //setup rotation
            Vector3    spawnAxis = Quaternion.AngleAxis(p.angleOffset, direction) * p.rotation;
            Quaternion rot       = Quaternion.LookRotation(direction, spawnAxis);

            //apply rotation to points
            for (int i = 0; i < list.Count; i++)
            {
                list[i] = rot * list[i];
            }


            int lengthWithPercent = Mathf.RoundToInt(list.Count * (p.viewPercentage * 0.01f));
            //to properly place points from surface after raycast
            float distanceFromSurface = GameController.Instance.GetDistanceFromSurface();

            //store proper amount of points based on percentage
            if (lengthWithPercent > 0)
            {
                int remove = list.Count - lengthWithPercent;
                list.RemoveRange(lengthWithPercent - 1, remove);
                points  = list.ToArray();
                normals = new Vector3[points.Length];
                //raycast onto map for exact points
                RaycastHit hit;
                Vector3    position      = map.TransformDirection(p.relativePosition);
                float      distanceToMap = direction.magnitude;
                for (int k = 0; k < points.Length; k++)
                {
                    points[k] += position;
                    //calculate raycast direction, depends on which bool is selected
                    //Vector3 dir = towardsCenter ? (map.position - shapePoints[i]).normalized : -transform.up;
                    //Debug.DrawLine(points[k], points[k] + -transform.transform.up, Color.yellow);
                    if (Physics.Raycast(points[k], direction, out hit, distanceToMap))
                    {
                        points[k] = hit.point + hit.normal * distanceFromSurface;
                        //needed for rotation
                        normals[k] = hit.normal;
                    }
                }
            }


            //spawn objects
            for (int i = 0; i < points.Length; i++)
            {
                AEnemy o = pools[levelPatterns.enemyTypeIndex[levelIndex]].Retrieve();

                if (o != null)
                {
                    //get position
                    //o.transform.position = levelPatterns.patterns[levelPatterns.patternIndex[levelIndex]].points[i];
                    o.transform.position = points[i];
                    //point transform down towards map
                    o.transform.rotation = Quaternion.FromToRotation(o.transform.up, normals[i]) * o.transform.rotation;
                }

                yield return(null);
            }
        }
Exemplo n.º 15
0
 static IControl Circle(Brush fillBrush)
 {
     return(PanelBorder(
                Brush.Transparent,
                Shapes.Circle(fill: fillBrush).WithWidth(11).WithHeight(11).Center()));
 }