3 local function viewer_mousewheel(self
, dir
)
4 local range
= self
.scrollframe
:GetVerticalScrollRange()
5 local pos
= math
.max(0, math
.min(range
, self
.scrollframe
:GetVerticalScroll()-dir
*25))
6 self
.scrollframe
:SetVerticalScroll(pos
)
7 self
.scrollbutton
:SetPoint("TOP", self
, "TOP", 0, -(pos
/range
*(self
:GetHeight()-32)+8))
10 local function viewer_mousedown(self
)
15 local function scrollbutton_scrolling(self
)
16 local vtop
, vbottom
= viewer
:GetTop()-8, viewer
:GetBottom()+24
17 local top
= math
.max(vbottom
, math
.min(vtop
, select(2, GetCursorPosition()) - self
.mouse_base
+ self
.base
))
18 viewer
.scrollframe
:SetVerticalScroll((vtop
-top
)/(vtop
-vbottom
)*viewer
.scrollframe
:GetVerticalScrollRange())
19 self
:SetPoint("TOP", viewer
, "TOP", 0, top
-viewer
:GetTop())
22 local function scrollbutton_mousedown(self
, btn
)
23 if btn
== "LeftButton" then
24 self
.base
= self
:GetTop()
25 self
.mouse_base
= select(2, GetCursorPosition())
26 self
:SetScript("OnUpdate", scrollbutton_scrolling
)
30 local function scrollbutton_mouseup(self
, btn
)
31 if btn
== "LeftButton" then
32 self
:SetScript("OnUpdate", nil)
36 function QuestHelper
:ShowText(text
, title
)
38 viewer
= CreateFrame("Frame", "QuestHelperTextViewer", nil) -- With no parent, this will always be visible.
39 viewer
:SetPoint("CENTER", UIParent
)
40 viewer
:EnableMouseWheel(true)
41 viewer
:EnableMouse(true)
42 viewer
:SetScript("OnMouseWheel", viewer_mousewheel
)
43 viewer
:SetScript("OnMouseDown", viewer_mousedown
)
45 viewer
.title
= viewer
:CreateFontString()
46 viewer
.title
:SetFont(self
.font
.serif
, 14)
47 viewer
.title
:SetPoint("TOPLEFT", viewer
, 8, -8)
48 viewer
.title
:SetPoint("RIGHT", viewer
, -8, 0)
51 bgFile
= "Interface/Tooltips/UI-Tooltip-Background",
52 edgeFile
= "Interface/Tooltips/UI-Tooltip-Border",
56 insets
= { left
= 4, right
= 4, top
= 4, bottom
= 4 }})
57 viewer
:SetBackdropColor(0, 0, 0, 0.65)
58 viewer
:SetBackdropBorderColor(1, 1, 1, 0.7)
60 viewer
.scrollframe
= CreateFrame("ScrollFrame", "QuestHelperTextViewer_ScrollFrame", viewer
)
61 viewer
.scrollframe
:SetPoint("LEFT", viewer
, "LEFT", 8, 0)
62 viewer
.scrollframe
:SetPoint("TOP", viewer
.title
, "BOTTOM", 0, -4)
64 viewer
.frame
= CreateFrame("Frame", "QuestHelperTextViewer_Frame", viewer
.scrollframe
)
65 viewer
.scrollframe
:SetScrollChild(viewer
.frame
)
67 viewer
.text
= viewer
.frame
:CreateFontString()
68 viewer
.text
:SetFont(self
.font
.sans
, 12)
69 viewer
.text
:SetJustifyH("LEFT")
70 viewer
.text
:SetPoint("TOPLEFT", viewer
.frame
)
72 viewer
.scrollbutton
= CreateFrame("Frame", "QuestHelperTextViewer_ScrollButton", viewer
)
73 viewer
.scrollbutton
:SetWidth(16)
74 viewer
.scrollbutton
:SetHeight(16)
75 viewer
.scrollbutton
:SetPoint("TOPRIGHT", viewer
, "TOPRIGHT", -8, -8)
76 viewer
.scrollbutton
.texture
= self
:CreateIconTexture(viewer
.scrollbutton
, 26)
77 viewer
.scrollbutton
.texture
:SetAllPoints()
78 viewer
.scrollbutton
:EnableMouse(true)
79 viewer
.scrollbutton
:SetScript("OnMouseDown", scrollbutton_mousedown
)
80 viewer
.scrollbutton
:SetScript("OnMouseUp", scrollbutton_mouseup
)
84 viewer
.title
:SetText(title
or "QuestHelper")
85 viewer
.text
:SetText(text
or "No text.")
86 viewer
.scrollframe
:SetVerticalScroll(0)
88 local w
= math
.min(600, math
.max(100, viewer
.text
:GetStringWidth()))
89 viewer
.text
:SetWidth(w
)
91 viewer
.scrollframe
:SetWidth(w
)
92 viewer
.frame
:SetWidth(w
)
94 local h
= math
.max(10, viewer
.text
:GetHeight())
95 local title_h
= viewer
.title
:GetHeight()
98 viewer
.frame
:SetHeight(400)
99 viewer
.scrollframe
:SetHeight(400)
100 viewer
:SetHeight(420+title_h
)
101 viewer
:SetWidth(w
+32)
102 viewer
.scrollbutton
:Show()
104 viewer
.frame
:SetHeight(h
)
105 viewer
.scrollframe
:SetHeight(h
)
106 viewer
:SetHeight(h
+20+title_h
)
107 viewer
.scrollbutton
:Hide()