Update FrameSequence
This commit is contained in:
parent
08a50ca474
commit
1bf197d351
|
|
@ -3,9 +3,9 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiLayer.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiLayer.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiModule.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiModule.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl_dx10.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx10.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl_dx11.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx11.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\kiwano-imgui.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\kiwano-imgui.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Label="ProjectConfigurations">
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
|
@ -21,8 +21,8 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiLayer.cpp" />
|
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiLayer.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiModule.cpp" />
|
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiModule.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl_dx10.cpp" />
|
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx10.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl_dx11.cpp" />
|
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx11.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{A7062ED8-8910-48A5-A3BC-C1612672571F}</ProjectGuid>
|
<ProjectGuid>{A7062ED8-8910-48A5-A3BC-C1612672571F}</ProjectGuid>
|
||||||
|
|
@ -112,4 +112,4 @@
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -2,16 +2,31 @@
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\kiwano-imgui.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\kiwano-imgui.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl.h" />
|
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl_dx10.h" />
|
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl_dx11.h" />
|
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiLayer.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiLayer.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiModule.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiModule.h" />
|
||||||
|
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl.h">
|
||||||
|
<Filter>imgui_impl</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx10.h">
|
||||||
|
<Filter>imgui_impl</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx11.h">
|
||||||
|
<Filter>imgui_impl</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl_dx10.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl_dx11.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiLayer.cpp" />
|
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiLayer.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiModule.cpp" />
|
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiModule.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx10.cpp">
|
||||||
|
<Filter>imgui_impl</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx11.cpp">
|
||||||
|
<Filter>imgui_impl</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="imgui_impl">
|
||||||
|
<UniqueIdentifier>{a11036bf-f334-4e51-aef2-15dd46be924d}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#include <kiwano/platform/win32/WindowImpl.h>
|
#include <kiwano/platform/win32/WindowImpl.h>
|
||||||
#include <kiwano/render/Renderer.h>
|
#include <kiwano/render/Renderer.h>
|
||||||
#include <kiwano-imgui/ImGuiModule.h>
|
#include <kiwano-imgui/ImGuiModule.h>
|
||||||
#include <kiwano-imgui/imgui_impl.h>
|
#include <kiwano-imgui/imgui_impl/imgui_impl.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#if !defined(KGE_USE_DIRECTX10)
|
#if !defined(KGE_USE_DIRECTX10)
|
||||||
|
|
||||||
#include <kiwano-imgui/imgui_impl_dx11.h>
|
#include <kiwano-imgui/imgui_impl/imgui_impl_dx11.h>
|
||||||
#include <kiwano/render/DirectX/RendererImpl.h>
|
#include <kiwano/render/DirectX/RendererImpl.h>
|
||||||
|
|
||||||
inline bool ImGui_Impl_Init()
|
inline bool ImGui_Impl_Init()
|
||||||
|
|
@ -43,7 +43,7 @@ inline bool ImGui_Impl_CreateDeviceObjects()
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <kiwano-imgui/imgui_impl_dx10.h>
|
#include <kiwano-imgui/imgui_impl/imgui_impl_dx10.h>
|
||||||
|
|
||||||
inline bool ImGui_Impl_Init()
|
inline bool ImGui_Impl_Init()
|
||||||
{
|
{
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// dear imgui: Renderer for Kiwano (DirectX10)
|
// dear imgui: Renderer for Kiwano (DirectX10)
|
||||||
|
|
||||||
#include <kiwano-imgui/imgui_impl_dx10.h>
|
#include <kiwano-imgui/imgui_impl/imgui_impl_dx10.h>
|
||||||
|
|
||||||
// DirectX
|
// DirectX
|
||||||
#include <d3d10_1.h>
|
#include <d3d10_1.h>
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// dear imgui: Renderer for Kiwano (DirectX11)
|
// dear imgui: Renderer for Kiwano (DirectX11)
|
||||||
|
|
||||||
#include <kiwano-imgui/imgui_impl_dx11.h>
|
#include <kiwano-imgui/imgui_impl/imgui_impl_dx11.h>
|
||||||
|
|
||||||
// DirectX
|
// DirectX
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
|
|
@ -24,6 +24,12 @@
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
||||||
|
FrameSequencePtr FrameSequence::Create()
|
||||||
|
{
|
||||||
|
FrameSequencePtr ptr = new (std::nothrow) FrameSequence;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
FrameSequencePtr FrameSequence::Create(Vector<FramePtr> const& frames)
|
FrameSequencePtr FrameSequence::Create(Vector<FramePtr> const& frames)
|
||||||
{
|
{
|
||||||
FrameSequencePtr ptr = new (std::nothrow) FrameSequence;
|
FrameSequencePtr ptr = new (std::nothrow) FrameSequence;
|
||||||
|
|
@ -34,6 +40,17 @@ FrameSequencePtr FrameSequence::Create(Vector<FramePtr> const& frames)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FrameSequencePtr FrameSequence::Create(FramePtr frame, int cols, int rows, int max_num, float padding_x,
|
||||||
|
float padding_y)
|
||||||
|
{
|
||||||
|
FrameSequencePtr ptr = new (std::nothrow) FrameSequence;
|
||||||
|
if (ptr)
|
||||||
|
{
|
||||||
|
ptr->AddFrames(frame, cols, rows, max_num, padding_x, padding_y);
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
FrameSequence::FrameSequence() {}
|
FrameSequence::FrameSequence() {}
|
||||||
|
|
||||||
FrameSequence::~FrameSequence() {}
|
FrameSequence::~FrameSequence() {}
|
||||||
|
|
@ -60,6 +77,51 @@ void FrameSequence::AddFrames(Vector<FramePtr> const& frames)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FrameSequence::AddFrames(FramePtr frame, int cols, int rows, int max_num, float padding_x, float padding_y)
|
||||||
|
{
|
||||||
|
if (cols <= 0 || rows <= 0 || max_num == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!frame)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Rect src_rect = frame->GetCropRect();
|
||||||
|
float raw_width = src_rect.GetWidth();
|
||||||
|
float raw_height = src_rect.GetHeight();
|
||||||
|
float width = (raw_width - (cols - 1) * padding_x) / cols;
|
||||||
|
float height = (raw_height - (rows - 1) * padding_y) / rows;
|
||||||
|
|
||||||
|
Vector<FramePtr> frames;
|
||||||
|
frames.reserve((max_num > 0) ? max_num : (rows * cols));
|
||||||
|
|
||||||
|
int current_num = 0;
|
||||||
|
|
||||||
|
float dty = src_rect.GetTop();
|
||||||
|
for (int i = 0; i < rows; i++)
|
||||||
|
{
|
||||||
|
float dtx = src_rect.GetLeft();
|
||||||
|
|
||||||
|
for (int j = 0; j < cols; j++)
|
||||||
|
{
|
||||||
|
FramePtr ptr = new (std::nothrow) Frame;
|
||||||
|
if (ptr)
|
||||||
|
{
|
||||||
|
ptr->SetTexture(frame->GetTexture());
|
||||||
|
ptr->SetCropRect(Rect{ dtx, dty, dtx + width, dty + height });
|
||||||
|
frames.push_back(ptr);
|
||||||
|
++current_num;
|
||||||
|
}
|
||||||
|
dtx += (width + padding_x);
|
||||||
|
}
|
||||||
|
dty += (height + padding_y);
|
||||||
|
|
||||||
|
if (max_num > 0 && current_num == max_num)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
AddFrames(frames);
|
||||||
|
}
|
||||||
|
|
||||||
FramePtr FrameSequence::GetFrame(size_t index) const
|
FramePtr FrameSequence::GetFrame(size_t index) const
|
||||||
{
|
{
|
||||||
KGE_ASSERT(index < frames_.size());
|
KGE_ASSERT(index < frames_.size());
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,26 @@ KGE_DECLARE_SMART_PTR(FrameSequence);
|
||||||
class KGE_API FrameSequence : public virtual ObjectBase
|
class KGE_API FrameSequence : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 创建序列帧
|
||||||
|
static FrameSequencePtr Create();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建序列帧
|
/// @brief 创建序列帧
|
||||||
/// @param frames 图像帧集合
|
/// @param frames 图像帧集合
|
||||||
static FrameSequencePtr Create(Vector<FramePtr> const& frames);
|
static FrameSequencePtr Create(Vector<FramePtr> const& frames);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 按行列分割图像并创建序列帧
|
||||||
|
/// @param frame 图像帧
|
||||||
|
/// @param cols 列数
|
||||||
|
/// @param rows 行数
|
||||||
|
/// @param max_num 最大帧数量,设-1为将分割后的图像全部作为序列帧
|
||||||
|
/// @param padding_x X方向间隔
|
||||||
|
/// @param padding_y Y方向间隔
|
||||||
|
static FrameSequencePtr Create(FramePtr frame, int cols, int rows = 1, int max_num = -1, float padding_x = 0,
|
||||||
|
float padding_y = 0);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构建空序列帧
|
/// @brief 构建空序列帧
|
||||||
FrameSequence();
|
FrameSequence();
|
||||||
|
|
@ -55,6 +70,16 @@ public:
|
||||||
/// @param frames 图像帧集合
|
/// @param frames 图像帧集合
|
||||||
void AddFrames(Vector<FramePtr> const& frames);
|
void AddFrames(Vector<FramePtr> const& frames);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 按行列分割图像并添加序列帧
|
||||||
|
/// @param frame 图像帧
|
||||||
|
/// @param cols 列数
|
||||||
|
/// @param rows 行数
|
||||||
|
/// @param max_num 最大帧数量,设-1为将分割后的图像全部作为序列帧
|
||||||
|
/// @param padding_x X方向间隔
|
||||||
|
/// @param padding_y Y方向间隔
|
||||||
|
void AddFrames(FramePtr frame, int cols, int rows = 1, int max_num = -1, float padding_x = 0, float padding_y = 0);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关键帧
|
/// @brief 获取关键帧
|
||||||
/// @param index 图像帧下标
|
/// @param index 图像帧下标
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue