Example #1
0
        public void PostEffectWithCamera()
        {
            var tc = new TestCore();

            tc.Init();

            const ulong cameraGroup1 = 0b01;
            const ulong cameraGroup2 = 0b10;

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            Engine.AddNode(new SpriteNode()
            {
                Scale       = new Vector2F(1.5f, 1.5f),
                Texture     = texture,
                ZOrder      = 1,
                CameraGroup = cameraGroup1 | cameraGroup2,
            });

            Engine.AddNode(new PostEffectGaussianBlurNode()
            {
                ZOrder      = 2,
                CameraGroup = cameraGroup2,
            });

            var target = RenderTexture.Create((new Vector2F(0.5f, 1.0f) * Engine.Window.Size.To2F()).To2I(), TextureFormat.R8G8B8A8_UNORM);

            Engine.AddNode(new CameraNode()
            {
                Group = cameraGroup2, TargetTexture = target, IsColorCleared = true, ClearColor = new Color(80, 80, 80)
            });

            // 表示用
            Engine.AddNode(new CameraNode()
            {
                Group = cameraGroup1
            });
            Engine.AddNode(new SpriteNode()
            {
                Texture = target, CameraGroup = cameraGroup1
            });

            tc.LoopBody(c =>
            {
            }, null);

            tc.End();
        }
Example #2
0
        public void Color()
        {
            var tc = new TestCore(new Configuration {
                EnabledCoreModules = CoreModules.Default | CoreModules.Tool
            });

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new SpriteNode();

            node.Src            = new RectF(new Vector2F(100, 100), new Vector2F(200, 200));
            node.Texture        = texture;
            node.CenterPosition = texture.Size / 2;
            Engine.AddNode(node);

            var font = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 64);
            var text = new TextNode()
            {
                Font = font, FontSize = 80, Text = "色テスト", Position = new Vector2F(0.0f, 0.0f)
            };

            Engine.AddNode(text);

            Color col1 = new Color(10, 20, 50, 100);
            Color col2 = new Color(10, 20, 50, 100);

            tc.LoopBody(c =>
            {
                bool open = true;
                if (Engine.Tool.Begin("Test", ref open, ToolWindowFlags.None))
                {
                    Engine.Tool.ColorEdit3("Color1", ref col1, ToolColorEditFlags.None);  // RGB
                    Engine.Tool.ColorEdit4("Color2", ref col2, ToolColorEditFlags.None);  // RGBAのアルファ付き

                    var flag = ToolColorEditFlags.Float | ToolColorEditFlags.NoInputs | ToolColorEditFlags.NoLabel;

                    Engine.Tool.ColorEdit3("Color ID", ref col1, flag);
                }
                Engine.Tool.End();

                text.Color = col1;
            }
                        , null);

            tc.End();
        }
Example #3
0
        public void SpriteNode()
        {
            var tc = new TestCore();

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new SpriteNode();

            //node.Src = new RectF(new Vector2F(100, 100), new Vector2F(200, 200));
            node.Texture        = texture;
            node.Position       = new Vector2F(200, 200);
            node.CenterPosition = texture.Size / 2;
            node.Scale          = new Vector2F(0.2f, 0.2f);
            Engine.AddNode(node);

            var col = new CircleCollider();

            col.Radius   = 200 * 0.2f;
            col.Position = node.Position;

            var node2 = new SpriteNode();

            //node.Src = new RectF(new Vector2F(100, 100), new Vector2F(200, 200));
            node2.Texture        = texture;
            node2.Position       = new Vector2F(200, 200);
            node2.CenterPosition = texture.Size / 2;
            node2.Scale          = new Vector2F(0.2f, 0.2f);
            Engine.AddNode(node2);
            var col2 = new CircleCollider();

            col2.Radius   = 200 * 0.2f;
            col2.Position = node.Position;

            tc.LoopBody(c =>
            {
                node2.Position = col2.Position = Engine.Mouse.Position;
                if (col.GetIsCollidedWith(col2))
                {
                    node2.Angle++;
                }
            }
                        , null);

            tc.End();
        }
Example #4
0
        public void TransformNodeInfo()
        {
            var tc = new TestCore(new Configuration()
            {
                VisibleTransformInfo = true
            });

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new SpriteNode();

            node.Texture  = texture;
            node.Position = new Vector2F(100, 200);
            node.Src      = new RectF(0, 0, 128, 128);
            Engine.AddNode(node);

            var node2 = new SpriteNode();

            node2.Texture        = texture;
            node2.CenterPosition = texture.Size / 2;
            node2.Position       = new Vector2F(200, 200);
            node2.Angle          = 68;
            node2.ZOrder         = 200;
            node2.Scale          = new Vector2F(0.8f, 0.5f);
            node2.Color          = new Color(0, 0, 255);
            node.AddChildNode(node2);

            var node3 = new SpriteNode();

            node3.Texture        = texture;
            node3.CenterPosition = texture.Size / 2;
            node3.Position       = new Vector2F(300, 300);
            node3.ZOrder         = 150;
            node3.Color          = new Color(0, 255, 0);
            node2.AddChildNode(node3);

            tc.Duration = 600;
            tc.LoopBody(c =>
            {
            }
                        , null);

            tc.End();
        }
Example #5
0
        public void StaticFont()
        {
            var tc = new TestCore();

            tc.Init();

            Assert.True(Font.GenerateFontFile("TestData/Font/mplus-1m-regular.ttf", "test.a2f", 100, "Hello, world! こんにちは"));
            var font1 = Font.LoadStaticFontStrict("test.a2f");

            Assert.NotNull(font1);

            const string path = "Serialization/StaticFont.bin";

            Serialize(path, font1);

            Assert.True(System.IO.File.Exists(path));

            var font2 = Deserialize <Font>(path);

            Assert.NotNull(font2);

            Assert.AreEqual(font1.Path, font2.Path);
            Assert.AreEqual(font1.Ascent, font2.Ascent);
            Assert.AreEqual(font1.Descent, font2.Descent);
            Assert.AreEqual(font1.LineGap, font2.LineGap);
            Assert.AreEqual(font1.Size, font2.Size);
            Assert.AreEqual(font1.IsStaticFont, font2.IsStaticFont);

            var obj1 = new TextNode()
            {
                Position = new Vector2F(100, 100),
                Font     = font1,
                Text     = "Hellow"
            };
            var obj2 = new TextNode()
            {
                Position = new Vector2F(100, 500),
                Font     = font2,
                Text     = "Hellow"
            };

            Engine.AddNode(obj1);
            Engine.AddNode(obj2);

            tc.LoopBody(null, null);

            tc.End();
        }
        public void Instantiate()
        {
            var tc = new TestCore();

            tc.Init();

            for (var i = 0; i < 10; i++)
            {
                var node = PartsTreeInstantiator.Instantiate("TestData/PartsTreeSystem/Parts.nodes");
                Engine.AddNode(node);
            }

            tc.LoopBody(null, null);

            tc.End();
        }
Example #7
0
        public void TextNode()
        {
            var tc = new TestCore();

            tc.Init();

            var font  = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 64);
            var font2 = Font.LoadDynamicFont("TestData/Font/GenYoMinJP-Bold.ttf", 64);

            Assert.NotNull(font);
            Assert.NotNull(font2);
            var imageFont = Font.CreateImageFont(font);

            imageFont.AddImageGlyph('〇', Texture2D.Load(@"TestData/IO/AltseedPink.png"));

            Engine.AddNode(new TextNode()
            {
                Font = font, FontSize = 80, Text = "Hello, world! こんにちは"
            });
            Engine.AddNode(new TextNode()
            {
                Font = font, FontSize = 80, Text = "色を指定します。", Position = new Vector2F(0.0f, 100.0f), Color = new Color(0, 0, 255)
            });
            Engine.AddNode(new TextNode()
            {
                Font = font2, FontSize = 80, Text = "𠀋 𡈽 𡌛 𡑮 𡢽 𠮟 𡚴 𡸴 𣇄 𣗄 𣜿 𣝣 𣳾", Position = new Vector2F(0.0f, 300.0f)
            });
            Engine.AddNode(new TextNode()
            {
                Font = imageFont, FontSize = 80, Text = "Altseed〇Altseed", Position = new Vector2F(0.0f, 500.0f)
            });
            var rotated = new TextNode()
            {
                Font = font, FontSize = 80, Text = "回転します。", Position = new Vector2F(400.0f, 400.0f)
            };

            Engine.AddNode(rotated);

            tc.LoopBody(c =>
            {
                rotated.Angle += 1.0f;
            }
                        , null);

            tc.End();
        }
Example #8
0
        public void Joystick()
        {
            var tc = new TestCore();

            tc.Init();

            var font = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 64);

            Assert.NotNull(font);

            var node = new TextNode();

            node.Font     = font;
            node.FontSize = 80;

            Engine.AddNode(node);
            tc.LoopBody(c =>
            {
                var text = "";
                for (int i = 0; i < Engine.Joystick.MaxCount; i++)
                {
                    var info = Engine.Joystick.GetJoystickInfo(i);
                    if (info == null)
                    {
                        continue;
                    }

                    if (info.IsGamepad)
                    {
                        var name  = info.GamepadName;
                        var state = Engine.Joystick.GetButtonState(i, JoystickButton.DPadUp);
                        text     += $"{name}: LeftUp = {state}\n";
                    }
                    else
                    {
                        var name  = info.Name;
                        var state = Engine.Joystick.GetButtonState(i, 0);
                        text     += $"{name}: Button 0 = {state}\n";
                    }
                }
                node.Text = text;
            }
                        , null);
            tc.End();
        }
Example #9
0
        public void Docking()
        {
            var tc = new TestCore(new Configuration {
                EnabledCoreModules = CoreModules.Default | CoreModules.Tool, IsResizable = true
            });

            tc.Init();

            tc.Duration = 20000;
            tc.LoopBody(c =>
            {
                bool open = true;
                Engine.Tool.ShowDemoWindow(ref open);
            }
                        , null);

            tc.End();
        }
Example #10
0
        public void TextNode2()
        {
            var tc = new TestCore();

            tc.Init();

            var font  = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 40);
            var font2 = Font.LoadDynamicFont("TestData/Font/GenYoMinJP-Bold.ttf", 40);

            Assert.NotNull(font);
            Assert.NotNull(font2);
            var imageFont = Font.CreateImageFont(font);

            imageFont.AddImageGlyph('〇', Texture2D.Load(@"TestData/IO/AltseedPink.png"));

            TextNode node = new TextNode()
            {
                Font = font2, Text = "Hello, world! こんにちは カーニングあるよ!!", IsEnableKerning = false, Color = new Color(255, 0, 0, 200)
            };

            Engine.AddNode(node);
            Engine.AddNode(new TextNode()
            {
                Font = font2, Text = "Hello, world! こんにちは カーニングないです", Color = new Color(0, 255, 0, 200)
            });
            Engine.AddNode(new TextNode()
            {
                Font = font, Text = node.ContentSize.ToString(), Position = new Vector2F(0.0f, 50.0f)
            });
            Engine.AddNode(new TextNode()
            {
                Font = font, Text = "字間5です。\n行間標準です。", CharacterSpace = 10, Position = new Vector2F(0.0f, 150.0f)
            });
            Engine.AddNode(new TextNode()
            {
                Font = font, Text = "字間10です。\n行間70です。", CharacterSpace = 50, LineGap = 200, Position = new Vector2F(0.0f, 250.0f)
            });
            tc.LoopBody(c =>
            {
            }
                        , null);

            tc.End();
        }
Example #11
0
        public void IBPolygonNodeWithTexture()
        {
            var tc = new TestCore();

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new PolygonNode()
            {
                Position = new Vector2F(250, 250),
                Texture  = texture
            };

            Engine.AddNode(node);

            var basePositions = new[]
            {
                new Vector2F(-100f, -100f),
                new Vector2F(100f, 100f),
                new Vector2F(-150f, 250f),
                new Vector2F(250f, -150f),
            };
            var array = new Vector2F[basePositions.Length][];

            for (int i = 0; i < basePositions.Length; i++)
            {
                array[i] = new[]
                {
                    basePositions[i],
                    basePositions[i] + new Vector2F(50f, 0f),
                    basePositions[i] + new Vector2F(50f, 50f),
                    basePositions[i] + new Vector2F(0f, 50f),
                };
            }

            node.SetVertexGroupsFromPositions(array, new Color(255, 255, 255));

            tc.LoopBody(null, null);

            tc.End();
        }
Example #12
0
        public void _RenderTexture()
        {
            var tc = new TestCore();

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new SpriteNode();

            node.Texture        = texture;
            node.CenterPosition = texture.Size / 2;
            node.Scale          = new Vector2F(0.5f, 0.5f);
            node.CameraGroup    = 0b1;
            Engine.AddNode(node);

            var renderTexture = RenderTexture.Create(new Vector2I(200, 200), TextureFormat.R8G8B8A8_UNORM);
            var camera        = new CameraNode();

            camera.Group         = 0b1;
            camera.TargetTexture = renderTexture;
            Engine.AddNode(camera);

            var node2 = new SpriteNode();

            node2.CameraGroup = 0b10;
            node2.Texture     = renderTexture;
            node2.Position    = new Vector2F(300, 300);
            Engine.AddNode(node2);

            var camera2 = new CameraNode();

            camera2.Group = 0b10;
            Engine.AddNode(camera2);

            tc.LoopBody(c =>
            {
            }
                        , null);

            tc.End();
        }
Example #13
0
        public void ZOrder()
        {
            var tc = new TestCore();

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new SpriteNode();

            node.Texture        = texture;
            node.CenterPosition = texture.Size / 2;
            node.Position       = new Vector2F(100, 100);
            node.Color          = new Color(255, 0, 0);
            node.ZOrder         = 300;
            Engine.AddNode(node);

            var node2 = new SpriteNode();

            node2.Texture        = texture;
            node2.CenterPosition = texture.Size / 2;
            node2.Position       = new Vector2F(200, 200);
            node2.ZOrder         = 200;
            node2.Color          = new Color(0, 0, 255);
            Engine.AddNode(node2);

            var node3 = new SpriteNode();

            node3.Texture        = texture;
            node3.CenterPosition = texture.Size / 2;
            node3.Position       = new Vector2F(300, 300);
            node3.ZOrder         = 150;
            node3.Color          = new Color(0, 255, 0);
            Engine.AddNode(node3);

            tc.LoopBody(c =>
            {
                node3.ZOrder++;
            }, null);

            tc.End();
        }
Example #14
0
        public void ArcNode()
        {
            var tc = new TestCore();

            tc.Init();

            var arc1 = new ArcNode()
            {
                Color    = new Color(255, 0, 0),
                Position = new Vector2F(100, 100),
                Radius   = 50f,
                VertNum  = 30,
            };
            var arc2 = new ArcNode()
            {
                Color    = new Color(0, 255, 0),
                Position = new Vector2F(400, 200),
                Radius   = 30f,
                VertNum  = 8,
            };
            var arc3 = new ArcNode()
            {
                Color    = new Color(0, 0, 255),
                Position = new Vector2F(50, 400),
                Radius   = 40f,
                VertNum  = 5,
            };

            Engine.AddNode(arc1);
            Engine.AddNode(arc2);
            Engine.AddNode(arc3);

            tc.LoopBody(x =>
            {
                arc1.StartDegree++;
                arc2.StartDegree++;
                arc3.StartDegree++;
                arc1.EndDegree--;
                arc2.EndDegree--;
                arc3.EndDegree--;
            }, null);

            tc.End();
        }
Example #15
0
        public void Culling()
        {
            var tc = new TestCore();

            tc.Init();

            var font = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 30);

            Assert.NotNull(font);

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var text = new TextNode()
            {
                Font = font, Text = "", ZOrder = 10
            };

            Engine.AddNode(text);

            var parent = new Altseed2.Node();

            Engine.AddNode(parent);

            tc.LoopBody(c =>
            {
                text.Text = "Drawing Object : " + Engine.CullingSystem.DrawingRenderedCount + " FPS: " + Engine.CurrentFPS.ToString();

                var node      = new SpriteNode();
                node.Src      = new RectF(new Vector2F(100, 100), new Vector2F(200, 200));
                node.Texture  = texture;
                node.Position = new Vector2F(200, -500);
                parent.AddChildNode(node);

                foreach (var item in parent.Children.OfType <SpriteNode>())
                {
                    item.Position += new Vector2F(0, 10);
                }
            }, null);

            tc.End();
        }
Example #16
0
        public void ReSize()
        {
            var tc = new TestCore();

            tc.Init();

            tc.LoopBody(null, x =>
            {
                if (x < 100)
                {
                    Engine.Window.Size += new Vector2I(1, 1);
                }
                else
                {
                    Engine.Window.Size -= new Vector2I(1, 1);
                }
            });

            tc.End();
        }
Example #17
0
        public void BeginEnd()
        {
            var tc = new TestCore(new Configuration {
                EnabledCoreModules = CoreModules.Default | CoreModules.Tool
            });

            tc.Init();

            tc.LoopBody(c =>
            {
                bool open = true;
                if (Engine.Tool.Begin("Test", ref open, ToolWindowFlags.None))
                {
                    Engine.Tool.End();
                }
            }
                        , null);

            tc.End();
        }
Example #18
0
        public void TreeAdd()
        {
            var tc = new TestCore();

            tc.Init();

            var t1 = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(t1);

            var s = new SpriteNode();

            s.Src      = new RectF(new Vector2F(100, 100), new Vector2F(100, 100));
            s.Texture  = t1;
            s.Position = new Vector2F(100, 100);

            var s2 = new SpriteNode();

            s2.Src      = new RectF(new Vector2F(200, 200), new Vector2F(100, 100));
            s2.Texture  = t1;
            s2.Position = new Vector2F(200, 200);

            var s3 = new SpriteNode();

            s3.Src      = new RectF(new Vector2F(200, 200), new Vector2F(100, 100));
            s3.Texture  = t1;
            s3.Position = new Vector2F(200, 200);

            s.AddChildNode(s2);
            s2.AddChildNode(s3);

            tc.LoopBody(c =>
            {
                if (c == 100)
                {
                    Engine.AddNode(s);
                }
            }, null);

            tc.End();
        }
Example #19
0
        public void CenterPosition()
        {
            var tc = new TestCore();

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new SpriteNode();

            node.Texture        = texture;
            node.CenterPosition = texture.Size / 2;
            node.Position       = Engine.WindowSize / 2;
            Engine.AddNode(node);

            var child = new SpriteNode();

            child.Texture        = texture;
            child.CenterPosition = texture.Size / 2;
            //child.Position = texture.Size / 2;
            node.AddChildNode(child);

            var child2 = new SpriteNode();

            child2.Texture        = texture;
            child2.CenterPosition = texture.Size / 2;
            child2.Position       = texture.Size / 2;
            node.AddChildNode(child2);

            tc.LoopBody(c =>
            {
                node.Angle   += 1.0f;
                child.Angle  += 1.0f;
                child2.Angle += 1.0f;
            }
                        , null);

            tc.End();
        }
Example #20
0
        public void Play()
        {
            var tc = new TestCore();

            tc.Init();

            var bgm = Altseed2.Sound.Load(@"TestData/Sound/bgm1.ogg", false);
            var se  = Altseed2.Sound.Load(@"TestData/Sound/se1.wav", true);

            Assert.NotNull(bgm);
            Assert.NotNull(se);

            var bgm_id = Engine.Sound.Play(bgm);
            var se_id  = Engine.Sound.Play(se);

            tc.LoopBody(null, null);

            Engine.Sound.StopAll();

            tc.End();
        }
Example #21
0
        public void EnuemrateAncestors()
        {
            var tc = new TestCore();

            tc.Init();

            var t1 = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(t1);

            var s = new SpriteNode();

            s.Src      = new RectF(new Vector2F(100, 100), new Vector2F(100, 100));
            s.Texture  = t1;
            s.Position = new Vector2F(100, 100);

            var s2 = new SpriteNode();

            s2.Src      = new RectF(new Vector2F(200, 200), new Vector2F(100, 100));
            s2.Texture  = t1;
            s2.Position = new Vector2F(200, 0);

            s.AddChildNode(s2);

            Engine.AddNode(s);

            tc.LoopBody(c =>
            {
                if (c == 2)
                {
                    var e = s2.EnumerateAncestors().ToArray();
                    Assert.AreEqual(1, e.Length);
                    Assert.AreSame(e[0], s);
                }
                s.Angle++;
            }, null);

            tc.End();
        }
Example #22
0
        public void Loop()
        {
            var tc = new TestCore();

            tc.Init();

            var bgm = Altseed2.Sound.Load(@"TestData/Sound/bgm1.ogg", false);

            Assert.NotNull(bgm);

            bgm.IsLoopingMode     = true;
            bgm.LoopStartingPoint = 1f;
            bgm.LoopEndPoint      = 2.5f;

            var bgm_id = Engine.Sound.Play(bgm);

            tc.LoopBody(null, null);

            Engine.Sound.StopAll();

            tc.End();
        }
Example #23
0
        public void PauseAndResume()
        {
            var tc = new TestCore();

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new RotateSpriteNode();

            node.Texture        = texture;
            node.CenterPosition = texture.Size / 2;
            node.Position       = new Vector2F(200, 200);
            Engine.AddNode(node);

            var node2 = new RotateSpriteNode();

            node2.Texture        = texture;
            node2.CenterPosition = texture.Size / 2;
            node2.Position       = new Vector2F(600, 200);
            Engine.AddNode(node2);

            tc.LoopBody(c =>
            {
                if (c == 50)
                {
                    Engine.Pause(node);
                }
                if (c == 150)
                {
                    Engine.Resume();
                }
            }
                        , null);

            tc.End();
        }
Example #24
0
        public void RemovingNodeCauseCrash()
        {
            var tc = new TestCore(new Configuration()
            {
                WaitVSync = false
            });

            tc.Init();
            Engine.TargetFPS = 10000;
            SpriteNode node = null;

#if !CI
            tc.Duration = 100000;
#endif
            tc.LoopBody(c =>
            {
                if (node != null)
                {
                    Engine.RemoveNode(node);
                }

                node                = new SpriteNode();
                node.Texture        = Texture2D.Load(@"TestData/IO/AltseedPink.png");
                node.CenterPosition = node.Texture.Size / 2;
                node.Position       = new Vector2F(200, 200);
                Engine.AddNode(node);

                if (c % 100 == 0)
                {
                    GC.Collect();
                    GC.WaitForFullGCComplete();
                }
            }
                        , null);

            tc.End();
        }
Example #25
0
        public void RectangleNode()
        {
            var tc = new TestCore(new Configuration());

            tc.Init();

            var rectangle1 = new RectangleNode()
            {
                Color          = new Color(255, 0, 0),
                Position       = new Vector2F(100f, 100f),
                CenterPosition = new Vector2F(25f, 25f),
                RectangleSize  = new Vector2F(50f, 50f),
            };
            var rectangle2 = new RectangleNode()
            {
                Color         = new Color(0, 255, 0),
                Position      = new Vector2F(400f, 200f),
                RectangleSize = new Vector2F(200f, 100f),
            };
            var rectangle3 = new RectangleNode()
            {
                Color         = new Color(0, 0, 255),
                Position      = new Vector2F(200f, 300f),
                RectangleSize = new Vector2F(100f, 150f),
            };

            Engine.AddNode(rectangle1);
            Engine.AddNode(rectangle2);
            Engine.AddNode(rectangle3);

            tc.LoopBody((c) =>
            {
                rectangle1.RectangleSize += new Vector2F(1, 1);
            }, null);

            tc.End();
        }
Example #26
0
        public void LineNode()
        {
            var tc = new TestCore(new Configuration());

            tc.Init();

            var line1 = new LineNode()
            {
                Color     = new Color(255, 0, 0),
                Point1    = new Vector2F(100f, 100f),
                Point2    = new Vector2F(200f, 200f),
                Thickness = 10f,
            };
            var line2 = new LineNode()
            {
                Color     = new Color(0, 255, 0),
                Point1    = new Vector2F(50f, 450f),
                Point2    = new Vector2F(600f, 50f),
                Thickness = 5.0f,
            };
            var line3 = new LineNode()
            {
                Color     = new Color(0, 0, 255),
                Point1    = new Vector2F(100f, 150f),
                Point2    = new Vector2F(100f, 350f),
                Thickness = 15.0f,
            };

            Engine.AddNode(line1);
            Engine.AddNode(line2);
            Engine.AddNode(line3);

            tc.LoopBody(null, null);

            tc.End();
        }
Example #27
0
        public void CircleNode()
        {
            var tc = new TestCore(new Configuration());

            tc.Init();

            var circle1 = new CircleNode()
            {
                Color    = new Color(255, 0, 0),
                Position = new Vector2F(100, 100),
                Radius   = 50f,
                VertNum  = 30,
            };
            var circle2 = new CircleNode()
            {
                Color    = new Color(0, 255, 0),
                Position = new Vector2F(400, 200),
                Radius   = 30f,
                VertNum  = 8,
            };
            var circle3 = new CircleNode()
            {
                Color    = new Color(0, 0, 255),
                Position = new Vector2F(50, 400),
                Radius   = 40f,
                VertNum  = 5,
            };

            Engine.AddNode(circle1);
            Engine.AddNode(circle2);
            Engine.AddNode(circle3);

            tc.LoopBody(null, null);

            tc.End();
        }
Example #28
0
        public void TriangleNode()
        {
            var tc = new TestCore(new Configuration());

            tc.Init();

            var triangle = new TriangleNode()
            {
                Color    = new Color(255, 0, 0),
                Point1   = new Vector2F(100f, 100f),
                Point2   = new Vector2F(200f, 200f),
                Point3   = new Vector2F(100f, 200f),
                Position = new Vector2F(100, 100),
            };

            Engine.AddNode(triangle);

            tc.LoopBody((c) =>
            {
                triangle.Point2 += new Vector2F(1, 1);
            }, null);

            tc.End();
        }
Example #29
0
        public void AcnhorAndShapeNode()
        {
            var tc = new TestCore(new Configuration()
            {
                VisibleTransformInfo = true
            });

            tc.Init();

            var font = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 64);

            Assert.NotNull(font);

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var sprite = new SpriteNode();

            sprite.Texture = texture;
            sprite.ZOrder  = 5;

            Vector2F rectSize = texture.Size;
            var      parent   = new AnchorTransformerNode();

            parent.Position   = Engine.WindowSize / 2;
            parent.Size       = rectSize;
            parent.AnchorMode = AnchorMode.Fill;
            Engine.AddNode(sprite);
            sprite.AddChildNode(parent);

            var circle2 = new CircleNode()
            {
                Color    = new Color(0, 255, 0),
                Position = new Vector2F(400, 200),
                Radius   = 100f,
                VertNum  = 80,
                ZOrder   = 10,
            };

            var circle2Anchor = new AnchorTransformerNode();

            circle2Anchor.AnchorMin  = new Vector2F(0.0f, 0.0f);
            circle2Anchor.AnchorMax  = new Vector2F(0.5f, 1f);
            circle2Anchor.AnchorMode = AnchorMode.Fill;
            sprite.AddChildNode(circle2);
            circle2.AddChildNode(circle2Anchor);

            var circle3 = new CircleNode()
            {
                Color    = new Color(0, 0, 255),
                Position = new Vector2F(50, 400),
                Radius   = 100f,
                VertNum  = 50,
                ZOrder   = 15,
            };

            var circle3Anchor = new AnchorTransformerNode();

            circle3Anchor.AnchorMin  = new Vector2F(0.5f, 0.5f);
            circle3Anchor.AnchorMax  = new Vector2F(1f, 1f);
            circle3Anchor.AnchorMode = AnchorMode.Fill;
            circle2.AddChildNode(circle3);
            circle3.AddChildNode(circle3Anchor);

            var text2 = new TextNode()
            {
                Font     = font,
                FontSize = 20,
                Text     = "",
                ZOrder   = 10,
                Scale    = new Vector2F(0.8f, 0.8f),
                Color    = new Color(255, 128, 0)
            };

            Engine.AddNode(text2);

            tc.Duration = 10000;

            string infoText(AnchorTransformerNode n) =>
            $"Scale:{n.Scale}\n" +
            $"Position:{n.Position}\n" +
            $"Pivot:{n.Pivot}\n" +
            $"Size:{n.Size}\n" +
            $"Margin: LT:{n.LeftTop} RB:{n.RightBottom}\n" +
            $"Anchor: {n.AnchorMin} {n.AnchorMax}\n";

            tc.LoopBody(c =>
            {
                circle2Anchor.RightBottom = new Vector2F();
                circle3Anchor.RightBottom = new Vector2F();

                if (Engine.Keyboard.GetKeyState(Key.Right) == ButtonState.Hold)
                {
                    rectSize.X += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Left) == ButtonState.Hold)
                {
                    rectSize.X -= 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Down) == ButtonState.Hold)
                {
                    rectSize.Y += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Up) == ButtonState.Hold)
                {
                    rectSize.Y -= 1.5f;
                }

                if (Engine.Keyboard.GetKeyState(Key.D) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.A) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(-1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.S) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(0, 1.5f);
                }
                if (Engine.Keyboard.GetKeyState(Key.W) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(0, -1.5f);
                }

                if (Engine.Keyboard.GetKeyState(Key.Q) == ButtonState.Hold)
                {
                    circle2Anchor.Angle += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.E) == ButtonState.Hold)
                {
                    circle2Anchor.Angle -= 1.5f;
                }

                if (Engine.Keyboard.GetKeyState(Key.Z) == ButtonState.Hold)
                {
                    parent.Scale += new Vector2F(0.1f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.C) == ButtonState.Hold)
                {
                    parent.Scale -= new Vector2F(0.1f, 0);
                }

                parent.Size = rectSize;

                text2.Text = infoText(parent) + '\n' + infoText(circle2Anchor) + '\n' + infoText(circle3Anchor);
            }, null);

            tc.End();
        }
Example #30
0
        public void TreeDelete()
        {
            var tc = new TestCore();

            tc.Init();

            var t1 = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(t1);

            var s = new Altseed2.Node();
            //s.Texture = t1;
            //s.Position = new Vector2F(100, 100);

            var s2 = new SpriteNode();

            s2.Texture  = t1;
            s2.Position = new Vector2F(100, 100);

            var s3 = new SpriteNode();

            s3.Texture  = t1;
            s3.Position = new Vector2F(100, 100);

            var s4 = new SpriteNode();

            s4.Texture  = t1;
            s4.Position = new Vector2F(100, 100);

            s.AddChildNode(s2);
            s2.AddChildNode(s3);
            s3.AddChildNode(s4);

            Engine.AddNode(s);

            tc.LoopBody(c =>
            {
                if (c == 100)
                {
                    Engine.RemoveNode(s);
                }
                if (c == 101)
                {
                    Assert.IsFalse(s.IsRegistered);
                    Assert.IsFalse(s2.IsRegistered);
                    Assert.IsFalse(s3.IsRegistered);
                    Assert.IsFalse(s4.IsRegistered);

                    var dc     = typeof(Engine).GetField("_DrawnCollection", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as DrawnCollection;
                    var drawns = typeof(DrawnCollection).GetField("_Drawns", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(dc) as SortedDictionary <int, HashSet <IDrawn> >;
                    Assert.IsTrue(drawns.All(kv => kv.Value.Count == 0));
                }
                if (c == 110)
                {
                    Engine.AddNode(s);
                }
                if (c == 111)
                {
                    Assert.IsTrue(s.IsRegistered);
                    Assert.IsTrue(s2.IsRegistered);
                    Assert.IsTrue(s3.IsRegistered);
                    Assert.IsTrue(s4.IsRegistered);

                    var dc     = typeof(Engine).GetField("_DrawnCollection", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as DrawnCollection;
                    var drawns = typeof(DrawnCollection).GetField("_Drawns", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(dc) as SortedDictionary <int, HashSet <IDrawn> >;
                    Assert.AreEqual(3, drawns.Sum(kv => kv.Value.Count));
                }
                if (c == 120)
                {
                    s2.RemoveChildNode(s3);
                    s2.FlushQueue();

                    Assert.AreEqual(RegisteredStatus.Free, s3.Status);

                    Assert.IsTrue(s.IsRegistered);
                    Assert.IsTrue(s2.IsRegistered);
                    Assert.IsFalse(s3.IsRegistered);
                    Assert.IsFalse(s4.IsRegistered);

                    var dc     = typeof(Engine).GetField("_DrawnCollection", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as DrawnCollection;
                    var drawns = typeof(DrawnCollection).GetField("_Drawns", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(dc) as SortedDictionary <int, HashSet <IDrawn> >;
                    Assert.AreEqual(1, drawns.Sum(kv => kv.Value.Count));
                }
            }, null);

            tc.End();
        }