2013-09-13 22:20:20 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:47:11 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
#ifndef __UILABEL_H__
|
|
|
|
#define __UILABEL_H__
|
|
|
|
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "gui/UIWidget.h"
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-12-23 15:02:52 +08:00
|
|
|
NS_CC_BEGIN
|
2013-11-06 16:04:06 +08:00
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
namespace ui {
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-12-23 15:02:52 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-12-31 16:36:33 +08:00
|
|
|
class Text : public Widget
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
DECLARE_CLASS_GUI_INFO
|
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*/
|
2013-12-31 16:36:33 +08:00
|
|
|
Text();
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
/**
|
|
|
|
* Default destructor
|
|
|
|
*/
|
2013-12-31 16:36:33 +08:00
|
|
|
virtual ~Text();
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
/**
|
|
|
|
* Allocates and initializes.
|
|
|
|
*/
|
2013-12-31 16:36:33 +08:00
|
|
|
static Text* create();
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
/**
|
|
|
|
* Changes the string value of label.
|
|
|
|
*
|
|
|
|
* @param text string value.
|
|
|
|
*/
|
2013-11-08 04:42:16 +08:00
|
|
|
void setText(const std::string& text);
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
/**
|
|
|
|
* Gets the string value of label.
|
|
|
|
*
|
|
|
|
* @return text string value.
|
|
|
|
*/
|
2013-11-08 04:42:16 +08:00
|
|
|
const std::string& getStringValue();
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
/**
|
|
|
|
* Gets the string length of label.
|
|
|
|
*
|
|
|
|
* @return string length.
|
|
|
|
*/
|
2014-01-07 18:26:31 +08:00
|
|
|
ssize_t getStringLength();
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
/**
|
|
|
|
* Sets the font size of label.
|
|
|
|
*
|
|
|
|
* @param font size.
|
|
|
|
*/
|
|
|
|
void setFontSize(int size);
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2014-03-01 22:34:25 +08:00
|
|
|
int getFontSize();
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
/**
|
|
|
|
* Sets the font name of label.
|
|
|
|
*
|
|
|
|
* @param font name.
|
|
|
|
*/
|
2013-11-08 04:42:16 +08:00
|
|
|
void setFontName(const std::string& name);
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2014-03-01 22:34:25 +08:00
|
|
|
const std::string& getFontName();
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
/**
|
|
|
|
* Sets the touch scale enabled of label.
|
|
|
|
*
|
|
|
|
* @param touch scale enabled of label.
|
|
|
|
*/
|
|
|
|
void setTouchScaleChangeEnabled(bool enabled);
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
/**
|
|
|
|
* Gets the touch scale enabled of label.
|
|
|
|
*
|
|
|
|
* @return touch scale enabled of label.
|
|
|
|
*/
|
|
|
|
bool isTouchScaleChangeEnabled();
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
//override "setAnchorPoint" method of widget.
|
2013-12-23 15:02:52 +08:00
|
|
|
virtual void setAnchorPoint(const Point &pt) override;
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
//override "getContentSize" method of widget.
|
2013-12-23 15:02:52 +08:00
|
|
|
virtual const Size& getContentSize() const override;
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
//override "getVirtualRenderer" method of widget.
|
2013-12-23 15:02:52 +08:00
|
|
|
virtual Node* getVirtualRenderer() override;
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-17 17:59:20 +08:00
|
|
|
/**
|
|
|
|
* Returns the "class name" of widget.
|
|
|
|
*/
|
2013-12-23 15:02:52 +08:00
|
|
|
virtual std::string getDescription() const override;
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-12-23 15:02:52 +08:00
|
|
|
void setTextAreaSize(const Size &size);
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2014-03-01 22:34:25 +08:00
|
|
|
const Size& getTextAreaSize();
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-12-23 15:02:52 +08:00
|
|
|
void setTextHorizontalAlignment(TextHAlignment alignment);
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2014-03-01 22:34:25 +08:00
|
|
|
TextHAlignment getTextHorizontalAlignment();
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2014-03-01 22:34:25 +08:00
|
|
|
void setTextVerticalAlignment(TextVAlignment alignment);
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2014-03-01 22:34:25 +08:00
|
|
|
TextVAlignment getTextVerticalAlignment();
|
2014-03-04 23:42:58 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
protected:
|
2013-11-14 13:42:10 +08:00
|
|
|
virtual bool init() override;
|
|
|
|
virtual void initRenderer() override;
|
|
|
|
virtual void onPressStateChangedToNormal() override;
|
|
|
|
virtual void onPressStateChangedToPressed() override;
|
|
|
|
virtual void onPressStateChangedToDisabled() override;
|
|
|
|
virtual void onSizeChanged() override;
|
2014-03-03 23:24:57 +08:00
|
|
|
virtual void updateTextureColor() override;
|
|
|
|
virtual void updateTextureOpacity() override;
|
|
|
|
virtual void updateTextureRGBA() override;
|
2014-03-06 13:40:46 +08:00
|
|
|
virtual void updateFlippedX() override;
|
|
|
|
virtual void updateFlippedY() override;
|
2013-09-13 22:20:20 +08:00
|
|
|
void labelScaleChangedWithSize();
|
2013-12-23 15:02:52 +08:00
|
|
|
virtual Widget* createCloneInstance() override;
|
|
|
|
virtual void copySpecialProperties(Widget* model) override;
|
2013-09-13 22:20:20 +08:00
|
|
|
protected:
|
2013-09-16 20:54:13 +08:00
|
|
|
bool _touchScaleChangeEnabled;
|
2013-11-13 20:01:57 +08:00
|
|
|
float _normalScaleValueX;
|
|
|
|
float _normalScaleValueY;
|
2013-09-16 20:54:13 +08:00
|
|
|
std::string _fontName;
|
|
|
|
int _fontSize;
|
|
|
|
float _onSelectedScaleOffset;
|
2013-12-23 15:02:52 +08:00
|
|
|
LabelTTF* _labelRenderer;
|
2013-09-13 22:20:20 +08:00
|
|
|
};
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-12-23 15:02:52 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
#endif /* defined(__CocoGUI__Label__) */
|