2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +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 __CCLABEL_ATLAS_H__
|
|
|
|
#define __CCLABEL_ATLAS_H__
|
|
|
|
|
|
|
|
#include "2d/CCAtlasNode.h"
|
|
|
|
#if CC_LABELATLAS_DEBUG_DRAW
|
2021-12-25 10:04:45 +08:00
|
|
|
# include "renderer/CCCustomCommand.h"
|
|
|
|
# include "2d/CCDrawNode.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
#endif
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup _2d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
* @class LabelAtlas
|
|
|
|
* @brief LabelAtlas is a subclass of AtlasNode.
|
|
|
|
*
|
|
|
|
* It can be as a replacement of Label since it is MUCH faster.
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2019-11-23 20:27:39 +08:00
|
|
|
* LabelAtlas versus Label:
|
|
|
|
* - LabelAtlas is MUCH faster than Label.
|
|
|
|
* - LabelAtlas "characters" have a fixed height and width.
|
|
|
|
* - LabelAtlas "characters" can be anything you want since they are taken from an image file.
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2019-11-23 20:27:39 +08:00
|
|
|
* A more flexible class is LabelBMFont. It supports variable width characters and it also has a nice editor.
|
|
|
|
*/
|
|
|
|
class CC_DLL LabelAtlas : public AtlasNode, public LabelProtocol
|
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Creates 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. */
|
2021-12-26 23:26:34 +08:00
|
|
|
static LabelAtlas* create(std::string_view string,
|
|
|
|
std::string_view charMapFile,
|
2021-12-25 10:04:45 +08:00
|
|
|
int itemWidth,
|
|
|
|
int itemHeight,
|
|
|
|
int startCharMap);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Creates the LabelAtlas with a string and a configuration file.
|
|
|
|
* @since v2.0
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static LabelAtlas* create(std::string_view string, std::string_view fntFile);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2020-09-09 15:29:56 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Creates the LabelAtlas with a string, a texture, the width and height of each element and the starting char of
|
|
|
|
* the atlas.
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static LabelAtlas* create(std::string_view string,
|
2021-12-25 10:04:45 +08:00
|
|
|
Texture2D* texture,
|
|
|
|
int itemWidth,
|
|
|
|
int itemHeight,
|
|
|
|
int startCharMap);
|
|
|
|
|
|
|
|
/** 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. */
|
2021-12-26 23:26:34 +08:00
|
|
|
bool initWithString(std::string_view string,
|
|
|
|
std::string_view charMapFile,
|
2021-12-25 10:04:45 +08:00
|
|
|
int itemWidth,
|
|
|
|
int itemHeight,
|
|
|
|
int startCharMap);
|
|
|
|
|
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
* Initializes the LabelAtlas with a string and a configuration file.
|
|
|
|
* @since v2.0
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
bool initWithString(std::string_view string, std::string_view fntFile);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/** Initializes the LabelAtlas with a string, a texture, the width and height in points of each element and the
|
|
|
|
* starting char of the atlas */
|
2021-12-26 23:26:34 +08:00
|
|
|
bool initWithString(std::string_view string, Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-01 03:35:34 +08:00
|
|
|
virtual void setString(std::string_view label) override;
|
2021-12-26 23:26:34 +08:00
|
|
|
virtual std::string_view getString() const override;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
virtual void updateAtlasValues() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
virtual std::string getDescription() const override;
|
|
|
|
|
|
|
|
#if CC_LABELATLAS_DEBUG_DRAW
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void draw(Renderer* renderer, const Mat4& transform, uint32_t flags) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
#endif
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS : LabelAtlas() : _string("")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
#if CC_LABELATLAS_DEBUG_DRAW
|
|
|
|
_debugDrawNode = DrawNode::create();
|
|
|
|
addChild(_debugDrawNode);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual ~LabelAtlas() { _string.clear(); }
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
|
|
|
virtual void updateColor() override;
|
|
|
|
|
|
|
|
#if CC_LABELATLAS_DEBUG_DRAW
|
2021-12-25 10:04:45 +08:00
|
|
|
DrawNode* _debugDrawNode;
|
2019-11-23 20:27:39 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// string to render
|
|
|
|
std::string _string;
|
|
|
|
// the first char in the char map
|
|
|
|
int _mapStartChar;
|
|
|
|
};
|
|
|
|
|
|
|
|
// end group
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif //__CCLABEL_ATLAS_H__
|