-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKui.lua
800 lines (732 loc) · 24.7 KB
/
Kui.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
local MAJOR, MINOR = 'Kui-1.0', 50
local kui = LibStub:NewLibrary(MAJOR, MINOR)
if not kui then
-- already registered
return
end
--luacheck:globals WOW_PROJECT_ID WOW_PROJECT_CLASSIC WOW_PROJECT_BURNING_CRUSADE_CLASSIC
local CLASSIC = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
local BURNING_CRUSADE = WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC
kui.CLASSIC = CLASSIC or BURNING_CRUSADE
kui.BURNING_CRUSADE = BURNING_CRUSADE
-- XXX 8X -> 90 compatibility helper
local SHADOWLANDS = select(4,GetBuildInfo()) >= 90000
kui.SHADOWLANDS = SHADOWLANDS
kui.UNIT_HEALTH = SHADOWLANDS and 'UNIT_HEALTH' or 'UNIT_HEALTH_FREQUENT'
-- media # XXX LEGACY #########################################################
local media = "Interface\\AddOns\\Kui_Media\\"
kui.m = {
t = {
-- borders
shadow = media .. 't\\shadowBorder',
rounded = media .. 't\\solidRoundedBorder',
-- textures
solid = media .. 't\\solid',
innerShade = media .. 't\\innerShade',
empty = media .. 't\\empty',
-- progress bars
bar = media .. 't\\bar',
oldbar = media .. 't\\bar-old',
sbar = media .. 't\\bar-small',
brightbar = media .. 't\\bar-bright',
stripebar = media .. 't\\stippled-bar',
},
f = {
francois = media..'f\\francois.ttf',
roboto = media..'f\\roboto.ttf',
},
}
-- other locals ################################################################
local TRILLION=1000000000000
local BILLION=1000000000
local MILLION=1000000
local THOUSAND=1000
local ct = { -- classification table
elite = { '+', 'elite' },
rare = { 'r', 'rare' },
rareelite = { 'r+', 'rare elite' },
worldboss = { 'b', 'boss' }
}
-- functions ###################################################################
local function SortedTableIndex(tbl)
local index = {}
for k in pairs(tbl) do
tinsert(index,k)
end
table.sort(index,function(a,b)
local str_a,str_b=tostring(a),tostring(b)
if str_a and not str_b then
return true
elseif str_b and not str_a then
return false
else
return strlower(str_a) < strlower(str_b)
end
end)
return index
end
kui.table_to_string = function(in_tbl,max_depth)
-- convert simple table to string (with restrictions)
if not max_depth then
max_depth = 3
end
local function loop(tbl,depth)
if depth and depth >= max_depth then
return '{..}'
else
local str
local tbl_index = SortedTableIndex(tbl)
for _,k in ipairs(tbl_index) do
local v = tbl[k]
if type(k) == 'string' or tostring(k) then
k = tostring(k)
else
k = '('..type(k)..')'
end
if type(v) == 'table' then
v = loop(v,depth and depth+1 or 1)
elseif type(v) == 'number' then
v = tonumber(string.format('%.3f',v))
elseif type(v) == 'string' or tostring(v) then
v = tostring(v)
else
v = '('..type(v)..')'
end
str = (str and str..',' or '')..k..'='..v
end
return str and '{'..str..'}' or '{}'
end
end
return loop(in_tbl)
end
function kui.string_to_table(in_str)
-- convert string from above function back to table
-- (with restrictions)
local out_table = {}
local out_length = 0
local function loop(str,nested_table)
if str == '{}' or str == '{..}' then
return {}
end
if strfind(str,'{') == 1 then
-- remove surrounding brackets
str = strsub(str,2,strlen(str)-1)
end
local next_comma,next_equals = strfind(str,','),strfind(str,'=')
if nested_table or next_equals and not next_comma then
-- parse "key=value" into final array
local k = strsub(str,1,next_equals-1)
local v = strsub(str,next_equals+1)
-- convert key
if tonumber(k) then
k = tonumber(k)
end
-- convert value
if strlower(v) == 'true' then
v = true
elseif strlower(v) == 'false' then
v = false
elseif strlower(v) == 'nil' then
v = nil
elseif tonumber(v) then
v = tonumber(v)
elseif strfind(v,'{') == 1 then
-- convert nested tables
v = kui.string_to_table(v)
end
out_table[k] = v
out_length = out_length + 1
return
end
local next_open = strfind(str,'{')
if next_open and next_equals and next_open == next_equals + 1 then
-- this value is a nested table,
-- find the comma after the end (or the end of the string)
-- XXX doesn't handle double-nested tables
next_comma = strfind(str,',',strfind(str,'}'))
if next_comma then
loop(strsub(str,1,next_comma-1),true)
-- and continue...
loop(strsub(str,next_comma+1))
else
-- this is the final value
loop(str,true)
end
return
end
if next_comma and next_equals and next_equals < next_comma then
-- parse each delimited section
loop(strsub(str,1,next_comma-1))
-- and continue with the remaining text
loop(strsub(str,next_comma+1))
return
end
end
loop(in_str)
if out_length == 0 then
return
else
return out_table,out_length
end
end
kui.print = function(...)
local msg
for _,v in ipairs({...}) do
if type(v) == 'table' then
v = kui.table_to_string(v)
end
msg = (msg and msg..', ' or '')..tostring(v)
end
print(GetTime()..': '..(msg or 'nil'))
end
kui.GetClassColour = function(class, str)
if not class then
class = select(2, UnitClass('player'))
elseif not RAID_CLASS_COLORS[class] then
-- assume class is a unit
class = select(2, UnitClass(class))
end
if CUSTOM_CLASS_COLORS then
class = CUSTOM_CLASS_COLORS[class]
else
class = RAID_CLASS_COLORS[class]
end
if str == 2 then
return class.r,class.g,class.b
elseif str then
return string.format("%02x%02x%02x", class.r*255, class.g*255, class.b*255)
else
-- XXX this is a direct reference
return class
end
end
kui.SetTextureToClass = function(texture,class,with_border,ymod)
--luacheck:globals CLASS_ICON_TCOORDS
local coords = CLASS_ICON_TCOORDS[class]
if not with_border then
coords={
coords[1]+.02,
coords[2]-.02,
coords[3]+.02+(ymod or 0),
coords[4]-.02-(ymod or 0)
}
end
texture:SetTexture('interface/glues/charactercreate/ui-charactercreate-classes')
texture:SetTexCoord(unpack(coords))
end
-- unit helpers ################################################################
kui.UnitIsPet = function(unit)
return (not UnitIsPlayer(unit) and UnitPlayerControlled(unit))
end
kui.GetUnitColour = function(unit, str)
-- class colour for players or pets
-- faction colour for NPCs
local r,g,b
if UnitIsTapDenied(unit) or
UnitIsDeadOrGhost(unit) or
not UnitIsConnected(unit)
then
r,g,b = .5,.5,.5
else
if UnitIsPlayer(unit) or kui.UnitIsPet(unit) then
-- XXX this inherits the direct reference (if str==nil)
return kui.GetClassColour(unit, str)
else
r, g, b = UnitSelectionColor(unit)
end
end
if str == 2 then
return r,g,b
elseif str then
return string.format("%02x%02x%02x", r*255, g*255, b*255)
else
return {r=r,g=g,b=b}
end
end
kui.UnitLevel = function(unit, long, real)
local level
if kui.CLASSIC then
level = UnitLevel(unit) or 0
else
level = real and UnitLevel(unit) or UnitEffectiveLevel(unit)
end
local classification = UnitClassification(unit)
local diff = GetQuestDifficultyColor(level <= 0 and 999 or level)
if ct[classification] then
classification = long and ct[classification][2] or ct[classification][1]
else
classification = ''
end
if level == -1 then
level = '??'
end
return level, classification, diff
end
-- frame helpers ###############################################################
kui.ModifyFontFlags = function(fs, io, flag)
local font, size, flags = fs:GetFont()
local flagStart,flagEnd = strfind(flags, flag)
if io and not flagStart then
-- add flag
flags = flags..' '..flag
elseif not io and flagStart then
-- remove flag
flags = strsub(flags, 0, flagStart-1) .. strsub(flags, flagEnd+1)
end
fs:SetFont(font, size, flags)
end
kui.CreateFontString = function(parent, args)
local ob, font, size, outline, alpha, shadow, mono
args = args or {}
if args.reset then
-- to change an already existing fontString
ob = parent
else
ob = parent:CreateFontString(nil, 'OVERLAY')
end
font = args.font or 'Fonts\\FRIZQT__.TTF'
size = args.size or 12
outline = args.outline or nil
mono = args.mono or args.monochrome or nil
alpha = args.alpha or 1
shadow = args.shadow or false
ob:SetFont(font, size, (outline and 'OUTLINE' or '')..(mono and ' MONOCHROME' or ''))
ob:SetAlpha(alpha)
if shadow then
ob:SetShadowColor(0, 0, 0, 1)
ob:SetShadowOffset(type(shadow) == 'table' and unpack(shadow) or 1, -1)
elseif not shadow and args.reset then
-- remove the shadow
ob:SetShadowColor(0, 0, 0, 0)
end
return ob
end
-- generic helpers #############################################################
kui.num = function(num) -- TODO needs locale
if not num then return end
if num < THOUSAND then
return floor(num)
elseif num >= TRILLION then
return string.format('%.3ft', num/TRILLION)
elseif num >= BILLION then
return string.format('%.3fb', num/BILLION)
elseif num >= MILLION then
return string.format('%.2fm', num/MILLION)
elseif num >= THOUSAND then
return string.format('%.1fk', num/THOUSAND)
end
end
kui.FormatTime = function(s)
if s > 86400 then
-- days
return ceil(s/86400) .. 'd', s%86400
elseif s >= 3600 then
-- hours
return ceil(s/3600) .. 'h', s%3600
elseif s >= 60 then
-- minutes
return ceil(s/60) .. 'm', s%60
elseif s <= 10 then
return ceil(s), s - format("%.1f", s)
end
return floor(s), s - floor(s)
end
kui.Pluralise = function(word, value, with)
if value == 1 then
return word
else
return word .. (with and with or 's')
end
end
do
local function _b(m,c)
return c + (1 - c) * m
end
kui.Brighten = function(m,r,g,b,a)
-- brighten (or darken) given colour
return _b(m,r),_b(m,g),_b(m,b),a
end
end
-- substr for utf8 characters ##################################################
do
local function chsize(char)
if not char then
return 0
elseif char > 240 then
return 4
elseif char > 225 then
return 3
elseif char > 192 then
return 2
else
return 1
end
end
kui.utf8sub = function(str, startChar, numChars)
numChars = numChars or #str
local startIndex = 1
while startChar > 1 do
local char = string.byte(str, startIndex)
startIndex = startIndex + chsize(char)
startChar = startChar - 1
end
local currentIndex = startIndex
while numChars > 0 and currentIndex <= #str do
local char = string.byte(str, currentIndex)
currentIndex = currentIndex + chsize(char)
numChars = numChars - 1
end
return str:sub(startIndex, currentIndex - 1)
end
end
-- editbox debug popup #########################################################
do
local debugpopup
local function Popup_Show(self)
self.ScrollFrame:Show()
self.Background:Show()
self:orig_Show()
end
local function Popup_Hide(self)
self:ClearFocus()
self:orig_Hide()
self.ScrollFrame:Hide()
self.Background:Hide()
if type(self.callback) == 'function' then
-- run input callback
self.callback(self:GetText())
end
self:SetText("")
end
local function Popup_AddText(self,v)
if not v then return end
local m = self:GetText()
if m ~= '' then
m = m..'|n'
end
if type(v) == 'table' then
v = kui.table_to_string(v)
end
self:SetText(m..v)
end
local function Popup_OnEscapePressed(self)
self:Hide()
end
local function ScrollFrame_OnMouseDown(self,button)
if button == 'RightButton' and not self.is_moving then
self:StartMoving()
self.is_moving = true
elseif button == 'LeftButton' then
self:GetScrollChild():SetFocus()
end
end
local function ScrollFrame_OnMouseUp(self,button)
if button == 'RightButton' and self.is_moving then
self:StopMovingOrSizing()
self.is_moving = nil
end
end
local function CloseButton_OnClick(self)
debugpopup:Hide()
end
local function CreateDebugPopup()
if debugpopup then return end
local p = CreateFrame('EditBox','KuiDebugEditBox',UIParent)
p:SetFrameStrata('DIALOG')
p:SetMultiLine(true)
p:SetAutoFocus(true)
p:SetFontObject(ChatFontNormal)
p:SetSize(450,300)
p:Hide()
p.orig_Hide = p.Hide
p.orig_Show = p.Show
p.Hide = Popup_Hide
p.Show = Popup_Show
p.AddText = Popup_AddText
p:SetScript('OnEscapePressed',Popup_OnEscapePressed)
local s = CreateFrame('ScrollFrame','KuiDebugEditBoxScrollFrame',UIParent,'UIPanelScrollFrameTemplate')
s:SetMovable(true)
s:SetFrameStrata('DIALOG')
s:SetSize(450,300)
s:SetHitRectInsets(-10,-30,-10,-10)
s:SetPoint('CENTER')
s:SetScrollChild(p)
s:Hide()
s.ScrollBar:SetPoint('TOPLEFT',s,'TOPRIGHT',6,-38)
s:SetScript('OnMouseDown',ScrollFrame_OnMouseDown)
s:SetScript('OnMouseUp',ScrollFrame_OnMouseUp)
local bg = CreateFrame('Frame',nil,UIParent,BackdropTemplateMixin and 'BackdropTemplate' or nil)
bg:SetFrameStrata('DIALOG')
bg:SetBackdrop({
bgFile = 'Interface\\ChatFrame\\ChatFrameBackground',
edgeFile = 'Interface\\Tooltips\\UI-Tooltip-border',
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
})
bg:SetBackdropColor(.05,.05,.05,.8)
bg:SetBackdropBorderColor(.5,.5,.5)
bg:SetPoint('TOPLEFT',s,-10,10)
bg:SetPoint('BOTTOMRIGHT',s,30,-10)
bg:Hide()
local button = CreateFrame('Button',nil,bg,'UIPanelCloseButton')
button:SetPoint('TOPRIGHT',bg)
button:SetScript('OnClick',CloseButton_OnClick)
p.ScrollFrame = s
p.Background = bg
debugpopup = p
end
function kui:DebugPopup(callback)
-- create/get and return reference to debug EditBox
CreateDebugPopup()
-- disable and hide popup if already visible
debugpopup.callback = nil
debugpopup:Hide()
if type(callback) == 'function' then
debugpopup.callback = callback
end
return debugpopup
end
end
-- Frame fading functions ######################################################
do
local frameFadeFrame = CreateFrame('Frame')
local FADEFRAMES = {}
local function OnUpdate(self, elapsed)
local frame, info
for _,value in pairs(FADEFRAMES) do
frame, info = value, value.fadeInfo
if info.startDelay and info.startDelay > 0 then
info.startDelay = info.startDelay - elapsed
else
info.fadeTimer = (info.fadeTimer and info.fadeTimer + elapsed) or 0
if info.fadeTimer < info.timeToFade then
-- perform animation in either direction
if info.mode == 'IN' then
frame:SetAlpha(
(info.fadeTimer / info.timeToFade) *
(info.endAlpha - info.startAlpha) +
info.startAlpha
)
elseif info.mode == 'OUT' then
frame:SetAlpha(
((info.timeToFade - info.fadeTimer) / info.timeToFade) *
(info.startAlpha - info.endAlpha) + info.endAlpha
)
end
else
-- animation has ended
frame:SetAlpha(info.endAlpha)
if info.fadeHoldTime and info.fadeHoldTime > 0 then
info.fadeHoldTime = info.fadeHoldTime - elapsed
else
kui.frameFadeRemoveFrame(frame)
if info.finishedFunc then
info.finishedFunc(frame)
info.finishedFunc = nil
end
end
end
end
end
if #FADEFRAMES == 0 then
self:SetScript('OnUpdate', nil)
end
end
function kui.frameIsFading(frame)
for _,value in pairs(FADEFRAMES) do
if value == frame then
return true
end
end
end
function kui.frameFadeRemoveFrame(frame)
tDeleteItem(FADEFRAMES, frame)
end
--[[
info = {
mode = "IN" (nil) or "OUT",
startAlpha = alpha value to start at,
endAlpha = alpha value to end at,
timeToFade = duration of animation,
startDelay = seconds to wait before starting animation,
fadeHoldTime = seconds to wait after ending animation before calling finishedFunc,
finishedFunc = function to call after animation has ended,
}
the `info` table is directly modified.
]]
function kui.frameFade(frame,info)
if not frame then return end
if kui.frameIsFading(frame) then
-- cancel the current operation
-- the code calling this should make sure not to interrupt a
-- necessary finishedFunc. This will entirely skip it.
kui.frameFadeRemoveFrame(frame)
end
info = info or {}
info.mode = info.mode or 'IN'
if info.mode == 'IN' then
info.startAlpha = info.startAlpha or 0
info.endAlpha = info.endAlpha or 1
elseif info.mode == 'OUT' then
info.startAlpha = info.startAlpha or 1
info.endAlpha = info.endAlpha or 0
end
frame:SetAlpha(info.startAlpha)
frame.fadeInfo = info
tinsert(FADEFRAMES, frame)
frameFadeFrame:SetScript('OnUpdate', OnUpdate)
end
end
-- eight-slice helper ##########################################################
-- simple helper for three-sided textures (not standard edgeFiles),
-- stretches textures rather than repeating,
-- creates texture objects in given frame,
-- can be arbitrarily positioned
do
-- this expects a quartered square: top left, top, left, blank.
local COORDS = {
{ 0, .5, 0, .5 }, -- top left
{ .5, 1, 0, .5 }, -- top
{ .5, 0, 0, .5 }, -- top right
{ .5, 0, .5, 1 }, -- right
{ .5, 0, .5, 0 }, -- bottom right
{ .5, 1, .5, 0 }, -- bottom
{ 0, .5, .5, 0 }, -- bottom left
{ 0, .5, .5, 1 }, -- left
}
local POINTS = {
{ 'BOTTOMRIGHT', 'TOPLEFT', 1, -1 }, -- top left
{ { 'BOTTOMLEFT', 'TOPLEFT', 1, -1 }, -- top
{ 'BOTTOMRIGHT', 'TOPRIGHT', -1, -1 }
},
{ 'BOTTOMLEFT', 'TOPRIGHT', -1, -1 }, -- top right
{ { 'TOPLEFT', 'TOPRIGHT', -1, -1 }, -- right
{ 'BOTTOMLEFT', 'BOTTOMRIGHT', -1, 1 }
},
{ 'TOPLEFT', 'BOTTOMRIGHT', -1, 1 }, -- bottom right
{ { 'TOPRIGHT', 'BOTTOMRIGHT', -1, 1 }, -- bottom
{ 'TOPLEFT', 'BOTTOMLEFT', 1, 1 }
},
{ 'TOPRIGHT', 'BOTTOMLEFT', 1, 1 }, -- bottom left
{ { 'BOTTOMRIGHT', 'BOTTOMLEFT', 1, 1 }, -- left
{ 'TOPRIGHT', 'TOPLEFT', 1, -1 }
}
}
local PROTOTYPE = {}
PROTOTYPE.__index = PROTOTYPE
function PROTOTYPE:SetVertexColor(...)
for _,side in ipairs(self.sides) do
side:SetVertexColor(...)
end
end
function PROTOTYPE:Show()
for _,side in ipairs(self.sides) do
side:Show()
end
end
function PROTOTYPE:Hide()
for _,side in ipairs(self.sides) do
side:Hide()
end
end
function PROTOTYPE:SetSize(size)
for _,side in ipairs(self.sides) do
side:SetSize(size,size)
end
end
function PROTOTYPE:SetAlpha(...)
for _,side in ipairs(self.sides) do
side:SetAlpha(...)
end
end
function PROTOTYPE:SetAllPoints(parent,inset)
local top,bottom,left,right
if type(inset) == 'table' then
top,bottom,left,right =
inset.top or 0,
inset.bottom or 0,
inset.left or 0,
inset.right or 0
else
inset = inset or 0
top,bottom,left,right = inset,inset,inset,inset
end
for i=1,#POINTS do
local side = self.sides[i]
local point = POINTS[i]
if type(point[1]) == 'table' then
-- flat side
local a,b,c,d
if i == 2 then
a,b,c,d = left,top,right,top
elseif i == 4 then
a,b,c,d = right,top,right,bottom
elseif i == 6 then
a,b,c,d = right,bottom,left,bottom
elseif i == 8 then
a,b,c,d = left,bottom,left,top
end
side:SetPoint(point[1][1],parent,point[1][2],point[1][3]*a,point[1][4]*b)
side:SetPoint(point[2][1],parent,point[2][2],point[2][3]*c,point[2][4]*d)
else
-- corner
local a,b
if i == 1 then
a,b = left,top
elseif i == 3 then
a,b = right,top
elseif i == 5 then
a,b = right,bottom
elseif i == 7 then
a,b = left,bottom
end
side:SetPoint(point[1],parent,point[2],point[3]*a,point[4]*b)
end
end
end
function kui.CreateEightSlice(parent,texture,layer,sublevel)
assert(parent and type(parent.CreateTexture) == 'function')
texture = texture or 'interface/buttons/white8x8'
layer = layer or 'BACKGROUND'
sublevel = sublevel or -5
local this = { sides = {} }
setmetatable(this,PROTOTYPE)
for i=1,#POINTS do
local side = parent:CreateTexture(nil,layer,nil,sublevel)
side:SetTexture(texture)
side:SetTexCoord(unpack(COORDS[i]))
tinsert(this.sides,side)
end
return this
end
end
-- frame-locked callback helper ###############################################
do
local function Nil(self)
self.instance.framelocked = nil
self:SetScript('OnUpdate',nil)
end
local FrameLockMixin = {}
-- true if this is the first time FrameLock has been called this frame
function FrameLockMixin:FrameLock()
if self.framelocked then
return
end
self.framelocked = true
if not self.FrameLockFrame then
self.FrameLockFrame = CreateFrame('Frame')
self.FrameLockFrame.instance = self
end
self.FrameLockFrame:SetScript('OnUpdate',Nil)
return true
end
-- common usage; run given function at most once per frame
-- (with no knowledge as to which function was actually run,
-- so should only be used for one function at a time)
function FrameLockMixin:FrameLockFunc(func,...)
if self:FrameLock() then
return func(...)
end
end
kui.FrameLockMixin = FrameLockMixin
end