mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 01:55:19 -04:00
Press F8 (temp debug) to switch between default.png and arial for chat.
This commit is contained in:
parent
2493feb86f
commit
57d4a937c8
@ -47,6 +47,9 @@ namespace ClassicalSharp {
|
||||
src = newBmp;
|
||||
}
|
||||
|
||||
/// <summary>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. </summary>
|
||||
public bool UseBitmappedChat = false;
|
||||
|
||||
/// <summary> Draws a string using the specified arguments and font at the
|
||||
/// specified coordinates in the currently bound bitmap. </summary>
|
||||
@ -63,8 +66,8 @@ namespace ClassicalSharp {
|
||||
/// <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( 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 {
|
||||
|
||||
/// <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 the 'useFont' argument. </summary>
|
||||
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 );
|
||||
}
|
||||
|
||||
|
@ -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 ) {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -68,8 +68,8 @@ namespace ClassicalSharp {
|
||||
|
||||
/// <summary> Raised when the user changes chat font to arial or back to bitmapped font,
|
||||
/// also raised when the bitmapped font changes. </summary>
|
||||
public event EventHandler<EventArgs> 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 {
|
||||
|
||||
/// <summary> true if chat should be drawn using arial,
|
||||
/// false if it should be drawn using the current bitmapped font. </summary>
|
||||
public bool UseArial;
|
||||
}
|
||||
|
||||
public enum EnvVar {
|
||||
SidesBlock,
|
||||
EdgeBlock,
|
||||
|
@ -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();
|
||||
|
@ -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 )) ) {
|
||||
|
@ -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 ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user