-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmallWikiPad.sb
2142 lines (2070 loc) · 50.6 KB
/
SmallWikiPad.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
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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
' Small Wiki Pad
' Version 0.5.1b
' Copyright © 2015-2017 Nonki Takahashi. The MIT License.
' Last update 2017-08-15
' Program ID NVD371-7
GraphicsWindow.Title = "Small Wiki Pad 0.5.1b"
Init()
Form()
LoadWikiText()
Controls.SetTextBoxText(tbox, wikiText)
GraphicsWindow.MouseDown = OnMouseDown
GraphicsWindow.MouseMove = OnMouseMove
While "True"
If mouseDown Then
GraphicsWindow.MouseDown = DoNothing
Controls_TabClick()
If tabClicked Then
ChangeTab()
Else
Controls_ScrollBar()
EndIf
GraphicsWindow.MouseDown = OnMouseDown
mouseDown = "False"
EndIf
EndWhile
Sub ChangeTab
i = lastTabClicked
If i <> iLast Then
Shapes.ShowShape(hline[iLast])
Shapes.SetOpacity(shadow[iLast], 20)
Shapes.HideShape(hline[i])
Shapes.SetOpacity(shadow[i], 0)
If iLast = 1 Then
Update()
EndIf
If (i = 1) Or (i = 2) Then
If iLast = 3 Then
Stack.PushValue("local", i)
i = iDocument
Group_Hide()
x = grp["x"]
y = ymaxPic
Group_Move()
i = iScrollbar
Group_Hide()
i = iThumb
Group_Hide()
x = grp["x"]
y = 32 + 14
Group_Move()
i = Stack.PopValue("local")
EndIf
Controls.ShowControl(tbox)
If i = 1 Then
Controls.SetTextBoxText(tbox, wikiText)
ElseIf i = 2 Then
Controls.SetTextBoxText(tbox, htmlText)
EndIf
ElseIf i = 3 Then
Stack.PushValue("local", i)
Controls.HideControl(tbox)
' initialize shapes
If iDocument = "" Then
Shapes_Restore()
scale = 1
angle = 0
' add shapes
name = "document"
Group_Add()
iDocument = nGroup
ph = shHeight + shY + 6 ' picture height
ymaxPic = 32 + shY
yminPic = gh - ph
x = shX
y = ymaxPic
i = iDocument
Group_Move()
Else
i = iDocument
Group_Show()
EndIf
If iScrollBar = "" Then
x = gw - 12
y = 32
height = gh - y
scale = 1
Controls_AddVScroll()
Else
i = iScrollBar
Group_Show()
i = iThumb
Group_Show()
EndIf
i = iTabs
Group_Remove()
Group_Add()
i = Stack.PopValue("local")
For _i = 1 To 3
shp = shape[_i * 4 - 1]
menu[_i] = shp["obj"]
shp = shape[_i * 4 + 1]
hline[_i] = shp["obj"]
shp = shape[_i * 4 + 2]
shadow[_i] = shp["obj"]
If _i = i Then
Shapes.SetOpacity(shadow[_i], 0)
Else
Shapes.SetOpacity(shadow[_i], 20)
EndIf
EndFor
Shapes.HideShape(hline[i])
EndIf
iLast = i
EndIf
EndSub
Sub DoNothing
EndSub
Sub Form
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BrushColor = "#333333"
GraphicsWindow.FontName = "Verdana"
GraphicsWindow.FontBold = "False"
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "#666666"
posX = "1=0;2=100;3=200;4=300;"
item = "1=Wiki;2=HTML;3=Preview;"
scale = 1
Controls_AddTabs()
iTabs = nGroup
GraphicsWindow.BrushColor = "#000"
tbox = Controls.AddMultiLineTextBox(posX[1], 31)
Controls.SetSize(tbox, gw, gh - 31)
EndSub
Sub Init
CR = Text.GetCharacter(13)
LF = Text.GetCharacter(10)
LT = "<"
TAB = Text.GetCharacter(19)
WQ = Text.GetCharacter(34)
Not = "False=True;True=False;"
SB_Workaround()
fsNormal = 16
fn = "Verdana"
fsH = "1=32;2=24;3=20;4=16;"
roman = "1=i;2=ii;3=iii;4=iv;5=v;6=vi;7=vii;8=viii;9=ix;10=x;11=xi;12=xii;"
fb = "False"
fi = "False"
bc = "#000000" ' font color (brush color)
pc = "#000000"
pw = 0
param = ""
shX = 10
shY = 10
x3 = 0
txt = ""
pw = 0
paragraph = "True"
lineHeight = fsNormal * 1.5
EndSub
Sub LoadWikiText
wikiText = "**bold**" + LT + "br>" + CR + LF
wikiText = wikiText + "_italics_" + LT + "br>" + CR + LF
wikiText = wikiText + "# Heading 1" + CR + LF
wikiText = wikiText + "## Heading 2" + CR + LF
wikiText = wikiText + "### Heading 3" + CR + LF
wikiText = wikiText + "#### Heading 4" + CR + LF
wikiText = wikiText + "- Bullet List" + CR + LF
wikiText = wikiText + " - Bullet List 2" + CR + LF
wikiText = wikiText + CR + LF
wikiText = wikiText + "1. Number List" + CR + LF
wikiText = wikiText + " 1. Number List 2" + CR + LF
wikiText = wikiText + CR + LF
wikiText = wikiText + "![Turtle](http://www.nonkit.com/smallbasic.files/Turtle.png)" + CR + LF
wikiText = wikiText + CR + LF
wikiText = wikiText + "[SmallWikiPad](http://github.com/nonkit/SmallWikiPad)" + CR + LF
wikiText = wikiText + CR + LF
wikiText = wikiText + "| Table Heading 1 | Table Heading 2 |" + CR + LF
wikiText = wikiText + "| --- | --- |" + CR + LF
wikiText = wikiText + "| Row 1 - Cell 1 | Row 1 - Cell 2 |" + CR + LF
wikiText = wikiText + "| Row 2 - Cell 1 | Row 2 - Cell 2 |" + CR + LF
wikiText = wikiText + "___" + CR + LF
EndSub
Sub OnMouseDown
dx = GraphicsWindow.MouseX
dy = GraphicsWindow.MouseY
mouseDown = "True"
EndSub
Sub OnMouseMove
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
mouseMove = "True"
EndSub
Sub Update
wikiText = Controls.GetTextBoxText(tbox)
If wikiText <> lastWikiText Then
name = "document"
Group_Remove()
shape = ""
iMax = 0
x = 0
y = 0
lineHeight = fsNormal * 1.5
Parse_WikiText()
shX = 10
shY = 10
Shapes_Save()
lastWikiText = wikiText
iDocument = ""
EndIf
EndSub
Sub Controls_AddTabs
' param item[] - tab items
shX = 0 ' x offset
shY = 0 ' y offset
shape = ""
shape[1] = "func=rect;x=0;y=0;width="+gw+";height=32;pw=0;bc=#FFF;"
shape[2] = "func=line;x="+posX[1]+";y=1;x1=0;y1=0;x2="+(posX[4]-posX[1])+";y2=0;pw=1;pc=#666;"
n = Array.GetItemCount(item)
For i = 1 To n
shape[i * 4 - 1] = "func=text;x="+(posX[i]+5)+";y=10;text="+item[i]+";fn=Segoe UI;fs=12;"
shape[i * 4] = "func=line;x="+posX[i]+";y=0;x1=0;y1=0;x2=0;y2=31;pw=1;pc=#666;"
shape[i * 4 + 1] = "func=line;x="+posX[i]+";y=31;x1=0;y1=0;x2="+(posX[i+1]-posX[i])+";y2=0;pw=1;pc=#666;"
shape[i * 4 + 2] = "func=rect;x="+posX[i]+";y=0;width="+(posX[i+1]-posX[i])+";height=32;pw=0;bc=#000;"
EndFor
iLast = 1
shape[n * 4 + 3] = "func=line;x="+posX[4]+";y=0;x1=0;y1=0;x2=0;y2=31;pw=1;pc=#666;"
shape[n * 4 + 4] = "func=rect;x="+(posX[4]+1)+";y=0;width="+(gw-posX[4]-1)+";height=32;pw=0;bc=#BBB;"
shape[n * 4 + 5] = "func=line;x="+posX[4]+";y=31;x1=0;y1=0;x2="+(gw-posX[4])+";y2=0;pw=1;pc=#666;"
name = "tabs"
Group_Add()
For i = 1 To n
shp = shape[i * 4 - 1]
menu[i] = shp["obj"]
shp = shape[i * 4 + 1]
hline[i] = shp["obj"]
shp = shape[i * 4 + 2]
shadow[i] = shp["obj"]
If i = iLast Then
Shapes.SetOpacity(shadow[i], 0)
Else
Shapes.SetOpacity(shadow[i], 20)
EndIf
EndFor
Shapes.HideShape(hline[iLast])
EndSub
Sub Controls_AddVScroll
' param x - left position x
' param y - top position y
' param height - height
' return group - array of shapes groups
' return nShape - number of indices for shape array
' return nGroup - number of indices for group array
' add vertical scroll bar
shX = x
shY = y
shape = ""
shape[1] = "func=rect;x=0;y=0;width=14;height="+height+";pw=0;bc=#99CCCCCC;"
shape[2] = "func=rect;x=0;y=0;width=14;height=14;pw=0;bc=#CCCCCC;"
shape[3] = "func=line;x=3;y=6;x1=0;y1=3;x2=3;y2=0;pw=1;pc=#666666;"
shape[4] = "func=line;x=6;y=6;x1=0;y1=0;x2=3;y2=3;pw=1;pc=#666666;"
shape[5] = "func=rect;x=0;y="+(height-14)+";width=14;height=14;pw=0;bc=#CCCCCC;"
shape[6] = "func=line;x=3;y="+(height-8)+";x1=0;y1=0;x2=3;y2=3;pw=1;pc=#666666;"
shape[7] = "func=line;x=6;y="+(height-8)+";x1=0;y1=3;x2=3;y2=0;pw=1;pc=#666666;"
name = "scroll"
Group_Add()
iScrollBar = nGroup
' add thumb
bh = height - 28 ' scroll bar height
th = bh * height / ph ' thumb heignt
shX = x
shY = y + 14
shape = ""
shape[1] = "func=rect;x=0;y=0;width=14;height="+th+";pw=0;bc=#999999;"
name = "thumb"
Group_Add()
iThumb = nGroup
yminThumb = y + 14
ymaxThumb = y + height - 14 - th
hPage = height ' page height in scroll bar
EndSub
Sub Controls_Scroll
' param yMove - relative thumb move
Stack.PushValue("local", y)
i = iDocument
grp = group[i]
x = grp["x"]
y = grp["y"] - yMove / bh * ph
If y < yminPic Then
y = yminPic
ElseIf ymaxPic < y Then
y = ymaxPic
EndIf
Group_Move()
y = Stack.PopValue("local")
EndSub
Sub Controls_ScrollBar
grp = group[iScrollBar]
shX = grp["x"]
shY = grp["y"]
shape = grp["shape"]
iMin = 1
iMax = Array.GetItemCount(shape)
shp = shape[iMin] ' vertical scroll bar
x1 = shX + shp["rx"]
x2 = shX + shp["rx"] + shp["width"]
y1 = shY + shp["ry"]
y2 = shY + shp["ry"] + shp["height"]
If x1 <= dx And dx <= x2 And y1 <= dy And dy <= y2 Then
shp = shape[iMin+1] ' line up button
y1 = shY + shp["ry"]
y2 = shY + shp["ry"] + shp["height"]
shp = shape[iMin+4] ' line down button
y3 = shY + shp["ry"]
y4 = shY + shp["ry"] + shp["height"]
grp = group[iThumb] ' thumb
shX = grp["x"]
shY = grp["y"]
shape = grp["shape"]
shp = shape[iMin]
y5 = shY + shp["ry"]
y6 = shY + shp["ry"] + shp["height"]
y = y5
yLast = y5
If y1 <= dy And dy <= y2 Then
' line up
x = shX
y = y5 - th / 25
If y < yminThumb Then
y = yminThumb
EndIf
ElseIf y3 <= dy And dy <= y4 Then
' line down
x = shX
y = y5 + th / 25
If ymaxThumb < y Then
y = ymaxThumb
EndIf
ElseIf y5 <= dy And dy <= y6 Then
' thumb truck
myLast = dy
myThumb = dy - y5
While Mouse.IsLeftButtonDown
If mouseMove Then
x = shX
y = my - myThumb
If ymaxThumb < y Then
y = ymaxThumb
ElseIf y < yminThumb Then
y = yminThumb
EndIf
If y <> yLast Then
yMove = y - yLast
yLast = y
i = iThumb
Group_Move() ' move thumb
Controls_Scroll()
EndIf
myLast = my
mouseMove = "False"
EndIf
EndWhile
ElseIf dy < y5 Then
' page up
x = shX
y = y5 - th
If y < yminThumb Then
y = yminThumb
EndIf
ElseIf y6 < dy Then
' page down
x = shX
y = y5 + th
If ymaxThumb < y Then
y = ymaxThumb
EndIf
EndIf
If y <> yLast Then
x = shX
yMove = y - yLast
i = iThumb
Group_Move() ' move thumb
Controls_Scroll()
EndIf
EndIf
EndSub
Sub Controls_TabClick
tabClicked = "False"
If 5 <= dy And dy < 30 Then
For i = 1 To 3
If posX[i] <= dx And dx < posX[i + 1] Then
tabClicked = "True"
lastTabClicked = i
i = 3 ' exit for
EndIf
EndFor
EndIf
EndSub
Sub Font_GetTextWidth
' param fs - font size
' param fn - font name
' param fb - font bold
' param fi - font italic
' param txt - text to get width in px
' return width - text width
yc = 4
GraphicsWindow.BrushColor = "#FFFFFF"
GraphicsWindow.FillRectangle(0, yc, gw, gh - yc)
GraphicsWindow.FontSize = fs
GraphicsWindow.FontName = fn
GraphicsWindow.FontBold = fb
GraphicsWindow.FontItalic = fi
GraphicsWindow.BrushColor = "#FEFEFE"
GraphicsWindow.DrawText(0, yc, "||")
y0 = yc
y1 = yc + fs
x0 = 0
x1 = fs * 2
If gw < x1 Then
x1 = gw - 1
EndIf
Font_Measure()
px0 = px
GraphicsWindow.BrushColor = "#FFFFFF"
GraphicsWindow.FillRectangle(0, yc, gw, gh - yc)
GraphicsWindow.BrushColor = "Gray"
GraphicsWindow.FillRectangle(0, yc + fs, gw, 1)
str = "|" + txt + "|"
GraphicsWindow.BrushColor = "#FEFEFE"
GraphicsWindow.DrawText(0, yc, str)
x1 = fs * Text.GetLength(str)
If gw < x1 Then
x1 = gw - 1
EndIf
Font_Measure()
width = px - px0
EndSub
Sub Font_Measure
' return px - width in pixel (px)
_y = Math.Floor((y0 + y1) / 2)
For _x = x0 To x1
color = GraphicsWindow.GetPixel(_x, _y)
If Not[Text.EndsWith(color, "FFFFFF")] Then
left = _x
_x = x1 ' exit For
EndIf
EndFor
For _x = x1 To x0 Step -1
color = GraphicsWindow.GetPixel(_x, _y)
If Not[Text.EndsWith(color, "FFFFFF")] Then
right = _x
_x = x0 ' exit For
EndIf
EndFor
For _x = right To x0 Step -1
color = GraphicsWindow.GetPixel(_x, _y)
If Text.EndsWith(color, "FFFFFF") Then
right = _x + 1
_x = x0 ' exit For
EndIf
EndFor
px = right - left
EndSub
Sub Group_Add
' Group | add shapes to a group
' param name - group name
' param shX, shY, origin of shape array
' param shape[] - shape array
' param nGroup - number of group
' return nGroup - updated number of group
' return group - group array
Stack.PushValue("local", i)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
Stack.PushValue("local", s)
nGroup = nGroup + 1
grp = ""
grp["name"] = name
grp["x"] = shX
grp["y"] = shY
grp["angle"] = 0
grp["dir"] = 1
Shapes_CalcWidthAndHeight()
grp["width"] = shWidth
grp["cx"] = shWidth / 2
grp["height"] = shHeight
s = 1
grp["scale"] = s
For i = 1 To Array.GetItemCount(shape)
shp = shape[i]
GraphicsWindow.PenWidth = shp["pw"] * s
If shp["pw"] > 0 Then
GraphicsWindow.PenColor = shp["pc"]
EndIf
If Text.IsSubText("rect|ell|tri|text", shp["func"]) Then
GraphicsWindow.BrushColor = shp["bc"]
EndIf
If shp["func"] = "rect" Then
shp["obj"] = Shapes.AddRectangle(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "ell" Then
shp["obj"] = Shapes.AddEllipse(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "tri" Then
shp["obj"] = Shapes.AddTriangle(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s, shp["x3"] * s, shp["y3"] * s)
ElseIf shp["func"] = "line" Then
shp["obj"] = Shapes.AddLine(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s)
ElseIf shp["func"] = "text" Then
If silverlight Then
fs = Math.Floor(shp["fs"] * 0.9)
Else
fs = shp["fs"]
EndIf
GraphicsWindow.FontSize = fs * s
GraphicsWindow.FontName = shp["fn"]
GraphicsWindow.FontBold = shp["fb"]
GraphicsWindow.FontItalic = shp["fi"]
shp["obj"] = Shapes.AddText(shp["text"])
ElseIf shp["func"] = "img" Then
shp["obj"] = Shapes.AddImage(shp["img"])
Shapes.Move(shp["obj"], shp["x"], shp["y"])
EndIf
x = shp["x"]
y = shp["y"]
shp["rx"] = x
shp["ry"] = y
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
alpha = Math.GetRadians(shp["angle"])
SB_RotateWorkaround()
shp["wx"] = x
shp["wy"] = y
EndIf
Shapes.Move(shp["obj"], shX + x * s, shY + y * s)
If Text.IsSubText("rect|ell|tri|text", shp["func"]) And (shp["angle"] <> 0) And (shp["angle"] <> "") Then
Shapes.Rotate(shp["obj"], shp["angle"])
EndIf
shape[i] = shp
EndFor
grp["shape"] = shape
group[nGroup] = grp
s = Stack.PopValue("local")
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub
Sub Group_Dump
' Gourp | Dump a group for debug
' param group[i] - group to dump
Stack.PushValue("local", j)
grp = group[i]
TextWindow.WriteLine("name=" + grp["name"])
TextWindow.WriteLine("x=" + grp["x"])
TextWindow.WriteLine("y=" + grp["y"])
TextWindow.WriteLine("cx=" + grp["cx"])
TextWindow.WriteLine("width=" + grp["width"])
TextWindow.WriteLine("dir=" + grp["dir"])
shape = grp["shape"]
For j = 1 To Array.GetItemCount(shape)
TextWindow.WriteLine("shape[" + j + "]=" + WQ + shape[j] + WQ)
EndFor
j = Stack.PopValue("local")
EndSub
Sub Group_Hide
' Group | Hide a group
' param group[i] - the group to hide
' return group[i] - the updated group
grp = group[i]
shape = grp["shape"]
Stack.PushValue("local", i)
For i = 1 To Array.GetItemCount(shape)
shp = shape[i]
Shapes.HideShape(shp["obj"])
EndFor
i = Stack.PopValue("local")
EndSub
Sub Group_Move
' Group | Move a group
' param group[i] - the group to move
' param x, y - the position to move
' return group[i] - the updated group
Stack.PushValue("local", s)
Stack.PushValue("local", n)
Stack.PushValue("local", j)
grp = group[i]
s = grp["scale"]
grp["x"] = x
grp["y"] = y
shape = grp["shape"]
n = Array.GetItemCount(shape)
For j = 1 To n
shp = shape[j]
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
_x = shp["wx"]
_y = shp["wy"]
Else
_x = shp["rx"]
_y = shp["ry"]
EndIf
Shapes.Move(shp["obj"], grp["x"] + _x * s, grp["y"] + _y * s)
EndFor
group[i] = grp
j = Stack.PopValue("local")
n = Stack.PopValue("local")
s = Stack.PopValue("local")
EndSub
Sub Group_Remove
' Group | Remove a group
' param group[i] - the group to hide
' return shape [] - the removed shapes
' return shX, shY - origin of shape array
' return name - removed group name
grp = group[i]
shape = grp["shape"]
Stack.PushValue("local", i)
For i = 1 To Array.GetItemCount(shape)
shp = shape[i]
Shapes.Remove(shp["obj"])
EndFor
shX = grp["x"]
shY = grp["y"]
i = Stack.PopValue("local")
EndSub
Sub Group_Show
' Group | Show a group
' param group[i] - the group to show
' return group[i] - the updated group
grp = group[i]
shape = grp["shape"]
Stack.PushValue("local", i)
For i = 1 To Array.GetItemCount(shape)
shp = shape[i]
Shapes.ShowShape(shp["obj"])
EndFor
i = Stack.PopValue("local")
EndSub
Sub Math_CartesianToPolar
' Math | convert cartesian coodinate to polar coordinate
' param x, y - cartesian coordinate
' return r, a - polar coordinate
r = Math.SquareRoot(x * x + y * y)
If x = 0 And y > 0 Then
a = 90 ' [degree]
ElseIf x = 0 And y < 0 Then
a = -90
ElseIf x = 0 And y = 0 Then
a = 0
Else
a = Math.ArcTan(y / x) * 180 / Math.Pi
EndIf
If x < 0 Then
a = a + 180
ElseIf x > 0 And y < 0 Then
a = a + 360
EndIf
EndSub
Sub Parse_BlankLine
' EBNF: blank line = [ space ], CR, LF;
' return match - "True" if match
' return htmlText - null
Stack.PushValue("local", pSave)
pSave = p
Parse_Space()
c2 = Text.GetSubText(buf, p, 2)
If c2 = CR + LF Then
htmlText = ""
match = "True"
p = p + 2
Else
match = "False"
p = pSave
EndIf
pSave = Stack.PopValue("local")
EndSub
Sub Parse_BlankLines
' EBNF: blank lines = blank line, { blank line };
' return match - "True" if match
' return htmlText - null
Parse_BlankLine()
If match Then
While match
Parse_BlankLine()
EndWhile
match = "True"
EndIf
If match Then
If paragraph Then
y = y + lineHeight + fsNormal
x = 0
lineHeight = fsNormal * 1.5
EndIf
y = y + fsNormal
EndIf
EndSub
Sub Parse_Block
' EBNF: block = heading | bullet list | number list | table | horizontal rule | blank lines | line;
' return match - "True" if match
' return htmlText - HTML text of block
' return paragraph - "True" if match with line
Parse_Heading()
If Not[match] Then
Parse_BulletList()
EndIf
If Not[match] Then
Parse_NumberList()
EndIf
If Not[match] Then
Parse_Table()
EndIf
If Not[match] Then
Parse_HorizontalRule()
EndIf
If Not[match] Then
Parse_BlankLines()
EndIf
If match Then
paragraph = "False"
Else
Parse_Line()
If match Then
paragraph = "True"
EndIF
EndIf
EndSub
Sub Parse_Bold
' EBNF: bold = '**', ( italic | text ), '**';
' return match - "True" if match
' return htmlText - bold
Stack.PushValue("local", pSave)
pSave = p
c2 = Text.GetSubText(buf, p, 2)
If c2 = "**" Then
p = p + 2
match = "True"
Else
match = "False"
EndIf
If match Then
Parse_Italic()
If Not[match] Then
delim = "**"
Parse_Text()
If match Then
htmlText = txt
EndIf
EndIf
EndIf
If match Then
c2 = Text.GetSubText(buf, p, 2)
If c2 = "**" Then
p = p + 2
Else
match = "False"
EndIf
EndIf
If match Then
htmlText = LT + "strong>" + htmlText + LT + "/strong>"
_fb = fb
fb = "True"
fs = fsNormal
Shapes_AddText()
x = x + width
fb = _fb
Else
p = pSave
EndIf
pSave = Stack.PopValue("local")
EndSub
Sub Parse_Break
' EBNF: break = '<', ('B' | 'b'), ('R' | 'r'), '>';
' return match - "True" if match
' return htmlText - HTML text of break
Stack.PushValue("local", pSave)
pSave = p
c = Text.GetSubText(buf, p, 1)
If c = LT Then
p = p + 1
match = "True"
Else
match = "False"
EndIf
If match Then
c = Text.GetSubText(buf, p, 1)
If Text.IsSubText("Bb", c) Then
p = p + 1
Else
match = "False"
EndIf
EndIf
If match Then
c = Text.GetSubText(buf, p, 1)
If Text.IsSubText("Rr", c) Then
p = p + 1
Else
match = "False"
EndIf
EndIf
If match Then
c = Text.GetSubText(buf, p, 1)
If c = ">" Then
p = p + 1
Else
match = "False"
EndIf
EndIf
If match Then
htmlText = LT + "br>"
y = y + lineHeight
lineHeight = fs * 1.5
x = 0
Else
p = pSave
EndIf
pSave = Stack.PopValue("local")
EndSub
Sub Parse_BulletList
' EBNF: bullet list = bullet list item, { bullet list item }, CR, LF;
' return match - "True" if match
' return htmlText - HTML text of bullet list
Stack.PushValue("local", pSave)
Stack.PushValue("local", htmlText)
pSave = p
lastIndent = -1
Parse_BulletListItem()
If match Then
While lastIndent < indent
htmlText = LT + "ul>" + CR + LF + htmlText
lastIndent = lastIndent + 1
EndWhile
While match
Stack.PushValue("local", htmlText)
Parse_BulletListItem()
_htmlText = Stack.PopValue("local")
If match Then
While lastIndent < indent
htmlText = LT + "ul>" + CR + LF + htmlText
lastIndent = lastIndent + 1
EndWhile
While indent < lastIndent
htmlText = LT + "/ul>" + CR + LF + htmlText
lastIndent = lastIndent - 1
EndWhile
htmlText = Text.Append(_htmlText, htmlText)
Else
htmlText = _htmlText
EndIf
EndWhile
match = "True"
EndIf
If match Then
c2 = Text.GetSubText(buf, p, 2)
If c2 = CR + LF Then
p = p + 2
Else
match = "False"
EndIf
EndIf
_htmlText = Stack.PopValue("local")
If match Then
While -1 < indent
htmlText = htmlText + LT + "/ul>" + CR + LF
indent = indent - 1
EndWhile
Else
htmlText = _htmlText
p = pSave
EndIf
pSave = Stack.PopValue("local")
EndSub
Sub Parse_BulletListItem
' EBNF: bullet list item = { ' ' }, '-', space, text, CR, LF;
' return match - "True" if match
' return indent - number of indent
' return htmlText - HTML text of bullet list item
Stack.PushValue("local", pSave)
Stack.PushValue("local", indent)
pSave = p
indent = 0
c4 = Text.GetSubText(buf, p, 4)
While c4 = " "
indent = indent + 1
p = p + 4
c4 = Text.GetSubText(buf, p, 4)
EndWhile
c = Text.GetSubText(buf, p, 1)
If c = "-" Then
p = p + 1
match = "True"
Else
match = "False"
EndIf
If match Then
Parse_Space()
EndIf
If match Then
delim = ""
Parse_Text()
EndIf
If match Then
c2 = Text.GetSubText(buf, p, 2)
If c2 = CR + LF Then
p = p + 2
Else
match = "False"
EndIf
EndIf
_indent = Stack.PopValue("local")
If match Then
htmlText = LT + "li>" + txt + LT + "/li>" + CR + LF
x = indent * 20 + 20
If paragraph Then
y = y + lineHeight + fsNormal
x = 0
lineHeight = fsNormal * 1.5
EndIf
y = y + 7
width = 5
height = 5
_bc = bc
_pw = pw
If indent = 1 Then
bc = "#FFFFFF"
pw = 1
EndIf
Shapes_AddEllipse()
bc = _bc
pw = _pw
y = y - 7
x = x + 10
Shapes_AddText()
lineHeight = Math.Max(lineHeight, fs * 1.5)
y = y + lineHeight
lineHeight = fsNormal * 1.5
Else
p = pSave
indent = _indent
EndIf
pSave = Stack.PopValue("local")
EndSub
Sub Parse_Character
' EBNF: character = '&' | '<' | escape character | normal character;
' return match - "True" if match
' return c - character
c = Text.GetSubText(buf, p, 1)
If c = "&" Then
p = p + 1
match = "True"
Else
match = "False"
EndIf
If Not[match] Then
c = Text.GetSubText(buf, p, 1)
If c = LT Then
p = p + 1
match = "True"
Else
match = "False"
EndIf
EndIf
If Not[match] Then
Parse_EscapeCharacter()
EndIf
If Not[match] Then
Parse_NormalCharacter()
EndIf
EndSub
Sub Parse_Column
' EBNF: column = rich text, '|';
' return match - "True" if match