bool Scrollbar::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier) { float step = 0; if ((direction == ScrollUp && m_orientation == VerticalScrollbar) || (direction == ScrollLeft && m_orientation == HorizontalScrollbar)) step = -1; else if ((direction == ScrollDown && m_orientation == VerticalScrollbar) || (direction == ScrollRight && m_orientation == HorizontalScrollbar)) step = 1; if (granularity == ScrollByLine) step *= m_lineStep; else if (granularity == ScrollByPage) step *= m_pageStep; else if (granularity == ScrollByDocument) step *= m_totalSize; else if (granularity == ScrollByPixel) step *= m_pixelStep; float newPos = m_currentPos + step * multiplier; float maxPos = m_totalSize - m_visibleSize; newPos = max(min(newPos, maxPos), 0.0f); if (newPos == m_currentPos) return false; int oldValue = value(); m_currentPos = newPos; updateThumbPosition(); if (value() != oldValue && client()) client()->valueChanged(this); // return true even if the integer value did not change so that scroll event gets eaten return true; }
void ScrollBar::resized() { const int length = vertical ? getHeight() : getWidth(); const int buttonSize = upButton != nullptr ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), length / 2) : 0; if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this)) { thumbAreaStart = length / 2; thumbAreaSize = 0; } else { thumbAreaStart = buttonSize; thumbAreaSize = length - (buttonSize << 1); } if (upButton != nullptr) { if (vertical) { upButton->setBounds (0, 0, getWidth(), buttonSize); downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize); } else { upButton->setBounds (0, 0, buttonSize, getHeight()); downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight()); } } updateThumbPosition(); }
void Slider::mouseNoLongerDown() { // The thumb might have been dragged between two values if (m_mouseDown) updateThumbPosition(); Widget::mouseNoLongerDown(); }
//============================================================================== void ScrollBar::setRangeLimits (const Range<double>& newRangeLimit) { if (totalRange != newRangeLimit) { totalRange = newRangeLimit; setCurrentRange (visibleRange); updateThumbPosition(); } }
void ScrollBar::setCurrentRange (const Range<double>& newRange) { const Range<double> constrainedRange (totalRange.constrainRange (newRange)); if (visibleRange != constrainedRange) { visibleRange = constrainedRange; updateThumbPosition(); triggerAsyncUpdate(); } }
void Scrollbar::offsetDidChange() { float position = static_cast<float>(m_scrollableArea.scrollOffset(m_orientation)); if (position == m_currentPos) return; int oldThumbPosition = theme().thumbPosition(*this); m_currentPos = position; updateThumbPosition(); if (m_pressedPart == ThumbPart) setPressedPos(m_pressedPos + theme().thumbPosition(*this) - oldThumbPosition); }
bool Scrollbar::setValue(int v) { v = max(min(v, m_totalSize - m_visibleSize), 0); if (value() == v) return false; // Our value stayed the same. m_currentPos = v; updateThumbPosition(); if (client()) client()->valueChanged(this); return true; }
void Scrollbar::offsetDidChange() { ASSERT(m_scrollableArea); float position = static_cast<float>(m_scrollableArea->scrollPosition(this)); if (position == m_currentPos) return; int oldThumbPosition = theme()->thumbPosition(this); m_currentPos = position; updateThumbPosition(); if (m_pressedPart == ThumbPart) setPressedPos(m_pressedPos + theme()->thumbPosition(this) - oldThumbPosition); }
void ScrollBar::setButtonVisibility (const bool buttonsAreVisible) { upButton = nullptr; downButton = nullptr; if (buttonsAreVisible) { addAndMakeVisible (upButton = new ScrollbarButton (vertical ? 0 : 3, *this)); addAndMakeVisible (downButton = new ScrollbarButton (vertical ? 2 : 1, *this)); setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs); } updateThumbPosition(); }
void ScrollBar::setOrientation (const bool shouldBeVertical) { if (vertical != shouldBeVertical) { vertical = shouldBeVertical; if (upButton != nullptr) { upButton->direction = vertical ? 0 : 3; downButton->direction = vertical ? 2 : 1; } updateThumbPosition(); } }
void Slider::setMaximum(int maximum) { // Set the new maximum m_maximum = maximum; // The minimum can't be below the maximum if (m_minimum > m_maximum) setMinimum(m_maximum); // When the value is above the maximum then adjust it if (m_value > m_maximum) setValue(m_maximum); updateThumbPosition(); }
void Slider::setValue(int value) { // When the value is below the minimum or above the maximum then adjust it if (value < m_minimum) value = m_minimum; else if (value > m_maximum) value = m_maximum; if (m_value != value) { m_value = value; onValueChange.emit(this, m_value); updateThumbPosition(); } }
bool Scrollbar::setCurrentPos(float pos, ScrollSource source) { if ((source != FromScrollAnimator) && client()) client()->setScrollPositionAndStopAnimation(m_orientation, pos); if (pos == m_currentPos) return false; int oldValue = value(); int oldThumbPos = theme()->thumbPosition(this); m_currentPos = pos; updateThumbPosition(); if (m_pressedPart == ThumbPart) setPressedPos(m_pressedPos + theme()->thumbPosition(this) - oldThumbPos); if (value() != oldValue && client()) client()->valueChanged(this); return true; }
bool Scrollbar::setCurrentPos(float pos) { if (pos == m_currentPos) #if PLATFORM(SDL) return true; #else return false; #endif int oldValue = value(); int oldThumbPos = theme()->thumbPosition(this); m_currentPos = pos; updateThumbPosition(); if (m_pressedPart == ThumbPart) setPressedPos(m_pressedPos + theme()->thumbPosition(this) - oldThumbPos); if (value() != oldValue && client()) client()->valueChanged(this); return true; }
void wySlider::updateUI() { float percent = (m_value - m_min) / (m_max - m_min); if(!m_showFullBar) m_progressTimer->setPercentage(percent * 100.f); updateThumbPosition(percent); }
void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange) { autohides = shouldHideWhenFullRange; updateThumbPosition(); }
void Slider::leftMouseReleased(sf::Vector2f) { // The thumb might have been dragged between two values if (m_mouseDown) updateThumbPosition(); }
void Slider::setSize(const Layout2d& size) { Widget::setSize(size); m_bordersCached.updateParentSize(getSize()); if (getSize().x < getSize().y) m_verticalScroll = true; else m_verticalScroll = false; if (m_spriteTrack.isSet() && m_spriteThumb.isSet()) { float scaleFactor; if (m_verticalImage == m_verticalScroll) { m_spriteTrack.setSize(getInnerSize()); m_spriteTrackHover.setSize(getInnerSize()); if (m_verticalScroll) scaleFactor = getInnerSize().x / m_spriteTrack.getTexture().getImageSize().x; else scaleFactor = getInnerSize().y / m_spriteTrack.getTexture().getImageSize().y; } else // The image is rotated { m_spriteTrack.setSize({getInnerSize().y, getInnerSize().x}); m_spriteTrackHover.setSize({getInnerSize().y, getInnerSize().x}); if (m_verticalScroll) scaleFactor = getInnerSize().x / m_spriteTrack.getTexture().getImageSize().y; else scaleFactor = getInnerSize().y / m_spriteTrack.getTexture().getImageSize().x; } m_thumb.width = scaleFactor * m_spriteThumb.getTexture().getImageSize().x; m_thumb.height = scaleFactor * m_spriteThumb.getTexture().getImageSize().y; m_spriteThumb.setSize({m_thumb.width, m_thumb.height}); m_spriteThumbHover.setSize({m_thumb.width, m_thumb.height}); // Apply the rotation now that the size has been set if (m_verticalScroll != m_verticalImage) { m_spriteTrack.setRotation(-90); m_spriteTrackHover.setRotation(-90); m_spriteThumb.setRotation(-90); m_spriteThumbHover.setRotation(-90); } else { m_spriteTrack.setRotation(0); m_spriteTrackHover.setRotation(0); m_spriteThumb.setRotation(0); m_spriteThumbHover.setRotation(0); } } else // There are no textures { if (m_verticalScroll) { m_thumb.width = getSize().x * 1.6f; m_thumb.height = m_thumb.width / 2.0f; } else { m_thumb.height = getSize().y * 1.6f; m_thumb.width = m_thumb.height / 2.0f; } } updateThumbPosition(); }