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
/// multiple of the size of a character in default.png. </summary>
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

View File

@ -157,7 +157,6 @@ namespace ClassicalSharp {
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 );

View File

@ -28,7 +28,7 @@ namespace ClassicalSharp.Gui {
if( lastX == mouseX && lastY == mouseY )
return true;
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;
}

View File

@ -18,7 +18,7 @@ namespace ClassicalSharp.Gui {
public override void Render( double delta ) {
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;
if( extendedHelp != null && extEndY <= extClipY ) {

View File

@ -53,7 +53,7 @@ namespace ClassicalSharp.Gui {
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 );
}

View File

@ -67,7 +67,7 @@ namespace ClassicalSharp.Gui {
if( button == null ) return;
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 ) {

View File

@ -32,12 +32,6 @@ namespace ClassicalSharp.Gui {
public int DesiredMaxWidth, DesiredMaxHeight;
int defaultHeight;
internal Font font;
bool active = false;
public override bool Active {
get { return active; }
set { active = value; SetText( Text ); }
}
public override void Init() {
DrawTextArgs args = new DrawTextArgs( "I", font, true );
@ -45,12 +39,12 @@ namespace ClassicalSharp.Gui {
Height = defaultHeight;
}
static Texture shadowTex = new Texture( 0, 0, 0, 0, 0,
static Texture shadowTex = new Texture( 0, 0, 0, 0, 0,
new TextureRec( 0, 66/256f, 200/256f, 20/256f ) );
static Texture selectedTex = new Texture( 0, 0, 0, 0, 0,
new TextureRec( 0, 86/256f, 200/256f, 20/256f ) );
static Texture disabledTex = new Texture( 0, 0, 0, 0, 0,
new TextureRec( 0, 46/256f, 200/256f, 20/256f ) );
new TextureRec( 0, 46/256f, 200/256f, 20/256f ) );
public string Text;
public void SetText( string text ) {
api.DeleteTexture( ref texture );
@ -67,6 +61,9 @@ namespace ClassicalSharp.Gui {
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 ) {
if( !texture.IsValid )
return;
@ -78,8 +75,7 @@ namespace ClassicalSharp.Gui {
backTex.Width = Width; backTex.Height = Height;
backTex.Render( api );
FastColour col = Active ? FastColour.White : new FastColour( 200, 200, 200 );
if( Disabled ) col = new FastColour( 150, 150, 150 );
FastColour col = Disabled ? disabledCol : (Active ? activeCol : normCol);
texture.Render( api, col );
}
@ -98,8 +94,6 @@ namespace ClassicalSharp.Gui {
void MakeTexture( string text ) {
DrawTextArgs args = new DrawTextArgs( text, font, true );
if( active )
args.Text = "&" + (char)0xFF + args.Text;
Size size = game.Drawer2D.MeasureChatSize( ref args );
int xOffset = Math.Max( size.Width, DesiredMaxWidth ) - size.Width;
@ -110,7 +104,7 @@ namespace ClassicalSharp.Gui {
using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) )
using( IDrawer2D drawer = game.Drawer2D )
{
drawer.SetBitmap( bmp );
drawer.SetBitmap( bmp );
args.SkipPartsCheck = true;
drawer.DrawChatText( ref args, xOffset / 2, yOffset / 2 );
texture = drawer.Make2DTexture( bmp, size, 0, 0 );