update: code style
This commit is contained in:
parent
0f1ba104dd
commit
b129a1bf18
|
|
@ -20,86 +20,90 @@
|
||||||
|
|
||||||
#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)
|
||||||
, target_(nullptr)
|
, target_(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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_)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Action::ResetTime()
|
void Action::ResetTime()
|
||||||
{
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,31 +21,33 @@
|
||||||
#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_)
|
||||||
{
|
{
|
||||||
if (animation_)
|
if (animation_)
|
||||||
|
|
@ -56,10 +58,10 @@ void easy2d::Animate::SetAnimation(Animation * animation)
|
||||||
animation_->Retain();
|
animation_->Retain();
|
||||||
frame_index_ = 0;
|
frame_index_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Animate::Init()
|
void Animate::Init()
|
||||||
{
|
{
|
||||||
Action::Init();
|
Action::Init();
|
||||||
|
|
||||||
auto target = dynamic_cast<Sprite*>(target_);
|
auto target = dynamic_cast<Sprite*>(target_);
|
||||||
|
|
@ -68,10 +70,10 @@ void easy2d::Animate::Init()
|
||||||
target->Load(animation_->GetFrames()[frame_index_]);
|
target->Load(animation_->GetFrames()[frame_index_]);
|
||||||
++frame_index_;
|
++frame_index_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Animate::Update()
|
void Animate::Update()
|
||||||
{
|
{
|
||||||
Action::Update();
|
Action::Update();
|
||||||
|
|
||||||
if (!animation_)
|
if (!animation_)
|
||||||
|
|
@ -99,30 +101,30 @@ void easy2d::Animate::Update()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_)
|
||||||
{
|
{
|
||||||
return new Animate(animation_);
|
return new Animate(animation_);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Animate * easy2d::Animate::Reverse() const
|
Animate * Animate::Reverse() const
|
||||||
{
|
{
|
||||||
if (animation_)
|
if (animation_)
|
||||||
{
|
{
|
||||||
auto animation = animation_->Reverse();
|
auto animation = animation_->Reverse();
|
||||||
|
|
@ -132,4 +134,5 @@ easy2d::Animate * easy2d::Animate::Reverse() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,71 +20,73 @@
|
||||||
|
|
||||||
#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_)
|
||||||
{
|
{
|
||||||
SafeRelease(frame);
|
SafeRelease(frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
frames_.push_back(frame);
|
frames_.push_back(frame);
|
||||||
frame->Retain();
|
frame->Retain();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Animation::Add(const Images& frames)
|
void Animation::Add(const Images& frames)
|
||||||
{
|
{
|
||||||
for (const auto &image : frames)
|
for (const auto &image : frames)
|
||||||
{
|
{
|
||||||
this->Add(image);
|
this->Add(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
@ -94,10 +96,10 @@ 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());
|
||||||
|
|
||||||
|
|
@ -117,4 +119,5 @@ easy2d::Animation * easy2d::Animation::Reverse() const
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Animation(this->GetInterval(), frames);
|
return new Animation(this->GetInterval(), frames);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,35 +20,37 @@
|
||||||
|
|
||||||
#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();
|
||||||
|
|
||||||
delta_ = (Time::Now() - started_).Seconds();
|
delta_ = (Time::Now() - started_).Seconds();
|
||||||
|
|
@ -57,10 +59,11 @@ void easy2d::Delay::Update()
|
||||||
{
|
{
|
||||||
this->Stop();
|
this->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Delay::ResetTime()
|
void Delay::ResetTime()
|
||||||
{
|
{
|
||||||
Action::ResetTime();
|
Action::ResetTime();
|
||||||
started_ = Time::Now() - Duration::Second * delta_;
|
started_ = Time::Now() - Duration::Second * delta_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,7 +20,10 @@
|
||||||
|
|
||||||
#include "..\e2daction.h"
|
#include "..\e2daction.h"
|
||||||
|
|
||||||
easy2d::FadeIn::FadeIn(float duration)
|
namespace easy2d
|
||||||
: OpacityTo(duration, 1)
|
|
||||||
{
|
{
|
||||||
|
FadeIn::FadeIn(float duration)
|
||||||
|
: OpacityTo(duration, 1)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,7 +20,10 @@
|
||||||
|
|
||||||
#include "..\e2daction.h"
|
#include "..\e2daction.h"
|
||||||
|
|
||||||
easy2d::FadeOut::FadeOut(float duration)
|
namespace easy2d
|
||||||
: OpacityTo(duration, 0)
|
|
||||||
{
|
{
|
||||||
|
FadeOut::FadeOut(float duration)
|
||||||
|
: OpacityTo(duration, 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,25 +20,27 @@
|
||||||
|
|
||||||
#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();
|
||||||
|
|
||||||
if (duration_ == 0)
|
if (duration_ == 0)
|
||||||
|
|
@ -55,10 +57,11 @@ void easy2d::FiniteTimeAction::Update()
|
||||||
this->Stop();
|
this->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,36 +21,38 @@
|
||||||
#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)
|
||||||
, jumps_(jumps)
|
, jumps_(jumps)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
if (target_)
|
if (target_)
|
||||||
{
|
{
|
||||||
prev_pos_ = start_pos_ = target_->GetPosition();
|
prev_pos_ = start_pos_ = target_->GetPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::JumpBy::Update()
|
void JumpBy::Update()
|
||||||
{
|
{
|
||||||
FiniteTimeAction::Update();
|
FiniteTimeAction::Update();
|
||||||
|
|
||||||
if (target_)
|
if (target_)
|
||||||
|
|
@ -70,4 +72,5 @@ void easy2d::JumpBy::Update()
|
||||||
|
|
||||||
prev_pos_ = newPos;
|
prev_pos_ = newPos;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,11 +20,13 @@
|
||||||
|
|
||||||
#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)
|
||||||
{
|
{
|
||||||
E2D_WARNING_IF(action == nullptr, "Loop NULL pointer exception!");
|
E2D_WARNING_IF(action == nullptr, "Loop NULL pointer exception!");
|
||||||
|
|
||||||
if (action)
|
if (action)
|
||||||
|
|
@ -32,15 +34,15 @@ easy2d::Loop::Loop(Action * action, int times /* = -1 */)
|
||||||
action_ = action;
|
action_ = action;
|
||||||
action_->Retain();
|
action_->Retain();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Loop::~Loop()
|
Loop::~Loop()
|
||||||
{
|
{
|
||||||
SafeRelease(action_);
|
SafeRelease(action_);
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Loop * easy2d::Loop::Clone() const
|
Loop * Loop::Clone() const
|
||||||
{
|
{
|
||||||
if (action_)
|
if (action_)
|
||||||
{
|
{
|
||||||
return new Loop(action_->Clone());
|
return new Loop(action_->Clone());
|
||||||
|
|
@ -49,10 +51,10 @@ easy2d::Loop * easy2d::Loop::Clone() const
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Loop * easy2d::Loop::Reverse() const
|
Loop * Loop::Reverse() const
|
||||||
{
|
{
|
||||||
if (action_)
|
if (action_)
|
||||||
{
|
{
|
||||||
return new Loop(action_->Clone());
|
return new Loop(action_->Clone());
|
||||||
|
|
@ -61,10 +63,10 @@ easy2d::Loop * easy2d::Loop::Reverse() const
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Loop::Init()
|
void Loop::Init()
|
||||||
{
|
{
|
||||||
Action::Init();
|
Action::Init();
|
||||||
|
|
||||||
if (action_)
|
if (action_)
|
||||||
|
|
@ -72,10 +74,10 @@ void easy2d::Loop::Init()
|
||||||
action_->target_ = target_;
|
action_->target_ = target_;
|
||||||
action_->Init();
|
action_->Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Loop::Update()
|
void Loop::Update()
|
||||||
{
|
{
|
||||||
Action::Update();
|
Action::Update();
|
||||||
|
|
||||||
if (times_ == total_times_)
|
if (times_ == total_times_)
|
||||||
|
|
@ -100,17 +102,18 @@ void easy2d::Loop::Update()
|
||||||
{
|
{
|
||||||
this->Stop();
|
this->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Loop::Reset()
|
void Loop::Reset()
|
||||||
{
|
{
|
||||||
Action::Reset();
|
Action::Reset();
|
||||||
|
|
||||||
if (action_) action_->Reset();
|
if (action_) action_->Reset();
|
||||||
times_ = 0;
|
times_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Loop::ResetTime()
|
void Loop::ResetTime()
|
||||||
{
|
{
|
||||||
if (action_) action_->ResetTime();
|
if (action_) action_->ResetTime();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,24 +22,26 @@
|
||||||
#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();
|
||||||
|
|
||||||
if (target_)
|
if (target_)
|
||||||
{
|
{
|
||||||
prev_pos_ = start_pos_ = target_->GetPosition();
|
prev_pos_ = start_pos_ = target_->GetPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::MoveBy::Update()
|
void MoveBy::Update()
|
||||||
{
|
{
|
||||||
FiniteTimeAction::Update();
|
FiniteTimeAction::Update();
|
||||||
|
|
||||||
if (target_)
|
if (target_)
|
||||||
|
|
@ -53,14 +55,15 @@ void easy2d::MoveBy::Update()
|
||||||
|
|
||||||
prev_pos_ = newPos;
|
prev_pos_ = newPos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,38 +22,41 @@
|
||||||
#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();
|
||||||
|
|
||||||
if (target_)
|
if (target_)
|
||||||
{
|
{
|
||||||
start_val_ = target_->GetOpacity();
|
start_val_ = target_->GetOpacity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::OpacityBy::Update()
|
void OpacityBy::Update()
|
||||||
{
|
{
|
||||||
FiniteTimeAction::Update();
|
FiniteTimeAction::Update();
|
||||||
|
|
||||||
if (target_)
|
if (target_)
|
||||||
{
|
{
|
||||||
target_->SetOpacity(start_val_ + delta_val_ * delta_);
|
target_->SetOpacity(start_val_ + delta_val_ * delta_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,38 +22,41 @@
|
||||||
#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();
|
||||||
|
|
||||||
if (target_)
|
if (target_)
|
||||||
{
|
{
|
||||||
start_val_ = target_->GetRotation();
|
start_val_ = target_->GetRotation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::RotateBy::Update()
|
void RotateBy::Update()
|
||||||
{
|
{
|
||||||
FiniteTimeAction::Update();
|
FiniteTimeAction::Update();
|
||||||
|
|
||||||
if (target_)
|
if (target_)
|
||||||
{
|
{
|
||||||
target_->SetRotation(start_val_ + delta_val_ * delta_);
|
target_->SetRotation(start_val_ + delta_val_ * delta_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,22 +22,24 @@
|
||||||
#include "..\e2dobject.h"
|
#include "..\e2dobject.h"
|
||||||
|
|
||||||
|
|
||||||
easy2d::ScaleBy::ScaleBy(float duration, float scale)
|
namespace easy2d
|
||||||
: FiniteTimeAction(duration)
|
|
||||||
{
|
{
|
||||||
|
ScaleBy::ScaleBy(float duration, float scale)
|
||||||
|
: 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();
|
||||||
|
|
||||||
if (target_)
|
if (target_)
|
||||||
|
|
@ -45,24 +47,25 @@ void easy2d::ScaleBy::Init()
|
||||||
start_scale_x_ = target_->GetScaleX();
|
start_scale_x_ = target_->GetScaleX();
|
||||||
start_scale_y_ = target_->GetScaleY();
|
start_scale_y_ = target_->GetScaleY();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::ScaleBy::Update()
|
void ScaleBy::Update()
|
||||||
{
|
{
|
||||||
FiniteTimeAction::Update();
|
FiniteTimeAction::Update();
|
||||||
|
|
||||||
if (target_)
|
if (target_)
|
||||||
{
|
{
|
||||||
target_->SetScale(start_scale_x_ + delta_x_ * delta_, start_scale_y_ + delta_y_ * delta_);
|
target_->SetScale(start_scale_x_ + delta_x_ * delta_, start_scale_y_ + delta_y_ * delta_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,28 +21,32 @@
|
||||||
#include "..\e2daction.h"
|
#include "..\e2daction.h"
|
||||||
#include "..\e2dobject.h"
|
#include "..\e2dobject.h"
|
||||||
|
|
||||||
easy2d::ScaleTo::ScaleTo(float duration, float scale)
|
|
||||||
: ScaleBy(duration, 0, 0)
|
namespace easy2d
|
||||||
{
|
{
|
||||||
|
ScaleTo::ScaleTo(float duration, float scale)
|
||||||
|
: 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_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,27 +20,30 @@
|
||||||
|
|
||||||
#include "..\e2daction.h"
|
#include "..\e2daction.h"
|
||||||
|
|
||||||
easy2d::Sequence::Sequence()
|
|
||||||
: action_index_(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
easy2d::Sequence::Sequence(const Actions& actions)
|
namespace easy2d
|
||||||
: action_index_(0)
|
|
||||||
{
|
{
|
||||||
|
Sequence::Sequence()
|
||||||
|
: action_index_(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Sequence::Sequence(const Actions& actions)
|
||||||
|
: action_index_(0)
|
||||||
|
{
|
||||||
this->Add(actions);
|
this->Add(actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Sequence::~Sequence()
|
Sequence::~Sequence()
|
||||||
{
|
{
|
||||||
for (auto action : actions_)
|
for (auto action : actions_)
|
||||||
{
|
{
|
||||||
SafeRelease(action);
|
SafeRelease(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Sequence::Init()
|
void Sequence::Init()
|
||||||
{
|
{
|
||||||
Action::Init();
|
Action::Init();
|
||||||
// 将所有动作与目标绑定
|
// 将所有动作与目标绑定
|
||||||
if (target_)
|
if (target_)
|
||||||
|
|
@ -52,10 +55,10 @@ void easy2d::Sequence::Init()
|
||||||
}
|
}
|
||||||
// 初始化第一个动作
|
// 初始化第一个动作
|
||||||
actions_[0]->Init();
|
actions_[0]->Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Sequence::Update()
|
void Sequence::Update()
|
||||||
{
|
{
|
||||||
Action::Update();
|
Action::Update();
|
||||||
|
|
||||||
auto &action = actions_[action_index_];
|
auto &action = actions_[action_index_];
|
||||||
|
|
@ -73,45 +76,45 @@ void easy2d::Sequence::Update()
|
||||||
actions_[action_index_]->Init();
|
actions_[action_index_]->Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Sequence::Reset()
|
void Sequence::Reset()
|
||||||
{
|
{
|
||||||
Action::Reset();
|
Action::Reset();
|
||||||
for (const auto& action : actions_)
|
for (const auto& action : actions_)
|
||||||
{
|
{
|
||||||
action->Reset();
|
action->Reset();
|
||||||
}
|
}
|
||||||
action_index_ = 0;
|
action_index_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Sequence::ResetTime()
|
void Sequence::ResetTime()
|
||||||
{
|
{
|
||||||
for (const auto& action : actions_)
|
for (const auto& action : actions_)
|
||||||
{
|
{
|
||||||
action->ResetTime();
|
action->ResetTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Sequence::Add(Action * action)
|
void Sequence::Add(Action * action)
|
||||||
{
|
{
|
||||||
if (action)
|
if (action)
|
||||||
{
|
{
|
||||||
actions_.push_back(action);
|
actions_.push_back(action);
|
||||||
action->Retain();
|
action->Retain();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Sequence::Add(const Actions& actions)
|
void Sequence::Add(const Actions& actions)
|
||||||
{
|
{
|
||||||
for (const auto &action : actions)
|
for (const auto &action : actions)
|
||||||
{
|
{
|
||||||
this->Add(action);
|
this->Add(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_)
|
||||||
{
|
{
|
||||||
|
|
@ -121,10 +124,10 @@ 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())
|
||||||
{
|
{
|
||||||
|
|
@ -136,4 +139,5 @@ easy2d::Sequence * easy2d::Sequence::Reverse() const
|
||||||
sequence->Add(newActions);
|
sequence->Add(newActions);
|
||||||
}
|
}
|
||||||
return sequence;
|
return sequence;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,25 +20,28 @@
|
||||||
|
|
||||||
#include "..\e2daction.h"
|
#include "..\e2daction.h"
|
||||||
|
|
||||||
easy2d::Spawn::Spawn()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
easy2d::Spawn::Spawn(const Actions& actions)
|
namespace easy2d
|
||||||
{
|
{
|
||||||
|
Spawn::Spawn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Spawn::Spawn(const Actions& actions)
|
||||||
|
{
|
||||||
this->Add(actions);
|
this->Add(actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Spawn::~Spawn()
|
Spawn::~Spawn()
|
||||||
{
|
{
|
||||||
for (auto action : actions_)
|
for (auto action : actions_)
|
||||||
{
|
{
|
||||||
SafeRelease(action);
|
SafeRelease(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Spawn::Init()
|
void Spawn::Init()
|
||||||
{
|
{
|
||||||
Action::Init();
|
Action::Init();
|
||||||
|
|
||||||
if (target_)
|
if (target_)
|
||||||
|
|
@ -49,10 +52,10 @@ void easy2d::Spawn::Init()
|
||||||
action->Init();
|
action->Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Spawn::Update()
|
void Spawn::Update()
|
||||||
{
|
{
|
||||||
Action::Update();
|
Action::Update();
|
||||||
|
|
||||||
size_t done_num = 0;
|
size_t done_num = 0;
|
||||||
|
|
@ -72,44 +75,44 @@ void easy2d::Spawn::Update()
|
||||||
{
|
{
|
||||||
this->Stop();
|
this->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Spawn::Reset()
|
void Spawn::Reset()
|
||||||
{
|
{
|
||||||
Action::Reset();
|
Action::Reset();
|
||||||
for (const auto& action : actions_)
|
for (const auto& action : actions_)
|
||||||
{
|
{
|
||||||
action->Reset();
|
action->Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Spawn::ResetTime()
|
void Spawn::ResetTime()
|
||||||
{
|
{
|
||||||
for (const auto& action : actions_)
|
for (const auto& action : actions_)
|
||||||
{
|
{
|
||||||
action->ResetTime();
|
action->ResetTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Spawn::Add(Action * action)
|
void Spawn::Add(Action * action)
|
||||||
{
|
{
|
||||||
if (action)
|
if (action)
|
||||||
{
|
{
|
||||||
actions_.push_back(action);
|
actions_.push_back(action);
|
||||||
action->Retain();
|
action->Retain();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Spawn::Add(const Actions& actions)
|
void Spawn::Add(const Actions& actions)
|
||||||
{
|
{
|
||||||
for (const auto &action : actions)
|
for (const auto &action : actions)
|
||||||
{
|
{
|
||||||
this->Add(action);
|
this->Add(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_)
|
||||||
{
|
{
|
||||||
|
|
@ -119,10 +122,10 @@ 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())
|
||||||
{
|
{
|
||||||
|
|
@ -134,4 +137,5 @@ easy2d::Spawn * easy2d::Spawn::Reverse() const
|
||||||
spawn->Add(newActions);
|
spawn->Add(newActions);
|
||||||
}
|
}
|
||||||
return spawn;
|
return spawn;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -46,10 +48,10 @@ easy2d::Button::Button()
|
||||||
, mouseover_(nullptr)
|
, mouseover_(nullptr)
|
||||||
, selected_(nullptr)
|
, selected_(nullptr)
|
||||||
, disabled_(nullptr)
|
, disabled_(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|
@ -58,12 +60,12 @@ easy2d::Button::Button(Node * normal, const Callback& func)
|
||||||
, mouseover_(nullptr)
|
, mouseover_(nullptr)
|
||||||
, selected_(nullptr)
|
, selected_(nullptr)
|
||||||
, disabled_(nullptr)
|
, disabled_(nullptr)
|
||||||
{
|
{
|
||||||
this->SetNormal(normal);
|
this->SetNormal(normal);
|
||||||
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)
|
||||||
|
|
@ -72,13 +74,13 @@ easy2d::Button::Button(Node * normal, Node * selected, const Callback& func)
|
||||||
, mouseover_(nullptr)
|
, mouseover_(nullptr)
|
||||||
, selected_(nullptr)
|
, selected_(nullptr)
|
||||||
, disabled_(nullptr)
|
, disabled_(nullptr)
|
||||||
{
|
{
|
||||||
this->SetNormal(normal);
|
this->SetNormal(normal);
|
||||||
this->SetSelected(selected);
|
this->SetSelected(selected);
|
||||||
this->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)
|
||||||
|
|
@ -87,14 +89,14 @@ easy2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const C
|
||||||
, mouseover_(nullptr)
|
, mouseover_(nullptr)
|
||||||
, selected_(nullptr)
|
, selected_(nullptr)
|
||||||
, disabled_(nullptr)
|
, disabled_(nullptr)
|
||||||
{
|
{
|
||||||
this->SetNormal(normal);
|
this->SetNormal(normal);
|
||||||
this->SetMouseOver(mouseover);
|
this->SetMouseOver(mouseover);
|
||||||
this->SetSelected(selected);
|
this->SetSelected(selected);
|
||||||
this->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)
|
||||||
|
|
@ -103,68 +105,68 @@ easy2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node *
|
||||||
, mouseover_(nullptr)
|
, mouseover_(nullptr)
|
||||||
, selected_(nullptr)
|
, selected_(nullptr)
|
||||||
, disabled_(nullptr)
|
, disabled_(nullptr)
|
||||||
{
|
{
|
||||||
this->SetNormal(normal);
|
this->SetNormal(normal);
|
||||||
this->SetMouseOver(mouseover);
|
this->SetMouseOver(mouseover);
|
||||||
this->SetSelected(selected);
|
this->SetSelected(selected);
|
||||||
this->SetDisabled(disabled);
|
this->SetDisabled(disabled);
|
||||||
this->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)
|
||||||
{
|
{
|
||||||
this->SetSize(normal->GetWidth(), normal->GetHeight());
|
this->SetSize(normal->GetWidth(), normal->GetHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
enabled_ = enabled;
|
enabled_ = enabled;
|
||||||
UpdateVisible();
|
UpdateVisible();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
SAFE_SET(mouseover_, SetPivot, pivot_x, pivot_y);
|
SAFE_SET(mouseover_, SetPivot, pivot_x, pivot_y);
|
||||||
SAFE_SET(selected_, SetPivot, pivot_x, pivot_y);
|
SAFE_SET(selected_, SetPivot, pivot_x, 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_)
|
||||||
{
|
{
|
||||||
bool contains = normal_->ContainsPoint(e.GetPosition());
|
bool contains = normal_->ContainsPoint(e.GetPosition());
|
||||||
|
|
@ -210,10 +212,10 @@ 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();
|
||||||
|
|
||||||
if (IsVisible() &&
|
if (IsVisible() &&
|
||||||
|
|
@ -235,19 +237,19 @@ void easy2d::Button::Visit()
|
||||||
::SetCursor(hcursor);
|
::SetCursor(hcursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Button::SetStatus(Status status)
|
void Button::SetStatus(Status status)
|
||||||
{
|
{
|
||||||
if (status_ != status)
|
if (status_ != status)
|
||||||
{
|
{
|
||||||
status_ = status;
|
status_ = status;
|
||||||
UpdateVisible();
|
UpdateVisible();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
SAFE_SET(selected_, SetVisible, false);
|
SAFE_SET(selected_, SetVisible, false);
|
||||||
|
|
@ -279,4 +281,5 @@ void easy2d::Button::UpdateVisible()
|
||||||
if (normal_) normal_->SetVisible(true);
|
if (normal_) normal_->SetVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,32 +20,35 @@
|
||||||
|
|
||||||
#include "..\e2dcomponent.h"
|
#include "..\e2dcomponent.h"
|
||||||
|
|
||||||
easy2d::Menu::Menu()
|
|
||||||
: enabled_(true)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
easy2d::Menu::Menu(const std::vector<Button*>& buttons)
|
namespace easy2d
|
||||||
: enabled_(true)
|
|
||||||
{
|
{
|
||||||
|
Menu::Menu()
|
||||||
|
: enabled_(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu::Menu(const std::vector<Button*>& buttons)
|
||||||
|
: enabled_(true)
|
||||||
|
{
|
||||||
for (const auto& button : buttons)
|
for (const auto& button : buttons)
|
||||||
{
|
{
|
||||||
this->AddButton(button);
|
this->AddButton(button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
enabled_ = enabled;
|
enabled_ = enabled;
|
||||||
|
|
@ -55,20 +58,20 @@ void easy2d::Menu::SetEnabled(bool enabled)
|
||||||
button->SetEnabled(enabled);
|
button->SetEnabled(enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Menu::AddButton(Button * button)
|
void Menu::AddButton(Button * button)
|
||||||
{
|
{
|
||||||
if (button)
|
if (button)
|
||||||
{
|
{
|
||||||
this->AddChild(button);
|
this->AddChild(button);
|
||||||
buttons_.push_back(button);
|
buttons_.push_back(button);
|
||||||
button->SetEnabled(enabled_);
|
button->SetEnabled(enabled_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool easy2d::Menu::RemoveButton(Button * button)
|
bool Menu::RemoveButton(Button * button)
|
||||||
{
|
{
|
||||||
if (buttons_.empty())
|
if (buttons_.empty())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -88,9 +91,10 @@ 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_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,17 @@
|
||||||
#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_)
|
||||||
{
|
{
|
||||||
case 'A': return KeyCode::A;
|
case 'A': return KeyCode::A;
|
||||||
|
|
@ -87,14 +89,15 @@ easy2d::KeyCode easy2d::KeyEvent::GetCode() const
|
||||||
case VK_ESCAPE: return KeyCode::Esc;
|
case VK_ESCAPE: return KeyCode::Esc;
|
||||||
default: return KeyCode::Unknown;
|
default: return KeyCode::Unknown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,65 +21,68 @@
|
||||||
#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(
|
||||||
((float)(short)LOWORD(l_param_)) * 96.f / dpi,
|
((float)(short)LOWORD(l_param_)) * 96.f / dpi,
|
||||||
((float)(short)HIWORD(l_param_)) * 96.f / dpi
|
((float)(short)HIWORD(l_param_)) * 96.f / dpi
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,10 +21,12 @@
|
||||||
#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)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(
|
ThrowIfFailed(
|
||||||
MFStartup(MF_VERSION)
|
MFStartup(MF_VERSION)
|
||||||
);
|
);
|
||||||
|
|
@ -36,10 +38,10 @@ easy2d::Audio::Audio()
|
||||||
ThrowIfFailed(
|
ThrowIfFailed(
|
||||||
x_audio2_->CreateMasteringVoice(&mastering_voice_)
|
x_audio2_->CreateMasteringVoice(&mastering_voice_)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Audio::~Audio()
|
Audio::~Audio()
|
||||||
{
|
{
|
||||||
if (mastering_voice_)
|
if (mastering_voice_)
|
||||||
{
|
{
|
||||||
mastering_voice_->DestroyVoice();
|
mastering_voice_->DestroyVoice();
|
||||||
|
|
@ -49,19 +51,20 @@ easy2d::Audio::~Audio()
|
||||||
SafeRelease(x_audio2_);
|
SafeRelease(x_audio2_);
|
||||||
|
|
||||||
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,34 +20,40 @@
|
||||||
|
|
||||||
#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)
|
||||||
{
|
{
|
||||||
delete audio_device;
|
delete audio_device;
|
||||||
|
|
@ -65,4 +71,5 @@ void easy2d::Device::Destroy()
|
||||||
delete graphics_device;
|
delete graphics_device;
|
||||||
graphics_device = nullptr;
|
graphics_device = nullptr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -30,14 +30,19 @@
|
||||||
#define REGISTER_CLASS L"Easy2DApp"
|
#define REGISTER_CLASS L"Easy2DApp"
|
||||||
|
|
||||||
|
|
||||||
static easy2d::Game * instance = nullptr;
|
namespace easy2d
|
||||||
|
|
||||||
easy2d::Game * easy2d::Game::GetInstance()
|
|
||||||
{
|
{
|
||||||
return instance;
|
namespace
|
||||||
}
|
{
|
||||||
|
Game * instance = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
easy2d::Game::Game()
|
Game * Game::GetInstance()
|
||||||
|
{
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game::Game()
|
||||||
: hwnd_(nullptr)
|
: hwnd_(nullptr)
|
||||||
, quit_(true)
|
, quit_(true)
|
||||||
, curr_scene_(nullptr)
|
, curr_scene_(nullptr)
|
||||||
|
|
@ -48,7 +53,7 @@ easy2d::Game::Game()
|
||||||
, height_(480)
|
, height_(480)
|
||||||
, icon_(0)
|
, icon_(0)
|
||||||
, debug_mode_(false)
|
, debug_mode_(false)
|
||||||
{
|
{
|
||||||
if (instance)
|
if (instance)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("同时只能存在一个游戏实例");
|
throw std::runtime_error("同时只能存在一个游戏实例");
|
||||||
|
|
@ -56,10 +61,10 @@ easy2d::Game::Game()
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
::CoInitialize(nullptr);
|
::CoInitialize(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Game::~Game()
|
Game::~Game()
|
||||||
{
|
{
|
||||||
SafeRelease(transition_);
|
SafeRelease(transition_);
|
||||||
SafeRelease(curr_scene_);
|
SafeRelease(curr_scene_);
|
||||||
SafeRelease(next_scene_);
|
SafeRelease(next_scene_);
|
||||||
|
|
@ -76,10 +81,10 @@ easy2d::Game::~Game()
|
||||||
instance = nullptr;
|
instance = nullptr;
|
||||||
|
|
||||||
::CoUninitialize();
|
::CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Game::Run()
|
void Game::Run()
|
||||||
{
|
{
|
||||||
// 初始化
|
// 初始化
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
|
|
@ -134,15 +139,15 @@ 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)
|
||||||
{
|
{
|
||||||
E2D_WARNING("Next scene is null pointer!");
|
E2D_WARNING("Next scene is null pointer!");
|
||||||
|
|
@ -170,20 +175,20 @@ void easy2d::Game::EnterScene(Scene * scene, Transition * transition)
|
||||||
|
|
||||||
transition_->Init(curr_scene_, next_scene_, this);
|
transition_->Init(curr_scene_, next_scene_, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
if (scene)
|
if (scene)
|
||||||
|
|
@ -228,10 +233,10 @@ void easy2d::Game::UpdateScene(float dt)
|
||||||
curr_scene_ = next_scene_;
|
curr_scene_ = next_scene_;
|
||||||
next_scene_ = nullptr;
|
next_scene_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Game::DrawScene()
|
void Game::DrawScene()
|
||||||
{
|
{
|
||||||
auto graphics = Device::GetGraphics();
|
auto graphics = Device::GetGraphics();
|
||||||
graphics->BeginDraw();
|
graphics->BeginDraw();
|
||||||
|
|
||||||
|
|
@ -262,10 +267,10 @@ void easy2d::Game::DrawScene()
|
||||||
graphics->DrawDebugInfo();
|
graphics->DrawDebugInfo();
|
||||||
}
|
}
|
||||||
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 };
|
||||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||||
|
|
@ -368,10 +373,10 @@ 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);
|
||||||
|
|
||||||
|
|
@ -394,38 +399,38 @@ easy2d::Rect easy2d::Game::Locate(int width, int height)
|
||||||
static_cast<float>(width),
|
static_cast<float>(width),
|
||||||
static_cast<float>(height)
|
static_cast<float>(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;
|
||||||
|
|
||||||
|
|
@ -444,20 +449,20 @@ void easy2d::Game::SetSize(int width, int height)
|
||||||
TRUE
|
TRUE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Game::SetTitle(const std::wstring& title)
|
void Game::SetTitle(const std::wstring& title)
|
||||||
{
|
{
|
||||||
title_ = title;
|
title_ = title;
|
||||||
|
|
||||||
if (hwnd_)
|
if (hwnd_)
|
||||||
{
|
{
|
||||||
::SetWindowText(hwnd_, title.c_str());
|
::SetWindowText(hwnd_, title.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Game::SetIcon(int resource_id)
|
void Game::SetIcon(int resource_id)
|
||||||
{
|
{
|
||||||
icon_ = resource_id;
|
icon_ = resource_id;
|
||||||
|
|
||||||
if (hwnd_)
|
if (hwnd_)
|
||||||
|
|
@ -475,16 +480,16 @@ void easy2d::Game::SetIcon(int resource_id)
|
||||||
::SendMessage(hwnd_, WM_SETICON, ICON_BIG, (LPARAM)icon);
|
::SendMessage(hwnd_, WM_SETICON, ICON_BIG, (LPARAM)icon);
|
||||||
::SendMessage(hwnd_, WM_SETICON, ICON_SMALL, (LPARAM)icon);
|
::SendMessage(hwnd_, WM_SETICON, ICON_SMALL, (LPARAM)icon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
Game * game = reinterpret_cast<Game*>(
|
Game * game = reinterpret_cast<Game*>(
|
||||||
|
|
@ -616,4 +621,5 @@ LRESULT easy2d::Game::WndProc(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_para
|
||||||
result = ::DefWindowProc(hwnd, msg, w_param, l_param);
|
result = ::DefWindowProc(hwnd, msg, w_param, l_param);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -521,7 +527,7 @@ easy2d::Graphics::Graphics(HWND hwnd)
|
||||||
, solid_brush_(nullptr)
|
, solid_brush_(nullptr)
|
||||||
, text_renderer_(nullptr)
|
, text_renderer_(nullptr)
|
||||||
, clear_color_(D2D1::ColorF(D2D1::ColorF::Black))
|
, clear_color_(D2D1::ColorF(D2D1::ColorF::Black))
|
||||||
{
|
{
|
||||||
ThrowIfFailed(
|
ThrowIfFailed(
|
||||||
D2D1CreateFactory(
|
D2D1CreateFactory(
|
||||||
D2D1_FACTORY_TYPE_SINGLE_THREADED,
|
D2D1_FACTORY_TYPE_SINGLE_THREADED,
|
||||||
|
|
@ -585,10 +591,10 @@ easy2d::Graphics::Graphics(HWND hwnd)
|
||||||
solid_brush_
|
solid_brush_
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Graphics::~Graphics()
|
Graphics::~Graphics()
|
||||||
{
|
{
|
||||||
SafeRelease(fps_text_format_);
|
SafeRelease(fps_text_format_);
|
||||||
SafeRelease(fps_text_layout_);
|
SafeRelease(fps_text_layout_);
|
||||||
SafeRelease(text_renderer_);
|
SafeRelease(text_renderer_);
|
||||||
|
|
@ -601,16 +607,16 @@ easy2d::Graphics::~Graphics()
|
||||||
SafeRelease(factory_);
|
SafeRelease(factory_);
|
||||||
SafeRelease(imaging_factory_);
|
SafeRelease(imaging_factory_);
|
||||||
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();
|
||||||
|
|
||||||
if (hr == D2DERR_RECREATE_TARGET)
|
if (hr == D2DERR_RECREATE_TARGET)
|
||||||
|
|
@ -627,10 +633,10 @@ 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();
|
||||||
int duration = (Time::Now() - last_render_time_).Milliseconds();
|
int duration = (Time::Now() - last_render_time_).Milliseconds();
|
||||||
|
|
@ -699,40 +705,40 @@ void easy2d::Graphics::DrawDebugInfo()
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(
|
ThrowIfFailed(
|
||||||
|
|
@ -752,10 +758,10 @@ 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_)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(
|
ThrowIfFailed(
|
||||||
|
|
@ -775,10 +781,10 @@ 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_)
|
||||||
{
|
{
|
||||||
ThrowIfFailed(
|
ThrowIfFailed(
|
||||||
|
|
@ -798,10 +804,10 @@ 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),
|
||||||
has_outline,
|
has_outline,
|
||||||
|
|
@ -809,10 +815,10 @@ void easy2d::Graphics::SetTextRendererStyle(const Color & fill_color, bool has_o
|
||||||
outline_width,
|
outline_width,
|
||||||
D2D1_LINE_JOIN(outline_stroke)
|
D2D1_LINE_JOIN(outline_stroke)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
float easy2d::Graphics::GetDpi()
|
float Graphics::GetDpi()
|
||||||
{
|
{
|
||||||
static float dpi = -1;
|
static float dpi = -1;
|
||||||
if (dpi < 0)
|
if (dpi < 0)
|
||||||
{
|
{
|
||||||
|
|
@ -821,4 +827,5 @@ float easy2d::Graphics::GetDpi()
|
||||||
::ReleaseDC(0, hdc);
|
::ReleaseDC(0, hdc);
|
||||||
}
|
}
|
||||||
return dpi;
|
return dpi;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,11 +22,13 @@
|
||||||
#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)
|
||||||
{
|
{
|
||||||
ZeroMemory(key_buffer_, sizeof(key_buffer_));
|
ZeroMemory(key_buffer_, sizeof(key_buffer_));
|
||||||
ZeroMemory(&mouse_state_, sizeof(mouse_state_));
|
ZeroMemory(&mouse_state_, sizeof(mouse_state_));
|
||||||
|
|
||||||
|
|
@ -70,10 +72,10 @@ easy2d::Input::Input(HWND hwnd)
|
||||||
mouse_device_->SetDataFormat(&c_dfDIMouse);
|
mouse_device_->SetDataFormat(&c_dfDIMouse);
|
||||||
mouse_device_->Acquire();
|
mouse_device_->Acquire();
|
||||||
mouse_device_->Poll();
|
mouse_device_->Poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Input::~Input()
|
Input::~Input()
|
||||||
{
|
{
|
||||||
if (keyboard_device_)
|
if (keyboard_device_)
|
||||||
keyboard_device_->Unacquire();
|
keyboard_device_->Unacquire();
|
||||||
if (mouse_device_)
|
if (mouse_device_)
|
||||||
|
|
@ -82,10 +84,10 @@ easy2d::Input::~Input()
|
||||||
SafeRelease(mouse_device_);
|
SafeRelease(mouse_device_);
|
||||||
SafeRelease(keyboard_device_);
|
SafeRelease(keyboard_device_);
|
||||||
SafeRelease(direct_input_);
|
SafeRelease(direct_input_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Input::Flush()
|
void Input::Flush()
|
||||||
{
|
{
|
||||||
if (keyboard_device_)
|
if (keyboard_device_)
|
||||||
{
|
{
|
||||||
HRESULT hr = keyboard_device_->Poll();
|
HRESULT hr = keyboard_device_->Poll();
|
||||||
|
|
@ -121,52 +123,53 @@ 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);
|
||||||
::ScreenToClient(Game::GetInstance()->GetHWnd(), &mousePos);
|
::ScreenToClient(Game::GetInstance()->GetHWnd(), &mousePos);
|
||||||
float dpi = Graphics::GetDpi();
|
float dpi = Graphics::GetDpi();
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,14 +21,16 @@
|
||||||
#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)
|
||||||
, stroke_style_(nullptr)
|
, stroke_style_(nullptr)
|
||||||
, stroke_width_(1.0f)
|
, stroke_width_(1.0f)
|
||||||
, stroke_(Stroke::Miter)
|
, stroke_(Stroke::Miter)
|
||||||
{
|
{
|
||||||
render_target_ = Device::GetGraphics()->GetRenderTarget();
|
render_target_ = Device::GetGraphics()->GetRenderTarget();
|
||||||
render_target_->AddRef();
|
render_target_->AddRef();
|
||||||
|
|
||||||
|
|
@ -50,68 +52,68 @@ easy2d::Canvas::Canvas(float width, float height)
|
||||||
this->SetWidth(width);
|
this->SetWidth(width);
|
||||||
this->SetHeight(height);
|
this->SetHeight(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),
|
||||||
D2D1::Point2F(end.x, end.y),
|
D2D1::Point2F(end.x, end.y),
|
||||||
|
|
@ -119,10 +121,10 @@ void easy2d::Canvas::DrawLine(const Point & begin, const Point & end)
|
||||||
stroke_width_,
|
stroke_width_,
|
||||||
stroke_style_
|
stroke_style_
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
||||||
D2D1::Point2F(
|
D2D1::Point2F(
|
||||||
|
|
@ -136,10 +138,10 @@ void easy2d::Canvas::DrawCircle(const Point & center, float radius)
|
||||||
stroke_width_,
|
stroke_width_,
|
||||||
stroke_style_
|
stroke_style_
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
||||||
D2D1::Point2F(
|
D2D1::Point2F(
|
||||||
|
|
@ -153,10 +155,10 @@ void easy2d::Canvas::DrawEllipse(const Point & center, float radius_x, float rad
|
||||||
stroke_width_,
|
stroke_width_,
|
||||||
stroke_style_
|
stroke_style_
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Canvas::DrawRect(const Rect & rect)
|
void Canvas::DrawRect(const Rect & rect)
|
||||||
{
|
{
|
||||||
render_target_->DrawRectangle(
|
render_target_->DrawRectangle(
|
||||||
D2D1::RectF(
|
D2D1::RectF(
|
||||||
rect.origin.x,
|
rect.origin.x,
|
||||||
|
|
@ -168,10 +170,10 @@ void easy2d::Canvas::DrawRect(const Rect & rect)
|
||||||
stroke_width_,
|
stroke_width_,
|
||||||
stroke_style_
|
stroke_style_
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
||||||
D2D1::RectF(
|
D2D1::RectF(
|
||||||
|
|
@ -187,10 +189,10 @@ void easy2d::Canvas::DrawRoundedRect(const Rect & rect, float radius_x, float ra
|
||||||
stroke_width_,
|
stroke_width_,
|
||||||
stroke_style_
|
stroke_style_
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
||||||
D2D1::Point2F(
|
D2D1::Point2F(
|
||||||
|
|
@ -202,10 +204,10 @@ void easy2d::Canvas::FillCircle(const Point & center, float radius)
|
||||||
),
|
),
|
||||||
fill_brush_
|
fill_brush_
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
||||||
D2D1::Point2F(
|
D2D1::Point2F(
|
||||||
|
|
@ -217,10 +219,10 @@ void easy2d::Canvas::FillEllipse(const Point & center, float radius_x, float rad
|
||||||
),
|
),
|
||||||
fill_brush_
|
fill_brush_
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Canvas::FillRect(const Rect & rect)
|
void Canvas::FillRect(const Rect & rect)
|
||||||
{
|
{
|
||||||
render_target_->FillRectangle(
|
render_target_->FillRectangle(
|
||||||
D2D1::RectF(
|
D2D1::RectF(
|
||||||
rect.origin.x,
|
rect.origin.x,
|
||||||
|
|
@ -230,10 +232,10 @@ void easy2d::Canvas::FillRect(const Rect & rect)
|
||||||
),
|
),
|
||||||
fill_brush_
|
fill_brush_
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
||||||
D2D1::RectF(
|
D2D1::RectF(
|
||||||
|
|
@ -247,4 +249,5 @@ void easy2d::Canvas::FillRoundedRect(const Rect & rect, float radius_x, float ra
|
||||||
),
|
),
|
||||||
fill_brush_
|
fill_brush_
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,51 +22,53 @@
|
||||||
#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_()
|
||||||
{
|
{
|
||||||
this->Load(res);
|
this->Load(res);
|
||||||
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_()
|
||||||
{
|
{
|
||||||
this->Load(file_name);
|
this->Load(file_name);
|
||||||
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))
|
||||||
{
|
{
|
||||||
E2D_WARNING("Load Image from file failed!");
|
E2D_WARNING("Load Image from file failed!");
|
||||||
|
|
@ -75,10 +77,10 @@ bool easy2d::Image::Load(Resource& res)
|
||||||
|
|
||||||
this->SetBitmap(bitmap_cache_.at(res.GetHashCode()));
|
this->SetBitmap(bitmap_cache_.at(res.GetHashCode()));
|
||||||
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.");
|
||||||
|
|
||||||
if (file_name.empty())
|
if (file_name.empty())
|
||||||
|
|
@ -92,10 +94,10 @@ bool easy2d::Image::Load(const std::wstring & file_name)
|
||||||
|
|
||||||
this->SetBitmap(bitmap_cache_.at(std::hash<std::wstring>{}(file_name)));
|
this->SetBitmap(bitmap_cache_.at(std::hash<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_)
|
||||||
{
|
{
|
||||||
auto bitmap_size = bitmap_->GetSize();
|
auto bitmap_size = bitmap_->GetSize();
|
||||||
|
|
@ -104,25 +106,25 @@ void easy2d::Image::Crop(const Rect& crop_rect)
|
||||||
crop_rect_.size.width = std::min(std::max(crop_rect.size.width, 0.f), bitmap_size.width - crop_rect.origin.x);
|
crop_rect_.size.width = std::min(std::max(crop_rect.size.width, 0.f), bitmap_size.width - crop_rect.origin.x);
|
||||||
crop_rect_.size.height = std::min(std::max(crop_rect.size.height, 0.f), bitmap_size.height - crop_rect.origin.y);
|
crop_rect_.size.height = std::min(std::max(crop_rect.size.height, 0.f), bitmap_size.height - crop_rect.origin.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_)
|
||||||
{
|
{
|
||||||
return bitmap_->GetSize().width;
|
return bitmap_->GetSize().width;
|
||||||
|
|
@ -131,10 +133,10 @@ float easy2d::Image::GetSourceWidth() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float easy2d::Image::GetSourceHeight() const
|
float Image::GetSourceHeight() const
|
||||||
{
|
{
|
||||||
if (bitmap_)
|
if (bitmap_)
|
||||||
{
|
{
|
||||||
return bitmap_->GetSize().height;
|
return bitmap_->GetSize().height;
|
||||||
|
|
@ -143,45 +145,45 @@ float easy2d::Image::GetSourceHeight() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Size easy2d::Image::GetSourceSize() const
|
Size Image::GetSourceSize() const
|
||||||
{
|
{
|
||||||
if (bitmap_)
|
if (bitmap_)
|
||||||
{
|
{
|
||||||
auto bitmap_size = bitmap_->GetSize();
|
auto bitmap_size = bitmap_->GetSize();
|
||||||
return Size{ bitmap_size.width, bitmap_size.height };
|
return Size{ bitmap_size.width, bitmap_size.height };
|
||||||
}
|
}
|
||||||
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())
|
||||||
{
|
{
|
||||||
|
|
@ -275,10 +277,10 @@ bool easy2d::Image::CacheBitmap(Resource& res)
|
||||||
SafeRelease(converter);
|
SafeRelease(converter);
|
||||||
|
|
||||||
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())
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -356,10 +358,10 @@ bool easy2d::Image::CacheBitmap(const std::wstring & file_name)
|
||||||
SafeRelease(converter);
|
SafeRelease(converter);
|
||||||
|
|
||||||
return SUCCEEDED(hr);
|
return SUCCEEDED(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Image::ClearCache()
|
void Image::ClearCache()
|
||||||
{
|
{
|
||||||
if (bitmap_cache_.empty())
|
if (bitmap_cache_.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -368,10 +370,10 @@ void easy2d::Image::ClearCache()
|
||||||
bitmap.second->Release();
|
bitmap.second->Release();
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -389,4 +391,5 @@ void easy2d::Image::SetBitmap(ID2D1Bitmap * bitmap)
|
||||||
crop_rect_.size.width = bitmap_->GetSize().width;
|
crop_rect_.size.width = bitmap_->GetSize().width;
|
||||||
crop_rect_.size.height = bitmap_->GetSize().height;
|
crop_rect_.size.height = bitmap_->GetSize().height;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -44,11 +46,11 @@ easy2d::Node::Node()
|
||||||
, initial_matrix_(D2D1::Matrix3x2F::Identity())
|
, initial_matrix_(D2D1::Matrix3x2F::Identity())
|
||||||
, final_matrix_(D2D1::Matrix3x2F::Identity())
|
, final_matrix_(D2D1::Matrix3x2F::Identity())
|
||||||
, border_color_(Color::Red, 0.6f)
|
, border_color_(Color::Red, 0.6f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Node::~Node()
|
Node::~Node()
|
||||||
{
|
{
|
||||||
SafeRelease(border_);
|
SafeRelease(border_);
|
||||||
|
|
||||||
for (auto action : actions_)
|
for (auto action : actions_)
|
||||||
|
|
@ -65,10 +67,10 @@ easy2d::Node::~Node()
|
||||||
{
|
{
|
||||||
SafeRelease(child);
|
SafeRelease(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::Visit()
|
void Node::Visit()
|
||||||
{
|
{
|
||||||
if (!visible_)
|
if (!visible_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -128,10 +130,10 @@ void easy2d::Node::Visit()
|
||||||
{
|
{
|
||||||
render_target->PopAxisAlignedClip();
|
render_target->PopAxisAlignedClip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::UpdateChildren(float dt)
|
void Node::UpdateChildren(float dt)
|
||||||
{
|
{
|
||||||
if (children_.empty())
|
if (children_.empty())
|
||||||
{
|
{
|
||||||
OnUpdate(dt);
|
OnUpdate(dt);
|
||||||
|
|
@ -165,10 +167,10 @@ void easy2d::Node::UpdateChildren(float dt)
|
||||||
for (; i < children_.size(); ++i)
|
for (; i < children_.size(); ++i)
|
||||||
children_[i]->UpdateChildren(dt);
|
children_[i]->UpdateChildren(dt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::DrawBorder()
|
void Node::DrawBorder()
|
||||||
{
|
{
|
||||||
if (visible_)
|
if (visible_)
|
||||||
{
|
{
|
||||||
if (border_)
|
if (border_)
|
||||||
|
|
@ -188,10 +190,10 @@ void easy2d::Node::DrawBorder()
|
||||||
child->DrawBorder();
|
child->DrawBorder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::UpdateTransform()
|
void Node::UpdateTransform()
|
||||||
{
|
{
|
||||||
if (!dirty_transform_)
|
if (!dirty_transform_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -245,10 +247,10 @@ void easy2d::Node::UpdateTransform()
|
||||||
{
|
{
|
||||||
child->dirty_transform_ = true;
|
child->dirty_transform_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool easy2d::Node::Dispatch(const MouseEvent & e, bool handled)
|
bool Node::Dispatch(const MouseEvent & e, bool handled)
|
||||||
{
|
{
|
||||||
if (visible_)
|
if (visible_)
|
||||||
{
|
{
|
||||||
for (auto riter = children_.crbegin(); riter != children_.crend(); ++riter)
|
for (auto riter = children_.crbegin(); riter != children_.crend(); ++riter)
|
||||||
|
|
@ -260,10 +262,10 @@ 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_)
|
||||||
{
|
{
|
||||||
for (auto riter = children_.crbegin(); riter != children_.crend(); ++riter)
|
for (auto riter = children_.crbegin(); riter != children_.crend(); ++riter)
|
||||||
|
|
@ -275,10 +277,10 @@ bool easy2d::Node::Dispatch(const KeyEvent & e, bool handled)
|
||||||
}
|
}
|
||||||
|
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::UpdateOpacity()
|
void Node::UpdateOpacity()
|
||||||
{
|
{
|
||||||
if (parent_)
|
if (parent_)
|
||||||
{
|
{
|
||||||
display_opacity_ = real_opacity_ * parent_->display_opacity_;
|
display_opacity_ = real_opacity_ * parent_->display_opacity_;
|
||||||
|
|
@ -287,10 +289,10 @@ void easy2d::Node::UpdateOpacity()
|
||||||
{
|
{
|
||||||
child->UpdateOpacity();
|
child->UpdateOpacity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::UpdateActions()
|
void Node::UpdateActions()
|
||||||
{
|
{
|
||||||
if (actions_.empty())
|
if (actions_.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -320,115 +322,115 @@ void easy2d::Node::UpdateActions()
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -437,170 +439,170 @@ void easy2d::Node::SetOrder(int order)
|
||||||
{
|
{
|
||||||
parent_->dirty_sort_ = true;
|
parent_->dirty_sort_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
transform_.position.x = x;
|
transform_.position.x = x;
|
||||||
transform_.position.y = y;
|
transform_.position.y = 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;
|
||||||
|
|
||||||
transform_.scale_x = scale_x;
|
transform_.scale_x = scale_x;
|
||||||
transform_.scale_y = scale_y;
|
transform_.scale_y = 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;
|
||||||
|
|
||||||
transform_.skew_x = skew_x;
|
transform_.skew_x = skew_x;
|
||||||
transform_.skew_y = skew_y;
|
transform_.skew_y = 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;
|
||||||
|
|
||||||
transform_.rotation = angle;
|
transform_.rotation = 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;
|
||||||
|
|
||||||
display_opacity_ = real_opacity_ = std::min(std::max(opacity, 0.f), 1.f);
|
display_opacity_ = real_opacity_ = std::min(std::max(opacity, 0.f), 1.f);
|
||||||
// 更新节点透明度
|
// 更新节点透明度
|
||||||
UpdateOpacity();
|
UpdateOpacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void 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;
|
||||||
|
|
||||||
transform_.pivot_x = pivot_x;
|
transform_.pivot_x = pivot_x;
|
||||||
transform_.pivot_y = pivot_y;
|
transform_.pivot_y = 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;
|
||||||
|
|
||||||
transform_.size.width = width;
|
transform_.size.width = width;
|
||||||
transform_.size.height = height;
|
transform_.size.height = 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.");
|
||||||
|
|
||||||
if (child)
|
if (child)
|
||||||
|
|
@ -634,28 +636,28 @@ void easy2d::Node::AddChild(Node * child, int order)
|
||||||
// 更新子节点排序
|
// 更新子节点排序
|
||||||
dirty_sort_ = true;
|
dirty_sort_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
this->AddChild(node, order);
|
this->AddChild(node, 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);
|
||||||
|
|
||||||
|
|
@ -668,10 +670,10 @@ 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);
|
||||||
|
|
||||||
for (const auto& child : children_)
|
for (const auto& child : children_)
|
||||||
|
|
@ -683,28 +685,28 @@ 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_)
|
||||||
{
|
{
|
||||||
parent_->RemoveChild(this);
|
parent_->RemoveChild(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.");
|
||||||
|
|
||||||
if (children_.empty())
|
if (children_.empty())
|
||||||
|
|
@ -730,10 +732,10 @@ 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())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|
@ -757,10 +759,10 @@ void easy2d::Node::RemoveChildren(const std::wstring& child_name)
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::RemoveAllChildren()
|
void Node::RemoveAllChildren()
|
||||||
{
|
{
|
||||||
// 所有节点的引用计数减一
|
// 所有节点的引用计数减一
|
||||||
for (const auto& child : children_)
|
for (const auto& child : children_)
|
||||||
{
|
{
|
||||||
|
|
@ -768,10 +770,10 @@ 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!");
|
||||||
|
|
||||||
if (action)
|
if (action)
|
||||||
|
|
@ -791,10 +793,10 @@ void easy2d::Node::RunAction(Action * action)
|
||||||
throw std::runtime_error("该 Action 已有执行目标");
|
throw std::runtime_error("该 Action 已有执行目标");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::ResumeAction(const std::wstring& name)
|
void Node::ResumeAction(const std::wstring& name)
|
||||||
{
|
{
|
||||||
if (actions_.empty())
|
if (actions_.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -805,10 +807,10 @@ void easy2d::Node::ResumeAction(const std::wstring& name)
|
||||||
action->Resume();
|
action->Resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::PauseAction(const std::wstring& name)
|
void Node::PauseAction(const std::wstring& name)
|
||||||
{
|
{
|
||||||
if (actions_.empty())
|
if (actions_.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -819,10 +821,10 @@ void easy2d::Node::PauseAction(const std::wstring& name)
|
||||||
action->Pause();
|
action->Pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::StopAction(const std::wstring& name)
|
void Node::StopAction(const std::wstring& name)
|
||||||
{
|
{
|
||||||
if (actions_.empty())
|
if (actions_.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -833,10 +835,10 @@ void easy2d::Node::StopAction(const std::wstring& name)
|
||||||
action->Stop();
|
action->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -851,10 +853,10 @@ 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;
|
||||||
|
|
||||||
|
|
@ -873,10 +875,10 @@ bool easy2d::Node::Intersects(Node * node)
|
||||||
);
|
);
|
||||||
return relation != D2D1_GEOMETRY_RELATION_UNKNOWN &&
|
return relation != D2D1_GEOMETRY_RELATION_UNKNOWN &&
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -884,10 +886,10 @@ void easy2d::Node::ResumeAllActions()
|
||||||
{
|
{
|
||||||
action->Resume();
|
action->Resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::PauseAllActions()
|
void Node::PauseAllActions()
|
||||||
{
|
{
|
||||||
if (actions_.empty())
|
if (actions_.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -895,10 +897,10 @@ void easy2d::Node::PauseAllActions()
|
||||||
{
|
{
|
||||||
action->Pause();
|
action->Pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::StopAllActions()
|
void Node::StopAllActions()
|
||||||
{
|
{
|
||||||
if (actions_.empty())
|
if (actions_.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -906,15 +908,15 @@ void easy2d::Node::StopAllActions()
|
||||||
{
|
{
|
||||||
action->Stop();
|
action->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
auto iter = std::find(tasks_.begin(), tasks_.end(), task);
|
auto iter = std::find(tasks_.begin(), tasks_.end(), task);
|
||||||
|
|
@ -925,10 +927,10 @@ void easy2d::Node::AddTask(Task * task)
|
||||||
tasks_.push_back(task);
|
tasks_.push_back(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_)
|
||||||
{
|
{
|
||||||
if (task->GetName() == name)
|
if (task->GetName() == name)
|
||||||
|
|
@ -936,10 +938,10 @@ void easy2d::Node::StopTasks(const std::wstring& name)
|
||||||
task->Stop();
|
task->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_)
|
||||||
{
|
{
|
||||||
if (task->GetName() == name)
|
if (task->GetName() == name)
|
||||||
|
|
@ -947,10 +949,10 @@ void easy2d::Node::StartTasks(const std::wstring& name)
|
||||||
task->Start();
|
task->Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_)
|
||||||
{
|
{
|
||||||
if (task->GetName() == name)
|
if (task->GetName() == name)
|
||||||
|
|
@ -958,39 +960,39 @@ void easy2d::Node::RemoveTasks(const std::wstring& name)
|
||||||
task->stopped_ = true;
|
task->stopped_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::StopAllTasks()
|
void Node::StopAllTasks()
|
||||||
{
|
{
|
||||||
for (const auto& task : tasks_)
|
for (const auto& task : tasks_)
|
||||||
{
|
{
|
||||||
task->Stop();
|
task->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::StartAllTasks()
|
void Node::StartAllTasks()
|
||||||
{
|
{
|
||||||
for (const auto& task : tasks_)
|
for (const auto& task : tasks_)
|
||||||
{
|
{
|
||||||
task->Start();
|
task->Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::RemoveAllTasks()
|
void Node::RemoveAllTasks()
|
||||||
{
|
{
|
||||||
for (const auto& task : tasks_)
|
for (const auto& task : tasks_)
|
||||||
{
|
{
|
||||||
task->stopped_ = true;
|
task->stopped_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -1020,10 +1022,10 @@ void easy2d::Node::UpdateTasks()
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Node::UpdateTime()
|
void Node::UpdateTime()
|
||||||
{
|
{
|
||||||
for (const auto& action : actions_)
|
for (const auto& action : actions_)
|
||||||
{
|
{
|
||||||
action->ResetTime();
|
action->ResetTime();
|
||||||
|
|
@ -1038,15 +1040,15 @@ void easy2d::Node::UpdateTime()
|
||||||
{
|
{
|
||||||
child->UpdateTime();
|
child->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)
|
||||||
{
|
{
|
||||||
// 保存节点名
|
// 保存节点名
|
||||||
|
|
@ -1054,13 +1056,14 @@ void easy2d::Node::SetName(const std::wstring& name)
|
||||||
// 保存节点 Hash 名
|
// 保存节点 Hash 名
|
||||||
hash_name_ = std::hash<std::wstring>{}(name);
|
hash_name_ = std::hash<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_)
|
||||||
{
|
{
|
||||||
child->SetParentScene(scene);
|
child->SetParentScene(scene);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,30 +21,32 @@
|
||||||
#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_)
|
||||||
{
|
{
|
||||||
root_->SetParentScene(nullptr);
|
root_->SetParentScene(nullptr);
|
||||||
root_->Release();
|
root_->Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Scene::SetRoot(Node * root)
|
void Scene::SetRoot(Node * root)
|
||||||
{
|
{
|
||||||
if (root_ == root)
|
if (root_ == root)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -61,23 +63,23 @@ 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_)
|
||||||
{
|
{
|
||||||
root_->Visit();
|
root_->Visit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
@ -88,10 +90,10 @@ void easy2d::Scene::Dispatch(const MouseEvent & e)
|
||||||
{
|
{
|
||||||
root_->Dispatch(e, false);
|
root_->Dispatch(e, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
@ -102,19 +104,20 @@ void easy2d::Scene::Dispatch(const KeyEvent & e)
|
||||||
{
|
{
|
||||||
root_->Dispatch(e, false);
|
root_->Dispatch(e, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Scene::SetTransform(const D2D1::Matrix3x2F& matrix)
|
void Scene::SetTransform(const D2D1::Matrix3x2F& matrix)
|
||||||
{
|
{
|
||||||
transform_ = matrix;
|
transform_ = matrix;
|
||||||
|
|
||||||
if (root_)
|
if (root_)
|
||||||
{
|
{
|
||||||
root_->dirty_transform_ = true;
|
root_->dirty_transform_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const D2D1::Matrix3x2F & easy2d::Scene::GetTransform() const
|
const D2D1::Matrix3x2F & Scene::GetTransform() const
|
||||||
{
|
{
|
||||||
return transform_;
|
return transform_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,50 +21,52 @@
|
||||||
#include "..\e2dobject.h"
|
#include "..\e2dobject.h"
|
||||||
#include "..\e2dmodule.h"
|
#include "..\e2dmodule.h"
|
||||||
|
|
||||||
easy2d::Sprite::Sprite()
|
namespace easy2d
|
||||||
: image_(nullptr)
|
|
||||||
{
|
{
|
||||||
}
|
Sprite::Sprite()
|
||||||
|
: 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)
|
||||||
{
|
{
|
||||||
if (image_)
|
if (image_)
|
||||||
|
|
@ -79,10 +81,10 @@ bool easy2d::Sprite::Load(Image * image)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool easy2d::Sprite::Load(Resource& res)
|
bool Sprite::Load(Resource& res)
|
||||||
{
|
{
|
||||||
if (!image_)
|
if (!image_)
|
||||||
{
|
{
|
||||||
image_ = new Image();
|
image_ = new Image();
|
||||||
|
|
@ -95,10 +97,10 @@ bool easy2d::Sprite::Load(Resource& res)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
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_)
|
||||||
{
|
{
|
||||||
image_ = new Image();
|
image_ = new Image();
|
||||||
|
|
@ -111,24 +113,24 @@ bool easy2d::Sprite::Load(const std::wstring & file_name)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
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(
|
||||||
std::min(std::max(crop_rect.size.width, 0.f), image_->GetSourceWidth() - image_->GetCropX()),
|
std::min(std::max(crop_rect.size.width, 0.f), image_->GetSourceWidth() - image_->GetCropX()),
|
||||||
std::min(std::max(crop_rect.size.height, 0.f), image_->GetSourceHeight() - image_->GetCropY())
|
std::min(std::max(crop_rect.size.height, 0.f), image_->GetSourceHeight() - image_->GetCropY())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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())
|
||||||
{
|
{
|
||||||
auto crop_pos = image_->GetCropPos();
|
auto crop_pos = image_->GetCropPos();
|
||||||
|
|
@ -145,4 +147,5 @@ void easy2d::Sprite::OnDraw() const
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -29,10 +31,10 @@ easy2d::Task::Task(const Callback & func, const std::wstring & name)
|
||||||
, delay_()
|
, delay_()
|
||||||
, callback_(func)
|
, callback_(func)
|
||||||
, name_(name)
|
, name_(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)
|
||||||
|
|
@ -40,22 +42,22 @@ easy2d::Task::Task(const Callback & func, float delay, int times, const std::wst
|
||||||
, total_times_(times)
|
, total_times_(times)
|
||||||
, callback_(func)
|
, callback_(func)
|
||||||
, name_(name)
|
, name_(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
stopped_ = true;
|
stopped_ = true;
|
||||||
|
|
@ -75,15 +77,15 @@ void easy2d::Task::Update()
|
||||||
stopped_ = true;
|
stopped_ = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_)
|
||||||
{
|
{
|
||||||
if (delay_.Milliseconds() == 0)
|
if (delay_.Milliseconds() == 0)
|
||||||
|
|
@ -96,14 +98,15 @@ 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_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,11 +21,14 @@
|
||||||
#include "..\e2dobject.h"
|
#include "..\e2dobject.h"
|
||||||
#include "..\e2dmodule.h"
|
#include "..\e2dmodule.h"
|
||||||
|
|
||||||
//-------------------------------------------------------
|
|
||||||
// Style
|
|
||||||
//-------------------------------------------------------
|
|
||||||
|
|
||||||
easy2d::Text::Style::Style()
|
namespace easy2d
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------
|
||||||
|
// Style
|
||||||
|
//-------------------------------------------------------
|
||||||
|
|
||||||
|
Text::Style::Style()
|
||||||
: color(Color::White)
|
: color(Color::White)
|
||||||
, alignment(Align::Left)
|
, alignment(Align::Left)
|
||||||
, wrap(false)
|
, wrap(false)
|
||||||
|
|
@ -37,9 +40,9 @@ easy2d::Text::Style::Style()
|
||||||
, outline_color(Color(Color::Black, 0.5))
|
, outline_color(Color(Color::Black, 0.5))
|
||||||
, outline_width(1.f)
|
, outline_width(1.f)
|
||||||
, 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,
|
||||||
|
|
@ -51,7 +54,7 @@ easy2d::Text::Style::Style(
|
||||||
Color outline_color,
|
Color outline_color,
|
||||||
float outline_width,
|
float outline_width,
|
||||||
Stroke outline_stroke
|
Stroke outline_stroke
|
||||||
)
|
)
|
||||||
: color(color)
|
: color(color)
|
||||||
, alignment(alignment)
|
, alignment(alignment)
|
||||||
, wrap(wrap)
|
, wrap(wrap)
|
||||||
|
|
@ -63,90 +66,90 @@ easy2d::Text::Style::Style(
|
||||||
, outline_color(outline_color)
|
, outline_color(outline_color)
|
||||||
, outline_width(outline_width)
|
, outline_width(outline_width)
|
||||||
, outline_stroke(outline_stroke)
|
, outline_stroke(outline_stroke)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
// Text
|
// Text
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
||||||
easy2d::Text::Text()
|
Text::Text()
|
||||||
: font_()
|
: font_()
|
||||||
, style_()
|
, style_()
|
||||||
, text_layout_(nullptr)
|
, text_layout_(nullptr)
|
||||||
, text_format_(nullptr)
|
, text_format_(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
, text_format_(nullptr)
|
, text_format_(nullptr)
|
||||||
, text_(text)
|
, text_(text)
|
||||||
{
|
{
|
||||||
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_)
|
||||||
{
|
{
|
||||||
DWRITE_TEXT_METRICS metrics;
|
DWRITE_TEXT_METRICS metrics;
|
||||||
|
|
@ -157,86 +160,86 @@ int easy2d::Text::GetLineCount() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
style_.wrap = wrap;
|
style_.wrap = wrap;
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
style_.wrap_width = std::max(wrap_width, 0.f);
|
style_.wrap_width = std::max(wrap_width, 0.f);
|
||||||
|
|
@ -246,28 +249,28 @@ void easy2d::Text::SetWrapWidth(float wrap_width)
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
style_.line_spacing = line_spacing;
|
style_.line_spacing = line_spacing;
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Text::SetAlignment(Align align)
|
void Text::SetAlignment(Align align)
|
||||||
{
|
{
|
||||||
if (style_.alignment != align)
|
if (style_.alignment != align)
|
||||||
{
|
{
|
||||||
style_.alignment = align;
|
style_.alignment = align;
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Text::SetUnderline(bool underline)
|
void Text::SetUnderline(bool underline)
|
||||||
{
|
{
|
||||||
if (style_.underline != underline)
|
if (style_.underline != underline)
|
||||||
{
|
{
|
||||||
style_.underline = underline;
|
style_.underline = underline;
|
||||||
|
|
@ -275,10 +278,10 @@ void easy2d::Text::SetUnderline(bool underline)
|
||||||
CreateFormat();
|
CreateFormat();
|
||||||
CreateLayout();
|
CreateLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Text::SetStrikethrough(bool strikethrough)
|
void Text::SetStrikethrough(bool strikethrough)
|
||||||
{
|
{
|
||||||
if (style_.strikethrough != strikethrough)
|
if (style_.strikethrough != strikethrough)
|
||||||
{
|
{
|
||||||
style_.strikethrough = strikethrough;
|
style_.strikethrough = strikethrough;
|
||||||
|
|
@ -286,30 +289,30 @@ void easy2d::Text::SetStrikethrough(bool strikethrough)
|
||||||
CreateFormat();
|
CreateFormat();
|
||||||
CreateLayout();
|
CreateLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_)
|
||||||
{
|
{
|
||||||
auto graphics = Device::GetGraphics();
|
auto graphics = Device::GetGraphics();
|
||||||
|
|
@ -328,18 +331,18 @@ void easy2d::Text::OnDraw() const
|
||||||
);
|
);
|
||||||
text_layout_->Draw(nullptr, text_renderer, 0, 0);
|
text_layout_->Draw(nullptr, text_renderer, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Text::Reset()
|
void Text::Reset()
|
||||||
{
|
{
|
||||||
// 创建文字格式化
|
// 创建文字格式化
|
||||||
CreateFormat();
|
CreateFormat();
|
||||||
// 创建文字布局
|
// 创建文字布局
|
||||||
CreateLayout();
|
CreateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Text::CreateFormat()
|
void Text::CreateFormat()
|
||||||
{
|
{
|
||||||
SafeRelease(text_format_);
|
SafeRelease(text_format_);
|
||||||
|
|
||||||
ThrowIfFailed(
|
ThrowIfFailed(
|
||||||
|
|
@ -381,10 +384,10 @@ void easy2d::Text::CreateFormat()
|
||||||
{
|
{
|
||||||
text_format_->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
|
text_format_->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Text::CreateLayout()
|
void Text::CreateLayout()
|
||||||
{
|
{
|
||||||
SafeRelease(text_layout_);
|
SafeRelease(text_layout_);
|
||||||
|
|
||||||
// 文本为空字符串时,重置属性
|
// 文本为空字符串时,重置属性
|
||||||
|
|
@ -466,4 +469,5 @@ void easy2d::Text::CreateLayout()
|
||||||
{
|
{
|
||||||
text_layout_->SetStrikethrough(true, Range);
|
text_layout_->SetStrikethrough(true, Range);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,15 +21,17 @@
|
||||||
#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(
|
||||||
field_.c_str(),
|
field_.c_str(),
|
||||||
|
|
@ -40,10 +42,10 @@ bool easy2d::Data::Exists() const
|
||||||
data_path_.c_str()
|
data_path_.c_str()
|
||||||
);
|
);
|
||||||
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(),
|
||||||
key_.c_str(),
|
key_.c_str(),
|
||||||
|
|
@ -51,10 +53,10 @@ bool easy2d::Data::SaveInt(int value)
|
||||||
data_path_.c_str()
|
data_path_.c_str()
|
||||||
);
|
);
|
||||||
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(),
|
||||||
key_.c_str(),
|
key_.c_str(),
|
||||||
|
|
@ -62,10 +64,10 @@ bool easy2d::Data::SaveFloat(float value)
|
||||||
data_path_.c_str()
|
data_path_.c_str()
|
||||||
);
|
);
|
||||||
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(),
|
||||||
key_.c_str(),
|
key_.c_str(),
|
||||||
|
|
@ -73,10 +75,10 @@ bool easy2d::Data::SaveDouble(double value)
|
||||||
data_path_.c_str()
|
data_path_.c_str()
|
||||||
);
|
);
|
||||||
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(),
|
||||||
key_.c_str(),
|
key_.c_str(),
|
||||||
|
|
@ -84,10 +86,10 @@ bool easy2d::Data::SaveBool(bool value)
|
||||||
data_path_.c_str()
|
data_path_.c_str()
|
||||||
);
|
);
|
||||||
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(),
|
||||||
key_.c_str(),
|
key_.c_str(),
|
||||||
|
|
@ -95,44 +97,44 @@ bool easy2d::Data::SaveString(const std::wstring& value)
|
||||||
data_path_.c_str()
|
data_path_.c_str()
|
||||||
);
|
);
|
||||||
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(),
|
||||||
key_.c_str(),
|
key_.c_str(),
|
||||||
0,
|
0,
|
||||||
data_path_.c_str()
|
data_path_.c_str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(),
|
||||||
key_.c_str(),
|
key_.c_str(),
|
||||||
0,
|
0,
|
||||||
data_path_.c_str());
|
data_path_.c_str());
|
||||||
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(
|
||||||
field_.c_str(),
|
field_.c_str(),
|
||||||
|
|
@ -143,4 +145,5 @@ std::wstring easy2d::Data::GetString()
|
||||||
data_path_.c_str()
|
data_path_.c_str()
|
||||||
);
|
);
|
||||||
return temp;
|
return temp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -23,25 +23,27 @@
|
||||||
#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;
|
||||||
|
|
||||||
|
|
@ -67,22 +69,22 @@ 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;
|
||||||
// 找到文件名中的最后一个 '.' 的位置
|
// 找到文件名中的最后一个 '.' 的位置
|
||||||
size_t pos = file_path_.find_last_of(L'.');
|
size_t pos = file_path_.find_last_of(L'.');
|
||||||
|
|
@ -95,17 +97,17 @@ std::wstring easy2d::File::GetExtension() const
|
||||||
std::transform(file_ext.begin(), file_ext.end(), file_ext.begin(), std::towlower);
|
std::transform(file_ext.begin(), file_ext.end(), file_ext.begin(), std::towlower);
|
||||||
}
|
}
|
||||||
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(
|
||||||
dest_file_name.c_str(),
|
dest_file_name.c_str(),
|
||||||
|
|
@ -136,10 +138,10 @@ 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;
|
||||||
while ((pos = tmp.find(L"/", pos)) != std::wstring::npos)
|
while ((pos = tmp.find(L"/", pos)) != std::wstring::npos)
|
||||||
|
|
@ -157,10 +159,10 @@ void easy2d::File::AddSearchPath(const std::wstring & path)
|
||||||
{
|
{
|
||||||
search_paths_.push_front(path);
|
search_paths_.push_front(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);
|
||||||
|
|
||||||
|
|
@ -219,10 +221,10 @@ easy2d::File easy2d::File::ShowOpenDialog(const std::wstring & title, const std:
|
||||||
::CoUninitialize();
|
::CoUninitialize();
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
|
||||||
|
|
@ -289,4 +291,5 @@ easy2d::File easy2d::File::ShowSaveDialog(const std::wstring & title, const std:
|
||||||
::CoUninitialize();
|
::CoUninitialize();
|
||||||
}
|
}
|
||||||
return File(file_path);
|
return File(file_path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,8 +22,10 @@
|
||||||
#include "..\e2dmodule.h"
|
#include "..\e2dmodule.h"
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace easy2d
|
||||||
{
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
void OutputDebugStringExW(LPCWSTR pszOutput, ...)
|
void OutputDebugStringExW(LPCWSTR pszOutput, ...)
|
||||||
{
|
{
|
||||||
va_list args = NULL;
|
va_list args = NULL;
|
||||||
|
|
@ -48,12 +50,12 @@ namespace
|
||||||
{
|
{
|
||||||
OutputDebugStringExW(L"[easy2d] Music error: %s (%#X)\r\n", output, hr);
|
OutputDebugStringExW(L"[easy2d] Music error: %s (%#X)\r\n", output, hr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------
|
||||||
|
// Transcoder
|
||||||
|
//-------------------------------------------------------
|
||||||
|
|
||||||
namespace easy2d
|
|
||||||
{
|
|
||||||
// ÒôƵ½âÂëÆ÷
|
|
||||||
class Transcoder
|
class Transcoder
|
||||||
{
|
{
|
||||||
WAVEFORMATEX* wave_format_;
|
WAVEFORMATEX* wave_format_;
|
||||||
|
|
@ -304,45 +306,47 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------
|
||||||
|
// Music
|
||||||
|
//-------------------------------------------------------
|
||||||
|
|
||||||
easy2d::Music::Music()
|
Music::Music()
|
||||||
: opened_(false)
|
: opened_(false)
|
||||||
, playing_(false)
|
, playing_(false)
|
||||||
, wave_data_(nullptr)
|
, wave_data_(nullptr)
|
||||||
, size_(0)
|
, size_(0)
|
||||||
, voice_(nullptr)
|
, voice_(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
, size_(0)
|
, size_(0)
|
||||||
, voice_(nullptr)
|
, voice_(nullptr)
|
||||||
{
|
{
|
||||||
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)
|
||||||
, size_(0)
|
, size_(0)
|
||||||
, voice_(nullptr)
|
, voice_(nullptr)
|
||||||
{
|
{
|
||||||
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_)
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
|
|
@ -379,10 +383,10 @@ bool easy2d::Music::Load(const std::wstring & file_path)
|
||||||
|
|
||||||
opened_ = true;
|
opened_ = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool easy2d::Music::Load(Resource& res)
|
bool Music::Load(Resource& res)
|
||||||
{
|
{
|
||||||
if (opened_)
|
if (opened_)
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
|
|
@ -408,10 +412,10 @@ bool easy2d::Music::Load(Resource& res)
|
||||||
|
|
||||||
opened_ = true;
|
opened_ = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool easy2d::Music::Play(int loop_count)
|
bool Music::Play(int loop_count)
|
||||||
{
|
{
|
||||||
if (!opened_)
|
if (!opened_)
|
||||||
{
|
{
|
||||||
E2D_WARNING("Music must be opened first!");
|
E2D_WARNING("Music must be opened first!");
|
||||||
|
|
@ -459,10 +463,10 @@ bool easy2d::Music::Play(int loop_count)
|
||||||
playing_ = SUCCEEDED(hr);
|
playing_ = SUCCEEDED(hr);
|
||||||
|
|
||||||
return playing_;
|
return playing_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Music::Pause()
|
void Music::Pause()
|
||||||
{
|
{
|
||||||
if (voice_)
|
if (voice_)
|
||||||
{
|
{
|
||||||
if (SUCCEEDED(voice_->Stop()))
|
if (SUCCEEDED(voice_->Stop()))
|
||||||
|
|
@ -470,10 +474,10 @@ void easy2d::Music::Pause()
|
||||||
playing_ = false;
|
playing_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Music::Resume()
|
void Music::Resume()
|
||||||
{
|
{
|
||||||
if (voice_)
|
if (voice_)
|
||||||
{
|
{
|
||||||
if (SUCCEEDED(voice_->Start()))
|
if (SUCCEEDED(voice_->Start()))
|
||||||
|
|
@ -481,10 +485,10 @@ void easy2d::Music::Resume()
|
||||||
playing_ = true;
|
playing_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Music::Stop()
|
void Music::Stop()
|
||||||
{
|
{
|
||||||
if (voice_)
|
if (voice_)
|
||||||
{
|
{
|
||||||
if (SUCCEEDED(voice_->Stop()))
|
if (SUCCEEDED(voice_->Stop()))
|
||||||
|
|
@ -494,10 +498,10 @@ void easy2d::Music::Stop()
|
||||||
playing_ = false;
|
playing_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Music::Close()
|
void Music::Close()
|
||||||
{
|
{
|
||||||
if (voice_)
|
if (voice_)
|
||||||
{
|
{
|
||||||
voice_->Stop();
|
voice_->Stop();
|
||||||
|
|
@ -514,10 +518,10 @@ void easy2d::Music::Close()
|
||||||
|
|
||||||
opened_ = false;
|
opened_ = false;
|
||||||
playing_ = false;
|
playing_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool easy2d::Music::IsPlaying() const
|
bool Music::IsPlaying() const
|
||||||
{
|
{
|
||||||
if (opened_ && voice_)
|
if (opened_ && voice_)
|
||||||
{
|
{
|
||||||
XAUDIO2_VOICE_STATE state;
|
XAUDIO2_VOICE_STATE state;
|
||||||
|
|
@ -526,10 +530,10 @@ bool easy2d::Music::IsPlaying() const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float easy2d::Music::GetVolume() const
|
float Music::GetVolume() const
|
||||||
{
|
{
|
||||||
if (voice_)
|
if (voice_)
|
||||||
{
|
{
|
||||||
float volume = 0.f;
|
float volume = 0.f;
|
||||||
|
|
@ -537,19 +541,20 @@ float easy2d::Music::GetVolume() const
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
return 0.f;
|
return 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool easy2d::Music::SetVolume(float volume)
|
bool Music::SetVolume(float volume)
|
||||||
{
|
{
|
||||||
if (voice_)
|
if (voice_)
|
||||||
{
|
{
|
||||||
volume = std::min(std::max(volume, -224.f), 224.f);
|
volume = std::min(std::max(volume, -224.f), 224.f);
|
||||||
return SUCCEEDED(voice_->SetVolume(volume));
|
return SUCCEEDED(voice_->SetVolume(volume));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
IXAudio2SourceVoice * easy2d::Music::GetSourceVoice() const
|
IXAudio2SourceVoice * Music::GetSourceVoice() const
|
||||||
{
|
{
|
||||||
return voice_;
|
return voice_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -23,8 +23,10 @@
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace easy2d
|
||||||
{
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
// ´´½¨Ö¸¶¨Îļþ¼Ð
|
// ´´½¨Ö¸¶¨Îļþ¼Ð
|
||||||
bool CreateFolder(const std::wstring & dir_path)
|
bool CreateFolder(const std::wstring & dir_path)
|
||||||
{
|
{
|
||||||
|
|
@ -50,11 +52,11 @@ namespace
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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())
|
||||||
{
|
{
|
||||||
|
|
@ -79,10 +81,10 @@ const std::wstring& easy2d::Path::GetDataPath()
|
||||||
data_path.append(L"Data.ini");
|
data_path.append(L"Data.ini");
|
||||||
}
|
}
|
||||||
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())
|
||||||
{
|
{
|
||||||
|
|
@ -106,10 +108,10 @@ 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())
|
||||||
{
|
{
|
||||||
|
|
@ -120,10 +122,10 @@ 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())
|
||||||
{
|
{
|
||||||
|
|
@ -134,4 +136,5 @@ const std::wstring& easy2d::Path::GetExeFilePath()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return exe_file_path;
|
return exe_file_path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,19 +1,21 @@
|
||||||
#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;
|
||||||
|
|
||||||
|
|
@ -35,10 +37,10 @@ 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;
|
||||||
|
|
||||||
|
|
@ -51,40 +53,40 @@ 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;
|
||||||
|
|
||||||
size_t hash_code = std::hash<std::wstring>{}(file_path);
|
size_t hash_code = std::hash<std::wstring>{}(file_path);
|
||||||
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(const std::wstring & file_path)
|
void Player::Resume(const std::wstring & file_path)
|
||||||
{
|
{
|
||||||
if (file_path.empty())
|
if (file_path.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
size_t hash_code = std::hash<std::wstring>{}(file_path);
|
size_t hash_code = std::hash<std::wstring>{}(file_path);
|
||||||
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(const std::wstring & file_path)
|
void Player::Stop(const std::wstring & file_path)
|
||||||
{
|
{
|
||||||
if (file_path.empty())
|
if (file_path.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
size_t hash_code = std::hash<std::wstring>{}(file_path);
|
size_t hash_code = std::hash<std::wstring>{}(file_path);
|
||||||
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(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;
|
||||||
|
|
||||||
|
|
@ -92,10 +94,10 @@ bool easy2d::Player::IsPlaying(const std::wstring & file_path)
|
||||||
if (musics_.end() != musics_.find(hash_code))
|
if (musics_.end() != musics_.find(hash_code))
|
||||||
return musics_[hash_code]->IsPlaying();
|
return musics_[hash_code]->IsPlaying();
|
||||||
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))
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -116,10 +118,10 @@ 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))
|
||||||
{
|
{
|
||||||
size_t hash_code = res.GetHashCode();
|
size_t hash_code = res.GetHashCode();
|
||||||
|
|
@ -130,77 +132,77 @@ 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))
|
||||||
return musics_[hash_code]->IsPlaying();
|
return musics_[hash_code]->IsPlaying();
|
||||||
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_)
|
||||||
{
|
{
|
||||||
pair.second->SetVolume(volume_);
|
pair.second->SetVolume(volume_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Player::PauseAll()
|
void Player::PauseAll()
|
||||||
{
|
{
|
||||||
for (const auto& pair : musics_)
|
for (const auto& pair : musics_)
|
||||||
{
|
{
|
||||||
pair.second->Pause();
|
pair.second->Pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Player::ResumeAll()
|
void Player::ResumeAll()
|
||||||
{
|
{
|
||||||
for (const auto& pair : musics_)
|
for (const auto& pair : musics_)
|
||||||
{
|
{
|
||||||
pair.second->Resume();
|
pair.second->Resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Player::StopAll()
|
void Player::StopAll()
|
||||||
{
|
{
|
||||||
for (const auto& pair : musics_)
|
for (const auto& pair : musics_)
|
||||||
{
|
{
|
||||||
pair.second->Stop();
|
pair.second->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Player::ClearCache()
|
void Player::ClearCache()
|
||||||
{
|
{
|
||||||
if (musics_.empty())
|
if (musics_.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -209,4 +211,5 @@ void easy2d::Player::ClearCache()
|
||||||
pair.second->Release();
|
pair.second->Release();
|
||||||
}
|
}
|
||||||
musics_.clear();
|
musics_.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,20 +21,22 @@
|
||||||
#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();
|
||||||
|
|
||||||
if (process_ < .5f)
|
if (process_ < .5f)
|
||||||
|
|
@ -57,4 +59,5 @@ void easy2d::BoxTransition::Update()
|
||||||
window_size_.height * process_
|
window_size_.height * process_
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,23 +21,26 @@
|
||||||
#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);
|
||||||
|
|
||||||
out_layer_param_.opacity = 1;
|
out_layer_param_.opacity = 1;
|
||||||
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_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,21 +21,23 @@
|
||||||
#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);
|
||||||
|
|
||||||
out_layer_param_.opacity = 1;
|
out_layer_param_.opacity = 1;
|
||||||
in_layer_param_.opacity = 0;
|
in_layer_param_.opacity = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::FadeTransition::Update()
|
void FadeTransition::Update()
|
||||||
{
|
{
|
||||||
Transition::Update();
|
Transition::Update();
|
||||||
|
|
||||||
if (process_ < 0.5)
|
if (process_ < 0.5)
|
||||||
|
|
@ -48,4 +50,5 @@ void easy2d::FadeTransition::Update()
|
||||||
out_layer_param_.opacity = 0;
|
out_layer_param_.opacity = 0;
|
||||||
in_layer_param_.opacity = (process_ - 0.5f) * 2;
|
in_layer_param_.opacity = (process_ - 0.5f) * 2;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,14 +21,16 @@
|
||||||
#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);
|
||||||
|
|
||||||
switch (direction_)
|
switch (direction_)
|
||||||
|
|
@ -65,10 +67,10 @@ void easy2d::MoveTransition::Init(Scene * prev, Scene * next, Game * game)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::MoveTransition::Update()
|
void MoveTransition::Update()
|
||||||
{
|
{
|
||||||
Transition::Update();
|
Transition::Update();
|
||||||
|
|
||||||
if (out_scene_)
|
if (out_scene_)
|
||||||
|
|
@ -92,10 +94,10 @@ void easy2d::MoveTransition::Update()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::MoveTransition::Reset()
|
void MoveTransition::Reset()
|
||||||
{
|
{
|
||||||
if (out_scene_)
|
if (out_scene_)
|
||||||
{
|
{
|
||||||
out_scene_->SetTransform(D2D1::Matrix3x2F::Identity());
|
out_scene_->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||||
|
|
@ -105,4 +107,5 @@ void easy2d::MoveTransition::Reset()
|
||||||
{
|
{
|
||||||
in_scene_->SetTransform(D2D1::Matrix3x2F::Identity());
|
in_scene_->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,14 +21,16 @@
|
||||||
#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);
|
||||||
|
|
||||||
if (out_scene_)
|
if (out_scene_)
|
||||||
|
|
@ -42,10 +44,10 @@ 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();
|
||||||
|
|
||||||
auto center_pos = D2D1::Point2F(
|
auto center_pos = D2D1::Point2F(
|
||||||
|
|
@ -88,10 +90,10 @@ void easy2d::RotationTransition::Update()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::RotationTransition::Reset()
|
void RotationTransition::Reset()
|
||||||
{
|
{
|
||||||
if (out_scene_)
|
if (out_scene_)
|
||||||
{
|
{
|
||||||
out_scene_->SetTransform(D2D1::Matrix3x2F::Identity());
|
out_scene_->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||||
|
|
@ -101,4 +103,5 @@ void easy2d::RotationTransition::Reset()
|
||||||
{
|
{
|
||||||
in_scene_->SetTransform(D2D1::Matrix3x2F::Identity());
|
in_scene_->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -33,25 +35,25 @@ easy2d::Transition::Transition(float duration)
|
||||||
, in_layer_(nullptr)
|
, in_layer_(nullptr)
|
||||||
, out_layer_param_()
|
, out_layer_param_()
|
||||||
, in_layer_param_()
|
, in_layer_param_()
|
||||||
{
|
{
|
||||||
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_);
|
||||||
SafeRelease(out_scene_);
|
SafeRelease(out_scene_);
|
||||||
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;
|
||||||
in_scene_ = next;
|
in_scene_ = next;
|
||||||
|
|
@ -92,10 +94,10 @@ void easy2d::Transition::Init(Scene * prev, Scene * next, Game * game)
|
||||||
graphics->GetSolidBrush(),
|
graphics->GetSolidBrush(),
|
||||||
D2D1_LAYER_OPTIONS_NONE
|
D2D1_LAYER_OPTIONS_NONE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Transition::Update()
|
void Transition::Update()
|
||||||
{
|
{
|
||||||
if (duration_ == 0)
|
if (duration_ == 0)
|
||||||
{
|
{
|
||||||
process_ = 1;
|
process_ = 1;
|
||||||
|
|
@ -110,10 +112,10 @@ void easy2d::Transition::Update()
|
||||||
{
|
{
|
||||||
this->Stop();
|
this->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Transition::Draw()
|
void Transition::Draw()
|
||||||
{
|
{
|
||||||
auto render_target = Device::GetGraphics()->GetRenderTarget();
|
auto render_target = Device::GetGraphics()->GetRenderTarget();
|
||||||
|
|
||||||
if (out_scene_)
|
if (out_scene_)
|
||||||
|
|
@ -155,10 +157,11 @@ void easy2d::Transition::Draw()
|
||||||
render_target->PopLayer();
|
render_target->PopLayer();
|
||||||
render_target->PopAxisAlignedClip();
|
render_target->PopAxisAlignedClip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void easy2d::Transition::Stop()
|
void Transition::Stop()
|
||||||
{
|
{
|
||||||
done_ = true;
|
done_ = true;
|
||||||
Reset();
|
Reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,63 +20,69 @@
|
||||||
|
|
||||||
#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)
|
||||||
, a(1.f)
|
, a(1.f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
, a(1.f)
|
, a(1.f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
, a(alpha)
|
, a(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)
|
||||||
, a(color.a)
|
, a(color.a)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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)
|
|
||||||
{
|
|
||||||
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}};
|
|
||||||
|
|
||||||
|
Duration Duration::Parse(const std::wstring & str)
|
||||||
|
{
|
||||||
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;
|
||||||
|
|
@ -140,157 +151,159 @@ easy2d::Duration easy2d::Duration::Parse(const std::wstring & str)
|
||||||
d.milliseconds_ = -d.milliseconds_;
|
d.milliseconds_ = -d.milliseconds_;
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,63 +22,66 @@
|
||||||
#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) +
|
||||||
(p1.y - p2.y) * (p1.y - p2.y)
|
(p1.y - p2.y) * (p1.y - p2.y)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,56 +20,59 @@
|
||||||
|
|
||||||
#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))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,23 +20,25 @@
|
||||||
|
|
||||||
#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_);
|
||||||
|
|
||||||
if (new_count <= 0)
|
if (new_count <= 0)
|
||||||
|
|
@ -46,9 +48,10 @@ 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_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,42 +21,44 @@
|
||||||
#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)
|
||||||
, data_size_(0)
|
, data_size_(0)
|
||||||
, loaded_(false)
|
, loaded_(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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_)
|
||||||
{
|
{
|
||||||
HRSRC res_info;
|
HRSRC res_info;
|
||||||
|
|
@ -94,4 +96,5 @@ bool easy2d::Resource::Load()
|
||||||
loaded_ = true;
|
loaded_ = true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,86 +20,89 @@
|
||||||
|
|
||||||
#include "..\e2dutil.h"
|
#include "..\e2dutil.h"
|
||||||
|
|
||||||
using namespace std::chrono;
|
namespace easy2d
|
||||||
|
|
||||||
|
|
||||||
easy2d::Time::Time()
|
|
||||||
{
|
{
|
||||||
}
|
using namespace std::chrono;
|
||||||
|
|
||||||
easy2d::Time::Time(std::chrono::steady_clock::time_point time)
|
|
||||||
|
Time::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;
|
||||||
|
|
||||||
time_ = other.time_;
|
time_ = other.time_;
|
||||||
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;
|
||||||
|
|
||||||
time_ = std::move(other.time_);
|
time_ = std::move(other.time_);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
easy2d::Time easy2d::Time::Now()
|
Time Time::Now()
|
||||||
{
|
{
|
||||||
return Time(steady_clock::now());
|
return Time(steady_clock::now());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -31,11 +33,11 @@ easy2d::Transform::Transform()
|
||||||
, skew_y(0)
|
, skew_y(0)
|
||||||
, pivot_x(0)
|
, pivot_x(0)
|
||||||
, pivot_y(0)
|
, pivot_y(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
||||||
scale_x,
|
scale_x,
|
||||||
|
|
@ -53,10 +55,10 @@ easy2d::Transform::operator D2D1::Matrix3x2F() const
|
||||||
position.y - pivot.y
|
position.y - pivot.y
|
||||||
);
|
);
|
||||||
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 &&
|
||||||
scale_x == other.scale_x &&
|
scale_x == other.scale_x &&
|
||||||
|
|
@ -66,4 +68,5 @@ bool easy2d::Transform::operator==(const Transform & other) const
|
||||||
rotation == other.rotation &&
|
rotation == other.rotation &&
|
||||||
pivot_x == other.pivot_x &&
|
pivot_x == other.pivot_x &&
|
||||||
pivot_y == other.pivot_y;
|
pivot_y == other.pivot_y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue