DayZ
1.24
Loading...
Searching...
No Matches
ScrollBarContainer.c
Go to the documentation of this file.
1
// -----------------------------------------------------------
2
class
ScrollBarContainer
:
ScriptedWidgetEventHandler
3
{
4
reference
bool
Invert
;
5
protected
Widget
Content
;
6
protected
Widget
ScrollBar
;
7
protected
Widget
Scroller
;
8
protected
Widget
m_root
;
9
10
const
int
WHEEL_STEP
= 20;
11
protected
float
m_root_height
;
12
protected
float
m_content_height
;
13
protected
float
m_position
;
14
protected
bool
m_scrolling
;
15
protected
float
m_scrolling_start_pos
;
16
protected
int
m_scrolling_mouse_pos
;
17
18
void
~ScrollBarContainer
()
19
{
20
//if(GetGame() != NULL)
21
//GetGame().GetDragQueue().RemoveCalls(this);
22
}
23
24
void
ScrollFixedAmount
(
bool
down
,
float
amount)
25
{
26
m_root
.Update();
27
Content
.Update();
28
float
width
;
29
30
m_root
.GetScreenSize(
width
,
m_root_height
);
31
Content
.GetScreenSize(
width
,
m_content_height
);
32
33
float
diff
=
m_root_height
/
m_content_height
;
34
float
one_percent
=
diff
/ 100;
35
float
percents
= amount /
m_content_height
;
36
//float step = (1.0 / (m_content_height - m_root_height)) * WHEEL_STEP;
37
float
step
= (
percents
/ 100);
38
if
(
down
)
39
m_position
+= 1 * (
percents
+ 0.05);
40
else
41
m_position
-= 1 * (
percents
+ 0.05);
42
43
if
(
m_position
< 0)
m_position
= 0;
44
if
(
m_position
> 1 -
diff
)
m_position
= 1 -
diff
;
45
UpdateScroller
();
46
}
47
48
void
ScrollToPos
(
float
pos)
49
{
50
m_root
.Update();
51
Content
.Update();
52
float
width
;
53
54
m_root
.GetScreenSize(
width
,
m_root_height
);
55
Content
.GetScreenSize(
width
,
m_content_height
);
56
57
float
diff
=
m_root_height
/
m_content_height
;
58
float
percents
= pos /
m_content_height
;
59
60
m_position
=
percents
;
61
62
if
(
m_position
< 0)
63
m_position
= 0;
64
if
(
m_position
> 1 -
diff
)
65
m_position
= 1 -
diff
;
66
UpdateScroller
();
67
}
68
69
void
ScrollToBottom
()
70
{
71
m_root
.Update();
72
Content
.Update();
73
float
width
;
74
75
m_root
.GetScreenSize(
width
,
m_root_height
);
76
Content
.GetScreenSize(
width
,
m_content_height
);
77
78
float
diff
=
m_root_height
/
m_content_height
;
79
m_position
= 1 -
diff
;
80
UpdateScroller
();
81
}
82
83
void
ScrollToTop
()
84
{
85
if
(
m_position
!= 0)
86
{
87
m_position
= 0;
88
UpdateScroller
();
89
}
90
}
91
92
float
GetContentYPos
()
93
{
94
float
x
,
y
;
95
Content
.GetPos(
x
,
y
);
96
return
y
;
97
}
98
99
float
GetRootHeight
()
100
{
101
return
m_root_height
;
102
}
103
104
void
UpdateScroller
()
105
{
106
m_root
.Update();
107
Content
.Update();
108
float
width
;
109
float
height
;
110
float
diff
;
111
float
scroller_height
;
112
113
m_root
.GetScreenSize(
width
,
m_root_height
);
114
Content
.GetScreenSize(
width
,
m_content_height
);
115
116
diff
=
m_content_height
-
m_root_height
;
117
if
(
diff
<= 0)
118
{
119
Content
.SetPos(0, 0);
120
Scroller
.Show(
false
);
121
ScrollBar
.Show(
false
);
122
m_position
= 0;
123
return
;
124
}
125
126
scroller_height
= (
m_root_height
/
m_content_height
) *
m_root_height
;
127
128
ScrollBar
.Show(
true
);
129
Scroller
.Show(
true
);
130
Scroller
.GetSize(
width
,
height
);
131
Scroller
.SetSize(
width
,
scroller_height
);
132
133
float
pos = (-
m_content_height
*
m_position
);
134
135
if
(pos <= -
diff
)
136
pos = -
diff
;
137
138
Scroller
.SetPos(0, -pos);
139
140
if
(
Invert
)
141
Content
.SetPos(0, -(
diff
+ (-
diff
*
m_position
)));
142
else
143
Content
.SetPos(0, pos);
144
}
145
146
void
OnWidgetScriptInit
(
Widget
w
)
147
{
148
m_root
=
w
;
149
m_root
.SetHandler(
this
);
150
m_root
.SetFlags(
WidgetFlags
.VEXACTPOS);
151
m_scrolling
=
false
;
152
UpdateScroller
();
153
}
154
155
protected
void
StopScrolling
()
156
{
157
if
(
m_scrolling
)
158
{
159
GetGame
().GetDragQueue().RemoveCalls(
this
);
160
m_scrolling
=
false
;
161
}
162
}
163
164
protected
void
UpdateScroll
(
int
mouse_x
,
int
mouse_y
,
bool
is_dragging
)
165
{
166
m_root
.Update();
167
Content
.Update();
168
float
width
;
169
170
m_root
.GetScreenSize(
width
,
m_root_height
);
171
Content
.GetScreenSize(
width
,
m_content_height
);
172
173
if
(
m_scrolling
)
174
{
175
if
(
is_dragging
)
176
{
177
float
diff
= (
mouse_y
-
m_scrolling_mouse_pos
);
178
float
scroller_height
= (
m_root_height
/
m_content_height
) *
m_root_height
;
179
m_position
=
m_scrolling_start_pos
+ (
diff
/ (
m_root_height
-
scroller_height
));
180
if
(
m_position
< 0)
m_position
= 0;
181
if
(
m_position
> 1)
m_position
= 1;
182
}
183
else
184
{
185
m_scrolling
=
false
;
186
StopScrolling
();
187
}
188
}
189
190
UpdateScroller
();
191
}
192
193
194
// ScriptedWidgetEventHandler override
195
//--------------------------------------------------------------------------
196
override
bool
OnMouseButtonDown
(
Widget
w
,
int
x
,
int
y
,
int
button
)
197
{
198
if
(
button
==
MouseState
.LEFT &&
w
==
Scroller
&& !
m_scrolling
)
199
{
200
m_scrolling
=
true
;
201
m_scrolling_start_pos
=
m_position
;
202
int
mouse_x
;
203
GetMousePos
(
mouse_x
,
m_scrolling_mouse_pos
);
204
GetGame
().GetDragQueue().Call(
this
,
"UpdateScroll"
);
205
return
true
;
206
}
207
208
return
false
;
209
}
210
211
//--------------------------------------------------------------------------
212
override
bool
OnMouseButtonUp
(
Widget
w
,
int
x
,
int
y
,
int
button
)
213
{
214
StopScrolling
();
215
return
false
;
216
}
217
218
//--------------------------------------------------------------------------
219
override
bool
OnMouseWheel
(
Widget
w
,
int
x
,
int
y
,
int
wheel
)
220
{
221
if
(
m_scrolling
||
m_content_height
<=
m_root_height
)
return
false
;
222
223
float
step
= (1.0 / (
m_content_height
-
m_root_height
)) *
WHEEL_STEP
;
224
m_position
-=
wheel
*
step
;
225
226
if
(
m_position
< 0)
m_position
= 0;
227
if
(
m_position
> 1)
m_position
= 1;
228
UpdateScroller
();
229
return
true
;
230
}
231
232
override
bool
OnResize
(
Widget
w
,
int
x
,
int
y
)
233
{
234
if
(
w
==
m_root
||
w
==
Content
)
235
UpdateScroller
();
236
return
false
;
237
}
238
};
x
Icon x
y
Icon y
Param3
Definition
EntityAI.c:95
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition
EnWidgets.c:651
ScrollBarContainer
Definition
ScrollBarContainer.c:3
ScrollBarContainer::Invert
reference bool Invert
Definition
ScrollBarContainer.c:4
ScrollBarContainer::ScrollToBottom
void ScrollToBottom()
Definition
ScrollBarContainer.c:69
ScrollBarContainer::ScrollFixedAmount
void ScrollFixedAmount(bool down, float amount)
Definition
ScrollBarContainer.c:24
ScrollBarContainer::ScrollToTop
void ScrollToTop()
Definition
ScrollBarContainer.c:83
ScrollBarContainer::m_content_height
float m_content_height
Definition
ScrollBarContainer.c:12
ScrollBarContainer::Scroller
Widget Scroller
Definition
ScrollBarContainer.c:7
ScrollBarContainer::m_root_height
float m_root_height
Definition
ScrollBarContainer.c:11
ScrollBarContainer::WHEEL_STEP
const int WHEEL_STEP
Definition
ScrollBarContainer.c:10
ScrollBarContainer::OnMouseWheel
override bool OnMouseWheel(Widget w, int x, int y, int wheel)
Definition
ScrollBarContainer.c:219
ScrollBarContainer::m_root
Widget m_root
Definition
ScrollBarContainer.c:8
ScrollBarContainer::StopScrolling
void StopScrolling()
Definition
ScrollBarContainer.c:155
ScrollBarContainer::GetRootHeight
float GetRootHeight()
Definition
ScrollBarContainer.c:99
ScrollBarContainer::OnMouseButtonUp
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
Definition
ScrollBarContainer.c:212
ScrollBarContainer::Content
Widget Content
Definition
ScrollBarContainer.c:5
ScrollBarContainer::m_scrolling_mouse_pos
int m_scrolling_mouse_pos
Definition
ScrollBarContainer.c:16
ScrollBarContainer::m_position
float m_position
Definition
ScrollBarContainer.c:13
ScrollBarContainer::m_scrolling
bool m_scrolling
Definition
ScrollBarContainer.c:14
ScrollBarContainer::OnMouseButtonDown
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
Definition
ScrollBarContainer.c:196
ScrollBarContainer::UpdateScroller
void UpdateScroller()
Definition
ScrollBarContainer.c:104
ScrollBarContainer::ScrollToPos
void ScrollToPos(float pos)
Definition
ScrollBarContainer.c:48
ScrollBarContainer::m_scrolling_start_pos
float m_scrolling_start_pos
Definition
ScrollBarContainer.c:15
ScrollBarContainer::GetContentYPos
float GetContentYPos()
Definition
ScrollBarContainer.c:92
ScrollBarContainer::OnResize
override bool OnResize(Widget w, int x, int y)
Definition
ScrollBarContainer.c:232
ScrollBarContainer::~ScrollBarContainer
void ~ScrollBarContainer()
Definition
ScrollBarContainer.c:18
ScrollBarContainer::ScrollBar
Widget ScrollBar
Definition
ScrollBarContainer.c:6
ScrollBarContainer::OnWidgetScriptInit
void OnWidgetScriptInit(Widget w)
Definition
ScrollBarContainer.c:146
ScrollBarContainer::UpdateScroll
void UpdateScroll(int mouse_x, int mouse_y, bool is_dragging)
Definition
ScrollBarContainer.c:164
Widget
Definition
EnWidgets.c:190
GetGame
proto native CGame GetGame()
MouseState
MouseState
Definition
EnSystem.c:311
GetMousePos
proto void GetMousePos(out int x, out int y)
WidgetFlags
WidgetFlags
Definition
EnWidgets.c:58
scripts
3_Game
GUI
Containers
ScrollBarContainer.c
Generated by
1.10.0