diff --git a/core/Base/Window.cpp b/core/Base/Window.cpp index 3d3f89fd..b74fc247 100644 --- a/core/Base/Window.cpp +++ b/core/Base/Window.cpp @@ -109,7 +109,7 @@ bool e2d::Window::__init(const String & sTitle, UINT32 nWidth, UINT32 nHeight, L bool e2d::Window::__initMutex(const String & sTitle) { // 创建进程互斥体 - HANDLE m_hMutex = ::CreateMutex(NULL, TRUE, sTitle); + HANDLE m_hMutex = ::CreateMutex(NULL, TRUE, L"Easy2DApp-" + sTitle); if (m_hMutex == nullptr) { diff --git a/core/Common/Scene.cpp b/core/Common/Scene.cpp index ed9a32b3..aea79382 100644 --- a/core/Common/Scene.cpp +++ b/core/Common/Scene.cpp @@ -15,8 +15,6 @@ e2d::Scene::Scene() m_pRoot->retain(); m_pRoot->_onEnter(); m_pRoot->_setParentScene(this); - m_pRoot->setPivot(0, 0); - m_pRoot->_setSize(Window::getWidth(), Window::getHeight()); } e2d::Scene::~Scene() diff --git a/core/Common/String.cpp b/core/Common/String.cpp index 05e58a05..76d0c8aa 100644 --- a/core/Common/String.cpp +++ b/core/Common/String.cpp @@ -282,11 +282,6 @@ e2d::String::operator const char*() const return ::ConvertWide2Ansi(m_str.c_str()).c_str(); } -e2d::String::operator bool() const -{ - return getLength() != 0; -} - bool e2d::String::isEmpty() const { return m_str.empty(); diff --git a/core/Node/Button.cpp b/core/Node/Button.cpp index 5d29b8e8..b94257b5 100644 --- a/core/Node/Button.cpp +++ b/core/Node/Button.cpp @@ -96,7 +96,7 @@ void e2d::Button::setNormal(Node * normal) if (normal) { this->addChild(normal); - this->_setSize(normal->getWidth(), normal->getHeight()); + this->setSize(normal->getWidth(), normal->getHeight()); } m_pNormal = normal; diff --git a/core/Node/ButtonToggle.cpp b/core/Node/ButtonToggle.cpp index 973e72cb..5c2c2ca9 100644 --- a/core/Node/ButtonToggle.cpp +++ b/core/Node/ButtonToggle.cpp @@ -122,7 +122,7 @@ void e2d::ButtonToggle::setNormal(Node * normal) if (normal) { this->addChild(normal); - this->_setSize(normal->getWidth(), normal->getHeight()); + this->setSize(normal->getWidth(), normal->getHeight()); } m_pNormalOn = normal; diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index 53732b20..e8234748 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -431,16 +431,6 @@ void e2d::Node::movePos(const Vector & v) this->movePos(v.x, v.y); } -void e2d::Node::_setSize(double width, double height) -{ - if (m_fWidth == width && m_fHeight == height) - return; - - m_fWidth = static_cast(width); - m_fHeight = static_cast(height); - m_bTransformNeeded = true; -} - void e2d::Node::setScaleX(double scaleX) { this->setScale(scaleX, m_fScaleY); @@ -525,6 +515,31 @@ void e2d::Node::setPivot(double pivotX, double pivotY) m_bTransformNeeded = true; } +void e2d::Node::setWidth(double width) +{ + this->setSize(width, m_fHeight); +} + +void e2d::Node::setHeight(double height) +{ + this->setSize(m_fWidth, height); +} + +void e2d::Node::setSize(double width, double height) +{ + if (m_fWidth == width && m_fHeight == height) + return; + + m_fWidth = static_cast(width); + m_fHeight = static_cast(height); + m_bTransformNeeded = true; +} + +void e2d::Node::setSize(Size size) +{ + this->setSize(size.width, size.height); +} + void e2d::Node::setShape(Shape * pShape) { // 删除旧的形状 diff --git a/core/Node/Sprite.cpp b/core/Node/Sprite.cpp index 8a8c999e..90ba8e08 100644 --- a/core/Node/Sprite.cpp +++ b/core/Node/Sprite.cpp @@ -38,7 +38,7 @@ void e2d::Sprite::loadFrom(Image * image) m_pImage = image; m_pImage->retain(); - Node::_setSize(m_pImage->getWidth(), m_pImage->getHeight()); + Node::setSize(m_pImage->getWidth(), m_pImage->getHeight()); } } @@ -50,7 +50,7 @@ void e2d::Sprite::loadFrom(const String & imageFileName) void e2d::Sprite::clip(double x, double y, double width, double height) { m_pImage->clip(x, y, width, height); - Node::_setSize( + Node::setSize( min(max(width, 0), m_pImage->getSourceWidth() - m_pImage->getClipX()), min(max(height, 0), m_pImage->getSourceHeight() - m_pImage->getClipY()) ); diff --git a/core/Node/Text.cpp b/core/Node/Text.cpp index 216766aa..45408ff4 100644 --- a/core/Node/Text.cpp +++ b/core/Node/Text.cpp @@ -120,7 +120,7 @@ void e2d::Text::_initTextLayout() // 未设置字体或空字符串时,文本宽高为 0 if (!m_pFont || m_sText.isEmpty()) { - this->_setSize(0, 0); + this->setSize(0, 0); m_fWordWrappingWidth = 0; return; } @@ -153,7 +153,7 @@ void e2d::Text::_initTextLayout() DWRITE_TEXT_METRICS metrics; pDWriteTextLayout->GetMetrics(&metrics); - this->_setSize(metrics.widthIncludingTrailingWhitespace, metrics.height); + this->setSize(metrics.widthIncludingTrailingWhitespace, metrics.height); m_fWordWrappingWidth = metrics.widthIncludingTrailingWhitespace; // 删除相关资源 diff --git a/core/Tool/Data.cpp b/core/Tool/Data.cpp index 4a9bc103..32b5f34e 100644 --- a/core/Tool/Data.cpp +++ b/core/Tool/Data.cpp @@ -13,8 +13,8 @@ void e2d::Data::saveDouble(const String & key, double value) void e2d::Data::saveBool(const String & key, bool value) { - int nValue = value ? 1 : 0; - ::WritePrivateProfileString(L"Default", key, String::toString(nValue), File::getDefaultSavePath()); + const wchar_t* sValue = value ? L"1" : L"0"; + ::WritePrivateProfileString(L"Default", key, sValue, File::getDefaultSavePath()); } void e2d::Data::saveString(const String & key, const String & value) diff --git a/core/ebase.h b/core/ebase.h index a8601138..c3743763 100644 --- a/core/ebase.h +++ b/core/ebase.h @@ -17,7 +17,7 @@ public: const String & sTitle, /* 窗口标题 */ UINT32 nWidth, /* 窗口宽度 */ UINT32 nHeight, /* 窗口高度 */ - LPCTSTR pIconID = L"", /* 窗口图标 */ + LPCTSTR pIconID = nullptr, /* 窗口图标 */ const String & sAppname = L"" /* AppName */ ); diff --git a/core/ecommon.h b/core/ecommon.h index 0344b648..aaffedbd 100644 --- a/core/ecommon.h +++ b/core/ecommon.h @@ -22,7 +22,7 @@ struct Point Point operator * (double const & value); Point operator / (double const & value); - operator Size() const; + operator e2d::Size() const; /* 成员变量 */ double x; // X 坐标 @@ -41,7 +41,7 @@ struct Size Size operator * (double const & value); Size operator / (double const & value); - operator Point() const; + operator e2d::Point() const; /* 成员变量 */ double width; // 宽度 @@ -168,7 +168,6 @@ public: operator const wchar_t* () const; operator wchar_t* () const; - operator bool () const; friend std::wostream& operator<< (std::wostream &, String &); friend std::wistream& operator>> (std::wistream &, String &); diff --git a/core/enodes.h b/core/enodes.h index 08a13305..518c19c5 100644 --- a/core/enodes.h +++ b/core/enodes.h @@ -289,6 +289,27 @@ public: double pivotY ); + // 修改节点宽度 + void setWidth( + double width + ); + + // 修改节点高度 + void setHeight( + double height + ); + + // 修改节点大小 + void setSize( + double width, + double height + ); + + // 修改节点大小 + void setSize( + Size size + ); + // 设置节点形状 virtual void setShape( Shape * pShape @@ -365,12 +386,6 @@ protected: // 更新所有子节点透明度 void _updateChildrenOpacity(); - // 修改节点大小 - void _setSize( - double width, - double height - ); - // 更新节点二维矩阵 static void _updateTransform(Node * node);