예제 #1
0
		public MyCanvas()
		{
			Width = DefaultWidth;
			Height = DefaultHeight;

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

			var t = new TextBox
			{
				AcceptsReturn = true,
				Text = "powered by jsc",
				BorderThickness = new Thickness(0),
				Foreground = Brushes.Black,
				Background = Brushes.White,
				IsReadOnly = true,
				Width = 300,
				Height = 300
			}.MoveTo(32, 32).AttachTo(this);

			var m = new MemoryStream();
			var w = new BinaryWriter(m);

			w.Write((byte)6);
			w.Write((short)7);
			w.Write((int)8);
			w.Write("hey Ԉ \ufffc \u00ff \u0100");

			t.AppendTextLine();

			foreach (var v in m.ToArray())
			{
				t.AppendText(v + " ");
			}

			m.Position = 0;

			var r = new BinaryReader(m);

			t.AppendTextLine();
			t.AppendTextLine("bytes: " + r.BaseStream.Length);
			t.AppendTextLine("byte " + r.ReadByte());
			t.AppendTextLine("short " + r.ReadInt16());
			t.AppendTextLine("int " + r.ReadInt32());
			t.AppendTextLine("string " + r.ReadString());
		}
        public ApplicationCanvas()
        {
            r.Fill = Brushes.Red;
            r.AttachTo(this);
            r.MoveTo(8, 8);
            this.SizeChanged += (s, e) => r.SizeTo(this.Width - 16.0, this.Height - 16.0);

            var Options = new Dictionary<Type, Func<int>>
			{
				{ typeof(Canvas), 
					() => 78
				},
				{ typeof(ApplicationCanvas), 
					() => 88
				}
            };

            var t = new TextBox { AcceptsReturn = true, IsReadOnly = true }.AttachTo(this);

            t.AppendTextLine(new { First = new { Options.First().Key.Name } }.ToString());
            t.AppendTextLine(new { Last = new { Options.Last().Key.Name } }.ToString());

            t.AppendTextLine(new { FirstKey = new { Options.Keys.First().Name } }.ToString());
            t.AppendTextLine(new { LastKey = new { Options.Keys.Last().Name } }.ToString());


            Options
                //.ForEach(
               .Select(Option => new { Option.Key, Option.Value })
               .WithEachIndex(
               (Option, Index) =>
               {
                   t.AppendTextLine(new { Option.Key.Name }.ToString());

               }
           );
        }
        public ApplicationCanvas()
        {
            r.Fill = Brushes.Red;
            r.AttachTo(this);
            r.MoveTo(8, 8);
            this.SizeChanged += (s, e) => r.SizeTo(this.Width - 16.0, this.Height - 16.0);

            var t = new TextBox
            {
                AcceptsReturn = true,
                IsReadOnly = true,
            }.AttachTo(this);

            t.AppendTextLine("hello world");

            var foo = new MyDynamic { WriteLine = t.AppendTextLine };
            dynamic bar = foo;

            bar.foo = "foo";

            var goo = bar.goo;

            t.AppendTextLine(new { goo }.ToString());
        }
        public AvalonBetrisCanvas()
        {
            Width = DefaultWidth;
            Height = DefaultHeight;

            this.ClipToBounds = true;

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

            var t = new TextBox
            {
                FontSize = 10,
                Text = "powered by jsc",
                BorderThickness = new Thickness(0),
                Foreground = 0xffffffff.ToSolidColorBrush(),
                Background = Brushes.Transparent,
                IsReadOnly = true,
                Width = DefaultWidth
            }.MoveTo(8, 8).AttachTo(this);

            var t2 = new TextBox
            {
                FontSize = 10,
                AcceptsReturn = true,
                Text = @"
            BETRIS
            ",
                BorderThickness = new Thickness(0),
                Foreground = 0xffffffff.ToSolidColorBrush(),
                Background = Brushes.Transparent,
                IsReadOnly = true,
                Width = DefaultWidth,
                Height = 128,
            }.MoveTo(8, 32).AttachTo(this);

            var bg = new Image
            {
                Source = ("assets/AvalonBetris/building_block_tetris.png").ToSource()
            }.MoveTo(0, 0).AttachTo(this);

            var img = new Image
            {
                Source = ("assets/AvalonBetris/jsc.png").ToSource()
            }.MoveTo(DefaultWidth - 128, DefaultHeight - 128).AttachTo(this);

            bg.MouseLeftButtonUp +=
                (sender, args) =>
                {
                    var p = args.GetPosition(this);
                    t2.AppendTextLine(new { p.X, p.Y }.ToString());
                };

            //help.Opacity = 1;
            img.Opacity = 0.5;

            var aw = 49;
            var ah = 49;

            var tri = new Image
            {
                Width = aw,
                Height = ah,
                Source = "assets/AvalonBetris/_19a.png".ToSource()
            }.AttachTo(this);

            var trig = new Image
            {
                Width = aw,
                Height = ah,
                Source = "assets/AvalonBetris/_19b.png".ToSource()
            }.AttachTo(this);

            var tri2 = new Image
            {
                Width = aw,
                Height = ah,
                Source = "assets/AvalonBetris/_18a.png".ToSource()
            }.AttachTo(this);

            var trig2 = new Image
            {
                Width = aw,
                Height = ah,
                Source = "assets/AvalonBetris/_18b.png".ToSource()
            }.AttachTo(this);

            // cursor position calculations are not ready
            // for transofrmed elements.
            // we will provide a floor for those events...
            var shadow = new Rectangle
            {
                Width = DefaultWidth,
                Height = DefaultHeight,

                Fill = Brushes.Black,
            }.AttachTo(this);

            var shadowa = shadow.ToAnimatedOpacity();

            shadowa.Opacity = 0;

            Func<Brush, int, int, Movable> m =
                (Color, X, Y) =>
                {
                    var m0 = new Movable
                    {
                        Context = this,
                        Color = Color
                    };

                    m0.MoveTo(X, Y);

                    return m0;
                };

            var m1 = m(Brushes.Green, 197, 123);
            var m2 = m(Brushes.Red, 224, 110);
            var m3 = m(Brushes.Blue, 197, 161);
            var m4 = m(Brushes.Yellow, 222, 159);

            var m5 = m(Brushes.Green, 265, 118);
            var m6 = m(Brushes.Blue, 265, 166);

            Action Update =
                delegate
                {

                    tri.RenderTransform = new AffineTransform
                    {
                        Left = 0,
                        Top = 0,
                        Width = aw,
                        Height = ah,

                        X1 = m2.X,
                        Y1 = m2.Y,

                        X2 = m3.X,
                        Y2 = m3.Y,

                        X3 = m1.X,
                        Y3 = m1.Y,

                    };

                    trig.RenderTransform = new AffineTransform
                    {
                        Left = 0,
                        Top = 0,
                        Width = aw,
                        Height = ah,

                        X1 = m3.X,
                        Y1 = m3.Y,

                        X2 = m2.X,
                        Y2 = m2.Y,

                        X3 = m4.X,
                        Y3 = m4.Y,

                    };

                    tri2.RenderTransform = new AffineTransform
                    {
                        Left = 0,
                        Top = 0,
                        Width = aw,
                        Height = ah,

                        X1 = m5.X,
                        Y1 = m5.Y,

                        X2 = m4.X,
                        Y2 = m4.Y,

                        X3 = m2.X,
                        Y3 = m2.Y,

                    };

                    trig2.RenderTransform = new AffineTransform
                    {
                        Left = 0,
                        Top = 0,
                        Width = aw,
                        Height = ah,

                        X1 = m4.X,
                        Y1 = m4.Y,

                        X2 = m5.X,
                        Y2 = m5.Y,

                        X3 = m6.X,
                        Y3 = m6.Y,

                    };
                };

            foreach (var k in new[] { m1, m2, m3, m4, m5, m6 })
            {
                k.Container.MouseLeftButtonDown += delegate { shadowa.Opacity = 0.2; };
                k.Container.MouseLeftButtonUp += delegate { shadowa.Opacity = 0; };
                k.Changed += Update;
            }

            Update();
        }
예제 #5
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()();
                        }
                    );
                }
            );
        }
예제 #6
0
		public MyCanvas()
		{
			Width = DefaultWidth;
			Height = DefaultHeight;

			#region Gradient
			for (int i = 0; i < DefaultHeight; i += 4)
			{
				new Rectangle
				{
					Fill = ((uint)(0xff00007F + 128 * i / DefaultHeight)).ToSolidColorBrush(),
					Width = DefaultWidth,
					Height = 4,
				}.MoveTo(0, i).AttachTo(this);
			}
			#endregion


			var t = new TextBox
			{
				AcceptsReturn = true,
				Text = "",
				BorderThickness = new Thickness(0),
				Foreground = Brushes.Black,
				Background = Brushes.White,
				IsReadOnly = true,
				Width = 400,
				Height = 300
			}.MoveTo(32, 10).AttachTo(this);

			Assets.Default.FileNames.ForEach(
				(v, index, SignalNext) =>
				{
					t.AppendTextLine(v);

					v.ToStringAsset(
						value =>
						{
							t.AppendTextLine(index + ": " + value);


							500.AtDelay(SignalNext);
						}
					);
				}
			);

			//var c = new FutureStream();


			//// ready for first call
			//c.Signal();

			//foreach (var _v in Assets.Default.FileNames)
			//{
			//    var v = _v;

			//    c.Continue(
			//        SignalNext =>
			//        {

			//            t.AppendTextLine(v);

			//            v.ToStringAsset(
			//                value =>
			//                {
			//                    t.AppendTextLine(value);


			//                    SignalNext();
			//                }
			//            );
			//        }
			//    );
			//}


		}