MCPcopy Create free account
hub / github.com/ddnet/ddnet / Update

Method Update

src/game/client/ui.cpp:183–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181}
182
183void CUi::Update(vec2 MouseWorldPos)
184{
185 const vec2 WindowSize = vec2(Graphics()->WindowWidth(), Graphics()->WindowHeight());
186 const CUIRect *pScreen = Screen();
187
188 unsigned UpdatedMouseButtonsNext = 0;
189 if(Enabled())
190 {
191 // Update mouse buttons based on mouse keys
192 for(int MouseKey = KEY_MOUSE_1; MouseKey <= KEY_MOUSE_3; ++MouseKey)
193 {
194 if(Input()->KeyIsPressed(MouseKey))
195 {
196 m_UpdatedMouseButtons |= 1 << (MouseKey - KEY_MOUSE_1);
197 }
198 }
199
200 // Update mouse position and buttons based on touch finger state
201 UpdateTouchState(m_TouchState);
202 if(m_TouchState.m_AnyPressed)
203 {
204 if(!CheckMouseLock())
205 {
206 m_UpdatedMousePos = m_TouchState.m_PrimaryPosition * WindowSize;
207 m_UpdatedMousePos.x = std::clamp(m_UpdatedMousePos.x, 0.0f, WindowSize.x - 1.0f);
208 m_UpdatedMousePos.y = std::clamp(m_UpdatedMousePos.y, 0.0f, WindowSize.y - 1.0f);
209 }
210 m_UpdatedMouseDelta += m_TouchState.m_PrimaryDelta * WindowSize;
211
212 // Scroll currently hovered scroll region with touch scroll gesture.
213 if(m_TouchState.m_ScrollAmount != vec2(0.0f, 0.0f))
214 {
215 if(m_pHotScrollRegion != nullptr)
216 {
217 m_pHotScrollRegion->ScrollRelativeDirect(-m_TouchState.m_ScrollAmount.y * pScreen->h);
218 }
219 m_TouchState.m_ScrollAmount = vec2(0.0f, 0.0f);
220 }
221
222 // We need to delay the click until the next update or it's not possible to use UI
223 // elements because click and hover would happen at the same time for touch events.
224 if(m_TouchState.m_PrimaryPressed)
225 {
226 UpdatedMouseButtonsNext |= 1;
227 }
228 if(m_TouchState.m_SecondaryPressed)
229 {
230 UpdatedMouseButtonsNext |= 2;
231 }
232 }
233 }
234
235 m_MousePos = m_UpdatedMousePos * vec2(pScreen->w, pScreen->h) / WindowSize;
236 m_MouseDelta = m_UpdatedMouseDelta;
237 m_UpdatedMouseDelta = vec2(0.0f, 0.0f);
238 m_MouseWorldPos = MouseWorldPos;
239 m_LastMouseButtons = m_MouseButtons;
240 m_MouseButtons = m_UpdatedMouseButtons;

Callers 2

ConMapbugMethod · 0.45
ConMapbugMethod · 0.45

Calls 9

GraphicsFunction · 0.85
InputFunction · 0.85
WindowWidthMethod · 0.80
WindowHeightMethod · 0.80
KeyIsPressedMethod · 0.80
ScrollRelativeDirectMethod · 0.80
DeactivateMethod · 0.80
RenderFrameTimeMethod · 0.80
ClientFunction · 0.50

Tested by

no test coverage detected