2015-07-01 11:41:47 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2015 Neo Kim (neo.kim@neofect.com)
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2015-07-01 11:41:47 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __UISCROLLVIEWBAR_H__
|
|
|
|
#define __UISCROLLVIEWBAR_H__
|
|
|
|
|
|
|
|
#include "ui/UIScrollView.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Sprite;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace ui
|
|
|
|
{
|
2015-07-01 11:41:47 +08:00
|
|
|
|
2015-07-03 21:17:15 +08:00
|
|
|
/**
|
|
|
|
* Scroll bar being attached to ScrollView layout container.
|
|
|
|
*/
|
2015-07-01 11:41:47 +08:00
|
|
|
class CC_GUI_DLL ScrollViewBar : public ProtectedNode
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
* @js ctor
|
|
|
|
* @lua new
|
|
|
|
*/
|
2015-07-01 11:41:47 +08:00
|
|
|
ScrollViewBar(ScrollView* parent, ScrollView::Direction direction);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
|
|
|
* Default destructor
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2015-07-01 11:41:47 +08:00
|
|
|
virtual ~ScrollViewBar();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
2015-09-20 22:39:41 +08:00
|
|
|
* Create a scroll bar with its parent scroll view and direction.
|
|
|
|
* @return A scroll bar instance.
|
2015-07-03 22:03:02 +08:00
|
|
|
*/
|
2015-07-01 11:41:47 +08:00
|
|
|
static ScrollViewBar* create(ScrollView* parent, ScrollView::Direction direction);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
2015-07-03 23:11:01 +08:00
|
|
|
* @brief Set the scroll bar position from the left-bottom corner (horizontal) or right-top corner (vertical).
|
2015-07-03 22:03:02 +08:00
|
|
|
*
|
2015-07-03 23:11:01 +08:00
|
|
|
* @param positionFromCorner The position from the left-bottom corner (horizontal) or right-top corner (vertical).
|
2015-07-03 22:03:02 +08:00
|
|
|
*/
|
2015-07-04 14:40:47 +08:00
|
|
|
void setPositionFromCorner(const Vec2& positionFromCorner);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
2015-07-03 23:11:01 +08:00
|
|
|
* @brief Get the scroll bar position from the left-bottom corner (horizontal) or right-top corner (vertical).
|
2015-07-03 22:03:02 +08:00
|
|
|
*
|
2015-07-03 23:11:01 +08:00
|
|
|
* @return positionFromCorner
|
2015-07-03 22:03:02 +08:00
|
|
|
*/
|
2015-07-04 14:40:47 +08:00
|
|
|
Vec2 getPositionFromCorner() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
|
|
|
* @brief Set the scroll bar's width
|
|
|
|
*
|
|
|
|
* @param width The scroll bar's width
|
|
|
|
*/
|
|
|
|
void setWidth(float width);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
|
|
|
* @brief Get the scroll bar's width
|
|
|
|
*
|
|
|
|
* @return the scroll bar's width
|
|
|
|
*/
|
|
|
|
float getWidth() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
|
|
|
* @brief Set scroll bar auto hide state
|
|
|
|
*
|
|
|
|
* @param scroll bar auto hide state
|
|
|
|
*/
|
|
|
|
void setAutoHideEnabled(bool autoHideEnabled);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
|
|
|
* @brief Query scroll bar auto hide state
|
|
|
|
*
|
|
|
|
* @return True if scroll bar auto hide is enabled, false otherwise.
|
|
|
|
*/
|
|
|
|
bool isAutoHideEnabled() const { return _autoHideEnabled; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
|
|
|
* @brief Set scroll bar auto hide time
|
|
|
|
*
|
|
|
|
* @param scroll bar auto hide time
|
|
|
|
*/
|
|
|
|
void setAutoHideTime(float autoHideTime) { _autoHideTime = autoHideTime; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
|
|
|
* @brief Get the scroll bar's auto hide time
|
|
|
|
*
|
|
|
|
* @return the scroll bar's auto hide time
|
|
|
|
*/
|
|
|
|
float getAutoHideTime() const { return _autoHideTime; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
|
|
|
* @brief This is called by parent ScrollView when the parent is scrolled. Don't call this directly.
|
|
|
|
*
|
|
|
|
* @param amount how much the inner container of ScrollView is out of boundary
|
|
|
|
*/
|
2015-07-01 11:41:47 +08:00
|
|
|
virtual void onScrolled(const Vec2& outOfBoundary);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2019-06-05 17:58:33 +08:00
|
|
|
virtual void setOpacity(uint8_t opacity) override { _opacity = opacity; }
|
|
|
|
virtual uint8_t getOpacity() const override { return _opacity; }
|
2015-07-01 11:41:47 +08:00
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void update(float deltaTime) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
|
|
|
* @brief This is called by parent ScrollView when a touch is began. Don't call this directly.
|
|
|
|
*/
|
2015-07-01 11:41:47 +08:00
|
|
|
void onTouchBegan();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-03 22:03:02 +08:00
|
|
|
/**
|
|
|
|
* @brief This is called by parent ScrollView when a touch is ended. Don't call this directly.
|
|
|
|
*/
|
2015-07-01 11:41:47 +08:00
|
|
|
void onTouchEnded();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS : virtual bool init() override;
|
|
|
|
|
2015-07-01 11:41:47 +08:00
|
|
|
private:
|
2015-07-04 14:40:47 +08:00
|
|
|
float calculateLength(float innerContainerMeasure, float scrollViewMeasure, float outOfBoundaryValue);
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 calculatePosition(float innerContainerMeasure,
|
|
|
|
float scrollViewMeasure,
|
|
|
|
float innerContainerPosition,
|
|
|
|
float outOfBoundaryValue,
|
|
|
|
float actualLength);
|
|
|
|
|
2015-07-04 14:40:47 +08:00
|
|
|
void updateLength(float length);
|
2015-08-24 17:19:28 +08:00
|
|
|
void processAutoHide(float deltaTime);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-01 11:41:47 +08:00
|
|
|
ScrollView* _parent;
|
|
|
|
ScrollView::Direction _direction;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-01 11:41:47 +08:00
|
|
|
Sprite* _upperHalfCircle;
|
|
|
|
Sprite* _lowerHalfCircle;
|
|
|
|
Sprite* _body;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-06-05 17:58:33 +08:00
|
|
|
uint8_t _opacity;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-04 14:40:47 +08:00
|
|
|
float _marginFromBoundary;
|
|
|
|
float _marginForLength;
|
|
|
|
|
2015-07-01 11:41:47 +08:00
|
|
|
bool _touching;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-07-01 11:41:47 +08:00
|
|
|
bool _autoHideEnabled;
|
2015-07-03 22:03:02 +08:00
|
|
|
float _autoHideTime;
|
2015-07-01 11:41:47 +08:00
|
|
|
float _autoHideRemainingTime;
|
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace ui
|
2015-07-01 11:41:47 +08:00
|
|
|
// end of ui group
|
|
|
|
/// @}
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif /* defined(__UISCROLLVIEWBAR_H__) */
|