Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ScrollBarHandleComponent.c
Go to the documentation of this file.
1 
2 //------------------------------------------------------------------------------------------------
4 {
5  protected bool m_bIsDragged = false;
6  protected bool m_bIsHovered = false;
7 
8  // Stable
9  protected float m_fSizeY;
10 
11  protected float m_fPositionY;
12  protected float m_fMouseOffsetY;
13 
14  protected ref Color COLOR_HANDLER_DEFAULT = UIColors.CONTRAST_COLOR;
15  protected ref Color COLOR_HANDLER_HOVERED = Color.White;
16 
17  ref ScriptInvoker m_OnDrag = new ScriptInvoker;
18 
19  //-------------------------------------
20  // Override
21  //-------------------------------------
22 
23  //------------------------------------------------------------------------------------------------
24  override void HandlerAttached(Widget w)
25  {
26  super.HandlerAttached(w);
27 
28  // Handler root setup
29  m_wRoot = w;
30  m_wRoot.SetColor(COLOR_HANDLER_DEFAULT);
31  }
32 
33  //------------------------------------------------------------------------------------------------
34  override bool OnMouseEnter(Widget w, int x, int y)
35  {
36  super.OnMouseEnter(w, x, y);
37 
38  m_bIsHovered = true;
39  m_wRoot.SetColor(COLOR_HANDLER_HOVERED);
40 
41  return false;
42  }
43 
44  //------------------------------------------------------------------------------------------------
45  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
46  {
47  super.OnMouseLeave(w, enterW, x, y);
48 
49  m_bIsHovered = true;
50 
51  if (m_bIsDragged)
52  return false;
53 
54  m_wRoot.SetColor(COLOR_HANDLER_DEFAULT);
55  return false;
56  }
57 
58  //------------------------------------------------------------------------------------------------
59  override bool OnMouseButtonDown(Widget w, int x, int y, int button)
60  {
61  // Accept only LMB as valid click
62  if (button != 0)
63  return false;
64 
65  m_bIsDragged = true;
66 
67  // Mouse offset
68  int mouseX, mouseY;
69  WidgetManager.GetMousePos(mouseX, mouseY);
70  m_fMouseOffsetY = mouseY - m_fPositionY - m_fSizeY/2;
71 
72  DragHandler();
73 
74  PlaySound(m_sSoundClicked);
75  return false;
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  override bool OnMouseButtonUp(Widget w, int x, int y, int button)
80  {
81  // Accept only LMB as valid click
82  if (button != 0)
83  return false;
84 
85  m_bIsDragged = false;
86 
87  if (!m_bIsHovered)
88  m_wRoot.SetColor(COLOR_HANDLER_DEFAULT);
89 
90  PlaySound(m_sSoundClicked);
91  return false;
92  }
93 
94  //-------------------------------------
95  // Protected
96  //-------------------------------------
97 
98  //------------------------------------------------------------------------------------------------
100  protected void DragHandler()
101  {
102  if(!m_bIsDragged)
103  return;
104 
105  // Invoke move
106  m_OnDrag.Invoke();
107 
108  // Call drag
109  GetGame().GetCallqueue().CallLater(DragHandler, 0);
110  }
111 
112  //-------------------------------------
113  // Get & Set
114  //-------------------------------------
115 
116  //------------------------------------------------------------------------------------------------
117  void SetSizeY(float size) { m_fSizeY = size; }
118 
119  //------------------------------------------------------------------------------------------------
120  float GetSizeY() { return m_fSizeY; }
121 
122  //------------------------------------------------------------------------------------------------
123  void SetPositionY(float pos) { m_fPositionY = pos; }
124 
125  //------------------------------------------------------------------------------------------------
126  float GetPositionY() { return m_fPositionY; }
127 
128  //------------------------------------------------------------------------------------------------
129  float GetMouseOffsetY() {return m_fMouseOffsetY; }
130 };
SCR_ScrollBarHandleComponent
Definition: SCR_ScrollBarHandleComponent.c:3
PlaySound
SCR_ParticleContactComponentClass ScriptComponentClass PlaySound(IEntity owner, SCR_ParticleContactComponentClass prefabData, Contact contact)
Definition: SCR_ParticleContactComponent.c:38
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_WLibComponentBase
Base class for all final Reforger interactive elements.
Definition: SCR_WLibComponentBase.c:4
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_bIsDragged
protected bool m_bIsDragged
Definition: SCR_MapRTWBaseUI.c:31
UIColors
Definition: Constants.c:16
m_bIsHovered
protected bool m_bIsHovered
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:23