public void MakeBackground() { if (Framebuffer == null || (Framebuffer.Width != Width || Framebuffer.Height != Height)) { if (Framebuffer != null) { Framebuffer.Dispose(); } Framebuffer = new Bitmap(Width, Height); } using (IDrawer2D drawer = Drawer) { drawer.SetBitmap(Framebuffer); ClearArea(0, 0, Width, Height); drawer.UseBitmappedChat = useBitmappedFont; DrawTextArgs args = new DrawTextArgs("&eClassical&fSharp", logoFont, false); Size size = drawer.MeasureChatSize(ref args); int xStart = Width / 2 - size.Width / 2; args.Text = "&0Classical&0Sharp"; drawer.DrawChatText(ref args, xStart + 5, 10 + 5); args.Text = "&eClassical&fSharp"; drawer.DrawChatText(ref args, xStart, 10); drawer.UseBitmappedChat = false; } Dirty = true; }
public void SetText(string value) { chatInputText.Clear(); chatInputText.Append(0, value); DrawTextArgs args = new DrawTextArgs(value, font, false); Size textSize = game.Drawer2D.MeasureChatSize(ref args); // Ensure we don't have 0 text height if (textSize.Height == 0) { args.Text = Validator.Range; textSize.Height = game.Drawer2D.MeasureChatSize(ref args).Height; args.Text = value; } else { args.SkipPartsCheck = true; } 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); drawer.DrawChatText(ref args, 3, yOffset); args.Text = Validator.Range; args.SkipPartsCheck = false; Size hintSize = drawer.MeasureChatSize(ref args); args.SkipPartsCheck = true; int hintX = size.Width - hintSize.Width; if (textSize.Width + 3 < hintX) { drawer.DrawChatText(ref args, hintX, yOffset); } chatInputTexture = drawer.Make2DTexture(bmp, size, 0, 0); } 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; }
void DrawTitle() { using (IDrawer2D drawer = Drawer) { drawer.SetBitmap(Framebuffer); drawer.UseBitmappedChat = (useBitmappedFont || ClassicBackground) && fontPng; DrawTextArgs args = new DrawTextArgs("&eClassical&fSharp", logoFont, false); Size size = drawer.MeasureChatSize(ref args); int xStart = Width / 2 - size.Width / 2; args.Text = "&0Classical&0Sharp"; drawer.DrawChatText(ref args, xStart + 4, 4); args.Text = "&eClassical&fSharp"; drawer.DrawChatText(ref args, xStart, 0); drawer.UseBitmappedChat = false; } }
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("> ", font, true); drawer.DrawChatText(ref args, 0, 0); for (int i = 0; i < parts.Length; i++) { if (parts[i] == null) { break; } args.Text = parts[i]; char lastCol = GetLastColour(0, i); if (!IDrawer2D.IsWhiteColour(lastCol)) { args.Text = "&" + lastCol + args.Text; } int offset = i == 0 ? defaultWidth : 0; drawer.DrawChatText(ref args, offset, 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; Width = size.Width; }
public void MakeBackground() { if (Framebuffer == null || (Framebuffer.Width != Width || Framebuffer.Height != Height)) { if (Framebuffer != null) { Framebuffer.Dispose(); } Framebuffer = new Bitmap(Width, Height); } if (ClassicMode) { using (FastBitmap dst = new FastBitmap(Framebuffer, true)) { ClearTile(0, 0, Width, 48, elemSize, 128, 64, dst); ClearTile(0, 48, Width, Height - 48, 0, 96, 96, dst); } } else { ClearArea(0, 0, Width, Height); } using (IDrawer2D drawer = Drawer) { drawer.SetBitmap(Framebuffer); drawer.UseBitmappedChat = useBitmappedFont; DrawTextArgs args = new DrawTextArgs("&eClassical&fSharp", logoFont, false); Size size = drawer.MeasureChatSize(ref args); int xStart = Width / 2 - size.Width / 2; args.Text = "&0Classical&0Sharp"; drawer.DrawChatText(ref args, xStart + 4, 8 + 4); args.Text = "&eClassical&fSharp"; drawer.DrawChatText(ref args, xStart, 8); drawer.UseBitmappedChat = false; } Dirty = true; }
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; 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 = fpsText.Height + 2; posTex = drawer.Make2DTexture(bmp, size, 0, y); game.Drawer2D.ReducePadding(ref posTex, Utils.Floor(font.Size)); posTex.U2 = (float)baseWidth / bmp.Width; posTex.Width = (short)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(0, 0, 0, 127);; 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); } } }
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)); } }