-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathControlContainer.cs
124 lines (105 loc) · 3.64 KB
/
ControlContainer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System.Drawing;
using System.Windows.Forms;
using AlphaTab.Platform;
namespace AlphaTab.WinForms
{
internal class ControlContainer : IContainer
{
public Control Control { get; }
public ControlContainer(Control control)
{
Control = control;
Resize = new DelegatedEventEmitter(
value => { Control.Resize += (sender, args) => value(); },
value => { }
);
MouseDown = new DelegatedEventEmitter<IMouseEventArgs>(
value =>
{
Control.MouseDown += (sender, args) => value(new WinFormsMouseEventArgs(Control, args));
},
value => { }
);
MouseMove = new DelegatedEventEmitter<IMouseEventArgs>(
value =>
{
Control.MouseMove += (sender, args) => value(new WinFormsMouseEventArgs(Control, args));
},
value => { }
);
MouseUp = new DelegatedEventEmitter<IMouseEventArgs>(
value =>
{
Control.MouseUp += (sender, args) => value(new WinFormsMouseEventArgs(Control, args));
},
value => { }
);
}
public double Top
{
get => Control.Top;
set => Control.Top = (int)value;
}
public double Left
{
get => Control.Left;
set => Control.Left = (int)value;
}
public double Width
{
get => Control.ClientSize.Width - Control.Padding.Horizontal;
set => Control.Width = (int)value + Control.Padding.Horizontal;
}
public double Height
{
get => Control.ClientSize.Height - Control.Padding.Vertical;
set => Control.Height = (int)value + Control.Padding.Vertical;
}
public bool IsVisible => Control.Visible && Control.Width > 0;
public double ScrollLeft
{
get => Control is ScrollableControl scroll ? scroll.AutoScrollPosition.X : 0;
set
{
if (Control is ScrollableControl scroll)
{
scroll.AutoScrollPosition = new Point((int)value, scroll.AutoScrollPosition.Y);
}
}
}
public double ScrollTop
{
get => Control is ScrollableControl scroll ? scroll.VerticalScroll.Value : 0;
set
{
if (Control is ScrollableControl scroll)
{
scroll.AutoScrollPosition = new Point(scroll.AutoScrollPosition.X, (int)value);
}
}
}
public void AppendChild(IContainer child)
{
Control.Controls.Add(((ControlContainer)child).Control);
}
public void StopAnimation()
{
//Control.BeginAnimation(Canvas.LeftProperty, null);
}
public void TransitionToX(double duration, double x)
{
// TODO: Animation
Control.Left = (int)x;
//Control.BeginAnimation(Canvas.LeftProperty,
// new DoubleAnimation(x, new Duration(TimeSpan.FromMilliseconds(duration))));
}
public void Clear()
{
Control.Controls.Clear();
}
public IEventEmitter Resize { get; set; }
public IEventEmitterOfT<IMouseEventArgs> MouseDown { get; set; }
public IEventEmitterOfT<IMouseEventArgs> MouseMove { get; set; }
public IEventEmitterOfT<IMouseEventArgs> MouseUp { get; set; }
}
}