private void CreateContent(int sandcount, int cubecount, bool rotor)
        {
            var t = new TextBox
            {
                FontSize = 10,
                Text = "powered by jsc",
                BorderThickness = new Thickness(0),
                Foreground = 0xffffffff.ToSolidColorBrush(),
                Background = Brushes.Transparent,
                IsReadOnly = true,
                Width = Width
            }.MoveTo(8, 8).AttachTo(InfoContent);

            if (rotor)
                t.MoveTo(8, 32);

            var a = new AffineMesh();


            var _17 = new Avalon.Images._17().Source;
            var _17g = new Avalon.Images._17g().Source;
            var _18 = new Avalon.Images._18().Source;
            var _18g = new Avalon.Images._18g().Source;




            for (int cubex = -cubecount; cubex < cubecount; cubex++)
            {


                AddCube(a, _18, _18g, new AffinePoint(-1 + cubex * 4, -1, 0));
                AddCube(a, _18, _18g, new AffinePoint(-1 + cubex * 4, 1, 0));

                AddCube(a, _18, _18g, new AffinePoint(1 + cubex * 4, -1, 0));
                AddCube(a, _18, _18g, new AffinePoint(1 + cubex * 4, 1, 0));

                AddCube(a, _17, _17g, new AffinePoint(-1 + cubex * 4, -1, 1));
                AddCube(a, _17, _17g, new AffinePoint(-1 + cubex * 4, 1, 1));

                AddCube(a, _17, _17g, new AffinePoint(1 + cubex * 4, -1, 1));
                AddCube(a, _17, _17g, new AffinePoint(1 + cubex * 4, 1, 1));


            }


            var top = default(AffineMesh);

            if (rotor)
                top = AddCube(a, _18, _18g, new AffinePoint(0, 0, 2));

            var topdef = top;

            if (!rotor)
                for (int ix = -sandcount; ix <= sandcount; ix++)
                    for (int iy = -sandcount; iy <= sandcount; iy++)
                    {
                        AddCubeFace(a,
                            new Avalon.Images.sandv().Source,
                            new Avalon.Images.sandv().Source,
                            new AffinePoint(-100 + ix * 200, -100, -100 + iy * 200),
                            new AffinePoint(100 + ix * 200, -100, -100 + iy * 200),
                            new AffinePoint(-100 + ix * 200, -100, 100 + iy * 200),
                            new AffinePoint(100 + ix * 200, -100, 100 + iy * 200)
                        );
                    }





            //z			a = a.ToZoom(0.5);


            //a = a.ToZoom(0.8);
            //a = a.ToZoom(1.2);

            var _a = a;
            var Rotation = new AffineRotation
            {
                XY = (180 + 22).DegreesToRadians(),
                YZ = -22.DegreesToRadians(),
                XZ = 45.DegreesToRadians()
            };

            var MouseOffset0 = 0.0;
            var MouseOffset1 = 0.0;
            var MouseOffset2 = 0.0;

            var MouseMode = 0;

            this.MouseLeftButtonUp +=
                delegate
                {
                    MouseMode++;
                };

            this.MouseMove +=
                (sender, args) =>
                {

                    var pp = args.GetPosition(this);

                    if ((MouseMode % 4) == 1)
                    {
                        MouseOffset1 = pp.X;
                        Rotation = new AffineRotation
                        {
                            XZ = Rotation.XZ,
                            YZ = Rotation.YZ,

                            XY = 0.01 * (pp.X - MouseOffset0) * 2,

                        };
                    }

                    if ((MouseMode % 4) == 2)
                    {
                        MouseOffset2 = pp.X;
                        Rotation = new AffineRotation
                        {
                            XY = Rotation.XY,
                            YZ = Rotation.YZ,


                            XZ = 0.01 * (pp.X - MouseOffset1) * 2,

                        };
                    }

                    if ((MouseMode % 4) == 3)
                    {
                        MouseOffset0 = pp.X;
                        Rotation = new AffineRotation
                        {
                            XY = Rotation.XY,
                            XZ = Rotation.XZ,

                            YZ = 0.01 * (pp.X - MouseOffset2) * 2,

                        };
                    }

                };


            Action<int> nextframe = null;

            var sw2 = new Stopwatch();
            sw2.Start();

            nextframe =
                c =>
                {

                    sw2.Stop();

                    var sw = new Stopwatch();

                    sw.Start();

                    if (top != null)
                    {
                        a.Meshes.Remove(top);

                        top = topdef.ToTranslation(
                            new AffinePoint(0, -200 * 3, 0)
                        ).ToRotation(
                            new AffineRotation { XZ = 0.01 * c }
                        ).ToTranslation(
                            new AffinePoint(0, 200 * 3, 0)
                        );

                        a.Meshes.Add(top);
                    }



                    // rotate floor

                    if (rotor)
                    {
                        _a = a.ToZoom(0.5).ToRotation(Rotation);
                        Show(_a);
                    }
                    else
                        if (c == 1)
                        {
                            _a = a.ToZoom(0.5).ToRotation(Rotation);
                            Show(_a);
                        }

                    sw.Stop();

                    t.Text = new
                    {
                        rotor,
                        ShowCounter,
                        XY = Rotation.XY.RadiansToDegrees() % 360,
                        YZ = Rotation.YZ.RadiansToDegrees() % 360,
                        XZ = Rotation.XZ.RadiansToDegrees() % 360,
                        Renderer = sw.ElapsedMilliseconds + "ms",
                        Other = sw2.ElapsedMilliseconds + "ms"
                    }.ToString();

                    sw2 = new Stopwatch();
                    //sw2.Reset();
                    sw2.Start();
                    1.AtDelay(() => nextframe(c + 1));

                    //this.UpdateLayout();
                }
            ;

            1.AtDelay(() => nextframe(0));
        }
예제 #2
0
        private void CreateContent(int sandcount, int cubecount, bool rotor)
        {
            var t = new TextBox
            {
                FontSize        = 10,
                Text            = "powered by jsc",
                BorderThickness = new Thickness(0),
                Foreground      = 0xffffffff.ToSolidColorBrush(),
                Background      = Brushes.Transparent,
                IsReadOnly      = true,
                Width           = Width
            }.MoveTo(8, 8).AttachTo(InfoContent);

            if (rotor)
            {
                t.MoveTo(8, 32);
            }

            var a = new AffineMesh();


            var _17  = new Avalon.Images._17().Source;
            var _17g = new Avalon.Images._17g().Source;
            var _18  = new Avalon.Images._18().Source;
            var _18g = new Avalon.Images._18g().Source;



            for (int cubex = -cubecount; cubex < cubecount; cubex++)
            {
                AddCube(a, _18, _18g, new AffinePoint(-1 + cubex * 4, -1, 0));
                AddCube(a, _18, _18g, new AffinePoint(-1 + cubex * 4, 1, 0));

                AddCube(a, _18, _18g, new AffinePoint(1 + cubex * 4, -1, 0));
                AddCube(a, _18, _18g, new AffinePoint(1 + cubex * 4, 1, 0));

                AddCube(a, _17, _17g, new AffinePoint(-1 + cubex * 4, -1, 1));
                AddCube(a, _17, _17g, new AffinePoint(-1 + cubex * 4, 1, 1));

                AddCube(a, _17, _17g, new AffinePoint(1 + cubex * 4, -1, 1));
                AddCube(a, _17, _17g, new AffinePoint(1 + cubex * 4, 1, 1));
            }


            var top = default(AffineMesh);

            if (rotor)
            {
                top = AddCube(a, _18, _18g, new AffinePoint(0, 0, 2));
            }

            var topdef = top;

            if (!rotor)
            {
                for (int ix = -sandcount; ix <= sandcount; ix++)
                {
                    for (int iy = -sandcount; iy <= sandcount; iy++)
                    {
                        AddCubeFace(a,
                                    new Avalon.Images.sandv().Source,
                                    new Avalon.Images.sandv().Source,
                                    new AffinePoint(-100 + ix * 200, -100, -100 + iy * 200),
                                    new AffinePoint(100 + ix * 200, -100, -100 + iy * 200),
                                    new AffinePoint(-100 + ix * 200, -100, 100 + iy * 200),
                                    new AffinePoint(100 + ix * 200, -100, 100 + iy * 200)
                                    );
                    }
                }
            }



            //z			a = a.ToZoom(0.5);


            //a = a.ToZoom(0.8);
            //a = a.ToZoom(1.2);

            var _a       = a;
            var Rotation = new AffineRotation
            {
                XY = (180 + 22).DegreesToRadians(),
                YZ = -22.DegreesToRadians(),
                XZ = 45.DegreesToRadians()
            };

            var MouseOffset0 = 0.0;
            var MouseOffset1 = 0.0;
            var MouseOffset2 = 0.0;

            var MouseMode = 0;

            this.MouseLeftButtonUp +=
                delegate
            {
                MouseMode++;
            };

            this.MouseMove +=
                (sender, args) =>
            {
                var pp = args.GetPosition(this);

                if ((MouseMode % 4) == 1)
                {
                    MouseOffset1 = pp.X;
                    Rotation     = new AffineRotation
                    {
                        XZ = Rotation.XZ,
                        YZ = Rotation.YZ,

                        XY = 0.01 * (pp.X - MouseOffset0) * 2,
                    };
                }

                if ((MouseMode % 4) == 2)
                {
                    MouseOffset2 = pp.X;
                    Rotation     = new AffineRotation
                    {
                        XY = Rotation.XY,
                        YZ = Rotation.YZ,


                        XZ = 0.01 * (pp.X - MouseOffset1) * 2,
                    };
                }

                if ((MouseMode % 4) == 3)
                {
                    MouseOffset0 = pp.X;
                    Rotation     = new AffineRotation
                    {
                        XY = Rotation.XY,
                        XZ = Rotation.XZ,

                        YZ = 0.01 * (pp.X - MouseOffset2) * 2,
                    };
                }
            };


            Action <int> nextframe = null;

            var sw2 = new Stopwatch();

            sw2.Start();

            nextframe =
                c =>
            {
                sw2.Stop();

                var sw = new Stopwatch();

                sw.Start();

                if (top != null)
                {
                    a.Meshes.Remove(top);

                    top = topdef.ToTranslation(
                        new AffinePoint(0, -200 * 3, 0)
                        ).ToRotation(
                        new AffineRotation {
                        XZ = 0.01 * c
                    }
                        ).ToTranslation(
                        new AffinePoint(0, 200 * 3, 0)
                        );

                    a.Meshes.Add(top);
                }



                // rotate floor

                if (rotor)
                {
                    _a = a.ToZoom(0.5).ToRotation(Rotation);
                    Show(_a);
                }
                else
                if (c == 1)
                {
                    _a = a.ToZoom(0.5).ToRotation(Rotation);
                    Show(_a);
                }

                sw.Stop();

                t.Text = new
                {
                    rotor,
                    ShowCounter,
                    XY       = Rotation.XY.RadiansToDegrees() % 360,
                    YZ       = Rotation.YZ.RadiansToDegrees() % 360,
                    XZ       = Rotation.XZ.RadiansToDegrees() % 360,
                    Renderer = sw.ElapsedMilliseconds + "ms",
                    Other    = sw2.ElapsedMilliseconds + "ms"
                }.ToString();

                sw2 = new Stopwatch();
                //sw2.Reset();
                sw2.Start();
                1.AtDelay(() => nextframe(c + 1));

                //this.UpdateLayout();
            }
            ;

            1.AtDelay(() => nextframe(0));
        }
        public ApplicationCanvas()
		{
			Width = DefaultWidth;
			Height = DefaultHeight;

            //this.ClipToBounds = true;

			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 help = new Image
			//{
			//    Source = (KnownAssets.Path.Assets + "/help.png").ToSource()
			//}.AttachTo(this);

			//help.Opacity = 0;

			var img = new Avalon.Images.jsc().MoveTo(DefaultWidth - 128, DefaultHeight - 128).AttachTo(this);

			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);

            this.WriteStatus = o => t.Text = o.ToString();

			var t2 = new TextBox
			{
				FontSize = 10,
				AcceptsReturn = true,
				Text = @"
ie and opera are not supported
firefox reports after transform
chrome reports before transform
we cannot rely on mouse position currently
shall wait for improvements like touch API
",
				BorderThickness = new Thickness(0),
				Foreground = 0xffffffff.ToSolidColorBrush(),
				Background = Brushes.Transparent,
				IsReadOnly = true,
				Width = DefaultWidth,
				Height = 128,
			}.MoveTo(8, 32).AttachTo(this);

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

			t.MouseEnter +=
				delegate
				{
					//help.Opacity = 0.5;

					img.Opacity = 1;
					t.Foreground = 0xffffff00.ToSolidColorBrush();
				};

			t.MouseLeave +=
				delegate
				{
					//help.Opacity = 1;

					img.Opacity = 0.5;
					t.Foreground = 0xffffffff.ToSolidColorBrush();
				};


			var sand = new Avalon.Images.sand()
			{
				Width = 100,
				Height = 100,
			}.AttachTo(this);

			// structs are not that good for translations...
			// we might be able to skip them it seems
			sand.RenderTransform = new MatrixTransform(1.2, 0.5, 0.2, 1, 100, 100);

			sand.Cursor = Cursors.Hand;

			// jsc/mxmlc cannot handle property name "this" :)

			sand.Opacity = 0.7;

			sand.MouseMove +=
				(sender, args) =>
				{
					var p1 = args.GetPosition(sand);
					var p2 = args.GetPosition(this);

					t.Text = new
					{
						sand = new { p1.X, p1.Y },
						that = new { p2.X, p2.Y }
					}.ToString();

				};


			


			var tri = new Avalon.Images._17()
			{
				Width = 100,
				Height = 100,
			}.AttachTo(this);


            var trig = new Avalon.Images._17g()
			{
				Width = 100,
				Height = 100,
			}.AttachTo(this);

            var tri2 = new Avalon.Images._17()
			{
				Width = 100,
				Height = 100,
			}.AttachTo(this);


            var trig2 = new Avalon.Images._17g()
			{
				Width = 100,
				Height = 100,
			}.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, 250, 50);
			var m2 = m(Brushes.Red, 250 + 100, 50);
			var m3 = m(Brushes.Blue, 250, 50 + 100);
			var m4 = m(Brushes.Yellow, 250 + 100, 50 + 100);

			var m5 = m(Brushes.Green, 250 + 200, 50);
			var m6 = m(Brushes.Blue, 250 + 200, 50 + 100);

            Movables = new[] { m1, m2, m3, m4, m5, m6};


			Action Update =
				delegate
				{
					

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

						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 = 100,
						Height = 100,

						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 = 100,
						Height = 100,

						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 = 100,
						Height = 100,

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

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

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

					};
				};

			foreach (var k in this.Movables)
			{
				k.Container.MouseLeftButtonDown += delegate { shadowa.Opacity = 0.2; };
				k.Container.MouseLeftButtonUp += delegate { shadowa.Opacity = 0; };
				k.Changed += Update;
			}

			Update();

            
		}
예제 #4
0
        public ApplicationCanvas()
        {
            Width  = DefaultWidth;
            Height = DefaultHeight;

            //this.ClipToBounds = true;

            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 help = new Image
            //{
            //    Source = (KnownAssets.Path.Assets + "/help.png").ToSource()
            //}.AttachTo(this);

            //help.Opacity = 0;

            var img = new Avalon.Images.jsc().MoveTo(DefaultWidth - 128, DefaultHeight - 128).AttachTo(this);

            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);

            this.WriteStatus = o => t.Text = o.ToString();

            var t2 = new TextBox
            {
                FontSize        = 10,
                AcceptsReturn   = true,
                Text            = @"
ie and opera are not supported
firefox reports after transform
chrome reports before transform
we cannot rely on mouse position currently
shall wait for improvements like touch API
",
                BorderThickness = new Thickness(0),
                Foreground      = 0xffffffff.ToSolidColorBrush(),
                Background      = Brushes.Transparent,
                IsReadOnly      = true,
                Width           = DefaultWidth,
                Height          = 128,
            }.MoveTo(8, 32).AttachTo(this);

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

            t.MouseEnter +=
                delegate
            {
                //help.Opacity = 0.5;

                img.Opacity  = 1;
                t.Foreground = 0xffffff00.ToSolidColorBrush();
            };

            t.MouseLeave +=
                delegate
            {
                //help.Opacity = 1;

                img.Opacity  = 0.5;
                t.Foreground = 0xffffffff.ToSolidColorBrush();
            };


            var sand = new Avalon.Images.sand()
            {
                Width  = 100,
                Height = 100,
            }.AttachTo(this);

            // structs are not that good for translations...
            // we might be able to skip them it seems
            sand.RenderTransform = new MatrixTransform(1.2, 0.5, 0.2, 1, 100, 100);

            sand.Cursor = Cursors.Hand;

            // jsc/mxmlc cannot handle property name "this" :)

            sand.Opacity = 0.7;

            sand.MouseMove +=
                (sender, args) =>
            {
                var p1 = args.GetPosition(sand);
                var p2 = args.GetPosition(this);

                t.Text = new
                {
                    sand = new { p1.X, p1.Y },
                    that = new { p2.X, p2.Y }
                }.ToString();
            };



            var tri = new Avalon.Images._17()
            {
                Width  = 100,
                Height = 100,
            }.AttachTo(this);


            var trig = new Avalon.Images._17g()
            {
                Width  = 100,
                Height = 100,
            }.AttachTo(this);

            var tri2 = new Avalon.Images._17()
            {
                Width  = 100,
                Height = 100,
            }.AttachTo(this);


            var trig2 = new Avalon.Images._17g()
            {
                Width  = 100,
                Height = 100,
            }.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, 250, 50);
            var m2 = m(Brushes.Red, 250 + 100, 50);
            var m3 = m(Brushes.Blue, 250, 50 + 100);
            var m4 = m(Brushes.Yellow, 250 + 100, 50 + 100);

            var m5 = m(Brushes.Green, 250 + 200, 50);
            var m6 = m(Brushes.Blue, 250 + 200, 50 + 100);

            Movables = new[] { m1, m2, m3, m4, m5, m6 };


            Action Update =
                delegate
            {
                tri.RenderTransform = new AffineTransform
                {
                    Left   = 0,
                    Top    = 0,
                    Width  = 100,
                    Height = 100,

                    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  = 100,
                    Height = 100,

                    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  = 100,
                    Height = 100,

                    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  = 100,
                    Height = 100,

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

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

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

            foreach (var k in this.Movables)
            {
                k.Container.MouseLeftButtonDown += delegate { shadowa.Opacity = 0.2; };
                k.Container.MouseLeftButtonUp   += delegate { shadowa.Opacity = 0; };
                k.Changed += Update;
            }

            Update();
        }