-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathifelem_titlebar.lua
118 lines (97 loc) · 3.79 KB
/
ifelem_titlebar.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
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--
-- Code, data for a expandable (horizontally) titlebar
--
-- Broken off from interface_util.lua for better encapsulation
-- fnSetSize for a TitleBar's Skin. Pulled out so its
-- implementation could be properly shared (refcounted) among all
-- instances. Bugs: 32x32 is the smallest size possible
function TitleBarSkin_fnSetSize(this,w,h)
-- Massive duplication. Sorry. :(
local x1 = (w * -0.5)
local x2 = x1 + 64
local x3 = (w * 0.5) - 32
local x4 = x3 + 32
IFImage_fnSetTexturePos(this.ChunkL ,x1 ,-16,x2+1,16)
IFImage_fnSetTexturePos(this.ChunkC ,x2-1,-16,x3,16) -- slightly overlap to avoid gap
IFImage_fnSetTexturePos(this.ChunkR ,x3 ,-16,x4,16)
end
-- fnSelect for a TitleBar's Skin. Pulled out so its
-- implementation could be properly shared (refcounted) among all
-- instances
function TitleBarSkin_fnSelect(this,NewTexture,NewAlpha)
IFImage_fnSetTexture(this.ChunkL,NewTexture,NewAlpha)
IFImage_fnSetTexture(this.ChunkC,NewTexture,NewAlpha)
IFImage_fnSetTexture(this.ChunkR,NewTexture,NewAlpha)
end
-- fnSetSize for a TitleBar's Label. Pulled out so its
-- implementation could be properly shared (refcounted) among all
-- instances
function TitleBarLabel_fnSetSize(this,w,h)
this.label.x = w * -0.5
this.label.y = h * -0.5
this.label.textw = w
this.label.texth = h
end
function TitleBarLabel_fnSetString(this,str)
IFText_fnSetString(this.labels.label,str)
end
function TitleBarLabel_fnSetUString(this,str)
IFText_fnSetUString(this.labels.label,str)
end
function TitleBarLabel_fnHilight(this,on,fDt,w,h)
if(on) then
-- gButton_CurSizeAdd = gButton_CurSizeAdd + fDt * gButton_CurDir
-- if(gButton_CurSizeAdd > 1) then
-- gButton_CurSizeAdd = 1
-- gButton_CurDir = -math.abs(gButton_CurDir)
-- elseif (gButton_CurSizeAdd < 0.3) then
-- gButton_CurSizeAdd = 0.3
-- gButton_CurDir = math.abs(gButton_CurDir)
-- end
-- Shell has label2 background text. Game doesn't. Blink one of them
IFObj_fnSetAlpha(this.label,gButton_CurSizeAdd)
end
end
function TitleBarSkin_fnHilight(this,on,fDt,w,h)
TitleBarSkin_fnSetSize(this,w,h) -- Off? Revert to standard size.
end
function NewIFTitleBar(Template)
local temp = Template
temp.skin = NewIFContainer {
ZPos = 140, -- Text will be at 128 by default, be a bit behind it
-- 8 chunks for the pieces of the texture. Note: no texture is specified,
-- as that's done in fnSelect
ChunkL = NewIFImage { texture = "titlebar_l", uvs_l = 0.0, uvs_r = 1.0, uvs_t = 0.00, uvs_b = 1.00, inert_all = 1, ZPos = 190},
ChunkC = NewIFImage { texture = "titlebar_r", uvs_l = 0.0, uvs_r = 0.5, uvs_t = 0.00, uvs_b = 1.00, inert_all = 1, ZPos = 190},
ChunkR = NewIFImage { texture = "titlebar_r", uvs_l = 0.5, uvs_r = 1.0, uvs_t = 0.00, uvs_b = 1.00, inert_all = 1, ZPos = 190},
} -- end of skin
if(Template.yFlip) then
temp.skin.ChunkL.uvs_t,temp.skin.ChunkL.uvs_b = temp.skin.ChunkL.uvs_b,temp.skin.ChunkL.uvs_t
temp.skin.ChunkR.uvs_t,temp.skin.ChunkR.uvs_b = temp.skin.ChunkR.uvs_b,temp.skin.ChunkR.uvs_t
Template.yFlip = nil
end
temp.labels = NewIFContainer {
y = -2,
label = NewIFText {
valign = "vcenter",
inert_all = 1,
font = Template.font,
-- ColorR = 255, ColorG = 255, ColorB = 255,
}, -- end of label
}
local Width = Template.width or 200
TitleBarSkin_fnSetSize(temp.skin,Width,32)
TitleBarLabel_fnSetSize(temp.labels,Width,32)
if(Template.string) then
TitleBarLabel_fnSetString(temp,Template.string)
Template.string = nil
end
if(Template.ustring) then
TitleBarLabel_fnSetUString(temp,Template.ustring)
Template.ustring = nil
end
-- Make a button from this expanded template
return NewIFContainer(temp)
end