private void DrawImageVertex(ImageInfo info) { // CCW from bottom left var tl = new Vector2(-info.Width / 2, info.Height / 2); var br = new Vector2(info.Width / 2, -info.Height / 2); var transform = info.Angle != 0 ? Matrix3x2.Rotation(info.Angle) : Matrix3x2.Identity; var offTL = tl * info.Scale; var offBR = br * info.Scale; var offTR = new Vector2(offBR.X, offTL.Y); var offBL = new Vector2(offTL.X, offBR.Y); BillboardVertices.Add(new BillboardVertex() { Position = info.Position.ToVector4(), Foreground = Color.White, Background = maskColor, TexTL = info.UV_TopLeft, TexBR = info.UV_BottomRight, OffTL = Matrix3x2.TransformPoint(transform, offTL), OffBL = Matrix3x2.TransformPoint(transform, offBL), OffBR = Matrix3x2.TransformPoint(transform, offBR), OffTR = Matrix3x2.TransformPoint(transform, offTR) }); }
private void DrawCharacter(string text, Vector3 origin, float w, float h, TextInfo info) { // CCW from bottom left var tl = new Vector2(-w / 2, h / 2); var br = new Vector2(w / 2, -h / 2); var uv_tl = new Vector2(0, 0); var uv_br = new Vector2(1, 1); var transform = info.Angle != 0 ? Matrix3x2.Rotation(info.Angle) : Matrix3x2.Identity; var offTL = tl * info.Scale; var offBR = br * info.Scale; var offTR = new Vector2(offBR.X, offTL.Y); var offBL = new Vector2(offTL.X, offBR.Y); BillboardVertices.Add(new BillboardVertex() { Position = info.Origin.ToVector4(), Foreground = FontColor, Background = BackgroundColor, TexTL = uv_tl, TexBR = uv_br, OffTL = Matrix3x2.TransformPoint(transform, offTL), OffBL = Matrix3x2.TransformPoint(transform, offBL), OffBR = Matrix3x2.TransformPoint(transform, offBR), OffTR = Matrix3x2.TransformPoint(transform, offTR) }); }
/// <summary> /// Called when [draw texture]. /// </summary> /// <param name="deviceResources">The device resources.</param> protected override void OnUpdateTextureAndBillboardVertices(IDeviceResources deviceResources) { var w = Width; var h = Height; // CCW from bottom left var tl = new Vector2(-w / 2, h / 2); var br = new Vector2(w / 2, -h / 2); var uv_tl = new Vector2(0, 0); var uv_br = new Vector2(1, 1); var transform = Angle != 0 ? Matrix3x2.Rotation(Angle) : Matrix3x2.Identity; var tr = new Vector2(br.X, tl.Y); var bl = new Vector2(tl.X, br.Y); BillboardVertices.Add(new BillboardVertex() { Position = Center.ToVector4(), Foreground = Color.White, Background = MaskColor, TexTL = uv_tl, TexBR = uv_br, OffTL = Matrix3x2.TransformPoint(transform, tl), OffBR = Matrix3x2.TransformPoint(transform, br), OffBL = Matrix3x2.TransformPoint(transform, bl), OffTR = Matrix3x2.TransformPoint(transform, tr) }); }
private void DrawCharacter(string text, Vector3 origin, float w, float h, TextInfo info) { // CCW from bottom left var tl = new Vector2(-w / 2, h / 2); var br = new Vector2(w / 2, -h / 2); var uv_tl = new Vector2(0, 0); var uv_br = new Vector2(1, 1); BillboardVertices.Add(new BillboardVertex() { Position = info.Origin.ToVector4(), Foreground = FontColor, Background = BackgroundColor, TexTL = uv_tl, TexBR = uv_br, OffTL = tl * info.Scale, OffBR = br * info.Scale }); }
/// <summary> /// Called when [draw texture]. /// </summary> /// <param name="deviceResources">The device resources.</param> protected override void OnDrawTexture(IDeviceResources deviceResources) { var w = Width; var h = Height; // CCW from bottom left var tl = new Vector2(-w / 2, h / 2); var br = new Vector2(w / 2, -h / 2); var uv_tl = new Vector2(0, 0); var uv_br = new Vector2(1, 1); BillboardVertices.Add(new BillboardVertex() { Position = Center.ToVector4(), Foreground = Color.White, Background = MaskColor, TexTL = uv_tl, TexBR = uv_br, OffTL = tl, OffBR = br }); }
private void DrawImageVertex(ImageInfo info) { GetQuadOffset(info.Width, info.Height, info.HorizontalAlignment, info.VerticalAlignment, out var tl, out var br); var transform = info.Angle != 0 ? Matrix3x2.Rotation(info.Angle) : Matrix3x2.Identity; var offTL = tl * info.Scale; var offBR = br * info.Scale; var offTR = new Vector2(offBR.X, offTL.Y); var offBL = new Vector2(offTL.X, offBR.Y); BillboardVertices.Add(new BillboardVertex() { Position = info.Position.ToVector4(), Foreground = Color.White, Background = maskColor, TexTL = info.UV_TopLeft, TexBR = info.UV_BottomRight, OffTL = Matrix3x2.TransformPoint(transform, offTL), OffBL = Matrix3x2.TransformPoint(transform, offBL), OffBR = Matrix3x2.TransformPoint(transform, offBR), OffTR = Matrix3x2.TransformPoint(transform, offTR) }); }
/// <summary> /// Called when [draw texture]. /// </summary> /// <param name="deviceResources">The device resources.</param> protected override void OnUpdateTextureAndBillboardVertices(IDeviceResources deviceResources) { GetQuadOffset(Width, Height, HorizontalAlignment, VerticalAlignment, out var tl, out var br); var uv_tl = new Vector2(0, 0); var uv_br = new Vector2(1, 1); var transform = Angle != 0 ? Matrix3x2.Rotation(Angle) : Matrix3x2.Identity; var tr = new Vector2(br.X, tl.Y); var bl = new Vector2(tl.X, br.Y); BillboardVertices.Add(new BillboardVertex() { Position = Center.ToVector4(), Foreground = Color.White, Background = MaskColor, TexTL = uv_tl, TexBR = uv_br, OffTL = Matrix3x2.TransformPoint(transform, tl), OffBR = Matrix3x2.TransformPoint(transform, br), OffBL = Matrix3x2.TransformPoint(transform, bl), OffTR = Matrix3x2.TransformPoint(transform, tr) }); }
protected override void OnDrawTexture(IDeviceResources deviceResources) { Texture = TextureStatic; Width = 0; Height = 0; // http://www.cyotek.com/blog/angelcode-bitmap-font-parsing-using-csharp var tempList = new List <BillboardVertex>(100); foreach (var textInfo in TextInfo) { tempList.Clear(); int x = 0; int y = 0; var w = BitmapFont.TextureSize.Width; var h = BitmapFont.TextureSize.Height; char previousCharacter; previousCharacter = ' '; var normalizedText = textInfo.Text; var rect = new RectangleF(textInfo.Origin.X, textInfo.Origin.Y, 0, 0); foreach (char character in normalizedText) { switch (character) { case '\n': x = 0; y -= BitmapFont.LineHeight; break; default: Character data = BitmapFont[character]; int kerning = BitmapFont.GetKerning(previousCharacter, character); tempList.Add(DrawCharacter(data, new Vector3(x + data.Offset.X, y - data.Offset.Y, 0), w, h, kerning, textInfo)); x += data.XAdvance + kerning; break; } previousCharacter = character; if (tempList.Count > 0) { rect.Width = Math.Max(rect.Width, x * textInfo.Scale * textureScale); rect.Height = Math.Max(rect.Height, Math.Abs(tempList.Last().OffBR.Y)); } } var halfW = rect.Width / 2; var halfH = rect.Height / 2; BillboardVertices.Add(new BillboardVertex() { Position = textInfo.Origin.ToVector4(), Background = textInfo.Background, TexTL = Vector2.Zero, TexBR = Vector2.Zero, OffTL = new Vector2(-halfW, halfH), OffBR = new Vector2(halfW, -halfH), }); textInfo.UpdateTextInfo(rect.Width, rect.Height); foreach (var vert in tempList) { var v = vert; v.OffTL += new Vector2(-halfW, halfH); v.OffBR += new Vector2(-halfW, halfH); BillboardVertices.Add(v); } Width += rect.Width; Height += rect.Height; } }
protected override void OnUpdateTextureAndBillboardVertices(IDeviceResources deviceResources) { Width = 0; Height = 0; // http://www.cyotek.com/blog/angelcode-bitmap-font-parsing-using-csharp var tempList = new List <BillboardVertex>(100); foreach (var textInfo in TextInfo) { int tempPrevCount = tempList.Count; int x = 0; int y = 0; var w = BitmapFont.TextureSize.Width; var h = BitmapFont.TextureSize.Height; char previousCharacter; previousCharacter = ' '; var normalizedText = textInfo.Text; var rect = new RectangleF(textInfo.Origin.X, textInfo.Origin.Y, 0, 0); foreach (char character in normalizedText) { switch (character) { case '\n': x = 0; y -= BitmapFont.LineHeight; break; default: Character data = BitmapFont[character]; int kerning = BitmapFont.GetKerning(previousCharacter, character); tempList.Add(DrawCharacter(data, new Vector3(x + data.Offset.X, y - data.Offset.Y, 0), w, h, kerning, textInfo)); x += data.XAdvance + kerning; break; } previousCharacter = character; if (tempList.Count > 0) { rect.Width = Math.Max(rect.Width, x * textInfo.Scale * textureScale); rect.Height = Math.Max(rect.Height, Math.Abs(tempList.Last().OffBR.Y)); } } var transform = textInfo.Angle != 0 ? Matrix3x2.Rotation(textInfo.Angle) : Matrix3x2.Identity; var halfW = rect.Width / 2; var halfH = rect.Height / 2; //Add backbround vertex first. This also used for hit test BillboardVertices.Add(new BillboardVertex() { Position = textInfo.Origin.ToVector4(), Background = textInfo.Background, TexTL = Vector2.Zero, TexBR = Vector2.Zero, OffTL = Matrix3x2.TransformPoint(transform, new Vector2(-halfW, halfH)), OffBR = Matrix3x2.TransformPoint(transform, new Vector2(halfW, -halfH)), OffTR = Matrix3x2.TransformPoint(transform, new Vector2(-halfW, -halfH)), OffBL = Matrix3x2.TransformPoint(transform, new Vector2(halfW, halfH)), }); textInfo.UpdateTextInfo(rect.Width, rect.Height); for (int k = tempPrevCount; k < tempList.Count; ++k) { var v = tempList[k]; v.OffTL = Matrix3x2.TransformPoint(transform, v.OffTL + new Vector2(-halfW, halfH)); v.OffBR = Matrix3x2.TransformPoint(transform, v.OffBR + new Vector2(-halfW, halfH)); v.OffTR = Matrix3x2.TransformPoint(transform, v.OffTR + new Vector2(-halfW, halfH)); v.OffBL = Matrix3x2.TransformPoint(transform, v.OffBL + new Vector2(-halfW, halfH)); tempList[k] = v; } Width += rect.Width; Height += rect.Height; } foreach (var v in tempList) { BillboardVertices.Add(v); } }