Skip to content

Commit

Permalink
little update
Browse files Browse the repository at this point in the history
  • Loading branch information
Meragon committed Jul 20, 2016
1 parent a45d327 commit a48c482
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 24 deletions.
20 changes: 13 additions & 7 deletions System/Drawing/Graphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal void GroupEnd()
_groupControls.RemoveAt(_groupControls.Count - 1);
}

private PointF[] GetBezierApproximation(PointF[] controlPoints, int outputSegmentCount)
public static PointF[] GetBezierApproximation(PointF[] controlPoints, int outputSegmentCount)
{
PointF[] points = new PointF[outputSegmentCount + 1];
for (int i = 0; i <= outputSegmentCount; i++)
Expand All @@ -43,7 +43,7 @@ private PointF[] GetBezierApproximation(PointF[] controlPoints, int outputSegmen
}
return points;
}
private PointF GetBezierPoint(float t, PointF[] controlPoints, int index, int count)
private static PointF GetBezierPoint(float t, PointF[] controlPoints, int index, int count)
{
if (count == 1)
return controlPoints[index];
Expand All @@ -64,7 +64,7 @@ private static int GUI_SetLabelFont(Font font)
else
{
GUI.skin.label.font = null;
UnityEngine.Debug.LogWarning(font.Name);
UnityEngine.Debug.Log(font.Name);
}
}
else
Expand Down Expand Up @@ -102,7 +102,7 @@ public void Dispose()
public void Clear(System.Drawing.Color color)
{
}
public void DrawCurve(Pen pen, PointF[] points) // very slow.
public void DrawCurve(Pen pen, PointF[] points, int segments = 32) // very slow.
{
if (points == null || points.Length <= 1) return;
if (points.Length == 2)
Expand All @@ -111,7 +111,7 @@ public void DrawCurve(Pen pen, PointF[] points) // very slow.
return;
}

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

if (GL_Lines)
{
GL.PushMatrix();
if (DefaultMaterial != null)
DefaultMaterial.SetPass(0);
GL.LoadOrtho();

GL.Begin(GL.LINES);
GL.Color(pen.Color.ToUColor());

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

GL.End();
GL.PopMatrix();
return;
}

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

DrawTexture(System.Windows.Forms.ApplicationBehaviour.DefaultSpriteSmoothLine, x1, y1, (float)Math.Sqrt(xDiff * xDiff + yDiff * yDiff), pen.Width, pen.Color, (float)angle, new PointF());
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());
return;
}

Expand Down Expand Up @@ -424,7 +430,7 @@ public void DrawRectangle(Pen pen, float x, float y, float width, float height)
}
//UnityEngine.Debug.Log(width.ToString() + " " + height.ToString());
//Application.Log(width.ToString() + " " + height.ToString());
//return;
// Batching
Expand Down
19 changes: 14 additions & 5 deletions System/Windows/Forms/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Application
internal List<Control> ToCloseControls = new List<Control>();

public static bool Debug { get; set; }
public static float DeltaTime { get { return UnityEngine.Time.deltaTime; } }
public static bool IsDraging { get { return _dragndrop; } }
public static bool IsStandalone
{
Expand Down Expand Up @@ -92,7 +93,7 @@ private bool _IsPointInPolygon(List<System.Drawing.Point> polygon, System.Drawin
}
private static Control _ParentContains(Control control, System.Drawing.PointF mousePosition, Control currentControl, ref bool ok)
{
//UnityEngine.Debug.Log(control.Name);
//Application.Log(control.Name);
if (control == null || control.Parent == null) return currentControl;

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

var client_mpos = control.PointToClient(mousePosition);
//UnityEngine.Debug.Log(control.ToString() + " " + client_mpos.ToString());
//Application.Log(control.ToString() + " " + client_mpos.ToString());

if (ignore_rect || contains)
{
Expand Down Expand Up @@ -214,7 +215,7 @@ private static Keys _UKeyToKey(UnityEngine.KeyCode ukey)
case KeyCode.Quote: key = Keys.OemQuotes; break;
}

UnityEngine.Debug.Log(key.ToString() + " mod: " + mod.ToString());
Application.Log(key.ToString() + " mod: " + mod.ToString());

return key;
}
Expand Down Expand Up @@ -468,7 +469,7 @@ public void ProccessMouse(System.Drawing.PointF mousePosition)

var clientRect = new System.Drawing.Rectangle(c_location.X, c_location.Y, Controls[i].Width, Controls[i].Height);
var contains = clientRect.Contains(mousePosition);
//UnityEngine.Debug.Log(Controls[i].ToString() + " " + contains.ToString());
//Application.Log(Controls[i].ToString() + " " + contains.ToString());
if (!contains)
{
/*bool dispose = true;
Expand Down Expand Up @@ -573,7 +574,7 @@ public void Update()
else
{
#if UNITY_EDITOR
UnityEngine.Debug.LogError("Not found. Da hell. " + ToCloseControls[0].GetType().ToString());
Application.LogError("Not found. Da hell. " + ToCloseControls[0].GetType().ToString());
#endif
}

Expand All @@ -595,6 +596,14 @@ internal static void DoDragDrop(object data, DragDropEffects effect, DragDropRen
_dragControlEffects = effect;
_dragRender = render;
}
public static void Log(object message)
{
UnityEngine.Debug.Log(message);
}
public static void LogError(object message)
{
UnityEngine.Debug.LogError(message);
}
public static void NextTabControl(Control control)
{
var controlForm = _GetRootControl(control) as Form;
Expand Down
7 changes: 3 additions & 4 deletions System/Windows/Forms/ApplicationBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static Texture2D DefaultSprite
internal static Texture2D DefaultSpriteSmoothLine { get; private set; }
public static AppResources Resources { get; private set; }

public GUISkin Skin;
public Material LineMaterial;
public AppResources _Resources;
public static bool ShowControlProperties { get; set; }

Expand All @@ -39,6 +39,7 @@ public static Texture2D DefaultSprite

private void Awake()
{
System.Drawing.Graphics.DefaultMaterial = LineMaterial;
Resources = _Resources;

_lastWidth = UnityEngine.Screen.width;
Expand Down Expand Up @@ -75,9 +76,7 @@ private void OnGUI()
_controller.ProccessMouse(mousePosition);
_controller.ProccessKeys();
}

if (Skin != null)
GUI.skin = Skin;

_controller.Draw();
}
}
Expand Down
2 changes: 1 addition & 1 deletion System/Windows/Forms/FileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected string currentFilter

public FileDialog()
{
#if !UNITY_STANDALONE
#if !UNITY_STANDALONE && !UNITY_ANDROID
throw new NotSupportedException();
#endif
BackColor = Color.White;
Expand Down
10 changes: 8 additions & 2 deletions System/Windows/Forms/ListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public override int SelectedIndex
get { return _selectedIndex; }
set
{
bool changed = _selectedIndex != value;
bool changed = _selectedIndex != value && value != -1;
_selectedIndex = value;
if (changed) SelectedIndexChanged(this, null);
if (changed) OnSelectedIndexChanged(EventArgs.Empty);
}
}
public object SelectedItem
Expand Down Expand Up @@ -246,6 +246,12 @@ protected override void OnResize(Point delta)

_visibleItems = Height / ItemHeight;
}
protected override void OnSelectedIndexChanged(EventArgs e)
{
base.OnSelectedIndexChanged(e);

SelectedIndexChanged(this, e);
}
protected override void OnLatePaint(PaintEventArgs e)
{
base.OnLatePaint(e);
Expand Down
3 changes: 0 additions & 3 deletions System/Windows/Forms/TreeNodeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@ public virtual void Clear()
{
items.Clear();
if (owner.TreeView != null)
{
owner.TreeView.ScrollIndex = 0;
owner.TreeView.Refresh();
}
}
public bool Contains(TreeNode node)
{
Expand Down
1 change: 1 addition & 0 deletions System/Windows/Forms/TreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ public override void Refresh()

ProccesNode(root);
_UpdateScrollList();
_FixScrollIndex();
}

public void CollapseAll()
Expand Down
62 changes: 62 additions & 0 deletions System/Windows/Forms/Utility/KeyHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
public static class KeyHelper
{
public static UnityEngine.KeyCode ToKey(this UnityEngine.EventModifiers modifier, bool returnLeftButton = true)
{
switch (modifier)
{
case UnityEngine.EventModifiers.Alt:
return returnLeftButton ? UnityEngine.KeyCode.LeftAlt : UnityEngine.KeyCode.RightAlt;
case UnityEngine.EventModifiers.CapsLock:
return UnityEngine.KeyCode.CapsLock;
case UnityEngine.EventModifiers.Command:
return returnLeftButton ? UnityEngine.KeyCode.LeftCommand : UnityEngine.KeyCode.RightCommand;
case UnityEngine.EventModifiers.Control:
return returnLeftButton ? UnityEngine.KeyCode.LeftControl : UnityEngine.KeyCode.RightControl;
case UnityEngine.EventModifiers.Numeric:
return UnityEngine.KeyCode.Numlock;
case UnityEngine.EventModifiers.Shift:
return returnLeftButton ? UnityEngine.KeyCode.LeftShift : UnityEngine.KeyCode.RightShift;

default:
return UnityEngine.KeyCode.None;
}
}
public static UnityEngine.EventModifiers ToModifier(this UnityEngine.KeyCode key)
{
switch (key)
{
case UnityEngine.KeyCode.LeftAlt:
case UnityEngine.KeyCode.RightAlt:
return UnityEngine.EventModifiers.Alt;

case UnityEngine.KeyCode.CapsLock:
return UnityEngine.EventModifiers.CapsLock;

case UnityEngine.KeyCode.LeftCommand:
case UnityEngine.KeyCode.RightCommand:
return UnityEngine.EventModifiers.Command;

case UnityEngine.KeyCode.LeftControl:
case UnityEngine.KeyCode.RightControl:
return UnityEngine.EventModifiers.Control;

case UnityEngine.KeyCode.Numlock:
return UnityEngine.EventModifiers.Numeric;

case UnityEngine.KeyCode.LeftShift:
case UnityEngine.KeyCode.RightShift:
return UnityEngine.EventModifiers.Shift;

default:
return UnityEngine.EventModifiers.None;
}
}
}
}
4 changes: 2 additions & 2 deletions System/Windows/Forms/Utility/MathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static float DistanceF(PointF p1, PointF p2)
/// <returns></returns>
public static float FloatLerp(float from_value, float to_value, float speed)
{
return from_value + (to_value - from_value) * speed * UnityEngine.Time.deltaTime;
return from_value + (to_value - from_value) * speed * Application.DeltaTime;
}
public static float Hermite(float value1, float tangent1, float value2, float tangent2, float amount)
{
Expand Down Expand Up @@ -108,7 +108,7 @@ public static float SmoothStep(float value1, float value2, float amount)
}
public static float Step(float from_value, float to_value, float speed)
{
float uSpeed = speed * UnityEngine.Time.deltaTime;
float uSpeed = speed * Application.DeltaTime;
if (Math.Abs(from_value - to_value) < uSpeed) return to_value;

if (from_value < to_value)
Expand Down

0 comments on commit a48c482

Please sign in to comment.