@@ -59,8 +59,7 @@ private: | |||||
//============================================================================== | //============================================================================== | ||||
ScrollBar::ScrollBar (const bool vertical_, | |||||
const bool buttonsAreVisible) | |||||
ScrollBar::ScrollBar (const bool vertical_) | |||||
: totalRange (0.0, 1.0), | : totalRange (0.0, 1.0), | ||||
visibleRange (0.0, 0.1), | visibleRange (0.0, 0.1), | ||||
singleStepSize (0.1), | singleStepSize (0.1), | ||||
@@ -75,8 +74,6 @@ ScrollBar::ScrollBar (const bool vertical_, | |||||
isDraggingThumb (false), | isDraggingThumb (false), | ||||
autohides (true) | autohides (true) | ||||
{ | { | ||||
setButtonVisibility (buttonsAreVisible); | |||||
setRepaintsOnMouseActivity (true); | setRepaintsOnMouseActivity (true); | ||||
setFocusContainer (true); | setFocusContainer (true); | ||||
} | } | ||||
@@ -235,22 +232,6 @@ void ScrollBar::setOrientation (const bool shouldBeVertical) | |||||
} | } | ||||
} | } | ||||
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::setAutoHide (const bool shouldHideWhenFullRange) | void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange) | ||||
{ | { | ||||
autohides = shouldHideWhenFullRange; | autohides = shouldHideWhenFullRange; | ||||
@@ -296,12 +277,31 @@ void ScrollBar::paint (Graphics& g) | |||||
void ScrollBar::lookAndFeelChanged() | void ScrollBar::lookAndFeelChanged() | ||||
{ | { | ||||
setComponentEffect (getLookAndFeel().getScrollbarEffect()); | setComponentEffect (getLookAndFeel().getScrollbarEffect()); | ||||
resized(); | |||||
} | } | ||||
void ScrollBar::resized() | void ScrollBar::resized() | ||||
{ | { | ||||
const int length = vertical ? getHeight() : getWidth(); | const int length = vertical ? getHeight() : getWidth(); | ||||
const bool buttonsVisible = getLookAndFeel().areScrollbarButtonsVisible(); | |||||
if (buttonsVisible) | |||||
{ | |||||
if (upButton == nullptr) | |||||
{ | |||||
addAndMakeVisible (upButton = new ScrollbarButton (vertical ? 0 : 3, *this)); | |||||
addAndMakeVisible (downButton = new ScrollbarButton (vertical ? 2 : 1, *this)); | |||||
setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs); | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
upButton = nullptr; | |||||
downButton = nullptr; | |||||
} | |||||
const int buttonSize = upButton != nullptr ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), length / 2) | const int buttonSize = upButton != nullptr ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), length / 2) | ||||
: 0; | : 0; | ||||
@@ -27,7 +27,7 @@ | |||||
#define __JUCE_SCROLLBAR_JUCEHEADER__ | #define __JUCE_SCROLLBAR_JUCEHEADER__ | ||||
#include "../buttons/juce_Button.h" | #include "../buttons/juce_Button.h" | ||||
class Viewport; | |||||
//============================================================================== | //============================================================================== | ||||
/** | /** | ||||
@@ -50,7 +50,7 @@ | |||||
@see ScrollBar::Listener | @see ScrollBar::Listener | ||||
*/ | */ | ||||
class JUCE_API ScrollBar : public Component, | class JUCE_API ScrollBar : public Component, | ||||
public AsyncUpdater, | |||||
private AsyncUpdater, | |||||
private Timer | private Timer | ||||
{ | { | ||||
public: | public: | ||||
@@ -60,8 +60,7 @@ public: | |||||
@param isVertical whether it should be a vertical or horizontal bar | @param isVertical whether it should be a vertical or horizontal bar | ||||
@param buttonsAreVisible whether to show the up/down or left/right buttons | @param buttonsAreVisible whether to show the up/down or left/right buttons | ||||
*/ | */ | ||||
ScrollBar (bool isVertical, | |||||
bool buttonsAreVisible = true); | |||||
ScrollBar (bool isVertical); | |||||
/** Destructor. */ | /** Destructor. */ | ||||
~ScrollBar(); | ~ScrollBar(); | ||||
@@ -79,9 +78,6 @@ public: | |||||
*/ | */ | ||||
void setOrientation (bool shouldBeVertical); | void setOrientation (bool shouldBeVertical); | ||||
/** Shows or hides the scrollbar's buttons. */ | |||||
void setButtonVisibility (bool buttonsAreVisible); | |||||
/** Tells the scrollbar whether to make itself invisible when not needed. | /** Tells the scrollbar whether to make itself invisible when not needed. | ||||
The default behaviour is for a scrollbar to become invisible when the thumb | The default behaviour is for a scrollbar to become invisible when the thumb | ||||
@@ -295,8 +291,6 @@ public: | |||||
/** @internal */ | /** @internal */ | ||||
void lookAndFeelChanged(); | void lookAndFeelChanged(); | ||||
/** @internal */ | /** @internal */ | ||||
void handleAsyncUpdate(); | |||||
/** @internal */ | |||||
void mouseDown (const MouseEvent&); | void mouseDown (const MouseEvent&); | ||||
/** @internal */ | /** @internal */ | ||||
void mouseDrag (const MouseEvent&); | void mouseDrag (const MouseEvent&); | ||||
@@ -320,9 +314,12 @@ private: | |||||
ScopedPointer<ScrollbarButton> upButton, downButton; | ScopedPointer<ScrollbarButton> upButton, downButton; | ||||
ListenerList <Listener> listeners; | ListenerList <Listener> listeners; | ||||
void handleAsyncUpdate(); | |||||
void updateThumbPosition(); | void updateThumbPosition(); | ||||
void timerCallback(); | void timerCallback(); | ||||
friend class Viewport; | |||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ScrollBar); | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ScrollBar); | ||||
}; | }; | ||||
@@ -328,12 +328,6 @@ int Viewport::getScrollBarThickness() const | |||||
: getLookAndFeel().getDefaultScrollbarWidth(); | : getLookAndFeel().getDefaultScrollbarWidth(); | ||||
} | } | ||||
void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible) | |||||
{ | |||||
verticalScrollBar.setButtonVisibility (buttonsVisible); | |||||
horizontalScrollBar.setButtonVisibility (buttonsVisible); | |||||
} | |||||
void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart) | void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart) | ||||
{ | { | ||||
const int newRangeStartInt = roundToInt (newRangeStart); | const int newRangeStartInt = roundToInt (newRangeStart); | ||||
@@ -225,12 +225,6 @@ public: | |||||
*/ | */ | ||||
void setSingleStepSizes (int stepX, int stepY); | void setSingleStepSizes (int stepX, int stepY); | ||||
/** Shows or hides the buttons on any scrollbars that are used. | |||||
@see ScrollBar::setButtonVisibility | |||||
*/ | |||||
void setScrollBarButtonVisibility (bool buttonsVisible); | |||||
/** Returns a pointer to the scrollbar component being used. | /** Returns a pointer to the scrollbar component being used. | ||||
Handy if you need to customise the bar somehow. | Handy if you need to customise the bar somehow. | ||||
*/ | */ | ||||
@@ -713,6 +713,11 @@ void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, | |||||
} | } | ||||
} | } | ||||
bool LookAndFeel::areScrollbarButtonsVisible() | |||||
{ | |||||
return true; | |||||
} | |||||
void LookAndFeel::drawScrollbarButton (Graphics& g, | void LookAndFeel::drawScrollbarButton (Graphics& g, | ||||
ScrollBar& scrollbar, | ScrollBar& scrollbar, | ||||
int width, int height, | int width, int height, | ||||
@@ -229,6 +229,8 @@ public: | |||||
int x, int y, int w, int h); | int x, int y, int w, int h); | ||||
//============================================================================== | //============================================================================== | ||||
virtual bool areScrollbarButtonsVisible(); | |||||
/** Draws one of the buttons on a scrollbar. | /** Draws one of the buttons on a scrollbar. | ||||
@param g the context to draw into | @param g the context to draw into | ||||
@@ -1200,11 +1200,6 @@ void TextEditor::setScrollBarThickness (const int newThicknessPixels) | |||||
viewport->setScrollBarThickness (newThicknessPixels); | viewport->setScrollBarThickness (newThicknessPixels); | ||||
} | } | ||||
void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible) | |||||
{ | |||||
viewport->setScrollBarButtonVisibility (buttonsVisible); | |||||
} | |||||
//============================================================================== | //============================================================================== | ||||
void TextEditor::clear() | void TextEditor::clear() | ||||
{ | { | ||||
@@ -287,12 +287,6 @@ public: | |||||
*/ | */ | ||||
void setScrollBarThickness (int newThicknessPixels); | void setScrollBarThickness (int newThicknessPixels); | ||||
/** Shows or hides the buttons on any scrollbars that are used. | |||||
@see ScrollBar::setButtonVisibility | |||||
*/ | |||||
void setScrollBarButtonVisibility (bool buttonsVisible); | |||||
//============================================================================== | //============================================================================== | ||||
/** | /** | ||||
Receives callbacks from a TextEditor component when it changes. | Receives callbacks from a TextEditor component when it changes. | ||||