public void Pivot() { var tc = new TestCore(); tc.Init(); var font = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 100); var font2 = Font.LoadDynamicFont("TestData/Font/GenYoMinJP-Bold.ttf", 100); Assert.NotNull(font); var rotated = new AnchorTransformerNode() { Position = new Vector2F(300.0f, 300.0f), Pivot = new Vector2F(0.5f, 0.5f), }; var text = new TextNode(); text.Font = font; text.Text = "中心で回転します"; rotated.Size = text.ContentSize; Engine.AddNode(text); text.AddChildNode(rotated); tc.LoopBody(c => { text.Text = "中心で回転します" + c.ToString(); rotated.Size = text.ContentSize; rotated.Angle += 1.0f; } , null); tc.End(); }
private SCNNode TextContainerForType(TextType type) { if (type == TextType.Chapter) { return(TextNode.ParentNode); } if (SubGroups [(int)type] != null) { return(SubGroups [(int)type]); } var container = SCNNode.Create(); TextNode.AddChildNode(container); SubGroups [(int)type] = container; BaselinePerType [(int)type] = CurrentBaseline; return(container); }
public void Anchor() { var tc = new TestCore(new Configuration() { VisibleTransformInfo = true }); 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 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 sprite2 = new SpriteNode(); sprite2.Texture = texture; sprite2.Color = new Color(255, 0, 0, 200); sprite2.ZOrder = 10; var child = new AnchorTransformerNode(); child.Position = rectSize / 2; child.Pivot = new Vector2F(0.5f, 0.5f); child.AnchorMin = new Vector2F(0.0f, 0.0f); child.AnchorMax = new Vector2F(1f, 1f); child.HorizontalAlignment = HorizontalAlignment.Left; child.VerticalAlignment = VerticalAlignment.Center; child.Size = sprite2.ContentSize; child.AnchorMode = AnchorMode.KeepAspect; sprite.AddChildNode(sprite2); sprite2.AddChildNode(child); var text = new TextNode(); text.Font = font; text.Color = new Color(0, 0, 0); text.Text = "あいうえお"; text.ZOrder = 15; var childText = new AnchorTransformerNode(); childText.Pivot = new Vector2F(0.5f, 0.5f); childText.AnchorMin = new Vector2F(0.5f, 0.5f); childText.AnchorMax = new Vector2F(0.5f, 0.5f); childText.Size = text.ContentSize; //childText.HorizontalAlignment = HorizontalAlignment.Center; //childText.VerticalAlignment = VerticalAlignment.Center; childText.AnchorMode = AnchorMode.ContentSize; sprite2.AddChildNode(text); text.AddChildNode(childText); var text2 = new TextNode() { Font = font, 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 => { 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) { child.Angle += 1.5f; } if (Engine.Keyboard.GetKeyState(Key.E) == ButtonState.Hold) { child.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(child) + '\n' + infoText(childText); }, null); tc.End(); }