DayZ 1.24
Loading...
Searching...
No Matches
ScrollBarContainer.c
Go to the documentation of this file.
1// -----------------------------------------------------------
3{
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
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
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;
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
58 float percents = pos / m_content_height;
59
61
62 if (m_position < 0)
63 m_position = 0;
64 if (m_position > 1 - diff)
65 m_position = 1 - diff;
67 }
68
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
79 m_position = 1 - diff;
81 }
82
84 {
85 if (m_position != 0)
86 {
87 m_position = 0;
89 }
90 }
91
93 {
94 float x, y;
95 Content.GetPos(x, y);
96 return y;
97 }
98
100 {
101 return m_root_height;
102 }
103
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
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
127
128 ScrollBar.Show(true);
129 Scroller.Show(true);
130 Scroller.GetSize(width, 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
147 {
148 m_root = w;
149 m_root.SetHandler(this);
150 m_root.SetFlags(WidgetFlags.VEXACTPOS);
151 m_scrolling = false;
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 {
180 if (m_position < 0) m_position = 0;
181 if (m_position > 1) m_position = 1;
182 }
183 else
184 {
185 m_scrolling = false;
187 }
188 }
189
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;
202 int mouse_x;
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 {
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;
229 return true;
230 }
231
232 override bool OnResize(Widget w, int x, int y)
233 {
234 if (w == m_root || w == Content)
236 return false;
237 }
238};
Icon x
Icon y
map: item x vector(index, width, height)
Definition EnWidgets.c:651
reference bool Invert
void ScrollFixedAmount(bool down, float amount)
override bool OnMouseWheel(Widget w, int x, int y, int wheel)
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
void ScrollToPos(float pos)
override bool OnResize(Widget w, int x, int y)
void OnWidgetScriptInit(Widget w)
void UpdateScroll(int mouse_x, int mouse_y, bool is_dragging)
proto native CGame GetGame()
MouseState
Definition EnSystem.c:311
proto void GetMousePos(out int x, out int y)
WidgetFlags
Definition EnWidgets.c:58