-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFTabControl.uc
157 lines (136 loc) · 3.53 KB
/
FTabControl.uc
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
/* ========================================================
* Copyright 2012-2013 Eliot van Uytfanghe
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================
* FTabControl: A container for FTabButtons with associated FPages.
* ======================================================== */
class FTabControl extends FMultiComponent;
/** The currently actively rendered and interactable tab's page. */
var(TabControl, Advanced) `{Automated} FPage ActivePage;
/** Put the @ActivePage within this ExternContainer. */
var(TabControl, Advanced) FMultiComponent ExternContainer;
/** Called when the tab control's active page is changed. */
delegate OnSwitch( FPage oldPage, FPage newPage );
function Free()
{
super.Free();
ActivePage = none;
OnSwitch = none;
ExternContainer = none;
}
protected function InitializeComponent()
{
local FComponent component;
local FTabButton tab;
super.InitializeComponent();
foreach Components( component )
{
if( FTabButton(component) != none )
{
tab = FTabButton(component);
tab.OnClick = TabClicked;
if( tab.TabPage == none )
{
`Log( "Warning! " @ tab $ "'s TabPage is none!" );
continue;
}
if( ExternContainer == none )
{
tab.TabPage.Initialize( self );
}
else
{
ExternContainer.AddComponent( tab.TabPage );
tab.TabPage.SetVisible( false );
}
}
}
SetActivePage( ActivePage );
}
protected function PostRender( Canvas C )
{
super.PostRender( C );
if( ExternContainer == none && ActivePage != none && ActivePage.CanRender() )
{
ActivePage.Render( C );
}
}
function Update( float DeltaTime )
{
super.Update( DeltaTime );
if( ExternContainer == none && ActivePage != none && ActivePage.CanInteract() )
{
ActivePage.Update( DeltaTime );
}
}
// Ignore self
function bool IsHover( IntPoint mousePosition, out FComponent hoveredComponent )
{
local FComponent component;
local bool bHover;
// Test this class first!
if( Collides( MousePosition ) )
{
foreach Components( component )
{
if( component.CanInteract() && component.IsHover( mousePosition, hoveredComponent ) )
{
bHover = true;
break;
}
}
if( !bHover )
{
hoveredComponent = none;
if( ExternContainer == none && ActivePage != none && ActivePage.CanInteract() && ActivePage.IsHover( mousePosition, hoveredComponent ) )
{
bHover = true;
}
}
return bHover;
}
return false;
}
function SetActivePage( FPage newPage )
{
local FPage previousPage;
previousPage = ActivePage;
ActivePage = newPage;
if( previousPage != none )
{
previousPage.SetVisible( false );
previousPage.Closed();
}
if( newPage != none )
{
newPage.SetVisible( true );
newPage.Opened();
}
OnSwitch( previousPage, newPage );
}
function TabClicked( FComponent sender, optional bool bRight )
{
local FPage newPage;
// Consider this as click on the FTabControl component as well!
OnClick( sender, bRight );
newPage = FTabButton(sender).TabPage;
if( newPage == ActivePage )
{
return;
}
SetActivePage( newPage );
}
defaultproperties
{
}