mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into develop
This commit is contained in:
commit
ed69a31b45
|
@ -100,3 +100,8 @@ tools/jenkins_scripts/mac/android/userconf.ini
|
|||
|
||||
# CTags
|
||||
tags
|
||||
|
||||
# ignore files, created with make-all-linux-project script
|
||||
/lib
|
||||
/build/linux-build
|
||||
|
||||
|
|
4
AUTHORS
4
AUTHORS
|
@ -628,6 +628,7 @@ Developers:
|
|||
HoGarfield (garfield_ho)
|
||||
Fixed a bug that CCBReader can't play sequence automatically in JSB.
|
||||
Could not set next animation in CCBAnimationCompleted callback.
|
||||
Fixed missing to add JSAutoCompartment when invoking JS functions from C++.
|
||||
|
||||
lite3
|
||||
Fixed a bug that Node's anchor point was changed after being added to ScrollView.
|
||||
|
@ -642,6 +643,9 @@ Developers:
|
|||
Fixed a bug that EventListeners can't be removed sometimes.
|
||||
Fixed a bug that the data size has to be specified when parsing XML using TinyXML.
|
||||
|
||||
Luis Parravicini (luisparravicini)
|
||||
Fixed typos in create_project.py.
|
||||
|
||||
Retired Core Developers:
|
||||
WenSheng Yang
|
||||
Author of windows port, CCTextField,
|
||||
|
|
10
CHANGELOG
10
CHANGELOG
|
@ -10,18 +10,23 @@ cocos2d-x-3.0alpha1 @??? 2013
|
|||
[FIX] Could not set next animation in CCBAnimationCompleted callback.
|
||||
[FIX] The Node's anchor point was changed after being added to ScrollView.
|
||||
[FIX] Refactored and improved EventDispatcher.
|
||||
[NEW] Added Mouse Support For Desktop Platforms.
|
||||
[FIX] EventListeners can't be removed sometimes.
|
||||
[FIX] When parsing XML using TinyXML, the data size has to be specified.
|
||||
[FIX] Parameter type: const char* -> const string&
|
||||
[FIX] Armature: many bug fixed, add more samples, add function to skip some frames when playing animation
|
||||
[NEW] Arm64 support.
|
||||
[NEW] Added Mouse Support For Desktop Platforms.
|
||||
[NEW] Point: Adds ANCHOR_XXX constants like ANCHOR_MIDDLE, ANCHOR_TOP_RIGHT, etc.
|
||||
[NEW] Sprite: Override setScale(float scaleX, float scaleY)
|
||||
[NEW] External: added | operator for Control::EventType
|
||||
[Android]
|
||||
[FIX] Added EGL_RENDERABLE_TYPE to OpenGL attributes
|
||||
[NEW] Added Cocos2dxHelper.runOnGLThread(Runnable) again
|
||||
[FIX] Fixed application will crash when pause and resume.
|
||||
[FIX] Clear NoSuchMethodError Exception when JniHelper fails to find method id
|
||||
[NEW] Added xlargeScreens="true" to supports-screens
|
||||
[NEW] Added build/android-build.py to build all Android samples, and remove all build_native.sh/cmd
|
||||
[NEW] Added build_native.py to build template projects, and remove build_native.sh/cmd
|
||||
[NEW] Added Cocos2dxHelper.runOnGLThread(Runnable) again
|
||||
[Mac]
|
||||
[FIX] Removed unused CCLOG() from GL initialization
|
||||
[iOS]
|
||||
|
@ -35,6 +40,7 @@ cocos2d-x-3.0alpha1 @??? 2013
|
|||
[FIX] sys.localStorage.getItem() does not support non-ascii string.
|
||||
[FIX] cc.Scheduler.schedule(target, func) without repeat argument couldn't repeat schedule forever on device.
|
||||
[FIX] CCBReader can't play sequence automatically in JSB.
|
||||
[NEW] main.js -> cocos2d-jsb.js
|
||||
[Lua Binding]
|
||||
[NEW] Added Armature lua binding and added test samples.
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
project (Cocos2dxSamples)
|
||||
project (Cocos2dx)
|
||||
|
||||
# The version number
|
||||
set(Cocos2dxSamples_VERSION_MAJOR 3)
|
||||
|
@ -7,14 +7,45 @@ set(Cocos2dxSamples_VERSION_MINOR 0)
|
|||
|
||||
include(build/BuildHelpers.CMakeLists.txt)
|
||||
|
||||
set(CMAKE_BUILE_TYPE DEBUG)
|
||||
option(USE_CHIPMUNK "Use chipmunk for physics library" ON)
|
||||
option(USE_BOX2D "Use box2d for physics library" OFF)
|
||||
option(DEBUG_MODE "Debug or release?" ON)
|
||||
option(BUILD_LIBS_LUA "Build lua libraries" ON)
|
||||
option(BUILD_GUI "Build GUI library" ON)
|
||||
option(BUILD_NETWORK "Build network library" ON)
|
||||
option(BUILD_EXTENSIONS "Build extension library" ON)
|
||||
option(BUILD_EDITOR_SPINE "Build editor support for spine" ON)
|
||||
option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" ON)
|
||||
option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON)
|
||||
|
||||
|
||||
option(BUILD_HelloCpp "Only build HelloCpp sample" ON)
|
||||
option(BUILD_TestCpp "Only build TestCpp sample" ON)
|
||||
option(BUILD_HelloLua "Only build HelloLua sample" ON)
|
||||
option(BUILD_TestLua "Only build TestLua sample" ON)
|
||||
|
||||
|
||||
if(DEBUG_MODE)
|
||||
set(CMAKE_BUILD_TYPE DEBUG)
|
||||
else(DEBUG_MODE)
|
||||
set(CMAKE_BUILD_TYPE RELEASE)
|
||||
endif(DEBUG_MODE)
|
||||
|
||||
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
|
||||
|
||||
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-std=c99")
|
||||
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11")
|
||||
|
||||
add_definitions(-DLINUX -DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
|
||||
if(USE_CHIPMUNK)
|
||||
message("Using chipmunk ...")
|
||||
add_definitions(-DLINUX -DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
|
||||
elseif(USE_BOX2D)
|
||||
message("Using box2d ...")
|
||||
add_definitions(-DLINUX -DCC_ENABLE_BOX2D_INTEGRATION=1)
|
||||
else(USE_CHIPMUNK)
|
||||
message(FATAL_ERROR "Must choose a physics library.")
|
||||
endif(USE_CHIPMUNK)
|
||||
|
||||
# architecture
|
||||
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
|
||||
|
@ -58,6 +89,7 @@ link_directories(
|
|||
${CMAKE_SOURCE_DIR}/external/linux-specific/fmod/prebuilt/${ARCH_DIR}
|
||||
)
|
||||
|
||||
|
||||
# kazmath
|
||||
add_subdirectory(cocos/math/kazmath)
|
||||
|
||||
|
@ -73,8 +105,6 @@ add_subdirectory(external/unzip)
|
|||
# tinyxml2 library
|
||||
add_subdirectory(external/tinyxml2)
|
||||
|
||||
add_subdirectory(external/json)
|
||||
|
||||
# audio
|
||||
add_subdirectory(cocos/audio)
|
||||
|
||||
|
@ -84,22 +114,51 @@ add_subdirectory(cocos/base)
|
|||
# cocos 2d library
|
||||
add_subdirectory(cocos/2d)
|
||||
|
||||
if(BUILD_GUI)
|
||||
# gui
|
||||
add_subdirectory(cocos/gui)
|
||||
endif(BUILD_GUI)
|
||||
|
||||
if(BUILD_NETWORK)
|
||||
# network
|
||||
add_subdirectory(cocos/network)
|
||||
endif(BUILD_NETWORK)
|
||||
|
||||
if(BUILD_EXTENSIONS)
|
||||
# extensions
|
||||
add_subdirectory(extensions)
|
||||
endif(BUILD_EXTENSIONS)
|
||||
|
||||
## Editor Support
|
||||
|
||||
if(BUILD_EDITOR_SPINE)
|
||||
# spine
|
||||
add_subdirectory(cocos/editor-support/spine)
|
||||
endif(BUILD_EDITOR_SPINE)
|
||||
|
||||
if(BUILD_EDITOR_COCOSBUILDER)
|
||||
# cocosbuilder
|
||||
add_subdirectory(cocos/editor-support/cocosbuilder)
|
||||
endif(BUILD_EDITOR_COCOSBUILDER)
|
||||
|
||||
if(BUILD_EDITOR_COCOSTUDIO)
|
||||
# cocostudio
|
||||
add_subdirectory(cocos/editor-support/cocostudio)
|
||||
# jsoncpp library, cocostuido depends on jsoncpp
|
||||
add_subdirectory(external/json)
|
||||
endif(BUILD_EDITOR_COCOSTUDIO)
|
||||
|
||||
|
||||
if(BUILD_LIBS_LUA)
|
||||
## Scripting
|
||||
# lua
|
||||
add_subdirectory(external/lua/lua)
|
||||
|
||||
# tolua
|
||||
add_subdirectory(external/lua/tolua)
|
||||
|
||||
# luabinding
|
||||
add_subdirectory(cocos/scripting)
|
||||
endif(BUILD_LIBS_LUA)
|
||||
|
||||
# build samples
|
||||
add_subdirectory(samples)
|
||||
|
||||
|
|
11
README.md
11
README.md
|
@ -29,8 +29,8 @@ How to start a new game
|
|||
|
||||
Example:
|
||||
|
||||
$ cd cocos2d-x/tools/project-creator
|
||||
$ ./create-multi-platform-projects.py -p mygame -k com.your_company.mygame -l cpp
|
||||
$ cd cocos2d-x/tools/project-creator
|
||||
$ ./create-multi-platform-projects.py -p mygame -k com.your_company.mygame -l cpp
|
||||
$ cd ../../projects/mygame
|
||||
|
||||
|
||||
|
@ -70,7 +70,7 @@ Build Requirements
|
|||
------------------
|
||||
|
||||
* Mac OS X 10.7+, Xcode 4.6+
|
||||
* or Ubuntu 13.04+
|
||||
* or Ubuntu 12.10+, CMake 2.6+
|
||||
* or Windows 7+, VS 2012+
|
||||
|
||||
|
||||
|
@ -97,8 +97,9 @@ $ open samples.xcodeproj
|
|||
* For Linux
|
||||
|
||||
```
|
||||
$ cd cocos2d-x/build
|
||||
$ ./make-all-linux-projects.sh
|
||||
$ cd cocos2d-x
|
||||
$ cmake CMakeLists.txt
|
||||
$ make
|
||||
```
|
||||
|
||||
* For Windows
|
||||
|
|
|
@ -1,53 +1,13 @@
|
|||
# This file was copied from GamePlay
|
||||
# Copies files for the given game into the target res directory
|
||||
# GAME_NAME name of the game
|
||||
# REL_DIR to which directory these files are relative
|
||||
# SRC_FILES which files from the REL_DIR to copy (GLOB)
|
||||
macro(COPY_RES_FILES GAME_NAME GAME_RES_TARGET REL_DIR SRC_FILES)
|
||||
file( GLOB_RECURSE RES_FILES RELATIVE ${REL_DIR} ${SRC_FILES} )
|
||||
macro(pre_build TARGET_NAME)
|
||||
add_custom_target( ${TARGET_NAME}_PRE_BUILD ALL )
|
||||
|
||||
set(ALL_FILES)
|
||||
foreach(SRC_FILE ${RES_FILES})
|
||||
IF(NOT (SRC_FILE MATCHES "(^\\.\\.)"))
|
||||
add_custom_command(
|
||||
OUTPUT "${APP_BIN_DIR}/${SRC_FILE}"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${REL_DIR}/${SRC_FILE}"
|
||||
"${APP_BIN_DIR}/Resources/${SRC_FILE}"
|
||||
COMMENT "Copy ${SRC_FILE}"
|
||||
)
|
||||
list(APPEND ALL_FILES "${APP_BIN_DIR}/${SRC_FILE}" )
|
||||
ENDIF(NOT (SRC_FILE MATCHES "(^\\.\\.)"))
|
||||
endforeach()
|
||||
# create target for copying these files
|
||||
add_custom_target( ${GAME_RES_TARGET} DEPENDS ${ALL_FILES} )
|
||||
endmacro()
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}_PRE_BUILD
|
||||
${ARGN}
|
||||
PRE_BUILD
|
||||
COMMENT "${TARGET_NAME}_PRE_BUILD ..."
|
||||
)
|
||||
|
||||
# convenience to call above with current directory and everything in "res"
|
||||
macro(COPY_RES GAME_NAME)
|
||||
# a target for all addition asserts (will be done in default compile, but if you target the executable
|
||||
# it won't be done -- good for testing)
|
||||
add_custom_target( ${GAME_NAME}_ASSETS ALL )
|
||||
|
||||
# copy entire "res" directory and "game.config" if there is one
|
||||
set(CRG_PATTERN "*")
|
||||
COPY_RES_FILES( ${GAME_NAME} ${GAME_NAME}_CORE_RES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Resources
|
||||
"${CRG_PATTERN}"
|
||||
)
|
||||
add_dependencies( ${GAME_NAME}_ASSETS ${GAME_NAME}_CORE_RES )
|
||||
endmacro()
|
||||
|
||||
# Copies resources from an additional directory
|
||||
# GAME_NAME name of the game
|
||||
# REL_DIR from which directory
|
||||
# ARGN which patterns to copy (should include res/ in name if to be placed in the res/ output)
|
||||
macro(COPY_RES_EXTRA GAME_NAME EXTRA_RES REL_DIR)
|
||||
# convert src's to full paths (based on rel_dir)
|
||||
set(SRC_FILES)
|
||||
foreach(SRC_FILE ${ARGN} )
|
||||
list(APPEND SRC_FILES "${REL_DIR}/${SRC_FILE}")
|
||||
endforeach()
|
||||
COPY_RES_FILES( ${GAME_NAME} ${GAME_NAME}_${EXTRA_RES} ${REL_DIR} "${SRC_FILES}" )
|
||||
add_dependencies( ${GAME_NAME}_ASSETS ${GAME_NAME}_${EXTRA_RES} )
|
||||
add_custom_target( ${TARGET_NAME}_CORE_PRE_BUILD )
|
||||
add_dependencies( ${TARGET_NAME}_PRE_BUILD ${TARGET_NAME}_CORE_PRE_BUILD )
|
||||
endmacro()
|
||||
|
|
|
@ -1 +1 @@
|
|||
695569fbf5580abb74dbc9b9d9fc7ad8d21db805
|
||||
30ca6c02884f9bc20405b3e657b444c0153bead7
|
|
@ -1 +1 @@
|
|||
13f41d81e48285159fafa45159fdd1c081b4bb06
|
||||
3ff18018375c71f683a484652678740cc6395eaf
|
|
@ -71,22 +71,20 @@ AnimationCache::~AnimationCache()
|
|||
CC_SAFE_RELEASE(_animations);
|
||||
}
|
||||
|
||||
void AnimationCache::addAnimation(Animation *animation, const char * name)
|
||||
void AnimationCache::addAnimation(Animation *animation, const std::string& name)
|
||||
{
|
||||
_animations->setObject(animation, name);
|
||||
}
|
||||
|
||||
void AnimationCache::removeAnimation(const char* name)
|
||||
void AnimationCache::removeAnimation(const std::string& name)
|
||||
{
|
||||
if (! name)
|
||||
{
|
||||
if (name.size()==0)
|
||||
return;
|
||||
}
|
||||
|
||||
_animations->removeObjectForKey(name);
|
||||
}
|
||||
|
||||
Animation* AnimationCache::getAnimation(const char* name)
|
||||
Animation* AnimationCache::getAnimation(const std::string& name)
|
||||
{
|
||||
return (Animation*)_animations->objectForKey(name);
|
||||
}
|
||||
|
@ -95,17 +93,17 @@ void AnimationCache::parseVersion1(Dictionary* animations)
|
|||
{
|
||||
SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();
|
||||
|
||||
DictElement* pElement = NULL;
|
||||
CCDICT_FOREACH(animations, pElement)
|
||||
DictElement* element = NULL;
|
||||
CCDICT_FOREACH(animations, element)
|
||||
{
|
||||
Dictionary* animationDict = static_cast<Dictionary*>(pElement->getObject());
|
||||
Dictionary* animationDict = static_cast<Dictionary*>(element->getObject());
|
||||
Array* frameNames = static_cast<Array*>(animationDict->objectForKey("frames"));
|
||||
float delay = animationDict->valueForKey("delay")->floatValue();
|
||||
Animation* animation = NULL;
|
||||
|
||||
if ( frameNames == NULL )
|
||||
{
|
||||
CCLOG("cocos2d: AnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", pElement->getStrKey());
|
||||
CCLOG("cocos2d: AnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", element->getStrKey());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -115,11 +113,11 @@ void AnimationCache::parseVersion1(Dictionary* animations)
|
|||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH(frameNames, pObj)
|
||||
{
|
||||
const char* frameName = static_cast<String*>(pObj)->getCString();
|
||||
const std::string& frameName = static_cast<String*>(pObj)->getCString();
|
||||
SpriteFrame* spriteFrame = frameCache->getSpriteFrameByName(frameName);
|
||||
|
||||
if ( ! spriteFrame ) {
|
||||
CCLOG("cocos2d: AnimationCache: Animation '%s' refers to frame '%s' which is not currently in the SpriteFrameCache. This frame will not be added to the animation.", pElement->getStrKey(), frameName);
|
||||
CCLOG("cocos2d: AnimationCache: Animation '%s' refers to frame '%s' which is not currently in the SpriteFrameCache. This frame will not be added to the animation.", element->getStrKey(), frameName.c_str());
|
||||
|
||||
continue;
|
||||
}
|
||||
|
@ -131,15 +129,15 @@ void AnimationCache::parseVersion1(Dictionary* animations)
|
|||
}
|
||||
|
||||
if ( frames->count() == 0 ) {
|
||||
CCLOG("cocos2d: AnimationCache: None of the frames for animation '%s' were found in the SpriteFrameCache. Animation is not being added to the Animation Cache.", pElement->getStrKey());
|
||||
CCLOG("cocos2d: AnimationCache: None of the frames for animation '%s' were found in the SpriteFrameCache. Animation is not being added to the Animation Cache.", element->getStrKey());
|
||||
continue;
|
||||
} else if ( frames->count() != frameNames->count() ) {
|
||||
CCLOG("cocos2d: AnimationCache: An animation in your dictionary refers to a frame which is not in the SpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.", pElement->getStrKey());
|
||||
CCLOG("cocos2d: AnimationCache: An animation in your dictionary refers to a frame which is not in the SpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.", element->getStrKey());
|
||||
}
|
||||
|
||||
animation = Animation::create(frames, delay, 1);
|
||||
|
||||
AnimationCache::getInstance()->addAnimation(animation, pElement->getStrKey());
|
||||
AnimationCache::getInstance()->addAnimation(animation, element->getStrKey());
|
||||
frames->release();
|
||||
}
|
||||
}
|
||||
|
@ -148,11 +146,11 @@ void AnimationCache::parseVersion2(Dictionary* animations)
|
|||
{
|
||||
SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();
|
||||
|
||||
DictElement* pElement = NULL;
|
||||
CCDICT_FOREACH(animations, pElement)
|
||||
DictElement* element = NULL;
|
||||
CCDICT_FOREACH(animations, element)
|
||||
{
|
||||
const char* name = pElement->getStrKey();
|
||||
Dictionary* animationDict = static_cast<Dictionary*>(pElement->getObject());
|
||||
const char* name = element->getStrKey();
|
||||
Dictionary* animationDict = static_cast<Dictionary*>(element->getObject());
|
||||
|
||||
const String* loops = animationDict->valueForKey("loops");
|
||||
bool restoreOriginalFrame = animationDict->valueForKey("restoreOriginalFrame")->boolValue();
|
||||
|
@ -241,9 +239,9 @@ void AnimationCache::addAnimationsWithDictionary(Dictionary* dictionary)
|
|||
}
|
||||
|
||||
/** Read an NSDictionary from a plist file and parse it automatically for animations */
|
||||
void AnimationCache::addAnimationsWithFile(const char* plist)
|
||||
void AnimationCache::addAnimationsWithFile(const std::string& plist)
|
||||
{
|
||||
CCASSERT( plist, "Invalid texture file name");
|
||||
CCASSERT( plist.size()>0, "Invalid texture file name");
|
||||
|
||||
std::string path = FileUtils::getInstance()->fullPathForFilename(plist);
|
||||
Dictionary* dict = Dictionary::createWithContentsOfFile(path.c_str());
|
||||
|
|
|
@ -76,29 +76,29 @@ public:
|
|||
|
||||
/** Adds a Animation with a name.
|
||||
*/
|
||||
void addAnimation(Animation *animation, const char * name);
|
||||
void addAnimation(Animation *animation, const std::string& name);
|
||||
|
||||
/** Deletes a Animation from the cache.
|
||||
|
||||
*/
|
||||
void removeAnimation(const char* name);
|
||||
void removeAnimation(const std::string& name);
|
||||
/** @deprecated. Use removeAnimation() instead
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE void removeAnimationByName(const char* name){ removeAnimation(name);}
|
||||
CC_DEPRECATED_ATTRIBUTE void removeAnimationByName(const std::string& name){ removeAnimation(name);}
|
||||
|
||||
/** Returns a Animation that was previously added.
|
||||
If the name is not found it will return nil.
|
||||
You should retain the returned copy if you are going to use it.
|
||||
*/
|
||||
Animation* getAnimation(const char* name);
|
||||
Animation* getAnimation(const std::string& name);
|
||||
/**
|
||||
@deprecated. Use getAnimation() instead
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE Animation* animationByName(const char* name){ return getAnimation(name); }
|
||||
CC_DEPRECATED_ATTRIBUTE Animation* animationByName(const std::string& name){ return getAnimation(name); }
|
||||
|
||||
/** Adds an animation from an NSDictionary
|
||||
Make sure that the frames were previously loaded in the SpriteFrameCache.
|
||||
|
@ -112,7 +112,7 @@ public:
|
|||
* @js addAnimations
|
||||
* @lua addAnimations
|
||||
*/
|
||||
void addAnimationsWithFile(const char* plist);
|
||||
void addAnimationsWithFile(const std::string& plist);
|
||||
|
||||
private:
|
||||
void parseVersion1(Dictionary* animations);
|
||||
|
|
|
@ -61,8 +61,7 @@ AtlasNode::~AtlasNode()
|
|||
CC_SAFE_RELEASE(_textureAtlas);
|
||||
}
|
||||
|
||||
AtlasNode * AtlasNode::create(const char *tile, unsigned int tileWidth, unsigned int tileHeight,
|
||||
unsigned int itemsToRender)
|
||||
AtlasNode * AtlasNode::create(const std::string& tile, long tileWidth, long tileHeight, long itemsToRender)
|
||||
{
|
||||
AtlasNode * pRet = new AtlasNode();
|
||||
if (pRet->initWithTileFile(tile, tileWidth, tileHeight, itemsToRender))
|
||||
|
@ -74,15 +73,14 @@ AtlasNode * AtlasNode::create(const char *tile, unsigned int tileWidth, unsigned
|
|||
return NULL;
|
||||
}
|
||||
|
||||
bool AtlasNode::initWithTileFile(const char *tile, unsigned int tileWidth, unsigned int tileHeight, unsigned int itemsToRender)
|
||||
bool AtlasNode::initWithTileFile(const std::string& tile, long tileWidth, long tileHeight, long itemsToRender)
|
||||
{
|
||||
CCASSERT(tile != NULL, "title should not be null");
|
||||
CCASSERT(tile.size() > 0, "file size should not be empty");
|
||||
Texture2D *texture = TextureCache::getInstance()->addImage(tile);
|
||||
return initWithTexture(texture, tileWidth, tileHeight, itemsToRender);
|
||||
}
|
||||
|
||||
bool AtlasNode::initWithTexture(Texture2D* texture, unsigned int tileWidth, unsigned int tileHeight,
|
||||
unsigned int itemsToRender)
|
||||
bool AtlasNode::initWithTexture(Texture2D* texture, long tileWidth, long tileHeight, long itemsToRender)
|
||||
{
|
||||
_itemWidth = tileWidth;
|
||||
_itemHeight = tileHeight;
|
||||
|
|
|
@ -52,8 +52,7 @@ class CC_DLL AtlasNode : public NodeRGBA, public TextureProtocol
|
|||
{
|
||||
public:
|
||||
/** creates a AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
||||
static AtlasNode * create(const char* tile,unsigned int tileWidth, unsigned int tileHeight,
|
||||
unsigned int itemsToRender);
|
||||
static AtlasNode * create(const std::string& filename, long tileWidth, long tileHeight, long itemsToRender);
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
|
@ -65,10 +64,10 @@ public:
|
|||
virtual ~AtlasNode();
|
||||
|
||||
/** initializes an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
|
||||
bool initWithTileFile(const char* tile, unsigned int tileWidth, unsigned int tileHeight, unsigned int itemsToRender);
|
||||
bool initWithTileFile(const std::string& tile, long tileWidth, long tileHeight, long itemsToRender);
|
||||
|
||||
/** initializes an AtlasNode with a texture the width and height of each item measured in points and the quantity of items to render*/
|
||||
bool initWithTexture(Texture2D* texture, unsigned int tileWidth, unsigned int tileHeight, unsigned int itemsToRender);
|
||||
bool initWithTexture(Texture2D* texture, long tileWidth, long tileHeight, long itemsToRender);
|
||||
|
||||
/** updates the Atlas (indexed vertex array).
|
||||
* Shall be overridden in subclasses
|
||||
|
@ -115,14 +114,14 @@ private :
|
|||
|
||||
protected:
|
||||
//! chars per row
|
||||
unsigned int _itemsPerRow;
|
||||
long _itemsPerRow;
|
||||
//! chars per column
|
||||
unsigned int _itemsPerColumn;
|
||||
long _itemsPerColumn;
|
||||
|
||||
//! width of each char
|
||||
unsigned int _itemWidth;
|
||||
long _itemWidth;
|
||||
//! height of each char
|
||||
unsigned int _itemHeight;
|
||||
long _itemHeight;
|
||||
|
||||
Color3B _colorUnmodified;
|
||||
|
||||
|
@ -132,7 +131,7 @@ protected:
|
|||
BlendFunc _blendFunc;
|
||||
|
||||
// quads to draw
|
||||
unsigned int _quadsToDraw;
|
||||
long _quadsToDraw;
|
||||
// color uniform
|
||||
GLint _uniformColor;
|
||||
// This varible is only used for LabelAtlas FPS display. So plz don't modify its value.
|
||||
|
|
|
@ -831,7 +831,7 @@ void Director::calculateMPF()
|
|||
}
|
||||
|
||||
// returns the FPS image data pointer and len
|
||||
void Director::getFPSImageData(unsigned char** datapointer, unsigned int* length)
|
||||
void Director::getFPSImageData(unsigned char** datapointer, long* length)
|
||||
{
|
||||
// XXX fixed me if it should be used
|
||||
*datapointer = cc_fps_images_png;
|
||||
|
@ -855,7 +855,7 @@ void Director::createStatsLabel()
|
|||
Texture2D::PixelFormat currentFormat = Texture2D::getDefaultAlphaPixelFormat();
|
||||
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
|
||||
unsigned char *data = nullptr;
|
||||
unsigned int dataLength = 0;
|
||||
long dataLength = 0;
|
||||
getFPSImageData(&data, &dataLength);
|
||||
|
||||
Image* image = new Image();
|
||||
|
|
|
@ -376,7 +376,7 @@ protected:
|
|||
void showStats();
|
||||
void createStatsLabel();
|
||||
void calculateMPF();
|
||||
void getFPSImageData(unsigned char** datapointer, unsigned int* length);
|
||||
void getFPSImageData(unsigned char** datapointer, long* length);
|
||||
|
||||
/** calculates delta time since last time it was called */
|
||||
void calculateDeltaTime();
|
||||
|
|
|
@ -140,7 +140,7 @@ DrawNode* DrawNode::create()
|
|||
return pRet;
|
||||
}
|
||||
|
||||
void DrawNode::ensureCapacity(int count)
|
||||
void DrawNode::ensureCapacity(long count)
|
||||
{
|
||||
CCASSERT(count>=0, "capacity must be >= 0");
|
||||
|
||||
|
@ -331,8 +331,10 @@ void DrawNode::drawSegment(const Point &from, const Point &to, float radius, con
|
|||
_dirty = true;
|
||||
}
|
||||
|
||||
void DrawNode::drawPolygon(Point *verts, unsigned int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor)
|
||||
void DrawNode::drawPolygon(Point *verts, long count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor)
|
||||
{
|
||||
CCASSERT(count >= 0, "invalid count value");
|
||||
|
||||
struct ExtrudeVerts {Vertex2F offset, n;};
|
||||
struct ExtrudeVerts* extrude = (struct ExtrudeVerts*)malloc(sizeof(struct ExtrudeVerts)*count);
|
||||
memset(extrude, 0, sizeof(struct ExtrudeVerts)*count);
|
||||
|
@ -376,9 +378,9 @@ void DrawNode::drawPolygon(Point *verts, unsigned int count, const Color4F &fill
|
|||
*cursor++ = tmp;
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < count; i++)
|
||||
for(long i = 0; i < count; i++)
|
||||
{
|
||||
int j = (i+1)%count;
|
||||
long j = (i+1)%count;
|
||||
Vertex2F v0 = __v2f(verts[i]);
|
||||
Vertex2F v1 = __v2f(verts[j]);
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ public:
|
|||
* In lua:local drawPolygon(local pointTable,local tableCount,local fillColor,local width,local borderColor)
|
||||
* @endcode
|
||||
*/
|
||||
void drawPolygon(Point *verts, unsigned int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor);
|
||||
void drawPolygon(Point *verts, long count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor);
|
||||
|
||||
/** Clear the geometry in the node's buffer. */
|
||||
void clear();
|
||||
|
@ -99,13 +99,13 @@ public:
|
|||
virtual void draw() override;
|
||||
|
||||
protected:
|
||||
void ensureCapacity(int count);
|
||||
void ensureCapacity(long count);
|
||||
void render();
|
||||
|
||||
GLuint _vao;
|
||||
GLuint _vbo;
|
||||
|
||||
int _bufferCapacity;
|
||||
long _bufferCapacity;
|
||||
GLsizei _bufferCount;
|
||||
V2F_C4B_T2F *_buffer;
|
||||
|
||||
|
|
|
@ -75,10 +75,9 @@ EventListenerTouchOneByOne* EventListenerTouchOneByOne::create()
|
|||
|
||||
bool EventListenerTouchOneByOne::checkAvailable()
|
||||
{
|
||||
if (onTouchBegan == nullptr && onTouchMoved == nullptr
|
||||
&& onTouchEnded == nullptr && onTouchCancelled == nullptr)
|
||||
if (onTouchBegan == nullptr)
|
||||
{
|
||||
CCASSERT(false, "Invalid TouchEventListener.");
|
||||
CCASSERT(false, "Invalid EventListenerTouchOneByOne!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -150,7 +149,7 @@ bool EventListenerTouchAllAtOnce::checkAvailable()
|
|||
if (onTouchesBegan == nullptr && onTouchesMoved == nullptr
|
||||
&& onTouchesEnded == nullptr && onTouchesCancelled == nullptr)
|
||||
{
|
||||
CCASSERT(false, "Invalid TouchEventListener.");
|
||||
CCASSERT(false, "Invalid EventListenerTouchAllAtOnce!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,12 +99,12 @@ const char * Font::getCurrentGlyphCollection() const
|
|||
}
|
||||
}
|
||||
|
||||
Font* Font::createWithTTF(const char* fntName, int fontSize, GlyphCollection glyphs, const char *customGlyphs)
|
||||
Font* Font::createWithTTF(const std::string& fntName, int fontSize, GlyphCollection glyphs, const char *customGlyphs)
|
||||
{
|
||||
return FontFreeType::create(fntName, fontSize, glyphs, customGlyphs);
|
||||
}
|
||||
|
||||
Font* Font::createWithFNT(const char* fntFilePath)
|
||||
Font* Font::createWithFNT(const std::string& fntFilePath)
|
||||
{
|
||||
return FontFNT::create(fntFilePath);
|
||||
}
|
||||
|
|
|
@ -42,21 +42,21 @@ class CC_DLL Font : public Object
|
|||
public:
|
||||
|
||||
// create the font
|
||||
static Font* createWithTTF(const char* fntName, int fontSize, GlyphCollection glyphs, const char *customGlyphs);
|
||||
static Font* createWithFNT(const char* fntFilePath);
|
||||
static Font* createWithTTF(const std::string& fntName, int fontSize, GlyphCollection glyphs, const char *customGlyphs);
|
||||
static Font* createWithFNT(const std::string& fntFilePath);
|
||||
|
||||
virtual FontAtlas *createFontAtlas() = 0;
|
||||
|
||||
virtual Size * getAdvancesForTextUTF16(unsigned short *text, int &outNumLetters) const = 0;
|
||||
virtual const char * getCurrentGlyphCollection() const;
|
||||
virtual Size* getAdvancesForTextUTF16(unsigned short *text, int &outNumLetters) const = 0;
|
||||
virtual const char* getCurrentGlyphCollection() const;
|
||||
|
||||
virtual int getLetterPadding() const { return 0; }
|
||||
virtual unsigned char * getGlyphBitmap(unsigned short theChar, int &outWidth, int &outHeight) const { return 0; }
|
||||
virtual GlyphDef * getGlyphDefintionsForText(const char *text, int &outNumGlyphs, bool UTF16text = false) const { return 0; }
|
||||
virtual int getFontMaxHeight() const { return 0; }
|
||||
virtual Rect getRectForChar(unsigned short theChar) const;
|
||||
virtual int getLetterPadding() const { return 0; }
|
||||
virtual unsigned char * getGlyphBitmap(unsigned short theChar, int &outWidth, int &outHeight) const { return 0; }
|
||||
virtual GlyphDef* getGlyphDefintionsForText(const char *text, int &outNumGlyphs, bool UTF16text = false) const { return 0; }
|
||||
virtual int getFontMaxHeight() const { return 0; }
|
||||
virtual Rect getRectForChar(unsigned short theChar) const;
|
||||
|
||||
virtual int getUTF16TextLenght(unsigned short int *text) const;
|
||||
virtual int getUTF16TextLenght(unsigned short int *text) const;
|
||||
virtual unsigned short int * getUTF16Text(const char *text, int &outNumLetters) const;
|
||||
virtual unsigned short int * trimUTF16Text(unsigned short int *text, int newBegin, int newEnd) const;
|
||||
|
||||
|
@ -71,8 +71,7 @@ protected:
|
|||
void setCurrentGlyphCollection(GlyphCollection glyphs, const char *customGlyphs = 0);
|
||||
const char * getGlyphCollection(GlyphCollection glyphs) const;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
GlyphCollection _usedGlyphs;
|
||||
char * _customGlyphs;
|
||||
static const char * _glyphASCII;
|
||||
|
|
|
@ -1,10 +1,26 @@
|
|||
//
|
||||
// CCFontAtlas.cpp
|
||||
// cocos2d_libs
|
||||
//
|
||||
// Created by Carlo Morgantini on 7/18/13.
|
||||
//
|
||||
//
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013 Zynga 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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "CCFontAtlas.h"
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#ifndef _CCFontAtlas_h_
|
||||
#define _CCFontAtlas_h_
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -34,17 +34,17 @@ class Font;
|
|||
struct FontLetterDefinition
|
||||
{
|
||||
unsigned short letteCharUTF16;
|
||||
float U;
|
||||
float V;
|
||||
float width;
|
||||
float height;
|
||||
float offsetX;
|
||||
float offsetY;
|
||||
int textureID;
|
||||
float commonLineHeight;
|
||||
float anchorX;
|
||||
float anchorY;
|
||||
bool validDefinition;
|
||||
float U;
|
||||
float V;
|
||||
float width;
|
||||
float height;
|
||||
float offsetX;
|
||||
float offsetY;
|
||||
int textureID;
|
||||
float commonLineHeight;
|
||||
float anchorX;
|
||||
float anchorY;
|
||||
bool validDefinition;
|
||||
};
|
||||
|
||||
class CC_DLL FontAtlas : public Object
|
||||
|
@ -69,26 +69,26 @@ public:
|
|||
float getCommonLineHeight() const;
|
||||
void setCommonLineHeight(float newHeight);
|
||||
|
||||
Texture2D & getTexture(int slot);
|
||||
const Font * getFont() const;
|
||||
Texture2D& getTexture(int slot);
|
||||
const Font* getFont() const;
|
||||
|
||||
private:
|
||||
bool renderCharAt(unsigned short int charToRender, int posX, int posY, unsigned char *destMemory, int destSize);
|
||||
|
||||
void relaseTextures();
|
||||
std::map<int, Texture2D *> _atlasTextures;
|
||||
std::map<unsigned short, FontLetterDefinition> _fontLetterDefinitions;
|
||||
float _commonLineHeight;
|
||||
Font * _font;
|
||||
std::unordered_map<int, Texture2D*> _atlasTextures;
|
||||
std::unordered_map<unsigned short, FontLetterDefinition> _fontLetterDefinitions;
|
||||
float _commonLineHeight;
|
||||
Font * _font;
|
||||
|
||||
// Dynamic GlyphCollection related stuff
|
||||
int _currentPage;
|
||||
unsigned char *_currentPageData;
|
||||
int _currentPageDataSize;
|
||||
float _currentPageOrigX;
|
||||
float _currentPageOrigY;
|
||||
float _currentPageLineHeight;
|
||||
float _letterPadding;
|
||||
int _currentPage;
|
||||
unsigned char *_currentPageData;
|
||||
int _currentPageDataSize;
|
||||
float _currentPageOrigX;
|
||||
float _currentPageOrigY;
|
||||
float _currentPageLineHeight;
|
||||
float _letterPadding;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
std::map<std::string, FontAtlas *> FontAtlasCache::_atlasMap;
|
||||
std::unordered_map<std::string, FontAtlas *> FontAtlasCache::_atlasMap;
|
||||
|
||||
FontAtlas * FontAtlasCache::getFontAtlasTTF(const char *fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs)
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#define _CCFontAtlasCache_h_
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "CCFontAtlas.h"
|
||||
|
@ -41,12 +41,12 @@ public:
|
|||
static FontAtlas * getFontAtlasTTF(const char *fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs = 0);
|
||||
static FontAtlas * getFontAtlasFNT(const char *fontFileName);
|
||||
|
||||
static bool releaseFontAtlas(FontAtlas *atlas);
|
||||
static bool releaseFontAtlas(FontAtlas *atlas);
|
||||
|
||||
private:
|
||||
|
||||
static std::string generateFontName(const char *fontFileName, int size, GlyphCollection theGlyphs);
|
||||
static std::map<std::string, FontAtlas *> _atlasMap;
|
||||
static std::unordered_map<std::string, FontAtlas *> _atlasMap;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -1,10 +1,26 @@
|
|||
//
|
||||
// CCFontAtlasFactory.cpp
|
||||
// cocos2d_libs
|
||||
//
|
||||
// Created by Carlo Morgantini on 7/23/13.
|
||||
//
|
||||
//
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013 Zynga 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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCFontAtlasFactory.h"
|
||||
#include "CCFontFNT.h"
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
const int FontDefinitionTTF::DEFAUL_ATALS_TEXTURE_SIZE = 1024;
|
||||
const int FontDefinitionTTF::DEFAUL_ATLAS_TEXTURE_SIZE = 1024;
|
||||
|
||||
FontDefinitionTTF::FontDefinitionTTF():_textImages(0), _commonLineHeight(0)
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ FontDefinitionTTF::FontDefinitionTTF():_textImages(0), _commonLineHeight(0)
|
|||
FontDefinitionTTF* FontDefinitionTTF::create(Font *font, int textureSize)
|
||||
{
|
||||
if (textureSize == 0)
|
||||
textureSize = DEFAUL_ATALS_TEXTURE_SIZE;
|
||||
textureSize = DEFAUL_ATLAS_TEXTURE_SIZE;
|
||||
|
||||
FontDefinitionTTF *ret = new FontDefinitionTTF;
|
||||
|
||||
|
@ -82,8 +82,8 @@ bool FontDefinitionTTF::prepareLetterDefinitions(TextFontPagesDef *pageDefs)
|
|||
// loops all the lines in this page
|
||||
for (int cLines = 0; cLines<pages->getPageAt(cPages)->getNumLines(); ++cLines)
|
||||
{
|
||||
float posXUV = 0.0;
|
||||
float posYUV = pages->getPageAt(cPages)->getLineAt(cLines)->getY();
|
||||
float posXUV = 0.0;
|
||||
float posYUV = pages->getPageAt(cPages)->getLineAt(cLines)->getY();
|
||||
|
||||
int charsCounter = 0;
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#ifndef _FontDefinition_h_
|
||||
#define _FontDefinition_h_
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "CCTextImage.h"
|
||||
#include "CCFont.h"
|
||||
#include "CCFontAtlas.h"
|
||||
|
@ -55,11 +57,11 @@ private:
|
|||
bool prepareLetterDefinitions(TextFontPagesDef *pageDefs);
|
||||
void addLetterDefinition(const FontLetterDefinition &defToAdd);
|
||||
|
||||
TextImage * _textImages;
|
||||
std::map<unsigned short, FontLetterDefinition> _fontLettersDefinitionUTF16;
|
||||
float _commonLineHeight;
|
||||
static const int DEFAUL_ATALS_TEXTURE_SIZE;
|
||||
|
||||
TextImage * _textImages;
|
||||
std::unordered_map<unsigned short, FontLetterDefinition> _fontLettersDefinitionUTF16;
|
||||
float _commonLineHeight;
|
||||
|
||||
static const int DEFAUL_ATLAS_TEXTURE_SIZE;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -1,17 +1,33 @@
|
|||
//
|
||||
// CCFontFNT.cpp
|
||||
// cocos2d_libs
|
||||
//
|
||||
// Created by Carlo Morgantini on 7/24/13.
|
||||
//
|
||||
//
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013 Zynga 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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCFontFNT.h"
|
||||
#include "CCFontAtlas.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
FontFNT * FontFNT::create(const char* fntFilePath)
|
||||
FontFNT * FontFNT::create(const std::string& fntFilePath)
|
||||
{
|
||||
CCBMFontConfiguration *newConf = FNTConfigLoadFile(fntFilePath);
|
||||
if (!newConf)
|
||||
|
|
|
@ -35,7 +35,7 @@ class FontFNT : public Font
|
|||
|
||||
public:
|
||||
|
||||
static FontFNT * create(const char* fntFilePath);
|
||||
static FontFNT * create(const std::string& fntFilePath);
|
||||
|
||||
virtual Size* getAdvancesForTextUTF16(unsigned short *text, int &outNumLetters) const override;
|
||||
virtual Rect getRectForChar(unsigned short theChar) const override;
|
||||
|
@ -43,7 +43,8 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
FontFNT(CCBMFontConfiguration *theContfig) : _configuration(theContfig) {}
|
||||
FontFNT(CCBMFontConfiguration *theContfig) :
|
||||
_configuration(theContfig) {}
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -56,7 +57,7 @@ private:
|
|||
int getHorizontalKerningForChars(unsigned short firstChar, unsigned short secondChar) const;
|
||||
Rect getRectForCharInternal(unsigned short theChar) const;
|
||||
|
||||
CCBMFontConfiguration * _configuration;
|
||||
CCBMFontConfiguration * _configuration;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -99,8 +99,8 @@ bool FontFreeType::createFontObject(const std::string &fontName, int fontSize)
|
|||
{
|
||||
FT_Face face;
|
||||
|
||||
int len = 0;
|
||||
_ttfData = FileUtils::getInstance()->getFileData(fontName.c_str(), "rb", (unsigned long *)(&len));
|
||||
long len = 0;
|
||||
_ttfData = FileUtils::getInstance()->getFileData(fontName.c_str(), "rb", &len);
|
||||
if (!_ttfData)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public:
|
|||
protected:
|
||||
GLuint _FBO;
|
||||
GLint _oldFBO;
|
||||
GLfloat _oldClearColor[4];
|
||||
GLfloat _oldClearColor[4];
|
||||
};
|
||||
|
||||
// end of effects group
|
||||
|
|
|
@ -119,7 +119,7 @@ bool GridBase::initWithSize(const Size& gridSize)
|
|||
// we only use rgba8888
|
||||
Texture2D::PixelFormat format = Texture2D::PixelFormat::RGBA8888;
|
||||
|
||||
int dataLen = (int)(POTWide * POTHigh * 4);
|
||||
long dataLen = POTWide * POTHigh * 4;
|
||||
void *data = calloc(dataLen, 1);
|
||||
if (! data)
|
||||
{
|
||||
|
|
|
@ -66,23 +66,23 @@ public:
|
|||
bool initWithSize(const Size& gridSize);
|
||||
|
||||
/** whether or not the grid is active */
|
||||
inline bool isActive(void) { return _active; }
|
||||
inline bool isActive(void) const { return _active; }
|
||||
void setActive(bool bActive);
|
||||
|
||||
/** number of times that the grid will be reused */
|
||||
inline int getReuseGrid(void) { return _reuseGrid; }
|
||||
inline int getReuseGrid(void) const { return _reuseGrid; }
|
||||
inline void setReuseGrid(int nReuseGrid) { _reuseGrid = nReuseGrid; }
|
||||
|
||||
/** size of the grid */
|
||||
inline const Size& getGridSize(void) { return _gridSize; }
|
||||
inline const Size& getGridSize(void) const { return _gridSize; }
|
||||
inline void setGridSize(const Size& gridSize) { _gridSize = gridSize; }
|
||||
|
||||
/** pixels between the grids */
|
||||
inline const Point& getStep(void) { return _step; }
|
||||
inline const Point& getStep(void) const { return _step; }
|
||||
inline void setStep(const Point& step) { _step = step; }
|
||||
|
||||
/** is texture flipped */
|
||||
inline bool isTextureFlipped(void) { return _isTextureFlipped; }
|
||||
inline bool isTextureFlipped(void) const { return _isTextureFlipped; }
|
||||
void setTextureFlipped(bool bFlipped);
|
||||
|
||||
void beforeDraw(void);
|
||||
|
@ -95,7 +95,7 @@ public:
|
|||
|
||||
protected:
|
||||
bool _active;
|
||||
int _reuseGrid;
|
||||
long _reuseGrid;
|
||||
Size _gridSize;
|
||||
Texture2D *_texture;
|
||||
Point _step;
|
||||
|
|
|
@ -29,9 +29,9 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Label* Label::createWithTTF( const char* label, const char* fontFilePath, int fontSize, int lineSize, TextHAlignment alignment, GlyphCollection glyphs, const char *customGlyphs )
|
||||
Label* Label::createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize, TextHAlignment alignment, GlyphCollection glyphs, const char *customGlyphs )
|
||||
{
|
||||
FontAtlas *tmpAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath, fontSize, glyphs, customGlyphs);
|
||||
FontAtlas *tmpAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath.c_str(), fontSize, glyphs, customGlyphs);
|
||||
|
||||
if (!tmpAtlas)
|
||||
return nullptr;
|
||||
|
@ -48,10 +48,10 @@ Label* Label::createWithTTF( const char* label, const char* fontFilePath, int fo
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Label* Label::createWithBMFont( const char* label, const char* bmfontFilePath, TextHAlignment alignment, int lineSize)
|
||||
Label* Label::createWithBMFont(const std::string& label, const std::string& bmfontFilePath, TextHAlignment alignment, int lineSize)
|
||||
{
|
||||
|
||||
FontAtlas *tmpAtlas = FontAtlasCache::getFontAtlasFNT(bmfontFilePath);
|
||||
FontAtlas *tmpAtlas = FontAtlasCache::getFontAtlasFNT(bmfontFilePath.c_str());
|
||||
|
||||
if (!tmpAtlas)
|
||||
return 0;
|
||||
|
@ -135,12 +135,12 @@ bool Label::init()
|
|||
return true;
|
||||
}
|
||||
|
||||
void Label::setString(const char *stringToRender)
|
||||
void Label::setString(const std::string &stringToRender)
|
||||
{
|
||||
setText(stringToRender, _width, TextHAlignment::CENTER, false);
|
||||
}
|
||||
|
||||
bool Label::setText(const char *stringToRender, float lineWidth, TextHAlignment alignment, bool lineBreakWithoutSpaces)
|
||||
bool Label::setText(const std::string& stringToRender, float lineWidth, TextHAlignment alignment, bool lineBreakWithoutSpaces)
|
||||
{
|
||||
if (!_fontAtlas)
|
||||
return false;
|
||||
|
@ -159,7 +159,7 @@ bool Label::setText(const char *stringToRender, float lineWidth, TextHAlignment
|
|||
return false;
|
||||
|
||||
// int numLetter = 0;
|
||||
unsigned short* utf16String = cc_utf8_to_utf16(stringToRender);
|
||||
unsigned short* utf16String = cc_utf8_to_utf16(stringToRender.c_str());
|
||||
if(!utf16String)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -51,13 +51,13 @@ class CC_DLL Label : public SpriteBatchNode, public LabelProtocol, public RGBAPr
|
|||
public:
|
||||
|
||||
// static create
|
||||
static Label* createWithTTF(const char* label, const char* fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0);
|
||||
static Label* createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0);
|
||||
|
||||
static Label* createWithBMFont(const char* label, const char* bmfontFilePath, TextHAlignment alignment = TextHAlignment::CENTER, int lineSize = 0);
|
||||
static Label* createWithBMFont(const std::string& label, const std::string& bmfontFilePath, TextHAlignment alignment = TextHAlignment::CENTER, int lineSize = 0);
|
||||
|
||||
bool setText(const char *stringToRender, float lineWidth, TextHAlignment alignment = TextHAlignment::LEFT, bool lineBreakWithoutSpaces = false);
|
||||
bool setText(const std::string& stringToRender, float lineWidth, TextHAlignment alignment = TextHAlignment::LEFT, bool lineBreakWithoutSpaces = false);
|
||||
|
||||
virtual void setString(const char *stringToRender) override;
|
||||
virtual void setString(const std::string &stringToRender) override;
|
||||
virtual void setAlignment(TextHAlignment alignment);
|
||||
virtual void setWidth(float width);
|
||||
virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
|
||||
|
@ -83,38 +83,38 @@ public:
|
|||
|
||||
// CCLabelTextFormat protocol implementation
|
||||
virtual std::vector<LetterInfo> *getLettersInfo() override { return &_lettersInfo; };
|
||||
virtual bool recordLetterInfo(const cocos2d::Point& point,unsigned short int theChar, int spriteIndex) override;
|
||||
virtual bool recordPlaceholderInfo(int spriteIndex) override;
|
||||
virtual float getLetterPosXLeft( int index ) const override;
|
||||
virtual float getLetterPosXRight( int index ) const override;
|
||||
virtual bool recordLetterInfo(const cocos2d::Point& point,unsigned short int theChar, int spriteIndex) override;
|
||||
virtual bool recordPlaceholderInfo(int spriteIndex) override;
|
||||
virtual float getLetterPosXLeft( int index ) const override;
|
||||
virtual float getLetterPosXRight( int index ) const override;
|
||||
|
||||
virtual Sprite * getLetter(int ID) override;
|
||||
virtual Sprite * getLetter(int ID) override;
|
||||
|
||||
// font related stuff
|
||||
virtual int getCommonLineHeight() const override;
|
||||
virtual int getKerningForCharsPair(unsigned short first, unsigned short second) const override;
|
||||
virtual int getXOffsetForChar(unsigned short c) const override;
|
||||
virtual int getYOffsetForChar(unsigned short c) const override;
|
||||
virtual int getAdvanceForChar(unsigned short c, int hintPositionInString) const override;
|
||||
virtual Rect getRectForChar(unsigned short c) const override;
|
||||
virtual int getCommonLineHeight() const override;
|
||||
virtual int getKerningForCharsPair(unsigned short first, unsigned short second) const override;
|
||||
virtual int getXOffsetForChar(unsigned short c) const override;
|
||||
virtual int getYOffsetForChar(unsigned short c) const override;
|
||||
virtual int getAdvanceForChar(unsigned short c, int hintPositionInString) const override;
|
||||
virtual Rect getRectForChar(unsigned short c) const override;
|
||||
|
||||
// string related stuff
|
||||
virtual int getStringNumLines() const override;
|
||||
virtual int getStringLenght() const override;
|
||||
virtual unsigned short getCharAtStringPosition(int position) const override;
|
||||
virtual unsigned short * getUTF8String() const override;
|
||||
virtual void assignNewUTF8String(unsigned short *newString) override;
|
||||
virtual TextHAlignment getTextAlignment() const override;
|
||||
virtual int getStringNumLines() const override;
|
||||
virtual int getStringLenght() const override;
|
||||
virtual unsigned short getCharAtStringPosition(int position) const override;
|
||||
virtual unsigned short * getUTF8String() const override;
|
||||
virtual void assignNewUTF8String(unsigned short *newString) override;
|
||||
virtual TextHAlignment getTextAlignment() const override;
|
||||
|
||||
// label related stuff
|
||||
virtual float getMaxLineWidth() const override;
|
||||
virtual bool breakLineWithoutSpace() const override;
|
||||
virtual Size getLabelContentSize() const override;
|
||||
virtual void setLabelContentSize(const Size &newSize) override;
|
||||
virtual float getMaxLineWidth() const override;
|
||||
virtual bool breakLineWithoutSpace() const override;
|
||||
virtual Size getLabelContentSize() const override;
|
||||
virtual void setLabelContentSize(const Size &newSize) override;
|
||||
|
||||
// carloX
|
||||
const char * getString() const { return "not implemented"; }
|
||||
void addChild(Node * child, int zOrder=0, int tag=0);
|
||||
virtual const std::string& getString() const override { static std::string _ret("not implemented"); return _ret; }
|
||||
void addChild(Node * child, int zOrder=0, int tag=0) override;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
|
|
@ -42,7 +42,7 @@ NS_CC_BEGIN
|
|||
|
||||
//CCLabelAtlas - Creation & Init
|
||||
|
||||
LabelAtlas* LabelAtlas::create(const char *string, const char *charMapFile, unsigned int itemWidth, int unsigned itemHeight, unsigned int startCharMap)
|
||||
LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& charMapFile, long itemWidth, long itemHeight, long startCharMap)
|
||||
{
|
||||
LabelAtlas *pRet = new LabelAtlas();
|
||||
if(pRet && pRet->initWithString(string, charMapFile, itemWidth, itemHeight, startCharMap))
|
||||
|
@ -54,16 +54,15 @@ LabelAtlas* LabelAtlas::create(const char *string, const char *charMapFile, unsi
|
|||
return NULL;
|
||||
}
|
||||
|
||||
bool LabelAtlas::initWithString(const char *string, const char *charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap)
|
||||
bool LabelAtlas::initWithString(const std::string& string, const std::string& charMapFile, long itemWidth, long itemHeight, long startCharMap)
|
||||
{
|
||||
Texture2D *texture = TextureCache::getInstance()->addImage(charMapFile);
|
||||
return initWithString(string, texture, itemWidth, itemHeight, startCharMap);
|
||||
}
|
||||
|
||||
bool LabelAtlas::initWithString(const char *string, Texture2D* texture, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap)
|
||||
bool LabelAtlas::initWithString(const std::string& string, Texture2D* texture, long itemWidth, long itemHeight, long startCharMap)
|
||||
{
|
||||
CCASSERT(string != NULL, "");
|
||||
if (AtlasNode::initWithTexture(texture, itemWidth, itemHeight, strlen(string)))
|
||||
if (AtlasNode::initWithTexture(texture, itemWidth, itemHeight, string.size()))
|
||||
{
|
||||
_mapStartChar = startCharMap;
|
||||
this->setString(string);
|
||||
|
@ -72,7 +71,7 @@ bool LabelAtlas::initWithString(const char *string, Texture2D* texture, unsigned
|
|||
return false;
|
||||
}
|
||||
|
||||
LabelAtlas* LabelAtlas::create(const char *string, const char *fntFile)
|
||||
LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& fntFile)
|
||||
{
|
||||
LabelAtlas *ret = new LabelAtlas();
|
||||
if (ret)
|
||||
|
@ -90,24 +89,24 @@ LabelAtlas* LabelAtlas::create(const char *string, const char *fntFile)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool LabelAtlas::initWithString(const char *theString, const char *fntFile)
|
||||
bool LabelAtlas::initWithString(const std::string& theString, const std::string& fntFile)
|
||||
{
|
||||
std::string pathStr = FileUtils::getInstance()->fullPathForFilename(fntFile);
|
||||
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of("/"))+"/";
|
||||
Dictionary *dict = Dictionary::createWithContentsOfFile(pathStr.c_str());
|
||||
|
||||
CCASSERT(((String*)dict->objectForKey("version"))->intValue() == 1, "Unsupported version. Upgrade cocos2d version");
|
||||
|
||||
std::string texturePathStr = relPathStr + ((String*)dict->objectForKey("textureFilename"))->getCString();
|
||||
String *textureFilename = String::create(texturePathStr);
|
||||
unsigned int width = ((String*)dict->objectForKey("itemWidth"))->intValue() / CC_CONTENT_SCALE_FACTOR();
|
||||
unsigned int height = ((String*)dict->objectForKey("itemHeight"))->intValue() / CC_CONTENT_SCALE_FACTOR();
|
||||
unsigned int startChar = ((String*)dict->objectForKey("firstChar"))->intValue();
|
||||
|
||||
std::string pathStr = FileUtils::getInstance()->fullPathForFilename(fntFile);
|
||||
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of("/"))+"/";
|
||||
Dictionary *dict = Dictionary::createWithContentsOfFile(pathStr.c_str());
|
||||
|
||||
this->initWithString(theString, textureFilename->getCString(), width, height, startChar);
|
||||
|
||||
return true;
|
||||
CCASSERT(((String*)dict->objectForKey("version"))->intValue() == 1, "Unsupported version. Upgrade cocos2d version");
|
||||
|
||||
std::string texturePathStr = relPathStr + ((String*)dict->objectForKey("textureFilename"))->getCString();
|
||||
String *textureFilename = String::create(texturePathStr);
|
||||
unsigned int width = ((String*)dict->objectForKey("itemWidth"))->intValue() / CC_CONTENT_SCALE_FACTOR();
|
||||
unsigned int height = ((String*)dict->objectForKey("itemHeight"))->intValue() / CC_CONTENT_SCALE_FACTOR();
|
||||
unsigned int startChar = ((String*)dict->objectForKey("firstChar"))->intValue();
|
||||
|
||||
|
||||
this->initWithString(theString, textureFilename->getCString(), width, height, startChar);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//CCLabelAtlas - Atlas generation
|
||||
|
@ -186,9 +185,9 @@ void LabelAtlas::updateAtlasValues()
|
|||
}
|
||||
|
||||
//CCLabelAtlas - LabelProtocol
|
||||
void LabelAtlas::setString(const char *label)
|
||||
void LabelAtlas::setString(const std::string &label)
|
||||
{
|
||||
size_t len = strlen(label);
|
||||
size_t len = label.size();
|
||||
if (len > _textureAtlas->getTotalQuads())
|
||||
{
|
||||
_textureAtlas->resizeCapacity(len);
|
||||
|
@ -204,9 +203,9 @@ void LabelAtlas::setString(const char *label)
|
|||
_quadsToDraw = len;
|
||||
}
|
||||
|
||||
const char* LabelAtlas::getString(void) const
|
||||
const std::string& LabelAtlas::getString(void) const
|
||||
{
|
||||
return _string.c_str();
|
||||
return _string;
|
||||
}
|
||||
|
||||
//CCLabelAtlas - draw
|
||||
|
|
|
@ -67,38 +67,39 @@ public:
|
|||
}
|
||||
|
||||
/** 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 */
|
||||
static LabelAtlas * create(const char *string, const char *charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap);
|
||||
static LabelAtlas * create(const std::string& string, const std::string& charMapFile, long itemWidth, long itemHeight, long startCharMap);
|
||||
|
||||
/** creates the LabelAtlas with a string and a configuration file
|
||||
@since v2.0
|
||||
*/
|
||||
static LabelAtlas* create(const char *string, const char *fntFile);
|
||||
static LabelAtlas* create(const std::string& string, const std::string& fntFile);
|
||||
|
||||
/** 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 */
|
||||
bool initWithString(const char *string, const char *charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap);
|
||||
bool initWithString(const std::string& string, const std::string& charMapFile, long itemWidth, long itemHeight, long startCharMap);
|
||||
|
||||
/** initializes the LabelAtlas with a string and a configuration file
|
||||
@since v2.0
|
||||
*/
|
||||
bool initWithString(const char *string, const char *fntFile);
|
||||
bool initWithString(const std::string& string, const std::string& fntFile);
|
||||
|
||||
/** initializes the LabelAtlas with a string, a texture, the width and height in points of each element and the starting char of the atlas */
|
||||
bool initWithString(const char* string, Texture2D* texture, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap);
|
||||
bool initWithString(const std::string& string, Texture2D* texture, long itemWidth, long itemHeight, long startCharMap);
|
||||
|
||||
// super methods
|
||||
virtual void updateAtlasValues();
|
||||
virtual void setString(const char *label);
|
||||
virtual const char* getString(void) const;
|
||||
|
||||
virtual void setString(const std::string &label) override;
|
||||
virtual const std::string& getString(void) const override;
|
||||
|
||||
#if CC_LABELATLAS_DEBUG_DRAW
|
||||
virtual void draw();
|
||||
virtual void draw() override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// string to render
|
||||
std::string _string;
|
||||
// the first char in the charmap
|
||||
unsigned int _mapStartChar;
|
||||
long _mapStartChar;
|
||||
};
|
||||
|
||||
// end of GUI group
|
||||
|
|
|
@ -62,9 +62,9 @@ static unsigned short* copyUTF16StringN(unsigned short* str)
|
|||
//
|
||||
static Dictionary* s_pConfigurations = NULL;
|
||||
|
||||
CCBMFontConfiguration* FNTConfigLoadFile( const char *fntFile)
|
||||
CCBMFontConfiguration* FNTConfigLoadFile(const std::string& fntFile)
|
||||
{
|
||||
CCBMFontConfiguration* pRet = NULL;
|
||||
CCBMFontConfiguration* ret = NULL;
|
||||
|
||||
if( s_pConfigurations == NULL )
|
||||
{
|
||||
|
@ -72,17 +72,17 @@ CCBMFontConfiguration* FNTConfigLoadFile( const char *fntFile)
|
|||
s_pConfigurations->init();
|
||||
}
|
||||
|
||||
pRet = static_cast<CCBMFontConfiguration*>( s_pConfigurations->objectForKey(fntFile) );
|
||||
if( pRet == NULL )
|
||||
ret = static_cast<CCBMFontConfiguration*>( s_pConfigurations->objectForKey(fntFile) );
|
||||
if( ret == NULL )
|
||||
{
|
||||
pRet = CCBMFontConfiguration::create(fntFile);
|
||||
if (pRet)
|
||||
ret = CCBMFontConfiguration::create(fntFile.c_str());
|
||||
if (ret)
|
||||
{
|
||||
s_pConfigurations->setObject(pRet, fntFile);
|
||||
s_pConfigurations->setObject(ret, fntFile);
|
||||
}
|
||||
}
|
||||
|
||||
return pRet;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void FNTConfigRemoveCache( void )
|
||||
|
@ -98,19 +98,19 @@ void FNTConfigRemoveCache( void )
|
|||
//BitmapFontConfiguration
|
||||
//
|
||||
|
||||
CCBMFontConfiguration * CCBMFontConfiguration::create(const char *FNTfile)
|
||||
CCBMFontConfiguration * CCBMFontConfiguration::create(const std::string& FNTfile)
|
||||
{
|
||||
CCBMFontConfiguration * pRet = new CCBMFontConfiguration();
|
||||
if (pRet->initWithFNTfile(FNTfile))
|
||||
CCBMFontConfiguration * ret = new CCBMFontConfiguration();
|
||||
if (ret->initWithFNTfile(FNTfile))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CCBMFontConfiguration::initWithFNTfile(const char *FNTfile)
|
||||
bool CCBMFontConfiguration::initWithFNTfile(const std::string& FNTfile)
|
||||
{
|
||||
_kerningDictionary = NULL;
|
||||
_fontDefDictionary = NULL;
|
||||
|
@ -180,7 +180,7 @@ void CCBMFontConfiguration::purgeFontDefDictionary()
|
|||
}
|
||||
}
|
||||
|
||||
std::set<unsigned int>* CCBMFontConfiguration::parseConfigFile(const char *controlFile)
|
||||
std::set<unsigned int>* CCBMFontConfiguration::parseConfigFile(const std::string& controlFile)
|
||||
{
|
||||
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(controlFile);
|
||||
String *contents = String::createWithContentsOfFile(fullpath.c_str());
|
||||
|
@ -191,7 +191,7 @@ std::set<unsigned int>* CCBMFontConfiguration::parseConfigFile(const char *contr
|
|||
|
||||
if (!contents)
|
||||
{
|
||||
CCLOG("cocos2d: Error parsing FNTfile %s", controlFile);
|
||||
CCLOG("cocos2d: Error parsing FNTfile %s", controlFile.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -259,7 +259,7 @@ std::set<unsigned int>* CCBMFontConfiguration::parseConfigFile(const char *contr
|
|||
return validCharsString;
|
||||
}
|
||||
|
||||
void CCBMFontConfiguration::parseImageFileName(std::string line, const char *fntFile)
|
||||
void CCBMFontConfiguration::parseImageFileName(std::string line, const std::string& fntFile)
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// line to parse:
|
||||
|
@ -431,23 +431,23 @@ LabelBMFont * LabelBMFont::create()
|
|||
return NULL;
|
||||
}
|
||||
|
||||
LabelBMFont * LabelBMFont::create(const char *str, const char *fntFile, float width, TextHAlignment alignment)
|
||||
LabelBMFont * LabelBMFont::create(const std::string& str, const std::string& fntFile, float width, TextHAlignment alignment)
|
||||
{
|
||||
return LabelBMFont::create(str, fntFile, width, alignment, Point::ZERO);
|
||||
}
|
||||
|
||||
LabelBMFont * LabelBMFont::create(const char *str, const char *fntFile, float width)
|
||||
LabelBMFont * LabelBMFont::create(const std::string& str, const std::string& fntFile, float width)
|
||||
{
|
||||
return LabelBMFont::create(str, fntFile, width, TextHAlignment::LEFT, Point::ZERO);
|
||||
}
|
||||
|
||||
LabelBMFont * LabelBMFont::create(const char *str, const char *fntFile)
|
||||
LabelBMFont * LabelBMFont::create(const std::string& str, const std::string& fntFile)
|
||||
{
|
||||
return LabelBMFont::create(str, fntFile, kLabelAutomaticWidth, TextHAlignment::LEFT, Point::ZERO);
|
||||
}
|
||||
|
||||
//LabelBMFont - Creation & Init
|
||||
LabelBMFont *LabelBMFont::create(const char *str, const char *fntFile, float width/* = kLabelAutomaticWidth*/, TextHAlignment alignment/* = TextHAlignment::LEFT*/, Point imageOffset/* = Point::ZERO*/)
|
||||
LabelBMFont *LabelBMFont::create(const std::string& str, const std::string& fntFile, float width/* = kLabelAutomaticWidth*/, TextHAlignment alignment/* = TextHAlignment::LEFT*/, Point imageOffset/* = Point::ZERO*/)
|
||||
{
|
||||
LabelBMFont *pRet = new LabelBMFont();
|
||||
if(pRet && pRet->initWithString(str, fntFile, width, alignment, imageOffset))
|
||||
|
@ -461,22 +461,21 @@ LabelBMFont *LabelBMFont::create(const char *str, const char *fntFile, float wid
|
|||
|
||||
bool LabelBMFont::init()
|
||||
{
|
||||
return initWithString(NULL, NULL, kLabelAutomaticWidth, TextHAlignment::LEFT, Point::ZERO);
|
||||
return initWithString("", "", kLabelAutomaticWidth, TextHAlignment::LEFT, Point::ZERO);
|
||||
}
|
||||
|
||||
bool LabelBMFont::initWithString(const char *theString, const char *fntFile, float width/* = kLabelAutomaticWidth*/, TextHAlignment alignment/* = TextHAlignment::LEFT*/, Point imageOffset/* = Point::ZERO*/)
|
||||
bool LabelBMFont::initWithString(const std::string& theString, const std::string& fntFile, float width/* = kLabelAutomaticWidth*/, TextHAlignment alignment/* = TextHAlignment::LEFT*/, Point imageOffset/* = Point::ZERO*/)
|
||||
{
|
||||
CCASSERT(!_configuration, "re-init is no longer supported");
|
||||
CCASSERT( (theString && fntFile) || (theString==NULL && fntFile==NULL), "Invalid params for LabelBMFont");
|
||||
|
||||
|
||||
Texture2D *texture = NULL;
|
||||
|
||||
if (fntFile)
|
||||
if (fntFile.size() > 0 )
|
||||
{
|
||||
CCBMFontConfiguration *newConf = FNTConfigLoadFile(fntFile);
|
||||
if (!newConf)
|
||||
{
|
||||
CCLOG("cocos2d: WARNING. LabelBMFont: Impossible to create font. Please check file: '%s'", fntFile);
|
||||
CCLOG("cocos2d: WARNING. LabelBMFont: Impossible to create font. Please check file: '%s'", fntFile.c_str());
|
||||
release();
|
||||
return false;
|
||||
}
|
||||
|
@ -495,12 +494,7 @@ bool LabelBMFont::initWithString(const char *theString, const char *fntFile, flo
|
|||
texture->autorelease();
|
||||
}
|
||||
|
||||
if (theString == NULL)
|
||||
{
|
||||
theString = "";
|
||||
}
|
||||
|
||||
if (SpriteBatchNode::initWithTexture(texture, strlen(theString)))
|
||||
if (SpriteBatchNode::initWithTexture(texture, theString.size()))
|
||||
{
|
||||
_width = width;
|
||||
_alignment = alignment;
|
||||
|
@ -724,20 +718,17 @@ void LabelBMFont::createFontChars()
|
|||
}
|
||||
|
||||
//LabelBMFont - LabelProtocol protocol
|
||||
void LabelBMFont::setString(const char *newString)
|
||||
void LabelBMFont::setString(const std::string &newString)
|
||||
{
|
||||
this->setString(newString, true);
|
||||
}
|
||||
|
||||
void LabelBMFont::setString(const char *newString, bool needUpdateLabel)
|
||||
void LabelBMFont::setString(const std::string &newString, bool needUpdateLabel)
|
||||
{
|
||||
if (newString == NULL) {
|
||||
newString = "";
|
||||
}
|
||||
if (needUpdateLabel) {
|
||||
_initialStringUTF8 = newString;
|
||||
}
|
||||
unsigned short* utf16String = cc_utf8_to_utf16(newString);
|
||||
unsigned short* utf16String = cc_utf8_to_utf16(newString.c_str());
|
||||
setString(utf16String, needUpdateLabel);
|
||||
CC_SAFE_DELETE_ARRAY(utf16String);
|
||||
}
|
||||
|
@ -776,9 +767,9 @@ void LabelBMFont::setString(unsigned short *newString, bool needUpdateLabel)
|
|||
}
|
||||
}
|
||||
|
||||
const char* LabelBMFont::getString(void) const
|
||||
const std::string& LabelBMFont::getString() const
|
||||
{
|
||||
return _initialStringUTF8.c_str();
|
||||
return _initialStringUTF8;
|
||||
}
|
||||
|
||||
void LabelBMFont::setCString(const char *label)
|
||||
|
|
|
@ -140,21 +140,21 @@ public:
|
|||
const char * description() const;
|
||||
|
||||
/** allocates a CCBMFontConfiguration with a FNT file */
|
||||
static CCBMFontConfiguration * create(const char *FNTfile);
|
||||
static CCBMFontConfiguration * create(const std::string& FNTfile);
|
||||
|
||||
/** initializes a BitmapFontConfiguration with a FNT file */
|
||||
bool initWithFNTfile(const char *FNTfile);
|
||||
bool initWithFNTfile(const std::string& FNTfile);
|
||||
|
||||
inline const char* getAtlasName(){ return _atlasName.c_str(); }
|
||||
inline void setAtlasName(const char* atlasName) { _atlasName = atlasName; }
|
||||
inline const std::string& getAtlasName(){ return _atlasName; }
|
||||
inline void setAtlasName(const std::string& atlasName) { _atlasName = atlasName; }
|
||||
|
||||
std::set<unsigned int>* getCharacterSet() const;
|
||||
private:
|
||||
std::set<unsigned int>* parseConfigFile(const char *controlFile);
|
||||
std::set<unsigned int>* parseConfigFile(const std::string& controlFile);
|
||||
void parseCharacterDefinition(std::string line, ccBMFontDef *characterDefinition);
|
||||
void parseInfoArguments(std::string line);
|
||||
void parseCommonArguments(std::string line);
|
||||
void parseImageFileName(std::string line, const char *fntFile);
|
||||
void parseImageFileName(std::string line, const std::string& fntFile);
|
||||
void parseKerningEntry(std::string line);
|
||||
void purgeKerningDictionary();
|
||||
void purgeFontDefDictionary();
|
||||
|
@ -209,13 +209,13 @@ public:
|
|||
static void purgeCachedData();
|
||||
|
||||
/** creates a bitmap font atlas with an initial string and the FNT file */
|
||||
static LabelBMFont * create(const char *str, const char *fntFile, float width, TextHAlignment alignment, Point imageOffset);
|
||||
static LabelBMFont * create(const std::string& str, const std::string& fntFile, float width, TextHAlignment alignment, Point imageOffset);
|
||||
|
||||
static LabelBMFont * create(const char *str, const char *fntFile, float width, TextHAlignment alignment);
|
||||
static LabelBMFont * create(const std::string& str, const std::string& fntFile, float width, TextHAlignment alignment);
|
||||
|
||||
static LabelBMFont * create(const char *str, const char *fntFile, float width);
|
||||
static LabelBMFont * create(const std::string& str, const std::string& fntFile, float width);
|
||||
|
||||
static LabelBMFont * create(const char *str, const char *fntFile);
|
||||
static LabelBMFont * create(const std::string& str, const std::string& fntFile);
|
||||
|
||||
/** Creates an label.
|
||||
*/
|
||||
|
@ -223,15 +223,15 @@ public:
|
|||
|
||||
bool init();
|
||||
/** init a bitmap font atlas with an initial string and the FNT file */
|
||||
bool initWithString(const char *str, const char *fntFile, float width = kLabelAutomaticWidth, TextHAlignment alignment = TextHAlignment::LEFT, Point imageOffset = Point::ZERO);
|
||||
bool initWithString(const std::string& str, const std::string& fntFile, float width = kLabelAutomaticWidth, TextHAlignment alignment = TextHAlignment::LEFT, Point imageOffset = Point::ZERO);
|
||||
|
||||
/** updates the font chars based on the string to render */
|
||||
void createFontChars();
|
||||
// super method
|
||||
virtual void setString(const char *newString);
|
||||
virtual void setString(const char *newString, bool needUpdateLabel);
|
||||
virtual void setString(const std::string& newString) override;
|
||||
virtual void setString(const std::string& newString, bool needUpdateLabel);
|
||||
|
||||
virtual const char* getString(void) const;
|
||||
virtual const std::string& getString() const override;
|
||||
virtual void setCString(const char *label);
|
||||
virtual void setAnchorPoint(const Point& var);
|
||||
virtual void updateLabel();
|
||||
|
@ -264,7 +264,7 @@ public:
|
|||
virtual void draw();
|
||||
#endif // CC_LABELBMFONT_DEBUG_DRAW
|
||||
private:
|
||||
char * atlasNameFromFntFile(const char *fntFile);
|
||||
char * atlasNameFromFntFile(const std::string& fntFile);
|
||||
int kerningAmountForFirst(unsigned short first, unsigned short second);
|
||||
float getLetterPosXLeft( Sprite* characterSprite );
|
||||
float getLetterPosXRight( Sprite* characterSprite );
|
||||
|
@ -303,13 +303,13 @@ protected:
|
|||
bool _cascadeColorEnabled;
|
||||
bool _cascadeOpacityEnabled;
|
||||
/** conforms to RGBAProtocol protocol */
|
||||
bool _isOpacityModifyRGB;
|
||||
bool _isOpacityModifyRGB;
|
||||
|
||||
};
|
||||
|
||||
/** Free function that parses a FNT file a place it on the cache
|
||||
*/
|
||||
CC_DLL CCBMFontConfiguration * FNTConfigLoadFile( const char *file );
|
||||
CC_DLL CCBMFontConfiguration * FNTConfigLoadFile(const std::string &file);
|
||||
/** Purges the FNT config cache
|
||||
*/
|
||||
CC_DLL void FNTConfigRemoveCache( void );
|
||||
|
|
|
@ -42,7 +42,7 @@ NS_CC_BEGIN
|
|||
LabelTTF::LabelTTF()
|
||||
: _alignment(TextHAlignment::CENTER)
|
||||
, _vAlignment(TextVAlignment::TOP)
|
||||
, _fontName(NULL)
|
||||
, _fontName("")
|
||||
, _fontSize(0.0)
|
||||
, _string("")
|
||||
, _shadowEnabled(false)
|
||||
|
@ -53,58 +53,57 @@ LabelTTF::LabelTTF()
|
|||
|
||||
LabelTTF::~LabelTTF()
|
||||
{
|
||||
CC_SAFE_DELETE(_fontName);
|
||||
}
|
||||
|
||||
LabelTTF * LabelTTF::create()
|
||||
{
|
||||
LabelTTF * pRet = new LabelTTF();
|
||||
if (pRet && pRet->init())
|
||||
LabelTTF * ret = new LabelTTF();
|
||||
if (ret && ret->init())
|
||||
{
|
||||
pRet->autorelease();
|
||||
ret->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
}
|
||||
return pRet;
|
||||
return ret;
|
||||
}
|
||||
|
||||
LabelTTF * LabelTTF::create(const char *string, const char *fontName, float fontSize)
|
||||
LabelTTF * LabelTTF::create(const std::string& string, const std::string& fontName, float fontSize)
|
||||
{
|
||||
return LabelTTF::create(string, fontName, fontSize,
|
||||
Size::ZERO, TextHAlignment::CENTER, TextVAlignment::TOP);
|
||||
}
|
||||
|
||||
LabelTTF * LabelTTF::create(const char *string, const char *fontName, float fontSize,
|
||||
LabelTTF * LabelTTF::create(const std::string& string, const std::string& fontName, float fontSize,
|
||||
const Size& dimensions, TextHAlignment hAlignment)
|
||||
{
|
||||
return LabelTTF::create(string, fontName, fontSize, dimensions, hAlignment, TextVAlignment::TOP);
|
||||
}
|
||||
|
||||
LabelTTF* LabelTTF::create(const char *string, const char *fontName, float fontSize,
|
||||
LabelTTF* LabelTTF::create(const std::string& string, const std::string& fontName, float fontSize,
|
||||
const Size &dimensions, TextHAlignment hAlignment,
|
||||
TextVAlignment vAlignment)
|
||||
{
|
||||
LabelTTF *pRet = new LabelTTF();
|
||||
if(pRet && pRet->initWithString(string, fontName, fontSize, dimensions, hAlignment, vAlignment))
|
||||
LabelTTF *ret = new LabelTTF();
|
||||
if(ret && ret->initWithString(string, fontName, fontSize, dimensions, hAlignment, vAlignment))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LabelTTF * LabelTTF::createWithFontDefinition(const char *string, FontDefinition &textDefinition)
|
||||
LabelTTF * LabelTTF::createWithFontDefinition(const std::string& string, FontDefinition &textDefinition)
|
||||
{
|
||||
LabelTTF *pRet = new LabelTTF();
|
||||
if(pRet && pRet->initWithStringAndTextDefinition(string, textDefinition))
|
||||
LabelTTF *ret = new LabelTTF();
|
||||
if(ret && ret->initWithStringAndTextDefinition(string, textDefinition))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -113,19 +112,19 @@ bool LabelTTF::init()
|
|||
return this->initWithString("", "Helvetica", 12);
|
||||
}
|
||||
|
||||
bool LabelTTF::initWithString(const char *label, const char *fontName, float fontSize,
|
||||
bool LabelTTF::initWithString(const std::string& label, const std::string& fontName, float fontSize,
|
||||
const Size& dimensions, TextHAlignment alignment)
|
||||
{
|
||||
return this->initWithString(label, fontName, fontSize, dimensions, alignment, TextVAlignment::TOP);
|
||||
}
|
||||
|
||||
bool LabelTTF::initWithString(const char *label, const char *fontName, float fontSize)
|
||||
bool LabelTTF::initWithString(const std::string& label, const std::string& fontName, float fontSize)
|
||||
{
|
||||
return this->initWithString(label, fontName, fontSize,
|
||||
Size::ZERO, TextHAlignment::LEFT, TextVAlignment::TOP);
|
||||
}
|
||||
|
||||
bool LabelTTF::initWithString(const char *string, const char *fontName, float fontSize,
|
||||
bool LabelTTF::initWithString(const std::string& string, const std::string& fontName, float fontSize,
|
||||
const cocos2d::Size &dimensions, TextHAlignment hAlignment,
|
||||
TextVAlignment vAlignment)
|
||||
{
|
||||
|
@ -135,10 +134,10 @@ bool LabelTTF::initWithString(const char *string, const char *fontName, float fo
|
|||
this->setShaderProgram(ShaderCache::getInstance()->getProgram(SHADER_PROGRAM));
|
||||
|
||||
_dimensions = Size(dimensions.width, dimensions.height);
|
||||
_alignment = hAlignment;
|
||||
_vAlignment = vAlignment;
|
||||
_fontName = new std::string(fontName);
|
||||
_fontSize = fontSize;
|
||||
_alignment = hAlignment;
|
||||
_vAlignment = vAlignment;
|
||||
_fontName = fontName;
|
||||
_fontSize = fontSize;
|
||||
|
||||
this->setString(string);
|
||||
|
||||
|
@ -148,7 +147,7 @@ bool LabelTTF::initWithString(const char *string, const char *fontName, float fo
|
|||
return false;
|
||||
}
|
||||
|
||||
bool LabelTTF::initWithStringAndTextDefinition(const char *string, FontDefinition &textDefinition)
|
||||
bool LabelTTF::initWithStringAndTextDefinition(const std::string& string, FontDefinition &textDefinition)
|
||||
{
|
||||
if (Sprite::init())
|
||||
{
|
||||
|
@ -171,10 +170,8 @@ bool LabelTTF::initWithStringAndTextDefinition(const char *string, FontDefinitio
|
|||
}
|
||||
|
||||
|
||||
void LabelTTF::setString(const char *string)
|
||||
void LabelTTF::setString(const std::string &string)
|
||||
{
|
||||
CCASSERT(string != NULL, "Invalid string");
|
||||
|
||||
if (_string.compare(string))
|
||||
{
|
||||
_string = string;
|
||||
|
@ -183,14 +180,14 @@ void LabelTTF::setString(const char *string)
|
|||
}
|
||||
}
|
||||
|
||||
const char* LabelTTF::getString(void) const
|
||||
const std::string& LabelTTF::getString() const
|
||||
{
|
||||
return _string.c_str();
|
||||
return _string;
|
||||
}
|
||||
|
||||
const char* LabelTTF::description() const
|
||||
{
|
||||
return String::createWithFormat("<LabelTTF | FontName = %s, FontSize = %.1f>", _fontName->c_str(), _fontSize)->getCString();
|
||||
return String::createWithFormat("<LabelTTF | FontName = %s, FontSize = %.1f>", _fontName.c_str(), _fontSize)->getCString();
|
||||
}
|
||||
|
||||
TextHAlignment LabelTTF::getHorizontalAlignment() const
|
||||
|
@ -238,6 +235,7 @@ const Size& LabelTTF::getDimensions() const
|
|||
|
||||
void LabelTTF::setDimensions(const Size &dim)
|
||||
{
|
||||
// XXX: float comparison... very unreliable
|
||||
if (dim.width != _dimensions.width || dim.height != _dimensions.height)
|
||||
{
|
||||
_dimensions = dim;
|
||||
|
@ -257,6 +255,7 @@ float LabelTTF::getFontSize() const
|
|||
|
||||
void LabelTTF::setFontSize(float fontSize)
|
||||
{
|
||||
// XXX: float comparison... very unreliable
|
||||
if (_fontSize != fontSize)
|
||||
{
|
||||
_fontSize = fontSize;
|
||||
|
@ -269,17 +268,16 @@ void LabelTTF::setFontSize(float fontSize)
|
|||
}
|
||||
}
|
||||
|
||||
const char* LabelTTF::getFontName() const
|
||||
const std::string& LabelTTF::getFontName() const
|
||||
{
|
||||
return _fontName->c_str();
|
||||
return _fontName;
|
||||
}
|
||||
|
||||
void LabelTTF::setFontName(const char *fontName)
|
||||
void LabelTTF::setFontName(const std::string& fontName)
|
||||
{
|
||||
if (_fontName->compare(fontName))
|
||||
if (_fontName.compare(fontName))
|
||||
{
|
||||
delete _fontName;
|
||||
_fontName = new std::string(fontName);
|
||||
_fontName = fontName;
|
||||
|
||||
// Force update
|
||||
if (_string.size() > 0)
|
||||
|
@ -298,21 +296,21 @@ bool LabelTTF::updateTexture()
|
|||
if (!tex)
|
||||
return false;
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
FontDefinition texDef = _prepareTextDefinition(true);
|
||||
tex->initWithString( _string.c_str(), texDef );
|
||||
|
||||
#else
|
||||
#else
|
||||
|
||||
tex->initWithString( _string.c_str(),
|
||||
_fontName->c_str(),
|
||||
_fontName.c_str(),
|
||||
_fontSize * CC_CONTENT_SCALE_FACTOR(),
|
||||
CC_SIZE_POINTS_TO_PIXELS(_dimensions),
|
||||
_alignment,
|
||||
_vAlignment);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// set the texture
|
||||
this->setTexture(tex);
|
||||
|
@ -342,7 +340,7 @@ void LabelTTF::enableShadow(const Size &shadowOffset, float shadowOpacity, float
|
|||
|
||||
if ( (_shadowOffset.width != shadowOffset.width) || (_shadowOffset.height!=shadowOffset.height) )
|
||||
{
|
||||
_shadowOffset.width = shadowOffset.width;
|
||||
_shadowOffset.width = shadowOffset.width;
|
||||
_shadowOffset.height = shadowOffset.height;
|
||||
|
||||
valueChanged = true;
|
||||
|
@ -354,27 +352,26 @@ void LabelTTF::enableShadow(const Size &shadowOffset, float shadowOpacity, float
|
|||
valueChanged = true;
|
||||
}
|
||||
|
||||
if (_shadowBlur != shadowBlur)
|
||||
if (_shadowBlur != shadowBlur)
|
||||
{
|
||||
_shadowBlur = shadowBlur;
|
||||
valueChanged = true;
|
||||
}
|
||||
|
||||
|
||||
if ( valueChanged && updateTexture )
|
||||
{
|
||||
this->updateTexture();
|
||||
}
|
||||
|
||||
#else
|
||||
#else
|
||||
CCLOGERROR("Currently only supported on iOS and Android!");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void LabelTTF::disableShadow(bool updateTexture)
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
if (_shadowEnabled)
|
||||
{
|
||||
|
@ -382,17 +379,16 @@ void LabelTTF::disableShadow(bool updateTexture)
|
|||
|
||||
if (updateTexture)
|
||||
this->updateTexture();
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
#else
|
||||
CCLOGERROR("Currently only supported on iOS and Android!");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void LabelTTF::enableStroke(const Color3B &strokeColor, float strokeSize, bool updateTexture)
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
bool valueChanged = false;
|
||||
|
||||
|
@ -419,15 +415,15 @@ void LabelTTF::enableStroke(const Color3B &strokeColor, float strokeSize, bool u
|
|||
this->updateTexture();
|
||||
}
|
||||
|
||||
#else
|
||||
#else
|
||||
CCLOGERROR("Currently only supported on iOS and Android!");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void LabelTTF::disableStroke(bool updateTexture)
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
if (_strokeEnabled)
|
||||
{
|
||||
|
@ -437,15 +433,15 @@ void LabelTTF::disableStroke(bool updateTexture)
|
|||
this->updateTexture();
|
||||
}
|
||||
|
||||
#else
|
||||
#else
|
||||
CCLOGERROR("Currently only supported on iOS and Android!");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void LabelTTF::setFontFillColor(const Color3B &tintColor, bool updateTexture)
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
if (_textFillColor.r != tintColor.r || _textFillColor.g != tintColor.g || _textFillColor.b != tintColor.b)
|
||||
{
|
||||
_textFillColor = tintColor;
|
||||
|
@ -453,9 +449,9 @@ void LabelTTF::setFontFillColor(const Color3B &tintColor, bool updateTexture)
|
|||
if (updateTexture)
|
||||
this->updateTexture();
|
||||
}
|
||||
#else
|
||||
#else
|
||||
CCLOGERROR("Currently only supported on iOS and Android!");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void LabelTTF::setTextDefinition(const FontDefinition& theDefinition)
|
||||
|
@ -471,11 +467,11 @@ FontDefinition LabelTTF::getTextDefinition()
|
|||
void LabelTTF::_updateWithTextDefinition(const FontDefinition& textDefinition, bool mustUpdateTexture)
|
||||
{
|
||||
_dimensions = Size(textDefinition._dimensions.width, textDefinition._dimensions.height);
|
||||
_alignment = textDefinition._alignment;
|
||||
_vAlignment = textDefinition._vertAlignment;
|
||||
_alignment = textDefinition._alignment;
|
||||
_vAlignment = textDefinition._vertAlignment;
|
||||
|
||||
_fontName = new std::string(textDefinition._fontName);
|
||||
_fontSize = textDefinition._fontSize;
|
||||
_fontName = textDefinition._fontName;
|
||||
_fontSize = textDefinition._fontSize;
|
||||
|
||||
|
||||
// shadow
|
||||
|
@ -502,19 +498,19 @@ FontDefinition LabelTTF::_prepareTextDefinition(bool adjustForResolution)
|
|||
FontDefinition texDef;
|
||||
|
||||
if (adjustForResolution)
|
||||
texDef._fontSize = _fontSize * CC_CONTENT_SCALE_FACTOR();
|
||||
texDef._fontSize = _fontSize * CC_CONTENT_SCALE_FACTOR();
|
||||
else
|
||||
texDef._fontSize = _fontSize;
|
||||
texDef._fontSize = _fontSize;
|
||||
|
||||
texDef._fontName = *_fontName;
|
||||
texDef._alignment = _alignment;
|
||||
texDef._vertAlignment = _vAlignment;
|
||||
texDef._fontName = _fontName;
|
||||
texDef._alignment = _alignment;
|
||||
texDef._vertAlignment = _vAlignment;
|
||||
|
||||
|
||||
if (adjustForResolution)
|
||||
texDef._dimensions = CC_SIZE_POINTS_TO_PIXELS(_dimensions);
|
||||
texDef._dimensions = CC_SIZE_POINTS_TO_PIXELS(_dimensions);
|
||||
else
|
||||
texDef._dimensions = _dimensions;
|
||||
texDef._dimensions = _dimensions;
|
||||
|
||||
|
||||
// stroke
|
||||
|
@ -527,21 +523,18 @@ FontDefinition LabelTTF::_prepareTextDefinition(bool adjustForResolution)
|
|||
texDef._stroke._strokeSize = _strokeSize * CC_CONTENT_SCALE_FACTOR();
|
||||
else
|
||||
texDef._stroke._strokeSize = _strokeSize;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
texDef._stroke._strokeEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
// shadow
|
||||
if ( _shadowEnabled )
|
||||
{
|
||||
texDef._shadow._shadowEnabled = true;
|
||||
texDef._shadow._shadowBlur = _shadowBlur;
|
||||
texDef._shadow._shadowOpacity = _shadowOpacity;
|
||||
texDef._shadow._shadowEnabled = true;
|
||||
texDef._shadow._shadowBlur = _shadowBlur;
|
||||
texDef._shadow._shadowOpacity = _shadowOpacity;
|
||||
|
||||
if (adjustForResolution)
|
||||
texDef._shadow._shadowOffset = CC_SIZE_POINTS_TO_PIXELS(_shadowOffset);
|
||||
|
|
|
@ -75,39 +75,39 @@ public:
|
|||
/** creates a LabelTTF with a font name and font size in points
|
||||
@since v2.0.1
|
||||
*/
|
||||
static LabelTTF * create(const char *string, const char *fontName, float fontSize);
|
||||
static LabelTTF * create(const std::string& string, const std::string& fontName, float fontSize);
|
||||
|
||||
/** creates a LabelTTF from a fontname, horizontal alignment, dimension in points, and font size in points.
|
||||
@since v2.0.1
|
||||
*/
|
||||
static LabelTTF * create(const char *string, const char *fontName, float fontSize,
|
||||
const Size& dimensions, TextHAlignment hAlignment);
|
||||
static LabelTTF * create(const std::string& string, const std::string& fontName, float fontSize,
|
||||
const Size& dimensions, TextHAlignment hAlignment);
|
||||
|
||||
/** creates a Label from a fontname, alignment, dimension in points and font size in points
|
||||
@since v2.0.1
|
||||
*/
|
||||
static LabelTTF * create(const char *string, const char *fontName, float fontSize,
|
||||
const Size& dimensions, TextHAlignment hAlignment,
|
||||
TextVAlignment vAlignment);
|
||||
static LabelTTF * create(const std::string& string, const std::string& fontName, float fontSize,
|
||||
const Size& dimensions, TextHAlignment hAlignment,
|
||||
TextVAlignment vAlignment);
|
||||
|
||||
|
||||
/** Create a lable with string and a font definition*/
|
||||
static LabelTTF * createWithFontDefinition(const char *string, FontDefinition &textDefinition);
|
||||
static LabelTTF * createWithFontDefinition(const std::string& string, FontDefinition &textDefinition);
|
||||
|
||||
/** initializes the LabelTTF with a font name and font size */
|
||||
bool initWithString(const char *string, const char *fontName, float fontSize);
|
||||
bool initWithString(const std::string& string, const std::string& fontName, float fontSize);
|
||||
|
||||
/** initializes the LabelTTF with a font name, alignment, dimension and font size */
|
||||
bool initWithString(const char *string, const char *fontName, float fontSize,
|
||||
bool initWithString(const std::string& string, const std::string& fontName, float fontSize,
|
||||
const Size& dimensions, TextHAlignment hAlignment);
|
||||
|
||||
/** initializes the LabelTTF with a font name, alignment, dimension and font size */
|
||||
bool initWithString(const char *string, const char *fontName, float fontSize,
|
||||
bool initWithString(const std::string& string, const std::string& fontName, float fontSize,
|
||||
const Size& dimensions, TextHAlignment hAlignment,
|
||||
TextVAlignment vAlignment);
|
||||
|
||||
/** initializes the LabelTTF with a font name, alignment, dimension and font size */
|
||||
bool initWithStringAndTextDefinition(const char *string, FontDefinition &textDefinition);
|
||||
bool initWithStringAndTextDefinition(const std::string& string, FontDefinition &textDefinition);
|
||||
|
||||
/** set the text definition used by this label */
|
||||
void setTextDefinition(const FontDefinition& theDefinition);
|
||||
|
@ -144,8 +144,8 @@ public:
|
|||
/** changes the string to render
|
||||
* @warning Changing the string is as expensive as creating a new LabelTTF. To obtain better performance use LabelAtlas
|
||||
*/
|
||||
virtual void setString(const char *label);
|
||||
virtual const char* getString(void) const;
|
||||
virtual void setString(const std::string &label) override;
|
||||
virtual const std::string& getString(void) const override;
|
||||
|
||||
TextHAlignment getHorizontalAlignment() const;
|
||||
void setHorizontalAlignment(TextHAlignment alignment);
|
||||
|
@ -159,8 +159,8 @@ public:
|
|||
float getFontSize() const;
|
||||
void setFontSize(float fontSize);
|
||||
|
||||
const char* getFontName() const;
|
||||
void setFontName(const char *fontName);
|
||||
const std::string& getFontName() const;
|
||||
void setFontName(const std::string& fontName);
|
||||
|
||||
private:
|
||||
bool updateTexture();
|
||||
|
@ -177,7 +177,7 @@ protected:
|
|||
/** The vertical alignment of the label */
|
||||
TextVAlignment _vAlignment;
|
||||
/** Font name used in the label */
|
||||
std::string * _fontName;
|
||||
std::string _fontName;
|
||||
/** Font size of the label */
|
||||
float _fontSize;
|
||||
/** label's string */
|
||||
|
|
|
@ -42,7 +42,7 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
static unsigned int _globalFontSize = kItemSize;
|
||||
static long _globalFontSize = kItemSize;
|
||||
static std::string _globalFontName = "Marker Felt";
|
||||
static bool _globalFontNameRelease = false;
|
||||
|
||||
|
@ -64,18 +64,18 @@ MenuItem* MenuItem::create()
|
|||
// XXX deprecated
|
||||
MenuItem* MenuItem::create(Object *target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItem *pRet = new MenuItem();
|
||||
pRet->initWithTarget(target, selector);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItem *ret = new MenuItem();
|
||||
ret->initWithTarget(target, selector);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
MenuItem* MenuItem::create( const ccMenuCallback& callback)
|
||||
{
|
||||
MenuItem *pRet = new MenuItem();
|
||||
pRet->initWithCallback(callback);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItem *ret = new MenuItem();
|
||||
ret->initWithCallback(callback);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// XXX deprecated
|
||||
|
@ -188,26 +188,26 @@ void MenuItemLabel::setLabel(Node* var)
|
|||
// XXX: deprecated
|
||||
MenuItemLabel * MenuItemLabel::create(Node*label, Object* target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItemLabel *pRet = new MenuItemLabel();
|
||||
pRet->initWithLabel(label, target, selector);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItemLabel *ret = new MenuItemLabel();
|
||||
ret->initWithLabel(label, target, selector);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
MenuItemLabel * MenuItemLabel::create(Node*label, const ccMenuCallback& callback)
|
||||
{
|
||||
MenuItemLabel *pRet = new MenuItemLabel();
|
||||
pRet->initWithLabel(label, callback);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItemLabel *ret = new MenuItemLabel();
|
||||
ret->initWithLabel(label, callback);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
MenuItemLabel* MenuItemLabel::create(Node *label)
|
||||
{
|
||||
MenuItemLabel *pRet = new MenuItemLabel();
|
||||
pRet->initWithLabel(label, (const ccMenuCallback&) nullptr);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItemLabel *ret = new MenuItemLabel();
|
||||
ret->initWithLabel(label, (const ccMenuCallback&) nullptr);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// XXX: deprecated
|
||||
|
@ -237,7 +237,7 @@ MenuItemLabel::~MenuItemLabel()
|
|||
{
|
||||
}
|
||||
|
||||
void MenuItemLabel::setString(const char * label)
|
||||
void MenuItemLabel::setString(const std::string& label)
|
||||
{
|
||||
dynamic_cast<LabelProtocol*>(_label)->setString(label);
|
||||
this->setContentSize(_label->getContentSize());
|
||||
|
@ -310,41 +310,39 @@ void MenuItemLabel::setEnabled(bool enabled)
|
|||
//CCMenuItemAtlasFont
|
||||
//
|
||||
|
||||
MenuItemAtlasFont * MenuItemAtlasFont::create(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap)
|
||||
MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap)
|
||||
{
|
||||
return MenuItemAtlasFont::create(value, charMapFile, itemWidth, itemHeight, startCharMap, (const ccMenuCallback&)nullptr);
|
||||
}
|
||||
|
||||
// XXX: deprecated
|
||||
MenuItemAtlasFont * MenuItemAtlasFont::create(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector)
|
||||
MenuItemAtlasFont * MenuItemAtlasFont::create(const char* value, const char* charMapFile, long itemWidth, long itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItemAtlasFont *pRet = new MenuItemAtlasFont();
|
||||
pRet->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItemAtlasFont *ret = new MenuItemAtlasFont();
|
||||
ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
MenuItemAtlasFont * MenuItemAtlasFont::create(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback)
|
||||
MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback)
|
||||
{
|
||||
MenuItemAtlasFont *pRet = new MenuItemAtlasFont();
|
||||
pRet->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, callback);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItemAtlasFont *ret = new MenuItemAtlasFont();
|
||||
ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, callback);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// XXX: deprecated
|
||||
bool MenuItemAtlasFont::initWithString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector)
|
||||
bool MenuItemAtlasFont::initWithString(const char* value, const char* charMapFile, long itemWidth, long itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector)
|
||||
{
|
||||
CCASSERT( value != NULL && strlen(value) != 0, "value length must be greater than 0");
|
||||
|
||||
_target = target;
|
||||
CC_SAFE_RETAIN(_target);
|
||||
return initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, std::bind(selector,target, std::placeholders::_1) );
|
||||
}
|
||||
|
||||
bool MenuItemAtlasFont::initWithString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback)
|
||||
bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback)
|
||||
{
|
||||
CCASSERT( value != NULL && strlen(value) != 0, "value length must be greater than 0");
|
||||
CCASSERT( value.size() != 0, "value length must be greater than 0");
|
||||
LabelAtlas *label = new LabelAtlas();
|
||||
label->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap);
|
||||
label->autorelease();
|
||||
|
@ -359,17 +357,17 @@ bool MenuItemAtlasFont::initWithString(const char *value, const char *charMapFil
|
|||
//CCMenuItemFont
|
||||
//
|
||||
|
||||
void MenuItemFont::setFontSize(unsigned int s)
|
||||
void MenuItemFont::setFontSize(long s)
|
||||
{
|
||||
_globalFontSize = s;
|
||||
}
|
||||
|
||||
unsigned int MenuItemFont::getFontSize()
|
||||
long MenuItemFont::getFontSize()
|
||||
{
|
||||
return _globalFontSize;
|
||||
}
|
||||
|
||||
void MenuItemFont::setFontName(const char *name)
|
||||
void MenuItemFont::setFontName(const std::string& name)
|
||||
{
|
||||
if (_globalFontNameRelease)
|
||||
{
|
||||
|
@ -379,35 +377,35 @@ void MenuItemFont::setFontName(const char *name)
|
|||
_globalFontNameRelease = true;
|
||||
}
|
||||
|
||||
const char * MenuItemFont::getFontName()
|
||||
const std::string& MenuItemFont::getFontName()
|
||||
{
|
||||
return _globalFontName.c_str();
|
||||
return _globalFontName;
|
||||
}
|
||||
|
||||
// XXX: deprecated
|
||||
MenuItemFont * MenuItemFont::create(const char *value, Object* target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItemFont *pRet = new MenuItemFont();
|
||||
pRet->initWithString(value, target, selector);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItemFont *ret = new MenuItemFont();
|
||||
ret->initWithString(value, target, selector);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
MenuItemFont * MenuItemFont::create(const char *value, const ccMenuCallback& callback)
|
||||
MenuItemFont * MenuItemFont::create(const std::string& value, const ccMenuCallback& callback)
|
||||
{
|
||||
MenuItemFont *pRet = new MenuItemFont();
|
||||
pRet->initWithString(value, callback);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItemFont *ret = new MenuItemFont();
|
||||
ret->initWithString(value, callback);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
MenuItemFont * MenuItemFont::create(const char *value)
|
||||
MenuItemFont * MenuItemFont::create(const std::string& value)
|
||||
{
|
||||
MenuItemFont *pRet = new MenuItemFont();
|
||||
pRet->initWithString(value, (const ccMenuCallback&)nullptr);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItemFont *ret = new MenuItemFont();
|
||||
ret->initWithString(value, (const ccMenuCallback&)nullptr);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
MenuItemFont::MenuItemFont()
|
||||
|
@ -429,14 +427,14 @@ bool MenuItemFont::initWithString(const char *value, Object* target, SEL_MenuHan
|
|||
return initWithString(value, std::bind(selector,target, std::placeholders::_1) );
|
||||
}
|
||||
|
||||
bool MenuItemFont::initWithString(const char *value, const ccMenuCallback& callback)
|
||||
bool MenuItemFont::initWithString(const std::string& value, const ccMenuCallback& callback)
|
||||
{
|
||||
CCASSERT( value != NULL && strlen(value) != 0, "Value length must be greater than 0");
|
||||
CCASSERT( value.size() >= 0, "Value length must be greater than 0");
|
||||
|
||||
_fontName = _globalFontName;
|
||||
_fontSize = _globalFontSize;
|
||||
|
||||
LabelTTF *label = LabelTTF::create(value, _fontName.c_str(), (float)_fontSize);
|
||||
LabelTTF *label = LabelTTF::create(value, _fontName, (float)_fontSize);
|
||||
if (MenuItemLabel::initWithLabel(label, callback))
|
||||
{
|
||||
// do something ?
|
||||
|
@ -451,26 +449,26 @@ void MenuItemFont::recreateLabel()
|
|||
this->setLabel(label);
|
||||
}
|
||||
|
||||
void MenuItemFont::setFontSizeObj(unsigned int s)
|
||||
void MenuItemFont::setFontSizeObj(long s)
|
||||
{
|
||||
_fontSize = s;
|
||||
recreateLabel();
|
||||
}
|
||||
|
||||
unsigned int MenuItemFont::getFontSizeObj() const
|
||||
long MenuItemFont::getFontSizeObj() const
|
||||
{
|
||||
return _fontSize;
|
||||
}
|
||||
|
||||
void MenuItemFont::setFontNameObj(const char* name)
|
||||
void MenuItemFont::setFontNameObj(const std::string& name)
|
||||
{
|
||||
_fontName = name;
|
||||
recreateLabel();
|
||||
}
|
||||
|
||||
const char* MenuItemFont::getFontNameObj() const
|
||||
const std::string& MenuItemFont::getFontNameObj() const
|
||||
{
|
||||
return _fontName.c_str();
|
||||
return _fontName;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -561,18 +559,18 @@ MenuItemSprite * MenuItemSprite::create(Node* normalSprite, Node* selectedSprite
|
|||
// XXX deprecated
|
||||
MenuItemSprite * MenuItemSprite::create(Node *normalSprite, Node *selectedSprite, Node *disabledSprite, Object *target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItemSprite *pRet = new MenuItemSprite();
|
||||
pRet->initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItemSprite *ret = new MenuItemSprite();
|
||||
ret->initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
MenuItemSprite * MenuItemSprite::create(Node *normalSprite, Node *selectedSprite, Node *disabledSprite, const ccMenuCallback& callback)
|
||||
{
|
||||
MenuItemSprite *pRet = new MenuItemSprite();
|
||||
pRet->initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, callback);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItemSprite *ret = new MenuItemSprite();
|
||||
ret->initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, callback);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// XXX deprecated
|
||||
|
@ -687,71 +685,71 @@ void MenuItemSprite::updateImagesVisibility()
|
|||
|
||||
MenuItemImage* MenuItemImage::create()
|
||||
{
|
||||
MenuItemImage *pRet = new MenuItemImage();
|
||||
if (pRet && pRet->init())
|
||||
MenuItemImage *ret = new MenuItemImage();
|
||||
if (ret && ret->init())
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool MenuItemImage::init(void)
|
||||
{
|
||||
return initWithNormalImage(NULL, NULL, NULL, (const ccMenuCallback&)nullptr);
|
||||
return initWithNormalImage("", "", "", (const ccMenuCallback&)nullptr);
|
||||
}
|
||||
|
||||
MenuItemImage * MenuItemImage::create(const char *normalImage, const char *selectedImage)
|
||||
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage)
|
||||
{
|
||||
return MenuItemImage::create(normalImage, selectedImage, NULL, (const ccMenuCallback&)nullptr);
|
||||
return MenuItemImage::create(normalImage, selectedImage, "", (const ccMenuCallback&)nullptr);
|
||||
}
|
||||
|
||||
// XXX deprecated
|
||||
MenuItemImage * MenuItemImage::create(const char *normalImage, const char *selectedImage, Object* target, SEL_MenuHandler selector)
|
||||
{
|
||||
return MenuItemImage::create(normalImage, selectedImage, NULL, target, selector);
|
||||
return MenuItemImage::create(normalImage, selectedImage, "", target, selector);
|
||||
}
|
||||
|
||||
MenuItemImage * MenuItemImage::create(const char *normalImage, const char *selectedImage, const ccMenuCallback& callback)
|
||||
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, const ccMenuCallback& callback)
|
||||
{
|
||||
return MenuItemImage::create(normalImage, selectedImage, NULL, callback);
|
||||
return MenuItemImage::create(normalImage, selectedImage, "", callback);
|
||||
}
|
||||
|
||||
// XXX deprecated
|
||||
MenuItemImage * MenuItemImage::create(const char *normalImage, const char *selectedImage, const char *disabledImage, Object* target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItemImage *pRet = new MenuItemImage();
|
||||
if (pRet && pRet->initWithNormalImage(normalImage, selectedImage, disabledImage, target, selector))
|
||||
MenuItemImage *ret = new MenuItemImage();
|
||||
if (ret && ret->initWithNormalImage(normalImage, selectedImage, disabledImage, target, selector))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MenuItemImage * MenuItemImage::create(const char *normalImage, const char *selectedImage, const char *disabledImage, const ccMenuCallback& callback)
|
||||
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, const ccMenuCallback& callback)
|
||||
{
|
||||
MenuItemImage *pRet = new MenuItemImage();
|
||||
if (pRet && pRet->initWithNormalImage(normalImage, selectedImage, disabledImage, callback))
|
||||
MenuItemImage *ret = new MenuItemImage();
|
||||
if (ret && ret->initWithNormalImage(normalImage, selectedImage, disabledImage, callback))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MenuItemImage * MenuItemImage::create(const char *normalImage, const char *selectedImage, const char *disabledImage)
|
||||
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage)
|
||||
{
|
||||
MenuItemImage *pRet = new MenuItemImage();
|
||||
if (pRet && pRet->initWithNormalImage(normalImage, selectedImage, disabledImage, (const ccMenuCallback&)nullptr))
|
||||
MenuItemImage *ret = new MenuItemImage();
|
||||
if (ret && ret->initWithNormalImage(normalImage, selectedImage, disabledImage, (const ccMenuCallback&)nullptr))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -762,23 +760,23 @@ bool MenuItemImage::initWithNormalImage(const char *normalImage, const char *sel
|
|||
CC_SAFE_RETAIN(_target);
|
||||
return initWithNormalImage(normalImage, selectedImage, disabledImage, std::bind(selector,target, std::placeholders::_1) );
|
||||
}
|
||||
bool MenuItemImage::initWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, const ccMenuCallback& callback)
|
||||
bool MenuItemImage::initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, const ccMenuCallback& callback)
|
||||
{
|
||||
Node *normalSprite = NULL;
|
||||
Node *selectedSprite = NULL;
|
||||
Node *disabledSprite = NULL;
|
||||
|
||||
if (normalImage)
|
||||
if (normalImage.size() >0)
|
||||
{
|
||||
normalSprite = Sprite::create(normalImage);
|
||||
}
|
||||
|
||||
if (selectedImage)
|
||||
if (selectedImage.size() >0)
|
||||
{
|
||||
selectedSprite = Sprite::create(selectedImage);
|
||||
}
|
||||
|
||||
if(disabledImage)
|
||||
if(disabledImage.size() >0)
|
||||
{
|
||||
disabledSprite = Sprite::create(disabledImage);
|
||||
}
|
||||
|
@ -810,38 +808,38 @@ void MenuItemImage::setDisabledSpriteFrame(SpriteFrame * frame)
|
|||
// XXX: deprecated
|
||||
MenuItemToggle * MenuItemToggle::createWithTarget(Object* target, SEL_MenuHandler selector, Array* menuItems)
|
||||
{
|
||||
MenuItemToggle *pRet = new MenuItemToggle();
|
||||
pRet->MenuItem::initWithTarget(target, selector);
|
||||
pRet->_subItems = Array::create();
|
||||
pRet->_subItems->retain();
|
||||
MenuItemToggle *ret = new MenuItemToggle();
|
||||
ret->MenuItem::initWithTarget(target, selector);
|
||||
ret->_subItems = Array::create();
|
||||
ret->_subItems->retain();
|
||||
|
||||
for (int z=0; z < menuItems->count(); z++)
|
||||
{
|
||||
MenuItem* menuItem = (MenuItem*)menuItems->getObjectAtIndex(z);
|
||||
pRet->_subItems->addObject(menuItem);
|
||||
ret->_subItems->addObject(menuItem);
|
||||
}
|
||||
|
||||
pRet->_selectedIndex = UINT_MAX;
|
||||
pRet->setSelectedIndex(0);
|
||||
return pRet;
|
||||
ret->_selectedIndex = UINT_MAX;
|
||||
ret->setSelectedIndex(0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
MenuItemToggle * MenuItemToggle::createWithCallback(const ccMenuCallback &callback, Array* menuItems)
|
||||
{
|
||||
MenuItemToggle *pRet = new MenuItemToggle();
|
||||
pRet->MenuItem::initWithCallback(callback);
|
||||
pRet->_subItems = Array::create();
|
||||
pRet->_subItems->retain();
|
||||
MenuItemToggle *ret = new MenuItemToggle();
|
||||
ret->MenuItem::initWithCallback(callback);
|
||||
ret->_subItems = Array::create();
|
||||
ret->_subItems->retain();
|
||||
|
||||
for (int z=0; z < menuItems->count(); z++)
|
||||
{
|
||||
MenuItem* menuItem = (MenuItem*)menuItems->getObjectAtIndex(z);
|
||||
pRet->_subItems->addObject(menuItem);
|
||||
ret->_subItems->addObject(menuItem);
|
||||
}
|
||||
|
||||
pRet->_selectedIndex = UINT_MAX;
|
||||
pRet->setSelectedIndex(0);
|
||||
return pRet;
|
||||
ret->_selectedIndex = UINT_MAX;
|
||||
ret->setSelectedIndex(0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// XXX: deprecated
|
||||
|
@ -849,30 +847,30 @@ MenuItemToggle * MenuItemToggle::createWithTarget(Object* target, SEL_MenuHandle
|
|||
{
|
||||
va_list args;
|
||||
va_start(args, item);
|
||||
MenuItemToggle *pRet = new MenuItemToggle();
|
||||
pRet->initWithTarget(target, selector, item, args);
|
||||
pRet->autorelease();
|
||||
MenuItemToggle *ret = new MenuItemToggle();
|
||||
ret->initWithTarget(target, selector, item, args);
|
||||
ret->autorelease();
|
||||
va_end(args);
|
||||
return pRet;
|
||||
return ret;
|
||||
}
|
||||
|
||||
MenuItemToggle * MenuItemToggle::createWithCallback(const ccMenuCallback &callback, MenuItem* item, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, item);
|
||||
MenuItemToggle *pRet = new MenuItemToggle();
|
||||
pRet->initWithCallback(callback, item, args);
|
||||
pRet->autorelease();
|
||||
MenuItemToggle *ret = new MenuItemToggle();
|
||||
ret->initWithCallback(callback, item, args);
|
||||
ret->autorelease();
|
||||
va_end(args);
|
||||
return pRet;
|
||||
return ret;
|
||||
}
|
||||
|
||||
MenuItemToggle * MenuItemToggle::create()
|
||||
{
|
||||
MenuItemToggle *pRet = new MenuItemToggle();
|
||||
pRet->initWithItem(NULL);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItemToggle *ret = new MenuItemToggle();
|
||||
ret->initWithItem(NULL);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// XXX: deprecated
|
||||
|
@ -903,10 +901,10 @@ bool MenuItemToggle::initWithCallback(const ccMenuCallback &callback, MenuItem *
|
|||
|
||||
MenuItemToggle* MenuItemToggle::create(MenuItem *item)
|
||||
{
|
||||
MenuItemToggle *pRet = new MenuItemToggle();
|
||||
pRet->initWithItem(item);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
MenuItemToggle *ret = new MenuItemToggle();
|
||||
ret->initWithItem(item);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool MenuItemToggle::initWithItem(MenuItem *item)
|
||||
|
|
|
@ -166,7 +166,7 @@ public:
|
|||
CC_DEPRECATED_ATTRIBUTE bool initWithLabel(Node* label, Object* target, SEL_MenuHandler selector);
|
||||
|
||||
/** sets a new string to the inner label */
|
||||
void setString(const char * label);
|
||||
void setString(const std::string& label);
|
||||
|
||||
/** Gets the color that will be used to disable the item */
|
||||
inline const Color3B& getDisabledColor() const { return _disabledColor; };
|
||||
|
@ -204,11 +204,11 @@ class CC_DLL MenuItemAtlasFont : public MenuItemLabel
|
|||
{
|
||||
public:
|
||||
/** creates a menu item from a string and atlas with a target/selector */
|
||||
static MenuItemAtlasFont* create(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap);
|
||||
static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap);
|
||||
/** creates a menu item from a string and atlas. Use it with MenuItemToggle */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemAtlasFont* create(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemAtlasFont* create(const char* value, const char* charMapFile, long itemWidth, long itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item from a string and atlas. Use it with MenuItemToggle */
|
||||
static MenuItemAtlasFont* create(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback);
|
||||
static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback);
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
|
@ -220,9 +220,9 @@ public:
|
|||
virtual ~MenuItemAtlasFont(){}
|
||||
|
||||
/** initializes a menu item from a string and atlas with a target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithString(const char *value, const char *charMapFile, long itemWidth, long itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector);
|
||||
/** initializes a menu item from a string and atlas with a target/selector */
|
||||
bool initWithString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback);
|
||||
bool initWithString(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback);
|
||||
};
|
||||
|
||||
|
||||
|
@ -233,11 +233,11 @@ class CC_DLL MenuItemFont : public MenuItemLabel
|
|||
{
|
||||
public:
|
||||
/** creates a menu item from a string without target/selector. To be used with MenuItemToggle */
|
||||
static MenuItemFont * create(const char *value);
|
||||
static MenuItemFont * create(const std::string& value);
|
||||
/** creates a menu item from a string with a target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemFont * create(const char *value, Object* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item from a string with a target/selector */
|
||||
static MenuItemFont * create(const char *value, const ccMenuCallback& callback);
|
||||
static MenuItemFont * create(const std::string& value, const ccMenuCallback& callback);
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
|
@ -251,30 +251,30 @@ public:
|
|||
/** initializes a menu item from a string with a target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithString(const char *value, Object* target, SEL_MenuHandler selector);
|
||||
/** initializes a menu item from a string with a target/selector */
|
||||
bool initWithString(const char *value, const ccMenuCallback& callback);
|
||||
bool initWithString(const std::string& value, const ccMenuCallback& callback);
|
||||
|
||||
/** set default font size */
|
||||
static void setFontSize(unsigned int s);
|
||||
static void setFontSize(long size);
|
||||
/** get default font size */
|
||||
static unsigned int getFontSize();
|
||||
static long getFontSize();
|
||||
CC_DEPRECATED_ATTRIBUTE static unsigned int fontSize() { return MenuItemFont::getFontSize(); };
|
||||
/** set the default font name */
|
||||
static void setFontName(const char *name);
|
||||
static void setFontName(const std::string& name);
|
||||
/** get the default font name */
|
||||
static const char *getFontName();
|
||||
CC_DEPRECATED_ATTRIBUTE static const char *fontName() { return MenuItemFont::getFontName(); };
|
||||
static const std::string& getFontName();
|
||||
CC_DEPRECATED_ATTRIBUTE static const std::string& fontName() { return MenuItemFont::getFontName(); };
|
||||
|
||||
/** set font size
|
||||
* c++ can not overload static and non-static member functions with the same parameter types
|
||||
* so change the name to setFontSizeObj
|
||||
* @js setFontSize
|
||||
*/
|
||||
void setFontSizeObj(unsigned int s);
|
||||
void setFontSizeObj(long size);
|
||||
|
||||
/** get font size
|
||||
* @js getFontSize
|
||||
*/
|
||||
unsigned int getFontSizeObj() const;
|
||||
long getFontSizeObj() const;
|
||||
CC_DEPRECATED_ATTRIBUTE unsigned int fontSizeObj() const { return getFontSizeObj(); };
|
||||
|
||||
/** set the font name
|
||||
|
@ -282,20 +282,20 @@ public:
|
|||
* so change the name to setFontNameObj
|
||||
* @js setFontName
|
||||
*/
|
||||
void setFontNameObj(const char* name);
|
||||
void setFontNameObj(const std::string& name);
|
||||
|
||||
/** returns the name of the Font
|
||||
* @js getFontNameObj
|
||||
*/
|
||||
const char* getFontNameObj() const;
|
||||
const std::string& getFontNameObj() const;
|
||||
|
||||
/** deprecated Use getFontNameObj() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE const char* fontNameObj() const { return getFontNameObj(); }
|
||||
CC_DEPRECATED_ATTRIBUTE const std::string& fontNameObj() const { return getFontNameObj(); }
|
||||
|
||||
protected:
|
||||
void recreateLabel();
|
||||
|
||||
unsigned int _fontSize;
|
||||
long _fontSize;
|
||||
std::string _fontName;
|
||||
};
|
||||
|
||||
|
@ -384,18 +384,18 @@ public:
|
|||
/** Creates an MenuItemImage. */
|
||||
static MenuItemImage* create();
|
||||
/** creates a menu item with a normal and selected image*/
|
||||
static MenuItemImage* create(const char *normalImage, const char *selectedImage);
|
||||
static MenuItemImage* create(const std::string& normalImage, const std::string& selectedImage);
|
||||
/** creates a menu item with a normal,selected and disabled image*/
|
||||
static MenuItemImage* create(const char *normalImage, const char *selectedImage, const char *disabledImage);
|
||||
static MenuItemImage* create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage);
|
||||
/** creates a menu item with a normal and selected image with target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const char *normalImage, const char *selectedImage, Object* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item with a normal and selected image with a callable object */
|
||||
static MenuItemImage* create(const char *normalImage, const char *selectedImage, const ccMenuCallback& callback);
|
||||
static MenuItemImage* create(const std::string&normalImage, const std::string&selectedImage, const ccMenuCallback& callback);
|
||||
|
||||
/** creates a menu item with a normal,selected and disabled image with target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const char *normalImage, const char *selectedImage, const char *disabledImage, Object* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item with a normal,selected and disabled image with a callable object */
|
||||
static MenuItemImage* create(const char *normalImage, const char *selectedImage, const char *disabledImage, const ccMenuCallback& callback);
|
||||
static MenuItemImage* create(const std::string&normalImage, const std::string&selectedImage, const std::string&disabledImage, const ccMenuCallback& callback);
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
|
@ -410,7 +410,7 @@ public:
|
|||
/** initializes a menu item with a normal, selected and disabled image with target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, Object* target, SEL_MenuHandler selector);
|
||||
/** initializes a menu item with a normal, selected and disabled image with a callable object */
|
||||
bool initWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, const ccMenuCallback& callback);
|
||||
bool initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, const ccMenuCallback& callback);
|
||||
|
||||
/** sets the sprite frame for the normal image */
|
||||
void setNormalSpriteFrame(SpriteFrame* frame);
|
||||
|
|
|
@ -136,7 +136,7 @@ ParticleSystem::ParticleSystem()
|
|||
}
|
||||
// implementation ParticleSystem
|
||||
|
||||
ParticleSystem * ParticleSystem::create(const char *plistFile)
|
||||
ParticleSystem * ParticleSystem::create(const std::string& plistFile)
|
||||
{
|
||||
ParticleSystem *pRet = new ParticleSystem();
|
||||
if (pRet && pRet->initWithFile(plistFile))
|
||||
|
@ -165,7 +165,7 @@ bool ParticleSystem::init()
|
|||
return initWithTotalParticles(150);
|
||||
}
|
||||
|
||||
bool ParticleSystem::initWithFile(const char *plistFile)
|
||||
bool ParticleSystem::initWithFile(const std::string& plistFile)
|
||||
{
|
||||
bool bRet = false;
|
||||
_plistFile = FileUtils::getInstance()->fullPathForFilename(plistFile);
|
||||
|
@ -195,7 +195,7 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary)
|
|||
return initWithDictionary(dictionary, "");
|
||||
}
|
||||
|
||||
bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const char *dirname)
|
||||
bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::string& dirname)
|
||||
{
|
||||
bool bRet = false;
|
||||
unsigned char *buffer = NULL;
|
||||
|
@ -353,17 +353,17 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const char *dirn
|
|||
{
|
||||
string textureDir = textureName.substr(0, rPos + 1);
|
||||
|
||||
if (dirname != NULL && textureDir != dirname)
|
||||
if (dirname.size()>0 && textureDir != dirname)
|
||||
{
|
||||
textureName = textureName.substr(rPos+1);
|
||||
textureName = string(dirname) + textureName;
|
||||
textureName = dirname + textureName;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dirname != NULL)
|
||||
if (dirname.size()>0)
|
||||
{
|
||||
textureName = string(dirname) + textureName;
|
||||
textureName = dirname + textureName;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ public:
|
|||
http://particledesigner.71squared.com/
|
||||
@since v2.0
|
||||
*/
|
||||
static ParticleSystem * create(const char *plistFile);
|
||||
static ParticleSystem * create(const std::string& plistFile);
|
||||
|
||||
//! create a system with a fixed number of particles
|
||||
static ParticleSystem* createWithTotalParticles(unsigned int numberOfParticles);
|
||||
|
@ -188,7 +188,7 @@ public:
|
|||
http://particledesigner.71squared.com/
|
||||
@since v0.99.3
|
||||
*/
|
||||
bool initWithFile(const char *plistFile);
|
||||
bool initWithFile(const std::string& plistFile);
|
||||
|
||||
/** initializes a QuadParticleSystem from a Dictionary.
|
||||
@since v0.99.3
|
||||
|
@ -198,7 +198,7 @@ public:
|
|||
/** initializes a particle system from a NSDictionary and the path from where to load the png
|
||||
@since v2.1
|
||||
*/
|
||||
bool initWithDictionary(Dictionary *dictionary, const char *dirname);
|
||||
bool initWithDictionary(Dictionary *dictionary, const std::string& dirname);
|
||||
|
||||
//! Initializes a system with a fixed number of particles
|
||||
virtual bool initWithTotalParticles(unsigned int numberOfParticles);
|
||||
|
|
|
@ -125,7 +125,7 @@ const char* ProfilingTimer::description() const
|
|||
{
|
||||
static char s_desciption[512] = {0};
|
||||
|
||||
sprintf(s_desciption, "%s ::\tavg1: %dµ,\tavg2: %dµ,\tmin: %dµ,\tmax: %dµ,\ttotal: %.2fs,\tnr calls: %d", _nameStr.c_str(), _averageTime1, _averageTime2, minTime, maxTime, totalTime/1000000., numberOfCalls);
|
||||
sprintf(s_desciption, "%s ::\tavg1: %ldµ,\tavg2: %ldµ,\tmin: %ldµ,\tmax: %ldµ,\ttotal: %.2fs,\tnr calls: %ld", _nameStr.c_str(), _averageTime1, _averageTime2, minTime, maxTime, totalTime/1000000., numberOfCalls);
|
||||
return s_desciption;
|
||||
}
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void setString(const char *label) = 0;
|
||||
virtual void setString(const std::string &label) = 0;
|
||||
|
||||
/**
|
||||
* Returns the string that is currently being used in this label
|
||||
|
@ -238,7 +238,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual const char* getString() const = 0;
|
||||
virtual const std::string& getString() const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -68,18 +68,14 @@ public:
|
|||
#ifdef CC_USE_PHYSICS
|
||||
public:
|
||||
bool initWithPhysics();
|
||||
|
||||
|
||||
inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; }
|
||||
|
||||
virtual void addChild(Node* child) override;
|
||||
virtual void addChild(Node* child, int zOrder) override;
|
||||
virtual void addChild(Node* child, int zOrder, int tag) override;
|
||||
|
||||
/*
|
||||
* Update method will be called automatically every frame if "scheduleUpdate" is called, and the node is "live"
|
||||
*/
|
||||
virtual void update(float delta) override;
|
||||
|
||||
inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; }
|
||||
|
||||
virtual void update(float delta) override;
|
||||
|
||||
protected:
|
||||
virtual void addChildToPhysicsWorld(Node* child);
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ Sprite* Sprite::createWithTexture(Texture2D *texture, const Rect& rect)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
Sprite* Sprite::create(const char *filename)
|
||||
Sprite* Sprite::create(const std::string& filename)
|
||||
{
|
||||
Sprite *sprite = new Sprite();
|
||||
if (sprite && sprite->initWithFile(filename))
|
||||
|
@ -94,7 +94,7 @@ Sprite* Sprite::create(const char *filename)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
Sprite* Sprite::create(const char *filename, const Rect& rect)
|
||||
Sprite* Sprite::create(const std::string& filename, const Rect& rect)
|
||||
{
|
||||
Sprite *sprite = new Sprite();
|
||||
if (sprite && sprite->initWithFile(filename, rect))
|
||||
|
@ -118,13 +118,13 @@ Sprite* Sprite::createWithSpriteFrame(SpriteFrame *spriteFrame)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
Sprite* Sprite::createWithSpriteFrameName(const char *spriteFrameName)
|
||||
Sprite* Sprite::createWithSpriteFrameName(const std::string& spriteFrameName)
|
||||
{
|
||||
SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName);
|
||||
|
||||
#if COCOS2D_DEBUG > 0
|
||||
char msg[256] = {0};
|
||||
sprintf(msg, "Invalid spriteFrameName: %s", spriteFrameName);
|
||||
sprintf(msg, "Invalid spriteFrameName: %s", spriteFrameName.c_str());
|
||||
CCASSERT(frame != NULL, msg);
|
||||
#endif
|
||||
|
||||
|
@ -215,9 +215,9 @@ bool Sprite::initWithTexture(Texture2D *texture)
|
|||
return initWithTexture(texture, rect);
|
||||
}
|
||||
|
||||
bool Sprite::initWithFile(const char *filename)
|
||||
bool Sprite::initWithFile(const std::string& filename)
|
||||
{
|
||||
CCASSERT(filename != NULL, "Invalid filename for sprite");
|
||||
CCASSERT(filename.size()>0, "Invalid filename for sprite");
|
||||
|
||||
Texture2D *texture = TextureCache::getInstance()->addImage(filename);
|
||||
if (texture)
|
||||
|
@ -233,9 +233,9 @@ bool Sprite::initWithFile(const char *filename)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Sprite::initWithFile(const char *filename, const Rect& rect)
|
||||
bool Sprite::initWithFile(const std::string &filename, const Rect& rect)
|
||||
{
|
||||
CCASSERT(filename != NULL, "");
|
||||
CCASSERT(filename.size()>0, "Invalid filename");
|
||||
|
||||
Texture2D *texture = TextureCache::getInstance()->addImage(filename);
|
||||
if (texture)
|
||||
|
@ -259,9 +259,9 @@ bool Sprite::initWithSpriteFrame(SpriteFrame *spriteFrame)
|
|||
return bRet;
|
||||
}
|
||||
|
||||
bool Sprite::initWithSpriteFrameName(const char *spriteFrameName)
|
||||
bool Sprite::initWithSpriteFrameName(const std::string& spriteFrameName)
|
||||
{
|
||||
CCASSERT(spriteFrameName != NULL, "");
|
||||
CCASSERT(spriteFrameName.size() > 0, "Invalid spriteFrameName");
|
||||
|
||||
SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName);
|
||||
return initWithSpriteFrame(frame);
|
||||
|
@ -840,6 +840,12 @@ void Sprite::setScale(float fScale)
|
|||
SET_DIRTY_RECURSIVELY();
|
||||
}
|
||||
|
||||
void Sprite::setScale(float scaleX, float scaleY)
|
||||
{
|
||||
Node::setScale(scaleX, scaleY);
|
||||
SET_DIRTY_RECURSIVELY();
|
||||
}
|
||||
|
||||
void Sprite::setVertexZ(float fVertexZ)
|
||||
{
|
||||
Node::setVertexZ(fVertexZ);
|
||||
|
@ -992,9 +998,9 @@ void Sprite::setDisplayFrame(SpriteFrame *pNewFrame)
|
|||
setTextureRect(pNewFrame->getRect(), _rectRotated, pNewFrame->getOriginalSize());
|
||||
}
|
||||
|
||||
void Sprite::setDisplayFrameWithAnimationName(const char *animationName, int frameIndex)
|
||||
void Sprite::setDisplayFrameWithAnimationName(const std::string& animationName, int frameIndex)
|
||||
{
|
||||
CCASSERT(animationName, "CCSprite#setDisplayFrameWithAnimationName. animationName must not be NULL");
|
||||
CCASSERT(animationName.size()>0, "CCSprite#setDisplayFrameWithAnimationName. animationName must not be NULL");
|
||||
|
||||
Animation *a = AnimationCache::getInstance()->getAnimation(animationName);
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __SPITE_NODE_CCSPRITE_H__
|
||||
#define __SPITE_NODE_CCSPRITE_H__
|
||||
#ifndef __SPRITE_NODE_CCSPRITE_H__
|
||||
#define __SPRITE_NODE_CCSPRITE_H__
|
||||
|
||||
#include "CCNode.h"
|
||||
#include "CCProtocols.h"
|
||||
|
@ -54,7 +54,7 @@ struct transformValues_;
|
|||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) )
|
||||
*
|
||||
* Sprite can be created with an image, or with a sub-rectangle of an image.
|
||||
|
@ -88,14 +88,14 @@ public:
|
|||
|
||||
/// @{
|
||||
/// @name Creators
|
||||
|
||||
|
||||
/**
|
||||
* Creates an empty sprite without texture. You can call setTexture method subsequently.
|
||||
*
|
||||
* @return An empty sprite object that is marked as autoreleased.
|
||||
*/
|
||||
static Sprite* create();
|
||||
|
||||
|
||||
/**
|
||||
* Creates a sprite with an image filename.
|
||||
*
|
||||
|
@ -105,8 +105,8 @@ public:
|
|||
* @param filename The string which indicates a path to image file, e.g., "scene1/monster.png".
|
||||
* @return A valid sprite object that is marked as autoreleased.
|
||||
*/
|
||||
static Sprite* create(const char *filename);
|
||||
|
||||
static Sprite* create(const std::string& filename);
|
||||
|
||||
/**
|
||||
* Creates a sprite with an image filename and a rect.
|
||||
*
|
||||
|
@ -114,8 +114,8 @@ public:
|
|||
* @param rect Only the contents inside rect of filename's texture will be applied for this sprite.
|
||||
* @return A valid sprite object that is marked as autoreleased.
|
||||
*/
|
||||
static Sprite* create(const char *filename, const Rect& rect);
|
||||
|
||||
static Sprite* create(const std::string& filename, const Rect& rect);
|
||||
|
||||
/**
|
||||
* Creates a sprite with an exsiting texture contained in a Texture2D object
|
||||
* After creation, the rect will be the size of the texture, and the offset will be (0,0).
|
||||
|
@ -124,7 +124,7 @@ public:
|
|||
* @return A valid sprite object that is marked as autoreleased.
|
||||
*/
|
||||
static Sprite* createWithTexture(Texture2D *texture);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a sprite with a texture and a rect.
|
||||
*
|
||||
|
@ -136,7 +136,7 @@ public:
|
|||
* @return A valid sprite object that is marked as autoreleased.
|
||||
*/
|
||||
static Sprite* createWithTexture(Texture2D *texture, const Rect& rect);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a sprite with an sprite frame.
|
||||
*
|
||||
|
@ -144,7 +144,7 @@ public:
|
|||
* @return A valid sprite object that is marked as autoreleased.
|
||||
*/
|
||||
static Sprite* createWithSpriteFrame(SpriteFrame *pSpriteFrame);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a sprite with an sprite frame name.
|
||||
*
|
||||
|
@ -154,32 +154,32 @@ public:
|
|||
* @param spriteFrameName A null terminated string which indicates the sprite frame name.
|
||||
* @return A valid sprite object that is marked as autoreleased.
|
||||
*/
|
||||
static Sprite* createWithSpriteFrameName(const char *spriteFrameName);
|
||||
|
||||
static Sprite* createWithSpriteFrameName(const std::string& spriteFrameName);
|
||||
|
||||
/// @} end of creators group
|
||||
|
||||
|
||||
|
||||
|
||||
/// @{
|
||||
/// @name Initializers
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
* @js ctor
|
||||
*/
|
||||
Sprite(void);
|
||||
|
||||
|
||||
/**
|
||||
* Default destructor
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual ~Sprite(void);
|
||||
|
||||
|
||||
/**
|
||||
* Initializes an empty sprite with nothing init.
|
||||
*/
|
||||
virtual bool init(void);
|
||||
|
||||
|
||||
/**
|
||||
* Initializes a sprite with a texture.
|
||||
*
|
||||
|
@ -190,7 +190,7 @@ public:
|
|||
* @return true if the sprite is initialized properly, false otherwise.
|
||||
*/
|
||||
virtual bool initWithTexture(Texture2D *texture);
|
||||
|
||||
|
||||
/**
|
||||
* Initializes a sprite with a texture and a rect.
|
||||
*
|
||||
|
@ -202,7 +202,7 @@ public:
|
|||
* @return true if the sprite is initialized properly, false otherwise.
|
||||
*/
|
||||
virtual bool initWithTexture(Texture2D *texture, const Rect& rect);
|
||||
|
||||
|
||||
/**
|
||||
* Initializes a sprite with a texture and a rect in points, optionally rotated.
|
||||
*
|
||||
|
@ -215,7 +215,7 @@ public:
|
|||
* @return true if the sprite is initialized properly, false otherwise.
|
||||
*/
|
||||
virtual bool initWithTexture(Texture2D *texture, const Rect& rect, bool rotated);
|
||||
|
||||
|
||||
/**
|
||||
* Initializes a sprite with an SpriteFrame. The texture and rect in SpriteFrame will be applied on this sprite
|
||||
*
|
||||
|
@ -223,7 +223,7 @@ public:
|
|||
* @return true if the sprite is initialized properly, false otherwise.
|
||||
*/
|
||||
virtual bool initWithSpriteFrame(SpriteFrame *pSpriteFrame);
|
||||
|
||||
|
||||
/**
|
||||
* Initializes a sprite with an sprite frame name.
|
||||
*
|
||||
|
@ -233,8 +233,8 @@ public:
|
|||
* @param spriteFrameName A key string that can fected a volid SpriteFrame from SpriteFrameCache
|
||||
* @return true if the sprite is initialized properly, false otherwise.
|
||||
*/
|
||||
virtual bool initWithSpriteFrameName(const char *spriteFrameName);
|
||||
|
||||
virtual bool initWithSpriteFrameName(const std::string& spriteFrameName);
|
||||
|
||||
/**
|
||||
* Initializes a sprite with an image filename.
|
||||
*
|
||||
|
@ -247,8 +247,8 @@ public:
|
|||
* @js init
|
||||
* @lua init
|
||||
*/
|
||||
virtual bool initWithFile(const char *filename);
|
||||
|
||||
virtual bool initWithFile(const std::string& filename);
|
||||
|
||||
/**
|
||||
* Initializes a sprite with an image filename, and a rect.
|
||||
*
|
||||
|
@ -262,18 +262,18 @@ public:
|
|||
* @js init
|
||||
* @lua init
|
||||
*/
|
||||
virtual bool initWithFile(const char *filename, const Rect& rect);
|
||||
|
||||
virtual bool initWithFile(const std::string& filename, const Rect& rect);
|
||||
|
||||
/// @} end of initializers
|
||||
|
||||
/// @{
|
||||
/// @name BatchNode methods
|
||||
|
||||
|
||||
/**
|
||||
* Updates the quad according the rotation, position, scale values.
|
||||
* Updates the quad according the rotation, position, scale values.
|
||||
*/
|
||||
virtual void updateTransform(void);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the batch node object if this sprite is rendered by SpriteBatchNode
|
||||
*
|
||||
|
@ -292,26 +292,26 @@ public:
|
|||
* @endcode
|
||||
*/
|
||||
virtual void setBatchNode(SpriteBatchNode *spriteBatchNode);
|
||||
|
||||
|
||||
/// @} end of BatchNode methods
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// @{
|
||||
/// @name Texture methods
|
||||
|
||||
|
||||
/**
|
||||
* Updates the texture rect of the Sprite in points.
|
||||
* It will call setTextureRect(const Rect& rect, bool rotated, const Size& untrimmedSize) with \p rotated = false, and \p utrimmedSize = rect.size.
|
||||
*/
|
||||
virtual void setTextureRect(const Rect& rect);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the texture rect, rectRotated and untrimmed size of the Sprite in points.
|
||||
* It will update the texture coordinates and the vertex rectangle.
|
||||
*/
|
||||
virtual void setTextureRect(const Rect& rect, bool rotated, const Size& untrimmedSize);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the vertex rect.
|
||||
* It will be called internally by setTextureRect.
|
||||
|
@ -319,34 +319,34 @@ public:
|
|||
* Do not call it manually. Use setTextureRect instead.
|
||||
*/
|
||||
virtual void setVertexRect(const Rect& rect);
|
||||
|
||||
/// @} end of texture methods
|
||||
|
||||
|
||||
|
||||
/// @} end of texture methods
|
||||
|
||||
|
||||
|
||||
/// @{
|
||||
/// @name Frames methods
|
||||
|
||||
|
||||
/**
|
||||
* Sets a new display frame to the Sprite.
|
||||
*/
|
||||
virtual void setDisplayFrame(SpriteFrame *pNewFrame);
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether or not a SpriteFrame is being displayed
|
||||
*/
|
||||
virtual bool isFrameDisplayed(SpriteFrame *pFrame) const;
|
||||
|
||||
|
||||
/** @deprecated Use getDisplayFrame() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE virtual SpriteFrame* displayFrame() { return getDisplayFrame(); };
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current displayed frame.
|
||||
*/
|
||||
virtual SpriteFrame* getDisplayFrame();
|
||||
|
||||
|
||||
/// @} End of frames methods
|
||||
|
||||
|
||||
|
||||
/// @{
|
||||
/// @name Animation methods
|
||||
|
@ -354,25 +354,25 @@ public:
|
|||
* Changes the display frame with animation name and index.
|
||||
* The animation name will be get from the AnimationCache
|
||||
*/
|
||||
virtual void setDisplayFrameWithAnimationName(const char *animationName, int frameIndex);
|
||||
virtual void setDisplayFrameWithAnimationName(const std::string& animationName, int frameIndex);
|
||||
/// @}
|
||||
|
||||
|
||||
|
||||
|
||||
/// @{
|
||||
/// @name Sprite Properties' setter/getters
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Whether or not the Sprite needs to be updated in the Atlas.
|
||||
*
|
||||
* @return true if the sprite needs to be updated in the Atlas, false otherwise.
|
||||
*/
|
||||
virtual bool isDirty(void) const { return _dirty; }
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Makes the Sprite to be updated in the Atlas.
|
||||
*/
|
||||
virtual void setDirty(bool bDirty) { _dirty = bDirty; }
|
||||
|
||||
|
||||
/**
|
||||
* Returns the quad (tex coords, vertex coords and color) information.
|
||||
* @js NA
|
||||
|
@ -380,24 +380,24 @@ public:
|
|||
*/
|
||||
inline V3F_C4B_T2F_Quad getQuad(void) const { return _quad; }
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns whether or not the texture rectangle is rotated.
|
||||
*/
|
||||
inline bool isTextureRectRotated(void) const { return _rectRotated; }
|
||||
|
||||
/**
|
||||
* Returns the index used on the TextureAtlas.
|
||||
|
||||
/**
|
||||
* Returns the index used on the TextureAtlas.
|
||||
*/
|
||||
inline int getAtlasIndex(void) const { return _atlasIndex; }
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Sets the index used on the TextureAtlas.
|
||||
* @warning Don't modify this value unless you know what you are doing
|
||||
*/
|
||||
inline void setAtlasIndex(int atlasIndex) { _atlasIndex = atlasIndex; }
|
||||
|
||||
/**
|
||||
* Returns the rect of the Sprite in points
|
||||
/**
|
||||
* Returns the rect of the Sprite in points
|
||||
*/
|
||||
inline const Rect& getTextureRect(void) { return _rect; }
|
||||
|
||||
|
@ -405,19 +405,19 @@ public:
|
|||
* Gets the weak reference of the TextureAtlas when the sprite is rendered using via SpriteBatchNode
|
||||
*/
|
||||
inline TextureAtlas* getTextureAtlas(void) { return _textureAtlas; }
|
||||
|
||||
|
||||
/**
|
||||
* Sets the weak reference of the TextureAtlas when the sprite is rendered using via SpriteBatchNode
|
||||
*/
|
||||
inline void setTextureAtlas(TextureAtlas *pobTextureAtlas) { _textureAtlas = pobTextureAtlas; }
|
||||
|
||||
/**
|
||||
/**
|
||||
* Gets the offset position of the sprite. Calculated automatically by editors like Zwoptex.
|
||||
*/
|
||||
inline const Point& getOffsetPosition(void) const { return _offsetPosition; }
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns the flag which indicates whether the sprite is flipped horizontally or not.
|
||||
*
|
||||
* It only flips the texture of the sprite, and not the texture of the sprite's children.
|
||||
|
@ -425,48 +425,48 @@ public:
|
|||
* If you want to flip the anchorPoint too, and/or to flip the children too use:
|
||||
* sprite->setScaleX(sprite->getScaleX() * -1);
|
||||
*
|
||||
* @return true if the sprite is flipped horizaontally, false otherwise.
|
||||
* @return true if the sprite is flipped horizontally, false otherwise.
|
||||
*/
|
||||
bool isFlippedX(void) const;
|
||||
/**
|
||||
* Sets whether the sprite should be flipped horizontally or not.
|
||||
*
|
||||
* @param bFlipX true if the sprite should be flipped horizaontally, false otherwise.
|
||||
* @param flippedX true if the sprite should be flipped horizontally, false otherwise.
|
||||
*/
|
||||
void setFlippedX(bool flippedX);
|
||||
|
||||
/** @deprecated Use isFlippedX() instead
|
||||
|
||||
/** @deprecated Use isFlippedX() instead
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE bool isFlipX() { return isFlippedX(); };
|
||||
/** @deprecated Use setFlippedX() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE void setFlipX(bool flippedX) { setFlippedX(flippedX); };
|
||||
|
||||
/**
|
||||
CC_DEPRECATED_ATTRIBUTE void setFlipX(bool flippedX) { setFlippedX(flippedX); };
|
||||
|
||||
/**
|
||||
* Return the flag which indicates whether the sprite is flipped vertically or not.
|
||||
*
|
||||
*
|
||||
* It only flips the texture of the sprite, and not the texture of the sprite's children.
|
||||
* Also, flipping the texture doesn't alter the anchorPoint.
|
||||
* If you want to flip the anchorPoint too, and/or to flip the children too use:
|
||||
* sprite->setScaleY(sprite->getScaleY() * -1);
|
||||
*
|
||||
* @return true if the sprite is flipped vertically, flase otherwise.
|
||||
*
|
||||
* @return true if the sprite is flipped vertically, false otherwise.
|
||||
*/
|
||||
bool isFlippedY(void) const;
|
||||
/**
|
||||
* Sets whether the sprite should be flipped vertically or not.
|
||||
*
|
||||
* @param bFlipY true if the sprite should be flipped vertically, flase otherwise.
|
||||
* @param flippedY true if the sprite should be flipped vertically, false otherwise.
|
||||
*/
|
||||
void setFlippedY(bool flippedY);
|
||||
|
||||
|
||||
/// @} End of Sprite properties getter/setters
|
||||
|
||||
|
||||
/** @deprecated Use isFlippedY() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE bool isFlipY() { return isFlippedY(); };
|
||||
/** @deprecated Use setFlippedY() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE void setFlipY(bool flippedY) { setFlippedY(flippedY); };
|
||||
CC_DEPRECATED_ATTRIBUTE void setFlipY(bool flippedY) { setFlippedY(flippedY); };
|
||||
|
||||
//
|
||||
// Overrides
|
||||
|
@ -494,6 +494,7 @@ public:
|
|||
/// @name Functions inherited from Node
|
||||
virtual void setScaleX(float scaleX) override;
|
||||
virtual void setScaleY(float scaleY) override;
|
||||
virtual void setScale(float scaleX, float scaleY) override;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -542,13 +543,13 @@ protected:
|
|||
TextureAtlas* _textureAtlas; /// SpriteBatchNode texture atlas (weak reference)
|
||||
int _atlasIndex; /// Absolute (real) Index on the SpriteSheet
|
||||
SpriteBatchNode* _batchNode; /// Used batch node (weak reference)
|
||||
|
||||
|
||||
bool _dirty; /// Whether the sprite needs to be updated
|
||||
bool _recursiveDirty; /// Whether all of the sprite's children needs to be updated
|
||||
bool _hasChildren; /// Whether the sprite contains children
|
||||
bool _shouldBeHidden; /// should not be drawn because one of the ancestors is not visible
|
||||
AffineTransform _transformToBatch;
|
||||
|
||||
|
||||
//
|
||||
// Data used when the sprite is self-rendered
|
||||
//
|
||||
|
@ -574,8 +575,8 @@ protected:
|
|||
bool _opacityModifyRGB;
|
||||
|
||||
// image is flipped
|
||||
bool _flippedX; /// Whether the sprite is flipped horizaontally or not.
|
||||
bool _flippedY; /// Whether the sprite is flipped vertically or not.
|
||||
bool _flippedX; /// Whether the sprite is flipped horizontally or not
|
||||
bool _flippedY; /// Whether the sprite is flipped vertically or not
|
||||
};
|
||||
|
||||
|
||||
|
@ -584,4 +585,4 @@ protected:
|
|||
|
||||
NS_CC_END
|
||||
|
||||
#endif // __SPITE_NODE_CCSPRITE_H__
|
||||
#endif // __SPRITE_NODE_CCSPRITE_H__
|
||||
|
|
|
@ -31,61 +31,61 @@ NS_CC_BEGIN
|
|||
|
||||
// implementation of SpriteFrame
|
||||
|
||||
SpriteFrame* SpriteFrame::create(const char* filename, const Rect& rect)
|
||||
SpriteFrame* SpriteFrame::create(const std::string& filename, const Rect& rect)
|
||||
{
|
||||
SpriteFrame *pSpriteFrame = new SpriteFrame();;
|
||||
SpriteFrame *pSpriteFrame = new SpriteFrame();
|
||||
pSpriteFrame->initWithTextureFilename(filename, rect);
|
||||
pSpriteFrame->autorelease();
|
||||
|
||||
return pSpriteFrame;
|
||||
}
|
||||
|
||||
SpriteFrame* SpriteFrame::createWithTexture(Texture2D *pobTexture, const Rect& rect)
|
||||
SpriteFrame* SpriteFrame::createWithTexture(Texture2D *texture, const Rect& rect)
|
||||
{
|
||||
SpriteFrame *pSpriteFrame = new SpriteFrame();;
|
||||
pSpriteFrame->initWithTexture(pobTexture, rect);
|
||||
SpriteFrame *pSpriteFrame = new SpriteFrame();
|
||||
pSpriteFrame->initWithTexture(texture, rect);
|
||||
pSpriteFrame->autorelease();
|
||||
|
||||
return pSpriteFrame;
|
||||
}
|
||||
|
||||
SpriteFrame* SpriteFrame::createWithTexture(Texture2D* pobTexture, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize)
|
||||
SpriteFrame* SpriteFrame::createWithTexture(Texture2D* texture, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize)
|
||||
{
|
||||
SpriteFrame *pSpriteFrame = new SpriteFrame();;
|
||||
pSpriteFrame->initWithTexture(pobTexture, rect, rotated, offset, originalSize);
|
||||
SpriteFrame *pSpriteFrame = new SpriteFrame();
|
||||
pSpriteFrame->initWithTexture(texture, rect, rotated, offset, originalSize);
|
||||
pSpriteFrame->autorelease();
|
||||
|
||||
return pSpriteFrame;
|
||||
}
|
||||
|
||||
SpriteFrame* SpriteFrame::create(const char* filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize)
|
||||
SpriteFrame* SpriteFrame::create(const std::string& filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize)
|
||||
{
|
||||
SpriteFrame *pSpriteFrame = new SpriteFrame();;
|
||||
SpriteFrame *pSpriteFrame = new SpriteFrame();
|
||||
pSpriteFrame->initWithTextureFilename(filename, rect, rotated, offset, originalSize);
|
||||
pSpriteFrame->autorelease();
|
||||
|
||||
return pSpriteFrame;
|
||||
}
|
||||
|
||||
bool SpriteFrame::initWithTexture(Texture2D* pobTexture, const Rect& rect)
|
||||
bool SpriteFrame::initWithTexture(Texture2D* texture, const Rect& rect)
|
||||
{
|
||||
Rect rectInPixels = CC_RECT_POINTS_TO_PIXELS(rect);
|
||||
return initWithTexture(pobTexture, rectInPixels, false, Point::ZERO, rectInPixels.size);
|
||||
return initWithTexture(texture, rectInPixels, false, Point::ZERO, rectInPixels.size);
|
||||
}
|
||||
|
||||
bool SpriteFrame::initWithTextureFilename(const char* filename, const Rect& rect)
|
||||
bool SpriteFrame::initWithTextureFilename(const std::string& filename, const Rect& rect)
|
||||
{
|
||||
Rect rectInPixels = CC_RECT_POINTS_TO_PIXELS( rect );
|
||||
return initWithTextureFilename(filename, rectInPixels, false, Point::ZERO, rectInPixels.size);
|
||||
}
|
||||
|
||||
bool SpriteFrame::initWithTexture(Texture2D* pobTexture, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize)
|
||||
bool SpriteFrame::initWithTexture(Texture2D* texture, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize)
|
||||
{
|
||||
_texture = pobTexture;
|
||||
_texture = texture;
|
||||
|
||||
if (pobTexture)
|
||||
if (texture)
|
||||
{
|
||||
pobTexture->retain();
|
||||
texture->retain();
|
||||
}
|
||||
|
||||
_rectInPixels = rect;
|
||||
|
@ -99,7 +99,7 @@ bool SpriteFrame::initWithTexture(Texture2D* pobTexture, const Rect& rect, bool
|
|||
return true;
|
||||
}
|
||||
|
||||
bool SpriteFrame::initWithTextureFilename(const char* filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize)
|
||||
bool SpriteFrame::initWithTextureFilename(const std::string& filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize)
|
||||
{
|
||||
_texture = NULL;
|
||||
_textureFilename = filename;
|
||||
|
|
|
@ -58,12 +58,12 @@ public:
|
|||
/** Create a SpriteFrame with a texture filename, rect in points.
|
||||
It is assumed that the frame was not trimmed.
|
||||
*/
|
||||
static SpriteFrame* create(const char* filename, const Rect& rect);
|
||||
static SpriteFrame* create(const std::string& filename, const Rect& rect);
|
||||
|
||||
/** Create a SpriteFrame with a texture filename, rect, rotated, offset and originalSize in pixels.
|
||||
The originalSize is the size in pixels of the frame before being trimmed.
|
||||
*/
|
||||
static SpriteFrame* create(const char* filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize);
|
||||
static SpriteFrame* create(const std::string& filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize);
|
||||
|
||||
/** Create a SpriteFrame with a texture, rect in points.
|
||||
It is assumed that the frame was not trimmed.
|
||||
|
@ -88,7 +88,7 @@ public:
|
|||
/** Initializes a SpriteFrame with a texture filename, rect in points;
|
||||
It is assumed that the frame was not trimmed.
|
||||
*/
|
||||
bool initWithTextureFilename(const char* filename, const Rect& rect);
|
||||
bool initWithTextureFilename(const std::string& filename, const Rect& rect);
|
||||
|
||||
/** Initializes a SpriteFrame with a texture, rect, rotated, offset and originalSize in pixels.
|
||||
The originalSize is the size in points of the frame before being trimmed.
|
||||
|
@ -100,7 +100,7 @@ public:
|
|||
|
||||
@since v1.1
|
||||
*/
|
||||
bool initWithTextureFilename(const char* filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize);
|
||||
bool initWithTextureFilename(const std::string& filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize);
|
||||
|
||||
|
||||
// attributes
|
||||
|
|
|
@ -102,11 +102,11 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
|||
// check the format
|
||||
CCASSERT(format >=0 && format <= 3, "format is not supported for SpriteFrameCache addSpriteFramesWithDictionary:textureFilename:");
|
||||
|
||||
DictElement* pElement = NULL;
|
||||
CCDICT_FOREACH(framesDict, pElement)
|
||||
DictElement* element = NULL;
|
||||
CCDICT_FOREACH(framesDict, element)
|
||||
{
|
||||
Dictionary* frameDict = static_cast<Dictionary*>(pElement->getObject());
|
||||
std::string spriteFrameName = pElement->getStrKey();
|
||||
Dictionary* frameDict = static_cast<Dictionary*>(element->getObject());
|
||||
std::string spriteFrameName = element->getStrKey();
|
||||
SpriteFrame* spriteFrame = static_cast<SpriteFrame*>(_spriteFrames->objectForKey(spriteFrameName));
|
||||
if (spriteFrame)
|
||||
{
|
||||
|
@ -203,7 +203,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(Dictionary* dictionary, Tex
|
|||
}
|
||||
}
|
||||
|
||||
void SpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, Texture2D *pobTexture)
|
||||
void SpriteFrameCache::addSpriteFramesWithFile(const std::string& pszPlist, Texture2D *pobTexture)
|
||||
{
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszPlist);
|
||||
Dictionary *dict = Dictionary::createWithContentsOfFileThreadSafe(fullPath.c_str());
|
||||
|
@ -212,9 +212,9 @@ void SpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, Texture2D *
|
|||
dict->release();
|
||||
}
|
||||
|
||||
void SpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char* textureFileName)
|
||||
void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName)
|
||||
{
|
||||
CCASSERT(textureFileName, "texture name should not be null");
|
||||
CCASSERT(textureFileName.size()>0, "texture name should not be null");
|
||||
Texture2D *texture = TextureCache::getInstance()->addImage(textureFileName);
|
||||
|
||||
if (texture)
|
||||
|
@ -223,13 +223,13 @@ void SpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char* te
|
|||
}
|
||||
else
|
||||
{
|
||||
CCLOG("cocos2d: SpriteFrameCache: couldn't load texture file. File not found %s", textureFileName);
|
||||
CCLOG("cocos2d: SpriteFrameCache: couldn't load texture file. File not found %s", textureFileName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void SpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
||||
void SpriteFrameCache::addSpriteFramesWithFile(const std::string& pszPlist)
|
||||
{
|
||||
CCASSERT(pszPlist, "plist filename should not be NULL");
|
||||
CCASSERT(pszPlist.size()>0, "plist filename should not be NULL");
|
||||
|
||||
if (_loadedFileNames->find(pszPlist) == _loadedFileNames->end())
|
||||
{
|
||||
|
@ -280,7 +280,7 @@ void SpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
|||
}
|
||||
}
|
||||
|
||||
void SpriteFrameCache::addSpriteFrame(SpriteFrame *pobFrame, const char *pszFrameName)
|
||||
void SpriteFrameCache::addSpriteFrame(SpriteFrame *pobFrame, const std::string& pszFrameName)
|
||||
{
|
||||
_spriteFrames->setObject(pobFrame, pszFrameName);
|
||||
}
|
||||
|
@ -295,14 +295,14 @@ void SpriteFrameCache::removeSpriteFrames(void)
|
|||
void SpriteFrameCache::removeUnusedSpriteFrames(void)
|
||||
{
|
||||
bool bRemoved = false;
|
||||
DictElement* pElement = NULL;
|
||||
CCDICT_FOREACH(_spriteFrames, pElement)
|
||||
DictElement* element = NULL;
|
||||
CCDICT_FOREACH(_spriteFrames, element)
|
||||
{
|
||||
SpriteFrame* spriteFrame = static_cast<SpriteFrame*>(pElement->getObject());
|
||||
SpriteFrame* spriteFrame = static_cast<SpriteFrame*>(element->getObject());
|
||||
if( spriteFrame->retainCount() == 1 )
|
||||
{
|
||||
CCLOG("cocos2d: SpriteFrameCache: removing unused frame: %s", pElement->getStrKey());
|
||||
_spriteFrames->removeObjectForElememt(pElement);
|
||||
CCLOG("cocos2d: SpriteFrameCache: removing unused frame: %s", element->getStrKey());
|
||||
_spriteFrames->removeObjectForElememt(element);
|
||||
bRemoved = true;
|
||||
}
|
||||
}
|
||||
|
@ -315,16 +315,14 @@ void SpriteFrameCache::removeUnusedSpriteFrames(void)
|
|||
}
|
||||
|
||||
|
||||
void SpriteFrameCache::removeSpriteFrameByName(const char *pszName)
|
||||
void SpriteFrameCache::removeSpriteFrameByName(const std::string& name)
|
||||
{
|
||||
// explicit nil handling
|
||||
if( ! pszName )
|
||||
{
|
||||
if( ! name.size()>0 )
|
||||
return;
|
||||
}
|
||||
|
||||
// Is this an alias ?
|
||||
String* key = (String*)_spriteFramesAliases->objectForKey(pszName);
|
||||
String* key = (String*)_spriteFramesAliases->objectForKey(name);
|
||||
|
||||
if (key)
|
||||
{
|
||||
|
@ -333,20 +331,20 @@ void SpriteFrameCache::removeSpriteFrameByName(const char *pszName)
|
|||
}
|
||||
else
|
||||
{
|
||||
_spriteFrames->removeObjectForKey(pszName);
|
||||
_spriteFrames->removeObjectForKey(name);
|
||||
}
|
||||
|
||||
// XXX. Since we don't know the .plist file that originated the frame, we must remove all .plist from the cache
|
||||
_loadedFileNames->clear();
|
||||
}
|
||||
|
||||
void SpriteFrameCache::removeSpriteFramesFromFile(const char* plist)
|
||||
void SpriteFrameCache::removeSpriteFramesFromFile(const std::string& plist)
|
||||
{
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plist);
|
||||
Dictionary* dict = Dictionary::createWithContentsOfFileThreadSafe(fullPath.c_str());
|
||||
if (dict == nullptr)
|
||||
{
|
||||
CCLOG("cocos2d:SpriteFrameCache:removeSpriteFramesFromFile: create dict by %s fail.",plist);
|
||||
CCLOG("cocos2d:SpriteFrameCache:removeSpriteFramesFromFile: create dict by %s fail.",plist.c_str());
|
||||
return;
|
||||
}
|
||||
removeSpriteFramesFromDictionary((Dictionary*)dict);
|
||||
|
@ -365,12 +363,12 @@ void SpriteFrameCache::removeSpriteFramesFromDictionary(Dictionary* dictionary)
|
|||
Dictionary* framesDict = static_cast<Dictionary*>(dictionary->objectForKey("frames"));
|
||||
Array* keysToRemove = Array::create();
|
||||
|
||||
DictElement* pElement = NULL;
|
||||
CCDICT_FOREACH(framesDict, pElement)
|
||||
DictElement* element = NULL;
|
||||
CCDICT_FOREACH(framesDict, element)
|
||||
{
|
||||
if (_spriteFrames->objectForKey(pElement->getStrKey()))
|
||||
if (_spriteFrames->objectForKey(element->getStrKey()))
|
||||
{
|
||||
keysToRemove->addObject(String::create(pElement->getStrKey()));
|
||||
keysToRemove->addObject(String::create(element->getStrKey()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -381,33 +379,33 @@ void SpriteFrameCache::removeSpriteFramesFromTexture(Texture2D* texture)
|
|||
{
|
||||
Array* keysToRemove = Array::create();
|
||||
|
||||
DictElement* pElement = NULL;
|
||||
CCDICT_FOREACH(_spriteFrames, pElement)
|
||||
DictElement* element = NULL;
|
||||
CCDICT_FOREACH(_spriteFrames, element)
|
||||
{
|
||||
string key = pElement->getStrKey();
|
||||
string key = element->getStrKey();
|
||||
SpriteFrame* frame = static_cast<SpriteFrame*>(_spriteFrames->objectForKey(key.c_str()));
|
||||
if (frame && (frame->getTexture() == texture))
|
||||
{
|
||||
keysToRemove->addObject(String::create(pElement->getStrKey()));
|
||||
keysToRemove->addObject(String::create(element->getStrKey()));
|
||||
}
|
||||
}
|
||||
|
||||
_spriteFrames->removeObjectsForKeys(keysToRemove);
|
||||
}
|
||||
|
||||
SpriteFrame* SpriteFrameCache::getSpriteFrameByName(const char *pszName)
|
||||
SpriteFrame* SpriteFrameCache::getSpriteFrameByName(const std::string& name)
|
||||
{
|
||||
SpriteFrame* frame = (SpriteFrame*)_spriteFrames->objectForKey(pszName);
|
||||
SpriteFrame* frame = (SpriteFrame*)_spriteFrames->objectForKey(name);
|
||||
if (!frame)
|
||||
{
|
||||
// try alias dictionary
|
||||
String *key = (String*)_spriteFramesAliases->objectForKey(pszName);
|
||||
String *key = (String*)_spriteFramesAliases->objectForKey(name);
|
||||
if (key)
|
||||
{
|
||||
frame = (SpriteFrame*)_spriteFrames->objectForKey(key->getCString());
|
||||
if (! frame)
|
||||
{
|
||||
CCLOG("cocos2d: SpriteFrameCache: Frame '%s' not found", pszName);
|
||||
CCLOG("cocos2d: SpriteFrameCache: Frame '%s' not found", name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,29 +85,29 @@ public:
|
|||
public:
|
||||
/** Adds multiple Sprite Frames from a plist file.
|
||||
* A texture will be loaded automatically. The texture name will composed by replacing the .plist suffix with .png
|
||||
* If you want to use another texture, you should use the addSpriteFramesWithFile(const char *plist, const char *textureFileName) method.
|
||||
* If you want to use another texture, you should use the addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName) method.
|
||||
* @js addSpriteFrames
|
||||
* @lua addSpriteFrames
|
||||
*/
|
||||
void addSpriteFramesWithFile(const char *plist);
|
||||
void addSpriteFramesWithFile(const std::string& plist);
|
||||
|
||||
/** Adds multiple Sprite Frames from a plist file. The texture will be associated with the created sprite frames.
|
||||
@since v0.99.5
|
||||
* @js addSpriteFrames
|
||||
* @lua addSpriteFrames
|
||||
*/
|
||||
void addSpriteFramesWithFile(const char* plist, const char* textureFileName);
|
||||
void addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName);
|
||||
|
||||
/** Adds multiple Sprite Frames from a plist file. The texture will be associated with the created sprite frames.
|
||||
* @js addSpriteFrames
|
||||
* @lua addSpriteFrames
|
||||
*/
|
||||
void addSpriteFramesWithFile(const char *plist, Texture2D *texture);
|
||||
void addSpriteFramesWithFile(const std::string&plist, Texture2D *texture);
|
||||
|
||||
/** Adds an sprite frame with a given name.
|
||||
If the name already exists, then the contents of the old name will be replaced with the new one.
|
||||
*/
|
||||
void addSpriteFrame(SpriteFrame *frame, const char *frameName);
|
||||
void addSpriteFrame(SpriteFrame *frame, const std::string& frameName);
|
||||
|
||||
/** Purges the dictionary of loaded sprite frames.
|
||||
* Call this method if you receive the "Memory Warning".
|
||||
|
@ -124,14 +124,14 @@ public:
|
|||
void removeUnusedSpriteFrames(void);
|
||||
|
||||
/** Deletes an sprite frame from the sprite frame cache. */
|
||||
void removeSpriteFrameByName(const char *name);
|
||||
void removeSpriteFrameByName(const std::string& name);
|
||||
|
||||
/** Removes multiple Sprite Frames from a plist file.
|
||||
* Sprite Frames stored in this file will be removed.
|
||||
* It is convenient to call this method when a specific texture needs to be removed.
|
||||
* @since v0.99.5
|
||||
*/
|
||||
void removeSpriteFramesFromFile(const char* plist);
|
||||
void removeSpriteFramesFromFile(const std::string& plist);
|
||||
|
||||
/** Removes all Sprite Frames associated with the specified textures.
|
||||
* It is convenient to call this method when a specific texture needs to be removed.
|
||||
|
@ -145,10 +145,10 @@ public:
|
|||
* @js getSpriteFrame
|
||||
* @lua getSpriteFrame
|
||||
*/
|
||||
SpriteFrame* getSpriteFrameByName(const char *name);
|
||||
SpriteFrame* getSpriteFrameByName(const std::string& name);
|
||||
|
||||
/** @deprecated use getSpriteFrameByName() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE SpriteFrame* spriteFrameByName(const char *name) { return getSpriteFrameByName(name); }
|
||||
CC_DEPRECATED_ATTRIBUTE SpriteFrame* spriteFrameByName(const std::string&name) { return getSpriteFrameByName(name); }
|
||||
|
||||
private:
|
||||
/*Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames.
|
||||
|
|
|
@ -32,33 +32,33 @@ NS_CC_BEGIN
|
|||
|
||||
// implementation TMXTiledMap
|
||||
|
||||
TMXTiledMap * TMXTiledMap::create(const char *tmxFile)
|
||||
TMXTiledMap * TMXTiledMap::create(const std::string& tmxFile)
|
||||
{
|
||||
TMXTiledMap *pRet = new TMXTiledMap();
|
||||
if (pRet->initWithTMXFile(tmxFile))
|
||||
TMXTiledMap *ret = new TMXTiledMap();
|
||||
if (ret->initWithTMXFile(tmxFile))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TMXTiledMap* TMXTiledMap::createWithXML(const char* tmxString, const char* resourcePath)
|
||||
TMXTiledMap* TMXTiledMap::createWithXML(const std::string& tmxString, const std::string& resourcePath)
|
||||
{
|
||||
TMXTiledMap *pRet = new TMXTiledMap();
|
||||
if (pRet->initWithXML(tmxString, resourcePath))
|
||||
TMXTiledMap *ret = new TMXTiledMap();
|
||||
if (ret->initWithXML(tmxString, resourcePath))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool TMXTiledMap::initWithTMXFile(const char *tmxFile)
|
||||
bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile)
|
||||
{
|
||||
CCASSERT(tmxFile != NULL && strlen(tmxFile)>0, "TMXTiledMap: tmx file should not bi NULL");
|
||||
CCASSERT(tmxFile.size()>0, "TMXTiledMap: tmx file should not be empty");
|
||||
|
||||
setContentSize(Size::ZERO);
|
||||
|
||||
|
@ -74,7 +74,7 @@ bool TMXTiledMap::initWithTMXFile(const char *tmxFile)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool TMXTiledMap::initWithXML(const char* tmxString, const char* resourcePath)
|
||||
bool TMXTiledMap::initWithXML(const std::string& tmxString, const std::string& resourcePath)
|
||||
{
|
||||
setContentSize(Size::ZERO);
|
||||
|
||||
|
@ -195,8 +195,8 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
|||
// update content size with the max size
|
||||
const Size& childSize = child->getContentSize();
|
||||
Size currentSize = this->getContentSize();
|
||||
currentSize.width = MAX( currentSize.width, childSize.width );
|
||||
currentSize.height = MAX( currentSize.height, childSize.height );
|
||||
currentSize.width = std::max( currentSize.width, childSize.width );
|
||||
currentSize.height = std::max( currentSize.height, childSize.height );
|
||||
this->setContentSize(currentSize);
|
||||
|
||||
idx++;
|
||||
|
@ -206,16 +206,16 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
|||
}
|
||||
|
||||
// public
|
||||
TMXLayer * TMXTiledMap::getLayer(const char *layerName) const
|
||||
TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const
|
||||
{
|
||||
CCASSERT(layerName != NULL && strlen(layerName) > 0, "Invalid layer name!");
|
||||
CCASSERT(layerName.size() > 0, "Invalid layer name!");
|
||||
Object* pObj = NULL;
|
||||
CCARRAY_FOREACH(_children, pObj)
|
||||
{
|
||||
TMXLayer* layer = dynamic_cast<TMXLayer*>(pObj);
|
||||
if(layer)
|
||||
{
|
||||
if(0 == strcmp(layer->getLayerName(), layerName))
|
||||
if(layerName.compare( layer->getLayerName()) == 0)
|
||||
{
|
||||
return layer;
|
||||
}
|
||||
|
@ -226,11 +226,10 @@ TMXLayer * TMXTiledMap::getLayer(const char *layerName) const
|
|||
return NULL;
|
||||
}
|
||||
|
||||
TMXObjectGroup * TMXTiledMap::getObjectGroup(const char *groupName) const
|
||||
TMXObjectGroup * TMXTiledMap::getObjectGroup(const std::string& groupName) const
|
||||
{
|
||||
CCASSERT(groupName != NULL && strlen(groupName) > 0, "Invalid group name!");
|
||||
CCASSERT(groupName.size() > 0, "Invalid group name!");
|
||||
|
||||
std::string sGroupName = groupName;
|
||||
if (_objectGroups && _objectGroups->count()>0)
|
||||
{
|
||||
TMXObjectGroup* objectGroup = NULL;
|
||||
|
@ -238,7 +237,7 @@ TMXObjectGroup * TMXTiledMap::getObjectGroup(const char *groupName) const
|
|||
CCARRAY_FOREACH(_objectGroups, pObj)
|
||||
{
|
||||
objectGroup = static_cast<TMXObjectGroup*>(pObj);
|
||||
if (objectGroup && objectGroup->getGroupName() == sGroupName)
|
||||
if (objectGroup && objectGroup->getGroupName() == groupName)
|
||||
{
|
||||
return objectGroup;
|
||||
}
|
||||
|
@ -249,7 +248,7 @@ TMXObjectGroup * TMXTiledMap::getObjectGroup(const char *groupName) const
|
|||
return NULL;
|
||||
}
|
||||
|
||||
String* TMXTiledMap::getProperty(const char *propertyName) const
|
||||
String* TMXTiledMap::getProperty(const std::string& propertyName) const
|
||||
{
|
||||
return static_cast<String*>(_properties->objectForKey(propertyName));
|
||||
}
|
||||
|
|
|
@ -120,19 +120,19 @@ public:
|
|||
virtual ~TMXTiledMap();
|
||||
|
||||
/** creates a TMX Tiled Map with a TMX file.*/
|
||||
static TMXTiledMap* create(const char *tmxFile);
|
||||
static TMXTiledMap* create(const std::string& tmxFile);
|
||||
|
||||
/** initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources */
|
||||
static TMXTiledMap* createWithXML(const char* tmxString, const char* resourcePath);
|
||||
static TMXTiledMap* createWithXML(const std::string& tmxString, const std::string& resourcePath);
|
||||
|
||||
/** initializes a TMX Tiled Map with a TMX file */
|
||||
bool initWithTMXFile(const char *tmxFile);
|
||||
bool initWithTMXFile(const std::string& tmxFile);
|
||||
|
||||
/** initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources */
|
||||
bool initWithXML(const char* tmxString, const char* resourcePath);
|
||||
bool initWithXML(const std::string& tmxString, const std::string& resourcePath);
|
||||
|
||||
/** return the TMXLayer for the specific layer */
|
||||
TMXLayer* getLayer(const char *layerName) const;
|
||||
TMXLayer* getLayer(const std::string& layerName) const;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -140,7 +140,7 @@ public:
|
|||
CC_DEPRECATED_ATTRIBUTE TMXLayer* layerNamed(const char *layerName) const { return getLayer(layerName); };
|
||||
|
||||
/** return the TMXObjectGroup for the specific group */
|
||||
TMXObjectGroup* getObjectGroup(const char *groupName) const;
|
||||
TMXObjectGroup* getObjectGroup(const std::string& groupName) const;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -148,7 +148,7 @@ public:
|
|||
CC_DEPRECATED_ATTRIBUTE TMXObjectGroup* objectGroupNamed(const char *groupName) const { return getObjectGroup(groupName); };
|
||||
|
||||
/** return the value for the specific property name */
|
||||
String *getProperty(const char *propertyName) const;
|
||||
String *getProperty(const std::string& propertyName) const;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
|
|
@ -112,7 +112,7 @@ Rect TMXTilesetInfo::rectForGID(unsigned int gid)
|
|||
|
||||
// implementation TMXMapInfo
|
||||
|
||||
TMXMapInfo * TMXMapInfo::create(const char *tmxFile)
|
||||
TMXMapInfo * TMXMapInfo::create(const std::string& tmxFile)
|
||||
{
|
||||
TMXMapInfo *pRet = new TMXMapInfo();
|
||||
if(pRet->initWithTMXFile(tmxFile))
|
||||
|
@ -124,7 +124,7 @@ TMXMapInfo * TMXMapInfo::create(const char *tmxFile)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
TMXMapInfo * TMXMapInfo::createWithXML(const char* tmxString, const char* resourcePath)
|
||||
TMXMapInfo * TMXMapInfo::createWithXML(const std::string& tmxString, const std::string& resourcePath)
|
||||
{
|
||||
TMXMapInfo *pRet = new TMXMapInfo();
|
||||
if(pRet->initWithXML(tmxString, resourcePath))
|
||||
|
@ -136,7 +136,7 @@ TMXMapInfo * TMXMapInfo::createWithXML(const char* tmxString, const char* resour
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void TMXMapInfo::internalInit(const char* tmxFileName, const char* resourcePath)
|
||||
void TMXMapInfo::internalInit(const std::string& tmxFileName, const std::string& resourcePath)
|
||||
{
|
||||
_tilesets = Array::create();
|
||||
_tilesets->retain();
|
||||
|
@ -144,12 +144,12 @@ void TMXMapInfo::internalInit(const char* tmxFileName, const char* resourcePath)
|
|||
_layers = Array::create();
|
||||
_layers->retain();
|
||||
|
||||
if (tmxFileName != NULL)
|
||||
if (tmxFileName.size() > 0)
|
||||
{
|
||||
_TMXFileName = FileUtils::getInstance()->fullPathForFilename(tmxFileName);
|
||||
}
|
||||
|
||||
if (resourcePath != NULL)
|
||||
if (resourcePath.size() > 0)
|
||||
{
|
||||
_resources = resourcePath;
|
||||
}
|
||||
|
@ -169,15 +169,15 @@ void TMXMapInfo::internalInit(const char* tmxFileName, const char* resourcePath)
|
|||
_parentElement = TMXPropertyNone;
|
||||
_currentFirstGID = 0;
|
||||
}
|
||||
bool TMXMapInfo::initWithXML(const char* tmxString, const char* resourcePath)
|
||||
bool TMXMapInfo::initWithXML(const std::string& tmxString, const std::string& resourcePath)
|
||||
{
|
||||
internalInit(NULL, resourcePath);
|
||||
internalInit("", resourcePath);
|
||||
return parseXMLString(tmxString);
|
||||
}
|
||||
|
||||
bool TMXMapInfo::initWithTMXFile(const char *tmxFile)
|
||||
bool TMXMapInfo::initWithTMXFile(const std::string& tmxFile)
|
||||
{
|
||||
internalInit(tmxFile, NULL);
|
||||
internalInit(tmxFile, "");
|
||||
return parseXMLFile(_TMXFileName.c_str());
|
||||
}
|
||||
|
||||
|
@ -205,13 +205,11 @@ TMXMapInfo::~TMXMapInfo()
|
|||
CC_SAFE_RELEASE(_objectGroups);
|
||||
}
|
||||
|
||||
bool TMXMapInfo::parseXMLString(const char *xmlString)
|
||||
bool TMXMapInfo::parseXMLString(const std::string& xmlString)
|
||||
{
|
||||
int len = strlen(xmlString);
|
||||
if (xmlString == NULL || len <= 0)
|
||||
{
|
||||
int len = xmlString.size();
|
||||
if (len <= 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
SAXParser parser;
|
||||
|
||||
|
@ -222,10 +220,10 @@ bool TMXMapInfo::parseXMLString(const char *xmlString)
|
|||
|
||||
parser.setDelegator(this);
|
||||
|
||||
return parser.parse(xmlString, len);
|
||||
return parser.parse(xmlString.c_str(), len);
|
||||
}
|
||||
|
||||
bool TMXMapInfo::parseXMLFile(const char *xmlFilename)
|
||||
bool TMXMapInfo::parseXMLFile(const std::string& xmlFilename)
|
||||
{
|
||||
SAXParser parser;
|
||||
|
||||
|
|
|
@ -166,9 +166,9 @@ class CC_DLL TMXMapInfo : public Object, public SAXDelegator
|
|||
{
|
||||
public:
|
||||
/** creates a TMX Format with a tmx file */
|
||||
static TMXMapInfo * create(const char *tmxFile);
|
||||
static TMXMapInfo * create(const std::string& tmxFile);
|
||||
/** creates a TMX Format with an XML string and a TMX resource path */
|
||||
static TMXMapInfo * createWithXML(const char* tmxString, const char* resourcePath);
|
||||
static TMXMapInfo * createWithXML(const std::string& tmxString, const std::string& resourcePath);
|
||||
|
||||
/** creates a TMX Format with a tmx file */
|
||||
CC_DEPRECATED_ATTRIBUTE static TMXMapInfo * formatWithTMXFile(const char *tmxFile) { return TMXMapInfo::create(tmxFile); };
|
||||
|
@ -185,13 +185,13 @@ public:
|
|||
virtual ~TMXMapInfo();
|
||||
|
||||
/** initializes a TMX format with a tmx file */
|
||||
bool initWithTMXFile(const char *tmxFile);
|
||||
bool initWithTMXFile(const std::string& tmxFile);
|
||||
/** initializes a TMX format with an XML string and a TMX resource path */
|
||||
bool initWithXML(const char* tmxString, const char* resourcePath);
|
||||
bool initWithXML(const std::string& tmxString, const std::string& resourcePath);
|
||||
/** initializes parsing of an XML file, either a tmx (Map) file or tsx (Tileset) file */
|
||||
bool parseXMLFile(const char *xmlFilename);
|
||||
bool parseXMLFile(const std::string& xmlFilename);
|
||||
/* initializes parsing of an XML string, either a tmx (Map) string or tsx (Tileset) string */
|
||||
bool parseXMLString(const char *xmlString);
|
||||
bool parseXMLString(const std::string& xmlString);
|
||||
|
||||
Dictionary* getTileProperties() { return _tileProperties; };
|
||||
void setTileProperties(Dictionary* tileProperties) {
|
||||
|
@ -278,13 +278,13 @@ public:
|
|||
*/
|
||||
void textHandler(void *ctx, const char *ch, int len);
|
||||
|
||||
inline const char* getCurrentString(){ return _currentString.c_str(); }
|
||||
inline void setCurrentString(const char *currentString){ _currentString = currentString; }
|
||||
inline const char* getTMXFileName(){ return _TMXFileName.c_str(); }
|
||||
inline void setTMXFileName(const char *fileName){ _TMXFileName = fileName; }
|
||||
private:
|
||||
void internalInit(const char* tmxFileName, const char* resourcePath);
|
||||
inline const std::string& getCurrentString() const { return _currentString; }
|
||||
inline void setCurrentString(const std::string& currentString){ _currentString = currentString; }
|
||||
inline const std::string& getTMXFileName() const { return _TMXFileName; }
|
||||
inline void setTMXFileName(const std::string& fileName){ _TMXFileName = fileName; }
|
||||
|
||||
protected:
|
||||
void internalInit(const std::string& tmxFileName, const std::string& resourcePath);
|
||||
|
||||
/// map orientation
|
||||
int _orientation;
|
||||
|
|
|
@ -53,8 +53,8 @@ static int _calcCharCount(const char * pszText)
|
|||
TextFieldTTF::TextFieldTTF()
|
||||
: _delegate(0)
|
||||
, _charCount(0)
|
||||
, _inputText(new std::string)
|
||||
, _placeHolder(new std::string) // prevent LabelTTF initWithString assertion
|
||||
, _inputText("")
|
||||
, _placeHolder("") // prevent LabelTTF initWithString assertion
|
||||
, _secureTextEntry(false)
|
||||
{
|
||||
_colorSpaceHolder.r = _colorSpaceHolder.g = _colorSpaceHolder.b = 127;
|
||||
|
@ -62,43 +62,41 @@ TextFieldTTF::TextFieldTTF()
|
|||
|
||||
TextFieldTTF::~TextFieldTTF()
|
||||
{
|
||||
CC_SAFE_DELETE(_inputText);
|
||||
CC_SAFE_DELETE(_placeHolder);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// static constructor
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TextFieldTTF * TextFieldTTF::textFieldWithPlaceHolder(const char *placeholder, const Size& dimensions, TextHAlignment alignment, const char *fontName, float fontSize)
|
||||
TextFieldTTF * TextFieldTTF::textFieldWithPlaceHolder(const std::string& placeholder, const Size& dimensions, TextHAlignment alignment, const std::string& fontName, float fontSize)
|
||||
{
|
||||
TextFieldTTF *pRet = new TextFieldTTF();
|
||||
if(pRet && pRet->initWithPlaceHolder("", dimensions, alignment, fontName, fontSize))
|
||||
TextFieldTTF *ret = new TextFieldTTF();
|
||||
if(ret && ret->initWithPlaceHolder("", dimensions, alignment, fontName, fontSize))
|
||||
{
|
||||
pRet->autorelease();
|
||||
if (placeholder)
|
||||
ret->autorelease();
|
||||
if (placeholder.size()>0)
|
||||
{
|
||||
pRet->setPlaceHolder(placeholder);
|
||||
ret->setPlaceHolder(placeholder);
|
||||
}
|
||||
return pRet;
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TextFieldTTF * TextFieldTTF::textFieldWithPlaceHolder(const char *placeholder, const char *fontName, float fontSize)
|
||||
TextFieldTTF * TextFieldTTF::textFieldWithPlaceHolder(const std::string& placeholder, const std::string& fontName, float fontSize)
|
||||
{
|
||||
TextFieldTTF *pRet = new TextFieldTTF();
|
||||
if(pRet && pRet->initWithString("", fontName, fontSize))
|
||||
TextFieldTTF *ret = new TextFieldTTF();
|
||||
if(ret && ret->initWithString("", fontName, fontSize))
|
||||
{
|
||||
pRet->autorelease();
|
||||
if (placeholder)
|
||||
ret->autorelease();
|
||||
if (placeholder.size()>0)
|
||||
{
|
||||
pRet->setPlaceHolder(placeholder);
|
||||
ret->setPlaceHolder(placeholder);
|
||||
}
|
||||
return pRet;
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
CC_SAFE_DELETE(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -106,23 +104,15 @@ TextFieldTTF * TextFieldTTF::textFieldWithPlaceHolder(const char *placeholder, c
|
|||
// initialize
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TextFieldTTF::initWithPlaceHolder(const char *placeholder, const Size& dimensions, TextHAlignment alignment, const char *fontName, float fontSize)
|
||||
bool TextFieldTTF::initWithPlaceHolder(const std::string& placeholder, const Size& dimensions, TextHAlignment alignment, const std::string& fontName, float fontSize)
|
||||
{
|
||||
if (placeholder)
|
||||
{
|
||||
CC_SAFE_DELETE(_placeHolder);
|
||||
_placeHolder = new std::string(placeholder);
|
||||
}
|
||||
return LabelTTF::initWithString(_placeHolder->c_str(), fontName, fontSize, dimensions, alignment);
|
||||
_placeHolder = placeholder;
|
||||
return LabelTTF::initWithString(_placeHolder, fontName, fontSize, dimensions, alignment);
|
||||
}
|
||||
bool TextFieldTTF::initWithPlaceHolder(const char *placeholder, const char *fontName, float fontSize)
|
||||
bool TextFieldTTF::initWithPlaceHolder(const std::string& placeholder, const std::string& fontName, float fontSize)
|
||||
{
|
||||
if (placeholder)
|
||||
{
|
||||
CC_SAFE_DELETE(_placeHolder);
|
||||
_placeHolder = new std::string(placeholder);
|
||||
}
|
||||
return LabelTTF::initWithString(_placeHolder->c_str(), fontName, fontSize);
|
||||
_placeHolder = std::string(placeholder);
|
||||
return LabelTTF::initWithString(_placeHolder, fontName, fontSize);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -190,9 +180,9 @@ void TextFieldTTF::insertText(const char * text, int len)
|
|||
}
|
||||
|
||||
_charCount += _calcCharCount(sInsert.c_str());
|
||||
std::string sText(*_inputText);
|
||||
std::string sText(_inputText);
|
||||
sText.append(sInsert);
|
||||
setString(sText.c_str());
|
||||
setString(sText);
|
||||
}
|
||||
|
||||
if ((int)sInsert.npos == nPos) {
|
||||
|
@ -211,7 +201,7 @@ void TextFieldTTF::insertText(const char * text, int len)
|
|||
|
||||
void TextFieldTTF::deleteBackward()
|
||||
{
|
||||
int nStrLen = _inputText->length();
|
||||
int nStrLen = _inputText.length();
|
||||
if (! nStrLen)
|
||||
{
|
||||
// there is no string
|
||||
|
@ -221,12 +211,12 @@ void TextFieldTTF::deleteBackward()
|
|||
// get the delete byte number
|
||||
int nDeleteLen = 1; // default, erase 1 byte
|
||||
|
||||
while(0x80 == (0xC0 & _inputText->at(nStrLen - nDeleteLen)))
|
||||
while(0x80 == (0xC0 & _inputText.at(nStrLen - nDeleteLen)))
|
||||
{
|
||||
++nDeleteLen;
|
||||
}
|
||||
|
||||
if (_delegate && _delegate->onTextFieldDeleteBackward(this, _inputText->c_str() + nStrLen - nDeleteLen, nDeleteLen))
|
||||
if (_delegate && _delegate->onTextFieldDeleteBackward(this, _inputText.c_str() + nStrLen - nDeleteLen, nDeleteLen))
|
||||
{
|
||||
// delegate doesn't wan't to delete backwards
|
||||
return;
|
||||
|
@ -235,21 +225,20 @@ void TextFieldTTF::deleteBackward()
|
|||
// if all text deleted, show placeholder string
|
||||
if (nStrLen <= nDeleteLen)
|
||||
{
|
||||
CC_SAFE_DELETE(_inputText);
|
||||
_inputText = new std::string;
|
||||
_inputText = "";
|
||||
_charCount = 0;
|
||||
LabelTTF::setString(_placeHolder->c_str());
|
||||
LabelTTF::setString(_placeHolder);
|
||||
return;
|
||||
}
|
||||
|
||||
// set new input text
|
||||
std::string sText(_inputText->c_str(), nStrLen - nDeleteLen);
|
||||
setString(sText.c_str());
|
||||
std::string sText(_inputText.c_str(), nStrLen - nDeleteLen);
|
||||
setString(sText);
|
||||
}
|
||||
|
||||
const char * TextFieldTTF::getContentText()
|
||||
{
|
||||
return _inputText->c_str();
|
||||
return _inputText.c_str();
|
||||
}
|
||||
|
||||
void TextFieldTTF::draw()
|
||||
|
@ -258,7 +247,7 @@ void TextFieldTTF::draw()
|
|||
{
|
||||
return;
|
||||
}
|
||||
if (_inputText->length())
|
||||
if (_inputText.length())
|
||||
{
|
||||
LabelTTF::draw();
|
||||
return;
|
||||
|
@ -286,22 +275,20 @@ void TextFieldTTF::setColorSpaceHolder(const Color3B& color)
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// input text property
|
||||
void TextFieldTTF::setString(const char *text)
|
||||
void TextFieldTTF::setString(const std::string &text)
|
||||
{
|
||||
static char bulletString[] = {(char)0xe2, (char)0x80, (char)0xa2, (char)0x00};
|
||||
std::string displayText;
|
||||
int length;
|
||||
|
||||
CC_SAFE_DELETE(_inputText);
|
||||
|
||||
if (text)
|
||||
if (text.length()>0)
|
||||
{
|
||||
_inputText = new std::string(text);
|
||||
displayText = *_inputText;
|
||||
_inputText = text;
|
||||
displayText = _inputText;
|
||||
if (_secureTextEntry)
|
||||
{
|
||||
displayText = "";
|
||||
length = _inputText->length();
|
||||
length = _inputText.length();
|
||||
while (length)
|
||||
{
|
||||
displayText.append(bulletString);
|
||||
|
@ -311,40 +298,39 @@ void TextFieldTTF::setString(const char *text)
|
|||
}
|
||||
else
|
||||
{
|
||||
_inputText = new std::string;
|
||||
_inputText = "";
|
||||
}
|
||||
|
||||
// if there is no input text, display placeholder instead
|
||||
if (! _inputText->length())
|
||||
if (! _inputText.length())
|
||||
{
|
||||
LabelTTF::setString(_placeHolder->c_str());
|
||||
LabelTTF::setString(_placeHolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
LabelTTF::setString(displayText.c_str());
|
||||
LabelTTF::setString(displayText);
|
||||
}
|
||||
_charCount = _calcCharCount(_inputText->c_str());
|
||||
_charCount = _calcCharCount(_inputText.c_str());
|
||||
}
|
||||
|
||||
const char* TextFieldTTF::getString(void) const
|
||||
const std::string& TextFieldTTF::getString() const
|
||||
{
|
||||
return _inputText->c_str();
|
||||
return _inputText;
|
||||
}
|
||||
|
||||
// place holder text property
|
||||
void TextFieldTTF::setPlaceHolder(const char * text)
|
||||
void TextFieldTTF::setPlaceHolder(const std::string& text)
|
||||
{
|
||||
CC_SAFE_DELETE(_placeHolder);
|
||||
_placeHolder = (text) ? new std::string(text) : new std::string;
|
||||
if (! _inputText->length())
|
||||
_placeHolder = text;
|
||||
if (! _inputText.length())
|
||||
{
|
||||
LabelTTF::setString(_placeHolder->c_str());
|
||||
LabelTTF::setString(_placeHolder);
|
||||
}
|
||||
}
|
||||
|
||||
const char * TextFieldTTF::getPlaceHolder(void)
|
||||
const std::string& TextFieldTTF::getPlaceHolder() const
|
||||
{
|
||||
return _placeHolder->c_str();
|
||||
return _placeHolder;
|
||||
}
|
||||
|
||||
// secureTextEntry
|
||||
|
|
|
@ -109,13 +109,13 @@ public:
|
|||
//char * description();
|
||||
|
||||
/** creates a TextFieldTTF from a fontname, alignment, dimension and font size */
|
||||
static TextFieldTTF * textFieldWithPlaceHolder(const char *placeholder, const Size& dimensions, TextHAlignment alignment, const char *fontName, float fontSize);
|
||||
static TextFieldTTF * textFieldWithPlaceHolder(const std::string& placeholder, const Size& dimensions, TextHAlignment alignment, const std::string& fontName, float fontSize);
|
||||
/** creates a LabelTTF from a fontname and font size */
|
||||
static TextFieldTTF * textFieldWithPlaceHolder(const char *placeholder, const char *fontName, float fontSize);
|
||||
static TextFieldTTF * textFieldWithPlaceHolder(const std::string& placeholder, const std::string& fontName, float fontSize);
|
||||
/** initializes the TextFieldTTF with a font name, alignment, dimension and font size */
|
||||
bool initWithPlaceHolder(const char *placeholder, const Size& dimensions, TextHAlignment alignment, const char *fontName, float fontSize);
|
||||
bool initWithPlaceHolder(const std::string& placeholder, const Size& dimensions, TextHAlignment alignment, const std::string& fontName, float fontSize);
|
||||
/** initializes the TextFieldTTF with a font name and font size */
|
||||
bool initWithPlaceHolder(const char *placeholder, const char *fontName, float fontSize);
|
||||
bool initWithPlaceHolder(const std::string& placeholder, const std::string& fontName, float fontSize);
|
||||
|
||||
/**
|
||||
@brief Open keyboard and receive input text.
|
||||
|
@ -147,21 +147,21 @@ public:
|
|||
|
||||
// input text property
|
||||
public:
|
||||
virtual void setString(const char *text);
|
||||
virtual const char* getString(void) const;
|
||||
virtual void setString(const std::string& text) override;
|
||||
virtual const std::string& getString() const override;
|
||||
protected:
|
||||
TextFieldDelegate * _delegate;
|
||||
int _charCount;
|
||||
|
||||
std::string * _inputText;
|
||||
std::string _inputText;
|
||||
|
||||
// place holder text property
|
||||
// place holder text displayed when there is no text in the text field.
|
||||
public:
|
||||
virtual void setPlaceHolder(const char * text);
|
||||
virtual const char * getPlaceHolder(void);
|
||||
virtual void setPlaceHolder(const std::string& text);
|
||||
virtual const std::string& getPlaceHolder(void) const;
|
||||
protected:
|
||||
std::string * _placeHolder;
|
||||
std::string _placeHolder;
|
||||
Color3B _colorSpaceHolder;
|
||||
public:
|
||||
virtual void setSecureTextEntry(bool value);
|
||||
|
@ -176,11 +176,11 @@ protected:
|
|||
// IMEDelegate interface
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual bool canAttachWithIME();
|
||||
virtual bool canDetachWithIME();
|
||||
virtual void insertText(const char * text, int len);
|
||||
virtual void deleteBackward();
|
||||
virtual const char * getContentText();
|
||||
virtual bool canAttachWithIME() override;
|
||||
virtual bool canDetachWithIME() override;
|
||||
virtual void insertText(const char * text, int len) override;
|
||||
virtual void deleteBackward() override;
|
||||
virtual const char * getContentText() override;
|
||||
private:
|
||||
class LengthStack;
|
||||
LengthStack * _lens;
|
||||
|
|
|
@ -614,10 +614,10 @@ void VolatileTexture::reloadAllTextures()
|
|||
case kImageFile:
|
||||
{
|
||||
Image* image = new Image();
|
||||
unsigned long nSize = 0;
|
||||
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &nSize);
|
||||
long size = 0;
|
||||
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &size);
|
||||
|
||||
if (image && image->initWithImageData(pBuffer, nSize))
|
||||
if (image && image->initWithImageData(pBuffer, size))
|
||||
{
|
||||
Texture2D::PixelFormat oldPixelFormat = Texture2D::getDefaultAlphaPixelFormat();
|
||||
Texture2D::setDefaultAlphaPixelFormat(vt->_pixelFormat);
|
||||
|
|
|
@ -58,7 +58,7 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLEle
|
|||
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
||||
*doc = xmlDoc;
|
||||
//CCFileData data(UserDefault::getInstance()->getXMLFilePath().c_str(),"rt");
|
||||
unsigned long nSize;
|
||||
long nSize;
|
||||
const char* pXmlBuffer = (const char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &nSize);
|
||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||
if(NULL == pXmlBuffer)
|
||||
|
|
|
@ -73,8 +73,8 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc
|
|||
{
|
||||
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
||||
*doc = xmlDoc;
|
||||
unsigned long nSize;
|
||||
const char* pXmlBuffer = (const char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &nSize);
|
||||
long size;
|
||||
const char* pXmlBuffer = (const char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size);
|
||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||
if(NULL == pXmlBuffer)
|
||||
{
|
||||
|
|
|
@ -74,8 +74,8 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc
|
|||
{
|
||||
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
|
||||
*doc = xmlDoc;
|
||||
unsigned long nSize;
|
||||
const char* pXmlBuffer = (const char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &nSize);
|
||||
long size;
|
||||
const char* pXmlBuffer = (const char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size);
|
||||
//const char* pXmlBuffer = (const char*)data.getBuffer();
|
||||
if(NULL == pXmlBuffer)
|
||||
{
|
||||
|
|
|
@ -134,9 +134,11 @@ target_link_libraries(cocos2d
|
|||
freetype
|
||||
fontconfig
|
||||
png
|
||||
pthread
|
||||
glfw
|
||||
GLEW
|
||||
GL
|
||||
X11
|
||||
rt
|
||||
z
|
||||
)
|
||||
|
|
|
@ -198,8 +198,8 @@ tImageTGA * tgaLoad(const char *filename)
|
|||
int mode,total;
|
||||
tImageTGA *info = NULL;
|
||||
|
||||
unsigned long nSize = 0;
|
||||
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(filename, "rb", &nSize);
|
||||
long size = 0;
|
||||
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(filename, "rb", &size);
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -207,7 +207,7 @@ tImageTGA * tgaLoad(const char *filename)
|
|||
info = (tImageTGA *)malloc(sizeof(tImageTGA));
|
||||
|
||||
// get the file header info
|
||||
if (! tgaLoadHeader(pBuffer, nSize, info))
|
||||
if (! tgaLoadHeader(pBuffer, size, info))
|
||||
{
|
||||
info->status = TGA_ERROR_MEMORY;
|
||||
break;
|
||||
|
@ -245,11 +245,11 @@ tImageTGA * tgaLoad(const char *filename)
|
|||
// finally load the image pixels
|
||||
if ( info->type == 10 )
|
||||
{
|
||||
bLoadImage = tgaLoadRLEImageData(pBuffer, nSize, info);
|
||||
bLoadImage = tgaLoadRLEImageData(pBuffer, size, info);
|
||||
}
|
||||
else
|
||||
{
|
||||
bLoadImage = tgaLoadImageData(pBuffer, nSize, info);
|
||||
bLoadImage = tgaLoadImageData(pBuffer, size, info);
|
||||
}
|
||||
|
||||
// check for errors when reading the pixels
|
||||
|
|
|
@ -39,7 +39,7 @@ bool ZipUtils::s_bEncryptionKeyIsValid = false;
|
|||
|
||||
// --------------------- ZipUtils ---------------------
|
||||
|
||||
inline void ZipUtils::ccDecodeEncodedPvr(unsigned int *data, int len)
|
||||
inline void ZipUtils::ccDecodeEncodedPvr(unsigned int *data, long len)
|
||||
{
|
||||
const int enclen = 1024;
|
||||
const int securelen = 512;
|
||||
|
@ -108,7 +108,7 @@ inline void ZipUtils::ccDecodeEncodedPvr(unsigned int *data, int len)
|
|||
}
|
||||
}
|
||||
|
||||
inline unsigned int ZipUtils::ccChecksumPvr(const unsigned int *data, int len)
|
||||
inline unsigned int ZipUtils::ccChecksumPvr(const unsigned int *data, long len)
|
||||
{
|
||||
unsigned int cs = 0;
|
||||
const int cslen = 128;
|
||||
|
@ -127,12 +127,12 @@ inline unsigned int ZipUtils::ccChecksumPvr(const unsigned int *data, int len)
|
|||
// Should buffer factor be 1.5 instead of 2 ?
|
||||
#define BUFFER_INC_FACTOR (2)
|
||||
|
||||
int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int *outLength, unsigned int outLenghtHint)
|
||||
int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long *outLength, long outLenghtHint)
|
||||
{
|
||||
/* ret value */
|
||||
int err = Z_OK;
|
||||
|
||||
int bufferSize = outLenghtHint;
|
||||
long bufferSize = outLenghtHint;
|
||||
*out = new unsigned char[bufferSize];
|
||||
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
@ -192,9 +192,9 @@ int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength,
|
|||
return err;
|
||||
}
|
||||
|
||||
int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int outLengthHint)
|
||||
int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long outLengthHint)
|
||||
{
|
||||
unsigned int outLength = 0;
|
||||
long outLength = 0;
|
||||
int err = ccInflateMemoryWithHint(in, inLength, out, &outLength, outLengthHint);
|
||||
|
||||
if (err != Z_OK || *out == NULL) {
|
||||
|
@ -223,7 +223,7 @@ int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength,
|
|||
return outLength;
|
||||
}
|
||||
|
||||
int ZipUtils::ccInflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out)
|
||||
int ZipUtils::ccInflateMemory(unsigned char *in, long inLength, unsigned char **out)
|
||||
{
|
||||
// 256k for hint
|
||||
return ccInflateMemoryWithHint(in, inLength, out, 256 * 1024);
|
||||
|
@ -304,7 +304,7 @@ bool ZipUtils::ccIsCCZFile(const char *path)
|
|||
// load file into memory
|
||||
unsigned char* compressed = NULL;
|
||||
|
||||
unsigned long fileLen = 0;
|
||||
long fileLen = 0;
|
||||
compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen);
|
||||
|
||||
if(NULL == compressed || 0 == fileLen)
|
||||
|
@ -316,7 +316,7 @@ bool ZipUtils::ccIsCCZFile(const char *path)
|
|||
return ccIsCCZBuffer(compressed, fileLen);
|
||||
}
|
||||
|
||||
bool ZipUtils::ccIsCCZBuffer(const unsigned char *buffer, int len)
|
||||
bool ZipUtils::ccIsCCZBuffer(const unsigned char *buffer, long len)
|
||||
{
|
||||
if (len < sizeof(struct CCZHeader))
|
||||
{
|
||||
|
@ -333,7 +333,7 @@ bool ZipUtils::ccIsGZipFile(const char *path)
|
|||
// load file into memory
|
||||
unsigned char* compressed = NULL;
|
||||
|
||||
unsigned long fileLen = 0;
|
||||
long fileLen = 0;
|
||||
compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen);
|
||||
|
||||
if(NULL == compressed || 0 == fileLen)
|
||||
|
@ -345,7 +345,7 @@ bool ZipUtils::ccIsGZipFile(const char *path)
|
|||
return ccIsGZipBuffer(compressed, fileLen);
|
||||
}
|
||||
|
||||
bool ZipUtils::ccIsGZipBuffer(const unsigned char *buffer, int len)
|
||||
bool ZipUtils::ccIsGZipBuffer(const unsigned char *buffer, long len)
|
||||
{
|
||||
if (len < 2)
|
||||
{
|
||||
|
@ -356,7 +356,7 @@ bool ZipUtils::ccIsGZipBuffer(const unsigned char *buffer, int len)
|
|||
}
|
||||
|
||||
|
||||
int ZipUtils::ccInflateCCZBuffer(const unsigned char *buffer, int bufferLen, unsigned char **out)
|
||||
int ZipUtils::ccInflateCCZBuffer(const unsigned char *buffer, long bufferLen, unsigned char **out)
|
||||
{
|
||||
struct CCZHeader *header = (struct CCZHeader*) buffer;
|
||||
|
||||
|
@ -454,7 +454,7 @@ int ZipUtils::ccInflateCCZFile(const char *path, unsigned char **out)
|
|||
// load file into memory
|
||||
unsigned char* compressed = NULL;
|
||||
|
||||
unsigned long fileLen = 0;
|
||||
long fileLen = 0;
|
||||
compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen);
|
||||
|
||||
if(NULL == compressed || 0 == fileLen)
|
||||
|
@ -582,7 +582,7 @@ bool ZipFile::fileExists(const std::string &fileName) const
|
|||
return ret;
|
||||
}
|
||||
|
||||
unsigned char *ZipFile::getFileData(const std::string &fileName, unsigned long *pSize)
|
||||
unsigned char *ZipFile::getFileData(const std::string &fileName, long *pSize)
|
||||
{
|
||||
unsigned char * pBuffer = NULL;
|
||||
if (pSize)
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace cocos2d
|
|||
*
|
||||
@since v0.8.1
|
||||
*/
|
||||
static int ccInflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out);
|
||||
static int ccInflateMemory(unsigned char *in, long inLength, unsigned char **out);
|
||||
|
||||
/**
|
||||
* Inflates either zlib or gzip deflated memory. The inflated memory is
|
||||
|
@ -76,7 +76,7 @@ namespace cocos2d
|
|||
*
|
||||
@since v1.0.0
|
||||
*/
|
||||
static int ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int outLenghtHint);
|
||||
static int ccInflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long outLenghtHint);
|
||||
|
||||
/** inflates a GZip file into memory
|
||||
*
|
||||
|
@ -100,7 +100,7 @@ namespace cocos2d
|
|||
*
|
||||
* @since v3.0
|
||||
*/
|
||||
static bool ccIsGZipBuffer(const unsigned char *buffer, int len);
|
||||
static bool ccIsGZipBuffer(const unsigned char *buffer, long len);
|
||||
|
||||
/** inflates a CCZ file into memory
|
||||
*
|
||||
|
@ -116,7 +116,7 @@ namespace cocos2d
|
|||
*
|
||||
* @since v3.0
|
||||
*/
|
||||
static int ccInflateCCZBuffer(const unsigned char *buffer, int len, unsigned char **out);
|
||||
static int ccInflateCCZBuffer(const unsigned char *buffer, long len, unsigned char **out);
|
||||
|
||||
/** test a file is a CCZ format file or not
|
||||
*
|
||||
|
@ -132,7 +132,7 @@ namespace cocos2d
|
|||
*
|
||||
* @since v3.0
|
||||
*/
|
||||
static bool ccIsCCZBuffer(const unsigned char *buffer, int len);
|
||||
static bool ccIsCCZBuffer(const unsigned char *buffer, long len);
|
||||
|
||||
/** Sets the pvr.ccz encryption key parts separately for added
|
||||
* security.
|
||||
|
@ -187,10 +187,10 @@ namespace cocos2d
|
|||
static void ccSetPvrEncryptionKey(unsigned int keyPart1, unsigned int keyPart2, unsigned int keyPart3, unsigned int keyPart4);
|
||||
|
||||
private:
|
||||
static int ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int *outLength,
|
||||
unsigned int outLenghtHint);
|
||||
static inline void ccDecodeEncodedPvr (unsigned int *data, int len);
|
||||
static inline unsigned int ccChecksumPvr(const unsigned int *data, int len);
|
||||
static int ccInflateMemoryWithHint(unsigned char *in, long inLength, unsigned char **out, long *outLength,
|
||||
long outLenghtHint);
|
||||
static inline void ccDecodeEncodedPvr (unsigned int *data, long len);
|
||||
static inline unsigned int ccChecksumPvr(const unsigned int *data, long len);
|
||||
|
||||
static unsigned int s_uEncryptedPvrKeyParts[4];
|
||||
static unsigned int s_uEncryptionKey[1024];
|
||||
|
@ -253,7 +253,7 @@ namespace cocos2d
|
|||
*
|
||||
* @since v2.0.5
|
||||
*/
|
||||
unsigned char *getFileData(const std::string &fileName, unsigned long *pSize);
|
||||
unsigned char *getFileData(const std::string &fileName, long *size);
|
||||
|
||||
private:
|
||||
/** Internal data like zip file pointer / file list array and so on */
|
||||
|
|
|
@ -488,7 +488,7 @@ void FileUtils::purgeCachedEntries()
|
|||
_fullPathCache.clear();
|
||||
}
|
||||
|
||||
unsigned char* FileUtils::getFileData(const char* filename, const char* mode, unsigned long * size)
|
||||
unsigned char* FileUtils::getFileData(const char* filename, const char* mode, long *size)
|
||||
{
|
||||
unsigned char * buffer = NULL;
|
||||
CCASSERT(filename != NULL && size != NULL && mode != NULL, "Invalid parameters.");
|
||||
|
@ -518,7 +518,7 @@ unsigned char* FileUtils::getFileData(const char* filename, const char* mode, un
|
|||
return buffer;
|
||||
}
|
||||
|
||||
unsigned char* FileUtils::getFileDataFromZip(const char* zipFilePath, const char* filename, unsigned long * size)
|
||||
unsigned char* FileUtils::getFileDataFromZip(const char* zipFilePath, const char* filename, long *size)
|
||||
{
|
||||
unsigned char * buffer = NULL;
|
||||
unzFile pFile = NULL;
|
||||
|
|
|
@ -88,7 +88,7 @@ public:
|
|||
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
||||
* @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned.
|
||||
*/
|
||||
virtual unsigned char* getFileData(const char* filename, const char* mode, unsigned long * size);
|
||||
virtual unsigned char* getFileData(const char* filename, const char* mode, long *size);
|
||||
|
||||
/**
|
||||
* Gets resource file data from a zip file.
|
||||
|
@ -98,7 +98,7 @@ public:
|
|||
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
||||
* @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned.
|
||||
*/
|
||||
virtual unsigned char* getFileDataFromZip(const char* zipFilePath, const char* filename, unsigned long *size);
|
||||
virtual unsigned char* getFileDataFromZip(const char* zipFilePath, const char* filename, long *size);
|
||||
|
||||
|
||||
/** Returns the fullpath for a given filename.
|
||||
|
|
|
@ -119,10 +119,10 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
bool initWithImageData(const unsigned char * data, int dataLen);
|
||||
bool initWithImageData(const unsigned char * data, long dataLen);
|
||||
|
||||
// @warning kFmtRawData only support RGBA8888
|
||||
bool initWithRawData(const unsigned char * data, int dataLen, int width, int height, int bitsPerComponent, bool preMulti = false);
|
||||
bool initWithRawData(const unsigned char * data, long dataLen, long width, long height, long bitsPerComponent, bool preMulti = false);
|
||||
|
||||
/**
|
||||
@brief Create image with specified string.
|
||||
|
|
|
@ -416,7 +416,7 @@ bool Image::initWithImageFile(const char * strPath)
|
|||
|
||||
SDL_FreeSurface(iSurf);
|
||||
#else
|
||||
unsigned long bufferLen = 0;
|
||||
long bufferLen = 0;
|
||||
unsigned char* buffer = FileUtils::getInstance()->getFileData(fullPath.c_str(), "rb", &bufferLen);
|
||||
|
||||
if (buffer != nullptr && bufferLen > 0)
|
||||
|
@ -432,23 +432,23 @@ bool Image::initWithImageFile(const char * strPath)
|
|||
|
||||
bool Image::initWithImageFileThreadSafe(const char *fullpath)
|
||||
{
|
||||
bool bRet = false;
|
||||
unsigned long dataLen = 0;
|
||||
bool ret = false;
|
||||
long dataLen = 0;
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
FileUtilsAndroid *fileUitls = (FileUtilsAndroid*)FileUtils::getInstance();
|
||||
unsigned char *pBuffer = fileUitls->getFileDataForAsync(fullpath, "rb", &dataLen);
|
||||
unsigned char *buffer = fileUitls->getFileDataForAsync(fullpath, "rb", &dataLen);
|
||||
#else
|
||||
unsigned char *pBuffer = FileUtils::getInstance()->getFileData(fullpath, "rb", &dataLen);
|
||||
unsigned char *buffer = FileUtils::getInstance()->getFileData(fullpath, "rb", &dataLen);
|
||||
#endif
|
||||
if (pBuffer != NULL && dataLen > 0)
|
||||
if (buffer != NULL && dataLen > 0)
|
||||
{
|
||||
bRet = initWithImageData(pBuffer, dataLen);
|
||||
ret = initWithImageData(buffer, dataLen);
|
||||
}
|
||||
CC_SAFE_DELETE_ARRAY(pBuffer);
|
||||
return bRet;
|
||||
CC_SAFE_DELETE_ARRAY(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Image::initWithImageData(const unsigned char * data, int dataLen)
|
||||
bool Image::initWithImageData(const unsigned char * data, long dataLen)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
|
@ -1190,13 +1190,13 @@ bool Image::initWithPVRv2Data(const unsigned char * data, int dataLen)
|
|||
|
||||
if (!testFormatForPvr2TCSupport(formatFlags))
|
||||
{
|
||||
CCLOG("cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", formatFlags);
|
||||
CCLOG("cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", (int)formatFlags);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (v2_pixel_formathash.find(formatFlags) == v2_pixel_formathash.end())
|
||||
{
|
||||
CCLOG("cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", formatFlags);
|
||||
CCLOG("cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", (int)formatFlags);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1204,7 +1204,7 @@ bool Image::initWithPVRv2Data(const unsigned char * data, int dataLen)
|
|||
|
||||
if (it == Texture2D::getPixelFormatInfoMap().end())
|
||||
{
|
||||
CCLOG("cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", formatFlags);
|
||||
CCLOG("cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", (int)formatFlags);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1757,7 +1757,7 @@ bool Image::initWithWebpData(const unsigned char * data, int dataLen)
|
|||
return bRet;
|
||||
}
|
||||
|
||||
bool Image::initWithRawData(const unsigned char * data, int dataLen, int width, int height, int bitsPerComponent, bool preMulti)
|
||||
bool Image::initWithRawData(const unsigned char * data, long dataLen, long width, long height, long bitsPerComponent, bool preMulti)
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
|
|
|
@ -114,15 +114,15 @@ bool SAXParser::parse(const char* pXMLData, unsigned int uDataLength)
|
|||
|
||||
bool SAXParser::parse(const char *pszFile)
|
||||
{
|
||||
bool bRet = false;
|
||||
unsigned long size = 0;
|
||||
bool ret = false;
|
||||
long size = 0;
|
||||
char* pBuffer = (char*)FileUtils::getInstance()->getFileData(pszFile, "rt", &size);
|
||||
if (pBuffer != NULL && size > 0)
|
||||
{
|
||||
bRet = parse(pBuffer, size);
|
||||
ret = parse(pBuffer, size);
|
||||
}
|
||||
CC_SAFE_DELETE_ARRAY(pBuffer);
|
||||
return bRet;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SAXParser::startElement(void *ctx, const CC_XML_CHAR *name, const CC_XML_CHAR **atts)
|
||||
|
|
|
@ -130,21 +130,21 @@ bool FileUtilsAndroid::isAbsolutePath(const std::string& strPath) const
|
|||
}
|
||||
|
||||
|
||||
unsigned char* FileUtilsAndroid::getFileData(const char* filename, const char* pszMode, unsigned long * pSize)
|
||||
unsigned char* FileUtilsAndroid::getFileData(const char* filename, const char* mode, long * size)
|
||||
{
|
||||
return doGetFileData(filename, pszMode, pSize, false);
|
||||
return doGetFileData(filename, mode, size, false);
|
||||
}
|
||||
|
||||
unsigned char* FileUtilsAndroid::getFileDataForAsync(const char* filename, const char* pszMode, unsigned long * pSize)
|
||||
unsigned char* FileUtilsAndroid::getFileDataForAsync(const char* filename, const char* pszMode, long * pSize)
|
||||
{
|
||||
return doGetFileData(filename, pszMode, pSize, true);
|
||||
}
|
||||
|
||||
unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char* pszMode, unsigned long * pSize, bool forAsync)
|
||||
unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char* mode, long * size, bool forAsync)
|
||||
{
|
||||
unsigned char * pData = 0;
|
||||
unsigned char * data = 0;
|
||||
|
||||
if ((! filename) || (! pszMode) || 0 == strlen(filename))
|
||||
if ((! filename) || (! mode) || 0 == strlen(filename))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -189,14 +189,14 @@ unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char*
|
|||
return NULL;
|
||||
}
|
||||
|
||||
off_t size = AAsset_getLength(asset);
|
||||
off_t fileSize = AAsset_getLength(asset);
|
||||
|
||||
pData = new unsigned char[size];
|
||||
data = new unsigned char[fileSize];
|
||||
|
||||
int bytesread = AAsset_read(asset, (void*)pData, size);
|
||||
if (pSize)
|
||||
int bytesread = AAsset_read(asset, (void*)data, fileSize);
|
||||
if (size)
|
||||
{
|
||||
*pSize = bytesread;
|
||||
*size = bytesread;
|
||||
}
|
||||
|
||||
AAsset_close(asset);
|
||||
|
@ -207,32 +207,32 @@ unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char*
|
|||
{
|
||||
// read rrom other path than user set it
|
||||
//CCLOG("GETTING FILE ABSOLUTE DATA: %s", filename);
|
||||
FILE *fp = fopen(fullPath.c_str(), pszMode);
|
||||
FILE *fp = fopen(fullPath.c_str(), mode);
|
||||
CC_BREAK_IF(!fp);
|
||||
|
||||
unsigned long size;
|
||||
long fileSize;
|
||||
fseek(fp,0,SEEK_END);
|
||||
size = ftell(fp);
|
||||
fileSize = ftell(fp);
|
||||
fseek(fp,0,SEEK_SET);
|
||||
pData = new unsigned char[size];
|
||||
size = fread(pData,sizeof(unsigned char), size,fp);
|
||||
data = new unsigned char[fileSize];
|
||||
fileSize = fread(data,sizeof(unsigned char), fileSize,fp);
|
||||
fclose(fp);
|
||||
|
||||
if (pSize)
|
||||
if (size)
|
||||
{
|
||||
*pSize = size;
|
||||
*size = fileSize;
|
||||
}
|
||||
} while (0);
|
||||
}
|
||||
|
||||
if (! pData)
|
||||
if (! data)
|
||||
{
|
||||
std::string msg = "Get data from file(";
|
||||
msg.append(filename).append(") failed!");
|
||||
CCLOG("%s", msg.c_str());
|
||||
}
|
||||
|
||||
return pData;
|
||||
return data;
|
||||
}
|
||||
|
||||
string FileUtilsAndroid::getWritablePath() const
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
|
||||
/* override funtions */
|
||||
bool init();
|
||||
virtual unsigned char* getFileData(const char* filename, const char* pszMode, unsigned long * pSize);
|
||||
virtual unsigned char* getFileData(const char* filename, const char* mode, long * size);
|
||||
|
||||
virtual std::string getWritablePath() const;
|
||||
virtual bool isFileExist(const std::string& strFilePath) const;
|
||||
|
@ -64,10 +64,10 @@ public:
|
|||
/** This function is android specific. It is used for TextureCache::addImageAsync().
|
||||
Don't use it in your codes.
|
||||
*/
|
||||
unsigned char* getFileDataForAsync(const char* filename, const char* pszMode, unsigned long * pSize);
|
||||
unsigned char* getFileDataForAsync(const char* filename, const char* mode, long * size);
|
||||
|
||||
private:
|
||||
unsigned char* doGetFileData(const char* filename, const char* pszMode, unsigned long * pSize, bool forAsync);
|
||||
unsigned char* doGetFileData(const char* filename, const char* mode, long * size, bool forAsync);
|
||||
static AAssetManager* assetmanager;
|
||||
};
|
||||
|
||||
|
|
0
cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxEditBoxDialog.java
Executable file → Normal file
0
cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxEditBoxDialog.java
Executable file → Normal file
0
cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java
Executable file → Normal file
0
cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java
Executable file → Normal file
0
cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxSound.java
Executable file → Normal file
0
cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxSound.java
Executable file → Normal file
|
@ -292,7 +292,7 @@ static void engine_term_display(struct engine* engine) {
|
|||
/*
|
||||
* Get X, Y positions and ID's for all pointers
|
||||
*/
|
||||
static void getTouchPos(AInputEvent *event, int ids[], float xs[], float ys[]) {
|
||||
static void getTouchPos(AInputEvent *event, long ids[], float xs[], float ys[]) {
|
||||
int pointerCount = AMotionEvent_getPointerCount(event);
|
||||
for(int i = 0; i < pointerCount; ++i) {
|
||||
ids[i] = AMotionEvent_getPointerId(event, i);
|
||||
|
@ -321,7 +321,7 @@ static int32_t handle_touch_input(AInputEvent *event) {
|
|||
|
||||
LOG_EVENTS_DEBUG("Event: Action DOWN x=%f y=%f pointerID=%d\n",
|
||||
xP, yP, pointerId);
|
||||
int pId = pointerId;
|
||||
long pId = pointerId;
|
||||
float x = xP;
|
||||
float y = yP;
|
||||
|
||||
|
@ -340,7 +340,7 @@ static int32_t handle_touch_input(AInputEvent *event) {
|
|||
|
||||
LOG_EVENTS_DEBUG("Event: Action POINTER DOWN x=%f y=%f pointerID=%d\n",
|
||||
xP, yP, pointerId);
|
||||
int pId = pointerId;
|
||||
long pId = pointerId;
|
||||
float x = xP;
|
||||
float y = yP;
|
||||
|
||||
|
@ -353,10 +353,10 @@ static int32_t handle_touch_input(AInputEvent *event) {
|
|||
{
|
||||
LOG_EVENTS_DEBUG("AMOTION_EVENT_ACTION_MOVE");
|
||||
int pointerCount = AMotionEvent_getPointerCount(event);
|
||||
int ids[pointerCount];
|
||||
long ids[pointerCount];
|
||||
float xs[pointerCount], ys[pointerCount];
|
||||
getTouchPos(event, ids, xs, ys);
|
||||
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(pointerCount, ids, xs, ys);
|
||||
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(pointerCount, ids, xs, ys);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
@ -369,7 +369,7 @@ static int32_t handle_touch_input(AInputEvent *event) {
|
|||
float yP = AMotionEvent_getY(event,0);
|
||||
LOG_EVENTS_DEBUG("Event: Action UP x=%f y=%f pointerID=%d\n",
|
||||
xP, yP, pointerId);
|
||||
int pId = pointerId;
|
||||
long pId = pointerId;
|
||||
float x = xP;
|
||||
float y = yP;
|
||||
|
||||
|
@ -387,7 +387,7 @@ static int32_t handle_touch_input(AInputEvent *event) {
|
|||
float yP = AMotionEvent_getY(event,pointerIndex);
|
||||
LOG_EVENTS_DEBUG("Event: Action POINTER UP x=%f y=%f pointerID=%d\n",
|
||||
xP, yP, pointerIndex);
|
||||
int pId = pointerId;
|
||||
long pId = pointerId;
|
||||
float x = xP;
|
||||
float y = yP;
|
||||
|
||||
|
@ -400,10 +400,10 @@ static int32_t handle_touch_input(AInputEvent *event) {
|
|||
{
|
||||
LOG_EVENTS_DEBUG("AMOTION_EVENT_ACTION_CANCEL");
|
||||
int pointerCount = AMotionEvent_getPointerCount(event);
|
||||
int ids[pointerCount];
|
||||
long ids[pointerCount];
|
||||
float xs[pointerCount], ys[pointerCount];
|
||||
getTouchPos(event, ids, xs, ys);
|
||||
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesCancel(pointerCount, ids, xs, ys);
|
||||
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesCancel(pointerCount, ids, xs, ys);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -7,8 +7,14 @@ add_library(audio STATIC
|
|||
${AUDIO_SRC}
|
||||
)
|
||||
|
||||
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
|
||||
set(FMOD_LIB "fmodex64")
|
||||
else()
|
||||
set(FMOD_LIB "fmodex")
|
||||
endif()
|
||||
|
||||
target_link_libraries(audio
|
||||
fmodex64
|
||||
${FMOD_LIB}
|
||||
)
|
||||
|
||||
set_target_properties(audio
|
||||
|
|
|
@ -96,6 +96,16 @@ bool Point::operator!=(const Point& right)
|
|||
return this->x != right.x || this->y != right.y;
|
||||
}
|
||||
|
||||
bool Point::operator==(const Point& right) const
|
||||
{
|
||||
return this->x == right.x && this->y == right.y;
|
||||
}
|
||||
|
||||
bool Point::operator!=(const Point& right) const
|
||||
{
|
||||
return this->x != right.x || this->y != right.y;
|
||||
}
|
||||
|
||||
Point Point::operator*(float a) const
|
||||
{
|
||||
return Point(this->x * a, this->y * a);
|
||||
|
@ -283,7 +293,16 @@ Point Point::getIntersectPoint(const Point& A, const Point& B, const Point& C, c
|
|||
return Point::ZERO;
|
||||
}
|
||||
|
||||
const Point Point::ZERO = Point(0, 0);
|
||||
const Point Point::ZERO = Point(0.0f, 0.0f);
|
||||
const Point Point::ANCHOR_MIDDLE = Point(0.5f, 0.5f);
|
||||
const Point Point::ANCHOR_BOTTOM_LEFT = Point(0.0f, 0.0f);
|
||||
const Point Point::ANCHOR_TOP_LEFT = Point(0.0f, 1.0f);
|
||||
const Point Point::ANCHOR_BOTTOM_RIGHT = Point(1.0f, 0.0f);
|
||||
const Point Point::ANCHOR_TOP_RIGHT = Point(1.0f, 1.0f);
|
||||
const Point Point::ANCHOR_MIDDLE_RIGHT = Point(1.0f, 0.5f);
|
||||
const Point Point::ANCHOR_MIDDLE_LEFT = Point(0.0f, 0.5f);
|
||||
const Point Point::ANCHOR_MIDDLE_TOP = Point(0.5f, 1.0f);
|
||||
const Point Point::ANCHOR_MIDDLE_BOTTOM = Point(0.5f, 0.0f);
|
||||
|
||||
// implementation of Size
|
||||
|
||||
|
|
|
@ -123,6 +123,16 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
bool operator!=(const Point& right);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
bool operator==(const Point& right) const;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
bool operator!=(const Point& right) const;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -423,7 +433,26 @@ public:
|
|||
*/
|
||||
static Point getIntersectPoint(const Point& A, const Point& B, const Point& C, const Point& D);
|
||||
|
||||
/** equals to Point(0,0) */
|
||||
static const Point ZERO;
|
||||
/** equals to Point(0.5, 0.5) */
|
||||
static const Point ANCHOR_MIDDLE;
|
||||
/** equals to Point(0, 0) */
|
||||
static const Point ANCHOR_BOTTOM_LEFT;
|
||||
/** equals to Point(0, 1) */
|
||||
static const Point ANCHOR_TOP_LEFT;
|
||||
/** equals to Point(1, 0) */
|
||||
static const Point ANCHOR_BOTTOM_RIGHT;
|
||||
/** equals to Point(1, 1) */
|
||||
static const Point ANCHOR_TOP_RIGHT;
|
||||
/** equals to Point(1, 0.5) */
|
||||
static const Point ANCHOR_MIDDLE_RIGHT;
|
||||
/** equals to Point(0, 0.5) */
|
||||
static const Point ANCHOR_MIDDLE_LEFT;
|
||||
/** equals to Point(0.5, 1) */
|
||||
static const Point ANCHOR_MIDDLE_TOP;
|
||||
/** equals to Point(0.5, 0) */
|
||||
static const Point ANCHOR_MIDDLE_BOTTOM;
|
||||
|
||||
private:
|
||||
// returns true if segment A-B intersects with segment C-D. S->E is the ovderlap part
|
||||
|
|
|
@ -216,15 +216,15 @@ bool String::isEqual(const Object* pObject)
|
|||
|
||||
String* String::create(const std::string& str)
|
||||
{
|
||||
String* pRet = new String(str);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
String* ret = new String(str);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
String* String::createWithData(const unsigned char* pData, unsigned long nLen)
|
||||
String* String::createWithData(const unsigned char* data, unsigned long nLen)
|
||||
{
|
||||
String* pRet = NULL;
|
||||
if (pData != NULL)
|
||||
String* ret = NULL;
|
||||
if (data != NULL)
|
||||
{
|
||||
char* pStr = (char*)malloc(nLen+1);
|
||||
if (pStr != NULL)
|
||||
|
@ -232,36 +232,36 @@ String* String::createWithData(const unsigned char* pData, unsigned long nLen)
|
|||
pStr[nLen] = '\0';
|
||||
if (nLen > 0)
|
||||
{
|
||||
memcpy(pStr, pData, nLen);
|
||||
memcpy(pStr, data, nLen);
|
||||
}
|
||||
|
||||
pRet = String::create(pStr);
|
||||
ret = String::create(pStr);
|
||||
free(pStr);
|
||||
}
|
||||
}
|
||||
return pRet;
|
||||
return ret;
|
||||
}
|
||||
|
||||
String* String::createWithFormat(const char* format, ...)
|
||||
{
|
||||
String* pRet = String::create("");
|
||||
String* ret = String::create("");
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
pRet->initWithFormatAndValist(format, ap);
|
||||
ret->initWithFormatAndValist(format, ap);
|
||||
va_end(ap);
|
||||
|
||||
return pRet;
|
||||
return ret;
|
||||
}
|
||||
|
||||
String* String::createWithContentsOfFile(const char* filename)
|
||||
{
|
||||
unsigned long size = 0;
|
||||
unsigned char* pData = 0;
|
||||
String* pRet = NULL;
|
||||
pData = FileUtils::getInstance()->getFileData(filename, "rb", &size);
|
||||
pRet = String::createWithData(pData, size);
|
||||
CC_SAFE_DELETE_ARRAY(pData);
|
||||
return pRet;
|
||||
long size = 0;
|
||||
unsigned char* data = 0;
|
||||
String* ret = NULL;
|
||||
data = FileUtils::getInstance()->getFileData(filename, "rb", &size);
|
||||
ret = String::createWithData(data, size);
|
||||
CC_SAFE_DELETE_ARRAY(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void String::acceptVisitor(DataVisitor &visitor)
|
||||
|
|
|
@ -244,7 +244,7 @@ Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, Object *pOwner,
|
|||
}
|
||||
|
||||
std::string strPath = FileUtils::getInstance()->fullPathForFilename(strCCBFileName.c_str());
|
||||
unsigned long size = 0;
|
||||
long size = 0;
|
||||
|
||||
unsigned char * pBytes = FileUtils::getInstance()->getFileData(strPath.c_str(), "rb", &size);
|
||||
Data *data = new Data(pBytes, size);
|
||||
|
|
|
@ -918,7 +918,7 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader
|
|||
|
||||
// Load sub file
|
||||
std::string path = FileUtils::getInstance()->fullPathForFilename(ccbFileName.c_str());
|
||||
unsigned long size = 0;
|
||||
long size = 0;
|
||||
unsigned char * pBytes = FileUtils::getInstance()->getFileData(path.c_str(), "rb", &size);
|
||||
|
||||
CCBReader * reader = new CCBReader(pCCBReader);
|
||||
|
|
|
@ -159,7 +159,7 @@ void ActionNode::initActionNodeFromRoot(Object* root)
|
|||
UIWidget* rootWidget = dynamic_cast<UIWidget*>(root);
|
||||
if (rootWidget != NULL)
|
||||
{
|
||||
UIWidget* widget = UIHelper::instance()->seekActionWidgetByActionTag(rootWidget, getActionTag());
|
||||
UIWidget* widget = UIHelper::seekActionWidgetByActionTag(rootWidget, getActionTag());
|
||||
if (widget != NULL)
|
||||
{
|
||||
setObject(widget);
|
||||
|
|
|
@ -335,7 +335,7 @@ void Armature::changeBoneParent(Bone *bone, const char *parentName)
|
|||
}
|
||||
}
|
||||
|
||||
const Dictionary *Armature::getBoneDic() const
|
||||
Dictionary *Armature::getBoneDic() const
|
||||
{
|
||||
return _boneDic;
|
||||
}
|
||||
|
@ -451,8 +451,7 @@ void Armature::update(float dt)
|
|||
{
|
||||
_animation->update(dt);
|
||||
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_topBoneList, object)
|
||||
for (auto object : *_topBoneList)
|
||||
{
|
||||
static_cast<Bone*>(object)->update(dt);
|
||||
}
|
||||
|
@ -468,8 +467,7 @@ void Armature::draw()
|
|||
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
|
||||
}
|
||||
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_children, object)
|
||||
for (auto object : *_children)
|
||||
{
|
||||
if (Bone *bone = dynamic_cast<Bone *>(object))
|
||||
{
|
||||
|
@ -642,8 +640,7 @@ Rect Armature::getBoundingBox() const
|
|||
|
||||
Rect boundingBox = Rect(0, 0, 0, 0);
|
||||
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_children, object)
|
||||
for(auto object : *_children)
|
||||
{
|
||||
if (Bone *bone = dynamic_cast<Bone *>(object))
|
||||
{
|
||||
|
@ -754,17 +751,15 @@ void Armature::setBody(b2Body *body)
|
|||
_body = body;
|
||||
_body->SetUserData(this);
|
||||
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_children, object)
|
||||
for(auto object : *_children)
|
||||
{
|
||||
if (Bone *bone = dynamic_cast<Bone *>(object))
|
||||
{
|
||||
Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList();
|
||||
|
||||
Object *displayObject = nullptr;
|
||||
CCARRAY_FOREACH(displayList, displayObject)
|
||||
for(auto displayObject : displayList)
|
||||
{
|
||||
ColliderDetector *detector = ((DecorativeDisplay *)displayObject)->getColliderDetector();
|
||||
ColliderDetector *detector = static_cast<DecorativeDisplay *>(displayObject)->getColliderDetector();
|
||||
if (detector != nullptr)
|
||||
{
|
||||
detector->setBody(_body);
|
||||
|
@ -802,17 +797,15 @@ void Armature::setBody(cpBody *body)
|
|||
_body = body;
|
||||
_body->data = this;
|
||||
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_children, object)
|
||||
for(auto object: *_children)
|
||||
{
|
||||
if (Bone *bone = dynamic_cast<Bone *>(object))
|
||||
{
|
||||
Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList();
|
||||
|
||||
Object *displayObject = nullptr;
|
||||
CCARRAY_FOREACH(displayList, displayObject)
|
||||
for(auto displayObject: *displayList)
|
||||
{
|
||||
ColliderDetector *detector = ((DecorativeDisplay *)displayObject)->getColliderDetector();
|
||||
ColliderDetector *detector = static_cast<DecorativeDisplay *>(displayObject)->getColliderDetector();
|
||||
if (detector != nullptr)
|
||||
{
|
||||
detector->setBody(_body);
|
||||
|
|
|
@ -94,7 +94,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
~Armature(void);
|
||||
virtual ~Armature(void);
|
||||
|
||||
/**
|
||||
* Init the empty armature
|
||||
|
@ -140,7 +140,7 @@ public:
|
|||
* Get Armature's bone dictionary
|
||||
* @return Armature's bone dictionary
|
||||
*/
|
||||
const cocos2d::Dictionary *getBoneDic() const;
|
||||
cocos2d::Dictionary *getBoneDic() const;
|
||||
|
||||
/**
|
||||
* This boundingBox will calculate all bones' boundingBox every time
|
||||
|
@ -180,10 +180,10 @@ public:
|
|||
|
||||
|
||||
virtual void setArmatureData(ArmatureData *armatureData) { _armatureData = armatureData; }
|
||||
virtual const ArmatureData *getArmatureData() const { return _armatureData; }
|
||||
virtual ArmatureData *getArmatureData() const { return _armatureData; }
|
||||
|
||||
virtual void setBatchNode(BatchNode *batchNode) { _batchNode = batchNode; }
|
||||
virtual const BatchNode *getBatchNode() const { return _batchNode; }
|
||||
virtual BatchNode *getBatchNode() const { return _batchNode; }
|
||||
|
||||
virtual void setName(const std::string &name) { _name = name; }
|
||||
virtual const std::string &getName() const { return _name; }
|
||||
|
|
|
@ -94,8 +94,7 @@ bool ArmatureAnimation::init(Armature *armature)
|
|||
|
||||
void ArmatureAnimation:: pause()
|
||||
{
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_tweenList, object)
|
||||
for(auto object : *_tweenList)
|
||||
{
|
||||
static_cast<Tween*>(object)->pause();
|
||||
}
|
||||
|
@ -104,8 +103,7 @@ void ArmatureAnimation:: pause()
|
|||
|
||||
void ArmatureAnimation::resume()
|
||||
{
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_tweenList, object)
|
||||
for(auto object : *_tweenList)
|
||||
{
|
||||
static_cast<Tween*>(object)->resume();
|
||||
}
|
||||
|
@ -114,8 +112,7 @@ void ArmatureAnimation::resume()
|
|||
|
||||
void ArmatureAnimation::stop()
|
||||
{
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_tweenList, object)
|
||||
for(auto object : *_tweenList)
|
||||
{
|
||||
static_cast<Tween*>(object)->stop();
|
||||
}
|
||||
|
@ -302,8 +299,7 @@ void ArmatureAnimation::gotoAndPlay(int frameIndex)
|
|||
_currentPercent = (float)_curFrameIndex / (float)_movementData->duration;
|
||||
_currentFrame = _nextFrameIndex * _currentPercent;
|
||||
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_tweenList, object)
|
||||
for(auto object : *_tweenList)
|
||||
{
|
||||
static_cast<Tween *>(object)->gotoAndPlay(frameIndex);
|
||||
}
|
||||
|
@ -327,8 +323,8 @@ int ArmatureAnimation::getMovementCount() const
|
|||
void ArmatureAnimation::update(float dt)
|
||||
{
|
||||
ProcessBase::update(dt);
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_tweenList, object)
|
||||
|
||||
for(auto object : *_tweenList)
|
||||
{
|
||||
static_cast<Tween *>(object)->update(dt);
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ void ArmatureDataManager::removeArmatureFileInfo(const char *configFilePath)
|
|||
}
|
||||
|
||||
_relativeDatas.erase(configFilePath);
|
||||
DataReaderHelper::sharedDataReaderHelper()->removeConfigFile(configFilePath);
|
||||
DataReaderHelper::getInstance()->removeConfigFile(configFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,8 +90,7 @@ void BatchNode::addChild(Node *child, int zOrder, int tag)
|
|||
Bone *bone = static_cast<Bone*>(element->getObject());
|
||||
|
||||
Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList();
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(displayList, object)
|
||||
for(auto object : *displayList)
|
||||
{
|
||||
DecorativeDisplay *display = static_cast<DecorativeDisplay*>(object);
|
||||
|
||||
|
@ -118,8 +117,7 @@ void BatchNode::removeChild(Node* child, bool cleanup)
|
|||
Bone *bone = static_cast<Bone*>(element->getObject());
|
||||
|
||||
Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList();
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(displayList, object)
|
||||
for(auto object : *displayList)
|
||||
{
|
||||
DecorativeDisplay *display = static_cast<DecorativeDisplay*>(object);
|
||||
|
||||
|
@ -166,8 +164,8 @@ void BatchNode::visit()
|
|||
void BatchNode::draw()
|
||||
{
|
||||
CC_NODE_DRAW_SETUP();
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_children, object)
|
||||
|
||||
for(auto object : *_children)
|
||||
{
|
||||
Armature *armature = dynamic_cast<Armature *>(object);
|
||||
if (armature)
|
||||
|
|
|
@ -229,11 +229,13 @@ void Bone::update(float delta)
|
|||
|
||||
DisplayFactory::updateDisplay(this, delta, _boneTransformDirty || _armature->getArmatureTransformDirty());
|
||||
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_children, object)
|
||||
if (_children)
|
||||
{
|
||||
Bone *childBone = (Bone *)object;
|
||||
childBone->update(delta);
|
||||
for(auto object : *_children)
|
||||
{
|
||||
Bone *childBone = (Bone *)object;
|
||||
childBone->update(delta);
|
||||
}
|
||||
}
|
||||
|
||||
_boneTransformDirty = false;
|
||||
|
@ -322,16 +324,16 @@ void Bone::addChildBone(Bone *child)
|
|||
|
||||
void Bone::removeChildBone(Bone *bone, bool recursion)
|
||||
{
|
||||
if ( _children->getIndexOfObject(bone) != UINT_MAX )
|
||||
if (_children && _children->getIndexOfObject(bone) != UINT_MAX )
|
||||
{
|
||||
if(recursion)
|
||||
{
|
||||
Array *_ccbones = bone->_children;
|
||||
Object *_object = nullptr;
|
||||
CCARRAY_FOREACH(_ccbones, _object)
|
||||
Array *ccbones = bone->_children;
|
||||
|
||||
for(auto object : *ccbones)
|
||||
{
|
||||
Bone *_ccBone = (Bone *)_object;
|
||||
bone->removeChildBone(_ccBone, recursion);
|
||||
Bone *ccBone = (Bone *)object;
|
||||
bone->removeChildBone(ccBone, recursion);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -412,6 +414,7 @@ DisplayType Bone::getDisplayRenderNodeType()
|
|||
return _displayManager->getDisplayRenderNodeType();
|
||||
}
|
||||
|
||||
|
||||
void Bone::addDisplay(DisplayData *displayData, int index)
|
||||
{
|
||||
_displayManager->addDisplay(displayData, index);
|
||||
|
@ -449,8 +452,8 @@ Array *Bone::getColliderBodyList()
|
|||
void Bone::setColliderFilter(ColliderFilter *filter)
|
||||
{
|
||||
Array *array = _displayManager->getDecorativeDisplayList();
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(array, object)
|
||||
|
||||
for(auto object : *array)
|
||||
{
|
||||
DecorativeDisplay *decoDisplay = static_cast<DecorativeDisplay *>(object);
|
||||
if (ColliderDetector *detector = decoDisplay->getColliderDetector())
|
||||
|
|
|
@ -176,6 +176,11 @@ public:
|
|||
virtual void setIgnoreMovementBoneData(bool ignore) { _ignoreMovementBoneData = ignore; }
|
||||
virtual bool isIgnoreMovementBoneData() const { return _ignoreMovementBoneData; }
|
||||
|
||||
/*
|
||||
* This function is deprecated, please use isIgnoreMovementBoneData()
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE virtual bool getIgnoreMovementBoneData() const { return isIgnoreMovementBoneData(); }
|
||||
|
||||
virtual void setBlendType(BlendType type) { _blendType = type; }
|
||||
virtual BlendType getBlendType() const { return _blendType; }
|
||||
|
||||
|
@ -184,7 +189,7 @@ public:
|
|||
virtual void setName(const std::string &name) { _name = name; }
|
||||
virtual const std::string getName() const { return _name; }
|
||||
|
||||
virtual const BaseData *getWorldInfo() const { return _worldInfo; }
|
||||
virtual BaseData *getWorldInfo() const { return _worldInfo; }
|
||||
protected:
|
||||
void applyParentTransform(Bone *parent);
|
||||
|
||||
|
|
|
@ -198,8 +198,7 @@ void ColliderDetector::addContourData(ContourData *contourData)
|
|||
|
||||
void ColliderDetector::addContourDataList(Array *contourDataList)
|
||||
{
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(contourDataList, object)
|
||||
for(auto object : *contourDataList)
|
||||
{
|
||||
addContourData((ContourData *)object);
|
||||
}
|
||||
|
@ -207,8 +206,7 @@ void ColliderDetector::addContourDataList(Array *contourDataList)
|
|||
|
||||
void ColliderDetector::removeContourData(ContourData *contourData)
|
||||
{
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_colliderBodyList, object)
|
||||
for(auto object : *_colliderBodyList)
|
||||
{
|
||||
ColliderBody *body = (ColliderBody*)object;
|
||||
if (body && body->getContourData() == contourData)
|
||||
|
@ -242,8 +240,7 @@ void ColliderDetector::setActive(bool active)
|
|||
}
|
||||
else
|
||||
{
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_colliderBodyList, object)
|
||||
for(auto object : *_colliderBodyList)
|
||||
{
|
||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||
b2Fixture *fixture = colliderBody->getB2Fixture();
|
||||
|
@ -256,10 +253,9 @@ void ColliderDetector::setActive(bool active)
|
|||
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||
if (_body)
|
||||
{
|
||||
Object *object = nullptr;
|
||||
if (_active)
|
||||
{
|
||||
CCARRAY_FOREACH(_colliderBodyList, object)
|
||||
for(auto object : *_colliderBodyList)
|
||||
{
|
||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||
cpShape *shape = colliderBody->getShape();
|
||||
|
@ -271,7 +267,7 @@ void ColliderDetector::setActive(bool active)
|
|||
}
|
||||
else
|
||||
{
|
||||
CCARRAY_FOREACH(_colliderBodyList, object)
|
||||
for(auto object : *_colliderBodyList)
|
||||
{
|
||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||
cpShape *shape = colliderBody->getShape();
|
||||
|
@ -299,8 +295,7 @@ void ColliderDetector::setColliderFilter(ColliderFilter *filter)
|
|||
{
|
||||
*_filter = *filter;
|
||||
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_colliderBodyList, object)
|
||||
for(auto object : *_colliderBodyList)
|
||||
{
|
||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||
colliderBody->setColliderFilter(filter);
|
||||
|
@ -333,8 +328,7 @@ void ColliderDetector::updateTransform(AffineTransform &t)
|
|||
return;
|
||||
}
|
||||
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_colliderBodyList, object)
|
||||
for(auto object : *_colliderBodyList)
|
||||
{
|
||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||
ContourData *contourData = colliderBody->getContourData();
|
||||
|
@ -408,8 +402,7 @@ void ColliderDetector::setBody(b2Body *pBody)
|
|||
{
|
||||
_body = pBody;
|
||||
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_colliderBodyList, object)
|
||||
for(auto object : *_colliderBodyList)
|
||||
{
|
||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||
|
||||
|
@ -420,7 +413,7 @@ void ColliderDetector::setBody(b2Body *pBody)
|
|||
b2Vec2 *b2bv = new b2Vec2[contourData->vertexList.count()];
|
||||
|
||||
int i = 0;
|
||||
CCARRAY_FOREACH(array, object)
|
||||
for(auto object : *array)
|
||||
{
|
||||
ContourVertex2 *v = (ContourVertex2 *)object;
|
||||
b2bv[i].Set(v->x / PT_RATIO, v->y / PT_RATIO);
|
||||
|
@ -459,8 +452,7 @@ void ColliderDetector::setBody(cpBody *pBody)
|
|||
{
|
||||
_body = pBody;
|
||||
|
||||
Object *object = nullptr;
|
||||
CCARRAY_FOREACH(_colliderBodyList, object)
|
||||
for(auto object : *_colliderBodyList)
|
||||
{
|
||||
ColliderBody *colliderBody = (ColliderBody *)object;
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue