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;
24 void ScrollFixedAmount(
bool down,
float amount )
30 m_root.GetScreenSize(width, m_root_height);
31 Content.GetScreenSize(width, m_content_height);
33 float diff = m_root_height / m_content_height;
34 float one_percent = diff / 100;
35 float percents = amount / m_content_height;
37 float step = (percents/100);
39 m_position += 1 * ( percents + 0.05 );
41 m_position -= 1 * ( percents + 0.05 );
43 if (m_position < 0) m_position = 0;
44 if (m_position > 1 - diff) m_position = 1 - diff;
48 void ScrollToPos(
float pos )
54 m_root.GetScreenSize(width, m_root_height);
55 Content.GetScreenSize(width, m_content_height);
57 float diff = m_root_height / m_content_height;
58 float percents = pos / m_content_height;
60 m_position = percents;
64 if (m_position > 1 - diff)
65 m_position = 1 - diff;
75 m_root.GetScreenSize(width, m_root_height);
76 Content.GetScreenSize(width, m_content_height);
78 float diff = m_root_height / m_content_height;
79 m_position = 1 - diff;
92 float GetContentYPos()
101 return m_root_height;
104 void UpdateScroller()
111 float scroller_height;
113 m_root.GetScreenSize(width, m_root_height);
114 Content.GetScreenSize(width, m_content_height);
116 diff = m_content_height - m_root_height;
120 Scroller.Show(
false);
121 ScrollBar.Show(
false);
126 scroller_height = (m_root_height / m_content_height) * m_root_height;
128 ScrollBar.Show(
true);
130 Scroller.GetSize(width, height);
131 Scroller.SetSize(width, scroller_height);
133 float pos = ( -m_content_height * m_position );
138 Scroller.SetPos(0, -pos);
141 Content.SetPos(0, -(diff + (-diff * m_position)));
146 void OnWidgetScriptInit(
Widget w)
149 m_root.SetHandler(
this);
155 protected void StopScrolling()
159 GetGame().GetDragQueue().RemoveCalls(
this);
164 protected void UpdateScroll(
int mouse_x,
int mouse_y,
bool is_dragging)
170 m_root.GetScreenSize(width, m_root_height);
171 Content.GetScreenSize(width, m_content_height);
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;
197 override bool OnMouseButtonDown(
Widget w,
int x,
int y,
int button)
199 if (button ==
MouseState.LEFT && w == Scroller && !m_scrolling)
202 m_scrolling_start_pos = m_position;
205 GetGame().GetDragQueue().Call(
this,
"UpdateScroll");
213 override bool OnMouseButtonUp(
Widget w,
int x,
int y,
int button)
220 override bool OnMouseWheel(
Widget w,
int x,
int y,
int wheel)
222 if (m_scrolling || m_content_height <= m_root_height)
return false;
224 float step = (1.0 / (m_content_height - m_root_height)) * WHEEL_STEP;
225 m_position -= wheel * step;
227 if (m_position < 0) m_position = 0;
228 if (m_position > 1) m_position = 1;
233 override bool OnResize(
Widget w,
int x,
int y) {
234 if (w == m_root || w ==
Content)