parent
46ce8726cb
commit
3b5704ee22
|
|
@ -1,45 +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 "ResLoader.h"
|
|
||||||
|
|
||||||
namespace easy2d
|
|
||||||
{
|
|
||||||
/*void ResLoader::Add(String const & id, SpImage const & image)
|
|
||||||
{
|
|
||||||
res_.insert(std::make_pair(id, image.Get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ResLoader::Add(String const & id, SpFrames const & frames)
|
|
||||||
{
|
|
||||||
res_.insert(std::make_pair(id, frames.Get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
SpImage easy2d::ResLoader::GetImage(String const & id)
|
|
||||||
{
|
|
||||||
return Get<Image*>(id);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*SpFrames easy2d::ResLoader::GetFrames(String const & id)
|
|
||||||
{
|
|
||||||
return Get<Frames*>(id);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -44,7 +44,7 @@
|
||||||
<ClInclude Include="..\..\src\core\include-forwards.h" />
|
<ClInclude Include="..\..\src\core\include-forwards.h" />
|
||||||
<ClInclude Include="..\..\src\core\Input.h" />
|
<ClInclude Include="..\..\src\core\Input.h" />
|
||||||
<ClInclude Include="..\..\src\core\intrusive\List.hpp" />
|
<ClInclude Include="..\..\src\core\intrusive\List.hpp" />
|
||||||
<ClInclude Include="..\..\src\core\intrusive\SmartPointer.hpp" />
|
<ClInclude Include="..\..\src\core\intrusive\SmartPtr.hpp" />
|
||||||
<ClInclude Include="..\..\src\core\KeyEvent.hpp" />
|
<ClInclude Include="..\..\src\core\KeyEvent.hpp" />
|
||||||
<ClInclude Include="..\..\src\core\keys.hpp" />
|
<ClInclude Include="..\..\src\core\keys.hpp" />
|
||||||
<ClInclude Include="..\..\src\core\logs.h" />
|
<ClInclude Include="..\..\src\core\logs.h" />
|
||||||
|
|
@ -84,6 +84,7 @@
|
||||||
<ClInclude Include="..\..\src\utils\File.h" />
|
<ClInclude Include="..\..\src\utils\File.h" />
|
||||||
<ClInclude Include="..\..\src\utils\Path.h" />
|
<ClInclude Include="..\..\src\utils\Path.h" />
|
||||||
<ClInclude Include="..\..\src\utils\Player.h" />
|
<ClInclude Include="..\..\src\utils\Player.h" />
|
||||||
|
<ClInclude Include="..\..\src\utils\ResLoader.h" />
|
||||||
<ClInclude Include="..\..\src\utils\string.h" />
|
<ClInclude Include="..\..\src\utils\string.h" />
|
||||||
<ClInclude Include="..\..\src\utils\Transcoder.h" />
|
<ClInclude Include="..\..\src\utils\Transcoder.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
@ -129,6 +130,7 @@
|
||||||
<ClCompile Include="..\..\src\utils\File.cpp" />
|
<ClCompile Include="..\..\src\utils\File.cpp" />
|
||||||
<ClCompile Include="..\..\src\utils\Path.cpp" />
|
<ClCompile Include="..\..\src\utils\Path.cpp" />
|
||||||
<ClCompile Include="..\..\src\utils\Player.cpp" />
|
<ClCompile Include="..\..\src\utils\Player.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\utils\ResLoader.cpp" />
|
||||||
<ClCompile Include="..\..\src\utils\string.cpp" />
|
<ClCompile Include="..\..\src\utils\string.cpp" />
|
||||||
<ClCompile Include="..\..\src\utils\Transcoder.cpp" />
|
<ClCompile Include="..\..\src\utils\Transcoder.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@
|
||||||
<ClInclude Include="..\..\src\core\intrusive\List.hpp">
|
<ClInclude Include="..\..\src\core\intrusive\List.hpp">
|
||||||
<Filter>core\intrusive</Filter>
|
<Filter>core\intrusive</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\core\intrusive\SmartPointer.hpp">
|
<ClInclude Include="..\..\src\core\intrusive\SmartPtr.hpp">
|
||||||
<Filter>core\intrusive</Filter>
|
<Filter>core\intrusive</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\core\Transform.hpp">
|
<ClInclude Include="..\..\src\core\Transform.hpp">
|
||||||
|
|
@ -200,6 +200,9 @@
|
||||||
<ClInclude Include="..\..\src\math\Rect.hpp">
|
<ClInclude Include="..\..\src\math\Rect.hpp">
|
||||||
<Filter>math</Filter>
|
<Filter>math</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\utils\ResLoader.h">
|
||||||
|
<Filter>utils</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="core">
|
<Filter Include="core">
|
||||||
|
|
@ -348,5 +351,8 @@
|
||||||
<ClCompile Include="..\..\src\core\DebugNode.cpp">
|
<ClCompile Include="..\..\src\core\DebugNode.cpp">
|
||||||
<Filter>core</Filter>
|
<Filter>core</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\utils\ResLoader.cpp">
|
||||||
|
<Filter>utils</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -44,7 +44,7 @@
|
||||||
<ClInclude Include="..\..\src\core\include-forwards.h" />
|
<ClInclude Include="..\..\src\core\include-forwards.h" />
|
||||||
<ClInclude Include="..\..\src\core\Input.h" />
|
<ClInclude Include="..\..\src\core\Input.h" />
|
||||||
<ClInclude Include="..\..\src\core\intrusive\List.hpp" />
|
<ClInclude Include="..\..\src\core\intrusive\List.hpp" />
|
||||||
<ClInclude Include="..\..\src\core\intrusive\SmartPointer.hpp" />
|
<ClInclude Include="..\..\src\core\intrusive\SmartPtr.hpp" />
|
||||||
<ClInclude Include="..\..\src\core\KeyEvent.hpp" />
|
<ClInclude Include="..\..\src\core\KeyEvent.hpp" />
|
||||||
<ClInclude Include="..\..\src\core\keys.hpp" />
|
<ClInclude Include="..\..\src\core\keys.hpp" />
|
||||||
<ClInclude Include="..\..\src\core\logs.h" />
|
<ClInclude Include="..\..\src\core\logs.h" />
|
||||||
|
|
@ -84,6 +84,7 @@
|
||||||
<ClInclude Include="..\..\src\utils\File.h" />
|
<ClInclude Include="..\..\src\utils\File.h" />
|
||||||
<ClInclude Include="..\..\src\utils\Path.h" />
|
<ClInclude Include="..\..\src\utils\Path.h" />
|
||||||
<ClInclude Include="..\..\src\utils\Player.h" />
|
<ClInclude Include="..\..\src\utils\Player.h" />
|
||||||
|
<ClInclude Include="..\..\src\utils\ResLoader.h" />
|
||||||
<ClInclude Include="..\..\src\utils\string.h" />
|
<ClInclude Include="..\..\src\utils\string.h" />
|
||||||
<ClInclude Include="..\..\src\utils\Transcoder.h" />
|
<ClInclude Include="..\..\src\utils\Transcoder.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
@ -129,6 +130,7 @@
|
||||||
<ClCompile Include="..\..\src\utils\File.cpp" />
|
<ClCompile Include="..\..\src\utils\File.cpp" />
|
||||||
<ClCompile Include="..\..\src\utils\Path.cpp" />
|
<ClCompile Include="..\..\src\utils\Path.cpp" />
|
||||||
<ClCompile Include="..\..\src\utils\Player.cpp" />
|
<ClCompile Include="..\..\src\utils\Player.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\utils\ResLoader.cpp" />
|
||||||
<ClCompile Include="..\..\src\utils\string.cpp" />
|
<ClCompile Include="..\..\src\utils\string.cpp" />
|
||||||
<ClCompile Include="..\..\src\utils\Transcoder.cpp" />
|
<ClCompile Include="..\..\src\utils\Transcoder.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@
|
||||||
<ClInclude Include="..\..\src\core\intrusive\List.hpp">
|
<ClInclude Include="..\..\src\core\intrusive\List.hpp">
|
||||||
<Filter>core\intrusive</Filter>
|
<Filter>core\intrusive</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\core\intrusive\SmartPointer.hpp">
|
<ClInclude Include="..\..\src\core\intrusive\SmartPtr.hpp">
|
||||||
<Filter>core\intrusive</Filter>
|
<Filter>core\intrusive</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\core\Transform.hpp">
|
<ClInclude Include="..\..\src\core\Transform.hpp">
|
||||||
|
|
@ -200,6 +200,9 @@
|
||||||
<ClInclude Include="..\..\src\math\Rect.hpp">
|
<ClInclude Include="..\..\src\math\Rect.hpp">
|
||||||
<Filter>math</Filter>
|
<Filter>math</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\utils\ResLoader.h">
|
||||||
|
<Filter>utils</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="core">
|
<Filter Include="core">
|
||||||
|
|
@ -348,5 +351,8 @@
|
||||||
<ClCompile Include="..\..\src\core\DebugNode.cpp">
|
<ClCompile Include="..\..\src\core\DebugNode.cpp">
|
||||||
<Filter>core</Filter>
|
<Filter>core</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\utils\ResLoader.cpp">
|
||||||
|
<Filter>utils</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -44,7 +44,7 @@
|
||||||
<ClInclude Include="..\..\src\core\include-forwards.h" />
|
<ClInclude Include="..\..\src\core\include-forwards.h" />
|
||||||
<ClInclude Include="..\..\src\core\Input.h" />
|
<ClInclude Include="..\..\src\core\Input.h" />
|
||||||
<ClInclude Include="..\..\src\core\intrusive\List.hpp" />
|
<ClInclude Include="..\..\src\core\intrusive\List.hpp" />
|
||||||
<ClInclude Include="..\..\src\core\intrusive\SmartPointer.hpp" />
|
<ClInclude Include="..\..\src\core\intrusive\SmartPtr.hpp" />
|
||||||
<ClInclude Include="..\..\src\core\KeyEvent.hpp" />
|
<ClInclude Include="..\..\src\core\KeyEvent.hpp" />
|
||||||
<ClInclude Include="..\..\src\core\keys.hpp" />
|
<ClInclude Include="..\..\src\core\keys.hpp" />
|
||||||
<ClInclude Include="..\..\src\core\logs.h" />
|
<ClInclude Include="..\..\src\core\logs.h" />
|
||||||
|
|
@ -84,6 +84,7 @@
|
||||||
<ClInclude Include="..\..\src\utils\File.h" />
|
<ClInclude Include="..\..\src\utils\File.h" />
|
||||||
<ClInclude Include="..\..\src\utils\Path.h" />
|
<ClInclude Include="..\..\src\utils\Path.h" />
|
||||||
<ClInclude Include="..\..\src\utils\Player.h" />
|
<ClInclude Include="..\..\src\utils\Player.h" />
|
||||||
|
<ClInclude Include="..\..\src\utils\ResLoader.h" />
|
||||||
<ClInclude Include="..\..\src\utils\string.h" />
|
<ClInclude Include="..\..\src\utils\string.h" />
|
||||||
<ClInclude Include="..\..\src\utils\Transcoder.h" />
|
<ClInclude Include="..\..\src\utils\Transcoder.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
@ -129,6 +130,7 @@
|
||||||
<ClCompile Include="..\..\src\utils\File.cpp" />
|
<ClCompile Include="..\..\src\utils\File.cpp" />
|
||||||
<ClCompile Include="..\..\src\utils\Path.cpp" />
|
<ClCompile Include="..\..\src\utils\Path.cpp" />
|
||||||
<ClCompile Include="..\..\src\utils\Player.cpp" />
|
<ClCompile Include="..\..\src\utils\Player.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\utils\ResLoader.cpp" />
|
||||||
<ClCompile Include="..\..\src\utils\string.cpp" />
|
<ClCompile Include="..\..\src\utils\string.cpp" />
|
||||||
<ClCompile Include="..\..\src\utils\Transcoder.cpp" />
|
<ClCompile Include="..\..\src\utils\Transcoder.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@
|
||||||
<ClInclude Include="..\..\src\core\intrusive\List.hpp">
|
<ClInclude Include="..\..\src\core\intrusive\List.hpp">
|
||||||
<Filter>core\intrusive</Filter>
|
<Filter>core\intrusive</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\core\intrusive\SmartPointer.hpp">
|
<ClInclude Include="..\..\src\core\intrusive\SmartPtr.hpp">
|
||||||
<Filter>core\intrusive</Filter>
|
<Filter>core\intrusive</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\core\Transform.hpp">
|
<ClInclude Include="..\..\src\core\Transform.hpp">
|
||||||
|
|
@ -200,6 +200,9 @@
|
||||||
<ClInclude Include="..\..\src\math\Rect.hpp">
|
<ClInclude Include="..\..\src\math\Rect.hpp">
|
||||||
<Filter>math</Filter>
|
<Filter>math</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\utils\ResLoader.h">
|
||||||
|
<Filter>utils</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="core">
|
<Filter Include="core">
|
||||||
|
|
@ -348,5 +351,8 @@
|
||||||
<ClCompile Include="..\..\src\core\DebugNode.cpp">
|
<ClCompile Include="..\..\src\core\DebugNode.cpp">
|
||||||
<Filter>core</Filter>
|
<Filter>core</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\utils\ResLoader.cpp">
|
||||||
|
<Filter>utils</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -30,13 +30,13 @@ namespace easy2d
|
||||||
|
|
||||||
class Action
|
class Action
|
||||||
: public Object
|
: public Object
|
||||||
, protected intrusive::ListItem<SpAction>
|
, protected intrusive::ListItem<ActionPtr>
|
||||||
{
|
{
|
||||||
friend class ActionManager;
|
friend class ActionManager;
|
||||||
friend class Loop;
|
friend class Loop;
|
||||||
friend class Sequence;
|
friend class Sequence;
|
||||||
friend class Spawn;
|
friend class Spawn;
|
||||||
friend class intrusive::List<SpAction>;
|
friend class intrusive::List<ActionPtr>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Action() : running_(false), done_(false), initialized_(false) {}
|
Action() : running_(false), done_(false), initialized_(false) {}
|
||||||
|
|
@ -56,10 +56,10 @@ namespace easy2d
|
||||||
virtual void Stop() { if (!done_) { done_ = true; if (cb_) cb_(); } }
|
virtual void Stop() { if (!done_) { done_ = true; if (cb_) cb_(); } }
|
||||||
|
|
||||||
// 获取动作的拷贝
|
// 获取动作的拷贝
|
||||||
virtual SpAction Clone() const = 0;
|
virtual ActionPtr Clone() const = 0;
|
||||||
|
|
||||||
// 获取动作的倒转
|
// 获取动作的倒转
|
||||||
virtual SpAction Reverse() const = 0;
|
virtual ActionPtr Reverse() const = 0;
|
||||||
|
|
||||||
// 重置动作
|
// 重置动作
|
||||||
virtual void Reset()
|
virtual void Reset()
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace easy2d
|
||||||
// Loop
|
// Loop
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
||||||
Loop::Loop(SpAction const& action, int times)
|
Loop::Loop(ActionPtr const& action, int times)
|
||||||
: action_(action)
|
: action_(action)
|
||||||
, times_(0)
|
, times_(0)
|
||||||
, total_times_(times)
|
, total_times_(times)
|
||||||
|
|
@ -41,7 +41,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction Loop::Clone() const
|
ActionPtr Loop::Clone() const
|
||||||
{
|
{
|
||||||
if (action_)
|
if (action_)
|
||||||
{
|
{
|
||||||
|
|
@ -53,7 +53,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction Loop::Reverse() const
|
ActionPtr Loop::Reverse() const
|
||||||
{
|
{
|
||||||
if (action_)
|
if (action_)
|
||||||
{
|
{
|
||||||
|
|
@ -125,7 +125,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Sequence::Sequence(Array<SpAction> const& actions)
|
Sequence::Sequence(Array<ActionPtr> const& actions)
|
||||||
: action_index_(0)
|
: action_index_(0)
|
||||||
{
|
{
|
||||||
this->Add(actions);
|
this->Add(actions);
|
||||||
|
|
@ -172,7 +172,7 @@ namespace easy2d
|
||||||
action_index_ = 0;
|
action_index_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sequence::Add(SpAction const& action)
|
void Sequence::Add(ActionPtr const& action)
|
||||||
{
|
{
|
||||||
if (action)
|
if (action)
|
||||||
{
|
{
|
||||||
|
|
@ -180,7 +180,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sequence::Add(Array<SpAction> const& actions)
|
void Sequence::Add(Array<ActionPtr> const& actions)
|
||||||
{
|
{
|
||||||
for (const auto &action : actions)
|
for (const auto &action : actions)
|
||||||
{
|
{
|
||||||
|
|
@ -188,7 +188,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction Sequence::Clone() const
|
ActionPtr Sequence::Clone() const
|
||||||
{
|
{
|
||||||
auto sequence = new (std::nothrow) Sequence();
|
auto sequence = new (std::nothrow) Sequence();
|
||||||
if (sequence)
|
if (sequence)
|
||||||
|
|
@ -204,7 +204,7 @@ namespace easy2d
|
||||||
return sequence;
|
return sequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction Sequence::Reverse() const
|
ActionPtr Sequence::Reverse() const
|
||||||
{
|
{
|
||||||
auto sequence = new (std::nothrow) Sequence();
|
auto sequence = new (std::nothrow) Sequence();
|
||||||
if (sequence && !actions_.empty())
|
if (sequence && !actions_.empty())
|
||||||
|
|
@ -227,7 +227,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Spawn::Spawn(Array<SpAction> const& actions)
|
Spawn::Spawn(Array<ActionPtr> const& actions)
|
||||||
{
|
{
|
||||||
this->Add(actions);
|
this->Add(actions);
|
||||||
}
|
}
|
||||||
|
|
@ -281,7 +281,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Spawn::Add(SpAction const& action)
|
void Spawn::Add(ActionPtr const& action)
|
||||||
{
|
{
|
||||||
if (action)
|
if (action)
|
||||||
{
|
{
|
||||||
|
|
@ -289,7 +289,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Spawn::Add(Array<SpAction> const& actions)
|
void Spawn::Add(Array<ActionPtr> const& actions)
|
||||||
{
|
{
|
||||||
for (const auto &action : actions)
|
for (const auto &action : actions)
|
||||||
{
|
{
|
||||||
|
|
@ -297,7 +297,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction Spawn::Clone() const
|
ActionPtr Spawn::Clone() const
|
||||||
{
|
{
|
||||||
auto spawn = new (std::nothrow) Spawn();
|
auto spawn = new (std::nothrow) Spawn();
|
||||||
if (spawn)
|
if (spawn)
|
||||||
|
|
@ -313,7 +313,7 @@ namespace easy2d
|
||||||
return spawn;
|
return spawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction Spawn::Reverse() const
|
ActionPtr Spawn::Reverse() const
|
||||||
{
|
{
|
||||||
auto spawn = new (std::nothrow) Spawn();
|
auto spawn = new (std::nothrow) Spawn();
|
||||||
if (spawn && !actions_.empty())
|
if (spawn && !actions_.empty())
|
||||||
|
|
|
||||||
|
|
@ -29,17 +29,17 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Loop(
|
explicit Loop(
|
||||||
SpAction const& action, /* 执行循环的动作 */
|
ActionPtr const& action, /* 执行循环的动作 */
|
||||||
int times = -1 /* 循环次数 */
|
int times = -1 /* 循环次数 */
|
||||||
);
|
);
|
||||||
|
|
||||||
virtual ~Loop();
|
virtual ~Loop();
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override;
|
virtual ActionPtr Reverse() const override;
|
||||||
|
|
||||||
// 重置动作
|
// 重置动作
|
||||||
virtual void Reset() override;
|
virtual void Reset() override;
|
||||||
|
|
@ -54,7 +54,7 @@ namespace easy2d
|
||||||
virtual void Update(Node* target, Duration const& dt) override;
|
virtual void Update(Node* target, Duration const& dt) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SpAction action_;
|
ActionPtr action_;
|
||||||
int times_;
|
int times_;
|
||||||
int total_times_;
|
int total_times_;
|
||||||
};
|
};
|
||||||
|
|
@ -68,26 +68,26 @@ namespace easy2d
|
||||||
Sequence();
|
Sequence();
|
||||||
|
|
||||||
explicit Sequence(
|
explicit Sequence(
|
||||||
Array<SpAction> const& actions /* 动作列表 */
|
Array<ActionPtr> const& actions /* 动作列表 */
|
||||||
);
|
);
|
||||||
|
|
||||||
virtual ~Sequence();
|
virtual ~Sequence();
|
||||||
|
|
||||||
// 在结尾添加动作
|
// 在结尾添加动作
|
||||||
void Add(
|
void Add(
|
||||||
SpAction const& action
|
ActionPtr const& action
|
||||||
);
|
);
|
||||||
|
|
||||||
// 在结尾添加多个动作
|
// 在结尾添加多个动作
|
||||||
void Add(
|
void Add(
|
||||||
Array<SpAction> const& actions /* 动作列表 */
|
Array<ActionPtr> const& actions /* 动作列表 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override;
|
virtual ActionPtr Reverse() const override;
|
||||||
|
|
||||||
// 重置动作
|
// 重置动作
|
||||||
virtual void Reset() override;
|
virtual void Reset() override;
|
||||||
|
|
@ -101,7 +101,7 @@ namespace easy2d
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UINT action_index_;
|
UINT action_index_;
|
||||||
Array<SpAction> actions_;
|
Array<ActionPtr> actions_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -113,26 +113,26 @@ namespace easy2d
|
||||||
Spawn();
|
Spawn();
|
||||||
|
|
||||||
explicit Spawn(
|
explicit Spawn(
|
||||||
Array<SpAction> const& actions /* 动作列表 */
|
Array<ActionPtr> const& actions /* 动作列表 */
|
||||||
);
|
);
|
||||||
|
|
||||||
virtual ~Spawn();
|
virtual ~Spawn();
|
||||||
|
|
||||||
// 在结尾添加动作
|
// 在结尾添加动作
|
||||||
void Add(
|
void Add(
|
||||||
SpAction const& action
|
ActionPtr const& action
|
||||||
);
|
);
|
||||||
|
|
||||||
// 在结尾添加多个动作
|
// 在结尾添加多个动作
|
||||||
void Add(
|
void Add(
|
||||||
Array<SpAction> const& actions /* 动作列表 */
|
Array<ActionPtr> const& actions /* 动作列表 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const;
|
virtual ActionPtr Reverse() const;
|
||||||
|
|
||||||
// 重置动作
|
// 重置动作
|
||||||
virtual void Reset() override;
|
virtual void Reset() override;
|
||||||
|
|
@ -145,6 +145,6 @@ namespace easy2d
|
||||||
virtual void Update(Node* target, Duration const& dt) override;
|
virtual void Update(Node* target, Duration const& dt) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Array<SpAction> actions_;
|
Array<ActionPtr> actions_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace easy2d
|
||||||
if (actions_.IsEmpty())
|
if (actions_.IsEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SpAction next;
|
ActionPtr next;
|
||||||
for (auto action = actions_.First(); action; action = next)
|
for (auto action = actions_.First(); action; action = next)
|
||||||
{
|
{
|
||||||
next = action->NextItem();
|
next = action->NextItem();
|
||||||
|
|
@ -41,7 +41,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionManager::AddAction(SpAction const& action)
|
void ActionManager::AddAction(ActionPtr const& action)
|
||||||
{
|
{
|
||||||
E2D_ASSERT(action && "AddAction failed, NULL pointer exception");
|
E2D_ASSERT(action && "AddAction failed, NULL pointer exception");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,12 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
class ActionManager
|
class ActionManager
|
||||||
{
|
{
|
||||||
using Actions = intrusive::List<SpAction>;
|
using Actions = intrusive::List<ActionPtr>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 执行动作
|
// 执行动作
|
||||||
void AddAction(
|
void AddAction(
|
||||||
SpAction const& action
|
ActionPtr const& action
|
||||||
);
|
);
|
||||||
|
|
||||||
// 继续所有暂停动作
|
// 继续所有暂停动作
|
||||||
|
|
|
||||||
|
|
@ -235,12 +235,12 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction MoveBy::Clone() const
|
ActionPtr MoveBy::Clone() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) MoveBy(duration_, delta_pos_, ease_type_);
|
return new (std::nothrow) MoveBy(duration_, delta_pos_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction MoveBy::Reverse() const
|
ActionPtr MoveBy::Reverse() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) MoveBy(duration_, -delta_pos_, ease_type_);
|
return new (std::nothrow) MoveBy(duration_, -delta_pos_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
@ -251,7 +251,7 @@ namespace easy2d
|
||||||
end_pos_ = pos;
|
end_pos_ = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction MoveTo::Clone() const
|
ActionPtr MoveTo::Clone() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) MoveTo(duration_, end_pos_, ease_type_);
|
return new (std::nothrow) MoveTo(duration_, end_pos_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
@ -275,12 +275,12 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction JumpBy::Clone() const
|
ActionPtr JumpBy::Clone() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) JumpBy(duration_, delta_pos_, height_, jumps_, ease_type_);
|
return new (std::nothrow) JumpBy(duration_, delta_pos_, height_, jumps_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction JumpBy::Reverse() const
|
ActionPtr JumpBy::Reverse() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) JumpBy(duration_, -delta_pos_, height_, jumps_, ease_type_);
|
return new (std::nothrow) JumpBy(duration_, -delta_pos_, height_, jumps_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
@ -320,7 +320,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction JumpTo::Clone() const
|
ActionPtr JumpTo::Clone() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) JumpTo(duration_, end_pos_, height_, jumps_, ease_type_);
|
return new (std::nothrow) JumpTo(duration_, end_pos_, height_, jumps_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
@ -369,12 +369,12 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction ScaleBy::Clone() const
|
ActionPtr ScaleBy::Clone() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) ScaleBy(duration_, delta_x_, delta_y_, ease_type_);
|
return new (std::nothrow) ScaleBy(duration_, delta_x_, delta_y_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction ScaleBy::Reverse() const
|
ActionPtr ScaleBy::Reverse() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) ScaleBy(duration_, -delta_x_, -delta_y_, ease_type_);
|
return new (std::nothrow) ScaleBy(duration_, -delta_x_, -delta_y_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
@ -393,7 +393,7 @@ namespace easy2d
|
||||||
end_scale_y_ = scale_y;
|
end_scale_y_ = scale_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction ScaleTo::Clone() const
|
ActionPtr ScaleTo::Clone() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) ScaleTo(duration_, end_scale_x_, end_scale_y_, ease_type_);
|
return new (std::nothrow) ScaleTo(duration_, end_scale_x_, end_scale_y_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
@ -434,12 +434,12 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction OpacityBy::Clone() const
|
ActionPtr OpacityBy::Clone() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) OpacityBy(duration_, delta_val_, ease_type_);
|
return new (std::nothrow) OpacityBy(duration_, delta_val_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction OpacityBy::Reverse() const
|
ActionPtr OpacityBy::Reverse() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) OpacityBy(duration_, -delta_val_, ease_type_);
|
return new (std::nothrow) OpacityBy(duration_, -delta_val_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
@ -450,7 +450,7 @@ namespace easy2d
|
||||||
end_val_ = opacity;
|
end_val_ = opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction OpacityTo::Clone() const
|
ActionPtr OpacityTo::Clone() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) OpacityTo(duration_, end_val_, ease_type_);
|
return new (std::nothrow) OpacityTo(duration_, end_val_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
@ -500,12 +500,12 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction RotateBy::Clone() const
|
ActionPtr RotateBy::Clone() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) RotateBy(duration_, delta_val_, ease_type_);
|
return new (std::nothrow) RotateBy(duration_, delta_val_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction RotateBy::Reverse() const
|
ActionPtr RotateBy::Reverse() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) RotateBy(duration_, -delta_val_, ease_type_);
|
return new (std::nothrow) RotateBy(duration_, -delta_val_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
@ -516,7 +516,7 @@ namespace easy2d
|
||||||
end_val_ = rotation;
|
end_val_ = rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction RotateTo::Clone() const
|
ActionPtr RotateTo::Clone() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) RotateTo(duration_, end_val_, ease_type_);
|
return new (std::nothrow) RotateTo(duration_, end_val_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
@ -532,7 +532,7 @@ namespace easy2d
|
||||||
// PathAction
|
// PathAction
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
||||||
PathAction::PathAction(Duration const & duration, SpGeometry const& geo, bool rotating, float start, float end, EaseFunc func)
|
PathAction::PathAction(Duration const & duration, GeometryPtr const& geo, bool rotating, float start, float end, EaseFunc func)
|
||||||
: Tween(duration, func)
|
: Tween(duration, func)
|
||||||
, start_(start)
|
, start_(start)
|
||||||
, end_(end)
|
, end_(end)
|
||||||
|
|
@ -541,12 +541,12 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction PathAction::Clone() const
|
ActionPtr PathAction::Clone() const
|
||||||
{
|
{
|
||||||
return new PathAction(duration_, geo_, rotating_, start_, end_, ease_type_);
|
return new PathAction(duration_, geo_, rotating_, start_, end_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction PathAction::Reverse() const
|
ActionPtr PathAction::Reverse() const
|
||||||
{
|
{
|
||||||
return new PathAction(duration_, geo_, rotating_, end_, start_, ease_type_);
|
return new PathAction(duration_, geo_, rotating_, end_, start_, ease_type_);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,10 +128,10 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override;
|
virtual ActionPtr Reverse() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Init(Node* target) override;
|
virtual void Init(Node* target) override;
|
||||||
|
|
@ -157,12 +157,12 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override
|
virtual ActionPtr Reverse() const override
|
||||||
{
|
{
|
||||||
logs::Errorln("Reverse() not supported in MoveTo");
|
logs::Errorln(L"Reverse() not supported in MoveTo");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,10 +188,10 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override;
|
virtual ActionPtr Reverse() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Init(Node* target) override;
|
virtual void Init(Node* target) override;
|
||||||
|
|
@ -221,12 +221,12 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override
|
virtual ActionPtr Reverse() const override
|
||||||
{
|
{
|
||||||
logs::Errorln("Reverse() not supported in JumpTo");
|
logs::Errorln(L"Reverse() not supported in JumpTo");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -257,10 +257,10 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override;
|
virtual ActionPtr Reverse() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Init(Node* target) override;
|
virtual void Init(Node* target) override;
|
||||||
|
|
@ -294,12 +294,12 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override
|
virtual ActionPtr Reverse() const override
|
||||||
{
|
{
|
||||||
logs::Errorln("Reverse() not supported in ScaleTo");
|
logs::Errorln(L"Reverse() not supported in ScaleTo");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -324,10 +324,10 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override;
|
virtual ActionPtr Reverse() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Init(Node* target) override;
|
virtual void Init(Node* target) override;
|
||||||
|
|
@ -352,12 +352,12 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override
|
virtual ActionPtr Reverse() const override
|
||||||
{
|
{
|
||||||
logs::Errorln("Reverse() not supported in OpacityTo");
|
logs::Errorln(L"Reverse() not supported in OpacityTo");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -407,10 +407,10 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override;
|
virtual ActionPtr Reverse() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Init(Node* target) override;
|
virtual void Init(Node* target) override;
|
||||||
|
|
@ -435,12 +435,12 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override
|
virtual ActionPtr Reverse() const override
|
||||||
{
|
{
|
||||||
logs::Errorln("Reverse() not supported in RotateTo");
|
logs::Errorln(L"Reverse() not supported in RotateTo");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -459,7 +459,7 @@ namespace easy2d
|
||||||
public:
|
public:
|
||||||
explicit PathAction(
|
explicit PathAction(
|
||||||
Duration const& duration, /* 持续时长 */
|
Duration const& duration, /* 持续时长 */
|
||||||
SpGeometry const& geo, /* ¼¸ºÎͼÐÎ */
|
GeometryPtr const& geo, /* ¼¸ºÎͼÐÎ */
|
||||||
bool rotating = false, /* 沿路径切线方向旋转 */
|
bool rotating = false, /* 沿路径切线方向旋转 */
|
||||||
float start = 0.f, /* 起点 */
|
float start = 0.f, /* 起点 */
|
||||||
float end = 1.f, /* 终点 */
|
float end = 1.f, /* 终点 */
|
||||||
|
|
@ -467,10 +467,10 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override;
|
virtual ActionPtr Reverse() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Init(Node* target) override;
|
virtual void Init(Node* target) override;
|
||||||
|
|
@ -482,6 +482,6 @@ namespace easy2d
|
||||||
float start_;
|
float start_;
|
||||||
float end_;
|
float end_;
|
||||||
Point start_pos_;
|
Point start_pos_;
|
||||||
SpGeometry geo_;
|
GeometryPtr geo_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation::Animation(SpFrames const& animation)
|
Animation::Animation(FramesPtr const& animation)
|
||||||
: frame_index_(0)
|
: frame_index_(0)
|
||||||
, frames_(nullptr)
|
, frames_(nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -42,12 +42,12 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SpFrames Animation::GetAnimation() const
|
FramesPtr Animation::GetAnimation() const
|
||||||
{
|
{
|
||||||
return frames_;
|
return frames_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animation::SetAnimation(SpFrames const& animation)
|
void Animation::SetAnimation(FramesPtr const& animation)
|
||||||
{
|
{
|
||||||
if (animation && animation != frames_)
|
if (animation && animation != frames_)
|
||||||
{
|
{
|
||||||
|
|
@ -106,7 +106,7 @@ namespace easy2d
|
||||||
frame_index_ = 0;
|
frame_index_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction Animation::Clone() const
|
ActionPtr Animation::Clone() const
|
||||||
{
|
{
|
||||||
if (frames_)
|
if (frames_)
|
||||||
{
|
{
|
||||||
|
|
@ -115,7 +115,7 @@ namespace easy2d
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction Animation::Reverse() const
|
ActionPtr Animation::Reverse() const
|
||||||
{
|
{
|
||||||
if (frames_)
|
if (frames_)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,24 +31,24 @@ namespace easy2d
|
||||||
Animation();
|
Animation();
|
||||||
|
|
||||||
explicit Animation(
|
explicit Animation(
|
||||||
SpFrames const& animation
|
FramesPtr const& animation
|
||||||
);
|
);
|
||||||
|
|
||||||
virtual ~Animation();
|
virtual ~Animation();
|
||||||
|
|
||||||
// 获取动画
|
// 获取动画
|
||||||
SpFrames GetAnimation() const;
|
FramesPtr GetAnimation() const;
|
||||||
|
|
||||||
// 设置动画
|
// 设置动画
|
||||||
void SetAnimation(
|
void SetAnimation(
|
||||||
SpFrames const& animation
|
FramesPtr const& animation
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override;
|
virtual ActionPtr Reverse() const override;
|
||||||
|
|
||||||
// 重置动作
|
// 重置动作
|
||||||
virtual void Reset() override;
|
virtual void Reset() override;
|
||||||
|
|
@ -63,6 +63,6 @@ namespace easy2d
|
||||||
protected:
|
protected:
|
||||||
size_t frame_index_;
|
size_t frame_index_;
|
||||||
Duration delta_;
|
Duration delta_;
|
||||||
SpFrames frames_;
|
FramesPtr frames_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ namespace easy2d
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::DrawImage(SpImage const & image, float opacity)
|
void Canvas::DrawImage(ImagePtr const & image, float opacity)
|
||||||
{
|
{
|
||||||
if (image && image->GetBitmap())
|
if (image && image->GetBitmap())
|
||||||
{
|
{
|
||||||
|
|
@ -267,7 +267,7 @@ namespace easy2d
|
||||||
if (text.empty())
|
if (text.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CpTextFormat text_format;
|
D2DTextFormatPtr text_format;
|
||||||
ThrowIfFailed(
|
ThrowIfFailed(
|
||||||
Factory::Instance()->CreateTextFormat(
|
Factory::Instance()->CreateTextFormat(
|
||||||
text_format,
|
text_format,
|
||||||
|
|
@ -276,7 +276,7 @@ namespace easy2d
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
CpTextLayout text_layout;
|
D2DTextLayoutPtr text_layout;
|
||||||
Size layout_size;
|
Size layout_size;
|
||||||
ThrowIfFailed(
|
ThrowIfFailed(
|
||||||
Factory::Instance()->CreateTextLayout(
|
Factory::Instance()->CreateTextLayout(
|
||||||
|
|
@ -293,7 +293,7 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::DrawGeometry(SpGeometry const & geo)
|
void Canvas::DrawGeometry(GeometryPtr const & geo)
|
||||||
{
|
{
|
||||||
if (geo && geo->geo_)
|
if (geo && geo->geo_)
|
||||||
{
|
{
|
||||||
|
|
@ -371,7 +371,7 @@ namespace easy2d
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::FillGeometry(SpGeometry const & geo)
|
void Canvas::FillGeometry(GeometryPtr const & geo)
|
||||||
{
|
{
|
||||||
if (geo && geo->geo_)
|
if (geo && geo->geo_)
|
||||||
{
|
{
|
||||||
|
|
@ -493,14 +493,14 @@ namespace easy2d
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpImage Canvas::ExportToImage() const
|
ImagePtr Canvas::ExportToImage() const
|
||||||
{
|
{
|
||||||
auto image = new Image(GetBitmap());
|
auto image = new Image(GetBitmap());
|
||||||
image->Crop(Rect(Point{}, this->GetSize()));
|
image->Crop(Rect(Point{}, this->GetSize()));
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
CpBitmap const& easy2d::Canvas::GetBitmap() const
|
D2DBitmapPtr const& easy2d::Canvas::GetBitmap() const
|
||||||
{
|
{
|
||||||
if (cache_expired_)
|
if (cache_expired_)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ namespace easy2d
|
||||||
|
|
||||||
// 画图片
|
// 画图片
|
||||||
void DrawImage(
|
void DrawImage(
|
||||||
SpImage const& image,
|
ImagePtr const& image,
|
||||||
float opacity = 1.f
|
float opacity = 1.f
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ namespace easy2d
|
||||||
|
|
||||||
// 画几何图形边框
|
// 画几何图形边框
|
||||||
void DrawGeometry(
|
void DrawGeometry(
|
||||||
SpGeometry const& geo
|
GeometryPtr const& geo
|
||||||
);
|
);
|
||||||
|
|
||||||
// 填充圆形
|
// 填充圆形
|
||||||
|
|
@ -127,7 +127,7 @@ namespace easy2d
|
||||||
|
|
||||||
// 填充几何图形
|
// 填充几何图形
|
||||||
void FillGeometry(
|
void FillGeometry(
|
||||||
SpGeometry const& geo
|
GeometryPtr const& geo
|
||||||
);
|
);
|
||||||
|
|
||||||
// 开始绘制路径
|
// 开始绘制路径
|
||||||
|
|
@ -216,26 +216,26 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 导出为图片
|
// 导出为图片
|
||||||
SpImage ExportToImage() const;
|
ImagePtr ExportToImage() const;
|
||||||
|
|
||||||
virtual void OnRender() override;
|
virtual void OnRender() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CpBitmap const& GetBitmap() const;
|
D2DBitmapPtr const& GetBitmap() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mutable bool cache_expired_;
|
mutable bool cache_expired_;
|
||||||
mutable CpBitmap bitmap_cached_;
|
mutable D2DBitmapPtr bitmap_cached_;
|
||||||
float stroke_width_;
|
float stroke_width_;
|
||||||
Font text_font_;
|
Font text_font_;
|
||||||
TextStyle text_style_;
|
TextStyle text_style_;
|
||||||
CpPathGeometry current_geometry_;
|
D2DPathGeometryPtr current_geometry_;
|
||||||
CpGeometrySink current_sink_;
|
D2DGeometrySinkPtr current_sink_;
|
||||||
CpStrokeStyle outline_join_style_;
|
D2DStrokeStylePtr outline_join_style_;
|
||||||
CpSolidColorBrush fill_brush_;
|
D2DSolidColorBrushPtr fill_brush_;
|
||||||
CpSolidColorBrush stroke_brush_;
|
D2DSolidColorBrushPtr stroke_brush_;
|
||||||
CpSolidColorBrush text_brush_;
|
D2DSolidColorBrushPtr text_brush_;
|
||||||
CpTextRenderer text_renderer_;
|
D2DTextRendererPtr text_renderer_;
|
||||||
CpBitmapRenderTarget render_target_;
|
D2DBitmapRenderTargetPtr render_target_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -44,7 +44,7 @@ namespace easy2d
|
||||||
void OnUpdate(Duration const& dt) override;
|
void OnUpdate(Duration const& dt) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SpText debug_text_;
|
TextPtr debug_text_;
|
||||||
Array<TimePoint> frame_time_;
|
Array<TimePoint> frame_time_;
|
||||||
Array<String> texts_;
|
Array<String> texts_;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -51,12 +51,12 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction Delay::Clone() const
|
ActionPtr Delay::Clone() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) Delay(delay_);
|
return new (std::nothrow) Delay(delay_);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpAction Delay::Reverse() const
|
ActionPtr Delay::Reverse() const
|
||||||
{
|
{
|
||||||
return new (std::nothrow) Delay(delay_);
|
return new (std::nothrow) Delay(delay_);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,10 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取该动作的拷贝对象
|
// 获取该动作的拷贝对象
|
||||||
virtual SpAction Clone() const override;
|
virtual ActionPtr Clone() const override;
|
||||||
|
|
||||||
// 获取该动作的倒转
|
// 获取该动作的倒转
|
||||||
virtual SpAction Reverse() const override;
|
virtual ActionPtr Reverse() const override;
|
||||||
|
|
||||||
// 重置动作
|
// 重置动作
|
||||||
virtual void Reset() override;
|
virtual void Reset() override;
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace easy2d
|
||||||
if (listeners_.IsEmpty())
|
if (listeners_.IsEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SpEventListener next;
|
EventListenerPtr next;
|
||||||
for (auto listener = listeners_.First(); listener; listener = next)
|
for (auto listener = listeners_.First(); listener; listener = next)
|
||||||
{
|
{
|
||||||
next = listener->NextItem();
|
next = listener->NextItem();
|
||||||
|
|
@ -40,7 +40,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventDispatcher::AddListener(SpEventListener const & listener)
|
void EventDispatcher::AddListener(EventListenerPtr const & listener)
|
||||||
{
|
{
|
||||||
E2D_ASSERT(listener && "AddListener failed, NULL pointer exception");
|
E2D_ASSERT(listener && "AddListener failed, NULL pointer exception");
|
||||||
|
|
||||||
|
|
@ -52,7 +52,7 @@ namespace easy2d
|
||||||
|
|
||||||
void EventDispatcher::AddListener(EventType type, EventCallback callback, String const& name)
|
void EventDispatcher::AddListener(EventType type, EventCallback callback, String const& name)
|
||||||
{
|
{
|
||||||
SpEventListener listener = new EventListener(type, callback, name);
|
EventListenerPtr listener = new EventListener(type, callback, name);
|
||||||
if (listener)
|
if (listener)
|
||||||
{
|
{
|
||||||
listeners_.PushBack(listener);
|
listeners_.PushBack(listener);
|
||||||
|
|
@ -83,7 +83,7 @@ namespace easy2d
|
||||||
|
|
||||||
void EventDispatcher::RemoveListeners(String const & listener_name)
|
void EventDispatcher::RemoveListeners(String const & listener_name)
|
||||||
{
|
{
|
||||||
SpEventListener next;
|
EventListenerPtr next;
|
||||||
for (auto listener = listeners_.First(); listener; listener = next)
|
for (auto listener = listeners_.First(); listener; listener = next)
|
||||||
{
|
{
|
||||||
next = listener->NextItem();
|
next = listener->NextItem();
|
||||||
|
|
@ -119,7 +119,7 @@ namespace easy2d
|
||||||
|
|
||||||
void EventDispatcher::RemoveListeners(EventType type)
|
void EventDispatcher::RemoveListeners(EventType type)
|
||||||
{
|
{
|
||||||
SpEventListener next;
|
EventListenerPtr next;
|
||||||
for (auto listener = listeners_.First(); listener; listener = next)
|
for (auto listener = listeners_.First(); listener; listener = next)
|
||||||
{
|
{
|
||||||
next = listener->NextItem();
|
next = listener->NextItem();
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,12 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
class EventDispatcher
|
class EventDispatcher
|
||||||
{
|
{
|
||||||
using Listeners = intrusive::List<SpEventListener>;
|
using Listeners = intrusive::List<EventListenerPtr>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 添加监听器
|
// 添加监听器
|
||||||
void AddListener(
|
void AddListener(
|
||||||
SpEventListener const& listener
|
EventListenerPtr const& listener
|
||||||
);
|
);
|
||||||
|
|
||||||
// 添加监听器
|
// 添加监听器
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,10 @@ namespace easy2d
|
||||||
|
|
||||||
class EventListener
|
class EventListener
|
||||||
: public Object
|
: public Object
|
||||||
, protected intrusive::ListItem<SpEventListener>
|
, protected intrusive::ListItem<EventListenerPtr>
|
||||||
{
|
{
|
||||||
friend class EventDispatcher;
|
friend class EventDispatcher;
|
||||||
friend class intrusive::List<SpEventListener>;
|
friend class intrusive::List<EventListenerPtr>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EventListener(
|
EventListener(
|
||||||
|
|
|
||||||
|
|
@ -31,16 +31,16 @@ namespace easy2d
|
||||||
|
|
||||||
FactoryImpl::~FactoryImpl()
|
FactoryImpl::~FactoryImpl()
|
||||||
{
|
{
|
||||||
E2D_LOG("Destroying device independent resources");
|
E2D_LOG(L"Destroying device independent resources");
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT FactoryImpl::Init(bool debug)
|
HRESULT FactoryImpl::Init(bool debug)
|
||||||
{
|
{
|
||||||
E2D_LOG("Creating device independent resources");
|
E2D_LOG(L"Creating device independent resources");
|
||||||
|
|
||||||
D2D1_FACTORY_OPTIONS fact_options;
|
D2D1_FACTORY_OPTIONS fact_options;
|
||||||
fact_options.debugLevel = debug ? D2D1_DEBUG_LEVEL_INFORMATION : D2D1_DEBUG_LEVEL_NONE;
|
fact_options.debugLevel = debug ? D2D1_DEBUG_LEVEL_INFORMATION : D2D1_DEBUG_LEVEL_NONE;
|
||||||
HRESULT hr = modules::DirectX().D2D1CreateFactory(
|
HRESULT hr = modules::DirectX::Get().D2D1CreateFactory(
|
||||||
D2D1_FACTORY_TYPE_SINGLE_THREADED,
|
D2D1_FACTORY_TYPE_SINGLE_THREADED,
|
||||||
__uuidof(ID2D1Factory),
|
__uuidof(ID2D1Factory),
|
||||||
&fact_options,
|
&fact_options,
|
||||||
|
|
@ -60,7 +60,7 @@ namespace easy2d
|
||||||
|
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
modules::DirectX().DWriteCreateFactory(
|
modules::DirectX::Get().DWriteCreateFactory(
|
||||||
DWRITE_FACTORY_TYPE_SHARED,
|
DWRITE_FACTORY_TYPE_SHARED,
|
||||||
__uuidof(IDWriteFactory),
|
__uuidof(IDWriteFactory),
|
||||||
reinterpret_cast<IUnknown**>(&write_factory_)
|
reinterpret_cast<IUnknown**>(&write_factory_)
|
||||||
|
|
@ -111,12 +111,12 @@ namespace easy2d
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT FactoryImpl::CreateHwndRenderTarget(CpHwndRenderTarget & hwnd_render_target, D2D1_RENDER_TARGET_PROPERTIES const & properties, D2D1_HWND_RENDER_TARGET_PROPERTIES const & hwnd_rt_properties) const
|
HRESULT FactoryImpl::CreateHwndRenderTarget(D2DHwndRenderTargetPtr & hwnd_render_target, D2D1_RENDER_TARGET_PROPERTIES const & properties, D2D1_HWND_RENDER_TARGET_PROPERTIES const & hwnd_rt_properties) const
|
||||||
{
|
{
|
||||||
if (!factory_)
|
if (!factory_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
CpHwndRenderTarget hwnd_render_target_tmp;
|
D2DHwndRenderTargetPtr hwnd_render_target_tmp;
|
||||||
HRESULT hr = factory_->CreateHwndRenderTarget(
|
HRESULT hr = factory_->CreateHwndRenderTarget(
|
||||||
properties,
|
properties,
|
||||||
hwnd_rt_properties,
|
hwnd_rt_properties,
|
||||||
|
|
@ -129,15 +129,15 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT FactoryImpl::CreateTextRenderer(
|
HRESULT FactoryImpl::CreateTextRenderer(
|
||||||
CpTextRenderer& text_renderer,
|
D2DTextRendererPtr& text_renderer,
|
||||||
CpRenderTarget const& render_target,
|
D2DRenderTargetPtr const& render_target,
|
||||||
CpSolidColorBrush const& brush
|
D2DSolidColorBrushPtr const& brush
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!factory_)
|
if (!factory_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
CpTextRenderer text_renderer_tmp;
|
D2DTextRendererPtr text_renderer_tmp;
|
||||||
HRESULT hr = ITextRenderer::Create(
|
HRESULT hr = ITextRenderer::Create(
|
||||||
&text_renderer_tmp,
|
&text_renderer_tmp,
|
||||||
factory_.Get(),
|
factory_.Get(),
|
||||||
|
|
@ -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(D2DBitmapPtr & bitmap, D2DRenderTargetPtr const & rt, String const & file_path)
|
||||||
{
|
{
|
||||||
if (imaging_factory_ == nullptr)
|
if (imaging_factory_ == nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -159,11 +159,11 @@ namespace easy2d
|
||||||
|
|
||||||
using namespace intrusive;
|
using namespace intrusive;
|
||||||
|
|
||||||
SmartPointer<IWICBitmapDecoder> decoder;
|
SmartPtr<IWICBitmapDecoder> decoder;
|
||||||
SmartPointer<IWICBitmapFrameDecode> source;
|
SmartPtr<IWICBitmapFrameDecode> source;
|
||||||
SmartPointer<IWICStream> stream;
|
SmartPtr<IWICStream> stream;
|
||||||
SmartPointer<IWICFormatConverter> converter;
|
SmartPtr<IWICFormatConverter> converter;
|
||||||
SmartPointer<ID2D1Bitmap> bitmap_tmp;
|
SmartPtr<ID2D1Bitmap> bitmap_tmp;
|
||||||
|
|
||||||
HRESULT hr = imaging_factory_->CreateDecoderFromFilename(
|
HRESULT hr = imaging_factory_->CreateDecoderFromFilename(
|
||||||
file_path.c_str(),
|
file_path.c_str(),
|
||||||
|
|
@ -211,7 +211,7 @@ namespace easy2d
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT FactoryImpl::CreateBitmapFromResource(CpBitmap & bitmap, CpRenderTarget const & rt, Resource const & res)
|
HRESULT FactoryImpl::CreateBitmapFromResource(D2DBitmapPtr & bitmap, D2DRenderTargetPtr const & rt, Resource const & res)
|
||||||
{
|
{
|
||||||
if (imaging_factory_ == nullptr)
|
if (imaging_factory_ == nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -220,11 +220,11 @@ namespace easy2d
|
||||||
|
|
||||||
using namespace intrusive;
|
using namespace intrusive;
|
||||||
|
|
||||||
SmartPointer<IWICBitmapDecoder> decoder;
|
SmartPtr<IWICBitmapDecoder> decoder;
|
||||||
SmartPointer<IWICBitmapFrameDecode> source;
|
SmartPtr<IWICBitmapFrameDecode> source;
|
||||||
SmartPointer<IWICStream> stream;
|
SmartPtr<IWICStream> stream;
|
||||||
SmartPointer<IWICFormatConverter> converter;
|
SmartPtr<IWICFormatConverter> converter;
|
||||||
SmartPointer<ID2D1Bitmap> bitmap_tmp;
|
SmartPtr<ID2D1Bitmap> bitmap_tmp;
|
||||||
|
|
||||||
// ¼ÓÔØ×ÊÔ´
|
// ¼ÓÔØ×ÊÔ´
|
||||||
LPVOID buffer;
|
LPVOID buffer;
|
||||||
|
|
@ -294,12 +294,12 @@ namespace easy2d
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT FactoryImpl::CreateRectangleGeometry(CpRectangleGeometry & geo, Rect const& rect) const
|
HRESULT FactoryImpl::CreateRectangleGeometry(D2DRectangleGeometryPtr & geo, Rect const& rect) const
|
||||||
{
|
{
|
||||||
if (!factory_)
|
if (!factory_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
CpRectangleGeometry rectangle;
|
D2DRectangleGeometryPtr rectangle;
|
||||||
HRESULT hr = factory_->CreateRectangleGeometry(
|
HRESULT hr = factory_->CreateRectangleGeometry(
|
||||||
rect,
|
rect,
|
||||||
&rectangle
|
&rectangle
|
||||||
|
|
@ -310,12 +310,12 @@ namespace easy2d
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT FactoryImpl::CreateRoundedRectangleGeometry(CpRoundedRectangleGeometry & geo, Rect const & rect, float radius_x, float radius_y) const
|
HRESULT FactoryImpl::CreateRoundedRectangleGeometry(D2DRoundedRectangleGeometryPtr & geo, Rect const & rect, float radius_x, float radius_y) const
|
||||||
{
|
{
|
||||||
if (!factory_)
|
if (!factory_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
CpRoundedRectangleGeometry rounded_rect;
|
D2DRoundedRectangleGeometryPtr rounded_rect;
|
||||||
HRESULT hr = factory_->CreateRoundedRectangleGeometry(
|
HRESULT hr = factory_->CreateRoundedRectangleGeometry(
|
||||||
D2D1::RoundedRect(
|
D2D1::RoundedRect(
|
||||||
rect,
|
rect,
|
||||||
|
|
@ -330,12 +330,12 @@ namespace easy2d
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT FactoryImpl::CreateEllipseGeometry(CpEllipseGeometry & geo, Point const & center, float radius_x, float radius_y) const
|
HRESULT FactoryImpl::CreateEllipseGeometry(D2DEllipseGeometryPtr & geo, Point const & center, float radius_x, float radius_y) const
|
||||||
{
|
{
|
||||||
if (!factory_)
|
if (!factory_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
CpEllipseGeometry ellipse;
|
D2DEllipseGeometryPtr ellipse;
|
||||||
HRESULT hr = factory_->CreateEllipseGeometry(
|
HRESULT hr = factory_->CreateEllipseGeometry(
|
||||||
D2D1::Ellipse(
|
D2D1::Ellipse(
|
||||||
center,
|
center,
|
||||||
|
|
@ -351,15 +351,15 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT FactoryImpl::CreateTransformedGeometry(
|
HRESULT FactoryImpl::CreateTransformedGeometry(
|
||||||
CpTransformedGeometry& transformed,
|
D2DTransformedGeometryPtr& transformed,
|
||||||
Matrix const& matrix,
|
Matrix const& matrix,
|
||||||
CpGeometry const& geo
|
D2DGeometryPtr const& geo
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if (!factory_)
|
if (!factory_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
CpTransformedGeometry transformed_tmp;
|
D2DTransformedGeometryPtr transformed_tmp;
|
||||||
HRESULT hr = factory_->CreateTransformedGeometry(
|
HRESULT hr = factory_->CreateTransformedGeometry(
|
||||||
geo.Get(),
|
geo.Get(),
|
||||||
matrix,
|
matrix,
|
||||||
|
|
@ -373,7 +373,7 @@ namespace easy2d
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT FactoryImpl::CreatePathGeometry(CpPathGeometry & geometry) const
|
HRESULT FactoryImpl::CreatePathGeometry(D2DPathGeometryPtr & geometry) const
|
||||||
{
|
{
|
||||||
if (!factory_)
|
if (!factory_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
@ -381,12 +381,12 @@ namespace easy2d
|
||||||
return factory_->CreatePathGeometry(&geometry);
|
return factory_->CreatePathGeometry(&geometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT FactoryImpl::CreateTextFormat(CpTextFormat & text_format, Font const & font, TextStyle const & text_style) const
|
HRESULT FactoryImpl::CreateTextFormat(D2DTextFormatPtr & text_format, Font const & font, TextStyle const & text_style) const
|
||||||
{
|
{
|
||||||
if (!write_factory_)
|
if (!write_factory_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
CpTextFormat text_format_tmp;
|
D2DTextFormatPtr text_format_tmp;
|
||||||
HRESULT hr = write_factory_->CreateTextFormat(
|
HRESULT hr = write_factory_->CreateTextFormat(
|
||||||
font.family.c_str(),
|
font.family.c_str(),
|
||||||
nullptr,
|
nullptr,
|
||||||
|
|
@ -419,7 +419,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(D2DTextLayoutPtr & text_layout, Size& layout_size, String const & text, D2DTextFormatPtr const& text_format, TextStyle const & text_style) const
|
||||||
{
|
{
|
||||||
if (!write_factory_)
|
if (!write_factory_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
@ -427,7 +427,7 @@ namespace easy2d
|
||||||
text_layout = nullptr;
|
text_layout = nullptr;
|
||||||
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
CpTextLayout text_layout_tmp;
|
D2DTextLayoutPtr text_layout_tmp;
|
||||||
UINT32 length = static_cast<UINT32>(text.length());
|
UINT32 length = static_cast<UINT32>(text.length());
|
||||||
|
|
||||||
if (text_style.wrap)
|
if (text_style.wrap)
|
||||||
|
|
@ -497,7 +497,7 @@ namespace easy2d
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CpStrokeStyle const& FactoryImpl::GetStrokeStyle(StrokeStyle stroke) const
|
D2DStrokeStylePtr const& FactoryImpl::GetStrokeStyle(StrokeStyle stroke) const
|
||||||
{
|
{
|
||||||
switch (stroke)
|
switch (stroke)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -38,73 +38,73 @@ namespace easy2d
|
||||||
HRESULT Init(bool debug);
|
HRESULT Init(bool debug);
|
||||||
|
|
||||||
HRESULT CreateHwndRenderTarget(
|
HRESULT CreateHwndRenderTarget(
|
||||||
CpHwndRenderTarget& hwnd_render_target,
|
D2DHwndRenderTargetPtr& hwnd_render_target,
|
||||||
D2D1_RENDER_TARGET_PROPERTIES const& properties,
|
D2D1_RENDER_TARGET_PROPERTIES const& properties,
|
||||||
D2D1_HWND_RENDER_TARGET_PROPERTIES const& hwnd_rt_properties
|
D2D1_HWND_RENDER_TARGET_PROPERTIES const& hwnd_rt_properties
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
HRESULT CreateTextRenderer(
|
HRESULT CreateTextRenderer(
|
||||||
CpTextRenderer& text_renderer,
|
D2DTextRendererPtr& text_renderer,
|
||||||
CpRenderTarget const& render_target,
|
D2DRenderTargetPtr const& render_target,
|
||||||
CpSolidColorBrush const& brush
|
D2DSolidColorBrushPtr const& brush
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT CreateBitmapFromFile(
|
HRESULT CreateBitmapFromFile(
|
||||||
CpBitmap& bitmap,
|
D2DBitmapPtr& bitmap,
|
||||||
CpRenderTarget const& rt,
|
D2DRenderTargetPtr const& rt,
|
||||||
String const& file_path
|
String const& file_path
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT CreateBitmapFromResource(
|
HRESULT CreateBitmapFromResource(
|
||||||
CpBitmap& bitmap,
|
D2DBitmapPtr& bitmap,
|
||||||
CpRenderTarget const& rt,
|
D2DRenderTargetPtr const& rt,
|
||||||
Resource const& res
|
Resource const& res
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT CreateRectangleGeometry(
|
HRESULT CreateRectangleGeometry(
|
||||||
CpRectangleGeometry& geo,
|
D2DRectangleGeometryPtr& geo,
|
||||||
Rect const& rect
|
Rect const& rect
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
HRESULT CreateRoundedRectangleGeometry(
|
HRESULT CreateRoundedRectangleGeometry(
|
||||||
CpRoundedRectangleGeometry& geo,
|
D2DRoundedRectangleGeometryPtr& geo,
|
||||||
Rect const& rect,
|
Rect const& rect,
|
||||||
float radius_x,
|
float radius_x,
|
||||||
float radius_y
|
float radius_y
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
HRESULT CreateEllipseGeometry(
|
HRESULT CreateEllipseGeometry(
|
||||||
CpEllipseGeometry& geo,
|
D2DEllipseGeometryPtr& geo,
|
||||||
Point const& center,
|
Point const& center,
|
||||||
float radius_x,
|
float radius_x,
|
||||||
float radius_y
|
float radius_y
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
HRESULT CreateTransformedGeometry(
|
HRESULT CreateTransformedGeometry(
|
||||||
CpTransformedGeometry& transformed,
|
D2DTransformedGeometryPtr& transformed,
|
||||||
Matrix const& matrix,
|
Matrix const& matrix,
|
||||||
CpGeometry const& geo
|
D2DGeometryPtr const& geo
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
HRESULT CreatePathGeometry(
|
HRESULT CreatePathGeometry(
|
||||||
CpPathGeometry& geometry
|
D2DPathGeometryPtr& geometry
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
HRESULT CreateTextFormat(
|
HRESULT CreateTextFormat(
|
||||||
CpTextFormat& text_format,
|
D2DTextFormatPtr& text_format,
|
||||||
Font const& font,
|
Font const& font,
|
||||||
TextStyle const& text_style
|
TextStyle const& text_style
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
HRESULT CreateTextLayout(
|
HRESULT CreateTextLayout(
|
||||||
CpTextLayout& text_layout,
|
D2DTextLayoutPtr& text_layout,
|
||||||
Size& layout_size,
|
Size& layout_size,
|
||||||
String const& text,
|
String const& text,
|
||||||
CpTextFormat const& text_format,
|
D2DTextFormatPtr const& text_format,
|
||||||
TextStyle const& text_style
|
TextStyle const& text_style
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
CpStrokeStyle const& GetStrokeStyle(
|
D2DStrokeStylePtr const& GetStrokeStyle(
|
||||||
StrokeStyle stroke
|
StrokeStyle stroke
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
|
@ -114,12 +114,12 @@ namespace easy2d
|
||||||
~FactoryImpl();
|
~FactoryImpl();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CpFactory factory_;
|
D2DFactoryPtr factory_;
|
||||||
CpImagingFactory imaging_factory_;
|
D2DImagingFactoryPtr imaging_factory_;
|
||||||
CpWriteFactory write_factory_;
|
D2DWriteFactoryPtr write_factory_;
|
||||||
CpStrokeStyle miter_stroke_style_;
|
D2DStrokeStylePtr miter_stroke_style_;
|
||||||
CpStrokeStyle bevel_stroke_style_;
|
D2DStrokeStylePtr bevel_stroke_style_;
|
||||||
CpStrokeStyle round_stroke_style_;
|
D2DStrokeStylePtr round_stroke_style_;
|
||||||
};
|
};
|
||||||
|
|
||||||
E2D_DECLARE_SINGLETON_TYPE(FactoryImpl, Factory);
|
E2D_DECLARE_SINGLETON_TYPE(FactoryImpl, Factory);
|
||||||
|
|
|
||||||
|
|
@ -25,22 +25,17 @@
|
||||||
namespace easy2d
|
namespace easy2d
|
||||||
{
|
{
|
||||||
Frames::Frames()
|
Frames::Frames()
|
||||||
: interval_(1)
|
: interval_(200)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Frames::Frames(Array<SpImage> const& frames)
|
Frames::Frames(Array<ImagePtr> const& frames)
|
||||||
: interval_(1)
|
: interval_(200)
|
||||||
{
|
{
|
||||||
this->Add(frames);
|
this->Add(frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
Frames::Frames(Duration const& interval)
|
Frames::Frames(Duration const& interval, Array<ImagePtr> const& frames)
|
||||||
: interval_(interval)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Frames::Frames(Duration const& interval, Array<SpImage> const& frames)
|
|
||||||
: interval_(interval)
|
: interval_(interval)
|
||||||
{
|
{
|
||||||
this->Add(frames);
|
this->Add(frames);
|
||||||
|
|
@ -55,7 +50,7 @@ namespace easy2d
|
||||||
interval_ = interval;
|
interval_ = interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Frames::Add(SpImage const& frame)
|
void Frames::Add(ImagePtr const& frame)
|
||||||
{
|
{
|
||||||
E2D_ASSERT(frame && "Frames::Add failed, NULL pointer exception");
|
E2D_ASSERT(frame && "Frames::Add failed, NULL pointer exception");
|
||||||
|
|
||||||
|
|
@ -65,7 +60,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Frames::Add(Array<SpImage> const& frames)
|
void Frames::Add(Array<ImagePtr> const& frames)
|
||||||
{
|
{
|
||||||
for (const auto &image : frames)
|
for (const auto &image : frames)
|
||||||
{
|
{
|
||||||
|
|
@ -78,16 +73,17 @@ namespace easy2d
|
||||||
return interval_;
|
return interval_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array<SpImage> const& Frames::GetFrames() const
|
Array<ImagePtr> const& Frames::GetFrames() const
|
||||||
{
|
{
|
||||||
return frames_;
|
return frames_;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpFrames Frames::Clone() const
|
FramesPtr Frames::Clone() const
|
||||||
{
|
{
|
||||||
auto animation = new (std::nothrow) Frames(interval_);
|
auto animation = new (std::nothrow) Frames;
|
||||||
if (animation)
|
if (animation)
|
||||||
{
|
{
|
||||||
|
animation->SetInterval(interval_);
|
||||||
for (const auto& frame : frames_)
|
for (const auto& frame : frames_)
|
||||||
{
|
{
|
||||||
animation->Add(frame);
|
animation->Add(frame);
|
||||||
|
|
@ -96,11 +92,12 @@ namespace easy2d
|
||||||
return animation;
|
return animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpFrames Frames::Reverse() const
|
FramesPtr Frames::Reverse() const
|
||||||
{
|
{
|
||||||
auto animation = new (std::nothrow) Frames(interval_);
|
auto animation = new (std::nothrow) Frames;
|
||||||
if (!frames_.empty())
|
if (!frames_.empty())
|
||||||
{
|
{
|
||||||
|
animation->SetInterval(interval_);
|
||||||
for (auto iter = frames_.crbegin(), crend = frames_.crend(); iter != crend; ++iter)
|
for (auto iter = frames_.crbegin(), crend = frames_.crend(); iter != crend; ++iter)
|
||||||
{
|
{
|
||||||
if (*iter)
|
if (*iter)
|
||||||
|
|
|
||||||
|
|
@ -32,35 +32,31 @@ namespace easy2d
|
||||||
Frames();
|
Frames();
|
||||||
|
|
||||||
explicit Frames(
|
explicit Frames(
|
||||||
Array<SpImage> const& frames /* 关键帧数组 */
|
Array<ImagePtr> const& frames /* 关键帧数组 */
|
||||||
);
|
|
||||||
|
|
||||||
explicit Frames(
|
|
||||||
Duration const& interval /* 帧间隔 */
|
|
||||||
);
|
);
|
||||||
|
|
||||||
explicit Frames(
|
explicit Frames(
|
||||||
Duration const& interval, /* 帧间隔 */
|
Duration const& interval, /* 帧间隔 */
|
||||||
Array<SpImage> const& frames /* 关键帧数组 */
|
Array<ImagePtr> const& frames /* 关键帧数组 */
|
||||||
);
|
);
|
||||||
|
|
||||||
virtual ~Frames();
|
virtual ~Frames();
|
||||||
|
|
||||||
// 添加关键帧
|
// 添加关键帧
|
||||||
void Add(
|
void Add(
|
||||||
SpImage const& frame
|
ImagePtr const& frame
|
||||||
);
|
);
|
||||||
|
|
||||||
// 添加多个关键帧
|
// 添加多个关键帧
|
||||||
void Add(
|
void Add(
|
||||||
Array<SpImage> const& frames
|
Array<ImagePtr> const& frames
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取帧间隔
|
// 获取帧间隔
|
||||||
Duration const& GetInterval() const;
|
Duration const& GetInterval() const;
|
||||||
|
|
||||||
// 获取关键帧
|
// 获取关键帧
|
||||||
Array<SpImage> const& GetFrames() const;
|
Array<ImagePtr> const& GetFrames() const;
|
||||||
|
|
||||||
// 设置每一帧的时间间隔
|
// 设置每一帧的时间间隔
|
||||||
void SetInterval(
|
void SetInterval(
|
||||||
|
|
@ -68,13 +64,13 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取帧动画的拷贝对象
|
// 获取帧动画的拷贝对象
|
||||||
SpFrames Clone() const;
|
FramesPtr Clone() const;
|
||||||
|
|
||||||
// 获取帧动画的倒转
|
// 获取帧动画的倒转
|
||||||
SpFrames Reverse() const;
|
FramesPtr Reverse() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Duration interval_;
|
Duration interval_;
|
||||||
Array<SpImage> frames_;
|
Array<ImagePtr> frames_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ namespace easy2d
|
||||||
Window::Instance()->Destroy();
|
Window::Instance()->Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::EnterScene(SpScene const & scene)
|
void Game::EnterScene(ScenePtr const & scene)
|
||||||
{
|
{
|
||||||
E2D_ASSERT(scene && "Game::EnterScene failed, NULL pointer exception");
|
E2D_ASSERT(scene && "Game::EnterScene failed, NULL pointer exception");
|
||||||
|
|
||||||
|
|
@ -163,7 +163,7 @@ namespace easy2d
|
||||||
next_scene_ = scene;
|
next_scene_ = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::EnterScene(SpScene const& scene, SpTransition const& transition)
|
void Game::EnterScene(ScenePtr const& scene, TransitionPtr const& transition)
|
||||||
{
|
{
|
||||||
EnterScene(scene);
|
EnterScene(scene);
|
||||||
|
|
||||||
|
|
@ -178,7 +178,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SpScene const& Game::GetCurrentScene()
|
ScenePtr const& Game::GetCurrentScene()
|
||||||
{
|
{
|
||||||
return curr_scene_;
|
return curr_scene_;
|
||||||
}
|
}
|
||||||
|
|
@ -337,7 +337,7 @@ namespace easy2d
|
||||||
|
|
||||||
case WM_DISPLAYCHANGE:
|
case WM_DISPLAYCHANGE:
|
||||||
{
|
{
|
||||||
E2D_LOG("The display resolution has changed");
|
E2D_LOG(L"The display resolution has changed");
|
||||||
|
|
||||||
::InvalidateRect(hwnd, nullptr, FALSE);
|
::InvalidateRect(hwnd, nullptr, FALSE);
|
||||||
}
|
}
|
||||||
|
|
@ -345,7 +345,7 @@ namespace easy2d
|
||||||
|
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
{
|
{
|
||||||
E2D_LOG("Received a message to close the window");
|
E2D_LOG(L"Received a message to close the window");
|
||||||
|
|
||||||
SysEvent event(SysEvent::WindowClose);
|
SysEvent event(SysEvent::WindowClose);
|
||||||
game->Dispatch(&event);
|
game->Dispatch(&event);
|
||||||
|
|
@ -360,7 +360,7 @@ namespace easy2d
|
||||||
|
|
||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
{
|
{
|
||||||
E2D_LOG("Window was destroyed");
|
E2D_LOG(L"Window was destroyed");
|
||||||
|
|
||||||
game->OnExit();
|
game->OnExit();
|
||||||
::PostQuitMessage(0);
|
::PostQuitMessage(0);
|
||||||
|
|
@ -374,14 +374,14 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
game->active_ = false;
|
game->active_ = false;
|
||||||
|
|
||||||
E2D_LOG("Window minimized");
|
E2D_LOG(L"Window minimized");
|
||||||
}
|
}
|
||||||
else if (SIZE_RESTORED == wparam)
|
else if (SIZE_RESTORED == wparam)
|
||||||
{
|
{
|
||||||
game->active_ = true;
|
game->active_ = true;
|
||||||
::InvalidateRect(hwnd, nullptr, FALSE);
|
::InvalidateRect(hwnd, nullptr, FALSE);
|
||||||
|
|
||||||
E2D_LOG("Window restored");
|
E2D_LOG(L"Window restored");
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT width = LOWORD(lparam);
|
UINT width = LOWORD(lparam);
|
||||||
|
|
@ -399,14 +399,14 @@ namespace easy2d
|
||||||
bool active = (LOWORD(wparam) != WA_INACTIVE);
|
bool active = (LOWORD(wparam) != WA_INACTIVE);
|
||||||
if (active)
|
if (active)
|
||||||
{
|
{
|
||||||
E2D_LOG("Window activated");
|
E2D_LOG(L"Window activated");
|
||||||
|
|
||||||
SysEvent event(SysEvent::WindowActivate);
|
SysEvent event(SysEvent::WindowActivate);
|
||||||
game->Dispatch(&event);
|
game->Dispatch(&event);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
E2D_LOG("Window deactivated");
|
E2D_LOG(L"Window deactivated");
|
||||||
|
|
||||||
SysEvent event(SysEvent::WindowDeavtivate);
|
SysEvent event(SysEvent::WindowDeavtivate);
|
||||||
game->Dispatch(&event);
|
game->Dispatch(&event);
|
||||||
|
|
@ -416,13 +416,13 @@ namespace easy2d
|
||||||
|
|
||||||
case WM_SETTEXT:
|
case WM_SETTEXT:
|
||||||
{
|
{
|
||||||
E2D_LOG("Window title changed");
|
E2D_LOG(L"Window title changed");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_SETICON:
|
case WM_SETICON:
|
||||||
{
|
{
|
||||||
E2D_LOG("Window icon changed");
|
E2D_LOG(L"Window icon changed");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,17 +80,17 @@ namespace easy2d
|
||||||
|
|
||||||
// Çл»³¡¾°
|
// Çл»³¡¾°
|
||||||
void EnterScene(
|
void EnterScene(
|
||||||
SpScene const& scene /* 场景 */
|
ScenePtr const& scene /* 场景 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// Çл»³¡¾°
|
// Çл»³¡¾°
|
||||||
void EnterScene(
|
void EnterScene(
|
||||||
SpScene const& scene, /* 场景 */
|
ScenePtr const& scene, /* 场景 */
|
||||||
SpTransition const& transition /* 场景动画 */
|
TransitionPtr const& transition /* 场景动画 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// »ñÈ¡µ±Ç°³¡¾°
|
// »ñÈ¡µ±Ç°³¡¾°
|
||||||
SpScene const& GetCurrentScene();
|
ScenePtr const& GetCurrentScene();
|
||||||
|
|
||||||
// ÉèÖñäËÙ
|
// ÉèÖñäËÙ
|
||||||
void SetTimeScale(float scale);
|
void SetTimeScale(float scale);
|
||||||
|
|
@ -110,8 +110,8 @@ namespace easy2d
|
||||||
bool debug_;
|
bool debug_;
|
||||||
bool active_;
|
bool active_;
|
||||||
float time_scale_;
|
float time_scale_;
|
||||||
SpScene curr_scene_;
|
ScenePtr curr_scene_;
|
||||||
SpScene next_scene_;
|
ScenePtr next_scene_;
|
||||||
SpTransition transition_;
|
TransitionPtr transition_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,8 +126,8 @@ namespace easy2d
|
||||||
|
|
||||||
void LineGeometry::SetLine(Point const & begin, Point const & end)
|
void LineGeometry::SetLine(Point const & begin, Point const & end)
|
||||||
{
|
{
|
||||||
CpPathGeometry path_geo;
|
D2DPathGeometryPtr path_geo;
|
||||||
CpGeometrySink path_sink;
|
D2DGeometrySinkPtr path_sink;
|
||||||
|
|
||||||
HRESULT hr = Factory::Instance()->CreatePathGeometry(path_geo);
|
HRESULT hr = Factory::Instance()->CreatePathGeometry(path_geo);
|
||||||
|
|
||||||
|
|
@ -185,7 +185,7 @@ namespace easy2d
|
||||||
|
|
||||||
void RectangleGeometry::SetRect(Rect const & rect)
|
void RectangleGeometry::SetRect(Rect const & rect)
|
||||||
{
|
{
|
||||||
CpRectangleGeometry geo;
|
D2DRectangleGeometryPtr geo;
|
||||||
if (SUCCEEDED(Factory::Instance()->CreateRectangleGeometry(geo, rect)))
|
if (SUCCEEDED(Factory::Instance()->CreateRectangleGeometry(geo, rect)))
|
||||||
{
|
{
|
||||||
geo_ = geo;
|
geo_ = geo;
|
||||||
|
|
@ -224,7 +224,7 @@ namespace easy2d
|
||||||
|
|
||||||
void CircleGeometry::SetCircle(Point const & center, float radius)
|
void CircleGeometry::SetCircle(Point const & center, float radius)
|
||||||
{
|
{
|
||||||
CpEllipseGeometry geo;
|
D2DEllipseGeometryPtr geo;
|
||||||
if (SUCCEEDED(Factory::Instance()->CreateEllipseGeometry(geo, center, radius, radius)))
|
if (SUCCEEDED(Factory::Instance()->CreateEllipseGeometry(geo, center, radius, radius)))
|
||||||
{
|
{
|
||||||
geo_ = geo;
|
geo_ = geo;
|
||||||
|
|
@ -265,7 +265,7 @@ namespace easy2d
|
||||||
|
|
||||||
void EllipseGeometry::SetEllipse(Point const & center, float radius_x, float radius_y)
|
void EllipseGeometry::SetEllipse(Point const & center, float radius_x, float radius_y)
|
||||||
{
|
{
|
||||||
CpEllipseGeometry geo;
|
D2DEllipseGeometryPtr geo;
|
||||||
if (SUCCEEDED(Factory::Instance()->CreateEllipseGeometry(geo, center, radius_x, radius_y)))
|
if (SUCCEEDED(Factory::Instance()->CreateEllipseGeometry(geo, center, radius_x, radius_y)))
|
||||||
{
|
{
|
||||||
geo_ = geo;
|
geo_ = geo;
|
||||||
|
|
@ -414,7 +414,7 @@ namespace easy2d
|
||||||
|
|
||||||
void RoundedRectGeometry::SetRoundedRect(Rect const & rect, float radius_x, float radius_y)
|
void RoundedRectGeometry::SetRoundedRect(Rect const & rect, float radius_x, float radius_y)
|
||||||
{
|
{
|
||||||
CpRoundedRectangleGeometry geo;
|
D2DRoundedRectangleGeometryPtr geo;
|
||||||
if (SUCCEEDED(Factory::Instance()->CreateRoundedRectangleGeometry(geo, rect, radius_x, radius_y)))
|
if (SUCCEEDED(Factory::Instance()->CreateRoundedRectangleGeometry(geo, rect, radius_x, radius_y)))
|
||||||
{
|
{
|
||||||
geo_ = geo;
|
geo_ = geo;
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ namespace easy2d
|
||||||
float ComputeArea();
|
float ComputeArea();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CpGeometry geo_;
|
D2DGeometryPtr geo_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -254,8 +254,8 @@ namespace easy2d
|
||||||
void ClearPath();
|
void ClearPath();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CpPathGeometry current_geometry_;
|
D2DPathGeometryPtr current_geometry_;
|
||||||
CpGeometrySink current_sink_;
|
D2DGeometrySinkPtr current_sink_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GeometryNode::GeometryNode(SpGeometry const& geometry)
|
GeometryNode::GeometryNode(GeometryPtr const& geometry)
|
||||||
: GeometryNode()
|
: GeometryNode()
|
||||||
{
|
{
|
||||||
SetGeometry(geometry);
|
SetGeometry(geometry);
|
||||||
|
|
@ -41,7 +41,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryNode::SetGeometry(SpGeometry const& geometry)
|
void GeometryNode::SetGeometry(GeometryPtr const& geometry)
|
||||||
{
|
{
|
||||||
geometry_ = geometry;
|
geometry_ = geometry;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,14 +32,14 @@ namespace easy2d
|
||||||
GeometryNode();
|
GeometryNode();
|
||||||
|
|
||||||
GeometryNode(
|
GeometryNode(
|
||||||
SpGeometry const& geometry
|
GeometryPtr const& geometry
|
||||||
);
|
);
|
||||||
|
|
||||||
virtual ~GeometryNode();
|
virtual ~GeometryNode();
|
||||||
|
|
||||||
// ÉčÖĂĐÎ×´
|
// ÉčÖĂĐÎ×´
|
||||||
void SetGeometry(
|
void SetGeometry(
|
||||||
SpGeometry const& geometry
|
GeometryPtr const& geometry
|
||||||
);
|
);
|
||||||
|
|
||||||
// ÉčÖĂĚîłäŃŐÉŤ
|
// ÉčÖĂĚîłäŃŐÉŤ
|
||||||
|
|
@ -63,7 +63,7 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// ťńČĄĐÎ×´
|
// ťńČĄĐÎ×´
|
||||||
SpGeometry const& GetGeometry() const { return geometry_; }
|
GeometryPtr const& GetGeometry() const { return geometry_; }
|
||||||
|
|
||||||
// ťńČĄĚîłäŃŐÉŤ
|
// ťńČĄĚîłäŃŐÉŤ
|
||||||
Color GetFillColor() const { return fill_color_; }
|
Color GetFillColor() const { return fill_color_; }
|
||||||
|
|
@ -84,6 +84,6 @@ namespace easy2d
|
||||||
Color stroke_color_;
|
Color stroke_color_;
|
||||||
float stroke_width_;
|
float stroke_width_;
|
||||||
StrokeStyle outline_join_;
|
StrokeStyle outline_join_;
|
||||||
SpGeometry geometry_;
|
GeometryPtr geometry_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ namespace easy2d
|
||||||
this->Crop(crop_rect);
|
this->Crop(crop_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::Image(CpBitmap const & bitmap)
|
Image::Image(D2DBitmapPtr const & bitmap)
|
||||||
: Image()
|
: Image()
|
||||||
{
|
{
|
||||||
SetBitmap(bitmap);
|
SetBitmap(bitmap);
|
||||||
|
|
@ -58,22 +58,16 @@ namespace easy2d
|
||||||
bool Image::Load(Resource const& res)
|
bool Image::Load(Resource const& res)
|
||||||
{
|
{
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
CpBitmap bitmap;
|
D2DBitmapPtr bitmap;
|
||||||
|
|
||||||
if (res.IsFile())
|
if (res.IsFile())
|
||||||
{
|
{
|
||||||
File image_file;
|
if (!File(res.GetFileName()).Exists())
|
||||||
if (!image_file.Open(res.GetFileName()))
|
|
||||||
{
|
{
|
||||||
logs::Warningln("Image file '%s' not found!", StringWideCharToMultiByte(res.GetFileName()).c_str());
|
logs::Warningln(L"Image file '%s' not found!", res.GetFileName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
hr = Graphics::Instance()->CreateBitmapFromFile(bitmap, res.GetFileName());
|
||||||
// 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加
|
|
||||||
// 默认搜索路径,所以需要通过 File::GetPath 获取完整路径
|
|
||||||
String image_file_path = image_file.GetPath();
|
|
||||||
|
|
||||||
hr = Graphics::Instance()->CreateBitmapFromFile(bitmap, image_file_path);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -82,7 +76,7 @@ namespace easy2d
|
||||||
|
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
logs::Errorln(hr, "Load image file failed!");
|
logs::Errorln(hr, L"Load image file failed!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,12 +159,12 @@ namespace easy2d
|
||||||
return crop_rect_;
|
return crop_rect_;
|
||||||
}
|
}
|
||||||
|
|
||||||
CpBitmap const& Image::GetBitmap() const
|
D2DBitmapPtr const& Image::GetBitmap() const
|
||||||
{
|
{
|
||||||
return bitmap_;
|
return bitmap_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::SetBitmap(CpBitmap const & bitmap)
|
void Image::SetBitmap(D2DBitmapPtr const & bitmap)
|
||||||
{
|
{
|
||||||
if (bitmap)
|
if (bitmap)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
explicit Image(
|
explicit Image(
|
||||||
CpBitmap const& bitmap
|
D2DBitmapPtr const& bitmap
|
||||||
);
|
);
|
||||||
|
|
||||||
virtual ~Image();
|
virtual ~Image();
|
||||||
|
|
@ -86,15 +86,15 @@ namespace easy2d
|
||||||
// »ñÈ¡²Ã¼ô¾ØÐÎ
|
// »ñÈ¡²Ã¼ô¾ØÐÎ
|
||||||
Rect const& GetCropRect() const;
|
Rect const& GetCropRect() const;
|
||||||
|
|
||||||
CpBitmap const& GetBitmap() const;
|
D2DBitmapPtr const& GetBitmap() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void SetBitmap(
|
void SetBitmap(
|
||||||
CpBitmap const& bitmap
|
D2DBitmapPtr const& bitmap
|
||||||
);
|
);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Rect crop_rect_;
|
Rect crop_rect_;
|
||||||
CpBitmap bitmap_;
|
D2DBitmapPtr bitmap_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,12 @@ namespace easy2d
|
||||||
|
|
||||||
InputDevice::~InputDevice()
|
InputDevice::~InputDevice()
|
||||||
{
|
{
|
||||||
E2D_LOG("Destroying input device");
|
E2D_LOG(L"Destroying input device");
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT InputDevice::Init(HWND hwnd, float scale_x, float scale_y, bool debug)
|
HRESULT InputDevice::Init(HWND hwnd, float scale_x, float scale_y, bool debug)
|
||||||
{
|
{
|
||||||
E2D_LOG("Initing input device");
|
E2D_LOG(L"Initing input device");
|
||||||
|
|
||||||
hwnd_ = hwnd;
|
hwnd_ = hwnd;
|
||||||
scale_x_ = scale_x;
|
scale_x_ = scale_x;
|
||||||
|
|
|
||||||
|
|
@ -60,17 +60,12 @@ namespace easy2d
|
||||||
|
|
||||||
if (res.IsFile())
|
if (res.IsFile())
|
||||||
{
|
{
|
||||||
File music_file;
|
if (!File(res.GetFileName()).Exists())
|
||||||
if (!music_file.Open(res.GetFileName()))
|
|
||||||
{
|
{
|
||||||
logs::Warningln("Media file '%s' not found", StringWideCharToMultiByte(res.GetFileName()).c_str());
|
logs::Warningln(L"Media file '%s' not found", res.GetFileName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
hr = transcoder.LoadMediaFile(res.GetFileName(), &wave_data_, &size_);
|
||||||
// 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加
|
|
||||||
// 默认搜索路径,所以需要通过 File::GetPath 获取完整路径
|
|
||||||
String music_file_path = music_file.GetPath();
|
|
||||||
HRESULT hr = transcoder.LoadMediaFile(music_file_path.c_str(), &wave_data_, &size_);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -79,7 +74,7 @@ namespace easy2d
|
||||||
|
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
logs::Errorln(hr, "Load media file failed");
|
logs::Errorln(hr, L"Load media file failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,7 +86,7 @@ namespace easy2d
|
||||||
delete[] wave_data_;
|
delete[] wave_data_;
|
||||||
wave_data_ = nullptr;
|
wave_data_ = nullptr;
|
||||||
}
|
}
|
||||||
logs::Errorln(hr, "Create source voice error");
|
logs::Errorln(hr, L"Create source voice error");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,7 +98,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
if (!opened_)
|
if (!opened_)
|
||||||
{
|
{
|
||||||
logs::Errorln("Music must be opened first!");
|
logs::Errorln(L"Music must be opened first!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,7 +115,7 @@ namespace easy2d
|
||||||
HRESULT hr = voice_.Play(wave_data_, size_, static_cast<UINT32>(loop_count));
|
HRESULT hr = voice_.Play(wave_data_, size_, static_cast<UINT32>(loop_count));
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
logs::Errorln(hr, "Submitting source buffer error");
|
logs::Errorln(hr, L"Submitting source buffer error");
|
||||||
}
|
}
|
||||||
|
|
||||||
playing_ = SUCCEEDED(hr);
|
playing_ = SUCCEEDED(hr);
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ namespace easy2d
|
||||||
|
|
||||||
if (!children_.IsEmpty())
|
if (!children_.IsEmpty())
|
||||||
{
|
{
|
||||||
SpNode next;
|
NodePtr next;
|
||||||
for (auto child = children_.First(); child; child = next)
|
for (auto child = children_.First(); child; child = next)
|
||||||
{
|
{
|
||||||
next = child->NextItem();
|
next = child->NextItem();
|
||||||
|
|
@ -118,7 +118,7 @@ namespace easy2d
|
||||||
if (!visible_)
|
if (!visible_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SpNode prev;
|
NodePtr prev;
|
||||||
for (auto child = children_.Last(); child; child = prev)
|
for (auto child = children_.Last(); child; child = prev)
|
||||||
{
|
{
|
||||||
prev = child->PrevItem();
|
prev = child->PrevItem();
|
||||||
|
|
@ -255,7 +255,7 @@ namespace easy2d
|
||||||
|
|
||||||
if (parent_)
|
if (parent_)
|
||||||
{
|
{
|
||||||
SpNode me = this;
|
NodePtr me = this;
|
||||||
|
|
||||||
parent_->children_.Remove(me);
|
parent_->children_.Remove(me);
|
||||||
|
|
||||||
|
|
@ -272,7 +272,7 @@ namespace easy2d
|
||||||
|
|
||||||
if (sibling)
|
if (sibling)
|
||||||
{
|
{
|
||||||
parent_->children_.InsertAfter(me, SpNode(sibling));
|
parent_->children_.InsertAfter(me, NodePtr(sibling));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -444,7 +444,7 @@ namespace easy2d
|
||||||
dirty_transform_ = true;
|
dirty_transform_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::AddChild(SpNode const& child)
|
void Node::AddChild(NodePtr const& child)
|
||||||
{
|
{
|
||||||
E2D_ASSERT(child && "Node::AddChild failed, NULL pointer exception");
|
E2D_ASSERT(child && "Node::AddChild failed, NULL pointer exception");
|
||||||
|
|
||||||
|
|
@ -453,11 +453,11 @@ namespace easy2d
|
||||||
#ifdef E2D_DEBUG
|
#ifdef E2D_DEBUG
|
||||||
|
|
||||||
if (child->parent_)
|
if (child->parent_)
|
||||||
logs::Errorln("The node to be added already has a parent");
|
logs::Errorln(L"The node to be added already has a parent");
|
||||||
|
|
||||||
for (Node* parent = parent_; parent; parent = parent->parent_)
|
for (Node* parent = parent_; parent; parent = parent->parent_)
|
||||||
if (parent == child)
|
if (parent == child)
|
||||||
logs::Errorln("A node cannot be its own parent");
|
logs::Errorln(L"A node cannot be its own parent");
|
||||||
|
|
||||||
#endif // E2D_DEBUG
|
#endif // E2D_DEBUG
|
||||||
|
|
||||||
|
|
@ -470,7 +470,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::AddChildren(Array<SpNode> const& children)
|
void Node::AddChildren(Array<NodePtr> const& children)
|
||||||
{
|
{
|
||||||
for (const auto& node : children)
|
for (const auto& node : children)
|
||||||
{
|
{
|
||||||
|
|
@ -483,9 +483,9 @@ namespace easy2d
|
||||||
return Rect(Point{}, size_);
|
return Rect(Point{}, size_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Array<SpNode> Node::GetChildren(String const& name) const
|
Array<NodePtr> Node::GetChildren(String const& name) const
|
||||||
{
|
{
|
||||||
Array<SpNode> children;
|
Array<NodePtr> children;
|
||||||
size_t hash_code = std::hash<String>{}(name);
|
size_t hash_code = std::hash<String>{}(name);
|
||||||
|
|
||||||
for (Node* child = children_.First().Get(); child; child = child->NextItem().Get())
|
for (Node* child = children_.First().Get(); child; child = child->NextItem().Get())
|
||||||
|
|
@ -498,7 +498,7 @@ namespace easy2d
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpNode Node::GetChild(String const& name) const
|
NodePtr Node::GetChild(String const& name) const
|
||||||
{
|
{
|
||||||
size_t hash_code = std::hash<String>{}(name);
|
size_t hash_code = std::hash<String>{}(name);
|
||||||
|
|
||||||
|
|
@ -525,7 +525,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node::RemoveChild(SpNode const& child)
|
bool Node::RemoveChild(NodePtr const& child)
|
||||||
{
|
{
|
||||||
return RemoveChild(child.Get());
|
return RemoveChild(child.Get());
|
||||||
}
|
}
|
||||||
|
|
@ -541,7 +541,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
child->parent_ = nullptr;
|
child->parent_ = nullptr;
|
||||||
if (child->scene_) child->SetScene(nullptr);
|
if (child->scene_) child->SetScene(nullptr);
|
||||||
children_.Remove(SpNode(child));
|
children_.Remove(NodePtr(child));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -37,14 +37,14 @@ namespace easy2d
|
||||||
, public TaskManager
|
, public TaskManager
|
||||||
, public ActionManager
|
, public ActionManager
|
||||||
, public EventDispatcher
|
, public EventDispatcher
|
||||||
, protected intrusive::ListItem<SpNode>
|
, protected intrusive::ListItem<NodePtr>
|
||||||
{
|
{
|
||||||
friend class Game;
|
friend class Game;
|
||||||
friend class Scene;
|
friend class Scene;
|
||||||
friend class Transition;
|
friend class Transition;
|
||||||
friend class intrusive::List<SpNode>;
|
friend class intrusive::List<NodePtr>;
|
||||||
|
|
||||||
using Children = intrusive::List<SpNode>;
|
using Children = intrusive::List<NodePtr>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Node();
|
Node();
|
||||||
|
|
@ -291,21 +291,21 @@ namespace easy2d
|
||||||
|
|
||||||
// 添加子节点
|
// 添加子节点
|
||||||
void AddChild(
|
void AddChild(
|
||||||
SpNode const& child
|
NodePtr const& child
|
||||||
);
|
);
|
||||||
|
|
||||||
// 添加多个子节点
|
// 添加多个子节点
|
||||||
void AddChildren(
|
void AddChildren(
|
||||||
Array<SpNode> const& children
|
Array<NodePtr> const& children
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取所有名称相同的子节点
|
// 获取所有名称相同的子节点
|
||||||
Array<SpNode> GetChildren(
|
Array<NodePtr> GetChildren(
|
||||||
String const& name
|
String const& name
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
// 获取名称相同的子节点
|
// 获取名称相同的子节点
|
||||||
SpNode GetChild(
|
NodePtr GetChild(
|
||||||
String const& name
|
String const& name
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
|
@ -314,7 +314,7 @@ namespace easy2d
|
||||||
|
|
||||||
// 移除子节点
|
// 移除子节点
|
||||||
bool RemoveChild(
|
bool RemoveChild(
|
||||||
SpNode const& child
|
NodePtr const& child
|
||||||
);
|
);
|
||||||
|
|
||||||
// 移除子节点
|
// 移除子节点
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,6 @@
|
||||||
|
|
||||||
namespace easy2d
|
namespace easy2d
|
||||||
{
|
{
|
||||||
Resource::Resource(String const& file_name)
|
|
||||||
: type_(Type::File)
|
|
||||||
, file_name_(file_name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Resource::Resource(LPCWSTR file_name)
|
Resource::Resource(LPCWSTR file_name)
|
||||||
: type_(Type::File)
|
: type_(Type::File)
|
||||||
, file_name_(file_name)
|
, file_name_(file_name)
|
||||||
|
|
@ -42,14 +36,10 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Resource::~Resource()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Resource::GetHashCode() const
|
size_t Resource::GetHashCode() const
|
||||||
{
|
{
|
||||||
if (type_ == Type::File)
|
if (type_ == Type::File)
|
||||||
return std::hash<String>{}(file_name_);
|
return std::hash<LPCWSTR>{}(file_name_);
|
||||||
return std::hash<LPCWSTR>{}(bin_name_);
|
return std::hash<LPCWSTR>{}(bin_name_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,28 +54,28 @@ namespace easy2d
|
||||||
res_info = FindResourceW(nullptr, bin_name_, bin_type_);
|
res_info = FindResourceW(nullptr, bin_name_, bin_type_);
|
||||||
if (res_info == nullptr)
|
if (res_info == nullptr)
|
||||||
{
|
{
|
||||||
logs::Errorln("FindResource");
|
logs::Errorln(L"FindResource");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
res_data = LoadResource(nullptr, res_info);
|
res_data = LoadResource(nullptr, res_info);
|
||||||
if (res_data == nullptr)
|
if (res_data == nullptr)
|
||||||
{
|
{
|
||||||
logs::Errorln("LoadResource");
|
logs::Errorln(L"LoadResource");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_size = SizeofResource(nullptr, res_info);
|
buffer_size = SizeofResource(nullptr, res_info);
|
||||||
if (buffer_size == 0)
|
if (buffer_size == 0)
|
||||||
{
|
{
|
||||||
logs::Errorln("SizeofResource");
|
logs::Errorln(L"SizeofResource");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = LockResource(res_data);
|
buffer = LockResource(res_data);
|
||||||
if (buffer == nullptr)
|
if (buffer == nullptr)
|
||||||
{
|
{
|
||||||
logs::Errorln("LockResource");
|
logs::Errorln(L"LockResource");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
// 资源
|
// 资源
|
||||||
//
|
//
|
||||||
// 资源可以是文件类型,也可以是保存在 exe 中的二进制文件
|
// 资源可以是文件类型,也可以是保存在 exe 中的二进制资源
|
||||||
// 例如, 一份音频资源的类型为 L"WAVE", 名称标识符为 IDR_WAVE_1,
|
// 例如, 一份音频资源的类型为 L"WAVE", 名称标识符为 IDR_WAVE_1,
|
||||||
// 那么可以这样指定该资源: Resource res(MAKEINTRESOURCE(IDR_WAVE_1), L"WAVE");
|
// 那么可以这样指定该资源: Resource res(MAKEINTRESOURCE(IDR_WAVE_1), L"WAVE");
|
||||||
//
|
//
|
||||||
|
|
@ -38,25 +38,19 @@ namespace easy2d
|
||||||
enum class Type { File, Binary };
|
enum class Type { File, Binary };
|
||||||
|
|
||||||
Resource(
|
Resource(
|
||||||
String const& file_name /* 文件路径 */
|
LPCWSTR file_name /* 文件路径 */
|
||||||
);
|
);
|
||||||
|
|
||||||
Resource(
|
Resource(
|
||||||
LPCWSTR file_name /* 文件路径 */
|
LPCWSTR name, /* 资源名称 */
|
||||||
|
LPCWSTR type /* 资源类型 */
|
||||||
);
|
);
|
||||||
|
|
||||||
Resource(
|
|
||||||
LPCWSTR name, /* 资源名称 */
|
|
||||||
LPCWSTR type /* 资源类型 */
|
|
||||||
);
|
|
||||||
|
|
||||||
virtual ~Resource();
|
|
||||||
|
|
||||||
inline bool IsFile() const { return type_ == Type::File; }
|
inline bool IsFile() const { return type_ == Type::File; }
|
||||||
|
|
||||||
inline Type GetType() const { return type_; }
|
inline Type GetType() const { return type_; }
|
||||||
|
|
||||||
inline String const& GetFileName() const { return file_name_; }
|
inline LPCWSTR GetFileName() const { return file_name_; }
|
||||||
|
|
||||||
bool Load(
|
bool Load(
|
||||||
LPVOID& buffer,
|
LPVOID& buffer,
|
||||||
|
|
@ -71,7 +65,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
String file_name_;
|
LPCWSTR file_name_;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,12 @@ namespace easy2d
|
||||||
|
|
||||||
void Scene::OnEnter()
|
void Scene::OnEnter()
|
||||||
{
|
{
|
||||||
E2D_LOG("Scene entered");
|
E2D_LOG(L"Scene entered");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::OnExit()
|
void Scene::OnExit()
|
||||||
{
|
{
|
||||||
E2D_LOG("Scene exited");
|
E2D_LOG(L"Scene exited");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::OnDeactivate()
|
void Scene::OnDeactivate()
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite::Sprite(SpImage const& image)
|
Sprite::Sprite(ImagePtr const& image)
|
||||||
: image_(nullptr)
|
: image_(nullptr)
|
||||||
{
|
{
|
||||||
Load(image);
|
Load(image);
|
||||||
|
|
@ -51,7 +51,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sprite::Load(SpImage const& image)
|
bool Sprite::Load(ImagePtr const& image)
|
||||||
{
|
{
|
||||||
if (image)
|
if (image)
|
||||||
{
|
{
|
||||||
|
|
@ -90,7 +90,7 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpImage const& Sprite::GetImage() const
|
ImagePtr const& Sprite::GetImage() const
|
||||||
{
|
{
|
||||||
return image_;
|
return image_;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace easy2d
|
||||||
Sprite();
|
Sprite();
|
||||||
|
|
||||||
explicit Sprite(
|
explicit Sprite(
|
||||||
SpImage const& image
|
ImagePtr const& image
|
||||||
);
|
);
|
||||||
|
|
||||||
explicit Sprite(
|
explicit Sprite(
|
||||||
|
|
@ -53,7 +53,7 @@ namespace easy2d
|
||||||
|
|
||||||
// 加载图片
|
// 加载图片
|
||||||
bool Load(
|
bool Load(
|
||||||
SpImage const& image
|
ImagePtr const& image
|
||||||
);
|
);
|
||||||
|
|
||||||
// 将图片裁剪为矩形
|
// 将图片裁剪为矩形
|
||||||
|
|
@ -62,12 +62,12 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取 Image 对象
|
// 获取 Image 对象
|
||||||
SpImage const& GetImage() const;
|
ImagePtr const& GetImage() const;
|
||||||
|
|
||||||
// 渲染精灵
|
// 渲染精灵
|
||||||
virtual void OnRender() override;
|
virtual void OnRender() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SpImage image_;
|
ImagePtr image_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@ namespace easy2d
|
||||||
// 定时任务
|
// 定时任务
|
||||||
class Task
|
class Task
|
||||||
: public Object
|
: public Object
|
||||||
, protected intrusive::ListItem<SpTask>
|
, protected intrusive::ListItem<TaskPtr>
|
||||||
{
|
{
|
||||||
friend class TaskManager;
|
friend class TaskManager;
|
||||||
friend class intrusive::List<SpTask>;
|
friend class intrusive::List<TaskPtr>;
|
||||||
|
|
||||||
using Callback = std::function<void()>;
|
using Callback = std::function<void()>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace easy2d
|
||||||
if (tasks_.IsEmpty())
|
if (tasks_.IsEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SpTask next;
|
TaskPtr next;
|
||||||
for (auto task = tasks_.First(); task; task = next)
|
for (auto task = tasks_.First(); task; task = next)
|
||||||
{
|
{
|
||||||
next = task->NextItem();
|
next = task->NextItem();
|
||||||
|
|
@ -41,7 +41,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskManager::AddTask(SpTask const& task)
|
void TaskManager::AddTask(TaskPtr const& task)
|
||||||
{
|
{
|
||||||
E2D_ASSERT(task && "AddTask failed, NULL pointer exception");
|
E2D_ASSERT(task && "AddTask failed, NULL pointer exception");
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ namespace easy2d
|
||||||
if (tasks_.IsEmpty())
|
if (tasks_.IsEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SpTask next;
|
TaskPtr next;
|
||||||
for (auto task = tasks_.First(); task; task = next)
|
for (auto task = tasks_.First(); task; task = next)
|
||||||
{
|
{
|
||||||
next = task->NextItem();
|
next = task->NextItem();
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,12 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
class TaskManager
|
class TaskManager
|
||||||
{
|
{
|
||||||
using Tasks = intrusive::List<SpTask>;
|
using Tasks = intrusive::List<TaskPtr>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 添加任务
|
// 添加任务
|
||||||
void AddTask(
|
void AddTask(
|
||||||
SpTask const& task
|
TaskPtr const& task
|
||||||
);
|
);
|
||||||
|
|
||||||
// 启动任务
|
// 启动任务
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::SetLineSpacing(float line_spacing)
|
void Text::SetLineacingPtr(float line_spacing)
|
||||||
{
|
{
|
||||||
if (style_.line_spacing != line_spacing)
|
if (style_.line_spacing != line_spacing)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,7 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 设置行间距(默认为 0)
|
// 设置行间距(默认为 0)
|
||||||
void SetLineSpacing(
|
void SetLineacingPtr(
|
||||||
float line_spacing
|
float line_spacing
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -208,7 +208,7 @@ namespace easy2d
|
||||||
String text_;
|
String text_;
|
||||||
Font font_;
|
Font font_;
|
||||||
TextStyle style_;
|
TextStyle style_;
|
||||||
CpTextFormat text_format_;
|
D2DTextFormatPtr text_format_;
|
||||||
CpTextLayout text_layout_;
|
D2DTextLayoutPtr text_layout_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -123,4 +123,4 @@ namespace easy2d
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
E2D_DECLARE_D2D_SMART_PTR(easy2d::ITextRenderer, CpTextRenderer);
|
E2D_DECLARE_D2D_SMART_PTR(easy2d::ITextRenderer, D2DTextRendererPtr);
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ namespace easy2d
|
||||||
return done_;
|
return done_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transition::Init(SpScene const& prev, SpScene const& next)
|
void Transition::Init(ScenePtr const& prev, ScenePtr const& next)
|
||||||
{
|
{
|
||||||
process_ = 0;
|
process_ = 0;
|
||||||
delta_ = Duration{};
|
delta_ = Duration{};
|
||||||
|
|
@ -147,7 +147,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxTransition::Init(SpScene const& prev, SpScene const& next)
|
void BoxTransition::Init(ScenePtr const& prev, ScenePtr const& next)
|
||||||
{
|
{
|
||||||
Transition::Init(prev, next);
|
Transition::Init(prev, next);
|
||||||
|
|
||||||
|
|
@ -189,7 +189,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmergeTransition::Init(SpScene const& prev, SpScene const& next)
|
void EmergeTransition::Init(ScenePtr const& prev, ScenePtr const& next)
|
||||||
{
|
{
|
||||||
Transition::Init(prev, next);
|
Transition::Init(prev, next);
|
||||||
|
|
||||||
|
|
@ -214,7 +214,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void FadeTransition::Init(SpScene const& prev, SpScene const& next)
|
void FadeTransition::Init(ScenePtr const& prev, ScenePtr const& next)
|
||||||
{
|
{
|
||||||
Transition::Init(prev, next);
|
Transition::Init(prev, next);
|
||||||
|
|
||||||
|
|
@ -248,7 +248,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoveTransition::Init(SpScene const& prev, SpScene const& next)
|
void MoveTransition::Init(ScenePtr const& prev, ScenePtr const& next)
|
||||||
{
|
{
|
||||||
Transition::Init(prev, next);
|
Transition::Init(prev, next);
|
||||||
|
|
||||||
|
|
@ -327,7 +327,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotationTransition::Init(SpScene const& prev, SpScene const& next)
|
void RotationTransition::Init(ScenePtr const& prev, ScenePtr const& next)
|
||||||
{
|
{
|
||||||
Transition::Init(prev, next);
|
Transition::Init(prev, next);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@ namespace easy2d
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Init(
|
virtual void Init(
|
||||||
SpScene const& prev,
|
ScenePtr const& prev,
|
||||||
SpScene const& next
|
ScenePtr const& next
|
||||||
);
|
);
|
||||||
|
|
||||||
virtual void Update(Duration const& dt);
|
virtual void Update(Duration const& dt);
|
||||||
|
|
@ -61,10 +61,10 @@ namespace easy2d
|
||||||
Duration duration_;
|
Duration duration_;
|
||||||
Duration delta_;
|
Duration delta_;
|
||||||
Size window_size_;
|
Size window_size_;
|
||||||
SpScene out_scene_;
|
ScenePtr out_scene_;
|
||||||
SpScene in_scene_;
|
ScenePtr in_scene_;
|
||||||
CpLayer out_layer_;
|
D2DLayerPtr out_layer_;
|
||||||
CpLayer in_layer_;
|
D2DLayerPtr in_layer_;
|
||||||
LayerProperties out_layer_prop_;
|
LayerProperties out_layer_prop_;
|
||||||
LayerProperties in_layer_prop_;
|
LayerProperties in_layer_prop_;
|
||||||
};
|
};
|
||||||
|
|
@ -84,8 +84,8 @@ namespace easy2d
|
||||||
virtual void Update(Duration const& dt) override;
|
virtual void Update(Duration const& dt) override;
|
||||||
|
|
||||||
virtual void Init(
|
virtual void Init(
|
||||||
SpScene const& prev,
|
ScenePtr const& prev,
|
||||||
SpScene const& next
|
ScenePtr const& next
|
||||||
) override;
|
) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -103,8 +103,8 @@ namespace easy2d
|
||||||
virtual void Update(Duration const& dt) override;
|
virtual void Update(Duration const& dt) override;
|
||||||
|
|
||||||
virtual void Init(
|
virtual void Init(
|
||||||
SpScene const& prev,
|
ScenePtr const& prev,
|
||||||
SpScene const& next
|
ScenePtr const& next
|
||||||
) override;
|
) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -122,8 +122,8 @@ namespace easy2d
|
||||||
virtual void Update(Duration const& dt) override;
|
virtual void Update(Duration const& dt) override;
|
||||||
|
|
||||||
virtual void Init(
|
virtual void Init(
|
||||||
SpScene const& prev,
|
ScenePtr const& prev,
|
||||||
SpScene const& next
|
ScenePtr const& next
|
||||||
) override;
|
) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -142,8 +142,8 @@ namespace easy2d
|
||||||
virtual void Update(Duration const& dt) override;
|
virtual void Update(Duration const& dt) override;
|
||||||
|
|
||||||
virtual void Init(
|
virtual void Init(
|
||||||
SpScene const& prev,
|
ScenePtr const& prev,
|
||||||
SpScene const& next
|
ScenePtr const& next
|
||||||
) override;
|
) override;
|
||||||
|
|
||||||
virtual void Reset() override;
|
virtual void Reset() override;
|
||||||
|
|
@ -169,8 +169,8 @@ namespace easy2d
|
||||||
virtual void Update(Duration const& dt) override;
|
virtual void Update(Duration const& dt) override;
|
||||||
|
|
||||||
virtual void Init(
|
virtual void Init(
|
||||||
SpScene const& prev,
|
ScenePtr const& prev,
|
||||||
SpScene const& next
|
ScenePtr const& next
|
||||||
) override;
|
) override;
|
||||||
|
|
||||||
virtual void Reset() override;
|
virtual void Reset() override;
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ namespace easy2d
|
||||||
|
|
||||||
AudioDevice::~AudioDevice()
|
AudioDevice::~AudioDevice()
|
||||||
{
|
{
|
||||||
E2D_LOG("Destroying audio device");
|
E2D_LOG(L"Destroying audio device");
|
||||||
|
|
||||||
ClearVoiceCache();
|
ClearVoiceCache();
|
||||||
|
|
||||||
|
|
@ -179,18 +179,18 @@ namespace easy2d
|
||||||
|
|
||||||
SafeRelease(x_audio2_);
|
SafeRelease(x_audio2_);
|
||||||
|
|
||||||
modules::MediaFoundation().MFShutdown();
|
modules::MediaFoundation::Get().MFShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT AudioDevice::Init(bool debug)
|
HRESULT AudioDevice::Init(bool debug)
|
||||||
{
|
{
|
||||||
E2D_LOG("Initing audio device");
|
E2D_LOG(L"Initing audio device");
|
||||||
|
|
||||||
HRESULT hr = modules::MediaFoundation().MFStartup(MF_VERSION, MFSTARTUP_FULL);
|
HRESULT hr = modules::MediaFoundation::Get().MFStartup(MF_VERSION, MFSTARTUP_FULL);
|
||||||
|
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
hr = modules::XAudio2().XAudio2Create(&x_audio2_, 0, XAUDIO2_DEFAULT_PROCESSOR);
|
hr = modules::XAudio2::Get().XAudio2Create(&x_audio2_, 0, XAUDIO2_DEFAULT_PROCESSOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
|
|
|
||||||
|
|
@ -19,42 +19,42 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "intrusive/SmartPointer.hpp"
|
#include "intrusive/SmartPtr.hpp"
|
||||||
#include <d2d1.h>
|
#include <d2d1.h>
|
||||||
#include <dwrite.h>
|
#include <dwrite.h>
|
||||||
|
|
||||||
#ifndef E2D_DECLARE_D2D_SMART_PTR
|
#ifndef E2D_DECLARE_D2D_SMART_PTR
|
||||||
#define E2D_DECLARE_D2D_SMART_PTR(class_name, sp_name)\
|
#define E2D_DECLARE_D2D_SMART_PTR(class_name, sp_name)\
|
||||||
using sp_name = ::easy2d::intrusive::SmartPointer< class_name >
|
using sp_name = ::easy2d::intrusive::SmartPtr< class_name >
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace easy2d
|
namespace easy2d
|
||||||
{
|
{
|
||||||
// "Cp" is a shorthand for "COM Pointer"
|
// "D2DPtr" is a shorthand for "COM Pointer"
|
||||||
|
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1Factory, CpFactory);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1Factory, D2DFactoryPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(IWICImagingFactory, CpImagingFactory);
|
E2D_DECLARE_D2D_SMART_PTR(IWICImagingFactory, D2DImagingFactoryPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(IDWriteFactory, CpWriteFactory);
|
E2D_DECLARE_D2D_SMART_PTR(IDWriteFactory, D2DWriteFactoryPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1SolidColorBrush, CpSolidColorBrush);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1SolidColorBrush, D2DSolidColorBrushPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1RenderTarget, CpRenderTarget);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1RenderTarget, D2DRenderTargetPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1HwndRenderTarget, CpHwndRenderTarget);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1HwndRenderTarget, D2DHwndRenderTargetPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1BitmapRenderTarget, CpBitmapRenderTarget);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1BitmapRenderTarget, D2DBitmapRenderTargetPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1StrokeStyle, CpStrokeStyle);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1StrokeStyle, D2DStrokeStylePtr);
|
||||||
|
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1Geometry, CpGeometry);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1Geometry, D2DGeometryPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1RectangleGeometry, CpRectangleGeometry);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1RectangleGeometry, D2DRectangleGeometryPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1RoundedRectangleGeometry, CpRoundedRectangleGeometry);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1RoundedRectangleGeometry, D2DRoundedRectangleGeometryPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1EllipseGeometry, CpEllipseGeometry);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1EllipseGeometry, D2DEllipseGeometryPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1GeometryGroup, CpGeometryGroup);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1GeometryGroup, D2DGeometryGroupPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1PathGeometry, CpPathGeometry);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1PathGeometry, D2DPathGeometryPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1TransformedGeometry, CpTransformedGeometry);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1TransformedGeometry, D2DTransformedGeometryPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1GeometrySink, CpGeometrySink);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1GeometrySink, D2DGeometrySinkPtr);
|
||||||
|
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1Layer, CpLayer);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1Layer, D2DLayerPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(ID2D1Bitmap, CpBitmap);
|
E2D_DECLARE_D2D_SMART_PTR(ID2D1Bitmap, D2DBitmapPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(IDWriteTextFormat, CpTextFormat);
|
E2D_DECLARE_D2D_SMART_PTR(IDWriteTextFormat, D2DTextFormatPtr);
|
||||||
E2D_DECLARE_D2D_SMART_PTR(IDWriteTextLayout, CpTextLayout);
|
E2D_DECLARE_D2D_SMART_PTR(IDWriteTextLayout, D2DTextLayoutPtr);
|
||||||
|
|
||||||
inline void IntrusivePtrAddRef(IUnknown* ptr)
|
inline void IntrusivePtrAddRef(IUnknown* ptr)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "RefCounter.hpp"
|
#include "RefCounter.hpp"
|
||||||
#include "intrusive/SmartPointer.hpp"
|
#include "intrusive/SmartPtr.hpp"
|
||||||
#include "../math/vector.hpp"
|
#include "../math/vector.hpp"
|
||||||
#include "../math/Rect.hpp"
|
#include "../math/Rect.hpp"
|
||||||
#include "../math/Matrix.hpp"
|
#include "../math/Matrix.hpp"
|
||||||
|
|
@ -34,13 +34,13 @@
|
||||||
#ifndef E2D_DECLARE_SMART_PTR
|
#ifndef E2D_DECLARE_SMART_PTR
|
||||||
#define E2D_DECLARE_SMART_PTR(class_name)\
|
#define E2D_DECLARE_SMART_PTR(class_name)\
|
||||||
class class_name;\
|
class class_name;\
|
||||||
using Sp##class_name = ::easy2d::intrusive::SmartPointer< class_name >
|
using class_name##Ptr = ::easy2d::intrusive::SmartPtr< class_name >
|
||||||
|
|
||||||
#define E2D_DECLARE_NS_SMART_PTR(ns_name, class_name)\
|
#define E2D_DECLARE_NS_SMART_PTR(ns_name, class_name)\
|
||||||
namespace ns_name\
|
namespace ns_name\
|
||||||
{\
|
{\
|
||||||
class class_name; \
|
class class_name; \
|
||||||
using Sp##class_name = ::easy2d::intrusive::SmartPointer< class_name >;\
|
using class_name##Ptr = ::easy2d::intrusive::SmartPtr< class_name >;\
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -70,8 +70,9 @@ namespace easy2d
|
||||||
|
|
||||||
namespace easy2d
|
namespace easy2d
|
||||||
{
|
{
|
||||||
// "Sp" is a shorthand for "Smart Pointer"
|
// "Ptr" is a shorthand for "Smart Pointer"
|
||||||
|
|
||||||
|
E2D_DECLARE_SMART_PTR(Object);
|
||||||
E2D_DECLARE_SMART_PTR(Image);
|
E2D_DECLARE_SMART_PTR(Image);
|
||||||
E2D_DECLARE_SMART_PTR(Music);
|
E2D_DECLARE_SMART_PTR(Music);
|
||||||
E2D_DECLARE_SMART_PTR(Task);
|
E2D_DECLARE_SMART_PTR(Task);
|
||||||
|
|
@ -140,9 +141,9 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline intrusive::SmartPointer<T> operator- (T* ptr) const
|
inline intrusive::SmartPtr<T> operator- (T* ptr) const
|
||||||
{
|
{
|
||||||
return intrusive::SmartPointer<T>(ptr);
|
return intrusive::SmartPtr<T>(ptr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,47 +27,49 @@ namespace easy2d
|
||||||
namespace intrusive
|
namespace intrusive
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class SmartPointer
|
class SmartPtr
|
||||||
{
|
{
|
||||||
T* ptr_{ nullptr };
|
T* ptr_{ nullptr };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using Type = T;
|
using Type = T;
|
||||||
|
|
||||||
SmartPointer() E2D_NOEXCEPT {}
|
SmartPtr() E2D_NOEXCEPT {}
|
||||||
|
|
||||||
SmartPointer(nullptr_t) E2D_NOEXCEPT {}
|
SmartPtr(nullptr_t) E2D_NOEXCEPT {}
|
||||||
|
|
||||||
SmartPointer(Type* p) E2D_NOEXCEPT : ptr_(p)
|
SmartPtr(Type* p) E2D_NOEXCEPT : ptr_(p)
|
||||||
{
|
{
|
||||||
IntrusivePtrAddRef(ptr_);
|
IntrusivePtrAddRef(ptr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
SmartPointer(const SmartPointer& other) E2D_NOEXCEPT : ptr_(other.ptr_)
|
SmartPtr(const SmartPtr& other) E2D_NOEXCEPT
|
||||||
|
: ptr_(other.ptr_)
|
||||||
{
|
{
|
||||||
IntrusivePtrAddRef(ptr_);
|
IntrusivePtrAddRef(ptr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
SmartPointer(const SmartPointer<U>& other) E2D_NOEXCEPT : ptr_(other.Get())
|
SmartPtr(const SmartPtr<U>& other) E2D_NOEXCEPT
|
||||||
|
: ptr_(other.Get())
|
||||||
{
|
{
|
||||||
IntrusivePtrAddRef(ptr_);
|
IntrusivePtrAddRef(ptr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
SmartPointer(SmartPointer&& other) E2D_NOEXCEPT
|
SmartPtr(SmartPtr&& other) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
ptr_ = other.ptr_;
|
ptr_ = other.ptr_;
|
||||||
other.ptr_ = nullptr;
|
other.ptr_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
~SmartPointer() E2D_NOEXCEPT
|
~SmartPtr() E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
IntrusivePtrRelease(ptr_);
|
IntrusivePtrRelease(ptr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Type* Get() const E2D_NOEXCEPT { return ptr_; }
|
inline Type* Get() const E2D_NOEXCEPT { return ptr_; }
|
||||||
|
|
||||||
inline void Swap(SmartPointer& other) E2D_NOEXCEPT
|
inline void Swap(SmartPtr& other) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
std::swap(ptr_, other.ptr_);
|
std::swap(ptr_, other.ptr_);
|
||||||
}
|
}
|
||||||
|
|
@ -94,14 +96,14 @@ namespace easy2d
|
||||||
|
|
||||||
inline bool operator !() const E2D_NOEXCEPT { return ptr_ == 0; }
|
inline bool operator !() const E2D_NOEXCEPT { return ptr_ == 0; }
|
||||||
|
|
||||||
inline SmartPointer& operator =(const SmartPointer& other) E2D_NOEXCEPT
|
inline SmartPtr& operator =(const SmartPtr& other) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
if (other.ptr_ != ptr_)
|
if (other.ptr_ != ptr_)
|
||||||
SmartPointer(other).Swap(*this);
|
SmartPtr(other).Swap(*this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline SmartPointer& operator =(SmartPointer&& other) E2D_NOEXCEPT
|
inline SmartPtr& operator =(SmartPtr&& other) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
IntrusivePtrRelease(ptr_);
|
IntrusivePtrRelease(ptr_);
|
||||||
ptr_ = other.ptr_;
|
ptr_ = other.ptr_;
|
||||||
|
|
@ -109,83 +111,83 @@ namespace easy2d
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline SmartPointer& operator =(Type* p) E2D_NOEXCEPT
|
inline SmartPtr& operator =(Type* p) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
if (p != ptr_)
|
if (p != ptr_)
|
||||||
SmartPointer(p).Swap(*this);
|
SmartPtr(p).Swap(*this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline SmartPointer& operator =(nullptr_t) E2D_NOEXCEPT
|
inline SmartPtr& operator =(nullptr_t) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
if (nullptr != ptr_)
|
if (nullptr != ptr_)
|
||||||
SmartPointer{}.Swap(*this);
|
SmartPtr{}.Swap(*this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T, class U>
|
template<class T, class U>
|
||||||
inline bool operator==(SmartPointer<T> const& lhs, SmartPointer<U> const& rhs) E2D_NOEXCEPT
|
inline bool operator==(SmartPtr<T> const& lhs, SmartPtr<U> const& rhs) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
return lhs.Get() == rhs.Get();
|
return lhs.Get() == rhs.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class U>
|
template<class T, class U>
|
||||||
inline bool operator!=(SmartPointer<T> const& lhs, SmartPointer<U> const& rhs) E2D_NOEXCEPT
|
inline bool operator!=(SmartPtr<T> const& lhs, SmartPtr<U> const& rhs) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
return lhs.Get() != rhs.Get();
|
return lhs.Get() != rhs.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class U>
|
template<class T, class U>
|
||||||
inline bool operator<(SmartPointer<T> const& lhs, SmartPointer<U> const& rhs) E2D_NOEXCEPT
|
inline bool operator<(SmartPtr<T> const& lhs, SmartPtr<U> const& rhs) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
return lhs.Get() < rhs.Get();
|
return lhs.Get() < rhs.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline bool operator==(SmartPointer<T> const& lhs, T* rhs) E2D_NOEXCEPT
|
inline bool operator==(SmartPtr<T> const& lhs, T* rhs) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
return lhs.Get() == rhs;
|
return lhs.Get() == rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline bool operator!=(SmartPointer<T> const& lhs, T* rhs) E2D_NOEXCEPT
|
inline bool operator!=(SmartPtr<T> const& lhs, T* rhs) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
return lhs.Get() != rhs;
|
return lhs.Get() != rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline bool operator==(T* lhs, SmartPointer<T> const& rhs) E2D_NOEXCEPT
|
inline bool operator==(T* lhs, SmartPtr<T> const& rhs) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
return lhs == rhs.Get();
|
return lhs == rhs.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline bool operator!=(T* lhs, SmartPointer<T> const& rhs) E2D_NOEXCEPT
|
inline bool operator!=(T* lhs, SmartPtr<T> const& rhs) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
return lhs != rhs.Get();
|
return lhs != rhs.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline bool operator==(SmartPointer<T> const& lhs, nullptr_t) E2D_NOEXCEPT
|
inline bool operator==(SmartPtr<T> const& lhs, nullptr_t) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
return !static_cast<bool>(lhs);
|
return !static_cast<bool>(lhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline bool operator!=(SmartPointer<T> const& lhs, nullptr_t) E2D_NOEXCEPT
|
inline bool operator!=(SmartPtr<T> const& lhs, nullptr_t) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
return static_cast<bool>(lhs);
|
return static_cast<bool>(lhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline bool operator==(nullptr_t, SmartPointer<T> const& rhs) E2D_NOEXCEPT
|
inline bool operator==(nullptr_t, SmartPtr<T> const& rhs) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
return !static_cast<bool>(rhs);
|
return !static_cast<bool>(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline bool operator!=(nullptr_t, SmartPointer<T> const& rhs) E2D_NOEXCEPT
|
inline bool operator!=(nullptr_t, SmartPtr<T> const& rhs) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
return static_cast<bool>(rhs);
|
return static_cast<bool>(rhs);
|
||||||
}
|
}
|
||||||
|
|
@ -194,7 +196,7 @@ namespace easy2d
|
||||||
// template class cannot specialize std::swap,
|
// template class cannot specialize std::swap,
|
||||||
// so implement a swap function in easy2d namespace
|
// so implement a swap function in easy2d namespace
|
||||||
template<class T>
|
template<class T>
|
||||||
inline void swap(intrusive::SmartPointer<T>& lhs, intrusive::SmartPointer<T>& rhs) E2D_NOEXCEPT
|
inline void swap(intrusive::SmartPtr<T>& lhs, intrusive::SmartPtr<T>& rhs) E2D_NOEXCEPT
|
||||||
{
|
{
|
||||||
lhs.Swap(rhs);
|
lhs.Swap(rhs);
|
||||||
}
|
}
|
||||||
|
|
@ -32,7 +32,7 @@ namespace easy2d
|
||||||
Right = VK_RIGHT,
|
Right = VK_RIGHT,
|
||||||
Down = VK_DOWN,
|
Down = VK_DOWN,
|
||||||
Enter = VK_RETURN,
|
Enter = VK_RETURN,
|
||||||
Space = VK_SPACE,
|
acePtr = VK_SPACE,
|
||||||
Esc = VK_ESCAPE,
|
Esc = VK_ESCAPE,
|
||||||
Ctrl = VK_CONTROL,
|
Ctrl = VK_CONTROL,
|
||||||
Shift = VK_SHIFT,
|
Shift = VK_SHIFT,
|
||||||
|
|
|
||||||
|
|
@ -33,30 +33,30 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
|
|
||||||
void Out(std::ostream& stream, const char* output)
|
void Out(std::ostream& stream, const wchar_t* output)
|
||||||
{
|
{
|
||||||
stream << output;
|
stream << output;
|
||||||
::OutputDebugStringA(output);
|
::OutputDebugStringW(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutPrefix(std::stringstream& ss)
|
void OutPrefix(std::wstringstream& ss)
|
||||||
{
|
{
|
||||||
std::time_t unix = ::time(NULL);
|
std::time_t unix = ::time(NULL);
|
||||||
struct tm tmbuf;
|
struct tm tmbuf;
|
||||||
localtime_s(&tmbuf, &unix);
|
localtime_s(&tmbuf, &unix);
|
||||||
ss << std::put_time(&tmbuf, "[easy2d] %H:%M:%S ");
|
ss << std::put_time(&tmbuf, L"[easy2d] %H:%M:%S ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Output(std::ostream& stream, const char* prompt, const char* format, va_list args)
|
void Output(std::ostream& stream, const wchar_t* prompt, const wchar_t* format, va_list args)
|
||||||
{
|
{
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
size_t len = ::_vscprintf(format, args) + 1;
|
size_t len = ::_vscwprintf(format, args) + 1;
|
||||||
char* buffer = new char[len];
|
wchar_t* buffer = new wchar_t[len];
|
||||||
::_vsnprintf_s(buffer, len, len, format, args);
|
::_vsnwprintf_s(buffer, len, len, format, args);
|
||||||
|
|
||||||
std::stringstream ss;
|
std::wstringstream ss;
|
||||||
OutPrefix(ss);
|
OutPrefix(ss);
|
||||||
ss << prompt << buffer;
|
ss << prompt << buffer;
|
||||||
Out(stream, ss.str().c_str());
|
Out(stream, ss.str().c_str());
|
||||||
|
|
@ -64,13 +64,13 @@ namespace easy2d
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputLine(std::ostream& stream, const char* prompt, const char* format, va_list args)
|
void OutputLine(std::ostream& stream, const wchar_t* prompt, const wchar_t* format, va_list args)
|
||||||
{
|
{
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Output(stream, prompt, format, args);
|
Output(stream, prompt, format, args);
|
||||||
Out(stream, "\r\n");
|
Out(stream, L"\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,74 +84,74 @@ namespace easy2d
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Print(const char* format, ...)
|
void Print(const wchar_t* format, ...)
|
||||||
{
|
{
|
||||||
va_list args = nullptr;
|
va_list args = nullptr;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
||||||
Output(std::cout, "", format, args);
|
Output(std::cout, L"", format, args);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Println(const char* format, ...)
|
void Println(const wchar_t* format, ...)
|
||||||
{
|
{
|
||||||
va_list args = nullptr;
|
va_list args = nullptr;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
||||||
OutputLine(std::cout, "", format, args);
|
OutputLine(std::cout, L"", format, args);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Warning(const char* format, ...)
|
void Warning(const wchar_t* format, ...)
|
||||||
{
|
{
|
||||||
va_list args = nullptr;
|
va_list args = nullptr;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
||||||
Output(std::cerr, "Warning: ", format, args);
|
Output(std::cerr, L"Warning: ", format, args);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Warningln(const char* format, ...)
|
void Warningln(const wchar_t* format, ...)
|
||||||
{
|
{
|
||||||
va_list args = nullptr;
|
va_list args = nullptr;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
||||||
OutputLine(std::cerr, "Warning: ", format, args);
|
OutputLine(std::cerr, L"Warning: ", format, args);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Error(const char* format, ...)
|
void Error(const wchar_t* format, ...)
|
||||||
{
|
{
|
||||||
va_list args = nullptr;
|
va_list args = nullptr;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
||||||
Output(std::cerr, "Error: ", format, args);
|
Output(std::cerr, L"Error: ", format, args);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Errorln(const char* format, ...)
|
void Errorln(const wchar_t* format, ...)
|
||||||
{
|
{
|
||||||
va_list args = nullptr;
|
va_list args = nullptr;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
||||||
OutputLine(std::cerr, "Error: ", format, args);
|
OutputLine(std::cerr, L"Error: ", format, args);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Errorln(HRESULT hr)
|
void Errorln(HRESULT hr)
|
||||||
{
|
{
|
||||||
Errorln("failure with HRESULT of %08X", hr);
|
Errorln(L"failure with HRESULT of %08X", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Errorln(HRESULT hr, const char* output)
|
void Errorln(HRESULT hr, const wchar_t* output)
|
||||||
{
|
{
|
||||||
Errorln("failure with HRESULT of %08X: %s", hr, output);
|
Errorln(L"failure with HRESULT of %08X: %s", hr, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,21 +37,21 @@ namespace easy2d
|
||||||
|
|
||||||
void Disable();
|
void Disable();
|
||||||
|
|
||||||
void Print(const char* format, ...);
|
void Print(const wchar_t* format, ...);
|
||||||
|
|
||||||
void Println(const char* format, ...);
|
void Println(const wchar_t* format, ...);
|
||||||
|
|
||||||
void Warning(const char* format, ...);
|
void Warning(const wchar_t* format, ...);
|
||||||
|
|
||||||
void Warningln(const char* format, ...);
|
void Warningln(const wchar_t* format, ...);
|
||||||
|
|
||||||
void Error(const char* format, ...);
|
void Error(const wchar_t* format, ...);
|
||||||
|
|
||||||
void Errorln(const char* format, ...);
|
void Errorln(const wchar_t* format, ...);
|
||||||
|
|
||||||
void Errorln(HRESULT hr);
|
void Errorln(HRESULT hr);
|
||||||
|
|
||||||
void Errorln(HRESULT hr, const char* output);
|
void Errorln(HRESULT hr, const wchar_t* output);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ThrowIfFailed(HRESULT hr)
|
inline void ThrowIfFailed(HRESULT hr)
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
E2D_LOG("load shlapi.dll failed");
|
E2D_LOG(L"load shlapi.dll failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,7 +52,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
E2D_LOG("load d2d.dll failed");
|
E2D_LOG(L"load d2d.dll failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
dwrite = LoadLibraryW(L"dwrite.dll");
|
dwrite = LoadLibraryW(L"dwrite.dll");
|
||||||
|
|
@ -63,7 +63,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
E2D_LOG("load dwrite.dll failed");
|
E2D_LOG(L"load dwrite.dll failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +89,7 @@ namespace easy2d
|
||||||
|
|
||||||
if (!xaudio2)
|
if (!xaudio2)
|
||||||
{
|
{
|
||||||
E2D_LOG("load xaudio2.dll failed");
|
E2D_LOG(L"load xaudio2.dll failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,7 +115,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
E2D_LOG("load Mfplat.dll failed");
|
E2D_LOG(L"load Mfplat.dll failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
mfreadwrite = LoadLibraryW(L"Mfreadwrite.dll");
|
mfreadwrite = LoadLibraryW(L"Mfreadwrite.dll");
|
||||||
|
|
@ -129,7 +129,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
E2D_LOG("load Mfreadwrite.dll failed");
|
E2D_LOG(L"load Mfreadwrite.dll failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
class Shlwapi
|
class Shlwapi
|
||||||
{
|
{
|
||||||
|
Shlwapi();
|
||||||
|
|
||||||
HMODULE shlwapi;
|
HMODULE shlwapi;
|
||||||
|
|
||||||
// Shlwapi functions
|
// Shlwapi functions
|
||||||
|
|
@ -40,7 +42,11 @@ namespace easy2d
|
||||||
typedef IStream*(WINAPI *PFN_SHCreateMemStream)(const BYTE*, UINT);
|
typedef IStream*(WINAPI *PFN_SHCreateMemStream)(const BYTE*, UINT);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Shlwapi();
|
static Shlwapi& Get()
|
||||||
|
{
|
||||||
|
static Shlwapi instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
PFN_PathFileExistsW PathFileExistsW;
|
PFN_PathFileExistsW PathFileExistsW;
|
||||||
PFN_SHCreateMemStream SHCreateMemStream;
|
PFN_SHCreateMemStream SHCreateMemStream;
|
||||||
|
|
@ -49,6 +55,8 @@ namespace easy2d
|
||||||
|
|
||||||
class DirectX
|
class DirectX
|
||||||
{
|
{
|
||||||
|
DirectX();
|
||||||
|
|
||||||
HMODULE d2d;
|
HMODULE d2d;
|
||||||
HMODULE dwrite;
|
HMODULE dwrite;
|
||||||
|
|
||||||
|
|
@ -57,7 +65,11 @@ namespace easy2d
|
||||||
typedef HRESULT(WINAPI *PFN_DWriteCreateFactory)(DWRITE_FACTORY_TYPE, const IID&, IUnknown **);
|
typedef HRESULT(WINAPI *PFN_DWriteCreateFactory)(DWRITE_FACTORY_TYPE, const IID&, IUnknown **);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DirectX();
|
static DirectX& Get()
|
||||||
|
{
|
||||||
|
static DirectX instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
PFN_D2D1CreateFactory D2D1CreateFactory;
|
PFN_D2D1CreateFactory D2D1CreateFactory;
|
||||||
PFN_DWriteCreateFactory DWriteCreateFactory;
|
PFN_DWriteCreateFactory DWriteCreateFactory;
|
||||||
|
|
@ -66,13 +78,19 @@ namespace easy2d
|
||||||
|
|
||||||
class XAudio2
|
class XAudio2
|
||||||
{
|
{
|
||||||
|
XAudio2();
|
||||||
|
|
||||||
HMODULE xaudio2;
|
HMODULE xaudio2;
|
||||||
|
|
||||||
// XAudio2 functions
|
// XAudio2 functions
|
||||||
typedef HRESULT(WINAPI *PFN_XAudio2Create)(IXAudio2**, UINT32, XAUDIO2_PROCESSOR);
|
typedef HRESULT(WINAPI *PFN_XAudio2Create)(IXAudio2**, UINT32, XAUDIO2_PROCESSOR);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
XAudio2();
|
static XAudio2& Get()
|
||||||
|
{
|
||||||
|
static XAudio2 instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
PFN_XAudio2Create XAudio2Create;
|
PFN_XAudio2Create XAudio2Create;
|
||||||
};
|
};
|
||||||
|
|
@ -80,6 +98,8 @@ namespace easy2d
|
||||||
|
|
||||||
class MediaFoundation
|
class MediaFoundation
|
||||||
{
|
{
|
||||||
|
MediaFoundation();
|
||||||
|
|
||||||
HMODULE mfplat;
|
HMODULE mfplat;
|
||||||
HMODULE mfreadwrite;
|
HMODULE mfreadwrite;
|
||||||
|
|
||||||
|
|
@ -93,7 +113,11 @@ namespace easy2d
|
||||||
typedef HRESULT(WINAPI *PFN_MFCreateMFByteStreamOnStream)(IStream*, IMFByteStream**);
|
typedef HRESULT(WINAPI *PFN_MFCreateMFByteStreamOnStream)(IStream*, IMFByteStream**);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MediaFoundation();
|
static MediaFoundation& Get()
|
||||||
|
{
|
||||||
|
static MediaFoundation instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
PFN_MFStartup MFStartup;
|
PFN_MFStartup MFStartup;
|
||||||
PFN_MFShutdown MFShutdown;
|
PFN_MFShutdown MFShutdown;
|
||||||
|
|
|
||||||
|
|
@ -41,14 +41,14 @@ namespace easy2d
|
||||||
|
|
||||||
GraphicsDevice::~GraphicsDevice()
|
GraphicsDevice::~GraphicsDevice()
|
||||||
{
|
{
|
||||||
E2D_LOG("Destroying graphics device");
|
E2D_LOG(L"Destroying graphics device");
|
||||||
|
|
||||||
ClearImageCache();
|
ClearImageCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GraphicsDevice::Init(HWND hwnd, bool vsync, bool debug)
|
HRESULT GraphicsDevice::Init(HWND hwnd, bool vsync, bool debug)
|
||||||
{
|
{
|
||||||
E2D_LOG("Initing graphics device");
|
E2D_LOG(L"Initing graphics device");
|
||||||
|
|
||||||
vsync_enabled_ = vsync;
|
vsync_enabled_ = vsync;
|
||||||
debug_ = debug;
|
debug_ = debug;
|
||||||
|
|
@ -108,17 +108,17 @@ namespace easy2d
|
||||||
bitmap_cache_.clear();
|
bitmap_cache_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
CpHwndRenderTarget const & GraphicsDevice::GetRenderTarget() const
|
D2DHwndRenderTargetPtr const & GraphicsDevice::GetRenderTarget() const
|
||||||
{
|
{
|
||||||
return render_target_;
|
return render_target_;
|
||||||
}
|
}
|
||||||
|
|
||||||
CpSolidColorBrush const & GraphicsDevice::GetSolidBrush() const
|
D2DSolidColorBrushPtr const & GraphicsDevice::GetSolidBrush() const
|
||||||
{
|
{
|
||||||
return solid_brush_;
|
return solid_brush_;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GraphicsDevice::CreateLayer(CpLayer& layer)
|
HRESULT GraphicsDevice::CreateLayer(D2DLayerPtr& layer)
|
||||||
{
|
{
|
||||||
if (!render_target_)
|
if (!render_target_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
@ -127,7 +127,7 @@ namespace easy2d
|
||||||
return render_target_->CreateLayer(&layer);
|
return render_target_->CreateLayer(&layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GraphicsDevice::CreateSolidColorBrush(CpSolidColorBrush & brush) const
|
HRESULT GraphicsDevice::CreateSolidColorBrush(D2DSolidColorBrushPtr & brush) const
|
||||||
{
|
{
|
||||||
if (!render_target_)
|
if (!render_target_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
@ -140,7 +140,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GraphicsDevice::DrawGeometry(
|
HRESULT GraphicsDevice::DrawGeometry(
|
||||||
CpGeometry const& geometry,
|
D2DGeometryPtr const& geometry,
|
||||||
Color const& stroke_color,
|
Color const& stroke_color,
|
||||||
float stroke_width,
|
float stroke_width,
|
||||||
StrokeStyle stroke
|
StrokeStyle stroke
|
||||||
|
|
@ -167,7 +167,7 @@ namespace easy2d
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GraphicsDevice::FillGeometry(CpGeometry const & geometry, const Color & fill_color)
|
HRESULT GraphicsDevice::FillGeometry(D2DGeometryPtr const & geometry, const Color & fill_color)
|
||||||
{
|
{
|
||||||
if (!solid_brush_ ||
|
if (!solid_brush_ ||
|
||||||
!render_target_)
|
!render_target_)
|
||||||
|
|
@ -187,7 +187,7 @@ namespace easy2d
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GraphicsDevice::DrawImage(SpImage const & image)
|
HRESULT GraphicsDevice::DrawImage(ImagePtr const & image)
|
||||||
{
|
{
|
||||||
if (!render_target_)
|
if (!render_target_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
@ -212,7 +212,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GraphicsDevice::DrawBitmap(
|
HRESULT GraphicsDevice::DrawBitmap(
|
||||||
CpBitmap const& bitmap
|
D2DBitmapPtr const& bitmap
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!render_target_)
|
if (!render_target_)
|
||||||
|
|
@ -236,7 +236,7 @@ namespace easy2d
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GraphicsDevice::DrawTextLayout(CpTextLayout const& text_layout)
|
HRESULT GraphicsDevice::DrawTextLayout(D2DTextLayoutPtr const& text_layout)
|
||||||
{
|
{
|
||||||
if (!text_renderer_)
|
if (!text_renderer_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
@ -277,7 +277,7 @@ namespace easy2d
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GraphicsDevice::PushLayer(CpLayer const& layer, LayerProperties const& properties)
|
HRESULT GraphicsDevice::PushLayer(D2DLayerPtr const& layer, LayerProperties const& properties)
|
||||||
{
|
{
|
||||||
if (!render_target_ ||
|
if (!render_target_ ||
|
||||||
!solid_brush_)
|
!solid_brush_)
|
||||||
|
|
@ -324,7 +324,7 @@ namespace easy2d
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GraphicsDevice::CreateBitmapFromFile(CpBitmap& bitmap, String const& file_path)
|
HRESULT GraphicsDevice::CreateBitmapFromFile(D2DBitmapPtr& bitmap, String const& file_path)
|
||||||
{
|
{
|
||||||
if (render_target_ == nullptr)
|
if (render_target_ == nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -338,7 +338,7 @@ namespace easy2d
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
CpBitmap bitmap_tmp;
|
D2DBitmapPtr bitmap_tmp;
|
||||||
HRESULT hr = Factory::Instance()->CreateBitmapFromFile(
|
HRESULT hr = Factory::Instance()->CreateBitmapFromFile(
|
||||||
bitmap,
|
bitmap,
|
||||||
render_target_,
|
render_target_,
|
||||||
|
|
@ -353,7 +353,7 @@ namespace easy2d
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GraphicsDevice::CreateBitmapFromResource(CpBitmap& bitmap, Resource const& res)
|
HRESULT GraphicsDevice::CreateBitmapFromResource(D2DBitmapPtr& bitmap, Resource const& res)
|
||||||
{
|
{
|
||||||
if (render_target_ == nullptr)
|
if (render_target_ == nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -381,7 +381,7 @@ namespace easy2d
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GraphicsDevice::CreateBitmapRenderTarget(CpBitmapRenderTarget & brt)
|
HRESULT GraphicsDevice::CreateBitmapRenderTarget(D2DBitmapRenderTargetPtr & brt)
|
||||||
{
|
{
|
||||||
if (!render_target_)
|
if (!render_target_)
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ namespace easy2d
|
||||||
int primitives;
|
int primitives;
|
||||||
};
|
};
|
||||||
|
|
||||||
using BitmapMap = UnorderedMap<size_t, CpBitmap>;
|
using BitmapMap = UnorderedMap<size_t, D2DBitmapPtr>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HRESULT Init(HWND hwnd, bool vsync, bool debug);
|
HRESULT Init(HWND hwnd, bool vsync, bool debug);
|
||||||
|
|
@ -78,25 +78,25 @@ namespace easy2d
|
||||||
void DiscardResources();
|
void DiscardResources();
|
||||||
|
|
||||||
HRESULT CreateLayer(
|
HRESULT CreateLayer(
|
||||||
CpLayer& layer
|
D2DLayerPtr& layer
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT CreateSolidColorBrush(
|
HRESULT CreateSolidColorBrush(
|
||||||
CpSolidColorBrush& brush
|
D2DSolidColorBrushPtr& brush
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
HRESULT CreateBitmapFromFile(
|
HRESULT CreateBitmapFromFile(
|
||||||
CpBitmap& bitmap,
|
D2DBitmapPtr& bitmap,
|
||||||
String const& file_path
|
String const& file_path
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT CreateBitmapFromResource(
|
HRESULT CreateBitmapFromResource(
|
||||||
CpBitmap& bitmap,
|
D2DBitmapPtr& bitmap,
|
||||||
Resource const& res
|
Resource const& res
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT CreateBitmapRenderTarget(
|
HRESULT CreateBitmapRenderTarget(
|
||||||
CpBitmapRenderTarget& brt
|
D2DBitmapRenderTargetPtr& brt
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT SetTransform(
|
HRESULT SetTransform(
|
||||||
|
|
@ -116,27 +116,27 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT DrawGeometry(
|
HRESULT DrawGeometry(
|
||||||
CpGeometry const& geometry,
|
D2DGeometryPtr const& geometry,
|
||||||
const Color& stroke_color,
|
const Color& stroke_color,
|
||||||
float stroke_width,
|
float stroke_width,
|
||||||
StrokeStyle stroke = StrokeStyle::Miter
|
StrokeStyle stroke = StrokeStyle::Miter
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT FillGeometry(
|
HRESULT FillGeometry(
|
||||||
CpGeometry const& geometry,
|
D2DGeometryPtr const& geometry,
|
||||||
const Color& fill_color
|
const Color& fill_color
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT DrawImage(
|
HRESULT DrawImage(
|
||||||
SpImage const& image
|
ImagePtr const& image
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT DrawBitmap(
|
HRESULT DrawBitmap(
|
||||||
CpBitmap const& bitmap
|
D2DBitmapPtr const& bitmap
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT DrawTextLayout(
|
HRESULT DrawTextLayout(
|
||||||
CpTextLayout const& text_layout
|
D2DTextLayoutPtr const& text_layout
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT PushClip(
|
HRESULT PushClip(
|
||||||
|
|
@ -147,7 +147,7 @@ namespace easy2d
|
||||||
HRESULT PopClip();
|
HRESULT PopClip();
|
||||||
|
|
||||||
HRESULT PushLayer(
|
HRESULT PushLayer(
|
||||||
CpLayer const& layer,
|
D2DLayerPtr const& layer,
|
||||||
LayerProperties const& properties
|
LayerProperties const& properties
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -164,9 +164,9 @@ namespace easy2d
|
||||||
|
|
||||||
void ClearImageCache();
|
void ClearImageCache();
|
||||||
|
|
||||||
CpHwndRenderTarget const& GetRenderTarget() const;
|
D2DHwndRenderTargetPtr const& GetRenderTarget() const;
|
||||||
|
|
||||||
CpSolidColorBrush const& GetSolidBrush() const;
|
D2DSolidColorBrushPtr const& GetSolidBrush() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GraphicsDevice();
|
GraphicsDevice();
|
||||||
|
|
@ -182,11 +182,11 @@ namespace easy2d
|
||||||
D2D1_COLOR_F clear_color_;
|
D2D1_COLOR_F clear_color_;
|
||||||
TextAntialias text_antialias_;
|
TextAntialias text_antialias_;
|
||||||
Status status_;
|
Status status_;
|
||||||
CpTextRenderer text_renderer_;
|
D2DTextRendererPtr text_renderer_;
|
||||||
CpSolidColorBrush solid_brush_;
|
D2DSolidColorBrushPtr solid_brush_;
|
||||||
CpHwndRenderTarget render_target_;
|
D2DHwndRenderTargetPtr render_target_;
|
||||||
CpTextFormat fps_text_format_;
|
D2DTextFormatPtr fps_text_format_;
|
||||||
CpTextLayout fps_text_layout_;
|
D2DTextLayoutPtr fps_text_layout_;
|
||||||
BitmapMap bitmap_cache_;
|
BitmapMap bitmap_cache_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -412,7 +412,7 @@ namespace easy2d
|
||||||
|
|
||||||
if (!std::regex_match(str, duration_regex))
|
if (!std::regex_match(str, duration_regex))
|
||||||
{
|
{
|
||||||
logs::Errorln("time::ParseDuration failed, invalid duration");
|
logs::Errorln(L"time::ParseDuration failed, invalid duration");
|
||||||
return Duration();
|
return Duration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -443,7 +443,7 @@ namespace easy2d
|
||||||
|
|
||||||
if (num_str.empty() || num_str == L".")
|
if (num_str.empty() || num_str == L".")
|
||||||
{
|
{
|
||||||
logs::Errorln("time::ParseDuration failed, invalid duration");
|
logs::Errorln(L"time::ParseDuration failed, invalid duration");
|
||||||
return Duration();
|
return Duration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -462,7 +462,7 @@ namespace easy2d
|
||||||
|
|
||||||
if (unit_map.find(unit_str) == unit_map.end())
|
if (unit_map.find(unit_str) == unit_map.end())
|
||||||
{
|
{
|
||||||
logs::Errorln("time::ParseDuration failed, invalid duration");
|
logs::Errorln(L"time::ParseDuration failed, invalid duration");
|
||||||
return Duration();
|
return Duration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,12 +44,12 @@ namespace easy2d
|
||||||
|
|
||||||
WindowImpl::~WindowImpl()
|
WindowImpl::~WindowImpl()
|
||||||
{
|
{
|
||||||
E2D_LOG("Destroying window");
|
E2D_LOG(L"Destroying window");
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT WindowImpl::Init(String title, int width, int height, LPCWSTR icon, WNDPROC proc, bool debug)
|
HRESULT WindowImpl::Init(String title, int width, int height, LPCWSTR icon, WNDPROC proc, bool debug)
|
||||||
{
|
{
|
||||||
E2D_LOG("Creating window");
|
E2D_LOG(L"Creating window");
|
||||||
|
|
||||||
HINSTANCE hinstance = GetModuleHandle(nullptr);
|
HINSTANCE hinstance = GetModuleHandle(nullptr);
|
||||||
WNDCLASSEX wcex = { 0 };
|
WNDCLASSEX wcex = { 0 };
|
||||||
|
|
@ -235,7 +235,7 @@ namespace easy2d
|
||||||
height = static_cast<int>(rect.bottom - rect.top);
|
height = static_cast<int>(rect.bottom - rect.top);
|
||||||
|
|
||||||
if (max_width < width || max_height < height)
|
if (max_width < width || max_height < height)
|
||||||
logs::Warningln("The window is larger than screen!");
|
logs::Warningln(L"The window is larger than screen!");
|
||||||
|
|
||||||
width = std::min(width, max_width);
|
width = std::min(width, max_width);
|
||||||
height = std::min(height, max_height);
|
height = std::min(height, max_height);
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@
|
||||||
|
|
||||||
#include "core/noncopyable.hpp"
|
#include "core/noncopyable.hpp"
|
||||||
#include "core/RefCounter.hpp"
|
#include "core/RefCounter.hpp"
|
||||||
#include "core/intrusive/SmartPointer.hpp"
|
#include "core/intrusive/SmartPtr.hpp"
|
||||||
#include "core/intrusive/List.hpp"
|
#include "core/intrusive/List.hpp"
|
||||||
|
|
||||||
#include "core/Object.h"
|
#include "core/Object.h"
|
||||||
|
|
@ -104,6 +104,7 @@
|
||||||
#include "utils/File.h"
|
#include "utils/File.h"
|
||||||
#include "utils/Player.h"
|
#include "utils/Player.h"
|
||||||
#include "utils/Transcoder.h"
|
#include "utils/Transcoder.h"
|
||||||
|
#include "utils/ResLoader.h"
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ namespace easy2d
|
||||||
return RandomReal(min, max);
|
return RandomReal(min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double Range(double min, double max)
|
inline double Rand(double min, double max)
|
||||||
{
|
{
|
||||||
return RandomReal(min, max);
|
return RandomReal(min, max);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu::Menu(Array<SpButton> const& buttons)
|
Menu::Menu(Array<ButtonPtr> const& buttons)
|
||||||
: enabled_(true)
|
: enabled_(true)
|
||||||
{
|
{
|
||||||
for (const auto& button : buttons)
|
for (const auto& button : buttons)
|
||||||
|
|
@ -61,7 +61,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::AddButton(SpButton const& button)
|
void Menu::AddButton(ButtonPtr const& button)
|
||||||
{
|
{
|
||||||
if (button)
|
if (button)
|
||||||
{
|
{
|
||||||
|
|
@ -71,7 +71,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Menu::RemoveButton(SpButton const& button)
|
bool Menu::RemoveButton(ButtonPtr const& button)
|
||||||
{
|
{
|
||||||
if (buttons_.empty())
|
if (buttons_.empty())
|
||||||
{
|
{
|
||||||
|
|
@ -94,7 +94,7 @@ namespace easy2d
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array<SpButton> const& Menu::GetAllButtons() const
|
Array<ButtonPtr> const& Menu::GetAllButtons() const
|
||||||
{
|
{
|
||||||
return buttons_;
|
return buttons_;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace easy2d
|
||||||
Menu();
|
Menu();
|
||||||
|
|
||||||
explicit Menu(
|
explicit Menu(
|
||||||
Array<SpButton> const& buttons /* 按钮数组 */
|
Array<ButtonPtr> const& buttons /* 按钮数组 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取菜单是否禁用
|
// 获取菜单是否禁用
|
||||||
|
|
@ -49,20 +49,20 @@ namespace easy2d
|
||||||
|
|
||||||
// 添加按钮
|
// 添加按钮
|
||||||
void AddButton(
|
void AddButton(
|
||||||
SpButton const& button
|
ButtonPtr const& button
|
||||||
);
|
);
|
||||||
|
|
||||||
// 移除按钮
|
// 移除按钮
|
||||||
bool RemoveButton(
|
bool RemoveButton(
|
||||||
SpButton const& button
|
ButtonPtr const& button
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取所有按钮
|
// 获取所有按钮
|
||||||
Array<SpButton> const& GetAllButtons() const;
|
Array<ButtonPtr> const& GetAllButtons() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool enabled_;
|
bool enabled_;
|
||||||
Array<SpButton> buttons_;
|
Array<ButtonPtr> buttons_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -24,8 +24,6 @@
|
||||||
|
|
||||||
namespace easy2d
|
namespace easy2d
|
||||||
{
|
{
|
||||||
std::list<String> File::search_paths_;
|
|
||||||
|
|
||||||
File::File()
|
File::File()
|
||||||
: file_path_()
|
: file_path_()
|
||||||
{
|
{
|
||||||
|
|
@ -34,7 +32,6 @@ namespace easy2d
|
||||||
File::File(String const& file_name)
|
File::File(String const& file_name)
|
||||||
: file_path_(file_name)
|
: file_path_(file_name)
|
||||||
{
|
{
|
||||||
this->Open(file_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
File::~File()
|
File::~File()
|
||||||
|
|
@ -46,35 +43,13 @@ namespace easy2d
|
||||||
if (file_name.empty())
|
if (file_name.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto FindFile = [](String const& path) -> bool
|
file_path_ = file_name;
|
||||||
{
|
return Exists();
|
||||||
if (modules::Shlwapi().PathFileExistsW(path.c_str()))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (FindFile(file_name))
|
|
||||||
{
|
|
||||||
file_path_ = file_name;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& path : search_paths_)
|
|
||||||
{
|
|
||||||
if (FindFile(path + file_name))
|
|
||||||
{
|
|
||||||
file_path_ = path + file_name;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::Exists() const
|
bool File::Exists() const
|
||||||
{
|
{
|
||||||
if (modules::Shlwapi().PathFileExistsW(file_path_.c_str()))
|
return modules::Shlwapi::Get().PathFileExistsW(file_path_.c_str());
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String const& File::GetPath() const
|
String const& File::GetPath() const
|
||||||
|
|
@ -101,7 +76,7 @@ namespace easy2d
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
File File::Extract(Resource& res, String const& dest_file_name)
|
File File::Extract(Resource const& res, String const& dest_file_name)
|
||||||
{
|
{
|
||||||
File file;
|
File file;
|
||||||
HANDLE file_handle = ::CreateFile(
|
HANDLE file_handle = ::CreateFile(
|
||||||
|
|
@ -136,25 +111,4 @@ namespace easy2d
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
void File::AddSearchPath(String const& path)
|
|
||||||
{
|
|
||||||
String tmp = path;
|
|
||||||
size_t pos = 0;
|
|
||||||
while ((pos = tmp.find(L"/", pos)) != String::npos)
|
|
||||||
{
|
|
||||||
tmp.replace(pos, 1, L"\\");
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tmp.at(tmp.length() - 1) != L'\\')
|
|
||||||
{
|
|
||||||
tmp.append(L"\\");
|
|
||||||
}
|
|
||||||
auto iter = std::find(search_paths_.cbegin(), search_paths_.cend(), tmp);
|
|
||||||
if (iter == search_paths_.cend())
|
|
||||||
{
|
|
||||||
search_paths_.push_front(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -53,20 +53,13 @@ namespace easy2d
|
||||||
// 获取文件扩展名
|
// 获取文件扩展名
|
||||||
String GetExtension() const;
|
String GetExtension() const;
|
||||||
|
|
||||||
// 释放资源到临时文件目录
|
// 释放二进制资源到临时文件目录
|
||||||
static File Extract(
|
static File Extract(
|
||||||
Resource& res, /* 资源 */
|
Resource const& res, /* 资源 */
|
||||||
String const& dest_file_name /* 目标文件名 */
|
String const& dest_file_name /* 目标文件名 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 添加文件搜索路径
|
|
||||||
static void AddSearchPath(
|
|
||||||
String const& path
|
|
||||||
);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
String file_path_;
|
String file_path_;
|
||||||
|
|
||||||
static List<String> search_paths_;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ namespace easy2d
|
||||||
if (musics_cache_.end() != musics_cache_.find(hash_code))
|
if (musics_cache_.end() != musics_cache_.find(hash_code))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
SpMusic music = new (std::nothrow) Music();
|
MusicPtr music = new (std::nothrow) Music();
|
||||||
|
|
||||||
if (music)
|
if (music)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ namespace easy2d
|
||||||
class Player
|
class Player
|
||||||
: protected Noncopyable
|
: protected Noncopyable
|
||||||
{
|
{
|
||||||
using MusicMap = Map<size_t, SpMusic>;
|
using MusicMap = Map<size_t, MusicPtr>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Player();
|
Player();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,114 @@
|
||||||
|
// 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 "ResLoader.h"
|
||||||
|
#include "../core/Image.h"
|
||||||
|
#include "../core/Frames.h"
|
||||||
|
#include "../core/modules.h"
|
||||||
|
|
||||||
|
namespace easy2d
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
String Search(LPCWSTR file_name, List<String> const& paths)
|
||||||
|
{
|
||||||
|
for (const auto& path : paths)
|
||||||
|
{
|
||||||
|
if (modules::Shlwapi::Get().PathFileExistsW((path + file_name).c_str()))
|
||||||
|
{
|
||||||
|
return path + file_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return file_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResLoader::AddImage(String const& id, Resource const& image)
|
||||||
|
{
|
||||||
|
auto path = Search(image.GetFileName(), search_paths_);
|
||||||
|
res_.insert(std::make_pair(id, ImagePtr(new Image(path.c_str()))));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResLoader::AddFrames(String const& id, Array<Resource> const& images, Duration const& interval)
|
||||||
|
{
|
||||||
|
auto frames = FramesPtr(new Frames);
|
||||||
|
frames->SetInterval(interval);
|
||||||
|
|
||||||
|
for (const auto& image : images)
|
||||||
|
{
|
||||||
|
auto path = Search(image.GetFileName(), search_paths_);
|
||||||
|
frames->Add(ImagePtr(new Image(path.c_str())));
|
||||||
|
}
|
||||||
|
res_.insert(std::make_pair(id, frames));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResLoader::AddObj(String const& id, ObjectPtr const& obj)
|
||||||
|
{
|
||||||
|
res_.insert(std::make_pair(id, obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
ImagePtr ResLoader::GetImage(String const & id) const
|
||||||
|
{
|
||||||
|
return Get<Image*>(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
FramesPtr ResLoader::GetFrames(String const & id) const
|
||||||
|
{
|
||||||
|
return Get<Frames*>(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectPtr ResLoader::GetObj(String const & id) const
|
||||||
|
{
|
||||||
|
return Get<Object*>(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResLoader::Delete(String const & id)
|
||||||
|
{
|
||||||
|
res_.erase(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResLoader::Destroy()
|
||||||
|
{
|
||||||
|
res_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResLoader::AddSearchPath(String const & path)
|
||||||
|
{
|
||||||
|
String tmp = path;
|
||||||
|
size_t pos = 0;
|
||||||
|
while ((pos = tmp.find(L"/", pos)) != String::npos)
|
||||||
|
{
|
||||||
|
tmp.replace(pos, 1, L"\\");
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tmp.at(tmp.length() - 1) != L'\\')
|
||||||
|
{
|
||||||
|
tmp.append(L"\\");
|
||||||
|
}
|
||||||
|
|
||||||
|
auto iter = std::find(search_paths_.cbegin(), search_paths_.cend(), tmp);
|
||||||
|
if (iter == search_paths_.cend())
|
||||||
|
{
|
||||||
|
search_paths_.push_front(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -19,30 +19,46 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "include-forwards.h"
|
#include "../core/include-forwards.h"
|
||||||
|
#include "../core/Resource.h"
|
||||||
|
|
||||||
namespace easy2d
|
namespace easy2d
|
||||||
{
|
{
|
||||||
class ResLoader
|
class ResLoader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//void Add(String const& id, SpImage const& image);
|
void AddImage(String const& id, Resource const& image);
|
||||||
|
|
||||||
//void Add(String const& id, SpFrames const& frames);
|
void AddFrames(String const& id, Array<Resource> const& images, Duration const& interval = 200);
|
||||||
|
|
||||||
//SpImage GetImage(String const& id);
|
void AddObj(String const& id, ObjectPtr const& obj);
|
||||||
|
|
||||||
//SpFrames GetFrames(String const& id);
|
ImagePtr GetImage(String const& id) const;
|
||||||
|
|
||||||
|
FramesPtr GetFrames(String const& id) const;
|
||||||
|
|
||||||
|
ObjectPtr GetObj(String const& id) const;
|
||||||
|
|
||||||
|
void Delete(String const& id);
|
||||||
|
|
||||||
|
void Destroy();
|
||||||
|
|
||||||
|
// Ìí¼Ó×ÊÔ´ËÑË÷·¾¶
|
||||||
|
void AddSearchPath(
|
||||||
|
String const& path
|
||||||
|
);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T Get(String const& id) const
|
auto Get(String const& id) const -> decltype(auto)
|
||||||
{
|
{
|
||||||
if (res_.find(id) == res_.end())
|
auto iter = res_.find(id);
|
||||||
|
if (iter == res_.end())
|
||||||
return T{};
|
return T{};
|
||||||
return static_cast<T>(res_.at(id));
|
return dynamic_cast<T>((*iter).second.Get());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UnorderedMap<String, void*> res_;
|
UnorderedMap<String, ObjectPtr> res_;
|
||||||
|
List<String> search_paths_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -51,9 +51,9 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
|
|
||||||
SmartPointer<IMFSourceReader> reader;
|
SmartPtr<IMFSourceReader> reader;
|
||||||
|
|
||||||
hr = modules::MediaFoundation().MFCreateSourceReaderFromURL(
|
hr = modules::MediaFoundation::Get().MFCreateSourceReaderFromURL(
|
||||||
file_path,
|
file_path,
|
||||||
nullptr,
|
nullptr,
|
||||||
&reader
|
&reader
|
||||||
|
|
@ -72,33 +72,33 @@ namespace easy2d
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
HINSTANCE hinstance = GetModuleHandle(nullptr);
|
HINSTANCE hinstance = GetModuleHandle(nullptr);
|
||||||
|
|
||||||
SmartPointer<IStream> stream;
|
SmartPtr<IStream> stream;
|
||||||
SmartPointer<IMFByteStream> byte_stream;
|
SmartPtr<IMFByteStream> byte_stream;
|
||||||
SmartPointer<IMFSourceReader> reader;
|
SmartPtr<IMFSourceReader> reader;
|
||||||
|
|
||||||
LPVOID buffer;
|
LPVOID buffer;
|
||||||
DWORD buffer_size;
|
DWORD buffer_size;
|
||||||
if (!res.Load(buffer, buffer_size)) { return false; }
|
if (!res.Load(buffer, buffer_size)) { return false; }
|
||||||
|
|
||||||
stream = modules::Shlwapi{}.SHCreateMemStream(
|
stream = modules::Shlwapi::Get().SHCreateMemStream(
|
||||||
static_cast<const BYTE*>(buffer),
|
static_cast<const BYTE*>(buffer),
|
||||||
static_cast<UINT>(buffer_size)
|
static_cast<UINT>(buffer_size)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (stream == nullptr)
|
if (stream == nullptr)
|
||||||
{
|
{
|
||||||
logs::Errorln("SHCreateMemStream");
|
logs::Errorln(L"SHCreateMemStream");
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
hr = modules::MediaFoundation().MFCreateMFByteStreamOnStream(stream.Get(), &byte_stream);
|
hr = modules::MediaFoundation::Get().MFCreateMFByteStreamOnStream(stream.Get(), &byte_stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
hr = modules::MediaFoundation().MFCreateSourceReaderFromByteStream(
|
hr = modules::MediaFoundation::Get().MFCreateSourceReaderFromByteStream(
|
||||||
byte_stream.Get(),
|
byte_stream.Get(),
|
||||||
nullptr,
|
nullptr,
|
||||||
&reader
|
&reader
|
||||||
|
|
@ -118,10 +118,10 @@ namespace easy2d
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
DWORD max_stream_size = 0;
|
DWORD max_stream_size = 0;
|
||||||
|
|
||||||
SmartPointer<IMFMediaType> partial_type;
|
SmartPtr<IMFMediaType> partial_type;
|
||||||
SmartPointer<IMFMediaType> uncompressed_type;
|
SmartPtr<IMFMediaType> uncompressed_type;
|
||||||
|
|
||||||
hr = modules::MediaFoundation().MFCreateMediaType(&partial_type);
|
hr = modules::MediaFoundation::Get().MFCreateMediaType(&partial_type);
|
||||||
|
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
|
|
@ -165,7 +165,7 @@ namespace easy2d
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
UINT32 size = 0;
|
UINT32 size = 0;
|
||||||
hr = modules::MediaFoundation().MFCreateWaveFormatExFromMFMediaType(
|
hr = modules::MediaFoundation::Get().MFCreateWaveFormatExFromMFMediaType(
|
||||||
uncompressed_type.Get(),
|
uncompressed_type.Get(),
|
||||||
&wave_format_,
|
&wave_format_,
|
||||||
&size,
|
&size,
|
||||||
|
|
@ -199,12 +199,12 @@ namespace easy2d
|
||||||
DWORD position = 0;
|
DWORD position = 0;
|
||||||
BYTE* data = new (std::nothrow) BYTE[max_stream_size];
|
BYTE* data = new (std::nothrow) BYTE[max_stream_size];
|
||||||
|
|
||||||
SmartPointer<IMFSample> sample;
|
SmartPtr<IMFSample> sample;
|
||||||
SmartPointer<IMFMediaBuffer> buffer;
|
SmartPtr<IMFMediaBuffer> buffer;
|
||||||
|
|
||||||
if (data == nullptr)
|
if (data == nullptr)
|
||||||
{
|
{
|
||||||
logs::Errorln("Low memory");
|
logs::Errorln(L"Low memory");
|
||||||
hr = E_OUTOFMEMORY;
|
hr = E_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logs::Errorln(HRESULT_FROM_WIN32(GetLastError()), "Wrong convert to WideChar code");
|
logs::Errorln(HRESULT_FROM_WIN32(GetLastError()), L"Convert to WideChar code failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -66,7 +66,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logs::Errorln(HRESULT_FROM_WIN32(GetLastError()), ("Wrong convert to MultiByte code"));
|
logs::Errorln(HRESULT_FROM_WIN32(GetLastError()), L"Convert to MultiByte code failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue