public NamedArrowCursorControl()
        {
            this.Container = new Canvas();
            this.Cursor = new ArrowCursorControl().AttachContainerTo(this.Container);

            var ShadowCointainer = new Canvas().AttachTo(this.Container);

            Func<int, Action> CreateShadow =
                ShadowLength => Enumerable.Range(2, ShadowLength).ToOrphanizeAction(
                    (c, i) => new Rectangle
                    {
                        Fill = Brushes.Black,
                        Width = 3,
                        Opacity = 1.0 - (double)i / (double)ShadowLength,
                        Height = 18
                    }
                    .AttachTo(ShadowCointainer)
                    .MoveTo(12 + i * 3, 24)
                );

            //this.CreateShadow = CreateShadow.ToContinuation((string t) => 10 + t.Length);
            this.CreateShadow = t => { };

            this.LabelShadow = new TextBox
            {
                IsReadOnly = true,
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0),
                Foreground = Brushes.Black,
                Width = 400,
                Height = 18,
                TextAlignment = TextAlignment.Left,
                FontFamily = new FontFamily("Verdana")
            }.AttachTo(Container).MoveTo(12 + 1, 24 + 1);

            this.Label = new TextBox
            {
                IsReadOnly = true,
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0),
                Foreground = Brushes.White,
                Width = 400,
                Height = 18,
                TextAlignment = TextAlignment.Left,
                FontFamily = new FontFamily("Verdana")
            }.AttachTo(Container).MoveTo(12, 24);
        }
		public DynamicCursorCanvas()
		{
			Width = DefaultWidth;
			Height = DefaultHeight;

			var g = Colors.Yellow.ToGradient(Colors.Red, DefaultHeight).ToArray();
			
			g.Select(
				(c, i) =>
					new Rectangle
					{
						Fill = new SolidColorBrush(c),
						Width = DefaultWidth,
						Height = 2,
					}.MoveTo(0, i).AttachTo(this)
			).ToArray();


			var cur = new ArrowCursorControl();

			cur.Cyan.Opacity = 0;
			cur.Magenta.Opacity = 0;
			cur.Yellow.Opacity = 0;


			new Rectangle
		   {
			   Fill = Brushes.Red,
			   Width = 32,
			   Height = 32
		   }.MoveTo(32, 32).AttachTo(this);

			new Rectangle
		   {
			   Fill = Brushes.Green,
			   Width = 32,
			   Height = 32
		   }.MoveTo(32 * 2, 32).AttachTo(this);

			new Rectangle
			{
				Fill = Brushes.Blue,
				Width = 32,
				Height = 32
			}.MoveTo(32 * 3, 32).AttachTo(this);


			cur.Container.AttachTo(this).MoveTo(64, 64);

			var Overlay = new Rectangle
			{
				Fill = Brushes.White,
				Width = DefaultWidth,
				Height = DefaultHeight,
				Opacity = 0
			}.AttachTo(this);


			var Overlay_Red = new Rectangle
			{
				Fill = Brushes.Red,
				Width = 32,
				Height = 32,
				Opacity = 0
			}.MoveTo(32, 32).AttachTo(this);

			var Overlay_Green = new Rectangle
			{
				Fill = Brushes.Green,
				Width = 32,
				Height = 32,
				Opacity = 0
			}.MoveTo(32 * 2, 32).AttachTo(this);

			var Overlay_Blue = new Rectangle
			{
				Fill = Brushes.Blue,
				Width = 32,
				Height = 32,
				Opacity = 0
			}.MoveTo(32 * 3, 32).AttachTo(this);


			var Overlay_Y = new Rectangle
			{
				Fill = Brushes.Blue,
				Width = 32,
				Height = DefaultHeight,
				Opacity = 0
			}.AttachTo(this);

			Overlay_Y.MouseMove +=
			(sender, e) =>
				{
					var p = e.GetPosition(this);

					cur.Color = g[Convert.ToInt32(p.Y)];
				};

			this.Cursor = Cursors.None;


			Overlay_Red.MouseEnter +=
				delegate
				{
					// http://acept.asu.edu/PiN/rdg/color/composition.shtml
					cur.Color = Colors.Red;

				};

			Overlay_Green.MouseEnter +=
				delegate
				{
					// http://acept.asu.edu/PiN/rdg/color/composition.shtml
					cur.Color = Colors.Green;
				};

			Overlay_Blue.MouseEnter +=
				delegate
				{
					// http://acept.asu.edu/PiN/rdg/color/composition.shtml
					cur.Color = Colors.Blue;
				};

			this.MouseMove +=
				(sender, e) =>
				{
					var p = e.GetPosition(this);


					cur.Container.MoveTo(p.X, p.Y);
				};
		}
		public NumericTransmitterCanvas()
		{
			Width = DefaultWidth;
			Height = DefaultHeight;

			Colors.Blue.ToGradient(Colors.Red, DefaultHeight / 4).Select(
				(c, i) =>
					new Rectangle
					{
						Fill = new SolidColorBrush(c),
						Width = DefaultWidth,
						Height = 4,
					}.MoveTo(0, i * 4).AttachTo(this)
			).ToArray();

			var c1 = new ArrowCursorControl
			{

			};

			c1.Red.Opacity = 0.8;
			c1.Container.AttachTo(this);


			var c2 = new ArrowCursorControl
			{

			};

			c2.Yellow.Opacity = 0.8;
			c2.Container.AttachTo(this);


			var c3 = new ArrowCursorControl
			{

			};

			c3.Green.Opacity = 0.8;
			c3.Container.AttachTo(this);

			var Overlay = new Rectangle
			{
				Fill = Brushes.White,
				Width = DefaultWidth,
				Height = DefaultHeight,
				Opacity = 0,
				Cursor = Cursors.None
			}.AttachTo(this);

			Action<int, int> Emitter = NumericEmitter.Of(
				(x, y) => c3.Container.MoveTo(x, y)
			);


			Action<int, int> Omitter = NumericOmitter.Of(
				(x, y) =>
				{
					c2.Container.MoveTo(x, y);
					Emitter(x, y);
				}
			);

			


			Overlay.MouseMove +=
				(sender, e) =>
				{
					var p = e.GetPosition(this);

					c1.Container.MoveTo(p.X, p.Y);

					//1000.AtDelay(
					//    delegate
					//    {
					//        c2.Container.MoveTo(p.X, p.Y);
					//    }
					//);

					300.AtDelay(
						() => Omitter(Convert.ToInt32(p.X), Convert.ToInt32(p.Y))
					);
				};
		}
Esempio n. 4
0
        public TileFieldTest()
        {
            this.Width = DefaultWidth;
            this.Height = DefaultHeight;

            new[]
            {
                Colors.White,
                Colors.Blue,
                Colors.Red,
                Colors.Yellow
            }.ToGradient(DefaultHeight / 4).ForEach(
                (c, i) =>
                new Rectangle
                {
                    Fill = new SolidColorBrush(c),
                    Width = DefaultWidth,
                    Height = 5,
                }.MoveTo(0, i * 4).AttachTo(this)
            );

            var t = new TextBox
            {
                AcceptsReturn = true,
                Background = Brushes.White,
                BorderThickness = new Thickness(0),
                Text = "hello world" + Environment.NewLine,
                Width = DefaultWidth / 2,
                Height = DefaultHeight / 4
            }.AttachTo(this).MoveTo(DefaultWidth / 4, 4);

            var OverlayCanvas = new Canvas
            {
                Width = DefaultWidth,
                Height = DefaultHeight
            };

            var OverlayRectangle = new Rectangle
            {
                Width = DefaultWidth,
                Height = DefaultHeight,
                Fill = Brushes.Black,
                Opacity = 0
            }.AttachTo(OverlayCanvas);

            var field = new TileField(8, 6);
            var field_x = 64;
            var field_y = 200;

            field.Container.MoveTo(field_x, field_y).AttachTo(this);
            field.Overlay.MoveTo(field_x, field_y).AttachTo(OverlayCanvas);

            var WaterFlow = new Queue<Action>();

            #region pipes
            {

                var pipe = new Pipe.PumpToLeft();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 5, field_y + Tile.ShadowBorder + 52 * 0 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i =>
                        WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            Enumerable.Range(0, 2).ForEach(
                ix_ =>
                {
                    var ix = 4 - ix_;

                    var pipe = new Pipe.LeftToRight();

                    pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * ix, field_y + Tile.ShadowBorder + 52 * 0 - 12).AttachTo(this);

                    pipe.Water.ForEachReversed(
                        i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                    );

                }

            );

            {

                var pipe = new Pipe.RightToBottom();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 2, field_y + Tile.ShadowBorder + 52 * 0 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            Enumerable.Range(1, 2).ForEach(
                iy =>
                {

                    var pipe = new Pipe.TopToBottom();

                    pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 2, field_y + Tile.ShadowBorder + 52 * iy - 12).AttachTo(this);

                    pipe.Water.ForEach(
                        i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                    );

                }
            );

            {

                var pipe = new Pipe.TopToRight();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 2, field_y + Tile.ShadowBorder + 52 * 3 - 12).AttachTo(this);

                pipe.Water.ForEach(
                                i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                            );

            }

            Enumerable.Range(3, 3).ForEach(
                ix =>
                {

                    var pipe = new Pipe.LeftToRight();

                    pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * ix, field_y + Tile.ShadowBorder + 52 * 3 - 12).AttachTo(this);

                    pipe.Water.ForEach(
                        i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                    );

                }
            );

            field[3, 2].Drain.Visibility = Visibility.Visible;

            {

                var pipe = new Pipe.LeftToDrain();

                field[6, 3].Drain.Visibility = Visibility.Visible;

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 6, field_y + Tile.ShadowBorder + 52 * 3 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            {

                var pipe = new Pipe.PumpToRight();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 0, field_y + Tile.ShadowBorder + 52 * 1 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i =>
                        WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            {

                var pipe = new Pipe.LeftToRight();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 1, field_y + Tile.ShadowBorder + 52 * 1 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            {

                var pipe = new Pipe.LeftToRightBent();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 2, field_y + Tile.ShadowBorder + 52 * 1 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            Enumerable.Range(3, 4).ForEach(
                ix =>
                {

                    var pipe = new Pipe.LeftToRight();

                    pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * ix, field_y + Tile.ShadowBorder + 52 * 1 - 12).AttachTo(this);

                    pipe.Water.ForEach(
                        i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                    );

                }
            );

            {

                var pipe = new Pipe.LeftToBottom();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 7, field_y + Tile.ShadowBorder + 52 * 1 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            Enumerable.Range(2, 2).ForEach(
                iy =>
                {

                    var pipe = new Pipe.TopToBottom();

                    pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 7, field_y + Tile.ShadowBorder + 52 * iy - 12).AttachTo(this);

                    pipe.Water.ForEach(
                        i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                    );

                }
            );

            {

                var pipe = new Pipe.TopToLeft();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 7, field_y + Tile.ShadowBorder + 52 * 4 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            Enumerable.Range(0, 3).ForEach(
                ix_ =>
                {
                    var ix = 6 - ix_;

                    var pipe = new Pipe.LeftToRight();

                    pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * ix, field_y + Tile.ShadowBorder + 52 * 4 - 12).AttachTo(this);

                    pipe.Water.ForEachReversed(
                        i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                    );

                }
            );

            {

                var pipe = new Pipe.RightToDrain();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 3, field_y + Tile.ShadowBorder + 52 * 4 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }
            #endregion

            field[3, 4].Drain.Visibility = Visibility.Visible;

            OverlayCanvas.AttachTo(this).MoveTo(0, 0);

            var Navigationbar = new AeroNavigationBar();

            Navigationbar.Container.MoveTo(4, 4).AttachTo(this);

            var c1 = new ArrowCursorControl
            {

            };

            c1.Container.MoveTo(32, 32).AttachTo(this);
            c1.Red.Opacity = 0.7;

            OverlayCanvas.MouseMove +=
                (sender, e) =>
                {
                    var p = e.GetPosition(OverlayCanvas);

                    c1.Container.MoveTo(32 + p.X, 32 + p.Y);
                };

            OverlayCanvas.MouseLeave +=
                delegate
                {
                    c1.Container.Visibility = Visibility.Hidden;
                };

            OverlayCanvas.MouseEnter +=
                delegate
                {
                    c1.Container.Visibility = Visibility.Visible;
                };

            foreach (var n in KnownAssets.Default.FileNames)
            {
                t.AppendTextLine(n);
            }

            3000.AtDelay(
                delegate
                {
                    (1000 / 10).AtIntervalWithTimer(
                        ttt =>
                        {
                            if (WaterFlow.Count == 0)
                            {
                                ttt.Stop();
                                return;
                            }

                            WaterFlow.Dequeue()();
                        }
                    );
                }
            );
        }