minor

refactoring

minor

minor

minor
This commit is contained in:
Haibo 2018-11-23 14:55:03 +08:00 committed by Nomango
parent a29584f756
commit 1d86da332c
76 changed files with 1045 additions and 1179 deletions

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "time.h" #include "time.h"
#include "noncopyable.hpp" #include "noncopyable.hpp"
#include "intrusive/List.hpp" #include "intrusive/List.hpp"
@ -29,7 +29,7 @@ namespace easy2d
class ActionManager; class ActionManager;
class Action class Action
: public ObjectBase : public Object
, protected intrusive::ListItem<spAction> , protected intrusive::ListItem<spAction>
{ {
friend class ActionManager; friend class ActionManager;
@ -53,7 +53,7 @@ namespace easy2d
virtual void Pause() { running_ = false; } virtual void Pause() { running_ = false; }
// 停止动作 // 停止动作
virtual void Stop() { if (!done_) { done_ = true; cb_(); } } virtual void Stop() { if (!done_) { done_ = true; if (cb_) cb_(); } }
// 获取动作的拷贝 // 获取动作的拷贝
virtual spAction Clone() const = 0; virtual spAction Clone() const = 0;

View File

@ -57,7 +57,7 @@ namespace easy2d
if (actions_.IsEmpty()) if (actions_.IsEmpty())
return; return;
for (auto action = actions_.First(); action; action = action->NextItem()) for (auto action = actions_.First().Get(); action; action = action->NextItem().Get())
{ {
action->Resume(); action->Resume();
} }
@ -68,7 +68,7 @@ namespace easy2d
if (actions_.IsEmpty()) if (actions_.IsEmpty())
return; return;
for (auto action = actions_.First(); action; action = action->NextItem()) for (auto action = actions_.First().Get(); action; action = action->NextItem().Get())
{ {
action->Pause(); action->Pause();
} }
@ -79,7 +79,7 @@ namespace easy2d
if (actions_.IsEmpty()) if (actions_.IsEmpty())
return; return;
for (auto action = actions_.First(); action; action = action->NextItem()) for (auto action = actions_.First().Get(); action; action = action->NextItem().Get())
{ {
action->Stop(); action->Stop();
} }

View File

@ -20,7 +20,7 @@
#include "ActionTween.h" #include "ActionTween.h"
#include "Geometry.h" #include "Geometry.h"
#include "base.hpp" #include "include-forwards.h"
#include "Node.h" #include "Node.h"
#include <algorithm> #include <algorithm>
#include <cfloat> #include <cfloat>
@ -56,13 +56,13 @@ namespace easy2d
case EaseFunc::Linear: case EaseFunc::Linear:
ease_func_ = math::Linear; ease_func_ = math::Linear;
break; break;
case EaseFunc::In: case EaseFunc::EaseIn:
ease_func_ = MakeEaseIn(2.f); ease_func_ = MakeEaseIn(2.f);
break; break;
case EaseFunc::Out: case EaseFunc::EaseOut:
ease_func_ = MakeEaseOut(2.f); ease_func_ = MakeEaseOut(2.f);
break; break;
case EaseFunc::InOut: case EaseFunc::EaseInOut:
ease_func_ = MakeEaseInOut(2.f); ease_func_ = MakeEaseInOut(2.f);
break; break;
case EaseFunc::ExpoIn: case EaseFunc::ExpoIn:
@ -552,6 +552,16 @@ namespace easy2d
return new PathAction(duration_, geo_, rotating_, end_, start_, ease_type_); return new PathAction(duration_, geo_, rotating_, end_, start_, ease_type_);
} }
void PathAction::Init(Node * target)
{
Tween::Init(target);
if (target)
{
start_pos_ = target->GetPosition();
}
}
void PathAction::UpdateStep(Node* target, float step) void PathAction::UpdateStep(Node* target, float step)
{ {
if (target) if (target)
@ -561,7 +571,7 @@ namespace easy2d
Point point, tangent; Point point, tangent;
if (geo_->ComputePointAt(length, &point, &tangent)) if (geo_->ComputePointAt(length, &point, &tangent))
{ {
target->SetPosition(point); target->SetPosition(start_pos_ + point);
if (rotating_) if (rotating_)
{ {

View File

@ -30,9 +30,9 @@ namespace easy2d
enum class EaseFunc enum class EaseFunc
{ {
Linear, // 窟昑 Linear, // 窟昑
In, // 譚찹긴우 EaseIn, // 譚찹긴우
Out, // 譚우긴찹 EaseOut, // 譚우긴찹
InOut, // 譚찹긴우, 疼譚우긴찹 EaseInOut, // 譚찹긴우, 疼譚우긴찹
ExpoIn, // 譚찹긴섐우 ExpoIn, // 譚찹긴섐우
ExpoOut, // 譚섐우긴찹 ExpoOut, // 譚섐우긴찹
ExpoInOut, // 譚찹逞섐우, 疼譚섐우긋찹 ExpoInOut, // 譚찹逞섐우, 疼譚섐우긋찹
@ -473,12 +473,15 @@ namespace easy2d
virtual spAction Reverse() const override; virtual spAction Reverse() const override;
protected: protected:
virtual void Init(Node* target) override;
virtual void UpdateStep(Node* target, float step) override; virtual void UpdateStep(Node* target, float step) override;
protected: protected:
bool rotating_; bool rotating_;
float start_; float start_;
float end_; float end_;
Point start_pos_;
spGeometry geo_; spGeometry geo_;
}; };
} }

View File

@ -160,7 +160,7 @@ namespace easy2d
void Canvas::SetBrushTransform(math::Matrix const & transform) void Canvas::SetBrushTransform(math::Matrix const & transform)
{ {
render_target_->SetTransform(ConvertToD2DMatrix(transform)); render_target_->SetTransform(transform);
} }
void Canvas::DrawLine(const Point & begin, const Point & end) void Canvas::DrawLine(const Point & begin, const Point & end)
@ -262,7 +262,7 @@ namespace easy2d
} }
} }
void Canvas::DrawText(String const & text, Point const & point) void Canvas::DrawText(std::wstring const & text, Point const & point)
{ {
if (text.empty()) if (text.empty())
return; return;

View File

@ -91,7 +91,7 @@ namespace easy2d
// 画文字 // 画文字
void DrawText( void DrawText(
String const& text, /* 文字 */ std::wstring const& text, /* 文字 */
Point const& point /* 文字位置 */ Point const& point /* 文字位置 */
); );

View File

@ -18,7 +18,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#include "Debuger.h" #include "DebugNode.h"
#include "render.h"
#include "../utils/string.h" #include "../utils/string.h"
#include <sstream> #include <sstream>
#include <psapi.h> #include <psapi.h>
@ -28,10 +29,10 @@
namespace easy2d namespace easy2d
{ {
DebugerNode::DebugerNode() DebugNodeImpl::DebugNodeImpl()
{ {
debug_text_ = new Text(); debug_text_ = new Text();
debug_text_->SetPosition(10, 10); debug_text_->SetPosition(15, 15);
this->AddChild(debug_text_); this->AddChild(debug_text_);
Font font; Font font;
@ -41,18 +42,15 @@ namespace easy2d
TextStyle style; TextStyle style;
style.wrap = false; style.wrap = false;
style.line_spacing = 18.f; style.line_spacing = 20.f;
debug_text_->SetStyle(style); debug_text_->SetStyle(style);
ObjectBase::__RemoveObjectFromTracingList(this);
ObjectBase::__RemoveObjectFromTracingList(debug_text_.Get());
} }
DebugerNode::~DebugerNode() DebugNodeImpl::~DebugNodeImpl()
{ {
} }
void DebugerNode::AddDebugText(String const & text) void DebugNodeImpl::AddDebugText(std::wstring const & text)
{ {
try try
{ {
@ -63,12 +61,29 @@ namespace easy2d
} }
} }
void DebugerNode::ClearDebugText() void DebugNodeImpl::ClearDebugText()
{ {
texts_.clear(); texts_.clear();
} }
void DebugerNode::Update(Duration const & dt) void DebugNodeImpl::OnRender()
{
auto graphics = Graphics::Instance();
graphics->SetTransform(math::Matrix{});
graphics->GetSolidBrush()->SetColor(Color(0.0f, 0.0f, 0.0f, 0.5f));
graphics->GetRenderTarget()->FillRoundedRectangle(
D2D1::RoundedRect(
D2D1_RECT_F{ 10, 10, 200, 120 },
6.f,
6.f),
graphics->GetSolidBrush().Get()
);
}
void DebugNodeImpl::OnUpdate(Duration const & dt)
{ {
try try
{ {
@ -85,20 +100,19 @@ namespace easy2d
} }
std::wstringstream ss; std::wstringstream ss;
ss << "fps=" << frame_time_.size() << std::endl; ss << "Fps: " << frame_time_.size() << std::endl;
#ifdef E2D_DEBUG #ifdef E2D_DEBUG
ss << "Objects: " << Object::__GetTracingObjects().size() << std::endl;
ss << "objects=" << ObjectBase::__GetTracingObjects().size() << std::endl;
#endif #endif
ss << "Render: " << Graphics::Instance()->GetStatus().duration.Milliseconds() << "ms" << std::endl;
ss << "Primitives / sec: " << Graphics::Instance()->GetStatus().primitives * frame_time_.size() << std::endl;
PROCESS_MEMORY_COUNTERS_EX pmc; PROCESS_MEMORY_COUNTERS_EX pmc;
GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc)); GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc));
if (pmc.PrivateUsage > 1024 * 1024) ss << "Memory: " << pmc.PrivateUsage / 1024 << "kb";
ss << "memory=" << pmc.PrivateUsage / 1024 / 1024 << "Mb " << (pmc.PrivateUsage / 1024) % 1024 << "Kb";
else
ss << "memory=" << pmc.PrivateUsage / 1024 << "Kb";
for (const auto& text : texts_) for (const auto& text : texts_)
ss << std::endl << text; ss << std::endl << text;

View File

@ -25,27 +25,29 @@
namespace easy2d namespace easy2d
{ {
class DebugerNode class DebugNodeImpl
: public Node : public Node
{ {
E2D_DECLARE_SINGLETON(DebugerNode); E2D_DECLARE_SINGLETON(DebugNodeImpl);
public: public:
DebugerNode(); DebugNodeImpl();
virtual ~DebugerNode(); virtual ~DebugNodeImpl();
void AddDebugText(String const& text); void AddDebugText(std::wstring const& text);
void ClearDebugText(); void ClearDebugText();
void Update(Duration const& dt) override; void OnRender() override;
void OnUpdate(Duration const& dt) override;
protected: protected:
spText debug_text_; spText debug_text_;
std::vector<TimePoint> frame_time_; std::vector<TimePoint> frame_time_;
std::vector<String> texts_; std::vector<std::wstring> texts_;
}; };
E2D_DECLARE_SINGLETON_TYPE(DebugerNode, Debuger); E2D_DECLARE_SINGLETON_TYPE(DebugNodeImpl, DebugNode);
} }

View File

@ -30,6 +30,8 @@ namespace easy2d
public: public:
Event(EventType type) : type(type), has_target(false) {} Event(EventType type) : type(type), has_target(false) {}
virtual ~Event() {}
EventType type; EventType type;
bool has_target; bool has_target;
}; };

View File

@ -50,7 +50,7 @@ namespace easy2d
} }
} }
void EventDispatcher::AddListener(EventType type, EventCallback callback, String const& name) void EventDispatcher::AddListener(EventType type, EventCallback callback, std::wstring const& name)
{ {
spEventListener listener = new EventListener(type, callback, name); spEventListener listener = new EventListener(type, callback, name);
if (listener) if (listener)
@ -59,7 +59,7 @@ namespace easy2d
} }
} }
void EventDispatcher::StartListeners(String const & listener_name) void EventDispatcher::StartListeners(std::wstring const & listener_name)
{ {
for (auto listener = listeners_.First(); listener; listener = listener->NextItem()) for (auto listener = listeners_.First(); listener; listener = listener->NextItem())
{ {
@ -70,7 +70,7 @@ namespace easy2d
} }
} }
void EventDispatcher::StopListeners(String const & listener_name) void EventDispatcher::StopListeners(std::wstring const & listener_name)
{ {
for (auto listener = listeners_.First(); listener; listener = listener->NextItem()) for (auto listener = listeners_.First(); listener; listener = listener->NextItem())
{ {
@ -81,7 +81,7 @@ namespace easy2d
} }
} }
void EventDispatcher::RemoveListeners(String const & listener_name) void EventDispatcher::RemoveListeners(std::wstring const & listener_name)
{ {
spEventListener next; spEventListener next;
for (auto listener = listeners_.First(); listener; listener = next) for (auto listener = listeners_.First(); listener; listener = next)

View File

@ -37,22 +37,22 @@ namespace easy2d
void AddListener( void AddListener(
EventType type, EventType type,
EventCallback callback, EventCallback callback,
String const& name = L"" std::wstring const& name = L""
); );
// 启动监听器 // 启动监听器
void StartListeners( void StartListeners(
String const& listener_name std::wstring const& listener_name
); );
// 停止监听器 // 停止监听器
void StopListeners( void StopListeners(
String const& listener_name std::wstring const& listener_name
); );
// 移除监听器 // 移除监听器
void RemoveListeners( void RemoveListeners(
String const& listener_name std::wstring const& listener_name
); );
// 启动监听器 // 启动监听器

View File

@ -23,7 +23,7 @@
namespace easy2d namespace easy2d
{ {
EventListener::EventListener(EventType type, EventCallback const & callback, String const & name) EventListener::EventListener(EventType type, EventCallback const & callback, std::wstring const & name)
: type_(type) : type_(type)
, callback_(callback) , callback_(callback)
, name_(name) , name_(name)
@ -50,12 +50,12 @@ namespace easy2d
return running_; return running_;
} }
String const & EventListener::GetName() const std::wstring const & EventListener::GetName() const
{ {
return name_; return name_;
} }
void EventListener::SetName(String const & name) void EventListener::SetName(std::wstring const & name)
{ {
name_ = name; name_ = name;
} }

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "intrusive/List.hpp" #include "intrusive/List.hpp"
#include "Event.hpp" #include "Event.hpp"
@ -31,7 +31,7 @@ namespace easy2d
class EventDispatcher; class EventDispatcher;
class EventListener class EventListener
: public RefCounter : public Object
, protected intrusive::ListItem<spEventListener> , protected intrusive::ListItem<spEventListener>
{ {
friend class EventDispatcher; friend class EventDispatcher;
@ -41,7 +41,7 @@ namespace easy2d
EventListener( EventListener(
EventType type, EventType type,
EventCallback const& callback, EventCallback const& callback,
String const& name = L"" std::wstring const& name = L""
); );
virtual ~EventListener(); virtual ~EventListener();
@ -50,15 +50,15 @@ namespace easy2d
void Stop(); void Stop();
void SetName(String const& name); void SetName(std::wstring const& name);
bool IsRunning() const; bool IsRunning() const;
String const& GetName() const; std::wstring const& GetName() const;
protected: protected:
bool running_; bool running_;
String name_; std::wstring name_;
EventType type_; EventType type_;
EventCallback callback_; EventCallback callback_;
}; };

View File

@ -150,7 +150,7 @@ namespace easy2d
return hr; return hr;
} }
HRESULT FactoryImpl::CreateBitmapFromFile(cpBitmap & bitmap, cpRenderTarget const & rt, String const & file_path) HRESULT FactoryImpl::CreateBitmapFromFile(cpBitmap & bitmap, cpRenderTarget const & rt, std::wstring const & file_path)
{ {
if (imaging_factory_ == nullptr) if (imaging_factory_ == nullptr)
{ {
@ -361,7 +361,7 @@ namespace easy2d
cpTransformedGeometry transformed_tmp; cpTransformedGeometry transformed_tmp;
HRESULT hr = factory_->CreateTransformedGeometry( HRESULT hr = factory_->CreateTransformedGeometry(
geo.Get(), geo.Get(),
ConvertToD2DMatrix(matrix), matrix,
&transformed_tmp &transformed_tmp
); );
@ -418,7 +418,7 @@ namespace easy2d
return hr; return hr;
} }
HRESULT FactoryImpl::CreateTextLayout(cpTextLayout & text_layout, Size& layout_size, String const & text, cpTextFormat const& text_format, TextStyle const & text_style) const HRESULT FactoryImpl::CreateTextLayout(cpTextLayout & text_layout, Size& layout_size, std::wstring const & text, cpTextFormat const& text_format, TextStyle const & text_style) const
{ {
if (!write_factory_) if (!write_factory_)
return E_UNEXPECTED; return E_UNEXPECTED;

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "Singleton.hpp" #include "Singleton.hpp"
#include "Font.hpp" #include "Font.hpp"
#include "Resource.h" #include "Resource.h"
@ -52,7 +52,7 @@ namespace easy2d
HRESULT CreateBitmapFromFile( HRESULT CreateBitmapFromFile(
cpBitmap& bitmap, cpBitmap& bitmap,
cpRenderTarget const& rt, cpRenderTarget const& rt,
String const& file_path std::wstring const& file_path
); );
HRESULT CreateBitmapFromResource( HRESULT CreateBitmapFromResource(
@ -99,7 +99,7 @@ namespace easy2d
HRESULT CreateTextLayout( HRESULT CreateTextLayout(
cpTextLayout& text_layout, cpTextLayout& text_layout,
Size& layout_size, Size& layout_size,
String const& text, std::wstring const& text,
cpTextFormat const& text_format, cpTextFormat const& text_format,
TextStyle const& text_style TextStyle const& text_style
) const; ) const;

View File

@ -19,14 +19,14 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "time.h" #include "time.h"
namespace easy2d namespace easy2d
{ {
// Ö¡¼¯ºÏ // Ö¡¼¯ºÏ
class Frames class Frames
: public ObjectBase : public Object
{ {
using Images = std::vector< spImage >; using Images = std::vector< spImage >;

View File

@ -23,7 +23,7 @@
#include "modules.h" #include "modules.h"
#include "Factory.h" #include "Factory.h"
#include "Scene.h" #include "Scene.h"
#include "Debuger.h" #include "DebugNode.h"
#include "Transition.h" #include "Transition.h"
#include "KeyEvent.hpp" #include "KeyEvent.hpp"
#include "MouseEvent.hpp" #include "MouseEvent.hpp"
@ -206,7 +206,7 @@ namespace easy2d
next_scene_->Update(dt); next_scene_->Update(dt);
if (debug_) if (debug_)
Debuger::Instance()->Update(dt); DebugNode::Instance()->Update(dt);
if (transition_) if (transition_)
{ {
@ -250,22 +250,7 @@ namespace easy2d
} }
if (debug_) if (debug_)
{ DebugNode::Instance()->Render();
graphics->SetTransform(math::Matrix());
graphics->SetOpacity(1.f);
if (curr_scene_)
{
curr_scene_->DrawBorder();
}
if (next_scene_)
{
next_scene_->DrawBorder();
}
Debuger::Instance()->Render();
}
ThrowIfFailed( ThrowIfFailed(
graphics->EndDraw() graphics->EndDraw()

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "time.h" #include "time.h"
#include "window.h" #include "window.h"
#include "render.h" #include "render.h"
@ -31,7 +31,7 @@ namespace easy2d
{ {
struct Options struct Options
{ {
String title; // ±êÌâ std::wstring title; // ±êÌâ
int width; // 宽度 int width; // 宽度
int height; // 高度 int height; // 高度
LPCWSTR icon; // 图标 LPCWSTR icon; // 图标

View File

@ -44,10 +44,7 @@ namespace easy2d
D2D1_RECT_F rect; D2D1_RECT_F rect;
// no matter it failed or not // no matter it failed or not
geo_->GetBounds( geo_->GetBounds(D2D1::Matrix3x2F::Identity(), &rect);
ConvertToD2DMatrix(GetTransformMatrix()),
&rect
);
return rect; return rect;
} }
@ -57,10 +54,7 @@ namespace easy2d
if (geo_) if (geo_)
{ {
// no matter it failed or not // no matter it failed or not
geo_->ComputeLength( geo_->ComputeLength(D2D1::Matrix3x2F::Identity(), &length);
ConvertToD2DMatrix(GetTransformMatrix()),
&length
);
} }
return length; return length;
} }
@ -72,7 +66,7 @@ namespace easy2d
D2D1_POINT_2F point_tmp, tangent_tmp; D2D1_POINT_2F point_tmp, tangent_tmp;
if (SUCCEEDED(geo_->ComputePointAtLength( if (SUCCEEDED(geo_->ComputePointAtLength(
length, length,
ConvertToD2DMatrix(GetTransformMatrix()), D2D1::Matrix3x2F::Identity(),
&point_tmp, &point_tmp,
&tangent_tmp))) &tangent_tmp)))
{ {
@ -93,10 +87,7 @@ namespace easy2d
float area = 0.f; float area = 0.f;
// no matter it failed or not // no matter it failed or not
geo_->ComputeArea( geo_->ComputeArea(D2D1::Matrix3x2F::Identity(), &area);
ConvertToD2DMatrix(GetTransformMatrix()),
&area
);
return area; return area;
} }
@ -109,37 +100,12 @@ namespace easy2d
// no matter it failed or not // no matter it failed or not
geo_->FillContainsPoint( geo_->FillContainsPoint(
point, point,
ConvertToD2DMatrix(GetTransformMatrix()), D2D1::Matrix3x2F::Identity(),
&ret &ret
); );
return !!ret; return !!ret;
} }
GeometryRelation Geometry::GetRelationWith(spGeometry const & other)
{
if (!geo_ || !other->geo_)
return GeometryRelation::Unknown;
cpTransformedGeometry transformed;
HRESULT hr = Factory::Instance()->CreateTransformedGeometry(
transformed,
GetTransformMatrix(),
geo_.Get()
);
D2D1_GEOMETRY_RELATION relation = D2D1_GEOMETRY_RELATION_UNKNOWN;
if (SUCCEEDED(hr))
{
transformed->CompareWithGeometry(
other->geo_.Get(),
ConvertToD2DMatrix(other->GetTransformMatrix()),
&relation
);
}
return GeometryRelation(relation);
}
//------------------------------------------------------- //-------------------------------------------------------
// LineGeometry // LineGeometry

View File

@ -19,25 +19,13 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "Unit.h"
namespace easy2d namespace easy2d
{ {
// 섯부暠近쇌宮슥밑溝
enum class GeometryRelation : int
{
Unknown,
Disjoin, // 轟슥섞
IsContained, // 굳관벵
Contains, // 관벵
Overlap // 路딸
};
// 几何抽象 // 几何抽象
class Geometry class Geometry
: public Unit : public RefCounter
{ {
friend class Canvas; friend class Canvas;
friend class GeometryNode; friend class GeometryNode;
@ -55,11 +43,6 @@ namespace easy2d
Point const& point Point const& point
); );
// 털뙤좃暠近宮슥榴檄
GeometryRelation GetRelationWith(
spGeometry const& other
);
// 获取图形展开成一条直线的长度 // 获取图形展开成一条直线的长度
float GetLength(); float GetLength();

View File

@ -72,11 +72,6 @@ namespace easy2d
{ {
auto graphics = Graphics::Instance(); auto graphics = Graphics::Instance();
if (geometry_->GetTransformMatrix().IsIdentity())
graphics->SetTransform(GetTransformMatrix());
else
graphics->SetTransform(geometry_->GetTransformMatrix() * GetTransformMatrix());
graphics->FillGeometry( graphics->FillGeometry(
geometry_->geo_, geometry_->geo_,
fill_color_ fill_color_

View File

@ -22,6 +22,7 @@
#include "render.h" #include "render.h"
#include "logs.h" #include "logs.h"
#include "../utils/File.h" #include "../utils/File.h"
#include "../utils/string.h"
namespace easy2d namespace easy2d
{ {
@ -44,13 +45,13 @@ namespace easy2d
this->Crop(crop_rect); this->Crop(crop_rect);
} }
Image::Image(String const& file_name) Image::Image(std::wstring const& file_name)
: Image() : Image()
{ {
this->Load(file_name); this->Load(file_name);
} }
Image::Image(String const& file_name, const Rect & crop_rect) Image::Image(std::wstring const& file_name, const Rect & crop_rect)
: Image() : Image()
{ {
this->Load(file_name); this->Load(file_name);
@ -80,18 +81,18 @@ namespace easy2d
return true; return true;
} }
bool Image::Load(String const& file_name) bool Image::Load(std::wstring const& file_name)
{ {
File image_file; File image_file;
if (!image_file.Open(file_name)) if (!image_file.Open(file_name))
{ {
logs::Warningln("Image file '%s' not found!", file_name.c_str()); logs::Warningln("Image file '%s' not found!", StringWideCharToMultiByte(file_name).c_str());
return false; return false;
} }
// 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加 // 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加
// 默认搜索路径,所以需要通过 File::GetPath 获取完整路径 // 默认搜索路径,所以需要通过 File::GetPath 获取完整路径
String image_file_path = image_file.GetPath(); std::wstring image_file_path = image_file.GetPath();
cpBitmap bitmap; cpBitmap bitmap;
HRESULT hr = Graphics::Instance()->CreateBitmapFromFile(bitmap, image_file_path); HRESULT hr = Graphics::Instance()->CreateBitmapFromFile(bitmap, image_file_path);

View File

@ -19,14 +19,14 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "Resource.h" #include "Resource.h"
namespace easy2d namespace easy2d
{ {
// 图片 // 图片
class Image class Image
: public ObjectBase : public Object
{ {
public: public:
Image(); Image();
@ -41,11 +41,11 @@ namespace easy2d
); );
explicit Image( explicit Image(
String const& file_name std::wstring const& file_name
); );
explicit Image( explicit Image(
String const& file_name, std::wstring const& file_name,
Rect const& crop_rect /* 裁剪矩形 */ Rect const& crop_rect /* 裁剪矩形 */
); );
@ -62,7 +62,7 @@ namespace easy2d
// 加载图片资源 // 加载图片资源
bool Load( bool Load(
String const& file_name std::wstring const& file_name
); );
// 将图片裁剪为矩形 // 将图片裁剪为矩形

View File

@ -19,11 +19,21 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "keys.hpp"
#include "Singleton.hpp" #include "Singleton.hpp"
namespace easy2d namespace easy2d
{ {
// 報炎囚峙
enum class MouseButton : int
{
Left = VK_LBUTTON, // 報炎恣囚
Right = VK_RBUTTON, // 報炎嘔囚
Middle = VK_MBUTTON // 報炎嶄囚
};
class InputDevice class InputDevice
: protected Noncopyable : protected Noncopyable
{ {

View File

@ -20,7 +20,7 @@
#pragma once #pragma once
#include "Event.hpp" #include "Event.hpp"
#include "BaseTypes.hpp" #include "keys.hpp"
namespace easy2d namespace easy2d
{ {

View File

@ -21,6 +21,7 @@
#include "Music.h" #include "Music.h"
#include "../utils/Transcoder.h" #include "../utils/Transcoder.h"
#include "../utils/File.h" #include "../utils/File.h"
#include "../utils/string.h"
#include "modules.h" #include "modules.h"
#include "audio.h" #include "audio.h"
#include "logs.h" #include "logs.h"
@ -36,7 +37,7 @@ namespace easy2d
{ {
} }
Music::Music(String const& file_path) Music::Music(std::wstring const& file_path)
: opened_(false) : opened_(false)
, playing_(false) , playing_(false)
, wave_data_(nullptr) , wave_data_(nullptr)
@ -61,7 +62,7 @@ namespace easy2d
Close(); Close();
} }
bool Music::Load(String const& file_path) bool Music::Load(std::wstring const& file_path)
{ {
if (opened_) if (opened_)
{ {
@ -71,13 +72,13 @@ namespace easy2d
File music_file; File music_file;
if (!music_file.Open(file_path)) if (!music_file.Open(file_path))
{ {
logs::Warningln("Media file '%s' not found", file_path.c_str()); logs::Warningln("Media file '%s' not found", StringWideCharToMultiByte(file_path).c_str());
return false; return false;
} }
// 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加 // 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加
// 默认搜索路径,所以需要通过 File::GetPath 获取完整路径 // 默认搜索路径,所以需要通过 File::GetPath 获取完整路径
String music_file_path = music_file.GetPath(); std::wstring music_file_path = music_file.GetPath();
Transcoder transcoder; Transcoder transcoder;
HRESULT hr = transcoder.LoadMediaFile(music_file_path.c_str(), &wave_data_, &size_); HRESULT hr = transcoder.LoadMediaFile(music_file_path.c_str(), &wave_data_, &size_);

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "audio.h" #include "audio.h"
#include "Resource.h" #include "Resource.h"
@ -27,13 +27,13 @@ namespace easy2d
{ {
// 稜있 // 稜있
class Music class Music
: public ObjectBase : public Object
{ {
public: public:
Music(); Music();
Music( Music(
String const& file_path /* 音乐文件路径 */ std::wstring const& file_path /* 音乐文件路径 */
); );
Music( Music(
@ -44,7 +44,7 @@ namespace easy2d
// 댔역稜있匡숭 // 댔역稜있匡숭
bool Load( bool Load(
String const& file_path /* 音乐文件路径 */ std::wstring const& file_path /* 音乐文件路径 */
); );
// 댔역稜있栗都 // 댔역稜있栗都

View File

@ -32,7 +32,6 @@ namespace easy2d
{ {
float default_pivot_x = 0.f; float default_pivot_x = 0.f;
float default_pivot_y = 0.f; float default_pivot_y = 0.f;
bool border_enabled = false;
} }
void Node::SetDefaultPivot(float pivot_x, float pivot_y) void Node::SetDefaultPivot(float pivot_x, float pivot_y)
@ -41,58 +40,30 @@ namespace easy2d
default_pivot_y = pivot_y; default_pivot_y = pivot_y;
} }
void easy2d::Node::EnableBorder()
{
border_enabled = true;
}
void easy2d::Node::DisableBorder()
{
border_enabled = false;
}
Node::Node() Node::Node()
: inited_(false) : visible_(true)
, visible_(true) , dirty_transform_(false)
, dirty_sort_(false)
, parent_(nullptr) , parent_(nullptr)
, hash_name_(0) , hash_name_(0)
, z_order_(0) , z_order_(0)
, opacity_(1.f) , opacity_(1.f)
, display_opacity_(1.f) , display_opacity_(1.f)
, children_()
, border_color_(Color::Red, 0.6f)
, initial_matrix_()
, final_matrix_()
, pivot_(default_pivot_x, default_pivot_y) , pivot_(default_pivot_x, default_pivot_y)
, size_()
{ {
} }
void Node::Init()
{
inited_ = true;
}
void Node::OnRender()
{
// normal node renders nothing
}
void Node::Update(Duration const & dt) void Node::Update(Duration const & dt)
{ {
if (!inited_) OnUpdate(dt);
{
Init();
}
UpdateActions(this, dt); UpdateActions(this, dt);
UpdateTasks(dt); UpdateTasks(dt);
if (!children_.IsEmpty()) if (!children_.IsEmpty())
{ {
for (auto child = children_.First(); child; child = child->NextItem()) spNode next;
for (auto child = children_.First(); child; child = next)
{ {
next = child->NextItem();
child->Update(dt); child->Update(dt);
} }
} }
@ -109,39 +80,33 @@ namespace easy2d
if (children_.IsEmpty()) if (children_.IsEmpty())
{ {
graphics->SetTransform(final_matrix_); graphics->SetTransform(transform_matrix_);
graphics->SetOpacity(display_opacity_); graphics->SetOpacity(display_opacity_);
OnRender(); OnRender();
} }
else else
{ {
SortChildren();
// render children those are less than 0 in Z-Order // render children those are less than 0 in Z-Order
spNode child = children_.First(); Node* child = children_.First().Get();
for (spNode next; child; child = next) while (child)
{
next = child->NextItem();
if (child->GetZOrder() < 0)
{
child->Render();
}
else
{ {
if (child->GetZOrder() >= 0)
break; break;
}
child->Render();
child = child->NextItem().Get();
} }
graphics->SetTransform(final_matrix_); graphics->SetTransform(transform_matrix_);
graphics->SetOpacity(display_opacity_); graphics->SetOpacity(display_opacity_);
OnRender(); OnRender();
for (spNode next; child; child = next) while (child)
{ {
next = child->NextItem();
child->Render(); child->Render();
child = child->NextItem().Get();
} }
} }
} }
@ -169,38 +134,10 @@ namespace easy2d
} }
} }
void Node::DrawBorder()
{
if (visible_)
{
if (border_)
{
Graphics::Instance()->DrawGeometry(border_, border_color_, 1.5f);
}
for (auto child = children_.First(); child; child = child->NextItem())
{
child->DrawBorder();
}
}
}
void Node::SortChildren()
{
if (dirty_sort_)
{
children_.Sort(
[](spNode const& n1, spNode const& n2) { return n1->GetZOrder() < n2->GetZOrder(); }
);
dirty_sort_ = false;
}
}
math::Matrix const & Node::GetTransformMatrix() math::Matrix const & Node::GetTransformMatrix()
{ {
UpdateTransform(); UpdateTransform();
return final_matrix_; return transform_matrix_;
} }
spNode Node::GetParent() const spNode Node::GetParent() const
@ -220,67 +157,30 @@ namespace easy2d
dirty_transform_ = false; dirty_transform_ = false;
Point center{ size_.width * pivot_.x, size_.height * pivot_.y }; // matrix multiplication is optimized by expression template
final_matrix_ = math::Matrix::Scaling(transform_.scale, center) transform_matrix_ = math::Matrix::Scaling(transform_.scale)
* math::Matrix::Skewing(transform_.skew.x, transform_.skew.y, center) * math::Matrix::Skewing(transform_.skew.x, transform_.skew.y)
* math::Matrix::Rotation(transform_.rotation, center) * math::Matrix::Rotation(transform_.rotation)
* math::Matrix::Translation(transform_.position - center); * math::Matrix::Translation(transform_.position);
initial_matrix_ = final_matrix_ * math::Matrix::Translation( Point offset{ -size_.width * pivot_.x, -size_.height * pivot_.y };
Point{ size_.width * pivot_.x, size_.height * pivot_.y } transform_matrix_.Translate(offset);
);
if (parent_) if (parent_)
{ transform_matrix_ = transform_matrix_ * parent_->transform_matrix_;
initial_matrix_ = initial_matrix_ * parent_->initial_matrix_;
final_matrix_ = final_matrix_ * parent_->initial_matrix_;
}
// update children's transform // update children's transform
for (auto child = children_.First(); child; child = child->NextItem()) for (Node* child = children_.First().Get(); child; child = child->NextItem().Get())
{
child->dirty_transform_ = true; child->dirty_transform_ = true;
} }
// update border
if (border_enabled)
{
UpdateBorder();
}
}
void Node::UpdateBorder()
{
cpRectangleGeometry rect;
cpTransformedGeometry transformed;
HRESULT hr = Factory::Instance()->CreateRectangleGeometry(
rect,
Rect(Point{}, size_)
);
if (SUCCEEDED(hr))
{
hr = Factory::Instance()->CreateTransformedGeometry(
transformed,
final_matrix_,
rect
);
}
if (SUCCEEDED(hr))
{
border_ = transformed;
}
}
void Node::UpdateOpacity() void Node::UpdateOpacity()
{ {
if (parent_) if (parent_)
{ {
display_opacity_ = opacity_ * parent_->display_opacity_; display_opacity_ = opacity_ * parent_->display_opacity_;
} }
for (auto child = children_.First(); child; child = child->NextItem()) for (Node* child = children_.First().Get(); child; child = child->NextItem().Get())
{ {
child->UpdateOpacity(); child->UpdateOpacity();
} }
@ -289,21 +189,44 @@ namespace easy2d
void Node::SetScene(Scene * scene) void Node::SetScene(Scene * scene)
{ {
scene_ = scene; scene_ = scene;
for (auto child = children_.First(); child; child = child->NextItem()) for (Node* child = children_.First().Get(); child; child = child->NextItem().Get())
{ {
child->scene_ = scene; child->scene_ = scene;
} }
} }
void Node::SetZOrder(int order) void Node::SetZOrder(int zorder)
{ {
if (z_order_ == order) if (z_order_ == zorder)
return; return;
z_order_ = order; z_order_ = zorder;
if (parent_) if (parent_)
{ {
parent_->dirty_sort_ = true; spNode me = this;
parent_->children_.Remove(me);
Node* sibling = parent_->children_.Last().Get();
if (sibling && sibling->GetZOrder() > zorder)
{
while (sibling = sibling->PrevItem().Get())
{
if (sibling->GetZOrder() <= zorder)
break;
}
}
if (sibling)
{
parent_->children_.InsertAfter(me, spNode(sibling));
}
else
{
parent_->children_.PushFront(me);
}
} }
} }
@ -367,26 +290,110 @@ namespace easy2d
dirty_transform_ = true; dirty_transform_ = true;
} }
void Node::SetBorderColor(Color const& color)
{
border_color_ = color;
}
void Node::SetVisible(bool val) void Node::SetVisible(bool val)
{ {
visible_ = val; visible_ = val;
} }
void Node::SetName(String const& name) void Node::SetName(std::wstring const& name)
{ {
if (name_ != name) if (name_ != name)
{ {
name_ = name; name_ = name;
hash_name_ = std::hash<String>{}(name); hash_name_ = std::hash<std::wstring>{}(name);
} }
} }
void Node::AddChild(spNode const& child, int z_order) void Node::SetPositionX(float x)
{
this->SetPosition(x, transform_.position.y);
}
void Node::SetPositionY(float y)
{
this->SetPosition(transform_.position.x, y);
}
void Node::SetPosition(const Point & p)
{
this->SetPosition(p.x, p.y);
}
void Node::SetPosition(float x, float y)
{
if (transform_.position.x == x && transform_.position.y == y)
return;
transform_.position.x = x;
transform_.position.y = y;
dirty_transform_ = true;
}
void Node::Move(float x, float y)
{
this->SetPosition(transform_.position.x + x, transform_.position.y + y);
}
void Node::Move(const Point & v)
{
this->Move(v.x, v.y);
}
void Node::SetScaleX(float scale_x)
{
this->SetScale(scale_x, transform_.scale.y);
}
void Node::SetScaleY(float scale_y)
{
this->SetScale(transform_.scale.x, scale_y);
}
void Node::SetScale(float scale)
{
this->SetScale(scale, scale);
}
void Node::SetScale(float scale_x, float scale_y)
{
if (transform_.scale.x == scale_x && transform_.scale.y == scale_y)
return;
transform_.scale.x = scale_x;
transform_.scale.y = scale_y;
dirty_transform_ = true;
}
void Node::SetSkewX(float skew_x)
{
this->SetSkew(skew_x, transform_.skew.y);
}
void Node::SetSkewY(float skew_y)
{
this->SetSkew(transform_.skew.x, skew_y);
}
void Node::SetSkew(float skew_x, float skew_y)
{
if (transform_.skew.x == skew_x && transform_.skew.y == skew_y)
return;
transform_.skew.x = skew_x;
transform_.skew.y = skew_y;
dirty_transform_ = true;
}
void Node::SetRotation(float angle)
{
if (transform_.rotation == angle)
return;
transform_.rotation = angle;
dirty_transform_ = true;
}
void Node::AddChild(spNode const& child)
{ {
E2D_ASSERT(child && "Node::AddChild failed, NULL pointer exception"); E2D_ASSERT(child && "Node::AddChild failed, NULL pointer exception");
@ -407,18 +414,16 @@ namespace easy2d
child->parent_ = this; child->parent_ = this;
child->SetScene(this->scene_); child->SetScene(this->scene_);
child->dirty_transform_ = true; child->dirty_transform_ = true;
child->SetZOrder(z_order);
child->UpdateOpacity(); child->UpdateOpacity();
child->SetZOrder(child->GetZOrder());
dirty_sort_ = true;
} }
} }
void Node::AddChild(const Nodes& nodes, int z_order) void Node::AddChildren(const Nodes& children)
{ {
for (const auto& node : nodes) for (const auto& node : children)
{ {
this->AddChild(node, z_order); this->AddChild(node);
} }
} }
@ -427,12 +432,12 @@ namespace easy2d
return Rect(Point{}, size_); return Rect(Point{}, size_);
} }
Node::Nodes Node::GetChildren(String const& name) const Node::Nodes Node::GetChildren(std::wstring const& name) const
{ {
Nodes children; Nodes children;
size_t hash_code = std::hash<String>{}(name); size_t hash_code = std::hash<std::wstring>{}(name);
for (auto child = children_.First(); child != children_.Last(); child = child->NextItem()) for (Node* child = children_.First().Get(); child; child = child->NextItem().Get())
{ {
if (child->hash_name_ == hash_code && child->name_ == name) if (child->hash_name_ == hash_code && child->name_ == name)
{ {
@ -442,11 +447,11 @@ namespace easy2d
return children; return children;
} }
spNode Node::GetChild(String const& name) const spNode Node::GetChild(std::wstring const& name) const
{ {
size_t hash_code = std::hash<String>{}(name); size_t hash_code = std::hash<std::wstring>{}(name);
for (auto child = children_.First(); child != children_.Last(); child = child->NextItem()) for (Node* child = children_.First().Get(); child; child = child->NextItem().Get())
{ {
if (child->hash_name_ == hash_code && child->name_ == name) if (child->hash_name_ == hash_code && child->name_ == name)
{ {
@ -470,6 +475,11 @@ namespace easy2d
} }
bool Node::RemoveChild(spNode const& child) bool Node::RemoveChild(spNode const& child)
{
return RemoveChild(child.Get());
}
bool Node::RemoveChild(Node * child)
{ {
E2D_ASSERT(child && "Node::RemoveChild failed, NULL pointer exception"); E2D_ASSERT(child && "Node::RemoveChild failed, NULL pointer exception");
@ -480,24 +490,25 @@ namespace easy2d
{ {
child->parent_ = nullptr; child->parent_ = nullptr;
if (child->scene_) child->SetScene(nullptr); if (child->scene_) child->SetScene(nullptr);
children_.Remove(Node::ItemType(child)); children_.Remove(spNode(child));
return true; return true;
} }
return false; return false;
} }
void Node::RemoveChildren(String const& child_name) void Node::RemoveChildren(std::wstring const& child_name)
{ {
if (children_.IsEmpty()) if (children_.IsEmpty())
{ {
return; return;
} }
size_t hash_code = std::hash<String>{}(child_name); size_t hash_code = std::hash<std::wstring>{}(child_name);
spNode next;
for (auto child = children_.First(); child; child = next) Node* next;
for (Node* child = children_.First().Get(); child; child = next)
{ {
next = child->NextItem(); next = child->NextItem().Get();
if (child->hash_name_ == hash_code && child->name_ == child_name) if (child->hash_name_ == hash_code && child->name_ == child_name)
{ {
@ -529,11 +540,7 @@ namespace easy2d
BOOL ret = 0; BOOL ret = 0;
// no matter it failed or not // no matter it failed or not
border->FillContainsPoint( border->FillContainsPoint(point, transform_matrix_, &ret);
point,
ConvertToD2DMatrix(final_matrix_),
&ret
);
return !!ret; return !!ret;
} }
} }

View File

@ -19,9 +19,9 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "time.h" #include "time.h"
#include "Unit.h" #include "Transform.hpp"
#include "TaskManager.h" #include "TaskManager.h"
#include "ActionManager.h" #include "ActionManager.h"
#include "EventDispatcher.h" #include "EventDispatcher.h"
@ -33,7 +33,7 @@ namespace easy2d
// 节点 // 节点
class Node class Node
: public Unit : public Object
, public TaskManager , public TaskManager
, public ActionManager , public ActionManager
, public EventDispatcher , public EventDispatcher
@ -50,14 +50,11 @@ namespace easy2d
public: public:
Node(); Node();
// 初始化节点
virtual void Init();
// 更新节点 // 更新节点
virtual void Update(Duration const& dt); virtual void OnUpdate(Duration const& dt) {}
// 渲染节点 // 渲染节点
virtual void OnRender(); virtual void OnRender() {}
// 处理事件 // 处理事件
virtual void HandleEvent(Event* e); virtual void HandleEvent(Event* e);
@ -66,7 +63,7 @@ namespace easy2d
bool IsVisible() const { return visible_; } bool IsVisible() const { return visible_; }
// 获取名称 // 获取名称
String const& GetName() const { return name_; } std::wstring const& GetName() const { return name_; }
// 获取名称的 Hash 值 // 获取名称的 Hash 值
size_t GetHashName() const { return hash_name_; } size_t GetHashName() const { return hash_name_; }
@ -74,29 +71,65 @@ namespace easy2d
// 获取 Z 轴顺序 // 获取 Z 轴顺序
int GetZOrder() const { return z_order_; } int GetZOrder() const { return z_order_; }
// 获取坐标
Point const& GetPosition() const { return transform_.position; }
// 获取 x 坐标
float GetPositionX() const { return transform_.position.x; }
// 获取 y 坐标
float GetPositionY() const { return transform_.position.y; }
// 获取横向缩放比例
float GetScaleX() const { return transform_.scale.x; }
// 获取纵向缩放比例
float GetScaleY() const { return transform_.scale.y; }
// 获取横向错切角度
float GetSkewX() const { return transform_.skew.x; }
// 获取纵向错切角度
float GetSkewY() const { return transform_.skew.y; }
// 获取旋转角度
float GetRotation() const { return transform_.rotation; }
// 获取宽度 // 获取宽度
virtual float GetWidth() const { return size_.width * transform_.scale.x; } float GetWidth() const { return size_.width; }
// 获取高度 // 获取高度
virtual float GetHeight() const { return size_.height * transform_.scale.y; } float GetHeight() const { return size_.height; }
// 获取大小 // 获取大小
Size GetSize() const { return Size{ GetWidth(), GetHeight() }; } Size const& GetSize() const { return size_; }
// 获取缩放后的宽度
float GetScaledWidth() const { return size_.width * transform_.scale.x; }
// 获取缩放后的高度
float GetScaledHeight() const { return size_.height * transform_.scale.y; }
// 获取缩放后的大小
Size GetScaledSize() const { return Size{ GetScaledWidth(), GetScaledHeight() }; }
// 获取 x 方向支点 // 获取 x 方向支点
virtual float GetPivotX() const { return pivot_.x; } float GetPivotX() const { return pivot_.x; }
// 获取 y 方向支点 // 获取 y 方向支点
virtual float GetPivotY() const { return pivot_.y; } float GetPivotY() const { return pivot_.y; }
// 获取透明度 // 获取透明度
virtual float GetOpacity() const { return opacity_; } float GetOpacity() const { return opacity_; }
// 获取变换
Transform const& GetTransform() const { return transform_; }
// 获取包围盒 // 获取包围盒
virtual Rect GetBounds(); virtual Rect GetBounds();
// 获取二维变换矩阵 // 获取二维变换矩阵
virtual math::Matrix const& GetTransformMatrix() override; math::Matrix const& GetTransformMatrix();
// 获取父节点 // 获取父节点
spNode GetParent() const; spNode GetParent() const;
@ -111,7 +144,89 @@ namespace easy2d
// 设置名称 // 设置名称
void SetName( void SetName(
String const& name std::wstring const& name
);
// 设置横坐标
void SetPositionX(
float x
);
// 设置纵坐标
void SetPositionY(
float y
);
// 设置坐标
void SetPosition(
const Point & point
);
// 设置坐标
void SetPosition(
float x,
float y
);
// 移动
void Move(
float x,
float y
);
// 移动
void Move(
const Point & vector
);
// 设置横向缩放比例
// 默认为 1.0
void SetScaleX(
float scale_x
);
// 设置纵向缩放比例
// 默认为 1.0
void SetScaleY(
float scale_y
);
// 设置缩放比例
// 默认为 (1.0, 1.0)
void SetScale(
float scale_x,
float scale_y
);
// 设置缩放比例
// 默认为 1.0
void SetScale(
float scale
);
// 设置横向错切角度
// 默认为 0
void SetSkewX(
float skew_x
);
// 设置纵向错切角度
// 默认为 0
void SetSkewY(
float skew_y
);
// 设置错切角度
// 默认为 (0, 0)
void SetSkew(
float skew_x,
float skew_y
);
// 设置旋转角度
// 默认为 0
void SetRotation(
float rotation
); );
// 设置支点的横向位置 // 设置支点的横向位置
@ -154,9 +269,9 @@ namespace easy2d
const Size & size const Size & size
); );
virtual void SetTransform( void SetTransform(
Transform const& transform Transform const& transform
) override; );
// 设置透明度 // 设置透明度
// 默认为 1.0, 范围 [0, 1] // 默认为 1.0, 范围 [0, 1]
@ -167,12 +282,7 @@ namespace easy2d
// 设置 Z 轴顺序 // 设置 Z 轴顺序
// 默认为 0 // 默认为 0
void SetZOrder( void SetZOrder(
int order int zorder
);
// 设置边框颜色
void SetBorderColor(
const Color& color
); );
// 判断点是否在节点内 // 判断点是否在节点内
@ -182,24 +292,22 @@ namespace easy2d
// 添加子节点 // 添加子节点
void AddChild( void AddChild(
spNode const& child, spNode const& child
int z_order = 0 /* Z 轴顺序 */
); );
// 添加多个子节点 // 添加多个子节点
void AddChild( void AddChildren(
const Nodes& nodes, /* 节点数组 */ const Nodes& children
int z_order = 0 /* Z 轴顺序 */
); );
// 获取所有名称相同的子节点 // 获取所有名称相同的子节点
Nodes GetChildren( Nodes GetChildren(
String const& name std::wstring const& name
) const; ) const;
// 获取名称相同的子节点 // 获取名称相同的子节点
spNode GetChild( spNode GetChild(
String const& name std::wstring const& name
) const; ) const;
// 获取全部子节点 // 获取全部子节点
@ -210,9 +318,14 @@ namespace easy2d
spNode const& child spNode const& child
); );
// 移除子节点
bool RemoveChild(
Node* child
);
// 移除所有名称相同的子节点 // 移除所有名称相同的子节点
void RemoveChildren( void RemoveChildren(
String const& child_name std::wstring const& child_name
); );
// 移除所有节点 // 移除所有节点
@ -229,21 +342,11 @@ namespace easy2d
float pivot_y float pivot_y
); );
// 启用边框自动生成
static void EnableBorder();
// 禁用边框自动生成
static void DisableBorder();
protected: protected:
void Update(Duration const& dt);
void Render(); void Render();
void DrawBorder();
void SortChildren();
void UpdateBorder();
void UpdateTransform(); void UpdateTransform();
void UpdateOpacity(); void UpdateOpacity();
@ -251,22 +354,19 @@ namespace easy2d
void SetScene(Scene* scene); void SetScene(Scene* scene);
protected: protected:
bool inited_;
bool visible_; bool visible_;
bool dirty_sort_; bool dirty_transform_;
int z_order_; int z_order_;
float opacity_; float opacity_;
float display_opacity_; float display_opacity_;
String name_; std::wstring name_;
size_t hash_name_; size_t hash_name_;
Node* parent_; Transform transform_;
Scene* scene_; math::Matrix transform_matrix_;
Color border_color_;
Children children_;
cpGeometry border_;
Point pivot_; Point pivot_;
Size size_; Size size_;
math::Matrix initial_matrix_; Node* parent_;
math::Matrix final_matrix_; Scene* scene_;
Children children_;
}; };
} }

View File

@ -18,51 +18,61 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#include "ObjectBase.h" #include "Object.h"
namespace easy2d namespace easy2d
{ {
namespace namespace
{ {
bool tracing_leaks = true; bool tracing_leaks = true;
std::vector<ObjectBase*> tracing_objects; std::vector<Object*> tracing_objects;
} }
ObjectBase::ObjectBase() Object::Object()
: tracing_leak_(false) : tracing_leak_(false)
{ {
#ifdef E2D_DEBUG #ifdef E2D_DEBUG
ObjectBase::__AddObjectToTracingList(this); Object::__AddObjectToTracingList(this);
#endif #endif
} }
ObjectBase::~ObjectBase() Object::~Object()
{ {
#ifdef E2D_DEBUG #ifdef E2D_DEBUG
ObjectBase::__RemoveObjectFromTracingList(this); Object::__RemoveObjectFromTracingList(this);
#endif #endif
} }
void ObjectBase::StartTracingLeaks() void * Object::GetUserData() const
{
return user_data_;
}
void Object::SetUserData(void * data)
{
user_data_ = data;
}
void Object::StartTracingLeaks()
{ {
tracing_leaks = true; tracing_leaks = true;
} }
void ObjectBase::StopTracingLeaks() void Object::StopTracingLeaks()
{ {
tracing_leaks = false; tracing_leaks = false;
} }
std::vector<ObjectBase*> const& easy2d::ObjectBase::__GetTracingObjects() std::vector<Object*> const& easy2d::Object::__GetTracingObjects()
{ {
return tracing_objects; return tracing_objects;
} }
void ObjectBase::__AddObjectToTracingList(ObjectBase * obj) void Object::__AddObjectToTracingList(Object * obj)
{ {
#ifdef E2D_DEBUG #ifdef E2D_DEBUG
@ -75,7 +85,7 @@ namespace easy2d
#endif #endif
} }
void ObjectBase::__RemoveObjectFromTracingList(ObjectBase * obj) void Object::__RemoveObjectFromTracingList(Object * obj)
{ {
#ifdef E2D_DEBUG #ifdef E2D_DEBUG

View File

@ -20,29 +20,35 @@
#pragma once #pragma once
#include "RefCounter.hpp" #include "RefCounter.hpp"
#include <vector>
namespace easy2d namespace easy2d
{ {
class ObjectBase class Object
: public RefCounter : public RefCounter
{ {
public: public:
ObjectBase(); Object();
virtual ~ObjectBase(); virtual ~Object();
void* GetUserData() const;
void SetUserData(void* data);
static void StartTracingLeaks(); static void StartTracingLeaks();
static void StopTracingLeaks(); static void StopTracingLeaks();
static std::vector<ObjectBase*> const& __GetTracingObjects(); static std::vector<Object*> const& __GetTracingObjects();
protected: protected:
static void __AddObjectToTracingList(ObjectBase*); static void __AddObjectToTracingList(Object*);
static void __RemoveObjectFromTracingList(ObjectBase*); static void __RemoveObjectFromTracingList(Object*);
private: private:
bool tracing_leak_; bool tracing_leak_;
void* user_data_;
}; };
} }

View File

@ -76,9 +76,14 @@ namespace easy2d
return (x == other.x) && (y == other.y); return (x == other.x) && (y == other.y);
} }
inline operator D2D1_POINT_2F () const inline operator D2D1_POINT_2F const& () const
{ {
return D2D1_POINT_2F{ x, y }; return reinterpret_cast<D2D1_POINT_2F const&>(*this);
}
inline operator D2D1_POINT_2F& ()
{
return reinterpret_cast<D2D1_POINT_2F&>(*this);
} }
}; };
} }

View File

@ -19,6 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "Point.hpp"
#include <d2d1.h> #include <d2d1.h>
namespace easy2d namespace easy2d
@ -54,6 +55,12 @@ namespace easy2d
height = other.height; height = other.height;
} }
Size(const Point & p)
{
width = p.x;
height = p.y;
}
inline const Size operator+(const Size & other) const inline const Size operator+(const Size & other) const
{ {
return Size(width + other.width, height + other.height); return Size(width + other.width, height + other.height);
@ -84,9 +91,19 @@ namespace easy2d
return (width == other.width) && (height == other.height); return (width == other.width) && (height == other.height);
} }
inline operator D2D1_SIZE_F () const inline operator Point () const
{ {
return D2D1_SIZE_F{ width, height }; return Point{ width, height };
}
inline operator D2D1_SIZE_F const& () const
{
return reinterpret_cast<D2D1_SIZE_F const&>(*this);
}
inline operator D2D1_SIZE_F& ()
{
return reinterpret_cast<D2D1_SIZE_F&>(*this);
} }
}; };
} }

View File

@ -48,13 +48,13 @@ namespace easy2d
Crop(crop_rect); Crop(crop_rect);
} }
Sprite::Sprite(String const& file_name) Sprite::Sprite(std::wstring const& file_name)
: image_(nullptr) : image_(nullptr)
{ {
Load(file_name); Load(file_name);
} }
Sprite::Sprite(String const& file_name, const Rect & crop_rect) Sprite::Sprite(std::wstring const& file_name, const Rect & crop_rect)
: image_(nullptr) : image_(nullptr)
{ {
Load(file_name); Load(file_name);
@ -95,7 +95,7 @@ namespace easy2d
return false; return false;
} }
bool Sprite::Load(String const& file_name) bool Sprite::Load(std::wstring const& file_name)
{ {
if (!image_) if (!image_)
{ {

View File

@ -45,11 +45,11 @@ namespace easy2d
); );
explicit Sprite( explicit Sprite(
String const& file_name std::wstring const& file_name
); );
explicit Sprite( explicit Sprite(
String const& file_name, std::wstring const& file_name,
const Rect& crop_rect /* 裁剪矩形 */ const Rect& crop_rect /* 裁剪矩形 */
); );
@ -62,7 +62,7 @@ namespace easy2d
// 加载图片文件 // 加载图片文件
bool Load( bool Load(
String const& file_name std::wstring const& file_name
); );
// 加载图片 // 加载图片

View File

@ -22,14 +22,13 @@
namespace easy2d namespace easy2d
{ {
Task::Task(const Callback & func, String const& name) Task::Task(const Callback & func, std::wstring const& name)
: Task(func, Duration{}, -1, name) : Task(func, Duration{}, -1, name)
{ {
} }
Task::Task(Callback const& func, Duration const& delay, int times, String const& name) Task::Task(Callback const& func, Duration const& delay, int times, std::wstring const& name)
: running_(true) : running_(true)
, stopped_(false)
, run_times_(0) , run_times_(0)
, total_times_(times) , total_times_(times)
, delay_(delay) , delay_(delay)
@ -42,7 +41,6 @@ namespace easy2d
void Task::Start() void Task::Start()
{ {
running_ = true; running_ = true;
delta_ = Duration{};
} }
void Task::Stop() void Task::Stop()
@ -50,14 +48,14 @@ namespace easy2d
running_ = false; running_ = false;
} }
void Task::Update(Duration const& dt) void Task::Update(Duration const& dt, bool& remove_after_update)
{ {
if (!running_) if (!running_)
return; return;
if (total_times_ == 0) if (total_times_ == 0)
{ {
stopped_ = true; remove_after_update = true;
return; return;
} }
@ -77,7 +75,7 @@ namespace easy2d
if (run_times_ == total_times_) if (run_times_ == total_times_)
{ {
stopped_ = true; remove_after_update = true;
return; return;
} }
} }
@ -85,6 +83,7 @@ namespace easy2d
void Task::Reset() void Task::Reset()
{ {
delta_ = Duration{}; delta_ = Duration{};
run_times_ = 0;
} }
bool Task::IsRunning() const bool Task::IsRunning() const
@ -92,8 +91,9 @@ namespace easy2d
return running_; return running_;
} }
String const& Task::GetName() const std::wstring const& Task::GetName() const
{ {
return name_; return name_;
} }
} }

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "time.h" #include "time.h"
#include "intrusive/List.hpp" #include "intrusive/List.hpp"
#include <functional> #include <functional>
@ -30,7 +30,7 @@ namespace easy2d
// 定时任务 // 定时任务
class Task class Task
: public ObjectBase : public Object
, protected intrusive::ListItem<spTask> , protected intrusive::ListItem<spTask>
{ {
friend class TaskManager; friend class TaskManager;
@ -41,14 +41,14 @@ namespace easy2d
public: public:
explicit Task( explicit Task(
const Callback& func, /* 执行函数 */ const Callback& func, /* 执行函数 */
String const& name = L"" /* ÈÎÎñÃû³Æ */ std::wstring const& name = L"" /* ÈÎÎñÃû³Æ */
); );
explicit Task( explicit Task(
Callback const& func, /* 执行函数 */ Callback const& func, /* 执行函数 */
Duration const& delay, /* 时间间隔(秒) */ Duration const& delay, /* 时间间隔(秒) */
int times = -1, /* 执行次数(设 -1 为永久执行) */ int times = -1, /* 执行次数(设 -1 为永久执行) */
String const& name = L"" /* ÈÎÎñÃû³Æ */ std::wstring const& name = L"" /* ÈÎÎñÃû³Æ */
); );
// 启动任务 // 启动任务
@ -61,19 +61,18 @@ namespace easy2d
bool IsRunning() const; bool IsRunning() const;
// 获取任务名称 // 获取任务名称
String const& GetName() const; std::wstring const& GetName() const;
protected: protected:
void Update(Duration const& dt); void Update(Duration const& dt, bool& remove_after_update);
void Reset(); void Reset();
protected: protected:
bool running_; bool running_;
bool stopped_;
int run_times_; int run_times_;
int total_times_; int total_times_;
String name_; std::wstring name_;
Duration delay_; Duration delay_;
Duration delta_; Duration delta_;
Callback callback_; Callback callback_;

View File

@ -33,9 +33,10 @@ namespace easy2d
{ {
next = task->NextItem(); next = task->NextItem();
task->Update(dt); bool remove_after_update = false;
task->Update(dt, remove_after_update);
if (task->stopped_) if (remove_after_update)
tasks_.Remove(task); tasks_.Remove(task);
} }
} }
@ -51,9 +52,12 @@ namespace easy2d
} }
} }
void TaskManager::StopTasks(String const& name) void TaskManager::StopTasks(std::wstring const& name)
{ {
for (auto task = tasks_.First(); task; task = task->NextItem()) if (tasks_.IsEmpty())
return;
for (auto task = tasks_.First().Get(); task; task = task->NextItem().Get())
{ {
if (task->GetName() == name) if (task->GetName() == name)
{ {
@ -62,9 +66,12 @@ namespace easy2d
} }
} }
void TaskManager::StartTasks(String const& name) void TaskManager::StartTasks(std::wstring const& name)
{ {
for (auto task = tasks_.First(); task; task = task->NextItem()) if (tasks_.IsEmpty())
return;
for (auto task = tasks_.First().Get(); task; task = task->NextItem().Get())
{ {
if (task->GetName() == name) if (task->GetName() == name)
{ {
@ -73,20 +80,28 @@ namespace easy2d
} }
} }
void TaskManager::RemoveTasks(String const& name) void TaskManager::RemoveTasks(std::wstring const& name)
{ {
for (auto task = tasks_.First(); task; task = task->NextItem()) if (tasks_.IsEmpty())
return;
spTask next;
for (auto task = tasks_.First(); task; task = next)
{ {
next = task->NextItem();
if (task->GetName() == name) if (task->GetName() == name)
{ {
task->stopped_ = true; tasks_.Remove(task);
} }
} }
} }
void TaskManager::StopAllTasks() void TaskManager::StopAllTasks()
{ {
for (auto task = tasks_.First(); task; task = task->NextItem()) if (tasks_.IsEmpty())
return;
for (auto task = tasks_.First().Get(); task; task = task->NextItem().Get())
{ {
task->Stop(); task->Stop();
} }
@ -94,7 +109,10 @@ namespace easy2d
void TaskManager::StartAllTasks() void TaskManager::StartAllTasks()
{ {
for (auto task = tasks_.First(); task; task = task->NextItem()) if (tasks_.IsEmpty())
return;
for (auto task = tasks_.First().Get(); task; task = task->NextItem().Get())
{ {
task->Start(); task->Start();
} }
@ -102,10 +120,7 @@ namespace easy2d
void TaskManager::RemoveAllTasks() void TaskManager::RemoveAllTasks()
{ {
for (auto task = tasks_.First(); task; task = task->NextItem()) tasks_.Clear();
{
task->stopped_ = true;
}
} }
const TaskManager::Tasks & TaskManager::GetAllTasks() const const TaskManager::Tasks & TaskManager::GetAllTasks() const

View File

@ -35,17 +35,17 @@ namespace easy2d
// 启动任务 // 启动任务
void StartTasks( void StartTasks(
String const& task_name std::wstring const& task_name
); );
// 停止任务 // 停止任务
void StopTasks( void StopTasks(
String const& task_name std::wstring const& task_name
); );
// 移除任务 // 移除任务
void RemoveTasks( void RemoveTasks(
String const& task_name std::wstring const& task_name
); );
// 启动所有任务 // 启动所有任务

View File

@ -21,7 +21,7 @@
#include "Text.h" #include "Text.h"
#include "Factory.h" #include "Factory.h"
#include "render.h" #include "render.h"
#include "base.hpp" #include "include-forwards.h"
#include "logs.h" #include "logs.h"
namespace easy2d namespace easy2d
@ -48,22 +48,22 @@ namespace easy2d
{ {
} }
Text::Text(String const& text) Text::Text(std::wstring const& text)
: Text(text, text_default_font, text_default_style) : Text(text, text_default_font, text_default_style)
{ {
} }
Text::Text(String const& text, const Font & font) Text::Text(std::wstring const& text, const Font & font)
: Text(text, font, text_default_style) : Text(text, font, text_default_style)
{ {
} }
Text::Text(String const& text, const TextStyle & style) Text::Text(std::wstring const& text, const TextStyle & style)
: Text(text, text_default_font, style) : Text(text, text_default_font, style)
{ {
} }
Text::Text(String const& text, const Font & font, const TextStyle & style) Text::Text(std::wstring const& text, const Font & font, const TextStyle & style)
: font_(font) : font_(font)
, style_(style) , style_(style)
, text_(text) , text_(text)
@ -75,7 +75,7 @@ namespace easy2d
{ {
} }
String const& Text::GetText() const std::wstring const& Text::GetText() const
{ {
return text_; return text_;
} }
@ -90,7 +90,7 @@ namespace easy2d
return style_; return style_;
} }
String const& Text::GetFontFamily() const std::wstring const& Text::GetFontFamily() const
{ {
return font_.family; return font_.family;
} }
@ -158,7 +158,7 @@ namespace easy2d
return style_.outline; return style_.outline;
} }
void Text::SetText(String const& text) void Text::SetText(std::wstring const& text)
{ {
text_ = text; text_ = text;
UpdateLayout(); UpdateLayout();
@ -176,7 +176,7 @@ namespace easy2d
UpdateLayout(); UpdateLayout();
} }
void Text::SetFontFamily(String const& family) void Text::SetFontFamily(std::wstring const& family)
{ {
if (font_.family != family) if (font_.family != family)
{ {

View File

@ -33,21 +33,21 @@ namespace easy2d
Text(); Text();
explicit Text( explicit Text(
String const& text /* 文字内容 */ std::wstring const& text /* 文字内容 */
); );
explicit Text( explicit Text(
String const& text, /* 文字内容 */ std::wstring const& text, /* 文字内容 */
const Font& font /* 字体 */ const Font& font /* 字体 */
); );
explicit Text( explicit Text(
String const& text, /* 文字内容 */ std::wstring const& text, /* 文字内容 */
const TextStyle& style /* 文本样式 */ const TextStyle& style /* 文本样式 */
); );
explicit Text( explicit Text(
String const& text, /* 文字内容 */ std::wstring const& text, /* 文字内容 */
const Font& font, /* 字体 */ const Font& font, /* 字体 */
const TextStyle& style /* 文本样式 */ const TextStyle& style /* 文本样式 */
); );
@ -55,7 +55,7 @@ namespace easy2d
virtual ~Text(); virtual ~Text();
// 获取文本 // 获取文本
String const& GetText() const; std::wstring const& GetText() const;
// 获取字体 // 获取字体
const Font& GetFont() const; const Font& GetFont() const;
@ -64,7 +64,7 @@ namespace easy2d
const TextStyle& GetStyle() const; const TextStyle& GetStyle() const;
// 获取字体族 // 获取字体族
String const& GetFontFamily() const; std::wstring const& GetFontFamily() const;
// 获取当前字号 // 获取当前字号
float GetFontSize() const; float GetFontSize() const;
@ -101,7 +101,7 @@ namespace easy2d
// 设置文本 // 设置文本
void SetText( void SetText(
String const& text std::wstring const& text
); );
// 设置文本样式 // 设置文本样式
@ -116,7 +116,7 @@ namespace easy2d
// 设置字体族 // 设置字体族
void SetFontFamily( void SetFontFamily(
String const& family std::wstring const& family
); );
// 设置字号(默认值为 22 // 设置字号(默认值为 22
@ -205,7 +205,7 @@ namespace easy2d
void UpdateLayout(); void UpdateLayout();
protected: protected:
String text_; std::wstring text_;
Font font_; Font font_;
TextStyle style_; TextStyle style_;
cpTextFormat text_format_; cpTextFormat text_format_;

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#include "TextRenderer.h" #include "TextRenderer.h"
#include "base.hpp" #include "include-forwards.h"
#include "render.h" #include "render.h"
namespace easy2d namespace easy2d

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "d2dres.hpp" #include "d2dhelper.hpp"
namespace easy2d namespace easy2d
{ {

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
namespace easy2d namespace easy2d
{ {

View File

@ -50,13 +50,4 @@ namespace easy2d
rotation == other.rotation; rotation == other.rotation;
} }
}; };
inline D2D1_MATRIX_3X2_F ConvertToD2DMatrix(math::Matrix const& matrix)
{
return D2D1_MATRIX_3X2_F{
matrix.m[0], matrix.m[1],
matrix.m[2], matrix.m[3],
matrix.m[4], matrix.m[5]
};
}
} }

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "time.h" #include "time.h"
namespace easy2d namespace easy2d
@ -28,7 +28,7 @@ namespace easy2d
// 场景过渡 // 场景过渡
class Transition class Transition
: public ObjectBase : public Object
{ {
friend class Game; friend class Game;

View File

@ -1,148 +0,0 @@
// Copyright (c) 2016-2018 Easy2D - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "Unit.h"
namespace easy2d
{
Unit::Unit()
: transform_()
, dirty_transform_(false)
{
}
Unit::~Unit()
{
}
math::Matrix const & Unit::GetTransformMatrix()
{
if (dirty_transform_)
{
UpdateMatrix();
dirty_transform_ = false;
}
return matrix_cached_;
}
void Unit::SetPositionX(float x)
{
this->SetPosition(x, transform_.position.y);
}
void Unit::SetPositionY(float y)
{
this->SetPosition(transform_.position.x, y);
}
void Unit::SetPosition(const Point & p)
{
this->SetPosition(p.x, p.y);
}
void Unit::SetPosition(float x, float y)
{
if (transform_.position.x == x && transform_.position.y == y)
return;
transform_.position.x = x;
transform_.position.y = y;
dirty_transform_ = true;
}
void Unit::Move(float x, float y)
{
this->SetPosition(transform_.position.x + x, transform_.position.y + y);
}
void Unit::Move(const Point & v)
{
this->Move(v.x, v.y);
}
void Unit::SetScaleX(float scale_x)
{
this->SetScale(scale_x, transform_.scale.y);
}
void Unit::SetScaleY(float scale_y)
{
this->SetScale(transform_.scale.x, scale_y);
}
void Unit::SetScale(float scale)
{
this->SetScale(scale, scale);
}
void Unit::SetScale(float scale_x, float scale_y)
{
if (transform_.scale.x == scale_x && transform_.scale.y == scale_y)
return;
transform_.scale.x = scale_x;
transform_.scale.y = scale_y;
dirty_transform_ = true;
}
void Unit::SetSkewX(float skew_x)
{
this->SetSkew(skew_x, transform_.skew.y);
}
void Unit::SetSkewY(float skew_y)
{
this->SetSkew(transform_.skew.x, skew_y);
}
void Unit::SetSkew(float skew_x, float skew_y)
{
if (transform_.skew.x == skew_x && transform_.skew.y == skew_y)
return;
transform_.skew.x = skew_x;
transform_.skew.y = skew_y;
dirty_transform_ = true;
}
void Unit::SetRotation(float angle)
{
if (transform_.rotation == angle)
return;
transform_.rotation = angle;
dirty_transform_ = true;
}
void Unit::SetTransform(Transform const& transform)
{
transform_ = transform;
}
void Unit::UpdateMatrix()
{
Point center;
matrix_cached_ = math::Matrix::Scaling(transform_.scale, center)
* math::Matrix::Skewing(transform_.skew.x, transform_.skew.y, center)
* math::Matrix::Rotation(transform_.rotation, center)
* math::Matrix::Translation(transform_.position - center);
}
}

View File

@ -1,152 +0,0 @@
// Copyright (c) 2016-2018 Easy2D - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include "base.hpp"
#include "Transform.hpp"
namespace easy2d
{
class Unit
: public ObjectBase
{
public:
Unit();
virtual ~Unit();
// 获取坐标
virtual const Point& GetPosition() const { return transform_.position; }
// 获取横向缩放比例
virtual float GetScaleX() const { return transform_.scale.x; }
// 获取纵向缩放比例
virtual float GetScaleY() const { return transform_.scale.y; }
// 获取横向错切角度
virtual float GetSkewX() const { return transform_.skew.x; }
// 获取纵向错切角度
virtual float GetSkewY() const { return transform_.skew.y; }
// 获取旋转角度
virtual float GetRotation() const { return transform_.rotation; }
Transform const& GetTransform() const { return transform_; }
// 设置横坐标
void SetPositionX(
float x
);
// 设置纵坐标
void SetPositionY(
float y
);
// 设置坐标
void SetPosition(
const Point & point
);
// 设置坐标
virtual void SetPosition(
float x,
float y
);
// 移动
void Move(
float x,
float y
);
// 移动
void Move(
const Point & vector
);
// 设置横向缩放比例
// 默认为 1.0
void SetScaleX(
float scale_x
);
// 设置纵向缩放比例
// 默认为 1.0
void SetScaleY(
float scale_y
);
// 设置缩放比例
// 默认为 (1.0, 1.0)
virtual void SetScale(
float scale_x,
float scale_y
);
// 设置缩放比例
// 默认为 1.0
void SetScale(
float scale
);
// 设置横向错切角度
// 默认为 0
void SetSkewX(
float skew_x
);
// 设置纵向错切角度
// 默认为 0
void SetSkewY(
float skew_y
);
// 设置错切角度
// 默认为 (0, 0)
virtual void SetSkew(
float skew_x,
float skew_y
);
// 设置旋转角度
// 默认为 0
virtual void SetRotation(
float rotation
);
virtual void SetTransform(
Transform const& transform
);
// 获取二维变换矩阵
virtual math::Matrix const& GetTransformMatrix();
protected:
virtual void UpdateMatrix();
protected:
bool dirty_transform_;
Transform transform_;
math::Matrix matrix_cached_;
};
}

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#include "audio.h" #include "audio.h"
#include "base.hpp" #include "include-forwards.h"
#include "modules.h" #include "modules.h"
#include "logs.h" #include "logs.h"
#include <mfapi.h> #include <mfapi.h>

View File

@ -19,7 +19,6 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "macros.h"
#include "intrusive/SmartPointer.hpp" #include "intrusive/SmartPointer.hpp"
#include <d2d1.h> #include <d2d1.h>
#include <dwrite.h> #include <dwrite.h>

View File

@ -19,11 +19,8 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "BaseTypes.hpp"
#include "RefCounter.hpp" #include "RefCounter.hpp"
#include "ObjectBase.h"
#include "intrusive/SmartPointer.hpp" #include "intrusive/SmartPointer.hpp"
#include "d2dres.hpp"
#ifndef E2D_DECLARE_SMART_PTR #ifndef E2D_DECLARE_SMART_PTR
#define E2D_DECLARE_SMART_PTR(class_name)\ #define E2D_DECLARE_SMART_PTR(class_name)\
@ -94,17 +91,17 @@ namespace easy2d
template <typename Dest, typename Src> template <typename Dest, typename Src>
inline Dest* SafeCast(Src* ptr) inline Dest SafeCast(Src ptr)
{ {
if (!ptr) if (!ptr)
return nullptr; return nullptr;
#ifdef E2D_DEBUG #ifdef E2D_DEBUG
Dest* cast = dynamic_cast<Dest*>(ptr); Dest cast = dynamic_cast<Dest>(ptr);
E2D_ASSERT(cast); E2D_ASSERT(cast);
return cast; return cast;
#else
return static_cast<Dest>(ptr);
#endif #endif
return static_cast<Dest*>(ptr);
} }
} }

View File

@ -0,0 +1,65 @@
// Copyright (c) 2016-2018 Easy2D - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include "macros.h"
#include "Point.hpp"
#include "Size.hpp"
#include "Rect.hpp"
#include "Color.h"
#include "Object.h"
#include "helper.hpp"
#include "d2dhelper.hpp"
namespace easy2d
{
// 画笔样式
enum class StrokeStyle : int
{
Miter = 0, /* 斜切 */
Bevel = 1, /* 斜角 */
Round = 2 /* 圆角 */
};
// 方向
enum class Direction : int
{
Up, /* 上 */
Down, /* 下 */
Left, /* 左 */
Right /* 右 */
};
// 文字抗锯齿属性
enum class TextAntialias
{
Default, // 系统默认
ClearType, // ClearType 抗锯齿
GrayScale, // 灰度抗锯齿
None // 不启用抗锯齿
};
// 图层属性
struct LayerProperties
{
Rect area;
float opacity;
};
}

View File

@ -130,7 +130,7 @@ namespace easy2d
DEBUG_CHECK_LIST(this); DEBUG_CHECK_LIST(this);
} }
void Insert(T& child, T& before) void InsertBefore(T& child, T& before)
{ {
if (child->prev_) if (child->prev_)
child->prev_->next_ = child->next_; child->prev_->next_ = child->next_;
@ -149,6 +149,25 @@ namespace easy2d
DEBUG_CHECK_LIST(this); DEBUG_CHECK_LIST(this);
} }
void InsertAfter(T& child, T& after)
{
if (child->prev_)
child->prev_->next_ = child->next_;
if (child->next_)
child->next_->prev_ = child->prev_;
if (after->next_)
after->next_->prev_ = child;
else
last_ = child;
child->next_ = after->next_;
child->prev_ = after;
after->next_ = child;
DEBUG_CHECK_LIST(this);
}
void Remove(T& child) void Remove(T& child)
{ {
#ifdef E2D_DEBUG #ifdef E2D_DEBUG
@ -202,42 +221,6 @@ namespace easy2d
last_ = nullptr; last_ = nullptr;
} }
void Sort(std::function<bool(T const&, T const&)> const& if_lt)
{
if (IsEmpty() || first_ == last_)
return;
std::vector<ItemType> temp_vec;
for (ItemType p = first_; p; p = p->NextItem())
{
temp_vec.push_back(p);
}
std::sort(temp_vec.begin(), temp_vec.end(), if_lt);
size_t size = temp_vec.size();
for (size_t i = 0; i < size; ++i)
{
if (i == 0)
temp_vec[i]->prev_ = nullptr;
else
{
temp_vec[i]->prev_ = temp_vec[i - 1];
temp_vec[i - 1]->next_ = temp_vec[i];
}
if (i == size - 1)
temp_vec[i]->next_ = nullptr;
else
{
temp_vec[i]->next_ = temp_vec[i + 1];
temp_vec[i + 1]->prev_ = temp_vec[i];
}
}
first_ = *temp_vec.begin();
last_ = *temp_vec.rbegin();
DEBUG_CHECK_LIST(this);
}
#ifdef E2D_DEBUG #ifdef E2D_DEBUG
private: private:

View File

@ -74,19 +74,19 @@ namespace easy2d
inline Type* operator ->() const inline Type* operator ->() const
{ {
E2D_ASSERT(ptr_ != nullptr, "Invalid pointer"); E2D_ASSERT(ptr_ != nullptr && "Invalid pointer");
return ptr_; return ptr_;
} }
inline Type& operator *() const inline Type& operator *() const
{ {
E2D_ASSERT(ptr_ != nullptr, "Invalid pointer"); E2D_ASSERT(ptr_ != nullptr && "Invalid pointer");
return *ptr_; return *ptr_;
} }
inline Type** operator &() inline Type** operator &()
{ {
E2D_ASSERT(ptr_ == nullptr, "Memory leak"); E2D_ASSERT(ptr_ == nullptr && "Memory leak");
return &ptr_; return &ptr_;
} }

View File

@ -20,47 +20,9 @@
#pragma once #pragma once
#include "macros.h" #include "macros.h"
#include "Point.hpp"
#include "Size.hpp"
#include "Rect.hpp"
#include "Color.h"
namespace easy2d namespace easy2d
{ {
using String = std::wstring;
// 方向
enum class Direction : int
{
Up, /* 上 */
Down, /* 下 */
Left, /* 左 */
Right /* 右 */
};
// 画笔样式
enum class StrokeStyle : int
{
Miter = 0, /* 斜切 */
Bevel = 1, /* 斜角 */
Round = 2 /* 圆角 */
};
// 图层属性
struct LayerProperties
{
Rect area;
float opacity;
};
// 鼠标键值
enum class MouseButton : int
{
Left = VK_LBUTTON, // 鼠标左键
Right = VK_RBUTTON, // 鼠标右键
Middle = VK_MBUTTON // 鼠标中键
};
// °´¼ü¼üÖµ // °´¼ü¼üÖµ
enum class KeyCode : int enum class KeyCode : int
{ {

View File

@ -19,8 +19,6 @@
// THE SOFTWARE. // THE SOFTWARE.
#include "render.h" #include "render.h"
#include "time.h"
#include "base.hpp"
#include "logs.h" #include "logs.h"
#include "Factory.h" #include "Factory.h"
#include "Image.h" #include "Image.h"
@ -33,6 +31,7 @@ namespace easy2d
, fps_text_layout_(nullptr) , fps_text_layout_(nullptr)
, clear_color_(D2D1::ColorF(D2D1::ColorF::Black)) , clear_color_(D2D1::ColorF(D2D1::ColorF::Black))
, opacity_(1.f) , opacity_(1.f)
, debug_(false)
, window_occluded_(false) , window_occluded_(false)
, vsync_enabled_(true) , vsync_enabled_(true)
, antialias_(true) , antialias_(true)
@ -51,19 +50,22 @@ namespace easy2d
{ {
E2D_LOG("Initing graphics device"); E2D_LOG("Initing graphics device");
HRESULT hr = CreateResources(hwnd);
if (SUCCEEDED(hr))
{
vsync_enabled_ = vsync; vsync_enabled_ = vsync;
} debug_ = debug;
return hr;
return CreateResources(hwnd);
} }
HRESULT GraphicsDevice::BeginDraw(HWND hwnd) HRESULT GraphicsDevice::BeginDraw(HWND hwnd)
{ {
HRESULT hr = CreateResources(hwnd); HRESULT hr = CreateResources(hwnd);
if (debug_)
{
status_.start = time::Now();
status_.primitives = 0;
}
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
window_occluded_ = !!(render_target_->CheckWindowState() & D2D1_WINDOW_STATE_OCCLUDED); window_occluded_ = !!(render_target_->CheckWindowState() & D2D1_WINDOW_STATE_OCCLUDED);
@ -74,13 +76,18 @@ namespace easy2d
render_target_->Clear(clear_color_); render_target_->Clear(clear_color_);
} }
} }
return hr; return hr;
} }
HRESULT GraphicsDevice::EndDraw() HRESULT GraphicsDevice::EndDraw()
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
if (debug_)
{
status_.duration = time::Now() - status_.start;
}
if (!window_occluded_) if (!window_occluded_)
{ {
hr = render_target_->EndDraw(); hr = render_target_->EndDraw();
@ -101,6 +108,16 @@ namespace easy2d
bitmap_cache_.clear(); bitmap_cache_.clear();
} }
cpHwndRenderTarget const & GraphicsDevice::GetRenderTarget() const
{
return render_target_;
}
cpSolidColorBrush const & GraphicsDevice::GetSolidBrush() const
{
return solid_brush_;
}
HRESULT GraphicsDevice::CreateLayer(cpLayer& layer) HRESULT GraphicsDevice::CreateLayer(cpLayer& layer)
{ {
if (!render_target_) if (!render_target_)
@ -144,6 +161,9 @@ namespace easy2d
stroke_width, stroke_width,
stroke_style.Get() stroke_style.Get()
); );
if (debug_)
++status_.primitives;
return S_OK; return S_OK;
} }
@ -161,6 +181,9 @@ namespace easy2d
geometry.Get(), geometry.Get(),
solid_brush_.Get() solid_brush_.Get()
); );
if (debug_)
++status_.primitives;
return S_OK; return S_OK;
} }
@ -182,6 +205,9 @@ namespace easy2d
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
image->GetCropRect() image->GetCropRect()
); );
if (debug_)
++status_.primitives;
return S_OK; return S_OK;
} }
@ -204,6 +230,9 @@ namespace easy2d
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
rect rect
); );
if (debug_)
++status_.primitives;
return S_OK; return S_OK;
} }
@ -215,6 +244,8 @@ namespace easy2d
if (window_occluded_) if (window_occluded_)
return S_OK; return S_OK;
if (debug_)
++status_.primitives;
return text_layout->Draw(nullptr, text_renderer_.Get(), 0, 0); return text_layout->Draw(nullptr, text_renderer_.Get(), 0, 0);
} }
@ -226,7 +257,7 @@ namespace easy2d
if (window_occluded_) if (window_occluded_)
return S_OK; return S_OK;
render_target_->SetTransform(ConvertToD2DMatrix(clip_matrix)); render_target_->SetTransform(clip_matrix);
render_target_->PushAxisAlignedClip( render_target_->PushAxisAlignedClip(
D2D1::RectF(0, 0, clip_size.width, clip_size.height), D2D1::RectF(0, 0, clip_size.width, clip_size.height),
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE D2D1_ANTIALIAS_MODE_PER_PRIMITIVE
@ -293,14 +324,14 @@ namespace easy2d
return S_OK; return S_OK;
} }
HRESULT GraphicsDevice::CreateBitmapFromFile(cpBitmap& bitmap, String const& file_path) HRESULT GraphicsDevice::CreateBitmapFromFile(cpBitmap& bitmap, std::wstring const& file_path)
{ {
if (render_target_ == nullptr) if (render_target_ == nullptr)
{ {
return E_UNEXPECTED; return E_UNEXPECTED;
} }
size_t hash_code = std::hash<String>{}(file_path); size_t hash_code = std::hash<std::wstring>{}(file_path);
if (bitmap_cache_.find(hash_code) != bitmap_cache_.end()) if (bitmap_cache_.find(hash_code) != bitmap_cache_.end())
{ {
bitmap = bitmap_cache_[hash_code]; bitmap = bitmap_cache_[hash_code];
@ -373,7 +404,7 @@ namespace easy2d
if (!render_target_) if (!render_target_)
return E_UNEXPECTED; return E_UNEXPECTED;
render_target_->SetTransform(ConvertToD2DMatrix(matrix)); render_target_->SetTransform(matrix);
return S_OK; return S_OK;
} }
@ -454,6 +485,11 @@ namespace easy2d
return S_OK; return S_OK;
} }
GraphicsDevice::Status const & GraphicsDevice::GetStatus() const
{
return status_;
}
HRESULT GraphicsDevice::CreateResources(HWND hwnd) HRESULT GraphicsDevice::CreateResources(HWND hwnd)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;

View File

@ -19,30 +19,29 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "Singleton.hpp" #include "time.h"
#include "Font.hpp" #include "Font.hpp"
#include "Resource.h" #include "Resource.h"
#include "TextRenderer.h" #include "TextRenderer.h"
#include "TextStyle.hpp" #include "TextStyle.hpp"
#include "Singleton.hpp"
#include "../math/Matrix.hpp" #include "../math/Matrix.hpp"
namespace easy2d namespace easy2d
{ {
enum class TextAntialias
{
Default, // 系统默认
ClearType, // ClearType 抗锯齿
GrayScale, // 灰度抗锯齿
None // 不启用抗锯齿
};
class GraphicsDevice class GraphicsDevice
: protected Noncopyable : protected Noncopyable
{ {
E2D_DECLARE_SINGLETON(GraphicsDevice); E2D_DECLARE_SINGLETON(GraphicsDevice);
struct Status
{
TimePoint start;
Duration duration;
int primitives;
};
public: public:
HRESULT Init(HWND hwnd, bool vsync, bool debug); HRESULT Init(HWND hwnd, bool vsync, bool debug);
@ -67,6 +66,8 @@ namespace easy2d
TextAntialias mode TextAntialias mode
); );
Status const& GetStatus() const;
HRESULT CreateResources( HRESULT CreateResources(
HWND hwnd HWND hwnd
); );
@ -83,7 +84,7 @@ namespace easy2d
HRESULT CreateBitmapFromFile( HRESULT CreateBitmapFromFile(
cpBitmap& bitmap, cpBitmap& bitmap,
String const& file_path std::wstring const& file_path
); );
HRESULT CreateBitmapFromResource( HRESULT CreateBitmapFromResource(
@ -160,21 +161,27 @@ namespace easy2d
void ClearImageCache(); void ClearImageCache();
cpHwndRenderTarget const& GetRenderTarget() const;
cpSolidColorBrush const& GetSolidBrush() const;
protected: protected:
GraphicsDevice(); GraphicsDevice();
~GraphicsDevice(); ~GraphicsDevice();
protected: protected:
bool debug_;
bool window_occluded_; bool window_occluded_;
bool vsync_enabled_; bool vsync_enabled_;
bool antialias_; bool antialias_;
TextAntialias text_antialias_;
float opacity_; float opacity_;
D2D1_COLOR_F clear_color_;
TextAntialias text_antialias_;
Status status_;
cpTextRenderer text_renderer_; cpTextRenderer text_renderer_;
cpSolidColorBrush solid_brush_; cpSolidColorBrush solid_brush_;
cpHwndRenderTarget render_target_; cpHwndRenderTarget render_target_;
D2D1_COLOR_F clear_color_;
cpTextFormat fps_text_format_; cpTextFormat fps_text_format_;
cpTextLayout fps_text_layout_; cpTextLayout fps_text_layout_;
std::map<size_t, cpBitmap> bitmap_cache_; std::map<size_t, cpBitmap> bitmap_cache_;

View File

@ -47,7 +47,7 @@ namespace easy2d
E2D_LOG("Destroying window"); E2D_LOG("Destroying window");
} }
HRESULT WindowImpl::Init(String title, int width, int height, LPCWSTR icon, WNDPROC proc, bool debug) HRESULT WindowImpl::Init(std::wstring title, int width, int height, LPCWSTR icon, WNDPROC proc, bool debug)
{ {
E2D_LOG("Creating window"); E2D_LOG("Creating window");
@ -105,7 +105,7 @@ namespace easy2d
return S_OK; return S_OK;
} }
String WindowImpl::GetTitle() const std::wstring WindowImpl::GetTitle() const
{ {
if (handle) if (handle)
{ {
@ -113,10 +113,10 @@ namespace easy2d
GetWindowTextW(handle, title, 256); GetWindowTextW(handle, title, 256);
return title; return title;
} }
return String(); return std::wstring();
} }
void WindowImpl::SetTitle(String const& title) void WindowImpl::SetTitle(std::wstring const& title)
{ {
if (handle) if (handle)
::SetWindowText(handle, title.c_str()); ::SetWindowText(handle, title.c_str());

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "base.hpp" #include "include-forwards.h"
#include "Singleton.hpp" #include "Singleton.hpp"
namespace easy2d namespace easy2d
@ -31,7 +31,7 @@ namespace easy2d
public: public:
HRESULT Init( HRESULT Init(
String title, std::wstring title,
int width, int width,
int height, int height,
LPCWSTR icon, LPCWSTR icon,
@ -40,10 +40,10 @@ namespace easy2d
); );
// 获取标题 // 获取标题
String GetTitle() const; std::wstring GetTitle() const;
// 设置标题 // 设置标题
void SetTitle(String const& title); void SetTitle(std::wstring const& title);
// 获取窗口大小 // 获取窗口大小
Size GetSize() const; Size GetSize() const;

View File

@ -31,7 +31,6 @@
// //
#include "base/macros.h" #include "base/macros.h"
#include "base/base.hpp"
#include "base/modules.h" #include "base/modules.h"
#include "base/render.h" #include "base/render.h"
#include "base/window.h" #include "base/window.h"
@ -54,19 +53,20 @@
#include "base/intrusive/SmartPointer.hpp" #include "base/intrusive/SmartPointer.hpp"
#include "base/intrusive/List.hpp" #include "base/intrusive/List.hpp"
#include "base/ObjectBase.h" #include "base/Object.h"
#include "base/Image.h" #include "base/Image.h"
#include "base/Frames.h" #include "base/Frames.h"
#include "base/Music.h" #include "base/Music.h"
#include "base/Geometry.h"
#include "base/Task.h" #include "base/Task.h"
#include "base/TaskManager.h"
#include "base/Action.hpp" #include "base/Action.hpp"
#include "base/ActionCombined.h" #include "base/ActionCombined.h"
#include "base/ActionTween.h" #include "base/ActionTween.h"
#include "base/Animation.h" #include "base/Animation.h"
#include "base/Delay.h" #include "base/Delay.h"
#include "base/Transition.h"
#include "base/TaskManager.h"
#include "base/ActionManager.h" #include "base/ActionManager.h"
#include "base/Transition.h"
#include "base/Event.hpp" #include "base/Event.hpp"
#include "base/MouseEvent.hpp" #include "base/MouseEvent.hpp"
@ -74,15 +74,13 @@
#include "base/EventListener.h" #include "base/EventListener.h"
#include "base/EventDispatcher.h" #include "base/EventDispatcher.h"
#include "base/Unit.h"
#include "base/Geometry.h"
#include "base/Node.h" #include "base/Node.h"
#include "base/Scene.h" #include "base/Scene.h"
#include "base/Sprite.h" #include "base/Sprite.h"
#include "base/Text.h" #include "base/Text.h"
#include "base/Canvas.h" #include "base/Canvas.h"
#include "base/GeometryNode.h" #include "base/GeometryNode.h"
#include "base/Debuger.h" #include "base/DebugNode.h"
#include "base/Factory.h" #include "base/Factory.h"
#include "base/Game.h" #include "base/Game.h"

View File

@ -20,6 +20,7 @@
#pragma once #pragma once
#include "vector.hpp" #include "vector.hpp"
#include <d2d1.h>
namespace easy2d namespace easy2d
{ {
@ -40,85 +41,112 @@ namespace easy2d
class Matrix class Matrix
{ {
public: union
{
struct
{
float m[6]; // m[3][2] float m[6]; // m[3][2]
};
struct
{
float
_11, _12,
_21, _22,
_31, _32;
};
};
public: public:
Matrix() Matrix()
: _11(1.f), _12(0.f)
, _21(0.f), _22(1.f)
, _31(0.f), _32(0.f)
{ {
m[0] = 1.f; m[1] = 0.f;
m[2] = 0.f; m[3] = 1.f;
m[4] = 0.f; m[5] = 0.f;
}
Matrix(float val[6])
{
m[0] = val[0]; m[1] = val[1];
m[2] = val[2]; m[3] = val[3];
m[4] = val[4]; m[5] = val[5];
} }
Matrix(float _11, float _12, float _21, float _22, float _31, float _32) Matrix(float _11, float _12, float _21, float _22, float _31, float _32)
: _11(_11), _12(_12), _21(_21), _22(_22), _31(_31), _32(_32)
{ {
m[0] = _11; m[1] = _12; }
m[2] = _21; m[3] = _22;
m[4] = _31; m[5] = _32; Matrix(const float* p)
{
for (int i = 0; i < 6; i++)
m[i] = p[i];
} }
Matrix(Matrix const& other) Matrix(Matrix const& other)
: _11(other._11), _12(other._12)
, _21(other._21), _22(other._22)
, _31(other._31), _32(other._32)
{ {
m[0] = other.m[0]; m[1] = other.m[1];
m[2] = other.m[2]; m[3] = other.m[3];
m[4] = other.m[4]; m[5] = other.m[5];
} }
template <typename T> template <typename T>
Matrix(T const& other) Matrix(T const& other)
{ {
m[0] = other[0]; m[1] = other[1]; for (int i = 0; i < 6; i++)
m[2] = other[2]; m[3] = other[3]; m[i] = other[i];
m[4] = other[4]; m[5] = other[5];
} }
inline float operator [](unsigned int index) const { return m[index]; } inline float operator [](unsigned int index) const
{
return m[index];
}
template <typename T> template <typename T>
inline Matrix& operator =(T const& other) inline Matrix& operator =(T const& other)
{ {
m[0] = other[0]; m[1] = other[1]; for (int i = 0; i < 6; i++)
m[2] = other[2]; m[3] = other[3]; m[i] = other[i];
m[4] = other[4]; m[5] = other[5];
return *this; return *this;
} }
inline Matrix& Identity() inline Matrix& Identity()
{ {
m[0] = 1.f; m[1] = 0.f; _11 = 1.f; _12 = 0.f;
m[2] = 0.f; m[3] = 1.f; _21 = 0.f; _12 = 1.f;
m[4] = 0.f; m[5] = 0.f; _31 = 0.f; _32 = 0.f;
return *this; return *this;
} }
inline float Determinant() const inline float Determinant() const
{ {
return (m[0] * m[3]) - (m[1] * m[2]); return (_11 * _22) - (_12 * _21);
} }
inline bool IsIdentity() const inline bool IsIdentity() const
{ {
return m[0] == 1.f && m[1] == 0.f && return _11 == 1.f && _12 == 0.f &&
m[2] == 0.f && m[3] == 1.f && _21 == 0.f && _22 == 1.f &&
m[4] == 0.f && m[5] == 0.f; _31 == 0.f && _32 == 0.f;
} }
Vector2 Transform(const Vector2& v) const Vector2 Transform(const Vector2& v) const
{ {
return Vector2( return Vector2(
v.x * m[0] + v.y * m[2] + m[4], v.x * _11 + v.y * _21 + _31,
v.x * m[1] + v.y * m[3] + m[5] v.x * _12 + v.y * _22 + _32
); );
} }
void Translate(const Vector2& v)
{
_31 += _11 * v.x + _21 * v.y;
_32 += _12 * v.x + _22 * v.y;
}
inline operator D2D1_MATRIX_3X2_F const& () const
{
return reinterpret_cast<D2D1_MATRIX_3X2_F const&>(*this);
}
inline operator D2D1_MATRIX_3X2_F& ()
{
return reinterpret_cast<D2D1_MATRIX_3X2_F&>(*this);
}
static Matrix Translation(const Vector2& v) static Matrix Translation(const Vector2& v)
{ {
return Matrix( return Matrix(

View File

@ -20,10 +20,11 @@
#include "Data.h" #include "Data.h"
#include "Path.h" #include "Path.h"
#include "../base/macros.h"
namespace easy2d namespace easy2d
{ {
Data::Data(String const& key, String const& field) Data::Data(std::wstring const& key, std::wstring const& field)
: key_(key) : key_(key)
, field_(field) , field_(field)
, data_path_(Path::GetDataPath()) , data_path_(Path::GetDataPath())
@ -88,7 +89,7 @@ namespace easy2d
return ret == TRUE; return ret == TRUE;
} }
bool Data::SaveString(String const& val) bool Data::SaveString(std::wstring const& val)
{ {
BOOL ret = ::WritePrivateProfileStringW( BOOL ret = ::WritePrivateProfileStringW(
field_.c_str(), field_.c_str(),
@ -133,7 +134,7 @@ namespace easy2d
return nValue == TRUE; return nValue == TRUE;
} }
String Data::GetString() std::wstring Data::GetString()
{ {
wchar_t temp[256] = { 0 }; wchar_t temp[256] = { 0 };
::GetPrivateProfileStringW( ::GetPrivateProfileStringW(

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "../base/base.hpp" #include <string>
namespace easy2d namespace easy2d
{ {
@ -28,8 +28,8 @@ namespace easy2d
{ {
public: public:
Data( Data(
String const& key, /* 键值 */ std::wstring const& key, /* 键值 */
String const& field = L"Defalut" /* 字段名称 */ std::wstring const& field = L"Defalut" /* 字段名称 */
); );
// 该数据是否存在 // 该数据是否存在
@ -55,9 +55,9 @@ namespace easy2d
bool val bool val
); );
// 保存 String 类型的值 // 保存 std::wstring 类型的值
bool SaveString( bool SaveString(
String const& val std::wstring const& val
); );
// 获取 int 类型的值 // 获取 int 类型的值
@ -73,11 +73,11 @@ namespace easy2d
bool GetBool() const; bool GetBool() const;
// 获取 字符串 类型的值 // 获取 字符串 类型的值
String GetString(); std::wstring GetString();
protected: protected:
String key_; std::wstring key_;
String field_; std::wstring field_;
String const& data_path_; std::wstring const& data_path_;
}; };
} }

View File

@ -24,14 +24,14 @@
namespace easy2d namespace easy2d
{ {
std::list<String> File::search_paths_; std::list<std::wstring> File::search_paths_;
File::File() File::File()
: file_path_() : file_path_()
{ {
} }
File::File(String const& file_name) File::File(std::wstring const& file_name)
: file_path_(file_name) : file_path_(file_name)
{ {
this->Open(file_name); this->Open(file_name);
@ -41,12 +41,12 @@ namespace easy2d
{ {
} }
bool File::Open(String const& file_name) bool File::Open(std::wstring const& file_name)
{ {
if (file_name.empty()) if (file_name.empty())
return false; return false;
auto FindFile = [](String const& path) -> bool auto FindFile = [](std::wstring const& path) -> bool
{ {
if (modules::Shlwapi().PathFileExistsW(path.c_str())) if (modules::Shlwapi().PathFileExistsW(path.c_str()))
return true; return true;
@ -77,16 +77,16 @@ namespace easy2d
return false; return false;
} }
String const& File::GetPath() const std::wstring const& File::GetPath() const
{ {
return file_path_; return file_path_;
} }
String File::GetExtension() const std::wstring File::GetExtension() const
{ {
String file_ext; std::wstring file_ext;
size_t pos = file_path_.find_last_of(L'.'); size_t pos = file_path_.find_last_of(L'.');
if (pos != String::npos) if (pos != std::wstring::npos)
{ {
file_ext = file_path_.substr(pos); file_ext = file_path_.substr(pos);
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);
@ -101,7 +101,7 @@ namespace easy2d
return false; return false;
} }
File File::Extract(Resource& res, String const& dest_file_name) File File::Extract(Resource& res, std::wstring const& dest_file_name)
{ {
File file; File file;
HANDLE file_handle = ::CreateFile( HANDLE file_handle = ::CreateFile(
@ -136,11 +136,11 @@ namespace easy2d
return file; return file;
} }
void File::AddSearchPath(String const& path) void File::AddSearchPath(std::wstring const& path)
{ {
String tmp = path; std::wstring tmp = path;
size_t pos = 0; size_t pos = 0;
while ((pos = tmp.find(L"/", pos)) != String::npos) while ((pos = tmp.find(L"/", pos)) != std::wstring::npos)
{ {
tmp.replace(pos, 1, L"\\"); tmp.replace(pos, 1, L"\\");
pos++; pos++;

View File

@ -19,8 +19,8 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "../base/base.hpp"
#include "../base/Resource.h" #include "../base/Resource.h"
#include <string>
namespace easy2d namespace easy2d
{ {
@ -31,14 +31,14 @@ namespace easy2d
File(); File();
File( File(
String const& file_name std::wstring const& file_name
); );
virtual ~File(); virtual ~File();
// 打开文件 // 打开文件
bool Open( bool Open(
String const& file_name std::wstring const& file_name
); );
// 文件是否存在 // 文件是否存在
@ -48,38 +48,25 @@ namespace easy2d
bool Delete(); bool Delete();
// 获取文件路径 // 获取文件路径
String const& GetPath() const; std::wstring const& GetPath() const;
// 获取文件扩展名 // 获取文件扩展名
String GetExtension() const; std::wstring GetExtension() const;
// 释放资源到临时文件目录 // 释放资源到临时文件目录
static File Extract( static File Extract(
Resource& res, /* 资源 */ Resource& res, /* 资源 */
String const& dest_file_name /* 目标文件名 */ std::wstring const& dest_file_name /* 目标文件名 */
); );
// 添加文件搜索路径 // 添加文件搜索路径
static void AddSearchPath( static void AddSearchPath(
String const& path std::wstring const& path
);
// 弹出打开文件对话框
static File ShowOpenDialog(
String const& title = L"打开", /* 对话框标题 */
String const& filter = L"" /* 筛选扩展名,例如 "*.jpg;*.jpeg" */
);
// 弹出保存文件对话框
static File ShowSaveDialog(
String const& title = L"保存", /* 对话框标题 */
String const& def_file = L"", /* 默认保存的文件名 */
String const& def_ext = L"" /* 默认追加的扩展名,例如 "txt" */
); );
protected: protected:
String file_path_; std::wstring file_path_;
static std::list<String> search_paths_; static std::list<std::wstring> search_paths_;
}; };
} }

View File

@ -28,7 +28,7 @@ namespace easy2d
namespace namespace
{ {
// 创建指定文件夹 // 创建指定文件夹
bool CreateFolder(String const& dir_path) bool CreateFolder(std::wstring const& dir_path)
{ {
if (dir_path.empty() || dir_path.size() >= MAX_PATH) if (dir_path.empty() || dir_path.size() >= MAX_PATH)
return false; return false;
@ -55,15 +55,15 @@ namespace easy2d
} }
String const& Path::GetDataPath() std::wstring const& Path::GetDataPath()
{ {
static String data_path; static std::wstring data_path;
if (data_path.empty()) if (data_path.empty())
{ {
// 设置数据的保存路径 // 设置数据的保存路径
String local_app_data_path = Path::GetLocalAppDataPath(); std::wstring local_app_data_path = Path::GetLocalAppDataPath();
String title = Window::Instance()->GetTitle(); std::wstring title = Window::Instance()->GetTitle();
String folder_name = std::to_wstring(std::hash<String>{}(title)); std::wstring folder_name = std::to_wstring(std::hash<std::wstring>{}(title));
if (!local_app_data_path.empty()) if (!local_app_data_path.empty())
{ {
@ -83,15 +83,15 @@ namespace easy2d
return data_path; return data_path;
} }
String const& Path::GetTemporaryPath() std::wstring const& Path::GetTemporaryPath()
{ {
static String temp_path; static std::wstring temp_path;
if (temp_path.empty()) if (temp_path.empty())
{ {
// 设置临时文件保存路径 // 设置临时文件保存路径
wchar_t path[_MAX_PATH]; wchar_t path[_MAX_PATH];
String title = Window::Instance()->GetTitle(); std::wstring title = Window::Instance()->GetTitle();
String folder_name = std::to_wstring(std::hash<String>{}(title)); std::wstring folder_name = std::to_wstring(std::hash<std::wstring>{}(title));
if (0 != ::GetTempPath(_MAX_PATH, path)) if (0 != ::GetTempPath(_MAX_PATH, path))
{ {
@ -110,9 +110,9 @@ namespace easy2d
return temp_path; return temp_path;
} }
String const& Path::GetLocalAppDataPath() std::wstring const& Path::GetLocalAppDataPath()
{ {
static String local_app_data_path; static std::wstring local_app_data_path;
if (local_app_data_path.empty()) if (local_app_data_path.empty())
{ {
// 获取 AppData/Local 文件夹的路径 // 获取 AppData/Local 文件夹的路径
@ -124,9 +124,9 @@ namespace easy2d
return local_app_data_path; return local_app_data_path;
} }
String const& Path::GetExeFilePath() std::wstring const& Path::GetExeFilePath()
{ {
static String exe_file_path; static std::wstring exe_file_path;
if (exe_file_path.empty()) if (exe_file_path.empty())
{ {
TCHAR path[_MAX_PATH] = { 0 }; TCHAR path[_MAX_PATH] = { 0 };

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "../base/base.hpp" #include <string>
namespace easy2d namespace easy2d
{ {
@ -28,15 +28,15 @@ namespace easy2d
{ {
public: public:
// 获取数据的默认保存路径 // 获取数据的默认保存路径
static String const& GetDataPath(); static std::wstring const& GetDataPath();
// 获取临时文件目录 // 获取临时文件目录
static String const& GetTemporaryPath(); static std::wstring const& GetTemporaryPath();
// 获取 LocalAppData 目录 // 获取 LocalAppData 目录
static String const& GetLocalAppDataPath(); static std::wstring const& GetLocalAppDataPath();
// 获取当前程序的运行路径 // 获取当前程序的运行路径
static String const& GetExeFilePath(); static std::wstring const& GetExeFilePath();
}; };
} }

View File

@ -33,7 +33,7 @@ namespace easy2d
ClearCache(); ClearCache();
} }
bool Player::Load(String const& file_path) bool Player::Load(std::wstring const& file_path)
{ {
if (file_path.empty()) if (file_path.empty())
return false; return false;
@ -46,7 +46,7 @@ namespace easy2d
{ {
music->SetVolume(volume_); music->SetVolume(volume_);
size_t hash_code = std::hash<String>{}(file_path); size_t hash_code = std::hash<std::wstring>{}(file_path);
musics_cache_.insert(std::make_pair(hash_code, music)); musics_cache_.insert(std::make_pair(hash_code, music));
return true; return true;
} }
@ -54,14 +54,14 @@ namespace easy2d
return false; return false;
} }
bool Player::Play(String const& file_path, int loop_count) bool Player::Play(std::wstring const& file_path, int loop_count)
{ {
if (file_path.empty()) if (file_path.empty())
return false; return false;
if (Load(file_path)) if (Load(file_path))
{ {
auto music = musics_cache_[std::hash<String>{}(file_path)]; auto music = musics_cache_[std::hash<std::wstring>{}(file_path)];
if (music->Play(loop_count)) if (music->Play(loop_count))
{ {
return true; return true;
@ -70,42 +70,42 @@ namespace easy2d
return false; return false;
} }
void Player::Pause(String const& file_path) void Player::Pause(std::wstring const& file_path)
{ {
if (file_path.empty()) if (file_path.empty())
return; return;
size_t hash_code = std::hash<String>{}(file_path); size_t hash_code = std::hash<std::wstring>{}(file_path);
if (musics_cache_.end() != musics_cache_.find(hash_code)) if (musics_cache_.end() != musics_cache_.find(hash_code))
musics_cache_[hash_code]->Pause(); musics_cache_[hash_code]->Pause();
} }
void Player::Resume(String const& file_path) void Player::Resume(std::wstring const& file_path)
{ {
if (file_path.empty()) if (file_path.empty())
return; return;
size_t hash_code = std::hash<String>{}(file_path); size_t hash_code = std::hash<std::wstring>{}(file_path);
if (musics_cache_.end() != musics_cache_.find(hash_code)) if (musics_cache_.end() != musics_cache_.find(hash_code))
musics_cache_[hash_code]->Resume(); musics_cache_[hash_code]->Resume();
} }
void Player::Stop(String const& file_path) void Player::Stop(std::wstring const& file_path)
{ {
if (file_path.empty()) if (file_path.empty())
return; return;
size_t hash_code = std::hash<String>{}(file_path); size_t hash_code = std::hash<std::wstring>{}(file_path);
if (musics_cache_.end() != musics_cache_.find(hash_code)) if (musics_cache_.end() != musics_cache_.find(hash_code))
musics_cache_[hash_code]->Stop(); musics_cache_[hash_code]->Stop();
} }
bool Player::IsPlaying(String const& file_path) bool Player::IsPlaying(std::wstring const& file_path)
{ {
if (file_path.empty()) if (file_path.empty())
return false; return false;
size_t hash_code = std::hash<String>{}(file_path); size_t hash_code = std::hash<std::wstring>{}(file_path);
if (musics_cache_.end() != musics_cache_.find(hash_code)) if (musics_cache_.end() != musics_cache_.find(hash_code))
return musics_cache_[hash_code]->IsPlaying(); return musics_cache_[hash_code]->IsPlaying();
return false; return false;

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "../base/base.hpp" #include "../base/include-forwards.h"
#include "../base/Resource.h" #include "../base/Resource.h"
namespace easy2d namespace easy2d
@ -35,33 +35,33 @@ namespace easy2d
// 渡속潼稜있栗都 // 渡속潼稜있栗都
bool Load( bool Load(
String const& file_path /* 音乐文件路径 */ std::wstring const& file_path /* 音乐文件路径 */
); );
// 꺄렴稜있 // 꺄렴稜있
bool Play( bool Play(
String const& file_path, /* 音乐文件路径 */ std::wstring const& file_path, /* 音乐文件路径 */
int loop_count = 0 /* 꺄렴琦뻔늴鑒 (-1 槨琦뻔꺄렴) */ int loop_count = 0 /* 꺄렴琦뻔늴鑒 (-1 槨琦뻔꺄렴) */
); );
// 董界稜있 // 董界稜있
void Pause( void Pause(
String const& file_path /* 音乐文件路径 */ std::wstring const& file_path /* 音乐文件路径 */
); );
// 셨崎꺄렴稜있 // 셨崎꺄렴稜있
void Resume( void Resume(
String const& file_path /* 音乐文件路径 */ std::wstring const& file_path /* 音乐文件路径 */
); );
// 界岺稜있 // 界岺稜있
void Stop( void Stop(
String const& file_path /* 音乐文件路径 */ std::wstring const& file_path /* 音乐文件路径 */
); );
// 삿혤稜있꺄렴榴檄 // 삿혤稜있꺄렴榴檄
bool IsPlaying( bool IsPlaying(
String const& file_path /* 音乐文件路径 */ std::wstring const& file_path /* 音乐文件路径 */
); );
// 渡속潼稜있栗都 // 渡속潼稜있栗都

View File

@ -19,13 +19,15 @@
// THE SOFTWARE. // THE SOFTWARE.
#include "Transcoder.h" #include "Transcoder.h"
#include "../base/base.hpp" #include "../base/d2dhelper.hpp"
#include "../base/modules.h" #include "../base/modules.h"
#include "../base/logs.h" #include "../base/logs.h"
#include <shlwapi.h> #include <shlwapi.h>
namespace easy2d namespace easy2d
{ {
using namespace intrusive;
Transcoder::Transcoder() Transcoder::Transcoder()
: wave_format_(nullptr) : wave_format_(nullptr)
{ {
@ -49,7 +51,7 @@ namespace easy2d
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
IMFSourceReader* reader = nullptr; SmartPointer<IMFSourceReader> reader;
hr = modules::MediaFoundation().MFCreateSourceReaderFromURL( hr = modules::MediaFoundation().MFCreateSourceReaderFromURL(
file_path, file_path,
@ -59,22 +61,20 @@ namespace easy2d
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = ReadSource(reader, wave_data, wave_data_size); hr = ReadSource(reader.Get(), wave_data, wave_data_size);
} }
SafeRelease(reader);
return hr; return hr;
} }
HRESULT Transcoder::LoadMediaResource(Resource const& res, BYTE** wave_data, UINT32* wave_data_size) HRESULT Transcoder::LoadMediaResource(Resource const& res, BYTE** wave_data, UINT32* wave_data_size)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
HINSTANCE hinstance = GetModuleHandle(nullptr); HINSTANCE hinstance = GetModuleHandle(nullptr);
IStream* stream = nullptr;
IMFByteStream* byte_stream = nullptr; SmartPointer<IStream> stream;
IMFSourceReader* reader = nullptr; SmartPointer<IMFByteStream> byte_stream;
SmartPointer<IMFSourceReader> reader;
ResourceData buffer; ResourceData buffer;
if (!res.Load(&buffer)) { return false; } if (!res.Load(&buffer)) { return false; }
@ -92,13 +92,13 @@ namespace easy2d
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = modules::MediaFoundation().MFCreateMFByteStreamOnStream(stream, &byte_stream); hr = modules::MediaFoundation().MFCreateMFByteStreamOnStream(stream.Get(), &byte_stream);
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = modules::MediaFoundation().MFCreateSourceReaderFromByteStream( hr = modules::MediaFoundation().MFCreateSourceReaderFromByteStream(
byte_stream, byte_stream.Get(),
nullptr, nullptr,
&reader &reader
); );
@ -106,13 +106,9 @@ namespace easy2d
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = ReadSource(reader, wave_data, wave_data_size); hr = ReadSource(reader.Get(), wave_data, wave_data_size);
} }
SafeRelease(stream);
SafeRelease(byte_stream);
SafeRelease(reader);
return hr; return hr;
} }
@ -121,8 +117,8 @@ namespace easy2d
HRESULT hr = S_OK; HRESULT hr = S_OK;
DWORD max_stream_size = 0; DWORD max_stream_size = 0;
IMFMediaType* partial_type = nullptr; SmartPointer<IMFMediaType> partial_type;
IMFMediaType* uncompressed_type = nullptr; SmartPointer<IMFMediaType> uncompressed_type;
hr = modules::MediaFoundation().MFCreateMediaType(&partial_type); hr = modules::MediaFoundation().MFCreateMediaType(&partial_type);
@ -142,7 +138,7 @@ namespace easy2d
hr = reader->SetCurrentMediaType( hr = reader->SetCurrentMediaType(
MF_SOURCE_READER_FIRST_AUDIO_STREAM, MF_SOURCE_READER_FIRST_AUDIO_STREAM,
0, 0,
partial_type partial_type.Get()
); );
} }
@ -169,7 +165,7 @@ namespace easy2d
{ {
UINT32 size = 0; UINT32 size = 0;
hr = modules::MediaFoundation().MFCreateWaveFormatExFromMFMediaType( hr = modules::MediaFoundation().MFCreateWaveFormatExFromMFMediaType(
uncompressed_type, uncompressed_type.Get(),
&wave_format_, &wave_format_,
&size, &size,
MFWaveFormatExConvertFlag_Normal MFWaveFormatExConvertFlag_Normal
@ -200,11 +196,11 @@ namespace easy2d
{ {
DWORD flags = 0; DWORD flags = 0;
DWORD position = 0; DWORD position = 0;
IMFSample* sample = nullptr;
IMFMediaBuffer* buffer = nullptr;
BYTE* data = new (std::nothrow) BYTE[max_stream_size]; BYTE* data = new (std::nothrow) BYTE[max_stream_size];
SmartPointer<IMFSample> sample;
SmartPointer<IMFMediaBuffer> buffer;
if (data == nullptr) if (data == nullptr)
{ {
logs::Errorln("Low memory"); logs::Errorln("Low memory");
@ -251,9 +247,9 @@ namespace easy2d
hr = buffer->Unlock(); hr = buffer->Unlock();
} }
} }
SafeRelease(buffer); buffer = nullptr;
} }
SafeRelease(sample); sample = nullptr;
if (FAILED(hr)) { break; } if (FAILED(hr)) { break; }
} }
@ -266,9 +262,6 @@ namespace easy2d
} }
} }
SafeRelease(partial_type);
SafeRelease(uncompressed_type);
return hr; return hr;
} }
} }

View File

@ -25,12 +25,10 @@
<ClInclude Include="..\..\core\base\ActionManager.h" /> <ClInclude Include="..\..\core\base\ActionManager.h" />
<ClInclude Include="..\..\core\base\Animation.h" /> <ClInclude Include="..\..\core\base\Animation.h" />
<ClInclude Include="..\..\core\base\audio.h" /> <ClInclude Include="..\..\core\base\audio.h" />
<ClInclude Include="..\..\core\base\base.hpp" />
<ClInclude Include="..\..\core\base\BaseTypes.hpp" />
<ClInclude Include="..\..\core\base\Canvas.h" /> <ClInclude Include="..\..\core\base\Canvas.h" />
<ClInclude Include="..\..\core\base\Color.h" /> <ClInclude Include="..\..\core\base\Color.h" />
<ClInclude Include="..\..\core\base\d2dres.hpp" /> <ClInclude Include="..\..\core\base\d2dhelper.hpp" />
<ClInclude Include="..\..\core\base\Debuger.h" /> <ClInclude Include="..\..\core\base\DebugNode.h" />
<ClInclude Include="..\..\core\base\Delay.h" /> <ClInclude Include="..\..\core\base\Delay.h" />
<ClInclude Include="..\..\core\base\Event.hpp" /> <ClInclude Include="..\..\core\base\Event.hpp" />
<ClInclude Include="..\..\core\base\EventDispatcher.h" /> <ClInclude Include="..\..\core\base\EventDispatcher.h" />
@ -41,11 +39,14 @@
<ClInclude Include="..\..\core\base\Game.h" /> <ClInclude Include="..\..\core\base\Game.h" />
<ClInclude Include="..\..\core\base\Geometry.h" /> <ClInclude Include="..\..\core\base\Geometry.h" />
<ClInclude Include="..\..\core\base\GeometryNode.h" /> <ClInclude Include="..\..\core\base\GeometryNode.h" />
<ClInclude Include="..\..\core\base\helper.hpp" />
<ClInclude Include="..\..\core\base\Image.h" /> <ClInclude Include="..\..\core\base\Image.h" />
<ClInclude Include="..\..\core\base\include-forwards.h" />
<ClInclude Include="..\..\core\base\Input.h" /> <ClInclude Include="..\..\core\base\Input.h" />
<ClInclude Include="..\..\core\base\intrusive\List.hpp" /> <ClInclude Include="..\..\core\base\intrusive\List.hpp" />
<ClInclude Include="..\..\core\base\intrusive\SmartPointer.hpp" /> <ClInclude Include="..\..\core\base\intrusive\SmartPointer.hpp" />
<ClInclude Include="..\..\core\base\KeyEvent.hpp" /> <ClInclude Include="..\..\core\base\KeyEvent.hpp" />
<ClInclude Include="..\..\core\base\keys.hpp" />
<ClInclude Include="..\..\core\base\logs.h" /> <ClInclude Include="..\..\core\base\logs.h" />
<ClInclude Include="..\..\core\base\macros.h" /> <ClInclude Include="..\..\core\base\macros.h" />
<ClInclude Include="..\..\core\base\modules.h" /> <ClInclude Include="..\..\core\base\modules.h" />
@ -53,7 +54,7 @@
<ClInclude Include="..\..\core\base\Music.h" /> <ClInclude Include="..\..\core\base\Music.h" />
<ClInclude Include="..\..\core\base\Node.h" /> <ClInclude Include="..\..\core\base\Node.h" />
<ClInclude Include="..\..\core\base\noncopyable.hpp" /> <ClInclude Include="..\..\core\base\noncopyable.hpp" />
<ClInclude Include="..\..\core\base\ObjectBase.h" /> <ClInclude Include="..\..\core\base\Object.h" />
<ClInclude Include="..\..\core\base\Point.hpp" /> <ClInclude Include="..\..\core\base\Point.hpp" />
<ClInclude Include="..\..\core\base\Rect.hpp" /> <ClInclude Include="..\..\core\base\Rect.hpp" />
<ClInclude Include="..\..\core\base\RefCounter.hpp" /> <ClInclude Include="..\..\core\base\RefCounter.hpp" />
@ -71,7 +72,6 @@
<ClInclude Include="..\..\core\base\time.h" /> <ClInclude Include="..\..\core\base\time.h" />
<ClInclude Include="..\..\core\base\Transform.hpp" /> <ClInclude Include="..\..\core\base\Transform.hpp" />
<ClInclude Include="..\..\core\base\Transition.h" /> <ClInclude Include="..\..\core\base\Transition.h" />
<ClInclude Include="..\..\core\base\Unit.h" />
<ClInclude Include="..\..\core\base\window.h" /> <ClInclude Include="..\..\core\base\window.h" />
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\math\constants.hpp" /> <ClInclude Include="..\..\core\math\constants.hpp" />
@ -97,7 +97,7 @@
<ClCompile Include="..\..\core\base\audio.cpp" /> <ClCompile Include="..\..\core\base\audio.cpp" />
<ClCompile Include="..\..\core\base\Canvas.cpp" /> <ClCompile Include="..\..\core\base\Canvas.cpp" />
<ClCompile Include="..\..\core\base\Color.cpp" /> <ClCompile Include="..\..\core\base\Color.cpp" />
<ClCompile Include="..\..\core\base\Debuger.cpp" /> <ClCompile Include="..\..\core\base\DebugNode.cpp" />
<ClCompile Include="..\..\core\base\Delay.cpp" /> <ClCompile Include="..\..\core\base\Delay.cpp" />
<ClCompile Include="..\..\core\base\EventDispatcher.cpp" /> <ClCompile Include="..\..\core\base\EventDispatcher.cpp" />
<ClCompile Include="..\..\core\base\EventListener.cpp" /> <ClCompile Include="..\..\core\base\EventListener.cpp" />
@ -112,7 +112,7 @@
<ClCompile Include="..\..\core\base\modules.cpp" /> <ClCompile Include="..\..\core\base\modules.cpp" />
<ClCompile Include="..\..\core\base\Music.cpp" /> <ClCompile Include="..\..\core\base\Music.cpp" />
<ClCompile Include="..\..\core\base\Node.cpp" /> <ClCompile Include="..\..\core\base\Node.cpp" />
<ClCompile Include="..\..\core\base\ObjectBase.cpp" /> <ClCompile Include="..\..\core\base\Object.cpp" />
<ClCompile Include="..\..\core\base\render.cpp" /> <ClCompile Include="..\..\core\base\render.cpp" />
<ClCompile Include="..\..\core\base\Resource.cpp" /> <ClCompile Include="..\..\core\base\Resource.cpp" />
<ClCompile Include="..\..\core\base\Scene.cpp" /> <ClCompile Include="..\..\core\base\Scene.cpp" />
@ -123,7 +123,6 @@
<ClCompile Include="..\..\core\base\TextRenderer.cpp" /> <ClCompile Include="..\..\core\base\TextRenderer.cpp" />
<ClCompile Include="..\..\core\base\time.cpp" /> <ClCompile Include="..\..\core\base\time.cpp" />
<ClCompile Include="..\..\core\base\Transition.cpp" /> <ClCompile Include="..\..\core\base\Transition.cpp" />
<ClCompile Include="..\..\core\base\Unit.cpp" />
<ClCompile Include="..\..\core\base\window.cpp" /> <ClCompile Include="..\..\core\base\window.cpp" />
<ClCompile Include="..\..\core\math\rand.cpp" /> <ClCompile Include="..\..\core\math\rand.cpp" />
<ClCompile Include="..\..\core\ui\Button.cpp" /> <ClCompile Include="..\..\core\ui\Button.cpp" />

View File

@ -134,12 +134,6 @@
<ClInclude Include="..\..\core\base\intrusive\SmartPointer.hpp"> <ClInclude Include="..\..\core\base\intrusive\SmartPointer.hpp">
<Filter>base\intrusive</Filter> <Filter>base\intrusive</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\base.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\BaseTypes.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\Transform.hpp"> <ClInclude Include="..\..\core\base\Transform.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
@ -149,30 +143,18 @@
<ClInclude Include="..\..\core\base\Size.hpp"> <ClInclude Include="..\..\core\base\Size.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\d2dres.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\noncopyable.hpp"> <ClInclude Include="..\..\core\base\noncopyable.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\Debuger.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\utils\string.h"> <ClInclude Include="..\..\core\utils\string.h">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\ObjectBase.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\Geometry.h"> <ClInclude Include="..\..\core\base\Geometry.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\GeometryNode.h"> <ClInclude Include="..\..\core\base\GeometryNode.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\Unit.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\math\ease.hpp"> <ClInclude Include="..\..\core\math\ease.hpp">
<Filter>math</Filter> <Filter>math</Filter>
</ClInclude> </ClInclude>
@ -206,6 +188,24 @@
<ClInclude Include="..\..\core\base\EventListener.h"> <ClInclude Include="..\..\core\base\EventListener.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\Object.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\helper.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\d2dhelper.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\keys.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\include-forwards.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\DebugNode.h">
<Filter>base</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="base"> <Filter Include="base">
@ -321,24 +321,15 @@
<ClCompile Include="..\..\core\base\logs.cpp"> <ClCompile Include="..\..\core\base\logs.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\Debuger.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\utils\string.cpp"> <ClCompile Include="..\..\core\utils\string.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\ObjectBase.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\Geometry.cpp"> <ClCompile Include="..\..\core\base\Geometry.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\GeometryNode.cpp"> <ClCompile Include="..\..\core\base\GeometryNode.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\Unit.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\ActionTween.cpp"> <ClCompile Include="..\..\core\base\ActionTween.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
@ -357,5 +348,11 @@
<ClCompile Include="..\..\core\base\EventListener.cpp"> <ClCompile Include="..\..\core\base\EventListener.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\Object.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\DebugNode.cpp">
<Filter>base</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -25,12 +25,10 @@
<ClInclude Include="..\..\core\base\ActionManager.h" /> <ClInclude Include="..\..\core\base\ActionManager.h" />
<ClInclude Include="..\..\core\base\Animation.h" /> <ClInclude Include="..\..\core\base\Animation.h" />
<ClInclude Include="..\..\core\base\audio.h" /> <ClInclude Include="..\..\core\base\audio.h" />
<ClInclude Include="..\..\core\base\base.hpp" />
<ClInclude Include="..\..\core\base\BaseTypes.hpp" />
<ClInclude Include="..\..\core\base\Canvas.h" /> <ClInclude Include="..\..\core\base\Canvas.h" />
<ClInclude Include="..\..\core\base\Color.h" /> <ClInclude Include="..\..\core\base\Color.h" />
<ClInclude Include="..\..\core\base\d2dres.hpp" /> <ClInclude Include="..\..\core\base\d2dhelper.hpp" />
<ClInclude Include="..\..\core\base\Debuger.h" /> <ClInclude Include="..\..\core\base\DebugNode.h" />
<ClInclude Include="..\..\core\base\Delay.h" /> <ClInclude Include="..\..\core\base\Delay.h" />
<ClInclude Include="..\..\core\base\Event.hpp" /> <ClInclude Include="..\..\core\base\Event.hpp" />
<ClInclude Include="..\..\core\base\EventDispatcher.h" /> <ClInclude Include="..\..\core\base\EventDispatcher.h" />
@ -41,11 +39,14 @@
<ClInclude Include="..\..\core\base\Game.h" /> <ClInclude Include="..\..\core\base\Game.h" />
<ClInclude Include="..\..\core\base\Geometry.h" /> <ClInclude Include="..\..\core\base\Geometry.h" />
<ClInclude Include="..\..\core\base\GeometryNode.h" /> <ClInclude Include="..\..\core\base\GeometryNode.h" />
<ClInclude Include="..\..\core\base\helper.hpp" />
<ClInclude Include="..\..\core\base\Image.h" /> <ClInclude Include="..\..\core\base\Image.h" />
<ClInclude Include="..\..\core\base\include-forwards.h" />
<ClInclude Include="..\..\core\base\Input.h" /> <ClInclude Include="..\..\core\base\Input.h" />
<ClInclude Include="..\..\core\base\intrusive\List.hpp" /> <ClInclude Include="..\..\core\base\intrusive\List.hpp" />
<ClInclude Include="..\..\core\base\intrusive\SmartPointer.hpp" /> <ClInclude Include="..\..\core\base\intrusive\SmartPointer.hpp" />
<ClInclude Include="..\..\core\base\KeyEvent.hpp" /> <ClInclude Include="..\..\core\base\KeyEvent.hpp" />
<ClInclude Include="..\..\core\base\keys.hpp" />
<ClInclude Include="..\..\core\base\logs.h" /> <ClInclude Include="..\..\core\base\logs.h" />
<ClInclude Include="..\..\core\base\macros.h" /> <ClInclude Include="..\..\core\base\macros.h" />
<ClInclude Include="..\..\core\base\modules.h" /> <ClInclude Include="..\..\core\base\modules.h" />
@ -53,7 +54,7 @@
<ClInclude Include="..\..\core\base\Music.h" /> <ClInclude Include="..\..\core\base\Music.h" />
<ClInclude Include="..\..\core\base\Node.h" /> <ClInclude Include="..\..\core\base\Node.h" />
<ClInclude Include="..\..\core\base\noncopyable.hpp" /> <ClInclude Include="..\..\core\base\noncopyable.hpp" />
<ClInclude Include="..\..\core\base\ObjectBase.h" /> <ClInclude Include="..\..\core\base\Object.h" />
<ClInclude Include="..\..\core\base\Point.hpp" /> <ClInclude Include="..\..\core\base\Point.hpp" />
<ClInclude Include="..\..\core\base\Rect.hpp" /> <ClInclude Include="..\..\core\base\Rect.hpp" />
<ClInclude Include="..\..\core\base\RefCounter.hpp" /> <ClInclude Include="..\..\core\base\RefCounter.hpp" />
@ -71,7 +72,6 @@
<ClInclude Include="..\..\core\base\time.h" /> <ClInclude Include="..\..\core\base\time.h" />
<ClInclude Include="..\..\core\base\Transform.hpp" /> <ClInclude Include="..\..\core\base\Transform.hpp" />
<ClInclude Include="..\..\core\base\Transition.h" /> <ClInclude Include="..\..\core\base\Transition.h" />
<ClInclude Include="..\..\core\base\Unit.h" />
<ClInclude Include="..\..\core\base\window.h" /> <ClInclude Include="..\..\core\base\window.h" />
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\math\constants.hpp" /> <ClInclude Include="..\..\core\math\constants.hpp" />
@ -97,7 +97,7 @@
<ClCompile Include="..\..\core\base\audio.cpp" /> <ClCompile Include="..\..\core\base\audio.cpp" />
<ClCompile Include="..\..\core\base\Canvas.cpp" /> <ClCompile Include="..\..\core\base\Canvas.cpp" />
<ClCompile Include="..\..\core\base\Color.cpp" /> <ClCompile Include="..\..\core\base\Color.cpp" />
<ClCompile Include="..\..\core\base\Debuger.cpp" /> <ClCompile Include="..\..\core\base\DebugNode.cpp" />
<ClCompile Include="..\..\core\base\Delay.cpp" /> <ClCompile Include="..\..\core\base\Delay.cpp" />
<ClCompile Include="..\..\core\base\EventDispatcher.cpp" /> <ClCompile Include="..\..\core\base\EventDispatcher.cpp" />
<ClCompile Include="..\..\core\base\EventListener.cpp" /> <ClCompile Include="..\..\core\base\EventListener.cpp" />
@ -112,7 +112,7 @@
<ClCompile Include="..\..\core\base\modules.cpp" /> <ClCompile Include="..\..\core\base\modules.cpp" />
<ClCompile Include="..\..\core\base\Music.cpp" /> <ClCompile Include="..\..\core\base\Music.cpp" />
<ClCompile Include="..\..\core\base\Node.cpp" /> <ClCompile Include="..\..\core\base\Node.cpp" />
<ClCompile Include="..\..\core\base\ObjectBase.cpp" /> <ClCompile Include="..\..\core\base\Object.cpp" />
<ClCompile Include="..\..\core\base\render.cpp" /> <ClCompile Include="..\..\core\base\render.cpp" />
<ClCompile Include="..\..\core\base\Resource.cpp" /> <ClCompile Include="..\..\core\base\Resource.cpp" />
<ClCompile Include="..\..\core\base\Scene.cpp" /> <ClCompile Include="..\..\core\base\Scene.cpp" />
@ -123,7 +123,6 @@
<ClCompile Include="..\..\core\base\TextRenderer.cpp" /> <ClCompile Include="..\..\core\base\TextRenderer.cpp" />
<ClCompile Include="..\..\core\base\time.cpp" /> <ClCompile Include="..\..\core\base\time.cpp" />
<ClCompile Include="..\..\core\base\Transition.cpp" /> <ClCompile Include="..\..\core\base\Transition.cpp" />
<ClCompile Include="..\..\core\base\Unit.cpp" />
<ClCompile Include="..\..\core\base\window.cpp" /> <ClCompile Include="..\..\core\base\window.cpp" />
<ClCompile Include="..\..\core\math\rand.cpp" /> <ClCompile Include="..\..\core\math\rand.cpp" />
<ClCompile Include="..\..\core\ui\Button.cpp" /> <ClCompile Include="..\..\core\ui\Button.cpp" />

View File

@ -134,12 +134,6 @@
<ClInclude Include="..\..\core\base\intrusive\SmartPointer.hpp"> <ClInclude Include="..\..\core\base\intrusive\SmartPointer.hpp">
<Filter>base\intrusive</Filter> <Filter>base\intrusive</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\base.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\BaseTypes.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\Transform.hpp"> <ClInclude Include="..\..\core\base\Transform.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
@ -149,30 +143,18 @@
<ClInclude Include="..\..\core\base\Size.hpp"> <ClInclude Include="..\..\core\base\Size.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\d2dres.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\noncopyable.hpp"> <ClInclude Include="..\..\core\base\noncopyable.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\Debuger.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\utils\string.h"> <ClInclude Include="..\..\core\utils\string.h">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\ObjectBase.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\Geometry.h"> <ClInclude Include="..\..\core\base\Geometry.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\GeometryNode.h"> <ClInclude Include="..\..\core\base\GeometryNode.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\Unit.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\math\ease.hpp"> <ClInclude Include="..\..\core\math\ease.hpp">
<Filter>math</Filter> <Filter>math</Filter>
</ClInclude> </ClInclude>
@ -206,6 +188,24 @@
<ClInclude Include="..\..\core\base\EventListener.h"> <ClInclude Include="..\..\core\base\EventListener.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\Object.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\helper.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\d2dhelper.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\keys.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\include-forwards.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\DebugNode.h">
<Filter>base</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="base"> <Filter Include="base">
@ -321,24 +321,15 @@
<ClCompile Include="..\..\core\base\logs.cpp"> <ClCompile Include="..\..\core\base\logs.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\Debuger.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\utils\string.cpp"> <ClCompile Include="..\..\core\utils\string.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\ObjectBase.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\Geometry.cpp"> <ClCompile Include="..\..\core\base\Geometry.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\GeometryNode.cpp"> <ClCompile Include="..\..\core\base\GeometryNode.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\Unit.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\ActionTween.cpp"> <ClCompile Include="..\..\core\base\ActionTween.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
@ -357,5 +348,11 @@
<ClCompile Include="..\..\core\base\EventListener.cpp"> <ClCompile Include="..\..\core\base\EventListener.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\Object.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\DebugNode.cpp">
<Filter>base</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -25,12 +25,10 @@
<ClInclude Include="..\..\core\base\ActionManager.h" /> <ClInclude Include="..\..\core\base\ActionManager.h" />
<ClInclude Include="..\..\core\base\Animation.h" /> <ClInclude Include="..\..\core\base\Animation.h" />
<ClInclude Include="..\..\core\base\audio.h" /> <ClInclude Include="..\..\core\base\audio.h" />
<ClInclude Include="..\..\core\base\base.hpp" />
<ClInclude Include="..\..\core\base\BaseTypes.hpp" />
<ClInclude Include="..\..\core\base\Canvas.h" /> <ClInclude Include="..\..\core\base\Canvas.h" />
<ClInclude Include="..\..\core\base\Color.h" /> <ClInclude Include="..\..\core\base\Color.h" />
<ClInclude Include="..\..\core\base\d2dres.hpp" /> <ClInclude Include="..\..\core\base\d2dhelper.hpp" />
<ClInclude Include="..\..\core\base\Debuger.h" /> <ClInclude Include="..\..\core\base\DebugNode.h" />
<ClInclude Include="..\..\core\base\Delay.h" /> <ClInclude Include="..\..\core\base\Delay.h" />
<ClInclude Include="..\..\core\base\Event.hpp" /> <ClInclude Include="..\..\core\base\Event.hpp" />
<ClInclude Include="..\..\core\base\EventDispatcher.h" /> <ClInclude Include="..\..\core\base\EventDispatcher.h" />
@ -41,11 +39,14 @@
<ClInclude Include="..\..\core\base\Game.h" /> <ClInclude Include="..\..\core\base\Game.h" />
<ClInclude Include="..\..\core\base\Geometry.h" /> <ClInclude Include="..\..\core\base\Geometry.h" />
<ClInclude Include="..\..\core\base\GeometryNode.h" /> <ClInclude Include="..\..\core\base\GeometryNode.h" />
<ClInclude Include="..\..\core\base\helper.hpp" />
<ClInclude Include="..\..\core\base\Image.h" /> <ClInclude Include="..\..\core\base\Image.h" />
<ClInclude Include="..\..\core\base\include-forwards.h" />
<ClInclude Include="..\..\core\base\Input.h" /> <ClInclude Include="..\..\core\base\Input.h" />
<ClInclude Include="..\..\core\base\intrusive\List.hpp" /> <ClInclude Include="..\..\core\base\intrusive\List.hpp" />
<ClInclude Include="..\..\core\base\intrusive\SmartPointer.hpp" /> <ClInclude Include="..\..\core\base\intrusive\SmartPointer.hpp" />
<ClInclude Include="..\..\core\base\KeyEvent.hpp" /> <ClInclude Include="..\..\core\base\KeyEvent.hpp" />
<ClInclude Include="..\..\core\base\keys.hpp" />
<ClInclude Include="..\..\core\base\logs.h" /> <ClInclude Include="..\..\core\base\logs.h" />
<ClInclude Include="..\..\core\base\macros.h" /> <ClInclude Include="..\..\core\base\macros.h" />
<ClInclude Include="..\..\core\base\modules.h" /> <ClInclude Include="..\..\core\base\modules.h" />
@ -53,7 +54,7 @@
<ClInclude Include="..\..\core\base\Music.h" /> <ClInclude Include="..\..\core\base\Music.h" />
<ClInclude Include="..\..\core\base\Node.h" /> <ClInclude Include="..\..\core\base\Node.h" />
<ClInclude Include="..\..\core\base\noncopyable.hpp" /> <ClInclude Include="..\..\core\base\noncopyable.hpp" />
<ClInclude Include="..\..\core\base\ObjectBase.h" /> <ClInclude Include="..\..\core\base\Object.h" />
<ClInclude Include="..\..\core\base\Point.hpp" /> <ClInclude Include="..\..\core\base\Point.hpp" />
<ClInclude Include="..\..\core\base\Rect.hpp" /> <ClInclude Include="..\..\core\base\Rect.hpp" />
<ClInclude Include="..\..\core\base\RefCounter.hpp" /> <ClInclude Include="..\..\core\base\RefCounter.hpp" />
@ -71,7 +72,6 @@
<ClInclude Include="..\..\core\base\time.h" /> <ClInclude Include="..\..\core\base\time.h" />
<ClInclude Include="..\..\core\base\Transform.hpp" /> <ClInclude Include="..\..\core\base\Transform.hpp" />
<ClInclude Include="..\..\core\base\Transition.h" /> <ClInclude Include="..\..\core\base\Transition.h" />
<ClInclude Include="..\..\core\base\Unit.h" />
<ClInclude Include="..\..\core\base\window.h" /> <ClInclude Include="..\..\core\base\window.h" />
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\math\constants.hpp" /> <ClInclude Include="..\..\core\math\constants.hpp" />
@ -97,7 +97,7 @@
<ClCompile Include="..\..\core\base\audio.cpp" /> <ClCompile Include="..\..\core\base\audio.cpp" />
<ClCompile Include="..\..\core\base\Canvas.cpp" /> <ClCompile Include="..\..\core\base\Canvas.cpp" />
<ClCompile Include="..\..\core\base\Color.cpp" /> <ClCompile Include="..\..\core\base\Color.cpp" />
<ClCompile Include="..\..\core\base\Debuger.cpp" /> <ClCompile Include="..\..\core\base\DebugNode.cpp" />
<ClCompile Include="..\..\core\base\Delay.cpp" /> <ClCompile Include="..\..\core\base\Delay.cpp" />
<ClCompile Include="..\..\core\base\EventDispatcher.cpp" /> <ClCompile Include="..\..\core\base\EventDispatcher.cpp" />
<ClCompile Include="..\..\core\base\EventListener.cpp" /> <ClCompile Include="..\..\core\base\EventListener.cpp" />
@ -112,7 +112,7 @@
<ClCompile Include="..\..\core\base\modules.cpp" /> <ClCompile Include="..\..\core\base\modules.cpp" />
<ClCompile Include="..\..\core\base\Music.cpp" /> <ClCompile Include="..\..\core\base\Music.cpp" />
<ClCompile Include="..\..\core\base\Node.cpp" /> <ClCompile Include="..\..\core\base\Node.cpp" />
<ClCompile Include="..\..\core\base\ObjectBase.cpp" /> <ClCompile Include="..\..\core\base\Object.cpp" />
<ClCompile Include="..\..\core\base\render.cpp" /> <ClCompile Include="..\..\core\base\render.cpp" />
<ClCompile Include="..\..\core\base\Resource.cpp" /> <ClCompile Include="..\..\core\base\Resource.cpp" />
<ClCompile Include="..\..\core\base\Scene.cpp" /> <ClCompile Include="..\..\core\base\Scene.cpp" />
@ -123,7 +123,6 @@
<ClCompile Include="..\..\core\base\TextRenderer.cpp" /> <ClCompile Include="..\..\core\base\TextRenderer.cpp" />
<ClCompile Include="..\..\core\base\time.cpp" /> <ClCompile Include="..\..\core\base\time.cpp" />
<ClCompile Include="..\..\core\base\Transition.cpp" /> <ClCompile Include="..\..\core\base\Transition.cpp" />
<ClCompile Include="..\..\core\base\Unit.cpp" />
<ClCompile Include="..\..\core\base\window.cpp" /> <ClCompile Include="..\..\core\base\window.cpp" />
<ClCompile Include="..\..\core\math\rand.cpp" /> <ClCompile Include="..\..\core\math\rand.cpp" />
<ClCompile Include="..\..\core\ui\Button.cpp" /> <ClCompile Include="..\..\core\ui\Button.cpp" />

View File

@ -134,12 +134,6 @@
<ClInclude Include="..\..\core\base\intrusive\SmartPointer.hpp"> <ClInclude Include="..\..\core\base\intrusive\SmartPointer.hpp">
<Filter>base\intrusive</Filter> <Filter>base\intrusive</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\base.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\BaseTypes.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\Transform.hpp"> <ClInclude Include="..\..\core\base\Transform.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
@ -149,30 +143,18 @@
<ClInclude Include="..\..\core\base\Size.hpp"> <ClInclude Include="..\..\core\base\Size.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\d2dres.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\noncopyable.hpp"> <ClInclude Include="..\..\core\base\noncopyable.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\Debuger.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\utils\string.h"> <ClInclude Include="..\..\core\utils\string.h">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\ObjectBase.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\Geometry.h"> <ClInclude Include="..\..\core\base\Geometry.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\GeometryNode.h"> <ClInclude Include="..\..\core\base\GeometryNode.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\Unit.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\math\ease.hpp"> <ClInclude Include="..\..\core\math\ease.hpp">
<Filter>math</Filter> <Filter>math</Filter>
</ClInclude> </ClInclude>
@ -206,6 +188,24 @@
<ClInclude Include="..\..\core\base\EventListener.h"> <ClInclude Include="..\..\core\base\EventListener.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\Object.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\helper.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\d2dhelper.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\keys.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\include-forwards.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\DebugNode.h">
<Filter>base</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="base"> <Filter Include="base">
@ -321,24 +321,15 @@
<ClCompile Include="..\..\core\base\logs.cpp"> <ClCompile Include="..\..\core\base\logs.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\Debuger.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\utils\string.cpp"> <ClCompile Include="..\..\core\utils\string.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\ObjectBase.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\Geometry.cpp"> <ClCompile Include="..\..\core\base\Geometry.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\GeometryNode.cpp"> <ClCompile Include="..\..\core\base\GeometryNode.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\Unit.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\ActionTween.cpp"> <ClCompile Include="..\..\core\base\ActionTween.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
@ -357,5 +348,11 @@
<ClCompile Include="..\..\core\base\EventListener.cpp"> <ClCompile Include="..\..\core\base\EventListener.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\Object.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\DebugNode.cpp">
<Filter>base</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>