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
|
|
|
|
|
2015-03-24 18:22:52 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2014-06-04 14:26:21 +08:00
|
|
|
class Label;
|
2015-12-05 00:26:07 +08:00
|
|
|
struct CC_DLL ResourceData;
|
2014-06-04 14:26:21 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
namespace ui {
|
|
|
|
|
2015-03-27 11:02:04 +08:00
|
|
|
/**
|
2015-03-24 18:22:52 +08:00
|
|
|
* @brief UI TextAtlas widget.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
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:
|
|
|
|
/**
|
2015-03-24 18:22:52 +08:00
|
|
|
* Default constructor.
|
2015-03-30 15:47:47 +08:00
|
|
|
*
|
|
|
|
* @lua new
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
TextAtlas();
|
|
|
|
|
|
|
|
/**
|
2015-03-24 18:22:52 +08:00
|
|
|
* Default destructor.
|
2015-03-30 15:47:47 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
virtual ~TextAtlas();
|
|
|
|
|
|
|
|
/**
|
2015-03-24 18:22:52 +08:00
|
|
|
* Create a TexAtlas object.
|
|
|
|
*
|
|
|
|
* @return An autoreleased TextAtlas object.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
static TextAtlas* create();
|
|
|
|
|
2014-04-02 18:06:03 +08:00
|
|
|
/**
|
2015-03-24 18:22:52 +08:00
|
|
|
* Create a LabelAtlas from a char map file.
|
|
|
|
*
|
|
|
|
* @param stringValue A given string needs to be displayed.
|
|
|
|
* @param charMapFile A given char map file name.
|
|
|
|
* @param itemWidth The element width.
|
|
|
|
* @param itemHeight The element height.
|
|
|
|
* @param startCharMap The starting char of the atlas.
|
|
|
|
* @return An autoreleased TextAtlas object.
|
2014-04-02 18:06:03 +08:00
|
|
|
*/
|
|
|
|
static TextAtlas* create(const std::string& stringValue,
|
|
|
|
const std::string& charMapFile,
|
|
|
|
int itemWidth,
|
|
|
|
int itemHeight,
|
|
|
|
const std::string& startCharMap);
|
|
|
|
|
2015-03-24 18:22:52 +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.
|
|
|
|
*
|
|
|
|
* @param stringValue A given string needs to be displayed.
|
|
|
|
* @param charMapFile A given char map file name.
|
|
|
|
* @param itemWidth The element width.
|
|
|
|
* @param itemHeight The element height.
|
|
|
|
* @param startCharMap 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
|
|
|
|
2015-03-24 18:22:52 +08:00
|
|
|
/**Set string value for labelatlas.
|
|
|
|
*
|
|
|
|
* @param value A given string needs to be displayed.
|
|
|
|
*/
|
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
|
|
|
|
2015-03-24 18:22:52 +08:00
|
|
|
/**Get string value for labelatlas.
|
|
|
|
*
|
|
|
|
* @return The string value of TextAtlas.
|
|
|
|
*/
|
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.
|
2014-09-12 14:39:22 +08:00
|
|
|
virtual 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;
|
|
|
|
|
2015-03-30 21:38:32 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-04-17 14:08:25 +08:00
|
|
|
virtual void adaptRenderers() override;
|
2015-11-18 13:38:29 +08:00
|
|
|
|
2015-12-05 00:26:07 +08:00
|
|
|
ResourceData getRenderFile();
|
2015-11-18 13:38:29 +08:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2015-03-24 18:22:52 +08:00
|
|
|
|
|
|
|
// end of ui group
|
|
|
|
/// @}
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif /* defined(__CocoGUI__LabelAtlas__) */
|