void MakePosTextWidget() { DrawTextArgs args = new DrawTextArgs("", posFont, true); for (int i = 0; i < possibleChars.Length; i++) { args.Text = new String(possibleChars[i], 1); widths[i] = game.Drawer2D.MeasureChatSize(ref args).Width; } using (IDrawer2D drawer = game.Drawer2D) { args.Text = "Feet pos: "; Size size = game.Drawer2D.MeasureChatSize(ref args); baseWidth = size.Width; size.Width += 16 * possibleChars.Length; posHeight = size.Height; using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) { drawer.SetBitmap(bmp); drawer.DrawChatText(ref args, 0, 0); for (int i = 0; i < possibleChars.Length; i++) { args.Text = new String(possibleChars[i], 1); drawer.DrawChatText(ref args, baseWidth + 16 * i, 0); } int y = fpsTextWidget.Height + 2; posTexture = drawer.Make2DTexture(bmp, size, 0, y); posTexture.U2 = (float)baseWidth / bmp.Width; posTexture.Width = baseWidth; texWidth = bmp.Width; } } }
public void Pack(string chars, Font font, string prefix) { DrawTextArgs args = new DrawTextArgs("", font, true); widths = new int[chars.Length]; using (IDrawer2D drawer = game.Drawer2D) { args.Text = prefix; Size size = game.Drawer2D.MeasureText(ref args); offset = size.Width; size.Width += fontSize * chars.Length; using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) { drawer.SetBitmap(bmp); drawer.DrawText(ref args, 0, 0); for (int i = 0; i < chars.Length; i++) { args.Text = new String(chars[i], 1); widths[i] = game.Drawer2D.MeasureText(ref args).Width; drawer.DrawText(ref args, offset + fontSize * i, 0); } tex = drawer.Make2DTexture(bmp, size, 0, 0); drawer.ReducePadding(ref tex, Utils.Floor(font.Size), 4); uScale = 1.0f / bmp.Width; tex.U2 = offset * uScale; tex.Width = (ushort)offset; } } }
public void SetText(string value) { chatInputText.Clear(); chatInputText.Append(0, value); DrawTextArgs args = new DrawTextArgs(value, font, false); Size textSize = game.Drawer2D.MeasureSize(ref args); Size size = new Size(Math.Max(textSize.Width, DesiredMaxWidth), Math.Max(textSize.Height, DesiredMaxHeight)); yOffset = 0; if (textSize.Height < DesiredMaxHeight) { yOffset = DesiredMaxHeight / 2 - textSize.Height / 2; } using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) using (IDrawer2D drawer = game.Drawer2D) { drawer.SetBitmap(bmp); drawer.DrawRect(backColour, 0, 0, size.Width, size.Height); args.SkipPartsCheck = true; drawer.DrawText(ref args, 0, 0); args.Text = Validator.Range; args.SkipPartsCheck = false; Size hintSize = drawer.MeasureSize(ref args); args.SkipPartsCheck = true; int hintX = size.Width - hintSize.Width; if (textSize.Width < hintX) { drawer.DrawText(ref args, hintX, 0); } chatInputTexture = drawer.Make2DTexture(bmp, size, 0, yOffset); } X = CalcOffset(game.Width, size.Width, XOffset, HorizontalAnchor); Y = CalcOffset(game.Height, size.Height, YOffset, VerticalAnchor); chatCaretTexture.X1 = chatInputTexture.X1 = X; chatCaretTexture.X1 += textSize.Width; chatCaretTexture.Y1 = chatInputTexture.Y1 = Y; chatCaretTexture.Y1 = (Y + size.Height) - chatCaretTexture.Height; Width = size.Width; Height = size.Height; }
public override void Init() { graphicsApi.Fog = false; SetTitle(serverName); SetMessage(serverMotd); progX = game.Width / 2f - progWidth / 2f; Size size = new Size(progWidth, progHeight); using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) { using (IDrawer2D drawer = game.Drawer2D) { drawer.SetBitmap(bmp); drawer.DrawRectBounds(FastColour.White, 3f, 0, 0, progWidth, progHeight); progressBoxTexture = drawer.Make2DTexture(bmp, size, (int)progX, (int)progY); } } game.MapEvents.MapLoading += MapLoading; }
unsafe void Make(Element e, Font font) { Size *sizes = stackalloc Size[e.Contents.Length / e.CharsPerItem]; MeasureContentSizes(e, font, sizes); Size bodySize = CalculateContentSize(e, sizes, out elementSize); int titleWidth = MeasureTitles(font), titleHeight = elements[0].TitleSize.Height; Size size = new Size(Math.Max(bodySize.Width, titleWidth), bodySize.Height + titleHeight); using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) using (IDrawer2D drawer = game.Drawer2D) { drawer.SetBitmap(bmp); DrawTitles(drawer, font); drawer.Clear(new FastColour(30, 30, 30, 200), 0, titleHeight, size.Width, bodySize.Height); DrawContent(drawer, font, e, titleHeight); texture = drawer.Make2DTexture(bmp, size, X, Y); } }
void MakeTexture(string text) { DrawTextArgs args = new DrawTextArgs(text, font, true); Size size = game.Drawer2D.MeasureChatSize(ref args); int xOffset = Math.Max(size.Width, DesiredMaxWidth) - size.Width; size.Width = Math.Max(size.Width, DesiredMaxWidth); int yOffset = Math.Max(size.Height, DesiredMaxHeight) - size.Height; size.Height = Math.Max(size.Height, DesiredMaxHeight); using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) using (IDrawer2D drawer = game.Drawer2D) { drawer.SetBitmap(bmp); args.SkipPartsCheck = true; drawer.DrawChatText(ref args, xOffset / 2, yOffset / 2); texture = drawer.Make2DTexture(bmp, size, 0, 0); } }
void DrawString() { int totalHeight = 0; for (int i = 0; i < lines; i++) { totalHeight += sizes[i].Height; } Size size = new Size(maxWidth, totalHeight); int realHeight = 0; using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) using (IDrawer2D drawer = game.Drawer2D) { drawer.SetBitmap(bmp); DrawTextArgs args = new DrawTextArgs(null, font, true); for (int i = 0; i < parts.Length; i++) { if (parts[i] == null) { break; } args.Text = parts[i]; drawer.DrawChatText(ref args, 0, realHeight); realHeight += sizes[i].Height; } inputTex = drawer.Make2DTexture(bmp, size, 10, 0); } Height = realHeight == 0 ? defaultHeight : realHeight; Y = game.Height - Height - YOffset; inputTex.Y1 = Y; caretTex.Y1 += Y; Width = size.Width; }
unsafe Texture DrawAdvanced(ref DrawTextArgs args, int index, string text) { LinkData data = Split(index, text); Size total = Size.Empty; Size * partSizes = stackalloc Size[data.parts.Length]; linkData[index] = data; for (int i = 0; i < data.parts.Length; i++) { args.Text = data.parts[i]; args.Font = (i & 1) == 0 ? font : underlineFont; partSizes[i] = game.Drawer2D.MeasureChatSize(ref args); total.Height = Math.Max(partSizes[i].Height, total.Height); total.Width += partSizes[i].Width; } using (IDrawer2D drawer = game.Drawer2D) using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(total)) { drawer.SetBitmap(bmp); int x = 0; for (int i = 0; i < data.parts.Length; i++) { args.Text = data.parts[i]; args.Font = (i & 1) == 0 ? font : underlineFont; Size size = partSizes[i]; drawer.DrawChatText(ref args, x, 0); data.bounds[i].X = x; data.bounds[i].Width = size.Width; x += size.Width; } return(drawer.Make2DTexture(bmp, total, 0, 0)); } }
Texture DrawAdvanced(ref DrawTextArgs args, int index, string text) { string[] items = Split(index, text); Size total = Size.Empty; Size[] partSizes = new Size[items.Length]; for (int i = 0; i < items.Length; i++) { args.Text = items[i]; args.Font = (i & 1) == 0 ? font : underlineFont; partSizes[i] = game.Drawer2D.MeasureChatSize(ref args); total.Height = Math.Max(partSizes[i].Height, total.Height); total.Width += partSizes[i].Width; } using (IDrawer2D drawer = game.Drawer2D) using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(total)) { drawer.SetBitmap(bmp); int x = 0; for (int i = 0; i < items.Length; i++) { args.Text = items[i]; args.Font = (i & 1) == 0 ? font : underlineFont; Size size = partSizes[i]; drawer.DrawChatText(ref args, x, 0); urlBounds[index][i].X = x; urlBounds[index][i].Width = size.Width; x += size.Width; } return(drawer.Make2DTexture(bmp, total, 0, 0)); } }