From 4a62b2a5bf9ed52184e8131c25b9893a476dd543 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Wed, 9 May 2018 00:34:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E8=B0=83=E6=95=B4=EF=BC=9B?= =?UTF-8?q?=E5=8E=BB=E9=99=A4Transition=E6=9E=84=E9=80=A0=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Action/Action.cpp | 10 +- core/Action/ActionGradual.cpp | 2 +- core/Action/Animation.cpp | 4 +- core/Action/Delay.cpp | 2 +- core/Collider/Collider.cpp | 50 ++-- core/Collider/ColliderCircle.cpp | 30 +- core/Collider/ColliderEllipse.cpp | 32 +-- core/Collider/ColliderRect.cpp | 26 +- core/Common/Color.cpp | 24 +- core/Common/Image.cpp | 68 ++--- core/Common/Object.cpp | 8 +- core/Common/Scene.cpp | 40 ++- core/Common/String.cpp | 8 +- core/Manager/ColliderManager.cpp | 8 +- core/Manager/SceneManager.cpp | 13 +- core/Node/Button.cpp | 164 +++++------ core/Node/ButtonToggle.cpp | 176 +++++------- core/Node/Menu.cpp | 28 +- core/Node/Node.cpp | 396 +++++++++++++------------- core/Node/Shape/Circle.cpp | 12 +- core/Node/Shape/Ellipse.cpp | 18 +- core/Node/Shape/Rect.cpp | 6 +- core/Node/Shape/RoundRect.cpp | 34 +-- core/Node/Shape/Shape.cpp | 36 +-- core/Node/Sprite.cpp | 66 ++--- core/Node/Text.cpp | 214 +++++++------- core/Tool/Music.cpp | 2 +- core/Transition/Transition.cpp | 130 ++++++++- core/Transition/TransitionBase.cpp | 135 --------- core/Transition/TransitionEmerge.cpp | 12 +- core/Transition/TransitionFade.cpp | 44 +-- core/Transition/TransitionMove.cpp | 52 ++-- core/e2daction.h | 2 +- core/e2dcollider.h | 18 +- core/e2dcommon.h | 45 +-- core/e2dmanager.h | 6 +- core/e2dnode.h | 98 +++---- core/e2dshape.h | 18 +- core/e2dtransition.h | 77 ++--- project/vs2017/Easy2D.vcxproj | 1 - project/vs2017/Easy2D.vcxproj.filters | 9 +- 41 files changed, 1022 insertions(+), 1102 deletions(-) delete mode 100644 core/Transition/TransitionBase.cpp diff --git a/core/Action/Action.cpp b/core/Action/Action.cpp index 1476d72e..0692d64e 100644 --- a/core/Action/Action.cpp +++ b/core/Action/Action.cpp @@ -6,7 +6,7 @@ e2d::Action::Action() , _done(false) , _initialized(false) , _target(nullptr) - , _fLast(0) + , _last(0) { ActionManager::__add(this); } @@ -35,7 +35,7 @@ bool e2d::Action::isRunning() void e2d::Action::resume() { _running = true; - _fLast = Time::getTotalTime(); + _last = Time::getTotalTime(); } void e2d::Action::pause() @@ -78,7 +78,7 @@ void e2d::Action::_init() { _initialized = true; // 记录当前时间 - _fLast = Time::getTotalTime(); + _last = Time::getTotalTime(); } void e2d::Action::_update() @@ -93,10 +93,10 @@ void e2d::Action::reset() { _initialized = false; _done = false; - _fLast = Time::getTotalTime(); + _last = Time::getTotalTime(); } void e2d::Action::_resetTime() { - _fLast = Time::getTotalTime(); + _last = Time::getTotalTime(); } diff --git a/core/Action/ActionGradual.cpp b/core/Action/ActionGradual.cpp index b0c2ab09..8d159805 100644 --- a/core/Action/ActionGradual.cpp +++ b/core/Action/ActionGradual.cpp @@ -22,7 +22,7 @@ void e2d::ActionGradual::_update() return; } // 计算动画进度 - _delta = min((Time::getTotalTime() - _fLast) / _duration, 1); + _delta = min((Time::getTotalTime() - _last) / _duration, 1); // 判断动作是否结束 if (_delta >= 1) { diff --git a/core/Action/Animation.cpp b/core/Action/Animation.cpp index 7685e84e..7b198ad6 100644 --- a/core/Action/Animation.cpp +++ b/core/Action/Animation.cpp @@ -87,10 +87,10 @@ void e2d::Animation::_update() } // 判断时间间隔是否足够 - while ((Time::getTotalTime() - _fLast) >= _interval) + while ((Time::getTotalTime() - _last) >= _interval) { // 重新记录时间 - _fLast += _interval; + _last += _interval; // 加载关键帧 static_cast(_target)->open(_frames[_frameIndex]); _frameIndex++; diff --git a/core/Action/Delay.cpp b/core/Action/Delay.cpp index 3fb5c307..30ed120b 100644 --- a/core/Action/Delay.cpp +++ b/core/Action/Delay.cpp @@ -19,7 +19,7 @@ void e2d::Delay::_update() { Action::_update(); // 判断时间间隔是否足够 - if ((Time::getTotalTime() - _fLast) >= _delay) + if ((Time::getTotalTime() - _last) >= _delay) { this->stop(); } diff --git a/core/Collider/Collider.cpp b/core/Collider/Collider.cpp index f79650f4..74a5c0c2 100644 --- a/core/Collider/Collider.cpp +++ b/core/Collider/Collider.cpp @@ -3,73 +3,73 @@ #include "..\e2dnode.h" e2d::Collider::Collider() - : _bIsVisiable(true) - , _nColor(Color::RED, 0.7f) - , _pParentNode(nullptr) - , _pTransformedGeometry(nullptr) - , _bEnable(true) - , _bAutoResize(true) + : _visiable(true) + , _color(Color::RED, 0.7f) + , _parentNode(nullptr) + , _transformed(nullptr) + , _enable(true) + , _autoResize(true) { } e2d::Collider::~Collider() { - SafeReleaseInterface(&_pTransformedGeometry); + SafeReleaseInterface(&_transformed); } e2d::Node * e2d::Collider::getParentNode() const { - return _pParentNode; + return _parentNode; } e2d::Color e2d::Collider::getColor() const { - return _nColor; + return _color; } void e2d::Collider::setEnable(bool enable) { - _bEnable = enable; + _enable = enable; } void e2d::Collider::setVisiable(bool bVisiable) { - _bIsVisiable = bVisiable; + _visiable = bVisiable; } void e2d::Collider::setColor(Color color) { - _nColor = color; + _color = color; } void e2d::Collider::setAutoResize(bool enable) { - _bAutoResize = enable; + _autoResize = enable; } void e2d::Collider::_render() { - if (_pTransformedGeometry && _bEnable) + if (_transformed && _enable) { // 获取纯色画刷 ID2D1SolidColorBrush * pBrush = Renderer::getSolidColorBrush(); // 设置画刷颜色和透明度 - pBrush->SetColor(_nColor.toColorF()); + pBrush->SetColor(_color.toColorF()); // 绘制几何碰撞体 - Renderer::getRenderTarget()->DrawGeometry(_pTransformedGeometry, pBrush); + Renderer::getRenderTarget()->DrawGeometry(_transformed, pBrush); } } e2d::Relation e2d::Collider::getRelationWith(Collider * pCollider) const { - if (_pTransformedGeometry && pCollider->_pTransformedGeometry) + if (_transformed && pCollider->_transformed) { - if (_bEnable && pCollider->_bEnable) + if (_enable && pCollider->_enable) { D2D1_GEOMETRY_RELATION relation; - _pTransformedGeometry->CompareWithGeometry( - pCollider->_pTransformedGeometry, + _transformed->CompareWithGeometry( + pCollider->_transformed, D2D1::Matrix3x2F::Identity(), &relation ); @@ -82,21 +82,21 @@ e2d::Relation e2d::Collider::getRelationWith(Collider * pCollider) const void e2d::Collider::_transform() { - if (_pParentNode && _bEnable) + if (_parentNode && _enable) { - if (_bAutoResize) + if (_autoResize) { this->_resize(); } // 释放原碰撞体 - SafeReleaseInterface(&_pTransformedGeometry); + SafeReleaseInterface(&_transformed); // 根据父节点转换几何图形 Renderer::getID2D1Factory()->CreateTransformedGeometry( getD2dGeometry(), - _pParentNode->_MatriFinal, - &_pTransformedGeometry + _parentNode->_finalMatri, + &_transformed ); ColliderManager::__updateCollider(this); diff --git a/core/Collider/ColliderCircle.cpp b/core/Collider/ColliderCircle.cpp index 3c685c18..8209b1c7 100644 --- a/core/Collider/ColliderCircle.cpp +++ b/core/Collider/ColliderCircle.cpp @@ -2,18 +2,18 @@ #include "..\e2dnode.h" e2d::ColliderCircle::ColliderCircle() - : _pD2dCircle(nullptr) + : _d2dCircle(nullptr) { } e2d::ColliderCircle::ColliderCircle(Point center, double radius) - : _pD2dCircle(nullptr) + : _d2dCircle(nullptr) { this->setCircle(center, radius); } e2d::ColliderCircle::ColliderCircle(Node * node) - : _pD2dCircle(nullptr) + : _d2dCircle(nullptr) { double minSide = min(node->getRealWidth(), node->getRealHeight()); this->setCircle( @@ -27,33 +27,33 @@ e2d::ColliderCircle::ColliderCircle(Node * node) e2d::ColliderCircle::~ColliderCircle() { - SafeReleaseInterface(&_pD2dCircle); + SafeReleaseInterface(&_d2dCircle); } void e2d::ColliderCircle::setCircle(Point center, double radius) { - SafeReleaseInterface(&_pD2dCircle); + SafeReleaseInterface(&_d2dCircle); Renderer::getID2D1Factory()->CreateEllipseGeometry( D2D1::Ellipse( D2D1::Point2F( - static_cast(center.x), - static_cast(center.y)), - static_cast(radius), - static_cast(radius)), - &_pD2dCircle + float(center.x), + float(center.y)), + float(radius), + float(radius)), + &_d2dCircle ); } void e2d::ColliderCircle::_resize() { - if (_pParentNode && _bEnable) + if (_parentNode && _enable) { - double minSide = min(_pParentNode->getRealWidth(), _pParentNode->getRealHeight()); + double minSide = min(_parentNode->getRealWidth(), _parentNode->getRealHeight()); this->setCircle( Point( - _pParentNode->getRealWidth() / 2, - _pParentNode->getRealHeight() / 2 + _parentNode->getRealWidth() / 2, + _parentNode->getRealHeight() / 2 ), minSide / 2 ); @@ -62,5 +62,5 @@ void e2d::ColliderCircle::_resize() ID2D1EllipseGeometry * e2d::ColliderCircle::getD2dGeometry() const { - return _pD2dCircle; + return _d2dCircle; } diff --git a/core/Collider/ColliderEllipse.cpp b/core/Collider/ColliderEllipse.cpp index e2a4b3ca..ef9b4663 100644 --- a/core/Collider/ColliderEllipse.cpp +++ b/core/Collider/ColliderEllipse.cpp @@ -2,18 +2,18 @@ #include "..\e2dnode.h" e2d::ColliderEllipse::ColliderEllipse() - : _pD2dEllipse(nullptr) + : _d2dEllipse(nullptr) { } e2d::ColliderEllipse::ColliderEllipse(Point center, double radiusX, double radiusY) - : _pD2dEllipse(nullptr) + : _d2dEllipse(nullptr) { this->setEllipse(center, radiusX, radiusY); } e2d::ColliderEllipse::ColliderEllipse(Node * node) - : _pD2dEllipse(nullptr) + : _d2dEllipse(nullptr) { this->setEllipse( Point( @@ -27,40 +27,40 @@ e2d::ColliderEllipse::ColliderEllipse(Node * node) e2d::ColliderEllipse::~ColliderEllipse() { - SafeReleaseInterface(&_pD2dEllipse); + SafeReleaseInterface(&_d2dEllipse); } void e2d::ColliderEllipse::setEllipse(Point center, double radiusX, double radiusY) { - SafeReleaseInterface(&_pD2dEllipse); + SafeReleaseInterface(&_d2dEllipse); Renderer::getID2D1Factory()->CreateEllipseGeometry( D2D1::Ellipse( D2D1::Point2F( - static_cast(center.x), - static_cast(center.y)), - static_cast(radiusX), - static_cast(radiusY)), - &_pD2dEllipse + float(center.x), + float(center.y)), + float(radiusX), + float(radiusY)), + &_d2dEllipse ); } void e2d::ColliderEllipse::_resize() { - if (_pParentNode && _bEnable) + if (_parentNode && _enable) { this->setEllipse( Point( - _pParentNode->getWidth() / 2, - _pParentNode->getHeight() / 2 + _parentNode->getWidth() / 2, + _parentNode->getHeight() / 2 ), - _pParentNode->getWidth() / 2, - _pParentNode->getHeight() / 2 + _parentNode->getWidth() / 2, + _parentNode->getHeight() / 2 ); } } ID2D1EllipseGeometry * e2d::ColliderEllipse::getD2dGeometry() const { - return _pD2dEllipse; + return _d2dEllipse; } diff --git a/core/Collider/ColliderRect.cpp b/core/Collider/ColliderRect.cpp index a0ea0144..1bd0d341 100644 --- a/core/Collider/ColliderRect.cpp +++ b/core/Collider/ColliderRect.cpp @@ -2,50 +2,50 @@ #include "..\e2dnode.h" e2d::ColliderRect::ColliderRect() - : _pD2dRectangle(nullptr) + : _d2dRectangle(nullptr) { } e2d::ColliderRect::ColliderRect(double x, double y, double width, double height) - : _pD2dRectangle(nullptr) + : _d2dRectangle(nullptr) { this->setRect(x, y, x + width, y + height); } e2d::ColliderRect::ColliderRect(Node * node) - : _pD2dRectangle(nullptr) + : _d2dRectangle(nullptr) { this->setRect(0, 0, node->getRealWidth(), node->getRealHeight()); } e2d::ColliderRect::~ColliderRect() { - SafeReleaseInterface(&_pD2dRectangle); + SafeReleaseInterface(&_d2dRectangle); } void e2d::ColliderRect::setRect(double left, double top, double right, double bottom) { - SafeReleaseInterface(&_pD2dRectangle); + SafeReleaseInterface(&_d2dRectangle); Renderer::getID2D1Factory()->CreateRectangleGeometry( D2D1::RectF( - static_cast(left), - static_cast(top), - static_cast(right), - static_cast(bottom)), - &_pD2dRectangle + float(left), + float(top), + float(right), + float(bottom)), + &_d2dRectangle ); } void e2d::ColliderRect::_resize() { - if (_pParentNode && _bEnable) + if (_parentNode && _enable) { - this->setRect( 0, 0, _pParentNode->getRealWidth(), _pParentNode->getRealHeight()); + this->setRect( 0, 0, _parentNode->getRealWidth(), _parentNode->getRealHeight()); } } ID2D1RectangleGeometry * e2d::ColliderRect::getD2dGeometry() const { - return _pD2dRectangle; + return _d2dRectangle; } diff --git a/core/Common/Color.cpp b/core/Common/Color.cpp index 5f97968f..9f675d2c 100644 --- a/core/Common/Color.cpp +++ b/core/Common/Color.cpp @@ -17,18 +17,18 @@ e2d::Color::Color() } e2d::Color::Color(double r, double g, double b) - : r(static_cast(r)) - , g(static_cast(g)) - , b(static_cast(b)) - , a(static_cast(1)) + : r(float(r)) + , g(float(g)) + , b(float(b)) + , a(float(1)) { } e2d::Color::Color(double r, double g, double b, double alpha) - : r(static_cast(r)) - , g(static_cast(g)) - , b(static_cast(b)) - , a(static_cast(alpha)) + : r(float(r)) + , g(float(g)) + , b(float(b)) + , a(float(alpha)) { } @@ -44,10 +44,10 @@ e2d::Color::Color(UINT32 rgb, double alpha) void e2d::Color::_init(UINT32 rgb, double alpha) { - r = static_cast((rgb & sc_redMask) >> sc_redShift) / 255.f; - g = static_cast((rgb & sc_greenMask) >> sc_greenShift) / 255.f; - b = static_cast((rgb & sc_blueMask) >> sc_blueShift) / 255.f; - a = static_cast(alpha); + r = float((rgb & sc_redMask) >> sc_redShift) / 255.f; + g = float((rgb & sc_greenMask) >> sc_greenShift) / 255.f; + b = float((rgb & sc_blueMask) >> sc_blueShift) / 255.f; + a = float(alpha); } D2D1_COLOR_F e2d::Color::toColorF() const diff --git a/core/Common/Image.cpp b/core/Common/Image.cpp index 76ab339e..9bae2b60 100644 --- a/core/Common/Image.cpp +++ b/core/Common/Image.cpp @@ -6,35 +6,35 @@ static std::map s_mBitmapsFromResource; e2d::Image::Image() - : _pBitmap(nullptr) - , _fSourceCropX(0) - , _fSourceCropY(0) - , _fSourceCropWidth(0) - , _fSourceCropHeight(0) + : _bitmap(nullptr) + , _cropX(0) + , _cropY(0) + , _cropWidth(0) + , _cropHeight(0) { } e2d::Image::Image(const String& filePath) - : _pBitmap(nullptr) + : _bitmap(nullptr) { this->open(filePath); } e2d::Image::Image(int resNameId, const String& resType) - : _pBitmap(nullptr) + : _bitmap(nullptr) { this->open(resNameId, resType); } e2d::Image::Image(const String& filePath, double cropX, double cropY, double cropWidth, double cropHeight) - : _pBitmap(nullptr) + : _bitmap(nullptr) { this->open(filePath); this->crop(cropX, cropY, cropWidth, cropHeight); } e2d::Image::Image(int resNameId, const String& resType, double cropX, double cropY, double cropWidth, double cropHeight) - : _pBitmap(nullptr) + : _bitmap(nullptr) { this->open(resNameId, resType); this->crop(cropX, cropY, cropWidth, cropHeight); @@ -57,10 +57,10 @@ bool e2d::Image::open(const String& filePath) return false; } - _pBitmap = s_mBitmapsFromFile.at(filePath.getHashCode()); - _fSourceCropX = _fSourceCropY = 0; - _fSourceCropWidth = _pBitmap->GetSize().width; - _fSourceCropHeight = _pBitmap->GetSize().height; + _bitmap = s_mBitmapsFromFile.at(filePath.getHashCode()); + _cropX = _cropY = 0; + _cropWidth = _bitmap->GetSize().width; + _cropHeight = _bitmap->GetSize().height; return true; } @@ -72,44 +72,44 @@ bool e2d::Image::open(int resNameId, const String& resType) return false; } - _pBitmap = s_mBitmapsFromResource.at(resNameId); - _fSourceCropX = _fSourceCropY = 0; - _fSourceCropWidth = _pBitmap->GetSize().width; - _fSourceCropHeight = _pBitmap->GetSize().height; + _bitmap = s_mBitmapsFromResource.at(resNameId); + _cropX = _cropY = 0; + _cropWidth = _bitmap->GetSize().width; + _cropHeight = _bitmap->GetSize().height; return true; } void e2d::Image::crop(double x, double y, double width, double height) { - if (_pBitmap) + if (_bitmap) { - _fSourceCropX = min(max(x, 0), this->getSourceWidth()); - _fSourceCropY = min(max(y, 0), this->getSourceHeight()); - _fSourceCropWidth = min(max(width, 0), this->getSourceWidth() - _fSourceCropX); - _fSourceCropHeight = min(max(height, 0), this->getSourceHeight() - _fSourceCropY); + _cropX = min(max(x, 0), this->getSourceWidth()); + _cropY = min(max(y, 0), this->getSourceHeight()); + _cropWidth = min(max(width, 0), this->getSourceWidth() - _cropX); + _cropHeight = min(max(height, 0), this->getSourceHeight() - _cropY); } } double e2d::Image::getWidth() const { - return _fSourceCropWidth; + return _cropWidth; } double e2d::Image::getHeight() const { - return _fSourceCropHeight; + return _cropHeight; } e2d::Size e2d::Image::getSize() const { - return Size(_fSourceCropWidth, _fSourceCropHeight); + return Size(_cropWidth, _cropHeight); } double e2d::Image::getSourceWidth() const { - if (_pBitmap) + if (_bitmap) { - return _pBitmap->GetSize().width; + return _bitmap->GetSize().width; } else { @@ -119,9 +119,9 @@ double e2d::Image::getSourceWidth() const double e2d::Image::getSourceHeight() const { - if (_pBitmap) + if (_bitmap) { - return _pBitmap->GetSize().height; + return _bitmap->GetSize().height; } else { @@ -131,7 +131,7 @@ double e2d::Image::getSourceHeight() const e2d::Size e2d::Image::getSourceSize() const { - if (_pBitmap) + if (_bitmap) { return Size(getSourceWidth(), getSourceHeight()); } @@ -143,17 +143,17 @@ e2d::Size e2d::Image::getSourceSize() const double e2d::Image::getCropX() const { - return _fSourceCropX; + return _cropX; } double e2d::Image::getCropY() const { - return _fSourceCropY; + return _cropY; } e2d::Point e2d::Image::getCropPos() const { - return Point(_fSourceCropX, _fSourceCropY); + return Point(_cropX, _cropY); } bool e2d::Image::preload(const String& fileName) @@ -376,5 +376,5 @@ void e2d::Image::clearCache() ID2D1Bitmap * e2d::Image::getBitmap() { - return _pBitmap; + return _bitmap; } diff --git a/core/Common/Object.cpp b/core/Common/Object.cpp index 6aa47f93..70b140da 100644 --- a/core/Common/Object.cpp +++ b/core/Common/Object.cpp @@ -2,7 +2,7 @@ #include "..\e2dmanager.h" e2d::Object::Object() - : _nRefCount(0) + : _refCount(0) { ObjectManager::__add(this); } @@ -14,18 +14,18 @@ e2d::Object::~Object() // 引用计数加一 void e2d::Object::retain() { - _nRefCount++; + _refCount++; } // 引用计数减一 void e2d::Object::release() { - _nRefCount--; + _refCount--; // 通知对象管理池刷新 ObjectManager::flush(); } int e2d::Object::getRefCount() const { - return _nRefCount; + return _refCount; } diff --git a/core/Common/Scene.cpp b/core/Common/Scene.cpp index 9609d0bd..8057f332 100644 --- a/core/Common/Scene.cpp +++ b/core/Common/Scene.cpp @@ -3,14 +3,12 @@ #include "..\e2dmanager.h" e2d::Scene::Scene() - : _bWillSave(true) - , _bAutoUpdate(true) - , _bSortNeeded(false) - , _bColliderVisiable(false) - , _pRoot(new Node()) + : _autoUpdate(true) + , _colliderVisiable(false) + , _root(new Node()) { - _pRoot->retain(); - _pRoot->_setParentScene(this); + _root->retain(); + _root->_setParentScene(this); } e2d::Scene::~Scene() @@ -19,36 +17,36 @@ e2d::Scene::~Scene() void e2d::Scene::_render() { - _pRoot->_render(); + _root->_render(); - if (_bColliderVisiable) + if (_colliderVisiable) { // 恢复矩阵转换 Renderer::getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); // 绘制所有几何图形 - _pRoot->_drawCollider(); + _root->_drawCollider(); } } void e2d::Scene::_update() { // 执行 onUpdate 函数 - if (_bAutoUpdate) + if (_autoUpdate) { this->onUpdate(); } // 更新根节点 - _pRoot->_update(); + _root->_update(); } void e2d::Scene::setAutoUpdate(bool bAutoUpdate) { - _bAutoUpdate = bAutoUpdate; + _autoUpdate = bAutoUpdate; } void e2d::Scene::add(Node * child, int order /* = 0 */) { - _pRoot->addChild(child, order); + _root->addChild(child, order); } #ifdef HIGHER_THAN_VS2012 @@ -63,35 +61,35 @@ void e2d::Scene::add(const std::initializer_list& vNodes, int order) bool e2d::Scene::remove(Node * child) { - return _pRoot->removeChild(child); + return _root->removeChild(child); } std::vector e2d::Scene::get(const String& name) const { - return _pRoot->getChildren(name); + return _root->getChildren(name); } e2d::Node * e2d::Scene::getOne(const String& name) const { - return _pRoot->getChild(name); + return _root->getChild(name); } std::vector e2d::Scene::getAll() const { - return _pRoot->getAllChildren(); + return _root->getAllChildren(); } e2d::Node * e2d::Scene::getRoot() const { - return _pRoot; + return _root; } void e2d::Scene::showCollider(bool visiable) { - _bColliderVisiable = visiable; + _colliderVisiable = visiable; } void e2d::Scene::onDestroy() { - SafeRelease(&_pRoot); + SafeRelease(&_root); } diff --git a/core/Common/String.cpp b/core/Common/String.cpp index 3b9370e6..06772062 100644 --- a/core/Common/String.cpp +++ b/core/Common/String.cpp @@ -191,7 +191,7 @@ bool e2d::String::operator!=(const e2d::String &str) wchar_t &e2d::String::operator[](int index) { - return _str[static_cast(index)]; + return _str[size_t(index)]; } e2d::String e2d::String::operator+(const wchar_t *str) @@ -440,7 +440,7 @@ e2d::String e2d::String::subtract(int offset, int count) const void e2d::String::insert(const String & str, int pos) { - _str.insert(static_cast(pos), str._str); + _str.insert(size_t(pos), str._str); } void e2d::String::replace(const String & from, const String & to) @@ -458,13 +458,13 @@ void e2d::String::replace(const String & from, const String & to) void e2d::String::erase(int offset, int count) { - _str.erase(static_cast(offset), static_cast(count)); + _str.erase(size_t(offset), size_t(count)); } int e2d::String::find(const String & str, int offset) const { size_t index; - if ((index = _str.find(str._str, static_cast(offset))) == std::wstring::npos) + if ((index = _str.find(str._str, size_t(offset))) == std::wstring::npos) { return -1; } diff --git a/core/Manager/ColliderManager.cpp b/core/Manager/ColliderManager.cpp index 433c0a4e..f9fa83fe 100644 --- a/core/Manager/ColliderManager.cpp +++ b/core/Manager/ColliderManager.cpp @@ -81,7 +81,7 @@ void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider) if (!s_bCollisionEnable) return; - Node* pActiveNode = pActiveCollider->_pParentNode; + Node* pActiveNode = pActiveCollider->_parentNode; if (pActiveNode) { // 获取节点所在场景 @@ -96,7 +96,7 @@ void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider) continue; // 获取被碰撞节点 - Node* pPassiveNode = pPassiveCollider->_pParentNode; + Node* pPassiveNode = pPassiveCollider->_parentNode; // 判断两节点是否处于同一场景中 if (pPassiveNode && pPassiveNode->getParentScene() == pCurrentScene) @@ -105,7 +105,7 @@ void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider) auto IsCollideWith = [](Node * active, Node * passive) -> bool { unsigned int hash = passive->getHashName(); - for (auto collider : active->_vColliders) + for (auto collider : active->_colliders) if (collider == hash) return true; return false; @@ -228,7 +228,7 @@ void e2d::ColliderManager::__addCollider(Collider * pCollider) { if (pCollider) { - if (pCollider->_pParentNode) + if (pCollider->_parentNode) { WARN_IF(true, "ColliderManager::__add Failed! The shape is already added."); return; diff --git a/core/Manager/SceneManager.cpp b/core/Manager/SceneManager.cpp index 917f1b68..a5b5fead 100644 --- a/core/Manager/SceneManager.cpp +++ b/core/Manager/SceneManager.cpp @@ -2,12 +2,13 @@ #include "..\e2dbase.h" #include "..\e2dtransition.h" +static bool s_bSaveCurrScene = true; static e2d::Scene * s_pCurrScene = nullptr; static e2d::Scene * s_pNextScene = nullptr; -static e2d::TransitionBase * s_pTransition = nullptr; +static e2d::Transition * s_pTransition = nullptr; static std::stack s_SceneStack; -void e2d::SceneManager::enter(Scene * scene, TransitionBase * transition /* = nullptr */, bool saveCurrentScene /* = true */) +void e2d::SceneManager::enter(Scene * scene, Transition * transition /* = nullptr */, bool saveCurrentScene /* = true */) { ASSERT(scene, "Next scene NULL pointer exception!"); scene->retain(); @@ -31,11 +32,11 @@ void e2d::SceneManager::enter(Scene * scene, TransitionBase * transition /* = nu if (s_pCurrScene) { - s_pCurrScene->_bWillSave = saveCurrentScene; + s_bSaveCurrScene = saveCurrentScene; } } -void e2d::SceneManager::back(TransitionBase * transition /* = nullptr */) +void e2d::SceneManager::back(Transition * transition /* = nullptr */) { // 栈为空时,调用返回场景函数失败 WARN_IF(s_SceneStack.size() == 0, "Scene stack is empty!"); @@ -48,7 +49,7 @@ void e2d::SceneManager::back(TransitionBase * transition /* = nullptr */) // 返回上一场景时,不保存当前场景 if (s_pCurrScene) { - s_pCurrScene->_bWillSave = false; + s_bSaveCurrScene = false; } // 设置切换场景动画 @@ -120,7 +121,7 @@ void e2d::SceneManager::__update() s_pCurrScene->onExit(); // 若要保存当前场景,把它放入栈中 - if (s_pCurrScene->_bWillSave) + if (s_bSaveCurrScene) { s_SceneStack.push(s_pCurrScene); } diff --git a/core/Node/Button.cpp b/core/Node/Button.cpp index a91dce5a..5e788e22 100644 --- a/core/Node/Button.cpp +++ b/core/Node/Button.cpp @@ -6,25 +6,25 @@ e2d::Button::Button() : _func(nullptr) - , _eBtnState(ButtonState::NORMAL) - , _bEnable(true) - , _bIsSelected(false) - , _pNormal(nullptr) - , _pMouseover(nullptr) - , _pSelected(nullptr) - , _pDisabled(nullptr) + , _state(ButtonState::NORMAL) + , _enable(true) + , _isSelected(false) + , _normal(nullptr) + , _mouseover(nullptr) + , _selected(nullptr) + , _disabled(nullptr) { } e2d::Button::Button(Node * normal, const Function& func) : _func(nullptr) - , _eBtnState(ButtonState::NORMAL) - , _bEnable(true) - , _bIsSelected(false) - , _pNormal(nullptr) - , _pMouseover(nullptr) - , _pSelected(nullptr) - , _pDisabled(nullptr) + , _state(ButtonState::NORMAL) + , _enable(true) + , _isSelected(false) + , _normal(nullptr) + , _mouseover(nullptr) + , _selected(nullptr) + , _disabled(nullptr) { this->setNormal(normal); this->setClickFunc(func); @@ -32,13 +32,13 @@ e2d::Button::Button(Node * normal, const Function& func) e2d::Button::Button(Node * normal, Node * selected, const Function& func) : _func(nullptr) - , _eBtnState(ButtonState::NORMAL) - , _bEnable(true) - , _bIsSelected(false) - , _pNormal(nullptr) - , _pMouseover(nullptr) - , _pSelected(nullptr) - , _pDisabled(nullptr) + , _state(ButtonState::NORMAL) + , _enable(true) + , _isSelected(false) + , _normal(nullptr) + , _mouseover(nullptr) + , _selected(nullptr) + , _disabled(nullptr) { this->setNormal(normal); this->setSelected(selected); @@ -47,13 +47,13 @@ e2d::Button::Button(Node * normal, Node * selected, const Function& func) e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Function& func) : _func(nullptr) - , _eBtnState(ButtonState::NORMAL) - , _bEnable(true) - , _bIsSelected(false) - , _pNormal(nullptr) - , _pMouseover(nullptr) - , _pSelected(nullptr) - , _pDisabled(nullptr) + , _state(ButtonState::NORMAL) + , _enable(true) + , _isSelected(false) + , _normal(nullptr) + , _mouseover(nullptr) + , _selected(nullptr) + , _disabled(nullptr) { this->setNormal(normal); this->setMouseOver(mouseover); @@ -63,13 +63,13 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Func e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Function& func) : _func(nullptr) - , _eBtnState(ButtonState::NORMAL) - , _bEnable(true) - , _bIsSelected(false) - , _pNormal(nullptr) - , _pMouseover(nullptr) - , _pSelected(nullptr) - , _pDisabled(nullptr) + , _state(ButtonState::NORMAL) + , _enable(true) + , _isSelected(false) + , _normal(nullptr) + , _mouseover(nullptr) + , _selected(nullptr) + , _disabled(nullptr) { this->setNormal(normal); this->setMouseOver(mouseover); @@ -80,17 +80,17 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * dis bool e2d::Button::isEnable() const { - return _bEnable; + return _enable; } void e2d::Button::setNormal(Node * normal) { - if (normal != _pNormal) + if (normal != _normal) { // 移除旧的 - if (_pNormal) + if (_normal) { - this->removeChild(_pNormal); + this->removeChild(_normal); } // 添加新的 if (normal) @@ -98,7 +98,7 @@ void e2d::Button::setNormal(Node * normal) this->addChild(normal); this->setSize(normal->getWidth(), normal->getHeight()); } - _pNormal = normal; + _normal = normal; _updateVisiable(); } @@ -106,73 +106,73 @@ void e2d::Button::setNormal(Node * normal) void e2d::Button::setMouseOver(Node * mouseover) { - if (mouseover != _pNormal) + if (mouseover != _normal) { // 移除旧的 - if (_pMouseover) + if (_mouseover) { - this->removeChild(_pMouseover); + this->removeChild(_mouseover); } // 添加新的 if (mouseover) { this->addChild(mouseover); } - _pMouseover = mouseover; + _mouseover = mouseover; _updateVisiable(); } } void e2d::Button::setSelected(Node * selected) { - if (selected != _pNormal) + if (selected != _normal) { // 移除旧的 - if (_pSelected) + if (_selected) { - this->removeChild(_pSelected); + this->removeChild(_selected); } // 添加新的 if (selected) { this->addChild(selected); } - _pSelected = selected; + _selected = selected; _updateVisiable(); } } void e2d::Button::setDisabled(Node * disabled) { - if (disabled != _pNormal) + if (disabled != _normal) { // 移除旧的 - if (_pDisabled) + if (_disabled) { - this->removeChild(_pDisabled); + this->removeChild(_disabled); } // 添加新的 if (disabled) { this->addChild(disabled); } - _pDisabled = disabled; + _disabled = disabled; _updateVisiable(); } } void e2d::Button::setEnable(bool enable) { - if (_bEnable != enable) + if (_enable != enable) { - _bEnable = enable; + _enable = enable; _updateVisiable(); } } void e2d::Button::setClickFunc(const Function& func) { - WARN_IF(_pNormal == nullptr, "Button cannot work without anything to show. Please set its normal displayed."); + WARN_IF(_normal == nullptr, "Button cannot work without anything to show. Please set its normal displayed."); _func = func; } @@ -182,40 +182,40 @@ void e2d::Button::onFixedUpdate() if (SceneManager::isTransitioning()) return; - if (_bEnable && _bVisiable && _pNormal) + if (_enable && _visiable && _normal) { if (Input::isMouseLButtonRelease()) { // 鼠标左键抬起时,判断鼠标坐标是否在按钮内部 - if (_bIsSelected && - _pNormal->isPointIn(Input::getMousePos())) + if (_isSelected && + _normal->isPointIn(Input::getMousePos())) { _runCallback(); } - // 标记 _bIsSelected 为 false - _bIsSelected = false; + // 标记 _isSelected 为 false + _isSelected = false; } if (Input::isMouseLButtonPress()) { - if (_pNormal->isPointIn(Input::getMousePos())) + if (_normal->isPointIn(Input::getMousePos())) { - // 鼠标左键按下,且位于按钮内时,标记 _bIsSelected 为 true - _bIsSelected = true; + // 鼠标左键按下,且位于按钮内时,标记 _isSelected 为 true + _isSelected = true; return; } } - if (_bIsSelected && Input::isMouseLButtonDown()) + if (_isSelected && Input::isMouseLButtonDown()) { - if (_pNormal->isPointIn(Input::getMousePos())) + if (_normal->isPointIn(Input::getMousePos())) { _setState(ButtonState::SELECTED); Window::setCursor(Cursor::HAND); return; } } - else if (_pNormal->isPointIn(Input::getMousePos())) + else if (_normal->isPointIn(Input::getMousePos())) { _setState(ButtonState::MOUSEOVER); Window::setCursor(Cursor::HAND); @@ -225,7 +225,7 @@ void e2d::Button::onFixedUpdate() _setState(ButtonState::NORMAL); } - if (_bVisiable && !_bEnable && _pNormal && _pNormal->isPointIn(Input::getMousePos())) + if (_visiable && !_enable && _normal && _normal->isPointIn(Input::getMousePos())) { Window::setCursor(Cursor::NO); } @@ -233,44 +233,44 @@ void e2d::Button::onFixedUpdate() void e2d::Button::_setState(ButtonState state) { - if (_eBtnState != state) + if (_state != state) { - _eBtnState = state; + _state = state; _updateVisiable(); } } void e2d::Button::_updateVisiable() { - SAFE_SET(_pNormal, setVisiable, false); - SAFE_SET(_pMouseover, setVisiable, false); - SAFE_SET(_pSelected, setVisiable, false); - SAFE_SET(_pDisabled, setVisiable, false); + SAFE_SET(_normal, setVisiable, false); + SAFE_SET(_mouseover, setVisiable, false); + SAFE_SET(_selected, setVisiable, false); + SAFE_SET(_disabled, setVisiable, false); - if (_bEnable) + if (_enable) { - if (_eBtnState == ButtonState::SELECTED && _pSelected) + if (_state == ButtonState::SELECTED && _selected) { - _pSelected->setVisiable(true); + _selected->setVisiable(true); } - else if (_eBtnState == ButtonState::MOUSEOVER && _pMouseover) + else if (_state == ButtonState::MOUSEOVER && _mouseover) { - _pMouseover->setVisiable(true); + _mouseover->setVisiable(true); } else { - if (_pNormal) _pNormal->setVisiable(true); + if (_normal) _normal->setVisiable(true); } } else { - if (_pDisabled) + if (_disabled) { - _pDisabled->setVisiable(true); + _disabled->setVisiable(true); } else { - if (_pNormal) _pNormal->setVisiable(true); + if (_normal) _normal->setVisiable(true); } } } diff --git a/core/Node/ButtonToggle.cpp b/core/Node/ButtonToggle.cpp index 11cb9638..0afb78d2 100644 --- a/core/Node/ButtonToggle.cpp +++ b/core/Node/ButtonToggle.cpp @@ -2,29 +2,21 @@ e2d::ButtonToggle::ButtonToggle() : Button() - , _bState(true) - , _pNormalOn(nullptr) - , _pMouseoverOn(nullptr) - , _pSelectedOn(nullptr) - , _pDisabledOn(nullptr) - , _pNormalOff(nullptr) - , _pMouseoverOff(nullptr) - , _pSelectedOff(nullptr) - , _pDisabledOff(nullptr) + , _toggle(true) + , _normalOff(nullptr) + , _mouseoverOff(nullptr) + , _selectedOff(nullptr) + , _disabledOff(nullptr) { } e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, const Function& func) : Button() - , _bState(true) - , _pNormalOn(nullptr) - , _pMouseoverOn(nullptr) - , _pSelectedOn(nullptr) - , _pDisabledOn(nullptr) - , _pNormalOff(nullptr) - , _pMouseoverOff(nullptr) - , _pSelectedOff(nullptr) - , _pDisabledOff(nullptr) + , _toggle(true) + , _normalOff(nullptr) + , _mouseoverOff(nullptr) + , _selectedOff(nullptr) + , _disabledOff(nullptr) { this->setNormal(toggleOnNormal); this->setNormalOff(toggleOffNormal); @@ -33,15 +25,11 @@ e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, c e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func) : Button() - , _bState(true) - , _pNormalOn(nullptr) - , _pMouseoverOn(nullptr) - , _pSelectedOn(nullptr) - , _pDisabledOn(nullptr) - , _pNormalOff(nullptr) - , _pMouseoverOff(nullptr) - , _pSelectedOff(nullptr) - , _pDisabledOff(nullptr) + , _toggle(true) + , _normalOff(nullptr) + , _mouseoverOff(nullptr) + , _selectedOff(nullptr) + , _disabledOff(nullptr) { this->setNormal(toggleOnNormal); this->setNormalOff(toggleOffNormal); @@ -52,15 +40,11 @@ e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, N e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func) : Button() - , _bState(true) - , _pNormalOn(nullptr) - , _pMouseoverOn(nullptr) - , _pSelectedOn(nullptr) - , _pDisabledOn(nullptr) - , _pNormalOff(nullptr) - , _pMouseoverOff(nullptr) - , _pSelectedOff(nullptr) - , _pDisabledOff(nullptr) + , _toggle(true) + , _normalOff(nullptr) + , _mouseoverOff(nullptr) + , _selectedOff(nullptr) + , _disabledOff(nullptr) { this->setNormal(toggleOnNormal); this->setNormalOff(toggleOffNormal); @@ -73,15 +57,11 @@ e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, N e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, Node * toggleOnDisabled, Node * toggleOffDisabled, const Function& func) : Button() - , _bState(true) - , _pNormalOn(nullptr) - , _pMouseoverOn(nullptr) - , _pSelectedOn(nullptr) - , _pDisabledOn(nullptr) - , _pNormalOff(nullptr) - , _pMouseoverOff(nullptr) - , _pSelectedOff(nullptr) - , _pDisabledOff(nullptr) + , _toggle(true) + , _normalOff(nullptr) + , _mouseoverOff(nullptr) + , _selectedOff(nullptr) + , _disabledOff(nullptr) { this->setNormal(toggleOnNormal); this->setNormalOff(toggleOffNormal); @@ -96,14 +76,14 @@ e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, N bool e2d::ButtonToggle::getState() const { - return _bState; + return _toggle; } void e2d::ButtonToggle::setState(bool bState) { - if (_bState != bState) + if (_toggle != bState) { - _bState = bState; + _toggle = bState; _updateState(); _updateVisiable(); } @@ -111,12 +91,12 @@ void e2d::ButtonToggle::setState(bool bState) void e2d::ButtonToggle::setNormal(Node * normal) { - if (normal != _pNormalOn) + if (normal != _normal) { // 移除旧的 - if (_pNormalOn) + if (_normal) { - this->removeChild(_pNormalOn); + this->removeChild(_normal); } // 添加新的 if (normal) @@ -124,7 +104,7 @@ void e2d::ButtonToggle::setNormal(Node * normal) this->addChild(normal); this->setSize(normal->getWidth(), normal->getHeight()); } - _pNormalOn = normal; + _normal = normal; _updateState(); _updateVisiable(); @@ -133,19 +113,19 @@ void e2d::ButtonToggle::setNormal(Node * normal) void e2d::ButtonToggle::setMouseOver(Node * mouseover) { - if (mouseover != _pMouseoverOn) + if (mouseover != _mouseover) { // 移除旧的 - if (_pMouseoverOn) + if (_mouseover) { - this->removeChild(_pMouseoverOn); + this->removeChild(_mouseover); } // 添加新的 if (mouseover) { this->addChild(mouseover); } - _pMouseoverOn = mouseover; + _mouseover = mouseover; _updateState(); _updateVisiable(); @@ -154,19 +134,19 @@ void e2d::ButtonToggle::setMouseOver(Node * mouseover) void e2d::ButtonToggle::setSelected(Node * selected) { - if (selected != _pSelectedOn) + if (selected != _selected) { // 移除旧的 - if (_pSelectedOn) + if (_selected) { - this->removeChild(_pSelectedOn); + this->removeChild(_selected); } // 添加新的 if (selected) { this->addChild(selected); } - _pSelectedOn = selected; + _selected = selected; _updateState(); _updateVisiable(); @@ -175,19 +155,19 @@ void e2d::ButtonToggle::setSelected(Node * selected) void e2d::ButtonToggle::setDisabled(Node * disabled) { - if (disabled != _pDisabledOn) + if (disabled != _disabled) { // 移除旧的 - if (_pDisabledOn) + if (_disabled) { - this->removeChild(_pDisabledOn); + this->removeChild(_disabled); } // 添加新的 if (disabled) { this->addChild(disabled); } - _pDisabledOn = disabled; + _disabled = disabled; _updateState(); _updateVisiable(); @@ -196,19 +176,19 @@ void e2d::ButtonToggle::setDisabled(Node * disabled) void e2d::ButtonToggle::setNormalOff(Node * normal) { - if (normal != _pNormalOff) + if (normal != _normalOff) { // 移除旧的 - if (_pNormalOff) + if (_normalOff) { - this->removeChild(_pNormalOff); + this->removeChild(_normalOff); } // 添加新的 if (normal) { this->addChild(normal); } - _pNormalOff = normal; + _normalOff = normal; _updateState(); _updateVisiable(); @@ -217,19 +197,19 @@ void e2d::ButtonToggle::setNormalOff(Node * normal) void e2d::ButtonToggle::setMouseOverOff(Node * mouseover) { - if (mouseover != _pMouseoverOff) + if (mouseover != _mouseoverOff) { // 移除旧的 - if (_pMouseoverOff) + if (_mouseoverOff) { - this->removeChild(_pMouseoverOff); + this->removeChild(_mouseoverOff); } // 添加新的 if (mouseover) { this->addChild(mouseover); } - _pMouseoverOff = mouseover; + _mouseoverOff = mouseover; _updateState(); _updateVisiable(); @@ -238,19 +218,19 @@ void e2d::ButtonToggle::setMouseOverOff(Node * mouseover) void e2d::ButtonToggle::setSelectedOff(Node * selected) { - if (selected != _pSelectedOff) + if (selected != _selectedOff) { // 移除旧的 - if (_pSelectedOff) + if (_selectedOff) { - this->removeChild(_pSelectedOff); + this->removeChild(_selectedOff); } // 添加新的 if (selected) { this->addChild(selected); } - _pSelectedOff = selected; + _selectedOff = selected; _updateState(); _updateVisiable(); @@ -259,19 +239,19 @@ void e2d::ButtonToggle::setSelectedOff(Node * selected) void e2d::ButtonToggle::setDisabledOff(Node * disabled) { - if (disabled != _pDisabledOff) + if (disabled != _disabledOff) { // 移除旧的 - if (_pDisabledOff) + if (_disabledOff) { - this->removeChild(_pDisabledOff); + this->removeChild(_disabledOff); } // 添加新的 if (disabled) { this->addChild(disabled); } - _pDisabledOff = disabled; + _disabledOff = disabled; _updateState(); _updateVisiable(); @@ -280,35 +260,35 @@ void e2d::ButtonToggle::setDisabledOff(Node * disabled) void e2d::ButtonToggle::_updateState() { - if (_bState) + if (_toggle) { - _pNormal = _pNormalOn; - _pMouseover = _pMouseoverOn; - _pSelected = _pSelectedOn; - _pDisabled = _pDisabledOn; + _normal = _normal; + _mouseover = _mouseover; + _selected = _selected; + _disabled = _disabled; - if (_pNormalOff) _pNormalOff->setVisiable(false); - if (_pMouseoverOff) _pMouseoverOff->setVisiable(false); - if (_pSelectedOff) _pSelectedOff->setVisiable(false); - if (_pDisabledOff) _pDisabledOff->setVisiable(false); + if (_normalOff) _normalOff->setVisiable(false); + if (_mouseoverOff) _mouseoverOff->setVisiable(false); + if (_selectedOff) _selectedOff->setVisiable(false); + if (_disabledOff) _disabledOff->setVisiable(false); } else { - _pNormal = _pNormalOff; - _pMouseover = _pMouseoverOff; - _pSelected = _pSelectedOff; - _pDisabled = _pDisabledOff; + _normal = _normalOff; + _mouseover = _mouseoverOff; + _selected = _selectedOff; + _disabled = _disabledOff; - if (_pNormalOn) _pNormalOn->setVisiable(false); - if (_pMouseoverOn) _pMouseoverOn->setVisiable(false); - if (_pSelectedOn) _pSelectedOn->setVisiable(false); - if (_pDisabledOn) _pDisabledOn->setVisiable(false); + if (_normal) _normal->setVisiable(false); + if (_mouseover) _mouseover->setVisiable(false); + if (_selected) _selected->setVisiable(false); + if (_disabled) _disabled->setVisiable(false); } } void e2d::ButtonToggle::_runCallback() { - _bState = !_bState; + _toggle = !_toggle; _updateState(); if (_func) diff --git a/core/Node/Menu.cpp b/core/Node/Menu.cpp index c756ed57..12601484 100644 --- a/core/Node/Menu.cpp +++ b/core/Node/Menu.cpp @@ -1,13 +1,13 @@ #include "..\e2dnode.h" e2d::Menu::Menu() - : _bEnable(true) + : _enable(true) { } #ifdef HIGHER_THAN_VS2012 e2d::Menu::Menu(const std::initializer_list& vButtons) - : _bEnable(true) + : _enable(true) { for (auto button : vButtons) { @@ -18,7 +18,7 @@ e2d::Menu::Menu(const std::initializer_list& vButtons) #else e2d::Menu::Menu(int number, Button * button1, ...) - : _bEnable(true) + : _enable(true) { Button ** ppButton = &button1; @@ -33,21 +33,21 @@ e2d::Menu::Menu(int number, Button * button1, ...) bool e2d::Menu::isEnable() const { - return _bEnable; + return _enable; } size_t e2d::Menu::getButtonCount() const { - return _vButtons.size(); + return _buttons.size(); } void e2d::Menu::setEnable(bool enable) { - if (_bEnable != enable) + if (_enable != enable) { - _bEnable = enable; + _enable = enable; - for (auto button : _vButtons) + for (auto button : _buttons) { button->setEnable(enable); } @@ -59,14 +59,14 @@ void e2d::Menu::addButton(Button * button) if (button) { this->addChild(button); - _vButtons.push_back(button); - button->setEnable(_bEnable); + _buttons.push_back(button); + button->setEnable(_enable); } } bool e2d::Menu::removeButton(Button * button) { - if (_vButtons.empty()) + if (_buttons.empty()) { return false; } @@ -75,14 +75,14 @@ bool e2d::Menu::removeButton(Button * button) if (button) { - size_t size = _vButtons.size(); + size_t size = _buttons.size(); for (size_t i = 0; i < size; i++) { - if (_vButtons[i] == button) + if (_buttons[i] == button) { // 移除按钮前,将它启用 button->setEnable(true); - _vButtons.erase(_vButtons.begin() + i); + _buttons.erase(_buttons.begin() + i); return true; } } diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index 9cc8e1ff..bbb04b6d 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -11,30 +11,30 @@ static bool s_fDefaultColliderEnabled = true; e2d::Node::Node() : _nOrder(0) - , _fPosX(0) - , _fPosY(0) - , _fWidth(0) - , _fHeight(0) - , _fScaleX(1.0f) - , _fScaleY(1.0f) - , _fRotation(0) - , _fSkewAngleX(0) - , _fSkewAngleY(0) - , _fDisplayOpacity(1.0f) - , _fRealOpacity(1.0f) - , _fPivotX(s_fDefaultPiovtX) - , _fPivotY(s_fDefaultPiovtY) - , _MatriInitial(D2D1::Matrix3x2F::Identity()) - , _MatriFinal(D2D1::Matrix3x2F::Identity()) - , _bVisiable(true) - , _pCollider(nullptr) - , _pParent(nullptr) - , _pParentScene(nullptr) - , _nHashName(0) - , _bSortChildrenNeeded(false) - , _bTransformNeeded(false) - , _bAutoUpdate(true) - , _bPositionFixed(false) + , _posX(0) + , _posY(0) + , _width(0) + , _height(0) + , _scaleX(1.0f) + , _scaleY(1.0f) + , _rotation(0) + , _skewAngleX(0) + , _skewAngleY(0) + , _displayOpacity(1.0f) + , _realOpacity(1.0f) + , _pivotX(s_fDefaultPiovtX) + , _pivotY(s_fDefaultPiovtY) + , _initialMatri(D2D1::Matrix3x2F::Identity()) + , _finalMatri(D2D1::Matrix3x2F::Identity()) + , _visiable(true) + , _collider(nullptr) + , _parent(nullptr) + , _parentScene(nullptr) + , _hashName(0) + , _needSort(false) + , _needTransform(false) + , _autoUpdate(true) + , _positionFixed(false) { if (s_fDefaultColliderEnabled) { @@ -49,14 +49,14 @@ e2d::Node::~Node() void e2d::Node::_update() { - if (_bTransformNeeded) + if (_needTransform) { _updateTransform(); } - if (!_vChildren.empty()) + if (!_children.empty()) { - if (_bSortChildrenNeeded) + if (_needSort) { // 子节点排序 auto sortFunc = [](Node * n1, Node * n2) { @@ -64,20 +64,20 @@ void e2d::Node::_update() }; std::sort( - std::begin(_vChildren), - std::end(_vChildren), + std::begin(_children), + std::end(_children), sortFunc ); - _bSortChildrenNeeded = false; + _needSort = false; } // 遍历子节点 - size_t size = _vChildren.size(); + size_t size = _children.size(); size_t i; for (i = 0; i < size; i++) { - auto child = _vChildren[i]; + auto child = _children[i]; // 访问 Order 小于零的节点 if (child->getOrder() < 0) { @@ -89,7 +89,7 @@ void e2d::Node::_update() } } - if (_bAutoUpdate) + if (_autoUpdate) { if (!Game::isPaused()) { @@ -100,11 +100,11 @@ void e2d::Node::_update() // 访问剩余节点 for (; i < size; i++) - _vChildren[i]->_update(); + _children[i]->_update(); } else { - if (_bAutoUpdate) + if (_autoUpdate) { if (!Game::isPaused()) { @@ -117,18 +117,18 @@ void e2d::Node::_update() void e2d::Node::_render() { - if (!_bVisiable) + if (!_visiable) { return; } - if (!_vChildren.empty()) + if (!_children.empty()) { - size_t size = _vChildren.size(); + size_t size = _children.size(); size_t i; for (i = 0; i < size; i++) { - auto child = _vChildren[i]; + auto child = _children[i]; // 访问 Order 小于零的节点 if (child->getOrder() < 0) { @@ -141,18 +141,18 @@ void e2d::Node::_render() } // 转换渲染器的二维矩阵 - Renderer::getRenderTarget()->SetTransform(_MatriFinal); + Renderer::getRenderTarget()->SetTransform(_finalMatri); // 渲染自身 this->onRender(); // 访问剩余节点 for (; i < size; i++) - _vChildren[i]->_render(); + _children[i]->_render(); } else { // 转换渲染器的二维矩阵 - Renderer::getRenderTarget()->SetTransform(_MatriFinal); + Renderer::getRenderTarget()->SetTransform(_finalMatri); // 渲染自身 this->onRender(); } @@ -161,13 +161,13 @@ void e2d::Node::_render() void e2d::Node::_drawCollider() { // 绘制自身的几何碰撞体 - if (_pCollider && _pCollider->_bIsVisiable) + if (_collider && _collider->_visiable) { - _pCollider->_render(); + _collider->_render(); } // 绘制所有子节点的几何碰撞体 - for (auto child : _vChildren) + for (auto child : _children) { child->_drawCollider(); } @@ -176,30 +176,30 @@ void e2d::Node::_drawCollider() void e2d::Node::_updateSelfTransform() { // 计算中心点坐标 - D2D1_POINT_2F pivot = { _fWidth * _fPivotX, _fHeight * _fPivotY }; + D2D1_POINT_2F pivot = { _width * _pivotX, _height * _pivotY }; // 变换 Initial 矩阵,子节点将根据这个矩阵进行变换 - _MatriInitial = D2D1::Matrix3x2F::Scale( - _fScaleX, - _fScaleY, + _initialMatri = D2D1::Matrix3x2F::Scale( + _scaleX, + _scaleY, pivot ) * D2D1::Matrix3x2F::Skew( - _fSkewAngleX, - _fSkewAngleY, + _skewAngleX, + _skewAngleY, pivot ) * D2D1::Matrix3x2F::Rotation( - _fRotation, + _rotation, pivot ) * D2D1::Matrix3x2F::Translation( - _fPosX, - _fPosY + _posX, + _posY ); // 根据自身中心点变换 Final 矩阵 - _MatriFinal = _MatriInitial * D2D1::Matrix3x2F::Translation(-pivot.x, -pivot.y); + _finalMatri = _initialMatri * D2D1::Matrix3x2F::Translation(-pivot.x, -pivot.y); // 和父节点矩阵相乘 - if (!_bPositionFixed && _pParent) + if (!_positionFixed && _parent) { - _MatriInitial = _MatriInitial * _pParent->_MatriInitial; - _MatriFinal = _MatriFinal * _pParent->_MatriInitial; + _initialMatri = _initialMatri * _parent->_initialMatri; + _finalMatri = _finalMatri * _parent->_initialMatri; } } @@ -208,14 +208,14 @@ void e2d::Node::_updateTransform() // 计算自身的转换矩阵 _updateSelfTransform(); // 绑定于自身的碰撞体也进行相应转换 - if (_pCollider) + if (_collider) { - _pCollider->_transform(); + _collider->_transform(); } // 标志已执行过变换 - _bTransformNeeded = false; + _needTransform = false; // 遍历子节点下的所有节点 - for (auto child : this->_vChildren) + for (auto child : this->_children) { child->_updateTransform(); } @@ -223,11 +223,11 @@ void e2d::Node::_updateTransform() void e2d::Node::_updateOpacity() { - if (_pParent) + if (_parent) { - _fDisplayOpacity = _fRealOpacity * _pParent->_fDisplayOpacity; + _displayOpacity = _realOpacity * _parent->_displayOpacity; } - for (auto child : _vChildren) + for (auto child : _children) { child->_updateOpacity(); } @@ -235,7 +235,7 @@ void e2d::Node::_updateOpacity() bool e2d::Node::isVisiable() const { - return _bVisiable; + return _visiable; } e2d::String e2d::Node::getName() const @@ -245,57 +245,57 @@ e2d::String e2d::Node::getName() const unsigned int e2d::Node::getHashName() const { - return _nHashName; + return _hashName; } double e2d::Node::getPosX() const { - return _fPosX; + return _posX; } double e2d::Node::getPosY() const { - return _fPosY; + return _posY; } e2d::Point e2d::Node::getPos() const { - return Point(_fPosX, _fPosY); + return Point(_posX, _posY); } double e2d::Node::getWidth() const { - return _fWidth * _fScaleX; + return _width * _scaleX; } double e2d::Node::getHeight() const { - return _fHeight * _fScaleY; + return _height * _scaleY; } double e2d::Node::getRealWidth() const { - return _fWidth; + return _width; } double e2d::Node::getRealHeight() const { - return _fHeight; + return _height; } e2d::Size e2d::Node::getRealSize() const { - return Size(_fWidth, _fHeight); + return Size(_width, _height); } double e2d::Node::getPivotX() const { - return _fPivotX; + return _pivotX; } double e2d::Node::getPivotY() const { - return _fPivotY; + return _pivotY; } e2d::Size e2d::Node::getSize() const @@ -305,56 +305,56 @@ e2d::Size e2d::Node::getSize() const double e2d::Node::getScaleX() const { - return _fScaleX; + return _scaleX; } double e2d::Node::getScaleY() const { - return _fScaleY; + return _scaleY; } double e2d::Node::getSkewX() const { - return _fSkewAngleX; + return _skewAngleX; } double e2d::Node::getSkewY() const { - return _fSkewAngleY; + return _skewAngleY; } double e2d::Node::getRotation() const { - return _fRotation; + return _rotation; } double e2d::Node::getOpacity() const { - return _fRealOpacity; + return _realOpacity; } e2d::NodeProperty e2d::Node::getProperty() const { NodeProperty prop; - prop.visable = _bVisiable; - prop.posX = _fPosX; - prop.posY = _fPosY; - prop.width = _fWidth; - prop.height = _fHeight; - prop.opacity = _fRealOpacity; - prop.pivotX = _fPivotX; - prop.pivotY = _fPivotY; - prop.scaleX = _fScaleX; - prop.scaleY = _fScaleY; - prop.rotation = _fRotation; - prop.skewAngleX = _fSkewAngleX; - prop.skewAngleY = _fSkewAngleY; + prop.visable = _visiable; + prop.posX = _posX; + prop.posY = _posY; + prop.width = _width; + prop.height = _height; + prop.opacity = _realOpacity; + prop.pivotX = _pivotX; + prop.pivotY = _pivotY; + prop.scaleX = _scaleX; + prop.scaleY = _scaleY; + prop.rotation = _rotation; + prop.skewAngleX = _skewAngleX; + prop.skewAngleY = _skewAngleY; return prop; } e2d::Collider * e2d::Node::getCollider() const { - return _pCollider; + return _collider; } int e2d::Node::getOrder() const @@ -369,12 +369,12 @@ void e2d::Node::setOrder(int order) void e2d::Node::setPosX(double x) { - this->setPos(x, _fPosY); + this->setPos(x, _posY); } void e2d::Node::setPosY(double y) { - this->setPos(_fPosX, y); + this->setPos(_posX, y); } void e2d::Node::setPos(const Point & p) @@ -384,21 +384,21 @@ void e2d::Node::setPos(const Point & p) void e2d::Node::setPos(double x, double y) { - if (_fPosX == x && _fPosY == y) + if (_posX == x && _posY == y) return; - _fPosX = static_cast(x); - _fPosY = static_cast(y); - _bTransformNeeded = true; + _posX = float(x); + _posY = float(y); + _needTransform = true; } void e2d::Node::setPosFixed(bool fixed) { - if (_bPositionFixed == fixed) + if (_positionFixed == fixed) return; - _bPositionFixed = fixed; - _bTransformNeeded = true; + _positionFixed = fixed; + _needTransform = true; } void e2d::Node::movePosX(double x) @@ -413,7 +413,7 @@ void e2d::Node::movePosY(double y) void e2d::Node::movePos(double x, double y) { - this->setPos(_fPosX + x, _fPosY + y); + this->setPos(_posX + x, _posY + y); } void e2d::Node::movePos(const Vector & v) @@ -423,12 +423,12 @@ void e2d::Node::movePos(const Vector & v) void e2d::Node::setScaleX(double scaleX) { - this->setScale(scaleX, _fScaleY); + this->setScale(scaleX, _scaleY); } void e2d::Node::setScaleY(double scaleY) { - this->setScale(_fScaleX, scaleY); + this->setScale(_scaleX, scaleY); } void e2d::Node::setScale(double scale) @@ -438,91 +438,91 @@ void e2d::Node::setScale(double scale) void e2d::Node::setScale(double scaleX, double scaleY) { - if (_fScaleX == scaleX && _fScaleY == scaleY) + if (_scaleX == scaleX && _scaleY == scaleY) return; - _fScaleX = static_cast(scaleX); - _fScaleY = static_cast(scaleY); - _bTransformNeeded = true; + _scaleX = float(scaleX); + _scaleY = float(scaleY); + _needTransform = true; } void e2d::Node::setSkewX(double angleX) { - this->setSkew(angleX, _fSkewAngleY); + this->setSkew(angleX, _skewAngleY); } void e2d::Node::setSkewY(double angleY) { - this->setSkew(_fSkewAngleX, angleY); + this->setSkew(_skewAngleX, angleY); } void e2d::Node::setSkew(double angleX, double angleY) { - if (_fSkewAngleX == angleX && _fSkewAngleY == angleY) + if (_skewAngleX == angleX && _skewAngleY == angleY) return; - _fSkewAngleX = static_cast(angleX); - _fSkewAngleY = static_cast(angleY); - _bTransformNeeded = true; + _skewAngleX = float(angleX); + _skewAngleY = float(angleY); + _needTransform = true; } void e2d::Node::setRotation(double angle) { - if (_fRotation == angle) + if (_rotation == angle) return; - _fRotation = static_cast(angle); - _bTransformNeeded = true; + _rotation = float(angle); + _needTransform = true; } void e2d::Node::setOpacity(double opacity) { - if (_fRealOpacity == opacity) + if (_realOpacity == opacity) return; - _fDisplayOpacity = _fRealOpacity = min(max(static_cast(opacity), 0), 1); + _displayOpacity = _realOpacity = min(max(float(opacity), 0), 1); // 更新节点透明度 _updateOpacity(); } void e2d::Node::setPivotX(double pivotX) { - this->setPivot(pivotX, _fPivotY); + this->setPivot(pivotX, _pivotY); } void e2d::Node::setPivotY(double pivotY) { - this->setPivot(_fPivotX, pivotY); + this->setPivot(_pivotX, pivotY); } void e2d::Node::setPivot(double pivotX, double pivotY) { - if (_fPivotX == pivotX && _fPivotY == pivotY) + if (_pivotX == pivotX && _pivotY == pivotY) return; - _fPivotX = min(max(static_cast(pivotX), 0), 1); - _fPivotY = min(max(static_cast(pivotY), 0), 1); - _bTransformNeeded = true; + _pivotX = min(max(float(pivotX), 0), 1); + _pivotY = min(max(float(pivotY), 0), 1); + _needTransform = true; } void e2d::Node::setWidth(double width) { - this->setSize(width, _fHeight); + this->setSize(width, _height); } void e2d::Node::setHeight(double height) { - this->setSize(_fWidth, height); + this->setSize(_width, height); } void e2d::Node::setSize(double width, double height) { - if (_fWidth == width && _fHeight == height) + if (_width == width && _height == height) return; - _fWidth = static_cast(width); - _fHeight = static_cast(height); - _bTransformNeeded = true; + _width = float(width); + _height = float(height); + _needTransform = true; } void e2d::Node::setSize(Size size) @@ -575,26 +575,26 @@ void e2d::Node::setCollider(ColliderType nColliderType) void e2d::Node::setCollider(Collider * pCollider) { // 删除旧的碰撞体 - ColliderManager::__removeCollider(_pCollider); + ColliderManager::__removeCollider(_collider); // 添加新的碰撞体 ColliderManager::__addCollider(pCollider); if (pCollider) { // 双向绑定 - this->_pCollider = pCollider; - pCollider->_pParentNode = this; + this->_collider = pCollider; + pCollider->_parentNode = this; } else { - this->_pCollider = nullptr; + this->_collider = nullptr; } } void e2d::Node::addColliableName(const String& collliderName) { unsigned int hash = collliderName.getHashCode(); - _vColliders.insert(hash); + _colliders.insert(hash); } #ifdef HIGHER_THAN_VS2012 @@ -610,7 +610,7 @@ void e2d::Node::addColliableName(const std::initializer_list& vColllider void e2d::Node::removeColliableName(const String& collliderName) { unsigned int hash = collliderName.getHashCode(); - _vColliders.erase(hash); + _colliders.erase(hash); } void e2d::Node::addChild(Node * child, int order /* = 0 */) @@ -619,32 +619,32 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */) if (child) { - ASSERT(child->_pParent == nullptr, "Node already added. It can't be added again!"); + ASSERT(child->_parent == nullptr, "Node already added. It can't be added again!"); for (Node * parent = this; parent != nullptr; parent = parent->getParent()) { ASSERT(child != parent, "A Node cannot be the child of his own children!"); } - _vChildren.push_back(child); + _children.push_back(child); child->setOrder(order); child->retain(); - child->_pParent = this; + child->_parent = this; - if (this->_pParentScene) + if (this->_parentScene) { - child->_setParentScene(this->_pParentScene); + child->_setParentScene(this->_parentScene); } // 更新子节点透明度 child->_updateOpacity(); // 更新节点转换 - child->_bTransformNeeded = true; + child->_needTransform = true; // 更新子节点排序 - _bSortChildrenNeeded = true; + _needSort = true; } } @@ -660,12 +660,12 @@ void e2d::Node::addChild(const std::initializer_list& vNodes, int order) e2d::Node * e2d::Node::getParent() const { - return _pParent; + return _parent; } e2d::Scene * e2d::Node::getParentScene() const { - return _pParentScene; + return _parentScene; } std::vector e2d::Node::getChildren(const String& name) const @@ -673,10 +673,10 @@ std::vector e2d::Node::getChildren(const String& name) const std::vector vChildren; unsigned int hash = name.getHashCode(); - for (auto child : _vChildren) + for (auto child : _children) { // 不同的名称可能会有相同的 Hash 值,但是先比较 Hash 可以提升搜索速度 - if (child->_nHashName == hash && child->_name == name) + if (child->_hashName == hash && child->_name == name) { vChildren.push_back(child); } @@ -688,10 +688,10 @@ e2d::Node * e2d::Node::getChild(const String& name) const { unsigned int hash = name.getHashCode(); - for (auto child : _vChildren) + for (auto child : _children) { // 不同的名称可能会有相同的 Hash 值,但是先比较 Hash 可以提升搜索速度 - if (child->_nHashName == hash && child->_name == name) + if (child->_hashName == hash && child->_name == name) { return child; } @@ -701,19 +701,19 @@ e2d::Node * e2d::Node::getChild(const String& name) const std::vector e2d::Node::getAllChildren() const { - return _vChildren; + return _children; } int e2d::Node::getChildrenCount() const { - return static_cast(_vChildren.size()); + return static_cast(_children.size()); } void e2d::Node::removeFromParent() { - if (_pParent) + if (_parent) { - _pParent->removeChild(this); + _parent->removeChild(this); } } @@ -721,22 +721,22 @@ bool e2d::Node::removeChild(Node * child) { WARN_IF(child == nullptr, "Node::removeChildren NULL pointer exception."); - if (_vChildren.empty()) + if (_children.empty()) { return false; } if (child) { - size_t size = _vChildren.size(); + size_t size = _children.size(); for (size_t i = 0; i < size; i++) { - if (_vChildren[i] == child) + if (_children[i] == child) { - _vChildren.erase(_vChildren.begin() + i); - child->_pParent = nullptr; + _children.erase(_children.begin() + i); + child->_parent = nullptr; - if (child->_pParentScene) + if (child->_parentScene) { child->_setParentScene(nullptr); } @@ -753,7 +753,7 @@ void e2d::Node::removeChildren(const String& childName) { WARN_IF(childName.isEmpty(), "Invalid Node name."); - if (_vChildren.empty()) + if (_children.empty()) { return; } @@ -761,15 +761,15 @@ void e2d::Node::removeChildren(const String& childName) // 计算名称 Hash 值 unsigned int hash = childName.getHashCode(); - size_t size = _vChildren.size(); + size_t size = _children.size(); for (size_t i = 0; i < size; i++) { - auto child = _vChildren[i]; - if (child->_nHashName == hash && child->_name == childName) + auto child = _children[i]; + if (child->_hashName == hash && child->_name == childName) { - _vChildren.erase(_vChildren.begin() + i); - child->_pParent = nullptr; - if (child->_pParentScene) + _children.erase(_children.begin() + i); + child->_parent = nullptr; + if (child->_parentScene) { child->_setParentScene(nullptr); } @@ -781,12 +781,12 @@ void e2d::Node::removeChildren(const String& childName) void e2d::Node::clearAllChildren() { // 所有节点的引用计数减一 - for (auto child : _vChildren) + for (auto child : _children) { child->release(); } // 清空储存节点的容器 - _vChildren.clear(); + _children.clear(); } void e2d::Node::runAction(Action * action) @@ -873,13 +873,13 @@ bool e2d::Node::isPointIn(Point point) const { BOOL ret = 0; // 如果存在碰撞体,用碰撞体判断 - if (_pCollider) + if (_collider) { - _pCollider->getD2dGeometry()->FillContainsPoint( + _collider->getD2dGeometry()->FillContainsPoint( D2D1::Point2F( - static_cast(point.x), - static_cast(point.y)), - _MatriFinal, + float(point.x), + float(point.y)), + _finalMatri, &ret ); } @@ -888,15 +888,15 @@ bool e2d::Node::isPointIn(Point point) const // 为节点创建一个临时碰撞体 ID2D1RectangleGeometry * rect; Renderer::getID2D1Factory()->CreateRectangleGeometry( - D2D1::RectF(0, 0, _fWidth, _fHeight), + D2D1::RectF(0, 0, _width, _height), &rect ); // 判断点是否在碰撞体内 rect->FillContainsPoint( D2D1::Point2F( - static_cast(point.x), - static_cast(point.y)), - _MatriFinal, + float(point.x), + float(point.y)), + _finalMatri, &ret ); // 删除临时创建的碰撞体 @@ -914,9 +914,9 @@ bool e2d::Node::isPointIn(Point point) const bool e2d::Node::isIntersectWith(const Node * node) const { // 如果存在碰撞体,用碰撞体判断 - if (this->_pCollider && node->_pCollider) + if (this->_collider && node->_collider) { - Relation relation = this->_pCollider->getRelationWith(node->_pCollider); + Relation relation = this->_collider->getRelationWith(node->_collider); if ((relation != Relation::UNKNOWN) && (relation != Relation::DISJOINT)) { @@ -933,24 +933,24 @@ bool e2d::Node::isIntersectWith(const Node * node) const // 根据自身大小位置创建矩形 Renderer::getID2D1Factory()->CreateRectangleGeometry( - D2D1::RectF(0, 0, _fWidth, _fHeight), + D2D1::RectF(0, 0, _width, _height), &pRect1 ); // 根据二维矩阵进行转换 Renderer::getID2D1Factory()->CreateTransformedGeometry( pRect1, - _MatriFinal, + _finalMatri, &pCollider ); // 根据相比较节点的大小位置创建矩形 Renderer::getID2D1Factory()->CreateRectangleGeometry( - D2D1::RectF(0, 0, node->_fWidth, node->_fHeight), + D2D1::RectF(0, 0, node->_width, node->_height), &pRect2 ); // 获取相交状态 pCollider->CompareWithGeometry( pRect2, - node->_MatriFinal, + node->_finalMatri, &relation ); // 删除临时创建的碰撞体 @@ -969,13 +969,13 @@ bool e2d::Node::isIntersectWith(const Node * node) const void e2d::Node::setAutoUpdate(bool bAutoUpdate) { - _bAutoUpdate = bAutoUpdate; + _autoUpdate = bAutoUpdate; } void e2d::Node::setDefaultPiovt(double defaultPiovtX, double defaultPiovtY) { - s_fDefaultPiovtX = min(max(static_cast(defaultPiovtX), 0), 1); - s_fDefaultPiovtY = min(max(static_cast(defaultPiovtY), 0), 1); + s_fDefaultPiovtX = min(max(float(defaultPiovtX), 0), 1); + s_fDefaultPiovtY = min(max(float(defaultPiovtY), 0), 1); } void e2d::Node::setDefaultColliderEnable(bool enable) @@ -986,8 +986,8 @@ void e2d::Node::setDefaultColliderEnable(bool enable) void e2d::Node::onDestroy() { ActionManager::__clearAllBindedWith(this); - ColliderManager::__removeCollider(_pCollider); - for (auto child : _vChildren) + ColliderManager::__removeCollider(_collider); + for (auto child : _children) { SafeRelease(&child); } @@ -1010,7 +1010,7 @@ void e2d::Node::stopAllActions() void e2d::Node::setVisiable(bool value) { - _bVisiable = value; + _visiable = value; } void e2d::Node::setName(const String& name) @@ -1022,14 +1022,14 @@ void e2d::Node::setName(const String& name) // 保存节点名 _name = name; // 保存节点 Hash 名 - _nHashName = name.getHashCode(); + _hashName = name.getHashCode(); } } void e2d::Node::_setParentScene(Scene * scene) { - _pParentScene = scene; - for (auto child : _vChildren) + _parentScene = scene; + for (auto child : _children) { child->_setParentScene(scene); } diff --git a/core/Node/Shape/Circle.cpp b/core/Node/Shape/Circle.cpp index be70277b..1f26fd93 100644 --- a/core/Node/Shape/Circle.cpp +++ b/core/Node/Shape/Circle.cpp @@ -1,7 +1,7 @@ #include "..\..\e2dshape.h" e2d::Circle::Circle() - : _fRadius(0) + : _radius(0) { this->setPivot(0.5, 0.5); } @@ -32,28 +32,28 @@ e2d::Circle::~Circle() double e2d::Circle::getRadius() const { - return _fRadius; + return _radius; } void e2d::Circle::setRadius(double radius) { - _fRadius = static_cast(radius); + _radius = float(radius); Node::setSize(radius * 2, radius * 2); } void e2d::Circle::_renderLine() { Renderer::getRenderTarget()->DrawEllipse( - D2D1::Ellipse(D2D1::Point2F(_fRadius, _fRadius), _fRadius, _fRadius), + D2D1::Ellipse(D2D1::Point2F(_radius, _radius), _radius, _radius), Renderer::getSolidColorBrush(), - _fStrokeWidth + _strokeWidth ); } void e2d::Circle::_renderFill() { Renderer::getRenderTarget()->FillEllipse( - D2D1::Ellipse(D2D1::Point2F(_fRadius, _fRadius), _fRadius, _fRadius), + D2D1::Ellipse(D2D1::Point2F(_radius, _radius), _radius, _radius), Renderer::getSolidColorBrush() ); } diff --git a/core/Node/Shape/Ellipse.cpp b/core/Node/Shape/Ellipse.cpp index 1bdd98dd..37bbc798 100644 --- a/core/Node/Shape/Ellipse.cpp +++ b/core/Node/Shape/Ellipse.cpp @@ -1,8 +1,8 @@ #include "..\..\e2dshape.h" e2d::Ellipse::Ellipse() - : _fRadiusX(0) - , _fRadiusY(0) + : _radiusX(0) + , _radiusY(0) { this->setPivot(0.5, 0.5); } @@ -36,39 +36,39 @@ e2d::Ellipse::~Ellipse() double e2d::Ellipse::getRadiusX() const { - return _fRadiusX; + return _radiusX; } double e2d::Ellipse::getRadiusY() const { - return _fRadiusY; + return _radiusY; } void e2d::Ellipse::setRadiusX(double radiusX) { - _fRadiusX = static_cast(radiusX); + _radiusX = float(radiusX); Node::setWidth(radiusX * 2); } void e2d::Ellipse::setRadiusY(double radiusY) { - _fRadiusY = static_cast(radiusY); + _radiusY = float(radiusY); Node::setHeight(radiusY * 2); } void e2d::Ellipse::_renderLine() { Renderer::getRenderTarget()->DrawEllipse( - D2D1::Ellipse(D2D1::Point2F(_fRadiusX, _fRadiusY), _fRadiusX, _fRadiusY), + D2D1::Ellipse(D2D1::Point2F(_radiusX, _radiusY), _radiusX, _radiusY), Renderer::getSolidColorBrush(), - _fStrokeWidth + _strokeWidth ); } void e2d::Ellipse::_renderFill() { Renderer::getRenderTarget()->FillEllipse( - D2D1::Ellipse(D2D1::Point2F(_fRadiusX, _fRadiusY), _fRadiusX, _fRadiusY), + D2D1::Ellipse(D2D1::Point2F(_radiusX, _radiusY), _radiusX, _radiusY), Renderer::getSolidColorBrush() ); } diff --git a/core/Node/Shape/Rect.cpp b/core/Node/Shape/Rect.cpp index d8c02fa2..e00380b8 100644 --- a/core/Node/Shape/Rect.cpp +++ b/core/Node/Shape/Rect.cpp @@ -35,16 +35,16 @@ e2d::Rect::~Rect() void e2d::Rect::_renderLine() { Renderer::getRenderTarget()->DrawRectangle( - D2D1::RectF(0, 0, _fWidth, _fHeight), + D2D1::RectF(0, 0, _width, _height), Renderer::getSolidColorBrush(), - _fStrokeWidth + _strokeWidth ); } void e2d::Rect::_renderFill() { Renderer::getRenderTarget()->FillRectangle( - D2D1::RectF(0, 0, _fWidth, _fHeight), + D2D1::RectF(0, 0, _width, _height), Renderer::getSolidColorBrush() ); } diff --git a/core/Node/Shape/RoundRect.cpp b/core/Node/Shape/RoundRect.cpp index cc42d76d..2555a5aa 100644 --- a/core/Node/Shape/RoundRect.cpp +++ b/core/Node/Shape/RoundRect.cpp @@ -1,28 +1,28 @@ #include "..\..\e2dshape.h" e2d::RoundRect::RoundRect() - : _fRadiusX(0) - , _fRadiusY(0) + : _radiusX(0) + , _radiusY(0) { } e2d::RoundRect::RoundRect(double width, double height, double radiusX, double radiusY) - : _fRadiusX(static_cast(radiusX)) - , _fRadiusY(static_cast(radiusY)) + : _radiusX(float(radiusX)) + , _radiusY(float(radiusY)) { this->setSize(width, height); } e2d::RoundRect::RoundRect(Size size, double radiusX, double radiusY) - : _fRadiusX(static_cast(radiusX)) - , _fRadiusY(static_cast(radiusY)) + : _radiusX(float(radiusX)) + , _radiusY(float(radiusY)) { this->setSize(size); } e2d::RoundRect::RoundRect(double top, double left, double width, double height, double radiusX, double radiusY) - : _fRadiusX(static_cast(radiusX)) - , _fRadiusY(static_cast(radiusY)) + : _radiusX(float(radiusX)) + , _radiusY(float(radiusY)) { this->setPivot(0, 0); this->setPos(top, left); @@ -30,8 +30,8 @@ e2d::RoundRect::RoundRect(double top, double left, double width, double height, } e2d::RoundRect::RoundRect(Point topLeft, Size size, double radiusX, double radiusY) - : _fRadiusX(static_cast(radiusX)) - , _fRadiusY(static_cast(radiusY)) + : _radiusX(float(radiusX)) + , _radiusY(float(radiusY)) { this->setPivot(0, 0); this->setPos(topLeft); @@ -44,37 +44,37 @@ e2d::RoundRect::~RoundRect() double e2d::RoundRect::getRadiusX() const { - return _fRadiusX; + return _radiusX; } double e2d::RoundRect::getRadiusY() const { - return _fRadiusY; + return _radiusY; } void e2d::RoundRect::setRadiusX(double radiusX) { - _fRadiusX = static_cast(radiusX); + _radiusX = float(radiusX); } void e2d::RoundRect::setRadiusY(double radiusY) { - _fRadiusY = static_cast(radiusY); + _radiusY = float(radiusY); } void e2d::RoundRect::_renderLine() { Renderer::getRenderTarget()->DrawRoundedRectangle( - D2D1::RoundedRect(D2D1::RectF(0, 0, _fWidth, _fHeight), _fRadiusX, _fRadiusY), + D2D1::RoundedRect(D2D1::RectF(0, 0, _width, _height), _radiusX, _radiusY), Renderer::getSolidColorBrush(), - _fStrokeWidth + _strokeWidth ); } void e2d::RoundRect::_renderFill() { Renderer::getRenderTarget()->FillRoundedRectangle( - D2D1::RoundedRect(D2D1::RectF(0, 0, _fWidth, _fHeight), _fRadiusX, _fRadiusY), + D2D1::RoundedRect(D2D1::RectF(0, 0, _width, _height), _radiusX, _radiusY), Renderer::getSolidColorBrush() ); } diff --git a/core/Node/Shape/Shape.cpp b/core/Node/Shape/Shape.cpp index 9eaa67c1..d3bdb175 100644 --- a/core/Node/Shape/Shape.cpp +++ b/core/Node/Shape/Shape.cpp @@ -1,10 +1,10 @@ #include "..\..\e2dshape.h" e2d::Shape::Shape() - : _nStyle(ShapeStyle::SOLID) - , _nFillColor(Color::WHITE) - , _nLineColor(Color::BLUE, 0.5) - , _fStrokeWidth(1) + : _style(ShapeStyle::SOLID) + , _fillColor(Color::WHITE) + , _lineColor(Color::BLUE, 0.5) + , _strokeWidth(1) { } @@ -15,30 +15,30 @@ e2d::Shape::~Shape() void e2d::Shape::onRender() { auto pBrush = Renderer::getSolidColorBrush(); - pBrush->SetOpacity(_fDisplayOpacity); + pBrush->SetOpacity(_displayOpacity); - switch (_nStyle) + switch (_style) { case ShapeStyle::FILL: { - pBrush->SetColor(_nFillColor.toColorF()); + pBrush->SetColor(_fillColor.toColorF()); this->_renderFill(); - pBrush->SetColor(_nLineColor.toColorF()); + pBrush->SetColor(_lineColor.toColorF()); this->_renderLine(); break; } case ShapeStyle::ROUND: { - pBrush->SetColor(_nLineColor.toColorF()); + pBrush->SetColor(_lineColor.toColorF()); this->_renderLine(); break; } case ShapeStyle::SOLID: { - pBrush->SetColor(_nFillColor.toColorF()); + pBrush->SetColor(_fillColor.toColorF()); this->_renderFill(); break; } @@ -50,40 +50,40 @@ void e2d::Shape::onRender() e2d::Color e2d::Shape::getFillColor() const { - return _nFillColor; + return _fillColor; } e2d::Color e2d::Shape::getLineColor() const { - return _nLineColor; + return _lineColor; } double e2d::Shape::getStrokeWidth() const { - return _fStrokeWidth; + return _strokeWidth; } e2d::ShapeStyle e2d::Shape::getStyle() const { - return _nStyle; + return _style; } void e2d::Shape::setFillColor(Color fillColor) { - _nFillColor = fillColor; + _fillColor = fillColor; } void e2d::Shape::setLineColor(Color lineColor) { - _nLineColor = lineColor; + _lineColor = lineColor; } void e2d::Shape::setStrokeWidth(double strokeWidth) { - _fStrokeWidth = static_cast(strokeWidth); + _strokeWidth = float(strokeWidth); } void e2d::Shape::setStyle(ShapeStyle style) { - _nStyle = style; + _style = style; } diff --git a/core/Node/Sprite.cpp b/core/Node/Sprite.cpp index e5302742..63da8082 100644 --- a/core/Node/Sprite.cpp +++ b/core/Node/Sprite.cpp @@ -2,37 +2,37 @@ e2d::Sprite::Sprite() - : _pImage(nullptr) + : _image(nullptr) { } e2d::Sprite::Sprite(Image * image) - : _pImage(nullptr) + : _image(nullptr) { open(image); } e2d::Sprite::Sprite(const String& filePath) - : _pImage(nullptr) + : _image(nullptr) { open(filePath); } e2d::Sprite::Sprite(int resNameId, const String& resType) - : _pImage(nullptr) + : _image(nullptr) { open(resNameId, resType); } e2d::Sprite::Sprite(const String& filePath, double x, double y, double width, double height) - : _pImage(nullptr) + : _image(nullptr) { open(filePath); crop(x, y, width, height); } e2d::Sprite::Sprite(int resNameId, const String& resType, double x, double y, double width, double height) - : _pImage(nullptr) + : _image(nullptr) { open(resNameId, resType); crop(x, y, width, height); @@ -46,11 +46,11 @@ bool e2d::Sprite::open(Image * image) { if (image) { - SafeRelease(&_pImage); - _pImage = image; - _pImage->retain(); + SafeRelease(&_image); + _image = image; + _image->retain(); - Node::setSize(_pImage->getWidth(), _pImage->getHeight()); + Node::setSize(_image->getWidth(), _image->getHeight()); return true; } return false; @@ -58,15 +58,15 @@ bool e2d::Sprite::open(Image * image) bool e2d::Sprite::open(const String& filePath) { - if (!_pImage) + if (!_image) { - _pImage = new (std::nothrow) Image(); - _pImage->retain(); + _image = new (std::nothrow) Image(); + _image->retain(); } - if (_pImage->open(filePath)) + if (_image->open(filePath)) { - Node::setSize(_pImage->getWidth(), _pImage->getHeight()); + Node::setSize(_image->getWidth(), _image->getHeight()); return true; } return false; @@ -74,15 +74,15 @@ bool e2d::Sprite::open(const String& filePath) bool e2d::Sprite::open(int resNameId, const String& resType) { - if (!_pImage) + if (!_image) { - _pImage = new (std::nothrow) Image(); - _pImage->retain(); + _image = new (std::nothrow) Image(); + _image->retain(); } - if (_pImage->open(resNameId, resType)) + if (_image->open(resNameId, resType)) { - Node::setSize(_pImage->getWidth(), _pImage->getHeight()); + Node::setSize(_image->getWidth(), _image->getHeight()); return true; } return false; @@ -90,36 +90,36 @@ bool e2d::Sprite::open(int resNameId, const String& resType) void e2d::Sprite::crop(double x, double y, double width, double height) { - _pImage->crop(x, y, width, height); + _image->crop(x, y, width, height); Node::setSize( - min(max(width, 0), _pImage->getSourceWidth() - _pImage->getCropX()), - min(max(height, 0), _pImage->getSourceHeight() - _pImage->getCropY()) + min(max(width, 0), _image->getSourceWidth() - _image->getCropX()), + min(max(height, 0), _image->getSourceHeight() - _image->getCropY()) ); } e2d::Image * e2d::Sprite::getImage() const { - return _pImage; + return _image; } void e2d::Sprite::onRender() { - if (_pImage && _pImage->getBitmap()) + if (_image && _image->getBitmap()) { // 获取图片裁剪位置 - float fCropX = static_cast(_pImage->getCropX()); - float fCropY = static_cast(_pImage->getCropY()); + float fCropX = float(_image->getCropX()); + float fCropY = float(_image->getCropY()); // 渲染图片 Renderer::getRenderTarget()->DrawBitmap( - _pImage->getBitmap(), - D2D1::RectF(0, 0, _fWidth, _fHeight), - _fDisplayOpacity, + _image->getBitmap(), + D2D1::RectF(0, 0, _width, _height), + _displayOpacity, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1::RectF( fCropX, fCropY, - fCropX + _fWidth, - fCropY + _fHeight + fCropX + _width, + fCropY + _height ) ); } @@ -128,5 +128,5 @@ void e2d::Sprite::onRender() void e2d::Sprite::onDestroy() { Node::onDestroy(); - SafeRelease(&_pImage); + SafeRelease(&_image); } diff --git a/core/Node/Text.cpp b/core/Node/Text.cpp index a3476a78..26c2784c 100644 --- a/core/Node/Text.cpp +++ b/core/Node/Text.cpp @@ -2,34 +2,34 @@ e2d::Text::Text() - : _TextStyle() - , _pDWriteTextLayout(nullptr) - , _pDWriteTextFormat(nullptr) + : _style() + , _textLayout(nullptr) + , _textFormat(nullptr) { } e2d::Text::Text(const String& text) - : _TextStyle() - , _pDWriteTextLayout(nullptr) - , _pDWriteTextFormat(nullptr) - , _sText(text) + : _style() + , _textLayout(nullptr) + , _textFormat(nullptr) + , _text(text) { _reset(); } e2d::Text::Text(TextStyle textStyle) - : _TextStyle(textStyle) - , _pDWriteTextLayout(nullptr) - , _pDWriteTextFormat(nullptr) + : _style(textStyle) + , _textLayout(nullptr) + , _textFormat(nullptr) { _reset(); } e2d::Text::Text(const String& text, TextStyle textStyle) - : _TextStyle(textStyle) - , _pDWriteTextLayout(nullptr) - , _pDWriteTextFormat(nullptr) - , _sText(text) + : _style(textStyle) + , _textLayout(nullptr) + , _textFormat(nullptr) + , _text(text) { _reset(); } @@ -51,7 +51,7 @@ e2d::Text::Text( UINT32 outlineColor, UINT32 outlineWidth ) - : _TextStyle( + : _style( fontFamily, fontSize, color, @@ -67,70 +67,70 @@ e2d::Text::Text( outlineColor, outlineWidth ) - , _pDWriteTextLayout(nullptr) - , _pDWriteTextFormat(nullptr) - , _sText(text) + , _textLayout(nullptr) + , _textFormat(nullptr) + , _text(text) { _reset(); } e2d::Text::~Text() { - SafeReleaseInterface(&_pDWriteTextFormat); - SafeReleaseInterface(&_pDWriteTextLayout); + SafeReleaseInterface(&_textFormat); + SafeReleaseInterface(&_textLayout); } e2d::String e2d::Text::getText() const { - return _sText; + return _text; } e2d::TextStyle e2d::Text::getTextStyle() const { - return _TextStyle; + return _style; } e2d::String e2d::Text::getFontFamily() const { - return _TextStyle.fontFamily; + return _style.fontFamily; } double e2d::Text::getFontSize() const { - return _TextStyle.fontSize; + return _style.fontSize; } UINT32 e2d::Text::getFontWeight() const { - return _TextStyle.fontWeight; + return _style.fontWeight; } e2d::Color e2d::Text::getColor() const { - return _TextStyle.color; + return _style.color; } e2d::Color e2d::Text::getOutlineColor() const { - return _TextStyle.outlineColor; + return _style.outlineColor; } double e2d::Text::getOutlineWidth() const { - return _TextStyle.outlineWidth; + return _style.outlineWidth; } e2d::LineJoin e2d::Text::getOutlineJoin() const { - return _TextStyle.outlineJoin; + return _style.outlineJoin; } int e2d::Text::getLineCount() const { - if (_pDWriteTextLayout) + if (_textLayout) { DWRITE_TEXT_METRICS metrics; - _pDWriteTextLayout->GetMetrics(&metrics); + _textLayout->GetMetrics(&metrics); return static_cast(metrics.lineCount); } else @@ -141,81 +141,81 @@ int e2d::Text::getLineCount() const bool e2d::Text::isItalic() const { - return _TextStyle.italic; + return _style.italic; } bool e2d::Text::hasStrikethrough() const { - return _TextStyle.hasStrikethrough; + return _style.hasStrikethrough; } bool e2d::Text::hasUnderline() const { - return _TextStyle.hasUnderline; + return _style.hasUnderline; } bool e2d::Text::hasOutline() const { - return _TextStyle.hasOutline; + return _style.hasOutline; } void e2d::Text::setText(const String& text) { - _sText = text; + _text = text; _reset(); } void e2d::Text::setTextStyle(TextStyle textStyle) { - _TextStyle = textStyle; + _style = textStyle; _reset(); } void e2d::Text::setFontFamily(const String& fontFamily) { - _TextStyle.fontFamily = fontFamily; + _style.fontFamily = fontFamily; _reset(); } void e2d::Text::setFontSize(double fontSize) { - _TextStyle.fontSize = fontSize; + _style.fontSize = fontSize; _reset(); } void e2d::Text::setFontWeight(UINT32 fontWeight) { - _TextStyle.fontWeight = fontWeight; + _style.fontWeight = fontWeight; _reset(); } void e2d::Text::setColor(Color color) { - _TextStyle.color = color; + _style.color = color; } void e2d::Text::setItalic(bool value) { - _TextStyle.italic = value; + _style.italic = value; _reset(); } void e2d::Text::setWrapping(bool wrapping) { - if (_TextStyle.wrapping != wrapping) + if (_style.wrapping != wrapping) { - _TextStyle.wrapping = wrapping; + _style.wrapping = wrapping; _reset(); } } void e2d::Text::setWrappingWidth(double fWrappingWidth) { - if (_TextStyle.wrappingWidth != fWrappingWidth) + if (_style.wrappingWidth != fWrappingWidth) { - _TextStyle.wrappingWidth = max(fWrappingWidth, 0); + _style.wrappingWidth = max(fWrappingWidth, 0); - if (_TextStyle.wrapping) + if (_style.wrapping) { _reset(); } @@ -224,28 +224,28 @@ void e2d::Text::setWrappingWidth(double fWrappingWidth) void e2d::Text::setLineSpacing(double fLineSpacing) { - if (_TextStyle.lineSpacing != fLineSpacing) + if (_style.lineSpacing != fLineSpacing) { - _TextStyle.lineSpacing = fLineSpacing; + _style.lineSpacing = fLineSpacing; _reset(); } } void e2d::Text::setAlignment(TextAlign align) { - if (_TextStyle.alignment != align) + if (_style.alignment != align) { - _TextStyle.alignment = align; + _style.alignment = align; _reset(); } } void e2d::Text::setUnderline(bool hasUnderline) { - if (_TextStyle.hasUnderline != hasUnderline) + if (_style.hasUnderline != hasUnderline) { - _TextStyle.hasUnderline = hasUnderline; - if (!_pDWriteTextFormat) + _style.hasUnderline = hasUnderline; + if (!_textFormat) _createFormat(); _createLayout(); } @@ -253,10 +253,10 @@ void e2d::Text::setUnderline(bool hasUnderline) void e2d::Text::setStrikethrough(bool hasStrikethrough) { - if (_TextStyle.hasStrikethrough != hasStrikethrough) + if (_style.hasStrikethrough != hasStrikethrough) { - _TextStyle.hasStrikethrough = hasStrikethrough; - if (!_pDWriteTextFormat) + _style.hasStrikethrough = hasStrikethrough; + if (!_textFormat) _createFormat(); _createLayout(); } @@ -264,42 +264,42 @@ void e2d::Text::setStrikethrough(bool hasStrikethrough) void e2d::Text::setOutline(bool hasOutline) { - _TextStyle.hasOutline = hasOutline; + _style.hasOutline = hasOutline; } void e2d::Text::setOutlineColor(Color outlineColor) { - _TextStyle.outlineColor = outlineColor; + _style.outlineColor = outlineColor; } void e2d::Text::setOutlineWidth(double outlineWidth) { - _TextStyle.outlineWidth = outlineWidth; + _style.outlineWidth = outlineWidth; } void e2d::Text::setOutlineJoin(LineJoin outlineJoin) { - _TextStyle.outlineJoin = outlineJoin; + _style.outlineJoin = outlineJoin; } void e2d::Text::onRender() { - if (_pDWriteTextLayout) + if (_textLayout) { // 创建文本区域 - D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, _fWidth, _fHeight); + D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, _width, _height); // 设置画刷颜色和透明度 - Renderer::getSolidColorBrush()->SetOpacity(_fDisplayOpacity); + Renderer::getSolidColorBrush()->SetOpacity(_displayOpacity); // 获取文本渲染器 auto pTextRenderer = Renderer::getCustomTextRenderer(); pTextRenderer->SetTextStyle( - _TextStyle.color.toColorF(), - _TextStyle.hasOutline, - _TextStyle.outlineColor.toColorF(), - static_cast(_TextStyle.outlineWidth), - D2D1_LINE_JOIN(_TextStyle.outlineJoin) + _style.color.toColorF(), + _style.hasOutline, + _style.outlineColor.toColorF(), + float(_style.outlineWidth), + D2D1_LINE_JOIN(_style.outlineJoin) ); - _pDWriteTextLayout->Draw(NULL, pTextRenderer, 0, 0); + _textLayout->Draw(NULL, pTextRenderer, 0, 0); } } @@ -313,105 +313,105 @@ void e2d::Text::_reset() void e2d::Text::_createFormat() { - SafeReleaseInterface(&_pDWriteTextFormat); + SafeReleaseInterface(&_textFormat); HRESULT hr = Renderer::getIDWriteFactory()->CreateTextFormat( - _TextStyle.fontFamily, + _style.fontFamily, NULL, - DWRITE_FONT_WEIGHT(_TextStyle.fontWeight), - _TextStyle.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL, + DWRITE_FONT_WEIGHT(_style.fontWeight), + _style.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, - static_cast(_TextStyle.fontSize), + float(_style.fontSize), L"", - &_pDWriteTextFormat + &_textFormat ); ASSERT(SUCCEEDED(hr), "Create IDWriteTextFormat Failed!"); - if (_pDWriteTextFormat) + if (_textFormat) { // 设置文字对齐方式 - _pDWriteTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT(_TextStyle.alignment)); + _textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT(_style.alignment)); // 设置行间距 - if (_TextStyle.lineSpacing == 0.0) + if (_style.lineSpacing == 0.0) { - _pDWriteTextFormat->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_DEFAULT, 0, 0); + _textFormat->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_DEFAULT, 0, 0); } else { - _pDWriteTextFormat->SetLineSpacing( + _textFormat->SetLineSpacing( DWRITE_LINE_SPACING_METHOD_UNIFORM, - static_cast(_TextStyle.lineSpacing), - static_cast(_TextStyle.lineSpacing) * 0.8f + float(_style.lineSpacing), + float(_style.lineSpacing) * 0.8f ); } // 打开文本自动换行时,设置换行属性 - if (_TextStyle.wrapping) + if (_style.wrapping) { - _pDWriteTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_WRAP); + _textFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_WRAP); } else { - _pDWriteTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); + _textFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); } } } void e2d::Text::_createLayout() { - SafeReleaseInterface(&_pDWriteTextLayout); + SafeReleaseInterface(&_textLayout); // 文本为空字符串时,重置属性 - if (_sText.isEmpty()) + if (_text.isEmpty()) { this->setSize(0, 0); return; } - if (_pDWriteTextFormat == nullptr) + if (_textFormat == nullptr) { - WARN_IF(true, "Text::_createLayout failed! _pDWriteTextFormat NULL pointer exception."); + WARN_IF(true, "Text::_createLayout failed! _textFormat NULL pointer exception."); return; } - UINT32 length = static_cast(_sText.getLength()); + UINT32 length = UINT32(_text.getLength()); // 创建 TextLayout HRESULT hr; // 对文本自动换行情况下进行处理 - if (_TextStyle.wrapping) + if (_style.wrapping) { hr = Renderer::getIDWriteFactory()->CreateTextLayout( - _sText, + _text, length, - _pDWriteTextFormat, - static_cast(_TextStyle.wrappingWidth), + _textFormat, + float(_style.wrappingWidth), 0, - &_pDWriteTextLayout + &_textLayout ); - if (_pDWriteTextLayout) + if (_textLayout) { // 获取文本布局的宽度和高度 DWRITE_TEXT_METRICS metrics; - _pDWriteTextLayout->GetMetrics(&metrics); + _textLayout->GetMetrics(&metrics); // 重设文本宽高 this->setSize(metrics.layoutWidth, metrics.height); } } else { - hr = Renderer::getIDWriteFactory()->CreateTextLayout(_sText, length, _pDWriteTextFormat, 0, 0, &_pDWriteTextLayout); + hr = Renderer::getIDWriteFactory()->CreateTextLayout(_text, length, _textFormat, 0, 0, &_textLayout); // 为防止文本对齐问题,根据刚才创建的 layout 宽度重新创建它 - if (_pDWriteTextLayout) + if (_textLayout) { // 获取文本布局的宽度和高度 DWRITE_TEXT_METRICS metrics; - _pDWriteTextLayout->GetMetrics(&metrics); + _textLayout->GetMetrics(&metrics); // 重设文本宽高 this->setSize(metrics.width, metrics.height); // 重新创建 layout - SafeReleaseInterface(&_pDWriteTextLayout); - hr = Renderer::getIDWriteFactory()->CreateTextLayout(_sText, length, _pDWriteTextFormat, _fWidth, 0, &_pDWriteTextLayout); + SafeReleaseInterface(&_textLayout); + hr = Renderer::getIDWriteFactory()->CreateTextLayout(_text, length, _textFormat, _width, 0, &_textLayout); } } @@ -419,12 +419,12 @@ void e2d::Text::_createLayout() // 添加下划线和删除线 DWRITE_TEXT_RANGE range = { 0, length }; - if (_TextStyle.hasUnderline) + if (_style.hasUnderline) { - _pDWriteTextLayout->SetUnderline(true, range); + _textLayout->SetUnderline(true, range); } - if (_TextStyle.hasStrikethrough) + if (_style.hasStrikethrough) { - _pDWriteTextLayout->SetStrikethrough(true, range); + _textLayout->SetStrikethrough(true, range); } } diff --git a/core/Tool/Music.cpp b/core/Tool/Music.cpp index 28674508..2edacd74 100644 --- a/core/Tool/Music.cpp +++ b/core/Tool/Music.cpp @@ -762,7 +762,7 @@ double e2d::Music::getVolume() void e2d::Music::setVolume(double fVolume) { - s_fMusicVolume = min(max(static_cast(fVolume), -224), 224); + s_fMusicVolume = min(max(float(fVolume), -224), 224); for (auto pair : GetMusicFileList()) { pair.second->setVolume(s_fMusicVolume); diff --git a/core/Transition/Transition.cpp b/core/Transition/Transition.cpp index e23951aa..3d668ef3 100644 --- a/core/Transition/Transition.cpp +++ b/core/Transition/Transition.cpp @@ -1,21 +1,135 @@ +#include "..\e2dbase.h" #include "..\e2dtransition.h" +#include "..\e2dnode.h" -e2d::TransitionFade * e2d::Transition::Fade(double duration) +e2d::Transition::Transition(double duration) + : _end(false) + , _last(0) + , _delta(0) + , _outScene(nullptr) + , _inScene(nullptr) + , _outLayer(nullptr) + , _inLayer(nullptr) + , _outLayerParam() + , _inLayerParam() { - return new (std::nothrow) TransitionFade(duration); + _duration = max(duration, 0); } -e2d::TransitionFade * e2d::Transition::Fade(double fadeOutDuration, double fadeInDuration) +e2d::Transition::~Transition() { - return new (std::nothrow) TransitionFade(fadeOutDuration, fadeInDuration); + SafeReleaseInterface(&_outLayer); + SafeReleaseInterface(&_inLayer); } -e2d::TransitionEmerge * e2d::Transition::Emerge(double duration) +bool e2d::Transition::isDone() { - return new (std::nothrow) TransitionEmerge(duration); + return _end; } -e2d::TransitionMove * e2d::Transition::Move(double duration, Direct direct) +void e2d::Transition::onDestroy() { - return new (std::nothrow) TransitionMove(duration, direct); + SafeRelease(&_outScene); + SafeRelease(&_inScene); +} + +void e2d::Transition::_init(Scene * prev, Scene * next) +{ + // 创建图层 + HRESULT hr = Renderer::getRenderTarget()->CreateLayer(&_inLayer); + + if (SUCCEEDED(hr)) + { + hr = Renderer::getRenderTarget()->CreateLayer(&_outLayer); + } + + if (FAILED(hr)) + { + ASSERT(false, "Create layer failed!"); + } + + _last = Time::getTotalTime(); + _outScene = prev; + _inScene = next; + if (_outScene) _outScene->retain(); + if (_inScene) _inScene->retain(); + + _windowSize = Window::getSize(); + _outLayerParam = _inLayerParam = D2D1::LayerParameters(); +} + +void e2d::Transition::_update() +{ + // 计算动画进度 + if (_duration == 0) + { + _delta = 1; + } + else + { + _delta = min((Time::getTotalTime() - _last) / _duration, 1); + } + + this->_updateCustom(); + + // 更新场景内容 + if (_outScene) + { + _outScene->_update(); + } + if (_inScene) + { + _inScene->_update(); + } +} + +void e2d::Transition::_render() +{ + auto pRT = Renderer::getRenderTarget(); + + if (_outScene) + { + Point rootPos = _outScene->getRoot()->getPos(); + auto clipRect = D2D1::RectF( + float(max(rootPos.x, 0)), + float(max(rootPos.y, 0)), + float(min(rootPos.x + _windowSize.width, _windowSize.width)), + float(min(rootPos.y + _windowSize.height, _windowSize.height)) + ); + pRT->SetTransform(D2D1::Matrix3x2F::Identity()); + pRT->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); + pRT->PushLayer(_outLayerParam, _outLayer); + + // 渲染场景 + _outScene->_render(); + + pRT->PopLayer(); + pRT->PopAxisAlignedClip(); + } + + if (_inScene) + { + Point rootPos = _inScene->getRoot()->getPos(); + auto clipRect = D2D1::RectF( + float(max(rootPos.x, 0)), + float(max(rootPos.y, 0)), + float(min(rootPos.x + _windowSize.width, _windowSize.width)), + float(min(rootPos.y + _windowSize.height, _windowSize.height)) + ); + pRT->SetTransform(D2D1::Matrix3x2F::Identity()); + pRT->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); + pRT->PushLayer(_inLayerParam, _inLayer); + + // 渲染场景 + _inScene->_render(); + + pRT->PopLayer(); + pRT->PopAxisAlignedClip(); + } +} + +void e2d::Transition::_stop() +{ + _end = true; + _reset(); } diff --git a/core/Transition/TransitionBase.cpp b/core/Transition/TransitionBase.cpp deleted file mode 100644 index fafc2ca0..00000000 --- a/core/Transition/TransitionBase.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#include "..\e2dbase.h" -#include "..\e2dtransition.h" -#include "..\e2dnode.h" - -e2d::TransitionBase::TransitionBase(double duration) - : _bEnd(false) - , _fLast(0) - , _delta(0) - , _pPrevScene(nullptr) - , _pNextScene(nullptr) - , _pPrevLayer(nullptr) - , _pNextLayer(nullptr) - , _sPrevLayerParam() - , _sNextLayerParam() -{ - _duration = max(duration, 0); -} - -e2d::TransitionBase::~TransitionBase() -{ - SafeReleaseInterface(&_pPrevLayer); - SafeReleaseInterface(&_pNextLayer); -} - -bool e2d::TransitionBase::isDone() -{ - return _bEnd; -} - -void e2d::TransitionBase::onDestroy() -{ - SafeRelease(&_pPrevScene); - SafeRelease(&_pNextScene); -} - -void e2d::TransitionBase::_init(Scene * prev, Scene * next) -{ - // 创建图层 - HRESULT hr = Renderer::getRenderTarget()->CreateLayer(&_pNextLayer); - - if (SUCCEEDED(hr)) - { - hr = Renderer::getRenderTarget()->CreateLayer(&_pPrevLayer); - } - - if (FAILED(hr)) - { - ASSERT(false, "Create layer failed!"); - } - - _fLast = Time::getTotalTime(); - _pPrevScene = prev; - _pNextScene = next; - if (_pPrevScene) _pPrevScene->retain(); - if (_pNextScene) _pNextScene->retain(); - - _WindowSize = Window::getSize(); - _sPrevLayerParam = _sNextLayerParam = D2D1::LayerParameters(); -} - -void e2d::TransitionBase::_update() -{ - // 计算动画进度 - if (_duration == 0) - { - _delta = 1; - } - else - { - _delta = min((Time::getTotalTime() - _fLast) / _duration, 1); - } - - this->_updateCustom(); - - // 更新场景内容 - if (_pPrevScene) - { - _pPrevScene->_update(); - } - if (_pNextScene) - { - _pNextScene->_update(); - } -} - -void e2d::TransitionBase::_render() -{ - auto pRT = Renderer::getRenderTarget(); - - if (_pPrevScene) - { - Point rootPos = _pPrevScene->getRoot()->getPos(); - auto clipRect = D2D1::RectF( - float(max(rootPos.x, 0)), - float(max(rootPos.y, 0)), - float(min(rootPos.x + _WindowSize.width, _WindowSize.width)), - float(min(rootPos.y + _WindowSize.height, _WindowSize.height)) - ); - pRT->SetTransform(D2D1::Matrix3x2F::Identity()); - pRT->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); - pRT->PushLayer(_sPrevLayerParam, _pPrevLayer); - - // 渲染场景 - _pPrevScene->_render(); - - pRT->PopLayer(); - pRT->PopAxisAlignedClip(); - } - - if (_pNextScene) - { - Point rootPos = _pNextScene->getRoot()->getPos(); - auto clipRect = D2D1::RectF( - float(max(rootPos.x, 0)), - float(max(rootPos.y, 0)), - float(min(rootPos.x + _WindowSize.width, _WindowSize.width)), - float(min(rootPos.y + _WindowSize.height, _WindowSize.height)) - ); - pRT->SetTransform(D2D1::Matrix3x2F::Identity()); - pRT->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); - pRT->PushLayer(_sNextLayerParam, _pNextLayer); - - // 渲染场景 - _pNextScene->_render(); - - pRT->PopLayer(); - pRT->PopAxisAlignedClip(); - } -} - -void e2d::TransitionBase::_stop() -{ - _bEnd = true; - _reset(); -} diff --git a/core/Transition/TransitionEmerge.cpp b/core/Transition/TransitionEmerge.cpp index 4a1a1832..cf7a60ce 100644 --- a/core/Transition/TransitionEmerge.cpp +++ b/core/Transition/TransitionEmerge.cpp @@ -2,21 +2,21 @@ #include "..\e2dnode.h" e2d::TransitionEmerge::TransitionEmerge(double duration) - : TransitionBase(duration) + : Transition(duration) { } void e2d::TransitionEmerge::_init(Scene * prev, Scene * next) { - TransitionBase::_init(prev, next); - _sPrevLayerParam.opacity = 1; - _sNextLayerParam.opacity = 0; + Transition::_init(prev, next); + _outLayerParam.opacity = 1; + _inLayerParam.opacity = 0; } void e2d::TransitionEmerge::_updateCustom() { - _sPrevLayerParam.opacity = float(1 - _delta); - _sNextLayerParam.opacity = float(_delta); + _outLayerParam.opacity = float(1 - _delta); + _inLayerParam.opacity = float(_delta); if (_delta >= 1) { diff --git a/core/Transition/TransitionFade.cpp b/core/Transition/TransitionFade.cpp index 75ba0b7f..dea004dd 100644 --- a/core/Transition/TransitionFade.cpp +++ b/core/Transition/TransitionFade.cpp @@ -2,53 +2,53 @@ #include "..\e2dnode.h" e2d::TransitionFade::TransitionFade(double duration) - : TransitionBase(0) - , _fFadeOutDuration(max(duration / 2, 0)) - , _fFadeInDuration(max(duration / 2, 0)) - , _bFadeOutTransioning(true) + : Transition(0) + , _fadeOutDuration(max(duration / 2, 0)) + , _fadeInDuration(max(duration / 2, 0)) + , _fadeOutTransioning(true) { } e2d::TransitionFade::TransitionFade(double fadeOutDuration, double fadeInDuration) - : TransitionBase(0) - , _fFadeOutDuration(max(fadeOutDuration, 0)) - , _fFadeInDuration(max(fadeInDuration, 0)) - , _bFadeOutTransioning(true) + : Transition(0) + , _fadeOutDuration(max(fadeOutDuration, 0)) + , _fadeInDuration(max(fadeInDuration, 0)) + , _fadeOutTransioning(true) { } void e2d::TransitionFade::_init(Scene * prev, Scene * next) { - TransitionBase::_init(prev, next); - if (_pPrevScene) + Transition::_init(prev, next); + if (_outScene) { - _bFadeOutTransioning = true; - _duration = _fFadeOutDuration; + _fadeOutTransioning = true; + _duration = _fadeOutDuration; } else { - _bFadeOutTransioning = false; - _duration = _fFadeInDuration; + _fadeOutTransioning = false; + _duration = _fadeInDuration; } - _sPrevLayerParam.opacity = 1; - _sNextLayerParam.opacity = 0; + _outLayerParam.opacity = 1; + _inLayerParam.opacity = 0; } void e2d::TransitionFade::_updateCustom() { - if (_bFadeOutTransioning) + if (_fadeOutTransioning) { - _sPrevLayerParam.opacity = float(1 - _delta); + _outLayerParam.opacity = float(1 - _delta); if (_delta >= 1) { - _bFadeOutTransioning = false; - _duration = _fFadeInDuration; - _fLast = Time::getTotalTime(); + _fadeOutTransioning = false; + _duration = _fadeInDuration; + _last = Time::getTotalTime(); } } else { - _sNextLayerParam.opacity = float(_delta); + _inLayerParam.opacity = float(_delta); if (_delta >= 1) { this->_stop(); diff --git a/core/Transition/TransitionMove.cpp b/core/Transition/TransitionMove.cpp index 1bb4e2fe..7377cc5e 100644 --- a/core/Transition/TransitionMove.cpp +++ b/core/Transition/TransitionMove.cpp @@ -1,52 +1,52 @@ #include "..\e2dtransition.h" #include "..\e2dnode.h" -e2d::TransitionMove::TransitionMove(double duration, Direct direct) - : TransitionBase(duration) - , _Direct(direct) +e2d::TransitionMove::TransitionMove(double duration, Direction direction) + : Transition(duration) + , _direction(direction) { } void e2d::TransitionMove::_init(Scene * prev, Scene * next) { - TransitionBase::_init(prev, next); + Transition::_init(prev, next); - double width = _WindowSize.width; - double height = _WindowSize.height; - if (_Direct == Direct::UP) + double width = _windowSize.width; + double height = _windowSize.height; + if (_direction == Direction::UP) { - _Vector = Vector(0, -height); - _NextPos = Point(0, height); + _posDelta = Vector(0, -height); + _startPos = Point(0, height); } - else if (_Direct == Direct::DOWN) + else if (_direction == Direction::DOWN) { - _Vector = Vector(0, height); - _NextPos = Point(0, -height); + _posDelta = Vector(0, height); + _startPos = Point(0, -height); } - else if (_Direct == Direct::LEFT) + else if (_direction == Direction::LEFT) { - _Vector = Vector(-width, 0); - _NextPos = Point(width, 0); + _posDelta = Vector(-width, 0); + _startPos = Point(width, 0); } - else if (_Direct == Direct::RIGHT) + else if (_direction == Direction::RIGHT) { - _Vector = Vector(width, 0); - _NextPos = Point(-width, 0); + _posDelta = Vector(width, 0); + _startPos = Point(-width, 0); } - if (_pPrevScene) _pPrevScene->getRoot()->setPos(0, 0); - _pNextScene->getRoot()->setPos(_NextPos); + if (_outScene) _outScene->getRoot()->setPos(0, 0); + _inScene->getRoot()->setPos(_startPos); } void e2d::TransitionMove::_updateCustom() { - if (_pPrevScene) + if (_outScene) { - _pPrevScene->getRoot()->setPos(_Vector * _delta); + _outScene->getRoot()->setPos(_posDelta * _delta); } - if (_pNextScene) + if (_inScene) { - _pNextScene->getRoot()->setPos(_NextPos + _Vector * _delta); + _inScene->getRoot()->setPos(_startPos + _posDelta * _delta); } if (_delta >= 1) @@ -57,7 +57,7 @@ void e2d::TransitionMove::_updateCustom() void e2d::TransitionMove::_reset() { - if (_pPrevScene) _pPrevScene->getRoot()->setPos(0, 0); - _pNextScene->getRoot()->setPos(0, 0); + if (_outScene) _outScene->getRoot()->setPos(0, 0); + _inScene->getRoot()->setPos(0, 0); } diff --git a/core/e2daction.h b/core/e2daction.h index a61575d9..3613e2e5 100644 --- a/core/e2daction.h +++ b/core/e2daction.h @@ -84,7 +84,7 @@ protected: bool _done; bool _initialized; Node * _target; - double _fLast; + double _last; }; diff --git a/core/e2dcollider.h b/core/e2dcollider.h index 0e486181..f0a61593 100644 --- a/core/e2dcollider.h +++ b/core/e2dcollider.h @@ -65,12 +65,12 @@ protected: virtual void _render(); protected: - bool _bEnable; - bool _bIsVisiable; - bool _bAutoResize; - Color _nColor; - Node * _pParentNode; - ID2D1TransformedGeometry * _pTransformedGeometry; + bool _enable; + bool _visiable; + bool _autoResize; + Color _color; + Node * _parentNode; + ID2D1TransformedGeometry * _transformed; }; @@ -113,7 +113,7 @@ protected: virtual void _resize(); protected: - ID2D1RectangleGeometry * _pD2dRectangle; + ID2D1RectangleGeometry * _d2dRectangle; }; @@ -152,7 +152,7 @@ protected: virtual void _resize(); protected: - ID2D1EllipseGeometry * _pD2dCircle; + ID2D1EllipseGeometry * _d2dCircle; }; @@ -193,7 +193,7 @@ protected: virtual void _resize(); protected: - ID2D1EllipseGeometry * _pD2dEllipse; + ID2D1EllipseGeometry * _d2dEllipse; }; } \ No newline at end of file diff --git a/core/e2dcommon.h b/core/e2dcommon.h index 1f6c0576..8cc04ce3 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -11,15 +11,16 @@ namespace e2d { -struct Size; +class Size; // 表示坐标的结构体 -struct Point +class Point { +public: double x; // X 坐标 double y; // Y 坐标 - /* 构造函数 */ +public: Point(); Point(double x, double y); @@ -37,12 +38,13 @@ struct Point typedef Point Vector; // 表示大小的结构体 -struct Size +class Size { +public: double width; // 宽度 double height; // 高度 - /* 构造函数 */ +public: Size(); Size(double width, double height); @@ -311,7 +313,7 @@ protected: double alpha ); -protected: +public: float r; float g; float b; @@ -429,7 +431,7 @@ enum class Cursor : int // 方向 -enum class Direct : int +enum class Direction : int { UP, /* 上 */ DOWN, /* 下 */ @@ -477,8 +479,9 @@ enum class ColliderType : int // 文本样式 -struct TextStyle +class TextStyle { +public: String fontFamily; // 字体 double fontSize; // 字号 Color color; // 颜色 @@ -495,7 +498,7 @@ struct TextStyle double outlineWidth; // 描边线宽 LineJoin outlineJoin; // 描边线相交样式 - /* 构造函数 */ +public: TextStyle(); TextStyle( @@ -593,7 +596,7 @@ public: virtual void onDestroy() {} private: - int _nRefCount; + int _refCount; }; @@ -701,24 +704,24 @@ public: static void clearCache(); protected: - double _fSourceCropX; - double _fSourceCropY; - double _fSourceCropWidth; - double _fSourceCropHeight; - ID2D1Bitmap * _pBitmap; + double _cropX; + double _cropY; + double _cropWidth; + double _cropHeight; + ID2D1Bitmap * _bitmap; }; class Node; class SceneManager; -class TransitionBase; +class Transition; // 场景 class Scene : public Object { friend SceneManager; - friend TransitionBase; + friend Transition; public: Scene(); @@ -799,11 +802,9 @@ protected: void _update(); protected: - bool _bAutoUpdate; - bool _bSortNeeded; - bool _bWillSave; - bool _bColliderVisiable; - Node * _pRoot; + bool _autoUpdate; + bool _colliderVisiable; + Node * _root; }; diff --git a/core/e2dmanager.h b/core/e2dmanager.h index b9d47729..9430bb96 100644 --- a/core/e2dmanager.h +++ b/core/e2dmanager.h @@ -13,7 +13,7 @@ class Timer; class Action; class Music; class Collider; -class TransitionBase; +class Transition; // 对象管理器 class ObjectManager @@ -49,13 +49,13 @@ public: // 切换场景 static void enter( Scene * scene, /* 下一个场景的指针 */ - TransitionBase * transition = nullptr, /* 场景切换动画 */ + Transition * transition = nullptr, /* 场景切换动画 */ bool saveCurrentScene = true /* 是否保存当前场景 */ ); // 返回上一场景 static void back( - TransitionBase * transition = nullptr /* 场景切换动画 */ + Transition * transition = nullptr /* 场景切换动画 */ ); // 清空保存的所有场景 diff --git a/core/e2dnode.h b/core/e2dnode.h index 9b87ceef..2e75341d 100644 --- a/core/e2dnode.h +++ b/core/e2dnode.h @@ -6,7 +6,7 @@ namespace e2d class Action; -class TransitionBase; +class Transition; class Collider; class ColliderManager; @@ -15,7 +15,7 @@ class Node : { friend Scene; friend Collider; - friend TransitionBase; + friend Transition; friend ColliderManager; public: @@ -443,33 +443,33 @@ protected: protected: String _name; - unsigned _nHashName; - float _fPosX; - float _fPosY; - float _fWidth; - float _fHeight; - float _fScaleX; - float _fScaleY; - float _fRotation; - float _fSkewAngleX; - float _fSkewAngleY; - float _fDisplayOpacity; - float _fRealOpacity; - float _fPivotX; - float _fPivotY; + unsigned _hashName; + float _posX; + float _posY; + float _width; + float _height; + float _scaleX; + float _scaleY; + float _rotation; + float _skewAngleX; + float _skewAngleY; + float _displayOpacity; + float _realOpacity; + float _pivotX; + float _pivotY; int _nOrder; - bool _bVisiable; - bool _bAutoUpdate; - bool _bSortChildrenNeeded; - bool _bTransformNeeded; - bool _bPositionFixed; - Collider * _pCollider; - Scene * _pParentScene; - Node * _pParent; - D2D1::Matrix3x2F _MatriInitial; - D2D1::Matrix3x2F _MatriFinal; - std::set _vColliders; - std::vector _vChildren; + bool _visiable; + bool _autoUpdate; + bool _needSort; + bool _needTransform; + bool _positionFixed; + Collider * _collider; + Scene * _parentScene; + Node * _parent; + D2D1::Matrix3x2F _initialMatri; + D2D1::Matrix3x2F _finalMatri; + std::set _colliders; + std::vector _children; }; @@ -551,7 +551,7 @@ public: virtual void onDestroy() override; protected: - Image * _pImage; + Image * _image; }; @@ -735,10 +735,10 @@ protected: void _createLayout(); protected: - String _sText; - TextStyle _TextStyle; - IDWriteTextFormat * _pDWriteTextFormat; - IDWriteTextLayout * _pDWriteTextLayout; + String _text; + TextStyle _style; + IDWriteTextFormat * _textFormat; + IDWriteTextLayout * _textLayout; }; @@ -829,13 +829,13 @@ protected: virtual void _runCallback(); protected: - Node * _pNormal; - Node * _pMouseover; - Node * _pSelected; - Node * _pDisabled; - bool _bEnable; - bool _bIsSelected; - ButtonState _eBtnState; + Node * _normal; + Node * _mouseover; + Node * _selected; + Node * _disabled; + bool _enable; + bool _isSelected; + ButtonState _state; Function _func; }; @@ -943,15 +943,11 @@ protected: virtual void _runCallback() override; protected: - Node * _pNormalOn; - Node * _pNormalOff; - Node * _pMouseoverOn; - Node * _pMouseoverOff; - Node * _pSelectedOn; - Node * _pSelectedOff; - Node * _pDisabledOn; - Node * _pDisabledOff; - bool _bState; + Node * _normalOff; + Node * _mouseoverOff; + Node * _selectedOff; + Node * _disabledOff; + bool _toggle; }; @@ -998,8 +994,8 @@ public: ); protected: - bool _bEnable; - std::vector _vButtons; + bool _enable; + std::vector _buttons; }; } \ No newline at end of file diff --git a/core/e2dshape.h b/core/e2dshape.h index 7c66c985..61672b77 100644 --- a/core/e2dshape.h +++ b/core/e2dshape.h @@ -55,10 +55,10 @@ protected: virtual void _renderFill() = 0; protected: - ShapeStyle _nStyle; - float _fStrokeWidth; - Color _nLineColor; - Color _nFillColor; + ShapeStyle _style; + float _strokeWidth; + Color _lineColor; + Color _fillColor; }; @@ -163,8 +163,8 @@ protected: virtual void _renderFill() override; protected: - float _fRadiusX; - float _fRadiusY; + float _radiusX; + float _radiusY; }; @@ -208,7 +208,7 @@ protected: virtual void _renderFill() override; protected: - float _fRadius; + float _radius; }; @@ -263,8 +263,8 @@ protected: virtual void _renderFill() override; protected: - float _fRadiusX; - float _fRadiusY; + float _radiusX; + float _radiusY; }; } \ No newline at end of file diff --git a/core/e2dtransition.h b/core/e2dtransition.h index b9017553..8597d2c1 100644 --- a/core/e2dtransition.h +++ b/core/e2dtransition.h @@ -6,49 +6,18 @@ namespace e2d class SceneManager; -class TransitionEmerge; -class TransitionFade; -class TransitionMove; - - -// 场景过渡动画生成器 -class Transition -{ -public: - // 创建淡入淡出式的场景切换动画 - static TransitionFade * Fade( - double duration /* 动画持续时长 */ - ); - - // 创建淡入淡出式的场景切换动画 - static TransitionFade * Fade( - double fadeOutDuration, /* 前一场景淡出动画持续时长 */ - double fadeInDuration /* 后一场景淡入动画持续时长 */ - ); - - // 创建浮现式的场景切换动画 - static TransitionEmerge * Emerge( - double duration /* 动画持续时长 */ - ); - - // 创建移动式的场景切换动画 - static TransitionMove * Move( - double duration, /* 动画持续时长 */ - Direct direct = Direct::LEFT /* 场景移动方向 */ - ); -}; // 基础过渡动画 -class TransitionBase : +class Transition : public Object { friend SceneManager; public: - TransitionBase(double duration); + Transition(double duration); - virtual ~TransitionBase(); + virtual ~Transition(); // 场景切换动画是否结束 bool isDone(); @@ -79,22 +48,22 @@ protected: virtual void _stop(); protected: - bool _bEnd; - double _fLast; + bool _end; + double _last; double _duration; double _delta; - Size _WindowSize; - Scene * _pPrevScene; - Scene * _pNextScene; - ID2D1Layer * _pPrevLayer; - ID2D1Layer * _pNextLayer; - D2D1_LAYER_PARAMETERS _sPrevLayerParam; - D2D1_LAYER_PARAMETERS _sNextLayerParam; + Size _windowSize; + Scene * _outScene; + Scene * _inScene; + ID2D1Layer * _outLayer; + ID2D1Layer * _inLayer; + D2D1_LAYER_PARAMETERS _outLayerParam; + D2D1_LAYER_PARAMETERS _inLayerParam; }; class TransitionFade : - public TransitionBase + public Transition { public: // 创建淡入淡出式的场景切换动画 @@ -120,14 +89,14 @@ protected: virtual void _reset() override; protected: - double _fFadeOutDuration; - double _fFadeInDuration; - bool _bFadeOutTransioning; + double _fadeOutDuration; + double _fadeInDuration; + bool _fadeOutTransioning; }; class TransitionEmerge : - public TransitionBase + public Transition { public: // 创建浮现式的场景切换动画 @@ -149,13 +118,13 @@ protected: class TransitionMove : - public TransitionBase + public Transition { public: // 创建移动式的场景切换动画 TransitionMove( - double moveDuration, /* 场景移动动画持续时长 */ - Direct direct = Direct::LEFT /* 场景移动方向 */ + double moveDuration, /* 场景移动动画持续时长 */ + Direction direction = Direction::LEFT /* 场景移动方向 */ ); protected: @@ -170,9 +139,9 @@ protected: virtual void _reset() override; protected: - Direct _Direct; - Vector _Vector; - Point _NextPos; + Direction _direction; + Vector _posDelta; + Point _startPos; }; } \ No newline at end of file diff --git a/project/vs2017/Easy2D.vcxproj b/project/vs2017/Easy2D.vcxproj index 3177673c..b790094a 100644 --- a/project/vs2017/Easy2D.vcxproj +++ b/project/vs2017/Easy2D.vcxproj @@ -253,7 +253,6 @@ - diff --git a/project/vs2017/Easy2D.vcxproj.filters b/project/vs2017/Easy2D.vcxproj.filters index a9abc15c..b422979e 100644 --- a/project/vs2017/Easy2D.vcxproj.filters +++ b/project/vs2017/Easy2D.vcxproj.filters @@ -168,12 +168,6 @@ Common - - Transition - - - Transition - Action @@ -216,6 +210,9 @@ Action + + Transition +