7 protected string WIDGET_BACKGROUND =
"Background";
8 protected string WIDGET_HANDLER =
"Handler";
9 protected string WIDGET_FILLER_TOP =
"FillerTop";
10 protected string WIDGET_FILLER_BOTTOM =
"FillerBottom";
12 protected Widget m_wBackground;
13 protected Widget m_wHandler;
14 protected Widget m_wFillerTop;
15 protected Widget m_wFillerBottom;
17 protected bool m_IsClicked =
false;
18 protected int mouseX, mouseY = 0;
23 protected float m_fRootPosY;
24 protected float m_fRootSizeY;
27 protected float m_fHandlerAmount = 1;
28 protected float m_fHandlerPositon = 0;
32 ref ScriptInvoker m_OnScroll =
new ScriptInvoker;
39 override void HandlerAttached(Widget w)
41 super.HandlerAttached(w);
45 m_wFillerTop = w.FindAnyWidget(WIDGET_FILLER_TOP);
46 m_wFillerBottom = w.FindAnyWidget(WIDGET_FILLER_BOTTOM);
49 m_wHandler = w.FindAnyWidget(WIDGET_HANDLER);
56 m_Handle.m_OnDrag.Insert(DragHandler);
64 protected void DragHandler()
67 float handlerW, handlerH = 0;
68 m_Handle.GetRootWidget().GetScreenSize(handlerW, handlerH);
71 float top = handlerH/2;
72 float bottom = m_fRootSizeY - handlerH/2;
74 float clampHeight = bottom - top;
77 int mousePosX, mousePosY;
78 WidgetManager.GetMousePos(mousePosX, mousePosY);
81 mousePosY = mousePosY - m_fRootPosY - top - m_Handle.GetMouseOffsetY();
84 float scrollY = mousePosY / clampHeight;
85 scrollY = Math.Clamp(scrollY, 0, 1);
88 SetupPosition(m_fHandlerAmount, scrollY);
91 m_OnScroll.Invoke(m_fHandlerPositon);
96 protected void SetupScrollbarProperties()
100 m_wRoot.GetScreenPos(x, m_fRootPosY);
101 m_wRoot.GetScreenSize(x, m_fRootSizeY);
110 void SetupHandlerFill(
float fillAmount)
113 fillAmount = Math.Clamp(fillAmount, 0, 1.0);
116 SetupScrollbarProperties();
123 m_fHandlerAmount = fillAmount;
125 VerticalLayoutSlot.SetFillWeight(m_Handle.GetRootWidget(), fillAmount);
126 m_Handle.SetSizeY(fillAmount * m_fRootSizeY);
129 SetupPosition(fillAmount, m_fHandlerPositon);
134 void SetupPosition(
float fillAmount,
float pos)
137 if (!m_wFillerTop || !m_wFillerBottom)
141 fillAmount = Math.Clamp(fillAmount, 0.0, 1.0);
142 pos = Math.Clamp(pos, 0.0, 1.0);
145 m_fHandlerPositon = pos;
148 float fillersAmout = 1 - fillAmount;
150 float fillTop = fillersAmout * pos;
151 float fillBottom = fillersAmout * (1 - pos);
154 VerticalLayoutSlot.SetFillWeight(m_wFillerTop, fillTop);
155 VerticalLayoutSlot.SetFillWeight(m_wFillerBottom, fillBottom);
159 m_Handle.GetRootWidget().GetScreenPos(x, y);
160 m_Handle.SetPositionY(y);
199 void MoveHandlerPos(
float pos) { SetupPosition(m_fHandlerAmount, pos); }
206 float GetHandlerPosition() {
return m_fHandlerPositon; }