-
Notifications
You must be signed in to change notification settings - Fork 18
/
SM_Common.lua
136 lines (105 loc) · 4.75 KB
/
SM_Common.lua
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
local function GetAddonDir()
local name = "SuperMacro"
for i=1, GetNumAddOns() do
name = GetAddOnInfo(i)
if string.find(name, "SuperMacro") then
break
end
end
return "Interface\\AddOns\\"..name
end
local function AddCustomHandlerForEditBox(editBox)
-- Add tabulation handler
editBox:SetScript("OnTabPressed", function()
this:Insert(" ")
end)
local scrollFrame = editBox:GetParent()
-- Add line show
editBox.textLineNumber = scrollFrame:CreateFontString("Status", "LOW", "GameFontHighlightSmall")
editBox.textLineNumber:SetPoint("BOTTOMLEFT", scrollFrame, "BOTTOMRIGHT", -50, -16)
editBox.textLineNumber:SetJustifyH("LEFT")
editBox:SetScript("OnCursorChanged", function()
local x = arg1
local y = arg2
local lineHeight = arg4
local lineNumber = math.abs(math.floor(y / lineHeight + 0.5)) + 1
this.textLineNumber:SetText(string.format("Line: %4d", lineNumber))
end)
end
-- Post load initialization for SuperMacro frames
function SuperMacroInitFrames()
SuperMacroUpdateConfig()
AddCustomHandlerForEditBox(SuperMacroFrameText)
AddCustomHandlerForEditBox(SuperMacroFrameExtendText)
AddCustomHandlerForEditBox(SuperMacroFrameSuperText)
end
function SuperMacroHandleEditBox(editBox)
local scrollBar = getglobal(editBox:GetParent():GetName().."ScrollBar")
editBox:GetParent():UpdateScrollChildRect();
local _, max = scrollBar:GetMinMaxValues();
scrollBar.prevMaxValue = scrollBar.prevMaxValue or max
if math.abs(scrollBar.prevMaxValue - scrollBar:GetValue()) <= 1 then
-- if scroll is down and add new line then move scroll
scrollBar:SetValue(max);
end
if max ~= scrollBar.prevMaxValue then
-- save max value
scrollBar.prevMaxValue = max
end
end
function SuperMacroUpdateConfig()
local windowSizeXMin = 590
local windowSizeYMin = 512
local windowSizeXMax = math.floor(UIParent:GetRight())
local windowSizeYMax = math.floor(UIParent:GetTop())
SM_VARS.windowWidth = math.max(SM_VARS.windowWidth, windowSizeXMin)
SM_VARS.windowWidth = math.min(SM_VARS.windowWidth, windowSizeXMax)
SM_VARS.windowHeight = math.max(SM_VARS.windowHeight, windowSizeYMin)
SM_VARS.windowHeight = math.min(SM_VARS.windowHeight, windowSizeYMax)
local editBoxFont = "Fonts\\FRIZQT__.TTF"
if SM_VARS.monoFont == 1 then
editBoxFont = GetAddonDir().."\\fonts\\UbuntuMono-R.ttf"
end
local textFontSize = SM_VARS.editBoxFontSize or 10
local sizeX = SM_VARS.windowWidth
local sizeY = SM_VARS.windowHeight
local scrollFrameSizeX = math.min((sizeX - 145) / 2 + 15, 500)
local scrollFrameSizeY = sizeY - 413
local extendScrollFrameSizeX = sizeX - scrollFrameSizeX - 130
local extendScrollFrameSizeY = scrollFrameSizeY + 40
if sizeX > 1110 then
extendScrollFrameSizeY = scrollFrameSizeY + 220
end
local superEditScrollFrameSizeX = sizeX - 92
local superEditScrollFrameSizeY = scrollFrameSizeY
-- Main Frame
SuperMacroFrame:SetWidth(sizeX)
SuperMacroFrame:SetHeight(sizeY)
-- interface
SuperMacroFrameMainBackground:SetWidth(sizeX - windowSizeXMin + 546)
SuperMacroFrameMainBackground:SetHeight(sizeY - windowSizeYMin + 430)
-- SuperMacroFrame
SuperMacroFrameScrollFrame:SetWidth(scrollFrameSizeX)
SuperMacroFrameScrollFrame:SetHeight(scrollFrameSizeY)
SuperMacroFrameTextBackground:SetWidth(scrollFrameSizeX + 36)
SuperMacroFrameTextBackground:SetHeight(scrollFrameSizeY + 12)
SuperMacroFrameText:SetWidth(scrollFrameSizeX - 2)
SuperMacroFrameText:SetHeight(scrollFrameSizeY)
SuperMacroFrameText:SetFont(editBoxFont, textFontSize)
-- SuperMacroFrameExtend
SuperMacroFrameExtendScrollFrame:SetWidth(extendScrollFrameSizeX)
SuperMacroFrameExtendScrollFrame:SetHeight(extendScrollFrameSizeY)
SuperMacroFrameExtendTextBackground:SetWidth(extendScrollFrameSizeX + 36)
SuperMacroFrameExtendTextBackground:SetHeight(extendScrollFrameSizeY + 12)
SuperMacroFrameExtendText:SetWidth(extendScrollFrameSizeX - 4)
SuperMacroFrameExtendText:SetHeight(extendScrollFrameSizeY)
SuperMacroFrameExtendText:SetFont(editBoxFont, textFontSize)
-- SuperMacroFrameSuper
SuperMacroFrameSuperEditScrollFrame:SetWidth(superEditScrollFrameSizeX)
SuperMacroFrameSuperEditScrollFrame:SetHeight(superEditScrollFrameSizeY)
SuperMacroFrameSuperTextBackground:SetWidth(superEditScrollFrameSizeX + 36)
SuperMacroFrameSuperTextBackground:SetHeight(superEditScrollFrameSizeY + 12)
SuperMacroFrameSuperText:SetWidth(superEditScrollFrameSizeX - 1)
SuperMacroFrameSuperText:SetHeight(superEditScrollFrameSizeY)
SuperMacroFrameSuperText:SetFont(editBoxFont, textFontSize)
end