Skip to content

Commit a48c482

Browse files
committed
little update
1 parent a45d327 commit a48c482

File tree

9 files changed

+104
-24
lines changed

9 files changed

+104
-24
lines changed

System/Drawing/Graphics.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal void GroupEnd()
3333
_groupControls.RemoveAt(_groupControls.Count - 1);
3434
}
3535

36-
private PointF[] GetBezierApproximation(PointF[] controlPoints, int outputSegmentCount)
36+
public static PointF[] GetBezierApproximation(PointF[] controlPoints, int outputSegmentCount)
3737
{
3838
PointF[] points = new PointF[outputSegmentCount + 1];
3939
for (int i = 0; i <= outputSegmentCount; i++)
@@ -43,7 +43,7 @@ private PointF[] GetBezierApproximation(PointF[] controlPoints, int outputSegmen
4343
}
4444
return points;
4545
}
46-
private PointF GetBezierPoint(float t, PointF[] controlPoints, int index, int count)
46+
private static PointF GetBezierPoint(float t, PointF[] controlPoints, int index, int count)
4747
{
4848
if (count == 1)
4949
return controlPoints[index];
@@ -64,7 +64,7 @@ private static int GUI_SetLabelFont(Font font)
6464
else
6565
{
6666
GUI.skin.label.font = null;
67-
UnityEngine.Debug.LogWarning(font.Name);
67+
UnityEngine.Debug.Log(font.Name);
6868
}
6969
}
7070
else
@@ -102,7 +102,7 @@ public void Dispose()
102102
public void Clear(System.Drawing.Color color)
103103
{
104104
}
105-
public void DrawCurve(Pen pen, PointF[] points) // very slow.
105+
public void DrawCurve(Pen pen, PointF[] points, int segments = 32) // very slow.
106106
{
107107
if (points == null || points.Length <= 1) return;
108108
if (points.Length == 2)
@@ -111,7 +111,7 @@ public void DrawCurve(Pen pen, PointF[] points) // very slow.
111111
return;
112112
}
113113

114-
var bPoints = GetBezierApproximation(points, 32); // decrease segments for better fps.
114+
var bPoints = GetBezierApproximation(points, segments); // decrease segments for better fps.
115115
for (int i = 0; i + 1 < bPoints.Length; i++)
116116
DrawLine(pen, bPoints[i].X, bPoints[i].Y, bPoints[i + 1].X, bPoints[i + 1].Y);
117117
}
@@ -130,6 +130,11 @@ public void DrawLine(Pen pen, float x1, float y1, float x2, float y2)
130130

131131
if (GL_Lines)
132132
{
133+
GL.PushMatrix();
134+
if (DefaultMaterial != null)
135+
DefaultMaterial.SetPass(0);
136+
GL.LoadOrtho();
137+
133138
GL.Begin(GL.LINES);
134139
GL.Color(pen.Color.ToUColor());
135140

@@ -139,6 +144,7 @@ public void DrawLine(Pen pen, float x1, float y1, float x2, float y2)
139144
GL.Vertex3(x2, y2, 0);
140145

141146
GL.End();
147+
GL.PopMatrix();
142148
return;
143149
}
144150

@@ -155,7 +161,7 @@ public void DrawLine(Pen pen, float x1, float y1, float x2, float y2)
155161
float yDiff = y2 - y1;
156162
var angle = Math.Atan2(yDiff, xDiff) * 180.0 / Math.PI;
157163

158-
DrawTexture(System.Windows.Forms.ApplicationBehaviour.DefaultSpriteSmoothLine, x1, y1, (float)Math.Sqrt(xDiff * xDiff + yDiff * yDiff), pen.Width, pen.Color, (float)angle, new PointF());
164+
DrawTexture(System.Windows.Forms.ApplicationBehaviour.Resources.Reserved.Circle, x1, y1, (float)Math.Sqrt(xDiff * xDiff + yDiff * yDiff), pen.Width, pen.Color, (float)angle, new PointF());
159165
return;
160166
}
161167

@@ -424,7 +430,7 @@ public void DrawRectangle(Pen pen, float x, float y, float width, float height)
424430
}
425431
426432
427-
//UnityEngine.Debug.Log(width.ToString() + " " + height.ToString());
433+
//Application.Log(width.ToString() + " " + height.ToString());
428434
//return;
429435
430436
// Batching

System/Windows/Forms/Application.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class Application
3131
internal List<Control> ToCloseControls = new List<Control>();
3232

3333
public static bool Debug { get; set; }
34+
public static float DeltaTime { get { return UnityEngine.Time.deltaTime; } }
3435
public static bool IsDraging { get { return _dragndrop; } }
3536
public static bool IsStandalone
3637
{
@@ -92,7 +93,7 @@ private bool _IsPointInPolygon(List<System.Drawing.Point> polygon, System.Drawin
9293
}
9394
private static Control _ParentContains(Control control, System.Drawing.PointF mousePosition, Control currentControl, ref bool ok)
9495
{
95-
//UnityEngine.Debug.Log(control.Name);
96+
//Application.Log(control.Name);
9697
if (control == null || control.Parent == null) return currentControl;
9798

9899
var parentLocation = control.Parent.PointToScreen(System.Drawing.Point.Zero);
@@ -123,7 +124,7 @@ private static bool _ProcessControl(System.Drawing.PointF mousePosition, Control
123124
}
124125

125126
var client_mpos = control.PointToClient(mousePosition);
126-
//UnityEngine.Debug.Log(control.ToString() + " " + client_mpos.ToString());
127+
//Application.Log(control.ToString() + " " + client_mpos.ToString());
127128

128129
if (ignore_rect || contains)
129130
{
@@ -214,7 +215,7 @@ private static Keys _UKeyToKey(UnityEngine.KeyCode ukey)
214215
case KeyCode.Quote: key = Keys.OemQuotes; break;
215216
}
216217

217-
UnityEngine.Debug.Log(key.ToString() + " mod: " + mod.ToString());
218+
Application.Log(key.ToString() + " mod: " + mod.ToString());
218219

219220
return key;
220221
}
@@ -468,7 +469,7 @@ public void ProccessMouse(System.Drawing.PointF mousePosition)
468469

469470
var clientRect = new System.Drawing.Rectangle(c_location.X, c_location.Y, Controls[i].Width, Controls[i].Height);
470471
var contains = clientRect.Contains(mousePosition);
471-
//UnityEngine.Debug.Log(Controls[i].ToString() + " " + contains.ToString());
472+
//Application.Log(Controls[i].ToString() + " " + contains.ToString());
472473
if (!contains)
473474
{
474475
/*bool dispose = true;
@@ -573,7 +574,7 @@ public void Update()
573574
else
574575
{
575576
#if UNITY_EDITOR
576-
UnityEngine.Debug.LogError("Not found. Da hell. " + ToCloseControls[0].GetType().ToString());
577+
Application.LogError("Not found. Da hell. " + ToCloseControls[0].GetType().ToString());
577578
#endif
578579
}
579580

@@ -595,6 +596,14 @@ internal static void DoDragDrop(object data, DragDropEffects effect, DragDropRen
595596
_dragControlEffects = effect;
596597
_dragRender = render;
597598
}
599+
public static void Log(object message)
600+
{
601+
UnityEngine.Debug.Log(message);
602+
}
603+
public static void LogError(object message)
604+
{
605+
UnityEngine.Debug.LogError(message);
606+
}
598607
public static void NextTabControl(Control control)
599608
{
600609
var controlForm = _GetRootControl(control) as Form;

System/Windows/Forms/ApplicationBehaviour.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static Texture2D DefaultSprite
2828
internal static Texture2D DefaultSpriteSmoothLine { get; private set; }
2929
public static AppResources Resources { get; private set; }
3030

31-
public GUISkin Skin;
31+
public Material LineMaterial;
3232
public AppResources _Resources;
3333
public static bool ShowControlProperties { get; set; }
3434

@@ -39,6 +39,7 @@ public static Texture2D DefaultSprite
3939

4040
private void Awake()
4141
{
42+
System.Drawing.Graphics.DefaultMaterial = LineMaterial;
4243
Resources = _Resources;
4344

4445
_lastWidth = UnityEngine.Screen.width;
@@ -75,9 +76,7 @@ private void OnGUI()
7576
_controller.ProccessMouse(mousePosition);
7677
_controller.ProccessKeys();
7778
}
78-
79-
if (Skin != null)
80-
GUI.skin = Skin;
79+
8180
_controller.Draw();
8281
}
8382
}

System/Windows/Forms/FileDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected string currentFilter
4343

4444
public FileDialog()
4545
{
46-
#if !UNITY_STANDALONE
46+
#if !UNITY_STANDALONE && !UNITY_ANDROID
4747
throw new NotSupportedException();
4848
#endif
4949
BackColor = Color.White;

System/Windows/Forms/ListBox.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public override int SelectedIndex
6363
get { return _selectedIndex; }
6464
set
6565
{
66-
bool changed = _selectedIndex != value;
66+
bool changed = _selectedIndex != value && value != -1;
6767
_selectedIndex = value;
68-
if (changed) SelectedIndexChanged(this, null);
68+
if (changed) OnSelectedIndexChanged(EventArgs.Empty);
6969
}
7070
}
7171
public object SelectedItem
@@ -246,6 +246,12 @@ protected override void OnResize(Point delta)
246246

247247
_visibleItems = Height / ItemHeight;
248248
}
249+
protected override void OnSelectedIndexChanged(EventArgs e)
250+
{
251+
base.OnSelectedIndexChanged(e);
252+
253+
SelectedIndexChanged(this, e);
254+
}
249255
protected override void OnLatePaint(PaintEventArgs e)
250256
{
251257
base.OnLatePaint(e);

System/Windows/Forms/TreeNodeCollection.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,7 @@ public virtual void Clear()
168168
{
169169
items.Clear();
170170
if (owner.TreeView != null)
171-
{
172-
owner.TreeView.ScrollIndex = 0;
173171
owner.TreeView.Refresh();
174-
}
175172
}
176173
public bool Contains(TreeNode node)
177174
{

System/Windows/Forms/TreeView.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ public override void Refresh()
422422

423423
ProccesNode(root);
424424
_UpdateScrollList();
425+
_FixScrollIndex();
425426
}
426427

427428
public void CollapseAll()
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace System.Windows.Forms
7+
{
8+
public static class KeyHelper
9+
{
10+
public static UnityEngine.KeyCode ToKey(this UnityEngine.EventModifiers modifier, bool returnLeftButton = true)
11+
{
12+
switch (modifier)
13+
{
14+
case UnityEngine.EventModifiers.Alt:
15+
return returnLeftButton ? UnityEngine.KeyCode.LeftAlt : UnityEngine.KeyCode.RightAlt;
16+
case UnityEngine.EventModifiers.CapsLock:
17+
return UnityEngine.KeyCode.CapsLock;
18+
case UnityEngine.EventModifiers.Command:
19+
return returnLeftButton ? UnityEngine.KeyCode.LeftCommand : UnityEngine.KeyCode.RightCommand;
20+
case UnityEngine.EventModifiers.Control:
21+
return returnLeftButton ? UnityEngine.KeyCode.LeftControl : UnityEngine.KeyCode.RightControl;
22+
case UnityEngine.EventModifiers.Numeric:
23+
return UnityEngine.KeyCode.Numlock;
24+
case UnityEngine.EventModifiers.Shift:
25+
return returnLeftButton ? UnityEngine.KeyCode.LeftShift : UnityEngine.KeyCode.RightShift;
26+
27+
default:
28+
return UnityEngine.KeyCode.None;
29+
}
30+
}
31+
public static UnityEngine.EventModifiers ToModifier(this UnityEngine.KeyCode key)
32+
{
33+
switch (key)
34+
{
35+
case UnityEngine.KeyCode.LeftAlt:
36+
case UnityEngine.KeyCode.RightAlt:
37+
return UnityEngine.EventModifiers.Alt;
38+
39+
case UnityEngine.KeyCode.CapsLock:
40+
return UnityEngine.EventModifiers.CapsLock;
41+
42+
case UnityEngine.KeyCode.LeftCommand:
43+
case UnityEngine.KeyCode.RightCommand:
44+
return UnityEngine.EventModifiers.Command;
45+
46+
case UnityEngine.KeyCode.LeftControl:
47+
case UnityEngine.KeyCode.RightControl:
48+
return UnityEngine.EventModifiers.Control;
49+
50+
case UnityEngine.KeyCode.Numlock:
51+
return UnityEngine.EventModifiers.Numeric;
52+
53+
case UnityEngine.KeyCode.LeftShift:
54+
case UnityEngine.KeyCode.RightShift:
55+
return UnityEngine.EventModifiers.Shift;
56+
57+
default:
58+
return UnityEngine.EventModifiers.None;
59+
}
60+
}
61+
}
62+
}

System/Windows/Forms/Utility/MathHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static float DistanceF(PointF p1, PointF p2)
6666
/// <returns></returns>
6767
public static float FloatLerp(float from_value, float to_value, float speed)
6868
{
69-
return from_value + (to_value - from_value) * speed * UnityEngine.Time.deltaTime;
69+
return from_value + (to_value - from_value) * speed * Application.DeltaTime;
7070
}
7171
public static float Hermite(float value1, float tangent1, float value2, float tangent2, float amount)
7272
{
@@ -108,7 +108,7 @@ public static float SmoothStep(float value1, float value2, float amount)
108108
}
109109
public static float Step(float from_value, float to_value, float speed)
110110
{
111-
float uSpeed = speed * UnityEngine.Time.deltaTime;
111+
float uSpeed = speed * Application.DeltaTime;
112112
if (Math.Abs(from_value - to_value) < uSpeed) return to_value;
113113

114114
if (from_value < to_value)

0 commit comments

Comments
 (0)