Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into develop_new_label

This commit is contained in:
samuele3hu 2014-04-09 14:29:04 +08:00
commit 1c124f52ad
96 changed files with 1598 additions and 1620 deletions

40
AUTHORS
View File

@ -49,12 +49,20 @@ Developers:
Asynchronous Image loading for Emscripten
DarraghCoy
Fix a potential crash SimpleAudioEngineOpenSL::playEffect
Fix some bugs with Set class
Add ccDrawSolidCircle
Add Rect::unionWithRect
Fix a memory leak in Set::removeAllObjects.
Fixed potential crashes in event dispatch while using SceneGraphPriroity listeners and added helper function to check it
Fixed a potential crash SimpleAudioEngineOpenSL::playEffect
Fixed some bugs with Set class
Added ccDrawSolidCircle
Added Rect::unionWithRect
Fixed a memory leak in Set::removeAllObjects
Fixed for unaligned memory access crash in CCBReader::readFloat()
Fixed for loading custom fonts on iOS when referenced from a CCB file
Fixed CCUserDefault.cpp compiling on Android.
Fixed CCFileUtils 'createXXXXWithContentsOfFile' path lookup issue
Added CCDirector::popToSceneStackLevel(int level)
Fixed a bug that custom font can't be loaded correctly if using full path of filename on android
Fixed potential crashes in EventDispatch while using SceneGraphPriroity listeners and added helper function to check it
Fixed a protential crash in EventDispatch while unregistering listener right after it was registered
Adding an extra verification in Node's destructor
silverscania
Pass correct parameter to glPixelStorei when creating a texture
@ -116,13 +124,6 @@ Developers:
Jimmy Sambuo
fix the bug that SimpleAudioEngine::playEffect() and playBackgroundMusic() play twice on linux
DarraghCoy
fix for loading custom fonts on iOS when referenced from a CCB file
Fix CCUserDefault.cpp compiling on Android.
Fixing CCFileUtils 'createXXXXWithContentsOfFile' path lookup issue.
Add CCDirector::popToSceneStackLevel(int level).
Fixing a bug that custom font can't be loaded correctly if using full path of filename on android.
Waiter
fix an error that OpenSLEngine can't load resources from SD card
add CCRemoveSelf action
@ -349,9 +350,6 @@ Developers:
Fixing a logical error in CCDrawNode::drawPolygon.
Fixing a bug that Jsb function getCPBody return type is not right.
DarraghCoy
Fix for unaligned memory access crash in CCBReader::readFloat().
Sergej Tatarincev (SevInf)
Making ScriptingCore.cpp compiled fine with C++11 on iOS.
Using shared NodeLoaderLibrary in CCBReader bindings.
@ -801,6 +799,16 @@ Developers:
zukkun
Fixed incorrect function invocation in PhysicsBody::setAngularVelocityLimit
dbaack
Fixed a bug that removing and re-adding an event listener will trigger assert
zakmandhro
A typo fix in RELEASE_NOTES.md
mgcL
A potential memory leak fix in value's default constructor
Added ScriptHandlerMgr::destroyInstance to avoid memory leak
Retired Core Developers:
WenSheng Yang

View File

@ -1 +1 @@
f379b6b038206d8dac5b09d1e0957f5f3a67710a
3b9099f5129483bbebfd9aa5daa25fbc6f69dd3a

View File

@ -393,7 +393,10 @@ void Director::setOpenGLView(GLView *openGLView)
CHECK_GL_ERROR_DEBUG();
// _touchDispatcher->setDispatchEvents(true);
if (_eventDispatcher)
{
_eventDispatcher->setEnabled(true);
}
}
}
@ -747,9 +750,11 @@ void Director::purgeDirector()
// cleanup scheduler
getScheduler()->unscheduleAll();
// don't release the event handlers
// They are needed in case the director is run again
// _touchDispatcher->removeAllDelegates();
// Disable event dispatching
if (_eventDispatcher)
{
_eventDispatcher->setEnabled(false);
}
if (_runningScene)
{

View File

@ -31,7 +31,7 @@
#include "CCEventListenerKeyboard.h"
#include "CCEventListenerCustom.h"
#include "CCNode.h"
#include "CCScene.h"
#include "CCDirector.h"
#include "CCEventType.h"
@ -191,7 +191,7 @@ void EventDispatcher::EventListenerVector::clear()
EventDispatcher::EventDispatcher()
: _inDispatch(0)
, _isEnabled(true)
, _isEnabled(false)
, _nodePriorityIndex(0)
{
_toAddedListeners.reserve(50);
@ -340,6 +340,28 @@ void EventDispatcher::removeEventListenersForTarget(Node* target, bool recursive
}
}
// Bug fix: ensure there are no references to the node in the list of listeners to be added.
// If we find any listeners associated with the destroyed node in this list then remove them.
// This is to catch the scenario where the node gets destroyed before it's listener
// is added into the event dispatcher fully. This could happen if a node registers a listener
// and gets destroyed while we are dispatching an event (touch etc.)
for (auto iter = _toAddedListeners.begin(); iter != _toAddedListeners.end(); )
{
EventListener * listener = *iter;
if (listener->getSceneGraphPriority() == target)
{
listener->setSceneGraphPriority(nullptr); // Ensure no dangling ptr to the target node.
listener->setRegistered(false);
listener->release();
iter = _toAddedListeners.erase(iter);
}
else
{
++iter;
}
}
if (recursive)
{
const auto& children = target->getChildren();
@ -637,6 +659,7 @@ void EventDispatcher::removeEventListener(EventListener* listener)
{
if (*iter == listener)
{
listener->setRegistered(false);
listener->release();
_toAddedListeners.erase(iter);
break;
@ -688,7 +711,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, c
for (; i < listeners->getGt0Index(); ++i)
{
auto l = fixedPriorityListeners->at(i);
if (!l->isPaused() && l->isRegistered() && onEvent(l))
if (l->isEnabled() && !l->isPaused() && l->isRegistered() && onEvent(l))
{
shouldStopPropagation = true;
break;
@ -704,7 +727,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, c
// priority == 0, scene graph priority
for (auto& l : *sceneGraphPriorityListeners)
{
if (!l->isPaused() && l->isRegistered() && onEvent(l))
if (l->isEnabled() && !l->isPaused() && l->isRegistered() && onEvent(l))
{
shouldStopPropagation = true;
break;
@ -723,7 +746,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, c
{
auto l = fixedPriorityListeners->at(i);
if (!l->isPaused() && l->isRegistered() && onEvent(l))
if (l->isEnabled() && !l->isPaused() && l->isRegistered() && onEvent(l))
{
shouldStopPropagation = true;
break;
@ -1103,6 +1126,9 @@ void EventDispatcher::sortEventListeners(const EventListener::ListenerID& listen
if (dirtyFlag != DirtyFlag::NONE)
{
// Clear the dirty flag first, if `rootNode` is nullptr, then set its dirty flag of scene graph priority
dirtyIter->second = DirtyFlag::NONE;
if ((int)dirtyFlag & (int)DirtyFlag::FIXED_PRIORITY)
{
sortEventListenersOfFixedPriority(listenerID);
@ -1110,14 +1136,20 @@ void EventDispatcher::sortEventListeners(const EventListener::ListenerID& listen
if ((int)dirtyFlag & (int)DirtyFlag::SCENE_GRAPH_PRIORITY)
{
sortEventListenersOfSceneGraphPriority(listenerID);
auto rootNode = Director::getInstance()->getRunningScene();
if (rootNode)
{
sortEventListenersOfSceneGraphPriority(listenerID, rootNode);
}
else
{
dirtyIter->second = DirtyFlag::SCENE_GRAPH_PRIORITY;
}
}
dirtyIter->second = DirtyFlag::NONE;
}
}
void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener::ListenerID& listenerID)
void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener::ListenerID& listenerID, Node* rootNode)
{
auto listeners = getListeners(listenerID);
@ -1127,8 +1159,7 @@ void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener
if (sceneGraphListeners == nullptr)
return;
Node* rootNode = (Node*)Director::getInstance()->getRunningScene();
// Reset priority index
_nodePriorityIndex = 0;
_nodePriorityMap.clear();
@ -1136,7 +1167,6 @@ void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener
visitTarget(rootNode, true);
// After sort: priority < 0, > 0
std::sort(sceneGraphListeners->begin(), sceneGraphListeners->end(), [this](const EventListener* l1, const EventListener* l2) {
return _nodePriorityMap[l1->getSceneGraphPriority()] > _nodePriorityMap[l2->getSceneGraphPriority()];
});
@ -1252,6 +1282,7 @@ void EventDispatcher::removeEventListenersForListenerID(const EventListener::Lis
{
if ((*iter)->getListenerID() == listenerID)
{
(*iter)->setRegistered(false);
(*iter)->release();
iter = _toAddedListeners.erase(iter);
}
@ -1328,7 +1359,6 @@ void EventDispatcher::setEnabled(bool isEnabled)
_isEnabled = isEnabled;
}
bool EventDispatcher::isEnabled() const
{
return _isEnabled;

View File

@ -207,7 +207,7 @@ protected:
void sortEventListeners(const EventListener::ListenerID& listenerID);
/** Sorts the listeners of specified type by scene graph priority */
void sortEventListenersOfSceneGraphPriority(const EventListener::ListenerID& listenerID);
void sortEventListenersOfSceneGraphPriority(const EventListener::ListenerID& listenerID, Node* rootNode);
/** Sorts the listeners of specified type by fixed priority */
void sortEventListenersOfFixedPriority(const EventListener::ListenerID& listenerID);

View File

@ -42,6 +42,7 @@ bool EventListener::init(Type t, const ListenerID& listenerID, const std::functi
_listenerID = listenerID;
_isRegistered = false;
_paused = true;
_isEnabled = true;
return true;
}

View File

@ -1,18 +1,18 @@
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -22,8 +22,8 @@
THE SOFTWARE.
****************************************************************************/
#ifndef cocos2d_libs_EventListener_h
#define cocos2d_libs_EventListener_h
#ifndef __CCEVENTLISTENER_H__
#define __CCEVENTLISTENER_H__
#include "CCPlatformMacros.h"
#include "CCRef.h"
@ -56,55 +56,102 @@ public:
ACCELERATION,
CUSTOM
};
typedef std::string ListenerID;
protected:
/** Constructor */
EventListener();
/** Initializes event with type and callback function */
bool init(Type t, const ListenerID& listenerID, const std::function<void(Event*)>& callback);
public:
/** Destructor */
virtual ~EventListener();
/** Checks whether the listener is available. */
virtual bool checkAvailable() = 0;
/** Clones the listener, its subclasses have to override this method. */
virtual EventListener* clone() = 0;
/** Enables or disables the listener
* @note Only listeners with `enabled` state will be able to receive events.
* When an listener was initialized, it's enabled by default.
* An event listener can receive events when it is enabled and is not paused.
* paused state is always false when it is a fixed priority listener.
*/
inline void setEnabled(bool enabled) { _isEnabled = enabled; };
/** Checks whether the listener is enabled */
inline bool isEnabled() const { return _isEnabled; };
protected:
/** Sets paused state for the listener
* The paused state is only used for scene graph priority listeners.
* `EventDispatcher::resumeAllEventListenersForTarget(node)` will set the paused state to `true`,
* while `EventDispatcher::pauseAllEventListenersForTarget(node)` will set it to `false`.
* @note 1) Fixed priority listeners will never get paused. If a fixed priority doesn't want to receive events,
* call `setEnabled(false)` instead.
* 2) In `Node`'s onEnter and onExit, the `paused state` of the listeners which associated with that node will be automatically updated.
*/
inline void setPaused(bool paused) { _paused = paused; };
/** Checks whether the listener is paused */
inline bool isPaused() const { return _paused; };
/** Marks the listener was registered by EventDispatcher */
inline void setRegistered(bool registered) { _isRegistered = registered; };
/** Checks whether the listener was registered by EventDispatcher */
inline bool isRegistered() const { return _isRegistered; };
/** Gets the type of this listener
* @note It's different from `EventType`, e.g. TouchEvent has two kinds of event listeners - EventListenerOneByOne, EventListenerAllAtOnce
*/
inline Type getType() const { return _type; };
/** Gets the listener ID of this listener
* When event is being dispatched, listener ID is used as key for searching listeners according to event type.
*/
inline const ListenerID& getListenerID() const { return _listenerID; };
/** Sets the fixed priority for this listener
* @note This method is only used for `fixed priority listeners`, it needs to access a non-zero value.
* 0 is reserved for scene graph priority listeners
*/
inline void setFixedPriority(int fixedPriority) { _fixedPriority = fixedPriority; };
/** Gets the fixed priority of this listener
* @return 0 if it's a scene graph priority listener, non-zero for fixed priority listener
*/
inline int getFixedPriority() const { return _fixedPriority; };
/** Sets scene graph priority for this listener */
inline void setSceneGraphPriority(Node* node) { _node = node; };
/** Gets scene graph priority of this listener
* @return nullptr if it's a fixed priority listener, non-nullptr for scene graph priority listener
*/
inline Node* getSceneGraphPriority() const { return _node; };
///////////////
// Properties
//////////////
std::function<void(Event*)> _onEvent; /// Event callback function
Type _type; /// Event listener type
ListenerID _listenerID; /// Event listener ID
ListenerID _listenerID; /// Event listener ID
bool _isRegistered; /// Whether the listener has been added to dispatcher.
// The priority of event listener
int _fixedPriority; // The higher the number, the higher the priority, 0 is for scene graph base priority.
Node* _node; // scene graph based priority
bool _paused; // Whether the listener is paused
bool _isEnabled; // Whether the listener is enabled
friend class EventDispatcher;
};
NS_CC_END
#endif
#endif // __CCEVENTLISTENER_H__

View File

@ -184,6 +184,7 @@ Node::~Node()
_eventDispatcher->debugCheckNodeHasNoEventListenersOnDestruction(this);
#endif
CCASSERT(!_running, "Node still marked as running on node destruction! Was base class onExit() called in derived class onExit() implementations?");
CC_SAFE_RELEASE(_eventDispatcher);
}

View File

@ -500,7 +500,9 @@ void FileUtils::purgeCachedEntries()
static Data getData(const std::string& filename, bool forString)
{
CCASSERT(!filename.empty(), "Invalid filename!");
// getData is used indirectly in Image::initWithImageFileThreadSafe(), but CCASSERT is not thread-safe
// CCASSERT(!filename.empty(), "Invalid filename!");
assert(!(filename.empty()));
Data ret;
unsigned char* buffer = nullptr;

View File

@ -24,7 +24,6 @@ THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.io.UnsupportedEncodingException;
import java.util.Locale;
import java.lang.Runnable;
@ -61,7 +60,6 @@ public class Cocos2dxHelper {
private static String sFileDirectory;
private static Activity sActivity = null;
private static Cocos2dxHelperListener sCocos2dxHelperListener;
private static ConcurrentLinkedQueue<Runnable> jobs = new ConcurrentLinkedQueue<Runnable>();
/**
* Optional meta-that can be in the manifest for this component, specifying
@ -75,18 +73,8 @@ public class Cocos2dxHelper {
// Constructors
// ===========================================================
public static void dispatchPendingRunnables() {
for (int i = RUNNABLES_PER_FRAME; i > 0; i--) {
Runnable job = jobs.poll();
if (job == null) {
return;
}
job.run();
}
}
public static void runOnGLThread(final Runnable r) {
jobs.add(r);
((Cocos2dxActivity)sActivity).runOnGLThread(r);
}
private static boolean sInited = false;

View File

@ -143,7 +143,7 @@ namespace cocos2d {
return false;
}
JniHelper::classloader = _c;
JniHelper::classloader = cocos2d::JniHelper::getEnv()->NewGlobalRef(_c);
JniHelper::loadclassMethod_methodID = _m.methodID;
return true;

View File

@ -112,7 +112,10 @@ bool FileUtilsWin32::isFileExistInternal(const std::string& strFilePath) const
WCHAR utf16Buf[CC_MAX_PATH] = {0};
MultiByteToWideChar(CP_UTF8, 0, strPath.c_str(), -1, utf16Buf, sizeof(utf16Buf)/sizeof(utf16Buf[0]));
return GetFileAttributesW(utf16Buf) != -1 ? true : false;
DWORD attr = GetFileAttributesW(utf16Buf);
if(attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
return false; // not a file
return true;
}
bool FileUtilsWin32::isAbsolutePath(const std::string& strPath) const

View File

@ -52,7 +52,6 @@ public:
//TODO use material to decide if it is translucent
inline bool isTranslucent() const { return true; }
void generateMaterialID();
inline uint32_t getMaterialID() const { return _materialID; }
inline GLuint getTextureID() const { return _textureID; }
@ -67,6 +66,9 @@ public:
inline const kmMat4& getModelView() const { return _mv; }
private:
void generateMaterialID();
protected:
uint32_t _materialID;

View File

@ -359,6 +359,12 @@ void Renderer::render()
}
}
clean();
}
void Renderer::clean()
{
// Clear render group
for (size_t j = 0 ; j < _renderGroups.size(); j++)
{
//commands are owned by nodes
@ -368,12 +374,18 @@ void Renderer::render()
// }
_renderGroups[j].clear();
}
//Clear the stack incase gl view hasn't been initialized yet
// Clear batch quad commands
_batchedQuadCommands.clear();
_numQuads = 0;
// Clear the stack incase gl view hasn't been initialized yet
while(!_renderStack.empty())
{
_renderStack.pop();
}
// Reset render stack
RenderStackElement element = {DEFAULT_RENDER_QUEUE, 0};
_renderStack.push(element);
_lastMaterialID = 0;

View File

@ -79,7 +79,7 @@ public:
//TODO manage GLView inside Render itself
void initGLView();
/** Adds a `RenderComamnd` into the renderer */
void addCommand(RenderCommand* command);
@ -98,6 +98,9 @@ public:
/** Renders into the GLView all the queued `RenderCommand` objects */
void render();
/** Cleans all `RenderCommand`s in the queue */
void clean();
/* returns the number of drawn batches in the last frame */
ssize_t getDrawnBatches() const { return _drawnBatches; }
/* RenderCommands (except) QuadCommand should update this value */

View File

@ -414,13 +414,13 @@ void Console::commandHelp(int fd, const std::string &args)
for(auto it=_commands.begin();it!=_commands.end();++it)
{
auto cmd = it->second;
mydprintf(fd, "\t%s", cmd.name);
ssize_t tabs = strlen(cmd.name) / 8;
mydprintf(fd, "\t%s", cmd.name.c_str());
ssize_t tabs = strlen(cmd.name.c_str()) / 8;
tabs = 3 - tabs;
for(int j=0;j<tabs;j++){
mydprintf(fd, "\t");
}
mydprintf(fd,"%s\n", cmd.help);
mydprintf(fd,"%s\n", cmd.help.c_str());
}
}
@ -765,6 +765,8 @@ void Console::commandTouch(int fd, const std::string& args)
}
}
static char invalid_filename_char[] = {':', '/', '\\', '?', '%', '*', '<', '>', '"', '|', '\r', '\n', '\t'};
void Console::commandUpload(int fd)
{
ssize_t n, rc;
@ -775,11 +777,20 @@ void Console::commandUpload(int fd)
{
if( (rc = recv(fd, &c, 1, 0)) ==1 )
{
*ptr++ = c;
for(char x : invalid_filename_char)
{
if(c == x)
{
const char err[] = "upload: invalid file name!\n";
send(fd, err, sizeof(err),0);
return;
}
}
if(c == ' ')
{
break;
}
*ptr++ = c;
}
else if( rc == 0 )
{
@ -875,10 +886,10 @@ bool Console::parseCommand(int fd)
}
else
{
const char err[] = "Unknown Command!\n";
sendPrompt(fd);
const char err[] = "upload: invalid args! Type 'help' for options\n";
send(fd, err, sizeof(err),0);
return false;
sendPrompt(fd);
return true;
}
}
@ -909,7 +920,7 @@ bool Console::parseCommand(int fd)
const char err[] = "Unknown command. Type 'help' for options\n";
send(fd, err, sizeof(err),0);
sendPrompt(fd);
return false;
return true;
}
auto it = _commands.find(trim(args[0]));

View File

@ -74,8 +74,8 @@ class CC_DLL Console
{
public:
struct Command {
const char* name;
const char* help;
std::string name;
std::string help;
std::function<void(int, const std::string&)> callback;
};

View File

@ -31,9 +31,9 @@ NS_CC_BEGIN
const Value Value::Null;
Value::Value()
: _vectorData(new ValueVector())
, _mapData(new ValueMap())
, _intKeyMapData(new ValueMapIntKey())
: _vectorData(nullptr)
, _mapData(nullptr)
, _intKeyMapData(nullptr)
, _type(Type::NONE)
{

View File

@ -41,75 +41,30 @@ namespace cocostudio
WidgetReader::setPropsFromJsonDictionary(widget, options);
std::string jsonPath = GUIReader::getInstance()->getFilePath();
Button* button = static_cast<Button*>(widget);
bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
button->setScale9Enabled(scale9Enable);
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "normalData");
int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType");
switch (normalType)
{
case 0:
{
std::string tp_n = jsonPath;
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr;
button->loadTextureNormal(normalFileName_tp);
break;
}
case 1:
{
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
button->loadTextureNormal(normalFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string normalTexturePath = this->getResourcePath(normalDic, "path", (TextureResType)normalType);
button->loadTextureNormal(normalTexturePath, (TextureResType)normalType);
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "pressedData");
int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType");
switch (pressedType)
{
case 0:
{
std::string tp_p = jsonPath;
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr;
button->loadTexturePressed(pressedFileName_tp);
break;
}
case 1:
{
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
button->loadTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string pressedTexturePath = this->getResourcePath(pressedDic, "path", (TextureResType)pressedType);
button->loadTexturePressed(pressedTexturePath, (TextureResType)pressedType);
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "disabledData");
int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType");
switch (disabledType)
{
case 0:
{
std::string tp_d = jsonPath;
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr;
button->loadTextureDisabled(disabledFileName_tp);
break;
}
case 1:
{
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
button->loadTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string disabledTexturePath = this->getResourcePath(disabledDic, "path", (TextureResType)disabledType);
button->loadTextureDisabled(disabledTexturePath, (TextureResType)disabledType);
if (scale9Enable)
{
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");

View File

@ -40,7 +40,9 @@ namespace cocostudio
static ButtonReader* getInstance();
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget,
const rapidjson::Value& options);
};
}

View File

@ -35,120 +35,38 @@ namespace cocostudio
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
std::string jsonPath = GUIReader::getInstance()->getFilePath();
CheckBox* checkBox = static_cast<CheckBox*>(widget);
//load background image
const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxData");
int backGroundType = DICTOOL->getIntValue_json(backGroundDic, "resourceType");
switch (backGroundType)
{
case 0:
{
std::string tp_b = jsonPath;
const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path");
const char* backGroundFileName_tp = (backGroundFileName && (strcmp(backGroundFileName, "") != 0))?tp_b.append(backGroundFileName).c_str():nullptr;
checkBox->loadTextureBackGround(backGroundFileName_tp);
break;
}
case 1:
{
const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path");
checkBox->loadTextureBackGround(backGroundFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string backGroundTexturePath = this->getResourcePath(backGroundDic, "path", (TextureResType)backGroundType);
checkBox->loadTextureBackGround(backGroundTexturePath, (TextureResType)backGroundType);
//load background selected image
const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxSelectedData");
int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, "resourceType");
switch (backGroundSelectedType)
{
case 0:
{
std::string tp_bs = jsonPath;
const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path");
const char* backGroundSelectedFileName_tp = (backGroundSelectedFileName && (strcmp(backGroundSelectedFileName, "") != 0))?tp_bs.append(backGroundSelectedFileName).c_str():nullptr;
checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName_tp);
break;
}
case 1:
{
const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path");
checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string backGroundSelectedTexturePath = this->getResourcePath(backGroundSelectedDic, "path", (TextureResType)backGroundSelectedType);
checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath, (TextureResType)backGroundSelectedType);
//load frontCross image
const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, "frontCrossData");
int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, "resourceType");
switch (frontCrossType)
{
case 0:
{
std::string tp_c = jsonPath;
const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path");
const char* frontCrossFileName_tp = (frontCrossFileName && (strcmp(frontCrossFileName, "") != 0))?tp_c.append(frontCrossFileName).c_str():nullptr;
checkBox->loadTextureFrontCross(frontCrossFileName_tp);
break;
}
case 1:
{
const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path");
checkBox->loadTextureFrontCross(frontCrossFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string frontCrossFileName = this->getResourcePath(frontCrossDic, "path", (TextureResType)frontCrossType);
checkBox->loadTextureFrontCross(frontCrossFileName, (TextureResType)frontCrossType);
//load backGroundBoxDisabledData
const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxDisabledData");
int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, "resourceType");
switch (backGroundDisabledType)
{
case 0:
{
std::string tp_bd = jsonPath;
const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path");
const char* backGroundDisabledFileName_tp = (backGroundDisabledFileName && (strcmp(backGroundDisabledFileName, "") != 0))?tp_bd.append(backGroundDisabledFileName).c_str():nullptr;
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName_tp);
break;
}
case 1:
{
const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path");
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string backGroundDisabledFileName = this->getResourcePath(backGroundDisabledDic, "path", (TextureResType)backGroundDisabledType);
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (TextureResType)backGroundDisabledType);
///load frontCrossDisabledData
const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, "frontCrossDisabledData");
int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, "resourceType");
switch (frontCrossDisabledType)
{
case 0:
{
std::string tp_cd = jsonPath;
const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path");
const char* frontCrossDisabledFileName_tp = (frontCrossDisabledFileName && (strcmp(frontCrossDisabledFileName, "") != 0))?tp_cd.append(frontCrossDisabledFileName).c_str():nullptr;
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName_tp);
break;
}
case 1:
{
const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path");
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string frontCrossDisabledFileName = this->getResourcePath(frontCrossDisabledDic, "path", (TextureResType)frontCrossDisabledType);
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (TextureResType)frontCrossDisabledType);
WidgetReader::setColorPropsFromJsonDictionary(widget, options);

View File

@ -36,35 +36,14 @@ namespace cocostudio
WidgetReader::setPropsFromJsonDictionary(widget, options);
std::string jsonPath = GUIReader::getInstance()->getFilePath();
ImageView* imageView = static_cast<ImageView*>(widget);
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "fileNameData");
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
switch (imageFileNameType)
{
case 0:
{
std::string tp_i = jsonPath;
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
const char* imageFileName_tp = nullptr;
if (imageFileName && (strcmp(imageFileName, "") != 0))
{
imageFileName_tp = tp_i.append(imageFileName).c_str();
imageView->loadTexture(imageFileName_tp);
}
break;
}
case 1:
{
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
imageView->loadTexture(imageFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (TextureResType)imageFileNameType);
imageView->loadTexture(imageFileName, (TextureResType)imageFileNameType);
bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, "scale9Enable");
bool scale9Enable = false;

View File

@ -35,9 +35,6 @@ namespace cocostudio
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
std::string jsonPath = GUIReader::getInstance()->getFilePath();
Layout* panel = static_cast<Layout*>(widget);
/* adapt screen gui */
@ -86,25 +83,9 @@ namespace cocostudio
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "backGroundImageData");
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
switch (imageFileNameType)
{
case 0:
{
std::string tp_b = jsonPath;
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
panel->setBackGroundImage(imageFileName_tp);
break;
}
case 1:
{
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
panel->setBackGroundImage(imageFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (TextureResType)imageFileNameType);
panel->setBackGroundImage(imageFileName, (TextureResType)imageFileNameType);
if (backGroundScale9Enable)
{

View File

@ -36,35 +36,13 @@ namespace cocostudio
WidgetReader::setPropsFromJsonDictionary(widget, options);
std::string jsonPath = GUIReader::getInstance()->getFilePath();
LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "textureData");
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
switch (imageFileNameType)
{
case 0:
{
std::string tp_i = jsonPath;
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
const char* imageFileName_tp = nullptr;
if (imageFileName && (strcmp(imageFileName, "") != 0))
{
imageFileName_tp = tp_i.append(imageFileName).c_str();
loadingBar->loadTexture(imageFileName_tp);
}
break;
}
case 1:
{
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
loadingBar->loadTexture(imageFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (TextureResType)imageFileNameType);
loadingBar->loadTexture(imageFileName, (TextureResType)imageFileNameType);
/* gui mark add load bar scale9 parse */
bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");

View File

@ -35,159 +35,55 @@ namespace cocostudio
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
std::string jsonPath = GUIReader::getInstance()->getFilePath();
Slider* slider = static_cast<Slider*>(widget);
bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
slider->setScale9Enabled(barTextureScale9Enable);
slider->setPercent(DICTOOL->getIntValue_json(options, "percent"));
bool bt = DICTOOL->checkObjectExist_json(options, "barFileName");
float barLength = DICTOOL->getFloatValue_json(options, "length");
if (bt)
{
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (TextureResType)imageFileNameType);
slider->loadBarTexture(imageFileName, (TextureResType)imageFileNameType);
if (barTextureScale9Enable)
{
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
switch (imageFileType)
{
case 0:
{
std::string tp_b = jsonPath;
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
slider->loadBarTexture(imageFileName_tp);
break;
}
case 1:
{
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
slider->setSize(Size(barLength, slider->getContentSize().height));
}
else
{
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
switch (imageFileType)
{
case 0:
{
std::string tp_b = jsonPath;
const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
slider->loadBarTexture(imageFileName_tp);
break;
}
case 1:
{
const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
}
}
//loading normal slider ball texture
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "ballNormalData");
int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType");
switch (normalType)
{
case 0:
{
std::string tp_n = jsonPath;
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr;
slider->loadSlidBallTextureNormal(normalFileName_tp);
break;
}
case 1:
{
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
slider->loadSlidBallTextureNormal(normalFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string imageFileName = this->getResourcePath(normalDic, "path", (TextureResType)normalType);
slider->loadSlidBallTextureNormal(imageFileName, (TextureResType)normalType);
//loading slider ball press texture
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "ballPressedData");
int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType");
switch (pressedType)
{
case 0:
{
std::string tp_p = jsonPath;
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr;
slider->loadSlidBallTexturePressed(pressedFileName_tp);
break;
}
case 1:
{
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
slider->loadSlidBallTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string pressedFileName = this->getResourcePath(pressedDic, "path", (TextureResType)pressedType);
slider->loadSlidBallTexturePressed(pressedFileName, (TextureResType)pressedType);
//loading silder ball disable texture
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "ballDisabledData");
int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType");
switch (disabledType)
{
case 0:
{
std::string tp_d = jsonPath;
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr;
slider->loadSlidBallTextureDisabled(disabledFileName_tp);
break;
}
case 1:
{
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
slider->loadSlidBallTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
slider->setPercent(DICTOOL->getIntValue_json(options, "percent"));
std::string disabledFileName = this->getResourcePath(disabledDic, "path", (TextureResType)disabledType);
slider->loadSlidBallTextureDisabled(disabledFileName, (TextureResType)disabledType);
//load slider progress texture
const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, "progressBarData");
int progressBarType = DICTOOL->getIntValue_json(progressBarDic, "resourceType");
switch (progressBarType)
{
case 0:
{
std::string tp_b = jsonPath;
const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path");
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
slider->loadProgressBarTexture(imageFileName_tp);
break;
}
case 1:
{
const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path");
slider->loadProgressBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string progressBarFileName = this->getResourcePath(progressBarDic, "path", (TextureResType)progressBarType);
slider->loadProgressBarTexture(progressBarFileName, (TextureResType)progressBarType);
WidgetReader::setColorPropsFromJsonDictionary(widget, options);

View File

@ -172,4 +172,26 @@ namespace cocostudio
widget->setFlippedX(flipX);
widget->setFlippedY(flipY);
}
std::string WidgetReader::getResourcePath(const rapidjson::Value &dict,
const std::string &key,
cocos2d::ui::TextureResType texType)
{
std::string jsonPath = GUIReader::getInstance()->getFilePath();
const char* imageFileName = DICTOOL->getStringValue_json(dict, key.c_str());
std::string imageFileName_tp;
if (nullptr != imageFileName)
{
if (texType == UI_TEX_TYPE_LOCAL) {
imageFileName_tp = jsonPath + imageFileName;
}
else if(texType == UI_TEX_TYPE_PLIST){
imageFileName_tp = imageFileName;
}
else{
CCASSERT(0, "invalid TextureResType!!!");
}
}
return imageFileName_tp;
}
}

View File

@ -43,8 +43,16 @@ namespace cocostudio
static WidgetReader* getInstance();
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setColorPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget,
const rapidjson::Value& options);
virtual void setColorPropsFromJsonDictionary(cocos2d::ui::Widget* widget,
const rapidjson::Value& options);
protected:
std::string getResourcePath(const rapidjson::Value& dict,
const std::string& key,
cocos2d::ui::TextureResType texType);
};
}

View File

@ -41,7 +41,7 @@
--------------------------------
-- @function [parent=#Button] loadTextureDisabled
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
@ -57,13 +57,13 @@
--------------------------------
-- @function [parent=#Button] loadTexturePressed
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
-- @function [parent=#Button] setTitleFontName
-- @param self
-- @param #char char
-- @param #string str
--------------------------------
-- @function [parent=#Button] getCapInsetsNormalRenderer
@ -78,9 +78,9 @@
--------------------------------
-- @function [parent=#Button] loadTextures
-- @param self
-- @param #char char
-- @param #char char
-- @param #char char
-- @param #string str
-- @param #string str
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
@ -91,7 +91,7 @@
--------------------------------
-- @function [parent=#Button] loadTextureNormal
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
@ -107,7 +107,7 @@
--------------------------------
-- @function [parent=#Button] getTitleFontName
-- @param self
-- @return char#char ret (return value: char)
-- @return string#string ret (return value: string)
--------------------------------
-- @function [parent=#Button] getTitleColor
@ -120,10 +120,18 @@
-- @param #bool bool
--------------------------------
-- @function [parent=#Button] create
-- overload function: create(string, string, string, ccui.TextureResType)
--
-- overload function: create()
--
-- @function [parent=#Button] create
-- @param self
-- @return Button#Button ret (return value: ccui.Button)
-- @param #string str
-- @param #string str
-- @param #string str
-- @param #ccui.TextureResType texturerestype
-- @return Button#Button ret (retunr value: ccui.Button)
--------------------------------
-- @function [parent=#Button] createInstance
-- @param self

View File

@ -11,35 +11,35 @@
--------------------------------
-- @function [parent=#CheckBox] loadTextureBackGroundSelected
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
-- @function [parent=#CheckBox] loadTextureBackGroundDisabled
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
-- @function [parent=#CheckBox] loadTextureFrontCross
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
-- @function [parent=#CheckBox] loadTextures
-- @param self
-- @param #char char
-- @param #char char
-- @param #char char
-- @param #char char
-- @param #char char
-- @param #string str
-- @param #string str
-- @param #string str
-- @param #string str
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
-- @function [parent=#CheckBox] loadTextureBackGround
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
@ -50,14 +50,24 @@
--------------------------------
-- @function [parent=#CheckBox] loadTextureFrontCrossDisabled
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
-- @function [parent=#CheckBox] create
-- overload function: create(string, string, string, string, string, ccui.TextureResType)
--
-- overload function: create()
--
-- @function [parent=#CheckBox] create
-- @param self
-- @return CheckBox#CheckBox ret (return value: ccui.CheckBox)
-- @param #string str
-- @param #string str
-- @param #string str
-- @param #string str
-- @param #string str
-- @param #ccui.TextureResType texturerestype
-- @return CheckBox#CheckBox ret (retunr value: ccui.CheckBox)
--------------------------------
-- @function [parent=#CheckBox] createInstance
-- @param self

View File

@ -3,11 +3,21 @@
-- @module EventListener
-- @extend Ref
--------------------------------
-- @function [parent=#EventListener] setEnabled
-- @param self
-- @param #bool bool
--------------------------------
-- @function [parent=#EventListener] clone
-- @param self
-- @return EventListener#EventListener ret (return value: cc.EventListener)
--------------------------------
-- @function [parent=#EventListener] isEnabled
-- @param self
-- @return bool#bool ret (return value: bool)
--------------------------------
-- @function [parent=#EventListener] checkAvailable
-- @param self

View File

@ -6,7 +6,7 @@
--------------------------------
-- @function [parent=#ImageView] loadTexture
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
@ -35,10 +35,16 @@
-- @return bool#bool ret (return value: bool)
--------------------------------
-- @function [parent=#ImageView] create
-- overload function: create(string, ccui.TextureResType)
--
-- overload function: create()
--
-- @function [parent=#ImageView] create
-- @param self
-- @return ImageView#ImageView ret (return value: ccui.ImageView)
-- @param #string str
-- @param #ccui.TextureResType texturerestype
-- @return ImageView#ImageView ret (retunr value: ccui.ImageView)
--------------------------------
-- @function [parent=#ImageView] createInstance
-- @param self

View File

@ -55,7 +55,7 @@
--------------------------------
-- @function [parent=#Layout] setBackGroundImage
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------

View File

@ -11,7 +11,7 @@
--------------------------------
-- @function [parent=#LoadingBar] loadTexture
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
@ -50,10 +50,16 @@
-- @return int#int ret (return value: int)
--------------------------------
-- @function [parent=#LoadingBar] create
-- overload function: create(string, int)
--
-- overload function: create()
--
-- @function [parent=#LoadingBar] create
-- @param self
-- @return LoadingBar#LoadingBar ret (return value: ccui.LoadingBar)
-- @param #string str
-- @param #int int
-- @return LoadingBar#LoadingBar ret (retunr value: ccui.LoadingBar)
--------------------------------
-- @function [parent=#LoadingBar] createInstance
-- @param self

View File

@ -15,13 +15,13 @@
-- @param #float float
--------------------------------
-- overload function: initWithSpriteFrameName(char)
-- overload function: initWithSpriteFrameName(string)
--
-- overload function: initWithSpriteFrameName(char, rect_table)
-- overload function: initWithSpriteFrameName(string, rect_table)
--
-- @function [parent=#Scale9Sprite] initWithSpriteFrameName
-- @param self
-- @param #char char
-- @param #string str
-- @param #rect_table rect
-- @return bool#bool ret (retunr value: bool)
@ -88,17 +88,17 @@
-- @return size_table#size_table ret (return value: size_table)
--------------------------------
-- overload function: initWithFile(char, rect_table)
-- overload function: initWithFile(string, rect_table)
--
-- overload function: initWithFile(char, rect_table, rect_table)
-- overload function: initWithFile(string, rect_table, rect_table)
--
-- overload function: initWithFile(rect_table, char)
-- overload function: initWithFile(rect_table, string)
--
-- overload function: initWithFile(char)
-- overload function: initWithFile(string)
--
-- @function [parent=#Scale9Sprite] initWithFile
-- @param self
-- @param #char char
-- @param #string str
-- @param #rect_table rect
-- @param #rect_table rect
-- @return bool#bool ret (retunr value: bool)
@ -145,31 +145,31 @@
-- @param #float float
--------------------------------
-- overload function: create(char, rect_table, rect_table)
-- overload function: create(string, rect_table, rect_table)
--
-- overload function: create()
--
-- overload function: create(rect_table, char)
-- overload function: create(rect_table, string)
--
-- overload function: create(char, rect_table)
-- overload function: create(string, rect_table)
--
-- overload function: create(char)
-- overload function: create(string)
--
-- @function [parent=#Scale9Sprite] create
-- @param self
-- @param #char char
-- @param #string str
-- @param #rect_table rect
-- @param #rect_table rect
-- @return Scale9Sprite#Scale9Sprite ret (retunr value: cc.Scale9Sprite)
--------------------------------
-- overload function: createWithSpriteFrameName(char, rect_table)
-- overload function: createWithSpriteFrameName(string, rect_table)
--
-- overload function: createWithSpriteFrameName(char)
-- overload function: createWithSpriteFrameName(string)
--
-- @function [parent=#Scale9Sprite] createWithSpriteFrameName
-- @param self
-- @param #char char
-- @param #string str
-- @param #rect_table rect
-- @return Scale9Sprite#Scale9Sprite ret (retunr value: cc.Scale9Sprite)

View File

@ -11,33 +11,33 @@
--------------------------------
-- @function [parent=#Slider] loadSlidBallTextureDisabled
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
-- @function [parent=#Slider] loadSlidBallTextureNormal
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
-- @function [parent=#Slider] loadBarTexture
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
-- @function [parent=#Slider] loadProgressBarTexture
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
-- @function [parent=#Slider] loadSlidBallTextures
-- @param self
-- @param #char char
-- @param #char char
-- @param #char char
-- @param #string str
-- @param #string str
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------
@ -68,7 +68,7 @@
--------------------------------
-- @function [parent=#Slider] loadSlidBallTexturePressed
-- @param self
-- @param #char char
-- @param #string str
-- @param #ccui.TextureResType texturerestype
--------------------------------

View File

@ -79,10 +79,17 @@
-- @param #size_table size
--------------------------------
-- @function [parent=#Text] create
-- overload function: create(string, string, int)
--
-- overload function: create()
--
-- @function [parent=#Text] create
-- @param self
-- @return Text#Text ret (return value: ccui.Text)
-- @param #string str
-- @param #string str
-- @param #int int
-- @return Text#Text ret (retunr value: ccui.Text)
--------------------------------
-- @function [parent=#Text] createInstance
-- @param self

View File

@ -23,10 +23,19 @@
-- @param #string str
--------------------------------
-- @function [parent=#TextAtlas] create
-- overload function: create(string, string, int, int, string)
--
-- overload function: create()
--
-- @function [parent=#TextAtlas] create
-- @param self
-- @return TextAtlas#TextAtlas ret (return value: ccui.TextAtlas)
-- @param #string str
-- @param #string str
-- @param #int int
-- @param #int int
-- @param #string str
-- @return TextAtlas#TextAtlas ret (retunr value: ccui.TextAtlas)
--------------------------------
-- @function [parent=#TextAtlas] createInstance
-- @param self

View File

@ -6,23 +6,29 @@
--------------------------------
-- @function [parent=#TextBMFont] setFntFile
-- @param self
-- @param #char char
-- @param #string str
--------------------------------
-- @function [parent=#TextBMFont] getStringValue
-- @param self
-- @return char#char ret (return value: char)
-- @return string#string ret (return value: string)
--------------------------------
-- @function [parent=#TextBMFont] setText
-- @param self
-- @param #char char
-- @param #string str
--------------------------------
-- @function [parent=#TextBMFont] create
-- overload function: create(string, string)
--
-- overload function: create()
--
-- @function [parent=#TextBMFont] create
-- @param self
-- @return TextBMFont#TextBMFont ret (return value: ccui.TextBMFont)
-- @param #string str
-- @param #string str
-- @return TextBMFont#TextBMFont ret (retunr value: ccui.TextBMFont)
--------------------------------
-- @function [parent=#TextBMFont] createInstance
-- @param self

View File

@ -168,10 +168,17 @@
-- @return size_table#size_table ret (return value: size_table)
--------------------------------
-- @function [parent=#TextField] create
-- overload function: create(string, string, int)
--
-- overload function: create()
--
-- @function [parent=#TextField] create
-- @param self
-- @return TextField#TextField ret (return value: ccui.TextField)
-- @param #string str
-- @param #string str
-- @param #int int
-- @return TextField#TextField ret (retunr value: ccui.TextField)
--------------------------------
-- @function [parent=#TextField] createInstance
-- @param self

View File

@ -1 +1 @@
ca5eff0f3f1ad889632735b70ab2ec4d70a268be
0df0891de897f9c846c5a731531bc371604ad381

View File

@ -1556,6 +1556,8 @@ int register_all_cocos2dx(lua_State* tolua_S);

View File

@ -1 +1 @@
cfd5546826cceb88f4a37396516b6863abb122c6
427b621d028746e72000086b320b1b9b3adf7a19

View File

@ -125,7 +125,7 @@ int lua_cocos2dx_spine_Skeleton_onDraw(lua_State* tolua_S)
kmMat4 arg0;
bool arg1;
#pragma warning NO CONVERSION TO NATIVE FOR kmMat4;
ok &= luaval_to_kmMat4(tolua_S, 2, &arg0);
ok &= luaval_to_boolean(tolua_S, 3,&arg1);
if(!ok)

View File

@ -1 +1 @@
d608beef525313b9c497786a1dd7b2460ff65d84
a1f2ceee65fe7b4bdae2cd2c32ff84fa332a6b50

View File

@ -124,10 +124,11 @@ ScriptHandlerMgr::ScriptHandlerMgr()
{
}
ScriptHandlerMgr::~ScriptHandlerMgr()
{
CC_SAFE_DELETE(_scriptHandlerMgr);
}
ScriptHandlerMgr* ScriptHandlerMgr::getInstance()
{
if (NULL == _scriptHandlerMgr)
@ -138,6 +139,11 @@ ScriptHandlerMgr* ScriptHandlerMgr::getInstance()
return _scriptHandlerMgr;
}
void ScriptHandlerMgr::destroyInstance()
{
CC_SAFE_DELETE(_scriptHandlerMgr);
}
void ScriptHandlerMgr::init()
{
_mapObjectHandlers.clear();

View File

@ -173,7 +173,8 @@ public:
ScriptHandlerMgr(void);
virtual ~ScriptHandlerMgr(void);
static ScriptHandlerMgr* getInstance(void);
static void destroyInstance(void);
void addObjectHandler(void* object,int handler,ScriptHandlerMgr::HandlerType handlerType);
void removeObjectHandler(void* object,ScriptHandlerMgr::HandlerType handlerType);
int getObjectHandler(void* object,ScriptHandlerMgr::HandlerType handlerType);

View File

@ -83,6 +83,38 @@ Button* Button::create()
CC_SAFE_DELETE(widget);
return nullptr;
}
Button* Button::create(const std::string &normalImage,
const std::string& selectedImage ,
const std::string& disableImage,
TextureResType texType)
{
Button *btn = new Button;
if (btn && btn->init(normalImage,selectedImage,disableImage,texType)) {
btn->autorelease();
return btn;
}
CC_SAFE_DELETE(btn);
return nullptr;
}
bool Button::init(const std::string &normalImage,
const std::string& selectedImage ,
const std::string& disableImage,
TextureResType texType)
{
bool ret = true;
do {
if (!Widget::init()) {
ret = false;
break;
}
setTouchEnabled(true);
this->loadTextures(normalImage, selectedImage, disableImage,texType);
} while (0);
return ret;
}
bool Button::init()
{
@ -135,9 +167,9 @@ void Button::setScale9Enabled(bool able)
_buttonDisableRenderer = Sprite::create();
}
loadTextureNormal(_normalFileName.c_str(), _normalTexType);
loadTexturePressed(_clickedFileName.c_str(), _pressedTexType);
loadTextureDisabled(_disabledFileName.c_str(), _disabledTexType);
loadTextureNormal(_normalFileName, _normalTexType);
loadTexturePressed(_clickedFileName, _pressedTexType);
loadTextureDisabled(_disabledFileName, _disabledTexType);
addProtectedChild(_buttonNormalRenderer, NORMAL_RENDERER_Z, -1);
addProtectedChild(_buttonClickedRenderer, PRESSED_RENDERER_Z, -1);
addProtectedChild(_buttonDisableRenderer, DISABLED_RENDERER_Z, -1);
@ -171,16 +203,19 @@ void Button::ignoreContentAdaptWithSize(bool ignore)
}
}
void Button::loadTextures(const char* normal,const char* selected,const char* disabled,TextureResType texType)
void Button::loadTextures(const std::string& normal,
const std::string& selected,
const std::string& disabled,
TextureResType texType)
{
loadTextureNormal(normal,texType);
loadTexturePressed(selected,texType);
loadTextureDisabled(disabled,texType);
}
void Button::loadTextureNormal(const char* normal,TextureResType texType)
void Button::loadTextureNormal(const std::string& normal,TextureResType texType)
{
if (!normal || strcmp(normal, "") == 0)
if (normal.empty())
{
return;
}
@ -226,9 +261,9 @@ void Button::loadTextureNormal(const char* normal,TextureResType texType)
_normalTextureLoaded = true;
}
void Button::loadTexturePressed(const char* selected,TextureResType texType)
void Button::loadTexturePressed(const std::string& selected,TextureResType texType)
{
if (!selected || strcmp(selected, "") == 0)
if (selected.empty())
{
return;
}
@ -274,9 +309,9 @@ void Button::loadTexturePressed(const char* selected,TextureResType texType)
_pressedTextureLoaded = true;
}
void Button::loadTextureDisabled(const char* disabled,TextureResType texType)
void Button::loadTextureDisabled(const std::string& disabled,TextureResType texType)
{
if (!disabled || strcmp(disabled, "") == 0)
if (disabled.empty())
{
return;
}
@ -662,14 +697,14 @@ float Button::getTitleFontSize() const
return _titleRenderer->getFontSize();
}
void Button::setTitleFontName(const char* fontName)
void Button::setTitleFontName(const std::string& fontName)
{
_titleRenderer->setFontName(fontName);
}
const char* Button::getTitleFontName() const
const std::string& Button::getTitleFontName() const
{
return _titleRenderer->getFontName().c_str();
return _titleRenderer->getFontName();
}
std::string Button::getDescription() const
@ -710,9 +745,9 @@ void Button::copySpecialProperties(Widget *widget)
{
_prevIgnoreSize = button->_prevIgnoreSize;
setScale9Enabled(button->_scale9Enabled);
loadTextureNormal(button->_normalFileName.c_str(), button->_normalTexType);
loadTexturePressed(button->_clickedFileName.c_str(), button->_pressedTexType);
loadTextureDisabled(button->_disabledFileName.c_str(), button->_disabledTexType);
loadTextureNormal(button->_normalFileName, button->_normalTexType);
loadTexturePressed(button->_clickedFileName, button->_pressedTexType);
loadTextureDisabled(button->_disabledFileName, button->_disabledTexType);
setCapInsetsNormalRenderer(button->_capInsetsNormal);
setCapInsetsPressedRenderer(button->_capInsetsPressed);
setCapInsetsDisabledRenderer(button->_capInsetsDisabled);

View File

@ -55,19 +55,35 @@ public:
* Allocates and initializes.
*/
static Button* create();
/**
* create a button with custom textures
* @normalImage normal state texture name
* @selectedImage selected state texture name
* @disableImage disabled state texture name
* @param texType @see UI_TEX_TYPE_LOCAL
*/
static Button* create(const std::string& normalImage,
const std::string& selectedImage = "",
const std::string& disableImage = "",
TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load textures for button.
*
* @param normal normal state texture.
* @param normal normal state texture name.
*
* @param selected selected state texture.
* @param selected selected state texture name.
*
* @param disabled dark state texture.
* @param disabled disabled state texture name.
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextures(const char* normal,const char* selected,const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadTextures(const std::string& normal,
const std::string& selected,
const std::string& disabled = "",
TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load normal state texture for button.
@ -76,7 +92,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureNormal(const char* normal, TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadTextureNormal(const std::string& normal, TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load selected state texture for button.
@ -85,7 +101,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTexturePressed(const char* selected, TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadTexturePressed(const std::string& selected, TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load dark state texture for button.
@ -94,7 +110,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureDisabled(const char* disabled, TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadTextureDisabled(const std::string& disabled, TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Sets capinsets for button, if button is using scale9 renderer.
@ -169,11 +185,16 @@ public:
const Color3B& getTitleColor() const;
void setTitleFontSize(float size);
float getTitleFontSize() const;
void setTitleFontName(const char* fontName);
const char* getTitleFontName() const;
void setTitleFontName(const std::string& fontName);
const std::string& getTitleFontName() const;
CC_CONSTRUCTOR_ACCESS:
virtual bool init() override;
virtual bool init(const std::string& normalImage,
const std::string& selectedImage = "",
const std::string& disableImage = "",
TextureResType texType = UI_TEX_TYPE_LOCAL);
protected:
virtual void initRenderer() override;

View File

@ -75,6 +75,49 @@ CheckBox* CheckBox::create()
CC_SAFE_DELETE(widget);
return nullptr;
}
CheckBox* CheckBox::create(const std::string& backGround,
const std::string& backGroundSeleted,
const std::string& cross,
const std::string& backGroundDisabled,
const std::string& frontCrossDisabled,
TextureResType texType)
{
CheckBox *pWidget = new CheckBox;
if (pWidget && pWidget->init(backGround,
backGroundSeleted,
cross,
backGroundDisabled,
frontCrossDisabled,
texType))
{
pWidget->autorelease();
return pWidget;
}
CC_SAFE_DELETE(pWidget);
return nullptr;
}
bool CheckBox::init(const std::string& backGround,
const std::string& backGroundSeleted,
const std::string& cross,
const std::string& backGroundDisabled,
const std::string& frontCrossDisabled,
TextureResType texType)
{
bool ret = true;
do {
if (!Widget::init()) {
ret = false;
break;
}
setSelectedState(false);
setTouchEnabled(true);
loadTextures(backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled,texType);
} while (0);
return ret;
}
bool CheckBox::init()
{
@ -102,7 +145,12 @@ void CheckBox::initRenderer()
addProtectedChild(_frontCrossDisabledRenderer, FRONTCROSSDISABLED_RENDERER_Z, -1);
}
void CheckBox::loadTextures(const char *backGround, const char *backGroundSelected, const char *cross,const char* backGroundDisabled,const char* frontCrossDisabled,TextureResType texType)
void CheckBox::loadTextures(const std::string& backGround,
const std::string& backGroundSelected,
const std::string& cross,
const std::string& backGroundDisabled,
const std::string& frontCrossDisabled,
TextureResType texType)
{
loadTextureBackGround(backGround,texType);
loadTextureBackGroundSelected(backGroundSelected,texType);
@ -111,9 +159,9 @@ void CheckBox::loadTextures(const char *backGround, const char *backGroundSelect
loadTextureFrontCrossDisabled(frontCrossDisabled,texType);
}
void CheckBox::loadTextureBackGround(const char *backGround,TextureResType texType)
void CheckBox::loadTextureBackGround(const std::string& backGround,TextureResType texType)
{
if (!backGround || strcmp(backGround, "") == 0)
if (backGround.empty())
{
return;
}
@ -137,9 +185,9 @@ void CheckBox::loadTextureBackGround(const char *backGround,TextureResType texTy
updateRGBAToRenderer(_backGroundBoxRenderer);
}
void CheckBox::loadTextureBackGroundSelected(const char *backGroundSelected,TextureResType texType)
void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType)
{
if (!backGroundSelected || strcmp(backGroundSelected, "") == 0)
if (backGroundSelected.empty())
{
return;
}
@ -163,9 +211,9 @@ void CheckBox::loadTextureBackGroundSelected(const char *backGroundSelected,Text
updateRGBAToRenderer(_backGroundSelectedBoxRenderer);
}
void CheckBox::loadTextureFrontCross(const char *cross,TextureResType texType)
void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType texType)
{
if (!cross || strcmp(cross, "") == 0)
if (cross.empty())
{
return;
}
@ -189,9 +237,9 @@ void CheckBox::loadTextureFrontCross(const char *cross,TextureResType texType)
updateRGBAToRenderer(_frontCrossRenderer);
}
void CheckBox::loadTextureBackGroundDisabled(const char *backGroundDisabled,TextureResType texType)
void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType)
{
if (!backGroundDisabled || strcmp(backGroundDisabled, "") == 0)
if (backGroundDisabled.empty())
{
return;
}
@ -215,9 +263,9 @@ void CheckBox::loadTextureBackGroundDisabled(const char *backGroundDisabled,Text
updateRGBAToRenderer(_backGroundBoxDisabledRenderer);
}
void CheckBox::loadTextureFrontCrossDisabled(const char *frontCrossDisabled,TextureResType texType)
void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType)
{
if (!frontCrossDisabled || strcmp(frontCrossDisabled, "") == 0)
if (frontCrossDisabled.empty())
{
return;
}
@ -526,11 +574,11 @@ void CheckBox::copySpecialProperties(Widget *widget)
CheckBox* checkBox = dynamic_cast<CheckBox*>(widget);
if (checkBox)
{
loadTextureBackGround(checkBox->_backGroundFileName.c_str(), checkBox->_backGroundTexType);
loadTextureBackGroundSelected(checkBox->_backGroundSelectedFileName.c_str(), checkBox->_backGroundSelectedTexType);
loadTextureFrontCross(checkBox->_frontCrossFileName.c_str(), checkBox->_frontCrossTexType);
loadTextureBackGroundDisabled(checkBox->_backGroundDisabledFileName.c_str(), checkBox->_backGroundDisabledTexType);
loadTextureFrontCrossDisabled(checkBox->_frontCrossDisabledFileName.c_str(), checkBox->_frontCrossDisabledTexType);
loadTextureBackGround(checkBox->_backGroundFileName, checkBox->_backGroundTexType);
loadTextureBackGroundSelected(checkBox->_backGroundSelectedFileName, checkBox->_backGroundSelectedTexType);
loadTextureFrontCross(checkBox->_frontCrossFileName, checkBox->_frontCrossTexType);
loadTextureBackGroundDisabled(checkBox->_backGroundDisabledFileName, checkBox->_backGroundDisabledTexType);
loadTextureFrontCrossDisabled(checkBox->_frontCrossDisabledFileName, checkBox->_frontCrossDisabledTexType);
setSelectedState(checkBox->_isSelected);
}
}

View File

@ -64,6 +64,26 @@ public:
* Allocates and initializes.
*/
static CheckBox* create();
/**
* create an checkbox
*
* @param backGround backGround texture.
*
* @param backGroundSelected backGround selected state texture.
*
* @param cross cross texture.
*
* @param frontCrossDisabled cross dark state texture.
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
static CheckBox* create(const std::string& backGround,
const std::string& backGroundSeleted,
const std::string& cross,
const std::string& backGroundDisabled,
const std::string& frontCrossDisabled,
TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load textures for checkbox.
@ -78,7 +98,12 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextures(const char* backGround,const char* backGroundSelected,const char* cross,const char* backGroundDisabled,const char* frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadTextures(const std::string& backGround,
const std::string& backGroundSelected,
const std::string& cross,
const std::string& backGroundDisabled,
const std::string& frontCrossDisabled,
TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load backGround texture for checkbox.
@ -87,7 +112,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureBackGround(const char* backGround,TextureResType type = UI_TEX_TYPE_LOCAL);
void loadTextureBackGround(const std::string& backGround,TextureResType type = UI_TEX_TYPE_LOCAL);
/**
* Load backGroundSelected texture for checkbox.
@ -96,7 +121,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureBackGroundSelected(const char* backGroundSelected,TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load cross texture for checkbox.
@ -105,7 +130,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureFrontCross(const char* cross,TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadTextureFrontCross(const std::string&,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load backGroundDisabled texture for checkbox.
@ -114,7 +139,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureBackGroundDisabled(const char* backGroundDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load frontCrossDisabled texture for checkbox.
@ -123,7 +148,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureFrontCrossDisabled(const char* frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Sets selcted state for checkbox.
@ -161,6 +186,12 @@ public:
CC_CONSTRUCTOR_ACCESS:
virtual bool init() override;
virtual bool init(const std::string& backGround,
const std::string& backGroundSeleted,
const std::string& cross,
const std::string& backGroundDisabled,
const std::string& frontCrossDisabled,
TextureResType texType = UI_TEX_TYPE_LOCAL);
protected:
virtual void initRenderer() override;

View File

@ -53,6 +53,17 @@ ImageView::~ImageView()
{
}
ImageView* ImageView::create(const std::string &imageFileName, TextureResType texType)
{
ImageView *widget = new ImageView;
if (widget && widget->init(imageFileName, texType)) {
widget->autorelease();
return widget;
}
CC_SAFE_DELETE(widget);
return nullptr;
}
ImageView* ImageView::create()
{
@ -65,6 +76,33 @@ ImageView* ImageView::create()
CC_SAFE_DELETE(widget);
return nullptr;
}
bool ImageView::init()
{
bool ret = true;
do {
if (!Widget::init()) {
ret = false;
break;
}
_imageTexType = UI_TEX_TYPE_LOCAL;
} while (0);
return ret;
}
bool ImageView::init(const std::string &imageFileName, TextureResType texType)
{
bool bRet = true;
do {
if (!Widget::init()) {
bRet = false;
break;
}
this->loadTexture(imageFileName, texType);
} while (0);
return bRet;
}
void ImageView::initRenderer()
{
@ -72,9 +110,9 @@ void ImageView::initRenderer()
addProtectedChild(_imageRenderer, IMAGE_RENDERER_Z, -1);
}
void ImageView::loadTexture(const char *fileName, TextureResType texType)
void ImageView::loadTexture(const std::string& fileName, TextureResType texType)
{
if (!fileName || strcmp(fileName, "") == 0)
if (fileName.empty())
{
return;
}
@ -176,7 +214,7 @@ void ImageView::setScale9Enabled(bool able)
{
_imageRenderer = Sprite::create();
}
loadTexture(_textureFile.c_str(),_imageTexType);
loadTexture(_textureFile,_imageTexType);
addProtectedChild(_imageRenderer, IMAGE_RENDERER_Z, -1);
if (_scale9Enabled)
{
@ -306,7 +344,7 @@ void ImageView::copySpecialProperties(Widget *widget)
{
_prevIgnoreSize = imageView->_prevIgnoreSize;
setScale9Enabled(imageView->_scale9Enabled);
loadTexture(imageView->_textureFile.c_str(), imageView->_imageTexType);
loadTexture(imageView->_textureFile, imageView->_imageTexType);
setCapInsets(imageView->_capInsets);
}
}

View File

@ -55,6 +55,16 @@ public:
* Allocates and initializes.
*/
static ImageView* create();
/**
* create a imageview
*
* @param fileName file name of texture.
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
static ImageView* create(const std::string& imageFileName, TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load texture for imageview.
@ -63,7 +73,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTexture(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadTexture(const std::string& fileName,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Updates the texture rect of the ImageView in points.
@ -102,6 +112,12 @@ public:
virtual const Size& getContentSize() const override;
virtual Node* getVirtualRenderer() override;
CC_CONSTRUCTOR_ACCESS:
//initializes state of widget.
virtual bool init() override;
virtual bool init(const std::string& imageFileName, TextureResType texType = UI_TEX_TYPE_LOCAL);
protected:
virtual void initRenderer() override;
virtual void onSizeChanged() override;

View File

@ -1111,7 +1111,7 @@ void Layout::setBackGroundImageScale9Enabled(bool able)
_backGroundImage = nullptr;
_backGroundScale9Enabled = able;
addBackGroundImage();
setBackGroundImage(_backGroundImageFileName.c_str(),_bgImageTexType);
setBackGroundImage(_backGroundImageFileName,_bgImageTexType);
setBackGroundImageCapInsets(_backGroundImageCapInsets);
}
@ -1120,9 +1120,9 @@ bool Layout::isBackGroundImageScale9Enabled()
return _backGroundScale9Enabled;
}
void Layout::setBackGroundImage(const char* fileName,TextureResType texType)
void Layout::setBackGroundImage(const std::string& fileName,TextureResType texType)
{
if (!fileName || strcmp(fileName, "") == 0)
if (fileName.empty())
{
return;
}
@ -1519,7 +1519,7 @@ void Layout::copySpecialProperties(Widget *widget)
if (layout)
{
setBackGroundImageScale9Enabled(layout->_backGroundScale9Enabled);
setBackGroundImage(layout->_backGroundImageFileName.c_str(),layout->_bgImageTexType);
setBackGroundImage(layout->_backGroundImageFileName,layout->_bgImageTexType);
setBackGroundImageCapInsets(layout->_backGroundImageCapInsets);
setBackGroundColorType(layout->_colorType);
setBackGroundColor(layout->_cColor);

View File

@ -86,7 +86,7 @@ public:
*
* @param texType @see TextureResType. UI_TEX_TYPE_LOCAL means local file, UI_TEX_TYPE_PLIST means sprite frame.
*/
void setBackGroundImage(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL);
void setBackGroundImage(const std::string& fileName,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Sets a background image capinsets for layout, if the background image is a scale9 render.

View File

@ -63,6 +63,19 @@ LoadingBar* LoadingBar::create()
CC_SAFE_DELETE(widget);
return nullptr;
}
LoadingBar* LoadingBar::create(const std::string &textureName, int percentage)
{
LoadingBar* widget = new LoadingBar;
if (widget && widget->init()) {
widget->autorelease();
widget->loadTexture(textureName);
widget->setPercent(percentage);
return widget;
}
CC_SAFE_DELETE(widget);
return nullptr;
}
void LoadingBar::initRenderer()
{
@ -105,9 +118,9 @@ int LoadingBar::getDirection()
return _barType;
}
void LoadingBar::loadTexture(const char* texture,TextureResType texType)
void LoadingBar::loadTexture(const std::string& texture,TextureResType texType)
{
if (!texture || strcmp(texture, "") == 0)
if (texture.empty())
{
return;
}
@ -182,7 +195,7 @@ void LoadingBar::setScale9Enabled(bool enabled)
{
_barRenderer = Sprite::create();
}
loadTexture(_textureFile.c_str(),_renderBarTexType);
loadTexture(_textureFile,_renderBarTexType);
addProtectedChild(_barRenderer, BAR_RENDERER_Z, -1);
if (_scale9Enabled)
{
@ -358,7 +371,7 @@ void LoadingBar::copySpecialProperties(Widget *widget)
{
_prevIgnoreSize = loadingBar->_prevIgnoreSize;
setScale9Enabled(loadingBar->_scale9Enabled);
loadTexture(loadingBar->_textureFile.c_str(), loadingBar->_renderBarTexType);
loadTexture(loadingBar->_textureFile, loadingBar->_renderBarTexType);
setCapInsets(loadingBar->_capInsets);
setPercent(loadingBar->_percent);
setDirection(loadingBar->_barType);

View File

@ -61,6 +61,11 @@ public:
*/
static LoadingBar* create();
/**
* create a LoadingBar with a texture and a percentage
**/
static LoadingBar* create(const std::string& textureName, int percentage = 0);
/**
* Changes the progress direction of loadingbar.
*
@ -86,7 +91,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTexture(const char* texture,TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadTexture(const std::string& texture,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Changes the progress direction of loadingbar.

View File

@ -111,9 +111,9 @@ void Slider::initRenderer()
addProtectedChild(_slidBallRenderer, SLIDBALL_RENDERER_Z, -1);
}
void Slider::loadBarTexture(const char* fileName, TextureResType texType)
void Slider::loadBarTexture(const std::string& fileName, TextureResType texType)
{
if (!fileName || strcmp(fileName, "") == 0)
if (fileName.empty())
{
return;
}
@ -149,9 +149,9 @@ void Slider::loadBarTexture(const char* fileName, TextureResType texType)
progressBarRendererScaleChangedWithSize();
}
void Slider::loadProgressBarTexture(const char *fileName, TextureResType texType)
void Slider::loadProgressBarTexture(const std::string& fileName, TextureResType texType)
{
if (!fileName || strcmp(fileName, "") == 0)
if (fileName.empty())
{
return;
}
@ -210,8 +210,8 @@ void Slider::setScale9Enabled(bool able)
_barRenderer = Sprite::create();
_progressBarRenderer = Sprite::create();
}
loadBarTexture(_textureFile.c_str(), _barTexType);
loadProgressBarTexture(_progressBarTextureFile.c_str(), _progressBarTexType);
loadBarTexture(_textureFile, _barTexType);
loadProgressBarTexture(_progressBarTextureFile, _progressBarTexType);
addProtectedChild(_barRenderer, BASEBAR_RENDERER_Z, -1);
addProtectedChild(_progressBarRenderer, PROGRESSBAR_RENDERER_Z, -1);
if (_scale9Enabled)
@ -278,16 +278,16 @@ const Rect& Slider::getCapInsetsProgressBarRebderer()
return _capInsetsProgressBarRenderer;
}
void Slider::loadSlidBallTextures(const char* normal,const char* pressed,const char* disabled,TextureResType texType)
void Slider::loadSlidBallTextures(const std::string& normal,const std::string& pressed,const std::string& disabled,TextureResType texType)
{
loadSlidBallTextureNormal(normal, texType);
loadSlidBallTexturePressed(pressed,texType);
loadSlidBallTextureDisabled(disabled,texType);
}
void Slider::loadSlidBallTextureNormal(const char* normal,TextureResType texType)
void Slider::loadSlidBallTextureNormal(const std::string& normal,TextureResType texType)
{
if (!normal || strcmp(normal, "") == 0)
if (normal.empty())
{
return;
}
@ -307,9 +307,9 @@ void Slider::loadSlidBallTextureNormal(const char* normal,TextureResType texType
updateRGBAToRenderer(_slidBallNormalRenderer);
}
void Slider::loadSlidBallTexturePressed(const char* pressed,TextureResType texType)
void Slider::loadSlidBallTexturePressed(const std::string& pressed,TextureResType texType)
{
if (!pressed || strcmp(pressed, "") == 0)
if (pressed.empty())
{
return;
}
@ -329,9 +329,9 @@ void Slider::loadSlidBallTexturePressed(const char* pressed,TextureResType texTy
updateRGBAToRenderer(_slidBallPressedRenderer);
}
void Slider::loadSlidBallTextureDisabled(const char* disabled,TextureResType texType)
void Slider::loadSlidBallTextureDisabled(const std::string& disabled,TextureResType texType)
{
if (!disabled || strcmp(disabled, "") == 0)
if (disabled.empty())
{
return;
}
@ -596,11 +596,11 @@ void Slider::copySpecialProperties(Widget *widget)
{
_prevIgnoreSize = slider->_prevIgnoreSize;
setScale9Enabled(slider->_scale9Enabled);
loadBarTexture(slider->_textureFile.c_str(), slider->_barTexType);
loadProgressBarTexture(slider->_progressBarTextureFile.c_str(), slider->_progressBarTexType);
loadSlidBallTextureNormal(slider->_slidBallNormalTextureFile.c_str(), slider->_ballNTexType);
loadSlidBallTexturePressed(slider->_slidBallPressedTextureFile.c_str(), slider->_ballPTexType);
loadSlidBallTextureDisabled(slider->_slidBallDisabledTextureFile.c_str(), slider->_ballDTexType);
loadBarTexture(slider->_textureFile, slider->_barTexType);
loadProgressBarTexture(slider->_progressBarTextureFile, slider->_progressBarTexType);
loadSlidBallTextureNormal(slider->_slidBallNormalTextureFile, slider->_ballNTexType);
loadSlidBallTexturePressed(slider->_slidBallPressedTextureFile, slider->_ballPTexType);
loadSlidBallTextureDisabled(slider->_slidBallDisabledTextureFile, slider->_ballDTexType);
setPercent(slider->getPercent());
}
}

View File

@ -71,7 +71,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadBarTexture(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadBarTexture(const std::string& fileName,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Sets if slider is using scale9 renderer.
@ -118,7 +118,10 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadSlidBallTextures(const char* normal,const char* pressed,const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadSlidBallTextures(const std::string& normal,
const std::string& pressed,
const std::string& disabled,
TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load normal state texture for slider ball.
@ -127,7 +130,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadSlidBallTextureNormal(const char* normal,TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadSlidBallTextureNormal(const std::string& normal,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load selected state texture for slider ball.
@ -136,7 +139,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadSlidBallTexturePressed(const char* pressed,TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadSlidBallTexturePressed(const std::string& pressed,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load dark state texture for slider ball.
@ -145,7 +148,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadSlidBallTextureDisabled(const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadSlidBallTextureDisabled(const std::string& disabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load dark state texture for slider progress bar.
@ -154,7 +157,7 @@ public:
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadProgressBarTexture(const char* fileName, TextureResType texType = UI_TEX_TYPE_LOCAL);
void loadProgressBarTexture(const std::string& fileName, TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Changes the progress direction of slider.

View File

@ -68,6 +68,32 @@ bool Text::init()
}
return false;
}
Text* Text::create(const std::string &textContent, const std::string &fontName, int fontSize)
{
Text *text = new Text;
if (text && text->init(textContent, fontName, fontSize)) {
text->autorelease();
return text;
}
CC_SAFE_DELETE(text);
return nullptr;
}
bool Text::init(const std::string &textContent, const std::string &fontName, int fontSize)
{
bool ret = true;
do {
if (!Widget::init()) {
ret = false;
break;
}
this->setText(textContent);
this->setFontName(fontName);
this->setFontSize(fontSize);
} while (0);
return ret;
}
void Text::initRenderer()
{
@ -287,7 +313,7 @@ void Text::copySpecialProperties(Widget *widget)
Text* label = dynamic_cast<Text*>(widget);
if (label)
{
setFontName(label->_fontName.c_str());
setFontName(label->_fontName);
setFontSize(label->_labelRenderer->getFontSize());
setText(label->getStringValue());
setTouchScaleChangeEnabled(label->_touchScaleChangeEnabled);

View File

@ -55,6 +55,13 @@ public:
* Allocates and initializes.
*/
static Text* create();
/**
* create a Text object with textContent, fontName and fontSize
*/
static Text* create(const std::string& textContent,
const std::string& fontName,
int fontSize);
/**
* Changes the string value of label.
@ -137,6 +144,9 @@ public:
CC_CONSTRUCTOR_ACCESS:
virtual bool init() override;
virtual bool init(const std::string& textContent,
const std::string& fontName,
int fontSize);
protected:
virtual void initRenderer() override;

View File

@ -64,6 +64,23 @@ void TextAtlas::initRenderer()
_labelAtlasRenderer = LabelAtlas::create();
addProtectedChild(_labelAtlasRenderer, LABELATLAS_RENDERER_Z, -1);
}
TextAtlas* TextAtlas::create(const std::string &stringValue,
const std::string &charMapFile,
int itemWidth,
int itemHeight,
const std::string &startCharMap)
{
TextAtlas* widget = new TextAtlas();
if (widget && widget->init())
{
widget->autorelease();
widget->setProperty(stringValue, charMapFile, itemWidth, itemHeight, startCharMap);
return widget;
}
CC_SAFE_DELETE(widget);
return nullptr;
}
void TextAtlas::setProperty(const std::string& stringValue, const std::string& charMapFile, int itemWidth, int itemHeight, const std::string& startCharMap)
{

View File

@ -56,8 +56,21 @@ public:
*/
static TextAtlas* create();
/**
* create a LabelAtlas from a char map file
*/
static TextAtlas* create(const std::string& stringValue,
const std::string& charMapFile,
int itemWidth,
int itemHeight,
const std::string& startCharMap);
/** 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 */
void setProperty(const std::string& stringValue,const std::string& charMapFile, int itemWidth, int itemHeight, const std::string& startCharMap);
void setProperty(const std::string& stringValue,
const std::string& charMapFile,
int itemWidth,
int itemHeight,
const std::string& startCharMap);
//set string value for labelatlas.
void setStringValue(const std::string& value);

View File

@ -56,6 +56,20 @@ TextBMFont* TextBMFont::create()
CC_SAFE_DELETE(widget);
return nullptr;
}
TextBMFont* TextBMFont::create(const std::string &text, const std::string &filename)
{
TextBMFont* widget = new TextBMFont();
if (widget && widget->init())
{
widget->setFntFile(filename);
widget->setText(text);
widget->autorelease();
return widget;
}
CC_SAFE_DELETE(widget);
return nullptr;
}
void TextBMFont::initRenderer()
{
@ -63,9 +77,9 @@ void TextBMFont::initRenderer()
addProtectedChild(_labelBMFontRenderer, LABELBMFONT_RENDERER_Z, -1);
}
void TextBMFont::setFntFile(const char *fileName)
void TextBMFont::setFntFile(const std::string& fileName)
{
if (!fileName || strcmp(fileName, "") == 0)
if (fileName.empty())
{
return;
}
@ -74,15 +88,11 @@ void TextBMFont::setFntFile(const char *fileName)
updateAnchorPoint();
labelBMFontScaleChangedWithSize();
_fntFileHasInit = true;
setText(_stringValue.c_str());
setText(_stringValue);
}
void TextBMFont::setText(const char* value)
void TextBMFont::setText(const std::string& value)
{
if (!value)
{
return;
}
_stringValue = value;
if (!_fntFileHasInit)
{
@ -92,9 +102,9 @@ void TextBMFont::setText(const char* value)
labelBMFontScaleChangedWithSize();
}
const char* TextBMFont::getStringValue()
const std::string TextBMFont::getStringValue()
{
return _stringValue.c_str();
return _stringValue;
}
void TextBMFont::setAnchorPoint(const Point &pt)
@ -171,8 +181,8 @@ void TextBMFont::copySpecialProperties(Widget *widget)
TextBMFont* labelBMFont = dynamic_cast<TextBMFont*>(widget);
if (labelBMFont)
{
setFntFile(labelBMFont->_fntFileName.c_str());
setText(labelBMFont->_stringValue.c_str());
setFntFile(labelBMFont->_fntFileName);
setText(labelBMFont->_stringValue);
}
}

View File

@ -56,14 +56,16 @@ public:
*/
static TextBMFont* create();
static TextBMFont* create(const std::string& text, const std::string& filename);
/** init a bitmap font atlas with an initial string and the FNT file */
void setFntFile(const char* fileName);
void setFntFile(const std::string& fileName);
/** set string value for labelbmfont*/
void setText(const char* value);
void setText(const std::string& value);
/** get string value for labelbmfont*/
const char* getStringValue();
const std::string getStringValue();
virtual void setAnchorPoint(const Point &pt) override;
virtual const Size& getContentSize() const override;
virtual Node* getVirtualRenderer() override;

View File

@ -386,6 +386,22 @@ TextField* TextField::create()
return nullptr;
}
TextField* TextField::create(const std::string &placeholder, const std::string &fontName, int fontSize)
{
TextField* widget = new TextField();
if (widget && widget->init())
{
widget->setTouchEnabled(true);
widget->setPlaceHolder(placeholder);
widget->setFontName(fontName);
widget->setFontSize(fontSize);
widget->autorelease();
return widget;
}
CC_SAFE_DELETE(widget);
return nullptr;
}
bool TextField::init()
{
if (Widget::init())

View File

@ -110,6 +110,9 @@ public:
TextField();
virtual ~TextField();
static TextField* create();
static TextField* create(const std::string& placeholder,
const std::string& fontName,
int fontSize);
void setTouchSize(const Size &size);
Size getTouchSize();
void setTouchAreaEnabled(bool enable);

View File

@ -49,8 +49,8 @@ typedef enum
typedef enum
{
UI_TEX_TYPE_LOCAL,
UI_TEX_TYPE_PLIST
UI_TEX_TYPE_LOCAL = 0,
UI_TEX_TYPE_PLIST = 1
}TextureResType;
typedef enum

View File

@ -141,7 +141,7 @@ Please refer to [ReadMe](../README.md)
# Highlights of v3.0
* Replaced Objective-C patters with C++ (C++11) patterns and best practices
* Replaced Objective-C patterns with C++ (C++11) patterns and best practices
* Improved Labels
* Improved renderer (much faster than in v2.2!!)
* New Event Dispatcher

View File

@ -458,16 +458,14 @@ void Scale9Sprite::updatePositions()
_centre->setPosition(Point(leftWidth, bottomHeight));
}
bool Scale9Sprite::initWithFile(const char* file, const Rect& rect, const Rect& capInsets)
{
CCASSERT(file != NULL, "Invalid file for sprite");
bool Scale9Sprite::initWithFile(const std::string& file, const Rect& rect, const Rect& capInsets)
{
SpriteBatchNode *batchnode = SpriteBatchNode::create(file, 9);
bool pReturn = this->initWithBatchNode(batchnode, rect, capInsets);
return pReturn;
}
Scale9Sprite* Scale9Sprite::create(const char* file, const Rect& rect, const Rect& capInsets)
Scale9Sprite* Scale9Sprite::create(const std::string& file, const Rect& rect, const Rect& capInsets)
{
Scale9Sprite* pReturn = new Scale9Sprite();
if ( pReturn && pReturn->initWithFile(file, rect, capInsets) )
@ -479,14 +477,13 @@ Scale9Sprite* Scale9Sprite::create(const char* file, const Rect& rect, const Re
return NULL;
}
bool Scale9Sprite::initWithFile(const char* file, const Rect& rect)
bool Scale9Sprite::initWithFile(const std::string& file, const Rect& rect)
{
CCASSERT(file != NULL, "Invalid file for sprite");
bool pReturn = this->initWithFile(file, rect, Rect::ZERO);
return pReturn;
}
Scale9Sprite* Scale9Sprite::create(const char* file, const Rect& rect)
Scale9Sprite* Scale9Sprite::create(const std::string& file, const Rect& rect)
{
Scale9Sprite* pReturn = new Scale9Sprite();
if ( pReturn && pReturn->initWithFile(file, rect) )
@ -499,13 +496,13 @@ Scale9Sprite* Scale9Sprite::create(const char* file, const Rect& rect)
}
bool Scale9Sprite::initWithFile(const Rect& capInsets, const char* file)
bool Scale9Sprite::initWithFile(const Rect& capInsets, const std::string& file)
{
bool pReturn = this->initWithFile(file, Rect::ZERO, capInsets);
return pReturn;
}
Scale9Sprite* Scale9Sprite::create(const Rect& capInsets, const char* file)
Scale9Sprite* Scale9Sprite::create(const Rect& capInsets, const std::string& file)
{
Scale9Sprite* pReturn = new Scale9Sprite();
if ( pReturn && pReturn->initWithFile(capInsets, file) )
@ -517,14 +514,14 @@ Scale9Sprite* Scale9Sprite::create(const Rect& capInsets, const char* file)
return NULL;
}
bool Scale9Sprite::initWithFile(const char* file)
bool Scale9Sprite::initWithFile(const std::string& file)
{
bool pReturn = this->initWithFile(file, Rect::ZERO);
return pReturn;
}
Scale9Sprite* Scale9Sprite::create(const char* file)
Scale9Sprite* Scale9Sprite::create(const std::string& file)
{
Scale9Sprite* pReturn = new Scale9Sprite();
if ( pReturn && pReturn->initWithFile(file) )
@ -578,7 +575,7 @@ Scale9Sprite* Scale9Sprite::createWithSpriteFrame(SpriteFrame* spriteFrame)
return NULL;
}
bool Scale9Sprite::initWithSpriteFrameName(const char* spriteFrameName, const Rect& capInsets)
bool Scale9Sprite::initWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets)
{
CCASSERT((SpriteFrameCache::getInstance()) != NULL, "SpriteFrameCache::getInstance() must be non-NULL");
@ -591,7 +588,7 @@ bool Scale9Sprite::initWithSpriteFrameName(const char* spriteFrameName, const Re
return pReturn;
}
Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const char* spriteFrameName, const Rect& capInsets)
Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets)
{
Scale9Sprite* pReturn = new Scale9Sprite();
if ( pReturn && pReturn->initWithSpriteFrameName(spriteFrameName, capInsets) )
@ -603,16 +600,14 @@ Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const char* spriteFrameNam
return NULL;
}
bool Scale9Sprite::initWithSpriteFrameName(const char* spriteFrameName)
bool Scale9Sprite::initWithSpriteFrameName(const std::string& spriteFrameName)
{
bool pReturn = this->initWithSpriteFrameName(spriteFrameName, Rect::ZERO);
return pReturn;
}
Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const char* spriteFrameName)
Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const std::string& spriteFrameName)
{
CCASSERT(spriteFrameName != NULL, "spriteFrameName must be non-NULL");
Scale9Sprite* pReturn = new Scale9Sprite();
if ( pReturn && pReturn->initWithSpriteFrameName(spriteFrameName) )
{

View File

@ -75,7 +75,7 @@ public:
*
* @see initWithFile(const char *file, const Rect& rect, const Rect& capInsets)
*/
static Scale9Sprite* create(const char* file, const Rect& rect, const Rect& capInsets);
static Scale9Sprite* create(const std::string& file, const Rect& rect, const Rect& capInsets);
/**
* Creates a 9-slice sprite with a texture file. The whole texture will be
@ -83,7 +83,7 @@ public:
*
* @see initWithFile(const Rect& capInsets, const char *file)
*/
static Scale9Sprite* create(const Rect& capInsets, const char* file);
static Scale9Sprite* create(const Rect& capInsets, const std::string& file);
/**
* Creates a 9-slice sprite with a texture file and a delimitation zone. The
@ -91,7 +91,7 @@ public:
*
* @see initWithFile(const char *file, const Rect& rect)
*/
static Scale9Sprite* create(const char* file, const Rect& rect);
static Scale9Sprite* create(const std::string& file, const Rect& rect);
/**
* Creates a 9-slice sprite with a texture file. The whole texture will be
@ -99,7 +99,7 @@ public:
*
* @see initWithFile(const char *file)
*/
static Scale9Sprite* create(const char* file);
static Scale9Sprite* create(const std::string& file);
/**
* Creates a 9-slice sprite with an sprite frame.
@ -129,7 +129,7 @@ public:
*
* @see initWithSpriteFrameName(const char *spriteFrameName)
*/
static Scale9Sprite* createWithSpriteFrameName(const char*spriteFrameName);
static Scale9Sprite* createWithSpriteFrameName(const std::string& spriteFrameName);
/**
* Creates a 9-slice sprite with an sprite frame name and the centre of its
@ -140,7 +140,7 @@ public:
*
* @see initWithSpriteFrameName(const char *spriteFrameName, const Rect& capInsets)
*/
static Scale9Sprite* createWithSpriteFrameName(const char*spriteFrameName, const Rect& capInsets);
static Scale9Sprite* createWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets);
/**
* Initializes a 9-slice sprite with a texture file, a delimitation zone and
@ -155,7 +155,7 @@ public:
* texture's full rect.
* @param capInsets The values to use for the cap insets.
*/
virtual bool initWithFile(const char* file, const Rect& rect, const Rect& capInsets);
virtual bool initWithFile(const std::string& file, const Rect& rect, const Rect& capInsets);
/**
* Initializes a 9-slice sprite with a texture file and a delimitation zone. The
@ -169,7 +169,7 @@ public:
* is the whole image. If the shape is the whole texture, set this to the
* texture's full rect.
*/
virtual bool initWithFile(const char* file, const Rect& rect);
virtual bool initWithFile(const std::string& file, const Rect& rect);
/**
* Initializes a 9-slice sprite with a texture file and with the specified cap
@ -181,7 +181,7 @@ public:
* @param file The name of the texture file.
* @param capInsets The values to use for the cap insets.
*/
virtual bool initWithFile(const Rect& capInsets, const char* file);
virtual bool initWithFile(const Rect& capInsets, const std::string& file);
/**
* Initializes a 9-slice sprite with a texture file. The whole texture will be
@ -192,7 +192,7 @@ public:
*
* @param file The name of the texture file.
*/
virtual bool initWithFile(const char* file);
virtual bool initWithFile(const std::string& file);
/**
* Initializes a 9-slice sprite with an sprite frame and with the specified
@ -226,7 +226,7 @@ public:
* @param spriteFrameName The sprite frame name.
* @param capInsets The values to use for the cap insets.
*/
virtual bool initWithSpriteFrameName(const char*spriteFrameName, const Rect& capInsets);
virtual bool initWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets);
/**
* Initializes a 9-slice sprite with an sprite frame name.
@ -236,7 +236,7 @@ public:
*
* @param spriteFrameName The sprite frame name.
*/
virtual bool initWithSpriteFrameName(const char*spriteFrameName);
virtual bool initWithSpriteFrameName(const std::string& spriteFrameName);
virtual bool init();
virtual bool initWithBatchNode(SpriteBatchNode* batchnode, const Rect& rect, bool rotated, const Rect& capInsets);

2
plugin

@ -1 +1 @@
Subproject commit d177da9b541ab1b436476f9caa057766d485d9c3
Subproject commit 547ce2ea62a220a419f5df6bc54ab609437e49f3

415
setup.py
View File

@ -62,6 +62,16 @@ ANT_ROOT = 'ANT_ROOT'
class SetEnvVar(object):
RESULT_UPDATE_FAILED = -2
RESULT_ADD_FAILED = -1
RESULT_DO_NOTHING = 0
RESULT_UPDATED = 1
RESULT_ADDED = 2
UNIX_CHECK_FILES = [ '.bash_profile', '.bash_login', '.profile' ]
RE_FORMAT = r'^export[ \t]+%s=(.+)'
def __init__(self):
self.need_backup = True
self.backup_file = None
@ -91,16 +101,9 @@ class SetEnvVar(object):
return file_to_write
def _find_string_in_file(self, string, file_path):
with open(file_path) as f:
for line in f:
if line.startswith(string):
return True
return False
# modify registry table to add an environment variable on windows
def _set_environment_variable_win32(self, key, value):
ret = False
import _winreg
try:
env = None
@ -111,13 +114,13 @@ class SetEnvVar(object):
_winreg.SetValueEx(env, key, 0, _winreg.REG_SZ, value)
_winreg.FlushKey(env)
_winreg.CloseKey(env)
ret = True
except Exception:
if env:
_winreg.CloseKey(env)
print 'Warning: Could not add "%s" into registry' % key
return False
return True
ret = False
return ret
def _gen_backup_file(self):
file_name = os.path.basename(self.file_used_for_setup)
@ -151,42 +154,49 @@ class SetEnvVar(object):
def _set_environment_variable(self, key, value):
print " -> Add %s environment variable..." % key
ret = False
if self._isWindows():
ret = self._set_environment_variable_win32(key, value)
else:
ret = self._set_environment_variable_unix(key, value)
if ret:
print " ->Added %s=%s\n" % (key, value)
else:
print " ->Add failed\n"
return ret
def _search_unix_variable(self, var_name, file_name):
if not os.path.isfile(file_name):
return None
import re
str_re = SetEnvVar.RE_FORMAT % var_name
patten = re.compile(str_re)
ret = None
for line in open(file_name):
str1 = line.lstrip(' \t')
match = patten.match(str1)
if match is not None:
ret = match.group(1)
return ret
def _find_environment_variable(self, var):
print " ->Find environment variable %s..." % var
ret = None
try:
os.environ[var]
return True
ret = os.environ[var]
except Exception:
if not self._isWindows():
string_to_search = 'export %s' % var
home = os.path.expanduser('~')
# search it in ~/.bash_profile
path = os.path.join(home, '.bash_profile')
if os.path.exists(path):
if self._find_string_in_file(string_to_search, path):
self.file_used_for_setup = path
return True
# search it in ~/.bash_login
path = os.path.join(home, '.bash_login')
if os.path.exists(path):
if self._find_string_in_file(string_to_search, path):
self.file_used_for_setup = path
return True
# search it in ~/.profile
path = os.path.join(home, '.profile')
if os.path.exists(path):
if self._find_string_in_file(string_to_search, path):
self.file_used_for_setup = path
return True
for name in SetEnvVar.UNIX_CHECK_FILES:
path = os.path.join(home, name)
ret = self._search_unix_variable(var, path)
if ret is not None:
break
else:
import _winreg
try:
@ -196,17 +206,24 @@ class SetEnvVar(object):
0,
_winreg.KEY_READ)
_winreg.QueryValueEx(env, var)
ret = _winreg.QueryValueEx(env, var)
_winreg.CloseKey(env)
return True
except Exception:
if env:
_winreg.CloseKey(env)
return False
ret = None
def _get_input_value(self):
if ret is None:
print " ->%s not found\n" % var
else:
print " ->%s is found : %s\n" % (var, ret)
return raw_input('\tPlease enter its path (or press Enter to skip): ')
return ret
def _get_input_value(self, var_name):
ret = raw_input(' ->Please enter the path of %s (or press Enter to skip):' % var_name)
ret.rstrip(" \t")
return ret
# # python on linux doesn't include Tkinter model, so let user input in terminal
# if self._isLinux():
@ -270,6 +287,22 @@ class SetEnvVar(object):
# win.geometry('{}x{}+{}+{}'.format(width, height, x, y))
# win.wm_attributes('-topmost', 1)
def _check_valid(self, var_name, value):
ret = False
if var_name == NDK_ROOT:
ret = self._is_ndk_root_valid(value)
elif var_name == ANDROID_SDK_ROOT:
ret = self._is_android_sdk_root_valid(value)
elif var_name == ANT_ROOT:
ret = self._is_ant_root_valid(value)
else:
ret = False
if not ret:
print ' ->Error: "%s" is not a valid path of %s. Ignoring it.' % (value, var_name)
return ret
def _is_ndk_root_valid(self, ndk_root):
if not ndk_root:
return False
@ -285,9 +318,9 @@ class SetEnvVar(object):
return False
if self._isWindows():
android_path = os.path.join(android_sdk_root, 'tools/android.bat')
android_path = os.path.join(android_sdk_root, 'tools', 'android.bat')
else:
android_path = os.path.join(android_sdk_root, 'tools/android')
android_path = os.path.join(android_sdk_root, 'tools', 'android')
if os.path.isfile(android_path):
return True
else:
@ -306,7 +339,7 @@ class SetEnvVar(object):
else:
return False
def set_windows_path(self, cocos_consle_root):
def remove_dir_from_win_path(self, remove_dir):
import _winreg
try:
env = None
@ -316,42 +349,187 @@ class SetEnvVar(object):
0,
_winreg.KEY_SET_VALUE | _winreg.KEY_READ)
path = _winreg.QueryValueEx(env, 'Path')[0]
path = path + ';' + cocos_consle_root
path.replace('/', '\\')
_winreg.SetValueEx(env, 'Path', 0, _winreg.REG_SZ, path)
_winreg.FlushKey(env)
_winreg.CloseKey(env)
except Exception:
if not path:
path = cocos_consle_root.replace('/', '\\')
path_lower = path.lower()
remove_dir = remove_dir.replace('/', '\\')
remove_dir_lower = remove_dir.lower()
start_pos = path_lower.find(remove_dir_lower)
if (start_pos >= 0):
length = len(remove_dir_lower)
need_remove = path[start_pos:(start_pos + length)]
path = path.replace(need_remove, '')
path = path.replace(';;', ';')
_winreg.SetValueEx(env, 'Path', 0, _winreg.REG_SZ, path)
_winreg.FlushKey(env)
_winreg.CloseKey(env)
print ' ->Remove directory \"%s\" from PATH!\n' % remove_dir
except Exception:
print ' ->Remove directory \"%s\" from PATH failed!\n' % remove_dir
def set_windows_path(self, add_dir):
ret = False
import _winreg
try:
env = None
path = None
env = _winreg.OpenKeyEx(_winreg.HKEY_CURRENT_USER,
'Environment',
0,
_winreg.KEY_SET_VALUE | _winreg.KEY_READ)
path = _winreg.QueryValueEx(env, 'Path')[0]
# add variable if can't find it in PATH
path_lower = path.lower()
add_dir_lower = add_dir.lower()
if (path_lower.find(add_dir_lower) == -1):
path = add_dir + ';' + path
_winreg.SetValueEx(env, 'Path', 0, _winreg.REG_SZ, path)
_winreg.FlushKey(env)
_winreg.CloseKey(env)
ret = True
except Exception:
if not path:
path = add_dir
_winreg.SetValueEx(env, 'Path', 0, _winreg.REG_SZ, path)
_winreg.FlushKey(env)
ret = True
else:
_winreg.SetValueEx(env, 'Path', 0, _winreg.REG_SZ, path)
_winreg.FlushKey(env)
ret = False
if env:
_winreg.CloseKey(env)
return False
return True
if ret:
print " ->Add directory \"%s\" into PATH succeed!\n" % add_dir
else:
print " ->Add directory \"%s\" into PATH failed!\n" % add_dir
def set_console_root(self):
print ""
print '-> Adding COCOS2D_CONSOLE_ROOT environment variable...',
if not self._find_environment_variable(COCOS_CONSOLE_ROOT):
cocos_consle_root = os.path.join(self.current_absolute_path, 'tools/cocos2d-console/bin')
print "->Check environment variable %s" % COCOS_CONSOLE_ROOT
cocos_consle_root = os.path.join(self.current_absolute_path, 'tools', 'cocos2d-console', 'bin')
old_dir = self._find_environment_variable(COCOS_CONSOLE_ROOT)
if old_dir is None:
# add environment variable
if self._isWindows():
self.set_windows_path(cocos_consle_root)
if self._set_environment_variable(COCOS_CONSOLE_ROOT, cocos_consle_root):
print 'OK'
print ' -> Added: %s = %s' % (COCOS_CONSOLE_ROOT, cocos_consle_root)
return True
else:
print 'ALREADY ADDED'
return False
self._set_environment_variable(COCOS_CONSOLE_ROOT, cocos_consle_root)
else:
# update the environment variable
if self._isWindows():
self.remove_dir_from_win_path(old_dir)
self.set_windows_path(cocos_consle_root)
self._force_update_env(COCOS_CONSOLE_ROOT, cocos_consle_root)
def _force_update_unix_env(self, var_name, value):
import re
home = os.path.expanduser('~')
str_re = SetEnvVar.RE_FORMAT % var_name
patten = re.compile(str_re)
replace_str = 'export %s=%s\n' % (var_name, value)
print " ->Update variable %s in files %s" % (var_name, str(SetEnvVar.UNIX_CHECK_FILES))
variable_updated = False
for file_name in SetEnvVar.UNIX_CHECK_FILES:
path = os.path.join(home, file_name)
if os.path.isfile(path):
lines = []
# read files
need_over_write = False
file_obj = open(path, 'r')
for line in file_obj:
str_temp = line.lstrip(' \t')
match = patten.match(str_temp)
if match is not None:
variable_updated = True
need_over_write = True
lines.append(replace_str)
else:
lines.append(line)
file_obj.close()
# rewrite file
if need_over_write:
file_obj = open(path, 'w')
file_obj.writelines(lines)
file_obj.close()
print " ->File %s updated!" % path
# nothing updated, should add variable
if not variable_updated:
print "\n ->No files updated, add variable %s instead!" % var_name
ret = self._set_environment_variable(var_name, value)
else:
ret = True
return ret
def _force_update_env(self, var_name, value):
ret = False
if self._isWindows():
print " ->Force update environment variable %s" % var_name
ret = self._set_environment_variable_win32(var_name, value)
if not ret:
print " ->Failed!"
else:
print " ->Succeed : %s=%s" % (var_name, value)
else:
ret = self._force_update_unix_env(var_name, value)
return ret
def set_variable(self, var_name, value):
print "->Check environment variable %s" % var_name
find_value = self._find_environment_variable(var_name)
var_found = (find_value is not None)
action_none = 0
action_add = 1
action_update = 2
need_action = action_none
if var_found:
if value and self._check_valid(var_name, value):
# should update
need_action = action_update
else:
# do nothing
need_action = action_none
else:
if not value:
value = self._get_input_value(var_name)
if value and self._check_valid(var_name, value):
# should add variable
need_action = action_add
else:
# do nothing
need_action = action_none
if need_action == action_none:
# do nothing
return SetEnvVar.RESULT_DO_NOTHING
elif need_action == action_add:
# add variable
if self._set_environment_variable(var_name, value):
return SetEnvVar.RESULT_ADDED
else:
return SetEnvVar.RESULT_ADD_FAILED
elif need_action == action_update:
# update variable
if self._force_update_env(var_name, value):
# update succeed
return SetEnvVar.RESULT_UPDATED
else:
# update failed
return SetEnvVar.RESULT_UPDATE_FAILED
else:
return SetEnvVar.RESULT_DO_NOTHING
def set_environment_variables(self, ndk_root, android_sdk_root, ant_root):
@ -359,111 +537,20 @@ class SetEnvVar(object):
self.file_used_for_setup = self._get_filepath_for_setup()
console_added = self.set_console_root()
#
# NDK_ROOT
#
print ""
print '-> Looking for NDK_ROOT envrironment variable...',
ndk_root_added = False
ndk_root_found = self._find_environment_variable(NDK_ROOT)
if not ndk_root and not ndk_root_found:
print "NOT FOUND"
ndk_root = self._get_input_value()
if ndk_root and not self._is_ndk_root_valid(ndk_root) and not ndk_root_found:
print 'Error: "%s" is not a valid path of NDK_ROOT. Ignoring it.' % ndk_root
if ndk_root_found:
print 'FOUND'
else:
if ndk_root and self._is_ndk_root_valid(ndk_root):
if self._set_environment_variable(NDK_ROOT, ndk_root):
ndk_root_added = True
print 'ADDED'
print ' -- Added: %s = %s' % (NDK_ROOT, ndk_root)
#
# ANDROID_SDK_ROOT
#
print ""
print '-> Looking for ANDROID_SDK_ROOT envrironment variable...',
android_sdk_root_added = False
android_sdk_root_found = self._find_environment_variable(ANDROID_SDK_ROOT)
if not android_sdk_root and not android_sdk_root_found:
print "NOT FOUND"
android_sdk_root = self._get_input_value()
if android_sdk_root and not self._is_android_sdk_root_valid(android_sdk_root) and not android_sdk_root_found:
print 'Error: "%s" is not a valid path of ANDROID_SDK_ROOT. Ignoring it.' % android_sdk_root
if android_sdk_root_found:
print 'FOUND'
else:
if android_sdk_root and self._is_android_sdk_root_valid(android_sdk_root):
if self._set_environment_variable(ANDROID_SDK_ROOT, android_sdk_root):
android_sdk_root_added = True
print 'ADDED'
print ' -> Added: %s = %s' % (ANDROID_SDK_ROOT, android_sdk_root)
#
# ANT_ROOT
#
print ""
print '-> Looking for ANT_ROOT envrironment variable...',
ant_root_added = False
ant_found = self._find_environment_variable(ANT_ROOT)
if not ant_root and not ant_found:
print 'NOT FOUND'
ant_root = self._get_input_value()
if ant_root and not self._is_ant_root_valid(ant_root) and not ant_found:
print 'Error: "%s" is not a valid path of ANT_ROOT. Ignoring it.' % ant_root
if ant_found:
print 'FOUND'
else:
if ant_root and self._is_ant_root_valid(ant_root):
if self._set_environment_variable(ANT_ROOT, ant_root):
ant_root_added = True
print 'ADDED'
print ' -> Added: %s = %s' % (ANT_ROOT, ant_root)
if self._isWindows():
target = 'registry'
else:
target = self.file_used_for_setup
if console_added or ndk_root_added or android_sdk_root_added or ant_root_added:
print '\nSet up successfull:'
if console_added:
print '\tCOCOS_CONSOLE_ROOT was added into %s' % target
if ndk_root_added:
print '\tNDK_ROOT was added into %s' % target
if android_sdk_root_added:
print '\tANDROID_SDK_ROOT was added into %s' % target
if ant_root_added:
print '\tANT_ROOT was added into %s' % target
else:
print '\nCOCOS_CONSOLE_ROOT was already added. Edit "%s" for manual changes' % target
self.set_console_root()
ndk_ret = self.set_variable(NDK_ROOT, ndk_root)
sdk_ret = self.set_variable(ANDROID_SDK_ROOT, android_sdk_root)
ant_ret = self.set_variable(ANT_ROOT, ant_root)
# tip the backup file
if (self.backup_file is not None) and (os.path.exists(self.backup_file)):
print '\nA backup file \"%s\" is created for \"%s\".' % (self.backup_file, self.file_used_for_setup)
if self._isWindows():
print '\nPlease restart the terminal or restart computer to make added system variables take effect'
print '\nPlease restart the terminal or restart computer to make added system variables take effect\n'
else:
print '\nPlease execute command: "source %s" to make added system variables take effect' % target
print '\nPlease execute command: "source %s" to make added system variables take effect\n' % self.file_used_for_setup
if __name__ == '__main__':
parser = OptionParser()

View File

@ -1 +1 @@
fc6ed30da5bae3afef933f3beab4a697286ee407
ee48702a58c132b4999c618ce6cd69b78f0d9cd9

View File

@ -21,29 +21,24 @@ bool UIButtonTest::init()
Size widgetSize = _widget->getSize();
// Add a label in which the button events will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create();
alert->setText("Button");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("Button","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
alert->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the button
Button* button = Button::create();
button->setTouchEnabled(true);
button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
Button* button = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
button->addTouchEventListener(this, toucheventselector(UIButtonTest::touchEvent));
_uiLayer->addChild(button);
@ -97,29 +92,22 @@ bool UIButtonTest_Scale9::init()
Size widgetSize = _widget->getSize();
// Add a label in which the button events will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create();
alert->setText("Button scale9 render");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("Button scale9 render", "fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
alert->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the button
Button* button = Button::create();
button->setTouchEnabled(true);
Button* button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
// open scale9 render
button->setScale9Enabled(true);
button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
button->setSize(Size(150, button->getContentSize().height * 1.5f));
button->addTouchEventListener(this, toucheventselector(UIButtonTest_Scale9::touchEvent));
@ -172,29 +160,23 @@ bool UIButtonTest_PressedAction::init()
Size widgetSize = _widget->getSize();
// Add a label in which the button events will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create();
alert->setText("Button Pressed Action");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("Button Pressed Action", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
alert->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the button
Button* button = Button::create();
button->setTouchEnabled(true);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setPressedActionEnabled(true);
button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
button->addTouchEventListener(this, toucheventselector(UIButtonTest_PressedAction::touchEvent));
_uiLayer->addChild(button);
@ -247,27 +229,21 @@ bool UIButtonTest_Title::init()
Size widgetSize = _widget->getSize();
// Add a label in which the text button events will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create();
alert->setText("Button with title");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("Button with title", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
alert->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the button with title
Button* button = Button::create();
button->setTouchEnabled(true);
button->loadTextures("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png", "");
Button* button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png");
button->setTitleText("Title Button");
button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
button->addTouchEventListener(this, toucheventselector(UIButtonTest_Title::touchEvent));

View File

@ -21,31 +21,23 @@ bool UICheckBoxTest::init()
Size widgetSize = _widget->getSize();;
// Add a label in which the checkbox events will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create();
alert->setText("CheckBox");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("CheckBox","fonts/Marker Felt.ttf",30 );
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the checkbox
CheckBox* checkBox = CheckBox::create();
checkBox->setTouchEnabled(true);
checkBox->loadTextures("cocosui/check_box_normal.png",
"cocosui/check_box_normal_press.png",
"cocosui/check_box_active.png",
"cocosui/check_box_normal_disable.png",
"cocosui/check_box_active_disable.png");
CheckBox* checkBox = CheckBox::create("cocosui/check_box_normal.png",
"cocosui/check_box_normal_press.png",
"cocosui/check_box_active.png",
"cocosui/check_box_normal_disable.png",
"cocosui/check_box_active_disable.png");
checkBox->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
checkBox->addEventListenerCheckBox(this, checkboxselectedeventselector(UICheckBoxTest::selectedEvent));

View File

@ -11,52 +11,21 @@ bool UIImageViewTest::init()
{
Size widgetSize = _widget->getSize();
Text* alert = Text::create();
alert->setText("ImageView");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("ImageView", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
alert->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the imageview
ImageView* imageView = ImageView::create();
imageView->loadTexture("cocosui/ccicon.png");
imageView->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + imageView->getSize().height / 4.0f));
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
imageView->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + imageView->getSize().height / 4.0f));
// imageView->setOpacity(64);
_uiLayer->addChild(imageView);
/*
NodeRGBA* root = NodeRGBA::create();
root->setCascadeOpacityEnabled(true);
NodeRGBA* render = Sprite::create();
static_cast<Sprite*>(render)->setTexture("cocosui/ccicon.png");
root->addChild(render);
// root->setOpacity(64);
root->setPosition(Point(200, 180));
_uiLayer->addChild(root);
*/
/*
NodeRGBA* nodergba = NodeRGBA::create();
Sprite* child = Sprite::create();
child->setTexture("cocosui/ccicon.png");
nodergba->addChild(child);
nodergba->setPosition(Point(120, 80));
nodergba->setOpacity(64);
_uiLayer->addChild(nodergba);
*/
/*
Sprite* sprite = Sprite::create();
sprite->setTexture("cocosui/ccicon.png");
sprite->setPosition(Point(200, 180));
// sprite->setOpacity(64);
_uiLayer->addChild(sprite);
*/
// imageView->setZOrder(20);
return true;
}
@ -72,20 +41,20 @@ bool UIImageViewTest_Scale9::init()
{
Size widgetSize = _widget->getSize();
Text* alert = Text::create();
alert->setText("ImageView scale9 render");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(26);
Text* alert = Text::create("ImageView scale9 render", "fonts/Marker Felt.ttf", 26);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.125f));
alert->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getSize().height * 2.125f));
_uiLayer->addChild(alert);
// Create the imageview
ImageView* imageView = ImageView::create();
ImageView* imageView = ImageView::create("cocosui/buttonHighlighted.png");
imageView->setScale9Enabled(true);
imageView->loadTexture("cocosui/buttonHighlighted.png");
imageView->setSize(Size(200, 85));
imageView->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + imageView->getSize().height / 4.0f));
imageView->setSize(Size(300, 115));
imageView->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + imageView->getSize().height / 4.0f));
_uiLayer->addChild(imageView);
return true;

View File

@ -20,12 +20,11 @@ bool UILayoutTest::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text* alert = Text::create();
alert->setText("Layout");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("Layout", "fonts/Marker Felt.ttf", 30 );
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
alert->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81)) ;
@ -42,25 +41,22 @@ bool UILayoutTest::init()
(backgroundSize.height - layout->getSize().height) / 2.0f));
_uiLayer->addChild(layout);
Button* button = Button::create();
button->setTouchEnabled(true);
button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f));
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setPosition(Point(button->getSize().width / 2.0f,
layout->getSize().height - button->getSize().height / 2.0f));
layout->addChild(button);
Button* titleButton = Button::create();
titleButton->setTouchEnabled(true);
titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
titleButton->setTitleText("Title Button");
titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f));
layout->addChild(titleButton);
Button* button_scale9 = Button::create();
button_scale9->setTouchEnabled(true);
button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true);
button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height));
button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f));
button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f,
button_scale9->getSize().height / 2.0f));
layout->addChild(button_scale9);
return true;
@ -86,12 +82,11 @@ bool UILayoutTest_Color::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text* alert = Text::create();
alert->setText("Layout color render");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("Layout color render", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
alert->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
@ -110,25 +105,23 @@ bool UILayoutTest_Color::init()
(backgroundSize.height - layout->getSize().height) / 2.0f));
_uiLayer->addChild(layout);
Button* button = Button::create();
button->setTouchEnabled(true);
button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f));
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setPosition(Point(button->getSize().width / 2.0f,
layout->getSize().height - button->getSize().height / 2.0f));
layout->addChild(button);
Button* titleButton = Button::create();
titleButton->setTouchEnabled(true);
titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
titleButton->setTitleText("Title Button");
titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f));
layout->addChild(titleButton);
Button* button_scale9 = Button::create();
button_scale9->setTouchEnabled(true);
button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true);
button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height));
button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f));
button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f,
button_scale9->getSize().height / 2.0f));
layout->addChild(button_scale9);
return true;
@ -153,12 +146,11 @@ bool UILayoutTest_Gradient::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text* alert = Text::create();
alert->setText("Layout gradient render");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("Layout gradient render", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
alert->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
@ -177,25 +169,23 @@ bool UILayoutTest_Gradient::init()
(backgroundSize.height - layout->getSize().height) / 2.0f));
_uiLayer->addChild(layout);
Button* button = Button::create();
button->setTouchEnabled(true);
button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f));
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setPosition(Point(button->getSize().width / 2.0f,
layout->getSize().height - button->getSize().height / 2.0f));
layout->addChild(button);
Button* titleButton = Button::create();
titleButton->setTouchEnabled(true);
titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
titleButton->setTitleText("Title Button");
titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f));
layout->addChild(titleButton);
Button* button_scale9 = Button::create();
button_scale9->setTouchEnabled(true);
button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true);
button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height));
button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f));
button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f,
button_scale9->getSize().height / 2.0f));
layout->addChild(button_scale9);
return true;
@ -220,10 +210,7 @@ bool UILayoutTest_BackGroundImage::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text* alert = Text::create();
alert->setText("Layout background image");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(20);
Text* alert = Text::create("Layout background image", "fonts/Marker Felt.ttf", 20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f));
_uiLayer->addChild(alert);
@ -244,25 +231,22 @@ bool UILayoutTest_BackGroundImage::init()
(backgroundSize.height - layout->getSize().height) / 2.0f));
_uiLayer->addChild(layout);
Button* button = Button::create();
button->setTouchEnabled(true);
button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f));
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setPosition(Point(button->getSize().width / 2.0f,
layout->getSize().height - button->getSize().height / 2.0f));
layout->addChild(button);
Button* titleButton = Button::create();
titleButton->setTouchEnabled(true);
titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
titleButton->setTitleText("Title Button");
titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f));
layout->addChild(titleButton);
Button* button_scale9 = Button::create();
button_scale9->setTouchEnabled(true);
button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true);
button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height));
button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f));
button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f,
button_scale9->getSize().height / 2.0f));
layout->addChild(button_scale9);
return true;
@ -287,10 +271,7 @@ bool UILayoutTest_BackGroundImage_Scale9::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text* alert = Text::create();
alert->setText("Layout background image scale9");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(20);
Text* alert = Text::create("Layout background image scale9", "fonts/Marker Felt.ttf", 20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f));
_uiLayer->addChild(alert);
@ -311,26 +292,23 @@ bool UILayoutTest_BackGroundImage_Scale9::init()
(backgroundSize.height - layout->getSize().height) / 2.0f));
_uiLayer->addChild(layout);
Button* button = Button::create();
button->setTouchEnabled(true);
button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f));
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setPosition(Point(button->getSize().width / 2.0f,
layout->getSize().height - button->getSize().height / 2.0f));
layout->addChild(button);
Button* titleButton = Button::create();
titleButton->setTouchEnabled(true);
titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
titleButton->setTitleText("Title Button");
titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f));
layout->addChild(titleButton);
Button* button_scale9 = Button::create();
button_scale9->setTouchEnabled(true);
button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true);
button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height));
button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f));
layout->addChild(button_scale9);
button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f,
button_scale9->getSize().height / 2.0f));
layout->addChild(button_scale9);
return true;
}
@ -354,12 +332,11 @@ bool UILayoutTest_Layout_Linear_Vertical::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text* alert = Text::create();
alert->setText("Layout Linear Vertical");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(20);
Text* alert = Text::create("Layout Linear Vertical", "fonts/Marker Felt.ttf", 20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f));
alert->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getSize().height * 4.5f));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
@ -378,9 +355,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init()
_uiLayer->addChild(layout);
Button* button = Button::create();
button->setTouchEnabled(true);
button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
layout->addChild(button);
LinearLayoutParameter* lp1 = LinearLayoutParameter::create();
@ -389,9 +364,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init()
lp1->setMargin(Margin(0.0f, 5.0f, 0.0f, 10.0f));
Button* titleButton = Button::create();
titleButton->setTouchEnabled(true);
titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
titleButton->setTitleText("Title Button");
layout->addChild(titleButton);
@ -401,9 +374,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init()
lp2->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
Button* button_scale9 = Button::create();
button_scale9->setTouchEnabled(true);
button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true);
button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height));
layout->addChild(button_scale9);
@ -414,8 +385,6 @@ bool UILayoutTest_Layout_Linear_Vertical::init()
lp3->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
// layout->doLayout();
return true;
}
@ -439,10 +408,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text* alert = Text::create();
alert->setText("Layout Linear Horizontal");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(20);
Text* alert = Text::create("Layout Linear Horizontal", "fonts/Marker Felt.ttf", 20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f));
_uiLayer->addChild(alert);
@ -463,9 +429,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init()
(backgroundSize.height - layout->getSize().height) / 2.0f));
_uiLayer->addChild(layout);
Button* button = Button::create();
button->setTouchEnabled(true);
button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
layout->addChild(button);
LinearLayoutParameter* lp1 = LinearLayoutParameter::create();
@ -474,9 +438,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init()
lp1->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
Button* titleButton = Button::create();
titleButton->setTouchEnabled(true);
titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
titleButton->setTitleText("Title Button");
layout->addChild(titleButton);
@ -486,9 +448,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init()
lp2->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
Button* button_scale9 = Button::create();
button_scale9->setTouchEnabled(true);
button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true);
button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height));
layout->addChild(button_scale9);
@ -499,8 +459,6 @@ bool UILayoutTest_Layout_Linear_Horizontal::init()
lp3->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
// layout->doLayout();
return true;
}
@ -524,10 +482,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text* alert = Text::create();
alert->setText("Layout Relative Align Parent");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(20);
Text* alert = Text::create("Layout Relative Align Parent", "fonts/Marker Felt.ttf", 20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f));
_uiLayer->addChild(alert);
@ -550,9 +505,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init()
_uiLayer->addChild(layout);
// top left
Button* button_TopLeft = Button::create();
button_TopLeft->setTouchEnabled(true);
button_TopLeft->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
Button* button_TopLeft = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
layout->addChild(button_TopLeft);
RelativeLayoutParameter* rp_TopLeft = RelativeLayoutParameter::create();
@ -561,9 +515,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init()
// top center horizontal
Button* button_TopCenter = Button::create();
button_TopCenter->setTouchEnabled(true);
button_TopCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
Button* button_TopCenter = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
layout->addChild(button_TopCenter);
RelativeLayoutParameter* rp_TopCenter = RelativeLayoutParameter::create();
@ -572,9 +525,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init()
// top right
Button* button_TopRight = Button::create();
button_TopRight->setTouchEnabled(true);
button_TopRight->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
Button* button_TopRight = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
layout->addChild(button_TopRight);
RelativeLayoutParameter* rp_TopRight = RelativeLayoutParameter::create();
@ -583,9 +535,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init()
// left center
Button* button_LeftCenter = Button::create();
button_LeftCenter->setTouchEnabled(true);
button_LeftCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
Button* button_LeftCenter = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
layout->addChild(button_LeftCenter);
RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create();
@ -594,9 +545,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init()
// center
Button* buttonCenter = Button::create();
buttonCenter->setTouchEnabled(true);
buttonCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
Button* buttonCenter = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
layout->addChild(buttonCenter);
RelativeLayoutParameter* rpCenter = RelativeLayoutParameter::create();
@ -605,9 +555,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init()
// right center
Button* button_RightCenter = Button::create();
button_RightCenter->setTouchEnabled(true);
button_RightCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
Button* button_RightCenter = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
layout->addChild(button_RightCenter);
RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create();
@ -616,9 +565,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init()
// left bottom
Button* button_LeftBottom = Button::create();
button_LeftBottom->setTouchEnabled(true);
button_LeftBottom->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
Button* button_LeftBottom = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
layout->addChild(button_LeftBottom);
RelativeLayoutParameter* rp_LeftBottom = RelativeLayoutParameter::create();
@ -627,9 +575,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init()
// bottom center
Button* button_BottomCenter = Button::create();
button_BottomCenter->setTouchEnabled(true);
button_BottomCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
Button* button_BottomCenter = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
layout->addChild(button_BottomCenter);
RelativeLayoutParameter* rp_BottomCenter = RelativeLayoutParameter::create();
@ -638,9 +585,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init()
// right bottom
Button* button_RightBottom = Button::create();
button_RightBottom->setTouchEnabled(true);
button_RightBottom->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
Button* button_RightBottom = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
layout->addChild(button_RightBottom);
RelativeLayoutParameter* rp_RightBottom = RelativeLayoutParameter::create();
@ -648,8 +594,6 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init()
button_RightBottom->setLayoutParameter(rp_RightBottom);
// layout->doLayout();
return true;
}
@ -673,10 +617,7 @@ bool UILayoutTest_Layout_Relative_Location::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text* alert = Text::create();
alert->setText("Layout Relative Location");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(20);
Text* alert = Text::create("Layout Relative Location", "fonts/Marker Felt.ttf", 20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f));
_uiLayer->addChild(alert);
@ -697,8 +638,7 @@ bool UILayoutTest_Layout_Relative_Location::init()
_uiLayer->addChild(layout);
// center
ImageView* imageView_Center = ImageView::create();
imageView_Center->loadTexture("cocosui/scrollviewbg.png");
ImageView* imageView_Center = ImageView::create("cocosui/scrollviewbg.png");
layout->addChild(imageView_Center);
RelativeLayoutParameter* rp_Center = RelativeLayoutParameter::create();
@ -708,8 +648,7 @@ bool UILayoutTest_Layout_Relative_Location::init()
// above center
ImageView* imageView_AboveCenter = ImageView::create();
imageView_AboveCenter->loadTexture("cocosui/switch-mask.png");
ImageView* imageView_AboveCenter = ImageView::create("cocosui/switch-mask.png");
layout->addChild(imageView_AboveCenter);
RelativeLayoutParameter* rp_AboveCenter = RelativeLayoutParameter::create();
@ -719,8 +658,7 @@ bool UILayoutTest_Layout_Relative_Location::init()
// below center
ImageView* imageView_BelowCenter = ImageView::create();
imageView_BelowCenter->loadTexture("cocosui/switch-mask.png");
ImageView* imageView_BelowCenter = ImageView::create("cocosui/switch-mask.png");
layout->addChild(imageView_BelowCenter);
RelativeLayoutParameter* rp_BelowCenter = RelativeLayoutParameter::create();
@ -730,8 +668,7 @@ bool UILayoutTest_Layout_Relative_Location::init()
// left center
ImageView* imageView_LeftCenter = ImageView::create();
imageView_LeftCenter->loadTexture("cocosui/switch-mask.png");
ImageView* imageView_LeftCenter = ImageView::create("cocosui/switch-mask.png");
layout->addChild(imageView_LeftCenter);
RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create();
@ -742,8 +679,7 @@ bool UILayoutTest_Layout_Relative_Location::init()
// right center
ImageView* imageView_RightCenter = ImageView::create();
imageView_RightCenter->loadTexture("cocosui/switch-mask.png");
ImageView* imageView_RightCenter = ImageView::create("cocosui/switch-mask.png");
layout->addChild(imageView_RightCenter);
RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create();
@ -752,93 +688,9 @@ bool UILayoutTest_Layout_Relative_Location::init()
imageView_RightCenter->setLayoutParameter(rp_RightCenter);
// layout->doLayout();
return true;
}
return false;
}
// UILayoutTest_Layout_Grid
/*
UILayoutTest_Layout_Grid::UILayoutTest_Layout_Grid()
{
}
UILayoutTest_Layout_Grid::~UILayoutTest_Layout_Grid()
{
}
bool UILayoutTest_Layout_Grid::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add the alert
Text* alert = Text::create();
alert->setText("Layout Grid");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
// Create the layout
Layout* layout = Layout::create();
layout->setLayoutType(LAYOUT_GRID_MODE_COLUMN);
layout->setSize(Size(280, 150));
Size backgroundSize = background->getSize();
layout->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f +
(backgroundSize.width - layout->getSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - layout->getSize().height) / 2.0f));
_uiLayer->addChild(layout);
// create items
for (int i = 0; i < 14; ++i)
{
Button* button = Button::create();
button->setName("TextButton");
button->setTouchEnabled(true);
button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
button->setScale9Enabled(true);
AffineTransform transform = AffineTransformMakeIdentity();
transform = AffineTransformScale(transform, 3.0f, 1.3f);
button->setSize(SizeApplyAffineTransform(button->getContentSize(), transform));
button->setTitleText(CCString::createWithFormat("grid_%d", i)->getCString());
Layout* item = Layout::create();
item->setTouchEnabled(true);
item->setSize(button->getSize());
button->setPosition(Point(item->getSize().width / 2.0f, item->getSize().height / 2.0f));
item->addChild(button);
GridLayoutParameter* gp = GridLayoutParameter::create();
item->setLayoutParameter(gp);
gp->setMargin(Margin(0.0f, 0.0f, 0.0f, 0.0f));
layout->addChild(item);
}
// set grid view row and column
Widget* item = static_cast<Widget*>(layout->getChildren().at(0));
int rowCount = layout->getSize().height / item->getSize().height;
int columnCount = layout->getSize().width / item->getSize().width;
layout->setGridLayoutRowAndColumnCount(rowCount, columnCount);
// layout->doLayout();
return true;
}
return false;
}
*/

View File

@ -24,21 +24,17 @@ bool UIListViewTest_Vertical::init()
{
Size widgetSize = _widget->getSize();
_displayValueLabel = Text::create();
_displayValueLabel->setText("Move by vertical direction");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel);
Text* alert = Text::create();
alert->setText("ListView vertical");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("ListView vertical", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
alert->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
@ -75,15 +71,14 @@ bool UIListViewTest_Vertical::init()
// create model
Button* default_button = Button::create();
Button* default_button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png");
default_button->setName("Title Button");
default_button->setTouchEnabled(true);
default_button->loadTextures("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png", "");
Layout* default_item = Layout::create();
default_item->setTouchEnabled(true);
default_item->setSize(default_button->getSize());
default_button->setPosition(Point(default_item->getSize().width / 2.0f, default_item->getSize().height / 2.0f));
default_button->setPosition(Point(default_item->getSize().width / 2.0f,
default_item->getSize().height / 2.0f));
default_item->addChild(default_button);
// set model
@ -104,10 +99,8 @@ bool UIListViewTest_Vertical::init()
// add custom item
for (int i = 0; i < count / 4; ++i)
{
Button* custom_button = Button::create();
Button* custom_button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
custom_button->setName("Title Button");
custom_button->setTouchEnabled(true);
custom_button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
custom_button->setScale9Enabled(true);
custom_button->setSize(default_button->getSize());
@ -123,10 +116,8 @@ bool UIListViewTest_Vertical::init()
ssize_t items_count = items.size();
for (int i = 0; i < count / 4; ++i)
{
Button* custom_button = Button::create();
Button* custom_button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
custom_button->setName("Title Button");
custom_button->setTouchEnabled(true);
custom_button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
custom_button->setScale9Enabled(true);
custom_button->setSize(default_button->getSize());
@ -209,19 +200,16 @@ bool UIListViewTest_Horizontal::init()
{
Size widgetSize = _widget->getSize();
_displayValueLabel = Text::create();
_displayValueLabel->setText("Move by horizontal direction");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("Move by horizontal direction", "fonts/Marker Felt.ttf", 32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f
+ _displayValueLabel->getContentSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel);
Text* alert = Text::create();
alert->setText("ListView horizontal");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("ListView horizontal", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
_uiLayer->addChild(alert);
@ -260,10 +248,8 @@ bool UIListViewTest_Horizontal::init()
// create model
Button* default_button = Button::create();
Button* default_button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png");
default_button->setName("Title Button");
default_button->setTouchEnabled(true);
default_button->loadTextures("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png", "");
Layout *default_item = Layout::create();
default_item->setTouchEnabled(true);
@ -289,10 +275,8 @@ bool UIListViewTest_Horizontal::init()
// add custom item
for (int i = 0; i < count / 4; ++i)
{
Button* custom_button = Button::create();
Button* custom_button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
custom_button->setName("Title Button");
custom_button->setTouchEnabled(true);
custom_button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
custom_button->setScale9Enabled(true);
custom_button->setSize(default_button->getSize());
@ -308,10 +292,8 @@ bool UIListViewTest_Horizontal::init()
ssize_t items_count = items.size();
for (int i = 0; i < count / 4; ++i)
{
Button* custom_button = Button::create();
Button* custom_button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
custom_button->setName("Title Button");
custom_button->setTouchEnabled(true);
custom_button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
custom_button->setScale9Enabled(true);
custom_button->setSize(default_button->getSize());

View File

@ -25,21 +25,17 @@ bool UILoadingBarTest_Left::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text* alert = Text::create();
alert->setText("LoadingBar left");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("LoadingBar left", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the loading bar
LoadingBar* loadingBar = LoadingBar::create();
LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png");
loadingBar->setTag(0);
loadingBar->loadTexture("cocosui/sliderProgress.png");
loadingBar->setPercent(0);
loadingBar->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
loadingBar->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
_uiLayer->addChild(loadingBar);
return true;
@ -107,22 +103,19 @@ bool UILoadingBarTest_Right::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text *alert = Text::create();
alert->setText("LoadingBar right");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text *alert = Text::create("LoadingBar right", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the loading bar
LoadingBar* loadingBar = LoadingBar::create();
LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png");
loadingBar->setTag(0);
loadingBar->loadTexture("cocosui/sliderProgress.png");
loadingBar->setDirection(LoadingBarTypeRight);
loadingBar->setPercent(0);
loadingBar->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
loadingBar->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
_uiLayer->addChild(loadingBar);
return true;
@ -190,24 +183,21 @@ bool UILoadingBarTest_Left_Scale9::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text* alert = Text::create();
alert->setText("LoadingBar left scale9 render");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(20);
Text* alert = Text::create("LoadingBar left scale9 render", "fonts/Marker Felt.ttf", 20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7f));
_uiLayer->addChild(alert);
// Create the loading bar
LoadingBar* loadingBar = LoadingBar::create();
LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png");
loadingBar->setTag(0);
loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png");
loadingBar->setScale9Enabled(true);
loadingBar->setCapInsets(Rect(0, 0, 0, 0));
loadingBar->setSize(Size(300, loadingBar->getContentSize().height));
loadingBar->setPercent(0);
loadingBar->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
loadingBar->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
_uiLayer->addChild(loadingBar);
return true;
@ -275,25 +265,22 @@ bool UILoadingBarTest_Right_Scale9::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text *alert = Text::create();
alert->setText("LoadingBar right scale9 render");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(20);
Text *alert = Text::create("LoadingBar right scale9 render", "fonts/Marker Felt.ttf", 20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7f));
_uiLayer->addChild(alert);
// Create the loading bar
LoadingBar* loadingBar = LoadingBar::create();
LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png");
loadingBar->setTag(0);
loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png");
loadingBar->setScale9Enabled(true);
loadingBar->setCapInsets(Rect(0, 0, 0, 0));
loadingBar->setSize(Size(300, loadingBar->getContentSize().height));
loadingBar->setDirection(LoadingBarTypeRight);
loadingBar->setPercent(0);
loadingBar->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
loadingBar->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
_uiLayer->addChild(loadingBar);
return true;

View File

@ -21,19 +21,15 @@ bool UIPageViewTest::init()
Size widgetSize = _widget->getSize();
// Add a label in which the dragpanel events will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("Move by horizontal direction");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("Move by horizontal direction", "fonts/Marker Felt.ttf", 32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f +
_displayValueLabel->getContentSize().height * 1.5));
_uiLayer->addChild(_displayValueLabel);
// Add the black background
Text* alert = Text::create();
alert->setText("PageView");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("PageView", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
_uiLayer->addChild(alert);
@ -44,7 +40,6 @@ bool UIPageViewTest::init()
// Create the page view
PageView* pageView = PageView::create();
pageView->setTouchEnabled(true);
pageView->setSize(Size(240.0f, 130.0f));
Size backgroundSize = background->getContentSize();
pageView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f +
@ -57,18 +52,13 @@ bool UIPageViewTest::init()
Layout* layout = Layout::create();
layout->setSize(Size(240.0f, 130.0f));
ImageView* imageView = ImageView::create();
imageView->setTouchEnabled(true);
ImageView* imageView = ImageView::create("cocosui/scrollviewbg.png");
imageView->setScale9Enabled(true);
imageView->loadTexture("cocosui/scrollviewbg.png");
imageView->setSize(Size(240, 130));
imageView->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f));
layout->addChild(imageView);
Text* label = Text::create();
label->setText(CCString::createWithFormat("page %d", (i + 1))->getCString());
label->setFontName("fonts/Marker Felt.ttf");
label->setFontSize(30);
Text* label = Text::create(StringUtils::format("page %d",(i+1)), "fonts/Marker Felt.ttf", 30);
label->setColor(Color3B(192, 192, 192));
label->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f));
layout->addChild(label);

View File

@ -21,18 +21,14 @@ bool UIRichTextTest::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text *alert = Text::create();
alert->setText("RichText");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create();
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
button->setTitleText("switch");
button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + button->getSize().height * 2.5));
button->addTouchEventListener(this, toucheventselector(UIRichTextTest::touchEvent));

View File

@ -21,19 +21,14 @@ bool UIScrollViewTest_Vertical::init()
Size widgetSize = _widget->getSize();
// Add a label in which the scrollview alert will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("Move by vertical direction");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create();
alert->setText("ScrollView vertical");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("ScrollView vertical", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
_uiLayer->addChild(alert);
@ -44,7 +39,6 @@ bool UIScrollViewTest_Vertical::init()
// Create the scrollview by vertical
ui::ScrollView* scrollView = ui::ScrollView::create();
scrollView->setTouchEnabled(true);
scrollView->setSize(Size(280.0f, 150.0f));
Size backgroundSize = background->getContentSize();
scrollView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f +
@ -53,31 +47,24 @@ bool UIScrollViewTest_Vertical::init()
(backgroundSize.height - scrollView->getSize().height) / 2.0f));
_uiLayer->addChild(scrollView);
ImageView* imageView = ImageView::create();
imageView->loadTexture("cocosui/ccicon.png");
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
float innerWidth = scrollView->getSize().width;
float innerHeight = scrollView->getSize().height + imageView->getSize().height;
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
Button* button = Button::create();
button->setTouchEnabled(true);
button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setPosition(Point(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getSize().height / 2.0f));
scrollView->addChild(button);
Button* titleButton = Button::create();
titleButton->setTouchEnabled(true);
titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
titleButton->setTitleText("Title Button");
titleButton->setPosition(Point(innerWidth / 2.0f, button->getBottomInParent() - button->getSize().height));
scrollView->addChild(titleButton);
Button* button_scale9 = Button::create();
button_scale9->setTouchEnabled(true);
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true);
button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height));
button_scale9->setPosition(Point(innerWidth / 2.0f, titleButton->getBottomInParent() - titleButton->getSize().height));
scrollView->addChild(button_scale9);
@ -109,18 +96,12 @@ bool UIScrollViewTest_Horizontal::init()
Size widgetSize = _widget->getSize();
// Add a label in which the scrollview alert will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("Move by horizontal direction");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("Move by horizontal direction","fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel);
Text* alert = Text::create();
alert->setText("ScrollView horizontal");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("ScrollView horizontal","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
_uiLayer->addChild(alert);
@ -133,7 +114,6 @@ bool UIScrollViewTest_Horizontal::init()
ui::ScrollView* scrollView = ui::ScrollView::create();
scrollView->setBounceEnabled(true);
scrollView->setDirection(SCROLLVIEW_DIR_HORIZONTAL);
scrollView->setTouchEnabled(true);
scrollView->setSize(Size(280.0f, 150.0f));
scrollView->setInnerContainerSize(scrollView->getSize());
Size backgroundSize = background->getContentSize();
@ -143,33 +123,26 @@ bool UIScrollViewTest_Horizontal::init()
(backgroundSize.height - scrollView->getSize().height) / 2.0f));
_uiLayer->addChild(scrollView);
ImageView* imageView = ImageView::create();
imageView->loadTexture("cocosui/ccicon.png");
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
float innerWidth = scrollView->getSize().width + imageView->getSize().width;
float innerHeight = scrollView->getSize().height;
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
Button* button = Button::create();
button->setTouchEnabled(true);
button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setPosition(Point(button->getSize().width / 2.0f,
scrollView->getInnerContainerSize().height - button->getSize().height / 2.0f));
scrollView->addChild(button);
Button* titleButton = Button::create();
titleButton->setTouchEnabled(true);
titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
titleButton->setTitleText("Title Button");
titleButton->setPosition(Point(button->getRightInParent() + button->getSize().width / 2.0f,
button->getBottomInParent() - button->getSize().height / 2.0f));
scrollView->addChild(titleButton);
Button* button_scale9 = Button::create();
button_scale9->setTouchEnabled(true);
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true);
button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height));
button_scale9->setPosition(Point(titleButton->getRightInParent() + titleButton->getSize().width / 2.0f,
titleButton->getBottomInParent() - titleButton->getSize().height / 2.0f));
@ -203,19 +176,13 @@ bool UIScrollViewTest_Both::init()
Size widgetSize = _widget->getSize();;
// Add a label in which the dragpanel events will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("Move by any direction");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("Move by any direction","fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create();
alert->setText("ScrollView both");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("ScrollView both","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
_uiLayer->addChild(alert);
@ -237,9 +204,7 @@ bool UIScrollViewTest_Both::init()
(backgroundSize.width - scrollView->getSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - scrollView->getSize().height) / 2.0f));
ImageView* imageView = ImageView::create();
imageView->setTouchEnabled(true);
imageView->loadTexture("Hello.png");
ImageView* imageView = ImageView::create("Hello.png");
scrollView->addChild(imageView);
scrollView->setInnerContainerSize(imageView->getContentSize());
@ -272,19 +237,13 @@ bool UIScrollViewTest_ScrollToPercentBothDirection::init()
Size widgetSize = _widget->getSize();
// Add a label in which the dragpanel events will be displayed
_displayValueLabel = Text::create();
// _displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf",30);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create();
alert->setText("ScrollView scroll to percent both directrion");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(20);
Text* alert = Text::create("ScrollView scroll to percent both directrion","fonts/Marker Felt.ttf",20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5));
_uiLayer->addChild(alert);
@ -305,8 +264,7 @@ bool UIScrollViewTest_ScrollToPercentBothDirection::init()
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - sc->getSize().height) / 2.0f));
sc->scrollToPercentBothDirection(Point(50, 50), 1, true);
ImageView* iv = ImageView::create();
iv->loadTexture("cocosui/Hello.png");
ImageView* iv = ImageView::create("cocosui/Hello.png");
iv->setPosition(Point(240, 160));
sc->addChild(iv);
_uiLayer->addChild(sc);
@ -334,19 +292,13 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce::init()
Size widgetSize = _widget->getSize();
// Add a label in which the dragpanel events will be displayed
_displayValueLabel = Text::create();
// _displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create();
alert->setText("ScrollView scroll to percent both directrion bounce");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(20);
Text* alert = Text::create("ScrollView scroll to percent both directrion bounce","fonts/Marker Felt.ttf",20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5));
_uiLayer->addChild(alert);
@ -368,8 +320,7 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce::init()
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - sc->getSize().height) / 2.0f));
sc->scrollToPercentBothDirection(Point(50, 50), 1, true);
ImageView* iv = ImageView::create();
iv->loadTexture("cocosui/Hello.png");
ImageView* iv = ImageView::create("cocosui/Hello.png");
iv->setPosition(Point(240, 160));
sc->addChild(iv);
_uiLayer->addChild(sc);

View File

@ -22,26 +22,19 @@ bool UISliderTest::init()
Size widgetSize = _widget->getSize();
// Add a label in which the slider alert will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("Move the slider thumb");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("Move the slider thumb","Move the slider thumb",32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create();
alert->setText("Slider");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("Slider","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the slider
Slider* slider = Slider::create();
slider->setTouchEnabled(true);
slider->loadBarTexture("cocosui/sliderTrack.png");
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
slider->loadProgressBarTexture("cocosui/sliderProgress.png");
@ -49,19 +42,6 @@ bool UISliderTest::init()
slider->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent));
_uiLayer->addChild(slider);
/*
// Create the slider that set allow min progress and allow max progress
Slider* sliderAllow = Slider::create();
// sliderAllow->setMinAllowPercent(20);
// sliderAllow->setMaxAllowPercent(80);
sliderAllow->setTouchEnabled(true);
sliderAllow->loadBarTexture("cocosui/sliderTrack.png");
sliderAllow->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
sliderAllow->loadProgressBarTexture("cocosui/sliderProgress.png");
sliderAllow->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - sliderAllow->getSize().height * 2.0f));
sliderAllow->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent));
_uiLayer->addChild(sliderAllow);
*/
return true;
}
@ -97,26 +77,19 @@ bool UISliderTest_Scale9::init()
Size widgetSize = _widget->getSize();
// Add a label in which the slider alert will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("Move the slider thumb");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("Move the slider thumb","fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text *alert = Text::create();
alert->setText("Slider scale9 render");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text *alert = Text::create("Slider scale9 render","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the slider
Slider* slider = Slider::create();
slider->setTouchEnabled(true);
slider->loadBarTexture("cocosui/sliderTrack2.png");
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
slider->loadProgressBarTexture("cocosui/slider_bar_active_9patch.png");
@ -127,22 +100,6 @@ bool UISliderTest_Scale9::init()
slider->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest_Scale9::sliderEvent));
_uiLayer->addChild(slider);
/*
// Create the slider that set allow min progress and allow max progress
Slider* sliderAllow = Slider::create();
// sliderAllow->setMinAllowPercent(20);
// sliderAllow->setMaxAllowPercent(80);
sliderAllow->setTouchEnabled(true);
sliderAllow->loadBarTexture("cocosui/sliderTrack2.png");
sliderAllow->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
sliderAllow->loadProgressBarTexture("cocosui/slider_bar_active_9patch.png");
sliderAllow->setScale9Enabled(true);
sliderAllow->setCapInsets(Rect(0, 0, 0, 0));
sliderAllow->setSize(Size(250.0f, 10.0f / Director::getInstance()->getContentScaleFactor()));
sliderAllow->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - slider->getSize().height * 3.0f));
sliderAllow->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest_Scale9::sliderEvent));
_uiLayer->addChild(sliderAllow);
*/
return true;
}

View File

@ -12,17 +12,13 @@ bool UITextAtlasTest::init()
Size widgetSize = _widget->getSize();
// Add the alert
Text* alert = Text::create();
alert->setText("TextAtlas");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("TextAtlas","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the text atlas
TextAtlas* textAtlas = TextAtlas::create();
textAtlas->setProperty("1234567890", "cocosui/labelatlas.png", 17, 22, "0");
TextAtlas* textAtlas = TextAtlas::create("1234567890", "cocosui/labelatlas.png", 17, 22, "0");
textAtlas->setPosition(Point((widgetSize.width) / 2, widgetSize.height / 2.0f));
_uiLayer->addChild(textAtlas);

View File

@ -11,18 +11,13 @@ bool UITextBMFontTest::init()
{
Size widgetSize = _widget->getSize();
Text* alert = Text::create();
alert->setText("TextBMFont");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("TextBMFont","TextBMFont",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the TextBMFont
TextBMFont* textBMFont = TextBMFont::create();
textBMFont->setFntFile("cocosui/bitmapFontTest2.fnt");
textBMFont->setText("BMFont");
TextBMFont* textBMFont = TextBMFont::create("BMFont", "cocosui/bitmapFontTest2.fnt");
textBMFont->setPosition(Point(widgetSize.width / 2, widgetSize.height / 2.0f + textBMFont->getSize().height / 8.0f));
_uiLayer->addChild(textBMFont);

View File

@ -20,35 +20,24 @@ bool UITextFieldTest::init()
Size widgetSize = _widget->getSize();
// Add a label in which the textfield events will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create();
alert->setText("TextField");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("TextField","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
_uiLayer->addChild(alert);
// Create the textfield
TextField* textField = TextField::create();
textField->setTouchEnabled(true);
textField->setFontName("fonts/Marker Felt.ttf");
textField->setFontSize(30);
textField->setPlaceHolder("input words here");
TextField* textField = TextField::create("input words here","fonts/Marker Felt.ttf",30);
textField->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest::textFieldEvent));
_uiLayer->addChild(textField);
// textField->setColor(Color3B(255, 0, 0));
// textField->setColorSpaceHolder(Color3B(255, 255, 255));
return true;
}
@ -109,31 +98,21 @@ bool UITextFieldTest_MaxLength::init()
Size screenSize = CCDirector::getInstance()->getWinSize();
// Add a label in which the textfield events will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text *alert = Text::create();
alert->setText("TextField max length");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text *alert = Text::create("TextField max length","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getSize().height * 3.075f));
_uiLayer->addChild(alert);
// Create the textfield
TextField* textField = TextField::create();
TextField* textField = TextField::create("input words here","fonts/Marker Felt.ttf",30);
textField->setMaxLengthEnabled(true);
textField->setMaxLength(3);
textField->setTouchEnabled(true);
textField->setFontName("fonts/Marker Felt.ttf");
textField->setFontSize(30);
textField->setPlaceHolder("input words here");
textField->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f));
textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest_MaxLength::textFieldEvent));
_uiLayer->addChild(textField);
@ -203,31 +182,21 @@ bool UITextFieldTest_Password::init()
Size screenSize = CCDirector::getInstance()->getWinSize();
// Add a label in which the textfield events will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(32);
_displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text *alert = Text::create();
alert->setText("TextField password");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text *alert = Text::create("TextField password","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getSize().height * 3.075f));
_uiLayer->addChild(alert);
// Create the textfield
TextField* textField = TextField::create();
TextField* textField = TextField::create("input password here","fonts/Marker Felt.ttf",30);
textField->setPasswordEnabled(true);
textField->setPasswordStyleText("*");
textField->setTouchEnabled(true);
textField->setFontName("fonts/Marker Felt.ttf");
textField->setFontSize(30);
textField->setPlaceHolder("input password here");
textField->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f));
textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest_Password::textFieldEvent));
_uiLayer->addChild(textField);
@ -292,33 +261,23 @@ bool UITextFieldTest_LineWrap::init()
Size widgetSize = _widget->getSize();
// Add a label in which the textfield events will be displayed
_displayValueLabel = Text::create();
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
_displayValueLabel->setFontSize(30);
_displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",30);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text *alert = Text::create();
alert->setText("TextField line wrap");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text *alert = Text::create("TextField line wrap","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
_uiLayer->addChild(alert);
// Create the textfield
TextField* textField = TextField::create();
TextField* textField = TextField::create("input words here","fonts/Marker Felt.ttf",30);
textField->ignoreContentAdaptWithSize(false);
textField->setSize(Size(240, 160));
textField->setTextHorizontalAlignment(TextHAlignment::CENTER);
textField->setTextVerticalAlignment(TextVAlignment::CENTER);
textField->setTouchEnabled(true);
textField->setFontName("fonts/Marker Felt.ttf");
textField->setFontSize(30);
textField->setPlaceHolder("input words here");
textField->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest_LineWrap::textFieldEvent));
_uiLayer->addChild(textField);

View File

@ -11,19 +11,13 @@ bool UITextTest::init()
{
Size widgetSize = _widget->getSize();
Text* alert = Text::create();
alert->setText("Text");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("Text","fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the text
Text* text = Text::create();
text->setText("Text");
text->setFontName("AmericanTypewriter");
text->setFontSize(30);
Text* text = Text::create("Text", "AmericanTypewriter", 30);
text->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + text->getSize().height / 4.0f));
_uiLayer->addChild(text);
@ -40,22 +34,16 @@ bool UITextTest_LineWrap::init()
{
Size widgetSize = _widget->getSize();
Text* alert = Text::create();
alert->setText("Text line wrap");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("Text line wrap","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the line wrap
Text* text = Text::create();
Text* text = Text::create("Text can line wrap","AmericanTypewriter",32);
text->ignoreContentAdaptWithSize(false);
text->setSize(Size(280, 150));
text->setTextHorizontalAlignment(TextHAlignment::CENTER);
text->setText("Text can line wrap");
text->setFontName("AmericanTypewriter");
text->setFontSize(32);
text->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - text->getSize().height / 8.0f));
_uiLayer->addChild(text);
@ -171,19 +159,13 @@ bool UITextTest_TTF::init()
{
Size widgetSize = _widget->getSize();
Text* alert = Text::create();
alert->setText("Text set TTF font");
alert->setFontName("fonts/Marker Felt.ttf");
alert->setFontSize(30);
Text* alert = Text::create("Text set TTF font","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the text, and set font with .ttf
Text* text = Text::create();
text->setText("Text");
text->setFontName("fonts/A Damn Mess.ttf");
text->setFontSize(30);
Text* text = Text::create("Text","fonts/A Damn Mess.ttf",30);
text->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + text->getSize().height / 4.0f));
_uiLayer->addChild(text);

View File

@ -8,6 +8,7 @@
#include "NewEventDispatcherTest.h"
#include "testResource.h"
#include "CCAutoreleasePool.h"
namespace {
@ -27,7 +28,8 @@ std::function<Layer*()> createFunctions[] =
CL(PauseResumeTargetTest),
CL(Issue4129),
CL(Issue4160),
CL(DanglingNodePointersTest)
CL(DanglingNodePointersTest),
CL(RegisterAndUnregisterWhileEventHanldingTest)
};
unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[0]);
@ -302,6 +304,8 @@ public:
void removeListenerOnTouchEnded(bool toRemove) { _removeListenerOnTouchEnded = toRemove; };
inline EventListener* getListener() { return _listener; };
private:
EventListener* _listener;
int _fixedPriority;
@ -1127,21 +1131,23 @@ PauseResumeTargetTest::PauseResumeTargetTest()
sprite2->setPosition(origin+Point(size.width/2, size.height/2));
addChild(sprite2, -20);
auto sprite3 = TouchableSprite::create();
auto sprite3 = TouchableSprite::create(100); // Sprite3 uses fixed priority listener
sprite3->setTexture("Images/YellowSquare.png");
sprite3->setPosition(Point(0, 0));
sprite2->addChild(sprite3, -1);
auto popup = MenuItemFont::create("Popup", [this](Ref* sender){
auto popup = MenuItemFont::create("Popup", [=](Ref* sender){
sprite3->getListener()->setEnabled(false);
_eventDispatcher->pauseEventListenersForTarget(this, true);
auto colorLayer = LayerColor::create(Color4B(0, 0, 255, 100));
this->addChild(colorLayer, 99999);
auto closeItem = MenuItemFont::create("close", [this, colorLayer](Ref* sender){
auto closeItem = MenuItemFont::create("close", [=](Ref* sender){
colorLayer->removeFromParent();
_eventDispatcher->resumeEventListenersForTarget(this, true);
sprite3->getListener()->setEnabled(true);
});
closeItem->setPosition(VisibleRect::center());
@ -1174,7 +1180,7 @@ std::string PauseResumeTargetTest::title() const
std::string PauseResumeTargetTest::subtitle() const
{
return "";
return "Yellow block uses fixed priority";
}
// Issue4129
@ -1409,3 +1415,44 @@ std::string DanglingNodePointersTest::subtitle() const
"CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS == 1\n&& COCOS2D_DEBUG > 0";
#endif
}
RegisterAndUnregisterWhileEventHanldingTest::RegisterAndUnregisterWhileEventHanldingTest()
{
Point origin = Director::getInstance()->getVisibleOrigin();
Size size = Director::getInstance()->getVisibleSize();
auto callback1 = [=](DanglingNodePointersTestSprite * sprite)
{
auto callback2 = [](DanglingNodePointersTestSprite * sprite)
{
CCASSERT(false, "This should never get called!");
};
{
AutoreleasePool pool;
auto sprite2 = DanglingNodePointersTestSprite::create(callback2);
sprite2->setTexture("Images/CyanSquare.png");
sprite2->setPosition(origin+Point(size.width/2, size.height/2));
addChild(sprite2, 0);
removeChild(sprite2);
}
};
auto sprite1 = DanglingNodePointersTestSprite::create(callback1);
sprite1->setTexture("Images/CyanSquare.png");
sprite1->setPosition(origin+Point(size.width/2, size.height/2));
addChild(sprite1, -10);
}
std::string RegisterAndUnregisterWhileEventHanldingTest::title() const
{
return "RegisterAndUnregisterWhileEventHanldingTest";
}
std::string RegisterAndUnregisterWhileEventHanldingTest::subtitle() const
{
return "Tap the square multiple times - should not crash!";
}

View File

@ -217,4 +217,14 @@ public:
virtual std::string subtitle() const override;
};
class RegisterAndUnregisterWhileEventHanldingTest : public EventDispatcherTestDemo
{
public:
CREATE_FUNC(RegisterAndUnregisterWhileEventHanldingTest);
RegisterAndUnregisterWhileEventHanldingTest();
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
#endif /* defined(__samples__NewEventDispatcherTest__) */

View File

@ -947,6 +947,10 @@ void VisitSceneGraph::update(float dt)
CC_PROFILER_START( this->profilerName() );
this->visit();
CC_PROFILER_STOP( this->profilerName() );
// Call `Renderer::clean` to prevent crash if current scene is destroyed.
// The render commands associated with current scene should be cleaned.
Director::getInstance()->getRenderer()->clean();
}
std::string VisitSceneGraph::title() const

View File

@ -6,7 +6,7 @@
static int sceneIdx = -1;
#define MAX_LAYER 9
#define MAX_LAYER 8
static Layer* createShaderLayer(int nIndex)
{
@ -20,7 +20,6 @@ static Layer* createShaderLayer(int nIndex)
case 5: return new ShaderPlasma();
case 6: return new ShaderBlur();
case 7: return new ShaderRetroEffect();
case 8: return new ShaderFail();
}
return NULL;
@ -745,58 +744,6 @@ std::string ShaderRetroEffect::subtitle() const
return "sin() effect with moving colors";
}
// ShaderFail
const GLchar *shader_frag_fail = "\n\
#ifdef GL_ES \n\
precision lowp float; \n\
#endif \n\
\n\
varying vec2 v_texCoord; \n\
uniform sampler2D CC_Texture0; \n\
\n\
vec4 colors[10]; \n\
\n\
void main(void) \n\
{ \n\
colors[0] = vec4(1,0,0,1); \n\
colors[1] = vec4(0,1,0,1); \n\
colors[2] = vec4(0,0,1,1); \n\
colors[3] = vec4(0,1,1,1); \n\
colors[4] = vec4(1,0,1,1); \n\
colors[5] = vec4(1,1,0,1); \n\
colors[6] = vec4(1,1,1,1); \n\
colors[7] = vec4(1,0.5,0,1); \n\
colors[8] = vec4(1,0.5,0.5,1); \n\
colors[9] = vec4(0.5,0.5,1,1); \n\
\n\
int y = int( mod(gl_FragCoord.y / 3.0, 10.0 ) ); \n\
gl_FragColor = colors[z] * texture2D(CC_Texture0, v_texCoord); \n\
} \n\
\n";
ShaderFail::ShaderFail()
{
auto p = new GLProgram();
p->initWithByteArrays(ccPositionTexture_vert, shader_frag_fail);
p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
p->link();
p->updateUniforms();
p->release();
}
std::string ShaderFail::title() const
{
return "Shader: Invalid shader";
}
std::string ShaderFail::subtitle() const
{
return "See console for output with useful error log";
}
///---------------------------------------
//
// ShaderTestScene

View File

@ -137,14 +137,6 @@ protected:
CustomCommand _customCommand;
};
class ShaderFail : public ShaderTestDemo
{
public:
ShaderFail();
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
class ShaderTestScene : public TestScene
{
public:

View File

@ -353,86 +353,83 @@ void TestController::addConsoleAutoTest()
for (int i = 0; i < g_testCount; i++)
{
// create the test scene and run it
auto scene = g_aTestNames[i].callback();
std::string msg("autotest: running test:");
msg += g_aTestNames[i].test_name;
send(fd, msg.c_str(), strlen(msg.c_str()),0);
send(fd, "\n",1,0);
if (scene)
currentController = &g_aTestNames[i];
sched->performFunctionInCocosThread( [&](){
auto scene = currentController->callback();
if(scene)
{
scene->runThisTest();
scene->release();
}
} );
wait(1);
BaseTest* firstTest = app->getCurrentTest();
if(firstTest == nullptr)
{
std::string msg("autotest: running test:");
msg += g_aTestNames[i].test_name;
send(fd, msg.c_str(), strlen(msg.c_str()),0);
send(fd, "\n",1,0);
continue;
}
std::string t1("");
t1 += firstTest->subtitle();
send(fd, t1.c_str(), strlen(t1.c_str()),0);
send(fd, "\n",1,0);
wait(2);
currentController = &g_aTestNames[i];
while(1)
{
//currentTest->nextCallback(nullptr);
sched->performFunctionInCocosThread( [&](){
currentController->callback()->runThisTest();
currentController->callback()->release();
BaseTest *t = app->getCurrentTest();
if(t != nullptr)
{
t->nextCallback(nullptr);
}
} );
wait(1);
BaseTest* firstTest = app->getCurrentTest();
if(firstTest == nullptr)
BaseTest * curTest = app->getCurrentTest();
if(curTest == nullptr)
{
continue;
break;
}
std::string t1("");
t1 += firstTest->subtitle();
send(fd, t1.c_str(), strlen(t1.c_str()),0);
std::string title("");
title += curTest->subtitle();
send(fd, title.c_str(), strlen(title.c_str()),0);
send(fd, "\n",1,0);
wait(2);
//printf("rtti:%s", typeid(firstTest).name());
while(1)
if(t1 == title)
{
//currentTest->nextCallback(nullptr);
sched->performFunctionInCocosThread( [&](){
BaseTest *t = app->getCurrentTest();
if(t != nullptr)
{
t->nextCallback(nullptr);
}
} );
wait(1);
BaseTest * curTest = app->getCurrentTest();
if(curTest == nullptr)
{
break;
}
std::string title("");
title += curTest->subtitle();
send(fd, title.c_str(), strlen(title.c_str()),0);
send(fd, "\n",1,0);
wait(2);
if(t1 == title)
{
break;
}
break;
}
}
}
return;
}
for(int i = 0; i < g_testCount; i++)
{
if(args == g_aTestNames[i].test_name)
{
// create the test scene and run it
auto scene = g_aTestNames[i].callback();
if (scene)
{
std::string msg("autotest: running test:");
msg += args;
send(fd, msg.c_str(), strlen(msg.c_str()),0);
send(fd, "\n",1,0);
currentController = &g_aTestNames[i];
std::string msg("autotest: running test:");
msg += args;
send(fd, msg.c_str(), strlen(msg.c_str()),0);
send(fd, "\n",1,0);
currentController = &g_aTestNames[i];
sched->performFunctionInCocosThread( [&](){
currentController->callback()->runThisTest();
currentController->callback()->release();
} );
return;
}
sched->performFunctionInCocosThread( [&](){
auto scene = currentController->callback();
if(scene)
{
scene->runThisTest();
scene->release();
}
} );
return;
}
}

@ -1 +1 @@
Subproject commit 47edbdcc88c99b4c0125bf70b847f03ad26f463d
Subproject commit 9aeab189f0a734423e7418c5ea11771c1db09592

View File

@ -11,6 +11,8 @@ import sys
import json
import time
import socket
import smtplib
from email.mime.text import MIMEText
# default console_param.
console_param = '[console run]'
@ -69,7 +71,7 @@ cocos_console_dir = 'tools/cocos2d-console/bin/'
# now cocos2d-console suport different run on Platforms, e.g: only run android on win
runSupport = {
'darwin' : {'mac':1,'ios':1,'android':1},
'darwin' : {'mac':1,'ios':1,'android':0},
'win' : {'mac':0,'ios':0,'android':1},
'linux' : {'mac':0,'ios':0,'android':1}
}
@ -86,6 +88,7 @@ print 'current platform is:', curPlat
# delete project.(will use different system command to delete.just mac now.)
def clean_project():
print 'delete older project.'
for proj in project_types:
cmd = 'rm -rf '+proj+PROJ_SUFFIX
os.system(cmd)
@ -122,6 +125,9 @@ def addConsoleListenOnTCP(name):
else:
print 'file is not exist.'
# console result, for record result
console_result = 'the result of cocos-console-test is:\n\r'
# get current android devices count.
def getAndroidDevices():
cmd = 'adb devices'
@ -144,6 +150,7 @@ PORT = 5678
def close_proj(proj, phone):
print 'close running project'
# connect socket
strClose = 'close ' + proj + ' on ' + phone
if IP_PHONE.has_key(phone):
soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
print proj, phone, IP_PHONE[phone]
@ -152,13 +159,25 @@ def close_proj(proj, phone):
cmd = 'director end\r\n'
print 'cmd close:', cmd
soc.send(cmd)
time.sleep(2)
strClose = strClose + ' success.'
except Exception, e:
print 'socket is not connect.'
strClose = strClose + ' failed.' + ' socket is not connect.'
else:
strClose = strClose + ' failed.' + ' no ' +phone+ ' type.'
time.sleep(2)
return strClose
# appendToResult
def appendToResult(content):
global console_result
console_result = console_result + content
# excute cocos command
def cocos_project(level):
print 'will excute cocos_command: ', COCOS_CMD[level]
print 'will excute cocos_command: ', COCOS_CMD[level], level
appendToResult('will excute ' + COCOS_CMD[level] + ' command:'+"\n\r\t")
for proj in project_types:
print 'proj: ', proj
if level == ENUM_PARAM.new:
@ -169,11 +188,13 @@ def cocos_project(level):
time.sleep(12)
addConsoleListenOnTCP(proj)
print 'create project',proj,' is:', not info_create
appendToResult(' '+cmd +': ' + str(not info_create) + ".\n\r\t")
else:
for phone in phonePlats:
print 'platform is: ', phone
cmd = './'+cocos_console_dir+'cocos '+COCOS_CMD[level]+' -s '+proj+PROJ_SUFFIX+' -p '+phone
print 'cmd:',cmd
info_cmd = ''
if level == ENUM_PARAM.compile:
if runSupport[curPlat][phone]:
info_cmd = os.system(cmd)
@ -187,11 +208,13 @@ def cocos_project(level):
print 'info '+COCOS_CMD[level]+':', not info_cmd
if level == ENUM_PARAM.run:
time.sleep(20)
close_proj(proj, phone)
strClose = close_proj(proj, phone)
appendToResult(' '+strClose+"\n\r\t")
appendToResult(' '+cmd +': ' + str(not info_cmd) + ".\n\r\t")
# build and run according to params of provided.(lv_ignore: e.g:ignore new)
def build_run(lv_ignore):
print 'will build and run'
print 'will build and run, in function build_run'
for level in LEVEL_COCOS:
print 'level:', level, cocos_param, LEVEL_COCOS[level]
if cocos_param >= LEVEL_COCOS[level] and level > lv_ignore:
@ -203,6 +226,7 @@ def build_run(lv_ignore):
ANDROID_SIMULATOR_NAME = 'console-test'
# start android simulator if no android devices connected.
def start_android_simulator():
print 'in function start_android_simulator.'
if getAndroidDevices() > 0:
print 'already connected android device.'
return
@ -212,11 +236,65 @@ def start_android_simulator():
info_start = subprocess.Popen(cmd_start, stdin=subprocess.PIPE, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print 'start an android simulator:', not info_start
# send email
EMAIL_KEYS={
0:'EMAIL_HOST',
1:'EMAIL_USER',
2:'EMAIL_PWD',
3:'EMAIL_POSTFIX',
4:'EMAIL_LIST',
5:'NEED_SEND_EMAIL'
}
OBJ_EMAIL_INFO = {}
print 'will get env info.'
for key in EMAIL_KEYS:
if os.environ.has_key(EMAIL_KEYS[key]):
OBJ_EMAIL_INFO[EMAIL_KEYS[key]] = os.environ[EMAIL_KEYS[key]]
if key == 4:
# string to list by ' ', for separate users.
OBJ_EMAIL_INFO[EMAIL_KEYS[4]] = OBJ_EMAIL_INFO[EMAIL_KEYS[4]].split(' ')
print 'will send email.', OBJ_EMAIL_INFO
def send_mail(to_list,sub,title,content):
mail_user = OBJ_EMAIL_INFO[ EMAIL_KEYS[1] ]
mail_postfix = OBJ_EMAIL_INFO[ EMAIL_KEYS[3] ]
mail_host = OBJ_EMAIL_INFO[ EMAIL_KEYS[0] ]
mail_pass = OBJ_EMAIL_INFO[ EMAIL_KEYS[2] ]
me = mail_user+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content,_subtype='plain',_charset='gb2312')
msg['Subject'] = sub
msg['From'] = me
msg['To'] = " ".join(to_list)
print 'to users:', msg['To']
msg['Content'] = 'test'
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me, to_list, str(msg))
print 'info:', me, to_list, str(msg)
s.close()
appendToResult( 'send email true:' + str(msg) )
return True
except Exception, e:
appendToResult( 'send email false:' + str(e) )
print str(e)
return False
def sendEmail(msg):
send_mail(OBJ_EMAIL_INFO[EMAIL_KEYS[4]], "cocos-console-test result", 'for error.', msg)
def main():
print 'in main:'
start_android_simulator()
# start_android_simulator()
print 'will build_run:'
build_run(-1)
print 'end build run.'
print 'will send email:'
if OBJ_EMAIL_INFO[ EMAIL_KEYS[5] ]:
sendEmail(console_result)
print 'console_result:', console_result
# -------------- main --------------
if __name__ == '__main__':

View File

@ -85,7 +85,7 @@ def main():
git_fetch_pr = "git fetch origin pull/" + str(pr_num) + "/merge"
ret = os.system(git_fetch_pr)
if(ret != 0):
return(1)
return(2)
#checkout
git_checkout = "git checkout -b " + "pull" + str(pr_num) + " FETCH_HEAD"
@ -99,7 +99,7 @@ def main():
git_update_submodule = "git submodule update --init --force"
ret = os.system(git_update_submodule)
if(ret != 0):
return(1)
return(2)
# Generate binding glue codes
if(branch == 'develop'):