From a67eefc0b427e941febf83ec09509bd5c7932ed7 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Tue, 4 Sep 2018 22:42:34 +0800 Subject: [PATCH] Refactoring : Google C++ style --- core/Action/Action.cpp | 74 +-- core/Action/Animate.cpp | 84 +-- core/Action/Animation.cpp | 60 +- core/Action/CallFunc.cpp | 26 - core/Action/Callback.cpp | 26 + core/Action/Delay.cpp | 38 +- core/Action/FadeIn.cpp | 6 + core/Action/FadeOut.cpp | 6 + core/Action/FiniteTimeAction.cpp | 36 +- core/Action/JumpBy.cpp | 50 +- core/Action/JumpTo.cpp | 12 +- core/Action/Loop.cpp | 68 +-- core/Action/MoveBy.cpp | 38 +- core/Action/MoveTo.cpp | 14 +- core/Action/OpacityBy.cpp | 26 +- core/Action/OpacityTo.cpp | 12 +- core/Action/RotateBy.cpp | 26 +- core/Action/RotateTo.cpp | 12 +- core/Action/ScaleBy.cpp | 36 +- core/Action/ScaleTo.cpp | 22 +- core/Action/Sequence.cpp | 86 +-- core/Action/Spawn.cpp | 76 +-- core/Base/Audio.cpp | 54 +- core/Base/GC.cpp | 66 +-- core/Base/Game.cpp | 232 ++++---- core/Base/Input.cpp | 128 ++--- core/Base/Renderer.cpp | 300 +++++----- core/Base/Window.cpp | 208 +++---- core/Common/Collider.cpp | 132 ++--- core/Common/Color.cpp | 18 +- core/Common/Duration.cpp | 32 +- core/Common/Function.cpp | 12 +- core/Common/Image.cpp | 162 +++--- core/Common/Point.cpp | 10 +- core/Common/Rect.cpp | 28 +- core/Common/Ref.cpp | 14 +- core/Common/Resource.cpp | 6 +- core/Common/Size.cpp | 16 +- core/Common/String.cpp | 201 ++++--- core/Common/Time.cpp | 22 +- core/Custom/Exception.cpp | 12 +- core/Custom/TextRenderer.cpp | 54 +- core/Custom/VoiceCallback.cpp | 20 +- core/Event/Collision.cpp | 16 +- core/Event/KeyEvent.cpp | 24 +- core/Event/MouseEvent.cpp | 54 +- core/Manager/ActionManager.cpp | 168 +++--- core/Manager/CollisionManager.cpp | 78 +-- core/Node/Button.cpp | 258 ++++----- core/Node/Canvas.cpp | 164 +++--- core/Node/Menu.cpp | 50 +- core/Node/Node.cpp | 762 +++++++++++++------------- core/Node/Scene.cpp | 32 +- core/Node/Sprite.cpp | 102 ++-- core/Node/Text.cpp | 384 ++++++------- core/Node/ToggleButton.cpp | 262 ++++----- core/Tool/Data.cpp | 76 +-- core/Tool/File.cpp | 136 ++--- core/Tool/Music.cpp | 324 +++++------ core/Tool/Path.cpp | 74 +-- core/Tool/Player.cpp | 162 +++--- core/Tool/Random.cpp | 2 +- core/Tool/Task.cpp | 72 +-- core/Tool/Timer.cpp | 96 ++-- core/Transition/BoxTransition.cpp | 42 +- core/Transition/EmergeTransition.cpp | 20 +- core/Transition/FadeTransition.cpp | 26 +- core/Transition/MoveTransition.cpp | 58 +- core/Transition/Transition.cpp | 98 ++-- core/e2daction.h | 356 ++++++------ core/e2dbase.h | 281 +++++----- core/e2dcommon.h | 304 +++++----- core/e2dcustom.h | 34 +- core/e2devent.h | 62 +-- core/e2dmanager.h | 60 +- core/e2dnode.h | 706 ++++++++++++------------ core/e2dtool.h | 292 +++++----- core/e2dtransition.h | 56 +- project/vs2012/Easy2D.vcxproj | 4 +- project/vs2012/Easy2D.vcxproj.filters | 12 +- project/vs2013/Easy2D.vcxproj | 4 +- project/vs2013/Easy2D.vcxproj.filters | 12 +- project/vs2017/Easy2D.vcxproj | 4 +- project/vs2017/Easy2D.vcxproj.filters | 12 +- 84 files changed, 4156 insertions(+), 4144 deletions(-) delete mode 100644 core/Action/CallFunc.cpp create mode 100644 core/Action/Callback.cpp create mode 100644 core/Action/FadeIn.cpp create mode 100644 core/Action/FadeOut.cpp diff --git a/core/Action/Action.cpp b/core/Action/Action.cpp index 24238d82..81655d57 100644 --- a/core/Action/Action.cpp +++ b/core/Action/Action.cpp @@ -2,87 +2,87 @@ #include "..\e2dmanager.h" e2d::Action::Action() - : _running(false) - , _done(false) - , _initialized(false) - , _target(nullptr) + : running_(false) + , done_(false) + , initialized_(false) + , target_(nullptr) { - ActionManager::getInstance()->__add(this); + ActionManager::GetInstance()->Add(this); } e2d::Action::~Action() { - ActionManager::getInstance()->__remove(this); + ActionManager::GetInstance()->Remove(this); } -bool e2d::Action::isRunning() +bool e2d::Action::IsRunning() { - return _running; + return running_; } -void e2d::Action::resume() +void e2d::Action::Resume() { - _running = true; + running_ = true; } -void e2d::Action::pause() +void e2d::Action::Pause() { - _running = false; + running_ = false; } -void e2d::Action::stop() +void e2d::Action::Stop() { - _done = true; + done_ = true; } -e2d::String e2d::Action::getName() const +const e2d::String& e2d::Action::GetName() const { - return _name; + return name_; } -void e2d::Action::setName(const String& name) +void e2d::Action::SetName(const String& name) { - _name = name; + name_ = name; } -e2d::Node * e2d::Action::getTarget() +e2d::Node * e2d::Action::GetTarget() { - return _target; + return target_; } -void e2d::Action::reset() +void e2d::Action::Reset() { - _initialized = false; - _done = false; - _started = Time::now(); + initialized_ = false; + done_ = false; + started_ = Time::Now(); } -bool e2d::Action::_isDone() +bool e2d::Action::IsDone() { - return _done; + return done_; } -void e2d::Action::_startWithTarget(Node* target) +void e2d::Action::StartWithTarget(Node* target) { - _target = target; - _running = true; - this->reset(); + target_ = target; + running_ = true; + this->Reset(); } -void e2d::Action::_init() +void e2d::Action::Init() { - _initialized = true; - _started = Time::now(); + initialized_ = true; + started_ = Time::Now(); } -void e2d::Action::_update() +void e2d::Action::Update() { - if (!_initialized) + if (!initialized_) { - _init(); + Init(); } } -void e2d::Action::_resetTime() +void e2d::Action::ResetTime() { } diff --git a/core/Action/Animate.cpp b/core/Action/Animate.cpp index 2c187440..35d613ca 100644 --- a/core/Action/Animate.cpp +++ b/core/Action/Animate.cpp @@ -2,106 +2,106 @@ #include "..\e2dnode.h" e2d::Animate::Animate() - : _frameIndex(0) - , _animation(nullptr) + : frame_index_(0) + , animation_(nullptr) { } e2d::Animate::Animate(Animation * animation) - : _frameIndex(0) - , _animation(nullptr) + : frame_index_(0) + , animation_(nullptr) { - this->setAnimation(animation); + this->SetAnimation(animation); } e2d::Animate::~Animate() { - GC::getInstance()->safeRelease(_animation); + GC::GetInstance()->SafeRelease(animation_); } -e2d::Animation * e2d::Animate::getAnimation() const +e2d::Animation * e2d::Animate::GetAnimation() const { - return _animation; + return animation_; } -void e2d::Animate::setAnimation(Animation * animation) +void e2d::Animate::SetAnimation(Animation * animation) { - if (animation && animation != _animation && !animation->getFrames().empty()) + if (animation && animation != animation_ && !animation->GetFrames().empty()) { - if (_animation) _animation->release(); - _animation = animation; - _animation->retain(); + if (animation_) animation_->Release(); + animation_ = animation; + animation_->Retain(); } } -void e2d::Animate::_init() +void e2d::Animate::Init() { - Action::_init(); + Action::Init(); - auto target = dynamic_cast(_target); - if (target && _animation) + auto target = dynamic_cast(target_); + if (target && animation_) { - target->open(_animation->getFrames()[_frameIndex]); - ++_frameIndex; + target->Open(animation_->GetFrames()[frame_index_]); + ++frame_index_; } } -void e2d::Animate::_update() +void e2d::Animate::Update() { - Action::_update(); + Action::Update(); - if (!_animation) + if (!animation_) { - this->stop(); + this->Stop(); return; } - while ((Time::now() - _started).seconds() >= _animation->getInterval()) + while ((Time::Now() - started_).Seconds() >= animation_->GetInterval()) { - auto& frames = _animation->getFrames(); - auto target = dynamic_cast(_target); + auto& frames = animation_->GetFrames(); + auto target = dynamic_cast(target_); if (target) { - target->open(frames[_frameIndex]); + target->Open(frames[frame_index_]); } - _started += Duration(_animation->getInterval()); - ++_frameIndex; + started_ += Duration(animation_->GetInterval()); + ++frame_index_; - if (_frameIndex == frames.size()) + if (frame_index_ == frames.size()) { - this->stop(); + this->Stop(); break; } } } -void e2d::Animate::_resetTime() +void e2d::Animate::ResetTime() { - Action::_resetTime(); + Action::ResetTime(); } -void e2d::Animate::reset() +void e2d::Animate::Reset() { - Action::reset(); - _frameIndex = 0; + Action::Reset(); + frame_index_ = 0; } -e2d::Animate * e2d::Animate::clone() const +e2d::Animate * e2d::Animate::Clone() const { - if (_animation) + if (animation_) { - return new (e2d::autorelease) Animate(_animation); + return new (e2d::autorelease) Animate(animation_); } return nullptr; } -e2d::Animate * e2d::Animate::reverse() const +e2d::Animate * e2d::Animate::Reverse() const { - if (_animation) + if (animation_) { - auto animation = _animation->reverse(); + auto animation = animation_->Reverse(); if (animation) { return new (e2d::autorelease) Animate(animation); diff --git a/core/Action/Animation.cpp b/core/Action/Animation.cpp index 42d0a933..dab6aa79 100644 --- a/core/Action/Animation.cpp +++ b/core/Action/Animation.cpp @@ -1,85 +1,85 @@ #include "..\e2daction.h" e2d::Animation::Animation() - : _interval(1) + : interval_(1) { } -e2d::Animation::Animation(const std::vector& frames) - : _interval(1) +e2d::Animation::Animation(const Images& frames) + : interval_(1) { - this->add(frames); + this->Add(frames); } e2d::Animation::Animation(float interval) - : _interval(interval) + : interval_(interval) { } -e2d::Animation::Animation(float interval, const std::vector& frames) - : _interval(interval) +e2d::Animation::Animation(float interval, const Images& frames) + : interval_(interval) { - this->add(frames); + this->Add(frames); } e2d::Animation::~Animation() { - for (const auto& frame : _frames) + for (const auto& frame : frames_) { - GC::getInstance()->safeRelease(frame); + GC::GetInstance()->SafeRelease(frame); } } -void e2d::Animation::setInterval(float interval) +void e2d::Animation::SetInterval(float interval) { - _interval = std::max(interval, 0.f); + interval_ = std::max(interval, 0.f); } -void e2d::Animation::add(Image * frame) +void e2d::Animation::Add(Image * frame) { - WARN_IF(frame == nullptr, "Animation::add failed, frame is nullptr."); + WARN_IF(frame == nullptr, "Animation::Add failed, frame Is nullptr."); if (frame) { - _frames.push_back(frame); - frame->retain(); + frames_.push_back(frame); + frame->Retain(); } } -void e2d::Animation::add(const std::vector& frames) +void e2d::Animation::Add(const Images& frames) { for (const auto &image : frames) { - this->add(image); + this->Add(image); } } -float e2d::Animation::getInterval() const +float e2d::Animation::GetInterval() const { - return _interval; + return interval_; } -const std::vector& e2d::Animation::getFrames() const +const e2d::Animation::Images& e2d::Animation::GetFrames() const { - return _frames; + return frames_; } -e2d::Animation * e2d::Animation::clone() const +e2d::Animation * e2d::Animation::Clone() const { - auto animation = new (e2d::autorelease) Animation(_interval); + auto animation = new (e2d::autorelease) Animation(interval_); if (animation) { - for (const auto& frame : _frames) + for (const auto& frame : frames_) { - animation->add(frame); + animation->Add(frame); } } return animation; } -e2d::Animation * e2d::Animation::reverse() const +e2d::Animation * e2d::Animation::Reverse() const { - auto& oldFrames = this->getFrames(); - std::vector frames(oldFrames.size()); + auto& oldFrames = this->GetFrames(); + Images frames(oldFrames.size()); if (!oldFrames.empty()) { @@ -96,5 +96,5 @@ e2d::Animation * e2d::Animation::reverse() const } } - return new (e2d::autorelease) Animation(this->getInterval(), frames); + return new (e2d::autorelease) Animation(this->GetInterval(), frames); } diff --git a/core/Action/CallFunc.cpp b/core/Action/CallFunc.cpp deleted file mode 100644 index c50c02b1..00000000 --- a/core/Action/CallFunc.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "..\e2daction.h" - -e2d::CallFunc::CallFunc(const Function& func) : - _func(func) -{ -} - -e2d::CallFunc * e2d::CallFunc::clone() const -{ - return new (e2d::autorelease) CallFunc(_func); -} - -e2d::CallFunc * e2d::CallFunc::reverse() const -{ - return new (e2d::autorelease) CallFunc(_func); -} - -void e2d::CallFunc::_init() -{ -} - -void e2d::CallFunc::_update() -{ - _func(); - this->stop(); -} diff --git a/core/Action/Callback.cpp b/core/Action/Callback.cpp new file mode 100644 index 00000000..09e746b8 --- /dev/null +++ b/core/Action/Callback.cpp @@ -0,0 +1,26 @@ +#include "..\e2daction.h" + +e2d::Callback::Callback(const Function& func) : + callback_(func) +{ +} + +e2d::Callback * e2d::Callback::Clone() const +{ + return new (e2d::autorelease) Callback(callback_); +} + +e2d::Callback * e2d::Callback::Reverse() const +{ + return new (e2d::autorelease) Callback(callback_); +} + +void e2d::Callback::Init() +{ +} + +void e2d::Callback::Update() +{ + callback_(); + this->Stop(); +} diff --git a/core/Action/Delay.cpp b/core/Action/Delay.cpp index 1f29436b..ca6dd0a5 100644 --- a/core/Action/Delay.cpp +++ b/core/Action/Delay.cpp @@ -1,46 +1,46 @@ #include "..\e2daction.h" e2d::Delay::Delay(float duration) - : _delta(0) - , _delay(std::max(duration, 0.f)) + : delta_(0) + , delay_(std::max(duration, 0.f)) { } -e2d::Delay * e2d::Delay::clone() const +e2d::Delay * e2d::Delay::Clone() const { - return new (e2d::autorelease) Delay(_delay); + return new (e2d::autorelease) Delay(delay_); } -e2d::Delay * e2d::Delay::reverse() const +e2d::Delay * e2d::Delay::Reverse() const { - return new (e2d::autorelease) Delay(_delay); + return new (e2d::autorelease) Delay(delay_); } -void e2d::Delay::reset() +void e2d::Delay::Reset() { - Action::reset(); - _delta = 0; + Action::Reset(); + delta_ = 0; } -void e2d::Delay::_init() +void e2d::Delay::Init() { - Action::_init(); + Action::Init(); } -void e2d::Delay::_update() +void e2d::Delay::Update() { - Action::_update(); + Action::Update(); - _delta = (Time::now() - _started).seconds(); + delta_ = (Time::Now() - started_).Seconds(); - if (_delta >= _delay) + if (delta_ >= delay_) { - this->stop(); + this->Stop(); } } -void e2d::Delay::_resetTime() +void e2d::Delay::ResetTime() { - Action::_resetTime(); - _started = Time::now() - Duration(_delta); + Action::ResetTime(); + started_ = Time::Now() - Duration(delta_); } diff --git a/core/Action/FadeIn.cpp b/core/Action/FadeIn.cpp new file mode 100644 index 00000000..53d4bdd6 --- /dev/null +++ b/core/Action/FadeIn.cpp @@ -0,0 +1,6 @@ +#include "..\e2daction.h" + +e2d::FadeIn::FadeIn(float duration) + : OpacityTo(duration, 1) +{ +} diff --git a/core/Action/FadeOut.cpp b/core/Action/FadeOut.cpp new file mode 100644 index 00000000..47353572 --- /dev/null +++ b/core/Action/FadeOut.cpp @@ -0,0 +1,6 @@ +#include "..\e2daction.h" + +e2d::FadeOut::FadeOut(float duration) + : OpacityTo(duration, 0) +{ +} diff --git a/core/Action/FiniteTimeAction.cpp b/core/Action/FiniteTimeAction.cpp index becd7b7c..4eabc851 100644 --- a/core/Action/FiniteTimeAction.cpp +++ b/core/Action/FiniteTimeAction.cpp @@ -1,44 +1,44 @@ #include "..\e2daction.h" e2d::FiniteTimeAction::FiniteTimeAction(float duration) - : _delta(0) - , _duration(std::max(duration, 0.f)) + : delta_(0) + , duration_(std::max(duration, 0.f)) { } -void e2d::FiniteTimeAction::reset() +void e2d::FiniteTimeAction::Reset() { - Action::reset(); - _delta = 0; + Action::Reset(); + delta_ = 0; } -void e2d::FiniteTimeAction::_init() +void e2d::FiniteTimeAction::Init() { - Action::_init(); + Action::Init(); } -void e2d::FiniteTimeAction::_update() +void e2d::FiniteTimeAction::Update() { - Action::_update(); + Action::Update(); - if (_duration == 0) + if (duration_ == 0) { - _delta = 1; - this->stop(); + delta_ = 1; + this->Stop(); } else { - _delta = std::min((Time::now() - _started).seconds() / _duration, 1.f); + delta_ = std::min((Time::Now() - started_).Seconds() / duration_, 1.f); - if (_delta >= 1) + if (delta_ >= 1) { - this->stop(); + this->Stop(); } } } -void e2d::FiniteTimeAction::_resetTime() +void e2d::FiniteTimeAction::ResetTime() { - Action::_resetTime(); - _started = Time::now() - Duration(_delta * _duration); + Action::ResetTime(); + started_ = Time::Now() - Duration(delta_ * duration_); } diff --git a/core/Action/JumpBy.cpp b/core/Action/JumpBy.cpp index 523cfb9f..dd373f51 100644 --- a/core/Action/JumpBy.cpp +++ b/core/Action/JumpBy.cpp @@ -1,53 +1,53 @@ #include "..\e2daction.h" #include "..\e2dnode.h" -e2d::JumpBy::JumpBy(float duration, const Vector2 & vec, float height, int jumps) +e2d::JumpBy::JumpBy(float duration, const Point & vec, float height, int jumps) : FiniteTimeAction(duration) - , _deltaPos(vec) - , _height(height) - , _jumps(jumps) + , delta_pos_(vec) + , height_(height) + , jumps_(jumps) { } -e2d::JumpBy * e2d::JumpBy::clone() const +e2d::JumpBy * e2d::JumpBy::Clone() const { - return new (e2d::autorelease) JumpBy(_duration, _deltaPos, _height, _jumps); + return new (e2d::autorelease) JumpBy(duration_, delta_pos_, height_, jumps_); } -e2d::JumpBy * e2d::JumpBy::reverse() const +e2d::JumpBy * e2d::JumpBy::Reverse() const { - return new (e2d::autorelease) JumpBy(_duration, -_deltaPos, _height, _jumps); + return new (e2d::autorelease) JumpBy(duration_, -delta_pos_, height_, jumps_); } -void e2d::JumpBy::_init() +void e2d::JumpBy::Init() { - FiniteTimeAction::_init(); + FiniteTimeAction::Init(); - if (_target) + if (target_) { - _prevPos = _startPos = _target->getPos(); + prev_pos_ = start_pos_ = target_->GetPos(); } } -void e2d::JumpBy::_update() +void e2d::JumpBy::Update() { - FiniteTimeAction::_update(); + FiniteTimeAction::Update(); - if (_target) + if (target_) { - float frac = fmod(_delta * _jumps, 1.f); - float x = _deltaPos.x * _delta; - float y = _height * 4 * frac * (1 - frac); - y += _deltaPos.y * _delta; + float frac = fmod(delta_ * jumps_, 1.f); + float x = delta_pos_.x * delta_; + float y = height_ * 4 * frac * (1 - frac); + y += delta_pos_.y * delta_; - Point currentPos = _target->getPos(); + Point currentPos = target_->GetPos(); - Vector2 diff = currentPos - _prevPos; - _startPos = diff + _startPos; + Point diff = currentPos - prev_pos_; + start_pos_ = diff + start_pos_; - Point newPos = _startPos + Vector2(x, y); - _target->setPos(newPos); + Point newPos = start_pos_ + Point(x, y); + target_->SetPos(newPos); - _prevPos = newPos; + prev_pos_ = newPos; } } diff --git a/core/Action/JumpTo.cpp b/core/Action/JumpTo.cpp index fd0a1869..ebe1968e 100644 --- a/core/Action/JumpTo.cpp +++ b/core/Action/JumpTo.cpp @@ -3,17 +3,17 @@ e2d::JumpTo::JumpTo(float duration, const Point & pos, float height, int jumps) : JumpBy(duration, Point(), height, jumps) - , _endPos(pos) + , end_pos_(pos) { } -e2d::JumpTo * e2d::JumpTo::clone() const +e2d::JumpTo * e2d::JumpTo::Clone() const { - return new (e2d::autorelease) JumpTo(_duration, _endPos, _height, _jumps); + return new (e2d::autorelease) JumpTo(duration_, end_pos_, height_, jumps_); } -void e2d::JumpTo::_init() +void e2d::JumpTo::Init() { - JumpBy::_init(); - _deltaPos = _endPos - _startPos; + JumpBy::Init(); + delta_pos_ = end_pos_ - start_pos_; } diff --git a/core/Action/Loop.cpp b/core/Action/Loop.cpp index 08892502..84dd422d 100644 --- a/core/Action/Loop.cpp +++ b/core/Action/Loop.cpp @@ -2,29 +2,29 @@ #include "..\e2dmanager.h" e2d::Loop::Loop(Action * action, int times /* = -1 */) - : _action(action) - , _times(0) - , _totalTimes(times) + : action_(action) + , times_(0) + , total_times_(times) { WARN_IF(action == nullptr, "Loop NULL pointer exception!"); if (action) { - _action = action; - _action->retain(); + action_ = action; + action_->Retain(); } } e2d::Loop::~Loop() { - GC::getInstance()->safeRelease(_action); + GC::GetInstance()->SafeRelease(action_); } -e2d::Loop * e2d::Loop::clone() const +e2d::Loop * e2d::Loop::Clone() const { - if (_action) + if (action_) { - return new (e2d::autorelease) Loop(_action->clone()); + return new (e2d::autorelease) Loop(action_->Clone()); } else { @@ -32,11 +32,11 @@ e2d::Loop * e2d::Loop::clone() const } } -e2d::Loop * e2d::Loop::reverse() const +e2d::Loop * e2d::Loop::Reverse() const { - if (_action) + if (action_) { - return new (e2d::autorelease) Loop(_action->clone()); + return new (e2d::autorelease) Loop(action_->Clone()); } else { @@ -44,54 +44,54 @@ e2d::Loop * e2d::Loop::reverse() const } } -void e2d::Loop::_init() +void e2d::Loop::Init() { - Action::_init(); + Action::Init(); - if (_action) + if (action_) { - _action->_target = _target; - _action->_init(); + action_->target_ = target_; + action_->Init(); } } -void e2d::Loop::_update() +void e2d::Loop::Update() { - Action::_update(); + Action::Update(); - if (_times == _totalTimes) + if (times_ == total_times_) { - this->stop(); + this->Stop(); return; } - if (_action) + if (action_) { - _action->_update(); + action_->Update(); - if (_action->_isDone()) + if (action_->IsDone()) { - ++_times; + ++times_; - Action::reset(); - _action->reset(); + Action::Reset(); + action_->Reset(); } } else { - this->stop(); + this->Stop(); } } -void e2d::Loop::reset() +void e2d::Loop::Reset() { - Action::reset(); + Action::Reset(); - if (_action) _action->reset(); - _times = 0; + if (action_) action_->Reset(); + times_ = 0; } -void e2d::Loop::_resetTime() +void e2d::Loop::ResetTime() { - if (_action) _action->_resetTime(); + if (action_) action_->ResetTime(); } diff --git a/core/Action/MoveBy.cpp b/core/Action/MoveBy.cpp index d537b797..7c819e94 100644 --- a/core/Action/MoveBy.cpp +++ b/core/Action/MoveBy.cpp @@ -2,45 +2,45 @@ #include "..\e2dnode.h" -e2d::MoveBy::MoveBy(float duration, Vector2 vector) +e2d::MoveBy::MoveBy(float duration, Point vector) : FiniteTimeAction(duration) { - _deltaPos = vector; + delta_pos_ = vector; } -void e2d::MoveBy::_init() +void e2d::MoveBy::Init() { - FiniteTimeAction::_init(); + FiniteTimeAction::Init(); - if (_target) + if (target_) { - _prevPos = _startPos = _target->getPos(); + prev_pos_ = start_pos_ = target_->GetPos(); } } -void e2d::MoveBy::_update() +void e2d::MoveBy::Update() { - FiniteTimeAction::_update(); + FiniteTimeAction::Update(); - if (_target) + if (target_) { - Point currentPos = _target->getPos(); - Vector2 diff = currentPos - _prevPos; - _startPos = _startPos + diff; + Point currentPos = target_->GetPos(); + Point diff = currentPos - prev_pos_; + start_pos_ = start_pos_ + diff; - Point newPos = _startPos + (_deltaPos * _delta); - _target->setPos(newPos); + Point newPos = start_pos_ + (delta_pos_ * delta_); + target_->SetPos(newPos); - _prevPos = newPos; + prev_pos_ = newPos; } } -e2d::MoveBy * e2d::MoveBy::clone() const +e2d::MoveBy * e2d::MoveBy::Clone() const { - return new (e2d::autorelease) MoveBy(_duration, _deltaPos); + return new (e2d::autorelease) MoveBy(duration_, delta_pos_); } -e2d::MoveBy * e2d::MoveBy::reverse() const +e2d::MoveBy * e2d::MoveBy::Reverse() const { - return new (e2d::autorelease) MoveBy(_duration, -_deltaPos); + return new (e2d::autorelease) MoveBy(duration_, -delta_pos_); } \ No newline at end of file diff --git a/core/Action/MoveTo.cpp b/core/Action/MoveTo.cpp index ea4e1f3d..001ac250 100644 --- a/core/Action/MoveTo.cpp +++ b/core/Action/MoveTo.cpp @@ -2,18 +2,18 @@ #include "..\e2dnode.h" e2d::MoveTo::MoveTo(float duration, Point pos) - : MoveBy(duration, Vector2()) + : MoveBy(duration, Point()) { - _endPos = pos; + end_pos_ = pos; } -e2d::MoveTo * e2d::MoveTo::clone() const +e2d::MoveTo * e2d::MoveTo::Clone() const { - return new (e2d::autorelease) MoveTo(_duration, _endPos); + return new (e2d::autorelease) MoveTo(duration_, end_pos_); } -void e2d::MoveTo::_init() +void e2d::MoveTo::Init() { - MoveBy::_init(); - _deltaPos = _endPos - _startPos; + MoveBy::Init(); + delta_pos_ = end_pos_ - start_pos_; } diff --git a/core/Action/OpacityBy.cpp b/core/Action/OpacityBy.cpp index 421e0c55..5bdc36a2 100644 --- a/core/Action/OpacityBy.cpp +++ b/core/Action/OpacityBy.cpp @@ -5,35 +5,35 @@ e2d::OpacityBy::OpacityBy(float duration, float opacity) : FiniteTimeAction(duration) { - _deltaVal = opacity; + delta_val_ = opacity; } -void e2d::OpacityBy::_init() +void e2d::OpacityBy::Init() { - FiniteTimeAction::_init(); + FiniteTimeAction::Init(); - if (_target) + if (target_) { - _startVal = _target->getOpacity(); + start_val_ = target_->GetOpacity(); } } -void e2d::OpacityBy::_update() +void e2d::OpacityBy::Update() { - FiniteTimeAction::_update(); + FiniteTimeAction::Update(); - if (_target) + if (target_) { - _target->setOpacity(_startVal + _deltaVal * _delta); + target_->SetOpacity(start_val_ + delta_val_ * delta_); } } -e2d::OpacityBy * e2d::OpacityBy::clone() const +e2d::OpacityBy * e2d::OpacityBy::Clone() const { - return new (e2d::autorelease) OpacityBy(_duration, _deltaVal); + return new (e2d::autorelease) OpacityBy(duration_, delta_val_); } -e2d::OpacityBy * e2d::OpacityBy::reverse() const +e2d::OpacityBy * e2d::OpacityBy::Reverse() const { - return new (e2d::autorelease) OpacityBy(_duration, -_deltaVal); + return new (e2d::autorelease) OpacityBy(duration_, -delta_val_); } \ No newline at end of file diff --git a/core/Action/OpacityTo.cpp b/core/Action/OpacityTo.cpp index 16fa4bf7..e55b1299 100644 --- a/core/Action/OpacityTo.cpp +++ b/core/Action/OpacityTo.cpp @@ -5,16 +5,16 @@ e2d::OpacityTo::OpacityTo(float duration, float opacity) : OpacityBy(duration, 0) { - _endVal = opacity; + end_val_ = opacity; } -e2d::OpacityTo * e2d::OpacityTo::clone() const +e2d::OpacityTo * e2d::OpacityTo::Clone() const { - return new (e2d::autorelease) OpacityTo(_duration, _endVal); + return new (e2d::autorelease) OpacityTo(duration_, end_val_); } -void e2d::OpacityTo::_init() +void e2d::OpacityTo::Init() { - OpacityBy::_init(); - _deltaVal = _endVal - _startVal; + OpacityBy::Init(); + delta_val_ = end_val_ - start_val_; } diff --git a/core/Action/RotateBy.cpp b/core/Action/RotateBy.cpp index ad0e5961..71ae1f33 100644 --- a/core/Action/RotateBy.cpp +++ b/core/Action/RotateBy.cpp @@ -5,35 +5,35 @@ e2d::RotateBy::RotateBy(float duration, float rotation) : FiniteTimeAction(duration) { - _deltaVal = rotation; + delta_val_ = rotation; } -void e2d::RotateBy::_init() +void e2d::RotateBy::Init() { - FiniteTimeAction::_init(); + FiniteTimeAction::Init(); - if (_target) + if (target_) { - _startVal = _target->getRotation(); + start_val_ = target_->GetRotation(); } } -void e2d::RotateBy::_update() +void e2d::RotateBy::Update() { - FiniteTimeAction::_update(); + FiniteTimeAction::Update(); - if (_target) + if (target_) { - _target->setRotation(_startVal + _deltaVal * _delta); + target_->SetRotation(start_val_ + delta_val_ * delta_); } } -e2d::RotateBy * e2d::RotateBy::clone() const +e2d::RotateBy * e2d::RotateBy::Clone() const { - return new (e2d::autorelease) RotateBy(_duration, _deltaVal); + return new (e2d::autorelease) RotateBy(duration_, delta_val_); } -e2d::RotateBy * e2d::RotateBy::reverse() const +e2d::RotateBy * e2d::RotateBy::Reverse() const { - return new (e2d::autorelease) RotateBy(_duration, -_deltaVal); + return new (e2d::autorelease) RotateBy(duration_, -delta_val_); } \ No newline at end of file diff --git a/core/Action/RotateTo.cpp b/core/Action/RotateTo.cpp index 07b4bfc5..18b64e50 100644 --- a/core/Action/RotateTo.cpp +++ b/core/Action/RotateTo.cpp @@ -5,16 +5,16 @@ e2d::RotateTo::RotateTo(float duration, float rotation) : RotateBy(duration, 0) { - _endVal = rotation; + end_val_ = rotation; } -e2d::RotateTo * e2d::RotateTo::clone() const +e2d::RotateTo * e2d::RotateTo::Clone() const { - return new (e2d::autorelease) RotateTo(_duration, _endVal); + return new (e2d::autorelease) RotateTo(duration_, end_val_); } -void e2d::RotateTo::_init() +void e2d::RotateTo::Init() { - RotateBy::_init(); - _deltaVal = _endVal - _startVal; + RotateBy::Init(); + delta_val_ = end_val_ - start_val_; } diff --git a/core/Action/ScaleBy.cpp b/core/Action/ScaleBy.cpp index 11e4673b..b03a8f53 100644 --- a/core/Action/ScaleBy.cpp +++ b/core/Action/ScaleBy.cpp @@ -5,44 +5,44 @@ e2d::ScaleBy::ScaleBy(float duration, float scale) : FiniteTimeAction(duration) { - _deltaX = scale; - _deltaY = scale; + delta_x_ = scale; + delta_y_ = scale; } -e2d::ScaleBy::ScaleBy(float duration, float scaleX, float scaleY) +e2d::ScaleBy::ScaleBy(float duration, float scale_x, float scale_y) : FiniteTimeAction(duration) { - _deltaX = scaleX; - _deltaY = scaleY; + delta_x_ = scale_x; + delta_y_ = scale_y; } -void e2d::ScaleBy::_init() +void e2d::ScaleBy::Init() { - FiniteTimeAction::_init(); + FiniteTimeAction::Init(); - if (_target) + if (target_) { - _startScaleX = _target->getScaleX(); - _startScaleY = _target->getScaleY(); + start_scale_x_ = target_->GetScaleX(); + start_scale_y_ = target_->GetScaleY(); } } -void e2d::ScaleBy::_update() +void e2d::ScaleBy::Update() { - FiniteTimeAction::_update(); + FiniteTimeAction::Update(); - if (_target) + if (target_) { - _target->setScale(_startScaleX + _deltaX * _delta, _startScaleY + _deltaY * _delta); + target_->SetScale(start_scale_x_ + delta_x_ * delta_, start_scale_y_ + delta_y_ * delta_); } } -e2d::ScaleBy * e2d::ScaleBy::clone() const +e2d::ScaleBy * e2d::ScaleBy::Clone() const { - return new (e2d::autorelease) ScaleBy(_duration, _deltaX, _deltaY); + return new (e2d::autorelease) ScaleBy(duration_, delta_x_, delta_y_); } -e2d::ScaleBy * e2d::ScaleBy::reverse() const +e2d::ScaleBy * e2d::ScaleBy::Reverse() const { - return new (e2d::autorelease) ScaleBy(_duration, -_deltaX, -_deltaY); + return new (e2d::autorelease) ScaleBy(duration_, -delta_x_, -delta_y_); } \ No newline at end of file diff --git a/core/Action/ScaleTo.cpp b/core/Action/ScaleTo.cpp index 62f68ce4..0855e660 100644 --- a/core/Action/ScaleTo.cpp +++ b/core/Action/ScaleTo.cpp @@ -4,25 +4,25 @@ e2d::ScaleTo::ScaleTo(float duration, float scale) : ScaleBy(duration, 0, 0) { - _endScaleX = scale; - _endScaleY = scale; + end_scale_x_ = scale; + end_scale_y_ = scale; } -e2d::ScaleTo::ScaleTo(float duration, float scaleX, float scaleY) +e2d::ScaleTo::ScaleTo(float duration, float scale_x, float scale_y) : ScaleBy(duration, 0, 0) { - _endScaleX = scaleX; - _endScaleY = scaleY; + end_scale_x_ = scale_x; + end_scale_y_ = scale_y; } -e2d::ScaleTo * e2d::ScaleTo::clone() const +e2d::ScaleTo * e2d::ScaleTo::Clone() const { - return new (e2d::autorelease) ScaleTo(_duration, _endScaleX, _endScaleY); + return new (e2d::autorelease) ScaleTo(duration_, end_scale_x_, end_scale_y_); } -void e2d::ScaleTo::_init() +void e2d::ScaleTo::Init() { - ScaleBy::_init(); - _deltaX = _endScaleX - _startScaleX; - _deltaY = _endScaleY - _startScaleY; + ScaleBy::Init(); + delta_x_ = end_scale_x_ - start_scale_x_; + delta_y_ = end_scale_y_ - start_scale_y_; } diff --git a/core/Action/Sequence.cpp b/core/Action/Sequence.cpp index 56408045..b601f567 100644 --- a/core/Action/Sequence.cpp +++ b/core/Action/Sequence.cpp @@ -1,119 +1,119 @@ #include "..\e2daction.h" e2d::Sequence::Sequence() - : _currIndex(0) + : action_index_(0) { } -e2d::Sequence::Sequence(const std::vector& actions) - : _currIndex(0) +e2d::Sequence::Sequence(const Actions& actions) + : action_index_(0) { - this->add(actions); + this->Add(actions); } e2d::Sequence::~Sequence() { - for (const auto& action : _actions) + for (const auto& action : actions_) { - GC::getInstance()->safeRelease(action); + GC::GetInstance()->SafeRelease(action); } } -void e2d::Sequence::_init() +void e2d::Sequence::Init() { - Action::_init(); + Action::Init(); // 将所有动作与目标绑定 - if (_target) + if (target_) { - for (const auto& action : _actions) + for (const auto& action : actions_) { - action->_target = _target; + action->target_ = target_; } } // 初始化第一个动作 - _actions[0]->_init(); + actions_[0]->Init(); } -void e2d::Sequence::_update() +void e2d::Sequence::Update() { - Action::_update(); + Action::Update(); - auto &action = _actions[_currIndex]; - action->_update(); + auto &action = actions_[action_index_]; + action->Update(); - if (action->_isDone()) + if (action->IsDone()) { - ++_currIndex; - if (_currIndex == _actions.size()) + ++action_index_; + if (action_index_ == actions_.size()) { - this->stop(); + this->Stop(); } else { - _actions[_currIndex]->_init(); + actions_[action_index_]->Init(); } } } -void e2d::Sequence::reset() +void e2d::Sequence::Reset() { - Action::reset(); - for (const auto& action : _actions) + Action::Reset(); + for (const auto& action : actions_) { - action->reset(); + action->Reset(); } - _currIndex = 0; + action_index_ = 0; } -void e2d::Sequence::_resetTime() +void e2d::Sequence::ResetTime() { - for (const auto& action : _actions) + for (const auto& action : actions_) { - action->_resetTime(); + action->ResetTime(); } } -void e2d::Sequence::add(Action * action) +void e2d::Sequence::Add(Action * action) { if (action) { - _actions.push_back(action); - action->retain(); + actions_.push_back(action); + action->Retain(); } } -void e2d::Sequence::add(const std::vector& actions) +void e2d::Sequence::Add(const Actions& actions) { for (const auto &action : actions) { - this->add(action); + this->Add(action); } } -e2d::Sequence * e2d::Sequence::clone() const +e2d::Sequence * e2d::Sequence::Clone() const { auto sequence = new (e2d::autorelease) Sequence(); - for (const auto& action : _actions) + for (const auto& action : actions_) { if (action) { - sequence->add(action->clone()); + sequence->Add(action->Clone()); } } return sequence; } -e2d::Sequence * e2d::Sequence::reverse() const +e2d::Sequence * e2d::Sequence::Reverse() const { auto sequence = new (e2d::autorelease) Sequence(); - if (sequence && !_actions.empty()) + if (sequence && !actions_.empty()) { - std::vector newActions(_actions.size()); - for (auto iter = _actions.crbegin(), iterCrend = _actions.crend(); iter != iterCrend; ++iter) + std::vector newActions(actions_.size()); + for (auto iter = actions_.crbegin(), iterCrend = actions_.crend(); iter != iterCrend; ++iter) { - newActions.push_back((*iter)->reverse()); + newActions.push_back((*iter)->Reverse()); } - sequence->add(newActions); + sequence->Add(newActions); } return sequence; } \ No newline at end of file diff --git a/core/Action/Spawn.cpp b/core/Action/Spawn.cpp index 89835179..df68758e 100644 --- a/core/Action/Spawn.cpp +++ b/core/Action/Spawn.cpp @@ -4,114 +4,114 @@ e2d::Spawn::Spawn() { } -e2d::Spawn::Spawn(const std::vector& actions) +e2d::Spawn::Spawn(const Actions& actions) { - this->add(actions); + this->Add(actions); } e2d::Spawn::~Spawn() { - for (const auto& action : _actions) + for (const auto& action : actions_) { - GC::getInstance()->safeRelease(action); + GC::GetInstance()->SafeRelease(action); } } -void e2d::Spawn::_init() +void e2d::Spawn::Init() { - Action::_init(); + Action::Init(); - if (_target) + if (target_) { - for (const auto& action : _actions) + for (const auto& action : actions_) { - action->_target = _target; - action->_init(); + action->target_ = target_; + action->Init(); } } } -void e2d::Spawn::_update() +void e2d::Spawn::Update() { - Action::_update(); + Action::Update(); size_t doneNum = 0; - for (const auto& action : _actions) + for (const auto& action : actions_) { - if (action->_isDone()) + if (action->IsDone()) { ++doneNum; } else { - action->_update(); + action->Update(); } } - if (doneNum == _actions.size()) + if (doneNum == actions_.size()) { - this->stop(); + this->Stop(); } } -void e2d::Spawn::reset() +void e2d::Spawn::Reset() { - Action::reset(); - for (const auto& action : _actions) + Action::Reset(); + for (const auto& action : actions_) { - action->reset(); + action->Reset(); } } -void e2d::Spawn::_resetTime() +void e2d::Spawn::ResetTime() { - for (const auto& action : _actions) + for (const auto& action : actions_) { - action->_resetTime(); + action->ResetTime(); } } -void e2d::Spawn::add(Action * action) +void e2d::Spawn::Add(Action * action) { if (action) { - _actions.push_back(action); - action->retain(); + actions_.push_back(action); + action->Retain(); } } -void e2d::Spawn::add(const std::vector& actions) +void e2d::Spawn::Add(const Actions& actions) { for (const auto &action : actions) { - this->add(action); + this->Add(action); } } -e2d::Spawn * e2d::Spawn::clone() const +e2d::Spawn * e2d::Spawn::Clone() const { auto spawn = new (e2d::autorelease) Spawn(); - for (const auto& action : _actions) + for (const auto& action : actions_) { if (action) { - spawn->add(action->clone()); + spawn->Add(action->Clone()); } } return spawn; } -e2d::Spawn * e2d::Spawn::reverse() const +e2d::Spawn * e2d::Spawn::Reverse() const { auto spawn = new (e2d::autorelease) Spawn(); - if (spawn && !_actions.empty()) + if (spawn && !actions_.empty()) { - std::vector newActions(_actions.size()); - for (auto iter = _actions.crbegin(), iterCrend = _actions.crend(); iter != iterCrend; ++iter) + std::vector newActions(actions_.size()); + for (auto iter = actions_.crbegin(), iterCrend = actions_.crend(); iter != iterCrend; ++iter) { - newActions.push_back((*iter)->reverse()); + newActions.push_back((*iter)->Reverse()); } - spawn->add(newActions); + spawn->Add(newActions); } return spawn; } \ No newline at end of file diff --git a/core/Base/Audio.cpp b/core/Base/Audio.cpp index 2629608e..cc7d4889 100644 --- a/core/Base/Audio.cpp +++ b/core/Base/Audio.cpp @@ -1,60 +1,60 @@ #include "..\e2dbase.h" -e2d::Audio * e2d::Audio::_instance = nullptr; +e2d::Audio * e2d::Audio::instance_ = nullptr; -e2d::Audio * e2d::Audio::getInstance() +e2d::Audio * e2d::Audio::GetInstance() { - if (!_instance) + if (!instance_) { - _instance = new (std::nothrow) Audio; + instance_ = new (std::nothrow) Audio; } - return _instance; + return instance_; } -void e2d::Audio::destroyInstance() +void e2d::Audio::DestroyInstance() { - if (_instance) + if (instance_) { - delete _instance; - _instance = nullptr; + delete instance_; + instance_ = nullptr; } } -IXAudio2 * e2d::Audio::getXAudio2() -{ - return _xAudio2; -} - -IXAudio2MasteringVoice * e2d::Audio::getMasteringVoice() -{ - return _masteringVoice; -} - e2d::Audio::Audio() - : _xAudio2(nullptr) - , _masteringVoice(nullptr) + : x_audio2_(nullptr) + , mastering_voice_(nullptr) { ::CoInitialize(nullptr); ThrowIfFailed( - XAudio2Create(&_xAudio2, 0) + XAudio2Create(&x_audio2_, 0) ); ThrowIfFailed( - _xAudio2->CreateMasteringVoice(&_masteringVoice) + x_audio2_->CreateMasteringVoice(&mastering_voice_) ); } e2d::Audio::~Audio() { - if (_masteringVoice) + if (mastering_voice_) { - _masteringVoice->DestroyVoice(); - _masteringVoice = nullptr; + mastering_voice_->DestroyVoice(); + mastering_voice_ = nullptr; } - SafeRelease(_xAudio2); + SafeRelease(x_audio2_); ::CoUninitialize(); } + +IXAudio2 * e2d::Audio::GetXAudio2() +{ + return x_audio2_; +} + +IXAudio2MasteringVoice * e2d::Audio::GetMasteringVoice() +{ + return mastering_voice_; +} diff --git a/core/Base/GC.cpp b/core/Base/GC.cpp index d601d3fb..a4fc7284 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::getInstance()->autorelease(static_cast(p)); + GC::GetInstance()->AutoRelease(static_cast(p)); } return p; } @@ -22,58 +22,58 @@ void operator delete(void * block, e2d::autorelease_t const &) E2D_NOEXCEPT } -e2d::GC * e2d::GC::getInstance() +e2d::GC * e2d::GC::GetInstance() { - static GC _instance; - return &_instance; + static GC instance_; + return &instance_; } e2d::GC::GC() - : _notifyed(false) - , _cleanup(false) - , _pool() + : notifyed_(false) + , cleanup_(false) + , pool_() { } e2d::GC::~GC() { // 删除所有对象 - Game::getInstance()->clearAllScenes(); - Timer::getInstance()->clearAllTasks(); - ActionManager::getInstance()->clearAll(); + Game::GetInstance()->ClearAllScenes(); + Timer::GetInstance()->ClearAllTasks(); + ActionManager::GetInstance()->ClearAll(); - _cleanup = true; - for (const auto& ref : _pool) + cleanup_ = true; + for (const auto& ref : pool_) { delete ref; } - _pool.clear(); - _cleanup = false; + pool_.clear(); + cleanup_ = false; // 清除缓存 - Image::clearCache(); + Image::ClearCache(); // 清除单例 - Player::destroyInstance(); - Audio::destroyInstance(); - Renderer::destroyInstance(); - Input::destroyInstance(); - Window::destroyInstance(); - Game::destroyInstance(); + Player::DestroyInstance(); + Audio::DestroyInstance(); + Renderer::DestroyInstance(); + Input::DestroyInstance(); + Window::DestroyInstance(); + Game::DestroyInstance(); } -void e2d::GC::flush() +void e2d::GC::Flush() { - if (!_notifyed) + if (!notifyed_) return; - _notifyed = false; - for (auto iter = _pool.begin(); iter != _pool.end();) + notifyed_ = false; + for (auto iter = pool_.begin(); iter != pool_.end();) { - if ((*iter)->getRefCount() <= 0) + if ((*iter)->GetRefCount() <= 0) { delete (*iter); - iter = _pool.erase(iter); + iter = pool_.erase(iter); } else { @@ -82,22 +82,22 @@ void e2d::GC::flush() } } -void e2d::GC::autorelease(Ref * ref) +void e2d::GC::AutoRelease(Ref * ref) { if (ref) { - _pool.insert(ref); + pool_.insert(ref); } } -void e2d::GC::safeRelease(Ref* ref) +void e2d::GC::SafeRelease(Ref* ref) { - if (_cleanup) + if (cleanup_) return; if (ref) { - ref->release(); - _notifyed = true; + ref->Release(); + notifyed_ = true; } } diff --git a/core/Base/Game.cpp b/core/Base/Game.cpp index be7a9156..47ea94c9 100644 --- a/core/Base/Game.cpp +++ b/core/Base/Game.cpp @@ -6,39 +6,33 @@ #include -e2d::Game * e2d::Game::_instance = nullptr; +e2d::Game * e2d::Game::instance_ = nullptr; -e2d::Game * e2d::Game::getInstance() +e2d::Game * e2d::Game::GetInstance() { - if (!_instance) - _instance = new (std::nothrow) Game; - return _instance; + if (!instance_) + instance_ = new (std::nothrow) Game; + return instance_; } -void e2d::Game::destroyInstance() +void e2d::Game::DestroyInstance() { - if (_instance) + if (instance_) { - delete _instance; - _instance = nullptr; + delete instance_; + instance_ = nullptr; } } e2d::Game::Game() - : _quit(true) - , _paused(false) - , _currScene(nullptr) - , _nextScene(nullptr) - , _transition(nullptr) - , _scenes() + : quit_(true) + , paused_(false) + , curr_scene_(nullptr) + , next_scene_(nullptr) + , transition_(nullptr) + , scenes_() { ::CoInitialize(nullptr); - - _window = Window::getInstance(); - _input = Input::getInstance(); - _renderer = Renderer::getInstance(); - _timer = Timer::getInstance(); - _actionManager = ActionManager::getInstance(); } e2d::Game::~Game() @@ -46,46 +40,52 @@ e2d::Game::~Game() ::CoUninitialize(); } -void e2d::Game::start() +void e2d::Game::Start() { - _quit = false; + quit_ = false; + + auto window = Window::GetInstance(); + auto input = Input::GetInstance(); + auto renderer = Renderer::GetInstance(); + auto timer = Timer::GetInstance(); + auto action_manager = ActionManager::GetInstance(); const int minInterval = 5; - Time last = Time::now(); - HWND hWnd = _window->getHWnd(); + Time last = Time::Now(); + HWND hWnd = window->GetHWnd(); ::ShowWindow(hWnd, SW_SHOWNORMAL); ::UpdateWindow(hWnd); - _window->poll(); - updateScene(); + window->Poll(); + UpdateScene(); - while (!_quit) + while (!quit_) { - auto now = Time::now(); + auto now = Time::Now(); auto dur = now - last; - if (dur.milliseconds() > minInterval) + if (dur.Milliseconds() > minInterval) { last = now; - _input->update(); + input->Update(); - if (!_paused) + if (!paused_) { - _timer->update(); - _actionManager->update(); - updateScene(); + timer->Update(); + action_manager->Update(); + UpdateScene(); } - drawScene(); - _window->poll(); - GC::getInstance()->flush(); + DrawScene(); + window->Poll(); + GC::GetInstance()->Flush(); } else { // ID2D1HwndRenderTarget 开启了垂直同步,在渲染时会等待显示器刷新, // 它起到了非常稳定的延时作用,所以大部分时候不需要手动挂起线程进行延时。 // 下面的代码仅在一些情况下(例如窗口最小化时)挂起线程,防止占用过高 CPU 。 - int wait = minInterval - dur.milliseconds(); + int wait = minInterval - dur.Milliseconds(); if (wait > 1) { std::this_thread::sleep_for(std::chrono::milliseconds(wait)); @@ -94,152 +94,152 @@ void e2d::Game::start() } } -void e2d::Game::pause() +void e2d::Game::Pause() { - _paused = true; + paused_ = true; } -void e2d::Game::resume() +void e2d::Game::Resume() { - if (_paused && !_quit) + if (paused_ && !quit_) { - _timer->updateTime(); - _actionManager->updateTime(); + Timer::GetInstance()->UpdateTime(); + ActionManager::GetInstance()->UpdateTime(); } - _paused = false; + paused_ = false; } -bool e2d::Game::isPaused() +bool e2d::Game::IsPaused() { - return _paused; + return paused_; } -void e2d::Game::quit() +void e2d::Game::Quit() { - _quit = true; + quit_ = true; } -void e2d::Game::pushScene(Scene * scene, bool saveCurrentScene) +void e2d::Game::PushScene(Scene * scene, bool save_current_scene) { if (!scene) return; // 保存下一场景的指针 - if (_nextScene) _nextScene->release(); - _nextScene = scene; - _nextScene->retain(); + if (next_scene_) next_scene_->Release(); + next_scene_ = scene; + next_scene_->Retain(); - if (saveCurrentScene && _currScene) + if (save_current_scene && curr_scene_) { - _scenes.push(_currScene); + scenes_.push(curr_scene_); } } -void e2d::Game::pushScene(Transition * transition, bool saveCurrentScene) +void e2d::Game::PushScene(Transition * transition, bool save_current_scene) { if (!transition) return; - pushScene(transition->_inScene, saveCurrentScene); + PushScene(transition->in_scene_, save_current_scene); - if (_transition) + if (transition_) { - _transition->_stop(); - _transition->release(); + transition_->Stop(); + transition_->Release(); } - _transition = transition; - _transition->retain(); + transition_ = transition; + transition_->Retain(); // 初始化场景切换动画 - if (!_transition->_init(this, _currScene)) + if (!transition_->Init(this, curr_scene_)) { WARN("Transition initialize failed!"); - _transition->release(); - _transition = nullptr; + transition_->Release(); + transition_ = nullptr; } } -e2d::Scene* e2d::Game::popScene() +e2d::Scene* e2d::Game::PopScene() { // 栈为空时,调用返回场景函数失败 - if (_scenes.size() == 0) + if (scenes_.size() == 0) { - WARN("Scene stack is empty!"); + WARN("Scene stack Is empty!"); return nullptr; } - _nextScene = _scenes.top(); - _nextScene->release(); - _scenes.pop(); + next_scene_ = scenes_.top(); + next_scene_->Release(); + scenes_.pop(); - return _nextScene; + return next_scene_; } -e2d::Scene * e2d::Game::popScene(Transition * transition) +e2d::Scene * e2d::Game::PopScene(Transition * transition) { if (!transition) return nullptr; - auto scene = popScene(); + auto scene = PopScene(); if (scene) { - if (_transition) + if (transition_) { - _transition->_stop(); - _transition->release(); + transition_->Stop(); + transition_->Release(); } - _transition = transition; - _transition->retain(); + transition_ = transition; + transition_->Retain(); - _transition->_inScene = scene; - _transition->_inScene->retain(); + transition_->in_scene_ = scene; + transition_->in_scene_->Retain(); // 初始化场景切换动画 - if (!_transition->_init(this, _currScene)) + if (!transition_->Init(this, curr_scene_)) { WARN("Transition initialize failed!"); - _transition->release(); - _transition = nullptr; + transition_->Release(); + transition_ = nullptr; } } return scene; } -void e2d::Game::clearAllScenes() +void e2d::Game::ClearAllScenes() { - while (!_scenes.empty()) + while (!scenes_.empty()) { - _scenes.top()->release(); - _scenes.pop(); + scenes_.top()->Release(); + scenes_.pop(); } } -e2d::Scene * e2d::Game::getCurrentScene() +e2d::Scene * e2d::Game::GetCurrentScene() { - return _currScene; + return curr_scene_; } -const std::stack& e2d::Game::getSceneStack() +const std::stack& e2d::Game::GetSceneStack() { - return _scenes; + return scenes_; } -bool e2d::Game::isTransitioning() const +bool e2d::Game::IsTransitioning() const { - return _transition != nullptr; + return transition_ != nullptr; } -void e2d::Game::updateScene() +void e2d::Game::UpdateScene() { - if (_transition) + if (transition_) { - _transition->_update(); + transition_->Update(); - if (_transition->isDone()) + if (transition_->IsDone()) { - _transition->release(); - _transition = nullptr; + transition_->Release(); + transition_ = nullptr; } else { @@ -247,36 +247,36 @@ void e2d::Game::updateScene() } } - if (_nextScene) + if (next_scene_) { - if (_currScene) + if (curr_scene_) { - _currScene->onExit(); - if (_scenes.empty() || _scenes.top() != _currScene) + curr_scene_->OnExit(); + if (scenes_.empty() || scenes_.top() != curr_scene_) { - _currScene->release(); + curr_scene_->Release(); } } - _nextScene->onEnter(); + next_scene_->OnEnter(); - _currScene = _nextScene; - _nextScene = nullptr; + curr_scene_ = next_scene_; + next_scene_ = nullptr; } } -void e2d::Game::drawScene() +void e2d::Game::DrawScene() { - _renderer->beginDraw(); + Renderer::GetInstance()->BeginDraw(); { - if (_transition) + if (transition_) { - _transition->_render(); + transition_->Draw(); } - else if (_currScene) + else if (curr_scene_) { - _currScene->visit(); + curr_scene_->Visit(); } } - _renderer->endDraw(); + Renderer::GetInstance()->EndDraw(); } diff --git a/core/Base/Input.cpp b/core/Base/Input.cpp index 9cdb51ab..0c6177ad 100644 --- a/core/Base/Input.cpp +++ b/core/Base/Input.cpp @@ -4,33 +4,33 @@ #pragma comment(lib, "dinput8.lib") -e2d::Input * e2d::Input::_instance = nullptr; +e2d::Input * e2d::Input::instance_ = nullptr; -e2d::Input * e2d::Input::getInstance() +e2d::Input * e2d::Input::GetInstance() { - if (!_instance) - _instance = new (std::nothrow) Input; - return _instance; + if (!instance_) + instance_ = new (std::nothrow) Input; + return instance_; } -void e2d::Input::destroyInstance() +void e2d::Input::DestroyInstance() { - if (_instance) + if (instance_) { - delete _instance; - _instance = nullptr; + delete instance_; + instance_ = nullptr; } } e2d::Input::Input() - : _directInput(false) - , _keyboardDevice(false) - , _mouseDevice(false) + : direct_input_(false) + , keyboard_device_(false) + , mouse_device_(false) { ::CoInitialize(nullptr); - ZeroMemory(_keyBuffer, sizeof(_keyBuffer)); - ZeroMemory(&_mouseState, sizeof(_mouseState)); + ZeroMemory(key_buffer_, sizeof(key_buffer_)); + ZeroMemory(&mouse_state_, sizeof(mouse_state_)); // 初始化接口对象 ThrowIfFailed( @@ -38,135 +38,135 @@ e2d::Input::Input() HINST_THISCOMPONENT, DIRECTINPUT_VERSION, IID_IDirectInput8, - (void**)&_directInput, + (void**)&direct_input_, nullptr ) ); - HWND hwnd = Window::getInstance()->getHWnd(); + HWND hwnd = Window::GetInstance()->GetHWnd(); // 初始化键盘设备 ThrowIfFailed( - _directInput->CreateDevice( + direct_input_->CreateDevice( GUID_SysKeyboard, - &_keyboardDevice, + &keyboard_device_, nullptr ) ); - _keyboardDevice->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); - _keyboardDevice->SetDataFormat(&c_dfDIKeyboard); - _keyboardDevice->Acquire(); - _keyboardDevice->Poll(); + keyboard_device_->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); + keyboard_device_->SetDataFormat(&c_dfDIKeyboard); + keyboard_device_->Acquire(); + keyboard_device_->Poll(); // 初始化鼠标设备 ThrowIfFailed( - _directInput->CreateDevice( + direct_input_->CreateDevice( GUID_SysMouse, - &_mouseDevice, + &mouse_device_, nullptr ) ); - _mouseDevice->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); - _mouseDevice->SetDataFormat(&c_dfDIMouse); - _mouseDevice->Acquire(); - _mouseDevice->Poll(); + mouse_device_->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); + mouse_device_->SetDataFormat(&c_dfDIMouse); + mouse_device_->Acquire(); + mouse_device_->Poll(); } e2d::Input::~Input() { - if (_keyboardDevice) - _keyboardDevice->Unacquire(); - if (_mouseDevice) - _mouseDevice->Unacquire(); + if (keyboard_device_) + keyboard_device_->Unacquire(); + if (mouse_device_) + mouse_device_->Unacquire(); - SafeRelease(_mouseDevice); - SafeRelease(_keyboardDevice); - SafeRelease(_directInput); + SafeRelease(mouse_device_); + SafeRelease(keyboard_device_); + SafeRelease(direct_input_); ::CoUninitialize(); } -void e2d::Input::update() +void e2d::Input::Update() { - if (_keyboardDevice) + if (keyboard_device_) { - HRESULT hr = _keyboardDevice->Poll(); + HRESULT hr = keyboard_device_->Poll(); if (FAILED(hr)) { - hr = _keyboardDevice->Acquire(); + hr = keyboard_device_->Acquire(); while (hr == DIERR_INPUTLOST) - hr = _keyboardDevice->Acquire(); + hr = keyboard_device_->Acquire(); } else { - _keyboardDevice->GetDeviceState(sizeof(_keyBuffer), (void**)&_keyBuffer); + keyboard_device_->GetDeviceState(sizeof(key_buffer_), (void**)&key_buffer_); } } - if (_mouseDevice) + if (mouse_device_) { - HRESULT hr = _mouseDevice->Poll(); + HRESULT hr = mouse_device_->Poll(); if (FAILED(hr)) { - hr = _mouseDevice->Acquire(); + hr = mouse_device_->Acquire(); while (hr == DIERR_INPUTLOST) - hr = _mouseDevice->Acquire(); + hr = mouse_device_->Acquire(); } else { - _mouseDevice->GetDeviceState(sizeof(_mouseState), (void**)&_mouseState); + mouse_device_->GetDeviceState(sizeof(mouse_state_), (void**)&mouse_state_); } } } -bool e2d::Input::isDown(KeyCode key) +bool e2d::Input::IsDown(KeyCode key) { - if (_keyBuffer[static_cast(key)] & 0x80) + if (key_buffer_[static_cast(key)] & 0x80) return true; return false; } -bool e2d::Input::isDown(MouseCode code) +bool e2d::Input::IsDown(MouseCode code) { - if (_mouseState.rgbButtons[static_cast(code)] & 0x80) + if (mouse_state_.rgbButtons[static_cast(code)] & 0x80) return true; return false; } -float e2d::Input::getMouseX() +float e2d::Input::GetMouseX() { - return getMousePos().x; + return GetMousePos().x; } -float e2d::Input::getMouseY() +float e2d::Input::GetMouseY() { - return getMousePos().y; + return GetMousePos().y; } -e2d::Point e2d::Input::getMousePos() +e2d::Point e2d::Input::GetMousePos() { - auto window = Window::getInstance(); - float dpi = window->getDpi(); + auto window = Window::GetInstance(); + float dpi = window->GetDpi(); POINT mousePos; ::GetCursorPos(&mousePos); - ::ScreenToClient(window->getHWnd(), &mousePos); + ::ScreenToClient(window->GetHWnd(), &mousePos); return Point(mousePos.x * 96.f / dpi, mousePos.y * 96.f / dpi); } -float e2d::Input::getMouseDeltaX() +float e2d::Input::GetMouseDeltaX() { - return (float)_mouseState.lX; + return (float)mouse_state_.lX; } -float e2d::Input::getMouseDeltaY() +float e2d::Input::GetMouseDeltaY() { - return (float)_mouseState.lY; + return (float)mouse_state_.lY; } -float e2d::Input::getMouseDeltaZ() +float e2d::Input::GetMouseDeltaZ() { - return (float)_mouseState.lZ; + return (float)mouse_state_.lZ; } diff --git a/core/Base/Renderer.cpp b/core/Base/Renderer.cpp index 2733b568..c75697cf 100644 --- a/core/Base/Renderer.cpp +++ b/core/Base/Renderer.cpp @@ -3,130 +3,89 @@ #include "..\e2dnode.h" -e2d::Renderer* e2d::Renderer::_instance = nullptr; -ID2D1Factory* e2d::Renderer::_factory = nullptr; -IWICImagingFactory* e2d::Renderer::_imagingFactory = nullptr; -IDWriteFactory* e2d::Renderer::_writeFactory = nullptr; -ID2D1StrokeStyle* e2d::Renderer::_miterStrokeStyle = nullptr; -ID2D1StrokeStyle* e2d::Renderer::_bevelStrokeStyle = nullptr; -ID2D1StrokeStyle* e2d::Renderer::_roundStrokeStyle = nullptr; +e2d::Renderer* e2d::Renderer::instance_ = nullptr; +ID2D1Factory* e2d::Renderer::factory_ = nullptr; +IWICImagingFactory* e2d::Renderer::imaging_factory_ = nullptr; +IDWriteFactory* e2d::Renderer::write_factory_ = nullptr; +ID2D1StrokeStyle* e2d::Renderer::miter_stroke_style_ = nullptr; +ID2D1StrokeStyle* e2d::Renderer::bevel_stroke_style_ = nullptr; +ID2D1StrokeStyle* e2d::Renderer::round_stroke_style_ = nullptr; -e2d::Renderer * e2d::Renderer::getInstance() +e2d::Renderer * e2d::Renderer::GetInstance() { - if (!_instance) + if (!instance_) { - _instance = new (std::nothrow) Renderer; + instance_ = new (std::nothrow) Renderer; } - return _instance; + return instance_; } -void e2d::Renderer::destroyInstance() +void e2d::Renderer::DestroyInstance() { - if (_instance) + if (instance_) { - delete _instance; - _instance = nullptr; + delete instance_; + instance_ = nullptr; - SafeRelease(_miterStrokeStyle); - SafeRelease(_bevelStrokeStyle); - SafeRelease(_roundStrokeStyle); - SafeRelease(_factory); - SafeRelease(_imagingFactory); - SafeRelease(_writeFactory); + SafeRelease(miter_stroke_style_); + SafeRelease(bevel_stroke_style_); + SafeRelease(round_stroke_style_); + SafeRelease(factory_); + SafeRelease(imaging_factory_); + SafeRelease(write_factory_); } } e2d::Renderer::Renderer() - : _showFps(false) - , _lastRenderTime(Time::now()) - , _renderTimes(0) - , _fpsFormat(nullptr) - , _fpsLayout(nullptr) - , _renderTarget(nullptr) - , _solidBrush(nullptr) - , _textRenderer(nullptr) - , _clearColor(D2D1::ColorF(D2D1::ColorF::Black)) + : show_fps_(false) + , last_render_time_(Time::Now()) + , render_times_(0) + , fps_text_format_(nullptr) + , fps_text_layout_(nullptr) + , render_target_(nullptr) + , solid_brush_(nullptr) + , text_renderer_(nullptr) + , clear_color_(D2D1::ColorF(D2D1::ColorF::Black)) { ::CoInitialize(nullptr); - - HWND hWnd = Window::getInstance()->getHWnd(); - - RECT rc; - GetClientRect(hWnd, &rc); - - D2D1_SIZE_U size = D2D1::SizeU( - rc.right - rc.left, - rc.bottom - rc.top - ); - - // 创建设备相关资源。这些资源应在 Direct2D 设备消失时重建 - // 创建一个 Direct2D 渲染目标 - ThrowIfFailed( - getFactory()->CreateHwndRenderTarget( - D2D1::RenderTargetProperties(), - D2D1::HwndRenderTargetProperties( - hWnd, - size, - D2D1_PRESENT_OPTIONS_NONE), - &_renderTarget - ) - ); - - // 创建画刷 - ThrowIfFailed( - _renderTarget->CreateSolidColorBrush( - D2D1::ColorF(D2D1::ColorF::White), - &_solidBrush - ) - ); - - // 创建自定义的文字渲染器 - ThrowIfFailed( - TextRenderer::Create( - &_textRenderer, - getFactory(), - _renderTarget, - _solidBrush - ) - ); } e2d::Renderer::~Renderer() { - SafeRelease(_fpsFormat); - SafeRelease(_fpsLayout); - SafeRelease(_textRenderer); - SafeRelease(_solidBrush); - SafeRelease(_renderTarget); + SafeRelease(fps_text_format_); + SafeRelease(fps_text_layout_); + SafeRelease(text_renderer_); + SafeRelease(solid_brush_); + SafeRelease(render_target_); ::CoUninitialize(); } -void e2d::Renderer::beginDraw() +void e2d::Renderer::BeginDraw() { - // 开始渲染 - _renderTarget->BeginDraw(); + auto render_target = GetRenderTarget(); + render_target->BeginDraw(); // 使用背景色清空屏幕 - _renderTarget->Clear(_clearColor); + render_target->Clear(clear_color_); } -void e2d::Renderer::endDraw() +void e2d::Renderer::EndDraw() { - if (_showFps) + if (show_fps_) { - int duration = (Time::now() - _lastRenderTime).milliseconds(); + int duration = (Time::Now() - last_render_time_).Milliseconds(); - ++_renderTimes; + ++render_times_; if (duration >= 100) { - String fpsText = String::format(L"FPS: %.1f", (1000.f / duration * _renderTimes)); - _lastRenderTime = Time::now(); - _renderTimes = 0; + String fpsText = String::Format(L"FPS: %.1f", (1000.f / duration * render_times_)); + last_render_time_ = Time::Now(); + render_times_ = 0; - if (!_fpsFormat) + if (!fps_text_format_) { ThrowIfFailed( - getWriteFactory()->CreateTextFormat( + GetWriteFactory()->CreateTextFormat( L"", nullptr, DWRITE_FONT_WEIGHT_NORMAL, @@ -134,34 +93,34 @@ void e2d::Renderer::endDraw() DWRITE_FONT_STRETCH_NORMAL, 20, L"", - &_fpsFormat + &fps_text_format_ ) ); ThrowIfFailed( - _fpsFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP) + fps_text_format_->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP) ); } - SafeRelease(_fpsLayout); + SafeRelease(fps_text_layout_); ThrowIfFailed( - getWriteFactory()->CreateTextLayout( + GetWriteFactory()->CreateTextLayout( (const WCHAR *)fpsText, - (UINT32)fpsText.length(), - _fpsFormat, + (UINT32)fpsText.GetLength(), + fps_text_format_, 0, 0, - &_fpsLayout + &fps_text_layout_ ) ); } - if (_fpsLayout) + if (fps_text_layout_) { - _renderTarget->SetTransform(D2D1::Matrix3x2F::Identity()); - _solidBrush->SetOpacity(1.0f); - _textRenderer->SetTextStyle( + render_target_->SetTransform(D2D1::Matrix3x2F::Identity()); + solid_brush_->SetOpacity(1.0f); + text_renderer_->SetTextStyle( D2D1::ColorF(D2D1::ColorF::White), TRUE, D2D1::ColorF(D2D1::ColorF::Black, 0.4f), @@ -170,13 +129,13 @@ void e2d::Renderer::endDraw() ); ThrowIfFailed( - _fpsLayout->Draw(nullptr, _textRenderer, 10, 0) + fps_text_layout_->Draw(nullptr, text_renderer_, 10, 0) ); } } // 终止渲染 - HRESULT hr = _renderTarget->EndDraw(); + HRESULT hr = render_target_->EndDraw(); if (hr == D2DERR_RECREATE_TARGET) { @@ -184,11 +143,11 @@ void e2d::Renderer::endDraw() // 并在下一次调用时重建资源 hr = S_OK; - SafeRelease(_fpsFormat); - SafeRelease(_fpsLayout); - SafeRelease(_textRenderer); - SafeRelease(_solidBrush); - SafeRelease(_renderTarget); + SafeRelease(fps_text_format_); + SafeRelease(fps_text_layout_); + SafeRelease(text_renderer_); + SafeRelease(solid_brush_); + SafeRelease(render_target_); } if (FAILED(hr)) @@ -197,42 +156,103 @@ void e2d::Renderer::endDraw() } } -e2d::Color e2d::Renderer::getBackgroundColor() +e2d::E2DTextRenderer * e2d::Renderer::GetTextRenderer() { - return _clearColor; + if (!text_renderer_) + { + // 创建自定义的文字渲染器 + ThrowIfFailed( + E2DTextRenderer::Create( + &text_renderer_, + GetFactory(), + GetRenderTarget(), + GetSolidBrush() + ) + ); + } + return text_renderer_; } -void e2d::Renderer::setBackgroundColor(Color color) +ID2D1HwndRenderTarget * e2d::Renderer::GetRenderTarget() { - _clearColor = (D2D1_COLOR_F)color; + if (!render_target_) + { + HWND hWnd = Window::GetInstance()->GetHWnd(); + + RECT rc; + GetClientRect(hWnd, &rc); + + D2D1_SIZE_U size = D2D1::SizeU( + rc.right - rc.left, + rc.bottom - rc.top + ); + + // 创建设备相关资源。这些资源应在 Direct2D 设备消失时重建 + // 创建一个 Direct2D 渲染目标 + ThrowIfFailed( + GetFactory()->CreateHwndRenderTarget( + D2D1::RenderTargetProperties(), + D2D1::HwndRenderTargetProperties( + hWnd, + size, + D2D1_PRESENT_OPTIONS_NONE), + &render_target_ + ) + ); + } + return render_target_; } -void e2d::Renderer::showFps(bool show) +ID2D1SolidColorBrush * e2d::Renderer::GetSolidBrush() { - _showFps = show; + if (!solid_brush_) + { + ThrowIfFailed( + GetRenderTarget()->CreateSolidColorBrush( + D2D1::ColorF(D2D1::ColorF::White), + &solid_brush_ + ) + ); + } + return solid_brush_; } -ID2D1Factory * e2d::Renderer::getFactory() +e2d::Color e2d::Renderer::GetBackgroundColor() { - if (!_factory) + return clear_color_; +} + +void e2d::Renderer::SetBackgroundColor(const Color& color) +{ + clear_color_ = (D2D1_COLOR_F)color; +} + +void e2d::Renderer::ShowFps(bool show) +{ + show_fps_ = show; +} + +ID2D1Factory * e2d::Renderer::GetFactory() +{ + if (!factory_) { ::CoInitialize(nullptr); ThrowIfFailed( D2D1CreateFactory( D2D1_FACTORY_TYPE_SINGLE_THREADED, - &_factory + &factory_ ) ); ::CoUninitialize(); } - return _factory; + return factory_; } -IWICImagingFactory * e2d::Renderer::getImagingFactory() +IWICImagingFactory * e2d::Renderer::GetImagingFactory() { - if (!_imagingFactory) + if (!imaging_factory_) { ::CoInitialize(nullptr); @@ -242,18 +262,18 @@ IWICImagingFactory * e2d::Renderer::getImagingFactory() nullptr, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, - reinterpret_cast(&_imagingFactory) + reinterpret_cast(&imaging_factory_) ) ); ::CoUninitialize(); } - return _imagingFactory; + return imaging_factory_; } -IDWriteFactory * e2d::Renderer::getWriteFactory() +IDWriteFactory * e2d::Renderer::GetWriteFactory() { - if (!_writeFactory) + if (!write_factory_) { ::CoInitialize(nullptr); @@ -261,21 +281,21 @@ IDWriteFactory * e2d::Renderer::getWriteFactory() DWriteCreateFactory( DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), - reinterpret_cast(&_writeFactory) + reinterpret_cast(&write_factory_) ) ); ::CoUninitialize(); } - return _writeFactory; + return write_factory_; } -ID2D1StrokeStyle * e2d::Renderer::getMiterStrokeStyle() +ID2D1StrokeStyle * e2d::Renderer::GetMiterStrokeStyle() { - if (!_miterStrokeStyle) + if (!miter_stroke_style_) { ThrowIfFailed( - getFactory()->CreateStrokeStyle( + GetFactory()->CreateStrokeStyle( D2D1::StrokeStyleProperties( D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT, @@ -286,19 +306,19 @@ ID2D1StrokeStyle * e2d::Renderer::getMiterStrokeStyle() 0.0f), nullptr, 0, - &_miterStrokeStyle + &miter_stroke_style_ ) ); } - return _miterStrokeStyle; + return miter_stroke_style_; } -ID2D1StrokeStyle * e2d::Renderer::getBevelStrokeStyle() +ID2D1StrokeStyle * e2d::Renderer::GetBevelStrokeStyle() { - if (!_bevelStrokeStyle) + if (!bevel_stroke_style_) { ThrowIfFailed( - getFactory()->CreateStrokeStyle( + GetFactory()->CreateStrokeStyle( D2D1::StrokeStyleProperties( D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT, @@ -309,19 +329,19 @@ ID2D1StrokeStyle * e2d::Renderer::getBevelStrokeStyle() 0.0f), nullptr, 0, - &_bevelStrokeStyle + &bevel_stroke_style_ ) ); } - return _bevelStrokeStyle; + return bevel_stroke_style_; } -ID2D1StrokeStyle * e2d::Renderer::getRoundStrokeStyle() +ID2D1StrokeStyle * e2d::Renderer::GetRoundStrokeStyle() { - if (!_roundStrokeStyle) + if (!round_stroke_style_) { ThrowIfFailed( - getFactory()->CreateStrokeStyle( + GetFactory()->CreateStrokeStyle( D2D1::StrokeStyleProperties( D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT, @@ -332,9 +352,9 @@ ID2D1StrokeStyle * e2d::Renderer::getRoundStrokeStyle() 0.0f), nullptr, 0, - &_roundStrokeStyle + &round_stroke_style_ ) ); } - return _roundStrokeStyle; + return round_stroke_style_; } diff --git a/core/Base/Window.cpp b/core/Base/Window.cpp index 7e3d122d..959034a4 100644 --- a/core/Base/Window.cpp +++ b/core/Base/Window.cpp @@ -8,36 +8,36 @@ #define REGISTER_CLASS L"Easy2DApp" -e2d::Window * e2d::Window::_instance = nullptr; +e2d::Window * e2d::Window::instance_ = nullptr; -e2d::Window * e2d::Window::getInstance() +e2d::Window * e2d::Window::GetInstance() { - if (!_instance) - _instance = new (std::nothrow) Window; - return _instance; + if (!instance_) + instance_ = new (std::nothrow) Window; + return instance_; } -void e2d::Window::destroyInstance() +void e2d::Window::DestroyInstance() { - if (_instance) + if (instance_) { - delete _instance; - _instance = nullptr; + delete instance_; + instance_ = nullptr; } } e2d::Window::Window() - : _hWnd(nullptr) - , _width(640) - , _height(480) - , _title(L"Easy2D Game") - , _iconID(0) - , _dpi(0.f) + : hWnd_(nullptr) + , width_(640) + , height_(480) + , title_(L"Easy2D Game") + , icon_id_(0) + , dpi_(0.f) { ::CoInitialize(nullptr); // 获取系统 DPI - _dpi = static_cast(::GetDpiForSystem()); + dpi_ = static_cast(::GetDpiForSystem()); } e2d::Window::~Window() @@ -47,15 +47,15 @@ e2d::Window::~Window() ::FreeConsole(); // 关闭窗口 - if (_hWnd) - ::DestroyWindow(_hWnd); + if (hWnd_) + ::DestroyWindow(hWnd_); ::CoUninitialize(); } -bool e2d::Window::createMutex(const String & mutex) +bool e2d::Window::CheckMutex(const String & mutex) { - if (mutex.isEmpty()) + if (mutex.IsEmpty()) return false; HANDLE hMutex = ::CreateMutex(nullptr, TRUE, LPCWSTR(L"Easy2DApp-" + mutex)); @@ -70,10 +70,10 @@ bool e2d::Window::createMutex(const String & mutex) // 关闭进程互斥体 ::CloseHandle(hMutex); // 打开游戏窗口 - if (!this->_title.isEmpty()) + if (!this->title_.IsEmpty()) { // 获取窗口句柄 - HWND hProgramWnd = ::FindWindow(REGISTER_CLASS, (LPCTSTR)_title); + HWND hProgramWnd = ::FindWindow(REGISTER_CLASS, (LPCTSTR)title_); if (hProgramWnd) { // 获取窗口显示状态 @@ -90,10 +90,10 @@ bool e2d::Window::createMutex(const String & mutex) return true; } -e2d::Rect e2d::Window::_locate(int width, int height) +e2d::Rect e2d::Window::Locate(int width, int height) { Rect result; - RECT wRECT = { 0, 0, LONG(ceil(width * _dpi / 96.f)), LONG(ceil(height * _dpi / 96.f)) }; + RECT wRECT = { 0, 0, LONG(ceil(width * dpi_ / 96.f)), LONG(ceil(height * dpi_ / 96.f)) }; int maxWidth = ::GetSystemMetrics(SM_CXSCREEN); int maxHeight = ::GetSystemMetrics(SM_CYSCREEN); @@ -103,7 +103,7 @@ e2d::Rect e2d::Window::_locate(int width, int height) height = static_cast(wRECT.bottom - wRECT.top); // 当输入的窗口大小比分辨率大时,给出警告 - WARN_IF(maxWidth < width || maxHeight < height, "The window is larger than screen!"); + WARN_IF(maxWidth < width || maxHeight < height, "The window Is larger than screen!"); width = std::min(width, maxWidth); height = std::min(height, maxHeight); @@ -111,43 +111,43 @@ e2d::Rect e2d::Window::_locate(int width, int height) return std::move(Rect(x, y, float(width), float(height))); } -void e2d::Window::poll() +void e2d::Window::Poll() { - while (::PeekMessage(&_msg, nullptr, 0, 0, PM_REMOVE)) + while (::PeekMessage(&msg_, nullptr, 0, 0, PM_REMOVE)) { - ::TranslateMessage(&_msg); - ::DispatchMessage(&_msg); + ::TranslateMessage(&msg_); + ::DispatchMessage(&msg_); } } -int e2d::Window::getWidth() const +int e2d::Window::GetWidth() const { - return _width; + return width_; } -int e2d::Window::getHeight() const +int e2d::Window::GetHeight() const { - return _height; + return height_; } -e2d::Size e2d::Window::getSize() const +e2d::Size e2d::Window::GetSize() const { - return Size(float(_width), float(_height)); + return e2d::Size(float(width_), float(height_)); } -float e2d::Window::getDpi() const +float e2d::Window::GetDpi() const { - return _dpi; + return dpi_; } -e2d::String e2d::Window::getTitle() const +const e2d::String& e2d::Window::GetTitle() const { - return _title; + return title_; } -HWND e2d::Window::getHWnd() +HWND e2d::Window::GetHWnd() { - if (!_hWnd) + if (!hWnd_) { WNDCLASSEX wcex = { 0 }; wcex.cbSize = sizeof(WNDCLASSEX); @@ -162,11 +162,11 @@ HWND e2d::Window::getHWnd() wcex.lpszMenuName = nullptr; wcex.hCursor = ::LoadCursor(nullptr, IDC_ARROW); - if (_iconID != 0) + if (icon_id_ != 0) { wcex.hIcon = (HICON)::LoadImage( HINST_THISCOMPONENT, - MAKEINTRESOURCE(_iconID), + MAKEINTRESOURCE(icon_id_), IMAGE_ICON, 0, 0, @@ -178,13 +178,13 @@ HWND e2d::Window::getHWnd() RegisterClassEx(&wcex); // 计算窗口大小 - Rect clientRect = _locate(_width, _height); + Rect clientRect = Locate(width_, height_); // 创建窗口 - _hWnd = ::CreateWindowEx( + hWnd_ = ::CreateWindowEx( NULL, REGISTER_CLASS, - (LPCTSTR)_title, + (LPCTSTR)title_, WINDOW_STYLE, int(clientRect.origin.x), int(clientRect.origin.y), @@ -196,10 +196,10 @@ HWND e2d::Window::getHWnd() this ); - if (_hWnd) + if (hWnd_) { // 禁用输入法 - setTypewritingEnabled(false); + SetTypewritingEnabled(false); // 禁用控制台关闭按钮 HWND consoleHWnd = ::GetConsoleWindow(); if (consoleHWnd) @@ -214,22 +214,22 @@ HWND e2d::Window::getHWnd() throw SystemException("Create window failed"); } } - return _hWnd; + return hWnd_; } -void e2d::Window::setSize(int width, int height) +void e2d::Window::SetSize(int width, int height) { - if (_width == width && _height == height) + if (width_ == width && height_ == height) return; - _width = width; - _height = height; + width_ = width; + height_ = height; - if (_hWnd) + if (hWnd_) { - Rect wRect = _locate(width, height); + Rect wRect = Locate(width, height); ::MoveWindow( - _hWnd, + hWnd_, int(wRect.origin.x), int(wRect.origin.y), int(wRect.size.width), @@ -239,28 +239,28 @@ void e2d::Window::setSize(int width, int height) } } -void e2d::Window::setTitle(const String& title) +void e2d::Window::SetTitle(const String& title) { - _title = title; - if (_hWnd) + title_ = title; + if (hWnd_) { - ::SetWindowText(_hWnd, (LPCWSTR)title); + ::SetWindowText(hWnd_, (LPCWSTR)title); } } -void e2d::Window::setIcon(int iconID) +void e2d::Window::SetIcon(int icon_id) { - this->_iconID = iconID; - if (_hWnd) + this->icon_id_ = icon_id; + if (hWnd_) { - HICON hIcon = (HICON)::LoadImage(HINST_THISCOMPONENT, MAKEINTRESOURCE(iconID), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); + HICON hIcon = (HICON)::LoadImage(HINST_THISCOMPONENT, MAKEINTRESOURCE(icon_id), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); // 设置窗口的图标 - ::SendMessage(_hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon); - ::SendMessage(_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); + ::SendMessage(hWnd_, WM_SETICON, ICON_BIG, (LPARAM)hIcon); + ::SendMessage(hWnd_, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); } } -void e2d::Window::setCursor(Cursor cursor) +void e2d::Window::SetCursor(Cursor cursor) { LPCWSTR pCursorName = nullptr; switch (cursor) @@ -293,7 +293,7 @@ void e2d::Window::setCursor(Cursor cursor) ::SetCursor(hCursor); } -void e2d::Window::setConsoleEnabled(bool enabled) +void e2d::Window::SetConsoleEnabled(bool enabled) { // 查找已存在的控制台句柄 HWND hwnd = ::GetConsoleWindow(); @@ -330,7 +330,7 @@ void e2d::Window::setConsoleEnabled(bool enabled) } } -void e2d::Window::setTypewritingEnabled(bool enabled) +void e2d::Window::SetTypewritingEnabled(bool enabled) { static HIMC hImc = nullptr; @@ -338,7 +338,7 @@ void e2d::Window::setTypewritingEnabled(bool enabled) { if (hImc != nullptr) { - ::ImmAssociateContext(getHWnd(), hImc); + ::ImmAssociateContext(GetHWnd(), hImc); hImc = nullptr; } } @@ -346,48 +346,48 @@ void e2d::Window::setTypewritingEnabled(bool enabled) { if (hImc == nullptr) { - hImc = ::ImmAssociateContext(getHWnd(), nullptr); + hImc = ::ImmAssociateContext(GetHWnd(), nullptr); } } } -bool e2d::Window::popup(const String & text, const String & title, Popup style, bool hasCancel) +bool e2d::Window::Popup(const String & text, const String & title, PopupStyle style, bool has_cancel) { UINT type = 0; switch (style) { - case e2d::Window::Popup::Information: + case PopupStyle::Info: type = MB_ICONINFORMATION; break; - case e2d::Window::Popup::Warning: + case PopupStyle::Warning: type = MB_ICONWARNING; break; - case e2d::Window::Popup::Error: + case PopupStyle::Error: type = MB_ICONERROR; break; default: break; } - if (hasCancel) + if (has_cancel) { type |= MB_OKCANCEL; } - Game::getInstance()->pause(); - int ret = ::MessageBox(_hWnd, (LPCWSTR)text, (LPCWSTR)title, type); - Game::getInstance()->resume(); + Game::GetInstance()->Pause(); + int ret = ::MessageBox(hWnd_, (LPCWSTR)text, (LPCWSTR)title, type); + Game::GetInstance()->Resume(); return ret == IDOK; } -LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +LRESULT e2d::Window::WndProc(HWND hWnd, UINT msg, WPARAM w_param, LPARAM l_param) { LRESULT result = 0; - if (uMsg == WM_CREATE) + if (msg == WM_CREATE) { - LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam; + LPCREATESTRUCT pcs = (LPCREATESTRUCT)l_param; Window *window = (Window *)pcs->lpCreateParams; ::SetWindowLongPtrW( @@ -407,7 +407,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ) ); - switch (uMsg) + switch (msg) { // 处理鼠标消息 @@ -423,13 +423,13 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_MOUSEMOVE: case WM_MOUSEWHEEL: { - auto game = Game::getInstance(); - if (game->isTransitioning()) + auto game = Game::GetInstance(); + if (game->IsTransitioning()) break; - if (game->getCurrentScene()) + if (game->GetCurrentScene()) { - game->getCurrentScene()->dispatch(MouseEvent(hWnd, uMsg, wParam, lParam, window->_dpi), false); + game->GetCurrentScene()->Dispatch(MouseEvent(hWnd, msg, w_param, l_param, window->dpi_), false); } } result = 0; @@ -440,13 +440,13 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_KEYDOWN: case WM_KEYUP: { - auto game = Game::getInstance(); - if (game->isTransitioning()) + auto game = Game::GetInstance(); + if (game->IsTransitioning()) break; - if (game->getCurrentScene()) + if (game->GetCurrentScene()) { - game->getCurrentScene()->dispatch(KeyEvent(hWnd, uMsg, wParam, lParam), false); + game->GetCurrentScene()->Dispatch(KeyEvent(hWnd, msg, w_param, l_param), false); } } result = 0; @@ -456,19 +456,19 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) // 处理窗口大小变化消息 case WM_SIZE: { - UINT width = LOWORD(lParam); - UINT height = HIWORD(lParam); + UINT width = LOWORD(l_param); + UINT height = HIWORD(l_param); - if (wParam == SIZE_RESTORED) + if (w_param == SIZE_RESTORED) { - window->_width = static_cast(width * 96.f / window->_dpi); - window->_height = static_cast(height * 96.f / window->_dpi); + window->width_ = static_cast(width * 96.f / window->dpi_); + window->height_ = static_cast(height * 96.f / window->dpi_); } // 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染 // 目标适当。它可能会调用失败,但是这里可以忽略有可能的 // 错误,因为这个错误将在下一次调用 EndDraw 时产生 - auto pRT = Renderer::getInstance()->getRenderTarget(); + auto pRT = Renderer::GetInstance()->GetRenderTarget(); if (pRT) { pRT->Resize(D2D1::SizeU(width, height)); @@ -479,7 +479,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) // 处理窗口标题变化消息 case WM_SETTEXT: { - window->_title = (const wchar_t*)lParam; + window->title_ = (const wchar_t*)l_param; } break; @@ -496,7 +496,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) // 重绘窗口 case WM_PAINT: { - Game::getInstance()->drawScene(); + Game::GetInstance()->DrawScene(); ValidateRect(hWnd, nullptr); } result = 0; @@ -506,11 +506,11 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) // 窗口关闭消息 case WM_CLOSE: { - auto game = Game::getInstance(); - auto currScene = game->getCurrentScene(); - if (!currScene || currScene->onCloseWindow()) + auto game = Game::GetInstance(); + auto currScene = game->GetCurrentScene(); + if (!currScene || currScene->OnCloseWindow()) { - game->quit(); + game->Quit(); } } result = 0; @@ -530,7 +530,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (!hasHandled) { - result = DefWindowProc(hWnd, uMsg, wParam, lParam); + result = DefWindowProc(hWnd, msg, w_param, l_param); } } return result; diff --git a/core/Common/Collider.cpp b/core/Common/Collider.cpp index e0422074..6efcece1 100644 --- a/core/Common/Collider.cpp +++ b/core/Common/Collider.cpp @@ -3,103 +3,103 @@ #include "..\e2dnode.h" e2d::Collider::Collider(Node * parent) - : _visible(true) - , _color(Color::Blue, 0.6f) - , _parentNode(parent) - , _geometry(nullptr) - , _enabled(true) - , _shape(Collider::Shape::None) - , _notify(true) + : visible_(true) + , border_color_(Color::Blue, 0.6f) + , parent_node_(parent) + , geometry_(nullptr) + , enabled_(true) + , shape_(Collider::Shape::None) + , notify_(true) { } e2d::Collider::~Collider() { - SafeRelease(_geometry); + SafeRelease(geometry_); } -e2d::Color e2d::Collider::getColor() const +const e2d::Color& e2d::Collider::GetBorderColor() const { - return _color; + return border_color_; } -e2d::Collider::Shape e2d::Collider::getShape() const +e2d::Collider::Shape e2d::Collider::GetShape() const { - return _shape; + return shape_; } -e2d::Node * e2d::Collider::getNode() const +e2d::Node * e2d::Collider::GetNode() const { - return _parentNode; + return parent_node_; } -ID2D1Geometry * e2d::Collider::getGeometry() const +ID2D1Geometry * e2d::Collider::GetGeometry() const { - return _geometry; + return geometry_; } -void e2d::Collider::setShape(Shape shape) +void e2d::Collider::SetShape(Shape shape) { - if (_shape == shape) + if (shape_ == shape) return; - _shape = shape; + shape_ = shape; if (shape == Shape::None) { - SafeRelease(_geometry); - CollisionManager::getInstance()->__removeCollider(this); + SafeRelease(geometry_); + CollisionManager::GetInstance()->RemoveCollider(this); } else { - this->recreate(); - CollisionManager::getInstance()->__addCollider(this); + this->Recreate(); + CollisionManager::GetInstance()->AddCollider(this); } } -void e2d::Collider::setCollisionNotify(bool notify) +void e2d::Collider::SetCollisionNotify(bool notify) { - _notify = notify; + notify_ = notify; } -void e2d::Collider::setEnabled(bool enabled) +void e2d::Collider::SetEnabled(bool enabled) { - _enabled = enabled; + enabled_ = enabled; } -void e2d::Collider::setVisible(bool visible) +void e2d::Collider::SetVisible(bool visible) { - _visible = visible; + visible_ = visible; } -void e2d::Collider::setColor(Color color) +void e2d::Collider::SetBorderColor(const Color& color) { - _color = color; + border_color_ = color; } -void e2d::Collider::render() +void e2d::Collider::Draw() { - if (_geometry && _enabled && _visible) + if (geometry_ && enabled_ && visible_) { - auto renderer = Renderer::getInstance(); + auto renderer = Renderer::GetInstance(); // 获取纯色画刷 - ID2D1SolidColorBrush * brush = renderer->getSolidColorBrush(); + ID2D1SolidColorBrush * brush = renderer->GetSolidBrush(); // 设置画刷颜色和透明度 - brush->SetColor((D2D1_COLOR_F)_color); + brush->SetColor((D2D1_COLOR_F)border_color_); brush->SetOpacity(1.f); // 绘制几何碰撞体 - renderer->getRenderTarget()->DrawGeometry(_geometry, brush, 1.5f); + renderer->GetRenderTarget()->DrawGeometry(geometry_, brush, 1.5f); } } -e2d::Collider::Relation e2d::Collider::getRelationWith(Collider * collider) const +e2d::Collider::Relation e2d::Collider::GetRelationWith(Collider * collider) const { - if (_geometry && collider->_geometry) + if (geometry_ && collider->geometry_) { - if (_enabled && collider->_enabled) + if (enabled_ && collider->enabled_) { D2D1_GEOMETRY_RELATION relation; - _geometry->CompareWithGeometry( - collider->_geometry, + geometry_->CompareWithGeometry( + collider->geometry_, D2D1::Matrix3x2F::Identity(), &relation ); @@ -110,66 +110,66 @@ e2d::Collider::Relation e2d::Collider::getRelationWith(Collider * collider) cons return Relation::Unknown; } -bool e2d::Collider::isEnabled() const +bool e2d::Collider::IsEnabled() const { - return _enabled; + return enabled_; } -bool e2d::Collider::isVisible() const +bool e2d::Collider::IsVisible() const { - return _visible; + return visible_; } -bool e2d::Collider::isCollisionNotify() const +bool e2d::Collider::IsCollisionNotify() const { - return _notify; + return notify_; } -void e2d::Collider::recreate() +void e2d::Collider::Recreate() { - if (!_enabled || _shape == Shape::None) + if (!enabled_ || shape_ == Shape::None) return; - SafeRelease(_geometry); - auto factory = Renderer::getFactory(); + SafeRelease(geometry_); + auto factory = Renderer::GetFactory(); - switch (_shape) + switch (shape_) { case Shape::Rect: { ID2D1RectangleGeometry* rectangle = nullptr; factory->CreateRectangleGeometry( - D2D1::RectF(0, 0, _parentNode->getRealWidth(), _parentNode->getRealHeight()), + D2D1::RectF(0, 0, parent_node_->GetRealWidth(), parent_node_->GetRealHeight()), &rectangle ); - _geometry = rectangle; + geometry_ = rectangle; } break; case Shape::Circle: { - float minSide = std::min(_parentNode->getRealWidth(), _parentNode->getRealHeight()); + float minSide = std::min(parent_node_->GetRealWidth(), parent_node_->GetRealHeight()); ID2D1EllipseGeometry* circle = nullptr; factory->CreateEllipseGeometry( D2D1::Ellipse( D2D1::Point2F( - _parentNode->getRealWidth() / 2, - _parentNode->getRealHeight() / 2 + parent_node_->GetRealWidth() / 2, + parent_node_->GetRealHeight() / 2 ), minSide / 2, minSide / 2 ), &circle ); - _geometry = circle; + geometry_ = circle; } break; case Shape::Ellipse: { - float halfWidth = _parentNode->getWidth() / 2, - halfHeight = _parentNode->getHeight() / 2; + float halfWidth = parent_node_->GetWidth() / 2, + halfHeight = parent_node_->GetHeight() / 2; ID2D1EllipseGeometry* ellipse = nullptr; factory->CreateEllipseGeometry( @@ -181,17 +181,17 @@ void e2d::Collider::recreate() halfHeight), &ellipse ); - _geometry = ellipse; + geometry_ = ellipse; } break; } ID2D1TransformedGeometry * transformed; factory->CreateTransformedGeometry( - _geometry, - _parentNode->_finalMatri, + geometry_, + parent_node_->final_matrix_, &transformed ); - SafeRelease(_geometry); - _geometry = transformed; + SafeRelease(geometry_); + geometry_ = transformed; } diff --git a/core/Common/Color.cpp b/core/Common/Color.cpp index d5690073..1d48901d 100644 --- a/core/Common/Color.cpp +++ b/core/Common/Color.cpp @@ -33,13 +33,19 @@ e2d::Color::Color(float r, float g, float b, float alpha) } e2d::Color::Color(UINT rgb) + : r(((rgb & sc_redMask) >> sc_redShift) / 255.f) + , g(((rgb & sc_greenMask) >> sc_greenShift) / 255.f) + , b(((rgb & sc_blueMask) >> sc_blueShift) / 255.f) + , a(1.f) { - _init(rgb, 1); } e2d::Color::Color(UINT rgb, float alpha) + : r(((rgb & sc_redMask) >> sc_redShift) / 255.f) + , g(((rgb & sc_greenMask) >> sc_greenShift) / 255.f) + , b(((rgb & sc_blueMask) >> sc_blueShift) / 255.f) + , a(alpha) { - _init(rgb, alpha); } e2d::Color::Color(const D2D1_COLOR_F& color) @@ -54,11 +60,3 @@ e2d::Color::operator D2D1_COLOR_F() const { return std::move(D2D1::ColorF(r, g, b, a)); } - -void e2d::Color::_init(UINT rgb, float alpha) -{ - r = ((rgb & sc_redMask) >> sc_redShift) / 255.f; - g = ((rgb & sc_greenMask) >> sc_greenShift) / 255.f; - b = ((rgb & sc_blueMask) >> sc_blueShift) / 255.f; - a = alpha; -} diff --git a/core/Common/Duration.cpp b/core/Common/Duration.cpp index 94a27ac5..d5c08768 100644 --- a/core/Common/Duration.cpp +++ b/core/Common/Duration.cpp @@ -3,77 +3,77 @@ using namespace std::chrono; e2d::Duration::Duration() - : _ms() + : duration_ms_() { } e2d::Duration::Duration(float seconds) - : _ms(static_cast(seconds * 1000.f)) + : duration_ms_(static_cast(seconds * 1000.f)) { } -int e2d::Duration::milliseconds() const +int e2d::Duration::Milliseconds() const { - return static_cast(_ms.count()); + return static_cast(duration_ms_.count()); } -float e2d::Duration::seconds() const +float e2d::Duration::Seconds() const { - return _ms.count() / 1000.f; + return duration_ms_.count() / 1000.f; } bool e2d::Duration::operator==(const Duration & other) const { - return _ms == other._ms; + return duration_ms_ == other.duration_ms_; } bool e2d::Duration::operator!=(const Duration & other) const { - return _ms != other._ms; + return duration_ms_ != other.duration_ms_; } bool e2d::Duration::operator>(const Duration & other) const { - return _ms > other._ms; + return duration_ms_ > other.duration_ms_; } bool e2d::Duration::operator>=(const Duration & other) const { - return _ms >= other._ms; + return duration_ms_ >= other.duration_ms_; } bool e2d::Duration::operator<(const Duration & other) const { - return _ms < other._ms; + return duration_ms_ < other.duration_ms_; } bool e2d::Duration::operator<=(const Duration & other) const { - return _ms <= other._ms; + return duration_ms_ <= other.duration_ms_; } e2d::Duration e2d::Duration::operator+(Duration const & other) const { Duration d; - d._ms = _ms + other._ms; + d.duration_ms_ = duration_ms_ + other.duration_ms_; return std::move(d); } e2d::Duration e2d::Duration::operator-(Duration const & other) const { Duration d; - d._ms = _ms - other._ms; + d.duration_ms_ = duration_ms_ - other.duration_ms_; return std::move(d); } e2d::Duration & e2d::Duration::operator+=(Duration const &other) { - _ms += other._ms; + duration_ms_ += other.duration_ms_; return (*this); } e2d::Duration & e2d::Duration::operator-=(Duration const &other) { - _ms -= other._ms; + duration_ms_ -= other.duration_ms_; return (*this); } diff --git a/core/Common/Function.cpp b/core/Common/Function.cpp index eb9ac9cc..520e405d 100644 --- a/core/Common/Function.cpp +++ b/core/Common/Function.cpp @@ -1,28 +1,28 @@ #include "..\e2dcommon.h" e2d::Function::Function() - : _func(nullptr) + : func_(nullptr) {} e2d::Function::Function(std::nullptr_t) - : _func(nullptr) + : func_(nullptr) { } e2d::Function::Function(std::function func) - : _func(func) + : func_(func) { } void e2d::Function::operator()(void) const { - if (_func) + if (func_) { - _func(); + func_(); } } e2d::Function::operator bool() const { - return static_cast(_func); + return static_cast(func_); } \ No newline at end of file diff --git a/core/Common/Image.cpp b/core/Common/Image.cpp index e9efae81..ab13e2a1 100644 --- a/core/Common/Image.cpp +++ b/core/Common/Image.cpp @@ -2,108 +2,108 @@ #include "..\e2dbase.h" #include "..\e2dtool.h" -std::map e2d::Image::_bitmapCache; +std::map e2d::Image::bitmap_cache_; e2d::Image::Image() - : _bitmap(nullptr) - , _cropRect() + : bitmap_(nullptr) + , crop_rect_() { } e2d::Image::Image(const Resource& res) - : _bitmap(nullptr) - , _cropRect() + : bitmap_(nullptr) + , crop_rect_() { - this->open(res); + this->Open(res); } -e2d::Image::Image(const Resource& res, const Rect& cropRect) - : _bitmap(nullptr) - , _cropRect() +e2d::Image::Image(const Resource& res, const Rect& crop_rect) + : bitmap_(nullptr) + , crop_rect_() { - this->open(res); - this->crop(cropRect); + this->Open(res); + this->Crop(crop_rect); } -e2d::Image::Image(const String & fileName) - : _bitmap(nullptr) - , _cropRect() +e2d::Image::Image(const String & file_name) + : bitmap_(nullptr) + , crop_rect_() { - this->open(fileName); + this->Open(file_name); } -e2d::Image::Image(const String & fileName, const Rect & cropRect) - : _bitmap(nullptr) - , _cropRect() +e2d::Image::Image(const String & file_name, const Rect & crop_rect) + : bitmap_(nullptr) + , crop_rect_() { - this->open(fileName); - this->crop(cropRect); + this->Open(file_name); + this->Crop(crop_rect); } e2d::Image::~Image() { } -bool e2d::Image::open(const Resource& res) +bool e2d::Image::Open(const Resource& res) { - if (!Image::preload(res)) + if (!Image::Preload(res)) { WARN("Load Image from file failed!"); return false; } - this->_setBitmap(_bitmapCache.at(res.resNameId)); + this->SetBitmap(bitmap_cache_.at(res.name)); return true; } -bool e2d::Image::open(const String & fileName) +bool e2d::Image::Open(const String & file_name) { - WARN_IF(fileName.isEmpty(), "Image open failed! Invalid file name."); + WARN_IF(file_name.IsEmpty(), "Image Open failed! Invalid file name."); - if (fileName.isEmpty()) + if (file_name.IsEmpty()) return false; - if (!Image::preload(fileName)) + if (!Image::Preload(file_name)) { WARN("Load Image from file failed!"); return false; } - this->_setBitmap(_bitmapCache.at(fileName.hash())); + this->SetBitmap(bitmap_cache_.at(file_name.GetHash())); return true; } -void e2d::Image::crop(const Rect& cropRect) +void e2d::Image::Crop(const Rect& crop_rect) { - if (_bitmap) + if (bitmap_) { - _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); + crop_rect_.origin.x = std::min(std::max(crop_rect.origin.x, 0.f), this->GetSourceWidth()); + crop_rect_.origin.y = std::min(std::max(crop_rect.origin.y, 0.f), this->GetSourceHeight()); + crop_rect_.size.width = std::min(std::max(crop_rect.size.width, 0.f), this->GetSourceWidth() - crop_rect.origin.x); + crop_rect_.size.height = std::min(std::max(crop_rect.size.height, 0.f), this->GetSourceHeight() - crop_rect.origin.y); } } -float e2d::Image::getWidth() const +float e2d::Image::GetWidth() const { - return _cropRect.size.width; + return crop_rect_.size.width; } -float e2d::Image::getHeight() const +float e2d::Image::GetHeight() const { - return _cropRect.size.height; + return crop_rect_.size.height; } -e2d::Size e2d::Image::getSize() const +e2d::Size e2d::Image::GetSize() const { - return _cropRect.size; + return crop_rect_.size; } -float e2d::Image::getSourceWidth() const +float e2d::Image::GetSourceWidth() const { - if (_bitmap) + if (bitmap_) { - return _bitmap->GetSize().width; + return bitmap_->GetSize().width; } else { @@ -111,11 +111,11 @@ float e2d::Image::getSourceWidth() const } } -float e2d::Image::getSourceHeight() const +float e2d::Image::GetSourceHeight() const { - if (_bitmap) + if (bitmap_) { - return _bitmap->GetSize().height; + return bitmap_->GetSize().height; } else { @@ -123,11 +123,11 @@ float e2d::Image::getSourceHeight() const } } -e2d::Size e2d::Image::getSourceSize() const +e2d::Size e2d::Image::GetSourceSize() const { - if (_bitmap) + if (bitmap_) { - return Size(getSourceWidth(), getSourceHeight()); + return Size(GetSourceWidth(), GetSourceHeight()); } else { @@ -135,30 +135,30 @@ e2d::Size e2d::Image::getSourceSize() const } } -float e2d::Image::getCropX() const +float e2d::Image::GetCropX() const { - return _cropRect.origin.x; + return crop_rect_.origin.x; } -float e2d::Image::getCropY() const +float e2d::Image::GetCropY() const { - return _cropRect.origin.y; + return crop_rect_.origin.y; } -e2d::Point e2d::Image::getCropPos() const +e2d::Point e2d::Image::GetCropPos() const { - return _cropRect.origin; + return crop_rect_.origin; } -bool e2d::Image::preload(const Resource& res) +bool e2d::Image::Preload(const Resource& res) { - if (_bitmapCache.find(res.resNameId) != _bitmapCache.end()) + if (bitmap_cache_.find(res.name) != bitmap_cache_.end()) { return true; } - IWICImagingFactory *pImagingFactory = Renderer::getImagingFactory(); - ID2D1HwndRenderTarget* pRenderTarget = Renderer::getInstance()->getRenderTarget(); + IWICImagingFactory *pImagingFactory = Renderer::GetImagingFactory(); + ID2D1HwndRenderTarget* pRenderTarget = Renderer::GetInstance()->GetRenderTarget(); IWICBitmapDecoder *pDecoder = nullptr; IWICBitmapFrameDecode *pSource = nullptr; IWICStream *pStream = nullptr; @@ -172,8 +172,8 @@ bool e2d::Image::preload(const Resource& res) // 定位资源 imageResHandle = ::FindResourceW( HINST_THISCOMPONENT, - MAKEINTRESOURCE(res.resNameId), - (LPCWSTR)res.resType + MAKEINTRESOURCE(res.name), + (LPCWSTR)res.type ); HRESULT hr = imageResHandle ? S_OK : E_FAIL; @@ -264,7 +264,7 @@ bool e2d::Image::preload(const Resource& res) if (SUCCEEDED(hr)) { - _bitmapCache.insert(std::make_pair(res.resNameId, pBitmap)); + bitmap_cache_.insert(std::make_pair(res.name, pBitmap)); } // 释放相关资源 @@ -276,18 +276,18 @@ bool e2d::Image::preload(const Resource& res) return SUCCEEDED(hr); } -bool e2d::Image::preload(const String & fileName) +bool e2d::Image::Preload(const String & file_name) { - String actualFilePath = File(fileName).getPath(); - if (actualFilePath.isEmpty()) + String actualFilePath = File(file_name).GetPath(); + if (actualFilePath.IsEmpty()) return false; - size_t hash = actualFilePath.hash(); - if (_bitmapCache.find(hash) != _bitmapCache.end()) + size_t hash = actualFilePath.GetHash(); + if (bitmap_cache_.find(hash) != bitmap_cache_.end()) return true; - IWICImagingFactory *pImagingFactory = Renderer::getImagingFactory(); - ID2D1HwndRenderTarget* pRenderTarget = Renderer::getInstance()->getRenderTarget(); + IWICImagingFactory *pImagingFactory = Renderer::GetImagingFactory(); + ID2D1HwndRenderTarget* pRenderTarget = Renderer::GetInstance()->GetRenderTarget(); IWICBitmapDecoder *pDecoder = nullptr; IWICBitmapFrameDecode *pSource = nullptr; IWICStream *pStream = nullptr; @@ -340,7 +340,7 @@ bool e2d::Image::preload(const String & fileName) if (SUCCEEDED(hr)) { - _bitmapCache.insert(std::make_pair(hash, pBitmap)); + bitmap_cache_.insert(std::make_pair(hash, pBitmap)); } // 释放相关资源 @@ -352,30 +352,30 @@ bool e2d::Image::preload(const String & fileName) return SUCCEEDED(hr); } -void e2d::Image::clearCache() +void e2d::Image::ClearCache() { - if (_bitmapCache.empty()) + if (bitmap_cache_.empty()) return; - for (const auto& bitmap : _bitmapCache) + for (const auto& bitmap : bitmap_cache_) { bitmap.second->Release(); } - _bitmapCache.clear(); + bitmap_cache_.clear(); } -void e2d::Image::_setBitmap(ID2D1Bitmap * bitmap) +void e2d::Image::SetBitmap(ID2D1Bitmap * bitmap) { if (bitmap) { - _bitmap = bitmap; - _cropRect.origin.x = _cropRect.origin.y = 0; - _cropRect.size.width = _bitmap->GetSize().width; - _cropRect.size.height = _bitmap->GetSize().height; + bitmap_ = bitmap; + crop_rect_.origin.x = crop_rect_.origin.y = 0; + crop_rect_.size.width = bitmap_->GetSize().width; + crop_rect_.size.height = bitmap_->GetSize().height; } } -ID2D1Bitmap * e2d::Image::getBitmap() +ID2D1Bitmap * e2d::Image::GetBitmap() { - return _bitmap; + return bitmap_; } diff --git a/core/Common/Point.cpp b/core/Common/Point.cpp index 5c0f2fb8..48463d97 100644 --- a/core/Common/Point.cpp +++ b/core/Common/Point.cpp @@ -20,22 +20,22 @@ e2d::Point::Point(const Point & other) y = other.y; } -e2d::Point e2d::Point::operator+(Point const & p) const +e2d::Point e2d::Point::operator+(const Point & p) const { return Point(x + p.x, y + p.y); } -e2d::Point e2d::Point::operator-(Point const & p) const +e2d::Point e2d::Point::operator-(const Point & p) const { return Point(x - p.x, y - p.y); } -e2d::Point e2d::Point::operator*(float const & value) const +e2d::Point e2d::Point::operator*(float value) const { return Point(x * value, y * value); } -e2d::Point e2d::Point::operator/(float const & value) const +e2d::Point e2d::Point::operator/(float value) const { return Point(x / value, y / value); } @@ -45,7 +45,7 @@ e2d::Point::operator e2d::Size() const return Size(x, y); } -float e2d::Point::distance(const Point &p1, const Point &p2) +float e2d::Point::Distance(const Point &p1, const Point &p2) { return sqrt( (p1.x - p2.x) * (p1.x - p2.x) + diff --git a/core/Common/Rect.cpp b/core/Common/Rect.cpp index 23d8022f..4ca4a78e 100644 --- a/core/Common/Rect.cpp +++ b/core/Common/Rect.cpp @@ -1,28 +1,33 @@ #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.x, pos.y) + , size(size.width, size.height) { - setRect(pos.x, pos.y, size.width, size.height); } e2d::Rect::Rect(const Rect& other) + : origin(other.origin.x, other.origin.y) + , size(other.size.width, other.size.height) { - setRect(other.origin.x, other.origin.y, other.size.width, other.size.height); } e2d::Rect& e2d::Rect::operator= (const Rect& other) { - setRect(other.origin.x, other.origin.y, other.size.width, other.size.height); + origin = other.origin; + size = other.size; return *this; } @@ -31,16 +36,7 @@ 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 +bool e2d::Rect::ContainsPoint(const Point& point) const { if (point.x >= origin.x && point.x <= (origin.y + size.height) && point.y >= origin.y && point.y <= (origin.y + size.height)) @@ -50,7 +46,7 @@ bool e2d::Rect::containsPoint(const Point& point) const return false; } -bool e2d::Rect::intersects(const Rect& rect) const +bool e2d::Rect::Intersects(const Rect& rect) const { return !((origin.x + size.width) < rect.origin.x || (rect.origin.x + rect.size.width) < origin.x || diff --git a/core/Common/Ref.cpp b/core/Common/Ref.cpp index fcd18fe5..7db787b0 100644 --- a/core/Common/Ref.cpp +++ b/core/Common/Ref.cpp @@ -1,7 +1,7 @@ #include "..\e2dcommon.h" e2d::Ref::Ref() - : _refCount(0) + : ref_count_(0) { } @@ -9,17 +9,17 @@ e2d::Ref::~Ref() { } -void e2d::Ref::retain() +void e2d::Ref::Retain() { - _refCount++; + ref_count_++; } -void e2d::Ref::release() +void e2d::Ref::Release() { - _refCount--; + ref_count_--; } -int e2d::Ref::getRefCount() const +int e2d::Ref::GetRefCount() const { - return _refCount; + return ref_count_; } diff --git a/core/Common/Resource.cpp b/core/Common/Resource.cpp index 3a4018db..e3807d62 100644 --- a/core/Common/Resource.cpp +++ b/core/Common/Resource.cpp @@ -1,8 +1,8 @@ #include "..\e2dtool.h" -e2d::Resource::Resource(size_t resNameId, const String & resType) - : resNameId(resNameId) - , resType(resType) +e2d::Resource::Resource(size_t resource_name, const String & resource_type) + : name(resource_name) + , type(resource_type) { } diff --git a/core/Common/Size.cpp b/core/Common/Size.cpp index 3148b697..8d043c7d 100644 --- a/core/Common/Size.cpp +++ b/core/Common/Size.cpp @@ -18,22 +18,22 @@ e2d::Size::Size(const Size & other) height = other.height; } -e2d::Size e2d::Size::operator+(Size const & size) const +e2d::Size e2d::Size::operator+(const Size & other) const { - return Size(width + size.width, height + size.height); + return Size(width + other.width, height + other.height); } -e2d::Size e2d::Size::operator-(Size const & size) const +e2d::Size e2d::Size::operator-(const Size & other) const { - return Size(width - size.width, height - size.height); + return Size(width - other.width, height - other.height); } -e2d::Size e2d::Size::operator*(float const & value) const +e2d::Size e2d::Size::operator*(float value) const { return Size(width * value, height * value); } -e2d::Size e2d::Size::operator/(float const & value) const +e2d::Size e2d::Size::operator/(float value) const { return Size(width / value, height / value); } @@ -48,7 +48,7 @@ e2d::Size e2d::Size::operator-() const return Size(-width, -height); } -bool e2d::Size::operator==(const Size & size) const +bool e2d::Size::operator==(const Size & other) const { - return (width == size.width) && (height == size.height); + return (width == other.width) && (height == other.height); } diff --git a/core/Common/String.cpp b/core/Common/String.cpp index 2d04cea4..f8e6f709 100644 --- a/core/Common/String.cpp +++ b/core/Common/String.cpp @@ -6,76 +6,76 @@ e2d::String::String() - : _str(L"") + : string_(L"") { } e2d::String::String(const wchar_t *str) - : _str(str) + : string_(str) { } e2d::String::String(const char *cstr) - : _str(static_cast(_bstr_t(cstr))) + : string_(static_cast(_bstr_t(cstr))) { } e2d::String::String(e2d::String && str) { - _str = std::move(str._str); + string_ = std::move(str.string_); } e2d::String::String(const e2d::String &str) - : _str(str._str) + : string_(str.string_) { } e2d::String::~String() { - _str.clear(); + string_.clear(); } e2d::String &e2d::String::operator=(const wchar_t *str) { - _str = str; + string_ = str; return (*this); } e2d::String & e2d::String::operator=(const char *cstr) { - _str = static_cast(_bstr_t(cstr)); + string_ = static_cast(_bstr_t(cstr)); return (*this); } -e2d::String e2d::String::parse(int value) +e2d::String e2d::String::Parse(int value) { String tmp; - tmp._str = std::to_wstring(value); + tmp.string_ = std::to_wstring(value); return std::move(tmp); } -e2d::String e2d::String::parse(unsigned int value) +e2d::String e2d::String::Parse(unsigned int value) { String tmp; - tmp._str = std::to_wstring(value); + tmp.string_ = std::to_wstring(value); return std::move(tmp); } -e2d::String e2d::String::parse(float value) +e2d::String e2d::String::Parse(float value) { String tmp; - tmp._str = std::to_wstring(value); + tmp.string_ = std::to_wstring(value); return std::move(tmp); } -e2d::String e2d::String::parse(double value) +e2d::String e2d::String::Parse(double value) { String tmp; - tmp._str = std::to_wstring(value); + tmp.string_ = std::to_wstring(value); return std::move(tmp); } -e2d::String e2d::String::format(const char * format, ...) +e2d::String e2d::String::Format(const char * format, ...) { std::string tmp; @@ -97,7 +97,7 @@ e2d::String e2d::String::format(const char * format, ...) return std::move(str); } -e2d::String e2d::String::format(const wchar_t * format, ...) +e2d::String e2d::String::Format(const wchar_t * format, ...) { std::wstring tmp; @@ -119,14 +119,9 @@ e2d::String e2d::String::format(const wchar_t * format, ...) return std::move(str); } -void e2d::String::swap(String & str1, String & str2) -{ - str1._str.swap(str2._str); -} - e2d::String & e2d::String::operator=(const String &str) { - _str = str._str; + string_ = str.string_; return (*this); } @@ -134,7 +129,7 @@ bool e2d::String::operator==(const wchar_t *str) const { if (str) { - return (_str.compare(str) == 0); + return (string_.compare(str) == 0); } else { @@ -147,7 +142,7 @@ bool e2d::String::operator==(const char *str) const if (str) { String temp(str); - return (_str == temp._str); + return (string_ == temp.string_); } else { @@ -157,14 +152,14 @@ bool e2d::String::operator==(const char *str) const bool e2d::String::operator ==(const e2d::String &str) const { - return _str == str._str; + return string_ == str.string_; } bool e2d::String::operator!=(const wchar_t *str) const { if (str) { - return (_str.compare(str) != 0); + return (string_.compare(str) != 0); } else { @@ -177,7 +172,7 @@ bool e2d::String::operator!=(const char *str) const if (str) { String temp(str); - return (_str != temp._str); + return (string_ != temp.string_); } else { @@ -187,247 +182,247 @@ bool e2d::String::operator!=(const char *str) const bool e2d::String::operator!=(const e2d::String &str) const { - return _str != str._str; + return string_ != str.string_; } -wchar_t &e2d::String::operator[](int index) +wchar_t &e2d::String::operator[](size_t index) { - return _str[size_t(index)]; + return string_[index]; } e2d::String e2d::String::operator+(const wchar_t *str) const { String temp; - temp._str = _str + str; + temp.string_ = string_ + str; return std::move(temp); } e2d::String e2d::String::operator+(const char *str) const { String temp; - temp._str = _str + static_cast(_bstr_t(str)); + temp.string_ = string_ + static_cast(_bstr_t(str)); return std::move(temp); } e2d::String e2d::String::operator+(const e2d::String &str) const { String temp; - temp._str = _str + str._str; + temp.string_ = string_ + str.string_; return std::move(temp); } e2d::String e2d::operator+(const wchar_t *str1, const e2d::String &str2) { String temp; - temp._str = str1 + str2._str; + temp.string_ = str1 + str2.string_; return std::move(temp); } e2d::String e2d::operator+(const char *str1, const String &str2) { String temp; - temp._str = static_cast(_bstr_t(str1)) + str2._str; + temp.string_ = static_cast(_bstr_t(str1)) + str2.string_; return std::move(temp); } e2d::String & e2d::String::operator+=(const wchar_t *str) { - _str += str; + string_ += str; return (*this); } e2d::String & e2d::String::operator+=(const char *str) { - _str += static_cast(_bstr_t(str)); + string_ += static_cast(_bstr_t(str)); return (*this); } e2d::String & e2d::String::operator+=(const String &str) { - _str += str._str; + string_ += str.string_; return (*this); } bool e2d::String::operator>(const String &str) const { - return _str > str._str; + return string_ > str.string_; } bool e2d::String::operator>=(const String &str) const { - return _str >= str._str; + return string_ >= str.string_; } bool e2d::String::operator<(const String &str) const { - return _str < str._str; + return string_ < str.string_; } bool e2d::String::operator<=(const String &str) const { - return _str <= str._str; + return string_ <= str.string_; } e2d::String & e2d::String::operator<<(const String &str) { - _str += str._str; + string_ += str.string_; return (*this); } e2d::String & e2d::String::operator<<(const wchar_t *str) { - _str += str; + string_ += str; return (*this); } e2d::String & e2d::String::operator<<(wchar_t *str) { - _str += str; + string_ += str; return (*this); } e2d::String & e2d::String::operator<<(const char * cstr) { - _str += static_cast(_bstr_t(cstr)); + string_ += static_cast(_bstr_t(cstr)); return (*this); } e2d::String & e2d::String::operator<<(char * cstr) { - _str += static_cast(_bstr_t(cstr)); + string_ += static_cast(_bstr_t(cstr)); return (*this); } e2d::String & e2d::String::operator<<(int value) { - (*this) += String::parse(value); + (*this) += String::Parse(value); return (*this); } e2d::String & e2d::String::operator<<(unsigned int value) { - (*this) += String::parse(value); + (*this) += String::Parse(value); return (*this); } e2d::String & e2d::String::operator<<(float value) { - (*this) += String::parse(value); + (*this) += String::Parse(value); return (*this); } e2d::String & e2d::String::operator<<(double value) { - (*this) += String::parse(value); + (*this) += String::Parse(value); return (*this); } e2d::String::operator const wchar_t*() const { - return _str.c_str(); + return string_.c_str(); } e2d::String::operator wchar_t*() const { - return const_cast(_str.c_str()); + return const_cast(string_.c_str()); } e2d::String::operator std::wstring() const { - return _str; + return string_; } e2d::String::operator std::string() const { - std::string str = static_cast(_bstr_t(_str.c_str())); + std::string str = static_cast(_bstr_t(string_.c_str())); return std::move(str); } -bool e2d::String::isEmpty() const +bool e2d::String::IsEmpty() const { - return _str.empty(); + return string_.empty(); } -int e2d::String::length() const +int e2d::String::GetLength() const { - return static_cast(_str.size()); + return static_cast(string_.size()); } -size_t e2d::String::hash() const +size_t e2d::String::GetHash() const { std::hash hash; - return hash(_str); + return hash(string_); } -wchar_t e2d::String::at(int index) const +const wchar_t& e2d::String::At(size_t index) const { - return _str[size_t(index)]; + return string_.at(index); } -int e2d::String::compare(const String & str) const +int e2d::String::Compare(const String & str) const { - return _str.compare(str._str); + return string_.compare(str.string_); } -e2d::String e2d::String::toUpper() const +e2d::String e2d::String::ToUpper() const { String str(*this); - std::transform(str._str.begin(), str._str.end(), str._str.begin(), std::towupper); + std::transform(str.string_.begin(), str.string_.end(), str.string_.begin(), std::towupper); return std::move(str); } -e2d::String e2d::String::toLower() const +e2d::String e2d::String::ToLower() const { e2d::String str(*this); - std::transform(str._str.begin(), str._str.end(), str._str.begin(), std::towlower); + std::transform(str.string_.begin(), str.string_.end(), str.string_.begin(), std::towlower); return std::move(str); } -int e2d::String::toInt() const +int e2d::String::ToInt() const { - if (_str.empty()) + if (string_.empty()) { return 0; } - return std::stoi(_str, 0, 10); + return std::stoi(string_, 0, 10); } -float e2d::String::toFloat() const +float e2d::String::ToFloat() const { - if (_str.empty()) + if (string_.empty()) { return 0.f; } - return std::stof(_str, 0); + return std::stof(string_, 0); } -double e2d::String::toDouble() const +double e2d::String::ToDouble() const { - if (_str.empty()) + if (string_.empty()) { return 0.0; } - return std::stod(_str, 0); + return std::stod(string_, 0); } -bool e2d::String::toBool() const +bool e2d::String::ToBool() const { - if (_str.empty()) + if (string_.empty()) { return false; } - if (_str.compare(L"0") == 0 || _str.compare(L"false") == 0) + if (string_.compare(L"0") == 0 || string_.compare(L"false") == 0) { return false; } return true; } -e2d::String e2d::String::subtract(int offset, int count) const +e2d::String e2d::String::Subtract(int offset, int count) const { String tmp; - int length = static_cast(_str.size()); + int length = static_cast(string_.size()); if (length == 0 || offset >= length) return std::move(tmp); @@ -437,37 +432,37 @@ e2d::String e2d::String::subtract(int offset, int count) const if (count < 0 || (offset + count) > length) count = length - offset; - tmp._str = _str.substr(offset, count); + tmp.string_ = string_.substr(offset, count); return std::move(tmp); } -void e2d::String::insert(const String & str, int pos) +void e2d::String::Insert(const String & str, int pos) { - _str.insert(size_t(pos), str._str); + string_.insert(size_t(pos), str.string_); } -void e2d::String::replace(const String & from, const String & to) +void e2d::String::Replace(const String & from, const String & to) { - if (from._str.empty()) + if (from.string_.empty()) return; size_t start_pos = 0; - while ((start_pos = _str.find((const wchar_t *)from, start_pos)) != std::wstring::npos) + while ((start_pos = string_.find((const wchar_t *)from, start_pos)) != std::wstring::npos) { - _str.replace(start_pos, from._str.length(), (const wchar_t *)to); - start_pos += to._str.length(); + string_.replace(start_pos, from.string_.length(), (const wchar_t *)to); + start_pos += to.string_.length(); } } -void e2d::String::erase(int offset, int count) +void e2d::String::Erase(int offset, int count) { - _str.erase(size_t(offset), size_t(count)); + string_.erase(size_t(offset), size_t(count)); } -int e2d::String::find(const String & str, int offset) const +int e2d::String::Find(const String & str, int offset) const { size_t index; - if ((index = _str.find(str._str, size_t(offset))) == std::wstring::npos) + if ((index = string_.find(str.string_, size_t(offset))) == std::wstring::npos) { return -1; } @@ -477,26 +472,26 @@ int e2d::String::find(const String & str, int offset) const } } -void e2d::String::clear() +void e2d::String::Clear() { - _str.clear(); + string_.clear(); } std::wostream & e2d::operator<<(std::wostream &cout, const String &str) { - cout << str._str; + cout << str.string_; return cout; } std::wistream & e2d::operator>>(std::wistream &cin, String &str) { - cin >> str._str; + cin >> str.string_; return cin; } std::ostream & e2d::operator<<(std::ostream &cout, const String &str) { - std::string cstr = static_cast(_bstr_t(str._str.c_str())); + std::string cstr = static_cast(_bstr_t(str.string_.c_str())); cout << cstr; return cout; } @@ -505,6 +500,6 @@ std::istream & e2d::operator>>(std::istream &cin, String &str) { std::string temp; cin >> temp; - str._str = static_cast(_bstr_t(temp.c_str())); + str.string_ = static_cast(_bstr_t(temp.c_str())); return cin; } \ No newline at end of file diff --git a/core/Common/Time.cpp b/core/Common/Time.cpp index a709e5ad..79e6f416 100644 --- a/core/Common/Time.cpp +++ b/core/Common/Time.cpp @@ -7,52 +7,52 @@ e2d::Time::Time() { } -time_t e2d::Time::getTimeStamp() const +time_t e2d::Time::GetTimeStamp() const { - auto& duration = time_point_cast(_timePoint).time_since_epoch(); + auto& duration = time_point_cast(time_).time_since_epoch(); return static_cast(duration.count()); } -bool e2d::Time::isZero() const +bool e2d::Time::IsZero() const { - return _timePoint.time_since_epoch().count() == 0LL; + return time_.time_since_epoch().count() == 0LL; } e2d::Time e2d::Time::operator+(Duration const & other) const { Time t; - t._timePoint = _timePoint + milliseconds(other.milliseconds()); + t.time_ = time_ + milliseconds(other.Milliseconds()); return std::move(t); } e2d::Time e2d::Time::operator-(Duration const & other) const { Time t; - t._timePoint = _timePoint - milliseconds(other.milliseconds()); + t.time_ = time_ - milliseconds(other.Milliseconds()); return std::move(t); } e2d::Time & e2d::Time::operator+=(Duration const & other) { - _timePoint += milliseconds(other.milliseconds()); + time_ += milliseconds(other.Milliseconds()); return (*this); } e2d::Time & e2d::Time::operator-=(Duration const &other) { - _timePoint -= milliseconds(other.milliseconds()); + time_ -= milliseconds(other.Milliseconds()); return (*this); } e2d::Duration e2d::Time::operator-(Time const & other) const { - auto ms = duration_cast(_timePoint - other._timePoint).count(); + auto ms = duration_cast(time_ - other.time_).count(); return std::move(Duration(static_cast(ms) / 1000.f)); } -e2d::Time e2d::Time::now() +e2d::Time e2d::Time::Now() { Time t; - t._timePoint = steady_clock::now(); + t.time_ = steady_clock::now(); return std::move(t); } diff --git a/core/Custom/Exception.cpp b/core/Custom/Exception.cpp index c3761dd0..4deccc32 100644 --- a/core/Custom/Exception.cpp +++ b/core/Custom/Exception.cpp @@ -2,17 +2,17 @@ e2d::Exception::Exception() E2D_NOEXCEPT - : _message() + : message_() { } e2d::Exception::Exception(const char * message) E2D_NOEXCEPT - : _message(message) + : message_(message) { } e2d::Exception::Exception(Exception const& other) E2D_NOEXCEPT - : _message(other._message) + : message_(other.message_) { } @@ -23,7 +23,7 @@ e2d::Exception& e2d::Exception::operator=(Exception const& other) E2D_NOEXCEPT return *this; } - _message = other._message; + message_ = other.message_; return *this; } @@ -31,7 +31,7 @@ e2d::Exception::~Exception() E2D_NOEXCEPT { } -const char * e2d::Exception::msg() const +const char * e2d::Exception::GetMsg() const { - return _message; + return message_; } diff --git a/core/Custom/TextRenderer.cpp b/core/Custom/TextRenderer.cpp index 73ca61ad..ffad7e99 100644 --- a/core/Custom/TextRenderer.cpp +++ b/core/Custom/TextRenderer.cpp @@ -3,7 +3,7 @@ using namespace e2d; -TextRenderer::TextRenderer() +E2DTextRenderer::E2DTextRenderer() : cRefCount_(0) , pD2DFactory_(nullptr) , pRT_(nullptr) @@ -16,21 +16,21 @@ TextRenderer::TextRenderer() { } -TextRenderer::~TextRenderer() +E2DTextRenderer::~E2DTextRenderer() { SafeRelease(pD2DFactory_); SafeRelease(pRT_); SafeRelease(pBrush_); } -HRESULT TextRenderer::Create( - TextRenderer** ppTextRenderer, +HRESULT E2DTextRenderer::Create( + E2DTextRenderer** ppTextRenderer, ID2D1Factory* pD2DFactory, ID2D1HwndRenderTarget* pRT, ID2D1SolidColorBrush* pBrush ) { - *ppTextRenderer = new (std::nothrow) TextRenderer(); + *ppTextRenderer = new (std::nothrow) E2DTextRenderer(); if (*ppTextRenderer) { pD2DFactory->AddRef(); @@ -46,29 +46,29 @@ HRESULT TextRenderer::Create( return E_FAIL; } -STDMETHODIMP_(void) TextRenderer::SetTextStyle( +STDMETHODIMP_(void) E2DTextRenderer::SetTextStyle( CONST D2D1_COLOR_F &fillColor, - BOOL hasOutline, - CONST D2D1_COLOR_F &outlineColor, - FLOAT outlineWidth, + BOOL outline, + CONST D2D1_COLOR_F &outline_color, + FLOAT outline_width, D2D1_LINE_JOIN outlineJoin ) { sFillColor_ = fillColor; - bShowOutline_ = hasOutline; - sOutlineColor_ = outlineColor; - fOutlineWidth = 2 * outlineWidth; + bShowOutline_ = outline; + sOutlineColor_ = outline_color; + fOutlineWidth = 2 * outline_width; switch (outlineJoin) { case D2D1_LINE_JOIN_MITER: - pCurrStrokeStyle_ = Renderer::getMiterStrokeStyle(); + pCurrStrokeStyle_ = Renderer::GetMiterStrokeStyle(); break; case D2D1_LINE_JOIN_BEVEL: - pCurrStrokeStyle_ = Renderer::getBevelStrokeStyle(); + pCurrStrokeStyle_ = Renderer::GetBevelStrokeStyle(); break; case D2D1_LINE_JOIN_ROUND: - pCurrStrokeStyle_ = Renderer::getRoundStrokeStyle(); + pCurrStrokeStyle_ = Renderer::GetRoundStrokeStyle(); break; default: pCurrStrokeStyle_ = nullptr; @@ -76,7 +76,7 @@ STDMETHODIMP_(void) TextRenderer::SetTextStyle( } } -STDMETHODIMP TextRenderer::DrawGlyphRun( +STDMETHODIMP E2DTextRenderer::DrawGlyphRun( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, @@ -165,7 +165,7 @@ STDMETHODIMP TextRenderer::DrawGlyphRun( return hr; } -STDMETHODIMP TextRenderer::DrawUnderline( +STDMETHODIMP E2DTextRenderer::DrawUnderline( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, @@ -232,7 +232,7 @@ STDMETHODIMP TextRenderer::DrawUnderline( return S_OK; } -STDMETHODIMP TextRenderer::DrawStrikethrough( +STDMETHODIMP E2DTextRenderer::DrawStrikethrough( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, @@ -299,25 +299,25 @@ STDMETHODIMP TextRenderer::DrawStrikethrough( return S_OK; } -STDMETHODIMP TextRenderer::DrawInlineObject( +STDMETHODIMP E2DTextRenderer::DrawInlineObject( __maybenull void* clientDrawingContext, FLOAT originX, FLOAT originY, IDWriteInlineObject* inlineObject, - BOOL isSideways, - BOOL isRightToLeft, + BOOL IsSideways, + BOOL IsRightToLeft, IUnknown* clientDrawingEffect ) { return E_NOTIMPL; } -STDMETHODIMP_(unsigned long) TextRenderer::AddRef() +STDMETHODIMP_(unsigned long) E2DTextRenderer::AddRef() { return InterlockedIncrement(&cRefCount_); } -STDMETHODIMP_(unsigned long) TextRenderer::Release() +STDMETHODIMP_(unsigned long) E2DTextRenderer::Release() { unsigned long newCount = InterlockedDecrement(&cRefCount_); @@ -330,7 +330,7 @@ STDMETHODIMP_(unsigned long) TextRenderer::Release() return newCount; } -STDMETHODIMP TextRenderer::IsPixelSnappingDisabled( +STDMETHODIMP E2DTextRenderer::IsPixelSnappingDisabled( __maybenull void* clientDrawingContext, __out BOOL* isDisabled ) @@ -339,7 +339,7 @@ STDMETHODIMP TextRenderer::IsPixelSnappingDisabled( return S_OK; } -STDMETHODIMP TextRenderer::GetCurrentTransform( +STDMETHODIMP E2DTextRenderer::GetCurrentTransform( __maybenull void* clientDrawingContext, __out DWRITE_MATRIX* transform ) @@ -348,7 +348,7 @@ STDMETHODIMP TextRenderer::GetCurrentTransform( return S_OK; } -STDMETHODIMP TextRenderer::GetPixelsPerDip( +STDMETHODIMP E2DTextRenderer::GetPixelsPerDip( __maybenull void* clientDrawingContext, __out FLOAT* pixelsPerDip ) @@ -361,7 +361,7 @@ STDMETHODIMP TextRenderer::GetPixelsPerDip( return S_OK; } -STDMETHODIMP TextRenderer::QueryInterface( +STDMETHODIMP E2DTextRenderer::QueryInterface( IID const& riid, void** ppvObject ) diff --git a/core/Custom/VoiceCallback.cpp b/core/Custom/VoiceCallback.cpp index afe2c79c..d9ef4f84 100644 --- a/core/Custom/VoiceCallback.cpp +++ b/core/Custom/VoiceCallback.cpp @@ -11,34 +11,34 @@ e2d::VoiceCallback::~VoiceCallback() void e2d::VoiceCallback::OnLoopEnd(void * pBufferContext) { - if (_loopEndFunc) + if (loop_end_callback_) { - _loopEndFunc(); + loop_end_callback_(); } } void e2d::VoiceCallback::OnStreamEnd() { - if (_streamEndFunc) + if (stream_end_callback_) { - _streamEndFunc(); + stream_end_callback_(); } } void e2d::VoiceCallback::OnBufferEnd(void * pBufferContext) { - if (_loopEndFunc) + if (loop_end_callback_) { - _loopEndFunc(); + loop_end_callback_(); } } -void e2d::VoiceCallback::SetFuncOnStreamEnd(const Function & func) +void e2d::VoiceCallback::SetCallbackOnStreamEnd(const Function & func) { - _streamEndFunc = func; + stream_end_callback_ = func; } -void e2d::VoiceCallback::SetFuncOnLoopEnd(const Function & func) +void e2d::VoiceCallback::SetCallbackOnLoopEnd(const Function & func) { - _loopEndFunc = func; + loop_end_callback_ = func; } diff --git a/core/Event/Collision.cpp b/core/Event/Collision.cpp index 2d4dd6ed..db4a9fb7 100644 --- a/core/Event/Collision.cpp +++ b/core/Event/Collision.cpp @@ -1,14 +1,14 @@ #include "..\e2devent.h" e2d::Collision::Collision() - : _node(nullptr) - , _relation(Collider::Relation::Unknown) + : node_(nullptr) + , relation_(Collider::Relation::Unknown) { } e2d::Collision::Collision(Node* node, Collider::Relation relation) - : _node(node) - , _relation(relation) + : node_(node) + , relation_(relation) { } @@ -16,12 +16,12 @@ e2d::Collision::~Collision() { } -e2d::Node * e2d::Collision::getNode() const +e2d::Node * e2d::Collision::GetNode() const { - return _node; + return node_; } -e2d::Collider::Relation e2d::Collision::getRelation() const +e2d::Collider::Relation e2d::Collision::GetRelation() const { - return _relation; + return relation_; } diff --git a/core/Event/KeyEvent.cpp b/core/Event/KeyEvent.cpp index da44f263..a0d627ab 100644 --- a/core/Event/KeyEvent.cpp +++ b/core/Event/KeyEvent.cpp @@ -1,31 +1,31 @@ #include "..\e2devent.h" -e2d::KeyEvent::KeyEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) - : _code(KeyCode(wParam)) - , _type(Type(message)) - , _count(static_cast((DWORD)lParam & 0x0000FFFF)) +e2d::KeyEvent::KeyEvent(HWND hWnd, UINT message, WPARAM w_param, LPARAM l_param) + : code_(KeyCode(w_param)) + , type_(Type(message)) + , count_(static_cast((DWORD)l_param & 0x0000FFFF)) { } -e2d::KeyCode e2d::KeyEvent::getCode() const +e2d::KeyCode e2d::KeyEvent::GetCode() const { - return _code; + return code_; } -int e2d::KeyEvent::getCount() const +int e2d::KeyEvent::GetCount() const { - return _count; + return count_; } -e2d::KeyEvent::Type e2d::KeyEvent::getType() const +e2d::KeyEvent::Type e2d::KeyEvent::GetType() const { - return _type; + return type_; } -e2d::KeyCode e2d::KeyEvent::convertKeyCode(WPARAM wParam) +e2d::KeyCode e2d::KeyEvent::ToKeyCode(WPARAM w_param) { - switch (wParam) + switch (w_param) { case 'A': return KeyCode::A; case 'B': return KeyCode::B; diff --git a/core/Event/MouseEvent.cpp b/core/Event/MouseEvent.cpp index 5b67ab95..c1568fe0 100644 --- a/core/Event/MouseEvent.cpp +++ b/core/Event/MouseEvent.cpp @@ -1,62 +1,62 @@ #include "..\e2devent.h" #include "..\e2dbase.h" -e2d::MouseEvent::MouseEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, float dpi) - : _message(message) - , _wParam(wParam) - , _lParam(lParam) - , _type(Type(message)) +e2d::MouseEvent::MouseEvent(HWND hWnd, UINT message, WPARAM w_param, LPARAM l_param, float dpi) + : message_(message) + , w_param_(w_param) + , l_param_(l_param) + , type_(Type(message)) { - _pos.x = ((float)(short)LOWORD(lParam)) * 96.f / dpi; - _pos.y = ((float)(short)HIWORD(lParam)) * 96.f / dpi; + pos_.x = ((float)(short)LOWORD(l_param)) * 96.f / dpi; + pos_.y = ((float)(short)HIWORD(l_param)) * 96.f / dpi; } -float e2d::MouseEvent::getX() const +float e2d::MouseEvent::GetX() const { - return _pos.x; + return pos_.x; } -float e2d::MouseEvent::getY() const +float e2d::MouseEvent::GetY() const { - return _pos.y; + return pos_.y; } -e2d::Point e2d::MouseEvent::getPos() const +e2d::Point e2d::MouseEvent::GetPos() const { - return _pos; + return pos_; } -bool e2d::MouseEvent::isShiftDown() const +bool e2d::MouseEvent::IsShiftDown() const { - return GET_KEYSTATE_WPARAM(_wParam) == MK_SHIFT; + return GET_KEYSTATE_WPARAM(w_param_) == MK_SHIFT; } -bool e2d::MouseEvent::isCtrlDown() const +bool e2d::MouseEvent::IsCtrlDown() const { - return GET_KEYSTATE_WPARAM(_wParam) == MK_CONTROL; + return GET_KEYSTATE_WPARAM(w_param_) == MK_CONTROL; } -float e2d::MouseEvent::getWheelDelta() const +float e2d::MouseEvent::GetWheelDelta() const { - return static_cast(GET_WHEEL_DELTA_WPARAM(_wParam)); + return static_cast(GET_WHEEL_DELTA_WPARAM(w_param_)); } -bool e2d::MouseEvent::isLButtonDown() const +bool e2d::MouseEvent::IsLButtonDown() const { - return GET_KEYSTATE_WPARAM(_wParam) == MK_LBUTTON; + return GET_KEYSTATE_WPARAM(w_param_) == MK_LBUTTON; } -bool e2d::MouseEvent::isRButtonDown() const +bool e2d::MouseEvent::IsRButtonDown() const { - return GET_KEYSTATE_WPARAM(_wParam) == MK_RBUTTON; + return GET_KEYSTATE_WPARAM(w_param_) == MK_RBUTTON; } -bool e2d::MouseEvent::isMButtonDown() const +bool e2d::MouseEvent::IsMButtonDown() const { - return GET_KEYSTATE_WPARAM(_wParam) == MK_MBUTTON; + return GET_KEYSTATE_WPARAM(w_param_) == MK_MBUTTON; } -e2d::MouseEvent::Type e2d::MouseEvent::getType() const +e2d::MouseEvent::Type e2d::MouseEvent::GetType() const { - return _type; + return type_; } diff --git a/core/Manager/ActionManager.cpp b/core/Manager/ActionManager.cpp index a356b5d9..9ba975e9 100644 --- a/core/Manager/ActionManager.cpp +++ b/core/Manager/ActionManager.cpp @@ -3,15 +3,15 @@ #include "..\e2dnode.h" -e2d::ActionManager * e2d::ActionManager::getInstance() +e2d::ActionManager * e2d::ActionManager::GetInstance() { static ActionManager instance; return &instance; } e2d::ActionManager::ActionManager() - : _actions() - , _runningActions() + : actions_() + , running_actions_() { } @@ -19,32 +19,32 @@ e2d::ActionManager::~ActionManager() { } -void e2d::ActionManager::update() +void e2d::ActionManager::Update() { - if (_runningActions.empty()) + if (running_actions_.empty()) return; std::vector currActions; - currActions.reserve(_runningActions.size()); + currActions.reserve(running_actions_.size()); std::copy_if( - _runningActions.begin(), - _runningActions.end(), + running_actions_.begin(), + running_actions_.end(), std::back_inserter(currActions), - [](Action* action) { return action->isRunning() && !action->_isDone(); } + [](Action* action) { return action->IsRunning() && !action->IsDone(); } ); // 遍历所有正在运行的动作 for (const auto& action : currActions) - action->_update(); + action->Update(); // 清除完成的动作 - for (auto iter = _runningActions.begin(); iter != _runningActions.end();) + for (auto iter = running_actions_.begin(); iter != running_actions_.end();) { - if ((*iter)->_isDone()) + if ((*iter)->IsDone()) { - (*iter)->release(); - (*iter)->_target = nullptr; - iter = _runningActions.erase(iter); + (*iter)->Release(); + (*iter)->target_ = nullptr; + iter = running_actions_.erase(iter); } else { @@ -53,88 +53,88 @@ void e2d::ActionManager::update() } } -void e2d::ActionManager::__add(Action * action) +void e2d::ActionManager::Add(Action * action) { if (action) { - auto iter = std::find(_actions.begin(), _actions.end(), action); - if (iter == _actions.end()) + auto iter = std::find(actions_.begin(), actions_.end(), action); + if (iter == actions_.end()) { - _actions.push_back(action); + actions_.push_back(action); } } } -void e2d::ActionManager::__remove(Action * action) +void e2d::ActionManager::Remove(Action * action) { - if (_actions.empty() || action == nullptr) + if (actions_.empty() || action == nullptr) return; - auto iter = std::find(_actions.begin(), _actions.end(), action); - if (iter != _actions.end()) + auto iter = std::find(actions_.begin(), actions_.end(), action); + if (iter != actions_.end()) { - _actions.erase(iter); + actions_.erase(iter); } } -void e2d::ActionManager::resumeAllBindedWith(Node * target) +void e2d::ActionManager::ResumeAllBindedWith(Node * target) { - if (_runningActions.empty() || target == nullptr) + if (running_actions_.empty() || target == nullptr) return; - for (const auto& action : _runningActions) + for (const auto& action : running_actions_) { - if (action->getTarget() == target) + if (action->GetTarget() == target) { - action->resume(); + action->Resume(); } } } -void e2d::ActionManager::pauseAllBindedWith(Node * target) +void e2d::ActionManager::PauseAllBindedWith(Node * target) { - if (_runningActions.empty() || target == nullptr) + if (running_actions_.empty() || target == nullptr) return; - for (const auto& action : _runningActions) + for (const auto& action : running_actions_) { - if (action->getTarget() == target) + if (action->GetTarget() == target) { - action->pause(); + action->Pause(); } } } -void e2d::ActionManager::stopAllBindedWith(Node * target) +void e2d::ActionManager::StopAllBindedWith(Node * target) { - if (_runningActions.empty() || target == nullptr) + if (running_actions_.empty() || target == nullptr) return; - for (const auto& action : _runningActions) + for (const auto& action : running_actions_) { - if (action->getTarget() == target) + if (action->GetTarget() == target) { - action->stop(); + action->Stop(); } } } -void e2d::ActionManager::start(Action * action, Node * target, bool paused) +void e2d::ActionManager::Start(Action * action, Node * target, bool paused) { WARN_IF(action == nullptr, "Action NULL pointer exception!"); - WARN_IF(target == nullptr, "Target node NULL pointer exception!"); + WARN_IF(target == nullptr, "GetTarget node NULL pointer exception!"); if (action && target) { - if (action->_target == nullptr) + if (action->target_ == nullptr) { - auto iter = std::find(_runningActions.begin(), _runningActions.end(), action); - if (iter == _runningActions.end()) + auto iter = std::find(running_actions_.begin(), running_actions_.end(), action); + if (iter == running_actions_.end()) { - action->retain(); - action->_startWithTarget(target); - action->_running = !paused; - _runningActions.push_back(action); + action->Retain(); + action->StartWithTarget(target); + action->running_ = !paused; + running_actions_.push_back(action); } } else @@ -144,86 +144,86 @@ void e2d::ActionManager::start(Action * action, Node * target, bool paused) } } -void e2d::ActionManager::resume(const String& name) +void e2d::ActionManager::Resume(const String& name) { - if (_runningActions.empty() || name.isEmpty()) + if (running_actions_.empty() || name.IsEmpty()) return; - for (const auto& action : _runningActions) + for (const auto& action : running_actions_) { - if (action->getName() == name) + if (action->GetName() == name) { - action->resume(); + action->Resume(); } } } -void e2d::ActionManager::pause(const String& name) +void e2d::ActionManager::Pause(const String& name) { - if (_runningActions.empty() || name.isEmpty()) + if (running_actions_.empty() || name.IsEmpty()) return; - for (const auto& action : _runningActions) + for (const auto& action : running_actions_) { - if (action->getName() == name) + if (action->GetName() == name) { - action->pause(); + action->Pause(); } } } -void e2d::ActionManager::stop(const String& name) +void e2d::ActionManager::Stop(const String& name) { - if (_runningActions.empty() || name.isEmpty()) + if (running_actions_.empty() || name.IsEmpty()) return; - for (const auto& action : _runningActions) + for (const auto& action : running_actions_) { - if (action->getName() == name) + if (action->GetName() == name) { - action->stop(); + action->Stop(); } } } -void e2d::ActionManager::clearAllBindedWith(Node * target) +void e2d::ActionManager::ClearAllBindedWith(Node * target) { if (target) { auto iter = std::find_if( - _runningActions.begin(), - _runningActions.end(), - [target](Action* action) ->bool { return action->getTarget() == target; } + running_actions_.begin(), + running_actions_.end(), + [target](Action* action) ->bool { return action->GetTarget() == target; } ); - if (iter != _runningActions.end()) + if (iter != running_actions_.end()) { - (*iter)->release(); - _runningActions.erase(iter); + (*iter)->Release(); + running_actions_.erase(iter); } } } -void e2d::ActionManager::clearAll() +void e2d::ActionManager::ClearAll() { - if (!_runningActions.empty()) + if (!running_actions_.empty()) { - for (const auto& action : _runningActions) + for (const auto& action : running_actions_) { - action->release(); + action->Release(); } - _runningActions.clear(); + running_actions_.clear(); } - _actions.clear(); + actions_.clear(); } -std::vector e2d::ActionManager::get(const String& name) +std::vector e2d::ActionManager::Get(const String& name) { std::vector actions; - for (const auto& action : _actions) + for (const auto& action : actions_) { - if (action->getName() == name) + if (action->GetName() == name) { actions.push_back(action); } @@ -231,15 +231,15 @@ std::vector e2d::ActionManager::get(const String& name) return std::move(actions); } -const std::vector& e2d::ActionManager::getAll() +const std::vector& e2d::ActionManager::GetAll() { - return _actions; + return actions_; } -void e2d::ActionManager::updateTime() +void e2d::ActionManager::UpdateTime() { - for (const auto& action : _runningActions) + for (const auto& action : running_actions_) { - action->_resetTime(); + action->ResetTime(); } } diff --git a/core/Manager/CollisionManager.cpp b/core/Manager/CollisionManager.cpp index 73a4c999..4861f87f 100644 --- a/core/Manager/CollisionManager.cpp +++ b/core/Manager/CollisionManager.cpp @@ -3,14 +3,14 @@ #include "..\e2dtool.h" -e2d::CollisionManager * e2d::CollisionManager::getInstance() +e2d::CollisionManager * e2d::CollisionManager::GetInstance() { static CollisionManager instance; return &instance; } e2d::CollisionManager::CollisionManager() - : _collisionEnabled(false) + : collision_enabled_(false) { } @@ -18,103 +18,103 @@ e2d::CollisionManager::~CollisionManager() { } -void e2d::CollisionManager::__addCollider(Collider * collider) +void e2d::CollisionManager::AddCollider(Collider * collider) { - _colliders.push_back(collider); + colliders_.push_back(collider); } -void e2d::CollisionManager::__removeCollider(Collider * collider) +void e2d::CollisionManager::RemoveCollider(Collider * collider) { - auto iter = std::find(_colliders.begin(), _colliders.end(), collider); - if (iter != _colliders.end()) + auto iter = std::find(colliders_.begin(), colliders_.end(), collider); + if (iter != colliders_.end()) { - _colliders.erase(iter); + colliders_.erase(iter); } } -void e2d::CollisionManager::__updateCollider(Collider* active) +void e2d::CollisionManager::UpdateCollider(Collider* active) { - if (!_collisionEnabled || - Game::getInstance()->isTransitioning()) + if (!collision_enabled_ || + Game::GetInstance()->IsTransitioning()) return; - auto currScene = Game::getInstance()->getCurrentScene(); - if (active->getNode()->getParentScene() != currScene) + auto currScene = Game::GetInstance()->GetCurrentScene(); + if (active->GetNode()->GetParentScene() != currScene) return; std::vector currColliders; - currColliders.reserve(_colliders.size()); + currColliders.reserve(colliders_.size()); std::copy_if( - _colliders.begin(), - _colliders.end(), + colliders_.begin(), + colliders_.end(), std::back_inserter(currColliders), [this, active, currScene](Collider* passive) -> bool { return active != passive && - passive->getNode()->isVisible() && - passive->getNode()->getParentScene() == currScene && - this->isCollidable(active->getNode(), passive->getNode()); + passive->GetNode()->IsVisible() && + passive->GetNode()->GetParentScene() == currScene && + this->IsCollidable(active->GetNode(), passive->GetNode()); } ); for (const auto& passive : currColliders) { // 判断两碰撞体交集情况 - Collider::Relation relation = active->getRelationWith(passive); + Collider::Relation relation = active->GetRelationWith(passive); // 忽略 UNKNOWN 和 DISJOIN 情况 if (relation != Collider::Relation::Unknown && relation != Collider::Relation::Disjoin) { - auto activeNode = active->getNode(); - auto passiveNode = passive->getNode(); + auto activeNode = active->GetNode(); + auto passiveNode = passive->GetNode(); // 触发两次碰撞事件 Collision activeCollision(passiveNode, relation); if (dynamic_cast(activeNode)) - dynamic_cast(activeNode)->handle(activeCollision); + dynamic_cast(activeNode)->Handle(activeCollision); - Collision passiveCollision(activeNode, passive->getRelationWith(active)); + Collision passiveCollision(activeNode, passive->GetRelationWith(active)); if (dynamic_cast(passiveNode)) - dynamic_cast(passiveNode)->handle(passiveCollision); + dynamic_cast(passiveNode)->Handle(passiveCollision); } } } -void e2d::CollisionManager::setCollisionEnabled(bool enabled) +void e2d::CollisionManager::SetCollisionEnabled(bool enabled) { - _collisionEnabled = enabled; + collision_enabled_ = enabled; } -void e2d::CollisionManager::addName(const String & name1, const String & name2) +void e2d::CollisionManager::AddName(const String & name1, const String & name2) { - if (!name1.isEmpty() && !name2.isEmpty()) + if (!name1.IsEmpty() && !name2.IsEmpty()) { - _collisionList.insert(std::make_pair(name1.hash(), name2.hash())); + collision_list_.insert(std::make_pair(name1.GetHash(), name2.GetHash())); } } -void e2d::CollisionManager::addName(const std::vector >& names) +void e2d::CollisionManager::AddName(const std::vector >& names) { for (const auto& name : names) { - if (!name.first.isEmpty() && !name.second.isEmpty()) + if (!name.first.IsEmpty() && !name.second.IsEmpty()) { - _collisionList.insert(std::make_pair(name.first.hash(), name.second.hash())); + collision_list_.insert(std::make_pair(name.first.GetHash(), name.second.GetHash())); } } } -bool e2d::CollisionManager::isCollidable(Node * node1, Node * node2) +bool e2d::CollisionManager::IsCollidable(Node * node1, Node * node2) { - return CollisionManager::isCollidable(node1->getName(), node2->getName()); + return CollisionManager::IsCollidable(node1->GetName(), node2->GetName()); } -bool e2d::CollisionManager::isCollidable(const String & name1, const String & name2) +bool e2d::CollisionManager::IsCollidable(const String & name1, const String & name2) { - size_t hashName1 = name1.hash(), - hashName2 = name2.hash(); + size_t hashName1 = name1.GetHash(), + hashName2 = name2.GetHash(); auto pair1 = std::make_pair(hashName1, hashName2), pair2 = std::make_pair(hashName2, hashName1); - for (const auto& pair : _collisionList) + for (const auto& pair : collision_list_) { if (pair == pair1 || pair == pair2) { diff --git a/core/Node/Button.cpp b/core/Node/Button.cpp index 1b086075..502c7a34 100644 --- a/core/Node/Button.cpp +++ b/core/Node/Button.cpp @@ -6,254 +6,254 @@ #define SET_BUTTON_NODE(Old, New) \ if (New != Old) \ { \ - if (Old) this->removeChild(Old); \ + if (Old) this->RemoveChild(Old); \ if (New) \ { \ - New->setAnchor(_anchorX, _anchorY); \ - this->addChild(New); \ + New->SetAnchor(anchor_.x, anchor_.y); \ + this->AddChild(New); \ } \ Old = New; \ - _updateVisible(); \ + UpdateVisible(); \ } \ e2d::Button::Button() - : _func(nullptr) - , _status(Status::Normal) - , _enabled(true) - , _isSelected(false) - , _normal(nullptr) - , _mouseover(nullptr) - , _selected(nullptr) - , _disabled(nullptr) + : callback_(nullptr) + , status_(Status::Normal) + , enabled_(true) + , is_selected_(false) + , normal_(nullptr) + , mouseover_(nullptr) + , selected_(nullptr) + , disabled_(nullptr) { } e2d::Button::Button(Node * normal, const Function& func) - : _func(nullptr) - , _status(Status::Normal) - , _enabled(true) - , _isSelected(false) - , _normal(nullptr) - , _mouseover(nullptr) - , _selected(nullptr) - , _disabled(nullptr) + : callback_(nullptr) + , status_(Status::Normal) + , enabled_(true) + , is_selected_(false) + , normal_(nullptr) + , mouseover_(nullptr) + , selected_(nullptr) + , disabled_(nullptr) { - this->setNormal(normal); - this->setClickFunc(func); + this->SetNormal(normal); + this->SetCallbackOnClick(func); } e2d::Button::Button(Node * normal, Node * selected, const Function& func) - : _func(nullptr) - , _status(Status::Normal) - , _enabled(true) - , _isSelected(false) - , _normal(nullptr) - , _mouseover(nullptr) - , _selected(nullptr) - , _disabled(nullptr) + : callback_(nullptr) + , status_(Status::Normal) + , enabled_(true) + , is_selected_(false) + , normal_(nullptr) + , mouseover_(nullptr) + , selected_(nullptr) + , disabled_(nullptr) { - this->setNormal(normal); - this->setSelected(selected); - this->setClickFunc(func); + this->SetNormal(normal); + this->SetSelected(selected); + this->SetCallbackOnClick(func); } e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Function& func) - : _func(nullptr) - , _status(Status::Normal) - , _enabled(true) - , _isSelected(false) - , _normal(nullptr) - , _mouseover(nullptr) - , _selected(nullptr) - , _disabled(nullptr) + : callback_(nullptr) + , status_(Status::Normal) + , enabled_(true) + , is_selected_(false) + , normal_(nullptr) + , mouseover_(nullptr) + , selected_(nullptr) + , disabled_(nullptr) { - this->setNormal(normal); - this->setMouseOver(mouseover); - this->setSelected(selected); - this->setClickFunc(func); + this->SetNormal(normal); + this->SetMouseOver(mouseover); + this->SetSelected(selected); + this->SetCallbackOnClick(func); } e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Function& func) - : _func(nullptr) - , _status(Status::Normal) - , _enabled(true) - , _isSelected(false) - , _normal(nullptr) - , _mouseover(nullptr) - , _selected(nullptr) - , _disabled(nullptr) + : callback_(nullptr) + , status_(Status::Normal) + , enabled_(true) + , is_selected_(false) + , normal_(nullptr) + , mouseover_(nullptr) + , selected_(nullptr) + , disabled_(nullptr) { - this->setNormal(normal); - this->setMouseOver(mouseover); - this->setSelected(selected); - this->setDisabled(disabled); - this->setClickFunc(func); + this->SetNormal(normal); + this->SetMouseOver(mouseover); + this->SetSelected(selected); + this->SetDisabled(disabled); + this->SetCallbackOnClick(func); } -bool e2d::Button::isEnable() const +bool e2d::Button::IsEnable() const { - return _enabled; + return enabled_; } -void e2d::Button::setNormal(Node * normal) +void e2d::Button::SetNormal(Node * normal) { - SET_BUTTON_NODE(_normal, normal); + SET_BUTTON_NODE(normal_, normal); if (normal) { - this->setSize(normal->getWidth(), normal->getHeight()); + this->SetSize(normal->GetWidth(), normal->GetHeight()); } } -void e2d::Button::setMouseOver(Node * mouseover) +void e2d::Button::SetMouseOver(Node * mouseover) { - SET_BUTTON_NODE(_mouseover, mouseover); + SET_BUTTON_NODE(mouseover_, mouseover); } -void e2d::Button::setSelected(Node * selected) +void e2d::Button::SetSelected(Node * selected) { - SET_BUTTON_NODE(_selected, selected); + SET_BUTTON_NODE(selected_, selected); } -void e2d::Button::setDisabled(Node * disabled) +void e2d::Button::SetDisabled(Node * disabled) { - SET_BUTTON_NODE(_disabled, disabled); + SET_BUTTON_NODE(disabled_, disabled); } -void e2d::Button::setEnabled(bool enabled) +void e2d::Button::SetEnabled(bool enabled) { - if (_enabled != enabled) + if (enabled_ != enabled) { - _enabled = enabled; - _updateVisible(); + enabled_ = enabled; + UpdateVisible(); } } -void e2d::Button::setClickFunc(const Function& func) +void e2d::Button::SetCallbackOnClick(const Function& func) { - _func = func; + callback_ = func; } -void e2d::Button::setAnchor(float anchorX, float anchorY) +void e2d::Button::SetAnchor(float anchor_x, float anchor_y) { - Node::setAnchor(anchorX, anchorY); - SAFE_SET(_normal, setAnchor, anchorX, anchorY); - SAFE_SET(_mouseover, setAnchor, anchorX, anchorY); - SAFE_SET(_selected, setAnchor, anchorX, anchorY); - SAFE_SET(_disabled, setAnchor, anchorX, anchorY); + Node::SetAnchor(anchor_x, anchor_y); + SAFE_SET(normal_, SetAnchor, anchor_x, anchor_y); + SAFE_SET(mouseover_, SetAnchor, anchor_x, anchor_y); + SAFE_SET(selected_, SetAnchor, anchor_x, anchor_y); + SAFE_SET(disabled_, SetAnchor, anchor_x, anchor_y); } -bool e2d::Button::dispatch(const MouseEvent & e, bool handled) +bool e2d::Button::Dispatch(const MouseEvent & e, bool handled) { - if (!handled && _enabled && _visible && _normal) + if (!handled && enabled_ && visible_ && normal_) { - bool contains = _normal->containsPoint(e.getPos()); - if (e.getType() == MouseEvent::Type::LeftUp && _isSelected && contains) + bool contains = normal_->ContainsPoint(e.GetPos()); + if (e.GetType() == MouseEvent::Type::LeftUp && is_selected_ && contains) { - _runCallback(); - _isSelected = false; - _setStatus(Status::Normal); + OnClick(); + is_selected_ = false; + SetStatus(Status::Normal); return true; } - else if (e.getType() == MouseEvent::Type::LeftDown) + else if (e.GetType() == MouseEvent::Type::LeftDown) { - _isSelected = contains; - _setStatus(contains ? Status::Selected : Status::Normal); + is_selected_ = contains; + SetStatus(contains ? Status::Selected : Status::Normal); if (contains) return true; } - else if (e.getType() == MouseEvent::Type::LeftUp) + else if (e.GetType() == MouseEvent::Type::LeftUp) { - _isSelected = false; + is_selected_ = false; } - else if (e.getType() == MouseEvent::Type::Move && _isSelected && contains) + else if (e.GetType() == MouseEvent::Type::Move && is_selected_ && contains) { - _setStatus(Status::Selected); + SetStatus(Status::Selected); return true; } else { - if (!e.isLButtonDown() && _isSelected) + if (!e.IsLButtonDown() && is_selected_) { - _isSelected = false; + is_selected_ = false; } - _setStatus(contains ? Status::Mouseover : Status::Normal); + SetStatus(contains ? Status::Mouseover : Status::Normal); if (contains) return true; } } - return Node::dispatch(e, handled); + return Node::Dispatch(e, handled); } -void e2d::Button::visit() +void e2d::Button::Visit() { - Node::visit(); + Node::Visit(); - if (_visible && - !_enabled && - _normal && - _normal->containsPoint(Input::getInstance()->getMousePos())) + if (visible_ && + !enabled_ && + normal_ && + normal_->ContainsPoint(Input::GetInstance()->GetMousePos())) { - Window::getInstance()->setCursor(Window::Cursor::No); + Window::GetInstance()->SetCursor(Window::Cursor::No); } - else if (_status == Status::Mouseover || _status == Status::Selected) + else if (status_ == Status::Mouseover || status_ == Status::Selected) { - Window::getInstance()->setCursor(Window::Cursor::Hand); + Window::GetInstance()->SetCursor(Window::Cursor::Hand); } } -void e2d::Button::_setStatus(Status status) +void e2d::Button::SetStatus(Status status) { - if (_status != status) + if (status_ != status) { - _status = status; - _updateVisible(); + status_ = status; + UpdateVisible(); } } -void e2d::Button::_updateVisible() +void e2d::Button::UpdateVisible() { - SAFE_SET(_normal, setVisible, false); - SAFE_SET(_mouseover, setVisible, false); - SAFE_SET(_selected, setVisible, false); - SAFE_SET(_disabled, setVisible, false); + SAFE_SET(normal_, SetVisible, false); + SAFE_SET(mouseover_, SetVisible, false); + SAFE_SET(selected_, SetVisible, false); + SAFE_SET(disabled_, SetVisible, false); - if (_enabled) + if (enabled_) { - if (_status == Status::Selected && _selected) + if (status_ == Status::Selected && selected_) { - _selected->setVisible(true); + selected_->SetVisible(true); } - else if (_status == Status::Mouseover && _mouseover) + else if (status_ == Status::Mouseover && mouseover_) { - _mouseover->setVisible(true); + mouseover_->SetVisible(true); } else { - if (_normal) _normal->setVisible(true); + if (normal_) normal_->SetVisible(true); } } else { - if (_disabled) + if (disabled_) { - _disabled->setVisible(true); + disabled_->SetVisible(true); } else { - if (_normal) _normal->setVisible(true); + if (normal_) normal_->SetVisible(true); } } } -void e2d::Button::_runCallback() +void e2d::Button::OnClick() { - if (_func) + if (callback_) { - _func(); + callback_(); } } diff --git a/core/Node/Canvas.cpp b/core/Node/Canvas.cpp index 3cb5a679..1b93a0e5 100644 --- a/core/Node/Canvas.cpp +++ b/core/Node/Canvas.cpp @@ -1,108 +1,108 @@ #include "..\e2dnode.h" e2d::Canvas::Canvas(float width, float height) - : _renderTarget(nullptr) - , _fillBrush(nullptr) - , _lineBrush(nullptr) - , _strokeStyle(nullptr) - , _strokeWidth(1.0f) - , _stroke(Stroke::Miter) + : render_target_(nullptr) + , fill_brush_(nullptr) + , line_brush_(nullptr) + , stroke_style_(nullptr) + , stroke_width_(1.0f) + , stroke_(Stroke::Miter) { - _renderTarget = Renderer::getInstance()->getRenderTarget(); - _renderTarget->AddRef(); + render_target_ = Renderer::GetInstance()->GetRenderTarget(); + render_target_->AddRef(); ThrowIfFailed( - _renderTarget->CreateSolidColorBrush( + render_target_->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::White), - &_fillBrush + &fill_brush_ ) ); ThrowIfFailed( - _renderTarget->CreateSolidColorBrush( + render_target_->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::White), - &_lineBrush + &line_brush_ ) ); - this->setClipEnabled(true); - this->setWidth(width); - this->setHeight(height); - this->setStrokeStyle(_stroke); + this->SetClipEnabled(true); + this->SetWidth(width); + this->SetHeight(height); + this->SetStrokeStyle(stroke_); } e2d::Canvas::~Canvas() { - SafeRelease(_lineBrush); - SafeRelease(_fillBrush); - SafeRelease(_renderTarget); + SafeRelease(line_brush_); + SafeRelease(fill_brush_); + SafeRelease(render_target_); } -void e2d::Canvas::setLineColor(const Color & color) +void e2d::Canvas::SetLineColor(const Color & color) { - _lineBrush->SetColor(D2D_COLOR_F(color)); + line_brush_->SetColor(D2D_COLOR_F(color)); } -void e2d::Canvas::setFillColor(const Color & color) +void e2d::Canvas::SetFillColor(const Color & color) { - _fillBrush->SetColor(D2D_COLOR_F(color)); + fill_brush_->SetColor(D2D_COLOR_F(color)); } -void e2d::Canvas::setStrokeWidth(float width) +void e2d::Canvas::SetStrokeWidth(float width) { - _strokeWidth = std::max(width, 0.f); + stroke_width_ = std::max(width, 0.f); } -void e2d::Canvas::setStrokeStyle(Stroke strokeStyle) +void e2d::Canvas::SetStrokeStyle(Stroke strokeStyle) { switch (strokeStyle) { case e2d::Stroke::Miter: - _strokeStyle = Renderer::getMiterStrokeStyle(); + stroke_style_ = Renderer::GetMiterStrokeStyle(); break; case e2d::Stroke::Bevel: - _strokeStyle = Renderer::getBevelStrokeStyle(); + stroke_style_ = Renderer::GetBevelStrokeStyle(); break; case e2d::Stroke::Round: - _strokeStyle = Renderer::getRoundStrokeStyle(); + stroke_style_ = Renderer::GetRoundStrokeStyle(); break; } } -e2d::Color e2d::Canvas::getLineColor() const +e2d::Color e2d::Canvas::GetLineColor() const { - return _lineBrush->GetColor(); + return line_brush_->GetColor(); } -e2d::Color e2d::Canvas::getFillColor() const +e2d::Color e2d::Canvas::GetFillColor() const { - return _fillBrush->GetColor(); + return fill_brush_->GetColor(); } -float e2d::Canvas::getStrokeWidth() const +float e2d::Canvas::GetStrokeWidth() const { - return _strokeWidth; + return stroke_width_; } -e2d::Stroke e2d::Canvas::getStrokeStyle() const +e2d::Stroke e2d::Canvas::GetStrokeStyle() const { - return _stroke; + return stroke_; } -void e2d::Canvas::drawLine(const Point & begin, const Point & end) +void e2d::Canvas::DrawLine(const Point & begin, const Point & end) { - _renderTarget->DrawLine( + render_target_->DrawLine( D2D1::Point2F(begin.x, begin.y), D2D1::Point2F(end.x, end.y), - _lineBrush, - _strokeWidth, - _strokeStyle + line_brush_, + stroke_width_, + stroke_style_ ); } -void e2d::Canvas::drawCircle(const Point & center, float radius) +void e2d::Canvas::DrawCircle(const Point & center, float radius) { - _renderTarget->DrawEllipse( + render_target_->DrawEllipse( D2D1::Ellipse( D2D1::Point2F( center.x, @@ -111,47 +111,47 @@ void e2d::Canvas::drawCircle(const Point & center, float radius) radius, radius ), - _lineBrush, - _strokeWidth, - _strokeStyle + line_brush_, + stroke_width_, + stroke_style_ ); } -void e2d::Canvas::drawEllipse(const Point & center, float radiusX, float radiusY) +void e2d::Canvas::DrawEllipse(const Point & center, float radius_x, float radius_y) { - _renderTarget->DrawEllipse( + render_target_->DrawEllipse( D2D1::Ellipse( D2D1::Point2F( center.x, center.y ), - radiusX, - radiusY + radius_x, + radius_y ), - _lineBrush, - _strokeWidth, - _strokeStyle + line_brush_, + stroke_width_, + stroke_style_ ); } -void e2d::Canvas::drawRect(const Rect & rect) +void e2d::Canvas::DrawRect(const Rect & rect) { - _renderTarget->DrawRectangle( + render_target_->DrawRectangle( D2D1::RectF( rect.origin.x, rect.origin.y, rect.origin.x + rect.size.width, rect.origin.y + rect.size.height ), - _lineBrush, - _strokeWidth, - _strokeStyle + line_brush_, + stroke_width_, + stroke_style_ ); } -void e2d::Canvas::drawRoundedRect(const Rect & rect, float radiusX, float radiusY) +void e2d::Canvas::DrawRoundedRect(const Rect & rect, float radius_x, float radius_y) { - _renderTarget->DrawRoundedRectangle( + render_target_->DrawRoundedRectangle( D2D1::RoundedRect( D2D1::RectF( rect.origin.x, @@ -159,18 +159,18 @@ void e2d::Canvas::drawRoundedRect(const Rect & rect, float radiusX, float radius rect.origin.x + rect.size.width, rect.origin.y + rect.size.height ), - radiusX, - radiusY + radius_x, + radius_y ), - _lineBrush, - _strokeWidth, - _strokeStyle + line_brush_, + stroke_width_, + stroke_style_ ); } -void e2d::Canvas::fillCircle(const Point & center, float radius) +void e2d::Canvas::FillCircle(const Point & center, float radius) { - _renderTarget->FillEllipse( + render_target_->FillEllipse( D2D1::Ellipse( D2D1::Point2F( center.x, @@ -179,41 +179,41 @@ void e2d::Canvas::fillCircle(const Point & center, float radius) radius, radius ), - _fillBrush + fill_brush_ ); } -void e2d::Canvas::fillEllipse(const Point & center, float radiusX, float radiusY) +void e2d::Canvas::FillEllipse(const Point & center, float radius_x, float radius_y) { - _renderTarget->FillEllipse( + render_target_->FillEllipse( D2D1::Ellipse( D2D1::Point2F( center.x, center.y ), - radiusX, - radiusY + radius_x, + radius_y ), - _fillBrush + fill_brush_ ); } -void e2d::Canvas::fillRect(const Rect & rect) +void e2d::Canvas::FillRect(const Rect & rect) { - _renderTarget->FillRectangle( + render_target_->FillRectangle( D2D1::RectF( rect.origin.x, rect.origin.y, rect.origin.x + rect.size.width, rect.origin.y + rect.size.height ), - _fillBrush + fill_brush_ ); } -void e2d::Canvas::fillRoundedRect(const Rect & rect, float radiusX, float radiusY) +void e2d::Canvas::FillRoundedRect(const Rect & rect, float radius_x, float radius_y) { - _renderTarget->FillRoundedRectangle( + render_target_->FillRoundedRectangle( D2D1::RoundedRect( D2D1::RectF( rect.origin.x, @@ -221,9 +221,9 @@ void e2d::Canvas::fillRoundedRect(const Rect & rect, float radiusX, float radius rect.origin.x + rect.size.width, rect.origin.y + rect.size.height ), - radiusX, - radiusY + radius_x, + radius_y ), - _fillBrush + fill_brush_ ); } diff --git a/core/Node/Menu.cpp b/core/Node/Menu.cpp index 68e3a17a..e36cb35c 100644 --- a/core/Node/Menu.cpp +++ b/core/Node/Menu.cpp @@ -1,76 +1,76 @@ #include "..\e2dnode.h" e2d::Menu::Menu() - : _enabled(true) + : enabled_(true) { } e2d::Menu::Menu(const std::vector& buttons) - : _enabled(true) + : enabled_(true) { for (const auto& button : buttons) { - this->addButton(button); + this->AddButton(button); } } -bool e2d::Menu::isEnable() const +bool e2d::Menu::IsEnable() const { - return _enabled; + return enabled_; } -size_t e2d::Menu::getButtonCount() const +size_t e2d::Menu::GetButtonCount() const { - return _buttons.size(); + return buttons_.size(); } -void e2d::Menu::setEnabled(bool enabled) +void e2d::Menu::SetEnabled(bool enabled) { - if (_enabled != enabled) + if (enabled_ != enabled) { - _enabled = enabled; + enabled_ = enabled; - for (const auto& button : _buttons) + for (const auto& button : buttons_) { - button->setEnabled(enabled); + button->SetEnabled(enabled); } } } -void e2d::Menu::addButton(Button * button) +void e2d::Menu::AddButton(Button * button) { if (button) { - this->addChild(button); - _buttons.push_back(button); - button->setEnabled(_enabled); + this->AddChild(button); + buttons_.push_back(button); + button->SetEnabled(enabled_); } } -bool e2d::Menu::removeButton(Button * button) +bool e2d::Menu::RemoveButton(Button * button) { - if (_buttons.empty()) + if (buttons_.empty()) { return false; } - this->removeChild(button); + this->RemoveChild(button); if (button) { - auto iter = std::find(_buttons.begin(), _buttons.end(), button); - if (iter != _buttons.end()) + auto iter = std::find(buttons_.begin(), buttons_.end(), button); + if (iter != buttons_.end()) { // 移除按钮前,将它启用 - button->setEnabled(true); - _buttons.erase(iter); + button->SetEnabled(true); + buttons_.erase(iter); return true; } } return false; } -const std::vector& e2d::Menu::getAllButtons() const +const std::vector& e2d::Menu::GetAllButtons() const { - return _buttons; + return buttons_; } diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index 1f20921b..e7cadf7e 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -3,135 +3,120 @@ #include "..\e2dmanager.h" #include "..\e2daction.h" -const e2d::Node::Property e2d::Node::Property::Origin = { 0 }; +const e2d::Node::Property e2d::Node::Property::Origin = { }; e2d::Node::Property e2d::Node::Property::operator+(Property const & prop) const { Property result; - 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.anchorX = this->anchorX + prop.anchorX; - result.anchorY = this->anchorY + prop.anchorY; - result.scaleX = this->scaleX + prop.scaleX; - result.scaleY = this->scaleY + prop.scaleY; + result.pos = this->pos + prop.pos; + result.size = this->size + prop.size; + result.anchor = this->anchor + prop.anchor; + result.scale = this->scale + prop.scale; + result.skew = this->skew + prop.skew; result.rotation = this->rotation + prop.rotation; - result.skewAngleX = this->skewAngleX + prop.skewAngleX; - result.skewAngleY = this->skewAngleY + prop.skewAngleY; return std::move(result); } e2d::Node::Property e2d::Node::Property::operator-(Property const & prop) const { Property result; - 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.anchorX = this->anchorX - prop.anchorX; - result.anchorY = this->anchorY - prop.anchorY; - result.scaleX = this->scaleX - prop.scaleX; - result.scaleY = this->scaleY - prop.scaleY; + result.pos = this->pos - prop.pos; + result.size = this->size - prop.size; + result.anchor = this->anchor - prop.anchor; + result.scale = this->scale - prop.scale; + result.skew = this->skew - prop.skew; result.rotation = this->rotation - prop.rotation; - result.skewAngleX = this->skewAngleX - prop.skewAngleX; - result.skewAngleY = this->skewAngleY - prop.skewAngleY; return std::move(result); } e2d::Node::Node() - : _order(0) - , _posX(0) - , _posY(0) - , _width(0) - , _height(0) - , _scaleX(1.0f) - , _scaleY(1.0f) - , _rotation(0) - , _skewAngleX(0) - , _skewAngleY(0) - , _displayOpacity(1.f) - , _realOpacity(1.f) - , _anchorX(0.f) - , _anchorY(0.f) - , _initialMatri(D2D1::Matrix3x2F::Identity()) - , _finalMatri(D2D1::Matrix3x2F::Identity()) - , _visible(true) - , _parent(nullptr) - , _parentScene(nullptr) - , _hashName(0) - , _clipEnabled(false) - , _needSort(false) - , _needTransform(false) - , _positionFixed(false) - , _collider(this) - , _border(nullptr) - , _borderColor(Color::Red, 0.6f) - , _extrapolate(Property::Origin) + : order_(0) + , pos_() + , size_() + , scale_(1.f, 1.f) + , rotation_(0) + , skew_(0, 0) + , display_opacity_(1.f) + , real_opacity_(1.f) + , anchor_() + , initial_matrix_(D2D1::Matrix3x2F::Identity()) + , final_matrix_(D2D1::Matrix3x2F::Identity()) + , visible_(true) + , parent_(nullptr) + , parent_scene_(nullptr) + , hash_name_(0) + , clip_enabled_(false) + , need_sort_(false) + , need_transform_(false) + , fixed_position_(false) + , collider_(this) + , border_(nullptr) + , border_color_(Color::Red, 0.6f) + , extrapolate_(Property::Origin) { } e2d::Node::~Node() { - SafeRelease(_border); + SafeRelease(border_); - ActionManager::getInstance()->clearAllBindedWith(this); - for (const auto& child : _children) + ActionManager::GetInstance()->ClearAllBindedWith(this); + for (const auto& child : children_) { - GC::getInstance()->safeRelease(child); + GC::GetInstance()->SafeRelease(child); } } -void e2d::Node::visit() +void e2d::Node::Visit() { - if (!_visible) + if (!visible_) return; - if (!Game::getInstance()->isPaused()) + if (!Game::GetInstance()->IsPaused()) { auto updatableNode = dynamic_cast(this); if (updatableNode) { - updatableNode->update(); + updatableNode->Update(); } } - _updateTransform(); - _extrapolate = this->getProperty(); + UpdateTransform(); + extrapolate_ = this->GetProperty(); - auto renderTarget = Renderer::getInstance()->getRenderTarget(); - if (_clipEnabled) + auto renderTarget = Renderer::GetInstance()->GetRenderTarget(); + if (clip_enabled_) { - renderTarget->SetTransform(_finalMatri); + renderTarget->SetTransform(final_matrix_); renderTarget->PushAxisAlignedClip( - D2D1::RectF(0, 0, _width, _height), + D2D1::RectF(0, 0, size_.width, size_.height), D2D1_ANTIALIAS_MODE_PER_PRIMITIVE ); } - if (_children.empty()) + if (children_.empty()) { auto drawableNode = dynamic_cast(this); if (drawableNode) { - renderTarget->SetTransform(_finalMatri); - drawableNode->draw(); + renderTarget->SetTransform(final_matrix_); + drawableNode->Draw(); } } else { // 子节点排序 - _sortChildren(); + SortChildren(); size_t i; - for (i = 0; i < _children.size(); ++i) + for (i = 0; i < children_.size(); ++i) { - auto child = _children[i]; + auto child = children_[i]; // 访问 Order 小于零的节点 - if (child->getOrder() < 0) + if (child->GetOrder() < 0) { - child->visit(); + child->Visit(); } else { @@ -142,526 +127,511 @@ void e2d::Node::visit() auto drawableNode = dynamic_cast(this); if (drawableNode) { - renderTarget->SetTransform(_finalMatri); - drawableNode->draw(); + renderTarget->SetTransform(final_matrix_); + drawableNode->Draw(); } // 访问剩余节点 - for (; i < _children.size(); ++i) - _children[i]->visit(); + for (; i < children_.size(); ++i) + children_[i]->Visit(); } - if (_clipEnabled) + if (clip_enabled_) { renderTarget->PopAxisAlignedClip(); } } -void e2d::Node::_drawBorder() +void e2d::Node::DrawBorder() { - if (_visible) + if (visible_) { - if (_border) + if (border_) { - auto renderer = Renderer::getInstance(); - auto brush = renderer->getSolidColorBrush(); - brush->SetColor(D2D1_COLOR_F(_borderColor)); - renderer->getRenderTarget()->DrawGeometry( - _border, + auto renderer = Renderer::GetInstance(); + auto brush = renderer->GetSolidBrush(); + brush->SetColor(D2D1_COLOR_F(border_color_)); + renderer->GetRenderTarget()->DrawGeometry( + border_, brush, 1.5f ); } - for (const auto& child : _children) + for (const auto& child : children_) { - child->_drawBorder(); + child->DrawBorder(); } } } -void e2d::Node::_drawCollider() +void e2d::Node::DrawCollider() { - if (_visible) + if (visible_) { - _collider.render(); + collider_.Draw(); - for (const auto& child : _children) + for (const auto& child : children_) { - child->_drawCollider(); + child->DrawCollider(); } } } -void e2d::Node::_updateTransform() +void e2d::Node::UpdateTransform() { - if (!_needTransform) + if (!need_transform_) return; - _needTransform = false; + need_transform_ = false; // 计算锚点坐标 - D2D1_POINT_2F anchor = { _width * _anchorX, _height * _anchorY }; + D2D1_POINT_2F anchor = { size_.width * anchor_.x, size_.height * anchor_.y }; // 变换 Initial 矩阵,子节点将根据这个矩阵进行变换 - _initialMatri = D2D1::Matrix3x2F::Scale( - _scaleX, - _scaleY, + initial_matrix_ = D2D1::Matrix3x2F::Scale( + scale_.x, + scale_.y, anchor ) * D2D1::Matrix3x2F::Skew( - _skewAngleX, - _skewAngleY, + skew_.x, + skew_.y, anchor ) * D2D1::Matrix3x2F::Rotation( - _rotation, + rotation_, anchor ) * D2D1::Matrix3x2F::Translation( - _posX, - _posY + pos_.x, + pos_.y ); // 根据自身锚点变换 Final 矩阵 - _finalMatri = _initialMatri * D2D1::Matrix3x2F::Translation(-anchor.x, -anchor.y); + final_matrix_ = initial_matrix_ * D2D1::Matrix3x2F::Translation(-anchor.x, -anchor.y); // 和父节点矩阵相乘 - if (!_positionFixed && _parent) + if (!fixed_position_ && parent_) { - _initialMatri = _initialMatri * _parent->_initialMatri; - _finalMatri = _finalMatri * _parent->_initialMatri; + initial_matrix_ = initial_matrix_ * parent_->initial_matrix_; + final_matrix_ = final_matrix_ * parent_->initial_matrix_; } // 重新构造轮廓 - SafeRelease(_border); + SafeRelease(border_); - ID2D1Factory * factory = Renderer::getFactory(); + ID2D1Factory * factory = Renderer::GetFactory(); ID2D1RectangleGeometry * rectangle = nullptr; ID2D1TransformedGeometry * transformed = nullptr; ThrowIfFailed( factory->CreateRectangleGeometry( - D2D1::RectF(0, 0, _width, _height), + D2D1::RectF(0, 0, size_.width, size_.height), &rectangle ) ); ThrowIfFailed( factory->CreateTransformedGeometry( rectangle, - _finalMatri, + final_matrix_, &transformed ) ); - _border = transformed; + border_ = transformed; SafeRelease(rectangle); // 通知子节点进行转换 - for (const auto& child : _children) + for (const auto& child : children_) { - child->_needTransform = true; + child->need_transform_ = true; } // 更新碰撞体 - _collider.recreate(); + collider_.Recreate(); - if (_collider.isEnabled() && - _collider.isCollisionNotify() && - _collider.getShape() != Collider::Shape::None) + if (collider_.IsEnabled() && + collider_.IsCollisionNotify() && + collider_.GetShape() != Collider::Shape::None) { - CollisionManager::getInstance()->__updateCollider(&_collider); + CollisionManager::GetInstance()->UpdateCollider(&collider_); } } -bool e2d::Node::dispatch(const MouseEvent & e, bool handled) +bool e2d::Node::Dispatch(const MouseEvent & e, bool handled) { - if (_visible) + if (visible_) { - for (auto riter = _children.crbegin(); riter != _children.crend(); ++riter) - handled = (*riter)->dispatch(e, handled); + for (auto riter = children_.crbegin(); riter != children_.crend(); ++riter) + handled = (*riter)->Dispatch(e, handled); auto handler = dynamic_cast(this); if (handler) - handler->handle(e); + handler->Handle(e); } return handled; } -bool e2d::Node::dispatch(const KeyEvent & e, bool handled) +bool e2d::Node::Dispatch(const KeyEvent & e, bool handled) { - if (_visible) + if (visible_) { - for (auto riter = _children.crbegin(); riter != _children.crend(); ++riter) - handled = (*riter)->dispatch(e, handled); + for (auto riter = children_.crbegin(); riter != children_.crend(); ++riter) + handled = (*riter)->Dispatch(e, handled); auto handler = dynamic_cast(this); if (handler) - handler->handle(e); + handler->Handle(e); } return handled; } -void e2d::Node::_sortChildren() +void e2d::Node::SortChildren() { - if (_needSort) + if (need_sort_) { std::sort( - std::begin(_children), - std::end(_children), - [](Node * n1, Node * n2) { return n1->getOrder() < n2->getOrder(); } + std::begin(children_), + std::end(children_), + [](Node * n1, Node * n2) { return n1->GetOrder() < n2->GetOrder(); } ); - _needSort = false; + need_sort_ = false; } } -void e2d::Node::_updateOpacity() +void e2d::Node::UpdateOpacity() { - if (_parent) + if (parent_) { - _displayOpacity = _realOpacity * _parent->_displayOpacity; + display_opacity_ = real_opacity_ * parent_->display_opacity_; } - for (const auto& child : _children) + for (const auto& child : children_) { - child->_updateOpacity(); + child->UpdateOpacity(); } } -bool e2d::Node::isVisible() const +bool e2d::Node::IsVisible() const { - return _visible; + return visible_; } -const e2d::String& e2d::Node::getName() const +const e2d::String& e2d::Node::GetName() const { - return _name; + return name_; } -size_t e2d::Node::getHashName() const +size_t e2d::Node::GetHashName() const { - return _hashName; + return hash_name_; } -float e2d::Node::getPosX() const +float e2d::Node::GetPosX() const { - return _posX; + return pos_.x; } -float e2d::Node::getPosY() const +float e2d::Node::GetPosY() const { - return _posY; + return pos_.y; } -e2d::Point e2d::Node::getPos() const +e2d::Point e2d::Node::GetPos() const { - return Point(_posX, _posY); + return Point(pos_.x, pos_.y); } -float e2d::Node::getWidth() const +float e2d::Node::GetWidth() const { - return _width * _scaleX; + return size_.width * scale_.x; } -float e2d::Node::getHeight() const +float e2d::Node::GetHeight() const { - return _height * _scaleY; + return size_.height * scale_.y; } -float e2d::Node::getRealWidth() const +float e2d::Node::GetRealWidth() const { - return _width; + return size_.width; } -float e2d::Node::getRealHeight() const +float e2d::Node::GetRealHeight() const { - return _height; + return size_.height; } -e2d::Size e2d::Node::getRealSize() const +e2d::Size e2d::Node::GetRealSize() const { - return Size(_width, _height); + return Size(size_.width, size_.height); } -float e2d::Node::getAnchorX() const +float e2d::Node::GetAnchorX() const { - return _anchorX; + return anchor_.x; } -float e2d::Node::getAnchorY() const +float e2d::Node::GetAnchorY() const { - return _anchorY; + return anchor_.y; } -e2d::Size e2d::Node::getSize() const +e2d::Size e2d::Node::GetSize() const { - return Size(getWidth(), getHeight()); + return Size(GetWidth(), GetHeight()); } -float e2d::Node::getScaleX() const +float e2d::Node::GetScaleX() const { - return _scaleX; + return scale_.x; } -float e2d::Node::getScaleY() const +float e2d::Node::GetScaleY() const { - return _scaleY; + return scale_.y; } -float e2d::Node::getSkewX() const +float e2d::Node::GetSkewX() const { - return _skewAngleX; + return skew_.x; } -float e2d::Node::getSkewY() const +float e2d::Node::GetSkewY() const { - return _skewAngleY; + return skew_.y; } -float e2d::Node::getRotation() const +float e2d::Node::GetRotation() const { - return _rotation; + return rotation_; } -float e2d::Node::getOpacity() const +float e2d::Node::GetOpacity() const { - return _realOpacity; + return real_opacity_; } -e2d::Node::Property e2d::Node::getProperty() const +e2d::Node::Property e2d::Node::GetProperty() const { Property prop; - prop.posX = _posX; - prop.posY = _posY; - prop.width = _width; - prop.height = _height; - prop.anchorX = _anchorX; - prop.anchorY = _anchorY; - prop.scaleX = _scaleX; - prop.scaleY = _scaleY; - prop.rotation = _rotation; - prop.skewAngleX = _skewAngleX; - prop.skewAngleY = _skewAngleY; + prop.pos = pos_; + prop.size = size_; + prop.anchor = anchor_; + prop.scale = scale_; + prop.rotation = rotation_; + prop.skew = skew_; return std::move(prop); } -e2d::Node::Property e2d::Node::getExtrapolate() const +e2d::Node::Property e2d::Node::GetExtrapolate() const { - return this->getProperty() - _extrapolate; + return this->GetProperty() - extrapolate_; } -e2d::Collider* e2d::Node::getCollider() +e2d::Collider* e2d::Node::GetCollider() { - return &_collider; + return &collider_; } -int e2d::Node::getOrder() const +int e2d::Node::GetOrder() const { - return _order; + return order_; } -void e2d::Node::setOrder(int order) +void e2d::Node::SetOrder(int order) { - if (_order == order) + if (order_ == order) return; - _order = order; - if (_parent) + order_ = order; + if (parent_) { - _parent->_needSort = true; + parent_->need_sort_ = true; } } -void e2d::Node::setPosX(float x) +void e2d::Node::SetPosX(float x) { - this->setPos(x, _posY); + this->SetPos(x, pos_.y); } -void e2d::Node::setPosY(float y) +void e2d::Node::SetPosY(float y) { - this->setPos(_posX, y); + this->SetPos(pos_.x, y); } -void e2d::Node::setPos(const Point & p) +void e2d::Node::SetPos(const Point & p) { - this->setPos(p.x, p.y); + this->SetPos(p.x, p.y); } -void e2d::Node::setPos(float x, float y) +void e2d::Node::SetPos(float x, float y) { - if (_posX == x && _posY == y) + if (pos_.x == x && pos_.y == y) return; - _posX = x; - _posY = y; - _needTransform = true; + pos_.x = x; + pos_.y = y; + need_transform_ = true; } -void e2d::Node::setPosFixed(bool fixed) +void e2d::Node::SetPosFixed(bool fixed) { - if (_positionFixed == fixed) + if (fixed_position_ == fixed) return; - _positionFixed = fixed; - _needTransform = true; + fixed_position_ = fixed; + need_transform_ = true; } -void e2d::Node::movePosX(float x) +void e2d::Node::Move(float x, float y) { - this->movePos(x, 0); + this->SetPos(pos_.x + x, pos_.y + y); } -void e2d::Node::movePosY(float y) +void e2d::Node::Move(const Point & v) { - this->movePos(0, y); + this->Move(v.x, v.y); } -void e2d::Node::movePos(float x, float y) +void e2d::Node::SetScaleX(float scale_x) { - this->setPos(_posX + x, _posY + y); + this->SetScale(scale_x, scale_.y); } -void e2d::Node::movePos(const Vector2 & v) +void e2d::Node::SetScaleY(float scale_y) { - this->movePos(v.x, v.y); + this->SetScale(scale_.x, scale_y); } -void e2d::Node::setScaleX(float scaleX) +void e2d::Node::SetScale(float scale) { - this->setScale(scaleX, _scaleY); + this->SetScale(scale, scale); } -void e2d::Node::setScaleY(float scaleY) +void e2d::Node::SetScale(float scale_x, float scale_y) { - this->setScale(_scaleX, scaleY); -} - -void e2d::Node::setScale(float scale) -{ - this->setScale(scale, scale); -} - -void e2d::Node::setScale(float scaleX, float scaleY) -{ - if (_scaleX == scaleX && _scaleY == scaleY) + if (scale_.x == scale_x && scale_.y == scale_y) return; - _scaleX = scaleX; - _scaleY = scaleY; - _needTransform = true; + scale_.x = scale_x; + scale_.y = scale_y; + need_transform_ = true; } -void e2d::Node::setSkewX(float angleX) +void e2d::Node::SetSkewX(float skew_x) { - this->setSkew(angleX, _skewAngleY); + this->SetSkew(skew_x, skew_.y); } -void e2d::Node::setSkewY(float angleY) +void e2d::Node::SetSkewY(float skew_y) { - this->setSkew(_skewAngleX, angleY); + this->SetSkew(skew_.x, skew_y); } -void e2d::Node::setSkew(float angleX, float angleY) +void e2d::Node::SetSkew(float skew_x, float skew_y) { - if (_skewAngleX == angleX && _skewAngleY == angleY) + if (skew_.x == skew_x && skew_.y == skew_y) return; - _skewAngleX = angleX; - _skewAngleY = angleY; - _needTransform = true; + skew_.x = skew_x; + skew_.y = skew_y; + need_transform_ = true; } -void e2d::Node::setRotation(float angle) +void e2d::Node::SetRotation(float angle) { - if (_rotation == angle) + if (rotation_ == angle) return; - _rotation = angle; - _needTransform = true; + rotation_ = angle; + need_transform_ = true; } -void e2d::Node::setOpacity(float opacity) +void e2d::Node::SetOpacity(float opacity) { - if (_realOpacity == opacity) + if (real_opacity_ == opacity) return; - _displayOpacity = _realOpacity = std::min(std::max(opacity, 0.f), 1.f); + display_opacity_ = real_opacity_ = std::min(std::max(opacity, 0.f), 1.f); // 更新节点透明度 - _updateOpacity(); + UpdateOpacity(); } -void e2d::Node::setAnchorX(float anchorX) +void e2d::Node::SetAnchorX(float anchor_x) { - this->setAnchor(anchorX, _anchorY); + this->SetAnchor(anchor_x, anchor_.y); } -void e2d::Node::setAnchorY(float anchorY) +void e2d::Node::SetAnchorY(float anchor_y) { - this->setAnchor(_anchorX, anchorY); + this->SetAnchor(anchor_.x, anchor_y); } -void e2d::Node::setAnchor(float anchorX, float anchorY) +void e2d::Node::SetAnchor(float anchor_x, float anchor_y) { - if (_anchorX == anchorX && _anchorY == anchorY) + if (anchor_.x == anchor_x && anchor_.y == anchor_y) return; - _anchorX = std::min(std::max(anchorX, 0.f), 1.f); - _anchorY = std::min(std::max(anchorY, 0.f), 1.f); - _needTransform = true; + anchor_.x = std::min(std::max(anchor_x, 0.f), 1.f); + anchor_.y = std::min(std::max(anchor_y, 0.f), 1.f); + need_transform_ = true; } -void e2d::Node::setWidth(float width) +void e2d::Node::SetWidth(float width) { - this->setSize(width, _height); + this->SetSize(width, size_.height); } -void e2d::Node::setHeight(float height) +void e2d::Node::SetHeight(float height) { - this->setSize(_width, height); + this->SetSize(size_.width, height); } -void e2d::Node::setSize(float width, float height) +void e2d::Node::SetSize(float width, float height) { - if (_width == width && _height == height) + if (size_.width == width && size_.height == height) return; - _width = width; - _height = height; - _needTransform = true; + size_.width = width; + size_.height = height; + need_transform_ = true; } -void e2d::Node::setSize(Size size) +void e2d::Node::SetSize(Size size) { - this->setSize(size.width, size.height); + this->SetSize(size.width, size.height); } -void e2d::Node::setProperty(Property prop) +void e2d::Node::SetProperty(Property prop) { - this->setPos(prop.posX, prop.posY); - this->setSize(prop.width, prop.height); - this->setAnchor(prop.anchorX, prop.anchorY); - this->setScale(prop.scaleX, prop.scaleY); - this->setRotation(prop.rotation); - this->setSkew(prop.skewAngleX, prop.skewAngleY); + this->SetPos(prop.pos.x, prop.pos.y); + this->SetSize(prop.size.width, prop.size.height); + this->SetAnchor(prop.anchor.x, prop.anchor.y); + this->SetScale(prop.scale.x, prop.scale.y); + this->SetRotation(prop.rotation); + this->SetSkew(prop.skew.x, prop.skew.y); } -void e2d::Node::setClipEnabled(bool enabled) +void e2d::Node::SetClipEnabled(bool enabled) { - _clipEnabled = enabled; + clip_enabled_ = enabled; } -void e2d::Node::setBorderColor(const Color & color) +void e2d::Node::SetBorderColor(const Color & color) { - _borderColor = color; + border_color_ = color; } -void 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."); + WARN_IF(child == nullptr, "Node::AddChild NULL pointer exception."); if (child) { - if (child->_parent != nullptr) + if (child->parent_ != nullptr) { throw Exception("节点已有父节点, 不能再添加到其他节点"); } - for (Node * parent = this; parent != nullptr; parent = parent->getParent()) + for (Node * parent = this; parent != nullptr; parent = parent->GetParent()) { if (child == parent) { @@ -669,66 +639,66 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */) } } - child->retain(); - _children.push_back(child); - child->setOrder(order); - child->_parent = this; - if (this->_parentScene) + child->Retain(); + children_.push_back(child); + child->SetOrder(order); + child->parent_ = this; + if (this->parent_scene_) { - child->_setParentScene(this->_parentScene); + child->SetParentScene(this->parent_scene_); } // 更新子节点透明度 - child->_updateOpacity(); + child->UpdateOpacity(); // 更新节点转换 - child->_needTransform = true; + child->need_transform_ = true; // 更新子节点排序 - _needSort = true; + need_sort_ = true; } } -void e2d::Node::addChild(const std::vector& nodes, int order) +void e2d::Node::AddChild(const Nodes& nodes, int order) { for (const auto& node : nodes) { - this->addChild(node, order); + this->AddChild(node, order); } } -e2d::Node * e2d::Node::getParent() const +e2d::Node * e2d::Node::GetParent() const { - return _parent; + return parent_; } -e2d::Scene * e2d::Node::getParentScene() const +e2d::Scene * e2d::Node::GetParentScene() const { - return _parentScene; + return parent_scene_; } -std::vector e2d::Node::getChildren(const String& name) const +e2d::Node::Nodes e2d::Node::GetChildren(const String& name) const { - std::vector vChildren; - size_t hash = name.hash(); + Nodes children; + size_t hash = name.GetHash(); - for (const auto& child : _children) + for (const auto& child : children_) { // 不同的名称可能会有相同的 Hash 值,但是先比较 Hash 可以提升搜索速度 - if (child->_hashName == hash && child->_name == name) + if (child->hash_name_ == hash && child->name_ == name) { - vChildren.push_back(child); + children.push_back(child); } } - return std::move(vChildren); + return std::move(children); } -e2d::Node * e2d::Node::getChild(const String& name) const +e2d::Node * e2d::Node::GetChild(const String& name) const { - size_t hash = name.hash(); + size_t hash = name.GetHash(); - for (const auto& child : _children) + for (const auto& child : children_) { // 不同的名称可能会有相同的 Hash 值,但是先比较 Hash 可以提升搜索速度 - if (child->_hashName == hash && child->_name == name) + if (child->hash_name_ == hash && child->name_ == name) { return child; } @@ -736,145 +706,145 @@ e2d::Node * e2d::Node::getChild(const String& name) const return nullptr; } -const std::vector& e2d::Node::getAllChildren() const +const std::vector& e2d::Node::GetAllChildren() const { - return _children; + return children_; } -int e2d::Node::getChildrenCount() const +int e2d::Node::GetChildrenCount() const { - return static_cast(_children.size()); + return static_cast(children_.size()); } -void e2d::Node::removeFromParent() +void e2d::Node::RemoveFromParent() { - if (_parent) + if (parent_) { - _parent->removeChild(this); + parent_->RemoveChild(this); } } -bool e2d::Node::removeChild(Node * child) +bool e2d::Node::RemoveChild(Node * child) { - WARN_IF(child == nullptr, "Node::removeChildren NULL pointer exception."); + WARN_IF(child == nullptr, "Node::RemoveChildren NULL pointer exception."); - if (_children.empty()) + if (children_.empty()) { return false; } if (child) { - auto iter = std::find(_children.begin(), _children.end(), child); - if (iter != _children.end()) + auto iter = std::find(children_.begin(), children_.end(), child); + if (iter != children_.end()) { - _children.erase(iter); - child->_parent = nullptr; + children_.erase(iter); + child->parent_ = nullptr; - if (child->_parentScene) + if (child->parent_scene_) { - child->_setParentScene(nullptr); + child->SetParentScene(nullptr); } - child->release(); + child->Release(); return true; } } return false; } -void e2d::Node::removeChildren(const String& childName) +void e2d::Node::RemoveChildren(const String& child_name) { - WARN_IF(childName.isEmpty(), "Invalid Node name."); + WARN_IF(child_name.IsEmpty(), "Invalid Node name."); - if (_children.empty()) + if (children_.empty()) { return; } // 计算名称 Hash 值 - size_t hash = childName.hash(); + size_t hash = child_name.GetHash(); auto iter = std::find_if( - _children.begin(), - _children.end(), - [childName, hash](Node* child) ->bool { return child->_hashName == hash && child->_name == childName; } + children_.begin(), + children_.end(), + [child_name, hash](Node* child) ->bool { return child->hash_name_ == hash && child->name_ == child_name; } ); - if (iter != _children.end()) + if (iter != children_.end()) { - (*iter)->_parent = nullptr; - if ((*iter)->_parentScene) + (*iter)->parent_ = nullptr; + if ((*iter)->parent_scene_) { - (*iter)->_setParentScene(nullptr); + (*iter)->SetParentScene(nullptr); } - (*iter)->release(); - _children.erase(iter); + (*iter)->Release(); + children_.erase(iter); } } -void e2d::Node::removeAllChildren() +void e2d::Node::RemoveAllChildren() { // 所有节点的引用计数减一 - for (const auto& child : _children) + for (const auto& child : children_) { - child->release(); + child->Release(); } // 清空储存节点的容器 - _children.clear(); + children_.clear(); } -void e2d::Node::runAction(Action * action) +void e2d::Node::RunAction(Action * action) { - ActionManager::getInstance()->start(action, this, false); + ActionManager::GetInstance()->Start(action, this, false); } -void e2d::Node::resumeAction(const String& name) +void e2d::Node::ResumeAction(const String& name) { - auto& actions = ActionManager::getInstance()->get(name); + auto& actions = ActionManager::GetInstance()->Get(name); for (const auto& action : actions) { - if (action->getTarget() == this) + if (action->GetTarget() == this) { - action->resume(); + action->Resume(); } } } -void e2d::Node::pauseAction(const String& name) +void e2d::Node::PauseAction(const String& name) { - auto& actions = ActionManager::getInstance()->get(name); + auto& actions = ActionManager::GetInstance()->Get(name); for (const auto& action : actions) { - if (action->getTarget() == this) + if (action->GetTarget() == this) { - action->pause(); + action->Pause(); } } } -void e2d::Node::stopAction(const String& name) +void e2d::Node::StopAction(const String& name) { - auto& actions = ActionManager::getInstance()->get(name); + auto& actions = ActionManager::GetInstance()->Get(name); for (const auto& action : actions) { - if (action->getTarget() == this) + if (action->GetTarget() == this) { - action->stop(); + action->Stop(); } } } -bool e2d::Node::containsPoint(const Point& point) +bool e2d::Node::ContainsPoint(const Point& point) { - if (_width == 0.f || _height == 0.f) + if (size_.width == 0.f || size_.height == 0.f) return false; - _updateTransform(); + UpdateTransform(); BOOL ret = 0; ThrowIfFailed( - _border->FillContainsPoint( + border_->FillContainsPoint( D2D1::Point2F(point.x, point.y), D2D1::Matrix3x2F::Identity(), &ret @@ -883,20 +853,20 @@ bool e2d::Node::containsPoint(const Point& point) return ret != 0; } -bool e2d::Node::intersects(Node * node) +bool e2d::Node::Intersects(Node * node) { - if (_width == 0.f || _height == 0.f || node->_width == 0.f || node->_height == 0.f) + if (size_.width == 0.f || size_.height == 0.f || node->size_.width == 0.f || node->size_.height == 0.f) return false; // 更新转换矩阵 - _updateTransform(); - node->_updateTransform(); + UpdateTransform(); + node->UpdateTransform(); // 获取相交状态 D2D1_GEOMETRY_RELATION relation = D2D1_GEOMETRY_RELATION_UNKNOWN; ThrowIfFailed( - _border->CompareWithGeometry( - node->_border, + border_->CompareWithGeometry( + node->border_, D2D1::Matrix3x2F::Identity(), &relation ) @@ -905,44 +875,44 @@ bool e2d::Node::intersects(Node * node) relation != D2D1_GEOMETRY_RELATION_DISJOINT; } -void e2d::Node::resumeAllActions() +void e2d::Node::ResumeAllActions() { - ActionManager::getInstance()->resumeAllBindedWith(this); + ActionManager::GetInstance()->ResumeAllBindedWith(this); } -void e2d::Node::pauseAllActions() +void e2d::Node::PauseAllActions() { - ActionManager::getInstance()->pauseAllBindedWith(this); + ActionManager::GetInstance()->PauseAllBindedWith(this); } -void e2d::Node::stopAllActions() +void e2d::Node::StopAllActions() { - ActionManager::getInstance()->stopAllBindedWith(this); + ActionManager::GetInstance()->StopAllBindedWith(this); } -void e2d::Node::setVisible(bool value) +void e2d::Node::SetVisible(bool value) { - _visible = value; + visible_ = value; } -void e2d::Node::setName(const String& name) +void e2d::Node::SetName(const String& name) { - WARN_IF(name.isEmpty(), "Invalid Node name."); + WARN_IF(name.IsEmpty(), "Invalid Node name."); - if (!name.isEmpty() && _name != name) + if (!name.IsEmpty() && name_ != name) { // 保存节点名 - _name = name; + name_ = name; // 保存节点 Hash 名 - _hashName = name.hash(); + hash_name_ = name.GetHash(); } } -void e2d::Node::_setParentScene(Scene * scene) +void e2d::Node::SetParentScene(Scene * scene) { - _parentScene = scene; - for (const auto& child : _children) + parent_scene_ = scene; + for (const auto& child : children_) { - child->_setParentScene(scene); + child->SetParentScene(scene); } } \ No newline at end of file diff --git a/core/Node/Scene.cpp b/core/Node/Scene.cpp index cedc2d63..724bea71 100644 --- a/core/Node/Scene.cpp +++ b/core/Node/Scene.cpp @@ -3,40 +3,40 @@ #include "..\e2dmanager.h" e2d::Scene::Scene() - : _borderVisible(false) - , _colliderVisible(false) + : border_visible_(false) + , collider_visible_(false) { - _parentScene = this; + parent_scene_ = this; } e2d::Scene::~Scene() { } -void e2d::Scene::showBorder(bool visible) +void e2d::Scene::ShowBorder(bool visible) { - _borderVisible = visible; + border_visible_ = visible; } -void e2d::Scene::showCollider(bool visible) +void e2d::Scene::ShowCollider(bool visible) { - _colliderVisible = visible; + collider_visible_ = visible; } -void e2d::Scene::visit() +void e2d::Scene::Visit() { - Node::visit(); + Node::Visit(); - if (_borderVisible) + if (border_visible_) { - Renderer::getInstance()->getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); - Renderer::getInstance()->getSolidColorBrush()->SetOpacity(1.f); - this->_drawBorder(); + Renderer::GetInstance()->GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); + Renderer::GetInstance()->GetSolidBrush()->SetOpacity(1.f); + this->DrawBorder(); } - if (_colliderVisible) + if (collider_visible_) { - Renderer::getInstance()->getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); - this->_drawCollider(); + Renderer::GetInstance()->GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); + this->DrawCollider(); } } diff --git a/core/Node/Sprite.cpp b/core/Node/Sprite.cpp index dfd7dca8..cb874b67 100644 --- a/core/Node/Sprite.cpp +++ b/core/Node/Sprite.cpp @@ -2,125 +2,125 @@ e2d::Sprite::Sprite() - : _image(nullptr) + : image_(nullptr) { } e2d::Sprite::Sprite(Image * image) - : _image(nullptr) + : image_(nullptr) { - open(image); + Open(image); } e2d::Sprite::Sprite(const Resource& res) - : _image(nullptr) + : image_(nullptr) { - open(res); + Open(res); } -e2d::Sprite::Sprite(const Resource& res, const Rect& cropRect) - : _image(nullptr) +e2d::Sprite::Sprite(const Resource& res, const Rect& crop_rect) + : image_(nullptr) { - open(res); - crop(cropRect); + Open(res); + Crop(crop_rect); } -e2d::Sprite::Sprite(const String & fileName) - : _image(nullptr) +e2d::Sprite::Sprite(const String & file_name) + : image_(nullptr) { - open(fileName); + Open(file_name); } -e2d::Sprite::Sprite(const String & fileName, const Rect & cropRect) - : _image(nullptr) +e2d::Sprite::Sprite(const String & file_name, const Rect & crop_rect) + : image_(nullptr) { - open(fileName); - crop(cropRect); + Open(file_name); + Crop(crop_rect); } e2d::Sprite::~Sprite() { - GC::getInstance()->safeRelease(_image); + GC::GetInstance()->SafeRelease(image_); } -bool e2d::Sprite::open(Image * image) +bool e2d::Sprite::Open(Image * image) { if (image) { - if (_image) _image->release(); - _image = image; - _image->retain(); + if (image_) image_->Release(); + image_ = image; + image_->Retain(); - Node::setSize(_image->getWidth(), _image->getHeight()); + Node::SetSize(image_->GetWidth(), image_->GetHeight()); return true; } return false; } -bool e2d::Sprite::open(const Resource& res) +bool e2d::Sprite::Open(const Resource& res) { - if (!_image) + if (!image_) { - _image = new (e2d::autorelease) Image(); - _image->retain(); + image_ = new (e2d::autorelease) Image(); + image_->Retain(); } - if (_image->open(res)) + if (image_->Open(res)) { - Node::setSize(_image->getWidth(), _image->getHeight()); + Node::SetSize(image_->GetWidth(), image_->GetHeight()); return true; } return false; } -bool e2d::Sprite::open(const String & fileName) +bool e2d::Sprite::Open(const String & file_name) { - if (!_image) + if (!image_) { - _image = new (e2d::autorelease) Image(); - _image->retain(); + image_ = new (e2d::autorelease) Image(); + image_->Retain(); } - if (_image->open(fileName)) + if (image_->Open(file_name)) { - Node::setSize(_image->getWidth(), _image->getHeight()); + Node::SetSize(image_->GetWidth(), image_->GetHeight()); return true; } return false; } -void e2d::Sprite::crop(const Rect& cropRect) +void e2d::Sprite::Crop(const Rect& crop_rect) { - _image->crop(cropRect); - 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()) + image_->Crop(crop_rect); + Node::SetSize( + std::min(std::max(crop_rect.size.width, 0.f), image_->GetSourceWidth() - image_->GetCropX()), + std::min(std::max(crop_rect.size.height, 0.f), image_->GetSourceHeight() - image_->GetCropY()) ); } -e2d::Image * e2d::Sprite::getImage() const +e2d::Image * e2d::Sprite::GetImage() const { - return _image; + return image_; } -void e2d::Sprite::draw() const +void e2d::Sprite::Draw() const { - if (_image && _image->getBitmap()) + if (image_ && image_->GetBitmap()) { // 获取图片裁剪位置 - float fCropX = _image->getCropX(); - float fCropY = _image->getCropY(); + float fCropX = image_->GetCropX(); + float fCropY = image_->GetCropY(); // 渲染图片 - Renderer::getInstance()->getRenderTarget()->DrawBitmap( - _image->getBitmap(), - D2D1::RectF(0, 0, _width, _height), - _displayOpacity, + Renderer::GetInstance()->GetRenderTarget()->DrawBitmap( + image_->GetBitmap(), + D2D1::RectF(0, 0, size_.width, size_.height), + display_opacity_, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1::RectF( fCropX, fCropY, - fCropX + _width, - fCropY + _height + fCropX + size_.width, + fCropY + size_.height ) ); } diff --git a/core/Node/Text.cpp b/core/Node/Text.cpp index 98f6fae0..341fdcb1 100644 --- a/core/Node/Text.cpp +++ b/core/Node/Text.cpp @@ -7,41 +7,41 @@ e2d::Text::Style::Style() : color(Color::White) , alignment(Align::Left) - , wrapping(false) - , wrappingWidth(0.f) - , lineSpacing(0.f) - , hasUnderline(false) - , hasStrikethrough(false) - , hasOutline(true) - , outlineColor(Color(Color::Black, 0.5)) - , outlineWidth(1.f) - , outlineStroke(Stroke::Round) + , wrap(false) + , wrap_width(0.f) + , line_spacing(0.f) + , underline(false) + , strikethrough(false) + , outline(true) + , outline_color(Color(Color::Black, 0.5)) + , outline_width(1.f) + , outline_stroke(Stroke::Round) {} e2d::Text::Style::Style( Color color, Align alignment, - bool wrapping, - float wrappingWidth, - float lineSpacing, - bool hasUnderline, - bool hasStrikethrough, - bool hasOutline, - Color outlineColor, - float outlineWidth, - Stroke outlineStroke + bool wrap, + float wrap_width, + float line_spacing, + bool underline, + bool strikethrough, + bool outline, + Color outline_color, + float outline_width, + Stroke outline_stroke ) : color(color) , alignment(alignment) - , wrapping(wrapping) - , wrappingWidth(wrappingWidth) - , lineSpacing(lineSpacing) - , hasUnderline(hasUnderline) - , hasStrikethrough(hasStrikethrough) - , hasOutline(hasOutline) - , outlineColor(outlineColor) - , outlineWidth(outlineWidth) - , outlineStroke(outlineStroke) + , wrap(wrap) + , wrap_width(wrap_width) + , line_spacing(line_spacing) + , underline(underline) + , strikethrough(strikethrough) + , outline(outline) + , outline_color(outline_color) + , outline_width(outline_width) + , outline_stroke(outline_stroke) {} @@ -51,85 +51,85 @@ e2d::Text::Style::Style( //------------------------------------------------------- e2d::Text::Text() - : _font() - , _style() - , _textLayout(nullptr) - , _textFormat(nullptr) + : font_() + , style_() + , text_layout_(nullptr) + , text_format_(nullptr) { } e2d::Text::Text(const String & text, const Font & font, const Style & style) - : _font(font) - , _style(style) - , _textLayout(nullptr) - , _textFormat(nullptr) - , _text(text) + : font_(font) + , style_(style) + , text_layout_(nullptr) + , text_format_(nullptr) + , text_(text) { - _reset(); + Reset(); } e2d::Text::~Text() { - SafeRelease(_textFormat); - SafeRelease(_textLayout); + SafeRelease(text_format_); + SafeRelease(text_layout_); } -const e2d::String& e2d::Text::getText() const +const e2d::String& e2d::Text::GetText() const { - return _text; + return text_; } -const e2d::Font& e2d::Text::getFont() const +const e2d::Font& e2d::Text::GetFont() const { - return _font; + return font_; } -const e2d::Text::Style& e2d::Text::getStyle() const +const e2d::Text::Style& e2d::Text::GetStyle() const { - return _style; + return style_; } -const e2d::String& e2d::Text::getFontFamily() const +const e2d::String& e2d::Text::GetFontFamily() const { - return _font.family; + return font_.family; } -float e2d::Text::getFontSize() const +float e2d::Text::GetFontSize() const { - return _font.size; + return font_.size; } -UINT e2d::Text::getFontWeight() const +UINT e2d::Text::GetFontWeight() const { - return _font.weight; + return font_.weight; } -const e2d::Color& e2d::Text::getColor() const +const e2d::Color& e2d::Text::GetColor() const { - return _style.color; + return style_.color; } -const e2d::Color& e2d::Text::getOutlineColor() const +const e2d::Color& e2d::Text::GetOutlineColor() const { - return _style.outlineColor; + return style_.outline_color; } -float e2d::Text::getOutlineWidth() const +float e2d::Text::GetOutlineWidth() const { - return _style.outlineWidth; + return style_.outline_width; } -e2d::Stroke e2d::Text::getOutlineStroke() const +e2d::Stroke e2d::Text::GetOutlineStroke() const { - return _style.outlineStroke; + return style_.outline_stroke; } -int e2d::Text::getLineCount() const +int e2d::Text::GetLineCount() const { - if (_textLayout) + if (text_layout_) { DWRITE_TEXT_METRICS metrics; - _textLayout->GetMetrics(&metrics); + text_layout_->GetMetrics(&metrics); return static_cast(metrics.lineCount); } else @@ -138,311 +138,311 @@ int e2d::Text::getLineCount() const } } -bool e2d::Text::isItalic() const +bool e2d::Text::IsItalic() const { - return _font.italic; + return font_.italic; } -bool e2d::Text::hasStrikethrough() const +bool e2d::Text::strikethrough() const { - return _style.hasStrikethrough; + return style_.strikethrough; } -bool e2d::Text::hasUnderline() const +bool e2d::Text::underline() const { - return _style.hasUnderline; + return style_.underline; } -bool e2d::Text::hasOutline() const +bool e2d::Text::outline() const { - return _style.hasOutline; + return style_.outline; } -void e2d::Text::setText(const String& text) +void e2d::Text::SetText(const String& text) { - _text = text; - _reset(); + text_ = text; + Reset(); } -void e2d::Text::setStyle(const Style& style) +void e2d::Text::SetStyle(const Style& style) { - _style = style; - _reset(); + style_ = style; + Reset(); } -void e2d::Text::setFont(const Font & font) +void e2d::Text::SetFont(const Font & font) { - _font = font; - _reset(); + font_ = font; + Reset(); } -void e2d::Text::setFontFamily(const String& family) +void e2d::Text::SetFontFamily(const String& family) { - _font.family = family; - _reset(); + font_.family = family; + Reset(); } -void e2d::Text::setFontSize(float size) +void e2d::Text::SetFontSize(float size) { - _font.size = size; - _reset(); + font_.size = size; + Reset(); } -void e2d::Text::setFontWeight(UINT weight) +void e2d::Text::SetFontWeight(UINT weight) { - _font.weight = weight; - _reset(); + font_.weight = weight; + Reset(); } -void e2d::Text::setColor(Color color) +void e2d::Text::SetColor(Color color) { - _style.color = color; + style_.color = color; } -void e2d::Text::setItalic(bool value) +void e2d::Text::SetItalic(bool value) { - _font.italic = value; - _reset(); + font_.italic = value; + Reset(); } -void e2d::Text::setWrapping(bool wrapping) +void e2d::Text::SetWrapEnabled(bool wrap) { - if (_style.wrapping != wrapping) + if (style_.wrap != wrap) { - _style.wrapping = wrapping; - _reset(); + style_.wrap = wrap; + Reset(); } } -void e2d::Text::setWrappingWidth(float wrappingWidth) +void e2d::Text::SetWrapWidth(float wrap_width) { - if (_style.wrappingWidth != wrappingWidth) + if (style_.wrap_width != wrap_width) { - _style.wrappingWidth = std::max(wrappingWidth, 0.f); + style_.wrap_width = std::max(wrap_width, 0.f); - if (_style.wrapping) + if (style_.wrap) { - _reset(); + Reset(); } } } -void e2d::Text::setLineSpacing(float lineSpacing) +void e2d::Text::SetLineSpacing(float line_spacing) { - if (_style.lineSpacing != lineSpacing) + if (style_.line_spacing != line_spacing) { - _style.lineSpacing = lineSpacing; - _reset(); + style_.line_spacing = line_spacing; + Reset(); } } -void e2d::Text::setAlignment(Align align) +void e2d::Text::SetAlignment(Align align) { - if (_style.alignment != align) + if (style_.alignment != align) { - _style.alignment = align; - _reset(); + style_.alignment = align; + Reset(); } } -void e2d::Text::setUnderline(bool hasUnderline) +void e2d::Text::SetUnderline(bool underline) { - if (_style.hasUnderline != hasUnderline) + if (style_.underline != underline) { - _style.hasUnderline = hasUnderline; - if (!_textFormat) - _createFormat(); - _createLayout(); + style_.underline = underline; + if (!text_format_) + CreateFormat(); + CreateLayout(); } } -void e2d::Text::setStrikethrough(bool hasStrikethrough) +void e2d::Text::SetStrikethrough(bool strikethrough) { - if (_style.hasStrikethrough != hasStrikethrough) + if (style_.strikethrough != strikethrough) { - _style.hasStrikethrough = hasStrikethrough; - if (!_textFormat) - _createFormat(); - _createLayout(); + style_.strikethrough = strikethrough; + if (!text_format_) + CreateFormat(); + CreateLayout(); } } -void e2d::Text::setOutline(bool hasOutline) +void e2d::Text::SetOutline(bool outline) { - _style.hasOutline = hasOutline; + style_.outline = outline; } -void e2d::Text::setOutlineColor(Color outlineColor) +void e2d::Text::SetOutlineColor(Color outline_color) { - _style.outlineColor = outlineColor; + style_.outline_color = outline_color; } -void e2d::Text::setOutlineWidth(float outlineWidth) +void e2d::Text::SetOutlineWidth(float outline_width) { - _style.outlineWidth = outlineWidth; + style_.outline_width = outline_width; } -void e2d::Text::setOutlineStroke(Stroke outlineStroke) +void e2d::Text::SetOutlineStroke(Stroke outline_stroke) { - _style.outlineStroke = outlineStroke; + style_.outline_stroke = outline_stroke; } -void e2d::Text::draw() const +void e2d::Text::Draw() const { - if (_textLayout) + if (text_layout_) { - auto renderer = Renderer::getInstance(); + auto renderer = Renderer::GetInstance(); // 创建文本区域 - D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, _width, _height); + D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, size_.width, size_.height); // 设置画刷颜色和透明度 - renderer->getSolidColorBrush()->SetOpacity(_displayOpacity); + renderer->GetSolidBrush()->SetOpacity(display_opacity_); // 获取文本渲染器 - auto textRenderer = renderer->getTextRenderer(); + auto textRenderer = renderer->GetTextRenderer(); textRenderer->SetTextStyle( - (D2D1_COLOR_F)_style.color, - _style.hasOutline, - (D2D1_COLOR_F)_style.outlineColor, - _style.outlineWidth, - D2D1_LINE_JOIN(_style.outlineStroke) + (D2D1_COLOR_F)style_.color, + style_.outline, + (D2D1_COLOR_F)style_.outline_color, + style_.outline_width, + D2D1_LINE_JOIN(style_.outline_stroke) ); - _textLayout->Draw(nullptr, textRenderer, 0, 0); + text_layout_->Draw(nullptr, textRenderer, 0, 0); } } -void e2d::Text::_reset() +void e2d::Text::Reset() { // 创建文字格式化 - _createFormat(); + CreateFormat(); // 创建文字布局 - _createLayout(); + CreateLayout(); } -void e2d::Text::_createFormat() +void e2d::Text::CreateFormat() { - SafeRelease(_textFormat); + SafeRelease(text_format_); ThrowIfFailed( - Renderer::getWriteFactory()->CreateTextFormat( - (const WCHAR *)_font.family, + Renderer::GetWriteFactory()->CreateTextFormat( + (const WCHAR *)font_.family, nullptr, - DWRITE_FONT_WEIGHT(_font.weight), - _font.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL, + DWRITE_FONT_WEIGHT(font_.weight), + font_.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, - _font.size, + font_.size, L"", - &_textFormat + &text_format_ ) ); // 设置文字对齐方式 - _textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT(_style.alignment)); + text_format_->SetTextAlignment(DWRITE_TEXT_ALIGNMENT(style_.alignment)); // 设置行间距 - if (_style.lineSpacing == 0.f) + if (style_.line_spacing == 0.f) { - _textFormat->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_DEFAULT, 0, 0); + text_format_->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_DEFAULT, 0, 0); } else { - _textFormat->SetLineSpacing( + text_format_->SetLineSpacing( DWRITE_LINE_SPACING_METHOD_UNIFORM, - _style.lineSpacing, - _style.lineSpacing * 0.8f + style_.line_spacing, + style_.line_spacing * 0.8f ); } // 打开文本自动换行时,设置换行属性 - if (_style.wrapping) + if (style_.wrap) { - _textFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_WRAP); + text_format_->SetWordWrapping(DWRITE_WORD_WRAPPING_WRAP); } else { - _textFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); + text_format_->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); } } -void e2d::Text::_createLayout() +void e2d::Text::CreateLayout() { - SafeRelease(_textLayout); + SafeRelease(text_layout_); // 文本为空字符串时,重置属性 - if (_text.isEmpty()) + if (text_.IsEmpty()) { - this->setSize(0, 0); + this->SetSize(0, 0); return; } - if (_textFormat == nullptr) + if (text_format_ == nullptr) { - WARN("Text::_createLayout failed! _textFormat NULL pointer exception."); + WARN("Text::CreateLayout failed! text_format_ NULL pointer exception."); return; } - UINT32 length = (UINT32)_text.length(); - auto writeFactory = Renderer::getWriteFactory(); + UINT32 length = (UINT32)text_.GetLength(); + auto writeFactory = Renderer::GetWriteFactory(); // 对文本自动换行情况下进行处理 - if (_style.wrapping) + if (style_.wrap) { ThrowIfFailed( writeFactory->CreateTextLayout( - (const WCHAR *)_text, + (const WCHAR *)text_, length, - _textFormat, - _style.wrappingWidth, + text_format_, + style_.wrap_width, 0, - &_textLayout + &text_layout_ ) ); // 获取文本布局的宽度和高度 DWRITE_TEXT_METRICS metrics; - _textLayout->GetMetrics(&metrics); + text_layout_->GetMetrics(&metrics); // 重设文本宽高 - this->setSize(metrics.layoutWidth, metrics.height); + this->SetSize(metrics.layoutWidth, metrics.height); } else { // 为防止文本对齐问题,根据先创建 layout 以获取宽度 ThrowIfFailed( writeFactory->CreateTextLayout( - (const WCHAR *)_text, + (const WCHAR *)text_, length, - _textFormat, + text_format_, 0, 0, - &_textLayout + &text_layout_ ) ); // 获取文本布局的宽度和高度 DWRITE_TEXT_METRICS metrics; - _textLayout->GetMetrics(&metrics); + text_layout_->GetMetrics(&metrics); // 重设文本宽高 - this->setSize(metrics.width, metrics.height); + this->SetSize(metrics.width, metrics.height); // 重新创建 layout - SafeRelease(_textLayout); + SafeRelease(text_layout_); ThrowIfFailed( writeFactory->CreateTextLayout( - (const WCHAR *)_text, + (const WCHAR *)text_, length, - _textFormat, - _width, + text_format_, + size_.width, 0, - &_textLayout + &text_layout_ ) ); } // 添加下划线和删除线 - DWRITE_TEXT_RANGE range = { 0, length }; - if (_style.hasUnderline) + DWRITE_TEXT_RANGE Range = { 0, length }; + if (style_.underline) { - _textLayout->SetUnderline(true, range); + text_layout_->SetUnderline(true, Range); } - if (_style.hasStrikethrough) + if (style_.strikethrough) { - _textLayout->SetStrikethrough(true, range); + text_layout_->SetStrikethrough(true, Range); } } diff --git a/core/Node/ToggleButton.cpp b/core/Node/ToggleButton.cpp index 89d0f52e..f042dc44 100644 --- a/core/Node/ToggleButton.cpp +++ b/core/Node/ToggleButton.cpp @@ -5,215 +5,215 @@ #define SET_BUTTON_NODE(Old, New) \ if (New != Old) \ { \ - if (Old) this->removeChild(Old); \ + if (Old) this->RemoveChild(Old); \ if (New) \ { \ - New->setAnchor(_anchorX, _anchorY); \ - this->addChild(New); \ + New->SetAnchor(anchor_.x, anchor_.y); \ + this->AddChild(New); \ } \ Old = New; \ - _updateStatus(); \ - _updateVisible(); \ + UpdateStatus(); \ + UpdateVisible(); \ } \ e2d::ToggleButton::ToggleButton() : Button() - , _checked(true) - , _normalOn(nullptr) - , _mouseoverOn(nullptr) - , _selectedOn(nullptr) - , _disabledOn(nullptr) - , _normalOff(nullptr) - , _mouseoverOff(nullptr) - , _selectedOff(nullptr) - , _disabledOff(nullptr) + , checked_(true) + , normal_on_(nullptr) + , mouseover_on_(nullptr) + , selected_on_(nullptr) + , disabled_on_(nullptr) + , normal_off_(nullptr) + , mouseover_off_(nullptr) + , selected_off_(nullptr) + , disabled_off_(nullptr) { } -e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, const Function& func) +e2d::ToggleButton::ToggleButton(Node * normal_on, Node * normal_off, const Function& func) : Button() - , _checked(true) - , _normalOn(nullptr) - , _mouseoverOn(nullptr) - , _selectedOn(nullptr) - , _disabledOn(nullptr) - , _normalOff(nullptr) - , _mouseoverOff(nullptr) - , _selectedOff(nullptr) - , _disabledOff(nullptr) + , checked_(true) + , normal_on_(nullptr) + , mouseover_on_(nullptr) + , selected_on_(nullptr) + , disabled_on_(nullptr) + , normal_off_(nullptr) + , mouseover_off_(nullptr) + , selected_off_(nullptr) + , disabled_off_(nullptr) { - this->setNormal(toggleOnNormal); - this->setNormalOff(toggleOffNormal); - this->setClickFunc(func); + this->SetNormal(normal_on); + this->SetNormalOff(normal_off); + this->SetCallbackOnClick(func); } -e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func) +e2d::ToggleButton::ToggleButton(Node * normal_on, Node * normal_off, Node * selected_on, Node * selected_off, const Function& func) : Button() - , _checked(true) - , _normalOn(nullptr) - , _mouseoverOn(nullptr) - , _selectedOn(nullptr) - , _disabledOn(nullptr) - , _normalOff(nullptr) - , _mouseoverOff(nullptr) - , _selectedOff(nullptr) - , _disabledOff(nullptr) + , checked_(true) + , normal_on_(nullptr) + , mouseover_on_(nullptr) + , selected_on_(nullptr) + , disabled_on_(nullptr) + , normal_off_(nullptr) + , mouseover_off_(nullptr) + , selected_off_(nullptr) + , disabled_off_(nullptr) { - this->setNormal(toggleOnNormal); - this->setNormalOff(toggleOffNormal); - this->setSelected(toggleOnSelected); - this->setSelectedOff(toggleOffSelected); - this->setClickFunc(func); + this->SetNormal(normal_on); + this->SetNormalOff(normal_off); + this->SetSelected(selected_on); + this->SetSelectedOff(selected_off); + this->SetCallbackOnClick(func); } -e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func) +e2d::ToggleButton::ToggleButton(Node * normal_on, Node * normal_off, Node * mouseover_on, Node * mouseover_off, Node * selected_on, Node * selected_off, const Function& func) : Button() - , _checked(true) - , _normalOn(nullptr) - , _mouseoverOn(nullptr) - , _selectedOn(nullptr) - , _disabledOn(nullptr) - , _normalOff(nullptr) - , _mouseoverOff(nullptr) - , _selectedOff(nullptr) - , _disabledOff(nullptr) + , checked_(true) + , normal_on_(nullptr) + , mouseover_on_(nullptr) + , selected_on_(nullptr) + , disabled_on_(nullptr) + , normal_off_(nullptr) + , mouseover_off_(nullptr) + , selected_off_(nullptr) + , disabled_off_(nullptr) { - this->setNormal(toggleOnNormal); - this->setNormalOff(toggleOffNormal); - this->setMouseOver(toggleOnMouseOver); - this->setMouseOverOff(toggleOffMouseOver); - this->setSelected(toggleOnSelected); - this->setSelectedOff(toggleOffSelected); - this->setClickFunc(func); + this->SetNormal(normal_on); + this->SetNormalOff(normal_off); + this->SetMouseOver(mouseover_on); + this->SetMouseOverOff(mouseover_off); + this->SetSelected(selected_on); + this->SetSelectedOff(selected_off); + this->SetCallbackOnClick(func); } -e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, Node * toggleOnDisabled, Node * toggleOffDisabled, const Function& func) +e2d::ToggleButton::ToggleButton(Node * normal_on, Node * normal_off, Node * mouseover_on, Node * mouseover_off, Node * selected_on, Node * selected_off, Node * disabled_on, Node * disabled_off, const Function& func) : Button() - , _checked(true) - , _normalOff(nullptr) - , _mouseoverOff(nullptr) - , _selectedOff(nullptr) - , _disabledOff(nullptr) + , checked_(true) + , normal_off_(nullptr) + , mouseover_off_(nullptr) + , selected_off_(nullptr) + , disabled_off_(nullptr) { - 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); + this->SetNormal(normal_on); + this->SetNormalOff(normal_off); + this->SetMouseOver(mouseover_on); + this->SetMouseOverOff(mouseover_off); + this->SetSelected(selected_on); + this->SetSelectedOff(selected_off); + this->SetDisabled(disabled_on); + this->SetDisabledOff(disabled_off); + this->SetCallbackOnClick(func); } -bool e2d::ToggleButton::isChecked() const +bool e2d::ToggleButton::IsChecked() const { - return _checked; + return checked_; } -void e2d::ToggleButton::setChecked(bool checked) +void e2d::ToggleButton::SetChecked(bool checked) { - if (_checked != checked) + if (checked_ != checked) { - _checked = checked; - _updateStatus(); - _updateVisible(); + checked_ = checked; + UpdateStatus(); + UpdateVisible(); } } -void e2d::ToggleButton::setNormal(Node * normal) +void e2d::ToggleButton::SetNormal(Node * normal) { - SET_BUTTON_NODE(_normalOn, normal); + SET_BUTTON_NODE(normal_on_, normal); if (normal) { - this->setSize(normal->getWidth(), normal->getHeight()); + this->SetSize(normal->GetWidth(), normal->GetHeight()); } } -void e2d::ToggleButton::setMouseOver(Node * mouseover) +void e2d::ToggleButton::SetMouseOver(Node * mouseover) { - SET_BUTTON_NODE(_mouseoverOn, mouseover); + SET_BUTTON_NODE(mouseover_on_, mouseover); } -void e2d::ToggleButton::setSelected(Node * selected) +void e2d::ToggleButton::SetSelected(Node * selected) { - SET_BUTTON_NODE(_selectedOn, selected); + SET_BUTTON_NODE(selected_on_, selected); } -void e2d::ToggleButton::setDisabled(Node * disabled) +void e2d::ToggleButton::SetDisabled(Node * disabled) { - SET_BUTTON_NODE(_disabledOn, disabled); + SET_BUTTON_NODE(disabled_on_, disabled); } -void e2d::ToggleButton::setNormalOff(Node * normal) +void e2d::ToggleButton::SetNormalOff(Node * normal) { - SET_BUTTON_NODE(_normalOff, normal); + SET_BUTTON_NODE(normal_off_, normal); } -void e2d::ToggleButton::setMouseOverOff(Node * mouseover) +void e2d::ToggleButton::SetMouseOverOff(Node * mouseover) { - SET_BUTTON_NODE(_mouseoverOff, mouseover); + SET_BUTTON_NODE(mouseover_off_, mouseover); } -void e2d::ToggleButton::setSelectedOff(Node * selected) +void e2d::ToggleButton::SetSelectedOff(Node * selected) { - SET_BUTTON_NODE(_selectedOff, selected); + SET_BUTTON_NODE(selected_off_, selected); } -void e2d::ToggleButton::setDisabledOff(Node * disabled) +void e2d::ToggleButton::SetDisabledOff(Node * disabled) { - SET_BUTTON_NODE(_disabledOff, disabled); + SET_BUTTON_NODE(disabled_off_, disabled); } -void e2d::ToggleButton::setAnchor(float anchorX, float anchorY) +void e2d::ToggleButton::SetAnchor(float anchor_x, float anchor_y) { - Node::setAnchor(anchorX, anchorY); - SAFE_SET(_normalOn, setAnchor, anchorX, anchorY); - SAFE_SET(_mouseoverOn, setAnchor, anchorX, anchorY); - SAFE_SET(_selectedOn, setAnchor, anchorX, anchorY); - SAFE_SET(_disabledOn, setAnchor, anchorX, anchorY); - SAFE_SET(_normalOff, setAnchor, anchorX, anchorY); - SAFE_SET(_mouseoverOff, setAnchor, anchorX, anchorY); - SAFE_SET(_selectedOff, setAnchor, anchorX, anchorY); - SAFE_SET(_disabledOff, setAnchor, anchorX, anchorY); + Node::SetAnchor(anchor_x, anchor_y); + SAFE_SET(normal_on_, SetAnchor, anchor_x, anchor_y); + SAFE_SET(mouseover_on_, SetAnchor, anchor_x, anchor_y); + SAFE_SET(selected_on_, SetAnchor, anchor_x, anchor_y); + SAFE_SET(disabled_on_, SetAnchor, anchor_x, anchor_y); + SAFE_SET(normal_off_, SetAnchor, anchor_x, anchor_y); + SAFE_SET(mouseover_off_, SetAnchor, anchor_x, anchor_y); + SAFE_SET(selected_off_, SetAnchor, anchor_x, anchor_y); + SAFE_SET(disabled_off_, SetAnchor, anchor_x, anchor_y); } -void e2d::ToggleButton::_updateStatus() +void e2d::ToggleButton::UpdateStatus() { - if (_checked) + if (checked_) { - _normal = _normalOn; - _mouseover = _mouseoverOn; - _selected = _selectedOn; - _disabled = _disabledOn; + normal_ = normal_on_; + mouseover_ = mouseover_on_; + selected_ = selected_on_; + disabled_ = disabled_on_; - SAFE_SET(_normalOff, setVisible, false); - SAFE_SET(_mouseoverOff, setVisible, false); - SAFE_SET(_selectedOff, setVisible, false); - SAFE_SET(_disabledOff, setVisible, false); + SAFE_SET(normal_off_, SetVisible, false); + SAFE_SET(mouseover_off_, SetVisible, false); + SAFE_SET(selected_off_, SetVisible, false); + SAFE_SET(disabled_off_, SetVisible, false); } else { - _normal = _normalOff; - _mouseover = _mouseoverOff; - _selected = _selectedOff; - _disabled = _disabledOff; + normal_ = normal_off_; + mouseover_ = mouseover_off_; + selected_ = selected_off_; + disabled_ = disabled_off_; - SAFE_SET(_normalOn, setVisible, false); - SAFE_SET(_mouseoverOn, setVisible, false); - SAFE_SET(_selectedOn, setVisible, false); - SAFE_SET(_disabledOn, setVisible, false); + SAFE_SET(normal_on_, SetVisible, false); + SAFE_SET(mouseover_on_, SetVisible, false); + SAFE_SET(selected_on_, SetVisible, false); + SAFE_SET(disabled_on_, SetVisible, false); } } -void e2d::ToggleButton::_runCallback() +void e2d::ToggleButton::OnClick() { - _checked = !_checked; - _updateStatus(); + checked_ = !checked_; + UpdateStatus(); - if (_func) + if (callback_) { - _func(); + callback_(); } } diff --git a/core/Tool/Data.cpp b/core/Tool/Data.cpp index bd91dd6e..4b24f7c3 100644 --- a/core/Tool/Data.cpp +++ b/core/Tool/Data.cpp @@ -2,89 +2,89 @@ e2d::Data::Data(const String & key, const String & field) - : _key(key) - , _field(field) - , _dataPath(Path::getDataPath()) + : key_(key) + , field_(field) + , data_path_(Path::GetDataPath()) { } -void e2d::Data::saveInt(int value) +void e2d::Data::SaveInt(int value) { ::WritePrivateProfileString( - (LPCWSTR)_field, - (LPCWSTR)_key, - (LPCWSTR)String::parse(value), - (LPCWSTR)_dataPath + (LPCWSTR)field_, + (LPCWSTR)key_, + (LPCWSTR)String::Parse(value), + (LPCWSTR)data_path_ ); } -void e2d::Data::saveDouble(float value) +void e2d::Data::SaveDouble(float value) { ::WritePrivateProfileString( - (LPCWSTR)_field, - (LPCWSTR)_key, - (LPCWSTR)String::parse(value), - (LPCWSTR)_dataPath + (LPCWSTR)field_, + (LPCWSTR)key_, + (LPCWSTR)String::Parse(value), + (LPCWSTR)data_path_ ); } -void e2d::Data::saveBool(bool value) +void e2d::Data::SaveBool(bool value) { ::WritePrivateProfileString( - (LPCWSTR)_field, - (LPCWSTR)_key, + (LPCWSTR)field_, + (LPCWSTR)key_, (value ? L"1" : L"0"), - (LPCWSTR)_dataPath + (LPCWSTR)data_path_ ); } -void e2d::Data::saveString(const String& value) +void e2d::Data::SaveString(const String& value) { ::WritePrivateProfileString( - (LPCWSTR)_field, - (LPCWSTR)_key, + (LPCWSTR)field_, + (LPCWSTR)key_, (LPCWSTR)value, - (LPCWSTR)_dataPath + (LPCWSTR)data_path_ ); } -int e2d::Data::getInt(int defaultValue) +int e2d::Data::GetInt(int default_value) { return ::GetPrivateProfileInt( - (LPCWSTR)_field, - (LPCWSTR)_key, - defaultValue, - (LPCWSTR)_dataPath + (LPCWSTR)field_, + (LPCWSTR)key_, + default_value, + (LPCWSTR)data_path_ ); } -float e2d::Data::getDouble(float defaultValue) +float e2d::Data::GetDouble(float default_value) { wchar_t temp[32] = { 0 }; - ::GetPrivateProfileString((LPCWSTR)_field, (LPCWSTR)_key, (LPCWSTR)String::parse(defaultValue), temp, 31, (LPCWSTR)_dataPath); + ::GetPrivateProfileString((LPCWSTR)field_, (LPCWSTR)key_, (LPCWSTR)String::Parse(default_value), temp, 31, (LPCWSTR)data_path_); return std::stof(temp); } -bool e2d::Data::getBool(bool defaultValue) +bool e2d::Data::GetBool(bool default_value) { int nValue = ::GetPrivateProfileInt( - (LPCWSTR)_field, - (LPCWSTR)_key, - defaultValue ? 1 : 0, - (LPCWSTR)_dataPath); + (LPCWSTR)field_, + (LPCWSTR)key_, + default_value ? 1 : 0, + (LPCWSTR)data_path_); return nValue != 0; } -e2d::String e2d::Data::getString(const String& defaultValue) +e2d::String e2d::Data::GetString(const String& default_value) { wchar_t temp[256] = { 0 }; ::GetPrivateProfileString( - (LPCWSTR)_field, - (LPCWSTR)_key, - (LPCWSTR)defaultValue, + (LPCWSTR)field_, + (LPCWSTR)key_, + (LPCWSTR)default_value, temp, 255, - (LPCWSTR)_dataPath + (LPCWSTR)data_path_ ); return temp; } \ No newline at end of file diff --git a/core/Tool/File.cpp b/core/Tool/File.cpp index 7adcb5e1..fd33a46b 100644 --- a/core/Tool/File.cpp +++ b/core/Tool/File.cpp @@ -1,49 +1,49 @@ #include "..\e2dtool.h" #include -std::list e2d::File::_searchPaths; +std::list e2d::File::search_paths_; e2d::File::File() - : _fileName() - , _attributes(0) + : file_path_() + , attributes_(0) { } -e2d::File::File(const String & fileName) - : _fileName(fileName) - , _attributes(0) +e2d::File::File(const String & file_name) + : file_path_(file_name) + , attributes_(0) { - this->open(fileName); + this->Open(file_name); } e2d::File::~File() { } -bool e2d::File::open(const String & fileName) +bool e2d::File::Open(const String & file_name) { auto FindFile = [=](const String & path) -> bool { if (::_waccess((const wchar_t*)path, 0) == 0) { - _attributes = ::GetFileAttributes((LPCTSTR)path); + attributes_ = ::GetFileAttributes((LPCTSTR)path); return true; } return false; }; - if (FindFile(fileName)) + if (FindFile(file_name)) { - _fileName = fileName; + file_path_ = file_name; return true; } else { - for (const auto& resPath : _searchPaths) + for (const auto& resPath : search_paths_) { - if (FindFile(resPath + fileName)) + if (FindFile(resPath + file_name)) { - _fileName = resPath + fileName; + file_path_ = resPath + file_name; return true; } } @@ -51,54 +51,62 @@ bool e2d::File::open(const String & fileName) return false; } -bool e2d::File::exists() const +bool e2d::File::Exists() const { - return ::_waccess((const wchar_t*)_fileName, 0) == 0; + return ::_waccess((const wchar_t*)file_path_, 0) == 0; } -bool e2d::File::isFolder() const +bool e2d::File::IsFolder() const { - return (_attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; + return (attributes_ & FILE_ATTRIBUTE_DIRECTORY) != 0; } -const e2d::String& e2d::File::getPath() const +const e2d::String& e2d::File::GetPath() const { - return _fileName; + return file_path_; } -e2d::String e2d::File::getExtension() const +e2d::String e2d::File::GetExtension() const { String fileExtension; // 找到文件名中的最后一个 '.' 的位置 - size_t pos = std::wstring(_fileName).find_last_of(L'.'); + size_t pos = std::wstring(file_path_).find_last_of(L'.'); // 判断 pos 是否是有效位置 if (pos != std::wstring::npos) { // 截取扩展名 - fileExtension = _fileName.subtract(static_cast(pos)); + fileExtension = file_path_.Subtract(static_cast(pos)); // 转换为小写字母 - fileExtension = fileExtension.toLower(); + fileExtension = fileExtension.ToLower(); } return std::move(fileExtension); } -bool e2d::File::del() +bool e2d::File::Delete() { - if (::DeleteFile((LPCWSTR)_fileName)) + if (::DeleteFile((LPCWSTR)file_path_)) return true; return false; } -e2d::File e2d::File::extract(int resNameId, const String & resType, const String& destFileName) +e2d::File e2d::File::Extract(int resource_name, const String & resource_type, const String& dest_file_name) { - String destFilePath = Path::getTempPath() + destFileName; // 创建文件 - HANDLE hFile = ::CreateFile((LPCWSTR)destFilePath, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL); + HANDLE hFile = ::CreateFile( + static_cast(dest_file_name), + GENERIC_WRITE, + NULL, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_TEMPORARY, + NULL + ); + if (hFile == INVALID_HANDLE_VALUE) return std::move(File()); // 查找资源文件中、加载资源到内存、得到资源大小 - HRSRC hRes = ::FindResource(NULL, MAKEINTRESOURCE(resNameId), (LPCWSTR)resType); + HRSRC hRes = ::FindResource(NULL, MAKEINTRESOURCE(resource_name), (LPCWSTR)resource_type); HGLOBAL hMem = ::LoadResource(NULL, hRes); DWORD dwSize = ::SizeofResource(NULL, hRes); @@ -108,42 +116,42 @@ e2d::File e2d::File::extract(int resNameId, const String & resType, const String DWORD dwWrite = 0; ::WriteFile(hFile, hMem, dwSize, &dwWrite, NULL); ::CloseHandle(hFile); - return File(destFilePath); + return File(dest_file_name); } else { ::CloseHandle(hFile); - ::DeleteFile((LPCWSTR)destFilePath); + ::DeleteFile(static_cast(dest_file_name)); return std::move(File()); } } -void e2d::File::addSearchPath(const String & path) +void e2d::File::AddSearchPath(const String & path) { String tmp = path; - tmp.replace(L"/", L"\\"); - if (tmp[tmp.length() - 1] != L'\\') + tmp.Replace(L"/", L"\\"); + if (tmp[tmp.GetLength() - 1] != L'\\') { tmp << L"\\"; } - auto iter = std::find(_searchPaths.cbegin(), _searchPaths.cend(), tmp); - if (iter == _searchPaths.cend()) + auto iter = std::find(search_paths_.cbegin(), search_paths_.cend(), tmp); + if (iter == search_paths_.cend()) { - _searchPaths.push_front(path); + search_paths_.push_front(path); } } -bool e2d::File::createFolder(const String & dirPath) +bool e2d::File::CreateFolder(const String & dir_path) { - if (dirPath.isEmpty() || dirPath.length() >= MAX_PATH) + if (dir_path.IsEmpty() || dir_path.GetLength() >= MAX_PATH) return false; wchar_t tmpDirPath[_MAX_PATH] = { 0 }; - int length = dirPath.length(); + int length = dir_path.GetLength(); for (int i = 0; i < length; ++i) { - tmpDirPath[i] = dirPath.at(i); + tmpDirPath[i] = dir_path.At(i); if (tmpDirPath[i] == L'\\' || tmpDirPath[i] == L'/' || i == (length - 1)) { if (::_waccess(tmpDirPath, 0) != 0) @@ -158,9 +166,9 @@ bool e2d::File::createFolder(const String & dirPath) return true; } -e2d::File e2d::File::showOpenDialog(const String & title, const String & filter) +e2d::File e2d::File::ShowOpenDialog(const String & title, const String & filter) { - String filePath; + String file_path; HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (SUCCEEDED(hr)) @@ -172,12 +180,12 @@ e2d::File e2d::File::showOpenDialog(const String & title, const String & filter) if (SUCCEEDED(hr)) { - if (!title.isEmpty()) + if (!title.IsEmpty()) { pFileOpen->SetTitle(LPCWSTR(title)); } - if (!filter.isEmpty()) + if (!filter.IsEmpty()) { COMDLG_FILTERSPEC rgSpec[] = { @@ -194,12 +202,12 @@ e2d::File e2d::File::showOpenDialog(const String & title, const String & filter) pFileOpen->SetFileTypes(1, rgSpec); } - Game::getInstance()->pause(); + Game::GetInstance()->Pause(); { - HWND hWnd = Window::getInstance()->getHWnd(); + HWND hWnd = Window::GetInstance()->GetHWnd(); hr = pFileOpen->Show(hWnd); } - Game::getInstance()->resume(); + Game::GetInstance()->Resume(); if (SUCCEEDED(hr)) { @@ -212,7 +220,7 @@ e2d::File e2d::File::showOpenDialog(const String & title, const String & filter) if (SUCCEEDED(hr)) { - filePath = pszFilePath; + file_path = pszFilePath; ::CoTaskMemFree(pszFilePath); } pItem->Release(); @@ -222,12 +230,12 @@ e2d::File e2d::File::showOpenDialog(const String & title, const String & filter) } ::CoUninitialize(); } - return std::move(File(filePath)); + return std::move(File(file_path)); } -e2d::File e2d::File::showSaveDialog(const String & title, const String& defFile, const String & defExt) +e2d::File e2d::File::ShowSaveDialog(const String & title, const String& def_file, const String & def_ext) { - String filePath; + String file_path; HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (SUCCEEDED(hr)) @@ -239,21 +247,21 @@ e2d::File e2d::File::showSaveDialog(const String & title, const String& defFile, if (SUCCEEDED(hr)) { - if (!title.isEmpty()) + if (!title.IsEmpty()) { pFileSave->SetTitle(LPCWSTR(title)); } - if (!defFile.isEmpty()) + if (!def_file.IsEmpty()) { - pFileSave->SetFileName(LPCWSTR(defFile)); + pFileSave->SetFileName(LPCWSTR(def_file)); } - if (!defExt.isEmpty()) + if (!def_ext.IsEmpty()) { - pFileSave->SetDefaultExtension(LPCWSTR(defExt)); + pFileSave->SetDefaultExtension(LPCWSTR(def_ext)); - String spec = L"*." + defExt; + String spec = L"*." + def_ext; COMDLG_FILTERSPEC rgSpec[] = { { L"", LPCWSTR(spec) } @@ -269,12 +277,12 @@ e2d::File e2d::File::showSaveDialog(const String & title, const String& defFile, pFileSave->SetFileTypes(1, rgSpec); } - Game::getInstance()->pause(); + Game::GetInstance()->Pause(); { - HWND hWnd = Window::getInstance()->getHWnd(); + HWND hWnd = Window::GetInstance()->GetHWnd(); hr = pFileSave->Show(hWnd); } - Game::getInstance()->resume(); + Game::GetInstance()->Resume(); if (SUCCEEDED(hr)) { @@ -287,7 +295,7 @@ e2d::File e2d::File::showSaveDialog(const String & title, const String& defFile, if (SUCCEEDED(hr)) { - filePath = pszFilePath; + file_path = pszFilePath; ::CoTaskMemFree(pszFilePath); } pItem->Release(); @@ -297,5 +305,5 @@ e2d::File e2d::File::showSaveDialog(const String & title, const String& defFile, } ::CoUninitialize(); } - return std::move(File(filePath)); + return std::move(File(file_path)); } diff --git a/core/Tool/Music.cpp b/core/Tool/Music.cpp index 1a4c310f..a1cdff74 100644 --- a/core/Tool/Music.cpp +++ b/core/Tool/Music.cpp @@ -23,65 +23,65 @@ inline bool TraceError(wchar_t* sPrompt, HRESULT hr) e2d::Music::Music() - : _opened(false) - , _wfx(nullptr) - , _hmmio(nullptr) - , _resBuffer(nullptr) - , _waveData(nullptr) - , _dwSize(0) - , _voice(nullptr) - , _voiceCallback() + : opened_(false) + , wfx_(nullptr) + , hmmio_(nullptr) + , buffer_(nullptr) + , wave_data_(nullptr) + , size_(0) + , voice_(nullptr) + , callback_() { } -e2d::Music::Music(const e2d::String & filePath) - : _opened(false) - , _wfx(nullptr) - , _hmmio(nullptr) - , _resBuffer(nullptr) - , _waveData(nullptr) - , _dwSize(0) - , _voice(nullptr) - , _voiceCallback() +e2d::Music::Music(const e2d::String & file_path) + : opened_(false) + , wfx_(nullptr) + , hmmio_(nullptr) + , buffer_(nullptr) + , wave_data_(nullptr) + , size_(0) + , voice_(nullptr) + , callback_() { - this->open(filePath); + this->Open(file_path); } e2d::Music::Music(const Resource& res) - : _opened(false) - , _wfx(nullptr) - , _hmmio(nullptr) - , _resBuffer(nullptr) - , _waveData(nullptr) - , _dwSize(0) - , _voice(nullptr) - , _voiceCallback() + : opened_(false) + , wfx_(nullptr) + , hmmio_(nullptr) + , buffer_(nullptr) + , wave_data_(nullptr) + , size_(0) + , voice_(nullptr) + , callback_() { - this->open(res); + this->Open(res); } e2d::Music::~Music() { - close(); + Close(); } -bool e2d::Music::open(const e2d::String & filePath) +bool e2d::Music::Open(const e2d::String & file_path) { - if (_opened) + if (opened_) { - close(); + Close(); } - if (filePath.isEmpty()) + if (file_path.IsEmpty()) { - WARN("MusicInfo::open Invalid file name."); + WARN("MusicInfo::Open Invalid file name."); return false; } - String actualFilePath = File(filePath).getPath(); - if (actualFilePath.isEmpty()) + String actualFilePath = File(file_path).GetPath(); + if (actualFilePath.IsEmpty()) { - WARN("MusicInfo::open File not found."); + WARN("MusicInfo::Open File not found."); return false; } @@ -89,13 +89,13 @@ bool e2d::Music::open(const e2d::String & filePath) wchar_t pFilePath[MAX_PATH]; if (!_findMediaFileCch(pFilePath, MAX_PATH, (const wchar_t *)actualFilePath)) { - WARN("Failed to find media file: %s", pFilePath); + WARN("Failed to Find media file: %s", pFilePath); return false; } - _hmmio = mmioOpen(pFilePath, nullptr, MMIO_ALLOCBUF | MMIO_READ); + hmmio_ = mmioOpen(pFilePath, nullptr, MMIO_ALLOCBUF | MMIO_READ); - if (nullptr == _hmmio) + if (nullptr == hmmio_) { return TraceError(L"mmioOpen"); } @@ -103,46 +103,46 @@ bool e2d::Music::open(const e2d::String & filePath) if (!_readMMIO()) { // 读取非 wave 文件时 ReadMMIO 调用失败 - mmioClose(_hmmio, 0); + mmioClose(hmmio_, 0); return TraceError(L"ReadMMIO"); } if (!_resetFile()) return TraceError(L"ResetFile"); - // 重置文件后,wave 文件的大小是 _ck.cksize - _dwSize = _ck.cksize; + // 重置文件后,wave 文件的大小是 ck_.cksize + size_ = ck_.cksize; // 将样本数据读取到内存中 - _waveData = new BYTE[_dwSize]; + wave_data_ = new BYTE[size_]; - if (!_read(_waveData, _dwSize)) + if (!_read(wave_data_, size_)) { TraceError(L"Failed to read WAV data"); - SAFE_DELETE_ARRAY(_waveData); + SAFE_DELETE_ARRAY(wave_data_); return false; } // 创建音源 - auto xAudio2 = Audio::getInstance()->getXAudio2(); - HRESULT hr = xAudio2->CreateSourceVoice(&_voice, _wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &_voiceCallback); + auto xAudio2 = Audio::GetInstance()->GetXAudio2(); + HRESULT hr = xAudio2->CreateSourceVoice(&voice_, wfx_, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &callback_); if (FAILED(hr)) { TraceError(L"Create source voice error", hr); - SAFE_DELETE_ARRAY(_waveData); + SAFE_DELETE_ARRAY(wave_data_); return false; } - _opened = true; + opened_ = true; return true; } -bool e2d::Music::open(const Resource& res) +bool e2d::Music::Open(const Resource& res) { - if (_opened) + if (opened_) { - close(); + Close(); } HRSRC hResInfo; @@ -150,7 +150,7 @@ bool e2d::Music::open(const Resource& res) DWORD dwSize; void* pvRes; - if (nullptr == (hResInfo = FindResourceW(HINST_THISCOMPONENT, MAKEINTRESOURCE(res.resNameId), (LPCWSTR)res.resType))) + if (nullptr == (hResInfo = FindResourceW(HINST_THISCOMPONENT, MAKEINTRESOURCE(res.name), (LPCWSTR)res.type))) return TraceError(L"FindResource"); if (nullptr == (hResData = LoadResource(HINST_THISCOMPONENT, hResInfo))) @@ -162,18 +162,18 @@ bool e2d::Music::open(const Resource& res) if (nullptr == (pvRes = LockResource(hResData))) return TraceError(L"LockResource"); - _resBuffer = new CHAR[dwSize]; - memcpy(_resBuffer, pvRes, dwSize); + buffer_ = new CHAR[dwSize]; + memcpy(buffer_, pvRes, dwSize); MMIOINFO mmioInfo; ZeroMemory(&mmioInfo, sizeof(mmioInfo)); mmioInfo.fccIOProc = FOURCC_MEM; mmioInfo.cchBuffer = dwSize; - mmioInfo.pchBuffer = (CHAR*)_resBuffer; + mmioInfo.pchBuffer = (CHAR*)buffer_; - _hmmio = mmioOpen(nullptr, &mmioInfo, MMIO_ALLOCBUF | MMIO_READ); + hmmio_ = mmioOpen(nullptr, &mmioInfo, MMIO_ALLOCBUF | MMIO_READ); - if (nullptr == _hmmio) + if (nullptr == hmmio_) { return TraceError(L"mmioOpen"); } @@ -181,171 +181,171 @@ bool e2d::Music::open(const Resource& res) if (!_readMMIO()) { // 读取非 wave 文件时 ReadMMIO 调用失败 - mmioClose(_hmmio, 0); + mmioClose(hmmio_, 0); return TraceError(L"ReadMMIO"); } if (!_resetFile()) return TraceError(L"ResetFile"); - // 重置文件后,wave 文件的大小是 _ck.cksize - _dwSize = _ck.cksize; + // 重置文件后,wave 文件的大小是 ck_.cksize + size_ = ck_.cksize; // 将样本数据读取到内存中 - _waveData = new BYTE[_dwSize]; + wave_data_ = new BYTE[size_]; - if (!_read(_waveData, _dwSize)) + if (!_read(wave_data_, size_)) { TraceError(L"Failed to read WAV data"); - SAFE_DELETE_ARRAY(_waveData); + SAFE_DELETE_ARRAY(wave_data_); return false; } // 创建音源 - auto xAudio2 = Audio::getInstance()->getXAudio2(); - HRESULT hr = xAudio2->CreateSourceVoice(&_voice, _wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &_voiceCallback); + auto xAudio2 = Audio::GetInstance()->GetXAudio2(); + HRESULT hr = xAudio2->CreateSourceVoice(&voice_, wfx_, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &callback_); if (FAILED(hr)) { TraceError(L"Create source voice error", hr); - SAFE_DELETE_ARRAY(_waveData); + SAFE_DELETE_ARRAY(wave_data_); return false; } - _opened = true; + opened_ = true; return true; } -bool e2d::Music::play(int nLoopCount) +bool e2d::Music::Play(int loop_count) { - if (!_opened) + if (!opened_) { - WARN("Music::play Failed: Music must be opened first!"); + WARN("Music::Play Failed: Music must be opened first!"); return false; } - if (_voice == nullptr) + if (voice_ == nullptr) { - WARN("Music::play Failed: IXAudio2SourceVoice Null pointer exception!"); + WARN("Music::Play Failed: IXAudio2SourceVoice Null pointer exception!"); return false; } XAUDIO2_VOICE_STATE state; - _voice->GetState(&state); + voice_->GetState(&state); if (state.BuffersQueued) { - stop(); + Stop(); } - nLoopCount = std::min(nLoopCount, XAUDIO2_LOOP_INFINITE - 1); - nLoopCount = (nLoopCount < 0) ? XAUDIO2_LOOP_INFINITE : nLoopCount; + loop_count = std::min(loop_count, XAUDIO2_LOOP_INFINITE - 1); + loop_count = (loop_count < 0) ? XAUDIO2_LOOP_INFINITE : loop_count; // 提交 wave 样本数据 XAUDIO2_BUFFER buffer = { 0 }; - buffer.pAudioData = _waveData; + buffer.pAudioData = wave_data_; buffer.Flags = XAUDIO2_END_OF_STREAM; - buffer.AudioBytes = _dwSize; - buffer.LoopCount = nLoopCount; + buffer.AudioBytes = size_; + buffer.LoopCount = loop_count; HRESULT hr; - if (FAILED(hr = _voice->SubmitSourceBuffer(&buffer))) + if (FAILED(hr = voice_->SubmitSourceBuffer(&buffer))) { TraceError(L"Submitting source buffer error", hr); - _voice->DestroyVoice(); - SAFE_DELETE_ARRAY(_waveData); + voice_->DestroyVoice(); + SAFE_DELETE_ARRAY(wave_data_); return false; } - hr = _voice->Start(0); + hr = voice_->Start(0); return SUCCEEDED(hr); } -void e2d::Music::pause() +void e2d::Music::Pause() { - if (_voice) + if (voice_) { - _voice->Stop(); + voice_->Stop(); } } -void e2d::Music::resume() +void e2d::Music::Resume() { - if (_voice) + if (voice_) { - _voice->Start(); + voice_->Start(); } } -void e2d::Music::stop() +void e2d::Music::Stop() { - if (_voice) + if (voice_) { - if (SUCCEEDED(_voice->Stop())) + if (SUCCEEDED(voice_->Stop())) { - _voice->ExitLoop(); - _voice->FlushSourceBuffers(); + voice_->ExitLoop(); + voice_->FlushSourceBuffers(); } } } -void e2d::Music::close() +void e2d::Music::Close() { - if (_voice) + if (voice_) { - _voice->Stop(); - _voice->FlushSourceBuffers(); - _voice->DestroyVoice(); - _voice = nullptr; + voice_->Stop(); + voice_->FlushSourceBuffers(); + voice_->DestroyVoice(); + voice_ = nullptr; } - if (_hmmio != nullptr) + if (hmmio_ != nullptr) { - mmioClose(_hmmio, 0); - _hmmio = nullptr; + mmioClose(hmmio_, 0); + hmmio_ = nullptr; } - SAFE_DELETE_ARRAY(_resBuffer); - SAFE_DELETE_ARRAY(_waveData); - SAFE_DELETE_ARRAY(_wfx); + SAFE_DELETE_ARRAY(buffer_); + SAFE_DELETE_ARRAY(wave_data_); + SAFE_DELETE_ARRAY(wfx_); - _opened = false; + opened_ = false; } -bool e2d::Music::isPlaying() const +bool e2d::Music::IsPlaying() const { - if (_opened && _voice) + if (opened_ && voice_) { XAUDIO2_VOICE_STATE state; - _voice->GetState(&state); + voice_->GetState(&state); if (state.BuffersQueued) return true; } return false; } -IXAudio2SourceVoice * e2d::Music::getIXAudio2SourceVoice() const +IXAudio2SourceVoice * e2d::Music::GetSourceVoice() const { - return _voice; + return voice_; } -bool e2d::Music::setVolume(float volume) +bool e2d::Music::SetVolume(float volume) { - if (_voice) + if (voice_) { - return SUCCEEDED(_voice->SetVolume(volume)); + return SUCCEEDED(voice_->SetVolume(volume)); } return false; } -void e2d::Music::setFuncOnEnd(const Function & func) +void e2d::Music::SetCallbackOnEnd(const Function & func) { - _voiceCallback.SetFuncOnStreamEnd(func); + callback_.SetCallbackOnStreamEnd(func); } -void e2d::Music::setFuncOnLoopEnd(const Function & func) +void e2d::Music::SetCallbackOnLoopEnd(const Function & func) { - _voiceCallback.SetFuncOnLoopEnd(func); + callback_.SetCallbackOnLoopEnd(func); } bool e2d::Music::_readMMIO() @@ -355,19 +355,19 @@ bool e2d::Music::_readMMIO() memset(&ckIn, 0, sizeof(ckIn)); - _wfx = nullptr; + wfx_ = nullptr; - if ((0 != mmioDescend(_hmmio, &_ckRiff, nullptr, 0))) + if ((0 != mmioDescend(hmmio_, &ck_riff_, nullptr, 0))) return TraceError(L"mmioDescend"); // 确认文件是一个合法的 wave 文件 - if ((_ckRiff.ckid != FOURCC_RIFF) || - (_ckRiff.fccType != mmioFOURCC('W', 'A', 'V', 'E'))) + if ((ck_riff_.ckid != FOURCC_RIFF) || + (ck_riff_.fccType != mmioFOURCC('W', 'A', 'V', 'E'))) return TraceError(L"mmioFOURCC"); // 在输入文件中查找 'fmt' 块 ckIn.ckid = mmioFOURCC('f', 'm', 't', ' '); - if (0 != mmioDescend(_hmmio, &ckIn, &_ckRiff, MMIO_FINDCHUNK)) + if (0 != mmioDescend(hmmio_, &ckIn, &ck_riff_, MMIO_FINDCHUNK)) return TraceError(L"mmioDescend"); // 'fmt' 块至少应和 PCMWAVEFORMAT 一样大 @@ -375,7 +375,7 @@ bool e2d::Music::_readMMIO() return TraceError(L"sizeof(PCMWAVEFORMAT)"); // 将 'fmt' 块读取到 pcmWaveFormat 中 - if (mmioRead(_hmmio, (HPSTR)&pcmWaveFormat, + if (mmioRead(hmmio_, (HPSTR)&pcmWaveFormat, sizeof(pcmWaveFormat)) != sizeof(pcmWaveFormat)) return TraceError(L"mmioRead"); @@ -383,37 +383,37 @@ bool e2d::Music::_readMMIO() // 的数据,这个数据就是额外分配的大小 if (pcmWaveFormat.wf.wFormatTag == WAVE_FORMAT_PCM) { - _wfx = (WAVEFORMATEX*) new CHAR[sizeof(WAVEFORMATEX)]; + wfx_ = (WAVEFORMATEX*) new CHAR[sizeof(WAVEFORMATEX)]; // 拷贝数据 - memcpy(_wfx, &pcmWaveFormat, sizeof(pcmWaveFormat)); - _wfx->cbSize = 0; + memcpy(wfx_, &pcmWaveFormat, sizeof(pcmWaveFormat)); + wfx_->cbSize = 0; } else { // 读取额外数据的大小 WORD cbExtraBytes = 0L; - if (mmioRead(_hmmio, (CHAR*)&cbExtraBytes, sizeof(WORD)) != sizeof(WORD)) + if (mmioRead(hmmio_, (CHAR*)&cbExtraBytes, sizeof(WORD)) != sizeof(WORD)) return TraceError(L"mmioRead"); - _wfx = (WAVEFORMATEX*) new CHAR[sizeof(WAVEFORMATEX) + cbExtraBytes]; + wfx_ = (WAVEFORMATEX*) new CHAR[sizeof(WAVEFORMATEX) + cbExtraBytes]; // 拷贝数据 - memcpy(_wfx, &pcmWaveFormat, sizeof(pcmWaveFormat)); - _wfx->cbSize = cbExtraBytes; + memcpy(wfx_, &pcmWaveFormat, sizeof(pcmWaveFormat)); + wfx_->cbSize = cbExtraBytes; // 读取额外数据 - if (mmioRead(_hmmio, (CHAR*)(((BYTE*)&(_wfx->cbSize)) + sizeof(WORD)), + if (mmioRead(hmmio_, (CHAR*)(((BYTE*)&(wfx_->cbSize)) + sizeof(WORD)), cbExtraBytes) != cbExtraBytes) { - SAFE_DELETE(_wfx); + SAFE_DELETE(wfx_); return TraceError(L"mmioRead"); } } - if (0 != mmioAscend(_hmmio, &ckIn, 0)) + if (0 != mmioAscend(hmmio_, &ckIn, 0)) { - SAFE_DELETE(_wfx); + SAFE_DELETE(wfx_); return TraceError(L"mmioAscend"); } @@ -423,37 +423,37 @@ bool e2d::Music::_readMMIO() bool e2d::Music::_resetFile() { // Seek to the data - if (-1 == mmioSeek(_hmmio, _ckRiff.dwDataOffset + sizeof(FOURCC), + if (-1 == mmioSeek(hmmio_, ck_riff_.dwDataOffset + sizeof(FOURCC), SEEK_SET)) return TraceError(L"mmioSeek"); // Search the input file for the 'data' chunk. - _ck.ckid = mmioFOURCC('d', 'a', 't', 'a'); - if (0 != mmioDescend(_hmmio, &_ck, &_ckRiff, MMIO_FINDCHUNK)) + ck_.ckid = mmioFOURCC('d', 'a', 't', 'a'); + if (0 != mmioDescend(hmmio_, &ck_, &ck_riff_, MMIO_FINDCHUNK)) return TraceError(L"mmioDescend"); return true; } -bool e2d::Music::_read(BYTE* pBuffer, DWORD dwSizeToRead) +bool e2d::Music::_read(BYTE* buffer, DWORD size_to_read) { - MMIOINFO mmioinfoIn; // current status of _hmmio + MMIOINFO mmioinfoIn; // current status of hmmio_ - if (0 != mmioGetInfo(_hmmio, &mmioinfoIn, 0)) + if (0 != mmioGetInfo(hmmio_, &mmioinfoIn, 0)) return TraceError(L"mmioGetInfo"); - UINT cbDataIn = dwSizeToRead; - if (cbDataIn > _ck.cksize) - cbDataIn = _ck.cksize; + UINT cbDataIn = size_to_read; + if (cbDataIn > ck_.cksize) + cbDataIn = ck_.cksize; - _ck.cksize -= cbDataIn; + ck_.cksize -= cbDataIn; for (DWORD cT = 0; cT < cbDataIn; ++cT) { // Copy the bytes from the io to the buffer. if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead) { - if (0 != mmioAdvance(_hmmio, &mmioinfoIn, MMIO_READ)) + if (0 != mmioAdvance(hmmio_, &mmioinfoIn, MMIO_READ)) return TraceError(L"mmioAdvance"); if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead) @@ -461,24 +461,24 @@ bool e2d::Music::_read(BYTE* pBuffer, DWORD dwSizeToRead) } // Actual copy. - *((BYTE*)pBuffer + cT) = *((BYTE*)mmioinfoIn.pchNext); + *((BYTE*)buffer + cT) = *((BYTE*)mmioinfoIn.pchNext); ++mmioinfoIn.pchNext; } - if (0 != mmioSetInfo(_hmmio, &mmioinfoIn, 0)) + if (0 != mmioSetInfo(hmmio_, &mmioinfoIn, 0)) return TraceError(L"mmioSetInfo"); return true; } -bool e2d::Music::_findMediaFileCch(wchar_t* strDestPath, int cchDest, const wchar_t * strFilename) +bool e2d::Music::_findMediaFileCch(wchar_t* dest_path, int cch_dest, const wchar_t * file_name) { bool bFound = false; - if (nullptr == strFilename || nullptr == strDestPath || cchDest < 10) + if (nullptr == file_name || nullptr == dest_path || cch_dest < 10) return false; - // Get the exe _name, and exe path + // Get the exe name, and exe path wchar_t strExePath[MAX_PATH] = { 0 }; wchar_t strExeName[MAX_PATH] = { 0 }; GetModuleFileName(HINST_THISCOMPONENT, strExePath, MAX_PATH); @@ -489,22 +489,22 @@ bool e2d::Music::_findMediaFileCch(wchar_t* strDestPath, int cchDest, const wcha { wcscpy_s(strExeName, MAX_PATH, &strLastSlash[1]); - // Chop the exe _name from the exe path + // Chop the exe name from the exe path *strLastSlash = 0; - // Chop the .exe from the exe _name + // Chop the .exe from the exe name strLastSlash = wcsrchr(strExeName, TEXT('.')); if (strLastSlash) *strLastSlash = 0; } - wcscpy_s(strDestPath, cchDest, strFilename); - if (GetFileAttributes(strDestPath) != 0xFFFFFFFF) + wcscpy_s(dest_path, cch_dest, file_name); + if (GetFileAttributes(dest_path) != 0xFFFFFFFF) return true; - // Search all parent directories starting at .\ and using strFilename as the leaf _name + // Search all parent directories starting At .\ and using file_name as the leaf name wchar_t strLeafName[MAX_PATH] = { 0 }; - wcscpy_s(strLeafName, MAX_PATH, strFilename); + wcscpy_s(strLeafName, MAX_PATH, file_name); wchar_t strFullPath[MAX_PATH] = { 0 }; wchar_t strFullFileName[MAX_PATH] = { 0 }; @@ -520,7 +520,7 @@ bool e2d::Music::_findMediaFileCch(wchar_t* strDestPath, int cchDest, const wcha swprintf_s(strFullFileName, MAX_PATH, L"%s\\%s", strFullPath, strLeafName); if (GetFileAttributes(strFullFileName) != 0xFFFFFFFF) { - wcscpy_s(strDestPath, cchDest, strFullFileName); + wcscpy_s(dest_path, cch_dest, strFullFileName); bFound = true; break; } @@ -528,7 +528,7 @@ bool e2d::Music::_findMediaFileCch(wchar_t* strDestPath, int cchDest, const wcha swprintf_s(strFullFileName, MAX_PATH, L"%s\\%s\\%s", strFullPath, strExeName, strLeafName); if (GetFileAttributes(strFullFileName) != 0xFFFFFFFF) { - wcscpy_s(strDestPath, cchDest, strFullFileName); + wcscpy_s(dest_path, cch_dest, strFullFileName); bFound = true; break; } @@ -540,7 +540,7 @@ bool e2d::Music::_findMediaFileCch(wchar_t* strDestPath, int cchDest, const wcha return true; // 失败时,将文件作为路径返回,同时也返回错误代码 - wcscpy_s(strDestPath, cchDest, strFilename); + wcscpy_s(dest_path, cch_dest, file_name); return false; } diff --git a/core/Tool/Path.cpp b/core/Tool/Path.cpp index c164bc2e..5c560444 100644 --- a/core/Tool/Path.cpp +++ b/core/Tool/Path.cpp @@ -1,79 +1,79 @@ #include "..\e2dtool.h" #include -e2d::String e2d::Path::getDataPath() +const e2d::String& e2d::Path::GetDataPath() { - static String dataPath; - if (dataPath.isEmpty()) + static String data_path; + if (data_path.IsEmpty()) { // 设置数据的保存路径 - String localAppDataPath = Path::getLocalAppDataPath(); - String title = Window::getInstance()->getTitle(); - String folderName = String::parse(title.hash()); + String local_app_data_path = Path::GetLocalAppDataPath(); + String title = Window::GetInstance()->GetTitle(); + String folder_name = String::Parse(title.GetHash()); - if (!localAppDataPath.isEmpty()) + if (!local_app_data_path.IsEmpty()) { - dataPath = localAppDataPath + L"\\Easy2DGameData\\" << folderName << L"\\"; + data_path = local_app_data_path + L"\\Easy2DGameData\\" << folder_name << L"\\"; - File file(dataPath); - if (!file.exists() && !File::createFolder(dataPath)) + File file(data_path); + if (!file.Exists() && !File::CreateFolder(data_path)) { - dataPath = L""; + data_path = L""; } } - dataPath << L"Data.ini"; + data_path << L"Data.ini"; } - return dataPath; + return data_path; } -e2d::String e2d::Path::getTempPath() +const e2d::String& e2d::Path::GetTemporaryPath() { - static String tempPath; - if (tempPath.isEmpty()) + static String temp_path; + if (temp_path.IsEmpty()) { // 设置临时文件保存路径 wchar_t path[_MAX_PATH]; - String title = Window::getInstance()->getTitle(); - String folderName = String::parse(title.hash()); + String title = Window::GetInstance()->GetTitle(); + String folder_name = String::Parse(title.GetHash()); if (0 != ::GetTempPath(_MAX_PATH, path)) { - tempPath << path << L"\\Easy2DGameTemp\\" << folderName << L"\\"; + temp_path << path << L"\\Easy2DGameTemp\\" << folder_name << L"\\"; - File file(tempPath); - if (!file.exists() && !File::createFolder(tempPath)) + File file(temp_path); + if (!file.Exists() && !File::CreateFolder(temp_path)) { - tempPath = L""; + temp_path = L""; } } } - return tempPath; + return temp_path; } -e2d::String e2d::Path::getLocalAppDataPath() +const e2d::String& e2d::Path::GetLocalAppDataPath() { - static String localAppDataPath; - if (localAppDataPath.isEmpty()) + static String local_app_data_path; + if (local_app_data_path.IsEmpty()) { // 获取 AppData/Local 文件夹的路径 - WCHAR strPath[MAX_PATH] = { 0 }; - ::SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, strPath); - localAppDataPath = strPath; + WCHAR path[MAX_PATH] = { 0 }; + ::SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path); + local_app_data_path = path; } - return localAppDataPath; + return local_app_data_path; } -e2d::String e2d::Path::getCurrentFilePath() +const e2d::String& e2d::Path::GetExeFilePath() { - static String currFilePath; - if (currFilePath.isEmpty()) + static String exe_file_path; + if (exe_file_path.IsEmpty()) { - TCHAR szPath[_MAX_PATH] = { 0 }; - if (::GetModuleFileName(nullptr, szPath, _MAX_PATH) != 0) + TCHAR path[_MAX_PATH] = { 0 }; + if (::GetModuleFileName(nullptr, path, _MAX_PATH) != 0) { - currFilePath = szPath; + exe_file_path = path; } } - return currFilePath; + return exe_file_path; } diff --git a/core/Tool/Player.cpp b/core/Tool/Player.cpp index 7c655652..d1aa096a 100644 --- a/core/Tool/Player.cpp +++ b/core/Tool/Player.cpp @@ -1,67 +1,67 @@ #include "..\e2dtool.h" -e2d::Player * e2d::Player::_instance = nullptr; +e2d::Player * e2d::Player::instance_ = nullptr; -e2d::Player * e2d::Player::getInstance() +e2d::Player * e2d::Player::GetInstance() { - if (!_instance) + if (!instance_) { - _instance = new (std::nothrow) Player; + instance_ = new (std::nothrow) Player; } - return _instance; + return instance_; } -void e2d::Player::destroyInstance() +void e2d::Player::DestroyInstance() { - if (_instance) + if (instance_) { - delete _instance; - _instance = nullptr; + delete instance_; + instance_ = nullptr; } } e2d::Player::Player() - : _volume(1.f) + : volume_(1.f) { } e2d::Player::~Player() { - if (!_musicList.empty()) + if (!musics_.empty()) { - for (const auto& pair : _musicList) + for (const auto& pair : musics_) { delete pair.second; } } } -bool e2d::Player::preload(const String & filePath) +bool e2d::Player::Preload(const String & file_path) { - if (filePath.isEmpty()) + if (file_path.IsEmpty()) return false; Music * music = new (std::nothrow) Music(); - if (music && music->open(filePath)) + if (music && music->Open(file_path)) { - music->setVolume(_volume); - _musicList.insert(std::make_pair(filePath.hash(), music)); + music->SetVolume(volume_); + musics_.insert(std::make_pair(file_path.GetHash(), music)); return true; } return false; } -bool e2d::Player::play(const String & filePath, int nLoopCount) +bool e2d::Player::Play(const String & file_path, int loop_count) { - if (filePath.isEmpty()) + if (file_path.IsEmpty()) return false; - if (Player::preload(filePath)) + if (Player::Preload(file_path)) { - auto music = _musicList[filePath.hash()]; - if (music->play(nLoopCount)) + auto music = musics_[file_path.GetHash()]; + if (music->Play(loop_count)) { return true; } @@ -69,69 +69,69 @@ bool e2d::Player::play(const String & filePath, int nLoopCount) return false; } -void e2d::Player::pause(const String & filePath) +void e2d::Player::Pause(const String & file_path) { - if (filePath.isEmpty()) + if (file_path.IsEmpty()) return; - size_t hash = filePath.hash(); - if (_musicList.end() != _musicList.find(hash)) - _musicList[hash]->pause(); + size_t hash = file_path.GetHash(); + if (musics_.end() != musics_.find(hash)) + musics_[hash]->Pause(); } -void e2d::Player::resume(const String & filePath) +void e2d::Player::Resume(const String & file_path) { - if (filePath.isEmpty()) + if (file_path.IsEmpty()) return; - size_t hash = filePath.hash(); - if (_musicList.end() != _musicList.find(hash)) - _musicList[hash]->resume(); + size_t hash = file_path.GetHash(); + if (musics_.end() != musics_.find(hash)) + musics_[hash]->Resume(); } -void e2d::Player::stop(const String & filePath) +void e2d::Player::Stop(const String & file_path) { - if (filePath.isEmpty()) + if (file_path.IsEmpty()) return; - size_t hash = filePath.hash(); - if (_musicList.end() != _musicList.find(hash)) - _musicList[hash]->stop(); + size_t hash = file_path.GetHash(); + if (musics_.end() != musics_.find(hash)) + musics_[hash]->Stop(); } -bool e2d::Player::isPlaying(const String & filePath) +bool e2d::Player::IsPlaying(const String & file_path) { - if (filePath.isEmpty()) + if (file_path.IsEmpty()) return false; - size_t hash = filePath.hash(); - if (_musicList.end() != _musicList.find(hash)) - return _musicList[hash]->isPlaying(); + size_t hash = file_path.GetHash(); + if (musics_.end() != musics_.find(hash)) + return musics_[hash]->IsPlaying(); return false; } -bool e2d::Player::preload(const Resource& res) +bool e2d::Player::Preload(const Resource& res) { - if (_musicList.end() != _musicList.find(res.resNameId)) + if (musics_.end() != musics_.find(res.name)) return true; Music * music = new (std::nothrow) Music(); - if (music && music->open(res)) + if (music && music->Open(res)) { - music->setVolume(_volume); - _musicList.insert(std::make_pair(res.resNameId, music)); + music->SetVolume(volume_); + musics_.insert(std::make_pair(res.name, music)); return true; } return false; } -bool e2d::Player::play(const Resource& res, int nLoopCount) +bool e2d::Player::Play(const Resource& res, int loop_count) { - if (Player::preload(res)) + if (Player::Preload(res)) { - auto music = _musicList[res.resNameId]; - if (music->play(nLoopCount)) + auto music = musics_[res.name]; + if (music->Play(loop_count)) { return true; } @@ -139,74 +139,74 @@ bool e2d::Player::play(const Resource& res, int nLoopCount) return false; } -void e2d::Player::pause(const Resource& res) +void e2d::Player::Pause(const Resource& res) { - if (_musicList.end() != _musicList.find(res.resNameId)) - _musicList[res.resNameId]->pause(); + if (musics_.end() != musics_.find(res.name)) + musics_[res.name]->Pause(); } -void e2d::Player::resume(const Resource& res) +void e2d::Player::Resume(const Resource& res) { - if (_musicList.end() != _musicList.find(res.resNameId)) - _musicList[res.resNameId]->resume(); + if (musics_.end() != musics_.find(res.name)) + musics_[res.name]->Resume(); } -void e2d::Player::stop(const Resource& res) +void e2d::Player::Stop(const Resource& res) { - if (_musicList.end() != _musicList.find(res.resNameId)) - _musicList[res.resNameId]->stop(); + if (musics_.end() != musics_.find(res.name)) + musics_[res.name]->Stop(); } -bool e2d::Player::isPlaying(const Resource& res) +bool e2d::Player::IsPlaying(const Resource& res) { - if (_musicList.end() != _musicList.find(res.resNameId)) - return _musicList[res.resNameId]->isPlaying(); + if (musics_.end() != musics_.find(res.name)) + return musics_[res.name]->IsPlaying(); return false; } -float e2d::Player::getVolume() +float e2d::Player::GetVolume() { - return _volume; + return volume_; } -void e2d::Player::setVolume(float volume) +void e2d::Player::SetVolume(float volume) { - _volume = std::min(std::max(volume, -224.f), 224.f); - for (const auto& pair : _musicList) + volume_ = std::min(std::max(volume, -224.f), 224.f); + for (const auto& pair : musics_) { - pair.second->setVolume(_volume); + pair.second->SetVolume(volume_); } } -void e2d::Player::pauseAll() +void e2d::Player::PauseAll() { - for (const auto& pair : _musicList) + for (const auto& pair : musics_) { - pair.second->pause(); + pair.second->Pause(); } } -void e2d::Player::resumeAll() +void e2d::Player::ResumeAll() { - for (const auto& pair : _musicList) + for (const auto& pair : musics_) { - pair.second->resume(); + pair.second->Resume(); } } -void e2d::Player::stopAll() +void e2d::Player::StopAll() { - for (const auto& pair : _musicList) + for (const auto& pair : musics_) { - pair.second->stop(); + pair.second->Stop(); } } -void e2d::Player::clearCache() +void e2d::Player::ClearCache() { - for (const auto& pair : _musicList) + for (const auto& pair : musics_) { delete pair.second; } - _musicList.clear(); + musics_.clear(); } diff --git a/core/Tool/Random.cpp b/core/Tool/Random.cpp index ca65fac9..09d55ec2 100644 --- a/core/Tool/Random.cpp +++ b/core/Tool/Random.cpp @@ -1,6 +1,6 @@ #include "..\e2dtool.h" -std::default_random_engine &e2d::Random::__getEngine() +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 17b1a53c..5e11f18d 100644 --- a/core/Tool/Task.cpp +++ b/core/Tool/Task.cpp @@ -2,70 +2,70 @@ e2d::Task::Task(const Function & func, const String & name) - : _running(true) - , _stopped(false) - , _runTimes(0) - , _totalTimes(-1) - , _delay() - , _callback(func) - , _name(name) + : running_(true) + , stopped_(false) + , run_times_(0) + , total_times_(-1) + , delay_() + , callback_(func) + , name_(name) { } e2d::Task::Task(const Function & func, float delay, int times, const String & name) - : _running(true) - , _stopped(false) - , _runTimes(0) - , _delay(std::max(delay, 0.f)) - , _totalTimes(times) - , _callback(func) - , _name(name) + : running_(true) + , stopped_(false) + , run_times_(0) + , delay_(std::max(delay, 0.f)) + , total_times_(times) + , callback_(func) + , name_(name) { } -void e2d::Task::start() +void e2d::Task::Start() { - _running = true; - _lastTime = Time::now(); + running_ = true; + last_time_ = Time::Now(); } -void e2d::Task::stop() +void e2d::Task::Stop() { - _running = false; + running_ = false; } -void e2d::Task::_update() +void e2d::Task::Update() { - if (_totalTimes == 0) + if (total_times_ == 0) { - _stopped = true; + stopped_ = true; return; } - ++_runTimes; - _lastTime += _delay; + ++run_times_; + last_time_ += delay_; - if (_callback) + if (callback_) { - _callback(); + callback_(); } - if (_runTimes == _totalTimes) + if (run_times_ == total_times_) { - _stopped = true; + stopped_ = true; return; } } -bool e2d::Task::_isReady() const +bool e2d::Task::IsReady() const { - if (_running) + if (running_) { - if (_delay.milliseconds() == 0) + if (delay_.Milliseconds() == 0) { return true; } - if (Time::now() - _lastTime >= _delay) + if (Time::Now() - last_time_ >= delay_) { return true; } @@ -73,12 +73,12 @@ bool e2d::Task::_isReady() const return false; } -bool e2d::Task::isRunning() const +bool e2d::Task::IsRunning() const { - return _running; + return running_; } -e2d::String e2d::Task::getName() const +const e2d::String& e2d::Task::GetName() const { - return _name; + return name_; } diff --git a/core/Tool/Timer.cpp b/core/Tool/Timer.cpp index 29a6f859..9934b00f 100644 --- a/core/Tool/Timer.cpp +++ b/core/Tool/Timer.cpp @@ -1,14 +1,14 @@ #include "..\e2dtool.h" -e2d::Timer * e2d::Timer::getInstance() +e2d::Timer * e2d::Timer::GetInstance() { static Timer instance; return &instance; } e2d::Timer::Timer() - : _tasks() + : tasks_() { } @@ -16,114 +16,114 @@ e2d::Timer::~Timer() { } -void e2d::Timer::addTask(Task * task) +void e2d::Timer::AddTask(Task * task) { if (task) { - auto iter = std::find(_tasks.begin(), _tasks.end(), task); - if (iter == _tasks.end()) + auto iter = std::find(tasks_.begin(), tasks_.end(), task); + if (iter == tasks_.end()) { - task->retain(); - task->_lastTime = Time::now(); - _tasks.push_back(task); + task->Retain(); + task->last_time_ = Time::Now(); + tasks_.push_back(task); } } } -void e2d::Timer::stopTasks(const String& name) +void e2d::Timer::StopTasks(const String& name) { - for (const auto& task : _tasks) + for (const auto& task : tasks_) { - if (task->getName() == name) + if (task->GetName() == name) { - task->stop(); + task->Stop(); } } } -void e2d::Timer::startTasks(const String& name) +void e2d::Timer::StartTasks(const String& name) { - for (const auto& task : _tasks) + for (const auto& task : tasks_) { - if (task->getName() == name) + if (task->GetName() == name) { - task->start(); + task->Start(); } } } -void e2d::Timer::removeTasks(const String& name) +void e2d::Timer::RemoveTasks(const String& name) { - for (const auto& task : _tasks) + for (const auto& task : tasks_) { - if (task->getName() == name) + if (task->GetName() == name) { - task->_stopped = true; + task->stopped_ = true; } } } -void e2d::Timer::stopAllTasks() +void e2d::Timer::StopAllTasks() { - for (const auto& task : _tasks) + for (const auto& task : tasks_) { - task->stop(); + task->Stop(); } } -void e2d::Timer::startAllTasks() +void e2d::Timer::StartAllTasks() { - for (const auto& task : _tasks) + for (const auto& task : tasks_) { - task->start(); + task->Start(); } } -void e2d::Timer::removeAllTasks() +void e2d::Timer::RemoveAllTasks() { - for (const auto& task : _tasks) + for (const auto& task : tasks_) { - task->_stopped = true; + task->stopped_ = true; } } -void e2d::Timer::clearAllTasks() +void e2d::Timer::ClearAllTasks() { - if (_tasks.empty()) + if (tasks_.empty()) return; - for (const auto& task : _tasks) + for (const auto& task : tasks_) { - task->release(); + task->Release(); } - _tasks.clear(); + tasks_.clear(); } -void e2d::Timer::update() +void e2d::Timer::Update() { - if (_tasks.empty()) + if (tasks_.empty()) return; std::vector currTasks; - currTasks.reserve(_tasks.size()); + currTasks.reserve(tasks_.size()); std::copy_if( - _tasks.begin(), - _tasks.end(), + tasks_.begin(), + tasks_.end(), std::back_inserter(currTasks), - [](Task* task) { return task->_isReady() && !task->_stopped; } + [](Task* task) { return task->IsReady() && !task->stopped_; } ); // 遍历就绪的任务 for (const auto& task : currTasks) - task->_update(); + task->Update(); // 清除结束的任务 - for (auto iter = _tasks.begin(); iter != _tasks.end();) + for (auto iter = tasks_.begin(); iter != tasks_.end();) { - if ((*iter)->_stopped) + if ((*iter)->stopped_) { - (*iter)->release(); - iter = _tasks.erase(iter); + (*iter)->Release(); + iter = tasks_.erase(iter); } else { @@ -132,10 +132,10 @@ void e2d::Timer::update() } } -void e2d::Timer::updateTime() +void e2d::Timer::UpdateTime() { - for (const auto& task : _tasks) + for (const auto& task : tasks_) { - task->_lastTime = Time::now(); + task->last_time_ = Time::Now(); } } diff --git a/core/Transition/BoxTransition.cpp b/core/Transition/BoxTransition.cpp index 2f837db2..20ae8799 100644 --- a/core/Transition/BoxTransition.cpp +++ b/core/Transition/BoxTransition.cpp @@ -6,43 +6,43 @@ e2d::BoxTransition::BoxTransition(Scene* scene, float duration) { } -bool e2d::BoxTransition::_init(Game * game, Scene * prev) +bool e2d::BoxTransition::Init(Game * game, Scene * prev) { - if (Transition::_init(game, prev)) + if (Transition::Init(game, prev)) { - _inLayerParam.opacity = 0; + in_layer_param_.opacity = 0; return true; } return false; } -void e2d::BoxTransition::_update() +void e2d::BoxTransition::Update() { - Transition::_update(); + Transition::Update(); - auto size = Window::getInstance()->getSize(); - if (_delta <= 0.5) + auto size = Window::GetInstance()->GetSize(); + if (delta_ <= 0.5) { - _outLayerParam.contentBounds = D2D1::RectF( - size.width * _delta, - size.height * _delta, - size.width * (1 - _delta), - size.height * (1 - _delta) + out_layer_param_.contentBounds = D2D1::RectF( + size.width * delta_, + size.height * delta_, + size.width * (1 - delta_), + size.height * (1 - delta_) ); } else { - _outLayerParam.opacity = 0; - _inLayerParam.opacity = 1; - _inLayerParam.contentBounds = D2D1::RectF( - size.width * (1 - _delta), - size.height * (1 - _delta), - size.width * _delta, - size.height * _delta + out_layer_param_.opacity = 0; + in_layer_param_.opacity = 1; + in_layer_param_.contentBounds = D2D1::RectF( + size.width * (1 - delta_), + size.height * (1 - delta_), + size.width * delta_, + size.height * delta_ ); - if (_delta >= 1) + if (delta_ >= 1) { - this->_stop(); + this->Stop(); } } } diff --git a/core/Transition/EmergeTransition.cpp b/core/Transition/EmergeTransition.cpp index ff11f1a6..428c03f4 100644 --- a/core/Transition/EmergeTransition.cpp +++ b/core/Transition/EmergeTransition.cpp @@ -6,26 +6,26 @@ e2d::EmergeTransition::EmergeTransition(Scene* scene, float duration) { } -bool e2d::EmergeTransition::_init(Game * game, Scene * prev) +bool e2d::EmergeTransition::Init(Game * game, Scene * prev) { - if (Transition::_init(game, prev)) + if (Transition::Init(game, prev)) { - _outLayerParam.opacity = 1; - _inLayerParam.opacity = 0; + out_layer_param_.opacity = 1; + in_layer_param_.opacity = 0; return true; } return false; } -void e2d::EmergeTransition::_update() +void e2d::EmergeTransition::Update() { - Transition::_update(); + Transition::Update(); - _outLayerParam.opacity = 1 - _delta; - _inLayerParam.opacity = _delta; + out_layer_param_.opacity = 1 - delta_; + in_layer_param_.opacity = delta_; - if (_delta >= 1) + if (delta_ >= 1) { - this->_stop(); + this->Stop(); } } diff --git a/core/Transition/FadeTransition.cpp b/core/Transition/FadeTransition.cpp index be5b3a00..50b7d0ff 100644 --- a/core/Transition/FadeTransition.cpp +++ b/core/Transition/FadeTransition.cpp @@ -6,33 +6,33 @@ e2d::FadeTransition::FadeTransition(Scene* scene, float duration) { } -bool e2d::FadeTransition::_init(Game * game, Scene * prev) +bool e2d::FadeTransition::Init(Game * game, Scene * prev) { - if (Transition::_init(game, prev)) + if (Transition::Init(game, prev)) { - _outLayerParam.opacity = 1; - _inLayerParam.opacity = 0; + out_layer_param_.opacity = 1; + in_layer_param_.opacity = 0; return true; } return false; } -void e2d::FadeTransition::_update() +void e2d::FadeTransition::Update() { - Transition::_update(); + Transition::Update(); - if (_delta < 0.5) + if (delta_ < 0.5) { - _outLayerParam.opacity = 1 - _delta * 2; - _inLayerParam.opacity = 0; + out_layer_param_.opacity = 1 - delta_ * 2; + in_layer_param_.opacity = 0; } else { - _outLayerParam.opacity = 0; - _inLayerParam.opacity = (_delta - 0.5f) * 2; - if (_delta >= 1) + out_layer_param_.opacity = 0; + in_layer_param_.opacity = (delta_ - 0.5f) * 2; + if (delta_ >= 1) { - this->_stop(); + this->Stop(); } } } diff --git a/core/Transition/MoveTransition.cpp b/core/Transition/MoveTransition.cpp index e7bc7efd..8fd755d3 100644 --- a/core/Transition/MoveTransition.cpp +++ b/core/Transition/MoveTransition.cpp @@ -3,64 +3,64 @@ e2d::MoveTransition::MoveTransition(Scene* scene, float duration, Direction direction) : Transition(scene, duration) - , _direction(direction) + , direction_(direction) { } -bool e2d::MoveTransition::_init(Game * game, Scene * prev) +bool e2d::MoveTransition::Init(Game * game, Scene * prev) { - if (Transition::_init(game, prev)) + if (Transition::Init(game, prev)) { - auto size = Window::getInstance()->getSize(); - if (_direction == Direction::Up) + auto size = Window::GetInstance()->GetSize(); + if (direction_ == Direction::Up) { - _posDelta = Vector2(0, -size.height); - _startPos = Point(0, size.height); + pos_delta_ = Point(0, -size.height); + start_pos_ = Point(0, size.height); } - else if (_direction == Direction::Down) + else if (direction_ == Direction::Down) { - _posDelta = Vector2(0, size.height); - _startPos = Point(0, -size.height); + pos_delta_ = Point(0, size.height); + start_pos_ = Point(0, -size.height); } - else if (_direction == Direction::Left) + else if (direction_ == Direction::Left) { - _posDelta = Vector2(-size.width, 0); - _startPos = Point(size.width, 0); + pos_delta_ = Point(-size.width, 0); + start_pos_ = Point(size.width, 0); } - else if (_direction == Direction::Right) + else if (direction_ == Direction::Right) { - _posDelta = Vector2(size.width, 0); - _startPos = Point(-size.width, 0); + pos_delta_ = Point(size.width, 0); + start_pos_ = Point(-size.width, 0); } - if (_outScene) _outScene->setPos(0, 0); - _inScene->setPos(_startPos); + if (out_scene_) out_scene_->SetPos(0, 0); + in_scene_->SetPos(start_pos_); return true; } return false; } -void e2d::MoveTransition::_update() +void e2d::MoveTransition::Update() { - Transition::_update(); + Transition::Update(); - if (_outScene) + if (out_scene_) { - _outScene->setPos(_posDelta * _delta); + out_scene_->SetPos(pos_delta_ * delta_); } - if (_inScene) + if (in_scene_) { - _inScene->setPos(_startPos + _posDelta * _delta); + in_scene_->SetPos(start_pos_ + pos_delta_ * delta_); } - if (_delta >= 1) + if (delta_ >= 1) { - this->_stop(); + this->Stop(); } } -void e2d::MoveTransition::_reset() +void e2d::MoveTransition::Reset() { - if (_outScene) _outScene->setPos(0, 0); - _inScene->setPos(0, 0); + if (out_scene_) out_scene_->SetPos(0, 0); + in_scene_->SetPos(0, 0); } diff --git a/core/Transition/Transition.cpp b/core/Transition/Transition.cpp index c9678d6b..625ba7c6 100644 --- a/core/Transition/Transition.cpp +++ b/core/Transition/Transition.cpp @@ -3,52 +3,52 @@ #include "..\e2dnode.h" e2d::Transition::Transition(Scene* scene, float duration) - : _end(false) - , _started() - , _delta(0) - , _outScene(nullptr) - , _inScene(scene) - , _outLayer(nullptr) - , _inLayer(nullptr) - , _outLayerParam() - , _inLayerParam() + : done_(false) + , started_() + , delta_(0) + , out_scene_(nullptr) + , in_scene_(scene) + , out_layer_(nullptr) + , in_layer_(nullptr) + , out_layer_param_() + , in_layer_param_() { - _duration = std::max(duration, 0.f); - if (_inScene) - _inScene->retain(); + duration_ = std::max(duration, 0.f); + if (in_scene_) + in_scene_->Retain(); } e2d::Transition::~Transition() { - SafeRelease(_outLayer); - SafeRelease(_inLayer); - GC::getInstance()->safeRelease(_outScene); - GC::getInstance()->safeRelease(_inScene); + SafeRelease(out_layer_); + SafeRelease(in_layer_); + GC::GetInstance()->SafeRelease(out_scene_); + GC::GetInstance()->SafeRelease(in_scene_); } -bool e2d::Transition::isDone() +bool e2d::Transition::IsDone() { - return _end; + return done_; } -bool e2d::Transition::_init(Game * game, Scene * prev) +bool e2d::Transition::Init(Game * game, Scene * prev) { - _started = Time::now(); - _outScene = prev; + started_ = Time::Now(); + out_scene_ = prev; - if (_outScene) - _outScene->retain(); + if (out_scene_) + out_scene_->Retain(); HRESULT hr = S_OK; - auto renderer = Renderer::getInstance(); - if (_inScene) + auto renderer = Renderer::GetInstance(); + if (in_scene_) { - hr = renderer->getRenderTarget()->CreateLayer(&_inLayer); + hr = renderer->GetRenderTarget()->CreateLayer(&in_layer_); } - if (SUCCEEDED(hr) && _outScene) + if (SUCCEEDED(hr) && out_scene_) { - hr = renderer->getRenderTarget()->CreateLayer(&_outLayer); + hr = renderer->GetRenderTarget()->CreateLayer(&out_layer_); } if (FAILED(hr)) @@ -56,40 +56,40 @@ bool e2d::Transition::_init(Game * game, Scene * prev) return false; } - _outLayerParam = _inLayerParam = D2D1::LayerParameters( + out_layer_param_ = in_layer_param_ = D2D1::LayerParameters( D2D1::InfiniteRect(), nullptr, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, D2D1::Matrix3x2F::Identity(), 1.f, - renderer->getSolidColorBrush(), + renderer->GetSolidBrush(), D2D1_LAYER_OPTIONS_NONE ); return true; } -void e2d::Transition::_update() +void e2d::Transition::Update() { - if (_duration == 0) + if (duration_ == 0) { - _delta = 1; + delta_ = 1; } else { - _delta = (Time::now() - _started).seconds() / _duration; - _delta = std::min(_delta, 1.f); + delta_ = (Time::Now() - started_).Seconds() / duration_; + delta_ = std::min(delta_, 1.f); } } -void e2d::Transition::_render() +void e2d::Transition::Draw() { - auto renderTarget = Renderer::getInstance()->getRenderTarget(); - auto size = Window::getInstance()->getSize(); + auto renderTarget = Renderer::GetInstance()->GetRenderTarget(); + auto size = Window::GetInstance()->GetSize(); - if (_outScene) + if (out_scene_) { - auto rootPos = _outScene->getPos(); + auto rootPos = out_scene_->GetPos(); auto clipRect = D2D1::RectF( std::max(rootPos.x, 0.f), std::max(rootPos.y, 0.f), @@ -98,17 +98,17 @@ void e2d::Transition::_render() ); renderTarget->SetTransform(D2D1::Matrix3x2F::Identity()); renderTarget->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); - renderTarget->PushLayer(_outLayerParam, _outLayer); + renderTarget->PushLayer(out_layer_param_, out_layer_); - _outScene->visit(); + out_scene_->Visit(); renderTarget->PopLayer(); renderTarget->PopAxisAlignedClip(); } - if (_inScene) + if (in_scene_) { - Point rootPos = _inScene->getPos(); + Point rootPos = in_scene_->GetPos(); auto clipRect = D2D1::RectF( std::max(rootPos.x, 0.f), std::max(rootPos.y, 0.f), @@ -117,17 +117,17 @@ void e2d::Transition::_render() ); renderTarget->SetTransform(D2D1::Matrix3x2F::Identity()); renderTarget->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); - renderTarget->PushLayer(_inLayerParam, _inLayer); + renderTarget->PushLayer(in_layer_param_, in_layer_); - _inScene->visit(); + in_scene_->Visit(); renderTarget->PopLayer(); renderTarget->PopAxisAlignedClip(); } } -void e2d::Transition::_stop() +void e2d::Transition::Stop() { - _end = true; - _reset(); + done_ = true; + Reset(); } diff --git a/core/e2daction.h b/core/e2daction.h index fa6352db..186537cc 100644 --- a/core/e2daction.h +++ b/core/e2daction.h @@ -28,64 +28,64 @@ public: virtual ~Action(); // 获取动作运行状态 - virtual bool isRunning(); + virtual bool IsRunning(); // 继续动作 - virtual void resume(); + virtual void Resume(); // 暂停动作 - virtual void pause(); + virtual void Pause(); // 停止动作 - virtual void stop(); + virtual void Stop(); // 获取动作名称 - virtual String getName() const; + virtual const String& GetName() const; // 设置动作名称 - virtual void setName( + virtual void SetName( const String& name ); // 获取动作的拷贝 - virtual Action * clone() const = 0; + virtual Action * Clone() const = 0; // 获取动作的倒转 - virtual Action * reverse() const = 0; + virtual Action * Reverse() const = 0; // 重置动作 - virtual void reset(); + virtual void Reset(); // 获取该动作的执行目标 - virtual Node * getTarget(); + virtual Node * GetTarget(); protected: E2D_DISABLE_COPY(Action); // 初始化动作 - virtual void _init(); + virtual void Init(); // 更新动作 - virtual void _update(); + virtual void Update(); // 获取动作结束状态 - virtual bool _isDone(); + virtual bool IsDone(); // 重置动作时间 - virtual void _resetTime(); + virtual void ResetTime(); // 开始动作 - virtual void _startWithTarget( + virtual void StartWithTarget( Node* target ); protected: - String _name; - bool _running; - bool _done; - bool _initialized; - Node * _target; - Time _started; + String name_; + bool running_; + bool done_; + bool initialized_; + Node * target_; + Time started_; }; @@ -100,23 +100,23 @@ public: ); // 重置动作 - virtual void reset() override; + virtual void Reset() override; protected: E2D_DISABLE_COPY(FiniteTimeAction); // 初始化动作 - virtual void _init() override; + virtual void Init() override; // 更新动作 - virtual void _update() override; + virtual void Update() override; // 重置动作时间 - virtual void _resetTime() override; + virtual void ResetTime() override; protected: - float _duration; - float _delta; + float duration_; + float delta_; }; @@ -127,28 +127,28 @@ class MoveBy : public: explicit MoveBy( float duration, /* 持续时长 */ - Vector2 vector /* 移动距离 */ + Point vector /* 移动距离 */ ); // 获取该动作的拷贝对象 - virtual MoveBy * clone() const override; + virtual MoveBy * Clone() const override; // 获取该动作的倒转 - virtual MoveBy * reverse() const override; + virtual MoveBy * Reverse() const override; protected: E2D_DISABLE_COPY(MoveBy); // 初始化动作 - virtual void _init() override; + virtual void Init() override; // 更新动作 - virtual void _update() override; + virtual void Update() override; protected: - Point _startPos; - Point _prevPos; - Vector2 _deltaPos; + Point start_pos_; + Point prev_pos_; + Point delta_pos_; }; @@ -163,12 +163,12 @@ public: ); // 获取该动作的拷贝对象 - virtual MoveTo * clone() const override; + virtual MoveTo * Clone() const override; // 获取该动作的倒转 - virtual MoveTo * reverse() const override + virtual MoveTo * Reverse() const override { - WARN("reverse() not supported in MoveTo"); + WARN("Reverse() not supported in MoveTo"); return nullptr; } @@ -176,10 +176,10 @@ protected: E2D_DISABLE_COPY(MoveTo); // 初始化动作 - virtual void _init() override; + virtual void Init() override; protected: - Point _endPos; + Point end_pos_; }; @@ -189,33 +189,33 @@ class JumpBy : { public: explicit JumpBy( - float duration, /* 持续时长 */ - const Vector2& vec, /* 跳跃距离 */ + float duration, /* 持续时长 */ + const Point& vec, /* 跳跃距离 */ float height, /* 跳跃高度 */ int jumps = 1 /* 跳跃次数 */ ); // 获取该动作的拷贝对象 - virtual JumpBy * clone() const override; + virtual JumpBy * Clone() const override; // 获取该动作的倒转 - virtual JumpBy * reverse() const override; + virtual JumpBy * Reverse() const override; protected: E2D_DISABLE_COPY(JumpBy); // 初始化动作 - virtual void _init() override; + virtual void Init() override; // 更新动作 - virtual void _update() override; + virtual void Update() override; protected: - Point _startPos; - Vector2 _deltaPos; - float _height; - int _jumps; - Point _prevPos; + Point start_pos_; + Point delta_pos_; + float height_; + int jumps_; + Point prev_pos_; }; @@ -225,19 +225,19 @@ class JumpTo : { public: explicit JumpTo( - float duration, /* 持续时长 */ + float duration, /* 持续时长 */ const Point& pos, /* 目的坐标 */ float height, /* 跳跃高度 */ int jumps = 1 /* 跳跃次数 */ ); // 获取该动作的拷贝对象 - virtual JumpTo * clone() const override; + virtual JumpTo * Clone() const override; // 获取该动作的倒转 - virtual JumpTo * reverse() const override + virtual JumpTo * Reverse() const override { - WARN("reverse() not supported in JumpTo"); + WARN("Reverse() not supported in JumpTo"); return nullptr; } @@ -245,10 +245,10 @@ protected: E2D_DISABLE_COPY(JumpTo); // 初始化动作 - virtual void _init() override; + virtual void Init() override; protected: - Point _endPos; + Point end_pos_; }; @@ -264,30 +264,30 @@ public: explicit ScaleBy( float duration, /* 持续时长 */ - float scaleX, /* 横向缩放相对变化值 */ - float scaleY /* 纵向缩放相对变化值 */ + float scale_x, /* 横向缩放相对变化值 */ + float scale_y /* 纵向缩放相对变化值 */ ); // 获取该动作的拷贝对象 - virtual ScaleBy * clone() const override; + virtual ScaleBy * Clone() const override; // 获取该动作的倒转 - virtual ScaleBy * reverse() const override; + virtual ScaleBy * Reverse() const override; protected: E2D_DISABLE_COPY(ScaleBy); // 初始化动作 - virtual void _init() override; + virtual void Init() override; // 更新动作 - virtual void _update() override; + virtual void Update() override; protected: - float _startScaleX; - float _startScaleY; - float _deltaX; - float _deltaY; + float start_scale_x_; + float start_scale_y_; + float delta_x_; + float delta_y_; }; @@ -303,17 +303,17 @@ public: explicit ScaleTo( float duration, /* 持续时长 */ - float scaleX, /* 横向缩放目标值 */ - float scaleY /* 纵向缩放目标值 */ + float scale_x, /* 横向缩放目标值 */ + float scale_y /* 纵向缩放目标值 */ ); // 获取该动作的拷贝对象 - virtual ScaleTo * clone() const override; + virtual ScaleTo * Clone() const override; // 获取该动作的倒转 - virtual ScaleTo * reverse() const override + virtual ScaleTo * Reverse() const override { - WARN("reverse() not supported in ScaleTo"); + WARN("Reverse() not supported in ScaleTo"); return nullptr; } @@ -321,11 +321,11 @@ protected: E2D_DISABLE_COPY(ScaleTo); // 初始化动作 - virtual void _init() override; + virtual void Init() override; protected: - float _endScaleX; - float _endScaleY; + float end_scale_x_; + float end_scale_y_; }; @@ -340,23 +340,23 @@ public: ); // 获取该动作的拷贝对象 - virtual OpacityBy * clone() const override; + virtual OpacityBy * Clone() const override; // 获取该动作的倒转 - virtual OpacityBy * reverse() const override; + virtual OpacityBy * Reverse() const override; protected: E2D_DISABLE_COPY(OpacityBy); // 初始化动作 - virtual void _init() override; + virtual void Init() override; // 更新动作 - virtual void _update() override; + virtual void Update() override; protected: - float _startVal; - float _deltaVal; + float start_val_; + float delta_val_; }; @@ -371,12 +371,12 @@ public: ); // 获取该动作的拷贝对象 - virtual OpacityTo * clone() const override; + virtual OpacityTo * Clone() const override; // 获取该动作的倒转 - virtual OpacityTo * reverse() const override + virtual OpacityTo * Reverse() const override { - WARN("reverse() not supported in OpacityTo"); + WARN("Reverse() not supported in OpacityTo"); return nullptr; } @@ -384,10 +384,10 @@ protected: E2D_DISABLE_COPY(OpacityTo); // 初始化动作 - virtual void _init() override; + virtual void Init() override; protected: - float _endVal; + float end_val_; }; @@ -399,10 +399,7 @@ public: // 创建淡入动作 explicit FadeIn( float duration /* 持续时长 */ - ) - : OpacityTo(duration, 1) - { - } + ); protected: E2D_DISABLE_COPY(FadeIn); @@ -417,10 +414,7 @@ public: // 创建淡出动作 explicit FadeOut( float duration /* 持续时长 */ - ) - : OpacityTo(duration, 0) - { - } + ); protected: E2D_DISABLE_COPY(FadeOut); @@ -438,23 +432,23 @@ public: ); // 获取该动作的拷贝对象 - virtual RotateBy * clone() const override; + virtual RotateBy * Clone() const override; // 获取该动作的倒转 - virtual RotateBy * reverse() const override; + virtual RotateBy * Reverse() const override; protected: E2D_DISABLE_COPY(RotateBy); // 初始化动作 - virtual void _init() override; + virtual void Init() override; // 更新动作 - virtual void _update() override; + virtual void Update() override; protected: - float _startVal; - float _deltaVal; + float start_val_; + float delta_val_; }; @@ -469,12 +463,12 @@ public: ); // 获取该动作的拷贝对象 - virtual RotateTo * clone() const override; + virtual RotateTo * Clone() const override; // 获取该动作的倒转 - virtual RotateTo * reverse() const override + virtual RotateTo * Reverse() const override { - WARN("reverse() not supported in RotateTo"); + WARN("Reverse() not supported in RotateTo"); return nullptr; } @@ -482,10 +476,10 @@ protected: E2D_DISABLE_COPY(RotateTo); // 初始化动作 - virtual void _init() override; + virtual void Init() override; protected: - float _endVal; + float end_val_; }; @@ -499,29 +493,29 @@ public: ); // 获取该动作的拷贝对象 - virtual Delay * clone() const override; + virtual Delay * Clone() const override; // 获取该动作的倒转 - virtual Delay * reverse() const override; + virtual Delay * Reverse() const override; // 重置动作 - virtual void reset() override; + virtual void Reset() override; protected: E2D_DISABLE_COPY(Delay); // 初始化动作 - virtual void _init() override; + virtual void Init() override; // 更新动作 - virtual void _update() override; + virtual void Update() override; // 重置动作时间 - virtual void _resetTime() override; + virtual void ResetTime() override; protected: - float _delay; - float _delta; + float delay_; + float delta_; }; @@ -538,59 +532,59 @@ public: virtual ~Loop(); // 获取该动作的拷贝对象 - virtual Loop * clone() const override; + virtual Loop * Clone() const override; // 获取该动作的倒转 - virtual Loop * reverse() const override; + virtual Loop * Reverse() const override; // 重置动作 - virtual void reset() override; + virtual void Reset() override; protected: E2D_DISABLE_COPY(Loop); // 初始化动作 - virtual void _init() override; + virtual void Init() override; // 更新动作 - virtual void _update() override; + virtual void Update() override; // 重置动作时间 - virtual void _resetTime() override; + virtual void ResetTime() override; protected: - Action * _action; - int _times; - int _totalTimes; + Action * action_; + int times_; + int total_times_; }; // 回调动作 -class CallFunc : +class Callback : public Action { public: - explicit CallFunc( + explicit Callback( const Function& func /* 函数对象 */ ); // 获取该动作的拷贝对象 - virtual CallFunc * clone() const override; + virtual Callback * Clone() const override; // 获取该动作的倒转 - virtual CallFunc * reverse() const override; + virtual Callback * Reverse() const override; protected: - E2D_DISABLE_COPY(CallFunc); + E2D_DISABLE_COPY(Callback); // 初始化动作 - virtual void _init() override; + virtual void Init() override; // 更新动作 - virtual void _update() override; + virtual void Update() override; protected: - Function _func; + Function callback_; }; @@ -599,48 +593,50 @@ class Sequence : public Action { public: + typedef std::vector Actions; + Sequence(); explicit Sequence( - const std::vector& actions /* 动作列表 */ + const Actions& actions /* 动作列表 */ ); virtual ~Sequence(); // 在结尾添加动作 - void add( + void Add( Action * action ); // 在结尾添加多个动作 - void add( - const std::vector& actions /* 动作列表 */ + void Add( + const Actions& actions /* 动作列表 */ ); // 获取该动作的拷贝对象 - virtual Sequence * clone() const override; + virtual Sequence * Clone() const override; // 获取该动作的倒转 - virtual Sequence * reverse() const; + virtual Sequence * Reverse() const; // 重置动作 - virtual void reset() override; + virtual void Reset() override; protected: E2D_DISABLE_COPY(Sequence); // 初始化动作 - virtual void _init() override; + virtual void Init() override; // 更新动作 - virtual void _update() override; + virtual void Update() override; // 重置动作时间 - virtual void _resetTime() override; + virtual void ResetTime() override; protected: - UINT _currIndex; - std::vector _actions; + UINT action_index_; + Actions actions_; }; @@ -649,47 +645,49 @@ class Spawn : public Action { public: + typedef std::vector Actions; + Spawn(); explicit Spawn( - const std::vector& actions /* 动作列表 */ + const Actions& actions /* 动作列表 */ ); virtual ~Spawn(); // 在结尾添加动作 - void add( + void Add( Action * action ); // 在结尾添加多个动作 - void add( - const std::vector& actions /* 动作列表 */ + void Add( + const Actions& actions /* 动作列表 */ ); // 获取该动作的拷贝对象 - virtual Spawn * clone() const override; + virtual Spawn * Clone() const override; // 获取该动作的倒转 - virtual Spawn * reverse() const; + virtual Spawn * Reverse() const; // 重置动作 - virtual void reset() override; + virtual void Reset() override; protected: E2D_DISABLE_COPY(Spawn); // 初始化动作 - virtual void _init() override; + virtual void Init() override; // 更新动作 - virtual void _update() override; + virtual void Update() override; // 重置动作时间 - virtual void _resetTime() override; + virtual void ResetTime() override; protected: - std::vector _actions; + Actions actions_; }; @@ -698,56 +696,58 @@ class Animation : public Ref { public: + typedef std::vector Images; + Animation(); explicit Animation( - const std::vector& frames /* 关键帧数组 */ + const Images& frames /* 关键帧数组 */ ); explicit Animation( - float interval /* 帧间隔(秒) */ + float interval /* 帧间隔(秒) */ ); explicit Animation( - float interval, /* 帧间隔(秒) */ - const std::vector& frames /* 关键帧数组 */ + float interval, /* 帧间隔(秒) */ + const Images& frames /* 关键帧数组 */ ); virtual ~Animation(); // 添加关键帧 - void add( - Image * frame /* 关键帧 */ + void Add( + Image * frame /* 关键帧 */ ); // 添加多个关键帧 - void add( - const std::vector& frames /* 关键帧列表 */ + void Add( + const Images& frames /* 关键帧数组 */ ); // 获取帧间隔 - float getInterval() const; + float GetInterval() const; // 获取关键帧 - const std::vector& getFrames() const; + const Images& GetFrames() const; // 设置每一帧的时间间隔 - void setInterval( + void SetInterval( float interval /* 帧间隔(秒) */ ); // 获取帧动画的拷贝对象 - Animation * clone() const; + Animation * Clone() const; // 获取帧动画的倒转 - Animation * reverse() const; + Animation * Reverse() const; protected: E2D_DISABLE_COPY(Animation); protected: - float _interval; - std::vector _frames; + float interval_; + Images frames_; }; @@ -765,37 +765,37 @@ public: virtual ~Animate(); // 获取动画 - virtual Animation * getAnimation() const; + virtual Animation * GetAnimation() const; // 设置动画 - virtual void setAnimation( + virtual void SetAnimation( Animation * animation ); // 获取该动作的拷贝对象 - virtual Animate * clone() const override; + virtual Animate * Clone() const override; // 获取该动作的倒转 - virtual Animate * reverse() const override; + virtual Animate * Reverse() const override; // 重置动作 - virtual void reset() override; + virtual void Reset() override; protected: E2D_DISABLE_COPY(Animate); // 初始化动作 - virtual void _init() override; + virtual void Init() override; // 更新动作 - virtual void _update() override; + virtual void Update() override; // 重置动作时间 - virtual void _resetTime() override; + virtual void ResetTime() override; protected: - UINT _frameIndex; - Animation * _animation; + UINT frame_index_; + Animation * animation_; }; diff --git a/core/e2dbase.h b/core/e2dbase.h index d713f4bc..00232b1e 100644 --- a/core/e2dbase.h +++ b/core/e2dbase.h @@ -25,85 +25,85 @@ public: }; // 弹窗样式 - enum class Popup : int + enum class PopupStyle : int { - Information, /* 信息 */ - Warning, /* 警告 */ - Error /* 错误 */ + Info, /* 提示 */ + Warning, /* 警告 */ + Error /* 错误 */ }; public: // 获取窗体实例 - static Window * getInstance(); + static Window * GetInstance(); // 销毁窗体实例 - static void destroyInstance(); + static void DestroyInstance(); // 创建窗体互斥体 - bool createMutex( + bool CheckMutex( const String& mutex = L"" /* 进程互斥体名称 */ ); + // 获取窗体标题 + const String& GetTitle() const; + + // 获取窗体宽度 + int GetWidth() const; + + // 获取窗体高度 + int GetHeight() const; + + // 获取窗体大小 + Size GetSize() const; + + // 获取窗口 DPI + float GetDpi() const; + + // 获取窗口句柄 + HWND GetHWnd(); + // 修改窗体大小 - void setSize( + void SetSize( int width, /* 窗体宽度 */ int height /* 窗体高度 */ ); // 设置窗体标题 - void setTitle( + void SetTitle( const String& title /* 窗体标题 */ ); // 设置窗体图标 - void setIcon( - int iconID + void SetIcon( + int icon_id ); // 设置鼠标指针样式 - void setCursor( + void SetCursor( Cursor cursor ); - // 获取窗体标题 - String getTitle() const; - - // 获取窗体宽度 - int getWidth() const; - - // 获取窗体高度 - int getHeight() const; - - // 获取窗体大小 - Size getSize() const; - - // 获取窗口 DPI - float getDpi() const; - - // 获取窗口句柄 - HWND getHWnd(); - // 打开或隐藏控制台 - void setConsoleEnabled( + void SetConsoleEnabled( bool enabled ); // 是否允许响应输入法 - void setTypewritingEnabled( + void SetTypewritingEnabled( bool enabled ); // 弹出窗口 // 返回值:当窗口包含取消按钮时,返回值表示用户是否点击确认按钮 - bool popup( + bool Popup( const String& text, /* 窗口内容 */ const String& title, /* 窗口标题 */ - Popup style = Popup::Information, /* 弹窗样式 */ - bool hasCancel = false /* 包含取消按钮 */ + PopupStyle style = PopupStyle::Info,/* 弹窗样式 */ + bool has_cancel = false /* 包含取消按钮 */ ); // 处理窗体消息 - void poll(); + void Poll(); private: Window(); @@ -113,7 +113,7 @@ private: E2D_DISABLE_COPY(Window); // 根据客户区大小定位窗口 - Rect _locate( + Rect Locate( int width, int height ); @@ -121,21 +121,21 @@ private: // Win32 窗口消息回调程序 static LRESULT CALLBACK WndProc( HWND hWnd, - UINT uMsg, - WPARAM wParam, - LPARAM lParam + UINT msg, + WPARAM w_param, + LPARAM l_param ); private: - HWND _hWnd; - MSG _msg; - int _width; - int _height; - String _title; - int _iconID; - float _dpi; + HWND hWnd_; + MSG msg_; + int width_; + int height_; + String title_; + int icon_id_; + float dpi_; - static Window * _instance; + static Window * instance_; }; @@ -144,57 +144,57 @@ class Renderer { public: // 获取渲染器实例 - static Renderer * getInstance(); + static Renderer * GetInstance(); // 销毁实例 - static void destroyInstance(); + static void DestroyInstance(); // 获取背景色 - Color getBackgroundColor(); + Color GetBackgroundColor(); // 修改背景色 - void setBackgroundColor( - Color color + void SetBackgroundColor( + const Color& color ); // 显示或隐藏 FPS // 默认:隐藏 - void showFps( + void ShowFps( bool show ); // 开始渲染 - void beginDraw(); + void BeginDraw(); // 结束渲染 - void endDraw(); + void EndDraw(); // 获取文字渲染器 - TextRenderer * getTextRenderer() const { return _textRenderer; } + E2DTextRenderer * GetTextRenderer(); // 获取 ID2D1HwndRenderTarget 对象 - ID2D1HwndRenderTarget * getRenderTarget() const { return _renderTarget; } + ID2D1HwndRenderTarget * GetRenderTarget(); // 获取 ID2D1SolidColorBrush 对象 - ID2D1SolidColorBrush * getSolidColorBrush() const { return _solidBrush; } + ID2D1SolidColorBrush * GetSolidBrush(); // 获取 ID2D1Factory 对象 - static ID2D1Factory * getFactory(); + static ID2D1Factory * GetFactory(); // 获取 IWICImagingFactory 对象 - static IWICImagingFactory * getImagingFactory(); + static IWICImagingFactory * GetImagingFactory(); // 获取 IDWriteFactory 对象 - static IDWriteFactory * getWriteFactory(); + static IDWriteFactory * GetWriteFactory(); // 获取 Miter 样式的 ID2D1StrokeStyle - static ID2D1StrokeStyle * getMiterStrokeStyle(); + static ID2D1StrokeStyle * GetMiterStrokeStyle(); // 获取 Bevel 样式的 ID2D1StrokeStyle - static ID2D1StrokeStyle * getBevelStrokeStyle(); + static ID2D1StrokeStyle * GetBevelStrokeStyle(); // 获取 Round 样式的 ID2D1StrokeStyle - static ID2D1StrokeStyle * getRoundStrokeStyle(); + static ID2D1StrokeStyle * GetRoundStrokeStyle(); protected: Renderer(); @@ -204,23 +204,23 @@ protected: E2D_DISABLE_COPY(Renderer); protected: - bool _showFps; - int _renderTimes; - Time _lastRenderTime; - D2D1_COLOR_F _clearColor; - TextRenderer* _textRenderer; - IDWriteTextFormat* _fpsFormat; - IDWriteTextLayout* _fpsLayout; - ID2D1SolidColorBrush* _solidBrush; - ID2D1HwndRenderTarget* _renderTarget; + bool show_fps_; + int render_times_; + Time last_render_time_; + D2D1_COLOR_F clear_color_; + E2DTextRenderer* text_renderer_; + IDWriteTextFormat* fps_text_format_; + IDWriteTextLayout* fps_text_layout_; + ID2D1SolidColorBrush* solid_brush_; + ID2D1HwndRenderTarget* render_target_; - static ID2D1Factory* _factory; - static IWICImagingFactory* _imagingFactory; - static IDWriteFactory* _writeFactory; - static ID2D1StrokeStyle* _miterStrokeStyle; - static ID2D1StrokeStyle* _bevelStrokeStyle; - static ID2D1StrokeStyle* _roundStrokeStyle; - static Renderer * _instance; + static ID2D1Factory* factory_; + static IWICImagingFactory* imaging_factory_; + static IDWriteFactory* write_factory_; + static ID2D1StrokeStyle* miter_stroke_style_; + static ID2D1StrokeStyle* bevel_stroke_style_; + static ID2D1StrokeStyle* round_stroke_style_; + static Renderer * instance_; }; @@ -229,41 +229,41 @@ class Input { public: // 获取输入设备实例 - static Input * getInstance(); + static Input * GetInstance(); // 销毁输入设备实例 - static void destroyInstance(); + static void DestroyInstance(); // 检测键盘某按键是否正被按下 - bool isDown( + bool IsDown( KeyCode key ); // 检测鼠标按键是否正被按下 - bool isDown( + bool IsDown( MouseCode code ); // 获得鼠标X轴坐标值 - float getMouseX(); + float GetMouseX(); // 获得鼠标Y轴坐标值 - float getMouseY(); + float GetMouseY(); // 获得鼠标坐标值 - Point getMousePos(); + Point GetMousePos(); // 获得鼠标X轴坐标增量 - float getMouseDeltaX(); + float GetMouseDeltaX(); // 获得鼠标Y轴坐标增量 - float getMouseDeltaY(); + float GetMouseDeltaY(); // 获得鼠标Z轴(鼠标滚轮)坐标增量 - float getMouseDeltaZ(); + float GetMouseDeltaZ(); // 刷新输入设备状态 - void update(); + void Update(); protected: Input(); @@ -273,13 +273,13 @@ protected: E2D_DISABLE_COPY(Input); protected: - IDirectInput8W * _directInput; - IDirectInputDevice8W* _keyboardDevice; - IDirectInputDevice8W* _mouseDevice; - DIMOUSESTATE _mouseState; - char _keyBuffer[256]; + IDirectInput8W * direct_input_; + IDirectInputDevice8W* keyboard_device_; + IDirectInputDevice8W* mouse_device_; + DIMOUSESTATE mouse_state_; + char key_buffer_[256]; - static Input * _instance; + static Input * instance_; }; @@ -288,16 +288,16 @@ class Audio { public: // 获取音频设备实例 - static Audio * getInstance(); + static Audio * GetInstance(); // 销毁实例 - static void destroyInstance(); + static void DestroyInstance(); // 获取 XAudio2 实例对象 - IXAudio2 * getXAudio2(); + IXAudio2 * GetXAudio2(); // 获取 MasteringVoice 实例对象 - IXAudio2MasteringVoice* getMasteringVoice(); + IXAudio2MasteringVoice* GetMasteringVoice(); protected: Audio(); @@ -307,10 +307,10 @@ protected: E2D_DISABLE_COPY(Audio); protected: - IXAudio2 * _xAudio2; - IXAudio2MasteringVoice* _masteringVoice; + IXAudio2 * x_audio2_; + IXAudio2MasteringVoice* mastering_voice_; - static Audio * _instance; + static Audio * instance_; }; @@ -324,63 +324,63 @@ class Game { public: // 获取 Game 实例 - static Game * getInstance(); + static Game * GetInstance(); // 销毁实例 - static void destroyInstance(); + static void DestroyInstance(); // 启动游戏 - void start(); + void Start(); // 暂停游戏 - void pause(); + void Pause(); // 继续游戏 - void resume(); + void Resume(); // 结束游戏 - void quit(); + void Quit(); // 游戏是否暂停 - bool isPaused(); + bool IsPaused(); // 场景入栈 - void pushScene( + void PushScene( Scene * scene, /* 下一个场景的指针 */ - bool saveCurrentScene = true /* 是否保存当前场景 */ + bool save_current_scene = true /* 是否保存当前场景 */ ); // 场景入栈 - void pushScene( + void PushScene( Transition * transition, /* 场景动画 */ - bool saveCurrentScene = true /* 是否保存当前场景 */ + bool save_current_scene = true /* 是否保存当前场景 */ ); // 场景出栈 - Scene* popScene(); + Scene* PopScene(); // 场景出栈 - Scene* popScene( + Scene* PopScene( Transition * transition /* 场景动画 */ ); // 清空保存的所有场景 - void clearAllScenes(); + void ClearAllScenes(); // 获取当前场景 - Scene * getCurrentScene(); + Scene * GetCurrentScene(); // 获取场景栈 - const std::stack& getSceneStack(); + const std::stack& GetSceneStack(); // 是否正在进行场景动画 - bool isTransitioning() const; + bool IsTransitioning() const; // 更新场景内容 - void updateScene(); + void UpdateScene(); // 渲染场景画面 - void drawScene(); + void DrawScene(); protected: Game(); @@ -390,19 +390,14 @@ protected: E2D_DISABLE_COPY(Game); private: - bool _quit; - bool _paused; - Timer* _timer; - Scene* _currScene; - Scene* _nextScene; - Transition* _transition; - Window* _window; - Input* _input; - Renderer* _renderer; - ActionManager* _actionManager; - std::stack _scenes; + bool quit_; + bool paused_; + Scene* curr_scene_; + Scene* next_scene_; + Transition* transition_; + std::stack scenes_; - static Game * _instance; + static Game * instance_; }; @@ -411,20 +406,20 @@ class GC { public: // 获取 GC 实例 - static GC * getInstance(); + static GC * GetInstance(); // 自动释放 - void autorelease( + void AutoRelease( Ref* ref ); // 安全地释放对象 - void safeRelease( + void SafeRelease( Ref* ref ); // 刷新内存池 - void flush(); + void Flush(); private: GC(); @@ -434,9 +429,9 @@ private: E2D_DISABLE_COPY(GC); private: - bool _notifyed; - bool _cleanup; - std::set _pool; + bool notifyed_; + bool cleanup_; + std::set pool_; }; } \ No newline at end of file diff --git a/core/e2dcommon.h b/core/e2dcommon.h index 70baca65..77944388 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -36,28 +36,32 @@ public: public: Point(); - Point(float x, float y); + Point( + float x, + float y + ); - Point(const Point& other); + Point( + const Point& other + ); - Point operator + (Point const & point) const; - Point operator - (Point const & point) const; - Point operator * (float const & point) const; - Point operator / (float const & point) const; + Point operator + (const Point & other) const; + Point operator - (const Point & other) const; + Point operator * (float value) const; + Point operator / (float value) const; Point operator - () const; - bool operator== (const Point& point) const; + bool operator== (const Point& other) const; - operator e2d::Size() const; + E2D_OP_EXPLICIT operator e2d::Size() const; // 判断两点间距离 - static float distance(const Point&, const Point&); + static float Distance( + const Point& p1, + const Point& p2 + ); }; -// 二维向量 -typedef Point Vector2; - - // 大小 class Size { @@ -68,18 +72,23 @@ public: public: Size(); - Size(float width, float height); + Size( + float width, + float height + ); - Size(const Size& other); + Size( + const Size& other + ); - Size operator + (Size const & size) const; - Size operator - (Size const & size) const; - Size operator * (float const & size) const; - Size operator / (float const & size) const; + Size operator + (const Size & other) const; + Size operator - (const Size & other) const; + Size operator * (float value) const; + Size operator / (float value) const; Size operator - () const; - bool operator== (const Size& size) const; + bool operator== (const Size& other) const; - operator e2d::Point() const; + E2D_OP_EXPLICIT operator e2d::Point() const; }; @@ -93,31 +102,33 @@ public: public: Rect(); - Rect(float x, float y, float width, float height); + Rect( + float x, + float y, + float width, + float height + ); - Rect(const Point& pos, const Size& size); + Rect( + const Point& pos, + const Size& size + ); - Rect(const Rect& other); + Rect( + const Rect& other + ); Rect& operator= (const Rect& other); bool operator== (const Rect& rect) const; - // 设置矩形 - void setRect( - float x, - float y, - float width, - float height - ); - // 判断点是否在矩形内 - bool containsPoint( + bool ContainsPoint( const Point& point ) const; // 判断两矩形是否相交 - bool intersects( + bool Intersects( const Rect& rect ) const; }; @@ -128,95 +139,104 @@ class String { public: String(); - String(const String &); - String(const char *); - String(const wchar_t *); - String(String &&); + + String( + const String & + ); + + String( + const char * + ); + + String( + const wchar_t * + ); + + String( + String && + ); ~String(); // 获取字符串长度 - int length() const; + int GetLength() const; - // 获取该字符串的散列值 - size_t hash() const; + // 获取该字符串的 Hash 值 + size_t GetHash() const; // 判断字符串是否为空 - bool isEmpty() const; + bool IsEmpty() const; // 获取指定位置字符 - wchar_t at( - int index + const wchar_t& At( + size_t index ) const; // 比较字符串 - int compare( + int Compare( const String & str ) const; // 截取字符串 - e2d::String subtract( + String Subtract( int offset, /* 偏移量 */ int count = -1 /* 截取字符数量 */ ) const; // 插入字符串 - void insert( + void Insert( const String & str, int pos ); // 替换字符串中的指定内容 - void replace( + void Replace( const String & from, /* 需替换内容 */ const String & to /* 替换成内容 */ ); // 删除字符串中的指定内容 - void erase( + void Erase( int offset, /* 偏移量 */ int count /* 删除字符数量 */ ); // 搜索字符串 - int find( + int Find( const String & str, /* 查找内容 */ int offset = 0 /* 偏移量 */ ) const; // 清空字符串 - void clear(); + void Clear(); // 获取大写字符串 - String toUpper() const; + String ToUpper() const; // 获取小写字符串 - String toLower() const; + String ToLower() const; // 将字符串转化为 int 型 - int toInt() const; + int ToInt() const; // 将字符串转化为 float 型 - float toFloat() const; + float ToFloat() const; // 将字符串转化为 double 型 - double toDouble() const; + double ToDouble() const; // 将字符串转化为 bool 型 - bool toBool() const; + bool ToBool() const; // 数字类型转字符串 - static String parse(int value); - static String parse(unsigned int value); - static String parse(float value); - static String parse(double value); + static String Parse(int value); + static String Parse(unsigned int value); + static String Parse(float value); + static String Parse(double value); // 格式化字符串 - static String format(const char * format, ...); - static String format(const wchar_t * format, ...); - - // 交换两字符串 - static void swap(String &str1, String &str2); + static String Format(const char * format, ...); + static String Format(const wchar_t * format, ...); // 赋值运算符 String& operator= (const String &); @@ -265,7 +285,7 @@ public: String& operator<< (double value); // 其他运算符 - wchar_t& operator[] (int); + wchar_t& operator[] (size_t); friend std::ostream& operator<< (std::ostream &, const String &); friend std::wostream& operator<< (std::wostream &, const String &); @@ -274,7 +294,7 @@ public: friend std::wistream& operator>> (std::wistream &, String &); private: - std::wstring _str; + std::wstring string_; }; @@ -356,13 +376,7 @@ public: Yellow_Green = 0x9ACD32 }; -private: - void _init( - UINT rgb, - float alpha - ); - -private: +public: float r; float g; float b; @@ -454,7 +468,7 @@ public: ); template - Function(Func func) : _func(func) {} + Function(Func func) : func_(func) {} template Function( @@ -462,7 +476,7 @@ public: Object&& obj /* 对象指针 */ ) { - _func = std::bind(func, obj); + func_ = std::bind(func, obj); } void operator() (void) const; @@ -470,7 +484,7 @@ public: E2D_OP_EXPLICIT operator bool() const; protected: - std::function _func; + std::function func_; }; @@ -485,10 +499,10 @@ public: ); // 获取毫秒数 - int milliseconds() const; + int Milliseconds() const; // 获取秒数 - float seconds() const; + float Seconds() const; bool operator== (const Duration &) const; bool operator!= (const Duration &) const; @@ -504,7 +518,7 @@ public: Duration& operator -= (Duration const &); protected: - std::chrono::milliseconds _ms; + std::chrono::milliseconds duration_ms_; }; @@ -515,10 +529,10 @@ public: Time(); // 获取时间戳 - time_t getTimeStamp() const; + time_t GetTimeStamp() const; // 是否是 - bool isZero() const; + bool IsZero() const; Time operator + (Duration const &) const; Time operator - (Duration const &) const; @@ -529,10 +543,10 @@ public: Duration operator - (Time const &) const; // 获取当前时间 - static Time now(); + static Time Now(); protected: - std::chrono::steady_clock::time_point _timePoint; + std::chrono::steady_clock::time_point time_; }; @@ -543,7 +557,7 @@ public: String family; // 字体族 float size; // 字号 UINT weight; // 粗细值 - bool italic; // 斜体 + bool italic; // 是否斜体 public: // 字体粗细值 @@ -605,73 +619,73 @@ public: virtual ~Collider(); // 设置碰撞体形状 - void setShape( + void SetShape( Shape shape ); // 是否触发碰撞事件 - void setCollisionNotify( + void SetCollisionNotify( bool notify ); // 启用或关闭该碰撞体 - void setEnabled( + void SetEnabled( bool enabled ); // 设置碰撞体的可见性 - void setVisible( + void SetVisible( bool visible ); // 设置绘制颜色 - void setColor( - Color color + void SetBorderColor( + const Color& color ); // 判断两碰撞体的交集关系 - Relation getRelationWith( - Collider * pCollider + Relation GetRelationWith( + Collider * collider ) const; // 是否启用碰撞体 - bool isEnabled() const; + bool IsEnabled() const; // 是否可见 - bool isVisible() const; + bool IsVisible() const; // 是否触发碰撞事件 - bool isCollisionNotify() const; + bool IsCollisionNotify() const; // 获取绘制颜色 - Color getColor() const; + const Color& GetBorderColor() const; // 获取形状 - Shape getShape() const; + Shape GetShape() const; // 获取绑定节点 - Node* getNode() const; + Node* GetNode() const; // 获取 ID2D1Geometry* 对象 - ID2D1Geometry* getGeometry() const; + ID2D1Geometry* GetGeometry() const; // 重新生成 - void recreate(); + void Recreate(); // 渲染碰撞体 - void render(); + void Draw(); protected: E2D_DISABLE_COPY(Collider); protected: - bool _enabled; - bool _visible; - bool _notify; - Color _color; - Node * _parentNode; - Shape _shape; - ID2D1Geometry* _geometry; + bool enabled_; + bool visible_; + bool notify_; + Color border_color_; + Node * parent_node_; + Shape shape_; + ID2D1Geometry* geometry_; }; @@ -680,13 +694,13 @@ class Resource { public: Resource( - size_t resNameId, /* 资源名称 */ - const String& resType /* 资源类型 */ + size_t resource_name, /* 资源名称 */ + const String& resource_type /* 资源类型 */ ); public: - size_t resNameId; - String resType; + size_t name; + String type; }; @@ -699,19 +713,19 @@ public: virtual ~Ref(); // 增加引用计数 - void retain(); + void Retain(); // 减少引用计数 - void release(); + void Release(); // 获取引用计数 - int getRefCount() const; + int GetRefCount() const; protected: E2D_DISABLE_COPY(Ref); private: - int _refCount; + int ref_count_; }; @@ -728,91 +742,91 @@ public: explicit Image( const Resource& res, - const Rect& cropRect /* 裁剪矩形 */ + const Rect& crop_rect /* 裁剪矩形 */ ); explicit Image( - const String& fileName + const String& file_name ); explicit Image( - const String& fileName, - const Rect& cropRect /* 裁剪矩形 */ + const String& file_name, + const Rect& crop_rect /* 裁剪矩形 */ ); virtual ~Image(); // 加载图片资源 - bool open( + bool Open( const Resource& res ); // 加载图片资源 - bool open( - const String& fileName + bool Open( + const String& file_name ); // 将图片裁剪为矩形 - void crop( - const Rect& cropRect /* 裁剪矩形 */ + void Crop( + const Rect& crop_rect /* 裁剪矩形 */ ); // 获取宽度 - virtual float getWidth() const; + virtual float GetWidth() const; // 获取高度 - virtual float getHeight() const; + virtual float GetHeight() const; // 获取大小 - virtual Size getSize() const; + virtual Size GetSize() const; // 获取源图片宽度 - virtual float getSourceWidth() const; + virtual float GetSourceWidth() const; // 获取源图片高度 - virtual float getSourceHeight() const; + virtual float GetSourceHeight() const; // 获取源图片大小 - virtual Size getSourceSize() const; + virtual Size GetSourceSize() const; // 获取裁剪位置 X 坐标 - virtual float getCropX() const; + virtual float GetCropX() const; // 获取裁剪位置 Y 坐标 - virtual float getCropY() const; + virtual float GetCropY() const; // 获取裁剪位置 - virtual Point getCropPos() const; + virtual Point GetCropPos() const; // 获取 ID2D1Bitmap 对象 - ID2D1Bitmap * getBitmap(); + ID2D1Bitmap * GetBitmap(); // 预加载图片资源 - static bool preload( - const String& fileName + static bool Preload( + const String& file_name ); // 预加载图片资源 - static bool preload( + static bool Preload( const Resource& res ); // 清空缓存 - static void clearCache(); + static void ClearCache(); protected: E2D_DISABLE_COPY(Image); // 设置 Bitmap - void _setBitmap( + void SetBitmap( ID2D1Bitmap * bitmap ); protected: - Rect _cropRect; - ID2D1Bitmap * _bitmap; + Rect crop_rect_; + ID2D1Bitmap * bitmap_; - static std::map _bitmapCache; + static std::map bitmap_cache_; }; diff --git a/core/e2dcustom.h b/core/e2dcustom.h index 54d20c36..caf4528c 100644 --- a/core/e2dcustom.h +++ b/core/e2dcustom.h @@ -31,32 +31,28 @@ public: STDMETHOD_(void, OnVoiceError) (THIS_ void* pBufferContext, HRESULT Error) {} - void SetFuncOnStreamEnd( - const Function& func - ); + STDMETHOD_(void, SetCallbackOnStreamEnd) (THIS_ const Function& func); - void SetFuncOnLoopEnd( - const Function& func - ); + STDMETHOD_(void, SetCallbackOnLoopEnd) (THIS_ const Function& func); protected: - Function _loopEndFunc; - Function _streamEndFunc; + Function loop_end_callback_; + Function stream_end_callback_; }; // 文字渲染器 -class TextRenderer +class E2DTextRenderer : public IDWriteTextRenderer { private: - TextRenderer(); + E2DTextRenderer(); - ~TextRenderer(); + ~E2DTextRenderer(); public: static HRESULT Create( - TextRenderer** ppTextRenderer, + E2DTextRenderer** ppTextRenderer, ID2D1Factory* pD2DFactory, ID2D1HwndRenderTarget* pRT, ID2D1SolidColorBrush* pBrush @@ -64,9 +60,9 @@ public: STDMETHOD_(void, SetTextStyle)( CONST D2D1_COLOR_F &fillColor, - BOOL hasOutline, - CONST D2D1_COLOR_F &outlineColor, - FLOAT outlineWidth, + BOOL outline, + CONST D2D1_COLOR_F &outline_color, + FLOAT outline_width, D2D1_LINE_JOIN outlineJoin ); @@ -101,8 +97,8 @@ public: FLOAT originX, FLOAT originY, IDWriteInlineObject* inlineObject, - BOOL isSideways, - BOOL isRightToLeft, + BOOL IsSideways, + BOOL IsRightToLeft, IUnknown* clientDrawingEffect ); @@ -157,10 +153,10 @@ public: Exception& operator=(Exception const& other) E2D_NOEXCEPT; // 获取异常信息 - virtual const char * msg() const; + virtual const char * GetMsg() const; private: - const char * _message; + const char * message_; }; diff --git a/core/e2devent.h b/core/e2devent.h index abc0835b..30231ef3 100644 --- a/core/e2devent.h +++ b/core/e2devent.h @@ -20,28 +20,28 @@ public: explicit KeyEvent( HWND hWnd, UINT message, - WPARAM wParam, - LPARAM lParam + WPARAM w_param, + LPARAM l_param ); // 获取按键键值 - KeyCode getCode() const; + KeyCode GetCode() const; // 获取按键次数 - int getCount() const; + int GetCount() const; // 获取事件类型 - KeyEvent::Type getType() const; + KeyEvent::Type GetType() const; // VK 键值转换 - static KeyCode convertKeyCode( - WPARAM wParam + static KeyCode ToKeyCode( + WPARAM w_param ); protected: - int _count; - KeyCode _code; - KeyEvent::Type _type; + int count_; + KeyCode code_; + KeyEvent::Type type_; }; @@ -69,46 +69,46 @@ public: explicit MouseEvent( HWND hWnd, UINT message, - WPARAM wParam, - LPARAM lParam, + WPARAM w_param, + LPARAM l_param, float dpi ); // 获取鼠标横坐标 - float getX() const; + float GetX() const; // 获取鼠标纵坐标 - float getY() const; + float GetY() const; // 获取鼠标坐标 - Point getPos() const; + Point GetPos() const; // 获取事件类型 - MouseEvent::Type getType() const; + MouseEvent::Type GetType() const; - float getWheelDelta() const; + float GetWheelDelta() const; // 鼠标左键是否按下 - bool isLButtonDown() const; + bool IsLButtonDown() const; // 鼠标右键是否按下 - bool isRButtonDown() const; + bool IsRButtonDown() const; // 鼠标中键是否按下 - bool isMButtonDown() const; + bool IsMButtonDown() const; // Shift 键是否按下 - bool isShiftDown() const; + bool IsShiftDown() const; // Ctrl 键是否按下 - bool isCtrlDown() const; + bool IsCtrlDown() const; protected: - UINT _message; - WPARAM _wParam; - LPARAM _lParam; - Point _pos; - MouseEvent::Type _type; + UINT message_; + WPARAM w_param_; + LPARAM l_param_; + Point pos_; + MouseEvent::Type type_; }; @@ -126,14 +126,14 @@ public: ~Collision(); // 获取发生碰撞节点 - Node* getNode() const; + Node* GetNode() const; // 获取交集关系 - Collider::Relation getRelation() const; + Collider::Relation GetRelation() const; protected: - Node * _node; - Collider::Relation _relation; + Node * node_; + Collider::Relation relation_; }; } \ No newline at end of file diff --git a/core/e2dmanager.h b/core/e2dmanager.h index 0f6ada8d..5039c0cc 100644 --- a/core/e2dmanager.h +++ b/core/e2dmanager.h @@ -16,66 +16,66 @@ class ActionManager public: // 获取动作管理器实例 - static ActionManager * getInstance(); + static ActionManager * GetInstance(); // 获取所有名称相同的动作 - std::vector get( + std::vector Get( const String& name ); // 获取所有动作 - const std::vector& getAll(); + const std::vector& GetAll(); // 执行动作 - void start( + void Start( Action * action, Node * target, bool paused ); // 继续名称相同的所有动作 - void resume( + void Resume( const String& name ); // 暂停名称相同的所有动作 - void pause( + void Pause( const String& name ); // 停止名称相同的所有动作 - void stop( + void Stop( const String& name ); // 继续绑定在节点上的所有动作 - void resumeAllBindedWith( + void ResumeAllBindedWith( Node * target ); // 暂停绑定在节点上的所有动作 - void pauseAllBindedWith( + void PauseAllBindedWith( Node * target ); // 停止绑定在节点上的所有动作 - void stopAllBindedWith( + void StopAllBindedWith( Node * target ); // 强制清除绑定在节点上的所有动作 - void clearAllBindedWith( + void ClearAllBindedWith( Node * target ); // 强制清除所有动作 - void clearAll(); + void ClearAll(); // 更新动作管理器状态 - void update(); + void Update(); // 刷新所有动作计时 - void updateTime(); + void UpdateTime(); private: ActionManager(); @@ -85,18 +85,18 @@ private: E2D_DISABLE_COPY(ActionManager); // 添加动作 - void __add( + void Add( Action * action ); // 删除动作 - void __remove( + void Remove( Action * action ); private: - std::vector _actions; - std::vector _runningActions; + std::vector actions_; + std::vector running_actions_; }; @@ -108,33 +108,33 @@ class CollisionManager public: // 获取碰撞体管理器实例 - static CollisionManager * getInstance(); + static CollisionManager * GetInstance(); // 打开或关闭碰撞监听 // 默认:关闭 - void setCollisionEnabled( + void SetCollisionEnabled( bool enabled ); // 添加可互相碰撞物体的名称 - void addName( + void AddName( const String& name1, const String& name2 ); // 添加可互相碰撞物体的名称 - void addName( + void AddName( const std::vector>& names ); // 判断两个物体是否是可碰撞的 - bool isCollidable( + bool IsCollidable( Node * node1, Node * node2 ); // 判断两个物体是否是可碰撞的 - bool isCollidable( + bool IsCollidable( const String& name1, const String& name2 ); @@ -147,24 +147,24 @@ private: E2D_DISABLE_COPY(CollisionManager); // 添加碰撞体 - void __addCollider( + void AddCollider( Collider* collider ); // 移除碰撞体 - void __removeCollider( + void RemoveCollider( Collider* collider ); // 更新碰撞体 - void __updateCollider( + void UpdateCollider( Collider* collider ); private: - bool _collisionEnabled; - std::vector _colliders; - std::set> _collisionList; + bool collision_enabled_; + std::vector colliders_; + std::set> collision_list_; }; } \ No newline at end of file diff --git a/core/e2dnode.h b/core/e2dnode.h index a961bb75..2de9ddc7 100644 --- a/core/e2dnode.h +++ b/core/e2dnode.h @@ -14,7 +14,7 @@ class Drawable { public: // 渲染图形 - virtual void draw() const = 0; + virtual void Draw() const = 0; }; @@ -23,7 +23,7 @@ class Updatable { public: // 渲染图形 - virtual void update() = 0; + virtual void Update() = 0; }; @@ -32,7 +32,7 @@ class KeyEventHandler { public: // 处理按键消息 - virtual void handle(KeyEvent e) = 0; + virtual void Handle(KeyEvent e) = 0; }; @@ -41,7 +41,7 @@ class MouseEventHandler { public: // 处理鼠标消息 - virtual void handle(MouseEvent e) = 0; + virtual void Handle(MouseEvent e) = 0; }; @@ -50,7 +50,7 @@ class CollisionHandler { public: // 处理碰撞消息 - virtual void handle(Collision collision) = 0; + virtual void Handle(Collision collision) = 0; }; @@ -64,17 +64,12 @@ public: // 节点属性 struct Property { - float posX; // X 坐标 - float posY; // Y 坐标 - float width; // 宽度 - float height; // 高度 - float anchorX; // 锚点 X 坐标 - float anchorY; // 锚点 Y 坐标 - float scaleX; // 横向缩放 - float scaleY; // 纵向缩放 + Point pos; // 坐标 + Size size; // 大小 + Point anchor; // 锚点坐标 + Point scale; // 缩放 + Point skew; // 倾斜角度 float rotation; // 旋转角度 - float skewAngleX; // 横向倾斜角度 - float skewAngleY; // 纵向倾斜角度 Property operator+ (Property const & prop) const; Property operator- (Property const & prop) const; @@ -83,414 +78,401 @@ public: }; public: + typedef std::vector Nodes; + Node(); virtual ~Node(); // 获取节点显示状态 - bool isVisible() const; + bool IsVisible() const; // 获取节点名称 - const String& getName() const; + const String& GetName() const; // 获取节点名称的 Hash 值 - size_t getHashName() const; + size_t GetHashName() const; // 获取节点绘图顺序 - int getOrder() const; + int GetOrder() const; // 获取节点横坐标 - float getPosX() const; + float GetPosX() const; // 获取节点纵坐标 - float getPosY() const; + float GetPosY() const; // 获取节点坐标 - Point getPos() const; + Point GetPos() const; // 获取节点宽度 - float getWidth() const; + float GetWidth() const; // 获取节点高度 - float getHeight() const; + float GetHeight() const; // 获取节点宽度(不考虑缩放) - float getRealWidth() const; + float GetRealWidth() const; // 获取节点高度(不考虑缩放) - float getRealHeight() const; + float GetRealHeight() const; // 获取节点大小(不考虑缩放) - Size getRealSize() const; + Size GetRealSize() const; // 获取节点的锚点 - float getAnchorX() const; + float GetAnchorX() const; // 获取节点的锚点 - float getAnchorY() const; + float GetAnchorY() const; // 获取节点大小 - Size getSize() const; + Size GetSize() const; // 获取节点横向缩放比例 - float getScaleX() const; + float GetScaleX() const; // 获取节点纵向缩放比例 - float getScaleY() const; + float GetScaleY() const; // 获取节点横向倾斜角度 - float getSkewX() const; + float GetSkewX() const; // 获取节点纵向倾斜角度 - float getSkewY() const; + float GetSkewY() const; // 获取节点旋转角度 - float getRotation() const; + float GetRotation() const; // 获取节点透明度 - float getOpacity() const; + float GetOpacity() const; // 获取节点属性 - Property getProperty() const; + Property GetProperty() const; // 获取差别属性 - Property getExtrapolate() const; + Property GetExtrapolate() const; // 获取节点碰撞体 - Collider * getCollider(); + Collider * GetCollider(); // 获取父节点 - Node * getParent() const; + Node * GetParent() const; // 获取节点所在场景 - Scene * getParentScene() const; + Scene * GetParentScene() const; // 设置节点是否显示 - void setVisible( + void SetVisible( bool value ); // 设置节点名称 - void setName( + void SetName( const String& name ); // 设置节点横坐标 - virtual void setPosX( + virtual void SetPosX( float x ); // 设置节点纵坐标 - virtual void setPosY( + virtual void SetPosY( float y ); // 设置节点坐标 - virtual void setPos( + virtual void SetPos( const Point & point ); // 设置节点坐标 - virtual void setPos( + virtual void SetPos( float x, float y ); // 节点坐标固定 - virtual void setPosFixed( + virtual void SetPosFixed( bool fixed ); // 移动节点 - virtual void movePosX( - float x - ); - - // 移动节点 - virtual void movePosY( - float y - ); - - // 移动节点 - virtual void movePos( + virtual void Move( float x, float y ); // 移动节点 - virtual void movePos( - const Vector2 & v + virtual void Move( + const Point & v ); // 设置节点绘图顺序 // 默认为 0 - virtual void setOrder( + virtual void SetOrder( int order ); // 设置横向缩放比例 // 默认为 1.0 - virtual void setScaleX( - float scaleX + virtual void SetScaleX( + float scale_x ); // 设置纵向缩放比例 // 默认为 1.0 - virtual void setScaleY( - float scaleY + virtual void SetScaleY( + float scale_y ); // 设置缩放比例 // 默认为 (1.0, 1.0) - virtual void setScale( - float scaleX, - float scaleY + virtual void SetScale( + float scale_x, + float scale_y ); // 设置缩放比例 // 默认为 1.0 - virtual void setScale( + virtual void SetScale( float scale ); // 设置横向倾斜角度 // 默认为 0 - virtual void setSkewX( - float angleX + virtual void SetSkewX( + float skew_x ); // 设置纵向倾斜角度 // 默认为 0 - virtual void setSkewY( - float angleY + virtual void SetSkewY( + float skew_y ); // 设置倾斜角度 // 默认为 (0, 0) - virtual void setSkew( - float angleX, - float angleY + virtual void SetSkew( + float skew_x, + float skew_y ); // 设置旋转角度 // 默认为 0 - virtual void setRotation( + virtual void SetRotation( float rotation ); // 设置透明度 // 默认为 1.0, 范围 [0, 1] - virtual void setOpacity( + virtual void SetOpacity( float opacity ); // 设置锚点的横向位置 // 默认为 0, 范围 [0, 1] - virtual void setAnchorX( - float anchorX + virtual void SetAnchorX( + float anchor_x ); // 设置锚点的纵向位置 // 默认为 0, 范围 [0, 1] - virtual void setAnchorY( - float anchorY + virtual void SetAnchorY( + float anchor_y ); // 设置锚点位置 // 默认为 (0, 0), 范围 [0, 1] - virtual void setAnchor( - float anchorX, - float anchorY + virtual void SetAnchor( + float anchor_x, + float anchor_y ); // 修改节点宽度 - virtual void setWidth( + virtual void SetWidth( float width ); // 修改节点高度 - virtual void setHeight( + virtual void SetHeight( float height ); // 修改节点大小 - virtual void setSize( + virtual void SetSize( float width, float height ); // 修改节点大小 - virtual void setSize( + virtual void SetSize( Size size ); // 设置节点属性 - virtual void setProperty( + virtual void SetProperty( Property prop ); // 启用或关闭渲染区域裁剪 - virtual void setClipEnabled( + virtual void SetClipEnabled( bool enabled ); // 设置节点边缘颜色 - virtual void setBorderColor( + virtual void SetBorderColor( const Color& color ); // 判断点是否在节点内 - bool containsPoint( + bool ContainsPoint( const Point& point ); // 判断两物体是否相交 - bool intersects( + bool Intersects( Node * node ); // 添加子节点 - void addChild( + void AddChild( Node * child, - int order = 0 /* 渲染顺序 */ + int order = 0 /* 渲染顺序 */ ); // 添加多个子节点 - void addChild( - const std::vector& nodes, /* 节点数组 */ - int order = 0 /* 渲染顺序 */ + void AddChild( + const Nodes& nodes, /* 节点数组 */ + int order = 0 /* 渲染顺序 */ ); // 获取所有名称相同的子节点 - std::vector getChildren( + Nodes GetChildren( const String& name ) const; // 获取名称相同的子节点 - Node* getChild( + Node* GetChild( const String& name ) const; // 获取所有子节点 - const std::vector& getAllChildren() const; + const Nodes& GetAllChildren() const; // 获取子节点数量 - int getChildrenCount() const; + int GetChildrenCount() const; // 移除子节点 - bool removeChild( + bool RemoveChild( Node * child ); // 移除所有名称相同的子节点 - void removeChildren( - const String& childName + void RemoveChildren( + const String& child_name ); // 移除所有节点 - void removeAllChildren(); + void RemoveAllChildren(); // 从父节点移除 - void removeFromParent(); + void RemoveFromParent(); // 执行动作 - void runAction( + void RunAction( Action * action ); // 继续动作 - void resumeAction( + void ResumeAction( const String& name ); // 暂停动作 - void pauseAction( + void PauseAction( const String& name ); // 停止动作 - void stopAction( + void StopAction( const String& name ); // 继续所有暂停动作 - void resumeAllActions(); + void ResumeAllActions(); // 暂停所有动作 - void pauseAllActions(); + void PauseAllActions(); // 停止所有动作 - void stopAllActions(); + void StopAllActions(); // 分发鼠标消息 - virtual bool dispatch( + virtual bool Dispatch( const MouseEvent& e, bool handled ); // 分发按键消息 - virtual bool dispatch( + virtual bool Dispatch( const KeyEvent& e, bool handled ); // 遍历节点 - virtual void visit(); + virtual void Visit(); protected: E2D_DISABLE_COPY(Node); // 渲染节点边缘 - void _drawBorder(); + void DrawBorder(); // 渲染碰撞体轮廓 - void _drawCollider(); + void DrawCollider(); // 设置节点所在场景 - void _setParentScene( + void SetParentScene( Scene * scene ); // 子节点排序 - void _sortChildren(); + void SortChildren(); // 更新转换矩阵 - void _updateTransform(); + void UpdateTransform(); // 更新节点透明度 - void _updateOpacity(); + void UpdateOpacity(); protected: - String _name; - size_t _hashName; - float _posX; - float _posY; - float _width; - float _height; - float _scaleX; - float _scaleY; - float _rotation; - float _skewAngleX; - float _skewAngleY; - float _displayOpacity; - float _realOpacity; - float _anchorX; - float _anchorY; - int _order; - bool _visible; - bool _clipEnabled; - bool _needSort; - bool _needTransform; - bool _positionFixed; - Collider _collider; - Scene * _parentScene; - Node * _parent; - Property _extrapolate; - Color _borderColor; - ID2D1Geometry* _border; - std::vector _children; - D2D1::Matrix3x2F _initialMatri; - D2D1::Matrix3x2F _finalMatri; + String name_; + size_t hash_name_; + Point pos_; + Size size_; + Point scale_; + Point anchor_; + Point skew_; + float rotation_; + float display_opacity_; + float real_opacity_; + int order_; + bool visible_; + bool clip_enabled_; + bool need_sort_; + bool need_transform_; + bool fixed_position_; + Collider collider_; + Scene * parent_scene_; + Node * parent_; + Property extrapolate_; + Color border_color_; + Nodes children_; + ID2D1Geometry* border_; + D2D1::Matrix3x2F initial_matrix_; + D2D1::Matrix3x2F final_matrix_; }; @@ -504,36 +486,36 @@ public: virtual ~Scene(); // 进入场景 - virtual void onEnter() {} + virtual void OnEnter() {} // 退出场景 - virtual void onExit() {} + virtual void OnExit() {} // 关闭窗口 // 说明:返回 false 将阻止窗口关闭 - virtual bool onCloseWindow() { return true; } + virtual bool OnCloseWindow() { return true; } // 显示或隐藏节点边缘 // 默认:隐藏 - void showBorder( + void ShowBorder( bool visible ); // 显示或隐藏碰撞体 // 默认:隐藏 - void showCollider( + void ShowCollider( bool visible ); // 遍历节点 - virtual void visit() override; + virtual void Visit() override; protected: E2D_DISABLE_COPY(Scene); protected: - bool _borderVisible; - bool _colliderVisible; + bool border_visible_; + bool collider_visible_; }; @@ -555,51 +537,51 @@ public: explicit Sprite( const Resource& res, - const Rect& cropRect /* 裁剪矩形 */ + const Rect& crop_rect /* 裁剪矩形 */ ); explicit Sprite( - const String& fileName + const String& file_name ); explicit Sprite( - const String& fileName, - const Rect& cropRect /* 裁剪矩形 */ + const String& file_name, + const Rect& crop_rect /* 裁剪矩形 */ ); virtual ~Sprite(); // 加载图片文件 - bool open( + bool Open( const Resource& res ); // 加载图片文件 - bool open( - const String& fileName + bool Open( + const String& file_name ); // 加载图片 - bool open( + bool Open( Image * image ); // 将图片裁剪为矩形 - void crop( - const Rect& cropRect /* 裁剪矩形 */ + void Crop( + const Rect& crop_rect /* 裁剪矩形 */ ); // 获取 Image 对象 - Image * getImage() const; + Image * GetImage() const; // 渲染精灵 - virtual void draw() const override; + virtual void Draw() const override; protected: E2D_DISABLE_COPY(Sprite); protected: - Image * _image; + Image * image_; }; @@ -623,15 +605,15 @@ public: public: Color color; // 颜色 Align alignment; // 对齐方式 - bool wrapping; // 打开自动换行 - float wrappingWidth; // 自动换行宽度 - float lineSpacing; // 行间距 - bool hasUnderline; // 下划线 - bool hasStrikethrough; // 删除线 - bool hasOutline; // 显示描边 - Color outlineColor; // 描边颜色 - float outlineWidth; // 描边线宽 - Stroke outlineStroke; // 描边线相交样式 + bool wrap; // 打开自动换行 + float wrap_width; // 自动换行宽度 + float line_spacing; // 行间距 + bool underline; // 下划线 + bool strikethrough; // 删除线 + bool outline; // 显示描边 + Color outline_color; // 描边颜色 + float outline_width; // 描边线宽 + Stroke outline_stroke; // 描边线相交样式 public: Style(); @@ -639,15 +621,15 @@ public: Style( Color color, Align alignment = Align::Left, - bool wrapping = false, - float wrappingWidth = 0.f, - float lineSpacing = 0.f, - bool hasUnderline = false, - bool hasStrikethrough = false, - bool hasOutline = true, - Color outlineColor = Color(Color::Black, 0.5), - float outlineWidth = 1.f, - Stroke outlineStroke = Stroke::Round + bool wrap = false, + float wrap_width = 0.f, + float line_spacing = 0.f, + bool underline = false, + bool strikethrough = false, + bool outline = true, + Color outline_color = Color(Color::Black, 0.5), + float outline_width = 1.f, + Stroke outline_stroke = Stroke::Round ); }; @@ -663,161 +645,161 @@ public: virtual ~Text(); // 获取文本 - const String& getText() const; + const String& GetText() const; // 获取字体 - const Font& getFont() const; + const Font& GetFont() const; // 获取文本样式 - const Style& getStyle() const; + const Style& GetStyle() const; // 获取字体族 - const String& getFontFamily() const; + const String& GetFontFamily() const; // 获取当前字号 - float getFontSize() const; + float GetFontSize() const; // 获取当前字体粗细值 - UINT getFontWeight() const; + UINT GetFontWeight() const; // 获取文字颜色 - const Color& getColor() const; + const Color& GetColor() const; // 获取描边颜色 - const Color& getOutlineColor() const; + const Color& GetOutlineColor() const; // 获取描边线宽 - float getOutlineWidth() const; + float GetOutlineWidth() const; // 获取描边线相交样式 - Stroke getOutlineStroke() const; + Stroke GetOutlineStroke() const; // 获取文本显示行数 - int getLineCount() const; + int GetLineCount() const; // 是否是斜体 - bool isItalic() const; + bool IsItalic() const; // 是否显示删除线 - bool hasStrikethrough() const; + bool strikethrough() const; // 是否显示下划线 - bool hasUnderline() const; + bool underline() const; // 是否显示描边 - bool hasOutline() const; + bool outline() const; // 设置文本 - void setText( + void SetText( const String& text ); // 设置文本样式 - void setStyle( + void SetStyle( const Style& style ); // 设置字体 - void setFont( + void SetFont( const Font& font ); // 设置字体族 - void setFontFamily( + void SetFontFamily( const String& family ); // 设置字号(默认值为 22) - void setFontSize( + void SetFontSize( float size ); // 设置字体粗细值(默认值为 Text::Font::Weight::Normal) - void setFontWeight( + void SetFontWeight( UINT weight ); // 设置文字颜色(默认值为 Color::WHITE) - void setColor( + void SetColor( Color color ); // 设置文字斜体(默认值为 false) - void setItalic( + void SetItalic( bool value ); // 打开或关闭文本自动换行(默认为关闭) - void setWrapping( - bool wrapping + void SetWrapEnabled( + bool wrap ); // 设置文本自动换行的宽度(默认为 0) - void setWrappingWidth( - float wrappingWidth + void SetWrapWidth( + float wrap_width ); // 设置行间距(默认为 0) - void setLineSpacing( - float lineSpacing + void SetLineSpacing( + float line_spacing ); // 设置对齐方式(默认为 Align::Left) - void setAlignment( + void SetAlignment( Align align ); // 设置下划线(默认值为 false) - void setUnderline( - bool hasUnderline + void SetUnderline( + bool underline ); // 设置删除线(默认值为 false) - void setStrikethrough( - bool hasStrikethrough + void SetStrikethrough( + bool strikethrough ); // 设置是否显示描边 - void setOutline( - bool hasOutline + void SetOutline( + bool outline ); // 设置描边颜色 - void setOutlineColor( - Color outlineColor + void SetOutlineColor( + Color outline_color ); // 设置描边线宽 - void setOutlineWidth( - float outlineWidth + void SetOutlineWidth( + float outline_width ); // 设置描边线相交样式 - void setOutlineStroke( - Stroke outlineStroke + void SetOutlineStroke( + Stroke outline_stroke ); // 渲染文字 - virtual void draw() const override; + virtual void Draw() const override; protected: E2D_DISABLE_COPY(Text); // 重新排版文字 - void _reset(); + void Reset(); // 创建文字格式化 - void _createFormat(); + void CreateFormat(); // 创建文字布局 - void _createLayout(); + void CreateLayout(); protected: - String _text; - Font _font; - Style _style; - IDWriteTextFormat * _textFormat; - IDWriteTextLayout * _textLayout; + String text_; + Font font_; + Style style_; + IDWriteTextFormat * text_format_; + IDWriteTextLayout * text_layout_; }; @@ -829,20 +811,20 @@ public: explicit Button( Node * normal, /* 普通状态 */ - const Function& func = nullptr /* 按钮点击后的执行函数 */ + const Function& func = nullptr /* 按钮点击后的回调函数 */ ); explicit Button( Node * normal, /* 普通状态 */ Node * selected, /* 鼠标按下状态 */ - const Function& func = nullptr /* 按钮点击后的执行函数 */ + const Function& func = nullptr /* 按钮点击后的回调函数 */ ); explicit Button( Node * normal, /* 普通状态 */ Node * mouseover, /* 鼠标移入状态 */ Node * selected, /* 鼠标按下状态 */ - const Function& func = nullptr /* 按钮点击后的执行函数 */ + const Function& func = nullptr /* 按钮点击后的回调函数 */ ); explicit Button( @@ -850,57 +832,57 @@ public: Node * mouseover, /* 鼠标移入状态 */ Node * selected, /* 鼠标移入状态 */ Node * disabled, /* 按钮禁用状态 */ - const Function& func = nullptr /* 按钮点击后的执行函数 */ + const Function& func = nullptr /* 按钮点击后的回调函数 */ ); // 获取按钮状态是启用还是禁用 - bool isEnable() const; + bool IsEnable() const; // 设置按钮启用或禁用 - void setEnabled( + void SetEnabled( bool enabled ); // 设置一般情况下显示的按钮 - virtual void setNormal( + virtual void SetNormal( Node * normal ); // 设置鼠标移入按钮时显示的按钮 - virtual void setMouseOver( + virtual void SetMouseOver( Node * mouseover ); // 设置鼠标按下按钮时显示的按钮 - virtual void setSelected( + virtual void SetSelected( Node * selected ); // 设置按钮被禁用时显示的按钮 - virtual void setDisabled( + virtual void SetDisabled( Node * disabled ); - // 设置按钮点击后的执行函数 - void setClickFunc( + // 设置按钮点击后的回调函数 + void SetCallbackOnClick( const Function& func ); // 设置锚点位置 // 默认为 (0, 0), 范围 [0, 1] - virtual void setAnchor( - float anchorX, - float anchorY + virtual void SetAnchor( + float anchor_x, + float anchor_y ) override; // 分发鼠标消息 - virtual bool dispatch( + virtual bool Dispatch( const MouseEvent& e, bool handled ) override; // 遍历节点 - virtual void visit() override; + virtual void Visit() override; protected: E2D_DISABLE_COPY(Button); @@ -909,23 +891,25 @@ protected: enum class Status { Normal, Mouseover, Selected }; // 设置按钮状态 - virtual void _setStatus(Status status); + virtual void SetStatus( + Status status + ); // 刷新按钮显示 - virtual void _updateVisible(); + virtual void UpdateVisible(); - // 执行按钮函数对象 - virtual void _runCallback(); + // 点击回调 + virtual void OnClick(); protected: - Node * _normal; - Node * _mouseover; - Node * _selected; - Node * _disabled; - bool _enabled; - bool _isSelected; - Status _status; - Function _func; + Node * normal_; + Node * mouseover_; + Node * selected_; + Node * disabled_; + bool enabled_; + bool is_selected_; + Status status_; + Function callback_; }; @@ -936,115 +920,115 @@ public: ToggleButton(); explicit ToggleButton( - Node * onNormal, /* 按钮打开时,普通状态 */ - Node * offNormal, /* 按钮关闭时,普通状态 */ - const Function& func = nullptr /* 按钮点击后的执行函数 */ + Node * normal_on, /* 按钮打开时,普通状态 */ + Node * normal_off, /* 按钮关闭时,普通状态 */ + const Function& func = nullptr /* 按钮点击后的回调函数 */ ); explicit ToggleButton( - Node * onNormal, /* 按钮打开时,普通状态 */ - Node * offNormal, /* 按钮关闭时,普通状态 */ - Node * onSelected, /* 按钮打开时,鼠标按下状态 */ - Node * offSelected, /* 按钮关闭时,鼠标按下状态 */ - const Function& func = nullptr /* 按钮点击后的执行函数 */ + Node * normal_on, /* 按钮打开时,普通状态 */ + Node * normal_off, /* 按钮关闭时,普通状态 */ + Node * selected_on, /* 按钮打开时,鼠标按下状态 */ + Node * selected_off, /* 按钮关闭时,鼠标按下状态 */ + const Function& func = nullptr /* 按钮点击后的回调函数 */ ); explicit ToggleButton( - Node * onNormal, /* 按钮打开时,普通状态 */ - Node * offNormal, /* 按钮关闭时,普通状态 */ - Node * onMouseOver, /* 按钮打开时,鼠标移入状态 */ - Node * offMouseOver, /* 按钮关闭时,鼠标移入状态 */ - Node * onSelected, /* 按钮打开时,鼠标按下状态 */ - Node * offSelected, /* 按钮关闭时,鼠标按下状态 */ - const Function& func = nullptr /* 按钮点击后的执行函数 */ + Node * normal_on, /* 按钮打开时,普通状态 */ + Node * normal_off, /* 按钮关闭时,普通状态 */ + Node * mouseover_on, /* 按钮打开时,鼠标移入状态 */ + Node * mouseover_off, /* 按钮关闭时,鼠标移入状态 */ + Node * selected_on, /* 按钮打开时,鼠标按下状态 */ + Node * selected_off, /* 按钮关闭时,鼠标按下状态 */ + const Function& func = nullptr /* 按钮点击后的回调函数 */ ); explicit ToggleButton( - Node * onNormal, /* 按钮打开时,普通状态 */ - Node * offNormal, /* 按钮关闭时,普通状态 */ - Node * onMouseOver, /* 按钮打开时,鼠标移入状态 */ - Node * offMouseOver, /* 按钮关闭时,鼠标移入状态 */ - Node * onSelected, /* 按钮打开时,鼠标按下状态 */ - Node * offSelected, /* 按钮关闭时,鼠标按下状态 */ - Node * onDisabled, /* 按钮打开时,禁用状态 */ - Node * offDisabled, /* 按钮关闭时,禁用状态 */ - const Function& func = nullptr /* 按钮点击后的执行函数 */ + Node * normal_on, /* 按钮打开时,普通状态 */ + Node * normal_off, /* 按钮关闭时,普通状态 */ + Node * mouseover_on, /* 按钮打开时,鼠标移入状态 */ + Node * mouseover_off, /* 按钮关闭时,鼠标移入状态 */ + Node * selected_on, /* 按钮打开时,鼠标按下状态 */ + Node * selected_off, /* 按钮关闭时,鼠标按下状态 */ + Node * disabled_on, /* 按钮打开时,禁用状态 */ + Node * disabled_off, /* 按钮关闭时,禁用状态 */ + const Function& func = nullptr /* 按钮点击后的回调函数 */ ); // 获取开关状态 - bool isChecked() const; + bool IsChecked() const; // 设置开关按钮的状态 - void setChecked( + void SetChecked( bool checked ); // 设置按钮打开状态下显示的按钮 - virtual void setNormal( + virtual void SetNormal( Node * normal ) override; // 设置按钮打开状态下,鼠标移入按钮时显示的按钮 - virtual void setMouseOver( + virtual void SetMouseOver( Node * mouseover ) override; // 设置按钮打开状态下,鼠标按下按钮时显示的按钮 - virtual void setSelected( + virtual void SetSelected( Node * selected ) override; // 设置按钮打开状态下,被禁用时显示的按钮 - virtual void setDisabled( + virtual void SetDisabled( Node * disabled ) override; // 设置按钮关闭状态下显示的按钮 - void setNormalOff( + void SetNormalOff( Node * normal ); // 设置按钮关闭状态下,鼠标移入按钮时显示的按钮 - void setMouseOverOff( + void SetMouseOverOff( Node * mouseover ); // 设置按钮关闭状态下,鼠标按下按钮时显示的按钮 - void setSelectedOff( + void SetSelectedOff( Node * selected ); // 设置按钮关闭状态下,按钮被禁用时显示的按钮 - void setDisabledOff( + void SetDisabledOff( Node * disabled ); // 设置锚点位置 // 默认为 (0, 0), 范围 [0, 1] - virtual void setAnchor( - float anchorX, - float anchorY + virtual void SetAnchor( + float anchor_x, + float anchor_y ) override; protected: E2D_DISABLE_COPY(ToggleButton); // 刷新按钮开关 - virtual void _updateStatus(); + virtual void UpdateStatus(); // 执行按钮函数对象 - virtual void _runCallback() override; + virtual void OnClick() override; protected: - Node* _normalOn; - Node* _mouseoverOn; - Node* _selectedOn; - Node* _disabledOn; - Node* _normalOff; - Node* _mouseoverOff; - Node* _selectedOff; - Node* _disabledOff; - bool _checked; + Node* normal_on_; + Node* mouseover_on_; + Node* selected_on_; + Node* disabled_on_; + Node* normal_off_; + Node* mouseover_off_; + Node* selected_off_; + Node* disabled_off_; + bool checked_; }; @@ -1059,35 +1043,35 @@ public: ); // 获取菜单是否禁用 - bool isEnable() const; + bool IsEnable() const; // 获取菜单中的按钮数量 - size_t getButtonCount() const; + size_t GetButtonCount() const; // 设置菜单启用或禁用 - void setEnabled( + void SetEnabled( bool enabled ); // 添加按钮 - void addButton( + void AddButton( Button * button ); // 移除按钮 - bool removeButton( + bool RemoveButton( Button * button ); // 获取所有按钮 - const std::vector& getAllButtons() const; + const std::vector& GetAllButtons() const; protected: E2D_DISABLE_COPY(Menu); protected: - bool _enabled; - std::vector _buttons; + bool enabled_; + std::vector buttons_; }; @@ -1105,103 +1089,103 @@ public: virtual ~Canvas(); // 设置线条颜色 - void setLineColor( + void SetLineColor( const Color& color ); // 设置填充颜色 - void setFillColor( + void SetFillColor( const Color& color ); // 设置线条宽度 - void setStrokeWidth( + void SetStrokeWidth( float width ); // 设置线条相交样式 - void setStrokeStyle( + void SetStrokeStyle( Stroke strokeStyle ); // 获取线条颜色 - Color getLineColor() const; + Color GetLineColor() const; // 获取填充颜色 - Color getFillColor() const; + Color GetFillColor() const; // 获取线条宽度 - float getStrokeWidth() const; + float GetStrokeWidth() const; // 获取线条相交样式 - Stroke getStrokeStyle() const; + Stroke GetStrokeStyle() const; // 画直线 - void drawLine( + void DrawLine( const Point& begin, const Point& end ); // 画圆形边框 - void drawCircle( + void DrawCircle( const Point& center, float radius ); // 画椭圆形边框 - void drawEllipse( + void DrawEllipse( const Point& center, - float radiusX, - float radiusY + float radius_x, + float radius_y ); // 画矩形边框 - void drawRect( + void DrawRect( const Rect& rect ); // 画圆角矩形边框 - void drawRoundedRect( + void DrawRoundedRect( const Rect& rect, - float radiusX, - float radiusY + float radius_x, + float radius_y ); // 填充圆形 - void fillCircle( + void FillCircle( const Point& center, float radius ); // 填充椭圆形 - void fillEllipse( + void FillEllipse( const Point& center, - float radiusX, - float radiusY + float radius_x, + float radius_y ); // 填充矩形 - void fillRect( + void FillRect( const Rect& rect ); // 填充圆角矩形 - void fillRoundedRect( + void FillRoundedRect( const Rect& rect, - float radiusX, - float radiusY + float radius_x, + float radius_y ); protected: E2D_DISABLE_COPY(Canvas); protected: - float _strokeWidth; - Stroke _stroke; - ID2D1RenderTarget * _renderTarget; - ID2D1SolidColorBrush * _fillBrush; - ID2D1SolidColorBrush * _lineBrush; - ID2D1StrokeStyle * _strokeStyle; + float stroke_width_; + Stroke stroke_; + ID2D1RenderTarget * render_target_; + ID2D1SolidColorBrush * fill_brush_; + ID2D1SolidColorBrush * line_brush_; + ID2D1StrokeStyle * stroke_style_; }; } \ No newline at end of file diff --git a/core/e2dtool.h b/core/e2dtool.h index 6f127daa..e8f3afdd 100644 --- a/core/e2dtool.h +++ b/core/e2dtool.h @@ -11,40 +11,40 @@ class Random public: // 取得范围内的一个整型随机数 template - static inline T range(T min, T max) + static inline T Range(T min, T max) { - return e2d::Random::__randomInt(min, max); + return e2d::Random::RandomInt(min, max); } // 取得范围内的一个浮点数随机数 - static inline float range(float min, float max) + static inline float Range(float min, float max) { - return e2d::Random::__randomReal(min, max); + return e2d::Random::RandomReal(min, max); } // 取得范围内的一个浮点数随机数 - static inline double range(double min, double max) + static inline double Range(double min, double max) { - return e2d::Random::__randomReal(min, max); + return e2d::Random::RandomReal(min, max); } private: template - static T __randomInt(T min, T max) + static T RandomInt(T min, T max) { std::uniform_int_distribution dist(min, max); - return dist(Random::__getEngine()); + return dist(Random::GetEngine()); } template - static T __randomReal(T min, T max) + static T RandomReal(T min, T max) { std::uniform_real_distribution dist(min, max); - return dist(Random::__getEngine()); + return dist(Random::GetEngine()); } // 获取随机数产生器 - static std::default_random_engine &__getEngine(); + static std::default_random_engine &GetEngine(); }; @@ -58,7 +58,7 @@ public: Music(); explicit Music( - const e2d::String& filePath /* 音乐文件路径 */ + const e2d::String& file_path /* 音乐文件路径 */ ); explicit Music( @@ -68,52 +68,52 @@ public: virtual ~Music(); // 打开音乐文件 - bool open( - const e2d::String& filePath /* 音乐文件路径 */ + bool Open( + const e2d::String& file_path /* 音乐文件路径 */ ); // 打开音乐资源 - bool open( + bool Open( const Resource& res ); // 播放 - bool play( - int nLoopCount = 0 + bool Play( + int loopCount = 0 ); // 暂停 - void pause(); + void Pause(); // 继续 - void resume(); + void Resume(); // 停止 - void stop(); + void Stop(); // 关闭并回收资源 - void close(); + void Close(); // 是否正在播放 - bool isPlaying() const; + bool IsPlaying() const; // 设置音量 - bool setVolume( + bool SetVolume( float volume ); // 设置播放结束时的执行函数 - void setFuncOnEnd( + void SetCallbackOnEnd( const Function& func ); // 设置循环播放中每一次播放结束时的执行函数 - void setFuncOnLoopEnd( + void SetCallbackOnLoopEnd( const Function& func ); // 获取 IXAudio2SourceVoice 对象 - IXAudio2SourceVoice * getIXAudio2SourceVoice() const; + IXAudio2SourceVoice * GetSourceVoice() const; protected: bool _readMMIO(); @@ -121,27 +121,27 @@ protected: bool _resetFile(); bool _read( - BYTE* pBuffer, - DWORD dwSizeToRead + BYTE* buffer, + DWORD size_to_read ); bool _findMediaFileCch( - wchar_t* strDestPath, - int cchDest, - const wchar_t * strFilename + wchar_t* dest_path, + int cch_dest, + const wchar_t * file_name ); protected: - bool _opened; - DWORD _dwSize; - CHAR* _resBuffer; - BYTE* _waveData; - HMMIO _hmmio; - MMCKINFO _ck; - MMCKINFO _ckRiff; - WAVEFORMATEX* _wfx; - VoiceCallback _voiceCallback; - IXAudio2SourceVoice* _voice; + bool opened_; + DWORD size_; + CHAR* buffer_; + BYTE* wave_data_; + HMMIO hmmio_; + MMCKINFO ck_; + MMCKINFO ck_riff_; + WAVEFORMATEX* wfx_; + VoiceCallback callback_; + IXAudio2SourceVoice* voice_; }; @@ -150,92 +150,92 @@ class Player { public: // 获取播放器实例 - static Player * getInstance(); + static Player * GetInstance(); // 销毁实例 - static void destroyInstance(); + static void DestroyInstance(); // 预加载音乐资源 - bool preload( - const String& filePath /* 音乐文件路径 */ + bool Preload( + const String& file_path /* 音乐文件路径 */ ); // 播放音乐 - bool play( - const String& filePath, /* 音乐文件路径 */ - int nLoopCount = 0 /* 重复播放次数,设置 -1 为循环播放 */ + bool Play( + const String& file_path, /* 音乐文件路径 */ + int loop_count = 0 /* 重复播放次数,设置 -1 为循环播放 */ ); // 暂停音乐 - void pause( - const String& filePath /* 音乐文件路径 */ + void Pause( + const String& file_path /* 音乐文件路径 */ ); // 继续播放音乐 - void resume( - const String& filePath /* 音乐文件路径 */ + void Resume( + const String& file_path /* 音乐文件路径 */ ); // 停止音乐 - void stop( - const String& filePath /* 音乐文件路径 */ + void Stop( + const String& file_path /* 音乐文件路径 */ ); // 获取音乐播放状态 - bool isPlaying( - const String& filePath /* 音乐文件路径 */ + bool IsPlaying( + const String& file_path /* 音乐文件路径 */ ); // 预加载音乐资源 - bool preload( + bool Preload( const Resource& res /* 音乐资源 */ ); // 播放音乐 - bool play( + bool Play( const Resource& res, /* 音乐资源 */ - int nLoopCount = 0 /* 重复播放次数,设置 -1 为循环播放 */ + int loop_count = 0 /* 重复播放次数,设置 -1 为循环播放 */ ); // 暂停音乐 - void pause( + void Pause( const Resource& res /* 音乐资源 */ ); // 继续播放音乐 - void resume( + void Resume( const Resource& res /* 音乐资源 */ ); // 停止音乐 - void stop( + void Stop( const Resource& res /* 音乐资源 */ ); // 获取音乐播放状态 - bool isPlaying( + bool IsPlaying( const Resource& res /* 音乐资源 */ ); // 获取音量 - float getVolume(); + float GetVolume(); // 设置音量 - void setVolume( + void SetVolume( float volume /* 音量范围为 -224 ~ 224,0 是静音,1 是正常音量 */ ); // 暂停所有音乐 - void pauseAll(); + void PauseAll(); // 继续播放所有音乐 - void resumeAll(); + void ResumeAll(); // 停止所有音乐 - void stopAll(); + void StopAll(); // 清空音乐缓存 - void clearCache(); + void ClearCache(); protected: Player(); @@ -245,10 +245,10 @@ protected: E2D_DISABLE_COPY(Player); protected: - float _volume; - std::map _musicList; + float volume_; + std::map musics_; - static Player * _instance; + static Player * instance_; }; @@ -274,33 +274,33 @@ public: ); // 启动任务 - void start(); + void Start(); // 停止任务 - void stop(); + void Stop(); // 任务是否正在执行 - bool isRunning() const; + bool IsRunning() const; // 获取任务名称 - String getName() const; + const String& GetName() const; protected: // 执行任务 - void _update(); + void Update(); // 任务是否就绪 - bool _isReady() const; + bool IsReady() const; private: - bool _running; - bool _stopped; - int _runTimes; - int _totalTimes; - Duration _delay; - Time _lastTime; - String _name; - Function _callback; + bool running_; + bool stopped_; + int run_times_; + int total_times_; + String name_; + Duration delay_; + Time last_time_; + Function callback_; }; @@ -309,45 +309,45 @@ class Timer { public: // 获取定时器实例 - static Timer * getInstance(); + static Timer * GetInstance(); // 添加任务 - void addTask( + void AddTask( Task * task ); // 启动任务 - void startTasks( - const String& taskName + void StartTasks( + const String& task_name ); // 停止任务 - void stopTasks( - const String& taskName + void StopTasks( + const String& task_name ); // 移除任务 - void removeTasks( - const String& taskName + void RemoveTasks( + const String& task_name ); // 启动所有任务 - void startAllTasks(); + void StartAllTasks(); // 停止所有任务 - void stopAllTasks(); + void StopAllTasks(); // 移除所有任务 - void removeAllTasks(); + void RemoveAllTasks(); // 强制清空所有任务 - void clearAllTasks(); + void ClearAllTasks(); // 更新定时器 - void update(); + void Update(); // 刷新所有任务计时 - void updateTime(); + void UpdateTime(); private: Timer(); @@ -357,7 +357,7 @@ private: E2D_DISABLE_COPY(Timer); private: - std::vector _tasks; + std::vector tasks_; }; @@ -371,53 +371,53 @@ public: ); // 保存 int 类型的值 - void saveInt( + void SaveInt( int value /* 数据 */ ); // 保存 float 类型的值 - void saveDouble( + void SaveDouble( float value /* 数据 */ ); // 保存 bool 类型的值 - void saveBool( + void SaveBool( bool value /* 数据 */ ); // 保存 字符串 类型的值 - void saveString( + void SaveString( const String& value /* 数据 */ ); // 获取 int 类型的值 - // (若不存在则返回 defaultValue 参数的值) - int getInt( - int defaultValue /* 默认值 */ + // (若不存在则返回 default_value 参数的值) + int GetInt( + int default_value /* 默认值 */ ); // 获取 float 类型的值 - // (若不存在则返回 defaultValue 参数的值) - float getDouble( - float defaultValue /* 默认值 */ + // (若不存在则返回 default_value 参数的值) + float GetDouble( + float default_value /* 默认值 */ ); // 获取 bool 类型的值 - // (若不存在则返回 defaultValue 参数的值) - bool getBool( - bool defaultValue /* 默认值 */ + // (若不存在则返回 default_value 参数的值) + bool GetBool( + bool default_value /* 默认值 */ ); // 获取 字符串 类型的值 - // (若不存在则返回 defaultValue 参数的值) - String getString( - const String& defaultValue /* 默认值 */ + // (若不存在则返回 default_value 参数的值) + String GetString( + const String& default_value /* 默认值 */ ); protected: - String _key; - String _field; - const String _dataPath; + String key_; + String field_; + const String& data_path_; }; @@ -428,66 +428,66 @@ public: File(); File( - const String& fileName + const String& file_name ); virtual ~File(); // 打开文件 - bool open( - const String& fileName + bool Open( + const String& file_name ); // 文件或文件夹是否存在 - bool exists() const; + bool Exists() const; // 是否是文件夹 - bool isFolder() const; + bool IsFolder() const; // 删除文件 - bool del(); + bool Delete(); // 获取文件路径 - const String& getPath() const; + const String& GetPath() const; // 获取文件扩展名 - String getExtension() const; + String GetExtension() const; // 释放资源到临时文件目录 - static File extract( - int resNameId, /* 资源名称 */ - const String& resType, /* 资源类型 */ - const String& destFileName /* 目标文件名 */ + static File Extract( + int resource_name, /* 资源名称 */ + const String& resource_type, /* 资源类型 */ + const String& dest_file_name /* 目标文件名 */ ); // 添加文件搜索路径 - static void addSearchPath( + static void AddSearchPath( const String& path ); // 创建文件夹 - static bool createFolder( - const String& dirPath /* 文件夹路径 */ + static bool CreateFolder( + const String& dir_path /* 文件夹路径 */ ); // 弹出打开文件对话框 - static File showOpenDialog( + static File ShowOpenDialog( const String& title = L"打开", /* 对话框标题 */ const String& filter = L"" /* 筛选扩展名,例如 "*.jpg;*.jpeg" */ ); // 弹出保存文件对话框 - static File showSaveDialog( + static File ShowSaveDialog( const String& title = L"保存", /* 对话框标题 */ - const String& defFile = L"", /* 默认保存的文件名 */ - const String& defExt = L"" /* 默认追加的扩展名,例如 "txt" */ + const String& def_file = L"", /* 默认保存的文件名 */ + const String& def_ext = L"" /* 默认追加的扩展名,例如 "txt" */ ); protected: - DWORD _attributes; - String _fileName; + DWORD attributes_; + String file_path_; - static std::list _searchPaths; + static std::list search_paths_; }; @@ -498,16 +498,16 @@ class Path public: // 获取数据的默认保存路径 - static String getDataPath(); + static const String& GetDataPath(); // 获取临时文件目录 - static String getTempPath(); + static const String& GetTemporaryPath(); // 获取 LocalAppData 目录 - static String getLocalAppDataPath(); + static const String& GetLocalAppDataPath(); // 获取当前程序的运行路径 - static String getCurrentFilePath(); + static const String& GetExeFilePath(); }; } \ No newline at end of file diff --git a/core/e2dtransition.h b/core/e2dtransition.h index 74cbc39a..8169d3a7 100644 --- a/core/e2dtransition.h +++ b/core/e2dtransition.h @@ -23,38 +23,38 @@ public: virtual ~Transition(); // 场景过渡动画是否结束 - bool isDone(); + bool IsDone(); protected: // 初始化场景过渡动画 - virtual bool _init( + virtual bool Init( Game * game, Scene * prev ); // 更新场景过渡动画 - virtual void _update(); + virtual void Update(); // 渲染场景过渡动画 - virtual void _render(); + virtual void Draw(); // 停止场景过渡动画 - virtual void _stop(); + virtual void Stop(); // 重置场景过渡动画 - virtual void _reset() { }; + virtual void Reset() { }; protected: - bool _end; - float _duration; - float _delta; - Time _started; - Scene* _outScene; - Scene* _inScene; - ID2D1Layer * _outLayer; - ID2D1Layer * _inLayer; - D2D1_LAYER_PARAMETERS _outLayerParam; - D2D1_LAYER_PARAMETERS _inLayerParam; + bool done_; + float duration_; + float delta_; + Time started_; + Scene* out_scene_; + Scene* in_scene_; + ID2D1Layer * out_layer_; + ID2D1Layer * in_layer_; + D2D1_LAYER_PARAMETERS out_layer_param_; + D2D1_LAYER_PARAMETERS in_layer_param_; }; @@ -70,9 +70,9 @@ public: protected: // 更新动画 - virtual void _update() override; + virtual void Update() override; - virtual bool _init( + virtual bool Init( Game * game, Scene * prev ) override; @@ -90,9 +90,9 @@ public: ); protected: - virtual void _update() override; + virtual void Update() override; - virtual bool _init( + virtual bool Init( Game * game, Scene * prev ) override; @@ -110,9 +110,9 @@ public: ); protected: - virtual void _update() override; + virtual void Update() override; - virtual bool _init( + virtual bool Init( Game * game, Scene * prev ) override; @@ -131,19 +131,19 @@ public: ); protected: - virtual void _update() override; + virtual void Update() override; - virtual bool _init( + virtual bool Init( Game * game, Scene * prev ) override; - virtual void _reset() override; + virtual void Reset() override; protected: - Direction _direction; - Vector2 _posDelta; - Point _startPos; + Direction direction_; + Point pos_delta_; + Point start_pos_; }; } \ No newline at end of file diff --git a/project/vs2012/Easy2D.vcxproj b/project/vs2012/Easy2D.vcxproj index 19f6b7c2..233f75e2 100644 --- a/project/vs2012/Easy2D.vcxproj +++ b/project/vs2012/Easy2D.vcxproj @@ -35,8 +35,10 @@ - + + + diff --git a/project/vs2012/Easy2D.vcxproj.filters b/project/vs2012/Easy2D.vcxproj.filters index 614b698b..523f97b7 100644 --- a/project/vs2012/Easy2D.vcxproj.filters +++ b/project/vs2012/Easy2D.vcxproj.filters @@ -52,9 +52,6 @@ Action - - Action - Action @@ -241,5 +238,14 @@ Base + + Action + + + Action + + + Action + \ No newline at end of file diff --git a/project/vs2013/Easy2D.vcxproj b/project/vs2013/Easy2D.vcxproj index 0c351db4..679f7c27 100644 --- a/project/vs2013/Easy2D.vcxproj +++ b/project/vs2013/Easy2D.vcxproj @@ -179,8 +179,10 @@ - + + + diff --git a/project/vs2013/Easy2D.vcxproj.filters b/project/vs2013/Easy2D.vcxproj.filters index e7000d78..f04ff05f 100644 --- a/project/vs2013/Easy2D.vcxproj.filters +++ b/project/vs2013/Easy2D.vcxproj.filters @@ -52,9 +52,6 @@ Action - - Action - Action @@ -241,5 +238,14 @@ Base + + Action + + + Action + + + Action + \ No newline at end of file diff --git a/project/vs2017/Easy2D.vcxproj b/project/vs2017/Easy2D.vcxproj index 87b87b36..a3408b19 100644 --- a/project/vs2017/Easy2D.vcxproj +++ b/project/vs2017/Easy2D.vcxproj @@ -198,8 +198,10 @@ - + + + diff --git a/project/vs2017/Easy2D.vcxproj.filters b/project/vs2017/Easy2D.vcxproj.filters index 4c27e902..34fb4c3a 100644 --- a/project/vs2017/Easy2D.vcxproj.filters +++ b/project/vs2017/Easy2D.vcxproj.filters @@ -123,9 +123,6 @@ Action - - Action - Action @@ -234,6 +231,15 @@ Base + + Action + + + Action + + + Action +