diff --git a/ClassicalSharp/2D/Drawing/IDrawer2D.cs b/ClassicalSharp/2D/Drawing/IDrawer2D.cs
index 8fc6e79a1..8067e1d75 100644
--- a/ClassicalSharp/2D/Drawing/IDrawer2D.cs
+++ b/ClassicalSharp/2D/Drawing/IDrawer2D.cs
@@ -47,6 +47,9 @@ namespace ClassicalSharp {
src = newBmp;
}
+ /// Whether chat text should be drawn and measuring using the currently bitmapped font,
+ /// false uses the font supplied as the DrawTextArgs argument supplied to the function.
+ public bool UseBitmappedChat = false;
/// Draws a string using the specified arguments and font at the
/// specified coordinates in the currently bound bitmap.
@@ -63,8 +66,8 @@ namespace ClassicalSharp {
/// 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.
- public void DrawChatText( bool useFont, ref DrawTextArgs args, int windowX, int windowY ) {
- if( useFont )
+ public void DrawChatText( ref DrawTextArgs args, int windowX, int windowY ) {
+ if( !UseBitmappedChat )
DrawText( ref args, windowX, windowY );
else
DrawBitmappedText( ref args, windowX, windowY );
@@ -79,8 +82,8 @@ namespace ClassicalSharp {
/// 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 the 'useFont' argument.
- public Size MeasureChatSize( bool useFont, ref DrawTextArgs args ) {
- return useFont ? MeasureSize( ref args ) :
+ public Size MeasureChatSize( ref DrawTextArgs args ) {
+ return !UseBitmappedChat ? MeasureSize( ref args ) :
MeasureBitmappedSize( ref args );
}
diff --git a/ClassicalSharp/2D/Screens/ChatScreen.cs b/ClassicalSharp/2D/Screens/ChatScreen.cs
index f564ae3fa..f8d6ef4c0 100644
--- a/ClassicalSharp/2D/Screens/ChatScreen.cs
+++ b/ClassicalSharp/2D/Screens/ChatScreen.cs
@@ -121,6 +121,7 @@ namespace ClassicalSharp {
game.chatInInputBuffer = null;
}
game.Events.ChatReceived += ChatReceived;
+ game.Events.ChatFontChanged += ChatFontChanged;
}
void ChatReceived( object sender, ChatEventArgs e ) {
@@ -159,6 +160,12 @@ namespace ClassicalSharp {
bottomRight.Dispose();
graphicsApi.DeleteTexture( ref announcementTex );
game.Events.ChatReceived -= ChatReceived;
+ game.Events.ChatFontChanged -= ChatFontChanged;
+ }
+
+ void ChatFontChanged( object sender, EventArgs e ) {
+ Dispose();
+ Init();
}
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
diff --git a/ClassicalSharp/2D/Screens/FpsScreen.cs b/ClassicalSharp/2D/Screens/FpsScreen.cs
index 73a961c10..51a04e175 100644
--- a/ClassicalSharp/2D/Screens/FpsScreen.cs
+++ b/ClassicalSharp/2D/Screens/FpsScreen.cs
@@ -62,7 +62,9 @@ namespace ClassicalSharp {
fpsTextWidget.XOffset = 2;
fpsTextWidget.YOffset = 2;
fpsTextWidget.Init();
- fpsTextWidget.SetText( "FPS: no data yet" );
+ string fpsText = text.Length > 0 ? text.GetString() :
+ "FPS: no data yet";
+ fpsTextWidget.SetText( fpsText );
MakePosTextWidget();
hackStatesWidget = new ChatTextWidget( game, posFont );
@@ -130,23 +132,23 @@ namespace ClassicalSharp {
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( game.UseArial, ref args ).Width;
+ widths[i] = game.Drawer2D.MeasureChatSize( ref args ).Width;
}
using( IDrawer2D drawer = game.Drawer2D ) {
args.Text = "Feet pos: ";
- Size size = game.Drawer2D.MeasureChatSize( game.UseArial, ref args );
+ 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( game.UseArial, ref args, 0, 0 );
+ drawer.DrawChatText( ref args, 0, 0 );
for( int i = 0; i < possibleChars.Length; i++ ) {
args.Text = new String( possibleChars[i], 1 );
- drawer.DrawChatText( game.UseArial, ref args, baseWidth + 16 * i, 0 );
+ drawer.DrawChatText( ref args, baseWidth + 16 * i, 0 );
}
int y = fpsTextWidget.Height + 2;
diff --git a/ClassicalSharp/2D/Widgets/Chat/ChatTextWidget.cs b/ClassicalSharp/2D/Widgets/Chat/ChatTextWidget.cs
index 7a542a207..a32a2568d 100644
--- a/ClassicalSharp/2D/Widgets/Chat/ChatTextWidget.cs
+++ b/ClassicalSharp/2D/Widgets/Chat/ChatTextWidget.cs
@@ -21,7 +21,7 @@ namespace ClassicalSharp {
public override void Init() {
DrawTextArgs args = new DrawTextArgs( "I", font, true );
- defaultHeight = game.Drawer2D.MeasureChatSize( game.UseArial, ref args ).Height;
+ defaultHeight = game.Drawer2D.MeasureChatSize( ref args ).Height;
Height = defaultHeight;
}
@@ -32,10 +32,10 @@ namespace ClassicalSharp {
Height = defaultHeight;
} else {
DrawTextArgs args = new DrawTextArgs( text, font, true );
- if( game.UseArial )
- texture = game.Drawer2D.MakeTextTexture( ref args, 0, 0 );
- else
- texture = game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 );
+ 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;
diff --git a/ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.cs b/ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.cs
index 905684458..c6906b3b0 100644
--- a/ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.cs
+++ b/ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.cs
@@ -19,11 +19,10 @@ namespace ClassicalSharp {
public override void Init() {
Textures = new Texture[ElementsCount];
DrawTextArgs args = new DrawTextArgs( "I", font, true );
- defaultHeight = game.Drawer2D.MeasureSize( ref args ).Height;
+ defaultHeight = game.Drawer2D.MeasureChatSize( ref args ).Height;
- for( int i = 0; i < Textures.Length; i++ ) {
+ for( int i = 0; i < Textures.Length; i++ )
Textures[i].Height = defaultHeight;
- }
UpdateDimensions();
}
@@ -31,8 +30,11 @@ namespace ClassicalSharp {
graphicsApi.DeleteTexture( ref Textures[index] );
DrawTextArgs args = new DrawTextArgs( text, font, true );
- if( !String.IsNullOrEmpty( text ) ) {
- Texture tex = game.Drawer2D.MakeTextTexture( ref args, 0, 0 );
+ if( !String.IsNullOrEmpty( text ) ) {
+ Texture tex = game.Drawer2D.UseBitmappedChat ?
+ game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 ) :
+ game.Drawer2D.MakeTextTexture( ref args, 0, 0 );
+
tex.X1 = CalcOffset( game.Width, tex.Width, XOffset, HorizontalAnchor );
tex.Y1 = CalcY( index, tex.Height );
Textures[index] = tex;
@@ -109,20 +111,17 @@ namespace ClassicalSharp {
}
public override void Dispose() {
- for( int i = 0; i < Textures.Length; i++ ) {
+ for( int i = 0; i < Textures.Length; i++ )
graphicsApi.DeleteTexture( ref Textures[i] );
- }
}
public override void MoveTo( int newX, int newY ) {
- int deltaX = newX - X;
- int deltaY = newY - Y;
+ int diffX = newX - X, diffY = newY - Y;
for( int i = 0; i < Textures.Length; i++ ) {
- Textures[i].X1 += deltaX;
- Textures[i].Y1 += deltaY;
+ Textures[i].X1 += diffX;
+ Textures[i].Y1 += diffY;
}
- X = newX;
- Y = newY;
+ X = newX; Y = newY;
}
}
}
\ No newline at end of file
diff --git a/ClassicalSharp/Game/Events.cs b/ClassicalSharp/Game/Events.cs
index 80c6cc0a6..fea597107 100644
--- a/ClassicalSharp/Game/Events.cs
+++ b/ClassicalSharp/Game/Events.cs
@@ -68,8 +68,8 @@ namespace ClassicalSharp {
/// Raised when the user changes chat font to arial or back to bitmapped font,
/// also raised when the bitmapped font changes.
- public event EventHandler ChatFontChanged;
- internal void RaiseChatFontChanged( bool arial ) { fontArgs.UseArial = arial; Raise( ChatFontChanged, fontArgs ); }
+ public event EventHandler ChatFontChanged;
+ internal void RaiseChatFontChanged() { Raise( ChatFontChanged ); }
@@ -78,7 +78,6 @@ namespace ClassicalSharp {
MapLoadingEventArgs loadingArgs = new MapLoadingEventArgs();
EnvVarEventArgs envArgs = new EnvVarEventArgs();
ChatEventArgs chatArgs = new ChatEventArgs();
- ChatFontChangedEventArgs fontArgs = new ChatFontChangedEventArgs();
void Raise( EventHandler handler ) {
if( handler != null ) {
@@ -120,13 +119,6 @@ namespace ClassicalSharp {
public EnvVar Var;
}
- public sealed class ChatFontChangedEventArgs : EventArgs {
-
- /// true if chat should be drawn using arial,
- /// false if it should be drawn using the current bitmapped font.
- public bool UseArial;
- }
-
public enum EnvVar {
SidesBlock,
EdgeBlock,
diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs
index 0b9ccab5f..17de18ba5 100644
--- a/ClassicalSharp/Game/Game.cs
+++ b/ClassicalSharp/Game/Game.cs
@@ -74,7 +74,6 @@ namespace ClassicalSharp {
internal int CloudsTextureId, RainTextureId, SnowTextureId;
internal bool screenshotRequested;
public Bitmap FontBitmap;
- public bool UseArial = false;
void LoadAtlas( Bitmap bmp ) {
TerrainAtlas1D.Dispose();
diff --git a/ClassicalSharp/Game/InputHandler.cs b/ClassicalSharp/Game/InputHandler.cs
index 52d351cd7..d47dde4dd 100644
--- a/ClassicalSharp/Game/InputHandler.cs
+++ b/ClassicalSharp/Game/InputHandler.cs
@@ -271,8 +271,8 @@ namespace ClassicalSharp {
// TODO: this is a temp debug statement
// NOTE: this is a temp debug statement
if( key == Key.F8 ) {
- game.UseArial = !game.UseArial;
- game.Events.RaiseChatFontChanged( game.UseArial );
+ game.Drawer2D.UseBitmappedChat = !game.Drawer2D.UseBitmappedChat;
+ game.Events.RaiseChatFontChanged();
return;
}
if( key == Key.F4 && (game.IsKeyDown( Key.AltLeft ) || game.IsKeyDown( Key.AltRight )) ) {
diff --git a/ClassicalSharp/TexturePack/TexturePackExtractor.cs b/ClassicalSharp/TexturePack/TexturePackExtractor.cs
index f8c998959..46099f4f6 100644
--- a/ClassicalSharp/TexturePack/TexturePackExtractor.cs
+++ b/ClassicalSharp/TexturePack/TexturePackExtractor.cs
@@ -88,8 +88,8 @@ namespace ClassicalSharp.TexturePack {
game.FontBitmap = new Bitmap( stream );
game.Drawer2D.SetFontBitmap( game.FontBitmap );
- if( !game.UseArial)
- game.Events.RaiseChatFontChanged( false );
+ if( game.Drawer2D.UseBitmappedChat )
+ game.Events.RaiseChatFontChanged();
}
void UpdateTexture( ref int texId, Stream stream, bool setSkinType ) {