static inline void UI_VScrollbarNodeAction (uiNode_t *node, int hoveredElement, qboolean allowCapture) { switch (hoveredElement) { case 0: UI_VScrollbarNodeDiff(node, -1); if (allowCapture) { UI_SetMouseCapture(node); capturedElement = hoveredElement; capturedTimer = UI_AllocTimer(node, 500, UI_VScrollbarNodeRepeat); UI_TimerStart(capturedTimer); } break; case 1: UI_VScrollbarNodeDiff(node, -10); if (allowCapture) { UI_SetMouseCapture(node); capturedElement = hoveredElement; capturedTimer = UI_AllocTimer(node, 500, UI_VScrollbarNodeRepeat); UI_TimerStart(capturedTimer); } break; case 2: if (allowCapture) { UI_SetMouseCapture(node); /* save start value */ oldMouseY = mousePosY; oldPos = EXTRADATA(node).pos; capturedElement = hoveredElement; } break; case 3: UI_VScrollbarNodeDiff(node, 10); if (allowCapture) { UI_SetMouseCapture(node); capturedElement = hoveredElement; capturedTimer = UI_AllocTimer(node, 500, UI_VScrollbarNodeRepeat); UI_TimerStart(capturedTimer); } break; case 4: UI_VScrollbarNodeDiff(node, 1); if (allowCapture) { UI_SetMouseCapture(node); capturedElement = hoveredElement; capturedTimer = UI_AllocTimer(node, 500, UI_VScrollbarNodeRepeat); UI_TimerStart(capturedTimer); } break; default: assert(qfalse); break; } }
/** * @brief Called when we are in UI mode and down a mouse button * @sa UI_LeftClick * @sa UI_RightClick * @sa UI_MiddleClick */ void UI_MouseDown (int x, int y, int button) { /* disable old long click event */ if (longPressTimer) UI_TimerStop(longPressTimer); uiNode_t* node; /* captured or hover node */ node = capturedNode ? capturedNode : hoveredNode; if (node != nullptr) { UI_MoveWindowOnTop(node->root); UI_Node_MouseDown(node, x, y, button); } /* select clickableNode on button up, and detect multipress button */ if (pressedNode == nullptr) { pressedNode = node; pressedNodeLocationX = x; pressedNodeLocationY = y; pressedNodeButton = button; /** @todo find a way to create the timer when UI loading and remove "if (longPressTimer)" */ if (longPressTimer == nullptr) { longPressTimer = UI_AllocTimer(nullptr, LONGPRESS_DELAY, UI_LongPressCallback); } UI_TimerStart(longPressTimer); } else { pressedNode = nullptr; } }
/** * @brief unittest around timer data structure. * It not test timer execution. */ TEST_F(UITest, TimerDataStructure) { uiNode_t* dummyNode = (uiNode_t*) 0x1; timerCallback_t dummyCallback = (timerCallback_t) 0x1; uiTimer_t* a, *b, *c; a = UI_AllocTimer(dummyNode, 10, dummyCallback); b = UI_AllocTimer(dummyNode, 20, dummyCallback); c = UI_AllocTimer(dummyNode, 30, dummyCallback); ASSERT_TRUE(UI_PrivateGetFirstTimer() == nullptr); UI_TimerStart(b); ASSERT_TRUE(UI_PrivateGetFirstTimer() == b); UI_TimerStart(a); ASSERT_TRUE(UI_PrivateGetFirstTimer() == a); UI_TimerStart(c); ASSERT_TRUE(UI_PrivateGetFirstTimer()->next->next == c); UI_TimerStop(a); UI_TimerStop(b); ASSERT_TRUE(a->owner != nullptr); ASSERT_TRUE(UI_PrivateGetFirstTimer() == c); ASSERT_TRUE(UI_PrivateGetFirstTimer()->next == nullptr); UI_TimerStart(a); ASSERT_TRUE(UI_PrivateGetFirstTimer() == a); ASSERT_TRUE(UI_PrivateGetFirstTimer()->next == c); UI_PrivateInsertTimerInActiveList(a->next, b); ASSERT_TRUE(UI_PrivateGetFirstTimer() == a); ASSERT_TRUE(UI_PrivateGetFirstTimer()->next == b); ASSERT_TRUE(UI_PrivateGetFirstTimer()->next->next == c); UI_TimerRelease(b); ASSERT_TRUE(UI_PrivateGetFirstTimer() == a); ASSERT_TRUE(UI_PrivateGetFirstTimer()->next == c); UI_TimerRelease(a); ASSERT_TRUE(UI_PrivateGetFirstTimer() == c); UI_TimerRelease(c); ASSERT_TRUE(UI_PrivateGetFirstTimer() == nullptr); ASSERT_TRUE(c->owner == nullptr); }
static void UI_ZoneNodeDown (uiNode_t *node, int x, int y, int button) { if (!EXTRADATA(node).repeat) return; if (button == K_MOUSE1) { UI_SetMouseCapture(node); capturedTimer = UI_AllocTimer(node, EXTRADATA(node).clickDelay, UI_ZoneNodeRepeat); UI_TimerStart(capturedTimer); } }
void uiSpinnerNode::onMouseDown (uiNode_t *node, int x, int y, int button) { const bool disabled = node->disabled || node->parent->disabled; if (disabled) return; if (button == K_MOUSE1) { UI_SetMouseCapture(node); UI_NodeAbsoluteToRelativePos(node, &x, &y); capturedDownButton = !isPositionIncrease(node, x, y); step(node, capturedDownButton); capturedTimer = UI_AllocTimer(node, 500, UI_SpinnerNodeRepeat); UI_TimerStart(capturedTimer); } }
/** * @brief Take all screenshots from lower to upper map level. * Use a timer to delay each capture */ static void CL_BattlescapeRadarGenerateAll_f (void) { const int delay = 1000; timer = UI_AllocTimer(nullptr, delay, CL_BattlescapeRadarGenerateAll); UI_TimerStart(timer); }