-
Notifications
You must be signed in to change notification settings - Fork 4
/
FWindow.uc
144 lines (122 loc) · 3.74 KB
/
FWindow.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
/* ========================================================
* 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.
* ========================================================
* FWindow: Anything that needs a title and body should subclass this!
* This class gives you a pre-defined Header and Body block along with a configurable title.
* Windows can be dragged as well, using the Header block.
* ======================================================== */
class FWindow extends FPage;
var(Window, Advanced) `{Automated} FContainer Header;
var(Window, Advanced) `{Automated} FLabel HeaderTitle;
var(Window, Advanced) `{Automated} FContainer Body;
var(Window, Usage) bool bDraggable;
var(Window, Usage) bool bClampPosition;
var transient IntPoint DragMPosition;
var transient Vector2D DragCPosition;
function Free()
{
super.Free();
Header = none;
HeaderTitle = none;
Body = none;
}
protected function InitializeComponent()
{
local FComponent comp;
super.InitializeComponent();
Body = FContainer(CreateComponent( Body.Class,, Body ));
Body.Components = Components;
foreach Components( comp )
{
comp.Parent = Body;
}
Components.Length = 0;
AddComponent( Body );
Header = FContainer(CreateComponent( Header.Class,, Header ));
AddComponent( Header );
HeaderTitle = FLabel(CreateComponent( HeaderTitle.Class, Header, HeaderTitle ));
if( bDraggable )
{
HeaderTitle.OnMouseButtonPressed = BeginDragEvent;
HeaderTitle.OnMouseButtonRelease = EndDragEvent;
}
Header.AddComponent( HeaderTitle );
}
protected function RenderComponent( Canvas C )
{
RenderBackground( C, GetStateColor() );
if( HasFocus() )
{
C.DrawColor = Style.FocusColor;
C.SetPos( PosX, C.CurY );
C.DrawBox( SizeX, SizeY );
}
super(FComponent).RenderComponent( C );
}
function BeginDragEvent( FComponent sender, optional bool bRight )
{
DragMPosition = Scene().MousePosition;
DragCPosition = RelativePosition;
HeaderTitle.OnMouseMove = DraggingEvent;
}
function DraggingEvent( FScene scene, float DeltaTime )
{
local float newX, newY;
newX = MoveLeft( float(scene.MousePosition.X - DragMPosition.X) );
newY = MoveTop( float(scene.MousePosition.Y - DragMPosition.Y) );
if( bClampPosition && RelativeSize.X <= 1.0 && RelativeSize.Y <= 1.0 )
{
SetPos( FClamp( newX, 0.0, 1.0-RelativeSize.X ), FClamp( newY, 0.0, 1.0-RelativeSize.Y ) );
}
else
{
SetPos( newX, newY );
}
DragMPosition = scene.MousePosition;
}
function EndDragEvent( FComponent sender, optional bool bRight )
{
HeaderTitle.OnMouseMove = none;
}
defaultproperties
{
bDraggable=true
bClampPosition=true
begin object name=oHeader class=FContainer
RelativePosition=(X=0.0,Y=0.0)
RelativeSize=(X=1.0,Y=32.0)
// Counter the padding from FWindow
Margin=(X=-8,W=-8,Y=-8,Z=-8)
begin object name=oHeaderTitle class=FLabel
Margin=(X=8,W=8,Y=4,Z=4)
RelativePosition=(X=0.0,Y=0.0)
RelativeSize=(X=1.0,Y=1.0)
Text="Window Title"
StyleNames.Add(WindowHeader)
bEnableCollision=true
bEnableClick=true
bEnabled=true
end object
end object
Header=oHeader
HeaderTitle=oHeader.oHeaderTitle
begin object name=oBody class=FContainer
Margin=(Y=16.0,Z=32.0)
RelativePosition=(X=0.0,Y=0.0)
RelativeSize=(X=1.0,Y=1.0)
// Actual components!
end object
Body=oBody
}