细节调整;去除Transition构造器

This commit is contained in:
Nomango 2018-05-09 00:34:15 +08:00
parent 83a90fcb0e
commit 4a62b2a5bf
41 changed files with 1022 additions and 1102 deletions

View File

@ -6,7 +6,7 @@ e2d::Action::Action()
, _done(false) , _done(false)
, _initialized(false) , _initialized(false)
, _target(nullptr) , _target(nullptr)
, _fLast(0) , _last(0)
{ {
ActionManager::__add(this); ActionManager::__add(this);
} }
@ -35,7 +35,7 @@ bool e2d::Action::isRunning()
void e2d::Action::resume() void e2d::Action::resume()
{ {
_running = true; _running = true;
_fLast = Time::getTotalTime(); _last = Time::getTotalTime();
} }
void e2d::Action::pause() void e2d::Action::pause()
@ -78,7 +78,7 @@ void e2d::Action::_init()
{ {
_initialized = true; _initialized = true;
// 记录当前时间 // 记录当前时间
_fLast = Time::getTotalTime(); _last = Time::getTotalTime();
} }
void e2d::Action::_update() void e2d::Action::_update()
@ -93,10 +93,10 @@ void e2d::Action::reset()
{ {
_initialized = false; _initialized = false;
_done = false; _done = false;
_fLast = Time::getTotalTime(); _last = Time::getTotalTime();
} }
void e2d::Action::_resetTime() void e2d::Action::_resetTime()
{ {
_fLast = Time::getTotalTime(); _last = Time::getTotalTime();
} }

View File

@ -22,7 +22,7 @@ void e2d::ActionGradual::_update()
return; return;
} }
// 计算动画进度 // 计算动画进度
_delta = min((Time::getTotalTime() - _fLast) / _duration, 1); _delta = min((Time::getTotalTime() - _last) / _duration, 1);
// 判断动作是否结束 // 判断动作是否结束
if (_delta >= 1) if (_delta >= 1)
{ {

View File

@ -87,10 +87,10 @@ void e2d::Animation::_update()
} }
// 判断时间间隔是否足够 // 判断时间间隔是否足够
while ((Time::getTotalTime() - _fLast) >= _interval) while ((Time::getTotalTime() - _last) >= _interval)
{ {
// 重新记录时间 // 重新记录时间
_fLast += _interval; _last += _interval;
// 加载关键帧 // 加载关键帧
static_cast<Sprite*>(_target)->open(_frames[_frameIndex]); static_cast<Sprite*>(_target)->open(_frames[_frameIndex]);
_frameIndex++; _frameIndex++;

View File

@ -19,7 +19,7 @@ void e2d::Delay::_update()
{ {
Action::_update(); Action::_update();
// 判断时间间隔是否足够 // 判断时间间隔是否足够
if ((Time::getTotalTime() - _fLast) >= _delay) if ((Time::getTotalTime() - _last) >= _delay)
{ {
this->stop(); this->stop();
} }

View File

@ -3,73 +3,73 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::Collider::Collider() e2d::Collider::Collider()
: _bIsVisiable(true) : _visiable(true)
, _nColor(Color::RED, 0.7f) , _color(Color::RED, 0.7f)
, _pParentNode(nullptr) , _parentNode(nullptr)
, _pTransformedGeometry(nullptr) , _transformed(nullptr)
, _bEnable(true) , _enable(true)
, _bAutoResize(true) , _autoResize(true)
{ {
} }
e2d::Collider::~Collider() e2d::Collider::~Collider()
{ {
SafeReleaseInterface(&_pTransformedGeometry); SafeReleaseInterface(&_transformed);
} }
e2d::Node * e2d::Collider::getParentNode() const e2d::Node * e2d::Collider::getParentNode() const
{ {
return _pParentNode; return _parentNode;
} }
e2d::Color e2d::Collider::getColor() const e2d::Color e2d::Collider::getColor() const
{ {
return _nColor; return _color;
} }
void e2d::Collider::setEnable(bool enable) void e2d::Collider::setEnable(bool enable)
{ {
_bEnable = enable; _enable = enable;
} }
void e2d::Collider::setVisiable(bool bVisiable) void e2d::Collider::setVisiable(bool bVisiable)
{ {
_bIsVisiable = bVisiable; _visiable = bVisiable;
} }
void e2d::Collider::setColor(Color color) void e2d::Collider::setColor(Color color)
{ {
_nColor = color; _color = color;
} }
void e2d::Collider::setAutoResize(bool enable) void e2d::Collider::setAutoResize(bool enable)
{ {
_bAutoResize = enable; _autoResize = enable;
} }
void e2d::Collider::_render() void e2d::Collider::_render()
{ {
if (_pTransformedGeometry && _bEnable) if (_transformed && _enable)
{ {
// 获取纯色画刷 // 获取纯色画刷
ID2D1SolidColorBrush * pBrush = Renderer::getSolidColorBrush(); 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 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; D2D1_GEOMETRY_RELATION relation;
_pTransformedGeometry->CompareWithGeometry( _transformed->CompareWithGeometry(
pCollider->_pTransformedGeometry, pCollider->_transformed,
D2D1::Matrix3x2F::Identity(), D2D1::Matrix3x2F::Identity(),
&relation &relation
); );
@ -82,21 +82,21 @@ e2d::Relation e2d::Collider::getRelationWith(Collider * pCollider) const
void e2d::Collider::_transform() void e2d::Collider::_transform()
{ {
if (_pParentNode && _bEnable) if (_parentNode && _enable)
{ {
if (_bAutoResize) if (_autoResize)
{ {
this->_resize(); this->_resize();
} }
// 释放原碰撞体 // 释放原碰撞体
SafeReleaseInterface(&_pTransformedGeometry); SafeReleaseInterface(&_transformed);
// 根据父节点转换几何图形 // 根据父节点转换几何图形
Renderer::getID2D1Factory()->CreateTransformedGeometry( Renderer::getID2D1Factory()->CreateTransformedGeometry(
getD2dGeometry(), getD2dGeometry(),
_pParentNode->_MatriFinal, _parentNode->_finalMatri,
&_pTransformedGeometry &_transformed
); );
ColliderManager::__updateCollider(this); ColliderManager::__updateCollider(this);

View File

@ -2,18 +2,18 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::ColliderCircle::ColliderCircle() e2d::ColliderCircle::ColliderCircle()
: _pD2dCircle(nullptr) : _d2dCircle(nullptr)
{ {
} }
e2d::ColliderCircle::ColliderCircle(Point center, double radius) e2d::ColliderCircle::ColliderCircle(Point center, double radius)
: _pD2dCircle(nullptr) : _d2dCircle(nullptr)
{ {
this->setCircle(center, radius); this->setCircle(center, radius);
} }
e2d::ColliderCircle::ColliderCircle(Node * node) e2d::ColliderCircle::ColliderCircle(Node * node)
: _pD2dCircle(nullptr) : _d2dCircle(nullptr)
{ {
double minSide = min(node->getRealWidth(), node->getRealHeight()); double minSide = min(node->getRealWidth(), node->getRealHeight());
this->setCircle( this->setCircle(
@ -27,33 +27,33 @@ e2d::ColliderCircle::ColliderCircle(Node * node)
e2d::ColliderCircle::~ColliderCircle() e2d::ColliderCircle::~ColliderCircle()
{ {
SafeReleaseInterface(&_pD2dCircle); SafeReleaseInterface(&_d2dCircle);
} }
void e2d::ColliderCircle::setCircle(Point center, double radius) void e2d::ColliderCircle::setCircle(Point center, double radius)
{ {
SafeReleaseInterface(&_pD2dCircle); SafeReleaseInterface(&_d2dCircle);
Renderer::getID2D1Factory()->CreateEllipseGeometry( Renderer::getID2D1Factory()->CreateEllipseGeometry(
D2D1::Ellipse( D2D1::Ellipse(
D2D1::Point2F( D2D1::Point2F(
static_cast<float>(center.x), float(center.x),
static_cast<float>(center.y)), float(center.y)),
static_cast<float>(radius), float(radius),
static_cast<float>(radius)), float(radius)),
&_pD2dCircle &_d2dCircle
); );
} }
void e2d::ColliderCircle::_resize() 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( this->setCircle(
Point( Point(
_pParentNode->getRealWidth() / 2, _parentNode->getRealWidth() / 2,
_pParentNode->getRealHeight() / 2 _parentNode->getRealHeight() / 2
), ),
minSide / 2 minSide / 2
); );
@ -62,5 +62,5 @@ void e2d::ColliderCircle::_resize()
ID2D1EllipseGeometry * e2d::ColliderCircle::getD2dGeometry() const ID2D1EllipseGeometry * e2d::ColliderCircle::getD2dGeometry() const
{ {
return _pD2dCircle; return _d2dCircle;
} }

View File

@ -2,18 +2,18 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::ColliderEllipse::ColliderEllipse() e2d::ColliderEllipse::ColliderEllipse()
: _pD2dEllipse(nullptr) : _d2dEllipse(nullptr)
{ {
} }
e2d::ColliderEllipse::ColliderEllipse(Point center, double radiusX, double radiusY) e2d::ColliderEllipse::ColliderEllipse(Point center, double radiusX, double radiusY)
: _pD2dEllipse(nullptr) : _d2dEllipse(nullptr)
{ {
this->setEllipse(center, radiusX, radiusY); this->setEllipse(center, radiusX, radiusY);
} }
e2d::ColliderEllipse::ColliderEllipse(Node * node) e2d::ColliderEllipse::ColliderEllipse(Node * node)
: _pD2dEllipse(nullptr) : _d2dEllipse(nullptr)
{ {
this->setEllipse( this->setEllipse(
Point( Point(
@ -27,40 +27,40 @@ e2d::ColliderEllipse::ColliderEllipse(Node * node)
e2d::ColliderEllipse::~ColliderEllipse() e2d::ColliderEllipse::~ColliderEllipse()
{ {
SafeReleaseInterface(&_pD2dEllipse); SafeReleaseInterface(&_d2dEllipse);
} }
void e2d::ColliderEllipse::setEllipse(Point center, double radiusX, double radiusY) void e2d::ColliderEllipse::setEllipse(Point center, double radiusX, double radiusY)
{ {
SafeReleaseInterface(&_pD2dEllipse); SafeReleaseInterface(&_d2dEllipse);
Renderer::getID2D1Factory()->CreateEllipseGeometry( Renderer::getID2D1Factory()->CreateEllipseGeometry(
D2D1::Ellipse( D2D1::Ellipse(
D2D1::Point2F( D2D1::Point2F(
static_cast<float>(center.x), float(center.x),
static_cast<float>(center.y)), float(center.y)),
static_cast<float>(radiusX), float(radiusX),
static_cast<float>(radiusY)), float(radiusY)),
&_pD2dEllipse &_d2dEllipse
); );
} }
void e2d::ColliderEllipse::_resize() void e2d::ColliderEllipse::_resize()
{ {
if (_pParentNode && _bEnable) if (_parentNode && _enable)
{ {
this->setEllipse( this->setEllipse(
Point( Point(
_pParentNode->getWidth() / 2, _parentNode->getWidth() / 2,
_pParentNode->getHeight() / 2 _parentNode->getHeight() / 2
), ),
_pParentNode->getWidth() / 2, _parentNode->getWidth() / 2,
_pParentNode->getHeight() / 2 _parentNode->getHeight() / 2
); );
} }
} }
ID2D1EllipseGeometry * e2d::ColliderEllipse::getD2dGeometry() const ID2D1EllipseGeometry * e2d::ColliderEllipse::getD2dGeometry() const
{ {
return _pD2dEllipse; return _d2dEllipse;
} }

View File

@ -2,50 +2,50 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::ColliderRect::ColliderRect() e2d::ColliderRect::ColliderRect()
: _pD2dRectangle(nullptr) : _d2dRectangle(nullptr)
{ {
} }
e2d::ColliderRect::ColliderRect(double x, double y, double width, double height) e2d::ColliderRect::ColliderRect(double x, double y, double width, double height)
: _pD2dRectangle(nullptr) : _d2dRectangle(nullptr)
{ {
this->setRect(x, y, x + width, y + height); this->setRect(x, y, x + width, y + height);
} }
e2d::ColliderRect::ColliderRect(Node * node) e2d::ColliderRect::ColliderRect(Node * node)
: _pD2dRectangle(nullptr) : _d2dRectangle(nullptr)
{ {
this->setRect(0, 0, node->getRealWidth(), node->getRealHeight()); this->setRect(0, 0, node->getRealWidth(), node->getRealHeight());
} }
e2d::ColliderRect::~ColliderRect() e2d::ColliderRect::~ColliderRect()
{ {
SafeReleaseInterface(&_pD2dRectangle); SafeReleaseInterface(&_d2dRectangle);
} }
void e2d::ColliderRect::setRect(double left, double top, double right, double bottom) void e2d::ColliderRect::setRect(double left, double top, double right, double bottom)
{ {
SafeReleaseInterface(&_pD2dRectangle); SafeReleaseInterface(&_d2dRectangle);
Renderer::getID2D1Factory()->CreateRectangleGeometry( Renderer::getID2D1Factory()->CreateRectangleGeometry(
D2D1::RectF( D2D1::RectF(
static_cast<float>(left), float(left),
static_cast<float>(top), float(top),
static_cast<float>(right), float(right),
static_cast<float>(bottom)), float(bottom)),
&_pD2dRectangle &_d2dRectangle
); );
} }
void e2d::ColliderRect::_resize() 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 ID2D1RectangleGeometry * e2d::ColliderRect::getD2dGeometry() const
{ {
return _pD2dRectangle; return _d2dRectangle;
} }

View File

@ -17,18 +17,18 @@ e2d::Color::Color()
} }
e2d::Color::Color(double r, double g, double b) e2d::Color::Color(double r, double g, double b)
: r(static_cast<float>(r)) : r(float(r))
, g(static_cast<float>(g)) , g(float(g))
, b(static_cast<float>(b)) , b(float(b))
, a(static_cast<float>(1)) , a(float(1))
{ {
} }
e2d::Color::Color(double r, double g, double b, double alpha) e2d::Color::Color(double r, double g, double b, double alpha)
: r(static_cast<float>(r)) : r(float(r))
, g(static_cast<float>(g)) , g(float(g))
, b(static_cast<float>(b)) , b(float(b))
, a(static_cast<float>(alpha)) , a(float(alpha))
{ {
} }
@ -44,10 +44,10 @@ e2d::Color::Color(UINT32 rgb, double alpha)
void e2d::Color::_init(UINT32 rgb, double alpha) void e2d::Color::_init(UINT32 rgb, double alpha)
{ {
r = static_cast<float>((rgb & sc_redMask) >> sc_redShift) / 255.f; r = float((rgb & sc_redMask) >> sc_redShift) / 255.f;
g = static_cast<float>((rgb & sc_greenMask) >> sc_greenShift) / 255.f; g = float((rgb & sc_greenMask) >> sc_greenShift) / 255.f;
b = static_cast<float>((rgb & sc_blueMask) >> sc_blueShift) / 255.f; b = float((rgb & sc_blueMask) >> sc_blueShift) / 255.f;
a = static_cast<float>(alpha); a = float(alpha);
} }
D2D1_COLOR_F e2d::Color::toColorF() const D2D1_COLOR_F e2d::Color::toColorF() const

View File

@ -6,35 +6,35 @@ static std::map<int, ID2D1Bitmap*> s_mBitmapsFromResource;
e2d::Image::Image() e2d::Image::Image()
: _pBitmap(nullptr) : _bitmap(nullptr)
, _fSourceCropX(0) , _cropX(0)
, _fSourceCropY(0) , _cropY(0)
, _fSourceCropWidth(0) , _cropWidth(0)
, _fSourceCropHeight(0) , _cropHeight(0)
{ {
} }
e2d::Image::Image(const String& filePath) e2d::Image::Image(const String& filePath)
: _pBitmap(nullptr) : _bitmap(nullptr)
{ {
this->open(filePath); this->open(filePath);
} }
e2d::Image::Image(int resNameId, const String& resType) e2d::Image::Image(int resNameId, const String& resType)
: _pBitmap(nullptr) : _bitmap(nullptr)
{ {
this->open(resNameId, resType); this->open(resNameId, resType);
} }
e2d::Image::Image(const String& filePath, double cropX, double cropY, double cropWidth, double cropHeight) e2d::Image::Image(const String& filePath, double cropX, double cropY, double cropWidth, double cropHeight)
: _pBitmap(nullptr) : _bitmap(nullptr)
{ {
this->open(filePath); this->open(filePath);
this->crop(cropX, cropY, cropWidth, cropHeight); this->crop(cropX, cropY, cropWidth, cropHeight);
} }
e2d::Image::Image(int resNameId, const String& resType, double cropX, double cropY, double cropWidth, double 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->open(resNameId, resType);
this->crop(cropX, cropY, cropWidth, cropHeight); this->crop(cropX, cropY, cropWidth, cropHeight);
@ -57,10 +57,10 @@ bool e2d::Image::open(const String& filePath)
return false; return false;
} }
_pBitmap = s_mBitmapsFromFile.at(filePath.getHashCode()); _bitmap = s_mBitmapsFromFile.at(filePath.getHashCode());
_fSourceCropX = _fSourceCropY = 0; _cropX = _cropY = 0;
_fSourceCropWidth = _pBitmap->GetSize().width; _cropWidth = _bitmap->GetSize().width;
_fSourceCropHeight = _pBitmap->GetSize().height; _cropHeight = _bitmap->GetSize().height;
return true; return true;
} }
@ -72,44 +72,44 @@ bool e2d::Image::open(int resNameId, const String& resType)
return false; return false;
} }
_pBitmap = s_mBitmapsFromResource.at(resNameId); _bitmap = s_mBitmapsFromResource.at(resNameId);
_fSourceCropX = _fSourceCropY = 0; _cropX = _cropY = 0;
_fSourceCropWidth = _pBitmap->GetSize().width; _cropWidth = _bitmap->GetSize().width;
_fSourceCropHeight = _pBitmap->GetSize().height; _cropHeight = _bitmap->GetSize().height;
return true; return true;
} }
void e2d::Image::crop(double x, double y, double width, double height) void e2d::Image::crop(double x, double y, double width, double height)
{ {
if (_pBitmap) if (_bitmap)
{ {
_fSourceCropX = min(max(x, 0), this->getSourceWidth()); _cropX = min(max(x, 0), this->getSourceWidth());
_fSourceCropY = min(max(y, 0), this->getSourceHeight()); _cropY = min(max(y, 0), this->getSourceHeight());
_fSourceCropWidth = min(max(width, 0), this->getSourceWidth() - _fSourceCropX); _cropWidth = min(max(width, 0), this->getSourceWidth() - _cropX);
_fSourceCropHeight = min(max(height, 0), this->getSourceHeight() - _fSourceCropY); _cropHeight = min(max(height, 0), this->getSourceHeight() - _cropY);
} }
} }
double e2d::Image::getWidth() const double e2d::Image::getWidth() const
{ {
return _fSourceCropWidth; return _cropWidth;
} }
double e2d::Image::getHeight() const double e2d::Image::getHeight() const
{ {
return _fSourceCropHeight; return _cropHeight;
} }
e2d::Size e2d::Image::getSize() const e2d::Size e2d::Image::getSize() const
{ {
return Size(_fSourceCropWidth, _fSourceCropHeight); return Size(_cropWidth, _cropHeight);
} }
double e2d::Image::getSourceWidth() const double e2d::Image::getSourceWidth() const
{ {
if (_pBitmap) if (_bitmap)
{ {
return _pBitmap->GetSize().width; return _bitmap->GetSize().width;
} }
else else
{ {
@ -119,9 +119,9 @@ double e2d::Image::getSourceWidth() const
double e2d::Image::getSourceHeight() const double e2d::Image::getSourceHeight() const
{ {
if (_pBitmap) if (_bitmap)
{ {
return _pBitmap->GetSize().height; return _bitmap->GetSize().height;
} }
else else
{ {
@ -131,7 +131,7 @@ double e2d::Image::getSourceHeight() const
e2d::Size e2d::Image::getSourceSize() const e2d::Size e2d::Image::getSourceSize() const
{ {
if (_pBitmap) if (_bitmap)
{ {
return Size(getSourceWidth(), getSourceHeight()); return Size(getSourceWidth(), getSourceHeight());
} }
@ -143,17 +143,17 @@ e2d::Size e2d::Image::getSourceSize() const
double e2d::Image::getCropX() const double e2d::Image::getCropX() const
{ {
return _fSourceCropX; return _cropX;
} }
double e2d::Image::getCropY() const double e2d::Image::getCropY() const
{ {
return _fSourceCropY; return _cropY;
} }
e2d::Point e2d::Image::getCropPos() const e2d::Point e2d::Image::getCropPos() const
{ {
return Point(_fSourceCropX, _fSourceCropY); return Point(_cropX, _cropY);
} }
bool e2d::Image::preload(const String& fileName) bool e2d::Image::preload(const String& fileName)
@ -376,5 +376,5 @@ void e2d::Image::clearCache()
ID2D1Bitmap * e2d::Image::getBitmap() ID2D1Bitmap * e2d::Image::getBitmap()
{ {
return _pBitmap; return _bitmap;
} }

View File

@ -2,7 +2,7 @@
#include "..\e2dmanager.h" #include "..\e2dmanager.h"
e2d::Object::Object() e2d::Object::Object()
: _nRefCount(0) : _refCount(0)
{ {
ObjectManager::__add(this); ObjectManager::__add(this);
} }
@ -14,18 +14,18 @@ e2d::Object::~Object()
// 引用计数加一 // 引用计数加一
void e2d::Object::retain() void e2d::Object::retain()
{ {
_nRefCount++; _refCount++;
} }
// 引用计数减一 // 引用计数减一
void e2d::Object::release() void e2d::Object::release()
{ {
_nRefCount--; _refCount--;
// 通知对象管理池刷新 // 通知对象管理池刷新
ObjectManager::flush(); ObjectManager::flush();
} }
int e2d::Object::getRefCount() const int e2d::Object::getRefCount() const
{ {
return _nRefCount; return _refCount;
} }

View File

@ -3,14 +3,12 @@
#include "..\e2dmanager.h" #include "..\e2dmanager.h"
e2d::Scene::Scene() e2d::Scene::Scene()
: _bWillSave(true) : _autoUpdate(true)
, _bAutoUpdate(true) , _colliderVisiable(false)
, _bSortNeeded(false) , _root(new Node())
, _bColliderVisiable(false)
, _pRoot(new Node())
{ {
_pRoot->retain(); _root->retain();
_pRoot->_setParentScene(this); _root->_setParentScene(this);
} }
e2d::Scene::~Scene() e2d::Scene::~Scene()
@ -19,36 +17,36 @@ e2d::Scene::~Scene()
void e2d::Scene::_render() void e2d::Scene::_render()
{ {
_pRoot->_render(); _root->_render();
if (_bColliderVisiable) if (_colliderVisiable)
{ {
// 恢复矩阵转换 // 恢复矩阵转换
Renderer::getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); Renderer::getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity());
// 绘制所有几何图形 // 绘制所有几何图形
_pRoot->_drawCollider(); _root->_drawCollider();
} }
} }
void e2d::Scene::_update() void e2d::Scene::_update()
{ {
// 执行 onUpdate 函数 // 执行 onUpdate 函数
if (_bAutoUpdate) if (_autoUpdate)
{ {
this->onUpdate(); this->onUpdate();
} }
// 更新根节点 // 更新根节点
_pRoot->_update(); _root->_update();
} }
void e2d::Scene::setAutoUpdate(bool bAutoUpdate) void e2d::Scene::setAutoUpdate(bool bAutoUpdate)
{ {
_bAutoUpdate = bAutoUpdate; _autoUpdate = bAutoUpdate;
} }
void e2d::Scene::add(Node * child, int order /* = 0 */) void e2d::Scene::add(Node * child, int order /* = 0 */)
{ {
_pRoot->addChild(child, order); _root->addChild(child, order);
} }
#ifdef HIGHER_THAN_VS2012 #ifdef HIGHER_THAN_VS2012
@ -63,35 +61,35 @@ void e2d::Scene::add(const std::initializer_list<Node*>& vNodes, int order)
bool e2d::Scene::remove(Node * child) bool e2d::Scene::remove(Node * child)
{ {
return _pRoot->removeChild(child); return _root->removeChild(child);
} }
std::vector<e2d::Node*> e2d::Scene::get(const String& name) const std::vector<e2d::Node*> e2d::Scene::get(const String& name) const
{ {
return _pRoot->getChildren(name); return _root->getChildren(name);
} }
e2d::Node * e2d::Scene::getOne(const String& name) const e2d::Node * e2d::Scene::getOne(const String& name) const
{ {
return _pRoot->getChild(name); return _root->getChild(name);
} }
std::vector<e2d::Node*> e2d::Scene::getAll() const std::vector<e2d::Node*> e2d::Scene::getAll() const
{ {
return _pRoot->getAllChildren(); return _root->getAllChildren();
} }
e2d::Node * e2d::Scene::getRoot() const e2d::Node * e2d::Scene::getRoot() const
{ {
return _pRoot; return _root;
} }
void e2d::Scene::showCollider(bool visiable) void e2d::Scene::showCollider(bool visiable)
{ {
_bColliderVisiable = visiable; _colliderVisiable = visiable;
} }
void e2d::Scene::onDestroy() void e2d::Scene::onDestroy()
{ {
SafeRelease(&_pRoot); SafeRelease(&_root);
} }

View File

@ -191,7 +191,7 @@ bool e2d::String::operator!=(const e2d::String &str)
wchar_t &e2d::String::operator[](int index) wchar_t &e2d::String::operator[](int index)
{ {
return _str[static_cast<size_t>(index)]; return _str[size_t(index)];
} }
e2d::String e2d::String::operator+(const wchar_t *str) 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) void e2d::String::insert(const String & str, int pos)
{ {
_str.insert(static_cast<size_t>(pos), str._str); _str.insert(size_t(pos), str._str);
} }
void e2d::String::replace(const String & from, const String & to) 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) void e2d::String::erase(int offset, int count)
{ {
_str.erase(static_cast<size_t>(offset), static_cast<size_t>(count)); _str.erase(size_t(offset), size_t(count));
} }
int e2d::String::find(const String & str, int offset) const int e2d::String::find(const String & str, int offset) const
{ {
size_t index; size_t index;
if ((index = _str.find(str._str, static_cast<size_t>(offset))) == std::wstring::npos) if ((index = _str.find(str._str, size_t(offset))) == std::wstring::npos)
{ {
return -1; return -1;
} }

View File

@ -81,7 +81,7 @@ void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider)
if (!s_bCollisionEnable) if (!s_bCollisionEnable)
return; return;
Node* pActiveNode = pActiveCollider->_pParentNode; Node* pActiveNode = pActiveCollider->_parentNode;
if (pActiveNode) if (pActiveNode)
{ {
// 获取节点所在场景 // 获取节点所在场景
@ -96,7 +96,7 @@ void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider)
continue; continue;
// 获取被碰撞节点 // 获取被碰撞节点
Node* pPassiveNode = pPassiveCollider->_pParentNode; Node* pPassiveNode = pPassiveCollider->_parentNode;
// 判断两节点是否处于同一场景中 // 判断两节点是否处于同一场景中
if (pPassiveNode && if (pPassiveNode &&
pPassiveNode->getParentScene() == pCurrentScene) pPassiveNode->getParentScene() == pCurrentScene)
@ -105,7 +105,7 @@ void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider)
auto IsCollideWith = [](Node * active, Node * passive) -> bool auto IsCollideWith = [](Node * active, Node * passive) -> bool
{ {
unsigned int hash = passive->getHashName(); unsigned int hash = passive->getHashName();
for (auto collider : active->_vColliders) for (auto collider : active->_colliders)
if (collider == hash) if (collider == hash)
return true; return true;
return false; return false;
@ -228,7 +228,7 @@ void e2d::ColliderManager::__addCollider(Collider * pCollider)
{ {
if (pCollider) if (pCollider)
{ {
if (pCollider->_pParentNode) if (pCollider->_parentNode)
{ {
WARN_IF(true, "ColliderManager::__add Failed! The shape is already added."); WARN_IF(true, "ColliderManager::__add Failed! The shape is already added.");
return; return;

View File

@ -2,12 +2,13 @@
#include "..\e2dbase.h" #include "..\e2dbase.h"
#include "..\e2dtransition.h" #include "..\e2dtransition.h"
static bool s_bSaveCurrScene = true;
static e2d::Scene * s_pCurrScene = nullptr; static e2d::Scene * s_pCurrScene = nullptr;
static e2d::Scene * s_pNextScene = nullptr; static e2d::Scene * s_pNextScene = nullptr;
static e2d::TransitionBase * s_pTransition = nullptr; static e2d::Transition * s_pTransition = nullptr;
static std::stack<e2d::Scene*> s_SceneStack; static std::stack<e2d::Scene*> 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!"); ASSERT(scene, "Next scene NULL pointer exception!");
scene->retain(); scene->retain();
@ -31,11 +32,11 @@ void e2d::SceneManager::enter(Scene * scene, TransitionBase * transition /* = nu
if (s_pCurrScene) 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!"); WARN_IF(s_SceneStack.size() == 0, "Scene stack is empty!");
@ -48,7 +49,7 @@ void e2d::SceneManager::back(TransitionBase * transition /* = nullptr */)
// 返回上一场景时,不保存当前场景 // 返回上一场景时,不保存当前场景
if (s_pCurrScene) if (s_pCurrScene)
{ {
s_pCurrScene->_bWillSave = false; s_bSaveCurrScene = false;
} }
// 设置切换场景动画 // 设置切换场景动画
@ -120,7 +121,7 @@ void e2d::SceneManager::__update()
s_pCurrScene->onExit(); s_pCurrScene->onExit();
// 若要保存当前场景,把它放入栈中 // 若要保存当前场景,把它放入栈中
if (s_pCurrScene->_bWillSave) if (s_bSaveCurrScene)
{ {
s_SceneStack.push(s_pCurrScene); s_SceneStack.push(s_pCurrScene);
} }

View File

@ -6,25 +6,25 @@
e2d::Button::Button() e2d::Button::Button()
: _func(nullptr) : _func(nullptr)
, _eBtnState(ButtonState::NORMAL) , _state(ButtonState::NORMAL)
, _bEnable(true) , _enable(true)
, _bIsSelected(false) , _isSelected(false)
, _pNormal(nullptr) , _normal(nullptr)
, _pMouseover(nullptr) , _mouseover(nullptr)
, _pSelected(nullptr) , _selected(nullptr)
, _pDisabled(nullptr) , _disabled(nullptr)
{ {
} }
e2d::Button::Button(Node * normal, const Function& func) e2d::Button::Button(Node * normal, const Function& func)
: _func(nullptr) : _func(nullptr)
, _eBtnState(ButtonState::NORMAL) , _state(ButtonState::NORMAL)
, _bEnable(true) , _enable(true)
, _bIsSelected(false) , _isSelected(false)
, _pNormal(nullptr) , _normal(nullptr)
, _pMouseover(nullptr) , _mouseover(nullptr)
, _pSelected(nullptr) , _selected(nullptr)
, _pDisabled(nullptr) , _disabled(nullptr)
{ {
this->setNormal(normal); this->setNormal(normal);
this->setClickFunc(func); 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) e2d::Button::Button(Node * normal, Node * selected, const Function& func)
: _func(nullptr) : _func(nullptr)
, _eBtnState(ButtonState::NORMAL) , _state(ButtonState::NORMAL)
, _bEnable(true) , _enable(true)
, _bIsSelected(false) , _isSelected(false)
, _pNormal(nullptr) , _normal(nullptr)
, _pMouseover(nullptr) , _mouseover(nullptr)
, _pSelected(nullptr) , _selected(nullptr)
, _pDisabled(nullptr) , _disabled(nullptr)
{ {
this->setNormal(normal); this->setNormal(normal);
this->setSelected(selected); 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) e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Function& func)
: _func(nullptr) : _func(nullptr)
, _eBtnState(ButtonState::NORMAL) , _state(ButtonState::NORMAL)
, _bEnable(true) , _enable(true)
, _bIsSelected(false) , _isSelected(false)
, _pNormal(nullptr) , _normal(nullptr)
, _pMouseover(nullptr) , _mouseover(nullptr)
, _pSelected(nullptr) , _selected(nullptr)
, _pDisabled(nullptr) , _disabled(nullptr)
{ {
this->setNormal(normal); this->setNormal(normal);
this->setMouseOver(mouseover); 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) e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Function& func)
: _func(nullptr) : _func(nullptr)
, _eBtnState(ButtonState::NORMAL) , _state(ButtonState::NORMAL)
, _bEnable(true) , _enable(true)
, _bIsSelected(false) , _isSelected(false)
, _pNormal(nullptr) , _normal(nullptr)
, _pMouseover(nullptr) , _mouseover(nullptr)
, _pSelected(nullptr) , _selected(nullptr)
, _pDisabled(nullptr) , _disabled(nullptr)
{ {
this->setNormal(normal); this->setNormal(normal);
this->setMouseOver(mouseover); this->setMouseOver(mouseover);
@ -80,17 +80,17 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * dis
bool e2d::Button::isEnable() const bool e2d::Button::isEnable() const
{ {
return _bEnable; return _enable;
} }
void e2d::Button::setNormal(Node * normal) void e2d::Button::setNormal(Node * normal)
{ {
if (normal != _pNormal) if (normal != _normal)
{ {
// 移除旧的 // 移除旧的
if (_pNormal) if (_normal)
{ {
this->removeChild(_pNormal); this->removeChild(_normal);
} }
// 添加新的 // 添加新的
if (normal) if (normal)
@ -98,7 +98,7 @@ void e2d::Button::setNormal(Node * normal)
this->addChild(normal); this->addChild(normal);
this->setSize(normal->getWidth(), normal->getHeight()); this->setSize(normal->getWidth(), normal->getHeight());
} }
_pNormal = normal; _normal = normal;
_updateVisiable(); _updateVisiable();
} }
@ -106,73 +106,73 @@ void e2d::Button::setNormal(Node * normal)
void e2d::Button::setMouseOver(Node * mouseover) void e2d::Button::setMouseOver(Node * mouseover)
{ {
if (mouseover != _pNormal) if (mouseover != _normal)
{ {
// 移除旧的 // 移除旧的
if (_pMouseover) if (_mouseover)
{ {
this->removeChild(_pMouseover); this->removeChild(_mouseover);
} }
// 添加新的 // 添加新的
if (mouseover) if (mouseover)
{ {
this->addChild(mouseover); this->addChild(mouseover);
} }
_pMouseover = mouseover; _mouseover = mouseover;
_updateVisiable(); _updateVisiable();
} }
} }
void e2d::Button::setSelected(Node * selected) void e2d::Button::setSelected(Node * selected)
{ {
if (selected != _pNormal) if (selected != _normal)
{ {
// 移除旧的 // 移除旧的
if (_pSelected) if (_selected)
{ {
this->removeChild(_pSelected); this->removeChild(_selected);
} }
// 添加新的 // 添加新的
if (selected) if (selected)
{ {
this->addChild(selected); this->addChild(selected);
} }
_pSelected = selected; _selected = selected;
_updateVisiable(); _updateVisiable();
} }
} }
void e2d::Button::setDisabled(Node * disabled) void e2d::Button::setDisabled(Node * disabled)
{ {
if (disabled != _pNormal) if (disabled != _normal)
{ {
// 移除旧的 // 移除旧的
if (_pDisabled) if (_disabled)
{ {
this->removeChild(_pDisabled); this->removeChild(_disabled);
} }
// 添加新的 // 添加新的
if (disabled) if (disabled)
{ {
this->addChild(disabled); this->addChild(disabled);
} }
_pDisabled = disabled; _disabled = disabled;
_updateVisiable(); _updateVisiable();
} }
} }
void e2d::Button::setEnable(bool enable) void e2d::Button::setEnable(bool enable)
{ {
if (_bEnable != enable) if (_enable != enable)
{ {
_bEnable = enable; _enable = enable;
_updateVisiable(); _updateVisiable();
} }
} }
void e2d::Button::setClickFunc(const Function& func) 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; _func = func;
} }
@ -182,40 +182,40 @@ void e2d::Button::onFixedUpdate()
if (SceneManager::isTransitioning()) if (SceneManager::isTransitioning())
return; return;
if (_bEnable && _bVisiable && _pNormal) if (_enable && _visiable && _normal)
{ {
if (Input::isMouseLButtonRelease()) if (Input::isMouseLButtonRelease())
{ {
// 鼠标左键抬起时,判断鼠标坐标是否在按钮内部 // 鼠标左键抬起时,判断鼠标坐标是否在按钮内部
if (_bIsSelected && if (_isSelected &&
_pNormal->isPointIn(Input::getMousePos())) _normal->isPointIn(Input::getMousePos()))
{ {
_runCallback(); _runCallback();
} }
// 标记 _bIsSelected 为 false // 标记 _isSelected 为 false
_bIsSelected = false; _isSelected = false;
} }
if (Input::isMouseLButtonPress()) if (Input::isMouseLButtonPress())
{ {
if (_pNormal->isPointIn(Input::getMousePos())) if (_normal->isPointIn(Input::getMousePos()))
{ {
// 鼠标左键按下,且位于按钮内时,标记 _bIsSelected 为 true // 鼠标左键按下,且位于按钮内时,标记 _isSelected 为 true
_bIsSelected = true; _isSelected = true;
return; return;
} }
} }
if (_bIsSelected && Input::isMouseLButtonDown()) if (_isSelected && Input::isMouseLButtonDown())
{ {
if (_pNormal->isPointIn(Input::getMousePos())) if (_normal->isPointIn(Input::getMousePos()))
{ {
_setState(ButtonState::SELECTED); _setState(ButtonState::SELECTED);
Window::setCursor(Cursor::HAND); Window::setCursor(Cursor::HAND);
return; return;
} }
} }
else if (_pNormal->isPointIn(Input::getMousePos())) else if (_normal->isPointIn(Input::getMousePos()))
{ {
_setState(ButtonState::MOUSEOVER); _setState(ButtonState::MOUSEOVER);
Window::setCursor(Cursor::HAND); Window::setCursor(Cursor::HAND);
@ -225,7 +225,7 @@ void e2d::Button::onFixedUpdate()
_setState(ButtonState::NORMAL); _setState(ButtonState::NORMAL);
} }
if (_bVisiable && !_bEnable && _pNormal && _pNormal->isPointIn(Input::getMousePos())) if (_visiable && !_enable && _normal && _normal->isPointIn(Input::getMousePos()))
{ {
Window::setCursor(Cursor::NO); Window::setCursor(Cursor::NO);
} }
@ -233,44 +233,44 @@ void e2d::Button::onFixedUpdate()
void e2d::Button::_setState(ButtonState state) void e2d::Button::_setState(ButtonState state)
{ {
if (_eBtnState != state) if (_state != state)
{ {
_eBtnState = state; _state = state;
_updateVisiable(); _updateVisiable();
} }
} }
void e2d::Button::_updateVisiable() void e2d::Button::_updateVisiable()
{ {
SAFE_SET(_pNormal, setVisiable, false); SAFE_SET(_normal, setVisiable, false);
SAFE_SET(_pMouseover, setVisiable, false); SAFE_SET(_mouseover, setVisiable, false);
SAFE_SET(_pSelected, setVisiable, false); SAFE_SET(_selected, setVisiable, false);
SAFE_SET(_pDisabled, 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 else
{ {
if (_pNormal) _pNormal->setVisiable(true); if (_normal) _normal->setVisiable(true);
} }
} }
else else
{ {
if (_pDisabled) if (_disabled)
{ {
_pDisabled->setVisiable(true); _disabled->setVisiable(true);
} }
else else
{ {
if (_pNormal) _pNormal->setVisiable(true); if (_normal) _normal->setVisiable(true);
} }
} }
} }

View File

@ -2,29 +2,21 @@
e2d::ButtonToggle::ButtonToggle() e2d::ButtonToggle::ButtonToggle()
: Button() : Button()
, _bState(true) , _toggle(true)
, _pNormalOn(nullptr) , _normalOff(nullptr)
, _pMouseoverOn(nullptr) , _mouseoverOff(nullptr)
, _pSelectedOn(nullptr) , _selectedOff(nullptr)
, _pDisabledOn(nullptr) , _disabledOff(nullptr)
, _pNormalOff(nullptr)
, _pMouseoverOff(nullptr)
, _pSelectedOff(nullptr)
, _pDisabledOff(nullptr)
{ {
} }
e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, const Function& func) e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, const Function& func)
: Button() : Button()
, _bState(true) , _toggle(true)
, _pNormalOn(nullptr) , _normalOff(nullptr)
, _pMouseoverOn(nullptr) , _mouseoverOff(nullptr)
, _pSelectedOn(nullptr) , _selectedOff(nullptr)
, _pDisabledOn(nullptr) , _disabledOff(nullptr)
, _pNormalOff(nullptr)
, _pMouseoverOff(nullptr)
, _pSelectedOff(nullptr)
, _pDisabledOff(nullptr)
{ {
this->setNormal(toggleOnNormal); this->setNormal(toggleOnNormal);
this->setNormalOff(toggleOffNormal); 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) e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func)
: Button() : Button()
, _bState(true) , _toggle(true)
, _pNormalOn(nullptr) , _normalOff(nullptr)
, _pMouseoverOn(nullptr) , _mouseoverOff(nullptr)
, _pSelectedOn(nullptr) , _selectedOff(nullptr)
, _pDisabledOn(nullptr) , _disabledOff(nullptr)
, _pNormalOff(nullptr)
, _pMouseoverOff(nullptr)
, _pSelectedOff(nullptr)
, _pDisabledOff(nullptr)
{ {
this->setNormal(toggleOnNormal); this->setNormal(toggleOnNormal);
this->setNormalOff(toggleOffNormal); 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) e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func)
: Button() : Button()
, _bState(true) , _toggle(true)
, _pNormalOn(nullptr) , _normalOff(nullptr)
, _pMouseoverOn(nullptr) , _mouseoverOff(nullptr)
, _pSelectedOn(nullptr) , _selectedOff(nullptr)
, _pDisabledOn(nullptr) , _disabledOff(nullptr)
, _pNormalOff(nullptr)
, _pMouseoverOff(nullptr)
, _pSelectedOff(nullptr)
, _pDisabledOff(nullptr)
{ {
this->setNormal(toggleOnNormal); this->setNormal(toggleOnNormal);
this->setNormalOff(toggleOffNormal); 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) e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, Node * toggleOnDisabled, Node * toggleOffDisabled, const Function& func)
: Button() : Button()
, _bState(true) , _toggle(true)
, _pNormalOn(nullptr) , _normalOff(nullptr)
, _pMouseoverOn(nullptr) , _mouseoverOff(nullptr)
, _pSelectedOn(nullptr) , _selectedOff(nullptr)
, _pDisabledOn(nullptr) , _disabledOff(nullptr)
, _pNormalOff(nullptr)
, _pMouseoverOff(nullptr)
, _pSelectedOff(nullptr)
, _pDisabledOff(nullptr)
{ {
this->setNormal(toggleOnNormal); this->setNormal(toggleOnNormal);
this->setNormalOff(toggleOffNormal); this->setNormalOff(toggleOffNormal);
@ -96,14 +76,14 @@ e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, N
bool e2d::ButtonToggle::getState() const bool e2d::ButtonToggle::getState() const
{ {
return _bState; return _toggle;
} }
void e2d::ButtonToggle::setState(bool bState) void e2d::ButtonToggle::setState(bool bState)
{ {
if (_bState != bState) if (_toggle != bState)
{ {
_bState = bState; _toggle = bState;
_updateState(); _updateState();
_updateVisiable(); _updateVisiable();
} }
@ -111,12 +91,12 @@ void e2d::ButtonToggle::setState(bool bState)
void e2d::ButtonToggle::setNormal(Node * normal) void e2d::ButtonToggle::setNormal(Node * normal)
{ {
if (normal != _pNormalOn) if (normal != _normal)
{ {
// 移除旧的 // 移除旧的
if (_pNormalOn) if (_normal)
{ {
this->removeChild(_pNormalOn); this->removeChild(_normal);
} }
// 添加新的 // 添加新的
if (normal) if (normal)
@ -124,7 +104,7 @@ void e2d::ButtonToggle::setNormal(Node * normal)
this->addChild(normal); this->addChild(normal);
this->setSize(normal->getWidth(), normal->getHeight()); this->setSize(normal->getWidth(), normal->getHeight());
} }
_pNormalOn = normal; _normal = normal;
_updateState(); _updateState();
_updateVisiable(); _updateVisiable();
@ -133,19 +113,19 @@ void e2d::ButtonToggle::setNormal(Node * normal)
void e2d::ButtonToggle::setMouseOver(Node * mouseover) void e2d::ButtonToggle::setMouseOver(Node * mouseover)
{ {
if (mouseover != _pMouseoverOn) if (mouseover != _mouseover)
{ {
// 移除旧的 // 移除旧的
if (_pMouseoverOn) if (_mouseover)
{ {
this->removeChild(_pMouseoverOn); this->removeChild(_mouseover);
} }
// 添加新的 // 添加新的
if (mouseover) if (mouseover)
{ {
this->addChild(mouseover); this->addChild(mouseover);
} }
_pMouseoverOn = mouseover; _mouseover = mouseover;
_updateState(); _updateState();
_updateVisiable(); _updateVisiable();
@ -154,19 +134,19 @@ void e2d::ButtonToggle::setMouseOver(Node * mouseover)
void e2d::ButtonToggle::setSelected(Node * selected) void e2d::ButtonToggle::setSelected(Node * selected)
{ {
if (selected != _pSelectedOn) if (selected != _selected)
{ {
// 移除旧的 // 移除旧的
if (_pSelectedOn) if (_selected)
{ {
this->removeChild(_pSelectedOn); this->removeChild(_selected);
} }
// 添加新的 // 添加新的
if (selected) if (selected)
{ {
this->addChild(selected); this->addChild(selected);
} }
_pSelectedOn = selected; _selected = selected;
_updateState(); _updateState();
_updateVisiable(); _updateVisiable();
@ -175,19 +155,19 @@ void e2d::ButtonToggle::setSelected(Node * selected)
void e2d::ButtonToggle::setDisabled(Node * disabled) void e2d::ButtonToggle::setDisabled(Node * disabled)
{ {
if (disabled != _pDisabledOn) if (disabled != _disabled)
{ {
// 移除旧的 // 移除旧的
if (_pDisabledOn) if (_disabled)
{ {
this->removeChild(_pDisabledOn); this->removeChild(_disabled);
} }
// 添加新的 // 添加新的
if (disabled) if (disabled)
{ {
this->addChild(disabled); this->addChild(disabled);
} }
_pDisabledOn = disabled; _disabled = disabled;
_updateState(); _updateState();
_updateVisiable(); _updateVisiable();
@ -196,19 +176,19 @@ void e2d::ButtonToggle::setDisabled(Node * disabled)
void e2d::ButtonToggle::setNormalOff(Node * normal) void e2d::ButtonToggle::setNormalOff(Node * normal)
{ {
if (normal != _pNormalOff) if (normal != _normalOff)
{ {
// 移除旧的 // 移除旧的
if (_pNormalOff) if (_normalOff)
{ {
this->removeChild(_pNormalOff); this->removeChild(_normalOff);
} }
// 添加新的 // 添加新的
if (normal) if (normal)
{ {
this->addChild(normal); this->addChild(normal);
} }
_pNormalOff = normal; _normalOff = normal;
_updateState(); _updateState();
_updateVisiable(); _updateVisiable();
@ -217,19 +197,19 @@ void e2d::ButtonToggle::setNormalOff(Node * normal)
void e2d::ButtonToggle::setMouseOverOff(Node * mouseover) void e2d::ButtonToggle::setMouseOverOff(Node * mouseover)
{ {
if (mouseover != _pMouseoverOff) if (mouseover != _mouseoverOff)
{ {
// 移除旧的 // 移除旧的
if (_pMouseoverOff) if (_mouseoverOff)
{ {
this->removeChild(_pMouseoverOff); this->removeChild(_mouseoverOff);
} }
// 添加新的 // 添加新的
if (mouseover) if (mouseover)
{ {
this->addChild(mouseover); this->addChild(mouseover);
} }
_pMouseoverOff = mouseover; _mouseoverOff = mouseover;
_updateState(); _updateState();
_updateVisiable(); _updateVisiable();
@ -238,19 +218,19 @@ void e2d::ButtonToggle::setMouseOverOff(Node * mouseover)
void e2d::ButtonToggle::setSelectedOff(Node * selected) void e2d::ButtonToggle::setSelectedOff(Node * selected)
{ {
if (selected != _pSelectedOff) if (selected != _selectedOff)
{ {
// 移除旧的 // 移除旧的
if (_pSelectedOff) if (_selectedOff)
{ {
this->removeChild(_pSelectedOff); this->removeChild(_selectedOff);
} }
// 添加新的 // 添加新的
if (selected) if (selected)
{ {
this->addChild(selected); this->addChild(selected);
} }
_pSelectedOff = selected; _selectedOff = selected;
_updateState(); _updateState();
_updateVisiable(); _updateVisiable();
@ -259,19 +239,19 @@ void e2d::ButtonToggle::setSelectedOff(Node * selected)
void e2d::ButtonToggle::setDisabledOff(Node * disabled) void e2d::ButtonToggle::setDisabledOff(Node * disabled)
{ {
if (disabled != _pDisabledOff) if (disabled != _disabledOff)
{ {
// 移除旧的 // 移除旧的
if (_pDisabledOff) if (_disabledOff)
{ {
this->removeChild(_pDisabledOff); this->removeChild(_disabledOff);
} }
// 添加新的 // 添加新的
if (disabled) if (disabled)
{ {
this->addChild(disabled); this->addChild(disabled);
} }
_pDisabledOff = disabled; _disabledOff = disabled;
_updateState(); _updateState();
_updateVisiable(); _updateVisiable();
@ -280,35 +260,35 @@ void e2d::ButtonToggle::setDisabledOff(Node * disabled)
void e2d::ButtonToggle::_updateState() void e2d::ButtonToggle::_updateState()
{ {
if (_bState) if (_toggle)
{ {
_pNormal = _pNormalOn; _normal = _normal;
_pMouseover = _pMouseoverOn; _mouseover = _mouseover;
_pSelected = _pSelectedOn; _selected = _selected;
_pDisabled = _pDisabledOn; _disabled = _disabled;
if (_pNormalOff) _pNormalOff->setVisiable(false); if (_normalOff) _normalOff->setVisiable(false);
if (_pMouseoverOff) _pMouseoverOff->setVisiable(false); if (_mouseoverOff) _mouseoverOff->setVisiable(false);
if (_pSelectedOff) _pSelectedOff->setVisiable(false); if (_selectedOff) _selectedOff->setVisiable(false);
if (_pDisabledOff) _pDisabledOff->setVisiable(false); if (_disabledOff) _disabledOff->setVisiable(false);
} }
else else
{ {
_pNormal = _pNormalOff; _normal = _normalOff;
_pMouseover = _pMouseoverOff; _mouseover = _mouseoverOff;
_pSelected = _pSelectedOff; _selected = _selectedOff;
_pDisabled = _pDisabledOff; _disabled = _disabledOff;
if (_pNormalOn) _pNormalOn->setVisiable(false); if (_normal) _normal->setVisiable(false);
if (_pMouseoverOn) _pMouseoverOn->setVisiable(false); if (_mouseover) _mouseover->setVisiable(false);
if (_pSelectedOn) _pSelectedOn->setVisiable(false); if (_selected) _selected->setVisiable(false);
if (_pDisabledOn) _pDisabledOn->setVisiable(false); if (_disabled) _disabled->setVisiable(false);
} }
} }
void e2d::ButtonToggle::_runCallback() void e2d::ButtonToggle::_runCallback()
{ {
_bState = !_bState; _toggle = !_toggle;
_updateState(); _updateState();
if (_func) if (_func)

View File

@ -1,13 +1,13 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::Menu::Menu() e2d::Menu::Menu()
: _bEnable(true) : _enable(true)
{ {
} }
#ifdef HIGHER_THAN_VS2012 #ifdef HIGHER_THAN_VS2012
e2d::Menu::Menu(const std::initializer_list<Button*>& vButtons) e2d::Menu::Menu(const std::initializer_list<Button*>& vButtons)
: _bEnable(true) : _enable(true)
{ {
for (auto button : vButtons) for (auto button : vButtons)
{ {
@ -18,7 +18,7 @@ e2d::Menu::Menu(const std::initializer_list<Button*>& vButtons)
#else #else
e2d::Menu::Menu(int number, Button * button1, ...) e2d::Menu::Menu(int number, Button * button1, ...)
: _bEnable(true) : _enable(true)
{ {
Button ** ppButton = &button1; Button ** ppButton = &button1;
@ -33,21 +33,21 @@ e2d::Menu::Menu(int number, Button * button1, ...)
bool e2d::Menu::isEnable() const bool e2d::Menu::isEnable() const
{ {
return _bEnable; return _enable;
} }
size_t e2d::Menu::getButtonCount() const size_t e2d::Menu::getButtonCount() const
{ {
return _vButtons.size(); return _buttons.size();
} }
void e2d::Menu::setEnable(bool enable) 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); button->setEnable(enable);
} }
@ -59,14 +59,14 @@ void e2d::Menu::addButton(Button * button)
if (button) if (button)
{ {
this->addChild(button); this->addChild(button);
_vButtons.push_back(button); _buttons.push_back(button);
button->setEnable(_bEnable); button->setEnable(_enable);
} }
} }
bool e2d::Menu::removeButton(Button * button) bool e2d::Menu::removeButton(Button * button)
{ {
if (_vButtons.empty()) if (_buttons.empty())
{ {
return false; return false;
} }
@ -75,14 +75,14 @@ bool e2d::Menu::removeButton(Button * button)
if (button) if (button)
{ {
size_t size = _vButtons.size(); size_t size = _buttons.size();
for (size_t i = 0; i < size; i++) for (size_t i = 0; i < size; i++)
{ {
if (_vButtons[i] == button) if (_buttons[i] == button)
{ {
// ÒÆ³ý°´Å¥Ç°£¬½«ËüÆôÓà // ÒÆ³ý°´Å¥Ç°£¬½«ËüÆôÓÃ
button->setEnable(true); button->setEnable(true);
_vButtons.erase(_vButtons.begin() + i); _buttons.erase(_buttons.begin() + i);
return true; return true;
} }
} }

View File

@ -11,30 +11,30 @@ static bool s_fDefaultColliderEnabled = true;
e2d::Node::Node() e2d::Node::Node()
: _nOrder(0) : _nOrder(0)
, _fPosX(0) , _posX(0)
, _fPosY(0) , _posY(0)
, _fWidth(0) , _width(0)
, _fHeight(0) , _height(0)
, _fScaleX(1.0f) , _scaleX(1.0f)
, _fScaleY(1.0f) , _scaleY(1.0f)
, _fRotation(0) , _rotation(0)
, _fSkewAngleX(0) , _skewAngleX(0)
, _fSkewAngleY(0) , _skewAngleY(0)
, _fDisplayOpacity(1.0f) , _displayOpacity(1.0f)
, _fRealOpacity(1.0f) , _realOpacity(1.0f)
, _fPivotX(s_fDefaultPiovtX) , _pivotX(s_fDefaultPiovtX)
, _fPivotY(s_fDefaultPiovtY) , _pivotY(s_fDefaultPiovtY)
, _MatriInitial(D2D1::Matrix3x2F::Identity()) , _initialMatri(D2D1::Matrix3x2F::Identity())
, _MatriFinal(D2D1::Matrix3x2F::Identity()) , _finalMatri(D2D1::Matrix3x2F::Identity())
, _bVisiable(true) , _visiable(true)
, _pCollider(nullptr) , _collider(nullptr)
, _pParent(nullptr) , _parent(nullptr)
, _pParentScene(nullptr) , _parentScene(nullptr)
, _nHashName(0) , _hashName(0)
, _bSortChildrenNeeded(false) , _needSort(false)
, _bTransformNeeded(false) , _needTransform(false)
, _bAutoUpdate(true) , _autoUpdate(true)
, _bPositionFixed(false) , _positionFixed(false)
{ {
if (s_fDefaultColliderEnabled) if (s_fDefaultColliderEnabled)
{ {
@ -49,14 +49,14 @@ e2d::Node::~Node()
void e2d::Node::_update() void e2d::Node::_update()
{ {
if (_bTransformNeeded) if (_needTransform)
{ {
_updateTransform(); _updateTransform();
} }
if (!_vChildren.empty()) if (!_children.empty())
{ {
if (_bSortChildrenNeeded) if (_needSort)
{ {
// 子节点排序 // 子节点排序
auto sortFunc = [](Node * n1, Node * n2) { auto sortFunc = [](Node * n1, Node * n2) {
@ -64,20 +64,20 @@ void e2d::Node::_update()
}; };
std::sort( std::sort(
std::begin(_vChildren), std::begin(_children),
std::end(_vChildren), std::end(_children),
sortFunc sortFunc
); );
_bSortChildrenNeeded = false; _needSort = false;
} }
// 遍历子节点 // 遍历子节点
size_t size = _vChildren.size(); size_t size = _children.size();
size_t i; size_t i;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
auto child = _vChildren[i]; auto child = _children[i];
// 访问 Order 小于零的节点 // 访问 Order 小于零的节点
if (child->getOrder() < 0) if (child->getOrder() < 0)
{ {
@ -89,7 +89,7 @@ void e2d::Node::_update()
} }
} }
if (_bAutoUpdate) if (_autoUpdate)
{ {
if (!Game::isPaused()) if (!Game::isPaused())
{ {
@ -100,11 +100,11 @@ void e2d::Node::_update()
// 访问剩余节点 // 访问剩余节点
for (; i < size; i++) for (; i < size; i++)
_vChildren[i]->_update(); _children[i]->_update();
} }
else else
{ {
if (_bAutoUpdate) if (_autoUpdate)
{ {
if (!Game::isPaused()) if (!Game::isPaused())
{ {
@ -117,18 +117,18 @@ void e2d::Node::_update()
void e2d::Node::_render() void e2d::Node::_render()
{ {
if (!_bVisiable) if (!_visiable)
{ {
return; return;
} }
if (!_vChildren.empty()) if (!_children.empty())
{ {
size_t size = _vChildren.size(); size_t size = _children.size();
size_t i; size_t i;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
auto child = _vChildren[i]; auto child = _children[i];
// 访问 Order 小于零的节点 // 访问 Order 小于零的节点
if (child->getOrder() < 0) if (child->getOrder() < 0)
{ {
@ -141,18 +141,18 @@ void e2d::Node::_render()
} }
// 转换渲染器的二维矩阵 // 转换渲染器的二维矩阵
Renderer::getRenderTarget()->SetTransform(_MatriFinal); Renderer::getRenderTarget()->SetTransform(_finalMatri);
// 渲染自身 // 渲染自身
this->onRender(); this->onRender();
// 访问剩余节点 // 访问剩余节点
for (; i < size; i++) for (; i < size; i++)
_vChildren[i]->_render(); _children[i]->_render();
} }
else else
{ {
// 转换渲染器的二维矩阵 // 转换渲染器的二维矩阵
Renderer::getRenderTarget()->SetTransform(_MatriFinal); Renderer::getRenderTarget()->SetTransform(_finalMatri);
// 渲染自身 // 渲染自身
this->onRender(); this->onRender();
} }
@ -161,13 +161,13 @@ void e2d::Node::_render()
void e2d::Node::_drawCollider() 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(); child->_drawCollider();
} }
@ -176,30 +176,30 @@ void e2d::Node::_drawCollider()
void e2d::Node::_updateSelfTransform() void e2d::Node::_updateSelfTransform()
{ {
// 计算中心点坐标 // 计算中心点坐标
D2D1_POINT_2F pivot = { _fWidth * _fPivotX, _fHeight * _fPivotY }; D2D1_POINT_2F pivot = { _width * _pivotX, _height * _pivotY };
// 变换 Initial 矩阵,子节点将根据这个矩阵进行变换 // 变换 Initial 矩阵,子节点将根据这个矩阵进行变换
_MatriInitial = D2D1::Matrix3x2F::Scale( _initialMatri = D2D1::Matrix3x2F::Scale(
_fScaleX, _scaleX,
_fScaleY, _scaleY,
pivot pivot
) * D2D1::Matrix3x2F::Skew( ) * D2D1::Matrix3x2F::Skew(
_fSkewAngleX, _skewAngleX,
_fSkewAngleY, _skewAngleY,
pivot pivot
) * D2D1::Matrix3x2F::Rotation( ) * D2D1::Matrix3x2F::Rotation(
_fRotation, _rotation,
pivot pivot
) * D2D1::Matrix3x2F::Translation( ) * D2D1::Matrix3x2F::Translation(
_fPosX, _posX,
_fPosY _posY
); );
// 根据自身中心点变换 Final 矩阵 // 根据自身中心点变换 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; _initialMatri = _initialMatri * _parent->_initialMatri;
_MatriFinal = _MatriFinal * _pParent->_MatriInitial; _finalMatri = _finalMatri * _parent->_initialMatri;
} }
} }
@ -208,14 +208,14 @@ void e2d::Node::_updateTransform()
// 计算自身的转换矩阵 // 计算自身的转换矩阵
_updateSelfTransform(); _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(); child->_updateTransform();
} }
@ -223,11 +223,11 @@ void e2d::Node::_updateTransform()
void e2d::Node::_updateOpacity() 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(); child->_updateOpacity();
} }
@ -235,7 +235,7 @@ void e2d::Node::_updateOpacity()
bool e2d::Node::isVisiable() const bool e2d::Node::isVisiable() const
{ {
return _bVisiable; return _visiable;
} }
e2d::String e2d::Node::getName() const e2d::String e2d::Node::getName() const
@ -245,57 +245,57 @@ e2d::String e2d::Node::getName() const
unsigned int e2d::Node::getHashName() const unsigned int e2d::Node::getHashName() const
{ {
return _nHashName; return _hashName;
} }
double e2d::Node::getPosX() const double e2d::Node::getPosX() const
{ {
return _fPosX; return _posX;
} }
double e2d::Node::getPosY() const double e2d::Node::getPosY() const
{ {
return _fPosY; return _posY;
} }
e2d::Point e2d::Node::getPos() const e2d::Point e2d::Node::getPos() const
{ {
return Point(_fPosX, _fPosY); return Point(_posX, _posY);
} }
double e2d::Node::getWidth() const double e2d::Node::getWidth() const
{ {
return _fWidth * _fScaleX; return _width * _scaleX;
} }
double e2d::Node::getHeight() const double e2d::Node::getHeight() const
{ {
return _fHeight * _fScaleY; return _height * _scaleY;
} }
double e2d::Node::getRealWidth() const double e2d::Node::getRealWidth() const
{ {
return _fWidth; return _width;
} }
double e2d::Node::getRealHeight() const double e2d::Node::getRealHeight() const
{ {
return _fHeight; return _height;
} }
e2d::Size e2d::Node::getRealSize() const e2d::Size e2d::Node::getRealSize() const
{ {
return Size(_fWidth, _fHeight); return Size(_width, _height);
} }
double e2d::Node::getPivotX() const double e2d::Node::getPivotX() const
{ {
return _fPivotX; return _pivotX;
} }
double e2d::Node::getPivotY() const double e2d::Node::getPivotY() const
{ {
return _fPivotY; return _pivotY;
} }
e2d::Size e2d::Node::getSize() const e2d::Size e2d::Node::getSize() const
@ -305,56 +305,56 @@ e2d::Size e2d::Node::getSize() const
double e2d::Node::getScaleX() const double e2d::Node::getScaleX() const
{ {
return _fScaleX; return _scaleX;
} }
double e2d::Node::getScaleY() const double e2d::Node::getScaleY() const
{ {
return _fScaleY; return _scaleY;
} }
double e2d::Node::getSkewX() const double e2d::Node::getSkewX() const
{ {
return _fSkewAngleX; return _skewAngleX;
} }
double e2d::Node::getSkewY() const double e2d::Node::getSkewY() const
{ {
return _fSkewAngleY; return _skewAngleY;
} }
double e2d::Node::getRotation() const double e2d::Node::getRotation() const
{ {
return _fRotation; return _rotation;
} }
double e2d::Node::getOpacity() const double e2d::Node::getOpacity() const
{ {
return _fRealOpacity; return _realOpacity;
} }
e2d::NodeProperty e2d::Node::getProperty() const e2d::NodeProperty e2d::Node::getProperty() const
{ {
NodeProperty prop; NodeProperty prop;
prop.visable = _bVisiable; prop.visable = _visiable;
prop.posX = _fPosX; prop.posX = _posX;
prop.posY = _fPosY; prop.posY = _posY;
prop.width = _fWidth; prop.width = _width;
prop.height = _fHeight; prop.height = _height;
prop.opacity = _fRealOpacity; prop.opacity = _realOpacity;
prop.pivotX = _fPivotX; prop.pivotX = _pivotX;
prop.pivotY = _fPivotY; prop.pivotY = _pivotY;
prop.scaleX = _fScaleX; prop.scaleX = _scaleX;
prop.scaleY = _fScaleY; prop.scaleY = _scaleY;
prop.rotation = _fRotation; prop.rotation = _rotation;
prop.skewAngleX = _fSkewAngleX; prop.skewAngleX = _skewAngleX;
prop.skewAngleY = _fSkewAngleY; prop.skewAngleY = _skewAngleY;
return prop; return prop;
} }
e2d::Collider * e2d::Node::getCollider() const e2d::Collider * e2d::Node::getCollider() const
{ {
return _pCollider; return _collider;
} }
int e2d::Node::getOrder() const int e2d::Node::getOrder() const
@ -369,12 +369,12 @@ void e2d::Node::setOrder(int order)
void e2d::Node::setPosX(double x) void e2d::Node::setPosX(double x)
{ {
this->setPos(x, _fPosY); this->setPos(x, _posY);
} }
void e2d::Node::setPosY(double y) void e2d::Node::setPosY(double y)
{ {
this->setPos(_fPosX, y); this->setPos(_posX, y);
} }
void e2d::Node::setPos(const Point & p) 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) void e2d::Node::setPos(double x, double y)
{ {
if (_fPosX == x && _fPosY == y) if (_posX == x && _posY == y)
return; return;
_fPosX = static_cast<float>(x); _posX = float(x);
_fPosY = static_cast<float>(y); _posY = float(y);
_bTransformNeeded = true; _needTransform = true;
} }
void e2d::Node::setPosFixed(bool fixed) void e2d::Node::setPosFixed(bool fixed)
{ {
if (_bPositionFixed == fixed) if (_positionFixed == fixed)
return; return;
_bPositionFixed = fixed; _positionFixed = fixed;
_bTransformNeeded = true; _needTransform = true;
} }
void e2d::Node::movePosX(double x) void e2d::Node::movePosX(double x)
@ -413,7 +413,7 @@ void e2d::Node::movePosY(double y)
void e2d::Node::movePos(double x, 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) void e2d::Node::movePos(const Vector & v)
@ -423,12 +423,12 @@ void e2d::Node::movePos(const Vector & v)
void e2d::Node::setScaleX(double scaleX) void e2d::Node::setScaleX(double scaleX)
{ {
this->setScale(scaleX, _fScaleY); this->setScale(scaleX, _scaleY);
} }
void e2d::Node::setScaleY(double scaleY) void e2d::Node::setScaleY(double scaleY)
{ {
this->setScale(_fScaleX, scaleY); this->setScale(_scaleX, scaleY);
} }
void e2d::Node::setScale(double scale) void e2d::Node::setScale(double scale)
@ -438,91 +438,91 @@ void e2d::Node::setScale(double scale)
void e2d::Node::setScale(double scaleX, double scaleY) void e2d::Node::setScale(double scaleX, double scaleY)
{ {
if (_fScaleX == scaleX && _fScaleY == scaleY) if (_scaleX == scaleX && _scaleY == scaleY)
return; return;
_fScaleX = static_cast<float>(scaleX); _scaleX = float(scaleX);
_fScaleY = static_cast<float>(scaleY); _scaleY = float(scaleY);
_bTransformNeeded = true; _needTransform = true;
} }
void e2d::Node::setSkewX(double angleX) void e2d::Node::setSkewX(double angleX)
{ {
this->setSkew(angleX, _fSkewAngleY); this->setSkew(angleX, _skewAngleY);
} }
void e2d::Node::setSkewY(double angleY) void e2d::Node::setSkewY(double angleY)
{ {
this->setSkew(_fSkewAngleX, angleY); this->setSkew(_skewAngleX, angleY);
} }
void e2d::Node::setSkew(double angleX, double angleY) void e2d::Node::setSkew(double angleX, double angleY)
{ {
if (_fSkewAngleX == angleX && _fSkewAngleY == angleY) if (_skewAngleX == angleX && _skewAngleY == angleY)
return; return;
_fSkewAngleX = static_cast<float>(angleX); _skewAngleX = float(angleX);
_fSkewAngleY = static_cast<float>(angleY); _skewAngleY = float(angleY);
_bTransformNeeded = true; _needTransform = true;
} }
void e2d::Node::setRotation(double angle) void e2d::Node::setRotation(double angle)
{ {
if (_fRotation == angle) if (_rotation == angle)
return; return;
_fRotation = static_cast<float>(angle); _rotation = float(angle);
_bTransformNeeded = true; _needTransform = true;
} }
void e2d::Node::setOpacity(double opacity) void e2d::Node::setOpacity(double opacity)
{ {
if (_fRealOpacity == opacity) if (_realOpacity == opacity)
return; return;
_fDisplayOpacity = _fRealOpacity = min(max(static_cast<float>(opacity), 0), 1); _displayOpacity = _realOpacity = min(max(float(opacity), 0), 1);
// 更新节点透明度 // 更新节点透明度
_updateOpacity(); _updateOpacity();
} }
void e2d::Node::setPivotX(double pivotX) void e2d::Node::setPivotX(double pivotX)
{ {
this->setPivot(pivotX, _fPivotY); this->setPivot(pivotX, _pivotY);
} }
void e2d::Node::setPivotY(double pivotY) void e2d::Node::setPivotY(double pivotY)
{ {
this->setPivot(_fPivotX, pivotY); this->setPivot(_pivotX, pivotY);
} }
void e2d::Node::setPivot(double pivotX, double pivotY) void e2d::Node::setPivot(double pivotX, double pivotY)
{ {
if (_fPivotX == pivotX && _fPivotY == pivotY) if (_pivotX == pivotX && _pivotY == pivotY)
return; return;
_fPivotX = min(max(static_cast<float>(pivotX), 0), 1); _pivotX = min(max(float(pivotX), 0), 1);
_fPivotY = min(max(static_cast<float>(pivotY), 0), 1); _pivotY = min(max(float(pivotY), 0), 1);
_bTransformNeeded = true; _needTransform = true;
} }
void e2d::Node::setWidth(double width) void e2d::Node::setWidth(double width)
{ {
this->setSize(width, _fHeight); this->setSize(width, _height);
} }
void e2d::Node::setHeight(double height) void e2d::Node::setHeight(double height)
{ {
this->setSize(_fWidth, height); this->setSize(_width, height);
} }
void e2d::Node::setSize(double width, double height) void e2d::Node::setSize(double width, double height)
{ {
if (_fWidth == width && _fHeight == height) if (_width == width && _height == height)
return; return;
_fWidth = static_cast<float>(width); _width = float(width);
_fHeight = static_cast<float>(height); _height = float(height);
_bTransformNeeded = true; _needTransform = true;
} }
void e2d::Node::setSize(Size size) void e2d::Node::setSize(Size size)
@ -575,26 +575,26 @@ void e2d::Node::setCollider(ColliderType nColliderType)
void e2d::Node::setCollider(Collider * pCollider) void e2d::Node::setCollider(Collider * pCollider)
{ {
// 删除旧的碰撞体 // 删除旧的碰撞体
ColliderManager::__removeCollider(_pCollider); ColliderManager::__removeCollider(_collider);
// 添加新的碰撞体 // 添加新的碰撞体
ColliderManager::__addCollider(pCollider); ColliderManager::__addCollider(pCollider);
if (pCollider) if (pCollider)
{ {
// 双向绑定 // 双向绑定
this->_pCollider = pCollider; this->_collider = pCollider;
pCollider->_pParentNode = this; pCollider->_parentNode = this;
} }
else else
{ {
this->_pCollider = nullptr; this->_collider = nullptr;
} }
} }
void e2d::Node::addColliableName(const String& collliderName) void e2d::Node::addColliableName(const String& collliderName)
{ {
unsigned int hash = collliderName.getHashCode(); unsigned int hash = collliderName.getHashCode();
_vColliders.insert(hash); _colliders.insert(hash);
} }
#ifdef HIGHER_THAN_VS2012 #ifdef HIGHER_THAN_VS2012
@ -610,7 +610,7 @@ void e2d::Node::addColliableName(const std::initializer_list<String>& vColllider
void e2d::Node::removeColliableName(const String& collliderName) void e2d::Node::removeColliableName(const String& collliderName)
{ {
unsigned int hash = collliderName.getHashCode(); unsigned int hash = collliderName.getHashCode();
_vColliders.erase(hash); _colliders.erase(hash);
} }
void e2d::Node::addChild(Node * child, int order /* = 0 */) void e2d::Node::addChild(Node * child, int order /* = 0 */)
@ -619,32 +619,32 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */)
if (child) 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()) for (Node * parent = this; parent != nullptr; parent = parent->getParent())
{ {
ASSERT(child != parent, "A Node cannot be the child of his own children!"); 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->setOrder(order);
child->retain(); 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->_updateOpacity();
// 更新节点转换 // 更新节点转换
child->_bTransformNeeded = true; child->_needTransform = true;
// 更新子节点排序 // 更新子节点排序
_bSortChildrenNeeded = true; _needSort = true;
} }
} }
@ -660,12 +660,12 @@ void e2d::Node::addChild(const std::initializer_list<Node*>& vNodes, int order)
e2d::Node * e2d::Node::getParent() const e2d::Node * e2d::Node::getParent() const
{ {
return _pParent; return _parent;
} }
e2d::Scene * e2d::Node::getParentScene() const e2d::Scene * e2d::Node::getParentScene() const
{ {
return _pParentScene; return _parentScene;
} }
std::vector<e2d::Node*> e2d::Node::getChildren(const String& name) const std::vector<e2d::Node*> e2d::Node::getChildren(const String& name) const
@ -673,10 +673,10 @@ std::vector<e2d::Node*> e2d::Node::getChildren(const String& name) const
std::vector<Node*> vChildren; std::vector<Node*> vChildren;
unsigned int hash = name.getHashCode(); unsigned int hash = name.getHashCode();
for (auto child : _vChildren) for (auto child : _children)
{ {
// 不同的名称可能会有相同的 Hash 值,但是先比较 Hash 可以提升搜索速度 // 不同的名称可能会有相同的 Hash 值,但是先比较 Hash 可以提升搜索速度
if (child->_nHashName == hash && child->_name == name) if (child->_hashName == hash && child->_name == name)
{ {
vChildren.push_back(child); vChildren.push_back(child);
} }
@ -688,10 +688,10 @@ e2d::Node * e2d::Node::getChild(const String& name) const
{ {
unsigned int hash = name.getHashCode(); unsigned int hash = name.getHashCode();
for (auto child : _vChildren) for (auto child : _children)
{ {
// 不同的名称可能会有相同的 Hash 值,但是先比较 Hash 可以提升搜索速度 // 不同的名称可能会有相同的 Hash 值,但是先比较 Hash 可以提升搜索速度
if (child->_nHashName == hash && child->_name == name) if (child->_hashName == hash && child->_name == name)
{ {
return child; return child;
} }
@ -701,19 +701,19 @@ e2d::Node * e2d::Node::getChild(const String& name) const
std::vector<e2d::Node*> e2d::Node::getAllChildren() const std::vector<e2d::Node*> e2d::Node::getAllChildren() const
{ {
return _vChildren; return _children;
} }
int e2d::Node::getChildrenCount() const int e2d::Node::getChildrenCount() const
{ {
return static_cast<int>(_vChildren.size()); return static_cast<int>(_children.size());
} }
void e2d::Node::removeFromParent() 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."); WARN_IF(child == nullptr, "Node::removeChildren NULL pointer exception.");
if (_vChildren.empty()) if (_children.empty())
{ {
return false; return false;
} }
if (child) if (child)
{ {
size_t size = _vChildren.size(); size_t size = _children.size();
for (size_t i = 0; i < size; i++) for (size_t i = 0; i < size; i++)
{ {
if (_vChildren[i] == child) if (_children[i] == child)
{ {
_vChildren.erase(_vChildren.begin() + i); _children.erase(_children.begin() + i);
child->_pParent = nullptr; child->_parent = nullptr;
if (child->_pParentScene) if (child->_parentScene)
{ {
child->_setParentScene(nullptr); child->_setParentScene(nullptr);
} }
@ -753,7 +753,7 @@ void e2d::Node::removeChildren(const String& childName)
{ {
WARN_IF(childName.isEmpty(), "Invalid Node name."); WARN_IF(childName.isEmpty(), "Invalid Node name.");
if (_vChildren.empty()) if (_children.empty())
{ {
return; return;
} }
@ -761,15 +761,15 @@ void e2d::Node::removeChildren(const String& childName)
// 计算名称 Hash 值 // 计算名称 Hash 值
unsigned int hash = childName.getHashCode(); unsigned int hash = childName.getHashCode();
size_t size = _vChildren.size(); size_t size = _children.size();
for (size_t i = 0; i < size; i++) for (size_t i = 0; i < size; i++)
{ {
auto child = _vChildren[i]; auto child = _children[i];
if (child->_nHashName == hash && child->_name == childName) if (child->_hashName == hash && child->_name == childName)
{ {
_vChildren.erase(_vChildren.begin() + i); _children.erase(_children.begin() + i);
child->_pParent = nullptr; child->_parent = nullptr;
if (child->_pParentScene) if (child->_parentScene)
{ {
child->_setParentScene(nullptr); child->_setParentScene(nullptr);
} }
@ -781,12 +781,12 @@ void e2d::Node::removeChildren(const String& childName)
void e2d::Node::clearAllChildren() void e2d::Node::clearAllChildren()
{ {
// 所有节点的引用计数减一 // 所有节点的引用计数减一
for (auto child : _vChildren) for (auto child : _children)
{ {
child->release(); child->release();
} }
// 清空储存节点的容器 // 清空储存节点的容器
_vChildren.clear(); _children.clear();
} }
void e2d::Node::runAction(Action * action) void e2d::Node::runAction(Action * action)
@ -873,13 +873,13 @@ bool e2d::Node::isPointIn(Point point) const
{ {
BOOL ret = 0; BOOL ret = 0;
// 如果存在碰撞体,用碰撞体判断 // 如果存在碰撞体,用碰撞体判断
if (_pCollider) if (_collider)
{ {
_pCollider->getD2dGeometry()->FillContainsPoint( _collider->getD2dGeometry()->FillContainsPoint(
D2D1::Point2F( D2D1::Point2F(
static_cast<float>(point.x), float(point.x),
static_cast<float>(point.y)), float(point.y)),
_MatriFinal, _finalMatri,
&ret &ret
); );
} }
@ -888,15 +888,15 @@ bool e2d::Node::isPointIn(Point point) const
// 为节点创建一个临时碰撞体 // 为节点创建一个临时碰撞体
ID2D1RectangleGeometry * rect; ID2D1RectangleGeometry * rect;
Renderer::getID2D1Factory()->CreateRectangleGeometry( Renderer::getID2D1Factory()->CreateRectangleGeometry(
D2D1::RectF(0, 0, _fWidth, _fHeight), D2D1::RectF(0, 0, _width, _height),
&rect &rect
); );
// 判断点是否在碰撞体内 // 判断点是否在碰撞体内
rect->FillContainsPoint( rect->FillContainsPoint(
D2D1::Point2F( D2D1::Point2F(
static_cast<float>(point.x), float(point.x),
static_cast<float>(point.y)), float(point.y)),
_MatriFinal, _finalMatri,
&ret &ret
); );
// 删除临时创建的碰撞体 // 删除临时创建的碰撞体
@ -914,9 +914,9 @@ bool e2d::Node::isPointIn(Point point) const
bool e2d::Node::isIntersectWith(const Node * node) 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) && if ((relation != Relation::UNKNOWN) &&
(relation != Relation::DISJOINT)) (relation != Relation::DISJOINT))
{ {
@ -933,24 +933,24 @@ bool e2d::Node::isIntersectWith(const Node * node) const
// 根据自身大小位置创建矩形 // 根据自身大小位置创建矩形
Renderer::getID2D1Factory()->CreateRectangleGeometry( Renderer::getID2D1Factory()->CreateRectangleGeometry(
D2D1::RectF(0, 0, _fWidth, _fHeight), D2D1::RectF(0, 0, _width, _height),
&pRect1 &pRect1
); );
// 根据二维矩阵进行转换 // 根据二维矩阵进行转换
Renderer::getID2D1Factory()->CreateTransformedGeometry( Renderer::getID2D1Factory()->CreateTransformedGeometry(
pRect1, pRect1,
_MatriFinal, _finalMatri,
&pCollider &pCollider
); );
// 根据相比较节点的大小位置创建矩形 // 根据相比较节点的大小位置创建矩形
Renderer::getID2D1Factory()->CreateRectangleGeometry( Renderer::getID2D1Factory()->CreateRectangleGeometry(
D2D1::RectF(0, 0, node->_fWidth, node->_fHeight), D2D1::RectF(0, 0, node->_width, node->_height),
&pRect2 &pRect2
); );
// 获取相交状态 // 获取相交状态
pCollider->CompareWithGeometry( pCollider->CompareWithGeometry(
pRect2, pRect2,
node->_MatriFinal, node->_finalMatri,
&relation &relation
); );
// 删除临时创建的碰撞体 // 删除临时创建的碰撞体
@ -969,13 +969,13 @@ bool e2d::Node::isIntersectWith(const Node * node) const
void e2d::Node::setAutoUpdate(bool bAutoUpdate) void e2d::Node::setAutoUpdate(bool bAutoUpdate)
{ {
_bAutoUpdate = bAutoUpdate; _autoUpdate = bAutoUpdate;
} }
void e2d::Node::setDefaultPiovt(double defaultPiovtX, double defaultPiovtY) void e2d::Node::setDefaultPiovt(double defaultPiovtX, double defaultPiovtY)
{ {
s_fDefaultPiovtX = min(max(static_cast<float>(defaultPiovtX), 0), 1); s_fDefaultPiovtX = min(max(float(defaultPiovtX), 0), 1);
s_fDefaultPiovtY = min(max(static_cast<float>(defaultPiovtY), 0), 1); s_fDefaultPiovtY = min(max(float(defaultPiovtY), 0), 1);
} }
void e2d::Node::setDefaultColliderEnable(bool enable) void e2d::Node::setDefaultColliderEnable(bool enable)
@ -986,8 +986,8 @@ void e2d::Node::setDefaultColliderEnable(bool enable)
void e2d::Node::onDestroy() void e2d::Node::onDestroy()
{ {
ActionManager::__clearAllBindedWith(this); ActionManager::__clearAllBindedWith(this);
ColliderManager::__removeCollider(_pCollider); ColliderManager::__removeCollider(_collider);
for (auto child : _vChildren) for (auto child : _children)
{ {
SafeRelease(&child); SafeRelease(&child);
} }
@ -1010,7 +1010,7 @@ void e2d::Node::stopAllActions()
void e2d::Node::setVisiable(bool value) void e2d::Node::setVisiable(bool value)
{ {
_bVisiable = value; _visiable = value;
} }
void e2d::Node::setName(const String& name) void e2d::Node::setName(const String& name)
@ -1022,14 +1022,14 @@ void e2d::Node::setName(const String& name)
// 保存节点名 // 保存节点名
_name = name; _name = name;
// 保存节点 Hash 名 // 保存节点 Hash 名
_nHashName = name.getHashCode(); _hashName = name.getHashCode();
} }
} }
void e2d::Node::_setParentScene(Scene * scene) void e2d::Node::_setParentScene(Scene * scene)
{ {
_pParentScene = scene; _parentScene = scene;
for (auto child : _vChildren) for (auto child : _children)
{ {
child->_setParentScene(scene); child->_setParentScene(scene);
} }

View File

@ -1,7 +1,7 @@
#include "..\..\e2dshape.h" #include "..\..\e2dshape.h"
e2d::Circle::Circle() e2d::Circle::Circle()
: _fRadius(0) : _radius(0)
{ {
this->setPivot(0.5, 0.5); this->setPivot(0.5, 0.5);
} }
@ -32,28 +32,28 @@ e2d::Circle::~Circle()
double e2d::Circle::getRadius() const double e2d::Circle::getRadius() const
{ {
return _fRadius; return _radius;
} }
void e2d::Circle::setRadius(double radius) void e2d::Circle::setRadius(double radius)
{ {
_fRadius = static_cast<float>(radius); _radius = float(radius);
Node::setSize(radius * 2, radius * 2); Node::setSize(radius * 2, radius * 2);
} }
void e2d::Circle::_renderLine() void e2d::Circle::_renderLine()
{ {
Renderer::getRenderTarget()->DrawEllipse( Renderer::getRenderTarget()->DrawEllipse(
D2D1::Ellipse(D2D1::Point2F(_fRadius, _fRadius), _fRadius, _fRadius), D2D1::Ellipse(D2D1::Point2F(_radius, _radius), _radius, _radius),
Renderer::getSolidColorBrush(), Renderer::getSolidColorBrush(),
_fStrokeWidth _strokeWidth
); );
} }
void e2d::Circle::_renderFill() void e2d::Circle::_renderFill()
{ {
Renderer::getRenderTarget()->FillEllipse( Renderer::getRenderTarget()->FillEllipse(
D2D1::Ellipse(D2D1::Point2F(_fRadius, _fRadius), _fRadius, _fRadius), D2D1::Ellipse(D2D1::Point2F(_radius, _radius), _radius, _radius),
Renderer::getSolidColorBrush() Renderer::getSolidColorBrush()
); );
} }

View File

@ -1,8 +1,8 @@
#include "..\..\e2dshape.h" #include "..\..\e2dshape.h"
e2d::Ellipse::Ellipse() e2d::Ellipse::Ellipse()
: _fRadiusX(0) : _radiusX(0)
, _fRadiusY(0) , _radiusY(0)
{ {
this->setPivot(0.5, 0.5); this->setPivot(0.5, 0.5);
} }
@ -36,39 +36,39 @@ e2d::Ellipse::~Ellipse()
double e2d::Ellipse::getRadiusX() const double e2d::Ellipse::getRadiusX() const
{ {
return _fRadiusX; return _radiusX;
} }
double e2d::Ellipse::getRadiusY() const double e2d::Ellipse::getRadiusY() const
{ {
return _fRadiusY; return _radiusY;
} }
void e2d::Ellipse::setRadiusX(double radiusX) void e2d::Ellipse::setRadiusX(double radiusX)
{ {
_fRadiusX = static_cast<float>(radiusX); _radiusX = float(radiusX);
Node::setWidth(radiusX * 2); Node::setWidth(radiusX * 2);
} }
void e2d::Ellipse::setRadiusY(double radiusY) void e2d::Ellipse::setRadiusY(double radiusY)
{ {
_fRadiusY = static_cast<float>(radiusY); _radiusY = float(radiusY);
Node::setHeight(radiusY * 2); Node::setHeight(radiusY * 2);
} }
void e2d::Ellipse::_renderLine() void e2d::Ellipse::_renderLine()
{ {
Renderer::getRenderTarget()->DrawEllipse( Renderer::getRenderTarget()->DrawEllipse(
D2D1::Ellipse(D2D1::Point2F(_fRadiusX, _fRadiusY), _fRadiusX, _fRadiusY), D2D1::Ellipse(D2D1::Point2F(_radiusX, _radiusY), _radiusX, _radiusY),
Renderer::getSolidColorBrush(), Renderer::getSolidColorBrush(),
_fStrokeWidth _strokeWidth
); );
} }
void e2d::Ellipse::_renderFill() void e2d::Ellipse::_renderFill()
{ {
Renderer::getRenderTarget()->FillEllipse( Renderer::getRenderTarget()->FillEllipse(
D2D1::Ellipse(D2D1::Point2F(_fRadiusX, _fRadiusY), _fRadiusX, _fRadiusY), D2D1::Ellipse(D2D1::Point2F(_radiusX, _radiusY), _radiusX, _radiusY),
Renderer::getSolidColorBrush() Renderer::getSolidColorBrush()
); );
} }

View File

@ -35,16 +35,16 @@ e2d::Rect::~Rect()
void e2d::Rect::_renderLine() void e2d::Rect::_renderLine()
{ {
Renderer::getRenderTarget()->DrawRectangle( Renderer::getRenderTarget()->DrawRectangle(
D2D1::RectF(0, 0, _fWidth, _fHeight), D2D1::RectF(0, 0, _width, _height),
Renderer::getSolidColorBrush(), Renderer::getSolidColorBrush(),
_fStrokeWidth _strokeWidth
); );
} }
void e2d::Rect::_renderFill() void e2d::Rect::_renderFill()
{ {
Renderer::getRenderTarget()->FillRectangle( Renderer::getRenderTarget()->FillRectangle(
D2D1::RectF(0, 0, _fWidth, _fHeight), D2D1::RectF(0, 0, _width, _height),
Renderer::getSolidColorBrush() Renderer::getSolidColorBrush()
); );
} }

View File

@ -1,28 +1,28 @@
#include "..\..\e2dshape.h" #include "..\..\e2dshape.h"
e2d::RoundRect::RoundRect() e2d::RoundRect::RoundRect()
: _fRadiusX(0) : _radiusX(0)
, _fRadiusY(0) , _radiusY(0)
{ {
} }
e2d::RoundRect::RoundRect(double width, double height, double radiusX, double radiusY) e2d::RoundRect::RoundRect(double width, double height, double radiusX, double radiusY)
: _fRadiusX(static_cast<float>(radiusX)) : _radiusX(float(radiusX))
, _fRadiusY(static_cast<float>(radiusY)) , _radiusY(float(radiusY))
{ {
this->setSize(width, height); this->setSize(width, height);
} }
e2d::RoundRect::RoundRect(Size size, double radiusX, double radiusY) e2d::RoundRect::RoundRect(Size size, double radiusX, double radiusY)
: _fRadiusX(static_cast<float>(radiusX)) : _radiusX(float(radiusX))
, _fRadiusY(static_cast<float>(radiusY)) , _radiusY(float(radiusY))
{ {
this->setSize(size); this->setSize(size);
} }
e2d::RoundRect::RoundRect(double top, double left, double width, double height, double radiusX, double radiusY) e2d::RoundRect::RoundRect(double top, double left, double width, double height, double radiusX, double radiusY)
: _fRadiusX(static_cast<float>(radiusX)) : _radiusX(float(radiusX))
, _fRadiusY(static_cast<float>(radiusY)) , _radiusY(float(radiusY))
{ {
this->setPivot(0, 0); this->setPivot(0, 0);
this->setPos(top, left); 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) e2d::RoundRect::RoundRect(Point topLeft, Size size, double radiusX, double radiusY)
: _fRadiusX(static_cast<float>(radiusX)) : _radiusX(float(radiusX))
, _fRadiusY(static_cast<float>(radiusY)) , _radiusY(float(radiusY))
{ {
this->setPivot(0, 0); this->setPivot(0, 0);
this->setPos(topLeft); this->setPos(topLeft);
@ -44,37 +44,37 @@ e2d::RoundRect::~RoundRect()
double e2d::RoundRect::getRadiusX() const double e2d::RoundRect::getRadiusX() const
{ {
return _fRadiusX; return _radiusX;
} }
double e2d::RoundRect::getRadiusY() const double e2d::RoundRect::getRadiusY() const
{ {
return _fRadiusY; return _radiusY;
} }
void e2d::RoundRect::setRadiusX(double radiusX) void e2d::RoundRect::setRadiusX(double radiusX)
{ {
_fRadiusX = static_cast<float>(radiusX); _radiusX = float(radiusX);
} }
void e2d::RoundRect::setRadiusY(double radiusY) void e2d::RoundRect::setRadiusY(double radiusY)
{ {
_fRadiusY = static_cast<float>(radiusY); _radiusY = float(radiusY);
} }
void e2d::RoundRect::_renderLine() void e2d::RoundRect::_renderLine()
{ {
Renderer::getRenderTarget()->DrawRoundedRectangle( 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(), Renderer::getSolidColorBrush(),
_fStrokeWidth _strokeWidth
); );
} }
void e2d::RoundRect::_renderFill() void e2d::RoundRect::_renderFill()
{ {
Renderer::getRenderTarget()->FillRoundedRectangle( 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() Renderer::getSolidColorBrush()
); );
} }

View File

@ -1,10 +1,10 @@
#include "..\..\e2dshape.h" #include "..\..\e2dshape.h"
e2d::Shape::Shape() e2d::Shape::Shape()
: _nStyle(ShapeStyle::SOLID) : _style(ShapeStyle::SOLID)
, _nFillColor(Color::WHITE) , _fillColor(Color::WHITE)
, _nLineColor(Color::BLUE, 0.5) , _lineColor(Color::BLUE, 0.5)
, _fStrokeWidth(1) , _strokeWidth(1)
{ {
} }
@ -15,30 +15,30 @@ e2d::Shape::~Shape()
void e2d::Shape::onRender() void e2d::Shape::onRender()
{ {
auto pBrush = Renderer::getSolidColorBrush(); auto pBrush = Renderer::getSolidColorBrush();
pBrush->SetOpacity(_fDisplayOpacity); pBrush->SetOpacity(_displayOpacity);
switch (_nStyle) switch (_style)
{ {
case ShapeStyle::FILL: case ShapeStyle::FILL:
{ {
pBrush->SetColor(_nFillColor.toColorF()); pBrush->SetColor(_fillColor.toColorF());
this->_renderFill(); this->_renderFill();
pBrush->SetColor(_nLineColor.toColorF()); pBrush->SetColor(_lineColor.toColorF());
this->_renderLine(); this->_renderLine();
break; break;
} }
case ShapeStyle::ROUND: case ShapeStyle::ROUND:
{ {
pBrush->SetColor(_nLineColor.toColorF()); pBrush->SetColor(_lineColor.toColorF());
this->_renderLine(); this->_renderLine();
break; break;
} }
case ShapeStyle::SOLID: case ShapeStyle::SOLID:
{ {
pBrush->SetColor(_nFillColor.toColorF()); pBrush->SetColor(_fillColor.toColorF());
this->_renderFill(); this->_renderFill();
break; break;
} }
@ -50,40 +50,40 @@ void e2d::Shape::onRender()
e2d::Color e2d::Shape::getFillColor() const e2d::Color e2d::Shape::getFillColor() const
{ {
return _nFillColor; return _fillColor;
} }
e2d::Color e2d::Shape::getLineColor() const e2d::Color e2d::Shape::getLineColor() const
{ {
return _nLineColor; return _lineColor;
} }
double e2d::Shape::getStrokeWidth() const double e2d::Shape::getStrokeWidth() const
{ {
return _fStrokeWidth; return _strokeWidth;
} }
e2d::ShapeStyle e2d::Shape::getStyle() const e2d::ShapeStyle e2d::Shape::getStyle() const
{ {
return _nStyle; return _style;
} }
void e2d::Shape::setFillColor(Color fillColor) void e2d::Shape::setFillColor(Color fillColor)
{ {
_nFillColor = fillColor; _fillColor = fillColor;
} }
void e2d::Shape::setLineColor(Color lineColor) void e2d::Shape::setLineColor(Color lineColor)
{ {
_nLineColor = lineColor; _lineColor = lineColor;
} }
void e2d::Shape::setStrokeWidth(double strokeWidth) void e2d::Shape::setStrokeWidth(double strokeWidth)
{ {
_fStrokeWidth = static_cast<float>(strokeWidth); _strokeWidth = float(strokeWidth);
} }
void e2d::Shape::setStyle(ShapeStyle style) void e2d::Shape::setStyle(ShapeStyle style)
{ {
_nStyle = style; _style = style;
} }

View File

@ -2,37 +2,37 @@
e2d::Sprite::Sprite() e2d::Sprite::Sprite()
: _pImage(nullptr) : _image(nullptr)
{ {
} }
e2d::Sprite::Sprite(Image * image) e2d::Sprite::Sprite(Image * image)
: _pImage(nullptr) : _image(nullptr)
{ {
open(image); open(image);
} }
e2d::Sprite::Sprite(const String& filePath) e2d::Sprite::Sprite(const String& filePath)
: _pImage(nullptr) : _image(nullptr)
{ {
open(filePath); open(filePath);
} }
e2d::Sprite::Sprite(int resNameId, const String& resType) e2d::Sprite::Sprite(int resNameId, const String& resType)
: _pImage(nullptr) : _image(nullptr)
{ {
open(resNameId, resType); open(resNameId, resType);
} }
e2d::Sprite::Sprite(const String& filePath, double x, double y, double width, double height) e2d::Sprite::Sprite(const String& filePath, double x, double y, double width, double height)
: _pImage(nullptr) : _image(nullptr)
{ {
open(filePath); open(filePath);
crop(x, y, width, height); crop(x, y, width, height);
} }
e2d::Sprite::Sprite(int resNameId, const String& resType, double x, double y, double width, double height) e2d::Sprite::Sprite(int resNameId, const String& resType, double x, double y, double width, double height)
: _pImage(nullptr) : _image(nullptr)
{ {
open(resNameId, resType); open(resNameId, resType);
crop(x, y, width, height); crop(x, y, width, height);
@ -46,11 +46,11 @@ bool e2d::Sprite::open(Image * image)
{ {
if (image) if (image)
{ {
SafeRelease(&_pImage); SafeRelease(&_image);
_pImage = image; _image = image;
_pImage->retain(); _image->retain();
Node::setSize(_pImage->getWidth(), _pImage->getHeight()); Node::setSize(_image->getWidth(), _image->getHeight());
return true; return true;
} }
return false; return false;
@ -58,15 +58,15 @@ bool e2d::Sprite::open(Image * image)
bool e2d::Sprite::open(const String& filePath) bool e2d::Sprite::open(const String& filePath)
{ {
if (!_pImage) if (!_image)
{ {
_pImage = new (std::nothrow) Image(); _image = new (std::nothrow) Image();
_pImage->retain(); _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 true;
} }
return false; return false;
@ -74,15 +74,15 @@ bool e2d::Sprite::open(const String& filePath)
bool e2d::Sprite::open(int resNameId, const String& resType) bool e2d::Sprite::open(int resNameId, const String& resType)
{ {
if (!_pImage) if (!_image)
{ {
_pImage = new (std::nothrow) Image(); _image = new (std::nothrow) Image();
_pImage->retain(); _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 true;
} }
return false; 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) 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( Node::setSize(
min(max(width, 0), _pImage->getSourceWidth() - _pImage->getCropX()), min(max(width, 0), _image->getSourceWidth() - _image->getCropX()),
min(max(height, 0), _pImage->getSourceHeight() - _pImage->getCropY()) min(max(height, 0), _image->getSourceHeight() - _image->getCropY())
); );
} }
e2d::Image * e2d::Sprite::getImage() const e2d::Image * e2d::Sprite::getImage() const
{ {
return _pImage; return _image;
} }
void e2d::Sprite::onRender() void e2d::Sprite::onRender()
{ {
if (_pImage && _pImage->getBitmap()) if (_image && _image->getBitmap())
{ {
// »ñȡͼƬ²Ã¼ôλÖà // »ñȡͼƬ²Ã¼ôλÖÃ
float fCropX = static_cast<float>(_pImage->getCropX()); float fCropX = float(_image->getCropX());
float fCropY = static_cast<float>(_pImage->getCropY()); float fCropY = float(_image->getCropY());
// äÖȾͼƬ // äÖȾͼƬ
Renderer::getRenderTarget()->DrawBitmap( Renderer::getRenderTarget()->DrawBitmap(
_pImage->getBitmap(), _image->getBitmap(),
D2D1::RectF(0, 0, _fWidth, _fHeight), D2D1::RectF(0, 0, _width, _height),
_fDisplayOpacity, _displayOpacity,
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
D2D1::RectF( D2D1::RectF(
fCropX, fCropX,
fCropY, fCropY,
fCropX + _fWidth, fCropX + _width,
fCropY + _fHeight fCropY + _height
) )
); );
} }
@ -128,5 +128,5 @@ void e2d::Sprite::onRender()
void e2d::Sprite::onDestroy() void e2d::Sprite::onDestroy()
{ {
Node::onDestroy(); Node::onDestroy();
SafeRelease(&_pImage); SafeRelease(&_image);
} }

View File

@ -2,34 +2,34 @@
e2d::Text::Text() e2d::Text::Text()
: _TextStyle() : _style()
, _pDWriteTextLayout(nullptr) , _textLayout(nullptr)
, _pDWriteTextFormat(nullptr) , _textFormat(nullptr)
{ {
} }
e2d::Text::Text(const String& text) e2d::Text::Text(const String& text)
: _TextStyle() : _style()
, _pDWriteTextLayout(nullptr) , _textLayout(nullptr)
, _pDWriteTextFormat(nullptr) , _textFormat(nullptr)
, _sText(text) , _text(text)
{ {
_reset(); _reset();
} }
e2d::Text::Text(TextStyle textStyle) e2d::Text::Text(TextStyle textStyle)
: _TextStyle(textStyle) : _style(textStyle)
, _pDWriteTextLayout(nullptr) , _textLayout(nullptr)
, _pDWriteTextFormat(nullptr) , _textFormat(nullptr)
{ {
_reset(); _reset();
} }
e2d::Text::Text(const String& text, TextStyle textStyle) e2d::Text::Text(const String& text, TextStyle textStyle)
: _TextStyle(textStyle) : _style(textStyle)
, _pDWriteTextLayout(nullptr) , _textLayout(nullptr)
, _pDWriteTextFormat(nullptr) , _textFormat(nullptr)
, _sText(text) , _text(text)
{ {
_reset(); _reset();
} }
@ -51,7 +51,7 @@ e2d::Text::Text(
UINT32 outlineColor, UINT32 outlineColor,
UINT32 outlineWidth UINT32 outlineWidth
) )
: _TextStyle( : _style(
fontFamily, fontFamily,
fontSize, fontSize,
color, color,
@ -67,70 +67,70 @@ e2d::Text::Text(
outlineColor, outlineColor,
outlineWidth outlineWidth
) )
, _pDWriteTextLayout(nullptr) , _textLayout(nullptr)
, _pDWriteTextFormat(nullptr) , _textFormat(nullptr)
, _sText(text) , _text(text)
{ {
_reset(); _reset();
} }
e2d::Text::~Text() e2d::Text::~Text()
{ {
SafeReleaseInterface(&_pDWriteTextFormat); SafeReleaseInterface(&_textFormat);
SafeReleaseInterface(&_pDWriteTextLayout); SafeReleaseInterface(&_textLayout);
} }
e2d::String e2d::Text::getText() const e2d::String e2d::Text::getText() const
{ {
return _sText; return _text;
} }
e2d::TextStyle e2d::Text::getTextStyle() const e2d::TextStyle e2d::Text::getTextStyle() const
{ {
return _TextStyle; return _style;
} }
e2d::String e2d::Text::getFontFamily() const e2d::String e2d::Text::getFontFamily() const
{ {
return _TextStyle.fontFamily; return _style.fontFamily;
} }
double e2d::Text::getFontSize() const double e2d::Text::getFontSize() const
{ {
return _TextStyle.fontSize; return _style.fontSize;
} }
UINT32 e2d::Text::getFontWeight() const UINT32 e2d::Text::getFontWeight() const
{ {
return _TextStyle.fontWeight; return _style.fontWeight;
} }
e2d::Color e2d::Text::getColor() const e2d::Color e2d::Text::getColor() const
{ {
return _TextStyle.color; return _style.color;
} }
e2d::Color e2d::Text::getOutlineColor() const e2d::Color e2d::Text::getOutlineColor() const
{ {
return _TextStyle.outlineColor; return _style.outlineColor;
} }
double e2d::Text::getOutlineWidth() const double e2d::Text::getOutlineWidth() const
{ {
return _TextStyle.outlineWidth; return _style.outlineWidth;
} }
e2d::LineJoin e2d::Text::getOutlineJoin() const e2d::LineJoin e2d::Text::getOutlineJoin() const
{ {
return _TextStyle.outlineJoin; return _style.outlineJoin;
} }
int e2d::Text::getLineCount() const int e2d::Text::getLineCount() const
{ {
if (_pDWriteTextLayout) if (_textLayout)
{ {
DWRITE_TEXT_METRICS metrics; DWRITE_TEXT_METRICS metrics;
_pDWriteTextLayout->GetMetrics(&metrics); _textLayout->GetMetrics(&metrics);
return static_cast<int>(metrics.lineCount); return static_cast<int>(metrics.lineCount);
} }
else else
@ -141,81 +141,81 @@ int e2d::Text::getLineCount() const
bool e2d::Text::isItalic() const bool e2d::Text::isItalic() const
{ {
return _TextStyle.italic; return _style.italic;
} }
bool e2d::Text::hasStrikethrough() const bool e2d::Text::hasStrikethrough() const
{ {
return _TextStyle.hasStrikethrough; return _style.hasStrikethrough;
} }
bool e2d::Text::hasUnderline() const bool e2d::Text::hasUnderline() const
{ {
return _TextStyle.hasUnderline; return _style.hasUnderline;
} }
bool e2d::Text::hasOutline() const bool e2d::Text::hasOutline() const
{ {
return _TextStyle.hasOutline; return _style.hasOutline;
} }
void e2d::Text::setText(const String& text) void e2d::Text::setText(const String& text)
{ {
_sText = text; _text = text;
_reset(); _reset();
} }
void e2d::Text::setTextStyle(TextStyle textStyle) void e2d::Text::setTextStyle(TextStyle textStyle)
{ {
_TextStyle = textStyle; _style = textStyle;
_reset(); _reset();
} }
void e2d::Text::setFontFamily(const String& fontFamily) void e2d::Text::setFontFamily(const String& fontFamily)
{ {
_TextStyle.fontFamily = fontFamily; _style.fontFamily = fontFamily;
_reset(); _reset();
} }
void e2d::Text::setFontSize(double fontSize) void e2d::Text::setFontSize(double fontSize)
{ {
_TextStyle.fontSize = fontSize; _style.fontSize = fontSize;
_reset(); _reset();
} }
void e2d::Text::setFontWeight(UINT32 fontWeight) void e2d::Text::setFontWeight(UINT32 fontWeight)
{ {
_TextStyle.fontWeight = fontWeight; _style.fontWeight = fontWeight;
_reset(); _reset();
} }
void e2d::Text::setColor(Color color) void e2d::Text::setColor(Color color)
{ {
_TextStyle.color = color; _style.color = color;
} }
void e2d::Text::setItalic(bool value) void e2d::Text::setItalic(bool value)
{ {
_TextStyle.italic = value; _style.italic = value;
_reset(); _reset();
} }
void e2d::Text::setWrapping(bool wrapping) void e2d::Text::setWrapping(bool wrapping)
{ {
if (_TextStyle.wrapping != wrapping) if (_style.wrapping != wrapping)
{ {
_TextStyle.wrapping = wrapping; _style.wrapping = wrapping;
_reset(); _reset();
} }
} }
void e2d::Text::setWrappingWidth(double fWrappingWidth) 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(); _reset();
} }
@ -224,28 +224,28 @@ void e2d::Text::setWrappingWidth(double fWrappingWidth)
void e2d::Text::setLineSpacing(double fLineSpacing) void e2d::Text::setLineSpacing(double fLineSpacing)
{ {
if (_TextStyle.lineSpacing != fLineSpacing) if (_style.lineSpacing != fLineSpacing)
{ {
_TextStyle.lineSpacing = fLineSpacing; _style.lineSpacing = fLineSpacing;
_reset(); _reset();
} }
} }
void e2d::Text::setAlignment(TextAlign align) void e2d::Text::setAlignment(TextAlign align)
{ {
if (_TextStyle.alignment != align) if (_style.alignment != align)
{ {
_TextStyle.alignment = align; _style.alignment = align;
_reset(); _reset();
} }
} }
void e2d::Text::setUnderline(bool hasUnderline) void e2d::Text::setUnderline(bool hasUnderline)
{ {
if (_TextStyle.hasUnderline != hasUnderline) if (_style.hasUnderline != hasUnderline)
{ {
_TextStyle.hasUnderline = hasUnderline; _style.hasUnderline = hasUnderline;
if (!_pDWriteTextFormat) if (!_textFormat)
_createFormat(); _createFormat();
_createLayout(); _createLayout();
} }
@ -253,10 +253,10 @@ void e2d::Text::setUnderline(bool hasUnderline)
void e2d::Text::setStrikethrough(bool hasStrikethrough) void e2d::Text::setStrikethrough(bool hasStrikethrough)
{ {
if (_TextStyle.hasStrikethrough != hasStrikethrough) if (_style.hasStrikethrough != hasStrikethrough)
{ {
_TextStyle.hasStrikethrough = hasStrikethrough; _style.hasStrikethrough = hasStrikethrough;
if (!_pDWriteTextFormat) if (!_textFormat)
_createFormat(); _createFormat();
_createLayout(); _createLayout();
} }
@ -264,42 +264,42 @@ void e2d::Text::setStrikethrough(bool hasStrikethrough)
void e2d::Text::setOutline(bool hasOutline) void e2d::Text::setOutline(bool hasOutline)
{ {
_TextStyle.hasOutline = hasOutline; _style.hasOutline = hasOutline;
} }
void e2d::Text::setOutlineColor(Color outlineColor) void e2d::Text::setOutlineColor(Color outlineColor)
{ {
_TextStyle.outlineColor = outlineColor; _style.outlineColor = outlineColor;
} }
void e2d::Text::setOutlineWidth(double outlineWidth) void e2d::Text::setOutlineWidth(double outlineWidth)
{ {
_TextStyle.outlineWidth = outlineWidth; _style.outlineWidth = outlineWidth;
} }
void e2d::Text::setOutlineJoin(LineJoin outlineJoin) void e2d::Text::setOutlineJoin(LineJoin outlineJoin)
{ {
_TextStyle.outlineJoin = outlineJoin; _style.outlineJoin = outlineJoin;
} }
void e2d::Text::onRender() 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(); auto pTextRenderer = Renderer::getCustomTextRenderer();
pTextRenderer->SetTextStyle( pTextRenderer->SetTextStyle(
_TextStyle.color.toColorF(), _style.color.toColorF(),
_TextStyle.hasOutline, _style.hasOutline,
_TextStyle.outlineColor.toColorF(), _style.outlineColor.toColorF(),
static_cast<FLOAT>(_TextStyle.outlineWidth), float(_style.outlineWidth),
D2D1_LINE_JOIN(_TextStyle.outlineJoin) 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() void e2d::Text::_createFormat()
{ {
SafeReleaseInterface(&_pDWriteTextFormat); SafeReleaseInterface(&_textFormat);
HRESULT hr = Renderer::getIDWriteFactory()->CreateTextFormat( HRESULT hr = Renderer::getIDWriteFactory()->CreateTextFormat(
_TextStyle.fontFamily, _style.fontFamily,
NULL, NULL,
DWRITE_FONT_WEIGHT(_TextStyle.fontWeight), DWRITE_FONT_WEIGHT(_style.fontWeight),
_TextStyle.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL, _style.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL, DWRITE_FONT_STRETCH_NORMAL,
static_cast<float>(_TextStyle.fontSize), float(_style.fontSize),
L"", L"",
&_pDWriteTextFormat &_textFormat
); );
ASSERT(SUCCEEDED(hr), "Create IDWriteTextFormat Failed!"); 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 else
{ {
_pDWriteTextFormat->SetLineSpacing( _textFormat->SetLineSpacing(
DWRITE_LINE_SPACING_METHOD_UNIFORM, DWRITE_LINE_SPACING_METHOD_UNIFORM,
static_cast<FLOAT>(_TextStyle.lineSpacing), float(_style.lineSpacing),
static_cast<FLOAT>(_TextStyle.lineSpacing) * 0.8f float(_style.lineSpacing) * 0.8f
); );
} }
// 打开文本自动换行时,设置换行属性 // 打开文本自动换行时,设置换行属性
if (_TextStyle.wrapping) if (_style.wrapping)
{ {
_pDWriteTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_WRAP); _textFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_WRAP);
} }
else else
{ {
_pDWriteTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); _textFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
} }
} }
} }
void e2d::Text::_createLayout() void e2d::Text::_createLayout()
{ {
SafeReleaseInterface(&_pDWriteTextLayout); SafeReleaseInterface(&_textLayout);
// 文本为空字符串时,重置属性 // 文本为空字符串时,重置属性
if (_sText.isEmpty()) if (_text.isEmpty())
{ {
this->setSize(0, 0); this->setSize(0, 0);
return; 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; return;
} }
UINT32 length = static_cast<UINT32>(_sText.getLength()); UINT32 length = UINT32(_text.getLength());
// 创建 TextLayout // 创建 TextLayout
HRESULT hr; HRESULT hr;
// 对文本自动换行情况下进行处理 // 对文本自动换行情况下进行处理
if (_TextStyle.wrapping) if (_style.wrapping)
{ {
hr = Renderer::getIDWriteFactory()->CreateTextLayout( hr = Renderer::getIDWriteFactory()->CreateTextLayout(
_sText, _text,
length, length,
_pDWriteTextFormat, _textFormat,
static_cast<FLOAT>(_TextStyle.wrappingWidth), float(_style.wrappingWidth),
0, 0,
&_pDWriteTextLayout &_textLayout
); );
if (_pDWriteTextLayout) if (_textLayout)
{ {
// 获取文本布局的宽度和高度 // 获取文本布局的宽度和高度
DWRITE_TEXT_METRICS metrics; DWRITE_TEXT_METRICS metrics;
_pDWriteTextLayout->GetMetrics(&metrics); _textLayout->GetMetrics(&metrics);
// 重设文本宽高 // 重设文本宽高
this->setSize(metrics.layoutWidth, metrics.height); this->setSize(metrics.layoutWidth, metrics.height);
} }
} }
else else
{ {
hr = Renderer::getIDWriteFactory()->CreateTextLayout(_sText, length, _pDWriteTextFormat, 0, 0, &_pDWriteTextLayout); hr = Renderer::getIDWriteFactory()->CreateTextLayout(_text, length, _textFormat, 0, 0, &_textLayout);
// 为防止文本对齐问题,根据刚才创建的 layout 宽度重新创建它 // 为防止文本对齐问题,根据刚才创建的 layout 宽度重新创建它
if (_pDWriteTextLayout) if (_textLayout)
{ {
// 获取文本布局的宽度和高度 // 获取文本布局的宽度和高度
DWRITE_TEXT_METRICS metrics; DWRITE_TEXT_METRICS metrics;
_pDWriteTextLayout->GetMetrics(&metrics); _textLayout->GetMetrics(&metrics);
// 重设文本宽高 // 重设文本宽高
this->setSize(metrics.width, metrics.height); this->setSize(metrics.width, metrics.height);
// 重新创建 layout // 重新创建 layout
SafeReleaseInterface(&_pDWriteTextLayout); SafeReleaseInterface(&_textLayout);
hr = Renderer::getIDWriteFactory()->CreateTextLayout(_sText, length, _pDWriteTextFormat, _fWidth, 0, &_pDWriteTextLayout); hr = Renderer::getIDWriteFactory()->CreateTextLayout(_text, length, _textFormat, _width, 0, &_textLayout);
} }
} }
@ -419,12 +419,12 @@ void e2d::Text::_createLayout()
// 添加下划线和删除线 // 添加下划线和删除线
DWRITE_TEXT_RANGE range = { 0, length }; 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);
} }
} }

View File

@ -762,7 +762,7 @@ double e2d::Music::getVolume()
void e2d::Music::setVolume(double fVolume) void e2d::Music::setVolume(double fVolume)
{ {
s_fMusicVolume = min(max(static_cast<float>(fVolume), -224), 224); s_fMusicVolume = min(max(float(fVolume), -224), 224);
for (auto pair : GetMusicFileList()) for (auto pair : GetMusicFileList())
{ {
pair.second->setVolume(s_fMusicVolume); pair.second->setVolume(s_fMusicVolume);

View File

@ -1,21 +1,135 @@
#include "..\e2dbase.h"
#include "..\e2dtransition.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();
} }

View File

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

View File

@ -2,21 +2,21 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::TransitionEmerge::TransitionEmerge(double duration) e2d::TransitionEmerge::TransitionEmerge(double duration)
: TransitionBase(duration) : Transition(duration)
{ {
} }
void e2d::TransitionEmerge::_init(Scene * prev, Scene * next) void e2d::TransitionEmerge::_init(Scene * prev, Scene * next)
{ {
TransitionBase::_init(prev, next); Transition::_init(prev, next);
_sPrevLayerParam.opacity = 1; _outLayerParam.opacity = 1;
_sNextLayerParam.opacity = 0; _inLayerParam.opacity = 0;
} }
void e2d::TransitionEmerge::_updateCustom() void e2d::TransitionEmerge::_updateCustom()
{ {
_sPrevLayerParam.opacity = float(1 - _delta); _outLayerParam.opacity = float(1 - _delta);
_sNextLayerParam.opacity = float(_delta); _inLayerParam.opacity = float(_delta);
if (_delta >= 1) if (_delta >= 1)
{ {

View File

@ -2,53 +2,53 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::TransitionFade::TransitionFade(double duration) e2d::TransitionFade::TransitionFade(double duration)
: TransitionBase(0) : Transition(0)
, _fFadeOutDuration(max(duration / 2, 0)) , _fadeOutDuration(max(duration / 2, 0))
, _fFadeInDuration(max(duration / 2, 0)) , _fadeInDuration(max(duration / 2, 0))
, _bFadeOutTransioning(true) , _fadeOutTransioning(true)
{ {
} }
e2d::TransitionFade::TransitionFade(double fadeOutDuration, double fadeInDuration) e2d::TransitionFade::TransitionFade(double fadeOutDuration, double fadeInDuration)
: TransitionBase(0) : Transition(0)
, _fFadeOutDuration(max(fadeOutDuration, 0)) , _fadeOutDuration(max(fadeOutDuration, 0))
, _fFadeInDuration(max(fadeInDuration, 0)) , _fadeInDuration(max(fadeInDuration, 0))
, _bFadeOutTransioning(true) , _fadeOutTransioning(true)
{ {
} }
void e2d::TransitionFade::_init(Scene * prev, Scene * next) void e2d::TransitionFade::_init(Scene * prev, Scene * next)
{ {
TransitionBase::_init(prev, next); Transition::_init(prev, next);
if (_pPrevScene) if (_outScene)
{ {
_bFadeOutTransioning = true; _fadeOutTransioning = true;
_duration = _fFadeOutDuration; _duration = _fadeOutDuration;
} }
else else
{ {
_bFadeOutTransioning = false; _fadeOutTransioning = false;
_duration = _fFadeInDuration; _duration = _fadeInDuration;
} }
_sPrevLayerParam.opacity = 1; _outLayerParam.opacity = 1;
_sNextLayerParam.opacity = 0; _inLayerParam.opacity = 0;
} }
void e2d::TransitionFade::_updateCustom() void e2d::TransitionFade::_updateCustom()
{ {
if (_bFadeOutTransioning) if (_fadeOutTransioning)
{ {
_sPrevLayerParam.opacity = float(1 - _delta); _outLayerParam.opacity = float(1 - _delta);
if (_delta >= 1) if (_delta >= 1)
{ {
_bFadeOutTransioning = false; _fadeOutTransioning = false;
_duration = _fFadeInDuration; _duration = _fadeInDuration;
_fLast = Time::getTotalTime(); _last = Time::getTotalTime();
} }
} }
else else
{ {
_sNextLayerParam.opacity = float(_delta); _inLayerParam.opacity = float(_delta);
if (_delta >= 1) if (_delta >= 1)
{ {
this->_stop(); this->_stop();

View File

@ -1,52 +1,52 @@
#include "..\e2dtransition.h" #include "..\e2dtransition.h"
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::TransitionMove::TransitionMove(double duration, Direct direct) e2d::TransitionMove::TransitionMove(double duration, Direction direction)
: TransitionBase(duration) : Transition(duration)
, _Direct(direct) , _direction(direction)
{ {
} }
void e2d::TransitionMove::_init(Scene * prev, Scene * next) void e2d::TransitionMove::_init(Scene * prev, Scene * next)
{ {
TransitionBase::_init(prev, next); Transition::_init(prev, next);
double width = _WindowSize.width; double width = _windowSize.width;
double height = _WindowSize.height; double height = _windowSize.height;
if (_Direct == Direct::UP) if (_direction == Direction::UP)
{ {
_Vector = Vector(0, -height); _posDelta = Vector(0, -height);
_NextPos = Point(0, height); _startPos = Point(0, height);
} }
else if (_Direct == Direct::DOWN) else if (_direction == Direction::DOWN)
{ {
_Vector = Vector(0, height); _posDelta = Vector(0, height);
_NextPos = Point(0, -height); _startPos = Point(0, -height);
} }
else if (_Direct == Direct::LEFT) else if (_direction == Direction::LEFT)
{ {
_Vector = Vector(-width, 0); _posDelta = Vector(-width, 0);
_NextPos = Point(width, 0); _startPos = Point(width, 0);
} }
else if (_Direct == Direct::RIGHT) else if (_direction == Direction::RIGHT)
{ {
_Vector = Vector(width, 0); _posDelta = Vector(width, 0);
_NextPos = Point(-width, 0); _startPos = Point(-width, 0);
} }
if (_pPrevScene) _pPrevScene->getRoot()->setPos(0, 0); if (_outScene) _outScene->getRoot()->setPos(0, 0);
_pNextScene->getRoot()->setPos(_NextPos); _inScene->getRoot()->setPos(_startPos);
} }
void e2d::TransitionMove::_updateCustom() 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) if (_delta >= 1)
@ -57,7 +57,7 @@ void e2d::TransitionMove::_updateCustom()
void e2d::TransitionMove::_reset() void e2d::TransitionMove::_reset()
{ {
if (_pPrevScene) _pPrevScene->getRoot()->setPos(0, 0); if (_outScene) _outScene->getRoot()->setPos(0, 0);
_pNextScene->getRoot()->setPos(0, 0); _inScene->getRoot()->setPos(0, 0);
} }

View File

@ -84,7 +84,7 @@ protected:
bool _done; bool _done;
bool _initialized; bool _initialized;
Node * _target; Node * _target;
double _fLast; double _last;
}; };

View File

@ -65,12 +65,12 @@ protected:
virtual void _render(); virtual void _render();
protected: protected:
bool _bEnable; bool _enable;
bool _bIsVisiable; bool _visiable;
bool _bAutoResize; bool _autoResize;
Color _nColor; Color _color;
Node * _pParentNode; Node * _parentNode;
ID2D1TransformedGeometry * _pTransformedGeometry; ID2D1TransformedGeometry * _transformed;
}; };
@ -113,7 +113,7 @@ protected:
virtual void _resize(); virtual void _resize();
protected: protected:
ID2D1RectangleGeometry * _pD2dRectangle; ID2D1RectangleGeometry * _d2dRectangle;
}; };
@ -152,7 +152,7 @@ protected:
virtual void _resize(); virtual void _resize();
protected: protected:
ID2D1EllipseGeometry * _pD2dCircle; ID2D1EllipseGeometry * _d2dCircle;
}; };
@ -193,7 +193,7 @@ protected:
virtual void _resize(); virtual void _resize();
protected: protected:
ID2D1EllipseGeometry * _pD2dEllipse; ID2D1EllipseGeometry * _d2dEllipse;
}; };
} }

View File

@ -11,15 +11,16 @@ namespace e2d
{ {
struct Size; class Size;
// 表示坐标的结构体 // 表示坐标的结构体
struct Point class Point
{ {
public:
double x; // X 坐标 double x; // X 坐标
double y; // Y 坐标 double y; // Y 坐标
/* 构造函数 */ public:
Point(); Point();
Point(double x, double y); Point(double x, double y);
@ -37,12 +38,13 @@ struct Point
typedef Point Vector; typedef Point Vector;
// 表示大小的结构体 // 表示大小的结构体
struct Size class Size
{ {
public:
double width; // 宽度 double width; // 宽度
double height; // 高度 double height; // 高度
/* 构造函数 */ public:
Size(); Size();
Size(double width, double height); Size(double width, double height);
@ -311,7 +313,7 @@ protected:
double alpha double alpha
); );
protected: public:
float r; float r;
float g; float g;
float b; float b;
@ -429,7 +431,7 @@ enum class Cursor : int
// 方向 // 方向
enum class Direct : int enum class Direction : int
{ {
UP, /* 上 */ UP, /* 上 */
DOWN, /* 下 */ DOWN, /* 下 */
@ -477,8 +479,9 @@ enum class ColliderType : int
// 文本样式 // 文本样式
struct TextStyle class TextStyle
{ {
public:
String fontFamily; // 字体 String fontFamily; // 字体
double fontSize; // 字号 double fontSize; // 字号
Color color; // 颜色 Color color; // 颜色
@ -495,7 +498,7 @@ struct TextStyle
double outlineWidth; // 描边线宽 double outlineWidth; // 描边线宽
LineJoin outlineJoin; // 描边线相交样式 LineJoin outlineJoin; // 描边线相交样式
/* 构造函数 */ public:
TextStyle(); TextStyle();
TextStyle( TextStyle(
@ -593,7 +596,7 @@ public:
virtual void onDestroy() {} virtual void onDestroy() {}
private: private:
int _nRefCount; int _refCount;
}; };
@ -701,24 +704,24 @@ public:
static void clearCache(); static void clearCache();
protected: protected:
double _fSourceCropX; double _cropX;
double _fSourceCropY; double _cropY;
double _fSourceCropWidth; double _cropWidth;
double _fSourceCropHeight; double _cropHeight;
ID2D1Bitmap * _pBitmap; ID2D1Bitmap * _bitmap;
}; };
class Node; class Node;
class SceneManager; class SceneManager;
class TransitionBase; class Transition;
// 场景 // 场景
class Scene : class Scene :
public Object public Object
{ {
friend SceneManager; friend SceneManager;
friend TransitionBase; friend Transition;
public: public:
Scene(); Scene();
@ -799,11 +802,9 @@ protected:
void _update(); void _update();
protected: protected:
bool _bAutoUpdate; bool _autoUpdate;
bool _bSortNeeded; bool _colliderVisiable;
bool _bWillSave; Node * _root;
bool _bColliderVisiable;
Node * _pRoot;
}; };

View File

@ -13,7 +13,7 @@ class Timer;
class Action; class Action;
class Music; class Music;
class Collider; class Collider;
class TransitionBase; class Transition;
// 对象管理器 // 对象管理器
class ObjectManager class ObjectManager
@ -49,13 +49,13 @@ public:
// 切换场景 // 切换场景
static void enter( static void enter(
Scene * scene, /* 下一个场景的指针 */ Scene * scene, /* 下一个场景的指针 */
TransitionBase * transition = nullptr, /* 场景切换动画 */ Transition * transition = nullptr, /* 场景切换动画 */
bool saveCurrentScene = true /* 是否保存当前场景 */ bool saveCurrentScene = true /* 是否保存当前场景 */
); );
// 返回上一场景 // 返回上一场景
static void back( static void back(
TransitionBase * transition = nullptr /* 场景切换动画 */ Transition * transition = nullptr /* 场景切换动画 */
); );
// 清空保存的所有场景 // 清空保存的所有场景

View File

@ -6,7 +6,7 @@ namespace e2d
class Action; class Action;
class TransitionBase; class Transition;
class Collider; class Collider;
class ColliderManager; class ColliderManager;
@ -15,7 +15,7 @@ class Node :
{ {
friend Scene; friend Scene;
friend Collider; friend Collider;
friend TransitionBase; friend Transition;
friend ColliderManager; friend ColliderManager;
public: public:
@ -443,33 +443,33 @@ protected:
protected: protected:
String _name; String _name;
unsigned _nHashName; unsigned _hashName;
float _fPosX; float _posX;
float _fPosY; float _posY;
float _fWidth; float _width;
float _fHeight; float _height;
float _fScaleX; float _scaleX;
float _fScaleY; float _scaleY;
float _fRotation; float _rotation;
float _fSkewAngleX; float _skewAngleX;
float _fSkewAngleY; float _skewAngleY;
float _fDisplayOpacity; float _displayOpacity;
float _fRealOpacity; float _realOpacity;
float _fPivotX; float _pivotX;
float _fPivotY; float _pivotY;
int _nOrder; int _nOrder;
bool _bVisiable; bool _visiable;
bool _bAutoUpdate; bool _autoUpdate;
bool _bSortChildrenNeeded; bool _needSort;
bool _bTransformNeeded; bool _needTransform;
bool _bPositionFixed; bool _positionFixed;
Collider * _pCollider; Collider * _collider;
Scene * _pParentScene; Scene * _parentScene;
Node * _pParent; Node * _parent;
D2D1::Matrix3x2F _MatriInitial; D2D1::Matrix3x2F _initialMatri;
D2D1::Matrix3x2F _MatriFinal; D2D1::Matrix3x2F _finalMatri;
std::set<unsigned int> _vColliders; std::set<unsigned int> _colliders;
std::vector<Node*> _vChildren; std::vector<Node*> _children;
}; };
@ -551,7 +551,7 @@ public:
virtual void onDestroy() override; virtual void onDestroy() override;
protected: protected:
Image * _pImage; Image * _image;
}; };
@ -735,10 +735,10 @@ protected:
void _createLayout(); void _createLayout();
protected: protected:
String _sText; String _text;
TextStyle _TextStyle; TextStyle _style;
IDWriteTextFormat * _pDWriteTextFormat; IDWriteTextFormat * _textFormat;
IDWriteTextLayout * _pDWriteTextLayout; IDWriteTextLayout * _textLayout;
}; };
@ -829,13 +829,13 @@ protected:
virtual void _runCallback(); virtual void _runCallback();
protected: protected:
Node * _pNormal; Node * _normal;
Node * _pMouseover; Node * _mouseover;
Node * _pSelected; Node * _selected;
Node * _pDisabled; Node * _disabled;
bool _bEnable; bool _enable;
bool _bIsSelected; bool _isSelected;
ButtonState _eBtnState; ButtonState _state;
Function _func; Function _func;
}; };
@ -943,15 +943,11 @@ protected:
virtual void _runCallback() override; virtual void _runCallback() override;
protected: protected:
Node * _pNormalOn; Node * _normalOff;
Node * _pNormalOff; Node * _mouseoverOff;
Node * _pMouseoverOn; Node * _selectedOff;
Node * _pMouseoverOff; Node * _disabledOff;
Node * _pSelectedOn; bool _toggle;
Node * _pSelectedOff;
Node * _pDisabledOn;
Node * _pDisabledOff;
bool _bState;
}; };
@ -998,8 +994,8 @@ public:
); );
protected: protected:
bool _bEnable; bool _enable;
std::vector<Button*> _vButtons; std::vector<Button*> _buttons;
}; };
} }

View File

@ -55,10 +55,10 @@ protected:
virtual void _renderFill() = 0; virtual void _renderFill() = 0;
protected: protected:
ShapeStyle _nStyle; ShapeStyle _style;
float _fStrokeWidth; float _strokeWidth;
Color _nLineColor; Color _lineColor;
Color _nFillColor; Color _fillColor;
}; };
@ -163,8 +163,8 @@ protected:
virtual void _renderFill() override; virtual void _renderFill() override;
protected: protected:
float _fRadiusX; float _radiusX;
float _fRadiusY; float _radiusY;
}; };
@ -208,7 +208,7 @@ protected:
virtual void _renderFill() override; virtual void _renderFill() override;
protected: protected:
float _fRadius; float _radius;
}; };
@ -263,8 +263,8 @@ protected:
virtual void _renderFill() override; virtual void _renderFill() override;
protected: protected:
float _fRadiusX; float _radiusX;
float _fRadiusY; float _radiusY;
}; };
} }

View File

@ -6,49 +6,18 @@ namespace e2d
class SceneManager; 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 public Object
{ {
friend SceneManager; friend SceneManager;
public: public:
TransitionBase(double duration); Transition(double duration);
virtual ~TransitionBase(); virtual ~Transition();
// 场景切换动画是否结束 // 场景切换动画是否结束
bool isDone(); bool isDone();
@ -79,22 +48,22 @@ protected:
virtual void _stop(); virtual void _stop();
protected: protected:
bool _bEnd; bool _end;
double _fLast; double _last;
double _duration; double _duration;
double _delta; double _delta;
Size _WindowSize; Size _windowSize;
Scene * _pPrevScene; Scene * _outScene;
Scene * _pNextScene; Scene * _inScene;
ID2D1Layer * _pPrevLayer; ID2D1Layer * _outLayer;
ID2D1Layer * _pNextLayer; ID2D1Layer * _inLayer;
D2D1_LAYER_PARAMETERS _sPrevLayerParam; D2D1_LAYER_PARAMETERS _outLayerParam;
D2D1_LAYER_PARAMETERS _sNextLayerParam; D2D1_LAYER_PARAMETERS _inLayerParam;
}; };
class TransitionFade : class TransitionFade :
public TransitionBase public Transition
{ {
public: public:
// 创建淡入淡出式的场景切换动画 // 创建淡入淡出式的场景切换动画
@ -120,14 +89,14 @@ protected:
virtual void _reset() override; virtual void _reset() override;
protected: protected:
double _fFadeOutDuration; double _fadeOutDuration;
double _fFadeInDuration; double _fadeInDuration;
bool _bFadeOutTransioning; bool _fadeOutTransioning;
}; };
class TransitionEmerge : class TransitionEmerge :
public TransitionBase public Transition
{ {
public: public:
// 创建浮现式的场景切换动画 // 创建浮现式的场景切换动画
@ -149,13 +118,13 @@ protected:
class TransitionMove : class TransitionMove :
public TransitionBase public Transition
{ {
public: public:
// 创建移动式的场景切换动画 // 创建移动式的场景切换动画
TransitionMove( TransitionMove(
double moveDuration, /* 场景移动动画持续时长 */ double moveDuration, /* 场景移动动画持续时长 */
Direct direct = Direct::LEFT /* 场景移动方向 */ Direction direction = Direction::LEFT /* 场景移动方向 */
); );
protected: protected:
@ -170,9 +139,9 @@ protected:
virtual void _reset() override; virtual void _reset() override;
protected: protected:
Direct _Direct; Direction _direction;
Vector _Vector; Vector _posDelta;
Point _NextPos; Point _startPos;
}; };
} }

View File

@ -253,7 +253,6 @@
<ClCompile Include="..\..\core\Tool\Random.cpp" /> <ClCompile Include="..\..\core\Tool\Random.cpp" />
<ClCompile Include="..\..\core\Tool\Timer.cpp" /> <ClCompile Include="..\..\core\Tool\Timer.cpp" />
<ClCompile Include="..\..\core\Transition\Transition.cpp" /> <ClCompile Include="..\..\core\Transition\Transition.cpp" />
<ClCompile Include="..\..\core\Transition\TransitionBase.cpp" />
<ClCompile Include="..\..\core\Transition\TransitionEmerge.cpp" /> <ClCompile Include="..\..\core\Transition\TransitionEmerge.cpp" />
<ClCompile Include="..\..\core\Transition\TransitionFade.cpp" /> <ClCompile Include="..\..\core\Transition\TransitionFade.cpp" />
<ClCompile Include="..\..\core\Transition\TransitionMove.cpp" /> <ClCompile Include="..\..\core\Transition\TransitionMove.cpp" />

View File

@ -168,12 +168,6 @@
<ClCompile Include="..\..\core\Common\Function.cpp"> <ClCompile Include="..\..\core\Common\Function.cpp">
<Filter>Common</Filter> <Filter>Common</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\Transition\TransitionBase.cpp">
<Filter>Transition</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Transition\Transition.cpp">
<Filter>Transition</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Action\Action.cpp"> <ClCompile Include="..\..\core\Action\Action.cpp">
<Filter>Action</Filter> <Filter>Action</Filter>
</ClCompile> </ClCompile>
@ -216,6 +210,9 @@
<ClCompile Include="..\..\core\Action\Spawn.cpp"> <ClCompile Include="..\..\core\Action\Spawn.cpp">
<Filter>Action</Filter> <Filter>Action</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\Transition\Transition.cpp">
<Filter>Transition</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />