annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-ScrollFrame.lua @ 0:169f5211fc7f

First public revision. At this point ItemAuditor watches mail for auctions sold or purchased, watches for buy/sell (money and 1 item type change) and conversions/tradeskills. Milling isn't working yet because there is too much time between the first event and the last event.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Thu, 20 May 2010 19:22:19 -0700
parents
children
rev   line source
Asa@0 1 local AceGUI = LibStub("AceGUI-3.0")
Asa@0 2
Asa@0 3 -- Lua APIs
Asa@0 4 local pairs, assert, type = pairs, assert, type
Asa@0 5 local min, max, floor = math.min, math.max, math.floor
Asa@0 6
Asa@0 7 -- WoW APIs
Asa@0 8 local CreateFrame, UIParent = CreateFrame, UIParent
Asa@0 9
Asa@0 10
Asa@0 11 -------------
Asa@0 12 -- Widgets --
Asa@0 13 -------------
Asa@0 14 --[[
Asa@0 15 Widgets must provide the following functions
Asa@0 16 Acquire() - Called when the object is aquired, should set everything to a default hidden state
Asa@0 17 Release() - Called when the object is Released, should remove any anchors and hide the Widget
Asa@0 18
Asa@0 19 And the following members
Asa@0 20 frame - the frame or derivitive object that will be treated as the widget for size and anchoring purposes
Asa@0 21 type - the type of the object, same as the name given to :RegisterWidget()
Asa@0 22
Asa@0 23 Widgets contain a table called userdata, this is a safe place to store data associated with the wigdet
Asa@0 24 It will be cleared automatically when a widget is released
Asa@0 25 Placing values directly into a widget object should be avoided
Asa@0 26
Asa@0 27 If the Widget can act as a container for other Widgets the following
Asa@0 28 content - frame or derivitive that children will be anchored to
Asa@0 29
Asa@0 30 The Widget can supply the following Optional Members
Asa@0 31
Asa@0 32
Asa@0 33 ]]
Asa@0 34
Asa@0 35 --------------------------
Asa@0 36 -- Scroll Frame --
Asa@0 37 --------------------------
Asa@0 38 do
Asa@0 39 local Type = "ScrollFrame"
Asa@0 40 local Version = 9
Asa@0 41
Asa@0 42 local function OnAcquire(self)
Asa@0 43
Asa@0 44 end
Asa@0 45
Asa@0 46 local function OnRelease(self)
Asa@0 47 self.frame:ClearAllPoints()
Asa@0 48 self.frame:Hide()
Asa@0 49 self.status = nil
Asa@0 50 -- do SetScroll after niling status, but before clearing localstatus
Asa@0 51 -- so the scroll value isnt populated back into status, but not kept in localstatus either
Asa@0 52 self:SetScroll(0)
Asa@0 53 for k in pairs(self.localstatus) do
Asa@0 54 self.localstatus[k] = nil
Asa@0 55 end
Asa@0 56 self.scrollframe:SetPoint("BOTTOMRIGHT",self.frame,"BOTTOMRIGHT",0,0)
Asa@0 57 self.scrollbar:Hide()
Asa@0 58 self.scrollBarShown = nil
Asa@0 59 self.content.height, self.content.width = nil, nil
Asa@0 60 end
Asa@0 61
Asa@0 62 local function SetScroll(self, value)
Asa@0 63 local status = self.status or self.localstatus
Asa@0 64 local viewheight = self.scrollframe:GetHeight()
Asa@0 65 local height = self.content:GetHeight()
Asa@0 66 local offset
Asa@0 67
Asa@0 68 if viewheight > height then
Asa@0 69 offset = 0
Asa@0 70 else
Asa@0 71 offset = floor((height - viewheight) / 1000.0 * value)
Asa@0 72 end
Asa@0 73 self.content:ClearAllPoints()
Asa@0 74 self.content:SetPoint("TOPLEFT", self.scrollframe, "TOPLEFT", 0, offset)
Asa@0 75 self.content:SetPoint("TOPRIGHT", self.scrollframe, "TOPRIGHT", 0, offset)
Asa@0 76 status.offset = offset
Asa@0 77 status.scrollvalue = value
Asa@0 78 end
Asa@0 79
Asa@0 80 local function MoveScroll(self, value)
Asa@0 81 local status = self.status or self.localstatus
Asa@0 82 local height, viewheight = self.scrollframe:GetHeight(), self.content:GetHeight()
Asa@0 83
Asa@0 84 if height > viewheight then
Asa@0 85 self.scrollbar:Hide()
Asa@0 86 else
Asa@0 87 self.scrollbar:Show()
Asa@0 88 local diff = height - viewheight
Asa@0 89 local delta = 1
Asa@0 90 if value < 0 then
Asa@0 91 delta = -1
Asa@0 92 end
Asa@0 93 self.scrollbar:SetValue(min(max(status.scrollvalue + delta*(1000/(diff/45)),0), 1000))
Asa@0 94 end
Asa@0 95 end
Asa@0 96
Asa@0 97
Asa@0 98 local function FixScroll(self)
Asa@0 99 if self.updateLock then return end
Asa@0 100 self.updateLock = true
Asa@0 101 local status = self.status or self.localstatus
Asa@0 102 local height, viewheight = self.scrollframe:GetHeight(), self.content:GetHeight()
Asa@0 103 local offset = status.offset or 0
Asa@0 104 local curvalue = self.scrollbar:GetValue()
Asa@0 105 if viewheight < height then
Asa@0 106 if self.scrollBarShown then
Asa@0 107 self.scrollBarShown = nil
Asa@0 108 self.scrollbar:Hide()
Asa@0 109 self.scrollbar:SetValue(0)
Asa@0 110 self.scrollframe:SetPoint("BOTTOMRIGHT",self.frame,"BOTTOMRIGHT",0,0)
Asa@0 111 self:DoLayout()
Asa@0 112 end
Asa@0 113 else
Asa@0 114 if not self.scrollBarShown then
Asa@0 115 self.scrollBarShown = true
Asa@0 116 self.scrollbar:Show()
Asa@0 117 self.scrollframe:SetPoint("BOTTOMRIGHT", self.frame,"BOTTOMRIGHT",-20,0)
Asa@0 118 self:DoLayout()
Asa@0 119 end
Asa@0 120 local value = (offset / (viewheight - height) * 1000)
Asa@0 121 if value > 1000 then value = 1000 end
Asa@0 122 self.scrollbar:SetValue(value)
Asa@0 123 self:SetScroll(value)
Asa@0 124 if value < 1000 then
Asa@0 125 self.content:ClearAllPoints()
Asa@0 126 self.content:SetPoint("TOPLEFT", self.scrollframe, "TOPLEFT", 0, offset)
Asa@0 127 self.content:SetPoint("TOPRIGHT", self.scrollframe, "TOPRIGHT", 0, offset)
Asa@0 128 status.offset = offset
Asa@0 129 end
Asa@0 130 end
Asa@0 131 self.updateLock = nil
Asa@0 132 end
Asa@0 133
Asa@0 134 local function OnMouseWheel(this, value)
Asa@0 135 this.obj:MoveScroll(value)
Asa@0 136 end
Asa@0 137
Asa@0 138 local function OnScrollValueChanged(this, value)
Asa@0 139 this.obj:SetScroll(value)
Asa@0 140 end
Asa@0 141
Asa@0 142 local function FixScrollOnUpdate(this)
Asa@0 143 this:SetScript("OnUpdate", nil)
Asa@0 144 this.obj:FixScroll()
Asa@0 145 end
Asa@0 146
Asa@0 147 local function OnSizeChanged(this)
Asa@0 148 this:SetScript("OnUpdate", FixScrollOnUpdate)
Asa@0 149 end
Asa@0 150
Asa@0 151 local function LayoutFinished(self, width, height)
Asa@0 152 self.content:SetHeight(height or 0 + 20)
Asa@0 153 self.scrollframe:SetScript("OnUpdate", FixScrollOnUpdate)
Asa@0 154 end
Asa@0 155
Asa@0 156 -- called to set an external table to store status in
Asa@0 157 local function SetStatusTable(self, status)
Asa@0 158 assert(type(status) == "table")
Asa@0 159 self.status = status
Asa@0 160 if not status.scrollvalue then
Asa@0 161 status.scrollvalue = 0
Asa@0 162 end
Asa@0 163 end
Asa@0 164
Asa@0 165 local function OnWidthSet(self, width)
Asa@0 166 local content = self.content
Asa@0 167 content.width = width
Asa@0 168 end
Asa@0 169
Asa@0 170
Asa@0 171 local function OnHeightSet(self, height)
Asa@0 172 local content = self.content
Asa@0 173 content.height = height
Asa@0 174 end
Asa@0 175
Asa@0 176 local function Constructor()
Asa@0 177 local frame = CreateFrame("Frame", nil, UIParent)
Asa@0 178 local self = {}
Asa@0 179 self.type = Type
Asa@0 180
Asa@0 181 self.OnRelease = OnRelease
Asa@0 182 self.OnAcquire = OnAcquire
Asa@0 183
Asa@0 184 self.MoveScroll = MoveScroll
Asa@0 185 self.FixScroll = FixScroll
Asa@0 186 self.SetScroll = SetScroll
Asa@0 187 self.LayoutFinished = LayoutFinished
Asa@0 188 self.SetStatusTable = SetStatusTable
Asa@0 189 self.OnWidthSet = OnWidthSet
Asa@0 190 self.OnHeightSet = OnHeightSet
Asa@0 191
Asa@0 192 self.localstatus = {}
Asa@0 193 self.frame = frame
Asa@0 194 frame.obj = self
Asa@0 195
Asa@0 196 --Container Support
Asa@0 197 local scrollframe = CreateFrame("ScrollFrame", nil, frame)
Asa@0 198 scrollframe.obj = self
Asa@0 199 scrollframe:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, 0)
Asa@0 200 scrollframe:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, 0)
Asa@0 201 scrollframe:EnableMouseWheel(true)
Asa@0 202 scrollframe:SetScript("OnMouseWheel", OnMouseWheel)
Asa@0 203 scrollframe:SetScript("OnSizeChanged", OnSizeChanged)
Asa@0 204 self.scrollframe = scrollframe
Asa@0 205
Asa@0 206 local content = CreateFrame("Frame", nil, scrollframe)
Asa@0 207 content.obj = self
Asa@0 208 content:SetPoint("TOPLEFT", scrollframe, "TOPLEFT", 0, 0)
Asa@0 209 content:SetPoint("TOPRIGHT", scrollframe, "TOPRIGHT", 0, 0)
Asa@0 210 content:SetHeight(400)
Asa@0 211 self.content = content
Asa@0 212 scrollframe:SetScrollChild(content)
Asa@0 213
Asa@0 214 local num = AceGUI:GetNextWidgetNum(Type)
Asa@0 215 local name = ("AceConfigDialogScrollFrame%dScrollBar"):format(num)
Asa@0 216 local scrollbar = CreateFrame("Slider", name, scrollframe, "UIPanelScrollBarTemplate")
Asa@0 217 scrollbar.obj = self
Asa@0 218 scrollbar:SetPoint("TOPLEFT", scrollframe, "TOPRIGHT", 4, -16)
Asa@0 219 scrollbar:SetPoint("BOTTOMLEFT", scrollframe, "BOTTOMRIGHT", 4, 16)
Asa@0 220 scrollbar:SetScript("OnValueChanged", OnScrollValueChanged)
Asa@0 221 scrollbar:SetMinMaxValues(0, 1000)
Asa@0 222 scrollbar:SetValueStep(1)
Asa@0 223 scrollbar:SetValue(0)
Asa@0 224 scrollbar:SetWidth(16)
Asa@0 225 scrollbar:Hide()
Asa@0 226 self.scrollbar = scrollbar
Asa@0 227
Asa@0 228 local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND")
Asa@0 229 scrollbg:SetAllPoints(scrollbar)
Asa@0 230 scrollbg:SetTexture(0, 0, 0, 0.4)
Asa@0 231
Asa@0 232 self.localstatus.scrollvalue = 0
Asa@0 233
Asa@0 234 --self:FixScroll()
Asa@0 235 AceGUI:RegisterAsContainer(self)
Asa@0 236 --AceGUI:RegisterAsWidget(self)
Asa@0 237 return self
Asa@0 238 end
Asa@0 239
Asa@0 240 AceGUI:RegisterWidgetType(Type,Constructor,Version)
Asa@0 241 end