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