-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form.sb
236 lines (227 loc) · 6.93 KB
/
Form.sb
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
'--
' Form
' Version 0.51b
' Copyright © 2017 Nonki Takahashi. The MIT License.
' Last update 2017-04-30
' Challenge 2016-01/02
' Repository https://github.com/nonkit/Form.git
' Program ID KMT677-5
formName = "Form.frm.sb"
grid = "False"
DrawForm()
' show form array
buf = ""
For i = 1 To nForm
buf = buf + "form[" + i + "]: " + form[i] + CR + LF
EndFor
Controls.SetTextBoxText(frm["obj"], buf)
While "True"
If buttonClicked Then
frm = form[id["filename"]]
formName = Controls.GetTextBoxText(frm["obj"])
GraphicsWindow.Clear()
DrawForm()
buttonClicked = "False"
Else
Program.Delay(200)
EndIf
EndWhile
Sub DrawForm
'--
' Draw form
Form_GetForm()
Form_ShowForm()
If grid Then
gap = 10
color = "#999999"
DrawGrids()
gap = 100
color = "#666666"
DrawGrids()
EndIf
EndSub
Sub DrawGrids
'--
' Draw grids
' param gap
' param color
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = color
For y = gap To gh Step gap
GraphicsWindow.DrawLine(0, y, gw, y)
EndFor
For x = gap To gw Step gap
GraphicsWindow.DrawLine(x, 0, x, gh)
EndFor
EndSub
Sub Form_ShowForm
'--
' Form | Show form
' param form - array of the form
' param nForm - number of objects in the form
' return gw - width of the graphics window
' return gh - height of the graphics window
' return id - array of ids in the form
For i = 1 To nForm
frm = form[i]
If frm["id"] <> "" Then
id[frm["id"]] = i
EndIf
If frm["func"] = "form" Then
' func=form;bg=LightGray;gx=10;gy=10;gw=598;gh=428;title=Form 0.5b;
If frm["bg"] <> "" Then
GraphicsWindow.BackgroundColor = frm["bg"]
EndIf
If frm["gx"] <> "" Then
GraphicsWindow.Left = frm["gx"]
EndIf
If frm["gx"] <> "" Then
GraphicsWindow.Top = frm["gy"]
EndIf
If frm["gw"] <> "" Then
GraphicsWindow.Width = frm["gw"]
EndIf
gw = GraphicsWindow.Width
If frm["gh"] <> "" Then
GraphicsWindow.Height = frm["gh"]
EndIf
gh = GraphicsWindow.Height
If frm["title"] <> "" Then
GraphicsWindow.Title = frm["title"]
EndIf
ElseIf frm["func"] = "text" Then
' func=text;text=Folder;x=10;y=15;bc=Black;fn=Segoe UI;fs=12;fb=True;fi=False;
' func=text;text=Filename;x=10;y=45;bc=Black;fn=Segoe UI;fs=12;fb=True;fi=False;
GraphicsWindow.FontName = frm["fn"]
GraphicsWindow.FontSize = frm["fs"]
GraphicsWindow.FontBold = frm["fb"]
GraphicsWindow.FontItalic = frm["fi"]
GraphicsWindow.BrushColor = frm["bc"]
frm["obj"] = Shapes.AddText(frm["text"])
Shapes.Move(frm["obj"], frm["x"], frm["y"])
ElseIf frm["func"] = "tbox" Then
' func=tbox;id=folder;x=70;y=12;width=460;height=22;bc=Black;fn=Segoe UI;fs=12;fb=True;fi=False;text=.;
' func=tbox;id=filename;x=70;y=42;width=140;height=22;bc=Black;fn=Segoe UI;fs=12;fb=True;fi=False;text=Form.sb;
GraphicsWindow.FontName = frm["fn"]
GraphicsWindow.FontSize = frm["fs"]
GraphicsWindow.FontBold = frm["fb"]
GraphicsWindow.FontItalic = frm["fi"]
GraphicsWindow.BrushColor = frm["bc"]
frm["obj"] = Controls.AddTextBox(frm["x"], frm["y"])
Controls.SetSize(frm["obj"], frm["width"], frm["height"])
Controls.SetTextBoxText(frm["obj"], frm["text"])
ElseIf frm["func"] = "btn" Then
' func=btn;caption=OK;x=220;y=40;width=28;height=26;bc=Black;fn=Segoe UI;fs=12;fb=True;fi=False;
GraphicsWindow.FontName = frm["fn"]
GraphicsWindow.FontSize = frm["fs"]
GraphicsWindow.FontBold = frm["fb"]
GraphicsWindow.FontItalic = frm["fi"]
GraphicsWindow.BrushColor = frm["bc"]
frm["obj"] = Controls.AddButton(frm["caption"], frm["x"], frm["y"])
Controls.SetSize(frm["obj"], frm["width"], frm["height"])
Controls.ButtonClicked = OnButtonClicked
ElseIf frm["func"] = "rect" Then
' func=rect;x=546;y=10;width=2;height=32;scale=2;pw=0;pc=Black;bc=#999999;
GraphicsWindow.PenWidth = frm["pw"]
GraphicsWindow.PenColor = frm["pc"]
GraphicsWindow.BrushColor = frm["bc"]
frm["obj"] = Shapes.AddRectangle(frm["width"], frm["height"])
Shapes.Move(frm["obj"], frm["x"], frm["y"])
ElseIf frm["func"] = "img" Then
' func=img;src=img/Form32.png;x=556;y=10;width=32;height=32;
img = ImageList.LoadImage(Program.Directory + "/" + frm["src"])
ix = ImageList.GetWidthOfImage(img)
iy = ImageList.GetHeightOfImage(img)
scaleX = frm["width"] / ix
scaleY = frm["height"] / iy
frm["obj"] = Shapes.AddImage(img)
Shapes.Move(frm["obj"], frm["x"] + (frm["width"] - ix) / 2, frm["y"] + (frm["height"] - iy) / 2)
Shapes.Zoom(frm["obj"], scaleX, scaleY)
ElseIf frm["func"] = "mtbox" Then
' func=mtbox;id=data;x=10;y=72;width=578;height=346;bc=Black;fn=Segoe UI;fs=12;fb=True;fi=False;
GraphicsWindow.FontName = frm["fn"]
GraphicsWindow.FontSize = frm["fs"]
GraphicsWindow.FontBold = frm["fb"]
GraphicsWindow.FontItalic = frm["fi"]
GraphicsWindow.BrushColor = frm["bc"]
frm["obj"] = Controls.AddMultiLineTextBox(frm["x"], frm["y"])
Controls.SetSize(frm["obj"], frm["width"], frm["height"])
Else
id[frm["id"]] = ""
EndIf
form[i] = frm
EndFor
EndSub
Sub OnButtonClicked
'--
' Button control handler when clicked
buttonClicked = "True"
EndSub
Sub Form_GetForm
'--
' Form | Get form from file
' param formName - form file name
' return form - array for the form
folder = Program.Directory
buf = File.ReadContents(folder + "/" + formName)
Buf_Init()
nForm = 0
While p <= len
Buf_GetLine()
Line_RemoveLeadingSpace()
If Text.StartsWith(line, "'") Then
func = Text.GetIndexOf(line, "func=")
If 0 < func Then
nForm = nForm + 1
form[nForm] = Text.GetSubTextToEnd(line, func)
EndIf
EndIf
EndWhile
EndSub
Sub Line_RemoveLeadingSpace
'--
' Line | Remove leading space
' param line - to remove leading space
' return line - the result
Stack.PushValue("local", p)
p = 1
While Text.GetSubText(line, p, 1) = " "
p = p + 1
EndWhile
line = Text.GetSubTextToEnd(line, p)
p = Stack.PopValue("local")
EndSub
Sub Buf_GetLine
'--
' Buffer | Get line from buf
' param p - pointer to buf
' param buf - buffer
' param len - length of the buffer
' return line - current line
' return p - updated pointer to next line in buf
If p <= len Then
nl = Text.GetIndexOf(Text.GetSubTextToEnd(buf, p), CR)
If 0 < nl Then
line = Text.GetSubText(buf, p, nl - 1)
p = p + nl
Else
line = Text.GetSubTextToEnd(buf, p)
p = len + 1
EndIf
If Text.GetSubText(buf, p, 1) = LF Then
p = p + 1
EndIf
EndIf
EndSub
Sub Buf_Init
'--
' param buf - buffer
' return CR - carriage return
' return LF - line feed
' return len - length of text in buf
' return p - pointer to buf
CR = Text.GetCharacter(13)
LF = Text.GetCharacter(10)
len = Text.GetLength(buf)
p = 1
EndSub