-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd
972 lines (889 loc) · 27 KB
/
d
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
local coreGui = game:GetService("CoreGui")
local camera = workspace.CurrentCamera
local drawingUI = Instance.new("ScreenGui")
drawingUI.Name = "Drawing | Xeno"
drawingUI.IgnoreGuiInset = true
drawingUI.DisplayOrder = 0x7fffffff
drawingUI.Parent = coreGui
local drawingIndex = 0
local drawingFontsEnum = {
[0] = Font.fromEnum(Enum.Font.Roboto),
[1] = Font.fromEnum(Enum.Font.Legacy),
[2] = Font.fromEnum(Enum.Font.SourceSans),
[3] = Font.fromEnum(Enum.Font.RobotoMono)
}
local function getFontFromIndex(fontIndex)
return drawingFontsEnum[fontIndex]
end
local function convertTransparency(transparency)
return math.clamp(1 - transparency, 0, 1)
end
local baseDrawingObj = setmetatable({
Visible = true,
ZIndex = 0,
Transparency = 1,
Color = Color3.new(),
Remove = function(self)
setmetatable(self, nil)
end,
Destroy = function(self)
setmetatable(self, nil)
end,
SetProperty = function(self, index, value)
if self[index] ~= nil then
self[index] = value
else
warn("Attempted to set invalid property: " .. tostring(index))
end
end,
GetProperty = function(self, index)
if self[index] ~= nil then
return self[index]
else
warn("Attempted to get invalid property: " .. tostring(index))
return nil
end
end,
SetParent = function(self, parent)
self.Parent = parent
end
}, {
__add = function(t1, t2)
local result = {}
for index, value in pairs(t1) do
result[index] = value
end
for index, value in pairs(t2) do
result[index] = value
end
return result
end
})
local DrawingLib = {}
DrawingLib.Fonts = {
["UI"] = 0,
["System"] = 1,
["Plex"] = 2,
["Monospace"] = 3
}
function DrawingLib.new(drawingType)
drawingIndex += 1
if drawingType == "Line" then
return DrawingLib.createLine()
elseif drawingType == "Text" then
return DrawingLib.createText()
elseif drawingType == "Circle" then
return DrawingLib.createCircle()
elseif drawingType == "Square" then
return DrawingLib.createSquare()
elseif drawingType == "Image" then
return DrawingLib.createImage()
elseif drawingType == "Quad" then
return DrawingLib.createQuad()
elseif drawingType == "Triangle" then
return DrawingLib.createTriangle()
elseif drawingType == "Frame" then
return DrawingLib.createFrame()
elseif drawingType == "ScreenGui" then
return DrawingLib.createScreenGui()
elseif drawingType == "TextButton" then
return DrawingLib.createTextButton()
elseif drawingType == "TextLabel" then
return DrawingLib.createTextLabel()
elseif drawingType == "TextBox" then
return DrawingLib.createTextBox()
else
error("Invalid drawing type: " .. tostring(drawingType))
end
end
function DrawingLib.createLine()
local lineObj = ({
From = Vector2.zero,
To = Vector2.zero,
Thickness = 1
} + baseDrawingObj)
local lineFrame = Instance.new("Frame")
lineFrame.Name = drawingIndex
lineFrame.AnchorPoint = Vector2.new(0.5, 0.5)
lineFrame.BorderSizePixel = 0
lineFrame.Parent = drawingUI
return setmetatable({Parent = drawingUI}, {
__newindex = function(_, index, value)
if lineObj[index] == nil then
warn("Invalid property: " .. tostring(index))
return
end
if index == "From" or index == "To" then
local direction = (index == "From" and lineObj.To or value) - (index == "From" and value or lineObj.From)
local center = (lineObj.To + lineObj.From) / 2
local distance = direction.Magnitude
local theta = math.deg(math.atan2(direction.Y, direction.X))
lineFrame.Position = UDim2.fromOffset(center.X, center.Y)
lineFrame.Rotation = theta
lineFrame.Size = UDim2.fromOffset(distance, lineObj.Thickness)
elseif index == "Thickness" then
lineFrame.Size = UDim2.fromOffset((lineObj.To - lineObj.From).Magnitude, value)
elseif index == "Visible" then
lineFrame.Visible = value
elseif index == "ZIndex" then
lineFrame.ZIndex = value
elseif index == "Transparency" then
lineFrame.BackgroundTransparency = convertTransparency(value)
elseif index == "Color" then
lineFrame.BackgroundColor3 = value
elseif index == "Parent" then
lineFrame.Parent = value
end
lineObj[index] = value
end,
__index = function(self, index)
if index == "Remove" or index == "Destroy" then
return function()
lineFrame:Destroy()
lineObj:Remove()
end
end
return lineObj[index]
end,
__tostring = function() return "Drawing" end
})
end
function DrawingLib.createText()
local textObj = ({
Text = "",
Font = DrawingLib.Fonts.UI,
Size = 0,
Position = Vector2.zero,
Center = false,
Outline = false,
OutlineColor = Color3.new()
} + baseDrawingObj)
local textLabel, uiStroke = Instance.new("TextLabel"), Instance.new("UIStroke")
textLabel.Name = drawingIndex
textLabel.AnchorPoint = Vector2.new(0.5, 0.5)
textLabel.BorderSizePixel = 0
textLabel.BackgroundTransparency = 1
local function updateTextPosition()
local textBounds = textLabel.TextBounds
local offset = textBounds / 2
textLabel.Size = UDim2.fromOffset(textBounds.X, textBounds.Y)
textLabel.Position = UDim2.fromOffset(textObj.Position.X + (not textObj.Center and offset.X or 0), textObj.Position.Y + offset.Y)
end
textLabel:GetPropertyChangedSignal("TextBounds"):Connect(updateTextPosition)
uiStroke.Thickness = 1
uiStroke.Enabled = textObj.Outline
uiStroke.Color = textObj.Color
textLabel.Parent, uiStroke.Parent = drawingUI, textLabel
return setmetatable({Parent = drawingUI}, {
__newindex = function(_, index, value)
if textObj[index] == nil then
warn("Invalid property: " .. tostring(index))
return
end
if index == "Text" then
textLabel.Text = value
elseif index == "Font" then
textLabel.FontFace = getFontFromIndex(math.clamp(value, 0, 3))
elseif index == "Size" then
textLabel.TextSize = value
elseif index == "Position" then
updateTextPosition()
elseif index == "Center" then
textLabel.Position = UDim2.fromOffset((value and camera.ViewportSize / 2 or textObj.Position).X, textObj.Position.Y)
elseif index == "Outline" then
uiStroke.Enabled = value
elseif index == "OutlineColor" then
uiStroke.Color = value
elseif index == "Visible" then
textLabel.Visible = value
elseif index == "ZIndex" then
textLabel.ZIndex = value
elseif index == "Transparency" then
local transparency = convertTransparency(value)
textLabel.TextTransparency = transparency
uiStroke.Transparency = transparency
elseif index == "Color" then
textLabel.TextColor3 = value
elseif index == "Parent" then
textLabel.Parent = value
end
textObj[index] = value
end,
__index = function(self, index)
if index == "Remove" or index == "Destroy" then
return function()
textLabel:Destroy()
textObj:Remove()
end
elseif index == "TextBounds" then
return textLabel.TextBounds
end
return textObj[index]
end,
__tostring = function() return "Drawing" end
})
end
function DrawingLib.createCircle()
local circleObj = ({
Radius = 150,
Position = Vector2.zero,
Thickness = 0.7,
Filled = false
} + baseDrawingObj)
local circleFrame, uiCorner, uiStroke = Instance.new("Frame"), Instance.new("UICorner"), Instance.new("UIStroke")
circleFrame.Name = drawingIndex
circleFrame.AnchorPoint = Vector2.new(0.5, 0.5)
circleFrame.BorderSizePixel = 0
uiCorner.CornerRadius = UDim.new(1, 0)
circleFrame.Size = UDim2.fromOffset(circleObj.Radius, circleObj.Radius)
uiStroke.Thickness = circleObj.Thickness
uiStroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
circleFrame.Parent, uiCorner.Parent, uiStroke.Parent = drawingUI, circleFrame, circleFrame
return setmetatable({Parent = drawingUI}, {
__newindex = function(_, index, value)
if circleObj[index] == nil then
warn("Invalid property: " .. tostring(index))
return
end
if index == "Radius" then
local radius = value * 2
circleFrame.Size = UDim2.fromOffset(radius, radius)
elseif index == "Position" then
circleFrame.Position = UDim2.fromOffset(value.X, value.Y)
elseif index == "Thickness" then
uiStroke.Thickness = math.clamp(value, 0.6, 0x7fffffff)
elseif index == "Filled" then
circleFrame.BackgroundTransparency = value and convertTransparency(circleObj.Transparency) or 1
uiStroke.Enabled = not value
elseif index == "Visible" then
circleFrame.Visible = value
elseif index == "ZIndex" then
circleFrame.ZIndex = value
elseif index == "Transparency" then
local transparency = convertTransparency(value)
circleFrame.BackgroundTransparency = circleObj.Filled and transparency or 1
uiStroke.Transparency = transparency
elseif index == "Color" then
circleFrame.BackgroundColor3 = value
uiStroke.Color = value
elseif index == "Parent" then
circleFrame.Parent = value
end
circleObj[index] = value
end,
__index = function(self, index)
if index == "Remove" or index == "Destroy" then
return function()
circleFrame:Destroy()
circleObj:Remove()
end
end
return circleObj[index]
end,
__tostring = function() return "Drawing" end
})
end
function DrawingLib.createSquare()
local squareObj = ({
Size = Vector2.zero,
Position = Vector2.zero,
Thickness = 0.7,
Filled = false
} + baseDrawingObj)
local squareFrame, uiStroke = Instance.new("Frame"), Instance.new("UIStroke")
squareFrame.Name = drawingIndex
squareFrame.BorderSizePixel = 0
squareFrame.Parent, uiStroke.Parent = drawingUI, squareFrame
return setmetatable({Parent = drawingUI}, {
__newindex = function(_, index, value)
if squareObj[index] == nil then
warn("Invalid property: " .. tostring(index))
return
end
if index == "Size" then
squareFrame.Size = UDim2.fromOffset(value.X, value.Y)
elseif index == "Position" then
squareFrame.Position = UDim2.fromOffset(value.X, value.Y)
elseif index == "Thickness" then
uiStroke.Thickness = math.clamp(value, 0.6, 0x7fffffff)
elseif index == "Filled" then
squareFrame.BackgroundTransparency = value and convertTransparency(squareObj.Transparency) or 1
uiStroke.Enabled = not value
elseif index == "Visible" then
squareFrame.Visible = value
elseif index == "ZIndex" then
squareFrame.ZIndex = value
elseif index == "Transparency" then
local transparency = convertTransparency(value)
squareFrame.BackgroundTransparency = squareObj.Filled and transparency or 1
uiStroke.Transparency = transparency
elseif index == "Color" then
squareFrame.BackgroundColor3 = value
uiStroke.Color = value
elseif index == "Parent" then
squareFrame.Parent = value
end
squareObj[index] = value
end,
__index = function(self, index)
if index == "Remove" or index == "Destroy" then
return function()
squareFrame:Destroy()
squareObj:Remove()
end
end
return squareObj[index]
end,
__tostring = function() return "Drawing" end
})
end
function DrawingLib.createImage()
local imageObj = ({
Data = "",
DataURL = "rbxassetid://0",
Size = Vector2.zero,
Position = Vector2.zero
} + baseDrawingObj)
local imageFrame = Instance.new("ImageLabel")
imageFrame.Name = drawingIndex
imageFrame.BorderSizePixel = 0
imageFrame.ScaleType = Enum.ScaleType.Stretch
imageFrame.BackgroundTransparency = 1
imageFrame.Parent = drawingUI
return setmetatable({Parent = drawingUI}, {
__newindex = function(_, index, value)
if imageObj[index] == nil then
warn("Invalid property: " .. tostring(index))
return
end
if index == "Data" then
elseif index == "DataURL" then
imageFrame.Image = value
elseif index == "Size" then
imageFrame.Size = UDim2.fromOffset(value.X, value.Y)
elseif index == "Position" then
imageFrame.Position = UDim2.fromOffset(value.X, value.Y)
elseif index == "Visible" then
imageFrame.Visible = value
elseif index == "ZIndex" then
imageFrame.ZIndex = value
elseif index == "Transparency" then
imageFrame.ImageTransparency = convertTransparency(value)
elseif index == "Color" then
imageFrame.ImageColor3 = value
elseif index == "Parent" then
imageFrame.Parent = value
end
imageObj[index] = value
end,
__index = function(self, index)
if index == "Remove" or index == "Destroy" then
return function()
imageFrame:Destroy()
imageObj:Remove()
end
elseif index == "Data" then
return nil
end
return imageObj[index]
end,
__tostring = function() return "Drawing" end
})
end
function DrawingLib.createQuad()
local quadObj = ({
PointA = Vector2.zero,
PointB = Vector2.zero,
PointC = Vector2.zero,
PointD = Vector2.zero,
Thickness = 1,
Filled = false
} + baseDrawingObj)
local _linePoints = {
A = DrawingLib.createLine(),
B = DrawingLib.createLine(),
C = DrawingLib.createLine(),
D = DrawingLib.createLine()
}
local fillFrame = Instance.new("Frame")
fillFrame.Name = drawingIndex .. "_Fill"
fillFrame.BorderSizePixel = 0
fillFrame.BackgroundTransparency = quadObj.Transparency
fillFrame.BackgroundColor3 = quadObj.Color
fillFrame.ZIndex = quadObj.ZIndex
fillFrame.Visible = quadObj.Visible and quadObj.Filled
fillFrame.Parent = drawingUI
return setmetatable({Parent = drawingUI}, {
__newindex = function(_, index, value)
if quadObj[index] == nil then
warn("Invalid property: " .. tostring(index))
return
end
if index == "PointA" then
_linePoints.A.From = value
_linePoints.B.To = value
elseif index == "PointB" then
_linePoints.B.From = value
_linePoints.C.To = value
elseif index == "PointC" then
_linePoints.C.From = value
_linePoints.D.To = value
elseif index == "PointD" then
_linePoints.D.From = value
_linePoints.A.To = value
elseif index == "Thickness" or index == "Visible" or index == "Color" or index == "ZIndex" then
for _, linePoint in pairs(_linePoints) do
linePoint[index] = value
end
if index == "Visible" then
fillFrame.Visible = value and quadObj.Filled
elseif index == "Color" then
fillFrame.BackgroundColor3 = value
elseif index == "ZIndex" then
fillFrame.ZIndex = value
end
elseif index == "Filled" then
for _, linePoint in pairs(_linePoints) do
linePoint.Transparency = value and 1 or quadObj.Transparency
end
fillFrame.Visible = value
elseif index == "Parent" then
fillFrame.Parent = value
end
quadObj[index] = value
end,
__index = function(self, index)
if index == "Remove" or index == "Destroy" then
return function()
for _, linePoint in pairs(_linePoints) do
linePoint:Remove()
end
fillFrame:Destroy()
quadObj:Remove()
end
end
return quadObj[index]
end,
__tostring = function() return "Drawing" end
})
end
function DrawingLib.createTriangle()
local triangleObj = ({
PointA = Vector2.zero,
PointB = Vector2.zero,
PointC = Vector2.zero,
Thickness = 1,
Filled = false
} + baseDrawingObj)
local _linePoints = {
A = DrawingLib.createLine(),
B = DrawingLib.createLine(),
C = DrawingLib.createLine()
}
local fillFrame = Instance.new("Frame")
fillFrame.Name = drawingIndex .. "_Fill"
fillFrame.BorderSizePixel = 0
fillFrame.BackgroundTransparency = triangleObj.Transparency
fillFrame.BackgroundColor3 = triangleObj.Color
fillFrame.ZIndex = triangleObj.ZIndex
fillFrame.Visible = triangleObj.Visible and triangleObj.Filled
fillFrame.Parent = drawingUI
return setmetatable({Parent = drawingUI}, {
__newindex = function(_, index, value)
if triangleObj[index] == nil then
warn("Invalid property: " .. tostring(index))
return
end
if index == "PointA" then
_linePoints.A.From = value
_linePoints.B.To = value
elseif index == "PointB" then
_linePoints.B.From = value
_linePoints.C.To = value
elseif index == "PointC" then
_linePoints.C.From = value
_linePoints.A.To = value
elseif index == "Thickness" or index == "Visible" or index == "Color" or index == "ZIndex" then
for _, linePoint in pairs(_linePoints) do
linePoint[index] = value
end
if index == "Visible" then
fillFrame.Visible = value and triangleObj.Filled
elseif index == "Color" then
fillFrame.BackgroundColor3 = value
elseif index == "ZIndex" then
fillFrame.ZIndex = value
end
elseif index == "Filled" then
for _, linePoint in pairs(_linePoints) do
linePoint.Transparency = value and 1 or triangleObj.Transparency
end
fillFrame.Visible = value
elseif index == "Parent" then
fillFrame.Parent = value
end
triangleObj[index] = value
end,
__index = function(self, index)
if index == "Remove" or index == "Destroy" then
return function()
for _, linePoint in pairs(_linePoints) do
linePoint:Remove()
end
fillFrame:Destroy()
triangleObj:Remove()
end
end
return triangleObj[index]
end,
__tostring = function() return "Drawing" end
})
end
function DrawingLib.createFrame()
local frameObj = ({
Size = UDim2.new(0, 100, 0, 100),
Position = UDim2.new(0, 0, 0, 0),
Color = Color3.new(1, 1, 1),
Transparency = 0,
Visible = true,
ZIndex = 1
} + baseDrawingObj)
local frame = Instance.new("Frame")
frame.Name = drawingIndex
frame.Size = frameObj.Size
frame.Position = frameObj.Position
frame.BackgroundColor3 = frameObj.Color
frame.BackgroundTransparency = convertTransparency(frameObj.Transparency)
frame.Visible = frameObj.Visible
frame.ZIndex = frameObj.ZIndex
frame.BorderSizePixel = 0
frame.Parent = drawingUI
return setmetatable({Parent = drawingUI}, {
__newindex = function(_, index, value)
if frameObj[index] == nil then
warn("Invalid property: " .. tostring(index))
return
end
if index == "Size" then
frame.Size = value
elseif index == "Position" then
frame.Position = value
elseif index == "Color" then
frame.BackgroundColor3 = value
elseif index == "Transparency" then
frame.BackgroundTransparency = convertTransparency(value)
elseif index == "Visible" then
frame.Visible = value
elseif index == "ZIndex" then
frame.ZIndex = value
elseif index == "Parent" then
frame.Parent = value
end
frameObj[index] = value
end,
__index = function(self, index)
if index == "Remove" or index == "Destroy" then
return function()
frame:Destroy()
frameObj:Remove()
end
end
return frameObj[index]
end,
__tostring = function() return "Drawing" end
})
end
function DrawingLib.createScreenGui()
local screenGuiObj = ({
IgnoreGuiInset = true,
DisplayOrder = 0,
ResetOnSpawn = true,
ZIndexBehavior = Enum.ZIndexBehavior.Sibling,
Enabled = true
} + baseDrawingObj)
local screenGui = Instance.new("ScreenGui")
screenGui.Name = drawingIndex
screenGui.IgnoreGuiInset = screenGuiObj.IgnoreGuiInset
screenGui.DisplayOrder = screenGuiObj.DisplayOrder
screenGui.ResetOnSpawn = screenGuiObj.ResetOnSpawn
screenGui.ZIndexBehavior = screenGuiObj.ZIndexBehavior
screenGui.Enabled = screenGuiObj.Enabled
screenGui.Parent = coreGui
return setmetatable({Parent = coreGui}, {
__newindex = function(_, index, value)
if screenGuiObj[index] == nil then
warn("Invalid property: " .. tostring(index))
return
end
if index == "IgnoreGuiInset" then
screenGui.IgnoreGuiInset = value
elseif index == "DisplayOrder" then
screenGui.DisplayOrder = value
elseif index == "ResetOnSpawn" then
screenGui.ResetOnSpawn = value
elseif index == "ZIndexBehavior" then
screenGui.ZIndexBehavior = value
elseif index == "Enabled" then
screenGui.Enabled = value
elseif index == "Parent" then
screenGui.Parent = value
end
screenGuiObj[index] = value
end,
__index = function(self, index)
if index == "Remove" or index == "Destroy" then
return function()
screenGui:Destroy()
screenGuiObj:Remove()
end
end
return screenGuiObj[index]
end,
__tostring = function() return "Drawing" end
})
end
function DrawingLib.createTextButton()
local buttonObj = ({
Text = "Button",
Font = DrawingLib.Fonts.UI,
Size = 20,
Position = UDim2.new(0, 0, 0, 0),
Color = Color3.new(1, 1, 1),
BackgroundColor = Color3.new(0.2, 0.2, 0.2),
Transparency = 0,
Visible = true,
ZIndex = 1,
MouseButton1Click = nil
} + baseDrawingObj)
local button = Instance.new("TextButton")
button.Name = drawingIndex
button.Text = buttonObj.Text
button.FontFace = getFontFromIndex(buttonObj.Font)
button.TextSize = buttonObj.Size
button.Position = buttonObj.Position
button.TextColor3 = buttonObj.Color
button.BackgroundColor3 = buttonObj.BackgroundColor
button.BackgroundTransparency = convertTransparency(buttonObj.Transparency)
button.Visible = buttonObj.Visible
button.ZIndex = buttonObj.ZIndex
button.Parent = drawingUI
local buttonEvents = {}
return setmetatable({
Parent = drawingUI,
Connect = function(_, eventName, callback)
if eventName == "MouseButton1Click" then
if buttonEvents["MouseButton1Click"] then
buttonEvents["MouseButton1Click"]:Disconnect()
end
buttonEvents["MouseButton1Click"] = button.MouseButton1Click:Connect(callback)
else
warn("Invalid event: " .. tostring(eventName))
end
end
}, {
__newindex = function(_, index, value)
if buttonObj[index] == nil then
warn("Invalid property: " .. tostring(index))
return
end
if index == "Text" then
button.Text = value
elseif index == "Font" then
button.FontFace = getFontFromIndex(math.clamp(value, 0, 3))
elseif index == "Size" then
button.TextSize = value
elseif index == "Position" then
button.Position = value
elseif index == "Color" then
button.TextColor3 = value
elseif index == "BackgroundColor" then
button.BackgroundColor3 = value
elseif index == "Transparency" then
button.BackgroundTransparency = convertTransparency(value)
elseif index == "Visible" then
button.Visible = value
elseif index == "ZIndex" then
button.ZIndex = value
elseif index == "Parent" then
button.Parent = value
elseif index == "MouseButton1Click" then
if typeof(value) == "function" then
if buttonEvents["MouseButton1Click"] then
buttonEvents["MouseButton1Click"]:Disconnect()
end
buttonEvents["MouseButton1Click"] = button.MouseButton1Click:Connect(value)
else
warn("Invalid value for MouseButton1Click: expected function, got " .. typeof(value))
end
end
buttonObj[index] = value
end,
__index = function(self, index)
if index == "Remove" or index == "Destroy" then
return function()
button:Destroy()
buttonObj:Remove()
end
end
return buttonObj[index]
end,
__tostring = function() return "Drawing" end
})
end
function DrawingLib.createTextLabel()
local labelObj = ({
Text = "Label",
Font = DrawingLib.Fonts.UI,
Size = 20,
Position = UDim2.new(0, 0, 0, 0),
Color = Color3.new(1, 1, 1),
BackgroundColor = Color3.new(0.2, 0.2, 0.2),
Transparency = 0,
Visible = true,
ZIndex = 1
} + baseDrawingObj)
local label = Instance.new("TextLabel")
label.Name = drawingIndex
label.Text = labelObj.Text
label.FontFace = getFontFromIndex(labelObj.Font)
label.TextSize = labelObj.Size
label.Position = labelObj.Position
label.TextColor3 = labelObj.Color
label.BackgroundColor3 = labelObj.BackgroundColor
label.BackgroundTransparency = convertTransparency(labelObj.Transparency)
label.Visible = labelObj.Visible
label.ZIndex = labelObj.ZIndex
label.Parent = drawingUI
return setmetatable({Parent = drawingUI}, {
__newindex = function(_, index, value)
if labelObj[index] == nil then
warn("Invalid property: " .. tostring(index))
return
end
if index == "Text" then
label.Text = value
elseif index == "Font" then
label.FontFace = getFontFromIndex(math.clamp(value, 0, 3))
elseif index == "Size" then
label.TextSize = value
elseif index == "Position" then
label.Position = value
elseif index == "Color" then
label.TextColor3 = value
elseif index == "BackgroundColor" then
label.BackgroundColor3 = value
elseif index == "Transparency" then
label.BackgroundTransparency = convertTransparency(value)
elseif index == "Visible" then
label.Visible = value
elseif index == "ZIndex" then
label.ZIndex = value
elseif index == "Parent" then
label.Parent = value
end
labelObj[index] = value
end,
__index = function(self, index)
if index == "Remove" or index == "Destroy" then
return function()
label:Destroy()
labelObj:Remove()
end
end
return labelObj[index]
end,
__tostring = function() return "Drawing" end
})
end
function DrawingLib.createTextBox()
local boxObj = ({
Text = "",
Font = DrawingLib.Fonts.UI,
Size = 20,
Position = UDim2.new(0, 0, 0, 0),
Color = Color3.new(1, 1, 1),
BackgroundColor = Color3.new(0.2, 0.2, 0.2),
Transparency = 0,
Visible = true,
ZIndex = 1
} + baseDrawingObj)
local textBox = Instance.new("TextBox")
textBox.Name = drawingIndex
textBox.Text = boxObj.Text
textBox.FontFace = getFontFromIndex(boxObj.Font)
textBox.TextSize = boxObj.Size
textBox.Position = boxObj.Position
textBox.TextColor3 = boxObj.Color
textBox.BackgroundColor3 = boxObj.BackgroundColor
textBox.BackgroundTransparency = convertTransparency(boxObj.Transparency)
textBox.Visible = boxObj.Visible
textBox.ZIndex = boxObj.ZIndex
textBox.Parent = drawingUI
return setmetatable({Parent = drawingUI}, {
__newindex = function(_, index, value)
if boxObj[index] == nil then
warn("Invalid property: " .. tostring(index))
return
end
if index == "Text" then
textBox.Text = value
elseif index == "Font" then
textBox.FontFace = getFontFromIndex(math.clamp(value, 0, 3))
elseif index == "Size" then
textBox.TextSize = value
elseif index == "Position" then
textBox.Position = value
elseif index == "Color" then
textBox.TextColor3 = value
elseif index == "BackgroundColor" then
textBox.BackgroundColor3 = value
elseif index == "Transparency" then
textBox.BackgroundTransparency = convertTransparency(value)
elseif index == "Visible" then
textBox.Visible = value
elseif index == "ZIndex" then
textBox.ZIndex = value
elseif index == "Parent" then
textBox.Parent = value
end
boxObj[index] = value
end,
__index = function(self, index)
if index == "Remove" or index == "Destroy" then
return function()
textBox:Destroy()
boxObj:Remove()
end
end
return boxObj[index]
end,
__tostring = function() return "Drawing" end
})
end
local drawingFunctions = {}
function drawingFunctions.isrenderobj(drawingObj)
local success, isrenderobj = pcall(function()
return drawingObj.Parent == drawingUI
end)
if not success then return false end
return isrenderobj
end
function drawingFunctions.getrenderproperty(drawingObj, property)
local success, drawingProperty = pcall(function()
return drawingObj[property]
end)
if not success then return end
if drawingProperty ~= nil then
return drawingProperty
end
end
function drawingFunctions.setrenderproperty(drawingObj, property, value)
assert(drawingFunctions.getrenderproperty(drawingObj, property), "'" .. tostring(property) .. "' is not a valid property of " .. tostring(drawingObj) .. ", " .. tostring(typeof(drawingObj)))
drawingObj[property] = value
end
function drawingFunctions.cleardrawcache()
for _, drawing in drawingUI:GetDescendants() do
drawing:Remove()
end
end
return {Drawing = DrawingLib, functions = drawingFunctions}