-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
756 lines (525 loc) · 20 KB
/
main.lua
File metadata and controls
756 lines (525 loc) · 20 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
local folderName = ...
local math_max = _G.math.max
local math_min = _G.math.min
local math_floor = _G.math.floor
local ButtonFrameTemplate_HidePortrait = _G.ButtonFrameTemplate_HidePortrait
local function Round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math_floor(num * mult + 0.5) / mult
end
---------------------
-- Constants --------
---------------------
local PIXEL_FILE_PATH = "Interface/BUTTONS/WHITE8X8"
local CONFIG_FRAME_WIDTH = 400
local CONFIG_FRAME_HEIGHT = 550
local GRAPH_WIDTH_MIN = 50
local GRAPH_WIDTH_MAX = 1000
local GRAPH_HEIGHT_MIN = 50
local GRAPH_HEIGHT_MAX = 600
local GRAPH_BAR_THICKNESS_MIN = 1
local GRAPH_BAR_THICKNESS_MAX = 10
local FRAMES_PER_GRAPH_BAR_MIN = 1
local FRAMES_PER_GRAPH_BAR_MAX = 30
local Y_AXIS_TOP_MIN = 1
local Y_AXIS_TOP_MAX = 300
local Y_AXIS_BOTTOM_MIN = 0
local Y_AXIS_BOTTOM_MAX = 299
local GRAPH_LINE_THICKNESS_MIN = 1
local GRAPH_LINE_THICKNESS_MAX = 10
local CONFIG_DEFAULTS = {
graphAnchor = "CENTER",
graphX = 0,
graphY = 0,
graphWidth = 300,
graphHeight = 120,
graphBarThickness = 3,
framesPerGraphBar = 4,
show = {
max = true,
avg = true,
min = true,
},
color = {
max = {1.0, 1.0, 1.0},
avg = {0.8, 0.8, 0.8},
min = {0.6, 0.6, 0.6},
},
yAxisTop = 120,
yAxisTopDynamic = false,
yAxisBottom = 0,
yAxisBottomDynamic = false,
graphLineThickness = 1,
}
---------------------
-- Locals -----------
---------------------
-- Forward declaration.
local UpdateGraphBarsColor
local RefreshGraph
local OneFrameMode
local config
-- The graph frame.
local gf = nil
local numberOfVisibleBars = 0
local numberOfCreatedBars = 0
-- To calculate the per bar values.
local frameCounter = 0
local minFPS = 99999
local maxFPS = 0
local sumFPS = 0
local graphBars = {
max = {},
avg = {},
min = {},
}
local graphBarValues = {
max = {},
avg = {},
min = {},
}
local graphBarValuesFirstIndex = 0
local graphLines = {}
local horizontalGridLines = {}
local verticalGridLines = {}
-- local function DrawFilledBox(f, bottomLeftX, bottomLeftY, topRightX, topRightY, r, g, b, a)
-- local box = f:CreateTexture()
-- box:SetTexture(PIXEL_FILE_PATH)
-- box:SetColorTexture(r, g, b, a)
-- box:SetPoint("BOTTOMLEFT", bottomLeftX, bottomLeftY)
-- box:SetSize(topRightX-bottomLeftX, topRightY-bottomLeftY)
-- end
-- local function DrawEmptyBox(f, bottomLeftX, bottomLeftY, topRightX, topRightY, linewidth, r, g, b, a)
-- -- LTTTTTTT
-- -- L R
-- -- L R
-- -- L R
-- -- BBBBBBBR
-- -- Bottom line
-- DrawFilledBox(f, bottomLeftX, bottomLeftY, bottomLeftX+topRightX-linewidth, bottomLeftY+linewidth, r, g, b, a)
-- -- Top line
-- DrawFilledBox(f, bottomLeftX+linewidth, topRightY-linewidth, bottomLeftX+topRightX, bottomLeftY+topRightY, r, g, b, a)
-- -- Left line
-- DrawFilledBox(f, bottomLeftX, bottomLeftY+linewidth, bottomLeftX+linewidth, bottomLeftY+topRightY, r, g, b, a)
-- -- Right line
-- DrawFilledBox(f, bottomLeftX+topRightX-linewidth, bottomLeftY, topRightX, bottomLeftY+topRightY-linewidth, r, g, b, a)
-- end
local function ColorPickerCallback(restore)
local variableSuffix = ColorPickerFrame.variableSuffix
local oldR, oldG, oldB, oldA = unpack(config.color[variableSuffix])
local newR, newG, newB, newA
if restore then
-- The user bailed, we extract the old color from the table created by ShowColorPicker.
newR, newG, newB, newA = unpack(restore)
else
-- Something changed
newA, newR, newG, newB = 1-OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB()
end
if oldR ~= newR or oldG ~= newG or oldB ~= newB or oldA ~= newA then
config.color[variableSuffix] = {newR, newG, newB, newA}
UpdateGraphBarsColor(graphBars[variableSuffix], config.color[variableSuffix])
_G["fpsGraph_"..variableSuffix.."ColorButton"].foreground:SetColorTexture(newR, newG, newB, 1)
end
end
-- https://warcraft.wiki.gg/wiki/Using_the_ColorPickerFrame
local function ShowColorPicker(variableSuffix)
ColorPickerFrame.variableSuffix = variableSuffix
local color = config.color[variableSuffix]
local r, g, b, a = unpack(color)
if a ~= nil then
ColorPickerFrame.hasOpacity = true
ColorPickerFrame.opacity = 1 - a
else
ColorPickerFrame.hasOpacity = false
end
ColorPickerFrame.previousValues = color
ColorPickerFrame.func = ColorPickerCallback
ColorPickerFrame.opacityFunc = ColorPickerCallback
ColorPickerFrame.cancelFunc = ColorPickerCallback
ColorPickerFrame:SetColorRGB(r,g,b)
-- Need to run the OnShow handler.
ColorPickerFrame:Hide()
ColorPickerFrame:Show()
end
local function DrawLine(f, startRelativeAnchor, startOffsetX, startOffsetY,
endRelativeAnchor, endOffsetX, endOffsetY,
thickness, r, g, b, a)
local line = f:CreateLine()
line:SetThickness(thickness)
line:SetColorTexture(r, g, b, a)
line:SetStartPoint(startRelativeAnchor, f, startOffsetX, startOffsetY)
line:SetEndPoint(endRelativeAnchor, f, endOffsetX, endOffsetY)
end
local function SetFrameBorder(f, thickness, r, g, b, a)
-- Bottom line.
DrawLine(f, "BOTTOMLEFT", 0, 0, "BOTTOMRIGHT", 0, 0, thickness, r, g, b, a)
-- Top line.
DrawLine(f, "TOPLEFT", 0, 0, "TOPRIGHT", 0, 0, thickness, r, g, b, a)
-- Left line.
DrawLine(f, "BOTTOMLEFT", 0, 0, "TOPLEFT", 0, 0, thickness, r, g, b, a)
-- Right line.
DrawLine(f, "BOTTOMRIGHT", 0, 0, "TOPRIGHT", 0, 0, thickness, r, g, b, a)
end
local function DrawGraphBars(graphBars, graphBarValues)
for i in pairs(graphBars) do
if i > numberOfVisibleBars then break end
local barTopY = graphBarValues[(graphBarValuesFirstIndex - i + 1) % numberOfVisibleBars]
if barTopY then
local smoothProgress = frameCounter / config.framesPerGraphBar
local barStartX
local barEndX
if i == 1 then
barStartX = 0
barEndX = config.graphBarThickness * smoothProgress
else
barStartX = config.graphBarThickness * (smoothProgress + i - 2)
barEndX = math_min(barStartX + config.graphBarThickness, gf.grid:GetWidth())
end
if barStartX > gf.grid:GetWidth() then
graphBars[i]:Hide()
else
-- Modify bar height according to yAxisBottom and yAxisTop.
barTopY = math_max(barTopY - config.yAxisBottom, 0)
barTopY = gf.grid:GetHeight() * math_min(barTopY / (config.yAxisTop - config.yAxisBottom), 1)
graphBars[i]:SetPoint("BOTTOMRIGHT", gf.grid, "BOTTOMRIGHT", -barStartX, 0)
graphBars[i]:SetPoint("TOPLEFT", gf.grid, "BOTTOMRIGHT", -barEndX, barTopY)
graphBars[i]:Show()
end
else
graphBars[i]:Hide()
end
end
end
local skipFirstFrames = 10
local updateFrame = CreateFrame("Frame")
updateFrame:SetScript("onUpdate", function(self, elapsed)
if skipFirstFrames > 0 then
skipFirstFrames = skipFirstFrames - 1
return
end
-- Calculate the framerate between this and the last frame.
local currentFramerate = 1 / elapsed
if config.framesPerGraphBar == 1 then
-- Increase the index.
graphBarValuesFirstIndex = (graphBarValuesFirstIndex + 1) % numberOfVisibleBars
-- Fill in the most recent value.
graphBarValues.avg[graphBarValuesFirstIndex] = currentFramerate
else
if config.show.max then maxFPS = math_max(maxFPS, currentFramerate) end
if config.show.avg then sumFPS = sumFPS + currentFramerate end
if config.show.min then minFPS = math_min(minFPS, currentFramerate) end
frameCounter = frameCounter + 1
-- If one graph bar is complete, fill in the value.
if frameCounter == config.framesPerGraphBar then
-- Increase the index.
graphBarValuesFirstIndex = (graphBarValuesFirstIndex + 1) % numberOfVisibleBars
-- Fill in the current values and reset frameCounter.
if config.show.max then
graphBarValues.max[graphBarValuesFirstIndex] = maxFPS
maxFPS = 0
end
if config.show.avg then
graphBarValues.avg[graphBarValuesFirstIndex] = sumFPS/config.framesPerGraphBar
sumFPS = 0
end
if config.show.min then
graphBarValues.min[graphBarValuesFirstIndex] = minFPS
minFPS = 99999
end
frameCounter = 0
end
end
-- Draw the graph.
if config.framesPerGraphBar == 1 then
DrawGraphBars(graphBars.avg, graphBarValues.avg)
else
if config.show.max then DrawGraphBars(graphBars.max, graphBarValues.max) end
if config.show.avg then DrawGraphBars(graphBars.avg, graphBarValues.avg) end
if config.show.min then DrawGraphBars(graphBars.min, graphBarValues.min) end
end
end)
local function InsertGraphBar(graphBars, drawLayerSubLevel)
local newBar = gf.grid:CreateTexture()
newBar:SetDrawLayer("ARTWORK", drawLayerSubLevel)
newBar:SetTexture(PIXEL_FILE_PATH)
tinsert(graphBars, newBar)
end
local function ShowGraphBars(graphBars, color, numberOfRequiredBars)
for i, bar in pairs(graphBars) do
if i <= numberOfRequiredBars then
bar:ClearAllPoints()
bar:Show()
bar:SetColorTexture(unpack(color))
else
bar:Hide()
end
end
end
-- Forward declaration above...
UpdateGraphBarsColor = function(graphBars, color)
for i, bar in pairs(graphBars) do
bar:SetColorTexture(unpack(color))
end
end
local function HideGraph(graphBars, graphBarValues)
for _, bar in pairs(graphBars) do
bar:Hide()
end
for i in pairs(graphBarValues) do
graphBarValues[i] = 0
end
end
local function UpdateLines()
for k, v in pairs (graphLines) do
v:SetThickness(config.graphLineThickness)
end
end
-- Called when the graph size is changed.
-- Forward declaration above...
RefreshGraph = function()
if config.framesPerGraphBar == 1 then
OneFrameMode(true)
HideGraph(graphBars.max, graphBarValues.max)
HideGraph(graphBars.min, graphBarValues.min)
else
OneFrameMode(false)
if not config.show.max then HideGraph(graphBars.max, graphBarValues.max) end
if not config.show.avg then HideGraph(graphBars.avg, graphBarValues.avg) end
if not config.show.min then HideGraph(graphBars.min, graphBarValues.min) end
end
UpdateLines()
gf:SetWidth(config.graphWidth)
gf:SetHeight(config.graphHeight)
gf:ClearAllPoints()
gf:SetPoint(config.graphAnchor, config.graphX, config.graphY)
-- Determine how many bars we need.
-- We need two more bars because the worst case is
-- that the first bar is just started to be shifted in
-- and the grid width is almost one bar width wider than the rounded number of bars.
local numberOfRequiredBars = math_floor(gf.grid:GetWidth() / config.graphBarThickness) + 2
-- If necessary create all we need.
if numberOfRequiredBars > numberOfCreatedBars then
-- The easiest way to make sure that all graphs have the same amount
-- of bars is to insert them all, regardless of whether they are
-- needed or not...
for i = numberOfCreatedBars + 1, numberOfRequiredBars, 1 do
InsertGraphBar(graphBars.max, -1)
InsertGraphBar(graphBars.avg, 0)
InsertGraphBar(graphBars.min, 1)
end
numberOfCreatedBars = numberOfRequiredBars
end
-- Make visible as many bars as we need and hide the others.
if config.framesPerGraphBar == 1 then
ShowGraphBars(graphBars.avg, config.color.avg, numberOfRequiredBars)
else
if config.show.max then ShowGraphBars(graphBars.max, config.color.max, numberOfRequiredBars) end
if config.show.avg then ShowGraphBars(graphBars.avg, config.color.avg, numberOfRequiredBars) end
if config.show.min then ShowGraphBars(graphBars.min, config.color.min, numberOfRequiredBars) end
end
numberOfVisibleBars = numberOfRequiredBars
-- Reset the counters.
frameCounter = 0
minFPS = 99999
maxFPS = 0
sumFPS = 0
end
local function CreateGraph()
if gf then return end
gf = CreateFrame("Frame", "fpsGraph_graphFrame", UIParent)
gf:SetFrameStrata("BACKGROUND")
gf:SetMovable(true)
gf:EnableMouse(true)
gf:RegisterForDrag("LeftButton")
gf:SetScript("OnDragStart", gf.StartMoving)
gf:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing(self)
config.graphAnchor, _, _, config.graphX, config.graphY = self:GetPoint(1)
end)
gf:SetClampedToScreen(true)
gf:Show()
gf.grid = CreateFrame("Frame", nil, gf)
gf.grid:SetPoint("BOTTOMLEFT", 10, 10)
gf.grid:SetPoint("TOPRIGHT", -50, -10)
SetFrameBorder(gf.grid, 1, 1, 0, 0, 1)
SetFrameBorder(gf, 1, 0, 0, 1, 1)
RefreshGraph()
end
local function AddSlider(parentFrame, anchor, offsetX, offsetY, sliderTitle, variableName, minValue, maxValue, valueStep, valueChangedFunction)
local slider = CreateFrame("Slider", "fpsGraph_"..variableName.."Slider", parentFrame, "OptionsSliderTemplate")
slider:SetPoint(anchor, offsetX, offsetY)
slider:SetWidth(CONFIG_FRAME_WIDTH - 85)
slider:SetHeight(17)
slider:SetMinMaxValues(minValue, maxValue)
slider:SetValueStep(valueStep)
slider:SetObeyStepOnDrag(true)
slider:SetValue(config[variableName])
_G[slider:GetName() .. 'Low']:SetText(minValue)
_G[slider:GetName() .. 'High']:SetText(maxValue)
_G[slider:GetName() .. 'Text']:SetText(sliderTitle)
slider.valueLabel = parentFrame:CreateFontString("fpsGraph_"..variableName.."SliderValueLabel", "OVERLAY")
slider.valueLabel:SetFont("Fonts\\FRIZQT__.TTF", 11)
slider.valueLabel:SetTextColor(1, 1, 1)
slider.valueLabel:SetPoint("LEFT", slider, "RIGHT", 15, 0)
slider.valueLabel:SetWidth(25)
slider.valueLabel:SetJustifyH("CENTER")
slider.valueLabel:SetText(config[variableName])
slider:SetScript("OnValueChanged", function(self, value)
config[variableName] = value
self.valueLabel:SetText(value)
if valueChangedFunction then valueChangedFunction(self, value) end
RefreshGraph()
end
)
end
local function AddSeriesSelector(parentFrame, anchor, offsetX, offsetY, labelText, variableSuffix)
local checkbox = CreateFrame("CheckButton", "fpsGraph_"..variableSuffix.."Checkbox", parentFrame, "UICheckButtonTemplate")
checkbox:SetSize(22, 22)
checkbox:SetPoint(anchor, offsetX, offsetY)
if config.show[variableSuffix] == true then
checkbox:SetChecked(true)
else
checkbox:SetChecked(false)
end
checkbox:SetScript("OnClick", function(self)
if self:GetChecked() then
config.show[variableSuffix] = true
else
config.show[variableSuffix] = false
end
RefreshGraph()
end
)
local label = parentFrame:CreateFontString("fpsGraph_"..variableSuffix.."SeriesSelector", "OVERLAY")
label:SetPoint("LEFT", checkbox, "RIGHT", 10, 0)
label:SetWidth(180)
label:SetFont("Fonts\\FRIZQT__.TTF", 12)
label:SetTextColor(1, 1, 1)
label:SetJustifyH("LEFT")
label:SetText(labelText)
local colorButton = CreateFrame("Button", "fpsGraph_"..variableSuffix.."ColorButton", parentFrame)
colorButton:SetSize(15, 15)
colorButton:SetPoint("LEFT", label, "RIGHT", 10, 0)
colorButton.background = colorButton:CreateTexture()
colorButton.background:SetAllPoints()
colorButton.background:SetDrawLayer("BACKGROUND", 0)
colorButton.background:SetTexture(PIXEL_FILE_PATH)
colorButton.background:SetColorTexture(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
local layer, subLevel = colorButton.background:GetDrawLayer()
colorButton.foreground = colorButton:CreateTexture()
colorButton.foreground:SetDrawLayer(layer, subLevel+1)
colorButton.foreground:SetTexture(PIXEL_FILE_PATH)
colorButton.foreground:SetColorTexture(unpack(config.color[variableSuffix]))
colorButton.foreground:SetPoint("TOPLEFT", 1, -1)
colorButton.foreground:SetPoint("BOTTOMRIGHT", -1, 1)
colorButton:SetScript("OnEnter", function(self)
self.background:SetColorTexture(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
end
)
colorButton:SetScript("OnLeave", function(self)
self.background:SetColorTexture(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
end
)
colorButton:SetScript("OnClick", function()
ShowColorPicker(variableSuffix)
end
)
end
-- When only one frame per graph bar is selected, max, avg and min are all the same.
-- So we only show avg.
-- Forward declaration above...
OneFrameMode = function(set)
if set then
_G["fpsGraph_maxCheckbox"]:SetChecked(false)
_G["fpsGraph_avgCheckbox"]:SetChecked(true)
_G["fpsGraph_minCheckbox"]:SetChecked(false)
_G["fpsGraph_maxCheckbox"]:Disable()
_G["fpsGraph_avgCheckbox"]:Disable()
_G["fpsGraph_minCheckbox"]:Disable()
else
_G["fpsGraph_maxCheckbox"]:Enable()
_G["fpsGraph_avgCheckbox"]:Enable()
_G["fpsGraph_minCheckbox"]:Enable()
_G["fpsGraph_maxCheckbox"]:SetChecked(config.show.max)
_G["fpsGraph_avgCheckbox"]:SetChecked(config.show.avg)
_G["fpsGraph_minCheckbox"]:SetChecked(config.show.min)
end
end
local cf = nil
local function DrawConfigFrame()
if cf then return end
cf = CreateFrame("Frame", "fpsGraph_configFrame", UIParent, "ButtonFrameTemplate")
cf:SetPoint("TOPLEFT")
ButtonFrameTemplate_HidePortrait(cf)
-- SetPortraitToTexture(...)
-- ButtonFrameTemplate_HideAttic(cf)
-- ButtonFrameTemplate_HideButtonBar(cf)
cf:SetFrameStrata("HIGH")
cf:SetWidth(CONFIG_FRAME_WIDTH)
cf:SetHeight(CONFIG_FRAME_HEIGHT)
cf:SetMovable(true)
cf:EnableMouse(true)
cf:RegisterForDrag("LeftButton")
cf:SetScript("OnDragStart", cf.StartMoving)
cf:SetScript("OnDragStop", cf.StopMovingOrSizing)
cf:SetClampedToScreen(true)
_G[cf:GetName().."TitleText"]:SetText("Framerate Graph - Config")
_G[cf:GetName().."TitleText"]:ClearAllPoints()
_G[cf:GetName().."TitleText"]:SetPoint("TOPLEFT", 10, -6)
AddSlider(cf.Inset, "TOPLEFT", 20, -20, "Graph width", "graphWidth", GRAPH_WIDTH_MIN, GRAPH_WIDTH_MAX, 1)
AddSlider(cf.Inset, "TOPLEFT", 20, -60, "Graph height", "graphHeight", GRAPH_HEIGHT_MIN, GRAPH_HEIGHT_MAX, 1)
AddSlider(cf.Inset, "TOPLEFT", 20, -100, "Graph bar thickness", "graphBarThickness", GRAPH_BAR_THICKNESS_MIN, GRAPH_BAR_THICKNESS_MAX, 1)
AddSlider(cf.Inset, "TOPLEFT", 20, -140, "Frames per graph bar", "framesPerGraphBar", FRAMES_PER_GRAPH_BAR_MIN, FRAMES_PER_GRAPH_BAR_MAX, 1)
AddSeriesSelector(cf.Inset, "TOPLEFT", 20, -180, "Maximum FPS per graph bar", "max")
AddSeriesSelector(cf.Inset, "TOPLEFT", 20, -200, "Average FPS per graph bar", "avg")
AddSeriesSelector(cf.Inset, "TOPLEFT", 20, -220, "Minimum FPS per graph bar", "min")
AddSlider(cf.Inset, "TOPLEFT", 20, -280, "Y-axis top", "yAxisTop", Y_AXIS_TOP_MIN, Y_AXIS_TOP_MAX, 1,
function(self, value)
if value < config.yAxisBottom + 1 then
_G["fpsGraph_yAxisBottomSlider"]:SetValue(value-1)
end
end
)
AddSlider(cf.Inset, "TOPLEFT", 20, -320, "Y-axis bottom", "yAxisBottom", Y_AXIS_BOTTOM_MIN, Y_AXIS_BOTTOM_MAX, 1,
function(self, value)
if value > config.yAxisTop - 1 then
_G["fpsGraph_yAxisTopSlider"]:SetValue(value+1)
end
end
)
AddSlider(cf.Inset, "TOPLEFT", 20, -380, "Graph line thickness", "graphLineThickness", GRAPH_LINE_THICKNESS_MIN, GRAPH_LINE_THICKNESS_MAX, 1)
tinsert(UISpecialFrames, cf:GetName())
end
local addonLoadedFrame = CreateFrame("Frame")
addonLoadedFrame:RegisterEvent("ADDON_LOADED")
addonLoadedFrame:SetScript("OnEvent", function(self, event, arg1)
if arg1 == folderName then
-- Saved config variable.
framerateGraph_config = framerateGraph_config or {}
-- For easier access.
config = framerateGraph_config
-- Remove obsolete values from saved variables.
for k in pairs(config) do
if CONFIG_DEFAULTS[k] == nil then
config[k] = nil
end
end
-- Fill missing values.
for k, v in pairs(CONFIG_DEFAULTS) do
if config[k] == nil then
config[k] = v
end
end
DrawConfigFrame()
CreateGraph()
end
end)
-- -- To manually open the config window!
-- local startupFrame = CreateFrame("Frame")
-- startupFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
-- startupFrame:SetScript("OnEvent", function()
-- cf:Show()
-- end)
-- FPS (frames per second)
-- FI (frame-to-frame interval) in msec (milliseconds)
-- Texture:SetGradientAlpha(orientation, minR, minG, minB, minA, maxR, maxG, maxB, maxA)