@@ -24,6 +24,7 @@ function Element:New(Idx, Config)
24
24
local Colorpicker = {
25
25
Value = Config .Default ,
26
26
Transparency = Config .Transparency or 0 ,
27
+ UpdateOnChange = Config .UpdateOnChange or Config .UpdateWhileSliding or false ,
27
28
Type = "Colorpicker" ,
28
29
Title = type (Config .Title ) == "string" and Config .Title or "Colorpicker" ,
29
30
Callback = Config .Callback or function (Color ) end ,
@@ -77,6 +78,8 @@ function Element:New(Idx, Config)
77
78
local Hue , Sat , Vib = Colorpicker .Hue , Colorpicker .Sat , Colorpicker .Vib
78
79
local Transparency = Colorpicker .Transparency
79
80
81
+ local OrigHue , OrigSat , OrigVib , OrigTransparency = Colorpicker .Hue , Colorpicker .Sat , Colorpicker .Vib , Colorpicker .Transparency
82
+
80
83
local function CreateInput ()
81
84
local Box = require (Components .Textbox )()
82
85
Box .Frame .Parent = Dialog .Root
@@ -330,6 +333,10 @@ function Element:New(Idx, Config)
330
333
TransparencyDrag .Position = UDim2 .new (0 , - 1 , 1 - Transparency , - 6 )
331
334
AlphaInput .Input .Text = `{Library .Utilities :Round ((1 - Transparency ) * 100 , 0 )}%`
332
335
end
336
+
337
+ if Colorpicker .UpdateOnChange then
338
+ Colorpicker :SetValue ({ Hue , Sat , Vib }, Transparency )
339
+ end
333
340
end
334
341
335
342
Creator .AddSignal (HexInput .Input .FocusLost , function (Enter )
@@ -395,59 +402,96 @@ function Element:New(Idx, Config)
395
402
end )
396
403
end
397
404
405
+ local function UpdateSatVib ()
406
+ local MinX = SatVibMap .AbsolutePosition .X
407
+ local MaxX = MinX + SatVibMap .AbsoluteSize .X
408
+ local MouseX = math.clamp (Mouse .X , MinX , MaxX )
409
+
410
+ local MinY = SatVibMap .AbsolutePosition .Y
411
+ local MaxY = MinY + SatVibMap .AbsoluteSize .Y
412
+ local MouseY = math.clamp (Mouse .Y , MinY , MaxY )
413
+
414
+ Sat = (MouseX - MinX ) / (MaxX - MinX )
415
+ Vib = 1 - ((MouseY - MinY ) / (MaxY - MinY ))
416
+ Display ()
417
+ end
418
+
419
+ local function UpdateHue ()
420
+ local MinY = HueSlider .AbsolutePosition .Y
421
+ local MaxY = MinY + HueSlider .AbsoluteSize .Y
422
+ local MouseY = math.clamp (Mouse .Y , MinY , MaxY )
423
+
424
+ Hue = ((MouseY - MinY ) / (MaxY - MinY ))
425
+ Display ()
426
+ end
427
+
428
+ local function UpdateTransparency ()
429
+ local MinY = TransparencySlider .AbsolutePosition .Y
430
+ local MaxY = MinY + TransparencySlider .AbsoluteSize .Y
431
+ local MouseY = math.clamp (Mouse .Y , MinY , MaxY )
432
+
433
+ Transparency = 1 - ((MouseY - MinY ) / (MaxY - MinY ))
434
+ Display ()
435
+ end
436
+
437
+ local MouseMoveConnection
398
438
Creator .AddSignal (SatVibMap .InputBegan , function (Input )
399
- if
400
- Input .UserInputType == Enum.UserInputType.MouseButton1
401
- or Input .UserInputType == Enum.UserInputType.Touch
402
- then
403
- while UserInputService :IsMouseButtonPressed (Enum.UserInputType.MouseButton1 ) do
404
- local MinX = SatVibMap .AbsolutePosition .X
405
- local MaxX = MinX + SatVibMap .AbsoluteSize .X
406
- local MouseX = math.clamp (Mouse .X , MinX , MaxX )
407
-
408
- local MinY = SatVibMap .AbsolutePosition .Y
409
- local MaxY = MinY + SatVibMap .AbsoluteSize .Y
410
- local MouseY = math.clamp (Mouse .Y , MinY , MaxY )
411
-
412
- Sat = (MouseX - MinX ) / (MaxX - MinX )
413
- Vib = 1 - ((MouseY - MinY ) / (MaxY - MinY ))
414
- Display ()
415
-
416
- RenderStepped :Wait ()
439
+ if Input .UserInputType == Enum.UserInputType.MouseButton1
440
+ or Input .UserInputType == Enum.UserInputType.Touch then
441
+
442
+ MouseMoveConnection = Mouse .Move :Connect (UpdateSatVib )
443
+ UpdateSatVib ()
444
+ end
445
+ end )
446
+
447
+ Creator .AddSignal (SatVibMap .InputEnded , function (Input )
448
+ if Input .UserInputType == Enum.UserInputType.MouseButton1
449
+ or Input .UserInputType == Enum.UserInputType.Touch then
450
+
451
+ if MouseMoveConnection then
452
+ MouseMoveConnection :Disconnect ()
453
+ MouseMoveConnection = nil
417
454
end
418
455
end
419
456
end )
420
457
421
458
Creator .AddSignal (HueSlider .InputBegan , function (Input )
422
- if
423
- Input .UserInputType == Enum.UserInputType.MouseButton1
424
- or Input .UserInputType == Enum.UserInputType.Touch
425
- then
426
- while UserInputService :IsMouseButtonPressed (Enum.UserInputType.MouseButton1 ) do
427
- local MinY = HueSlider .AbsolutePosition .Y
428
- local MaxY = MinY + HueSlider .AbsoluteSize .Y
429
- local MouseY = math.clamp (Mouse .Y , MinY , MaxY )
430
-
431
- Hue = ((MouseY - MinY ) / (MaxY - MinY ))
432
- Display ()
433
-
434
- RenderStepped :Wait ()
459
+ if Input .UserInputType == Enum.UserInputType.MouseButton1
460
+ or Input .UserInputType == Enum.UserInputType.Touch then
461
+
462
+ MouseMoveConnection = Mouse .Move :Connect (UpdateHue )
463
+ UpdateHue ()
464
+ end
465
+ end )
466
+
467
+ Creator .AddSignal (HueSlider .InputEnded , function (Input )
468
+ if Input .UserInputType == Enum.UserInputType.MouseButton1
469
+ or Input .UserInputType == Enum.UserInputType.Touch then
470
+
471
+ if MouseMoveConnection then
472
+ MouseMoveConnection :Disconnect ()
473
+ MouseMoveConnection = nil
435
474
end
436
475
end
437
476
end )
438
477
439
478
if Config .Transparency then
440
479
Creator .AddSignal (TransparencySlider .InputBegan , function (Input )
441
- if Input .UserInputType == Enum.UserInputType.MouseButton1 then
442
- while UserInputService :IsMouseButtonPressed (Enum.UserInputType.MouseButton1 ) do
443
- local MinY = TransparencySlider .AbsolutePosition .Y
444
- local MaxY = MinY + TransparencySlider .AbsoluteSize .Y
445
- local MouseY = math.clamp (Mouse .Y , MinY , MaxY )
446
-
447
- Transparency = 1 - ((MouseY - MinY ) / (MaxY - MinY ))
448
- Display ()
480
+ if Input .UserInputType == Enum.UserInputType.MouseButton1
481
+ or Input .UserInputType == Enum.UserInputType.Touch then
482
+
483
+ MouseMoveConnection = Mouse .Move :Connect (UpdateTransparency )
484
+ UpdateTransparency ()
485
+ end
486
+ end )
449
487
450
- RenderStepped :Wait ()
488
+ Creator .AddSignal (TransparencySlider .InputEnded , function (Input )
489
+ if Input .UserInputType == Enum.UserInputType.MouseButton1
490
+ or Input .UserInputType == Enum.UserInputType.Touch then
491
+
492
+ if MouseMoveConnection then
493
+ MouseMoveConnection :Disconnect ()
494
+ MouseMoveConnection = nil
451
495
end
452
496
end
453
497
end )
@@ -458,7 +502,11 @@ function Element:New(Idx, Config)
458
502
Dialog :Button ("Done" , function ()
459
503
Colorpicker :SetValue ({ Hue , Sat , Vib }, Transparency )
460
504
end )
461
- Dialog :Button ("Cancel" )
505
+
506
+ Dialog :Button ("Cancel" , function ()
507
+ Colorpicker :SetValue ({ OrigHue , OrigSat , OrigVib }, OrigTransparency )
508
+ end )
509
+
462
510
Dialog :Open ()
463
511
end
464
512
@@ -524,4 +572,4 @@ function Element:New(Idx, Config)
524
572
})
525
573
end
526
574
527
- return Element
575
+ return Element
0 commit comments