1 QuestHelper_File
["textviewer.lua"] = "Development Version"
5 local function viewer_mousewheel(self
, dir
)
6 local range
= self
.scrollframe
:GetVerticalScrollRange()
7 local pos
= math
.max(0, math
.min(range
, self
.scrollframe
:GetVerticalScroll()-dir
*25))
8 self
.scrollframe
:SetVerticalScroll(pos
)
9 self
.scrollbutton
:SetPoint("TOP", self
, "TOP", 0, -(pos
/range
*(self
:GetHeight()-32)+8))
12 local function viewer_mousedown(self
)
17 local function scrollbutton_scrolling(self
)
18 local vtop
, vbottom
= viewer
:GetTop()-8, viewer
:GetBottom()+24
19 local top
= math
.max(vbottom
, math
.min(vtop
, select(2, GetCursorPosition()) - self
.mouse_base
+ self
.base
))
20 viewer
.scrollframe
:SetVerticalScroll((vtop
-top
)/(vtop
-vbottom
)*viewer
.scrollframe
:GetVerticalScrollRange())
21 self
:SetPoint("TOP", viewer
, "TOP", 0, top
-viewer
:GetTop())
24 local function scrollbutton_mousedown(self
, btn
)
25 if btn
== "LeftButton" then
26 self
.base
= self
:GetTop()
27 self
.mouse_base
= select(2, GetCursorPosition())
28 self
:SetScript("OnUpdate", scrollbutton_scrolling
)
32 local function scrollbutton_mouseup(self
, btn
)
33 if btn
== "LeftButton" then
34 self
:SetScript("OnUpdate", nil)
38 function QuestHelper
:ShowText(text
, title
)
40 viewer
= CreateFrame("Frame", "QuestHelperTextViewer", nil) -- With no parent, this will always be visible.
41 viewer
:SetFrameStrata("FULLSCREEN_DIALOG")
42 viewer
:SetPoint("CENTER", UIParent
)
43 viewer
:EnableMouseWheel(true)
44 viewer
:EnableMouse(true)
45 viewer
:SetScript("OnMouseWheel", viewer_mousewheel
)
46 viewer
:SetScript("OnMouseDown", viewer_mousedown
)
48 -- This will cause it to be hidden if Esc is pressed.
49 table.insert(UISpecialFrames
, viewer
:GetName())
51 viewer
.title
= viewer
:CreateFontString()
52 viewer
.title
:SetFont(self
.font
.serif
, 14)
53 viewer
.title
:SetPoint("TOPLEFT", viewer
, 8, -8)
54 viewer
.title
:SetPoint("RIGHT", viewer
, -8, 0)
57 bgFile
= "Interface/Tooltips/UI-Tooltip-Background",
58 edgeFile
= "Interface/Tooltips/UI-Tooltip-Border",
62 insets
= { left
= 4, right
= 4, top
= 4, bottom
= 4 }})
63 viewer
:SetBackdropColor(0, 0, 0, 0.8)
64 viewer
:SetBackdropBorderColor(1, 1, 1, 0.7)
66 viewer
.scrollframe
= CreateFrame("ScrollFrame", "QuestHelperTextViewer_ScrollFrame", viewer
)
67 viewer
.scrollframe
:SetPoint("LEFT", viewer
, "LEFT", 8, 0)
68 viewer
.scrollframe
:SetPoint("TOP", viewer
.title
, "BOTTOM", 0, -4)
70 viewer
.frame
= CreateFrame("Frame", "QuestHelperTextViewer_Frame", viewer
.scrollframe
)
71 viewer
.scrollframe
:SetScrollChild(viewer
.frame
)
73 viewer
.text
= viewer
.frame
:CreateFontString()
74 viewer
.text
:SetFont(self
.font
.sans
, 12)
75 viewer
.text
:SetJustifyH("LEFT")
76 viewer
.text
:SetPoint("TOPLEFT", viewer
.frame
)
78 viewer
.scrollbutton
= CreateFrame("Frame", "QuestHelperTextViewer_ScrollButton", viewer
)
79 viewer
.scrollbutton
:SetWidth(16)
80 viewer
.scrollbutton
:SetHeight(16)
81 viewer
.scrollbutton
.texture
= self
:CreateIconTexture(viewer
.scrollbutton
, 26)
82 viewer
.scrollbutton
.texture
:SetAllPoints()
83 viewer
.scrollbutton
:EnableMouse(true)
84 viewer
.scrollbutton
:SetScript("OnMouseDown", scrollbutton_mousedown
)
85 viewer
.scrollbutton
:SetScript("OnMouseUp", scrollbutton_mouseup
)
89 viewer
.title
:SetText(title
or "QuestHelper")
90 viewer
.text
:SetText(text
or "No text.")
91 viewer
.scrollframe
:SetVerticalScroll(0)
92 viewer
.scrollbutton
:ClearAllPoints()
93 viewer
.scrollbutton
:SetPoint("TOPRIGHT", viewer
, "TOPRIGHT", -8, -8)
95 local w
= math
.min(600, math
.max(100, viewer
.text
:GetStringWidth()))
96 viewer
.text
:SetWidth(w
)
98 viewer
.scrollframe
:SetWidth(w
)
99 viewer
.frame
:SetWidth(w
)
101 local h
= math
.max(10, viewer
.text
:GetHeight())
102 local title_h
= viewer
.title
:GetHeight()
105 viewer
.frame
:SetHeight(400)
106 viewer
.scrollframe
:SetHeight(400)
107 viewer
:SetHeight(420+title_h
)
108 viewer
:SetWidth(w
+32)
109 viewer
.scrollbutton
:Show()
111 viewer
.frame
:SetHeight(h
)
112 viewer
.scrollframe
:SetHeight(h
)
113 viewer
:SetHeight(h
+20+title_h
)
114 viewer
.scrollbutton
:Hide()