diff --git a/core/Action/Action.cpp b/core/Action/Action.cpp index 86e742fd..24238d82 100644 --- a/core/Action/Action.cpp +++ b/core/Action/Action.cpp @@ -7,12 +7,12 @@ e2d::Action::Action() , _initialized(false) , _target(nullptr) { - ActionManager::instance()->__add(this); + ActionManager::getInstance()->__add(this); } e2d::Action::~Action() { - ActionManager::instance()->__remove(this); + ActionManager::getInstance()->__remove(this); } bool e2d::Action::isRunning() @@ -35,17 +35,17 @@ void e2d::Action::stop() _done = true; } -const e2d::String& e2d::Action::name() const +e2d::String e2d::Action::getName() const { return _name; } -void e2d::Action::name(const String& name) +void e2d::Action::setName(const String& name) { _name = name; } -e2d::Node * e2d::Action::target() +e2d::Node * e2d::Action::getTarget() { return _target; } diff --git a/core/Action/Animate.cpp b/core/Action/Animate.cpp index 7e97629e..2c187440 100644 --- a/core/Action/Animate.cpp +++ b/core/Action/Animate.cpp @@ -11,22 +11,22 @@ e2d::Animate::Animate(Animation * animation) : _frameIndex(0) , _animation(nullptr) { - this->animation(animation); + this->setAnimation(animation); } e2d::Animate::~Animate() { - GC::instance()->safeRelease(_animation); + GC::getInstance()->safeRelease(_animation); } -e2d::Animation * e2d::Animate::animation() const +e2d::Animation * e2d::Animate::getAnimation() const { return _animation; } -void e2d::Animate::animation(Animation * animation) +void e2d::Animate::setAnimation(Animation * animation) { - if (animation && animation != _animation && !animation->frames().empty()) + if (animation && animation != _animation && !animation->getFrames().empty()) { if (_animation) _animation->release(); _animation = animation; @@ -41,7 +41,7 @@ void e2d::Animate::_init() auto target = dynamic_cast(_target); if (target && _animation) { - target->open(_animation->frames()[_frameIndex]); + target->open(_animation->getFrames()[_frameIndex]); ++_frameIndex; } } @@ -56,9 +56,9 @@ void e2d::Animate::_update() return; } - while ((Time::now() - _started).seconds() >= _animation->interval()) + while ((Time::now() - _started).seconds() >= _animation->getInterval()) { - auto& frames = _animation->frames(); + auto& frames = _animation->getFrames(); auto target = dynamic_cast(_target); if (target) @@ -66,7 +66,7 @@ void e2d::Animate::_update() target->open(frames[_frameIndex]); } - _started += Duration(_animation->interval()); + _started += Duration(_animation->getInterval()); ++_frameIndex; if (_frameIndex == frames.size()) diff --git a/core/Action/Animation.cpp b/core/Action/Animation.cpp index 4ed37917..42d0a933 100644 --- a/core/Action/Animation.cpp +++ b/core/Action/Animation.cpp @@ -26,17 +26,16 @@ e2d::Animation::~Animation() { for (const auto& frame : _frames) { - GC::instance()->safeRelease(frame); + GC::getInstance()->safeRelease(frame); } } -e2d::Animation& e2d::Animation::interval(float interval) +void e2d::Animation::setInterval(float interval) { _interval = std::max(interval, 0.f); - return *this; } -e2d::Animation& e2d::Animation::add(Image * frame) +void e2d::Animation::add(Image * frame) { WARN_IF(frame == nullptr, "Animation::add failed, frame is nullptr."); if (frame) @@ -44,24 +43,22 @@ e2d::Animation& e2d::Animation::add(Image * frame) _frames.push_back(frame); frame->retain(); } - return *this; } -e2d::Animation& e2d::Animation::add(const std::vector& frames) +void e2d::Animation::add(const std::vector& frames) { for (const auto &image : frames) { this->add(image); } - return *this; } -float e2d::Animation::interval() const +float e2d::Animation::getInterval() const { return _interval; } -const std::vector& e2d::Animation::frames() const +const std::vector& e2d::Animation::getFrames() const { return _frames; } @@ -81,7 +78,7 @@ e2d::Animation * e2d::Animation::clone() const e2d::Animation * e2d::Animation::reverse() const { - auto& oldFrames = this->frames(); + auto& oldFrames = this->getFrames(); std::vector frames(oldFrames.size()); if (!oldFrames.empty()) @@ -99,5 +96,5 @@ e2d::Animation * e2d::Animation::reverse() const } } - return new (e2d::autorelease) Animation(this->interval(), frames); + return new (e2d::autorelease) Animation(this->getInterval(), frames); } diff --git a/core/Action/JumpBy.cpp b/core/Action/JumpBy.cpp index 5aec96a7..523cfb9f 100644 --- a/core/Action/JumpBy.cpp +++ b/core/Action/JumpBy.cpp @@ -25,7 +25,7 @@ void e2d::JumpBy::_init() if (_target) { - _prevPos = _startPos = _target->position(); + _prevPos = _startPos = _target->getPos(); } } @@ -40,13 +40,13 @@ void e2d::JumpBy::_update() float y = _height * 4 * frac * (1 - frac); y += _deltaPos.y * _delta; - Point currentPos = _target->position(); + Point currentPos = _target->getPos(); Vector2 diff = currentPos - _prevPos; _startPos = diff + _startPos; Point newPos = _startPos + Vector2(x, y); - _target->position(newPos); + _target->setPos(newPos); _prevPos = newPos; } diff --git a/core/Action/Loop.cpp b/core/Action/Loop.cpp index 7c5c99c1..08892502 100644 --- a/core/Action/Loop.cpp +++ b/core/Action/Loop.cpp @@ -17,7 +17,7 @@ e2d::Loop::Loop(Action * action, int times /* = -1 */) e2d::Loop::~Loop() { - GC::instance()->safeRelease(_action); + GC::getInstance()->safeRelease(_action); } e2d::Loop * e2d::Loop::clone() const diff --git a/core/Action/MoveBy.cpp b/core/Action/MoveBy.cpp index 25dcd53b..d537b797 100644 --- a/core/Action/MoveBy.cpp +++ b/core/Action/MoveBy.cpp @@ -14,7 +14,7 @@ void e2d::MoveBy::_init() if (_target) { - _prevPos = _startPos = _target->position(); + _prevPos = _startPos = _target->getPos(); } } @@ -24,12 +24,12 @@ void e2d::MoveBy::_update() if (_target) { - Point currentPos = _target->position(); + Point currentPos = _target->getPos(); Vector2 diff = currentPos - _prevPos; _startPos = _startPos + diff; Point newPos = _startPos + (_deltaPos * _delta); - _target->position(newPos); + _target->setPos(newPos); _prevPos = newPos; } diff --git a/core/Action/OpacityBy.cpp b/core/Action/OpacityBy.cpp index 0a8b2eb3..421e0c55 100644 --- a/core/Action/OpacityBy.cpp +++ b/core/Action/OpacityBy.cpp @@ -14,7 +14,7 @@ void e2d::OpacityBy::_init() if (_target) { - _startVal = _target->opacity(); + _startVal = _target->getOpacity(); } } @@ -24,7 +24,7 @@ void e2d::OpacityBy::_update() if (_target) { - _target->opacity(_startVal + _deltaVal * _delta); + _target->setOpacity(_startVal + _deltaVal * _delta); } } diff --git a/core/Action/RotateBy.cpp b/core/Action/RotateBy.cpp index f58a6d8f..ad0e5961 100644 --- a/core/Action/RotateBy.cpp +++ b/core/Action/RotateBy.cpp @@ -14,7 +14,7 @@ void e2d::RotateBy::_init() if (_target) { - _startVal = _target->rotation(); + _startVal = _target->getRotation(); } } @@ -24,7 +24,7 @@ void e2d::RotateBy::_update() if (_target) { - _target->rotation(_startVal + _deltaVal * _delta); + _target->setRotation(_startVal + _deltaVal * _delta); } } diff --git a/core/Action/ScaleBy.cpp b/core/Action/ScaleBy.cpp index 31f82ef2..11e4673b 100644 --- a/core/Action/ScaleBy.cpp +++ b/core/Action/ScaleBy.cpp @@ -22,8 +22,8 @@ void e2d::ScaleBy::_init() if (_target) { - _startScaleX = _target->scaleX(); - _startScaleY = _target->scaleY(); + _startScaleX = _target->getScaleX(); + _startScaleY = _target->getScaleY(); } } @@ -33,7 +33,7 @@ void e2d::ScaleBy::_update() if (_target) { - _target->scale(_startScaleX + _deltaX * _delta, _startScaleY + _deltaY * _delta); + _target->setScale(_startScaleX + _deltaX * _delta, _startScaleY + _deltaY * _delta); } } diff --git a/core/Action/Sequence.cpp b/core/Action/Sequence.cpp index a8ab5290..56408045 100644 --- a/core/Action/Sequence.cpp +++ b/core/Action/Sequence.cpp @@ -15,7 +15,7 @@ e2d::Sequence::~Sequence() { for (const auto& action : _actions) { - GC::instance()->safeRelease(action); + GC::getInstance()->safeRelease(action); } } diff --git a/core/Action/Spawn.cpp b/core/Action/Spawn.cpp index 02db0938..89835179 100644 --- a/core/Action/Spawn.cpp +++ b/core/Action/Spawn.cpp @@ -13,7 +13,7 @@ e2d::Spawn::~Spawn() { for (const auto& action : _actions) { - GC::instance()->safeRelease(action); + GC::getInstance()->safeRelease(action); } } diff --git a/core/Base/GC.cpp b/core/Base/GC.cpp index 1b17e38f..e3721700 100644 --- a/core/Base/GC.cpp +++ b/core/Base/GC.cpp @@ -11,7 +11,7 @@ void * operator new(size_t size, e2d::autorelease_t const &) E2D_NOEXCEPT void* p = ::operator new(size, std::nothrow); if (p) { - GC::instance()->autorelease(static_cast(p)); + GC::getInstance()->autorelease(static_cast(p)); } return p; } @@ -47,7 +47,7 @@ void e2d::GC::flush() _notifyed = false; for (auto iter = _pool.begin(); iter != _pool.end();) { - if ((*iter)->refCount() <= 0) + if ((*iter)->getRefCount() <= 0) { delete (*iter); iter = _pool.erase(iter); @@ -63,9 +63,9 @@ void e2d::GC::clear() { _cleanup = true; - Game::instance()->clearAllScenes(); - Timer::instance()->clearAllTasks(); - ActionManager::instance()->clearAll(); + Game::getInstance()->clearAllScenes(); + Timer::getInstance()->clearAllTasks(); + ActionManager::getInstance()->clearAll(); for (const auto& ref : _pool) { @@ -75,7 +75,7 @@ void e2d::GC::clear() _cleanup = false; } -e2d::GC * e2d::GC::instance() +e2d::GC * e2d::GC::getInstance() { static GC _instance; return &_instance; diff --git a/core/Base/Game.cpp b/core/Base/Game.cpp index 90aaa461..b26df78e 100644 --- a/core/Base/Game.cpp +++ b/core/Base/Game.cpp @@ -21,8 +21,8 @@ e2d::Game::Game() _input = new (std::nothrow) Input; _renderer = new (std::nothrow) Renderer; - _timer = Timer::instance(); - _actionManager = ActionManager::instance(); + _timer = Timer::getInstance(); + _actionManager = ActionManager::getInstance(); } e2d::Game::~Game() @@ -36,7 +36,7 @@ e2d::Game::~Game() CoUninitialize(); } -e2d::Game * e2d::Game::instance() +e2d::Game * e2d::Game::getInstance() { static Game instance; return &instance; @@ -55,7 +55,7 @@ void e2d::Game::start() const int minInterval = 5; Time last = Time::now(); - HWND hWnd = _window->hWnd(); + HWND hWnd = _window->getHWnd(); ::ShowWindow(hWnd, SW_SHOWNORMAL); ::UpdateWindow(hWnd); @@ -81,7 +81,7 @@ void e2d::Game::start() drawScene(); _window->poll(); - GC::instance()->flush(); + GC::getInstance()->flush(); } else { @@ -112,7 +112,7 @@ void e2d::Game::resume() _paused = false; } -bool e2d::Game::paused() +bool e2d::Game::isPaused() { return _paused; } @@ -218,17 +218,17 @@ void e2d::Game::clearAllScenes() } } -e2d::Scene * e2d::Game::currentScene() +e2d::Scene * e2d::Game::getCurrentScene() { return _currScene; } -const std::stack& e2d::Game::sceneStack() +const std::stack& e2d::Game::getSceneStack() { return _scenes; } -bool e2d::Game::transitioning() const +bool e2d::Game::isTransitioning() const { return _transition != nullptr; } @@ -239,7 +239,7 @@ void e2d::Game::updateScene() { _transition->_update(); - if (_transition->done()) + if (_transition->isDone()) { _transition->release(); _transition = nullptr; diff --git a/core/Base/Input.cpp b/core/Base/Input.cpp index b0d613f9..f02ab4b0 100644 --- a/core/Base/Input.cpp +++ b/core/Base/Input.cpp @@ -40,7 +40,7 @@ e2d::Input::~Input() void e2d::Input::initWithWindow(Window * window) { - HWND hwnd = window->hWnd(); + HWND hwnd = window->getHWnd(); // 初始化键盘设备 ThrowIfFailed( @@ -118,39 +118,39 @@ bool e2d::Input::isDown(MouseCode code) return false; } -float e2d::Input::mouseX() +float e2d::Input::getMouseX() { - return mousePos().x; + return getMousePos().x; } -float e2d::Input::mouseY() +float e2d::Input::getMouseY() { - return mousePos().y; + return getMousePos().y; } -e2d::Point e2d::Input::mousePos() +e2d::Point e2d::Input::getMousePos() { - auto window = Game::instance()->window(); + auto window = Game::getInstance()->getWindow(); POINT mousePos; ::GetCursorPos(&mousePos); - ::ScreenToClient(window->hWnd(), &mousePos); + ::ScreenToClient(window->getHWnd(), &mousePos); - float dpi = window->dpi(); + float dpi = window->getDpi(); return Point(mousePos.x * 96.f / dpi, mousePos.y * 96.f / dpi); } -float e2d::Input::mouseDeltaX() +float e2d::Input::getMouseDeltaX() { return (float)_mouseState.lX; } -float e2d::Input::mouseDeltaY() +float e2d::Input::getMouseDeltaY() { return (float)_mouseState.lY; } -float e2d::Input::mouseDeltaZ() +float e2d::Input::getMouseDeltaZ() { return (float)_mouseState.lZ; } diff --git a/core/Base/Renderer.cpp b/core/Base/Renderer.cpp index b64e6f05..0eedb7cd 100644 --- a/core/Base/Renderer.cpp +++ b/core/Base/Renderer.cpp @@ -68,7 +68,7 @@ e2d::Renderer::~Renderer() void e2d::Renderer::initWithWindow(Window * window) { - HWND hWnd = window->hWnd(); + HWND hWnd = window->getHWnd(); RECT rc; GetClientRect(hWnd, &rc); @@ -205,12 +205,12 @@ void e2d::Renderer::endDraw() } } -e2d::Color e2d::Renderer::backgroundColor() +e2d::Color e2d::Renderer::getBackgroundColor() { - return _clearColor; + return Color(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a); } -void e2d::Renderer::backgroundColor(const Color& color) +void e2d::Renderer::setBackgroundColor(Color color) { _clearColor = (D2D1_COLOR_F)color; } @@ -220,7 +220,7 @@ void e2d::Renderer::showFps(bool show) _showFps = show; } -ID2D1StrokeStyle * e2d::Renderer::miterStrokeStyle() +ID2D1StrokeStyle * e2d::Renderer::getMiterStrokeStyle() { if (!_miterStrokeStyle) { @@ -243,7 +243,7 @@ ID2D1StrokeStyle * e2d::Renderer::miterStrokeStyle() return _miterStrokeStyle; } -ID2D1StrokeStyle * e2d::Renderer::bevelStrokeStyle() +ID2D1StrokeStyle * e2d::Renderer::getBevelStrokeStyle() { if (!_bevelStrokeStyle) { @@ -266,7 +266,7 @@ ID2D1StrokeStyle * e2d::Renderer::bevelStrokeStyle() return _bevelStrokeStyle; } -ID2D1StrokeStyle * e2d::Renderer::roundStrokeStyle() +ID2D1StrokeStyle * e2d::Renderer::getRoundStrokeStyle() { if (!_roundStrokeStyle) { diff --git a/core/Base/Window.cpp b/core/Base/Window.cpp index 5a39166d..25a37e87 100644 --- a/core/Base/Window.cpp +++ b/core/Base/Window.cpp @@ -71,7 +71,7 @@ e2d::Window::Window(const String & title, int width, int height, int iconID) if (_hWnd) { // 禁用输入法 - typewritingEnabled(false); + setTypewritingEnabled(false); // 禁用控制台关闭按钮 HWND consoleHWnd = ::GetConsoleWindow(); if (consoleHWnd) @@ -102,7 +102,7 @@ e2d::Window::~Window() bool e2d::Window::createMutex(const String & mutex) { - if (mutex.empty()) + if (mutex.isEmpty()) return false; HANDLE hMutex = ::CreateMutex(nullptr, TRUE, LPCWSTR(L"Easy2DApp-" + mutex)); @@ -117,7 +117,7 @@ bool e2d::Window::createMutex(const String & mutex) // 关闭进程互斥体 ::CloseHandle(hMutex); // 打开游戏窗口 - if (!this->_title.empty()) + if (!this->_title.isEmpty()) { // 获取窗口句柄 HWND hProgramWnd = ::FindWindow(REGISTER_CLASS, (LPCTSTR)_title); @@ -167,40 +167,40 @@ void e2d::Window::poll() } } -int e2d::Window::width() const +int e2d::Window::getWidth() const { return _width; } -int e2d::Window::height() const +int e2d::Window::getHeight() const { return _height; } -e2d::Size e2d::Window::size() const +e2d::Size e2d::Window::getSize() const { return Size(float(_width), float(_height)); } -float e2d::Window::dpi() const +float e2d::Window::getDpi() const { return _dpi; } -const e2d::String& e2d::Window::title() const +e2d::String e2d::Window::getTitle() const { return _title; } -HWND e2d::Window::hWnd() const +HWND e2d::Window::getHWnd() const { return _hWnd; } -e2d::Window& e2d::Window::size(int width, int height) +void e2d::Window::setSize(int width, int height) { if (_width == width && _height == height) - return *this; + return; _width = width; _height = height; @@ -217,20 +217,18 @@ e2d::Window& e2d::Window::size(int width, int height) TRUE ); } - return *this; } -e2d::Window& e2d::Window::title(const String& title) +void e2d::Window::setTitle(const String& title) { _title = title; if (_hWnd) { ::SetWindowText(_hWnd, (LPCWSTR)title); } - return *this; } -e2d::Window& e2d::Window::icon(int iconID) +void e2d::Window::setIcon(int iconID) { this->_iconID = iconID; if (_hWnd) @@ -240,10 +238,9 @@ e2d::Window& e2d::Window::icon(int iconID) ::SendMessage(_hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon); ::SendMessage(_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); } - return *this; } -e2d::Window& e2d::Window::cursor(Cursor cursor) +void e2d::Window::setCursor(Cursor cursor) { LPCWSTR pCursorName = nullptr; switch (cursor) @@ -274,10 +271,9 @@ e2d::Window& e2d::Window::cursor(Cursor cursor) HCURSOR hCursor = ::LoadCursor(nullptr, pCursorName); ::SetCursor(hCursor); - return *this; } -e2d::Window& e2d::Window::showConsole(bool enabled) +void e2d::Window::setConsoleEnabled(bool enabled) { // 查找已存在的控制台句柄 HWND hwnd = ::GetConsoleWindow(); @@ -312,10 +308,9 @@ e2d::Window& e2d::Window::showConsole(bool enabled) ::ShowWindow(hwnd, SW_HIDE); } } - return *this; } -e2d::Window& e2d::Window::typewritingEnabled(bool enabled) +void e2d::Window::setTypewritingEnabled(bool enabled) { static HIMC hImc = nullptr; @@ -334,7 +329,6 @@ e2d::Window& e2d::Window::typewritingEnabled(bool enabled) hImc = ::ImmAssociateContext(_hWnd, nullptr); } } - return *this; } bool e2d::Window::popup(const String & text, const String & title, Popup style, bool hasCancel) @@ -360,9 +354,9 @@ bool e2d::Window::popup(const String & text, const String & title, Popup style, type |= MB_OKCANCEL; } - Game::instance()->pause(); + Game::getInstance()->pause(); int ret = ::MessageBox(_hWnd, (LPCWSTR)text, (LPCWSTR)title, type); - Game::instance()->resume(); + Game::getInstance()->resume(); return ret == IDOK; } @@ -409,13 +403,13 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_MOUSEMOVE: case WM_MOUSEWHEEL: { - auto game = Game::instance(); - if (game->transitioning()) + auto game = Game::getInstance(); + if (game->isTransitioning()) break; - if (game->currentScene()) + if (game->getCurrentScene()) { - game->currentScene()->dispatch(MouseEvent(hWnd, uMsg, wParam, lParam, window->_dpi), false); + game->getCurrentScene()->dispatch(MouseEvent(hWnd, uMsg, wParam, lParam, window->_dpi), false); } } result = 0; @@ -426,13 +420,13 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_KEYDOWN: case WM_KEYUP: { - auto game = Game::instance(); - if (game->transitioning()) + auto game = Game::getInstance(); + if (game->isTransitioning()) break; - if (game->currentScene()) + if (game->getCurrentScene()) { - game->currentScene()->dispatch(KeyEvent(hWnd, uMsg, wParam, lParam), false); + game->getCurrentScene()->dispatch(KeyEvent(hWnd, uMsg, wParam, lParam), false); } } result = 0; @@ -454,8 +448,8 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) // 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染 // 目标适当。它可能会调用失败,但是这里可以忽略有可能的 // 错误,因为这个错误将在下一次调用 EndDraw 时产生 - auto renderer = Game::instance()->renderer(); - auto pRT = renderer->renderTarget(); + auto renderer = Game::getInstance()->getRenderer(); + auto pRT = renderer->getRenderTarget(); if (pRT) { pRT->Resize(D2D1::SizeU(width, height)); @@ -483,7 +477,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) // 重绘窗口 case WM_PAINT: { - Game::instance()->drawScene(); + Game::getInstance()->drawScene(); ValidateRect(hWnd, nullptr); } result = 0; @@ -493,8 +487,8 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) // 窗口关闭消息 case WM_CLOSE: { - auto game = Game::instance(); - auto currScene = game->currentScene(); + auto game = Game::getInstance(); + auto currScene = game->getCurrentScene(); if (!currScene || currScene->onCloseWindow()) { game->quit(); diff --git a/core/Common/Collider.cpp b/core/Common/Collider.cpp index 6c1af5e3..f9253b52 100644 --- a/core/Common/Collider.cpp +++ b/core/Common/Collider.cpp @@ -18,85 +18,80 @@ e2d::Collider::~Collider() SafeRelease(_geometry); } -e2d::Color e2d::Collider::color() const +e2d::Color e2d::Collider::getColor() const { return _color; } -e2d::Collider::Shape e2d::Collider::shape() const +e2d::Collider::Shape e2d::Collider::getShape() const { return _shape; } -e2d::Node * e2d::Collider::node() const +e2d::Node * e2d::Collider::getNode() const { return _parentNode; } -ID2D1Geometry * e2d::Collider::geometry() const +ID2D1Geometry * e2d::Collider::getGeometry() const { return _geometry; } -e2d::Collider& e2d::Collider::shape(Shape shape) +void e2d::Collider::setShape(Shape shape) { if (_shape == shape) - return *this; + return; _shape = shape; if (shape == Shape::None) { SafeRelease(_geometry); - CollisionManager::instance()->__removeCollider(this); + CollisionManager::getInstance()->__removeCollider(this); } else { this->recreate(); - CollisionManager::instance()->__addCollider(this); + CollisionManager::getInstance()->__addCollider(this); } - return *this; } -e2d::Collider& e2d::Collider::notify(bool notify) +void e2d::Collider::setCollisionNotify(bool notify) { _notify = notify; - return *this; } -e2d::Collider& e2d::Collider::enabled(bool enabled) +void e2d::Collider::setEnabled(bool enabled) { _enabled = enabled; - return *this; } -e2d::Collider& e2d::Collider::visible(bool visible) +void e2d::Collider::setVisible(bool visible) { _visible = visible; - return *this; } -e2d::Collider& e2d::Collider::color(Color color) +void e2d::Collider::setColor(Color color) { _color = color; - return *this; } void e2d::Collider::render() { if (_geometry && _enabled && _visible) { - auto renderer = Game::instance()->renderer(); + auto renderer = Game::getInstance()->getRenderer(); // 获取纯色画刷 - ID2D1SolidColorBrush * brush = renderer->solidBrush(); + ID2D1SolidColorBrush * brush = renderer->getSolidColorBrush(); // 设置画刷颜色和透明度 brush->SetColor((D2D1_COLOR_F)_color); brush->SetOpacity(1.f); // 绘制几何碰撞体 - renderer->renderTarget()->DrawGeometry(_geometry, brush, 1.5f); + renderer->getRenderTarget()->DrawGeometry(_geometry, brush, 1.5f); } } -e2d::Collider::Relation e2d::Collider::relationWith(Collider * collider) const +e2d::Collider::Relation e2d::Collider::getRelationWith(Collider * collider) const { if (_geometry && collider->_geometry) { @@ -115,17 +110,17 @@ e2d::Collider::Relation e2d::Collider::relationWith(Collider * collider) const return Relation::Unknown; } -bool e2d::Collider::enabled() const +bool e2d::Collider::isEnabled() const { return _enabled; } -bool e2d::Collider::visible() const +bool e2d::Collider::isVisible() const { return _visible; } -bool e2d::Collider::notify() const +bool e2d::Collider::isCollisionNotify() const { return _notify; } @@ -136,7 +131,7 @@ void e2d::Collider::recreate() return; SafeRelease(_geometry); - auto factory = Game::instance()->renderer()->factory(); + auto factory = Game::getInstance()->getRenderer()->getFactory(); switch (_shape) { @@ -144,7 +139,7 @@ void e2d::Collider::recreate() { ID2D1RectangleGeometry* rectangle = nullptr; factory->CreateRectangleGeometry( - D2D1::RectF(0, 0, _parentNode->realWidth(), _parentNode->realHeight()), + D2D1::RectF(0, 0, _parentNode->getRealWidth(), _parentNode->getRealHeight()), &rectangle ); _geometry = rectangle; @@ -153,14 +148,14 @@ void e2d::Collider::recreate() case Shape::Circle: { - float minSide = std::min(_parentNode->realWidth(), _parentNode->realHeight()); + float minSide = std::min(_parentNode->getRealWidth(), _parentNode->getRealHeight()); ID2D1EllipseGeometry* circle = nullptr; factory->CreateEllipseGeometry( D2D1::Ellipse( D2D1::Point2F( - _parentNode->realWidth() / 2, - _parentNode->realHeight() / 2 + _parentNode->getRealWidth() / 2, + _parentNode->getRealHeight() / 2 ), minSide / 2, minSide / 2 @@ -173,8 +168,8 @@ void e2d::Collider::recreate() case Shape::Ellipse: { - float halfWidth = _parentNode->width() / 2, - halfHeight = _parentNode->height() / 2; + float halfWidth = _parentNode->getWidth() / 2, + halfHeight = _parentNode->getHeight() / 2; ID2D1EllipseGeometry* ellipse = nullptr; factory->CreateEllipseGeometry( diff --git a/core/Common/Image.cpp b/core/Common/Image.cpp index 1006e809..df9d2cae 100644 --- a/core/Common/Image.cpp +++ b/core/Common/Image.cpp @@ -58,9 +58,9 @@ bool e2d::Image::open(const Resource& res) bool e2d::Image::open(const String & fileName) { - WARN_IF(fileName.empty(), "Image open failed! Invalid file name."); + WARN_IF(fileName.isEmpty(), "Image open failed! Invalid file name."); - if (fileName.empty()) + if (fileName.isEmpty()) return false; if (!Image::preload(fileName)) @@ -77,29 +77,29 @@ void e2d::Image::crop(const Rect& cropRect) { if (_bitmap) { - _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->realHeight()); - _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->realHeight() - cropRect.origin.y); + _cropRect.origin.x = std::min(std::max(cropRect.origin.x, 0.f), this->getSourceWidth()); + _cropRect.origin.y = std::min(std::max(cropRect.origin.y, 0.f), this->getSourceHeight()); + _cropRect.size.width = std::min(std::max(cropRect.size.width, 0.f), this->getSourceWidth() - cropRect.origin.x); + _cropRect.size.height = std::min(std::max(cropRect.size.height, 0.f), this->getSourceHeight() - cropRect.origin.y); } } -float e2d::Image::width() const +float e2d::Image::getWidth() const { return _cropRect.size.width; } -float e2d::Image::height() const +float e2d::Image::getHeight() const { return _cropRect.size.height; } -const e2d::Size& e2d::Image::size() const +e2d::Size e2d::Image::getSize() const { return _cropRect.size; } -float e2d::Image::realWidth() const +float e2d::Image::getSourceWidth() const { if (_bitmap) { @@ -111,7 +111,7 @@ float e2d::Image::realWidth() const } } -float e2d::Image::realHeight() const +float e2d::Image::getSourceHeight() const { if (_bitmap) { @@ -123,11 +123,11 @@ float e2d::Image::realHeight() const } } -e2d::Size e2d::Image::realSize() const +e2d::Size e2d::Image::getSourceSize() const { if (_bitmap) { - return Size(realWidth(), realHeight()); + return Size(getSourceWidth(), getSourceHeight()); } else { @@ -135,17 +135,17 @@ e2d::Size e2d::Image::realSize() const } } -float e2d::Image::cropX() const +float e2d::Image::getCropX() const { return _cropRect.origin.x; } -float e2d::Image::cropY() const +float e2d::Image::getCropY() const { return _cropRect.origin.y; } -const e2d::Point& e2d::Image::cropPosition() const +e2d::Point e2d::Image::getCropPos() const { return _cropRect.origin; } @@ -157,9 +157,9 @@ bool e2d::Image::preload(const Resource& res) return true; } - Renderer* renderer = Game::instance()->renderer(); - ID2D1HwndRenderTarget* pRenderTarget = renderer->renderTarget(); - IWICImagingFactory *pImagingFactory = renderer->imagingFactory(); + Renderer* renderer = Game::getInstance()->getRenderer(); + ID2D1HwndRenderTarget* pRenderTarget = renderer->getRenderTarget(); + IWICImagingFactory *pImagingFactory = renderer->getImagingFactory(); IWICBitmapDecoder *pDecoder = nullptr; IWICBitmapFrameDecode *pSource = nullptr; IWICStream *pStream = nullptr; @@ -279,17 +279,17 @@ bool e2d::Image::preload(const Resource& res) bool e2d::Image::preload(const String & fileName) { - String actualFilePath = File(fileName).path(); - if (actualFilePath.empty()) + String actualFilePath = File(fileName).getFilePath(); + if (actualFilePath.isEmpty()) return false; size_t hash = actualFilePath.hash(); if (_bitmapCache.find(hash) != _bitmapCache.end()) return true; - Renderer* renderer = Game::instance()->renderer(); - ID2D1HwndRenderTarget* pRenderTarget = renderer->renderTarget(); - IWICImagingFactory *pImagingFactory = renderer->imagingFactory(); + Renderer* renderer = Game::getInstance()->getRenderer(); + ID2D1HwndRenderTarget* pRenderTarget = renderer->getRenderTarget(); + IWICImagingFactory *pImagingFactory = renderer->getImagingFactory(); IWICBitmapDecoder *pDecoder = nullptr; IWICBitmapFrameDecode *pSource = nullptr; IWICStream *pStream = nullptr; @@ -377,7 +377,7 @@ void e2d::Image::_setBitmap(ID2D1Bitmap * bitmap) } } -ID2D1Bitmap * e2d::Image::bitmap() +ID2D1Bitmap * e2d::Image::getBitmap() { return _bitmap; } diff --git a/core/Common/Rect.cpp b/core/Common/Rect.cpp index cbb3bca5..23d8022f 100644 --- a/core/Common/Rect.cpp +++ b/core/Common/Rect.cpp @@ -1,33 +1,28 @@ #include "..\e2dcommon.h" 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) - : origin(x, y) - , size(width, height) { + setRect(x, y, width, height); } 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) - : 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) { - origin = other.origin; - size = other.size; + setRect(other.origin.x, other.origin.y, other.size.width, other.size.height); return *this; } @@ -36,6 +31,15 @@ bool e2d::Rect::operator==(const Rect & rect) const 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 { if (point.x >= origin.x && point.x <= (origin.y + size.height) diff --git a/core/Common/Ref.cpp b/core/Common/Ref.cpp index 67028a02..fcd18fe5 100644 --- a/core/Common/Ref.cpp +++ b/core/Common/Ref.cpp @@ -19,7 +19,7 @@ void e2d::Ref::release() _refCount--; } -int e2d::Ref::refCount() const +int e2d::Ref::getRefCount() const { return _refCount; } diff --git a/core/Common/String.cpp b/core/Common/String.cpp index 8016efb9..a85c0b58 100644 --- a/core/Common/String.cpp +++ b/core/Common/String.cpp @@ -332,18 +332,7 @@ e2d::String::operator wchar_t*() const return const_cast(_str.c_str()); } -e2d::String::operator std::wstring() const -{ - return _str; -} - -e2d::String::operator std::string() const -{ - std::string str = static_cast(_bstr_t(_str.c_str())); - return std::move(str); -} - -bool e2d::String::empty() const +bool e2d::String::isEmpty() const { return _str.empty(); } @@ -359,6 +348,17 @@ size_t e2d::String::hash() const return hash(_str); } +std::wstring e2d::String::getWString() const +{ + return _str; +} + +std::string e2d::String::getCString() const +{ + std::string str = static_cast(_bstr_t(_str.c_str())); + return std::move(str); +} + wchar_t e2d::String::at(int index) const { return _str[size_t(index)]; diff --git a/core/Common/Time.cpp b/core/Common/Time.cpp index 5e145528..a709e5ad 100644 --- a/core/Common/Time.cpp +++ b/core/Common/Time.cpp @@ -7,13 +7,13 @@ e2d::Time::Time() { } -time_t e2d::Time::stamp() const +time_t e2d::Time::getTimeStamp() const { auto& duration = time_point_cast(_timePoint).time_since_epoch(); return static_cast(duration.count()); } -bool e2d::Time::zero() const +bool e2d::Time::isZero() const { return _timePoint.time_since_epoch().count() == 0LL; } diff --git a/core/Custom/TextRenderer.cpp b/core/Custom/TextRenderer.cpp index 196494d9..4a1c9ed0 100644 --- a/core/Custom/TextRenderer.cpp +++ b/core/Custom/TextRenderer.cpp @@ -59,18 +59,18 @@ STDMETHODIMP_(void) TextRenderer::SetTextStyle( sOutlineColor_ = outlineColor; fOutlineWidth = 2 * outlineWidth; - auto pRenderer = Game::instance()->renderer(); + auto pRenderer = Game::getInstance()->getRenderer(); switch (outlineJoin) { case D2D1_LINE_JOIN_MITER: - pCurrStrokeStyle_ = pRenderer->miterStrokeStyle(); + pCurrStrokeStyle_ = pRenderer->getMiterStrokeStyle(); break; case D2D1_LINE_JOIN_BEVEL: - pCurrStrokeStyle_ = pRenderer->bevelStrokeStyle(); + pCurrStrokeStyle_ = pRenderer->getBevelStrokeStyle(); break; case D2D1_LINE_JOIN_ROUND: - pCurrStrokeStyle_ = pRenderer->roundStrokeStyle(); + pCurrStrokeStyle_ = pRenderer->getRoundStrokeStyle(); break; default: pCurrStrokeStyle_ = nullptr; diff --git a/core/Custom/VoiceCallback.cpp b/core/Custom/VoiceCallback.cpp index dc00539a..c5ececc8 100644 --- a/core/Custom/VoiceCallback.cpp +++ b/core/Custom/VoiceCallback.cpp @@ -65,12 +65,12 @@ void e2d::VoiceCallback::OnVoiceError(void * pBufferContext, HRESULT Error) { } -void e2d::VoiceCallback::SetCallbackOnStreamEnd(const Function & func) +void e2d::VoiceCallback::SetFuncOnStreamEnd(const Function & func) { _streamEndFunc = func; } -void e2d::VoiceCallback::SetCallbackOnLoopEnd(const Function & func) +void e2d::VoiceCallback::SetFuncOnLoopEnd(const Function & func) { _loopEndFunc = func; } \ No newline at end of file diff --git a/core/Event/Collision.cpp b/core/Event/Collision.cpp index 1cb06e13..2d4dd6ed 100644 --- a/core/Event/Collision.cpp +++ b/core/Event/Collision.cpp @@ -16,12 +16,12 @@ e2d::Collision::~Collision() { } -e2d::Node * e2d::Collision::node() const +e2d::Node * e2d::Collision::getNode() const { return _node; } -e2d::Collider::Relation e2d::Collision::relation() const +e2d::Collider::Relation e2d::Collision::getRelation() const { return _relation; } diff --git a/core/Event/KeyEvent.cpp b/core/Event/KeyEvent.cpp index df9b57df..da44f263 100644 --- a/core/Event/KeyEvent.cpp +++ b/core/Event/KeyEvent.cpp @@ -8,17 +8,17 @@ e2d::KeyEvent::KeyEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { } -e2d::KeyCode e2d::KeyEvent::code() const +e2d::KeyCode e2d::KeyEvent::getCode() const { return _code; } -int e2d::KeyEvent::count() const +int e2d::KeyEvent::getCount() const { return _count; } -e2d::KeyEvent::Type e2d::KeyEvent::type() const +e2d::KeyEvent::Type e2d::KeyEvent::getType() const { return _type; } diff --git a/core/Event/MouseEvent.cpp b/core/Event/MouseEvent.cpp index feadaee3..5b67ab95 100644 --- a/core/Event/MouseEvent.cpp +++ b/core/Event/MouseEvent.cpp @@ -11,17 +11,17 @@ e2d::MouseEvent::MouseEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara _pos.y = ((float)(short)HIWORD(lParam)) * 96.f / dpi; } -float e2d::MouseEvent::positionX() const +float e2d::MouseEvent::getX() const { return _pos.x; } -float e2d::MouseEvent::positionY() const +float e2d::MouseEvent::getY() const { return _pos.y; } -e2d::Point e2d::MouseEvent::position() const +e2d::Point e2d::MouseEvent::getPos() const { return _pos; } @@ -36,7 +36,7 @@ bool e2d::MouseEvent::isCtrlDown() const return GET_KEYSTATE_WPARAM(_wParam) == MK_CONTROL; } -float e2d::MouseEvent::wheelDelta() const +float e2d::MouseEvent::getWheelDelta() const { return static_cast(GET_WHEEL_DELTA_WPARAM(_wParam)); } @@ -56,7 +56,7 @@ bool e2d::MouseEvent::isMButtonDown() const return GET_KEYSTATE_WPARAM(_wParam) == MK_MBUTTON; } -e2d::MouseEvent::Type e2d::MouseEvent::type() const +e2d::MouseEvent::Type e2d::MouseEvent::getType() const { return _type; } diff --git a/core/Manager/ActionManager.cpp b/core/Manager/ActionManager.cpp index b4402409..a356b5d9 100644 --- a/core/Manager/ActionManager.cpp +++ b/core/Manager/ActionManager.cpp @@ -3,7 +3,7 @@ #include "..\e2dnode.h" -e2d::ActionManager * e2d::ActionManager::instance() +e2d::ActionManager * e2d::ActionManager::getInstance() { static ActionManager instance; return &instance; @@ -84,7 +84,7 @@ void e2d::ActionManager::resumeAllBindedWith(Node * target) for (const auto& action : _runningActions) { - if (action->target() == target) + if (action->getTarget() == target) { action->resume(); } @@ -98,7 +98,7 @@ void e2d::ActionManager::pauseAllBindedWith(Node * target) for (const auto& action : _runningActions) { - if (action->target() == target) + if (action->getTarget() == target) { action->pause(); } @@ -112,7 +112,7 @@ void e2d::ActionManager::stopAllBindedWith(Node * target) for (const auto& action : _runningActions) { - if (action->target() == target) + if (action->getTarget() == target) { action->stop(); } @@ -146,12 +146,12 @@ void e2d::ActionManager::start(Action * action, Node * target, bool paused) void e2d::ActionManager::resume(const String& name) { - if (_runningActions.empty() || name.empty()) + if (_runningActions.empty() || name.isEmpty()) return; for (const auto& action : _runningActions) { - if (action->name() == name) + if (action->getName() == name) { action->resume(); } @@ -160,12 +160,12 @@ void e2d::ActionManager::resume(const String& name) void e2d::ActionManager::pause(const String& name) { - if (_runningActions.empty() || name.empty()) + if (_runningActions.empty() || name.isEmpty()) return; for (const auto& action : _runningActions) { - if (action->name() == name) + if (action->getName() == name) { action->pause(); } @@ -174,12 +174,12 @@ void e2d::ActionManager::pause(const String& name) void e2d::ActionManager::stop(const String& name) { - if (_runningActions.empty() || name.empty()) + if (_runningActions.empty() || name.isEmpty()) return; for (const auto& action : _runningActions) { - if (action->name() == name) + if (action->getName() == name) { action->stop(); } @@ -193,7 +193,7 @@ void e2d::ActionManager::clearAllBindedWith(Node * target) auto iter = std::find_if( _runningActions.begin(), _runningActions.end(), - [target](Action* action) ->bool { return action->target() == target; } + [target](Action* action) ->bool { return action->getTarget() == target; } ); if (iter != _runningActions.end()) @@ -218,12 +218,12 @@ void e2d::ActionManager::clearAll() _actions.clear(); } -std::vector e2d::ActionManager::actions(const String& name) +std::vector e2d::ActionManager::get(const String& name) { std::vector actions; for (const auto& action : _actions) { - if (action->name() == name) + if (action->getName() == name) { actions.push_back(action); } @@ -231,7 +231,7 @@ std::vector e2d::ActionManager::actions(const String& name) return std::move(actions); } -const std::vector& e2d::ActionManager::actions() +const std::vector& e2d::ActionManager::getAll() { return _actions; } diff --git a/core/Manager/CollisionManager.cpp b/core/Manager/CollisionManager.cpp index 89cc2833..d1f56555 100644 --- a/core/Manager/CollisionManager.cpp +++ b/core/Manager/CollisionManager.cpp @@ -3,7 +3,7 @@ #include "..\e2dtool.h" -e2d::CollisionManager * e2d::CollisionManager::instance() +e2d::CollisionManager * e2d::CollisionManager::getInstance() { static CollisionManager instance; return &instance; @@ -35,7 +35,7 @@ void e2d::CollisionManager::__removeCollider(Collider * collider) void e2d::CollisionManager::__updateCollider(Collider* collider) { if (!_collisionEnabled || - Game::instance()->transitioning()) + Game::getInstance()->isTransitioning()) return; std::vector currColliders; @@ -47,46 +47,46 @@ void e2d::CollisionManager::__updateCollider(Collider* collider) [this, collider](Collider* passive) -> bool { return collider != passive && - passive->node()->visible() && - collider->node()->parentScene() == passive->node()->parentScene() && - this->isCollidable(collider->node(), passive->node()); + passive->getNode()->isVisible() && + collider->getNode()->getParentScene() == passive->getNode()->getParentScene() && + this->isCollidable(collider->getNode(), passive->getNode()); } ); for (const auto& passive : currColliders) { // 判断两碰撞体交集情况 - Collider::Relation relation = collider->relationWith(passive); + Collider::Relation relation = collider->getRelationWith(passive); // 忽略 UNKNOWN 和 DISJOIN 情况 if (relation != Collider::Relation::Unknown && relation != Collider::Relation::Disjoin) { - auto activeNode = collider->node(); - auto passiveNode = passive->node(); + auto activeNode = collider->getNode(); + auto passiveNode = passive->getNode(); // 触发两次碰撞事件 Collision activeCollision(passiveNode, relation); - if (dynamic_cast(activeNode->parentScene())) - dynamic_cast(activeNode->parentScene())->handle(activeCollision); + if (dynamic_cast(activeNode->getParentScene())) + dynamic_cast(activeNode->getParentScene())->handle(activeCollision); if (dynamic_cast(activeNode)) dynamic_cast(activeNode)->handle(activeCollision); - Collision passiveCollision(activeNode, passive->relationWith(collider)); - if (dynamic_cast(passiveNode->parentScene())) - dynamic_cast(passiveNode->parentScene())->handle(passiveCollision); + Collision passiveCollision(activeNode, passive->getRelationWith(collider)); + if (dynamic_cast(passiveNode->getParentScene())) + dynamic_cast(passiveNode->getParentScene())->handle(passiveCollision); if (dynamic_cast(passiveNode)) dynamic_cast(passiveNode)->handle(passiveCollision); } } } -void e2d::CollisionManager::enabled(bool enabled) +void e2d::CollisionManager::setCollisionEnabled(bool enabled) { _collisionEnabled = enabled; } void e2d::CollisionManager::addName(const String & name1, const String & name2) { - if (!name1.empty() && !name2.empty()) + if (!name1.isEmpty() && !name2.isEmpty()) { _collisionList.insert(std::make_pair(name1.hash(), name2.hash())); } @@ -96,7 +96,7 @@ void e2d::CollisionManager::addName(const std::vector { for (const auto& name : names) { - if (!name.first.empty() && !name.second.empty()) + if (!name.first.isEmpty() && !name.second.isEmpty()) { _collisionList.insert(std::make_pair(name.first.hash(), name.second.hash())); } @@ -105,7 +105,7 @@ void e2d::CollisionManager::addName(const std::vector bool e2d::CollisionManager::isCollidable(Node * node1, Node * node2) { - return CollisionManager::isCollidable(node1->name(), node2->name()); + return CollisionManager::isCollidable(node1->getName(), node2->getName()); } bool e2d::CollisionManager::isCollidable(const String & name1, const String & name2) diff --git a/core/Node/Button.cpp b/core/Node/Button.cpp index a828f820..d248e343 100644 --- a/core/Node/Button.cpp +++ b/core/Node/Button.cpp @@ -9,7 +9,7 @@ if (Old) this->removeChild(Old); \ if (New) \ { \ - New->anchor(_anchorX, _anchorY); \ + New->setPivot(_pivotX, _pivotY); \ this->addChild(New); \ } \ Old = New; \ @@ -39,8 +39,8 @@ e2d::Button::Button(Node * normal, const Function& func) , _selected(nullptr) , _disabled(nullptr) { - this->normal(normal); - this->clickCallback(func); + this->setNormal(normal); + this->setClickFunc(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) , _disabled(nullptr) { - this->normal(normal); - this->selected(selected); - this->clickCallback(func); + this->setNormal(normal); + this->setSelected(selected); + this->setClickFunc(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) , _disabled(nullptr) { - this->normal(normal); - this->mouseover(mouseover); - this->selected(selected); - this->clickCallback(func); + this->setNormal(normal); + this->setMouseOver(mouseover); + this->setSelected(selected); + this->setClickFunc(func); } e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Function& func) @@ -84,85 +84,78 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * dis , _selected(nullptr) , _disabled(nullptr) { - this->normal(normal); - this->mouseover(mouseover); - this->selected(selected); - this->disabled(disabled); - this->clickCallback(func); + this->setNormal(normal); + this->setMouseOver(mouseover); + this->setSelected(selected); + this->setDisabled(disabled); + this->setClickFunc(func); } -bool e2d::Button::enabled() const +bool e2d::Button::isEnable() const { return _enabled; } -e2d::Button& e2d::Button::normal(Node * normal) +void e2d::Button::setNormal(Node * normal) { SET_BUTTON_NODE(_normal, normal); if (normal) { - this->size(normal->width(), normal->height()); + this->setSize(normal->getWidth(), normal->getHeight()); } - return *this; } -e2d::Button& e2d::Button::mouseover(Node * mouseover) +void e2d::Button::setMouseOver(Node * mouseover) { SET_BUTTON_NODE(_mouseover, mouseover); - return *this; } -e2d::Button& e2d::Button::selected(Node * selected) +void e2d::Button::setSelected(Node * selected) { SET_BUTTON_NODE(_selected, selected); - return *this; } -e2d::Button& e2d::Button::disabled(Node * disabled) +void e2d::Button::setDisabled(Node * disabled) { SET_BUTTON_NODE(_disabled, disabled); - return *this; } -e2d::Button& e2d::Button::enabled(bool enabled) +void e2d::Button::setEnabled(bool enabled) { if (_enabled != enabled) { _enabled = enabled; _updateVisible(); } - return *this; } -e2d::Button& e2d::Button::clickCallback(const Function& func) +void e2d::Button::setClickFunc(const Function& func) { _func = func; - return *this; } -e2d::Button& e2d::Button::anchor(float anchorX, float anchorY) +void e2d::Button::setPivot(float pivotX, float pivotY) { - Node::anchor(anchorX, anchorY); - SAFE_SET(_normal, anchor, anchorX, anchorY); - SAFE_SET(_mouseover, anchor, anchorX, anchorY); - SAFE_SET(_selected, anchor, anchorX, anchorY); - SAFE_SET(_disabled, anchor, anchorX, anchorY); - return *this; + Node::setPivot(pivotX, pivotY); + SAFE_SET(_normal, setPivot, pivotX, pivotY); + SAFE_SET(_mouseover, setPivot, pivotX, pivotY); + SAFE_SET(_selected, setPivot, pivotX, pivotY); + SAFE_SET(_disabled, setPivot, pivotX, pivotY); } bool e2d::Button::dispatch(const MouseEvent & e, bool handled) { if (!handled && _enabled && _visible && _normal) { - bool contains = _normal->containsPoint(e.position()); - if (e.type() == MouseEvent::Type::LeftUp && _isSelected && contains) + bool contains = _normal->containsPoint(e.getPos()); + if (e.getType() == MouseEvent::Type::LeftUp && _isSelected && contains) { _runCallback(); _isSelected = false; _setStatus(Status::Normal); return true; } - else if (e.type() == MouseEvent::Type::LeftDown) + else if (e.getType() == MouseEvent::Type::LeftDown) { _isSelected = contains; _setStatus(contains ? Status::Selected : Status::Normal); @@ -170,11 +163,11 @@ bool e2d::Button::dispatch(const MouseEvent & e, bool handled) if (contains) return true; } - else if (e.type() == MouseEvent::Type::LeftUp) + else if (e.getType() == MouseEvent::Type::LeftUp) { _isSelected = false; } - else if (e.type() == MouseEvent::Type::Move && _isSelected && contains) + else if (e.getType() == MouseEvent::Type::Move && _isSelected && contains) { _setStatus(Status::Selected); return true; @@ -203,13 +196,13 @@ void e2d::Button::visit(Game * game) if (_visible && !_enabled && _normal && - _normal->containsPoint(game->input()->mousePos())) + _normal->containsPoint(game->getInput()->getMousePos())) { - game->window()->cursor(Window::Cursor::No); + game->getWindow()->setCursor(Window::Cursor::No); } else if (_status == Status::Mouseover || _status == Status::Selected) { - game->window()->cursor(Window::Cursor::Hand); + game->getWindow()->setCursor(Window::Cursor::Hand); } } @@ -224,35 +217,35 @@ void e2d::Button::_setStatus(Status status) void e2d::Button::_updateVisible() { - SAFE_SET(_normal, visible, false); - SAFE_SET(_mouseover, visible, false); - SAFE_SET(_selected, visible, false); - SAFE_SET(_disabled, visible, false); + SAFE_SET(_normal, setVisible, false); + SAFE_SET(_mouseover, setVisible, false); + SAFE_SET(_selected, setVisible, false); + SAFE_SET(_disabled, setVisible, false); if (_enabled) { if (_status == Status::Selected && _selected) { - _selected->visible(true); + _selected->setVisible(true); } else if (_status == Status::Mouseover && _mouseover) { - _mouseover->visible(true); + _mouseover->setVisible(true); } else { - if (_normal) _normal->visible(true); + if (_normal) _normal->setVisible(true); } } else { if (_disabled) { - _disabled->visible(true); + _disabled->setVisible(true); } else { - if (_normal) _normal->visible(true); + if (_normal) _normal->setVisible(true); } } } diff --git a/core/Node/Canvas.cpp b/core/Node/Canvas.cpp index df90440d..574133a8 100644 --- a/core/Node/Canvas.cpp +++ b/core/Node/Canvas.cpp @@ -9,8 +9,8 @@ e2d::Canvas::Canvas(float width, float height) , _strokeWidth(1.0f) , _stroke(Stroke::Miter) { - _renderer = Game::instance()->renderer(); - _renderTarget = _renderer->renderTarget(); + _renderer = Game::getInstance()->getRenderer(); + _renderTarget = _renderer->getRenderTarget(); _renderTarget->AddRef(); ThrowIfFailed( @@ -27,10 +27,10 @@ e2d::Canvas::Canvas(float width, float height) ) ); - this->clipEnabled(true); - this->width(width); - this->height(height); - this->strokeStyle(_stroke); + this->setClipEnabled(true); + this->setWidth(width); + this->setHeight(height); + this->setStrokeStyle(_stroke); } e2d::Canvas::~Canvas() @@ -40,62 +40,58 @@ e2d::Canvas::~Canvas() SafeRelease(_renderTarget); } -e2d::Canvas& e2d::Canvas::lineColor(const Color & color) +void e2d::Canvas::setLineColor(const Color & color) { _lineBrush->SetColor(D2D_COLOR_F(color)); - return *this; } -e2d::Canvas& e2d::Canvas::fillColor(const Color & color) +void e2d::Canvas::setFillColor(const Color & color) { _fillBrush->SetColor(D2D_COLOR_F(color)); - return *this; } -e2d::Canvas& e2d::Canvas::strokeWidth(float width) +void e2d::Canvas::setStrokeWidth(float width) { _strokeWidth = std::max(width, 0.f); - return *this; } -e2d::Canvas& e2d::Canvas::strokeStyle(Stroke strokeStyle) +void e2d::Canvas::setStrokeStyle(Stroke strokeStyle) { switch (strokeStyle) { case e2d::Stroke::Miter: - _strokeStyle = _renderer->miterStrokeStyle(); + _strokeStyle = _renderer->getMiterStrokeStyle(); break; case e2d::Stroke::Bevel: - _strokeStyle = _renderer->bevelStrokeStyle(); + _strokeStyle = _renderer->getBevelStrokeStyle(); break; case e2d::Stroke::Round: - _strokeStyle = _renderer->roundStrokeStyle(); + _strokeStyle = _renderer->getRoundStrokeStyle(); break; } - return *this; } -e2d::Color e2d::Canvas::lineColor() const +const e2d::Color & e2d::Canvas::getLineColor() const { - return _lineBrush->GetColor(); + return Color(_lineBrush->GetColor()); } -e2d::Color e2d::Canvas::fillColor() const +const e2d::Color & e2d::Canvas::getFillColor() const { - return _fillBrush->GetColor(); + return Color(_fillBrush->GetColor()); } -float e2d::Canvas::strokeWidth() const +float e2d::Canvas::getStrokeWidth() const { return _strokeWidth; } -e2d::Stroke e2d::Canvas::strokeStyle() const +e2d::Stroke e2d::Canvas::getStrokeStyle() const { return _stroke; } -e2d::Canvas& e2d::Canvas::drawLine(const Point & begin, const Point & end) +void e2d::Canvas::drawLine(const Point & begin, const Point & end) { _renderTarget->DrawLine( D2D1::Point2F(begin.x, begin.y), @@ -104,10 +100,9 @@ e2d::Canvas& e2d::Canvas::drawLine(const Point & begin, const Point & end) _strokeWidth, _strokeStyle ); - return *this; } -e2d::Canvas& e2d::Canvas::drawCircle(const Point & center, float radius) +void e2d::Canvas::drawCircle(const Point & center, float radius) { _renderTarget->DrawEllipse( D2D1::Ellipse( @@ -122,10 +117,9 @@ e2d::Canvas& e2d::Canvas::drawCircle(const Point & center, float radius) _strokeWidth, _strokeStyle ); - return *this; } -e2d::Canvas& e2d::Canvas::drawEllipse(const Point & center, float radiusX, float radiusY) +void e2d::Canvas::drawEllipse(const Point & center, float radiusX, float radiusY) { _renderTarget->DrawEllipse( D2D1::Ellipse( @@ -140,10 +134,9 @@ e2d::Canvas& e2d::Canvas::drawEllipse(const Point & center, float radiusX, float _strokeWidth, _strokeStyle ); - return *this; } -e2d::Canvas& e2d::Canvas::drawRect(const Rect & rect) +void e2d::Canvas::drawRect(const Rect & rect) { _renderTarget->DrawRectangle( D2D1::RectF( @@ -156,10 +149,9 @@ e2d::Canvas& e2d::Canvas::drawRect(const Rect & rect) _strokeWidth, _strokeStyle ); - return *this; } -e2d::Canvas& e2d::Canvas::drawRoundedRect(const Rect & rect, float radiusX, float radiusY) +void e2d::Canvas::drawRoundedRect(const Rect & rect, float radiusX, float radiusY) { _renderTarget->DrawRoundedRectangle( D2D1::RoundedRect( @@ -176,10 +168,9 @@ e2d::Canvas& e2d::Canvas::drawRoundedRect(const Rect & rect, float radiusX, floa _strokeWidth, _strokeStyle ); - return *this; } -e2d::Canvas& e2d::Canvas::fillCircle(const Point & center, float radius) +void e2d::Canvas::fillCircle(const Point & center, float radius) { _renderTarget->FillEllipse( D2D1::Ellipse( @@ -192,10 +183,9 @@ e2d::Canvas& e2d::Canvas::fillCircle(const Point & center, float radius) ), _fillBrush ); - return *this; } -e2d::Canvas& e2d::Canvas::fillEllipse(const Point & center, float radiusX, float radiusY) +void e2d::Canvas::fillEllipse(const Point & center, float radiusX, float radiusY) { _renderTarget->FillEllipse( D2D1::Ellipse( @@ -208,10 +198,9 @@ e2d::Canvas& e2d::Canvas::fillEllipse(const Point & center, float radiusX, float ), _fillBrush ); - return *this; } -e2d::Canvas& e2d::Canvas::fillRect(const Rect & rect) +void e2d::Canvas::fillRect(const Rect & rect) { _renderTarget->FillRectangle( D2D1::RectF( @@ -222,10 +211,9 @@ e2d::Canvas& e2d::Canvas::fillRect(const Rect & rect) ), _fillBrush ); - return *this; } -e2d::Canvas& e2d::Canvas::fillRoundedRect(const Rect & rect, float radiusX, float radiusY) +void e2d::Canvas::fillRoundedRect(const Rect & rect, float radiusX, float radiusY) { _renderTarget->FillRoundedRectangle( D2D1::RoundedRect( @@ -240,5 +228,4 @@ e2d::Canvas& e2d::Canvas::fillRoundedRect(const Rect & rect, float radiusX, floa ), _fillBrush ); - return *this; } diff --git a/core/Node/Menu.cpp b/core/Node/Menu.cpp index 52d32f6c..68e3a17a 100644 --- a/core/Node/Menu.cpp +++ b/core/Node/Menu.cpp @@ -14,17 +14,17 @@ e2d::Menu::Menu(const std::vector& buttons) } } -bool e2d::Menu::enabled() const +bool e2d::Menu::isEnable() const { return _enabled; } -int e2d::Menu::buttonCount() const +size_t e2d::Menu::getButtonCount() const { - return static_cast(_buttons.size()); + return _buttons.size(); } -e2d::Menu& e2d::Menu::enabled(bool enabled) +void e2d::Menu::setEnabled(bool enabled) { if (_enabled != enabled) { @@ -32,21 +32,19 @@ e2d::Menu& e2d::Menu::enabled(bool enabled) for (const auto& button : _buttons) { - button->enabled(enabled); + button->setEnabled(enabled); } } - return *this; } -e2d::Menu& e2d::Menu::addButton(Button * button) +void e2d::Menu::addButton(Button * button) { if (button) { this->addChild(button); _buttons.push_back(button); - button->enabled(_enabled); + button->setEnabled(_enabled); } - return *this; } bool e2d::Menu::removeButton(Button * button) @@ -64,7 +62,7 @@ bool e2d::Menu::removeButton(Button * button) if (iter != _buttons.end()) { // 移除按钮前,将它启用 - button->enabled(true); + button->setEnabled(true); _buttons.erase(iter); return true; } @@ -72,7 +70,7 @@ bool e2d::Menu::removeButton(Button * button) return false; } -const std::vector& e2d::Menu::buttons() const +const std::vector& e2d::Menu::getAllButtons() const { return _buttons; } diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index 25f12624..5b96e7e2 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -3,15 +3,17 @@ #include "..\e2dmanager.h" #include "..\e2daction.h" -const e2d::Node::Property e2d::Node::Property::Origin; +const e2d::Node::Property e2d::Node::Property::Origin = { 0 }; e2d::Node::Property e2d::Node::Property::operator+(Property const & prop) const { Property result; - result.position = this->position + prop.position; - result.size = this->size + prop.size; - result.anchorX = this->anchorX + prop.anchorX; - result.anchorY = this->anchorY + prop.anchorY; + result.posX = this->posX + prop.posX; + result.posY = this->posY + prop.posY; + result.width = this->width + prop.width; + result.height = this->height + prop.height; + result.pivotX = this->pivotX + prop.pivotX; + result.pivotY = this->pivotY + prop.pivotY; result.scaleX = this->scaleX + prop.scaleX; result.scaleY = this->scaleY + prop.scaleY; result.rotation = this->rotation + prop.rotation; @@ -23,10 +25,12 @@ e2d::Node::Property e2d::Node::Property::operator+(Property const & prop) const e2d::Node::Property e2d::Node::Property::operator-(Property const & prop) const { Property result; - result.position = this->position - prop.position; - result.size = this->size - prop.size; - result.anchorX = this->anchorX - prop.anchorX; - result.anchorY = this->anchorY - prop.anchorY; + result.posX = this->posX - prop.posX; + result.posY = this->posY - prop.posY; + result.width = this->width - prop.width; + result.height = this->height - prop.height; + result.pivotX = this->pivotX - prop.pivotX; + result.pivotY = this->pivotY - prop.pivotY; result.scaleX = this->scaleX - prop.scaleX; result.scaleY = this->scaleY - prop.scaleY; result.rotation = this->rotation - prop.rotation; @@ -38,8 +42,10 @@ e2d::Node::Property e2d::Node::Property::operator-(Property const & prop) const e2d::Node::Node() : _order(0) - , _position() - , _size() + , _posX(0) + , _posY(0) + , _width(0) + , _height(0) , _scaleX(1.0f) , _scaleY(1.0f) , _rotation(0) @@ -47,8 +53,8 @@ e2d::Node::Node() , _skewAngleY(0) , _displayOpacity(1.f) , _realOpacity(1.f) - , _anchorX(0.f) - , _anchorY(0.f) + , _pivotX(0.f) + , _pivotY(0.f) , _initialMatri(D2D1::Matrix3x2F::Identity()) , _finalMatri(D2D1::Matrix3x2F::Identity()) , _visible(true) @@ -66,10 +72,10 @@ e2d::Node::Node() e2d::Node::~Node() { - ActionManager::instance()->clearAllBindedWith(this); + ActionManager::getInstance()->clearAllBindedWith(this); for (const auto& child : _children) { - GC::instance()->safeRelease(child); + GC::getInstance()->safeRelease(child); } } @@ -78,7 +84,7 @@ void e2d::Node::visit(Game * game) if (!_visible) return; - if (!game->paused()) + if (!game->isPaused()) { auto updatableNode = dynamic_cast(this); if (updatableNode) @@ -90,16 +96,16 @@ void e2d::Node::visit(Game * game) _updateTransform(); // 保留差别属性 - _extrapolate = this->properties(); + _extrapolate = this->getProperty(); } - auto renderer = game->renderer(); - auto renderTarget = renderer->renderTarget(); + auto renderer = game->getRenderer(); + auto renderTarget = renderer->getRenderTarget(); if (_clipEnabled) { renderTarget->SetTransform(_finalMatri); renderTarget->PushAxisAlignedClip( - D2D1::RectF(0, 0, _size.width, _size.height), + D2D1::RectF(0, 0, _width, _height), D2D1_ANTIALIAS_MODE_PER_PRIMITIVE ); } @@ -123,7 +129,7 @@ void e2d::Node::visit(Game * game) { auto child = _children[i]; // 访问 Order 小于零的节点 - if (child->order() < 0) + if (child->getOrder() < 0) { child->visit(game); } @@ -155,10 +161,10 @@ void e2d::Node::drawOutline(Renderer * renderer) { if (_visible) { - renderer->renderTarget()->SetTransform(_finalMatri); - renderer->renderTarget()->DrawRectangle( - D2D1::RectF(0, 0, _size.width, _size.height), - renderer->solidBrush(), + renderer->getRenderTarget()->SetTransform(_finalMatri); + renderer->getRenderTarget()->DrawRectangle( + D2D1::RectF(0, 0, _width, _height), + renderer->getSolidColorBrush(), 1.5f ); @@ -191,26 +197,26 @@ void e2d::Node::_updateTransform() _needTransform = false; - // 计算锚点坐标 - D2D1_POINT_2F anchor = { _size.width * _anchorX, _size.height * _anchorY }; + // 计算中心点坐标 + D2D1_POINT_2F pivot = { _width * _pivotX, _height * _pivotY }; // 变换 Initial 矩阵,子节点将根据这个矩阵进行变换 _initialMatri = D2D1::Matrix3x2F::Scale( _scaleX, _scaleY, - anchor + pivot ) * D2D1::Matrix3x2F::Skew( _skewAngleX, _skewAngleY, - anchor + pivot ) * D2D1::Matrix3x2F::Rotation( _rotation, - anchor + pivot ) * D2D1::Matrix3x2F::Translation( - _position.x, - _position.y + _posX, + _posY ); - // 根据自身锚点变换 Final 矩阵 - _finalMatri = _initialMatri * D2D1::Matrix3x2F::Translation(-anchor.x, -anchor.y); + // 根据自身中心点变换 Final 矩阵 + _finalMatri = _initialMatri * D2D1::Matrix3x2F::Translation(-pivot.x, -pivot.y); // 和父节点矩阵相乘 if (!_positionFixed && _parent) { @@ -227,11 +233,11 @@ void e2d::Node::_updateTransform() // 更新碰撞体 _collider.recreate(); - if (_collider.enabled() && - _collider.notify() && - _collider.shape() != Collider::Shape::None) + if (_collider.isEnabled() && + _collider.isCollisionNotify() && + _collider.getShape() != Collider::Shape::None) { - CollisionManager::instance()->__updateCollider(&_collider); + CollisionManager::getInstance()->__updateCollider(&_collider); } } @@ -272,7 +278,7 @@ void e2d::Node::_sortChildren() std::sort( std::begin(_children), std::end(_children), - [](Node * n1, Node * n2) { return n1->order() < n2->order(); } + [](Node * n1, Node * n2) { return n1->getOrder() < n2->getOrder(); } ); _needSort = false; @@ -291,113 +297,115 @@ void e2d::Node::_updateOpacity() } } -bool e2d::Node::visible() const +bool e2d::Node::isVisible() const { return _visible; } -const e2d::String& e2d::Node::name() const +e2d::String e2d::Node::getName() const { return _name; } -size_t e2d::Node::hashName() const +size_t e2d::Node::getHashName() const { return _hashName; } -float e2d::Node::positionX() const +float e2d::Node::getPosX() const { - return _position.x; + return _posX; } -float e2d::Node::positionY() const +float e2d::Node::getPosY() const { - return _position.y; + return _posY; } -const e2d::Point& e2d::Node::position() const +e2d::Point e2d::Node::getPos() const { - return _position; + return Point(_posX, _posY); } -float e2d::Node::width() const +float e2d::Node::getWidth() const { - return _size.width * _scaleX; + return _width * _scaleX; } -float e2d::Node::height() const +float e2d::Node::getHeight() const { - return _size.height * _scaleY; + return _height * _scaleY; } -e2d::Size e2d::Node::size() const +float e2d::Node::getRealWidth() const { - return Size(width(), height()); + return _width; } -float e2d::Node::realWidth() const +float e2d::Node::getRealHeight() const { - return _size.width; + return _height; } -float e2d::Node::realHeight() const +e2d::Size e2d::Node::getRealSize() const { - return _size.height; + return Size(_width, _height); } -const e2d::Size& e2d::Node::realSize() const +float e2d::Node::getPivotX() const { - return _size; + return _pivotX; } -float e2d::Node::anchorX() const +float e2d::Node::getPivotY() const { - return _anchorX; + return _pivotY; } -float e2d::Node::anchorY() const +e2d::Size e2d::Node::getSize() const { - return _anchorY; + return Size(getWidth(), getHeight()); } -float e2d::Node::scaleX() const +float e2d::Node::getScaleX() const { return _scaleX; } -float e2d::Node::scaleY() const +float e2d::Node::getScaleY() const { return _scaleY; } -float e2d::Node::skewX() const +float e2d::Node::getSkewX() const { return _skewAngleX; } -float e2d::Node::skewY() const +float e2d::Node::getSkewY() const { return _skewAngleY; } -float e2d::Node::rotation() const +float e2d::Node::getRotation() const { return _rotation; } -float e2d::Node::opacity() const +float e2d::Node::getOpacity() const { return _realOpacity; } -e2d::Node::Property e2d::Node::properties() const +e2d::Node::Property e2d::Node::getProperty() const { Property prop; - prop.position = _position; - prop.size = _size; - prop.anchorX = _anchorX; - prop.anchorY = _anchorY; + prop.posX = _posX; + prop.posY = _posY; + prop.width = _width; + prop.height = _height; + prop.pivotX = _pivotX; + prop.pivotY = _pivotY; prop.scaleX = _scaleX; prop.scaleY = _scaleY; prop.rotation = _rotation; @@ -406,213 +414,212 @@ e2d::Node::Property e2d::Node::properties() const return std::move(prop); } -e2d::Node::Property e2d::Node::extrapolate() const +e2d::Node::Property e2d::Node::getExtrapolate() const { - return this->properties() - _extrapolate; + return this->getProperty() - _extrapolate; } -e2d::Collider* e2d::Node::collider() +e2d::Collider* e2d::Node::getCollider() { return &_collider; } -int e2d::Node::order() const +int e2d::Node::getOrder() const { return _order; } -e2d::Node& e2d::Node::order(int order) +void e2d::Node::setOrder(int order) { if (_order == order) - return *this; + return; _order = order; if (_parent) { _parent->_needSort = true; } - return *this; } -e2d::Node& e2d::Node::positionX(float x) +void e2d::Node::setPosX(float x) { - return position(x, _position.y); + this->setPos(x, _posY); } -e2d::Node& e2d::Node::positionY(float y) +void e2d::Node::setPosY(float y) { - return position(_position.x, y); + this->setPos(_posX, y); } -e2d::Node& e2d::Node::position(const Point & p) +void e2d::Node::setPos(const Point & p) { - return position(p.x, p.y); + this->setPos(p.x, p.y); } -e2d::Node& e2d::Node::position(float x, float y) +void e2d::Node::setPos(float x, float y) { - if (_position.x == x && _position.y == y) - return *this; + if (_posX == x && _posY == y) + return; - _position.x = x; - _position.y = y; + _posX = x; + _posY = y; _needTransform = true; - return *this; } -e2d::Node& e2d::Node::positionFixed(bool fixed) +void e2d::Node::setPosFixed(bool fixed) { if (_positionFixed == fixed) - return *this; + return; _positionFixed = fixed; _needTransform = true; - return *this; } -e2d::Node& e2d::Node::move(float x, float y) +void e2d::Node::movePosX(float x) { - return position(_position.x + x, _position.y + y); + this->movePos(x, 0); } -e2d::Node& e2d::Node::move(const Vector2 & v) +void e2d::Node::movePosY(float y) { - return move(v.x, v.y); + this->movePos(0, y); } -e2d::Node& e2d::Node::scaleX(float scaleX) +void e2d::Node::movePos(float x, float y) { - return scale(scaleX, _scaleY); + this->setPos(_posX + x, _posY + y); } -e2d::Node& e2d::Node::scaleY(float scaleY) +void e2d::Node::movePos(const Vector2 & v) { - return scale(_scaleX, scaleY); + this->movePos(v.x, v.y); } -e2d::Node& e2d::Node::scale(float scale0) +void e2d::Node::setScaleX(float scaleX) { - return scale(scale0, scale0); + this->setScale(scaleX, _scaleY); } -e2d::Node& e2d::Node::scale(float scaleX, float scaleY) +void e2d::Node::setScaleY(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) - return *this; + return; _scaleX = scaleX; _scaleY = scaleY; _needTransform = true; - return *this; } -e2d::Node& e2d::Node::skewX(float angleX) +void e2d::Node::setSkewX(float angleX) { - return skew(angleX, _skewAngleY); + this->setSkew(angleX, _skewAngleY); } -e2d::Node& e2d::Node::skewY(float angleY) +void e2d::Node::setSkewY(float angleY) { - return skew(_skewAngleX, angleY); + this->setSkew(_skewAngleX, angleY); } -e2d::Node& e2d::Node::skew(float angleX, float angleY) +void e2d::Node::setSkew(float angleX, float angleY) { if (_skewAngleX == angleX && _skewAngleY == angleY) - return *this; + return; _skewAngleX = angleX; _skewAngleY = angleY; _needTransform = true; - return *this; } -e2d::Node& e2d::Node::rotation(float angle) +void e2d::Node::setRotation(float angle) { if (_rotation == angle) - return *this; + return; _rotation = angle; _needTransform = true; - return *this; } -e2d::Node& e2d::Node::opacity(float opacity) +void e2d::Node::setOpacity(float opacity) { if (_realOpacity == opacity) - return *this; + return; _displayOpacity = _realOpacity = std::min(std::max(opacity, 0.f), 1.f); // 更新节点透明度 _updateOpacity(); - return *this; } -e2d::Node& e2d::Node::anchorX(float anchorX) +void e2d::Node::setPivotX(float pivotX) { - return anchor(anchorX, _anchorY); + this->setPivot(pivotX, _pivotY); } -e2d::Node& e2d::Node::anchorY(float anchorY) +void e2d::Node::setPivotY(float pivotY) { - return anchor(_anchorX, anchorY); + this->setPivot(_pivotX, pivotY); } -e2d::Node& e2d::Node::anchor(float anchorX, float anchorY) +void e2d::Node::setPivot(float pivotX, float pivotY) { - if (_anchorX == anchorX && _anchorY == anchorY) - return *this; + if (_pivotX == pivotX && _pivotY == pivotY) + return; - _anchorX = std::min(std::max(anchorX, 0.f), 1.f); - _anchorY = std::min(std::max(anchorY, 0.f), 1.f); + _pivotX = std::min(std::max(pivotX, 0.f), 1.f); + _pivotY = std::min(std::max(pivotY, 0.f), 1.f); _needTransform = true; - return *this; } -e2d::Node& e2d::Node::width(float width) +void e2d::Node::setWidth(float width) { - return size(width, _size.height); + this->setSize(width, _height); } -e2d::Node& e2d::Node::height(float height) +void e2d::Node::setHeight(float height) { - return size(_size.width, height); + this->setSize(_width, height); } -e2d::Node& e2d::Node::size(float width, float height) +void e2d::Node::setSize(float width, float height) { - if (_size.width == width && _size.height == height) - return *this; + if (_width == width && _height == height) + return; - _size.width = width; - _size.height = height; + _width = width; + _height = height; _needTransform = true; - return *this; } -e2d::Node& e2d::Node::size(Size size0) +void e2d::Node::setSize(Size size) { - return size(size0.width, size0.height); + this->setSize(size.width, size.height); } -e2d::Node& e2d::Node::properties(Property prop) +void e2d::Node::setProperty(Property prop) { - this->position(prop.position.x, prop.position.y); - this->size(prop.size.width, prop.size.height); - this->anchor(prop.anchorX, prop.anchorY); - this->scale(prop.scaleX, prop.scaleY); - this->rotation(prop.rotation); - this->skew(prop.skewAngleX, prop.skewAngleY); - return *this; + this->setPos(prop.posX, prop.posY); + this->setSize(prop.width, prop.height); + this->setPivot(prop.pivotX, prop.pivotY); + this->setScale(prop.scaleX, prop.scaleY); + this->setRotation(prop.rotation); + this->setSkew(prop.skewAngleX, prop.skewAngleY); } -e2d::Node& e2d::Node::clipEnabled(bool enabled) +void e2d::Node::setClipEnabled(bool enabled) { _clipEnabled = enabled; - return *this; } -e2d::Node& e2d::Node::addChild(Node * child, int order /* = 0 */) +void e2d::Node::addChild(Node * child, int order /* = 0 */) { WARN_IF(child == nullptr, "Node::addChild NULL pointer exception."); @@ -623,7 +630,7 @@ e2d::Node& e2d::Node::addChild(Node * child, int order /* = 0 */) throw Exception("节点已有父节点, 不能再添加到其他节点"); } - for (Node * parent = this; parent != nullptr; parent = parent->parent()) + for (Node * parent = this; parent != nullptr; parent = parent->getParent()) { if (child == parent) { @@ -633,7 +640,7 @@ e2d::Node& e2d::Node::addChild(Node * child, int order /* = 0 */) child->retain(); _children.push_back(child); - child->order(order); + child->setOrder(order); child->_parent = this; if (this->_parentScene) { @@ -647,29 +654,27 @@ e2d::Node& e2d::Node::addChild(Node * child, int order /* = 0 */) // 更新子节点排序 _needSort = true; } - return *this; } -e2d::Node& e2d::Node::addChild(const std::vector& nodes, int order) +void e2d::Node::addChild(const std::vector& nodes, int order) { for (const auto& node : nodes) { this->addChild(node, order); } - return *this; } -e2d::Node * e2d::Node::parent() const +e2d::Node * e2d::Node::getParent() const { return _parent; } -e2d::Scene * e2d::Node::parentScene() const +e2d::Scene * e2d::Node::getParentScene() const { return _parentScene; } -std::vector e2d::Node::children(const String& name) const +std::vector e2d::Node::getChildren(const String& name) const { std::vector vChildren; size_t hash = name.hash(); @@ -685,7 +690,7 @@ std::vector e2d::Node::children(const String& name) const return std::move(vChildren); } -e2d::Node * e2d::Node::child(const String& name) const +e2d::Node * e2d::Node::getChild(const String& name) const { size_t hash = name.hash(); @@ -700,32 +705,31 @@ e2d::Node * e2d::Node::child(const String& name) const return nullptr; } -const std::vector& e2d::Node::children() const +const std::vector& e2d::Node::getAllChildren() const { return _children; } -int e2d::Node::childrenCount() const +int e2d::Node::getChildrenCount() const { return static_cast(_children.size()); } -e2d::Node& e2d::Node::removeFromParent() +void e2d::Node::removeFromParent() { if (_parent) { _parent->removeChild(this); } - return *this; } -e2d::Node& e2d::Node::removeChild(Node * child) +bool e2d::Node::removeChild(Node * child) { WARN_IF(child == nullptr, "Node::removeChildren NULL pointer exception."); if (_children.empty()) { - return *this; + return false; } if (child) @@ -742,19 +746,19 @@ e2d::Node& e2d::Node::removeChild(Node * child) } child->release(); - return *this; + return true; } } - return *this; + return false; } -e2d::Node& e2d::Node::removeChildren(const String& childName) +void e2d::Node::removeChildren(const String& childName) { - WARN_IF(childName.empty(), "Invalid Node name."); + WARN_IF(childName.isEmpty(), "Invalid Node name."); if (_children.empty()) { - return *this; + return; } // 计算名称 Hash 值 @@ -776,10 +780,9 @@ e2d::Node& e2d::Node::removeChildren(const String& childName) (*iter)->release(); _children.erase(iter); } - return *this; } -e2d::Node& e2d::Node::removeAllChildren() +void e2d::Node::removeAllChildren() { // 所有节点的引用计数减一 for (const auto& child : _children) @@ -788,52 +791,47 @@ e2d::Node& e2d::Node::removeAllChildren() } // 清空储存节点的容器 _children.clear(); - return *this; } -e2d::Node& e2d::Node::runAction(Action * action) +void e2d::Node::runAction(Action * action) { - ActionManager::instance()->start(action, this, false); - return *this; + ActionManager::getInstance()->start(action, this, false); } -e2d::Node& e2d::Node::resumeAction(const String& name) +void e2d::Node::resumeAction(const String& name) { - auto& actions = ActionManager::instance()->actions(name); + auto& actions = ActionManager::getInstance()->get(name); for (const auto& action : actions) { - if (action->target() == this) + if (action->getTarget() == this) { action->resume(); } } - return *this; } -e2d::Node& e2d::Node::pauseAction(const String& name) +void e2d::Node::pauseAction(const String& name) { - auto& actions = ActionManager::instance()->actions(name); + auto& actions = ActionManager::getInstance()->get(name); for (const auto& action : actions) { - if (action->target() == this) + if (action->getTarget() == this) { action->pause(); } } - return *this; } -e2d::Node& e2d::Node::stopAction(const String& name) +void e2d::Node::stopAction(const String& name) { - auto& actions = ActionManager::instance()->actions(name); + auto& actions = ActionManager::getInstance()->get(name); for (const auto& action : actions) { - if (action->target() == this) + if (action->getTarget() == this) { action->stop(); } } - return *this; } bool e2d::Node::containsPoint(const Point& point) @@ -844,11 +842,11 @@ bool e2d::Node::containsPoint(const Point& point) // 为节点创建一个轮廓 BOOL ret = 0; ID2D1RectangleGeometry * rectGeo = nullptr; - auto factory = Game::instance()->renderer()->factory(); + auto factory = Game::getInstance()->getRenderer()->getFactory(); ThrowIfFailed( factory->CreateRectangleGeometry( - D2D1::RectF(0, 0, _size.width, _size.height), + D2D1::RectF(0, 0, _width, _height), &rectGeo ) ); @@ -876,18 +874,18 @@ bool e2d::Node::intersects(Node * node) D2D1_GEOMETRY_RELATION relation = D2D1_GEOMETRY_RELATION_UNKNOWN; ID2D1RectangleGeometry *rectGeo = nullptr, *rectGeo2 = nullptr; ID2D1TransformedGeometry *transGeo = nullptr, *transGeo2 = nullptr; - auto factory = Game::instance()->renderer()->factory(); + auto factory = Game::getInstance()->getRenderer()->getFactory(); ThrowIfFailed( factory->CreateRectangleGeometry( - D2D1::RectF(0, 0, _size.width, _size.height), + D2D1::RectF(0, 0, _width, _height), &rectGeo ) ); ThrowIfFailed( factory->CreateRectangleGeometry( - D2D1::RectF(0, 0, node->_size.width, node->_size.height), + D2D1::RectF(0, 0, node->_width, node->_height), &rectGeo2 ) ); @@ -926,43 +924,37 @@ bool e2d::Node::intersects(Node * node) relation != D2D1_GEOMETRY_RELATION_DISJOINT; } -e2d::Node& e2d::Node::resumeAllActions() +void e2d::Node::resumeAllActions() { - ActionManager::instance()->resumeAllBindedWith(this); - return *this; + ActionManager::getInstance()->resumeAllBindedWith(this); } -e2d::Node& e2d::Node::pauseAllActions() +void e2d::Node::pauseAllActions() { - ActionManager::instance()->pauseAllBindedWith(this); - return *this; + ActionManager::getInstance()->pauseAllBindedWith(this); } -e2d::Node& e2d::Node::stopAllActions() +void e2d::Node::stopAllActions() { - ActionManager::instance()->stopAllBindedWith(this); - return *this; + ActionManager::getInstance()->stopAllBindedWith(this); } -e2d::Node& e2d::Node::visible(bool value) +void e2d::Node::setVisible(bool value) { _visible = value; - return *this; } -e2d::Node& e2d::Node::name(const String& name) +void e2d::Node::setName(const String& name) { - WARN_IF(name.empty(), "Invalid Node name."); + WARN_IF(name.isEmpty(), "Invalid Node name."); - if (!name.empty() && _name != name) + if (!name.isEmpty() && _name != name) { // 保存节点名 _name = name; // 保存节点 Hash 名 _hashName = name.hash(); } - - return *this; } void e2d::Node::_setParentScene(Scene * scene) diff --git a/core/Node/Scene.cpp b/core/Node/Scene.cpp index 9dc596e1..31110ad5 100644 --- a/core/Node/Scene.cpp +++ b/core/Node/Scene.cpp @@ -12,16 +12,14 @@ e2d::Scene::~Scene() { } -e2d::Scene& e2d::Scene::outlineVisible(bool visible) +void e2d::Scene::setOutlineVisible(bool visible) { _outlineVisible = visible; - return *this; } -e2d::Scene& e2d::Scene::colliderVisible(bool visible) +void e2d::Scene::setColliderVisible(bool visible) { _colliderVisible = visible; - return *this; } void e2d::Scene::visit(Game * game) @@ -30,14 +28,14 @@ void e2d::Scene::visit(Game * game) if (_outlineVisible) { - auto brush = game->renderer()->solidBrush(); + auto brush = game->getRenderer()->getSolidColorBrush(); brush->SetColor(D2D1::ColorF(D2D1::ColorF::Red, 0.6f)); brush->SetOpacity(1.f); - this->drawOutline(game->renderer()); + this->drawOutline(game->getRenderer()); } if (_colliderVisible) { - game->renderer()->renderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); + game->getRenderer()->getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); this->drawCollider(); } } diff --git a/core/Node/Sprite.cpp b/core/Node/Sprite.cpp index fc7e7b67..f4c2cc09 100644 --- a/core/Node/Sprite.cpp +++ b/core/Node/Sprite.cpp @@ -40,7 +40,7 @@ e2d::Sprite::Sprite(const String & fileName, const Rect & cropRect) e2d::Sprite::~Sprite() { - GC::instance()->safeRelease(_image); + GC::getInstance()->safeRelease(_image); } bool e2d::Sprite::open(Image * image) @@ -51,7 +51,7 @@ bool e2d::Sprite::open(Image * image) _image = image; _image->retain(); - Node::size(_image->width(), _image->height()); + Node::setSize(_image->getWidth(), _image->getHeight()); return true; } return false; @@ -67,7 +67,7 @@ bool e2d::Sprite::open(const Resource& res) if (_image->open(res)) { - Node::size(_image->width(), _image->height()); + Node::setSize(_image->getWidth(), _image->getHeight()); return true; } return false; @@ -83,45 +83,44 @@ bool e2d::Sprite::open(const String & fileName) if (_image->open(fileName)) { - Node::size(_image->width(), _image->height()); + Node::setSize(_image->getWidth(), _image->getHeight()); return true; } return false; } -e2d::Sprite& e2d::Sprite::crop(const Rect& cropRect) +void e2d::Sprite::crop(const Rect& cropRect) { _image->crop(cropRect); - Node::size( - std::min(std::max(cropRect.size.width, 0.f), _image->realWidth() - _image->cropX()), - std::min(std::max(cropRect.size.height, 0.f), _image->realHeight() - _image->cropY()) + Node::setSize( + std::min(std::max(cropRect.size.width, 0.f), _image->getSourceWidth() - _image->getCropX()), + std::min(std::max(cropRect.size.height, 0.f), _image->getSourceHeight() - _image->getCropY()) ); - return *this; } -e2d::Image * e2d::Sprite::image() const +e2d::Image * e2d::Sprite::getImage() const { return _image; } void e2d::Sprite::draw(Renderer * renderer) const { - if (_image && _image->bitmap()) + if (_image && _image->getBitmap()) { // 获取图片裁剪位置 - float fCropX = _image->cropX(); - float fCropY = _image->cropY(); + float fCropX = _image->getCropX(); + float fCropY = _image->getCropY(); // 渲染图片 - renderer->renderTarget()->DrawBitmap( - _image->bitmap(), - D2D1::RectF(0, 0, _size.width, _size.height), + renderer->getRenderTarget()->DrawBitmap( + _image->getBitmap(), + D2D1::RectF(0, 0, _width, _height), _displayOpacity, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1::RectF( fCropX, fCropY, - fCropX + _size.width, - fCropY + _size.height + fCropX + _width, + fCropY + _height ) ); } diff --git a/core/Node/Text.cpp b/core/Node/Text.cpp index e37c71ba..2f646cc2 100644 --- a/core/Node/Text.cpp +++ b/core/Node/Text.cpp @@ -74,57 +74,57 @@ e2d::Text::~Text() SafeRelease(_textLayout); } -const e2d::String& e2d::Text::text() const +e2d::String e2d::Text::getText() const { return _text; } -const e2d::Font& e2d::Text::font() const +e2d::Font e2d::Text::getFont() const { return _font; } -const e2d::Text::Style& e2d::Text::style() const +e2d::Text::Style e2d::Text::getStyle() const { return _style; } -const e2d::String& e2d::Text::fontFamily() const +e2d::String e2d::Text::getFontFamily() const { return _font.family; } -float e2d::Text::fontSize() const +float e2d::Text::getFontSize() const { return _font.size; } -UINT e2d::Text::fontWeight() const +UINT e2d::Text::getFontWeight() const { return _font.weight; } -const e2d::Color& e2d::Text::color() const +e2d::Color e2d::Text::getColor() const { return _style.color; } -const e2d::Color& e2d::Text::outlineColor() const +e2d::Color e2d::Text::getOutlineColor() const { return _style.outlineColor; } -float e2d::Text::outlineWidth() const +float e2d::Text::getOutlineWidth() const { return _style.outlineWidth; } -e2d::Stroke e2d::Text::outlineStroke() const +e2d::Stroke e2d::Text::getOutlineStroke() const { return _style.outlineStroke; } -int e2d::Text::lineCount() const +int e2d::Text::getLineCount() const { if (_textLayout) { @@ -138,7 +138,7 @@ int e2d::Text::lineCount() const } } -bool e2d::Text::italic() const +bool e2d::Text::isItalic() const { return _font.italic; } @@ -158,72 +158,63 @@ bool e2d::Text::hasOutline() const return _style.hasOutline; } -e2d::Text& e2d::Text::text(const String& text) +void e2d::Text::setText(const String& text) { _text = text; _reset(); - return *this; } -e2d::Text& e2d::Text::style(const Style& style) +void e2d::Text::setStyle(const Style& style) { _style = style; _reset(); - return *this; } -e2d::Text& e2d::Text::font(const Font & font) +void e2d::Text::setFont(const Font & font) { _font = font; _reset(); - return *this; } -e2d::Text& e2d::Text::fontFamily(const String& family) +void e2d::Text::setFontFamily(const String& family) { _font.family = family; _reset(); - return *this; } -e2d::Text& e2d::Text::fontSize(float size) +void e2d::Text::setFontSize(float size) { _font.size = size; _reset(); - return *this; } -e2d::Text& e2d::Text::fontWeight(UINT weight) +void e2d::Text::setFontWeight(UINT weight) { _font.weight = weight; _reset(); - return *this; } -e2d::Text& e2d::Text::color(Color color) +void e2d::Text::setColor(Color color) { _style.color = color; - return *this; } -e2d::Text& e2d::Text::italic(bool value) +void e2d::Text::setItalic(bool value) { _font.italic = value; _reset(); - return *this; } -e2d::Text& e2d::Text::wrapping(bool wrapping) +void e2d::Text::setWrapping(bool wrapping) { if (_style.wrapping != wrapping) { _style.wrapping = wrapping; _reset(); } - return *this; } -e2d::Text& e2d::Text::wrappingWidth(float wrappingWidth) +void e2d::Text::setWrappingWidth(float wrappingWidth) { if (_style.wrappingWidth != wrappingWidth) { @@ -234,30 +225,27 @@ e2d::Text& e2d::Text::wrappingWidth(float wrappingWidth) _reset(); } } - return *this; } -e2d::Text& e2d::Text::lineSpacing(float lineSpacing) +void e2d::Text::setLineSpacing(float lineSpacing) { if (_style.lineSpacing != lineSpacing) { _style.lineSpacing = lineSpacing; _reset(); } - return *this; } -e2d::Text& e2d::Text::alignment(Align align) +void e2d::Text::setAlignment(Align align) { if (_style.alignment != align) { _style.alignment = align; _reset(); } - return *this; } -e2d::Text& e2d::Text::underline(bool hasUnderline) +void e2d::Text::setUnderline(bool hasUnderline) { if (_style.hasUnderline != hasUnderline) { @@ -266,10 +254,9 @@ e2d::Text& e2d::Text::underline(bool hasUnderline) _createFormat(); _createLayout(); } - return *this; } -e2d::Text& e2d::Text::strikethrough(bool hasStrikethrough) +void e2d::Text::setStrikethrough(bool hasStrikethrough) { if (_style.hasStrikethrough != hasStrikethrough) { @@ -278,31 +265,26 @@ e2d::Text& e2d::Text::strikethrough(bool hasStrikethrough) _createFormat(); _createLayout(); } - return *this; } -e2d::Text& e2d::Text::outline(bool hasOutline) +void e2d::Text::setOutline(bool hasOutline) { _style.hasOutline = hasOutline; - return *this; } -e2d::Text& e2d::Text::outlineColor(Color outlineColor) +void e2d::Text::setOutlineColor(Color outlineColor) { _style.outlineColor = outlineColor; - return *this; } -e2d::Text& e2d::Text::outlineWidth(float outlineWidth) +void e2d::Text::setOutlineWidth(float outlineWidth) { _style.outlineWidth = outlineWidth; - return *this; } -e2d::Text& e2d::Text::outlineStroke(Stroke outlineStroke) +void e2d::Text::setOutlineStroke(Stroke outlineStroke) { _style.outlineStroke = outlineStroke; - return *this; } void e2d::Text::draw(Renderer * renderer) const @@ -310,11 +292,11 @@ void e2d::Text::draw(Renderer * renderer) const if (_textLayout) { // 创建文本区域 - D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, _size.width, _size.height); + D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, _width, _height); // 设置画刷颜色和透明度 - renderer->solidBrush()->SetOpacity(_displayOpacity); + renderer->getSolidColorBrush()->SetOpacity(_displayOpacity); // 获取文本渲染器 - auto pTextRenderer = renderer->textRenderer(); + auto pTextRenderer = renderer->getTextRenderer(); pTextRenderer->SetTextStyle( (D2D1_COLOR_F)_style.color, _style.hasOutline, @@ -338,7 +320,7 @@ void e2d::Text::_createFormat() { SafeRelease(_textFormat); - HRESULT hr = Game::instance()->renderer()->writeFactory()->CreateTextFormat( + HRESULT hr = Game::getInstance()->getRenderer()->getWriteFactory()->CreateTextFormat( (const WCHAR *)_font.family, nullptr, DWRITE_FONT_WEIGHT(_font.weight), @@ -389,9 +371,9 @@ void e2d::Text::_createLayout() SafeRelease(_textLayout); // 文本为空字符串时,重置属性 - if (_text.empty()) + if (_text.isEmpty()) { - this->size(0, 0); + this->setSize(0, 0); return; } @@ -403,7 +385,7 @@ void e2d::Text::_createLayout() HRESULT hr; UINT32 length = (UINT32)_text.length(); - auto writeFactory = Game::instance()->renderer()->writeFactory(); + auto writeFactory = Game::getInstance()->getRenderer()->getWriteFactory(); // 对文本自动换行情况下进行处理 if (_style.wrapping) @@ -422,7 +404,7 @@ void e2d::Text::_createLayout() DWRITE_TEXT_METRICS metrics; _textLayout->GetMetrics(&metrics); // 重设文本宽高 - this->size(metrics.layoutWidth, metrics.height); + this->setSize(metrics.layoutWidth, metrics.height); } } else @@ -435,10 +417,10 @@ void e2d::Text::_createLayout() DWRITE_TEXT_METRICS metrics; _textLayout->GetMetrics(&metrics); // 重设文本宽高 - this->size(metrics.width, metrics.height); + this->setSize(metrics.width, metrics.height); // 重新创建 layout SafeRelease(_textLayout); - hr = writeFactory->CreateTextLayout((const WCHAR *)_text, length, _textFormat, _size.width, 0, &_textLayout); + hr = writeFactory->CreateTextLayout((const WCHAR *)_text, length, _textFormat, _width, 0, &_textLayout); } } diff --git a/core/Node/ToggleButton.cpp b/core/Node/ToggleButton.cpp index f51f7729..467db624 100644 --- a/core/Node/ToggleButton.cpp +++ b/core/Node/ToggleButton.cpp @@ -8,7 +8,7 @@ if (Old) this->removeChild(Old); \ if (New) \ { \ - New->anchor(_anchorX, _anchorY); \ + New->setPivot(_pivotX, _pivotY); \ this->addChild(New); \ } \ Old = New; \ @@ -43,9 +43,9 @@ e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, c , _selectedOff(nullptr) , _disabledOff(nullptr) { - this->normal(toggleOnNormal); - this->normalOff(toggleOffNormal); - this->clickCallback(func); + this->setNormal(toggleOnNormal); + this->setNormalOff(toggleOffNormal); + this->setClickFunc(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) , _disabledOff(nullptr) { - this->normal(toggleOnNormal); - this->normalOff(toggleOffNormal); - this->selected(toggleOnSelected); - this->selectedOff(toggleOffSelected); - this->clickCallback(func); + this->setNormal(toggleOnNormal); + this->setNormalOff(toggleOffNormal); + this->setSelected(toggleOnSelected); + this->setSelectedOff(toggleOffSelected); + this->setClickFunc(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) , _disabledOff(nullptr) { - this->normal(toggleOnNormal); - this->normalOff(toggleOffNormal); - this->mouseover(toggleOnMouseOver); - this->mouseOverOff(toggleOffMouseOver); - this->selected(toggleOnSelected); - this->selectedOff(toggleOffSelected); - this->clickCallback(func); + this->setNormal(toggleOnNormal); + this->setNormalOff(toggleOffNormal); + this->setMouseOver(toggleOnMouseOver); + this->setMouseOverOff(toggleOffMouseOver); + this->setSelected(toggleOnSelected); + this->setSelectedOff(toggleOffSelected); + this->setClickFunc(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) , _disabledOff(nullptr) { - this->normal(toggleOnNormal); - this->normalOff(toggleOffNormal); - this->mouseover(toggleOnMouseOver); - this->mouseOverOff(toggleOffMouseOver); - this->selected(toggleOnSelected); - this->selectedOff(toggleOffSelected); - this->disabled(toggleOnDisabled); - this->disabledOff(toggleOffDisabled); - this->clickCallback(func); + this->setNormal(toggleOnNormal); + this->setNormalOff(toggleOffNormal); + this->setMouseOver(toggleOnMouseOver); + this->setMouseOverOff(toggleOffMouseOver); + this->setSelected(toggleOnSelected); + this->setSelectedOff(toggleOffSelected); + this->setDisabled(toggleOnDisabled); + this->setDisabledOff(toggleOffDisabled); + this->setClickFunc(func); } -bool e2d::ToggleButton::checked() const +bool e2d::ToggleButton::isChecked() const { return _checked; } -e2d::ToggleButton& e2d::ToggleButton::checked(bool checked) +void e2d::ToggleButton::setChecked(bool checked) { if (_checked != checked) { @@ -120,73 +120,63 @@ e2d::ToggleButton& e2d::ToggleButton::checked(bool checked) _updateStatus(); _updateVisible(); } - return *this; } -e2d::ToggleButton& e2d::ToggleButton::normal(Node * normal) +void e2d::ToggleButton::setNormal(Node * normal) { SET_BUTTON_NODE(_normalOn, normal); if (normal) { - this->size(normal->width(), normal->height()); + this->setSize(normal->getWidth(), normal->getHeight()); } - return *this; } -e2d::ToggleButton& e2d::ToggleButton::mouseover(Node * mouseover) +void e2d::ToggleButton::setMouseOver(Node * mouseover) { SET_BUTTON_NODE(_mouseoverOn, mouseover); - return *this; } -e2d::ToggleButton& e2d::ToggleButton::selected(Node * selected) +void e2d::ToggleButton::setSelected(Node * selected) { SET_BUTTON_NODE(_selectedOn, selected); - return *this; } -e2d::ToggleButton& e2d::ToggleButton::disabled(Node * disabled) +void e2d::ToggleButton::setDisabled(Node * disabled) { SET_BUTTON_NODE(_disabledOn, disabled); - return *this; } -e2d::ToggleButton& e2d::ToggleButton::normalOff(Node * normal) +void e2d::ToggleButton::setNormalOff(Node * normal) { SET_BUTTON_NODE(_normalOff, normal); - return *this; } -e2d::ToggleButton& e2d::ToggleButton::mouseOverOff(Node * mouseover) +void e2d::ToggleButton::setMouseOverOff(Node * mouseover) { SET_BUTTON_NODE(_mouseoverOff, mouseover); - return *this; } -e2d::ToggleButton& e2d::ToggleButton::selectedOff(Node * selected) +void e2d::ToggleButton::setSelectedOff(Node * selected) { SET_BUTTON_NODE(_selectedOff, selected); - return *this; } -e2d::ToggleButton& e2d::ToggleButton::disabledOff(Node * disabled) +void e2d::ToggleButton::setDisabledOff(Node * disabled) { SET_BUTTON_NODE(_disabledOff, disabled); - return *this; } -e2d::ToggleButton& e2d::ToggleButton::anchor(float anchorX, float anchorY) +void e2d::ToggleButton::setPivot(float pivotX, float pivotY) { - Node::anchor(anchorX, anchorY); - SAFE_SET(_normalOn, anchor, anchorX, anchorY); - SAFE_SET(_mouseoverOn, anchor, anchorX, anchorY); - SAFE_SET(_selectedOn, anchor, anchorX, anchorY); - SAFE_SET(_disabledOn, anchor, anchorX, anchorY); - SAFE_SET(_normalOff, anchor, anchorX, anchorY); - SAFE_SET(_mouseoverOff, anchor, anchorX, anchorY); - SAFE_SET(_selectedOff, anchor, anchorX, anchorY); - SAFE_SET(_disabledOff, anchor, anchorX, anchorY); - return *this; + Node::setPivot(pivotX, pivotY); + SAFE_SET(_normalOn, setPivot, pivotX, pivotY); + SAFE_SET(_mouseoverOn, setPivot, pivotX, pivotY); + SAFE_SET(_selectedOn, setPivot, pivotX, pivotY); + SAFE_SET(_disabledOn, setPivot, pivotX, pivotY); + SAFE_SET(_normalOff, setPivot, pivotX, pivotY); + SAFE_SET(_mouseoverOff, setPivot, pivotX, pivotY); + SAFE_SET(_selectedOff, setPivot, pivotX, pivotY); + SAFE_SET(_disabledOff, setPivot, pivotX, pivotY); } void e2d::ToggleButton::_updateStatus() @@ -198,10 +188,10 @@ void e2d::ToggleButton::_updateStatus() _selected = _selectedOn; _disabled = _disabledOn; - SAFE_SET(_normalOff, visible, false); - SAFE_SET(_mouseoverOff, visible, false); - SAFE_SET(_selectedOff, visible, false); - SAFE_SET(_disabledOff, visible, false); + SAFE_SET(_normalOff, setVisible, false); + SAFE_SET(_mouseoverOff, setVisible, false); + SAFE_SET(_selectedOff, setVisible, false); + SAFE_SET(_disabledOff, setVisible, false); } else { @@ -210,10 +200,10 @@ void e2d::ToggleButton::_updateStatus() _selected = _selectedOff; _disabled = _disabledOff; - SAFE_SET(_normalOn, visible, false); - SAFE_SET(_mouseoverOn, visible, false); - SAFE_SET(_selectedOn, visible, false); - SAFE_SET(_disabledOn, visible, false); + SAFE_SET(_normalOn, setVisible, false); + SAFE_SET(_mouseoverOn, setVisible, false); + SAFE_SET(_selectedOn, setVisible, false); + SAFE_SET(_disabledOn, setVisible, false); } } diff --git a/core/Tool/Data.cpp b/core/Tool/Data.cpp index e6c1c150..bd91dd6e 100644 --- a/core/Tool/Data.cpp +++ b/core/Tool/Data.cpp @@ -4,7 +4,7 @@ e2d::Data::Data(const String & key, const String & field) : _key(key) , _field(field) - , _dataPath(Path::dataPath()) + , _dataPath(Path::getDataPath()) { } @@ -48,7 +48,7 @@ void e2d::Data::saveString(const String& value) ); } -int e2d::Data::toInt(int defaultValue) +int e2d::Data::getInt(int defaultValue) { return ::GetPrivateProfileInt( (LPCWSTR)_field, @@ -58,14 +58,14 @@ int e2d::Data::toInt(int defaultValue) ); } -float e2d::Data::toDouble(float defaultValue) +float e2d::Data::getDouble(float defaultValue) { wchar_t temp[32] = { 0 }; ::GetPrivateProfileString((LPCWSTR)_field, (LPCWSTR)_key, (LPCWSTR)String::parse(defaultValue), temp, 31, (LPCWSTR)_dataPath); return std::stof(temp); } -bool e2d::Data::toBool(bool defaultValue) +bool e2d::Data::getBool(bool defaultValue) { int nValue = ::GetPrivateProfileInt( (LPCWSTR)_field, @@ -75,7 +75,7 @@ bool e2d::Data::toBool(bool defaultValue) return nValue != 0; } -e2d::String e2d::Data::toString(const String& defaultValue) +e2d::String e2d::Data::getString(const String& defaultValue) { wchar_t temp[256] = { 0 }; ::GetPrivateProfileString( diff --git a/core/Tool/File.cpp b/core/Tool/File.cpp index a04ebb05..14d0702d 100644 --- a/core/Tool/File.cpp +++ b/core/Tool/File.cpp @@ -61,16 +61,16 @@ bool e2d::File::isFolder() const return (_attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; } -const e2d::String& e2d::File::path() const +e2d::String e2d::File::getFilePath() const { return _fileName; } -e2d::String e2d::File::ext() const +e2d::String e2d::File::getExtension() const { String fileExtension; // 找到文件名中的最后一个 '.' 的位置 - size_t pos = std::wstring(_fileName).find_last_of(L'.'); + size_t pos = _fileName.getWString().find_last_of(L'.'); // 判断 pos 是否是有效位置 if (pos != std::wstring::npos) { @@ -79,10 +79,10 @@ e2d::String e2d::File::ext() const // 转换为小写字母 fileExtension = fileExtension.toLower(); } - return std::move(fileExtension); + return fileExtension; } -bool e2d::File::del() +bool e2d::File::deleteFile() { if (::DeleteFile((LPCWSTR)_fileName)) return true; @@ -91,7 +91,7 @@ bool e2d::File::del() e2d::File e2d::File::extract(int resNameId, const String & resType, const String& destFileName) { - String destFilePath = Path::tempPath() + destFileName; + String destFilePath = Path::getTempPath() + destFileName; // 创建文件 HANDLE hFile = ::CreateFile((LPCWSTR)destFilePath, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL); if (hFile == INVALID_HANDLE_VALUE) @@ -135,7 +135,7 @@ void e2d::File::addSearchPath(const String & path) bool e2d::File::createFolder(const String & dirPath) { - if (dirPath.empty() || dirPath.length() >= MAX_PATH) + if (dirPath.isEmpty() || dirPath.length() >= MAX_PATH) return false; wchar_t tmpDirPath[_MAX_PATH] = { 0 }; @@ -158,10 +158,10 @@ bool e2d::File::createFolder(const String & dirPath) return true; } -e2d::String e2d::File::openSaveDialog(const String& title, const String& defExt) +e2d::String e2d::File::getSaveFilePath(const String& title, const String& defExt) { - auto window = Game::instance()->window(); - HWND hwnd = window->hWnd(); + auto window = Game::getInstance()->getWindow(); + HWND hwnd = window->getHWnd(); // 弹出保存对话框 OPENFILENAME ofn = { 0 }; diff --git a/core/Tool/Music.cpp b/core/Tool/Music.cpp index 7dd7e157..b29ff1cd 100644 --- a/core/Tool/Music.cpp +++ b/core/Tool/Music.cpp @@ -43,18 +43,18 @@ e2d::Music::XAudio2Tool::~XAudio2Tool() CoUninitialize(); } -e2d::Music::XAudio2Tool* e2d::Music::XAudio2Tool::instance() +e2d::Music::XAudio2Tool* e2d::Music::XAudio2Tool::getInstance() { static XAudio2Tool instance; return &instance; } -IXAudio2 * e2d::Music::XAudio2Tool::xAudio2() +IXAudio2 * e2d::Music::XAudio2Tool::getXAudio2() { return _xAudio2; } -IXAudio2MasteringVoice * e2d::Music::XAudio2Tool::masteringVoice() +IXAudio2MasteringVoice * e2d::Music::XAudio2Tool::getMasteringVoice() { return _masteringVoice; } @@ -70,9 +70,8 @@ e2d::Music::Music() , _dwSize(0) , _voice(nullptr) , _voiceCallback(this) - , _volume(1.f) { - auto xAudio2 = XAudio2Tool::instance()->xAudio2(); + auto xAudio2 = XAudio2Tool::getInstance()->getXAudio2(); xAudio2->AddRef(); } @@ -86,9 +85,8 @@ e2d::Music::Music(const e2d::String & filePath) , _dwSize(0) , _voice(nullptr) , _voiceCallback(this) - , _volume(1.f) { - auto xAudio2 = XAudio2Tool::instance()->xAudio2(); + auto xAudio2 = XAudio2Tool::getInstance()->getXAudio2(); xAudio2->AddRef(); this->open(filePath); @@ -104,9 +102,8 @@ e2d::Music::Music(const Resource& res) , _dwSize(0) , _voice(nullptr) , _voiceCallback(this) - , _volume(1.f) { - auto xAudio2 = XAudio2Tool::instance()->xAudio2(); + auto xAudio2 = XAudio2Tool::getInstance()->getXAudio2(); xAudio2->AddRef(); this->open(res); @@ -116,7 +113,7 @@ e2d::Music::~Music() { close(); - auto xAudio2 = XAudio2Tool::instance()->xAudio2(); + auto xAudio2 = XAudio2Tool::getInstance()->getXAudio2(); xAudio2->Release(); } @@ -127,14 +124,14 @@ bool e2d::Music::open(const e2d::String & filePath) close(); } - if (filePath.empty()) + if (filePath.isEmpty()) { WARN("MusicInfo::open Invalid file name."); return false; } - String actualFilePath = File(filePath).path(); - if (actualFilePath.empty()) + String actualFilePath = File(filePath).getFilePath(); + if (actualFilePath.isEmpty()) { WARN("MusicInfo::open File not found."); return false; @@ -179,7 +176,7 @@ bool e2d::Music::open(const e2d::String & filePath) } // 创建音源 - auto xAudio2 = XAudio2Tool::instance()->xAudio2(); + auto xAudio2 = XAudio2Tool::getInstance()->getXAudio2(); HRESULT hr = xAudio2->CreateSourceVoice(&_voice, _wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &_voiceCallback); if (FAILED(hr)) @@ -258,7 +255,7 @@ bool e2d::Music::open(const Resource& res) } // 创建音源 - auto xAudio2 = XAudio2Tool::instance()->xAudio2(); + auto xAudio2 = XAudio2Tool::getInstance()->getXAudio2(); HRESULT hr = xAudio2->CreateSourceVoice(&_voice, _wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &_voiceCallback); if (FAILED(hr)) @@ -378,7 +375,7 @@ void e2d::Music::close() _playing = false; } -bool e2d::Music::playing() const +bool e2d::Music::isPlaying() const { if (_opened && _voice) { @@ -390,19 +387,13 @@ bool e2d::Music::playing() const } } -float e2d::Music::volume() const -{ - return _volume; -} - -IXAudio2SourceVoice * e2d::Music::sourceVoice() const +IXAudio2SourceVoice * e2d::Music::getIXAudio2SourceVoice() const { return _voice; } -bool e2d::Music::volume(float volume) +bool e2d::Music::setVolume(float volume) { - _volume = volume; if (_voice) { return SUCCEEDED(_voice->SetVolume(volume)); @@ -410,14 +401,14 @@ bool e2d::Music::volume(float volume) return false; } -void e2d::Music::callbackOnEnd(const Function & func) +void e2d::Music::setFuncOnEnd(const Function & func) { - _voiceCallback.SetCallbackOnStreamEnd(func); + _voiceCallback.SetFuncOnStreamEnd(func); } -void e2d::Music::callbackOnLoopEnd(const Function & func) +void e2d::Music::setFuncOnLoopEnd(const Function & func) { - _voiceCallback.SetCallbackOnLoopEnd(func); + _voiceCallback.SetFuncOnLoopEnd(func); } bool e2d::Music::_readMMIO() diff --git a/core/Tool/Path.cpp b/core/Tool/Path.cpp index 5f617b6e..5383139d 100644 --- a/core/Tool/Path.cpp +++ b/core/Tool/Path.cpp @@ -5,17 +5,17 @@ extern "C" const GUID DECLSPEC_SELECTANY FOLDERID_LocalAppData = { }; -const e2d::String& e2d::Path::dataPath() +e2d::String e2d::Path::getDataPath() { static String dataPath; - if (dataPath.empty()) + if (dataPath.isEmpty()) { // 设置数据的保存路径 - String localAppDataPath = Path::localAppDataPath(); - String title = Game::instance()->window()->title(); + String localAppDataPath = Path::getLocalAppDataPath(); + String title = Game::getInstance()->getWindow()->getTitle(); String folderName = String::parse(title.hash()); - if (!localAppDataPath.empty()) + if (!localAppDataPath.isEmpty()) { dataPath = localAppDataPath + L"\\Easy2DGameData\\" << folderName << L"\\"; @@ -30,14 +30,14 @@ const e2d::String& e2d::Path::dataPath() return dataPath; } -const e2d::String& e2d::Path::tempPath() +e2d::String e2d::Path::getTempPath() { static String tempPath; - if (tempPath.empty()) + if (tempPath.isEmpty()) { // 设置临时文件保存路径 wchar_t path[_MAX_PATH]; - String title = Game::instance()->window()->title(); + String title = Game::getInstance()->getWindow()->getTitle(); String folderName = String::parse(title.hash()); if (0 != ::GetTempPath(_MAX_PATH, path)) @@ -54,10 +54,10 @@ const e2d::String& e2d::Path::tempPath() return tempPath; } -const e2d::String& e2d::Path::localAppDataPath() +e2d::String e2d::Path::getLocalAppDataPath() { static String localAppDataPath; - if (localAppDataPath.empty()) + if (localAppDataPath.isEmpty()) { // 获取 AppData/Local 文件夹的路径 typedef HRESULT(WINAPI* pFunSHGetKnownFolderPath)(const GUID& rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath); @@ -77,10 +77,10 @@ const e2d::String& e2d::Path::localAppDataPath() return localAppDataPath; } -const e2d::String& e2d::Path::currentFilePath() +e2d::String e2d::Path::getCurrentFilePath() { static String currFilePath; - if (currFilePath.empty()) + if (currFilePath.isEmpty()) { TCHAR szPath[_MAX_PATH] = { 0 }; if (::GetModuleFileName(nullptr, szPath, _MAX_PATH) != 0) diff --git a/core/Tool/Player.cpp b/core/Tool/Player.cpp index 8b2e4272..bcd89b40 100644 --- a/core/Tool/Player.cpp +++ b/core/Tool/Player.cpp @@ -21,14 +21,14 @@ e2d::Player::~Player() bool e2d::Player::preload(const String & filePath) { - if (filePath.empty()) + if (filePath.isEmpty()) return false; Music * music = new (std::nothrow) Music(); if (music && music->open(filePath)) { - music->volume(_volume); + music->setVolume(_volume); _musicList.insert(std::make_pair(filePath.hash(), music)); return true; } @@ -37,7 +37,7 @@ bool e2d::Player::preload(const String & filePath) bool e2d::Player::play(const String & filePath, int nLoopCount) { - if (filePath.empty()) + if (filePath.isEmpty()) return false; if (Player::preload(filePath)) @@ -53,7 +53,7 @@ bool e2d::Player::play(const String & filePath, int nLoopCount) void e2d::Player::pause(const String & filePath) { - if (filePath.empty()) + if (filePath.isEmpty()) return; size_t hash = filePath.hash(); @@ -63,7 +63,7 @@ void e2d::Player::pause(const String & filePath) void e2d::Player::resume(const String & filePath) { - if (filePath.empty()) + if (filePath.isEmpty()) return; size_t hash = filePath.hash(); @@ -73,7 +73,7 @@ void e2d::Player::resume(const String & filePath) void e2d::Player::stop(const String & filePath) { - if (filePath.empty()) + if (filePath.isEmpty()) return; size_t hash = filePath.hash(); @@ -81,14 +81,14 @@ void e2d::Player::stop(const String & filePath) _musicList[hash]->stop(); } -bool e2d::Player::playing(const String & filePath) +bool e2d::Player::isPlaying(const String & filePath) { - if (filePath.empty()) + if (filePath.isEmpty()) return false; size_t hash = filePath.hash(); if (_musicList.end() != _musicList.find(hash)) - return _musicList[hash]->playing(); + return _musicList[hash]->isPlaying(); return false; } @@ -101,7 +101,7 @@ bool e2d::Player::preload(const Resource& res) if (music && music->open(res)) { - music->volume(_volume); + music->setVolume(_volume); _musicList.insert(std::make_pair(res.resNameId, music)); return true; } @@ -139,24 +139,24 @@ void e2d::Player::stop(const Resource& res) _musicList[res.resNameId]->stop(); } -bool e2d::Player::playing(const Resource& res) const +bool e2d::Player::isPlaying(const Resource& res) { if (_musicList.end() != _musicList.find(res.resNameId)) - return _musicList.at(res.resNameId)->playing(); + return _musicList[res.resNameId]->isPlaying(); return false; } -float e2d::Player::volume() const +float e2d::Player::getVolume() { return _volume; } -void e2d::Player::volume(float volume) +void e2d::Player::setVolume(float volume) { _volume = std::min(std::max(volume, -224.f), 224.f); for (const auto& pair : _musicList) { - pair.second->volume(_volume); + pair.second->setVolume(_volume); } } diff --git a/core/Tool/Random.cpp b/core/Tool/Random.cpp index 7f0fc1a8..ca65fac9 100644 --- a/core/Tool/Random.cpp +++ b/core/Tool/Random.cpp @@ -1,6 +1,6 @@ #include "..\e2dtool.h" -std::default_random_engine &e2d::Random::__engine() +std::default_random_engine &e2d::Random::__getEngine() { static std::random_device device; static std::default_random_engine engine(device()); diff --git a/core/Tool/Task.cpp b/core/Tool/Task.cpp index b9d842c7..17b1a53c 100644 --- a/core/Tool/Task.cpp +++ b/core/Tool/Task.cpp @@ -78,7 +78,7 @@ bool e2d::Task::isRunning() const return _running; } -e2d::String e2d::Task::name() const +e2d::String e2d::Task::getName() const { return _name; } diff --git a/core/Tool/Timer.cpp b/core/Tool/Timer.cpp index bdfcb807..29a6f859 100644 --- a/core/Tool/Timer.cpp +++ b/core/Tool/Timer.cpp @@ -1,7 +1,7 @@ #include "..\e2dtool.h" -e2d::Timer * e2d::Timer::instance() +e2d::Timer * e2d::Timer::getInstance() { static Timer instance; return &instance; @@ -34,7 +34,7 @@ void e2d::Timer::stopTasks(const String& name) { for (const auto& task : _tasks) { - if (task->name() == name) + if (task->getName() == name) { task->stop(); } @@ -45,7 +45,7 @@ void e2d::Timer::startTasks(const String& name) { for (const auto& task : _tasks) { - if (task->name() == name) + if (task->getName() == name) { task->start(); } @@ -56,7 +56,7 @@ void e2d::Timer::removeTasks(const String& name) { for (const auto& task : _tasks) { - if (task->name() == name) + if (task->getName() == name) { task->_stopped = true; } diff --git a/core/Transition/MoveTransition.cpp b/core/Transition/MoveTransition.cpp index 4e5647c4..208dbcbb 100644 --- a/core/Transition/MoveTransition.cpp +++ b/core/Transition/MoveTransition.cpp @@ -34,8 +34,8 @@ bool e2d::MoveTransition::_init(Game * game, Scene * prev) _startPos = Point(-width, 0); } - if (_outScene) _outScene->position(0, 0); - _inScene->position(_startPos); + if (_outScene) _outScene->setPos(0, 0); + _inScene->setPos(_startPos); return true; } return false; @@ -47,11 +47,11 @@ void e2d::MoveTransition::_update() if (_outScene) { - _outScene->position(_posDelta * _delta); + _outScene->setPos(_posDelta * _delta); } if (_inScene) { - _inScene->position(_startPos + _posDelta * _delta); + _inScene->setPos(_startPos + _posDelta * _delta); } if (_delta >= 1) @@ -62,6 +62,6 @@ void e2d::MoveTransition::_update() void e2d::MoveTransition::_reset() { - if (_outScene) _outScene->position(0, 0); - _inScene->position(0, 0); + if (_outScene) _outScene->setPos(0, 0); + _inScene->setPos(0, 0); } diff --git a/core/Transition/Transition.cpp b/core/Transition/Transition.cpp index 86ace071..cf7b5f51 100644 --- a/core/Transition/Transition.cpp +++ b/core/Transition/Transition.cpp @@ -22,11 +22,11 @@ e2d::Transition::~Transition() { SafeRelease(_outLayer); SafeRelease(_inLayer); - GC::instance()->safeRelease(_outScene); - GC::instance()->safeRelease(_inScene); + GC::getInstance()->safeRelease(_outScene); + GC::getInstance()->safeRelease(_inScene); } -bool e2d::Transition::done() +bool e2d::Transition::isDone() { return _end; } @@ -40,15 +40,15 @@ bool e2d::Transition::_init(Game * game, Scene * prev) _outScene->retain(); HRESULT hr = S_OK; - auto renderer = game->renderer(); + auto renderer = game->getRenderer(); if (_inScene) { - hr = renderer->renderTarget()->CreateLayer(&_inLayer); + hr = renderer->getRenderTarget()->CreateLayer(&_inLayer); } if (SUCCEEDED(hr) && _outScene) { - hr = renderer->renderTarget()->CreateLayer(&_outLayer); + hr = renderer->getRenderTarget()->CreateLayer(&_outLayer); } if (FAILED(hr)) @@ -56,14 +56,14 @@ bool e2d::Transition::_init(Game * game, Scene * prev) return false; } - _windowSize = game->window()->size(); + _windowSize = game->getWindow()->getSize(); _outLayerParam = _inLayerParam = D2D1::LayerParameters( D2D1::InfiniteRect(), nullptr, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, D2D1::Matrix3x2F::Identity(), 1.f, - renderer->solidBrush(), + renderer->getSolidColorBrush(), D2D1_LAYER_OPTIONS_NONE ); @@ -85,11 +85,11 @@ void e2d::Transition::_update() void e2d::Transition::_render(Game * game) { - auto renderTarget = game->renderer()->renderTarget(); + auto renderTarget = game->getRenderer()->getRenderTarget(); if (_outScene) { - Point rootPos = _outScene->position(); + Point rootPos = _outScene->getPos(); auto clipRect = D2D1::RectF( std::max(rootPos.x, 0.f), std::max(rootPos.y, 0.f), @@ -108,7 +108,7 @@ void e2d::Transition::_render(Game * game) if (_inScene) { - Point rootPos = _inScene->position(); + Point rootPos = _inScene->getPos(); auto clipRect = D2D1::RectF( std::max(rootPos.x, 0.f), std::max(rootPos.y, 0.f), diff --git a/core/e2daction.h b/core/e2daction.h index 4425054e..fa6352db 100644 --- a/core/e2daction.h +++ b/core/e2daction.h @@ -40,10 +40,10 @@ public: virtual void stop(); // 获取动作名称 - virtual const String& name() const; + virtual String getName() const; // 设置动作名称 - virtual void name( + virtual void setName( const String& name ); @@ -57,7 +57,7 @@ public: virtual void reset(); // 获取该动作的执行目标 - virtual Node * target(); + virtual Node * getTarget(); protected: E2D_DISABLE_COPY(Action); @@ -716,25 +716,25 @@ public: virtual ~Animation(); // 添加关键帧 - Animation& add( + void add( Image * frame /* 关键帧 */ ); // 添加多个关键帧 - Animation& add( + void add( const std::vector& frames /* 关键帧列表 */ ); - // 设置每一帧的时间间隔 - Animation& interval( - float interval /* 帧间隔(秒) */ - ); - // 获取帧间隔 - float interval() const; + float getInterval() const; // 获取关键帧 - const std::vector& frames() const; + const std::vector& getFrames() const; + + // 设置每一帧的时间间隔 + void setInterval( + float interval /* 帧间隔(秒) */ + ); // 获取帧动画的拷贝对象 Animation * clone() const; @@ -765,10 +765,10 @@ public: virtual ~Animate(); // 获取动画 - Animation * animation() const; + virtual Animation * getAnimation() const; // 设置动画 - void animation( + virtual void setAnimation( Animation * animation ); diff --git a/core/e2dbase.h b/core/e2dbase.h index 2e3086a0..f293686f 100644 --- a/core/e2dbase.h +++ b/core/e2dbase.h @@ -48,51 +48,51 @@ public: ); // 修改窗体大小 - Window& size( + void setSize( int width, /* 窗体宽度 */ int height /* 窗体高度 */ ); // 设置窗体标题 - Window& title( + void setTitle( const String& title /* 窗体标题 */ ); // 设置窗体图标 - Window& icon( + void setIcon( int iconID ); // 设置鼠标指针样式 - Window& cursor( - Cursor c + void setCursor( + Cursor cursor ); // 获取窗体标题 - const String& title() const; + String getTitle() const; // 获取窗体宽度 - int width() const; + int getWidth() const; // 获取窗体高度 - int height() const; + int getHeight() const; // 获取窗体大小 - Size size() const; + Size getSize() const; // 获取窗口 DPI - float dpi() const; + float getDpi() const; // 获取窗口句柄 - HWND hWnd() const; + HWND getHWnd() const; // 打开或隐藏控制台 - Window& showConsole( + void setConsoleEnabled( bool enabled ); // 是否允许响应输入法 - Window& typewritingEnabled( + void setTypewritingEnabled( bool enabled ); @@ -153,22 +153,22 @@ public: ); // 获得鼠标X轴坐标值 - float mouseX(); + float getMouseX(); // 获得鼠标Y轴坐标值 - float mouseY(); + float getMouseY(); // 获得鼠标坐标值 - Point mousePos(); + Point getMousePos(); // 获得鼠标X轴坐标增量 - float mouseDeltaX(); + float getMouseDeltaX(); // 获得鼠标Y轴坐标增量 - float mouseDeltaY(); + float getMouseDeltaY(); // 获得鼠标Z轴(鼠标滚轮)坐标增量 - float mouseDeltaZ(); + float getMouseDeltaZ(); // 初始化输入设备 void initWithWindow( @@ -196,11 +196,11 @@ public: ~Renderer(); // 获取背景色 - Color backgroundColor(); + Color getBackgroundColor(); // 修改背景色 - void backgroundColor( - const Color& color + void setBackgroundColor( + Color color ); // 显示或隐藏 FPS @@ -210,31 +210,31 @@ public: ); // 获取文字渲染器 - TextRenderer * textRenderer() const { return _textRenderer; } + TextRenderer * getTextRenderer() const { return _textRenderer; } // 获取 ID2D1HwndRenderTarget 对象 - ID2D1HwndRenderTarget * renderTarget() const { return _renderTarget; } + ID2D1HwndRenderTarget * getRenderTarget() const { return _renderTarget; } // 获取 ID2D1SolidColorBrush 对象 - ID2D1SolidColorBrush * solidBrush() const { return _solidBrush; } + ID2D1SolidColorBrush * getSolidColorBrush() const { return _solidBrush; } // 获取 ID2D1Factory 对象 - ID2D1Factory * factory() const { return _factory; } + ID2D1Factory * getFactory() const { return _factory; } // 获取 IWICImagingFactory 对象 - IWICImagingFactory * imagingFactory() const { return _imagingFactory; } + IWICImagingFactory * getImagingFactory() const { return _imagingFactory; } // 获取 IDWriteFactory 对象 - IDWriteFactory * writeFactory() const { return _writeFactory; } + IDWriteFactory * getWriteFactory() const { return _writeFactory; } // 获取 Miter 样式的 ID2D1StrokeStyle - ID2D1StrokeStyle * miterStrokeStyle(); + ID2D1StrokeStyle * getMiterStrokeStyle(); // 获取 Bevel 样式的 ID2D1StrokeStyle - ID2D1StrokeStyle * bevelStrokeStyle(); + ID2D1StrokeStyle * getBevelStrokeStyle(); // 获取 Round 样式的 ID2D1StrokeStyle - ID2D1StrokeStyle * roundStrokeStyle(); + ID2D1StrokeStyle * getRoundStrokeStyle(); // 初始化渲染器 void initWithWindow( @@ -276,7 +276,7 @@ class Game { public: // 获取 Game 实例 - static Game * instance(); + static Game * getInstance(); // 初始化 void initWithWindow( @@ -284,13 +284,13 @@ public: ); // 获取窗体 - Window * window() const { return _window; } + Window * getWindow() const { return _window; } // 获取输入设备 - Input * input() const { return _input; } + Input * getInput() const { return _input; } // 获取图形设备 - Renderer * renderer() const { return _renderer; } + Renderer * getRenderer() const { return _renderer; } // 启动游戏 void start(); @@ -305,7 +305,7 @@ public: void quit(); // 游戏是否暂停 - bool paused(); + bool isPaused(); // 场景入栈 void pushScene( @@ -331,13 +331,13 @@ public: void clearAllScenes(); // 获取当前场景 - Scene * currentScene(); + Scene * getCurrentScene(); // 获取场景栈 - const std::stack& sceneStack(); + const std::stack& getSceneStack(); // 是否正在进行场景动画 - bool transitioning() const; + bool isTransitioning() const; // 更新场景内容 void updateScene(); @@ -372,7 +372,7 @@ class GC { public: // 获取 GC 实例 - static GC * instance(); + static GC * getInstance(); // 自动释放 void autorelease( diff --git a/core/e2dcommon.h b/core/e2dcommon.h index cbc498cd..249846b4 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -103,6 +103,14 @@ public: bool operator== (const Rect& rect) const; + // 设置矩形 + void setRect( + float x, + float y, + float width, + float height + ); + // 判断点是否在矩形内 bool containsPoint( const Point& point @@ -134,7 +142,13 @@ public: size_t hash() const; // 判断字符串是否为空 - bool empty() const; + bool isEmpty() const; + + // 获取 Unicode 字符串 + std::wstring getWString() const; + + // 获取 ANSI 字符串 + std::string getCString() const; // 获取指定位置字符 wchar_t at( @@ -230,8 +244,6 @@ public: // 类型转换操作符 E2D_OP_EXPLICIT operator const 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; @@ -507,10 +519,10 @@ public: Time(); // 获取时间戳 - time_t stamp() const; + time_t getTimeStamp() const; - // 是否是零点 - bool zero() const; + // 是否是 + bool isZero() const; Time operator + (Duration const &) const; Time operator - (Duration const &) const; @@ -597,55 +609,55 @@ public: virtual ~Collider(); // 设置碰撞体形状 - Collider& shape( + void setShape( Shape shape ); // 是否触发碰撞事件 - Collider& notify( + void setCollisionNotify( bool notify ); // 启用或关闭该碰撞体 - Collider& enabled( + void setEnabled( bool enabled ); // 设置碰撞体的可见性 - Collider& visible( + void setVisible( bool visible ); // 设置绘制颜色 - Collider& color( + void setColor( Color color ); // 判断两碰撞体的交集关系 - Relation relationWith( + Relation getRelationWith( Collider * pCollider ) const; // 是否启用碰撞体 - bool enabled() const; + bool isEnabled() const; // 是否可见 - bool visible() const; + bool isVisible() const; // 是否触发碰撞事件 - bool notify() const; + bool isCollisionNotify() const; // 获取绘制颜色 - Color color() const; + Color getColor() const; // 获取形状 - Shape shape() const; + Shape getShape() const; // 获取绑定节点 - Node* node() const; + Node* getNode() const; // 获取 ID2D1Geometry* 对象 - ID2D1Geometry* geometry() const; + ID2D1Geometry* getGeometry() const; // 重新生成 void recreate(); @@ -697,7 +709,7 @@ public: void release(); // 获取引用计数 - int refCount() const; + int getRefCount() const; protected: E2D_DISABLE_COPY(Ref); @@ -750,34 +762,34 @@ public: ); // 获取宽度 - float width() const; + virtual float getWidth() const; // 获取高度 - float height() const; + virtual float getHeight() const; // 获取大小 - const Size& size() const; + virtual Size getSize() const; - // 获取图片实际宽度 - float realWidth() const; + // 获取源图片宽度 + virtual float getSourceWidth() const; - // 获取图片实际高度 - float realHeight() const; + // 获取源图片高度 + virtual float getSourceHeight() const; - // 获取图片实际大小 - Size realSize() const; + // 获取源图片大小 + virtual Size getSourceSize() const; // 获取裁剪位置 X 坐标 - float cropX() const; + virtual float getCropX() const; // 获取裁剪位置 Y 坐标 - float cropY() const; + virtual float getCropY() const; // 获取裁剪位置 - const Point& cropPosition() const; + virtual Point getCropPos() const; // 获取 ID2D1Bitmap 对象 - ID2D1Bitmap * bitmap(); + ID2D1Bitmap * getBitmap(); // 预加载图片资源 static bool preload( diff --git a/core/e2dcustom.h b/core/e2dcustom.h index b4032f3b..1bdde289 100644 --- a/core/e2dcustom.h +++ b/core/e2dcustom.h @@ -44,11 +44,11 @@ public: HRESULT Error ); - void SetCallbackOnStreamEnd( + void SetFuncOnStreamEnd( const Function& func ); - void SetCallbackOnLoopEnd( + void SetFuncOnLoopEnd( const Function& func ); diff --git a/core/e2devent.h b/core/e2devent.h index a3763009..abc0835b 100644 --- a/core/e2devent.h +++ b/core/e2devent.h @@ -25,13 +25,13 @@ public: ); // 获取按键键值 - KeyCode code() const; + KeyCode getCode() const; // 获取按键次数 - int count() const; + int getCount() const; // 获取事件类型 - KeyEvent::Type type() const; + KeyEvent::Type getType() const; // VK 键值转换 static KeyCode convertKeyCode( @@ -75,18 +75,18 @@ public: ); // 获取鼠标横坐标 - float positionX() const; + float getX() const; // 获取鼠标纵坐标 - float positionY() const; + float getY() const; // 获取鼠标坐标 - Point position() const; + Point getPos() const; // 获取事件类型 - MouseEvent::Type type() const; + MouseEvent::Type getType() const; - float wheelDelta() const; + float getWheelDelta() const; // 鼠标左键是否按下 bool isLButtonDown() const; @@ -126,10 +126,10 @@ public: ~Collision(); // 获取发生碰撞节点 - Node* node() const; + Node* getNode() const; // 获取交集关系 - Collider::Relation relation() const; + Collider::Relation getRelation() const; protected: Node * _node; diff --git a/core/e2dmanager.h b/core/e2dmanager.h index ef321708..0f6ada8d 100644 --- a/core/e2dmanager.h +++ b/core/e2dmanager.h @@ -16,15 +16,15 @@ class ActionManager public: // 获取动作管理器实例 - static ActionManager * instance(); + static ActionManager * getInstance(); // 获取所有名称相同的动作 - std::vector actions( + std::vector get( const String& name ); // 获取所有动作 - const std::vector& actions(); + const std::vector& getAll(); // 执行动作 void start( @@ -108,11 +108,11 @@ class CollisionManager public: // 获取碰撞体管理器实例 - static CollisionManager * instance(); + static CollisionManager * getInstance(); // 打开或关闭碰撞监听 // 默认:关闭 - void enabled( + void setCollisionEnabled( bool enabled ); diff --git a/core/e2dnode.h b/core/e2dnode.h index c1cbe01f..67227ff3 100644 --- a/core/e2dnode.h +++ b/core/e2dnode.h @@ -32,7 +32,7 @@ class KeyEventHandler { public: // 处理按键消息 - virtual void handle(const KeyEvent& e) = 0; + virtual void handle(KeyEvent e) = 0; }; @@ -41,7 +41,7 @@ class MouseEventHandler { public: // 处理鼠标消息 - virtual void handle(const MouseEvent& e) = 0; + virtual void handle(MouseEvent e) = 0; }; @@ -50,7 +50,7 @@ class CollisionHandler { public: // 处理碰撞消息 - virtual void handle(const Collision& collision) = 0; + virtual void handle(Collision collision) = 0; }; @@ -64,10 +64,12 @@ public: // 节点属性 struct Property { - Point position; // 坐标 - Size size; // 大小 - float anchorX; // 锚点 X 坐标 - float anchorY; // 锚点 Y 坐标 + float posX; // X 坐标 + float posY; // Y 坐标 + float width; // 宽度 + float height; // 高度 + float pivotX; // 中心点 X 坐标 + float pivotY; // 中心点 Y 坐标 float scaleX; // 横向缩放 float scaleY; // 纵向缩放 float rotation; // 旋转角度 @@ -86,285 +88,7 @@ public: virtual ~Node(); // 获取节点显示状态 - virtual bool visible() const; - - // 获取节点名称 - const String& name() const; - - // 获取节点名称的 Hash 值 - size_t hashName() const; - - // 获取节点绘图顺序 - int order() const; - - // 获取节点横坐标 - float positionX() const; - - // 获取节点纵坐标 - float positionY() const; - - // 获取节点坐标 - const Point& position() const; - - // 获取节点宽度 - float width() const; - - // 获取节点高度 - float height() const; - - // 获取节点大小 - Size size() const; - - // 获取节点实际宽度(不考虑缩放) - float realWidth() const; - - // 获取节点实际高度(不考虑缩放) - float realHeight() const; - - // 获取节点实际大小(不考虑缩放) - const Size& realSize() const; - - // 获取节点的锚点 - float anchorX() const; - - // 获取节点的锚点 - float anchorY() const; - - // 获取节点横向缩放比例 - float scaleX() const; - - // 获取节点纵向缩放比例 - float scaleY() const; - - // 获取节点横向倾斜角度 - float skewX() const; - - // 获取节点纵向倾斜角度 - float skewY() const; - - // 获取节点旋转角度 - float rotation() const; - - // 获取节点透明度 - float opacity() const; - - // 获取节点属性 - Property properties() const; - - // 获取差别属性 - Property extrapolate() const; - - // 设置节点是否显示 - Node& visible( - bool value - ); - - // 设置节点名称 - Node& name( - const String& name - ); - - // 设置节点横坐标 - virtual Node& positionX( - float x - ); - - // 设置节点纵坐标 - virtual Node& positionY( - float y - ); - - // 设置节点坐标 - virtual Node& position( - const Point & point - ); - - // 设置节点坐标 - virtual Node& position( - float x, - float y - ); - - // 节点坐标固定 - virtual Node& positionFixed( - bool fixed - ); - - // 移动节点 - virtual Node& move( - float x, - float y - ); - - // 移动节点 - virtual Node& move( - const Vector2 & v - ); - - // 设置节点绘图顺序 - // 默认为 0 - virtual Node& order( - int order - ); - - // 设置横向缩放比例 - // 默认为 1.0 - virtual Node& scaleX( - float scaleX - ); - - // 设置纵向缩放比例 - // 默认为 1.0 - virtual Node& scaleY( - float scaleY - ); - - // 设置缩放比例 - // 默认为 (1.0, 1.0) - virtual Node& scale( - float scaleX, - float scaleY - ); - - // 设置缩放比例 - // 默认为 1.0 - virtual Node& scale( - float scale - ); - - // 设置横向倾斜角度 - // 默认为 0 - virtual Node& skewX( - float angleX - ); - - // 设置纵向倾斜角度 - // 默认为 0 - virtual Node& skewY( - float angleY - ); - - // 设置倾斜角度 - // 默认为 (0, 0) - virtual Node& skew( - float angleX, - float angleY - ); - - // 设置旋转角度 - // 默认为 0 - virtual Node& rotation( - float rotation - ); - - // 设置透明度 - // 默认为 1.0, 范围 [0, 1] - virtual Node& opacity( - float opacity - ); - - // 设置锚点的横向位置 - // 默认为 0, 范围 [0, 1] - virtual Node& anchorX( - float anchorX - ); - - // 设置锚点的纵向位置 - // 默认为 0, 范围 [0, 1] - virtual Node& anchorY( - float anchorY - ); - - // 设置锚点位置 - // 默认为 (0, 0), 范围 [0, 1] - virtual Node& anchor( - float anchorX, - float anchorY - ); - - // 修改节点宽度 - virtual Node& width( - float width - ); - - // 修改节点高度 - virtual Node& height( - float height - ); - - // 修改节点大小 - virtual Node& size( - float width, - float height - ); - - // 修改节点大小 - virtual Node& size( - Size size - ); - - // 设置节点属性 - virtual Node& properties( - Property prop - ); - - // 启用或关闭渲染区域裁剪 - virtual Node& clipEnabled( - bool enabled - ); - - // 添加子节点 - Node& addChild( - Node * child, - int order = 0 /* 渲染顺序 */ - ); - - // 添加多个子节点 - Node& addChild( - const std::vector& nodes, /* 节点数组 */ - int order = 0 /* 渲染顺序 */ - ); - - // 获取节点碰撞体 - Collider * collider(); - - // 获取父节点 - Node * parent() const; - - // 获取节点所在场景 - Scene * parentScene() const; - - // 获取名称相同的子节点 - Node* child( - const String& name - ) const; - - // 获取所有子节点 - const std::vector& children() const; - - // 获取所有名称相同的子节点 - std::vector children( - const String& name - ) const; - - // 获取子节点数量 - int childrenCount() const; - - // 移除子节点 - Node& removeChild( - Node * child - ); - - // 移除所有名称相同的子节点 - Node& removeChildren( - const String& childName - ); - - // 移除所有节点 - Node& removeAllChildren(); - - // 从父节点移除 - Node& removeFromParent(); + virtual bool isVisible() const; // 判断点是否在节点内 bool containsPoint( @@ -376,34 +100,322 @@ public: Node * node ); + // 获取节点名称 + String getName() const; + + // 获取节点名称的 Hash 值 + size_t getHashName() const; + + // 获取节点绘图顺序 + int getOrder() const; + + // 获取节点横坐标 + float getPosX() const; + + // 获取节点纵坐标 + float getPosY() const; + + // 获取节点坐标 + Point getPos() const; + + // 获取节点宽度 + float getWidth() const; + + // 获取节点高度 + float getHeight() const; + + // 获取节点宽度(不考虑缩放) + float getRealWidth() const; + + // 获取节点高度(不考虑缩放) + float getRealHeight() const; + + // 获取节点大小(不考虑缩放) + Size getRealSize() const; + + // 获取节点的中心点 + float getPivotX() const; + + // 获取节点的中心点 + float getPivotY() const; + + // 获取节点大小 + Size getSize() const; + + // 获取节点横向缩放比例 + float getScaleX() const; + + // 获取节点纵向缩放比例 + float getScaleY() const; + + // 获取节点横向倾斜角度 + float getSkewX() const; + + // 获取节点纵向倾斜角度 + float getSkewY() const; + + // 获取节点旋转角度 + float getRotation() const; + + // 获取节点透明度 + float getOpacity() const; + + // 获取节点属性 + Property getProperty() const; + + // 获取差别属性 + Property getExtrapolate() const; + + // 获取节点碰撞体 + Collider * getCollider(); + + // 获取父节点 + Node * getParent() const; + + // 获取节点所在场景 + Scene * getParentScene() const; + + // 获取所有名称相同的子节点 + std::vector getChildren( + const String& name + ) const; + + // 获取名称相同的子节点 + Node* getChild( + const String& name + ) const; + + // 获取所有子节点 + const std::vector& getAllChildren() const; + + // 获取子节点数量 + int getChildrenCount() const; + + // 移除子节点 + bool removeChild( + Node * child + ); + + // 移除所有名称相同的子节点 + void removeChildren( + const String& childName + ); + + // 移除所有节点 + void removeAllChildren(); + + // 从父节点移除 + void removeFromParent(); + + // 设置节点是否显示 + void setVisible( + bool value + ); + + // 设置节点名称 + void setName( + const String& name + ); + + // 设置节点横坐标 + virtual void setPosX( + float x + ); + + // 设置节点纵坐标 + virtual void setPosY( + float y + ); + + // 设置节点坐标 + virtual void setPos( + const Point & point + ); + + // 设置节点坐标 + virtual void setPos( + float x, + float y + ); + + // 节点坐标固定 + virtual void setPosFixed( + bool fixed + ); + + // 移动节点 + virtual void movePosX( + float x + ); + + // 移动节点 + virtual void movePosY( + float y + ); + + // 移动节点 + virtual void movePos( + float x, + float y + ); + + // 移动节点 + virtual void movePos( + const Vector2 & v + ); + + // 设置节点绘图顺序 + // 默认为 0 + virtual void setOrder( + int order + ); + + // 设置横向缩放比例 + // 默认为 1.0 + virtual void setScaleX( + float scaleX + ); + + // 设置纵向缩放比例 + // 默认为 1.0 + virtual void setScaleY( + float scaleY + ); + + // 设置缩放比例 + // 默认为 (1.0, 1.0) + virtual void setScale( + float scaleX, + float scaleY + ); + + // 设置缩放比例 + // 默认为 1.0 + virtual void setScale( + float scale + ); + + // 设置横向倾斜角度 + // 默认为 0 + virtual void setSkewX( + float angleX + ); + + // 设置纵向倾斜角度 + // 默认为 0 + virtual void setSkewY( + float angleY + ); + + // 设置倾斜角度 + // 默认为 (0, 0) + virtual void setSkew( + float angleX, + float angleY + ); + + // 设置旋转角度 + // 默认为 0 + virtual void setRotation( + float rotation + ); + + // 设置透明度 + // 默认为 1.0, 范围 [0, 1] + virtual void setOpacity( + float opacity + ); + + // 设置中心点的横向位置 + // 默认为 0, 范围 [0, 1] + virtual void setPivotX( + float pivotX + ); + + // 设置中心点的纵向位置 + // 默认为 0, 范围 [0, 1] + virtual void setPivotY( + float pivotY + ); + + // 设置中心点位置 + // 默认为 (0, 0), 范围 [0, 1] + virtual void setPivot( + float pivotX, + float pivotY + ); + + // 修改节点宽度 + virtual void setWidth( + float width + ); + + // 修改节点高度 + virtual void setHeight( + float height + ); + + // 修改节点大小 + virtual void setSize( + float width, + float height + ); + + // 修改节点大小 + virtual void setSize( + Size size + ); + + // 设置节点属性 + virtual void setProperty( + Property prop + ); + + // 启用或关闭渲染区域裁剪 + virtual void setClipEnabled( + bool enabled + ); + + // 添加子节点 + void addChild( + Node * child, + int order = 0 /* 渲染顺序 */ + ); + + // 添加多个子节点 + void addChild( + const std::vector& nodes, /* 节点数组 */ + int order = 0 /* 渲染顺序 */ + ); + // 执行动作 - Node& runAction( + void runAction( Action * action ); // 继续动作 - Node& resumeAction( + void resumeAction( const String& name ); // 暂停动作 - Node& pauseAction( + void pauseAction( const String& name ); // 停止动作 - Node& stopAction( + void stopAction( const String& name ); // 继续所有暂停动作 - Node& resumeAllActions(); + void resumeAllActions(); // 暂停所有动作 - Node& pauseAllActions(); + void pauseAllActions(); // 停止所有动作 - Node& stopAllActions(); + void stopAllActions(); // 分发鼠标消息 virtual bool dispatch( @@ -450,8 +462,10 @@ protected: protected: String _name; size_t _hashName; - Point _position; - Size _size; + float _posX; + float _posY; + float _width; + float _height; float _scaleX; float _scaleY; float _rotation; @@ -459,8 +473,8 @@ protected: float _skewAngleY; float _displayOpacity; float _realOpacity; - float _anchorX; - float _anchorY; + float _pivotX; + float _pivotY; int _order; bool _visible; bool _clipEnabled; @@ -498,13 +512,13 @@ public: // 显示或隐藏节点轮廓 // 默认:隐藏 - Scene& outlineVisible( + void setOutlineVisible( bool visible ); // 打开或关闭碰撞体可视化 // 默认:关闭 - Scene& colliderVisible( + void setColliderVisible( bool visible ); @@ -570,12 +584,12 @@ public: ); // 将图片裁剪为矩形 - Sprite& crop( + void crop( const Rect& cropRect /* 裁剪矩形 */ ); // 获取 Image 对象 - Image * image() const; + virtual Image * getImage() const; // 渲染精灵 virtual void draw( @@ -650,40 +664,40 @@ public: virtual ~Text(); // 获取文本 - const String& text() const; + String getText() const; // 获取字体 - const Font& font() const; + Font getFont() const; // 获取文本样式 - const Style& style() const; + Style getStyle() const; // 获取字体族 - const String& fontFamily() const; + String getFontFamily() const; // 获取当前字号 - float fontSize() const; + float getFontSize() const; // 获取当前字体粗细值 - UINT fontWeight() const; + UINT getFontWeight() const; // 获取文字颜色 - const Color& color() const; + Color getColor() const; // 获取描边颜色 - const Color& outlineColor() const; + Color getOutlineColor() const; // 获取描边线宽 - float outlineWidth() const; + float getOutlineWidth() const; // 获取描边线相交样式 - Stroke outlineStroke() const; + Stroke getOutlineStroke() const; // 获取文本显示行数 - int lineCount() const; + int getLineCount() const; // 是否是斜体 - bool italic() const; + bool isItalic() const; // 是否显示删除线 bool hasStrikethrough() const; @@ -695,92 +709,92 @@ public: bool hasOutline() const; // 设置文本 - Text& text( + void setText( const String& text ); // 设置文本样式 - Text& style( + void setStyle( const Style& style ); // 设置字体 - Text& font( + void setFont( const Font& font ); // 设置字体族 - Text& fontFamily( + void setFontFamily( const String& family ); // 设置字号(默认值为 22) - Text& fontSize( + void setFontSize( float size ); // 设置字体粗细值(默认值为 Text::Font::Weight::Normal) - Text& fontWeight( + void setFontWeight( UINT weight ); // 设置文字颜色(默认值为 Color::WHITE) - Text& color( + void setColor( Color color ); // 设置文字斜体(默认值为 false) - Text& italic( + void setItalic( bool value ); // 打开或关闭文本自动换行(默认为关闭) - Text& wrapping( + void setWrapping( bool wrapping ); // 设置文本自动换行的宽度(默认为 0) - Text& wrappingWidth( + void setWrappingWidth( float wrappingWidth ); // 设置行间距(默认为 0) - Text& lineSpacing( + void setLineSpacing( float lineSpacing ); // 设置对齐方式(默认为 Align::Left) - Text& alignment( + void setAlignment( Align align ); // 设置下划线(默认值为 false) - Text& underline( + void setUnderline( bool hasUnderline ); // 设置删除线(默认值为 false) - Text& strikethrough( + void setStrikethrough( bool hasStrikethrough ); // 设置是否显示描边 - Text& outline( + void setOutline( bool hasOutline ); // 设置描边颜色 - Text& outlineColor( + void setOutlineColor( Color outlineColor ); // 设置描边线宽 - Text& outlineWidth( + void setOutlineWidth( float outlineWidth ); // 设置描边线相交样式 - Text& outlineStroke( + void setOutlineStroke( Stroke outlineStroke ); @@ -843,43 +857,43 @@ public: ); // 获取按钮状态是启用还是禁用 - bool enabled() const; + bool isEnable() const; // 设置按钮启用或禁用 - Button& enabled( + void setEnabled( bool enabled ); // 设置一般情况下显示的按钮 - virtual Button& normal( + virtual void setNormal( Node * normal ); // 设置鼠标移入按钮时显示的按钮 - virtual Button& mouseover( + virtual void setMouseOver( Node * mouseover ); // 设置鼠标按下按钮时显示的按钮 - virtual Button& selected( + virtual void setSelected( Node * selected ); // 设置按钮被禁用时显示的按钮 - virtual Button& disabled( + virtual void setDisabled( Node * disabled ); - // 设置点击回调函数 - Button& clickCallback( + // 设置按钮点击后的执行函数 + void setClickFunc( const Function& func ); - // 设置锚点位置 + // 设置中心点位置 // 默认为 (0, 0), 范围 [0, 1] - virtual Button& anchor( - float anchorX, - float anchorY + virtual void setPivot( + float pivotX, + float pivotY ) override; // 分发鼠标消息 @@ -963,58 +977,58 @@ public: ); // 获取开关状态 - bool checked() const; + bool isChecked() const; // 设置开关按钮的状态 - ToggleButton& checked( + void setChecked( bool checked ); // 设置按钮打开状态下显示的按钮 - virtual ToggleButton& normal( + virtual void setNormal( Node * normal ) override; // 设置按钮打开状态下,鼠标移入按钮时显示的按钮 - virtual ToggleButton& mouseover( + virtual void setMouseOver( Node * mouseover ) override; // 设置按钮打开状态下,鼠标按下按钮时显示的按钮 - virtual ToggleButton& selected( + virtual void setSelected( Node * selected ) override; // 设置按钮打开状态下,被禁用时显示的按钮 - virtual ToggleButton& disabled( + virtual void setDisabled( Node * disabled ) override; // 设置按钮关闭状态下显示的按钮 - ToggleButton& normalOff( + void setNormalOff( Node * normal ); // 设置按钮关闭状态下,鼠标移入按钮时显示的按钮 - ToggleButton& mouseOverOff( + void setMouseOverOff( Node * mouseover ); // 设置按钮关闭状态下,鼠标按下按钮时显示的按钮 - ToggleButton& selectedOff( + void setSelectedOff( Node * selected ); // 设置按钮关闭状态下,按钮被禁用时显示的按钮 - ToggleButton& disabledOff( + void setDisabledOff( Node * disabled ); - // 设置锚点位置 + // 设置中心点位置 // 默认为 (0, 0), 范围 [0, 1] - virtual ToggleButton& anchor( - float anchorX, - float anchorY + virtual void setPivot( + float pivotX, + float pivotY ) override; protected: @@ -1050,18 +1064,18 @@ public: ); // 获取菜单是否禁用 - bool enabled() const; + bool isEnable() const; // 获取菜单中的按钮数量 - int buttonCount() const; + size_t getButtonCount() const; // 设置菜单启用或禁用 - Menu& enabled( + void setEnabled( bool enabled ); // 添加按钮 - Menu& addButton( + void addButton( Button * button ); @@ -1071,7 +1085,7 @@ public: ); // 获取所有按钮 - const std::vector& buttons() const; + const std::vector& getAllButtons() const; protected: E2D_DISABLE_COPY(Menu); @@ -1096,88 +1110,88 @@ public: virtual ~Canvas(); // 设置线条颜色 - Canvas& lineColor( + void setLineColor( const Color& color ); // 设置填充颜色 - Canvas& fillColor( + void setFillColor( const Color& color ); // 设置线条宽度 - Canvas& strokeWidth( + void setStrokeWidth( float width ); // 设置线条相交样式 - Canvas& strokeStyle( + void setStrokeStyle( Stroke strokeStyle ); // 获取线条颜色 - Color lineColor() const; + const Color& getLineColor() const; // 获取填充颜色 - Color fillColor() const; + const Color& getFillColor() const; // 获取线条宽度 - float strokeWidth() const; + float getStrokeWidth() const; // 获取线条相交样式 - Stroke strokeStyle() const; + Stroke getStrokeStyle() const; // 画直线 - Canvas& drawLine( + void drawLine( const Point& begin, const Point& end ); // 画圆形边框 - Canvas& drawCircle( + void drawCircle( const Point& center, float radius ); // 画椭圆形边框 - Canvas& drawEllipse( + void drawEllipse( const Point& center, float radiusX, float radiusY ); // 画矩形边框 - Canvas& drawRect( + void drawRect( const Rect& rect ); // 画圆角矩形边框 - Canvas& drawRoundedRect( + void drawRoundedRect( const Rect& rect, float radiusX, float radiusY ); // 填充圆形 - Canvas& fillCircle( + void fillCircle( const Point& center, float radius ); // 填充椭圆形 - Canvas& fillEllipse( + void fillEllipse( const Point& center, float radiusX, float radiusY ); // 填充矩形 - Canvas& fillRect( + void fillRect( const Rect& rect ); // 填充圆角矩形 - Canvas& fillRoundedRect( + void fillRoundedRect( const Rect& rect, float radiusX, float radiusY diff --git a/core/e2dtool.h b/core/e2dtool.h index f1651a58..3666c99c 100644 --- a/core/e2dtool.h +++ b/core/e2dtool.h @@ -33,18 +33,18 @@ private: static T __randomInt(T min, T max) { std::uniform_int_distribution dist(min, max); - return dist(Random::__engine()); + return dist(Random::__getEngine()); } template static T __randomReal(T min, T max) { std::uniform_real_distribution dist(min, max); - return dist(Random::__engine()); + return dist(Random::__getEngine()); } // 获取随机数产生器 - static std::default_random_engine &__engine(); + static std::default_random_engine &__getEngine(); }; @@ -95,28 +95,25 @@ public: void close(); // 是否正在播放 - bool playing() const; - - // 获取音量 - float volume() const; + bool isPlaying() const; // 设置音量 - bool volume( - float volume /* 音量范围为 -224 ~ 224,0 是静音,1 是正常音量 */ + bool setVolume( + float volume ); - // 设置播放结束回调函数 - void callbackOnEnd( + // 设置播放结束时的执行函数 + void setFuncOnEnd( const Function& func ); - // 设置循环播放中每一次播放结束时的回调函数 - void callbackOnLoopEnd( + // 设置循环播放中每一次播放结束时的执行函数 + void setFuncOnLoopEnd( const Function& func ); // 获取 IXAudio2SourceVoice 对象 - IXAudio2SourceVoice * sourceVoice() const; + IXAudio2SourceVoice * getIXAudio2SourceVoice() const; public: class XAudio2Tool @@ -126,13 +123,13 @@ public: ~XAudio2Tool(); - static XAudio2Tool* instance(); + static XAudio2Tool* getInstance(); // 获取 XAudio2 实例对象 - IXAudio2 * xAudio2(); + IXAudio2 * getXAudio2(); // 获取 MasteringVoice 实例对象 - IXAudio2MasteringVoice* masteringVoice(); + IXAudio2MasteringVoice* getMasteringVoice(); protected: IXAudio2 * _xAudio2; @@ -158,7 +155,6 @@ protected: protected: bool _opened; bool _playing; - float _volume; DWORD _dwSize; CHAR* _resBuffer; BYTE* _waveData; @@ -208,7 +204,7 @@ public: ); // 获取音乐播放状态 - bool playing( + bool isPlaying( const String& filePath /* 音乐文件路径 */ ); @@ -239,15 +235,15 @@ public: ); // 获取音乐播放状态 - bool playing( + bool isPlaying( const Resource& res /* 音乐资源 */ - ) const; + ); // 获取音量 - float volume() const; + float getVolume(); // 设置音量 - void volume( + void setVolume( float volume /* 音量范围为 -224 ~ 224,0 是静音,1 是正常音量 */ ); @@ -300,7 +296,7 @@ public: bool isRunning() const; // 获取任务名称 - String name() const; + String getName() const; protected: // 执行任务 @@ -326,7 +322,7 @@ class Timer { public: // 获取定时器实例 - static Timer * instance(); + static Timer * getInstance(); // 添加任务 void addTask( @@ -389,46 +385,46 @@ public: // 保存 int 类型的值 void saveInt( - int value /* 数据 */ + int value /* 数据 */ ); // 保存 float 类型的值 void saveDouble( - float value /* 数据 */ + float value /* 数据 */ ); // 保存 bool 类型的值 void saveBool( - bool value /* 数据 */ + bool value /* 数据 */ ); // 保存 字符串 类型的值 void saveString( - const String& value /* 数据 */ + const String& value /* 数据 */ ); // 获取 int 类型的值 // (若不存在则返回 defaultValue 参数的值) - int toInt( - int defaultValue /* 默认值 */ + int getInt( + int defaultValue /* 默认值 */ ); // 获取 float 类型的值 // (若不存在则返回 defaultValue 参数的值) - float toDouble( - float defaultValue /* 默认值 */ + float getDouble( + float defaultValue /* 默认值 */ ); // 获取 bool 类型的值 // (若不存在则返回 defaultValue 参数的值) - bool toBool( - bool defaultValue /* 默认值 */ + bool getBool( + bool defaultValue /* 默认值 */ ); // 获取 字符串 类型的值 // (若不存在则返回 defaultValue 参数的值) - String toString( - const String& defaultValue /* 默认值 */ + String getString( + const String& defaultValue /* 默认值 */ ); protected: @@ -462,13 +458,13 @@ public: bool isFolder() const; // 删除文件 - bool del(); + bool deleteFile(); // 获取文件路径 - const String& path() const; + String getFilePath() const; // 获取文件扩展名 - String ext() const; + String getExtension() const; // 释放资源到临时文件目录 static File extract( @@ -488,7 +484,7 @@ public: ); // 打开保存文件对话框 - static String openSaveDialog( + static String getSaveFilePath( const String& title = L"保存到", /* 对话框标题 */ const String& defExt = L"" /* 默认扩展名 */ ); @@ -508,16 +504,16 @@ class Path public: // 获取数据的默认保存路径 - static const String& dataPath(); + static String getDataPath(); // 获取临时文件目录 - static const String& tempPath(); + static String getTempPath(); // 获取 LocalAppData 目录 - static const String& localAppDataPath(); + static String getLocalAppDataPath(); // 获取当前程序的运行路径 - static const String& currentFilePath(); + static String getCurrentFilePath(); }; } \ No newline at end of file diff --git a/core/e2dtransition.h b/core/e2dtransition.h index 67eaa2ac..f6edd7ef 100644 --- a/core/e2dtransition.h +++ b/core/e2dtransition.h @@ -23,7 +23,7 @@ public: virtual ~Transition(); // 场景过渡动画是否结束 - bool done(); + bool isDone(); protected: // 初始化场景过渡动画