Skip to content

Commit 3c5ce90

Browse files
committed
minor optimization changes for UnityGdi.DrawString;
1 parent 9723997 commit 3c5ce90

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

System/Windows/Forms/Control.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class Control : Component, IDropTarget
1818

1919
internal Application uwfAppOwner;
2020
internal bool uwfAutoGroup;
21-
internal int uwfBatches;
2221
internal bool uwfShadowBox;
2322
internal DrawHandler uwfShadowHandler;
2423
internal Point uwfOffset;
@@ -554,8 +553,6 @@ internal virtual void RaiseOnKeyUp(KeyEventArgs e)
554553
}
555554
internal virtual void RaiseOnPaint(PaintEventArgs e)
556555
{
557-
uwfBatches = 0;
558-
559556
if (uwfShadowBox)
560557
{
561558
if (uwfShadowHandler == null)

System/Windows/Forms/Form.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class Form : ContainerControl, IResizableControl
88
internal readonly Pen borderPen = new Pen(defaultFormBorderColor);
99
internal readonly Pen innerBorderPen = new Pen(defaultFormInnerBorderColor);
1010
internal bool dialog;
11+
internal bool formMoving;
1112
internal Color uwfHeaderColor = defaultFormHeaderColor;
1213
internal Font uwfHeaderFont;
1314
internal int uwfHeaderHeight = 24;
@@ -33,7 +34,6 @@ public class Form : ContainerControl, IResizableControl
3334
private Button closeButton;
3435
private Action<Form, DialogResult> dialogCallback;
3536
private MenuStrip mainMenuStrip;
36-
private bool windowMove;
3737
private Point windowMove_StartPosition;
3838
private Form owner;
3939
private ControlResizeTypes resizeType;
@@ -333,7 +333,7 @@ internal virtual void Application_UpdateEvent()
333333
}
334334
internal virtual void Application_UpClick(object sender, MouseEventArgs e)
335335
{
336-
windowMove = false;
336+
formMoving = false;
337337
resizeType = ControlResizeTypes.None;
338338
if (Application.activeResizeControl == this)
339339
Application.activeResizeControl = null;
@@ -418,15 +418,15 @@ protected override void OnMouseDown(MouseEventArgs e)
418418
if (e.Location.Y < uwfHeaderHeight)
419419
{
420420
windowMove_StartPosition = e.Location;
421-
windowMove = true;
421+
formMoving = true;
422422
}
423423
}
424424
}
425425
}
426426
protected override void OnMouseMove(MouseEventArgs e)
427427
{
428428
base.OnMouseMove(e);
429-
if (windowMove)
429+
if (formMoving)
430430
{
431431
if (Parent == null)
432432
Location = PointToScreen(e.Location).Subtract(windowMove_StartPosition);

System/Windows/Forms/TabControl.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void SelectTab(int index)
157157
var cancelArgs = new TabControlCancelEventArgs(selectedPage, index, false, TabControlAction.Selecting);
158158

159159
OnSelecting(cancelArgs);
160-
160+
161161
if (cancelArgs.Cancel)
162162
return;
163163

@@ -731,6 +731,7 @@ internal class TabPageButton : Button
731731
internal Color disabledBackHoverColor = Color.FromArgb(223, 238, 252);
732732
internal Padding textPadding = new Padding(6, 0, 6, 0);
733733

734+
private readonly Pen borderPen = new Pen(Color.Gray);
734735
private readonly TabControl owner;
735736
private readonly int index;
736737
private bool hidden;
@@ -794,7 +795,7 @@ protected override void OnPaint(PaintEventArgs e)
794795
var h = Height;
795796

796797
// Draw borders.
797-
var borderPen = new Pen(owner.uwfBorderColor);
798+
borderPen.Color = owner.uwfBorderColor;
798799
g.DrawLine(borderPen, 0, 0, w, 0); // Top.
799800
g.DrawLine(borderPen, 0, 0, 0, h - 1); // Left.
800801
g.DrawLine(borderPen, w - 1, 0, w - 1, h - 1); // Right.

Unity/API/UnityGdi.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ public class UnityGdi : IApiGraphics
1212
public static UE.Texture2D defaultTexture = UnityWinForms.DefaultSprite;
1313
public static bool GL_LINES;
1414

15+
private static readonly UE.GUIContent textContent = new UE.GUIContent(""); // GUIContent.Temp(text) replacement.
16+
1517
private readonly PointF defaultPivot = PointF.Empty;
1618

1719
public void BeginGroup(float x, float y, float width, float height)
1820
{
19-
UE.GUI.BeginGroup(new UE.Rect(x, y, width, height));
21+
UE.GUI.BeginGroup(new UE.Rect(x, y, width, height), UE.GUIContent.none, UE.GUIStyle.none);
2022
}
2123
public void Clear(Color color)
2224
{
@@ -301,7 +303,11 @@ public void DrawString(string text, Font font, Color color, float x, float y, fl
301303

302304
UE.GUI.color = color.ToUnityColor();
303305
labelSkin.alignment = uAlign;
304-
UE.GUI.Label(new UE.Rect(x, y, width, height), text);
306+
307+
textContent.text = text;
308+
309+
// It's faster to invoke less methods and use your own GUIContent. Not that much, but anyway.
310+
UE.GUI.Label(new UE.Rect(x, y, width, height), textContent, labelSkin);
305311

306312
labelSkin.fontSize = guiSkinFontSizeBuffer;
307313
}

0 commit comments

Comments
 (0)