[deploy] Merge pull request #49 from KiwanoEngine/dev
Change source charset to utf-8 & add exceptions
This commit is contained in:
commit
64319fb996
|
|
@ -11,7 +11,7 @@ insert_final_newline = true
|
|||
# Matches multiple files with brace expansion notation
|
||||
# Set default charset
|
||||
[*.{h,hpp,cpp}]
|
||||
charset = gb2312
|
||||
charset = utf8
|
||||
|
||||
# 4 space indentation
|
||||
indent_style = space
|
||||
|
|
|
|||
2
Doxyfile
2
Doxyfile
|
|
@ -32,7 +32,7 @@ SHOW_NAMESPACES = YES
|
|||
#---------------------------------------------------------------------------
|
||||
|
||||
INPUT = src/
|
||||
INPUT_ENCODING = gb2312
|
||||
INPUT_ENCODING = UTF-8
|
||||
FILE_PATTERNS = *.c \
|
||||
*.cc \
|
||||
*.cxx \
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@
|
|||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
|
@ -92,6 +93,7 @@
|
|||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@
|
|||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
|
@ -91,6 +92,7 @@
|
|||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@
|
|||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
|
@ -87,6 +88,7 @@
|
|||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@
|
|||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
|
@ -97,6 +98,7 @@
|
|||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
<ClInclude Include="..\..\src\kiwano\core\event\KeyEvent.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\event\MouseEvent.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\event\WindowEvent.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\Exception.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\Keys.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\Library.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\Singleton.h" />
|
||||
|
|
@ -30,7 +31,7 @@
|
|||
<ClInclude Include="..\..\src\kiwano\2d\DebugActor.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\2d\FrameSequence.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\2d\ShapeActor.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\2d\Layer.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\2d\LayerActor.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\2d\Actor.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\2d\Stage.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\2d\Sprite.h" />
|
||||
|
|
@ -62,6 +63,7 @@
|
|||
<ClInclude Include="..\..\src\kiwano\platform\win32\ComPtr.hpp" />
|
||||
<ClInclude Include="..\..\src\kiwano\platform\win32\helper.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\platform\win32\libraries.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\platform\win32\WindowImpl.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\platform\Window.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\Brush.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\Color.h" />
|
||||
|
|
@ -71,12 +73,15 @@
|
|||
<ClInclude Include="..\..\src\kiwano\render\DirectX\D3DDeviceResourcesBase.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\FontCollectionLoader.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\helper.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\RenderContextImpl.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\RendererImpl.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\TextRenderer.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\TextureRenderContextImpl.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\Font.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\Shape.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\ShapeSink.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\GifImage.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\LayerArea.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\Layer.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\RenderContext.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\Renderer.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\StrokeStyle.h" />
|
||||
|
|
@ -84,6 +89,7 @@
|
|||
<ClInclude Include="..\..\src\kiwano\render\TextStyle.hpp" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\Texture.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\TextureCache.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\TextureRenderContext.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\utils\LocalStorage.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\utils\ResourceCache.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\utils\UserData.h" />
|
||||
|
|
@ -103,7 +109,7 @@
|
|||
<ClCompile Include="..\..\src\kiwano\2d\FrameSequence.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\2d\ShapeActor.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\2d\GifSprite.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\2d\Layer.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\2d\LayerActor.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\2d\Actor.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\2d\Stage.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\2d\Sprite.cpp" />
|
||||
|
|
@ -118,6 +124,7 @@
|
|||
<ClCompile Include="..\..\src\kiwano\core\event\KeyEvent.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\core\event\MouseEvent.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\core\event\WindowEvent.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\core\Exception.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\core\Library.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\core\Logger.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\core\ObjectBase.cpp" />
|
||||
|
|
@ -139,18 +146,22 @@
|
|||
<ClCompile Include="..\..\src\kiwano\render\DirectX\D3D10DeviceResources.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\D3D11DeviceResources.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\FontCollectionLoader.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\RenderContextImpl.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\RendererImpl.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\TextRenderer.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\TextureRenderContextImpl.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\Font.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\Shape.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\ShapeSink.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\GifImage.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\LayerArea.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\Layer.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\RenderContext.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\Renderer.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\StrokeStyle.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\TextLayout.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\Texture.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\TextureCache.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\TextureRenderContext.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\utils\LocalStorage.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\utils\ResourceCache.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\utils\UserData.cpp" />
|
||||
|
|
@ -212,6 +223,7 @@
|
|||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
|
@ -230,6 +242,7 @@
|
|||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
|
|
|||
|
|
@ -36,9 +36,6 @@
|
|||
<ClInclude Include="..\..\src\kiwano\2d\Canvas.h">
|
||||
<Filter>2d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\2d\Layer.h">
|
||||
<Filter>2d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\2d\Sprite.h">
|
||||
<Filter>2d</Filter>
|
||||
</ClInclude>
|
||||
|
|
@ -216,9 +213,6 @@
|
|||
<ClInclude Include="..\..\src\kiwano\render\GifImage.h">
|
||||
<Filter>render</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\LayerArea.h">
|
||||
<Filter>render</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\RenderContext.h">
|
||||
<Filter>render</Filter>
|
||||
</ClInclude>
|
||||
|
|
@ -285,14 +279,35 @@
|
|||
<ClInclude Include="..\..\src\kiwano\math\Scalar.h">
|
||||
<Filter>math</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\TextureRenderContext.h">
|
||||
<Filter>render</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\RenderContextImpl.h">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\TextureRenderContextImpl.h">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\RendererImpl.h">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\platform\win32\WindowImpl.h">
|
||||
<Filter>platform\win32</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\core\Exception.h">
|
||||
<Filter>core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\2d\LayerActor.h">
|
||||
<Filter>2d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\Layer.h">
|
||||
<Filter>render</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp">
|
||||
<Filter>2d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\2d\Layer.cpp">
|
||||
<Filter>2d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\2d\Sprite.cpp">
|
||||
<Filter>2d</Filter>
|
||||
</ClCompile>
|
||||
|
|
@ -440,9 +455,6 @@
|
|||
<ClCompile Include="..\..\src\kiwano\render\GifImage.cpp">
|
||||
<Filter>render</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\LayerArea.cpp">
|
||||
<Filter>render</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\RenderContext.cpp">
|
||||
<Filter>render</Filter>
|
||||
</ClCompile>
|
||||
|
|
@ -482,5 +494,26 @@
|
|||
<ClCompile Include="..\..\src\kiwano\render\ShapeSink.cpp">
|
||||
<Filter>render</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\TextureRenderContext.cpp">
|
||||
<Filter>render</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\RenderContextImpl.cpp">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\TextureRenderContextImpl.cpp">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\RendererImpl.cpp">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\core\Exception.cpp">
|
||||
<Filter>core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\2d\LayerActor.cpp">
|
||||
<Filter>2d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\Layer.cpp">
|
||||
<Filter>render</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -93,11 +93,11 @@ struct json_lexer
|
|||
break;
|
||||
|
||||
case 't':
|
||||
return scan_literal(L"true", token_type::LITERAL_TRUE);
|
||||
return scan_literal("true", token_type::LITERAL_TRUE);
|
||||
case 'f':
|
||||
return scan_literal(L"false", token_type::LITERAL_FALSE);
|
||||
return scan_literal("false", token_type::LITERAL_FALSE);
|
||||
case 'n':
|
||||
return scan_literal(L"null", token_type::LITERAL_NULL);
|
||||
return scan_literal("null", token_type::LITERAL_NULL);
|
||||
|
||||
case '\"':
|
||||
return scan_string();
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class vector
|
|||
public:
|
||||
using value_type = _Ty;
|
||||
using size_type = size_t;
|
||||
using difference_type = ptrdiff_t;
|
||||
using reference = value_type&;
|
||||
using const_reference = const value_type&;
|
||||
using iterator = value_type*;
|
||||
|
|
@ -70,6 +71,7 @@ public:
|
|||
inline bool empty() const { return size_ == 0; }
|
||||
inline size_type size() const { return size_; }
|
||||
inline size_type size_in_bytes() const { return size_ * ((size_type)sizeof(_Ty)); }
|
||||
inline size_type max_size() const { return std::numeric_limits<difference_type>::max(); }
|
||||
inline size_type capacity() const { return capacity_; }
|
||||
inline reference operator[](size_type off) { if (off < 0 || off >= size_) throw std::out_of_range("vector subscript out of range"); return data_[off]; }
|
||||
inline const_reference operator[](size_type off) const { if (off < 0 || off >= size_) throw std::out_of_range("vector subscript out of range"); return data_[off]; }
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -15,7 +15,7 @@
|
|||
#define HEADER_PUGICONFIG_HPP
|
||||
|
||||
// Uncomment this to enable wchar_t mode
|
||||
#define PUGIXML_WCHAR_MODE
|
||||
// #define PUGIXML_WCHAR_MODE
|
||||
|
||||
// Uncomment this to enable compact mode
|
||||
// #define PUGIXML_COMPACT
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ AudioEngine::~AudioEngine() {}
|
|||
|
||||
void AudioEngine::SetupComponent()
|
||||
{
|
||||
KGE_SYS_LOG(L"Creating audio resources");
|
||||
KGE_SYS_LOG("Creating audio resources");
|
||||
|
||||
HRESULT hr = dlls::MediaFoundation::Get().MFStartup(MF_VERSION, MFSTARTUP_FULL);
|
||||
|
||||
|
|
@ -51,12 +51,12 @@ void AudioEngine::SetupComponent()
|
|||
hr = x_audio2_->CreateMasteringVoice(&mastering_voice_);
|
||||
}
|
||||
|
||||
win32::ThrowIfFailed(hr);
|
||||
win32::ThrowIfFailed(hr, "Create audio resources failed");
|
||||
}
|
||||
|
||||
void AudioEngine::DestroyComponent()
|
||||
{
|
||||
KGE_SYS_LOG(L"Destroying audio resources");
|
||||
KGE_SYS_LOG("Destroying audio resources");
|
||||
|
||||
if (mastering_voice_)
|
||||
{
|
||||
|
|
@ -100,7 +100,7 @@ bool AudioEngine::CreateSound(Sound& sound, const Transcoder::Buffer& buffer)
|
|||
}
|
||||
}
|
||||
|
||||
win32::WarnIfFailed(hr);
|
||||
win32::WarnIfFailed(hr, "Create sound failed");
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace audio
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* \defgroup Audio 音频引擎
|
||||
* \defgroup Audio 音频引擎
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -42,7 +42,7 @@ namespace audio
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 音频引擎
|
||||
* @brief 音频引擎
|
||||
*/
|
||||
class KGE_API AudioEngine
|
||||
: public Singleton<AudioEngine>
|
||||
|
|
@ -52,15 +52,15 @@ class KGE_API AudioEngine
|
|||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 开启音频设备
|
||||
/// @brief 开启音频设备
|
||||
void Open();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 关闭音频设备
|
||||
/// @brief 关闭音频设备
|
||||
void Close();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 从解码器数据缓冲中创建音频对象
|
||||
/// @brief 从解码器数据缓冲中创建音频对象
|
||||
bool CreateSound(Sound& sound, const Transcoder::Buffer& buffer);
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -63,9 +63,9 @@ Sound::~Sound()
|
|||
|
||||
bool Sound::Load(String const& file_path)
|
||||
{
|
||||
if (!FileSystem::Instance().IsFileExists(file_path))
|
||||
if (!FileSystem::GetInstance().IsFileExists(file_path))
|
||||
{
|
||||
KGE_WARN(L"Media file '%s' not found", file_path.c_str());
|
||||
KGE_WARN("Media file '%s' not found", file_path.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -74,16 +74,16 @@ bool Sound::Load(String const& file_path)
|
|||
Close();
|
||||
}
|
||||
|
||||
String full_path = FileSystem::Instance().GetFullPathForFile(file_path);
|
||||
String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path);
|
||||
|
||||
HRESULT hr = transcoder_.LoadMediaFile(full_path);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
KGE_ERROR(L"Load media file failed with HRESULT of %08X", hr);
|
||||
KGE_ERROR("Load media file failed with HRESULT of %08X", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!AudioEngine::Instance().CreateSound(*this, transcoder_.GetBuffer()))
|
||||
if (!AudioEngine::GetInstance().CreateSound(*this, transcoder_.GetBuffer()))
|
||||
{
|
||||
Close();
|
||||
return false;
|
||||
|
|
@ -103,11 +103,11 @@ bool Sound::Load(Resource const& res)
|
|||
HRESULT hr = transcoder_.LoadMediaResource(res);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
KGE_ERROR(L"Load media resource failed with HRESULT of %08X", hr);
|
||||
KGE_ERROR("Load media resource failed with HRESULT of %08X", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!AudioEngine::Instance().CreateSound(*this, transcoder_.GetBuffer()))
|
||||
if (!AudioEngine::GetInstance().CreateSound(*this, transcoder_.GetBuffer()))
|
||||
{
|
||||
Close();
|
||||
return false;
|
||||
|
|
@ -126,7 +126,7 @@ void Sound::Play(int loop_count)
|
|||
{
|
||||
if (!opened_)
|
||||
{
|
||||
KGE_ERROR(L"Sound must be opened first!");
|
||||
KGE_ERROR("Sound must be opened first!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ void Sound::Play(int loop_count)
|
|||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
KGE_ERROR(L"Submitting source buffer failed with HRESULT of %08X", hr);
|
||||
KGE_ERROR("Submitting source buffer failed with HRESULT of %08X", hr);
|
||||
}
|
||||
|
||||
playing_ = SUCCEEDED(hr);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ KGE_DECLARE_SMART_PTR(Sound);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 音频对象
|
||||
* @brief 音频对象
|
||||
*/
|
||||
class KGE_API Sound : public virtual ObjectBase
|
||||
{
|
||||
|
|
@ -48,13 +48,13 @@ class KGE_API Sound : public virtual ObjectBase
|
|||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建音频对象
|
||||
/// @param res 本地音频文件路径
|
||||
/// @brief 创建音频对象
|
||||
/// @param res 本地音频文件路径
|
||||
static SoundPtr Create(String const& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建音频对象
|
||||
/// @param res 音频资源
|
||||
/// @brief 创建音频对象
|
||||
/// @param res 音频资源
|
||||
static SoundPtr Create(Resource const& res);
|
||||
|
||||
Sound();
|
||||
|
|
@ -62,51 +62,51 @@ public:
|
|||
virtual ~Sound();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 打开本地音频文件
|
||||
/// @param res 本地音频文件路径
|
||||
/// @brief 打开本地音频文件
|
||||
/// @param res 本地音频文件路径
|
||||
bool Load(String const& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 打开音频资源
|
||||
/// @param res 音频资源
|
||||
/// @brief 打开音频资源
|
||||
/// @param res 音频资源
|
||||
bool Load(Resource const& res);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否有效
|
||||
/// @brief 是否有效
|
||||
bool IsValid() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 播放
|
||||
/// @param loop_count 播放循环次数,设置 -1 为循环播放
|
||||
/// @brief 播放
|
||||
/// @param loop_count 播放循环次数,设置 -1 为循环播放
|
||||
void Play(int loop_count = 0);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 暂停
|
||||
/// @brief 暂停
|
||||
void Pause();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 继续
|
||||
/// @brief 继续
|
||||
void Resume();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 停止
|
||||
/// @brief 停止
|
||||
void Stop();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 关闭并销毁资源
|
||||
/// @brief 关闭并销毁资源
|
||||
void Close();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否正在播放
|
||||
/// @brief 是否正在播放
|
||||
bool IsPlaying() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取音量
|
||||
/// @brief 获取音量
|
||||
float GetVolume() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置音量
|
||||
/// @param volume 音量大小,1.0 为原始音量, 大于 1 为放大音量, 0 为最小音量
|
||||
/// @brief 设置音量
|
||||
/// @param volume 音量大小,1.0 为原始音量, 大于 1 为放大音量, 0 为最小音量
|
||||
void SetVolume(float volume);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -35,13 +35,13 @@ KGE_DECLARE_SMART_PTR(SoundPlayer);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 音频播放器
|
||||
* @brief 音频播放器
|
||||
*/
|
||||
class KGE_API SoundPlayer : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建音频播放器
|
||||
/// @brief 创建音频播放器
|
||||
static SoundPlayerPtr Create();
|
||||
|
||||
SoundPlayer();
|
||||
|
|
@ -49,66 +49,66 @@ public:
|
|||
~SoundPlayer();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载本地音频文件
|
||||
/// @param file_path 本地音频文件路径
|
||||
/// @return 音频标识符
|
||||
/// @brief 加载本地音频文件
|
||||
/// @param file_path 本地音频文件路径
|
||||
/// @return 音频标识符
|
||||
size_t Load(String const& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载音频资源
|
||||
/// @param res 音频资源
|
||||
/// @return 音频标识符
|
||||
/// @brief 加载音频资源
|
||||
/// @param res 音频资源
|
||||
/// @return 音频标识符
|
||||
size_t Load(Resource const& res);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 播放音频
|
||||
/// @param id 音频标识符
|
||||
/// @param loop_count 播放循环次数,设置 -1 为循环播放
|
||||
/// @brief 播放音频
|
||||
/// @param id 音频标识符
|
||||
/// @param loop_count 播放循环次数,设置 -1 为循环播放
|
||||
void Play(size_t id, int loop_count = 0);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 暂停音频
|
||||
/// @param id 音频标识符
|
||||
/// @brief 暂停音频
|
||||
/// @param id 音频标识符
|
||||
void Pause(size_t id);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 继续播放音频
|
||||
/// @param id 音频标识符
|
||||
/// @brief 继续播放音频
|
||||
/// @param id 音频标识符
|
||||
void Resume(size_t id);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 停止音频
|
||||
/// @param id 音频标识符
|
||||
/// @brief 停止音频
|
||||
/// @param id 音频标识符
|
||||
void Stop(size_t id);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取音频播放状态
|
||||
/// @param id 音频标识符
|
||||
/// @brief 获取音频播放状态
|
||||
/// @param id 音频标识符
|
||||
bool IsPlaying(size_t id);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取音量
|
||||
/// @brief 获取音量
|
||||
float GetVolume() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置音量
|
||||
/// @param volume 音量大小,1.0 为原始音量, 大于 1 为放大音量, 0 为最小音量
|
||||
/// @brief 设置音量
|
||||
/// @param volume 音量大小,1.0 为原始音量, 大于 1 为放大音量, 0 为最小音量
|
||||
void SetVolume(float volume);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 暂停所有音频
|
||||
/// @brief 暂停所有音频
|
||||
void PauseAll();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 继续播放所有音频
|
||||
/// @brief 继续播放所有音频
|
||||
void ResumeAll();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 停止所有音频
|
||||
/// @brief 停止所有音频
|
||||
void StopAll();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 清除缓存
|
||||
/// @brief 清除缓存
|
||||
void ClearCache();
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ HRESULT Transcoder::LoadMediaFile(String const& file_path)
|
|||
|
||||
ComPtr<IMFSourceReader> reader;
|
||||
|
||||
hr = dlls::MediaFoundation::Get().MFCreateSourceReaderFromURL(file_path.c_str(), nullptr, &reader);
|
||||
hr = dlls::MediaFoundation::Get().MFCreateSourceReaderFromURL(MultiByteToWide(file_path).c_str(), nullptr, &reader);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
|
|
@ -105,7 +105,7 @@ HRESULT Transcoder::LoadMediaResource(Resource const& res)
|
|||
|
||||
if (stream == nullptr)
|
||||
{
|
||||
KGE_ERROR(L"SHCreateMemStream failed");
|
||||
KGE_ERROR("SHCreateMemStream failed");
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
|
|
@ -147,25 +147,25 @@ HRESULT Transcoder::ReadSource(IMFSourceReader* reader)
|
|||
hr = partial_type->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
|
||||
}
|
||||
|
||||
// 设置 source reader 的媒体类型,它将使用合适的解码器去解码这个音频
|
||||
// 设置 source reader 的媒体类型,它将使用合适的解码器去解码这个音频
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = reader->SetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, partial_type.get());
|
||||
}
|
||||
|
||||
// 从 IMFMediaType 中获取 WAVEFORMAT 结构
|
||||
// 从 IMFMediaType 中获取 WAVEFORMAT 结构
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = reader->GetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, &uncompressed_type);
|
||||
}
|
||||
|
||||
// 指定音频流
|
||||
// 指定音频流
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = reader->SetStreamSelection((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, true);
|
||||
}
|
||||
|
||||
// 获取 WAVEFORMAT 数据
|
||||
// 获取 WAVEFORMAT 数据
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
uint32_t size = 0;
|
||||
|
|
@ -173,7 +173,7 @@ HRESULT Transcoder::ReadSource(IMFSourceReader* reader)
|
|||
uncompressed_type.get(), &wave_format_, &size, (DWORD)MFWaveFormatExConvertFlag_Normal);
|
||||
}
|
||||
|
||||
// 估算音频流大小
|
||||
// 估算音频流大小
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
PROPVARIANT prop;
|
||||
|
|
@ -186,7 +186,7 @@ HRESULT Transcoder::ReadSource(IMFSourceReader* reader)
|
|||
PropVariantClear(&prop);
|
||||
}
|
||||
|
||||
// 读取音频数据
|
||||
// 读取音频数据
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
DWORD flags = 0;
|
||||
|
|
@ -198,7 +198,7 @@ HRESULT Transcoder::ReadSource(IMFSourceReader* reader)
|
|||
|
||||
if (data == nullptr)
|
||||
{
|
||||
KGE_ERROR(L"Low memory");
|
||||
KGE_ERROR("Low memory");
|
||||
hr = E_OUTOFMEMORY;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Sound;
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 音频解码器
|
||||
* @brief 音频解码器
|
||||
*/
|
||||
class KGE_API Transcoder
|
||||
{
|
||||
|
|
@ -46,13 +46,13 @@ class KGE_API Transcoder
|
|||
public:
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 音频数据缓冲
|
||||
* @brief 音频数据缓冲
|
||||
*/
|
||||
struct Buffer
|
||||
{
|
||||
BYTE* data; ///< 音频数据
|
||||
uint32_t size; ///< 音频数据大小
|
||||
const WAVEFORMATEX* format; ///< 音频数据格式
|
||||
BYTE* data; ///< 音频数据
|
||||
uint32_t size; ///< 音频数据大小
|
||||
const WAVEFORMATEX* format; ///< 音频数据格式
|
||||
};
|
||||
|
||||
Transcoder();
|
||||
|
|
@ -60,24 +60,24 @@ public:
|
|||
~Transcoder();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取数据缓冲
|
||||
/// @brief 获取数据缓冲
|
||||
Buffer GetBuffer() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 清空数据缓冲
|
||||
/// @brief 清空数据缓冲
|
||||
void ClearBuffer();
|
||||
|
||||
private:
|
||||
/// \~chinese
|
||||
/// @brief 解码本地音频文件
|
||||
/// @brief 解码本地音频文件
|
||||
HRESULT LoadMediaFile(String const& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 解码音频资源
|
||||
/// @brief 解码音频资源
|
||||
HRESULT LoadMediaResource(Resource const& res);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 读取音频源数据
|
||||
/// @brief 读取音频源数据
|
||||
HRESULT ReadSource(IMFSourceReader* reader);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ XAudio2::XAudio2()
|
|||
}
|
||||
else
|
||||
{
|
||||
KGE_ERROR(L"Load xaudio2.dll failed");
|
||||
KGE_ERROR("Load xaudio2.dll failed");
|
||||
throw std::runtime_error("Load xaudio2.dll failed");
|
||||
}
|
||||
}
|
||||
|
|
@ -79,7 +79,7 @@ MediaFoundation::MediaFoundation()
|
|||
}
|
||||
else
|
||||
{
|
||||
KGE_ERROR(L"Load Mfplat.dll failed");
|
||||
KGE_ERROR("Load Mfplat.dll failed");
|
||||
throw std::runtime_error("Load Mfplat.dll failed");
|
||||
}
|
||||
|
||||
|
|
@ -92,7 +92,7 @@ MediaFoundation::MediaFoundation()
|
|||
}
|
||||
else
|
||||
{
|
||||
KGE_ERROR(L"Load Mfreadwrite.dll failed");
|
||||
KGE_ERROR("Load Mfreadwrite.dll failed");
|
||||
throw std::runtime_error("Load Mfreadwrite.dll failed");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/2d/Layer.h>
|
||||
#include <kiwano/2d/LayerActor.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -28,24 +28,24 @@ namespace imgui
|
|||
KGE_DECLARE_SMART_PTR(ImGuiLayer);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief ImGui管道
|
||||
/// @brief ImGui管道
|
||||
using ImGuiPipeline = Function<void()>;
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief ImGui图层
|
||||
* @brief ImGui图层
|
||||
*/
|
||||
class ImGuiLayer : public Layer
|
||||
class ImGuiLayer : public LayerActor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建ImGui图层
|
||||
/// @brief 创建ImGui图层
|
||||
static ImGuiLayerPtr Create();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建ImGui图层
|
||||
/// @param name 元素名称
|
||||
/// @param item 管道
|
||||
/// @brief 创建ImGui图层
|
||||
/// @param name 元素名称
|
||||
/// @param item 管道
|
||||
static ImGuiLayerPtr Create(String const& name, ImGuiPipeline const& item);
|
||||
|
||||
ImGuiLayer();
|
||||
|
|
@ -53,19 +53,19 @@ public:
|
|||
virtual ~ImGuiLayer();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加 ImGui 元素
|
||||
/// @param name 元素名称
|
||||
/// @param item 管道
|
||||
/// @brief 添加 ImGui 元素
|
||||
/// @param name 元素名称
|
||||
/// @param item 管道
|
||||
void AddItem(String const& name, ImGuiPipeline const& item);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除 ImGui 元素
|
||||
/// @param name 元素名称
|
||||
/// @brief 移除 ImGui 元素
|
||||
/// @param name 元素名称
|
||||
void RemoveItem(String const& name);
|
||||
|
||||
// 移除所有元素
|
||||
// 移除所有元素
|
||||
/// \~chinese
|
||||
/// @brief 移除所有元素
|
||||
/// @brief 移除所有元素
|
||||
void RemoveAllItems();
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include <kiwano/core/event/KeyEvent.h>
|
||||
#include <kiwano/core/event/MouseEvent.h>
|
||||
#include <kiwano/platform/Input.h>
|
||||
#include <kiwano/platform/Window.h>
|
||||
#include <kiwano/platform/win32/WindowImpl.h>
|
||||
#include <kiwano/render/Renderer.h>
|
||||
#include <kiwano-imgui/ImGuiModule.h>
|
||||
#include <kiwano-imgui/imgui_impl.h>
|
||||
|
|
@ -15,7 +15,6 @@ namespace kiwano
|
|||
namespace imgui
|
||||
{
|
||||
ImGuiModule::ImGuiModule()
|
||||
: target_window_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -31,13 +30,11 @@ void ImGuiModule::SetupComponent()
|
|||
ImGui::StyleColorsDark();
|
||||
|
||||
// Setup Platform/Renderer bindings
|
||||
target_window_ = Renderer::Instance().GetTargetWindow();
|
||||
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
||||
io.BackendFlags |=
|
||||
ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||||
io.BackendPlatformName = "imgui_impl_win32";
|
||||
io.ImeWindowHandle = target_window_;
|
||||
io.ImeWindowHandle = WindowImpl::GetInstance().GetHandle();
|
||||
|
||||
// Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array that we will update during
|
||||
// the application lifetime.
|
||||
|
|
@ -58,7 +55,7 @@ void ImGuiModule::SetupComponent()
|
|||
io.KeyMap[ImGuiKey_Y] = (int)KeyCode::Y;
|
||||
io.KeyMap[ImGuiKey_Z] = (int)KeyCode::Z;
|
||||
|
||||
ImGui_Impl_Init(Renderer::Instance());
|
||||
ImGui_Impl_Init();
|
||||
}
|
||||
|
||||
void ImGuiModule::DestroyComponent()
|
||||
|
|
@ -75,10 +72,10 @@ void ImGuiModule::OnUpdate(Duration dt)
|
|||
io.DeltaTime = dt.Seconds();
|
||||
|
||||
// Read keyboard modifiers inputs
|
||||
io.KeyCtrl = Input::Instance().IsDown(KeyCode::Ctrl);
|
||||
io.KeyShift = Input::Instance().IsDown(KeyCode::Shift);
|
||||
io.KeyAlt = Input::Instance().IsDown(KeyCode::Alt);
|
||||
io.KeySuper = Input::Instance().IsDown(KeyCode::Super);
|
||||
io.KeyCtrl = Input::GetInstance().IsDown(KeyCode::Ctrl);
|
||||
io.KeyShift = Input::GetInstance().IsDown(KeyCode::Shift);
|
||||
io.KeyAlt = Input::GetInstance().IsDown(KeyCode::Alt);
|
||||
io.KeySuper = Input::GetInstance().IsDown(KeyCode::Super);
|
||||
// io.KeysDown[], io.MousePos, io.MouseDown[], io.MouseWheel: filled by the HandleEvent function below.
|
||||
|
||||
// Update OS mouse position
|
||||
|
|
@ -96,7 +93,7 @@ void ImGuiModule::BeforeRender()
|
|||
KGE_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built!");
|
||||
|
||||
// Setup display size (every frame to accommodate for window resizing)
|
||||
Size display_size = Renderer::Instance().GetOutputSize();
|
||||
Size display_size = Renderer::GetInstance().GetOutputSize();
|
||||
io.DisplaySize = ImVec2(display_size.x, display_size.y);
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
|
@ -177,11 +174,11 @@ void ImGuiModule::UpdateMousePos()
|
|||
if (io.WantSetMousePos)
|
||||
{
|
||||
POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y };
|
||||
::ClientToScreen(target_window_, &pos);
|
||||
::ClientToScreen(WindowImpl::GetInstance().GetHandle(), &pos);
|
||||
::SetCursorPos(pos.x, pos.y);
|
||||
}
|
||||
|
||||
Point pos = Input::Instance().GetMousePos();
|
||||
Point pos = Input::GetInstance().GetMousePos();
|
||||
io.MousePos = ImVec2(pos.x, pos.y);
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +216,7 @@ void ImGuiModule::UpdateMouseCursor()
|
|||
break;
|
||||
}
|
||||
|
||||
Window::Instance().SetCursor(cursor);
|
||||
Window::GetInstance().SetCursor(cursor);
|
||||
}
|
||||
|
||||
} // namespace imgui
|
||||
|
|
|
|||
|
|
@ -26,9 +26,10 @@ namespace kiwano
|
|||
{
|
||||
namespace imgui
|
||||
{
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief ImGuiÄ£¿é
|
||||
* @brief ImGui模块
|
||||
*/
|
||||
class ImGuiModule
|
||||
: public Singleton<ImGuiModule>
|
||||
|
|
@ -57,9 +58,7 @@ private:
|
|||
void UpdateMousePos();
|
||||
|
||||
void UpdateMouseCursor();
|
||||
|
||||
private:
|
||||
WindowHandle target_window_;
|
||||
};
|
||||
|
||||
} // namespace imgui
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -7,20 +7,25 @@
|
|||
#if !defined(KGE_USE_DIRECTX10)
|
||||
|
||||
#include <kiwano-imgui/imgui_impl_dx11.h>
|
||||
#include <kiwano/render/DirectX/RendererImpl.h>
|
||||
|
||||
inline bool ImGui_Impl_Init(::kiwano::Renderer& renderer)
|
||||
inline bool ImGui_Impl_Init()
|
||||
{
|
||||
::kiwano::RendererImpl& renderer = ::kiwano::RendererImpl::GetInstance();
|
||||
return ImGui_ImplDX11_Init(renderer.GetD3DDeviceResources()->GetDevice(),
|
||||
renderer.GetD3DDeviceResources()->GetDeviceContext());
|
||||
}
|
||||
|
||||
inline void ImGui_Impl_Shutdown()
|
||||
{
|
||||
ImGui_ImplDX11_Shutdown();
|
||||
}
|
||||
|
||||
inline void ImGui_Impl_NewFrame()
|
||||
{
|
||||
ImGui_ImplDX11_NewFrame();
|
||||
}
|
||||
|
||||
inline void ImGui_Impl_RenderDrawData(ImDrawData* draw_data)
|
||||
{
|
||||
ImGui_ImplDX11_RenderDrawData(draw_data);
|
||||
|
|
@ -30,6 +35,7 @@ inline void ImGui_Impl_InvalidateDeviceObjects()
|
|||
{
|
||||
ImGui_ImplDX11_InvalidateDeviceObjects();
|
||||
}
|
||||
|
||||
inline bool ImGui_Impl_CreateDeviceObjects()
|
||||
{
|
||||
return ImGui_ImplDX11_CreateDeviceObjects();
|
||||
|
|
@ -39,18 +45,22 @@ inline bool ImGui_Impl_CreateDeviceObjects()
|
|||
|
||||
#include <kiwano-imgui/imgui_impl_dx10.h>
|
||||
|
||||
inline bool ImGui_Impl_Init(::kiwano::Renderer& renderer)
|
||||
inline bool ImGui_Impl_Init()
|
||||
{
|
||||
::kiwano::RendererImpl& renderer = ::kiwano::RendererImpl::GetInstance();
|
||||
return ImGui_ImplDX10_Init(renderer.GetD3DDeviceResources()->GetDevice());
|
||||
}
|
||||
|
||||
inline void ImGui_Impl_Shutdown()
|
||||
{
|
||||
ImGui_ImplDX10_Shutdown();
|
||||
}
|
||||
|
||||
inline void ImGui_Impl_NewFrame()
|
||||
{
|
||||
ImGui_ImplDX10_NewFrame();
|
||||
}
|
||||
|
||||
inline void ImGui_Impl_RenderDrawData(ImDrawData* draw_data)
|
||||
{
|
||||
ImGui_ImplDX10_RenderDrawData(draw_data);
|
||||
|
|
@ -60,6 +70,7 @@ inline void ImGui_Impl_InvalidateDeviceObjects()
|
|||
{
|
||||
ImGui_ImplDX10_InvalidateDeviceObjects();
|
||||
}
|
||||
|
||||
inline bool ImGui_Impl_CreateDeviceObjects()
|
||||
{
|
||||
return ImGui_ImplDX10_CreateDeviceObjects();
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <codecvt>
|
||||
#include <thread>
|
||||
#include <kiwano/core/Logger.h>
|
||||
#include <kiwano/platform/Application.h>
|
||||
|
|
@ -34,8 +33,8 @@ using namespace kiwano::network;
|
|||
|
||||
uint32_t write_data(void* buffer, uint32_t size, uint32_t nmemb, void* userp)
|
||||
{
|
||||
ByteString* recv_buffer = (ByteString*)userp;
|
||||
uint32_t total = size * nmemb;
|
||||
String* recv_buffer = (String*)userp;
|
||||
uint32_t total = size * nmemb;
|
||||
|
||||
// add data to the end of recv_buffer
|
||||
// write data maybe called more than once in a single request
|
||||
|
|
@ -44,40 +43,6 @@ uint32_t write_data(void* buffer, uint32_t size, uint32_t nmemb, void* userp)
|
|||
return total;
|
||||
}
|
||||
|
||||
ByteString convert_to_utf8(String const& str)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_conv;
|
||||
ByteString result;
|
||||
|
||||
try
|
||||
{
|
||||
result = utf8_conv.to_bytes(str.c_str());
|
||||
}
|
||||
catch (std::range_error&)
|
||||
{
|
||||
// bad conversion
|
||||
result = WideToMultiByte(str);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
String convert_from_utf8(ByteString const& str)
|
||||
{
|
||||
oc::string_convert<std::codecvt_utf8<wchar_t>> utf8_conv;
|
||||
String result;
|
||||
|
||||
try
|
||||
{
|
||||
result = utf8_conv.from_bytes(str);
|
||||
}
|
||||
catch (std::range_error&)
|
||||
{
|
||||
// bad conversion
|
||||
result = MultiByteToWide(str);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
class Curl
|
||||
{
|
||||
public:
|
||||
|
|
@ -102,8 +67,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
bool Init(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url, ByteString* response_data,
|
||||
ByteString* response_header, char* error_buffer)
|
||||
bool Init(HttpClient* client, Vector<String> const& headers, String const& url, String* response_data,
|
||||
String* response_header, char* error_buffer)
|
||||
{
|
||||
if (!SetOption(CURLOPT_ERRORBUFFER, error_buffer))
|
||||
return false;
|
||||
|
|
@ -112,7 +77,7 @@ public:
|
|||
if (!SetOption(CURLOPT_CONNECTTIMEOUT, client->GetTimeoutForConnect()))
|
||||
return false;
|
||||
|
||||
const auto ssl_ca_file = wide_to_string(client->GetSSLVerification());
|
||||
const String& ssl_ca_file = client->GetSSLVerification();
|
||||
if (ssl_ca_file.empty())
|
||||
{
|
||||
if (!SetOption(CURLOPT_SSL_VERIFYPEER, 0L))
|
||||
|
|
@ -167,8 +132,8 @@ public:
|
|||
}
|
||||
|
||||
public:
|
||||
static inline bool GetRequest(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url,
|
||||
long* response_code, ByteString* response_data, ByteString* response_header,
|
||||
static inline bool GetRequest(HttpClient* client, Vector<String> const& headers, String const& url,
|
||||
long* response_code, String* response_data, String* response_header,
|
||||
char* error_buffer)
|
||||
{
|
||||
Curl curl;
|
||||
|
|
@ -176,9 +141,9 @@ public:
|
|||
&& curl.SetOption(CURLOPT_FOLLOWLOCATION, true) && curl.Perform(response_code);
|
||||
}
|
||||
|
||||
static inline bool PostRequest(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url,
|
||||
ByteString const& request_data, long* response_code, ByteString* response_data,
|
||||
ByteString* response_header, char* error_buffer)
|
||||
static inline bool PostRequest(HttpClient* client, Vector<String> const& headers, String const& url,
|
||||
String const& request_data, long* response_code, String* response_data,
|
||||
String* response_header, char* error_buffer)
|
||||
{
|
||||
Curl curl;
|
||||
return curl.Init(client, headers, url, response_data, response_header, error_buffer)
|
||||
|
|
@ -186,9 +151,9 @@ public:
|
|||
&& curl.SetOption(CURLOPT_POSTFIELDSIZE, request_data.size()) && curl.Perform(response_code);
|
||||
}
|
||||
|
||||
static inline bool PutRequest(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url,
|
||||
ByteString const& request_data, long* response_code, ByteString* response_data,
|
||||
ByteString* response_header, char* error_buffer)
|
||||
static inline bool PutRequest(HttpClient* client, Vector<String> const& headers, String const& url,
|
||||
String const& request_data, long* response_code, String* response_data,
|
||||
String* response_header, char* error_buffer)
|
||||
{
|
||||
Curl curl;
|
||||
return curl.Init(client, headers, url, response_data, response_header, error_buffer)
|
||||
|
|
@ -197,8 +162,8 @@ public:
|
|||
&& curl.SetOption(CURLOPT_POSTFIELDSIZE, request_data.size()) && curl.Perform(response_code);
|
||||
}
|
||||
|
||||
static inline bool DeleteRequest(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url,
|
||||
long* response_code, ByteString* response_data, ByteString* response_header,
|
||||
static inline bool DeleteRequest(HttpClient* client, Vector<String> const& headers, String const& url,
|
||||
long* response_code, String* response_data, String* response_header,
|
||||
char* error_buffer)
|
||||
{
|
||||
Curl curl;
|
||||
|
|
@ -276,20 +241,19 @@ void HttpClient::NetworkThread()
|
|||
|
||||
void HttpClient::Perform(HttpRequestPtr request, HttpResponsePtr response)
|
||||
{
|
||||
bool ok = false;
|
||||
long response_code = 0;
|
||||
char error_message[256] = { 0 };
|
||||
ByteString response_header;
|
||||
ByteString response_data;
|
||||
bool ok = false;
|
||||
long response_code = 0;
|
||||
char error_message[256] = { 0 };
|
||||
String response_header;
|
||||
String response_data;
|
||||
String url = request->GetUrl();
|
||||
String data = request->GetData();
|
||||
|
||||
ByteString url = convert_to_utf8(request->GetUrl());
|
||||
ByteString data = convert_to_utf8(request->GetData());
|
||||
|
||||
Vector<ByteString> headers;
|
||||
Vector<String> headers;
|
||||
headers.reserve(request->GetHeaders().size());
|
||||
for (const auto& pair : request->GetHeaders())
|
||||
{
|
||||
headers.push_back(wide_to_string(pair.first) + ":" + wide_to_string(pair.second));
|
||||
headers.push_back(pair.first + ":" + pair.second);
|
||||
}
|
||||
|
||||
switch (request->GetType())
|
||||
|
|
@ -309,17 +273,17 @@ void HttpClient::Perform(HttpRequestPtr request, HttpResponsePtr response)
|
|||
ok = Curl::DeleteRequest(this, headers, url, &response_code, &response_data, &response_header, error_message);
|
||||
break;
|
||||
default:
|
||||
KGE_ERROR(L"HttpClient: unknown request type, only GET, POST, PUT or DELETE is supported");
|
||||
KGE_ERROR("HttpClient: unknown request type, only GET, POST, PUT or DELETE is supported");
|
||||
return;
|
||||
}
|
||||
|
||||
response->SetResponseCode(response_code);
|
||||
response->SetHeader(MultiByteToWide(response_header));
|
||||
response->SetData(convert_from_utf8(response_data));
|
||||
response->SetHeader(response_header);
|
||||
response->SetData(response_data);
|
||||
if (!ok)
|
||||
{
|
||||
response->SetSucceed(false);
|
||||
response->SetError(MultiByteToWide(error_message));
|
||||
response->SetError(error_message);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace network
|
|||
{
|
||||
/**
|
||||
* \~chinese
|
||||
* \defgroup Network 网络通信
|
||||
* \defgroup Network 网络通信
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -40,7 +40,7 @@ namespace network
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief HTTP客户端
|
||||
* @brief HTTP客户端
|
||||
*/
|
||||
class KGE_API HttpClient
|
||||
: public Singleton<HttpClient>
|
||||
|
|
@ -50,33 +50,33 @@ class KGE_API HttpClient
|
|||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 发送HTTP请求
|
||||
/// @param[in] request HTTP请求
|
||||
/// @details 发送请求后,无论结束或失败都将调用请求的响应回调函数
|
||||
/// @brief 发送HTTP请求
|
||||
/// @param[in] request HTTP请求
|
||||
/// @details 发送请求后,无论结束或失败都将调用请求的响应回调函数
|
||||
void Send(HttpRequestPtr request);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置连接超时时长
|
||||
/// @brief 设置连接超时时长
|
||||
void SetTimeoutForConnect(Duration timeout);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取连接超时时长
|
||||
/// @brief 获取连接超时时长
|
||||
Duration GetTimeoutForConnect() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置读取超时时长
|
||||
/// @brief 设置读取超时时长
|
||||
void SetTimeoutForRead(Duration timeout);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取读取超时时长
|
||||
/// @brief 获取读取超时时长
|
||||
Duration GetTimeoutForRead() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置SSL证书地址
|
||||
/// @brief 设置SSL证书地址
|
||||
void SetSSLVerification(String const& root_certificate_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取SSL证书地址
|
||||
/// @brief 获取SSL证书地址
|
||||
String const& GetSSLVerification() const;
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ HttpRequestPtr HttpRequest::Create(String const& url, HttpType type, Json const&
|
|||
|
||||
void HttpRequest::SetJsonData(Json const& json)
|
||||
{
|
||||
SetHeader(L"Content-Type", L"application/json;charset=UTF-8");
|
||||
SetHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
data_ = json.dump();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,48 +37,48 @@ KGE_DECLARE_SMART_PTR(HttpRequest);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief HTTP请求类型
|
||||
/// @brief HTTP请求类型
|
||||
enum class HttpType
|
||||
{
|
||||
Unknown, ///< 未知
|
||||
Get, ///< HTTP GET请求
|
||||
Post, ///< HTTP POST请求
|
||||
Put, ///< HTTP PUT请求
|
||||
Delete ///< HTTP DELETE请求
|
||||
Unknown, ///< 未知
|
||||
Get, ///< HTTP GET请求
|
||||
Post, ///< HTTP POST请求
|
||||
Put, ///< HTTP PUT请求
|
||||
Delete ///< HTTP DELETE请求
|
||||
};
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief HTTP请求
|
||||
* @brief HTTP请求
|
||||
*/
|
||||
class KGE_API HttpRequest : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 响应回调函数
|
||||
/// @brief 响应回调函数
|
||||
using ResponseCallback = Function<void(HttpRequest* /* request */, HttpResponse* /* response */)>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建HTTP请求
|
||||
/// @param url 请求地址
|
||||
/// @param type 请求类型
|
||||
/// @param callback 响应回调函数
|
||||
/// @brief 创建HTTP请求
|
||||
/// @param url 请求地址
|
||||
/// @param type 请求类型
|
||||
/// @param callback 响应回调函数
|
||||
static HttpRequestPtr Create(String const& url, HttpType type, ResponseCallback const& callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建HTTP请求
|
||||
/// @param url 请求地址
|
||||
/// @param type 请求类型
|
||||
/// @param data 请求数据
|
||||
/// @param callback 响应回调函数
|
||||
/// @brief 创建HTTP请求
|
||||
/// @param url 请求地址
|
||||
/// @param type 请求类型
|
||||
/// @param data 请求数据
|
||||
/// @param callback 响应回调函数
|
||||
static HttpRequestPtr Create(String const& url, HttpType type, String const& data, ResponseCallback const& callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建HTTP请求
|
||||
/// @param url 请求地址
|
||||
/// @param type 请求类型
|
||||
/// @param json 请求的JSON数据
|
||||
/// @param callback 响应回调函数
|
||||
/// @brief 创建HTTP请求
|
||||
/// @param url 请求地址
|
||||
/// @param type 请求类型
|
||||
/// @param json 请求的JSON数据
|
||||
/// @param callback 响应回调函数
|
||||
static HttpRequestPtr Create(String const& url, HttpType type, Json const& json, ResponseCallback const& callback);
|
||||
|
||||
HttpRequest();
|
||||
|
|
@ -86,55 +86,55 @@ public:
|
|||
HttpRequest(HttpType type);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置请求地址
|
||||
/// @brief 设置请求地址
|
||||
void SetUrl(String const& url);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置请求类型
|
||||
/// @brief 设置请求类型
|
||||
void SetType(HttpType type);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置请求数据
|
||||
/// @brief 设置请求数据
|
||||
void SetData(String const& data);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置请求的JSON数据
|
||||
/// @brief 设置请求的JSON数据
|
||||
void SetJsonData(Json const& json);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置HTTP头
|
||||
/// @brief 设置HTTP头
|
||||
void SetHeaders(Map<String, String> const& headers);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置HTTP头
|
||||
/// @brief 设置HTTP头
|
||||
void SetHeader(String const& field, String const& content);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置响应回调函数
|
||||
/// @brief 设置响应回调函数
|
||||
void SetResponseCallback(ResponseCallback const& callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取请求地址
|
||||
/// @brief 获取请求地址
|
||||
String const& GetUrl() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取请求类型
|
||||
/// @brief 获取请求类型
|
||||
HttpType GetType() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取请求数据
|
||||
/// @brief 获取请求数据
|
||||
String const& GetData() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取HTTP头
|
||||
/// @brief 获取HTTP头
|
||||
Map<String, String>& GetHeaders();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取HTTP头
|
||||
/// @brief 获取HTTP头
|
||||
String const& GetHeader(String const& header) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取响应回调函数
|
||||
/// @brief 获取响应回调函数
|
||||
ResponseCallback const& GetResponseCallback() const;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ KGE_DECLARE_SMART_PTR(HttpResponse);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief HTTP响应
|
||||
* @brief HTTP响应
|
||||
*/
|
||||
class KGE_API HttpResponse : public virtual ObjectBase
|
||||
{
|
||||
|
|
@ -42,47 +42,47 @@ public:
|
|||
HttpResponse(HttpRequestPtr request);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取对应的HTTP请求
|
||||
/// @brief 获取对应的HTTP请求
|
||||
HttpRequestPtr GetRequest() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取响应状态
|
||||
/// @brief 获取响应状态
|
||||
bool IsSucceed() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取HTTP状态码
|
||||
/// @brief 获取HTTP状态码
|
||||
long GetResponseCode() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取响应头
|
||||
/// @brief 获取响应头
|
||||
String GetHeader() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取响应数据
|
||||
/// @brief 获取响应数据
|
||||
String const& GetData() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取错误信息
|
||||
/// @brief 获取错误信息
|
||||
String const& GetError() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置响应状态
|
||||
/// @brief 设置响应状态
|
||||
void SetSucceed(bool succeed);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置HTTP状态码
|
||||
/// @brief 设置HTTP状态码
|
||||
void SetResponseCode(long response_code);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置响应头
|
||||
/// @brief 设置响应头
|
||||
void SetHeader(String const& response_header);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置响应数据
|
||||
/// @brief 设置响应数据
|
||||
void SetData(String const& response_data);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置错误信息
|
||||
/// @brief 设置错误信息
|
||||
void SetError(String const& error_buffer);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -37,31 +37,31 @@ KGE_DECLARE_SMART_PTR(Body);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物体
|
||||
/// @brief 物体
|
||||
class KGE_API Body : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 物体类型
|
||||
/// @brief 物体类型
|
||||
enum class Type
|
||||
{
|
||||
Static = 0, ///< 静态物体
|
||||
Kinematic, ///< 动力学物体
|
||||
Dynamic, ///< 动态物体
|
||||
Static = 0, ///< 静态物体
|
||||
Kinematic, ///< 动力学物体
|
||||
Dynamic, ///< 动态物体
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化
|
||||
/// @param[in] world 物理世界
|
||||
/// @param[in] actor 绑定的角色
|
||||
/// @param[in] type 物体类型
|
||||
/// @brief 初始化
|
||||
/// @param[in] world 物理世界
|
||||
/// @param[in] actor 绑定的角色
|
||||
/// @param[in] type 物体类型
|
||||
static BodyPtr Create(World* world, ActorPtr actor, Type type);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化
|
||||
/// @param[in] world 物理世界
|
||||
/// @param[in] actor 绑定的角色
|
||||
/// @param[in] type 物体类型
|
||||
/// @brief 初始化
|
||||
/// @param[in] world 物理世界
|
||||
/// @param[in] actor 绑定的角色
|
||||
/// @param[in] type 物体类型
|
||||
static BodyPtr Create(World* world, Actor* actor, Type type);
|
||||
|
||||
Body();
|
||||
|
|
@ -69,250 +69,250 @@ public:
|
|||
virtual ~Body();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化
|
||||
/// @param[in] world 物理世界
|
||||
/// @param[in] actor 绑定的角色
|
||||
/// @brief 初始化
|
||||
/// @param[in] world 物理世界
|
||||
/// @param[in] actor 绑定的角色
|
||||
bool InitBody(World* world, ActorPtr actor);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化
|
||||
/// @param[in] world 物理世界
|
||||
/// @param[in] actor 绑定的角色
|
||||
/// @brief 初始化
|
||||
/// @param[in] world 物理世界
|
||||
/// @param[in] actor 绑定的角色
|
||||
bool InitBody(World* world, Actor* actor);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加夹具
|
||||
/// @brief 添加夹具
|
||||
void AddFixture(FixturePtr fixture);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加圆形夹具
|
||||
/// @param radius 圆形半径
|
||||
/// @param density 物体密度
|
||||
/// @brief 添加圆形夹具
|
||||
/// @param radius 圆形半径
|
||||
/// @param density 物体密度
|
||||
/// @param
|
||||
Fixture* AddCircleShape(float radius, float density, float friction = 0.2f, float restitution = 0.f,
|
||||
bool is_sensor = false);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加矩形夹具
|
||||
/// @param size 矩形大小
|
||||
/// @param density 物体密度
|
||||
/// @brief 添加矩形夹具
|
||||
/// @param size 矩形大小
|
||||
/// @param density 物体密度
|
||||
Fixture* AddRectShape(Vec2 const& size, float density, float friction = 0.2f, float restitution = 0.f,
|
||||
bool is_sensor = false);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加多边形夹具
|
||||
/// @param vertexs 多边形端点
|
||||
/// @param density 物体密度
|
||||
/// @brief 添加多边形夹具
|
||||
/// @param vertexs 多边形端点
|
||||
/// @param density 物体密度
|
||||
Fixture* AddPolygonShape(Vector<Point> const& vertexs, float density, float friction = 0.2f,
|
||||
float restitution = 0.f, bool is_sensor = false);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加线段形夹具
|
||||
/// @param p1 线段起点
|
||||
/// @param p2 线段终点
|
||||
/// @param density 物体密度
|
||||
/// @brief 添加线段形夹具
|
||||
/// @param p1 线段起点
|
||||
/// @param p2 线段终点
|
||||
/// @param density 物体密度
|
||||
Fixture* AddEdgeShape(Point const& p1, Point const& p2, float density, float friction = 0.2f,
|
||||
float restitution = 0.f, bool is_sensor = false);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加链条形夹具
|
||||
/// @param vertexs 链条端点
|
||||
/// @param loop 是否闭合
|
||||
/// @param density 物体密度
|
||||
/// @brief 添加链条形夹具
|
||||
/// @param vertexs 链条端点
|
||||
/// @param loop 是否闭合
|
||||
/// @param density 物体密度
|
||||
Fixture* AddChainShape(Vector<Point> const& vertexs, bool loop, float density, float friction = 0.2f,
|
||||
float restitution = 0.f, bool is_sensor = false);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除夹具
|
||||
/// @brief 移除夹具
|
||||
void RemoveFixture(FixturePtr fixture);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取夹具列表
|
||||
/// @brief 获取夹具列表
|
||||
FixtureList GetFixtureList() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取接触边列表
|
||||
/// @brief 获取接触边列表
|
||||
ContactEdgeList GetContactList() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取类别码
|
||||
/// @brief 获取类别码
|
||||
uint16_t GetCategoryBits() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置类别码
|
||||
/// @brief 设置类别码
|
||||
void SetCategoryBits(uint16_t category_bits);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取碰撞掩码
|
||||
/// @brief 获取碰撞掩码
|
||||
uint16_t GetMaskBits() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置碰撞掩码
|
||||
/// @brief 设置碰撞掩码
|
||||
void SetMaskBits(uint16_t mask_bits);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取组索引
|
||||
/// @brief 获取组索引
|
||||
int16_t GetGroupIndex() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置组索引
|
||||
/// @brief 设置组索引
|
||||
void SetGroupIndex(int16_t index);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取旋转角度
|
||||
/// @brief 获取旋转角度
|
||||
float GetBodyRotation() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置旋转角度
|
||||
/// @brief 设置旋转角度
|
||||
void SetBodyRotation(float angle);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体位置
|
||||
/// @brief 获取物体位置
|
||||
Point GetBodyPosition() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置物体位置
|
||||
/// @brief 设置物体位置
|
||||
void SetBodyPosition(Point const& pos);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 位置和旋转变换
|
||||
/// @brief 位置和旋转变换
|
||||
void SetBodyTransform(Point const& pos, float angle);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取质量 [kg]
|
||||
/// @brief 获取质量 [kg]
|
||||
float GetMass() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取惯性
|
||||
/// @brief 获取惯性
|
||||
float GetInertia() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取质量数据
|
||||
/// @param[out] mass 物体质量 [kg]
|
||||
/// @param[out] center 质心位置
|
||||
/// @param[out] inertia 惯性
|
||||
/// @brief 获取质量数据
|
||||
/// @param[out] mass 物体质量 [kg]
|
||||
/// @param[out] center 质心位置
|
||||
/// @param[out] inertia 惯性
|
||||
void GetMassData(float* mass, Point* center, float* inertia) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置质量数据
|
||||
/// @param mass 物体质量 [kg]
|
||||
/// @param center 质心位置
|
||||
/// @param inertia 惯性
|
||||
/// @brief 设置质量数据
|
||||
/// @param mass 物体质量 [kg]
|
||||
/// @param center 质心位置
|
||||
/// @param inertia 惯性
|
||||
void SetMassData(float mass, Point const& center, float inertia);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 重置质量数据
|
||||
/// @brief 重置质量数据
|
||||
void ResetMassData();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取世界坐标系上的点在物体上的位置
|
||||
/// @brief 获取世界坐标系上的点在物体上的位置
|
||||
Point GetLocalPoint(Point const& world) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体上的点在世界坐标系的位置
|
||||
/// @brief 获取物体上的点在世界坐标系的位置
|
||||
Point GetWorldPoint(Point const& local) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体质心相对于物体的位置
|
||||
/// @brief 获取物体质心相对于物体的位置
|
||||
Point GetLocalCenter() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体质心位置
|
||||
/// @brief 获取物体质心位置
|
||||
Point GetWorldCenter() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体类型
|
||||
/// @brief 获取物体类型
|
||||
Type GetType() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置物体类型
|
||||
/// @brief 设置物体类型
|
||||
void SetType(Type type);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体受重力的比例
|
||||
/// @brief 获取物体受重力的比例
|
||||
float GetGravityScale() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置物体受重力的比例
|
||||
/// @brief 设置物体受重力的比例
|
||||
void SetGravityScale(float scale);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 施力
|
||||
/// @param force 力的大小和方向
|
||||
/// @param point 施力点
|
||||
/// @param wake 是否唤醒物体
|
||||
/// @brief 施力
|
||||
/// @param force 力的大小和方向
|
||||
/// @param point 施力点
|
||||
/// @param wake 是否唤醒物体
|
||||
void ApplyForce(Vec2 const& force, Point const& point, bool wake = true);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 给物体中心施力
|
||||
/// @param force 力的大小和方向
|
||||
/// @param wake 是否唤醒物体
|
||||
/// @brief 给物体中心施力
|
||||
/// @param force 力的大小和方向
|
||||
/// @param wake 是否唤醒物体
|
||||
void ApplyForceToCenter(Vec2 const& force, bool wake = true);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 施加扭矩
|
||||
/// @param torque 扭矩
|
||||
/// @param wake 是否唤醒物体
|
||||
/// @brief 施加扭矩
|
||||
/// @param torque 扭矩
|
||||
/// @param wake 是否唤醒物体
|
||||
void ApplyTorque(float torque, bool wake = false);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 旋转角度是否固定
|
||||
/// @brief 旋转角度是否固定
|
||||
bool IsIgnoreRotation() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置是否固定旋转角度
|
||||
/// @brief 设置是否固定旋转角度
|
||||
void SetIgnoreRotation(bool flag);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否是子弹物体
|
||||
/// @brief 是否是子弹物体
|
||||
bool IsBullet() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置物体是否是子弹物体
|
||||
/// @brief 设置物体是否是子弹物体
|
||||
void SetBullet(bool flag);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否处于唤醒状态
|
||||
/// @brief 是否处于唤醒状态
|
||||
bool IsAwake() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置唤醒状态
|
||||
/// @brief 设置唤醒状态
|
||||
void SetAwake(bool flag);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否启用休眠
|
||||
/// @brief 是否启用休眠
|
||||
bool IsSleepingAllowed() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置是否允许休眠
|
||||
/// @brief 设置是否允许休眠
|
||||
void SetSleepingAllowed(bool flag);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否启用
|
||||
/// @brief 是否启用
|
||||
bool IsActive() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置启用状态
|
||||
/// @brief 设置启用状态
|
||||
void SetActive(bool flag);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体所在物理世界
|
||||
/// @brief 获取物体所在物理世界
|
||||
World* GetWorld() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体绑定的角色
|
||||
/// @brief 获取物体绑定的角色
|
||||
Actor* GetActor() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置物体绑定的角色
|
||||
/// @brief 设置物体绑定的角色
|
||||
void SetActor(Actor* actor);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 将物体信息更新到角色
|
||||
/// @brief 将物体信息更新到角色
|
||||
void UpdateActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 将角色信息更新到物体
|
||||
/// @brief 将角色信息更新到物体
|
||||
void UpdateFromActor();
|
||||
|
||||
b2Body* GetB2Body() const;
|
||||
|
|
@ -320,11 +320,11 @@ public:
|
|||
|
||||
private:
|
||||
/// \~chinese
|
||||
/// @brief 销毁物体
|
||||
/// @brief 销毁物体
|
||||
void UpdateFixtureFilter(b2Fixture* fixture);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 销毁物体
|
||||
/// @brief 销毁物体
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -34,74 +34,74 @@ class Body;
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物理接触
|
||||
/// @brief 物理接触
|
||||
class KGE_API Contact
|
||||
{
|
||||
public:
|
||||
Contact();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否有效
|
||||
/// @brief 是否有效
|
||||
bool IsValid() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否是接触
|
||||
/// @brief 是否是接触
|
||||
bool IsTouching() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 启用或禁用 (仅作用于一个时间步)
|
||||
/// @brief 启用或禁用 (仅作用于一个时间步)
|
||||
void SetEnabled(bool flag);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否启用
|
||||
/// @brief 是否启用
|
||||
bool IsEnabled() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体A的夹具
|
||||
/// @brief 获取物体A的夹具
|
||||
Fixture* GetFixtureA() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体B的夹具
|
||||
/// @brief 获取物体B的夹具
|
||||
Fixture* GetFixtureB() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体A
|
||||
/// @brief 获取物体A
|
||||
Body* GetBodyA() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体B
|
||||
/// @brief 获取物体B
|
||||
Body* GetBodyB() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置摩擦力
|
||||
/// @brief 设置摩擦力
|
||||
void SetFriction(float friction);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取摩擦力
|
||||
/// @brief 获取摩擦力
|
||||
float GetFriction() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 重置摩擦力
|
||||
/// @brief 重置摩擦力
|
||||
void ResetFriction();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置弹性恢复
|
||||
/// @brief 设置弹性恢复
|
||||
void SetRestitution(float restitution);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取弹性恢复
|
||||
/// @brief 获取弹性恢复
|
||||
float GetRestitution() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 重置弹性恢复
|
||||
/// @brief 重置弹性恢复
|
||||
void ResetRestitution();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置切线速度
|
||||
/// @brief 设置切线速度
|
||||
void SetTangentSpeed(float speed);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取切线速度
|
||||
/// @brief 获取切线速度
|
||||
float GetTangentSpeed() const;
|
||||
|
||||
b2Contact* GetB2Contact() const;
|
||||
|
|
@ -116,7 +116,7 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物理接触列表
|
||||
/// @brief 物理接触列表
|
||||
class ContactList
|
||||
{
|
||||
template <typename _Ty>
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace physics
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 接触边
|
||||
/// @brief 接触边
|
||||
class KGE_API ContactEdge
|
||||
{
|
||||
public:
|
||||
|
|
@ -40,15 +40,15 @@ public:
|
|||
ContactEdge(b2ContactEdge* edge);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否有效
|
||||
/// @brief 是否有效
|
||||
bool IsValid() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取接触物体
|
||||
/// @brief 获取接触物体
|
||||
Body* GetOtherBody() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取接触
|
||||
/// @brief 获取接触
|
||||
Contact GetContact() const;
|
||||
|
||||
b2ContactEdge* GetB2ContactEdge() const;
|
||||
|
|
@ -63,7 +63,7 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物理接触边列表
|
||||
/// @brief 物理接触边列表
|
||||
class ContactEdgeList
|
||||
{
|
||||
template <typename _Ty>
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ KGE_DECLARE_SMART_PTR(ContactEndEvent);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物理接触开始事件
|
||||
/// @brief 物理接触开始事件
|
||||
class KGE_API ContactBeginEvent : public Event
|
||||
{
|
||||
public:
|
||||
Contact contact; ///< 产生的接触
|
||||
Contact contact; ///< 产生的接触
|
||||
|
||||
ContactBeginEvent();
|
||||
|
||||
|
|
@ -47,11 +47,11 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物理接触结束事件
|
||||
/// @brief 物理接触结束事件
|
||||
class KGE_API ContactEndEvent : public Event
|
||||
{
|
||||
public:
|
||||
Contact contact; ///< 产生的接触
|
||||
Contact contact; ///< 产生的接触
|
||||
|
||||
ContactEndEvent();
|
||||
|
||||
|
|
|
|||
|
|
@ -35,18 +35,18 @@ KGE_DECLARE_SMART_PTR(Fixture);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物理夹具
|
||||
/// @brief 物理夹具
|
||||
class Fixture : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 夹具参数
|
||||
/// @brief 夹具参数
|
||||
struct Param
|
||||
{
|
||||
float density = 0.0f; ///< 密度
|
||||
float friction = 0.2f; ///< 摩擦力
|
||||
float restitution = 0.0f; ///< 弹性恢复
|
||||
bool is_sensor = false; ///< 是否是接触传感器
|
||||
float density = 0.0f; ///< 密度
|
||||
float friction = 0.2f; ///< 摩擦力
|
||||
float restitution = 0.0f; ///< 弹性恢复
|
||||
bool is_sensor = false; ///< 是否是接触传感器
|
||||
|
||||
Param() {}
|
||||
|
||||
|
|
@ -60,44 +60,44 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建圆形夹具
|
||||
/// @param body 添加夹具的物体
|
||||
/// @param param 夹具参数
|
||||
/// @param radius 圆形半径
|
||||
/// @param offset 偏移量
|
||||
/// @brief 创建圆形夹具
|
||||
/// @param body 添加夹具的物体
|
||||
/// @param param 夹具参数
|
||||
/// @param radius 圆形半径
|
||||
/// @param offset 偏移量
|
||||
static FixturePtr CreateCircle(Body* body, Param const& param, float radius, Point const& offset = Point());
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建矩形夹具
|
||||
/// @param body 添加夹具的物体
|
||||
/// @param param 夹具参数
|
||||
/// @param size 矩形大小
|
||||
/// @param offset 偏移量
|
||||
/// @param rotation 旋转角度
|
||||
/// @brief 创建矩形夹具
|
||||
/// @param body 添加夹具的物体
|
||||
/// @param param 夹具参数
|
||||
/// @param size 矩形大小
|
||||
/// @param offset 偏移量
|
||||
/// @param rotation 旋转角度
|
||||
static FixturePtr CreateRect(Body* body, Param const& param, Size const& size, Point const& offset = Point(),
|
||||
float rotation = 0.f);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建多边形夹具
|
||||
/// @param body 添加夹具的物体
|
||||
/// @param param 夹具参数
|
||||
/// @param vertexs 多边形顶点
|
||||
/// @brief 创建多边形夹具
|
||||
/// @param body 添加夹具的物体
|
||||
/// @param param 夹具参数
|
||||
/// @param vertexs 多边形顶点
|
||||
static FixturePtr CreatePolygon(Body* body, Param const& param, Vector<Point> const& vertexs);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建边夹具
|
||||
/// @param body 添加夹具的物体
|
||||
/// @param param 夹具参数
|
||||
/// @param p1 边的起点
|
||||
/// @param p2 边的终点
|
||||
/// @brief 创建边夹具
|
||||
/// @param body 添加夹具的物体
|
||||
/// @param param 夹具参数
|
||||
/// @param p1 边的起点
|
||||
/// @param p2 边的终点
|
||||
static FixturePtr CreateEdge(Body* body, Param const& param, Point const& p1, Point const& p2);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建链条夹具
|
||||
/// @param body 添加夹具的物体
|
||||
/// @param param 夹具参数
|
||||
/// @param vertexs 链条顶点
|
||||
/// @param loop 是否连接链条的起点和终点
|
||||
/// @brief 创建链条夹具
|
||||
/// @param body 添加夹具的物体
|
||||
/// @param param 夹具参数
|
||||
/// @param vertexs 链条顶点
|
||||
/// @param loop 是否连接链条的起点和终点
|
||||
static FixturePtr CreateChain(Body* body, Param const& param, Vector<Point> const& vertexs, bool loop = false);
|
||||
|
||||
Fixture();
|
||||
|
|
@ -105,52 +105,52 @@ public:
|
|||
virtual ~Fixture();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否有效
|
||||
/// @brief 是否有效
|
||||
bool IsValid() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取夹具所在的物体
|
||||
/// @brief 获取夹具所在的物体
|
||||
Body* GetBody() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否是接触传感器
|
||||
/// @brief 是否是接触传感器
|
||||
bool IsSensor() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置夹具是否是接触传感器
|
||||
/// @details 接触传感器只会产生物理接触,而不会影响物体运动
|
||||
/// @brief 设置夹具是否是接触传感器
|
||||
/// @details 接触传感器只会产生物理接触,而不会影响物体运动
|
||||
void SetSensor(bool sensor);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取夹具的质量数据
|
||||
/// @brief 获取夹具的质量数据
|
||||
void GetMassData(float* mass, Point* center, float* inertia) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取密度
|
||||
/// @brief 获取密度
|
||||
float GetDensity() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置密度
|
||||
/// @brief 设置密度
|
||||
void SetDensity(float density);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取摩擦力 [N]
|
||||
/// @brief 获取摩擦力 [N]
|
||||
float GetFriction() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置摩擦力 [N]
|
||||
/// @brief 设置摩擦力 [N]
|
||||
void SetFriction(float friction);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取弹性恢复
|
||||
/// @brief 获取弹性恢复
|
||||
float GetRestitution() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置弹性恢复
|
||||
/// @brief 设置弹性恢复
|
||||
void SetRestitution(float restitution);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 点测试
|
||||
/// @brief 点测试
|
||||
bool TestPoint(const Point& p) const;
|
||||
|
||||
b2Fixture* GetB2Fixture() const;
|
||||
|
|
@ -165,7 +165,7 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物理夹具列表
|
||||
/// @brief 物理夹具列表
|
||||
class FixtureList
|
||||
{
|
||||
template <typename _Ty>
|
||||
|
|
|
|||
|
|
@ -45,34 +45,34 @@ KGE_DECLARE_SMART_PTR(WheelJoint);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 关节
|
||||
/// @brief 关节
|
||||
class KGE_API Joint : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 关节类型
|
||||
/// @brief 关节类型
|
||||
enum class Type
|
||||
{
|
||||
Unknown = 0, ///< 未知
|
||||
Revolute, ///< 旋转关节
|
||||
Prismatic, ///< 平移关节
|
||||
Distance, ///< 固定距离关节
|
||||
Pulley, ///< 滑轮关节
|
||||
Mouse, ///< 鼠标关节
|
||||
Gear, ///< 齿轮关节
|
||||
Wheel, ///< 轮关节
|
||||
Weld, ///< 焊接关节
|
||||
Friction, ///< 摩擦关节
|
||||
Rope, ///< 绳关节
|
||||
Motor ///< 马达关节
|
||||
Unknown = 0, ///< 未知
|
||||
Revolute, ///< 旋转关节
|
||||
Prismatic, ///< 平移关节
|
||||
Distance, ///< 固定距离关节
|
||||
Pulley, ///< 滑轮关节
|
||||
Mouse, ///< 鼠标关节
|
||||
Gear, ///< 齿轮关节
|
||||
Wheel, ///< 轮关节
|
||||
Weld, ///< 焊接关节
|
||||
Friction, ///< 摩擦关节
|
||||
Rope, ///< 绳关节
|
||||
Motor ///< 马达关节
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 关节基础参数
|
||||
/// @brief 关节基础参数
|
||||
struct ParamBase
|
||||
{
|
||||
Body* body_a; ///< 关节连接的物体A
|
||||
Body* body_b; ///< 关节连接的物体B
|
||||
Body* body_a; ///< 关节连接的物体A
|
||||
Body* body_b; ///< 关节连接的物体B
|
||||
|
||||
ParamBase(Body* body_a, Body* body_b)
|
||||
: body_a(body_a)
|
||||
|
|
@ -92,23 +92,23 @@ public:
|
|||
virtual ~Joint();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
/// @brief 初始化关节
|
||||
bool InitJoint(World* world, b2JointDef* joint_def);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关节连接的物体A
|
||||
/// @brief 获取关节连接的物体A
|
||||
BodyPtr GetBodyA() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关节连接的物体B
|
||||
/// @brief 获取关节连接的物体B
|
||||
BodyPtr GetBodyB() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物理世界
|
||||
/// @brief 获取物理世界
|
||||
World* GetWorld() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 销毁关节
|
||||
/// @brief 销毁关节
|
||||
void Destroy();
|
||||
|
||||
b2Joint* GetB2Joint() const;
|
||||
|
|
@ -121,18 +121,18 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 固定距离关节
|
||||
/// @brief 固定距离关节
|
||||
class KGE_API DistanceJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 固定距离关节参数
|
||||
/// @brief 固定距离关节参数
|
||||
struct Param : public Joint::ParamBase
|
||||
{
|
||||
Point anchor_a; ///< 关节在物体A上的连接点
|
||||
Point anchor_b; ///< 关节在物体B上的连接点
|
||||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
||||
Point anchor_a; ///< 关节在物体A上的连接点
|
||||
Point anchor_b; ///< 关节在物体B上的连接点
|
||||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
||||
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor_a, Point const& anchor_b, float frequency_hz = 0.f,
|
||||
float damping_ratio = 0.f)
|
||||
|
|
@ -152,39 +152,39 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建固定距离关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
/// @brief 创建固定距离关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
static DistanceJointPtr Create(World* world, Param const& param);
|
||||
|
||||
DistanceJoint();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
/// @brief 初始化关节
|
||||
bool InitJoint(World* world, Param const& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置关节长度
|
||||
/// @brief 设置关节长度
|
||||
void SetLength(float length);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关节长度
|
||||
/// @brief 获取关节长度
|
||||
float GetLength() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置弹簧响应速度 [赫兹]
|
||||
/// @brief 设置弹簧响应速度 [赫兹]
|
||||
void SetFrequency(float hz);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取弹簧响应速度 [赫兹]
|
||||
/// @brief 获取弹簧响应速度 [赫兹]
|
||||
float GetFrequency() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置阻尼率
|
||||
/// @brief 设置阻尼率
|
||||
void SetDampingRatio(float ratio);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取阻尼率
|
||||
/// @brief 获取阻尼率
|
||||
float GetDampingRatio() const;
|
||||
|
||||
private:
|
||||
|
|
@ -192,15 +192,15 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 摩擦关节
|
||||
/// @brief 摩擦关节
|
||||
class KGE_API FrictionJoint : public Joint
|
||||
{
|
||||
public:
|
||||
struct Param : public Joint::ParamBase
|
||||
{
|
||||
Point anchor; ///< 摩擦作用点
|
||||
float max_force; ///< 最大摩擦力
|
||||
float max_torque; ///< 最大扭力
|
||||
Point anchor; ///< 摩擦作用点
|
||||
float max_force; ///< 最大摩擦力
|
||||
float max_torque; ///< 最大扭力
|
||||
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor, float max_force = 0.f, float max_torque = 0.f)
|
||||
: ParamBase(body_a, body_b)
|
||||
|
|
@ -217,31 +217,31 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建摩擦关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
/// @brief 创建摩擦关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
static FrictionJointPtr Create(World* world, Param const& param);
|
||||
|
||||
FrictionJoint();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
/// @brief 初始化关节
|
||||
bool InitJoint(World* world, Param const& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置最大摩擦力
|
||||
/// @brief 设置最大摩擦力
|
||||
void SetMaxForce(float force);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取最大摩擦力
|
||||
/// @brief 获取最大摩擦力
|
||||
float GetMaxForce() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置最大转矩
|
||||
/// @brief 设置最大转矩
|
||||
void SetMaxTorque(float torque);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取最大转矩
|
||||
/// @brief 获取最大转矩
|
||||
float GetMaxTorque() const;
|
||||
|
||||
private:
|
||||
|
|
@ -249,17 +249,17 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 齿轮关节
|
||||
/// @brief 齿轮关节
|
||||
class KGE_API GearJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 齿轮关节参数
|
||||
/// @brief 齿轮关节参数
|
||||
struct Param : public Joint::ParamBase
|
||||
{
|
||||
Joint* joint_a; ///< 关节A(旋转关节/平移关节)
|
||||
Joint* joint_b; ///< 关节B(旋转关节/平移关节)
|
||||
float ratio; ///< 齿轮传动比
|
||||
Joint* joint_a; ///< 关节A(旋转关节/平移关节)
|
||||
Joint* joint_b; ///< 关节B(旋转关节/平移关节)
|
||||
float ratio; ///< 齿轮传动比
|
||||
|
||||
Param(Joint* joint_a, Joint* joint_b, float ratio = 1.f)
|
||||
: ParamBase(nullptr, nullptr)
|
||||
|
|
@ -276,23 +276,23 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建齿轮关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
/// @brief 创建齿轮关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
static GearJointPtr Create(World* world, Param const& param);
|
||||
|
||||
GearJoint();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
/// @brief 初始化关节
|
||||
bool InitJoint(World* world, Param const& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设定齿轮传动比
|
||||
/// @brief 设定齿轮传动比
|
||||
void SetRatio(float ratio);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取齿轮传动比
|
||||
/// @brief 获取齿轮传动比
|
||||
float GetRatio() const;
|
||||
|
||||
private:
|
||||
|
|
@ -300,17 +300,17 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 马达关节
|
||||
/// @brief 马达关节
|
||||
class KGE_API MotorJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 马达关节参数
|
||||
/// @brief 马达关节参数
|
||||
struct Param : public Joint::ParamBase
|
||||
{
|
||||
float max_force; ///< 最大摩擦力
|
||||
float max_torque; ///< 最大转矩
|
||||
float correction_factor; ///< 位置矫正因子(范围 0-1)
|
||||
float max_force; ///< 最大摩擦力
|
||||
float max_torque; ///< 最大转矩
|
||||
float correction_factor; ///< 位置矫正因子(范围 0-1)
|
||||
|
||||
Param(Body* body_a, Body* body_b, float max_force = 1.f, float max_torque = 100.f,
|
||||
float correction_factor = 0.3f)
|
||||
|
|
@ -329,31 +329,31 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建马达关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
/// @brief 创建马达关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
static MotorJointPtr Create(World* world, Param const& param);
|
||||
|
||||
MotorJoint();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
/// @brief 初始化关节
|
||||
bool InitJoint(World* world, Param const& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置最大摩擦力
|
||||
/// @brief 设置最大摩擦力
|
||||
void SetMaxForce(float force);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取最大摩擦力
|
||||
/// @brief 获取最大摩擦力
|
||||
float GetMaxForce() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置最大转矩
|
||||
/// @brief 设置最大转矩
|
||||
void SetMaxTorque(float torque);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取最大转矩
|
||||
/// @brief 获取最大转矩
|
||||
float GetMaxTorque() const;
|
||||
|
||||
private:
|
||||
|
|
@ -361,22 +361,22 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 平移关节
|
||||
/// @brief 平移关节
|
||||
class KGE_API PrismaticJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 平移关节参数
|
||||
/// @brief 平移关节参数
|
||||
struct Param : public Joint::ParamBase
|
||||
{
|
||||
Point anchor; ///< 关节位置
|
||||
Vec2 axis; ///< 物体A滑动的方向
|
||||
bool enable_limit; ///< 是否启用限制
|
||||
float lower_translation; ///< 移动的最小限制,与方向同向为正,反向为负,启用限制后才有效果
|
||||
float upper_translation; ///< 移动的最大限制,与方向同向为正,反向为负,启用限制后才有效果
|
||||
bool enable_motor; ///< 是否启用马达
|
||||
float max_motor_force; ///< 最大马达力 [N]
|
||||
float motor_speed; ///< 马达转速 [degree/s]
|
||||
Point anchor; ///< 关节位置
|
||||
Vec2 axis; ///< 物体A滑动的方向
|
||||
bool enable_limit; ///< 是否启用限制
|
||||
float lower_translation; ///< 移动的最小限制,与方向同向为正,反向为负,启用限制后才有效果
|
||||
float upper_translation; ///< 移动的最大限制,与方向同向为正,反向为负,启用限制后才有效果
|
||||
bool enable_motor; ///< 是否启用马达
|
||||
float max_motor_force; ///< 最大马达力 [N]
|
||||
float motor_speed; ///< 马达转速 [degree/s]
|
||||
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor, Vec2 const& axis, bool enable_limit = false,
|
||||
float lower_translation = 0.0f, float upper_translation = 0.0f, bool enable_motor = false,
|
||||
|
|
@ -403,71 +403,71 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建平移关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
/// @brief 创建平移关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
static PrismaticJointPtr Create(World* world, Param const& param);
|
||||
|
||||
PrismaticJoint();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
/// @brief 初始化关节
|
||||
bool InitJoint(World* world, Param const& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取参考角
|
||||
/// @brief 获取参考角
|
||||
float GetReferenceAngle() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关节转换
|
||||
/// @brief 获取关节转换
|
||||
float GetJointTranslation() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关节速度
|
||||
/// @brief 获取关节速度
|
||||
float GetJointSpeed() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否启用关节限制
|
||||
/// @brief 是否启用关节限制
|
||||
bool IsLimitEnabled() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置是否启用关节限制
|
||||
/// @brief 设置是否启用关节限制
|
||||
void EnableLimit(bool flag);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取平移最小限制
|
||||
/// @brief 获取平移最小限制
|
||||
float GetLowerLimit() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取平移最大限制
|
||||
/// @brief 获取平移最大限制
|
||||
float GetUpperLimit() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置关节限制
|
||||
/// @brief 设置关节限制
|
||||
void SetLimits(float lower, float upper);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否启用马达
|
||||
/// @brief 是否启用马达
|
||||
bool IsMotorEnabled() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置是否启用马达
|
||||
/// @brief 设置是否启用马达
|
||||
void EnableMotor(bool flag);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置马达转速 [degree/s]
|
||||
/// @brief 设置马达转速 [degree/s]
|
||||
void SetMotorSpeed(float speed);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取马达转速 [degree/s]
|
||||
/// @brief 获取马达转速 [degree/s]
|
||||
float GetMotorSpeed() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置最大马达力 [N]
|
||||
/// @brief 设置最大马达力 [N]
|
||||
void SetMaxMotorForce(float force);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取最大马达力 [N]
|
||||
/// @brief 获取最大马达力 [N]
|
||||
float GetMaxMotorForce() const;
|
||||
|
||||
private:
|
||||
|
|
@ -475,19 +475,19 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 滑轮关节
|
||||
/// @brief 滑轮关节
|
||||
class KGE_API PulleyJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 滑轮关节参数
|
||||
/// @brief 滑轮关节参数
|
||||
struct Param : public Joint::ParamBase
|
||||
{
|
||||
Point anchor_a; ///< 关节在物体A上的作用点
|
||||
Point anchor_b; ///< 关节在物体B上的作用点
|
||||
Point ground_anchor_a; ///< 物体A对应的滑轮的位置
|
||||
Point ground_anchor_b; ///< 物体B对应的滑轮的位置
|
||||
float ratio; ///< 滑轮比,关节传动时,滑轮上升和下降的两头的位移比例
|
||||
Point anchor_a; ///< 关节在物体A上的作用点
|
||||
Point anchor_b; ///< 关节在物体B上的作用点
|
||||
Point ground_anchor_a; ///< 物体A对应的滑轮的位置
|
||||
Point ground_anchor_b; ///< 物体B对应的滑轮的位置
|
||||
float ratio; ///< 滑轮比,关节传动时,滑轮上升和下降的两头的位移比例
|
||||
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor_a, Point const& anchor_b, Point const& ground_anchor_a,
|
||||
Point const& ground_anchor_b, float ratio = 1.0f)
|
||||
|
|
@ -508,43 +508,43 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建滑轮关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
/// @brief 创建滑轮关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
static PulleyJointPtr Create(World* world, Param const& param);
|
||||
|
||||
PulleyJoint();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
/// @brief 初始化关节
|
||||
bool InitJoint(World* world, Param const& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物体A对应的滑轮的位置
|
||||
/// @brief 物体A对应的滑轮的位置
|
||||
Point GetGroundAnchorA() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物体B对应的滑轮的位置
|
||||
/// @brief 物体B对应的滑轮的位置
|
||||
Point GetGroundAnchorB() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取滑轮传动比
|
||||
/// @brief 获取滑轮传动比
|
||||
float GetRatio() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体A与滑轮的距离
|
||||
/// @brief 获取物体A与滑轮的距离
|
||||
float GetLengthA() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体B与滑轮的距离
|
||||
/// @brief 获取物体B与滑轮的距离
|
||||
float GetLengthB() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体A与滑轮的当前距离
|
||||
/// @brief 获取物体A与滑轮的当前距离
|
||||
float GetCurrentLengthA() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体B与滑轮的当前距离
|
||||
/// @brief 获取物体B与滑轮的当前距离
|
||||
float GetCurrentLengthB() const;
|
||||
|
||||
private:
|
||||
|
|
@ -552,21 +552,21 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 旋转关节
|
||||
/// @brief 旋转关节
|
||||
class KGE_API RevoluteJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 旋转关节参数
|
||||
/// @brief 旋转关节参数
|
||||
struct Param : public Joint::ParamBase
|
||||
{
|
||||
Point anchor; ///< 关节位置
|
||||
bool enable_limit; ///< 是否启用限制
|
||||
float lower_angle; ///< 移动的最小限制,与方向同向为正,反向为负,启用限制后才有效果
|
||||
float upper_angle; ///< 移动的最大限制,与方向同向为正,反向为负,启用限制后才有效果
|
||||
bool enable_motor; ///< 是否启用马达
|
||||
float max_motor_torque; ///< 最大马达力 [N]
|
||||
float motor_speed; ///< 马达转速 [degree/s]
|
||||
Point anchor; ///< 关节位置
|
||||
bool enable_limit; ///< 是否启用限制
|
||||
float lower_angle; ///< 移动的最小限制,与方向同向为正,反向为负,启用限制后才有效果
|
||||
float upper_angle; ///< 移动的最大限制,与方向同向为正,反向为负,启用限制后才有效果
|
||||
bool enable_motor; ///< 是否启用马达
|
||||
float max_motor_torque; ///< 最大马达力 [N]
|
||||
float motor_speed; ///< 马达转速 [degree/s]
|
||||
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor, bool enable_limit = false, float lower_angle = 0.0f,
|
||||
float upper_angle = 0.0f, bool enable_motor = false, float max_motor_torque = 0.0f,
|
||||
|
|
@ -592,71 +592,71 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建旋转关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
/// @brief 创建旋转关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
static RevoluteJointPtr Create(World* world, Param const& param);
|
||||
|
||||
RevoluteJoint();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
/// @brief 初始化关节
|
||||
bool InitJoint(World* world, Param const& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取参考角
|
||||
/// @brief 获取参考角
|
||||
float GetReferenceAngle() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关节角度
|
||||
/// @brief 获取关节角度
|
||||
float GetJointAngle() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关节速度
|
||||
/// @brief 获取关节速度
|
||||
float GetJointSpeed() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否启用关节限制
|
||||
/// @brief 是否启用关节限制
|
||||
bool IsLimitEnabled() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置是否启用关节限制
|
||||
/// @brief 设置是否启用关节限制
|
||||
void EnableLimit(bool flag);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取平移最小限制
|
||||
/// @brief 获取平移最小限制
|
||||
float GetLowerLimit() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取平移最大限制
|
||||
/// @brief 获取平移最大限制
|
||||
float GetUpperLimit() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置关节限制
|
||||
/// @brief 设置关节限制
|
||||
void SetLimits(float lower, float upper);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否启用马达
|
||||
/// @brief 是否启用马达
|
||||
bool IsMotorEnabled() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置是否启用马达
|
||||
/// @brief 设置是否启用马达
|
||||
void EnableMotor(bool flag);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置马达转速 [degree/s]
|
||||
/// @brief 设置马达转速 [degree/s]
|
||||
void SetMotorSpeed(float speed);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取马达转速 [degree/s]
|
||||
/// @brief 获取马达转速 [degree/s]
|
||||
float GetMotorSpeed() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置最大马达转矩 [N/m]
|
||||
/// @brief 设置最大马达转矩 [N/m]
|
||||
void SetMaxMotorTorque(float torque);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取最大马达转矩 [N/m]
|
||||
/// @brief 获取最大马达转矩 [N/m]
|
||||
float GetMaxMotorTorque() const;
|
||||
|
||||
private:
|
||||
|
|
@ -664,17 +664,17 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 绳关节
|
||||
/// @brief 绳关节
|
||||
class KGE_API RopeJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 绳关节参数
|
||||
/// @brief 绳关节参数
|
||||
struct Param : public Joint::ParamBase
|
||||
{
|
||||
Point local_anchor_a; ///< 关节在物体A上的连接点
|
||||
Point local_anchor_b; ///< 关节在物体B上的连接点
|
||||
float max_length; ///< 绳索最大长度
|
||||
Point local_anchor_a; ///< 关节在物体A上的连接点
|
||||
Point local_anchor_b; ///< 关节在物体B上的连接点
|
||||
float max_length; ///< 绳索最大长度
|
||||
|
||||
Param(Body* body_a, Body* body_b, Point const& local_anchor_a, Point const& local_anchor_b,
|
||||
float max_length = 0.f)
|
||||
|
|
@ -693,23 +693,23 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建绳关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
/// @brief 创建绳关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
static RopeJointPtr Create(World* world, Param const& param);
|
||||
|
||||
RopeJoint();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
/// @brief 初始化关节
|
||||
bool InitJoint(World* world, Param const& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置关节最大长度
|
||||
/// @brief 设置关节最大长度
|
||||
void SetMaxLength(float length);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关节最大长度
|
||||
/// @brief 获取关节最大长度
|
||||
float GetMaxLength() const;
|
||||
|
||||
private:
|
||||
|
|
@ -717,17 +717,17 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 焊接关节
|
||||
/// @brief 焊接关节
|
||||
class KGE_API WeldJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 焊接关节参数
|
||||
/// @brief 焊接关节参数
|
||||
struct Param : public Joint::ParamBase
|
||||
{
|
||||
Point anchor; ///< 焊接位置
|
||||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
||||
Point anchor; ///< 焊接位置
|
||||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
||||
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor, float frequency_hz = 0.f, float damping_ratio = 0.f)
|
||||
: ParamBase(body_a, body_b)
|
||||
|
|
@ -744,35 +744,35 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建焊接关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
/// @brief 创建焊接关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
static WeldJointPtr Create(World* world, Param const& param);
|
||||
|
||||
WeldJoint();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
/// @brief 初始化关节
|
||||
bool InitJoint(World* world, Param const& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物体B相对于物体A的角度
|
||||
/// @brief 获取物体B相对于物体A的角度
|
||||
float GetReferenceAngle() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置弹簧响应速度 [赫兹]
|
||||
/// @brief 设置弹簧响应速度 [赫兹]
|
||||
void SetFrequency(float hz);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取弹簧响应速度 [赫兹]
|
||||
/// @brief 获取弹簧响应速度 [赫兹]
|
||||
float GetFrequency() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置阻尼率
|
||||
/// @brief 设置阻尼率
|
||||
void SetDampingRatio(float ratio);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取阻尼率
|
||||
/// @brief 获取阻尼率
|
||||
float GetDampingRatio() const;
|
||||
|
||||
private:
|
||||
|
|
@ -780,21 +780,21 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 轮关节
|
||||
/// @brief 轮关节
|
||||
class KGE_API WheelJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 轮关节参数
|
||||
/// @brief 轮关节参数
|
||||
struct Param : public Joint::ParamBase
|
||||
{
|
||||
Point anchor; ///< 轮关节位置
|
||||
Vec2 axis; ///< 物体A滑动方向
|
||||
bool enable_motor; ///< 是否启用马达
|
||||
float max_motor_torque; ///< 最大马达力 [N]
|
||||
float motor_speed; ///< 马达转速 [degree/s]
|
||||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||
float damping_ratio; ///< 弹簧阻尼率,值越大关节运动阻尼越大
|
||||
Point anchor; ///< 轮关节位置
|
||||
Vec2 axis; ///< 物体A滑动方向
|
||||
bool enable_motor; ///< 是否启用马达
|
||||
float max_motor_torque; ///< 最大马达力 [N]
|
||||
float motor_speed; ///< 马达转速 [degree/s]
|
||||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||
float damping_ratio; ///< 弹簧阻尼率,值越大关节运动阻尼越大
|
||||
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor, Vec2 const& axis, float frequency_hz = 2.0f,
|
||||
float damping_ratio = 0.7f, bool enable_motor = false, float max_motor_torque = 0.0f,
|
||||
|
|
@ -820,71 +820,71 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建轮关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
/// @brief 创建轮关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
static WheelJointPtr Create(World* world, Param const& param);
|
||||
|
||||
WheelJoint();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
/// @brief 初始化关节
|
||||
bool InitJoint(World* world, Param const& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关节当前的平移距离
|
||||
/// @brief 获取关节当前的平移距离
|
||||
float GetJointTranslation() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关节当前的线性速度
|
||||
/// @brief 获取关节当前的线性速度
|
||||
float GetJointLinearSpeed() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关节当前的角度
|
||||
/// @brief 获取关节当前的角度
|
||||
float GetJointAngle() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关节当前的旋转速度
|
||||
/// @brief 获取关节当前的旋转速度
|
||||
float GetJointAngularSpeed() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否启用马达
|
||||
/// @brief 是否启用马达
|
||||
bool IsMotorEnabled() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置是否启用马达
|
||||
/// @brief 设置是否启用马达
|
||||
void EnableMotor(bool flag);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置马达转速 [degree/s]
|
||||
/// @brief 设置马达转速 [degree/s]
|
||||
void SetMotorSpeed(float speed);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取马达转速 [degree/s]
|
||||
/// @brief 获取马达转速 [degree/s]
|
||||
float GetMotorSpeed() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置最大马达转矩 [N/m]
|
||||
/// @brief 设置最大马达转矩 [N/m]
|
||||
void SetMaxMotorTorque(float torque);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取最大马达转矩 [N/m]
|
||||
/// @brief 获取最大马达转矩 [N/m]
|
||||
float GetMaxMotorTorque() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置弹簧响应速度
|
||||
/// @brief 设置弹簧响应速度
|
||||
void SetSpringFrequencyHz(float hz);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取弹簧响应速度
|
||||
/// @brief 获取弹簧响应速度
|
||||
float GetSpringFrequencyHz() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置弹簧阻尼率
|
||||
/// @brief 设置弹簧阻尼率
|
||||
void SetSpringDampingRatio(float ratio);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取弹簧阻尼率
|
||||
/// @brief 获取弹簧阻尼率
|
||||
float GetSpringDampingRatio() const;
|
||||
|
||||
private:
|
||||
|
|
@ -892,19 +892,19 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 鼠标关节
|
||||
/// @details 用于使身体的某个点追踪世界上的指定点,例如让物体追踪鼠标位置
|
||||
/// @brief 鼠标关节
|
||||
/// @details 用于使身体的某个点追踪世界上的指定点,例如让物体追踪鼠标位置
|
||||
class KGE_API MouseJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 鼠标关节参数
|
||||
/// @brief 鼠标关节参数
|
||||
struct Param : public Joint::ParamBase
|
||||
{
|
||||
Point target; ///< 关节作用目标位置
|
||||
float max_force; ///< 作用在物体A上的最大力
|
||||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
||||
Point target; ///< 关节作用目标位置
|
||||
float max_force; ///< 作用在物体A上的最大力
|
||||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
||||
|
||||
Param(Body* body_a, Body* body_b, Point const& target, float max_force, float frequency_hz = 5.0f,
|
||||
float damping_ratio = 0.7f)
|
||||
|
|
@ -924,39 +924,39 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建鼠标关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
/// @brief 创建鼠标关节
|
||||
/// @param world 物理世界
|
||||
/// @param param 关节参数
|
||||
static MouseJointPtr Create(World* world, Param const& param);
|
||||
|
||||
MouseJoint();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
/// @brief 初始化关节
|
||||
bool InitJoint(World* world, Param const& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设定最大摩擦力 [N]
|
||||
/// @brief 设定最大摩擦力 [N]
|
||||
void SetMaxForce(float force);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取最大摩擦力 [N]
|
||||
/// @brief 获取最大摩擦力 [N]
|
||||
float GetMaxForce() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置响应速度 [hz]
|
||||
/// @brief 设置响应速度 [hz]
|
||||
void SetFrequency(float hz);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取响应速度 [hz]
|
||||
/// @brief 获取响应速度 [hz]
|
||||
float GetFrequency() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置阻尼率
|
||||
/// @brief 设置阻尼率
|
||||
void SetDampingRatio(float ratio);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取阻尼率
|
||||
/// @brief 获取阻尼率
|
||||
float GetDampingRatio() const;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ KGE_DECLARE_SMART_PTR(World);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* \defgroup Physics 物理引擎
|
||||
* \defgroup Physics 物理引擎
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -40,7 +40,7 @@ KGE_DECLARE_SMART_PTR(World);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 物理世界
|
||||
* @brief 物理世界
|
||||
*/
|
||||
class KGE_API World : public Stage
|
||||
{
|
||||
|
|
@ -53,53 +53,53 @@ public:
|
|||
virtual ~World();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取重力 [N]
|
||||
/// @brief 获取重力 [N]
|
||||
Vec2 GetGravity() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置重力 [N]
|
||||
/// @brief 设置重力 [N]
|
||||
void SetGravity(Vec2 gravity);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取物理接触列表
|
||||
/// @brief 获取物理接触列表
|
||||
ContactList GetContactList();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取全局缩放比例
|
||||
/// @details 缩放比例是指由物理世界的单位米转换到屏幕像素的比例,默认比例为1:100
|
||||
/// @brief 获取全局缩放比例
|
||||
/// @details 缩放比例是指由物理世界的单位米转换到屏幕像素的比例,默认比例为1:100
|
||||
float GetGlobalScale() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置全局缩放比例
|
||||
/// @details 缩放比例是指由物理世界的单位米转换到屏幕像素的比例,默认比例为1:100
|
||||
/// @brief 设置全局缩放比例
|
||||
/// @details 缩放比例是指由物理世界的单位米转换到屏幕像素的比例,默认比例为1:100
|
||||
void SetGlobalScale(float scale);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 游戏世界单位转换为物理世界单位
|
||||
/// @details 根据全局缩放比例将物理世界的单位米转换为像素单位
|
||||
/// @brief 游戏世界单位转换为物理世界单位
|
||||
/// @details 根据全局缩放比例将物理世界的单位米转换为像素单位
|
||||
float World2Stage(float value) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 游戏世界单位转换为物理世界单位
|
||||
/// @details 根据全局缩放比例将物理世界的单位米转换为像素单位
|
||||
/// @brief 游戏世界单位转换为物理世界单位
|
||||
/// @details 根据全局缩放比例将物理世界的单位米转换为像素单位
|
||||
Vec2 World2Stage(const b2Vec2& pos) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物理世界单位转换为游戏世界单位
|
||||
/// @details 根据全局缩放比例将像素单位转换为物理世界的单位米
|
||||
/// @brief 物理世界单位转换为游戏世界单位
|
||||
/// @details 根据全局缩放比例将像素单位转换为物理世界的单位米
|
||||
float Stage2World(float value) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物理世界单位转换为游戏世界单位
|
||||
/// @details 根据全局缩放比例将像素单位转换为物理世界的单位米
|
||||
/// @brief 物理世界单位转换为游戏世界单位
|
||||
/// @details 根据全局缩放比例将像素单位转换为物理世界的单位米
|
||||
b2Vec2 Stage2World(const Vec2& pos) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置速度迭代次数, 默认为 6
|
||||
/// @brief 设置速度迭代次数, 默认为 6
|
||||
void SetVelocityIterations(int vel_iter);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置位置迭代次数, 默认为 2
|
||||
/// @brief 设置位置迭代次数, 默认为 2
|
||||
void SetPositionIterations(int pos_iter);
|
||||
|
||||
b2World* GetB2World();
|
||||
|
|
@ -108,27 +108,27 @@ public:
|
|||
|
||||
private:
|
||||
/// \~chinese
|
||||
/// @brief 移除物体
|
||||
/// @brief 移除物体
|
||||
void RemoveBody(Body* body);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除所有物体
|
||||
/// @brief 移除所有物体
|
||||
void RemoveAllBodies();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加关节
|
||||
/// @brief 添加关节
|
||||
void AddJoint(Joint* joint);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除关节
|
||||
/// @brief 移除关节
|
||||
void RemoveJoint(Joint* joint);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除所有关节
|
||||
/// @brief 移除所有关节
|
||||
void RemoveAllJoints();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 关节被移除
|
||||
/// @brief 关节被移除
|
||||
void JointRemoved(b2Joint* joint);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ void Actor::RenderBorder(RenderContext& ctx)
|
|||
ctx.FillRectangle(bounds);
|
||||
|
||||
ctx.SetCurrentBrush(GetStage()->GetBorderStrokeBrush());
|
||||
ctx.DrawRectangle(bounds, 2.f);
|
||||
ctx.DrawRectangle(bounds, nullptr, 2.f);
|
||||
}
|
||||
|
||||
for (auto child = children_.first_item(); child; child = child->next_item())
|
||||
|
|
@ -513,7 +513,7 @@ void Actor::AddChild(Actor* child, int zorder)
|
|||
{
|
||||
if (parent == child)
|
||||
{
|
||||
KGE_ERROR(L"A actor cannot be its own parent");
|
||||
KGE_ERROR("A actor cannot be its own parent");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ KGE_DECLARE_SMART_PTR(Actor);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* \defgroup Actors 基础角色
|
||||
* \defgroup Actors 基础角色
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -46,9 +46,9 @@ KGE_DECLARE_SMART_PTR(Actor);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 角色
|
||||
* @brief 角色
|
||||
* @details
|
||||
* 角色是舞台上最基本的元素,是完成渲染、更新、事件分发等功能的最小单位,也是动画、定时器、事件监听等功能的载体
|
||||
* 角色是舞台上最基本的元素,是完成渲染、更新、事件分发等功能的最小单位,也是动画、定时器、事件监听等功能的载体
|
||||
*/
|
||||
class KGE_API Actor
|
||||
: public virtual ObjectBase
|
||||
|
|
@ -63,15 +63,15 @@ class KGE_API Actor
|
|||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 子成员列表
|
||||
/// @brief 子成员列表
|
||||
using Children = IntrusiveList<ActorPtr>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 角色更新回调函数
|
||||
/// @brief 角色更新回调函数
|
||||
using UpdateCallback = Function<void(Duration)>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建角色
|
||||
/// @brief 创建角色
|
||||
static ActorPtr Create();
|
||||
|
||||
Actor();
|
||||
|
|
@ -79,372 +79,372 @@ public:
|
|||
virtual ~Actor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 更新角色
|
||||
/// @details 每帧画面刷新前调用该函数,重载该函数以实现角色的更新处理
|
||||
/// @param dt 距上一次更新的时间间隔
|
||||
/// @brief 更新角色
|
||||
/// @details 每帧画面刷新前调用该函数,重载该函数以实现角色的更新处理
|
||||
/// @param dt 距上一次更新的时间间隔
|
||||
virtual void OnUpdate(Duration dt);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 渲染角色
|
||||
/// @brief 渲染角色
|
||||
/// @details
|
||||
/// 每帧画面刷新时调用该函数,默认不进行渲染,重载该函数以实现具体渲染过程
|
||||
/// @param ctx 渲染上下文
|
||||
/// 每帧画面刷新时调用该函数,默认不进行渲染,重载该函数以实现具体渲染过程
|
||||
/// @param ctx 渲染上下文
|
||||
virtual void OnRender(RenderContext& ctx);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取显示状态
|
||||
/// @brief 获取显示状态
|
||||
bool IsVisible() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取响应状态
|
||||
/// @brief 获取响应状态
|
||||
bool IsResponsible() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否启用级联透明度
|
||||
/// @brief 是否启用级联透明度
|
||||
bool IsCascadeOpacityEnabled() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取名称的 Hash 值
|
||||
/// @brief 获取名称的 Hash 值
|
||||
size_t GetHashName() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取 Z 轴顺序
|
||||
/// @brief 获取 Z 轴顺序
|
||||
int GetZOrder() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取坐标
|
||||
/// @brief 获取坐标
|
||||
Point const& GetPosition() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取 x 坐标
|
||||
/// @brief 获取 x 坐标
|
||||
float GetPositionX() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取 y 坐标
|
||||
/// @brief 获取 y 坐标
|
||||
float GetPositionY() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取宽度
|
||||
/// @brief 获取宽度
|
||||
float GetWidth() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取高度
|
||||
/// @brief 获取高度
|
||||
float GetHeight() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取大小
|
||||
/// @brief 获取大小
|
||||
Size const& GetSize() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取缩放后的宽度
|
||||
/// @brief 获取缩放后的宽度
|
||||
float GetScaledWidth() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取缩放后的高度
|
||||
/// @brief 获取缩放后的高度
|
||||
float GetScaledHeight() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取缩放后的大小
|
||||
/// @brief 获取缩放后的大小
|
||||
Size GetScaledSize() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取锚点
|
||||
/// @brief 获取锚点
|
||||
Point const& GetAnchor() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取 x 方向锚点
|
||||
/// @brief 获取 x 方向锚点
|
||||
float GetAnchorX() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取 y 方向锚点
|
||||
/// @brief 获取 y 方向锚点
|
||||
float GetAnchorY() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取透明度
|
||||
/// @brief 获取透明度
|
||||
float GetOpacity() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取显示透明度
|
||||
/// @brief 获取显示透明度
|
||||
float GetDisplayedOpacity() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取旋转角度
|
||||
/// @brief 获取旋转角度
|
||||
float GetRotation() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取缩放比例
|
||||
/// @brief 获取缩放比例
|
||||
Point const& GetScale() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取横向缩放比例
|
||||
/// @brief 获取横向缩放比例
|
||||
float GetScaleX() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取纵向缩放比例
|
||||
/// @brief 获取纵向缩放比例
|
||||
float GetScaleY() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取错切角度
|
||||
/// @brief 获取错切角度
|
||||
Point const& GetSkew() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取横向错切角度
|
||||
/// @brief 获取横向错切角度
|
||||
float GetSkewX() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取纵向错切角度
|
||||
/// @brief 获取纵向错切角度
|
||||
float GetSkewY() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取变换
|
||||
/// @brief 获取变换
|
||||
Transform GetTransform() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取父角色
|
||||
/// @brief 获取父角色
|
||||
Actor* GetParent() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取所在舞台
|
||||
/// @brief 获取所在舞台
|
||||
Stage* GetStage() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取边框
|
||||
/// @brief 获取边框
|
||||
virtual Rect GetBounds() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取外切包围盒
|
||||
/// @brief 获取外切包围盒
|
||||
virtual Rect GetBoundingBox() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取二维变换矩阵
|
||||
/// @brief 获取二维变换矩阵
|
||||
Matrix3x2 const& GetTransformMatrix() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取二维变换的逆矩阵
|
||||
/// @brief 获取二维变换的逆矩阵
|
||||
Matrix3x2 const& GetTransformInverseMatrix() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置角色是否可见
|
||||
/// @brief 设置角色是否可见
|
||||
void SetVisible(bool val);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置名称
|
||||
/// @brief 设置名称
|
||||
void SetName(String const& name);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置坐标
|
||||
/// @brief 设置坐标
|
||||
virtual void SetPosition(Point const& point);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置坐标
|
||||
/// @brief 设置坐标
|
||||
void SetPosition(float x, float y);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置横坐标
|
||||
/// @brief 设置横坐标
|
||||
void SetPositionX(float x);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置纵坐标
|
||||
/// @brief 设置纵坐标
|
||||
void SetPositionY(float y);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移动坐标
|
||||
/// @brief 移动坐标
|
||||
void Move(Vec2 const& v);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移动坐标
|
||||
/// @brief 移动坐标
|
||||
void Move(float vx, float vy);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置缩放比例,默认为 (1.0, 1.0)
|
||||
/// @brief 设置缩放比例,默认为 (1.0, 1.0)
|
||||
virtual void SetScale(Vec2 const& scale);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置缩放比例,默认为 (1.0, 1.0)
|
||||
/// @brief 设置缩放比例,默认为 (1.0, 1.0)
|
||||
void SetScale(float scalex, float scaley);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置错切角度,默认为 (0, 0)
|
||||
/// @brief 设置错切角度,默认为 (0, 0)
|
||||
virtual void SetSkew(Vec2 const& skew);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置错切角度,默认为 (0, 0)
|
||||
/// @brief 设置错切角度,默认为 (0, 0)
|
||||
void SetSkew(float skewx, float skewy);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置旋转角度,默认为 0
|
||||
/// @brief 设置旋转角度,默认为 0
|
||||
virtual void SetRotation(float rotation);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置锚点位置,默认为 (0, 0), 范围 [0, 1]
|
||||
/// @brief 设置锚点位置,默认为 (0, 0), 范围 [0, 1]
|
||||
virtual void SetAnchor(Vec2 const& anchor);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置锚点位置,默认为 (0, 0), 范围 [0, 1]
|
||||
/// @brief 设置锚点位置,默认为 (0, 0), 范围 [0, 1]
|
||||
void SetAnchor(float anchorx, float anchory);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 修改宽度
|
||||
/// @brief 修改宽度
|
||||
virtual void SetWidth(float width);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 修改高度
|
||||
/// @brief 修改高度
|
||||
virtual void SetHeight(float height);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 修改大小
|
||||
/// @brief 修改大小
|
||||
virtual void SetSize(Size const& size);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 修改大小
|
||||
/// @brief 修改大小
|
||||
void SetSize(float width, float height);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置透明度,默认为 1.0, 范围 [0, 1]
|
||||
/// @brief 设置透明度,默认为 1.0, 范围 [0, 1]
|
||||
virtual void SetOpacity(float opacity);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 启用或禁用级联透明度
|
||||
/// @brief 启用或禁用级联透明度
|
||||
void SetCascadeOpacityEnabled(bool enabled);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置二维仿射变换
|
||||
/// @brief 设置二维仿射变换
|
||||
void SetTransform(Transform const& transform);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置 Z 轴顺序,默认为 0
|
||||
/// @brief 设置 Z 轴顺序,默认为 0
|
||||
void SetZOrder(int zorder);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置角色是否可响应,默认为 false
|
||||
/// @details 可响应的角色会收到鼠标的 Hover | Out | Click 消息
|
||||
/// @brief 设置角色是否可响应,默认为 false
|
||||
/// @details 可响应的角色会收到鼠标的 Hover | Out | Click 消息
|
||||
void SetResponsible(bool enable);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加子角色
|
||||
/// @brief 添加子角色
|
||||
void AddChild(ActorPtr child, int zorder = 0);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加子角色
|
||||
/// @brief 添加子角色
|
||||
void AddChild(Actor* child, int zorder = 0);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加多个子角色
|
||||
/// @brief 添加多个子角色
|
||||
void AddChildren(Vector<ActorPtr> const& children);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取名称相同的子角色
|
||||
/// @brief 获取名称相同的子角色
|
||||
Actor* GetChild(String const& name) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取所有名称相同的子角色
|
||||
/// @brief 获取所有名称相同的子角色
|
||||
Vector<ActorPtr> GetChildren(String const& name) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取全部子角色
|
||||
/// @brief 获取全部子角色
|
||||
Children& GetAllChildren();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取全部子角色
|
||||
/// @brief 获取全部子角色
|
||||
Children const& GetAllChildren() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除子角色
|
||||
/// @brief 移除子角色
|
||||
void RemoveChild(ActorPtr child);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除子角色
|
||||
/// @brief 移除子角色
|
||||
void RemoveChild(Actor* child);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除所有名称相同的子角色
|
||||
/// @brief 移除所有名称相同的子角色
|
||||
void RemoveChildren(String const& child_name);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除所有角色
|
||||
/// @brief 移除所有角色
|
||||
void RemoveAllChildren();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 从父角色移除
|
||||
/// @brief 从父角色移除
|
||||
void RemoveFromParent();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 暂停角色更新
|
||||
/// @brief 暂停角色更新
|
||||
void PauseUpdating();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 继续角色更新
|
||||
/// @brief 继续角色更新
|
||||
void ResumeUpdating();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 角色更新是否暂停
|
||||
/// @brief 角色更新是否暂停
|
||||
bool IsUpdatePausing() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置更新时的回调函数
|
||||
/// @brief 设置更新时的回调函数
|
||||
void SetCallbackOnUpdate(UpdateCallback const& cb);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取更新时的回调函数
|
||||
/// @brief 获取更新时的回调函数
|
||||
UpdateCallback GetCallbackOnUpdate() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 判断点是否在角色内
|
||||
/// @brief 判断点是否在角色内
|
||||
virtual bool ContainsPoint(const Point& point) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 渲染角色边界
|
||||
/// @brief 渲染角色边界
|
||||
void ShowBorder(bool show);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 分发事件
|
||||
/// @param evt 事件
|
||||
/// @return 是否继续分发该事件
|
||||
/// @brief 分发事件
|
||||
/// @param evt 事件
|
||||
/// @return 是否继续分发该事件
|
||||
virtual bool DispatchEvent(Event* evt);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置默认锚点
|
||||
/// @brief 设置默认锚点
|
||||
static void SetDefaultAnchor(float anchor_x, float anchor_y);
|
||||
|
||||
protected:
|
||||
/// \~chinese
|
||||
/// @brief 更新自身和所有子角色
|
||||
/// @brief 更新自身和所有子角色
|
||||
virtual void Update(Duration dt);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 渲染自身和所有子角色
|
||||
/// @brief 渲染自身和所有子角色
|
||||
virtual void Render(RenderContext& ctx);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 绘制自身和所有子角色的边界
|
||||
/// @brief 绘制自身和所有子角色的边界
|
||||
virtual void RenderBorder(RenderContext& ctx);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 检查是否在渲染上下文的视区内
|
||||
/// @brief 检查是否在渲染上下文的视区内
|
||||
virtual bool CheckVisibility(RenderContext& ctx) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 渲染前初始化渲染上下文状态,仅当 CheckVisibility 返回真时调用该函数
|
||||
/// @brief 渲染前初始化渲染上下文状态,仅当 CheckVisibility 返回真时调用该函数
|
||||
virtual void PrepareToRender(RenderContext& ctx);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 更新自己的二维变换,并通知所有子角色
|
||||
/// @brief 更新自己的二维变换,并通知所有子角色
|
||||
void UpdateTransform() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 更新自己和所有子角色的透明度
|
||||
/// @brief 更新自己和所有子角色的透明度
|
||||
void UpdateOpacity();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 将所有子角色按Z轴顺序排序
|
||||
/// @brief 将所有子角色按Z轴顺序排序
|
||||
void Reorder();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置节点所在舞台
|
||||
/// @brief 设置节点所在舞台
|
||||
void SetStage(Stage* stage);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 处理事件
|
||||
/// @brief 处理事件
|
||||
void HandleEvent(Event* evt);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -78,14 +78,14 @@ void Button::SetStatus(Status status)
|
|||
|
||||
if (status == Status::Normal)
|
||||
{
|
||||
Window::Instance().SetCursor(CursorType::Arrow);
|
||||
Window::GetInstance().SetCursor(CursorType::Arrow);
|
||||
|
||||
if (mouse_out_callback_)
|
||||
mouse_out_callback_(this);
|
||||
}
|
||||
else if (status == Status::Hover)
|
||||
{
|
||||
Window::Instance().SetCursor(CursorType::Hand);
|
||||
Window::GetInstance().SetCursor(CursorType::Hand);
|
||||
|
||||
if (old_status == Status::Pressed)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,13 +30,13 @@ KGE_DECLARE_SMART_PTR(TextButton);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 按钮
|
||||
* @brief 按钮
|
||||
*/
|
||||
class KGE_API Button : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 按钮回调函数
|
||||
/// @brief 按钮回调函数
|
||||
using Callback = Function<void(Button* /* self */)>;
|
||||
|
||||
Button();
|
||||
|
|
@ -44,53 +44,53 @@ public:
|
|||
virtual ~Button();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取按钮状态是启用还是禁用
|
||||
/// @brief 获取按钮状态是启用还是禁用
|
||||
bool IsEnable() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置按钮启用或禁用
|
||||
/// @brief 设置按钮启用或禁用
|
||||
void SetEnabled(bool enabled);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置按钮点击后的回调函数
|
||||
/// @brief 设置按钮点击后的回调函数
|
||||
void SetClickCallback(const Callback& func);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置按钮被按下时的回调函数
|
||||
/// @brief 设置按钮被按下时的回调函数
|
||||
void SetPressedCallback(const Callback& func);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置按钮被抬起时的回调函数
|
||||
/// @brief 设置按钮被抬起时的回调函数
|
||||
void SetReleasedCallback(const Callback& func);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置鼠标移入按钮时的回调函数
|
||||
/// @brief 设置鼠标移入按钮时的回调函数
|
||||
void SetMouseOverCallback(const Callback& func);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置鼠标移出按钮时的回调函数
|
||||
/// @brief 设置鼠标移出按钮时的回调函数
|
||||
void SetMouseOutCallback(const Callback& func);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 按钮状态
|
||||
/// @brief 按钮状态
|
||||
enum class Status
|
||||
{
|
||||
Normal, ///< 普通
|
||||
Hover, ///< 鼠标在按钮内
|
||||
Pressed ///< 被按下
|
||||
Normal, ///< 普通
|
||||
Hover, ///< 鼠标在按钮内
|
||||
Pressed ///< 被按下
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置按钮状态
|
||||
/// @brief 设置按钮状态
|
||||
void SetStatus(Status status);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取按钮状态
|
||||
/// @brief 获取按钮状态
|
||||
Status GetStatus() const;
|
||||
|
||||
protected:
|
||||
/// \~chinese
|
||||
/// @brief 更新按钮状态
|
||||
/// @brief 更新按钮状态
|
||||
void UpdateStatus(Event* evt);
|
||||
|
||||
private:
|
||||
|
|
@ -104,7 +104,7 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 精灵按钮
|
||||
/// @brief 精灵按钮
|
||||
class SpriteButton
|
||||
: public Sprite
|
||||
, public Button
|
||||
|
|
@ -113,22 +113,22 @@ public:
|
|||
SpriteButton();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建精灵按钮
|
||||
/// @param click 按钮点击回调函数
|
||||
/// @brief 创建精灵按钮
|
||||
/// @param click 按钮点击回调函数
|
||||
static SpriteButtonPtr Create(Callback const& click);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建精灵按钮
|
||||
/// @param click 按钮点击回调函数
|
||||
/// @param pressed 按钮按下回调函数
|
||||
/// @param mouse_over 按钮移入回调函数
|
||||
/// @param mouse_out 按钮移出回调函数
|
||||
/// @brief 创建精灵按钮
|
||||
/// @param click 按钮点击回调函数
|
||||
/// @param pressed 按钮按下回调函数
|
||||
/// @param mouse_over 按钮移入回调函数
|
||||
/// @param mouse_out 按钮移出回调函数
|
||||
static SpriteButtonPtr Create(Callback const& click, Callback const& pressed, Callback const& mouse_over,
|
||||
Callback const& mouse_out);
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 文字按钮
|
||||
/// @brief 文字按钮
|
||||
class TextButton
|
||||
: public TextActor
|
||||
, public Button
|
||||
|
|
@ -137,16 +137,16 @@ public:
|
|||
TextButton();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建文字按钮
|
||||
/// @param click 按钮点击回调函数
|
||||
/// @brief 创建文字按钮
|
||||
/// @param click 按钮点击回调函数
|
||||
static TextButtonPtr Create(Callback const& click);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建文字按钮
|
||||
/// @param click 按钮点击回调函数
|
||||
/// @param pressed 按钮按下回调函数
|
||||
/// @param mouse_over 按钮移入回调函数
|
||||
/// @param mouse_out 按钮移出回调函数
|
||||
/// @brief 创建文字按钮
|
||||
/// @param click 按钮点击回调函数
|
||||
/// @param pressed 按钮按下回调函数
|
||||
/// @param mouse_over 按钮移入回调函数
|
||||
/// @param mouse_out 按钮移出回调函数
|
||||
static TextButtonPtr Create(Callback const& click, Callback const& pressed, Callback const& mouse_over, Callback const& mouse_out);
|
||||
};
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -25,9 +25,24 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
CanvasPtr Canvas::Create()
|
||||
CanvasPtr Canvas::Create(Size const& size)
|
||||
{
|
||||
CanvasPtr ptr = new (std::nothrow) Canvas;
|
||||
if (ptr)
|
||||
{
|
||||
try
|
||||
{
|
||||
ptr->ctx_ = TextureRenderContext::Create();
|
||||
ptr->stroke_brush_ = Brush::Create(Color::White);
|
||||
ptr->fill_brush_ = Brush::Create(Color::White);
|
||||
|
||||
ptr->SetSize(ptr->ctx_->GetSize());
|
||||
}
|
||||
catch (std::exception)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
|
@ -38,17 +53,15 @@ Canvas::Canvas()
|
|||
{
|
||||
}
|
||||
|
||||
Canvas::~Canvas() {}
|
||||
|
||||
void Canvas::BeginDraw()
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->BeginDraw();
|
||||
}
|
||||
|
||||
void Canvas::EndDraw()
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->EndDraw();
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
|
@ -60,124 +73,117 @@ void Canvas::OnRender(RenderContext& ctx)
|
|||
if (texture_cached_ && texture_cached_->IsValid())
|
||||
{
|
||||
PrepareToRender(ctx);
|
||||
|
||||
Rect bitmap_rect(0.f, 0.f, texture_cached_->GetWidth(), texture_cached_->GetHeight());
|
||||
ctx.DrawTexture(*texture_cached_, bitmap_rect, bitmap_rect);
|
||||
ctx.DrawTexture(*texture_cached_, nullptr, &GetBounds());
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::SetBrush(BrushPtr brush)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetCurrentBrush(brush);
|
||||
}
|
||||
|
||||
float Canvas::GetStrokeWidth() const
|
||||
{
|
||||
return stroke_width_;
|
||||
}
|
||||
|
||||
void Canvas::SetBrushTransform(Transform const& transform)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetTransform(transform.ToMatrix());
|
||||
}
|
||||
|
||||
void Canvas::SetBrushTransform(Matrix3x2 const& transform)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetTransform(transform);
|
||||
}
|
||||
|
||||
void Canvas::PushLayerArea(LayerArea& area)
|
||||
void Canvas::PushLayer(Layer& layer)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->PushLayer(area);
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->PushLayer(layer);
|
||||
}
|
||||
|
||||
void Canvas::PopLayerArea()
|
||||
void Canvas::PopLayer()
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->PopLayer();
|
||||
}
|
||||
|
||||
void Canvas::PushClipRect(Rect const& clip_rect)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->PushClipRect(clip_rect);
|
||||
}
|
||||
|
||||
void Canvas::PopClipRect()
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->PopClipRect();
|
||||
}
|
||||
|
||||
void Canvas::DrawShape(ShapePtr shape)
|
||||
{
|
||||
if (!shape)
|
||||
return;
|
||||
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawShape(*shape, stroke_width_, stroke_style_);
|
||||
cache_expired_ = true;
|
||||
KGE_ASSERT(ctx_);
|
||||
if (shape)
|
||||
{
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawShape(*shape, stroke_style_, stroke_width_);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::DrawLine(Point const& begin, Point const& end)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawLine(begin, end, stroke_width_, stroke_style_);
|
||||
ctx_->DrawLine(begin, end, stroke_style_, stroke_width_);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
void Canvas::DrawCircle(Point const& center, float radius)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawEllipse(center, Vec2(radius, radius), stroke_width_, stroke_style_);
|
||||
ctx_->DrawEllipse(center, Vec2(radius, radius), stroke_style_, stroke_width_);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
void Canvas::DrawEllipse(Point const& center, Vec2 const& radius)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawEllipse(center, radius, stroke_width_, stroke_style_);
|
||||
ctx_->DrawEllipse(center, radius, stroke_style_, stroke_width_);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
void Canvas::DrawRect(Rect const& rect)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawRectangle(rect, stroke_width_, stroke_style_);
|
||||
ctx_->DrawRectangle(rect, stroke_style_, stroke_width_);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
void Canvas::DrawRoundedRect(Rect const& rect, Vec2 const& radius)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawRoundedRectangle(rect, radius, stroke_width_, stroke_style_);
|
||||
ctx_->DrawRoundedRectangle(rect, radius, stroke_style_, stroke_width_);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
void Canvas::FillShape(ShapePtr shape)
|
||||
{
|
||||
if (!shape)
|
||||
return;
|
||||
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->SetCurrentBrush(fill_brush_);
|
||||
ctx_->FillShape(*shape);
|
||||
cache_expired_ = true;
|
||||
KGE_ASSERT(ctx_);
|
||||
if (shape)
|
||||
{
|
||||
ctx_->SetCurrentBrush(fill_brush_);
|
||||
ctx_->FillShape(*shape);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::FillCircle(Point const& center, float radius)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetCurrentBrush(fill_brush_);
|
||||
ctx_->FillEllipse(center, Vec2(radius, radius));
|
||||
cache_expired_ = true;
|
||||
|
|
@ -185,7 +191,7 @@ void Canvas::FillCircle(Point const& center, float radius)
|
|||
|
||||
void Canvas::FillEllipse(Point const& center, Vec2 const& radius)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetCurrentBrush(fill_brush_);
|
||||
ctx_->FillEllipse(center, radius);
|
||||
cache_expired_ = true;
|
||||
|
|
@ -193,7 +199,7 @@ void Canvas::FillEllipse(Point const& center, Vec2 const& radius)
|
|||
|
||||
void Canvas::FillRect(Rect const& rect)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetCurrentBrush(fill_brush_);
|
||||
ctx_->FillRectangle(rect);
|
||||
cache_expired_ = true;
|
||||
|
|
@ -201,7 +207,7 @@ void Canvas::FillRect(Rect const& rect)
|
|||
|
||||
void Canvas::FillRoundedRect(Rect const& rect, Vec2 const& radius)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetCurrentBrush(fill_brush_);
|
||||
ctx_->FillRoundedRectangle(rect, radius);
|
||||
cache_expired_ = true;
|
||||
|
|
@ -209,9 +215,9 @@ void Canvas::FillRoundedRect(Rect const& rect, Vec2 const& radius)
|
|||
|
||||
void Canvas::DrawTexture(TexturePtr texture, const Rect* src_rect, const Rect* dest_rect)
|
||||
{
|
||||
KGE_ASSERT(ctx_);
|
||||
if (texture)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->DrawTexture(*texture, src_rect, dest_rect);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
|
@ -230,7 +236,7 @@ void Canvas::DrawTextLayout(String const& text, Point const& point)
|
|||
|
||||
void Canvas::DrawTextLayout(TextLayout const& layout, Point const& point)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->DrawTextLayout(layout, point);
|
||||
}
|
||||
|
||||
|
|
@ -266,15 +272,15 @@ void Canvas::AddArc(Point const& point, Size const& radius, float rotation, bool
|
|||
|
||||
void Canvas::StrokePath()
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawShape(*shape_sink_.GetShape(), stroke_width_, stroke_style_);
|
||||
ctx_->DrawShape(*shape_sink_.GetShape(), stroke_style_, stroke_width_);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
void Canvas::FillPath()
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->SetCurrentBrush(fill_brush_);
|
||||
ctx_->FillShape(*shape_sink_.GetShape());
|
||||
cache_expired_ = true;
|
||||
|
|
@ -282,44 +288,29 @@ void Canvas::FillPath()
|
|||
|
||||
void Canvas::Clear()
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->Clear();
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
void Canvas::Clear(Color const& clear_color)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
KGE_ASSERT(ctx_);
|
||||
ctx_->Clear(clear_color);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
void Canvas::ResizeAndClear(Size size)
|
||||
{
|
||||
ctx_ = TextureRenderContext::Create(size);
|
||||
}
|
||||
|
||||
TexturePtr Canvas::ExportToTexture() const
|
||||
{
|
||||
UpdateCache();
|
||||
return texture_cached_;
|
||||
}
|
||||
|
||||
void Canvas::InitRenderTargetAndBrushs()
|
||||
{
|
||||
if (!ctx_)
|
||||
{
|
||||
Renderer::Instance().CreateTextureRenderTarget(ctx_);
|
||||
}
|
||||
|
||||
if (!stroke_brush_)
|
||||
{
|
||||
stroke_brush_ = new Brush;
|
||||
stroke_brush_->SetColor(Color::White);
|
||||
}
|
||||
|
||||
if (!fill_brush_)
|
||||
{
|
||||
fill_brush_ = new Brush;
|
||||
fill_brush_->SetColor(Color::White);
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::UpdateCache() const
|
||||
{
|
||||
if (cache_expired_ && ctx_)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#pragma once
|
||||
#include <kiwano/2d/Actor.h>
|
||||
#include <kiwano/render/ShapeSink.h>
|
||||
#include <kiwano/render/RenderContext.h>
|
||||
#include <kiwano/render/TextureRenderContext.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -35,251 +35,251 @@ KGE_DECLARE_SMART_PTR(Canvas);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 画布,用于绘制图元
|
||||
* @brief 画布
|
||||
* @details 用于绘制图形、图像、文字等各种类型的图元,同时可以将绘制内容导出至图像
|
||||
*/
|
||||
class KGE_API Canvas : public Actor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建画布
|
||||
static CanvasPtr Create();
|
||||
/// @brief 创建画布
|
||||
/// @param size 画布大小
|
||||
static CanvasPtr Create(Size const& size);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构建空画布
|
||||
Canvas();
|
||||
|
||||
virtual ~Canvas();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 开始绘图
|
||||
/// @brief 开始绘图
|
||||
void BeginDraw();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 结束绘图
|
||||
/// @brief 结束绘图
|
||||
void EndDraw();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 画形状轮廓
|
||||
/// @param shape 形状
|
||||
/// @brief 画形状轮廓
|
||||
/// @param shape 形状
|
||||
void DrawShape(ShapePtr shape);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 画线段
|
||||
/// @param begin 线段起点
|
||||
/// @param end 线段终点
|
||||
/// @brief 画线段
|
||||
/// @param begin 线段起点
|
||||
/// @param end 线段终点
|
||||
void DrawLine(Point const& begin, Point const& end);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 画圆形边框
|
||||
/// @param center 圆形原点
|
||||
/// @param radius 圆形半径
|
||||
/// @brief 画圆形边框
|
||||
/// @param center 圆形原点
|
||||
/// @param radius 圆形半径
|
||||
void DrawCircle(Point const& center, float radius);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 画椭圆形边框
|
||||
/// @param center 椭圆原点
|
||||
/// @param radius 椭圆半径
|
||||
/// @brief 画椭圆形边框
|
||||
/// @param center 椭圆原点
|
||||
/// @param radius 椭圆半径
|
||||
void DrawEllipse(Point const& center, Vec2 const& radius);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 画矩形边框
|
||||
/// @param rect 矩形
|
||||
/// @brief 画矩形边框
|
||||
/// @param rect 矩形
|
||||
void DrawRect(Rect const& rect);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 画圆角矩形边框
|
||||
/// @param rect 矩形
|
||||
/// @param radius 矩形圆角半径
|
||||
/// @brief 画圆角矩形边框
|
||||
/// @param rect 矩形
|
||||
/// @param radius 矩形圆角半径
|
||||
void DrawRoundedRect(Rect const& rect, Vec2 const& radius);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 填充形状
|
||||
/// @param shape 形状
|
||||
/// @brief 填充形状
|
||||
/// @param shape 形状
|
||||
void FillShape(ShapePtr shape);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 填充圆形
|
||||
/// @param center 圆形原点
|
||||
/// @param radius 圆形半径
|
||||
/// @brief 填充圆形
|
||||
/// @param center 圆形原点
|
||||
/// @param radius 圆形半径
|
||||
void FillCircle(Point const& center, float radius);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 填充椭圆形
|
||||
/// @param center 椭圆原点
|
||||
/// @param radius 椭圆半径
|
||||
/// @brief 填充椭圆形
|
||||
/// @param center 椭圆原点
|
||||
/// @param radius 椭圆半径
|
||||
void FillEllipse(Point const& center, Vec2 const& radius);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 填充矩形
|
||||
/// @param rect 矩形
|
||||
/// @brief 填充矩形
|
||||
/// @param rect 矩形
|
||||
void FillRect(Rect const& rect);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 填充圆角矩形
|
||||
/// @param rect 矩形
|
||||
/// @param radius 矩形圆角半径
|
||||
/// @brief 填充圆角矩形
|
||||
/// @param rect 矩形
|
||||
/// @param radius 矩形圆角半径
|
||||
void FillRoundedRect(Rect const& rect, Vec2 const& radius);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 绘制纹理
|
||||
/// @param texture 纹理
|
||||
/// @param src_rect 纹理裁剪区域
|
||||
/// @param dest_rect 绘制目标区域
|
||||
/// @brief 绘制纹理
|
||||
/// @param texture 纹理
|
||||
/// @param src_rect 纹理裁剪区域
|
||||
/// @param dest_rect 绘制目标区域
|
||||
void DrawTexture(TexturePtr texture, const Rect* src_rect = nullptr, const Rect* dest_rect = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 绘制文字布局
|
||||
/// @param text 文字
|
||||
/// @param point 绘制文字的位置
|
||||
/// @brief 绘制文字布局
|
||||
/// @param text 文字
|
||||
/// @param point 绘制文字的位置
|
||||
void DrawTextLayout(String const& text, Point const& point);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 绘制文字布局
|
||||
/// @param layout 文字布局
|
||||
/// @param point 绘制布局的位置
|
||||
/// @brief 绘制文字布局
|
||||
/// @param layout 文字布局
|
||||
/// @param point 绘制布局的位置
|
||||
void DrawTextLayout(TextLayout const& layout, Point const& point);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 开始绘制路径
|
||||
/// @param begin_pos 路径起始点
|
||||
/// @brief 开始绘制路径
|
||||
/// @param begin_pos 路径起始点
|
||||
void BeginPath(Point const& begin_pos);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 结束路径
|
||||
/// @param closed 路径是否闭合
|
||||
/// @brief 结束路径
|
||||
/// @param closed 路径是否闭合
|
||||
void EndPath(bool closed = false);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加一条线段
|
||||
/// @param point 端点
|
||||
/// @brief 添加一条线段
|
||||
/// @param point 端点
|
||||
void AddLine(Point const& point);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加多条线段
|
||||
/// @param points 端点集合
|
||||
/// @brief 添加多条线段
|
||||
/// @param points 端点集合
|
||||
void AddLines(Vector<Point> const& points);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加一条三次方贝塞尔曲线
|
||||
/// @param point1 贝塞尔曲线的第一个控制点
|
||||
/// @param point2 贝塞尔曲线的第二个控制点
|
||||
/// @param point3 贝塞尔曲线的终点
|
||||
/// @brief 添加一条三次方贝塞尔曲线
|
||||
/// @param point1 贝塞尔曲线的第一个控制点
|
||||
/// @param point2 贝塞尔曲线的第二个控制点
|
||||
/// @param point3 贝塞尔曲线的终点
|
||||
void AddBezier(Point const& point1, Point const& point2, Point const& point3);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加弧线
|
||||
/// @param point 终点
|
||||
/// @param radius 椭圆半径
|
||||
/// @param rotation 椭圆旋转角度
|
||||
/// @param clockwise 顺时针 or 逆时针
|
||||
/// @param is_small 是否取小于 180° 的弧
|
||||
/// @brief 添加弧线
|
||||
/// @param point 终点
|
||||
/// @param radius 椭圆半径
|
||||
/// @param rotation 椭圆旋转角度
|
||||
/// @param clockwise 顺时针 or 逆时针
|
||||
/// @param is_small 是否取小于 180° 的弧
|
||||
void AddArc(Point const& point, Size const& radius, float rotation, bool clockwise = true, bool is_small = true);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 以描边的方式绘制路径
|
||||
/// @brief 以描边的方式绘制路径
|
||||
void StrokePath();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 以填充的方式绘制路径
|
||||
/// @brief 以填充的方式绘制路径
|
||||
void FillPath();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 清空画布
|
||||
/// @brief 清空画布
|
||||
void Clear();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 清空画布
|
||||
/// @param clear_color 清空颜色
|
||||
/// @brief 清空画布
|
||||
/// @param clear_color 清空颜色
|
||||
void Clear(Color const& clear_color);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置填充颜色
|
||||
/// @param color 填充颜色
|
||||
/// @brief 设置填充颜色
|
||||
/// @param color 填充颜色
|
||||
void SetFillColor(Color const& color);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置填充画刷
|
||||
/// @param[in] brush 填充画刷
|
||||
/// @brief 设置填充画刷
|
||||
/// @param[in] brush 填充画刷
|
||||
void SetFillBrush(BrushPtr brush);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置轮廓颜色
|
||||
/// @param color 轮廓颜色
|
||||
/// @brief 设置轮廓颜色
|
||||
/// @param color 轮廓颜色
|
||||
void SetStrokeColor(Color const& color);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置轮廓画刷
|
||||
/// @param[in] brush 轮廓画刷
|
||||
/// @brief 设置轮廓画刷
|
||||
/// @param[in] brush 轮廓画刷
|
||||
void SetStrokeBrush(BrushPtr brush);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置轮廓宽度
|
||||
/// @param width 轮廓宽度
|
||||
/// @brief 设置轮廓宽度
|
||||
/// @param width 轮廓宽度
|
||||
void SetStrokeWidth(float width);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置轮廓样式
|
||||
/// @param stroke_style 轮廓样式
|
||||
/// @brief 设置轮廓样式
|
||||
/// @param stroke_style 轮廓样式
|
||||
void SetStrokeStyle(StrokeStylePtr stroke_style);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置文字画刷样式
|
||||
/// @param text_style 文字画刷样式
|
||||
/// @brief 设置文字画刷样式
|
||||
/// @param text_style 文字画刷样式
|
||||
void SetTextStyle(TextStyle const& text_style);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置画刷
|
||||
/// @param[in] brush 画刷
|
||||
/// @brief 设置画刷
|
||||
/// @param[in] brush 画刷
|
||||
void SetBrush(BrushPtr brush);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置画刷二维变换
|
||||
/// @param transform 二维变换
|
||||
/// @brief 设置画刷二维变换
|
||||
/// @param transform 二维变换
|
||||
void SetBrushTransform(Transform const& transform);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置画刷二维变换矩阵
|
||||
/// @param transform 二维变换矩阵
|
||||
/// @brief 设置画刷二维变换矩阵
|
||||
/// @param transform 二维变换矩阵
|
||||
void SetBrushTransform(Matrix3x2 const& transform);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加一个图层
|
||||
/// @param area 图层区域
|
||||
void PushLayerArea(LayerArea& area);
|
||||
/// @brief 添加一个图层
|
||||
/// @param layer 图层
|
||||
void PushLayer(Layer& layer);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 删除最近添加的图层
|
||||
void PopLayerArea();
|
||||
/// @brief 删除最近添加的图层
|
||||
void PopLayer();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加一个裁剪区域
|
||||
/// @param clip_rect 裁剪矩形
|
||||
/// @brief 添加一个裁剪区域
|
||||
/// @param clip_rect 裁剪矩形
|
||||
void PushClipRect(Rect const& clip_rect);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 删除最近添加的裁剪区域
|
||||
/// @brief 删除最近添加的裁剪区域
|
||||
void PopClipRect();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取轮廓宽度
|
||||
/// @brief 获取轮廓宽度
|
||||
float GetStrokeWidth() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取填充画刷
|
||||
/// @brief 获取填充画刷
|
||||
BrushPtr GetFillBrush() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取轮廓画刷
|
||||
/// @brief 获取轮廓画刷
|
||||
BrushPtr GetStrokeBrush() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 导出纹理
|
||||
/// @brief 清空画布大小并重设画布大小
|
||||
void ResizeAndClear(Size size);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 导出纹理
|
||||
TexturePtr ExportToTexture() const;
|
||||
|
||||
void OnRender(RenderContext& ctx) override;
|
||||
|
||||
private:
|
||||
void InitRenderTargetAndBrushs();
|
||||
Canvas();
|
||||
|
||||
void UpdateCache() const;
|
||||
|
||||
|
|
@ -298,6 +298,11 @@ private:
|
|||
|
||||
/** @} */
|
||||
|
||||
inline float Canvas::GetStrokeWidth() const
|
||||
{
|
||||
return stroke_width_;
|
||||
}
|
||||
|
||||
inline void Canvas::SetStrokeWidth(float width)
|
||||
{
|
||||
stroke_width_ = std::max(width, 0.f);
|
||||
|
|
@ -315,13 +320,19 @@ inline void Canvas::SetTextStyle(TextStyle const& text_style)
|
|||
|
||||
inline void Canvas::SetStrokeColor(Color const& color)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
if (!stroke_brush_)
|
||||
{
|
||||
stroke_brush_ = new Brush;
|
||||
}
|
||||
stroke_brush_->SetColor(color);
|
||||
}
|
||||
|
||||
inline void Canvas::SetFillColor(Color const& color)
|
||||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
if (!fill_brush_)
|
||||
{
|
||||
fill_brush_ = new Brush;
|
||||
}
|
||||
fill_brush_->SetColor(color);
|
||||
}
|
||||
|
||||
|
|
@ -344,4 +355,5 @@ inline BrushPtr Canvas::GetStrokeBrush() const
|
|||
{
|
||||
return stroke_brush_;
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class comma_numpunct : public std::numpunct<wchar_t>
|
|||
private:
|
||||
virtual wchar_t do_thousands_sep() const override
|
||||
{
|
||||
return L',';
|
||||
return ',';
|
||||
}
|
||||
|
||||
virtual std::string do_grouping() const override
|
||||
|
|
@ -46,7 +46,7 @@ private:
|
|||
|
||||
DebugActor::DebugActor()
|
||||
{
|
||||
SetName(L"kiwano-debug-actor");
|
||||
SetName("kiwano-debug-actor");
|
||||
SetPosition(Point{ 10, 10 });
|
||||
SetResponsible(true);
|
||||
SetCascadeOpacityEnabled(true);
|
||||
|
|
@ -60,7 +60,7 @@ DebugActor::DebugActor()
|
|||
fill_brush->SetColor(Color::White);
|
||||
|
||||
TextStyle style;
|
||||
style.font_family = L"Arial";
|
||||
style.font_family = "Arial";
|
||||
style.font_size = 16.f;
|
||||
style.font_weight = FontWeight::Normal;
|
||||
style.line_spacing = 20.f;
|
||||
|
|
@ -78,17 +78,17 @@ void DebugActor::OnRender(RenderContext& ctx)
|
|||
ctx.SetCurrentBrush(background_brush_);
|
||||
ctx.FillRoundedRectangle(GetBounds(), Vec2{ 5.f, 5.f });
|
||||
ctx.DrawTextLayout(debug_text_, Point(10, 10));
|
||||
}
|
||||
|
||||
void DebugActor::OnUpdate(Duration dt)
|
||||
{
|
||||
KGE_NOT_USED(dt);
|
||||
|
||||
frame_time_.push_back(Time::Now());
|
||||
while (frame_time_.back() - frame_time_.front() >= Duration::Second)
|
||||
{
|
||||
frame_time_.erase(frame_time_.begin());
|
||||
}
|
||||
}
|
||||
|
||||
void DebugActor::OnUpdate(Duration dt)
|
||||
{
|
||||
KGE_NOT_USED(dt);
|
||||
|
||||
StringStream ss;
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ void DebugActor::OnUpdate(Duration dt)
|
|||
}
|
||||
#endif
|
||||
|
||||
const auto& status = Renderer::Instance().GetContext().GetStatus();
|
||||
const auto& status = Renderer::GetInstance().GetContext().GetStatus();
|
||||
|
||||
ss << "Render: " << status.duration.Milliseconds() << "ms" << std::endl;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace kiwano
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 调试节点
|
||||
* @brief 调试节点
|
||||
*/
|
||||
class KGE_API DebugActor : public Actor
|
||||
{
|
||||
|
|
@ -48,10 +48,10 @@ protected:
|
|||
bool CheckVisibility(RenderContext& ctx) const override;
|
||||
|
||||
private:
|
||||
std::locale comma_locale_;
|
||||
BrushPtr background_brush_;
|
||||
TextLayout debug_text_;
|
||||
Vector<Time> frame_time_;
|
||||
std::locale comma_locale_;
|
||||
BrushPtr background_brush_;
|
||||
TextLayout debug_text_;
|
||||
List<Time> frame_time_;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ Frame::Frame() {}
|
|||
|
||||
bool Frame::Load(String const& file_path)
|
||||
{
|
||||
TexturePtr texture = TextureCache::Instance().AddOrGetTexture(file_path);
|
||||
TexturePtr texture = TextureCache::GetInstance().AddOrGetTexture(file_path);
|
||||
if (texture->IsValid())
|
||||
{
|
||||
SetTexture(texture);
|
||||
|
|
@ -71,7 +71,7 @@ bool Frame::Load(String const& file_path)
|
|||
|
||||
bool Frame::Load(Resource const& res)
|
||||
{
|
||||
TexturePtr texture = TextureCache::Instance().AddOrGetTexture(res);
|
||||
TexturePtr texture = TextureCache::GetInstance().AddOrGetTexture(res);
|
||||
if (texture->IsValid())
|
||||
{
|
||||
SetTexture(texture);
|
||||
|
|
|
|||
|
|
@ -28,76 +28,76 @@ KGE_DECLARE_SMART_PTR(Frame);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 图像帧
|
||||
* @brief 图像帧
|
||||
*/
|
||||
class KGE_API Frame : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建图像帧
|
||||
/// @param file_path 图像路径
|
||||
/// @brief 创建图像帧
|
||||
/// @param file_path 图像路径
|
||||
static FramePtr Create(String const& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建图像帧
|
||||
/// @param res 图像资源
|
||||
/// @brief 创建图像帧
|
||||
/// @param res 图像资源
|
||||
static FramePtr Create(Resource const& res);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建图像帧
|
||||
/// @param texture 纹理
|
||||
/// @brief 创建图像帧
|
||||
/// @param texture 纹理
|
||||
static FramePtr Create(TexturePtr texture);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构建空图像帧
|
||||
/// @brief 构建空图像帧
|
||||
Frame();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载图像
|
||||
/// @param file_path 图像路径
|
||||
/// @brief 加载图像
|
||||
/// @param file_path 图像路径
|
||||
bool Load(String const& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载图像
|
||||
/// @param res 图像资源
|
||||
/// @brief 加载图像
|
||||
/// @param res 图像资源
|
||||
bool Load(Resource const& res);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 裁剪图像帧为矩形
|
||||
/// @param crop_rect 裁剪矩形定义
|
||||
/// @brief 裁剪图像帧为矩形
|
||||
/// @param crop_rect 裁剪矩形定义
|
||||
void SetCropRect(Rect const& crop_rect);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置纹理
|
||||
/// @param texture 纹理
|
||||
/// @brief 设置纹理
|
||||
/// @param texture 纹理
|
||||
void SetTexture(TexturePtr texture);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否有效
|
||||
/// @brief 是否有效
|
||||
bool IsValid() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取宽度
|
||||
/// @brief 获取宽度
|
||||
float GetWidth() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取高度
|
||||
/// @brief 获取高度
|
||||
float GetHeight() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取大小
|
||||
/// @brief 获取大小
|
||||
Size GetSize() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取裁剪位置
|
||||
/// @brief 获取裁剪位置
|
||||
Point GetCropPoint() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取裁剪矩形
|
||||
/// @brief 获取裁剪矩形
|
||||
Rect const& GetCropRect() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取纹理
|
||||
/// @brief 获取纹理
|
||||
TexturePtr GetTexture() const;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -29,51 +29,51 @@ KGE_DECLARE_SMART_PTR(FrameSequence);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 序列帧
|
||||
* @brief 序列帧
|
||||
*/
|
||||
class KGE_API FrameSequence : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建序列帧
|
||||
/// @param frames 图像帧集合
|
||||
/// @brief 创建序列帧
|
||||
/// @param frames 图像帧集合
|
||||
static FrameSequencePtr Create(Vector<FramePtr> const& frames);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构建空序列帧
|
||||
/// @brief 构建空序列帧
|
||||
FrameSequence();
|
||||
|
||||
virtual ~FrameSequence();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加关键帧
|
||||
/// @param frame 图像帧
|
||||
/// @brief 添加关键帧
|
||||
/// @param frame 图像帧
|
||||
void AddFrame(FramePtr frame);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加多个关键帧
|
||||
/// @param frames 图像帧集合
|
||||
/// @brief 添加多个关键帧
|
||||
/// @param frames 图像帧集合
|
||||
void AddFrames(Vector<FramePtr> const& frames);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关键帧
|
||||
/// @param index 图像帧下标
|
||||
/// @brief 获取关键帧
|
||||
/// @param index 图像帧下标
|
||||
FramePtr GetFrame(size_t index) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取所有关键帧
|
||||
/// @brief 获取所有关键帧
|
||||
Vector<FramePtr> const& GetFrames() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取关键帧数量
|
||||
/// @brief 获取关键帧数量
|
||||
size_t GetFramesCount() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取序列帧的拷贝对象
|
||||
/// @brief 获取序列帧的拷贝对象
|
||||
FrameSequencePtr Clone() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取序列帧的倒转
|
||||
/// @brief 获取序列帧的倒转
|
||||
FrameSequencePtr Reverse() const;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -67,13 +67,13 @@ GifSprite::GifSprite()
|
|||
|
||||
bool GifSprite::Load(String const& file_path)
|
||||
{
|
||||
GifImagePtr image = TextureCache::Instance().AddOrGetGifImage(file_path);
|
||||
GifImagePtr image = TextureCache::GetInstance().AddOrGetGifImage(file_path);
|
||||
return Load(image);
|
||||
}
|
||||
|
||||
bool GifSprite::Load(Resource const& res)
|
||||
{
|
||||
GifImagePtr image = TextureCache::Instance().AddOrGetGifImage(res);
|
||||
GifImagePtr image = TextureCache::GetInstance().AddOrGetGifImage(res);
|
||||
return Load(image);
|
||||
}
|
||||
|
||||
|
|
@ -83,17 +83,18 @@ bool GifSprite::Load(GifImagePtr gif)
|
|||
{
|
||||
gif_ = gif;
|
||||
|
||||
next_index_ = 0;
|
||||
loop_count_ = 0;
|
||||
frame_.disposal_type = GifImage::DisposalType::None;
|
||||
|
||||
SetSize(Size{ static_cast<float>(gif_->GetWidthInPixels()), static_cast<float>(gif_->GetHeightInPixels()) });
|
||||
next_index_ = 0;
|
||||
loop_count_ = 0;
|
||||
frame_ = GifImage::Frame();
|
||||
|
||||
if (!frame_rt_)
|
||||
{
|
||||
Renderer::Instance().CreateTextureRenderTarget(frame_rt_);
|
||||
Size frame_size = Size(float(gif_->GetWidthInPixels()), float(gif_->GetHeightInPixels()));
|
||||
frame_rt_ = TextureRenderContext::Create(frame_size);
|
||||
}
|
||||
|
||||
SetSize(frame_rt_->GetSize());
|
||||
|
||||
if (gif_->GetFramesCount() > 0)
|
||||
{
|
||||
ComposeNextFrame();
|
||||
|
|
@ -109,7 +110,7 @@ void GifSprite::OnRender(RenderContext& ctx)
|
|||
{
|
||||
PrepareToRender(ctx);
|
||||
|
||||
ctx.DrawTexture(*frame_to_render_, &frame_.rect, nullptr);
|
||||
ctx.DrawTexture(*frame_to_render_, nullptr, &GetBounds());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -137,10 +138,10 @@ void GifSprite::SetGifImage(GifImagePtr gif)
|
|||
|
||||
void GifSprite::RestartAnimation()
|
||||
{
|
||||
animating_ = true;
|
||||
next_index_ = 0;
|
||||
loop_count_ = 0;
|
||||
frame_.disposal_type = GifImage::DisposalType::None;
|
||||
animating_ = true;
|
||||
next_index_ = 0;
|
||||
loop_count_ = 0;
|
||||
frame_ = GifImage::Frame();
|
||||
}
|
||||
|
||||
void GifSprite::ComposeNextFrame()
|
||||
|
|
@ -181,7 +182,7 @@ void GifSprite::DisposeCurrentFrame()
|
|||
void GifSprite::OverlayNextFrame()
|
||||
{
|
||||
KGE_ASSERT(frame_rt_);
|
||||
KGE_ASSERT(gif_ && gif_->IsValid());
|
||||
KGE_ASSERT(gif_);
|
||||
|
||||
frame_ = gif_->GetFrame(next_index_);
|
||||
|
||||
|
|
@ -196,6 +197,7 @@ void GifSprite::OverlayNextFrame()
|
|||
|
||||
if (next_index_ == 0)
|
||||
{
|
||||
frame_rt_->Clear();
|
||||
loop_count_++;
|
||||
}
|
||||
|
||||
|
|
@ -217,6 +219,7 @@ void GifSprite::OverlayNextFrame()
|
|||
}
|
||||
}
|
||||
|
||||
// Execute callback
|
||||
if (IsLastFrame() && loop_cb_)
|
||||
{
|
||||
loop_cb_(loop_count_ - 1);
|
||||
|
|
@ -239,8 +242,7 @@ void GifSprite::SaveComposedFrame()
|
|||
if (!saved_frame_)
|
||||
{
|
||||
saved_frame_ = new Texture;
|
||||
frame_rt_->CreateTexture(*saved_frame_, frame_to_be_saved->GetSizeInPixels(),
|
||||
frame_to_be_saved->GetPixelFormat());
|
||||
frame_rt_->CreateTexture(*saved_frame_, frame_to_be_saved->GetSizeInPixels());
|
||||
}
|
||||
|
||||
saved_frame_->CopyFrom(frame_to_be_saved);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
#include <kiwano/2d/Actor.h>
|
||||
#include <kiwano/core/Resource.h>
|
||||
#include <kiwano/render/GifImage.h>
|
||||
#include <kiwano/render/RenderContext.h>
|
||||
#include <kiwano/render/TextureRenderContext.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -35,81 +35,81 @@ KGE_DECLARE_SMART_PTR(GifSprite);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief GIF 精灵
|
||||
* @brief GIF 精灵
|
||||
*/
|
||||
class KGE_API GifSprite : public Actor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief GIF播放循环结束回调
|
||||
/// @brief GIF播放循环结束回调
|
||||
using LoopDoneCallback = Function<void(int /* times */)>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief GIF播放结束回调
|
||||
/// @brief GIF播放结束回调
|
||||
using DoneCallback = Function<void()>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建GIF精灵
|
||||
/// @param file_path GIF图片路径
|
||||
/// @brief 创建GIF精灵
|
||||
/// @param file_path GIF图片路径
|
||||
static GifSpritePtr Create(String const& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建GIF精灵
|
||||
/// @param res GIF图片资源
|
||||
/// @brief 创建GIF精灵
|
||||
/// @param res GIF图片资源
|
||||
static GifSpritePtr Create(Resource const& res);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建GIF精灵
|
||||
/// @param gif GIF图片
|
||||
/// @brief 创建GIF精灵
|
||||
/// @param gif GIF图片
|
||||
static GifSpritePtr Create(GifImagePtr gif);
|
||||
|
||||
GifSprite();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载GIF图片
|
||||
/// @param file_path GIF图片路径
|
||||
/// @brief 加载GIF图片
|
||||
/// @param file_path GIF图片路径
|
||||
bool Load(String const& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载GIF图片
|
||||
/// @param res GIF图片资源
|
||||
/// @brief 加载GIF图片
|
||||
/// @param res GIF图片资源
|
||||
bool Load(Resource const& res);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载GIF图片
|
||||
/// @param gif GIF图片
|
||||
/// @brief 加载GIF图片
|
||||
/// @param gif GIF图片
|
||||
bool Load(GifImagePtr gif);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置 GIF 动画循环次数
|
||||
/// @brief 设置 GIF 动画循环次数
|
||||
void SetLoopCount(int loops);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置 GIF 动画每次循环结束回调函数
|
||||
/// @brief 设置 GIF 动画每次循环结束回调函数
|
||||
void SetLoopDoneCallback(LoopDoneCallback const& cb);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置 GIF 动画结束回调函数
|
||||
/// @brief 设置 GIF 动画结束回调函数
|
||||
void SetDoneCallback(DoneCallback const& cb);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置 GIF 图像
|
||||
/// @brief 设置 GIF 图像
|
||||
void SetGifImage(GifImagePtr gif);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 重新播放 GIF 动画
|
||||
/// @brief 重新播放 GIF 动画
|
||||
void RestartAnimation();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取 GIF 动画循环结束回调
|
||||
/// @brief 获取 GIF 动画循环结束回调
|
||||
LoopDoneCallback GetLoopDoneCallback() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取 GIF 动画播放结束回调
|
||||
/// @brief 获取 GIF 动画播放结束回调
|
||||
DoneCallback GetDoneCallback() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取 GIF 图片
|
||||
/// @brief 获取 GIF 图片
|
||||
GifImagePtr GetGifImage() const;
|
||||
|
||||
void OnRender(RenderContext& ctx) override;
|
||||
|
|
@ -118,35 +118,35 @@ private:
|
|||
void Update(Duration dt) override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否是最后一帧
|
||||
/// @brief 是否是最后一帧
|
||||
bool IsLastFrame() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 动画是否已结束
|
||||
/// @brief 动画是否已结束
|
||||
bool EndOfAnimation() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 合成下一帧
|
||||
/// @brief 合成下一帧
|
||||
void ComposeNextFrame();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 解析当前图像帧
|
||||
/// @brief 解析当前图像帧
|
||||
void DisposeCurrentFrame();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 覆盖下一帧
|
||||
/// @brief 覆盖下一帧
|
||||
void OverlayNextFrame();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 保存合成后的图像帧
|
||||
/// @brief 保存合成后的图像帧
|
||||
void SaveComposedFrame();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 恢复已保存的图像帧
|
||||
/// @brief 恢复已保存的图像帧
|
||||
void RestoreSavedFrame();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 清空当前图像区域
|
||||
/// @brief 清空当前图像区域
|
||||
void ClearCurrentFrameArea();
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -19,47 +19,47 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/2d/Layer.h>
|
||||
#include <kiwano/2d/LayerActor.h>
|
||||
#include <kiwano/render/Renderer.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
||||
LayerPtr Layer::Create()
|
||||
LayerActorPtr LayerActor::Create()
|
||||
{
|
||||
LayerPtr ptr = new (std::nothrow) Layer;
|
||||
LayerActorPtr ptr = new (std::nothrow) LayerActor;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Layer::Layer()
|
||||
LayerActor::LayerActor()
|
||||
: swallow_(false)
|
||||
{
|
||||
}
|
||||
|
||||
Layer::~Layer() {}
|
||||
LayerActor::~LayerActor() {}
|
||||
|
||||
void Layer::SetClipRect(Rect const& clip_rect)
|
||||
void LayerActor::SetClipRect(Rect const& clip_rect)
|
||||
{
|
||||
area_.SetAreaRect(clip_rect);
|
||||
layer_.SetClipRect(clip_rect);
|
||||
}
|
||||
|
||||
void Layer::SetOpacity(float opacity)
|
||||
void LayerActor::SetOpacity(float opacity)
|
||||
{
|
||||
// Actor::SetOpacity(opacity);
|
||||
area_.SetOpacity(opacity);
|
||||
layer_.SetOpacity(opacity);
|
||||
}
|
||||
|
||||
void Layer::SetMaskShape(ShapePtr mask)
|
||||
void LayerActor::SetMaskShape(ShapePtr mask)
|
||||
{
|
||||
area_.SetMaskShape(mask);
|
||||
layer_.SetMaskShape(mask);
|
||||
}
|
||||
|
||||
void Layer::SetMaskTransform(Matrix3x2 const& transform)
|
||||
void LayerActor::SetMaskTransform(Matrix3x2 const& transform)
|
||||
{
|
||||
area_.SetMaskTransform(transform);
|
||||
layer_.SetMaskTransform(transform);
|
||||
}
|
||||
|
||||
bool Layer::DispatchEvent(Event* evt)
|
||||
bool LayerActor::DispatchEvent(Event* evt)
|
||||
{
|
||||
if (!IsVisible())
|
||||
return true;
|
||||
|
|
@ -71,18 +71,18 @@ bool Layer::DispatchEvent(Event* evt)
|
|||
return Actor::DispatchEvent(evt);
|
||||
}
|
||||
|
||||
void Layer::Render(RenderContext& ctx)
|
||||
void LayerActor::Render(RenderContext& ctx)
|
||||
{
|
||||
ctx.PushLayer(area_);
|
||||
ctx.PushLayer(layer_);
|
||||
|
||||
Actor::Render(ctx);
|
||||
|
||||
ctx.PopLayer();
|
||||
}
|
||||
|
||||
bool Layer::CheckVisibility(RenderContext& ctx) const
|
||||
bool LayerActor::CheckVisibility(RenderContext& ctx) const
|
||||
{
|
||||
// Do not need to render Layer
|
||||
// Do not need to render LayerActor
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -20,12 +20,12 @@
|
|||
|
||||
#pragma once
|
||||
#include <kiwano/2d/Actor.h>
|
||||
#include <kiwano/render/LayerArea.h>
|
||||
#include <kiwano/render/Layer.h>
|
||||
#include <kiwano/render/RenderContext.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
KGE_DECLARE_SMART_PTR(Layer);
|
||||
KGE_DECLARE_SMART_PTR(LayerActor);
|
||||
|
||||
/**
|
||||
* \addtogroup Actors
|
||||
|
|
@ -34,56 +34,56 @@ KGE_DECLARE_SMART_PTR(Layer);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 图层
|
||||
* @brief 图层
|
||||
*/
|
||||
class KGE_API Layer : public Actor
|
||||
class KGE_API LayerActor : public Actor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建图层
|
||||
static LayerPtr Create();
|
||||
/// @brief 创建图层
|
||||
static LayerActorPtr Create();
|
||||
|
||||
Layer();
|
||||
LayerActor();
|
||||
|
||||
virtual ~Layer();
|
||||
virtual ~LayerActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否开启消息吞没
|
||||
/// @brief 是否开启消息吞没
|
||||
bool IsSwallowEventsEnabled() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置消息吞没功能
|
||||
/// @param enabled 是否启用
|
||||
/// @brief 设置消息吞没功能
|
||||
/// @param enabled 是否启用
|
||||
void SetSwallowEvents(bool enabled);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置裁剪区域
|
||||
/// @param clip_rect 裁剪矩形
|
||||
/// @brief 设置裁剪区域
|
||||
/// @param clip_rect 裁剪矩形
|
||||
void SetClipRect(Rect const& clip_rect);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置图层透明度
|
||||
/// @param opacity 透明度
|
||||
/// @brief 设置图层透明度
|
||||
/// @param opacity 透明度
|
||||
void SetOpacity(float opacity) override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置几何蒙层
|
||||
/// @param mask 蒙层的形状
|
||||
/// @brief 设置几何蒙层
|
||||
/// @param mask 蒙层的形状
|
||||
void SetMaskShape(ShapePtr mask);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置几何蒙层的二维变换
|
||||
/// @param transform 应用于蒙层的二维变换
|
||||
/// @brief 设置几何蒙层的二维变换
|
||||
/// @param transform 应用于蒙层的二维变换
|
||||
void SetMaskTransform(Matrix3x2 const& transform);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置图层区域
|
||||
/// @param area 图层区域属性
|
||||
void SetArea(LayerArea const& area);
|
||||
/// @brief 设置图层区域
|
||||
/// @param area 图层区域属性
|
||||
void SetLayer(Layer const& layer);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取图层区域
|
||||
LayerArea const& GetArea() const;
|
||||
/// @brief 获取图层区域
|
||||
Layer const& GetLayer() const;
|
||||
|
||||
bool DispatchEvent(Event* evt) override;
|
||||
|
||||
|
|
@ -93,29 +93,29 @@ protected:
|
|||
bool CheckVisibility(RenderContext& ctx) const override;
|
||||
|
||||
private:
|
||||
bool swallow_;
|
||||
LayerArea area_;
|
||||
bool swallow_;
|
||||
Layer layer_;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
inline bool Layer::IsSwallowEventsEnabled() const
|
||||
inline bool LayerActor::IsSwallowEventsEnabled() const
|
||||
{
|
||||
return swallow_;
|
||||
}
|
||||
|
||||
inline void Layer::SetSwallowEvents(bool enabled)
|
||||
inline void LayerActor::SetSwallowEvents(bool enabled)
|
||||
{
|
||||
swallow_ = enabled;
|
||||
}
|
||||
|
||||
inline void Layer::SetArea(LayerArea const& area)
|
||||
inline void LayerActor::SetLayer(Layer const& layer)
|
||||
{
|
||||
area_ = area;
|
||||
layer_ = layer;
|
||||
}
|
||||
|
||||
inline LayerArea const& Layer::GetArea() const
|
||||
inline Layer const& LayerActor::GetLayer() const
|
||||
{
|
||||
return area_;
|
||||
return layer_;
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
@ -91,7 +91,7 @@ void ShapeActor::OnRender(RenderContext& ctx)
|
|||
if (stroke_brush_)
|
||||
{
|
||||
ctx.SetCurrentBrush(stroke_brush_);
|
||||
ctx.DrawShape(*shape_, stroke_width_ * 2 /* twice width for widening */, stroke_style_);
|
||||
ctx.DrawShape(*shape_, stroke_style_, stroke_width_ * 2 /* twice width for widening */);
|
||||
}
|
||||
|
||||
if (fill_brush_)
|
||||
|
|
|
|||
|
|
@ -43,83 +43,83 @@ KGE_DECLARE_SMART_PTR(PolygonActor);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 形状角色
|
||||
* @brief 形状角色
|
||||
*/
|
||||
class KGE_API ShapeActor : public Actor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建形状角色
|
||||
/// @brief 创建形状角色
|
||||
static ShapeActorPtr Create();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造形状角色
|
||||
/// @brief 构造形状角色
|
||||
ShapeActor();
|
||||
|
||||
virtual ~ShapeActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取填充画刷
|
||||
/// @brief 获取填充画刷
|
||||
BrushPtr GetFillBrush() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取轮廓画刷
|
||||
/// @brief 获取轮廓画刷
|
||||
BrushPtr GetStrokeBrush() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取线条宽度
|
||||
/// @brief 获取线条宽度
|
||||
float GetStrokeWidth() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取线条样式
|
||||
/// @brief 获取线条样式
|
||||
StrokeStylePtr GetStrokeStyle() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取形状
|
||||
/// @brief 获取形状
|
||||
ShapePtr GetShape() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取边界
|
||||
/// @brief 获取边界
|
||||
Rect GetBounds() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取外切包围盒
|
||||
/// @brief 获取外切包围盒
|
||||
Rect GetBoundingBox() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 判断点是否在形状内
|
||||
/// @brief 判断点是否在形状内
|
||||
bool ContainsPoint(const Point& point) const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置填充颜色
|
||||
/// @param color 填充颜色
|
||||
/// @brief 设置填充颜色
|
||||
/// @param color 填充颜色
|
||||
void SetFillColor(Color const& color);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置填充画刷
|
||||
/// @param[in] brush 填充画刷
|
||||
/// @brief 设置填充画刷
|
||||
/// @param[in] brush 填充画刷
|
||||
void SetFillBrush(BrushPtr brush);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置轮廓颜色
|
||||
/// @param color 轮廓颜色
|
||||
/// @brief 设置轮廓颜色
|
||||
/// @param color 轮廓颜色
|
||||
void SetStrokeColor(Color const& color);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置轮廓画刷
|
||||
/// @param[in] brush 轮廓画刷
|
||||
/// @brief 设置轮廓画刷
|
||||
/// @param[in] brush 轮廓画刷
|
||||
void SetStrokeBrush(BrushPtr brush);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置线条宽度,默认为 1.0
|
||||
/// @brief 设置线条宽度,默认为 1.0
|
||||
void SetStrokeWidth(float width);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置线条样式
|
||||
/// @brief 设置线条样式
|
||||
void SetStrokeStyle(StrokeStylePtr stroke_style);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置形状
|
||||
/// @brief 设置形状
|
||||
void SetShape(ShapePtr shape);
|
||||
|
||||
void OnRender(RenderContext& ctx) override;
|
||||
|
|
@ -137,14 +137,14 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 线段角色
|
||||
/// @brief 线段角色
|
||||
class KGE_API LineActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建线段角色
|
||||
/// @param begin 线段起点
|
||||
/// @param end 线段终点
|
||||
/// @brief 创建线段角色
|
||||
/// @param begin 线段起点
|
||||
/// @param end 线段终点
|
||||
static LineActorPtr Create(Point const& begin, Point const& end);
|
||||
|
||||
LineActor();
|
||||
|
|
@ -152,27 +152,27 @@ public:
|
|||
virtual ~LineActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取线段起点
|
||||
/// @brief 获取线段起点
|
||||
Point const& GetBeginPoint() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取线段终点
|
||||
/// @brief 获取线段终点
|
||||
Point const& GetEndPoint() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置线段起点
|
||||
/// @param begin 线段起点
|
||||
/// @brief 设置线段起点
|
||||
/// @param begin 线段起点
|
||||
void SetBeginPoint(Point const& begin);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置线段终点
|
||||
/// @param end 线段终点
|
||||
/// @brief 设置线段终点
|
||||
/// @param end 线段终点
|
||||
void SetEndPoint(Point const& end);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置线段起点和终点
|
||||
/// @param begin 线段起点
|
||||
/// @param end 线段终点
|
||||
/// @brief 设置线段起点和终点
|
||||
/// @param begin 线段起点
|
||||
/// @param end 线段终点
|
||||
void SetLine(Point const& begin, Point const& end);
|
||||
|
||||
private:
|
||||
|
|
@ -181,13 +181,13 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 矩形角色
|
||||
/// @brief 矩形角色
|
||||
class KGE_API RectActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建矩形角色
|
||||
/// @param size 矩形大小
|
||||
/// @brief 创建矩形角色
|
||||
/// @param size 矩形大小
|
||||
static RectActorPtr Create(Size const& size);
|
||||
|
||||
RectActor();
|
||||
|
|
@ -195,12 +195,12 @@ public:
|
|||
virtual ~RectActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取矩形大小
|
||||
/// @brief 获取矩形大小
|
||||
Size const& GetRectSize() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置矩形大小
|
||||
/// @param size 矩形大小
|
||||
/// @brief 设置矩形大小
|
||||
/// @param size 矩形大小
|
||||
void SetRectSize(Size const& size);
|
||||
|
||||
private:
|
||||
|
|
@ -208,14 +208,14 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 圆角矩形角色
|
||||
/// @brief 圆角矩形角色
|
||||
class KGE_API RoundedRectActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建圆角矩形角色
|
||||
/// @param size 圆角矩形大小
|
||||
/// @param radius 圆角半径
|
||||
/// @brief 创建圆角矩形角色
|
||||
/// @param size 圆角矩形大小
|
||||
/// @param radius 圆角半径
|
||||
static RoundedRectActorPtr Create(Size const& size, Vec2 const& radius);
|
||||
|
||||
RoundedRectActor();
|
||||
|
|
@ -223,27 +223,27 @@ public:
|
|||
virtual ~RoundedRectActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取圆角半径
|
||||
/// @brief 获取圆角半径
|
||||
Vec2 GetRadius() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取圆角矩形大小
|
||||
/// @brief 获取圆角矩形大小
|
||||
Size GetRectSize() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置圆角半径
|
||||
/// @param radius 圆角半径
|
||||
/// @brief 设置圆角半径
|
||||
/// @param radius 圆角半径
|
||||
void SetRadius(Vec2 const& radius);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置圆角矩形大小
|
||||
/// @param size 圆角矩形大小
|
||||
/// @brief 设置圆角矩形大小
|
||||
/// @param size 圆角矩形大小
|
||||
void SetRectSize(Size const& size);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置圆角矩形
|
||||
/// @param size 圆角矩形大小
|
||||
/// @param radius 圆角半径
|
||||
/// @brief 设置圆角矩形
|
||||
/// @param size 圆角矩形大小
|
||||
/// @param radius 圆角半径
|
||||
void SetRoundedRect(Size const& size, Vec2 const& radius);
|
||||
|
||||
private:
|
||||
|
|
@ -252,13 +252,13 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 圆形角色
|
||||
/// @brief 圆形角色
|
||||
class KGE_API CircleActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建圆形角色
|
||||
/// @param radius 圆形半径
|
||||
/// @brief 创建圆形角色
|
||||
/// @param radius 圆形半径
|
||||
static CircleActorPtr Create(float radius);
|
||||
|
||||
CircleActor();
|
||||
|
|
@ -266,12 +266,12 @@ public:
|
|||
virtual ~CircleActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取圆形半径
|
||||
/// @brief 获取圆形半径
|
||||
float GetRadius() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置圆形半径
|
||||
/// @param radius 圆形半径
|
||||
/// @brief 设置圆形半径
|
||||
/// @param radius 圆形半径
|
||||
void SetRadius(float radius);
|
||||
|
||||
private:
|
||||
|
|
@ -279,13 +279,13 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 椭圆角色
|
||||
/// @brief 椭圆角色
|
||||
class KGE_API EllipseActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建椭圆角色
|
||||
/// @param radius 椭圆半径
|
||||
/// @brief 创建椭圆角色
|
||||
/// @param radius 椭圆半径
|
||||
static EllipseActorPtr Create(Vec2 const& radius);
|
||||
|
||||
EllipseActor();
|
||||
|
|
@ -293,12 +293,12 @@ public:
|
|||
virtual ~EllipseActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取椭圆半径
|
||||
/// @brief 获取椭圆半径
|
||||
Vec2 GetRadius() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置椭圆半径
|
||||
/// @param radius 椭圆半径
|
||||
/// @brief 设置椭圆半径
|
||||
/// @param radius 椭圆半径
|
||||
void SetRadius(Vec2 const& radius);
|
||||
|
||||
private:
|
||||
|
|
@ -306,13 +306,13 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 多边形角色
|
||||
/// @brief 多边形角色
|
||||
class KGE_API PolygonActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建多边形角色
|
||||
/// @param points 多边形端点集合
|
||||
/// @brief 创建多边形角色
|
||||
/// @param points 多边形端点集合
|
||||
static PolygonActorPtr Create(Vector<Point> const& points);
|
||||
|
||||
PolygonActor();
|
||||
|
|
@ -320,8 +320,8 @@ public:
|
|||
virtual ~PolygonActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置多边形端点
|
||||
/// @param points 多边形端点集合
|
||||
/// @brief 设置多边形端点
|
||||
/// @param points 多边形端点集合
|
||||
void SetVertices(Vector<Point> const& points);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -33,24 +33,24 @@ KGE_DECLARE_SMART_PTR(Sprite);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 精灵
|
||||
* @brief 精灵
|
||||
*/
|
||||
class KGE_API Sprite : public Actor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建精灵
|
||||
/// @param file_path 本地图片路径
|
||||
/// @brief 创建精灵
|
||||
/// @param file_path 本地图片路径
|
||||
static SpritePtr Create(String const& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建精灵
|
||||
/// @param res 图片资源
|
||||
/// @brief 创建精灵
|
||||
/// @param res 图片资源
|
||||
static SpritePtr Create(Resource const& res);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建精灵
|
||||
/// @param frame 图像帧
|
||||
/// @brief 创建精灵
|
||||
/// @param frame 图像帧
|
||||
static SpritePtr Create(FramePtr frame);
|
||||
|
||||
Sprite();
|
||||
|
|
@ -58,27 +58,27 @@ public:
|
|||
virtual ~Sprite();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载本地图片
|
||||
/// @param file_path 本地图片路径
|
||||
/// @brief 加载本地图片
|
||||
/// @param file_path 本地图片路径
|
||||
bool Load(String const& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载图像资源
|
||||
/// @param res 图片资源
|
||||
/// @brief 加载图像资源
|
||||
/// @param res 图片资源
|
||||
bool Load(Resource const& res);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 使用矩形区域裁剪精灵
|
||||
/// @param crop_rect 裁剪矩形
|
||||
/// @brief 使用矩形区域裁剪精灵
|
||||
/// @param crop_rect 裁剪矩形
|
||||
void SetCropRect(const Rect& crop_rect);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取帧图像
|
||||
/// @brief 获取帧图像
|
||||
FramePtr GetFrame() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置图像帧
|
||||
/// @param[in] frame 图像帧
|
||||
/// @brief 设置图像帧
|
||||
/// @param[in] frame 图像帧
|
||||
void SetFrame(FramePtr frame);
|
||||
|
||||
void OnRender(RenderContext& ctx) override;
|
||||
|
|
|
|||
|
|
@ -36,19 +36,19 @@ Stage::Stage()
|
|||
SetStage(this);
|
||||
|
||||
SetAnchor(Vec2{ 0, 0 });
|
||||
SetSize(Renderer::Instance().GetOutputSize());
|
||||
SetSize(Renderer::GetInstance().GetOutputSize());
|
||||
}
|
||||
|
||||
Stage::~Stage() {}
|
||||
|
||||
void Stage::OnEnter()
|
||||
{
|
||||
KGE_SYS_LOG(L"Stage entered");
|
||||
KGE_SYS_LOG("Stage entered");
|
||||
}
|
||||
|
||||
void Stage::OnExit()
|
||||
{
|
||||
KGE_SYS_LOG(L"Stage exited");
|
||||
KGE_SYS_LOG("Stage exited");
|
||||
}
|
||||
|
||||
void Stage::RenderBorder(RenderContext& ctx)
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ KGE_DECLARE_SMART_PTR(Stage);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 舞台
|
||||
* @details 舞台是所有角色的载体,是导演直接控制的对象
|
||||
* @brief 舞台
|
||||
* @details 舞台是所有角色的载体,是导演直接控制的对象
|
||||
* @see kiwano::Actor kiwano::Director
|
||||
*/
|
||||
class KGE_API Stage : public Actor
|
||||
|
|
@ -44,7 +44,7 @@ class KGE_API Stage : public Actor
|
|||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 进入舞台时
|
||||
/// @brief 进入舞台时
|
||||
static StagePtr Create();
|
||||
|
||||
Stage();
|
||||
|
|
@ -52,34 +52,34 @@ public:
|
|||
virtual ~Stage();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 进入舞台时
|
||||
/// @details 重载该函数以处理进入舞台前的行为
|
||||
/// @brief 进入舞台时
|
||||
/// @details 重载该函数以处理进入舞台前的行为
|
||||
virtual void OnEnter();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 退出舞台时
|
||||
/// @details 重载该函数以处理退出舞台前的行为
|
||||
/// @brief 退出舞台时
|
||||
/// @details 重载该函数以处理退出舞台前的行为
|
||||
virtual void OnExit();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取角色边界填充画刷
|
||||
/// @brief 获取角色边界填充画刷
|
||||
BrushPtr GetBorderFillBrush() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取角色边界轮廓画刷
|
||||
/// @brief 获取角色边界轮廓画刷
|
||||
BrushPtr GetBorderStrokeBrush() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置角色边界填充画刷
|
||||
/// @brief 设置角色边界填充画刷
|
||||
void SetBorderFillBrush(BrushPtr brush);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置角色边界轮廓画刷
|
||||
/// @brief 设置角色边界轮廓画刷
|
||||
void SetBorderStrokeBrush(BrushPtr brush);
|
||||
|
||||
protected:
|
||||
/// \~chinese
|
||||
/// @brief 绘制所有子角色的边界
|
||||
/// @brief 绘制所有子角色的边界
|
||||
void RenderBorder(RenderContext& ctx) override;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -34,20 +34,20 @@ KGE_DECLARE_SMART_PTR(TextActor);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 文本角色
|
||||
* @brief 文本角色
|
||||
*/
|
||||
class KGE_API TextActor : public Actor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建文本角色
|
||||
/// @param text 文字内容
|
||||
/// @brief 创建文本角色
|
||||
/// @param text 文字内容
|
||||
static TextActorPtr Create(const String& text);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建文本角色
|
||||
/// @param text 文字内容
|
||||
/// @param style 文本样式
|
||||
/// @brief 创建文本角色
|
||||
/// @param text 文字内容
|
||||
/// @param style 文本样式
|
||||
static TextActorPtr Create(const String& text, const TextStyle& style);
|
||||
|
||||
TextActor();
|
||||
|
|
@ -55,108 +55,108 @@ public:
|
|||
virtual ~TextActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取文本
|
||||
/// @brief 获取文本
|
||||
const String& GetText() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取文本样式
|
||||
/// @brief 获取文本样式
|
||||
const TextStyle& GetStyle() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取文本布局
|
||||
/// @brief 获取文本布局
|
||||
const TextLayout& GetLayout() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取文本布局大小
|
||||
/// @brief 获取文本布局大小
|
||||
Size GetLayoutSize() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取填充画刷
|
||||
/// @brief 获取填充画刷
|
||||
BrushPtr GetFillBrush() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取描边画刷
|
||||
/// @brief 获取描边画刷
|
||||
BrushPtr GetOutlineBrush() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取字体
|
||||
/// @brief 获取字体
|
||||
FontPtr GetFont() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置文本
|
||||
/// @brief 设置文本
|
||||
void SetText(String const& text);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置文本样式
|
||||
/// @brief 设置文本样式
|
||||
void SetStyle(const TextStyle& style);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置字体
|
||||
/// @brief 设置字体
|
||||
void SetFont(FontPtr font);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置字体族
|
||||
/// @brief 设置字体族
|
||||
void SetFontFamily(String const& family);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置字号(默认值为 18)
|
||||
/// @brief 设置字号(默认值为 18)
|
||||
void SetFontSize(float size);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置字体粗细值(默认值为 FontWeight::Normal)
|
||||
/// @brief 设置字体粗细值(默认值为 FontWeight::Normal)
|
||||
void SetFontWeight(uint32_t weight);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置文字填充画刷
|
||||
/// @brief 设置文字填充画刷
|
||||
void SetFillBrush(BrushPtr brush);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置文字填充颜色(默认值为 Color::White)
|
||||
/// @brief 设置文字填充颜色(默认值为 Color::White)
|
||||
void SetFillColor(Color const& color);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置文字斜体(默认值为 false)
|
||||
/// @brief 设置文字斜体(默认值为 false)
|
||||
void SetItalic(bool italic);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置文本自动换行的宽度(默认为 0)
|
||||
/// @brief 设置文本自动换行的宽度(默认为 0)
|
||||
void SetWrapWidth(float wrap_width);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置行间距(默认为 0)
|
||||
/// @brief 设置行间距(默认为 0)
|
||||
void SetLineSpacing(float line_spacing);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置对齐方式(默认为 TextAlign::Left)
|
||||
/// @brief 设置对齐方式(默认为 TextAlign::Left)
|
||||
void SetAlignment(TextAlign align);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置文字描边画刷
|
||||
/// @brief 设置文字描边画刷
|
||||
void SetOutlineBrush(BrushPtr brush);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置文字描边颜色
|
||||
/// @brief 设置文字描边颜色
|
||||
void SetOutlineColor(Color const& outline_color);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置文字描边线宽
|
||||
/// @brief 设置文字描边线宽
|
||||
void SetOutlineWidth(float outline_width);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置文字描边线相交样式
|
||||
/// @brief 设置文字描边线相交样式
|
||||
void SetOutlineStroke(StrokeStylePtr outline_stroke);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置是否显示下划线(默认值为 false)
|
||||
/// @brief 设置是否显示下划线(默认值为 false)
|
||||
void SetUnderline(bool enable);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置是否显示删除线(默认值为 false)
|
||||
/// @brief 设置是否显示删除线(默认值为 false)
|
||||
void SetStrikethrough(bool enable);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 更新文字布局
|
||||
/// @details 文字布局是懒更新的,手动更新文字布局以更新节点状态
|
||||
/// @brief 更新文字布局
|
||||
/// @details 文字布局是懒更新的,手动更新文字布局以更新节点状态
|
||||
void UpdateLayout();
|
||||
|
||||
void OnRender(RenderContext& ctx) override;
|
||||
|
|
|
|||
|
|
@ -58,16 +58,16 @@ void Transition::Init(StagePtr prev, StagePtr next)
|
|||
|
||||
out_stage_ = prev;
|
||||
in_stage_ = next;
|
||||
window_size_ = Renderer::Instance().GetOutputSize();
|
||||
window_size_ = Renderer::GetInstance().GetOutputSize();
|
||||
|
||||
if (in_stage_)
|
||||
{
|
||||
in_layer_.SetAreaRect(Rect{ Point(), window_size_ });
|
||||
in_layer_.SetClipRect(Rect{ Point(), window_size_ });
|
||||
}
|
||||
|
||||
if (out_stage_)
|
||||
{
|
||||
out_layer_.SetAreaRect(Rect{ Point(), window_size_ });
|
||||
out_layer_.SetClipRect(Rect{ Point(), window_size_ });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -151,14 +151,14 @@ void BoxTransition::Update(Duration dt)
|
|||
|
||||
if (process_ < .5f)
|
||||
{
|
||||
out_layer_.SetAreaRect(Rect(window_size_.x * process_, window_size_.y * process_,
|
||||
out_layer_.SetClipRect(Rect(window_size_.x * process_, window_size_.y * process_,
|
||||
window_size_.x * (1 - process_), window_size_.y * (1 - process_)));
|
||||
}
|
||||
else
|
||||
{
|
||||
out_layer_.SetOpacity(0.f);
|
||||
in_layer_.SetOpacity(1.f);
|
||||
in_layer_.SetAreaRect(Rect(window_size_.x * (1 - process_), window_size_.y * (1 - process_),
|
||||
in_layer_.SetClipRect(Rect(window_size_.x * (1 - process_), window_size_.y * (1 - process_),
|
||||
window_size_.x * process_, window_size_.y * process_));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
#include <kiwano/2d/Stage.h>
|
||||
#include <kiwano/render/LayerArea.h>
|
||||
#include <kiwano/render/Layer.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -36,7 +36,7 @@ KGE_DECLARE_SMART_PTR(RotationTransition);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 舞台过渡动画
|
||||
* @brief 舞台过渡动画
|
||||
*/
|
||||
class KGE_API Transition : public virtual ObjectBase
|
||||
{
|
||||
|
|
@ -49,48 +49,48 @@ public:
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 设置动画时长
|
||||
* @brief 设置动画时长
|
||||
*/
|
||||
void SetDuration(Duration dt);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 场景过渡动画是否已结束
|
||||
* @brief 场景过渡动画是否已结束
|
||||
*/
|
||||
bool IsDone();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 初始化场景过渡动画
|
||||
* @param[in] prev 转出场景
|
||||
* @param[in] next 转入场景
|
||||
* @brief 初始化场景过渡动画
|
||||
* @param[in] prev 转出场景
|
||||
* @param[in] next 转入场景
|
||||
*/
|
||||
virtual void Init(StagePtr prev, StagePtr next);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 更新过渡动画
|
||||
* @param dt 距上一次更新的时间间隔
|
||||
* @brief 更新过渡动画
|
||||
* @param dt 距上一次更新的时间间隔
|
||||
*/
|
||||
virtual void Update(Duration dt);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 渲染过度动画
|
||||
* @param[in] ctx 渲染上下文
|
||||
* @brief 渲染过度动画
|
||||
* @param[in] ctx 渲染上下文
|
||||
*/
|
||||
virtual void Render(RenderContext& ctx);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 停止动画
|
||||
* @brief 停止动画
|
||||
*/
|
||||
virtual void Stop();
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 重置动画
|
||||
* @brief 重置动画
|
||||
*/
|
||||
virtual void Reset() {}
|
||||
|
||||
|
|
@ -102,22 +102,22 @@ protected:
|
|||
Size window_size_;
|
||||
StagePtr out_stage_;
|
||||
StagePtr in_stage_;
|
||||
LayerArea out_layer_;
|
||||
LayerArea in_layer_;
|
||||
Layer out_layer_;
|
||||
Layer in_layer_;
|
||||
};
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 淡入淡出过渡动画
|
||||
* @details 前一场景淡出动画结束后,后一场景淡入
|
||||
* @brief 淡入淡出过渡动画
|
||||
* @details 前一场景淡出动画结束后,后一场景淡入
|
||||
*/
|
||||
class FadeTransition : public Transition
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 创建淡入淡出过渡动画
|
||||
* @param duration 动画时长
|
||||
* @brief 创建淡入淡出过渡动画
|
||||
* @param duration 动画时长
|
||||
*/
|
||||
static FadeTransitionPtr Create(Duration duration);
|
||||
|
||||
|
|
@ -131,16 +131,16 @@ protected:
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 渐变过渡动画
|
||||
* @details 前一场景淡出动画的同时,后一场景淡入
|
||||
* @brief 渐变过渡动画
|
||||
* @details 前一场景淡出动画的同时,后一场景淡入
|
||||
*/
|
||||
class EmergeTransition : public Transition
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 创建渐变过渡动画
|
||||
* @param duration 动画时长
|
||||
* @brief 创建渐变过渡动画
|
||||
* @param duration 动画时长
|
||||
*/
|
||||
static EmergeTransitionPtr Create(Duration duration);
|
||||
|
||||
|
|
@ -154,16 +154,16 @@ protected:
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 盒状过渡动画
|
||||
* @details 前一场景以盒状收缩至消失,后一场景以盒状扩大
|
||||
* @brief 盒状过渡动画
|
||||
* @details 前一场景以盒状收缩至消失,后一场景以盒状扩大
|
||||
*/
|
||||
class BoxTransition : public Transition
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 创建盒状过渡动画
|
||||
* @param duration 动画时长
|
||||
* @brief 创建盒状过渡动画
|
||||
* @param duration 动画时长
|
||||
*/
|
||||
static BoxTransitionPtr Create(Duration duration);
|
||||
|
||||
|
|
@ -177,29 +177,29 @@ protected:
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 位移过渡动画
|
||||
* @details 两场景以位移的方式切换
|
||||
* @brief 位移过渡动画
|
||||
* @details 两场景以位移的方式切换
|
||||
*/
|
||||
class MoveTransition : public Transition
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 位移方式
|
||||
* @brief 位移方式
|
||||
*/
|
||||
enum class Type : int
|
||||
{
|
||||
Up, ///< 上移
|
||||
Down, ///< 下移
|
||||
Left, ///< 左移
|
||||
Right ///< 右移
|
||||
Up, ///< 上移
|
||||
Down, ///< 下移
|
||||
Left, ///< 左移
|
||||
Right ///< 右移
|
||||
};
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 创建位移过渡动画
|
||||
* @param duration 动画时长
|
||||
* @param type 位移方式
|
||||
* @brief 创建位移过渡动画
|
||||
* @param duration 动画时长
|
||||
* @param type 位移方式
|
||||
*/
|
||||
static MoveTransitionPtr Create(Duration duration, Type type);
|
||||
|
||||
|
|
@ -220,17 +220,17 @@ private:
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 旋转过渡动画
|
||||
* @details 前一场景以旋转方式收缩至消失,后一场景以旋转方式扩大
|
||||
* @brief 旋转过渡动画
|
||||
* @details 前一场景以旋转方式收缩至消失,后一场景以旋转方式扩大
|
||||
*/
|
||||
class RotationTransition : public Transition
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 创建旋转过渡动画
|
||||
* @param duration 动画时长
|
||||
* @param rotation 旋转度数
|
||||
* @brief 创建旋转过渡动画
|
||||
* @param duration 动画时长
|
||||
* @param rotation 旋转度数
|
||||
*/
|
||||
static RotationTransitionPtr Create(Duration duration, float rotation = 360.0f);
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ KGE_DECLARE_SMART_PTR(Action);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* \defgroup Actions 动画
|
||||
* \defgroup Actions 动画
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -43,7 +43,7 @@ KGE_DECLARE_SMART_PTR(Action);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 动画
|
||||
/// @brief 动画
|
||||
class KGE_API Action
|
||||
: public virtual ObjectBase
|
||||
, protected IntrusiveListItem<ActionPtr>
|
||||
|
|
@ -54,7 +54,7 @@ class KGE_API Action
|
|||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 动画结束时的回调函数
|
||||
/// @brief 动画结束时的回调函数
|
||||
using DoneCallback = Function<void(Actor* /* target */)>;
|
||||
|
||||
Action();
|
||||
|
|
@ -62,120 +62,120 @@ public:
|
|||
virtual ~Action();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 继续动画
|
||||
/// @brief 继续动画
|
||||
void Resume();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 暂停动画
|
||||
/// @brief 暂停动画
|
||||
void Pause();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 停止动画
|
||||
/// @brief 停止动画
|
||||
void Stop();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画延时
|
||||
/// @brief 设置动画延时
|
||||
void SetDelay(Duration delay);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置循环次数
|
||||
/// @param loops 循环次数,-1 为永久循环
|
||||
/// @brief 设置循环次数
|
||||
/// @param loops 循环次数,-1 为永久循环
|
||||
void SetLoops(int loops);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 动画结束时移除目标角色
|
||||
/// @brief 动画结束时移除目标角色
|
||||
void RemoveTargetWhenDone();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画结束时的回调函数
|
||||
/// @brief 设置动画结束时的回调函数
|
||||
void SetDoneCallback(DoneCallback const& cb);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画循环结束时的回调函数
|
||||
/// @brief 设置动画循环结束时的回调函数
|
||||
void SetLoopDoneCallback(DoneCallback const& cb);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画的拷贝
|
||||
/// @brief 获取动画的拷贝
|
||||
virtual ActionPtr Clone() const = 0;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画的倒转
|
||||
/// @brief 获取动画的倒转
|
||||
virtual ActionPtr Reverse() const = 0;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画的运行状态
|
||||
/// @brief 获取动画的运行状态
|
||||
bool IsRunning() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画的循环次数
|
||||
/// @brief 获取动画的循环次数
|
||||
int GetLoops() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画的延时
|
||||
/// @brief 获取动画的延时
|
||||
Duration GetDelay() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画结束时的回调函数
|
||||
/// @brief 获取动画结束时的回调函数
|
||||
DoneCallback GetDoneCallback() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画循环结束时的回调函数
|
||||
/// @brief 获取动画循环结束时的回调函数
|
||||
DoneCallback GetLoopDoneCallback() const;
|
||||
|
||||
protected:
|
||||
/// \~chinese
|
||||
/// @brief 初始化动画
|
||||
/// @brief 初始化动画
|
||||
virtual void Init(Actor* target);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 更新动画
|
||||
/// @brief 更新动画
|
||||
virtual void Update(Actor* target, Duration dt);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 更新一个时间步
|
||||
/// @brief 更新一个时间步
|
||||
void UpdateStep(Actor* target, Duration dt);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 完成动画
|
||||
/// @brief 完成动画
|
||||
void Complete(Actor* target);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 重新开始动画
|
||||
/// @brief 重新开始动画
|
||||
void Restart(Actor* target);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 动画状态
|
||||
/// @brief 动画状态
|
||||
enum class Status
|
||||
{
|
||||
NotStarted, ///< 未开始
|
||||
Delayed, ///< 等待延时
|
||||
Started, ///< 已开始
|
||||
Done, ///< 已结束
|
||||
Removeable ///< 可移除
|
||||
NotStarted, ///< 未开始
|
||||
Delayed, ///< 等待延时
|
||||
Started, ///< 已开始
|
||||
Done, ///< 已结束
|
||||
Removeable ///< 可移除
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画状态
|
||||
/// @brief 获取动画状态
|
||||
Status GetStatus() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取消逝时间
|
||||
/// @brief 获取消逝时间
|
||||
Duration GetElapsed() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取完成的循环次数
|
||||
/// @brief 获取完成的循环次数
|
||||
int GetLoopsDone() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 结束动画
|
||||
/// @brief 结束动画
|
||||
void Done();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否已结束
|
||||
/// @brief 是否已结束
|
||||
bool IsDone() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否可移除
|
||||
/// @brief 是否可移除
|
||||
bool IsRemoveable() const;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -29,21 +29,21 @@ namespace kiwano
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 延时动画
|
||||
/// @brief 延时动画
|
||||
class KGE_API ActionDelay : public Action
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构建延时动画
|
||||
/// @param delay 延时时长
|
||||
/// @brief 构建延时动画
|
||||
/// @param delay 延时时长
|
||||
ActionDelay(Duration delay);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionPtr Reverse() const override;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ KGE_DECLARE_SMART_PTR(ActionGroup);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 动画组合
|
||||
/// @brief 动画组合
|
||||
class KGE_API ActionGroup : public Action
|
||||
{
|
||||
public:
|
||||
|
|
@ -40,33 +40,33 @@ public:
|
|||
ActionGroup();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 动画组合
|
||||
/// @param actions 动画集合
|
||||
/// @param sync 同步执行
|
||||
/// @brief 动画组合
|
||||
/// @param actions 动画集合
|
||||
/// @param sync 同步执行
|
||||
explicit ActionGroup(Vector<ActionPtr> const& actions, bool sync = false);
|
||||
|
||||
virtual ~ActionGroup();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加动画
|
||||
/// @param action 动画
|
||||
/// @brief 添加动画
|
||||
/// @param action 动画
|
||||
void Add(ActionPtr action);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加多个动画
|
||||
/// @param actions 动画集合
|
||||
/// @brief 添加多个动画
|
||||
/// @param actions 动画集合
|
||||
void Add(Vector<ActionPtr> const& actions);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取所有动画
|
||||
/// @brief 获取所有动画
|
||||
ActionList const& GetActions() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionPtr Reverse() const override;
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -33,13 +33,13 @@ namespace kiwano
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 动画辅助类
|
||||
/// @brief 动画辅助类
|
||||
struct ActionHelper
|
||||
{
|
||||
using DoneCallback = Action::DoneCallback;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置循环次数
|
||||
/// @brief 设置循环次数
|
||||
inline ActionHelper& SetLoops(int loops)
|
||||
{
|
||||
core->SetLoops(loops);
|
||||
|
|
@ -47,7 +47,7 @@ struct ActionHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画延迟
|
||||
/// @brief 设置动画延迟
|
||||
inline ActionHelper& SetDelay(Duration delay)
|
||||
{
|
||||
core->SetDelay(delay);
|
||||
|
|
@ -55,7 +55,7 @@ struct ActionHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画结束回调函数
|
||||
/// @brief 设置动画结束回调函数
|
||||
inline ActionHelper& SetDoneCallback(DoneCallback const& cb)
|
||||
{
|
||||
core->SetDoneCallback(cb);
|
||||
|
|
@ -63,7 +63,7 @@ struct ActionHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画循环结束时的回调函数
|
||||
/// @brief 设置动画循环结束时的回调函数
|
||||
inline ActionHelper& SetLoopDoneCallback(DoneCallback const& cb)
|
||||
{
|
||||
core->SetLoopDoneCallback(cb);
|
||||
|
|
@ -71,7 +71,7 @@ struct ActionHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 动画结束时移除目标角色
|
||||
/// @brief 动画结束时移除目标角色
|
||||
inline ActionHelper& RemoveTargetWhenDone()
|
||||
{
|
||||
core->RemoveTargetWhenDone();
|
||||
|
|
@ -79,7 +79,7 @@ struct ActionHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置名称
|
||||
/// @brief 设置名称
|
||||
inline ActionHelper& SetName(String const& name)
|
||||
{
|
||||
core->SetName(name);
|
||||
|
|
@ -87,7 +87,7 @@ struct ActionHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取指针
|
||||
/// @brief 获取指针
|
||||
inline ActionPtr Get() const
|
||||
{
|
||||
return core;
|
||||
|
|
@ -108,13 +108,13 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 补间动画辅助类
|
||||
/// @brief 补间动画辅助类
|
||||
struct TweenHelper
|
||||
{
|
||||
using DoneCallback = Action::DoneCallback;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画持续时长
|
||||
/// @brief 设置动画持续时长
|
||||
inline TweenHelper& SetDuration(Duration dur)
|
||||
{
|
||||
core->SetDuration(dur);
|
||||
|
|
@ -122,7 +122,7 @@ struct TweenHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置循环次数
|
||||
/// @brief 设置循环次数
|
||||
inline TweenHelper& SetLoops(int loops)
|
||||
{
|
||||
core->SetLoops(loops);
|
||||
|
|
@ -130,7 +130,7 @@ struct TweenHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置缓动函数
|
||||
/// @brief 设置缓动函数
|
||||
inline TweenHelper& SetEaseFunc(EaseFunc ease)
|
||||
{
|
||||
core->SetEaseFunc(ease);
|
||||
|
|
@ -138,7 +138,7 @@ struct TweenHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画延迟
|
||||
/// @brief 设置动画延迟
|
||||
inline TweenHelper& SetDelay(Duration delay)
|
||||
{
|
||||
core->SetDelay(delay);
|
||||
|
|
@ -146,7 +146,7 @@ struct TweenHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画结束回调函数
|
||||
/// @brief 设置动画结束回调函数
|
||||
inline TweenHelper& SetDoneCallback(DoneCallback const& cb)
|
||||
{
|
||||
core->SetDoneCallback(cb);
|
||||
|
|
@ -154,7 +154,7 @@ struct TweenHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画循环结束时的回调函数
|
||||
/// @brief 设置动画循环结束时的回调函数
|
||||
inline TweenHelper& SetLoopDoneCallback(DoneCallback const& cb)
|
||||
{
|
||||
core->SetLoopDoneCallback(cb);
|
||||
|
|
@ -162,7 +162,7 @@ struct TweenHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 动画结束时移除目标角色
|
||||
/// @brief 动画结束时移除目标角色
|
||||
inline TweenHelper& RemoveTargetWhenDone()
|
||||
{
|
||||
core->RemoveTargetWhenDone();
|
||||
|
|
@ -170,7 +170,7 @@ struct TweenHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置名称
|
||||
/// @brief 设置名称
|
||||
inline TweenHelper& SetName(String const& name)
|
||||
{
|
||||
core->SetName(name);
|
||||
|
|
@ -178,7 +178,7 @@ struct TweenHelper
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取指针
|
||||
/// @brief 获取指针
|
||||
inline ActionTweenPtr Get() const
|
||||
{
|
||||
return core;
|
||||
|
|
@ -204,120 +204,120 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 动画构造器
|
||||
/// @brief 动画构造器
|
||||
struct Tween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造相对位移动画
|
||||
/// @param duration 动画时长
|
||||
/// @param vector 移动向量
|
||||
/// @brief 构造相对位移动画
|
||||
/// @param duration 动画时长
|
||||
/// @param vector 移动向量
|
||||
static inline TweenHelper MoveBy(Duration dur, Point const& vector)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionMoveBy(dur, vector));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造位移动画
|
||||
/// @param duration 动画时长
|
||||
/// @param pos 目的坐标
|
||||
/// @brief 构造位移动画
|
||||
/// @param duration 动画时长
|
||||
/// @param pos 目的坐标
|
||||
static inline TweenHelper MoveTo(Duration dur, Point const& pos)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionMoveTo(dur, pos));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造相对跳跃动画
|
||||
/// @param duration 动画时长
|
||||
/// @param vec 跳跃位移向量
|
||||
/// @param height 跳跃高度
|
||||
/// @param jumps 跳跃次数
|
||||
/// @brief 构造相对跳跃动画
|
||||
/// @param duration 动画时长
|
||||
/// @param vec 跳跃位移向量
|
||||
/// @param height 跳跃高度
|
||||
/// @param jumps 跳跃次数
|
||||
static inline TweenHelper JumpBy(Duration duration, Vec2 const& vec, float height, int jumps = 1)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionJumpBy(duration, vec, height, jumps));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造跳跃动画
|
||||
/// @param duration 动画时长
|
||||
/// @param pos 目的坐标
|
||||
/// @param height 跳跃高度
|
||||
/// @param jumps 跳跃次数
|
||||
/// @brief 构造跳跃动画
|
||||
/// @param duration 动画时长
|
||||
/// @param pos 目的坐标
|
||||
/// @param height 跳跃高度
|
||||
/// @param jumps 跳跃次数
|
||||
static inline TweenHelper JumpTo(Duration duration, Point const& pos, float height, int jumps = 1)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionJumpTo(duration, pos, height, jumps));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造相对缩放动画
|
||||
/// @param duration 动画时长
|
||||
/// @param scale_x 横向缩放相对变化值
|
||||
/// @param scale_y 纵向缩放相对变化值
|
||||
/// @brief 构造相对缩放动画
|
||||
/// @param duration 动画时长
|
||||
/// @param scale_x 横向缩放相对变化值
|
||||
/// @param scale_y 纵向缩放相对变化值
|
||||
static inline TweenHelper ScaleBy(Duration dur, float scale_x, float scale_y)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionScaleBy(dur, scale_x, scale_y));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造缩放动画
|
||||
/// @param duration 动画时长
|
||||
/// @param scale_x 横向缩放目标值
|
||||
/// @param scale_y 纵向缩放目标值
|
||||
/// @brief 构造缩放动画
|
||||
/// @param duration 动画时长
|
||||
/// @param scale_x 横向缩放目标值
|
||||
/// @param scale_y 纵向缩放目标值
|
||||
static inline TweenHelper ScaleTo(Duration dur, float scale_x, float scale_y)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionScaleTo(dur, scale_x, scale_y));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造透明度渐变动画
|
||||
/// @param duration 动画时长
|
||||
/// @param opacity 目标透明度
|
||||
/// @brief 构造透明度渐变动画
|
||||
/// @param duration 动画时长
|
||||
/// @param opacity 目标透明度
|
||||
static inline TweenHelper FadeTo(Duration dur, float opacity)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionFadeTo(dur, opacity));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造淡入动画
|
||||
/// @param duration 动画时长
|
||||
/// @brief 构造淡入动画
|
||||
/// @param duration 动画时长
|
||||
static inline TweenHelper FadeIn(Duration dur)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionFadeIn(dur));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造淡出动画
|
||||
/// @param duration 动画时长
|
||||
/// @brief 构造淡出动画
|
||||
/// @param duration 动画时长
|
||||
static inline TweenHelper FadeOut(Duration dur)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionFadeOut(dur));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造相对旋转动画
|
||||
/// @param duration 动画时长
|
||||
/// @param rotation 角度相对变化值
|
||||
/// @brief 构造相对旋转动画
|
||||
/// @param duration 动画时长
|
||||
/// @param rotation 角度相对变化值
|
||||
static inline TweenHelper RotateBy(Duration dur, float rotation)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionRotateBy(dur, rotation));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造旋转动画
|
||||
/// @param duration 动画时长
|
||||
/// @param rotation 目标角度
|
||||
/// @brief 构造旋转动画
|
||||
/// @param duration 动画时长
|
||||
/// @param rotation 目标角度
|
||||
static inline TweenHelper RotateTo(Duration dur, float rotation)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionRotateTo(dur, rotation));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造路径行走动画
|
||||
/// @param duration 持续时长
|
||||
/// @param path 路径形状
|
||||
/// @param rotating 是否沿路径切线方向旋转
|
||||
/// @param start 路径起点(百分比)
|
||||
/// @param end 路径终点(百分比)
|
||||
/// @brief 构造路径行走动画
|
||||
/// @param duration 持续时长
|
||||
/// @param path 路径形状
|
||||
/// @param rotating 是否沿路径切线方向旋转
|
||||
/// @param start 路径起点(百分比)
|
||||
/// @param end 路径终点(百分比)
|
||||
static inline TweenHelper Walk(Duration duration, ShapePtr path, bool rotating = false, float start = 0.f,
|
||||
float end = 1.f)
|
||||
{
|
||||
|
|
@ -325,35 +325,35 @@ public:
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构建帧动画
|
||||
/// @param duration 动画时长
|
||||
/// @param[in] frame_seq 序列帧
|
||||
/// @brief 构建帧动画
|
||||
/// @param duration 动画时长
|
||||
/// @param[in] frame_seq 序列帧
|
||||
static inline TweenHelper Animation(Duration dur, FrameSequencePtr frames)
|
||||
{
|
||||
return TweenHelper(new kiwano::Animation(dur, frames));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造自定义动画
|
||||
/// @param duration 动画时长
|
||||
/// @param tween_func 动画回调函数
|
||||
/// @brief 构造自定义动画
|
||||
/// @param duration 动画时长
|
||||
/// @param tween_func 动画回调函数
|
||||
static inline TweenHelper Custom(Duration dur, ActionCustom::TweenFunc tween_func)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionCustom(dur, tween_func));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构建延时动画
|
||||
/// @param delay 延时时长
|
||||
/// @brief 构建延时动画
|
||||
/// @param delay 延时时长
|
||||
static inline ActionHelper Delay(Duration delay)
|
||||
{
|
||||
return ActionHelper(new kiwano::ActionDelay(delay));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 动画组合
|
||||
/// @param actions 动画集合
|
||||
/// @param sync 同步执行
|
||||
/// @brief 动画组合
|
||||
/// @param actions 动画集合
|
||||
/// @param sync 同步执行
|
||||
static inline ActionHelper Group(Vector<ActionPtr> const& actions, bool sync = false)
|
||||
{
|
||||
return ActionHelper(new kiwano::ActionGroup(actions, sync));
|
||||
|
|
|
|||
|
|
@ -30,47 +30,47 @@ namespace kiwano
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 动画管理器
|
||||
* @brief 动画管理器
|
||||
*/
|
||||
class KGE_API ActionManager
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 动画列表
|
||||
/// @brief 动画列表
|
||||
using Actions = IntrusiveList<ActionPtr>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加动画
|
||||
/// @brief 添加动画
|
||||
Action* AddAction(ActionPtr action);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加动画
|
||||
/// @brief 添加动画
|
||||
Action* AddAction(Action* action);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 继续所有暂停动画
|
||||
/// @brief 继续所有暂停动画
|
||||
void ResumeAllActions();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 暂停所有动画
|
||||
/// @brief 暂停所有动画
|
||||
void PauseAllActions();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 停止所有动画
|
||||
/// @brief 停止所有动画
|
||||
void StopAllActions();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取指定名称的动画
|
||||
/// @param name 动画名称
|
||||
/// @brief 获取指定名称的动画
|
||||
/// @param name 动画名称
|
||||
ActionPtr GetAction(String const& name);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取所有动画
|
||||
/// @brief 获取所有动画
|
||||
Actions const& GetAllActions() const;
|
||||
|
||||
protected:
|
||||
/// \~chinese
|
||||
/// @brief 更新动画
|
||||
/// @brief 更新动画
|
||||
void UpdateActions(Actor* target, Duration dt);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -25,27 +25,27 @@
|
|||
namespace kiwano
|
||||
{
|
||||
/// \~chinese
|
||||
/// @brief 缓动函数
|
||||
/// @brief 缓动函数
|
||||
using EaseFunc = Function<float(float)>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 缓动函数枚举
|
||||
/// @details 查看 https://easings.net 获取更多信息
|
||||
/// @brief 缓动函数枚举
|
||||
/// @details 查看 https://easings.net 获取更多信息
|
||||
struct Ease
|
||||
{
|
||||
static KGE_API EaseFunc Linear; ///< 线性
|
||||
static KGE_API EaseFunc EaseIn; ///< 由慢变快
|
||||
static KGE_API EaseFunc EaseOut; ///< 由快变慢
|
||||
static KGE_API EaseFunc EaseInOut; ///< 由慢变快, 再由快变慢
|
||||
static KGE_API EaseFunc ExpoIn; ///< 由慢变极快
|
||||
static KGE_API EaseFunc ExpoOut; ///< 由极快变慢
|
||||
static KGE_API EaseFunc ExpoInOut; ///< 由慢至极快, 再由极快边慢
|
||||
static KGE_API EaseFunc ElasticIn; ///< 自起点赋予弹性
|
||||
static KGE_API EaseFunc ElasticOut; ///< 自终点赋予弹性
|
||||
static KGE_API EaseFunc ElasticInOut; ///< 再起点和终点赋予弹性
|
||||
static KGE_API EaseFunc BounceIn; ///< 自起点赋予反弹力
|
||||
static KGE_API EaseFunc BounceOut; ///< 自终点赋予反弹力
|
||||
static KGE_API EaseFunc BounceInOut; ///< 在起点和终点赋予反弹力
|
||||
static KGE_API EaseFunc Linear; ///< 线性
|
||||
static KGE_API EaseFunc EaseIn; ///< 由慢变快
|
||||
static KGE_API EaseFunc EaseOut; ///< 由快变慢
|
||||
static KGE_API EaseFunc EaseInOut; ///< 由慢变快, 再由快变慢
|
||||
static KGE_API EaseFunc ExpoIn; ///< 由慢变极快
|
||||
static KGE_API EaseFunc ExpoOut; ///< 由极快变慢
|
||||
static KGE_API EaseFunc ExpoInOut; ///< 由慢至极快, 再由极快边慢
|
||||
static KGE_API EaseFunc ElasticIn; ///< 自起点赋予弹性
|
||||
static KGE_API EaseFunc ElasticOut; ///< 自终点赋予弹性
|
||||
static KGE_API EaseFunc ElasticInOut; ///< 再起点和终点赋予弹性
|
||||
static KGE_API EaseFunc BounceIn; ///< 自起点赋予反弹力
|
||||
static KGE_API EaseFunc BounceOut; ///< 自终点赋予反弹力
|
||||
static KGE_API EaseFunc BounceInOut; ///< 在起点和终点赋予反弹力
|
||||
static KGE_API EaseFunc BackIn;
|
||||
static KGE_API EaseFunc BackOut;
|
||||
static KGE_API EaseFunc BackInOut;
|
||||
|
|
@ -86,32 +86,32 @@ KGE_DECLARE_SMART_PTR(ActionCustom);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 补间动画
|
||||
/// @brief 补间动画
|
||||
class KGE_API ActionTween : public Action
|
||||
{
|
||||
public:
|
||||
ActionTween();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 补间动画
|
||||
/// @param duration 动画时长
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 补间动画
|
||||
/// @param duration 动画时长
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionTween(Duration duration, EaseFunc func);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画时长
|
||||
/// @brief 获取动画时长
|
||||
Duration GetDuration() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画时长
|
||||
/// @brief 设置动画时长
|
||||
void SetDuration(Duration duration);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画速度缓动函数
|
||||
/// @brief 获取动画速度缓动函数
|
||||
EaseFunc const& GetEaseFunc() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画速度缓动函数
|
||||
/// @brief 设置动画速度缓动函数
|
||||
void SetEaseFunc(EaseFunc const& func);
|
||||
|
||||
protected:
|
||||
|
|
@ -125,23 +125,23 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 相对位移动画
|
||||
/// @brief 相对位移动画
|
||||
class KGE_API ActionMoveBy : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造相对位移动画
|
||||
/// @param duration 动画时长
|
||||
/// @param vector 移动向量
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造相对位移动画
|
||||
/// @param duration 动画时长
|
||||
/// @param vector 移动向量
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionMoveBy(Duration duration, Vec2 const& vector, EaseFunc func = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionPtr Reverse() const override;
|
||||
|
||||
protected:
|
||||
|
|
@ -156,26 +156,26 @@ protected:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 位移动画
|
||||
/// @brief 位移动画
|
||||
class KGE_API ActionMoveTo : public ActionMoveBy
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造位移动画
|
||||
/// @param duration 动画时长
|
||||
/// @param pos 目的坐标
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造位移动画
|
||||
/// @param duration 动画时长
|
||||
/// @param pos 目的坐标
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionMoveTo(Duration duration, Point const& pos, EaseFunc func = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
virtual ActionPtr Reverse() const override
|
||||
{
|
||||
KGE_ERROR(L"Reverse() not supported in ActionMoveTo");
|
||||
KGE_ERROR("Reverse() not supported in ActionMoveTo");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -187,25 +187,25 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 相对跳跃动画
|
||||
/// @brief 相对跳跃动画
|
||||
class KGE_API ActionJumpBy : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造相对跳跃动画
|
||||
/// @param duration 动画时长
|
||||
/// @param vec 跳跃位移向量
|
||||
/// @param height 跳跃高度
|
||||
/// @param jumps 跳跃次数
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造相对跳跃动画
|
||||
/// @param duration 动画时长
|
||||
/// @param vec 跳跃位移向量
|
||||
/// @param height 跳跃高度
|
||||
/// @param jumps 跳跃次数
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionJumpBy(Duration duration, Vec2 const& vec, float height, int jumps = 1, EaseFunc func = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionPtr Reverse() const override;
|
||||
|
||||
protected:
|
||||
|
|
@ -222,28 +222,28 @@ protected:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 跳跃动画
|
||||
/// @brief 跳跃动画
|
||||
class KGE_API ActionJumpTo : public ActionJumpBy
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造跳跃动画
|
||||
/// @param duration 动画时长
|
||||
/// @param pos 目的坐标
|
||||
/// @param height 跳跃高度
|
||||
/// @param jumps 跳跃次数
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造跳跃动画
|
||||
/// @param duration 动画时长
|
||||
/// @param pos 目的坐标
|
||||
/// @param height 跳跃高度
|
||||
/// @param jumps 跳跃次数
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionJumpTo(Duration duration, Point const& pos, float height, int jumps = 1, EaseFunc func = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
virtual ActionPtr Reverse() const override
|
||||
{
|
||||
KGE_ERROR(L"Reverse() not supported in ActionJumpTo");
|
||||
KGE_ERROR("Reverse() not supported in ActionJumpTo");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -255,24 +255,24 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 相对缩放动画
|
||||
/// @brief 相对缩放动画
|
||||
class KGE_API ActionScaleBy : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造相对缩放动画
|
||||
/// @param duration 动画时长
|
||||
/// @param scale_x 横向缩放相对变化值
|
||||
/// @param scale_y 纵向缩放相对变化值
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造相对缩放动画
|
||||
/// @param duration 动画时长
|
||||
/// @param scale_x 横向缩放相对变化值
|
||||
/// @param scale_y 纵向缩放相对变化值
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionScaleBy(Duration duration, float scale_x, float scale_y, EaseFunc func = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionPtr Reverse() const override;
|
||||
|
||||
protected:
|
||||
|
|
@ -288,27 +288,27 @@ protected:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 缩放动画
|
||||
/// @brief 缩放动画
|
||||
class KGE_API ActionScaleTo : public ActionScaleBy
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造缩放动画
|
||||
/// @param duration 动画时长
|
||||
/// @param scale_x 横向缩放目标值
|
||||
/// @param scale_y 纵向缩放目标值
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造缩放动画
|
||||
/// @param duration 动画时长
|
||||
/// @param scale_x 横向缩放目标值
|
||||
/// @param scale_y 纵向缩放目标值
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionScaleTo(Duration duration, float scale_x, float scale_y, EaseFunc func = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
virtual ActionPtr Reverse() const override
|
||||
{
|
||||
KGE_ERROR(L"Reverse() not supported in ActionScaleTo");
|
||||
KGE_ERROR("Reverse() not supported in ActionScaleTo");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -321,26 +321,26 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 透明度渐变动画
|
||||
/// @brief 透明度渐变动画
|
||||
class KGE_API ActionFadeTo : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造透明度渐变动画
|
||||
/// @param duration 动画时长
|
||||
/// @param opacity 目标透明度
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造透明度渐变动画
|
||||
/// @param duration 动画时长
|
||||
/// @param opacity 目标透明度
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionFadeTo(Duration duration, float opacity, EaseFunc func = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
virtual ActionPtr Reverse() const override
|
||||
{
|
||||
KGE_ERROR(L"Reverse() not supported in ActionFadeTo");
|
||||
KGE_ERROR("Reverse() not supported in ActionFadeTo");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -356,47 +356,47 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 淡入动画
|
||||
/// @brief 淡入动画
|
||||
class KGE_API ActionFadeIn : public ActionFadeTo
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造淡入动画
|
||||
/// @param duration 动画时长
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造淡入动画
|
||||
/// @param duration 动画时长
|
||||
/// @param func 动画速度缓动函数
|
||||
explicit ActionFadeIn(Duration duration, EaseFunc func = nullptr);
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 淡出动画
|
||||
/// @brief 淡出动画
|
||||
class KGE_API ActionFadeOut : public ActionFadeTo
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造淡出动画
|
||||
/// @param duration 动画时长
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造淡出动画
|
||||
/// @param duration 动画时长
|
||||
/// @param func 动画速度缓动函数
|
||||
explicit ActionFadeOut(Duration duration, EaseFunc func = nullptr);
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 相对旋转动画
|
||||
/// @brief 相对旋转动画
|
||||
class KGE_API ActionRotateBy : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造相对旋转动画
|
||||
/// @param duration 动画时长
|
||||
/// @param rotation 角度相对变化值
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造相对旋转动画
|
||||
/// @param duration 动画时长
|
||||
/// @param rotation 角度相对变化值
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionRotateBy(Duration duration, float rotation, EaseFunc func = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionPtr Reverse() const override;
|
||||
|
||||
protected:
|
||||
|
|
@ -410,26 +410,26 @@ protected:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 旋转动画
|
||||
/// @brief 旋转动画
|
||||
class KGE_API ActionRotateTo : public ActionRotateBy
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造旋转动画
|
||||
/// @param duration 动画时长
|
||||
/// @param rotation 目标角度
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造旋转动画
|
||||
/// @param duration 动画时长
|
||||
/// @param rotation 目标角度
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionRotateTo(Duration duration, float rotation, EaseFunc func = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
virtual ActionPtr Reverse() const override
|
||||
{
|
||||
KGE_ERROR(L"Reverse() not supported in ActionRotateTo");
|
||||
KGE_ERROR("Reverse() not supported in ActionRotateTo");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -441,31 +441,31 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 自定义动画
|
||||
/// @brief 自定义动画
|
||||
class KGE_API ActionCustom : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 动画回调函数
|
||||
/// @details 在动画更新时回调该函数,第一个参数是执行动画的目标,第二个参数是动画进度(0.0 - 1.0)
|
||||
/// @brief 动画回调函数
|
||||
/// @details 在动画更新时回调该函数,第一个参数是执行动画的目标,第二个参数是动画进度(0.0 - 1.0)
|
||||
using TweenFunc = Function<void(Actor* /* target */, float /* percent */)>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造自定义动画
|
||||
/// @param duration 动画时长
|
||||
/// @param tween_func 动画回调函数
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造自定义动画
|
||||
/// @param duration 动画时长
|
||||
/// @param tween_func 动画回调函数
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionCustom(Duration duration, TweenFunc tween_func, EaseFunc func = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionPtr Reverse() const override
|
||||
{
|
||||
KGE_ERROR(L"Reverse() not supported in ActionCustom");
|
||||
KGE_ERROR("Reverse() not supported in ActionCustom");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,44 +33,44 @@ KGE_DECLARE_SMART_PTR(ActionWalk);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 路径行走动画
|
||||
/// @brief 路径行走动画
|
||||
class KGE_API ActionWalk : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造路径行走动画
|
||||
/// @param duration 持续时长
|
||||
/// @param rotating 是否沿路径切线方向旋转
|
||||
/// @param start 路径起点(百分比)
|
||||
/// @param end 路径终点(百分比)
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造路径行走动画
|
||||
/// @param duration 持续时长
|
||||
/// @param rotating 是否沿路径切线方向旋转
|
||||
/// @param start 路径起点(百分比)
|
||||
/// @param end 路径终点(百分比)
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionWalk(Duration duration, bool rotating = false, float start = 0.f, float end = 1.f, EaseFunc func = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造路径行走动画
|
||||
/// @param duration 持续时长
|
||||
/// @param path 路径形状
|
||||
/// @param rotating 是否沿路径切线方向旋转
|
||||
/// @param start 路径起点(百分比)
|
||||
/// @param end 路径终点(百分比)
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构造路径行走动画
|
||||
/// @param duration 持续时长
|
||||
/// @param path 路径形状
|
||||
/// @param rotating 是否沿路径切线方向旋转
|
||||
/// @param start 路径起点(百分比)
|
||||
/// @param end 路径终点(百分比)
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionWalk(Duration duration, ShapePtr path, bool rotating = false, float start = 0.f, float end = 1.f,
|
||||
EaseFunc func = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionPtr Reverse() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取路线
|
||||
/// @brief 获取路线
|
||||
ShapePtr const& GetPath() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置路径形状
|
||||
/// @brief 设置路径形状
|
||||
void SetPath(ShapePtr path);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -32,36 +32,36 @@ KGE_DECLARE_SMART_PTR(Animation);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 帧动画
|
||||
/// @brief 帧动画
|
||||
class KGE_API Animation : public ActionTween
|
||||
{
|
||||
public:
|
||||
Animation();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构建帧动画
|
||||
/// @param duration 动画时长
|
||||
/// @param[in] frame_seq 序列帧
|
||||
/// @param func 动画速度缓动函数
|
||||
/// @brief 构建帧动画
|
||||
/// @param duration 动画时长
|
||||
/// @param[in] frame_seq 序列帧
|
||||
/// @param func 动画速度缓动函数
|
||||
Animation(Duration duration, FrameSequencePtr frame_seq, EaseFunc func = nullptr);
|
||||
|
||||
virtual ~Animation();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取序列帧
|
||||
/// @brief 获取序列帧
|
||||
FrameSequencePtr GetFrameSequence() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置序列帧
|
||||
/// @param[in] frame_seq 序列帧
|
||||
/// @brief 设置序列帧
|
||||
/// @param[in] frame_seq 序列帧
|
||||
void SetFrameSequence(FrameSequencePtr frame_seq);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionPtr Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionPtr Reverse() const override;
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@
|
|||
//#define KGE_ASSERT(EXPR) __noop // Disable asserts
|
||||
|
||||
//---- Define debug-output handler. Defaults to calling kiwano::logs::Messageln()/Warningln()/Errorln()
|
||||
//#define KGE_SYS_LOG(FORMAT, ...) wprintf(FORMAT L"\n", __VA_ARGS__)
|
||||
//#define KGE_WARN(FORMAT, ...) wprintf(FORMAT L"\n", __VA_ARGS__)
|
||||
//#define KGE_ERROR(FORMAT, ...) wprintf(FORMAT L"\n", __VA_ARGS__)
|
||||
//#define KGE_SYS_LOG(FORMAT, ...) wprintf(FORMAT "\n", __VA_ARGS__)
|
||||
//#define KGE_WARN(FORMAT, ...) wprintf(FORMAT "\n", __VA_ARGS__)
|
||||
//#define KGE_ERROR(FORMAT, ...) wprintf(FORMAT "\n", __VA_ARGS__)
|
||||
|
||||
//---- Define attributes of all API symbols declarations for DLL
|
||||
//#define KGE_USE_DLL
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ typedef Function<void()> AsyncTaskFunc;
|
|||
typedef Function<void()> AsyncTaskCallback;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 异步任务
|
||||
/// @details 在多线程下执行任务并返回
|
||||
/// @brief 异步任务
|
||||
/// @details 在多线程下执行任务并返回
|
||||
/// @code
|
||||
/// AsyncTaskPtr task = new AsyncTask;
|
||||
/// task->Then(DoSomething);
|
||||
|
|
@ -42,27 +42,27 @@ class AsyncTask : public virtual ObjectBase
|
|||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建异步任务
|
||||
/// @param func 异步回调函数
|
||||
/// @brief 创建异步任务
|
||||
/// @param func 异步回调函数
|
||||
static AsyncTaskPtr Create(AsyncTaskFunc func);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造异步任务
|
||||
/// @brief 构造异步任务
|
||||
AsyncTask();
|
||||
|
||||
virtual ~AsyncTask();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加异步任务链
|
||||
/// @brief 添加异步任务链
|
||||
AsyncTask& Then(AsyncTaskFunc func);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置任务执行完成后的回调函数
|
||||
/// @note 该函数在 Kiwano 主线程中执行
|
||||
/// @brief 设置任务执行完成后的回调函数
|
||||
/// @note 该函数在 Kiwano 主线程中执行
|
||||
AsyncTask& SetCallback(AsyncTaskCallback callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 启动异步任务
|
||||
/// @brief 启动异步任务
|
||||
void Start();
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -19,125 +19,126 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <3rd-party/OuterC/oc/oc.h>
|
||||
#include <kiwano/core/Singleton.h>
|
||||
#include <kiwano/macros.h>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <kiwano/macros.h>
|
||||
#include <kiwano/core/Singleton.h>
|
||||
#include <3rd-party/OuterC/oc/oc.h>
|
||||
#include <3rd-party/nlohmann/json.hpp>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
/// \~chinese
|
||||
/// @brief 字符串容器
|
||||
using String = oc::wstring;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 窄字符串容器
|
||||
using ByteString = oc::string;
|
||||
/// @brief 输入流
|
||||
using InputStream = std::istream;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 字符串流
|
||||
using StringStream = std::wstringstream;
|
||||
/// @brief 输出流
|
||||
using OutputStream = std::ostream;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 线性数组容器
|
||||
/// @brief 字符串容器
|
||||
using String = oc::string;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 宽字符串容器
|
||||
using WideString = oc::wstring;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 字符串流
|
||||
using StringStream = std::stringstream;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 宽字符串流
|
||||
using WideStringStream = std::wstringstream;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 线性数组容器
|
||||
template <typename _Ty, typename... _Args>
|
||||
using Vector = oc::vector<_Ty, _Args...>;
|
||||
using Vector = std::vector<_Ty, _Args...>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 链表容器
|
||||
/// @brief 链表容器
|
||||
template <typename _Ty, typename... _Args>
|
||||
using List = std::list<_Ty, _Args...>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 队列容器
|
||||
/// @brief 队列容器
|
||||
template <typename _Ty, typename... _Args>
|
||||
using Queue = std::queue<_Ty, _Args...>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 集合容器
|
||||
/// @brief 集合容器
|
||||
template <typename _Ty, typename... _Args>
|
||||
using Set = std::set<_Ty, _Args...>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 对容器
|
||||
/// @brief 对容器
|
||||
template <typename _Ty1, typename _Ty2>
|
||||
using Pair = std::pair<_Ty1, _Ty2>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 无序集合容器
|
||||
/// @brief 无序集合容器
|
||||
template <typename _Ty, typename... _Args>
|
||||
using UnorderedSet = std::unordered_set<_Ty, _Args...>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 栈容器
|
||||
/// @brief 栈容器
|
||||
template <typename _Ty, typename... _Args>
|
||||
using Stack = std::stack<_Ty, _Args...>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 字符串容器
|
||||
/// @brief 字符串容器
|
||||
template <typename _Kty, typename _Ty, typename... _Args>
|
||||
using Map = std::map<_Kty, _Ty, _Args...>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 字符串容器
|
||||
/// @brief 字符串容器
|
||||
template <typename _Kty, typename _Ty, typename... _Args>
|
||||
using UnorderedMap = std::unordered_map<_Kty, _Ty, _Args...>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 函数封装器
|
||||
/// @par
|
||||
/// 使用函数封装器可以储存、复制和调用任何可调用目标,示例代码如下:
|
||||
/// @code
|
||||
/// Function<bool(int)> func1 = StaticFunc; // bool
|
||||
/// StaticFunc(int x);
|
||||
/// Function<bool(int)> func2 = Closure(&t, &T::Func); // bool
|
||||
/// T::Func(int x);
|
||||
/// Function<bool(int)> func3 = T::StaticFunc; // static bool
|
||||
/// T::StaticFunc(int x);
|
||||
/// Function<bool(int)> func4 = [](int x) -> bool {}; // Lambda function
|
||||
/// Function<bool(int)> func5 = std::bind(&T::Func, &t); // std::bind
|
||||
/// Function<bool(int)> func5 = Callable(); // Callable
|
||||
/// objects: struct Callable { bool operator()(int x) {} };
|
||||
/// @endcode
|
||||
/// @brief 函数封装器
|
||||
template <typename _FuncTy>
|
||||
using Function = oc::function<_FuncTy>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 单值容器
|
||||
/// @brief 单值容器
|
||||
using Any = oc::any;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief JSON对象容器
|
||||
using Json = oc::basic_json<Map, Vector, String, int, double, bool, std::allocator>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 侵入式链表容器
|
||||
/// @brief 侵入式链表容器
|
||||
template <typename _Ty>
|
||||
using IntrusiveList = oc::intrusive_list<_Ty>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 侵入式链表元素
|
||||
/// @brief 侵入式链表元素
|
||||
template <typename _Ty>
|
||||
using IntrusiveListItem = oc::intrusive_list_item<_Ty>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 侵入式智能指针
|
||||
/// @brief 侵入式智能指针
|
||||
template <typename _Ty, typename _RefProxyTy>
|
||||
using IntrusivePtr = oc::intrusive_ptr<_Ty, _RefProxyTy>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 不可拷贝对象
|
||||
/// @brief JSON对象容器
|
||||
using Json = nlohmann::basic_json<Map, Vector, String>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 不可拷贝对象
|
||||
using Noncopyable = oc::noncopyable;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 闭包函数
|
||||
/// @brief 闭包函数
|
||||
template <typename _Ty, typename _Uty, typename _Ret, typename... _Args>
|
||||
inline Function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret (_Ty::*func)(_Args...))
|
||||
{
|
||||
|
|
@ -145,20 +146,43 @@ inline Function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret (_Ty::*func)(_Args...))
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 闭包函数
|
||||
/// @brief 闭包函数
|
||||
template <typename _Ty, typename _Uty, typename _Ret, typename... _Args>
|
||||
inline Function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret (_Ty::*func)(_Args...) const)
|
||||
{
|
||||
return oc::closure(ptr, func);
|
||||
}
|
||||
|
||||
inline ByteString WideToMultiByte(const String& str)
|
||||
#if defined(KGE_WIN32)
|
||||
|
||||
inline String WideToMultiByte(const WideString& str)
|
||||
{
|
||||
return oc::wide_to_string(str);
|
||||
int chars_num = ::WideCharToMultiByte(CP_UTF8, 0, str.c_str(), -1, NULL, 0, NULL, NULL);
|
||||
if (chars_num)
|
||||
{
|
||||
String result;
|
||||
result.resize(chars_num);
|
||||
|
||||
::WideCharToMultiByte(CP_UTF8, 0, str.c_str(), -1, &result[0], chars_num, NULL, NULL);
|
||||
return result;
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
inline String MultiByteToWide(const ByteString& str)
|
||||
inline WideString MultiByteToWide(const String& str)
|
||||
{
|
||||
return oc::string_to_wide(str);
|
||||
int wchars_num = ::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0);
|
||||
if (wchars_num)
|
||||
{
|
||||
WideString result;
|
||||
result.resize(wchars_num);
|
||||
|
||||
::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &result[0], wchars_num);
|
||||
return result;
|
||||
}
|
||||
return WideString();
|
||||
}
|
||||
|
||||
#endif // KGE_WIN32
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -29,17 +29,17 @@ class Event;
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 基础功能组件
|
||||
* @brief 基础功能组件
|
||||
*/
|
||||
class KGE_API ComponentBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 启动组件
|
||||
/// @brief 启动组件
|
||||
virtual void SetupComponent() = 0;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 销毁组件
|
||||
/// @brief 销毁组件
|
||||
virtual void DestroyComponent() = 0;
|
||||
|
||||
bool Check(const int flag);
|
||||
|
|
@ -53,22 +53,22 @@ protected:
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 渲染支持组件
|
||||
* @brief 渲染支持组件
|
||||
*/
|
||||
class KGE_API RenderComponent : public virtual ComponentBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 渲染前
|
||||
/// @brief 渲染前
|
||||
virtual void BeforeRender() {}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 渲染时
|
||||
/// @param ctx 渲染上下文
|
||||
/// @brief 渲染时
|
||||
/// @param ctx 渲染上下文
|
||||
virtual void OnRender(RenderContext& ctx) {}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 渲染后
|
||||
/// @brief 渲染后
|
||||
virtual void AfterRender() {}
|
||||
|
||||
public:
|
||||
|
|
@ -79,22 +79,22 @@ public:
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 更新支持组件
|
||||
* @brief 更新支持组件
|
||||
*/
|
||||
class KGE_API UpdateComponent : public virtual ComponentBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 更新前
|
||||
/// @brief 更新前
|
||||
virtual void BeforeUpdate() {}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 更新时
|
||||
/// @param dt 间隔时间
|
||||
/// @brief 更新时
|
||||
/// @param dt 间隔时间
|
||||
virtual void OnUpdate(Duration dt) {}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 更新后
|
||||
/// @brief 更新后
|
||||
virtual void AfterUpdate() {}
|
||||
|
||||
public:
|
||||
|
|
@ -105,14 +105,14 @@ public:
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 事件支持组件
|
||||
* @brief 事件支持组件
|
||||
*/
|
||||
class KGE_API EventComponent : public virtual ComponentBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 事件处理
|
||||
/// @param evt 事件
|
||||
/// @brief 事件处理
|
||||
/// @param evt 事件
|
||||
virtual void HandleEvent(Event* evt) {}
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ namespace kiwano
|
|||
{
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 导演
|
||||
* @details 导演完成舞台的渲染、更新、事件分发以及控制舞台间跳转
|
||||
* @brief 导演
|
||||
* @details 导演完成舞台的渲染、更新、事件分发以及控制舞台间跳转
|
||||
* @see kiwano::Stage
|
||||
*/
|
||||
class KGE_API Director
|
||||
|
|
@ -43,51 +43,51 @@ class KGE_API Director
|
|||
public:
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 切换舞台
|
||||
* @param[in] stage 舞台
|
||||
* @param[in] transition 过渡动画
|
||||
* @brief 切换舞台
|
||||
* @param[in] stage 舞台
|
||||
* @param[in] transition 过渡动画
|
||||
*/
|
||||
void EnterStage(StagePtr stage, TransitionPtr transition = nullptr);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 切换舞台,并将当前舞台储存到栈中
|
||||
* @param[in] stage 舞台
|
||||
* @param[in] transition 过渡动画
|
||||
* @brief 切换舞台,并将当前舞台储存到栈中
|
||||
* @param[in] stage 舞台
|
||||
* @param[in] transition 过渡动画
|
||||
*/
|
||||
void PushStage(StagePtr stage, TransitionPtr transition = nullptr);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 退出当前舞台,并切换到上一个舞台
|
||||
* @param[in] transition 过渡动画
|
||||
* @brief 退出当前舞台,并切换到上一个舞台
|
||||
* @param[in] transition 过渡动画
|
||||
*/
|
||||
void PopStage(TransitionPtr transition = nullptr);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 获取当前舞台
|
||||
* @return 返回当前舞台的指针
|
||||
* @brief 获取当前舞台
|
||||
* @return 返回当前舞台的指针
|
||||
*/
|
||||
StagePtr GetCurrentStage();
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 启用或禁用角色边界渲染功能
|
||||
* @param enabled 是否启用
|
||||
* @brief 启用或禁用角色边界渲染功能
|
||||
* @param enabled 是否启用
|
||||
*/
|
||||
void SetRenderBorderEnabled(bool enabled);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 显示或隐藏调试信息
|
||||
* @param show 是否显示
|
||||
* @brief 显示或隐藏调试信息
|
||||
* @param show 是否显示
|
||||
*/
|
||||
void ShowDebugInfo(bool show = true);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 退出当前舞台并清空舞台栈
|
||||
* @brief 退出当前舞台并清空舞台栈
|
||||
*/
|
||||
void ClearStages();
|
||||
|
||||
|
|
|
|||
|
|
@ -25,40 +25,40 @@ namespace kiwano
|
|||
{
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 事件分发系统
|
||||
* @brief 事件分发系统
|
||||
*/
|
||||
class KGE_API EventDispatcher
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 监听器列表
|
||||
/// @brief 监听器列表
|
||||
using Listeners = IntrusiveList<EventListenerPtr>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加监听器
|
||||
/// @brief 添加监听器
|
||||
EventListener* AddListener(EventListenerPtr listener);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加监听器
|
||||
/// @brief 添加监听器
|
||||
EventListener* AddListener(EventListener* listener);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加监听器
|
||||
/// @param type 监听的事件类型
|
||||
/// @param callback 回调函数
|
||||
/// @brief 添加监听器
|
||||
/// @param type 监听的事件类型
|
||||
/// @param callback 回调函数
|
||||
EventListener* AddListener(EventType type, EventListener::Callback callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加监听器
|
||||
/// @param name 监听器名称
|
||||
/// @param type 监听的事件类型
|
||||
/// @param callback 回调函数
|
||||
/// @brief 添加监听器
|
||||
/// @param name 监听器名称
|
||||
/// @param type 监听的事件类型
|
||||
/// @param callback 回调函数
|
||||
EventListener* AddListener(String const& name, EventType type, EventListener::Callback callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加监听器
|
||||
/// @tparam _EventTy 事件类型
|
||||
/// @param callback 回调函数
|
||||
/// @brief 添加监听器
|
||||
/// @tparam _EventTy 事件类型
|
||||
/// @param callback 回调函数
|
||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
||||
EventListener* AddListener(EventListener::Callback callback)
|
||||
{
|
||||
|
|
@ -66,10 +66,10 @@ public:
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加监听器
|
||||
/// @tparam _EventTy 事件类型
|
||||
/// @param name 监听器名称
|
||||
/// @param callback 回调函数
|
||||
/// @brief 添加监听器
|
||||
/// @tparam _EventTy 事件类型
|
||||
/// @param name 监听器名称
|
||||
/// @param callback 回调函数
|
||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>>
|
||||
EventListener* AddListener(String const& name, EventListener::Callback callback)
|
||||
{
|
||||
|
|
@ -77,55 +77,55 @@ public:
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 启动监听器
|
||||
/// @param name 监听器名称
|
||||
/// @brief 启动监听器
|
||||
/// @param name 监听器名称
|
||||
void StartListeners(String const& name);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 停止监听器
|
||||
/// @param name 监听器名称
|
||||
/// @brief 停止监听器
|
||||
/// @param name 监听器名称
|
||||
void StopListeners(String const& name);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除监听器
|
||||
/// @param name 监听器名称
|
||||
/// @brief 移除监听器
|
||||
/// @param name 监听器名称
|
||||
void RemoveListeners(String const& name);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 启动监听器
|
||||
/// @param type 监听的事件类型
|
||||
/// @brief 启动监听器
|
||||
/// @param type 监听的事件类型
|
||||
void StartListeners(const EventType& type);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 停止监听器
|
||||
/// @param type 监听的事件类型
|
||||
/// @brief 停止监听器
|
||||
/// @param type 监听的事件类型
|
||||
void StopListeners(const EventType& type);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除监听器
|
||||
/// @param type 监听的事件类型
|
||||
/// @brief 移除监听器
|
||||
/// @param type 监听的事件类型
|
||||
void RemoveListeners(const EventType& type);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 启动所有监听器
|
||||
/// @brief 启动所有监听器
|
||||
void StartAllListeners();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 停止所有监听器
|
||||
/// @brief 停止所有监听器
|
||||
void StopAllListeners();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除所有监听器
|
||||
/// @brief 移除所有监听器
|
||||
void RemoveAllListeners();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取所有监听器
|
||||
/// @brief 获取所有监听器
|
||||
const Listeners& GetAllListeners() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 分发事件
|
||||
/// @param evt 事件
|
||||
/// @return 是否继续分发该事件
|
||||
/// @brief 分发事件
|
||||
/// @param evt 事件
|
||||
/// @return 是否继续分发该事件
|
||||
bool DispatchEvent(Event* evt);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ KGE_DECLARE_SMART_PTR(EventListener);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 事件监听器
|
||||
* @brief 事件监听器
|
||||
*/
|
||||
class KGE_API EventListener
|
||||
: public virtual ObjectBase
|
||||
|
|
@ -46,26 +46,26 @@ class KGE_API EventListener
|
|||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 监听器回调函数
|
||||
/// @brief 监听器回调函数
|
||||
using Callback = Function<void(Event*)>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建监听器
|
||||
/// @param type 监听的事件类型
|
||||
/// @param callback 回调函数
|
||||
/// @brief 创建监听器
|
||||
/// @param type 监听的事件类型
|
||||
/// @param callback 回调函数
|
||||
static EventListenerPtr Create(EventType type, Callback const& callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建监听器
|
||||
/// @param name 监听器名称
|
||||
/// @param type 监听的事件类型
|
||||
/// @param callback 回调函数
|
||||
/// @brief 创建监听器
|
||||
/// @param name 监听器名称
|
||||
/// @param type 监听的事件类型
|
||||
/// @param callback 回调函数
|
||||
static EventListenerPtr Create(String const& name, EventType type, Callback const& callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建监听器
|
||||
/// @tparam _EventTy 事件类型
|
||||
/// @param callback 回调函数
|
||||
/// @brief 创建监听器
|
||||
/// @tparam _EventTy 事件类型
|
||||
/// @param callback 回调函数
|
||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
||||
static inline EventListenerPtr Create(Callback const& callback)
|
||||
{
|
||||
|
|
@ -73,10 +73,10 @@ public:
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建监听器
|
||||
/// @tparam _EventTy 事件类型
|
||||
/// @param name 监听器名称
|
||||
/// @param callback 回调函数
|
||||
/// @brief 创建监听器
|
||||
/// @tparam _EventTy 事件类型
|
||||
/// @param name 监听器名称
|
||||
/// @param callback 回调函数
|
||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
||||
static inline EventListenerPtr Create(String const& name, Callback const& callback)
|
||||
{
|
||||
|
|
@ -88,53 +88,53 @@ public:
|
|||
virtual ~EventListener();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 启动监听器
|
||||
/// @brief 启动监听器
|
||||
void Start();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 停止监听器
|
||||
/// @brief 停止监听器
|
||||
void Stop();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除监听器
|
||||
/// @brief 移除监听器
|
||||
void Remove();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否正在运行
|
||||
/// @brief 是否正在运行
|
||||
bool IsRunning() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否可移除
|
||||
/// @brief 是否可移除
|
||||
bool IsRemoveable() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否开启消息吞没
|
||||
/// @brief 是否开启消息吞没
|
||||
bool IsSwallowEnabled() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置消息吞没功能
|
||||
/// @param enabled 是否启用
|
||||
/// @brief 设置消息吞没功能
|
||||
/// @param enabled 是否启用
|
||||
void SetSwallowEnabled(bool enabled);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取回调函数
|
||||
/// @brief 获取回调函数
|
||||
const Callback& GetCallback() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置回调函数
|
||||
/// @brief 设置回调函数
|
||||
void SetCallback(Callback const& cb);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取监听的事件类型
|
||||
/// @brief 获取监听的事件类型
|
||||
EventType GetEventType() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置监听的事件类型
|
||||
/// @brief 设置监听的事件类型
|
||||
void SetEventType(EventType const& type);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置监听的事件类型
|
||||
/// @tparam _EventTy 事件类型
|
||||
/// @brief 设置监听的事件类型
|
||||
/// @tparam _EventTy 事件类型
|
||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
||||
inline void SetEventType()
|
||||
{
|
||||
|
|
@ -142,7 +142,7 @@ public:
|
|||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 接收消息
|
||||
/// @brief 接收消息
|
||||
void Receive(Event* evt);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
// 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/core/Exception.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
||||
Exception::Exception()
|
||||
{
|
||||
}
|
||||
|
||||
Exception::Exception(String const& message)
|
||||
: message_(message)
|
||||
{
|
||||
}
|
||||
|
||||
Exception::~Exception()
|
||||
{
|
||||
}
|
||||
|
||||
const String& Exception::ToString() const
|
||||
{
|
||||
return message_;
|
||||
}
|
||||
|
||||
const char* Exception::what() const
|
||||
{
|
||||
return message_.c_str();
|
||||
}
|
||||
|
||||
SystemException::SystemException()
|
||||
: code_(0)
|
||||
{
|
||||
}
|
||||
|
||||
SystemException::SystemException(ErrorCodeType code, String const& message)
|
||||
: Exception(message)
|
||||
, code_(code)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
// 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/core/Common.h>
|
||||
#include <kiwano/macros.h>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 异常
|
||||
*/
|
||||
class KGE_API Exception : public std::exception
|
||||
{
|
||||
public:
|
||||
Exception();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造异常
|
||||
/// @param message 描述异常的信息
|
||||
explicit Exception(String const& message);
|
||||
|
||||
virtual ~Exception();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 转为解释性字符串
|
||||
const String& ToString() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 转为解释性字符串
|
||||
virtual const char* what() const override;
|
||||
|
||||
protected:
|
||||
String message_;
|
||||
};
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 系统异常
|
||||
*/
|
||||
class SystemException : public Exception
|
||||
{
|
||||
public:
|
||||
#if defined(KGE_WIN32)
|
||||
/// \~chinese
|
||||
/// @brief 错误代码类型
|
||||
typedef HRESULT ErrorCodeType;
|
||||
#endif
|
||||
|
||||
SystemException();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造系统异常
|
||||
/// @param code 错误代码
|
||||
/// @param message 描述异常的信息
|
||||
SystemException(ErrorCodeType code, String const& message);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取错误代码
|
||||
ErrorCodeType GetErrorCode() const;
|
||||
|
||||
private:
|
||||
ErrorCodeType code_;
|
||||
};
|
||||
|
||||
inline SystemException::ErrorCodeType SystemException::GetErrorCode() const
|
||||
{
|
||||
return code_;
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
@ -24,97 +24,97 @@
|
|||
namespace kiwano
|
||||
{
|
||||
/// \~chinese
|
||||
/// @brief 鼠标按键
|
||||
/// @brief 鼠标按键
|
||||
enum class MouseButton
|
||||
{
|
||||
Left, ///< 鼠标左键
|
||||
Right, ///< 鼠标右键
|
||||
Middle, ///< 鼠标中键
|
||||
Left, ///< 鼠标左键
|
||||
Right, ///< 鼠标右键
|
||||
Middle, ///< 鼠标中键
|
||||
|
||||
Last
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 按键键值
|
||||
/// @brief 按键键值
|
||||
enum class KeyCode
|
||||
{
|
||||
Unknown, ///< 未知
|
||||
Up, ///< 上键
|
||||
Left, ///< 左键
|
||||
Right, ///< 右键
|
||||
Down, ///< 下键
|
||||
Enter, ///< 回车键
|
||||
Space, ///< 空格键
|
||||
Esc, ///< 退出键
|
||||
Ctrl, ///< CTRL键
|
||||
Shift, ///< SHIFT键
|
||||
Alt, ///< ALT键
|
||||
Tab, ///< TAB键
|
||||
Delete, ///< 删除键
|
||||
Back, ///< 退格键
|
||||
Super, ///< Cmd|Super|Windows键
|
||||
Unknown, ///< 未知
|
||||
Up, ///< 上键
|
||||
Left, ///< 左键
|
||||
Right, ///< 右键
|
||||
Down, ///< 下键
|
||||
Enter, ///< 回车键
|
||||
Space, ///< 空格键
|
||||
Esc, ///< 退出键
|
||||
Ctrl, ///< CTRL键
|
||||
Shift, ///< SHIFT键
|
||||
Alt, ///< ALT键
|
||||
Tab, ///< TAB键
|
||||
Delete, ///< 删除键
|
||||
Back, ///< 退格键
|
||||
Super, ///< Cmd|Super|Windows键
|
||||
|
||||
A, ///< A键
|
||||
B, ///< B键
|
||||
C, ///< C键
|
||||
D, ///< D键
|
||||
E, ///< E键
|
||||
F, ///< F键
|
||||
G, ///< G键
|
||||
H, ///< H键
|
||||
I, ///< I键
|
||||
J, ///< J键
|
||||
K, ///< K键
|
||||
L, ///< L键
|
||||
M, ///< M键
|
||||
N, ///< N键
|
||||
O, ///< O键
|
||||
P, ///< P键
|
||||
Q, ///< Q键
|
||||
R, ///< R键
|
||||
S, ///< S键
|
||||
T, ///< T键
|
||||
U, ///< U键
|
||||
V, ///< V键
|
||||
W, ///< W键
|
||||
X, ///< X键
|
||||
Y, ///< Y键
|
||||
Z, ///< Z键
|
||||
A, ///< A键
|
||||
B, ///< B键
|
||||
C, ///< C键
|
||||
D, ///< D键
|
||||
E, ///< E键
|
||||
F, ///< F键
|
||||
G, ///< G键
|
||||
H, ///< H键
|
||||
I, ///< I键
|
||||
J, ///< J键
|
||||
K, ///< K键
|
||||
L, ///< L键
|
||||
M, ///< M键
|
||||
N, ///< N键
|
||||
O, ///< O键
|
||||
P, ///< P键
|
||||
Q, ///< Q键
|
||||
R, ///< R键
|
||||
S, ///< S键
|
||||
T, ///< T键
|
||||
U, ///< U键
|
||||
V, ///< V键
|
||||
W, ///< W键
|
||||
X, ///< X键
|
||||
Y, ///< Y键
|
||||
Z, ///< Z键
|
||||
|
||||
Num0, ///< 数字0键
|
||||
Num1, ///< 数字1键
|
||||
Num2, ///< 数字2键
|
||||
Num3, ///< 数字3键
|
||||
Num4, ///< 数字4键
|
||||
Num5, ///< 数字5键
|
||||
Num6, ///< 数字6键
|
||||
Num7, ///< 数字7键
|
||||
Num8, ///< 数字8键
|
||||
Num9, ///< 数字9键
|
||||
Num0, ///< 数字0键
|
||||
Num1, ///< 数字1键
|
||||
Num2, ///< 数字2键
|
||||
Num3, ///< 数字3键
|
||||
Num4, ///< 数字4键
|
||||
Num5, ///< 数字5键
|
||||
Num6, ///< 数字6键
|
||||
Num7, ///< 数字7键
|
||||
Num8, ///< 数字8键
|
||||
Num9, ///< 数字9键
|
||||
|
||||
Numpad0, ///< 数字小键盘0键
|
||||
Numpad1, ///< 数字小键盘1键
|
||||
Numpad2, ///< 数字小键盘2键
|
||||
Numpad3, ///< 数字小键盘3键
|
||||
Numpad4, ///< 数字小键盘4键
|
||||
Numpad5, ///< 数字小键盘5键
|
||||
Numpad6, ///< 数字小键盘6键
|
||||
Numpad7, ///< 数字小键盘7键
|
||||
Numpad8, ///< 数字小键盘8键
|
||||
Numpad9, ///< 数字小键盘9键
|
||||
Numpad0, ///< 数字小键盘0键
|
||||
Numpad1, ///< 数字小键盘1键
|
||||
Numpad2, ///< 数字小键盘2键
|
||||
Numpad3, ///< 数字小键盘3键
|
||||
Numpad4, ///< 数字小键盘4键
|
||||
Numpad5, ///< 数字小键盘5键
|
||||
Numpad6, ///< 数字小键盘6键
|
||||
Numpad7, ///< 数字小键盘7键
|
||||
Numpad8, ///< 数字小键盘8键
|
||||
Numpad9, ///< 数字小键盘9键
|
||||
|
||||
F1, ///< F1键
|
||||
F2, ///< F2键
|
||||
F3, ///< F3键
|
||||
F4, ///< F4键
|
||||
F5, ///< F5键
|
||||
F6, ///< F6键
|
||||
F7, ///< F7键
|
||||
F8, ///< F8键
|
||||
F9, ///< F9键
|
||||
F10, ///< F10键
|
||||
F11, ///< F11键
|
||||
F12, ///< F12键
|
||||
F1, ///< F1键
|
||||
F2, ///< F2键
|
||||
F3, ///< F3键
|
||||
F4, ///< F4键
|
||||
F5, ///< F5键
|
||||
F6, ///< F6键
|
||||
F7, ///< F7键
|
||||
F8, ///< F8键
|
||||
F9, ///< F9键
|
||||
F10, ///< F10键
|
||||
F11, ///< F11键
|
||||
F12, ///< F12键
|
||||
|
||||
Last
|
||||
};
|
||||
|
|
|
|||
|
|
@ -40,12 +40,6 @@ Library::~Library()
|
|||
}
|
||||
|
||||
bool Library::Load(String const& lib)
|
||||
{
|
||||
instance_ = ::LoadLibraryW(lib.c_str());
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
bool Library::Load(ByteString const& lib)
|
||||
{
|
||||
instance_ = ::LoadLibraryA(lib.c_str());
|
||||
return IsValid();
|
||||
|
|
@ -65,7 +59,7 @@ void Library::Free()
|
|||
}
|
||||
}
|
||||
|
||||
FARPROC Library::GetProcess(ByteString const& proc_name)
|
||||
FARPROC Library::GetProcess(String const& proc_name)
|
||||
{
|
||||
KGE_ASSERT(instance_ != nullptr);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,56 +20,50 @@
|
|||
|
||||
#pragma once
|
||||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/macros.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief DLL库
|
||||
* @brief DLL库
|
||||
*/
|
||||
class KGE_API Library
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造DLL库
|
||||
/// @brief 构造DLL库
|
||||
Library();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造DLL库
|
||||
/// @param lib DLL文件路径
|
||||
/// @brief 构造DLL库
|
||||
/// @param lib DLL文件路径
|
||||
Library(String const& lib);
|
||||
|
||||
virtual ~Library();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载DLL
|
||||
/// @param lib DLL文件路径
|
||||
/// @brief 加载DLL
|
||||
/// @param lib DLL文件路径
|
||||
bool Load(String const& lib);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载DLL
|
||||
/// @param lib DLL文件路径
|
||||
bool Load(ByteString const& lib);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否有效
|
||||
/// @brief 是否有效
|
||||
bool IsValid() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 释放DLL
|
||||
/// @brief 释放DLL
|
||||
void Free();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 检索指定的DLL中的输出库函数地址
|
||||
/// @param proc_name 函数名
|
||||
FARPROC GetProcess(ByteString const& proc_name);
|
||||
/// @brief 检索指定的DLL中的输出库函数地址
|
||||
/// @param proc_name 函数名
|
||||
FARPROC GetProcess(String const& proc_name);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 检索指定的DLL中的输出库函数地址
|
||||
/// @param proc_name 函数名
|
||||
/// @brief 检索指定的DLL中的输出库函数地址
|
||||
/// @param proc_name 函数名
|
||||
template <typename _Proc>
|
||||
inline _Proc GetProcess(ByteString const& proc_name)
|
||||
inline _Proc GetProcess(String const& proc_name)
|
||||
{
|
||||
return reinterpret_cast<_Proc>(GetProcess(proc_name));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ const WORD reset = white;
|
|||
} // namespace console_colors
|
||||
|
||||
#define DECLARE_HANDLE_COLOR(NAME, HANDLE_NAME, COLOR) \
|
||||
inline std::wostream&(NAME)(std::wostream & _out) \
|
||||
inline OutputStream&(NAME)(OutputStream & _out) \
|
||||
{ \
|
||||
::SetConsoleTextAttribute(::GetStdHandle(HANDLE_NAME), console_colors::##COLOR); \
|
||||
return _out; \
|
||||
|
|
@ -175,8 +175,8 @@ Logger::Logger()
|
|||
: enabled_(true)
|
||||
, default_stdout_color_(0)
|
||||
, default_stderr_color_(0)
|
||||
, output_stream_(std::wcout.rdbuf())
|
||||
, error_stream_(std::wcerr.rdbuf())
|
||||
, output_stream_(std::cout.rdbuf())
|
||||
, error_stream_(std::cerr.rdbuf())
|
||||
{
|
||||
ResetOutputStream();
|
||||
}
|
||||
|
|
@ -186,7 +186,7 @@ Logger::~Logger()
|
|||
FreeAllocatedConsole();
|
||||
}
|
||||
|
||||
void Logger::Printf(Level level, const wchar_t* format, ...)
|
||||
void Logger::Printf(Level level, const char* format, ...)
|
||||
{
|
||||
if (!enabled_)
|
||||
return;
|
||||
|
|
@ -200,11 +200,11 @@ void Logger::Printf(Level level, const wchar_t* format, ...)
|
|||
va_list args = nullptr;
|
||||
va_start(args, format);
|
||||
|
||||
static wchar_t temp_buffer[1024 * 3 + 1];
|
||||
const auto len = ::_vscwprintf(format, args) + 1;
|
||||
::_vsnwprintf_s(temp_buffer, len, len, format, args);
|
||||
static char temp_buffer[1024 * 3 + 1];
|
||||
const auto len = ::_vscprintf(format, args) + 1;
|
||||
::_vsnprintf_s(temp_buffer, len, len, format, args);
|
||||
|
||||
sstream << ' ' << temp_buffer << L"\r\n";
|
||||
sstream << ' ' << temp_buffer << "\r\n";
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
|
@ -219,16 +219,16 @@ void Logger::Prepare(Level level, StringStream& sstream)
|
|||
switch (level)
|
||||
{
|
||||
case Level::Info:
|
||||
prefix = L"[INFO] ";
|
||||
prefix = "[INFO] ";
|
||||
break;
|
||||
case Level::System:
|
||||
prefix = L"[SYSTEM] ";
|
||||
prefix = "[SYSTEM] ";
|
||||
break;
|
||||
case Level::Warning:
|
||||
prefix = L"[WARN] ";
|
||||
prefix = "[WARN] ";
|
||||
break;
|
||||
case Level::Error:
|
||||
prefix = L"[ERROR] ";
|
||||
prefix = "[ERROR] ";
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -236,11 +236,13 @@ void Logger::Prepare(Level level, StringStream& sstream)
|
|||
time_t unix = std::time(nullptr);
|
||||
std::tm tmbuf;
|
||||
localtime_s(&tmbuf, &unix);
|
||||
sstream << prefix << std::put_time(&tmbuf, L"%H:%M:%S ");
|
||||
sstream << prefix << std::put_time(&tmbuf, "%H:%M:%S ");
|
||||
}
|
||||
|
||||
void Logger::Output(Level level, StringStream& sstream)
|
||||
{
|
||||
using ConsoleColor = Function<OutputStream&(OutputStream&)>;
|
||||
|
||||
OutputStream* ostream = nullptr;
|
||||
ConsoleColor color = nullptr;
|
||||
|
||||
|
|
@ -269,7 +271,7 @@ void Logger::Output(Level level, StringStream& sstream)
|
|||
{
|
||||
auto output = sstream.str();
|
||||
color(*ostream) << output << std::flush;
|
||||
::OutputDebugStringW(output.c_str());
|
||||
::OutputDebugStringA(output.c_str());
|
||||
|
||||
ResetConsoleColor();
|
||||
}
|
||||
|
|
@ -297,20 +299,20 @@ void Logger::ResetOutputStream()
|
|||
|
||||
// replace the C++ global locale with the user-preferred locale
|
||||
(void)std::locale::global(std::locale(""));
|
||||
(void)std::wcout.imbue(std::locale());
|
||||
(void)std::wcerr.imbue(std::locale());
|
||||
(void)std::cout.imbue(std::locale());
|
||||
(void)std::cerr.imbue(std::locale());
|
||||
|
||||
RedirectOutputStreamBuffer(std::wcout.rdbuf());
|
||||
RedirectErrorStreamBuffer(std::wcerr.rdbuf());
|
||||
RedirectOutputStreamBuffer(std::cout.rdbuf());
|
||||
RedirectErrorStreamBuffer(std::cerr.rdbuf());
|
||||
}
|
||||
}
|
||||
|
||||
std::wstreambuf* Logger::RedirectOutputStreamBuffer(std::wstreambuf* buf)
|
||||
std::streambuf* Logger::RedirectOutputStreamBuffer(std::streambuf* buf)
|
||||
{
|
||||
return output_stream_.rdbuf(buf);
|
||||
}
|
||||
|
||||
std::wstreambuf* Logger::RedirectErrorStreamBuffer(std::wstreambuf* buf)
|
||||
std::streambuf* Logger::RedirectErrorStreamBuffer(std::streambuf* buf)
|
||||
{
|
||||
return error_stream_.rdbuf(buf);
|
||||
}
|
||||
|
|
@ -329,7 +331,7 @@ void Logger::ShowConsole(bool show)
|
|||
HWND console = ::AllocateConsole();
|
||||
if (!console)
|
||||
{
|
||||
KGE_WARN(L"AllocConsole failed");
|
||||
KGE_WARN("AllocConsole failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,33 +27,33 @@
|
|||
#ifndef KGE_SYS_LOG
|
||||
#ifdef KGE_DEBUG
|
||||
#define KGE_SYS_LOG(FORMAT, ...) \
|
||||
::kiwano::Logger::Instance().Printf(::kiwano::Logger::Level::System, FORMAT, __VA_ARGS__)
|
||||
::kiwano::Logger::GetInstance().Printf(::kiwano::Logger::Level::System, FORMAT, __VA_ARGS__)
|
||||
#else
|
||||
#define KGE_SYS_LOG __noop
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef KGE_WARN
|
||||
#define KGE_WARN(FORMAT, ...) ::kiwano::Logger::Instance().Printf(::kiwano::Logger::Level::Warning, FORMAT, __VA_ARGS__)
|
||||
#define KGE_WARN(FORMAT, ...) ::kiwano::Logger::GetInstance().Printf(::kiwano::Logger::Level::Warning, FORMAT, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifndef KGE_ERROR
|
||||
#define KGE_ERROR(FORMAT, ...) ::kiwano::Logger::Instance().Printf(::kiwano::Logger::Level::Error, FORMAT, __VA_ARGS__)
|
||||
#define KGE_ERROR(FORMAT, ...) ::kiwano::Logger::GetInstance().Printf(::kiwano::Logger::Level::Error, FORMAT, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifndef KGE_LOG
|
||||
#define KGE_LOG(...) ::kiwano::Logger::Instance().Println(::kiwano::Logger::Level::Info, __VA_ARGS__)
|
||||
#define KGE_LOG(...) ::kiwano::Logger::GetInstance().Println(::kiwano::Logger::Level::Info, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifndef KGE_LOGF
|
||||
#define KGE_LOGF(FORMAT, ...) ::kiwano::Logger::Instance().Printf(::kiwano::Logger::Level::Info, FORMAT, __VA_ARGS__)
|
||||
#define KGE_LOGF(FORMAT, ...) ::kiwano::Logger::GetInstance().Printf(::kiwano::Logger::Level::Info, FORMAT, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 日志
|
||||
* @brief 日志
|
||||
*/
|
||||
class KGE_API Logger : public Singleton<Logger>
|
||||
{
|
||||
|
|
@ -61,74 +61,66 @@ class KGE_API Logger : public Singleton<Logger>
|
|||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 日志级别
|
||||
/// @brief 日志级别
|
||||
enum class Level
|
||||
{
|
||||
Info, ///< 信息
|
||||
System, ///< 系统
|
||||
Warning, ///< 警告
|
||||
Error ///< 错误
|
||||
Info, ///< 信息
|
||||
System, ///< 系统
|
||||
Warning, ///< 警告
|
||||
Error ///< 错误
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 输出流
|
||||
using OutputStream = std::wostream;
|
||||
/// @brief 打印日志
|
||||
/// @param level 日志级别
|
||||
/// @param format 格式字符串
|
||||
void Printf(Level level, const char* format, ...);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 控制台颜色
|
||||
using ConsoleColor = Function<OutputStream&(OutputStream&)>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 打印日志
|
||||
/// @param level 日志级别
|
||||
/// @param format 格式字符串
|
||||
void Printf(Level level, const wchar_t* format, ...);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 打印日志
|
||||
/// @param level 日志级别
|
||||
/// @param args 参数
|
||||
/// @brief 打印日志
|
||||
/// @param level 日志级别
|
||||
/// @param args 参数
|
||||
template <typename... _Args>
|
||||
void Print(Level level, _Args&&... args);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 打印一行日志
|
||||
/// @param level 日志级别
|
||||
/// @param args 参数
|
||||
/// @brief 打印一行日志
|
||||
/// @param level 日志级别
|
||||
/// @param args 参数
|
||||
template <typename... _Args>
|
||||
void Println(Level level, _Args&&... args);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 显示或关闭控制台
|
||||
/// @note 此操作会重置输出流
|
||||
/// @brief 显示或关闭控制台
|
||||
/// @note 此操作会重置输出流
|
||||
void ShowConsole(bool show);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 启用日志
|
||||
/// @brief 启用日志
|
||||
void Enable();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 禁用日志
|
||||
/// @brief 禁用日志
|
||||
void Disable();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取输出流
|
||||
std::wostream& GetOutputStream();
|
||||
/// @brief 获取输出流
|
||||
OutputStream& GetOutputStream();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取错误流
|
||||
std::wostream& GetErrorStream();
|
||||
/// @brief 获取错误流
|
||||
OutputStream& GetErrorStream();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 重定向输出流
|
||||
std::wstreambuf* RedirectOutputStreamBuffer(std::wstreambuf* buf);
|
||||
/// @brief 重定向输出流
|
||||
std::streambuf* RedirectOutputStreamBuffer(std::streambuf* buf);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 重定向错误流
|
||||
std::wstreambuf* RedirectErrorStreamBuffer(std::wstreambuf* buf);
|
||||
/// @brief 重定向错误流
|
||||
std::streambuf* RedirectErrorStreamBuffer(std::streambuf* buf);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 重置输出流
|
||||
/// @brief 重置输出流
|
||||
void ResetOutputStream();
|
||||
|
||||
private:
|
||||
|
|
@ -190,7 +182,7 @@ void Logger::Println(Level level, _Args&&... args)
|
|||
// Format message
|
||||
(void)std::initializer_list<int>{ ((sstream << ' ' << args), 0)... };
|
||||
|
||||
sstream << L"\r\n";
|
||||
sstream << "\r\n";
|
||||
|
||||
Output(level, sstream);
|
||||
}
|
||||
|
|
@ -201,18 +193,18 @@ inline void Logger::ResetConsoleColor() const
|
|||
::SetConsoleTextAttribute(::GetStdHandle(STD_ERROR_HANDLE), default_stderr_color_);
|
||||
}
|
||||
|
||||
inline Logger::OutputStream& Logger::DefaultOutputColor(OutputStream& out)
|
||||
inline OutputStream& Logger::DefaultOutputColor(OutputStream& out)
|
||||
{
|
||||
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), default_stdout_color_);
|
||||
return out;
|
||||
}
|
||||
|
||||
inline std::wostream& Logger::GetOutputStream()
|
||||
inline OutputStream& Logger::GetOutputStream()
|
||||
{
|
||||
return output_stream_;
|
||||
}
|
||||
|
||||
inline std::wostream& Logger::GetErrorStream()
|
||||
inline OutputStream& Logger::GetErrorStream()
|
||||
{
|
||||
return error_stream_;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,9 +88,8 @@ void ObjectBase::SetName(String const& name)
|
|||
|
||||
String ObjectBase::DumpObject()
|
||||
{
|
||||
String name = oc::string_to_wide(typeid(*this).name());
|
||||
return String::format(L"{ class=\"%s\" id=%d refcount=%d name=\"%s\" }", name.c_str(), GetObjectID(), GetRefCount(),
|
||||
GetName().c_str());
|
||||
return String::format("{ class=\"%s\" id=%d refcount=%d name=\"%s\" }", typeid(*this).name(), GetObjectID(),
|
||||
GetRefCount(), GetName().c_str());
|
||||
}
|
||||
|
||||
bool ObjectBase::IsTracingLeaks()
|
||||
|
|
@ -110,12 +109,12 @@ void ObjectBase::StopTracingLeaks()
|
|||
|
||||
void ObjectBase::DumpTracingObjects()
|
||||
{
|
||||
KGE_SYS_LOG(L"-------------------------- All Objects --------------------------");
|
||||
KGE_SYS_LOG("-------------------------- All Objects --------------------------");
|
||||
for (const auto object : tracing_objects)
|
||||
{
|
||||
KGE_SYS_LOG(L"%s", object->DumpObject().c_str());
|
||||
KGE_SYS_LOG("%s", object->DumpObject().c_str());
|
||||
}
|
||||
KGE_SYS_LOG(L"------------------------- Total size: %d -------------------------", tracing_objects.size());
|
||||
KGE_SYS_LOG("------------------------- Total size: %d -------------------------", tracing_objects.size());
|
||||
}
|
||||
|
||||
Vector<ObjectBase*>& ObjectBase::GetTracingObjects()
|
||||
|
|
|
|||
|
|
@ -30,65 +30,65 @@ KGE_DECLARE_SMART_PTR(ObjectBase);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 基础对象
|
||||
* @brief 基础对象
|
||||
*/
|
||||
class KGE_API ObjectBase : public RefCounter
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造基础对象
|
||||
/// @brief 构造基础对象
|
||||
ObjectBase();
|
||||
|
||||
virtual ~ObjectBase();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置对象名
|
||||
/// @brief 设置对象名
|
||||
void SetName(String const& name);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取对象名
|
||||
/// @brief 获取对象名
|
||||
String GetName() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 判断对象的名称是否相同
|
||||
/// @param name 需要判断的名称
|
||||
/// @brief 判断对象的名称是否相同
|
||||
/// @param name 需要判断的名称
|
||||
bool IsName(String const& name) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取用户数据
|
||||
/// @brief 获取用户数据
|
||||
const Any& GetUserData() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置用户数据
|
||||
/// @brief 设置用户数据
|
||||
void SetUserData(Any const& data);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取对象ID
|
||||
/// @brief 获取对象ID
|
||||
uint32_t GetObjectID() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 序列化对象
|
||||
/// @brief 序列化对象
|
||||
String DumpObject();
|
||||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 是否启用了内存泄漏追踪
|
||||
/// @brief 是否启用了内存泄漏追踪
|
||||
static bool IsTracingLeaks();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 开始追踪内存泄漏
|
||||
/// @brief 开始追踪内存泄漏
|
||||
static void StartTracingLeaks();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 停止追踪内存泄漏
|
||||
/// @brief 停止追踪内存泄漏
|
||||
static void StopTracingLeaks();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 打印所有追踪中的对象信息
|
||||
/// @brief 打印所有追踪中的对象信息
|
||||
static void DumpTracingObjects();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取所有追踪中的对象
|
||||
/// @brief 获取所有追踪中的对象
|
||||
static Vector<ObjectBase*>& GetTracingObjects();
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -26,21 +26,21 @@ namespace kiwano
|
|||
{
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 引用计数器
|
||||
* @brief 引用计数器
|
||||
*/
|
||||
class KGE_API RefCounter : protected Noncopyable
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 增加引用计数
|
||||
/// @brief 增加引用计数
|
||||
void Retain();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 减少引用计数
|
||||
/// @brief 减少引用计数
|
||||
void Release();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取引用计数
|
||||
/// @brief 获取引用计数
|
||||
long GetRefCount() const;
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -48,28 +48,28 @@ Resource::Data Resource::GetData() const
|
|||
HRSRC res_info = FindResourceW(nullptr, MAKEINTRESOURCE(id_), type_);
|
||||
if (res_info == nullptr)
|
||||
{
|
||||
KGE_ERROR(L"FindResource failed");
|
||||
KGE_ERROR("FindResource failed");
|
||||
break;
|
||||
}
|
||||
|
||||
HGLOBAL res_data = LoadResource(nullptr, res_info);
|
||||
if (res_data == nullptr)
|
||||
{
|
||||
KGE_ERROR(L"LoadResource failed");
|
||||
KGE_ERROR("LoadResource failed");
|
||||
break;
|
||||
}
|
||||
|
||||
DWORD size = SizeofResource(nullptr, res_info);
|
||||
if (size == 0)
|
||||
{
|
||||
KGE_ERROR(L"SizeofResource failed");
|
||||
KGE_ERROR("SizeofResource failed");
|
||||
break;
|
||||
}
|
||||
|
||||
LPVOID buffer = LockResource(res_data);
|
||||
if (buffer == nullptr)
|
||||
{
|
||||
KGE_ERROR(L"LockResource failed");
|
||||
KGE_ERROR("LockResource failed");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,26 +26,26 @@ namespace kiwano
|
|||
{
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 资源
|
||||
* @brief 资源
|
||||
* @details
|
||||
* 资源是保存在 exe 中的二进制数据,
|
||||
* 例如,一份音频资源的类型为 L"WAVE",名称标识符为
|
||||
* IDR_WAVE_1,那么可以这样指定该资源:
|
||||
* 资源是保存在 exe 中的二进制数据,
|
||||
* 例如,一份音频资源的类型为 "WAVE",名称标识符为
|
||||
* IDR_WAVE_1,那么可以这样指定该资源:
|
||||
* @code
|
||||
* Resource(IDR_WAVE_1, L"WAVE");
|
||||
* Resource(IDR_WAVE_1, "WAVE");
|
||||
* @endcode
|
||||
* 了解资源的更多信息:
|
||||
* 了解资源的更多信息:
|
||||
* https://docs.microsoft.com/en-us/windows/desktop/menurc/resources
|
||||
*/
|
||||
class KGE_API Resource
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 资源的二进制数据
|
||||
/// @brief 资源的二进制数据
|
||||
struct Data
|
||||
{
|
||||
void* buffer; ///< 资源数据
|
||||
uint32_t size; ///< 资源数据大小
|
||||
void* buffer; ///< 资源数据
|
||||
uint32_t size; ///< 资源数据大小
|
||||
|
||||
Data();
|
||||
|
||||
|
|
@ -53,26 +53,26 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造资源
|
||||
/// @brief 构造资源
|
||||
Resource();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造资源
|
||||
/// @param id 资源 ID
|
||||
/// @param type 资源类型
|
||||
/// @brief 构造资源
|
||||
/// @param id 资源 ID
|
||||
/// @param type 资源类型
|
||||
Resource(uint32_t id, const wchar_t* type);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取资源的二进制数据
|
||||
/// @return 资源数据
|
||||
/// @brief 获取资源的二进制数据
|
||||
/// @return 资源数据
|
||||
Resource::Data GetData() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取资源 ID
|
||||
/// @brief 获取资源 ID
|
||||
uint32_t GetId() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取资源类型
|
||||
/// @brief 获取资源类型
|
||||
const wchar_t* GetType() const;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ private:
|
|||
{
|
||||
ObjectCreator()
|
||||
{
|
||||
(void)Singleton<_Ty>::Instance();
|
||||
(void)Singleton<_Ty>::GetInstance();
|
||||
}
|
||||
|
||||
inline void Dummy() const {}
|
||||
|
|
@ -46,7 +46,7 @@ private:
|
|||
public:
|
||||
using object_type = _Ty;
|
||||
|
||||
static inline object_type& Instance()
|
||||
static inline object_type& GetInstance()
|
||||
{
|
||||
static object_type instance;
|
||||
creator_.Dummy();
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace kiwano
|
|||
{
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 默认的智能指针代理
|
||||
* @brief 默认的智能指针代理
|
||||
*/
|
||||
struct DefaultSmartPtrRefProxy
|
||||
{
|
||||
|
|
@ -45,7 +45,7 @@ struct DefaultSmartPtrRefProxy
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 智能指针
|
||||
* @brief 智能指针
|
||||
*/
|
||||
template <typename _Ty>
|
||||
using SmartPtr = IntrusivePtr<_Ty, DefaultSmartPtrRefProxy>;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/core/Exception.h>
|
||||
#include <kiwano/core/Logger.h>
|
||||
#include <kiwano/core/Time.h>
|
||||
#include <regex>
|
||||
|
|
@ -94,12 +95,13 @@ const Duration Duration::Hour = 60 * Duration::Minute;
|
|||
|
||||
namespace
|
||||
{
|
||||
const auto duration_regex = std::wregex(LR"(^[-+]?([0-9]*(\.[0-9]*)?(h|m|s|ms)+)+$)");
|
||||
const auto duration_regex = std::regex(R"(^[-+]?([0-9]*(\.[0-9]*)?(h|m|s|ms)+)+$)");
|
||||
|
||||
typedef std::unordered_map<String, Duration> UnitMap;
|
||||
const auto unit_map = UnitMap{
|
||||
{ L"ms", Duration::Ms }, { L"s", Duration::Second }, { L"m", Duration::Minute }, { L"h", Duration::Hour }
|
||||
};
|
||||
|
||||
const auto unit_map =
|
||||
UnitMap{ { "ms", Duration::Ms }, { "s", Duration::Second }, { "m", Duration::Minute }, { "h", Duration::Hour } };
|
||||
|
||||
} // namespace
|
||||
|
||||
Duration::Duration()
|
||||
|
|
@ -137,14 +139,14 @@ String Duration::ToString() const
|
|||
{
|
||||
if (IsZero())
|
||||
{
|
||||
return String(L"0s");
|
||||
return String("0s");
|
||||
}
|
||||
|
||||
String result;
|
||||
long total_ms = milliseconds_;
|
||||
if (total_ms < 0)
|
||||
{
|
||||
result.append(L"-");
|
||||
result.append("-");
|
||||
total_ms = -total_ms;
|
||||
}
|
||||
|
||||
|
|
@ -155,21 +157,21 @@ String Duration::ToString() const
|
|||
|
||||
if (hour)
|
||||
{
|
||||
result.append(String::parse(hour)).append(L"h");
|
||||
result.append(String::parse(min)).append(L"m");
|
||||
result.append(String::parse(hour)).append("h");
|
||||
result.append(String::parse(min)).append("m");
|
||||
}
|
||||
else if (min)
|
||||
{
|
||||
result.append(String::parse(min)).append(L"m");
|
||||
result.append(String::parse(min)).append("m");
|
||||
}
|
||||
|
||||
if (ms != 0)
|
||||
{
|
||||
result.append(String::parse(static_cast<float>(sec) + static_cast<float>(ms) / 1000.f)).append(L"s");
|
||||
result.append(String::parse(static_cast<float>(sec) + static_cast<float>(ms) / 1000.f)).append("s");
|
||||
}
|
||||
else if (sec != 0)
|
||||
{
|
||||
result.append(String::parse(sec)).append(L"s");
|
||||
result.append(String::parse(sec)).append("s");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -356,57 +358,59 @@ Duration Duration::Parse(const String& format)
|
|||
|
||||
if (!std::regex_match(format.c_str(), duration_regex))
|
||||
{
|
||||
throw std::runtime_error("Duration::Parse failed, invalid duration");
|
||||
throw Exception("Duration::Parse failed, invalid duration");
|
||||
}
|
||||
|
||||
if (format.empty() || format == L"0")
|
||||
if (format.empty() || format == "0")
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ·ûºÅλ
|
||||
if (format[0] == L'-' || format[0] == L'+')
|
||||
// 符号位
|
||||
if (format[0] == '-' || format[0] == '+')
|
||||
{
|
||||
negative = (format[0] == L'-');
|
||||
negative = (format[0] == '-');
|
||||
pos++;
|
||||
}
|
||||
|
||||
while (pos < len)
|
||||
{
|
||||
// ÊýÖµ
|
||||
// 数值
|
||||
size_t i = pos;
|
||||
for (; i < len; ++i)
|
||||
{
|
||||
wchar_t ch = format[i];
|
||||
if (!(ch == L'.' || L'0' <= ch && ch <= L'9'))
|
||||
if (!(ch == '.' || '0' <= ch && ch <= '9'))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
String num_str = format.substr(pos, i - pos);
|
||||
pos = i;
|
||||
|
||||
if (num_str.empty() || num_str == L".")
|
||||
throw std::runtime_error("Duration::Parse failed, invalid duration");
|
||||
pos = i;
|
||||
|
||||
// µ¥Î»
|
||||
if (num_str.empty() || num_str == ".")
|
||||
throw Exception("Duration::Parse failed, invalid duration");
|
||||
|
||||
// 单位
|
||||
for (; i < len; ++i)
|
||||
{
|
||||
wchar_t ch = format[i];
|
||||
if (ch == L'.' || L'0' <= ch && ch <= L'9')
|
||||
if (ch == '.' || '0' <= ch && ch <= '9')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
String unit_str = format.substr(pos, i - pos);
|
||||
pos = i;
|
||||
|
||||
pos = i;
|
||||
|
||||
if (unit_map.find(unit_str) == unit_map.end())
|
||||
throw std::runtime_error("Duration::Parse failed, invalid duration");
|
||||
throw Exception("Duration::Parse failed, invalid duration");
|
||||
|
||||
double num = std::wcstod(num_str.c_str(), nullptr);
|
||||
double num = std::stod(num_str.c_str());
|
||||
Duration unit = unit_map.at(unit_str);
|
||||
ret += unit * num;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,94 +26,94 @@ namespace kiwano
|
|||
{
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 时间段
|
||||
* @brief 时间段
|
||||
* @par
|
||||
* 时间段表示法:
|
||||
* 时间段表示法:
|
||||
* @code
|
||||
* time::Second * 5 // 5 秒
|
||||
* time::Hour * 1.5 // 1.5 小时
|
||||
* time::Hour * 3 + time::Minute * 45 + time::Second * 15 // 3 小时 45 分 15
|
||||
* 秒
|
||||
* time::Second * 5 // 5 秒
|
||||
* time::Hour * 1.5 // 1.5 小时
|
||||
* time::Hour * 3 + time::Minute * 45 + time::Second * 15 // 3 小时 45 分 15
|
||||
* 秒
|
||||
* @endcode
|
||||
* 在 VS2015 及更高版本可以使用 time literals:
|
||||
* 在 VS2015 及更高版本可以使用 time literals:
|
||||
* @code
|
||||
* using namespace kiwano;
|
||||
* 5_sec // 5 秒
|
||||
* 1.5_hour // 1.5 小时
|
||||
* 3_hour + 45_min + 15_sec // 3 小时 45 分 15 秒
|
||||
* 5_sec // 5 秒
|
||||
* 1.5_hour // 1.5 小时
|
||||
* 3_hour + 45_min + 15_sec // 3 小时 45 分 15 秒
|
||||
* @endcode
|
||||
*/
|
||||
struct KGE_API Duration
|
||||
{
|
||||
/// \~chinese
|
||||
/// @brief 构造时间段
|
||||
/// @brief 构造时间段
|
||||
Duration();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造时间段
|
||||
/// @param milliseconds 毫秒数
|
||||
/// @brief 构造时间段
|
||||
/// @param milliseconds 毫秒数
|
||||
Duration(long milliseconds);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取毫秒数
|
||||
/// @brief 获取毫秒数
|
||||
long Milliseconds() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取秒数
|
||||
/// @brief 获取秒数
|
||||
float Seconds() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取分钟数
|
||||
/// @brief 获取分钟数
|
||||
float Minutes() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取小时数
|
||||
/// @brief 获取小时数
|
||||
float Hours() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 时长是否是零
|
||||
/// @return 若时长是零,返回true
|
||||
/// @brief 时长是否是零
|
||||
/// @return 若时长是零,返回true
|
||||
bool IsZero() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置毫秒数
|
||||
/// @param ms 毫秒数
|
||||
/// @brief 设置毫秒数
|
||||
/// @param ms 毫秒数
|
||||
void SetMilliseconds(long ms);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置秒数
|
||||
/// @param seconds 秒数
|
||||
/// @brief 设置秒数
|
||||
/// @param seconds 秒数
|
||||
void SetSeconds(float seconds);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置分钟数
|
||||
/// @param minutes 分钟数
|
||||
/// @brief 设置分钟数
|
||||
/// @param minutes 分钟数
|
||||
void SetMinutes(float minutes);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置小时数
|
||||
/// @param hours 小时数
|
||||
/// @brief 设置小时数
|
||||
/// @param hours 小时数
|
||||
void SetHours(float hours);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 转为字符串
|
||||
/// @brief 转为字符串
|
||||
String ToString() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 解析时间段字符串
|
||||
/// @param str 时间段字符串
|
||||
/// @brief 解析时间段字符串
|
||||
/// @param str 时间段字符串
|
||||
/// @details
|
||||
/// 时间段字符串允许是有符号的浮点数, 并且带有时间单位后缀
|
||||
/// 例如: "300ms", "-1.5h", "2h45m"
|
||||
/// 允许的时间单位有 "ms", "s", "m", "h"
|
||||
/// @return 解析出的时间段
|
||||
/// @throw std::runtime_error 传入了一个不合法的格式
|
||||
/// 时间段字符串允许是有符号的浮点数, 并且带有时间单位后缀
|
||||
/// 例如: "300ms", "-1.5h", "2h45m"
|
||||
/// 允许的时间单位有 "ms", "s", "m", "h"
|
||||
/// @return 解析出的时间段
|
||||
/// @throw kiwano::Exception 传入一个不合法的格式时抛出
|
||||
static Duration Parse(const String& str);
|
||||
|
||||
static const Duration Ms; ///< 毫秒
|
||||
static const Duration Second; ///< 秒
|
||||
static const Duration Minute; ///< 分钟
|
||||
static const Duration Hour; ///< 小时
|
||||
static const Duration Ms; ///< 毫秒
|
||||
static const Duration Second; ///< 秒
|
||||
static const Duration Minute; ///< 分钟
|
||||
static const Duration Hour; ///< 小时
|
||||
|
||||
bool operator==(const Duration&) const;
|
||||
bool operator!=(const Duration&) const;
|
||||
|
|
@ -159,28 +159,28 @@ private:
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 时间
|
||||
* @par 示例:
|
||||
* @brief 时间
|
||||
* @par 示例:
|
||||
* @code
|
||||
* // 两时间相减, 可得到一个 Duration 对象
|
||||
* // 两时间相减, 可得到一个 Duration 对象
|
||||
* Time t1 = Time::Now();
|
||||
* // 等待一段时间后
|
||||
* // 等待一段时间后
|
||||
* Time t2 = Time::Now();
|
||||
* int ms = (t2 - t1).Milliseconds(); // 获取两时间相差的毫秒数
|
||||
* int ms = (t2 - t1).Milliseconds(); // 获取两时间相差的毫秒数
|
||||
* @endcode
|
||||
* @note 时间点与系统时钟无关,因此不能将时间点转化为时分秒
|
||||
* @note 时间点与系统时钟无关,因此不能将时间点转化为时分秒
|
||||
*/
|
||||
struct KGE_API Time
|
||||
{
|
||||
Time();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否是零时
|
||||
/// @return 若是零时,返回true
|
||||
/// @brief 是否是零时
|
||||
/// @return 若是零时,返回true
|
||||
bool IsZero() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取当前时间
|
||||
/// @brief 获取当前时间
|
||||
static Time Now() noexcept;
|
||||
|
||||
const Duration operator-(const Time&) const;
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ class TimerManager;
|
|||
KGE_DECLARE_SMART_PTR(Timer);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 定时器
|
||||
/// @details 定时器用于每隔一段时间执行一次回调函数,且可以指定执行总次数
|
||||
/// @brief 定时器
|
||||
/// @details 定时器用于每隔一段时间执行一次回调函数,且可以指定执行总次数
|
||||
class KGE_API Timer
|
||||
: public virtual ObjectBase
|
||||
, protected IntrusiveListItem<TimerPtr>
|
||||
|
|
@ -40,85 +40,85 @@ class KGE_API Timer
|
|||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 定时器回调函数
|
||||
/// @brief 定时器回调函数
|
||||
/// @details
|
||||
/// 回调函数第一个参数是定时器自身,第二个参数是距离上次更新的时间间隔
|
||||
/// 回调函数第一个参数是定时器自身,第二个参数是距离上次更新的时间间隔
|
||||
using Callback = Function<void(Timer* /* self */, Duration /* dt */)>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建定时器
|
||||
/// @param cb 回调函数
|
||||
/// @param interval 时间间隔
|
||||
/// @param times 执行次数(设 -1 为永久执行)
|
||||
/// @brief 创建定时器
|
||||
/// @param cb 回调函数
|
||||
/// @param interval 时间间隔
|
||||
/// @param times 执行次数(设 -1 为永久执行)
|
||||
static TimerPtr Create(Callback const& cb, Duration interval, int times = -1);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建定时器
|
||||
/// @param name 名称
|
||||
/// @param cb 回调函数
|
||||
/// @param interval 时间间隔
|
||||
/// @param times 执行次数(设 -1 为永久执行)
|
||||
/// @brief 创建定时器
|
||||
/// @param name 名称
|
||||
/// @param cb 回调函数
|
||||
/// @param interval 时间间隔
|
||||
/// @param times 执行次数(设 -1 为永久执行)
|
||||
static TimerPtr Create(String const& name, Callback const& cb, Duration interval, int times = -1);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造空定时器
|
||||
/// @brief 构造空定时器
|
||||
Timer();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 启动定时器
|
||||
/// @brief 启动定时器
|
||||
void Start();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 停止定时器
|
||||
/// @brief 停止定时器
|
||||
void Stop();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除定时器
|
||||
/// @brief 移除定时器
|
||||
void Remove();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 定时器是否在运行
|
||||
/// @brief 定时器是否在运行
|
||||
bool IsRunning() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 定时器是否可移除
|
||||
/// @brief 定时器是否可移除
|
||||
bool IsRemoveable() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取定时器执行过回调函数的次数
|
||||
/// @brief 获取定时器执行过回调函数的次数
|
||||
int GetRunTimes() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取定时器执行回调函数的总次数
|
||||
/// @brief 获取定时器执行回调函数的总次数
|
||||
int GetTotalRunTimes() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置定时器执行回调函数的总次数
|
||||
/// @brief 设置定时器执行回调函数的总次数
|
||||
void SetTotalRunTimes(int times);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取定时器执行时间间隔
|
||||
/// @brief 获取定时器执行时间间隔
|
||||
Duration GetInterval() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置定时器执行时间间隔
|
||||
/// @brief 设置定时器执行时间间隔
|
||||
void SetInterval(Duration interval);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取定时器回调函数
|
||||
/// @brief 获取定时器回调函数
|
||||
Callback GetCallback() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置定时器回调函数
|
||||
/// @brief 设置定时器回调函数
|
||||
void SetCallback(const Callback& callback);
|
||||
|
||||
private:
|
||||
/// \~chinese
|
||||
/// @brief 更新定时器
|
||||
/// @brief 更新定时器
|
||||
void Update(Duration dt);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 重置定时器
|
||||
/// @brief 重置定时器
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -25,65 +25,65 @@ namespace kiwano
|
|||
{
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 定时器管理器
|
||||
* @brief 定时器管理器
|
||||
*/
|
||||
class KGE_API TimerManager
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 定时器列表
|
||||
/// @brief 定时器列表
|
||||
using Timers = IntrusiveList<TimerPtr>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加定时器
|
||||
/// @param cb 回调函数
|
||||
/// @param interval 时间间隔
|
||||
/// @param times 执行次数(设 -1 为永久执行)
|
||||
/// @brief 添加定时器
|
||||
/// @param cb 回调函数
|
||||
/// @param interval 时间间隔
|
||||
/// @param times 执行次数(设 -1 为永久执行)
|
||||
Timer* AddTimer(Timer::Callback const& cb, Duration interval, int times = -1);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加定时器
|
||||
/// @param name 定时器名称
|
||||
/// @param cb 回调函数
|
||||
/// @param interval 时间间隔
|
||||
/// @param times 执行次数(设 -1 为永久执行)
|
||||
/// @brief 添加定时器
|
||||
/// @param name 定时器名称
|
||||
/// @param cb 回调函数
|
||||
/// @param interval 时间间隔
|
||||
/// @param times 执行次数(设 -1 为永久执行)
|
||||
Timer* AddTimer(String const& name, Timer::Callback const& cb, Duration interval, int times = -1);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加定时器
|
||||
/// @brief 添加定时器
|
||||
Timer* AddTimer(TimerPtr timer);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 启动定时器
|
||||
/// @brief 启动定时器
|
||||
void StartTimers(String const& timer_name);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 停止定时器
|
||||
/// @brief 停止定时器
|
||||
void StopTimers(String const& timer_name);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除定时器
|
||||
/// @brief 移除定时器
|
||||
void RemoveTimers(String const& timer_name);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 启动所有定时器
|
||||
/// @brief 启动所有定时器
|
||||
void StartAllTimers();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 停止所有定时器
|
||||
/// @brief 停止所有定时器
|
||||
void StopAllTimers();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 移除所有定时器
|
||||
/// @brief 移除所有定时器
|
||||
void RemoveAllTimers();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取所有定时器
|
||||
/// @brief 获取所有定时器
|
||||
const Timers& GetAllTimers() const;
|
||||
|
||||
protected:
|
||||
/// \~chinese
|
||||
/// @brief 更新定时器
|
||||
/// @brief 更新定时器
|
||||
void UpdateTimers(Duration dt);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ KGE_DECLARE_SMART_PTR(Event);
|
|||
|
||||
/**
|
||||
* \~chinese
|
||||
* \defgroup Events 事件
|
||||
* \defgroup Events 事件
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -38,35 +38,35 @@ KGE_DECLARE_SMART_PTR(Event);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 事件
|
||||
/// @brief 事件
|
||||
class KGE_API Event : public RefCounter
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构造事件
|
||||
/// @brief 构造事件
|
||||
Event(EventType const& type);
|
||||
|
||||
virtual ~Event();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取类型事件
|
||||
/// @brief 获取类型事件
|
||||
const EventType& GetType() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 判断事件类型
|
||||
/// @return 是否是指定事件类型
|
||||
/// @brief 判断事件类型
|
||||
/// @return 是否是指定事件类型
|
||||
template <typename _Ty, typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type>
|
||||
bool IsType() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 安全转换为其他类型事件
|
||||
/// @throw std::bad_cast 类型无法转换时抛出
|
||||
/// @brief 安全转换为其他类型事件
|
||||
/// @throw std::bad_cast 类型无法转换时抛出
|
||||
template <typename _Ty, typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type>
|
||||
const _Ty* SafeCast() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 安全转换为其他类型事件
|
||||
/// @throw std::bad_cast 类型无法转换时抛出
|
||||
/// @brief 安全转换为其他类型事件
|
||||
/// @throw std::bad_cast 类型无法转换时抛出
|
||||
template <typename _Ty, typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type>
|
||||
_Ty* SafeCast();
|
||||
|
||||
|
|
@ -75,14 +75,14 @@ private:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 事件特性:判断指定类型是否是事件
|
||||
/// @brief 事件特性:判断指定类型是否是事件
|
||||
template <typename _Ty>
|
||||
struct IsEvent : public std::bool_constant<std::is_base_of<Event, _Ty>::value || std::is_same<Event, _Ty>::value>
|
||||
{
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 事件特性:判断一个事件能否安全转换到另一事件类型
|
||||
/// @brief 事件特性:判断一个事件能否安全转换到另一事件类型
|
||||
template <typename _Ty, typename = typename std::enable_if<IsEvent<_Ty>::value, int>::type>
|
||||
struct IsEventType
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace kiwano
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 事件类型
|
||||
/// @brief 事件类型
|
||||
class EventType : public std::type_index
|
||||
{
|
||||
class Dummy
|
||||
|
|
@ -40,7 +40,7 @@ class EventType : public std::type_index
|
|||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构建事件类型
|
||||
/// @brief 构建事件类型
|
||||
EventType();
|
||||
|
||||
using std::type_index::type_index;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ KGE_DECLARE_SMART_PTR(KeyCharEvent);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 键盘事件
|
||||
/// @brief 键盘事件
|
||||
class KGE_API KeyEvent : public Event
|
||||
{
|
||||
public:
|
||||
|
|
@ -43,31 +43,31 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 键盘按下事件
|
||||
/// @brief 键盘按下事件
|
||||
class KGE_API KeyDownEvent : public KeyEvent
|
||||
{
|
||||
public:
|
||||
KeyCode code; ///< 键值
|
||||
KeyCode code; ///< 键值
|
||||
|
||||
KeyDownEvent();
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 键盘抬起事件
|
||||
/// @brief 键盘抬起事件
|
||||
class KGE_API KeyUpEvent : public KeyEvent
|
||||
{
|
||||
public:
|
||||
KeyCode code; ///< 键值
|
||||
KeyCode code; ///< 键值
|
||||
|
||||
KeyUpEvent();
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 键盘字符事件
|
||||
/// @brief 键盘字符事件
|
||||
class KGE_API KeyCharEvent : public KeyEvent
|
||||
{
|
||||
public:
|
||||
char value; ///< 字符
|
||||
char value; ///< 字符
|
||||
|
||||
KeyCharEvent();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -40,17 +40,17 @@ KGE_DECLARE_SMART_PTR(MouseWheelEvent);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 鼠标事件
|
||||
/// @brief 鼠标事件
|
||||
class KGE_API MouseEvent : public Event
|
||||
{
|
||||
public:
|
||||
Point pos; ///< 鼠标位置
|
||||
Point pos; ///< 鼠标位置
|
||||
|
||||
MouseEvent(EventType const& type);
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 鼠标移动事件
|
||||
/// @brief 鼠标移动事件
|
||||
class KGE_API MouseMoveEvent : public MouseEvent
|
||||
{
|
||||
public:
|
||||
|
|
@ -58,37 +58,37 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 鼠标按键按下事件
|
||||
/// @brief 鼠标按键按下事件
|
||||
class KGE_API MouseDownEvent : public MouseEvent
|
||||
{
|
||||
public:
|
||||
MouseButton button; ///< 鼠标键值
|
||||
MouseButton button; ///< 鼠标键值
|
||||
|
||||
MouseDownEvent();
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 鼠标按键抬起事件
|
||||
/// @brief 鼠标按键抬起事件
|
||||
class KGE_API MouseUpEvent : public MouseEvent
|
||||
{
|
||||
public:
|
||||
MouseButton button; ///< 鼠标键值
|
||||
MouseButton button; ///< 鼠标键值
|
||||
|
||||
MouseUpEvent();
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 鼠标点击事件
|
||||
/// @brief 鼠标点击事件
|
||||
class KGE_API MouseClickEvent : public MouseEvent
|
||||
{
|
||||
public:
|
||||
MouseButton button; ///< 鼠标键值
|
||||
MouseButton button; ///< 鼠标键值
|
||||
|
||||
MouseClickEvent();
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 鼠标移入事件
|
||||
/// @brief 鼠标移入事件
|
||||
class KGE_API MouseHoverEvent : public MouseEvent
|
||||
{
|
||||
public:
|
||||
|
|
@ -96,7 +96,7 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 鼠标移出事件
|
||||
/// @brief 鼠标移出事件
|
||||
class KGE_API MouseOutEvent : public MouseEvent
|
||||
{
|
||||
public:
|
||||
|
|
@ -104,11 +104,11 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 鼠标滚轮事件
|
||||
/// @brief 鼠标滚轮事件
|
||||
class KGE_API MouseWheelEvent : public MouseEvent
|
||||
{
|
||||
public:
|
||||
float wheel; ///< 滚轮值
|
||||
float wheel; ///< 滚轮值
|
||||
|
||||
MouseWheelEvent();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ KGE_DECLARE_SMART_PTR(WindowClosedEvent);
|
|||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 窗口事件
|
||||
/// @brief 窗口事件
|
||||
class KGE_API WindowEvent : public Event
|
||||
{
|
||||
public:
|
||||
|
|
@ -44,49 +44,49 @@ public:
|
|||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 窗口移动事件
|
||||
/// @brief 窗口移动事件
|
||||
class KGE_API WindowMovedEvent : public WindowEvent
|
||||
{
|
||||
public:
|
||||
int x; ///< 窗口左上角 x 坐标
|
||||
int y; ///< 窗口左上角 y 坐标
|
||||
int x; ///< 窗口左上角 x 坐标
|
||||
int y; ///< 窗口左上角 y 坐标
|
||||
|
||||
WindowMovedEvent();
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 窗口大小变化事件
|
||||
/// @brief 窗口大小变化事件
|
||||
class KGE_API WindowResizedEvent : public WindowEvent
|
||||
{
|
||||
public:
|
||||
uint32_t width; ///< 窗口宽度
|
||||
uint32_t height; ///< 窗口高度
|
||||
uint32_t width; ///< 窗口宽度
|
||||
uint32_t height; ///< 窗口高度
|
||||
|
||||
WindowResizedEvent();
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 窗口焦点变化事件
|
||||
/// @brief 窗口焦点变化事件
|
||||
class KGE_API WindowFocusChangedEvent : public WindowEvent
|
||||
{
|
||||
public:
|
||||
bool focus; ///< 是否获取到焦点
|
||||
bool focus; ///< 是否获取到焦点
|
||||
|
||||
WindowFocusChangedEvent();
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 窗口标题更改事件
|
||||
/// @brief 窗口标题更改事件
|
||||
class KGE_API WindowTitleChangedEvent : public WindowEvent
|
||||
{
|
||||
public:
|
||||
String title; ///< 标题
|
||||
String title; ///< 标题
|
||||
|
||||
WindowTitleChangedEvent();
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 窗口关闭事件
|
||||
/// @brief 窗口关闭事件
|
||||
class KGE_API WindowClosedEvent : public WindowEvent
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@
|
|||
#include <kiwano/render/ShapeSink.h>
|
||||
#include <kiwano/render/Texture.h>
|
||||
#include <kiwano/render/GifImage.h>
|
||||
#include <kiwano/render/LayerArea.h>
|
||||
#include <kiwano/render/Layer.h>
|
||||
#include <kiwano/render/TextLayout.h>
|
||||
#include <kiwano/render/TextureCache.h>
|
||||
#include <kiwano/render/Renderer.h>
|
||||
|
|
@ -86,7 +86,7 @@
|
|||
#include <kiwano/2d/Frame.h>
|
||||
#include <kiwano/2d/FrameSequence.h>
|
||||
#include <kiwano/2d/GifSprite.h>
|
||||
#include <kiwano/2d/Layer.h>
|
||||
#include <kiwano/2d/LayerActor.h>
|
||||
#include <kiwano/2d/ShapeActor.h>
|
||||
#include <kiwano/2d/Sprite.h>
|
||||
#include <kiwano/2d/Stage.h>
|
||||
|
|
|
|||
|
|
@ -21,28 +21,28 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error Kiwano only supports C++
|
||||
# error Kiwano only supports C++
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define KGE_WIN32
|
||||
#ifdef _WIN64
|
||||
#define KGE_WIN64
|
||||
#endif
|
||||
# define KGE_WIN32
|
||||
# ifdef _WIN64
|
||||
# define KGE_WIN64
|
||||
# endif
|
||||
#elif __ANDROID__
|
||||
#define KGE_ANDROID
|
||||
# define KGE_ANDROID
|
||||
#elif __linux__
|
||||
#define KGE_LINUX
|
||||
# define KGE_LINUX
|
||||
#elif __APPLE__
|
||||
#if TARGET_OS_IPHONE
|
||||
#define KGE_IPHONE
|
||||
#elif TARGET_OS_MAC
|
||||
#define KGE_MACOS
|
||||
# if TARGET_OS_IPHONE
|
||||
# define KGE_IPHONE
|
||||
# elif TARGET_OS_MAC
|
||||
# define KGE_MACOS
|
||||
# else
|
||||
# error "Unsupported Apple platform"
|
||||
# endif
|
||||
#else
|
||||
#error "Unsupported Apple platform"
|
||||
#endif
|
||||
#else
|
||||
#error "Unsupported compiler"
|
||||
# error "Unsupported compiler"
|
||||
#endif
|
||||
|
||||
// C++ RunTime Header Files
|
||||
|
|
@ -56,48 +56,48 @@
|
|||
#ifdef KGE_WIN32
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#error Kiwano only supports MSVC compiler
|
||||
# error Kiwano only supports MSVC compiler
|
||||
#endif
|
||||
|
||||
#ifndef KGE_VS_VER
|
||||
#define KGE_VS_VER _MSC_VER
|
||||
#define KGE_VS_2013 1800
|
||||
#define KGE_VS_2015 1900
|
||||
#define KGE_VS_2017 1900
|
||||
#define KGE_VS_2019 1920
|
||||
# define KGE_VS_VER _MSC_VER
|
||||
# define KGE_VS_2013 1800
|
||||
# define KGE_VS_2015 1900
|
||||
# define KGE_VS_2017 1900
|
||||
# define KGE_VS_2019 1920
|
||||
#endif
|
||||
|
||||
#if KGE_VS_VER < KGE_VS_2015
|
||||
#error Kiwano only supports Visual Studio 2015 and above
|
||||
# error Kiwano only supports Visual Studio 2015 and above
|
||||
#endif
|
||||
|
||||
#ifndef WINVER
|
||||
#define WINVER 0x0700 // Allow use of features specific to Windows 7 or later
|
||||
# define WINVER 0x0700 // Allow use of features specific to Windows 7 or later
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0700 // Allow use of features specific to Windows 7 or later
|
||||
# define _WIN32_WINNT 0x0700 // Allow use of features specific to Windows 7 or later
|
||||
#endif
|
||||
|
||||
#ifndef NTDDI_VERSION
|
||||
#define NTDDI_VERSION NTDDI_WIN7
|
||||
# define NTDDI_VERSION NTDDI_WIN7
|
||||
#endif
|
||||
|
||||
#ifndef UNICODE
|
||||
#define UNICODE
|
||||
# define UNICODE
|
||||
#endif
|
||||
|
||||
// Exclude rarely-used items from Windows headers
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
# define NOMINMAX
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG) || defined(_DEBUG)
|
||||
#define KGE_DEBUG
|
||||
# define KGE_DEBUG
|
||||
#endif
|
||||
|
||||
#define KGE_SUPPRESS_WARNING_PUSH __pragma(warning(push))
|
||||
|
|
@ -105,28 +105,28 @@
|
|||
#define KGE_SUPPRESS_WARNING_POP __pragma(warning(pop))
|
||||
|
||||
#ifndef KGE_ASSERT
|
||||
#ifdef KGE_DEBUG
|
||||
#define KGE_ASSERT(EXPR) \
|
||||
do \
|
||||
{ \
|
||||
(void)((!!(EXPR)) || (_wassert(_CRT_WIDE(#EXPR), _CRT_WIDE(__FUNCTION__), (unsigned)(__LINE__)), 0)); \
|
||||
} while (0)
|
||||
#else
|
||||
#define KGE_ASSERT __noop
|
||||
#endif
|
||||
# ifdef KGE_DEBUG
|
||||
# define KGE_ASSERT(EXPR) \
|
||||
do \
|
||||
{ \
|
||||
(void)((!!(EXPR)) || (_wassert(_CRT_WIDE(#EXPR), _CRT_WIDE(__FUNCTION__), (unsigned)(__LINE__)), 0)); \
|
||||
} while (0)
|
||||
# else
|
||||
# define KGE_ASSERT __noop
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef KGE_API
|
||||
#if defined(KGE_USE_DLL)
|
||||
#define KGE_API __declspec(dllimport)
|
||||
#elif defined(KGE_EXPORT_DLL)
|
||||
#define KGE_API __declspec(dllexport)
|
||||
#endif
|
||||
# if defined(KGE_USE_DLL)
|
||||
# define KGE_API __declspec(dllimport)
|
||||
# elif defined(KGE_EXPORT_DLL)
|
||||
# define KGE_API __declspec(dllexport)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef KGE_API
|
||||
/* Building or calling Kiwano as a static library */
|
||||
#define KGE_API
|
||||
# define KGE_API
|
||||
#else
|
||||
/*
|
||||
* C4251 can be ignored if you are deriving from a type in the
|
||||
|
|
@ -136,8 +136,6 @@
|
|||
KGE_SUPPRESS_WARNING(4251)
|
||||
#endif
|
||||
|
||||
#define KGE_NOT_USED(VAR) ((void)VAR)
|
||||
|
||||
#define KGE_DEPRECATED(...) __declspec(deprecated(__VA_ARGS__))
|
||||
|
||||
// Windows Header Files
|
||||
|
|
@ -145,3 +143,5 @@ KGE_SUPPRESS_WARNING(4251)
|
|||
#include <windows.h>
|
||||
|
||||
#endif // KGE_WIN32
|
||||
|
||||
#define KGE_NOT_USED(VAR) ((void)VAR)
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@ namespace kiwano
|
|||
namespace math
|
||||
{
|
||||
//
|
||||
// 随机数
|
||||
// 随机数
|
||||
//
|
||||
// 获取指定范围内的一个随机数, 如:
|
||||
// int n = math::Random(1, 5); // 获取 1~5 内的随机整数, 包含 1 和 5
|
||||
// 产生的随机数类型取决于参数的类型, 如获取随机浮点数:
|
||||
// 获取指定范围内的一个随机数, 如:
|
||||
// int n = math::Random(1, 5); // 获取 1~5 内的随机整数, 包含 1 和 5
|
||||
// 产生的随机数类型取决于参数的类型, 如获取随机浮点数:
|
||||
// float d = math::Random(1.2f, 1.5f);
|
||||
//
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue