protected void HandleTexturedRect() { switch (FillMode) { default: case UIFillModes.Tilled: ShapeBuffer.TexturedRect(this, Rect, CurrentMaterial.DiffuseTexture, ReverseU, ReverseV); break; case UIFillModes.Stretch: ShapeBuffer.TexturedRect(this, Rect, UVScale, ReverseU, ReverseV); break; case UIFillModes.StretchMiddle: StrechedBuffer.Stretched(this, Rect); break; case UIFillModes.Stretch4Quad: SlicedSprite.FourSlice(this, Rect, CurrentMaterial.DiffuseTexture.PixelSize); break; case UIFillModes.Fill9Sprite: SlicedSprite.NineSlice(this, Rect, CurrentMaterial.DiffuseTexture.PixelSize); break; } }
public override void Resize(int x, int y) { base.Resize(x, y); CheckMaterial(); if (CurrentMaterial.DiffuseTexture == null) { ShapeBuffer.FilledRect(this, Rect); } else { ShapeBuffer.TexturedRect(this, Rect); } }
protected void HandleTexturedRect() { switch (FillMode) { default: // and titled ShapeBuffer.TexturedRect(this, Rect, CurrentMaterial.DiffuseTexture, ReverseU, ReverseV); break; case UIFillModes.Stretch: ShapeBuffer.TexturedRect(this, Rect, UVScale, ReverseU, ReverseV); break; case UIFillModes.StretchMiddle: StrechedBuffer.Stretched(this, Rect); break; case UIFillModes.Stretch4Quad: SlicedSprite.FourSlice(this, Rect, CurrentMaterial.DiffuseTexture.PixelSize); break; case UIFillModes.Fill9Sprite: SlicedSprite.NineSlice(this, Rect, CurrentMaterial.DiffuseTexture.PixelSize); break; case UIFillModes.SmartStprite: if (CurrentMaterial == null || CurrentMaterial.DiffuseTexture == null) { ShapeBuffer.TexturedRect(this, Rect, UVScale, ReverseU, ReverseV); } else { if (CurrentMaterial.DiffuseTexture != null && CurrentMaterial.DiffuseTexture.HasMetaData("9Sprite")) { SlicedSprite.NineSlice(this, Rect, CurrentMaterial.DiffuseTexture.PixelSize); } else { SlicedSprite.FourSlice(this, Rect, CurrentMaterial.DiffuseTexture.PixelSize); } } break; } }
public override void Resize(int x, int y) { LastParentSize.X = x; LastParentSize.Y = y; RelativeSize heightCache = Rect.Height; RelativeSize widthCache = Rect.Width; float pixelWidth = widthCache.ToScreen(x, y); ActualFontSize = GetNominalFontHeight(Rect.Height.ToScreen(LastParentSize)); float textWidth = 0; string effectiveText = Text; switch (FittingMode) { case TextFittingModes.ByHeightExtend: break; case TextFittingModes.ByHeightTrim: effectiveText = String.Copy(Text); textWidth = FontManager.MeasureText(Font, ActualFontSize, effectiveText).X; while (textWidth > pixelWidth) { if (textWidth > pixelWidth * 2) { effectiveText = effectiveText.Substring(0, effectiveText.Length / 2); } else { effectiveText = effectiveText.Substring(0, effectiveText.Length - 1); } textWidth = FontManager.MeasureText(Font, ActualFontSize, effectiveText).X; } break; case TextFittingModes.ByHeightReverseTrim: effectiveText = String.Copy(Text); textWidth = FontManager.MeasureText(Font, ActualFontSize, effectiveText).X; while (textWidth > pixelWidth) { if (textWidth > pixelWidth * 2) { effectiveText = effectiveText.Substring(effectiveText.Length / 2); } else { effectiveText = effectiveText.Substring(1); } textWidth = FontManager.MeasureText(Font, ActualFontSize, effectiveText).X; } break; case TextFittingModes.ByWidth: textWidth = FontManager.MeasureText(Font, ActualFontSize, Text).X; while (textWidth > pixelWidth) { ActualFontSize -= 1; if (ActualFontSize <= 5) // that's the smallest we can go, it just wont' fit { break; } textWidth = FontManager.MeasureText(Font, ActualFontSize, effectiveText).X; } break; } DrawInfo = FontManager.DrawText(Font, ActualFontSize, effectiveText); if (DrawInfo == null) { return; } Rect.Width = new RelativeSize(DrawInfo.Size.X, true); Rect.Width.Mode = RelativeSize.SizeModes.Raw; Rect.Height = new RelativeSize(DrawInfo.Size.Y, true); Rect.Height.Mode = RelativeSize.SizeModes.Raw; Rect.Resize(x, y); var pixelSize = Rect.GetPixelSize(); if (CurrentMaterial == null || CurrentMaterial.DiffuseTexture != DrawInfo.CachedTexture) { CurrentMaterial = GUIManager.GetMaterial(DrawInfo.CachedTexture, DefaultMaterial.Color); } ShapeBuffer.TexturedRect(this, Rect); foreach (var child in Children) { child.Resize(pixelSize); } Rect.Height = heightCache; Rect.Width = widthCache; }
public static void StretchedH(PrimitivBuffer target, RelativeRect rect) { var origin = rect.GetPixelOrigin(); var size = rect.GetPixelSize(); if (size.X <= size.Y) { ShapeBuffer.TexturedRect(target, rect); return; } float halfHeight = size.Y * 0.5f; target.Clear(); target.DrawType = PrimitiveType.Quads; float minimumX = origin.X; float minimumY = origin.Y; float maxiumX = origin.X + halfHeight; float maxiumY = origin.Y + size.Y; float minU = 0; float maxU = 0.5f; float minV = 0; float maxV = 1; // left side target.Vertex(minimumX, minimumY); target.UVs.Add(new Vector2(minU, maxV)); target.Vertex(maxiumX, minimumY); target.UVs.Add(new Vector2(maxU, maxV)); target.Vertex(maxiumX, maxiumY); target.UVs.Add(new Vector2(maxU, minV)); target.Vertex(minimumX, maxiumY); target.UVs.Add(new Vector2(minU, minV)); // middle minimumX = origin.X + halfHeight; minimumY = origin.Y; maxiumX = origin.X + size.X - halfHeight; maxiumY = origin.Y + size.Y; minU = 0.5f; maxU = 0.5f; minV = 0; maxV = 1; target.Vertex(minimumX, minimumY); target.UVs.Add(new Vector2(minU, maxV)); target.Vertex(maxiumX, minimumY); target.UVs.Add(new Vector2(maxU, maxV)); target.Vertex(maxiumX, maxiumY); target.UVs.Add(new Vector2(maxU, minV)); target.Vertex(minimumX, maxiumY); target.UVs.Add(new Vector2(minU, minV)); // right minimumX = origin.X + size.X - halfHeight; minimumY = origin.Y; maxiumX = origin.X + size.X; maxiumY = origin.Y + size.Y; minU = 0.5f; maxU = 1f; minV = 0; maxV = 1; target.Vertex(minimumX, minimumY); target.UVs.Add(new Vector2(minU, maxV)); target.Vertex(maxiumX, minimumY); target.UVs.Add(new Vector2(maxU, maxV)); target.Vertex(maxiumX, maxiumY); target.UVs.Add(new Vector2(maxU, minV)); target.Vertex(minimumX, maxiumY); target.UVs.Add(new Vector2(minU, minV)); }