2014-03-11 17:13:54 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __UILABELATLAS_H__
|
|
|
|
#define __UILABELATLAS_H__
|
|
|
|
|
|
|
|
#include "ui/UIWidget.h"
|
2014-07-21 17:45:56 +08:00
|
|
|
#include "ui/GUIExport.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2014-06-04 14:26:21 +08:00
|
|
|
class Label;
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_GUI_DLL TextAtlas : public Widget
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
DECLARE_CLASS_GUI_INFO
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*/
|
|
|
|
TextAtlas();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default destructor
|
|
|
|
*/
|
|
|
|
virtual ~TextAtlas();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates and initializes.
|
|
|
|
*/
|
|
|
|
static TextAtlas* create();
|
|
|
|
|
2014-04-02 18:06:03 +08:00
|
|
|
/**
|
|
|
|
* create a LabelAtlas from a char map file
|
|
|
|
*/
|
|
|
|
static TextAtlas* create(const std::string& stringValue,
|
|
|
|
const std::string& charMapFile,
|
|
|
|
int itemWidth,
|
|
|
|
int itemHeight,
|
|
|
|
const std::string& startCharMap);
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
/** initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */
|
2014-04-02 18:06:03 +08:00
|
|
|
void setProperty(const std::string& stringValue,
|
|
|
|
const std::string& charMapFile,
|
|
|
|
int itemWidth,
|
|
|
|
int itemHeight,
|
|
|
|
const std::string& startCharMap);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
//set string value for labelatlas.
|
2014-05-14 15:51:50 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void setStringValue(const std::string& value){this->setString(value);}
|
|
|
|
void setString(const std::string& value);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
//get string value for labelatlas.
|
2014-05-14 15:51:50 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE const std::string& getStringValue() const{return this->getString();}
|
|
|
|
const std::string& getString() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the string length of the label.
|
|
|
|
* Note: This length will be larger than the raw string length,
|
|
|
|
* if you want to get the raw string length, you should call this->getString().size() instead
|
|
|
|
*
|
|
|
|
* @return string length.
|
|
|
|
*/
|
2014-05-14 16:25:30 +08:00
|
|
|
ssize_t getStringLength()const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2014-04-17 14:08:25 +08:00
|
|
|
//override "getVirtualRendererSize" method of widget.
|
|
|
|
virtual const Size& getVirtualRendererSize() const override;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
//override "getVirtualRenderer" method of widget.
|
|
|
|
virtual Node* getVirtualRenderer() override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the "class name" of widget.
|
|
|
|
*/
|
|
|
|
virtual std::string getDescription() const override;
|
|
|
|
|
2014-04-17 14:08:25 +08:00
|
|
|
virtual void adaptRenderers() override;
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
|
|
|
virtual void initRenderer() override;
|
|
|
|
virtual void onSizeChanged() override;
|
2014-06-06 16:09:13 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
void labelAtlasScaleChangedWithSize();
|
|
|
|
virtual Widget* createCloneInstance() override;
|
|
|
|
virtual void copySpecialProperties(Widget* model) override;
|
|
|
|
protected:
|
2014-05-14 15:51:50 +08:00
|
|
|
Label* _labelAtlasRenderer;
|
2014-03-11 17:13:54 +08:00
|
|
|
std::string _stringValue;
|
|
|
|
std::string _charMapFileName;
|
|
|
|
int _itemWidth;
|
|
|
|
int _itemHeight;
|
|
|
|
std::string _startCharMap;
|
2014-04-17 14:08:25 +08:00
|
|
|
bool _labelAtlasRendererAdaptDirty;
|
2014-03-11 17:13:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif /* defined(__CocoGUI__LabelAtlas__) */
|