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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ShiftOS.Engine.Scripting;
using System.Drawing;
using ShiftOS.Engine;
using System.Windows.Forms;
using ShiftOS.WinForms.Tools;
namespace ShiftOS.WinForms
{
[Exposed("gui")]
public class GUIFunctions
{
public dynamic color(int r, int g, int b)
{
return Color.FromArgb(r, g, b);
}
public dynamic color(string name)
{
return Color.FromName(name);
}
public dynamic point(int x, int y)
{
return new Point(x, y);
}
public dynamic size(int w, int h)
{
return new Size(w, h);
}
public dynamic font(string name, float size, bool bold, bool italic, bool strikethrough, bool underline)
{
FontStyle fs = FontStyle.Regular;
if (bold)
fs = fs | FontStyle.Bold;
if (italic)
fs = fs | FontStyle.Italic;
if (underline)
fs = fs | FontStyle.Underline;
if (strikethrough)
fs = fs | FontStyle.Strikeout;
return new Font(name, size, fs);
}
public dynamic createWindow(string name, dynamic size)
{
var win = new Window();
win.Size = size;
AppearanceManager.SetupWindow(win);
return win;
}
public dynamic panel(Control parent, Point loc, Size size)
{
var pnl = new Panel();
pnl.Location = loc;
pnl.Size = size;
parent.Controls.Add(pnl);
pnl.Show();
return pnl;
}
public DockStyle dock(string type)
{
DockStyle d = DockStyle.None;
switch (type.ToLower())
{
case "top":
d = DockStyle.Top;
break;
case "bottom":
d = DockStyle.Bottom;
break;
case "left":
d = DockStyle.Left;
break;
case "right":
d = DockStyle.Right;
break;
case "fill":
d = DockStyle.Fill;
break;
}
return d;
}
public AnchorStyles anchor(bool top, bool left, bool bottom, bool right)
{
AnchorStyles a = AnchorStyles.None;
if (top)
a = a | AnchorStyles.Top;
if (left)
a = a | AnchorStyles.Left;
if (bottom)
a = a | AnchorStyles.Bottom;
if (right)
a = a | AnchorStyles.Right;
return a;
}
public dynamic flow(Control parent, Point loc, Size size)
{
var pnl = new FlowLayoutPanel();
pnl.Size = size;
pnl.Location = loc;
parent.Controls.Add(pnl);
pnl.Show();
return pnl;
}
private Control addToParent(Control parent, Point loc, Size size, Control newControl)
{
newControl.Size = size;
newControl.Location = loc;
parent.Controls.Add(newControl);
newControl.Show();
ControlManager.SetupControls(parent);
return newControl;
}
public dynamic button(Control parent, Point loc, Size size, string text)
{
var btn = new Button();
btn.Text = text;
btn.AutoSize = false;
return addToParent(parent, loc, size, btn);
}
public dynamic label(Control parent, Point loc, Size size, string text)
{
var lbl = new Label();
lbl.Text = text;
lbl.AutoSize = false;
return addToParent(parent, loc, size, lbl);
}
}
[Exposed("clr")]
public class CommonLanguageRuntimeInterop
{
public dynamic construct(Type type, dynamic[] ctorParams)
{
return Activator.CreateInstance(type, ctorParams);
}
public dynamic typeOf(string typeName)
{
return Type.GetType(typeName);
}
public void throwException(string message)
{
throw new UserException(message);
}
}
public class UserException : Exception
{
public UserException(string message) :base("User threw exception using clr:throwException().\r\n\r\n" + message)
{
}
}
}
|