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 ); } }
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; } }
Texture MakeTexture(int index, string text) { DrawTextArgs args = new DrawTextArgs(text, font, true); LinkFlags prevFlags = index > 0 ? linkData[index - 1].flags : 0; Texture tex; if (game.ClassicMode || NextToken(text, 0, ref prevFlags) == -1) { tex = game.Drawer2D.MakeTextTexture(ref args, 0, 0); } else { tex = DrawAdvanced(ref args, index, text); } game.Drawer2D.ReducePadding(ref tex, Utils.Floor(args.Font.Size), 3); return(tex); }
Texture MakeNameTextureImpl(Size size, DrawTextArgs args) { size.Width += 3; size.Height += 3; using (IDrawer2D drawer = game.Drawer2D) using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) { drawer.SetBitmap(bmp); args.Text = "&\xFF" + Utils.StripColours(args.Text); IDrawer2D.Cols['\xFF'] = new FastColour(80, 80, 80); game.Drawer2D.DrawText(ref args, 3, 3); IDrawer2D.Cols['\xFF'] = default(FastColour); args.Text = DisplayName; game.Drawer2D.DrawText(ref args, 0, 0); return(game.Drawer2D.Make2DTexture(bmp, size, 0, 0)); } }
unsafe void MeasureContentSizes(SpecialInputTab e, Font font, Size *sizes) { string s = new String('\0', e.CharsPerItem); DrawTextArgs args = new DrawTextArgs(s, font, false); // avoid allocating temporary strings here 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]; } sizes[i / e.CharsPerItem] = game.Drawer2D.MeasureSize(ref args); } } }
public override void Init() { Textures = new Texture[ElementsCount]; PlaceholderHeight = new bool[ElementsCount]; lines = new string[ElementsCount]; linkData = new LinkData[ElementsCount]; DrawTextArgs args = new DrawTextArgs( "I", font, true ); int height = game.Drawer2D.MeasureChatSize( ref args ).Height; game.Drawer2D.ReducePadding( ref height, Utils.Floor( font.Size ), 3 ); defaultHeight = height; for( int i = 0; i < Textures.Length; i++ ) { Textures[i].Height = defaultHeight; PlaceholderHeight[i] = true; } UpdateDimensions(); }
public override void SetText( string text ) { api.DeleteTexture( ref texture ); if( String.IsNullOrEmpty( text ) ) { texture = new Texture(); Height = defaultHeight; } else { DrawTextArgs args = new DrawTextArgs( text, font, true ); texture = game.Drawer2D.MakeChatTextTexture( ref args, 0, 0 ); if( ReducePadding ) game.Drawer2D.ReducePadding( ref texture, Utils.Floor( font.Size ) ); X = texture.X1 = CalcOffset( game.Width, texture.Width, XOffset, HorizontalAnchor ); Y = texture.Y1 = CalcOffset( game.Height, texture.Height, YOffset, VerticalAnchor ); Height = texture.Height; } Width = texture.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 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 override void Init() { X = 5; buffer.WordWrap(game.Drawer2D, ref parts, ref partLens, LineLength, TotalChars); for (int y = 0; y < sizes.Length; y++) { sizes[y] = Size.Empty; } sizes[0].Width = defaultWidth; maxWidth = defaultWidth; DrawTextArgs args = new DrawTextArgs(null, font, true); for (int y = 0; y < lines; y++) { int offset = y == 0 ? defaultWidth : 0; args.Text = parts[y]; sizes[y] += game.Drawer2D.MeasureChatSize(ref args); maxWidth = Math.Max(maxWidth, sizes[y].Width); } if (sizes[0].Height == 0) { sizes[0].Height = defaultHeight; } bool supports = game.Network.ServerSupportsPartialMessages; if (buffer.Length > LineLength && !shownWarning && !supports) { game.Chat.Add("&eNote: Each line will be sent as a separate packet.", MessageType.ClientStatus6); shownWarning = true; } else if (buffer.Length <= LineLength && shownWarning) { game.Chat.Add(null, MessageType.ClientStatus6); shownWarning = false; } DrawString(); UpdateAltTextY(); CalculateCaretData(); }
protected void MakeNameTexture() { using (Font font = new Font(game.FontName, 24)) { DrawTextArgs args = new DrawTextArgs(DisplayName, font, false); bool bitmapped = game.Drawer2D.UseBitmappedChat; // we want names to always be drawn without game.Drawer2D.UseBitmappedChat = true; Size size = game.Drawer2D.MeasureSize(ref args); if (size.Width == 0) { nameTex = new Texture(-1, 0, 0, 0, 0, 1, 1); } else { nameTex = MakeNameTextureImpl(size, args); } game.Drawer2D.UseBitmappedChat = bitmapped; } }
void AddPlayerInfo(TabListEntry player, byte id, int index) { DrawTextArgs args = new DrawTextArgs(player.ListName, font, true); Texture tex = game.Drawer2D.MakeTextTexture(ref args, 0, 0); game.Drawer2D.ReducePadding(ref tex, Utils.Floor(font.Size), 3); if (index < 0) { info[namesCount] = new PlayerInfo(player, id); textures[namesCount] = tex; namesCount++; } else { info[index] = new PlayerInfo(player, id); textures[index] = tex; } }
void DrawText(IDrawer2D drawer, DrawTextArgs args) { if (Text.Length != 0 || HintText == null) { int y = Y + 2 + (Height - textHeight) / 2; drawer.DrawText(ref args, X + 5, y); } else { args.SkipPartsCheck = false; args.Text = HintText; args.Font = hintFont; Size hintSize = drawer.MeasureSize(ref args); int y = Y + (Height - hintSize.Height) / 2; args.SkipPartsCheck = true; drawer.DrawText(ref args, X + 5, y); } }
public override void Init() { Textures = new Texture[ElementsCount]; PlaceholderHeight = new bool[ElementsCount]; lines = new string[ElementsCount]; linkData = new LinkData[ElementsCount]; DrawTextArgs args = new DrawTextArgs("I", font, true); int height = game.Drawer2D.MeasureChatSize(ref args).Height; game.Drawer2D.ReducePadding(ref height, Utils.Floor(font.Size), 3); defaultHeight = height; for (int i = 0; i < Textures.Length; i++) { Textures[i].Height = (short)defaultHeight; PlaceholderHeight[i] = true; } UpdateDimensions(); }
public void SetText(string text) { game.Graphics.DeleteTexture(ref texture); if (IDrawer2D.EmptyText(text)) { texture = default(Texture); Width = 0; Height = defaultHeight; } else { DrawTextArgs args = new DrawTextArgs(text, font, true); texture = game.Drawer2D.MakeTextTexture(ref args, 0, 0); Width = Math.Max(texture.Width, MinWidth); Height = Math.Max((int)texture.Height, minHeight); Reposition(); texture.X1 = X + (Width / 2 - texture.Width / 2); texture.Y1 = Y + (Height / 2 - texture.Height / 2); } }
/// <summary> Calculates the sizes of each line in the text buffer. </summary> public void CalculateLineSizes() { for (int y = 0; y < lineSizes.Length; y++) { lineSizes[y] = Size.Empty; } lineSizes[0].Width = prefixWidth; DrawTextArgs args = new DrawTextArgs(null, font, true); for (int y = 0; y < UsedLines; y++) { args.Text = lines[y]; lineSizes[y] += game.Drawer2D.MeasureSize(ref args); } if (lineSizes[0].Height == 0) { lineSizes[0].Height = prefixHeight; } }
public void SetDrawData(IDrawer2D drawer, string text, Font font, Font hintFont, Anchor horAnchor, Anchor verAnchor, int width, int height, int x, int y) { ButtonWidth = width; ButtonHeight = height; Width = width; Height = height; CalculateOffset(x, y, horAnchor, verAnchor); Text = text; if (Password) { text = new String('*', text.Length); } this.font = font; this.hintFont = hintFont; DrawTextArgs args = new DrawTextArgs(text, font, true); Size size = drawer.MeasureSize(ref args); Width = Math.Max(ButtonWidth, size.Width + 15); textHeight = size.Height; }
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); } }
public void SetText(string text) { gfx.DeleteTexture(ref texture); Text = text; if (String.IsNullOrEmpty(text)) { texture = default(Texture); Width = 0; Height = defaultHeight; } else { DrawTextArgs args = new DrawTextArgs(text, font, true); texture = game.Drawer2D.MakeTextTexture(ref args, 0, 0); Width = Math.Max(texture.Width, MinWidth); Height = Math.Max(texture.Height, MinHeight); CalculatePosition(); texture.X1 = X + (Width / 2 - texture.Width / 2); texture.Y1 = Y + (Height / 2 - texture.Height / 2); } }
Texture MakeNameTextureImpl(Size size, DrawTextArgs args) { size.Width += 3; size.Height += 3; using (IDrawer2D drawer = game.Drawer2D) using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) { drawer.SetBitmap(bmp); PackedCol origWhiteCol = IDrawer2D.Cols['f']; IDrawer2D.Cols['f'] = new PackedCol(80, 80, 80); args.Text = Utils.StripColours(args.Text); game.Drawer2D.DrawText(ref args, 3, 3); IDrawer2D.Cols['f'] = origWhiteCol; args.Text = DisplayName; game.Drawer2D.DrawText(ref args, 0, 0); return(game.Drawer2D.Make2DTexture(bmp, size, 0, 0)); } }
public static void DrawClippedText(ref DrawTextArgs args, IDrawer2D drawer, int x, int y, int maxWidth) { Size size = drawer.MeasureSize(ref args); // No clipping necessary if (size.Width <= maxWidth) { drawer.DrawText(ref args, x, y); return; } DrawTextArgs copy = args; copy.SkipPartsCheck = true; char[] chars = new char[args.Text.Length + 2]; for (int i = 0; i < args.Text.Length; i++) { chars[i] = args.Text[i]; } chars[args.Text.Length] = '.'; chars[args.Text.Length + 1] = '.'; for (int len = args.Text.Length; len > 0; len--) { chars[len] = '.'; if (chars[len - 1] == ' ') { continue; } copy.Text = new string(chars, 0, len + 2); size = drawer.MeasureSize(ref copy); if (size.Width > maxWidth) { continue; } drawer.DrawText(ref copy, x, y); return; } }
protected unsafe void SetCaretToCursor(int mouseX, int mouseY) { mouseX -= inputTex.X1; mouseY -= inputTex.Y1; DrawTextArgs args = new DrawTextArgs(null, font, true); IDrawer2D drawer = game.Drawer2D; int offset = 0, elemHeight = caretTex.Height; string oneChar = new String('A', 1); for (int y = 0; y < lines.Length; y++) { string line = lines[y]; int xOffset = y == 0 ? prefixWidth : 0; if (line == null) { continue; } for (int x = 0; x < line.Length; x++) { args.Text = line.Substring(0, x); int trimmedWidth = drawer.MeasureSize(ref args).Width + xOffset; // avoid allocating an unnecessary string fixed(char *ptr = oneChar) ptr[0] = line[x]; args.Text = oneChar; int elemWidth = drawer.MeasureSize(ref args).Width; if (GuiElement.Contains(trimmedWidth, y * elemHeight, elemWidth, elemHeight, mouseX, mouseY)) { caret = offset + x; UpdateCaret(); return; } } offset += line.Length; } caret = -1; UpdateCaret(); }
public void SetText(string text) { gfx.DeleteTexture(ref texture); if (String.IsNullOrEmpty(text)) { texture = new Texture(); Width = 0; Height = defaultHeight; } else { DrawTextArgs args = new DrawTextArgs(text, font, true); texture = game.Drawer2D.MakeTextTexture(ref args, 0, 0); if (ReducePadding) { game.Drawer2D.ReducePadding(ref texture, Utils.Floor(font.Size)); } Width = texture.Width; Height = texture.Height; CalculatePosition(); texture.X1 = X; texture.Y1 = Y; } }
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; }
public override void SetText(string text) { api.DeleteTexture(ref texture); if (String.IsNullOrEmpty(text)) { texture = new Texture(); Width = 0; Height = defaultHeight; } else { DrawTextArgs args = new DrawTextArgs(text, font, true); texture = game.Drawer2D.MakeChatTextTexture(ref args, 0, 0); if (ReducePadding) { game.Drawer2D.ReducePadding(ref texture, Utils.Floor(font.Size)); } Width = texture.Width; Height = texture.Height; X = texture.X1 = CalcOffset(game.Width, Width, XOffset, HorizontalAnchor); Y = texture.Y1 = CalcOffset(game.Height, Height, YOffset, VerticalAnchor); } }
unsafe void DrawContent(IDrawer2D drawer, Font font, SpecialInputTab 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.DrawText(ref args, x, y); } } }
public void SetText(string text) { api.DeleteTexture(ref texture); Text = text; if (String.IsNullOrEmpty(text)) { texture = default(Texture); Width = 0; Height = defaultHeight; } else { DrawTextArgs args = new DrawTextArgs(text, font, true); texture = game.Drawer2D.MakeChatTextTexture(ref args, 0, 0); Width = Math.Max(texture.Width, DesiredMaxWidth); Height = Math.Max(texture.Height, DesiredMaxHeight); X = CalcOffset(game.Width, Width, XOffset, HorizontalAnchor); Y = CalcOffset(game.Height, Height, YOffset, VerticalAnchor); texture.X1 = X + (Width / 2 - texture.Width / 2); texture.Y1 = Y + (Height / 2 - texture.Height / 2); } }
public TextInputWidget( Game game, Font font ) : base(game) { HorizontalAnchor = Anchor.LeftOrTop; VerticalAnchor = Anchor.BottomOrRight; typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1. buffer = new WrappableStringBuffer( 64 * lines ); DrawTextArgs args = new DrawTextArgs( "_", font, true ); caretTex = game.Drawer2D.MakeChatTextTexture( ref args, 0, 0 ); caretTex.Width = (caretTex.Width * 3) / 4; defaultCaretWidth = caretTex.Width; args = new DrawTextArgs( "> ", font, true ); Size defSize = game.Drawer2D.MeasureChatSize( ref args ); defaultWidth = Width = defSize.Width; defaultHeight = Height = defSize.Height; this.font = font; altText = new AltTextInputWidget( game, font, this ); altText.Init(); }
public void SetText(string text) { game.Graphics.DeleteTexture(ref texture); if (IDrawer2D.EmptyText(text)) { texture = new Texture(); Width = 0; Height = defaultHeight; } else { DrawTextArgs args = new DrawTextArgs(text, font, true); texture = game.Drawer2D.MakeTextTexture(ref args, 0, 0); if (ReducePadding) { game.Drawer2D.ReducePadding(ref texture, Utils.Floor(font.Size), 4); } Width = texture.Width; Height = texture.Height; Reposition(); texture.X1 = X; texture.Y1 = Y; } }
public void Redraw(IDrawer2D drawer, string text, Font font, Font hintFont) { Text = text; if (Password) { text = new String('*', text.Length); } DrawTextArgs args = new DrawTextArgs(text, font, true); Size size = drawer.MeasureSize(ref args); Width = Math.Max(ButtonWidth, size.Width + 7); FastColour col = Active ? new FastColour(240, 240, 240) : new FastColour(180, 180, 180); drawer.Clear(col, X + 1, Y, Width - 2, 2); drawer.Clear(col, X + 1, Y + Height - 2, Width - 2, 2); drawer.Clear(col, X, Y + 1, 2, Height - 2); drawer.Clear(col, X + Width - 2, Y + 1, 2, Height - 2); drawer.Clear(FastColour.Black, X + 2, Y + 2, Width - 4, Height - 4); args.SkipPartsCheck = true; if (Text.Length != 0 || HintText == null) { int y = Y + 2 + (Height - size.Height) / 2; drawer.DrawText(ref args, X + 5, y); } else { args.SkipPartsCheck = false; args.Text = HintText; args.Font = hintFont; Size hintSize = drawer.MeasureSize(ref args); int y = Y + (Height - hintSize.Height) / 2; args.SkipPartsCheck = true; drawer.DrawText(ref args, X + 5, y); } }
protected void SetCaretToCursor(int mouseX, int mouseY) { mouseX -= inputTex.X1; mouseY -= inputTex.Y1; DrawTextArgs args = new DrawTextArgs(null, font, true); IDrawer2D drawer = game.Drawer2D; int offset = 0, charHeight = caretTex.Height; for (int y = 0; y < lines.Length; y++) { string line = lines[y]; if (line == null) { continue; } for (int x = 0; x < line.Length; x++) { args.Text = line.Substring(0, x); int charOffset = drawer.MeasureText(ref args).Width; if (y == 0) { charOffset += prefixWidth; } args.Text = new string(line[x], 1); int charWidth = drawer.MeasureText(ref args).Width; if (GuiElement.Contains(charOffset, y * charHeight, charWidth, charHeight, mouseX, mouseY)) { caret = offset + x; UpdateCaret(); return; } } offset += line.Length; } caret = -1; UpdateCaret(); }
public InputWidget(Game game, Font font) : base(game) { Text = new WrappableStringBuffer(Utils.StringLength * MaxLines); lines = new string[MaxLines]; lineSizes = new Size[MaxLines]; DrawTextArgs args = new DrawTextArgs("_", font, true); caretTex = game.Drawer2D.MakeTextTexture(ref args, 0, 0); caretTex.Width = (short)((caretTex.Width * 3) / 4); caretWidth = caretTex.Width; caretHeight = caretTex.Height; this.font = font; if (Prefix == null) { return; } args = new DrawTextArgs(Prefix, font, true); Size size = game.Drawer2D.MeasureSize(ref args); prefixWidth = Width = size.Width; prefixHeight = Height = size.Height; }
public TextInputWidget(Game game, Font font) : base(game) { HorizontalAnchor = Anchor.LeftOrTop; VerticalAnchor = Anchor.BottomOrRight; typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1. buffer = new WrappableStringBuffer(64 * lines); DrawTextArgs args = new DrawTextArgs("_", font, true); caretTex = game.Drawer2D.MakeChatTextTexture(ref args, 0, 0); caretTex.Width = (caretTex.Width * 3) / 4; defaultCaretWidth = caretTex.Width; args = new DrawTextArgs("> ", font, true); Size defSize = game.Drawer2D.MeasureChatSize(ref args); defaultWidth = Width = defSize.Width; defaultHeight = Height = defSize.Height; this.font = font; altText = new AltTextInputWidget(game, font, this); altText.Init(); }
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)); } }
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; } } }
public void SetText( int index, string text ) { api.DeleteTexture( ref Textures[index] ); DrawTextArgs args = new DrawTextArgs( text, font, true ); linkData[index] = default(LinkData); LinkFlags prevFlags = index > 0 ? linkData[index - 1].flags : 0; if( !String.IsNullOrEmpty( text ) ) { Texture tex = NextToken( text, 0, ref prevFlags ) == -1 ? DrawSimple( ref args ) : DrawAdvanced( ref args, index, text ); game.Drawer2D.ReducePadding( ref tex, Utils.Floor( args.Font.Size ), 3 ); tex.X1 = CalcOffset( game.Width, tex.Width, XOffset, HorizontalAnchor ); tex.Y1 = CalcY( index, tex.Height ); Textures[index] = tex; lines[index] = text; } else { int height = PlaceholderHeight[index] ? defaultHeight : 0; int y = CalcY( index, height ); Textures[index] = new Texture( -1, 0, y, 0, height, 0, 0 ); lines[index] = null; } UpdateDimensions(); }
void RecreateDescTex() { if (SelectedIndex == lastCreatedIndex || Elements == null) { return; } lastCreatedIndex = SelectedIndex; game.Graphics.DeleteTexture(ref descTex); if (SelectedIndex == -1) { return; } BlockID block = Elements[SelectedIndex]; UpdateBlockInfoString(block); string value = buffer.ToString(); DrawTextArgs args = new DrawTextArgs(value, font, true); descTex = game.Drawer2D.MakeTextTexture(ref args, 0, 0); UpdateDescTexPos(); }
Texture DrawSimple( ref DrawTextArgs args ) { return game.Drawer2D.MakeChatTextTexture( ref args, 0, 0 ); }
public override void Init() { DrawTextArgs args = new DrawTextArgs( "I", font, true ); int height = game.Drawer2D.MeasureChatSize( ref args ).Height; SetHeight( height ); }
unsafe void SetCaretToCursor( int mouseX, int mouseY ) { mouseX -= inputTex.X1; mouseY -= inputTex.Y1; DrawTextArgs args = new DrawTextArgs( null, font, true ); IDrawer2D drawer = game.Drawer2D; int offset = 0, elemHeight = defaultHeight; string oneChar = new String( 'A', 1 ); for( int y = 0; y < lines; y++ ) { string line = parts[y]; int xOffset = y == 0 ? defaultWidth : 0; if( line == null ) continue; for( int x = 0; x < line.Length; x++ ) { args.Text = line.Substring( 0, x ); int trimmedWidth = drawer.MeasureChatSize( ref args ).Width + xOffset; // avoid allocating an unnecessary string fixed( char* ptr = oneChar ) ptr[0] = line[x]; args.Text = oneChar; int elemWidth = drawer.MeasureChatSize( ref args ).Width; if( Contains( trimmedWidth, y * elemHeight, elemWidth, elemHeight, mouseX, mouseY ) ) { caretPos = offset + x; CalculateCaretData(); return; } } offset += line.Length; } caretPos = -1; CalculateCaretData(); }
void RecreateBlockInfoTexture() { if( selIndex == lastCreatedIndex ) return; lastCreatedIndex = selIndex; api.DeleteTexture( ref blockInfoTexture ); if( selIndex == -1 ) return; Block block = blocksTable[selIndex]; UpdateBlockInfoString( block ); string value = buffer.GetString(); DrawTextArgs args = new DrawTextArgs( value, font, true ); Size size = game.Drawer2D.MeasureChatSize( ref args ); int x = startX + (blockSize * blocksPerRow) / 2 - size.Width / 2; int y = startY - size.Height - 5; args.SkipPartsCheck = true; blockInfoTexture = game.Drawer2D.MakeChatTextTexture( ref args, x, y ); }
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 = baseWidth; texWidth = bmp.Width; } } }
public override void Init() { X = 5; buffer.WordWrap( game.Drawer2D, ref parts, ref partLens, LineLength, TotalChars ); for( int y = 0; y < sizes.Length; y++ ) sizes[y] = Size.Empty; sizes[0].Width = defaultWidth; maxWidth = defaultWidth; DrawTextArgs args = new DrawTextArgs( null, font, true ); for( int y = 0; y < lines; y++ ) { int offset = y == 0 ? defaultWidth : 0; args.Text = parts[y]; sizes[y] += game.Drawer2D.MeasureChatSize( ref args ); maxWidth = Math.Max( maxWidth, sizes[y].Width ); } if( sizes[0].Height == 0 ) sizes[0].Height = defaultHeight; bool supports = game.Network.ServerSupportsPartialMessages; if( buffer.Length > LineLength && !shownWarning && !supports ) { game.Chat.Add( "&eNote: Each line will be sent as a separate packet.", MessageType.ClientStatus6 ); shownWarning = true; } else if( buffer.Length <= LineLength && shownWarning ) { game.Chat.Add( null, MessageType.ClientStatus6 ); shownWarning = false; } DrawString(); altText.texture.Y1 = game.Height - (YOffset + Height + altText.texture.Height); altText.Y = altText.texture.Y1; CalculateCaretData(); }
unsafe void MeasureContentSizes( Element e, Font font, Size* sizes ) { string s = new String( '\0', e.CharsPerItem ); DrawTextArgs args = new DrawTextArgs( s, font, false ); // avoid allocating temporary strings here 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]; sizes[i / e.CharsPerItem] = game.Drawer2D.MeasureChatSize( ref args ); } } }
int MeasureTitles( Font font ) { int totalWidth = 0; DrawTextArgs args = new DrawTextArgs( null, font, false ); for( int i = 0; i < elements.Length; i++ ) { args.Text = elements[i].Title; elements[i].TitleSize = game.Drawer2D.MeasureChatSize( ref args ); elements[i].TitleSize.Width += titleSpacing; totalWidth += elements[i].TitleSize.Width; } return totalWidth; }
public override void Init() { DrawTextArgs args = new DrawTextArgs( "I", font, true ); defaultHeight = game.Drawer2D.MeasureChatSize( ref args ).Height; Height = defaultHeight; }
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; }
protected void InitRenderingData() { using( Font font = new Font( game.FontName, 24 ) ) { DrawTextArgs args = new DrawTextArgs( DisplayName, font, true ); nameTex = game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 ); } }
void CalculateCaretData() { if( caretPos >= buffer.Length ) caretPos = -1; buffer.MakeCoords( caretPos, partLens, out indexX, out indexY ); DrawTextArgs args = new DrawTextArgs( null, font, true ); if( indexX == LineLength ) { caretTex.X1 = 10 + sizes[indexY].Width; caretCol = FastColour.Yellow; caretTex.Width = defaultCaretWidth; } else { args.Text = parts[indexY].Substring( 0, indexX ); Size trimmedSize = game.Drawer2D.MeasureChatSize( ref args ); if( indexY == 0 ) trimmedSize.Width += defaultWidth; caretTex.X1 = 10 + trimmedSize.Width; caretCol = FastColour.Scale( FastColour.White, 0.8f ); string line = parts[indexY]; args.Text = indexX < line.Length ? new String( line[indexX], 1 ) : ""; caretTex.Width = indexX < line.Length ? game.Drawer2D.MeasureChatSize( ref args ).Width : defaultCaretWidth; } caretTex.Y1 = sizes[0].Height * indexY + Y; CalcCaretColour(); }
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( "> ", 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 override void Init() { DrawTextArgs caretArgs = new DrawTextArgs( "_", boldFont, false ); chatCaretTexture = game.Drawer2D.MakeChatTextTexture( ref caretArgs, 0, 0 ); SetText( chatInputText.GetString() ); }