Fix issues with UnsafeString on Windows XP and below. (Unfortunately, I couldn't work around this without having to allocate strings.)

This commit is contained in:
UnknownShadow200 2015-05-21 16:22:48 +10:00
parent 59a98083b1
commit df4c6b4b32
3 changed files with 14 additions and 2 deletions

View File

@ -36,7 +36,11 @@ namespace ClassicalSharp {
.Append( ref ptr2, "), chunks/s: " ).AppendNum( ref ptr2, Window.ChunkUpdates )
.Append( ref ptr2, ", vertices: " ).AppendNum( ref ptr2, Window.Vertices );
}
fpsTextWidget.SetText( text.value );
string textString = text.value;
if( Utils2D.needWinXpFix )
textString = textString.TrimEnd( Utils2D.trimChars );
fpsTextWidget.SetText( textString );
maxDelta = 0;
accumulator = 0;
fpsCount = 0;

View File

@ -12,6 +12,9 @@ namespace ClassicalSharp {
static Bitmap measuringBmp;
static Graphics measuringGraphics;
static Dictionary<int, SolidBrush> brushCache = new Dictionary<int, SolidBrush>( 16 );
internal static bool needWinXpFix;
internal static char[] trimChars = { '\0' };
static Utils2D() {
format = StringFormat.GenericTypographic;
format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
@ -20,6 +23,9 @@ namespace ClassicalSharp {
//format.FormatFlags |= StringFormatFlags.NoClip;
measuringBmp = new Bitmap( 1, 1 );
measuringGraphics = Graphics.FromImage( measuringBmp );
measuringGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
OperatingSystem os = Environment.OSVersion;
needWinXpFix = os.Platform == PlatformID.Win32NT && os.Version.Major < 6;
}
static SolidBrush GetOrCreateBrush( Color color ) {
@ -33,7 +39,7 @@ namespace ClassicalSharp {
return brush;
}
const float shadowOffset = 1.3f;
const float shadowOffset = 1.3f;
public static Size MeasureSize( string text, Font font, bool shadow ) {
SizeF size = measuringGraphics.MeasureString( text, font, Int32.MaxValue, format );
if( shadow ) {

View File

@ -41,6 +41,8 @@ namespace ClassicalSharp {
DrawTextArgs caretArgs = new DrawTextArgs( GraphicsApi, "_", Color.White, false );
chatCaretTexture = Utils2D.MakeTextTexture( boldFont, 0, 0, ref caretArgs );
string value = chatInputText.value;
if( Utils2D.needWinXpFix )
value = value.TrimEnd( Utils2D.trimChars );
if( chatInputText.Empty ) {
caretPos = -1;