update: code style

This commit is contained in:
Haibo 2018-11-08 00:21:59 +08:00 committed by Nomango
parent 0f1ba104dd
commit b129a1bf18
60 changed files with 6300 additions and 6091 deletions

View File

@ -20,7 +20,10 @@
#include "..\e2daction.h" #include "..\e2daction.h"
easy2d::Action::Action()
namespace easy2d
{
Action::Action()
: running_(false) : running_(false)
, done_(false) , done_(false)
, initialized_(false) , initialized_(false)
@ -28,71 +31,71 @@ easy2d::Action::Action()
{ {
} }
easy2d::Action::~Action() Action::~Action()
{ {
} }
bool easy2d::Action::IsRunning() bool Action::IsRunning()
{ {
return running_; return running_;
} }
void easy2d::Action::Resume() void Action::Resume()
{ {
running_ = true; running_ = true;
} }
void easy2d::Action::Pause() void Action::Pause()
{ {
running_ = false; running_ = false;
} }
void easy2d::Action::Stop() void Action::Stop()
{ {
done_ = true; done_ = true;
} }
const std::wstring& easy2d::Action::GetName() const const std::wstring& Action::GetName() const
{ {
return name_; return name_;
} }
void easy2d::Action::SetName(const std::wstring& name) void Action::SetName(const std::wstring& name)
{ {
name_ = name; name_ = name;
} }
easy2d::Node * easy2d::Action::GetTarget() Node * Action::GetTarget()
{ {
return target_; return target_;
} }
void easy2d::Action::Reset() void Action::Reset()
{ {
initialized_ = false; initialized_ = false;
done_ = false; done_ = false;
started_ = Time::Now(); started_ = Time::Now();
} }
bool easy2d::Action::IsDone() const bool Action::IsDone() const
{ {
return done_; return done_;
} }
void easy2d::Action::StartWithTarget(Node* target) void Action::StartWithTarget(Node* target)
{ {
target_ = target; target_ = target;
running_ = true; running_ = true;
this->Reset(); this->Reset();
} }
void easy2d::Action::Init() void Action::Init()
{ {
initialized_ = true; initialized_ = true;
started_ = Time::Now(); started_ = Time::Now();
} }
void easy2d::Action::Update() void Action::Update()
{ {
if (!initialized_) if (!initialized_)
{ {
@ -100,6 +103,7 @@ void easy2d::Action::Update()
} }
} }
void easy2d::Action::ResetTime() void Action::ResetTime()
{ {
} }
}

View File

@ -21,30 +21,32 @@
#include "..\e2daction.h" #include "..\e2daction.h"
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::Animate::Animate() namespace easy2d
{
Animate::Animate()
: frame_index_(0) : frame_index_(0)
, animation_(nullptr) , animation_(nullptr)
{ {
} }
easy2d::Animate::Animate(Animation * animation) Animate::Animate(Animation * animation)
: frame_index_(0) : frame_index_(0)
, animation_(nullptr) , animation_(nullptr)
{ {
this->SetAnimation(animation); this->SetAnimation(animation);
} }
easy2d::Animate::~Animate() Animate::~Animate()
{ {
SafeRelease(animation_); SafeRelease(animation_);
} }
easy2d::Animation * easy2d::Animate::GetAnimation() const Animation * Animate::GetAnimation() const
{ {
return animation_; return animation_;
} }
void easy2d::Animate::SetAnimation(Animation * animation) void Animate::SetAnimation(Animation * animation)
{ {
if (animation && animation != animation_) if (animation && animation != animation_)
{ {
@ -58,7 +60,7 @@ void easy2d::Animate::SetAnimation(Animation * animation)
} }
} }
void easy2d::Animate::Init() void Animate::Init()
{ {
Action::Init(); Action::Init();
@ -70,7 +72,7 @@ void easy2d::Animate::Init()
} }
} }
void easy2d::Animate::Update() void Animate::Update()
{ {
Action::Update(); Action::Update();
@ -101,18 +103,18 @@ void easy2d::Animate::Update()
} }
} }
void easy2d::Animate::ResetTime() void Animate::ResetTime()
{ {
Action::ResetTime(); Action::ResetTime();
} }
void easy2d::Animate::Reset() void Animate::Reset()
{ {
Action::Reset(); Action::Reset();
frame_index_ = 0; frame_index_ = 0;
} }
easy2d::Animate * easy2d::Animate::Clone() const Animate * Animate::Clone() const
{ {
if (animation_) if (animation_)
{ {
@ -121,7 +123,7 @@ easy2d::Animate * easy2d::Animate::Clone() const
return nullptr; return nullptr;
} }
easy2d::Animate * easy2d::Animate::Reverse() const Animate * Animate::Reverse() const
{ {
if (animation_) if (animation_)
{ {
@ -133,3 +135,4 @@ easy2d::Animate * easy2d::Animate::Reverse() const
} }
return nullptr; return nullptr;
} }
}

View File

@ -20,29 +20,31 @@
#include "..\e2daction.h" #include "..\e2daction.h"
easy2d::Animation::Animation() namespace easy2d
{
Animation::Animation()
: interval_(1) : interval_(1)
{ {
} }
easy2d::Animation::Animation(const Images& frames) Animation::Animation(const Images& frames)
: interval_(1) : interval_(1)
{ {
this->Add(frames); this->Add(frames);
} }
easy2d::Animation::Animation(float interval) Animation::Animation(float interval)
: interval_(interval) : interval_(interval)
{ {
} }
easy2d::Animation::Animation(float interval, const Images& frames) Animation::Animation(float interval, const Images& frames)
: interval_(interval) : interval_(interval)
{ {
this->Add(frames); this->Add(frames);
} }
easy2d::Animation::~Animation() Animation::~Animation()
{ {
for (auto frame : frames_) for (auto frame : frames_)
{ {
@ -50,12 +52,12 @@ easy2d::Animation::~Animation()
} }
} }
void easy2d::Animation::SetInterval(float interval) void Animation::SetInterval(float interval)
{ {
interval_ = std::max(interval, 0.f); interval_ = std::max(interval, 0.f);
} }
void easy2d::Animation::Add(Image * frame) void Animation::Add(Image * frame)
{ {
E2D_WARNING_IF(frame == nullptr, "Animation::Add failed, frame Is nullptr."); E2D_WARNING_IF(frame == nullptr, "Animation::Add failed, frame Is nullptr.");
if (frame) if (frame)
@ -65,7 +67,7 @@ void easy2d::Animation::Add(Image * frame)
} }
} }
void easy2d::Animation::Add(const Images& frames) void Animation::Add(const Images& frames)
{ {
for (const auto &image : frames) for (const auto &image : frames)
{ {
@ -73,17 +75,17 @@ void easy2d::Animation::Add(const Images& frames)
} }
} }
float easy2d::Animation::GetInterval() const float Animation::GetInterval() const
{ {
return interval_; return interval_;
} }
const easy2d::Animation::Images& easy2d::Animation::GetFrames() const const Animation::Images& Animation::GetFrames() const
{ {
return frames_; return frames_;
} }
easy2d::Animation * easy2d::Animation::Clone() const Animation * Animation::Clone() const
{ {
auto animation = new Animation(interval_); auto animation = new Animation(interval_);
if (animation) if (animation)
@ -96,7 +98,7 @@ easy2d::Animation * easy2d::Animation::Clone() const
return animation; return animation;
} }
easy2d::Animation * easy2d::Animation::Reverse() const Animation * Animation::Reverse() const
{ {
auto& oldFrames = this->GetFrames(); auto& oldFrames = this->GetFrames();
Images frames(oldFrames.size()); Images frames(oldFrames.size());
@ -118,3 +120,4 @@ easy2d::Animation * easy2d::Animation::Reverse() const
return new Animation(this->GetInterval(), frames); return new Animation(this->GetInterval(), frames);
} }
}

View File

@ -20,27 +20,30 @@
#include "..\e2daction.h" #include "..\e2daction.h"
easy2d::CallFunc::CallFunc(const Callback& func) : namespace easy2d
{
CallFunc::CallFunc(const Callback& func) :
callback_(func) callback_(func)
{ {
} }
easy2d::CallFunc * easy2d::CallFunc::Clone() const CallFunc * CallFunc::Clone() const
{ {
return new CallFunc(callback_); return new CallFunc(callback_);
} }
easy2d::CallFunc * easy2d::CallFunc::Reverse() const CallFunc * CallFunc::Reverse() const
{ {
return new CallFunc(callback_); return new CallFunc(callback_);
} }
void easy2d::CallFunc::Init() void CallFunc::Init()
{ {
} }
void easy2d::CallFunc::Update() void CallFunc::Update()
{ {
callback_(); callback_();
this->Stop(); this->Stop();
} }
}

View File

@ -20,34 +20,36 @@
#include "..\e2daction.h" #include "..\e2daction.h"
easy2d::Delay::Delay(float duration) namespace easy2d
{
Delay::Delay(float duration)
: delta_(0) : delta_(0)
, delay_(std::max(duration, 0.f)) , delay_(std::max(duration, 0.f))
{ {
} }
easy2d::Delay * easy2d::Delay::Clone() const Delay * Delay::Clone() const
{ {
return new Delay(delay_); return new Delay(delay_);
} }
easy2d::Delay * easy2d::Delay::Reverse() const Delay * Delay::Reverse() const
{ {
return new Delay(delay_); return new Delay(delay_);
} }
void easy2d::Delay::Reset() void Delay::Reset()
{ {
Action::Reset(); Action::Reset();
delta_ = 0; delta_ = 0;
} }
void easy2d::Delay::Init() void Delay::Init()
{ {
Action::Init(); Action::Init();
} }
void easy2d::Delay::Update() void Delay::Update()
{ {
Action::Update(); Action::Update();
@ -59,8 +61,9 @@ void easy2d::Delay::Update()
} }
} }
void easy2d::Delay::ResetTime() void Delay::ResetTime()
{ {
Action::ResetTime(); Action::ResetTime();
started_ = Time::Now() - Duration::Second * delta_; started_ = Time::Now() - Duration::Second * delta_;
} }
}

View File

@ -20,7 +20,10 @@
#include "..\e2daction.h" #include "..\e2daction.h"
easy2d::FadeIn::FadeIn(float duration) namespace easy2d
{
FadeIn::FadeIn(float duration)
: OpacityTo(duration, 1) : OpacityTo(duration, 1)
{ {
} }
}

View File

@ -20,7 +20,10 @@
#include "..\e2daction.h" #include "..\e2daction.h"
easy2d::FadeOut::FadeOut(float duration) namespace easy2d
{
FadeOut::FadeOut(float duration)
: OpacityTo(duration, 0) : OpacityTo(duration, 0)
{ {
} }
}

View File

@ -20,24 +20,26 @@
#include "..\e2daction.h" #include "..\e2daction.h"
easy2d::FiniteTimeAction::FiniteTimeAction(float duration) namespace easy2d
{
FiniteTimeAction::FiniteTimeAction(float duration)
: delta_(0) : delta_(0)
, duration_(std::max(duration, 0.f)) , duration_(std::max(duration, 0.f))
{ {
} }
void easy2d::FiniteTimeAction::Reset() void FiniteTimeAction::Reset()
{ {
Action::Reset(); Action::Reset();
delta_ = 0; delta_ = 0;
} }
void easy2d::FiniteTimeAction::Init() void FiniteTimeAction::Init()
{ {
Action::Init(); Action::Init();
} }
void easy2d::FiniteTimeAction::Update() void FiniteTimeAction::Update()
{ {
Action::Update(); Action::Update();
@ -57,8 +59,9 @@ void easy2d::FiniteTimeAction::Update()
} }
} }
void easy2d::FiniteTimeAction::ResetTime() void FiniteTimeAction::ResetTime()
{ {
Action::ResetTime(); Action::ResetTime();
started_ = Time::Now() - Duration::Second * (delta_ * duration_); started_ = Time::Now() - Duration::Second * (delta_ * duration_);
} }
}

View File

@ -21,7 +21,9 @@
#include "..\e2daction.h" #include "..\e2daction.h"
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::JumpBy::JumpBy(float duration, const Point & vec, float height, int jumps) namespace easy2d
{
JumpBy::JumpBy(float duration, const Point & vec, float height, int jumps)
: FiniteTimeAction(duration) : FiniteTimeAction(duration)
, delta_pos_(vec) , delta_pos_(vec)
, height_(height) , height_(height)
@ -29,17 +31,17 @@ easy2d::JumpBy::JumpBy(float duration, const Point & vec, float height, int jump
{ {
} }
easy2d::JumpBy * easy2d::JumpBy::Clone() const JumpBy * JumpBy::Clone() const
{ {
return new JumpBy(duration_, delta_pos_, height_, jumps_); return new JumpBy(duration_, delta_pos_, height_, jumps_);
} }
easy2d::JumpBy * easy2d::JumpBy::Reverse() const JumpBy * JumpBy::Reverse() const
{ {
return new JumpBy(duration_, -delta_pos_, height_, jumps_); return new JumpBy(duration_, -delta_pos_, height_, jumps_);
} }
void easy2d::JumpBy::Init() void JumpBy::Init()
{ {
FiniteTimeAction::Init(); FiniteTimeAction::Init();
@ -49,7 +51,7 @@ void easy2d::JumpBy::Init()
} }
} }
void easy2d::JumpBy::Update() void JumpBy::Update()
{ {
FiniteTimeAction::Update(); FiniteTimeAction::Update();
@ -71,3 +73,4 @@ void easy2d::JumpBy::Update()
prev_pos_ = newPos; prev_pos_ = newPos;
} }
} }
}

View File

@ -21,19 +21,22 @@
#include "..\e2daction.h" #include "..\e2daction.h"
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::JumpTo::JumpTo(float duration, const Point & pos, float height, int jumps) namespace easy2d
{
JumpTo::JumpTo(float duration, const Point & pos, float height, int jumps)
: JumpBy(duration, Point(), height, jumps) : JumpBy(duration, Point(), height, jumps)
, end_pos_(pos) , end_pos_(pos)
{ {
} }
easy2d::JumpTo * easy2d::JumpTo::Clone() const JumpTo * JumpTo::Clone() const
{ {
return new JumpTo(duration_, end_pos_, height_, jumps_); return new JumpTo(duration_, end_pos_, height_, jumps_);
} }
void easy2d::JumpTo::Init() void JumpTo::Init()
{ {
JumpBy::Init(); JumpBy::Init();
delta_pos_ = end_pos_ - start_pos_; delta_pos_ = end_pos_ - start_pos_;
} }
}

View File

@ -20,7 +20,9 @@
#include "..\e2daction.h" #include "..\e2daction.h"
easy2d::Loop::Loop(Action * action, int times /* = -1 */) namespace easy2d
{
Loop::Loop(Action * action, int times /* = -1 */)
: action_(action) : action_(action)
, times_(0) , times_(0)
, total_times_(times) , total_times_(times)
@ -34,12 +36,12 @@ easy2d::Loop::Loop(Action * action, int times /* = -1 */)
} }
} }
easy2d::Loop::~Loop() Loop::~Loop()
{ {
SafeRelease(action_); SafeRelease(action_);
} }
easy2d::Loop * easy2d::Loop::Clone() const Loop * Loop::Clone() const
{ {
if (action_) if (action_)
{ {
@ -51,7 +53,7 @@ easy2d::Loop * easy2d::Loop::Clone() const
} }
} }
easy2d::Loop * easy2d::Loop::Reverse() const Loop * Loop::Reverse() const
{ {
if (action_) if (action_)
{ {
@ -63,7 +65,7 @@ easy2d::Loop * easy2d::Loop::Reverse() const
} }
} }
void easy2d::Loop::Init() void Loop::Init()
{ {
Action::Init(); Action::Init();
@ -74,7 +76,7 @@ void easy2d::Loop::Init()
} }
} }
void easy2d::Loop::Update() void Loop::Update()
{ {
Action::Update(); Action::Update();
@ -102,7 +104,7 @@ void easy2d::Loop::Update()
} }
} }
void easy2d::Loop::Reset() void Loop::Reset()
{ {
Action::Reset(); Action::Reset();
@ -110,7 +112,8 @@ void easy2d::Loop::Reset()
times_ = 0; times_ = 0;
} }
void easy2d::Loop::ResetTime() void Loop::ResetTime()
{ {
if (action_) action_->ResetTime(); if (action_) action_->ResetTime();
} }
}

View File

@ -22,13 +22,15 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::MoveBy::MoveBy(float duration, Point vector) namespace easy2d
{
MoveBy::MoveBy(float duration, Point vector)
: FiniteTimeAction(duration) : FiniteTimeAction(duration)
{ {
delta_pos_ = vector; delta_pos_ = vector;
} }
void easy2d::MoveBy::Init() void MoveBy::Init()
{ {
FiniteTimeAction::Init(); FiniteTimeAction::Init();
@ -38,7 +40,7 @@ void easy2d::MoveBy::Init()
} }
} }
void easy2d::MoveBy::Update() void MoveBy::Update()
{ {
FiniteTimeAction::Update(); FiniteTimeAction::Update();
@ -55,12 +57,13 @@ void easy2d::MoveBy::Update()
} }
} }
easy2d::MoveBy * easy2d::MoveBy::Clone() const MoveBy * MoveBy::Clone() const
{ {
return new MoveBy(duration_, delta_pos_); return new MoveBy(duration_, delta_pos_);
} }
easy2d::MoveBy * easy2d::MoveBy::Reverse() const MoveBy * MoveBy::Reverse() const
{ {
return new MoveBy(duration_, -delta_pos_); return new MoveBy(duration_, -delta_pos_);
} }
}

View File

@ -21,19 +21,22 @@
#include "..\e2daction.h" #include "..\e2daction.h"
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::MoveTo::MoveTo(float duration, Point pos) namespace easy2d
{
MoveTo::MoveTo(float duration, Point pos)
: MoveBy(duration, Point()) : MoveBy(duration, Point())
{ {
end_pos_ = pos; end_pos_ = pos;
} }
easy2d::MoveTo * easy2d::MoveTo::Clone() const MoveTo * MoveTo::Clone() const
{ {
return new MoveTo(duration_, end_pos_); return new MoveTo(duration_, end_pos_);
} }
void easy2d::MoveTo::Init() void MoveTo::Init()
{ {
MoveBy::Init(); MoveBy::Init();
delta_pos_ = end_pos_ - start_pos_; delta_pos_ = end_pos_ - start_pos_;
} }
}

View File

@ -22,13 +22,15 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::OpacityBy::OpacityBy(float duration, float opacity) namespace easy2d
{
OpacityBy::OpacityBy(float duration, float opacity)
: FiniteTimeAction(duration) : FiniteTimeAction(duration)
{ {
delta_val_ = opacity; delta_val_ = opacity;
} }
void easy2d::OpacityBy::Init() void OpacityBy::Init()
{ {
FiniteTimeAction::Init(); FiniteTimeAction::Init();
@ -38,7 +40,7 @@ void easy2d::OpacityBy::Init()
} }
} }
void easy2d::OpacityBy::Update() void OpacityBy::Update()
{ {
FiniteTimeAction::Update(); FiniteTimeAction::Update();
@ -48,12 +50,13 @@ void easy2d::OpacityBy::Update()
} }
} }
easy2d::OpacityBy * easy2d::OpacityBy::Clone() const OpacityBy * OpacityBy::Clone() const
{ {
return new OpacityBy(duration_, delta_val_); return new OpacityBy(duration_, delta_val_);
} }
easy2d::OpacityBy * easy2d::OpacityBy::Reverse() const OpacityBy * OpacityBy::Reverse() const
{ {
return new OpacityBy(duration_, -delta_val_); return new OpacityBy(duration_, -delta_val_);
} }
}

View File

@ -22,19 +22,22 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::OpacityTo::OpacityTo(float duration, float opacity) namespace easy2d
{
OpacityTo::OpacityTo(float duration, float opacity)
: OpacityBy(duration, 0) : OpacityBy(duration, 0)
{ {
end_val_ = opacity; end_val_ = opacity;
} }
easy2d::OpacityTo * easy2d::OpacityTo::Clone() const OpacityTo * OpacityTo::Clone() const
{ {
return new OpacityTo(duration_, end_val_); return new OpacityTo(duration_, end_val_);
} }
void easy2d::OpacityTo::Init() void OpacityTo::Init()
{ {
OpacityBy::Init(); OpacityBy::Init();
delta_val_ = end_val_ - start_val_; delta_val_ = end_val_ - start_val_;
} }
}

View File

@ -22,13 +22,15 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::RotateBy::RotateBy(float duration, float rotation) namespace easy2d
{
RotateBy::RotateBy(float duration, float rotation)
: FiniteTimeAction(duration) : FiniteTimeAction(duration)
{ {
delta_val_ = rotation; delta_val_ = rotation;
} }
void easy2d::RotateBy::Init() void RotateBy::Init()
{ {
FiniteTimeAction::Init(); FiniteTimeAction::Init();
@ -38,7 +40,7 @@ void easy2d::RotateBy::Init()
} }
} }
void easy2d::RotateBy::Update() void RotateBy::Update()
{ {
FiniteTimeAction::Update(); FiniteTimeAction::Update();
@ -48,12 +50,13 @@ void easy2d::RotateBy::Update()
} }
} }
easy2d::RotateBy * easy2d::RotateBy::Clone() const RotateBy * RotateBy::Clone() const
{ {
return new RotateBy(duration_, delta_val_); return new RotateBy(duration_, delta_val_);
} }
easy2d::RotateBy * easy2d::RotateBy::Reverse() const RotateBy * RotateBy::Reverse() const
{ {
return new RotateBy(duration_, -delta_val_); return new RotateBy(duration_, -delta_val_);
} }
}

View File

@ -22,19 +22,22 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::RotateTo::RotateTo(float duration, float rotation) namespace easy2d
{
RotateTo::RotateTo(float duration, float rotation)
: RotateBy(duration, 0) : RotateBy(duration, 0)
{ {
end_val_ = rotation; end_val_ = rotation;
} }
easy2d::RotateTo * easy2d::RotateTo::Clone() const RotateTo * RotateTo::Clone() const
{ {
return new RotateTo(duration_, end_val_); return new RotateTo(duration_, end_val_);
} }
void easy2d::RotateTo::Init() void RotateTo::Init()
{ {
RotateBy::Init(); RotateBy::Init();
delta_val_ = end_val_ - start_val_; delta_val_ = end_val_ - start_val_;
} }
}

View File

@ -22,21 +22,23 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::ScaleBy::ScaleBy(float duration, float scale) namespace easy2d
{
ScaleBy::ScaleBy(float duration, float scale)
: FiniteTimeAction(duration) : FiniteTimeAction(duration)
{ {
delta_x_ = scale; delta_x_ = scale;
delta_y_ = scale; delta_y_ = scale;
} }
easy2d::ScaleBy::ScaleBy(float duration, float scale_x, float scale_y) ScaleBy::ScaleBy(float duration, float scale_x, float scale_y)
: FiniteTimeAction(duration) : FiniteTimeAction(duration)
{ {
delta_x_ = scale_x; delta_x_ = scale_x;
delta_y_ = scale_y; delta_y_ = scale_y;
} }
void easy2d::ScaleBy::Init() void ScaleBy::Init()
{ {
FiniteTimeAction::Init(); FiniteTimeAction::Init();
@ -47,7 +49,7 @@ void easy2d::ScaleBy::Init()
} }
} }
void easy2d::ScaleBy::Update() void ScaleBy::Update()
{ {
FiniteTimeAction::Update(); FiniteTimeAction::Update();
@ -57,12 +59,13 @@ void easy2d::ScaleBy::Update()
} }
} }
easy2d::ScaleBy * easy2d::ScaleBy::Clone() const ScaleBy * ScaleBy::Clone() const
{ {
return new ScaleBy(duration_, delta_x_, delta_y_); return new ScaleBy(duration_, delta_x_, delta_y_);
} }
easy2d::ScaleBy * easy2d::ScaleBy::Reverse() const ScaleBy * ScaleBy::Reverse() const
{ {
return new ScaleBy(duration_, -delta_x_, -delta_y_); return new ScaleBy(duration_, -delta_x_, -delta_y_);
} }
}

View File

@ -21,28 +21,32 @@
#include "..\e2daction.h" #include "..\e2daction.h"
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::ScaleTo::ScaleTo(float duration, float scale)
namespace easy2d
{
ScaleTo::ScaleTo(float duration, float scale)
: ScaleBy(duration, 0, 0) : ScaleBy(duration, 0, 0)
{ {
end_scale_x_ = scale; end_scale_x_ = scale;
end_scale_y_ = scale; end_scale_y_ = scale;
} }
easy2d::ScaleTo::ScaleTo(float duration, float scale_x, float scale_y) ScaleTo::ScaleTo(float duration, float scale_x, float scale_y)
: ScaleBy(duration, 0, 0) : ScaleBy(duration, 0, 0)
{ {
end_scale_x_ = scale_x; end_scale_x_ = scale_x;
end_scale_y_ = scale_y; end_scale_y_ = scale_y;
} }
easy2d::ScaleTo * easy2d::ScaleTo::Clone() const ScaleTo * ScaleTo::Clone() const
{ {
return new ScaleTo(duration_, end_scale_x_, end_scale_y_); return new ScaleTo(duration_, end_scale_x_, end_scale_y_);
} }
void easy2d::ScaleTo::Init() void ScaleTo::Init()
{ {
ScaleBy::Init(); ScaleBy::Init();
delta_x_ = end_scale_x_ - start_scale_x_; delta_x_ = end_scale_x_ - start_scale_x_;
delta_y_ = end_scale_y_ - start_scale_y_; delta_y_ = end_scale_y_ - start_scale_y_;
} }
}

View File

@ -20,18 +20,21 @@
#include "..\e2daction.h" #include "..\e2daction.h"
easy2d::Sequence::Sequence()
namespace easy2d
{
Sequence::Sequence()
: action_index_(0) : action_index_(0)
{ {
} }
easy2d::Sequence::Sequence(const Actions& actions) Sequence::Sequence(const Actions& actions)
: action_index_(0) : action_index_(0)
{ {
this->Add(actions); this->Add(actions);
} }
easy2d::Sequence::~Sequence() Sequence::~Sequence()
{ {
for (auto action : actions_) for (auto action : actions_)
{ {
@ -39,7 +42,7 @@ easy2d::Sequence::~Sequence()
} }
} }
void easy2d::Sequence::Init() void Sequence::Init()
{ {
Action::Init(); Action::Init();
// ½«ËùÓж¯×÷ÓëÄ¿±ê°ó¶¨ // ½«ËùÓж¯×÷ÓëÄ¿±ê°ó¶¨
@ -54,7 +57,7 @@ void easy2d::Sequence::Init()
actions_[0]->Init(); actions_[0]->Init();
} }
void easy2d::Sequence::Update() void Sequence::Update()
{ {
Action::Update(); Action::Update();
@ -75,7 +78,7 @@ void easy2d::Sequence::Update()
} }
} }
void easy2d::Sequence::Reset() void Sequence::Reset()
{ {
Action::Reset(); Action::Reset();
for (const auto& action : actions_) for (const auto& action : actions_)
@ -85,7 +88,7 @@ void easy2d::Sequence::Reset()
action_index_ = 0; action_index_ = 0;
} }
void easy2d::Sequence::ResetTime() void Sequence::ResetTime()
{ {
for (const auto& action : actions_) for (const auto& action : actions_)
{ {
@ -93,7 +96,7 @@ void easy2d::Sequence::ResetTime()
} }
} }
void easy2d::Sequence::Add(Action * action) void Sequence::Add(Action * action)
{ {
if (action) if (action)
{ {
@ -102,7 +105,7 @@ void easy2d::Sequence::Add(Action * action)
} }
} }
void easy2d::Sequence::Add(const Actions& actions) void Sequence::Add(const Actions& actions)
{ {
for (const auto &action : actions) for (const auto &action : actions)
{ {
@ -110,7 +113,7 @@ void easy2d::Sequence::Add(const Actions& actions)
} }
} }
easy2d::Sequence * easy2d::Sequence::Clone() const Sequence * Sequence::Clone() const
{ {
auto sequence = new Sequence(); auto sequence = new Sequence();
for (const auto& action : actions_) for (const auto& action : actions_)
@ -123,7 +126,7 @@ easy2d::Sequence * easy2d::Sequence::Clone() const
return sequence; return sequence;
} }
easy2d::Sequence * easy2d::Sequence::Reverse() const Sequence * Sequence::Reverse() const
{ {
auto sequence = new Sequence(); auto sequence = new Sequence();
if (sequence && !actions_.empty()) if (sequence && !actions_.empty())
@ -137,3 +140,4 @@ easy2d::Sequence * easy2d::Sequence::Reverse() const
} }
return sequence; return sequence;
} }
}

View File

@ -20,16 +20,19 @@
#include "..\e2daction.h" #include "..\e2daction.h"
easy2d::Spawn::Spawn()
namespace easy2d
{
Spawn::Spawn()
{ {
} }
easy2d::Spawn::Spawn(const Actions& actions) Spawn::Spawn(const Actions& actions)
{ {
this->Add(actions); this->Add(actions);
} }
easy2d::Spawn::~Spawn() Spawn::~Spawn()
{ {
for (auto action : actions_) for (auto action : actions_)
{ {
@ -37,7 +40,7 @@ easy2d::Spawn::~Spawn()
} }
} }
void easy2d::Spawn::Init() void Spawn::Init()
{ {
Action::Init(); Action::Init();
@ -51,7 +54,7 @@ void easy2d::Spawn::Init()
} }
} }
void easy2d::Spawn::Update() void Spawn::Update()
{ {
Action::Update(); Action::Update();
@ -74,7 +77,7 @@ void easy2d::Spawn::Update()
} }
} }
void easy2d::Spawn::Reset() void Spawn::Reset()
{ {
Action::Reset(); Action::Reset();
for (const auto& action : actions_) for (const auto& action : actions_)
@ -83,7 +86,7 @@ void easy2d::Spawn::Reset()
} }
} }
void easy2d::Spawn::ResetTime() void Spawn::ResetTime()
{ {
for (const auto& action : actions_) for (const auto& action : actions_)
{ {
@ -91,7 +94,7 @@ void easy2d::Spawn::ResetTime()
} }
} }
void easy2d::Spawn::Add(Action * action) void Spawn::Add(Action * action)
{ {
if (action) if (action)
{ {
@ -100,7 +103,7 @@ void easy2d::Spawn::Add(Action * action)
} }
} }
void easy2d::Spawn::Add(const Actions& actions) void Spawn::Add(const Actions& actions)
{ {
for (const auto &action : actions) for (const auto &action : actions)
{ {
@ -108,7 +111,7 @@ void easy2d::Spawn::Add(const Actions& actions)
} }
} }
easy2d::Spawn * easy2d::Spawn::Clone() const Spawn * Spawn::Clone() const
{ {
auto spawn = new Spawn(); auto spawn = new Spawn();
for (const auto& action : actions_) for (const auto& action : actions_)
@ -121,7 +124,7 @@ easy2d::Spawn * easy2d::Spawn::Clone() const
return spawn; return spawn;
} }
easy2d::Spawn * easy2d::Spawn::Reverse() const Spawn * Spawn::Reverse() const
{ {
auto spawn = new Spawn(); auto spawn = new Spawn();
if (spawn && !actions_.empty()) if (spawn && !actions_.empty())
@ -135,3 +138,4 @@ easy2d::Spawn * easy2d::Spawn::Reverse() const
} }
return spawn; return spawn;
} }
}

View File

@ -37,7 +37,9 @@
} \ } \
easy2d::Button::Button() namespace easy2d
{
Button::Button()
: callback_(nullptr) : callback_(nullptr)
, status_(Status::Normal) , status_(Status::Normal)
, enabled_(true) , enabled_(true)
@ -49,7 +51,7 @@ easy2d::Button::Button()
{ {
} }
easy2d::Button::Button(Node * normal, const Callback& func) Button::Button(Node * normal, const Callback& func)
: callback_(nullptr) : callback_(nullptr)
, status_(Status::Normal) , status_(Status::Normal)
, enabled_(true) , enabled_(true)
@ -63,7 +65,7 @@ easy2d::Button::Button(Node * normal, const Callback& func)
this->SetCallbackOnClick(func); this->SetCallbackOnClick(func);
} }
easy2d::Button::Button(Node * normal, Node * selected, const Callback& func) Button::Button(Node * normal, Node * selected, const Callback& func)
: callback_(nullptr) : callback_(nullptr)
, status_(Status::Normal) , status_(Status::Normal)
, enabled_(true) , enabled_(true)
@ -78,7 +80,7 @@ easy2d::Button::Button(Node * normal, Node * selected, const Callback& func)
this->SetCallbackOnClick(func); this->SetCallbackOnClick(func);
} }
easy2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Callback& func) Button::Button(Node * normal, Node * mouseover, Node * selected, const Callback& func)
: callback_(nullptr) : callback_(nullptr)
, status_(Status::Normal) , status_(Status::Normal)
, enabled_(true) , enabled_(true)
@ -94,7 +96,7 @@ easy2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const C
this->SetCallbackOnClick(func); this->SetCallbackOnClick(func);
} }
easy2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Callback& func) Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Callback& func)
: callback_(nullptr) : callback_(nullptr)
, status_(Status::Normal) , status_(Status::Normal)
, enabled_(true) , enabled_(true)
@ -111,12 +113,12 @@ easy2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node *
this->SetCallbackOnClick(func); this->SetCallbackOnClick(func);
} }
bool easy2d::Button::IsEnable() const bool Button::IsEnable() const
{ {
return enabled_; return enabled_;
} }
void easy2d::Button::SetNormal(Node * normal) void Button::SetNormal(Node * normal)
{ {
SET_BUTTON_NODE(normal_, normal); SET_BUTTON_NODE(normal_, normal);
if (normal) if (normal)
@ -125,22 +127,22 @@ void easy2d::Button::SetNormal(Node * normal)
} }
} }
void easy2d::Button::SetMouseOver(Node * mouseover) void Button::SetMouseOver(Node * mouseover)
{ {
SET_BUTTON_NODE(mouseover_, mouseover); SET_BUTTON_NODE(mouseover_, mouseover);
} }
void easy2d::Button::SetSelected(Node * selected) void Button::SetSelected(Node * selected)
{ {
SET_BUTTON_NODE(selected_, selected); SET_BUTTON_NODE(selected_, selected);
} }
void easy2d::Button::SetDisabled(Node * disabled) void Button::SetDisabled(Node * disabled)
{ {
SET_BUTTON_NODE(disabled_, disabled); SET_BUTTON_NODE(disabled_, disabled);
} }
void easy2d::Button::SetEnabled(bool enabled) void Button::SetEnabled(bool enabled)
{ {
if (enabled_ != enabled) if (enabled_ != enabled)
{ {
@ -149,12 +151,12 @@ void easy2d::Button::SetEnabled(bool enabled)
} }
} }
void easy2d::Button::SetCallbackOnClick(const Callback& func) void Button::SetCallbackOnClick(const Callback& func)
{ {
callback_ = func; callback_ = func;
} }
void easy2d::Button::SetPivot(float pivot_x, float pivot_y) void Button::SetPivot(float pivot_x, float pivot_y)
{ {
Node::SetPivot(pivot_x, pivot_y); Node::SetPivot(pivot_x, pivot_y);
SAFE_SET(normal_, SetPivot, pivot_x, pivot_y); SAFE_SET(normal_, SetPivot, pivot_x, pivot_y);
@ -163,7 +165,7 @@ void easy2d::Button::SetPivot(float pivot_x, float pivot_y)
SAFE_SET(disabled_, SetPivot, pivot_x, pivot_y); SAFE_SET(disabled_, SetPivot, pivot_x, pivot_y);
} }
bool easy2d::Button::Dispatch(const MouseEvent & e, bool handled) bool Button::Dispatch(const MouseEvent & e, bool handled)
{ {
if (!handled && enabled_ && IsVisible() && normal_) if (!handled && enabled_ && IsVisible() && normal_)
{ {
@ -212,7 +214,7 @@ bool easy2d::Button::Dispatch(const MouseEvent & e, bool handled)
return Node::Dispatch(e, handled); return Node::Dispatch(e, handled);
} }
void easy2d::Button::Visit() void Button::Visit()
{ {
Node::Visit(); Node::Visit();
@ -237,7 +239,7 @@ void easy2d::Button::Visit()
} }
} }
void easy2d::Button::SetStatus(Status status) void Button::SetStatus(Status status)
{ {
if (status_ != status) if (status_ != status)
{ {
@ -246,7 +248,7 @@ void easy2d::Button::SetStatus(Status status)
} }
} }
void easy2d::Button::UpdateVisible() void Button::UpdateVisible()
{ {
SAFE_SET(normal_, SetVisible, false); SAFE_SET(normal_, SetVisible, false);
SAFE_SET(mouseover_, SetVisible, false); SAFE_SET(mouseover_, SetVisible, false);
@ -280,3 +282,4 @@ void easy2d::Button::UpdateVisible()
} }
} }
} }
}

View File

@ -20,12 +20,15 @@
#include "..\e2dcomponent.h" #include "..\e2dcomponent.h"
easy2d::Menu::Menu()
namespace easy2d
{
Menu::Menu()
: enabled_(true) : enabled_(true)
{ {
} }
easy2d::Menu::Menu(const std::vector<Button*>& buttons) Menu::Menu(const std::vector<Button*>& buttons)
: enabled_(true) : enabled_(true)
{ {
for (const auto& button : buttons) for (const auto& button : buttons)
@ -34,17 +37,17 @@ easy2d::Menu::Menu(const std::vector<Button*>& buttons)
} }
} }
bool easy2d::Menu::IsEnable() const bool Menu::IsEnable() const
{ {
return enabled_; return enabled_;
} }
size_t easy2d::Menu::GetButtonCount() const size_t Menu::GetButtonCount() const
{ {
return buttons_.size(); return buttons_.size();
} }
void easy2d::Menu::SetEnabled(bool enabled) void Menu::SetEnabled(bool enabled)
{ {
if (enabled_ != enabled) if (enabled_ != enabled)
{ {
@ -57,7 +60,7 @@ void easy2d::Menu::SetEnabled(bool enabled)
} }
} }
void easy2d::Menu::AddButton(Button * button) void Menu::AddButton(Button * button)
{ {
if (button) if (button)
{ {
@ -67,7 +70,7 @@ void easy2d::Menu::AddButton(Button * button)
} }
} }
bool easy2d::Menu::RemoveButton(Button * button) bool Menu::RemoveButton(Button * button)
{ {
if (buttons_.empty()) if (buttons_.empty())
{ {
@ -90,7 +93,8 @@ bool easy2d::Menu::RemoveButton(Button * button)
return false; return false;
} }
const std::vector<easy2d::Button*>& easy2d::Menu::GetAllButtons() const const std::vector<Button*>& Menu::GetAllButtons() const
{ {
return buttons_; return buttons_;
} }
}

View File

@ -61,7 +61,7 @@ namespace easy2d
Point operator - () const; Point operator - () const;
bool operator== (const Point& other) const; bool operator== (const Point& other) const;
explicit operator easy2d::Size() const; explicit operator Size() const;
// 判断两点间距离 // 判断两点间距离
static float Distance( static float Distance(
@ -102,7 +102,7 @@ namespace easy2d
Size operator - () const; Size operator - () const;
bool operator== (const Size& other) const; bool operator== (const Size& other) const;
explicit operator easy2d::Point() const; explicit operator Point() const;
}; };
@ -585,19 +585,19 @@ namespace easy2d
template<typename T> template<typename T>
static inline T Range(T min, T max) static inline T Range(T min, T max)
{ {
return easy2d::Random::RandomInt(min, max); return Random::RandomInt(min, max);
} }
// 取得范围内的一个浮点数随机数 // 取得范围内的一个浮点数随机数
static inline float Range(float min, float max) static inline float Range(float min, float max)
{ {
return easy2d::Random::RandomReal(min, max); return Random::RandomReal(min, max);
} }
// 取得范围内的一个浮点数随机数 // 取得范围内的一个浮点数随机数
static inline double Range(double min, double max) static inline double Range(double min, double max)
{ {
return easy2d::Random::RandomReal(min, max); return Random::RandomReal(min, max);
} }
private: private:

View File

@ -21,14 +21,16 @@
#include "..\e2devent.h" #include "..\e2devent.h"
easy2d::KeyEvent::KeyEvent(UINT message, WPARAM w_param, LPARAM l_param) namespace easy2d
{
KeyEvent::KeyEvent(UINT message, WPARAM w_param, LPARAM l_param)
: message_(message) : message_(message)
, w_param_(w_param) , w_param_(w_param)
, l_param_(l_param) , l_param_(l_param)
{ {
} }
easy2d::KeyCode easy2d::KeyEvent::GetCode() const KeyCode KeyEvent::GetCode() const
{ {
switch (w_param_) switch (w_param_)
{ {
@ -89,12 +91,13 @@ easy2d::KeyCode easy2d::KeyEvent::GetCode() const
} }
} }
int easy2d::KeyEvent::GetCount() const int KeyEvent::GetCount() const
{ {
return static_cast<int>((DWORD)l_param_ & 0x0000FFFF); return static_cast<int>((DWORD)l_param_ & 0x0000FFFF);
} }
easy2d::KeyEvent::Type easy2d::KeyEvent::GetType() const KeyEvent::Type KeyEvent::GetType() const
{ {
return Type(message_); return Type(message_);
} }
}

View File

@ -21,26 +21,28 @@
#include "..\e2devent.h" #include "..\e2devent.h"
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
easy2d::MouseEvent::MouseEvent(UINT message, WPARAM w_param, LPARAM l_param) namespace easy2d
{
MouseEvent::MouseEvent(UINT message, WPARAM w_param, LPARAM l_param)
: message_(message) : message_(message)
, w_param_(w_param) , w_param_(w_param)
, l_param_(l_param) , l_param_(l_param)
{ {
} }
float easy2d::MouseEvent::GetX() const float MouseEvent::GetX() const
{ {
float dpi = Graphics::GetDpi(); float dpi = Graphics::GetDpi();
return ((float)(short)LOWORD(l_param_)) * 96.f / dpi; return ((float)(short)LOWORD(l_param_)) * 96.f / dpi;
} }
float easy2d::MouseEvent::GetY() const float MouseEvent::GetY() const
{ {
float dpi = Graphics::GetDpi(); float dpi = Graphics::GetDpi();
return ((float)(short)HIWORD(l_param_)) * 96.f / dpi; return ((float)(short)HIWORD(l_param_)) * 96.f / dpi;
} }
easy2d::Point easy2d::MouseEvent::GetPosition() const Point MouseEvent::GetPosition() const
{ {
float dpi = Graphics::GetDpi(); float dpi = Graphics::GetDpi();
return Point( return Point(
@ -49,37 +51,38 @@ easy2d::Point easy2d::MouseEvent::GetPosition() const
); );
} }
bool easy2d::MouseEvent::IsShiftDown() const bool MouseEvent::IsShiftDown() const
{ {
return GET_KEYSTATE_WPARAM(w_param_) == MK_SHIFT; return GET_KEYSTATE_WPARAM(w_param_) == MK_SHIFT;
} }
bool easy2d::MouseEvent::IsCtrlDown() const bool MouseEvent::IsCtrlDown() const
{ {
return GET_KEYSTATE_WPARAM(w_param_) == MK_CONTROL; return GET_KEYSTATE_WPARAM(w_param_) == MK_CONTROL;
} }
float easy2d::MouseEvent::GetWheelDelta() const float MouseEvent::GetWheelDelta() const
{ {
return static_cast<float>(GET_WHEEL_DELTA_WPARAM(w_param_)); return static_cast<float>(GET_WHEEL_DELTA_WPARAM(w_param_));
} }
bool easy2d::MouseEvent::IsLButtonDown() const bool MouseEvent::IsLButtonDown() const
{ {
return GET_KEYSTATE_WPARAM(w_param_) == MK_LBUTTON; return GET_KEYSTATE_WPARAM(w_param_) == MK_LBUTTON;
} }
bool easy2d::MouseEvent::IsRButtonDown() const bool MouseEvent::IsRButtonDown() const
{ {
return GET_KEYSTATE_WPARAM(w_param_) == MK_RBUTTON; return GET_KEYSTATE_WPARAM(w_param_) == MK_RBUTTON;
} }
bool easy2d::MouseEvent::IsMButtonDown() const bool MouseEvent::IsMButtonDown() const
{ {
return GET_KEYSTATE_WPARAM(w_param_) == MK_MBUTTON; return GET_KEYSTATE_WPARAM(w_param_) == MK_MBUTTON;
} }
easy2d::MouseEvent::Type easy2d::MouseEvent::GetType() const MouseEvent::Type MouseEvent::GetType() const
{ {
return Type(message_); return Type(message_);
} }
}

View File

@ -21,7 +21,9 @@
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
easy2d::Audio::Audio() namespace easy2d
{
Audio::Audio()
: x_audio2_(nullptr) : x_audio2_(nullptr)
, mastering_voice_(nullptr) , mastering_voice_(nullptr)
{ {
@ -38,7 +40,7 @@ easy2d::Audio::Audio()
); );
} }
easy2d::Audio::~Audio() Audio::~Audio()
{ {
if (mastering_voice_) if (mastering_voice_)
{ {
@ -51,17 +53,18 @@ easy2d::Audio::~Audio()
MFShutdown(); MFShutdown();
} }
HRESULT easy2d::Audio::CreateVoice(IXAudio2SourceVoice ** voice, WAVEFORMATEX * wfx) HRESULT Audio::CreateVoice(IXAudio2SourceVoice ** voice, WAVEFORMATEX * wfx)
{ {
return x_audio2_->CreateSourceVoice(voice, wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO); return x_audio2_->CreateSourceVoice(voice, wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO);
} }
void easy2d::Audio::Open() void Audio::Open()
{ {
x_audio2_->StartEngine(); x_audio2_->StartEngine();
} }
void easy2d::Audio::Close() void Audio::Close()
{ {
x_audio2_->StopEngine(); x_audio2_->StopEngine();
} }
}

View File

@ -20,33 +20,39 @@
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
static easy2d::Graphics * graphics_device = nullptr;
static easy2d::Input * input_device = nullptr;
static easy2d::Audio * audio_device = nullptr;
easy2d::Graphics * easy2d::Device::GetGraphics() namespace easy2d
{
namespace
{
Graphics * graphics_device = nullptr;
Input * input_device = nullptr;
Audio * audio_device = nullptr;
}
Graphics * Device::GetGraphics()
{ {
return graphics_device; return graphics_device;
} }
easy2d::Input * easy2d::Device::GetInput() Input * Device::GetInput()
{ {
return input_device; return input_device;
} }
easy2d::Audio * easy2d::Device::GetAudio() Audio * Device::GetAudio()
{ {
return audio_device; return audio_device;
} }
void easy2d::Device::Init(HWND hwnd) void Device::Init(HWND hwnd)
{ {
graphics_device = new (std::nothrow) Graphics(hwnd); graphics_device = new (std::nothrow) Graphics(hwnd);
input_device = new (std::nothrow) Input(hwnd); input_device = new (std::nothrow) Input(hwnd);
audio_device = new (std::nothrow) Audio(); audio_device = new (std::nothrow) Audio();
} }
void easy2d::Device::Destroy() void Device::Destroy()
{ {
if (audio_device) if (audio_device)
{ {
@ -66,3 +72,4 @@ void easy2d::Device::Destroy()
graphics_device = nullptr; graphics_device = nullptr;
} }
} }
}

View File

@ -30,14 +30,19 @@
#define REGISTER_CLASS L"Easy2DApp" #define REGISTER_CLASS L"Easy2DApp"
static easy2d::Game * instance = nullptr; namespace easy2d
{
namespace
{
Game * instance = nullptr;
}
easy2d::Game * easy2d::Game::GetInstance() Game * Game::GetInstance()
{ {
return instance; return instance;
} }
easy2d::Game::Game() Game::Game()
: hwnd_(nullptr) : hwnd_(nullptr)
, quit_(true) , quit_(true)
, curr_scene_(nullptr) , curr_scene_(nullptr)
@ -58,7 +63,7 @@ easy2d::Game::Game()
::CoInitialize(nullptr); ::CoInitialize(nullptr);
} }
easy2d::Game::~Game() Game::~Game()
{ {
SafeRelease(transition_); SafeRelease(transition_);
SafeRelease(curr_scene_); SafeRelease(curr_scene_);
@ -78,7 +83,7 @@ easy2d::Game::~Game()
::CoUninitialize(); ::CoUninitialize();
} }
void easy2d::Game::Run() void Game::Run()
{ {
// ³õʼ»¯ // ³õʼ»¯
Init(); Init();
@ -136,12 +141,12 @@ void easy2d::Game::Run()
} }
} }
void easy2d::Game::Quit() void Game::Quit()
{ {
quit_ = true; quit_ = true;
} }
void easy2d::Game::EnterScene(Scene * scene, Transition * transition) void Game::EnterScene(Scene * scene, Transition * transition)
{ {
if (scene == nullptr) if (scene == nullptr)
{ {
@ -172,17 +177,17 @@ void easy2d::Game::EnterScene(Scene * scene, Transition * transition)
} }
} }
easy2d::Scene * easy2d::Game::GetCurrentScene() Scene * Game::GetCurrentScene()
{ {
return curr_scene_; return curr_scene_;
} }
bool easy2d::Game::IsTransitioning() const bool Game::IsTransitioning() const
{ {
return transition_ != nullptr; return transition_ != nullptr;
} }
void easy2d::Game::UpdateScene(float dt) void Game::UpdateScene(float dt)
{ {
auto update = [&](Scene * scene) -> void auto update = [&](Scene * scene) -> void
{ {
@ -230,7 +235,7 @@ void easy2d::Game::UpdateScene(float dt)
} }
} }
void easy2d::Game::DrawScene() void Game::DrawScene()
{ {
auto graphics = Device::GetGraphics(); auto graphics = Device::GetGraphics();
graphics->BeginDraw(); graphics->BeginDraw();
@ -264,7 +269,7 @@ void easy2d::Game::DrawScene()
graphics->EndDraw(); graphics->EndDraw();
} }
void easy2d::Game::Init() void Game::Init()
{ {
HINSTANCE hinstance = GetModuleHandle(nullptr); HINSTANCE hinstance = GetModuleHandle(nullptr);
WNDCLASSEX wcex = { 0 }; WNDCLASSEX wcex = { 0 };
@ -370,7 +375,7 @@ void easy2d::Game::Init()
quit_ = false; quit_ = false;
} }
easy2d::Rect easy2d::Game::Locate(int width, int height) Rect Game::Locate(int width, int height)
{ {
int max_width = ::GetSystemMetrics(SM_CXSCREEN); int max_width = ::GetSystemMetrics(SM_CXSCREEN);
int max_height = ::GetSystemMetrics(SM_CYSCREEN); int max_height = ::GetSystemMetrics(SM_CYSCREEN);
@ -396,35 +401,35 @@ easy2d::Rect easy2d::Game::Locate(int width, int height)
); );
} }
int easy2d::Game::GetWidth() const int Game::GetWidth() const
{ {
return width_; return width_;
} }
int easy2d::Game::GetHeight() const int Game::GetHeight() const
{ {
return height_; return height_;
} }
easy2d::Size easy2d::Game::GetSize() const Size Game::GetSize() const
{ {
return easy2d::Size( return Size(
static_cast<float>(width_), static_cast<float>(width_),
static_cast<float>(height_) static_cast<float>(height_)
); );
} }
HWND easy2d::Game::GetHWnd() const HWND Game::GetHWnd() const
{ {
return hwnd_; return hwnd_;
} }
const std::wstring& easy2d::Game::GetTitle() const const std::wstring& Game::GetTitle() const
{ {
return title_; return title_;
} }
void easy2d::Game::SetSize(int width, int height) void Game::SetSize(int width, int height)
{ {
if (width_ == width && height_ == height) if (width_ == width && height_ == height)
return; return;
@ -446,7 +451,7 @@ void easy2d::Game::SetSize(int width, int height)
} }
} }
void easy2d::Game::SetTitle(const std::wstring& title) void Game::SetTitle(const std::wstring& title)
{ {
title_ = title; title_ = title;
@ -456,7 +461,7 @@ void easy2d::Game::SetTitle(const std::wstring& title)
} }
} }
void easy2d::Game::SetIcon(int resource_id) void Game::SetIcon(int resource_id)
{ {
icon_ = resource_id; icon_ = resource_id;
@ -477,13 +482,13 @@ void easy2d::Game::SetIcon(int resource_id)
} }
} }
void easy2d::Game::SetDebugMode(bool enabled) void Game::SetDebugMode(bool enabled)
{ {
debug_mode_ = enabled; debug_mode_ = enabled;
} }
LRESULT easy2d::Game::WndProc(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param) LRESULT Game::WndProc(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param)
{ {
LRESULT result = 0; LRESULT result = 0;
bool was_handled = false; bool was_handled = false;
@ -617,3 +622,4 @@ LRESULT easy2d::Game::WndProc(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_para
} }
return result; return result;
} }
}

View File

@ -24,7 +24,10 @@
namespace easy2d namespace easy2d
{ {
// ÎÄ×ÖäÖČžĆ÷ //-------------------------------------------------------
// TextRenderer
//-------------------------------------------------------
class TextRenderer class TextRenderer
: public IDWriteTextRenderer : public IDWriteTextRenderer
{ {
@ -505,10 +508,13 @@ namespace easy2d
return S_OK; return S_OK;
} }
}
easy2d::Graphics::Graphics(HWND hwnd) //-------------------------------------------------------
// Graphics
//-------------------------------------------------------
Graphics::Graphics(HWND hwnd)
: factory_(nullptr) : factory_(nullptr)
, imaging_factory_(nullptr) , imaging_factory_(nullptr)
, write_factory_(nullptr) , write_factory_(nullptr)
@ -587,7 +593,7 @@ easy2d::Graphics::Graphics(HWND hwnd)
); );
} }
easy2d::Graphics::~Graphics() Graphics::~Graphics()
{ {
SafeRelease(fps_text_format_); SafeRelease(fps_text_format_);
SafeRelease(fps_text_layout_); SafeRelease(fps_text_layout_);
@ -603,13 +609,13 @@ easy2d::Graphics::~Graphics()
SafeRelease(write_factory_); SafeRelease(write_factory_);
} }
void easy2d::Graphics::BeginDraw() void Graphics::BeginDraw()
{ {
render_target_->BeginDraw(); render_target_->BeginDraw();
render_target_->Clear(clear_color_); render_target_->Clear(clear_color_);
} }
void easy2d::Graphics::EndDraw() void Graphics::EndDraw()
{ {
HRESULT hr = render_target_->EndDraw(); HRESULT hr = render_target_->EndDraw();
@ -629,7 +635,7 @@ void easy2d::Graphics::EndDraw()
ThrowIfFailed(hr); ThrowIfFailed(hr);
} }
void easy2d::Graphics::DrawDebugInfo() void Graphics::DrawDebugInfo()
{ {
static int render_times_ = 0; static int render_times_ = 0;
static Time last_render_time_ = Time::Now(); static Time last_render_time_ = Time::Now();
@ -701,37 +707,37 @@ void easy2d::Graphics::DrawDebugInfo()
} }
} }
ID2D1HwndRenderTarget * easy2d::Graphics::GetRenderTarget() const ID2D1HwndRenderTarget * Graphics::GetRenderTarget() const
{ {
return render_target_; return render_target_;
} }
ID2D1SolidColorBrush * easy2d::Graphics::GetSolidBrush() const ID2D1SolidColorBrush * Graphics::GetSolidBrush() const
{ {
return solid_brush_; return solid_brush_;
} }
IDWriteTextRenderer* easy2d::Graphics::GetTextRender() const IDWriteTextRenderer* Graphics::GetTextRender() const
{ {
return text_renderer_; return text_renderer_;
} }
ID2D1Factory * easy2d::Graphics::GetFactory() const ID2D1Factory * Graphics::GetFactory() const
{ {
return factory_; return factory_;
} }
IWICImagingFactory * easy2d::Graphics::GetImagingFactory() const IWICImagingFactory * Graphics::GetImagingFactory() const
{ {
return imaging_factory_; return imaging_factory_;
} }
IDWriteFactory * easy2d::Graphics::GetWriteFactory() const IDWriteFactory * Graphics::GetWriteFactory() const
{ {
return write_factory_; return write_factory_;
} }
ID2D1StrokeStyle * easy2d::Graphics::GetMiterStrokeStyle() ID2D1StrokeStyle * Graphics::GetMiterStrokeStyle()
{ {
if (!miter_stroke_style_) if (!miter_stroke_style_)
{ {
@ -754,7 +760,7 @@ ID2D1StrokeStyle * easy2d::Graphics::GetMiterStrokeStyle()
return miter_stroke_style_; return miter_stroke_style_;
} }
ID2D1StrokeStyle * easy2d::Graphics::GetBevelStrokeStyle() ID2D1StrokeStyle * Graphics::GetBevelStrokeStyle()
{ {
if (!bevel_stroke_style_) if (!bevel_stroke_style_)
{ {
@ -777,7 +783,7 @@ ID2D1StrokeStyle * easy2d::Graphics::GetBevelStrokeStyle()
return bevel_stroke_style_; return bevel_stroke_style_;
} }
ID2D1StrokeStyle * easy2d::Graphics::GetRoundStrokeStyle() ID2D1StrokeStyle * Graphics::GetRoundStrokeStyle()
{ {
if (!round_stroke_style_) if (!round_stroke_style_)
{ {
@ -800,7 +806,7 @@ ID2D1StrokeStyle * easy2d::Graphics::GetRoundStrokeStyle()
return round_stroke_style_; return round_stroke_style_;
} }
void easy2d::Graphics::SetTextRendererStyle(const Color & fill_color, bool has_outline, const Color & outline_color, float outline_width, Stroke outline_stroke) void Graphics::SetTextRendererStyle(const Color & fill_color, bool has_outline, const Color & outline_color, float outline_width, Stroke outline_stroke)
{ {
static_cast<TextRenderer*>(text_renderer_)->SetTextStyle( static_cast<TextRenderer*>(text_renderer_)->SetTextStyle(
D2D1_COLOR_F(fill_color), D2D1_COLOR_F(fill_color),
@ -811,7 +817,7 @@ void easy2d::Graphics::SetTextRendererStyle(const Color & fill_color, bool has_o
); );
} }
float easy2d::Graphics::GetDpi() float Graphics::GetDpi()
{ {
static float dpi = -1; static float dpi = -1;
if (dpi < 0) if (dpi < 0)
@ -822,3 +828,4 @@ float easy2d::Graphics::GetDpi()
} }
return dpi; return dpi;
} }
}

View File

@ -22,7 +22,9 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
easy2d::Input::Input(HWND hwnd) namespace easy2d
{
Input::Input(HWND hwnd)
: direct_input_(nullptr) : direct_input_(nullptr)
, keyboard_device_(nullptr) , keyboard_device_(nullptr)
, mouse_device_(nullptr) , mouse_device_(nullptr)
@ -72,7 +74,7 @@ easy2d::Input::Input(HWND hwnd)
mouse_device_->Poll(); mouse_device_->Poll();
} }
easy2d::Input::~Input() Input::~Input()
{ {
if (keyboard_device_) if (keyboard_device_)
keyboard_device_->Unacquire(); keyboard_device_->Unacquire();
@ -84,7 +86,7 @@ easy2d::Input::~Input()
SafeRelease(direct_input_); SafeRelease(direct_input_);
} }
void easy2d::Input::Flush() void Input::Flush()
{ {
if (keyboard_device_) if (keyboard_device_)
{ {
@ -123,31 +125,31 @@ void easy2d::Input::Flush()
} }
} }
bool easy2d::Input::IsDown(KeyCode key) bool Input::IsDown(KeyCode key)
{ {
if (key_buffer_[static_cast<int>(key)] & 0x80) if (key_buffer_[static_cast<int>(key)] & 0x80)
return true; return true;
return false; return false;
} }
bool easy2d::Input::IsDown(MouseCode code) bool Input::IsDown(MouseCode code)
{ {
if (mouse_state_.rgbButtons[static_cast<int>(code)] & 0x80) if (mouse_state_.rgbButtons[static_cast<int>(code)] & 0x80)
return true; return true;
return false; return false;
} }
float easy2d::Input::GetMouseX() float Input::GetMouseX()
{ {
return GetMousePos().x; return GetMousePos().x;
} }
float easy2d::Input::GetMouseY() float Input::GetMouseY()
{ {
return GetMousePos().y; return GetMousePos().y;
} }
easy2d::Point easy2d::Input::GetMousePos() Point Input::GetMousePos()
{ {
POINT mousePos; POINT mousePos;
::GetCursorPos(&mousePos); ::GetCursorPos(&mousePos);
@ -156,17 +158,18 @@ easy2d::Point easy2d::Input::GetMousePos()
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 easy2d::Input::GetMouseDeltaX() float Input::GetMouseDeltaX()
{ {
return (float)mouse_state_.lX; return (float)mouse_state_.lX;
} }
float easy2d::Input::GetMouseDeltaY() float Input::GetMouseDeltaY()
{ {
return (float)mouse_state_.lY; return (float)mouse_state_.lY;
} }
float easy2d::Input::GetMouseDeltaZ() float Input::GetMouseDeltaZ()
{ {
return (float)mouse_state_.lZ; return (float)mouse_state_.lZ;
} }
}

View File

@ -21,7 +21,9 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
easy2d::Canvas::Canvas(float width, float height) namespace easy2d
{
Canvas::Canvas(float width, float height)
: render_target_(nullptr) : render_target_(nullptr)
, fill_brush_(nullptr) , fill_brush_(nullptr)
, line_brush_(nullptr) , line_brush_(nullptr)
@ -52,65 +54,65 @@ easy2d::Canvas::Canvas(float width, float height)
this->SetStrokeStyle(stroke_); this->SetStrokeStyle(stroke_);
} }
easy2d::Canvas::~Canvas() Canvas::~Canvas()
{ {
SafeRelease(line_brush_); SafeRelease(line_brush_);
SafeRelease(fill_brush_); SafeRelease(fill_brush_);
SafeRelease(render_target_); SafeRelease(render_target_);
} }
void easy2d::Canvas::SetLineColor(const Color & color) void Canvas::SetLineColor(const Color & color)
{ {
line_brush_->SetColor(D2D_COLOR_F(color)); line_brush_->SetColor(D2D_COLOR_F(color));
} }
void easy2d::Canvas::SetFillColor(const Color & color) void Canvas::SetFillColor(const Color & color)
{ {
fill_brush_->SetColor(D2D_COLOR_F(color)); fill_brush_->SetColor(D2D_COLOR_F(color));
} }
void easy2d::Canvas::SetStrokeWidth(float width) void Canvas::SetStrokeWidth(float width)
{ {
stroke_width_ = std::max(width, 0.f); stroke_width_ = std::max(width, 0.f);
} }
void easy2d::Canvas::SetStrokeStyle(Stroke strokeStyle) void Canvas::SetStrokeStyle(Stroke strokeStyle)
{ {
switch (strokeStyle) switch (strokeStyle)
{ {
case easy2d::Stroke::Miter: case Stroke::Miter:
stroke_style_ = Device::GetGraphics()->GetMiterStrokeStyle(); stroke_style_ = Device::GetGraphics()->GetMiterStrokeStyle();
break; break;
case easy2d::Stroke::Bevel: case Stroke::Bevel:
stroke_style_ = Device::GetGraphics()->GetBevelStrokeStyle(); stroke_style_ = Device::GetGraphics()->GetBevelStrokeStyle();
break; break;
case easy2d::Stroke::Round: case Stroke::Round:
stroke_style_ = Device::GetGraphics()->GetRoundStrokeStyle(); stroke_style_ = Device::GetGraphics()->GetRoundStrokeStyle();
break; break;
} }
} }
easy2d::Color easy2d::Canvas::GetLineColor() const Color Canvas::GetLineColor() const
{ {
return line_brush_->GetColor(); return line_brush_->GetColor();
} }
easy2d::Color easy2d::Canvas::GetFillColor() const Color Canvas::GetFillColor() const
{ {
return fill_brush_->GetColor(); return fill_brush_->GetColor();
} }
float easy2d::Canvas::GetStrokeWidth() const float Canvas::GetStrokeWidth() const
{ {
return stroke_width_; return stroke_width_;
} }
easy2d::Stroke easy2d::Canvas::GetStrokeStyle() const Stroke Canvas::GetStrokeStyle() const
{ {
return stroke_; return stroke_;
} }
void easy2d::Canvas::DrawLine(const Point & begin, const Point & end) void Canvas::DrawLine(const Point & begin, const Point & end)
{ {
render_target_->DrawLine( render_target_->DrawLine(
D2D1::Point2F(begin.x, begin.y), D2D1::Point2F(begin.x, begin.y),
@ -121,7 +123,7 @@ void easy2d::Canvas::DrawLine(const Point & begin, const Point & end)
); );
} }
void easy2d::Canvas::DrawCircle(const Point & center, float radius) void Canvas::DrawCircle(const Point & center, float radius)
{ {
render_target_->DrawEllipse( render_target_->DrawEllipse(
D2D1::Ellipse( D2D1::Ellipse(
@ -138,7 +140,7 @@ void easy2d::Canvas::DrawCircle(const Point & center, float radius)
); );
} }
void easy2d::Canvas::DrawEllipse(const Point & center, float radius_x, float radius_y) void Canvas::DrawEllipse(const Point & center, float radius_x, float radius_y)
{ {
render_target_->DrawEllipse( render_target_->DrawEllipse(
D2D1::Ellipse( D2D1::Ellipse(
@ -155,7 +157,7 @@ void easy2d::Canvas::DrawEllipse(const Point & center, float radius_x, float rad
); );
} }
void easy2d::Canvas::DrawRect(const Rect & rect) void Canvas::DrawRect(const Rect & rect)
{ {
render_target_->DrawRectangle( render_target_->DrawRectangle(
D2D1::RectF( D2D1::RectF(
@ -170,7 +172,7 @@ void easy2d::Canvas::DrawRect(const Rect & rect)
); );
} }
void easy2d::Canvas::DrawRoundedRect(const Rect & rect, float radius_x, float radius_y) void Canvas::DrawRoundedRect(const Rect & rect, float radius_x, float radius_y)
{ {
render_target_->DrawRoundedRectangle( render_target_->DrawRoundedRectangle(
D2D1::RoundedRect( D2D1::RoundedRect(
@ -189,7 +191,7 @@ void easy2d::Canvas::DrawRoundedRect(const Rect & rect, float radius_x, float ra
); );
} }
void easy2d::Canvas::FillCircle(const Point & center, float radius) void Canvas::FillCircle(const Point & center, float radius)
{ {
render_target_->FillEllipse( render_target_->FillEllipse(
D2D1::Ellipse( D2D1::Ellipse(
@ -204,7 +206,7 @@ void easy2d::Canvas::FillCircle(const Point & center, float radius)
); );
} }
void easy2d::Canvas::FillEllipse(const Point & center, float radius_x, float radius_y) void Canvas::FillEllipse(const Point & center, float radius_x, float radius_y)
{ {
render_target_->FillEllipse( render_target_->FillEllipse(
D2D1::Ellipse( D2D1::Ellipse(
@ -219,7 +221,7 @@ void easy2d::Canvas::FillEllipse(const Point & center, float radius_x, float rad
); );
} }
void easy2d::Canvas::FillRect(const Rect & rect) void Canvas::FillRect(const Rect & rect)
{ {
render_target_->FillRectangle( render_target_->FillRectangle(
D2D1::RectF( D2D1::RectF(
@ -232,7 +234,7 @@ void easy2d::Canvas::FillRect(const Rect & rect)
); );
} }
void easy2d::Canvas::FillRoundedRect(const Rect & rect, float radius_x, float radius_y) void Canvas::FillRoundedRect(const Rect & rect, float radius_x, float radius_y)
{ {
render_target_->FillRoundedRectangle( render_target_->FillRoundedRectangle(
D2D1::RoundedRect( D2D1::RoundedRect(
@ -248,3 +250,4 @@ void easy2d::Canvas::FillRoundedRect(const Rect & rect, float radius_x, float ra
fill_brush_ fill_brush_
); );
} }
}

View File

@ -22,22 +22,24 @@
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
#include "..\e2dtool.h" #include "..\e2dtool.h"
std::map<size_t, ID2D1Bitmap*> easy2d::Image::bitmap_cache_; namespace easy2d
{
std::map<size_t, ID2D1Bitmap*> Image::bitmap_cache_;
easy2d::Image::Image() Image::Image()
: bitmap_(nullptr) : bitmap_(nullptr)
, crop_rect_() , crop_rect_()
{ {
} }
easy2d::Image::Image(Resource& res) Image::Image(Resource& res)
: bitmap_(nullptr) : bitmap_(nullptr)
, crop_rect_() , crop_rect_()
{ {
this->Load(res); this->Load(res);
} }
easy2d::Image::Image(Resource& res, const Rect& crop_rect) Image::Image(Resource& res, const Rect& crop_rect)
: bitmap_(nullptr) : bitmap_(nullptr)
, crop_rect_() , crop_rect_()
{ {
@ -45,14 +47,14 @@ easy2d::Image::Image(Resource& res, const Rect& crop_rect)
this->Crop(crop_rect); this->Crop(crop_rect);
} }
easy2d::Image::Image(const std::wstring & file_name) Image::Image(const std::wstring & file_name)
: bitmap_(nullptr) : bitmap_(nullptr)
, crop_rect_() , crop_rect_()
{ {
this->Load(file_name); this->Load(file_name);
} }
easy2d::Image::Image(const std::wstring & file_name, const Rect & crop_rect) Image::Image(const std::wstring & file_name, const Rect & crop_rect)
: bitmap_(nullptr) : bitmap_(nullptr)
, crop_rect_() , crop_rect_()
{ {
@ -60,12 +62,12 @@ easy2d::Image::Image(const std::wstring & file_name, const Rect & crop_rect)
this->Crop(crop_rect); this->Crop(crop_rect);
} }
easy2d::Image::~Image() Image::~Image()
{ {
SafeRelease(bitmap_); SafeRelease(bitmap_);
} }
bool easy2d::Image::Load(Resource& res) bool Image::Load(Resource& res)
{ {
if (!Image::CacheBitmap(res)) if (!Image::CacheBitmap(res))
{ {
@ -77,7 +79,7 @@ bool easy2d::Image::Load(Resource& res)
return true; return true;
} }
bool easy2d::Image::Load(const std::wstring & file_name) bool Image::Load(const std::wstring & file_name)
{ {
E2D_WARNING_IF(file_name.empty(), "Image Load failed! Invalid file name."); E2D_WARNING_IF(file_name.empty(), "Image Load failed! Invalid file name.");
@ -94,7 +96,7 @@ bool easy2d::Image::Load(const std::wstring & file_name)
return true; return true;
} }
void easy2d::Image::Crop(const Rect& crop_rect) void Image::Crop(const Rect& crop_rect)
{ {
if (bitmap_) if (bitmap_)
{ {
@ -106,22 +108,22 @@ void easy2d::Image::Crop(const Rect& crop_rect)
} }
} }
float easy2d::Image::GetWidth() const float Image::GetWidth() const
{ {
return crop_rect_.size.width; return crop_rect_.size.width;
} }
float easy2d::Image::GetHeight() const float Image::GetHeight() const
{ {
return crop_rect_.size.height; return crop_rect_.size.height;
} }
easy2d::Size easy2d::Image::GetSize() const Size Image::GetSize() const
{ {
return crop_rect_.size; return crop_rect_.size;
} }
float easy2d::Image::GetSourceWidth() const float Image::GetSourceWidth() const
{ {
if (bitmap_) if (bitmap_)
{ {
@ -133,7 +135,7 @@ float easy2d::Image::GetSourceWidth() const
} }
} }
float easy2d::Image::GetSourceHeight() const float Image::GetSourceHeight() const
{ {
if (bitmap_) if (bitmap_)
{ {
@ -145,7 +147,7 @@ float easy2d::Image::GetSourceHeight() const
} }
} }
easy2d::Size easy2d::Image::GetSourceSize() const Size Image::GetSourceSize() const
{ {
if (bitmap_) if (bitmap_)
{ {
@ -155,32 +157,32 @@ easy2d::Size easy2d::Image::GetSourceSize() const
return Size{}; return Size{};
} }
float easy2d::Image::GetCropX() const float Image::GetCropX() const
{ {
return crop_rect_.origin.x; return crop_rect_.origin.x;
} }
float easy2d::Image::GetCropY() const float Image::GetCropY() const
{ {
return crop_rect_.origin.y; return crop_rect_.origin.y;
} }
easy2d::Point easy2d::Image::GetCropPos() const Point Image::GetCropPos() const
{ {
return crop_rect_.origin; return crop_rect_.origin;
} }
const easy2d::Rect & easy2d::Image::GetCropRect() const const Rect & Image::GetCropRect() const
{ {
return crop_rect_; return crop_rect_;
} }
ID2D1Bitmap * easy2d::Image::GetBitmap() const ID2D1Bitmap * Image::GetBitmap() const
{ {
return bitmap_; return bitmap_;
} }
bool easy2d::Image::CacheBitmap(Resource& res) bool Image::CacheBitmap(Resource& res)
{ {
size_t hash_code = res.GetHashCode(); size_t hash_code = res.GetHashCode();
if (bitmap_cache_.find(hash_code) != bitmap_cache_.end()) if (bitmap_cache_.find(hash_code) != bitmap_cache_.end())
@ -277,7 +279,7 @@ bool easy2d::Image::CacheBitmap(Resource& res)
return SUCCEEDED(hr); return SUCCEEDED(hr);
} }
bool easy2d::Image::CacheBitmap(const std::wstring & file_name) bool Image::CacheBitmap(const std::wstring & file_name)
{ {
size_t hash_code = std::hash<std::wstring>{}(file_name); size_t hash_code = std::hash<std::wstring>{}(file_name);
if (bitmap_cache_.find(hash_code) != bitmap_cache_.end()) if (bitmap_cache_.find(hash_code) != bitmap_cache_.end())
@ -358,7 +360,7 @@ bool easy2d::Image::CacheBitmap(const std::wstring & file_name)
return SUCCEEDED(hr); return SUCCEEDED(hr);
} }
void easy2d::Image::ClearCache() void Image::ClearCache()
{ {
if (bitmap_cache_.empty()) if (bitmap_cache_.empty())
return; return;
@ -370,7 +372,7 @@ void easy2d::Image::ClearCache()
bitmap_cache_.clear(); bitmap_cache_.clear();
} }
void easy2d::Image::SetBitmap(ID2D1Bitmap * bitmap) void Image::SetBitmap(ID2D1Bitmap * bitmap)
{ {
if (bitmap_ == bitmap) if (bitmap_ == bitmap)
return; return;
@ -390,3 +392,4 @@ void easy2d::Image::SetBitmap(ID2D1Bitmap * bitmap)
crop_rect_.size.height = bitmap_->GetSize().height; crop_rect_.size.height = bitmap_->GetSize().height;
} }
} }
}

View File

@ -25,7 +25,9 @@
#include <iterator> #include <iterator>
easy2d::Node::Node() namespace easy2d
{
Node::Node()
: visible_(true) : visible_(true)
, parent_(nullptr) , parent_(nullptr)
, parent_scene_(nullptr) , parent_scene_(nullptr)
@ -47,7 +49,7 @@ easy2d::Node::Node()
{ {
} }
easy2d::Node::~Node() Node::~Node()
{ {
SafeRelease(border_); SafeRelease(border_);
@ -67,7 +69,7 @@ easy2d::Node::~Node()
} }
} }
void easy2d::Node::Visit() void Node::Visit()
{ {
if (!visible_) if (!visible_)
return; return;
@ -130,7 +132,7 @@ void easy2d::Node::Visit()
} }
} }
void easy2d::Node::UpdateChildren(float dt) void Node::UpdateChildren(float dt)
{ {
if (children_.empty()) if (children_.empty())
{ {
@ -167,7 +169,7 @@ void easy2d::Node::UpdateChildren(float dt)
} }
} }
void easy2d::Node::DrawBorder() void Node::DrawBorder()
{ {
if (visible_) if (visible_)
{ {
@ -190,7 +192,7 @@ void easy2d::Node::DrawBorder()
} }
} }
void easy2d::Node::UpdateTransform() void Node::UpdateTransform()
{ {
if (!dirty_transform_) if (!dirty_transform_)
return; return;
@ -247,7 +249,7 @@ void easy2d::Node::UpdateTransform()
} }
} }
bool easy2d::Node::Dispatch(const MouseEvent & e, bool handled) bool Node::Dispatch(const MouseEvent & e, bool handled)
{ {
if (visible_) if (visible_)
{ {
@ -262,7 +264,7 @@ bool easy2d::Node::Dispatch(const MouseEvent & e, bool handled)
return handled; return handled;
} }
bool easy2d::Node::Dispatch(const KeyEvent & e, bool handled) bool Node::Dispatch(const KeyEvent & e, bool handled)
{ {
if (visible_) if (visible_)
{ {
@ -277,7 +279,7 @@ bool easy2d::Node::Dispatch(const KeyEvent & e, bool handled)
return handled; return handled;
} }
void easy2d::Node::UpdateOpacity() void Node::UpdateOpacity()
{ {
if (parent_) if (parent_)
{ {
@ -289,7 +291,7 @@ void easy2d::Node::UpdateOpacity()
} }
} }
void easy2d::Node::UpdateActions() void Node::UpdateActions()
{ {
if (actions_.empty()) if (actions_.empty())
return; return;
@ -322,112 +324,112 @@ void easy2d::Node::UpdateActions()
} }
} }
bool easy2d::Node::IsVisible() const bool Node::IsVisible() const
{ {
return visible_; return visible_;
} }
const std::wstring& easy2d::Node::GetName() const const std::wstring& Node::GetName() const
{ {
return name_; return name_;
} }
size_t easy2d::Node::GetHashName() const size_t Node::GetHashName() const
{ {
return hash_name_; return hash_name_;
} }
const easy2d::Point& easy2d::Node::GetPosition() const const Point& Node::GetPosition() const
{ {
return transform_.position; return transform_.position;
} }
float easy2d::Node::GetWidth() const float Node::GetWidth() const
{ {
return transform_.size.width * transform_.scale_x; return transform_.size.width * transform_.scale_x;
} }
float easy2d::Node::GetHeight() const float Node::GetHeight() const
{ {
return transform_.size.height * transform_.scale_y; return transform_.size.height * transform_.scale_y;
} }
float easy2d::Node::GetRealWidth() const float Node::GetRealWidth() const
{ {
return transform_.size.width; return transform_.size.width;
} }
float easy2d::Node::GetRealHeight() const float Node::GetRealHeight() const
{ {
return transform_.size.height; return transform_.size.height;
} }
const easy2d::Size& easy2d::Node::GetRealSize() const const Size& Node::GetRealSize() const
{ {
return transform_.size; return transform_.size;
} }
float easy2d::Node::GetPivotX() const float Node::GetPivotX() const
{ {
return transform_.pivot_x; return transform_.pivot_x;
} }
float easy2d::Node::GetPivotY() const float Node::GetPivotY() const
{ {
return transform_.pivot_y; return transform_.pivot_y;
} }
easy2d::Size easy2d::Node::GetSize() const Size Node::GetSize() const
{ {
return Size{ GetWidth(), GetHeight() }; return Size{ GetWidth(), GetHeight() };
} }
float easy2d::Node::GetScaleX() const float Node::GetScaleX() const
{ {
return transform_.scale_x; return transform_.scale_x;
} }
float easy2d::Node::GetScaleY() const float Node::GetScaleY() const
{ {
return transform_.scale_y; return transform_.scale_y;
} }
float easy2d::Node::GetSkewX() const float Node::GetSkewX() const
{ {
return transform_.skew_x; return transform_.skew_x;
} }
float easy2d::Node::GetSkewY() const float Node::GetSkewY() const
{ {
return transform_.skew_y; return transform_.skew_y;
} }
float easy2d::Node::GetRotation() const float Node::GetRotation() const
{ {
return transform_.rotation; return transform_.rotation;
} }
const easy2d::Transform & easy2d::Node::GetTransform() const const Transform & Node::GetTransform() const
{ {
return transform_; return transform_;
} }
float easy2d::Node::GetOpacity() const float Node::GetOpacity() const
{ {
return real_opacity_; return real_opacity_;
} }
float easy2d::Node::GetDisplayOpacity() const float Node::GetDisplayOpacity() const
{ {
return display_opacity_; return display_opacity_;
} }
int easy2d::Node::GetOrder() const int Node::GetOrder() const
{ {
return order_; return order_;
} }
void easy2d::Node::SetOrder(int order) void Node::SetOrder(int order)
{ {
if (order_ == order) if (order_ == order)
return; return;
@ -439,22 +441,22 @@ void easy2d::Node::SetOrder(int order)
} }
} }
void easy2d::Node::SetPositionX(float x) void Node::SetPositionX(float x)
{ {
this->SetPosition(x, transform_.position.y); this->SetPosition(x, transform_.position.y);
} }
void easy2d::Node::SetPositionY(float y) void Node::SetPositionY(float y)
{ {
this->SetPosition(transform_.position.x, y); this->SetPosition(transform_.position.x, y);
} }
void easy2d::Node::SetPosition(const Point & p) void Node::SetPosition(const Point & p)
{ {
this->SetPosition(p.x, p.y); this->SetPosition(p.x, p.y);
} }
void easy2d::Node::SetPosition(float x, float y) void Node::SetPosition(float x, float y)
{ {
if (transform_.position.x == x && transform_.position.y == y) if (transform_.position.x == x && transform_.position.y == y)
return; return;
@ -464,32 +466,32 @@ void easy2d::Node::SetPosition(float x, float y)
dirty_transform_ = true; dirty_transform_ = true;
} }
void easy2d::Node::MoveBy(float x, float y) void Node::MoveBy(float x, float y)
{ {
this->SetPosition(transform_.position.x + x, transform_.position.y + y); this->SetPosition(transform_.position.x + x, transform_.position.y + y);
} }
void easy2d::Node::MoveBy(const Point & v) void Node::MoveBy(const Point & v)
{ {
this->MoveBy(v.x, v.y); this->MoveBy(v.x, v.y);
} }
void easy2d::Node::SetScaleX(float scale_x) void Node::SetScaleX(float scale_x)
{ {
this->SetScale(scale_x, transform_.scale_y); this->SetScale(scale_x, transform_.scale_y);
} }
void easy2d::Node::SetScaleY(float scale_y) void Node::SetScaleY(float scale_y)
{ {
this->SetScale(transform_.scale_x, scale_y); this->SetScale(transform_.scale_x, scale_y);
} }
void easy2d::Node::SetScale(float scale) void Node::SetScale(float scale)
{ {
this->SetScale(scale, scale); this->SetScale(scale, scale);
} }
void easy2d::Node::SetScale(float scale_x, float scale_y) void Node::SetScale(float scale_x, float scale_y)
{ {
if (transform_.scale_x == scale_x && transform_.scale_y == scale_y) if (transform_.scale_x == scale_x && transform_.scale_y == scale_y)
return; return;
@ -499,17 +501,17 @@ void easy2d::Node::SetScale(float scale_x, float scale_y)
dirty_transform_ = true; dirty_transform_ = true;
} }
void easy2d::Node::SetSkewX(float skew_x) void Node::SetSkewX(float skew_x)
{ {
this->SetSkew(skew_x, transform_.skew_y); this->SetSkew(skew_x, transform_.skew_y);
} }
void easy2d::Node::SetSkewY(float skew_y) void Node::SetSkewY(float skew_y)
{ {
this->SetSkew(transform_.skew_x, skew_y); this->SetSkew(transform_.skew_x, skew_y);
} }
void easy2d::Node::SetSkew(float skew_x, float skew_y) void Node::SetSkew(float skew_x, float skew_y)
{ {
if (transform_.skew_x == skew_x && transform_.skew_y == skew_y) if (transform_.skew_x == skew_x && transform_.skew_y == skew_y)
return; return;
@ -519,7 +521,7 @@ void easy2d::Node::SetSkew(float skew_x, float skew_y)
dirty_transform_ = true; dirty_transform_ = true;
} }
void easy2d::Node::SetRotation(float angle) void Node::SetRotation(float angle)
{ {
if (transform_.rotation == angle) if (transform_.rotation == angle)
return; return;
@ -528,7 +530,7 @@ void easy2d::Node::SetRotation(float angle)
dirty_transform_ = true; dirty_transform_ = true;
} }
void easy2d::Node::SetOpacity(float opacity) void Node::SetOpacity(float opacity)
{ {
if (real_opacity_ == opacity) if (real_opacity_ == opacity)
return; return;
@ -538,17 +540,17 @@ void easy2d::Node::SetOpacity(float opacity)
UpdateOpacity(); UpdateOpacity();
} }
void easy2d::Node::SetPivotX(float pivot_x) void Node::SetPivotX(float pivot_x)
{ {
this->SetPivot(pivot_x, transform_.pivot_y); this->SetPivot(pivot_x, transform_.pivot_y);
} }
void easy2d::Node::SetPivotY(float pivot_y) void Node::SetPivotY(float pivot_y)
{ {
this->SetPivot(transform_.pivot_x, pivot_y); this->SetPivot(transform_.pivot_x, pivot_y);
} }
void easy2d::Node::SetPivot(float pivot_x, float pivot_y) void Node::SetPivot(float pivot_x, float pivot_y)
{ {
if (transform_.pivot_x == pivot_x && transform_.pivot_y == pivot_y) if (transform_.pivot_x == pivot_x && transform_.pivot_y == pivot_y)
return; return;
@ -558,17 +560,17 @@ void easy2d::Node::SetPivot(float pivot_x, float pivot_y)
dirty_transform_ = true; dirty_transform_ = true;
} }
void easy2d::Node::SetWidth(float width) void Node::SetWidth(float width)
{ {
this->SetSize(width, transform_.size.height); this->SetSize(width, transform_.size.height);
} }
void easy2d::Node::SetHeight(float height) void Node::SetHeight(float height)
{ {
this->SetSize(transform_.size.width, height); this->SetSize(transform_.size.width, height);
} }
void easy2d::Node::SetSize(float width, float height) void Node::SetSize(float width, float height)
{ {
if (transform_.size.width == width && transform_.size.height == height) if (transform_.size.width == width && transform_.size.height == height)
return; return;
@ -578,28 +580,28 @@ void easy2d::Node::SetSize(float width, float height)
dirty_transform_ = true; dirty_transform_ = true;
} }
void easy2d::Node::SetSize(const Size& size) void Node::SetSize(const Size& size)
{ {
this->SetSize(size.width, size.height); this->SetSize(size.width, size.height);
} }
void easy2d::Node::SetTransform(const Transform & transform) void Node::SetTransform(const Transform & transform)
{ {
transform_ = transform; transform_ = transform;
dirty_transform_ = true; dirty_transform_ = true;
} }
void easy2d::Node::SetClipEnabled(bool enabled) void Node::SetClipEnabled(bool enabled)
{ {
clip_enabled_ = enabled; clip_enabled_ = enabled;
} }
void easy2d::Node::SetBorderColor(const Color & color) void Node::SetBorderColor(const Color & color)
{ {
border_color_ = color; border_color_ = color;
} }
void easy2d::Node::AddChild(Node * child, int order) void Node::AddChild(Node * child, int order)
{ {
E2D_WARNING_IF(child == nullptr, "Node::AddChild NULL pointer exception."); E2D_WARNING_IF(child == nullptr, "Node::AddChild NULL pointer exception.");
@ -636,7 +638,7 @@ void easy2d::Node::AddChild(Node * child, int order)
} }
} }
void easy2d::Node::AddChild(const Nodes& nodes, int order) void Node::AddChild(const Nodes& nodes, int order)
{ {
for (const auto& node : nodes) for (const auto& node : nodes)
{ {
@ -644,17 +646,17 @@ void easy2d::Node::AddChild(const Nodes& nodes, int order)
} }
} }
easy2d::Node * easy2d::Node::GetParent() const Node * Node::GetParent() const
{ {
return parent_; return parent_;
} }
easy2d::Scene * easy2d::Node::GetParentScene() const Scene * Node::GetParentScene() const
{ {
return parent_scene_; return parent_scene_;
} }
easy2d::Node::Nodes easy2d::Node::GetChildren(const std::wstring& name) const Node::Nodes Node::GetChildren(const std::wstring& name) const
{ {
Nodes children; Nodes children;
size_t hash_code = std::hash<std::wstring>{}(name); size_t hash_code = std::hash<std::wstring>{}(name);
@ -670,7 +672,7 @@ easy2d::Node::Nodes easy2d::Node::GetChildren(const std::wstring& name) const
return children; return children;
} }
easy2d::Node * easy2d::Node::GetChild(const std::wstring& name) const Node * Node::GetChild(const std::wstring& name) const
{ {
size_t hash_code = std::hash<std::wstring>{}(name); size_t hash_code = std::hash<std::wstring>{}(name);
@ -685,17 +687,17 @@ easy2d::Node * easy2d::Node::GetChild(const std::wstring& name) const
return nullptr; return nullptr;
} }
const std::vector<easy2d::Node*>& easy2d::Node::GetAllChildren() const const std::vector<Node*>& Node::GetAllChildren() const
{ {
return children_; return children_;
} }
int easy2d::Node::GetChildrenCount() const int Node::GetChildrenCount() const
{ {
return static_cast<int>(children_.size()); return static_cast<int>(children_.size());
} }
void easy2d::Node::RemoveFromParent() void Node::RemoveFromParent()
{ {
if (parent_) if (parent_)
{ {
@ -703,7 +705,7 @@ void easy2d::Node::RemoveFromParent()
} }
} }
bool easy2d::Node::RemoveChild(Node * child) bool Node::RemoveChild(Node * child)
{ {
E2D_WARNING_IF(child == nullptr, "Node::RemoveChildren NULL pointer exception."); E2D_WARNING_IF(child == nullptr, "Node::RemoveChildren NULL pointer exception.");
@ -732,7 +734,7 @@ bool easy2d::Node::RemoveChild(Node * child)
return false; return false;
} }
void easy2d::Node::RemoveChildren(const std::wstring& child_name) void Node::RemoveChildren(const std::wstring& child_name)
{ {
if (children_.empty()) if (children_.empty())
{ {
@ -759,7 +761,7 @@ void easy2d::Node::RemoveChildren(const std::wstring& child_name)
} }
} }
void easy2d::Node::RemoveAllChildren() void Node::RemoveAllChildren()
{ {
// 所有节点的引用计数减一 // 所有节点的引用计数减一
for (const auto& child : children_) for (const auto& child : children_)
@ -770,7 +772,7 @@ void easy2d::Node::RemoveAllChildren()
children_.clear(); children_.clear();
} }
void easy2d::Node::RunAction(Action * action) void Node::RunAction(Action * action)
{ {
E2D_WARNING_IF(action == nullptr, "Action NULL pointer exception!"); E2D_WARNING_IF(action == nullptr, "Action NULL pointer exception!");
@ -793,7 +795,7 @@ void easy2d::Node::RunAction(Action * action)
} }
} }
void easy2d::Node::ResumeAction(const std::wstring& name) void Node::ResumeAction(const std::wstring& name)
{ {
if (actions_.empty()) if (actions_.empty())
return; return;
@ -807,7 +809,7 @@ void easy2d::Node::ResumeAction(const std::wstring& name)
} }
} }
void easy2d::Node::PauseAction(const std::wstring& name) void Node::PauseAction(const std::wstring& name)
{ {
if (actions_.empty()) if (actions_.empty())
return; return;
@ -821,7 +823,7 @@ void easy2d::Node::PauseAction(const std::wstring& name)
} }
} }
void easy2d::Node::StopAction(const std::wstring& name) void Node::StopAction(const std::wstring& name)
{ {
if (actions_.empty()) if (actions_.empty())
return; return;
@ -835,7 +837,7 @@ void easy2d::Node::StopAction(const std::wstring& name)
} }
} }
bool easy2d::Node::ContainsPoint(const Point& point) bool Node::ContainsPoint(const Point& point)
{ {
if (transform_.size.width == 0.f || transform_.size.height == 0.f) if (transform_.size.width == 0.f || transform_.size.height == 0.f)
return false; return false;
@ -853,7 +855,7 @@ bool easy2d::Node::ContainsPoint(const Point& point)
return ret != 0; return ret != 0;
} }
bool easy2d::Node::Intersects(Node * node) bool Node::Intersects(Node * node)
{ {
if (transform_.size.width == 0.f || transform_.size.height == 0.f || node->transform_.size.width == 0.f || node->transform_.size.height == 0.f) if (transform_.size.width == 0.f || transform_.size.height == 0.f || node->transform_.size.width == 0.f || node->transform_.size.height == 0.f)
return false; return false;
@ -875,7 +877,7 @@ bool easy2d::Node::Intersects(Node * node)
relation != D2D1_GEOMETRY_RELATION_DISJOINT; relation != D2D1_GEOMETRY_RELATION_DISJOINT;
} }
void easy2d::Node::ResumeAllActions() void Node::ResumeAllActions()
{ {
if (actions_.empty()) if (actions_.empty())
return; return;
@ -886,7 +888,7 @@ void easy2d::Node::ResumeAllActions()
} }
} }
void easy2d::Node::PauseAllActions() void Node::PauseAllActions()
{ {
if (actions_.empty()) if (actions_.empty())
return; return;
@ -897,7 +899,7 @@ void easy2d::Node::PauseAllActions()
} }
} }
void easy2d::Node::StopAllActions() void Node::StopAllActions()
{ {
if (actions_.empty()) if (actions_.empty())
return; return;
@ -908,12 +910,12 @@ void easy2d::Node::StopAllActions()
} }
} }
const easy2d::Node::Actions & easy2d::Node::GetAllActions() const const Node::Actions & Node::GetAllActions() const
{ {
return actions_; return actions_;
} }
void easy2d::Node::AddTask(Task * task) void Node::AddTask(Task * task)
{ {
if (task) if (task)
{ {
@ -927,7 +929,7 @@ void easy2d::Node::AddTask(Task * task)
} }
} }
void easy2d::Node::StopTasks(const std::wstring& name) void Node::StopTasks(const std::wstring& name)
{ {
for (const auto& task : tasks_) for (const auto& task : tasks_)
{ {
@ -938,7 +940,7 @@ void easy2d::Node::StopTasks(const std::wstring& name)
} }
} }
void easy2d::Node::StartTasks(const std::wstring& name) void Node::StartTasks(const std::wstring& name)
{ {
for (const auto& task : tasks_) for (const auto& task : tasks_)
{ {
@ -949,7 +951,7 @@ void easy2d::Node::StartTasks(const std::wstring& name)
} }
} }
void easy2d::Node::RemoveTasks(const std::wstring& name) void Node::RemoveTasks(const std::wstring& name)
{ {
for (const auto& task : tasks_) for (const auto& task : tasks_)
{ {
@ -960,7 +962,7 @@ void easy2d::Node::RemoveTasks(const std::wstring& name)
} }
} }
void easy2d::Node::StopAllTasks() void Node::StopAllTasks()
{ {
for (const auto& task : tasks_) for (const auto& task : tasks_)
{ {
@ -968,7 +970,7 @@ void easy2d::Node::StopAllTasks()
} }
} }
void easy2d::Node::StartAllTasks() void Node::StartAllTasks()
{ {
for (const auto& task : tasks_) for (const auto& task : tasks_)
{ {
@ -976,7 +978,7 @@ void easy2d::Node::StartAllTasks()
} }
} }
void easy2d::Node::RemoveAllTasks() void Node::RemoveAllTasks()
{ {
for (const auto& task : tasks_) for (const auto& task : tasks_)
{ {
@ -984,12 +986,12 @@ void easy2d::Node::RemoveAllTasks()
} }
} }
const easy2d::Node::Tasks & easy2d::Node::GetAllTasks() const const Node::Tasks & Node::GetAllTasks() const
{ {
return tasks_; return tasks_;
} }
void easy2d::Node::UpdateTasks() void Node::UpdateTasks()
{ {
if (tasks_.empty()) if (tasks_.empty())
return; return;
@ -1022,7 +1024,7 @@ void easy2d::Node::UpdateTasks()
} }
} }
void easy2d::Node::UpdateTime() void Node::UpdateTime()
{ {
for (const auto& action : actions_) for (const auto& action : actions_)
{ {
@ -1040,12 +1042,12 @@ void easy2d::Node::UpdateTime()
} }
} }
void easy2d::Node::SetVisible(bool value) void Node::SetVisible(bool value)
{ {
visible_ = value; visible_ = value;
} }
void easy2d::Node::SetName(const std::wstring& name) void Node::SetName(const std::wstring& name)
{ {
if (name_ != name) if (name_ != name)
{ {
@ -1056,7 +1058,7 @@ void easy2d::Node::SetName(const std::wstring& name)
} }
} }
void easy2d::Node::SetParentScene(Scene * scene) void Node::SetParentScene(Scene * scene)
{ {
parent_scene_ = scene; parent_scene_ = scene;
for (const auto& child : children_) for (const auto& child : children_)
@ -1064,3 +1066,4 @@ void easy2d::Node::SetParentScene(Scene * scene)
child->SetParentScene(scene); child->SetParentScene(scene);
} }
} }
}

View File

@ -21,20 +21,22 @@
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::Scene::Scene() namespace easy2d
{
Scene::Scene()
: root_(nullptr) : root_(nullptr)
, transform_(D2D1::Matrix3x2F::Identity()) , transform_(D2D1::Matrix3x2F::Identity())
{ {
} }
easy2d::Scene::Scene(Node * root) Scene::Scene(Node * root)
: root_(nullptr) : root_(nullptr)
, transform_(D2D1::Matrix3x2F::Identity()) , transform_(D2D1::Matrix3x2F::Identity())
{ {
this->SetRoot(root); this->SetRoot(root);
} }
easy2d::Scene::~Scene() Scene::~Scene()
{ {
if (root_) if (root_)
{ {
@ -43,7 +45,7 @@ easy2d::Scene::~Scene()
} }
} }
void easy2d::Scene::SetRoot(Node * root) void Scene::SetRoot(Node * root)
{ {
if (root_ == root) if (root_ == root)
return; return;
@ -63,12 +65,12 @@ void easy2d::Scene::SetRoot(Node * root)
root_ = root; root_ = root;
} }
easy2d::Node * easy2d::Scene::GetRoot() const Node * Scene::GetRoot() const
{ {
return root_; return root_;
} }
void easy2d::Scene::Draw() void Scene::Draw()
{ {
if (root_) if (root_)
{ {
@ -76,7 +78,7 @@ void easy2d::Scene::Draw()
} }
} }
void easy2d::Scene::Dispatch(const MouseEvent & e) void Scene::Dispatch(const MouseEvent & e)
{ {
auto handler = dynamic_cast<MouseEventHandler*>(this); auto handler = dynamic_cast<MouseEventHandler*>(this);
if (handler) if (handler)
@ -90,7 +92,7 @@ void easy2d::Scene::Dispatch(const MouseEvent & e)
} }
} }
void easy2d::Scene::Dispatch(const KeyEvent & e) void Scene::Dispatch(const KeyEvent & e)
{ {
auto handler = dynamic_cast<KeyEventHandler*>(this); auto handler = dynamic_cast<KeyEventHandler*>(this);
if (handler) if (handler)
@ -104,7 +106,7 @@ void easy2d::Scene::Dispatch(const KeyEvent & e)
} }
} }
void easy2d::Scene::SetTransform(const D2D1::Matrix3x2F& matrix) void Scene::SetTransform(const D2D1::Matrix3x2F& matrix)
{ {
transform_ = matrix; transform_ = matrix;
@ -114,7 +116,8 @@ void easy2d::Scene::SetTransform(const D2D1::Matrix3x2F& matrix)
} }
} }
const D2D1::Matrix3x2F & easy2d::Scene::GetTransform() const const D2D1::Matrix3x2F & Scene::GetTransform() const
{ {
return transform_; return transform_;
} }
}

View File

@ -21,49 +21,51 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
easy2d::Sprite::Sprite() namespace easy2d
{
Sprite::Sprite()
: image_(nullptr) : image_(nullptr)
{ {
} }
easy2d::Sprite::Sprite(Image * image) Sprite::Sprite(Image * image)
: image_(nullptr) : image_(nullptr)
{ {
Load(image); Load(image);
} }
easy2d::Sprite::Sprite(Resource& res) Sprite::Sprite(Resource& res)
: image_(nullptr) : image_(nullptr)
{ {
Load(res); Load(res);
} }
easy2d::Sprite::Sprite(Resource& res, const Rect& crop_rect) Sprite::Sprite(Resource& res, const Rect& crop_rect)
: image_(nullptr) : image_(nullptr)
{ {
Load(res); Load(res);
Crop(crop_rect); Crop(crop_rect);
} }
easy2d::Sprite::Sprite(const std::wstring & file_name) Sprite::Sprite(const std::wstring & file_name)
: image_(nullptr) : image_(nullptr)
{ {
Load(file_name); Load(file_name);
} }
easy2d::Sprite::Sprite(const std::wstring & file_name, const Rect & crop_rect) Sprite::Sprite(const std::wstring & file_name, const Rect & crop_rect)
: image_(nullptr) : image_(nullptr)
{ {
Load(file_name); Load(file_name);
Crop(crop_rect); Crop(crop_rect);
} }
easy2d::Sprite::~Sprite() Sprite::~Sprite()
{ {
SafeRelease(image_); SafeRelease(image_);
} }
bool easy2d::Sprite::Load(Image * image) bool Sprite::Load(Image * image)
{ {
if (image) if (image)
{ {
@ -81,7 +83,7 @@ bool easy2d::Sprite::Load(Image * image)
return false; return false;
} }
bool easy2d::Sprite::Load(Resource& res) bool Sprite::Load(Resource& res)
{ {
if (!image_) if (!image_)
{ {
@ -97,7 +99,7 @@ bool easy2d::Sprite::Load(Resource& res)
return false; return false;
} }
bool easy2d::Sprite::Load(const std::wstring & file_name) bool Sprite::Load(const std::wstring & file_name)
{ {
if (!image_) if (!image_)
{ {
@ -113,7 +115,7 @@ bool easy2d::Sprite::Load(const std::wstring & file_name)
return false; return false;
} }
void easy2d::Sprite::Crop(const Rect& crop_rect) void Sprite::Crop(const Rect& crop_rect)
{ {
image_->Crop(crop_rect); image_->Crop(crop_rect);
Node::SetSize( Node::SetSize(
@ -122,12 +124,12 @@ void easy2d::Sprite::Crop(const Rect& crop_rect)
); );
} }
easy2d::Image * easy2d::Sprite::GetImage() const Image * Sprite::GetImage() const
{ {
return image_; return image_;
} }
void easy2d::Sprite::OnDraw() const void Sprite::OnDraw() const
{ {
if (image_ && image_->GetBitmap()) if (image_ && image_->GetBitmap())
{ {
@ -146,3 +148,4 @@ void easy2d::Sprite::OnDraw() const
); );
} }
} }
}

View File

@ -21,7 +21,9 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::Task::Task(const Callback & func, const std::wstring & name) namespace easy2d
{
Task::Task(const Callback & func, const std::wstring & name)
: running_(true) : running_(true)
, stopped_(false) , stopped_(false)
, run_times_(0) , run_times_(0)
@ -32,7 +34,7 @@ easy2d::Task::Task(const Callback & func, const std::wstring & name)
{ {
} }
easy2d::Task::Task(const Callback & func, float delay, int times, const std::wstring & name) Task::Task(const Callback & func, float delay, int times, const std::wstring & name)
: running_(true) : running_(true)
, stopped_(false) , stopped_(false)
, run_times_(0) , run_times_(0)
@ -43,18 +45,18 @@ easy2d::Task::Task(const Callback & func, float delay, int times, const std::wst
{ {
} }
void easy2d::Task::Start() void Task::Start()
{ {
running_ = true; running_ = true;
last_time_ = Time::Now(); last_time_ = Time::Now();
} }
void easy2d::Task::Stop() void Task::Stop()
{ {
running_ = false; running_ = false;
} }
void easy2d::Task::Update() void Task::Update()
{ {
if (total_times_ == 0) if (total_times_ == 0)
{ {
@ -77,12 +79,12 @@ void easy2d::Task::Update()
} }
} }
void easy2d::Task::ResetTime() void Task::ResetTime()
{ {
last_time_ = Time::Now(); last_time_ = Time::Now();
} }
bool easy2d::Task::IsReady() const bool Task::IsReady() const
{ {
if (running_) if (running_)
{ {
@ -98,12 +100,13 @@ bool easy2d::Task::IsReady() const
return false; return false;
} }
bool easy2d::Task::IsRunning() const bool Task::IsRunning() const
{ {
return running_; return running_;
} }
const std::wstring& easy2d::Task::GetName() const const std::wstring& Task::GetName() const
{ {
return name_; return name_;
} }
}

View File

@ -21,11 +21,14 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
namespace easy2d
{
//------------------------------------------------------- //-------------------------------------------------------
// Style // Style
//------------------------------------------------------- //-------------------------------------------------------
easy2d::Text::Style::Style() Text::Style::Style()
: color(Color::White) : color(Color::White)
, alignment(Align::Left) , alignment(Align::Left)
, wrap(false) , wrap(false)
@ -39,7 +42,7 @@ easy2d::Text::Style::Style()
, outline_stroke(Stroke::Round) , outline_stroke(Stroke::Round)
{} {}
easy2d::Text::Style::Style( Text::Style::Style(
Color color, Color color,
Align alignment, Align alignment,
bool wrap, bool wrap,
@ -71,7 +74,7 @@ easy2d::Text::Style::Style(
// Text // Text
//------------------------------------------------------- //-------------------------------------------------------
easy2d::Text::Text() Text::Text()
: font_() : font_()
, style_() , style_()
, text_layout_(nullptr) , text_layout_(nullptr)
@ -79,7 +82,7 @@ easy2d::Text::Text()
{ {
} }
easy2d::Text::Text(const std::wstring & text, const Font & font, const Style & style) Text::Text(const std::wstring & text, const Font & font, const Style & style)
: font_(font) : font_(font)
, style_(style) , style_(style)
, text_layout_(nullptr) , text_layout_(nullptr)
@ -89,63 +92,63 @@ easy2d::Text::Text(const std::wstring & text, const Font & font, const Style & s
Reset(); Reset();
} }
easy2d::Text::~Text() Text::~Text()
{ {
SafeRelease(text_format_); SafeRelease(text_format_);
SafeRelease(text_layout_); SafeRelease(text_layout_);
} }
const std::wstring& easy2d::Text::GetText() const const std::wstring& Text::GetText() const
{ {
return text_; return text_;
} }
const easy2d::Font& easy2d::Text::GetFont() const const Font& Text::GetFont() const
{ {
return font_; return font_;
} }
const easy2d::Text::Style& easy2d::Text::GetStyle() const const Text::Style& Text::GetStyle() const
{ {
return style_; return style_;
} }
const std::wstring& easy2d::Text::GetFontFamily() const const std::wstring& Text::GetFontFamily() const
{ {
return font_.family; return font_.family;
} }
float easy2d::Text::GetFontSize() const float Text::GetFontSize() const
{ {
return font_.size; return font_.size;
} }
UINT easy2d::Text::GetFontWeight() const UINT Text::GetFontWeight() const
{ {
return font_.weight; return font_.weight;
} }
const easy2d::Color& easy2d::Text::GetColor() const const Color& Text::GetColor() const
{ {
return style_.color; return style_.color;
} }
const easy2d::Color& easy2d::Text::GetOutlineColor() const const Color& Text::GetOutlineColor() const
{ {
return style_.outline_color; return style_.outline_color;
} }
float easy2d::Text::GetOutlineWidth() const float Text::GetOutlineWidth() const
{ {
return style_.outline_width; return style_.outline_width;
} }
easy2d::Stroke easy2d::Text::GetOutlineStroke() const Stroke Text::GetOutlineStroke() const
{ {
return style_.outline_stroke; return style_.outline_stroke;
} }
int easy2d::Text::GetLineCount() const int Text::GetLineCount() const
{ {
if (text_layout_) if (text_layout_)
{ {
@ -159,74 +162,74 @@ int easy2d::Text::GetLineCount() const
} }
} }
bool easy2d::Text::IsItalic() const bool Text::IsItalic() const
{ {
return font_.italic; return font_.italic;
} }
bool easy2d::Text::strikethrough() const bool Text::strikethrough() const
{ {
return style_.strikethrough; return style_.strikethrough;
} }
bool easy2d::Text::underline() const bool Text::underline() const
{ {
return style_.underline; return style_.underline;
} }
bool easy2d::Text::outline() const bool Text::outline() const
{ {
return style_.outline; return style_.outline;
} }
void easy2d::Text::SetText(const std::wstring& text) void Text::SetText(const std::wstring& text)
{ {
text_ = text; text_ = text;
Reset(); Reset();
} }
void easy2d::Text::SetStyle(const Style& style) void Text::SetStyle(const Style& style)
{ {
style_ = style; style_ = style;
Reset(); Reset();
} }
void easy2d::Text::SetFont(const Font & font) void Text::SetFont(const Font & font)
{ {
font_ = font; font_ = font;
Reset(); Reset();
} }
void easy2d::Text::SetFontFamily(const std::wstring& family) void Text::SetFontFamily(const std::wstring& family)
{ {
font_.family = family; font_.family = family;
Reset(); Reset();
} }
void easy2d::Text::SetFontSize(float size) void Text::SetFontSize(float size)
{ {
font_.size = size; font_.size = size;
Reset(); Reset();
} }
void easy2d::Text::SetFontWeight(UINT weight) void Text::SetFontWeight(UINT weight)
{ {
font_.weight = weight; font_.weight = weight;
Reset(); Reset();
} }
void easy2d::Text::SetColor(Color color) void Text::SetColor(Color color)
{ {
style_.color = color; style_.color = color;
} }
void easy2d::Text::SetItalic(bool value) void Text::SetItalic(bool value)
{ {
font_.italic = value; font_.italic = value;
Reset(); Reset();
} }
void easy2d::Text::SetWrapEnabled(bool wrap) void Text::SetWrapEnabled(bool wrap)
{ {
if (style_.wrap != wrap) if (style_.wrap != wrap)
{ {
@ -235,7 +238,7 @@ void easy2d::Text::SetWrapEnabled(bool wrap)
} }
} }
void easy2d::Text::SetWrapWidth(float wrap_width) void Text::SetWrapWidth(float wrap_width)
{ {
if (style_.wrap_width != wrap_width) if (style_.wrap_width != wrap_width)
{ {
@ -248,7 +251,7 @@ void easy2d::Text::SetWrapWidth(float wrap_width)
} }
} }
void easy2d::Text::SetLineSpacing(float line_spacing) void Text::SetLineSpacing(float line_spacing)
{ {
if (style_.line_spacing != line_spacing) if (style_.line_spacing != line_spacing)
{ {
@ -257,7 +260,7 @@ void easy2d::Text::SetLineSpacing(float line_spacing)
} }
} }
void easy2d::Text::SetAlignment(Align align) void Text::SetAlignment(Align align)
{ {
if (style_.alignment != align) if (style_.alignment != align)
{ {
@ -266,7 +269,7 @@ void easy2d::Text::SetAlignment(Align align)
} }
} }
void easy2d::Text::SetUnderline(bool underline) void Text::SetUnderline(bool underline)
{ {
if (style_.underline != underline) if (style_.underline != underline)
{ {
@ -277,7 +280,7 @@ void easy2d::Text::SetUnderline(bool underline)
} }
} }
void easy2d::Text::SetStrikethrough(bool strikethrough) void Text::SetStrikethrough(bool strikethrough)
{ {
if (style_.strikethrough != strikethrough) if (style_.strikethrough != strikethrough)
{ {
@ -288,27 +291,27 @@ void easy2d::Text::SetStrikethrough(bool strikethrough)
} }
} }
void easy2d::Text::SetOutline(bool outline) void Text::SetOutline(bool outline)
{ {
style_.outline = outline; style_.outline = outline;
} }
void easy2d::Text::SetOutlineColor(Color outline_color) void Text::SetOutlineColor(Color outline_color)
{ {
style_.outline_color = outline_color; style_.outline_color = outline_color;
} }
void easy2d::Text::SetOutlineWidth(float outline_width) void Text::SetOutlineWidth(float outline_width)
{ {
style_.outline_width = outline_width; style_.outline_width = outline_width;
} }
void easy2d::Text::SetOutlineStroke(Stroke outline_stroke) void Text::SetOutlineStroke(Stroke outline_stroke)
{ {
style_.outline_stroke = outline_stroke; style_.outline_stroke = outline_stroke;
} }
void easy2d::Text::OnDraw() const void Text::OnDraw() const
{ {
if (text_layout_) if (text_layout_)
{ {
@ -330,7 +333,7 @@ void easy2d::Text::OnDraw() const
} }
} }
void easy2d::Text::Reset() void Text::Reset()
{ {
// ´´½¨ÎÄ×Ö¸ñʽ»¯ // ´´½¨ÎÄ×Ö¸ñʽ»¯
CreateFormat(); CreateFormat();
@ -338,7 +341,7 @@ void easy2d::Text::Reset()
CreateLayout(); CreateLayout();
} }
void easy2d::Text::CreateFormat() void Text::CreateFormat()
{ {
SafeRelease(text_format_); SafeRelease(text_format_);
@ -383,7 +386,7 @@ void easy2d::Text::CreateFormat()
} }
} }
void easy2d::Text::CreateLayout() void Text::CreateLayout()
{ {
SafeRelease(text_layout_); SafeRelease(text_layout_);
@ -467,3 +470,4 @@ void easy2d::Text::CreateLayout()
text_layout_->SetStrikethrough(true, Range); text_layout_->SetStrikethrough(true, Range);
} }
} }
}

View File

@ -21,14 +21,16 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
easy2d::Data::Data(const std::wstring & key, const std::wstring & field) namespace easy2d
{
Data::Data(const std::wstring & key, const std::wstring & field)
: key_(key) : key_(key)
, field_(field) , field_(field)
, data_path_(Path::GetDataPath()) , data_path_(Path::GetDataPath())
{ {
} }
bool easy2d::Data::Exists() const bool Data::Exists() const
{ {
wchar_t temp[256] = { 0 }; wchar_t temp[256] = { 0 };
::GetPrivateProfileStringW( ::GetPrivateProfileStringW(
@ -42,7 +44,7 @@ bool easy2d::Data::Exists() const
return temp[0] == L'\0'; return temp[0] == L'\0';
} }
bool easy2d::Data::SaveInt(int value) bool Data::SaveInt(int value)
{ {
BOOL ret = ::WritePrivateProfileStringW( BOOL ret = ::WritePrivateProfileStringW(
field_.c_str(), field_.c_str(),
@ -53,7 +55,7 @@ bool easy2d::Data::SaveInt(int value)
return ret == TRUE; return ret == TRUE;
} }
bool easy2d::Data::SaveFloat(float value) bool Data::SaveFloat(float value)
{ {
BOOL ret = ::WritePrivateProfileStringW( BOOL ret = ::WritePrivateProfileStringW(
field_.c_str(), field_.c_str(),
@ -64,7 +66,7 @@ bool easy2d::Data::SaveFloat(float value)
return ret == TRUE; return ret == TRUE;
} }
bool easy2d::Data::SaveDouble(double value) bool Data::SaveDouble(double value)
{ {
BOOL ret = ::WritePrivateProfileStringW( BOOL ret = ::WritePrivateProfileStringW(
field_.c_str(), field_.c_str(),
@ -75,7 +77,7 @@ bool easy2d::Data::SaveDouble(double value)
return ret == TRUE; return ret == TRUE;
} }
bool easy2d::Data::SaveBool(bool value) bool Data::SaveBool(bool value)
{ {
BOOL ret = ::WritePrivateProfileStringW( BOOL ret = ::WritePrivateProfileStringW(
field_.c_str(), field_.c_str(),
@ -86,7 +88,7 @@ bool easy2d::Data::SaveBool(bool value)
return ret == TRUE; return ret == TRUE;
} }
bool easy2d::Data::SaveString(const std::wstring& value) bool Data::SaveString(const std::wstring& value)
{ {
BOOL ret = ::WritePrivateProfileStringW( BOOL ret = ::WritePrivateProfileStringW(
field_.c_str(), field_.c_str(),
@ -97,7 +99,7 @@ bool easy2d::Data::SaveString(const std::wstring& value)
return ret == TRUE; return ret == TRUE;
} }
int easy2d::Data::GetInt() const int Data::GetInt() const
{ {
return ::GetPrivateProfileIntW( return ::GetPrivateProfileIntW(
field_.c_str(), field_.c_str(),
@ -107,21 +109,21 @@ int easy2d::Data::GetInt() const
); );
} }
float easy2d::Data::GetFloat() const float Data::GetFloat() const
{ {
wchar_t temp[32] = { 0 }; wchar_t temp[32] = { 0 };
::GetPrivateProfileStringW(field_.c_str(), key_.c_str(), L"0.0", temp, 31, data_path_.c_str()); ::GetPrivateProfileStringW(field_.c_str(), key_.c_str(), L"0.0", temp, 31, data_path_.c_str());
return std::stof(temp); return std::stof(temp);
} }
double easy2d::Data::GetDouble() const double Data::GetDouble() const
{ {
wchar_t temp[32] = { 0 }; wchar_t temp[32] = { 0 };
::GetPrivateProfileStringW(field_.c_str(), key_.c_str(), L"0.0", temp, 31, data_path_.c_str()); ::GetPrivateProfileStringW(field_.c_str(), key_.c_str(), L"0.0", temp, 31, data_path_.c_str());
return std::stod(temp); return std::stod(temp);
} }
bool easy2d::Data::GetBool() const bool Data::GetBool() const
{ {
int nValue = ::GetPrivateProfileIntW( int nValue = ::GetPrivateProfileIntW(
field_.c_str(), field_.c_str(),
@ -131,7 +133,7 @@ bool easy2d::Data::GetBool() const
return nValue == TRUE; return nValue == TRUE;
} }
std::wstring easy2d::Data::GetString() std::wstring Data::GetString()
{ {
wchar_t temp[256] = { 0 }; wchar_t temp[256] = { 0 };
::GetPrivateProfileStringW( ::GetPrivateProfileStringW(
@ -144,3 +146,4 @@ std::wstring easy2d::Data::GetString()
); );
return temp; return temp;
} }
}

View File

@ -23,24 +23,26 @@
#include <cwctype> #include <cwctype>
#include <shobjidl.h> #include <shobjidl.h>
std::list<std::wstring> easy2d::File::search_paths_; namespace easy2d
{
std::list<std::wstring> File::search_paths_;
easy2d::File::File() File::File()
: file_path_() : file_path_()
{ {
} }
easy2d::File::File(const std::wstring & file_name) File::File(const std::wstring & file_name)
: file_path_(file_name) : file_path_(file_name)
{ {
this->Open(file_name); this->Open(file_name);
} }
easy2d::File::~File() File::~File()
{ {
} }
bool easy2d::File::Open(const std::wstring & file_name) bool File::Open(const std::wstring & file_name)
{ {
if (file_name.empty()) if (file_name.empty())
return false; return false;
@ -69,19 +71,19 @@ bool easy2d::File::Open(const std::wstring & file_name)
return false; return false;
} }
bool easy2d::File::Exists() const bool File::Exists() const
{ {
if (::PathFileExists(file_path_.c_str())) if (::PathFileExists(file_path_.c_str()))
return true; return true;
return false; return false;
} }
const std::wstring& easy2d::File::GetPath() const const std::wstring& File::GetPath() const
{ {
return file_path_; return file_path_;
} }
std::wstring easy2d::File::GetExtension() const std::wstring File::GetExtension() const
{ {
std::wstring file_ext; std::wstring file_ext;
// 找到文件名中的最后一个 '.' 的位置 // 找到文件名中的最后一个 '.' 的位置
@ -97,14 +99,14 @@ std::wstring easy2d::File::GetExtension() const
return file_ext; return file_ext;
} }
bool easy2d::File::Delete() bool File::Delete()
{ {
if (::DeleteFile(file_path_.c_str())) if (::DeleteFile(file_path_.c_str()))
return true; return true;
return false; return false;
} }
easy2d::File easy2d::File::Extract(Resource& res, const std::wstring& dest_file_name) File File::Extract(Resource& res, const std::wstring& dest_file_name)
{ {
File file; File file;
HANDLE file_handle = ::CreateFile( HANDLE file_handle = ::CreateFile(
@ -138,7 +140,7 @@ easy2d::File easy2d::File::Extract(Resource& res, const std::wstring& dest_file_
return file; return file;
} }
void easy2d::File::AddSearchPath(const std::wstring & path) void File::AddSearchPath(const std::wstring & path)
{ {
std::wstring tmp = path; std::wstring tmp = path;
size_t pos = 0; size_t pos = 0;
@ -159,7 +161,7 @@ void easy2d::File::AddSearchPath(const std::wstring & path)
} }
} }
easy2d::File easy2d::File::ShowOpenDialog(const std::wstring & title, const std::wstring & filter) File File::ShowOpenDialog(const std::wstring & title, const std::wstring & filter)
{ {
std::wstring file_path; std::wstring file_path;
HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
@ -221,7 +223,7 @@ easy2d::File easy2d::File::ShowOpenDialog(const std::wstring & title, const std:
return File(file_path); return File(file_path);
} }
easy2d::File easy2d::File::ShowSaveDialog(const std::wstring & title, const std::wstring& def_file, const std::wstring & def_ext) File File::ShowSaveDialog(const std::wstring & title, const std::wstring& def_file, const std::wstring & def_ext)
{ {
std::wstring file_path; std::wstring file_path;
HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
@ -290,3 +292,4 @@ easy2d::File easy2d::File::ShowSaveDialog(const std::wstring & title, const std:
} }
return File(file_path); return File(file_path);
} }
}

View File

@ -22,6 +22,8 @@
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
namespace easy2d
{
namespace namespace
{ {
void OutputDebugStringExW(LPCWSTR pszOutput, ...) void OutputDebugStringExW(LPCWSTR pszOutput, ...)
@ -50,10 +52,10 @@ namespace
} }
} }
//-------------------------------------------------------
// Transcoder
//-------------------------------------------------------
namespace easy2d
{
// ÒôƵ½âÂëÆ÷
class Transcoder class Transcoder
{ {
WAVEFORMATEX* wave_format_; WAVEFORMATEX* wave_format_;
@ -304,10 +306,12 @@ namespace easy2d
} }
}; };
}
//-------------------------------------------------------
// Music
//-------------------------------------------------------
easy2d::Music::Music() Music::Music()
: opened_(false) : opened_(false)
, playing_(false) , playing_(false)
, wave_data_(nullptr) , wave_data_(nullptr)
@ -316,7 +320,7 @@ easy2d::Music::Music()
{ {
} }
easy2d::Music::Music(const std::wstring& file_path) Music::Music(const std::wstring& file_path)
: opened_(false) : opened_(false)
, playing_(false) , playing_(false)
, wave_data_(nullptr) , wave_data_(nullptr)
@ -326,7 +330,7 @@ easy2d::Music::Music(const std::wstring& file_path)
Load(file_path); Load(file_path);
} }
easy2d::Music::Music(Resource& res) Music::Music(Resource& res)
: opened_(false) : opened_(false)
, playing_(false) , playing_(false)
, wave_data_(nullptr) , wave_data_(nullptr)
@ -336,12 +340,12 @@ easy2d::Music::Music(Resource& res)
Load(res); Load(res);
} }
easy2d::Music::~Music() Music::~Music()
{ {
Close(); Close();
} }
bool easy2d::Music::Load(const std::wstring & file_path) bool Music::Load(const std::wstring & file_path)
{ {
if (opened_) if (opened_)
{ {
@ -381,7 +385,7 @@ bool easy2d::Music::Load(const std::wstring & file_path)
return true; return true;
} }
bool easy2d::Music::Load(Resource& res) bool Music::Load(Resource& res)
{ {
if (opened_) if (opened_)
{ {
@ -410,7 +414,7 @@ bool easy2d::Music::Load(Resource& res)
return true; return true;
} }
bool easy2d::Music::Play(int loop_count) bool Music::Play(int loop_count)
{ {
if (!opened_) if (!opened_)
{ {
@ -461,7 +465,7 @@ bool easy2d::Music::Play(int loop_count)
return playing_; return playing_;
} }
void easy2d::Music::Pause() void Music::Pause()
{ {
if (voice_) if (voice_)
{ {
@ -472,7 +476,7 @@ void easy2d::Music::Pause()
} }
} }
void easy2d::Music::Resume() void Music::Resume()
{ {
if (voice_) if (voice_)
{ {
@ -483,7 +487,7 @@ void easy2d::Music::Resume()
} }
} }
void easy2d::Music::Stop() void Music::Stop()
{ {
if (voice_) if (voice_)
{ {
@ -496,7 +500,7 @@ void easy2d::Music::Stop()
} }
} }
void easy2d::Music::Close() void Music::Close()
{ {
if (voice_) if (voice_)
{ {
@ -516,7 +520,7 @@ void easy2d::Music::Close()
playing_ = false; playing_ = false;
} }
bool easy2d::Music::IsPlaying() const bool Music::IsPlaying() const
{ {
if (opened_ && voice_) if (opened_ && voice_)
{ {
@ -528,7 +532,7 @@ bool easy2d::Music::IsPlaying() const
return false; return false;
} }
float easy2d::Music::GetVolume() const float Music::GetVolume() const
{ {
if (voice_) if (voice_)
{ {
@ -539,7 +543,7 @@ float easy2d::Music::GetVolume() const
return 0.f; return 0.f;
} }
bool easy2d::Music::SetVolume(float volume) bool Music::SetVolume(float volume)
{ {
if (voice_) if (voice_)
{ {
@ -549,7 +553,8 @@ bool easy2d::Music::SetVolume(float volume)
return false; return false;
} }
IXAudio2SourceVoice * easy2d::Music::GetSourceVoice() const IXAudio2SourceVoice * Music::GetSourceVoice() const
{ {
return voice_; return voice_;
} }
}

View File

@ -23,6 +23,8 @@
#include <shlobj.h> #include <shlobj.h>
namespace easy2d
{
namespace namespace
{ {
// 创建指定文件夹 // 创建指定文件夹
@ -53,7 +55,7 @@ namespace
} }
const std::wstring& easy2d::Path::GetDataPath() const std::wstring& Path::GetDataPath()
{ {
static std::wstring data_path; static std::wstring data_path;
if (data_path.empty()) if (data_path.empty())
@ -81,7 +83,7 @@ const std::wstring& easy2d::Path::GetDataPath()
return data_path; return data_path;
} }
const std::wstring& easy2d::Path::GetTemporaryPath() const std::wstring& Path::GetTemporaryPath()
{ {
static std::wstring temp_path; static std::wstring temp_path;
if (temp_path.empty()) if (temp_path.empty())
@ -108,7 +110,7 @@ const std::wstring& easy2d::Path::GetTemporaryPath()
return temp_path; return temp_path;
} }
const std::wstring& easy2d::Path::GetLocalAppDataPath() const std::wstring& Path::GetLocalAppDataPath()
{ {
static std::wstring local_app_data_path; static std::wstring local_app_data_path;
if (local_app_data_path.empty()) if (local_app_data_path.empty())
@ -122,7 +124,7 @@ const std::wstring& easy2d::Path::GetLocalAppDataPath()
return local_app_data_path; return local_app_data_path;
} }
const std::wstring& easy2d::Path::GetExeFilePath() const std::wstring& Path::GetExeFilePath()
{ {
static std::wstring exe_file_path; static std::wstring exe_file_path;
if (exe_file_path.empty()) if (exe_file_path.empty())
@ -135,3 +137,4 @@ const std::wstring& easy2d::Path::GetExeFilePath()
} }
return exe_file_path; return exe_file_path;
} }
}

View File

@ -1,18 +1,20 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
std::map<size_t, easy2d::Music*> easy2d::Player::musics_; namespace easy2d
{
std::map<size_t, Music*> Player::musics_;
easy2d::Player::Player() Player::Player()
: volume_(1.f) : volume_(1.f)
{ {
} }
easy2d::Player::~Player() Player::~Player()
{ {
} }
bool easy2d::Player::Load(const std::wstring & file_path) bool Player::Load(const std::wstring & file_path)
{ {
if (file_path.empty()) if (file_path.empty())
return false; return false;
@ -37,7 +39,7 @@ bool easy2d::Player::Load(const std::wstring & file_path)
return false; return false;
} }
bool easy2d::Player::Play(const std::wstring & file_path, int loop_count) bool Player::Play(const std::wstring & file_path, int loop_count)
{ {
if (file_path.empty()) if (file_path.empty())
return false; return false;
@ -53,7 +55,7 @@ bool easy2d::Player::Play(const std::wstring & file_path, int loop_count)
return false; return false;
} }
void easy2d::Player::Pause(const std::wstring & file_path) void Player::Pause(const std::wstring & file_path)
{ {
if (file_path.empty()) if (file_path.empty())
return; return;
@ -63,7 +65,7 @@ void easy2d::Player::Pause(const std::wstring & file_path)
musics_[hash_code]->Pause(); musics_[hash_code]->Pause();
} }
void easy2d::Player::Resume(const std::wstring & file_path) void Player::Resume(const std::wstring & file_path)
{ {
if (file_path.empty()) if (file_path.empty())
return; return;
@ -73,7 +75,7 @@ void easy2d::Player::Resume(const std::wstring & file_path)
musics_[hash_code]->Resume(); musics_[hash_code]->Resume();
} }
void easy2d::Player::Stop(const std::wstring & file_path) void Player::Stop(const std::wstring & file_path)
{ {
if (file_path.empty()) if (file_path.empty())
return; return;
@ -83,7 +85,7 @@ void easy2d::Player::Stop(const std::wstring & file_path)
musics_[hash_code]->Stop(); musics_[hash_code]->Stop();
} }
bool easy2d::Player::IsPlaying(const std::wstring & file_path) bool Player::IsPlaying(const std::wstring & file_path)
{ {
if (file_path.empty()) if (file_path.empty())
return false; return false;
@ -94,7 +96,7 @@ bool easy2d::Player::IsPlaying(const std::wstring & file_path)
return false; return false;
} }
bool easy2d::Player::Load(Resource& res) bool Player::Load(Resource& res)
{ {
size_t hash_code = res.GetHashCode(); size_t hash_code = res.GetHashCode();
if (musics_.end() != musics_.find(hash_code)) if (musics_.end() != musics_.find(hash_code))
@ -118,7 +120,7 @@ bool easy2d::Player::Load(Resource& res)
return false; return false;
} }
bool easy2d::Player::Play(Resource& res, int loop_count) bool Player::Play(Resource& res, int loop_count)
{ {
if (Load(res)) if (Load(res))
{ {
@ -132,28 +134,28 @@ bool easy2d::Player::Play(Resource& res, int loop_count)
return false; return false;
} }
void easy2d::Player::Pause(Resource& res) void Player::Pause(Resource& res)
{ {
size_t hash_code = res.GetHashCode(); size_t hash_code = res.GetHashCode();
if (musics_.end() != musics_.find(hash_code)) if (musics_.end() != musics_.find(hash_code))
musics_[hash_code]->Pause(); musics_[hash_code]->Pause();
} }
void easy2d::Player::Resume(Resource& res) void Player::Resume(Resource& res)
{ {
size_t hash_code = res.GetHashCode(); size_t hash_code = res.GetHashCode();
if (musics_.end() != musics_.find(hash_code)) if (musics_.end() != musics_.find(hash_code))
musics_[hash_code]->Resume(); musics_[hash_code]->Resume();
} }
void easy2d::Player::Stop(Resource& res) void Player::Stop(Resource& res)
{ {
size_t hash_code = res.GetHashCode(); size_t hash_code = res.GetHashCode();
if (musics_.end() != musics_.find(hash_code)) if (musics_.end() != musics_.find(hash_code))
musics_[hash_code]->Stop(); musics_[hash_code]->Stop();
} }
bool easy2d::Player::IsPlaying(Resource& res) bool Player::IsPlaying(Resource& res)
{ {
size_t hash_code = res.GetHashCode(); size_t hash_code = res.GetHashCode();
if (musics_.end() != musics_.find(hash_code)) if (musics_.end() != musics_.find(hash_code))
@ -161,12 +163,12 @@ bool easy2d::Player::IsPlaying(Resource& res)
return false; return false;
} }
float easy2d::Player::GetVolume() const float Player::GetVolume() const
{ {
return volume_; return volume_;
} }
void easy2d::Player::SetVolume(float volume) void 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 : musics_) for (const auto& pair : musics_)
@ -175,7 +177,7 @@ void easy2d::Player::SetVolume(float volume)
} }
} }
void easy2d::Player::PauseAll() void Player::PauseAll()
{ {
for (const auto& pair : musics_) for (const auto& pair : musics_)
{ {
@ -183,7 +185,7 @@ void easy2d::Player::PauseAll()
} }
} }
void easy2d::Player::ResumeAll() void Player::ResumeAll()
{ {
for (const auto& pair : musics_) for (const auto& pair : musics_)
{ {
@ -191,7 +193,7 @@ void easy2d::Player::ResumeAll()
} }
} }
void easy2d::Player::StopAll() void Player::StopAll()
{ {
for (const auto& pair : musics_) for (const auto& pair : musics_)
{ {
@ -199,7 +201,7 @@ void easy2d::Player::StopAll()
} }
} }
void easy2d::Player::ClearCache() void Player::ClearCache()
{ {
if (musics_.empty()) if (musics_.empty())
return; return;
@ -210,3 +212,4 @@ void easy2d::Player::ClearCache()
} }
musics_.clear(); musics_.clear();
} }
}

View File

@ -21,19 +21,21 @@
#include "..\e2dtransition.h" #include "..\e2dtransition.h"
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::BoxTransition::BoxTransition(float duration) namespace easy2d
{
BoxTransition::BoxTransition(float duration)
: Transition(duration) : Transition(duration)
{ {
} }
void easy2d::BoxTransition::Init(Scene * prev, Scene * next, Game * game) void BoxTransition::Init(Scene * prev, Scene * next, Game * game)
{ {
Transition::Init(prev, next, game); Transition::Init(prev, next, game);
in_layer_param_.opacity = 0; in_layer_param_.opacity = 0;
} }
void easy2d::BoxTransition::Update() void BoxTransition::Update()
{ {
Transition::Update(); Transition::Update();
@ -58,3 +60,4 @@ void easy2d::BoxTransition::Update()
); );
} }
} }
}

View File

@ -21,12 +21,14 @@
#include "..\e2dtransition.h" #include "..\e2dtransition.h"
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::EmergeTransition::EmergeTransition(float duration) namespace easy2d
{
EmergeTransition::EmergeTransition(float duration)
: Transition(duration) : Transition(duration)
{ {
} }
void easy2d::EmergeTransition::Init(Scene * prev, Scene * next, Game * game) void EmergeTransition::Init(Scene * prev, Scene * next, Game * game)
{ {
Transition::Init(prev, next, game); Transition::Init(prev, next, game);
@ -34,10 +36,11 @@ void easy2d::EmergeTransition::Init(Scene * prev, Scene * next, Game * game)
in_layer_param_.opacity = 0; in_layer_param_.opacity = 0;
} }
void easy2d::EmergeTransition::Update() void EmergeTransition::Update()
{ {
Transition::Update(); Transition::Update();
out_layer_param_.opacity = 1 - process_; out_layer_param_.opacity = 1 - process_;
in_layer_param_.opacity = process_; in_layer_param_.opacity = process_;
} }
}

View File

@ -21,12 +21,14 @@
#include "..\e2dtransition.h" #include "..\e2dtransition.h"
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::FadeTransition::FadeTransition(float duration) namespace easy2d
{
FadeTransition::FadeTransition(float duration)
: Transition(duration) : Transition(duration)
{ {
} }
void easy2d::FadeTransition::Init(Scene * prev, Scene * next, Game * game) void FadeTransition::Init(Scene * prev, Scene * next, Game * game)
{ {
Transition::Init(prev, next, game); Transition::Init(prev, next, game);
@ -34,7 +36,7 @@ void easy2d::FadeTransition::Init(Scene * prev, Scene * next, Game * game)
in_layer_param_.opacity = 0; in_layer_param_.opacity = 0;
} }
void easy2d::FadeTransition::Update() void FadeTransition::Update()
{ {
Transition::Update(); Transition::Update();
@ -49,3 +51,4 @@ void easy2d::FadeTransition::Update()
in_layer_param_.opacity = (process_ - 0.5f) * 2; in_layer_param_.opacity = (process_ - 0.5f) * 2;
} }
} }
}

View File

@ -21,13 +21,15 @@
#include "..\e2dtransition.h" #include "..\e2dtransition.h"
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::MoveTransition::MoveTransition(float duration, Direction direction) namespace easy2d
{
MoveTransition::MoveTransition(float duration, Direction direction)
: Transition(duration) : Transition(duration)
, direction_(direction) , direction_(direction)
{ {
} }
void easy2d::MoveTransition::Init(Scene * prev, Scene * next, Game * game) void MoveTransition::Init(Scene * prev, Scene * next, Game * game)
{ {
Transition::Init(prev, next, game); Transition::Init(prev, next, game);
@ -67,7 +69,7 @@ void easy2d::MoveTransition::Init(Scene * prev, Scene * next, Game * game)
} }
} }
void easy2d::MoveTransition::Update() void MoveTransition::Update()
{ {
Transition::Update(); Transition::Update();
@ -94,7 +96,7 @@ void easy2d::MoveTransition::Update()
} }
} }
void easy2d::MoveTransition::Reset() void MoveTransition::Reset()
{ {
if (out_scene_) if (out_scene_)
{ {
@ -106,3 +108,4 @@ void easy2d::MoveTransition::Reset()
in_scene_->SetTransform(D2D1::Matrix3x2F::Identity()); in_scene_->SetTransform(D2D1::Matrix3x2F::Identity());
} }
} }
}

View File

@ -21,13 +21,15 @@
#include "..\e2dtransition.h" #include "..\e2dtransition.h"
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::RotationTransition::RotationTransition(float duration, float rotation) namespace easy2d
{
RotationTransition::RotationTransition(float duration, float rotation)
: Transition(duration) : Transition(duration)
, rotation_(rotation) , rotation_(rotation)
{ {
} }
void easy2d::RotationTransition::Init(Scene * prev, Scene * next, Game * game) void RotationTransition::Init(Scene * prev, Scene * next, Game * game)
{ {
Transition::Init(prev, next, game); Transition::Init(prev, next, game);
@ -44,7 +46,7 @@ void easy2d::RotationTransition::Init(Scene * prev, Scene * next, Game * game)
in_layer_param_.opacity = 0; in_layer_param_.opacity = 0;
} }
void easy2d::RotationTransition::Update() void RotationTransition::Update()
{ {
Transition::Update(); Transition::Update();
@ -90,7 +92,7 @@ void easy2d::RotationTransition::Update()
} }
} }
void easy2d::RotationTransition::Reset() void RotationTransition::Reset()
{ {
if (out_scene_) if (out_scene_)
{ {
@ -102,3 +104,4 @@ void easy2d::RotationTransition::Reset()
in_scene_->SetTransform(D2D1::Matrix3x2F::Identity()); in_scene_->SetTransform(D2D1::Matrix3x2F::Identity());
} }
} }
}

View File

@ -22,7 +22,9 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
easy2d::Transition::Transition(float duration) namespace easy2d
{
Transition::Transition(float duration)
: done_(false) : done_(false)
, started_() , started_()
, process_(0) , process_(0)
@ -37,7 +39,7 @@ easy2d::Transition::Transition(float duration)
duration_ = std::max(duration, 0.f); duration_ = std::max(duration, 0.f);
} }
easy2d::Transition::~Transition() Transition::~Transition()
{ {
SafeRelease(out_layer_); SafeRelease(out_layer_);
SafeRelease(in_layer_); SafeRelease(in_layer_);
@ -45,12 +47,12 @@ easy2d::Transition::~Transition()
SafeRelease(in_scene_); SafeRelease(in_scene_);
} }
bool easy2d::Transition::IsDone() bool Transition::IsDone()
{ {
return done_; return done_;
} }
void easy2d::Transition::Init(Scene * prev, Scene * next, Game * game) void Transition::Init(Scene * prev, Scene * next, Game * game)
{ {
started_ = Time::Now(); started_ = Time::Now();
out_scene_ = prev; out_scene_ = prev;
@ -94,7 +96,7 @@ void easy2d::Transition::Init(Scene * prev, Scene * next, Game * game)
); );
} }
void easy2d::Transition::Update() void Transition::Update()
{ {
if (duration_ == 0) if (duration_ == 0)
{ {
@ -112,7 +114,7 @@ void easy2d::Transition::Update()
} }
} }
void easy2d::Transition::Draw() void Transition::Draw()
{ {
auto render_target = Device::GetGraphics()->GetRenderTarget(); auto render_target = Device::GetGraphics()->GetRenderTarget();
@ -157,8 +159,9 @@ void easy2d::Transition::Draw()
} }
} }
void easy2d::Transition::Stop() void Transition::Stop()
{ {
done_ = true; done_ = true;
Reset(); Reset();
} }
}

View File

@ -20,15 +20,20 @@
#include "..\e2dutil.h" #include "..\e2dutil.h"
static const UINT kRedShift = 16; namespace easy2d
static const UINT kGreenShift = 8; {
static const UINT kBlueShift = 0; namespace
{
const UINT RED_SHIFT = 16;
const UINT GREEN_SHIFT = 8;
const UINT BLUE_SHIFT = 0;
static const UINT kRedMask = 0xff << kRedShift; const UINT RED_MASK = 0xff << RED_SHIFT;
static const UINT kGreenMask = 0xff << kGreenShift; const UINT GREEN_MASK = 0xff << GREEN_SHIFT;
static const UINT kBlueMask = 0xff << kBlueShift; const UINT BLUE_MASK = 0xff << BLUE_SHIFT;
}
easy2d::Color::Color() Color::Color()
: r(0) : r(0)
, g(0) , g(0)
, b(0) , b(0)
@ -36,7 +41,7 @@ easy2d::Color::Color()
{ {
} }
easy2d::Color::Color(float r, float g, float b) Color::Color(float r, float g, float b)
: r(r) : r(r)
, g(g) , g(g)
, b(b) , b(b)
@ -44,7 +49,7 @@ easy2d::Color::Color(float r, float g, float b)
{ {
} }
easy2d::Color::Color(float r, float g, float b, float alpha) Color::Color(float r, float g, float b, float alpha)
: r(r) : r(r)
, g(g) , g(g)
, b(b) , b(b)
@ -52,23 +57,23 @@ easy2d::Color::Color(float r, float g, float b, float alpha)
{ {
} }
easy2d::Color::Color(UINT rgb) Color::Color(UINT rgb)
: r(((rgb & kRedMask) >> kRedShift) / 255.f) : r(((rgb & RED_MASK) >> RED_SHIFT) / 255.f)
, g(((rgb & kGreenMask) >> kGreenShift) / 255.f) , g(((rgb & GREEN_MASK) >> GREEN_SHIFT) / 255.f)
, b(((rgb & kBlueMask) >> kBlueShift) / 255.f) , b(((rgb & BLUE_MASK) >> BLUE_SHIFT) / 255.f)
, a(1.f) , a(1.f)
{ {
} }
easy2d::Color::Color(UINT rgb, float alpha) Color::Color(UINT rgb, float alpha)
: r(((rgb & kRedMask) >> kRedShift) / 255.f) : r(((rgb & RED_MASK) >> RED_SHIFT) / 255.f)
, g(((rgb & kGreenMask) >> kGreenShift) / 255.f) , g(((rgb & GREEN_MASK) >> GREEN_SHIFT) / 255.f)
, b(((rgb & kBlueMask) >> kBlueShift) / 255.f) , b(((rgb & BLUE_MASK) >> BLUE_SHIFT) / 255.f)
, a(alpha) , a(alpha)
{ {
} }
easy2d::Color::Color(const D2D1_COLOR_F& color) Color::Color(const D2D1_COLOR_F& color)
: r(color.r) : r(color.r)
, g(color.g) , g(color.g)
, b(color.b) , b(color.b)
@ -76,7 +81,8 @@ easy2d::Color::Color(const D2D1_COLOR_F& color)
{ {
} }
easy2d::Color::operator D2D1_COLOR_F() const Color::operator D2D1_COLOR_F() const
{ {
return D2D1::ColorF(r, g, b, a); return D2D1::ColorF(r, g, b, a);
} }
}

View File

@ -22,59 +22,70 @@
#include <regex> #include <regex>
const easy2d::Duration easy2d::Duration::Millisecond = easy2d::Duration(1); namespace easy2d
const easy2d::Duration easy2d::Duration::Second = 1000 * easy2d::Duration::Millisecond; {
const easy2d::Duration easy2d::Duration::Minute = 60 * easy2d::Duration::Second; const Duration Duration::Millisecond = Duration(1);
const easy2d::Duration easy2d::Duration::Hour = 60 * easy2d::Duration::Minute; const Duration Duration::Second = 1000 * Duration::Millisecond;
const Duration Duration::Minute = 60 * Duration::Second;
const Duration Duration::Hour = 60 * Duration::Minute;
easy2d::Duration::Duration() namespace
{
const auto duration_regex = std::wregex(L"[-+]?([0-9]*(\\.[0-9]*)?[a-z]+)+");
typedef std::map<std::wstring, Duration> UnitMap;
const auto unit_map = UnitMap{
{L"ms", Duration::Millisecond},
{L"s", Duration::Second},
{L"m", Duration::Minute},
{L"h", Duration::Hour}
};
}
Duration::Duration()
: milliseconds_(0) : milliseconds_(0)
{ {
} }
easy2d::Duration::Duration(int milliseconds) Duration::Duration(int milliseconds)
: milliseconds_(milliseconds) : milliseconds_(milliseconds)
{ {
} }
int easy2d::Duration::Milliseconds() const int Duration::Milliseconds() const
{ {
return milliseconds_; return milliseconds_;
} }
float easy2d::Duration::Seconds() const float Duration::Seconds() const
{ {
int64_t sec = milliseconds_ / Second.milliseconds_; int64_t sec = milliseconds_ / Second.milliseconds_;
int64_t ms = milliseconds_ % Second.milliseconds_; int64_t ms = milliseconds_ % Second.milliseconds_;
return static_cast<float>(sec) + static_cast<float>(ms) / 1000.f; return static_cast<float>(sec) + static_cast<float>(ms) / 1000.f;
} }
float easy2d::Duration::Minutes() const float Duration::Minutes() const
{ {
int64_t min = milliseconds_ / Minute.milliseconds_; int64_t min = milliseconds_ / Minute.milliseconds_;
int64_t ms = milliseconds_ % Minute.milliseconds_; int64_t ms = milliseconds_ % Minute.milliseconds_;
return static_cast<float>(min) + static_cast<float>(ms) / (60 * 1000.f); return static_cast<float>(min) + static_cast<float>(ms) / (60 * 1000.f);
} }
float easy2d::Duration::Hours() const float Duration::Hours() const
{ {
int64_t hour = milliseconds_ / Hour.milliseconds_; int64_t hour = milliseconds_ / Hour.milliseconds_;
int64_t ms = milliseconds_ % Hour.milliseconds_; int64_t ms = milliseconds_ % Hour.milliseconds_;
return static_cast<float>(hour) + static_cast<float>(ms) / (60 * 60 * 1000.f); return static_cast<float>(hour) + static_cast<float>(ms) / (60 * 60 * 1000.f);
} }
easy2d::Duration easy2d::Duration::Parse(const std::wstring & str) Duration Duration::Parse(const std::wstring & str)
{ {
typedef std::map<std::wstring, Duration> UnitMap;
static const auto regex = std::wregex(L"[-+]?([0-9]*(\\.[0-9]*)?[a-z]+)+");
static const auto unit_map = UnitMap{{L"ms", Millisecond}, {L"s", Second}, {L"m", Minute}, {L"h", Hour}};
size_t len = str.length(); size_t len = str.length();
size_t pos = 0; size_t pos = 0;
bool negative = false; bool negative = false;
Duration d; Duration d;
if (!std::regex_match(str, regex)) if (!std::regex_match(str, duration_regex))
{ {
E2D_WARNING("Duration::Parse: invalid duration"); E2D_WARNING("Duration::Parse: invalid duration");
return d; return d;
@ -142,155 +153,157 @@ easy2d::Duration easy2d::Duration::Parse(const std::wstring & str)
return d; return d;
} }
bool easy2d::Duration::operator==(const Duration & other) const bool Duration::operator==(const Duration & other) const
{ {
return milliseconds_ == other.milliseconds_; return milliseconds_ == other.milliseconds_;
} }
bool easy2d::Duration::operator!=(const Duration & other) const bool Duration::operator!=(const Duration & other) const
{ {
return milliseconds_ != other.milliseconds_; return milliseconds_ != other.milliseconds_;
} }
bool easy2d::Duration::operator>(const Duration & other) const bool Duration::operator>(const Duration & other) const
{ {
return milliseconds_ > other.milliseconds_; return milliseconds_ > other.milliseconds_;
} }
bool easy2d::Duration::operator>=(const Duration & other) const bool Duration::operator>=(const Duration & other) const
{ {
return milliseconds_ >= other.milliseconds_; return milliseconds_ >= other.milliseconds_;
} }
bool easy2d::Duration::operator<(const Duration & other) const bool Duration::operator<(const Duration & other) const
{ {
return milliseconds_ < other.milliseconds_; return milliseconds_ < other.milliseconds_;
} }
bool easy2d::Duration::operator<=(const Duration & other) const bool Duration::operator<=(const Duration & other) const
{ {
return milliseconds_ <= other.milliseconds_; return milliseconds_ <= other.milliseconds_;
} }
easy2d::Duration easy2d::Duration::operator+(const Duration & other) const Duration Duration::operator+(const Duration & other) const
{ {
return Duration(milliseconds_ + other.milliseconds_); return Duration(milliseconds_ + other.milliseconds_);
} }
easy2d::Duration easy2d::Duration::operator-(const Duration & other) const Duration Duration::operator-(const Duration & other) const
{ {
return Duration(milliseconds_ - other.milliseconds_); return Duration(milliseconds_ - other.milliseconds_);
} }
easy2d::Duration easy2d::Duration::operator-() const Duration Duration::operator-() const
{ {
return Duration(-milliseconds_); return Duration(-milliseconds_);
} }
easy2d::Duration easy2d::Duration::operator*(int value) const Duration Duration::operator*(int value) const
{ {
return Duration(milliseconds_ * value); return Duration(milliseconds_ * value);
} }
easy2d::Duration easy2d::Duration::operator/(int value) const Duration Duration::operator/(int value) const
{ {
return Duration(milliseconds_ / value); return Duration(milliseconds_ / value);
} }
easy2d::Duration easy2d::Duration::operator*(float value) const Duration Duration::operator*(float value) const
{ {
return Duration(static_cast<int>(milliseconds_ * value)); return Duration(static_cast<int>(milliseconds_ * value));
} }
easy2d::Duration easy2d::Duration::operator/(float value) const Duration Duration::operator/(float value) const
{ {
return Duration(static_cast<int>(milliseconds_ / value)); return Duration(static_cast<int>(milliseconds_ / value));
} }
easy2d::Duration easy2d::Duration::operator*(double value) const Duration Duration::operator*(double value) const
{ {
return Duration(static_cast<int>(milliseconds_ * value)); return Duration(static_cast<int>(milliseconds_ * value));
} }
easy2d::Duration easy2d::Duration::operator/(double value) const Duration Duration::operator/(double value) const
{ {
return Duration(static_cast<int>(milliseconds_ / value)); return Duration(static_cast<int>(milliseconds_ / value));
} }
easy2d::Duration & easy2d::Duration::operator+=(const Duration &other) Duration & Duration::operator+=(const Duration &other)
{ {
milliseconds_ += other.milliseconds_; milliseconds_ += other.milliseconds_;
return (*this); return (*this);
} }
easy2d::Duration & easy2d::Duration::operator-=(const Duration &other) Duration & Duration::operator-=(const Duration &other)
{ {
milliseconds_ -= other.milliseconds_; milliseconds_ -= other.milliseconds_;
return (*this); return (*this);
} }
easy2d::Duration & easy2d::Duration::operator*=(int value) Duration & Duration::operator*=(int value)
{ {
milliseconds_ *= value; milliseconds_ *= value;
return (*this); return (*this);
} }
easy2d::Duration & easy2d::Duration::operator/=(int value) Duration & Duration::operator/=(int value)
{ {
milliseconds_ /= value; milliseconds_ /= value;
return (*this); return (*this);
} }
easy2d::Duration & easy2d::Duration::operator*=(float value) Duration & Duration::operator*=(float value)
{ {
milliseconds_ = static_cast<int>(milliseconds_ * value); milliseconds_ = static_cast<int>(milliseconds_ * value);
return (*this); return (*this);
} }
easy2d::Duration & easy2d::Duration::operator/=(float value) Duration & Duration::operator/=(float value)
{ {
milliseconds_ = static_cast<int>(milliseconds_ / value); milliseconds_ = static_cast<int>(milliseconds_ / value);
return (*this); return (*this);
} }
easy2d::Duration & easy2d::Duration::operator*=(double value) Duration & Duration::operator*=(double value)
{ {
milliseconds_ = static_cast<int>(milliseconds_ * value); milliseconds_ = static_cast<int>(milliseconds_ * value);
return (*this); return (*this);
} }
easy2d::Duration & easy2d::Duration::operator/=(double value) Duration & Duration::operator/=(double value)
{ {
milliseconds_ = static_cast<int>(milliseconds_ / value); milliseconds_ = static_cast<int>(milliseconds_ / value);
return (*this); return (*this);
} }
easy2d::Duration easy2d::operator*(int value, const Duration & dur) Duration operator*(int value, const Duration & dur)
{ {
return dur * value; return dur * value;
} }
easy2d::Duration easy2d::operator/(int value, const Duration & dur) Duration operator/(int value, const Duration & dur)
{ {
return dur / value; return dur / value;
} }
easy2d::Duration easy2d::operator*(float value, const Duration & dur) Duration operator*(float value, const Duration & dur)
{ {
return dur * value; return dur * value;
} }
easy2d::Duration easy2d::operator/(float value, const Duration & dur) Duration operator/(float value, const Duration & dur)
{ {
return dur / value; return dur / value;
} }
easy2d::Duration easy2d::operator*(double value, const Duration & dur) Duration operator*(double value, const Duration & dur)
{ {
return dur * value; return dur * value;
} }
easy2d::Duration easy2d::operator/(double value, const Duration & dur) Duration operator/(double value, const Duration & dur)
{ {
return dur / value; return dur / value;
} }
}

View File

@ -21,10 +21,13 @@
#include "..\e2dutil.h" #include "..\e2dutil.h"
easy2d::Font::Font(const std::wstring & family, float size, UINT weight, bool italic) namespace easy2d
{
Font::Font(const std::wstring & family, float size, UINT weight, bool italic)
: family(family) : family(family)
, size(size) , size(size)
, weight(weight) , weight(weight)
, italic(italic) , italic(italic)
{ {
} }
}

View File

@ -22,50 +22,52 @@
#include <cmath> #include <cmath>
easy2d::Point::Point() namespace easy2d
{
Point::Point()
{ {
x = 0; x = 0;
y = 0; y = 0;
} }
easy2d::Point::Point(float x, float y) Point::Point(float x, float y)
{ {
this->x = x; this->x = x;
this->y = y; this->y = y;
} }
easy2d::Point::Point(const Point & other) Point::Point(const Point & other)
{ {
x = other.x; x = other.x;
y = other.y; y = other.y;
} }
easy2d::Point easy2d::Point::operator+(const Point & p) const Point Point::operator+(const Point & p) const
{ {
return Point(x + p.x, y + p.y); return Point(x + p.x, y + p.y);
} }
easy2d::Point easy2d::Point::operator-(const Point & p) const Point Point::operator-(const Point & p) const
{ {
return Point(x - p.x, y - p.y); return Point(x - p.x, y - p.y);
} }
easy2d::Point easy2d::Point::operator*(float value) const Point Point::operator*(float value) const
{ {
return Point(x * value, y * value); return Point(x * value, y * value);
} }
easy2d::Point easy2d::Point::operator/(float value) const Point Point::operator/(float value) const
{ {
return Point(x / value, y / value); return Point(x / value, y / value);
} }
easy2d::Point::operator easy2d::Size() const Point::operator Size() const
{ {
return Size(x, y); return Size(x, y);
} }
float easy2d::Point::Distance(const Point &p1, const Point &p2) float 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) +
@ -73,12 +75,13 @@ float easy2d::Point::Distance(const Point &p1, const Point &p2)
); );
} }
easy2d::Point easy2d::Point::operator-() const Point Point::operator-() const
{ {
return Point(-x, -y); return Point(-x, -y);
} }
bool easy2d::Point::operator==(const Point & point) const bool Point::operator==(const Point & point) const
{ {
return (x == point.x) && (y == point.y); return (x == point.x) && (y == point.y);
} }
}

View File

@ -20,9 +20,12 @@
#include "..\e2dutil.h" #include "..\e2dutil.h"
std::default_random_engine &easy2d::Random::GetEngine() namespace easy2d
{
std::default_random_engine &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());
return engine; return engine;
} }
}

View File

@ -20,43 +20,45 @@
#include "..\e2dutil.h" #include "..\e2dutil.h"
easy2d::Rect::Rect(void) namespace easy2d
{
Rect::Rect(void)
: origin() : origin()
, size() , size()
{ {
} }
easy2d::Rect::Rect(float x, float y, float width, float height) Rect::Rect(float x, float y, float width, float height)
: origin(x, y) : origin(x, y)
, size(width, height) , size(width, height)
{ {
} }
easy2d::Rect::Rect(const Point& pos, const Size& size) Rect::Rect(const Point& pos, const Size& size)
: origin(pos.x, pos.y) : origin(pos.x, pos.y)
, size(size.width, size.height) , size(size.width, size.height)
{ {
} }
easy2d::Rect::Rect(const Rect& other) Rect::Rect(const Rect& other)
: origin(other.origin.x, other.origin.y) : origin(other.origin.x, other.origin.y)
, size(other.size.width, other.size.height) , size(other.size.width, other.size.height)
{ {
} }
easy2d::Rect& easy2d::Rect::operator= (const Rect& other) Rect& Rect::operator= (const Rect& other)
{ {
origin = other.origin; origin = other.origin;
size = other.size; size = other.size;
return *this; return *this;
} }
bool easy2d::Rect::operator==(const Rect & rect) const bool Rect::operator==(const Rect & rect) const
{ {
return (origin == rect.origin) && (size == rect.size); return (origin == rect.origin) && (size == rect.size);
} }
bool easy2d::Rect::ContainsPoint(const Point& point) const bool 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))
@ -66,10 +68,11 @@ bool easy2d::Rect::ContainsPoint(const Point& point) const
return false; return false;
} }
bool easy2d::Rect::Intersects(const Rect& rect) const bool 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 ||
(origin.y + size.height) < rect.origin.y || (origin.y + size.height) < rect.origin.y ||
(rect.origin.y + rect.size.height) < origin.y); (rect.origin.y + rect.size.height) < origin.y);
} }
}

View File

@ -20,22 +20,24 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::Ref::Ref() namespace easy2d
{
Ref::Ref()
{ {
// 当对象被创建时,意味着它已经被引用了一次 // 当对象被创建时,意味着它已经被引用了一次
ref_count_ = 1; ref_count_ = 1;
} }
easy2d::Ref::~Ref() Ref::~Ref()
{ {
} }
LONG easy2d::Ref::Retain() LONG Ref::Retain()
{ {
return ::InterlockedIncrement(&ref_count_); return ::InterlockedIncrement(&ref_count_);
} }
LONG easy2d::Ref::Release() LONG Ref::Release()
{ {
LONG new_count = ::InterlockedDecrement(&ref_count_); LONG new_count = ::InterlockedDecrement(&ref_count_);
@ -48,7 +50,8 @@ LONG easy2d::Ref::Release()
return new_count; return new_count;
} }
LONG easy2d::Ref::GetRefCount() const LONG Ref::GetRefCount() const
{ {
return ref_count_; return ref_count_;
} }
}

View File

@ -21,7 +21,9 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
easy2d::Resource::Resource(LPCWSTR name, LPCWSTR type) namespace easy2d
{
Resource::Resource(LPCWSTR name, LPCWSTR type)
: name_(name) : name_(name)
, type_(type) , type_(type)
, data_(nullptr) , data_(nullptr)
@ -30,32 +32,32 @@ easy2d::Resource::Resource(LPCWSTR name, LPCWSTR type)
{ {
} }
LPCWSTR easy2d::Resource::GetName() const LPCWSTR Resource::GetName() const
{ {
return name_; return name_;
} }
LPCWSTR easy2d::Resource::GetType() const LPCWSTR Resource::GetType() const
{ {
return type_; return type_;
} }
LPVOID easy2d::Resource::GetData() const LPVOID Resource::GetData() const
{ {
return data_; return data_;
} }
DWORD easy2d::Resource::GetDataSize() const DWORD Resource::GetDataSize() const
{ {
return data_size_; return data_size_;
} }
size_t easy2d::Resource::GetHashCode() const size_t Resource::GetHashCode() const
{ {
return std::hash<LPCWSTR>{}(name_); return std::hash<LPCWSTR>{}(name_);
} }
bool easy2d::Resource::Load() bool Resource::Load()
{ {
if (!loaded_) if (!loaded_)
{ {
@ -95,3 +97,4 @@ bool easy2d::Resource::Load()
} }
return true; return true;
} }
}

View File

@ -20,55 +20,58 @@
#include "..\e2dutil.h" #include "..\e2dutil.h"
easy2d::Size::Size() namespace easy2d
{
Size::Size()
{ {
width = 0; width = 0;
height = 0; height = 0;
} }
easy2d::Size::Size(float width, float height) Size::Size(float width, float height)
{ {
this->width = width; this->width = width;
this->height = height; this->height = height;
} }
easy2d::Size::Size(const Size & other) Size::Size(const Size & other)
{ {
width = other.width; width = other.width;
height = other.height; height = other.height;
} }
easy2d::Size easy2d::Size::operator+(const Size & other) const Size Size::operator+(const Size & other) const
{ {
return Size(width + other.width, height + other.height); return Size(width + other.width, height + other.height);
} }
easy2d::Size easy2d::Size::operator-(const Size & other) const Size Size::operator-(const Size & other) const
{ {
return Size(width - other.width, height - other.height); return Size(width - other.width, height - other.height);
} }
easy2d::Size easy2d::Size::operator*(float value) const Size Size::operator*(float value) const
{ {
return Size(width * value, height * value); return Size(width * value, height * value);
} }
easy2d::Size easy2d::Size::operator/(float value) const Size Size::operator/(float value) const
{ {
return Size(width / value, height / value); return Size(width / value, height / value);
} }
easy2d::Size::operator easy2d::Point() const Size::operator Point() const
{ {
return Point(width, height); return Point(width, height);
} }
easy2d::Size easy2d::Size::operator-() const Size Size::operator-() const
{ {
return Size(-width, -height); return Size(-width, -height);
} }
bool easy2d::Size::operator==(const Size & other) const bool Size::operator==(const Size & other) const
{ {
return (width == other.width) && (height == other.height); return (width == other.width) && (height == other.height);
} }
}

View File

@ -20,68 +20,70 @@
#include "..\e2dutil.h" #include "..\e2dutil.h"
namespace easy2d
{
using namespace std::chrono; using namespace std::chrono;
easy2d::Time::Time() Time::Time()
{ {
} }
easy2d::Time::Time(std::chrono::steady_clock::time_point time) Time::Time(std::chrono::steady_clock::time_point time)
: time_(time) : time_(time)
{ {
} }
easy2d::Time::Time(const Time & other) Time::Time(const Time & other)
: time_(other.time_) : time_(other.time_)
{ {
} }
easy2d::Time::Time(Time && other) Time::Time(Time && other)
: time_(std::move(other.time_)) : time_(std::move(other.time_))
{ {
} }
time_t easy2d::Time::GetTimeStamp() const time_t Time::GetTimeStamp() const
{ {
auto& duration = time_point_cast<milliseconds>(time_).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 easy2d::Time::IsZero() const bool Time::IsZero() const
{ {
return time_.time_since_epoch().count() == 0LL; return time_.time_since_epoch().count() == 0LL;
} }
easy2d::Time easy2d::Time::operator+(const Duration & other) const Time Time::operator+(const Duration & other) const
{ {
return Time(time_ + milliseconds(other.Milliseconds())); return Time(time_ + milliseconds(other.Milliseconds()));
} }
easy2d::Time easy2d::Time::operator-(const Duration & other) const Time Time::operator-(const Duration & other) const
{ {
return Time(time_ - milliseconds(other.Milliseconds())); return Time(time_ - milliseconds(other.Milliseconds()));
} }
easy2d::Time & easy2d::Time::operator+=(const Duration & other) Time & Time::operator+=(const Duration & other)
{ {
time_ += milliseconds(other.Milliseconds()); time_ += milliseconds(other.Milliseconds());
return (*this); return (*this);
} }
easy2d::Time & easy2d::Time::operator-=(const Duration &other) Time & Time::operator-=(const Duration &other)
{ {
time_ -= milliseconds(other.Milliseconds()); time_ -= milliseconds(other.Milliseconds());
return (*this); return (*this);
} }
easy2d::Duration easy2d::Time::operator-(const Time & other) const Duration Time::operator-(const Time & other) const
{ {
auto ms = duration_cast<milliseconds>(time_ - other.time_).count(); auto ms = duration_cast<milliseconds>(time_ - other.time_).count();
return Duration(static_cast<int>(ms)); return Duration(static_cast<int>(ms));
} }
easy2d::Time& easy2d::Time::operator=(const Time & other) E2D_NOEXCEPT Time& Time::operator=(const Time & other) E2D_NOEXCEPT
{ {
if (this == &other) if (this == &other)
return *this; return *this;
@ -90,7 +92,7 @@ easy2d::Time& easy2d::Time::operator=(const Time & other) E2D_NOEXCEPT
return *this; return *this;
} }
easy2d::Time& easy2d::Time::operator=(Time && other) E2D_NOEXCEPT Time& Time::operator=(Time && other) E2D_NOEXCEPT
{ {
if (this == &other) if (this == &other)
return *this; return *this;
@ -99,7 +101,8 @@ easy2d::Time& easy2d::Time::operator=(Time && other) E2D_NOEXCEPT
return *this; return *this;
} }
easy2d::Time easy2d::Time::Now() Time Time::Now()
{ {
return Time(steady_clock::now()); return Time(steady_clock::now());
} }
}

View File

@ -21,7 +21,9 @@
#include "..\e2dutil.h" #include "..\e2dutil.h"
easy2d::Transform::Transform() namespace easy2d
{
Transform::Transform()
: position() : position()
, size() , size()
, scale_x(1.f) , scale_x(1.f)
@ -34,7 +36,7 @@ easy2d::Transform::Transform()
{ {
} }
easy2d::Transform::operator D2D1::Matrix3x2F() const Transform::operator D2D1::Matrix3x2F() const
{ {
auto pivot = D2D1::Point2F(size.width * pivot_x, size.height * pivot_y); auto pivot = D2D1::Point2F(size.width * pivot_x, size.height * pivot_y);
auto matrix = D2D1::Matrix3x2F::Scale( auto matrix = D2D1::Matrix3x2F::Scale(
@ -55,7 +57,7 @@ easy2d::Transform::operator D2D1::Matrix3x2F() const
return matrix; return matrix;
} }
bool easy2d::Transform::operator==(const Transform & other) const bool Transform::operator==(const Transform & other) const
{ {
return position == other.position && return position == other.position &&
size == other.size && size == other.size &&
@ -67,3 +69,4 @@ bool easy2d::Transform::operator==(const Transform & other) const
pivot_x == other.pivot_x && pivot_x == other.pivot_x &&
pivot_y == other.pivot_y; pivot_y == other.pivot_y;
} }
}