-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathforms.red
More file actions
446 lines (374 loc) · 13.5 KB
/
forms.red
File metadata and controls
446 lines (374 loc) · 13.5 KB
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
Red [
Title: "RED Forms Generator"
Author: "PlanetSizeCpu"
Contributor: "YKProg"
File: %forms_dynamic.red
Version: Under Development see below
Needs: 'View
Usage: {
Use for form scripts generation, save result then copy&paste or load code
}
History: [
0.1.0 "22-08-2017" "Start of work."
0.3.4 "26-03-2018" "Source editor split"
0.3.5 "30-04-2018" "Dynamic code arrangement"
0.3.6 "30-07-2018" "Fixed font size typo"
0.3.7 "27-08-2018" "Fixed on-drop issue"
0.3.8 "05-10-2018" "Fixed widgets toolbox issue"
]
]
WindowDefXsize: 800
WindowDefYsize: 650
WindowDefSize: as-pair WindowDefXsize WindowDefYsize
WindowMinXSize: 800
WindowMinYSize: 650
FormSheetDefXorigin: 145
FormSheetDefYorigin: 17
FormSheetDefOrigin: as-pair FormSheetDefXorigin FormSheetDefYorigin
FormSheetDefXsize: WindowDefXsize - FormSheetDefXorigin
FormSheetDefYsize: WindowDefYsize - 135
FormSheetDefSize: as-pair FormSheetDefXsize FormSheetDefYsize
FormSheetStr: ""
FormSheetCounter: 0
FormSheetContent: []
FormSheetRecodeBlock: []
FormSheetWidgetSize: 200x150
FormSheetWidgetBackground: gray
FormSheetWidgetForeground: black
str: make string! FormSheetDefSize
ToolboxDefXsize: 125
ToolboxFileSize: as-pair ToolboxDefXsize 90
ToolboxFontSize: as-pair ToolboxDefXsize 140
ToolboxWidgetsSize: as-pair ToolboxDefXsize 200
ToolboxFormSheetSize: as-pair ToolboxDefXsize 60
ToolboxWidgetList: ["area" "base" "box" "button" "calendar" "camera" "check" "drop-down" "drop-list" "field" "group-box" "image" "panel" "progress" "radio" "scroller" "slider" "tab-panel" "text" "text-list"]
DynamicEditorDefXsize: (WindowDefXsize / 3)
StaticEditorDefXsize: (WindowDefXsize / 3 * 2)
EditorDefYsize: 114
DynamicEditorDefSize: as-pair DynamicEditorDefXsize EditorDefYsize
staticEditorDefSize: as-pair StaticEditorDefXsize EditorDefYsize
StaticDefOrigin: as-pair 0 (FormSheetDefYorigin + FormSheetDefYsize + 5)
DynamicDefOrigin: as-pair StaticEditorDefXsize (FormSheetDefYorigin + FormSheetDefYsize + 5)
DynamicCode: does copy [" "]
FontSel: attempt [make font! [name: "Arial" size: 14 style: "normal" color:FormSheetWidgetForeground ] ]
FontDefName: "Arial"
FontDefStyl: "Normal"
FontDefSize: "14"
forg: func[
clr [tuple!]
][
FormSheetWidgetForeground: clr
unview
WidgetGroupFgn/color: clr
]
bacg: func[
clr [tuple!]
][
FormSheetWidgetBackground: clr
unview
WidgetGroupBgn/color: clr
]
specified-color-f: function [][
to-color: function [r g b][0
color: 0.0.0
if r [color/1: to integer! 256 * r]
if g [color/2: to integer! 256 * g]
if b [color/3: to integer! 256 * b]
color
]
to-text: function [val][form to integer! 0.5 + 255 * any [val 0]]
view [
title "Color sliders"
style txt: text 40 right
style value: text "0" 30 right bold
across
txt "Red:" R: slider 256 value react [face/text: to-text R/data] return
txt "Green:" G: slider 256 value react [face/text: to-text G/data] return
txt "Blue:" B: slider 256 value react [face/text: to-text B/data]
pad 0x-65 box: base react [face/color: to-color R/data G/data B/data] return
pad 0x20 text "The new color"
font [size: 14]
react [face/font/color: box/color]
button "Done!" [do forg box/color]
]
]
specified-color-b: function [][
to-color: function [r g b][0
color: 0.0.0
if r [color/1: to integer! 256 * r]
if g [color/2: to integer! 256 * g]
if b [color/3: to integer! 256 * b]
color
]
to-text: function [val][form to integer! 0.5 + 255 * any [val 0]]
view [
title "Color sliders"
style txt: text 40 right
style value: text "0" 30 right bold
across
txt "Red:" R: slider 256 value react [face/text: to-text R/data] return
txt "Green:" G: slider 256 value react [face/text: to-text G/data] return
txt "Blue:" B: slider 256 value react [face/text: to-text B/data]
pad 0x-65 box: base react [face/color: to-color R/data G/data B/data] return
pad 0x20 text "The new color"
font [size: 14]
react [face/font/color: box/color]
button "Done!" [do bacg box/color]
]
]
mainScreen: layout [
title "RED FORMS"
size WindowDefSize
below center
style btn: button 100x20 red black bold
InfoGroup: group-box ToolboxFormSheetSize "Form-sheet size" [
InfoGroupFormSize: text 100x25 center bold font-size 14 str
]
WidgetGroup: group-box ToolboxWidgetsSize "Widgets" [
below center
text center 100x15 bold "Size:"
WidgetGroupSize: field 100x20 data FormSheetWidgetSize
across middle
text 70x20 left "Foreground:"
WidgetGroupFgn: box 20x20 FormSheetWidgetForeground [specified-color-f]
return
text 70x20 left "Background:"
WidgetGroupBgn: box 20x20 FormSheetWidgetBackground [specified-color-b]
return below center
WidgetGroupList: drop-down data ToolboxWidgetList select 1
WidgetGroupAddbtn: btn bold "Add" [FormSheetAddWidget]
]
FontGroup: group-box ToolboxFontSize "Font" [
below
FontGroupFontName: text bold 90x15 FontDefName
FontGroupFontStyl: text bold 90x15 FontDefStyl
across
text 30x25 bold "Size:"
FontGroupFontSize: text bold 30x15 FontDefSize
return
below
FontGroupFontBtn: btn bold "Font" [attempt [FormFontChange]]
return
]
SourceGroup: group-box ToolboxFileSize "File" [
below center
RunButton: btn "Run" [Recode attempt [SourceRun]]
SaveSourceButton: btn "Save" [SourceSave]
]
at FormSheetDefOrigin
FormSheet: panel FormSheetDefSize white blue cursor cross []
at StaticDefOrigin
EditorStatic: area StaticEditorDefSize 250.240.240 yellow
at DynamicDefOrigin
EditorDynamic: area DynamicEditorDefSize black green
on-resize [mainScreenSizeAdjust2]
on-detect [mainScreenSizeAdjust1]
]
system/view/capturing?: yes
mainScreen/actors: context [
on-detect: func [f e][
foreach-face f[
if select face/actors 'on-detect [
face/actors/on-detect face e
]
]
]
on-resize: func [f e][
foreach-face f[
if select face/actors 'on-resize [
face/actors/on-resize face e
]
]
]
]
EditorStatic/enabled?: false
mainScreenSizeAdjust2: does [
if FormSheet/Parent/size/x < WindowMinXSize [
FormSheet/Parent/size/x: WindowMinXSize
mainScreenSizeAdjust1
]
if FormSheet/Parent/size/y < WindowMinYSize [
FormSheet/Parent/size/y: WindowMinYSize
mainScreenSizeAdjust1
]
str: make string! FormSheetDefSize
InfoGroupFormSize/text: str
Recode
]
mainScreenSizeAdjust1: does [
WindowDefXsize: FormSheet/Parent/size/x
WindowDefYsize: FormSheet/Parent/size/y
WindowDefsize: as-pair WindowDefXsize WindowDefYsize
FormSheetDefXorigin: 145
FormSheetDefYorigin: 17
FormSheetDefOrigin: as-pair FormSheetDefXorigin FormSheetDefYorigin
FormSheetDefXsize: WindowDefXsize - FormSheetDefXorigin
FormSheetDefYsize: WindowDefYsize - 135
FormSheetDefSize: as-pair FormSheetDefXsize FormSheetDefYsize
FormSheet/offset: FormSheetDefOrigin
FormSheet/size: FormSheetDefSize
DynamicEditorDefXsize: (WindowDefXsize / 3)
StaticEditorDefXsize: (WindowDefXsize / 3 * 2)
EditorDefYsize: 114
DynamicEditorDefSize: as-pair DynamicEditorDefXsize EditorDefYsize
staticEditorDefSize: as-pair StaticEditorDefXsize EditorDefYsize
StaticDefOrigin: as-pair 0 (FormSheetDefYorigin + FormSheetDefYsize + 5)
DynamicDefOrigin: as-pair StaticEditorDefXsize (FormSheetDefYorigin + FormSheetDefYsize + 5)
EditorStatic/offset: StaticDefOrigin
EditorStatic/size: staticEditorDefSize
EditorDynamic/offset: DynamicDefOrigin
EditorDynamic/size: DynamicEditorDefSize
]
FormFontChange: does [
FontSel: attempt [make font! request-font]
FontSel/color: FormSheetWidgetForeground
FontDefName: FontSel/name
FontDefSize: to-string FontSel/size
FontGroupFontName/text: FontDefName
FontGroupFontStyl/text: FontDefStyl
FontGroupFontSize/text: FontDefSize
]
FormSheetAddWidget: does [
FormSheetStr: null
FormSheetWidgetName: null
FormSheetWidgetType: null
FormSheetCounter: add FormSheetCounter 1
FormSheetStr: to-string ToolboxWidgetList/(WidgetGroupList/selected)
FormSheetWidgetType: to-word copy FormSheetStr
append FormSheetStr to-string FormSheetCounter
append FormSheetStr ":"
FormSheetWidgetName: to-set-word FormSheetStr
append FormSheetContent FormSheetStr
either unset? 'FormSheetWidgetFiller [] [unset 'FormSheetWidgetFiller]
switch FormSheetWidgetType [
area [FormSheetWidgetFiller: to-string FormSheetWidgetName]
base [FormSheetWidgetFiller: to-string FormSheetWidgetName]
box [FormSheetWidgetFiller: to-string FormSheetWidgetName]
button [FormSheetWidgetFiller: to-string FormSheetWidgetName]
calendar [FormSheetWidgetFiller: to-string FormSheetWidgetName]
camera [FormSheetWidgetFiller: to-string FormSheetWidgetName]
check [FormSheetWidgetFiller: to-string FormSheetWidgetName]
drop-down [FormSheetWidgetFiller: to-string FormSheetWidgetName]
drop-list [FormSheetWidgetFiller: to-string FormSheetWidgetName]
field [FormSheetWidgetFiller: to-string FormSheetWidgetName]
group-box [FormSheetWidgetFiller: to-string FormSheetWidgetName]
image [FormSheetWidgetFiller: to-string FormSheetWidgetName]
panel [FormSheetWidgetFiller: to-string FormSheetWidgetName]
progress [FormSheetWidgetFiller: to-string FormSheetWidgetName]
radio [FormSheetWidgetFiller: to-string FormSheetWidgetName]
slider [FormSheetWidgetFiller: to-string FormSheetWidgetName]
scroller [FormSheetWidgetFiller: to-string FormSheetWidgetName]
tab-panel [FormSheetWidgetFiller: reduce [ to-string (FormSheetWidgetName) [] ] ]
text [FormSheetWidgetFiller: to-string FormSheetWidgetName]
text-list [FormSheetWidgetFiller: to-string FormSheetWidgetName]
]
Dly: layout reduce [(FormSheetWidgetName) (FormSheetWidgetType) (WidgetGroupSize/data) (FormSheetWidgetFiller)
'font FontSel (FormSheetWidgetBackground) (FormSheetWidgetForeground) 'loose 'on-drop [Recode show face] ]
append FormSheet/pane Dly/pane
Wgw: get to word! FormSheetWidgetName
Wgw/menu: ["Size +" Size+ "Size -" Size- "Change Size" Defsize "Change Font" Deffont "Change Color" Defcolor "Delete" Deletewt]
Wgw/actors: make object! [on-menu: func [face [object!] event [event!]][
switch event/picked [
Size+ [face/size: add face/size 10 Recode]
Size- [face/size: subtract face/size 10 Recode]
Defsize [face/size: WidgetGroupSize/data Recode]
Deffont [face/font: copy FontSel Recode]
Defcolor [FormSheetSetDefcolor face]
Deletewt [FormSheetDeleteWidget face]
]
]
on-drop: func [][Recode]]
Wgw/offset: 25x25
Recode
]
FormSheetDeleteWidget: func [face [object!]][
either none? face/text [Wnm: to-string face/data] [Wnm: face/text]
append Wnm ":"
alter FormSheetContent Wnm
if [face? to-word Wnm] [unset to-word Wnm]
remove find face/parent/pane face
Recode
]
FormSheetSetDefcolor: func [face [object!]][
face/color: FormSheetWidgetBackground face/font/color: FormSheetWidgetForeground
Recode
]
Recode: does [
clear FormSheetRecodeBlock
Widget: copy "size "
append Widget FormSheetDefSize
append FormSheetRecodeBlock Widget
foreach Wgt FormSheetContent [
Wgw: get to word! Wgt
Widget: copy "at "
Woffset: Wgw/offset
append Widget Woffset
append Widget " "
append Widget Wgt
append Widget " "
Wtype: Wgw/type
append Widget Wtype
append Widget " "
Wsize: Wgw/size
append Widget Wsize
append Widget " "
Wcolor: Wgw/color
append Widget Wcolor
append Widget " "
Wcolor: Wgw/font/color
append Widget Wcolor
append Widget " "
Wfiller: copy ""
switch/default Wtype [
tab-panel [
Wfiller: copy mold reduce [ Wgt [] ]
append Widget Wfiller]
text [Wfiller: copy Wgw/text append Widget mold Wfiller
Wfiller: " para [align: 'center v-align: 'middle]"
append Widget Wfiller]
][
Wfiller: copy Wgw/text
append Widget mold Wfiller
]
append Widget " "
Wft: copy "font ["
append Wft "name: "
append Wft dbl-quote
append Wft Wgw/font/name
append Wft dbl-quote
append Wft " "
append Wft "size: "
append Wft Wgw/font/size
append Wft " "
append Wft "style: '"
append Wft Wgw/font/style
append Wft "]"
append Widget Wft
append FormSheetRecodeBlock Widget
]
EditorStatic/text: copy "Red [ Needs: 'View ]"
append EditorStatic/text newline
append EditorStatic/text "view ["
foreach Wgt FormSheetRecodeBlock [append EditorStatic/text newline append EditorStatic/text Wgt]
append EditorStatic/text newline
append EditorStatic/text "]"
append EditorStatic/text newline
Globalcode: copy EditorStatic/text
append Globalcode newline
append Globalcode "DynamicCode: does ["
append Globalcode newline
append Globalcode EditorDynamic/text
append Globalcode "]"
append Globalcode newline
append Globalcode "do DynamicCode"
]
SourceRun: does [
do to-block Globalcode
]
SourceSave: does [
SourceFile: request-file
either none? SourceFile [][
Recode write SourceFile Globalcode
]
]
view/flags mainScreen [resize]