Skip to content

Commit 9ea916a

Browse files
committed
added Layout event to Control;
moved more Unity dependencies away from SWF;
1 parent 25bffde commit 9ea916a

File tree

14 files changed

+225
-166
lines changed

14 files changed

+225
-166
lines changed

Core/API/IApiInput.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace System.Drawing.API
2+
{
3+
public interface IApiInput
4+
{
5+
bool CursorVisible { get; set; }
6+
}
7+
}

Utility/ApiHolder.cs renamed to Core/ApiHolder.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
using System.Drawing;
44
using System.Drawing.API;
55

6-
using Unity.API;
7-
86
/// <summary>
97
/// Replace with your own implementation if needed.
108
/// </summary>
119
public static class ApiHolder
1210
{
13-
public static IApiGraphics Graphics = new UnityGdi();
14-
public static IApiSystem System = new UnitySystem();
15-
public static IApiTiming Timing = new UnityTiming();
11+
public static IApiGraphics Graphics;
12+
public static IApiInput Input;
13+
public static IApiSystem System;
14+
public static IApiTiming Timing;
1615
}
1716
}

Examples/FormExamples.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ public FormExamples()
8282
// uwfSizeGripRenderer.BringToFront();
8383
}
8484

85+
public void SetPanel(BaseExamplePanel panel)
86+
{
87+
if (currentPanel != null && currentPanel.IsDisposed == false)
88+
currentPanel.Dispose();
89+
90+
currentPanel = panel;
91+
currentPanel.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
92+
currentPanel.Location = new Point(treeView.Location.X + treeView.Width, uwfHeaderHeight);
93+
currentPanel.Height = Height - uwfHeaderHeight - 16; // We don't want to hide SizeGripRenderer with scrollbars.
94+
currentPanel.Width = Width - treeView.Width;
95+
96+
Controls.Add(currentPanel);
97+
98+
currentPanel.Initialize();
99+
}
100+
85101
private static void AddNode(TreeNode parent, string text, object tag)
86102
{
87103
var node = new TreeNode(text);
@@ -102,18 +118,7 @@ private void TreeViewOnNodeMouseClick(object sender, TreeNodeMouseClickEventArgs
102118
if (panel == null)
103119
return;
104120

105-
if (currentPanel != null && currentPanel.IsDisposed == false)
106-
currentPanel.Dispose();
107-
108-
currentPanel = panel;
109-
currentPanel.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
110-
currentPanel.Location = new Point(treeView.Location.X + treeView.Width, uwfHeaderHeight);
111-
currentPanel.Height = Height - uwfHeaderHeight - 16; // We don't want to hide SizeGripRenderer with scrollbars.
112-
currentPanel.Width = Width - treeView.Width;
113-
114-
Controls.Add(currentPanel);
115-
116-
currentPanel.Initialize();
121+
SetPanel(panel);
117122
}
118123
}
119124
}

System/Windows/Forms/Application.cs

Lines changed: 22 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ public class Application
3737
private readonly PaintEventArgs paintEventArgs;
3838
private float mousePositionX;
3939
private float mousePositionY;
40-
private MouseEvents userMouseEvent;
41-
private MouseEventArgs userMouseArgs;
42-
40+
4341
public Application()
4442
{
4543
TabSwitching = true;
@@ -157,107 +155,30 @@ public void ProccessKeys(KeyEventArgs args, KeyEvents keyEventType)
157155
if (keyEventType == KeyEvents.Down)
158156
currentKeyDown = args.KeyCode;
159157
}
160-
public void ProccessMouse(float mouseX, float mouseY)
158+
public void ProccessMouse(MouseEvents mE, float mX, float mY, MouseButtons mButton, int clicks, int delta)
161159
{
162160
if (scaleX != 1f || scaleY != 1f)
163161
{
164-
mouseX /= scaleX;
165-
mouseY /= scaleY;
162+
mX /= scaleX;
163+
mY /= scaleY;
166164
}
167165

168-
mouseEvent = MouseEvents.None;
169-
mouseButton = MouseButtons.None;
166+
mouseEvent = mE;
167+
mouseButton = mButton;
168+
mouseWheelDelta = delta;
170169

171-
mousePositionChanged = mousePositionX != mouseX || mousePositionY != mouseY;
170+
mousePositionChanged = mousePositionX != mX || mousePositionY != mY;
172171
if (mousePositionChanged)
173172
updateHoveredControl = true;
174173

175-
mousePositionX = mouseX;
176-
mousePositionY = mouseY;
177-
178-
#region Set events.
179-
180-
int eventButton = -1;
181-
int eventClicks = 0;
182-
float eventDelta = 0;
183-
EventType eventType = EventType.Ignore;
184-
185-
if (userMouseArgs != null)
186-
{
187-
switch (userMouseArgs.Button)
188-
{
189-
case MouseButtons.Left: eventButton = 0; break;
190-
case MouseButtons.Right: eventButton = 1; break;
191-
case MouseButtons.Middle: eventButton = 2; break;
192-
}
193-
eventClicks = userMouseArgs.Clicks;
194-
eventDelta = userMouseArgs.Delta;
195-
switch (userMouseEvent)
196-
{
197-
case MouseEvents.Down: eventType = EventType.MouseDown; break;
198-
case MouseEvents.Up: eventType = EventType.MouseUp; break;
199-
case MouseEvents.Wheel: eventType = EventType.ScrollWheel; break;
200-
}
201-
userMouseArgs = null;
202-
}
203-
else
204-
{
205-
eventButton = Event.current.button;
206-
eventClicks = Event.current.clickCount;
207-
eventDelta = Event.current.delta.y;
208-
eventType = Event.current.type;
209-
}
210-
211-
switch (eventType)
212-
{
213-
case EventType.MouseDown:
214-
switch (eventButton)
215-
{
216-
case 0:
217-
mouseButton = MouseButtons.Left;
218-
mouseEvent = MouseEvents.Down;
219-
if (eventClicks > 1)
220-
mouseEvent = MouseEvents.DoubleClick;
221-
break;
222-
case 1:
223-
mouseButton = MouseButtons.Right;
224-
mouseEvent = MouseEvents.Down;
225-
break;
226-
case 2:
227-
mouseButton = MouseButtons.Middle;
228-
mouseEvent = MouseEvents.Down;
229-
break;
230-
}
231-
break;
232-
case EventType.MouseUp:
233-
switch (eventButton)
234-
{
235-
case 0:
236-
mouseButton = MouseButtons.Left;
237-
mouseEvent = MouseEvents.Up;
238-
break;
239-
case 1:
240-
mouseButton = MouseButtons.Right;
241-
mouseEvent = MouseEvents.Up;
242-
break;
243-
case 2:
244-
mouseButton = MouseButtons.Middle;
245-
mouseEvent = MouseEvents.Up;
246-
break;
247-
}
248-
break;
249-
case EventType.ScrollWheel:
250-
mouseEvent = MouseEvents.Wheel;
251-
mouseWheelDelta = eventDelta;
252-
break;
253-
}
254-
255-
#endregion
256-
174+
mousePositionX = mX;
175+
mousePositionY = mY;
176+
257177
//if (_mouseLastClickControl != null && _mouseEvent == MouseEvents.None && _mouseMovePosition != mousePosition)
258178
// _ProcessControl(mousePosition, _mouseLastClickControl, true);
259179

260-
if (mouseEvent == MouseEvents.None && !mousePositionChanged) return;
180+
if (mE == MouseEvents.None && !mousePositionChanged)
181+
return;
261182

262183
// Dispose context first.
263184
for (int i = Contexts.Count - 1; i >= 0; i--) // We want to dispose child context first.
@@ -266,53 +187,43 @@ public void ProccessMouse(float mouseX, float mouseY)
266187
if (!contextControl.uwfContext) continue;
267188

268189
if (Contains(contextControl, hoveredControl)) continue;
269-
if (mouseEvent != MouseEvents.Down) continue;
190+
if (mE != MouseEvents.Down) continue;
270191

271192
contextControl.Dispose();
272193
}
273194

274-
if (hoveredControl == null && mouseEvent == MouseEvents.Up)
195+
if (hoveredControl == null && mE == MouseEvents.Up)
275196
{
276197
dragndrop = false;
277198
dragData = null;
278199
dragRender = null;
279200
}
280201

281202
if (hoveredControl != null)
282-
_ProcessControl(new PointF(mouseX, mouseY), hoveredControl, false);
203+
_ProcessControl(new PointF(mX, mY), hoveredControl, false);
283204

284-
if (mouseEvent == MouseEvents.Down)
205+
if (mE == MouseEvents.Down)
285206
{
286-
var downArgs = new MouseEventArgs(mouseButton, 1, (int)mouseX, (int)mouseY, 0);
207+
var downArgs = new MouseEventArgs(mouseButton, clicks, (int) mX, (int) mY, delta);
287208
MouseHook.RaiseMouseDown(hoveredControl, downArgs);
288209
}
289210

290-
if (mouseEvent == MouseEvents.Up)
211+
if (mE == MouseEvents.Up)
291212
{
292-
var upArgs = new MouseEventArgs(mouseButton, 1, (int)mouseX, (int)mouseY, 0);
213+
var upArgs = new MouseEventArgs(mouseButton, clicks, (int) mX, (int) mY, delta);
293214
MouseHook.RaiseMouseUp(hoveredControl, upArgs);
294215
}
295216
}
296-
public void ProccessMouse(PointF mousePosition)
297-
{
298-
ProccessMouse(mousePosition.X, mousePosition.Y);
299-
}
300217
public void RaiseMouseEvent(MouseEvents mEv, MouseEventArgs mArgs)
301218
{
302-
userMouseEvent = mEv;
303-
userMouseArgs = mArgs;
304-
305-
ProccessMouse(new Drawing.PointF(mArgs.X, mArgs.Y));
219+
if (mArgs != null)
220+
ProccessMouse(mEv, mArgs.X, mArgs.Y, mArgs.Button, mArgs.Clicks, mArgs.Delta);
306221
}
307222
/// <summary>
308223
/// Redrawing the whole screen.
309224
/// </summary>
310225
public void Redraw()
311226
{
312-
// Scale if needed.
313-
if (scaleX != 1f || scaleY != 1f)
314-
UnityEngine.GUI.matrix = UnityEngine.Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(0, Vector3.up), new Vector3(scaleX, scaleY, 1));
315-
316227
paintEventArgs.Graphics.Clear(System.Drawing.Color.White);
317228

318229
for (int i = 0; i < Forms.Count; i++)

System/Windows/Forms/Control.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public Control()
8484
public event KeyEventHandler KeyDown;
8585
public event KeyPressEventHandler KeyPress;
8686
public event KeyEventHandler KeyUp;
87+
public event LayoutEventHandler Layout;
8788
public event EventHandler LocationChanged;
8889
public event EventHandler LostFocus;
8990
public event MouseEventHandler MouseClick;
@@ -350,7 +351,7 @@ public virtual void Invalidate(Rectangle rc, bool invalidateChildren)
350351
}
351352
public void PerformLayout()
352353
{
353-
PerformLayout(null);
354+
OnLayout(null);
354355
}
355356
public Point PointToClient(Point p)
356357
{
@@ -492,9 +493,9 @@ internal void PaintBackground(PaintEventArgs e, Rectangle rectangle, Color backC
492493
else if (backColor.A > 0) // Fill back.
493494
PaintBackColor(e, rectangle, backColor);
494495
}
495-
internal void PerformLayout(object args)
496+
internal void PerformLayout(Control affectedControl, string affectedProperty)
496497
{
497-
OnLayout(args);
498+
OnLayout(new LayoutEventArgs(affectedControl, affectedProperty));
498499
}
499500
internal virtual void RaiseOnDragDrop(DragEventArgs drgevent)
500501
{
@@ -767,8 +768,11 @@ protected virtual void OnKeyUp(KeyEventArgs e)
767768
if (keyUp != null)
768769
keyUp(this, e);
769770
}
770-
protected virtual void OnLayout(object levent)
771+
protected virtual void OnLayout(LayoutEventArgs e)
771772
{
773+
var handler = Layout;
774+
if (handler != null)
775+
handler(this, e);
772776
}
773777
protected virtual void OnLocationChanged(EventArgs e)
774778
{

System/Windows/Forms/Cursor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static Cursor Current
3535
if (current == null)
3636
current = Cursors.Default;
3737

38-
UnityEngine.Cursor.visible = IsVisible;
38+
ApiHolder.Input.CursorVisible = IsVisible;
3939
}
4040
}
4141
public static Point Position
@@ -55,7 +55,7 @@ internal static Cursor CurrentSystem
5555

5656
currentSystem = value;
5757

58-
UnityEngine.Cursor.visible = IsVisible;
58+
ApiHolder.Input.CursorVisible = IsVisible;
5959
}
6060
}
6161
internal static bool IsVisible

System/Windows/Forms/Cursors.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public static class Cursors
66
{
7-
private static AppGdiImages.CursorImages images = Unity.API.UnityWinForms.GdiImages.Cursors;
7+
internal static AppGdiImages.CursorImages images;
88

99
private static Cursor defaultCursor;
1010
private static Cursor sizeAll;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace System.Windows.Forms
2+
{
3+
using System.ComponentModel;
4+
5+
public class LayoutEventArgs : EventArgs
6+
{
7+
private readonly IComponent affectedComponent;
8+
private readonly string affectedProperty;
9+
10+
public LayoutEventArgs(IComponent affectedComponent, string affectedProperty)
11+
{
12+
this.affectedComponent = affectedComponent;
13+
this.affectedProperty = affectedProperty;
14+
}
15+
public LayoutEventArgs(Control affectedControl, string affectedProperty) : this((IComponent)affectedControl, affectedProperty)
16+
{
17+
}
18+
19+
public IComponent AffectedComponent
20+
{
21+
get
22+
{
23+
return this.affectedComponent;
24+
}
25+
}
26+
public Control AffectedControl
27+
{
28+
get
29+
{
30+
return this.affectedComponent as Control;
31+
}
32+
}
33+
public string AffectedProperty
34+
{
35+
get
36+
{
37+
return this.affectedProperty;
38+
}
39+
}
40+
}
41+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace System.Windows.Forms
2+
{
3+
public delegate void LayoutEventHandler(object sender, LayoutEventArgs e);
4+
}

System/Windows/Forms/ScrollableControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ protected bool GetScrollState(int bit)
163163
{
164164
return (bit & scrollState) == bit;
165165
}
166-
protected override void OnLayout(object levent)
166+
protected override void OnLayout(LayoutEventArgs e)
167167
{
168-
base.OnLayout(levent);
168+
base.OnLayout(e);
169169

170170
UpdateScrolls();
171171
}

0 commit comments

Comments
 (0)