Add Library
This commit is contained in:
parent
4667333e7c
commit
48d85a1e97
|
|
@ -12,6 +12,7 @@
|
|||
<ClInclude Include="..\..\src\kiwano\2d\Frame.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\2d\GifSprite.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\base\Director.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\base\Library.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\base\win32\ComPtr.hpp" />
|
||||
<ClInclude Include="..\..\src\kiwano\base\win32\helper.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\any.hpp" />
|
||||
|
|
@ -118,6 +119,7 @@
|
|||
<ClCompile Include="..\..\src\kiwano\base\EventDispatcher.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\base\EventListener.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\base\Input.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\base\Library.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\base\Logger.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\base\ObjectBase.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\base\Resource.cpp" />
|
||||
|
|
|
|||
|
|
@ -300,6 +300,9 @@
|
|||
<ClInclude Include="..\..\src\kiwano\utils\UserData.h">
|
||||
<Filter>utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\base\Library.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\kiwano\ui\Button.cpp">
|
||||
|
|
@ -476,5 +479,8 @@
|
|||
<ClCompile Include="..\..\src\kiwano\utils\UserData.cpp">
|
||||
<Filter>utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\base\Library.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -28,7 +28,7 @@ namespace kiwano
|
|||
namespace modules
|
||||
{
|
||||
XAudio2::XAudio2()
|
||||
: xaudio2(nullptr)
|
||||
: xaudio2()
|
||||
, XAudio2Create(nullptr)
|
||||
{
|
||||
const auto xaudio2_dll_names =
|
||||
|
|
@ -40,16 +40,17 @@ namespace kiwano
|
|||
|
||||
for (const auto& name : xaudio2_dll_names)
|
||||
{
|
||||
xaudio2 = LoadLibraryW(name);
|
||||
if (xaudio2)
|
||||
if (xaudio2.Load(name))
|
||||
{
|
||||
XAudio2Create = (PFN_XAudio2Create)
|
||||
GetProcAddress(xaudio2, "XAudio2Create");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!xaudio2)
|
||||
if (xaudio2.IsValid())
|
||||
{
|
||||
XAudio2Create = xaudio2.GetProcess<PFN_XAudio2Create>(L"XAudio2Create");
|
||||
}
|
||||
else
|
||||
{
|
||||
KGE_ERROR_LOG(L"Load xaudio2.dll failed");
|
||||
throw std::runtime_error("Load xaudio2.dll failed");
|
||||
|
|
@ -57,8 +58,8 @@ namespace kiwano
|
|||
}
|
||||
|
||||
MediaFoundation::MediaFoundation()
|
||||
: mfplat(nullptr)
|
||||
, mfreadwrite(nullptr)
|
||||
: mfplat()
|
||||
, mfreadwrite()
|
||||
, MFStartup(nullptr)
|
||||
, MFShutdown(nullptr)
|
||||
, MFCreateMediaType(nullptr)
|
||||
|
|
@ -67,23 +68,13 @@ namespace kiwano
|
|||
, MFCreateSourceReaderFromByteStream(nullptr)
|
||||
, MFCreateMFByteStreamOnStream(nullptr)
|
||||
{
|
||||
mfplat = LoadLibraryW(L"Mfplat.dll");
|
||||
if (mfplat)
|
||||
if (mfplat.Load(L"Mfplat.dll"))
|
||||
{
|
||||
MFStartup = (PFN_MFStartup)
|
||||
GetProcAddress(mfplat, "MFStartup");
|
||||
|
||||
MFShutdown = (PFN_MFShutdown)
|
||||
GetProcAddress(mfplat, "MFShutdown");
|
||||
|
||||
MFCreateMediaType = (PFN_MFCreateMediaType)
|
||||
GetProcAddress(mfplat, "MFCreateMediaType");
|
||||
|
||||
MFCreateWaveFormatExFromMFMediaType = (PFN_MFCreateWaveFormatExFromMFMediaType)
|
||||
GetProcAddress(mfplat, "MFCreateWaveFormatExFromMFMediaType");
|
||||
|
||||
MFCreateMFByteStreamOnStream = (PFN_MFCreateMFByteStreamOnStream)
|
||||
GetProcAddress(mfplat, "MFCreateMFByteStreamOnStream");
|
||||
MFStartup = mfplat.GetProcess<PFN_MFStartup>(L"MFStartup");
|
||||
MFShutdown = mfplat.GetProcess<PFN_MFShutdown>(L"MFShutdown");
|
||||
MFCreateMediaType = mfplat.GetProcess<PFN_MFCreateMediaType>(L"MFCreateMediaType");
|
||||
MFCreateWaveFormatExFromMFMediaType = mfplat.GetProcess<PFN_MFCreateWaveFormatExFromMFMediaType>(L"MFCreateWaveFormatExFromMFMediaType");
|
||||
MFCreateMFByteStreamOnStream = mfplat.GetProcess<PFN_MFCreateMFByteStreamOnStream>(L"MFCreateMFByteStreamOnStream");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -91,14 +82,10 @@ namespace kiwano
|
|||
throw std::runtime_error("Load Mfplat.dll failed");
|
||||
}
|
||||
|
||||
mfreadwrite = LoadLibraryW(L"Mfreadwrite.dll");
|
||||
if (mfreadwrite)
|
||||
if (mfreadwrite.Load(L"Mfreadwrite.dll"))
|
||||
{
|
||||
MFCreateSourceReaderFromURL = (PFN_MFCreateSourceReaderFromURL)
|
||||
GetProcAddress(mfreadwrite, "MFCreateSourceReaderFromURL");
|
||||
|
||||
MFCreateSourceReaderFromByteStream = (PFN_MFCreateSourceReaderFromByteStream)
|
||||
GetProcAddress(mfreadwrite, "MFCreateSourceReaderFromByteStream");
|
||||
MFCreateSourceReaderFromURL = mfreadwrite.GetProcess<PFN_MFCreateSourceReaderFromURL>(L"MFCreateSourceReaderFromURL");
|
||||
MFCreateSourceReaderFromByteStream = mfreadwrite.GetProcess<PFN_MFCreateSourceReaderFromByteStream>(L"MFCreateSourceReaderFromByteStream");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/base/Library.h>
|
||||
#include <xaudio2.h>
|
||||
#include <mfapi.h>
|
||||
#include <mfidl.h>
|
||||
|
|
@ -32,13 +33,6 @@ namespace kiwano
|
|||
{
|
||||
class KGE_API XAudio2
|
||||
{
|
||||
XAudio2();
|
||||
|
||||
HMODULE xaudio2;
|
||||
|
||||
// XAudio2 functions
|
||||
typedef HRESULT(WINAPI* PFN_XAudio2Create)(IXAudio2**, UINT32, XAUDIO2_PROCESSOR);
|
||||
|
||||
public:
|
||||
static inline XAudio2& Get()
|
||||
{
|
||||
|
|
@ -46,16 +40,29 @@ namespace kiwano
|
|||
return instance;
|
||||
}
|
||||
|
||||
// XAudio2 functions
|
||||
typedef HRESULT(WINAPI* PFN_XAudio2Create)(IXAudio2**, UINT32, XAUDIO2_PROCESSOR);
|
||||
|
||||
PFN_XAudio2Create XAudio2Create;
|
||||
|
||||
private:
|
||||
XAudio2();
|
||||
|
||||
XAudio2(const XAudio2&) = delete;
|
||||
XAudio2& operator=(const XAudio2&) = delete;
|
||||
|
||||
Library xaudio2;
|
||||
};
|
||||
|
||||
|
||||
class KGE_API MediaFoundation
|
||||
{
|
||||
MediaFoundation();
|
||||
|
||||
HMODULE mfplat;
|
||||
HMODULE mfreadwrite;
|
||||
public:
|
||||
static inline MediaFoundation& Get()
|
||||
{
|
||||
static MediaFoundation instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
// MediaFoundation functions
|
||||
typedef HRESULT(WINAPI* PFN_MFStartup)(ULONG, DWORD);
|
||||
|
|
@ -66,13 +73,6 @@ namespace kiwano
|
|||
typedef HRESULT(WINAPI* PFN_MFCreateSourceReaderFromByteStream)(IMFByteStream*, IMFAttributes*, IMFSourceReader**);
|
||||
typedef HRESULT(WINAPI* PFN_MFCreateMFByteStreamOnStream)(IStream*, IMFByteStream**);
|
||||
|
||||
public:
|
||||
static inline MediaFoundation& Get()
|
||||
{
|
||||
static MediaFoundation instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
PFN_MFStartup MFStartup;
|
||||
PFN_MFShutdown MFShutdown;
|
||||
PFN_MFCreateMediaType MFCreateMediaType;
|
||||
|
|
@ -80,6 +80,15 @@ namespace kiwano
|
|||
PFN_MFCreateSourceReaderFromURL MFCreateSourceReaderFromURL;
|
||||
PFN_MFCreateSourceReaderFromByteStream MFCreateSourceReaderFromByteStream;
|
||||
PFN_MFCreateMFByteStreamOnStream MFCreateMFByteStreamOnStream;
|
||||
|
||||
private:
|
||||
MediaFoundation();
|
||||
|
||||
MediaFoundation(const MediaFoundation&) = delete;
|
||||
MediaFoundation& operator=(const MediaFoundation&) = delete;
|
||||
|
||||
Library mfplat;
|
||||
Library mfreadwrite;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,109 +49,109 @@ namespace kiwano
|
|||
Actor();
|
||||
|
||||
// 更新角色
|
||||
virtual void OnUpdate(Duration dt) { KGE_NOT_USED(dt); }
|
||||
virtual void OnUpdate(Duration dt);
|
||||
|
||||
// 渲染角色
|
||||
virtual void OnRender(RenderTarget* rt) { KGE_NOT_USED(rt); }
|
||||
virtual void OnRender(RenderTarget* rt);
|
||||
|
||||
// 获取显示状态
|
||||
bool IsVisible() const { return visible_; }
|
||||
bool IsVisible() const;
|
||||
|
||||
// 获取响应状态
|
||||
bool IsResponsible() const { return responsible_; }
|
||||
bool IsResponsible() const;
|
||||
|
||||
// 是否启用级联透明度
|
||||
bool IsCascadeOpacityEnabled() const { return cascade_opacity_; }
|
||||
bool IsCascadeOpacityEnabled() const;
|
||||
|
||||
// 获取名称的 Hash 值
|
||||
size_t GetHashName() const { return hash_name_; }
|
||||
size_t GetHashName() const;
|
||||
|
||||
// 获取 Z 轴顺序
|
||||
int GetZOrder() const { return z_order_; }
|
||||
int GetZOrder() const;
|
||||
|
||||
// 获取坐标
|
||||
Point const& GetPosition() const { return transform_.position; }
|
||||
Point const& GetPosition() const;
|
||||
|
||||
// 获取 x 坐标
|
||||
float GetPositionX() const { return GetPosition().x; }
|
||||
float GetPositionX() const;
|
||||
|
||||
// 获取 y 坐标
|
||||
float GetPositionY() const { return GetPosition().y; }
|
||||
float GetPositionY() const;
|
||||
|
||||
// 获取缩放比例
|
||||
Point const& GetScale() const { return transform_.scale; }
|
||||
Point const& GetScale() const;
|
||||
|
||||
// 获取横向缩放比例
|
||||
float GetScaleX() const { return GetScale().x; }
|
||||
float GetScaleX() const;
|
||||
|
||||
// 获取纵向缩放比例
|
||||
float GetScaleY() const { return GetScale().y; }
|
||||
float GetScaleY() const;
|
||||
|
||||
// 获取错切角度
|
||||
Point const& GetSkew() const { return transform_.skew; }
|
||||
Point const& GetSkew() const;
|
||||
|
||||
// 获取横向错切角度
|
||||
float GetSkewX() const { return GetSkew().x; }
|
||||
float GetSkewX() const;
|
||||
|
||||
// 获取纵向错切角度
|
||||
float GetSkewY() const { return GetSkew().y; }
|
||||
float GetSkewY() const;
|
||||
|
||||
// 获取旋转角度
|
||||
float GetRotation() const { return transform_.rotation; }
|
||||
float GetRotation() const;
|
||||
|
||||
// 获取宽度
|
||||
float GetWidth() const { return GetSize().x; }
|
||||
float GetWidth() const;
|
||||
|
||||
// 获取高度
|
||||
float GetHeight() const { return GetSize().y; }
|
||||
float GetHeight() const;
|
||||
|
||||
// 获取大小
|
||||
Size const& GetSize() const { return size_; }
|
||||
Size const& GetSize() const;
|
||||
|
||||
// 获取缩放后的宽度
|
||||
float GetScaledWidth() const { return GetWidth() * GetScaleX(); }
|
||||
float GetScaledWidth() const;
|
||||
|
||||
// 获取缩放后的高度
|
||||
float GetScaledHeight() const { return GetHeight() * GetScaleY(); }
|
||||
float GetScaledHeight() const;
|
||||
|
||||
// 获取缩放后的大小
|
||||
Size GetScaledSize() const { return Size{ GetScaledWidth(), GetScaledHeight() }; }
|
||||
Size GetScaledSize() const;
|
||||
|
||||
// 获取锚点
|
||||
Point const& GetAnchor() const { return anchor_; }
|
||||
Point const& GetAnchor() const;
|
||||
|
||||
// 获取 x 方向锚点
|
||||
float GetAnchorX() const { return GetAnchor().x; }
|
||||
float GetAnchorX() const;
|
||||
|
||||
// 获取 y 方向锚点
|
||||
float GetAnchorY() const { return GetAnchor().y; }
|
||||
float GetAnchorY() const;
|
||||
|
||||
// 获取透明度
|
||||
float GetOpacity() const { return opacity_; }
|
||||
float GetOpacity() const;
|
||||
|
||||
// 获取显示透明度
|
||||
float GetDisplayedOpacity() const { return displayed_opacity_; }
|
||||
float GetDisplayedOpacity() const;
|
||||
|
||||
// 获取变换
|
||||
Transform GetTransform() const { return transform_; }
|
||||
Transform GetTransform() const;
|
||||
|
||||
// 获取父角色
|
||||
inline Actor* GetParent() const { return parent_; }
|
||||
Actor* GetParent() const;
|
||||
|
||||
// 获取所在舞台
|
||||
inline Stage* GetStage() const { return stage_; }
|
||||
Stage* GetStage() const;
|
||||
|
||||
// 获取边框
|
||||
virtual Rect GetBounds() const;
|
||||
virtual Rect GetBounds() const;
|
||||
|
||||
// 获取外切包围盒
|
||||
virtual Rect GetBoundingBox() const;
|
||||
virtual Rect GetBoundingBox() const;
|
||||
|
||||
// 获取二维变换矩阵
|
||||
Matrix3x2 const& GetTransformMatrix() const;
|
||||
Matrix3x2 const& GetTransformMatrix() const;
|
||||
|
||||
// 获取二维变换的逆矩阵
|
||||
Matrix3x2 const& GetTransformInverseMatrix() const;
|
||||
Matrix3x2 const& GetTransformInverseMatrix() const;
|
||||
|
||||
// 设置是否显示
|
||||
void SetVisible(
|
||||
|
|
@ -169,13 +169,10 @@ namespace kiwano
|
|||
);
|
||||
|
||||
// 设置坐标
|
||||
inline void SetPosition(
|
||||
void SetPosition(
|
||||
float x,
|
||||
float y
|
||||
)
|
||||
{
|
||||
SetPosition(Point{ x, y });
|
||||
}
|
||||
);
|
||||
|
||||
// 设置横坐标
|
||||
void SetPositionX(
|
||||
|
|
@ -193,13 +190,10 @@ namespace kiwano
|
|||
);
|
||||
|
||||
// 移动坐标
|
||||
inline void Move(
|
||||
void Move(
|
||||
float vx,
|
||||
float vy
|
||||
)
|
||||
{
|
||||
Move(Vec2{ vx, vy });
|
||||
}
|
||||
);
|
||||
|
||||
// 设置缩放比例
|
||||
// 默认为 (1.0, 1.0)
|
||||
|
|
@ -209,13 +203,10 @@ namespace kiwano
|
|||
|
||||
// 设置缩放比例
|
||||
// 默认为 (1.0, 1.0)
|
||||
inline void SetScale(
|
||||
void SetScale(
|
||||
float scalex,
|
||||
float scaley
|
||||
)
|
||||
{
|
||||
SetScale(Vec2{ scalex, scaley });
|
||||
}
|
||||
);
|
||||
|
||||
// 设置错切角度
|
||||
// 默认为 (0, 0)
|
||||
|
|
@ -225,13 +216,10 @@ namespace kiwano
|
|||
|
||||
// 设置错切角度
|
||||
// 默认为 (0, 0)
|
||||
inline void SetSkew(
|
||||
void SetSkew(
|
||||
float skewx,
|
||||
float skewy
|
||||
)
|
||||
{
|
||||
SetSkew(Vec2{ skewx, skewy });
|
||||
}
|
||||
);
|
||||
|
||||
// 设置旋转角度
|
||||
// 默认为 0
|
||||
|
|
@ -247,13 +235,10 @@ namespace kiwano
|
|||
|
||||
// 设置锚点位置
|
||||
// 默认为 (0, 0), 范围 [0, 1]
|
||||
inline void SetAnchor(
|
||||
void SetAnchor(
|
||||
float anchorx,
|
||||
float anchory
|
||||
)
|
||||
{
|
||||
SetAnchor(Vec2{ anchorx, anchory });
|
||||
}
|
||||
);
|
||||
|
||||
// 修改宽度
|
||||
virtual void SetWidth(
|
||||
|
|
@ -271,13 +256,10 @@ namespace kiwano
|
|||
);
|
||||
|
||||
// 修改大小
|
||||
inline void SetSize(
|
||||
void SetSize(
|
||||
float width,
|
||||
float height
|
||||
)
|
||||
{
|
||||
SetSize(Size{ width, height });
|
||||
}
|
||||
);
|
||||
|
||||
// 设置透明度
|
||||
// 默认为 1.0, 范围 [0, 1]
|
||||
|
|
@ -364,6 +346,24 @@ namespace kiwano
|
|||
// 判断点是否在角色内
|
||||
virtual bool ContainsPoint(const Point& point) const;
|
||||
|
||||
// 暂停角色更新
|
||||
void PauseUpdating();
|
||||
|
||||
// 继续角色更新
|
||||
void ResumeUpdating();
|
||||
|
||||
// 角色更新是否暂停
|
||||
bool IsUpdatePausing() const;
|
||||
|
||||
// 设置更新时的回调函数
|
||||
void SetCallbackOnUpdate(UpdateCallback const& cb);
|
||||
|
||||
// 获取更新时的回调函数
|
||||
UpdateCallback GetCallbackOnUpdate() const;
|
||||
|
||||
// 渲染角色边界
|
||||
void ShowBorder(bool show);
|
||||
|
||||
// 事件分发
|
||||
void Dispatch(Event& evt) override;
|
||||
|
||||
|
|
@ -373,24 +373,6 @@ namespace kiwano
|
|||
float anchor_y
|
||||
);
|
||||
|
||||
// 暂停角色更新
|
||||
inline void PauseUpdating() { update_pausing_ = true; }
|
||||
|
||||
// 继续角色更新
|
||||
inline void ResumeUpdating() { update_pausing_ = false; }
|
||||
|
||||
// 角色更新是否暂停
|
||||
inline bool IsUpdatePausing() const { return update_pausing_; }
|
||||
|
||||
// 设置更新时的回调函数
|
||||
inline void SetCallbackOnUpdate(UpdateCallback const& cb) { cb_update_ = cb; }
|
||||
|
||||
// 获取更新时的回调函数
|
||||
inline UpdateCallback GetCallbackOnUpdate() const { return cb_update_; }
|
||||
|
||||
// 渲染角色边界
|
||||
inline void ShowBorder(bool show) { show_border_ = show; }
|
||||
|
||||
protected:
|
||||
virtual void Update(Duration dt);
|
||||
|
||||
|
|
@ -439,4 +421,219 @@ namespace kiwano
|
|||
mutable Matrix3x2 transform_matrix_inverse_;
|
||||
};
|
||||
|
||||
inline void Actor::OnUpdate(Duration dt)
|
||||
{
|
||||
KGE_NOT_USED(dt);
|
||||
}
|
||||
|
||||
inline void Actor::OnRender(RenderTarget* rt)
|
||||
{
|
||||
KGE_NOT_USED(rt);
|
||||
}
|
||||
|
||||
inline bool Actor::IsVisible() const
|
||||
{
|
||||
return visible_;
|
||||
}
|
||||
|
||||
inline bool Actor::IsResponsible() const
|
||||
{
|
||||
return responsible_;
|
||||
}
|
||||
|
||||
inline bool Actor::IsCascadeOpacityEnabled() const
|
||||
{
|
||||
return cascade_opacity_;
|
||||
}
|
||||
|
||||
inline size_t Actor::GetHashName() const
|
||||
{
|
||||
return hash_name_;
|
||||
}
|
||||
|
||||
inline int Actor::GetZOrder() const
|
||||
{
|
||||
return z_order_;
|
||||
}
|
||||
|
||||
inline Point const& Actor::GetPosition() const
|
||||
{
|
||||
return transform_.position;
|
||||
}
|
||||
|
||||
inline float Actor::GetPositionX() const
|
||||
{
|
||||
return GetPosition().x;
|
||||
}
|
||||
|
||||
inline float Actor::GetPositionY() const
|
||||
{
|
||||
return GetPosition().y;
|
||||
}
|
||||
|
||||
inline Point const& Actor::GetScale() const
|
||||
{
|
||||
return transform_.scale;
|
||||
}
|
||||
|
||||
inline float Actor::GetScaleX() const
|
||||
{
|
||||
return GetScale().x;
|
||||
}
|
||||
|
||||
inline float Actor::GetScaleY() const
|
||||
{
|
||||
return GetScale().y;
|
||||
}
|
||||
|
||||
inline Point const& Actor::GetSkew() const
|
||||
{
|
||||
return transform_.skew;
|
||||
}
|
||||
|
||||
inline float Actor::GetSkewX() const
|
||||
{
|
||||
return GetSkew().x;
|
||||
}
|
||||
|
||||
inline float Actor::GetSkewY() const
|
||||
{
|
||||
return GetSkew().y;
|
||||
}
|
||||
|
||||
inline float Actor::GetRotation() const
|
||||
{
|
||||
return transform_.rotation;
|
||||
}
|
||||
|
||||
inline float Actor::GetWidth() const
|
||||
{
|
||||
return GetSize().x;
|
||||
}
|
||||
|
||||
inline float Actor::GetHeight() const
|
||||
{
|
||||
return GetSize().y;
|
||||
}
|
||||
|
||||
inline Size const& Actor::GetSize() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
inline float Actor::GetScaledWidth() const
|
||||
{
|
||||
return GetWidth() * GetScaleX();
|
||||
}
|
||||
|
||||
inline float Actor::GetScaledHeight() const
|
||||
{
|
||||
return GetHeight() * GetScaleY();
|
||||
}
|
||||
|
||||
inline Size Actor::GetScaledSize() const
|
||||
{
|
||||
return Size{ GetScaledWidth(), GetScaledHeight() };
|
||||
}
|
||||
|
||||
inline Point const& Actor::GetAnchor() const
|
||||
{
|
||||
return anchor_;
|
||||
}
|
||||
|
||||
inline float Actor::GetAnchorX() const
|
||||
{
|
||||
return GetAnchor().x;
|
||||
}
|
||||
|
||||
inline float Actor::GetAnchorY() const
|
||||
{
|
||||
return GetAnchor().y;
|
||||
}
|
||||
|
||||
inline float Actor::GetOpacity() const
|
||||
{
|
||||
return opacity_;
|
||||
}
|
||||
|
||||
inline float Actor::GetDisplayedOpacity() const
|
||||
{
|
||||
return displayed_opacity_;
|
||||
}
|
||||
|
||||
inline Transform Actor::GetTransform() const
|
||||
{
|
||||
return transform_;
|
||||
}
|
||||
|
||||
inline Actor* Actor::GetParent() const
|
||||
{
|
||||
return parent_;
|
||||
}
|
||||
|
||||
inline Stage* Actor::GetStage() const
|
||||
{
|
||||
return stage_;
|
||||
}
|
||||
|
||||
inline void Actor::PauseUpdating()
|
||||
{
|
||||
update_pausing_ = true;
|
||||
}
|
||||
|
||||
inline void Actor::ResumeUpdating()
|
||||
{
|
||||
update_pausing_ = false;
|
||||
}
|
||||
|
||||
inline bool Actor::IsUpdatePausing() const
|
||||
{
|
||||
return update_pausing_;
|
||||
}
|
||||
|
||||
inline void Actor::SetCallbackOnUpdate(UpdateCallback const& cb)
|
||||
{
|
||||
cb_update_ = cb;
|
||||
}
|
||||
|
||||
inline Actor::UpdateCallback Actor::GetCallbackOnUpdate() const
|
||||
{
|
||||
return cb_update_;
|
||||
}
|
||||
|
||||
inline void Actor::ShowBorder(bool show)
|
||||
{
|
||||
show_border_ = show;
|
||||
}
|
||||
|
||||
inline void Actor::SetPosition(float x, float y)
|
||||
{
|
||||
SetPosition(Point{ x, y });
|
||||
}
|
||||
|
||||
inline void Actor::Move(float vx, float vy)
|
||||
{
|
||||
Move(Vec2{ vx, vy });
|
||||
}
|
||||
|
||||
inline void Actor::SetScale(float scalex, float scaley)
|
||||
{
|
||||
SetScale(Vec2{ scalex, scaley });
|
||||
}
|
||||
|
||||
inline void Actor::SetAnchor(float anchorx, float anchory)
|
||||
{
|
||||
SetAnchor(Vec2{ anchorx, anchory });
|
||||
}
|
||||
|
||||
inline void Actor::SetSize(float width, float height)
|
||||
{
|
||||
SetSize(Size{ width, height });
|
||||
}
|
||||
|
||||
inline void Actor::SetSkew(float skewx, float skewy)
|
||||
{
|
||||
SetSkew(Vec2{ skewx, skewy });
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,42 +36,33 @@ namespace kiwano
|
|||
friend IntrusiveList<ActionPtr>;
|
||||
|
||||
public:
|
||||
enum class Status
|
||||
{
|
||||
NotStarted,
|
||||
Delayed,
|
||||
Started,
|
||||
Done,
|
||||
Removeable
|
||||
};
|
||||
|
||||
Action();
|
||||
|
||||
virtual ~Action();
|
||||
|
||||
// 继续动作
|
||||
inline void Resume() { running_ = true; }
|
||||
void Resume();
|
||||
|
||||
// 暂停动作
|
||||
inline void Pause() { running_ = false; }
|
||||
void Pause();
|
||||
|
||||
// 停止动作
|
||||
inline void Stop() { status_ = Status::Removeable; }
|
||||
void Stop();
|
||||
|
||||
// 设置动作延时
|
||||
inline void SetDelay(Duration delay) { delay_ = delay; }
|
||||
void SetDelay(Duration delay);
|
||||
|
||||
// 设置循环次数 (-1 为永久循环)
|
||||
inline void SetLoops(int loops) { loops_ = loops; }
|
||||
void SetLoops(int loops);
|
||||
|
||||
// 动作结束时移除目标角色
|
||||
inline void RemoveTargetWhenDone() { detach_target_ = true; }
|
||||
void RemoveTargetWhenDone();
|
||||
|
||||
// 设置动作结束时的回调函数
|
||||
inline void SetDoneCallback(ActionCallback const& cb) { cb_done_ = cb; }
|
||||
void SetDoneCallback(ActionCallback const& cb);
|
||||
|
||||
// 设置动作循环结束时的回调函数
|
||||
inline void SetLoopDoneCallback(ActionCallback const& cb) { cb_loop_done_ = cb; }
|
||||
void SetLoopDoneCallback(ActionCallback const& cb);
|
||||
|
||||
// 获取动作的拷贝
|
||||
virtual ActionPtr Clone() const = 0;
|
||||
|
|
@ -79,25 +70,15 @@ namespace kiwano
|
|||
// 获取动作的倒转
|
||||
virtual ActionPtr Reverse() const = 0;
|
||||
|
||||
inline void Done() { status_ = Status::Done; }
|
||||
bool IsRunning() const;
|
||||
|
||||
inline Status GetStatus() const { return status_; }
|
||||
int GetLoops() const;
|
||||
|
||||
inline bool IsRunning() const { return running_; }
|
||||
Duration GetDelay() const;
|
||||
|
||||
inline bool IsDone() const { return status_ == Status::Done || status_ == Status::Removeable; }
|
||||
ActionCallback GetDoneCallback() const;
|
||||
|
||||
inline bool IsRemoveable() const { return status_ == Status::Removeable; }
|
||||
|
||||
inline int GetLoops() const { return loops_; }
|
||||
|
||||
inline Duration GetDelay() const { return delay_; }
|
||||
|
||||
inline Duration GetElapsed() const { return elapsed_; }
|
||||
|
||||
inline ActionCallback GetDoneCallback() const { return cb_done_; }
|
||||
|
||||
inline ActionCallback GetLoopDoneCallback() const { return cb_loop_done_; }
|
||||
ActionCallback GetLoopDoneCallback() const;
|
||||
|
||||
protected:
|
||||
virtual void Init(ActorPtr target);
|
||||
|
|
@ -110,7 +91,28 @@ namespace kiwano
|
|||
|
||||
void Restart(ActorPtr target);
|
||||
|
||||
protected:
|
||||
enum class Status
|
||||
{
|
||||
NotStarted,
|
||||
Delayed,
|
||||
Started,
|
||||
Done,
|
||||
Removeable
|
||||
};
|
||||
|
||||
Status GetStatus() const;
|
||||
|
||||
Duration GetElapsed() const;
|
||||
|
||||
int GetLoopsDone() const;
|
||||
|
||||
void Done();
|
||||
|
||||
bool IsDone() const;
|
||||
|
||||
bool IsRemoveable() const;
|
||||
|
||||
private:
|
||||
Status status_;
|
||||
bool running_;
|
||||
bool detach_target_;
|
||||
|
|
@ -121,4 +123,100 @@ namespace kiwano
|
|||
ActionCallback cb_done_;
|
||||
ActionCallback cb_loop_done_;
|
||||
};
|
||||
|
||||
|
||||
inline void Action::Resume()
|
||||
{
|
||||
running_ = true;
|
||||
}
|
||||
|
||||
inline void Action::Pause()
|
||||
{
|
||||
running_ = false;
|
||||
}
|
||||
|
||||
inline void Action::Stop()
|
||||
{
|
||||
Done();
|
||||
}
|
||||
|
||||
inline void Action::SetDelay(Duration delay)
|
||||
{
|
||||
delay_ = delay;
|
||||
}
|
||||
|
||||
inline void Action::SetLoops(int loops)
|
||||
{
|
||||
loops_ = loops;
|
||||
}
|
||||
|
||||
inline void Action::RemoveTargetWhenDone()
|
||||
{
|
||||
detach_target_ = true;
|
||||
}
|
||||
|
||||
inline void Action::SetDoneCallback(ActionCallback const& cb)
|
||||
{
|
||||
cb_done_ = cb;
|
||||
}
|
||||
|
||||
inline void Action::SetLoopDoneCallback(ActionCallback const& cb)
|
||||
{
|
||||
cb_loop_done_ = cb;
|
||||
}
|
||||
|
||||
inline void Action::Done()
|
||||
{
|
||||
status_ = Status::Done;
|
||||
}
|
||||
|
||||
inline Action::Status Action::GetStatus() const
|
||||
{
|
||||
return status_;
|
||||
}
|
||||
|
||||
inline bool Action::IsRunning() const
|
||||
{
|
||||
return running_;
|
||||
}
|
||||
|
||||
inline bool Action::IsDone() const
|
||||
{
|
||||
return status_ == Status::Done || status_ == Status::Removeable;
|
||||
}
|
||||
|
||||
inline bool Action::IsRemoveable() const
|
||||
{
|
||||
return status_ == Status::Removeable;
|
||||
}
|
||||
|
||||
inline int Action::GetLoops() const
|
||||
{
|
||||
return loops_;
|
||||
}
|
||||
|
||||
inline Duration Action::GetDelay() const
|
||||
{
|
||||
return delay_;
|
||||
}
|
||||
|
||||
inline Duration Action::GetElapsed() const
|
||||
{
|
||||
return elapsed_;
|
||||
}
|
||||
|
||||
inline int Action::GetLoopsDone() const
|
||||
{
|
||||
return loops_done_;
|
||||
}
|
||||
|
||||
inline ActionCallback Action::GetDoneCallback() const
|
||||
{
|
||||
return cb_done_;
|
||||
}
|
||||
|
||||
inline ActionCallback Action::GetLoopDoneCallback() const
|
||||
{
|
||||
return cb_loop_done_;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,12 +29,12 @@ namespace kiwano
|
|||
|
||||
ActionPtr ActionDelay::Clone() const
|
||||
{
|
||||
return new ActionDelay(delay_);
|
||||
return new ActionDelay(GetDelay());
|
||||
}
|
||||
|
||||
ActionPtr ActionDelay::Reverse() const
|
||||
{
|
||||
return new ActionDelay(delay_);
|
||||
return new ActionDelay(GetDelay());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,15 +108,15 @@ namespace kiwano
|
|||
}
|
||||
else
|
||||
{
|
||||
Duration elapsed = elapsed_ - delay_;
|
||||
Duration elapsed = GetElapsed() - GetDelay();
|
||||
float loops_done = elapsed / dur_;
|
||||
|
||||
while (loops_done_ < static_cast<int>(loops_done))
|
||||
while (GetLoopsDone() < static_cast<int>(loops_done))
|
||||
{
|
||||
Complete(target); // loops_done_++
|
||||
}
|
||||
|
||||
percent = (status_ == Status::Done) ? 1.f : (loops_done - static_cast<float>(loops_done_));
|
||||
percent = (GetStatus() == Status::Done) ? 1.f : (loops_done - static_cast<float>(GetLoopsDone()));
|
||||
}
|
||||
|
||||
if (ease_func_)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
// Copyright (c) 2016-2018 Kiwano - 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 <kiwano/base/Library.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
||||
Library::Library()
|
||||
: instance_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
Library::Library(String const& lib)
|
||||
: instance_(nullptr)
|
||||
{
|
||||
Load(lib);
|
||||
}
|
||||
|
||||
Library::~Library()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
bool Library::Load(String const& lib)
|
||||
{
|
||||
instance_ = ::LoadLibraryW(lib.c_str());
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
bool Library::IsValid() const
|
||||
{
|
||||
return instance_ != nullptr;
|
||||
}
|
||||
|
||||
void Library::Free()
|
||||
{
|
||||
if (instance_)
|
||||
{
|
||||
::FreeLibrary(instance_);
|
||||
instance_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
FARPROC Library::GetProcess(String const& proc_name)
|
||||
{
|
||||
KGE_ASSERT(instance_ != nullptr);
|
||||
return GetProcAddress(instance_, wide_to_string(proc_name).c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
// Copyright (c) 2016-2018 Kiwano - Nomango
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/macros.h>
|
||||
#include <kiwano/base/time.h>
|
||||
#include <kiwano/base/Event.hpp>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
// DLL ¿â
|
||||
class KGE_API Library
|
||||
{
|
||||
public:
|
||||
Library();
|
||||
Library(String const& lib);
|
||||
virtual ~Library();
|
||||
|
||||
bool Load(String const& lib);
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
void Free();
|
||||
|
||||
FARPROC GetProcess(String const& proc_name);
|
||||
|
||||
template <typename _Proc>
|
||||
inline _Proc GetProcess(String const& proc_name)
|
||||
{
|
||||
return reinterpret_cast<_Proc>(GetProcess(proc_name));
|
||||
}
|
||||
|
||||
private:
|
||||
HMODULE instance_;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -26,18 +26,14 @@ namespace kiwano
|
|||
namespace modules
|
||||
{
|
||||
Shlwapi::Shlwapi()
|
||||
: shlwapi(nullptr)
|
||||
: shlwapi()
|
||||
, PathFileExistsW(nullptr)
|
||||
, SHCreateMemStream(nullptr)
|
||||
{
|
||||
shlwapi = LoadLibraryW(L"shlwapi.dll");
|
||||
if (shlwapi)
|
||||
if (shlwapi.Load(L"shlwapi.dll"))
|
||||
{
|
||||
PathFileExistsW = (PFN_PathFileExistsW)
|
||||
GetProcAddress(shlwapi, "PathFileExistsW");
|
||||
|
||||
SHCreateMemStream = (PFN_SHCreateMemStream)
|
||||
GetProcAddress(shlwapi, "SHCreateMemStream");
|
||||
PathFileExistsW = shlwapi.GetProcess<PFN_PathFileExistsW>(L"PathFileExistsW");
|
||||
SHCreateMemStream = shlwapi.GetProcess<PFN_SHCreateMemStream>(L"SHCreateMemStream");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,10 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
#include <kiwano/macros.h>
|
||||
#include <xaudio2.h>
|
||||
#include <mfapi.h>
|
||||
#include <mfidl.h>
|
||||
#include <mfreadwrite.h>
|
||||
#include <kiwano/base/Library.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -31,14 +28,6 @@ namespace kiwano
|
|||
{
|
||||
class KGE_API Shlwapi
|
||||
{
|
||||
Shlwapi();
|
||||
|
||||
HMODULE shlwapi;
|
||||
|
||||
// Shlwapi functions
|
||||
typedef BOOL(WINAPI *PFN_PathFileExistsW)(LPCWSTR);
|
||||
typedef IStream*(WINAPI *PFN_SHCreateMemStream)(const BYTE*, UINT);
|
||||
|
||||
public:
|
||||
static inline Shlwapi& Get()
|
||||
{
|
||||
|
|
@ -46,8 +35,20 @@ namespace kiwano
|
|||
return instance;
|
||||
}
|
||||
|
||||
// Shlwapi functions
|
||||
typedef BOOL(WINAPI* PFN_PathFileExistsW)(LPCWSTR);
|
||||
typedef IStream* (WINAPI* PFN_SHCreateMemStream)(const BYTE*, UINT);
|
||||
|
||||
PFN_PathFileExistsW PathFileExistsW;
|
||||
PFN_SHCreateMemStream SHCreateMemStream;
|
||||
|
||||
private:
|
||||
Shlwapi();
|
||||
|
||||
Shlwapi(const Shlwapi&) = delete;
|
||||
Shlwapi& operator=(const Shlwapi&) = delete;
|
||||
|
||||
Library shlwapi;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue