2020-10-18 12:31:45 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 cocos2d-x.org
|
2022-07-10 09:47:41 +08:00
|
|
|
* https://axis-project.github.io/
|
2020-10-18 12:31:45 +08:00
|
|
|
*
|
|
|
|
* Copyright 2011 Yannick Loriot. All rights reserved.
|
|
|
|
* http://yannickloriot.com
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2020-10-18 12:31:45 +08:00
|
|
|
* Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2020-10-18 12:31:45 +08:00
|
|
|
* 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:
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2020-10-18 12:31:45 +08:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2020-10-18 12:31:45 +08:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Converted to c++ / cocos2d-x by Angus C
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __CCCONTROL_SLIDER_H__
|
|
|
|
#define __CCCONTROL_SLIDER_H__
|
|
|
|
|
|
|
|
#include "CCControl.h"
|
|
|
|
#include "CCInvocation.h"
|
|
|
|
#include "extensions/ExtensionExport.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_EXT_BEGIN
|
2020-10-18 12:31:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup GUI
|
|
|
|
* @{
|
|
|
|
* @addtogroup control_extension
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_EX_DLL ControlSlider : public Control
|
2020-10-18 12:31:45 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates slider with a background filename, a progress filename and a
|
|
|
|
* thumb image filename.
|
|
|
|
*/
|
|
|
|
static ControlSlider* create(const char* bgFile, const char* progressFile, const char* thumbFile);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a slider with a given background sprite and a progress bar and a
|
|
|
|
* thumb item.
|
|
|
|
*
|
|
|
|
* @see initWithSprites
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static ControlSlider* create(Sprite* backgroundSprite, Sprite* pogressSprite, Sprite* thumbSprite);
|
2020-10-18 12:31:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates slider with a background filename, a progress filename, a thumb
|
|
|
|
* and a selected thumb image filename.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static ControlSlider* create(const char* bgFile,
|
|
|
|
const char* progressFile,
|
|
|
|
const char* thumbFile,
|
|
|
|
const char* selectedThumbSpriteFile);
|
2020-10-18 12:31:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a slider with a given background sprite and a progress bar, a thumb
|
|
|
|
* and a selected thumb .
|
|
|
|
*
|
|
|
|
* @see initWithSprites
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static ControlSlider* create(Sprite* backgroundSprite,
|
|
|
|
Sprite* pogressSprite,
|
|
|
|
Sprite* thumbSprite,
|
|
|
|
Sprite* selectedThumbSprite);
|
2020-10-18 12:31:45 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
* @lua new
|
|
|
|
*/
|
|
|
|
ControlSlider();
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~ControlSlider();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Initializes a slider with a background sprite, a progress bar and a thumb
|
|
|
|
* item.
|
|
|
|
*
|
|
|
|
* @param backgroundSprite Sprite, that is used as a background.
|
|
|
|
* @param progressSprite Sprite, that is used as a progress bar.
|
|
|
|
* @param thumbSprite Sprite, that is used as a thumb.
|
|
|
|
*/
|
|
|
|
virtual bool initWithSprites(Sprite* backgroundSprite, Sprite* progressSprite, Sprite* thumbSprite);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a slider with a background sprite, a progress bar and a thumb
|
|
|
|
* item.
|
|
|
|
*
|
|
|
|
* @param backgroundSprite Sprite, that is used as a background.
|
|
|
|
* @param progressSprite Sprite, that is used as a progress bar.
|
|
|
|
* @param thumbSprite Sprite, that is used as a thumb.
|
|
|
|
* @param selectedThumbSprite Sprite, that is used as a selected thumb.
|
|
|
|
*/
|
|
|
|
virtual bool initWithSprites(Sprite* backgroundSprite,
|
|
|
|
Sprite* progressSprite,
|
|
|
|
Sprite* thumbSprite,
|
|
|
|
Sprite* selectedThumbSprite);
|
2020-10-18 12:31:45 +08:00
|
|
|
|
|
|
|
virtual void needsLayout() override;
|
|
|
|
|
|
|
|
virtual void setMaximumValue(float val);
|
|
|
|
virtual void setEnabled(bool enabled) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual bool isTouchInside(Touch* touch) override;
|
2020-10-18 12:31:45 +08:00
|
|
|
Vec2 locationFromTouch(Touch* touch);
|
|
|
|
virtual void setValue(float val);
|
|
|
|
virtual void setMinimumValue(float val);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void sliderBegan(Vec2 location);
|
|
|
|
void sliderMoved(Vec2 location);
|
|
|
|
void sliderEnded(Vec2 location);
|
|
|
|
|
|
|
|
virtual bool onTouchBegan(Touch* touch, Event* pEvent) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void onTouchMoved(Touch* pTouch, Event* pEvent) override;
|
|
|
|
virtual void onTouchEnded(Touch* pTouch, Event* pEvent) override;
|
2020-10-18 12:31:45 +08:00
|
|
|
|
|
|
|
/** Returns the value for the given location. */
|
|
|
|
float valueForLocation(Vec2 location);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
// manually put in the setters
|
2020-10-18 12:31:45 +08:00
|
|
|
/** Contains the receiver's current value. */
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_SYNTHESIZE_READONLY(float, _value, Value);
|
2020-10-18 12:31:45 +08:00
|
|
|
|
|
|
|
/** Contains the minimum value of the receiver.
|
|
|
|
* The default value of this property is 0.0. */
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_SYNTHESIZE_READONLY(float, _minimumValue, MinimumValue);
|
2020-10-18 12:31:45 +08:00
|
|
|
|
|
|
|
/** Contains the maximum value of the receiver.
|
|
|
|
* The default value of this property is 1.0. */
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_SYNTHESIZE_READONLY(float, _maximumValue, MaximumValue);
|
2020-10-18 12:31:45 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_SYNTHESIZE(float, _minimumAllowedValue, MinimumAllowedValue);
|
|
|
|
AX_SYNTHESIZE(float, _maximumAllowedValue, MaximumAllowedValue);
|
2020-10-18 12:31:45 +08:00
|
|
|
|
|
|
|
// maybe this should be read-only
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_SYNTHESIZE_RETAIN(Sprite*, _thumbSprite, ThumbSprite);
|
|
|
|
AX_SYNTHESIZE_RETAIN(Sprite*, _selectedThumbSprite, SelectedThumbSprite);
|
|
|
|
AX_SYNTHESIZE_RETAIN(Sprite*, _progressSprite, ProgressSprite);
|
|
|
|
AX_SYNTHESIZE_RETAIN(Sprite*, _backgroundSprite, BackgroundSprite);
|
2020-10-18 12:31:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// end of GUI group
|
|
|
|
/// @}
|
|
|
|
/// @}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_EXT_END
|
2020-10-18 12:31:45 +08:00
|
|
|
|
|
|
|
#endif
|