mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-04 10:32:39 +08:00
@@ -58,7 +58,7 @@ bool ComponentContainer::add(Component *com)
|
||||
CCASSERT(com->getOwner() == nullptr, "Component already added. It can't be added again");
|
||||
do
|
||||
{
|
||||
if (com == nullptr || com->getOwner() == nullptr) {
|
||||
if (com == nullptr || com->getOwner() != nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -730,6 +730,8 @@ Node* Node::getChildByTag(int tag) const
|
||||
Node* Node::getChildByName(const std::string& name) const
|
||||
{
|
||||
CCASSERT(!name.empty(), "Invalid name");
|
||||
if (name.empty())
|
||||
return nullptr;
|
||||
|
||||
std::hash<std::string> h;
|
||||
size_t hash = h(name);
|
||||
|
||||
@@ -167,7 +167,10 @@ void ScriptEngineManager::destroyInstance()
|
||||
|
||||
bool ScriptEngineManager::sendActionEventToJS(Action* actionObject, int eventType, void* param)
|
||||
{
|
||||
auto scriptEngine = getInstance()->getScriptEngine();
|
||||
if (ShareInstance == nullptr)
|
||||
return false;
|
||||
|
||||
auto scriptEngine = ShareInstance->getScriptEngine();
|
||||
|
||||
ActionObjectScriptData data(actionObject,(int*)&eventType, param);
|
||||
ScriptEvent scriptEvent(kScriptActionEvent,(void*)&data);
|
||||
@@ -179,7 +182,10 @@ bool ScriptEngineManager::sendActionEventToJS(Action* actionObject, int eventTyp
|
||||
|
||||
bool ScriptEngineManager::sendNodeEventToJS(Node* node, int action)
|
||||
{
|
||||
auto scriptEngine = getInstance()->getScriptEngine();
|
||||
if (ShareInstance == nullptr)
|
||||
return false;
|
||||
|
||||
auto scriptEngine = ShareInstance->getScriptEngine();
|
||||
|
||||
if (scriptEngine->isCalledFromScript())
|
||||
{
|
||||
@@ -199,7 +205,10 @@ bool ScriptEngineManager::sendNodeEventToJS(Node* node, int action)
|
||||
|
||||
bool ScriptEngineManager::sendNodeEventToJSExtended(Node* node, int action)
|
||||
{
|
||||
auto scriptEngine = getInstance()->getScriptEngine();
|
||||
if (ShareInstance == nullptr)
|
||||
return false;
|
||||
|
||||
auto scriptEngine = ShareInstance->getScriptEngine();
|
||||
|
||||
if (!scriptEngine->isCalledFromScript())
|
||||
{
|
||||
@@ -214,7 +223,10 @@ bool ScriptEngineManager::sendNodeEventToJSExtended(Node* node, int action)
|
||||
|
||||
void ScriptEngineManager::sendNodeEventToLua(Node* node, int action)
|
||||
{
|
||||
auto scriptEngine = getInstance()->getScriptEngine();
|
||||
if (ShareInstance == nullptr)
|
||||
return;
|
||||
|
||||
auto scriptEngine = ShareInstance->getScriptEngine();
|
||||
|
||||
BasicScriptData data(node,(void*)&action);
|
||||
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
|
||||
|
||||
@@ -221,10 +221,10 @@ Vec2 GLView::getVisibleOrigin() const
|
||||
|
||||
void GLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||
{
|
||||
glViewport((float)(x * _scaleX + _viewPortRect.origin.x),
|
||||
(float)(y * _scaleY + _viewPortRect.origin.y),
|
||||
(float)(w * _scaleX),
|
||||
(float)(h * _scaleY));
|
||||
glViewport((GLint)(x * _scaleX + _viewPortRect.origin.x),
|
||||
(GLint)(y * _scaleY + _viewPortRect.origin.y),
|
||||
(GLsizei)(w * _scaleX),
|
||||
(GLsizei)(h * _scaleY));
|
||||
}
|
||||
|
||||
void GLView::setScissorInPoints(float x , float y , float w , float h)
|
||||
|
||||
@@ -57,9 +57,12 @@ public:
|
||||
|
||||
virtual ValueVector getValueVectorFromFile(const std::string& filename) override;
|
||||
void setBundle(NSBundle* bundle);
|
||||
private:
|
||||
|
||||
virtual bool isDirectoryExistInternal(const std::string& dirPath) const override;
|
||||
virtual bool isFileExistInternal(const std::string& filePath) const override;
|
||||
virtual bool removeDirectory(const std::string& dirPath) override;
|
||||
private:
|
||||
bool isFileExistInternal(const std::string& filePath,bool& isDirectory) const;
|
||||
|
||||
NSBundle* getBundle() const;
|
||||
NSBundle* _bundle;
|
||||
|
||||
@@ -359,46 +359,43 @@ std::string FileUtilsApple::getWritablePath() const
|
||||
return strRet;
|
||||
}
|
||||
|
||||
bool FileUtilsApple::isFileExistInternal(const std::string& filePath) const
|
||||
bool FileUtilsApple::isDirectoryExistInternal(const std::string &dirPath) const
|
||||
{
|
||||
bool isDirectory = false;
|
||||
auto isExist = isFileExistInternal(dirPath, isDirectory);
|
||||
return isExist && isDirectory;
|
||||
}
|
||||
|
||||
bool FileUtilsApple::isFileExistInternal(const std::string &filePath) const
|
||||
{
|
||||
bool isDirectory = false;
|
||||
auto isExist = isFileExistInternal(filePath, isDirectory);
|
||||
return isExist && !isDirectory;
|
||||
}
|
||||
|
||||
bool FileUtilsApple::isFileExistInternal(const std::string& filePath, bool& isDirectory) const
|
||||
{
|
||||
if (filePath.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = false;
|
||||
|
||||
|
||||
isDirectory = false;
|
||||
|
||||
NSString* path = nil;
|
||||
if (filePath[0] != '/')
|
||||
{
|
||||
std::string path;
|
||||
std::string file;
|
||||
size_t pos = filePath.find_last_of("/");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
file = filePath.substr(pos+1);
|
||||
path = filePath.substr(0, pos+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
file = filePath;
|
||||
}
|
||||
|
||||
NSString* fullpath = [getBundle() pathForResource:[NSString stringWithUTF8String:file.c_str()]
|
||||
ofType:nil
|
||||
inDirectory:[NSString stringWithUTF8String:path.c_str()]];
|
||||
if (fullpath != nil) {
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
path = [[getBundle() resourcePath] stringByAppendingPathComponent:
|
||||
[NSString stringWithUTF8String:filePath.c_str()]];
|
||||
else
|
||||
{
|
||||
// Search path is an absolute path.
|
||||
if ([s_fileManager fileExistsAtPath:[NSString stringWithUTF8String:filePath.c_str()]]) {
|
||||
ret = true;
|
||||
}
|
||||
path = [NSString stringWithUTF8String:filePath.c_str()];
|
||||
|
||||
BOOL isDir = NO;
|
||||
// Search path is an absolute path.
|
||||
if ([s_fileManager fileExistsAtPath:path isDirectory:&isDir]) {
|
||||
if (isDir)
|
||||
isDirectory = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
|
||||
|
||||
@@ -774,13 +774,10 @@ const Color3B& Layout::getBackGroundColor()const
|
||||
void Layout::setBackGroundColor(const Color3B &startColor, const Color3B &endColor)
|
||||
{
|
||||
_gStartColor = startColor;
|
||||
if (_gradientRender)
|
||||
{
|
||||
_gradientRender->setStartColor(startColor);
|
||||
}
|
||||
_gEndColor = endColor;
|
||||
if (_gradientRender)
|
||||
{
|
||||
_gradientRender->setStartColor(startColor);
|
||||
_gradientRender->setEndColor(endColor);
|
||||
}
|
||||
}
|
||||
@@ -899,8 +896,6 @@ void Layout::setLayoutType(Type type)
|
||||
_doLayoutDirty = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Layout::Type Layout::getLayoutType() const
|
||||
{
|
||||
return _layoutType;
|
||||
@@ -950,7 +945,6 @@ LayoutManager* Layout::createLayoutManager()
|
||||
|
||||
void Layout::doLayout()
|
||||
{
|
||||
|
||||
if (!_doLayoutDirty)
|
||||
{
|
||||
return;
|
||||
@@ -1158,7 +1152,7 @@ int Layout::findFirstFocusEnabledWidgetIndex()
|
||||
}
|
||||
index++;
|
||||
}
|
||||
CCASSERT(0, "invalide operation");
|
||||
CCASSERT(0, "invalid operation");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1257,8 +1251,6 @@ int Layout::findFarthestChildWidgetIndex(FocusDirection direction, cocos2d::ui::
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Widget* Layout::findFocusEnabledChildWidgetByIndex(ssize_t index)
|
||||
{
|
||||
|
||||
@@ -1472,7 +1464,7 @@ Widget* Layout::getPreviousFocusedWidget(FocusDirection direction, Widget *curre
|
||||
}
|
||||
else
|
||||
{
|
||||
//handling the disabled widget, there is no actual focus lose or get, so we don't need any envet
|
||||
//handling the disabled widget, there is no actual focus lose or get, so we don't need any event
|
||||
return this->getPreviousFocusedWidget(direction, nextWidget);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ NS_CC_BEGIN
|
||||
|
||||
namespace ui {
|
||||
LayoutComponent::LayoutComponent()
|
||||
:_horizontalEdge(HorizontalEdge::None)
|
||||
: _horizontalEdge(HorizontalEdge::None)
|
||||
, _verticalEdge(VerticalEdge::None)
|
||||
, _leftMargin(0)
|
||||
, _rightMargin(0)
|
||||
@@ -75,23 +75,6 @@ namespace ui {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool LayoutComponent::init()
|
||||
{
|
||||
bool ret = true;
|
||||
do
|
||||
{
|
||||
if (!Component::init())
|
||||
{
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
|
||||
//put layout component initalized code here
|
||||
|
||||
} while (0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Node* LayoutComponent::getOwnerParent()
|
||||
{
|
||||
if (_owner) {
|
||||
@@ -188,7 +171,7 @@ namespace ui {
|
||||
else
|
||||
{
|
||||
_positionPercentX = 0;
|
||||
if (_usingPositionPercentX)
|
||||
if (_usingPositionPercentX || _horizontalEdge == HorizontalEdge::Center)
|
||||
ownerPoint.x = 0;
|
||||
}
|
||||
|
||||
@@ -197,7 +180,7 @@ namespace ui {
|
||||
else
|
||||
{
|
||||
_positionPercentY = 0;
|
||||
if (_usingPositionPercentY)
|
||||
if (_usingPositionPercentY || _verticalEdge == VerticalEdge::Center)
|
||||
ownerPoint.y = 0;
|
||||
}
|
||||
|
||||
@@ -231,11 +214,14 @@ namespace ui {
|
||||
{
|
||||
_positionPercentX = percentMargin;
|
||||
|
||||
Node* parent = this->getOwnerParent();
|
||||
if (parent != nullptr)
|
||||
if (_usingPositionPercentX || _horizontalEdge == HorizontalEdge::Center)
|
||||
{
|
||||
_owner->setPositionX(parent->getContentSize().width * _positionPercentX);
|
||||
this->refreshHorizontalMargin();
|
||||
Node* parent = this->getOwnerParent();
|
||||
if (parent != nullptr)
|
||||
{
|
||||
_owner->setPositionX(parent->getContentSize().width * _positionPercentX);
|
||||
this->refreshHorizontalMargin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,11 +246,14 @@ namespace ui {
|
||||
{
|
||||
_positionPercentY = percentMargin;
|
||||
|
||||
Node* parent = this->getOwnerParent();
|
||||
if (parent != nullptr)
|
||||
if (_usingPositionPercentY || _verticalEdge == VerticalEdge::Center)
|
||||
{
|
||||
_owner->setPositionY(parent->getContentSize().height * _positionPercentY);
|
||||
this->refreshVerticalMargin();
|
||||
Node* parent = this->getOwnerParent();
|
||||
if (parent != nullptr)
|
||||
{
|
||||
_owner->setPositionY(parent->getContentSize().height * _positionPercentY);
|
||||
this->refreshVerticalMargin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,24 +268,6 @@ namespace ui {
|
||||
{
|
||||
_usingPositionPercentX = false;
|
||||
}
|
||||
|
||||
Node* parent = this->getOwnerParent();
|
||||
if (parent != nullptr)
|
||||
{
|
||||
Point ownerPoint = _owner->getPosition();
|
||||
const Size& parentSize = parent->getContentSize();
|
||||
if (parentSize.width != 0)
|
||||
_positionPercentX = ownerPoint.x / parentSize.width;
|
||||
else
|
||||
{
|
||||
_positionPercentX = 0;
|
||||
ownerPoint.x = 0;
|
||||
if (_usingPositionPercentX)
|
||||
_owner->setPosition(ownerPoint);
|
||||
}
|
||||
|
||||
this->refreshHorizontalMargin();
|
||||
}
|
||||
}
|
||||
|
||||
LayoutComponent::VerticalEdge LayoutComponent::getVerticalEdge()const
|
||||
@@ -310,24 +281,6 @@ namespace ui {
|
||||
{
|
||||
_usingPositionPercentY = false;
|
||||
}
|
||||
|
||||
Node* parent = this->getOwnerParent();
|
||||
if (parent != nullptr)
|
||||
{
|
||||
Point ownerPoint = _owner->getPosition();
|
||||
const Size& parentSize = parent->getContentSize();
|
||||
if (parentSize.height != 0)
|
||||
_positionPercentY = ownerPoint.y / parentSize.height;
|
||||
else
|
||||
{
|
||||
_positionPercentY = 0;
|
||||
ownerPoint.y = 0;
|
||||
if (_usingPositionPercentY)
|
||||
_owner->setPosition(ownerPoint);
|
||||
}
|
||||
|
||||
this->refreshVerticalMargin();
|
||||
}
|
||||
}
|
||||
|
||||
float LayoutComponent::getLeftMargin()const
|
||||
@@ -384,7 +337,7 @@ namespace ui {
|
||||
else
|
||||
{
|
||||
_percentWidth = 0;
|
||||
if (_usingPercentWidth)
|
||||
if (_usingPercentWidth || (this->_horizontalEdge != HorizontalEdge::Center && this->_usingStretchWidth))
|
||||
ownerSize.width = 0;
|
||||
}
|
||||
|
||||
@@ -393,7 +346,7 @@ namespace ui {
|
||||
else
|
||||
{
|
||||
_percentHeight = 0;
|
||||
if (_usingPercentHeight)
|
||||
if (_usingPercentHeight || (this->_verticalEdge != VerticalEdge::Center && this->_usingStretchHeight))
|
||||
ownerSize.height = 0;
|
||||
}
|
||||
|
||||
@@ -455,14 +408,17 @@ namespace ui {
|
||||
{
|
||||
_percentWidth = percentWidth;
|
||||
|
||||
Node* parent = this->getOwnerParent();
|
||||
if (parent != nullptr)
|
||||
if (_usingPercentWidth)
|
||||
{
|
||||
Size ownerSize = _owner->getContentSize();
|
||||
ownerSize.width = parent->getContentSize().width * _percentWidth;
|
||||
_owner->setContentSize(ownerSize);
|
||||
Node* parent = this->getOwnerParent();
|
||||
if (parent != nullptr)
|
||||
{
|
||||
Size ownerSize = _owner->getContentSize();
|
||||
ownerSize.width = parent->getContentSize().width * _percentWidth;
|
||||
_owner->setContentSize(ownerSize);
|
||||
|
||||
this->refreshHorizontalMargin();
|
||||
this->refreshHorizontalMargin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,14 +471,17 @@ namespace ui {
|
||||
{
|
||||
_percentHeight = percentHeight;
|
||||
|
||||
Node* parent = this->getOwnerParent();
|
||||
if (parent != nullptr)
|
||||
if (_usingPercentHeight)
|
||||
{
|
||||
Size ownerSize = _owner->getContentSize();
|
||||
ownerSize.height = parent->getContentSize().height * _percentHeight;
|
||||
_owner->setContentSize(ownerSize);
|
||||
Node* parent = this->getOwnerParent();
|
||||
if (parent != nullptr)
|
||||
{
|
||||
Size ownerSize = _owner->getContentSize();
|
||||
ownerSize.height = parent->getContentSize().height * _percentHeight;
|
||||
_owner->setContentSize(ownerSize);
|
||||
|
||||
this->refreshVerticalMargin();
|
||||
this->refreshVerticalMargin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,6 @@ namespace ui {
|
||||
*/
|
||||
~LayoutComponent();
|
||||
|
||||
virtual bool init()override;
|
||||
|
||||
/**
|
||||
* Create a LayoutComponent instance with default settings.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user