update repo
[QuestHelper.git] / textviewer.lua
blobba725fdd2f08cad4676ebd5cf75a2aee407d7498
1 QuestHelper_File["textviewer.lua"] = "Development Version"
3 local viewer
5 local function viewer_cancelmove(self)
6 if self.isMoving then
7 self:StopMovingOrSizing()
8 self.isMoving = false
9 end
10 end
12 local function viewer_mousedown(self, button)
13 if button == "LeftButton" then
14 self:StartMoving()
15 self.isMoving = true
16 end
17 end
19 local function viewer_closebutton(self)
20 viewer.text:SetText("")
21 viewer:Hide()
22 end
24 function QuestHelper:ShowText(text, title)
25 if not viewer then
26 viewer = CreateFrame("Frame", "QuestHelperTextViewer", nil) -- With no parent, this will always be visible.
27 viewer:SetFrameStrata("FULLSCREEN_DIALOG")
28 viewer:SetPoint("CENTER", UIParent)
29 viewer:EnableMouse(true)
30 viewer:SetMovable(true)
31 viewer:SetScript("OnMouseDown", viewer_mousedown)
32 viewer:SetScript("OnMouseUp", viewer_cancelmove)
33 viewer:SetScript("OnHide", viewer_cancelmove)
35 -- This will cause it to be hidden if Esc is pressed.
36 table.insert(UISpecialFrames, viewer:GetName())
38 viewer.title = viewer:CreateFontString()
39 viewer.title:SetFont(self.font.serif, 14)
40 viewer.title:SetPoint("TOPLEFT", viewer, 8, -8)
41 viewer.title:SetPoint("RIGHT", viewer, -8, 0)
43 viewer:SetBackdrop({
44 bgFile = "Interface/Tooltips/UI-Tooltip-Background",
45 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
46 edgeSize = 16,
47 tile = true,
48 tileSize = 16,
49 insets = { left = 4, right = 4, top = 4, bottom = 4 }})
50 viewer:SetBackdropColor(0, 0, 0, 0.8)
51 viewer:SetBackdropBorderColor(1, 1, 1, 0.7)
53 viewer.scrollframe = CreateFrame("ScrollFrame", "QuestHelperTextViewer_ScrollFrame", viewer, "UIPanelScrollFrameTemplate")
54 viewer.scrollframe:SetPoint("LEFT", viewer, "LEFT", 8, 0)
55 viewer.scrollframe:SetPoint("TOP", viewer.title, "BOTTOM", 0, -4)
57 viewer.scrollbar = QuestHelperTextViewer_ScrollFrameScrollBar
58 viewer.scrollbar:SetBackdrop({ -- Note: These settings are coppied from UIPanelScrollBarTemplateLightBorder in UIPanelTemplates.xml
59 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
60 edgeSize = 12,
61 tileSize = 16,
62 insets = { left = 0, right = 0, top = 5, bottom = 5 }})
63 viewer.scrollbar:SetThumbTexture(self:CreateIconTexture(viewer.scrollbar, 26)) -- Use the snazzy blue thumb
65 viewer.closebutton = CreateFrame("Button", "QuestHelperTextViewer_CloseButton", viewer, "UIPanelCloseButton")
66 viewer.closebutton:SetPoint("TOPRIGHT", viewer)
67 viewer.closebutton:SetScript("OnClick", viewer_closebutton)
69 viewer.frame = CreateFrame("Frame", "QuestHelperTextViewer_Frame", viewer.scrollframe)
70 viewer.scrollframe:SetScrollChild(viewer.frame)
72 viewer.text = viewer.frame:CreateFontString()
73 viewer.text:SetFont(self.font.sans, 12)
74 viewer.text:SetJustifyH("LEFT")
75 viewer.text:SetPoint("TOPLEFT", viewer.frame)
76 end
78 viewer:Show()
79 viewer.title:SetText(title or "QuestHelper")
80 viewer.text:SetText(text or "No text.")
81 viewer.scrollframe:SetVerticalScroll(0)
83 local w = math.min(600, math.max(100, viewer.text:GetStringWidth()))
84 viewer.text:SetWidth(w)
85 viewer:SetWidth(w+16)
86 viewer.scrollframe:SetWidth(w)
87 viewer.frame:SetWidth(w)
89 local h = math.max(10, viewer.text:GetHeight())
90 local title_h = viewer.title:GetHeight()
92 if h > 400 then
93 viewer.frame:SetHeight(400)
94 viewer.scrollframe:SetHeight(400)
95 viewer:SetHeight(420+title_h)
96 viewer:SetWidth(w+38)
97 viewer.scrollbar:Show()
98 else
99 viewer.frame:SetHeight(h)
100 viewer.scrollframe:SetHeight(h)
101 viewer:SetHeight(h+20+title_h)
102 viewer.scrollbar:Hide()
103 --[[
104 WoW Bug: For some reason, setting the thumb texture on the scrollbar causes the following scenario:
105 1. Display the viewer with scrollable text (eg /qh)
106 2. Display the viewer with smaller text (eg /qh help filter)
107 The second time the viewer is displayed, the close button doesn't show its normal state.
108 When you hover over it, the glow appears. If you press the left button over it, the depressed state appears.
109 If you drag off of it, then release, the normal state appears, and the button is fine until you repeat 1 & 2.
111 viewer.closebutton:SetButtonState("PUSHED") -- Workaround: there's a wierd quirk that's causing it to not show sometimes...
112 viewer.closebutton:SetButtonState("NORMAL") -- Workaround, part 2