Refactoring: getter & setter coding style

This commit is contained in:
Nomango 2018-08-23 16:37:44 +08:00
parent 8323a245ee
commit 0905c91dd0
56 changed files with 1330 additions and 1272 deletions

View File

@ -7,12 +7,12 @@ e2d::Action::Action()
, _initialized(false) , _initialized(false)
, _target(nullptr) , _target(nullptr)
{ {
ActionManager::getInstance()->__add(this); ActionManager::instance()->__add(this);
} }
e2d::Action::~Action() e2d::Action::~Action()
{ {
ActionManager::getInstance()->__remove(this); ActionManager::instance()->__remove(this);
} }
bool e2d::Action::isRunning() bool e2d::Action::isRunning()
@ -35,17 +35,17 @@ void e2d::Action::stop()
_done = true; _done = true;
} }
e2d::String e2d::Action::getName() const const e2d::String& e2d::Action::name() const
{ {
return _name; return _name;
} }
void e2d::Action::setName(const String& name) void e2d::Action::name(const String& name)
{ {
_name = name; _name = name;
} }
e2d::Node * e2d::Action::getTarget() e2d::Node * e2d::Action::target()
{ {
return _target; return _target;
} }

View File

@ -11,22 +11,22 @@ e2d::Animate::Animate(Animation * animation)
: _frameIndex(0) : _frameIndex(0)
, _animation(nullptr) , _animation(nullptr)
{ {
this->setAnimation(animation); this->animation(animation);
} }
e2d::Animate::~Animate() e2d::Animate::~Animate()
{ {
GC::getInstance()->safeRelease(_animation); GC::instance()->safeRelease(_animation);
} }
e2d::Animation * e2d::Animate::getAnimation() const e2d::Animation * e2d::Animate::animation() const
{ {
return _animation; return _animation;
} }
void e2d::Animate::setAnimation(Animation * animation) void e2d::Animate::animation(Animation * animation)
{ {
if (animation && animation != _animation && !animation->getFrames().empty()) if (animation && animation != _animation && !animation->frames().empty())
{ {
if (_animation) _animation->release(); if (_animation) _animation->release();
_animation = animation; _animation = animation;
@ -41,7 +41,7 @@ void e2d::Animate::_init()
auto target = dynamic_cast<Sprite*>(_target); auto target = dynamic_cast<Sprite*>(_target);
if (target && _animation) if (target && _animation)
{ {
target->open(_animation->getFrames()[_frameIndex]); target->open(_animation->frames()[_frameIndex]);
++_frameIndex; ++_frameIndex;
} }
} }
@ -56,9 +56,9 @@ void e2d::Animate::_update()
return; return;
} }
while ((Time::now() - _started).seconds() >= _animation->getInterval()) while ((Time::now() - _started).seconds() >= _animation->interval())
{ {
auto& frames = _animation->getFrames(); auto& frames = _animation->frames();
auto target = dynamic_cast<Sprite*>(_target); auto target = dynamic_cast<Sprite*>(_target);
if (target) if (target)
@ -66,7 +66,7 @@ void e2d::Animate::_update()
target->open(frames[_frameIndex]); target->open(frames[_frameIndex]);
} }
_started += Duration(_animation->getInterval()); _started += Duration(_animation->interval());
++_frameIndex; ++_frameIndex;
if (_frameIndex == frames.size()) if (_frameIndex == frames.size())

View File

@ -26,16 +26,17 @@ e2d::Animation::~Animation()
{ {
for (const auto& frame : _frames) for (const auto& frame : _frames)
{ {
GC::getInstance()->safeRelease(frame); GC::instance()->safeRelease(frame);
} }
} }
void e2d::Animation::setInterval(float interval) e2d::Animation& e2d::Animation::interval(float interval)
{ {
_interval = std::max(interval, 0.f); _interval = std::max(interval, 0.f);
return *this;
} }
void e2d::Animation::add(Image * frame) e2d::Animation& e2d::Animation::add(Image * frame)
{ {
WARN_IF(frame == nullptr, "Animation::add failed, frame is nullptr."); WARN_IF(frame == nullptr, "Animation::add failed, frame is nullptr.");
if (frame) if (frame)
@ -43,22 +44,24 @@ void e2d::Animation::add(Image * frame)
_frames.push_back(frame); _frames.push_back(frame);
frame->retain(); frame->retain();
} }
return *this;
} }
void e2d::Animation::add(const std::vector<Image*>& frames) e2d::Animation& e2d::Animation::add(const std::vector<Image*>& frames)
{ {
for (const auto &image : frames) for (const auto &image : frames)
{ {
this->add(image); this->add(image);
} }
return *this;
} }
float e2d::Animation::getInterval() const float e2d::Animation::interval() const
{ {
return _interval; return _interval;
} }
const std::vector<e2d::Image*>& e2d::Animation::getFrames() const const std::vector<e2d::Image*>& e2d::Animation::frames() const
{ {
return _frames; return _frames;
} }
@ -78,7 +81,7 @@ e2d::Animation * e2d::Animation::clone() const
e2d::Animation * e2d::Animation::reverse() const e2d::Animation * e2d::Animation::reverse() const
{ {
auto& oldFrames = this->getFrames(); auto& oldFrames = this->frames();
std::vector<Image*> frames(oldFrames.size()); std::vector<Image*> frames(oldFrames.size());
if (!oldFrames.empty()) if (!oldFrames.empty())
@ -96,5 +99,5 @@ e2d::Animation * e2d::Animation::reverse() const
} }
} }
return new (e2d::autorelease) Animation(this->getInterval(), frames); return new (e2d::autorelease) Animation(this->interval(), frames);
} }

View File

@ -25,7 +25,7 @@ void e2d::JumpBy::_init()
if (_target) if (_target)
{ {
_prevPos = _startPos = _target->getPos(); _prevPos = _startPos = _target->position();
} }
} }
@ -40,13 +40,13 @@ void e2d::JumpBy::_update()
float y = _height * 4 * frac * (1 - frac); float y = _height * 4 * frac * (1 - frac);
y += _deltaPos.y * _delta; y += _deltaPos.y * _delta;
Point currentPos = _target->getPos(); Point currentPos = _target->position();
Vector2 diff = currentPos - _prevPos; Vector2 diff = currentPos - _prevPos;
_startPos = diff + _startPos; _startPos = diff + _startPos;
Point newPos = _startPos + Vector2(x, y); Point newPos = _startPos + Vector2(x, y);
_target->setPos(newPos); _target->position(newPos);
_prevPos = newPos; _prevPos = newPos;
} }

View File

@ -17,7 +17,7 @@ e2d::Loop::Loop(Action * action, int times /* = -1 */)
e2d::Loop::~Loop() e2d::Loop::~Loop()
{ {
GC::getInstance()->safeRelease(_action); GC::instance()->safeRelease(_action);
} }
e2d::Loop * e2d::Loop::clone() const e2d::Loop * e2d::Loop::clone() const

View File

@ -14,7 +14,7 @@ void e2d::MoveBy::_init()
if (_target) if (_target)
{ {
_prevPos = _startPos = _target->getPos(); _prevPos = _startPos = _target->position();
} }
} }
@ -24,12 +24,12 @@ void e2d::MoveBy::_update()
if (_target) if (_target)
{ {
Point currentPos = _target->getPos(); Point currentPos = _target->position();
Vector2 diff = currentPos - _prevPos; Vector2 diff = currentPos - _prevPos;
_startPos = _startPos + diff; _startPos = _startPos + diff;
Point newPos = _startPos + (_deltaPos * _delta); Point newPos = _startPos + (_deltaPos * _delta);
_target->setPos(newPos); _target->position(newPos);
_prevPos = newPos; _prevPos = newPos;
} }

View File

@ -14,7 +14,7 @@ void e2d::OpacityBy::_init()
if (_target) if (_target)
{ {
_startVal = _target->getOpacity(); _startVal = _target->opacity();
} }
} }
@ -24,7 +24,7 @@ void e2d::OpacityBy::_update()
if (_target) if (_target)
{ {
_target->setOpacity(_startVal + _deltaVal * _delta); _target->opacity(_startVal + _deltaVal * _delta);
} }
} }

View File

@ -14,7 +14,7 @@ void e2d::RotateBy::_init()
if (_target) if (_target)
{ {
_startVal = _target->getRotation(); _startVal = _target->rotation();
} }
} }
@ -24,7 +24,7 @@ void e2d::RotateBy::_update()
if (_target) if (_target)
{ {
_target->setRotation(_startVal + _deltaVal * _delta); _target->rotation(_startVal + _deltaVal * _delta);
} }
} }

View File

@ -22,8 +22,8 @@ void e2d::ScaleBy::_init()
if (_target) if (_target)
{ {
_startScaleX = _target->getScaleX(); _startScaleX = _target->scaleX();
_startScaleY = _target->getScaleY(); _startScaleY = _target->scaleY();
} }
} }
@ -33,7 +33,7 @@ void e2d::ScaleBy::_update()
if (_target) if (_target)
{ {
_target->setScale(_startScaleX + _deltaX * _delta, _startScaleY + _deltaY * _delta); _target->scale(_startScaleX + _deltaX * _delta, _startScaleY + _deltaY * _delta);
} }
} }

View File

@ -15,7 +15,7 @@ e2d::Sequence::~Sequence()
{ {
for (const auto& action : _actions) for (const auto& action : _actions)
{ {
GC::getInstance()->safeRelease(action); GC::instance()->safeRelease(action);
} }
} }

View File

@ -13,7 +13,7 @@ e2d::Spawn::~Spawn()
{ {
for (const auto& action : _actions) for (const auto& action : _actions)
{ {
GC::getInstance()->safeRelease(action); GC::instance()->safeRelease(action);
} }
} }

View File

@ -11,7 +11,7 @@ void * operator new(size_t size, e2d::autorelease_t const &) E2D_NOEXCEPT
void* p = ::operator new(size, std::nothrow); void* p = ::operator new(size, std::nothrow);
if (p) if (p)
{ {
GC::getInstance()->autorelease(static_cast<Ref*>(p)); GC::instance()->autorelease(static_cast<Ref*>(p));
} }
return p; return p;
} }
@ -47,7 +47,7 @@ void e2d::GC::flush()
_notifyed = false; _notifyed = false;
for (auto iter = _pool.begin(); iter != _pool.end();) for (auto iter = _pool.begin(); iter != _pool.end();)
{ {
if ((*iter)->getRefCount() <= 0) if ((*iter)->refCount() <= 0)
{ {
delete (*iter); delete (*iter);
iter = _pool.erase(iter); iter = _pool.erase(iter);
@ -63,9 +63,9 @@ void e2d::GC::clear()
{ {
_cleanup = true; _cleanup = true;
Game::getInstance()->clearAllScenes(); Game::instance()->clearAllScenes();
Timer::getInstance()->clearAllTasks(); Timer::instance()->clearAllTasks();
ActionManager::getInstance()->clearAll(); ActionManager::instance()->clearAll();
for (const auto& ref : _pool) for (const auto& ref : _pool)
{ {
@ -75,7 +75,7 @@ void e2d::GC::clear()
_cleanup = false; _cleanup = false;
} }
e2d::GC * e2d::GC::getInstance() e2d::GC * e2d::GC::instance()
{ {
static GC _instance; static GC _instance;
return &_instance; return &_instance;

View File

@ -21,8 +21,8 @@ e2d::Game::Game()
_input = new (std::nothrow) Input; _input = new (std::nothrow) Input;
_renderer = new (std::nothrow) Renderer; _renderer = new (std::nothrow) Renderer;
_timer = Timer::getInstance(); _timer = Timer::instance();
_actionManager = ActionManager::getInstance(); _actionManager = ActionManager::instance();
} }
e2d::Game::~Game() e2d::Game::~Game()
@ -36,7 +36,7 @@ e2d::Game::~Game()
CoUninitialize(); CoUninitialize();
} }
e2d::Game * e2d::Game::getInstance() e2d::Game * e2d::Game::instance()
{ {
static Game instance; static Game instance;
return &instance; return &instance;
@ -55,7 +55,7 @@ void e2d::Game::start()
const int minInterval = 5; const int minInterval = 5;
Time last = Time::now(); Time last = Time::now();
HWND hWnd = _window->getHWnd(); HWND hWnd = _window->hWnd();
::ShowWindow(hWnd, SW_SHOWNORMAL); ::ShowWindow(hWnd, SW_SHOWNORMAL);
::UpdateWindow(hWnd); ::UpdateWindow(hWnd);
@ -81,7 +81,7 @@ void e2d::Game::start()
drawScene(); drawScene();
_window->poll(); _window->poll();
GC::getInstance()->flush(); GC::instance()->flush();
} }
else else
{ {
@ -112,7 +112,7 @@ void e2d::Game::resume()
_paused = false; _paused = false;
} }
bool e2d::Game::isPaused() bool e2d::Game::paused()
{ {
return _paused; return _paused;
} }
@ -218,17 +218,17 @@ void e2d::Game::clearAllScenes()
} }
} }
e2d::Scene * e2d::Game::getCurrentScene() e2d::Scene * e2d::Game::currentScene()
{ {
return _currScene; return _currScene;
} }
const std::stack<e2d::Scene*>& e2d::Game::getSceneStack() const std::stack<e2d::Scene*>& e2d::Game::sceneStack()
{ {
return _scenes; return _scenes;
} }
bool e2d::Game::isTransitioning() const bool e2d::Game::transitioning() const
{ {
return _transition != nullptr; return _transition != nullptr;
} }
@ -239,7 +239,7 @@ void e2d::Game::updateScene()
{ {
_transition->_update(); _transition->_update();
if (_transition->isDone()) if (_transition->done())
{ {
_transition->release(); _transition->release();
_transition = nullptr; _transition = nullptr;

View File

@ -40,7 +40,7 @@ e2d::Input::~Input()
void e2d::Input::initWithWindow(Window * window) void e2d::Input::initWithWindow(Window * window)
{ {
HWND hwnd = window->getHWnd(); HWND hwnd = window->hWnd();
// 初始化键盘设备 // 初始化键盘设备
ThrowIfFailed( ThrowIfFailed(
@ -118,39 +118,39 @@ bool e2d::Input::isDown(MouseCode code)
return false; return false;
} }
float e2d::Input::getMouseX() float e2d::Input::mouseX()
{ {
return getMousePos().x; return mousePos().x;
} }
float e2d::Input::getMouseY() float e2d::Input::mouseY()
{ {
return getMousePos().y; return mousePos().y;
} }
e2d::Point e2d::Input::getMousePos() e2d::Point e2d::Input::mousePos()
{ {
auto window = Game::getInstance()->getWindow(); auto window = Game::instance()->window();
POINT mousePos; POINT mousePos;
::GetCursorPos(&mousePos); ::GetCursorPos(&mousePos);
::ScreenToClient(window->getHWnd(), &mousePos); ::ScreenToClient(window->hWnd(), &mousePos);
float dpi = window->getDpi(); float dpi = window->dpi();
return Point(mousePos.x * 96.f / dpi, mousePos.y * 96.f / dpi); return Point(mousePos.x * 96.f / dpi, mousePos.y * 96.f / dpi);
} }
float e2d::Input::getMouseDeltaX() float e2d::Input::mouseDeltaX()
{ {
return (float)_mouseState.lX; return (float)_mouseState.lX;
} }
float e2d::Input::getMouseDeltaY() float e2d::Input::mouseDeltaY()
{ {
return (float)_mouseState.lY; return (float)_mouseState.lY;
} }
float e2d::Input::getMouseDeltaZ() float e2d::Input::mouseDeltaZ()
{ {
return (float)_mouseState.lZ; return (float)_mouseState.lZ;
} }

View File

@ -68,7 +68,7 @@ e2d::Renderer::~Renderer()
void e2d::Renderer::initWithWindow(Window * window) void e2d::Renderer::initWithWindow(Window * window)
{ {
HWND hWnd = window->getHWnd(); HWND hWnd = window->hWnd();
RECT rc; RECT rc;
GetClientRect(hWnd, &rc); GetClientRect(hWnd, &rc);
@ -205,12 +205,12 @@ void e2d::Renderer::endDraw()
} }
} }
e2d::Color e2d::Renderer::getBackgroundColor() e2d::Color e2d::Renderer::backgroundColor()
{ {
return Color(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a); return _clearColor;
} }
void e2d::Renderer::setBackgroundColor(Color color) void e2d::Renderer::backgroundColor(const Color& color)
{ {
_clearColor = (D2D1_COLOR_F)color; _clearColor = (D2D1_COLOR_F)color;
} }
@ -220,7 +220,7 @@ void e2d::Renderer::showFps(bool show)
_showFps = show; _showFps = show;
} }
ID2D1StrokeStyle * e2d::Renderer::getMiterStrokeStyle() ID2D1StrokeStyle * e2d::Renderer::miterStrokeStyle()
{ {
if (!_miterStrokeStyle) if (!_miterStrokeStyle)
{ {
@ -243,7 +243,7 @@ ID2D1StrokeStyle * e2d::Renderer::getMiterStrokeStyle()
return _miterStrokeStyle; return _miterStrokeStyle;
} }
ID2D1StrokeStyle * e2d::Renderer::getBevelStrokeStyle() ID2D1StrokeStyle * e2d::Renderer::bevelStrokeStyle()
{ {
if (!_bevelStrokeStyle) if (!_bevelStrokeStyle)
{ {
@ -266,7 +266,7 @@ ID2D1StrokeStyle * e2d::Renderer::getBevelStrokeStyle()
return _bevelStrokeStyle; return _bevelStrokeStyle;
} }
ID2D1StrokeStyle * e2d::Renderer::getRoundStrokeStyle() ID2D1StrokeStyle * e2d::Renderer::roundStrokeStyle()
{ {
if (!_roundStrokeStyle) if (!_roundStrokeStyle)
{ {

View File

@ -71,7 +71,7 @@ e2d::Window::Window(const String & title, int width, int height, int iconID)
if (_hWnd) if (_hWnd)
{ {
// 禁用输入法 // 禁用输入法
setTypewritingEnabled(false); typewritingEnabled(false);
// 禁用控制台关闭按钮 // 禁用控制台关闭按钮
HWND consoleHWnd = ::GetConsoleWindow(); HWND consoleHWnd = ::GetConsoleWindow();
if (consoleHWnd) if (consoleHWnd)
@ -102,7 +102,7 @@ e2d::Window::~Window()
bool e2d::Window::createMutex(const String & mutex) bool e2d::Window::createMutex(const String & mutex)
{ {
if (mutex.isEmpty()) if (mutex.empty())
return false; return false;
HANDLE hMutex = ::CreateMutex(nullptr, TRUE, LPCWSTR(L"Easy2DApp-" + mutex)); HANDLE hMutex = ::CreateMutex(nullptr, TRUE, LPCWSTR(L"Easy2DApp-" + mutex));
@ -117,7 +117,7 @@ bool e2d::Window::createMutex(const String & mutex)
// 关闭进程互斥体 // 关闭进程互斥体
::CloseHandle(hMutex); ::CloseHandle(hMutex);
// 打开游戏窗口 // 打开游戏窗口
if (!this->_title.isEmpty()) if (!this->_title.empty())
{ {
// 获取窗口句柄 // 获取窗口句柄
HWND hProgramWnd = ::FindWindow(REGISTER_CLASS, (LPCTSTR)_title); HWND hProgramWnd = ::FindWindow(REGISTER_CLASS, (LPCTSTR)_title);
@ -167,40 +167,40 @@ void e2d::Window::poll()
} }
} }
int e2d::Window::getWidth() const int e2d::Window::width() const
{ {
return _width; return _width;
} }
int e2d::Window::getHeight() const int e2d::Window::height() const
{ {
return _height; return _height;
} }
e2d::Size e2d::Window::getSize() const e2d::Size e2d::Window::size() const
{ {
return Size(float(_width), float(_height)); return Size(float(_width), float(_height));
} }
float e2d::Window::getDpi() const float e2d::Window::dpi() const
{ {
return _dpi; return _dpi;
} }
e2d::String e2d::Window::getTitle() const const e2d::String& e2d::Window::title() const
{ {
return _title; return _title;
} }
HWND e2d::Window::getHWnd() const HWND e2d::Window::hWnd() const
{ {
return _hWnd; return _hWnd;
} }
void e2d::Window::setSize(int width, int height) e2d::Window& e2d::Window::size(int width, int height)
{ {
if (_width == width && _height == height) if (_width == width && _height == height)
return; return *this;
_width = width; _width = width;
_height = height; _height = height;
@ -217,18 +217,20 @@ void e2d::Window::setSize(int width, int height)
TRUE TRUE
); );
} }
return *this;
} }
void e2d::Window::setTitle(const String& title) e2d::Window& e2d::Window::title(const String& title)
{ {
_title = title; _title = title;
if (_hWnd) if (_hWnd)
{ {
::SetWindowText(_hWnd, (LPCWSTR)title); ::SetWindowText(_hWnd, (LPCWSTR)title);
} }
return *this;
} }
void e2d::Window::setIcon(int iconID) e2d::Window& e2d::Window::icon(int iconID)
{ {
this->_iconID = iconID; this->_iconID = iconID;
if (_hWnd) if (_hWnd)
@ -238,9 +240,10 @@ void e2d::Window::setIcon(int iconID)
::SendMessage(_hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon); ::SendMessage(_hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
::SendMessage(_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); ::SendMessage(_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
} }
return *this;
} }
void e2d::Window::setCursor(Cursor cursor) e2d::Window& e2d::Window::cursor(Cursor cursor)
{ {
LPCWSTR pCursorName = nullptr; LPCWSTR pCursorName = nullptr;
switch (cursor) switch (cursor)
@ -271,9 +274,10 @@ void e2d::Window::setCursor(Cursor cursor)
HCURSOR hCursor = ::LoadCursor(nullptr, pCursorName); HCURSOR hCursor = ::LoadCursor(nullptr, pCursorName);
::SetCursor(hCursor); ::SetCursor(hCursor);
return *this;
} }
void e2d::Window::setConsoleEnabled(bool enabled) e2d::Window& e2d::Window::showConsole(bool enabled)
{ {
// 查找已存在的控制台句柄 // 查找已存在的控制台句柄
HWND hwnd = ::GetConsoleWindow(); HWND hwnd = ::GetConsoleWindow();
@ -308,9 +312,10 @@ void e2d::Window::setConsoleEnabled(bool enabled)
::ShowWindow(hwnd, SW_HIDE); ::ShowWindow(hwnd, SW_HIDE);
} }
} }
return *this;
} }
void e2d::Window::setTypewritingEnabled(bool enabled) e2d::Window& e2d::Window::typewritingEnabled(bool enabled)
{ {
static HIMC hImc = nullptr; static HIMC hImc = nullptr;
@ -329,6 +334,7 @@ void e2d::Window::setTypewritingEnabled(bool enabled)
hImc = ::ImmAssociateContext(_hWnd, nullptr); hImc = ::ImmAssociateContext(_hWnd, nullptr);
} }
} }
return *this;
} }
bool e2d::Window::popup(const String & text, const String & title, Popup style, bool hasCancel) bool e2d::Window::popup(const String & text, const String & title, Popup style, bool hasCancel)
@ -354,9 +360,9 @@ bool e2d::Window::popup(const String & text, const String & title, Popup style,
type |= MB_OKCANCEL; type |= MB_OKCANCEL;
} }
Game::getInstance()->pause(); Game::instance()->pause();
int ret = ::MessageBox(_hWnd, (LPCWSTR)text, (LPCWSTR)title, type); int ret = ::MessageBox(_hWnd, (LPCWSTR)text, (LPCWSTR)title, type);
Game::getInstance()->resume(); Game::instance()->resume();
return ret == IDOK; return ret == IDOK;
} }
@ -403,13 +409,13 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
{ {
auto game = Game::getInstance(); auto game = Game::instance();
if (game->isTransitioning()) if (game->transitioning())
break; break;
if (game->getCurrentScene()) if (game->currentScene())
{ {
game->getCurrentScene()->dispatch(MouseEvent(hWnd, uMsg, wParam, lParam, window->_dpi), false); game->currentScene()->dispatch(MouseEvent(hWnd, uMsg, wParam, lParam, window->_dpi), false);
} }
} }
result = 0; result = 0;
@ -420,13 +426,13 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_KEYDOWN: case WM_KEYDOWN:
case WM_KEYUP: case WM_KEYUP:
{ {
auto game = Game::getInstance(); auto game = Game::instance();
if (game->isTransitioning()) if (game->transitioning())
break; break;
if (game->getCurrentScene()) if (game->currentScene())
{ {
game->getCurrentScene()->dispatch(KeyEvent(hWnd, uMsg, wParam, lParam), false); game->currentScene()->dispatch(KeyEvent(hWnd, uMsg, wParam, lParam), false);
} }
} }
result = 0; result = 0;
@ -448,8 +454,8 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染 // 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染
// 目标适当。它可能会调用失败,但是这里可以忽略有可能的 // 目标适当。它可能会调用失败,但是这里可以忽略有可能的
// 错误,因为这个错误将在下一次调用 EndDraw 时产生 // 错误,因为这个错误将在下一次调用 EndDraw 时产生
auto renderer = Game::getInstance()->getRenderer(); auto renderer = Game::instance()->renderer();
auto pRT = renderer->getRenderTarget(); auto pRT = renderer->renderTarget();
if (pRT) if (pRT)
{ {
pRT->Resize(D2D1::SizeU(width, height)); pRT->Resize(D2D1::SizeU(width, height));
@ -477,7 +483,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// 重绘窗口 // 重绘窗口
case WM_PAINT: case WM_PAINT:
{ {
Game::getInstance()->drawScene(); Game::instance()->drawScene();
ValidateRect(hWnd, nullptr); ValidateRect(hWnd, nullptr);
} }
result = 0; result = 0;
@ -487,8 +493,8 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// 窗口关闭消息 // 窗口关闭消息
case WM_CLOSE: case WM_CLOSE:
{ {
auto game = Game::getInstance(); auto game = Game::instance();
auto currScene = game->getCurrentScene(); auto currScene = game->currentScene();
if (!currScene || currScene->onCloseWindow()) if (!currScene || currScene->onCloseWindow())
{ {
game->quit(); game->quit();

View File

@ -18,80 +18,85 @@ e2d::Collider::~Collider()
SafeRelease(_geometry); SafeRelease(_geometry);
} }
e2d::Color e2d::Collider::getColor() const e2d::Color e2d::Collider::color() const
{ {
return _color; return _color;
} }
e2d::Collider::Shape e2d::Collider::getShape() const e2d::Collider::Shape e2d::Collider::shape() const
{ {
return _shape; return _shape;
} }
e2d::Node * e2d::Collider::getNode() const e2d::Node * e2d::Collider::node() const
{ {
return _parentNode; return _parentNode;
} }
ID2D1Geometry * e2d::Collider::getGeometry() const ID2D1Geometry * e2d::Collider::geometry() const
{ {
return _geometry; return _geometry;
} }
void e2d::Collider::setShape(Shape shape) e2d::Collider& e2d::Collider::shape(Shape shape)
{ {
if (_shape == shape) if (_shape == shape)
return; return *this;
_shape = shape; _shape = shape;
if (shape == Shape::None) if (shape == Shape::None)
{ {
SafeRelease(_geometry); SafeRelease(_geometry);
CollisionManager::getInstance()->__removeCollider(this); CollisionManager::instance()->__removeCollider(this);
} }
else else
{ {
this->recreate(); this->recreate();
CollisionManager::getInstance()->__addCollider(this); CollisionManager::instance()->__addCollider(this);
} }
return *this;
} }
void e2d::Collider::setCollisionNotify(bool notify) e2d::Collider& e2d::Collider::notify(bool notify)
{ {
_notify = notify; _notify = notify;
return *this;
} }
void e2d::Collider::setEnabled(bool enabled) e2d::Collider& e2d::Collider::enabled(bool enabled)
{ {
_enabled = enabled; _enabled = enabled;
return *this;
} }
void e2d::Collider::setVisible(bool visible) e2d::Collider& e2d::Collider::visible(bool visible)
{ {
_visible = visible; _visible = visible;
return *this;
} }
void e2d::Collider::setColor(Color color) e2d::Collider& e2d::Collider::color(Color color)
{ {
_color = color; _color = color;
return *this;
} }
void e2d::Collider::render() void e2d::Collider::render()
{ {
if (_geometry && _enabled && _visible) if (_geometry && _enabled && _visible)
{ {
auto renderer = Game::getInstance()->getRenderer(); auto renderer = Game::instance()->renderer();
// 获取纯色画刷 // 获取纯色画刷
ID2D1SolidColorBrush * brush = renderer->getSolidColorBrush(); ID2D1SolidColorBrush * brush = renderer->solidBrush();
// 设置画刷颜色和透明度 // 设置画刷颜色和透明度
brush->SetColor((D2D1_COLOR_F)_color); brush->SetColor((D2D1_COLOR_F)_color);
brush->SetOpacity(1.f); brush->SetOpacity(1.f);
// 绘制几何碰撞体 // 绘制几何碰撞体
renderer->getRenderTarget()->DrawGeometry(_geometry, brush, 1.5f); renderer->renderTarget()->DrawGeometry(_geometry, brush, 1.5f);
} }
} }
e2d::Collider::Relation e2d::Collider::getRelationWith(Collider * collider) const e2d::Collider::Relation e2d::Collider::relationWith(Collider * collider) const
{ {
if (_geometry && collider->_geometry) if (_geometry && collider->_geometry)
{ {
@ -110,17 +115,17 @@ e2d::Collider::Relation e2d::Collider::getRelationWith(Collider * collider) cons
return Relation::Unknown; return Relation::Unknown;
} }
bool e2d::Collider::isEnabled() const bool e2d::Collider::enabled() const
{ {
return _enabled; return _enabled;
} }
bool e2d::Collider::isVisible() const bool e2d::Collider::visible() const
{ {
return _visible; return _visible;
} }
bool e2d::Collider::isCollisionNotify() const bool e2d::Collider::notify() const
{ {
return _notify; return _notify;
} }
@ -131,7 +136,7 @@ void e2d::Collider::recreate()
return; return;
SafeRelease(_geometry); SafeRelease(_geometry);
auto factory = Game::getInstance()->getRenderer()->getFactory(); auto factory = Game::instance()->renderer()->factory();
switch (_shape) switch (_shape)
{ {
@ -139,7 +144,7 @@ void e2d::Collider::recreate()
{ {
ID2D1RectangleGeometry* rectangle = nullptr; ID2D1RectangleGeometry* rectangle = nullptr;
factory->CreateRectangleGeometry( factory->CreateRectangleGeometry(
D2D1::RectF(0, 0, _parentNode->getRealWidth(), _parentNode->getRealHeight()), D2D1::RectF(0, 0, _parentNode->realWidth(), _parentNode->realHeight()),
&rectangle &rectangle
); );
_geometry = rectangle; _geometry = rectangle;
@ -148,14 +153,14 @@ void e2d::Collider::recreate()
case Shape::Circle: case Shape::Circle:
{ {
float minSide = std::min(_parentNode->getRealWidth(), _parentNode->getRealHeight()); float minSide = std::min(_parentNode->realWidth(), _parentNode->realHeight());
ID2D1EllipseGeometry* circle = nullptr; ID2D1EllipseGeometry* circle = nullptr;
factory->CreateEllipseGeometry( factory->CreateEllipseGeometry(
D2D1::Ellipse( D2D1::Ellipse(
D2D1::Point2F( D2D1::Point2F(
_parentNode->getRealWidth() / 2, _parentNode->realWidth() / 2,
_parentNode->getRealHeight() / 2 _parentNode->realHeight() / 2
), ),
minSide / 2, minSide / 2,
minSide / 2 minSide / 2
@ -168,8 +173,8 @@ void e2d::Collider::recreate()
case Shape::Ellipse: case Shape::Ellipse:
{ {
float halfWidth = _parentNode->getWidth() / 2, float halfWidth = _parentNode->width() / 2,
halfHeight = _parentNode->getHeight() / 2; halfHeight = _parentNode->height() / 2;
ID2D1EllipseGeometry* ellipse = nullptr; ID2D1EllipseGeometry* ellipse = nullptr;
factory->CreateEllipseGeometry( factory->CreateEllipseGeometry(

View File

@ -58,9 +58,9 @@ bool e2d::Image::open(const Resource& res)
bool e2d::Image::open(const String & fileName) bool e2d::Image::open(const String & fileName)
{ {
WARN_IF(fileName.isEmpty(), "Image open failed! Invalid file name."); WARN_IF(fileName.empty(), "Image open failed! Invalid file name.");
if (fileName.isEmpty()) if (fileName.empty())
return false; return false;
if (!Image::preload(fileName)) if (!Image::preload(fileName))
@ -77,29 +77,29 @@ void e2d::Image::crop(const Rect& cropRect)
{ {
if (_bitmap) if (_bitmap)
{ {
_cropRect.origin.x = std::min(std::max(cropRect.origin.x, 0.f), this->getSourceWidth()); _cropRect.origin.x = std::min(std::max(cropRect.origin.x, 0.f), this->realWidth());
_cropRect.origin.y = std::min(std::max(cropRect.origin.y, 0.f), this->getSourceHeight()); _cropRect.origin.y = std::min(std::max(cropRect.origin.y, 0.f), this->realHeight());
_cropRect.size.width = std::min(std::max(cropRect.size.width, 0.f), this->getSourceWidth() - cropRect.origin.x); _cropRect.size.width = std::min(std::max(cropRect.size.width, 0.f), this->realWidth() - cropRect.origin.x);
_cropRect.size.height = std::min(std::max(cropRect.size.height, 0.f), this->getSourceHeight() - cropRect.origin.y); _cropRect.size.height = std::min(std::max(cropRect.size.height, 0.f), this->realHeight() - cropRect.origin.y);
} }
} }
float e2d::Image::getWidth() const float e2d::Image::width() const
{ {
return _cropRect.size.width; return _cropRect.size.width;
} }
float e2d::Image::getHeight() const float e2d::Image::height() const
{ {
return _cropRect.size.height; return _cropRect.size.height;
} }
e2d::Size e2d::Image::getSize() const const e2d::Size& e2d::Image::size() const
{ {
return _cropRect.size; return _cropRect.size;
} }
float e2d::Image::getSourceWidth() const float e2d::Image::realWidth() const
{ {
if (_bitmap) if (_bitmap)
{ {
@ -111,7 +111,7 @@ float e2d::Image::getSourceWidth() const
} }
} }
float e2d::Image::getSourceHeight() const float e2d::Image::realHeight() const
{ {
if (_bitmap) if (_bitmap)
{ {
@ -123,11 +123,11 @@ float e2d::Image::getSourceHeight() const
} }
} }
e2d::Size e2d::Image::getSourceSize() const e2d::Size e2d::Image::realSize() const
{ {
if (_bitmap) if (_bitmap)
{ {
return Size(getSourceWidth(), getSourceHeight()); return Size(realWidth(), realHeight());
} }
else else
{ {
@ -135,17 +135,17 @@ e2d::Size e2d::Image::getSourceSize() const
} }
} }
float e2d::Image::getCropX() const float e2d::Image::cropX() const
{ {
return _cropRect.origin.x; return _cropRect.origin.x;
} }
float e2d::Image::getCropY() const float e2d::Image::cropY() const
{ {
return _cropRect.origin.y; return _cropRect.origin.y;
} }
e2d::Point e2d::Image::getCropPos() const const e2d::Point& e2d::Image::cropPosition() const
{ {
return _cropRect.origin; return _cropRect.origin;
} }
@ -157,9 +157,9 @@ bool e2d::Image::preload(const Resource& res)
return true; return true;
} }
Renderer* renderer = Game::getInstance()->getRenderer(); Renderer* renderer = Game::instance()->renderer();
ID2D1HwndRenderTarget* pRenderTarget = renderer->getRenderTarget(); ID2D1HwndRenderTarget* pRenderTarget = renderer->renderTarget();
IWICImagingFactory *pImagingFactory = renderer->getImagingFactory(); IWICImagingFactory *pImagingFactory = renderer->imagingFactory();
IWICBitmapDecoder *pDecoder = nullptr; IWICBitmapDecoder *pDecoder = nullptr;
IWICBitmapFrameDecode *pSource = nullptr; IWICBitmapFrameDecode *pSource = nullptr;
IWICStream *pStream = nullptr; IWICStream *pStream = nullptr;
@ -279,17 +279,17 @@ bool e2d::Image::preload(const Resource& res)
bool e2d::Image::preload(const String & fileName) bool e2d::Image::preload(const String & fileName)
{ {
String actualFilePath = File(fileName).getFilePath(); String actualFilePath = File(fileName).path();
if (actualFilePath.isEmpty()) if (actualFilePath.empty())
return false; return false;
size_t hash = actualFilePath.hash(); size_t hash = actualFilePath.hash();
if (_bitmapCache.find(hash) != _bitmapCache.end()) if (_bitmapCache.find(hash) != _bitmapCache.end())
return true; return true;
Renderer* renderer = Game::getInstance()->getRenderer(); Renderer* renderer = Game::instance()->renderer();
ID2D1HwndRenderTarget* pRenderTarget = renderer->getRenderTarget(); ID2D1HwndRenderTarget* pRenderTarget = renderer->renderTarget();
IWICImagingFactory *pImagingFactory = renderer->getImagingFactory(); IWICImagingFactory *pImagingFactory = renderer->imagingFactory();
IWICBitmapDecoder *pDecoder = nullptr; IWICBitmapDecoder *pDecoder = nullptr;
IWICBitmapFrameDecode *pSource = nullptr; IWICBitmapFrameDecode *pSource = nullptr;
IWICStream *pStream = nullptr; IWICStream *pStream = nullptr;
@ -377,7 +377,7 @@ void e2d::Image::_setBitmap(ID2D1Bitmap * bitmap)
} }
} }
ID2D1Bitmap * e2d::Image::getBitmap() ID2D1Bitmap * e2d::Image::bitmap()
{ {
return _bitmap; return _bitmap;
} }

View File

@ -1,28 +1,33 @@
#include "..\e2dcommon.h" #include "..\e2dcommon.h"
e2d::Rect::Rect(void) e2d::Rect::Rect(void)
: origin()
, size()
{ {
setRect(0.f, 0.f, 0.f, 0.f);
} }
e2d::Rect::Rect(float x, float y, float width, float height) e2d::Rect::Rect(float x, float y, float width, float height)
: origin(x, y)
, size(width, height)
{ {
setRect(x, y, width, height);
} }
e2d::Rect::Rect(const Point& pos, const Size& size) e2d::Rect::Rect(const Point& pos, const Size& size)
: origin(pos)
, size(size)
{ {
setRect(pos.x, pos.y, size.width, size.height);
} }
e2d::Rect::Rect(const Rect& other) e2d::Rect::Rect(const Rect& other)
: origin(other.origin)
, size(other.size)
{ {
setRect(other.origin.x, other.origin.y, other.size.width, other.size.height);
} }
e2d::Rect& e2d::Rect::operator= (const Rect& other) e2d::Rect& e2d::Rect::operator= (const Rect& other)
{ {
setRect(other.origin.x, other.origin.y, other.size.width, other.size.height); origin = other.origin;
size = other.size;
return *this; return *this;
} }
@ -31,15 +36,6 @@ bool e2d::Rect::operator==(const Rect & rect) const
return (origin == rect.origin) && (size == rect.size); return (origin == rect.origin) && (size == rect.size);
} }
void e2d::Rect::setRect(float x, float y, float width, float height)
{
origin.x = x;
origin.y = y;
size.width = width;
size.height = height;
}
bool e2d::Rect::containsPoint(const Point& point) const bool e2d::Rect::containsPoint(const Point& point) const
{ {
if (point.x >= origin.x && point.x <= (origin.y + size.height) if (point.x >= origin.x && point.x <= (origin.y + size.height)

View File

@ -19,7 +19,7 @@ void e2d::Ref::release()
_refCount--; _refCount--;
} }
int e2d::Ref::getRefCount() const int e2d::Ref::refCount() const
{ {
return _refCount; return _refCount;
} }

View File

@ -332,7 +332,18 @@ e2d::String::operator wchar_t*() const
return const_cast<wchar_t*>(_str.c_str()); return const_cast<wchar_t*>(_str.c_str());
} }
bool e2d::String::isEmpty() const e2d::String::operator std::wstring() const
{
return _str;
}
e2d::String::operator std::string() const
{
std::string str = static_cast<const char *>(_bstr_t(_str.c_str()));
return std::move(str);
}
bool e2d::String::empty() const
{ {
return _str.empty(); return _str.empty();
} }
@ -348,17 +359,6 @@ size_t e2d::String::hash() const
return hash(_str); return hash(_str);
} }
std::wstring e2d::String::getWString() const
{
return _str;
}
std::string e2d::String::getCString() const
{
std::string str = static_cast<const char *>(_bstr_t(_str.c_str()));
return std::move(str);
}
wchar_t e2d::String::at(int index) const wchar_t e2d::String::at(int index) const
{ {
return _str[size_t(index)]; return _str[size_t(index)];

View File

@ -7,13 +7,13 @@ e2d::Time::Time()
{ {
} }
time_t e2d::Time::getTimeStamp() const time_t e2d::Time::stamp() const
{ {
auto& duration = time_point_cast<milliseconds>(_timePoint).time_since_epoch(); auto& duration = time_point_cast<milliseconds>(_timePoint).time_since_epoch();
return static_cast<time_t>(duration.count()); return static_cast<time_t>(duration.count());
} }
bool e2d::Time::isZero() const bool e2d::Time::zero() const
{ {
return _timePoint.time_since_epoch().count() == 0LL; return _timePoint.time_since_epoch().count() == 0LL;
} }

View File

@ -59,18 +59,18 @@ STDMETHODIMP_(void) TextRenderer::SetTextStyle(
sOutlineColor_ = outlineColor; sOutlineColor_ = outlineColor;
fOutlineWidth = 2 * outlineWidth; fOutlineWidth = 2 * outlineWidth;
auto pRenderer = Game::getInstance()->getRenderer(); auto pRenderer = Game::instance()->renderer();
switch (outlineJoin) switch (outlineJoin)
{ {
case D2D1_LINE_JOIN_MITER: case D2D1_LINE_JOIN_MITER:
pCurrStrokeStyle_ = pRenderer->getMiterStrokeStyle(); pCurrStrokeStyle_ = pRenderer->miterStrokeStyle();
break; break;
case D2D1_LINE_JOIN_BEVEL: case D2D1_LINE_JOIN_BEVEL:
pCurrStrokeStyle_ = pRenderer->getBevelStrokeStyle(); pCurrStrokeStyle_ = pRenderer->bevelStrokeStyle();
break; break;
case D2D1_LINE_JOIN_ROUND: case D2D1_LINE_JOIN_ROUND:
pCurrStrokeStyle_ = pRenderer->getRoundStrokeStyle(); pCurrStrokeStyle_ = pRenderer->roundStrokeStyle();
break; break;
default: default:
pCurrStrokeStyle_ = nullptr; pCurrStrokeStyle_ = nullptr;

View File

@ -65,12 +65,12 @@ void e2d::VoiceCallback::OnVoiceError(void * pBufferContext, HRESULT Error)
{ {
} }
void e2d::VoiceCallback::SetFuncOnStreamEnd(const Function & func) void e2d::VoiceCallback::SetCallbackOnStreamEnd(const Function & func)
{ {
_streamEndFunc = func; _streamEndFunc = func;
} }
void e2d::VoiceCallback::SetFuncOnLoopEnd(const Function & func) void e2d::VoiceCallback::SetCallbackOnLoopEnd(const Function & func)
{ {
_loopEndFunc = func; _loopEndFunc = func;
} }

View File

@ -16,12 +16,12 @@ e2d::Collision::~Collision()
{ {
} }
e2d::Node * e2d::Collision::getNode() const e2d::Node * e2d::Collision::node() const
{ {
return _node; return _node;
} }
e2d::Collider::Relation e2d::Collision::getRelation() const e2d::Collider::Relation e2d::Collision::relation() const
{ {
return _relation; return _relation;
} }

View File

@ -8,17 +8,17 @@ e2d::KeyEvent::KeyEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
} }
e2d::KeyCode e2d::KeyEvent::getCode() const e2d::KeyCode e2d::KeyEvent::code() const
{ {
return _code; return _code;
} }
int e2d::KeyEvent::getCount() const int e2d::KeyEvent::count() const
{ {
return _count; return _count;
} }
e2d::KeyEvent::Type e2d::KeyEvent::getType() const e2d::KeyEvent::Type e2d::KeyEvent::type() const
{ {
return _type; return _type;
} }

View File

@ -11,17 +11,17 @@ e2d::MouseEvent::MouseEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
_pos.y = ((float)(short)HIWORD(lParam)) * 96.f / dpi; _pos.y = ((float)(short)HIWORD(lParam)) * 96.f / dpi;
} }
float e2d::MouseEvent::getX() const float e2d::MouseEvent::positionX() const
{ {
return _pos.x; return _pos.x;
} }
float e2d::MouseEvent::getY() const float e2d::MouseEvent::positionY() const
{ {
return _pos.y; return _pos.y;
} }
e2d::Point e2d::MouseEvent::getPos() const e2d::Point e2d::MouseEvent::position() const
{ {
return _pos; return _pos;
} }
@ -36,7 +36,7 @@ bool e2d::MouseEvent::isCtrlDown() const
return GET_KEYSTATE_WPARAM(_wParam) == MK_CONTROL; return GET_KEYSTATE_WPARAM(_wParam) == MK_CONTROL;
} }
float e2d::MouseEvent::getWheelDelta() const float e2d::MouseEvent::wheelDelta() const
{ {
return static_cast<float>(GET_WHEEL_DELTA_WPARAM(_wParam)); return static_cast<float>(GET_WHEEL_DELTA_WPARAM(_wParam));
} }
@ -56,7 +56,7 @@ bool e2d::MouseEvent::isMButtonDown() const
return GET_KEYSTATE_WPARAM(_wParam) == MK_MBUTTON; return GET_KEYSTATE_WPARAM(_wParam) == MK_MBUTTON;
} }
e2d::MouseEvent::Type e2d::MouseEvent::getType() const e2d::MouseEvent::Type e2d::MouseEvent::type() const
{ {
return _type; return _type;
} }

View File

@ -3,7 +3,7 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::ActionManager * e2d::ActionManager::getInstance() e2d::ActionManager * e2d::ActionManager::instance()
{ {
static ActionManager instance; static ActionManager instance;
return &instance; return &instance;
@ -84,7 +84,7 @@ void e2d::ActionManager::resumeAllBindedWith(Node * target)
for (const auto& action : _runningActions) for (const auto& action : _runningActions)
{ {
if (action->getTarget() == target) if (action->target() == target)
{ {
action->resume(); action->resume();
} }
@ -98,7 +98,7 @@ void e2d::ActionManager::pauseAllBindedWith(Node * target)
for (const auto& action : _runningActions) for (const auto& action : _runningActions)
{ {
if (action->getTarget() == target) if (action->target() == target)
{ {
action->pause(); action->pause();
} }
@ -112,7 +112,7 @@ void e2d::ActionManager::stopAllBindedWith(Node * target)
for (const auto& action : _runningActions) for (const auto& action : _runningActions)
{ {
if (action->getTarget() == target) if (action->target() == target)
{ {
action->stop(); action->stop();
} }
@ -146,12 +146,12 @@ void e2d::ActionManager::start(Action * action, Node * target, bool paused)
void e2d::ActionManager::resume(const String& name) void e2d::ActionManager::resume(const String& name)
{ {
if (_runningActions.empty() || name.isEmpty()) if (_runningActions.empty() || name.empty())
return; return;
for (const auto& action : _runningActions) for (const auto& action : _runningActions)
{ {
if (action->getName() == name) if (action->name() == name)
{ {
action->resume(); action->resume();
} }
@ -160,12 +160,12 @@ void e2d::ActionManager::resume(const String& name)
void e2d::ActionManager::pause(const String& name) void e2d::ActionManager::pause(const String& name)
{ {
if (_runningActions.empty() || name.isEmpty()) if (_runningActions.empty() || name.empty())
return; return;
for (const auto& action : _runningActions) for (const auto& action : _runningActions)
{ {
if (action->getName() == name) if (action->name() == name)
{ {
action->pause(); action->pause();
} }
@ -174,12 +174,12 @@ void e2d::ActionManager::pause(const String& name)
void e2d::ActionManager::stop(const String& name) void e2d::ActionManager::stop(const String& name)
{ {
if (_runningActions.empty() || name.isEmpty()) if (_runningActions.empty() || name.empty())
return; return;
for (const auto& action : _runningActions) for (const auto& action : _runningActions)
{ {
if (action->getName() == name) if (action->name() == name)
{ {
action->stop(); action->stop();
} }
@ -193,7 +193,7 @@ void e2d::ActionManager::clearAllBindedWith(Node * target)
auto iter = std::find_if( auto iter = std::find_if(
_runningActions.begin(), _runningActions.begin(),
_runningActions.end(), _runningActions.end(),
[target](Action* action) ->bool { return action->getTarget() == target; } [target](Action* action) ->bool { return action->target() == target; }
); );
if (iter != _runningActions.end()) if (iter != _runningActions.end())
@ -218,12 +218,12 @@ void e2d::ActionManager::clearAll()
_actions.clear(); _actions.clear();
} }
std::vector<e2d::Action*> e2d::ActionManager::get(const String& name) std::vector<e2d::Action*> e2d::ActionManager::actions(const String& name)
{ {
std::vector<Action*> actions; std::vector<Action*> actions;
for (const auto& action : _actions) for (const auto& action : _actions)
{ {
if (action->getName() == name) if (action->name() == name)
{ {
actions.push_back(action); actions.push_back(action);
} }
@ -231,7 +231,7 @@ std::vector<e2d::Action*> e2d::ActionManager::get(const String& name)
return std::move(actions); return std::move(actions);
} }
const std::vector<e2d::Action*>& e2d::ActionManager::getAll() const std::vector<e2d::Action*>& e2d::ActionManager::actions()
{ {
return _actions; return _actions;
} }

View File

@ -3,7 +3,7 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
e2d::CollisionManager * e2d::CollisionManager::getInstance() e2d::CollisionManager * e2d::CollisionManager::instance()
{ {
static CollisionManager instance; static CollisionManager instance;
return &instance; return &instance;
@ -35,7 +35,7 @@ void e2d::CollisionManager::__removeCollider(Collider * collider)
void e2d::CollisionManager::__updateCollider(Collider* collider) void e2d::CollisionManager::__updateCollider(Collider* collider)
{ {
if (!_collisionEnabled || if (!_collisionEnabled ||
Game::getInstance()->isTransitioning()) Game::instance()->transitioning())
return; return;
std::vector<Collider*> currColliders; std::vector<Collider*> currColliders;
@ -47,46 +47,46 @@ void e2d::CollisionManager::__updateCollider(Collider* collider)
[this, collider](Collider* passive) -> bool [this, collider](Collider* passive) -> bool
{ {
return collider != passive && return collider != passive &&
passive->getNode()->isVisible() && passive->node()->visible() &&
collider->getNode()->getParentScene() == passive->getNode()->getParentScene() && collider->node()->parentScene() == passive->node()->parentScene() &&
this->isCollidable(collider->getNode(), passive->getNode()); this->isCollidable(collider->node(), passive->node());
} }
); );
for (const auto& passive : currColliders) for (const auto& passive : currColliders)
{ {
// 判断两碰撞体交集情况 // 判断两碰撞体交集情况
Collider::Relation relation = collider->getRelationWith(passive); Collider::Relation relation = collider->relationWith(passive);
// 忽略 UNKNOWN 和 DISJOIN 情况 // 忽略 UNKNOWN 和 DISJOIN 情况
if (relation != Collider::Relation::Unknown && if (relation != Collider::Relation::Unknown &&
relation != Collider::Relation::Disjoin) relation != Collider::Relation::Disjoin)
{ {
auto activeNode = collider->getNode(); auto activeNode = collider->node();
auto passiveNode = passive->getNode(); auto passiveNode = passive->node();
// 触发两次碰撞事件 // 触发两次碰撞事件
Collision activeCollision(passiveNode, relation); Collision activeCollision(passiveNode, relation);
if (dynamic_cast<CollisionHandler*>(activeNode->getParentScene())) if (dynamic_cast<CollisionHandler*>(activeNode->parentScene()))
dynamic_cast<CollisionHandler*>(activeNode->getParentScene())->handle(activeCollision); dynamic_cast<CollisionHandler*>(activeNode->parentScene())->handle(activeCollision);
if (dynamic_cast<CollisionHandler*>(activeNode)) if (dynamic_cast<CollisionHandler*>(activeNode))
dynamic_cast<CollisionHandler*>(activeNode)->handle(activeCollision); dynamic_cast<CollisionHandler*>(activeNode)->handle(activeCollision);
Collision passiveCollision(activeNode, passive->getRelationWith(collider)); Collision passiveCollision(activeNode, passive->relationWith(collider));
if (dynamic_cast<CollisionHandler*>(passiveNode->getParentScene())) if (dynamic_cast<CollisionHandler*>(passiveNode->parentScene()))
dynamic_cast<CollisionHandler*>(passiveNode->getParentScene())->handle(passiveCollision); dynamic_cast<CollisionHandler*>(passiveNode->parentScene())->handle(passiveCollision);
if (dynamic_cast<CollisionHandler*>(passiveNode)) if (dynamic_cast<CollisionHandler*>(passiveNode))
dynamic_cast<CollisionHandler*>(passiveNode)->handle(passiveCollision); dynamic_cast<CollisionHandler*>(passiveNode)->handle(passiveCollision);
} }
} }
} }
void e2d::CollisionManager::setCollisionEnabled(bool enabled) void e2d::CollisionManager::enabled(bool enabled)
{ {
_collisionEnabled = enabled; _collisionEnabled = enabled;
} }
void e2d::CollisionManager::addName(const String & name1, const String & name2) void e2d::CollisionManager::addName(const String & name1, const String & name2)
{ {
if (!name1.isEmpty() && !name2.isEmpty()) if (!name1.empty() && !name2.empty())
{ {
_collisionList.insert(std::make_pair(name1.hash(), name2.hash())); _collisionList.insert(std::make_pair(name1.hash(), name2.hash()));
} }
@ -96,7 +96,7 @@ void e2d::CollisionManager::addName(const std::vector<std::pair<String, String>
{ {
for (const auto& name : names) for (const auto& name : names)
{ {
if (!name.first.isEmpty() && !name.second.isEmpty()) if (!name.first.empty() && !name.second.empty())
{ {
_collisionList.insert(std::make_pair(name.first.hash(), name.second.hash())); _collisionList.insert(std::make_pair(name.first.hash(), name.second.hash()));
} }
@ -105,7 +105,7 @@ void e2d::CollisionManager::addName(const std::vector<std::pair<String, String>
bool e2d::CollisionManager::isCollidable(Node * node1, Node * node2) bool e2d::CollisionManager::isCollidable(Node * node1, Node * node2)
{ {
return CollisionManager::isCollidable(node1->getName(), node2->getName()); return CollisionManager::isCollidable(node1->name(), node2->name());
} }
bool e2d::CollisionManager::isCollidable(const String & name1, const String & name2) bool e2d::CollisionManager::isCollidable(const String & name1, const String & name2)

View File

@ -9,7 +9,7 @@
if (Old) this->removeChild(Old); \ if (Old) this->removeChild(Old); \
if (New) \ if (New) \
{ \ { \
New->setPivot(_pivotX, _pivotY); \ New->anchor(_anchorX, _anchorY); \
this->addChild(New); \ this->addChild(New); \
} \ } \
Old = New; \ Old = New; \
@ -39,8 +39,8 @@ e2d::Button::Button(Node * normal, const Function& func)
, _selected(nullptr) , _selected(nullptr)
, _disabled(nullptr) , _disabled(nullptr)
{ {
this->setNormal(normal); this->normal(normal);
this->setClickFunc(func); this->clickCallback(func);
} }
e2d::Button::Button(Node * normal, Node * selected, const Function& func) e2d::Button::Button(Node * normal, Node * selected, const Function& func)
@ -53,9 +53,9 @@ e2d::Button::Button(Node * normal, Node * selected, const Function& func)
, _selected(nullptr) , _selected(nullptr)
, _disabled(nullptr) , _disabled(nullptr)
{ {
this->setNormal(normal); this->normal(normal);
this->setSelected(selected); this->selected(selected);
this->setClickFunc(func); this->clickCallback(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)
@ -68,10 +68,10 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Func
, _selected(nullptr) , _selected(nullptr)
, _disabled(nullptr) , _disabled(nullptr)
{ {
this->setNormal(normal); this->normal(normal);
this->setMouseOver(mouseover); this->mouseover(mouseover);
this->setSelected(selected); this->selected(selected);
this->setClickFunc(func); this->clickCallback(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)
@ -84,78 +84,85 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * dis
, _selected(nullptr) , _selected(nullptr)
, _disabled(nullptr) , _disabled(nullptr)
{ {
this->setNormal(normal); this->normal(normal);
this->setMouseOver(mouseover); this->mouseover(mouseover);
this->setSelected(selected); this->selected(selected);
this->setDisabled(disabled); this->disabled(disabled);
this->setClickFunc(func); this->clickCallback(func);
} }
bool e2d::Button::isEnable() const bool e2d::Button::enabled() const
{ {
return _enabled; return _enabled;
} }
void e2d::Button::setNormal(Node * normal) e2d::Button& e2d::Button::normal(Node * normal)
{ {
SET_BUTTON_NODE(_normal, normal); SET_BUTTON_NODE(_normal, normal);
if (normal) if (normal)
{ {
this->setSize(normal->getWidth(), normal->getHeight()); this->size(normal->width(), normal->height());
} }
return *this;
} }
void e2d::Button::setMouseOver(Node * mouseover) e2d::Button& e2d::Button::mouseover(Node * mouseover)
{ {
SET_BUTTON_NODE(_mouseover, mouseover); SET_BUTTON_NODE(_mouseover, mouseover);
return *this;
} }
void e2d::Button::setSelected(Node * selected) e2d::Button& e2d::Button::selected(Node * selected)
{ {
SET_BUTTON_NODE(_selected, selected); SET_BUTTON_NODE(_selected, selected);
return *this;
} }
void e2d::Button::setDisabled(Node * disabled) e2d::Button& e2d::Button::disabled(Node * disabled)
{ {
SET_BUTTON_NODE(_disabled, disabled); SET_BUTTON_NODE(_disabled, disabled);
return *this;
} }
void e2d::Button::setEnabled(bool enabled) e2d::Button& e2d::Button::enabled(bool enabled)
{ {
if (_enabled != enabled) if (_enabled != enabled)
{ {
_enabled = enabled; _enabled = enabled;
_updateVisible(); _updateVisible();
} }
return *this;
} }
void e2d::Button::setClickFunc(const Function& func) e2d::Button& e2d::Button::clickCallback(const Function& func)
{ {
_func = func; _func = func;
return *this;
} }
void e2d::Button::setPivot(float pivotX, float pivotY) e2d::Button& e2d::Button::anchor(float anchorX, float anchorY)
{ {
Node::setPivot(pivotX, pivotY); Node::anchor(anchorX, anchorY);
SAFE_SET(_normal, setPivot, pivotX, pivotY); SAFE_SET(_normal, anchor, anchorX, anchorY);
SAFE_SET(_mouseover, setPivot, pivotX, pivotY); SAFE_SET(_mouseover, anchor, anchorX, anchorY);
SAFE_SET(_selected, setPivot, pivotX, pivotY); SAFE_SET(_selected, anchor, anchorX, anchorY);
SAFE_SET(_disabled, setPivot, pivotX, pivotY); SAFE_SET(_disabled, anchor, anchorX, anchorY);
return *this;
} }
bool e2d::Button::dispatch(const MouseEvent & e, bool handled) bool e2d::Button::dispatch(const MouseEvent & e, bool handled)
{ {
if (!handled && _enabled && _visible && _normal) if (!handled && _enabled && _visible && _normal)
{ {
bool contains = _normal->containsPoint(e.getPos()); bool contains = _normal->containsPoint(e.position());
if (e.getType() == MouseEvent::Type::LeftUp && _isSelected && contains) if (e.type() == MouseEvent::Type::LeftUp && _isSelected && contains)
{ {
_runCallback(); _runCallback();
_isSelected = false; _isSelected = false;
_setStatus(Status::Normal); _setStatus(Status::Normal);
return true; return true;
} }
else if (e.getType() == MouseEvent::Type::LeftDown) else if (e.type() == MouseEvent::Type::LeftDown)
{ {
_isSelected = contains; _isSelected = contains;
_setStatus(contains ? Status::Selected : Status::Normal); _setStatus(contains ? Status::Selected : Status::Normal);
@ -163,11 +170,11 @@ bool e2d::Button::dispatch(const MouseEvent & e, bool handled)
if (contains) if (contains)
return true; return true;
} }
else if (e.getType() == MouseEvent::Type::LeftUp) else if (e.type() == MouseEvent::Type::LeftUp)
{ {
_isSelected = false; _isSelected = false;
} }
else if (e.getType() == MouseEvent::Type::Move && _isSelected && contains) else if (e.type() == MouseEvent::Type::Move && _isSelected && contains)
{ {
_setStatus(Status::Selected); _setStatus(Status::Selected);
return true; return true;
@ -196,13 +203,13 @@ void e2d::Button::visit(Game * game)
if (_visible && if (_visible &&
!_enabled && !_enabled &&
_normal && _normal &&
_normal->containsPoint(game->getInput()->getMousePos())) _normal->containsPoint(game->input()->mousePos()))
{ {
game->getWindow()->setCursor(Window::Cursor::No); game->window()->cursor(Window::Cursor::No);
} }
else if (_status == Status::Mouseover || _status == Status::Selected) else if (_status == Status::Mouseover || _status == Status::Selected)
{ {
game->getWindow()->setCursor(Window::Cursor::Hand); game->window()->cursor(Window::Cursor::Hand);
} }
} }
@ -217,35 +224,35 @@ void e2d::Button::_setStatus(Status status)
void e2d::Button::_updateVisible() void e2d::Button::_updateVisible()
{ {
SAFE_SET(_normal, setVisible, false); SAFE_SET(_normal, visible, false);
SAFE_SET(_mouseover, setVisible, false); SAFE_SET(_mouseover, visible, false);
SAFE_SET(_selected, setVisible, false); SAFE_SET(_selected, visible, false);
SAFE_SET(_disabled, setVisible, false); SAFE_SET(_disabled, visible, false);
if (_enabled) if (_enabled)
{ {
if (_status == Status::Selected && _selected) if (_status == Status::Selected && _selected)
{ {
_selected->setVisible(true); _selected->visible(true);
} }
else if (_status == Status::Mouseover && _mouseover) else if (_status == Status::Mouseover && _mouseover)
{ {
_mouseover->setVisible(true); _mouseover->visible(true);
} }
else else
{ {
if (_normal) _normal->setVisible(true); if (_normal) _normal->visible(true);
} }
} }
else else
{ {
if (_disabled) if (_disabled)
{ {
_disabled->setVisible(true); _disabled->visible(true);
} }
else else
{ {
if (_normal) _normal->setVisible(true); if (_normal) _normal->visible(true);
} }
} }
} }

View File

@ -9,8 +9,8 @@ e2d::Canvas::Canvas(float width, float height)
, _strokeWidth(1.0f) , _strokeWidth(1.0f)
, _stroke(Stroke::Miter) , _stroke(Stroke::Miter)
{ {
_renderer = Game::getInstance()->getRenderer(); _renderer = Game::instance()->renderer();
_renderTarget = _renderer->getRenderTarget(); _renderTarget = _renderer->renderTarget();
_renderTarget->AddRef(); _renderTarget->AddRef();
ThrowIfFailed( ThrowIfFailed(
@ -27,10 +27,10 @@ e2d::Canvas::Canvas(float width, float height)
) )
); );
this->setClipEnabled(true); this->clipEnabled(true);
this->setWidth(width); this->width(width);
this->setHeight(height); this->height(height);
this->setStrokeStyle(_stroke); this->strokeStyle(_stroke);
} }
e2d::Canvas::~Canvas() e2d::Canvas::~Canvas()
@ -40,58 +40,62 @@ e2d::Canvas::~Canvas()
SafeRelease(_renderTarget); SafeRelease(_renderTarget);
} }
void e2d::Canvas::setLineColor(const Color & color) e2d::Canvas& e2d::Canvas::lineColor(const Color & color)
{ {
_lineBrush->SetColor(D2D_COLOR_F(color)); _lineBrush->SetColor(D2D_COLOR_F(color));
return *this;
} }
void e2d::Canvas::setFillColor(const Color & color) e2d::Canvas& e2d::Canvas::fillColor(const Color & color)
{ {
_fillBrush->SetColor(D2D_COLOR_F(color)); _fillBrush->SetColor(D2D_COLOR_F(color));
return *this;
} }
void e2d::Canvas::setStrokeWidth(float width) e2d::Canvas& e2d::Canvas::strokeWidth(float width)
{ {
_strokeWidth = std::max(width, 0.f); _strokeWidth = std::max(width, 0.f);
return *this;
} }
void e2d::Canvas::setStrokeStyle(Stroke strokeStyle) e2d::Canvas& e2d::Canvas::strokeStyle(Stroke strokeStyle)
{ {
switch (strokeStyle) switch (strokeStyle)
{ {
case e2d::Stroke::Miter: case e2d::Stroke::Miter:
_strokeStyle = _renderer->getMiterStrokeStyle(); _strokeStyle = _renderer->miterStrokeStyle();
break; break;
case e2d::Stroke::Bevel: case e2d::Stroke::Bevel:
_strokeStyle = _renderer->getBevelStrokeStyle(); _strokeStyle = _renderer->bevelStrokeStyle();
break; break;
case e2d::Stroke::Round: case e2d::Stroke::Round:
_strokeStyle = _renderer->getRoundStrokeStyle(); _strokeStyle = _renderer->roundStrokeStyle();
break; break;
} }
return *this;
} }
const e2d::Color & e2d::Canvas::getLineColor() const e2d::Color e2d::Canvas::lineColor() const
{ {
return Color(_lineBrush->GetColor()); return _lineBrush->GetColor();
} }
const e2d::Color & e2d::Canvas::getFillColor() const e2d::Color e2d::Canvas::fillColor() const
{ {
return Color(_fillBrush->GetColor()); return _fillBrush->GetColor();
} }
float e2d::Canvas::getStrokeWidth() const float e2d::Canvas::strokeWidth() const
{ {
return _strokeWidth; return _strokeWidth;
} }
e2d::Stroke e2d::Canvas::getStrokeStyle() const e2d::Stroke e2d::Canvas::strokeStyle() const
{ {
return _stroke; return _stroke;
} }
void e2d::Canvas::drawLine(const Point & begin, const Point & end) e2d::Canvas& e2d::Canvas::drawLine(const Point & begin, const Point & end)
{ {
_renderTarget->DrawLine( _renderTarget->DrawLine(
D2D1::Point2F(begin.x, begin.y), D2D1::Point2F(begin.x, begin.y),
@ -100,9 +104,10 @@ void e2d::Canvas::drawLine(const Point & begin, const Point & end)
_strokeWidth, _strokeWidth,
_strokeStyle _strokeStyle
); );
return *this;
} }
void e2d::Canvas::drawCircle(const Point & center, float radius) e2d::Canvas& e2d::Canvas::drawCircle(const Point & center, float radius)
{ {
_renderTarget->DrawEllipse( _renderTarget->DrawEllipse(
D2D1::Ellipse( D2D1::Ellipse(
@ -117,9 +122,10 @@ void e2d::Canvas::drawCircle(const Point & center, float radius)
_strokeWidth, _strokeWidth,
_strokeStyle _strokeStyle
); );
return *this;
} }
void e2d::Canvas::drawEllipse(const Point & center, float radiusX, float radiusY) e2d::Canvas& e2d::Canvas::drawEllipse(const Point & center, float radiusX, float radiusY)
{ {
_renderTarget->DrawEllipse( _renderTarget->DrawEllipse(
D2D1::Ellipse( D2D1::Ellipse(
@ -134,9 +140,10 @@ void e2d::Canvas::drawEllipse(const Point & center, float radiusX, float radiusY
_strokeWidth, _strokeWidth,
_strokeStyle _strokeStyle
); );
return *this;
} }
void e2d::Canvas::drawRect(const Rect & rect) e2d::Canvas& e2d::Canvas::drawRect(const Rect & rect)
{ {
_renderTarget->DrawRectangle( _renderTarget->DrawRectangle(
D2D1::RectF( D2D1::RectF(
@ -149,9 +156,10 @@ void e2d::Canvas::drawRect(const Rect & rect)
_strokeWidth, _strokeWidth,
_strokeStyle _strokeStyle
); );
return *this;
} }
void e2d::Canvas::drawRoundedRect(const Rect & rect, float radiusX, float radiusY) e2d::Canvas& e2d::Canvas::drawRoundedRect(const Rect & rect, float radiusX, float radiusY)
{ {
_renderTarget->DrawRoundedRectangle( _renderTarget->DrawRoundedRectangle(
D2D1::RoundedRect( D2D1::RoundedRect(
@ -168,9 +176,10 @@ void e2d::Canvas::drawRoundedRect(const Rect & rect, float radiusX, float radius
_strokeWidth, _strokeWidth,
_strokeStyle _strokeStyle
); );
return *this;
} }
void e2d::Canvas::fillCircle(const Point & center, float radius) e2d::Canvas& e2d::Canvas::fillCircle(const Point & center, float radius)
{ {
_renderTarget->FillEllipse( _renderTarget->FillEllipse(
D2D1::Ellipse( D2D1::Ellipse(
@ -183,9 +192,10 @@ void e2d::Canvas::fillCircle(const Point & center, float radius)
), ),
_fillBrush _fillBrush
); );
return *this;
} }
void e2d::Canvas::fillEllipse(const Point & center, float radiusX, float radiusY) e2d::Canvas& e2d::Canvas::fillEllipse(const Point & center, float radiusX, float radiusY)
{ {
_renderTarget->FillEllipse( _renderTarget->FillEllipse(
D2D1::Ellipse( D2D1::Ellipse(
@ -198,9 +208,10 @@ void e2d::Canvas::fillEllipse(const Point & center, float radiusX, float radiusY
), ),
_fillBrush _fillBrush
); );
return *this;
} }
void e2d::Canvas::fillRect(const Rect & rect) e2d::Canvas& e2d::Canvas::fillRect(const Rect & rect)
{ {
_renderTarget->FillRectangle( _renderTarget->FillRectangle(
D2D1::RectF( D2D1::RectF(
@ -211,9 +222,10 @@ void e2d::Canvas::fillRect(const Rect & rect)
), ),
_fillBrush _fillBrush
); );
return *this;
} }
void e2d::Canvas::fillRoundedRect(const Rect & rect, float radiusX, float radiusY) e2d::Canvas& e2d::Canvas::fillRoundedRect(const Rect & rect, float radiusX, float radiusY)
{ {
_renderTarget->FillRoundedRectangle( _renderTarget->FillRoundedRectangle(
D2D1::RoundedRect( D2D1::RoundedRect(
@ -228,4 +240,5 @@ void e2d::Canvas::fillRoundedRect(const Rect & rect, float radiusX, float radius
), ),
_fillBrush _fillBrush
); );
return *this;
} }

View File

@ -14,17 +14,17 @@ e2d::Menu::Menu(const std::vector<Button*>& buttons)
} }
} }
bool e2d::Menu::isEnable() const bool e2d::Menu::enabled() const
{ {
return _enabled; return _enabled;
} }
size_t e2d::Menu::getButtonCount() const int e2d::Menu::buttonCount() const
{ {
return _buttons.size(); return static_cast<int>(_buttons.size());
} }
void e2d::Menu::setEnabled(bool enabled) e2d::Menu& e2d::Menu::enabled(bool enabled)
{ {
if (_enabled != enabled) if (_enabled != enabled)
{ {
@ -32,19 +32,21 @@ void e2d::Menu::setEnabled(bool enabled)
for (const auto& button : _buttons) for (const auto& button : _buttons)
{ {
button->setEnabled(enabled); button->enabled(enabled);
} }
} }
return *this;
} }
void e2d::Menu::addButton(Button * button) e2d::Menu& e2d::Menu::addButton(Button * button)
{ {
if (button) if (button)
{ {
this->addChild(button); this->addChild(button);
_buttons.push_back(button); _buttons.push_back(button);
button->setEnabled(_enabled); button->enabled(_enabled);
} }
return *this;
} }
bool e2d::Menu::removeButton(Button * button) bool e2d::Menu::removeButton(Button * button)
@ -62,7 +64,7 @@ bool e2d::Menu::removeButton(Button * button)
if (iter != _buttons.end()) if (iter != _buttons.end())
{ {
// 移除按钮前,将它启用 // 移除按钮前,将它启用
button->setEnabled(true); button->enabled(true);
_buttons.erase(iter); _buttons.erase(iter);
return true; return true;
} }
@ -70,7 +72,7 @@ bool e2d::Menu::removeButton(Button * button)
return false; return false;
} }
const std::vector<e2d::Button*>& e2d::Menu::getAllButtons() const const std::vector<e2d::Button*>& e2d::Menu::buttons() const
{ {
return _buttons; return _buttons;
} }

View File

@ -3,17 +3,15 @@
#include "..\e2dmanager.h" #include "..\e2dmanager.h"
#include "..\e2daction.h" #include "..\e2daction.h"
const e2d::Node::Property e2d::Node::Property::Origin = { 0 }; const e2d::Node::Property e2d::Node::Property::Origin;
e2d::Node::Property e2d::Node::Property::operator+(Property const & prop) const e2d::Node::Property e2d::Node::Property::operator+(Property const & prop) const
{ {
Property result; Property result;
result.posX = this->posX + prop.posX; result.position = this->position + prop.position;
result.posY = this->posY + prop.posY; result.size = this->size + prop.size;
result.width = this->width + prop.width; result.anchorX = this->anchorX + prop.anchorX;
result.height = this->height + prop.height; result.anchorY = this->anchorY + prop.anchorY;
result.pivotX = this->pivotX + prop.pivotX;
result.pivotY = this->pivotY + prop.pivotY;
result.scaleX = this->scaleX + prop.scaleX; result.scaleX = this->scaleX + prop.scaleX;
result.scaleY = this->scaleY + prop.scaleY; result.scaleY = this->scaleY + prop.scaleY;
result.rotation = this->rotation + prop.rotation; result.rotation = this->rotation + prop.rotation;
@ -25,12 +23,10 @@ e2d::Node::Property e2d::Node::Property::operator+(Property const & prop) const
e2d::Node::Property e2d::Node::Property::operator-(Property const & prop) const e2d::Node::Property e2d::Node::Property::operator-(Property const & prop) const
{ {
Property result; Property result;
result.posX = this->posX - prop.posX; result.position = this->position - prop.position;
result.posY = this->posY - prop.posY; result.size = this->size - prop.size;
result.width = this->width - prop.width; result.anchorX = this->anchorX - prop.anchorX;
result.height = this->height - prop.height; result.anchorY = this->anchorY - prop.anchorY;
result.pivotX = this->pivotX - prop.pivotX;
result.pivotY = this->pivotY - prop.pivotY;
result.scaleX = this->scaleX - prop.scaleX; result.scaleX = this->scaleX - prop.scaleX;
result.scaleY = this->scaleY - prop.scaleY; result.scaleY = this->scaleY - prop.scaleY;
result.rotation = this->rotation - prop.rotation; result.rotation = this->rotation - prop.rotation;
@ -42,10 +38,8 @@ e2d::Node::Property e2d::Node::Property::operator-(Property const & prop) const
e2d::Node::Node() e2d::Node::Node()
: _order(0) : _order(0)
, _posX(0) , _position()
, _posY(0) , _size()
, _width(0)
, _height(0)
, _scaleX(1.0f) , _scaleX(1.0f)
, _scaleY(1.0f) , _scaleY(1.0f)
, _rotation(0) , _rotation(0)
@ -53,8 +47,8 @@ e2d::Node::Node()
, _skewAngleY(0) , _skewAngleY(0)
, _displayOpacity(1.f) , _displayOpacity(1.f)
, _realOpacity(1.f) , _realOpacity(1.f)
, _pivotX(0.f) , _anchorX(0.f)
, _pivotY(0.f) , _anchorY(0.f)
, _initialMatri(D2D1::Matrix3x2F::Identity()) , _initialMatri(D2D1::Matrix3x2F::Identity())
, _finalMatri(D2D1::Matrix3x2F::Identity()) , _finalMatri(D2D1::Matrix3x2F::Identity())
, _visible(true) , _visible(true)
@ -72,10 +66,10 @@ e2d::Node::Node()
e2d::Node::~Node() e2d::Node::~Node()
{ {
ActionManager::getInstance()->clearAllBindedWith(this); ActionManager::instance()->clearAllBindedWith(this);
for (const auto& child : _children) for (const auto& child : _children)
{ {
GC::getInstance()->safeRelease(child); GC::instance()->safeRelease(child);
} }
} }
@ -84,7 +78,7 @@ void e2d::Node::visit(Game * game)
if (!_visible) if (!_visible)
return; return;
if (!game->isPaused()) if (!game->paused())
{ {
auto updatableNode = dynamic_cast<Updatable*>(this); auto updatableNode = dynamic_cast<Updatable*>(this);
if (updatableNode) if (updatableNode)
@ -96,16 +90,16 @@ void e2d::Node::visit(Game * game)
_updateTransform(); _updateTransform();
// 保留差别属性 // 保留差别属性
_extrapolate = this->getProperty(); _extrapolate = this->properties();
} }
auto renderer = game->getRenderer(); auto renderer = game->renderer();
auto renderTarget = renderer->getRenderTarget(); auto renderTarget = renderer->renderTarget();
if (_clipEnabled) if (_clipEnabled)
{ {
renderTarget->SetTransform(_finalMatri); renderTarget->SetTransform(_finalMatri);
renderTarget->PushAxisAlignedClip( renderTarget->PushAxisAlignedClip(
D2D1::RectF(0, 0, _width, _height), D2D1::RectF(0, 0, _size.width, _size.height),
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE D2D1_ANTIALIAS_MODE_PER_PRIMITIVE
); );
} }
@ -129,7 +123,7 @@ void e2d::Node::visit(Game * game)
{ {
auto child = _children[i]; auto child = _children[i];
// 访问 Order 小于零的节点 // 访问 Order 小于零的节点
if (child->getOrder() < 0) if (child->order() < 0)
{ {
child->visit(game); child->visit(game);
} }
@ -161,10 +155,10 @@ void e2d::Node::drawOutline(Renderer * renderer)
{ {
if (_visible) if (_visible)
{ {
renderer->getRenderTarget()->SetTransform(_finalMatri); renderer->renderTarget()->SetTransform(_finalMatri);
renderer->getRenderTarget()->DrawRectangle( renderer->renderTarget()->DrawRectangle(
D2D1::RectF(0, 0, _width, _height), D2D1::RectF(0, 0, _size.width, _size.height),
renderer->getSolidColorBrush(), renderer->solidBrush(),
1.5f 1.5f
); );
@ -197,26 +191,26 @@ void e2d::Node::_updateTransform()
_needTransform = false; _needTransform = false;
// 计算中心点坐标 // 计算点坐标
D2D1_POINT_2F pivot = { _width * _pivotX, _height * _pivotY }; D2D1_POINT_2F anchor = { _size.width * _anchorX, _size.height * _anchorY };
// 变换 Initial 矩阵,子节点将根据这个矩阵进行变换 // 变换 Initial 矩阵,子节点将根据这个矩阵进行变换
_initialMatri = D2D1::Matrix3x2F::Scale( _initialMatri = D2D1::Matrix3x2F::Scale(
_scaleX, _scaleX,
_scaleY, _scaleY,
pivot anchor
) * D2D1::Matrix3x2F::Skew( ) * D2D1::Matrix3x2F::Skew(
_skewAngleX, _skewAngleX,
_skewAngleY, _skewAngleY,
pivot anchor
) * D2D1::Matrix3x2F::Rotation( ) * D2D1::Matrix3x2F::Rotation(
_rotation, _rotation,
pivot anchor
) * D2D1::Matrix3x2F::Translation( ) * D2D1::Matrix3x2F::Translation(
_posX, _position.x,
_posY _position.y
); );
// 根据自身中心点变换 Final 矩阵 // 根据自身点变换 Final 矩阵
_finalMatri = _initialMatri * D2D1::Matrix3x2F::Translation(-pivot.x, -pivot.y); _finalMatri = _initialMatri * D2D1::Matrix3x2F::Translation(-anchor.x, -anchor.y);
// 和父节点矩阵相乘 // 和父节点矩阵相乘
if (!_positionFixed && _parent) if (!_positionFixed && _parent)
{ {
@ -233,11 +227,11 @@ void e2d::Node::_updateTransform()
// 更新碰撞体 // 更新碰撞体
_collider.recreate(); _collider.recreate();
if (_collider.isEnabled() && if (_collider.enabled() &&
_collider.isCollisionNotify() && _collider.notify() &&
_collider.getShape() != Collider::Shape::None) _collider.shape() != Collider::Shape::None)
{ {
CollisionManager::getInstance()->__updateCollider(&_collider); CollisionManager::instance()->__updateCollider(&_collider);
} }
} }
@ -278,7 +272,7 @@ void e2d::Node::_sortChildren()
std::sort( std::sort(
std::begin(_children), std::begin(_children),
std::end(_children), std::end(_children),
[](Node * n1, Node * n2) { return n1->getOrder() < n2->getOrder(); } [](Node * n1, Node * n2) { return n1->order() < n2->order(); }
); );
_needSort = false; _needSort = false;
@ -297,115 +291,113 @@ void e2d::Node::_updateOpacity()
} }
} }
bool e2d::Node::isVisible() const bool e2d::Node::visible() const
{ {
return _visible; return _visible;
} }
e2d::String e2d::Node::getName() const const e2d::String& e2d::Node::name() const
{ {
return _name; return _name;
} }
size_t e2d::Node::getHashName() const size_t e2d::Node::hashName() const
{ {
return _hashName; return _hashName;
} }
float e2d::Node::getPosX() const float e2d::Node::positionX() const
{ {
return _posX; return _position.x;
} }
float e2d::Node::getPosY() const float e2d::Node::positionY() const
{ {
return _posY; return _position.y;
} }
e2d::Point e2d::Node::getPos() const const e2d::Point& e2d::Node::position() const
{ {
return Point(_posX, _posY); return _position;
} }
float e2d::Node::getWidth() const float e2d::Node::width() const
{ {
return _width * _scaleX; return _size.width * _scaleX;
} }
float e2d::Node::getHeight() const float e2d::Node::height() const
{ {
return _height * _scaleY; return _size.height * _scaleY;
} }
float e2d::Node::getRealWidth() const e2d::Size e2d::Node::size() const
{ {
return _width; return Size(width(), height());
} }
float e2d::Node::getRealHeight() const float e2d::Node::realWidth() const
{ {
return _height; return _size.width;
} }
e2d::Size e2d::Node::getRealSize() const float e2d::Node::realHeight() const
{ {
return Size(_width, _height); return _size.height;
} }
float e2d::Node::getPivotX() const const e2d::Size& e2d::Node::realSize() const
{ {
return _pivotX; return _size;
} }
float e2d::Node::getPivotY() const float e2d::Node::anchorX() const
{ {
return _pivotY; return _anchorX;
} }
e2d::Size e2d::Node::getSize() const float e2d::Node::anchorY() const
{ {
return Size(getWidth(), getHeight()); return _anchorY;
} }
float e2d::Node::getScaleX() const float e2d::Node::scaleX() const
{ {
return _scaleX; return _scaleX;
} }
float e2d::Node::getScaleY() const float e2d::Node::scaleY() const
{ {
return _scaleY; return _scaleY;
} }
float e2d::Node::getSkewX() const float e2d::Node::skewX() const
{ {
return _skewAngleX; return _skewAngleX;
} }
float e2d::Node::getSkewY() const float e2d::Node::skewY() const
{ {
return _skewAngleY; return _skewAngleY;
} }
float e2d::Node::getRotation() const float e2d::Node::rotation() const
{ {
return _rotation; return _rotation;
} }
float e2d::Node::getOpacity() const float e2d::Node::opacity() const
{ {
return _realOpacity; return _realOpacity;
} }
e2d::Node::Property e2d::Node::getProperty() const e2d::Node::Property e2d::Node::properties() const
{ {
Property prop; Property prop;
prop.posX = _posX; prop.position = _position;
prop.posY = _posY; prop.size = _size;
prop.width = _width; prop.anchorX = _anchorX;
prop.height = _height; prop.anchorY = _anchorY;
prop.pivotX = _pivotX;
prop.pivotY = _pivotY;
prop.scaleX = _scaleX; prop.scaleX = _scaleX;
prop.scaleY = _scaleY; prop.scaleY = _scaleY;
prop.rotation = _rotation; prop.rotation = _rotation;
@ -414,212 +406,213 @@ e2d::Node::Property e2d::Node::getProperty() const
return std::move(prop); return std::move(prop);
} }
e2d::Node::Property e2d::Node::getExtrapolate() const e2d::Node::Property e2d::Node::extrapolate() const
{ {
return this->getProperty() - _extrapolate; return this->properties() - _extrapolate;
} }
e2d::Collider* e2d::Node::getCollider() e2d::Collider* e2d::Node::collider()
{ {
return &_collider; return &_collider;
} }
int e2d::Node::getOrder() const int e2d::Node::order() const
{ {
return _order; return _order;
} }
void e2d::Node::setOrder(int order) e2d::Node& e2d::Node::order(int order)
{ {
if (_order == order) if (_order == order)
return; return *this;
_order = order; _order = order;
if (_parent) if (_parent)
{ {
_parent->_needSort = true; _parent->_needSort = true;
} }
return *this;
} }
void e2d::Node::setPosX(float x) e2d::Node& e2d::Node::positionX(float x)
{ {
this->setPos(x, _posY); return position(x, _position.y);
} }
void e2d::Node::setPosY(float y) e2d::Node& e2d::Node::positionY(float y)
{ {
this->setPos(_posX, y); return position(_position.x, y);
} }
void e2d::Node::setPos(const Point & p) e2d::Node& e2d::Node::position(const Point & p)
{ {
this->setPos(p.x, p.y); return position(p.x, p.y);
} }
void e2d::Node::setPos(float x, float y) e2d::Node& e2d::Node::position(float x, float y)
{ {
if (_posX == x && _posY == y) if (_position.x == x && _position.y == y)
return; return *this;
_posX = x; _position.x = x;
_posY = y; _position.y = y;
_needTransform = true; _needTransform = true;
return *this;
} }
void e2d::Node::setPosFixed(bool fixed) e2d::Node& e2d::Node::positionFixed(bool fixed)
{ {
if (_positionFixed == fixed) if (_positionFixed == fixed)
return; return *this;
_positionFixed = fixed; _positionFixed = fixed;
_needTransform = true; _needTransform = true;
return *this;
} }
void e2d::Node::movePosX(float x) e2d::Node& e2d::Node::move(float x, float y)
{ {
this->movePos(x, 0); return position(_position.x + x, _position.y + y);
} }
void e2d::Node::movePosY(float y) e2d::Node& e2d::Node::move(const Vector2 & v)
{ {
this->movePos(0, y); return move(v.x, v.y);
} }
void e2d::Node::movePos(float x, float y) e2d::Node& e2d::Node::scaleX(float scaleX)
{ {
this->setPos(_posX + x, _posY + y); return scale(scaleX, _scaleY);
} }
void e2d::Node::movePos(const Vector2 & v) e2d::Node& e2d::Node::scaleY(float scaleY)
{ {
this->movePos(v.x, v.y); return scale(_scaleX, scaleY);
} }
void e2d::Node::setScaleX(float scaleX) e2d::Node& e2d::Node::scale(float scale0)
{ {
this->setScale(scaleX, _scaleY); return scale(scale0, scale0);
} }
void e2d::Node::setScaleY(float scaleY) e2d::Node& e2d::Node::scale(float scaleX, float scaleY)
{
this->setScale(_scaleX, scaleY);
}
void e2d::Node::setScale(float scale)
{
this->setScale(scale, scale);
}
void e2d::Node::setScale(float scaleX, float scaleY)
{ {
if (_scaleX == scaleX && _scaleY == scaleY) if (_scaleX == scaleX && _scaleY == scaleY)
return; return *this;
_scaleX = scaleX; _scaleX = scaleX;
_scaleY = scaleY; _scaleY = scaleY;
_needTransform = true; _needTransform = true;
return *this;
} }
void e2d::Node::setSkewX(float angleX) e2d::Node& e2d::Node::skewX(float angleX)
{ {
this->setSkew(angleX, _skewAngleY); return skew(angleX, _skewAngleY);
} }
void e2d::Node::setSkewY(float angleY) e2d::Node& e2d::Node::skewY(float angleY)
{ {
this->setSkew(_skewAngleX, angleY); return skew(_skewAngleX, angleY);
} }
void e2d::Node::setSkew(float angleX, float angleY) e2d::Node& e2d::Node::skew(float angleX, float angleY)
{ {
if (_skewAngleX == angleX && _skewAngleY == angleY) if (_skewAngleX == angleX && _skewAngleY == angleY)
return; return *this;
_skewAngleX = angleX; _skewAngleX = angleX;
_skewAngleY = angleY; _skewAngleY = angleY;
_needTransform = true; _needTransform = true;
return *this;
} }
void e2d::Node::setRotation(float angle) e2d::Node& e2d::Node::rotation(float angle)
{ {
if (_rotation == angle) if (_rotation == angle)
return; return *this;
_rotation = angle; _rotation = angle;
_needTransform = true; _needTransform = true;
return *this;
} }
void e2d::Node::setOpacity(float opacity) e2d::Node& e2d::Node::opacity(float opacity)
{ {
if (_realOpacity == opacity) if (_realOpacity == opacity)
return; return *this;
_displayOpacity = _realOpacity = std::min(std::max(opacity, 0.f), 1.f); _displayOpacity = _realOpacity = std::min(std::max(opacity, 0.f), 1.f);
// 更新节点透明度 // 更新节点透明度
_updateOpacity(); _updateOpacity();
return *this;
} }
void e2d::Node::setPivotX(float pivotX) e2d::Node& e2d::Node::anchorX(float anchorX)
{ {
this->setPivot(pivotX, _pivotY); return anchor(anchorX, _anchorY);
} }
void e2d::Node::setPivotY(float pivotY) e2d::Node& e2d::Node::anchorY(float anchorY)
{ {
this->setPivot(_pivotX, pivotY); return anchor(_anchorX, anchorY);
} }
void e2d::Node::setPivot(float pivotX, float pivotY) e2d::Node& e2d::Node::anchor(float anchorX, float anchorY)
{ {
if (_pivotX == pivotX && _pivotY == pivotY) if (_anchorX == anchorX && _anchorY == anchorY)
return; return *this;
_pivotX = std::min(std::max(pivotX, 0.f), 1.f); _anchorX = std::min(std::max(anchorX, 0.f), 1.f);
_pivotY = std::min(std::max(pivotY, 0.f), 1.f); _anchorY = std::min(std::max(anchorY, 0.f), 1.f);
_needTransform = true; _needTransform = true;
return *this;
} }
void e2d::Node::setWidth(float width) e2d::Node& e2d::Node::width(float width)
{ {
this->setSize(width, _height); return size(width, _size.height);
} }
void e2d::Node::setHeight(float height) e2d::Node& e2d::Node::height(float height)
{ {
this->setSize(_width, height); return size(_size.width, height);
} }
void e2d::Node::setSize(float width, float height) e2d::Node& e2d::Node::size(float width, float height)
{ {
if (_width == width && _height == height) if (_size.width == width && _size.height == height)
return; return *this;
_width = width; _size.width = width;
_height = height; _size.height = height;
_needTransform = true; _needTransform = true;
return *this;
} }
void e2d::Node::setSize(Size size) e2d::Node& e2d::Node::size(Size size0)
{ {
this->setSize(size.width, size.height); return size(size0.width, size0.height);
} }
void e2d::Node::setProperty(Property prop) e2d::Node& e2d::Node::properties(Property prop)
{ {
this->setPos(prop.posX, prop.posY); this->position(prop.position.x, prop.position.y);
this->setSize(prop.width, prop.height); this->size(prop.size.width, prop.size.height);
this->setPivot(prop.pivotX, prop.pivotY); this->anchor(prop.anchorX, prop.anchorY);
this->setScale(prop.scaleX, prop.scaleY); this->scale(prop.scaleX, prop.scaleY);
this->setRotation(prop.rotation); this->rotation(prop.rotation);
this->setSkew(prop.skewAngleX, prop.skewAngleY); this->skew(prop.skewAngleX, prop.skewAngleY);
return *this;
} }
void e2d::Node::setClipEnabled(bool enabled) e2d::Node& e2d::Node::clipEnabled(bool enabled)
{ {
_clipEnabled = enabled; _clipEnabled = enabled;
return *this;
} }
void e2d::Node::addChild(Node * child, int order /* = 0 */) e2d::Node& e2d::Node::addChild(Node * child, int order /* = 0 */)
{ {
WARN_IF(child == nullptr, "Node::addChild NULL pointer exception."); WARN_IF(child == nullptr, "Node::addChild NULL pointer exception.");
@ -630,7 +623,7 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */)
throw Exception("节点已有父节点, 不能再添加到其他节点"); throw Exception("节点已有父节点, 不能再添加到其他节点");
} }
for (Node * parent = this; parent != nullptr; parent = parent->getParent()) for (Node * parent = this; parent != nullptr; parent = parent->parent())
{ {
if (child == parent) if (child == parent)
{ {
@ -640,7 +633,7 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */)
child->retain(); child->retain();
_children.push_back(child); _children.push_back(child);
child->setOrder(order); child->order(order);
child->_parent = this; child->_parent = this;
if (this->_parentScene) if (this->_parentScene)
{ {
@ -654,27 +647,29 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */)
// 更新子节点排序 // 更新子节点排序
_needSort = true; _needSort = true;
} }
return *this;
} }
void e2d::Node::addChild(const std::vector<Node*>& nodes, int order) e2d::Node& e2d::Node::addChild(const std::vector<Node*>& nodes, int order)
{ {
for (const auto& node : nodes) for (const auto& node : nodes)
{ {
this->addChild(node, order); this->addChild(node, order);
} }
return *this;
} }
e2d::Node * e2d::Node::getParent() const e2d::Node * e2d::Node::parent() const
{ {
return _parent; return _parent;
} }
e2d::Scene * e2d::Node::getParentScene() const e2d::Scene * e2d::Node::parentScene() const
{ {
return _parentScene; return _parentScene;
} }
std::vector<e2d::Node*> e2d::Node::getChildren(const String& name) const std::vector<e2d::Node*> e2d::Node::children(const String& name) const
{ {
std::vector<Node*> vChildren; std::vector<Node*> vChildren;
size_t hash = name.hash(); size_t hash = name.hash();
@ -690,7 +685,7 @@ std::vector<e2d::Node*> e2d::Node::getChildren(const String& name) const
return std::move(vChildren); return std::move(vChildren);
} }
e2d::Node * e2d::Node::getChild(const String& name) const e2d::Node * e2d::Node::child(const String& name) const
{ {
size_t hash = name.hash(); size_t hash = name.hash();
@ -705,31 +700,32 @@ e2d::Node * e2d::Node::getChild(const String& name) const
return nullptr; return nullptr;
} }
const std::vector<e2d::Node*>& e2d::Node::getAllChildren() const const std::vector<e2d::Node*>& e2d::Node::children() const
{ {
return _children; return _children;
} }
int e2d::Node::getChildrenCount() const int e2d::Node::childrenCount() const
{ {
return static_cast<int>(_children.size()); return static_cast<int>(_children.size());
} }
void e2d::Node::removeFromParent() e2d::Node& e2d::Node::removeFromParent()
{ {
if (_parent) if (_parent)
{ {
_parent->removeChild(this); _parent->removeChild(this);
} }
return *this;
} }
bool e2d::Node::removeChild(Node * child) e2d::Node& e2d::Node::removeChild(Node * child)
{ {
WARN_IF(child == nullptr, "Node::removeChildren NULL pointer exception."); WARN_IF(child == nullptr, "Node::removeChildren NULL pointer exception.");
if (_children.empty()) if (_children.empty())
{ {
return false; return *this;
} }
if (child) if (child)
@ -746,19 +742,19 @@ bool e2d::Node::removeChild(Node * child)
} }
child->release(); child->release();
return true; return *this;
} }
} }
return false; return *this;
} }
void e2d::Node::removeChildren(const String& childName) e2d::Node& e2d::Node::removeChildren(const String& childName)
{ {
WARN_IF(childName.isEmpty(), "Invalid Node name."); WARN_IF(childName.empty(), "Invalid Node name.");
if (_children.empty()) if (_children.empty())
{ {
return; return *this;
} }
// 计算名称 Hash 值 // 计算名称 Hash 值
@ -780,9 +776,10 @@ void e2d::Node::removeChildren(const String& childName)
(*iter)->release(); (*iter)->release();
_children.erase(iter); _children.erase(iter);
} }
return *this;
} }
void e2d::Node::removeAllChildren() e2d::Node& e2d::Node::removeAllChildren()
{ {
// 所有节点的引用计数减一 // 所有节点的引用计数减一
for (const auto& child : _children) for (const auto& child : _children)
@ -791,47 +788,52 @@ void e2d::Node::removeAllChildren()
} }
// 清空储存节点的容器 // 清空储存节点的容器
_children.clear(); _children.clear();
return *this;
} }
void e2d::Node::runAction(Action * action) e2d::Node& e2d::Node::runAction(Action * action)
{ {
ActionManager::getInstance()->start(action, this, false); ActionManager::instance()->start(action, this, false);
return *this;
} }
void e2d::Node::resumeAction(const String& name) e2d::Node& e2d::Node::resumeAction(const String& name)
{ {
auto& actions = ActionManager::getInstance()->get(name); auto& actions = ActionManager::instance()->actions(name);
for (const auto& action : actions) for (const auto& action : actions)
{ {
if (action->getTarget() == this) if (action->target() == this)
{ {
action->resume(); action->resume();
} }
} }
return *this;
} }
void e2d::Node::pauseAction(const String& name) e2d::Node& e2d::Node::pauseAction(const String& name)
{ {
auto& actions = ActionManager::getInstance()->get(name); auto& actions = ActionManager::instance()->actions(name);
for (const auto& action : actions) for (const auto& action : actions)
{ {
if (action->getTarget() == this) if (action->target() == this)
{ {
action->pause(); action->pause();
} }
} }
return *this;
} }
void e2d::Node::stopAction(const String& name) e2d::Node& e2d::Node::stopAction(const String& name)
{ {
auto& actions = ActionManager::getInstance()->get(name); auto& actions = ActionManager::instance()->actions(name);
for (const auto& action : actions) for (const auto& action : actions)
{ {
if (action->getTarget() == this) if (action->target() == this)
{ {
action->stop(); action->stop();
} }
} }
return *this;
} }
bool e2d::Node::containsPoint(const Point& point) bool e2d::Node::containsPoint(const Point& point)
@ -842,11 +844,11 @@ bool e2d::Node::containsPoint(const Point& point)
// 为节点创建一个轮廓 // 为节点创建一个轮廓
BOOL ret = 0; BOOL ret = 0;
ID2D1RectangleGeometry * rectGeo = nullptr; ID2D1RectangleGeometry * rectGeo = nullptr;
auto factory = Game::getInstance()->getRenderer()->getFactory(); auto factory = Game::instance()->renderer()->factory();
ThrowIfFailed( ThrowIfFailed(
factory->CreateRectangleGeometry( factory->CreateRectangleGeometry(
D2D1::RectF(0, 0, _width, _height), D2D1::RectF(0, 0, _size.width, _size.height),
&rectGeo &rectGeo
) )
); );
@ -874,18 +876,18 @@ bool e2d::Node::intersects(Node * node)
D2D1_GEOMETRY_RELATION relation = D2D1_GEOMETRY_RELATION_UNKNOWN; D2D1_GEOMETRY_RELATION relation = D2D1_GEOMETRY_RELATION_UNKNOWN;
ID2D1RectangleGeometry *rectGeo = nullptr, *rectGeo2 = nullptr; ID2D1RectangleGeometry *rectGeo = nullptr, *rectGeo2 = nullptr;
ID2D1TransformedGeometry *transGeo = nullptr, *transGeo2 = nullptr; ID2D1TransformedGeometry *transGeo = nullptr, *transGeo2 = nullptr;
auto factory = Game::getInstance()->getRenderer()->getFactory(); auto factory = Game::instance()->renderer()->factory();
ThrowIfFailed( ThrowIfFailed(
factory->CreateRectangleGeometry( factory->CreateRectangleGeometry(
D2D1::RectF(0, 0, _width, _height), D2D1::RectF(0, 0, _size.width, _size.height),
&rectGeo &rectGeo
) )
); );
ThrowIfFailed( ThrowIfFailed(
factory->CreateRectangleGeometry( factory->CreateRectangleGeometry(
D2D1::RectF(0, 0, node->_width, node->_height), D2D1::RectF(0, 0, node->_size.width, node->_size.height),
&rectGeo2 &rectGeo2
) )
); );
@ -924,37 +926,43 @@ bool e2d::Node::intersects(Node * node)
relation != D2D1_GEOMETRY_RELATION_DISJOINT; relation != D2D1_GEOMETRY_RELATION_DISJOINT;
} }
void e2d::Node::resumeAllActions() e2d::Node& e2d::Node::resumeAllActions()
{ {
ActionManager::getInstance()->resumeAllBindedWith(this); ActionManager::instance()->resumeAllBindedWith(this);
return *this;
} }
void e2d::Node::pauseAllActions() e2d::Node& e2d::Node::pauseAllActions()
{ {
ActionManager::getInstance()->pauseAllBindedWith(this); ActionManager::instance()->pauseAllBindedWith(this);
return *this;
} }
void e2d::Node::stopAllActions() e2d::Node& e2d::Node::stopAllActions()
{ {
ActionManager::getInstance()->stopAllBindedWith(this); ActionManager::instance()->stopAllBindedWith(this);
return *this;
} }
void e2d::Node::setVisible(bool value) e2d::Node& e2d::Node::visible(bool value)
{ {
_visible = value; _visible = value;
return *this;
} }
void e2d::Node::setName(const String& name) e2d::Node& e2d::Node::name(const String& name)
{ {
WARN_IF(name.isEmpty(), "Invalid Node name."); WARN_IF(name.empty(), "Invalid Node name.");
if (!name.isEmpty() && _name != name) if (!name.empty() && _name != name)
{ {
// 保存节点名 // 保存节点名
_name = name; _name = name;
// 保存节点 Hash 名 // 保存节点 Hash 名
_hashName = name.hash(); _hashName = name.hash();
} }
return *this;
} }
void e2d::Node::_setParentScene(Scene * scene) void e2d::Node::_setParentScene(Scene * scene)

View File

@ -12,14 +12,16 @@ e2d::Scene::~Scene()
{ {
} }
void e2d::Scene::setOutlineVisible(bool visible) e2d::Scene& e2d::Scene::outlineVisible(bool visible)
{ {
_outlineVisible = visible; _outlineVisible = visible;
return *this;
} }
void e2d::Scene::setColliderVisible(bool visible) e2d::Scene& e2d::Scene::colliderVisible(bool visible)
{ {
_colliderVisible = visible; _colliderVisible = visible;
return *this;
} }
void e2d::Scene::visit(Game * game) void e2d::Scene::visit(Game * game)
@ -28,14 +30,14 @@ void e2d::Scene::visit(Game * game)
if (_outlineVisible) if (_outlineVisible)
{ {
auto brush = game->getRenderer()->getSolidColorBrush(); auto brush = game->renderer()->solidBrush();
brush->SetColor(D2D1::ColorF(D2D1::ColorF::Red, 0.6f)); brush->SetColor(D2D1::ColorF(D2D1::ColorF::Red, 0.6f));
brush->SetOpacity(1.f); brush->SetOpacity(1.f);
this->drawOutline(game->getRenderer()); this->drawOutline(game->renderer());
} }
if (_colliderVisible) if (_colliderVisible)
{ {
game->getRenderer()->getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); game->renderer()->renderTarget()->SetTransform(D2D1::Matrix3x2F::Identity());
this->drawCollider(); this->drawCollider();
} }
} }

View File

@ -40,7 +40,7 @@ e2d::Sprite::Sprite(const String & fileName, const Rect & cropRect)
e2d::Sprite::~Sprite() e2d::Sprite::~Sprite()
{ {
GC::getInstance()->safeRelease(_image); GC::instance()->safeRelease(_image);
} }
bool e2d::Sprite::open(Image * image) bool e2d::Sprite::open(Image * image)
@ -51,7 +51,7 @@ bool e2d::Sprite::open(Image * image)
_image = image; _image = image;
_image->retain(); _image->retain();
Node::setSize(_image->getWidth(), _image->getHeight()); Node::size(_image->width(), _image->height());
return true; return true;
} }
return false; return false;
@ -67,7 +67,7 @@ bool e2d::Sprite::open(const Resource& res)
if (_image->open(res)) if (_image->open(res))
{ {
Node::setSize(_image->getWidth(), _image->getHeight()); Node::size(_image->width(), _image->height());
return true; return true;
} }
return false; return false;
@ -83,44 +83,45 @@ bool e2d::Sprite::open(const String & fileName)
if (_image->open(fileName)) if (_image->open(fileName))
{ {
Node::setSize(_image->getWidth(), _image->getHeight()); Node::size(_image->width(), _image->height());
return true; return true;
} }
return false; return false;
} }
void e2d::Sprite::crop(const Rect& cropRect) e2d::Sprite& e2d::Sprite::crop(const Rect& cropRect)
{ {
_image->crop(cropRect); _image->crop(cropRect);
Node::setSize( Node::size(
std::min(std::max(cropRect.size.width, 0.f), _image->getSourceWidth() - _image->getCropX()), std::min(std::max(cropRect.size.width, 0.f), _image->realWidth() - _image->cropX()),
std::min(std::max(cropRect.size.height, 0.f), _image->getSourceHeight() - _image->getCropY()) std::min(std::max(cropRect.size.height, 0.f), _image->realHeight() - _image->cropY())
); );
return *this;
} }
e2d::Image * e2d::Sprite::getImage() const e2d::Image * e2d::Sprite::image() const
{ {
return _image; return _image;
} }
void e2d::Sprite::draw(Renderer * renderer) const void e2d::Sprite::draw(Renderer * renderer) const
{ {
if (_image && _image->getBitmap()) if (_image && _image->bitmap())
{ {
// »ñȡͼƬ²Ã¼ôλÖà // »ñȡͼƬ²Ã¼ôλÖÃ
float fCropX = _image->getCropX(); float fCropX = _image->cropX();
float fCropY = _image->getCropY(); float fCropY = _image->cropY();
// äÖȾͼƬ // äÖȾͼƬ
renderer->getRenderTarget()->DrawBitmap( renderer->renderTarget()->DrawBitmap(
_image->getBitmap(), _image->bitmap(),
D2D1::RectF(0, 0, _width, _height), D2D1::RectF(0, 0, _size.width, _size.height),
_displayOpacity, _displayOpacity,
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
D2D1::RectF( D2D1::RectF(
fCropX, fCropX,
fCropY, fCropY,
fCropX + _width, fCropX + _size.width,
fCropY + _height fCropY + _size.height
) )
); );
} }

View File

@ -74,57 +74,57 @@ e2d::Text::~Text()
SafeRelease(_textLayout); SafeRelease(_textLayout);
} }
e2d::String e2d::Text::getText() const const e2d::String& e2d::Text::text() const
{ {
return _text; return _text;
} }
e2d::Font e2d::Text::getFont() const const e2d::Font& e2d::Text::font() const
{ {
return _font; return _font;
} }
e2d::Text::Style e2d::Text::getStyle() const const e2d::Text::Style& e2d::Text::style() const
{ {
return _style; return _style;
} }
e2d::String e2d::Text::getFontFamily() const const e2d::String& e2d::Text::fontFamily() const
{ {
return _font.family; return _font.family;
} }
float e2d::Text::getFontSize() const float e2d::Text::fontSize() const
{ {
return _font.size; return _font.size;
} }
UINT e2d::Text::getFontWeight() const UINT e2d::Text::fontWeight() const
{ {
return _font.weight; return _font.weight;
} }
e2d::Color e2d::Text::getColor() const const e2d::Color& e2d::Text::color() const
{ {
return _style.color; return _style.color;
} }
e2d::Color e2d::Text::getOutlineColor() const const e2d::Color& e2d::Text::outlineColor() const
{ {
return _style.outlineColor; return _style.outlineColor;
} }
float e2d::Text::getOutlineWidth() const float e2d::Text::outlineWidth() const
{ {
return _style.outlineWidth; return _style.outlineWidth;
} }
e2d::Stroke e2d::Text::getOutlineStroke() const e2d::Stroke e2d::Text::outlineStroke() const
{ {
return _style.outlineStroke; return _style.outlineStroke;
} }
int e2d::Text::getLineCount() const int e2d::Text::lineCount() const
{ {
if (_textLayout) if (_textLayout)
{ {
@ -138,7 +138,7 @@ int e2d::Text::getLineCount() const
} }
} }
bool e2d::Text::isItalic() const bool e2d::Text::italic() const
{ {
return _font.italic; return _font.italic;
} }
@ -158,63 +158,72 @@ bool e2d::Text::hasOutline() const
return _style.hasOutline; return _style.hasOutline;
} }
void e2d::Text::setText(const String& text) e2d::Text& e2d::Text::text(const String& text)
{ {
_text = text; _text = text;
_reset(); _reset();
return *this;
} }
void e2d::Text::setStyle(const Style& style) e2d::Text& e2d::Text::style(const Style& style)
{ {
_style = style; _style = style;
_reset(); _reset();
return *this;
} }
void e2d::Text::setFont(const Font & font) e2d::Text& e2d::Text::font(const Font & font)
{ {
_font = font; _font = font;
_reset(); _reset();
return *this;
} }
void e2d::Text::setFontFamily(const String& family) e2d::Text& e2d::Text::fontFamily(const String& family)
{ {
_font.family = family; _font.family = family;
_reset(); _reset();
return *this;
} }
void e2d::Text::setFontSize(float size) e2d::Text& e2d::Text::fontSize(float size)
{ {
_font.size = size; _font.size = size;
_reset(); _reset();
return *this;
} }
void e2d::Text::setFontWeight(UINT weight) e2d::Text& e2d::Text::fontWeight(UINT weight)
{ {
_font.weight = weight; _font.weight = weight;
_reset(); _reset();
return *this;
} }
void e2d::Text::setColor(Color color) e2d::Text& e2d::Text::color(Color color)
{ {
_style.color = color; _style.color = color;
return *this;
} }
void e2d::Text::setItalic(bool value) e2d::Text& e2d::Text::italic(bool value)
{ {
_font.italic = value; _font.italic = value;
_reset(); _reset();
return *this;
} }
void e2d::Text::setWrapping(bool wrapping) e2d::Text& e2d::Text::wrapping(bool wrapping)
{ {
if (_style.wrapping != wrapping) if (_style.wrapping != wrapping)
{ {
_style.wrapping = wrapping; _style.wrapping = wrapping;
_reset(); _reset();
} }
return *this;
} }
void e2d::Text::setWrappingWidth(float wrappingWidth) e2d::Text& e2d::Text::wrappingWidth(float wrappingWidth)
{ {
if (_style.wrappingWidth != wrappingWidth) if (_style.wrappingWidth != wrappingWidth)
{ {
@ -225,27 +234,30 @@ void e2d::Text::setWrappingWidth(float wrappingWidth)
_reset(); _reset();
} }
} }
return *this;
} }
void e2d::Text::setLineSpacing(float lineSpacing) e2d::Text& e2d::Text::lineSpacing(float lineSpacing)
{ {
if (_style.lineSpacing != lineSpacing) if (_style.lineSpacing != lineSpacing)
{ {
_style.lineSpacing = lineSpacing; _style.lineSpacing = lineSpacing;
_reset(); _reset();
} }
return *this;
} }
void e2d::Text::setAlignment(Align align) e2d::Text& e2d::Text::alignment(Align align)
{ {
if (_style.alignment != align) if (_style.alignment != align)
{ {
_style.alignment = align; _style.alignment = align;
_reset(); _reset();
} }
return *this;
} }
void e2d::Text::setUnderline(bool hasUnderline) e2d::Text& e2d::Text::underline(bool hasUnderline)
{ {
if (_style.hasUnderline != hasUnderline) if (_style.hasUnderline != hasUnderline)
{ {
@ -254,9 +266,10 @@ void e2d::Text::setUnderline(bool hasUnderline)
_createFormat(); _createFormat();
_createLayout(); _createLayout();
} }
return *this;
} }
void e2d::Text::setStrikethrough(bool hasStrikethrough) e2d::Text& e2d::Text::strikethrough(bool hasStrikethrough)
{ {
if (_style.hasStrikethrough != hasStrikethrough) if (_style.hasStrikethrough != hasStrikethrough)
{ {
@ -265,26 +278,31 @@ void e2d::Text::setStrikethrough(bool hasStrikethrough)
_createFormat(); _createFormat();
_createLayout(); _createLayout();
} }
return *this;
} }
void e2d::Text::setOutline(bool hasOutline) e2d::Text& e2d::Text::outline(bool hasOutline)
{ {
_style.hasOutline = hasOutline; _style.hasOutline = hasOutline;
return *this;
} }
void e2d::Text::setOutlineColor(Color outlineColor) e2d::Text& e2d::Text::outlineColor(Color outlineColor)
{ {
_style.outlineColor = outlineColor; _style.outlineColor = outlineColor;
return *this;
} }
void e2d::Text::setOutlineWidth(float outlineWidth) e2d::Text& e2d::Text::outlineWidth(float outlineWidth)
{ {
_style.outlineWidth = outlineWidth; _style.outlineWidth = outlineWidth;
return *this;
} }
void e2d::Text::setOutlineStroke(Stroke outlineStroke) e2d::Text& e2d::Text::outlineStroke(Stroke outlineStroke)
{ {
_style.outlineStroke = outlineStroke; _style.outlineStroke = outlineStroke;
return *this;
} }
void e2d::Text::draw(Renderer * renderer) const void e2d::Text::draw(Renderer * renderer) const
@ -292,11 +310,11 @@ void e2d::Text::draw(Renderer * renderer) const
if (_textLayout) if (_textLayout)
{ {
// 创建文本区域 // 创建文本区域
D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, _width, _height); D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, _size.width, _size.height);
// 设置画刷颜色和透明度 // 设置画刷颜色和透明度
renderer->getSolidColorBrush()->SetOpacity(_displayOpacity); renderer->solidBrush()->SetOpacity(_displayOpacity);
// 获取文本渲染器 // 获取文本渲染器
auto pTextRenderer = renderer->getTextRenderer(); auto pTextRenderer = renderer->textRenderer();
pTextRenderer->SetTextStyle( pTextRenderer->SetTextStyle(
(D2D1_COLOR_F)_style.color, (D2D1_COLOR_F)_style.color,
_style.hasOutline, _style.hasOutline,
@ -320,7 +338,7 @@ void e2d::Text::_createFormat()
{ {
SafeRelease(_textFormat); SafeRelease(_textFormat);
HRESULT hr = Game::getInstance()->getRenderer()->getWriteFactory()->CreateTextFormat( HRESULT hr = Game::instance()->renderer()->writeFactory()->CreateTextFormat(
(const WCHAR *)_font.family, (const WCHAR *)_font.family,
nullptr, nullptr,
DWRITE_FONT_WEIGHT(_font.weight), DWRITE_FONT_WEIGHT(_font.weight),
@ -371,9 +389,9 @@ void e2d::Text::_createLayout()
SafeRelease(_textLayout); SafeRelease(_textLayout);
// 文本为空字符串时,重置属性 // 文本为空字符串时,重置属性
if (_text.isEmpty()) if (_text.empty())
{ {
this->setSize(0, 0); this->size(0, 0);
return; return;
} }
@ -385,7 +403,7 @@ void e2d::Text::_createLayout()
HRESULT hr; HRESULT hr;
UINT32 length = (UINT32)_text.length(); UINT32 length = (UINT32)_text.length();
auto writeFactory = Game::getInstance()->getRenderer()->getWriteFactory(); auto writeFactory = Game::instance()->renderer()->writeFactory();
// 对文本自动换行情况下进行处理 // 对文本自动换行情况下进行处理
if (_style.wrapping) if (_style.wrapping)
@ -404,7 +422,7 @@ void e2d::Text::_createLayout()
DWRITE_TEXT_METRICS metrics; DWRITE_TEXT_METRICS metrics;
_textLayout->GetMetrics(&metrics); _textLayout->GetMetrics(&metrics);
// 重设文本宽高 // 重设文本宽高
this->setSize(metrics.layoutWidth, metrics.height); this->size(metrics.layoutWidth, metrics.height);
} }
} }
else else
@ -417,10 +435,10 @@ void e2d::Text::_createLayout()
DWRITE_TEXT_METRICS metrics; DWRITE_TEXT_METRICS metrics;
_textLayout->GetMetrics(&metrics); _textLayout->GetMetrics(&metrics);
// 重设文本宽高 // 重设文本宽高
this->setSize(metrics.width, metrics.height); this->size(metrics.width, metrics.height);
// 重新创建 layout // 重新创建 layout
SafeRelease(_textLayout); SafeRelease(_textLayout);
hr = writeFactory->CreateTextLayout((const WCHAR *)_text, length, _textFormat, _width, 0, &_textLayout); hr = writeFactory->CreateTextLayout((const WCHAR *)_text, length, _textFormat, _size.width, 0, &_textLayout);
} }
} }

View File

@ -8,7 +8,7 @@
if (Old) this->removeChild(Old); \ if (Old) this->removeChild(Old); \
if (New) \ if (New) \
{ \ { \
New->setPivot(_pivotX, _pivotY); \ New->anchor(_anchorX, _anchorY); \
this->addChild(New); \ this->addChild(New); \
} \ } \
Old = New; \ Old = New; \
@ -43,9 +43,9 @@ e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, c
, _selectedOff(nullptr) , _selectedOff(nullptr)
, _disabledOff(nullptr) , _disabledOff(nullptr)
{ {
this->setNormal(toggleOnNormal); this->normal(toggleOnNormal);
this->setNormalOff(toggleOffNormal); this->normalOff(toggleOffNormal);
this->setClickFunc(func); this->clickCallback(func);
} }
e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func) e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func)
@ -60,11 +60,11 @@ e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, N
, _selectedOff(nullptr) , _selectedOff(nullptr)
, _disabledOff(nullptr) , _disabledOff(nullptr)
{ {
this->setNormal(toggleOnNormal); this->normal(toggleOnNormal);
this->setNormalOff(toggleOffNormal); this->normalOff(toggleOffNormal);
this->setSelected(toggleOnSelected); this->selected(toggleOnSelected);
this->setSelectedOff(toggleOffSelected); this->selectedOff(toggleOffSelected);
this->setClickFunc(func); this->clickCallback(func);
} }
e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func) e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func)
@ -79,13 +79,13 @@ e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, N
, _selectedOff(nullptr) , _selectedOff(nullptr)
, _disabledOff(nullptr) , _disabledOff(nullptr)
{ {
this->setNormal(toggleOnNormal); this->normal(toggleOnNormal);
this->setNormalOff(toggleOffNormal); this->normalOff(toggleOffNormal);
this->setMouseOver(toggleOnMouseOver); this->mouseover(toggleOnMouseOver);
this->setMouseOverOff(toggleOffMouseOver); this->mouseOverOff(toggleOffMouseOver);
this->setSelected(toggleOnSelected); this->selected(toggleOnSelected);
this->setSelectedOff(toggleOffSelected); this->selectedOff(toggleOffSelected);
this->setClickFunc(func); this->clickCallback(func);
} }
e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, Node * toggleOnDisabled, Node * toggleOffDisabled, const Function& func) e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, Node * toggleOnDisabled, Node * toggleOffDisabled, const Function& func)
@ -96,23 +96,23 @@ e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, N
, _selectedOff(nullptr) , _selectedOff(nullptr)
, _disabledOff(nullptr) , _disabledOff(nullptr)
{ {
this->setNormal(toggleOnNormal); this->normal(toggleOnNormal);
this->setNormalOff(toggleOffNormal); this->normalOff(toggleOffNormal);
this->setMouseOver(toggleOnMouseOver); this->mouseover(toggleOnMouseOver);
this->setMouseOverOff(toggleOffMouseOver); this->mouseOverOff(toggleOffMouseOver);
this->setSelected(toggleOnSelected); this->selected(toggleOnSelected);
this->setSelectedOff(toggleOffSelected); this->selectedOff(toggleOffSelected);
this->setDisabled(toggleOnDisabled); this->disabled(toggleOnDisabled);
this->setDisabledOff(toggleOffDisabled); this->disabledOff(toggleOffDisabled);
this->setClickFunc(func); this->clickCallback(func);
} }
bool e2d::ToggleButton::isChecked() const bool e2d::ToggleButton::checked() const
{ {
return _checked; return _checked;
} }
void e2d::ToggleButton::setChecked(bool checked) e2d::ToggleButton& e2d::ToggleButton::checked(bool checked)
{ {
if (_checked != checked) if (_checked != checked)
{ {
@ -120,63 +120,73 @@ void e2d::ToggleButton::setChecked(bool checked)
_updateStatus(); _updateStatus();
_updateVisible(); _updateVisible();
} }
return *this;
} }
void e2d::ToggleButton::setNormal(Node * normal) e2d::ToggleButton& e2d::ToggleButton::normal(Node * normal)
{ {
SET_BUTTON_NODE(_normalOn, normal); SET_BUTTON_NODE(_normalOn, normal);
if (normal) if (normal)
{ {
this->setSize(normal->getWidth(), normal->getHeight()); this->size(normal->width(), normal->height());
} }
return *this;
} }
void e2d::ToggleButton::setMouseOver(Node * mouseover) e2d::ToggleButton& e2d::ToggleButton::mouseover(Node * mouseover)
{ {
SET_BUTTON_NODE(_mouseoverOn, mouseover); SET_BUTTON_NODE(_mouseoverOn, mouseover);
return *this;
} }
void e2d::ToggleButton::setSelected(Node * selected) e2d::ToggleButton& e2d::ToggleButton::selected(Node * selected)
{ {
SET_BUTTON_NODE(_selectedOn, selected); SET_BUTTON_NODE(_selectedOn, selected);
return *this;
} }
void e2d::ToggleButton::setDisabled(Node * disabled) e2d::ToggleButton& e2d::ToggleButton::disabled(Node * disabled)
{ {
SET_BUTTON_NODE(_disabledOn, disabled); SET_BUTTON_NODE(_disabledOn, disabled);
return *this;
} }
void e2d::ToggleButton::setNormalOff(Node * normal) e2d::ToggleButton& e2d::ToggleButton::normalOff(Node * normal)
{ {
SET_BUTTON_NODE(_normalOff, normal); SET_BUTTON_NODE(_normalOff, normal);
return *this;
} }
void e2d::ToggleButton::setMouseOverOff(Node * mouseover) e2d::ToggleButton& e2d::ToggleButton::mouseOverOff(Node * mouseover)
{ {
SET_BUTTON_NODE(_mouseoverOff, mouseover); SET_BUTTON_NODE(_mouseoverOff, mouseover);
return *this;
} }
void e2d::ToggleButton::setSelectedOff(Node * selected) e2d::ToggleButton& e2d::ToggleButton::selectedOff(Node * selected)
{ {
SET_BUTTON_NODE(_selectedOff, selected); SET_BUTTON_NODE(_selectedOff, selected);
return *this;
} }
void e2d::ToggleButton::setDisabledOff(Node * disabled) e2d::ToggleButton& e2d::ToggleButton::disabledOff(Node * disabled)
{ {
SET_BUTTON_NODE(_disabledOff, disabled); SET_BUTTON_NODE(_disabledOff, disabled);
return *this;
} }
void e2d::ToggleButton::setPivot(float pivotX, float pivotY) e2d::ToggleButton& e2d::ToggleButton::anchor(float anchorX, float anchorY)
{ {
Node::setPivot(pivotX, pivotY); Node::anchor(anchorX, anchorY);
SAFE_SET(_normalOn, setPivot, pivotX, pivotY); SAFE_SET(_normalOn, anchor, anchorX, anchorY);
SAFE_SET(_mouseoverOn, setPivot, pivotX, pivotY); SAFE_SET(_mouseoverOn, anchor, anchorX, anchorY);
SAFE_SET(_selectedOn, setPivot, pivotX, pivotY); SAFE_SET(_selectedOn, anchor, anchorX, anchorY);
SAFE_SET(_disabledOn, setPivot, pivotX, pivotY); SAFE_SET(_disabledOn, anchor, anchorX, anchorY);
SAFE_SET(_normalOff, setPivot, pivotX, pivotY); SAFE_SET(_normalOff, anchor, anchorX, anchorY);
SAFE_SET(_mouseoverOff, setPivot, pivotX, pivotY); SAFE_SET(_mouseoverOff, anchor, anchorX, anchorY);
SAFE_SET(_selectedOff, setPivot, pivotX, pivotY); SAFE_SET(_selectedOff, anchor, anchorX, anchorY);
SAFE_SET(_disabledOff, setPivot, pivotX, pivotY); SAFE_SET(_disabledOff, anchor, anchorX, anchorY);
return *this;
} }
void e2d::ToggleButton::_updateStatus() void e2d::ToggleButton::_updateStatus()
@ -188,10 +198,10 @@ void e2d::ToggleButton::_updateStatus()
_selected = _selectedOn; _selected = _selectedOn;
_disabled = _disabledOn; _disabled = _disabledOn;
SAFE_SET(_normalOff, setVisible, false); SAFE_SET(_normalOff, visible, false);
SAFE_SET(_mouseoverOff, setVisible, false); SAFE_SET(_mouseoverOff, visible, false);
SAFE_SET(_selectedOff, setVisible, false); SAFE_SET(_selectedOff, visible, false);
SAFE_SET(_disabledOff, setVisible, false); SAFE_SET(_disabledOff, visible, false);
} }
else else
{ {
@ -200,10 +210,10 @@ void e2d::ToggleButton::_updateStatus()
_selected = _selectedOff; _selected = _selectedOff;
_disabled = _disabledOff; _disabled = _disabledOff;
SAFE_SET(_normalOn, setVisible, false); SAFE_SET(_normalOn, visible, false);
SAFE_SET(_mouseoverOn, setVisible, false); SAFE_SET(_mouseoverOn, visible, false);
SAFE_SET(_selectedOn, setVisible, false); SAFE_SET(_selectedOn, visible, false);
SAFE_SET(_disabledOn, setVisible, false); SAFE_SET(_disabledOn, visible, false);
} }
} }

View File

@ -4,7 +4,7 @@
e2d::Data::Data(const String & key, const String & field) e2d::Data::Data(const String & key, const String & field)
: _key(key) : _key(key)
, _field(field) , _field(field)
, _dataPath(Path::getDataPath()) , _dataPath(Path::dataPath())
{ {
} }
@ -48,7 +48,7 @@ void e2d::Data::saveString(const String& value)
); );
} }
int e2d::Data::getInt(int defaultValue) int e2d::Data::toInt(int defaultValue)
{ {
return ::GetPrivateProfileInt( return ::GetPrivateProfileInt(
(LPCWSTR)_field, (LPCWSTR)_field,
@ -58,14 +58,14 @@ int e2d::Data::getInt(int defaultValue)
); );
} }
float e2d::Data::getDouble(float defaultValue) float e2d::Data::toDouble(float defaultValue)
{ {
wchar_t temp[32] = { 0 }; wchar_t temp[32] = { 0 };
::GetPrivateProfileString((LPCWSTR)_field, (LPCWSTR)_key, (LPCWSTR)String::parse(defaultValue), temp, 31, (LPCWSTR)_dataPath); ::GetPrivateProfileString((LPCWSTR)_field, (LPCWSTR)_key, (LPCWSTR)String::parse(defaultValue), temp, 31, (LPCWSTR)_dataPath);
return std::stof(temp); return std::stof(temp);
} }
bool e2d::Data::getBool(bool defaultValue) bool e2d::Data::toBool(bool defaultValue)
{ {
int nValue = ::GetPrivateProfileInt( int nValue = ::GetPrivateProfileInt(
(LPCWSTR)_field, (LPCWSTR)_field,
@ -75,7 +75,7 @@ bool e2d::Data::getBool(bool defaultValue)
return nValue != 0; return nValue != 0;
} }
e2d::String e2d::Data::getString(const String& defaultValue) e2d::String e2d::Data::toString(const String& defaultValue)
{ {
wchar_t temp[256] = { 0 }; wchar_t temp[256] = { 0 };
::GetPrivateProfileString( ::GetPrivateProfileString(

View File

@ -61,16 +61,16 @@ bool e2d::File::isFolder() const
return (_attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; return (_attributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
} }
e2d::String e2d::File::getFilePath() const const e2d::String& e2d::File::path() const
{ {
return _fileName; return _fileName;
} }
e2d::String e2d::File::getExtension() const e2d::String e2d::File::ext() const
{ {
String fileExtension; String fileExtension;
// 找到文件名中的最后一个 '.' 的位置 // 找到文件名中的最后一个 '.' 的位置
size_t pos = _fileName.getWString().find_last_of(L'.'); size_t pos = std::wstring(_fileName).find_last_of(L'.');
// 判断 pos 是否是有效位置 // 判断 pos 是否是有效位置
if (pos != std::wstring::npos) if (pos != std::wstring::npos)
{ {
@ -79,10 +79,10 @@ e2d::String e2d::File::getExtension() const
// 转换为小写字母 // 转换为小写字母
fileExtension = fileExtension.toLower(); fileExtension = fileExtension.toLower();
} }
return fileExtension; return std::move(fileExtension);
} }
bool e2d::File::deleteFile() bool e2d::File::del()
{ {
if (::DeleteFile((LPCWSTR)_fileName)) if (::DeleteFile((LPCWSTR)_fileName))
return true; return true;
@ -91,7 +91,7 @@ bool e2d::File::deleteFile()
e2d::File e2d::File::extract(int resNameId, const String & resType, const String& destFileName) e2d::File e2d::File::extract(int resNameId, const String & resType, const String& destFileName)
{ {
String destFilePath = Path::getTempPath() + destFileName; String destFilePath = Path::tempPath() + destFileName;
// 创建文件 // 创建文件
HANDLE hFile = ::CreateFile((LPCWSTR)destFilePath, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL); HANDLE hFile = ::CreateFile((LPCWSTR)destFilePath, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL);
if (hFile == INVALID_HANDLE_VALUE) if (hFile == INVALID_HANDLE_VALUE)
@ -135,7 +135,7 @@ void e2d::File::addSearchPath(const String & path)
bool e2d::File::createFolder(const String & dirPath) bool e2d::File::createFolder(const String & dirPath)
{ {
if (dirPath.isEmpty() || dirPath.length() >= MAX_PATH) if (dirPath.empty() || dirPath.length() >= MAX_PATH)
return false; return false;
wchar_t tmpDirPath[_MAX_PATH] = { 0 }; wchar_t tmpDirPath[_MAX_PATH] = { 0 };
@ -158,10 +158,10 @@ bool e2d::File::createFolder(const String & dirPath)
return true; return true;
} }
e2d::String e2d::File::getSaveFilePath(const String& title, const String& defExt) e2d::String e2d::File::openSaveDialog(const String& title, const String& defExt)
{ {
auto window = Game::getInstance()->getWindow(); auto window = Game::instance()->window();
HWND hwnd = window->getHWnd(); HWND hwnd = window->hWnd();
// 弹出保存对话框 // 弹出保存对话框
OPENFILENAME ofn = { 0 }; OPENFILENAME ofn = { 0 };

View File

@ -43,18 +43,18 @@ e2d::Music::XAudio2Tool::~XAudio2Tool()
CoUninitialize(); CoUninitialize();
} }
e2d::Music::XAudio2Tool* e2d::Music::XAudio2Tool::getInstance() e2d::Music::XAudio2Tool* e2d::Music::XAudio2Tool::instance()
{ {
static XAudio2Tool instance; static XAudio2Tool instance;
return &instance; return &instance;
} }
IXAudio2 * e2d::Music::XAudio2Tool::getXAudio2() IXAudio2 * e2d::Music::XAudio2Tool::xAudio2()
{ {
return _xAudio2; return _xAudio2;
} }
IXAudio2MasteringVoice * e2d::Music::XAudio2Tool::getMasteringVoice() IXAudio2MasteringVoice * e2d::Music::XAudio2Tool::masteringVoice()
{ {
return _masteringVoice; return _masteringVoice;
} }
@ -70,8 +70,9 @@ e2d::Music::Music()
, _dwSize(0) , _dwSize(0)
, _voice(nullptr) , _voice(nullptr)
, _voiceCallback(this) , _voiceCallback(this)
, _volume(1.f)
{ {
auto xAudio2 = XAudio2Tool::getInstance()->getXAudio2(); auto xAudio2 = XAudio2Tool::instance()->xAudio2();
xAudio2->AddRef(); xAudio2->AddRef();
} }
@ -85,8 +86,9 @@ e2d::Music::Music(const e2d::String & filePath)
, _dwSize(0) , _dwSize(0)
, _voice(nullptr) , _voice(nullptr)
, _voiceCallback(this) , _voiceCallback(this)
, _volume(1.f)
{ {
auto xAudio2 = XAudio2Tool::getInstance()->getXAudio2(); auto xAudio2 = XAudio2Tool::instance()->xAudio2();
xAudio2->AddRef(); xAudio2->AddRef();
this->open(filePath); this->open(filePath);
@ -102,8 +104,9 @@ e2d::Music::Music(const Resource& res)
, _dwSize(0) , _dwSize(0)
, _voice(nullptr) , _voice(nullptr)
, _voiceCallback(this) , _voiceCallback(this)
, _volume(1.f)
{ {
auto xAudio2 = XAudio2Tool::getInstance()->getXAudio2(); auto xAudio2 = XAudio2Tool::instance()->xAudio2();
xAudio2->AddRef(); xAudio2->AddRef();
this->open(res); this->open(res);
@ -113,7 +116,7 @@ e2d::Music::~Music()
{ {
close(); close();
auto xAudio2 = XAudio2Tool::getInstance()->getXAudio2(); auto xAudio2 = XAudio2Tool::instance()->xAudio2();
xAudio2->Release(); xAudio2->Release();
} }
@ -124,14 +127,14 @@ bool e2d::Music::open(const e2d::String & filePath)
close(); close();
} }
if (filePath.isEmpty()) if (filePath.empty())
{ {
WARN("MusicInfo::open Invalid file name."); WARN("MusicInfo::open Invalid file name.");
return false; return false;
} }
String actualFilePath = File(filePath).getFilePath(); String actualFilePath = File(filePath).path();
if (actualFilePath.isEmpty()) if (actualFilePath.empty())
{ {
WARN("MusicInfo::open File not found."); WARN("MusicInfo::open File not found.");
return false; return false;
@ -176,7 +179,7 @@ bool e2d::Music::open(const e2d::String & filePath)
} }
// ´´½¨ÒôÔ´ // ´´½¨ÒôÔ´
auto xAudio2 = XAudio2Tool::getInstance()->getXAudio2(); auto xAudio2 = XAudio2Tool::instance()->xAudio2();
HRESULT hr = xAudio2->CreateSourceVoice(&_voice, _wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &_voiceCallback); HRESULT hr = xAudio2->CreateSourceVoice(&_voice, _wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &_voiceCallback);
if (FAILED(hr)) if (FAILED(hr))
@ -255,7 +258,7 @@ bool e2d::Music::open(const Resource& res)
} }
// ´´½¨ÒôÔ´ // ´´½¨ÒôÔ´
auto xAudio2 = XAudio2Tool::getInstance()->getXAudio2(); auto xAudio2 = XAudio2Tool::instance()->xAudio2();
HRESULT hr = xAudio2->CreateSourceVoice(&_voice, _wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &_voiceCallback); HRESULT hr = xAudio2->CreateSourceVoice(&_voice, _wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &_voiceCallback);
if (FAILED(hr)) if (FAILED(hr))
@ -375,7 +378,7 @@ void e2d::Music::close()
_playing = false; _playing = false;
} }
bool e2d::Music::isPlaying() const bool e2d::Music::playing() const
{ {
if (_opened && _voice) if (_opened && _voice)
{ {
@ -387,13 +390,19 @@ bool e2d::Music::isPlaying() const
} }
} }
IXAudio2SourceVoice * e2d::Music::getIXAudio2SourceVoice() const float e2d::Music::volume() const
{
return _volume;
}
IXAudio2SourceVoice * e2d::Music::sourceVoice() const
{ {
return _voice; return _voice;
} }
bool e2d::Music::setVolume(float volume) bool e2d::Music::volume(float volume)
{ {
_volume = volume;
if (_voice) if (_voice)
{ {
return SUCCEEDED(_voice->SetVolume(volume)); return SUCCEEDED(_voice->SetVolume(volume));
@ -401,14 +410,14 @@ bool e2d::Music::setVolume(float volume)
return false; return false;
} }
void e2d::Music::setFuncOnEnd(const Function & func) void e2d::Music::callbackOnEnd(const Function & func)
{ {
_voiceCallback.SetFuncOnStreamEnd(func); _voiceCallback.SetCallbackOnStreamEnd(func);
} }
void e2d::Music::setFuncOnLoopEnd(const Function & func) void e2d::Music::callbackOnLoopEnd(const Function & func)
{ {
_voiceCallback.SetFuncOnLoopEnd(func); _voiceCallback.SetCallbackOnLoopEnd(func);
} }
bool e2d::Music::_readMMIO() bool e2d::Music::_readMMIO()

View File

@ -5,17 +5,17 @@ extern "C" const GUID DECLSPEC_SELECTANY FOLDERID_LocalAppData = {
}; };
e2d::String e2d::Path::getDataPath() const e2d::String& e2d::Path::dataPath()
{ {
static String dataPath; static String dataPath;
if (dataPath.isEmpty()) if (dataPath.empty())
{ {
// 设置数据的保存路径 // 设置数据的保存路径
String localAppDataPath = Path::getLocalAppDataPath(); String localAppDataPath = Path::localAppDataPath();
String title = Game::getInstance()->getWindow()->getTitle(); String title = Game::instance()->window()->title();
String folderName = String::parse(title.hash()); String folderName = String::parse(title.hash());
if (!localAppDataPath.isEmpty()) if (!localAppDataPath.empty())
{ {
dataPath = localAppDataPath + L"\\Easy2DGameData\\" << folderName << L"\\"; dataPath = localAppDataPath + L"\\Easy2DGameData\\" << folderName << L"\\";
@ -30,14 +30,14 @@ e2d::String e2d::Path::getDataPath()
return dataPath; return dataPath;
} }
e2d::String e2d::Path::getTempPath() const e2d::String& e2d::Path::tempPath()
{ {
static String tempPath; static String tempPath;
if (tempPath.isEmpty()) if (tempPath.empty())
{ {
// 设置临时文件保存路径 // 设置临时文件保存路径
wchar_t path[_MAX_PATH]; wchar_t path[_MAX_PATH];
String title = Game::getInstance()->getWindow()->getTitle(); String title = Game::instance()->window()->title();
String folderName = String::parse(title.hash()); String folderName = String::parse(title.hash());
if (0 != ::GetTempPath(_MAX_PATH, path)) if (0 != ::GetTempPath(_MAX_PATH, path))
@ -54,10 +54,10 @@ e2d::String e2d::Path::getTempPath()
return tempPath; return tempPath;
} }
e2d::String e2d::Path::getLocalAppDataPath() const e2d::String& e2d::Path::localAppDataPath()
{ {
static String localAppDataPath; static String localAppDataPath;
if (localAppDataPath.isEmpty()) if (localAppDataPath.empty())
{ {
// 获取 AppData/Local 文件夹的路径 // 获取 AppData/Local 文件夹的路径
typedef HRESULT(WINAPI* pFunSHGetKnownFolderPath)(const GUID& rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath); typedef HRESULT(WINAPI* pFunSHGetKnownFolderPath)(const GUID& rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath);
@ -77,10 +77,10 @@ e2d::String e2d::Path::getLocalAppDataPath()
return localAppDataPath; return localAppDataPath;
} }
e2d::String e2d::Path::getCurrentFilePath() const e2d::String& e2d::Path::currentFilePath()
{ {
static String currFilePath; static String currFilePath;
if (currFilePath.isEmpty()) if (currFilePath.empty())
{ {
TCHAR szPath[_MAX_PATH] = { 0 }; TCHAR szPath[_MAX_PATH] = { 0 };
if (::GetModuleFileName(nullptr, szPath, _MAX_PATH) != 0) if (::GetModuleFileName(nullptr, szPath, _MAX_PATH) != 0)

View File

@ -21,14 +21,14 @@ e2d::Player::~Player()
bool e2d::Player::preload(const String & filePath) bool e2d::Player::preload(const String & filePath)
{ {
if (filePath.isEmpty()) if (filePath.empty())
return false; return false;
Music * music = new (std::nothrow) Music(); Music * music = new (std::nothrow) Music();
if (music && music->open(filePath)) if (music && music->open(filePath))
{ {
music->setVolume(_volume); music->volume(_volume);
_musicList.insert(std::make_pair(filePath.hash(), music)); _musicList.insert(std::make_pair(filePath.hash(), music));
return true; return true;
} }
@ -37,7 +37,7 @@ bool e2d::Player::preload(const String & filePath)
bool e2d::Player::play(const String & filePath, int nLoopCount) bool e2d::Player::play(const String & filePath, int nLoopCount)
{ {
if (filePath.isEmpty()) if (filePath.empty())
return false; return false;
if (Player::preload(filePath)) if (Player::preload(filePath))
@ -53,7 +53,7 @@ bool e2d::Player::play(const String & filePath, int nLoopCount)
void e2d::Player::pause(const String & filePath) void e2d::Player::pause(const String & filePath)
{ {
if (filePath.isEmpty()) if (filePath.empty())
return; return;
size_t hash = filePath.hash(); size_t hash = filePath.hash();
@ -63,7 +63,7 @@ void e2d::Player::pause(const String & filePath)
void e2d::Player::resume(const String & filePath) void e2d::Player::resume(const String & filePath)
{ {
if (filePath.isEmpty()) if (filePath.empty())
return; return;
size_t hash = filePath.hash(); size_t hash = filePath.hash();
@ -73,7 +73,7 @@ void e2d::Player::resume(const String & filePath)
void e2d::Player::stop(const String & filePath) void e2d::Player::stop(const String & filePath)
{ {
if (filePath.isEmpty()) if (filePath.empty())
return; return;
size_t hash = filePath.hash(); size_t hash = filePath.hash();
@ -81,14 +81,14 @@ void e2d::Player::stop(const String & filePath)
_musicList[hash]->stop(); _musicList[hash]->stop();
} }
bool e2d::Player::isPlaying(const String & filePath) bool e2d::Player::playing(const String & filePath)
{ {
if (filePath.isEmpty()) if (filePath.empty())
return false; return false;
size_t hash = filePath.hash(); size_t hash = filePath.hash();
if (_musicList.end() != _musicList.find(hash)) if (_musicList.end() != _musicList.find(hash))
return _musicList[hash]->isPlaying(); return _musicList[hash]->playing();
return false; return false;
} }
@ -101,7 +101,7 @@ bool e2d::Player::preload(const Resource& res)
if (music && music->open(res)) if (music && music->open(res))
{ {
music->setVolume(_volume); music->volume(_volume);
_musicList.insert(std::make_pair(res.resNameId, music)); _musicList.insert(std::make_pair(res.resNameId, music));
return true; return true;
} }
@ -139,24 +139,24 @@ void e2d::Player::stop(const Resource& res)
_musicList[res.resNameId]->stop(); _musicList[res.resNameId]->stop();
} }
bool e2d::Player::isPlaying(const Resource& res) bool e2d::Player::playing(const Resource& res) const
{ {
if (_musicList.end() != _musicList.find(res.resNameId)) if (_musicList.end() != _musicList.find(res.resNameId))
return _musicList[res.resNameId]->isPlaying(); return _musicList.at(res.resNameId)->playing();
return false; return false;
} }
float e2d::Player::getVolume() float e2d::Player::volume() const
{ {
return _volume; return _volume;
} }
void e2d::Player::setVolume(float volume) void e2d::Player::volume(float volume)
{ {
_volume = std::min(std::max(volume, -224.f), 224.f); _volume = std::min(std::max(volume, -224.f), 224.f);
for (const auto& pair : _musicList) for (const auto& pair : _musicList)
{ {
pair.second->setVolume(_volume); pair.second->volume(_volume);
} }
} }

View File

@ -1,6 +1,6 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
std::default_random_engine &e2d::Random::__getEngine() std::default_random_engine &e2d::Random::__engine()
{ {
static std::random_device device; static std::random_device device;
static std::default_random_engine engine(device()); static std::default_random_engine engine(device());

View File

@ -78,7 +78,7 @@ bool e2d::Task::isRunning() const
return _running; return _running;
} }
e2d::String e2d::Task::getName() const e2d::String e2d::Task::name() const
{ {
return _name; return _name;
} }

View File

@ -1,7 +1,7 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
e2d::Timer * e2d::Timer::getInstance() e2d::Timer * e2d::Timer::instance()
{ {
static Timer instance; static Timer instance;
return &instance; return &instance;
@ -34,7 +34,7 @@ void e2d::Timer::stopTasks(const String& name)
{ {
for (const auto& task : _tasks) for (const auto& task : _tasks)
{ {
if (task->getName() == name) if (task->name() == name)
{ {
task->stop(); task->stop();
} }
@ -45,7 +45,7 @@ void e2d::Timer::startTasks(const String& name)
{ {
for (const auto& task : _tasks) for (const auto& task : _tasks)
{ {
if (task->getName() == name) if (task->name() == name)
{ {
task->start(); task->start();
} }
@ -56,7 +56,7 @@ void e2d::Timer::removeTasks(const String& name)
{ {
for (const auto& task : _tasks) for (const auto& task : _tasks)
{ {
if (task->getName() == name) if (task->name() == name)
{ {
task->_stopped = true; task->_stopped = true;
} }

View File

@ -34,8 +34,8 @@ bool e2d::MoveTransition::_init(Game * game, Scene * prev)
_startPos = Point(-width, 0); _startPos = Point(-width, 0);
} }
if (_outScene) _outScene->setPos(0, 0); if (_outScene) _outScene->position(0, 0);
_inScene->setPos(_startPos); _inScene->position(_startPos);
return true; return true;
} }
return false; return false;
@ -47,11 +47,11 @@ void e2d::MoveTransition::_update()
if (_outScene) if (_outScene)
{ {
_outScene->setPos(_posDelta * _delta); _outScene->position(_posDelta * _delta);
} }
if (_inScene) if (_inScene)
{ {
_inScene->setPos(_startPos + _posDelta * _delta); _inScene->position(_startPos + _posDelta * _delta);
} }
if (_delta >= 1) if (_delta >= 1)
@ -62,6 +62,6 @@ void e2d::MoveTransition::_update()
void e2d::MoveTransition::_reset() void e2d::MoveTransition::_reset()
{ {
if (_outScene) _outScene->setPos(0, 0); if (_outScene) _outScene->position(0, 0);
_inScene->setPos(0, 0); _inScene->position(0, 0);
} }

View File

@ -22,11 +22,11 @@ e2d::Transition::~Transition()
{ {
SafeRelease(_outLayer); SafeRelease(_outLayer);
SafeRelease(_inLayer); SafeRelease(_inLayer);
GC::getInstance()->safeRelease(_outScene); GC::instance()->safeRelease(_outScene);
GC::getInstance()->safeRelease(_inScene); GC::instance()->safeRelease(_inScene);
} }
bool e2d::Transition::isDone() bool e2d::Transition::done()
{ {
return _end; return _end;
} }
@ -40,15 +40,15 @@ bool e2d::Transition::_init(Game * game, Scene * prev)
_outScene->retain(); _outScene->retain();
HRESULT hr = S_OK; HRESULT hr = S_OK;
auto renderer = game->getRenderer(); auto renderer = game->renderer();
if (_inScene) if (_inScene)
{ {
hr = renderer->getRenderTarget()->CreateLayer(&_inLayer); hr = renderer->renderTarget()->CreateLayer(&_inLayer);
} }
if (SUCCEEDED(hr) && _outScene) if (SUCCEEDED(hr) && _outScene)
{ {
hr = renderer->getRenderTarget()->CreateLayer(&_outLayer); hr = renderer->renderTarget()->CreateLayer(&_outLayer);
} }
if (FAILED(hr)) if (FAILED(hr))
@ -56,14 +56,14 @@ bool e2d::Transition::_init(Game * game, Scene * prev)
return false; return false;
} }
_windowSize = game->getWindow()->getSize(); _windowSize = game->window()->size();
_outLayerParam = _inLayerParam = D2D1::LayerParameters( _outLayerParam = _inLayerParam = D2D1::LayerParameters(
D2D1::InfiniteRect(), D2D1::InfiniteRect(),
nullptr, nullptr,
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
D2D1::Matrix3x2F::Identity(), D2D1::Matrix3x2F::Identity(),
1.f, 1.f,
renderer->getSolidColorBrush(), renderer->solidBrush(),
D2D1_LAYER_OPTIONS_NONE D2D1_LAYER_OPTIONS_NONE
); );
@ -85,11 +85,11 @@ void e2d::Transition::_update()
void e2d::Transition::_render(Game * game) void e2d::Transition::_render(Game * game)
{ {
auto renderTarget = game->getRenderer()->getRenderTarget(); auto renderTarget = game->renderer()->renderTarget();
if (_outScene) if (_outScene)
{ {
Point rootPos = _outScene->getPos(); Point rootPos = _outScene->position();
auto clipRect = D2D1::RectF( auto clipRect = D2D1::RectF(
std::max(rootPos.x, 0.f), std::max(rootPos.x, 0.f),
std::max(rootPos.y, 0.f), std::max(rootPos.y, 0.f),
@ -108,7 +108,7 @@ void e2d::Transition::_render(Game * game)
if (_inScene) if (_inScene)
{ {
Point rootPos = _inScene->getPos(); Point rootPos = _inScene->position();
auto clipRect = D2D1::RectF( auto clipRect = D2D1::RectF(
std::max(rootPos.x, 0.f), std::max(rootPos.x, 0.f),
std::max(rootPos.y, 0.f), std::max(rootPos.y, 0.f),

View File

@ -40,10 +40,10 @@ public:
virtual void stop(); virtual void stop();
// 获取动作名称 // 获取动作名称
virtual String getName() const; virtual const String& name() const;
// 设置动作名称 // 设置动作名称
virtual void setName( virtual void name(
const String& name const String& name
); );
@ -57,7 +57,7 @@ public:
virtual void reset(); virtual void reset();
// 获取该动作的执行目标 // 获取该动作的执行目标
virtual Node * getTarget(); virtual Node * target();
protected: protected:
E2D_DISABLE_COPY(Action); E2D_DISABLE_COPY(Action);
@ -716,26 +716,26 @@ public:
virtual ~Animation(); virtual ~Animation();
// 添加关键帧 // 添加关键帧
void add( Animation& add(
Image * frame /* 关键帧 */ Image * frame /* 关键帧 */
); );
// 添加多个关键帧 // 添加多个关键帧
void add( Animation& add(
const std::vector<Image*>& frames /* 关键帧列表 */ const std::vector<Image*>& frames /* 关键帧列表 */
); );
// 获取帧间隔
float getInterval() const;
// 获取关键帧
const std::vector<Image*>& getFrames() const;
// 设置每一帧的时间间隔 // 设置每一帧的时间间隔
void setInterval( Animation& interval(
float interval /* 帧间隔(秒) */ float interval /* 帧间隔(秒) */
); );
// »ñȡ֡¼ä¸ô
float interval() const;
// »ñÈ¡¹Ø¼üÖ¡
const std::vector<Image*>& frames() const;
// 获取帧动画的拷贝对象 // 获取帧动画的拷贝对象
Animation * clone() const; Animation * clone() const;
@ -765,10 +765,10 @@ public:
virtual ~Animate(); virtual ~Animate();
// 获取动画 // 获取动画
virtual Animation * getAnimation() const; Animation * animation() const;
// 设置动画 // 设置动画
virtual void setAnimation( void animation(
Animation * animation Animation * animation
); );

View File

@ -48,51 +48,51 @@ public:
); );
// 修改窗体大小 // 修改窗体大小
void setSize( Window& size(
int width, /* 窗体宽度 */ int width, /* 窗体宽度 */
int height /* 窗体高度 */ int height /* 窗体高度 */
); );
// 设置窗体标题 // 设置窗体标题
void setTitle( Window& title(
const String& title /* 窗体标题 */ const String& title /* 窗体标题 */
); );
// 设置窗体图标 // 设置窗体图标
void setIcon( Window& icon(
int iconID int iconID
); );
// 设置鼠标指针样式 // 设置鼠标指针样式
void setCursor( Window& cursor(
Cursor cursor Cursor c
); );
// 获取窗体标题 // 获取窗体标题
String getTitle() const; const String& title() const;
// 获取窗体宽度 // 获取窗体宽度
int getWidth() const; int width() const;
// 获取窗体高度 // 获取窗体高度
int getHeight() const; int height() const;
// 获取窗体大小 // 获取窗体大小
Size getSize() const; Size size() const;
// 获取窗口 DPI // 获取窗口 DPI
float getDpi() const; float dpi() const;
// 获取窗口句柄 // 获取窗口句柄
HWND getHWnd() const; HWND hWnd() const;
// 打开或隐藏控制台 // 打开或隐藏控制台
void setConsoleEnabled( Window& showConsole(
bool enabled bool enabled
); );
// 是否允许响应输入法 // 是否允许响应输入法
void setTypewritingEnabled( Window& typewritingEnabled(
bool enabled bool enabled
); );
@ -153,22 +153,22 @@ public:
); );
// 获得鼠标X轴坐标值 // 获得鼠标X轴坐标值
float getMouseX(); float mouseX();
// 获得鼠标Y轴坐标值 // 获得鼠标Y轴坐标值
float getMouseY(); float mouseY();
// 获得鼠标坐标值 // 获得鼠标坐标值
Point getMousePos(); Point mousePos();
// 获得鼠标X轴坐标增量 // 获得鼠标X轴坐标增量
float getMouseDeltaX(); float mouseDeltaX();
// 获得鼠标Y轴坐标增量 // 获得鼠标Y轴坐标增量
float getMouseDeltaY(); float mouseDeltaY();
// 获得鼠标Z轴鼠标滚轮坐标增量 // 获得鼠标Z轴鼠标滚轮坐标增量
float getMouseDeltaZ(); float mouseDeltaZ();
// 初始化输入设备 // 初始化输入设备
void initWithWindow( void initWithWindow(
@ -196,11 +196,11 @@ public:
~Renderer(); ~Renderer();
// 获取背景色 // 获取背景色
Color getBackgroundColor(); Color backgroundColor();
// 修改背景色 // 修改背景色
void setBackgroundColor( void backgroundColor(
Color color const Color& color
); );
// 显示或隐藏 FPS // 显示或隐藏 FPS
@ -210,31 +210,31 @@ public:
); );
// 获取文字渲染器 // 获取文字渲染器
TextRenderer * getTextRenderer() const { return _textRenderer; } TextRenderer * textRenderer() const { return _textRenderer; }
// 获取 ID2D1HwndRenderTarget 对象 // 获取 ID2D1HwndRenderTarget 对象
ID2D1HwndRenderTarget * getRenderTarget() const { return _renderTarget; } ID2D1HwndRenderTarget * renderTarget() const { return _renderTarget; }
// 获取 ID2D1SolidColorBrush 对象 // 获取 ID2D1SolidColorBrush 对象
ID2D1SolidColorBrush * getSolidColorBrush() const { return _solidBrush; } ID2D1SolidColorBrush * solidBrush() const { return _solidBrush; }
// 获取 ID2D1Factory 对象 // 获取 ID2D1Factory 对象
ID2D1Factory * getFactory() const { return _factory; } ID2D1Factory * factory() const { return _factory; }
// 获取 IWICImagingFactory 对象 // 获取 IWICImagingFactory 对象
IWICImagingFactory * getImagingFactory() const { return _imagingFactory; } IWICImagingFactory * imagingFactory() const { return _imagingFactory; }
// 获取 IDWriteFactory 对象 // 获取 IDWriteFactory 对象
IDWriteFactory * getWriteFactory() const { return _writeFactory; } IDWriteFactory * writeFactory() const { return _writeFactory; }
// 获取 Miter 样式的 ID2D1StrokeStyle // 获取 Miter 样式的 ID2D1StrokeStyle
ID2D1StrokeStyle * getMiterStrokeStyle(); ID2D1StrokeStyle * miterStrokeStyle();
// 获取 Bevel 样式的 ID2D1StrokeStyle // 获取 Bevel 样式的 ID2D1StrokeStyle
ID2D1StrokeStyle * getBevelStrokeStyle(); ID2D1StrokeStyle * bevelStrokeStyle();
// 获取 Round 样式的 ID2D1StrokeStyle // 获取 Round 样式的 ID2D1StrokeStyle
ID2D1StrokeStyle * getRoundStrokeStyle(); ID2D1StrokeStyle * roundStrokeStyle();
// 初始化渲染器 // 初始化渲染器
void initWithWindow( void initWithWindow(
@ -276,7 +276,7 @@ class Game
{ {
public: public:
// 获取 Game 实例 // 获取 Game 实例
static Game * getInstance(); static Game * instance();
// 初始化 // 初始化
void initWithWindow( void initWithWindow(
@ -284,13 +284,13 @@ public:
); );
// 获取窗体 // 获取窗体
Window * getWindow() const { return _window; } Window * window() const { return _window; }
// 获取输入设备 // 获取输入设备
Input * getInput() const { return _input; } Input * input() const { return _input; }
// 获取图形设备 // 获取图形设备
Renderer * getRenderer() const { return _renderer; } Renderer * renderer() const { return _renderer; }
// 启动游戏 // 启动游戏
void start(); void start();
@ -305,7 +305,7 @@ public:
void quit(); void quit();
// 游戏是否暂停 // 游戏是否暂停
bool isPaused(); bool paused();
// 场景入栈 // 场景入栈
void pushScene( void pushScene(
@ -331,13 +331,13 @@ public:
void clearAllScenes(); void clearAllScenes();
// 获取当前场景 // 获取当前场景
Scene * getCurrentScene(); Scene * currentScene();
// 获取场景栈 // 获取场景栈
const std::stack<Scene*>& getSceneStack(); const std::stack<Scene*>& sceneStack();
// 是否正在进行场景动画 // 是否正在进行场景动画
bool isTransitioning() const; bool transitioning() const;
// 更新场景内容 // 更新场景内容
void updateScene(); void updateScene();
@ -372,7 +372,7 @@ class GC
{ {
public: public:
// 获取 GC 实例 // 获取 GC 实例
static GC * getInstance(); static GC * instance();
// 自动释放 // 自动释放
void autorelease( void autorelease(

View File

@ -103,14 +103,6 @@ public:
bool operator== (const Rect& rect) const; bool operator== (const Rect& rect) const;
// 设置矩形
void setRect(
float x,
float y,
float width,
float height
);
// 判断点是否在矩形内 // 判断点是否在矩形内
bool containsPoint( bool containsPoint(
const Point& point const Point& point
@ -142,13 +134,7 @@ public:
size_t hash() const; size_t hash() const;
// 判断字符串是否为空 // 判断字符串是否为空
bool isEmpty() const; bool empty() const;
// 获取 Unicode 字符串
std::wstring getWString() const;
// 获取 ANSI 字符串
std::string getCString() const;
// 获取指定位置字符 // 获取指定位置字符
wchar_t at( wchar_t at(
@ -244,6 +230,8 @@ public:
// 类型转换操作符 // 类型转换操作符
E2D_OP_EXPLICIT operator const wchar_t* () const; E2D_OP_EXPLICIT operator const wchar_t* () const;
E2D_OP_EXPLICIT operator wchar_t* () const; E2D_OP_EXPLICIT operator wchar_t* () const;
E2D_OP_EXPLICIT operator std::wstring () const;
E2D_OP_EXPLICIT operator std::string () const;
// 比较运算符 // 比较运算符
bool operator== (const String &) const; bool operator== (const String &) const;
@ -519,10 +507,10 @@ public:
Time(); Time();
// 获取时间戳 // 获取时间戳
time_t getTimeStamp() const; time_t stamp() const;
// 是否是 // 是否是零点
bool isZero() const; bool zero() const;
Time operator + (Duration const &) const; Time operator + (Duration const &) const;
Time operator - (Duration const &) const; Time operator - (Duration const &) const;
@ -609,55 +597,55 @@ public:
virtual ~Collider(); virtual ~Collider();
// 设置碰撞体形状 // 设置碰撞体形状
void setShape( Collider& shape(
Shape shape Shape shape
); );
// 是否触发碰撞事件 // 是否触发碰撞事件
void setCollisionNotify( Collider& notify(
bool notify bool notify
); );
// 启用或关闭该碰撞体 // 启用或关闭该碰撞体
void setEnabled( Collider& enabled(
bool enabled bool enabled
); );
// 设置碰撞体的可见性 // 设置碰撞体的可见性
void setVisible( Collider& visible(
bool visible bool visible
); );
// 设置绘制颜色 // 设置绘制颜色
void setColor( Collider& color(
Color color Color color
); );
// 判断两碰撞体的交集关系 // 判断两碰撞体的交集关系
Relation getRelationWith( Relation relationWith(
Collider * pCollider Collider * pCollider
) const; ) const;
// 是否启用碰撞体 // 是否启用碰撞体
bool isEnabled() const; bool enabled() const;
// 是否可见 // 是否可见
bool isVisible() const; bool visible() const;
// 是否触发碰撞事件 // 是否触发碰撞事件
bool isCollisionNotify() const; bool notify() const;
// 获取绘制颜色 // 获取绘制颜色
Color getColor() const; Color color() const;
// 获取形状 // 获取形状
Shape getShape() const; Shape shape() const;
// 获取绑定节点 // 获取绑定节点
Node* getNode() const; Node* node() const;
// 获取 ID2D1Geometry* 对象 // 获取 ID2D1Geometry* 对象
ID2D1Geometry* getGeometry() const; ID2D1Geometry* geometry() const;
// 重新生成 // 重新生成
void recreate(); void recreate();
@ -709,7 +697,7 @@ public:
void release(); void release();
// 获取引用计数 // 获取引用计数
int getRefCount() const; int refCount() const;
protected: protected:
E2D_DISABLE_COPY(Ref); E2D_DISABLE_COPY(Ref);
@ -762,34 +750,34 @@ public:
); );
// 获取宽度 // 获取宽度
virtual float getWidth() const; float width() const;
// 获取高度 // 获取高度
virtual float getHeight() const; float height() const;
// 获取大小 // 获取大小
virtual Size getSize() const; const Size& size() const;
// 获取图片宽度 // 获取图片实际宽度
virtual float getSourceWidth() const; float realWidth() const;
// 获取图片高度 // 获取图片实际高度
virtual float getSourceHeight() const; float realHeight() const;
// 获取图片大小 // 获取图片实际大小
virtual Size getSourceSize() const; Size realSize() const;
// 获取裁剪位置 X 坐标 // 获取裁剪位置 X 坐标
virtual float getCropX() const; float cropX() const;
// 获取裁剪位置 Y 坐标 // 获取裁剪位置 Y 坐标
virtual float getCropY() const; float cropY() const;
// 获取裁剪位置 // 获取裁剪位置
virtual Point getCropPos() const; const Point& cropPosition() const;
// 获取 ID2D1Bitmap 对象 // 获取 ID2D1Bitmap 对象
ID2D1Bitmap * getBitmap(); ID2D1Bitmap * bitmap();
// 预加载图片资源 // 预加载图片资源
static bool preload( static bool preload(

View File

@ -44,11 +44,11 @@ public:
HRESULT Error HRESULT Error
); );
void SetFuncOnStreamEnd( void SetCallbackOnStreamEnd(
const Function& func const Function& func
); );
void SetFuncOnLoopEnd( void SetCallbackOnLoopEnd(
const Function& func const Function& func
); );

View File

@ -25,13 +25,13 @@ public:
); );
// 获取按键键值 // 获取按键键值
KeyCode getCode() const; KeyCode code() const;
// 获取按键次数 // 获取按键次数
int getCount() const; int count() const;
// 获取事件类型 // 获取事件类型
KeyEvent::Type getType() const; KeyEvent::Type type() const;
// VK 键值转换 // VK 键值转换
static KeyCode convertKeyCode( static KeyCode convertKeyCode(
@ -75,18 +75,18 @@ public:
); );
// 获取鼠标横坐标 // 获取鼠标横坐标
float getX() const; float positionX() const;
// 获取鼠标纵坐标 // 获取鼠标纵坐标
float getY() const; float positionY() const;
// 获取鼠标坐标 // 获取鼠标坐标
Point getPos() const; Point position() const;
// 获取事件类型 // 获取事件类型
MouseEvent::Type getType() const; MouseEvent::Type type() const;
float getWheelDelta() const; float wheelDelta() const;
// 鼠标左键是否按下 // 鼠标左键是否按下
bool isLButtonDown() const; bool isLButtonDown() const;
@ -126,10 +126,10 @@ public:
~Collision(); ~Collision();
// 获取发生碰撞节点 // 获取发生碰撞节点
Node* getNode() const; Node* node() const;
// 获取交集关系 // 获取交集关系
Collider::Relation getRelation() const; Collider::Relation relation() const;
protected: protected:
Node * _node; Node * _node;

View File

@ -16,15 +16,15 @@ class ActionManager
public: public:
// 获取动作管理器实例 // 获取动作管理器实例
static ActionManager * getInstance(); static ActionManager * instance();
// 获取所有名称相同的动作 // 获取所有名称相同的动作
std::vector<Action *> get( std::vector<Action*> actions(
const String& name const String& name
); );
// 获取所有动作 // 获取所有动作
const std::vector<Action*>& getAll(); const std::vector<Action*>& actions();
// 执行动作 // 执行动作
void start( void start(
@ -108,11 +108,11 @@ class CollisionManager
public: public:
// 获取碰撞体管理器实例 // 获取碰撞体管理器实例
static CollisionManager * getInstance(); static CollisionManager * instance();
// 打开或关闭碰撞监听 // 打开或关闭碰撞监听
// 默认:关闭 // 默认:关闭
void setCollisionEnabled( void enabled(
bool enabled bool enabled
); );

File diff suppressed because it is too large Load Diff

View File

@ -33,18 +33,18 @@ private:
static T __randomInt(T min, T max) static T __randomInt(T min, T max)
{ {
std::uniform_int_distribution<T> dist(min, max); std::uniform_int_distribution<T> dist(min, max);
return dist(Random::__getEngine()); return dist(Random::__engine());
} }
template<typename T> template<typename T>
static T __randomReal(T min, T max) static T __randomReal(T min, T max)
{ {
std::uniform_real_distribution<T> dist(min, max); std::uniform_real_distribution<T> dist(min, max);
return dist(Random::__getEngine()); return dist(Random::__engine());
} }
// 获取随机数产生器 // 获取随机数产生器
static std::default_random_engine &__getEngine(); static std::default_random_engine &__engine();
}; };
@ -95,25 +95,28 @@ public:
void close(); void close();
// 是否正在播放 // 是否正在播放
bool isPlaying() const; bool playing() const;
// 获取音量
float volume() const;
// 设置音量 // 设置音量
bool setVolume( bool volume(
float volume float volume /* 音量范围为 -224 ~ 2240 是静音1 是正常音量 */
); );
// 设置播放结束时的执行函数 // 设置播放结束回调函数
void setFuncOnEnd( void callbackOnEnd(
const Function& func const Function& func
); );
// 设置循环播放中每一次播放结束时的执行函数 // 设置循环播放中每一次播放结束时的回调函数
void setFuncOnLoopEnd( void callbackOnLoopEnd(
const Function& func const Function& func
); );
// 获取 IXAudio2SourceVoice 对象 // 获取 IXAudio2SourceVoice 对象
IXAudio2SourceVoice * getIXAudio2SourceVoice() const; IXAudio2SourceVoice * sourceVoice() const;
public: public:
class XAudio2Tool class XAudio2Tool
@ -123,13 +126,13 @@ public:
~XAudio2Tool(); ~XAudio2Tool();
static XAudio2Tool* getInstance(); static XAudio2Tool* instance();
// 获取 XAudio2 实例对象 // 获取 XAudio2 实例对象
IXAudio2 * getXAudio2(); IXAudio2 * xAudio2();
// 获取 MasteringVoice 实例对象 // 获取 MasteringVoice 实例对象
IXAudio2MasteringVoice* getMasteringVoice(); IXAudio2MasteringVoice* masteringVoice();
protected: protected:
IXAudio2 * _xAudio2; IXAudio2 * _xAudio2;
@ -155,6 +158,7 @@ protected:
protected: protected:
bool _opened; bool _opened;
bool _playing; bool _playing;
float _volume;
DWORD _dwSize; DWORD _dwSize;
CHAR* _resBuffer; CHAR* _resBuffer;
BYTE* _waveData; BYTE* _waveData;
@ -204,7 +208,7 @@ public:
); );
// 获取音乐播放状态 // 获取音乐播放状态
bool isPlaying( bool playing(
const String& filePath /* 音乐文件路径 */ const String& filePath /* 音乐文件路径 */
); );
@ -235,15 +239,15 @@ public:
); );
// 获取音乐播放状态 // 获取音乐播放状态
bool isPlaying( bool playing(
const Resource& res /* 音乐资源 */ const Resource& res /* 音乐资源 */
); ) const;
// 获取音量 // 获取音量
float getVolume(); float volume() const;
// 设置音量 // 设置音量
void setVolume( void volume(
float volume /* 音量范围为 -224 ~ 2240 是静音1 是正常音量 */ float volume /* 音量范围为 -224 ~ 2240 是静音1 是正常音量 */
); );
@ -296,7 +300,7 @@ public:
bool isRunning() const; bool isRunning() const;
// 获取任务名称 // 获取任务名称
String getName() const; String name() const;
protected: protected:
// 执行任务 // 执行任务
@ -322,7 +326,7 @@ class Timer
{ {
public: public:
// 获取定时器实例 // 获取定时器实例
static Timer * getInstance(); static Timer * instance();
// 添加任务 // 添加任务
void addTask( void addTask(
@ -385,46 +389,46 @@ public:
// 保存 int 类型的值 // 保存 int 类型的值
void saveInt( void saveInt(
int value /* 数据 */ int value /* 数据 */
); );
// 保存 float 类型的值 // 保存 float 类型的值
void saveDouble( void saveDouble(
float value /* 数据 */ float value /* 数据 */
); );
// 保存 bool 类型的值 // 保存 bool 类型的值
void saveBool( void saveBool(
bool value /* 数据 */ bool value /* 数据 */
); );
// 保存 字符串 类型的值 // 保存 字符串 类型的值
void saveString( void saveString(
const String& value /* 数据 */ const String& value /* 数据 */
); );
// 获取 int 类型的值 // 获取 int 类型的值
// (若不存在则返回 defaultValue 参数的值) // (若不存在则返回 defaultValue 参数的值)
int getInt( int toInt(
int defaultValue /* 默认值 */ int defaultValue /* 默认值 */
); );
// 获取 float 类型的值 // 获取 float 类型的值
// (若不存在则返回 defaultValue 参数的值) // (若不存在则返回 defaultValue 参数的值)
float getDouble( float toDouble(
float defaultValue /* 默认值 */ float defaultValue /* 默认值 */
); );
// 获取 bool 类型的值 // 获取 bool 类型的值
// (若不存在则返回 defaultValue 参数的值) // (若不存在则返回 defaultValue 参数的值)
bool getBool( bool toBool(
bool defaultValue /* 默认值 */ bool defaultValue /* 默认值 */
); );
// 获取 字符串 类型的值 // 获取 字符串 类型的值
// (若不存在则返回 defaultValue 参数的值) // (若不存在则返回 defaultValue 参数的值)
String getString( String toString(
const String& defaultValue /* 默认值 */ const String& defaultValue /* 默认值 */
); );
protected: protected:
@ -458,13 +462,13 @@ public:
bool isFolder() const; bool isFolder() const;
// 删除文件 // 删除文件
bool deleteFile(); bool del();
// 获取文件路径 // 获取文件路径
String getFilePath() const; const String& path() const;
// 获取文件扩展名 // 获取文件扩展名
String getExtension() const; String ext() const;
// 释放资源到临时文件目录 // 释放资源到临时文件目录
static File extract( static File extract(
@ -484,7 +488,7 @@ public:
); );
// 打开保存文件对话框 // 打开保存文件对话框
static String getSaveFilePath( static String openSaveDialog(
const String& title = L"保存到", /* 对话框标题 */ const String& title = L"保存到", /* 对话框标题 */
const String& defExt = L"" /* 默认扩展名 */ const String& defExt = L"" /* 默认扩展名 */
); );
@ -504,16 +508,16 @@ class Path
public: public:
// 获取数据的默认保存路径 // 获取数据的默认保存路径
static String getDataPath(); static const String& dataPath();
// 获取临时文件目录 // 获取临时文件目录
static String getTempPath(); static const String& tempPath();
// 获取 LocalAppData 目录 // 获取 LocalAppData 目录
static String getLocalAppDataPath(); static const String& localAppDataPath();
// 获取当前程序的运行路径 // 获取当前程序的运行路径
static String getCurrentFilePath(); static const String& currentFilePath();
}; };
} }

View File

@ -23,7 +23,7 @@ public:
virtual ~Transition(); virtual ~Transition();
// 场景过渡动画是否结束 // 场景过渡动画是否结束
bool isDone(); bool done();
protected: protected:
// 初始化场景过渡动画 // 初始化场景过渡动画