// force slider to new position manually void UI_SLIDER2::set_currentItem(int _currentItem) { if (_currentItem > numberItems) goto cpSafety; if (_currentItem == currentItem) goto cpSafety; if (_currentItem < 0) goto cpSafety; if (_currentItem > currentItem) { while (currentItem != _currentItem) { currentItem++; if (downCallback != NULL) downCallback(); } } else if (_currentItem < currentItem) { while (currentItem != _currentItem) { currentItem--; if (upCallback != NULL) upCallback(); } } currentPosition = fl2i(((float)currentItem/(float)numberItems) * (float)numberPositions); cpSafety: // helps fix math problem on x86_64 if (currentPosition > numberItems) currentPosition = numberItems; if (currentPosition < 0) currentPosition = 0; }
// force slider to new position manually void UI_SLIDER2::set_currentItem(int _currentItem) { if (_currentItem > numberItems) return; if (_currentItem == currentItem) return; if (_currentItem < 0) return; if (_currentItem > currentItem) { while (currentItem != _currentItem) { currentItem++; if (downCallback != NULL) downCallback(); } } else if (_currentItem < currentItem) { while (currentItem != _currentItem) { currentItem--; if (upCallback != NULL) upCallback(); } } currentPosition = fl2i(((float)currentItem/(float)numberItems) * (float)numberPositions); }
void UI_SLIDER2::process(int focus) { int OnMe, mouse_lock_move; if (disabled_flag) { return; } OnMe = is_mouse_on(); if ( OnMe ) { // are we on the button? if ( (ui_mouse.y >= (y+currentPosition)) && (ui_mouse.y <= (y+currentPosition+slider_h)) ) { slider_mode = S2M_ON_ME; if ( B1_PRESSED ) { mouse_locked = 1; } } } else slider_mode = S2M_DEFAULT; if ( !B1_PRESSED) { if (mouse_locked == 1) if (captureCallback != NULL) { captureCallback(); mprintf(("Called captureCallback()!\n")); } mouse_locked = 0; } if (!OnMe && !mouse_locked) return; // could we possibly be moving up? if ((OnMe && B1_PRESSED && ui_mouse.y < (currentPosition+y+slider_half_h-1)) || (mouse_locked && (ui_mouse.y < (currentPosition+y+slider_half_h-1))) ) { // make sure we wait at least 50 ms between events unless mouse locked if ( (timer_get_milliseconds() > last_scrolled+50) || B1_JUST_PRESSED || mouse_locked ) { last_scrolled = timer_get_milliseconds(); if (!mouse_locked) { if (currentItem > 0) { currentItem--; if (upCallback != NULL) { upCallback(); if (captureCallback != NULL) captureCallback(); } } currentPosition = fl2i((((float)currentItem/(float)numberItems) * (float)numberPositions)-.49); } else { mouse_lock_move = fl2i( ((((float)ui_mouse.y - (float)y - (float)slider_half_h)/(float)numberPositions) * (float)numberItems) -.49); mouse_lock_move = currentItem - mouse_lock_move; if (mouse_lock_move > 0) { while (mouse_lock_move > 0) { if (currentItem > 0) { currentItem--; if (upCallback != NULL) upCallback(); } mouse_lock_move--; } } // currentPosition = ui_mouse.y - y - slider_half_h; currentPosition = fl2i((((float)currentItem/(float)numberItems) * (float)numberPositions)-.49); } if (currentPosition < 0) currentPosition = 0; if (currentPosition > numberPositions) currentPosition = numberPositions; slider_mode = S2M_MOVING; } } if ( ( OnMe && B1_PRESSED && ui_mouse.y > (currentPosition+y+slider_half_h+1)) || (mouse_locked && (ui_mouse.y > (currentPosition+y+slider_half_h+1))) ) { // make sure we wait at least 50 ms between events unless mouse locked if ( (timer_get_milliseconds() > last_scrolled+50) || B1_JUST_PRESSED || mouse_locked ) { last_scrolled = timer_get_milliseconds(); if (!mouse_locked) { if (currentItem < numberItems) { currentItem++; if (downCallback != NULL) { downCallback(); if (captureCallback != NULL) captureCallback(); } } currentPosition = fl2i((((float)currentItem/(float)numberItems) * (float)numberPositions)-.49); } else { mouse_lock_move = fl2i( ((((float)ui_mouse.y - (float)y - (float)slider_half_h)/(float)numberPositions) * (float)numberItems) -.49); mouse_lock_move -= currentItem; if (mouse_lock_move > 0) { while (mouse_lock_move > 0) { if (currentItem < numberItems) { currentItem++; if (downCallback != NULL) downCallback(); } mouse_lock_move--; } } // currentPosition = ui_mouse.y - y - slider_half_h; currentPosition = fl2i((((float)currentItem/(float)numberItems) * (float)numberPositions)-.49); } if (currentPosition < 0){ currentPosition = 0; } if (currentPosition > numberPositions){ currentPosition = numberPositions; } slider_mode = S2M_MOVING; } } // if we are centerd on the bitmap and still in mouse lock mode, we need to make sure the MOVING bitmap is still shown // or if mouse is on us and we are pressing the mouse button if (mouse_locked || (OnMe && B1_PRESSED)){ slider_mode = S2M_MOVING; } }
void JoystickShield::processCallbacks() { processEvents(); // Joystick Callbacks if (isCenter() && centerCallback != NULL) { centerCallback(); } if (isUp() && upCallback != NULL) { upCallback(); } if (isRightUp() && rightUpCallback != NULL) { rightUpCallback(); } if (isRight() && rightCallback != NULL) { rightCallback(); } if (isRightDown() && rightDownCallback != NULL) { rightDownCallback(); } if (isDown() && downCallback != NULL) { downCallback(); } if (isLeftDown() && leftDownCallback != NULL) { leftDownCallback(); } if (isLeft() && leftCallback != NULL) { leftCallback(); } if (isLeftUp() && leftUpCallback != NULL) { leftUpCallback(); } // Button Callbacks if (isJoystickButton() && jsButtonCallback != NULL) { jsButtonCallback(); } if (isUpButton() && upButtonCallback != NULL) { upButtonCallback(); } if (isRightButton() && rightButtonCallback != NULL) { rightButtonCallback(); } if (isDownButton() && downButtonCallback != NULL) { downButtonCallback(); } if (isLeftButton() && leftButtonCallback != NULL) { leftButtonCallback(); } }