Fix performance drop in gui introduced several commits ago.

This commit is contained in:
UnknownShadow200 2016-04-19 11:27:39 +10:00
parent e51aefe4d7
commit ff9de47b1f
7 changed files with 12 additions and 19 deletions

View File

@ -226,7 +226,7 @@ namespace ClassicalSharp {
/// <summary> Rounds the given font size up to the nearest whole /// <summary> Rounds the given font size up to the nearest whole
/// multiple of the size of a character in default.png. </summary> /// multiple of the size of a character in default.png. </summary>
protected int AdjTextSize( int point ) { protected int AdjTextSize( int point ) {
return Utils.CeilDiv( point, boxSize ) * boxSize; return point; //Utils.CeilDiv( point, boxSize ) * boxSize;
} }
/// <summary> Returns the height of the bounding box that /// <summary> Returns the height of the bounding box that

View File

@ -157,7 +157,6 @@ namespace ClassicalSharp {
Colours['a' + i - 10] = FastColour.GetHexEncodedCol( i ); Colours['a' + i - 10] = FastColour.GetHexEncodedCol( i );
Colours['A' + i - 10] = FastColour.GetHexEncodedCol( i ); Colours['A' + i - 10] = FastColour.GetHexEncodedCol( i );
} }
Colours[255] = new FastColour( 255, 255, 160 );
} }
protected List<TextPart> parts = new List<TextPart>( 64 ); protected List<TextPart> parts = new List<TextPart>( 64 );

View File

@ -28,7 +28,7 @@ namespace ClassicalSharp.Gui {
if( lastX == mouseX && lastY == mouseY ) if( lastX == mouseX && lastY == mouseY )
return true; return true;
for( int i = 0; i < widgets.Length; i++ ) { for( int i = 0; i < widgets.Length; i++ ) {
if( widgets[i] == null ) continue; if( widgets[i] == null || !widgets[i].Active ) continue;
widgets[i].Active = false; widgets[i].Active = false;
} }

View File

@ -18,7 +18,7 @@ namespace ClassicalSharp.Gui {
public override void Render( double delta ) { public override void Render( double delta ) {
RenderMenuBounds(); RenderMenuBounds();
int extClipY = widgets[widgets.Length - 3].Y; int extClipY = extendedHelp == null ? 0 : widgets[widgets.Length - 3].Y;
int extEndY = extendedHelp == null ? 0 : extendedHelp.Y + extendedHelp.Height; int extEndY = extendedHelp == null ? 0 : extendedHelp.Y + extendedHelp.Height;
if( extendedHelp != null && extEndY <= extClipY ) { if( extendedHelp != null && extEndY <= extClipY ) {

View File

@ -53,7 +53,7 @@ namespace ClassicalSharp.Gui {
new BooleanValidator(), new BooleanValidator(),
new BooleanValidator(), new BooleanValidator(),
}; };
infoWidget = TextWidget.Create( game, 0, 150, "&eButtons on the right require a client restart.", infoWidget = ChatTextWidget.Create( game, 0, 100, "&eButtons on the right require a client restart",
Anchor.Centre, Anchor.Centre, regularFont ); Anchor.Centre, Anchor.Centre, regularFont );
} }

View File

@ -67,7 +67,7 @@ namespace ClassicalSharp.Gui {
if( button == null ) return; if( button == null ) return;
string text = descriptions[Array.IndexOf<Widget>(widgets, button)]; string text = descriptions[Array.IndexOf<Widget>(widgets, button)];
descWidget = TextWidget.Create( game, 0, 100, text, Anchor.Centre, Anchor.Centre, regularFont ); descWidget = ChatTextWidget.Create( game, 0, 100, text, Anchor.Centre, Anchor.Centre, regularFont );
} }
ButtonWidget Make( int x, int y, string text, Action<Game, Widget> onClick ) { ButtonWidget Make( int x, int y, string text, Action<Game, Widget> onClick ) {

View File

@ -32,12 +32,6 @@ namespace ClassicalSharp.Gui {
public int DesiredMaxWidth, DesiredMaxHeight; public int DesiredMaxWidth, DesiredMaxHeight;
int defaultHeight; int defaultHeight;
internal Font font; internal Font font;
bool active = false;
public override bool Active {
get { return active; }
set { active = value; SetText( Text ); }
}
public override void Init() { public override void Init() {
DrawTextArgs args = new DrawTextArgs( "I", font, true ); DrawTextArgs args = new DrawTextArgs( "I", font, true );
@ -67,6 +61,9 @@ namespace ClassicalSharp.Gui {
Width = texture.Width; Width = texture.Width;
} }
static FastColour normCol = new FastColour( 224, 224, 224 ),
activeCol = new FastColour( 255, 255, 160 ),
disabledCol = new FastColour( 160, 160, 160 );
public override void Render( double delta ) { public override void Render( double delta ) {
if( !texture.IsValid ) if( !texture.IsValid )
return; return;
@ -78,8 +75,7 @@ namespace ClassicalSharp.Gui {
backTex.Width = Width; backTex.Height = Height; backTex.Width = Width; backTex.Height = Height;
backTex.Render( api ); backTex.Render( api );
FastColour col = Active ? FastColour.White : new FastColour( 200, 200, 200 ); FastColour col = Disabled ? disabledCol : (Active ? activeCol : normCol);
if( Disabled ) col = new FastColour( 150, 150, 150 );
texture.Render( api, col ); texture.Render( api, col );
} }
@ -98,8 +94,6 @@ namespace ClassicalSharp.Gui {
void MakeTexture( string text ) { void MakeTexture( string text ) {
DrawTextArgs args = new DrawTextArgs( text, font, true ); DrawTextArgs args = new DrawTextArgs( text, font, true );
if( active )
args.Text = "&" + (char)0xFF + args.Text;
Size size = game.Drawer2D.MeasureChatSize( ref args ); Size size = game.Drawer2D.MeasureChatSize( ref args );
int xOffset = Math.Max( size.Width, DesiredMaxWidth ) - size.Width; int xOffset = Math.Max( size.Width, DesiredMaxWidth ) - size.Width;