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; } } }
void DrawTitles( IDrawer2D drawer, Font font ) { int x = 0; DrawTextArgs args = new DrawTextArgs( null, font, false ); for( int i = 0; i < elements.Length; i++ ) { args.Text = elements[i].Title; FastColour col = i == selectedIndex ? new FastColour( 30, 30, 30, 200 ) : new FastColour( 60, 60, 60, 200 ); Size size = elements[i].TitleSize; drawer.Clear( col, x, 0, size.Width, size.Height ); drawer.DrawChatText( ref args, x + titleSpacing / 2, 0 ); x += size.Width; } }
void DrawTitles(IDrawer2D drawer, Font font) { int x = 0; DrawTextArgs args = new DrawTextArgs(null, font, false); for (int i = 0; i < elements.Length; i++) { args.Text = elements[i].Title; FastColour col = i == selectedIndex ? new FastColour(30, 30, 30, 200) : new FastColour(60, 60, 60, 200); Size size = elements[i].TitleSize; drawer.Clear(col, x, 0, size.Width, size.Height); drawer.DrawChatText(ref args, x + titleSpacing / 2, 0); x += size.Width; } }
unsafe void DrawContent( IDrawer2D drawer, Font font, Element e, int yOffset ) { string s = new String( '\0', e.CharsPerItem ); int wrap = e.ItemsPerRow; DrawTextArgs args = new DrawTextArgs( s, font, false ); fixed( char* ptr = s ) { for( int i = 0; i < e.Contents.Length; i += e.CharsPerItem ) { for( int j = 0; j < e.CharsPerItem; j++ ) ptr[j] = e.Contents[i + j]; int item = i / e.CharsPerItem; int x = (item % wrap) * elementSize.Width, y = (item / wrap) * elementSize.Height; y += yOffset; drawer.DrawChatText( ref args, 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); } }
unsafe void DrawContent(IDrawer2D drawer, Font font, Element e, int yOffset) { string s = new String('\0', e.CharsPerItem); int wrap = e.ItemsPerRow; DrawTextArgs args = new DrawTextArgs(s, font, false); fixed(char *ptr = s) { for (int i = 0; i < e.Contents.Length; i += e.CharsPerItem) { for (int j = 0; j < e.CharsPerItem; j++) { ptr[j] = e.Contents[i + j]; } int item = i / e.CharsPerItem; int x = (item % wrap) * elementSize.Width, y = (item / wrap) * elementSize.Height; y += yOffset; drawer.DrawChatText(ref args, x, y); } } }
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)); } }