fixed bugs

This commit is contained in:
Nomango 2018-03-01 19:28:22 +08:00
parent d0c167360e
commit 6331a4c111
12 changed files with 58 additions and 36 deletions

View File

@ -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)
{

View File

@ -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()

View File

@ -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();

View File

@ -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;

View File

@ -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;

View File

@ -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<float>(width);
m_fHeight = static_cast<float>(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<float>(width);
m_fHeight = static_cast<float>(height);
m_bTransformNeeded = true;
}
void e2d::Node::setSize(Size size)
{
this->setSize(size.width, size.height);
}
void e2d::Node::setShape(Shape * pShape)
{
// 删除旧的形状

View File

@ -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())
);

View File

@ -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;
// 删除相关资源

View File

@ -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)

View File

@ -17,7 +17,7 @@ public:
const String & sTitle, /* 窗口标题 */
UINT32 nWidth, /* 窗口宽度 */
UINT32 nHeight, /* 窗口高度 */
LPCTSTR pIconID = L"", /* ´°¿Úͼ±ê */
LPCTSTR pIconID = nullptr, /* ´°¿Úͼ±ê */
const String & sAppname = L"" /* AppName */
);

View File

@ -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 &);

View File

@ -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);