forked from Jaslm/ColorPickerPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorPickerPlus.lua
More file actions
executable file
·1432 lines (1277 loc) · 43.1 KB
/
ColorPickerPlus.lua
File metadata and controls
executable file
·1432 lines (1277 loc) · 43.1 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
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
-- ColorPickerPlus replaces the standard Color Picker to provide
-- © Jaslm
-- 1. text entry for colors (RGB, hex, and HSV values) and alpha (for opacity),
-- 2. copy to and paste from color palette
-- 3. color swatches for the copied color and for the starting color
-- 4. analog color choice through a hue bar and saturation/value gradient square
-- 5. class palette and copy/paste independent of palette
--VARIABLES
-------------------------------------------------------------------------------------------------------
local _, ColorPickerPlus = ...
local MOD = ColorPickerPlus
local DB
local lockedHueBar = false
local lockedOpacityBar = false
local lockedGradient = false
local lockedOpacity = 0 -- saves value of opacity while HueBar or Gradient changes color values
local colorHue -- 0 to 1
local colorSat -- 0 to 1
local colorVal -- 0 to 1
local borderSize = 5
local dialogWidthNoOpacity = 380
local dialogWidthWithOpacity = 420
local dialogHeight = 380
local sideMargin = 28
local topMargin = 28
local spacing = 12
local hueBarWidth = 18
local hueBarHeight = 300
local hueTextureSize = 50 -- allow for 1/6 of hueBarHeight
local opacityBarWidth = 18
local opacityBarHeight = 300
local gradientWidth = 160
local gradientHeight = 160
local colorSwatchWidth = 120
local colorSwatchHeight = 120
local isClassic = (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC)
local isCata = (WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC)
local isTWW = floor(select(4, GetBuildInfo()) / 11000) == 10
local opacitySliderFrame = OpacitySliderFrame and OpacitySliderFrame or OpacityFrameSlider
-- bgTable used in creation of backdrops
local bgTable = {
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
tile = false,
tileSize = 16,
edgeSize = 1,
insets = { 0, 0, 0, 0 },
}
-- initial values in palette
-- these are overridden by user and saved in WoW SavedVariables
local defaults = {
palette = { -- 36 color allotted
{ r = 1.0, g = 0.0, b = 0.0, a = 1.0 }, -- red
{ r = 1.0, g = 0.0, b = 0.5, a = 1.0 }, -- rose
{ r = 1.0, g = 0.0, b = 1.0, a = 1.0 }, -- magenta
{ r = 0.5, g = 0.0, b = 1.0, a = 1.0 }, -- violet
{ r = 0.0, g = 0.0, b = 1.0, a = 1.0 }, -- blue
{ r = 0.0, g = 0.5, b = 1.0, a = 1.0 }, -- azure
{ r = 0.0, g = 1.0, b = 1.0, a = 1.0 }, -- cyan
{ r = 0.0, g = 1.0, b = 0.5, a = 1.0 }, -- aquamarine
{ r = 0.0, g = 1.0, b = 0.0, a = 1.0 }, -- green
{ r = 0.5, g = 1.0, b = 0.0, a = 1.0 }, -- chartreuse
{ r = 1.0, g = 1.0, b = 0.0, a = 1.0 }, -- yellow
{ r = 1.0, g = 0.5, b = 0.0, a = 1.0 }, -- orange
{ r = 0.976, g = 0.549, b = 0.714, a = 1.0 }, -- pastels
{ r = 0.984, g = 0.714, b = 0.820, a = 1.0 },
{ r = 0.647, g = 0.537, b = 0.757, a = 1.0 },
{ r = 0.757, g = 0.702, b = 0.843, a = 1.0 },
{ r = 0.459, g = 0.537, b = 0.749, a = 1.0 },
{ r = 0.580, g = 0.659, b = 0.816, a = 1.0 },
{ r = 0.604, g = 0.808, b = 0.874, a = 1.0 },
{ r = 0.710, g = 0.882, b = 0.682, a = 1.0 },
{ r = 0.749, g = 0.894, b = 0.462, a = 1.0 },
{ r = 0.999, g = 0.980, b = 0.506, a = 1.0 },
{ r = 0.992, g = 0.792, b = 0.635, a = 1.0 },
{ r = 0.859, g = 0.835, b = 0.725, a = 1.0 },
{ r = 0.0, g = 0.0, b = 0.0, a = 1.0 }, -- black
{ r = 0.1, g = 0.1, b = 0.1, a = 1.0 }, -- shades of gray
{ r = 0.2, g = 0.2, b = 0.2, a = 1.0 },
{ r = 0.3, g = 0.3, b = 0.3, a = 1.0 },
{ r = 0.4, g = 0.4, b = 0.4, a = 1.0 },
{ r = 0.5, g = 0.5, b = 0.5, a = 1.0 },
{ r = 0.6, g = 0.6, b = 0.6, a = 1.0 },
{ r = 0.7, g = 0.7, b = 0.7, a = 1.0 },
{ r = 0.8, g = 0.8, b = 0.8, a = 1.0 },
{ r = 0.9, g = 0.9, b = 0.9, a = 1.0 },
{ r = 1.0, g = 1.0, b = 1.0, a = 1.0 }, -- white
{ r = 0.7, g = 0.7, b = 0.7, a = 0.7 }, -- transparent gray
},
paletteState = 2,
}
local classColorPalette = {
{ r = 0.77, g = 0.12, b = 0.23, a = 1.0 }, -- Death Knight red
{ r = 0.64, g = 0.19, b = 0.79, a = 1.0 }, -- Demon Hunter Magenta
{ r = 1.00, g = 0.49, b = 0.04, a = 1.0 }, -- Druid Orange
{ r = 0.20, g = 0.57, b = 0.50, a = 1.0 }, -- Evoker Green
{ r = 0.67, g = 0.83, b = 0.45, a = 1.0 }, -- Hunter Green
{ r = 0.41, g = 0.80, b = 0.94, a = 1.0 }, -- Mage Blue
{ r = 0.00, g = 1.00, b = 0.59, a = 1.0 }, -- Monk Green
{ r = 0.96, g = 0.55, b = 0.73, a = 1.0 }, -- Paladin Pink
{ r = 1.00, g = 1.00, b = 1.00, a = 1.0 }, -- Priest White
{ r = 1.00, g = 0.96, b = 0.41, a = 1.0 }, -- Rogue Yellow
{ r = 0.00, g = 0.44, b = 0.87, a = 1.0 }, -- Shaman Blue
{ r = 0.58, g = 0.51, b = 0.79, a = 1.0 }, -- Warlock Purple
{ r = 0.78, g = 0.61, b = 0.43, a = 1.0 }, -- Warrior Tan
}
if isClassic then
tremove(classColorPalette, 7) -- Monk
tremove(classColorPalette, 4) -- Evoker
tremove(classColorPalette, 2) -- Demon Hunter
tremove(classColorPalette, 1) -- Death Knight
elseif isCata then
tremove(classColorPalette, 7) -- Monk
tremove(classColorPalette, 4) -- Evoker
tremove(classColorPalette, 2) -- Demon Hunter
end
--EVENT REGISTRATION
-------------------------------------------------------------------------------------------------------------------------
-- these need to happen inline at lua file load time
local eventFrame = CreateFrame("Frame")
eventFrame:Hide()
eventFrame:SetScript("OnEvent", function(self, event, ...)
if MOD[event] then
MOD[event](self, ...)
end
end)
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("PLAYER_LOGIN")
-------------------------------------------------------------------------------------------------------------------------
-- utility functions
-- Convert r, g, b input values into h, s, v return values
-- All values are in the range 0 to 1.0
local function RGB_to_HSV(r, g, b)
local mincolor, maxcolor = math.min(r, g, b), math.max(r, g, b)
local ch, cs, cv = 0, 0, maxcolor
if maxcolor > 0 then -- technically ch is undefined if cs is zero
local delta = maxcolor - mincolor
cs = delta / maxcolor
if delta > 0 then -- don't allow divide by zero
if r == maxcolor then
ch = (g - b) / delta -- between yellow and magenta
elseif g == maxcolor then
ch = 2 + ((b - r) / delta) -- between cyan and yellow
else
ch = 4 + ((r - g) / delta) -- between magenta and cyan
end
end
if ch < 0 then
ch = ch + 6
end -- correct for negative values
ch = ch / 6 -- and finally adjust range 0 to 1.0
end
return ch, cs, cv
end
-- Convert h, s, l input values into r, g, b return values
-- All values are in the range 0 to 1.0
local function HSV_to_RGB(ch, cs, cv)
if not ch or not cs or not cv then
return 1, 0, 0
end
if ch == 1 then
ch = 0
end
local r, g, b = cv, cv, cv
if cs > 0 then -- if cs is zero then grey is returned
local h = ch * 6
local sextant = math.floor(h) -- figure out which sextant of the color wheel
local fractionalOffset = h - sextant -- fractional offset into the sextant
local p, q, t = cv * (1 - cs), cv * (1 - (cs * fractionalOffset)), cv * (1 - (cs * (1 - fractionalOffset)))
if sextant == 0 then
r, g, b = cv, t, p
elseif sextant == 1 then
r, g, b = q, cv, p
elseif sextant == 2 then
r, g, b = p, cv, t
elseif sextant == 3 then
r, g, b = p, q, cv
elseif sextant == 4 then
r, g, b = t, p, cv
else
r, g, b = cv, p, q
end
end
return r, g, b
end
function MOD:SetColor(r, g, b)
if isTWW then
ColorPickerFrame.Content.ColorPicker:SetColorRGB(r, g, b)
else
ColorPickerFrame:SetColorRGB(r, g, b)
end
ColorPickerFrame.swatchFunc()
MOD:UpdateHSVfromColorPickerRGB()
end
function MOD:SetAlpha(a)
if isTWW then
ColorPickerFrame.Content.ColorPicker:SetColorAlpha(a)
else
opacitySliderFrame:SetValue(1 - a)
end
end
function MOD:UpdateHSVfromColorPickerRGB()
colorHue, colorSat, colorVal = RGB_to_HSV(ColorPickerFrame:GetColorRGB())
end
function MOD:SetRGBfromHSV()
if isTWW then
ColorPickerFrame.Content.ColorPicker:SetColorRGB(HSV_to_RGB(colorHue, colorSat, colorVal))
else
ColorPickerFrame:SetColorRGB(HSV_to_RGB(colorHue, colorSat, colorVal))
end
end
function MOD:GetAlpha()
local colorAlpha
if ColorPickerFrame.hasOpacity then
if isTWW then
colorAlpha = ColorPickerFrame:GetColorAlpha()
else
colorAlpha = 1 - opacitySliderFrame:GetValue()
end
else
colorAlpha = 1
end
return colorAlpha
end
function MOD:UpdateGradientColorOverlay() -- assumes color variables all set prior
local r, g, b = HSV_to_RGB(colorHue, 1, 1)
ColorPPColorOverlay:SetVertexColor(r, g, b)
end
function MOD:UpdateChosenColor()
local r, g, b = ColorPickerFrame:GetColorRGB()
local a = MOD:GetAlpha()
ColorPPChosenColor:SetBackdropColor(r, g, b, a)
end
function MOD:UpdateOldColor(r, g, b, a)
ColorPPOldColor:SetBackdropColor(r, g, b, a)
end
function MOD.ADDON_LOADED(ev, name)
if name == "ColorPickerPlus" then
DB = ColorPickerPlusDB
if DB then
if not DB.palette then
DB.palette = defaults.palette
end
if not DB.paletteState then
DB.paletteState = defaults.paletteState
end
else
ColorPickerPlusDB = defaults
DB = ColorPickerPlusDB
end
end
end
-- functions to update thumb cursors
function MOD:UpdateGradientThumb()
local rx = (colorSat * gradientWidth) -- use saturation and brightness to adjust gradient selection point
local ry = (colorVal * gradientHeight)
ColorPPColorGradientThumb:ClearAllPoints()
-- allow for 5 pixel border around gradient, which allows user to 'grab' thumb and move it to edge of gradient
if rx == 0 then
rx = borderSize
elseif rx > gradientWidth - borderSize then
rx = rx - borderSize
end
if ry == 0 then
ry = borderSize
elseif ry > gradientHeight - borderSize then
ry = ry - borderSize
end
ColorPPColorGradientThumb:SetPoint("CENTER", ColorPPGradient, "BOTTOMLEFT", rx, ry)
end
function MOD:UpdateOpacityBarThumb()
local a
if isTWW then
a = ColorPickerFrame:GetColorAlpha()
else
a = opacitySliderFrame:GetValue()
end
local ry = a * opacityBarHeight
ColorPPOpacityBarThumb:ClearAllPoints()
ColorPPOpacityBarThumb:SetPoint("CENTER", ColorPPOpacityBar, "BOTTOM", 0, ry)
end
function MOD:UpdateHueBarThumb()
local ry = colorHue * hueBarHeight
if colorHue < 0.5 then
ry = ry + 1
else
ry = ry - 1
end -- adjust for thumb position at ends of bar
ColorPPHueBarThumb:ClearAllPoints()
ColorPPHueBarThumb:SetPoint("CENTER", ColorPPHueBar, "TOP", 0, -ry)
end
function MOD:UpdateColorGraphics()
MOD:UpdateChosenColor()
MOD:UpdateGradientColorOverlay()
MOD:UpdateGradientThumb()
MOD:UpdateHueBarThumb()
end
function MOD:ShowHideAlpha()
-- show/hide the alpha box and adjust related components
if ColorPickerFrame.hasOpacity then
opacitySliderFrame:Hide() -- have to do this every time
ColorPPOpacityBar:Show()
ColorPPBoxA:Show()
ColorPPBoxLabelA:Show()
ColorPickerFrame:SetWidth(dialogWidthWithOpacity)
MOD:UpdateOpacityBarThumb()
else
ColorPPOpacityBar:Hide()
ColorPPBoxA:Hide()
ColorPPBoxLabelA:Hide()
ColorPickerFrame:SetWidth(dialogWidthNoOpacity)
end
end
function MOD:Hooked_OnShow(...)
local r, g, b = ColorPickerFrame:GetColorRGB()
colorHue, colorSat, colorVal = RGB_to_HSV(r, g, b) -- store HSV values in our own variables
MOD:ShowHideAlpha()
MOD:UpdateOldColor(r, g, b, MOD:GetAlpha())
MOD:UpdateColorGraphics()
MOD:UpdateColorTexts()
MOD:UpdateAlphaText()
end
function MOD:CleanUpColorPickerFrame()
-- First, disable some standard Blizzard components
if isTWW then
ColorPickerFrame:Hide()
ColorPickerFrame.Content:Hide()
ColorPickerFrame.Content.ColorPicker:Hide()
ColorPickerFrame.Content.ColorSwatchCurrent:Hide()
ColorPickerFrame.Content.HexBox:Hide()
ColorPickerFrame.Content.ColorPicker.Alpha:Hide()
ColorPickerFrame.Content.ColorPicker.AlphaThumb:Hide()
ColorPickerFrame.Content.AlphaBackground:Hide()
else
ColorPickerFrame:GetColorWheelThumbTexture():Hide()
ColorPickerFrame:GetColorValueTexture():Hide()
ColorPickerFrame:GetColorValueThumbTexture():Hide()
ColorPickerWheel:Hide()
opacitySliderFrame:Hide()
end
-- Hide the "Color Picker" dialog title
local children = { ColorPickerFrame:GetRegions() }
for _, v in ipairs(children) do
if v:IsObjectType("FontString") then
if v:GetText() == COLOR_PICKER then
v:Hide()
end
end
end
-- Add the "Color Picker Plus" dialog title
if isClassic or isCata then
local t = ColorPickerFrame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
t:SetFontObject("GameFontNormal")
t:SetText("Color Picker Plus")
t:SetPoint("TOP", ColorPickerFrameHeader, "TOP", 0, -14)
else
ColorPickerFrame.Header:Hide()
local h = CreateFrame("Frame", "ColorPPHeaderTitle", ColorPickerFrame, "DialogHeaderTemplate")
local t = h:CreateFontString(nil, "ARTWORK", "GameFontNormal")
t:SetFontObject("GameFontNormal")
t:SetText("Color Picker Plus")
t:SetPoint("TOP", h, "TOP", 0, -14)
end
-- make the color picker movable.
local mover = CreateFrame("Frame", nil, ColorPickerFrame)
mover:SetPoint("TOPLEFT", ColorPickerFrame, "TOP", -60, 0)
mover:SetPoint("BOTTOMRIGHT", ColorPickerFrame, "TOP", 60, -15)
mover:EnableMouse(true)
mover:SetScript("OnMouseDown", function()
ColorPickerFrame:StartMoving()
end)
mover:SetScript("OnMouseUp", function()
ColorPickerFrame:StopMovingOrSizing()
end)
mover:SetScript("OnHide", function()
ColorPickerFrame:StopMovingOrSizing()
end)
ColorPickerFrame:SetUserPlaced(true)
ColorPickerFrame:SetClampedToScreen(true) -- keep color picker frame on-screen
ColorPickerFrame:SetClampRectInsets(120, -120, 0, 90) -- but allow for dragging partially off to sides and down
ColorPickerFrame:EnableKeyboard(false)
-- make the Color Picker dialog a bit taller to accommodate new widget layout
-- width must be handled in the onShow script
ColorPickerFrame:SetHeight(dialogHeight)
end
function MOD:CreateCheckerboardBG(fr, dense, w, h)
local t = fr:CreateTexture("ColorPPCheckerboard", "BACKGROUND", nil, -3)
t:SetSize(w, h)
if dense then
t:SetTexture("Interface\\AddOns\\ColorPickerPlus\\media\\checkerboard16")
else
t:SetTexture("Interface\\AddOns\\ColorPickerPlus\\media\\checkerboard8")
end
t:SetPoint("TOPLEFT", fr, "TOPLEFT", 0, 0)
return t
end
local function OldColorOnMouseUp(frame, button)
if frame:IsMouseOver() and button == "LeftButton" then
-- Set the chosen color to the old color
local r, g, b, a = frame:GetBackdropColor()
-- update color and opacity variables
MOD:SetColor(r, g, b)
MOD:SetAlpha(a)
MOD:UpdateColorGraphics()
MOD:UpdateColorTexts()
MOD:UpdateAlphaText()
end
end
local function ChosenColorOnMouseUp(frame, button)
if frame:IsMouseOver() and button == "LeftButton" and IsControlKeyDown() then
local r, g, b, a = frame:GetBackdropColor()
-- print chosen color in [0-1] RGB to the chat window
print("ColorPickerPlus color in [0-1] RGB: r = ", string.format("%.3f", r), " g = ", string.format("%.3f", g), " b = ", string.format("%.3f", b))
end
end
function MOD:CreateColorSwatches()
local fh = CreateFrame("Frame", "ColorPPSwatches", ColorPickerFrame)
fh:SetSize(colorSwatchWidth, colorSwatchHeight)
MOD:CreateCheckerboardBG(fh, true, colorSwatchWidth, colorSwatchHeight)
fh:SetPoint("BOTTOM", ColorPPPaletteFrame, "BOTTOM", 0, 0)
fh:SetPoint("LEFT", ColorPPBoxR, "LEFT", -14, 0)
-- create frame for the old color that was passed in, to display color as its backdrop color
local fr = CreateFrame("Frame", "ColorPPOldColor", fh, "BackdropTemplate")
fr:SetBackdrop(bgTable)
fr:SetFrameLevel(ColorPickerFrame:GetFrameLevel() + 1)
fr:SetSize(colorSwatchWidth, colorSwatchHeight * 0.35)
fr:ClearAllPoints()
fr:SetPoint("TOPLEFT", fh, "TOPLEFT")
fr:SetBackdropColor(0, 0, 0, 1)
fr:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
fr:SetScript("OnMouseUp", OldColorOnMouseUp)
fr:Show()
-- create frame for the chosen color for backdrop
fr = CreateFrame("Frame", "ColorPPChosenColor", ColorPickerFrame, "BackdropTemplate")
fr:SetBackdrop(bgTable)
fr:SetSize(colorSwatchWidth, colorSwatchHeight * 0.65)
fr:ClearAllPoints()
fr:SetPoint("TOPLEFT", ColorPPOldColor, "BOTTOMLEFT", 0, 0)
fr:SetBackdropColor(0, 0, 0, 1)
fr:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
fr:SetScript("OnMouseUp", ChosenColorOnMouseUp)
fr:Show()
end
function MOD:CreateCopyPasteArea()
-- create frame for buttons and copiedColorSwatch
fr = CreateFrame("Frame", "ColorPPCopyPasteArea", ColorPPPaletteFrame, "BackdropTemplate")
fr:SetBackdrop(bgTable)
fr:SetSize(gradientWidth - 10, gradientHeight - 10)
fr:ClearAllPoints()
fr:SetPoint("CENTER", ColorPPPaletteFrame, "CENTER", 0, 0)
fr:SetBackdropColor(0.4, 0.4, 0.4, 0)
fr:SetBackdropBorderColor(0.4, 0.4, 0.4, 0)
fr:Show()
-- Create copiedColorSwatch
local f = CreateFrame("Frame", "ColorPPCopiedColor", fr, "BackdropTemplate")
local x = colorSwatchHeight * 0.65
f:SetBackdrop(bgTable)
f:SetBackdropColor(0, 0, 0, 0)
f:SetBackdropBorderColor(0.1, 0.1, 0.1, 1)
f:SetSize(x, x)
MOD:CreateCheckerboardBG(f, true, x, x)
f:ClearAllPoints()
f:SetPoint("LEFT", fr, "LEFT", 0, 0)
f:SetPoint("BOTTOM", fr, "BOTTOM", 0, 0)
-- create label for buffer swatch
-- local t = fr:CreateFontString(fr)
-- t:SetFontObject("GameFontNormal")
-- t:SetText("Buffer")
-- t:SetTextColor(0.5,0.5,0.5,1)
-- t:SetPoint("BOTTOM", ColorPPCopiedColor, "TOP", 0, 5)
-- t:Show()
-- add copy button
local copyButton = CreateFrame("Button", "ColorPPCopy", fr, "UIPanelButtonTemplate")
copyButton:SetText("<-- Copy")
copyButton:SetWidth(80)
copyButton:SetHeight(22)
copyButton:SetScale(0.80)
copyButton:SetPoint("TOP", "ColorPPCopiedColor", "TOP", 0, -20)
copyButton:SetPoint("RIGHT", "ColorPPCopyPasteArea", "RIGHT", 0, 0)
-- copy color into buffer on button click
copyButton:SetScript("OnClick", function(self)
-- copy current dialog colors into buffer
local r, g, b = ColorPickerFrame:GetColorRGB()
local a = MOD:GetAlpha()
ColorPPCopiedColor:SetBackdropColor(r, g, b, a)
ColorPPPaste:Enable()
end)
-- add paste button to the ColorPickerFrame
pasteButton = CreateFrame("Button", "ColorPPPaste", fr, "UIPanelButtonTemplate")
pasteButton:SetText("Paste -->")
pasteButton:SetWidth(80)
pasteButton:SetHeight(22)
pasteButton:SetScale(0.8)
pasteButton:SetPoint("TOPRIGHT", "ColorPPCopy", "BOTTOMRIGHT", 0, -10)
pasteButton:Disable() -- enable when something has been copied
-- paste color on button click, updating frame components
pasteButton:SetScript("OnClick", function(self)
local r, g, b, a = ColorPPCopiedColor:GetBackdropColor()
-- update color and opacity variables
MOD:SetColor(r, g, b)
MOD:SetAlpha(a)
MOD:UpdateColorGraphics()
MOD:UpdateColorTexts()
MOD:UpdateAlphaText()
end)
end
local function PaletteSwatchOnMouseUp(frame, button)
local r, g, b, a
if frame:IsMouseOver() then
if button == "LeftButton" then
if IsModifierKeyDown() then
if IsShiftKeyDown() then -- Set the swatch color to the chosen color
r, g, b, a = ColorPPChosenColor:GetBackdropColor()
frame:SetBackdropColor(r, g, b, a)
local c = DB.palette[frame._cppKey]
c.r = r
c.g = g
c.b = b
c.a = a
end
else -- Set the chosen color to the swatch color
r, g, b, a = frame:GetBackdropColor()
MOD:SetColor(r, g, b)
MOD:SetAlpha(a)
MOD:UpdateColorGraphics()
MOD:UpdateColorTexts()
MOD:UpdateAlphaText()
end
end
end
end
function MOD:CreatePalette()
local rows = 6
local cols = 6 -- set to work for square matrix currently
local spacer = 2
local margin = 0
local swatchSize = 20
-- create frame for palette
fr = CreateFrame("Frame", "ColorPPPalette", ColorPPPaletteFrame, "BackdropTemplate")
fr:SetBackdrop(bgTable)
fr:SetSize((cols * swatchSize) + ((cols - 1) * spacer) + (2 * margin), (rows * swatchSize) + ((rows - 1) * spacer) + (2 * margin))
fr:ClearAllPoints()
fr:SetPoint("CENTER", ColorPPPaletteFrame, "CENTER", 0, 0)
fr:SetPoint("BOTTOM", ColorPPPaletteFrame, "BOTTOM", 0, 0)
fr:SetBackdropColor(0.4, 0.4, 0.4, 0)
fr:SetBackdropBorderColor(0.4, 0.4, 0.4, 0)
fr:Show()
-- Create Palette Swatches
local i, j, k = 0, 0, 0
for j = 1, rows do
for i = 1, cols do
k = k + 1
local c = DB.palette[k]
local f = CreateFrame("Frame", "ColorPPswatch_" .. tostring(k), fr, "BackdropTemplate")
f._cppKey = k
f:SetBackdrop(bgTable)
f:SetBackdropColor(c.r, c.g, c.b, c.a)
f:SetBackdropBorderColor(0, 0, 0, c.a)
f:SetSize(swatchSize, swatchSize)
MOD:CreateCheckerboardBG(f, false, swatchSize, swatchSize)
f:ClearAllPoints()
f:SetPoint("TOPLEFT", fr, "TOPLEFT", margin + (spacer * (i - 1)) + ((i - 1) * swatchSize), -(margin + (spacer * (j - 1)) + ((j - 1) * swatchSize)))
f:SetScript("OnMouseUp", PaletteSwatchOnMouseUp)
end
end
end
local function ClassPaletteSwatchOnMouseUp(frame, button)
local r, g, b, a
if frame:IsMouseOver() then
-- Set the chosen color to the swatch color
r, g, b, a = frame:GetBackdropColor()
MOD:SetColor(r, g, b)
MOD:SetAlpha(a)
MOD:UpdateColorGraphics()
MOD:UpdateColorTexts()
MOD:UpdateAlphaText()
end
end
function MOD:CreateClassPalette()
local rows = isTWW and 4 or 3
local cols = 4
local spacer = 2
local margin = 0
local swatchSize = 20
-- create frame for palette
local fr = CreateFrame("Frame", "ColorPPClassPalette", ColorPPPaletteFrame, "BackdropTemplate")
fr:SetBackdrop(bgTable)
fr:SetSize((cols * swatchSize) + ((cols - 1) * spacer) + (2 * margin), (rows * swatchSize) + ((rows - 1) * spacer) + (2 * margin))
fr:ClearAllPoints()
fr:SetPoint("CENTER", ColorPPPaletteFrame, "CENTER", 0, -5)
fr:SetBackdropColor(0.4, 0.4, 0.4, 0)
fr:SetBackdropBorderColor(0.4, 0.4, 0.4, 0)
fr:Show()
-- create label for frame
local t = fr:CreateFontString(nil, "OVERLAY", "GameFontNormal")
t:SetText("Class Colors")
t:SetTextColor(1, 1, 1, 1)
t:SetPoint("BOTTOM", fr, "TOP", 0, 5)
t:Show()
-- Create Palette Swatches
local i, j, k = 0, 0, 0
for j = 1, rows do
for i = 1, cols do
k = k + 1
local c = classColorPalette[k]
if not c then
break
end
local f = CreateFrame("Frame", "ColorPPswatch_" .. tostring(k), fr, "BackdropTemplate")
f._cppKey = k
f:SetBackdrop(bgTable)
f:SetBackdropColor(c.r, c.g, c.b, c.a)
f:SetBackdropBorderColor(0, 0, 0, c.a)
f:SetSize(swatchSize, swatchSize)
MOD:CreateCheckerboardBG(f, false, swatchSize, swatchSize)
f:ClearAllPoints()
f:SetPoint("TOPLEFT", fr, "TOPLEFT", margin + (spacer * (i - 1)) + ((i - 1) * swatchSize), -(margin + (spacer * (j - 1)) + ((j - 1) * swatchSize)))
f:SetScript("OnMouseUp", ClassPaletteSwatchOnMouseUp)
end
end
end
local function GradientOnMouseDown(self, button)
if self:IsMouseOver() and IsMouseButtonDown(LeftButton) then
if not (lockedHueBar or lockedOpacityBar) then
lockedGradient = true
if ColorPickerFrame.hasOpacity then
if isTWW then
lockedOpacity = ColorPickerFrame:GetColorAlpha()
else
lockedOpacity = 1 - opacitySliderFrame:GetValue()
end
else
lockedOpacity = 1
end
end
end
end
local function GradientOnUpdate(self)
if IsMouseButtonDown(LeftButton) then
if lockedHueBar or lockedOpacityBar then
return
end
if lockedGradient then -- begin to track motion, until button release
-- Get the bounds of the frame and account for any Scale settings
-- note that position is within 5 pixel border on each side
local scale = ColorPickerFrame:GetScale() -- We inherit scale from our "parent" the ColorPickerFrame
local top = (self:GetTop() * scale) + borderSize
local bottom = (self:GetBottom() * scale) - borderSize
local left = (self:GetLeft() * scale) + borderSize
local right = (self:GetRight()) * scale - borderSize
local height = top - bottom
local width = right - left
-- Get the cursor position and account for any UI Scale settings
local uiScale = UIParent:GetEffectiveScale()
local x, y = GetCursorPosition()
x = x / uiScale
y = y / uiScale
local mousePosX = right - x
local mousePosY = top - y
if y < bottom then
colorVal = 0
elseif y > top then
colorVal = 1
else
colorVal = 1 - (mousePosY / height)
if colorVal < 0 then
colorVal = 0
end
end
if x < left then
colorSat = 0
elseif x > right then
colorSat = 1
else
colorSat = 1 - (mousePosX / width)
if colorSat < 0 then
colorSat = 0
end
end
local r, g, b = HSV_to_RGB(colorHue, colorSat, colorVal)
MOD:SetColor(r, g, b)
ColorPPChosenColor:SetBackdropColor(r, g, b, lockedOpacity)
MOD:UpdateColorTexts()
MOD:UpdateGradientThumb()
end
else
lockedGradient = false
lockedHueBar = false
lockedOpacityBar = false
end
end
function MOD:CreateColorGradient() -- allows selection of saturation/value
local f = CreateFrame("Frame", "ColorPPGradient", ColorPickerFrame)
f:SetSize(gradientWidth, gradientHeight)
f:SetPoint("TOPLEFT", ColorPPHueBar, "TOPRIGHT", spacing, 5)
f:EnableMouse(true)
f:SetScript("OnMouseDown", GradientOnMouseDown)
f:SetScript("OnUpdate", GradientOnUpdate)
-- add Color Gradient
local t = f:CreateTexture("ColorPPGradientTexture")
t:SetSize(gradientWidth - 10, gradientHeight - 10)
t:SetTexture("Interface\\AddOns\\ColorPickerPlus\\media\\color_gradient")
t:SetPoint("CENTER", ColorPPGradient, "CENTER", 0, 0)
t:Show()
-- add Color Overlay
t = f:CreateTexture("ColorPPColorOverlay", "OVERLAY", nil, 0)
t:SetSize(gradientWidth - 10, gradientHeight - 10)
t:SetTexture("Interface\\AddOns\\ColorPickerPlus\\media\\color_overlay")
t:SetPoint("CENTER", ColorPPGradient, "CENTER", 0, 0)
t:Show()
-- add gradient thumb texture
t = f:CreateTexture("ColorPPColorGradientThumb", "OVERLAY", nil, 1)
t:SetSize(10, 10)
--t:SetTexture("Interface\\AddOns\\ColorPickerPlus\\media\\cursor2")
t:SetTexture("Interface\\Buttons\\UI-ColorPicker-Buttons")
t:SetTexCoord(0, 0.15625, 0, 0.625)
t:SetPoint("CENTER", ColorPPGradientTexture, "CENTER", 0, 0)
t:Show()
end
local function HueBarOnMouseDown(self, button)
if self:IsMouseOver() and IsMouseButtonDown(LeftButton) then
if not (lockedGradient or lockedOpacityBar) then
lockedHueBar = true
if ColorPickerFrame.hasOpacity then
if isTWW then
lockedOpacity = ColorPickerFrame:GetColorAlpha()
else
lockedOpacity = 1 - opacitySliderFrame:GetValue()
end
else
lockedOpacity = 1
end
MOD:UpdateHueBarThumb()
end
end
end
local function HueBarOnUpdate(self) -- it's actually the holder that receives this call
if IsMouseButtonDown(LeftButton) then
if lockedGradient or lockedOpacityBar then
return
end
if lockedHueBar then -- tracking mouse in or out of bar
local fr = ColorPPHueBar
-- Get the bounds of the frame and account for any Scale settings
local scale = ColorPickerFrame:GetScale()
local top = fr:GetTop() * scale
local bottom = fr:GetBottom() * scale
local left = fr:GetLeft() * scale
local right = fr:GetRight() * scale
local height = top - bottom
-- Get the cursor position and account for any UI Scale settings
local uiScale = UIParent:GetEffectiveScale()
local x, y = GetCursorPosition()
x = x / uiScale
y = y / uiScale
if y < bottom then
colorHue = 1
elseif y > top then
colorHue = 0
else
colorHue = (top - y) / height
end
local r, g, b = HSV_to_RGB(colorHue, colorSat, colorVal)
MOD:SetColor(r, g, b)
MOD:UpdateColorTexts()
ColorPPChosenColor:SetBackdropColor(r, g, b, lockedOpacity)
ColorPPColorOverlay:SetVertexColor(HSV_to_RGB(colorHue, 1, 1))
MOD:UpdateHueBarThumb()
end
else
lockedGradient = false
lockedHueBar = false
lockedOpacityBar = false
return
end
end
function MOD:CreateHueBar()
local fh = CreateFrame("Frame", "ColorPPHueBarHolder", ColorPickerFrame)
fh:SetSize(hueBarWidth + 6, hueBarHeight + 8)
fh:SetPoint("TOPLEFT", ColorPickerFrame, "TOPLEFT", sideMargin, -topMargin)
local f = CreateFrame("Frame", "ColorPPHueBar", fh)
f:SetSize(hueBarWidth, hueBarHeight)
f:SetPoint("CENTER", fh, "CENTER")
fh:EnableMouse(true)
fh:SetScript("OnUpdate", HueBarOnUpdate)
fh:SetScript("OnMouseDown", HueBarOnMouseDown)
local color = {
{ r = 1.0, g = 0.0, b = 0.0 }, -- Red
{ r = 1.0, g = 1.0, b = 0.0 }, -- Yellow
{ r = 0.0, g = 1.0, b = 0.0 }, -- Green
{ r = 0.0, g = 1.0, b = 1.0 }, -- Cyan
{ r = 0.0, g = 0.0, b = 1.0 }, -- Blue
{ r = 1.0, g = 0.0, b = 1.0 }, -- Purple
{ r = 1.0, g = 0.0, b = 0.0 }, -- Red again
}
for i = 1, 6 do
local t = f:CreateTexture("ColorPPHue" .. tostring(i), "OVERLAY")
if i == 1 then
t:SetPoint("TOP", ColorPPHueBar, "TOP", 0, 0)
else
t:SetPoint("TOP", "ColorPPHue" .. tostring(i - 1), "BOTTOM", 0, 0)
end
t:SetSize(hueBarWidth, hueTextureSize)
t:SetVertexColor(1.0, 1.0, 1.0, 1.0)
t:SetColorTexture(1.0, 1.0, 1.0, 1.0)
t:SetGradient("VERTICAL", CreateColor(color[i + 1].r, color[i + 1].g, color[i + 1].b, 1), CreateColor(color[i].r, color[i].g, color[i].b, 1))
end
-- Thumb indicates value position on the slider
local thumb = f:CreateTexture("ColorPPHueBarThumb", "OVERLAY")
thumb:SetTexture("Interface\\AddOns\\ColorPickerPlus\\Media\\SliderVBar.tga")
thumb:SetSize(hueBarWidth + 6, 8)
end
local function OpacityBarOnMouseDown(self, button)
if self:IsMouseOver() and IsMouseButtonDown(LeftButton) then
if not (lockedHueBar or lockedGradient) then
lockedOpacityBar = true
MOD:UpdateOpacityBarThumb()
end
end
end
local function OpacityBarOnUpdate(self)
if IsMouseButtonDown(LeftButton) then
if lockedGradient or lockedHueBar then
return
end
if lockedOpacityBar then -- tracking mouse in or out of bar
-- Get the bounds of the frame and account for any Scale settings
local scale = ColorPickerFrame:GetScale() -- We inherit scale from our "parent" the ColorPickerFrame
local top = self:GetTop() * scale
local bottom = self:GetBottom() * scale
local left = self:GetLeft() * scale
local right = self:GetRight() * scale
local height = top - bottom
-- Get the cursor position and account for any UI Scale settings
local uiScale = UIParent:GetEffectiveScale()
local x, y = GetCursorPosition()
x = x / uiScale
y = y / uiScale
local a
if y < bottom then
a = 0
elseif y > top then
a = 1
else
a = 1 - ((top - y) / height)
end
if isTWW then
ColorPickerFrame.Content.ColorPicker:SetColorAlpha(a)
MOD:UpdateAlphaText()
local r, g, b = ColorPickerFrame:GetColorRGB()
ColorPPChosenColor:SetBackdropColor(r, g, b, a)
else
-- blizzard reverse alpha
opacitySliderFrame:SetValue(a)
MOD:UpdateAlphaText()
local r, g, b = ColorPickerFrame:GetColorRGB()
ColorPPChosenColor:SetBackdropColor(r, g, b, 1 - a)
end
end
else
lockedGradient = false
lockedHueBar = false
lockedOpacityBar = false
return
end
end
function MOD:CreateOpacityBar()
local f = CreateFrame("Frame", "ColorPPOpacityBar", ColorPickerFrame)
f:SetSize(opacityBarWidth, opacityBarHeight)
f:SetPoint("TOP", ColorPickerFrame, "TOP", 0, -topMargin)
f:EnableMouse(true)
f:SetScript("OnUpdate", OpacityBarOnUpdate)
f:SetScript("OnMouseDown", OpacityBarOnMouseDown)
local t = f:CreateTexture("ColorPPOpacityBarBG", "OVERLAY")
t:SetPoint("TOP", ColorPPOpacityBar, "TOP", 0, 0)
t:SetSize(opacityBarWidth, opacityBarHeight)
t:SetVertexColor(1.0, 1.0, 1.0, 1.0)
t:SetColorTexture(1.0, 1.0, 1.0, 1.0)
t:SetGradient("VERTICAL", CreateColor(1, 1, 1, 1), CreateColor(0, 0, 0, 1))
-- Thumb indicates value position on the slider
local thumb = f:CreateTexture("ColorPPOpacityBarThumb", "OVERLAY", nil, 4)
thumb:SetTexture("Interface\\AddOns\\ColorPickerPlus\\Media\\SliderVBar.tga")
thumb:SetSize(opacityBarWidth + 6, 8)
thumb:SetPoint("CENTER", f, "CENTER", 0, 0)
f:ClearAllPoints()
f:SetPoint("TOP", ColorPPHueBar, "TOP", 0, 0)
f:SetPoint("RIGHT", "ColorPickerFrame", "RIGHT", -sideMargin, 0)
end
function MOD:CreateTextBoxes()