Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
scrollbarcontainer.c
Go to the documentation of this file.
1// -----------------------------------------------------------
2class 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
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;
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;
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
78 float diff = m_root_height / m_content_height;
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
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;
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;
187 }
188 }
189
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;
203 int mouse_x;
205 GetGame().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 {
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;
230 return true;
231 }
232
233 override bool OnResize( Widget w, int x, int y) {
234 if (w == m_root || w == Content)
235 {
237 }
238 return false;
239 }
240};
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
Icon x
Icon y