Refactoring : Google C++ style

This commit is contained in:
Nomango 2018-09-04 22:42:34 +08:00
parent 637fe89e37
commit a67eefc0b4
84 changed files with 4156 additions and 4144 deletions

View File

@ -2,87 +2,87 @@
#include "..\e2dmanager.h" #include "..\e2dmanager.h"
e2d::Action::Action() e2d::Action::Action()
: _running(false) : running_(false)
, _done(false) , done_(false)
, _initialized(false) , initialized_(false)
, _target(nullptr) , target_(nullptr)
{ {
ActionManager::getInstance()->__add(this); ActionManager::GetInstance()->Add(this);
} }
e2d::Action::~Action() 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; initialized_ = false;
_done = false; done_ = false;
_started = Time::now(); 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; target_ = target;
_running = true; running_ = true;
this->reset(); this->Reset();
} }
void e2d::Action::_init() void e2d::Action::Init()
{ {
_initialized = true; initialized_ = true;
_started = Time::now(); 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()
{ {
} }

View File

@ -2,106 +2,106 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::Animate::Animate() e2d::Animate::Animate()
: _frameIndex(0) : frame_index_(0)
, _animation(nullptr) , animation_(nullptr)
{ {
} }
e2d::Animate::Animate(Animation * animation) e2d::Animate::Animate(Animation * animation)
: _frameIndex(0) : frame_index_(0)
, _animation(nullptr) , animation_(nullptr)
{ {
this->setAnimation(animation); this->SetAnimation(animation);
} }
e2d::Animate::~Animate() 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(); if (animation_) animation_->Release();
_animation = animation; animation_ = animation;
_animation->retain(); animation_->Retain();
} }
} }
void e2d::Animate::_init() void e2d::Animate::Init()
{ {
Action::_init(); Action::Init();
auto target = dynamic_cast<Sprite*>(_target); auto target = dynamic_cast<Sprite*>(target_);
if (target && _animation) if (target && animation_)
{ {
target->open(_animation->getFrames()[_frameIndex]); target->Open(animation_->GetFrames()[frame_index_]);
++_frameIndex; ++frame_index_;
} }
} }
void e2d::Animate::_update() void e2d::Animate::Update()
{ {
Action::_update(); Action::Update();
if (!_animation) if (!animation_)
{ {
this->stop(); this->Stop();
return; return;
} }
while ((Time::now() - _started).seconds() >= _animation->getInterval()) while ((Time::Now() - started_).Seconds() >= animation_->GetInterval())
{ {
auto& frames = _animation->getFrames(); auto& frames = animation_->GetFrames();
auto target = dynamic_cast<Sprite*>(_target); auto target = dynamic_cast<Sprite*>(target_);
if (target) if (target)
{ {
target->open(frames[_frameIndex]); target->Open(frames[frame_index_]);
} }
_started += Duration(_animation->getInterval()); started_ += Duration(animation_->GetInterval());
++_frameIndex; ++frame_index_;
if (_frameIndex == frames.size()) if (frame_index_ == frames.size())
{ {
this->stop(); this->Stop();
break; break;
} }
} }
} }
void e2d::Animate::_resetTime() void e2d::Animate::ResetTime()
{ {
Action::_resetTime(); Action::ResetTime();
} }
void e2d::Animate::reset() void e2d::Animate::Reset()
{ {
Action::reset(); Action::Reset();
_frameIndex = 0; 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; 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) if (animation)
{ {
return new (e2d::autorelease) Animate(animation); return new (e2d::autorelease) Animate(animation);

View File

@ -1,85 +1,85 @@
#include "..\e2daction.h" #include "..\e2daction.h"
e2d::Animation::Animation() e2d::Animation::Animation()
: _interval(1) : interval_(1)
{ {
} }
e2d::Animation::Animation(const std::vector<Image*>& frames) e2d::Animation::Animation(const Images& frames)
: _interval(1) : interval_(1)
{ {
this->add(frames); this->Add(frames);
} }
e2d::Animation::Animation(float interval) e2d::Animation::Animation(float interval)
: _interval(interval) : interval_(interval)
{ {
} }
e2d::Animation::Animation(float interval, const std::vector<Image*>& frames) e2d::Animation::Animation(float interval, const Images& frames)
: _interval(interval) : interval_(interval)
{ {
this->add(frames); this->Add(frames);
} }
e2d::Animation::~Animation() 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) if (frame)
{ {
_frames.push_back(frame); frames_.push_back(frame);
frame->retain(); frame->Retain();
} }
} }
void e2d::Animation::add(const std::vector<Image*>& frames) void e2d::Animation::Add(const Images& frames)
{ {
for (const auto &image : 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::Image*>& 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) if (animation)
{ {
for (const auto& frame : _frames) for (const auto& frame : frames_)
{ {
animation->add(frame); animation->Add(frame);
} }
} }
return animation; return animation;
} }
e2d::Animation * e2d::Animation::reverse() const e2d::Animation * e2d::Animation::Reverse() const
{ {
auto& oldFrames = this->getFrames(); auto& oldFrames = this->GetFrames();
std::vector<Image*> frames(oldFrames.size()); Images frames(oldFrames.size());
if (!oldFrames.empty()) 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);
} }

View File

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

26
core/Action/Callback.cpp Normal file
View File

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

View File

@ -1,46 +1,46 @@
#include "..\e2daction.h" #include "..\e2daction.h"
e2d::Delay::Delay(float duration) e2d::Delay::Delay(float duration)
: _delta(0) : delta_(0)
, _delay(std::max(duration, 0.f)) , 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(); Action::Reset();
_delta = 0; 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(); Action::ResetTime();
_started = Time::now() - Duration(_delta); started_ = Time::Now() - Duration(delta_);
} }

6
core/Action/FadeIn.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "..\e2daction.h"
e2d::FadeIn::FadeIn(float duration)
: OpacityTo(duration, 1)
{
}

6
core/Action/FadeOut.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "..\e2daction.h"
e2d::FadeOut::FadeOut(float duration)
: OpacityTo(duration, 0)
{
}

View File

@ -1,44 +1,44 @@
#include "..\e2daction.h" #include "..\e2daction.h"
e2d::FiniteTimeAction::FiniteTimeAction(float duration) e2d::FiniteTimeAction::FiniteTimeAction(float duration)
: _delta(0) : delta_(0)
, _duration(std::max(duration, 0.f)) , duration_(std::max(duration, 0.f))
{ {
} }
void e2d::FiniteTimeAction::reset() void e2d::FiniteTimeAction::Reset()
{ {
Action::reset(); Action::Reset();
_delta = 0; 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; delta_ = 1;
this->stop(); this->Stop();
} }
else 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(); Action::ResetTime();
_started = Time::now() - Duration(_delta * _duration); started_ = Time::Now() - Duration(delta_ * duration_);
} }

View File

@ -1,53 +1,53 @@
#include "..\e2daction.h" #include "..\e2daction.h"
#include "..\e2dnode.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) : FiniteTimeAction(duration)
, _deltaPos(vec) , delta_pos_(vec)
, _height(height) , height_(height)
, _jumps(jumps) , 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 frac = fmod(delta_ * jumps_, 1.f);
float x = _deltaPos.x * _delta; float x = delta_pos_.x * delta_;
float y = _height * 4 * frac * (1 - frac); float y = height_ * 4 * frac * (1 - frac);
y += _deltaPos.y * _delta; y += delta_pos_.y * delta_;
Point currentPos = _target->getPos(); Point currentPos = target_->GetPos();
Vector2 diff = currentPos - _prevPos; Point diff = currentPos - prev_pos_;
_startPos = diff + _startPos; start_pos_ = diff + start_pos_;
Point newPos = _startPos + Vector2(x, y); Point newPos = start_pos_ + Point(x, y);
_target->setPos(newPos); target_->SetPos(newPos);
_prevPos = newPos; prev_pos_ = newPos;
} }
} }

View File

@ -3,17 +3,17 @@
e2d::JumpTo::JumpTo(float duration, const Point & pos, float height, int jumps) e2d::JumpTo::JumpTo(float duration, const Point & pos, float height, int jumps)
: JumpBy(duration, Point(), height, 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(); JumpBy::Init();
_deltaPos = _endPos - _startPos; delta_pos_ = end_pos_ - start_pos_;
} }

View File

@ -2,29 +2,29 @@
#include "..\e2dmanager.h" #include "..\e2dmanager.h"
e2d::Loop::Loop(Action * action, int times /* = -1 */) e2d::Loop::Loop(Action * action, int times /* = -1 */)
: _action(action) : action_(action)
, _times(0) , times_(0)
, _totalTimes(times) , total_times_(times)
{ {
WARN_IF(action == nullptr, "Loop NULL pointer exception!"); WARN_IF(action == nullptr, "Loop NULL pointer exception!");
if (action) if (action)
{ {
_action = action; action_ = action;
_action->retain(); action_->Retain();
} }
} }
e2d::Loop::~Loop() 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 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 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_->target_ = target_;
_action->_init(); 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; 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 else
{ {
this->stop(); this->Stop();
} }
} }
void e2d::Loop::reset() void e2d::Loop::Reset()
{ {
Action::reset(); Action::Reset();
if (_action) _action->reset(); if (action_) action_->Reset();
_times = 0; times_ = 0;
} }
void e2d::Loop::_resetTime() void e2d::Loop::ResetTime()
{ {
if (_action) _action->_resetTime(); if (action_) action_->ResetTime();
} }

View File

@ -2,45 +2,45 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::MoveBy::MoveBy(float duration, Vector2 vector) e2d::MoveBy::MoveBy(float duration, Point vector)
: FiniteTimeAction(duration) : 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(); Point currentPos = target_->GetPos();
Vector2 diff = currentPos - _prevPos; Point diff = currentPos - prev_pos_;
_startPos = _startPos + diff; start_pos_ = start_pos_ + diff;
Point newPos = _startPos + (_deltaPos * _delta); Point newPos = start_pos_ + (delta_pos_ * delta_);
_target->setPos(newPos); 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_);
} }

View File

@ -2,18 +2,18 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::MoveTo::MoveTo(float duration, Point pos) 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(); MoveBy::Init();
_deltaPos = _endPos - _startPos; delta_pos_ = end_pos_ - start_pos_;
} }

View File

@ -5,35 +5,35 @@
e2d::OpacityBy::OpacityBy(float duration, float opacity) e2d::OpacityBy::OpacityBy(float duration, float opacity)
: FiniteTimeAction(duration) : 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_);
} }

View File

@ -5,16 +5,16 @@
e2d::OpacityTo::OpacityTo(float duration, float opacity) e2d::OpacityTo::OpacityTo(float duration, float opacity)
: OpacityBy(duration, 0) : 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(); OpacityBy::Init();
_deltaVal = _endVal - _startVal; delta_val_ = end_val_ - start_val_;
} }

View File

@ -5,35 +5,35 @@
e2d::RotateBy::RotateBy(float duration, float rotation) e2d::RotateBy::RotateBy(float duration, float rotation)
: FiniteTimeAction(duration) : 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_);
} }

View File

@ -5,16 +5,16 @@
e2d::RotateTo::RotateTo(float duration, float rotation) e2d::RotateTo::RotateTo(float duration, float rotation)
: RotateBy(duration, 0) : 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(); RotateBy::Init();
_deltaVal = _endVal - _startVal; delta_val_ = end_val_ - start_val_;
} }

View File

@ -5,44 +5,44 @@
e2d::ScaleBy::ScaleBy(float duration, float scale) e2d::ScaleBy::ScaleBy(float duration, float scale)
: FiniteTimeAction(duration) : FiniteTimeAction(duration)
{ {
_deltaX = scale; delta_x_ = scale;
_deltaY = 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) : FiniteTimeAction(duration)
{ {
_deltaX = scaleX; delta_x_ = scale_x;
_deltaY = scaleY; delta_y_ = scale_y;
} }
void e2d::ScaleBy::_init() void e2d::ScaleBy::Init()
{ {
FiniteTimeAction::_init(); FiniteTimeAction::Init();
if (_target) if (target_)
{ {
_startScaleX = _target->getScaleX(); start_scale_x_ = target_->GetScaleX();
_startScaleY = _target->getScaleY(); 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_);
} }

View File

@ -4,25 +4,25 @@
e2d::ScaleTo::ScaleTo(float duration, float scale) e2d::ScaleTo::ScaleTo(float duration, float scale)
: ScaleBy(duration, 0, 0) : ScaleBy(duration, 0, 0)
{ {
_endScaleX = scale; end_scale_x_ = scale;
_endScaleY = 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) : ScaleBy(duration, 0, 0)
{ {
_endScaleX = scaleX; end_scale_x_ = scale_x;
_endScaleY = scaleY; 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(); ScaleBy::Init();
_deltaX = _endScaleX - _startScaleX; delta_x_ = end_scale_x_ - start_scale_x_;
_deltaY = _endScaleY - _startScaleY; delta_y_ = end_scale_y_ - start_scale_y_;
} }

View File

@ -1,119 +1,119 @@
#include "..\e2daction.h" #include "..\e2daction.h"
e2d::Sequence::Sequence() e2d::Sequence::Sequence()
: _currIndex(0) : action_index_(0)
{ {
} }
e2d::Sequence::Sequence(const std::vector<Action*>& actions) e2d::Sequence::Sequence(const Actions& actions)
: _currIndex(0) : action_index_(0)
{ {
this->add(actions); this->Add(actions);
} }
e2d::Sequence::~Sequence() 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]; auto &action = actions_[action_index_];
action->_update(); action->Update();
if (action->_isDone()) if (action->IsDone())
{ {
++_currIndex; ++action_index_;
if (_currIndex == _actions.size()) if (action_index_ == actions_.size())
{ {
this->stop(); this->Stop();
} }
else else
{ {
_actions[_currIndex]->_init(); actions_[action_index_]->Init();
} }
} }
} }
void e2d::Sequence::reset() void e2d::Sequence::Reset()
{ {
Action::reset(); Action::Reset();
for (const auto& action : _actions) 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) if (action)
{ {
_actions.push_back(action); actions_.push_back(action);
action->retain(); action->Retain();
} }
} }
void e2d::Sequence::add(const std::vector<Action*>& actions) void e2d::Sequence::Add(const Actions& actions)
{ {
for (const auto &action : 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(); auto sequence = new (e2d::autorelease) Sequence();
for (const auto& action : _actions) for (const auto& action : actions_)
{ {
if (action) if (action)
{ {
sequence->add(action->clone()); sequence->Add(action->Clone());
} }
} }
return sequence; return sequence;
} }
e2d::Sequence * e2d::Sequence::reverse() const e2d::Sequence * e2d::Sequence::Reverse() const
{ {
auto sequence = new (e2d::autorelease) Sequence(); auto sequence = new (e2d::autorelease) Sequence();
if (sequence && !_actions.empty()) if (sequence && !actions_.empty())
{ {
std::vector<Action*> newActions(_actions.size()); std::vector<Action*> newActions(actions_.size());
for (auto iter = _actions.crbegin(), iterCrend = _actions.crend(); iter != iterCrend; ++iter) 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; return sequence;
} }

View File

@ -4,114 +4,114 @@ e2d::Spawn::Spawn()
{ {
} }
e2d::Spawn::Spawn(const std::vector<Action*>& actions) e2d::Spawn::Spawn(const Actions& actions)
{ {
this->add(actions); this->Add(actions);
} }
e2d::Spawn::~Spawn() 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->target_ = target_;
action->_init(); action->Init();
} }
} }
} }
void e2d::Spawn::_update() void e2d::Spawn::Update()
{ {
Action::_update(); Action::Update();
size_t doneNum = 0; size_t doneNum = 0;
for (const auto& action : _actions) for (const auto& action : actions_)
{ {
if (action->_isDone()) if (action->IsDone())
{ {
++doneNum; ++doneNum;
} }
else 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(); Action::Reset();
for (const auto& action : _actions) 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) if (action)
{ {
_actions.push_back(action); actions_.push_back(action);
action->retain(); action->Retain();
} }
} }
void e2d::Spawn::add(const std::vector<Action*>& actions) void e2d::Spawn::Add(const Actions& actions)
{ {
for (const auto &action : 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(); auto spawn = new (e2d::autorelease) Spawn();
for (const auto& action : _actions) for (const auto& action : actions_)
{ {
if (action) if (action)
{ {
spawn->add(action->clone()); spawn->Add(action->Clone());
} }
} }
return spawn; return spawn;
} }
e2d::Spawn * e2d::Spawn::reverse() const e2d::Spawn * e2d::Spawn::Reverse() const
{ {
auto spawn = new (e2d::autorelease) Spawn(); auto spawn = new (e2d::autorelease) Spawn();
if (spawn && !_actions.empty()) if (spawn && !actions_.empty())
{ {
std::vector<Action*> newActions(_actions.size()); std::vector<Action*> newActions(actions_.size());
for (auto iter = _actions.crbegin(), iterCrend = _actions.crend(); iter != iterCrend; ++iter) 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; return spawn;
} }

View File

@ -1,60 +1,60 @@
#include "..\e2dbase.h" #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; delete instance_;
_instance = nullptr; instance_ = nullptr;
} }
} }
IXAudio2 * e2d::Audio::getXAudio2()
{
return _xAudio2;
}
IXAudio2MasteringVoice * e2d::Audio::getMasteringVoice()
{
return _masteringVoice;
}
e2d::Audio::Audio() e2d::Audio::Audio()
: _xAudio2(nullptr) : x_audio2_(nullptr)
, _masteringVoice(nullptr) , mastering_voice_(nullptr)
{ {
::CoInitialize(nullptr); ::CoInitialize(nullptr);
ThrowIfFailed( ThrowIfFailed(
XAudio2Create(&_xAudio2, 0) XAudio2Create(&x_audio2_, 0)
); );
ThrowIfFailed( ThrowIfFailed(
_xAudio2->CreateMasteringVoice(&_masteringVoice) x_audio2_->CreateMasteringVoice(&mastering_voice_)
); );
} }
e2d::Audio::~Audio() e2d::Audio::~Audio()
{ {
if (_masteringVoice) if (mastering_voice_)
{ {
_masteringVoice->DestroyVoice(); mastering_voice_->DestroyVoice();
_masteringVoice = nullptr; mastering_voice_ = nullptr;
} }
SafeRelease(_xAudio2); SafeRelease(x_audio2_);
::CoUninitialize(); ::CoUninitialize();
} }
IXAudio2 * e2d::Audio::GetXAudio2()
{
return x_audio2_;
}
IXAudio2MasteringVoice * e2d::Audio::GetMasteringVoice()
{
return mastering_voice_;
}

View File

@ -11,7 +11,7 @@ void * operator new(size_t size, e2d::autorelease_t const &) E2D_NOEXCEPT
void* p = ::operator new(size, std::nothrow); void* p = ::operator new(size, std::nothrow);
if (p) if (p)
{ {
GC::getInstance()->autorelease(static_cast<Ref*>(p)); GC::GetInstance()->AutoRelease(static_cast<Ref*>(p));
} }
return 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; static GC instance_;
return &_instance; return &instance_;
} }
e2d::GC::GC() e2d::GC::GC()
: _notifyed(false) : notifyed_(false)
, _cleanup(false) , cleanup_(false)
, _pool() , pool_()
{ {
} }
e2d::GC::~GC() e2d::GC::~GC()
{ {
// <20>뇜杰唐뚤蹶 // <20>뇜杰唐뚤蹶
Game::getInstance()->clearAllScenes(); Game::GetInstance()->ClearAllScenes();
Timer::getInstance()->clearAllTasks(); Timer::GetInstance()->ClearAllTasks();
ActionManager::getInstance()->clearAll(); ActionManager::GetInstance()->ClearAll();
_cleanup = true; cleanup_ = true;
for (const auto& ref : _pool) for (const auto& ref : pool_)
{ {
delete ref; delete ref;
} }
_pool.clear(); pool_.clear();
_cleanup = false; cleanup_ = false;
// 헌뇜뻠닸 // 헌뇜뻠닸
Image::clearCache(); Image::ClearCache();
// 헌뇜데절 // 헌뇜데절
Player::destroyInstance(); Player::DestroyInstance();
Audio::destroyInstance(); Audio::DestroyInstance();
Renderer::destroyInstance(); Renderer::DestroyInstance();
Input::destroyInstance(); Input::DestroyInstance();
Window::destroyInstance(); Window::DestroyInstance();
Game::destroyInstance(); Game::DestroyInstance();
} }
void e2d::GC::flush() void e2d::GC::Flush()
{ {
if (!_notifyed) if (!notifyed_)
return; return;
_notifyed = false; notifyed_ = false;
for (auto iter = _pool.begin(); iter != _pool.end();) for (auto iter = pool_.begin(); iter != pool_.end();)
{ {
if ((*iter)->getRefCount() <= 0) if ((*iter)->GetRefCount() <= 0)
{ {
delete (*iter); delete (*iter);
iter = _pool.erase(iter); iter = pool_.erase(iter);
} }
else else
{ {
@ -82,22 +82,22 @@ void e2d::GC::flush()
} }
} }
void e2d::GC::autorelease(Ref * ref) void e2d::GC::AutoRelease(Ref * ref)
{ {
if (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; return;
if (ref) if (ref)
{ {
ref->release(); ref->Release();
_notifyed = true; notifyed_ = true;
} }
} }

View File

@ -6,39 +6,33 @@
#include <thread> #include <thread>
e2d::Game * e2d::Game::_instance = nullptr; e2d::Game * e2d::Game::instance_ = nullptr;
e2d::Game * e2d::Game::getInstance() e2d::Game * e2d::Game::GetInstance()
{ {
if (!_instance) if (!instance_)
_instance = new (std::nothrow) Game; instance_ = new (std::nothrow) Game;
return _instance; return instance_;
} }
void e2d::Game::destroyInstance() void e2d::Game::DestroyInstance()
{ {
if (_instance) if (instance_)
{ {
delete _instance; delete instance_;
_instance = nullptr; instance_ = nullptr;
} }
} }
e2d::Game::Game() e2d::Game::Game()
: _quit(true) : quit_(true)
, _paused(false) , paused_(false)
, _currScene(nullptr) , curr_scene_(nullptr)
, _nextScene(nullptr) , next_scene_(nullptr)
, _transition(nullptr) , transition_(nullptr)
, _scenes() , scenes_()
{ {
::CoInitialize(nullptr); ::CoInitialize(nullptr);
_window = Window::getInstance();
_input = Input::getInstance();
_renderer = Renderer::getInstance();
_timer = Timer::getInstance();
_actionManager = ActionManager::getInstance();
} }
e2d::Game::~Game() e2d::Game::~Game()
@ -46,46 +40,52 @@ e2d::Game::~Game()
::CoUninitialize(); ::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; const int minInterval = 5;
Time last = Time::now(); Time last = Time::Now();
HWND hWnd = _window->getHWnd(); HWND hWnd = window->GetHWnd();
::ShowWindow(hWnd, SW_SHOWNORMAL); ::ShowWindow(hWnd, SW_SHOWNORMAL);
::UpdateWindow(hWnd); ::UpdateWindow(hWnd);
_window->poll(); window->Poll();
updateScene(); UpdateScene();
while (!_quit) while (!quit_)
{ {
auto now = Time::now(); auto now = Time::Now();
auto dur = now - last; auto dur = now - last;
if (dur.milliseconds() > minInterval) if (dur.Milliseconds() > minInterval)
{ {
last = now; last = now;
_input->update(); input->Update();
if (!_paused) if (!paused_)
{ {
_timer->update(); timer->Update();
_actionManager->update(); action_manager->Update();
updateScene(); UpdateScene();
} }
drawScene(); DrawScene();
_window->poll(); window->Poll();
GC::getInstance()->flush(); GC::GetInstance()->Flush();
} }
else else
{ {
// ID2D1HwndRenderTarget 开启了垂直同步,在渲染时会等待显示器刷新, // ID2D1HwndRenderTarget 开启了垂直同步,在渲染时会等待显示器刷新,
// 它起到了非常稳定的延时作用,所以大部分时候不需要手动挂起线程进行延时。 // 它起到了非常稳定的延时作用,所以大部分时候不需要手动挂起线程进行延时。
// 下面的代码仅在一些情况下(例如窗口最小化时)挂起线程,防止占用过高 CPU 。 // 下面的代码仅在一些情况下(例如窗口最小化时)挂起线程,防止占用过高 CPU 。
int wait = minInterval - dur.milliseconds(); int wait = minInterval - dur.Milliseconds();
if (wait > 1) if (wait > 1)
{ {
std::this_thread::sleep_for(std::chrono::milliseconds(wait)); 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(); Timer::GetInstance()->UpdateTime();
_actionManager->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) if (!scene)
return; return;
// 保存下一场景的指针 // 保存下一场景的指针
if (_nextScene) _nextScene->release(); if (next_scene_) next_scene_->Release();
_nextScene = scene; next_scene_ = scene;
_nextScene->retain(); 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) if (!transition)
return; return;
pushScene(transition->_inScene, saveCurrentScene); PushScene(transition->in_scene_, save_current_scene);
if (_transition) if (transition_)
{ {
_transition->_stop(); transition_->Stop();
_transition->release(); transition_->Release();
} }
_transition = transition; transition_ = transition;
_transition->retain(); transition_->Retain();
// 初始化场景切换动画 // 初始化场景切换动画
if (!_transition->_init(this, _currScene)) if (!transition_->Init(this, curr_scene_))
{ {
WARN("Transition initialize failed!"); WARN("Transition initialize failed!");
_transition->release(); transition_->Release();
_transition = nullptr; 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; return nullptr;
} }
_nextScene = _scenes.top(); next_scene_ = scenes_.top();
_nextScene->release(); next_scene_->Release();
_scenes.pop(); scenes_.pop();
return _nextScene; return next_scene_;
} }
e2d::Scene * e2d::Game::popScene(Transition * transition) e2d::Scene * e2d::Game::PopScene(Transition * transition)
{ {
if (!transition) if (!transition)
return nullptr; return nullptr;
auto scene = popScene(); auto scene = PopScene();
if (scene) if (scene)
{ {
if (_transition) if (transition_)
{ {
_transition->_stop(); transition_->Stop();
_transition->release(); transition_->Release();
} }
_transition = transition; transition_ = transition;
_transition->retain(); transition_->Retain();
_transition->_inScene = scene; transition_->in_scene_ = scene;
_transition->_inScene->retain(); transition_->in_scene_->Retain();
// 初始化场景切换动画 // 初始化场景切换动画
if (!_transition->_init(this, _currScene)) if (!transition_->Init(this, curr_scene_))
{ {
WARN("Transition initialize failed!"); WARN("Transition initialize failed!");
_transition->release(); transition_->Release();
_transition = nullptr; transition_ = nullptr;
} }
} }
return scene; return scene;
} }
void e2d::Game::clearAllScenes() void e2d::Game::ClearAllScenes()
{ {
while (!_scenes.empty()) while (!scenes_.empty())
{ {
_scenes.top()->release(); scenes_.top()->Release();
_scenes.pop(); scenes_.pop();
} }
} }
e2d::Scene * e2d::Game::getCurrentScene() e2d::Scene * e2d::Game::GetCurrentScene()
{ {
return _currScene; return curr_scene_;
} }
const std::stack<e2d::Scene*>& e2d::Game::getSceneStack() const std::stack<e2d::Scene*>& 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_->Release();
_transition = nullptr; transition_ = nullptr;
} }
else else
{ {
@ -247,36 +247,36 @@ void e2d::Game::updateScene()
} }
} }
if (_nextScene) if (next_scene_)
{ {
if (_currScene) if (curr_scene_)
{ {
_currScene->onExit(); curr_scene_->OnExit();
if (_scenes.empty() || _scenes.top() != _currScene) if (scenes_.empty() || scenes_.top() != curr_scene_)
{ {
_currScene->release(); curr_scene_->Release();
} }
} }
_nextScene->onEnter(); next_scene_->OnEnter();
_currScene = _nextScene; curr_scene_ = next_scene_;
_nextScene = nullptr; 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();
} }

View File

@ -4,33 +4,33 @@
#pragma comment(lib, "dinput8.lib") #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) if (!instance_)
_instance = new (std::nothrow) Input; instance_ = new (std::nothrow) Input;
return _instance; return instance_;
} }
void e2d::Input::destroyInstance() void e2d::Input::DestroyInstance()
{ {
if (_instance) if (instance_)
{ {
delete _instance; delete instance_;
_instance = nullptr; instance_ = nullptr;
} }
} }
e2d::Input::Input() e2d::Input::Input()
: _directInput(false) : direct_input_(false)
, _keyboardDevice(false) , keyboard_device_(false)
, _mouseDevice(false) , mouse_device_(false)
{ {
::CoInitialize(nullptr); ::CoInitialize(nullptr);
ZeroMemory(_keyBuffer, sizeof(_keyBuffer)); ZeroMemory(key_buffer_, sizeof(key_buffer_));
ZeroMemory(&_mouseState, sizeof(_mouseState)); ZeroMemory(&mouse_state_, sizeof(mouse_state_));
// 初始化接口对象 // 初始化接口对象
ThrowIfFailed( ThrowIfFailed(
@ -38,135 +38,135 @@ e2d::Input::Input()
HINST_THISCOMPONENT, HINST_THISCOMPONENT,
DIRECTINPUT_VERSION, DIRECTINPUT_VERSION,
IID_IDirectInput8, IID_IDirectInput8,
(void**)&_directInput, (void**)&direct_input_,
nullptr nullptr
) )
); );
HWND hwnd = Window::getInstance()->getHWnd(); HWND hwnd = Window::GetInstance()->GetHWnd();
// 初始化键盘设备 // 初始化键盘设备
ThrowIfFailed( ThrowIfFailed(
_directInput->CreateDevice( direct_input_->CreateDevice(
GUID_SysKeyboard, GUID_SysKeyboard,
&_keyboardDevice, &keyboard_device_,
nullptr nullptr
) )
); );
_keyboardDevice->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); keyboard_device_->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
_keyboardDevice->SetDataFormat(&c_dfDIKeyboard); keyboard_device_->SetDataFormat(&c_dfDIKeyboard);
_keyboardDevice->Acquire(); keyboard_device_->Acquire();
_keyboardDevice->Poll(); keyboard_device_->Poll();
// 初始化鼠标设备 // 初始化鼠标设备
ThrowIfFailed( ThrowIfFailed(
_directInput->CreateDevice( direct_input_->CreateDevice(
GUID_SysMouse, GUID_SysMouse,
&_mouseDevice, &mouse_device_,
nullptr nullptr
) )
); );
_mouseDevice->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); mouse_device_->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
_mouseDevice->SetDataFormat(&c_dfDIMouse); mouse_device_->SetDataFormat(&c_dfDIMouse);
_mouseDevice->Acquire(); mouse_device_->Acquire();
_mouseDevice->Poll(); mouse_device_->Poll();
} }
e2d::Input::~Input() e2d::Input::~Input()
{ {
if (_keyboardDevice) if (keyboard_device_)
_keyboardDevice->Unacquire(); keyboard_device_->Unacquire();
if (_mouseDevice) if (mouse_device_)
_mouseDevice->Unacquire(); mouse_device_->Unacquire();
SafeRelease(_mouseDevice); SafeRelease(mouse_device_);
SafeRelease(_keyboardDevice); SafeRelease(keyboard_device_);
SafeRelease(_directInput); SafeRelease(direct_input_);
::CoUninitialize(); ::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)) if (FAILED(hr))
{ {
hr = _keyboardDevice->Acquire(); hr = keyboard_device_->Acquire();
while (hr == DIERR_INPUTLOST) while (hr == DIERR_INPUTLOST)
hr = _keyboardDevice->Acquire(); hr = keyboard_device_->Acquire();
} }
else 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)) if (FAILED(hr))
{ {
hr = _mouseDevice->Acquire(); hr = mouse_device_->Acquire();
while (hr == DIERR_INPUTLOST) while (hr == DIERR_INPUTLOST)
hr = _mouseDevice->Acquire(); hr = mouse_device_->Acquire();
} }
else 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<int>(key)] & 0x80) if (key_buffer_[static_cast<int>(key)] & 0x80)
return true; return true;
return false; return false;
} }
bool e2d::Input::isDown(MouseCode code) bool e2d::Input::IsDown(MouseCode code)
{ {
if (_mouseState.rgbButtons[static_cast<int>(code)] & 0x80) if (mouse_state_.rgbButtons[static_cast<int>(code)] & 0x80)
return true; return true;
return false; 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(); auto window = Window::GetInstance();
float dpi = window->getDpi(); float dpi = window->GetDpi();
POINT mousePos; POINT mousePos;
::GetCursorPos(&mousePos); ::GetCursorPos(&mousePos);
::ScreenToClient(window->getHWnd(), &mousePos); ::ScreenToClient(window->GetHWnd(), &mousePos);
return Point(mousePos.x * 96.f / dpi, mousePos.y * 96.f / dpi); return Point(mousePos.x * 96.f / dpi, mousePos.y * 96.f / dpi);
} }
float e2d::Input::getMouseDeltaX() float e2d::Input::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;
} }

View File

@ -3,53 +3,181 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::Renderer* e2d::Renderer::_instance = nullptr; e2d::Renderer* e2d::Renderer::instance_ = nullptr;
ID2D1Factory* e2d::Renderer::_factory = nullptr; ID2D1Factory* e2d::Renderer::factory_ = nullptr;
IWICImagingFactory* e2d::Renderer::_imagingFactory = nullptr; IWICImagingFactory* e2d::Renderer::imaging_factory_ = nullptr;
IDWriteFactory* e2d::Renderer::_writeFactory = nullptr; IDWriteFactory* e2d::Renderer::write_factory_ = nullptr;
ID2D1StrokeStyle* e2d::Renderer::_miterStrokeStyle = nullptr; ID2D1StrokeStyle* e2d::Renderer::miter_stroke_style_ = nullptr;
ID2D1StrokeStyle* e2d::Renderer::_bevelStrokeStyle = nullptr; ID2D1StrokeStyle* e2d::Renderer::bevel_stroke_style_ = nullptr;
ID2D1StrokeStyle* e2d::Renderer::_roundStrokeStyle = 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; delete instance_;
_instance = nullptr; instance_ = nullptr;
SafeRelease(_miterStrokeStyle); SafeRelease(miter_stroke_style_);
SafeRelease(_bevelStrokeStyle); SafeRelease(bevel_stroke_style_);
SafeRelease(_roundStrokeStyle); SafeRelease(round_stroke_style_);
SafeRelease(_factory); SafeRelease(factory_);
SafeRelease(_imagingFactory); SafeRelease(imaging_factory_);
SafeRelease(_writeFactory); SafeRelease(write_factory_);
} }
} }
e2d::Renderer::Renderer() e2d::Renderer::Renderer()
: _showFps(false) : show_fps_(false)
, _lastRenderTime(Time::now()) , last_render_time_(Time::Now())
, _renderTimes(0) , render_times_(0)
, _fpsFormat(nullptr) , fps_text_format_(nullptr)
, _fpsLayout(nullptr) , fps_text_layout_(nullptr)
, _renderTarget(nullptr) , render_target_(nullptr)
, _solidBrush(nullptr) , solid_brush_(nullptr)
, _textRenderer(nullptr) , text_renderer_(nullptr)
, _clearColor(D2D1::ColorF(D2D1::ColorF::Black)) , clear_color_(D2D1::ColorF(D2D1::ColorF::Black))
{ {
::CoInitialize(nullptr); ::CoInitialize(nullptr);
}
HWND hWnd = Window::getInstance()->getHWnd(); e2d::Renderer::~Renderer()
{
SafeRelease(fps_text_format_);
SafeRelease(fps_text_layout_);
SafeRelease(text_renderer_);
SafeRelease(solid_brush_);
SafeRelease(render_target_);
::CoUninitialize();
}
void e2d::Renderer::BeginDraw()
{
auto render_target = GetRenderTarget();
render_target->BeginDraw();
// 使用背景色清空屏幕
render_target->Clear(clear_color_);
}
void e2d::Renderer::EndDraw()
{
if (show_fps_)
{
int duration = (Time::Now() - last_render_time_).Milliseconds();
++render_times_;
if (duration >= 100)
{
String fpsText = String::Format(L"FPS: %.1f", (1000.f / duration * render_times_));
last_render_time_ = Time::Now();
render_times_ = 0;
if (!fps_text_format_)
{
ThrowIfFailed(
GetWriteFactory()->CreateTextFormat(
L"",
nullptr,
DWRITE_FONT_WEIGHT_NORMAL,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
20,
L"",
&fps_text_format_
)
);
ThrowIfFailed(
fps_text_format_->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP)
);
}
SafeRelease(fps_text_layout_);
ThrowIfFailed(
GetWriteFactory()->CreateTextLayout(
(const WCHAR *)fpsText,
(UINT32)fpsText.GetLength(),
fps_text_format_,
0,
0,
&fps_text_layout_
)
);
}
if (fps_text_layout_)
{
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),
1.5f,
D2D1_LINE_JOIN_ROUND
);
ThrowIfFailed(
fps_text_layout_->Draw(nullptr, text_renderer_, 10, 0)
);
}
}
// 终止渲染
HRESULT hr = render_target_->EndDraw();
if (hr == D2DERR_RECREATE_TARGET)
{
// 如果 Direct3D 设备在执行过程中消失,将丢弃当前的设备相关资源
// 并在下一次调用时重建资源
hr = S_OK;
SafeRelease(fps_text_format_);
SafeRelease(fps_text_layout_);
SafeRelease(text_renderer_);
SafeRelease(solid_brush_);
SafeRelease(render_target_);
}
if (FAILED(hr))
{
throw SystemException("Device loss recovery failed");
}
}
e2d::E2DTextRenderer * e2d::Renderer::GetTextRenderer()
{
if (!text_renderer_)
{
// 创建自定义的文字渲染器
ThrowIfFailed(
E2DTextRenderer::Create(
&text_renderer_,
GetFactory(),
GetRenderTarget(),
GetSolidBrush()
)
);
}
return text_renderer_;
}
ID2D1HwndRenderTarget * e2d::Renderer::GetRenderTarget()
{
if (!render_target_)
{
HWND hWnd = Window::GetInstance()->GetHWnd();
RECT rc; RECT rc;
GetClientRect(hWnd, &rc); GetClientRect(hWnd, &rc);
@ -62,177 +190,69 @@ e2d::Renderer::Renderer()
// 创建设备相关资源。这些资源应在 Direct2D 设备消失时重建 // 创建设备相关资源。这些资源应在 Direct2D 设备消失时重建
// 创建一个 Direct2D 渲染目标 // 创建一个 Direct2D 渲染目标
ThrowIfFailed( ThrowIfFailed(
getFactory()->CreateHwndRenderTarget( GetFactory()->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(), D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties( D2D1::HwndRenderTargetProperties(
hWnd, hWnd,
size, size,
D2D1_PRESENT_OPTIONS_NONE), D2D1_PRESENT_OPTIONS_NONE),
&_renderTarget &render_target_
) )
); );
}
return render_target_;
}
// 创建画刷 ID2D1SolidColorBrush * e2d::Renderer::GetSolidBrush()
{
if (!solid_brush_)
{
ThrowIfFailed( ThrowIfFailed(
_renderTarget->CreateSolidColorBrush( GetRenderTarget()->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::White), D2D1::ColorF(D2D1::ColorF::White),
&_solidBrush &solid_brush_
)
);
// 创建自定义的文字渲染器
ThrowIfFailed(
TextRenderer::Create(
&_textRenderer,
getFactory(),
_renderTarget,
_solidBrush
)
);
}
e2d::Renderer::~Renderer()
{
SafeRelease(_fpsFormat);
SafeRelease(_fpsLayout);
SafeRelease(_textRenderer);
SafeRelease(_solidBrush);
SafeRelease(_renderTarget);
::CoUninitialize();
}
void e2d::Renderer::beginDraw()
{
// 开始渲染
_renderTarget->BeginDraw();
// 使用背景色清空屏幕
_renderTarget->Clear(_clearColor);
}
void e2d::Renderer::endDraw()
{
if (_showFps)
{
int duration = (Time::now() - _lastRenderTime).milliseconds();
++_renderTimes;
if (duration >= 100)
{
String fpsText = String::format(L"FPS: %.1f", (1000.f / duration * _renderTimes));
_lastRenderTime = Time::now();
_renderTimes = 0;
if (!_fpsFormat)
{
ThrowIfFailed(
getWriteFactory()->CreateTextFormat(
L"",
nullptr,
DWRITE_FONT_WEIGHT_NORMAL,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
20,
L"",
&_fpsFormat
)
);
ThrowIfFailed(
_fpsFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP)
);
}
SafeRelease(_fpsLayout);
ThrowIfFailed(
getWriteFactory()->CreateTextLayout(
(const WCHAR *)fpsText,
(UINT32)fpsText.length(),
_fpsFormat,
0,
0,
&_fpsLayout
) )
); );
} }
return solid_brush_;
if (_fpsLayout)
{
_renderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
_solidBrush->SetOpacity(1.0f);
_textRenderer->SetTextStyle(
D2D1::ColorF(D2D1::ColorF::White),
TRUE,
D2D1::ColorF(D2D1::ColorF::Black, 0.4f),
1.5f,
D2D1_LINE_JOIN_ROUND
);
ThrowIfFailed(
_fpsLayout->Draw(nullptr, _textRenderer, 10, 0)
);
}
}
// 终止渲染
HRESULT hr = _renderTarget->EndDraw();
if (hr == D2DERR_RECREATE_TARGET)
{
// 如果 Direct3D 设备在执行过程中消失,将丢弃当前的设备相关资源
// 并在下一次调用时重建资源
hr = S_OK;
SafeRelease(_fpsFormat);
SafeRelease(_fpsLayout);
SafeRelease(_textRenderer);
SafeRelease(_solidBrush);
SafeRelease(_renderTarget);
}
if (FAILED(hr))
{
throw SystemException("Device loss recovery failed");
}
} }
e2d::Color e2d::Renderer::getBackgroundColor() e2d::Color e2d::Renderer::GetBackgroundColor()
{ {
return _clearColor; return clear_color_;
} }
void e2d::Renderer::setBackgroundColor(Color color) void e2d::Renderer::SetBackgroundColor(const Color& color)
{ {
_clearColor = (D2D1_COLOR_F)color; clear_color_ = (D2D1_COLOR_F)color;
} }
void e2d::Renderer::showFps(bool show) void e2d::Renderer::ShowFps(bool show)
{ {
_showFps = show; show_fps_ = show;
} }
ID2D1Factory * e2d::Renderer::getFactory() ID2D1Factory * e2d::Renderer::GetFactory()
{ {
if (!_factory) if (!factory_)
{ {
::CoInitialize(nullptr); ::CoInitialize(nullptr);
ThrowIfFailed( ThrowIfFailed(
D2D1CreateFactory( D2D1CreateFactory(
D2D1_FACTORY_TYPE_SINGLE_THREADED, D2D1_FACTORY_TYPE_SINGLE_THREADED,
&_factory &factory_
) )
); );
::CoUninitialize(); ::CoUninitialize();
} }
return _factory; return factory_;
} }
IWICImagingFactory * e2d::Renderer::getImagingFactory() IWICImagingFactory * e2d::Renderer::GetImagingFactory()
{ {
if (!_imagingFactory) if (!imaging_factory_)
{ {
::CoInitialize(nullptr); ::CoInitialize(nullptr);
@ -242,18 +262,18 @@ IWICImagingFactory * e2d::Renderer::getImagingFactory()
nullptr, nullptr,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory, IID_IWICImagingFactory,
reinterpret_cast<void**>(&_imagingFactory) reinterpret_cast<void**>(&imaging_factory_)
) )
); );
::CoUninitialize(); ::CoUninitialize();
} }
return _imagingFactory; return imaging_factory_;
} }
IDWriteFactory * e2d::Renderer::getWriteFactory() IDWriteFactory * e2d::Renderer::GetWriteFactory()
{ {
if (!_writeFactory) if (!write_factory_)
{ {
::CoInitialize(nullptr); ::CoInitialize(nullptr);
@ -261,21 +281,21 @@ IDWriteFactory * e2d::Renderer::getWriteFactory()
DWriteCreateFactory( DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED, DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory), __uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(&_writeFactory) reinterpret_cast<IUnknown**>(&write_factory_)
) )
); );
::CoUninitialize(); ::CoUninitialize();
} }
return _writeFactory; return write_factory_;
} }
ID2D1StrokeStyle * e2d::Renderer::getMiterStrokeStyle() ID2D1StrokeStyle * e2d::Renderer::GetMiterStrokeStyle()
{ {
if (!_miterStrokeStyle) if (!miter_stroke_style_)
{ {
ThrowIfFailed( ThrowIfFailed(
getFactory()->CreateStrokeStyle( GetFactory()->CreateStrokeStyle(
D2D1::StrokeStyleProperties( D2D1::StrokeStyleProperties(
D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT,
D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT,
@ -286,19 +306,19 @@ ID2D1StrokeStyle * e2d::Renderer::getMiterStrokeStyle()
0.0f), 0.0f),
nullptr, nullptr,
0, 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( ThrowIfFailed(
getFactory()->CreateStrokeStyle( GetFactory()->CreateStrokeStyle(
D2D1::StrokeStyleProperties( D2D1::StrokeStyleProperties(
D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT,
D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT,
@ -309,19 +329,19 @@ ID2D1StrokeStyle * e2d::Renderer::getBevelStrokeStyle()
0.0f), 0.0f),
nullptr, nullptr,
0, 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( ThrowIfFailed(
getFactory()->CreateStrokeStyle( GetFactory()->CreateStrokeStyle(
D2D1::StrokeStyleProperties( D2D1::StrokeStyleProperties(
D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT,
D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT,
@ -332,9 +352,9 @@ ID2D1StrokeStyle * e2d::Renderer::getRoundStrokeStyle()
0.0f), 0.0f),
nullptr, nullptr,
0, 0,
&_roundStrokeStyle &round_stroke_style_
) )
); );
} }
return _roundStrokeStyle; return round_stroke_style_;
} }

View File

@ -8,36 +8,36 @@
#define REGISTER_CLASS L"Easy2DApp" #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) if (!instance_)
_instance = new (std::nothrow) Window; instance_ = new (std::nothrow) Window;
return _instance; return instance_;
} }
void e2d::Window::destroyInstance() void e2d::Window::DestroyInstance()
{ {
if (_instance) if (instance_)
{ {
delete _instance; delete instance_;
_instance = nullptr; instance_ = nullptr;
} }
} }
e2d::Window::Window() e2d::Window::Window()
: _hWnd(nullptr) : hWnd_(nullptr)
, _width(640) , width_(640)
, _height(480) , height_(480)
, _title(L"Easy2D Game") , title_(L"Easy2D Game")
, _iconID(0) , icon_id_(0)
, _dpi(0.f) , dpi_(0.f)
{ {
::CoInitialize(nullptr); ::CoInitialize(nullptr);
// 获取系统 DPI // 获取系统 DPI
_dpi = static_cast<float>(::GetDpiForSystem()); dpi_ = static_cast<float>(::GetDpiForSystem());
} }
e2d::Window::~Window() e2d::Window::~Window()
@ -47,15 +47,15 @@ e2d::Window::~Window()
::FreeConsole(); ::FreeConsole();
// 关闭窗口 // 关闭窗口
if (_hWnd) if (hWnd_)
::DestroyWindow(_hWnd); ::DestroyWindow(hWnd_);
::CoUninitialize(); ::CoUninitialize();
} }
bool e2d::Window::createMutex(const String & mutex) bool e2d::Window::CheckMutex(const String & mutex)
{ {
if (mutex.isEmpty()) if (mutex.IsEmpty())
return false; return false;
HANDLE hMutex = ::CreateMutex(nullptr, TRUE, LPCWSTR(L"Easy2DApp-" + mutex)); HANDLE hMutex = ::CreateMutex(nullptr, TRUE, LPCWSTR(L"Easy2DApp-" + mutex));
@ -70,10 +70,10 @@ bool e2d::Window::createMutex(const String & mutex)
// 关闭进程互斥体 // 关闭进程互斥体
::CloseHandle(hMutex); ::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) if (hProgramWnd)
{ {
// 获取窗口显示状态 // 获取窗口显示状态
@ -90,10 +90,10 @@ bool e2d::Window::createMutex(const String & mutex)
return true; return true;
} }
e2d::Rect e2d::Window::_locate(int width, int height) e2d::Rect e2d::Window::Locate(int width, int height)
{ {
Rect result; 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 maxWidth = ::GetSystemMetrics(SM_CXSCREEN);
int maxHeight = ::GetSystemMetrics(SM_CYSCREEN); int maxHeight = ::GetSystemMetrics(SM_CYSCREEN);
@ -103,7 +103,7 @@ e2d::Rect e2d::Window::_locate(int width, int height)
height = static_cast<int>(wRECT.bottom - wRECT.top); height = static_cast<int>(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); width = std::min(width, maxWidth);
height = std::min(height, maxHeight); 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))); 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); ::TranslateMessage(&msg_);
::DispatchMessage(&_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 }; WNDCLASSEX wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEX); wcex.cbSize = sizeof(WNDCLASSEX);
@ -162,11 +162,11 @@ HWND e2d::Window::getHWnd()
wcex.lpszMenuName = nullptr; wcex.lpszMenuName = nullptr;
wcex.hCursor = ::LoadCursor(nullptr, IDC_ARROW); wcex.hCursor = ::LoadCursor(nullptr, IDC_ARROW);
if (_iconID != 0) if (icon_id_ != 0)
{ {
wcex.hIcon = (HICON)::LoadImage( wcex.hIcon = (HICON)::LoadImage(
HINST_THISCOMPONENT, HINST_THISCOMPONENT,
MAKEINTRESOURCE(_iconID), MAKEINTRESOURCE(icon_id_),
IMAGE_ICON, IMAGE_ICON,
0, 0,
0, 0,
@ -178,13 +178,13 @@ HWND e2d::Window::getHWnd()
RegisterClassEx(&wcex); RegisterClassEx(&wcex);
// 计算窗口大小 // 计算窗口大小
Rect clientRect = _locate(_width, _height); Rect clientRect = Locate(width_, height_);
// 创建窗口 // 创建窗口
_hWnd = ::CreateWindowEx( hWnd_ = ::CreateWindowEx(
NULL, NULL,
REGISTER_CLASS, REGISTER_CLASS,
(LPCTSTR)_title, (LPCTSTR)title_,
WINDOW_STYLE, WINDOW_STYLE,
int(clientRect.origin.x), int(clientRect.origin.x),
int(clientRect.origin.y), int(clientRect.origin.y),
@ -196,10 +196,10 @@ HWND e2d::Window::getHWnd()
this this
); );
if (_hWnd) if (hWnd_)
{ {
// 禁用输入法 // 禁用输入法
setTypewritingEnabled(false); SetTypewritingEnabled(false);
// 禁用控制台关闭按钮 // 禁用控制台关闭按钮
HWND consoleHWnd = ::GetConsoleWindow(); HWND consoleHWnd = ::GetConsoleWindow();
if (consoleHWnd) if (consoleHWnd)
@ -214,22 +214,22 @@ HWND e2d::Window::getHWnd()
throw SystemException("Create window failed"); 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; return;
_width = width; width_ = width;
_height = height; height_ = height;
if (_hWnd) if (hWnd_)
{ {
Rect wRect = _locate(width, height); Rect wRect = Locate(width, height);
::MoveWindow( ::MoveWindow(
_hWnd, hWnd_,
int(wRect.origin.x), int(wRect.origin.x),
int(wRect.origin.y), int(wRect.origin.y),
int(wRect.size.width), 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; title_ = title;
if (_hWnd) 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; this->icon_id_ = icon_id;
if (_hWnd) 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_BIG, (LPARAM)hIcon);
::SendMessage(_hWnd, WM_SETICON, ICON_SMALL, (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; LPCWSTR pCursorName = nullptr;
switch (cursor) switch (cursor)
@ -293,7 +293,7 @@ void e2d::Window::setCursor(Cursor cursor)
::SetCursor(hCursor); ::SetCursor(hCursor);
} }
void e2d::Window::setConsoleEnabled(bool enabled) void e2d::Window::SetConsoleEnabled(bool enabled)
{ {
// 查找已存在的控制台句柄 // 查找已存在的控制台句柄
HWND hwnd = ::GetConsoleWindow(); 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; static HIMC hImc = nullptr;
@ -338,7 +338,7 @@ void e2d::Window::setTypewritingEnabled(bool enabled)
{ {
if (hImc != nullptr) if (hImc != nullptr)
{ {
::ImmAssociateContext(getHWnd(), hImc); ::ImmAssociateContext(GetHWnd(), hImc);
hImc = nullptr; hImc = nullptr;
} }
} }
@ -346,48 +346,48 @@ void e2d::Window::setTypewritingEnabled(bool enabled)
{ {
if (hImc == nullptr) 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; UINT type = 0;
switch (style) switch (style)
{ {
case e2d::Window::Popup::Information: case PopupStyle::Info:
type = MB_ICONINFORMATION; type = MB_ICONINFORMATION;
break; break;
case e2d::Window::Popup::Warning: case PopupStyle::Warning:
type = MB_ICONWARNING; type = MB_ICONWARNING;
break; break;
case e2d::Window::Popup::Error: case PopupStyle::Error:
type = MB_ICONERROR; type = MB_ICONERROR;
break; break;
default: default:
break; break;
} }
if (hasCancel) if (has_cancel)
{ {
type |= MB_OKCANCEL; type |= MB_OKCANCEL;
} }
Game::getInstance()->pause(); Game::GetInstance()->Pause();
int ret = ::MessageBox(_hWnd, (LPCWSTR)text, (LPCWSTR)title, type); int ret = ::MessageBox(hWnd_, (LPCWSTR)text, (LPCWSTR)title, type);
Game::getInstance()->resume(); Game::GetInstance()->Resume();
return ret == IDOK; 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; 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; Window *window = (Window *)pcs->lpCreateParams;
::SetWindowLongPtrW( ::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_MOUSEMOVE:
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
{ {
auto game = Game::getInstance(); auto game = Game::GetInstance();
if (game->isTransitioning()) if (game->IsTransitioning())
break; 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; result = 0;
@ -440,13 +440,13 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_KEYDOWN: case WM_KEYDOWN:
case WM_KEYUP: case WM_KEYUP:
{ {
auto game = Game::getInstance(); auto game = Game::GetInstance();
if (game->isTransitioning()) if (game->IsTransitioning())
break; 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; result = 0;
@ -456,19 +456,19 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// 处理窗口大小变化消息 // 处理窗口大小变化消息
case WM_SIZE: case WM_SIZE:
{ {
UINT width = LOWORD(lParam); UINT width = LOWORD(l_param);
UINT height = HIWORD(lParam); UINT height = HIWORD(l_param);
if (wParam == SIZE_RESTORED) if (w_param == SIZE_RESTORED)
{ {
window->_width = static_cast<int>(width * 96.f / window->_dpi); window->width_ = static_cast<int>(width * 96.f / window->dpi_);
window->_height = static_cast<int>(height * 96.f / window->_dpi); window->height_ = static_cast<int>(height * 96.f / window->dpi_);
} }
// 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染 // 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染
// 目标适当。它可能会调用失败,但是这里可以忽略有可能的 // 目标适当。它可能会调用失败,但是这里可以忽略有可能的
// 错误,因为这个错误将在下一次调用 EndDraw 时产生 // 错误,因为这个错误将在下一次调用 EndDraw 时产生
auto pRT = Renderer::getInstance()->getRenderTarget(); auto pRT = Renderer::GetInstance()->GetRenderTarget();
if (pRT) if (pRT)
{ {
pRT->Resize(D2D1::SizeU(width, height)); 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: case WM_SETTEXT:
{ {
window->_title = (const wchar_t*)lParam; window->title_ = (const wchar_t*)l_param;
} }
break; break;
@ -496,7 +496,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// 重绘窗口 // 重绘窗口
case WM_PAINT: case WM_PAINT:
{ {
Game::getInstance()->drawScene(); Game::GetInstance()->DrawScene();
ValidateRect(hWnd, nullptr); ValidateRect(hWnd, nullptr);
} }
result = 0; result = 0;
@ -506,11 +506,11 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// 窗口关闭消息 // 窗口关闭消息
case WM_CLOSE: case WM_CLOSE:
{ {
auto game = Game::getInstance(); auto game = Game::GetInstance();
auto currScene = game->getCurrentScene(); auto currScene = game->GetCurrentScene();
if (!currScene || currScene->onCloseWindow()) if (!currScene || currScene->OnCloseWindow())
{ {
game->quit(); game->Quit();
} }
} }
result = 0; result = 0;
@ -530,7 +530,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (!hasHandled) if (!hasHandled)
{ {
result = DefWindowProc(hWnd, uMsg, wParam, lParam); result = DefWindowProc(hWnd, msg, w_param, l_param);
} }
} }
return result; return result;

View File

@ -3,103 +3,103 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::Collider::Collider(Node * parent) e2d::Collider::Collider(Node * parent)
: _visible(true) : visible_(true)
, _color(Color::Blue, 0.6f) , border_color_(Color::Blue, 0.6f)
, _parentNode(parent) , parent_node_(parent)
, _geometry(nullptr) , geometry_(nullptr)
, _enabled(true) , enabled_(true)
, _shape(Collider::Shape::None) , shape_(Collider::Shape::None)
, _notify(true) , notify_(true)
{ {
} }
e2d::Collider::~Collider() 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; return;
_shape = shape; shape_ = shape;
if (shape == Shape::None) if (shape == Shape::None)
{ {
SafeRelease(_geometry); SafeRelease(geometry_);
CollisionManager::getInstance()->__removeCollider(this); CollisionManager::GetInstance()->RemoveCollider(this);
} }
else else
{ {
this->recreate(); this->Recreate();
CollisionManager::getInstance()->__addCollider(this); 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); 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; D2D1_GEOMETRY_RELATION relation;
_geometry->CompareWithGeometry( geometry_->CompareWithGeometry(
collider->_geometry, collider->geometry_,
D2D1::Matrix3x2F::Identity(), D2D1::Matrix3x2F::Identity(),
&relation &relation
); );
@ -110,66 +110,66 @@ e2d::Collider::Relation e2d::Collider::getRelationWith(Collider * collider) cons
return Relation::Unknown; 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; return;
SafeRelease(_geometry); SafeRelease(geometry_);
auto factory = Renderer::getFactory(); auto factory = Renderer::GetFactory();
switch (_shape) switch (shape_)
{ {
case Shape::Rect: case Shape::Rect:
{ {
ID2D1RectangleGeometry* rectangle = nullptr; ID2D1RectangleGeometry* rectangle = nullptr;
factory->CreateRectangleGeometry( factory->CreateRectangleGeometry(
D2D1::RectF(0, 0, _parentNode->getRealWidth(), _parentNode->getRealHeight()), D2D1::RectF(0, 0, parent_node_->GetRealWidth(), parent_node_->GetRealHeight()),
&rectangle &rectangle
); );
_geometry = rectangle; geometry_ = rectangle;
} }
break; break;
case Shape::Circle: case Shape::Circle:
{ {
float minSide = std::min(_parentNode->getRealWidth(), _parentNode->getRealHeight()); float minSide = std::min(parent_node_->GetRealWidth(), parent_node_->GetRealHeight());
ID2D1EllipseGeometry* circle = nullptr; ID2D1EllipseGeometry* circle = nullptr;
factory->CreateEllipseGeometry( factory->CreateEllipseGeometry(
D2D1::Ellipse( D2D1::Ellipse(
D2D1::Point2F( D2D1::Point2F(
_parentNode->getRealWidth() / 2, parent_node_->GetRealWidth() / 2,
_parentNode->getRealHeight() / 2 parent_node_->GetRealHeight() / 2
), ),
minSide / 2, minSide / 2,
minSide / 2 minSide / 2
), ),
&circle &circle
); );
_geometry = circle; geometry_ = circle;
} }
break; break;
case Shape::Ellipse: case Shape::Ellipse:
{ {
float halfWidth = _parentNode->getWidth() / 2, float halfWidth = parent_node_->GetWidth() / 2,
halfHeight = _parentNode->getHeight() / 2; halfHeight = parent_node_->GetHeight() / 2;
ID2D1EllipseGeometry* ellipse = nullptr; ID2D1EllipseGeometry* ellipse = nullptr;
factory->CreateEllipseGeometry( factory->CreateEllipseGeometry(
@ -181,17 +181,17 @@ void e2d::Collider::recreate()
halfHeight), halfHeight),
&ellipse &ellipse
); );
_geometry = ellipse; geometry_ = ellipse;
} }
break; break;
} }
ID2D1TransformedGeometry * transformed; ID2D1TransformedGeometry * transformed;
factory->CreateTransformedGeometry( factory->CreateTransformedGeometry(
_geometry, geometry_,
_parentNode->_finalMatri, parent_node_->final_matrix_,
&transformed &transformed
); );
SafeRelease(_geometry); SafeRelease(geometry_);
_geometry = transformed; geometry_ = transformed;
} }

View File

@ -33,13 +33,19 @@ e2d::Color::Color(float r, float g, float b, float alpha)
} }
e2d::Color::Color(UINT rgb) 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) 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) 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)); 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;
}

View File

@ -3,77 +3,77 @@
using namespace std::chrono; using namespace std::chrono;
e2d::Duration::Duration() e2d::Duration::Duration()
: _ms() : duration_ms_()
{ {
} }
e2d::Duration::Duration(float seconds) e2d::Duration::Duration(float seconds)
: _ms(static_cast<long long>(seconds * 1000.f)) : duration_ms_(static_cast<long long>(seconds * 1000.f))
{ {
} }
int e2d::Duration::milliseconds() const int e2d::Duration::Milliseconds() const
{ {
return static_cast<int>(_ms.count()); return static_cast<int>(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 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 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 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 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 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 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 e2d::Duration e2d::Duration::operator+(Duration const & other) const
{ {
Duration d; Duration d;
d._ms = _ms + other._ms; d.duration_ms_ = duration_ms_ + other.duration_ms_;
return std::move(d); return std::move(d);
} }
e2d::Duration e2d::Duration::operator-(Duration const & other) const e2d::Duration e2d::Duration::operator-(Duration const & other) const
{ {
Duration d; Duration d;
d._ms = _ms - other._ms; d.duration_ms_ = duration_ms_ - other.duration_ms_;
return std::move(d); return std::move(d);
} }
e2d::Duration & e2d::Duration::operator+=(Duration const &other) e2d::Duration & e2d::Duration::operator+=(Duration const &other)
{ {
_ms += other._ms; duration_ms_ += other.duration_ms_;
return (*this); return (*this);
} }
e2d::Duration & e2d::Duration::operator-=(Duration const &other) e2d::Duration & e2d::Duration::operator-=(Duration const &other)
{ {
_ms -= other._ms; duration_ms_ -= other.duration_ms_;
return (*this); return (*this);
} }

View File

@ -1,28 +1,28 @@
#include "..\e2dcommon.h" #include "..\e2dcommon.h"
e2d::Function::Function() e2d::Function::Function()
: _func(nullptr) : func_(nullptr)
{} {}
e2d::Function::Function(std::nullptr_t) e2d::Function::Function(std::nullptr_t)
: _func(nullptr) : func_(nullptr)
{ {
} }
e2d::Function::Function(std::function<void()> func) e2d::Function::Function(std::function<void()> func)
: _func(func) : func_(func)
{ {
} }
void e2d::Function::operator()(void) const void e2d::Function::operator()(void) const
{ {
if (_func) if (func_)
{ {
_func(); func_();
} }
} }
e2d::Function::operator bool() const e2d::Function::operator bool() const
{ {
return static_cast<bool>(_func); return static_cast<bool>(func_);
} }

View File

@ -2,108 +2,108 @@
#include "..\e2dbase.h" #include "..\e2dbase.h"
#include "..\e2dtool.h" #include "..\e2dtool.h"
std::map<size_t, ID2D1Bitmap*> e2d::Image::_bitmapCache; std::map<size_t, ID2D1Bitmap*> e2d::Image::bitmap_cache_;
e2d::Image::Image() e2d::Image::Image()
: _bitmap(nullptr) : bitmap_(nullptr)
, _cropRect() , crop_rect_()
{ {
} }
e2d::Image::Image(const Resource& res) e2d::Image::Image(const Resource& res)
: _bitmap(nullptr) : bitmap_(nullptr)
, _cropRect() , crop_rect_()
{ {
this->open(res); this->Open(res);
} }
e2d::Image::Image(const Resource& res, const Rect& cropRect) e2d::Image::Image(const Resource& res, const Rect& crop_rect)
: _bitmap(nullptr) : bitmap_(nullptr)
, _cropRect() , crop_rect_()
{ {
this->open(res); this->Open(res);
this->crop(cropRect); this->Crop(crop_rect);
} }
e2d::Image::Image(const String & fileName) e2d::Image::Image(const String & file_name)
: _bitmap(nullptr) : bitmap_(nullptr)
, _cropRect() , crop_rect_()
{ {
this->open(fileName); this->Open(file_name);
} }
e2d::Image::Image(const String & fileName, const Rect & cropRect) e2d::Image::Image(const String & file_name, const Rect & crop_rect)
: _bitmap(nullptr) : bitmap_(nullptr)
, _cropRect() , crop_rect_()
{ {
this->open(fileName); this->Open(file_name);
this->crop(cropRect); this->Crop(crop_rect);
} }
e2d::Image::~Image() 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!"); WARN("Load Image from file failed!");
return false; return false;
} }
this->_setBitmap(_bitmapCache.at(res.resNameId)); this->SetBitmap(bitmap_cache_.at(res.name));
return true; 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; return false;
if (!Image::preload(fileName)) if (!Image::Preload(file_name))
{ {
WARN("Load Image from file failed!"); WARN("Load Image from file failed!");
return false; return false;
} }
this->_setBitmap(_bitmapCache.at(fileName.hash())); this->SetBitmap(bitmap_cache_.at(file_name.GetHash()));
return true; 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()); crop_rect_.origin.x = std::min(std::max(crop_rect.origin.x, 0.f), this->GetSourceWidth());
_cropRect.origin.y = std::min(std::max(cropRect.origin.y, 0.f), this->getSourceHeight()); crop_rect_.origin.y = std::min(std::max(crop_rect.origin.y, 0.f), this->GetSourceHeight());
_cropRect.size.width = std::min(std::max(cropRect.size.width, 0.f), this->getSourceWidth() - cropRect.origin.x); crop_rect_.size.width = std::min(std::max(crop_rect.size.width, 0.f), this->GetSourceWidth() - crop_rect.origin.x);
_cropRect.size.height = std::min(std::max(cropRect.size.height, 0.f), this->getSourceHeight() - cropRect.origin.y); 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 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 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 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; return true;
} }
IWICImagingFactory *pImagingFactory = Renderer::getImagingFactory(); IWICImagingFactory *pImagingFactory = Renderer::GetImagingFactory();
ID2D1HwndRenderTarget* pRenderTarget = Renderer::getInstance()->getRenderTarget(); ID2D1HwndRenderTarget* pRenderTarget = Renderer::GetInstance()->GetRenderTarget();
IWICBitmapDecoder *pDecoder = nullptr; IWICBitmapDecoder *pDecoder = nullptr;
IWICBitmapFrameDecode *pSource = nullptr; IWICBitmapFrameDecode *pSource = nullptr;
IWICStream *pStream = nullptr; IWICStream *pStream = nullptr;
@ -172,8 +172,8 @@ bool e2d::Image::preload(const Resource& res)
// 定位资源 // 定位资源
imageResHandle = ::FindResourceW( imageResHandle = ::FindResourceW(
HINST_THISCOMPONENT, HINST_THISCOMPONENT,
MAKEINTRESOURCE(res.resNameId), MAKEINTRESOURCE(res.name),
(LPCWSTR)res.resType (LPCWSTR)res.type
); );
HRESULT hr = imageResHandle ? S_OK : E_FAIL; HRESULT hr = imageResHandle ? S_OK : E_FAIL;
@ -264,7 +264,7 @@ bool e2d::Image::preload(const Resource& res)
if (SUCCEEDED(hr)) 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); return SUCCEEDED(hr);
} }
bool e2d::Image::preload(const String & fileName) bool e2d::Image::Preload(const String & file_name)
{ {
String actualFilePath = File(fileName).getPath(); String actualFilePath = File(file_name).GetPath();
if (actualFilePath.isEmpty()) if (actualFilePath.IsEmpty())
return false; return false;
size_t hash = actualFilePath.hash(); size_t hash = actualFilePath.GetHash();
if (_bitmapCache.find(hash) != _bitmapCache.end()) if (bitmap_cache_.find(hash) != bitmap_cache_.end())
return true; return true;
IWICImagingFactory *pImagingFactory = Renderer::getImagingFactory(); IWICImagingFactory *pImagingFactory = Renderer::GetImagingFactory();
ID2D1HwndRenderTarget* pRenderTarget = Renderer::getInstance()->getRenderTarget(); ID2D1HwndRenderTarget* pRenderTarget = Renderer::GetInstance()->GetRenderTarget();
IWICBitmapDecoder *pDecoder = nullptr; IWICBitmapDecoder *pDecoder = nullptr;
IWICBitmapFrameDecode *pSource = nullptr; IWICBitmapFrameDecode *pSource = nullptr;
IWICStream *pStream = nullptr; IWICStream *pStream = nullptr;
@ -340,7 +340,7 @@ bool e2d::Image::preload(const String & fileName)
if (SUCCEEDED(hr)) 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); return SUCCEEDED(hr);
} }
void e2d::Image::clearCache() void e2d::Image::ClearCache()
{ {
if (_bitmapCache.empty()) if (bitmap_cache_.empty())
return; return;
for (const auto& bitmap : _bitmapCache) for (const auto& bitmap : bitmap_cache_)
{ {
bitmap.second->Release(); bitmap.second->Release();
} }
_bitmapCache.clear(); bitmap_cache_.clear();
} }
void e2d::Image::_setBitmap(ID2D1Bitmap * bitmap) void e2d::Image::SetBitmap(ID2D1Bitmap * bitmap)
{ {
if (bitmap) if (bitmap)
{ {
_bitmap = bitmap; bitmap_ = bitmap;
_cropRect.origin.x = _cropRect.origin.y = 0; crop_rect_.origin.x = crop_rect_.origin.y = 0;
_cropRect.size.width = _bitmap->GetSize().width; crop_rect_.size.width = bitmap_->GetSize().width;
_cropRect.size.height = _bitmap->GetSize().height; crop_rect_.size.height = bitmap_->GetSize().height;
} }
} }
ID2D1Bitmap * e2d::Image::getBitmap() ID2D1Bitmap * e2d::Image::GetBitmap()
{ {
return _bitmap; return bitmap_;
} }

View File

@ -20,22 +20,22 @@ e2d::Point::Point(const Point & other)
y = other.y; 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); 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); 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); 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); return Point(x / value, y / value);
} }
@ -45,7 +45,7 @@ e2d::Point::operator e2d::Size() const
return Size(x, y); 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( return sqrt(
(p1.x - p2.x) * (p1.x - p2.x) + (p1.x - p2.x) * (p1.x - p2.x) +

View File

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

View File

@ -1,7 +1,7 @@
#include "..\e2dcommon.h" #include "..\e2dcommon.h"
e2d::Ref::Ref() 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_;
} }

View File

@ -1,8 +1,8 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
e2d::Resource::Resource(size_t resNameId, const String & resType) e2d::Resource::Resource(size_t resource_name, const String & resource_type)
: resNameId(resNameId) : name(resource_name)
, resType(resType) , type(resource_type)
{ {
} }

View File

@ -18,22 +18,22 @@ e2d::Size::Size(const Size & other)
height = other.height; 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); 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); return Size(width / value, height / value);
} }
@ -48,7 +48,7 @@ e2d::Size e2d::Size::operator-() const
return Size(-width, -height); 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);
} }

View File

@ -6,76 +6,76 @@
e2d::String::String() e2d::String::String()
: _str(L"") : string_(L"")
{ {
} }
e2d::String::String(const wchar_t *str) e2d::String::String(const wchar_t *str)
: _str(str) : string_(str)
{ {
} }
e2d::String::String(const char *cstr) e2d::String::String(const char *cstr)
: _str(static_cast<wchar_t*>(_bstr_t(cstr))) : string_(static_cast<wchar_t*>(_bstr_t(cstr)))
{ {
} }
e2d::String::String(e2d::String && str) e2d::String::String(e2d::String && str)
{ {
_str = std::move(str._str); string_ = std::move(str.string_);
} }
e2d::String::String(const e2d::String &str) e2d::String::String(const e2d::String &str)
: _str(str._str) : string_(str.string_)
{ {
} }
e2d::String::~String() e2d::String::~String()
{ {
_str.clear(); string_.clear();
} }
e2d::String &e2d::String::operator=(const wchar_t *str) e2d::String &e2d::String::operator=(const wchar_t *str)
{ {
_str = str; string_ = str;
return (*this); return (*this);
} }
e2d::String & e2d::String::operator=(const char *cstr) e2d::String & e2d::String::operator=(const char *cstr)
{ {
_str = static_cast<wchar_t*>(_bstr_t(cstr)); string_ = static_cast<wchar_t*>(_bstr_t(cstr));
return (*this); return (*this);
} }
e2d::String e2d::String::parse(int value) e2d::String e2d::String::Parse(int value)
{ {
String tmp; String tmp;
tmp._str = std::to_wstring(value); tmp.string_ = std::to_wstring(value);
return std::move(tmp); return std::move(tmp);
} }
e2d::String e2d::String::parse(unsigned int value) e2d::String e2d::String::Parse(unsigned int value)
{ {
String tmp; String tmp;
tmp._str = std::to_wstring(value); tmp.string_ = std::to_wstring(value);
return std::move(tmp); return std::move(tmp);
} }
e2d::String e2d::String::parse(float value) e2d::String e2d::String::Parse(float value)
{ {
String tmp; String tmp;
tmp._str = std::to_wstring(value); tmp.string_ = std::to_wstring(value);
return std::move(tmp); return std::move(tmp);
} }
e2d::String e2d::String::parse(double value) e2d::String e2d::String::Parse(double value)
{ {
String tmp; String tmp;
tmp._str = std::to_wstring(value); tmp.string_ = std::to_wstring(value);
return std::move(tmp); return std::move(tmp);
} }
e2d::String e2d::String::format(const char * format, ...) e2d::String e2d::String::Format(const char * format, ...)
{ {
std::string tmp; std::string tmp;
@ -97,7 +97,7 @@ e2d::String e2d::String::format(const char * format, ...)
return std::move(str); 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; std::wstring tmp;
@ -119,14 +119,9 @@ e2d::String e2d::String::format(const wchar_t * format, ...)
return std::move(str); 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) e2d::String & e2d::String::operator=(const String &str)
{ {
_str = str._str; string_ = str.string_;
return (*this); return (*this);
} }
@ -134,7 +129,7 @@ bool e2d::String::operator==(const wchar_t *str) const
{ {
if (str) if (str)
{ {
return (_str.compare(str) == 0); return (string_.compare(str) == 0);
} }
else else
{ {
@ -147,7 +142,7 @@ bool e2d::String::operator==(const char *str) const
if (str) if (str)
{ {
String temp(str); String temp(str);
return (_str == temp._str); return (string_ == temp.string_);
} }
else else
{ {
@ -157,14 +152,14 @@ bool e2d::String::operator==(const char *str) const
bool e2d::String::operator ==(const e2d::String &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 bool e2d::String::operator!=(const wchar_t *str) const
{ {
if (str) if (str)
{ {
return (_str.compare(str) != 0); return (string_.compare(str) != 0);
} }
else else
{ {
@ -177,7 +172,7 @@ bool e2d::String::operator!=(const char *str) const
if (str) if (str)
{ {
String temp(str); String temp(str);
return (_str != temp._str); return (string_ != temp.string_);
} }
else else
{ {
@ -187,247 +182,247 @@ bool e2d::String::operator!=(const char *str) const
bool e2d::String::operator!=(const e2d::String &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 e2d::String e2d::String::operator+(const wchar_t *str) const
{ {
String temp; String temp;
temp._str = _str + str; temp.string_ = string_ + str;
return std::move(temp); return std::move(temp);
} }
e2d::String e2d::String::operator+(const char *str) const e2d::String e2d::String::operator+(const char *str) const
{ {
String temp; String temp;
temp._str = _str + static_cast<wchar_t*>(_bstr_t(str)); temp.string_ = string_ + static_cast<wchar_t*>(_bstr_t(str));
return std::move(temp); return std::move(temp);
} }
e2d::String e2d::String::operator+(const e2d::String &str) const e2d::String e2d::String::operator+(const e2d::String &str) const
{ {
String temp; String temp;
temp._str = _str + str._str; temp.string_ = string_ + str.string_;
return std::move(temp); return std::move(temp);
} }
e2d::String e2d::operator+(const wchar_t *str1, const e2d::String &str2) e2d::String e2d::operator+(const wchar_t *str1, const e2d::String &str2)
{ {
String temp; String temp;
temp._str = str1 + str2._str; temp.string_ = str1 + str2.string_;
return std::move(temp); return std::move(temp);
} }
e2d::String e2d::operator+(const char *str1, const String &str2) e2d::String e2d::operator+(const char *str1, const String &str2)
{ {
String temp; String temp;
temp._str = static_cast<wchar_t*>(_bstr_t(str1)) + str2._str; temp.string_ = static_cast<wchar_t*>(_bstr_t(str1)) + str2.string_;
return std::move(temp); return std::move(temp);
} }
e2d::String & e2d::String::operator+=(const wchar_t *str) e2d::String & e2d::String::operator+=(const wchar_t *str)
{ {
_str += str; string_ += str;
return (*this); return (*this);
} }
e2d::String & e2d::String::operator+=(const char *str) e2d::String & e2d::String::operator+=(const char *str)
{ {
_str += static_cast<wchar_t*>(_bstr_t(str)); string_ += static_cast<wchar_t*>(_bstr_t(str));
return (*this); return (*this);
} }
e2d::String & e2d::String::operator+=(const String &str) e2d::String & e2d::String::operator+=(const String &str)
{ {
_str += str._str; string_ += str.string_;
return (*this); return (*this);
} }
bool e2d::String::operator>(const String &str) const bool e2d::String::operator>(const String &str) const
{ {
return _str > str._str; return string_ > str.string_;
} }
bool e2d::String::operator>=(const String &str) const bool e2d::String::operator>=(const String &str) const
{ {
return _str >= str._str; return string_ >= str.string_;
} }
bool e2d::String::operator<(const String &str) const bool e2d::String::operator<(const String &str) const
{ {
return _str < str._str; return string_ < str.string_;
} }
bool e2d::String::operator<=(const String &str) const bool e2d::String::operator<=(const String &str) const
{ {
return _str <= str._str; return string_ <= str.string_;
} }
e2d::String & e2d::String::operator<<(const String &str) e2d::String & e2d::String::operator<<(const String &str)
{ {
_str += str._str; string_ += str.string_;
return (*this); return (*this);
} }
e2d::String & e2d::String::operator<<(const wchar_t *str) e2d::String & e2d::String::operator<<(const wchar_t *str)
{ {
_str += str; string_ += str;
return (*this); return (*this);
} }
e2d::String & e2d::String::operator<<(wchar_t *str) e2d::String & e2d::String::operator<<(wchar_t *str)
{ {
_str += str; string_ += str;
return (*this); return (*this);
} }
e2d::String & e2d::String::operator<<(const char * cstr) e2d::String & e2d::String::operator<<(const char * cstr)
{ {
_str += static_cast<wchar_t*>(_bstr_t(cstr)); string_ += static_cast<wchar_t*>(_bstr_t(cstr));
return (*this); return (*this);
} }
e2d::String & e2d::String::operator<<(char * cstr) e2d::String & e2d::String::operator<<(char * cstr)
{ {
_str += static_cast<wchar_t*>(_bstr_t(cstr)); string_ += static_cast<wchar_t*>(_bstr_t(cstr));
return (*this); return (*this);
} }
e2d::String & e2d::String::operator<<(int value) e2d::String & e2d::String::operator<<(int value)
{ {
(*this) += String::parse(value); (*this) += String::Parse(value);
return (*this); return (*this);
} }
e2d::String & e2d::String::operator<<(unsigned int value) e2d::String & e2d::String::operator<<(unsigned int value)
{ {
(*this) += String::parse(value); (*this) += String::Parse(value);
return (*this); return (*this);
} }
e2d::String & e2d::String::operator<<(float value) e2d::String & e2d::String::operator<<(float value)
{ {
(*this) += String::parse(value); (*this) += String::Parse(value);
return (*this); return (*this);
} }
e2d::String & e2d::String::operator<<(double value) e2d::String & e2d::String::operator<<(double value)
{ {
(*this) += String::parse(value); (*this) += String::Parse(value);
return (*this); return (*this);
} }
e2d::String::operator const wchar_t*() const e2d::String::operator const wchar_t*() const
{ {
return _str.c_str(); return string_.c_str();
} }
e2d::String::operator wchar_t*() const e2d::String::operator wchar_t*() const
{ {
return const_cast<wchar_t*>(_str.c_str()); return const_cast<wchar_t*>(string_.c_str());
} }
e2d::String::operator std::wstring() const e2d::String::operator std::wstring() const
{ {
return _str; return string_;
} }
e2d::String::operator std::string() const e2d::String::operator std::string() const
{ {
std::string str = static_cast<const char *>(_bstr_t(_str.c_str())); std::string str = static_cast<const char *>(_bstr_t(string_.c_str()));
return std::move(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<int>(_str.size()); return static_cast<int>(string_.size());
} }
size_t e2d::String::hash() const size_t e2d::String::GetHash() const
{ {
std::hash<std::wstring> hash; std::hash<std::wstring> 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); 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); return std::move(str);
} }
e2d::String e2d::String::toLower() const e2d::String e2d::String::ToLower() const
{ {
e2d::String str(*this); 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); return std::move(str);
} }
int e2d::String::toInt() const int e2d::String::ToInt() const
{ {
if (_str.empty()) if (string_.empty())
{ {
return 0; 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 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 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; 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 false;
} }
return true; return true;
} }
e2d::String e2d::String::subtract(int offset, int count) const e2d::String e2d::String::Subtract(int offset, int count) const
{ {
String tmp; String tmp;
int length = static_cast<int>(_str.size()); int length = static_cast<int>(string_.size());
if (length == 0 || offset >= length) if (length == 0 || offset >= length)
return std::move(tmp); return std::move(tmp);
@ -437,37 +432,37 @@ e2d::String e2d::String::subtract(int offset, int count) const
if (count < 0 || (offset + count) > length) if (count < 0 || (offset + count) > length)
count = length - offset; count = length - offset;
tmp._str = _str.substr(offset, count); tmp.string_ = string_.substr(offset, count);
return std::move(tmp); 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; return;
size_t start_pos = 0; 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); string_.replace(start_pos, from.string_.length(), (const wchar_t *)to);
start_pos += to._str.length(); 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; 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; 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) std::wostream & e2d::operator<<(std::wostream &cout, const String &str)
{ {
cout << str._str; cout << str.string_;
return cout; return cout;
} }
std::wistream & e2d::operator>>(std::wistream &cin, String &str) std::wistream & e2d::operator>>(std::wistream &cin, String &str)
{ {
cin >> str._str; cin >> str.string_;
return cin; return cin;
} }
std::ostream & e2d::operator<<(std::ostream &cout, const String &str) std::ostream & e2d::operator<<(std::ostream &cout, const String &str)
{ {
std::string cstr = static_cast<char*>(_bstr_t(str._str.c_str())); std::string cstr = static_cast<char*>(_bstr_t(str.string_.c_str()));
cout << cstr; cout << cstr;
return cout; return cout;
} }
@ -505,6 +500,6 @@ std::istream & e2d::operator>>(std::istream &cin, String &str)
{ {
std::string temp; std::string temp;
cin >> temp; cin >> temp;
str._str = static_cast<wchar_t*>(_bstr_t(temp.c_str())); str.string_ = static_cast<wchar_t*>(_bstr_t(temp.c_str()));
return cin; return cin;
} }

View File

@ -7,52 +7,52 @@ e2d::Time::Time()
{ {
} }
time_t e2d::Time::getTimeStamp() const time_t e2d::Time::GetTimeStamp() const
{ {
auto& duration = time_point_cast<milliseconds>(_timePoint).time_since_epoch(); auto& duration = time_point_cast<milliseconds>(time_).time_since_epoch();
return static_cast<time_t>(duration.count()); return static_cast<time_t>(duration.count());
} }
bool e2d::Time::isZero() const bool e2d::Time::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 e2d::Time e2d::Time::operator+(Duration const & other) const
{ {
Time t; Time t;
t._timePoint = _timePoint + milliseconds(other.milliseconds()); t.time_ = time_ + milliseconds(other.Milliseconds());
return std::move(t); return std::move(t);
} }
e2d::Time e2d::Time::operator-(Duration const & other) const e2d::Time e2d::Time::operator-(Duration const & other) const
{ {
Time t; Time t;
t._timePoint = _timePoint - milliseconds(other.milliseconds()); t.time_ = time_ - milliseconds(other.Milliseconds());
return std::move(t); return std::move(t);
} }
e2d::Time & e2d::Time::operator+=(Duration const & other) e2d::Time & e2d::Time::operator+=(Duration const & other)
{ {
_timePoint += milliseconds(other.milliseconds()); time_ += milliseconds(other.Milliseconds());
return (*this); return (*this);
} }
e2d::Time & e2d::Time::operator-=(Duration const &other) e2d::Time & e2d::Time::operator-=(Duration const &other)
{ {
_timePoint -= milliseconds(other.milliseconds()); time_ -= milliseconds(other.Milliseconds());
return (*this); return (*this);
} }
e2d::Duration e2d::Time::operator-(Time const & other) const e2d::Duration e2d::Time::operator-(Time const & other) const
{ {
auto ms = duration_cast<milliseconds>(_timePoint - other._timePoint).count(); auto ms = duration_cast<milliseconds>(time_ - other.time_).count();
return std::move(Duration(static_cast<float>(ms) / 1000.f)); return std::move(Duration(static_cast<float>(ms) / 1000.f));
} }
e2d::Time e2d::Time::now() e2d::Time e2d::Time::Now()
{ {
Time t; Time t;
t._timePoint = steady_clock::now(); t.time_ = steady_clock::now();
return std::move(t); return std::move(t);
} }

View File

@ -2,17 +2,17 @@
e2d::Exception::Exception() E2D_NOEXCEPT e2d::Exception::Exception() E2D_NOEXCEPT
: _message() : message_()
{ {
} }
e2d::Exception::Exception(const char * message) E2D_NOEXCEPT e2d::Exception::Exception(const char * message) E2D_NOEXCEPT
: _message(message) : message_(message)
{ {
} }
e2d::Exception::Exception(Exception const& other) E2D_NOEXCEPT 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; return *this;
} }
_message = other._message; message_ = other.message_;
return *this; 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_;
} }

View File

@ -3,7 +3,7 @@
using namespace e2d; using namespace e2d;
TextRenderer::TextRenderer() E2DTextRenderer::E2DTextRenderer()
: cRefCount_(0) : cRefCount_(0)
, pD2DFactory_(nullptr) , pD2DFactory_(nullptr)
, pRT_(nullptr) , pRT_(nullptr)
@ -16,21 +16,21 @@ TextRenderer::TextRenderer()
{ {
} }
TextRenderer::~TextRenderer() E2DTextRenderer::~E2DTextRenderer()
{ {
SafeRelease(pD2DFactory_); SafeRelease(pD2DFactory_);
SafeRelease(pRT_); SafeRelease(pRT_);
SafeRelease(pBrush_); SafeRelease(pBrush_);
} }
HRESULT TextRenderer::Create( HRESULT E2DTextRenderer::Create(
TextRenderer** ppTextRenderer, E2DTextRenderer** ppTextRenderer,
ID2D1Factory* pD2DFactory, ID2D1Factory* pD2DFactory,
ID2D1HwndRenderTarget* pRT, ID2D1HwndRenderTarget* pRT,
ID2D1SolidColorBrush* pBrush ID2D1SolidColorBrush* pBrush
) )
{ {
*ppTextRenderer = new (std::nothrow) TextRenderer(); *ppTextRenderer = new (std::nothrow) E2DTextRenderer();
if (*ppTextRenderer) if (*ppTextRenderer)
{ {
pD2DFactory->AddRef(); pD2DFactory->AddRef();
@ -46,29 +46,29 @@ HRESULT TextRenderer::Create(
return E_FAIL; return E_FAIL;
} }
STDMETHODIMP_(void) TextRenderer::SetTextStyle( STDMETHODIMP_(void) E2DTextRenderer::SetTextStyle(
CONST D2D1_COLOR_F &fillColor, CONST D2D1_COLOR_F &fillColor,
BOOL hasOutline, BOOL outline,
CONST D2D1_COLOR_F &outlineColor, CONST D2D1_COLOR_F &outline_color,
FLOAT outlineWidth, FLOAT outline_width,
D2D1_LINE_JOIN outlineJoin D2D1_LINE_JOIN outlineJoin
) )
{ {
sFillColor_ = fillColor; sFillColor_ = fillColor;
bShowOutline_ = hasOutline; bShowOutline_ = outline;
sOutlineColor_ = outlineColor; sOutlineColor_ = outline_color;
fOutlineWidth = 2 * outlineWidth; fOutlineWidth = 2 * outline_width;
switch (outlineJoin) switch (outlineJoin)
{ {
case D2D1_LINE_JOIN_MITER: case D2D1_LINE_JOIN_MITER:
pCurrStrokeStyle_ = Renderer::getMiterStrokeStyle(); pCurrStrokeStyle_ = Renderer::GetMiterStrokeStyle();
break; break;
case D2D1_LINE_JOIN_BEVEL: case D2D1_LINE_JOIN_BEVEL:
pCurrStrokeStyle_ = Renderer::getBevelStrokeStyle(); pCurrStrokeStyle_ = Renderer::GetBevelStrokeStyle();
break; break;
case D2D1_LINE_JOIN_ROUND: case D2D1_LINE_JOIN_ROUND:
pCurrStrokeStyle_ = Renderer::getRoundStrokeStyle(); pCurrStrokeStyle_ = Renderer::GetRoundStrokeStyle();
break; break;
default: default:
pCurrStrokeStyle_ = nullptr; pCurrStrokeStyle_ = nullptr;
@ -76,7 +76,7 @@ STDMETHODIMP_(void) TextRenderer::SetTextStyle(
} }
} }
STDMETHODIMP TextRenderer::DrawGlyphRun( STDMETHODIMP E2DTextRenderer::DrawGlyphRun(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
FLOAT baselineOriginX, FLOAT baselineOriginX,
FLOAT baselineOriginY, FLOAT baselineOriginY,
@ -165,7 +165,7 @@ STDMETHODIMP TextRenderer::DrawGlyphRun(
return hr; return hr;
} }
STDMETHODIMP TextRenderer::DrawUnderline( STDMETHODIMP E2DTextRenderer::DrawUnderline(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
FLOAT baselineOriginX, FLOAT baselineOriginX,
FLOAT baselineOriginY, FLOAT baselineOriginY,
@ -232,7 +232,7 @@ STDMETHODIMP TextRenderer::DrawUnderline(
return S_OK; return S_OK;
} }
STDMETHODIMP TextRenderer::DrawStrikethrough( STDMETHODIMP E2DTextRenderer::DrawStrikethrough(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
FLOAT baselineOriginX, FLOAT baselineOriginX,
FLOAT baselineOriginY, FLOAT baselineOriginY,
@ -299,25 +299,25 @@ STDMETHODIMP TextRenderer::DrawStrikethrough(
return S_OK; return S_OK;
} }
STDMETHODIMP TextRenderer::DrawInlineObject( STDMETHODIMP E2DTextRenderer::DrawInlineObject(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
FLOAT originX, FLOAT originX,
FLOAT originY, FLOAT originY,
IDWriteInlineObject* inlineObject, IDWriteInlineObject* inlineObject,
BOOL isSideways, BOOL IsSideways,
BOOL isRightToLeft, BOOL IsRightToLeft,
IUnknown* clientDrawingEffect IUnknown* clientDrawingEffect
) )
{ {
return E_NOTIMPL; return E_NOTIMPL;
} }
STDMETHODIMP_(unsigned long) TextRenderer::AddRef() STDMETHODIMP_(unsigned long) E2DTextRenderer::AddRef()
{ {
return InterlockedIncrement(&cRefCount_); return InterlockedIncrement(&cRefCount_);
} }
STDMETHODIMP_(unsigned long) TextRenderer::Release() STDMETHODIMP_(unsigned long) E2DTextRenderer::Release()
{ {
unsigned long newCount = InterlockedDecrement(&cRefCount_); unsigned long newCount = InterlockedDecrement(&cRefCount_);
@ -330,7 +330,7 @@ STDMETHODIMP_(unsigned long) TextRenderer::Release()
return newCount; return newCount;
} }
STDMETHODIMP TextRenderer::IsPixelSnappingDisabled( STDMETHODIMP E2DTextRenderer::IsPixelSnappingDisabled(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
__out BOOL* isDisabled __out BOOL* isDisabled
) )
@ -339,7 +339,7 @@ STDMETHODIMP TextRenderer::IsPixelSnappingDisabled(
return S_OK; return S_OK;
} }
STDMETHODIMP TextRenderer::GetCurrentTransform( STDMETHODIMP E2DTextRenderer::GetCurrentTransform(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
__out DWRITE_MATRIX* transform __out DWRITE_MATRIX* transform
) )
@ -348,7 +348,7 @@ STDMETHODIMP TextRenderer::GetCurrentTransform(
return S_OK; return S_OK;
} }
STDMETHODIMP TextRenderer::GetPixelsPerDip( STDMETHODIMP E2DTextRenderer::GetPixelsPerDip(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
__out FLOAT* pixelsPerDip __out FLOAT* pixelsPerDip
) )
@ -361,7 +361,7 @@ STDMETHODIMP TextRenderer::GetPixelsPerDip(
return S_OK; return S_OK;
} }
STDMETHODIMP TextRenderer::QueryInterface( STDMETHODIMP E2DTextRenderer::QueryInterface(
IID const& riid, IID const& riid,
void** ppvObject void** ppvObject
) )

View File

@ -11,34 +11,34 @@ e2d::VoiceCallback::~VoiceCallback()
void e2d::VoiceCallback::OnLoopEnd(void * pBufferContext) void e2d::VoiceCallback::OnLoopEnd(void * pBufferContext)
{ {
if (_loopEndFunc) if (loop_end_callback_)
{ {
_loopEndFunc(); loop_end_callback_();
} }
} }
void e2d::VoiceCallback::OnStreamEnd() void e2d::VoiceCallback::OnStreamEnd()
{ {
if (_streamEndFunc) if (stream_end_callback_)
{ {
_streamEndFunc(); stream_end_callback_();
} }
} }
void e2d::VoiceCallback::OnBufferEnd(void * pBufferContext) 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;
} }

View File

@ -1,14 +1,14 @@
#include "..\e2devent.h" #include "..\e2devent.h"
e2d::Collision::Collision() e2d::Collision::Collision()
: _node(nullptr) : node_(nullptr)
, _relation(Collider::Relation::Unknown) , relation_(Collider::Relation::Unknown)
{ {
} }
e2d::Collision::Collision(Node* node, Collider::Relation relation) e2d::Collision::Collision(Node* node, Collider::Relation relation)
: _node(node) : node_(node)
, _relation(relation) , 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_;
} }

View File

@ -1,31 +1,31 @@
#include "..\e2devent.h" #include "..\e2devent.h"
e2d::KeyEvent::KeyEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) e2d::KeyEvent::KeyEvent(HWND hWnd, UINT message, WPARAM w_param, LPARAM l_param)
: _code(KeyCode(wParam)) : code_(KeyCode(w_param))
, _type(Type(message)) , type_(Type(message))
, _count(static_cast<int>((DWORD)lParam & 0x0000FFFF)) , count_(static_cast<int>((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 'A': return KeyCode::A;
case 'B': return KeyCode::B; case 'B': return KeyCode::B;

View File

@ -1,62 +1,62 @@
#include "..\e2devent.h" #include "..\e2devent.h"
#include "..\e2dbase.h" #include "..\e2dbase.h"
e2d::MouseEvent::MouseEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, float dpi) e2d::MouseEvent::MouseEvent(HWND hWnd, UINT message, WPARAM w_param, LPARAM l_param, float dpi)
: _message(message) : message_(message)
, _wParam(wParam) , w_param_(w_param)
, _lParam(lParam) , l_param_(l_param)
, _type(Type(message)) , type_(Type(message))
{ {
_pos.x = ((float)(short)LOWORD(lParam)) * 96.f / dpi; pos_.x = ((float)(short)LOWORD(l_param)) * 96.f / dpi;
_pos.y = ((float)(short)HIWORD(lParam)) * 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<float>(GET_WHEEL_DELTA_WPARAM(_wParam)); return static_cast<float>(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_;
} }

View File

@ -3,15 +3,15 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::ActionManager * e2d::ActionManager::getInstance() e2d::ActionManager * e2d::ActionManager::GetInstance()
{ {
static ActionManager instance; static ActionManager instance;
return &instance; return &instance;
} }
e2d::ActionManager::ActionManager() e2d::ActionManager::ActionManager()
: _actions() : actions_()
, _runningActions() , 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; return;
std::vector<Action*> currActions; std::vector<Action*> currActions;
currActions.reserve(_runningActions.size()); currActions.reserve(running_actions_.size());
std::copy_if( std::copy_if(
_runningActions.begin(), running_actions_.begin(),
_runningActions.end(), running_actions_.end(),
std::back_inserter(currActions), std::back_inserter(currActions),
[](Action* action) { return action->isRunning() && !action->_isDone(); } [](Action* action) { return action->IsRunning() && !action->IsDone(); }
); );
// 遍历所有正在运行的动作 // 遍历所有正在运行的动作
for (const auto& action : currActions) 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)->Release();
(*iter)->_target = nullptr; (*iter)->target_ = nullptr;
iter = _runningActions.erase(iter); iter = running_actions_.erase(iter);
} }
else else
{ {
@ -53,88 +53,88 @@ void e2d::ActionManager::update()
} }
} }
void e2d::ActionManager::__add(Action * action) void e2d::ActionManager::Add(Action * action)
{ {
if (action) if (action)
{ {
auto iter = std::find(_actions.begin(), _actions.end(), action); auto iter = std::find(actions_.begin(), actions_.end(), action);
if (iter == _actions.end()) 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; return;
auto iter = std::find(_actions.begin(), _actions.end(), action); auto iter = std::find(actions_.begin(), actions_.end(), action);
if (iter != _actions.end()) 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; 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; 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; 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(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)
{ {
if (action->_target == nullptr) if (action->target_ == nullptr)
{ {
auto iter = std::find(_runningActions.begin(), _runningActions.end(), action); auto iter = std::find(running_actions_.begin(), running_actions_.end(), action);
if (iter == _runningActions.end()) if (iter == running_actions_.end())
{ {
action->retain(); action->Retain();
action->_startWithTarget(target); action->StartWithTarget(target);
action->_running = !paused; action->running_ = !paused;
_runningActions.push_back(action); running_actions_.push_back(action);
} }
} }
else 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; 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; 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; 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) if (target)
{ {
auto iter = std::find_if( auto iter = std::find_if(
_runningActions.begin(), running_actions_.begin(),
_runningActions.end(), running_actions_.end(),
[target](Action* action) ->bool { return action->getTarget() == target; } [target](Action* action) ->bool { return action->GetTarget() == target; }
); );
if (iter != _runningActions.end()) if (iter != running_actions_.end())
{ {
(*iter)->release(); (*iter)->Release();
_runningActions.erase(iter); 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::Action*> e2d::ActionManager::get(const String& name) std::vector<e2d::Action*> e2d::ActionManager::Get(const String& name)
{ {
std::vector<Action*> actions; std::vector<Action*> actions;
for (const auto& action : _actions) for (const auto& action : actions_)
{ {
if (action->getName() == name) if (action->GetName() == name)
{ {
actions.push_back(action); actions.push_back(action);
} }
@ -231,15 +231,15 @@ std::vector<e2d::Action*> e2d::ActionManager::get(const String& name)
return std::move(actions); return std::move(actions);
} }
const std::vector<e2d::Action*>& e2d::ActionManager::getAll() const std::vector<e2d::Action*>& e2d::ActionManager::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();
} }
} }

View File

@ -3,14 +3,14 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
e2d::CollisionManager * e2d::CollisionManager::getInstance() e2d::CollisionManager * e2d::CollisionManager::GetInstance()
{ {
static CollisionManager instance; static CollisionManager instance;
return &instance; return &instance;
} }
e2d::CollisionManager::CollisionManager() 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); auto iter = std::find(colliders_.begin(), colliders_.end(), collider);
if (iter != _colliders.end()) if (iter != colliders_.end())
{ {
_colliders.erase(iter); colliders_.erase(iter);
} }
} }
void e2d::CollisionManager::__updateCollider(Collider* active) void e2d::CollisionManager::UpdateCollider(Collider* active)
{ {
if (!_collisionEnabled || if (!collision_enabled_ ||
Game::getInstance()->isTransitioning()) Game::GetInstance()->IsTransitioning())
return; return;
auto currScene = Game::getInstance()->getCurrentScene(); auto currScene = Game::GetInstance()->GetCurrentScene();
if (active->getNode()->getParentScene() != currScene) if (active->GetNode()->GetParentScene() != currScene)
return; return;
std::vector<Collider*> currColliders; std::vector<Collider*> currColliders;
currColliders.reserve(_colliders.size()); currColliders.reserve(colliders_.size());
std::copy_if( std::copy_if(
_colliders.begin(), colliders_.begin(),
_colliders.end(), colliders_.end(),
std::back_inserter(currColliders), std::back_inserter(currColliders),
[this, active, currScene](Collider* passive) -> bool [this, active, currScene](Collider* passive) -> bool
{ {
return active != passive && return active != passive &&
passive->getNode()->isVisible() && passive->GetNode()->IsVisible() &&
passive->getNode()->getParentScene() == currScene && passive->GetNode()->GetParentScene() == currScene &&
this->isCollidable(active->getNode(), passive->getNode()); this->IsCollidable(active->GetNode(), passive->GetNode());
} }
); );
for (const auto& passive : currColliders) for (const auto& passive : currColliders)
{ {
// 判断两碰撞体交集情况 // 判断两碰撞体交集情况
Collider::Relation relation = active->getRelationWith(passive); Collider::Relation relation = active->GetRelationWith(passive);
// 忽略 UNKNOWN 和 DISJOIN 情况 // 忽略 UNKNOWN 和 DISJOIN 情况
if (relation != Collider::Relation::Unknown && if (relation != Collider::Relation::Unknown &&
relation != Collider::Relation::Disjoin) relation != Collider::Relation::Disjoin)
{ {
auto activeNode = active->getNode(); auto activeNode = active->GetNode();
auto passiveNode = passive->getNode(); auto passiveNode = passive->GetNode();
// 触发两次碰撞事件 // 触发两次碰撞事件
Collision activeCollision(passiveNode, relation); Collision activeCollision(passiveNode, relation);
if (dynamic_cast<CollisionHandler*>(activeNode)) if (dynamic_cast<CollisionHandler*>(activeNode))
dynamic_cast<CollisionHandler*>(activeNode)->handle(activeCollision); dynamic_cast<CollisionHandler*>(activeNode)->Handle(activeCollision);
Collision passiveCollision(activeNode, passive->getRelationWith(active)); Collision passiveCollision(activeNode, passive->GetRelationWith(active));
if (dynamic_cast<CollisionHandler*>(passiveNode)) if (dynamic_cast<CollisionHandler*>(passiveNode))
dynamic_cast<CollisionHandler*>(passiveNode)->handle(passiveCollision); dynamic_cast<CollisionHandler*>(passiveNode)->Handle(passiveCollision);
} }
} }
} }
void e2d::CollisionManager::setCollisionEnabled(bool enabled) void e2d::CollisionManager::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<std::pair<String, String> >& names) void e2d::CollisionManager::AddName(const std::vector<std::pair<String, String> >& names)
{ {
for (const auto& name : 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(), size_t hashName1 = name1.GetHash(),
hashName2 = name2.hash(); hashName2 = name2.GetHash();
auto pair1 = std::make_pair(hashName1, hashName2), auto pair1 = std::make_pair(hashName1, hashName2),
pair2 = std::make_pair(hashName2, hashName1); pair2 = std::make_pair(hashName2, hashName1);
for (const auto& pair : _collisionList) for (const auto& pair : collision_list_)
{ {
if (pair == pair1 || pair == pair2) if (pair == pair1 || pair == pair2)
{ {

View File

@ -6,254 +6,254 @@
#define SET_BUTTON_NODE(Old, New) \ #define SET_BUTTON_NODE(Old, New) \
if (New != Old) \ if (New != Old) \
{ \ { \
if (Old) this->removeChild(Old); \ if (Old) this->RemoveChild(Old); \
if (New) \ if (New) \
{ \ { \
New->setAnchor(_anchorX, _anchorY); \ New->SetAnchor(anchor_.x, anchor_.y); \
this->addChild(New); \ this->AddChild(New); \
} \ } \
Old = New; \ Old = New; \
_updateVisible(); \ UpdateVisible(); \
} \ } \
e2d::Button::Button() e2d::Button::Button()
: _func(nullptr) : callback_(nullptr)
, _status(Status::Normal) , status_(Status::Normal)
, _enabled(true) , enabled_(true)
, _isSelected(false) , is_selected_(false)
, _normal(nullptr) , normal_(nullptr)
, _mouseover(nullptr) , mouseover_(nullptr)
, _selected(nullptr) , selected_(nullptr)
, _disabled(nullptr) , disabled_(nullptr)
{ {
} }
e2d::Button::Button(Node * normal, const Function& func) e2d::Button::Button(Node * normal, const Function& func)
: _func(nullptr) : callback_(nullptr)
, _status(Status::Normal) , status_(Status::Normal)
, _enabled(true) , enabled_(true)
, _isSelected(false) , is_selected_(false)
, _normal(nullptr) , normal_(nullptr)
, _mouseover(nullptr) , mouseover_(nullptr)
, _selected(nullptr) , selected_(nullptr)
, _disabled(nullptr) , disabled_(nullptr)
{ {
this->setNormal(normal); this->SetNormal(normal);
this->setClickFunc(func); this->SetCallbackOnClick(func);
} }
e2d::Button::Button(Node * normal, Node * selected, const Function& func) e2d::Button::Button(Node * normal, Node * selected, const Function& func)
: _func(nullptr) : callback_(nullptr)
, _status(Status::Normal) , status_(Status::Normal)
, _enabled(true) , enabled_(true)
, _isSelected(false) , is_selected_(false)
, _normal(nullptr) , normal_(nullptr)
, _mouseover(nullptr) , mouseover_(nullptr)
, _selected(nullptr) , selected_(nullptr)
, _disabled(nullptr) , disabled_(nullptr)
{ {
this->setNormal(normal); this->SetNormal(normal);
this->setSelected(selected); this->SetSelected(selected);
this->setClickFunc(func); this->SetCallbackOnClick(func);
} }
e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Function& func) e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Function& func)
: _func(nullptr) : callback_(nullptr)
, _status(Status::Normal) , status_(Status::Normal)
, _enabled(true) , enabled_(true)
, _isSelected(false) , is_selected_(false)
, _normal(nullptr) , normal_(nullptr)
, _mouseover(nullptr) , mouseover_(nullptr)
, _selected(nullptr) , selected_(nullptr)
, _disabled(nullptr) , disabled_(nullptr)
{ {
this->setNormal(normal); this->SetNormal(normal);
this->setMouseOver(mouseover); this->SetMouseOver(mouseover);
this->setSelected(selected); this->SetSelected(selected);
this->setClickFunc(func); this->SetCallbackOnClick(func);
} }
e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Function& func) e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Function& func)
: _func(nullptr) : callback_(nullptr)
, _status(Status::Normal) , status_(Status::Normal)
, _enabled(true) , enabled_(true)
, _isSelected(false) , is_selected_(false)
, _normal(nullptr) , normal_(nullptr)
, _mouseover(nullptr) , mouseover_(nullptr)
, _selected(nullptr) , selected_(nullptr)
, _disabled(nullptr) , disabled_(nullptr)
{ {
this->setNormal(normal); this->SetNormal(normal);
this->setMouseOver(mouseover); this->SetMouseOver(mouseover);
this->setSelected(selected); this->SetSelected(selected);
this->setDisabled(disabled); this->SetDisabled(disabled);
this->setClickFunc(func); 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) 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; enabled_ = enabled;
_updateVisible(); 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); Node::SetAnchor(anchor_x, anchor_y);
SAFE_SET(_normal, setAnchor, anchorX, anchorY); SAFE_SET(normal_, SetAnchor, anchor_x, anchor_y);
SAFE_SET(_mouseover, setAnchor, anchorX, anchorY); SAFE_SET(mouseover_, SetAnchor, anchor_x, anchor_y);
SAFE_SET(_selected, setAnchor, anchorX, anchorY); SAFE_SET(selected_, SetAnchor, anchor_x, anchor_y);
SAFE_SET(_disabled, setAnchor, anchorX, anchorY); 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()); bool contains = normal_->ContainsPoint(e.GetPos());
if (e.getType() == MouseEvent::Type::LeftUp && _isSelected && contains) if (e.GetType() == MouseEvent::Type::LeftUp && is_selected_ && contains)
{ {
_runCallback(); OnClick();
_isSelected = false; is_selected_ = false;
_setStatus(Status::Normal); SetStatus(Status::Normal);
return true; return true;
} }
else if (e.getType() == MouseEvent::Type::LeftDown) else if (e.GetType() == MouseEvent::Type::LeftDown)
{ {
_isSelected = contains; is_selected_ = contains;
_setStatus(contains ? Status::Selected : Status::Normal); SetStatus(contains ? Status::Selected : Status::Normal);
if (contains) if (contains)
return true; 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; return true;
} }
else 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) if (contains)
return true; 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 && if (visible_ &&
!_enabled && !enabled_ &&
_normal && normal_ &&
_normal->containsPoint(Input::getInstance()->getMousePos())) 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; status_ = status;
_updateVisible(); UpdateVisible();
} }
} }
void e2d::Button::_updateVisible() void e2d::Button::UpdateVisible()
{ {
SAFE_SET(_normal, setVisible, false); SAFE_SET(normal_, SetVisible, false);
SAFE_SET(_mouseover, setVisible, false); SAFE_SET(mouseover_, SetVisible, false);
SAFE_SET(_selected, setVisible, false); SAFE_SET(selected_, SetVisible, false);
SAFE_SET(_disabled, 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 else
{ {
if (_normal) _normal->setVisible(true); if (normal_) normal_->SetVisible(true);
} }
} }
else else
{ {
if (_disabled) if (disabled_)
{ {
_disabled->setVisible(true); disabled_->SetVisible(true);
} }
else 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_();
} }
} }

View File

@ -1,108 +1,108 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::Canvas::Canvas(float width, float height) e2d::Canvas::Canvas(float width, float height)
: _renderTarget(nullptr) : render_target_(nullptr)
, _fillBrush(nullptr) , fill_brush_(nullptr)
, _lineBrush(nullptr) , line_brush_(nullptr)
, _strokeStyle(nullptr) , stroke_style_(nullptr)
, _strokeWidth(1.0f) , stroke_width_(1.0f)
, _stroke(Stroke::Miter) , stroke_(Stroke::Miter)
{ {
_renderTarget = Renderer::getInstance()->getRenderTarget(); render_target_ = Renderer::GetInstance()->GetRenderTarget();
_renderTarget->AddRef(); render_target_->AddRef();
ThrowIfFailed( ThrowIfFailed(
_renderTarget->CreateSolidColorBrush( render_target_->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::White), D2D1::ColorF(D2D1::ColorF::White),
&_fillBrush &fill_brush_
) )
); );
ThrowIfFailed( ThrowIfFailed(
_renderTarget->CreateSolidColorBrush( render_target_->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::White), D2D1::ColorF(D2D1::ColorF::White),
&_lineBrush &line_brush_
) )
); );
this->setClipEnabled(true); this->SetClipEnabled(true);
this->setWidth(width); this->SetWidth(width);
this->setHeight(height); this->SetHeight(height);
this->setStrokeStyle(_stroke); this->SetStrokeStyle(stroke_);
} }
e2d::Canvas::~Canvas() e2d::Canvas::~Canvas()
{ {
SafeRelease(_lineBrush); SafeRelease(line_brush_);
SafeRelease(_fillBrush); SafeRelease(fill_brush_);
SafeRelease(_renderTarget); 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) switch (strokeStyle)
{ {
case e2d::Stroke::Miter: case e2d::Stroke::Miter:
_strokeStyle = Renderer::getMiterStrokeStyle(); stroke_style_ = Renderer::GetMiterStrokeStyle();
break; break;
case e2d::Stroke::Bevel: case e2d::Stroke::Bevel:
_strokeStyle = Renderer::getBevelStrokeStyle(); stroke_style_ = Renderer::GetBevelStrokeStyle();
break; break;
case e2d::Stroke::Round: case e2d::Stroke::Round:
_strokeStyle = Renderer::getRoundStrokeStyle(); stroke_style_ = Renderer::GetRoundStrokeStyle();
break; 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(begin.x, begin.y),
D2D1::Point2F(end.x, end.y), D2D1::Point2F(end.x, end.y),
_lineBrush, line_brush_,
_strokeWidth, stroke_width_,
_strokeStyle 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::Ellipse(
D2D1::Point2F( D2D1::Point2F(
center.x, center.x,
@ -111,47 +111,47 @@ void e2d::Canvas::drawCircle(const Point & center, float radius)
radius, radius,
radius radius
), ),
_lineBrush, line_brush_,
_strokeWidth, stroke_width_,
_strokeStyle 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::Ellipse(
D2D1::Point2F( D2D1::Point2F(
center.x, center.x,
center.y center.y
), ),
radiusX, radius_x,
radiusY radius_y
), ),
_lineBrush, line_brush_,
_strokeWidth, stroke_width_,
_strokeStyle stroke_style_
); );
} }
void e2d::Canvas::drawRect(const Rect & rect) void e2d::Canvas::DrawRect(const Rect & rect)
{ {
_renderTarget->DrawRectangle( render_target_->DrawRectangle(
D2D1::RectF( D2D1::RectF(
rect.origin.x, rect.origin.x,
rect.origin.y, rect.origin.y,
rect.origin.x + rect.size.width, rect.origin.x + rect.size.width,
rect.origin.y + rect.size.height rect.origin.y + rect.size.height
), ),
_lineBrush, line_brush_,
_strokeWidth, stroke_width_,
_strokeStyle 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::RoundedRect(
D2D1::RectF( D2D1::RectF(
rect.origin.x, 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.x + rect.size.width,
rect.origin.y + rect.size.height rect.origin.y + rect.size.height
), ),
radiusX, radius_x,
radiusY radius_y
), ),
_lineBrush, line_brush_,
_strokeWidth, stroke_width_,
_strokeStyle 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::Ellipse(
D2D1::Point2F( D2D1::Point2F(
center.x, center.x,
@ -179,41 +179,41 @@ void e2d::Canvas::fillCircle(const Point & center, float radius)
radius, 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::Ellipse(
D2D1::Point2F( D2D1::Point2F(
center.x, center.x,
center.y center.y
), ),
radiusX, radius_x,
radiusY 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( D2D1::RectF(
rect.origin.x, rect.origin.x,
rect.origin.y, rect.origin.y,
rect.origin.x + rect.size.width, rect.origin.x + rect.size.width,
rect.origin.y + rect.size.height 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::RoundedRect(
D2D1::RectF( D2D1::RectF(
rect.origin.x, 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.x + rect.size.width,
rect.origin.y + rect.size.height rect.origin.y + rect.size.height
), ),
radiusX, radius_x,
radiusY radius_y
), ),
_fillBrush fill_brush_
); );
} }

View File

@ -1,76 +1,76 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::Menu::Menu() e2d::Menu::Menu()
: _enabled(true) : enabled_(true)
{ {
} }
e2d::Menu::Menu(const std::vector<Button*>& buttons) e2d::Menu::Menu(const std::vector<Button*>& buttons)
: _enabled(true) : enabled_(true)
{ {
for (const auto& button : buttons) 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) if (button)
{ {
this->addChild(button); this->AddChild(button);
_buttons.push_back(button); buttons_.push_back(button);
button->setEnabled(_enabled); button->SetEnabled(enabled_);
} }
} }
bool e2d::Menu::removeButton(Button * button) bool e2d::Menu::RemoveButton(Button * button)
{ {
if (_buttons.empty()) if (buttons_.empty())
{ {
return false; return false;
} }
this->removeChild(button); this->RemoveChild(button);
if (button) if (button)
{ {
auto iter = std::find(_buttons.begin(), _buttons.end(), button); auto iter = std::find(buttons_.begin(), buttons_.end(), button);
if (iter != _buttons.end()) if (iter != buttons_.end())
{ {
// 移除按钮前,将它启用 // 移除按钮前,将它启用
button->setEnabled(true); button->SetEnabled(true);
_buttons.erase(iter); buttons_.erase(iter);
return true; return true;
} }
} }
return false; return false;
} }
const std::vector<e2d::Button*>& e2d::Menu::getAllButtons() const const std::vector<e2d::Button*>& e2d::Menu::GetAllButtons() const
{ {
return _buttons; return buttons_;
} }

File diff suppressed because it is too large Load Diff

View File

@ -3,40 +3,40 @@
#include "..\e2dmanager.h" #include "..\e2dmanager.h"
e2d::Scene::Scene() e2d::Scene::Scene()
: _borderVisible(false) : border_visible_(false)
, _colliderVisible(false) , collider_visible_(false)
{ {
_parentScene = this; parent_scene_ = this;
} }
e2d::Scene::~Scene() 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()->GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity());
Renderer::getInstance()->getSolidColorBrush()->SetOpacity(1.f); Renderer::GetInstance()->GetSolidBrush()->SetOpacity(1.f);
this->_drawBorder(); this->DrawBorder();
} }
if (_colliderVisible) if (collider_visible_)
{ {
Renderer::getInstance()->getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); Renderer::GetInstance()->GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity());
this->_drawCollider(); this->DrawCollider();
} }
} }

View File

@ -2,125 +2,125 @@
e2d::Sprite::Sprite() e2d::Sprite::Sprite()
: _image(nullptr) : image_(nullptr)
{ {
} }
e2d::Sprite::Sprite(Image * image) e2d::Sprite::Sprite(Image * image)
: _image(nullptr) : image_(nullptr)
{ {
open(image); Open(image);
} }
e2d::Sprite::Sprite(const Resource& res) e2d::Sprite::Sprite(const Resource& res)
: _image(nullptr) : image_(nullptr)
{ {
open(res); Open(res);
} }
e2d::Sprite::Sprite(const Resource& res, const Rect& cropRect) e2d::Sprite::Sprite(const Resource& res, const Rect& crop_rect)
: _image(nullptr) : image_(nullptr)
{ {
open(res); Open(res);
crop(cropRect); Crop(crop_rect);
} }
e2d::Sprite::Sprite(const String & fileName) e2d::Sprite::Sprite(const String & file_name)
: _image(nullptr) : image_(nullptr)
{ {
open(fileName); Open(file_name);
} }
e2d::Sprite::Sprite(const String & fileName, const Rect & cropRect) e2d::Sprite::Sprite(const String & file_name, const Rect & crop_rect)
: _image(nullptr) : image_(nullptr)
{ {
open(fileName); Open(file_name);
crop(cropRect); Crop(crop_rect);
} }
e2d::Sprite::~Sprite() 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)
{ {
if (_image) _image->release(); if (image_) image_->Release();
_image = image; image_ = image;
_image->retain(); image_->Retain();
Node::setSize(_image->getWidth(), _image->getHeight()); Node::SetSize(image_->GetWidth(), image_->GetHeight());
return true; return true;
} }
return false; 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_ = new (e2d::autorelease) Image();
_image->retain(); 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 true;
} }
return false; 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_ = new (e2d::autorelease) Image();
_image->retain(); 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 true;
} }
return false; return false;
} }
void e2d::Sprite::crop(const Rect& cropRect) void e2d::Sprite::Crop(const Rect& crop_rect)
{ {
_image->crop(cropRect); image_->Crop(crop_rect);
Node::setSize( Node::SetSize(
std::min(std::max(cropRect.size.width, 0.f), _image->getSourceWidth() - _image->getCropX()), std::min(std::max(crop_rect.size.width, 0.f), image_->GetSourceWidth() - image_->GetCropX()),
std::min(std::max(cropRect.size.height, 0.f), _image->getSourceHeight() - _image->getCropY()) 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 fCropX = image_->GetCropX();
float fCropY = _image->getCropY(); float fCropY = image_->GetCropY();
// äÖȾͼƬ // äÖȾͼƬ
Renderer::getInstance()->getRenderTarget()->DrawBitmap( Renderer::GetInstance()->GetRenderTarget()->DrawBitmap(
_image->getBitmap(), image_->GetBitmap(),
D2D1::RectF(0, 0, _width, _height), D2D1::RectF(0, 0, size_.width, size_.height),
_displayOpacity, display_opacity_,
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
D2D1::RectF( D2D1::RectF(
fCropX, fCropX,
fCropY, fCropY,
fCropX + _width, fCropX + size_.width,
fCropY + _height fCropY + size_.height
) )
); );
} }

View File

@ -7,41 +7,41 @@
e2d::Text::Style::Style() e2d::Text::Style::Style()
: color(Color::White) : color(Color::White)
, alignment(Align::Left) , alignment(Align::Left)
, wrapping(false) , wrap(false)
, wrappingWidth(0.f) , wrap_width(0.f)
, lineSpacing(0.f) , line_spacing(0.f)
, hasUnderline(false) , underline(false)
, hasStrikethrough(false) , strikethrough(false)
, hasOutline(true) , outline(true)
, outlineColor(Color(Color::Black, 0.5)) , outline_color(Color(Color::Black, 0.5))
, outlineWidth(1.f) , outline_width(1.f)
, outlineStroke(Stroke::Round) , outline_stroke(Stroke::Round)
{} {}
e2d::Text::Style::Style( e2d::Text::Style::Style(
Color color, Color color,
Align alignment, Align alignment,
bool wrapping, bool wrap,
float wrappingWidth, float wrap_width,
float lineSpacing, float line_spacing,
bool hasUnderline, bool underline,
bool hasStrikethrough, bool strikethrough,
bool hasOutline, bool outline,
Color outlineColor, Color outline_color,
float outlineWidth, float outline_width,
Stroke outlineStroke Stroke outline_stroke
) )
: color(color) : color(color)
, alignment(alignment) , alignment(alignment)
, wrapping(wrapping) , wrap(wrap)
, wrappingWidth(wrappingWidth) , wrap_width(wrap_width)
, lineSpacing(lineSpacing) , line_spacing(line_spacing)
, hasUnderline(hasUnderline) , underline(underline)
, hasStrikethrough(hasStrikethrough) , strikethrough(strikethrough)
, hasOutline(hasOutline) , outline(outline)
, outlineColor(outlineColor) , outline_color(outline_color)
, outlineWidth(outlineWidth) , outline_width(outline_width)
, outlineStroke(outlineStroke) , outline_stroke(outline_stroke)
{} {}
@ -51,85 +51,85 @@ e2d::Text::Style::Style(
//------------------------------------------------------- //-------------------------------------------------------
e2d::Text::Text() e2d::Text::Text()
: _font() : font_()
, _style() , style_()
, _textLayout(nullptr) , text_layout_(nullptr)
, _textFormat(nullptr) , text_format_(nullptr)
{ {
} }
e2d::Text::Text(const String & text, const Font & font, const Style & style) e2d::Text::Text(const String & text, const Font & font, const Style & style)
: _font(font) : font_(font)
, _style(style) , style_(style)
, _textLayout(nullptr) , text_layout_(nullptr)
, _textFormat(nullptr) , text_format_(nullptr)
, _text(text) , text_(text)
{ {
_reset(); Reset();
} }
e2d::Text::~Text() e2d::Text::~Text()
{ {
SafeRelease(_textFormat); SafeRelease(text_format_);
SafeRelease(_textLayout); 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; DWRITE_TEXT_METRICS metrics;
_textLayout->GetMetrics(&metrics); text_layout_->GetMetrics(&metrics);
return static_cast<int>(metrics.lineCount); return static_cast<int>(metrics.lineCount);
} }
else 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; text_ = text;
_reset(); Reset();
} }
void e2d::Text::setStyle(const Style& style) void e2d::Text::SetStyle(const Style& style)
{ {
_style = style; style_ = style;
_reset(); Reset();
} }
void e2d::Text::setFont(const Font & font) void e2d::Text::SetFont(const Font & font)
{ {
_font = font; font_ = font;
_reset(); Reset();
} }
void e2d::Text::setFontFamily(const String& family) void e2d::Text::SetFontFamily(const String& family)
{ {
_font.family = family; font_.family = family;
_reset(); Reset();
} }
void e2d::Text::setFontSize(float size) void e2d::Text::SetFontSize(float size)
{ {
_font.size = size; font_.size = size;
_reset(); Reset();
} }
void e2d::Text::setFontWeight(UINT weight) void e2d::Text::SetFontWeight(UINT weight)
{ {
_font.weight = weight; font_.weight = weight;
_reset(); 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; font_.italic = value;
_reset(); Reset();
} }
void e2d::Text::setWrapping(bool wrapping) void e2d::Text::SetWrapEnabled(bool wrap)
{ {
if (_style.wrapping != wrapping) if (style_.wrap != wrap)
{ {
_style.wrapping = wrapping; style_.wrap = wrap;
_reset(); 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; style_.line_spacing = line_spacing;
_reset(); Reset();
} }
} }
void e2d::Text::setAlignment(Align align) void e2d::Text::SetAlignment(Align align)
{ {
if (_style.alignment != align) if (style_.alignment != align)
{ {
_style.alignment = align; style_.alignment = align;
_reset(); Reset();
} }
} }
void e2d::Text::setUnderline(bool hasUnderline) void e2d::Text::SetUnderline(bool underline)
{ {
if (_style.hasUnderline != hasUnderline) if (style_.underline != underline)
{ {
_style.hasUnderline = hasUnderline; style_.underline = underline;
if (!_textFormat) if (!text_format_)
_createFormat(); CreateFormat();
_createLayout(); CreateLayout();
} }
} }
void e2d::Text::setStrikethrough(bool hasStrikethrough) void e2d::Text::SetStrikethrough(bool strikethrough)
{ {
if (_style.hasStrikethrough != hasStrikethrough) if (style_.strikethrough != strikethrough)
{ {
_style.hasStrikethrough = hasStrikethrough; style_.strikethrough = strikethrough;
if (!_textFormat) if (!text_format_)
_createFormat(); CreateFormat();
_createLayout(); 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( textRenderer->SetTextStyle(
(D2D1_COLOR_F)_style.color, (D2D1_COLOR_F)style_.color,
_style.hasOutline, style_.outline,
(D2D1_COLOR_F)_style.outlineColor, (D2D1_COLOR_F)style_.outline_color,
_style.outlineWidth, style_.outline_width,
D2D1_LINE_JOIN(_style.outlineStroke) 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( ThrowIfFailed(
Renderer::getWriteFactory()->CreateTextFormat( Renderer::GetWriteFactory()->CreateTextFormat(
(const WCHAR *)_font.family, (const WCHAR *)font_.family,
nullptr, nullptr,
DWRITE_FONT_WEIGHT(_font.weight), DWRITE_FONT_WEIGHT(font_.weight),
_font.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL, font_.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL, DWRITE_FONT_STRETCH_NORMAL,
_font.size, font_.size,
L"", 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 else
{ {
_textFormat->SetLineSpacing( text_format_->SetLineSpacing(
DWRITE_LINE_SPACING_METHOD_UNIFORM, DWRITE_LINE_SPACING_METHOD_UNIFORM,
_style.lineSpacing, style_.line_spacing,
_style.lineSpacing * 0.8f 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 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; 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; return;
} }
UINT32 length = (UINT32)_text.length(); UINT32 length = (UINT32)text_.GetLength();
auto writeFactory = Renderer::getWriteFactory(); auto writeFactory = Renderer::GetWriteFactory();
// 对文本自动换行情况下进行处理 // 对文本自动换行情况下进行处理
if (_style.wrapping) if (style_.wrap)
{ {
ThrowIfFailed( ThrowIfFailed(
writeFactory->CreateTextLayout( writeFactory->CreateTextLayout(
(const WCHAR *)_text, (const WCHAR *)text_,
length, length,
_textFormat, text_format_,
_style.wrappingWidth, style_.wrap_width,
0, 0,
&_textLayout &text_layout_
) )
); );
// 获取文本布局的宽度和高度 // 获取文本布局的宽度和高度
DWRITE_TEXT_METRICS metrics; DWRITE_TEXT_METRICS metrics;
_textLayout->GetMetrics(&metrics); text_layout_->GetMetrics(&metrics);
// 重设文本宽高 // 重设文本宽高
this->setSize(metrics.layoutWidth, metrics.height); this->SetSize(metrics.layoutWidth, metrics.height);
} }
else else
{ {
// 为防止文本对齐问题,根据先创建 layout 以获取宽度 // 为防止文本对齐问题,根据先创建 layout 以获取宽度
ThrowIfFailed( ThrowIfFailed(
writeFactory->CreateTextLayout( writeFactory->CreateTextLayout(
(const WCHAR *)_text, (const WCHAR *)text_,
length, length,
_textFormat, text_format_,
0, 0,
0, 0,
&_textLayout &text_layout_
) )
); );
// 获取文本布局的宽度和高度 // 获取文本布局的宽度和高度
DWRITE_TEXT_METRICS metrics; DWRITE_TEXT_METRICS metrics;
_textLayout->GetMetrics(&metrics); text_layout_->GetMetrics(&metrics);
// 重设文本宽高 // 重设文本宽高
this->setSize(metrics.width, metrics.height); this->SetSize(metrics.width, metrics.height);
// 重新创建 layout // 重新创建 layout
SafeRelease(_textLayout); SafeRelease(text_layout_);
ThrowIfFailed( ThrowIfFailed(
writeFactory->CreateTextLayout( writeFactory->CreateTextLayout(
(const WCHAR *)_text, (const WCHAR *)text_,
length, length,
_textFormat, text_format_,
_width, size_.width,
0, 0,
&_textLayout &text_layout_
) )
); );
} }
// 添加下划线和删除线 // 添加下划线和删除线
DWRITE_TEXT_RANGE range = { 0, length }; DWRITE_TEXT_RANGE Range = { 0, length };
if (_style.hasUnderline) 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);
} }
} }

View File

@ -5,215 +5,215 @@
#define SET_BUTTON_NODE(Old, New) \ #define SET_BUTTON_NODE(Old, New) \
if (New != Old) \ if (New != Old) \
{ \ { \
if (Old) this->removeChild(Old); \ if (Old) this->RemoveChild(Old); \
if (New) \ if (New) \
{ \ { \
New->setAnchor(_anchorX, _anchorY); \ New->SetAnchor(anchor_.x, anchor_.y); \
this->addChild(New); \ this->AddChild(New); \
} \ } \
Old = New; \ Old = New; \
_updateStatus(); \ UpdateStatus(); \
_updateVisible(); \ UpdateVisible(); \
} \ } \
e2d::ToggleButton::ToggleButton() e2d::ToggleButton::ToggleButton()
: Button() : Button()
, _checked(true) , checked_(true)
, _normalOn(nullptr) , normal_on_(nullptr)
, _mouseoverOn(nullptr) , mouseover_on_(nullptr)
, _selectedOn(nullptr) , selected_on_(nullptr)
, _disabledOn(nullptr) , disabled_on_(nullptr)
, _normalOff(nullptr) , normal_off_(nullptr)
, _mouseoverOff(nullptr) , mouseover_off_(nullptr)
, _selectedOff(nullptr) , selected_off_(nullptr)
, _disabledOff(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() : Button()
, _checked(true) , checked_(true)
, _normalOn(nullptr) , normal_on_(nullptr)
, _mouseoverOn(nullptr) , mouseover_on_(nullptr)
, _selectedOn(nullptr) , selected_on_(nullptr)
, _disabledOn(nullptr) , disabled_on_(nullptr)
, _normalOff(nullptr) , normal_off_(nullptr)
, _mouseoverOff(nullptr) , mouseover_off_(nullptr)
, _selectedOff(nullptr) , selected_off_(nullptr)
, _disabledOff(nullptr) , disabled_off_(nullptr)
{ {
this->setNormal(toggleOnNormal); this->SetNormal(normal_on);
this->setNormalOff(toggleOffNormal); this->SetNormalOff(normal_off);
this->setClickFunc(func); 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() : Button()
, _checked(true) , checked_(true)
, _normalOn(nullptr) , normal_on_(nullptr)
, _mouseoverOn(nullptr) , mouseover_on_(nullptr)
, _selectedOn(nullptr) , selected_on_(nullptr)
, _disabledOn(nullptr) , disabled_on_(nullptr)
, _normalOff(nullptr) , normal_off_(nullptr)
, _mouseoverOff(nullptr) , mouseover_off_(nullptr)
, _selectedOff(nullptr) , selected_off_(nullptr)
, _disabledOff(nullptr) , disabled_off_(nullptr)
{ {
this->setNormal(toggleOnNormal); this->SetNormal(normal_on);
this->setNormalOff(toggleOffNormal); this->SetNormalOff(normal_off);
this->setSelected(toggleOnSelected); this->SetSelected(selected_on);
this->setSelectedOff(toggleOffSelected); this->SetSelectedOff(selected_off);
this->setClickFunc(func); 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() : Button()
, _checked(true) , checked_(true)
, _normalOn(nullptr) , normal_on_(nullptr)
, _mouseoverOn(nullptr) , mouseover_on_(nullptr)
, _selectedOn(nullptr) , selected_on_(nullptr)
, _disabledOn(nullptr) , disabled_on_(nullptr)
, _normalOff(nullptr) , normal_off_(nullptr)
, _mouseoverOff(nullptr) , mouseover_off_(nullptr)
, _selectedOff(nullptr) , selected_off_(nullptr)
, _disabledOff(nullptr) , disabled_off_(nullptr)
{ {
this->setNormal(toggleOnNormal); this->SetNormal(normal_on);
this->setNormalOff(toggleOffNormal); this->SetNormalOff(normal_off);
this->setMouseOver(toggleOnMouseOver); this->SetMouseOver(mouseover_on);
this->setMouseOverOff(toggleOffMouseOver); this->SetMouseOverOff(mouseover_off);
this->setSelected(toggleOnSelected); this->SetSelected(selected_on);
this->setSelectedOff(toggleOffSelected); this->SetSelectedOff(selected_off);
this->setClickFunc(func); 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() : Button()
, _checked(true) , checked_(true)
, _normalOff(nullptr) , normal_off_(nullptr)
, _mouseoverOff(nullptr) , mouseover_off_(nullptr)
, _selectedOff(nullptr) , selected_off_(nullptr)
, _disabledOff(nullptr) , disabled_off_(nullptr)
{ {
this->setNormal(toggleOnNormal); this->SetNormal(normal_on);
this->setNormalOff(toggleOffNormal); this->SetNormalOff(normal_off);
this->setMouseOver(toggleOnMouseOver); this->SetMouseOver(mouseover_on);
this->setMouseOverOff(toggleOffMouseOver); this->SetMouseOverOff(mouseover_off);
this->setSelected(toggleOnSelected); this->SetSelected(selected_on);
this->setSelectedOff(toggleOffSelected); this->SetSelectedOff(selected_off);
this->setDisabled(toggleOnDisabled); this->SetDisabled(disabled_on);
this->setDisabledOff(toggleOffDisabled); this->SetDisabledOff(disabled_off);
this->setClickFunc(func); 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; checked_ = checked;
_updateStatus(); UpdateStatus();
_updateVisible(); 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) 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); Node::SetAnchor(anchor_x, anchor_y);
SAFE_SET(_normalOn, setAnchor, anchorX, anchorY); SAFE_SET(normal_on_, SetAnchor, anchor_x, anchor_y);
SAFE_SET(_mouseoverOn, setAnchor, anchorX, anchorY); SAFE_SET(mouseover_on_, SetAnchor, anchor_x, anchor_y);
SAFE_SET(_selectedOn, setAnchor, anchorX, anchorY); SAFE_SET(selected_on_, SetAnchor, anchor_x, anchor_y);
SAFE_SET(_disabledOn, setAnchor, anchorX, anchorY); SAFE_SET(disabled_on_, SetAnchor, anchor_x, anchor_y);
SAFE_SET(_normalOff, setAnchor, anchorX, anchorY); SAFE_SET(normal_off_, SetAnchor, anchor_x, anchor_y);
SAFE_SET(_mouseoverOff, setAnchor, anchorX, anchorY); SAFE_SET(mouseover_off_, SetAnchor, anchor_x, anchor_y);
SAFE_SET(_selectedOff, setAnchor, anchorX, anchorY); SAFE_SET(selected_off_, SetAnchor, anchor_x, anchor_y);
SAFE_SET(_disabledOff, setAnchor, anchorX, anchorY); SAFE_SET(disabled_off_, SetAnchor, anchor_x, anchor_y);
} }
void e2d::ToggleButton::_updateStatus() void e2d::ToggleButton::UpdateStatus()
{ {
if (_checked) if (checked_)
{ {
_normal = _normalOn; normal_ = normal_on_;
_mouseover = _mouseoverOn; mouseover_ = mouseover_on_;
_selected = _selectedOn; selected_ = selected_on_;
_disabled = _disabledOn; disabled_ = disabled_on_;
SAFE_SET(_normalOff, setVisible, false); SAFE_SET(normal_off_, SetVisible, false);
SAFE_SET(_mouseoverOff, setVisible, false); SAFE_SET(mouseover_off_, SetVisible, false);
SAFE_SET(_selectedOff, setVisible, false); SAFE_SET(selected_off_, SetVisible, false);
SAFE_SET(_disabledOff, setVisible, false); SAFE_SET(disabled_off_, SetVisible, false);
} }
else else
{ {
_normal = _normalOff; normal_ = normal_off_;
_mouseover = _mouseoverOff; mouseover_ = mouseover_off_;
_selected = _selectedOff; selected_ = selected_off_;
_disabled = _disabledOff; disabled_ = disabled_off_;
SAFE_SET(_normalOn, setVisible, false); SAFE_SET(normal_on_, SetVisible, false);
SAFE_SET(_mouseoverOn, setVisible, false); SAFE_SET(mouseover_on_, SetVisible, false);
SAFE_SET(_selectedOn, setVisible, false); SAFE_SET(selected_on_, SetVisible, false);
SAFE_SET(_disabledOn, setVisible, false); SAFE_SET(disabled_on_, SetVisible, false);
} }
} }
void e2d::ToggleButton::_runCallback() void e2d::ToggleButton::OnClick()
{ {
_checked = !_checked; checked_ = !checked_;
_updateStatus(); UpdateStatus();
if (_func) if (callback_)
{ {
_func(); callback_();
} }
} }

View File

@ -2,89 +2,89 @@
e2d::Data::Data(const String & key, const String & field) e2d::Data::Data(const String & key, const String & field)
: _key(key) : key_(key)
, _field(field) , field_(field)
, _dataPath(Path::getDataPath()) , data_path_(Path::GetDataPath())
{ {
} }
void e2d::Data::saveInt(int value) void e2d::Data::SaveInt(int value)
{ {
::WritePrivateProfileString( ::WritePrivateProfileString(
(LPCWSTR)_field, (LPCWSTR)field_,
(LPCWSTR)_key, (LPCWSTR)key_,
(LPCWSTR)String::parse(value), (LPCWSTR)String::Parse(value),
(LPCWSTR)_dataPath (LPCWSTR)data_path_
); );
} }
void e2d::Data::saveDouble(float value) void e2d::Data::SaveDouble(float value)
{ {
::WritePrivateProfileString( ::WritePrivateProfileString(
(LPCWSTR)_field, (LPCWSTR)field_,
(LPCWSTR)_key, (LPCWSTR)key_,
(LPCWSTR)String::parse(value), (LPCWSTR)String::Parse(value),
(LPCWSTR)_dataPath (LPCWSTR)data_path_
); );
} }
void e2d::Data::saveBool(bool value) void e2d::Data::SaveBool(bool value)
{ {
::WritePrivateProfileString( ::WritePrivateProfileString(
(LPCWSTR)_field, (LPCWSTR)field_,
(LPCWSTR)_key, (LPCWSTR)key_,
(value ? L"1" : L"0"), (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( ::WritePrivateProfileString(
(LPCWSTR)_field, (LPCWSTR)field_,
(LPCWSTR)_key, (LPCWSTR)key_,
(LPCWSTR)value, (LPCWSTR)value,
(LPCWSTR)_dataPath (LPCWSTR)data_path_
); );
} }
int e2d::Data::getInt(int defaultValue) int e2d::Data::GetInt(int default_value)
{ {
return ::GetPrivateProfileInt( return ::GetPrivateProfileInt(
(LPCWSTR)_field, (LPCWSTR)field_,
(LPCWSTR)_key, (LPCWSTR)key_,
defaultValue, default_value,
(LPCWSTR)_dataPath (LPCWSTR)data_path_
); );
} }
float e2d::Data::getDouble(float defaultValue) float e2d::Data::GetDouble(float default_value)
{ {
wchar_t temp[32] = { 0 }; wchar_t temp[32] = { 0 };
::GetPrivateProfileString((LPCWSTR)_field, (LPCWSTR)_key, (LPCWSTR)String::parse(defaultValue), temp, 31, (LPCWSTR)_dataPath); ::GetPrivateProfileString((LPCWSTR)field_, (LPCWSTR)key_, (LPCWSTR)String::Parse(default_value), temp, 31, (LPCWSTR)data_path_);
return std::stof(temp); return std::stof(temp);
} }
bool e2d::Data::getBool(bool defaultValue) bool e2d::Data::GetBool(bool default_value)
{ {
int nValue = ::GetPrivateProfileInt( int nValue = ::GetPrivateProfileInt(
(LPCWSTR)_field, (LPCWSTR)field_,
(LPCWSTR)_key, (LPCWSTR)key_,
defaultValue ? 1 : 0, default_value ? 1 : 0,
(LPCWSTR)_dataPath); (LPCWSTR)data_path_);
return nValue != 0; 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 }; wchar_t temp[256] = { 0 };
::GetPrivateProfileString( ::GetPrivateProfileString(
(LPCWSTR)_field, (LPCWSTR)field_,
(LPCWSTR)_key, (LPCWSTR)key_,
(LPCWSTR)defaultValue, (LPCWSTR)default_value,
temp, temp,
255, 255,
(LPCWSTR)_dataPath (LPCWSTR)data_path_
); );
return temp; return temp;
} }

View File

@ -1,49 +1,49 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
#include <shobjidl.h> #include <shobjidl.h>
std::list<e2d::String> e2d::File::_searchPaths; std::list<e2d::String> e2d::File::search_paths_;
e2d::File::File() e2d::File::File()
: _fileName() : file_path_()
, _attributes(0) , attributes_(0)
{ {
} }
e2d::File::File(const String & fileName) e2d::File::File(const String & file_name)
: _fileName(fileName) : file_path_(file_name)
, _attributes(0) , attributes_(0)
{ {
this->open(fileName); this->Open(file_name);
} }
e2d::File::~File() e2d::File::~File()
{ {
} }
bool e2d::File::open(const String & fileName) bool e2d::File::Open(const String & file_name)
{ {
auto FindFile = [=](const String & path) -> bool auto FindFile = [=](const String & path) -> bool
{ {
if (::_waccess((const wchar_t*)path, 0) == 0) if (::_waccess((const wchar_t*)path, 0) == 0)
{ {
_attributes = ::GetFileAttributes((LPCTSTR)path); attributes_ = ::GetFileAttributes((LPCTSTR)path);
return true; return true;
} }
return false; return false;
}; };
if (FindFile(fileName)) if (FindFile(file_name))
{ {
_fileName = fileName; file_path_ = file_name;
return true; return true;
} }
else 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; return true;
} }
} }
@ -51,54 +51,62 @@ bool e2d::File::open(const String & fileName)
return false; 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; String fileExtension;
// 找到文件名中的最后一个 '.' 的位置 // 找到文件名中的最后一个 '.' 的位置
size_t pos = std::wstring(_fileName).find_last_of(L'.'); size_t pos = std::wstring(file_path_).find_last_of(L'.');
// 判断 pos 是否是有效位置 // 判断 pos 是否是有效位置
if (pos != std::wstring::npos) if (pos != std::wstring::npos)
{ {
// 截取扩展名 // 截取扩展名
fileExtension = _fileName.subtract(static_cast<int>(pos)); fileExtension = file_path_.Subtract(static_cast<int>(pos));
// 转换为小写字母 // 转换为小写字母
fileExtension = fileExtension.toLower(); fileExtension = fileExtension.ToLower();
} }
return std::move(fileExtension); return std::move(fileExtension);
} }
bool e2d::File::del() bool e2d::File::Delete()
{ {
if (::DeleteFile((LPCWSTR)_fileName)) if (::DeleteFile((LPCWSTR)file_path_))
return true; return true;
return false; 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<LPCWSTR>(dest_file_name),
GENERIC_WRITE,
NULL,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_TEMPORARY,
NULL
);
if (hFile == INVALID_HANDLE_VALUE) if (hFile == INVALID_HANDLE_VALUE)
return std::move(File()); 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); HGLOBAL hMem = ::LoadResource(NULL, hRes);
DWORD dwSize = ::SizeofResource(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; DWORD dwWrite = 0;
::WriteFile(hFile, hMem, dwSize, &dwWrite, NULL); ::WriteFile(hFile, hMem, dwSize, &dwWrite, NULL);
::CloseHandle(hFile); ::CloseHandle(hFile);
return File(destFilePath); return File(dest_file_name);
} }
else else
{ {
::CloseHandle(hFile); ::CloseHandle(hFile);
::DeleteFile((LPCWSTR)destFilePath); ::DeleteFile(static_cast<LPCWSTR>(dest_file_name));
return std::move(File()); return std::move(File());
} }
} }
void e2d::File::addSearchPath(const String & path) void e2d::File::AddSearchPath(const String & path)
{ {
String tmp = path; String tmp = path;
tmp.replace(L"/", L"\\"); tmp.Replace(L"/", L"\\");
if (tmp[tmp.length() - 1] != L'\\') if (tmp[tmp.GetLength() - 1] != L'\\')
{ {
tmp << L"\\"; tmp << L"\\";
} }
auto iter = std::find(_searchPaths.cbegin(), _searchPaths.cend(), tmp); auto iter = std::find(search_paths_.cbegin(), search_paths_.cend(), tmp);
if (iter == _searchPaths.cend()) 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; return false;
wchar_t tmpDirPath[_MAX_PATH] = { 0 }; wchar_t tmpDirPath[_MAX_PATH] = { 0 };
int length = dirPath.length(); int length = dir_path.GetLength();
for (int i = 0; i < length; ++i) 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 (tmpDirPath[i] == L'\\' || tmpDirPath[i] == L'/' || i == (length - 1))
{ {
if (::_waccess(tmpDirPath, 0) != 0) if (::_waccess(tmpDirPath, 0) != 0)
@ -158,9 +166,9 @@ bool e2d::File::createFolder(const String & dirPath)
return true; 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); HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
@ -172,12 +180,12 @@ e2d::File e2d::File::showOpenDialog(const String & title, const String & filter)
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
if (!title.isEmpty()) if (!title.IsEmpty())
{ {
pFileOpen->SetTitle(LPCWSTR(title)); pFileOpen->SetTitle(LPCWSTR(title));
} }
if (!filter.isEmpty()) if (!filter.IsEmpty())
{ {
COMDLG_FILTERSPEC rgSpec[] = COMDLG_FILTERSPEC rgSpec[] =
{ {
@ -194,12 +202,12 @@ e2d::File e2d::File::showOpenDialog(const String & title, const String & filter)
pFileOpen->SetFileTypes(1, rgSpec); pFileOpen->SetFileTypes(1, rgSpec);
} }
Game::getInstance()->pause(); Game::GetInstance()->Pause();
{ {
HWND hWnd = Window::getInstance()->getHWnd(); HWND hWnd = Window::GetInstance()->GetHWnd();
hr = pFileOpen->Show(hWnd); hr = pFileOpen->Show(hWnd);
} }
Game::getInstance()->resume(); Game::GetInstance()->Resume();
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
@ -212,7 +220,7 @@ e2d::File e2d::File::showOpenDialog(const String & title, const String & filter)
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
filePath = pszFilePath; file_path = pszFilePath;
::CoTaskMemFree(pszFilePath); ::CoTaskMemFree(pszFilePath);
} }
pItem->Release(); pItem->Release();
@ -222,12 +230,12 @@ e2d::File e2d::File::showOpenDialog(const String & title, const String & filter)
} }
::CoUninitialize(); ::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); HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
@ -239,21 +247,21 @@ e2d::File e2d::File::showSaveDialog(const String & title, const String& defFile,
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
if (!title.isEmpty()) if (!title.IsEmpty())
{ {
pFileSave->SetTitle(LPCWSTR(title)); 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[] = COMDLG_FILTERSPEC rgSpec[] =
{ {
{ L"", LPCWSTR(spec) } { L"", LPCWSTR(spec) }
@ -269,12 +277,12 @@ e2d::File e2d::File::showSaveDialog(const String & title, const String& defFile,
pFileSave->SetFileTypes(1, rgSpec); pFileSave->SetFileTypes(1, rgSpec);
} }
Game::getInstance()->pause(); Game::GetInstance()->Pause();
{ {
HWND hWnd = Window::getInstance()->getHWnd(); HWND hWnd = Window::GetInstance()->GetHWnd();
hr = pFileSave->Show(hWnd); hr = pFileSave->Show(hWnd);
} }
Game::getInstance()->resume(); Game::GetInstance()->Resume();
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
@ -287,7 +295,7 @@ e2d::File e2d::File::showSaveDialog(const String & title, const String& defFile,
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
filePath = pszFilePath; file_path = pszFilePath;
::CoTaskMemFree(pszFilePath); ::CoTaskMemFree(pszFilePath);
} }
pItem->Release(); pItem->Release();
@ -297,5 +305,5 @@ e2d::File e2d::File::showSaveDialog(const String & title, const String& defFile,
} }
::CoUninitialize(); ::CoUninitialize();
} }
return std::move(File(filePath)); return std::move(File(file_path));
} }

View File

@ -23,65 +23,65 @@ inline bool TraceError(wchar_t* sPrompt, HRESULT hr)
e2d::Music::Music() e2d::Music::Music()
: _opened(false) : opened_(false)
, _wfx(nullptr) , wfx_(nullptr)
, _hmmio(nullptr) , hmmio_(nullptr)
, _resBuffer(nullptr) , buffer_(nullptr)
, _waveData(nullptr) , wave_data_(nullptr)
, _dwSize(0) , size_(0)
, _voice(nullptr) , voice_(nullptr)
, _voiceCallback() , callback_()
{ {
} }
e2d::Music::Music(const e2d::String & filePath) e2d::Music::Music(const e2d::String & file_path)
: _opened(false) : opened_(false)
, _wfx(nullptr) , wfx_(nullptr)
, _hmmio(nullptr) , hmmio_(nullptr)
, _resBuffer(nullptr) , buffer_(nullptr)
, _waveData(nullptr) , wave_data_(nullptr)
, _dwSize(0) , size_(0)
, _voice(nullptr) , voice_(nullptr)
, _voiceCallback() , callback_()
{ {
this->open(filePath); this->Open(file_path);
} }
e2d::Music::Music(const Resource& res) e2d::Music::Music(const Resource& res)
: _opened(false) : opened_(false)
, _wfx(nullptr) , wfx_(nullptr)
, _hmmio(nullptr) , hmmio_(nullptr)
, _resBuffer(nullptr) , buffer_(nullptr)
, _waveData(nullptr) , wave_data_(nullptr)
, _dwSize(0) , size_(0)
, _voice(nullptr) , voice_(nullptr)
, _voiceCallback() , callback_()
{ {
this->open(res); this->Open(res);
} }
e2d::Music::~Music() 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; return false;
} }
String actualFilePath = File(filePath).getPath(); String actualFilePath = File(file_path).GetPath();
if (actualFilePath.isEmpty()) if (actualFilePath.IsEmpty())
{ {
WARN("MusicInfo::open File not found."); WARN("MusicInfo::Open File not found.");
return false; return false;
} }
@ -89,13 +89,13 @@ bool e2d::Music::open(const e2d::String & filePath)
wchar_t pFilePath[MAX_PATH]; wchar_t pFilePath[MAX_PATH];
if (!_findMediaFileCch(pFilePath, MAX_PATH, (const wchar_t *)actualFilePath)) 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; 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"); return TraceError(L"mmioOpen");
} }
@ -103,46 +103,46 @@ bool e2d::Music::open(const e2d::String & filePath)
if (!_readMMIO()) if (!_readMMIO())
{ {
// 读取非 wave 文件时 ReadMMIO 调用失败 // 读取非 wave 文件时 ReadMMIO 调用失败
mmioClose(_hmmio, 0); mmioClose(hmmio_, 0);
return TraceError(L"ReadMMIO"); return TraceError(L"ReadMMIO");
} }
if (!_resetFile()) if (!_resetFile())
return TraceError(L"ResetFile"); return TraceError(L"ResetFile");
// 重置文件后wave 文件的大小是 _ck.cksize // 重置文件后wave 文件的大小是 ck_.cksize
_dwSize = _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"); TraceError(L"Failed to read WAV data");
SAFE_DELETE_ARRAY(_waveData); SAFE_DELETE_ARRAY(wave_data_);
return false; return false;
} }
// 创建音源 // 创建音源
auto xAudio2 = Audio::getInstance()->getXAudio2(); auto xAudio2 = Audio::GetInstance()->GetXAudio2();
HRESULT hr = xAudio2->CreateSourceVoice(&_voice, _wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &_voiceCallback); HRESULT hr = xAudio2->CreateSourceVoice(&voice_, wfx_, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &callback_);
if (FAILED(hr)) if (FAILED(hr))
{ {
TraceError(L"Create source voice error", hr); TraceError(L"Create source voice error", hr);
SAFE_DELETE_ARRAY(_waveData); SAFE_DELETE_ARRAY(wave_data_);
return false; return false;
} }
_opened = true; opened_ = true;
return 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; HRSRC hResInfo;
@ -150,7 +150,7 @@ bool e2d::Music::open(const Resource& res)
DWORD dwSize; DWORD dwSize;
void* pvRes; 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"); return TraceError(L"FindResource");
if (nullptr == (hResData = LoadResource(HINST_THISCOMPONENT, hResInfo))) if (nullptr == (hResData = LoadResource(HINST_THISCOMPONENT, hResInfo)))
@ -162,18 +162,18 @@ bool e2d::Music::open(const Resource& res)
if (nullptr == (pvRes = LockResource(hResData))) if (nullptr == (pvRes = LockResource(hResData)))
return TraceError(L"LockResource"); return TraceError(L"LockResource");
_resBuffer = new CHAR[dwSize]; buffer_ = new CHAR[dwSize];
memcpy(_resBuffer, pvRes, dwSize); memcpy(buffer_, pvRes, dwSize);
MMIOINFO mmioInfo; MMIOINFO mmioInfo;
ZeroMemory(&mmioInfo, sizeof(mmioInfo)); ZeroMemory(&mmioInfo, sizeof(mmioInfo));
mmioInfo.fccIOProc = FOURCC_MEM; mmioInfo.fccIOProc = FOURCC_MEM;
mmioInfo.cchBuffer = dwSize; 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"); return TraceError(L"mmioOpen");
} }
@ -181,171 +181,171 @@ bool e2d::Music::open(const Resource& res)
if (!_readMMIO()) if (!_readMMIO())
{ {
// 读取非 wave 文件时 ReadMMIO 调用失败 // 读取非 wave 文件时 ReadMMIO 调用失败
mmioClose(_hmmio, 0); mmioClose(hmmio_, 0);
return TraceError(L"ReadMMIO"); return TraceError(L"ReadMMIO");
} }
if (!_resetFile()) if (!_resetFile())
return TraceError(L"ResetFile"); return TraceError(L"ResetFile");
// 重置文件后wave 文件的大小是 _ck.cksize // 重置文件后wave 文件的大小是 ck_.cksize
_dwSize = _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"); TraceError(L"Failed to read WAV data");
SAFE_DELETE_ARRAY(_waveData); SAFE_DELETE_ARRAY(wave_data_);
return false; return false;
} }
// 创建音源 // 创建音源
auto xAudio2 = Audio::getInstance()->getXAudio2(); auto xAudio2 = Audio::GetInstance()->GetXAudio2();
HRESULT hr = xAudio2->CreateSourceVoice(&_voice, _wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &_voiceCallback); HRESULT hr = xAudio2->CreateSourceVoice(&voice_, wfx_, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &callback_);
if (FAILED(hr)) if (FAILED(hr))
{ {
TraceError(L"Create source voice error", hr); TraceError(L"Create source voice error", hr);
SAFE_DELETE_ARRAY(_waveData); SAFE_DELETE_ARRAY(wave_data_);
return false; return false;
} }
_opened = true; opened_ = true;
return 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; 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; return false;
} }
XAUDIO2_VOICE_STATE state; XAUDIO2_VOICE_STATE state;
_voice->GetState(&state); voice_->GetState(&state);
if (state.BuffersQueued) if (state.BuffersQueued)
{ {
stop(); Stop();
} }
nLoopCount = std::min(nLoopCount, XAUDIO2_LOOP_INFINITE - 1); loop_count = std::min(loop_count, XAUDIO2_LOOP_INFINITE - 1);
nLoopCount = (nLoopCount < 0) ? XAUDIO2_LOOP_INFINITE : nLoopCount; loop_count = (loop_count < 0) ? XAUDIO2_LOOP_INFINITE : loop_count;
// 提交 wave 样本数据 // 提交 wave 样本数据
XAUDIO2_BUFFER buffer = { 0 }; XAUDIO2_BUFFER buffer = { 0 };
buffer.pAudioData = _waveData; buffer.pAudioData = wave_data_;
buffer.Flags = XAUDIO2_END_OF_STREAM; buffer.Flags = XAUDIO2_END_OF_STREAM;
buffer.AudioBytes = _dwSize; buffer.AudioBytes = size_;
buffer.LoopCount = nLoopCount; buffer.LoopCount = loop_count;
HRESULT hr; HRESULT hr;
if (FAILED(hr = _voice->SubmitSourceBuffer(&buffer))) if (FAILED(hr = voice_->SubmitSourceBuffer(&buffer)))
{ {
TraceError(L"Submitting source buffer error", hr); TraceError(L"Submitting source buffer error", hr);
_voice->DestroyVoice(); voice_->DestroyVoice();
SAFE_DELETE_ARRAY(_waveData); SAFE_DELETE_ARRAY(wave_data_);
return false; return false;
} }
hr = _voice->Start(0); hr = voice_->Start(0);
return SUCCEEDED(hr); 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_->ExitLoop();
_voice->FlushSourceBuffers(); voice_->FlushSourceBuffers();
} }
} }
} }
void e2d::Music::close() void e2d::Music::Close()
{ {
if (_voice) if (voice_)
{ {
_voice->Stop(); voice_->Stop();
_voice->FlushSourceBuffers(); voice_->FlushSourceBuffers();
_voice->DestroyVoice(); voice_->DestroyVoice();
_voice = nullptr; voice_ = nullptr;
} }
if (_hmmio != nullptr) if (hmmio_ != nullptr)
{ {
mmioClose(_hmmio, 0); mmioClose(hmmio_, 0);
_hmmio = nullptr; hmmio_ = nullptr;
} }
SAFE_DELETE_ARRAY(_resBuffer); SAFE_DELETE_ARRAY(buffer_);
SAFE_DELETE_ARRAY(_waveData); SAFE_DELETE_ARRAY(wave_data_);
SAFE_DELETE_ARRAY(_wfx); 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; XAUDIO2_VOICE_STATE state;
_voice->GetState(&state); voice_->GetState(&state);
if (state.BuffersQueued) if (state.BuffersQueued)
return true; return true;
} }
return false; 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; 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() bool e2d::Music::_readMMIO()
@ -355,19 +355,19 @@ bool e2d::Music::_readMMIO()
memset(&ckIn, 0, sizeof(ckIn)); 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"); return TraceError(L"mmioDescend");
// 确认文件是一个合法的 wave 文件 // 确认文件是一个合法的 wave 文件
if ((_ckRiff.ckid != FOURCC_RIFF) || if ((ck_riff_.ckid != FOURCC_RIFF) ||
(_ckRiff.fccType != mmioFOURCC('W', 'A', 'V', 'E'))) (ck_riff_.fccType != mmioFOURCC('W', 'A', 'V', 'E')))
return TraceError(L"mmioFOURCC"); return TraceError(L"mmioFOURCC");
// 在输入文件中查找 'fmt' 块 // 在输入文件中查找 'fmt' 块
ckIn.ckid = mmioFOURCC('f', 'm', 't', ' '); 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"); return TraceError(L"mmioDescend");
// 'fmt' 块至少应和 PCMWAVEFORMAT 一样大 // 'fmt' 块至少应和 PCMWAVEFORMAT 一样大
@ -375,7 +375,7 @@ bool e2d::Music::_readMMIO()
return TraceError(L"sizeof(PCMWAVEFORMAT)"); return TraceError(L"sizeof(PCMWAVEFORMAT)");
// 将 'fmt' 块读取到 pcmWaveFormat 中 // 将 'fmt' 块读取到 pcmWaveFormat 中
if (mmioRead(_hmmio, (HPSTR)&pcmWaveFormat, if (mmioRead(hmmio_, (HPSTR)&pcmWaveFormat,
sizeof(pcmWaveFormat)) != sizeof(pcmWaveFormat)) sizeof(pcmWaveFormat)) != sizeof(pcmWaveFormat))
return TraceError(L"mmioRead"); return TraceError(L"mmioRead");
@ -383,37 +383,37 @@ bool e2d::Music::_readMMIO()
// 的数据,这个数据就是额外分配的大小 // 的数据,这个数据就是额外分配的大小
if (pcmWaveFormat.wf.wFormatTag == WAVE_FORMAT_PCM) if (pcmWaveFormat.wf.wFormatTag == WAVE_FORMAT_PCM)
{ {
_wfx = (WAVEFORMATEX*) new CHAR[sizeof(WAVEFORMATEX)]; wfx_ = (WAVEFORMATEX*) new CHAR[sizeof(WAVEFORMATEX)];
// 拷贝数据 // 拷贝数据
memcpy(_wfx, &pcmWaveFormat, sizeof(pcmWaveFormat)); memcpy(wfx_, &pcmWaveFormat, sizeof(pcmWaveFormat));
_wfx->cbSize = 0; wfx_->cbSize = 0;
} }
else else
{ {
// 读取额外数据的大小 // 读取额外数据的大小
WORD cbExtraBytes = 0L; 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"); return TraceError(L"mmioRead");
_wfx = (WAVEFORMATEX*) new CHAR[sizeof(WAVEFORMATEX) + cbExtraBytes]; wfx_ = (WAVEFORMATEX*) new CHAR[sizeof(WAVEFORMATEX) + cbExtraBytes];
// 拷贝数据 // 拷贝数据
memcpy(_wfx, &pcmWaveFormat, sizeof(pcmWaveFormat)); memcpy(wfx_, &pcmWaveFormat, sizeof(pcmWaveFormat));
_wfx->cbSize = cbExtraBytes; wfx_->cbSize = cbExtraBytes;
// 读取额外数据 // 读取额外数据
if (mmioRead(_hmmio, (CHAR*)(((BYTE*)&(_wfx->cbSize)) + sizeof(WORD)), if (mmioRead(hmmio_, (CHAR*)(((BYTE*)&(wfx_->cbSize)) + sizeof(WORD)),
cbExtraBytes) != cbExtraBytes) cbExtraBytes) != cbExtraBytes)
{ {
SAFE_DELETE(_wfx); SAFE_DELETE(wfx_);
return TraceError(L"mmioRead"); 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"); return TraceError(L"mmioAscend");
} }
@ -423,37 +423,37 @@ bool e2d::Music::_readMMIO()
bool e2d::Music::_resetFile() bool e2d::Music::_resetFile()
{ {
// Seek to the data // Seek to the data
if (-1 == mmioSeek(_hmmio, _ckRiff.dwDataOffset + sizeof(FOURCC), if (-1 == mmioSeek(hmmio_, ck_riff_.dwDataOffset + sizeof(FOURCC),
SEEK_SET)) SEEK_SET))
return TraceError(L"mmioSeek"); return TraceError(L"mmioSeek");
// Search the input file for the 'data' chunk. // Search the input file for the 'data' chunk.
_ck.ckid = mmioFOURCC('d', 'a', 't', 'a'); ck_.ckid = mmioFOURCC('d', 'a', 't', 'a');
if (0 != mmioDescend(_hmmio, &_ck, &_ckRiff, MMIO_FINDCHUNK)) if (0 != mmioDescend(hmmio_, &ck_, &ck_riff_, MMIO_FINDCHUNK))
return TraceError(L"mmioDescend"); return TraceError(L"mmioDescend");
return true; 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"); return TraceError(L"mmioGetInfo");
UINT cbDataIn = dwSizeToRead; UINT cbDataIn = size_to_read;
if (cbDataIn > _ck.cksize) if (cbDataIn > ck_.cksize)
cbDataIn = _ck.cksize; cbDataIn = ck_.cksize;
_ck.cksize -= cbDataIn; ck_.cksize -= cbDataIn;
for (DWORD cT = 0; cT < cbDataIn; ++cT) for (DWORD cT = 0; cT < cbDataIn; ++cT)
{ {
// Copy the bytes from the io to the buffer. // Copy the bytes from the io to the buffer.
if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead) if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead)
{ {
if (0 != mmioAdvance(_hmmio, &mmioinfoIn, MMIO_READ)) if (0 != mmioAdvance(hmmio_, &mmioinfoIn, MMIO_READ))
return TraceError(L"mmioAdvance"); return TraceError(L"mmioAdvance");
if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead) if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead)
@ -461,24 +461,24 @@ bool e2d::Music::_read(BYTE* pBuffer, DWORD dwSizeToRead)
} }
// Actual copy. // Actual copy.
*((BYTE*)pBuffer + cT) = *((BYTE*)mmioinfoIn.pchNext); *((BYTE*)buffer + cT) = *((BYTE*)mmioinfoIn.pchNext);
++mmioinfoIn.pchNext; ++mmioinfoIn.pchNext;
} }
if (0 != mmioSetInfo(_hmmio, &mmioinfoIn, 0)) if (0 != mmioSetInfo(hmmio_, &mmioinfoIn, 0))
return TraceError(L"mmioSetInfo"); return TraceError(L"mmioSetInfo");
return true; 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; bool bFound = false;
if (nullptr == strFilename || nullptr == strDestPath || cchDest < 10) if (nullptr == file_name || nullptr == dest_path || cch_dest < 10)
return false; return false;
// Get the exe _name, and exe path // Get the exe name, and exe path
wchar_t strExePath[MAX_PATH] = { 0 }; wchar_t strExePath[MAX_PATH] = { 0 };
wchar_t strExeName[MAX_PATH] = { 0 }; wchar_t strExeName[MAX_PATH] = { 0 };
GetModuleFileName(HINST_THISCOMPONENT, strExePath, MAX_PATH); 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]); 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; *strLastSlash = 0;
// Chop the .exe from the exe _name // Chop the .exe from the exe name
strLastSlash = wcsrchr(strExeName, TEXT('.')); strLastSlash = wcsrchr(strExeName, TEXT('.'));
if (strLastSlash) if (strLastSlash)
*strLastSlash = 0; *strLastSlash = 0;
} }
wcscpy_s(strDestPath, cchDest, strFilename); wcscpy_s(dest_path, cch_dest, file_name);
if (GetFileAttributes(strDestPath) != 0xFFFFFFFF) if (GetFileAttributes(dest_path) != 0xFFFFFFFF)
return true; 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 }; 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 strFullPath[MAX_PATH] = { 0 };
wchar_t strFullFileName[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); swprintf_s(strFullFileName, MAX_PATH, L"%s\\%s", strFullPath, strLeafName);
if (GetFileAttributes(strFullFileName) != 0xFFFFFFFF) if (GetFileAttributes(strFullFileName) != 0xFFFFFFFF)
{ {
wcscpy_s(strDestPath, cchDest, strFullFileName); wcscpy_s(dest_path, cch_dest, strFullFileName);
bFound = true; bFound = true;
break; 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); swprintf_s(strFullFileName, MAX_PATH, L"%s\\%s\\%s", strFullPath, strExeName, strLeafName);
if (GetFileAttributes(strFullFileName) != 0xFFFFFFFF) if (GetFileAttributes(strFullFileName) != 0xFFFFFFFF)
{ {
wcscpy_s(strDestPath, cchDest, strFullFileName); wcscpy_s(dest_path, cch_dest, strFullFileName);
bFound = true; bFound = true;
break; break;
} }
@ -540,7 +540,7 @@ bool e2d::Music::_findMediaFileCch(wchar_t* strDestPath, int cchDest, const wcha
return true; return true;
// 失败时,将文件作为路径返回,同时也返回错误代码 // 失败时,将文件作为路径返回,同时也返回错误代码
wcscpy_s(strDestPath, cchDest, strFilename); wcscpy_s(dest_path, cch_dest, file_name);
return false; return false;
} }

View File

@ -1,79 +1,79 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
#include <shlobj.h> #include <shlobj.h>
e2d::String e2d::Path::getDataPath() const e2d::String& e2d::Path::GetDataPath()
{ {
static String dataPath; static String data_path;
if (dataPath.isEmpty()) if (data_path.IsEmpty())
{ {
// 设置数据的保存路径 // 设置数据的保存路径
String localAppDataPath = Path::getLocalAppDataPath(); String local_app_data_path = Path::GetLocalAppDataPath();
String title = Window::getInstance()->getTitle(); String title = Window::GetInstance()->GetTitle();
String folderName = String::parse(title.hash()); 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); File file(data_path);
if (!file.exists() && !File::createFolder(dataPath)) 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; static String temp_path;
if (tempPath.isEmpty()) if (temp_path.IsEmpty())
{ {
// 设置临时文件保存路径 // 设置临时文件保存路径
wchar_t path[_MAX_PATH]; wchar_t path[_MAX_PATH];
String title = Window::getInstance()->getTitle(); String title = Window::GetInstance()->GetTitle();
String folderName = String::parse(title.hash()); String folder_name = String::Parse(title.GetHash());
if (0 != ::GetTempPath(_MAX_PATH, path)) if (0 != ::GetTempPath(_MAX_PATH, path))
{ {
tempPath << path << L"\\Easy2DGameTemp\\" << folderName << L"\\"; temp_path << path << L"\\Easy2DGameTemp\\" << folder_name << L"\\";
File file(tempPath); File file(temp_path);
if (!file.exists() && !File::createFolder(tempPath)) 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; static String local_app_data_path;
if (localAppDataPath.isEmpty()) if (local_app_data_path.IsEmpty())
{ {
// 获取 AppData/Local 文件夹的路径 // 获取 AppData/Local 文件夹的路径
WCHAR strPath[MAX_PATH] = { 0 }; WCHAR path[MAX_PATH] = { 0 };
::SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, strPath); ::SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
localAppDataPath = strPath; 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; static String exe_file_path;
if (currFilePath.isEmpty()) if (exe_file_path.IsEmpty())
{ {
TCHAR szPath[_MAX_PATH] = { 0 }; TCHAR path[_MAX_PATH] = { 0 };
if (::GetModuleFileName(nullptr, szPath, _MAX_PATH) != 0) if (::GetModuleFileName(nullptr, path, _MAX_PATH) != 0)
{ {
currFilePath = szPath; exe_file_path = path;
} }
} }
return currFilePath; return exe_file_path;
} }

View File

@ -1,67 +1,67 @@
#include "..\e2dtool.h" #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; delete instance_;
_instance = nullptr; instance_ = nullptr;
} }
} }
e2d::Player::Player() e2d::Player::Player()
: _volume(1.f) : volume_(1.f)
{ {
} }
e2d::Player::~Player() e2d::Player::~Player()
{ {
if (!_musicList.empty()) if (!musics_.empty())
{ {
for (const auto& pair : _musicList) for (const auto& pair : musics_)
{ {
delete pair.second; 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; return false;
Music * music = new (std::nothrow) Music(); Music * music = new (std::nothrow) Music();
if (music && music->open(filePath)) if (music && music->Open(file_path))
{ {
music->setVolume(_volume); music->SetVolume(volume_);
_musicList.insert(std::make_pair(filePath.hash(), music)); musics_.insert(std::make_pair(file_path.GetHash(), music));
return true; return true;
} }
return false; 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; return false;
if (Player::preload(filePath)) if (Player::Preload(file_path))
{ {
auto music = _musicList[filePath.hash()]; auto music = musics_[file_path.GetHash()];
if (music->play(nLoopCount)) if (music->Play(loop_count))
{ {
return true; return true;
} }
@ -69,69 +69,69 @@ bool e2d::Player::play(const String & filePath, int nLoopCount)
return false; 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; return;
size_t hash = filePath.hash(); size_t hash = file_path.GetHash();
if (_musicList.end() != _musicList.find(hash)) if (musics_.end() != musics_.find(hash))
_musicList[hash]->pause(); 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; return;
size_t hash = filePath.hash(); size_t hash = file_path.GetHash();
if (_musicList.end() != _musicList.find(hash)) if (musics_.end() != musics_.find(hash))
_musicList[hash]->resume(); 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; return;
size_t hash = filePath.hash(); size_t hash = file_path.GetHash();
if (_musicList.end() != _musicList.find(hash)) if (musics_.end() != musics_.find(hash))
_musicList[hash]->stop(); 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; return false;
size_t hash = filePath.hash(); size_t hash = file_path.GetHash();
if (_musicList.end() != _musicList.find(hash)) if (musics_.end() != musics_.find(hash))
return _musicList[hash]->isPlaying(); return musics_[hash]->IsPlaying();
return false; 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; return true;
Music * music = new (std::nothrow) Music(); Music * music = new (std::nothrow) Music();
if (music && music->open(res)) if (music && music->Open(res))
{ {
music->setVolume(_volume); music->SetVolume(volume_);
_musicList.insert(std::make_pair(res.resNameId, music)); musics_.insert(std::make_pair(res.name, music));
return true; return true;
} }
return false; 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]; auto music = musics_[res.name];
if (music->play(nLoopCount)) if (music->Play(loop_count))
{ {
return true; return true;
} }
@ -139,74 +139,74 @@ bool e2d::Player::play(const Resource& res, int nLoopCount)
return false; return false;
} }
void e2d::Player::pause(const Resource& res) void e2d::Player::Pause(const Resource& res)
{ {
if (_musicList.end() != _musicList.find(res.resNameId)) if (musics_.end() != musics_.find(res.name))
_musicList[res.resNameId]->pause(); 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)) if (musics_.end() != musics_.find(res.name))
_musicList[res.resNameId]->resume(); 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)) if (musics_.end() != musics_.find(res.name))
_musicList[res.resNameId]->stop(); 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)) if (musics_.end() != musics_.find(res.name))
return _musicList[res.resNameId]->isPlaying(); return musics_[res.name]->IsPlaying();
return false; 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); volume_ = std::min(std::max(volume, -224.f), 224.f);
for (const auto& pair : _musicList) 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; delete pair.second;
} }
_musicList.clear(); musics_.clear();
} }

View File

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

View File

@ -2,70 +2,70 @@
e2d::Task::Task(const Function & func, const String & name) e2d::Task::Task(const Function & func, const String & name)
: _running(true) : running_(true)
, _stopped(false) , stopped_(false)
, _runTimes(0) , run_times_(0)
, _totalTimes(-1) , total_times_(-1)
, _delay() , delay_()
, _callback(func) , callback_(func)
, _name(name) , name_(name)
{ {
} }
e2d::Task::Task(const Function & func, float delay, int times, const String & name) e2d::Task::Task(const Function & func, float delay, int times, const String & name)
: _running(true) : running_(true)
, _stopped(false) , stopped_(false)
, _runTimes(0) , run_times_(0)
, _delay(std::max(delay, 0.f)) , delay_(std::max(delay, 0.f))
, _totalTimes(times) , total_times_(times)
, _callback(func) , callback_(func)
, _name(name) , name_(name)
{ {
} }
void e2d::Task::start() void e2d::Task::Start()
{ {
_running = true; running_ = true;
_lastTime = Time::now(); 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; return;
} }
++_runTimes; ++run_times_;
_lastTime += _delay; last_time_ += delay_;
if (_callback) if (callback_)
{ {
_callback(); callback_();
} }
if (_runTimes == _totalTimes) if (run_times_ == total_times_)
{ {
_stopped = true; stopped_ = true;
return; 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; return true;
} }
if (Time::now() - _lastTime >= _delay) if (Time::Now() - last_time_ >= delay_)
{ {
return true; return true;
} }
@ -73,12 +73,12 @@ bool e2d::Task::_isReady() const
return false; 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_;
} }

View File

@ -1,14 +1,14 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
e2d::Timer * e2d::Timer::getInstance() e2d::Timer * e2d::Timer::GetInstance()
{ {
static Timer instance; static Timer instance;
return &instance; return &instance;
} }
e2d::Timer::Timer() 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) if (task)
{ {
auto iter = std::find(_tasks.begin(), _tasks.end(), task); auto iter = std::find(tasks_.begin(), tasks_.end(), task);
if (iter == _tasks.end()) if (iter == tasks_.end())
{ {
task->retain(); task->Retain();
task->_lastTime = Time::now(); task->last_time_ = Time::Now();
_tasks.push_back(task); 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; 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; return;
std::vector<Task*> currTasks; std::vector<Task*> currTasks;
currTasks.reserve(_tasks.size()); currTasks.reserve(tasks_.size());
std::copy_if( std::copy_if(
_tasks.begin(), tasks_.begin(),
_tasks.end(), tasks_.end(),
std::back_inserter(currTasks), std::back_inserter(currTasks),
[](Task* task) { return task->_isReady() && !task->_stopped; } [](Task* task) { return task->IsReady() && !task->stopped_; }
); );
// 遍历就绪的任务 // 遍历就绪的任务
for (const auto& task : currTasks) 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)->Release();
iter = _tasks.erase(iter); iter = tasks_.erase(iter);
} }
else 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();
} }
} }

View File

@ -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 true;
} }
return false; return false;
} }
void e2d::BoxTransition::_update() void e2d::BoxTransition::Update()
{ {
Transition::_update(); Transition::Update();
auto size = Window::getInstance()->getSize(); auto size = Window::GetInstance()->GetSize();
if (_delta <= 0.5) if (delta_ <= 0.5)
{ {
_outLayerParam.contentBounds = D2D1::RectF( out_layer_param_.contentBounds = D2D1::RectF(
size.width * _delta, size.width * delta_,
size.height * _delta, size.height * delta_,
size.width * (1 - _delta), size.width * (1 - delta_),
size.height * (1 - _delta) size.height * (1 - delta_)
); );
} }
else else
{ {
_outLayerParam.opacity = 0; out_layer_param_.opacity = 0;
_inLayerParam.opacity = 1; in_layer_param_.opacity = 1;
_inLayerParam.contentBounds = D2D1::RectF( in_layer_param_.contentBounds = D2D1::RectF(
size.width * (1 - _delta), size.width * (1 - delta_),
size.height * (1 - _delta), size.height * (1 - delta_),
size.width * _delta, size.width * delta_,
size.height * _delta size.height * delta_
); );
if (_delta >= 1) if (delta_ >= 1)
{ {
this->_stop(); this->Stop();
} }
} }
} }

View File

@ -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; out_layer_param_.opacity = 1;
_inLayerParam.opacity = 0; in_layer_param_.opacity = 0;
return true; return true;
} }
return false; return false;
} }
void e2d::EmergeTransition::_update() void e2d::EmergeTransition::Update()
{ {
Transition::_update(); Transition::Update();
_outLayerParam.opacity = 1 - _delta; out_layer_param_.opacity = 1 - delta_;
_inLayerParam.opacity = _delta; in_layer_param_.opacity = delta_;
if (_delta >= 1) if (delta_ >= 1)
{ {
this->_stop(); this->Stop();
} }
} }

View File

@ -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; out_layer_param_.opacity = 1;
_inLayerParam.opacity = 0; in_layer_param_.opacity = 0;
return true; return true;
} }
return false; 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; out_layer_param_.opacity = 1 - delta_ * 2;
_inLayerParam.opacity = 0; in_layer_param_.opacity = 0;
} }
else else
{ {
_outLayerParam.opacity = 0; out_layer_param_.opacity = 0;
_inLayerParam.opacity = (_delta - 0.5f) * 2; in_layer_param_.opacity = (delta_ - 0.5f) * 2;
if (_delta >= 1) if (delta_ >= 1)
{ {
this->_stop(); this->Stop();
} }
} }
} }

View File

@ -3,64 +3,64 @@
e2d::MoveTransition::MoveTransition(Scene* scene, float duration, Direction direction) e2d::MoveTransition::MoveTransition(Scene* scene, float duration, Direction direction)
: Transition(scene, duration) : 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(); auto size = Window::GetInstance()->GetSize();
if (_direction == Direction::Up) if (direction_ == Direction::Up)
{ {
_posDelta = Vector2(0, -size.height); pos_delta_ = Point(0, -size.height);
_startPos = 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); pos_delta_ = Point(0, size.height);
_startPos = 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); pos_delta_ = Point(-size.width, 0);
_startPos = 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); pos_delta_ = Point(size.width, 0);
_startPos = Point(-size.width, 0); start_pos_ = Point(-size.width, 0);
} }
if (_outScene) _outScene->setPos(0, 0); if (out_scene_) out_scene_->SetPos(0, 0);
_inScene->setPos(_startPos); in_scene_->SetPos(start_pos_);
return true; return true;
} }
return false; 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); if (out_scene_) out_scene_->SetPos(0, 0);
_inScene->setPos(0, 0); in_scene_->SetPos(0, 0);
} }

View File

@ -3,52 +3,52 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
e2d::Transition::Transition(Scene* scene, float duration) e2d::Transition::Transition(Scene* scene, float duration)
: _end(false) : done_(false)
, _started() , started_()
, _delta(0) , delta_(0)
, _outScene(nullptr) , out_scene_(nullptr)
, _inScene(scene) , in_scene_(scene)
, _outLayer(nullptr) , out_layer_(nullptr)
, _inLayer(nullptr) , in_layer_(nullptr)
, _outLayerParam() , out_layer_param_()
, _inLayerParam() , in_layer_param_()
{ {
_duration = std::max(duration, 0.f); duration_ = std::max(duration, 0.f);
if (_inScene) if (in_scene_)
_inScene->retain(); in_scene_->Retain();
} }
e2d::Transition::~Transition() e2d::Transition::~Transition()
{ {
SafeRelease(_outLayer); SafeRelease(out_layer_);
SafeRelease(_inLayer); SafeRelease(in_layer_);
GC::getInstance()->safeRelease(_outScene); GC::GetInstance()->SafeRelease(out_scene_);
GC::getInstance()->safeRelease(_inScene); 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(); started_ = Time::Now();
_outScene = prev; out_scene_ = prev;
if (_outScene) if (out_scene_)
_outScene->retain(); out_scene_->Retain();
HRESULT hr = S_OK; HRESULT hr = S_OK;
auto renderer = Renderer::getInstance(); auto renderer = Renderer::GetInstance();
if (_inScene) 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)) if (FAILED(hr))
@ -56,40 +56,40 @@ bool e2d::Transition::_init(Game * game, Scene * prev)
return false; return false;
} }
_outLayerParam = _inLayerParam = D2D1::LayerParameters( out_layer_param_ = in_layer_param_ = D2D1::LayerParameters(
D2D1::InfiniteRect(), D2D1::InfiniteRect(),
nullptr, nullptr,
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
D2D1::Matrix3x2F::Identity(), D2D1::Matrix3x2F::Identity(),
1.f, 1.f,
renderer->getSolidColorBrush(), renderer->GetSolidBrush(),
D2D1_LAYER_OPTIONS_NONE D2D1_LAYER_OPTIONS_NONE
); );
return true; return true;
} }
void e2d::Transition::_update() void e2d::Transition::Update()
{ {
if (_duration == 0) if (duration_ == 0)
{ {
_delta = 1; delta_ = 1;
} }
else else
{ {
_delta = (Time::now() - _started).seconds() / _duration; delta_ = (Time::Now() - started_).Seconds() / duration_;
_delta = std::min(_delta, 1.f); delta_ = std::min(delta_, 1.f);
} }
} }
void e2d::Transition::_render() void e2d::Transition::Draw()
{ {
auto renderTarget = Renderer::getInstance()->getRenderTarget(); auto renderTarget = Renderer::GetInstance()->GetRenderTarget();
auto size = Window::getInstance()->getSize(); auto size = Window::GetInstance()->GetSize();
if (_outScene) if (out_scene_)
{ {
auto rootPos = _outScene->getPos(); auto rootPos = out_scene_->GetPos();
auto clipRect = D2D1::RectF( auto clipRect = D2D1::RectF(
std::max(rootPos.x, 0.f), std::max(rootPos.x, 0.f),
std::max(rootPos.y, 0.f), std::max(rootPos.y, 0.f),
@ -98,17 +98,17 @@ void e2d::Transition::_render()
); );
renderTarget->SetTransform(D2D1::Matrix3x2F::Identity()); renderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
renderTarget->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); 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->PopLayer();
renderTarget->PopAxisAlignedClip(); renderTarget->PopAxisAlignedClip();
} }
if (_inScene) if (in_scene_)
{ {
Point rootPos = _inScene->getPos(); Point rootPos = in_scene_->GetPos();
auto clipRect = D2D1::RectF( auto clipRect = D2D1::RectF(
std::max(rootPos.x, 0.f), std::max(rootPos.x, 0.f),
std::max(rootPos.y, 0.f), std::max(rootPos.y, 0.f),
@ -117,17 +117,17 @@ void e2d::Transition::_render()
); );
renderTarget->SetTransform(D2D1::Matrix3x2F::Identity()); renderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
renderTarget->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); 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->PopLayer();
renderTarget->PopAxisAlignedClip(); renderTarget->PopAxisAlignedClip();
} }
} }
void e2d::Transition::_stop() void e2d::Transition::Stop()
{ {
_end = true; done_ = true;
_reset(); Reset();
} }

View File

@ -28,64 +28,64 @@ public:
virtual ~Action(); 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 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: protected:
E2D_DISABLE_COPY(Action); 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 Node* target
); );
protected: protected:
String _name; String name_;
bool _running; bool running_;
bool _done; bool done_;
bool _initialized; bool initialized_;
Node * _target; Node * target_;
Time _started; Time started_;
}; };
@ -100,23 +100,23 @@ public:
); );
// 重置动作 // 重置动作
virtual void reset() override; virtual void Reset() override;
protected: protected:
E2D_DISABLE_COPY(FiniteTimeAction); 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: protected:
float _duration; float duration_;
float _delta; float delta_;
}; };
@ -127,28 +127,28 @@ class MoveBy :
public: public:
explicit MoveBy( explicit MoveBy(
float duration, /* 持续时长 */ 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: protected:
E2D_DISABLE_COPY(MoveBy); E2D_DISABLE_COPY(MoveBy);
// 初始化动作 // 初始化动作
virtual void _init() override; virtual void Init() override;
// 更新动作 // 更新动作
virtual void _update() override; virtual void Update() override;
protected: protected:
Point _startPos; Point start_pos_;
Point _prevPos; Point prev_pos_;
Vector2 _deltaPos; 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; return nullptr;
} }
@ -176,10 +176,10 @@ protected:
E2D_DISABLE_COPY(MoveTo); E2D_DISABLE_COPY(MoveTo);
// 初始化动作 // 初始化动作
virtual void _init() override; virtual void Init() override;
protected: protected:
Point _endPos; Point end_pos_;
}; };
@ -190,32 +190,32 @@ class JumpBy :
public: public:
explicit JumpBy( explicit JumpBy(
float duration, /* 持续时长 */ float duration, /* 持续时长 */
const Vector2& vec, /* 跳跃距离 */ const Point& vec, /* 跳跃距离 */
float height, /* 跳跃高度 */ float height, /* 跳跃高度 */
int jumps = 1 /* 跳跃次数 */ int jumps = 1 /* 跳跃次数 */
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual JumpBy * clone() const override; virtual JumpBy * Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual JumpBy * reverse() const override; virtual JumpBy * Reverse() const override;
protected: protected:
E2D_DISABLE_COPY(JumpBy); E2D_DISABLE_COPY(JumpBy);
// 初始化动作 // 初始化动作
virtual void _init() override; virtual void Init() override;
// 更新动作 // 更新动作
virtual void _update() override; virtual void Update() override;
protected: protected:
Point _startPos; Point start_pos_;
Vector2 _deltaPos; Point delta_pos_;
float _height; float height_;
int _jumps; int jumps_;
Point _prevPos; Point prev_pos_;
}; };
@ -232,12 +232,12 @@ public:
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
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; return nullptr;
} }
@ -245,10 +245,10 @@ protected:
E2D_DISABLE_COPY(JumpTo); E2D_DISABLE_COPY(JumpTo);
// 初始化动作 // 初始化动作
virtual void _init() override; virtual void Init() override;
protected: protected:
Point _endPos; Point end_pos_;
}; };
@ -264,30 +264,30 @@ public:
explicit ScaleBy( explicit ScaleBy(
float duration, /* 持续时长 */ float duration, /* 持续时长 */
float scaleX, /* 横向缩放相对变化值 */ float scale_x, /* 横向缩放相对变化值 */
float scaleY /* 纵向缩放相对变化值 */ float scale_y /* 纵向缩放相对变化值 */
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual ScaleBy * clone() const override; virtual ScaleBy * Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual ScaleBy * reverse() const override; virtual ScaleBy * Reverse() const override;
protected: protected:
E2D_DISABLE_COPY(ScaleBy); E2D_DISABLE_COPY(ScaleBy);
// 初始化动作 // 初始化动作
virtual void _init() override; virtual void Init() override;
// 更新动作 // 更新动作
virtual void _update() override; virtual void Update() override;
protected: protected:
float _startScaleX; float start_scale_x_;
float _startScaleY; float start_scale_y_;
float _deltaX; float delta_x_;
float _deltaY; float delta_y_;
}; };
@ -303,17 +303,17 @@ public:
explicit ScaleTo( explicit ScaleTo(
float duration, /* 持续时长 */ float duration, /* 持续时长 */
float scaleX, /* 横向缩放目标值 */ float scale_x, /* 横向缩放目标值 */
float scaleY /* 纵向缩放目标值 */ 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; return nullptr;
} }
@ -321,11 +321,11 @@ protected:
E2D_DISABLE_COPY(ScaleTo); E2D_DISABLE_COPY(ScaleTo);
// 初始化动作 // 初始化动作
virtual void _init() override; virtual void Init() override;
protected: protected:
float _endScaleX; float end_scale_x_;
float _endScaleY; 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: protected:
E2D_DISABLE_COPY(OpacityBy); E2D_DISABLE_COPY(OpacityBy);
// 初始化动作 // 初始化动作
virtual void _init() override; virtual void Init() override;
// 更新动作 // 更新动作
virtual void _update() override; virtual void Update() override;
protected: protected:
float _startVal; float start_val_;
float _deltaVal; 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; return nullptr;
} }
@ -384,10 +384,10 @@ protected:
E2D_DISABLE_COPY(OpacityTo); E2D_DISABLE_COPY(OpacityTo);
// 初始化动作 // 初始化动作
virtual void _init() override; virtual void Init() override;
protected: protected:
float _endVal; float end_val_;
}; };
@ -399,10 +399,7 @@ public:
// 创建淡入动作 // 创建淡入动作
explicit FadeIn( explicit FadeIn(
float duration /* 持续时长 */ float duration /* 持续时长 */
) );
: OpacityTo(duration, 1)
{
}
protected: protected:
E2D_DISABLE_COPY(FadeIn); E2D_DISABLE_COPY(FadeIn);
@ -417,10 +414,7 @@ public:
// 创建淡出动作 // 创建淡出动作
explicit FadeOut( explicit FadeOut(
float duration /* 持续时长 */ float duration /* 持续时长 */
) );
: OpacityTo(duration, 0)
{
}
protected: protected:
E2D_DISABLE_COPY(FadeOut); 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: protected:
E2D_DISABLE_COPY(RotateBy); E2D_DISABLE_COPY(RotateBy);
// 初始化动作 // 初始化动作
virtual void _init() override; virtual void Init() override;
// 更新动作 // 更新动作
virtual void _update() override; virtual void Update() override;
protected: protected:
float _startVal; float start_val_;
float _deltaVal; 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; return nullptr;
} }
@ -482,10 +476,10 @@ protected:
E2D_DISABLE_COPY(RotateTo); E2D_DISABLE_COPY(RotateTo);
// 初始化动作 // 初始化动作
virtual void _init() override; virtual void Init() override;
protected: 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: protected:
E2D_DISABLE_COPY(Delay); 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: protected:
float _delay; float delay_;
float _delta; float delta_;
}; };
@ -538,59 +532,59 @@ public:
virtual ~Loop(); 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: protected:
E2D_DISABLE_COPY(Loop); 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: protected:
Action * _action; Action * action_;
int _times; int times_;
int _totalTimes; int total_times_;
}; };
// 回调动作 // 回调动作
class CallFunc : class Callback :
public Action public Action
{ {
public: public:
explicit CallFunc( explicit Callback(
const Function& func /* 函数对象 */ const Function& func /* 函数对象 */
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual CallFunc * clone() const override; virtual Callback * Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual CallFunc * reverse() const override; virtual Callback * Reverse() const override;
protected: 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: protected:
Function _func; Function callback_;
}; };
@ -599,48 +593,50 @@ class Sequence :
public Action public Action
{ {
public: public:
typedef std::vector<Action*> Actions;
Sequence(); Sequence();
explicit Sequence( explicit Sequence(
const std::vector<Action*>& actions /* 动作列表 */ const Actions& actions /* 动作列表 */
); );
virtual ~Sequence(); virtual ~Sequence();
// 在结尾添加动作 // 在结尾添加动作
void add( void Add(
Action * action Action * action
); );
// 在结尾添加多个动作 // 在结尾添加多个动作
void add( void Add(
const std::vector<Action*>& actions /* 动作列表 */ 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: protected:
E2D_DISABLE_COPY(Sequence); 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: protected:
UINT _currIndex; UINT action_index_;
std::vector<Action*> _actions; Actions actions_;
}; };
@ -649,47 +645,49 @@ class Spawn :
public Action public Action
{ {
public: public:
typedef std::vector<Action*> Actions;
Spawn(); Spawn();
explicit Spawn( explicit Spawn(
const std::vector<Action*>& actions /* 动作列表 */ const Actions& actions /* 动作列表 */
); );
virtual ~Spawn(); virtual ~Spawn();
// 在结尾添加动作 // 在结尾添加动作
void add( void Add(
Action * action Action * action
); );
// 在结尾添加多个动作 // 在结尾添加多个动作
void add( void Add(
const std::vector<Action*>& actions /* 动作列表 */ 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: protected:
E2D_DISABLE_COPY(Spawn); 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: protected:
std::vector<Action*> _actions; Actions actions_;
}; };
@ -698,10 +696,12 @@ class Animation :
public Ref public Ref
{ {
public: public:
typedef std::vector<Image*> Images;
Animation(); Animation();
explicit Animation( explicit Animation(
const std::vector<Image*>& frames /* 关键帧数组 */ const Images& frames /* 关键帧数组 */
); );
explicit Animation( explicit Animation(
@ -710,44 +710,44 @@ public:
explicit Animation( explicit Animation(
float interval, /* 帧间隔(秒) */ float interval, /* 帧间隔(秒) */
const std::vector<Image*>& frames /* 关键帧数组 */ const Images& frames /* 关键帧数组 */
); );
virtual ~Animation(); virtual ~Animation();
// 添加关键帧 // 添加关键帧
void add( void Add(
Image * frame /* 关键帧 */ Image * frame /* 关键帧 */
); );
// 添加多个关键帧 // 添加多个关键帧
void add( void Add(
const std::vector<Image*>& frames /* 关键帧列表 */ const Images& frames /* 关键帧数组 */
); );
// 获取帧间隔 // 获取帧间隔
float getInterval() const; float GetInterval() const;
// 获取关键帧 // 获取关键帧
const std::vector<Image*>& getFrames() const; const Images& GetFrames() const;
// 设置每一帧的时间间隔 // 设置每一帧的时间间隔
void setInterval( void SetInterval(
float interval /* 帧间隔(秒) */ float interval /* 帧间隔(秒) */
); );
// 获取帧动画的拷贝对象 // 获取帧动画的拷贝对象
Animation * clone() const; Animation * Clone() const;
// 获取帧动画的倒转 // 获取帧动画的倒转
Animation * reverse() const; Animation * Reverse() const;
protected: protected:
E2D_DISABLE_COPY(Animation); E2D_DISABLE_COPY(Animation);
protected: protected:
float _interval; float interval_;
std::vector<Image*> _frames; Images frames_;
}; };
@ -765,37 +765,37 @@ public:
virtual ~Animate(); virtual ~Animate();
// 获取动画 // 获取动画
virtual Animation * getAnimation() const; virtual Animation * GetAnimation() const;
// 设置动画 // 设置动画
virtual void setAnimation( virtual void SetAnimation(
Animation * animation 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: protected:
E2D_DISABLE_COPY(Animate); 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: protected:
UINT _frameIndex; UINT frame_index_;
Animation * _animation; Animation * animation_;
}; };

View File

@ -25,85 +25,85 @@ public:
}; };
// 弹窗样式 // 弹窗样式
enum class Popup : int enum class PopupStyle : int
{ {
Information, /* 信息 */ Info, /* 提示 */
Warning, /* 警告 */ Warning, /* 警告 */
Error /* 错误 */ Error /* 错误 */
}; };
public: public:
// 获取窗体实例 // 获取窗体实例
static Window * getInstance(); static Window * GetInstance();
// 销毁窗体实例 // 销毁窗体实例
static void destroyInstance(); static void DestroyInstance();
// 创建窗体互斥体 // 创建窗体互斥体
bool createMutex( bool CheckMutex(
const String& mutex = L"" /* 进程互斥体名称 */ 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 width, /* 窗体宽度 */
int height /* 窗体高度 */ int height /* 窗体高度 */
); );
// 设置窗体标题 // 设置窗体标题
void setTitle( void SetTitle(
const String& title /* 窗体标题 */ const String& title /* 窗体标题 */
); );
// 设置窗体图标 // 设置窗体图标
void setIcon( void SetIcon(
int iconID int icon_id
); );
// 设置鼠标指针样式 // 设置鼠标指针样式
void setCursor( void SetCursor(
Cursor cursor 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 bool enabled
); );
// 是否允许响应输入法 // 是否允许响应输入法
void setTypewritingEnabled( void SetTypewritingEnabled(
bool enabled bool enabled
); );
// 弹出窗口 // 弹出窗口
// 返回值:当窗口包含取消按钮时,返回值表示用户是否点击确认按钮 // 返回值:当窗口包含取消按钮时,返回值表示用户是否点击确认按钮
bool popup( bool Popup(
const String& text, /* 窗口内容 */ const String& text, /* 窗口内容 */
const String& title, /* 窗口标题 */ const String& title, /* 窗口标题 */
Popup style = Popup::Information, /* 弹窗样式 */ PopupStyle style = PopupStyle::Info,/* 弹窗样式 */
bool hasCancel = false /* 包含取消按钮 */ bool has_cancel = false /* 包含取消按钮 */
); );
// 处理窗体消息 // 处理窗体消息
void poll(); void Poll();
private: private:
Window(); Window();
@ -113,7 +113,7 @@ private:
E2D_DISABLE_COPY(Window); E2D_DISABLE_COPY(Window);
// 根据客户区大小定位窗口 // 根据客户区大小定位窗口
Rect _locate( Rect Locate(
int width, int width,
int height int height
); );
@ -121,21 +121,21 @@ private:
// Win32 窗口消息回调程序 // Win32 窗口消息回调程序
static LRESULT CALLBACK WndProc( static LRESULT CALLBACK WndProc(
HWND hWnd, HWND hWnd,
UINT uMsg, UINT msg,
WPARAM wParam, WPARAM w_param,
LPARAM lParam LPARAM l_param
); );
private: private:
HWND _hWnd; HWND hWnd_;
MSG _msg; MSG msg_;
int _width; int width_;
int _height; int height_;
String _title; String title_;
int _iconID; int icon_id_;
float _dpi; float dpi_;
static Window * _instance; static Window * instance_;
}; };
@ -144,57 +144,57 @@ class Renderer
{ {
public: public:
// 获取渲染器实例 // 获取渲染器实例
static Renderer * getInstance(); static Renderer * GetInstance();
// 销毁实例 // 销毁实例
static void destroyInstance(); static void DestroyInstance();
// 获取背景色 // 获取背景色
Color getBackgroundColor(); Color GetBackgroundColor();
// 修改背景色 // 修改背景色
void setBackgroundColor( void SetBackgroundColor(
Color color const Color& color
); );
// 显示或隐藏 FPS // 显示或隐藏 FPS
// 默认:隐藏 // 默认:隐藏
void showFps( void ShowFps(
bool show bool show
); );
// 开始渲染 // 开始渲染
void beginDraw(); void BeginDraw();
// 结束渲染 // 结束渲染
void endDraw(); void EndDraw();
// 获取文字渲染器 // 获取文字渲染器
TextRenderer * getTextRenderer() const { return _textRenderer; } E2DTextRenderer * GetTextRenderer();
// 获取 ID2D1HwndRenderTarget 对象 // 获取 ID2D1HwndRenderTarget 对象
ID2D1HwndRenderTarget * getRenderTarget() const { return _renderTarget; } ID2D1HwndRenderTarget * GetRenderTarget();
// 获取 ID2D1SolidColorBrush 对象 // 获取 ID2D1SolidColorBrush 对象
ID2D1SolidColorBrush * getSolidColorBrush() const { return _solidBrush; } ID2D1SolidColorBrush * GetSolidBrush();
// 获取 ID2D1Factory 对象 // 获取 ID2D1Factory 对象
static ID2D1Factory * getFactory(); static ID2D1Factory * GetFactory();
// 获取 IWICImagingFactory 对象 // 获取 IWICImagingFactory 对象
static IWICImagingFactory * getImagingFactory(); static IWICImagingFactory * GetImagingFactory();
// 获取 IDWriteFactory 对象 // 获取 IDWriteFactory 对象
static IDWriteFactory * getWriteFactory(); static IDWriteFactory * GetWriteFactory();
// 获取 Miter 样式的 ID2D1StrokeStyle // 获取 Miter 样式的 ID2D1StrokeStyle
static ID2D1StrokeStyle * getMiterStrokeStyle(); static ID2D1StrokeStyle * GetMiterStrokeStyle();
// 获取 Bevel 样式的 ID2D1StrokeStyle // 获取 Bevel 样式的 ID2D1StrokeStyle
static ID2D1StrokeStyle * getBevelStrokeStyle(); static ID2D1StrokeStyle * GetBevelStrokeStyle();
// 获取 Round 样式的 ID2D1StrokeStyle // 获取 Round 样式的 ID2D1StrokeStyle
static ID2D1StrokeStyle * getRoundStrokeStyle(); static ID2D1StrokeStyle * GetRoundStrokeStyle();
protected: protected:
Renderer(); Renderer();
@ -204,23 +204,23 @@ protected:
E2D_DISABLE_COPY(Renderer); E2D_DISABLE_COPY(Renderer);
protected: protected:
bool _showFps; bool show_fps_;
int _renderTimes; int render_times_;
Time _lastRenderTime; Time last_render_time_;
D2D1_COLOR_F _clearColor; D2D1_COLOR_F clear_color_;
TextRenderer* _textRenderer; E2DTextRenderer* text_renderer_;
IDWriteTextFormat* _fpsFormat; IDWriteTextFormat* fps_text_format_;
IDWriteTextLayout* _fpsLayout; IDWriteTextLayout* fps_text_layout_;
ID2D1SolidColorBrush* _solidBrush; ID2D1SolidColorBrush* solid_brush_;
ID2D1HwndRenderTarget* _renderTarget; ID2D1HwndRenderTarget* render_target_;
static ID2D1Factory* _factory; static ID2D1Factory* factory_;
static IWICImagingFactory* _imagingFactory; static IWICImagingFactory* imaging_factory_;
static IDWriteFactory* _writeFactory; static IDWriteFactory* write_factory_;
static ID2D1StrokeStyle* _miterStrokeStyle; static ID2D1StrokeStyle* miter_stroke_style_;
static ID2D1StrokeStyle* _bevelStrokeStyle; static ID2D1StrokeStyle* bevel_stroke_style_;
static ID2D1StrokeStyle* _roundStrokeStyle; static ID2D1StrokeStyle* round_stroke_style_;
static Renderer * _instance; static Renderer * instance_;
}; };
@ -229,41 +229,41 @@ class Input
{ {
public: public:
// 获取输入设备实例 // 获取输入设备实例
static Input * getInstance(); static Input * GetInstance();
// 销毁输入设备实例 // 销毁输入设备实例
static void destroyInstance(); static void DestroyInstance();
// 检测键盘某按键是否正被按下 // 检测键盘某按键是否正被按下
bool isDown( bool IsDown(
KeyCode key KeyCode key
); );
// 检测鼠标按键是否正被按下 // 检测鼠标按键是否正被按下
bool isDown( bool IsDown(
MouseCode code MouseCode code
); );
// 获得鼠标X轴坐标值 // 获得鼠标X轴坐标值
float getMouseX(); float GetMouseX();
// 获得鼠标Y轴坐标值 // 获得鼠标Y轴坐标值
float getMouseY(); float GetMouseY();
// 获得鼠标坐标值 // 获得鼠标坐标值
Point getMousePos(); Point GetMousePos();
// 获得鼠标X轴坐标增量 // 获得鼠标X轴坐标增量
float getMouseDeltaX(); float GetMouseDeltaX();
// 获得鼠标Y轴坐标增量 // 获得鼠标Y轴坐标增量
float getMouseDeltaY(); float GetMouseDeltaY();
// 获得鼠标Z轴鼠标滚轮坐标增量 // 获得鼠标Z轴鼠标滚轮坐标增量
float getMouseDeltaZ(); float GetMouseDeltaZ();
// 刷新输入设备状态 // 刷新输入设备状态
void update(); void Update();
protected: protected:
Input(); Input();
@ -273,13 +273,13 @@ protected:
E2D_DISABLE_COPY(Input); E2D_DISABLE_COPY(Input);
protected: protected:
IDirectInput8W * _directInput; IDirectInput8W * direct_input_;
IDirectInputDevice8W* _keyboardDevice; IDirectInputDevice8W* keyboard_device_;
IDirectInputDevice8W* _mouseDevice; IDirectInputDevice8W* mouse_device_;
DIMOUSESTATE _mouseState; DIMOUSESTATE mouse_state_;
char _keyBuffer[256]; char key_buffer_[256];
static Input * _instance; static Input * instance_;
}; };
@ -288,16 +288,16 @@ class Audio
{ {
public: public:
// 获取音频设备实例 // 获取音频设备实例
static Audio * getInstance(); static Audio * GetInstance();
// 销毁实例 // 销毁实例
static void destroyInstance(); static void DestroyInstance();
// 获取 XAudio2 实例对象 // 获取 XAudio2 实例对象
IXAudio2 * getXAudio2(); IXAudio2 * GetXAudio2();
// 获取 MasteringVoice 实例对象 // 获取 MasteringVoice 实例对象
IXAudio2MasteringVoice* getMasteringVoice(); IXAudio2MasteringVoice* GetMasteringVoice();
protected: protected:
Audio(); Audio();
@ -307,10 +307,10 @@ protected:
E2D_DISABLE_COPY(Audio); E2D_DISABLE_COPY(Audio);
protected: protected:
IXAudio2 * _xAudio2; IXAudio2 * x_audio2_;
IXAudio2MasteringVoice* _masteringVoice; IXAudio2MasteringVoice* mastering_voice_;
static Audio * _instance; static Audio * instance_;
}; };
@ -324,63 +324,63 @@ class Game
{ {
public: public:
// 获取 Game 实例 // 获取 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, /* 下一个场景的指针 */ Scene * scene, /* 下一个场景的指针 */
bool saveCurrentScene = true /* 是否保存当前场景 */ bool save_current_scene = true /* 是否保存当前场景 */
); );
// 场景入栈 // 场景入栈
void pushScene( void PushScene(
Transition * transition, /* 场景动画 */ Transition * transition, /* 场景动画 */
bool saveCurrentScene = true /* 是否保存当前场景 */ bool save_current_scene = true /* 是否保存当前场景 */
); );
// 场景出栈 // 场景出栈
Scene* popScene(); Scene* PopScene();
// 场景出栈 // 场景出栈
Scene* popScene( Scene* PopScene(
Transition * transition /* 场景动画 */ Transition * transition /* 场景动画 */
); );
// 清空保存的所有场景 // 清空保存的所有场景
void clearAllScenes(); void ClearAllScenes();
// 获取当前场景 // 获取当前场景
Scene * getCurrentScene(); Scene * GetCurrentScene();
// 获取场景栈 // 获取场景栈
const std::stack<Scene*>& getSceneStack(); const std::stack<Scene*>& GetSceneStack();
// 是否正在进行场景动画 // 是否正在进行场景动画
bool isTransitioning() const; bool IsTransitioning() const;
// 更新场景内容 // 更新场景内容
void updateScene(); void UpdateScene();
// 渲染场景画面 // 渲染场景画面
void drawScene(); void DrawScene();
protected: protected:
Game(); Game();
@ -390,19 +390,14 @@ protected:
E2D_DISABLE_COPY(Game); E2D_DISABLE_COPY(Game);
private: private:
bool _quit; bool quit_;
bool _paused; bool paused_;
Timer* _timer; Scene* curr_scene_;
Scene* _currScene; Scene* next_scene_;
Scene* _nextScene; Transition* transition_;
Transition* _transition; std::stack<Scene*> scenes_;
Window* _window;
Input* _input;
Renderer* _renderer;
ActionManager* _actionManager;
std::stack<Scene*> _scenes;
static Game * _instance; static Game * instance_;
}; };
@ -411,20 +406,20 @@ class GC
{ {
public: public:
// 获取 GC 实例 // 获取 GC 实例
static GC * getInstance(); static GC * GetInstance();
// 自动释放 // 自动释放
void autorelease( void AutoRelease(
Ref* ref Ref* ref
); );
// 安全地释放对象 // 安全地释放对象
void safeRelease( void SafeRelease(
Ref* ref Ref* ref
); );
// 刷新内存池 // 刷新内存池
void flush(); void Flush();
private: private:
GC(); GC();
@ -434,9 +429,9 @@ private:
E2D_DISABLE_COPY(GC); E2D_DISABLE_COPY(GC);
private: private:
bool _notifyed; bool notifyed_;
bool _cleanup; bool cleanup_;
std::set<Ref*> _pool; std::set<Ref*> pool_;
}; };
} }

View File

@ -36,28 +36,32 @@ public:
public: public:
Point(); 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 + (const Point & other) const;
Point operator - (Point const & point) const; Point operator - (const Point & other) const;
Point operator * (float const & point) const; Point operator * (float value) const;
Point operator / (float const & point) const; Point operator / (float value) const;
Point operator - () 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 class Size
{ {
@ -68,18 +72,23 @@ public:
public: public:
Size(); 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 + (const Size & other) const;
Size operator - (Size const & size) const; Size operator - (const Size & other) const;
Size operator * (float const & size) const; Size operator * (float value) const;
Size operator / (float const & size) const; Size operator / (float value) const;
Size operator - () 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: public:
Rect(); Rect();
Rect(float x, float y, float width, float height); Rect(
Rect(const Point& pos, const Size& size);
Rect(const Rect& other);
Rect& operator= (const Rect& other);
bool operator== (const Rect& rect) const;
// ÉèÖþØÐÎ
void setRect(
float x, float x,
float y, float y,
float width, float width,
float height float height
); );
Rect(
const Point& pos,
const Size& size
);
Rect(
const Rect& other
);
Rect& operator= (const Rect& other);
bool operator== (const Rect& rect) const;
// 判断点是否在矩形内 // 判断点是否在矩形内
bool containsPoint( bool ContainsPoint(
const Point& point const Point& point
) const; ) const;
// 判断两矩形是否相交 // 判断两矩形是否相交
bool intersects( bool Intersects(
const Rect& rect const Rect& rect
) const; ) const;
}; };
@ -128,95 +139,104 @@ class String
{ {
public: public:
String(); String();
String(const String &);
String(const char *); String(
String(const wchar_t *); const String &
String(String &&); );
String(
const char *
);
String(
const wchar_t *
);
String(
String &&
);
~String(); ~String();
// 获取字符串长度 // 获取字符串长度
int length() const; int GetLength() const;
// »ñÈ¡¸Ã×Ö·û´®µÄÉ¢ÁÐÖµ // 获取该字符串的 Hash 值
size_t hash() const; size_t GetHash() const;
// 判断字符串是否为空 // 判断字符串是否为空
bool isEmpty() const; bool IsEmpty() const;
// 获取指定位置字符 // 获取指定位置字符
wchar_t at( const wchar_t& At(
int index size_t index
) const; ) const;
// 比较字符串 // 比较字符串
int compare( int Compare(
const String & str const String & str
) const; ) const;
// 截取字符串 // 截取字符串
e2d::String subtract( String Subtract(
int offset, /* 偏移量 */ int offset, /* 偏移量 */
int count = -1 /* 截取字符数量 */ int count = -1 /* 截取字符数量 */
) const; ) const;
// 插入字符串 // 插入字符串
void insert( void Insert(
const String & str, const String & str,
int pos int pos
); );
// 替换字符串中的指定内容 // 替换字符串中的指定内容
void replace( void Replace(
const String & from, /* 需替换内容 */ const String & from, /* 需替换内容 */
const String & to /* 替换成内容 */ const String & to /* 替换成内容 */
); );
// 删除字符串中的指定内容 // 删除字符串中的指定内容
void erase( void Erase(
int offset, /* 偏移量 */ int offset, /* 偏移量 */
int count /* 删除字符数量 */ int count /* 删除字符数量 */
); );
// 搜索字符串 // 搜索字符串
int find( int Find(
const String & str, /* 查找内容 */ const String & str, /* 查找内容 */
int offset = 0 /* 偏移量 */ int offset = 0 /* 偏移量 */
) const; ) const;
// 清空字符串 // 清空字符串
void clear(); void Clear();
// 获取大写字符串 // 获取大写字符串
String toUpper() const; String ToUpper() const;
// 获取小写字符串 // 获取小写字符串
String toLower() const; String ToLower() const;
// 将字符串转化为 int 型 // 将字符串转化为 int 型
int toInt() const; int ToInt() const;
// 将字符串转化为 float 型 // 将字符串转化为 float 型
float toFloat() const; float ToFloat() const;
// 将字符串转化为 double 型 // 将字符串转化为 double 型
double toDouble() const; double ToDouble() const;
// 将字符串转化为 bool 型 // 将字符串转化为 bool 型
bool toBool() const; bool ToBool() const;
// 数字类型转字符串 // 数字类型转字符串
static String parse(int value); static String Parse(int value);
static String parse(unsigned int value); static String Parse(unsigned int value);
static String parse(float value); static String Parse(float value);
static String parse(double value); static String Parse(double value);
// 格式化字符串 // 格式化字符串
static String format(const char * format, ...); static String Format(const char * format, ...);
static String format(const wchar_t * format, ...); static String Format(const wchar_t * format, ...);
// ½»»»Á½×Ö·û´®
static void swap(String &str1, String &str2);
// 赋值运算符 // 赋值运算符
String& operator= (const String &); String& operator= (const String &);
@ -265,7 +285,7 @@ public:
String& operator<< (double value); String& operator<< (double value);
// 其他运算符 // 其他运算符
wchar_t& operator[] (int); wchar_t& operator[] (size_t);
friend std::ostream& operator<< (std::ostream &, const String &); friend std::ostream& operator<< (std::ostream &, const String &);
friend std::wostream& operator<< (std::wostream &, const String &); friend std::wostream& operator<< (std::wostream &, const String &);
@ -274,7 +294,7 @@ public:
friend std::wistream& operator>> (std::wistream &, String &); friend std::wistream& operator>> (std::wistream &, String &);
private: private:
std::wstring _str; std::wstring string_;
}; };
@ -356,13 +376,7 @@ public:
Yellow_Green = 0x9ACD32 Yellow_Green = 0x9ACD32
}; };
private: public:
void _init(
UINT rgb,
float alpha
);
private:
float r; float r;
float g; float g;
float b; float b;
@ -454,7 +468,7 @@ public:
); );
template<typename Func> template<typename Func>
Function(Func func) : _func(func) {} Function(Func func) : func_(func) {}
template<typename Func, typename Object> template<typename Func, typename Object>
Function( Function(
@ -462,7 +476,7 @@ public:
Object&& obj /* 对象指针 */ Object&& obj /* 对象指针 */
) )
{ {
_func = std::bind(func, obj); func_ = std::bind(func, obj);
} }
void operator() (void) const; void operator() (void) const;
@ -470,7 +484,7 @@ public:
E2D_OP_EXPLICIT operator bool() const; E2D_OP_EXPLICIT operator bool() const;
protected: protected:
std::function<void()> _func; std::function<void()> 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;
bool operator!= (const Duration &) const; bool operator!= (const Duration &) const;
@ -504,7 +518,7 @@ public:
Duration& operator -= (Duration const &); Duration& operator -= (Duration const &);
protected: protected:
std::chrono::milliseconds _ms; std::chrono::milliseconds duration_ms_;
}; };
@ -515,10 +529,10 @@ public:
Time(); 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;
Time operator - (Duration const &) const; Time operator - (Duration const &) const;
@ -529,10 +543,10 @@ public:
Duration operator - (Time const &) const; Duration operator - (Time const &) const;
// 获取当前时间 // 获取当前时间
static Time now(); static Time Now();
protected: protected:
std::chrono::steady_clock::time_point _timePoint; std::chrono::steady_clock::time_point time_;
}; };
@ -543,7 +557,7 @@ public:
String family; // 字体族 String family; // 字体族
float size; // 字号 float size; // 字号
UINT weight; // 粗细值 UINT weight; // 粗细值
bool italic; // бÌå bool italic; // 是否斜体
public: public:
// 字体粗细值 // 字体粗细值
@ -605,73 +619,73 @@ public:
virtual ~Collider(); virtual ~Collider();
// 设置碰撞体形状 // 设置碰撞体形状
void setShape( void SetShape(
Shape shape Shape shape
); );
// 是否触发碰撞事件 // 是否触发碰撞事件
void setCollisionNotify( void SetCollisionNotify(
bool notify bool notify
); );
// 启用或关闭该碰撞体 // 启用或关闭该碰撞体
void setEnabled( void SetEnabled(
bool enabled bool enabled
); );
// 设置碰撞体的可见性 // 设置碰撞体的可见性
void setVisible( void SetVisible(
bool visible bool visible
); );
// 设置绘制颜色 // 设置绘制颜色
void setColor( void SetBorderColor(
Color color const Color& color
); );
// 判断两碰撞体的交集关系 // 判断两碰撞体的交集关系
Relation getRelationWith( Relation GetRelationWith(
Collider * pCollider Collider * collider
) const; ) 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* 对象
ID2D1Geometry* getGeometry() const; ID2D1Geometry* GetGeometry() const;
// 重新生成 // 重新生成
void recreate(); void Recreate();
// 渲染碰撞体 // 渲染碰撞体
void render(); void Draw();
protected: protected:
E2D_DISABLE_COPY(Collider); E2D_DISABLE_COPY(Collider);
protected: protected:
bool _enabled; bool enabled_;
bool _visible; bool visible_;
bool _notify; bool notify_;
Color _color; Color border_color_;
Node * _parentNode; Node * parent_node_;
Shape _shape; Shape shape_;
ID2D1Geometry* _geometry; ID2D1Geometry* geometry_;
}; };
@ -680,13 +694,13 @@ class Resource
{ {
public: public:
Resource( Resource(
size_t resNameId, /* ×ÊÔ´Ãû³Æ */ size_t resource_name, /* 资源名称 */
const String& resType /* ×ÊÔ´ÀàÐÍ */ const String& resource_type /* 资源类型 */
); );
public: public:
size_t resNameId; size_t name;
String resType; String type;
}; };
@ -699,19 +713,19 @@ public:
virtual ~Ref(); virtual ~Ref();
// 增加引用计数 // 增加引用计数
void retain(); void Retain();
// 减少引用计数 // 减少引用计数
void release(); void Release();
// 获取引用计数 // 获取引用计数
int getRefCount() const; int GetRefCount() const;
protected: protected:
E2D_DISABLE_COPY(Ref); E2D_DISABLE_COPY(Ref);
private: private:
int _refCount; int ref_count_;
}; };
@ -728,91 +742,91 @@ public:
explicit Image( explicit Image(
const Resource& res, const Resource& res,
const Rect& cropRect /* ²Ã¼ô¾ØÐÎ */ const Rect& crop_rect /* 裁剪矩形 */
); );
explicit Image( explicit Image(
const String& fileName const String& file_name
); );
explicit Image( explicit Image(
const String& fileName, const String& file_name,
const Rect& cropRect /* ²Ã¼ô¾ØÐÎ */ const Rect& crop_rect /* 裁剪矩形 */
); );
virtual ~Image(); virtual ~Image();
// 加载图片资源 // 加载图片资源
bool open( bool Open(
const Resource& res const Resource& res
); );
// 加载图片资源 // 加载图片资源
bool open( bool Open(
const String& fileName const String& file_name
); );
// 将图片裁剪为矩形 // 将图片裁剪为矩形
void crop( void Crop(
const Rect& cropRect /* ²Ã¼ô¾ØÐÎ */ 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 坐标 // 获取裁剪位置 X 坐标
virtual float getCropX() const; virtual float GetCropX() const;
// 获取裁剪位置 Y 坐标 // 获取裁剪位置 Y 坐标
virtual float getCropY() const; virtual float GetCropY() const;
// 获取裁剪位置 // 获取裁剪位置
virtual Point getCropPos() const; virtual Point GetCropPos() const;
// 获取 ID2D1Bitmap 对象 // 获取 ID2D1Bitmap 对象
ID2D1Bitmap * getBitmap(); ID2D1Bitmap * GetBitmap();
// 预加载图片资源 // 预加载图片资源
static bool preload( static bool Preload(
const String& fileName const String& file_name
); );
// 预加载图片资源 // 预加载图片资源
static bool preload( static bool Preload(
const Resource& res const Resource& res
); );
// 清空缓存 // 清空缓存
static void clearCache(); static void ClearCache();
protected: protected:
E2D_DISABLE_COPY(Image); E2D_DISABLE_COPY(Image);
// 设置 Bitmap // 设置 Bitmap
void _setBitmap( void SetBitmap(
ID2D1Bitmap * bitmap ID2D1Bitmap * bitmap
); );
protected: protected:
Rect _cropRect; Rect crop_rect_;
ID2D1Bitmap * _bitmap; ID2D1Bitmap * bitmap_;
static std::map<size_t, ID2D1Bitmap*> _bitmapCache; static std::map<size_t, ID2D1Bitmap*> bitmap_cache_;
}; };

View File

@ -31,32 +31,28 @@ public:
STDMETHOD_(void, OnVoiceError) (THIS_ void* pBufferContext, HRESULT Error) {} STDMETHOD_(void, OnVoiceError) (THIS_ void* pBufferContext, HRESULT Error) {}
void SetFuncOnStreamEnd( STDMETHOD_(void, SetCallbackOnStreamEnd) (THIS_ const Function& func);
const Function& func
);
void SetFuncOnLoopEnd( STDMETHOD_(void, SetCallbackOnLoopEnd) (THIS_ const Function& func);
const Function& func
);
protected: protected:
Function _loopEndFunc; Function loop_end_callback_;
Function _streamEndFunc; Function stream_end_callback_;
}; };
// 文字渲染器 // 文字渲染器
class TextRenderer class E2DTextRenderer
: public IDWriteTextRenderer : public IDWriteTextRenderer
{ {
private: private:
TextRenderer(); E2DTextRenderer();
~TextRenderer(); ~E2DTextRenderer();
public: public:
static HRESULT Create( static HRESULT Create(
TextRenderer** ppTextRenderer, E2DTextRenderer** ppTextRenderer,
ID2D1Factory* pD2DFactory, ID2D1Factory* pD2DFactory,
ID2D1HwndRenderTarget* pRT, ID2D1HwndRenderTarget* pRT,
ID2D1SolidColorBrush* pBrush ID2D1SolidColorBrush* pBrush
@ -64,9 +60,9 @@ public:
STDMETHOD_(void, SetTextStyle)( STDMETHOD_(void, SetTextStyle)(
CONST D2D1_COLOR_F &fillColor, CONST D2D1_COLOR_F &fillColor,
BOOL hasOutline, BOOL outline,
CONST D2D1_COLOR_F &outlineColor, CONST D2D1_COLOR_F &outline_color,
FLOAT outlineWidth, FLOAT outline_width,
D2D1_LINE_JOIN outlineJoin D2D1_LINE_JOIN outlineJoin
); );
@ -101,8 +97,8 @@ public:
FLOAT originX, FLOAT originX,
FLOAT originY, FLOAT originY,
IDWriteInlineObject* inlineObject, IDWriteInlineObject* inlineObject,
BOOL isSideways, BOOL IsSideways,
BOOL isRightToLeft, BOOL IsRightToLeft,
IUnknown* clientDrawingEffect IUnknown* clientDrawingEffect
); );
@ -157,10 +153,10 @@ public:
Exception& operator=(Exception const& other) E2D_NOEXCEPT; Exception& operator=(Exception const& other) E2D_NOEXCEPT;
// 获取异常信息 // 获取异常信息
virtual const char * msg() const; virtual const char * GetMsg() const;
private: private:
const char * _message; const char * message_;
}; };

View File

@ -20,28 +20,28 @@ public:
explicit KeyEvent( explicit KeyEvent(
HWND hWnd, HWND hWnd,
UINT message, UINT message,
WPARAM wParam, WPARAM w_param,
LPARAM lParam LPARAM l_param
); );
// 获取按键键值 // 获取按键键值
KeyCode getCode() const; KeyCode GetCode() const;
// 获取按键次数 // 获取按键次数
int getCount() const; int GetCount() const;
// 获取事件类型 // 获取事件类型
KeyEvent::Type getType() const; KeyEvent::Type GetType() const;
// VK 键值转换 // VK 键值转换
static KeyCode convertKeyCode( static KeyCode ToKeyCode(
WPARAM wParam WPARAM w_param
); );
protected: protected:
int _count; int count_;
KeyCode _code; KeyCode code_;
KeyEvent::Type _type; KeyEvent::Type type_;
}; };
@ -69,46 +69,46 @@ public:
explicit MouseEvent( explicit MouseEvent(
HWND hWnd, HWND hWnd,
UINT message, UINT message,
WPARAM wParam, WPARAM w_param,
LPARAM lParam, LPARAM l_param,
float dpi 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 键是否按下 // Shift 键是否按下
bool isShiftDown() const; bool IsShiftDown() const;
// Ctrl 键是否按下 // Ctrl 键是否按下
bool isCtrlDown() const; bool IsCtrlDown() const;
protected: protected:
UINT _message; UINT message_;
WPARAM _wParam; WPARAM w_param_;
LPARAM _lParam; LPARAM l_param_;
Point _pos; Point pos_;
MouseEvent::Type _type; MouseEvent::Type type_;
}; };
@ -126,14 +126,14 @@ public:
~Collision(); ~Collision();
// 获取发生碰撞节点 // 获取发生碰撞节点
Node* getNode() const; Node* GetNode() const;
// 获取交集关系 // 获取交集关系
Collider::Relation getRelation() const; Collider::Relation GetRelation() const;
protected: protected:
Node * _node; Node * node_;
Collider::Relation _relation; Collider::Relation relation_;
}; };
} }

View File

@ -16,66 +16,66 @@ class ActionManager
public: public:
// 获取动作管理器实例 // 获取动作管理器实例
static ActionManager * getInstance(); static ActionManager * GetInstance();
// 获取所有名称相同的动作 // 获取所有名称相同的动作
std::vector<Action *> get( std::vector<Action *> Get(
const String& name const String& name
); );
// 获取所有动作 // 获取所有动作
const std::vector<Action*>& getAll(); const std::vector<Action*>& GetAll();
// 执行动作 // 执行动作
void start( void Start(
Action * action, Action * action,
Node * target, Node * target,
bool paused bool paused
); );
// 继续名称相同的所有动作 // 继续名称相同的所有动作
void resume( void Resume(
const String& name const String& name
); );
// 暂停名称相同的所有动作 // 暂停名称相同的所有动作
void pause( void Pause(
const String& name const String& name
); );
// 停止名称相同的所有动作 // 停止名称相同的所有动作
void stop( void Stop(
const String& name const String& name
); );
// 继续绑定在节点上的所有动作 // 继续绑定在节点上的所有动作
void resumeAllBindedWith( void ResumeAllBindedWith(
Node * target Node * target
); );
// 暂停绑定在节点上的所有动作 // 暂停绑定在节点上的所有动作
void pauseAllBindedWith( void PauseAllBindedWith(
Node * target Node * target
); );
// 停止绑定在节点上的所有动作 // 停止绑定在节点上的所有动作
void stopAllBindedWith( void StopAllBindedWith(
Node * target Node * target
); );
// 强制清除绑定在节点上的所有动作 // 强制清除绑定在节点上的所有动作
void clearAllBindedWith( void ClearAllBindedWith(
Node * target Node * target
); );
// 强制清除所有动作 // 强制清除所有动作
void clearAll(); void ClearAll();
// 更新动作管理器状态 // 更新动作管理器状态
void update(); void Update();
// 刷新所有动作计时 // 刷新所有动作计时
void updateTime(); void UpdateTime();
private: private:
ActionManager(); ActionManager();
@ -85,18 +85,18 @@ private:
E2D_DISABLE_COPY(ActionManager); E2D_DISABLE_COPY(ActionManager);
// 添加动作 // 添加动作
void __add( void Add(
Action * action Action * action
); );
// 删除动作 // 删除动作
void __remove( void Remove(
Action * action Action * action
); );
private: private:
std::vector<Action*> _actions; std::vector<Action*> actions_;
std::vector<Action*> _runningActions; std::vector<Action*> running_actions_;
}; };
@ -108,33 +108,33 @@ class CollisionManager
public: public:
// 获取碰撞体管理器实例 // 获取碰撞体管理器实例
static CollisionManager * getInstance(); static CollisionManager * GetInstance();
// 打开或关闭碰撞监听 // 打开或关闭碰撞监听
// 默认:关闭 // 默认:关闭
void setCollisionEnabled( void SetCollisionEnabled(
bool enabled bool enabled
); );
// 添加可互相碰撞物体的名称 // 添加可互相碰撞物体的名称
void addName( void AddName(
const String& name1, const String& name1,
const String& name2 const String& name2
); );
// 添加可互相碰撞物体的名称 // 添加可互相碰撞物体的名称
void addName( void AddName(
const std::vector<std::pair<String, String>>& names const std::vector<std::pair<String, String>>& names
); );
// 判断两个物体是否是可碰撞的 // 判断两个物体是否是可碰撞的
bool isCollidable( bool IsCollidable(
Node * node1, Node * node1,
Node * node2 Node * node2
); );
// 判断两个物体是否是可碰撞的 // 判断两个物体是否是可碰撞的
bool isCollidable( bool IsCollidable(
const String& name1, const String& name1,
const String& name2 const String& name2
); );
@ -147,24 +147,24 @@ private:
E2D_DISABLE_COPY(CollisionManager); E2D_DISABLE_COPY(CollisionManager);
// 添加碰撞体 // 添加碰撞体
void __addCollider( void AddCollider(
Collider* collider Collider* collider
); );
// 移除碰撞体 // 移除碰撞体
void __removeCollider( void RemoveCollider(
Collider* collider Collider* collider
); );
// 更新碰撞体 // 更新碰撞体
void __updateCollider( void UpdateCollider(
Collider* collider Collider* collider
); );
private: private:
bool _collisionEnabled; bool collision_enabled_;
std::vector<Collider*> _colliders; std::vector<Collider*> colliders_;
std::set<std::pair<size_t, size_t>> _collisionList; std::set<std::pair<size_t, size_t>> collision_list_;
}; };
} }

File diff suppressed because it is too large Load Diff

View File

@ -11,40 +11,40 @@ class Random
public: public:
// 取得范围内的一个整型随机数 // 取得范围内的一个整型随机数
template<typename T> template<typename T>
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: private:
template<typename T> template<typename T>
static T __randomInt(T min, T max) static T RandomInt(T min, T max)
{ {
std::uniform_int_distribution<T> dist(min, max); std::uniform_int_distribution<T> dist(min, max);
return dist(Random::__getEngine()); return dist(Random::GetEngine());
} }
template<typename T> template<typename T>
static T __randomReal(T min, T max) static T RandomReal(T min, T max)
{ {
std::uniform_real_distribution<T> dist(min, max); std::uniform_real_distribution<T> dist(min, max);
return dist(Random::__getEngine()); return dist(Random::GetEngine());
} }
// 获取随机数产生器 // 获取随机数产生器
static std::default_random_engine &__getEngine(); static std::default_random_engine &GetEngine();
}; };
@ -58,7 +58,7 @@ public:
Music(); Music();
explicit Music( explicit Music(
const e2d::String& filePath /* 音乐文件路径 */ const e2d::String& file_path /* 音乐文件路径 */
); );
explicit Music( explicit Music(
@ -68,52 +68,52 @@ public:
virtual ~Music(); virtual ~Music();
// 打开音乐文件 // 打开音乐文件
bool open( bool Open(
const e2d::String& filePath /* 音乐文件路径 */ const e2d::String& file_path /* 音乐文件路径 */
); );
// 打开音乐资源 // 打开音乐资源
bool open( bool Open(
const Resource& res const Resource& res
); );
// 播放 // 播放
bool play( bool Play(
int nLoopCount = 0 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 float volume
); );
// 设置播放结束时的执行函数 // 设置播放结束时的执行函数
void setFuncOnEnd( void SetCallbackOnEnd(
const Function& func const Function& func
); );
// 设置循环播放中每一次播放结束时的执行函数 // 设置循环播放中每一次播放结束时的执行函数
void setFuncOnLoopEnd( void SetCallbackOnLoopEnd(
const Function& func const Function& func
); );
// 获取 IXAudio2SourceVoice 对象 // 获取 IXAudio2SourceVoice 对象
IXAudio2SourceVoice * getIXAudio2SourceVoice() const; IXAudio2SourceVoice * GetSourceVoice() const;
protected: protected:
bool _readMMIO(); bool _readMMIO();
@ -121,27 +121,27 @@ protected:
bool _resetFile(); bool _resetFile();
bool _read( bool _read(
BYTE* pBuffer, BYTE* buffer,
DWORD dwSizeToRead DWORD size_to_read
); );
bool _findMediaFileCch( bool _findMediaFileCch(
wchar_t* strDestPath, wchar_t* dest_path,
int cchDest, int cch_dest,
const wchar_t * strFilename const wchar_t * file_name
); );
protected: protected:
bool _opened; bool opened_;
DWORD _dwSize; DWORD size_;
CHAR* _resBuffer; CHAR* buffer_;
BYTE* _waveData; BYTE* wave_data_;
HMMIO _hmmio; HMMIO hmmio_;
MMCKINFO _ck; MMCKINFO ck_;
MMCKINFO _ckRiff; MMCKINFO ck_riff_;
WAVEFORMATEX* _wfx; WAVEFORMATEX* wfx_;
VoiceCallback _voiceCallback; VoiceCallback callback_;
IXAudio2SourceVoice* _voice; IXAudio2SourceVoice* voice_;
}; };
@ -150,92 +150,92 @@ class Player
{ {
public: public:
// 获取播放器实例 // 获取播放器实例
static Player * getInstance(); static Player * GetInstance();
// 销毁实例 // 销毁实例
static void destroyInstance(); static void DestroyInstance();
// 预加载音乐资源 // 预加载音乐资源
bool preload( bool Preload(
const String& filePath /* 音乐文件路径 */ const String& file_path /* 音乐文件路径 */
); );
// 播放音乐 // 播放音乐
bool play( bool Play(
const String& filePath, /* 音乐文件路径 */ const String& file_path, /* 音乐文件路径 */
int nLoopCount = 0 /* 重复播放次数,设置 -1 为循环播放 */ int loop_count = 0 /* 重复播放次数,设置 -1 为循环播放 */
); );
// 暂停音乐 // 暂停音乐
void pause( void Pause(
const String& filePath /* 音乐文件路径 */ const String& file_path /* 音乐文件路径 */
); );
// 继续播放音乐 // 继续播放音乐
void resume( void Resume(
const String& filePath /* 音乐文件路径 */ const String& file_path /* 音乐文件路径 */
); );
// 停止音乐 // 停止音乐
void stop( void Stop(
const String& filePath /* 音乐文件路径 */ const String& file_path /* 音乐文件路径 */
); );
// 获取音乐播放状态 // 获取音乐播放状态
bool isPlaying( bool IsPlaying(
const String& filePath /* 音乐文件路径 */ const String& file_path /* 音乐文件路径 */
); );
// 预加载音乐资源 // 预加载音乐资源
bool preload( bool Preload(
const Resource& res /* 音乐资源 */ const Resource& res /* 音乐资源 */
); );
// 播放音乐 // 播放音乐
bool play( bool Play(
const Resource& res, /* 音乐资源 */ const Resource& res, /* 音乐资源 */
int nLoopCount = 0 /* 重复播放次数,设置 -1 为循环播放 */ int loop_count = 0 /* 重复播放次数,设置 -1 为循环播放 */
); );
// 暂停音乐 // 暂停音乐
void pause( void Pause(
const Resource& res /* 音乐资源 */ const Resource& res /* 音乐资源 */
); );
// 继续播放音乐 // 继续播放音乐
void resume( void Resume(
const Resource& res /* 音乐资源 */ const Resource& res /* 音乐资源 */
); );
// 停止音乐 // 停止音乐
void stop( void Stop(
const Resource& res /* 音乐资源 */ const Resource& res /* 音乐资源 */
); );
// 获取音乐播放状态 // 获取音乐播放状态
bool isPlaying( bool IsPlaying(
const Resource& res /* 音乐资源 */ const Resource& res /* 音乐资源 */
); );
// 获取音量 // 获取音量
float getVolume(); float GetVolume();
// 设置音量 // 设置音量
void setVolume( void SetVolume(
float volume /* 音量范围为 -224 ~ 2240 是静音1 是正常音量 */ float volume /* 音量范围为 -224 ~ 2240 是静音1 是正常音量 */
); );
// 暂停所有音乐 // 暂停所有音乐
void pauseAll(); void PauseAll();
// 继续播放所有音乐 // 继续播放所有音乐
void resumeAll(); void ResumeAll();
// 停止所有音乐 // 停止所有音乐
void stopAll(); void StopAll();
// 清空音乐缓存 // 清空音乐缓存
void clearCache(); void ClearCache();
protected: protected:
Player(); Player();
@ -245,10 +245,10 @@ protected:
E2D_DISABLE_COPY(Player); E2D_DISABLE_COPY(Player);
protected: protected:
float _volume; float volume_;
std::map<size_t, Music*> _musicList; std::map<size_t, Music*> 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: protected:
// 执行任务 // 执行任务
void _update(); void Update();
// 任务是否就绪 // 任务是否就绪
bool _isReady() const; bool IsReady() const;
private: private:
bool _running; bool running_;
bool _stopped; bool stopped_;
int _runTimes; int run_times_;
int _totalTimes; int total_times_;
Duration _delay; String name_;
Time _lastTime; Duration delay_;
String _name; Time last_time_;
Function _callback; Function callback_;
}; };
@ -309,45 +309,45 @@ class Timer
{ {
public: public:
// 获取定时器实例 // 获取定时器实例
static Timer * getInstance(); static Timer * GetInstance();
// 添加任务 // 添加任务
void addTask( void AddTask(
Task * task Task * task
); );
// 启动任务 // 启动任务
void startTasks( void StartTasks(
const String& taskName const String& task_name
); );
// 停止任务 // 停止任务
void stopTasks( void StopTasks(
const String& taskName const String& task_name
); );
// 移除任务 // 移除任务
void removeTasks( void RemoveTasks(
const String& taskName 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: private:
Timer(); Timer();
@ -357,7 +357,7 @@ private:
E2D_DISABLE_COPY(Timer); E2D_DISABLE_COPY(Timer);
private: private:
std::vector<Task*> _tasks; std::vector<Task*> tasks_;
}; };
@ -371,53 +371,53 @@ public:
); );
// 保存 int 类型的值 // 保存 int 类型的值
void saveInt( void SaveInt(
int value /* 数据 */ int value /* 数据 */
); );
// 保存 float 类型的值 // 保存 float 类型的值
void saveDouble( void SaveDouble(
float value /* 数据 */ float value /* 数据 */
); );
// 保存 bool 类型的值 // 保存 bool 类型的值
void saveBool( void SaveBool(
bool value /* 数据 */ bool value /* 数据 */
); );
// 保存 字符串 类型的值 // 保存 字符串 类型的值
void saveString( void SaveString(
const String& value /* 数据 */ const String& value /* 数据 */
); );
// 获取 int 类型的值 // 获取 int 类型的值
// (若不存在则返回 defaultValue 参数的值) // (若不存在则返回 default_value 参数的值)
int getInt( int GetInt(
int defaultValue /* 默认值 */ int default_value /* 默认值 */
); );
// 获取 float 类型的值 // 获取 float 类型的值
// (若不存在则返回 defaultValue 参数的值) // (若不存在则返回 default_value 参数的值)
float getDouble( float GetDouble(
float defaultValue /* 默认值 */ float default_value /* 默认值 */
); );
// 获取 bool 类型的值 // 获取 bool 类型的值
// (若不存在则返回 defaultValue 参数的值) // (若不存在则返回 default_value 参数的值)
bool getBool( bool GetBool(
bool defaultValue /* 默认值 */ bool default_value /* 默认值 */
); );
// 获取 字符串 类型的值 // 获取 字符串 类型的值
// (若不存在则返回 defaultValue 参数的值) // (若不存在则返回 default_value 参数的值)
String getString( String GetString(
const String& defaultValue /* 默认值 */ const String& default_value /* 默认值 */
); );
protected: protected:
String _key; String key_;
String _field; String field_;
const String _dataPath; const String& data_path_;
}; };
@ -428,66 +428,66 @@ public:
File(); File();
File( File(
const String& fileName const String& file_name
); );
virtual ~File(); virtual ~File();
// 打开文件 // 打开文件
bool open( bool Open(
const String& fileName 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( static File Extract(
int resNameId, /* 资源名称 */ int resource_name, /* 资源名称 */
const String& resType, /* 资源类型 */ const String& resource_type, /* 资源类型 */
const String& destFileName /* 目标文件名 */ const String& dest_file_name /* 目标文件名 */
); );
// 添加文件搜索路径 // 添加文件搜索路径
static void addSearchPath( static void AddSearchPath(
const String& path const String& path
); );
// 创建文件夹 // 创建文件夹
static bool createFolder( static bool CreateFolder(
const String& dirPath /* 文件夹路径 */ const String& dir_path /* 文件夹路径 */
); );
// 弹出打开文件对话框 // 弹出打开文件对话框
static File showOpenDialog( static File ShowOpenDialog(
const String& title = L"打开", /* 对话框标题 */ const String& title = L"打开", /* 对话框标题 */
const String& filter = L"" /* 筛选扩展名,例如 "*.jpg;*.jpeg" */ const String& filter = L"" /* 筛选扩展名,例如 "*.jpg;*.jpeg" */
); );
// 弹出保存文件对话框 // 弹出保存文件对话框
static File showSaveDialog( static File ShowSaveDialog(
const String& title = L"保存", /* 对话框标题 */ const String& title = L"保存", /* 对话框标题 */
const String& defFile = L"", /* 默认保存的文件名 */ const String& def_file = L"", /* 默认保存的文件名 */
const String& defExt = L"" /* 默认追加的扩展名,例如 "txt" */ const String& def_ext = L"" /* 默认追加的扩展名,例如 "txt" */
); );
protected: protected:
DWORD _attributes; DWORD attributes_;
String _fileName; String file_path_;
static std::list<String> _searchPaths; static std::list<String> search_paths_;
}; };
@ -498,16 +498,16 @@ class Path
public: public:
// 获取数据的默认保存路径 // 获取数据的默认保存路径
static String getDataPath(); static const String& GetDataPath();
// 获取临时文件目录 // 获取临时文件目录
static String getTempPath(); static const String& GetTemporaryPath();
// 获取 LocalAppData 目录 // 获取 LocalAppData 目录
static String getLocalAppDataPath(); static const String& GetLocalAppDataPath();
// 获取当前程序的运行路径 // 获取当前程序的运行路径
static String getCurrentFilePath(); static const String& GetExeFilePath();
}; };
} }

View File

@ -23,38 +23,38 @@ public:
virtual ~Transition(); virtual ~Transition();
// 场景过渡动画是否结束 // 场景过渡动画是否结束
bool isDone(); bool IsDone();
protected: protected:
// 初始化场景过渡动画 // 初始化场景过渡动画
virtual bool _init( virtual bool Init(
Game * game, Game * game,
Scene * prev 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: protected:
bool _end; bool done_;
float _duration; float duration_;
float _delta; float delta_;
Time _started; Time started_;
Scene* _outScene; Scene* out_scene_;
Scene* _inScene; Scene* in_scene_;
ID2D1Layer * _outLayer; ID2D1Layer * out_layer_;
ID2D1Layer * _inLayer; ID2D1Layer * in_layer_;
D2D1_LAYER_PARAMETERS _outLayerParam; D2D1_LAYER_PARAMETERS out_layer_param_;
D2D1_LAYER_PARAMETERS _inLayerParam; D2D1_LAYER_PARAMETERS in_layer_param_;
}; };
@ -70,9 +70,9 @@ public:
protected: protected:
// 更新动画 // 更新动画
virtual void _update() override; virtual void Update() override;
virtual bool _init( virtual bool Init(
Game * game, Game * game,
Scene * prev Scene * prev
) override; ) override;
@ -90,9 +90,9 @@ public:
); );
protected: protected:
virtual void _update() override; virtual void Update() override;
virtual bool _init( virtual bool Init(
Game * game, Game * game,
Scene * prev Scene * prev
) override; ) override;
@ -110,9 +110,9 @@ public:
); );
protected: protected:
virtual void _update() override; virtual void Update() override;
virtual bool _init( virtual bool Init(
Game * game, Game * game,
Scene * prev Scene * prev
) override; ) override;
@ -131,19 +131,19 @@ public:
); );
protected: protected:
virtual void _update() override; virtual void Update() override;
virtual bool _init( virtual bool Init(
Game * game, Game * game,
Scene * prev Scene * prev
) override; ) override;
virtual void _reset() override; virtual void Reset() override;
protected: protected:
Direction _direction; Direction direction_;
Vector2 _posDelta; Point pos_delta_;
Point _startPos; Point start_pos_;
}; };
} }

View File

@ -35,8 +35,10 @@
<ClCompile Include="..\..\core\Action\Action.cpp" /> <ClCompile Include="..\..\core\Action\Action.cpp" />
<ClCompile Include="..\..\core\Action\Animate.cpp" /> <ClCompile Include="..\..\core\Action\Animate.cpp" />
<ClCompile Include="..\..\core\Action\Animation.cpp" /> <ClCompile Include="..\..\core\Action\Animation.cpp" />
<ClCompile Include="..\..\core\Action\CallFunc.cpp" /> <ClCompile Include="..\..\core\Action\Callback.cpp" />
<ClCompile Include="..\..\core\Action\Delay.cpp" /> <ClCompile Include="..\..\core\Action\Delay.cpp" />
<ClCompile Include="..\..\core\Action\FadeIn.cpp" />
<ClCompile Include="..\..\core\Action\FadeOut.cpp" />
<ClCompile Include="..\..\core\Action\FiniteTimeAction.cpp" /> <ClCompile Include="..\..\core\Action\FiniteTimeAction.cpp" />
<ClCompile Include="..\..\core\Action\JumpBy.cpp" /> <ClCompile Include="..\..\core\Action\JumpBy.cpp" />
<ClCompile Include="..\..\core\Action\JumpTo.cpp" /> <ClCompile Include="..\..\core\Action\JumpTo.cpp" />

View File

@ -52,9 +52,6 @@
<ClCompile Include="..\..\core\Action\Animation.cpp"> <ClCompile Include="..\..\core\Action\Animation.cpp">
<Filter>Action</Filter> <Filter>Action</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\Action\CallFunc.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Action\Delay.cpp"> <ClCompile Include="..\..\core\Action\Delay.cpp">
<Filter>Action</Filter> <Filter>Action</Filter>
</ClCompile> </ClCompile>
@ -241,5 +238,14 @@
<ClCompile Include="..\..\core\Base\Audio.cpp"> <ClCompile Include="..\..\core\Base\Audio.cpp">
<Filter>Base</Filter> <Filter>Base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\Action\FadeIn.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Action\FadeOut.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Action\Callback.cpp">
<Filter>Action</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -179,8 +179,10 @@
<ClCompile Include="..\..\core\Action\Action.cpp" /> <ClCompile Include="..\..\core\Action\Action.cpp" />
<ClCompile Include="..\..\core\Action\Animate.cpp" /> <ClCompile Include="..\..\core\Action\Animate.cpp" />
<ClCompile Include="..\..\core\Action\Animation.cpp" /> <ClCompile Include="..\..\core\Action\Animation.cpp" />
<ClCompile Include="..\..\core\Action\CallFunc.cpp" /> <ClCompile Include="..\..\core\Action\Callback.cpp" />
<ClCompile Include="..\..\core\Action\Delay.cpp" /> <ClCompile Include="..\..\core\Action\Delay.cpp" />
<ClCompile Include="..\..\core\Action\FadeIn.cpp" />
<ClCompile Include="..\..\core\Action\FadeOut.cpp" />
<ClCompile Include="..\..\core\Action\FiniteTimeAction.cpp" /> <ClCompile Include="..\..\core\Action\FiniteTimeAction.cpp" />
<ClCompile Include="..\..\core\Action\JumpBy.cpp" /> <ClCompile Include="..\..\core\Action\JumpBy.cpp" />
<ClCompile Include="..\..\core\Action\JumpTo.cpp" /> <ClCompile Include="..\..\core\Action\JumpTo.cpp" />

View File

@ -52,9 +52,6 @@
<ClCompile Include="..\..\core\Action\Animation.cpp"> <ClCompile Include="..\..\core\Action\Animation.cpp">
<Filter>Action</Filter> <Filter>Action</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\Action\CallFunc.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Action\Delay.cpp"> <ClCompile Include="..\..\core\Action\Delay.cpp">
<Filter>Action</Filter> <Filter>Action</Filter>
</ClCompile> </ClCompile>
@ -241,5 +238,14 @@
<ClCompile Include="..\..\core\Base\Audio.cpp"> <ClCompile Include="..\..\core\Base\Audio.cpp">
<Filter>Base</Filter> <Filter>Base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\Action\FadeIn.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Action\FadeOut.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Action\Callback.cpp">
<Filter>Action</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -198,8 +198,10 @@
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\core\Action\Action.cpp" /> <ClCompile Include="..\..\core\Action\Action.cpp" />
<ClCompile Include="..\..\core\Action\Animation.cpp" /> <ClCompile Include="..\..\core\Action\Animation.cpp" />
<ClCompile Include="..\..\core\Action\CallFunc.cpp" /> <ClCompile Include="..\..\core\Action\Callback.cpp" />
<ClCompile Include="..\..\core\Action\Delay.cpp" /> <ClCompile Include="..\..\core\Action\Delay.cpp" />
<ClCompile Include="..\..\core\Action\FadeIn.cpp" />
<ClCompile Include="..\..\core\Action\FadeOut.cpp" />
<ClCompile Include="..\..\core\Action\JumpBy.cpp" /> <ClCompile Include="..\..\core\Action\JumpBy.cpp" />
<ClCompile Include="..\..\core\Action\JumpTo.cpp" /> <ClCompile Include="..\..\core\Action\JumpTo.cpp" />
<ClCompile Include="..\..\core\Action\MoveBy.cpp" /> <ClCompile Include="..\..\core\Action\MoveBy.cpp" />

View File

@ -123,9 +123,6 @@
<ClCompile Include="..\..\core\Action\Loop.cpp"> <ClCompile Include="..\..\core\Action\Loop.cpp">
<Filter>Action</Filter> <Filter>Action</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\Action\CallFunc.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Action\Delay.cpp"> <ClCompile Include="..\..\core\Action\Delay.cpp">
<Filter>Action</Filter> <Filter>Action</Filter>
</ClCompile> </ClCompile>
@ -234,6 +231,15 @@
<ClCompile Include="..\..\core\Base\Audio.cpp"> <ClCompile Include="..\..\core\Base\Audio.cpp">
<Filter>Base</Filter> <Filter>Base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\Action\FadeIn.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Action\FadeOut.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Action\Callback.cpp">
<Filter>Action</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />