public override void DrawClippedText( ref DrawTextArgs args, int x, int y, float maxWidth, float maxHeight ) { if( !args.SkipPartsCheck ) GetTextParts( args.Text ); Brush shadowBrush = GetOrCreateBrush( FastColour.Black ); StringFormatFlags flags = format.FormatFlags; format.FormatFlags |= StringFormatFlags.NoWrap; format.Trimming = StringTrimming.EllipsisCharacter; float textX = x; for( int i = 0; i < parts.Count; i++ ) { TextPart part = parts[i]; Brush textBrush = GetOrCreateBrush( part.TextColour ); RectangleF rect = new RectangleF( textX + Offset, y + Offset, maxWidth, maxHeight ); if( args.UseShadow ) g.DrawString( part.Text, args.Font, shadowBrush, rect, format ); rect = new RectangleF( textX, y, maxWidth, maxHeight ); g.DrawString( part.Text, args.Font, textBrush, rect, format ); textX += g.MeasureString( part.Text, args.Font, Int32.MaxValue, format ).Width; } format.Trimming = StringTrimming.None; format.FormatFlags = flags; }
/// <summary> Draws a string using the specified arguments, using the specified font or /// the current bitmapped font depending on the 'useFont' argument, at the /// specified coordinates in the currently bound bitmap. </summary> public void DrawChatText( ref DrawTextArgs args, int windowX, int windowY ) { if( !UseBitmappedChat ) DrawText( ref args, windowX, windowY ); else DrawBitmappedText( ref args, windowX, windowY ); }
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 ); } }
public override void Init() { X = 10; DrawTextArgs caretArgs = new DrawTextArgs( "_", Color.White, false ); chatCaretTexture = game.Drawer2D.MakeTextTexture( boldFont, 0, 0, ref caretArgs ); string value = chatInputText.GetString(); if( chatInputText.Empty ) { caretPos = -1; } Size size = game.Drawer2D.MeasureSize( value, font, false ); if( caretPos == -1 ) { chatCaretTexture.X1 = 10 + size.Width; size.Width += chatCaretTexture.Width; DrawString( size, value, true ); } else { string subString = chatInputText.GetSubstring( caretPos ); Size trimmedSize = game.Drawer2D.MeasureSize( subString, font, false ); chatCaretTexture.X1 = 10 + trimmedSize.Width; Size charSize = game.Drawer2D.MeasureSize( new String( value[caretPos], 1 ), font, false ); chatCaretTexture.Width = charSize.Width; DrawString( size, value, false ); } }
public override void DrawBitmappedText( ref DrawTextArgs args, int x, int y ) { using( bitmapWrapper ) { bitmapWrapper.SetData( curBmp, true, false ); DrawBitmapTextImpl( bitmapWrapper, ref args, x, y ); } }
public override void DrawBitmappedText( ref DrawTextArgs args, int x, int y ) { if( !args.SkipPartsCheck ) GetTextParts( args.Text ); using( FastBitmap fastBmp = new FastBitmap( curBmp, true ) ) DrawTextImpl( fastBmp, ref args, x, y ); }
protected void InitRenderingData() { api = game.Graphics; using( Font font = new Font( "Arial", 14 ) ) { DrawTextArgs args = new DrawTextArgs( DisplayName, font, true ); nameTex = game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 ); } }
public void DrawAt( IDrawer2D drawer, string text, Font font, Anchor horAnchor, Anchor verAnchor, int x, int y) { DrawTextArgs args = new DrawTextArgs( text, font, true ); Size size = drawer.MeasureSize( ref args ); Width = size.Width; Height = size.Height; CalculateOffset( x, y, horAnchor, verAnchor ); Redraw( drawer, text, font ); }
public void Redraw( IDrawer2D drawer, string text, Font font ) { DrawTextArgs args = new DrawTextArgs( text, font, true ); Size size = drawer.MeasureSize( ref args ); Width = size.Width; Height = size.Height; args.SkipPartsCheck = true; drawer.DrawText( ref args, X, Y ); Text = text; }
public override void Init() { Textures = new Texture[ElementsCount]; DrawTextArgs args = new DrawTextArgs( "I", font, true ); defaultHeight = game.Drawer2D.MeasureSize( ref args ).Height; for( int i = 0; i < Textures.Length; i++ ) { Textures[i].Height = defaultHeight; } UpdateDimensions(); }
public void SetDrawData( IDrawer2D drawer, string text, Font font, Anchor horAnchor, Anchor verAnchor, int x, int y) { DrawTextArgs args = new DrawTextArgs( text, font, true ); Size size = drawer.MeasureSize( ref args ); Width = size.Width; Height = size.Height; CalculateOffset( x, y, horAnchor, verAnchor ); Text = text; this.font = font; }
public override void Init() { Textures = new Texture[ElementsCount]; lines = new string[ElementsCount]; urlBounds = new Rectangle[ElementsCount][]; DrawTextArgs args = new DrawTextArgs( "I", font, true ); defaultHeight = game.Drawer2D.MeasureChatSize( ref args ).Height; for( int i = 0; i < Textures.Length; i++ ) Textures[i].Height = defaultHeight; UpdateDimensions(); }
protected void DrawBitmapTextImpl( FastBitmap dst, ref DrawTextArgs args, int x, int y ) { bool underline = args.Font.Style == FontStyle.Underline; if( args.UseShadow ) { int offset = ShadowOffset( args.Font.Size ); DrawPart( dst, ref args, x + offset, y + offset, true ); if( underline ) DrawUnderline( dst, x + offset, 0, ref args, true ); } DrawPart( dst, ref args, x, y, false ); if( underline ) DrawUnderline( dst, x, -2, ref args, false ); }
public void Redraw( IDrawer2D drawer ) { drawer.DrawRect( FastColour.Black, X, Y, Width, Height ); if( Value ) { DrawTextArgs args = new DrawTextArgs( "X", font, false ); Size size = drawer.MeasureSize( ref args ); args.SkipPartsCheck = true; drawer.DrawText( ref args, X + (Width - size.Width) / 2, Y + (Height - size.Height) / 2 ); } drawer.DrawRectBounds( FastColour.White, 2, X, Y, Width, Height ); }
public override void Redraw( IDrawer2D drawer ) { if( Window.Minimised ) return; drawer.DrawRect( FastColour.Black, X, Y, Width, Height ); if( Value ) { DrawTextArgs args = new DrawTextArgs( "X", font, false ); Size size = drawer.MeasureSize( ref args ); args.SkipPartsCheck = true; drawer.DrawText( ref args, X + (Width + 2 - size.Width) / 2, // account for border Y + (Height - size.Height) / 2 ); } drawer.DrawRectBounds( FastColour.White, 2, X, Y, Width, Height ); }
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 ); } } }
public override void Redraw( IDrawer2D drawer ) { if( Window.Minimised ) return; string text = Text; if( !Active ) text = "&7" + text; int xOffset = Width - textSize.Width, yOffset = Height - textSize.Height; DrawTextArgs args = new DrawTextArgs( text, font, true ); DrawBorder( drawer ); if( Window.ClassicBackground ) DrawClassic( drawer ); else DrawNormal( drawer ); drawer.DrawText( ref args, X + xOffset / 2, Y + yOffset / 2 ); }
public Texture MakeTextTexture( Font font, int screenX, int screenY, ref DrawTextArgs args ) { Size size = MeasureSize( args.Text, font, args.UseShadow ); if( parts.Count == 0 ) return new Texture( -1, screenX, screenY, 0, 0, 1, 1 ); using( Bitmap bmp = CreatePow2Bitmap( size ) ) { SetBitmap( bmp ); args.SkipPartsCheck = true; DrawText( font, ref args, 0, 0 ); Dispose(); return Make2DTexture( bmp, size, screenX, screenY ); } }
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; } }
public void SetText( string text ) { graphicsApi.DeleteTexture( ref texture ); if( String.IsNullOrEmpty( text ) ) { texture = new Texture(); Height = defaultHeight; } else { DrawTextArgs args = new DrawTextArgs( text, true ); texture = game.Drawer2D.MakeTextTexture( font, 0, 0, ref args ); X = texture.X1 = CalcOffset( game.Width, texture.Width, XOffset, HorizontalDocking ); Y = texture.Y1 = CalcOffset( game.Height, texture.Height, YOffset, VerticalDocking ); Height = texture.Height; } Width = texture.Width; }
/// <summary> Draws the specified string from the arguments into a new bitmap, /// them creates a 2D texture with origin at the specified window coordinates. </summary> public Texture MakeTextTexture( ref DrawTextArgs args, int windowX, int windowY ) { Size size = MeasureSize( ref args ); if( parts.Count == 0 ) return new Texture( -1, windowX, windowY, 0, 0, 1, 1 ); using( Bitmap bmp = CreatePow2Bitmap( size ) ) { SetBitmap( bmp ); args.SkipPartsCheck = true; DrawText( ref args, 0, 0 ); Dispose(); return Make2DTexture( bmp, size, windowX, windowY ); } }
public override Size MeasureSize( ref DrawTextArgs args ) { GetTextParts( args.Text ); SizeF total = SizeF.Empty; for( int i = 0; i < parts.Count; i++ ) { SizeF size = measuringGraphics.MeasureString( parts[i].Text, args.Font, Int32.MaxValue, format ); total.Height = Math.Max( total.Height, size.Height ); total.Width += size.Width; } if( args.UseShadow && parts.Count > 0 ) { total.Width += Offset; total.Height += Offset; } return Size.Ceiling( total ); }
public override void DrawText( ref DrawTextArgs args, int x, int y ) { if( !args.SkipPartsCheck ) GetTextParts( args.Text ); Paint shadowBrush = GetOrCreateBrush( Color.Black ); float textX = x; for( int i = 0; i < parts.Count; i++ ) { TextPart part = parts[i]; Paint textBrush = GetOrCreateBrush( part.TextColour ); if( args.UseShadow ) c.DrawText( part.Text, textX + Offset, y + Offset, shadowBrush ); c.DrawText( part.Text, textX, y, textBrush ); textX += textBrush.MeasureText( part.Text ); } }
public override void DrawText( ref DrawTextArgs args, int x, int y ) { if( !args.SkipPartsCheck ) GetTextParts( args.Text ); Brush shadowBrush = GetOrCreateBrush( Color.Black ); float textX = x; for( int i = 0; i < parts.Count; i++ ) { TextPart part = parts[i]; Brush textBrush = GetOrCreateBrush( part.TextColour ); if( args.UseShadow ) g.DrawString( part.Text, args.Font, shadowBrush, textX + Offset, y + Offset, format ); g.DrawString( part.Text, args.Font, textBrush, textX, y, format ); textX += g.MeasureString( part.Text, args.Font, Int32.MaxValue, format ).Width; } }
public override Size MeasureSize( ref DrawTextArgs args ) { GetTextParts( args.Text ); if( parts.Count == 0 ) return Size.Empty; SizeF total = SizeF.Empty; for( int i = 0; i < parts.Count; i++ ) { TextPart part = parts[i]; Paint textBrush = GetOrCreateBrush( part.TextColour ); total.Width += textBrush.MeasureText( part.Text ); } total.Height = PtToPx( args.Font.Size ); if( args.UseShadow ) { total.Width += Offset; total.Height += Offset; } return Size.Ceiling( total ); }
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); } } }
public override void SetText( string text ) { graphicsApi.DeleteTexture( ref texture ); if( String.IsNullOrEmpty( text ) ) { texture = new Texture(); Height = defaultHeight; } else { DrawTextArgs args = new DrawTextArgs( text, font, true ); texture = game.Drawer2D.UseBitmappedChat ? game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 ) : game.Drawer2D.MakeTextTexture( ref args, 0, 0 ); 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; }
public virtual void SetText(string text) { graphicsApi.DeleteTexture(ref texture); if (String.IsNullOrEmpty(text)) { texture = new Texture(); Height = defaultHeight; } else { DrawTextArgs args = new DrawTextArgs(text, font, true); texture = game.Drawer2D.MakeTextTexture(ref args, 0, 0); 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; }
public void Redraw( IDrawer2D drawer, string text, Font font ) { if( !Active ) text = "&7" + Text; DrawTextArgs args = new DrawTextArgs( text, font, true ); Size size = drawer.MeasureSize( ref args ); int width = ButtonWidth, height = ButtonHeight; int xOffset = width - size.Width, yOffset = height - size.Height; if( Shadow ) drawer.DrawRoundedRect( Active ? shadowColActive : shadowCol, 3, X + IDrawer2D.Offset, Y + IDrawer2D.Offset, width, height ); drawer.DrawRoundedRect( Active ? boxColActive : boxCol, 3, X, Y, width, height ); args.SkipPartsCheck = true; drawer.DrawText( ref args, X + 1 + xOffset / 2, Y + 1 + yOffset / 2 ); }
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 ); } } }
/// <summary> Draws the specified string from the arguments into a new bitmap, /// using the specified font or the current bitmapped font depending on 'UseBitmappedChat', /// then creates a 2D texture with origin at the specified window coordinates. </summary> public Texture MakeTextTexture(ref DrawTextArgs args, int windowX, int windowY) { Size size = MeasureSize(ref args); if (size == Size.Empty) { return(new Texture(-1, windowX, windowY, 0, 0, 1, 1)); } using (Bitmap bmp = CreatePow2Bitmap(size)) { SetBitmap(bmp); args.SkipPartsCheck = true; DrawText(ref args, 0, 0); Dispose(); return(Make2DTexture(bmp, size, windowX, windowY)); } }
protected override Size MeasureSysSize(ref DrawTextArgs args) { GetTextParts(args.Text); float width = 0, height = 0; for (int i = 0; i < parts.Count; i++) { SizeF size = measuringGraphics.MeasureString(parts[i].Text, args.Font, Int32.MaxValue, format); height = Math.Max(height, size.Height); width += size.Width; } if (args.UseShadow) { width += Offset; height += Offset; } return(new Size((int)Math.Ceiling(width), (int)Math.Ceiling(height))); }
protected override Size MeasureSysSize(ref DrawTextArgs args) { GetTextParts(args.Text); SizeF total = SizeF.Empty; for (int i = 0; i < parts.Count; i++) { TextPart part = parts[i]; Paint textBrush = GetOrCreateBrush(part.Col); total.Width += textBrush.MeasureText(part.Text); } total.Height = PtToPx(args.Font.Size); if (args.UseShadow) { total.Width += Offset; total.Height += Offset; } return(Size.Ceiling(total)); }
public TextInputWidget(Game game, Font font, Font boldFont) : base(game) { HorizontalAnchor = Anchor.LeftOrTop; VerticalAnchor = Anchor.BottomOrRight; typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1. chatInputText = new WrappableStringBuffer(len); DrawTextArgs args = new DrawTextArgs("A", boldFont, true); Size defSize = game.Drawer2D.MeasureChatSize(ref args); defaultWidth = defSize.Width; defaultHeight = defSize.Height; Width = defaultWidth; Height = defaultHeight; args = new DrawTextArgs("_", boldFont, true); caretTex = game.Drawer2D.MakeChatTextTexture(ref args, 0, 0); this.font = font; altText = new AltTextInputWidget(game, font, this); altText.Init(); }
public void SetText( int index, string text ) { graphicsApi.DeleteTexture( ref Textures[index] ); DrawTextArgs args = new DrawTextArgs( text, font, true ); Font underlineFont = new Font( font, FontStyle.Underline ); urlBounds[index] = null; if( !String.IsNullOrEmpty( text ) ) { Texture tex = NextToken( text, 0 ) == -1 ? DrawSimple( ref args ) : DrawAdvanced( ref args, index, text ); tex.X1 = CalcOffset( game.Width, tex.Width, XOffset, HorizontalAnchor ); tex.Y1 = CalcY( index, tex.Height ); Textures[index] = tex; lines[index] = text; } else { Textures[index] = new Texture( -1, 0, 0, 0, defaultHeight, 0, 0 ); lines[index] = null; } UpdateDimensions(); }
protected void DrawBitmapTextImpl(FastBitmap dst, ref DrawTextArgs args, int x, int y) { bool underline = args.Font.Style == FontStyle.Underline; if (args.UseShadow) { int offset = ShadowOffset(args.Font.Size); DrawPart(dst, ref args, x + offset, y + offset, true); if (underline) { DrawUnderline(dst, x + offset, 0, ref args, true); } } DrawPart(dst, ref args, x, y, false); if (underline) { DrawUnderline(dst, x, -2, ref args, false); } }
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 DrawUnderline(FastBitmap fastBmp, FastColour textCol, int startX, int endX, int yOffset, ref DrawTextArgs args) { int height = PtToPx(args.Font.Size, boxSize); int offset = ShadowOffset(args.Font.Size); int col = textCol.ToArgb(); if (args.UseShadow) { height += offset; } for (int yy = height - offset; yy < height; yy++) { int *dstRow = fastBmp.GetRowPtr(yy + yOffset); for (int xx = startX; xx < endX; xx++) { dstRow[xx] = col; } } }
public override void Init() { DrawTextArgs measureArgs = new DrawTextArgs("ABC", font, false); elemHeight = game.Drawer2D.MeasureChatSize(ref measureArgs).Height; overview = ChatTextWidget.Create(game, 0, 0, "Connected players:", Anchor.Centre, Anchor.Centre, font); base.Init(); if (!extList) { game.EntityEvents.EntityAdded += PlayerSpawned; game.EntityEvents.EntityRemoved += PlayerDespawned; } else { game.EntityEvents.CpeListInfoAdded += PlayerListInfoAdded; game.EntityEvents.CpeListInfoRemoved += PlayerDespawned; game.EntityEvents.CpeListInfoChanged += PlayerListInfoChanged; } }
public TextInputWidget( Game game, Font font, Font boldFont ) : base(game) { HorizontalAnchor = Anchor.LeftOrTop; VerticalAnchor = Anchor.BottomOrRight; typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1. chatInputText = new WrappableStringBuffer( len ); DrawTextArgs args = new DrawTextArgs( "A", boldFont, true ); Size defSize = game.Drawer2D.MeasureChatSize( ref args ); defaultWidth = defSize.Width; defaultHeight = defSize.Height; Width = defaultWidth; Height = defaultHeight; args = new DrawTextArgs( "_", boldFont, true ); caretTex = game.Drawer2D.MakeChatTextTexture( ref args, 0, 0 ); this.font = font; this.boldFont = boldFont; altText = new AltTextInputWidget( game, font, boldFont, this ); altText.Init(); }
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)); 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, 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; }
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 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]; 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; // 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 += partLens[y]; } caretPos = -1; CalculateCaretData(); }
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; }
protected override void DrawSysText(ref DrawTextArgs args, int x, int y) { if (!args.SkipPartsCheck) { GetTextParts(args.Text); } float textX = x; Paint backBrush = GetOrCreateBrush(PackedCol.Black); for (int i = 0; i < parts.Count; i++) { TextPart part = parts[i]; Paint foreBrush = GetOrCreateBrush(part.Col); if (args.UseShadow) { c.DrawText(part.Text, textX + Offset, y + Offset, backBrush); } c.DrawText(part.Text, textX, y, foreBrush); textX += foreBrush.MeasureText(part.Text); } }
public override void DrawText(ref DrawTextArgs args, int x, int y) { if (!args.SkipPartsCheck) { GetTextParts(args.Text); } Paint shadowBrush = GetOrCreateBrush(Color.Black); float textX = x; for (int i = 0; i < parts.Count; i++) { TextPart part = parts[i]; Paint textBrush = GetOrCreateBrush(part.TextColour); if (args.UseShadow) { c.DrawText(part.Text, textX + Offset, y + Offset, shadowBrush); } c.DrawText(part.Text, textX, y, textBrush); textX += textBrush.MeasureText(part.Text); } }
protected override void DrawSysText(ref DrawTextArgs args, int x, int y) { if (!args.SkipPartsCheck) { GetTextParts(args.Text); } float textX = x; Brush backBrush = GetOrCreateBrush(PackedCol.Black); for (int i = 0; i < parts.Count; i++) { TextPart part = parts[i]; Brush foreBrush = GetOrCreateBrush(part.Col); if (args.UseShadow) { g.DrawString(part.Text, args.Font, backBrush, textX + Offset, y + Offset, format); } g.DrawString(part.Text, args.Font, foreBrush, textX, y, format); textX += g.MeasureString(part.Text, args.Font, Int32.MaxValue, format).Width; } }
public override void DrawText(ref DrawTextArgs args, int x, int y) { if (!args.SkipPartsCheck) { GetTextParts(args.Text); } Brush shadowBrush = GetOrCreateBrush(Color.Black); float textX = x; for (int i = 0; i < parts.Count; i++) { TextPart part = parts[i]; Brush textBrush = GetOrCreateBrush(part.TextColour); if (args.UseShadow) { g.DrawString(part.Text, args.Font, shadowBrush, textX + Offset, y + Offset, format); } g.DrawString(part.Text, args.Font, textBrush, textX, y, format); textX += g.MeasureString(part.Text, args.Font, Int32.MaxValue, format).Width; } }
public override Size MeasureSize(ref DrawTextArgs args) { GetTextParts(args.Text); if (parts.Count == 0) { return(Size.Empty); } SizeF total = SizeF.Empty; for (int i = 0; i < parts.Count; i++) { SizeF size = measuringGraphics.MeasureString(parts[i].Text, args.Font, Int32.MaxValue, format); total.Height = Math.Max(total.Height, size.Height); total.Width += size.Width; } if (args.UseShadow) { total.Width += Offset; total.Height += Offset; } return(Size.Ceiling(total)); }
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)); } }
protected void DrawBitmapTextImpl(FastBitmap dst, ref DrawTextArgs args, int x, int y) { bool ul = args.Font.Style == FontStyle.Underline; int offset = Utils.Floor(args.Font.Size) / 8; if (args.UseShadow) { DrawCore(dst, ref args, x + offset, y + offset, true); #if !LAUNCHER if (ul) { DrawUnderline(dst, ref args, x + offset, y + offset, true); } #endif } DrawCore(dst, ref args, x, y, false); #if !LAUNCHER if (ul) { DrawUnderline(dst, ref args, x, y, false); } #endif }
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)); } }
public void SetText(int index, string text) { graphicsApi.DeleteTexture(ref Textures[index]); DrawTextArgs args = new DrawTextArgs(text, font, true); Font underlineFont = new Font(font, FontStyle.Underline); urlBounds[index] = null; if (!String.IsNullOrEmpty(text)) { Texture tex = NextToken(text, 0) == -1 ? DrawSimple(ref args) : DrawAdvanced(ref args, index, text); tex.X1 = CalcOffset(game.Width, tex.Width, XOffset, HorizontalAnchor); tex.Y1 = CalcY(index, tex.Height); Textures[index] = tex; lines[index] = text; } else { Textures[index] = new Texture(-1, 0, 0, 0, defaultHeight, 0, 0); lines[index] = null; } UpdateDimensions(); }
public override void DrawClippedText(ref DrawTextArgs args, int x, int y, float maxWidth, float maxHeight) { throw new NotImplementedException(); }
/// <summary> Returns the size of a bitmap needed to contain the specified text with the given arguments, /// when drawn with the specified font or the current bitmapped font depending on 'UseBitmappedChat'. </summary> public Size MeasureChatSize(ref DrawTextArgs args) { return(!UseBitmappedChat?MeasureSize(ref args) : MeasureBitmappedSize(ref args)); }
/// <summary> Returns the size of a bitmap needed to contain the specified text with the given arguments, /// when drawn with the current bitmapped font. </summary> public abstract Size MeasureBitmappedSize(ref DrawTextArgs args);
/// <summary> Returns the size of a bitmap needed to contain the specified text with the given arguments. </summary> public abstract Size MeasureSize(ref DrawTextArgs args);
/// <summary> Draws a string using the specified arguments and the current bitmapped font at the /// specified coordinates in the currently bound bitmap. </summary> public abstract void DrawBitmappedText(ref DrawTextArgs args, int x, int y);
/// <summary> Draws a string using the specified arguments and fonts at the /// specified coordinates in the currently bound bitmap, clipping if necessary. </summary> public abstract void DrawClippedText(ref DrawTextArgs args, int x, int y, float maxWidth, float maxHeight);
/// <summary> Draws the specified string from the arguments into a new bitmap, /// using the specified font or the current bitmapped font depending on 'UseBitmappedChat', /// then creates a 2D texture with origin at the specified window coordinates. </summary> public Texture MakeChatTextTexture(ref DrawTextArgs args, int windowX, int windowY) { return(MakeTextureImpl(ref args, windowX, windowY, UseBitmappedChat)); }