Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
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(g_Game != NULL)
21
//g_Game.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
g_Game
.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
195
// ScriptedWidgetEventHandler override
196
//--------------------------------------------------------------------------
197
override
bool
OnMouseButtonDown
(
Widget
w,
int
x
,
int
y
,
int
button)
198
{
199
if
(button ==
MouseState
.LEFT && w ==
Scroller
&& !
m_scrolling
)
200
{
201
m_scrolling
=
true
;
202
m_scrolling_start_pos
=
m_position
;
203
int
mouse_x;
204
GetMousePos
(mouse_x,
m_scrolling_mouse_pos
);
205
g_Game
.GetDragQueue().Call(
this
,
"UpdateScroll"
);
206
return
true
;
207
}
208
209
return
false
;
210
}
211
212
//--------------------------------------------------------------------------
213
override
bool
OnMouseButtonUp
(
Widget
w,
int
x
,
int
y
,
int
button)
214
{
215
StopScrolling
();
216
return
false
;
217
}
218
219
//--------------------------------------------------------------------------
220
override
bool
OnMouseWheel
(
Widget
w,
int
x
,
int
y
,
int
wheel)
221
{
222
if
(
m_scrolling
||
m_content_height
<=
m_root_height
)
return
false
;
223
224
float
step = (1.0 / (
m_content_height
-
m_root_height
)) *
WHEEL_STEP
;
225
m_position
-= wheel * step;
226
227
if
(
m_position
< 0)
m_position
= 0;
228
if
(
m_position
> 1)
m_position
= 1;
229
UpdateScroller
();
230
return
true
;
231
}
232
233
override
bool
OnResize
(
Widget
w,
int
x
,
int
y
) {
234
if
(w ==
m_root
|| w ==
Content
)
235
{
236
UpdateScroller
();
237
}
238
return
false
;
239
}
240
};
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition
enwidgets.c:657
ScrollBarContainer
Definition
scrollbarcontainer.c:3
ScrollBarContainer::m_root
Widget m_root
Definition
scrollbarcontainer.c:8
ScrollBarContainer::m_position
float m_position
Definition
scrollbarcontainer.c:13
ScrollBarContainer::GetContentYPos
float GetContentYPos()
Definition
scrollbarcontainer.c:92
ScrollBarContainer::GetRootHeight
float GetRootHeight()
Definition
scrollbarcontainer.c:99
ScrollBarContainer::m_content_height
float m_content_height
Definition
scrollbarcontainer.c:12
ScrollBarContainer::~ScrollBarContainer
void ~ScrollBarContainer()
Definition
scrollbarcontainer.c:18
ScrollBarContainer::ScrollToPos
void ScrollToPos(float pos)
Definition
scrollbarcontainer.c:48
ScrollBarContainer::Invert
reference bool Invert
Definition
scrollbarcontainer.c:4
ScrollBarContainer::WHEEL_STEP
const int WHEEL_STEP
Definition
scrollbarcontainer.c:10
ScrollBarContainer::ScrollFixedAmount
void ScrollFixedAmount(bool down, float amount)
Definition
scrollbarcontainer.c:24
ScrollBarContainer::m_scrolling_start_pos
float m_scrolling_start_pos
Definition
scrollbarcontainer.c:15
ScrollBarContainer::Content
Widget Content
Definition
scrollbarcontainer.c:5
ScrollBarContainer::m_scrolling
bool m_scrolling
Definition
scrollbarcontainer.c:14
ScrollBarContainer::OnResize
override bool OnResize(Widget w, int x, int y)
Definition
scrollbarcontainer.c:233
ScrollBarContainer::ScrollToBottom
void ScrollToBottom()
Definition
scrollbarcontainer.c:69
ScrollBarContainer::UpdateScroll
void UpdateScroll(int mouse_x, int mouse_y, bool is_dragging)
Definition
scrollbarcontainer.c:164
ScrollBarContainer::Scroller
Widget Scroller
Definition
scrollbarcontainer.c:7
ScrollBarContainer::m_scrolling_mouse_pos
int m_scrolling_mouse_pos
Definition
scrollbarcontainer.c:16
ScrollBarContainer::ScrollToTop
void ScrollToTop()
Definition
scrollbarcontainer.c:83
ScrollBarContainer::UpdateScroller
void UpdateScroller()
Definition
scrollbarcontainer.c:104
ScrollBarContainer::m_root_height
float m_root_height
Definition
scrollbarcontainer.c:11
ScrollBarContainer::OnWidgetScriptInit
void OnWidgetScriptInit(Widget w)
Definition
scrollbarcontainer.c:146
ScrollBarContainer::OnMouseButtonDown
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
Definition
scrollbarcontainer.c:197
ScrollBarContainer::ScrollBar
Widget ScrollBar
Definition
scrollbarcontainer.c:6
ScrollBarContainer::OnMouseWheel
override bool OnMouseWheel(Widget w, int x, int y, int wheel)
Definition
scrollbarcontainer.c:220
ScrollBarContainer::OnMouseButtonUp
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
Definition
scrollbarcontainer.c:213
ScrollBarContainer::StopScrolling
void StopScrolling()
Definition
scrollbarcontainer.c:155
Widget
Definition
enwidgets.c:190
g_Game
DayZGame g_Game
Definition
dayzgame.c:3942
MouseState
MouseState
Definition
ensystem.c:311
GetMousePos
proto void GetMousePos(out int x, out int y)
WidgetFlags
WidgetFlags
Definition
enwidgets.c:58
x
Icon x
y
Icon y
Games
Dayz
scripts
3_game
gui
containers
scrollbarcontainer.c
Generated by
1.17.0