[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
|
# Matches multiple files with brace expansion notation
|
||||||
# Set default charset
|
# Set default charset
|
||||||
[*.{h,hpp,cpp}]
|
[*.{h,hpp,cpp}]
|
||||||
charset = gb2312
|
charset = utf8
|
||||||
|
|
||||||
# 4 space indentation
|
# 4 space indentation
|
||||||
indent_style = space
|
indent_style = space
|
||||||
|
|
|
||||||
2
Doxyfile
2
Doxyfile
|
|
@ -32,7 +32,7 @@ SHOW_NAMESPACES = YES
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
INPUT = src/
|
INPUT = src/
|
||||||
INPUT_ENCODING = gb2312
|
INPUT_ENCODING = UTF-8
|
||||||
FILE_PATTERNS = *.c \
|
FILE_PATTERNS = *.c \
|
||||||
*.cc \
|
*.cc \
|
||||||
*.cxx \
|
*.cxx \
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@
|
||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||||
<MinimalRebuild>false</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|
@ -92,6 +93,7 @@
|
||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||||
<MinimalRebuild>false</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@
|
||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||||
<MinimalRebuild>false</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|
@ -91,6 +92,7 @@
|
||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||||
<MinimalRebuild>false</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@
|
||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||||
<MinimalRebuild>false</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|
@ -87,6 +88,7 @@
|
||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||||
<MinimalRebuild>false</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@
|
||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||||
<MinimalRebuild>false</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|
@ -97,6 +98,7 @@
|
||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||||
<MinimalRebuild>false</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\core\event\KeyEvent.h" />
|
<ClInclude Include="..\..\src\kiwano\core\event\KeyEvent.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\core\event\MouseEvent.h" />
|
<ClInclude Include="..\..\src\kiwano\core\event\MouseEvent.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\core\event\WindowEvent.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\Keys.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\core\Library.h" />
|
<ClInclude Include="..\..\src\kiwano\core\Library.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\core\Singleton.h" />
|
<ClInclude Include="..\..\src\kiwano\core\Singleton.h" />
|
||||||
|
|
@ -30,7 +31,7 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\DebugActor.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\DebugActor.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\FrameSequence.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\FrameSequence.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\ShapeActor.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\Actor.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\Stage.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\Stage.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\Sprite.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\ComPtr.hpp" />
|
||||||
<ClInclude Include="..\..\src\kiwano\platform\win32\helper.h" />
|
<ClInclude Include="..\..\src\kiwano\platform\win32\helper.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\platform\win32\libraries.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\platform\Window.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\Brush.h" />
|
<ClInclude Include="..\..\src\kiwano\render\Brush.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\Color.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\D3DDeviceResourcesBase.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\FontCollectionLoader.h" />
|
<ClInclude Include="..\..\src\kiwano\render\DirectX\FontCollectionLoader.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\helper.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\TextRenderer.h" />
|
||||||
|
<ClInclude Include="..\..\src\kiwano\render\DirectX\TextureRenderContextImpl.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\Font.h" />
|
<ClInclude Include="..\..\src\kiwano\render\Font.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\Shape.h" />
|
<ClInclude Include="..\..\src\kiwano\render\Shape.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\ShapeSink.h" />
|
<ClInclude Include="..\..\src\kiwano\render\ShapeSink.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\GifImage.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\RenderContext.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\Renderer.h" />
|
<ClInclude Include="..\..\src\kiwano\render\Renderer.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\StrokeStyle.h" />
|
<ClInclude Include="..\..\src\kiwano\render\StrokeStyle.h" />
|
||||||
|
|
@ -84,6 +89,7 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\render\TextStyle.hpp" />
|
<ClInclude Include="..\..\src\kiwano\render\TextStyle.hpp" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\Texture.h" />
|
<ClInclude Include="..\..\src\kiwano\render\Texture.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\render\TextureCache.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\LocalStorage.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\utils\ResourceCache.h" />
|
<ClInclude Include="..\..\src\kiwano\utils\ResourceCache.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\utils\UserData.h" />
|
<ClInclude Include="..\..\src\kiwano\utils\UserData.h" />
|
||||||
|
|
@ -103,7 +109,7 @@
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\FrameSequence.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\FrameSequence.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\ShapeActor.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\ShapeActor.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\GifSprite.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\Actor.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Stage.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\Stage.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Sprite.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\KeyEvent.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\core\event\MouseEvent.cpp" />
|
<ClCompile Include="..\..\src\kiwano\core\event\MouseEvent.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\core\event\WindowEvent.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\Library.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\core\Logger.cpp" />
|
<ClCompile Include="..\..\src\kiwano\core\Logger.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\core\ObjectBase.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\D3D10DeviceResources.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\D3D11DeviceResources.cpp" />
|
<ClCompile Include="..\..\src\kiwano\render\DirectX\D3D11DeviceResources.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\FontCollectionLoader.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\TextRenderer.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\kiwano\render\DirectX\TextureRenderContextImpl.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\Font.cpp" />
|
<ClCompile Include="..\..\src\kiwano\render\Font.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\Shape.cpp" />
|
<ClCompile Include="..\..\src\kiwano\render\Shape.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\ShapeSink.cpp" />
|
<ClCompile Include="..\..\src\kiwano\render\ShapeSink.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\GifImage.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\RenderContext.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\Renderer.cpp" />
|
<ClCompile Include="..\..\src\kiwano\render\Renderer.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\StrokeStyle.cpp" />
|
<ClCompile Include="..\..\src\kiwano\render\StrokeStyle.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\TextLayout.cpp" />
|
<ClCompile Include="..\..\src\kiwano\render\TextLayout.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\Texture.cpp" />
|
<ClCompile Include="..\..\src\kiwano\render\Texture.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\render\TextureCache.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\LocalStorage.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\utils\ResourceCache.cpp" />
|
<ClCompile Include="..\..\src\kiwano\utils\ResourceCache.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\utils\UserData.cpp" />
|
<ClCompile Include="..\..\src\kiwano\utils\UserData.cpp" />
|
||||||
|
|
@ -212,6 +223,7 @@
|
||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
<MinimalRebuild>false</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|
@ -230,6 +242,7 @@
|
||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
<MinimalRebuild>false</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,6 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\Canvas.h">
|
<ClInclude Include="..\..\src\kiwano\2d\Canvas.h">
|
||||||
<Filter>2d</Filter>
|
<Filter>2d</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\Layer.h">
|
|
||||||
<Filter>2d</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\Sprite.h">
|
<ClInclude Include="..\..\src\kiwano\2d\Sprite.h">
|
||||||
<Filter>2d</Filter>
|
<Filter>2d</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
@ -216,9 +213,6 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\render\GifImage.h">
|
<ClInclude Include="..\..\src\kiwano\render\GifImage.h">
|
||||||
<Filter>render</Filter>
|
<Filter>render</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\kiwano\render\LayerArea.h">
|
|
||||||
<Filter>render</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\kiwano\render\RenderContext.h">
|
<ClInclude Include="..\..\src\kiwano\render\RenderContext.h">
|
||||||
<Filter>render</Filter>
|
<Filter>render</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
@ -285,14 +279,35 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\math\Scalar.h">
|
<ClInclude Include="..\..\src\kiwano\math\Scalar.h">
|
||||||
<Filter>math</Filter>
|
<Filter>math</Filter>
|
||||||
</ClInclude>
|
</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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp">
|
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp">
|
||||||
<Filter>2d</Filter>
|
<Filter>2d</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Layer.cpp">
|
|
||||||
<Filter>2d</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Sprite.cpp">
|
<ClCompile Include="..\..\src\kiwano\2d\Sprite.cpp">
|
||||||
<Filter>2d</Filter>
|
<Filter>2d</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
@ -440,9 +455,6 @@
|
||||||
<ClCompile Include="..\..\src\kiwano\render\GifImage.cpp">
|
<ClCompile Include="..\..\src\kiwano\render\GifImage.cpp">
|
||||||
<Filter>render</Filter>
|
<Filter>render</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\kiwano\render\LayerArea.cpp">
|
|
||||||
<Filter>render</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\kiwano\render\RenderContext.cpp">
|
<ClCompile Include="..\..\src\kiwano\render\RenderContext.cpp">
|
||||||
<Filter>render</Filter>
|
<Filter>render</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
@ -482,5 +494,26 @@
|
||||||
<ClCompile Include="..\..\src\kiwano\render\ShapeSink.cpp">
|
<ClCompile Include="..\..\src\kiwano\render\ShapeSink.cpp">
|
||||||
<Filter>render</Filter>
|
<Filter>render</Filter>
|
||||||
</ClCompile>
|
</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>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -93,11 +93,11 @@ struct json_lexer
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
return scan_literal(L"true", token_type::LITERAL_TRUE);
|
return scan_literal("true", token_type::LITERAL_TRUE);
|
||||||
case 'f':
|
case 'f':
|
||||||
return scan_literal(L"false", token_type::LITERAL_FALSE);
|
return scan_literal("false", token_type::LITERAL_FALSE);
|
||||||
case 'n':
|
case 'n':
|
||||||
return scan_literal(L"null", token_type::LITERAL_NULL);
|
return scan_literal("null", token_type::LITERAL_NULL);
|
||||||
|
|
||||||
case '\"':
|
case '\"':
|
||||||
return scan_string();
|
return scan_string();
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ class vector
|
||||||
public:
|
public:
|
||||||
using value_type = _Ty;
|
using value_type = _Ty;
|
||||||
using size_type = size_t;
|
using size_type = size_t;
|
||||||
|
using difference_type = ptrdiff_t;
|
||||||
using reference = value_type&;
|
using reference = value_type&;
|
||||||
using const_reference = const value_type&;
|
using const_reference = const value_type&;
|
||||||
using iterator = value_type*;
|
using iterator = value_type*;
|
||||||
|
|
@ -70,6 +71,7 @@ public:
|
||||||
inline bool empty() const { return size_ == 0; }
|
inline bool empty() const { return size_ == 0; }
|
||||||
inline size_type size() const { return size_; }
|
inline size_type size() const { return size_; }
|
||||||
inline size_type size_in_bytes() const { return size_ * ((size_type)sizeof(_Ty)); }
|
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 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 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]; }
|
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
|
#define HEADER_PUGICONFIG_HPP
|
||||||
|
|
||||||
// Uncomment this to enable wchar_t mode
|
// Uncomment this to enable wchar_t mode
|
||||||
#define PUGIXML_WCHAR_MODE
|
// #define PUGIXML_WCHAR_MODE
|
||||||
|
|
||||||
// Uncomment this to enable compact mode
|
// Uncomment this to enable compact mode
|
||||||
// #define PUGIXML_COMPACT
|
// #define PUGIXML_COMPACT
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ AudioEngine::~AudioEngine() {}
|
||||||
|
|
||||||
void AudioEngine::SetupComponent()
|
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);
|
HRESULT hr = dlls::MediaFoundation::Get().MFStartup(MF_VERSION, MFSTARTUP_FULL);
|
||||||
|
|
||||||
|
|
@ -51,12 +51,12 @@ void AudioEngine::SetupComponent()
|
||||||
hr = x_audio2_->CreateMasteringVoice(&mastering_voice_);
|
hr = x_audio2_->CreateMasteringVoice(&mastering_voice_);
|
||||||
}
|
}
|
||||||
|
|
||||||
win32::ThrowIfFailed(hr);
|
win32::ThrowIfFailed(hr, "Create audio resources failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioEngine::DestroyComponent()
|
void AudioEngine::DestroyComponent()
|
||||||
{
|
{
|
||||||
KGE_SYS_LOG(L"Destroying audio resources");
|
KGE_SYS_LOG("Destroying audio resources");
|
||||||
|
|
||||||
if (mastering_voice_)
|
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);
|
return SUCCEEDED(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace audio
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* \defgroup Audio 音频引擎
|
* \defgroup Audio 音频引擎
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -42,7 +42,7 @@ namespace audio
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 音频引擎
|
* @brief 音频引擎
|
||||||
*/
|
*/
|
||||||
class KGE_API AudioEngine
|
class KGE_API AudioEngine
|
||||||
: public Singleton<AudioEngine>
|
: public Singleton<AudioEngine>
|
||||||
|
|
@ -52,15 +52,15 @@ class KGE_API AudioEngine
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 开启音频设备
|
/// @brief 开启音频设备
|
||||||
void Open();
|
void Open();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 关闭音频设备
|
/// @brief 关闭音频设备
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 从解码器数据缓冲中创建音频对象
|
/// @brief 从解码器数据缓冲中创建音频对象
|
||||||
bool CreateSound(Sound& sound, const Transcoder::Buffer& buffer);
|
bool CreateSound(Sound& sound, const Transcoder::Buffer& buffer);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,9 @@ Sound::~Sound()
|
||||||
|
|
||||||
bool Sound::Load(String const& file_path)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,16 +74,16 @@ bool Sound::Load(String const& file_path)
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
String full_path = FileSystem::Instance().GetFullPathForFile(file_path);
|
String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path);
|
||||||
|
|
||||||
HRESULT hr = transcoder_.LoadMediaFile(full_path);
|
HRESULT hr = transcoder_.LoadMediaFile(full_path);
|
||||||
if (FAILED(hr))
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AudioEngine::Instance().CreateSound(*this, transcoder_.GetBuffer()))
|
if (!AudioEngine::GetInstance().CreateSound(*this, transcoder_.GetBuffer()))
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -103,11 +103,11 @@ bool Sound::Load(Resource const& res)
|
||||||
HRESULT hr = transcoder_.LoadMediaResource(res);
|
HRESULT hr = transcoder_.LoadMediaResource(res);
|
||||||
if (FAILED(hr))
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AudioEngine::Instance().CreateSound(*this, transcoder_.GetBuffer()))
|
if (!AudioEngine::GetInstance().CreateSound(*this, transcoder_.GetBuffer()))
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -126,7 +126,7 @@ void Sound::Play(int loop_count)
|
||||||
{
|
{
|
||||||
if (!opened_)
|
if (!opened_)
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"Sound must be opened first!");
|
KGE_ERROR("Sound must be opened first!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,7 +157,7 @@ void Sound::Play(int loop_count)
|
||||||
|
|
||||||
if (FAILED(hr))
|
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);
|
playing_ = SUCCEEDED(hr);
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ KGE_DECLARE_SMART_PTR(Sound);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 音频对象
|
* @brief 音频对象
|
||||||
*/
|
*/
|
||||||
class KGE_API Sound : public virtual ObjectBase
|
class KGE_API Sound : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
|
|
@ -48,13 +48,13 @@ class KGE_API Sound : public virtual ObjectBase
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建音频对象
|
/// @brief 创建音频对象
|
||||||
/// @param res 本地音频文件路径
|
/// @param res 本地音频文件路径
|
||||||
static SoundPtr Create(String const& file_path);
|
static SoundPtr Create(String const& file_path);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建音频对象
|
/// @brief 创建音频对象
|
||||||
/// @param res 音频资源
|
/// @param res 音频资源
|
||||||
static SoundPtr Create(Resource const& res);
|
static SoundPtr Create(Resource const& res);
|
||||||
|
|
||||||
Sound();
|
Sound();
|
||||||
|
|
@ -62,51 +62,51 @@ public:
|
||||||
virtual ~Sound();
|
virtual ~Sound();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 打开本地音频文件
|
/// @brief 打开本地音频文件
|
||||||
/// @param res 本地音频文件路径
|
/// @param res 本地音频文件路径
|
||||||
bool Load(String const& file_path);
|
bool Load(String const& file_path);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 打开音频资源
|
/// @brief 打开音频资源
|
||||||
/// @param res 音频资源
|
/// @param res 音频资源
|
||||||
bool Load(Resource const& res);
|
bool Load(Resource const& res);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否有效
|
/// @brief 是否有效
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 播放
|
/// @brief 播放
|
||||||
/// @param loop_count 播放循环次数,设置 -1 为循环播放
|
/// @param loop_count 播放循环次数,设置 -1 为循环播放
|
||||||
void Play(int loop_count = 0);
|
void Play(int loop_count = 0);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 暂停
|
/// @brief 暂停
|
||||||
void Pause();
|
void Pause();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 继续
|
/// @brief 继续
|
||||||
void Resume();
|
void Resume();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 停止
|
/// @brief 停止
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 关闭并销毁资源
|
/// @brief 关闭并销毁资源
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否正在播放
|
/// @brief 是否正在播放
|
||||||
bool IsPlaying() const;
|
bool IsPlaying() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取音量
|
/// @brief 获取音量
|
||||||
float GetVolume() const;
|
float GetVolume() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置音量
|
/// @brief 设置音量
|
||||||
/// @param volume 音量大小,1.0 为原始音量, 大于 1 为放大音量, 0 为最小音量
|
/// @param volume 音量大小,1.0 为原始音量, 大于 1 为放大音量, 0 为最小音量
|
||||||
void SetVolume(float volume);
|
void SetVolume(float volume);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -35,13 +35,13 @@ KGE_DECLARE_SMART_PTR(SoundPlayer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 音频播放器
|
* @brief 音频播放器
|
||||||
*/
|
*/
|
||||||
class KGE_API SoundPlayer : public virtual ObjectBase
|
class KGE_API SoundPlayer : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建音频播放器
|
/// @brief 创建音频播放器
|
||||||
static SoundPlayerPtr Create();
|
static SoundPlayerPtr Create();
|
||||||
|
|
||||||
SoundPlayer();
|
SoundPlayer();
|
||||||
|
|
@ -49,66 +49,66 @@ public:
|
||||||
~SoundPlayer();
|
~SoundPlayer();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 加载本地音频文件
|
/// @brief 加载本地音频文件
|
||||||
/// @param file_path 本地音频文件路径
|
/// @param file_path 本地音频文件路径
|
||||||
/// @return 音频标识符
|
/// @return 音频标识符
|
||||||
size_t Load(String const& file_path);
|
size_t Load(String const& file_path);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 加载音频资源
|
/// @brief 加载音频资源
|
||||||
/// @param res 音频资源
|
/// @param res 音频资源
|
||||||
/// @return 音频标识符
|
/// @return 音频标识符
|
||||||
size_t Load(Resource const& res);
|
size_t Load(Resource const& res);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 播放音频
|
/// @brief 播放音频
|
||||||
/// @param id 音频标识符
|
/// @param id 音频标识符
|
||||||
/// @param loop_count 播放循环次数,设置 -1 为循环播放
|
/// @param loop_count 播放循环次数,设置 -1 为循环播放
|
||||||
void Play(size_t id, int loop_count = 0);
|
void Play(size_t id, int loop_count = 0);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 暂停音频
|
/// @brief 暂停音频
|
||||||
/// @param id 音频标识符
|
/// @param id 音频标识符
|
||||||
void Pause(size_t id);
|
void Pause(size_t id);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 继续播放音频
|
/// @brief 继续播放音频
|
||||||
/// @param id 音频标识符
|
/// @param id 音频标识符
|
||||||
void Resume(size_t id);
|
void Resume(size_t id);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 停止音频
|
/// @brief 停止音频
|
||||||
/// @param id 音频标识符
|
/// @param id 音频标识符
|
||||||
void Stop(size_t id);
|
void Stop(size_t id);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取音频播放状态
|
/// @brief 获取音频播放状态
|
||||||
/// @param id 音频标识符
|
/// @param id 音频标识符
|
||||||
bool IsPlaying(size_t id);
|
bool IsPlaying(size_t id);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取音量
|
/// @brief 获取音量
|
||||||
float GetVolume() const;
|
float GetVolume() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置音量
|
/// @brief 设置音量
|
||||||
/// @param volume 音量大小,1.0 为原始音量, 大于 1 为放大音量, 0 为最小音量
|
/// @param volume 音量大小,1.0 为原始音量, 大于 1 为放大音量, 0 为最小音量
|
||||||
void SetVolume(float volume);
|
void SetVolume(float volume);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 暂停所有音频
|
/// @brief 暂停所有音频
|
||||||
void PauseAll();
|
void PauseAll();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 继续播放所有音频
|
/// @brief 继续播放所有音频
|
||||||
void ResumeAll();
|
void ResumeAll();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 停止所有音频
|
/// @brief 停止所有音频
|
||||||
void StopAll();
|
void StopAll();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 清除缓存
|
/// @brief 清除缓存
|
||||||
void ClearCache();
|
void ClearCache();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ HRESULT Transcoder::LoadMediaFile(String const& file_path)
|
||||||
|
|
||||||
ComPtr<IMFSourceReader> reader;
|
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))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
|
|
@ -105,7 +105,7 @@ HRESULT Transcoder::LoadMediaResource(Resource const& res)
|
||||||
|
|
||||||
if (stream == nullptr)
|
if (stream == nullptr)
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"SHCreateMemStream failed");
|
KGE_ERROR("SHCreateMemStream failed");
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -147,25 +147,25 @@ HRESULT Transcoder::ReadSource(IMFSourceReader* reader)
|
||||||
hr = partial_type->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
|
hr = partial_type->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置 source reader 的媒体类型,它将使用合适的解码器去解码这个音频
|
// 设置 source reader 的媒体类型,它将使用合适的解码器去解码这个音频
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
hr = reader->SetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, partial_type.get());
|
hr = reader->SetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, partial_type.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从 IMFMediaType 中获取 WAVEFORMAT 结构
|
// 从 IMFMediaType 中获取 WAVEFORMAT 结构
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
hr = reader->GetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, &uncompressed_type);
|
hr = reader->GetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, &uncompressed_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 指定音频流
|
// 指定音频流
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
hr = reader->SetStreamSelection((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, true);
|
hr = reader->SetStreamSelection((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取 WAVEFORMAT 数据
|
// 获取 WAVEFORMAT 数据
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
|
|
@ -173,7 +173,7 @@ HRESULT Transcoder::ReadSource(IMFSourceReader* reader)
|
||||||
uncompressed_type.get(), &wave_format_, &size, (DWORD)MFWaveFormatExConvertFlag_Normal);
|
uncompressed_type.get(), &wave_format_, &size, (DWORD)MFWaveFormatExConvertFlag_Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 估算音频流大小
|
// 估算音频流大小
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
PROPVARIANT prop;
|
PROPVARIANT prop;
|
||||||
|
|
@ -186,7 +186,7 @@ HRESULT Transcoder::ReadSource(IMFSourceReader* reader)
|
||||||
PropVariantClear(&prop);
|
PropVariantClear(&prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取音频数据
|
// 读取音频数据
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
DWORD flags = 0;
|
DWORD flags = 0;
|
||||||
|
|
@ -198,7 +198,7 @@ HRESULT Transcoder::ReadSource(IMFSourceReader* reader)
|
||||||
|
|
||||||
if (data == nullptr)
|
if (data == nullptr)
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"Low memory");
|
KGE_ERROR("Low memory");
|
||||||
hr = E_OUTOFMEMORY;
|
hr = E_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class Sound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 音频解码器
|
* @brief 音频解码器
|
||||||
*/
|
*/
|
||||||
class KGE_API Transcoder
|
class KGE_API Transcoder
|
||||||
{
|
{
|
||||||
|
|
@ -46,13 +46,13 @@ class KGE_API Transcoder
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 音频数据缓冲
|
* @brief 音频数据缓冲
|
||||||
*/
|
*/
|
||||||
struct Buffer
|
struct Buffer
|
||||||
{
|
{
|
||||||
BYTE* data; ///< 音频数据
|
BYTE* data; ///< 音频数据
|
||||||
uint32_t size; ///< 音频数据大小
|
uint32_t size; ///< 音频数据大小
|
||||||
const WAVEFORMATEX* format; ///< 音频数据格式
|
const WAVEFORMATEX* format; ///< 音频数据格式
|
||||||
};
|
};
|
||||||
|
|
||||||
Transcoder();
|
Transcoder();
|
||||||
|
|
@ -60,24 +60,24 @@ public:
|
||||||
~Transcoder();
|
~Transcoder();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取数据缓冲
|
/// @brief 获取数据缓冲
|
||||||
Buffer GetBuffer() const;
|
Buffer GetBuffer() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 清空数据缓冲
|
/// @brief 清空数据缓冲
|
||||||
void ClearBuffer();
|
void ClearBuffer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 解码本地音频文件
|
/// @brief 解码本地音频文件
|
||||||
HRESULT LoadMediaFile(String const& file_path);
|
HRESULT LoadMediaFile(String const& file_path);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 解码音频资源
|
/// @brief 解码音频资源
|
||||||
HRESULT LoadMediaResource(Resource const& res);
|
HRESULT LoadMediaResource(Resource const& res);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 读取音频源数据
|
/// @brief 读取音频源数据
|
||||||
HRESULT ReadSource(IMFSourceReader* reader);
|
HRESULT ReadSource(IMFSourceReader* reader);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ XAudio2::XAudio2()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"Load xaudio2.dll failed");
|
KGE_ERROR("Load xaudio2.dll failed");
|
||||||
throw std::runtime_error("Load xaudio2.dll failed");
|
throw std::runtime_error("Load xaudio2.dll failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -79,7 +79,7 @@ MediaFoundation::MediaFoundation()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"Load Mfplat.dll failed");
|
KGE_ERROR("Load Mfplat.dll failed");
|
||||||
throw std::runtime_error("Load Mfplat.dll failed");
|
throw std::runtime_error("Load Mfplat.dll failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ MediaFoundation::MediaFoundation()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"Load Mfreadwrite.dll failed");
|
KGE_ERROR("Load Mfreadwrite.dll failed");
|
||||||
throw std::runtime_error("Load Mfreadwrite.dll failed");
|
throw std::runtime_error("Load Mfreadwrite.dll failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/2d/Layer.h>
|
#include <kiwano/2d/LayerActor.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
@ -28,24 +28,24 @@ namespace imgui
|
||||||
KGE_DECLARE_SMART_PTR(ImGuiLayer);
|
KGE_DECLARE_SMART_PTR(ImGuiLayer);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief ImGui管道
|
/// @brief ImGui管道
|
||||||
using ImGuiPipeline = Function<void()>;
|
using ImGuiPipeline = Function<void()>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief ImGui图层
|
* @brief ImGui图层
|
||||||
*/
|
*/
|
||||||
class ImGuiLayer : public Layer
|
class ImGuiLayer : public LayerActor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建ImGui图层
|
/// @brief 创建ImGui图层
|
||||||
static ImGuiLayerPtr Create();
|
static ImGuiLayerPtr Create();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建ImGui图层
|
/// @brief 创建ImGui图层
|
||||||
/// @param name 元素名称
|
/// @param name 元素名称
|
||||||
/// @param item 管道
|
/// @param item 管道
|
||||||
static ImGuiLayerPtr Create(String const& name, ImGuiPipeline const& item);
|
static ImGuiLayerPtr Create(String const& name, ImGuiPipeline const& item);
|
||||||
|
|
||||||
ImGuiLayer();
|
ImGuiLayer();
|
||||||
|
|
@ -53,19 +53,19 @@ public:
|
||||||
virtual ~ImGuiLayer();
|
virtual ~ImGuiLayer();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加 ImGui 元素
|
/// @brief 添加 ImGui 元素
|
||||||
/// @param name 元素名称
|
/// @param name 元素名称
|
||||||
/// @param item 管道
|
/// @param item 管道
|
||||||
void AddItem(String const& name, ImGuiPipeline const& item);
|
void AddItem(String const& name, ImGuiPipeline const& item);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除 ImGui 元素
|
/// @brief 移除 ImGui 元素
|
||||||
/// @param name 元素名称
|
/// @param name 元素名称
|
||||||
void RemoveItem(String const& name);
|
void RemoveItem(String const& name);
|
||||||
|
|
||||||
// 移除所有元素
|
// 移除所有元素
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除所有元素
|
/// @brief 移除所有元素
|
||||||
void RemoveAllItems();
|
void RemoveAllItems();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <kiwano/core/event/KeyEvent.h>
|
#include <kiwano/core/event/KeyEvent.h>
|
||||||
#include <kiwano/core/event/MouseEvent.h>
|
#include <kiwano/core/event/MouseEvent.h>
|
||||||
#include <kiwano/platform/Input.h>
|
#include <kiwano/platform/Input.h>
|
||||||
#include <kiwano/platform/Window.h>
|
#include <kiwano/platform/win32/WindowImpl.h>
|
||||||
#include <kiwano/render/Renderer.h>
|
#include <kiwano/render/Renderer.h>
|
||||||
#include <kiwano-imgui/ImGuiModule.h>
|
#include <kiwano-imgui/ImGuiModule.h>
|
||||||
#include <kiwano-imgui/imgui_impl.h>
|
#include <kiwano-imgui/imgui_impl.h>
|
||||||
|
|
@ -15,7 +15,6 @@ namespace kiwano
|
||||||
namespace imgui
|
namespace imgui
|
||||||
{
|
{
|
||||||
ImGuiModule::ImGuiModule()
|
ImGuiModule::ImGuiModule()
|
||||||
: target_window_(nullptr)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,13 +30,11 @@ void ImGuiModule::SetupComponent()
|
||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
|
|
||||||
// Setup Platform/Renderer bindings
|
// Setup Platform/Renderer bindings
|
||||||
target_window_ = Renderer::Instance().GetTargetWindow();
|
|
||||||
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
||||||
io.BackendFlags |=
|
io.BackendFlags |=
|
||||||
ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||||||
io.BackendPlatformName = "imgui_impl_win32";
|
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
|
// Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array that we will update during
|
||||||
// the application lifetime.
|
// the application lifetime.
|
||||||
|
|
@ -58,7 +55,7 @@ void ImGuiModule::SetupComponent()
|
||||||
io.KeyMap[ImGuiKey_Y] = (int)KeyCode::Y;
|
io.KeyMap[ImGuiKey_Y] = (int)KeyCode::Y;
|
||||||
io.KeyMap[ImGuiKey_Z] = (int)KeyCode::Z;
|
io.KeyMap[ImGuiKey_Z] = (int)KeyCode::Z;
|
||||||
|
|
||||||
ImGui_Impl_Init(Renderer::Instance());
|
ImGui_Impl_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiModule::DestroyComponent()
|
void ImGuiModule::DestroyComponent()
|
||||||
|
|
@ -75,10 +72,10 @@ void ImGuiModule::OnUpdate(Duration dt)
|
||||||
io.DeltaTime = dt.Seconds();
|
io.DeltaTime = dt.Seconds();
|
||||||
|
|
||||||
// Read keyboard modifiers inputs
|
// Read keyboard modifiers inputs
|
||||||
io.KeyCtrl = Input::Instance().IsDown(KeyCode::Ctrl);
|
io.KeyCtrl = Input::GetInstance().IsDown(KeyCode::Ctrl);
|
||||||
io.KeyShift = Input::Instance().IsDown(KeyCode::Shift);
|
io.KeyShift = Input::GetInstance().IsDown(KeyCode::Shift);
|
||||||
io.KeyAlt = Input::Instance().IsDown(KeyCode::Alt);
|
io.KeyAlt = Input::GetInstance().IsDown(KeyCode::Alt);
|
||||||
io.KeySuper = Input::Instance().IsDown(KeyCode::Super);
|
io.KeySuper = Input::GetInstance().IsDown(KeyCode::Super);
|
||||||
// io.KeysDown[], io.MousePos, io.MouseDown[], io.MouseWheel: filled by the HandleEvent function below.
|
// io.KeysDown[], io.MousePos, io.MouseDown[], io.MouseWheel: filled by the HandleEvent function below.
|
||||||
|
|
||||||
// Update OS mouse position
|
// Update OS mouse position
|
||||||
|
|
@ -96,7 +93,7 @@ void ImGuiModule::BeforeRender()
|
||||||
KGE_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built!");
|
KGE_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built!");
|
||||||
|
|
||||||
// Setup display size (every frame to accommodate for window resizing)
|
// 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);
|
io.DisplaySize = ImVec2(display_size.x, display_size.y);
|
||||||
|
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
@ -177,11 +174,11 @@ void ImGuiModule::UpdateMousePos()
|
||||||
if (io.WantSetMousePos)
|
if (io.WantSetMousePos)
|
||||||
{
|
{
|
||||||
POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y };
|
POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y };
|
||||||
::ClientToScreen(target_window_, &pos);
|
::ClientToScreen(WindowImpl::GetInstance().GetHandle(), &pos);
|
||||||
::SetCursorPos(pos.x, pos.y);
|
::SetCursorPos(pos.x, pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Point pos = Input::Instance().GetMousePos();
|
Point pos = Input::GetInstance().GetMousePos();
|
||||||
io.MousePos = ImVec2(pos.x, pos.y);
|
io.MousePos = ImVec2(pos.x, pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -219,7 +216,7 @@ void ImGuiModule::UpdateMouseCursor()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::Instance().SetCursor(cursor);
|
Window::GetInstance().SetCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace imgui
|
} // namespace imgui
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,10 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
namespace imgui
|
namespace imgui
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief ImGuiÄ£¿é
|
* @brief ImGui模块
|
||||||
*/
|
*/
|
||||||
class ImGuiModule
|
class ImGuiModule
|
||||||
: public Singleton<ImGuiModule>
|
: public Singleton<ImGuiModule>
|
||||||
|
|
@ -57,9 +58,7 @@ private:
|
||||||
void UpdateMousePos();
|
void UpdateMousePos();
|
||||||
|
|
||||||
void UpdateMouseCursor();
|
void UpdateMouseCursor();
|
||||||
|
|
||||||
private:
|
|
||||||
WindowHandle target_window_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace imgui
|
} // namespace imgui
|
||||||
} // namespace kiwano
|
} // namespace kiwano
|
||||||
|
|
|
||||||
|
|
@ -7,20 +7,25 @@
|
||||||
#if !defined(KGE_USE_DIRECTX10)
|
#if !defined(KGE_USE_DIRECTX10)
|
||||||
|
|
||||||
#include <kiwano-imgui/imgui_impl_dx11.h>
|
#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(),
|
return ImGui_ImplDX11_Init(renderer.GetD3DDeviceResources()->GetDevice(),
|
||||||
renderer.GetD3DDeviceResources()->GetDeviceContext());
|
renderer.GetD3DDeviceResources()->GetDeviceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ImGui_Impl_Shutdown()
|
inline void ImGui_Impl_Shutdown()
|
||||||
{
|
{
|
||||||
ImGui_ImplDX11_Shutdown();
|
ImGui_ImplDX11_Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ImGui_Impl_NewFrame()
|
inline void ImGui_Impl_NewFrame()
|
||||||
{
|
{
|
||||||
ImGui_ImplDX11_NewFrame();
|
ImGui_ImplDX11_NewFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ImGui_Impl_RenderDrawData(ImDrawData* draw_data)
|
inline void ImGui_Impl_RenderDrawData(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX11_RenderDrawData(draw_data);
|
ImGui_ImplDX11_RenderDrawData(draw_data);
|
||||||
|
|
@ -30,6 +35,7 @@ inline void ImGui_Impl_InvalidateDeviceObjects()
|
||||||
{
|
{
|
||||||
ImGui_ImplDX11_InvalidateDeviceObjects();
|
ImGui_ImplDX11_InvalidateDeviceObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool ImGui_Impl_CreateDeviceObjects()
|
inline bool ImGui_Impl_CreateDeviceObjects()
|
||||||
{
|
{
|
||||||
return ImGui_ImplDX11_CreateDeviceObjects();
|
return ImGui_ImplDX11_CreateDeviceObjects();
|
||||||
|
|
@ -39,18 +45,22 @@ inline bool ImGui_Impl_CreateDeviceObjects()
|
||||||
|
|
||||||
#include <kiwano-imgui/imgui_impl_dx10.h>
|
#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());
|
return ImGui_ImplDX10_Init(renderer.GetD3DDeviceResources()->GetDevice());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ImGui_Impl_Shutdown()
|
inline void ImGui_Impl_Shutdown()
|
||||||
{
|
{
|
||||||
ImGui_ImplDX10_Shutdown();
|
ImGui_ImplDX10_Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ImGui_Impl_NewFrame()
|
inline void ImGui_Impl_NewFrame()
|
||||||
{
|
{
|
||||||
ImGui_ImplDX10_NewFrame();
|
ImGui_ImplDX10_NewFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ImGui_Impl_RenderDrawData(ImDrawData* draw_data)
|
inline void ImGui_Impl_RenderDrawData(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX10_RenderDrawData(draw_data);
|
ImGui_ImplDX10_RenderDrawData(draw_data);
|
||||||
|
|
@ -60,6 +70,7 @@ inline void ImGui_Impl_InvalidateDeviceObjects()
|
||||||
{
|
{
|
||||||
ImGui_ImplDX10_InvalidateDeviceObjects();
|
ImGui_ImplDX10_InvalidateDeviceObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool ImGui_Impl_CreateDeviceObjects()
|
inline bool ImGui_Impl_CreateDeviceObjects()
|
||||||
{
|
{
|
||||||
return ImGui_ImplDX10_CreateDeviceObjects();
|
return ImGui_ImplDX10_CreateDeviceObjects();
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#include <codecvt>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <kiwano/core/Logger.h>
|
#include <kiwano/core/Logger.h>
|
||||||
#include <kiwano/platform/Application.h>
|
#include <kiwano/platform/Application.h>
|
||||||
|
|
@ -34,7 +33,7 @@ using namespace kiwano::network;
|
||||||
|
|
||||||
uint32_t write_data(void* buffer, uint32_t size, uint32_t nmemb, void* userp)
|
uint32_t write_data(void* buffer, uint32_t size, uint32_t nmemb, void* userp)
|
||||||
{
|
{
|
||||||
ByteString* recv_buffer = (ByteString*)userp;
|
String* recv_buffer = (String*)userp;
|
||||||
uint32_t total = size * nmemb;
|
uint32_t total = size * nmemb;
|
||||||
|
|
||||||
// add data to the end of recv_buffer
|
// add data to the end of recv_buffer
|
||||||
|
|
@ -44,40 +43,6 @@ uint32_t write_data(void* buffer, uint32_t size, uint32_t nmemb, void* userp)
|
||||||
return total;
|
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
|
class Curl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -102,8 +67,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Init(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url, ByteString* response_data,
|
bool Init(HttpClient* client, Vector<String> const& headers, String const& url, String* response_data,
|
||||||
ByteString* response_header, char* error_buffer)
|
String* response_header, char* error_buffer)
|
||||||
{
|
{
|
||||||
if (!SetOption(CURLOPT_ERRORBUFFER, error_buffer))
|
if (!SetOption(CURLOPT_ERRORBUFFER, error_buffer))
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -112,7 +77,7 @@ public:
|
||||||
if (!SetOption(CURLOPT_CONNECTTIMEOUT, client->GetTimeoutForConnect()))
|
if (!SetOption(CURLOPT_CONNECTTIMEOUT, client->GetTimeoutForConnect()))
|
||||||
return false;
|
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 (ssl_ca_file.empty())
|
||||||
{
|
{
|
||||||
if (!SetOption(CURLOPT_SSL_VERIFYPEER, 0L))
|
if (!SetOption(CURLOPT_SSL_VERIFYPEER, 0L))
|
||||||
|
|
@ -167,8 +132,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static inline bool GetRequest(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url,
|
static inline bool GetRequest(HttpClient* client, Vector<String> const& headers, String const& url,
|
||||||
long* response_code, ByteString* response_data, ByteString* response_header,
|
long* response_code, String* response_data, String* response_header,
|
||||||
char* error_buffer)
|
char* error_buffer)
|
||||||
{
|
{
|
||||||
Curl curl;
|
Curl curl;
|
||||||
|
|
@ -176,9 +141,9 @@ public:
|
||||||
&& curl.SetOption(CURLOPT_FOLLOWLOCATION, true) && curl.Perform(response_code);
|
&& curl.SetOption(CURLOPT_FOLLOWLOCATION, true) && curl.Perform(response_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool PostRequest(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url,
|
static inline bool PostRequest(HttpClient* client, Vector<String> const& headers, String const& url,
|
||||||
ByteString const& request_data, long* response_code, ByteString* response_data,
|
String const& request_data, long* response_code, String* response_data,
|
||||||
ByteString* response_header, char* error_buffer)
|
String* response_header, char* error_buffer)
|
||||||
{
|
{
|
||||||
Curl curl;
|
Curl curl;
|
||||||
return curl.Init(client, headers, url, response_data, response_header, error_buffer)
|
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);
|
&& curl.SetOption(CURLOPT_POSTFIELDSIZE, request_data.size()) && curl.Perform(response_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool PutRequest(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url,
|
static inline bool PutRequest(HttpClient* client, Vector<String> const& headers, String const& url,
|
||||||
ByteString const& request_data, long* response_code, ByteString* response_data,
|
String const& request_data, long* response_code, String* response_data,
|
||||||
ByteString* response_header, char* error_buffer)
|
String* response_header, char* error_buffer)
|
||||||
{
|
{
|
||||||
Curl curl;
|
Curl curl;
|
||||||
return curl.Init(client, headers, url, response_data, response_header, error_buffer)
|
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);
|
&& curl.SetOption(CURLOPT_POSTFIELDSIZE, request_data.size()) && curl.Perform(response_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool DeleteRequest(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url,
|
static inline bool DeleteRequest(HttpClient* client, Vector<String> const& headers, String const& url,
|
||||||
long* response_code, ByteString* response_data, ByteString* response_header,
|
long* response_code, String* response_data, String* response_header,
|
||||||
char* error_buffer)
|
char* error_buffer)
|
||||||
{
|
{
|
||||||
Curl curl;
|
Curl curl;
|
||||||
|
|
@ -279,17 +244,16 @@ void HttpClient::Perform(HttpRequestPtr request, HttpResponsePtr response)
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
long response_code = 0;
|
long response_code = 0;
|
||||||
char error_message[256] = { 0 };
|
char error_message[256] = { 0 };
|
||||||
ByteString response_header;
|
String response_header;
|
||||||
ByteString response_data;
|
String response_data;
|
||||||
|
String url = request->GetUrl();
|
||||||
|
String data = request->GetData();
|
||||||
|
|
||||||
ByteString url = convert_to_utf8(request->GetUrl());
|
Vector<String> headers;
|
||||||
ByteString data = convert_to_utf8(request->GetData());
|
|
||||||
|
|
||||||
Vector<ByteString> headers;
|
|
||||||
headers.reserve(request->GetHeaders().size());
|
headers.reserve(request->GetHeaders().size());
|
||||||
for (const auto& pair : request->GetHeaders())
|
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())
|
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);
|
ok = Curl::DeleteRequest(this, headers, url, &response_code, &response_data, &response_header, error_message);
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
response->SetResponseCode(response_code);
|
response->SetResponseCode(response_code);
|
||||||
response->SetHeader(MultiByteToWide(response_header));
|
response->SetHeader(response_header);
|
||||||
response->SetData(convert_from_utf8(response_data));
|
response->SetData(response_data);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
response->SetSucceed(false);
|
response->SetSucceed(false);
|
||||||
response->SetError(MultiByteToWide(error_message));
|
response->SetError(error_message);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace network
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* \defgroup Network 网络通信
|
* \defgroup Network 网络通信
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -40,7 +40,7 @@ namespace network
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief HTTP客户端
|
* @brief HTTP客户端
|
||||||
*/
|
*/
|
||||||
class KGE_API HttpClient
|
class KGE_API HttpClient
|
||||||
: public Singleton<HttpClient>
|
: public Singleton<HttpClient>
|
||||||
|
|
@ -50,33 +50,33 @@ class KGE_API HttpClient
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 发送HTTP请求
|
/// @brief 发送HTTP请求
|
||||||
/// @param[in] request HTTP请求
|
/// @param[in] request HTTP请求
|
||||||
/// @details 发送请求后,无论结束或失败都将调用请求的响应回调函数
|
/// @details 发送请求后,无论结束或失败都将调用请求的响应回调函数
|
||||||
void Send(HttpRequestPtr request);
|
void Send(HttpRequestPtr request);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置连接超时时长
|
/// @brief 设置连接超时时长
|
||||||
void SetTimeoutForConnect(Duration timeout);
|
void SetTimeoutForConnect(Duration timeout);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取连接超时时长
|
/// @brief 获取连接超时时长
|
||||||
Duration GetTimeoutForConnect() const;
|
Duration GetTimeoutForConnect() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置读取超时时长
|
/// @brief 设置读取超时时长
|
||||||
void SetTimeoutForRead(Duration timeout);
|
void SetTimeoutForRead(Duration timeout);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取读取超时时长
|
/// @brief 获取读取超时时长
|
||||||
Duration GetTimeoutForRead() const;
|
Duration GetTimeoutForRead() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置SSL证书地址
|
/// @brief 设置SSL证书地址
|
||||||
void SetSSLVerification(String const& root_certificate_path);
|
void SetSSLVerification(String const& root_certificate_path);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取SSL证书地址
|
/// @brief 获取SSL证书地址
|
||||||
String const& GetSSLVerification() const;
|
String const& GetSSLVerification() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ HttpRequestPtr HttpRequest::Create(String const& url, HttpType type, Json const&
|
||||||
|
|
||||||
void HttpRequest::SetJsonData(Json const& json)
|
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();
|
data_ = json.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,48 +37,48 @@ KGE_DECLARE_SMART_PTR(HttpRequest);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief HTTP请求类型
|
/// @brief HTTP请求类型
|
||||||
enum class HttpType
|
enum class HttpType
|
||||||
{
|
{
|
||||||
Unknown, ///< 未知
|
Unknown, ///< 未知
|
||||||
Get, ///< HTTP GET请求
|
Get, ///< HTTP GET请求
|
||||||
Post, ///< HTTP POST请求
|
Post, ///< HTTP POST请求
|
||||||
Put, ///< HTTP PUT请求
|
Put, ///< HTTP PUT请求
|
||||||
Delete ///< HTTP DELETE请求
|
Delete ///< HTTP DELETE请求
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief HTTP请求
|
* @brief HTTP请求
|
||||||
*/
|
*/
|
||||||
class KGE_API HttpRequest : public virtual ObjectBase
|
class KGE_API HttpRequest : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 响应回调函数
|
/// @brief 响应回调函数
|
||||||
using ResponseCallback = Function<void(HttpRequest* /* request */, HttpResponse* /* response */)>;
|
using ResponseCallback = Function<void(HttpRequest* /* request */, HttpResponse* /* response */)>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建HTTP请求
|
/// @brief 创建HTTP请求
|
||||||
/// @param url 请求地址
|
/// @param url 请求地址
|
||||||
/// @param type 请求类型
|
/// @param type 请求类型
|
||||||
/// @param callback 响应回调函数
|
/// @param callback 响应回调函数
|
||||||
static HttpRequestPtr Create(String const& url, HttpType type, ResponseCallback const& callback);
|
static HttpRequestPtr Create(String const& url, HttpType type, ResponseCallback const& callback);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建HTTP请求
|
/// @brief 创建HTTP请求
|
||||||
/// @param url 请求地址
|
/// @param url 请求地址
|
||||||
/// @param type 请求类型
|
/// @param type 请求类型
|
||||||
/// @param data 请求数据
|
/// @param data 请求数据
|
||||||
/// @param callback 响应回调函数
|
/// @param callback 响应回调函数
|
||||||
static HttpRequestPtr Create(String const& url, HttpType type, String const& data, ResponseCallback const& callback);
|
static HttpRequestPtr Create(String const& url, HttpType type, String const& data, ResponseCallback const& callback);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建HTTP请求
|
/// @brief 创建HTTP请求
|
||||||
/// @param url 请求地址
|
/// @param url 请求地址
|
||||||
/// @param type 请求类型
|
/// @param type 请求类型
|
||||||
/// @param json 请求的JSON数据
|
/// @param json 请求的JSON数据
|
||||||
/// @param callback 响应回调函数
|
/// @param callback 响应回调函数
|
||||||
static HttpRequestPtr Create(String const& url, HttpType type, Json const& json, ResponseCallback const& callback);
|
static HttpRequestPtr Create(String const& url, HttpType type, Json const& json, ResponseCallback const& callback);
|
||||||
|
|
||||||
HttpRequest();
|
HttpRequest();
|
||||||
|
|
@ -86,55 +86,55 @@ public:
|
||||||
HttpRequest(HttpType type);
|
HttpRequest(HttpType type);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置请求地址
|
/// @brief 设置请求地址
|
||||||
void SetUrl(String const& url);
|
void SetUrl(String const& url);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置请求类型
|
/// @brief 设置请求类型
|
||||||
void SetType(HttpType type);
|
void SetType(HttpType type);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置请求数据
|
/// @brief 设置请求数据
|
||||||
void SetData(String const& data);
|
void SetData(String const& data);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置请求的JSON数据
|
/// @brief 设置请求的JSON数据
|
||||||
void SetJsonData(Json const& json);
|
void SetJsonData(Json const& json);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置HTTP头
|
/// @brief 设置HTTP头
|
||||||
void SetHeaders(Map<String, String> const& headers);
|
void SetHeaders(Map<String, String> const& headers);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置HTTP头
|
/// @brief 设置HTTP头
|
||||||
void SetHeader(String const& field, String const& content);
|
void SetHeader(String const& field, String const& content);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置响应回调函数
|
/// @brief 设置响应回调函数
|
||||||
void SetResponseCallback(ResponseCallback const& callback);
|
void SetResponseCallback(ResponseCallback const& callback);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取请求地址
|
/// @brief 获取请求地址
|
||||||
String const& GetUrl() const;
|
String const& GetUrl() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取请求类型
|
/// @brief 获取请求类型
|
||||||
HttpType GetType() const;
|
HttpType GetType() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取请求数据
|
/// @brief 获取请求数据
|
||||||
String const& GetData() const;
|
String const& GetData() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取HTTP头
|
/// @brief 获取HTTP头
|
||||||
Map<String, String>& GetHeaders();
|
Map<String, String>& GetHeaders();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取HTTP头
|
/// @brief 获取HTTP头
|
||||||
String const& GetHeader(String const& header) const;
|
String const& GetHeader(String const& header) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取响应回调函数
|
/// @brief 获取响应回调函数
|
||||||
ResponseCallback const& GetResponseCallback() const;
|
ResponseCallback const& GetResponseCallback() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ KGE_DECLARE_SMART_PTR(HttpResponse);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief HTTP响应
|
* @brief HTTP响应
|
||||||
*/
|
*/
|
||||||
class KGE_API HttpResponse : public virtual ObjectBase
|
class KGE_API HttpResponse : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
|
|
@ -42,47 +42,47 @@ public:
|
||||||
HttpResponse(HttpRequestPtr request);
|
HttpResponse(HttpRequestPtr request);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取对应的HTTP请求
|
/// @brief 获取对应的HTTP请求
|
||||||
HttpRequestPtr GetRequest() const;
|
HttpRequestPtr GetRequest() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取响应状态
|
/// @brief 获取响应状态
|
||||||
bool IsSucceed() const;
|
bool IsSucceed() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取HTTP状态码
|
/// @brief 获取HTTP状态码
|
||||||
long GetResponseCode() const;
|
long GetResponseCode() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取响应头
|
/// @brief 获取响应头
|
||||||
String GetHeader() const;
|
String GetHeader() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取响应数据
|
/// @brief 获取响应数据
|
||||||
String const& GetData() const;
|
String const& GetData() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取错误信息
|
/// @brief 获取错误信息
|
||||||
String const& GetError() const;
|
String const& GetError() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置响应状态
|
/// @brief 设置响应状态
|
||||||
void SetSucceed(bool succeed);
|
void SetSucceed(bool succeed);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置HTTP状态码
|
/// @brief 设置HTTP状态码
|
||||||
void SetResponseCode(long response_code);
|
void SetResponseCode(long response_code);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置响应头
|
/// @brief 设置响应头
|
||||||
void SetHeader(String const& response_header);
|
void SetHeader(String const& response_header);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置响应数据
|
/// @brief 设置响应数据
|
||||||
void SetData(String const& response_data);
|
void SetData(String const& response_data);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置错误信息
|
/// @brief 设置错误信息
|
||||||
void SetError(String const& error_buffer);
|
void SetError(String const& error_buffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -37,31 +37,31 @@ KGE_DECLARE_SMART_PTR(Body);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物体
|
/// @brief 物体
|
||||||
class KGE_API Body : public virtual ObjectBase
|
class KGE_API Body : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物体类型
|
/// @brief 物体类型
|
||||||
enum class Type
|
enum class Type
|
||||||
{
|
{
|
||||||
Static = 0, ///< 静态物体
|
Static = 0, ///< 静态物体
|
||||||
Kinematic, ///< 动力学物体
|
Kinematic, ///< 动力学物体
|
||||||
Dynamic, ///< 动态物体
|
Dynamic, ///< 动态物体
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化
|
/// @brief 初始化
|
||||||
/// @param[in] world 物理世界
|
/// @param[in] world 物理世界
|
||||||
/// @param[in] actor 绑定的角色
|
/// @param[in] actor 绑定的角色
|
||||||
/// @param[in] type 物体类型
|
/// @param[in] type 物体类型
|
||||||
static BodyPtr Create(World* world, ActorPtr actor, Type type);
|
static BodyPtr Create(World* world, ActorPtr actor, Type type);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化
|
/// @brief 初始化
|
||||||
/// @param[in] world 物理世界
|
/// @param[in] world 物理世界
|
||||||
/// @param[in] actor 绑定的角色
|
/// @param[in] actor 绑定的角色
|
||||||
/// @param[in] type 物体类型
|
/// @param[in] type 物体类型
|
||||||
static BodyPtr Create(World* world, Actor* actor, Type type);
|
static BodyPtr Create(World* world, Actor* actor, Type type);
|
||||||
|
|
||||||
Body();
|
Body();
|
||||||
|
|
@ -69,250 +69,250 @@ public:
|
||||||
virtual ~Body();
|
virtual ~Body();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化
|
/// @brief 初始化
|
||||||
/// @param[in] world 物理世界
|
/// @param[in] world 物理世界
|
||||||
/// @param[in] actor 绑定的角色
|
/// @param[in] actor 绑定的角色
|
||||||
bool InitBody(World* world, ActorPtr actor);
|
bool InitBody(World* world, ActorPtr actor);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化
|
/// @brief 初始化
|
||||||
/// @param[in] world 物理世界
|
/// @param[in] world 物理世界
|
||||||
/// @param[in] actor 绑定的角色
|
/// @param[in] actor 绑定的角色
|
||||||
bool InitBody(World* world, Actor* actor);
|
bool InitBody(World* world, Actor* actor);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加夹具
|
/// @brief 添加夹具
|
||||||
void AddFixture(FixturePtr fixture);
|
void AddFixture(FixturePtr fixture);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加圆形夹具
|
/// @brief 添加圆形夹具
|
||||||
/// @param radius 圆形半径
|
/// @param radius 圆形半径
|
||||||
/// @param density 物体密度
|
/// @param density 物体密度
|
||||||
/// @param
|
/// @param
|
||||||
Fixture* AddCircleShape(float radius, float density, float friction = 0.2f, float restitution = 0.f,
|
Fixture* AddCircleShape(float radius, float density, float friction = 0.2f, float restitution = 0.f,
|
||||||
bool is_sensor = false);
|
bool is_sensor = false);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加矩形夹具
|
/// @brief 添加矩形夹具
|
||||||
/// @param size 矩形大小
|
/// @param size 矩形大小
|
||||||
/// @param density 物体密度
|
/// @param density 物体密度
|
||||||
Fixture* AddRectShape(Vec2 const& size, float density, float friction = 0.2f, float restitution = 0.f,
|
Fixture* AddRectShape(Vec2 const& size, float density, float friction = 0.2f, float restitution = 0.f,
|
||||||
bool is_sensor = false);
|
bool is_sensor = false);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加多边形夹具
|
/// @brief 添加多边形夹具
|
||||||
/// @param vertexs 多边形端点
|
/// @param vertexs 多边形端点
|
||||||
/// @param density 物体密度
|
/// @param density 物体密度
|
||||||
Fixture* AddPolygonShape(Vector<Point> const& vertexs, float density, float friction = 0.2f,
|
Fixture* AddPolygonShape(Vector<Point> const& vertexs, float density, float friction = 0.2f,
|
||||||
float restitution = 0.f, bool is_sensor = false);
|
float restitution = 0.f, bool is_sensor = false);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加线段形夹具
|
/// @brief 添加线段形夹具
|
||||||
/// @param p1 线段起点
|
/// @param p1 线段起点
|
||||||
/// @param p2 线段终点
|
/// @param p2 线段终点
|
||||||
/// @param density 物体密度
|
/// @param density 物体密度
|
||||||
Fixture* AddEdgeShape(Point const& p1, Point const& p2, float density, float friction = 0.2f,
|
Fixture* AddEdgeShape(Point const& p1, Point const& p2, float density, float friction = 0.2f,
|
||||||
float restitution = 0.f, bool is_sensor = false);
|
float restitution = 0.f, bool is_sensor = false);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加链条形夹具
|
/// @brief 添加链条形夹具
|
||||||
/// @param vertexs 链条端点
|
/// @param vertexs 链条端点
|
||||||
/// @param loop 是否闭合
|
/// @param loop 是否闭合
|
||||||
/// @param density 物体密度
|
/// @param density 物体密度
|
||||||
Fixture* AddChainShape(Vector<Point> const& vertexs, bool loop, float density, float friction = 0.2f,
|
Fixture* AddChainShape(Vector<Point> const& vertexs, bool loop, float density, float friction = 0.2f,
|
||||||
float restitution = 0.f, bool is_sensor = false);
|
float restitution = 0.f, bool is_sensor = false);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除夹具
|
/// @brief 移除夹具
|
||||||
void RemoveFixture(FixturePtr fixture);
|
void RemoveFixture(FixturePtr fixture);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取夹具列表
|
/// @brief 获取夹具列表
|
||||||
FixtureList GetFixtureList() const;
|
FixtureList GetFixtureList() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取接触边列表
|
/// @brief 获取接触边列表
|
||||||
ContactEdgeList GetContactList() const;
|
ContactEdgeList GetContactList() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取类别码
|
/// @brief 获取类别码
|
||||||
uint16_t GetCategoryBits() const;
|
uint16_t GetCategoryBits() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置类别码
|
/// @brief 设置类别码
|
||||||
void SetCategoryBits(uint16_t category_bits);
|
void SetCategoryBits(uint16_t category_bits);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取碰撞掩码
|
/// @brief 获取碰撞掩码
|
||||||
uint16_t GetMaskBits() const;
|
uint16_t GetMaskBits() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置碰撞掩码
|
/// @brief 设置碰撞掩码
|
||||||
void SetMaskBits(uint16_t mask_bits);
|
void SetMaskBits(uint16_t mask_bits);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取组索引
|
/// @brief 获取组索引
|
||||||
int16_t GetGroupIndex() const;
|
int16_t GetGroupIndex() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置组索引
|
/// @brief 设置组索引
|
||||||
void SetGroupIndex(int16_t index);
|
void SetGroupIndex(int16_t index);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取旋转角度
|
/// @brief 获取旋转角度
|
||||||
float GetBodyRotation() const;
|
float GetBodyRotation() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置旋转角度
|
/// @brief 设置旋转角度
|
||||||
void SetBodyRotation(float angle);
|
void SetBodyRotation(float angle);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体位置
|
/// @brief 获取物体位置
|
||||||
Point GetBodyPosition() const;
|
Point GetBodyPosition() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置物体位置
|
/// @brief 设置物体位置
|
||||||
void SetBodyPosition(Point const& pos);
|
void SetBodyPosition(Point const& pos);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 位置和旋转变换
|
/// @brief 位置和旋转变换
|
||||||
void SetBodyTransform(Point const& pos, float angle);
|
void SetBodyTransform(Point const& pos, float angle);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取质量 [kg]
|
/// @brief 获取质量 [kg]
|
||||||
float GetMass() const;
|
float GetMass() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取惯性
|
/// @brief 获取惯性
|
||||||
float GetInertia() const;
|
float GetInertia() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取质量数据
|
/// @brief 获取质量数据
|
||||||
/// @param[out] mass 物体质量 [kg]
|
/// @param[out] mass 物体质量 [kg]
|
||||||
/// @param[out] center 质心位置
|
/// @param[out] center 质心位置
|
||||||
/// @param[out] inertia 惯性
|
/// @param[out] inertia 惯性
|
||||||
void GetMassData(float* mass, Point* center, float* inertia) const;
|
void GetMassData(float* mass, Point* center, float* inertia) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置质量数据
|
/// @brief 设置质量数据
|
||||||
/// @param mass 物体质量 [kg]
|
/// @param mass 物体质量 [kg]
|
||||||
/// @param center 质心位置
|
/// @param center 质心位置
|
||||||
/// @param inertia 惯性
|
/// @param inertia 惯性
|
||||||
void SetMassData(float mass, Point const& center, float inertia);
|
void SetMassData(float mass, Point const& center, float inertia);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 重置质量数据
|
/// @brief 重置质量数据
|
||||||
void ResetMassData();
|
void ResetMassData();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取世界坐标系上的点在物体上的位置
|
/// @brief 获取世界坐标系上的点在物体上的位置
|
||||||
Point GetLocalPoint(Point const& world) const;
|
Point GetLocalPoint(Point const& world) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体上的点在世界坐标系的位置
|
/// @brief 获取物体上的点在世界坐标系的位置
|
||||||
Point GetWorldPoint(Point const& local) const;
|
Point GetWorldPoint(Point const& local) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体质心相对于物体的位置
|
/// @brief 获取物体质心相对于物体的位置
|
||||||
Point GetLocalCenter() const;
|
Point GetLocalCenter() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体质心位置
|
/// @brief 获取物体质心位置
|
||||||
Point GetWorldCenter() const;
|
Point GetWorldCenter() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体类型
|
/// @brief 获取物体类型
|
||||||
Type GetType() const;
|
Type GetType() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置物体类型
|
/// @brief 设置物体类型
|
||||||
void SetType(Type type);
|
void SetType(Type type);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体受重力的比例
|
/// @brief 获取物体受重力的比例
|
||||||
float GetGravityScale() const;
|
float GetGravityScale() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置物体受重力的比例
|
/// @brief 设置物体受重力的比例
|
||||||
void SetGravityScale(float scale);
|
void SetGravityScale(float scale);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 施力
|
/// @brief 施力
|
||||||
/// @param force 力的大小和方向
|
/// @param force 力的大小和方向
|
||||||
/// @param point 施力点
|
/// @param point 施力点
|
||||||
/// @param wake 是否唤醒物体
|
/// @param wake 是否唤醒物体
|
||||||
void ApplyForce(Vec2 const& force, Point const& point, bool wake = true);
|
void ApplyForce(Vec2 const& force, Point const& point, bool wake = true);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 给物体中心施力
|
/// @brief 给物体中心施力
|
||||||
/// @param force 力的大小和方向
|
/// @param force 力的大小和方向
|
||||||
/// @param wake 是否唤醒物体
|
/// @param wake 是否唤醒物体
|
||||||
void ApplyForceToCenter(Vec2 const& force, bool wake = true);
|
void ApplyForceToCenter(Vec2 const& force, bool wake = true);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 施加扭矩
|
/// @brief 施加扭矩
|
||||||
/// @param torque 扭矩
|
/// @param torque 扭矩
|
||||||
/// @param wake 是否唤醒物体
|
/// @param wake 是否唤醒物体
|
||||||
void ApplyTorque(float torque, bool wake = false);
|
void ApplyTorque(float torque, bool wake = false);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 旋转角度是否固定
|
/// @brief 旋转角度是否固定
|
||||||
bool IsIgnoreRotation() const;
|
bool IsIgnoreRotation() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置是否固定旋转角度
|
/// @brief 设置是否固定旋转角度
|
||||||
void SetIgnoreRotation(bool flag);
|
void SetIgnoreRotation(bool flag);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否是子弹物体
|
/// @brief 是否是子弹物体
|
||||||
bool IsBullet() const;
|
bool IsBullet() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置物体是否是子弹物体
|
/// @brief 设置物体是否是子弹物体
|
||||||
void SetBullet(bool flag);
|
void SetBullet(bool flag);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否处于唤醒状态
|
/// @brief 是否处于唤醒状态
|
||||||
bool IsAwake() const;
|
bool IsAwake() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置唤醒状态
|
/// @brief 设置唤醒状态
|
||||||
void SetAwake(bool flag);
|
void SetAwake(bool flag);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否启用休眠
|
/// @brief 是否启用休眠
|
||||||
bool IsSleepingAllowed() const;
|
bool IsSleepingAllowed() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置是否允许休眠
|
/// @brief 设置是否允许休眠
|
||||||
void SetSleepingAllowed(bool flag);
|
void SetSleepingAllowed(bool flag);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否启用
|
/// @brief 是否启用
|
||||||
bool IsActive() const;
|
bool IsActive() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置启用状态
|
/// @brief 设置启用状态
|
||||||
void SetActive(bool flag);
|
void SetActive(bool flag);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体所在物理世界
|
/// @brief 获取物体所在物理世界
|
||||||
World* GetWorld() const;
|
World* GetWorld() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体绑定的角色
|
/// @brief 获取物体绑定的角色
|
||||||
Actor* GetActor() const;
|
Actor* GetActor() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置物体绑定的角色
|
/// @brief 设置物体绑定的角色
|
||||||
void SetActor(Actor* actor);
|
void SetActor(Actor* actor);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 将物体信息更新到角色
|
/// @brief 将物体信息更新到角色
|
||||||
void UpdateActor();
|
void UpdateActor();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 将角色信息更新到物体
|
/// @brief 将角色信息更新到物体
|
||||||
void UpdateFromActor();
|
void UpdateFromActor();
|
||||||
|
|
||||||
b2Body* GetB2Body() const;
|
b2Body* GetB2Body() const;
|
||||||
|
|
@ -320,11 +320,11 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 销毁物体
|
/// @brief 销毁物体
|
||||||
void UpdateFixtureFilter(b2Fixture* fixture);
|
void UpdateFixtureFilter(b2Fixture* fixture);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 销毁物体
|
/// @brief 销毁物体
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -34,74 +34,74 @@ class Body;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物理接触
|
/// @brief 物理接触
|
||||||
class KGE_API Contact
|
class KGE_API Contact
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Contact();
|
Contact();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否有效
|
/// @brief 是否有效
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否是接触
|
/// @brief 是否是接触
|
||||||
bool IsTouching() const;
|
bool IsTouching() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 启用或禁用 (仅作用于一个时间步)
|
/// @brief 启用或禁用 (仅作用于一个时间步)
|
||||||
void SetEnabled(bool flag);
|
void SetEnabled(bool flag);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否启用
|
/// @brief 是否启用
|
||||||
bool IsEnabled() const;
|
bool IsEnabled() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体A的夹具
|
/// @brief 获取物体A的夹具
|
||||||
Fixture* GetFixtureA() const;
|
Fixture* GetFixtureA() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体B的夹具
|
/// @brief 获取物体B的夹具
|
||||||
Fixture* GetFixtureB() const;
|
Fixture* GetFixtureB() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体A
|
/// @brief 获取物体A
|
||||||
Body* GetBodyA() const;
|
Body* GetBodyA() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体B
|
/// @brief 获取物体B
|
||||||
Body* GetBodyB() const;
|
Body* GetBodyB() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置摩擦力
|
/// @brief 设置摩擦力
|
||||||
void SetFriction(float friction);
|
void SetFriction(float friction);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取摩擦力
|
/// @brief 获取摩擦力
|
||||||
float GetFriction() const;
|
float GetFriction() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 重置摩擦力
|
/// @brief 重置摩擦力
|
||||||
void ResetFriction();
|
void ResetFriction();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置弹性恢复
|
/// @brief 设置弹性恢复
|
||||||
void SetRestitution(float restitution);
|
void SetRestitution(float restitution);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取弹性恢复
|
/// @brief 获取弹性恢复
|
||||||
float GetRestitution() const;
|
float GetRestitution() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 重置弹性恢复
|
/// @brief 重置弹性恢复
|
||||||
void ResetRestitution();
|
void ResetRestitution();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置切线速度
|
/// @brief 设置切线速度
|
||||||
void SetTangentSpeed(float speed);
|
void SetTangentSpeed(float speed);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取切线速度
|
/// @brief 获取切线速度
|
||||||
float GetTangentSpeed() const;
|
float GetTangentSpeed() const;
|
||||||
|
|
||||||
b2Contact* GetB2Contact() const;
|
b2Contact* GetB2Contact() const;
|
||||||
|
|
@ -116,7 +116,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物理接触列表
|
/// @brief 物理接触列表
|
||||||
class ContactList
|
class ContactList
|
||||||
{
|
{
|
||||||
template <typename _Ty>
|
template <typename _Ty>
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace physics
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 接触边
|
/// @brief 接触边
|
||||||
class KGE_API ContactEdge
|
class KGE_API ContactEdge
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -40,15 +40,15 @@ public:
|
||||||
ContactEdge(b2ContactEdge* edge);
|
ContactEdge(b2ContactEdge* edge);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否有效
|
/// @brief 是否有效
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取接触物体
|
/// @brief 获取接触物体
|
||||||
Body* GetOtherBody() const;
|
Body* GetOtherBody() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取接触
|
/// @brief 获取接触
|
||||||
Contact GetContact() const;
|
Contact GetContact() const;
|
||||||
|
|
||||||
b2ContactEdge* GetB2ContactEdge() const;
|
b2ContactEdge* GetB2ContactEdge() const;
|
||||||
|
|
@ -63,7 +63,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物理接触边列表
|
/// @brief 物理接触边列表
|
||||||
class ContactEdgeList
|
class ContactEdgeList
|
||||||
{
|
{
|
||||||
template <typename _Ty>
|
template <typename _Ty>
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,11 @@ KGE_DECLARE_SMART_PTR(ContactEndEvent);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物理接触开始事件
|
/// @brief 物理接触开始事件
|
||||||
class KGE_API ContactBeginEvent : public Event
|
class KGE_API ContactBeginEvent : public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Contact contact; ///< 产生的接触
|
Contact contact; ///< 产生的接触
|
||||||
|
|
||||||
ContactBeginEvent();
|
ContactBeginEvent();
|
||||||
|
|
||||||
|
|
@ -47,11 +47,11 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物理接触结束事件
|
/// @brief 物理接触结束事件
|
||||||
class KGE_API ContactEndEvent : public Event
|
class KGE_API ContactEndEvent : public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Contact contact; ///< 产生的接触
|
Contact contact; ///< 产生的接触
|
||||||
|
|
||||||
ContactEndEvent();
|
ContactEndEvent();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,18 +35,18 @@ KGE_DECLARE_SMART_PTR(Fixture);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物理夹具
|
/// @brief 物理夹具
|
||||||
class Fixture : public virtual ObjectBase
|
class Fixture : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 夹具参数
|
/// @brief 夹具参数
|
||||||
struct Param
|
struct Param
|
||||||
{
|
{
|
||||||
float density = 0.0f; ///< 密度
|
float density = 0.0f; ///< 密度
|
||||||
float friction = 0.2f; ///< 摩擦力
|
float friction = 0.2f; ///< 摩擦力
|
||||||
float restitution = 0.0f; ///< 弹性恢复
|
float restitution = 0.0f; ///< 弹性恢复
|
||||||
bool is_sensor = false; ///< 是否是接触传感器
|
bool is_sensor = false; ///< 是否是接触传感器
|
||||||
|
|
||||||
Param() {}
|
Param() {}
|
||||||
|
|
||||||
|
|
@ -60,44 +60,44 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建圆形夹具
|
/// @brief 创建圆形夹具
|
||||||
/// @param body 添加夹具的物体
|
/// @param body 添加夹具的物体
|
||||||
/// @param param 夹具参数
|
/// @param param 夹具参数
|
||||||
/// @param radius 圆形半径
|
/// @param radius 圆形半径
|
||||||
/// @param offset 偏移量
|
/// @param offset 偏移量
|
||||||
static FixturePtr CreateCircle(Body* body, Param const& param, float radius, Point const& offset = Point());
|
static FixturePtr CreateCircle(Body* body, Param const& param, float radius, Point const& offset = Point());
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建矩形夹具
|
/// @brief 创建矩形夹具
|
||||||
/// @param body 添加夹具的物体
|
/// @param body 添加夹具的物体
|
||||||
/// @param param 夹具参数
|
/// @param param 夹具参数
|
||||||
/// @param size 矩形大小
|
/// @param size 矩形大小
|
||||||
/// @param offset 偏移量
|
/// @param offset 偏移量
|
||||||
/// @param rotation 旋转角度
|
/// @param rotation 旋转角度
|
||||||
static FixturePtr CreateRect(Body* body, Param const& param, Size const& size, Point const& offset = Point(),
|
static FixturePtr CreateRect(Body* body, Param const& param, Size const& size, Point const& offset = Point(),
|
||||||
float rotation = 0.f);
|
float rotation = 0.f);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建多边形夹具
|
/// @brief 创建多边形夹具
|
||||||
/// @param body 添加夹具的物体
|
/// @param body 添加夹具的物体
|
||||||
/// @param param 夹具参数
|
/// @param param 夹具参数
|
||||||
/// @param vertexs 多边形顶点
|
/// @param vertexs 多边形顶点
|
||||||
static FixturePtr CreatePolygon(Body* body, Param const& param, Vector<Point> const& vertexs);
|
static FixturePtr CreatePolygon(Body* body, Param const& param, Vector<Point> const& vertexs);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建边夹具
|
/// @brief 创建边夹具
|
||||||
/// @param body 添加夹具的物体
|
/// @param body 添加夹具的物体
|
||||||
/// @param param 夹具参数
|
/// @param param 夹具参数
|
||||||
/// @param p1 边的起点
|
/// @param p1 边的起点
|
||||||
/// @param p2 边的终点
|
/// @param p2 边的终点
|
||||||
static FixturePtr CreateEdge(Body* body, Param const& param, Point const& p1, Point const& p2);
|
static FixturePtr CreateEdge(Body* body, Param const& param, Point const& p1, Point const& p2);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建链条夹具
|
/// @brief 创建链条夹具
|
||||||
/// @param body 添加夹具的物体
|
/// @param body 添加夹具的物体
|
||||||
/// @param param 夹具参数
|
/// @param param 夹具参数
|
||||||
/// @param vertexs 链条顶点
|
/// @param vertexs 链条顶点
|
||||||
/// @param loop 是否连接链条的起点和终点
|
/// @param loop 是否连接链条的起点和终点
|
||||||
static FixturePtr CreateChain(Body* body, Param const& param, Vector<Point> const& vertexs, bool loop = false);
|
static FixturePtr CreateChain(Body* body, Param const& param, Vector<Point> const& vertexs, bool loop = false);
|
||||||
|
|
||||||
Fixture();
|
Fixture();
|
||||||
|
|
@ -105,52 +105,52 @@ public:
|
||||||
virtual ~Fixture();
|
virtual ~Fixture();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否有效
|
/// @brief 是否有效
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取夹具所在的物体
|
/// @brief 获取夹具所在的物体
|
||||||
Body* GetBody() const;
|
Body* GetBody() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否是接触传感器
|
/// @brief 是否是接触传感器
|
||||||
bool IsSensor() const;
|
bool IsSensor() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置夹具是否是接触传感器
|
/// @brief 设置夹具是否是接触传感器
|
||||||
/// @details 接触传感器只会产生物理接触,而不会影响物体运动
|
/// @details 接触传感器只会产生物理接触,而不会影响物体运动
|
||||||
void SetSensor(bool sensor);
|
void SetSensor(bool sensor);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取夹具的质量数据
|
/// @brief 获取夹具的质量数据
|
||||||
void GetMassData(float* mass, Point* center, float* inertia) const;
|
void GetMassData(float* mass, Point* center, float* inertia) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取密度
|
/// @brief 获取密度
|
||||||
float GetDensity() const;
|
float GetDensity() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置密度
|
/// @brief 设置密度
|
||||||
void SetDensity(float density);
|
void SetDensity(float density);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取摩擦力 [N]
|
/// @brief 获取摩擦力 [N]
|
||||||
float GetFriction() const;
|
float GetFriction() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置摩擦力 [N]
|
/// @brief 设置摩擦力 [N]
|
||||||
void SetFriction(float friction);
|
void SetFriction(float friction);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取弹性恢复
|
/// @brief 获取弹性恢复
|
||||||
float GetRestitution() const;
|
float GetRestitution() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置弹性恢复
|
/// @brief 设置弹性恢复
|
||||||
void SetRestitution(float restitution);
|
void SetRestitution(float restitution);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 点测试
|
/// @brief 点测试
|
||||||
bool TestPoint(const Point& p) const;
|
bool TestPoint(const Point& p) const;
|
||||||
|
|
||||||
b2Fixture* GetB2Fixture() const;
|
b2Fixture* GetB2Fixture() const;
|
||||||
|
|
@ -165,7 +165,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物理夹具列表
|
/// @brief 物理夹具列表
|
||||||
class FixtureList
|
class FixtureList
|
||||||
{
|
{
|
||||||
template <typename _Ty>
|
template <typename _Ty>
|
||||||
|
|
|
||||||
|
|
@ -45,34 +45,34 @@ KGE_DECLARE_SMART_PTR(WheelJoint);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 关节
|
/// @brief 关节
|
||||||
class KGE_API Joint : public virtual ObjectBase
|
class KGE_API Joint : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 关节类型
|
/// @brief 关节类型
|
||||||
enum class Type
|
enum class Type
|
||||||
{
|
{
|
||||||
Unknown = 0, ///< 未知
|
Unknown = 0, ///< 未知
|
||||||
Revolute, ///< 旋转关节
|
Revolute, ///< 旋转关节
|
||||||
Prismatic, ///< 平移关节
|
Prismatic, ///< 平移关节
|
||||||
Distance, ///< 固定距离关节
|
Distance, ///< 固定距离关节
|
||||||
Pulley, ///< 滑轮关节
|
Pulley, ///< 滑轮关节
|
||||||
Mouse, ///< 鼠标关节
|
Mouse, ///< 鼠标关节
|
||||||
Gear, ///< 齿轮关节
|
Gear, ///< 齿轮关节
|
||||||
Wheel, ///< 轮关节
|
Wheel, ///< 轮关节
|
||||||
Weld, ///< 焊接关节
|
Weld, ///< 焊接关节
|
||||||
Friction, ///< 摩擦关节
|
Friction, ///< 摩擦关节
|
||||||
Rope, ///< 绳关节
|
Rope, ///< 绳关节
|
||||||
Motor ///< 马达关节
|
Motor ///< 马达关节
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 关节基础参数
|
/// @brief 关节基础参数
|
||||||
struct ParamBase
|
struct ParamBase
|
||||||
{
|
{
|
||||||
Body* body_a; ///< 关节连接的物体A
|
Body* body_a; ///< 关节连接的物体A
|
||||||
Body* body_b; ///< 关节连接的物体B
|
Body* body_b; ///< 关节连接的物体B
|
||||||
|
|
||||||
ParamBase(Body* body_a, Body* body_b)
|
ParamBase(Body* body_a, Body* body_b)
|
||||||
: body_a(body_a)
|
: body_a(body_a)
|
||||||
|
|
@ -92,23 +92,23 @@ public:
|
||||||
virtual ~Joint();
|
virtual ~Joint();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化关节
|
/// @brief 初始化关节
|
||||||
bool InitJoint(World* world, b2JointDef* joint_def);
|
bool InitJoint(World* world, b2JointDef* joint_def);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节连接的物体A
|
/// @brief 获取关节连接的物体A
|
||||||
BodyPtr GetBodyA() const;
|
BodyPtr GetBodyA() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节连接的物体B
|
/// @brief 获取关节连接的物体B
|
||||||
BodyPtr GetBodyB() const;
|
BodyPtr GetBodyB() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物理世界
|
/// @brief 获取物理世界
|
||||||
World* GetWorld() const;
|
World* GetWorld() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 销毁关节
|
/// @brief 销毁关节
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
b2Joint* GetB2Joint() const;
|
b2Joint* GetB2Joint() const;
|
||||||
|
|
@ -121,18 +121,18 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 固定距离关节
|
/// @brief 固定距离关节
|
||||||
class KGE_API DistanceJoint : public Joint
|
class KGE_API DistanceJoint : public Joint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 固定距离关节参数
|
/// @brief 固定距离关节参数
|
||||||
struct Param : public Joint::ParamBase
|
struct Param : public Joint::ParamBase
|
||||||
{
|
{
|
||||||
Point anchor_a; ///< 关节在物体A上的连接点
|
Point anchor_a; ///< 关节在物体A上的连接点
|
||||||
Point anchor_b; ///< 关节在物体B上的连接点
|
Point anchor_b; ///< 关节在物体B上的连接点
|
||||||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||||
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
||||||
|
|
||||||
Param(Body* body_a, Body* body_b, Point const& anchor_a, Point const& anchor_b, float frequency_hz = 0.f,
|
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)
|
float damping_ratio = 0.f)
|
||||||
|
|
@ -152,39 +152,39 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建固定距离关节
|
/// @brief 创建固定距离关节
|
||||||
/// @param world 物理世界
|
/// @param world 物理世界
|
||||||
/// @param param 关节参数
|
/// @param param 关节参数
|
||||||
static DistanceJointPtr Create(World* world, Param const& param);
|
static DistanceJointPtr Create(World* world, Param const& param);
|
||||||
|
|
||||||
DistanceJoint();
|
DistanceJoint();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化关节
|
/// @brief 初始化关节
|
||||||
bool InitJoint(World* world, Param const& param);
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置关节长度
|
/// @brief 设置关节长度
|
||||||
void SetLength(float length);
|
void SetLength(float length);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节长度
|
/// @brief 获取关节长度
|
||||||
float GetLength() const;
|
float GetLength() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置弹簧响应速度 [赫兹]
|
/// @brief 设置弹簧响应速度 [赫兹]
|
||||||
void SetFrequency(float hz);
|
void SetFrequency(float hz);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取弹簧响应速度 [赫兹]
|
/// @brief 获取弹簧响应速度 [赫兹]
|
||||||
float GetFrequency() const;
|
float GetFrequency() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置阻尼率
|
/// @brief 设置阻尼率
|
||||||
void SetDampingRatio(float ratio);
|
void SetDampingRatio(float ratio);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取阻尼率
|
/// @brief 获取阻尼率
|
||||||
float GetDampingRatio() const;
|
float GetDampingRatio() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -192,15 +192,15 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 摩擦关节
|
/// @brief 摩擦关节
|
||||||
class KGE_API FrictionJoint : public Joint
|
class KGE_API FrictionJoint : public Joint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct Param : public Joint::ParamBase
|
struct Param : public Joint::ParamBase
|
||||||
{
|
{
|
||||||
Point anchor; ///< 摩擦作用点
|
Point anchor; ///< 摩擦作用点
|
||||||
float max_force; ///< 最大摩擦力
|
float max_force; ///< 最大摩擦力
|
||||||
float max_torque; ///< 最大扭力
|
float max_torque; ///< 最大扭力
|
||||||
|
|
||||||
Param(Body* body_a, Body* body_b, Point const& anchor, float max_force = 0.f, float max_torque = 0.f)
|
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)
|
: ParamBase(body_a, body_b)
|
||||||
|
|
@ -217,31 +217,31 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建摩擦关节
|
/// @brief 创建摩擦关节
|
||||||
/// @param world 物理世界
|
/// @param world 物理世界
|
||||||
/// @param param 关节参数
|
/// @param param 关节参数
|
||||||
static FrictionJointPtr Create(World* world, Param const& param);
|
static FrictionJointPtr Create(World* world, Param const& param);
|
||||||
|
|
||||||
FrictionJoint();
|
FrictionJoint();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化关节
|
/// @brief 初始化关节
|
||||||
bool InitJoint(World* world, Param const& param);
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置最大摩擦力
|
/// @brief 设置最大摩擦力
|
||||||
void SetMaxForce(float force);
|
void SetMaxForce(float force);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取最大摩擦力
|
/// @brief 获取最大摩擦力
|
||||||
float GetMaxForce() const;
|
float GetMaxForce() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置最大转矩
|
/// @brief 设置最大转矩
|
||||||
void SetMaxTorque(float torque);
|
void SetMaxTorque(float torque);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取最大转矩
|
/// @brief 获取最大转矩
|
||||||
float GetMaxTorque() const;
|
float GetMaxTorque() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -249,17 +249,17 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 齿轮关节
|
/// @brief 齿轮关节
|
||||||
class KGE_API GearJoint : public Joint
|
class KGE_API GearJoint : public Joint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 齿轮关节参数
|
/// @brief 齿轮关节参数
|
||||||
struct Param : public Joint::ParamBase
|
struct Param : public Joint::ParamBase
|
||||||
{
|
{
|
||||||
Joint* joint_a; ///< 关节A(旋转关节/平移关节)
|
Joint* joint_a; ///< 关节A(旋转关节/平移关节)
|
||||||
Joint* joint_b; ///< 关节B(旋转关节/平移关节)
|
Joint* joint_b; ///< 关节B(旋转关节/平移关节)
|
||||||
float ratio; ///< 齿轮传动比
|
float ratio; ///< 齿轮传动比
|
||||||
|
|
||||||
Param(Joint* joint_a, Joint* joint_b, float ratio = 1.f)
|
Param(Joint* joint_a, Joint* joint_b, float ratio = 1.f)
|
||||||
: ParamBase(nullptr, nullptr)
|
: ParamBase(nullptr, nullptr)
|
||||||
|
|
@ -276,23 +276,23 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建齿轮关节
|
/// @brief 创建齿轮关节
|
||||||
/// @param world 物理世界
|
/// @param world 物理世界
|
||||||
/// @param param 关节参数
|
/// @param param 关节参数
|
||||||
static GearJointPtr Create(World* world, Param const& param);
|
static GearJointPtr Create(World* world, Param const& param);
|
||||||
|
|
||||||
GearJoint();
|
GearJoint();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化关节
|
/// @brief 初始化关节
|
||||||
bool InitJoint(World* world, Param const& param);
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设定齿轮传动比
|
/// @brief 设定齿轮传动比
|
||||||
void SetRatio(float ratio);
|
void SetRatio(float ratio);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取齿轮传动比
|
/// @brief 获取齿轮传动比
|
||||||
float GetRatio() const;
|
float GetRatio() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -300,17 +300,17 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 马达关节
|
/// @brief 马达关节
|
||||||
class KGE_API MotorJoint : public Joint
|
class KGE_API MotorJoint : public Joint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 马达关节参数
|
/// @brief 马达关节参数
|
||||||
struct Param : public Joint::ParamBase
|
struct Param : public Joint::ParamBase
|
||||||
{
|
{
|
||||||
float max_force; ///< 最大摩擦力
|
float max_force; ///< 最大摩擦力
|
||||||
float max_torque; ///< 最大转矩
|
float max_torque; ///< 最大转矩
|
||||||
float correction_factor; ///< 位置矫正因子(范围 0-1)
|
float correction_factor; ///< 位置矫正因子(范围 0-1)
|
||||||
|
|
||||||
Param(Body* body_a, Body* body_b, float max_force = 1.f, float max_torque = 100.f,
|
Param(Body* body_a, Body* body_b, float max_force = 1.f, float max_torque = 100.f,
|
||||||
float correction_factor = 0.3f)
|
float correction_factor = 0.3f)
|
||||||
|
|
@ -329,31 +329,31 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建马达关节
|
/// @brief 创建马达关节
|
||||||
/// @param world 物理世界
|
/// @param world 物理世界
|
||||||
/// @param param 关节参数
|
/// @param param 关节参数
|
||||||
static MotorJointPtr Create(World* world, Param const& param);
|
static MotorJointPtr Create(World* world, Param const& param);
|
||||||
|
|
||||||
MotorJoint();
|
MotorJoint();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化关节
|
/// @brief 初始化关节
|
||||||
bool InitJoint(World* world, Param const& param);
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置最大摩擦力
|
/// @brief 设置最大摩擦力
|
||||||
void SetMaxForce(float force);
|
void SetMaxForce(float force);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取最大摩擦力
|
/// @brief 获取最大摩擦力
|
||||||
float GetMaxForce() const;
|
float GetMaxForce() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置最大转矩
|
/// @brief 设置最大转矩
|
||||||
void SetMaxTorque(float torque);
|
void SetMaxTorque(float torque);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取最大转矩
|
/// @brief 获取最大转矩
|
||||||
float GetMaxTorque() const;
|
float GetMaxTorque() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -361,22 +361,22 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 平移关节
|
/// @brief 平移关节
|
||||||
class KGE_API PrismaticJoint : public Joint
|
class KGE_API PrismaticJoint : public Joint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 平移关节参数
|
/// @brief 平移关节参数
|
||||||
struct Param : public Joint::ParamBase
|
struct Param : public Joint::ParamBase
|
||||||
{
|
{
|
||||||
Point anchor; ///< 关节位置
|
Point anchor; ///< 关节位置
|
||||||
Vec2 axis; ///< 物体A滑动的方向
|
Vec2 axis; ///< 物体A滑动的方向
|
||||||
bool enable_limit; ///< 是否启用限制
|
bool enable_limit; ///< 是否启用限制
|
||||||
float lower_translation; ///< 移动的最小限制,与方向同向为正,反向为负,启用限制后才有效果
|
float lower_translation; ///< 移动的最小限制,与方向同向为正,反向为负,启用限制后才有效果
|
||||||
float upper_translation; ///< 移动的最大限制,与方向同向为正,反向为负,启用限制后才有效果
|
float upper_translation; ///< 移动的最大限制,与方向同向为正,反向为负,启用限制后才有效果
|
||||||
bool enable_motor; ///< 是否启用马达
|
bool enable_motor; ///< 是否启用马达
|
||||||
float max_motor_force; ///< 最大马达力 [N]
|
float max_motor_force; ///< 最大马达力 [N]
|
||||||
float motor_speed; ///< 马达转速 [degree/s]
|
float motor_speed; ///< 马达转速 [degree/s]
|
||||||
|
|
||||||
Param(Body* body_a, Body* body_b, Point const& anchor, Vec2 const& axis, bool enable_limit = false,
|
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,
|
float lower_translation = 0.0f, float upper_translation = 0.0f, bool enable_motor = false,
|
||||||
|
|
@ -403,71 +403,71 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建平移关节
|
/// @brief 创建平移关节
|
||||||
/// @param world 物理世界
|
/// @param world 物理世界
|
||||||
/// @param param 关节参数
|
/// @param param 关节参数
|
||||||
static PrismaticJointPtr Create(World* world, Param const& param);
|
static PrismaticJointPtr Create(World* world, Param const& param);
|
||||||
|
|
||||||
PrismaticJoint();
|
PrismaticJoint();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化关节
|
/// @brief 初始化关节
|
||||||
bool InitJoint(World* world, Param const& param);
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取参考角
|
/// @brief 获取参考角
|
||||||
float GetReferenceAngle() const;
|
float GetReferenceAngle() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节转换
|
/// @brief 获取关节转换
|
||||||
float GetJointTranslation() const;
|
float GetJointTranslation() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节速度
|
/// @brief 获取关节速度
|
||||||
float GetJointSpeed() const;
|
float GetJointSpeed() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否启用关节限制
|
/// @brief 是否启用关节限制
|
||||||
bool IsLimitEnabled() const;
|
bool IsLimitEnabled() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置是否启用关节限制
|
/// @brief 设置是否启用关节限制
|
||||||
void EnableLimit(bool flag);
|
void EnableLimit(bool flag);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取平移最小限制
|
/// @brief 获取平移最小限制
|
||||||
float GetLowerLimit() const;
|
float GetLowerLimit() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取平移最大限制
|
/// @brief 获取平移最大限制
|
||||||
float GetUpperLimit() const;
|
float GetUpperLimit() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置关节限制
|
/// @brief 设置关节限制
|
||||||
void SetLimits(float lower, float upper);
|
void SetLimits(float lower, float upper);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否启用马达
|
/// @brief 是否启用马达
|
||||||
bool IsMotorEnabled() const;
|
bool IsMotorEnabled() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置是否启用马达
|
/// @brief 设置是否启用马达
|
||||||
void EnableMotor(bool flag);
|
void EnableMotor(bool flag);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置马达转速 [degree/s]
|
/// @brief 设置马达转速 [degree/s]
|
||||||
void SetMotorSpeed(float speed);
|
void SetMotorSpeed(float speed);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取马达转速 [degree/s]
|
/// @brief 获取马达转速 [degree/s]
|
||||||
float GetMotorSpeed() const;
|
float GetMotorSpeed() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置最大马达力 [N]
|
/// @brief 设置最大马达力 [N]
|
||||||
void SetMaxMotorForce(float force);
|
void SetMaxMotorForce(float force);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取最大马达力 [N]
|
/// @brief 获取最大马达力 [N]
|
||||||
float GetMaxMotorForce() const;
|
float GetMaxMotorForce() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -475,19 +475,19 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 滑轮关节
|
/// @brief 滑轮关节
|
||||||
class KGE_API PulleyJoint : public Joint
|
class KGE_API PulleyJoint : public Joint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 滑轮关节参数
|
/// @brief 滑轮关节参数
|
||||||
struct Param : public Joint::ParamBase
|
struct Param : public Joint::ParamBase
|
||||||
{
|
{
|
||||||
Point anchor_a; ///< 关节在物体A上的作用点
|
Point anchor_a; ///< 关节在物体A上的作用点
|
||||||
Point anchor_b; ///< 关节在物体B上的作用点
|
Point anchor_b; ///< 关节在物体B上的作用点
|
||||||
Point ground_anchor_a; ///< 物体A对应的滑轮的位置
|
Point ground_anchor_a; ///< 物体A对应的滑轮的位置
|
||||||
Point ground_anchor_b; ///< 物体B对应的滑轮的位置
|
Point ground_anchor_b; ///< 物体B对应的滑轮的位置
|
||||||
float ratio; ///< 滑轮比,关节传动时,滑轮上升和下降的两头的位移比例
|
float ratio; ///< 滑轮比,关节传动时,滑轮上升和下降的两头的位移比例
|
||||||
|
|
||||||
Param(Body* body_a, Body* body_b, Point const& anchor_a, Point const& anchor_b, Point const& ground_anchor_a,
|
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)
|
Point const& ground_anchor_b, float ratio = 1.0f)
|
||||||
|
|
@ -508,43 +508,43 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建滑轮关节
|
/// @brief 创建滑轮关节
|
||||||
/// @param world 物理世界
|
/// @param world 物理世界
|
||||||
/// @param param 关节参数
|
/// @param param 关节参数
|
||||||
static PulleyJointPtr Create(World* world, Param const& param);
|
static PulleyJointPtr Create(World* world, Param const& param);
|
||||||
|
|
||||||
PulleyJoint();
|
PulleyJoint();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化关节
|
/// @brief 初始化关节
|
||||||
bool InitJoint(World* world, Param const& param);
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物体A对应的滑轮的位置
|
/// @brief 物体A对应的滑轮的位置
|
||||||
Point GetGroundAnchorA() const;
|
Point GetGroundAnchorA() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物体B对应的滑轮的位置
|
/// @brief 物体B对应的滑轮的位置
|
||||||
Point GetGroundAnchorB() const;
|
Point GetGroundAnchorB() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取滑轮传动比
|
/// @brief 获取滑轮传动比
|
||||||
float GetRatio() const;
|
float GetRatio() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体A与滑轮的距离
|
/// @brief 获取物体A与滑轮的距离
|
||||||
float GetLengthA() const;
|
float GetLengthA() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体B与滑轮的距离
|
/// @brief 获取物体B与滑轮的距离
|
||||||
float GetLengthB() const;
|
float GetLengthB() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体A与滑轮的当前距离
|
/// @brief 获取物体A与滑轮的当前距离
|
||||||
float GetCurrentLengthA() const;
|
float GetCurrentLengthA() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体B与滑轮的当前距离
|
/// @brief 获取物体B与滑轮的当前距离
|
||||||
float GetCurrentLengthB() const;
|
float GetCurrentLengthB() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -552,21 +552,21 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 旋转关节
|
/// @brief 旋转关节
|
||||||
class KGE_API RevoluteJoint : public Joint
|
class KGE_API RevoluteJoint : public Joint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 旋转关节参数
|
/// @brief 旋转关节参数
|
||||||
struct Param : public Joint::ParamBase
|
struct Param : public Joint::ParamBase
|
||||||
{
|
{
|
||||||
Point anchor; ///< 关节位置
|
Point anchor; ///< 关节位置
|
||||||
bool enable_limit; ///< 是否启用限制
|
bool enable_limit; ///< 是否启用限制
|
||||||
float lower_angle; ///< 移动的最小限制,与方向同向为正,反向为负,启用限制后才有效果
|
float lower_angle; ///< 移动的最小限制,与方向同向为正,反向为负,启用限制后才有效果
|
||||||
float upper_angle; ///< 移动的最大限制,与方向同向为正,反向为负,启用限制后才有效果
|
float upper_angle; ///< 移动的最大限制,与方向同向为正,反向为负,启用限制后才有效果
|
||||||
bool enable_motor; ///< 是否启用马达
|
bool enable_motor; ///< 是否启用马达
|
||||||
float max_motor_torque; ///< 最大马达力 [N]
|
float max_motor_torque; ///< 最大马达力 [N]
|
||||||
float motor_speed; ///< 马达转速 [degree/s]
|
float motor_speed; ///< 马达转速 [degree/s]
|
||||||
|
|
||||||
Param(Body* body_a, Body* body_b, Point const& anchor, bool enable_limit = false, float lower_angle = 0.0f,
|
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,
|
float upper_angle = 0.0f, bool enable_motor = false, float max_motor_torque = 0.0f,
|
||||||
|
|
@ -592,71 +592,71 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建旋转关节
|
/// @brief 创建旋转关节
|
||||||
/// @param world 物理世界
|
/// @param world 物理世界
|
||||||
/// @param param 关节参数
|
/// @param param 关节参数
|
||||||
static RevoluteJointPtr Create(World* world, Param const& param);
|
static RevoluteJointPtr Create(World* world, Param const& param);
|
||||||
|
|
||||||
RevoluteJoint();
|
RevoluteJoint();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化关节
|
/// @brief 初始化关节
|
||||||
bool InitJoint(World* world, Param const& param);
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取参考角
|
/// @brief 获取参考角
|
||||||
float GetReferenceAngle() const;
|
float GetReferenceAngle() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节角度
|
/// @brief 获取关节角度
|
||||||
float GetJointAngle() const;
|
float GetJointAngle() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节速度
|
/// @brief 获取关节速度
|
||||||
float GetJointSpeed() const;
|
float GetJointSpeed() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否启用关节限制
|
/// @brief 是否启用关节限制
|
||||||
bool IsLimitEnabled() const;
|
bool IsLimitEnabled() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置是否启用关节限制
|
/// @brief 设置是否启用关节限制
|
||||||
void EnableLimit(bool flag);
|
void EnableLimit(bool flag);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取平移最小限制
|
/// @brief 获取平移最小限制
|
||||||
float GetLowerLimit() const;
|
float GetLowerLimit() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取平移最大限制
|
/// @brief 获取平移最大限制
|
||||||
float GetUpperLimit() const;
|
float GetUpperLimit() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置关节限制
|
/// @brief 设置关节限制
|
||||||
void SetLimits(float lower, float upper);
|
void SetLimits(float lower, float upper);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否启用马达
|
/// @brief 是否启用马达
|
||||||
bool IsMotorEnabled() const;
|
bool IsMotorEnabled() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置是否启用马达
|
/// @brief 设置是否启用马达
|
||||||
void EnableMotor(bool flag);
|
void EnableMotor(bool flag);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置马达转速 [degree/s]
|
/// @brief 设置马达转速 [degree/s]
|
||||||
void SetMotorSpeed(float speed);
|
void SetMotorSpeed(float speed);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取马达转速 [degree/s]
|
/// @brief 获取马达转速 [degree/s]
|
||||||
float GetMotorSpeed() const;
|
float GetMotorSpeed() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置最大马达转矩 [N/m]
|
/// @brief 设置最大马达转矩 [N/m]
|
||||||
void SetMaxMotorTorque(float torque);
|
void SetMaxMotorTorque(float torque);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取最大马达转矩 [N/m]
|
/// @brief 获取最大马达转矩 [N/m]
|
||||||
float GetMaxMotorTorque() const;
|
float GetMaxMotorTorque() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -664,17 +664,17 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 绳关节
|
/// @brief 绳关节
|
||||||
class KGE_API RopeJoint : public Joint
|
class KGE_API RopeJoint : public Joint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 绳关节参数
|
/// @brief 绳关节参数
|
||||||
struct Param : public Joint::ParamBase
|
struct Param : public Joint::ParamBase
|
||||||
{
|
{
|
||||||
Point local_anchor_a; ///< 关节在物体A上的连接点
|
Point local_anchor_a; ///< 关节在物体A上的连接点
|
||||||
Point local_anchor_b; ///< 关节在物体B上的连接点
|
Point local_anchor_b; ///< 关节在物体B上的连接点
|
||||||
float max_length; ///< 绳索最大长度
|
float max_length; ///< 绳索最大长度
|
||||||
|
|
||||||
Param(Body* body_a, Body* body_b, Point const& local_anchor_a, Point const& local_anchor_b,
|
Param(Body* body_a, Body* body_b, Point const& local_anchor_a, Point const& local_anchor_b,
|
||||||
float max_length = 0.f)
|
float max_length = 0.f)
|
||||||
|
|
@ -693,23 +693,23 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建绳关节
|
/// @brief 创建绳关节
|
||||||
/// @param world 物理世界
|
/// @param world 物理世界
|
||||||
/// @param param 关节参数
|
/// @param param 关节参数
|
||||||
static RopeJointPtr Create(World* world, Param const& param);
|
static RopeJointPtr Create(World* world, Param const& param);
|
||||||
|
|
||||||
RopeJoint();
|
RopeJoint();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化关节
|
/// @brief 初始化关节
|
||||||
bool InitJoint(World* world, Param const& param);
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置关节最大长度
|
/// @brief 设置关节最大长度
|
||||||
void SetMaxLength(float length);
|
void SetMaxLength(float length);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节最大长度
|
/// @brief 获取关节最大长度
|
||||||
float GetMaxLength() const;
|
float GetMaxLength() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -717,17 +717,17 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 焊接关节
|
/// @brief 焊接关节
|
||||||
class KGE_API WeldJoint : public Joint
|
class KGE_API WeldJoint : public Joint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 焊接关节参数
|
/// @brief 焊接关节参数
|
||||||
struct Param : public Joint::ParamBase
|
struct Param : public Joint::ParamBase
|
||||||
{
|
{
|
||||||
Point anchor; ///< 焊接位置
|
Point anchor; ///< 焊接位置
|
||||||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||||
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
||||||
|
|
||||||
Param(Body* body_a, Body* body_b, Point const& anchor, float frequency_hz = 0.f, float damping_ratio = 0.f)
|
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)
|
: ParamBase(body_a, body_b)
|
||||||
|
|
@ -744,35 +744,35 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建焊接关节
|
/// @brief 创建焊接关节
|
||||||
/// @param world 物理世界
|
/// @param world 物理世界
|
||||||
/// @param param 关节参数
|
/// @param param 关节参数
|
||||||
static WeldJointPtr Create(World* world, Param const& param);
|
static WeldJointPtr Create(World* world, Param const& param);
|
||||||
|
|
||||||
WeldJoint();
|
WeldJoint();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化关节
|
/// @brief 初始化关节
|
||||||
bool InitJoint(World* world, Param const& param);
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体B相对于物体A的角度
|
/// @brief 获取物体B相对于物体A的角度
|
||||||
float GetReferenceAngle() const;
|
float GetReferenceAngle() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置弹簧响应速度 [赫兹]
|
/// @brief 设置弹簧响应速度 [赫兹]
|
||||||
void SetFrequency(float hz);
|
void SetFrequency(float hz);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取弹簧响应速度 [赫兹]
|
/// @brief 获取弹簧响应速度 [赫兹]
|
||||||
float GetFrequency() const;
|
float GetFrequency() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置阻尼率
|
/// @brief 设置阻尼率
|
||||||
void SetDampingRatio(float ratio);
|
void SetDampingRatio(float ratio);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取阻尼率
|
/// @brief 获取阻尼率
|
||||||
float GetDampingRatio() const;
|
float GetDampingRatio() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -780,21 +780,21 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 轮关节
|
/// @brief 轮关节
|
||||||
class KGE_API WheelJoint : public Joint
|
class KGE_API WheelJoint : public Joint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 轮关节参数
|
/// @brief 轮关节参数
|
||||||
struct Param : public Joint::ParamBase
|
struct Param : public Joint::ParamBase
|
||||||
{
|
{
|
||||||
Point anchor; ///< 轮关节位置
|
Point anchor; ///< 轮关节位置
|
||||||
Vec2 axis; ///< 物体A滑动方向
|
Vec2 axis; ///< 物体A滑动方向
|
||||||
bool enable_motor; ///< 是否启用马达
|
bool enable_motor; ///< 是否启用马达
|
||||||
float max_motor_torque; ///< 最大马达力 [N]
|
float max_motor_torque; ///< 最大马达力 [N]
|
||||||
float motor_speed; ///< 马达转速 [degree/s]
|
float motor_speed; ///< 马达转速 [degree/s]
|
||||||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||||
float damping_ratio; ///< 弹簧阻尼率,值越大关节运动阻尼越大
|
float damping_ratio; ///< 弹簧阻尼率,值越大关节运动阻尼越大
|
||||||
|
|
||||||
Param(Body* body_a, Body* body_b, Point const& anchor, Vec2 const& axis, float frequency_hz = 2.0f,
|
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,
|
float damping_ratio = 0.7f, bool enable_motor = false, float max_motor_torque = 0.0f,
|
||||||
|
|
@ -820,71 +820,71 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建轮关节
|
/// @brief 创建轮关节
|
||||||
/// @param world 物理世界
|
/// @param world 物理世界
|
||||||
/// @param param 关节参数
|
/// @param param 关节参数
|
||||||
static WheelJointPtr Create(World* world, Param const& param);
|
static WheelJointPtr Create(World* world, Param const& param);
|
||||||
|
|
||||||
WheelJoint();
|
WheelJoint();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化关节
|
/// @brief 初始化关节
|
||||||
bool InitJoint(World* world, Param const& param);
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节当前的平移距离
|
/// @brief 获取关节当前的平移距离
|
||||||
float GetJointTranslation() const;
|
float GetJointTranslation() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节当前的线性速度
|
/// @brief 获取关节当前的线性速度
|
||||||
float GetJointLinearSpeed() const;
|
float GetJointLinearSpeed() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节当前的角度
|
/// @brief 获取关节当前的角度
|
||||||
float GetJointAngle() const;
|
float GetJointAngle() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节当前的旋转速度
|
/// @brief 获取关节当前的旋转速度
|
||||||
float GetJointAngularSpeed() const;
|
float GetJointAngularSpeed() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否启用马达
|
/// @brief 是否启用马达
|
||||||
bool IsMotorEnabled() const;
|
bool IsMotorEnabled() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置是否启用马达
|
/// @brief 设置是否启用马达
|
||||||
void EnableMotor(bool flag);
|
void EnableMotor(bool flag);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置马达转速 [degree/s]
|
/// @brief 设置马达转速 [degree/s]
|
||||||
void SetMotorSpeed(float speed);
|
void SetMotorSpeed(float speed);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取马达转速 [degree/s]
|
/// @brief 获取马达转速 [degree/s]
|
||||||
float GetMotorSpeed() const;
|
float GetMotorSpeed() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置最大马达转矩 [N/m]
|
/// @brief 设置最大马达转矩 [N/m]
|
||||||
void SetMaxMotorTorque(float torque);
|
void SetMaxMotorTorque(float torque);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取最大马达转矩 [N/m]
|
/// @brief 获取最大马达转矩 [N/m]
|
||||||
float GetMaxMotorTorque() const;
|
float GetMaxMotorTorque() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置弹簧响应速度
|
/// @brief 设置弹簧响应速度
|
||||||
void SetSpringFrequencyHz(float hz);
|
void SetSpringFrequencyHz(float hz);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取弹簧响应速度
|
/// @brief 获取弹簧响应速度
|
||||||
float GetSpringFrequencyHz() const;
|
float GetSpringFrequencyHz() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置弹簧阻尼率
|
/// @brief 设置弹簧阻尼率
|
||||||
void SetSpringDampingRatio(float ratio);
|
void SetSpringDampingRatio(float ratio);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取弹簧阻尼率
|
/// @brief 获取弹簧阻尼率
|
||||||
float GetSpringDampingRatio() const;
|
float GetSpringDampingRatio() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -892,19 +892,19 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 鼠标关节
|
/// @brief 鼠标关节
|
||||||
/// @details 用于使身体的某个点追踪世界上的指定点,例如让物体追踪鼠标位置
|
/// @details 用于使身体的某个点追踪世界上的指定点,例如让物体追踪鼠标位置
|
||||||
class KGE_API MouseJoint : public Joint
|
class KGE_API MouseJoint : public Joint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 鼠标关节参数
|
/// @brief 鼠标关节参数
|
||||||
struct Param : public Joint::ParamBase
|
struct Param : public Joint::ParamBase
|
||||||
{
|
{
|
||||||
Point target; ///< 关节作用目标位置
|
Point target; ///< 关节作用目标位置
|
||||||
float max_force; ///< 作用在物体A上的最大力
|
float max_force; ///< 作用在物体A上的最大力
|
||||||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||||
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
||||||
|
|
||||||
Param(Body* body_a, Body* body_b, Point const& target, float max_force, float frequency_hz = 5.0f,
|
Param(Body* body_a, Body* body_b, Point const& target, float max_force, float frequency_hz = 5.0f,
|
||||||
float damping_ratio = 0.7f)
|
float damping_ratio = 0.7f)
|
||||||
|
|
@ -924,39 +924,39 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建鼠标关节
|
/// @brief 创建鼠标关节
|
||||||
/// @param world 物理世界
|
/// @param world 物理世界
|
||||||
/// @param param 关节参数
|
/// @param param 关节参数
|
||||||
static MouseJointPtr Create(World* world, Param const& param);
|
static MouseJointPtr Create(World* world, Param const& param);
|
||||||
|
|
||||||
MouseJoint();
|
MouseJoint();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化关节
|
/// @brief 初始化关节
|
||||||
bool InitJoint(World* world, Param const& param);
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设定最大摩擦力 [N]
|
/// @brief 设定最大摩擦力 [N]
|
||||||
void SetMaxForce(float force);
|
void SetMaxForce(float force);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取最大摩擦力 [N]
|
/// @brief 获取最大摩擦力 [N]
|
||||||
float GetMaxForce() const;
|
float GetMaxForce() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置响应速度 [hz]
|
/// @brief 设置响应速度 [hz]
|
||||||
void SetFrequency(float hz);
|
void SetFrequency(float hz);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取响应速度 [hz]
|
/// @brief 获取响应速度 [hz]
|
||||||
float GetFrequency() const;
|
float GetFrequency() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置阻尼率
|
/// @brief 设置阻尼率
|
||||||
void SetDampingRatio(float ratio);
|
void SetDampingRatio(float ratio);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取阻尼率
|
/// @brief 获取阻尼率
|
||||||
float GetDampingRatio() const;
|
float GetDampingRatio() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ KGE_DECLARE_SMART_PTR(World);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* \defgroup Physics 物理引擎
|
* \defgroup Physics 物理引擎
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -40,7 +40,7 @@ KGE_DECLARE_SMART_PTR(World);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 物理世界
|
* @brief 物理世界
|
||||||
*/
|
*/
|
||||||
class KGE_API World : public Stage
|
class KGE_API World : public Stage
|
||||||
{
|
{
|
||||||
|
|
@ -53,53 +53,53 @@ public:
|
||||||
virtual ~World();
|
virtual ~World();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取重力 [N]
|
/// @brief 获取重力 [N]
|
||||||
Vec2 GetGravity() const;
|
Vec2 GetGravity() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置重力 [N]
|
/// @brief 设置重力 [N]
|
||||||
void SetGravity(Vec2 gravity);
|
void SetGravity(Vec2 gravity);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物理接触列表
|
/// @brief 获取物理接触列表
|
||||||
ContactList GetContactList();
|
ContactList GetContactList();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取全局缩放比例
|
/// @brief 获取全局缩放比例
|
||||||
/// @details 缩放比例是指由物理世界的单位米转换到屏幕像素的比例,默认比例为1:100
|
/// @details 缩放比例是指由物理世界的单位米转换到屏幕像素的比例,默认比例为1:100
|
||||||
float GetGlobalScale() const;
|
float GetGlobalScale() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置全局缩放比例
|
/// @brief 设置全局缩放比例
|
||||||
/// @details 缩放比例是指由物理世界的单位米转换到屏幕像素的比例,默认比例为1:100
|
/// @details 缩放比例是指由物理世界的单位米转换到屏幕像素的比例,默认比例为1:100
|
||||||
void SetGlobalScale(float scale);
|
void SetGlobalScale(float scale);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 游戏世界单位转换为物理世界单位
|
/// @brief 游戏世界单位转换为物理世界单位
|
||||||
/// @details 根据全局缩放比例将物理世界的单位米转换为像素单位
|
/// @details 根据全局缩放比例将物理世界的单位米转换为像素单位
|
||||||
float World2Stage(float value) const;
|
float World2Stage(float value) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 游戏世界单位转换为物理世界单位
|
/// @brief 游戏世界单位转换为物理世界单位
|
||||||
/// @details 根据全局缩放比例将物理世界的单位米转换为像素单位
|
/// @details 根据全局缩放比例将物理世界的单位米转换为像素单位
|
||||||
Vec2 World2Stage(const b2Vec2& pos) const;
|
Vec2 World2Stage(const b2Vec2& pos) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物理世界单位转换为游戏世界单位
|
/// @brief 物理世界单位转换为游戏世界单位
|
||||||
/// @details 根据全局缩放比例将像素单位转换为物理世界的单位米
|
/// @details 根据全局缩放比例将像素单位转换为物理世界的单位米
|
||||||
float Stage2World(float value) const;
|
float Stage2World(float value) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物理世界单位转换为游戏世界单位
|
/// @brief 物理世界单位转换为游戏世界单位
|
||||||
/// @details 根据全局缩放比例将像素单位转换为物理世界的单位米
|
/// @details 根据全局缩放比例将像素单位转换为物理世界的单位米
|
||||||
b2Vec2 Stage2World(const Vec2& pos) const;
|
b2Vec2 Stage2World(const Vec2& pos) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置速度迭代次数, 默认为 6
|
/// @brief 设置速度迭代次数, 默认为 6
|
||||||
void SetVelocityIterations(int vel_iter);
|
void SetVelocityIterations(int vel_iter);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置位置迭代次数, 默认为 2
|
/// @brief 设置位置迭代次数, 默认为 2
|
||||||
void SetPositionIterations(int pos_iter);
|
void SetPositionIterations(int pos_iter);
|
||||||
|
|
||||||
b2World* GetB2World();
|
b2World* GetB2World();
|
||||||
|
|
@ -108,27 +108,27 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除物体
|
/// @brief 移除物体
|
||||||
void RemoveBody(Body* body);
|
void RemoveBody(Body* body);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除所有物体
|
/// @brief 移除所有物体
|
||||||
void RemoveAllBodies();
|
void RemoveAllBodies();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加关节
|
/// @brief 添加关节
|
||||||
void AddJoint(Joint* joint);
|
void AddJoint(Joint* joint);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除关节
|
/// @brief 移除关节
|
||||||
void RemoveJoint(Joint* joint);
|
void RemoveJoint(Joint* joint);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除所有关节
|
/// @brief 移除所有关节
|
||||||
void RemoveAllJoints();
|
void RemoveAllJoints();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 关节被移除
|
/// @brief 关节被移除
|
||||||
void JointRemoved(b2Joint* joint);
|
void JointRemoved(b2Joint* joint);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ void Actor::RenderBorder(RenderContext& ctx)
|
||||||
ctx.FillRectangle(bounds);
|
ctx.FillRectangle(bounds);
|
||||||
|
|
||||||
ctx.SetCurrentBrush(GetStage()->GetBorderStrokeBrush());
|
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())
|
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)
|
if (parent == child)
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"A actor cannot be its own parent");
|
KGE_ERROR("A actor cannot be its own parent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ KGE_DECLARE_SMART_PTR(Actor);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* \defgroup Actors 基础角色
|
* \defgroup Actors 基础角色
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,9 +46,9 @@ KGE_DECLARE_SMART_PTR(Actor);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 角色
|
* @brief 角色
|
||||||
* @details
|
* @details
|
||||||
* 角色是舞台上最基本的元素,是完成渲染、更新、事件分发等功能的最小单位,也是动画、定时器、事件监听等功能的载体
|
* 角色是舞台上最基本的元素,是完成渲染、更新、事件分发等功能的最小单位,也是动画、定时器、事件监听等功能的载体
|
||||||
*/
|
*/
|
||||||
class KGE_API Actor
|
class KGE_API Actor
|
||||||
: public virtual ObjectBase
|
: public virtual ObjectBase
|
||||||
|
|
@ -63,15 +63,15 @@ class KGE_API Actor
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 子成员列表
|
/// @brief 子成员列表
|
||||||
using Children = IntrusiveList<ActorPtr>;
|
using Children = IntrusiveList<ActorPtr>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 角色更新回调函数
|
/// @brief 角色更新回调函数
|
||||||
using UpdateCallback = Function<void(Duration)>;
|
using UpdateCallback = Function<void(Duration)>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建角色
|
/// @brief 创建角色
|
||||||
static ActorPtr Create();
|
static ActorPtr Create();
|
||||||
|
|
||||||
Actor();
|
Actor();
|
||||||
|
|
@ -79,372 +79,372 @@ public:
|
||||||
virtual ~Actor();
|
virtual ~Actor();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新角色
|
/// @brief 更新角色
|
||||||
/// @details 每帧画面刷新前调用该函数,重载该函数以实现角色的更新处理
|
/// @details 每帧画面刷新前调用该函数,重载该函数以实现角色的更新处理
|
||||||
/// @param dt 距上一次更新的时间间隔
|
/// @param dt 距上一次更新的时间间隔
|
||||||
virtual void OnUpdate(Duration dt);
|
virtual void OnUpdate(Duration dt);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 渲染角色
|
/// @brief 渲染角色
|
||||||
/// @details
|
/// @details
|
||||||
/// 每帧画面刷新时调用该函数,默认不进行渲染,重载该函数以实现具体渲染过程
|
/// 每帧画面刷新时调用该函数,默认不进行渲染,重载该函数以实现具体渲染过程
|
||||||
/// @param ctx 渲染上下文
|
/// @param ctx 渲染上下文
|
||||||
virtual void OnRender(RenderContext& ctx);
|
virtual void OnRender(RenderContext& ctx);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取显示状态
|
/// @brief 获取显示状态
|
||||||
bool IsVisible() const;
|
bool IsVisible() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取响应状态
|
/// @brief 获取响应状态
|
||||||
bool IsResponsible() const;
|
bool IsResponsible() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否启用级联透明度
|
/// @brief 是否启用级联透明度
|
||||||
bool IsCascadeOpacityEnabled() const;
|
bool IsCascadeOpacityEnabled() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取名称的 Hash 值
|
/// @brief 获取名称的 Hash 值
|
||||||
size_t GetHashName() const;
|
size_t GetHashName() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取 Z 轴顺序
|
/// @brief 获取 Z 轴顺序
|
||||||
int GetZOrder() const;
|
int GetZOrder() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取坐标
|
/// @brief 获取坐标
|
||||||
Point const& GetPosition() const;
|
Point const& GetPosition() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取 x 坐标
|
/// @brief 获取 x 坐标
|
||||||
float GetPositionX() const;
|
float GetPositionX() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取 y 坐标
|
/// @brief 获取 y 坐标
|
||||||
float GetPositionY() const;
|
float GetPositionY() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取宽度
|
/// @brief 获取宽度
|
||||||
float GetWidth() const;
|
float GetWidth() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取高度
|
/// @brief 获取高度
|
||||||
float GetHeight() const;
|
float GetHeight() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取大小
|
/// @brief 获取大小
|
||||||
Size const& GetSize() const;
|
Size const& GetSize() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取缩放后的宽度
|
/// @brief 获取缩放后的宽度
|
||||||
float GetScaledWidth() const;
|
float GetScaledWidth() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取缩放后的高度
|
/// @brief 获取缩放后的高度
|
||||||
float GetScaledHeight() const;
|
float GetScaledHeight() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取缩放后的大小
|
/// @brief 获取缩放后的大小
|
||||||
Size GetScaledSize() const;
|
Size GetScaledSize() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取锚点
|
/// @brief 获取锚点
|
||||||
Point const& GetAnchor() const;
|
Point const& GetAnchor() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取 x 方向锚点
|
/// @brief 获取 x 方向锚点
|
||||||
float GetAnchorX() const;
|
float GetAnchorX() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取 y 方向锚点
|
/// @brief 获取 y 方向锚点
|
||||||
float GetAnchorY() const;
|
float GetAnchorY() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取透明度
|
/// @brief 获取透明度
|
||||||
float GetOpacity() const;
|
float GetOpacity() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取显示透明度
|
/// @brief 获取显示透明度
|
||||||
float GetDisplayedOpacity() const;
|
float GetDisplayedOpacity() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取旋转角度
|
/// @brief 获取旋转角度
|
||||||
float GetRotation() const;
|
float GetRotation() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取缩放比例
|
/// @brief 获取缩放比例
|
||||||
Point const& GetScale() const;
|
Point const& GetScale() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取横向缩放比例
|
/// @brief 获取横向缩放比例
|
||||||
float GetScaleX() const;
|
float GetScaleX() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取纵向缩放比例
|
/// @brief 获取纵向缩放比例
|
||||||
float GetScaleY() const;
|
float GetScaleY() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取错切角度
|
/// @brief 获取错切角度
|
||||||
Point const& GetSkew() const;
|
Point const& GetSkew() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取横向错切角度
|
/// @brief 获取横向错切角度
|
||||||
float GetSkewX() const;
|
float GetSkewX() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取纵向错切角度
|
/// @brief 获取纵向错切角度
|
||||||
float GetSkewY() const;
|
float GetSkewY() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取变换
|
/// @brief 获取变换
|
||||||
Transform GetTransform() const;
|
Transform GetTransform() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取父角色
|
/// @brief 获取父角色
|
||||||
Actor* GetParent() const;
|
Actor* GetParent() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取所在舞台
|
/// @brief 获取所在舞台
|
||||||
Stage* GetStage() const;
|
Stage* GetStage() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取边框
|
/// @brief 获取边框
|
||||||
virtual Rect GetBounds() const;
|
virtual Rect GetBounds() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取外切包围盒
|
/// @brief 获取外切包围盒
|
||||||
virtual Rect GetBoundingBox() const;
|
virtual Rect GetBoundingBox() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取二维变换矩阵
|
/// @brief 获取二维变换矩阵
|
||||||
Matrix3x2 const& GetTransformMatrix() const;
|
Matrix3x2 const& GetTransformMatrix() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取二维变换的逆矩阵
|
/// @brief 获取二维变换的逆矩阵
|
||||||
Matrix3x2 const& GetTransformInverseMatrix() const;
|
Matrix3x2 const& GetTransformInverseMatrix() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置角色是否可见
|
/// @brief 设置角色是否可见
|
||||||
void SetVisible(bool val);
|
void SetVisible(bool val);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置名称
|
/// @brief 设置名称
|
||||||
void SetName(String const& name);
|
void SetName(String const& name);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置坐标
|
/// @brief 设置坐标
|
||||||
virtual void SetPosition(Point const& point);
|
virtual void SetPosition(Point const& point);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置坐标
|
/// @brief 设置坐标
|
||||||
void SetPosition(float x, float y);
|
void SetPosition(float x, float y);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置横坐标
|
/// @brief 设置横坐标
|
||||||
void SetPositionX(float x);
|
void SetPositionX(float x);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置纵坐标
|
/// @brief 设置纵坐标
|
||||||
void SetPositionY(float y);
|
void SetPositionY(float y);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移动坐标
|
/// @brief 移动坐标
|
||||||
void Move(Vec2 const& v);
|
void Move(Vec2 const& v);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移动坐标
|
/// @brief 移动坐标
|
||||||
void Move(float vx, float vy);
|
void Move(float vx, float vy);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置缩放比例,默认为 (1.0, 1.0)
|
/// @brief 设置缩放比例,默认为 (1.0, 1.0)
|
||||||
virtual void SetScale(Vec2 const& scale);
|
virtual void SetScale(Vec2 const& scale);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置缩放比例,默认为 (1.0, 1.0)
|
/// @brief 设置缩放比例,默认为 (1.0, 1.0)
|
||||||
void SetScale(float scalex, float scaley);
|
void SetScale(float scalex, float scaley);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置错切角度,默认为 (0, 0)
|
/// @brief 设置错切角度,默认为 (0, 0)
|
||||||
virtual void SetSkew(Vec2 const& skew);
|
virtual void SetSkew(Vec2 const& skew);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置错切角度,默认为 (0, 0)
|
/// @brief 设置错切角度,默认为 (0, 0)
|
||||||
void SetSkew(float skewx, float skewy);
|
void SetSkew(float skewx, float skewy);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置旋转角度,默认为 0
|
/// @brief 设置旋转角度,默认为 0
|
||||||
virtual void SetRotation(float rotation);
|
virtual void SetRotation(float rotation);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置锚点位置,默认为 (0, 0), 范围 [0, 1]
|
/// @brief 设置锚点位置,默认为 (0, 0), 范围 [0, 1]
|
||||||
virtual void SetAnchor(Vec2 const& anchor);
|
virtual void SetAnchor(Vec2 const& anchor);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置锚点位置,默认为 (0, 0), 范围 [0, 1]
|
/// @brief 设置锚点位置,默认为 (0, 0), 范围 [0, 1]
|
||||||
void SetAnchor(float anchorx, float anchory);
|
void SetAnchor(float anchorx, float anchory);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 修改宽度
|
/// @brief 修改宽度
|
||||||
virtual void SetWidth(float width);
|
virtual void SetWidth(float width);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 修改高度
|
/// @brief 修改高度
|
||||||
virtual void SetHeight(float height);
|
virtual void SetHeight(float height);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 修改大小
|
/// @brief 修改大小
|
||||||
virtual void SetSize(Size const& size);
|
virtual void SetSize(Size const& size);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 修改大小
|
/// @brief 修改大小
|
||||||
void SetSize(float width, float height);
|
void SetSize(float width, float height);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置透明度,默认为 1.0, 范围 [0, 1]
|
/// @brief 设置透明度,默认为 1.0, 范围 [0, 1]
|
||||||
virtual void SetOpacity(float opacity);
|
virtual void SetOpacity(float opacity);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 启用或禁用级联透明度
|
/// @brief 启用或禁用级联透明度
|
||||||
void SetCascadeOpacityEnabled(bool enabled);
|
void SetCascadeOpacityEnabled(bool enabled);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置二维仿射变换
|
/// @brief 设置二维仿射变换
|
||||||
void SetTransform(Transform const& transform);
|
void SetTransform(Transform const& transform);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置 Z 轴顺序,默认为 0
|
/// @brief 设置 Z 轴顺序,默认为 0
|
||||||
void SetZOrder(int zorder);
|
void SetZOrder(int zorder);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置角色是否可响应,默认为 false
|
/// @brief 设置角色是否可响应,默认为 false
|
||||||
/// @details 可响应的角色会收到鼠标的 Hover | Out | Click 消息
|
/// @details 可响应的角色会收到鼠标的 Hover | Out | Click 消息
|
||||||
void SetResponsible(bool enable);
|
void SetResponsible(bool enable);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加子角色
|
/// @brief 添加子角色
|
||||||
void AddChild(ActorPtr child, int zorder = 0);
|
void AddChild(ActorPtr child, int zorder = 0);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加子角色
|
/// @brief 添加子角色
|
||||||
void AddChild(Actor* child, int zorder = 0);
|
void AddChild(Actor* child, int zorder = 0);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加多个子角色
|
/// @brief 添加多个子角色
|
||||||
void AddChildren(Vector<ActorPtr> const& children);
|
void AddChildren(Vector<ActorPtr> const& children);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取名称相同的子角色
|
/// @brief 获取名称相同的子角色
|
||||||
Actor* GetChild(String const& name) const;
|
Actor* GetChild(String const& name) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取所有名称相同的子角色
|
/// @brief 获取所有名称相同的子角色
|
||||||
Vector<ActorPtr> GetChildren(String const& name) const;
|
Vector<ActorPtr> GetChildren(String const& name) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取全部子角色
|
/// @brief 获取全部子角色
|
||||||
Children& GetAllChildren();
|
Children& GetAllChildren();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取全部子角色
|
/// @brief 获取全部子角色
|
||||||
Children const& GetAllChildren() const;
|
Children const& GetAllChildren() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除子角色
|
/// @brief 移除子角色
|
||||||
void RemoveChild(ActorPtr child);
|
void RemoveChild(ActorPtr child);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除子角色
|
/// @brief 移除子角色
|
||||||
void RemoveChild(Actor* child);
|
void RemoveChild(Actor* child);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除所有名称相同的子角色
|
/// @brief 移除所有名称相同的子角色
|
||||||
void RemoveChildren(String const& child_name);
|
void RemoveChildren(String const& child_name);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除所有角色
|
/// @brief 移除所有角色
|
||||||
void RemoveAllChildren();
|
void RemoveAllChildren();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 从父角色移除
|
/// @brief 从父角色移除
|
||||||
void RemoveFromParent();
|
void RemoveFromParent();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 暂停角色更新
|
/// @brief 暂停角色更新
|
||||||
void PauseUpdating();
|
void PauseUpdating();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 继续角色更新
|
/// @brief 继续角色更新
|
||||||
void ResumeUpdating();
|
void ResumeUpdating();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 角色更新是否暂停
|
/// @brief 角色更新是否暂停
|
||||||
bool IsUpdatePausing() const;
|
bool IsUpdatePausing() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置更新时的回调函数
|
/// @brief 设置更新时的回调函数
|
||||||
void SetCallbackOnUpdate(UpdateCallback const& cb);
|
void SetCallbackOnUpdate(UpdateCallback const& cb);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取更新时的回调函数
|
/// @brief 获取更新时的回调函数
|
||||||
UpdateCallback GetCallbackOnUpdate() const;
|
UpdateCallback GetCallbackOnUpdate() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 判断点是否在角色内
|
/// @brief 判断点是否在角色内
|
||||||
virtual bool ContainsPoint(const Point& point) const;
|
virtual bool ContainsPoint(const Point& point) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 渲染角色边界
|
/// @brief 渲染角色边界
|
||||||
void ShowBorder(bool show);
|
void ShowBorder(bool show);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 分发事件
|
/// @brief 分发事件
|
||||||
/// @param evt 事件
|
/// @param evt 事件
|
||||||
/// @return 是否继续分发该事件
|
/// @return 是否继续分发该事件
|
||||||
virtual bool DispatchEvent(Event* evt);
|
virtual bool DispatchEvent(Event* evt);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置默认锚点
|
/// @brief 设置默认锚点
|
||||||
static void SetDefaultAnchor(float anchor_x, float anchor_y);
|
static void SetDefaultAnchor(float anchor_x, float anchor_y);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新自身和所有子角色
|
/// @brief 更新自身和所有子角色
|
||||||
virtual void Update(Duration dt);
|
virtual void Update(Duration dt);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 渲染自身和所有子角色
|
/// @brief 渲染自身和所有子角色
|
||||||
virtual void Render(RenderContext& ctx);
|
virtual void Render(RenderContext& ctx);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 绘制自身和所有子角色的边界
|
/// @brief 绘制自身和所有子角色的边界
|
||||||
virtual void RenderBorder(RenderContext& ctx);
|
virtual void RenderBorder(RenderContext& ctx);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 检查是否在渲染上下文的视区内
|
/// @brief 检查是否在渲染上下文的视区内
|
||||||
virtual bool CheckVisibility(RenderContext& ctx) const;
|
virtual bool CheckVisibility(RenderContext& ctx) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 渲染前初始化渲染上下文状态,仅当 CheckVisibility 返回真时调用该函数
|
/// @brief 渲染前初始化渲染上下文状态,仅当 CheckVisibility 返回真时调用该函数
|
||||||
virtual void PrepareToRender(RenderContext& ctx);
|
virtual void PrepareToRender(RenderContext& ctx);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新自己的二维变换,并通知所有子角色
|
/// @brief 更新自己的二维变换,并通知所有子角色
|
||||||
void UpdateTransform() const;
|
void UpdateTransform() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新自己和所有子角色的透明度
|
/// @brief 更新自己和所有子角色的透明度
|
||||||
void UpdateOpacity();
|
void UpdateOpacity();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 将所有子角色按Z轴顺序排序
|
/// @brief 将所有子角色按Z轴顺序排序
|
||||||
void Reorder();
|
void Reorder();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置节点所在舞台
|
/// @brief 设置节点所在舞台
|
||||||
void SetStage(Stage* stage);
|
void SetStage(Stage* stage);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 处理事件
|
/// @brief 处理事件
|
||||||
void HandleEvent(Event* evt);
|
void HandleEvent(Event* evt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -78,14 +78,14 @@ void Button::SetStatus(Status status)
|
||||||
|
|
||||||
if (status == Status::Normal)
|
if (status == Status::Normal)
|
||||||
{
|
{
|
||||||
Window::Instance().SetCursor(CursorType::Arrow);
|
Window::GetInstance().SetCursor(CursorType::Arrow);
|
||||||
|
|
||||||
if (mouse_out_callback_)
|
if (mouse_out_callback_)
|
||||||
mouse_out_callback_(this);
|
mouse_out_callback_(this);
|
||||||
}
|
}
|
||||||
else if (status == Status::Hover)
|
else if (status == Status::Hover)
|
||||||
{
|
{
|
||||||
Window::Instance().SetCursor(CursorType::Hand);
|
Window::GetInstance().SetCursor(CursorType::Hand);
|
||||||
|
|
||||||
if (old_status == Status::Pressed)
|
if (old_status == Status::Pressed)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,13 @@ KGE_DECLARE_SMART_PTR(TextButton);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 按钮
|
* @brief 按钮
|
||||||
*/
|
*/
|
||||||
class KGE_API Button : public virtual ObjectBase
|
class KGE_API Button : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 按钮回调函数
|
/// @brief 按钮回调函数
|
||||||
using Callback = Function<void(Button* /* self */)>;
|
using Callback = Function<void(Button* /* self */)>;
|
||||||
|
|
||||||
Button();
|
Button();
|
||||||
|
|
@ -44,53 +44,53 @@ public:
|
||||||
virtual ~Button();
|
virtual ~Button();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取按钮状态是启用还是禁用
|
/// @brief 获取按钮状态是启用还是禁用
|
||||||
bool IsEnable() const;
|
bool IsEnable() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置按钮启用或禁用
|
/// @brief 设置按钮启用或禁用
|
||||||
void SetEnabled(bool enabled);
|
void SetEnabled(bool enabled);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置按钮点击后的回调函数
|
/// @brief 设置按钮点击后的回调函数
|
||||||
void SetClickCallback(const Callback& func);
|
void SetClickCallback(const Callback& func);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置按钮被按下时的回调函数
|
/// @brief 设置按钮被按下时的回调函数
|
||||||
void SetPressedCallback(const Callback& func);
|
void SetPressedCallback(const Callback& func);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置按钮被抬起时的回调函数
|
/// @brief 设置按钮被抬起时的回调函数
|
||||||
void SetReleasedCallback(const Callback& func);
|
void SetReleasedCallback(const Callback& func);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置鼠标移入按钮时的回调函数
|
/// @brief 设置鼠标移入按钮时的回调函数
|
||||||
void SetMouseOverCallback(const Callback& func);
|
void SetMouseOverCallback(const Callback& func);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置鼠标移出按钮时的回调函数
|
/// @brief 设置鼠标移出按钮时的回调函数
|
||||||
void SetMouseOutCallback(const Callback& func);
|
void SetMouseOutCallback(const Callback& func);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 按钮状态
|
/// @brief 按钮状态
|
||||||
enum class Status
|
enum class Status
|
||||||
{
|
{
|
||||||
Normal, ///< 普通
|
Normal, ///< 普通
|
||||||
Hover, ///< 鼠标在按钮内
|
Hover, ///< 鼠标在按钮内
|
||||||
Pressed ///< 被按下
|
Pressed ///< 被按下
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置按钮状态
|
/// @brief 设置按钮状态
|
||||||
void SetStatus(Status status);
|
void SetStatus(Status status);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取按钮状态
|
/// @brief 获取按钮状态
|
||||||
Status GetStatus() const;
|
Status GetStatus() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新按钮状态
|
/// @brief 更新按钮状态
|
||||||
void UpdateStatus(Event* evt);
|
void UpdateStatus(Event* evt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -104,7 +104,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 精灵按钮
|
/// @brief 精灵按钮
|
||||||
class SpriteButton
|
class SpriteButton
|
||||||
: public Sprite
|
: public Sprite
|
||||||
, public Button
|
, public Button
|
||||||
|
|
@ -113,22 +113,22 @@ public:
|
||||||
SpriteButton();
|
SpriteButton();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建精灵按钮
|
/// @brief 创建精灵按钮
|
||||||
/// @param click 按钮点击回调函数
|
/// @param click 按钮点击回调函数
|
||||||
static SpriteButtonPtr Create(Callback const& click);
|
static SpriteButtonPtr Create(Callback const& click);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建精灵按钮
|
/// @brief 创建精灵按钮
|
||||||
/// @param click 按钮点击回调函数
|
/// @param click 按钮点击回调函数
|
||||||
/// @param pressed 按钮按下回调函数
|
/// @param pressed 按钮按下回调函数
|
||||||
/// @param mouse_over 按钮移入回调函数
|
/// @param mouse_over 按钮移入回调函数
|
||||||
/// @param mouse_out 按钮移出回调函数
|
/// @param mouse_out 按钮移出回调函数
|
||||||
static SpriteButtonPtr Create(Callback const& click, Callback const& pressed, Callback const& mouse_over,
|
static SpriteButtonPtr Create(Callback const& click, Callback const& pressed, Callback const& mouse_over,
|
||||||
Callback const& mouse_out);
|
Callback const& mouse_out);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 文字按钮
|
/// @brief 文字按钮
|
||||||
class TextButton
|
class TextButton
|
||||||
: public TextActor
|
: public TextActor
|
||||||
, public Button
|
, public Button
|
||||||
|
|
@ -137,16 +137,16 @@ public:
|
||||||
TextButton();
|
TextButton();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建文字按钮
|
/// @brief 创建文字按钮
|
||||||
/// @param click 按钮点击回调函数
|
/// @param click 按钮点击回调函数
|
||||||
static TextButtonPtr Create(Callback const& click);
|
static TextButtonPtr Create(Callback const& click);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建文字按钮
|
/// @brief 创建文字按钮
|
||||||
/// @param click 按钮点击回调函数
|
/// @param click 按钮点击回调函数
|
||||||
/// @param pressed 按钮按下回调函数
|
/// @param pressed 按钮按下回调函数
|
||||||
/// @param mouse_over 按钮移入回调函数
|
/// @param mouse_over 按钮移入回调函数
|
||||||
/// @param mouse_out 按钮移出回调函数
|
/// @param mouse_out 按钮移出回调函数
|
||||||
static TextButtonPtr Create(Callback const& click, Callback const& pressed, Callback const& mouse_over, Callback const& mouse_out);
|
static TextButtonPtr Create(Callback const& click, Callback const& pressed, Callback const& mouse_over, Callback const& mouse_out);
|
||||||
};
|
};
|
||||||
} // namespace kiwano
|
} // namespace kiwano
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,24 @@
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
||||||
CanvasPtr Canvas::Create()
|
CanvasPtr Canvas::Create(Size const& size)
|
||||||
{
|
{
|
||||||
CanvasPtr ptr = new (std::nothrow) Canvas;
|
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;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,17 +53,15 @@ Canvas::Canvas()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Canvas::~Canvas() {}
|
|
||||||
|
|
||||||
void Canvas::BeginDraw()
|
void Canvas::BeginDraw()
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->BeginDraw();
|
ctx_->BeginDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::EndDraw()
|
void Canvas::EndDraw()
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->EndDraw();
|
ctx_->EndDraw();
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
}
|
}
|
||||||
|
|
@ -60,124 +73,117 @@ void Canvas::OnRender(RenderContext& ctx)
|
||||||
if (texture_cached_ && texture_cached_->IsValid())
|
if (texture_cached_ && texture_cached_->IsValid())
|
||||||
{
|
{
|
||||||
PrepareToRender(ctx);
|
PrepareToRender(ctx);
|
||||||
|
ctx.DrawTexture(*texture_cached_, nullptr, &GetBounds());
|
||||||
Rect bitmap_rect(0.f, 0.f, texture_cached_->GetWidth(), texture_cached_->GetHeight());
|
|
||||||
ctx.DrawTexture(*texture_cached_, bitmap_rect, bitmap_rect);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::SetBrush(BrushPtr brush)
|
void Canvas::SetBrush(BrushPtr brush)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetCurrentBrush(brush);
|
ctx_->SetCurrentBrush(brush);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Canvas::GetStrokeWidth() const
|
|
||||||
{
|
|
||||||
return stroke_width_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Canvas::SetBrushTransform(Transform const& transform)
|
void Canvas::SetBrushTransform(Transform const& transform)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetTransform(transform.ToMatrix());
|
ctx_->SetTransform(transform.ToMatrix());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::SetBrushTransform(Matrix3x2 const& transform)
|
void Canvas::SetBrushTransform(Matrix3x2 const& transform)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetTransform(transform);
|
ctx_->SetTransform(transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::PushLayerArea(LayerArea& area)
|
void Canvas::PushLayer(Layer& layer)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->PushLayer(area);
|
ctx_->PushLayer(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::PopLayerArea()
|
void Canvas::PopLayer()
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->PopLayer();
|
ctx_->PopLayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::PushClipRect(Rect const& clip_rect)
|
void Canvas::PushClipRect(Rect const& clip_rect)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->PushClipRect(clip_rect);
|
ctx_->PushClipRect(clip_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::PopClipRect()
|
void Canvas::PopClipRect()
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->PopClipRect();
|
ctx_->PopClipRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::DrawShape(ShapePtr shape)
|
void Canvas::DrawShape(ShapePtr shape)
|
||||||
{
|
{
|
||||||
if (!shape)
|
KGE_ASSERT(ctx_);
|
||||||
return;
|
if (shape)
|
||||||
|
{
|
||||||
InitRenderTargetAndBrushs();
|
|
||||||
ctx_->SetCurrentBrush(stroke_brush_);
|
ctx_->SetCurrentBrush(stroke_brush_);
|
||||||
ctx_->DrawShape(*shape, stroke_width_, stroke_style_);
|
ctx_->DrawShape(*shape, stroke_style_, stroke_width_);
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::DrawLine(Point const& begin, Point const& end)
|
void Canvas::DrawLine(Point const& begin, Point const& end)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetCurrentBrush(stroke_brush_);
|
ctx_->SetCurrentBrush(stroke_brush_);
|
||||||
ctx_->DrawLine(begin, end, stroke_width_, stroke_style_);
|
ctx_->DrawLine(begin, end, stroke_style_, stroke_width_);
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::DrawCircle(Point const& center, float radius)
|
void Canvas::DrawCircle(Point const& center, float radius)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetCurrentBrush(stroke_brush_);
|
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;
|
cache_expired_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::DrawEllipse(Point const& center, Vec2 const& radius)
|
void Canvas::DrawEllipse(Point const& center, Vec2 const& radius)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetCurrentBrush(stroke_brush_);
|
ctx_->SetCurrentBrush(stroke_brush_);
|
||||||
ctx_->DrawEllipse(center, radius, stroke_width_, stroke_style_);
|
ctx_->DrawEllipse(center, radius, stroke_style_, stroke_width_);
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::DrawRect(Rect const& rect)
|
void Canvas::DrawRect(Rect const& rect)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetCurrentBrush(stroke_brush_);
|
ctx_->SetCurrentBrush(stroke_brush_);
|
||||||
ctx_->DrawRectangle(rect, stroke_width_, stroke_style_);
|
ctx_->DrawRectangle(rect, stroke_style_, stroke_width_);
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::DrawRoundedRect(Rect const& rect, Vec2 const& radius)
|
void Canvas::DrawRoundedRect(Rect const& rect, Vec2 const& radius)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetCurrentBrush(stroke_brush_);
|
ctx_->SetCurrentBrush(stroke_brush_);
|
||||||
ctx_->DrawRoundedRectangle(rect, radius, stroke_width_, stroke_style_);
|
ctx_->DrawRoundedRectangle(rect, radius, stroke_style_, stroke_width_);
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::FillShape(ShapePtr shape)
|
void Canvas::FillShape(ShapePtr shape)
|
||||||
{
|
{
|
||||||
if (!shape)
|
KGE_ASSERT(ctx_);
|
||||||
return;
|
if (shape)
|
||||||
|
{
|
||||||
InitRenderTargetAndBrushs();
|
|
||||||
ctx_->SetCurrentBrush(fill_brush_);
|
ctx_->SetCurrentBrush(fill_brush_);
|
||||||
ctx_->FillShape(*shape);
|
ctx_->FillShape(*shape);
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::FillCircle(Point const& center, float radius)
|
void Canvas::FillCircle(Point const& center, float radius)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetCurrentBrush(fill_brush_);
|
ctx_->SetCurrentBrush(fill_brush_);
|
||||||
ctx_->FillEllipse(center, Vec2(radius, radius));
|
ctx_->FillEllipse(center, Vec2(radius, radius));
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
|
|
@ -185,7 +191,7 @@ void Canvas::FillCircle(Point const& center, float radius)
|
||||||
|
|
||||||
void Canvas::FillEllipse(Point const& center, Vec2 const& radius)
|
void Canvas::FillEllipse(Point const& center, Vec2 const& radius)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetCurrentBrush(fill_brush_);
|
ctx_->SetCurrentBrush(fill_brush_);
|
||||||
ctx_->FillEllipse(center, radius);
|
ctx_->FillEllipse(center, radius);
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
|
|
@ -193,7 +199,7 @@ void Canvas::FillEllipse(Point const& center, Vec2 const& radius)
|
||||||
|
|
||||||
void Canvas::FillRect(Rect const& rect)
|
void Canvas::FillRect(Rect const& rect)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetCurrentBrush(fill_brush_);
|
ctx_->SetCurrentBrush(fill_brush_);
|
||||||
ctx_->FillRectangle(rect);
|
ctx_->FillRectangle(rect);
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
|
|
@ -201,7 +207,7 @@ void Canvas::FillRect(Rect const& rect)
|
||||||
|
|
||||||
void Canvas::FillRoundedRect(Rect const& rect, Vec2 const& radius)
|
void Canvas::FillRoundedRect(Rect const& rect, Vec2 const& radius)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetCurrentBrush(fill_brush_);
|
ctx_->SetCurrentBrush(fill_brush_);
|
||||||
ctx_->FillRoundedRectangle(rect, radius);
|
ctx_->FillRoundedRectangle(rect, radius);
|
||||||
cache_expired_ = true;
|
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)
|
void Canvas::DrawTexture(TexturePtr texture, const Rect* src_rect, const Rect* dest_rect)
|
||||||
{
|
{
|
||||||
|
KGE_ASSERT(ctx_);
|
||||||
if (texture)
|
if (texture)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
|
||||||
ctx_->DrawTexture(*texture, src_rect, dest_rect);
|
ctx_->DrawTexture(*texture, src_rect, dest_rect);
|
||||||
cache_expired_ = true;
|
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)
|
void Canvas::DrawTextLayout(TextLayout const& layout, Point const& point)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->DrawTextLayout(layout, point);
|
ctx_->DrawTextLayout(layout, point);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,15 +272,15 @@ void Canvas::AddArc(Point const& point, Size const& radius, float rotation, bool
|
||||||
|
|
||||||
void Canvas::StrokePath()
|
void Canvas::StrokePath()
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetCurrentBrush(stroke_brush_);
|
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;
|
cache_expired_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::FillPath()
|
void Canvas::FillPath()
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->SetCurrentBrush(fill_brush_);
|
ctx_->SetCurrentBrush(fill_brush_);
|
||||||
ctx_->FillShape(*shape_sink_.GetShape());
|
ctx_->FillShape(*shape_sink_.GetShape());
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
|
|
@ -282,44 +288,29 @@ void Canvas::FillPath()
|
||||||
|
|
||||||
void Canvas::Clear()
|
void Canvas::Clear()
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->Clear();
|
ctx_->Clear();
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::Clear(Color const& clear_color)
|
void Canvas::Clear(Color const& clear_color)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
KGE_ASSERT(ctx_);
|
||||||
ctx_->Clear(clear_color);
|
ctx_->Clear(clear_color);
|
||||||
cache_expired_ = true;
|
cache_expired_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Canvas::ResizeAndClear(Size size)
|
||||||
|
{
|
||||||
|
ctx_ = TextureRenderContext::Create(size);
|
||||||
|
}
|
||||||
|
|
||||||
TexturePtr Canvas::ExportToTexture() const
|
TexturePtr Canvas::ExportToTexture() const
|
||||||
{
|
{
|
||||||
UpdateCache();
|
UpdateCache();
|
||||||
return texture_cached_;
|
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
|
void Canvas::UpdateCache() const
|
||||||
{
|
{
|
||||||
if (cache_expired_ && ctx_)
|
if (cache_expired_ && ctx_)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/2d/Actor.h>
|
#include <kiwano/2d/Actor.h>
|
||||||
#include <kiwano/render/ShapeSink.h>
|
#include <kiwano/render/ShapeSink.h>
|
||||||
#include <kiwano/render/RenderContext.h>
|
#include <kiwano/render/TextureRenderContext.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
@ -35,251 +35,251 @@ KGE_DECLARE_SMART_PTR(Canvas);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 画布,用于绘制图元
|
* @brief 画布
|
||||||
|
* @details 用于绘制图形、图像、文字等各种类型的图元,同时可以将绘制内容导出至图像
|
||||||
*/
|
*/
|
||||||
class KGE_API Canvas : public Actor
|
class KGE_API Canvas : public Actor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建画布
|
/// @brief 创建画布
|
||||||
static CanvasPtr Create();
|
/// @param size 画布大小
|
||||||
|
static CanvasPtr Create(Size const& size);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构建空画布
|
/// @brief 开始绘图
|
||||||
Canvas();
|
|
||||||
|
|
||||||
virtual ~Canvas();
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 开始绘图
|
|
||||||
void BeginDraw();
|
void BeginDraw();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 结束绘图
|
/// @brief 结束绘图
|
||||||
void EndDraw();
|
void EndDraw();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 画形状轮廓
|
/// @brief 画形状轮廓
|
||||||
/// @param shape 形状
|
/// @param shape 形状
|
||||||
void DrawShape(ShapePtr shape);
|
void DrawShape(ShapePtr shape);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 画线段
|
/// @brief 画线段
|
||||||
/// @param begin 线段起点
|
/// @param begin 线段起点
|
||||||
/// @param end 线段终点
|
/// @param end 线段终点
|
||||||
void DrawLine(Point const& begin, Point const& end);
|
void DrawLine(Point const& begin, Point const& end);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 画圆形边框
|
/// @brief 画圆形边框
|
||||||
/// @param center 圆形原点
|
/// @param center 圆形原点
|
||||||
/// @param radius 圆形半径
|
/// @param radius 圆形半径
|
||||||
void DrawCircle(Point const& center, float radius);
|
void DrawCircle(Point const& center, float radius);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 画椭圆形边框
|
/// @brief 画椭圆形边框
|
||||||
/// @param center 椭圆原点
|
/// @param center 椭圆原点
|
||||||
/// @param radius 椭圆半径
|
/// @param radius 椭圆半径
|
||||||
void DrawEllipse(Point const& center, Vec2 const& radius);
|
void DrawEllipse(Point const& center, Vec2 const& radius);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 画矩形边框
|
/// @brief 画矩形边框
|
||||||
/// @param rect 矩形
|
/// @param rect 矩形
|
||||||
void DrawRect(Rect const& rect);
|
void DrawRect(Rect const& rect);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 画圆角矩形边框
|
/// @brief 画圆角矩形边框
|
||||||
/// @param rect 矩形
|
/// @param rect 矩形
|
||||||
/// @param radius 矩形圆角半径
|
/// @param radius 矩形圆角半径
|
||||||
void DrawRoundedRect(Rect const& rect, Vec2 const& radius);
|
void DrawRoundedRect(Rect const& rect, Vec2 const& radius);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 填充形状
|
/// @brief 填充形状
|
||||||
/// @param shape 形状
|
/// @param shape 形状
|
||||||
void FillShape(ShapePtr shape);
|
void FillShape(ShapePtr shape);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 填充圆形
|
/// @brief 填充圆形
|
||||||
/// @param center 圆形原点
|
/// @param center 圆形原点
|
||||||
/// @param radius 圆形半径
|
/// @param radius 圆形半径
|
||||||
void FillCircle(Point const& center, float radius);
|
void FillCircle(Point const& center, float radius);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 填充椭圆形
|
/// @brief 填充椭圆形
|
||||||
/// @param center 椭圆原点
|
/// @param center 椭圆原点
|
||||||
/// @param radius 椭圆半径
|
/// @param radius 椭圆半径
|
||||||
void FillEllipse(Point const& center, Vec2 const& radius);
|
void FillEllipse(Point const& center, Vec2 const& radius);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 填充矩形
|
/// @brief 填充矩形
|
||||||
/// @param rect 矩形
|
/// @param rect 矩形
|
||||||
void FillRect(Rect const& rect);
|
void FillRect(Rect const& rect);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 填充圆角矩形
|
/// @brief 填充圆角矩形
|
||||||
/// @param rect 矩形
|
/// @param rect 矩形
|
||||||
/// @param radius 矩形圆角半径
|
/// @param radius 矩形圆角半径
|
||||||
void FillRoundedRect(Rect const& rect, Vec2 const& radius);
|
void FillRoundedRect(Rect const& rect, Vec2 const& radius);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 绘制纹理
|
/// @brief 绘制纹理
|
||||||
/// @param texture 纹理
|
/// @param texture 纹理
|
||||||
/// @param src_rect 纹理裁剪区域
|
/// @param src_rect 纹理裁剪区域
|
||||||
/// @param dest_rect 绘制目标区域
|
/// @param dest_rect 绘制目标区域
|
||||||
void DrawTexture(TexturePtr texture, const Rect* src_rect = nullptr, const Rect* dest_rect = nullptr);
|
void DrawTexture(TexturePtr texture, const Rect* src_rect = nullptr, const Rect* dest_rect = nullptr);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 绘制文字布局
|
/// @brief 绘制文字布局
|
||||||
/// @param text 文字
|
/// @param text 文字
|
||||||
/// @param point 绘制文字的位置
|
/// @param point 绘制文字的位置
|
||||||
void DrawTextLayout(String const& text, Point const& point);
|
void DrawTextLayout(String const& text, Point const& point);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 绘制文字布局
|
/// @brief 绘制文字布局
|
||||||
/// @param layout 文字布局
|
/// @param layout 文字布局
|
||||||
/// @param point 绘制布局的位置
|
/// @param point 绘制布局的位置
|
||||||
void DrawTextLayout(TextLayout const& layout, Point const& point);
|
void DrawTextLayout(TextLayout const& layout, Point const& point);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 开始绘制路径
|
/// @brief 开始绘制路径
|
||||||
/// @param begin_pos 路径起始点
|
/// @param begin_pos 路径起始点
|
||||||
void BeginPath(Point const& begin_pos);
|
void BeginPath(Point const& begin_pos);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 结束路径
|
/// @brief 结束路径
|
||||||
/// @param closed 路径是否闭合
|
/// @param closed 路径是否闭合
|
||||||
void EndPath(bool closed = false);
|
void EndPath(bool closed = false);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加一条线段
|
/// @brief 添加一条线段
|
||||||
/// @param point 端点
|
/// @param point 端点
|
||||||
void AddLine(Point const& point);
|
void AddLine(Point const& point);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加多条线段
|
/// @brief 添加多条线段
|
||||||
/// @param points 端点集合
|
/// @param points 端点集合
|
||||||
void AddLines(Vector<Point> const& points);
|
void AddLines(Vector<Point> const& points);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加一条三次方贝塞尔曲线
|
/// @brief 添加一条三次方贝塞尔曲线
|
||||||
/// @param point1 贝塞尔曲线的第一个控制点
|
/// @param point1 贝塞尔曲线的第一个控制点
|
||||||
/// @param point2 贝塞尔曲线的第二个控制点
|
/// @param point2 贝塞尔曲线的第二个控制点
|
||||||
/// @param point3 贝塞尔曲线的终点
|
/// @param point3 贝塞尔曲线的终点
|
||||||
void AddBezier(Point const& point1, Point const& point2, Point const& point3);
|
void AddBezier(Point const& point1, Point const& point2, Point const& point3);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加弧线
|
/// @brief 添加弧线
|
||||||
/// @param point 终点
|
/// @param point 终点
|
||||||
/// @param radius 椭圆半径
|
/// @param radius 椭圆半径
|
||||||
/// @param rotation 椭圆旋转角度
|
/// @param rotation 椭圆旋转角度
|
||||||
/// @param clockwise 顺时针 or 逆时针
|
/// @param clockwise 顺时针 or 逆时针
|
||||||
/// @param is_small 是否取小于 180° 的弧
|
/// @param is_small 是否取小于 180° 的弧
|
||||||
void AddArc(Point const& point, Size const& radius, float rotation, bool clockwise = true, bool is_small = true);
|
void AddArc(Point const& point, Size const& radius, float rotation, bool clockwise = true, bool is_small = true);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 以描边的方式绘制路径
|
/// @brief 以描边的方式绘制路径
|
||||||
void StrokePath();
|
void StrokePath();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 以填充的方式绘制路径
|
/// @brief 以填充的方式绘制路径
|
||||||
void FillPath();
|
void FillPath();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 清空画布
|
/// @brief 清空画布
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 清空画布
|
/// @brief 清空画布
|
||||||
/// @param clear_color 清空颜色
|
/// @param clear_color 清空颜色
|
||||||
void Clear(Color const& clear_color);
|
void Clear(Color const& clear_color);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置填充颜色
|
/// @brief 设置填充颜色
|
||||||
/// @param color 填充颜色
|
/// @param color 填充颜色
|
||||||
void SetFillColor(Color const& color);
|
void SetFillColor(Color const& color);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置填充画刷
|
/// @brief 设置填充画刷
|
||||||
/// @param[in] brush 填充画刷
|
/// @param[in] brush 填充画刷
|
||||||
void SetFillBrush(BrushPtr brush);
|
void SetFillBrush(BrushPtr brush);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置轮廓颜色
|
/// @brief 设置轮廓颜色
|
||||||
/// @param color 轮廓颜色
|
/// @param color 轮廓颜色
|
||||||
void SetStrokeColor(Color const& color);
|
void SetStrokeColor(Color const& color);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置轮廓画刷
|
/// @brief 设置轮廓画刷
|
||||||
/// @param[in] brush 轮廓画刷
|
/// @param[in] brush 轮廓画刷
|
||||||
void SetStrokeBrush(BrushPtr brush);
|
void SetStrokeBrush(BrushPtr brush);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置轮廓宽度
|
/// @brief 设置轮廓宽度
|
||||||
/// @param width 轮廓宽度
|
/// @param width 轮廓宽度
|
||||||
void SetStrokeWidth(float width);
|
void SetStrokeWidth(float width);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置轮廓样式
|
/// @brief 设置轮廓样式
|
||||||
/// @param stroke_style 轮廓样式
|
/// @param stroke_style 轮廓样式
|
||||||
void SetStrokeStyle(StrokeStylePtr stroke_style);
|
void SetStrokeStyle(StrokeStylePtr stroke_style);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置文字画刷样式
|
/// @brief 设置文字画刷样式
|
||||||
/// @param text_style 文字画刷样式
|
/// @param text_style 文字画刷样式
|
||||||
void SetTextStyle(TextStyle const& text_style);
|
void SetTextStyle(TextStyle const& text_style);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置画刷
|
/// @brief 设置画刷
|
||||||
/// @param[in] brush 画刷
|
/// @param[in] brush 画刷
|
||||||
void SetBrush(BrushPtr brush);
|
void SetBrush(BrushPtr brush);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置画刷二维变换
|
/// @brief 设置画刷二维变换
|
||||||
/// @param transform 二维变换
|
/// @param transform 二维变换
|
||||||
void SetBrushTransform(Transform const& transform);
|
void SetBrushTransform(Transform const& transform);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置画刷二维变换矩阵
|
/// @brief 设置画刷二维变换矩阵
|
||||||
/// @param transform 二维变换矩阵
|
/// @param transform 二维变换矩阵
|
||||||
void SetBrushTransform(Matrix3x2 const& transform);
|
void SetBrushTransform(Matrix3x2 const& transform);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加一个图层
|
/// @brief 添加一个图层
|
||||||
/// @param area 图层区域
|
/// @param layer 图层
|
||||||
void PushLayerArea(LayerArea& area);
|
void PushLayer(Layer& layer);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 删除最近添加的图层
|
/// @brief 删除最近添加的图层
|
||||||
void PopLayerArea();
|
void PopLayer();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加一个裁剪区域
|
/// @brief 添加一个裁剪区域
|
||||||
/// @param clip_rect 裁剪矩形
|
/// @param clip_rect 裁剪矩形
|
||||||
void PushClipRect(Rect const& clip_rect);
|
void PushClipRect(Rect const& clip_rect);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 删除最近添加的裁剪区域
|
/// @brief 删除最近添加的裁剪区域
|
||||||
void PopClipRect();
|
void PopClipRect();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取轮廓宽度
|
/// @brief 获取轮廓宽度
|
||||||
float GetStrokeWidth() const;
|
float GetStrokeWidth() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取填充画刷
|
/// @brief 获取填充画刷
|
||||||
BrushPtr GetFillBrush() const;
|
BrushPtr GetFillBrush() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取轮廓画刷
|
/// @brief 获取轮廓画刷
|
||||||
BrushPtr GetStrokeBrush() const;
|
BrushPtr GetStrokeBrush() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 导出纹理
|
/// @brief 清空画布大小并重设画布大小
|
||||||
|
void ResizeAndClear(Size size);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 导出纹理
|
||||||
TexturePtr ExportToTexture() const;
|
TexturePtr ExportToTexture() const;
|
||||||
|
|
||||||
void OnRender(RenderContext& ctx) override;
|
void OnRender(RenderContext& ctx) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitRenderTargetAndBrushs();
|
Canvas();
|
||||||
|
|
||||||
void UpdateCache() const;
|
void UpdateCache() const;
|
||||||
|
|
||||||
|
|
@ -298,6 +298,11 @@ private:
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
inline float Canvas::GetStrokeWidth() const
|
||||||
|
{
|
||||||
|
return stroke_width_;
|
||||||
|
}
|
||||||
|
|
||||||
inline void Canvas::SetStrokeWidth(float width)
|
inline void Canvas::SetStrokeWidth(float width)
|
||||||
{
|
{
|
||||||
stroke_width_ = std::max(width, 0.f);
|
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)
|
inline void Canvas::SetStrokeColor(Color const& color)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
if (!stroke_brush_)
|
||||||
|
{
|
||||||
|
stroke_brush_ = new Brush;
|
||||||
|
}
|
||||||
stroke_brush_->SetColor(color);
|
stroke_brush_->SetColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Canvas::SetFillColor(Color const& color)
|
inline void Canvas::SetFillColor(Color const& color)
|
||||||
{
|
{
|
||||||
InitRenderTargetAndBrushs();
|
if (!fill_brush_)
|
||||||
|
{
|
||||||
|
fill_brush_ = new Brush;
|
||||||
|
}
|
||||||
fill_brush_->SetColor(color);
|
fill_brush_->SetColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -344,4 +355,5 @@ inline BrushPtr Canvas::GetStrokeBrush() const
|
||||||
{
|
{
|
||||||
return stroke_brush_;
|
return stroke_brush_;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace kiwano
|
} // namespace kiwano
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class comma_numpunct : public std::numpunct<wchar_t>
|
||||||
private:
|
private:
|
||||||
virtual wchar_t do_thousands_sep() const override
|
virtual wchar_t do_thousands_sep() const override
|
||||||
{
|
{
|
||||||
return L',';
|
return ',';
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string do_grouping() const override
|
virtual std::string do_grouping() const override
|
||||||
|
|
@ -46,7 +46,7 @@ private:
|
||||||
|
|
||||||
DebugActor::DebugActor()
|
DebugActor::DebugActor()
|
||||||
{
|
{
|
||||||
SetName(L"kiwano-debug-actor");
|
SetName("kiwano-debug-actor");
|
||||||
SetPosition(Point{ 10, 10 });
|
SetPosition(Point{ 10, 10 });
|
||||||
SetResponsible(true);
|
SetResponsible(true);
|
||||||
SetCascadeOpacityEnabled(true);
|
SetCascadeOpacityEnabled(true);
|
||||||
|
|
@ -60,7 +60,7 @@ DebugActor::DebugActor()
|
||||||
fill_brush->SetColor(Color::White);
|
fill_brush->SetColor(Color::White);
|
||||||
|
|
||||||
TextStyle style;
|
TextStyle style;
|
||||||
style.font_family = L"Arial";
|
style.font_family = "Arial";
|
||||||
style.font_size = 16.f;
|
style.font_size = 16.f;
|
||||||
style.font_weight = FontWeight::Normal;
|
style.font_weight = FontWeight::Normal;
|
||||||
style.line_spacing = 20.f;
|
style.line_spacing = 20.f;
|
||||||
|
|
@ -78,17 +78,17 @@ void DebugActor::OnRender(RenderContext& ctx)
|
||||||
ctx.SetCurrentBrush(background_brush_);
|
ctx.SetCurrentBrush(background_brush_);
|
||||||
ctx.FillRoundedRectangle(GetBounds(), Vec2{ 5.f, 5.f });
|
ctx.FillRoundedRectangle(GetBounds(), Vec2{ 5.f, 5.f });
|
||||||
ctx.DrawTextLayout(debug_text_, Point(10, 10));
|
ctx.DrawTextLayout(debug_text_, Point(10, 10));
|
||||||
}
|
|
||||||
|
|
||||||
void DebugActor::OnUpdate(Duration dt)
|
|
||||||
{
|
|
||||||
KGE_NOT_USED(dt);
|
|
||||||
|
|
||||||
frame_time_.push_back(Time::Now());
|
frame_time_.push_back(Time::Now());
|
||||||
while (frame_time_.back() - frame_time_.front() >= Duration::Second)
|
while (frame_time_.back() - frame_time_.front() >= Duration::Second)
|
||||||
{
|
{
|
||||||
frame_time_.erase(frame_time_.begin());
|
frame_time_.erase(frame_time_.begin());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugActor::OnUpdate(Duration dt)
|
||||||
|
{
|
||||||
|
KGE_NOT_USED(dt);
|
||||||
|
|
||||||
StringStream ss;
|
StringStream ss;
|
||||||
|
|
||||||
|
|
@ -104,7 +104,7 @@ void DebugActor::OnUpdate(Duration dt)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const auto& status = Renderer::Instance().GetContext().GetStatus();
|
const auto& status = Renderer::GetInstance().GetContext().GetStatus();
|
||||||
|
|
||||||
ss << "Render: " << status.duration.Milliseconds() << "ms" << std::endl;
|
ss << "Render: " << status.duration.Milliseconds() << "ms" << std::endl;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace kiwano
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 调试节点
|
* @brief 调试节点
|
||||||
*/
|
*/
|
||||||
class KGE_API DebugActor : public Actor
|
class KGE_API DebugActor : public Actor
|
||||||
{
|
{
|
||||||
|
|
@ -51,7 +51,7 @@ private:
|
||||||
std::locale comma_locale_;
|
std::locale comma_locale_;
|
||||||
BrushPtr background_brush_;
|
BrushPtr background_brush_;
|
||||||
TextLayout debug_text_;
|
TextLayout debug_text_;
|
||||||
Vector<Time> frame_time_;
|
List<Time> frame_time_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ Frame::Frame() {}
|
||||||
|
|
||||||
bool Frame::Load(String const& file_path)
|
bool Frame::Load(String const& file_path)
|
||||||
{
|
{
|
||||||
TexturePtr texture = TextureCache::Instance().AddOrGetTexture(file_path);
|
TexturePtr texture = TextureCache::GetInstance().AddOrGetTexture(file_path);
|
||||||
if (texture->IsValid())
|
if (texture->IsValid())
|
||||||
{
|
{
|
||||||
SetTexture(texture);
|
SetTexture(texture);
|
||||||
|
|
@ -71,7 +71,7 @@ bool Frame::Load(String const& file_path)
|
||||||
|
|
||||||
bool Frame::Load(Resource const& res)
|
bool Frame::Load(Resource const& res)
|
||||||
{
|
{
|
||||||
TexturePtr texture = TextureCache::Instance().AddOrGetTexture(res);
|
TexturePtr texture = TextureCache::GetInstance().AddOrGetTexture(res);
|
||||||
if (texture->IsValid())
|
if (texture->IsValid())
|
||||||
{
|
{
|
||||||
SetTexture(texture);
|
SetTexture(texture);
|
||||||
|
|
|
||||||
|
|
@ -28,76 +28,76 @@ KGE_DECLARE_SMART_PTR(Frame);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 图像帧
|
* @brief 图像帧
|
||||||
*/
|
*/
|
||||||
class KGE_API Frame : public virtual ObjectBase
|
class KGE_API Frame : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建图像帧
|
/// @brief 创建图像帧
|
||||||
/// @param file_path 图像路径
|
/// @param file_path 图像路径
|
||||||
static FramePtr Create(String const& file_path);
|
static FramePtr Create(String const& file_path);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建图像帧
|
/// @brief 创建图像帧
|
||||||
/// @param res 图像资源
|
/// @param res 图像资源
|
||||||
static FramePtr Create(Resource const& res);
|
static FramePtr Create(Resource const& res);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建图像帧
|
/// @brief 创建图像帧
|
||||||
/// @param texture 纹理
|
/// @param texture 纹理
|
||||||
static FramePtr Create(TexturePtr texture);
|
static FramePtr Create(TexturePtr texture);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构建空图像帧
|
/// @brief 构建空图像帧
|
||||||
Frame();
|
Frame();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 加载图像
|
/// @brief 加载图像
|
||||||
/// @param file_path 图像路径
|
/// @param file_path 图像路径
|
||||||
bool Load(String const& file_path);
|
bool Load(String const& file_path);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 加载图像
|
/// @brief 加载图像
|
||||||
/// @param res 图像资源
|
/// @param res 图像资源
|
||||||
bool Load(Resource const& res);
|
bool Load(Resource const& res);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 裁剪图像帧为矩形
|
/// @brief 裁剪图像帧为矩形
|
||||||
/// @param crop_rect 裁剪矩形定义
|
/// @param crop_rect 裁剪矩形定义
|
||||||
void SetCropRect(Rect const& crop_rect);
|
void SetCropRect(Rect const& crop_rect);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置纹理
|
/// @brief 设置纹理
|
||||||
/// @param texture 纹理
|
/// @param texture 纹理
|
||||||
void SetTexture(TexturePtr texture);
|
void SetTexture(TexturePtr texture);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否有效
|
/// @brief 是否有效
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取宽度
|
/// @brief 获取宽度
|
||||||
float GetWidth() const;
|
float GetWidth() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取高度
|
/// @brief 获取高度
|
||||||
float GetHeight() const;
|
float GetHeight() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取大小
|
/// @brief 获取大小
|
||||||
Size GetSize() const;
|
Size GetSize() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取裁剪位置
|
/// @brief 获取裁剪位置
|
||||||
Point GetCropPoint() const;
|
Point GetCropPoint() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取裁剪矩形
|
/// @brief 获取裁剪矩形
|
||||||
Rect const& GetCropRect() const;
|
Rect const& GetCropRect() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取纹理
|
/// @brief 获取纹理
|
||||||
TexturePtr GetTexture() const;
|
TexturePtr GetTexture() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -29,51 +29,51 @@ KGE_DECLARE_SMART_PTR(FrameSequence);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 序列帧
|
* @brief 序列帧
|
||||||
*/
|
*/
|
||||||
class KGE_API FrameSequence : public virtual ObjectBase
|
class KGE_API FrameSequence : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建序列帧
|
/// @brief 创建序列帧
|
||||||
/// @param frames 图像帧集合
|
/// @param frames 图像帧集合
|
||||||
static FrameSequencePtr Create(Vector<FramePtr> const& frames);
|
static FrameSequencePtr Create(Vector<FramePtr> const& frames);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构建空序列帧
|
/// @brief 构建空序列帧
|
||||||
FrameSequence();
|
FrameSequence();
|
||||||
|
|
||||||
virtual ~FrameSequence();
|
virtual ~FrameSequence();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加关键帧
|
/// @brief 添加关键帧
|
||||||
/// @param frame 图像帧
|
/// @param frame 图像帧
|
||||||
void AddFrame(FramePtr frame);
|
void AddFrame(FramePtr frame);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加多个关键帧
|
/// @brief 添加多个关键帧
|
||||||
/// @param frames 图像帧集合
|
/// @param frames 图像帧集合
|
||||||
void AddFrames(Vector<FramePtr> const& frames);
|
void AddFrames(Vector<FramePtr> const& frames);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关键帧
|
/// @brief 获取关键帧
|
||||||
/// @param index 图像帧下标
|
/// @param index 图像帧下标
|
||||||
FramePtr GetFrame(size_t index) const;
|
FramePtr GetFrame(size_t index) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取所有关键帧
|
/// @brief 获取所有关键帧
|
||||||
Vector<FramePtr> const& GetFrames() const;
|
Vector<FramePtr> const& GetFrames() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关键帧数量
|
/// @brief 获取关键帧数量
|
||||||
size_t GetFramesCount() const;
|
size_t GetFramesCount() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取序列帧的拷贝对象
|
/// @brief 获取序列帧的拷贝对象
|
||||||
FrameSequencePtr Clone() const;
|
FrameSequencePtr Clone() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取序列帧的倒转
|
/// @brief 获取序列帧的倒转
|
||||||
FrameSequencePtr Reverse() const;
|
FrameSequencePtr Reverse() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -67,13 +67,13 @@ GifSprite::GifSprite()
|
||||||
|
|
||||||
bool GifSprite::Load(String const& file_path)
|
bool GifSprite::Load(String const& file_path)
|
||||||
{
|
{
|
||||||
GifImagePtr image = TextureCache::Instance().AddOrGetGifImage(file_path);
|
GifImagePtr image = TextureCache::GetInstance().AddOrGetGifImage(file_path);
|
||||||
return Load(image);
|
return Load(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GifSprite::Load(Resource const& res)
|
bool GifSprite::Load(Resource const& res)
|
||||||
{
|
{
|
||||||
GifImagePtr image = TextureCache::Instance().AddOrGetGifImage(res);
|
GifImagePtr image = TextureCache::GetInstance().AddOrGetGifImage(res);
|
||||||
return Load(image);
|
return Load(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,15 +85,16 @@ bool GifSprite::Load(GifImagePtr gif)
|
||||||
|
|
||||||
next_index_ = 0;
|
next_index_ = 0;
|
||||||
loop_count_ = 0;
|
loop_count_ = 0;
|
||||||
frame_.disposal_type = GifImage::DisposalType::None;
|
frame_ = GifImage::Frame();
|
||||||
|
|
||||||
SetSize(Size{ static_cast<float>(gif_->GetWidthInPixels()), static_cast<float>(gif_->GetHeightInPixels()) });
|
|
||||||
|
|
||||||
if (!frame_rt_)
|
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)
|
if (gif_->GetFramesCount() > 0)
|
||||||
{
|
{
|
||||||
ComposeNextFrame();
|
ComposeNextFrame();
|
||||||
|
|
@ -109,7 +110,7 @@ void GifSprite::OnRender(RenderContext& ctx)
|
||||||
{
|
{
|
||||||
PrepareToRender(ctx);
|
PrepareToRender(ctx);
|
||||||
|
|
||||||
ctx.DrawTexture(*frame_to_render_, &frame_.rect, nullptr);
|
ctx.DrawTexture(*frame_to_render_, nullptr, &GetBounds());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,7 +141,7 @@ void GifSprite::RestartAnimation()
|
||||||
animating_ = true;
|
animating_ = true;
|
||||||
next_index_ = 0;
|
next_index_ = 0;
|
||||||
loop_count_ = 0;
|
loop_count_ = 0;
|
||||||
frame_.disposal_type = GifImage::DisposalType::None;
|
frame_ = GifImage::Frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GifSprite::ComposeNextFrame()
|
void GifSprite::ComposeNextFrame()
|
||||||
|
|
@ -181,7 +182,7 @@ void GifSprite::DisposeCurrentFrame()
|
||||||
void GifSprite::OverlayNextFrame()
|
void GifSprite::OverlayNextFrame()
|
||||||
{
|
{
|
||||||
KGE_ASSERT(frame_rt_);
|
KGE_ASSERT(frame_rt_);
|
||||||
KGE_ASSERT(gif_ && gif_->IsValid());
|
KGE_ASSERT(gif_);
|
||||||
|
|
||||||
frame_ = gif_->GetFrame(next_index_);
|
frame_ = gif_->GetFrame(next_index_);
|
||||||
|
|
||||||
|
|
@ -196,6 +197,7 @@ void GifSprite::OverlayNextFrame()
|
||||||
|
|
||||||
if (next_index_ == 0)
|
if (next_index_ == 0)
|
||||||
{
|
{
|
||||||
|
frame_rt_->Clear();
|
||||||
loop_count_++;
|
loop_count_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,6 +219,7 @@ void GifSprite::OverlayNextFrame()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute callback
|
||||||
if (IsLastFrame() && loop_cb_)
|
if (IsLastFrame() && loop_cb_)
|
||||||
{
|
{
|
||||||
loop_cb_(loop_count_ - 1);
|
loop_cb_(loop_count_ - 1);
|
||||||
|
|
@ -239,8 +242,7 @@ void GifSprite::SaveComposedFrame()
|
||||||
if (!saved_frame_)
|
if (!saved_frame_)
|
||||||
{
|
{
|
||||||
saved_frame_ = new Texture;
|
saved_frame_ = new Texture;
|
||||||
frame_rt_->CreateTexture(*saved_frame_, frame_to_be_saved->GetSizeInPixels(),
|
frame_rt_->CreateTexture(*saved_frame_, frame_to_be_saved->GetSizeInPixels());
|
||||||
frame_to_be_saved->GetPixelFormat());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saved_frame_->CopyFrom(frame_to_be_saved);
|
saved_frame_->CopyFrom(frame_to_be_saved);
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
#include <kiwano/2d/Actor.h>
|
#include <kiwano/2d/Actor.h>
|
||||||
#include <kiwano/core/Resource.h>
|
#include <kiwano/core/Resource.h>
|
||||||
#include <kiwano/render/GifImage.h>
|
#include <kiwano/render/GifImage.h>
|
||||||
#include <kiwano/render/RenderContext.h>
|
#include <kiwano/render/TextureRenderContext.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
@ -35,81 +35,81 @@ KGE_DECLARE_SMART_PTR(GifSprite);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief GIF 精灵
|
* @brief GIF 精灵
|
||||||
*/
|
*/
|
||||||
class KGE_API GifSprite : public Actor
|
class KGE_API GifSprite : public Actor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief GIF播放循环结束回调
|
/// @brief GIF播放循环结束回调
|
||||||
using LoopDoneCallback = Function<void(int /* times */)>;
|
using LoopDoneCallback = Function<void(int /* times */)>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief GIF播放结束回调
|
/// @brief GIF播放结束回调
|
||||||
using DoneCallback = Function<void()>;
|
using DoneCallback = Function<void()>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建GIF精灵
|
/// @brief 创建GIF精灵
|
||||||
/// @param file_path GIF图片路径
|
/// @param file_path GIF图片路径
|
||||||
static GifSpritePtr Create(String const& file_path);
|
static GifSpritePtr Create(String const& file_path);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建GIF精灵
|
/// @brief 创建GIF精灵
|
||||||
/// @param res GIF图片资源
|
/// @param res GIF图片资源
|
||||||
static GifSpritePtr Create(Resource const& res);
|
static GifSpritePtr Create(Resource const& res);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建GIF精灵
|
/// @brief 创建GIF精灵
|
||||||
/// @param gif GIF图片
|
/// @param gif GIF图片
|
||||||
static GifSpritePtr Create(GifImagePtr gif);
|
static GifSpritePtr Create(GifImagePtr gif);
|
||||||
|
|
||||||
GifSprite();
|
GifSprite();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 加载GIF图片
|
/// @brief 加载GIF图片
|
||||||
/// @param file_path GIF图片路径
|
/// @param file_path GIF图片路径
|
||||||
bool Load(String const& file_path);
|
bool Load(String const& file_path);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 加载GIF图片
|
/// @brief 加载GIF图片
|
||||||
/// @param res GIF图片资源
|
/// @param res GIF图片资源
|
||||||
bool Load(Resource const& res);
|
bool Load(Resource const& res);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 加载GIF图片
|
/// @brief 加载GIF图片
|
||||||
/// @param gif GIF图片
|
/// @param gif GIF图片
|
||||||
bool Load(GifImagePtr gif);
|
bool Load(GifImagePtr gif);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置 GIF 动画循环次数
|
/// @brief 设置 GIF 动画循环次数
|
||||||
void SetLoopCount(int loops);
|
void SetLoopCount(int loops);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置 GIF 动画每次循环结束回调函数
|
/// @brief 设置 GIF 动画每次循环结束回调函数
|
||||||
void SetLoopDoneCallback(LoopDoneCallback const& cb);
|
void SetLoopDoneCallback(LoopDoneCallback const& cb);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置 GIF 动画结束回调函数
|
/// @brief 设置 GIF 动画结束回调函数
|
||||||
void SetDoneCallback(DoneCallback const& cb);
|
void SetDoneCallback(DoneCallback const& cb);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置 GIF 图像
|
/// @brief 设置 GIF 图像
|
||||||
void SetGifImage(GifImagePtr gif);
|
void SetGifImage(GifImagePtr gif);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 重新播放 GIF 动画
|
/// @brief 重新播放 GIF 动画
|
||||||
void RestartAnimation();
|
void RestartAnimation();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取 GIF 动画循环结束回调
|
/// @brief 获取 GIF 动画循环结束回调
|
||||||
LoopDoneCallback GetLoopDoneCallback() const;
|
LoopDoneCallback GetLoopDoneCallback() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取 GIF 动画播放结束回调
|
/// @brief 获取 GIF 动画播放结束回调
|
||||||
DoneCallback GetDoneCallback() const;
|
DoneCallback GetDoneCallback() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取 GIF 图片
|
/// @brief 获取 GIF 图片
|
||||||
GifImagePtr GetGifImage() const;
|
GifImagePtr GetGifImage() const;
|
||||||
|
|
||||||
void OnRender(RenderContext& ctx) override;
|
void OnRender(RenderContext& ctx) override;
|
||||||
|
|
@ -118,35 +118,35 @@ private:
|
||||||
void Update(Duration dt) override;
|
void Update(Duration dt) override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否是最后一帧
|
/// @brief 是否是最后一帧
|
||||||
bool IsLastFrame() const;
|
bool IsLastFrame() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画是否已结束
|
/// @brief 动画是否已结束
|
||||||
bool EndOfAnimation() const;
|
bool EndOfAnimation() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 合成下一帧
|
/// @brief 合成下一帧
|
||||||
void ComposeNextFrame();
|
void ComposeNextFrame();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 解析当前图像帧
|
/// @brief 解析当前图像帧
|
||||||
void DisposeCurrentFrame();
|
void DisposeCurrentFrame();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 覆盖下一帧
|
/// @brief 覆盖下一帧
|
||||||
void OverlayNextFrame();
|
void OverlayNextFrame();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 保存合成后的图像帧
|
/// @brief 保存合成后的图像帧
|
||||||
void SaveComposedFrame();
|
void SaveComposedFrame();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 恢复已保存的图像帧
|
/// @brief 恢复已保存的图像帧
|
||||||
void RestoreSavedFrame();
|
void RestoreSavedFrame();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 清空当前图像区域
|
/// @brief 清空当前图像区域
|
||||||
void ClearCurrentFrameArea();
|
void ClearCurrentFrameArea();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -19,47 +19,47 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/2d/Layer.h>
|
#include <kiwano/2d/LayerActor.h>
|
||||||
#include <kiwano/render/Renderer.h>
|
#include <kiwano/render/Renderer.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
||||||
LayerPtr Layer::Create()
|
LayerActorPtr LayerActor::Create()
|
||||||
{
|
{
|
||||||
LayerPtr ptr = new (std::nothrow) Layer;
|
LayerActorPtr ptr = new (std::nothrow) LayerActor;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Layer::Layer()
|
LayerActor::LayerActor()
|
||||||
: swallow_(false)
|
: 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);
|
// 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())
|
if (!IsVisible())
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -71,18 +71,18 @@ bool Layer::DispatchEvent(Event* evt)
|
||||||
return Actor::DispatchEvent(evt);
|
return Actor::DispatchEvent(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::Render(RenderContext& ctx)
|
void LayerActor::Render(RenderContext& ctx)
|
||||||
{
|
{
|
||||||
ctx.PushLayer(area_);
|
ctx.PushLayer(layer_);
|
||||||
|
|
||||||
Actor::Render(ctx);
|
Actor::Render(ctx);
|
||||||
|
|
||||||
ctx.PopLayer();
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -20,12 +20,12 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/2d/Actor.h>
|
#include <kiwano/2d/Actor.h>
|
||||||
#include <kiwano/render/LayerArea.h>
|
#include <kiwano/render/Layer.h>
|
||||||
#include <kiwano/render/RenderContext.h>
|
#include <kiwano/render/RenderContext.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
KGE_DECLARE_SMART_PTR(Layer);
|
KGE_DECLARE_SMART_PTR(LayerActor);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \addtogroup Actors
|
* \addtogroup Actors
|
||||||
|
|
@ -34,56 +34,56 @@ KGE_DECLARE_SMART_PTR(Layer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 图层
|
* @brief 图层
|
||||||
*/
|
*/
|
||||||
class KGE_API Layer : public Actor
|
class KGE_API LayerActor : public Actor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建图层
|
/// @brief 创建图层
|
||||||
static LayerPtr Create();
|
static LayerActorPtr Create();
|
||||||
|
|
||||||
Layer();
|
LayerActor();
|
||||||
|
|
||||||
virtual ~Layer();
|
virtual ~LayerActor();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否开启消息吞没
|
/// @brief 是否开启消息吞没
|
||||||
bool IsSwallowEventsEnabled() const;
|
bool IsSwallowEventsEnabled() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置消息吞没功能
|
/// @brief 设置消息吞没功能
|
||||||
/// @param enabled 是否启用
|
/// @param enabled 是否启用
|
||||||
void SetSwallowEvents(bool enabled);
|
void SetSwallowEvents(bool enabled);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置裁剪区域
|
/// @brief 设置裁剪区域
|
||||||
/// @param clip_rect 裁剪矩形
|
/// @param clip_rect 裁剪矩形
|
||||||
void SetClipRect(Rect const& clip_rect);
|
void SetClipRect(Rect const& clip_rect);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置图层透明度
|
/// @brief 设置图层透明度
|
||||||
/// @param opacity 透明度
|
/// @param opacity 透明度
|
||||||
void SetOpacity(float opacity) override;
|
void SetOpacity(float opacity) override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置几何蒙层
|
/// @brief 设置几何蒙层
|
||||||
/// @param mask 蒙层的形状
|
/// @param mask 蒙层的形状
|
||||||
void SetMaskShape(ShapePtr mask);
|
void SetMaskShape(ShapePtr mask);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置几何蒙层的二维变换
|
/// @brief 设置几何蒙层的二维变换
|
||||||
/// @param transform 应用于蒙层的二维变换
|
/// @param transform 应用于蒙层的二维变换
|
||||||
void SetMaskTransform(Matrix3x2 const& transform);
|
void SetMaskTransform(Matrix3x2 const& transform);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置图层区域
|
/// @brief 设置图层区域
|
||||||
/// @param area 图层区域属性
|
/// @param area 图层区域属性
|
||||||
void SetArea(LayerArea const& area);
|
void SetLayer(Layer const& layer);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取图层区域
|
/// @brief 获取图层区域
|
||||||
LayerArea const& GetArea() const;
|
Layer const& GetLayer() const;
|
||||||
|
|
||||||
bool DispatchEvent(Event* evt) override;
|
bool DispatchEvent(Event* evt) override;
|
||||||
|
|
||||||
|
|
@ -94,28 +94,28 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool swallow_;
|
bool swallow_;
|
||||||
LayerArea area_;
|
Layer layer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
inline bool Layer::IsSwallowEventsEnabled() const
|
inline bool LayerActor::IsSwallowEventsEnabled() const
|
||||||
{
|
{
|
||||||
return swallow_;
|
return swallow_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Layer::SetSwallowEvents(bool enabled)
|
inline void LayerActor::SetSwallowEvents(bool enabled)
|
||||||
{
|
{
|
||||||
swallow_ = 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
|
} // namespace kiwano
|
||||||
|
|
@ -91,7 +91,7 @@ void ShapeActor::OnRender(RenderContext& ctx)
|
||||||
if (stroke_brush_)
|
if (stroke_brush_)
|
||||||
{
|
{
|
||||||
ctx.SetCurrentBrush(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_)
|
if (fill_brush_)
|
||||||
|
|
|
||||||
|
|
@ -43,83 +43,83 @@ KGE_DECLARE_SMART_PTR(PolygonActor);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 形状角色
|
* @brief 形状角色
|
||||||
*/
|
*/
|
||||||
class KGE_API ShapeActor : public Actor
|
class KGE_API ShapeActor : public Actor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建形状角色
|
/// @brief 创建形状角色
|
||||||
static ShapeActorPtr Create();
|
static ShapeActorPtr Create();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造形状角色
|
/// @brief 构造形状角色
|
||||||
ShapeActor();
|
ShapeActor();
|
||||||
|
|
||||||
virtual ~ShapeActor();
|
virtual ~ShapeActor();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取填充画刷
|
/// @brief 获取填充画刷
|
||||||
BrushPtr GetFillBrush() const;
|
BrushPtr GetFillBrush() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取轮廓画刷
|
/// @brief 获取轮廓画刷
|
||||||
BrushPtr GetStrokeBrush() const;
|
BrushPtr GetStrokeBrush() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取线条宽度
|
/// @brief 获取线条宽度
|
||||||
float GetStrokeWidth() const;
|
float GetStrokeWidth() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取线条样式
|
/// @brief 获取线条样式
|
||||||
StrokeStylePtr GetStrokeStyle() const;
|
StrokeStylePtr GetStrokeStyle() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取形状
|
/// @brief 获取形状
|
||||||
ShapePtr GetShape() const;
|
ShapePtr GetShape() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取边界
|
/// @brief 获取边界
|
||||||
Rect GetBounds() const override;
|
Rect GetBounds() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取外切包围盒
|
/// @brief 获取外切包围盒
|
||||||
Rect GetBoundingBox() const override;
|
Rect GetBoundingBox() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 判断点是否在形状内
|
/// @brief 判断点是否在形状内
|
||||||
bool ContainsPoint(const Point& point) const override;
|
bool ContainsPoint(const Point& point) const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置填充颜色
|
/// @brief 设置填充颜色
|
||||||
/// @param color 填充颜色
|
/// @param color 填充颜色
|
||||||
void SetFillColor(Color const& color);
|
void SetFillColor(Color const& color);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置填充画刷
|
/// @brief 设置填充画刷
|
||||||
/// @param[in] brush 填充画刷
|
/// @param[in] brush 填充画刷
|
||||||
void SetFillBrush(BrushPtr brush);
|
void SetFillBrush(BrushPtr brush);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置轮廓颜色
|
/// @brief 设置轮廓颜色
|
||||||
/// @param color 轮廓颜色
|
/// @param color 轮廓颜色
|
||||||
void SetStrokeColor(Color const& color);
|
void SetStrokeColor(Color const& color);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置轮廓画刷
|
/// @brief 设置轮廓画刷
|
||||||
/// @param[in] brush 轮廓画刷
|
/// @param[in] brush 轮廓画刷
|
||||||
void SetStrokeBrush(BrushPtr brush);
|
void SetStrokeBrush(BrushPtr brush);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置线条宽度,默认为 1.0
|
/// @brief 设置线条宽度,默认为 1.0
|
||||||
void SetStrokeWidth(float width);
|
void SetStrokeWidth(float width);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置线条样式
|
/// @brief 设置线条样式
|
||||||
void SetStrokeStyle(StrokeStylePtr stroke_style);
|
void SetStrokeStyle(StrokeStylePtr stroke_style);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置形状
|
/// @brief 设置形状
|
||||||
void SetShape(ShapePtr shape);
|
void SetShape(ShapePtr shape);
|
||||||
|
|
||||||
void OnRender(RenderContext& ctx) override;
|
void OnRender(RenderContext& ctx) override;
|
||||||
|
|
@ -137,14 +137,14 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 线段角色
|
/// @brief 线段角色
|
||||||
class KGE_API LineActor : public ShapeActor
|
class KGE_API LineActor : public ShapeActor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建线段角色
|
/// @brief 创建线段角色
|
||||||
/// @param begin 线段起点
|
/// @param begin 线段起点
|
||||||
/// @param end 线段终点
|
/// @param end 线段终点
|
||||||
static LineActorPtr Create(Point const& begin, Point const& end);
|
static LineActorPtr Create(Point const& begin, Point const& end);
|
||||||
|
|
||||||
LineActor();
|
LineActor();
|
||||||
|
|
@ -152,27 +152,27 @@ public:
|
||||||
virtual ~LineActor();
|
virtual ~LineActor();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取线段起点
|
/// @brief 获取线段起点
|
||||||
Point const& GetBeginPoint() const;
|
Point const& GetBeginPoint() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取线段终点
|
/// @brief 获取线段终点
|
||||||
Point const& GetEndPoint() const;
|
Point const& GetEndPoint() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置线段起点
|
/// @brief 设置线段起点
|
||||||
/// @param begin 线段起点
|
/// @param begin 线段起点
|
||||||
void SetBeginPoint(Point const& begin);
|
void SetBeginPoint(Point const& begin);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置线段终点
|
/// @brief 设置线段终点
|
||||||
/// @param end 线段终点
|
/// @param end 线段终点
|
||||||
void SetEndPoint(Point const& end);
|
void SetEndPoint(Point const& end);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置线段起点和终点
|
/// @brief 设置线段起点和终点
|
||||||
/// @param begin 线段起点
|
/// @param begin 线段起点
|
||||||
/// @param end 线段终点
|
/// @param end 线段终点
|
||||||
void SetLine(Point const& begin, Point const& end);
|
void SetLine(Point const& begin, Point const& end);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -181,13 +181,13 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 矩形角色
|
/// @brief 矩形角色
|
||||||
class KGE_API RectActor : public ShapeActor
|
class KGE_API RectActor : public ShapeActor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建矩形角色
|
/// @brief 创建矩形角色
|
||||||
/// @param size 矩形大小
|
/// @param size 矩形大小
|
||||||
static RectActorPtr Create(Size const& size);
|
static RectActorPtr Create(Size const& size);
|
||||||
|
|
||||||
RectActor();
|
RectActor();
|
||||||
|
|
@ -195,12 +195,12 @@ public:
|
||||||
virtual ~RectActor();
|
virtual ~RectActor();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取矩形大小
|
/// @brief 获取矩形大小
|
||||||
Size const& GetRectSize() const;
|
Size const& GetRectSize() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置矩形大小
|
/// @brief 设置矩形大小
|
||||||
/// @param size 矩形大小
|
/// @param size 矩形大小
|
||||||
void SetRectSize(Size const& size);
|
void SetRectSize(Size const& size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -208,14 +208,14 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 圆角矩形角色
|
/// @brief 圆角矩形角色
|
||||||
class KGE_API RoundedRectActor : public ShapeActor
|
class KGE_API RoundedRectActor : public ShapeActor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建圆角矩形角色
|
/// @brief 创建圆角矩形角色
|
||||||
/// @param size 圆角矩形大小
|
/// @param size 圆角矩形大小
|
||||||
/// @param radius 圆角半径
|
/// @param radius 圆角半径
|
||||||
static RoundedRectActorPtr Create(Size const& size, Vec2 const& radius);
|
static RoundedRectActorPtr Create(Size const& size, Vec2 const& radius);
|
||||||
|
|
||||||
RoundedRectActor();
|
RoundedRectActor();
|
||||||
|
|
@ -223,27 +223,27 @@ public:
|
||||||
virtual ~RoundedRectActor();
|
virtual ~RoundedRectActor();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取圆角半径
|
/// @brief 获取圆角半径
|
||||||
Vec2 GetRadius() const;
|
Vec2 GetRadius() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取圆角矩形大小
|
/// @brief 获取圆角矩形大小
|
||||||
Size GetRectSize() const;
|
Size GetRectSize() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置圆角半径
|
/// @brief 设置圆角半径
|
||||||
/// @param radius 圆角半径
|
/// @param radius 圆角半径
|
||||||
void SetRadius(Vec2 const& radius);
|
void SetRadius(Vec2 const& radius);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置圆角矩形大小
|
/// @brief 设置圆角矩形大小
|
||||||
/// @param size 圆角矩形大小
|
/// @param size 圆角矩形大小
|
||||||
void SetRectSize(Size const& size);
|
void SetRectSize(Size const& size);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置圆角矩形
|
/// @brief 设置圆角矩形
|
||||||
/// @param size 圆角矩形大小
|
/// @param size 圆角矩形大小
|
||||||
/// @param radius 圆角半径
|
/// @param radius 圆角半径
|
||||||
void SetRoundedRect(Size const& size, Vec2 const& radius);
|
void SetRoundedRect(Size const& size, Vec2 const& radius);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -252,13 +252,13 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 圆形角色
|
/// @brief 圆形角色
|
||||||
class KGE_API CircleActor : public ShapeActor
|
class KGE_API CircleActor : public ShapeActor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建圆形角色
|
/// @brief 创建圆形角色
|
||||||
/// @param radius 圆形半径
|
/// @param radius 圆形半径
|
||||||
static CircleActorPtr Create(float radius);
|
static CircleActorPtr Create(float radius);
|
||||||
|
|
||||||
CircleActor();
|
CircleActor();
|
||||||
|
|
@ -266,12 +266,12 @@ public:
|
||||||
virtual ~CircleActor();
|
virtual ~CircleActor();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取圆形半径
|
/// @brief 获取圆形半径
|
||||||
float GetRadius() const;
|
float GetRadius() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置圆形半径
|
/// @brief 设置圆形半径
|
||||||
/// @param radius 圆形半径
|
/// @param radius 圆形半径
|
||||||
void SetRadius(float radius);
|
void SetRadius(float radius);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -279,13 +279,13 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 椭圆角色
|
/// @brief 椭圆角色
|
||||||
class KGE_API EllipseActor : public ShapeActor
|
class KGE_API EllipseActor : public ShapeActor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建椭圆角色
|
/// @brief 创建椭圆角色
|
||||||
/// @param radius 椭圆半径
|
/// @param radius 椭圆半径
|
||||||
static EllipseActorPtr Create(Vec2 const& radius);
|
static EllipseActorPtr Create(Vec2 const& radius);
|
||||||
|
|
||||||
EllipseActor();
|
EllipseActor();
|
||||||
|
|
@ -293,12 +293,12 @@ public:
|
||||||
virtual ~EllipseActor();
|
virtual ~EllipseActor();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取椭圆半径
|
/// @brief 获取椭圆半径
|
||||||
Vec2 GetRadius() const;
|
Vec2 GetRadius() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置椭圆半径
|
/// @brief 设置椭圆半径
|
||||||
/// @param radius 椭圆半径
|
/// @param radius 椭圆半径
|
||||||
void SetRadius(Vec2 const& radius);
|
void SetRadius(Vec2 const& radius);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -306,13 +306,13 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 多边形角色
|
/// @brief 多边形角色
|
||||||
class KGE_API PolygonActor : public ShapeActor
|
class KGE_API PolygonActor : public ShapeActor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建多边形角色
|
/// @brief 创建多边形角色
|
||||||
/// @param points 多边形端点集合
|
/// @param points 多边形端点集合
|
||||||
static PolygonActorPtr Create(Vector<Point> const& points);
|
static PolygonActorPtr Create(Vector<Point> const& points);
|
||||||
|
|
||||||
PolygonActor();
|
PolygonActor();
|
||||||
|
|
@ -320,8 +320,8 @@ public:
|
||||||
virtual ~PolygonActor();
|
virtual ~PolygonActor();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置多边形端点
|
/// @brief 设置多边形端点
|
||||||
/// @param points 多边形端点集合
|
/// @param points 多边形端点集合
|
||||||
void SetVertices(Vector<Point> const& points);
|
void SetVertices(Vector<Point> const& points);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,24 +33,24 @@ KGE_DECLARE_SMART_PTR(Sprite);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 精灵
|
* @brief 精灵
|
||||||
*/
|
*/
|
||||||
class KGE_API Sprite : public Actor
|
class KGE_API Sprite : public Actor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建精灵
|
/// @brief 创建精灵
|
||||||
/// @param file_path 本地图片路径
|
/// @param file_path 本地图片路径
|
||||||
static SpritePtr Create(String const& file_path);
|
static SpritePtr Create(String const& file_path);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建精灵
|
/// @brief 创建精灵
|
||||||
/// @param res 图片资源
|
/// @param res 图片资源
|
||||||
static SpritePtr Create(Resource const& res);
|
static SpritePtr Create(Resource const& res);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建精灵
|
/// @brief 创建精灵
|
||||||
/// @param frame 图像帧
|
/// @param frame 图像帧
|
||||||
static SpritePtr Create(FramePtr frame);
|
static SpritePtr Create(FramePtr frame);
|
||||||
|
|
||||||
Sprite();
|
Sprite();
|
||||||
|
|
@ -58,27 +58,27 @@ public:
|
||||||
virtual ~Sprite();
|
virtual ~Sprite();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 加载本地图片
|
/// @brief 加载本地图片
|
||||||
/// @param file_path 本地图片路径
|
/// @param file_path 本地图片路径
|
||||||
bool Load(String const& file_path);
|
bool Load(String const& file_path);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 加载图像资源
|
/// @brief 加载图像资源
|
||||||
/// @param res 图片资源
|
/// @param res 图片资源
|
||||||
bool Load(Resource const& res);
|
bool Load(Resource const& res);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 使用矩形区域裁剪精灵
|
/// @brief 使用矩形区域裁剪精灵
|
||||||
/// @param crop_rect 裁剪矩形
|
/// @param crop_rect 裁剪矩形
|
||||||
void SetCropRect(const Rect& crop_rect);
|
void SetCropRect(const Rect& crop_rect);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取帧图像
|
/// @brief 获取帧图像
|
||||||
FramePtr GetFrame() const;
|
FramePtr GetFrame() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置图像帧
|
/// @brief 设置图像帧
|
||||||
/// @param[in] frame 图像帧
|
/// @param[in] frame 图像帧
|
||||||
void SetFrame(FramePtr frame);
|
void SetFrame(FramePtr frame);
|
||||||
|
|
||||||
void OnRender(RenderContext& ctx) override;
|
void OnRender(RenderContext& ctx) override;
|
||||||
|
|
|
||||||
|
|
@ -36,19 +36,19 @@ Stage::Stage()
|
||||||
SetStage(this);
|
SetStage(this);
|
||||||
|
|
||||||
SetAnchor(Vec2{ 0, 0 });
|
SetAnchor(Vec2{ 0, 0 });
|
||||||
SetSize(Renderer::Instance().GetOutputSize());
|
SetSize(Renderer::GetInstance().GetOutputSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
Stage::~Stage() {}
|
Stage::~Stage() {}
|
||||||
|
|
||||||
void Stage::OnEnter()
|
void Stage::OnEnter()
|
||||||
{
|
{
|
||||||
KGE_SYS_LOG(L"Stage entered");
|
KGE_SYS_LOG("Stage entered");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stage::OnExit()
|
void Stage::OnExit()
|
||||||
{
|
{
|
||||||
KGE_SYS_LOG(L"Stage exited");
|
KGE_SYS_LOG("Stage exited");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stage::RenderBorder(RenderContext& ctx)
|
void Stage::RenderBorder(RenderContext& ctx)
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ KGE_DECLARE_SMART_PTR(Stage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 舞台
|
* @brief 舞台
|
||||||
* @details 舞台是所有角色的载体,是导演直接控制的对象
|
* @details 舞台是所有角色的载体,是导演直接控制的对象
|
||||||
* @see kiwano::Actor kiwano::Director
|
* @see kiwano::Actor kiwano::Director
|
||||||
*/
|
*/
|
||||||
class KGE_API Stage : public Actor
|
class KGE_API Stage : public Actor
|
||||||
|
|
@ -44,7 +44,7 @@ class KGE_API Stage : public Actor
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 进入舞台时
|
/// @brief 进入舞台时
|
||||||
static StagePtr Create();
|
static StagePtr Create();
|
||||||
|
|
||||||
Stage();
|
Stage();
|
||||||
|
|
@ -52,34 +52,34 @@ public:
|
||||||
virtual ~Stage();
|
virtual ~Stage();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 进入舞台时
|
/// @brief 进入舞台时
|
||||||
/// @details 重载该函数以处理进入舞台前的行为
|
/// @details 重载该函数以处理进入舞台前的行为
|
||||||
virtual void OnEnter();
|
virtual void OnEnter();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 退出舞台时
|
/// @brief 退出舞台时
|
||||||
/// @details 重载该函数以处理退出舞台前的行为
|
/// @details 重载该函数以处理退出舞台前的行为
|
||||||
virtual void OnExit();
|
virtual void OnExit();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取角色边界填充画刷
|
/// @brief 获取角色边界填充画刷
|
||||||
BrushPtr GetBorderFillBrush() const;
|
BrushPtr GetBorderFillBrush() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取角色边界轮廓画刷
|
/// @brief 获取角色边界轮廓画刷
|
||||||
BrushPtr GetBorderStrokeBrush() const;
|
BrushPtr GetBorderStrokeBrush() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置角色边界填充画刷
|
/// @brief 设置角色边界填充画刷
|
||||||
void SetBorderFillBrush(BrushPtr brush);
|
void SetBorderFillBrush(BrushPtr brush);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置角色边界轮廓画刷
|
/// @brief 设置角色边界轮廓画刷
|
||||||
void SetBorderStrokeBrush(BrushPtr brush);
|
void SetBorderStrokeBrush(BrushPtr brush);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 绘制所有子角色的边界
|
/// @brief 绘制所有子角色的边界
|
||||||
void RenderBorder(RenderContext& ctx) override;
|
void RenderBorder(RenderContext& ctx) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -34,20 +34,20 @@ KGE_DECLARE_SMART_PTR(TextActor);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 文本角色
|
* @brief 文本角色
|
||||||
*/
|
*/
|
||||||
class KGE_API TextActor : public Actor
|
class KGE_API TextActor : public Actor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建文本角色
|
/// @brief 创建文本角色
|
||||||
/// @param text 文字内容
|
/// @param text 文字内容
|
||||||
static TextActorPtr Create(const String& text);
|
static TextActorPtr Create(const String& text);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建文本角色
|
/// @brief 创建文本角色
|
||||||
/// @param text 文字内容
|
/// @param text 文字内容
|
||||||
/// @param style 文本样式
|
/// @param style 文本样式
|
||||||
static TextActorPtr Create(const String& text, const TextStyle& style);
|
static TextActorPtr Create(const String& text, const TextStyle& style);
|
||||||
|
|
||||||
TextActor();
|
TextActor();
|
||||||
|
|
@ -55,108 +55,108 @@ public:
|
||||||
virtual ~TextActor();
|
virtual ~TextActor();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取文本
|
/// @brief 获取文本
|
||||||
const String& GetText() const;
|
const String& GetText() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取文本样式
|
/// @brief 获取文本样式
|
||||||
const TextStyle& GetStyle() const;
|
const TextStyle& GetStyle() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取文本布局
|
/// @brief 获取文本布局
|
||||||
const TextLayout& GetLayout() const;
|
const TextLayout& GetLayout() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取文本布局大小
|
/// @brief 获取文本布局大小
|
||||||
Size GetLayoutSize() const;
|
Size GetLayoutSize() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取填充画刷
|
/// @brief 获取填充画刷
|
||||||
BrushPtr GetFillBrush() const;
|
BrushPtr GetFillBrush() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取描边画刷
|
/// @brief 获取描边画刷
|
||||||
BrushPtr GetOutlineBrush() const;
|
BrushPtr GetOutlineBrush() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取字体
|
/// @brief 获取字体
|
||||||
FontPtr GetFont() const;
|
FontPtr GetFont() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置文本
|
/// @brief 设置文本
|
||||||
void SetText(String const& text);
|
void SetText(String const& text);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置文本样式
|
/// @brief 设置文本样式
|
||||||
void SetStyle(const TextStyle& style);
|
void SetStyle(const TextStyle& style);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置字体
|
/// @brief 设置字体
|
||||||
void SetFont(FontPtr font);
|
void SetFont(FontPtr font);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置字体族
|
/// @brief 设置字体族
|
||||||
void SetFontFamily(String const& family);
|
void SetFontFamily(String const& family);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置字号(默认值为 18)
|
/// @brief 设置字号(默认值为 18)
|
||||||
void SetFontSize(float size);
|
void SetFontSize(float size);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置字体粗细值(默认值为 FontWeight::Normal)
|
/// @brief 设置字体粗细值(默认值为 FontWeight::Normal)
|
||||||
void SetFontWeight(uint32_t weight);
|
void SetFontWeight(uint32_t weight);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置文字填充画刷
|
/// @brief 设置文字填充画刷
|
||||||
void SetFillBrush(BrushPtr brush);
|
void SetFillBrush(BrushPtr brush);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置文字填充颜色(默认值为 Color::White)
|
/// @brief 设置文字填充颜色(默认值为 Color::White)
|
||||||
void SetFillColor(Color const& color);
|
void SetFillColor(Color const& color);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置文字斜体(默认值为 false)
|
/// @brief 设置文字斜体(默认值为 false)
|
||||||
void SetItalic(bool italic);
|
void SetItalic(bool italic);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置文本自动换行的宽度(默认为 0)
|
/// @brief 设置文本自动换行的宽度(默认为 0)
|
||||||
void SetWrapWidth(float wrap_width);
|
void SetWrapWidth(float wrap_width);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置行间距(默认为 0)
|
/// @brief 设置行间距(默认为 0)
|
||||||
void SetLineSpacing(float line_spacing);
|
void SetLineSpacing(float line_spacing);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置对齐方式(默认为 TextAlign::Left)
|
/// @brief 设置对齐方式(默认为 TextAlign::Left)
|
||||||
void SetAlignment(TextAlign align);
|
void SetAlignment(TextAlign align);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置文字描边画刷
|
/// @brief 设置文字描边画刷
|
||||||
void SetOutlineBrush(BrushPtr brush);
|
void SetOutlineBrush(BrushPtr brush);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置文字描边颜色
|
/// @brief 设置文字描边颜色
|
||||||
void SetOutlineColor(Color const& outline_color);
|
void SetOutlineColor(Color const& outline_color);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置文字描边线宽
|
/// @brief 设置文字描边线宽
|
||||||
void SetOutlineWidth(float outline_width);
|
void SetOutlineWidth(float outline_width);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置文字描边线相交样式
|
/// @brief 设置文字描边线相交样式
|
||||||
void SetOutlineStroke(StrokeStylePtr outline_stroke);
|
void SetOutlineStroke(StrokeStylePtr outline_stroke);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置是否显示下划线(默认值为 false)
|
/// @brief 设置是否显示下划线(默认值为 false)
|
||||||
void SetUnderline(bool enable);
|
void SetUnderline(bool enable);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置是否显示删除线(默认值为 false)
|
/// @brief 设置是否显示删除线(默认值为 false)
|
||||||
void SetStrikethrough(bool enable);
|
void SetStrikethrough(bool enable);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新文字布局
|
/// @brief 更新文字布局
|
||||||
/// @details 文字布局是懒更新的,手动更新文字布局以更新节点状态
|
/// @details 文字布局是懒更新的,手动更新文字布局以更新节点状态
|
||||||
void UpdateLayout();
|
void UpdateLayout();
|
||||||
|
|
||||||
void OnRender(RenderContext& ctx) override;
|
void OnRender(RenderContext& ctx) override;
|
||||||
|
|
|
||||||
|
|
@ -58,16 +58,16 @@ void Transition::Init(StagePtr prev, StagePtr next)
|
||||||
|
|
||||||
out_stage_ = prev;
|
out_stage_ = prev;
|
||||||
in_stage_ = next;
|
in_stage_ = next;
|
||||||
window_size_ = Renderer::Instance().GetOutputSize();
|
window_size_ = Renderer::GetInstance().GetOutputSize();
|
||||||
|
|
||||||
if (in_stage_)
|
if (in_stage_)
|
||||||
{
|
{
|
||||||
in_layer_.SetAreaRect(Rect{ Point(), window_size_ });
|
in_layer_.SetClipRect(Rect{ Point(), window_size_ });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out_stage_)
|
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)
|
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_)));
|
window_size_.x * (1 - process_), window_size_.y * (1 - process_)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
out_layer_.SetOpacity(0.f);
|
out_layer_.SetOpacity(0.f);
|
||||||
in_layer_.SetOpacity(1.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_));
|
window_size_.x * process_, window_size_.y * process_));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/2d/Stage.h>
|
#include <kiwano/2d/Stage.h>
|
||||||
#include <kiwano/render/LayerArea.h>
|
#include <kiwano/render/Layer.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
@ -36,7 +36,7 @@ KGE_DECLARE_SMART_PTR(RotationTransition);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 舞台过渡动画
|
* @brief 舞台过渡动画
|
||||||
*/
|
*/
|
||||||
class KGE_API Transition : public virtual ObjectBase
|
class KGE_API Transition : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
|
|
@ -49,48 +49,48 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 设置动画时长
|
* @brief 设置动画时长
|
||||||
*/
|
*/
|
||||||
void SetDuration(Duration dt);
|
void SetDuration(Duration dt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 场景过渡动画是否已结束
|
* @brief 场景过渡动画是否已结束
|
||||||
*/
|
*/
|
||||||
bool IsDone();
|
bool IsDone();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 初始化场景过渡动画
|
* @brief 初始化场景过渡动画
|
||||||
* @param[in] prev 转出场景
|
* @param[in] prev 转出场景
|
||||||
* @param[in] next 转入场景
|
* @param[in] next 转入场景
|
||||||
*/
|
*/
|
||||||
virtual void Init(StagePtr prev, StagePtr next);
|
virtual void Init(StagePtr prev, StagePtr next);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 更新过渡动画
|
* @brief 更新过渡动画
|
||||||
* @param dt 距上一次更新的时间间隔
|
* @param dt 距上一次更新的时间间隔
|
||||||
*/
|
*/
|
||||||
virtual void Update(Duration dt);
|
virtual void Update(Duration dt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 渲染过度动画
|
* @brief 渲染过度动画
|
||||||
* @param[in] ctx 渲染上下文
|
* @param[in] ctx 渲染上下文
|
||||||
*/
|
*/
|
||||||
virtual void Render(RenderContext& ctx);
|
virtual void Render(RenderContext& ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 停止动画
|
* @brief 停止动画
|
||||||
*/
|
*/
|
||||||
virtual void Stop();
|
virtual void Stop();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 重置动画
|
* @brief 重置动画
|
||||||
*/
|
*/
|
||||||
virtual void Reset() {}
|
virtual void Reset() {}
|
||||||
|
|
||||||
|
|
@ -102,22 +102,22 @@ protected:
|
||||||
Size window_size_;
|
Size window_size_;
|
||||||
StagePtr out_stage_;
|
StagePtr out_stage_;
|
||||||
StagePtr in_stage_;
|
StagePtr in_stage_;
|
||||||
LayerArea out_layer_;
|
Layer out_layer_;
|
||||||
LayerArea in_layer_;
|
Layer in_layer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 淡入淡出过渡动画
|
* @brief 淡入淡出过渡动画
|
||||||
* @details 前一场景淡出动画结束后,后一场景淡入
|
* @details 前一场景淡出动画结束后,后一场景淡入
|
||||||
*/
|
*/
|
||||||
class FadeTransition : public Transition
|
class FadeTransition : public Transition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 创建淡入淡出过渡动画
|
* @brief 创建淡入淡出过渡动画
|
||||||
* @param duration 动画时长
|
* @param duration 动画时长
|
||||||
*/
|
*/
|
||||||
static FadeTransitionPtr Create(Duration duration);
|
static FadeTransitionPtr Create(Duration duration);
|
||||||
|
|
||||||
|
|
@ -131,16 +131,16 @@ protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 渐变过渡动画
|
* @brief 渐变过渡动画
|
||||||
* @details 前一场景淡出动画的同时,后一场景淡入
|
* @details 前一场景淡出动画的同时,后一场景淡入
|
||||||
*/
|
*/
|
||||||
class EmergeTransition : public Transition
|
class EmergeTransition : public Transition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 创建渐变过渡动画
|
* @brief 创建渐变过渡动画
|
||||||
* @param duration 动画时长
|
* @param duration 动画时长
|
||||||
*/
|
*/
|
||||||
static EmergeTransitionPtr Create(Duration duration);
|
static EmergeTransitionPtr Create(Duration duration);
|
||||||
|
|
||||||
|
|
@ -154,16 +154,16 @@ protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 盒状过渡动画
|
* @brief 盒状过渡动画
|
||||||
* @details 前一场景以盒状收缩至消失,后一场景以盒状扩大
|
* @details 前一场景以盒状收缩至消失,后一场景以盒状扩大
|
||||||
*/
|
*/
|
||||||
class BoxTransition : public Transition
|
class BoxTransition : public Transition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 创建盒状过渡动画
|
* @brief 创建盒状过渡动画
|
||||||
* @param duration 动画时长
|
* @param duration 动画时长
|
||||||
*/
|
*/
|
||||||
static BoxTransitionPtr Create(Duration duration);
|
static BoxTransitionPtr Create(Duration duration);
|
||||||
|
|
||||||
|
|
@ -177,29 +177,29 @@ protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 位移过渡动画
|
* @brief 位移过渡动画
|
||||||
* @details 两场景以位移的方式切换
|
* @details 两场景以位移的方式切换
|
||||||
*/
|
*/
|
||||||
class MoveTransition : public Transition
|
class MoveTransition : public Transition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 位移方式
|
* @brief 位移方式
|
||||||
*/
|
*/
|
||||||
enum class Type : int
|
enum class Type : int
|
||||||
{
|
{
|
||||||
Up, ///< 上移
|
Up, ///< 上移
|
||||||
Down, ///< 下移
|
Down, ///< 下移
|
||||||
Left, ///< 左移
|
Left, ///< 左移
|
||||||
Right ///< 右移
|
Right ///< 右移
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 创建位移过渡动画
|
* @brief 创建位移过渡动画
|
||||||
* @param duration 动画时长
|
* @param duration 动画时长
|
||||||
* @param type 位移方式
|
* @param type 位移方式
|
||||||
*/
|
*/
|
||||||
static MoveTransitionPtr Create(Duration duration, Type type);
|
static MoveTransitionPtr Create(Duration duration, Type type);
|
||||||
|
|
||||||
|
|
@ -220,17 +220,17 @@ private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 旋转过渡动画
|
* @brief 旋转过渡动画
|
||||||
* @details 前一场景以旋转方式收缩至消失,后一场景以旋转方式扩大
|
* @details 前一场景以旋转方式收缩至消失,后一场景以旋转方式扩大
|
||||||
*/
|
*/
|
||||||
class RotationTransition : public Transition
|
class RotationTransition : public Transition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 创建旋转过渡动画
|
* @brief 创建旋转过渡动画
|
||||||
* @param duration 动画时长
|
* @param duration 动画时长
|
||||||
* @param rotation 旋转度数
|
* @param rotation 旋转度数
|
||||||
*/
|
*/
|
||||||
static RotationTransitionPtr Create(Duration duration, float rotation = 360.0f);
|
static RotationTransitionPtr Create(Duration duration, float rotation = 360.0f);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ KGE_DECLARE_SMART_PTR(Action);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* \defgroup Actions 动画
|
* \defgroup Actions 动画
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -43,7 +43,7 @@ KGE_DECLARE_SMART_PTR(Action);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画
|
/// @brief 动画
|
||||||
class KGE_API Action
|
class KGE_API Action
|
||||||
: public virtual ObjectBase
|
: public virtual ObjectBase
|
||||||
, protected IntrusiveListItem<ActionPtr>
|
, protected IntrusiveListItem<ActionPtr>
|
||||||
|
|
@ -54,7 +54,7 @@ class KGE_API Action
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画结束时的回调函数
|
/// @brief 动画结束时的回调函数
|
||||||
using DoneCallback = Function<void(Actor* /* target */)>;
|
using DoneCallback = Function<void(Actor* /* target */)>;
|
||||||
|
|
||||||
Action();
|
Action();
|
||||||
|
|
@ -62,120 +62,120 @@ public:
|
||||||
virtual ~Action();
|
virtual ~Action();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 继续动画
|
/// @brief 继续动画
|
||||||
void Resume();
|
void Resume();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 暂停动画
|
/// @brief 暂停动画
|
||||||
void Pause();
|
void Pause();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 停止动画
|
/// @brief 停止动画
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置动画延时
|
/// @brief 设置动画延时
|
||||||
void SetDelay(Duration delay);
|
void SetDelay(Duration delay);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置循环次数
|
/// @brief 设置循环次数
|
||||||
/// @param loops 循环次数,-1 为永久循环
|
/// @param loops 循环次数,-1 为永久循环
|
||||||
void SetLoops(int loops);
|
void SetLoops(int loops);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画结束时移除目标角色
|
/// @brief 动画结束时移除目标角色
|
||||||
void RemoveTargetWhenDone();
|
void RemoveTargetWhenDone();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置动画结束时的回调函数
|
/// @brief 设置动画结束时的回调函数
|
||||||
void SetDoneCallback(DoneCallback const& cb);
|
void SetDoneCallback(DoneCallback const& cb);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置动画循环结束时的回调函数
|
/// @brief 设置动画循环结束时的回调函数
|
||||||
void SetLoopDoneCallback(DoneCallback const& cb);
|
void SetLoopDoneCallback(DoneCallback const& cb);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取动画的拷贝
|
/// @brief 获取动画的拷贝
|
||||||
virtual ActionPtr Clone() const = 0;
|
virtual ActionPtr Clone() const = 0;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取动画的倒转
|
/// @brief 获取动画的倒转
|
||||||
virtual ActionPtr Reverse() const = 0;
|
virtual ActionPtr Reverse() const = 0;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取动画的运行状态
|
/// @brief 获取动画的运行状态
|
||||||
bool IsRunning() const;
|
bool IsRunning() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取动画的循环次数
|
/// @brief 获取动画的循环次数
|
||||||
int GetLoops() const;
|
int GetLoops() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取动画的延时
|
/// @brief 获取动画的延时
|
||||||
Duration GetDelay() const;
|
Duration GetDelay() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取动画结束时的回调函数
|
/// @brief 获取动画结束时的回调函数
|
||||||
DoneCallback GetDoneCallback() const;
|
DoneCallback GetDoneCallback() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取动画循环结束时的回调函数
|
/// @brief 获取动画循环结束时的回调函数
|
||||||
DoneCallback GetLoopDoneCallback() const;
|
DoneCallback GetLoopDoneCallback() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化动画
|
/// @brief 初始化动画
|
||||||
virtual void Init(Actor* target);
|
virtual void Init(Actor* target);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新动画
|
/// @brief 更新动画
|
||||||
virtual void Update(Actor* target, Duration dt);
|
virtual void Update(Actor* target, Duration dt);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新一个时间步
|
/// @brief 更新一个时间步
|
||||||
void UpdateStep(Actor* target, Duration dt);
|
void UpdateStep(Actor* target, Duration dt);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 完成动画
|
/// @brief 完成动画
|
||||||
void Complete(Actor* target);
|
void Complete(Actor* target);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 重新开始动画
|
/// @brief 重新开始动画
|
||||||
void Restart(Actor* target);
|
void Restart(Actor* target);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画状态
|
/// @brief 动画状态
|
||||||
enum class Status
|
enum class Status
|
||||||
{
|
{
|
||||||
NotStarted, ///< 未开始
|
NotStarted, ///< 未开始
|
||||||
Delayed, ///< 等待延时
|
Delayed, ///< 等待延时
|
||||||
Started, ///< 已开始
|
Started, ///< 已开始
|
||||||
Done, ///< 已结束
|
Done, ///< 已结束
|
||||||
Removeable ///< 可移除
|
Removeable ///< 可移除
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取动画状态
|
/// @brief 获取动画状态
|
||||||
Status GetStatus() const;
|
Status GetStatus() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取消逝时间
|
/// @brief 获取消逝时间
|
||||||
Duration GetElapsed() const;
|
Duration GetElapsed() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取完成的循环次数
|
/// @brief 获取完成的循环次数
|
||||||
int GetLoopsDone() const;
|
int GetLoopsDone() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 结束动画
|
/// @brief 结束动画
|
||||||
void Done();
|
void Done();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否已结束
|
/// @brief 是否已结束
|
||||||
bool IsDone() const;
|
bool IsDone() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否可移除
|
/// @brief 是否可移除
|
||||||
bool IsRemoveable() const;
|
bool IsRemoveable() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -29,21 +29,21 @@ namespace kiwano
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 延时动画
|
/// @brief 延时动画
|
||||||
class KGE_API ActionDelay : public Action
|
class KGE_API ActionDelay : public Action
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构建延时动画
|
/// @brief 构建延时动画
|
||||||
/// @param delay 延时时长
|
/// @param delay 延时时长
|
||||||
ActionDelay(Duration delay);
|
ActionDelay(Duration delay);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
ActionPtr Reverse() const override;
|
ActionPtr Reverse() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ KGE_DECLARE_SMART_PTR(ActionGroup);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画组合
|
/// @brief 动画组合
|
||||||
class KGE_API ActionGroup : public Action
|
class KGE_API ActionGroup : public Action
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -40,33 +40,33 @@ public:
|
||||||
ActionGroup();
|
ActionGroup();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画组合
|
/// @brief 动画组合
|
||||||
/// @param actions 动画集合
|
/// @param actions 动画集合
|
||||||
/// @param sync 同步执行
|
/// @param sync 同步执行
|
||||||
explicit ActionGroup(Vector<ActionPtr> const& actions, bool sync = false);
|
explicit ActionGroup(Vector<ActionPtr> const& actions, bool sync = false);
|
||||||
|
|
||||||
virtual ~ActionGroup();
|
virtual ~ActionGroup();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加动画
|
/// @brief 添加动画
|
||||||
/// @param action 动画
|
/// @param action 动画
|
||||||
void Add(ActionPtr action);
|
void Add(ActionPtr action);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加多个动画
|
/// @brief 添加多个动画
|
||||||
/// @param actions 动画集合
|
/// @param actions 动画集合
|
||||||
void Add(Vector<ActionPtr> const& actions);
|
void Add(Vector<ActionPtr> const& actions);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取所有动画
|
/// @brief 获取所有动画
|
||||||
ActionList const& GetActions() const;
|
ActionList const& GetActions() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
ActionPtr Reverse() const override;
|
ActionPtr Reverse() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,13 @@ namespace kiwano
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画辅助类
|
/// @brief 动画辅助类
|
||||||
struct ActionHelper
|
struct ActionHelper
|
||||||
{
|
{
|
||||||
using DoneCallback = Action::DoneCallback;
|
using DoneCallback = Action::DoneCallback;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置循环次数
|
/// @brief 设置循环次数
|
||||||
inline ActionHelper& SetLoops(int loops)
|
inline ActionHelper& SetLoops(int loops)
|
||||||
{
|
{
|
||||||
core->SetLoops(loops);
|
core->SetLoops(loops);
|
||||||
|
|
@ -47,7 +47,7 @@ struct ActionHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置动画延迟
|
/// @brief 设置动画延迟
|
||||||
inline ActionHelper& SetDelay(Duration delay)
|
inline ActionHelper& SetDelay(Duration delay)
|
||||||
{
|
{
|
||||||
core->SetDelay(delay);
|
core->SetDelay(delay);
|
||||||
|
|
@ -55,7 +55,7 @@ struct ActionHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置动画结束回调函数
|
/// @brief 设置动画结束回调函数
|
||||||
inline ActionHelper& SetDoneCallback(DoneCallback const& cb)
|
inline ActionHelper& SetDoneCallback(DoneCallback const& cb)
|
||||||
{
|
{
|
||||||
core->SetDoneCallback(cb);
|
core->SetDoneCallback(cb);
|
||||||
|
|
@ -63,7 +63,7 @@ struct ActionHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置动画循环结束时的回调函数
|
/// @brief 设置动画循环结束时的回调函数
|
||||||
inline ActionHelper& SetLoopDoneCallback(DoneCallback const& cb)
|
inline ActionHelper& SetLoopDoneCallback(DoneCallback const& cb)
|
||||||
{
|
{
|
||||||
core->SetLoopDoneCallback(cb);
|
core->SetLoopDoneCallback(cb);
|
||||||
|
|
@ -71,7 +71,7 @@ struct ActionHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画结束时移除目标角色
|
/// @brief 动画结束时移除目标角色
|
||||||
inline ActionHelper& RemoveTargetWhenDone()
|
inline ActionHelper& RemoveTargetWhenDone()
|
||||||
{
|
{
|
||||||
core->RemoveTargetWhenDone();
|
core->RemoveTargetWhenDone();
|
||||||
|
|
@ -79,7 +79,7 @@ struct ActionHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置名称
|
/// @brief 设置名称
|
||||||
inline ActionHelper& SetName(String const& name)
|
inline ActionHelper& SetName(String const& name)
|
||||||
{
|
{
|
||||||
core->SetName(name);
|
core->SetName(name);
|
||||||
|
|
@ -87,7 +87,7 @@ struct ActionHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取指针
|
/// @brief 获取指针
|
||||||
inline ActionPtr Get() const
|
inline ActionPtr Get() const
|
||||||
{
|
{
|
||||||
return core;
|
return core;
|
||||||
|
|
@ -108,13 +108,13 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 补间动画辅助类
|
/// @brief 补间动画辅助类
|
||||||
struct TweenHelper
|
struct TweenHelper
|
||||||
{
|
{
|
||||||
using DoneCallback = Action::DoneCallback;
|
using DoneCallback = Action::DoneCallback;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置动画持续时长
|
/// @brief 设置动画持续时长
|
||||||
inline TweenHelper& SetDuration(Duration dur)
|
inline TweenHelper& SetDuration(Duration dur)
|
||||||
{
|
{
|
||||||
core->SetDuration(dur);
|
core->SetDuration(dur);
|
||||||
|
|
@ -122,7 +122,7 @@ struct TweenHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置循环次数
|
/// @brief 设置循环次数
|
||||||
inline TweenHelper& SetLoops(int loops)
|
inline TweenHelper& SetLoops(int loops)
|
||||||
{
|
{
|
||||||
core->SetLoops(loops);
|
core->SetLoops(loops);
|
||||||
|
|
@ -130,7 +130,7 @@ struct TweenHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置缓动函数
|
/// @brief 设置缓动函数
|
||||||
inline TweenHelper& SetEaseFunc(EaseFunc ease)
|
inline TweenHelper& SetEaseFunc(EaseFunc ease)
|
||||||
{
|
{
|
||||||
core->SetEaseFunc(ease);
|
core->SetEaseFunc(ease);
|
||||||
|
|
@ -138,7 +138,7 @@ struct TweenHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置动画延迟
|
/// @brief 设置动画延迟
|
||||||
inline TweenHelper& SetDelay(Duration delay)
|
inline TweenHelper& SetDelay(Duration delay)
|
||||||
{
|
{
|
||||||
core->SetDelay(delay);
|
core->SetDelay(delay);
|
||||||
|
|
@ -146,7 +146,7 @@ struct TweenHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置动画结束回调函数
|
/// @brief 设置动画结束回调函数
|
||||||
inline TweenHelper& SetDoneCallback(DoneCallback const& cb)
|
inline TweenHelper& SetDoneCallback(DoneCallback const& cb)
|
||||||
{
|
{
|
||||||
core->SetDoneCallback(cb);
|
core->SetDoneCallback(cb);
|
||||||
|
|
@ -154,7 +154,7 @@ struct TweenHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置动画循环结束时的回调函数
|
/// @brief 设置动画循环结束时的回调函数
|
||||||
inline TweenHelper& SetLoopDoneCallback(DoneCallback const& cb)
|
inline TweenHelper& SetLoopDoneCallback(DoneCallback const& cb)
|
||||||
{
|
{
|
||||||
core->SetLoopDoneCallback(cb);
|
core->SetLoopDoneCallback(cb);
|
||||||
|
|
@ -162,7 +162,7 @@ struct TweenHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画结束时移除目标角色
|
/// @brief 动画结束时移除目标角色
|
||||||
inline TweenHelper& RemoveTargetWhenDone()
|
inline TweenHelper& RemoveTargetWhenDone()
|
||||||
{
|
{
|
||||||
core->RemoveTargetWhenDone();
|
core->RemoveTargetWhenDone();
|
||||||
|
|
@ -170,7 +170,7 @@ struct TweenHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置名称
|
/// @brief 设置名称
|
||||||
inline TweenHelper& SetName(String const& name)
|
inline TweenHelper& SetName(String const& name)
|
||||||
{
|
{
|
||||||
core->SetName(name);
|
core->SetName(name);
|
||||||
|
|
@ -178,7 +178,7 @@ struct TweenHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取指针
|
/// @brief 获取指针
|
||||||
inline ActionTweenPtr Get() const
|
inline ActionTweenPtr Get() const
|
||||||
{
|
{
|
||||||
return core;
|
return core;
|
||||||
|
|
@ -204,120 +204,120 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画构造器
|
/// @brief 动画构造器
|
||||||
struct Tween
|
struct Tween
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造相对位移动画
|
/// @brief 构造相对位移动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param vector 移动向量
|
/// @param vector 移动向量
|
||||||
static inline TweenHelper MoveBy(Duration dur, Point const& vector)
|
static inline TweenHelper MoveBy(Duration dur, Point const& vector)
|
||||||
{
|
{
|
||||||
return TweenHelper(new kiwano::ActionMoveBy(dur, vector));
|
return TweenHelper(new kiwano::ActionMoveBy(dur, vector));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造位移动画
|
/// @brief 构造位移动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param pos 目的坐标
|
/// @param pos 目的坐标
|
||||||
static inline TweenHelper MoveTo(Duration dur, Point const& pos)
|
static inline TweenHelper MoveTo(Duration dur, Point const& pos)
|
||||||
{
|
{
|
||||||
return TweenHelper(new kiwano::ActionMoveTo(dur, pos));
|
return TweenHelper(new kiwano::ActionMoveTo(dur, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造相对跳跃动画
|
/// @brief 构造相对跳跃动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param vec 跳跃位移向量
|
/// @param vec 跳跃位移向量
|
||||||
/// @param height 跳跃高度
|
/// @param height 跳跃高度
|
||||||
/// @param jumps 跳跃次数
|
/// @param jumps 跳跃次数
|
||||||
static inline TweenHelper JumpBy(Duration duration, Vec2 const& vec, float height, int jumps = 1)
|
static inline TweenHelper JumpBy(Duration duration, Vec2 const& vec, float height, int jumps = 1)
|
||||||
{
|
{
|
||||||
return TweenHelper(new kiwano::ActionJumpBy(duration, vec, height, jumps));
|
return TweenHelper(new kiwano::ActionJumpBy(duration, vec, height, jumps));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造跳跃动画
|
/// @brief 构造跳跃动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param pos 目的坐标
|
/// @param pos 目的坐标
|
||||||
/// @param height 跳跃高度
|
/// @param height 跳跃高度
|
||||||
/// @param jumps 跳跃次数
|
/// @param jumps 跳跃次数
|
||||||
static inline TweenHelper JumpTo(Duration duration, Point const& pos, float height, int jumps = 1)
|
static inline TweenHelper JumpTo(Duration duration, Point const& pos, float height, int jumps = 1)
|
||||||
{
|
{
|
||||||
return TweenHelper(new kiwano::ActionJumpTo(duration, pos, height, jumps));
|
return TweenHelper(new kiwano::ActionJumpTo(duration, pos, height, jumps));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造相对缩放动画
|
/// @brief 构造相对缩放动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param scale_x 横向缩放相对变化值
|
/// @param scale_x 横向缩放相对变化值
|
||||||
/// @param scale_y 纵向缩放相对变化值
|
/// @param scale_y 纵向缩放相对变化值
|
||||||
static inline TweenHelper ScaleBy(Duration dur, float scale_x, float scale_y)
|
static inline TweenHelper ScaleBy(Duration dur, float scale_x, float scale_y)
|
||||||
{
|
{
|
||||||
return TweenHelper(new kiwano::ActionScaleBy(dur, scale_x, scale_y));
|
return TweenHelper(new kiwano::ActionScaleBy(dur, scale_x, scale_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造缩放动画
|
/// @brief 构造缩放动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param scale_x 横向缩放目标值
|
/// @param scale_x 横向缩放目标值
|
||||||
/// @param scale_y 纵向缩放目标值
|
/// @param scale_y 纵向缩放目标值
|
||||||
static inline TweenHelper ScaleTo(Duration dur, float scale_x, float scale_y)
|
static inline TweenHelper ScaleTo(Duration dur, float scale_x, float scale_y)
|
||||||
{
|
{
|
||||||
return TweenHelper(new kiwano::ActionScaleTo(dur, scale_x, scale_y));
|
return TweenHelper(new kiwano::ActionScaleTo(dur, scale_x, scale_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造透明度渐变动画
|
/// @brief 构造透明度渐变动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param opacity 目标透明度
|
/// @param opacity 目标透明度
|
||||||
static inline TweenHelper FadeTo(Duration dur, float opacity)
|
static inline TweenHelper FadeTo(Duration dur, float opacity)
|
||||||
{
|
{
|
||||||
return TweenHelper(new kiwano::ActionFadeTo(dur, opacity));
|
return TweenHelper(new kiwano::ActionFadeTo(dur, opacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造淡入动画
|
/// @brief 构造淡入动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
static inline TweenHelper FadeIn(Duration dur)
|
static inline TweenHelper FadeIn(Duration dur)
|
||||||
{
|
{
|
||||||
return TweenHelper(new kiwano::ActionFadeIn(dur));
|
return TweenHelper(new kiwano::ActionFadeIn(dur));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造淡出动画
|
/// @brief 构造淡出动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
static inline TweenHelper FadeOut(Duration dur)
|
static inline TweenHelper FadeOut(Duration dur)
|
||||||
{
|
{
|
||||||
return TweenHelper(new kiwano::ActionFadeOut(dur));
|
return TweenHelper(new kiwano::ActionFadeOut(dur));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造相对旋转动画
|
/// @brief 构造相对旋转动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param rotation 角度相对变化值
|
/// @param rotation 角度相对变化值
|
||||||
static inline TweenHelper RotateBy(Duration dur, float rotation)
|
static inline TweenHelper RotateBy(Duration dur, float rotation)
|
||||||
{
|
{
|
||||||
return TweenHelper(new kiwano::ActionRotateBy(dur, rotation));
|
return TweenHelper(new kiwano::ActionRotateBy(dur, rotation));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造旋转动画
|
/// @brief 构造旋转动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param rotation 目标角度
|
/// @param rotation 目标角度
|
||||||
static inline TweenHelper RotateTo(Duration dur, float rotation)
|
static inline TweenHelper RotateTo(Duration dur, float rotation)
|
||||||
{
|
{
|
||||||
return TweenHelper(new kiwano::ActionRotateTo(dur, rotation));
|
return TweenHelper(new kiwano::ActionRotateTo(dur, rotation));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造路径行走动画
|
/// @brief 构造路径行走动画
|
||||||
/// @param duration 持续时长
|
/// @param duration 持续时长
|
||||||
/// @param path 路径形状
|
/// @param path 路径形状
|
||||||
/// @param rotating 是否沿路径切线方向旋转
|
/// @param rotating 是否沿路径切线方向旋转
|
||||||
/// @param start 路径起点(百分比)
|
/// @param start 路径起点(百分比)
|
||||||
/// @param end 路径终点(百分比)
|
/// @param end 路径终点(百分比)
|
||||||
static inline TweenHelper Walk(Duration duration, ShapePtr path, bool rotating = false, float start = 0.f,
|
static inline TweenHelper Walk(Duration duration, ShapePtr path, bool rotating = false, float start = 0.f,
|
||||||
float end = 1.f)
|
float end = 1.f)
|
||||||
{
|
{
|
||||||
|
|
@ -325,35 +325,35 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构建帧动画
|
/// @brief 构建帧动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param[in] frame_seq 序列帧
|
/// @param[in] frame_seq 序列帧
|
||||||
static inline TweenHelper Animation(Duration dur, FrameSequencePtr frames)
|
static inline TweenHelper Animation(Duration dur, FrameSequencePtr frames)
|
||||||
{
|
{
|
||||||
return TweenHelper(new kiwano::Animation(dur, frames));
|
return TweenHelper(new kiwano::Animation(dur, frames));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造自定义动画
|
/// @brief 构造自定义动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param tween_func 动画回调函数
|
/// @param tween_func 动画回调函数
|
||||||
static inline TweenHelper Custom(Duration dur, ActionCustom::TweenFunc tween_func)
|
static inline TweenHelper Custom(Duration dur, ActionCustom::TweenFunc tween_func)
|
||||||
{
|
{
|
||||||
return TweenHelper(new kiwano::ActionCustom(dur, tween_func));
|
return TweenHelper(new kiwano::ActionCustom(dur, tween_func));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构建延时动画
|
/// @brief 构建延时动画
|
||||||
/// @param delay 延时时长
|
/// @param delay 延时时长
|
||||||
static inline ActionHelper Delay(Duration delay)
|
static inline ActionHelper Delay(Duration delay)
|
||||||
{
|
{
|
||||||
return ActionHelper(new kiwano::ActionDelay(delay));
|
return ActionHelper(new kiwano::ActionDelay(delay));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画组合
|
/// @brief 动画组合
|
||||||
/// @param actions 动画集合
|
/// @param actions 动画集合
|
||||||
/// @param sync 同步执行
|
/// @param sync 同步执行
|
||||||
static inline ActionHelper Group(Vector<ActionPtr> const& actions, bool sync = false)
|
static inline ActionHelper Group(Vector<ActionPtr> const& actions, bool sync = false)
|
||||||
{
|
{
|
||||||
return ActionHelper(new kiwano::ActionGroup(actions, sync));
|
return ActionHelper(new kiwano::ActionGroup(actions, sync));
|
||||||
|
|
|
||||||
|
|
@ -30,47 +30,47 @@ namespace kiwano
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 动画管理器
|
* @brief 动画管理器
|
||||||
*/
|
*/
|
||||||
class KGE_API ActionManager
|
class KGE_API ActionManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画列表
|
/// @brief 动画列表
|
||||||
using Actions = IntrusiveList<ActionPtr>;
|
using Actions = IntrusiveList<ActionPtr>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加动画
|
/// @brief 添加动画
|
||||||
Action* AddAction(ActionPtr action);
|
Action* AddAction(ActionPtr action);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加动画
|
/// @brief 添加动画
|
||||||
Action* AddAction(Action* action);
|
Action* AddAction(Action* action);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 继续所有暂停动画
|
/// @brief 继续所有暂停动画
|
||||||
void ResumeAllActions();
|
void ResumeAllActions();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 暂停所有动画
|
/// @brief 暂停所有动画
|
||||||
void PauseAllActions();
|
void PauseAllActions();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 停止所有动画
|
/// @brief 停止所有动画
|
||||||
void StopAllActions();
|
void StopAllActions();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取指定名称的动画
|
/// @brief 获取指定名称的动画
|
||||||
/// @param name 动画名称
|
/// @param name 动画名称
|
||||||
ActionPtr GetAction(String const& name);
|
ActionPtr GetAction(String const& name);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取所有动画
|
/// @brief 获取所有动画
|
||||||
Actions const& GetAllActions() const;
|
Actions const& GetAllActions() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新动画
|
/// @brief 更新动画
|
||||||
void UpdateActions(Actor* target, Duration dt);
|
void UpdateActions(Actor* target, Duration dt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -25,27 +25,27 @@
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 缓动函数
|
/// @brief 缓动函数
|
||||||
using EaseFunc = Function<float(float)>;
|
using EaseFunc = Function<float(float)>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 缓动函数枚举
|
/// @brief 缓动函数枚举
|
||||||
/// @details 查看 https://easings.net 获取更多信息
|
/// @details 查看 https://easings.net 获取更多信息
|
||||||
struct Ease
|
struct Ease
|
||||||
{
|
{
|
||||||
static KGE_API EaseFunc Linear; ///< 线性
|
static KGE_API EaseFunc Linear; ///< 线性
|
||||||
static KGE_API EaseFunc EaseIn; ///< 由慢变快
|
static KGE_API EaseFunc EaseIn; ///< 由慢变快
|
||||||
static KGE_API EaseFunc EaseOut; ///< 由快变慢
|
static KGE_API EaseFunc EaseOut; ///< 由快变慢
|
||||||
static KGE_API EaseFunc EaseInOut; ///< 由慢变快, 再由快变慢
|
static KGE_API EaseFunc EaseInOut; ///< 由慢变快, 再由快变慢
|
||||||
static KGE_API EaseFunc ExpoIn; ///< 由慢变极快
|
static KGE_API EaseFunc ExpoIn; ///< 由慢变极快
|
||||||
static KGE_API EaseFunc ExpoOut; ///< 由极快变慢
|
static KGE_API EaseFunc ExpoOut; ///< 由极快变慢
|
||||||
static KGE_API EaseFunc ExpoInOut; ///< 由慢至极快, 再由极快边慢
|
static KGE_API EaseFunc ExpoInOut; ///< 由慢至极快, 再由极快边慢
|
||||||
static KGE_API EaseFunc ElasticIn; ///< 自起点赋予弹性
|
static KGE_API EaseFunc ElasticIn; ///< 自起点赋予弹性
|
||||||
static KGE_API EaseFunc ElasticOut; ///< 自终点赋予弹性
|
static KGE_API EaseFunc ElasticOut; ///< 自终点赋予弹性
|
||||||
static KGE_API EaseFunc ElasticInOut; ///< 再起点和终点赋予弹性
|
static KGE_API EaseFunc ElasticInOut; ///< 再起点和终点赋予弹性
|
||||||
static KGE_API EaseFunc BounceIn; ///< 自起点赋予反弹力
|
static KGE_API EaseFunc BounceIn; ///< 自起点赋予反弹力
|
||||||
static KGE_API EaseFunc BounceOut; ///< 自终点赋予反弹力
|
static KGE_API EaseFunc BounceOut; ///< 自终点赋予反弹力
|
||||||
static KGE_API EaseFunc BounceInOut; ///< 在起点和终点赋予反弹力
|
static KGE_API EaseFunc BounceInOut; ///< 在起点和终点赋予反弹力
|
||||||
static KGE_API EaseFunc BackIn;
|
static KGE_API EaseFunc BackIn;
|
||||||
static KGE_API EaseFunc BackOut;
|
static KGE_API EaseFunc BackOut;
|
||||||
static KGE_API EaseFunc BackInOut;
|
static KGE_API EaseFunc BackInOut;
|
||||||
|
|
@ -86,32 +86,32 @@ KGE_DECLARE_SMART_PTR(ActionCustom);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 补间动画
|
/// @brief 补间动画
|
||||||
class KGE_API ActionTween : public Action
|
class KGE_API ActionTween : public Action
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ActionTween();
|
ActionTween();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 补间动画
|
/// @brief 补间动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
ActionTween(Duration duration, EaseFunc func);
|
ActionTween(Duration duration, EaseFunc func);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取动画时长
|
/// @brief 获取动画时长
|
||||||
Duration GetDuration() const;
|
Duration GetDuration() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置动画时长
|
/// @brief 设置动画时长
|
||||||
void SetDuration(Duration duration);
|
void SetDuration(Duration duration);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取动画速度缓动函数
|
/// @brief 获取动画速度缓动函数
|
||||||
EaseFunc const& GetEaseFunc() const;
|
EaseFunc const& GetEaseFunc() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置动画速度缓动函数
|
/// @brief 设置动画速度缓动函数
|
||||||
void SetEaseFunc(EaseFunc const& func);
|
void SetEaseFunc(EaseFunc const& func);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -125,23 +125,23 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 相对位移动画
|
/// @brief 相对位移动画
|
||||||
class KGE_API ActionMoveBy : public ActionTween
|
class KGE_API ActionMoveBy : public ActionTween
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造相对位移动画
|
/// @brief 构造相对位移动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param vector 移动向量
|
/// @param vector 移动向量
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
ActionMoveBy(Duration duration, Vec2 const& vector, EaseFunc func = nullptr);
|
ActionMoveBy(Duration duration, Vec2 const& vector, EaseFunc func = nullptr);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
ActionPtr Reverse() const override;
|
ActionPtr Reverse() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -156,26 +156,26 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 位移动画
|
/// @brief 位移动画
|
||||||
class KGE_API ActionMoveTo : public ActionMoveBy
|
class KGE_API ActionMoveTo : public ActionMoveBy
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造位移动画
|
/// @brief 构造位移动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param pos 目的坐标
|
/// @param pos 目的坐标
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
ActionMoveTo(Duration duration, Point const& pos, EaseFunc func = nullptr);
|
ActionMoveTo(Duration duration, Point const& pos, EaseFunc func = nullptr);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
virtual ActionPtr Reverse() const override
|
virtual ActionPtr Reverse() const override
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"Reverse() not supported in ActionMoveTo");
|
KGE_ERROR("Reverse() not supported in ActionMoveTo");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,25 +187,25 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 相对跳跃动画
|
/// @brief 相对跳跃动画
|
||||||
class KGE_API ActionJumpBy : public ActionTween
|
class KGE_API ActionJumpBy : public ActionTween
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造相对跳跃动画
|
/// @brief 构造相对跳跃动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param vec 跳跃位移向量
|
/// @param vec 跳跃位移向量
|
||||||
/// @param height 跳跃高度
|
/// @param height 跳跃高度
|
||||||
/// @param jumps 跳跃次数
|
/// @param jumps 跳跃次数
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
ActionJumpBy(Duration duration, Vec2 const& vec, float height, int jumps = 1, EaseFunc func = nullptr);
|
ActionJumpBy(Duration duration, Vec2 const& vec, float height, int jumps = 1, EaseFunc func = nullptr);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
ActionPtr Reverse() const override;
|
ActionPtr Reverse() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -222,28 +222,28 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 跳跃动画
|
/// @brief 跳跃动画
|
||||||
class KGE_API ActionJumpTo : public ActionJumpBy
|
class KGE_API ActionJumpTo : public ActionJumpBy
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造跳跃动画
|
/// @brief 构造跳跃动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param pos 目的坐标
|
/// @param pos 目的坐标
|
||||||
/// @param height 跳跃高度
|
/// @param height 跳跃高度
|
||||||
/// @param jumps 跳跃次数
|
/// @param jumps 跳跃次数
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
ActionJumpTo(Duration duration, Point const& pos, float height, int jumps = 1, EaseFunc func = nullptr);
|
ActionJumpTo(Duration duration, Point const& pos, float height, int jumps = 1, EaseFunc func = nullptr);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
virtual ActionPtr Reverse() const override
|
virtual ActionPtr Reverse() const override
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"Reverse() not supported in ActionJumpTo");
|
KGE_ERROR("Reverse() not supported in ActionJumpTo");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -255,24 +255,24 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 相对缩放动画
|
/// @brief 相对缩放动画
|
||||||
class KGE_API ActionScaleBy : public ActionTween
|
class KGE_API ActionScaleBy : public ActionTween
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造相对缩放动画
|
/// @brief 构造相对缩放动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param scale_x 横向缩放相对变化值
|
/// @param scale_x 横向缩放相对变化值
|
||||||
/// @param scale_y 纵向缩放相对变化值
|
/// @param scale_y 纵向缩放相对变化值
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
ActionScaleBy(Duration duration, float scale_x, float scale_y, EaseFunc func = nullptr);
|
ActionScaleBy(Duration duration, float scale_x, float scale_y, EaseFunc func = nullptr);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
ActionPtr Reverse() const override;
|
ActionPtr Reverse() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -288,27 +288,27 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 缩放动画
|
/// @brief 缩放动画
|
||||||
class KGE_API ActionScaleTo : public ActionScaleBy
|
class KGE_API ActionScaleTo : public ActionScaleBy
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造缩放动画
|
/// @brief 构造缩放动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param scale_x 横向缩放目标值
|
/// @param scale_x 横向缩放目标值
|
||||||
/// @param scale_y 纵向缩放目标值
|
/// @param scale_y 纵向缩放目标值
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
ActionScaleTo(Duration duration, float scale_x, float scale_y, EaseFunc func = nullptr);
|
ActionScaleTo(Duration duration, float scale_x, float scale_y, EaseFunc func = nullptr);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
virtual ActionPtr Reverse() const override
|
virtual ActionPtr Reverse() const override
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"Reverse() not supported in ActionScaleTo");
|
KGE_ERROR("Reverse() not supported in ActionScaleTo");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -321,26 +321,26 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 透明度渐变动画
|
/// @brief 透明度渐变动画
|
||||||
class KGE_API ActionFadeTo : public ActionTween
|
class KGE_API ActionFadeTo : public ActionTween
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造透明度渐变动画
|
/// @brief 构造透明度渐变动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param opacity 目标透明度
|
/// @param opacity 目标透明度
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
ActionFadeTo(Duration duration, float opacity, EaseFunc func = nullptr);
|
ActionFadeTo(Duration duration, float opacity, EaseFunc func = nullptr);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
virtual ActionPtr Reverse() const override
|
virtual ActionPtr Reverse() const override
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"Reverse() not supported in ActionFadeTo");
|
KGE_ERROR("Reverse() not supported in ActionFadeTo");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -356,47 +356,47 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 淡入动画
|
/// @brief 淡入动画
|
||||||
class KGE_API ActionFadeIn : public ActionFadeTo
|
class KGE_API ActionFadeIn : public ActionFadeTo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造淡入动画
|
/// @brief 构造淡入动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
explicit ActionFadeIn(Duration duration, EaseFunc func = nullptr);
|
explicit ActionFadeIn(Duration duration, EaseFunc func = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 淡出动画
|
/// @brief 淡出动画
|
||||||
class KGE_API ActionFadeOut : public ActionFadeTo
|
class KGE_API ActionFadeOut : public ActionFadeTo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造淡出动画
|
/// @brief 构造淡出动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
explicit ActionFadeOut(Duration duration, EaseFunc func = nullptr);
|
explicit ActionFadeOut(Duration duration, EaseFunc func = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 相对旋转动画
|
/// @brief 相对旋转动画
|
||||||
class KGE_API ActionRotateBy : public ActionTween
|
class KGE_API ActionRotateBy : public ActionTween
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造相对旋转动画
|
/// @brief 构造相对旋转动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param rotation 角度相对变化值
|
/// @param rotation 角度相对变化值
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
ActionRotateBy(Duration duration, float rotation, EaseFunc func = nullptr);
|
ActionRotateBy(Duration duration, float rotation, EaseFunc func = nullptr);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
ActionPtr Reverse() const override;
|
ActionPtr Reverse() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -410,26 +410,26 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 旋转动画
|
/// @brief 旋转动画
|
||||||
class KGE_API ActionRotateTo : public ActionRotateBy
|
class KGE_API ActionRotateTo : public ActionRotateBy
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造旋转动画
|
/// @brief 构造旋转动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param rotation 目标角度
|
/// @param rotation 目标角度
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
ActionRotateTo(Duration duration, float rotation, EaseFunc func = nullptr);
|
ActionRotateTo(Duration duration, float rotation, EaseFunc func = nullptr);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
virtual ActionPtr Reverse() const override
|
virtual ActionPtr Reverse() const override
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"Reverse() not supported in ActionRotateTo");
|
KGE_ERROR("Reverse() not supported in ActionRotateTo");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -441,31 +441,31 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 自定义动画
|
/// @brief 自定义动画
|
||||||
class KGE_API ActionCustom : public ActionTween
|
class KGE_API ActionCustom : public ActionTween
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画回调函数
|
/// @brief 动画回调函数
|
||||||
/// @details 在动画更新时回调该函数,第一个参数是执行动画的目标,第二个参数是动画进度(0.0 - 1.0)
|
/// @details 在动画更新时回调该函数,第一个参数是执行动画的目标,第二个参数是动画进度(0.0 - 1.0)
|
||||||
using TweenFunc = Function<void(Actor* /* target */, float /* percent */)>;
|
using TweenFunc = Function<void(Actor* /* target */, float /* percent */)>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造自定义动画
|
/// @brief 构造自定义动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param tween_func 动画回调函数
|
/// @param tween_func 动画回调函数
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
ActionCustom(Duration duration, TweenFunc tween_func, EaseFunc func = nullptr);
|
ActionCustom(Duration duration, TweenFunc tween_func, EaseFunc func = nullptr);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
ActionPtr Reverse() const override
|
ActionPtr Reverse() const override
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"Reverse() not supported in ActionCustom");
|
KGE_ERROR("Reverse() not supported in ActionCustom");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,44 +33,44 @@ KGE_DECLARE_SMART_PTR(ActionWalk);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 路径行走动画
|
/// @brief 路径行走动画
|
||||||
class KGE_API ActionWalk : public ActionTween
|
class KGE_API ActionWalk : public ActionTween
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造路径行走动画
|
/// @brief 构造路径行走动画
|
||||||
/// @param duration 持续时长
|
/// @param duration 持续时长
|
||||||
/// @param rotating 是否沿路径切线方向旋转
|
/// @param rotating 是否沿路径切线方向旋转
|
||||||
/// @param start 路径起点(百分比)
|
/// @param start 路径起点(百分比)
|
||||||
/// @param end 路径终点(百分比)
|
/// @param end 路径终点(百分比)
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
ActionWalk(Duration duration, bool rotating = false, float start = 0.f, float end = 1.f, EaseFunc func = nullptr);
|
ActionWalk(Duration duration, bool rotating = false, float start = 0.f, float end = 1.f, EaseFunc func = nullptr);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造路径行走动画
|
/// @brief 构造路径行走动画
|
||||||
/// @param duration 持续时长
|
/// @param duration 持续时长
|
||||||
/// @param path 路径形状
|
/// @param path 路径形状
|
||||||
/// @param rotating 是否沿路径切线方向旋转
|
/// @param rotating 是否沿路径切线方向旋转
|
||||||
/// @param start 路径起点(百分比)
|
/// @param start 路径起点(百分比)
|
||||||
/// @param end 路径终点(百分比)
|
/// @param end 路径终点(百分比)
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
ActionWalk(Duration duration, ShapePtr path, bool rotating = false, float start = 0.f, float end = 1.f,
|
ActionWalk(Duration duration, ShapePtr path, bool rotating = false, float start = 0.f, float end = 1.f,
|
||||||
EaseFunc func = nullptr);
|
EaseFunc func = nullptr);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
ActionPtr Reverse() const override;
|
ActionPtr Reverse() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取路线
|
/// @brief 获取路线
|
||||||
ShapePtr const& GetPath() const;
|
ShapePtr const& GetPath() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置路径形状
|
/// @brief 设置路径形状
|
||||||
void SetPath(ShapePtr path);
|
void SetPath(ShapePtr path);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -32,36 +32,36 @@ KGE_DECLARE_SMART_PTR(Animation);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 帧动画
|
/// @brief 帧动画
|
||||||
class KGE_API Animation : public ActionTween
|
class KGE_API Animation : public ActionTween
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Animation();
|
Animation();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构建帧动画
|
/// @brief 构建帧动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param[in] frame_seq 序列帧
|
/// @param[in] frame_seq 序列帧
|
||||||
/// @param func 动画速度缓动函数
|
/// @param func 动画速度缓动函数
|
||||||
Animation(Duration duration, FrameSequencePtr frame_seq, EaseFunc func = nullptr);
|
Animation(Duration duration, FrameSequencePtr frame_seq, EaseFunc func = nullptr);
|
||||||
|
|
||||||
virtual ~Animation();
|
virtual ~Animation();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取序列帧
|
/// @brief 获取序列帧
|
||||||
FrameSequencePtr GetFrameSequence() const;
|
FrameSequencePtr GetFrameSequence() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置序列帧
|
/// @brief 设置序列帧
|
||||||
/// @param[in] frame_seq 序列帧
|
/// @param[in] frame_seq 序列帧
|
||||||
void SetFrameSequence(FrameSequencePtr frame_seq);
|
void SetFrameSequence(FrameSequencePtr frame_seq);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
ActionPtr Clone() const override;
|
ActionPtr Clone() const override;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
ActionPtr Reverse() const override;
|
ActionPtr Reverse() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,9 @@
|
||||||
//#define KGE_ASSERT(EXPR) __noop // Disable asserts
|
//#define KGE_ASSERT(EXPR) __noop // Disable asserts
|
||||||
|
|
||||||
//---- Define debug-output handler. Defaults to calling kiwano::logs::Messageln()/Warningln()/Errorln()
|
//---- 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_SYS_LOG(FORMAT, ...) wprintf(FORMAT "\n", __VA_ARGS__)
|
||||||
//#define KGE_WARN(FORMAT, ...) wprintf(FORMAT L"\n", __VA_ARGS__)
|
//#define KGE_WARN(FORMAT, ...) wprintf(FORMAT "\n", __VA_ARGS__)
|
||||||
//#define KGE_ERROR(FORMAT, ...) wprintf(FORMAT L"\n", __VA_ARGS__)
|
//#define KGE_ERROR(FORMAT, ...) wprintf(FORMAT "\n", __VA_ARGS__)
|
||||||
|
|
||||||
//---- Define attributes of all API symbols declarations for DLL
|
//---- Define attributes of all API symbols declarations for DLL
|
||||||
//#define KGE_USE_DLL
|
//#define KGE_USE_DLL
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ typedef Function<void()> AsyncTaskFunc;
|
||||||
typedef Function<void()> AsyncTaskCallback;
|
typedef Function<void()> AsyncTaskCallback;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 异步任务
|
/// @brief 异步任务
|
||||||
/// @details 在多线程下执行任务并返回
|
/// @details 在多线程下执行任务并返回
|
||||||
/// @code
|
/// @code
|
||||||
/// AsyncTaskPtr task = new AsyncTask;
|
/// AsyncTaskPtr task = new AsyncTask;
|
||||||
/// task->Then(DoSomething);
|
/// task->Then(DoSomething);
|
||||||
|
|
@ -42,27 +42,27 @@ class AsyncTask : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建异步任务
|
/// @brief 创建异步任务
|
||||||
/// @param func 异步回调函数
|
/// @param func 异步回调函数
|
||||||
static AsyncTaskPtr Create(AsyncTaskFunc func);
|
static AsyncTaskPtr Create(AsyncTaskFunc func);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造异步任务
|
/// @brief 构造异步任务
|
||||||
AsyncTask();
|
AsyncTask();
|
||||||
|
|
||||||
virtual ~AsyncTask();
|
virtual ~AsyncTask();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加异步任务链
|
/// @brief 添加异步任务链
|
||||||
AsyncTask& Then(AsyncTaskFunc func);
|
AsyncTask& Then(AsyncTaskFunc func);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置任务执行完成后的回调函数
|
/// @brief 设置任务执行完成后的回调函数
|
||||||
/// @note 该函数在 Kiwano 主线程中执行
|
/// @note 该函数在 Kiwano 主线程中执行
|
||||||
AsyncTask& SetCallback(AsyncTaskCallback callback);
|
AsyncTask& SetCallback(AsyncTaskCallback callback);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 启动异步任务
|
/// @brief 启动异步任务
|
||||||
void Start();
|
void Start();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -19,125 +19,126 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <3rd-party/OuterC/oc/oc.h>
|
|
||||||
#include <kiwano/core/Singleton.h>
|
|
||||||
#include <kiwano/macros.h>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#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
|
namespace kiwano
|
||||||
{
|
{
|
||||||
/// \~chinese
|
|
||||||
/// @brief 字符串容器
|
|
||||||
using String = oc::wstring;
|
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 窄字符串容器
|
/// @brief 输入流
|
||||||
using ByteString = oc::string;
|
using InputStream = std::istream;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 字符串流
|
/// @brief 输出流
|
||||||
using StringStream = std::wstringstream;
|
using OutputStream = std::ostream;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~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>
|
template <typename _Ty, typename... _Args>
|
||||||
using Vector = oc::vector<_Ty, _Args...>;
|
using Vector = std::vector<_Ty, _Args...>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 链表容器
|
/// @brief 链表容器
|
||||||
template <typename _Ty, typename... _Args>
|
template <typename _Ty, typename... _Args>
|
||||||
using List = std::list<_Ty, _Args...>;
|
using List = std::list<_Ty, _Args...>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 队列容器
|
/// @brief 队列容器
|
||||||
template <typename _Ty, typename... _Args>
|
template <typename _Ty, typename... _Args>
|
||||||
using Queue = std::queue<_Ty, _Args...>;
|
using Queue = std::queue<_Ty, _Args...>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 集合容器
|
/// @brief 集合容器
|
||||||
template <typename _Ty, typename... _Args>
|
template <typename _Ty, typename... _Args>
|
||||||
using Set = std::set<_Ty, _Args...>;
|
using Set = std::set<_Ty, _Args...>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 对容器
|
/// @brief 对容器
|
||||||
template <typename _Ty1, typename _Ty2>
|
template <typename _Ty1, typename _Ty2>
|
||||||
using Pair = std::pair<_Ty1, _Ty2>;
|
using Pair = std::pair<_Ty1, _Ty2>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 无序集合容器
|
/// @brief 无序集合容器
|
||||||
template <typename _Ty, typename... _Args>
|
template <typename _Ty, typename... _Args>
|
||||||
using UnorderedSet = std::unordered_set<_Ty, _Args...>;
|
using UnorderedSet = std::unordered_set<_Ty, _Args...>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 栈容器
|
/// @brief 栈容器
|
||||||
template <typename _Ty, typename... _Args>
|
template <typename _Ty, typename... _Args>
|
||||||
using Stack = std::stack<_Ty, _Args...>;
|
using Stack = std::stack<_Ty, _Args...>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 字符串容器
|
/// @brief 字符串容器
|
||||||
template <typename _Kty, typename _Ty, typename... _Args>
|
template <typename _Kty, typename _Ty, typename... _Args>
|
||||||
using Map = std::map<_Kty, _Ty, _Args...>;
|
using Map = std::map<_Kty, _Ty, _Args...>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 字符串容器
|
/// @brief 字符串容器
|
||||||
template <typename _Kty, typename _Ty, typename... _Args>
|
template <typename _Kty, typename _Ty, typename... _Args>
|
||||||
using UnorderedMap = std::unordered_map<_Kty, _Ty, _Args...>;
|
using UnorderedMap = std::unordered_map<_Kty, _Ty, _Args...>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 函数封装器
|
/// @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
|
|
||||||
template <typename _FuncTy>
|
template <typename _FuncTy>
|
||||||
using Function = oc::function<_FuncTy>;
|
using Function = oc::function<_FuncTy>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 单值容器
|
/// @brief 单值容器
|
||||||
using Any = oc::any;
|
using Any = oc::any;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief JSON对象容器
|
/// @brief 侵入式链表容器
|
||||||
using Json = oc::basic_json<Map, Vector, String, int, double, bool, std::allocator>;
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 侵入式链表容器
|
|
||||||
template <typename _Ty>
|
template <typename _Ty>
|
||||||
using IntrusiveList = oc::intrusive_list<_Ty>;
|
using IntrusiveList = oc::intrusive_list<_Ty>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 侵入式链表元素
|
/// @brief 侵入式链表元素
|
||||||
template <typename _Ty>
|
template <typename _Ty>
|
||||||
using IntrusiveListItem = oc::intrusive_list_item<_Ty>;
|
using IntrusiveListItem = oc::intrusive_list_item<_Ty>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 侵入式智能指针
|
/// @brief 侵入式智能指针
|
||||||
template <typename _Ty, typename _RefProxyTy>
|
template <typename _Ty, typename _RefProxyTy>
|
||||||
using IntrusivePtr = oc::intrusive_ptr<_Ty, _RefProxyTy>;
|
using IntrusivePtr = oc::intrusive_ptr<_Ty, _RefProxyTy>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 不可拷贝对象
|
/// @brief JSON对象容器
|
||||||
|
using Json = nlohmann::basic_json<Map, Vector, String>;
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 不可拷贝对象
|
||||||
using Noncopyable = oc::noncopyable;
|
using Noncopyable = oc::noncopyable;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 闭包函数
|
/// @brief 闭包函数
|
||||||
template <typename _Ty, typename _Uty, typename _Ret, typename... _Args>
|
template <typename _Ty, typename _Uty, typename _Ret, typename... _Args>
|
||||||
inline Function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret (_Ty::*func)(_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
|
/// \~chinese
|
||||||
/// @brief 闭包函数
|
/// @brief 闭包函数
|
||||||
template <typename _Ty, typename _Uty, typename _Ret, typename... _Args>
|
template <typename _Ty, typename _Uty, typename _Ret, typename... _Args>
|
||||||
inline Function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret (_Ty::*func)(_Args...) const)
|
inline Function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret (_Ty::*func)(_Args...) const)
|
||||||
{
|
{
|
||||||
return oc::closure(ptr, func);
|
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
|
} // namespace kiwano
|
||||||
|
|
|
||||||
|
|
@ -29,17 +29,17 @@ class Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 基础功能组件
|
* @brief 基础功能组件
|
||||||
*/
|
*/
|
||||||
class KGE_API ComponentBase
|
class KGE_API ComponentBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 启动组件
|
/// @brief 启动组件
|
||||||
virtual void SetupComponent() = 0;
|
virtual void SetupComponent() = 0;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 销毁组件
|
/// @brief 销毁组件
|
||||||
virtual void DestroyComponent() = 0;
|
virtual void DestroyComponent() = 0;
|
||||||
|
|
||||||
bool Check(const int flag);
|
bool Check(const int flag);
|
||||||
|
|
@ -53,22 +53,22 @@ protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 渲染支持组件
|
* @brief 渲染支持组件
|
||||||
*/
|
*/
|
||||||
class KGE_API RenderComponent : public virtual ComponentBase
|
class KGE_API RenderComponent : public virtual ComponentBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 渲染前
|
/// @brief 渲染前
|
||||||
virtual void BeforeRender() {}
|
virtual void BeforeRender() {}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 渲染时
|
/// @brief 渲染时
|
||||||
/// @param ctx 渲染上下文
|
/// @param ctx 渲染上下文
|
||||||
virtual void OnRender(RenderContext& ctx) {}
|
virtual void OnRender(RenderContext& ctx) {}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 渲染后
|
/// @brief 渲染后
|
||||||
virtual void AfterRender() {}
|
virtual void AfterRender() {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -79,22 +79,22 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 更新支持组件
|
* @brief 更新支持组件
|
||||||
*/
|
*/
|
||||||
class KGE_API UpdateComponent : public virtual ComponentBase
|
class KGE_API UpdateComponent : public virtual ComponentBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新前
|
/// @brief 更新前
|
||||||
virtual void BeforeUpdate() {}
|
virtual void BeforeUpdate() {}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新时
|
/// @brief 更新时
|
||||||
/// @param dt 间隔时间
|
/// @param dt 间隔时间
|
||||||
virtual void OnUpdate(Duration dt) {}
|
virtual void OnUpdate(Duration dt) {}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新后
|
/// @brief 更新后
|
||||||
virtual void AfterUpdate() {}
|
virtual void AfterUpdate() {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -105,14 +105,14 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 事件支持组件
|
* @brief 事件支持组件
|
||||||
*/
|
*/
|
||||||
class KGE_API EventComponent : public virtual ComponentBase
|
class KGE_API EventComponent : public virtual ComponentBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 事件处理
|
/// @brief 事件处理
|
||||||
/// @param evt 事件
|
/// @param evt 事件
|
||||||
virtual void HandleEvent(Event* evt) {}
|
virtual void HandleEvent(Event* evt) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 导演
|
* @brief 导演
|
||||||
* @details 导演完成舞台的渲染、更新、事件分发以及控制舞台间跳转
|
* @details 导演完成舞台的渲染、更新、事件分发以及控制舞台间跳转
|
||||||
* @see kiwano::Stage
|
* @see kiwano::Stage
|
||||||
*/
|
*/
|
||||||
class KGE_API Director
|
class KGE_API Director
|
||||||
|
|
@ -43,51 +43,51 @@ class KGE_API Director
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 切换舞台
|
* @brief 切换舞台
|
||||||
* @param[in] stage 舞台
|
* @param[in] stage 舞台
|
||||||
* @param[in] transition 过渡动画
|
* @param[in] transition 过渡动画
|
||||||
*/
|
*/
|
||||||
void EnterStage(StagePtr stage, TransitionPtr transition = nullptr);
|
void EnterStage(StagePtr stage, TransitionPtr transition = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 切换舞台,并将当前舞台储存到栈中
|
* @brief 切换舞台,并将当前舞台储存到栈中
|
||||||
* @param[in] stage 舞台
|
* @param[in] stage 舞台
|
||||||
* @param[in] transition 过渡动画
|
* @param[in] transition 过渡动画
|
||||||
*/
|
*/
|
||||||
void PushStage(StagePtr stage, TransitionPtr transition = nullptr);
|
void PushStage(StagePtr stage, TransitionPtr transition = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 退出当前舞台,并切换到上一个舞台
|
* @brief 退出当前舞台,并切换到上一个舞台
|
||||||
* @param[in] transition 过渡动画
|
* @param[in] transition 过渡动画
|
||||||
*/
|
*/
|
||||||
void PopStage(TransitionPtr transition = nullptr);
|
void PopStage(TransitionPtr transition = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 获取当前舞台
|
* @brief 获取当前舞台
|
||||||
* @return 返回当前舞台的指针
|
* @return 返回当前舞台的指针
|
||||||
*/
|
*/
|
||||||
StagePtr GetCurrentStage();
|
StagePtr GetCurrentStage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 启用或禁用角色边界渲染功能
|
* @brief 启用或禁用角色边界渲染功能
|
||||||
* @param enabled 是否启用
|
* @param enabled 是否启用
|
||||||
*/
|
*/
|
||||||
void SetRenderBorderEnabled(bool enabled);
|
void SetRenderBorderEnabled(bool enabled);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 显示或隐藏调试信息
|
* @brief 显示或隐藏调试信息
|
||||||
* @param show 是否显示
|
* @param show 是否显示
|
||||||
*/
|
*/
|
||||||
void ShowDebugInfo(bool show = true);
|
void ShowDebugInfo(bool show = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 退出当前舞台并清空舞台栈
|
* @brief 退出当前舞台并清空舞台栈
|
||||||
*/
|
*/
|
||||||
void ClearStages();
|
void ClearStages();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,40 +25,40 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 事件分发系统
|
* @brief 事件分发系统
|
||||||
*/
|
*/
|
||||||
class KGE_API EventDispatcher
|
class KGE_API EventDispatcher
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 监听器列表
|
/// @brief 监听器列表
|
||||||
using Listeners = IntrusiveList<EventListenerPtr>;
|
using Listeners = IntrusiveList<EventListenerPtr>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加监听器
|
/// @brief 添加监听器
|
||||||
EventListener* AddListener(EventListenerPtr listener);
|
EventListener* AddListener(EventListenerPtr listener);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加监听器
|
/// @brief 添加监听器
|
||||||
EventListener* AddListener(EventListener* listener);
|
EventListener* AddListener(EventListener* listener);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加监听器
|
/// @brief 添加监听器
|
||||||
/// @param type 监听的事件类型
|
/// @param type 监听的事件类型
|
||||||
/// @param callback 回调函数
|
/// @param callback 回调函数
|
||||||
EventListener* AddListener(EventType type, EventListener::Callback callback);
|
EventListener* AddListener(EventType type, EventListener::Callback callback);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加监听器
|
/// @brief 添加监听器
|
||||||
/// @param name 监听器名称
|
/// @param name 监听器名称
|
||||||
/// @param type 监听的事件类型
|
/// @param type 监听的事件类型
|
||||||
/// @param callback 回调函数
|
/// @param callback 回调函数
|
||||||
EventListener* AddListener(String const& name, EventType type, EventListener::Callback callback);
|
EventListener* AddListener(String const& name, EventType type, EventListener::Callback callback);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加监听器
|
/// @brief 添加监听器
|
||||||
/// @tparam _EventTy 事件类型
|
/// @tparam _EventTy 事件类型
|
||||||
/// @param callback 回调函数
|
/// @param callback 回调函数
|
||||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
||||||
EventListener* AddListener(EventListener::Callback callback)
|
EventListener* AddListener(EventListener::Callback callback)
|
||||||
{
|
{
|
||||||
|
|
@ -66,10 +66,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加监听器
|
/// @brief 添加监听器
|
||||||
/// @tparam _EventTy 事件类型
|
/// @tparam _EventTy 事件类型
|
||||||
/// @param name 监听器名称
|
/// @param name 监听器名称
|
||||||
/// @param callback 回调函数
|
/// @param callback 回调函数
|
||||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>>
|
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>>
|
||||||
EventListener* AddListener(String const& name, EventListener::Callback callback)
|
EventListener* AddListener(String const& name, EventListener::Callback callback)
|
||||||
{
|
{
|
||||||
|
|
@ -77,55 +77,55 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 启动监听器
|
/// @brief 启动监听器
|
||||||
/// @param name 监听器名称
|
/// @param name 监听器名称
|
||||||
void StartListeners(String const& name);
|
void StartListeners(String const& name);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 停止监听器
|
/// @brief 停止监听器
|
||||||
/// @param name 监听器名称
|
/// @param name 监听器名称
|
||||||
void StopListeners(String const& name);
|
void StopListeners(String const& name);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除监听器
|
/// @brief 移除监听器
|
||||||
/// @param name 监听器名称
|
/// @param name 监听器名称
|
||||||
void RemoveListeners(String const& name);
|
void RemoveListeners(String const& name);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 启动监听器
|
/// @brief 启动监听器
|
||||||
/// @param type 监听的事件类型
|
/// @param type 监听的事件类型
|
||||||
void StartListeners(const EventType& type);
|
void StartListeners(const EventType& type);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 停止监听器
|
/// @brief 停止监听器
|
||||||
/// @param type 监听的事件类型
|
/// @param type 监听的事件类型
|
||||||
void StopListeners(const EventType& type);
|
void StopListeners(const EventType& type);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除监听器
|
/// @brief 移除监听器
|
||||||
/// @param type 监听的事件类型
|
/// @param type 监听的事件类型
|
||||||
void RemoveListeners(const EventType& type);
|
void RemoveListeners(const EventType& type);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 启动所有监听器
|
/// @brief 启动所有监听器
|
||||||
void StartAllListeners();
|
void StartAllListeners();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 停止所有监听器
|
/// @brief 停止所有监听器
|
||||||
void StopAllListeners();
|
void StopAllListeners();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除所有监听器
|
/// @brief 移除所有监听器
|
||||||
void RemoveAllListeners();
|
void RemoveAllListeners();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取所有监听器
|
/// @brief 获取所有监听器
|
||||||
const Listeners& GetAllListeners() const;
|
const Listeners& GetAllListeners() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 分发事件
|
/// @brief 分发事件
|
||||||
/// @param evt 事件
|
/// @param evt 事件
|
||||||
/// @return 是否继续分发该事件
|
/// @return 是否继续分发该事件
|
||||||
bool DispatchEvent(Event* evt);
|
bool DispatchEvent(Event* evt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ KGE_DECLARE_SMART_PTR(EventListener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 事件监听器
|
* @brief 事件监听器
|
||||||
*/
|
*/
|
||||||
class KGE_API EventListener
|
class KGE_API EventListener
|
||||||
: public virtual ObjectBase
|
: public virtual ObjectBase
|
||||||
|
|
@ -46,26 +46,26 @@ class KGE_API EventListener
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 监听器回调函数
|
/// @brief 监听器回调函数
|
||||||
using Callback = Function<void(Event*)>;
|
using Callback = Function<void(Event*)>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建监听器
|
/// @brief 创建监听器
|
||||||
/// @param type 监听的事件类型
|
/// @param type 监听的事件类型
|
||||||
/// @param callback 回调函数
|
/// @param callback 回调函数
|
||||||
static EventListenerPtr Create(EventType type, Callback const& callback);
|
static EventListenerPtr Create(EventType type, Callback const& callback);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建监听器
|
/// @brief 创建监听器
|
||||||
/// @param name 监听器名称
|
/// @param name 监听器名称
|
||||||
/// @param type 监听的事件类型
|
/// @param type 监听的事件类型
|
||||||
/// @param callback 回调函数
|
/// @param callback 回调函数
|
||||||
static EventListenerPtr Create(String const& name, EventType type, Callback const& callback);
|
static EventListenerPtr Create(String const& name, EventType type, Callback const& callback);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建监听器
|
/// @brief 创建监听器
|
||||||
/// @tparam _EventTy 事件类型
|
/// @tparam _EventTy 事件类型
|
||||||
/// @param callback 回调函数
|
/// @param callback 回调函数
|
||||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
||||||
static inline EventListenerPtr Create(Callback const& callback)
|
static inline EventListenerPtr Create(Callback const& callback)
|
||||||
{
|
{
|
||||||
|
|
@ -73,10 +73,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建监听器
|
/// @brief 创建监听器
|
||||||
/// @tparam _EventTy 事件类型
|
/// @tparam _EventTy 事件类型
|
||||||
/// @param name 监听器名称
|
/// @param name 监听器名称
|
||||||
/// @param callback 回调函数
|
/// @param callback 回调函数
|
||||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
||||||
static inline EventListenerPtr Create(String const& name, Callback const& callback)
|
static inline EventListenerPtr Create(String const& name, Callback const& callback)
|
||||||
{
|
{
|
||||||
|
|
@ -88,53 +88,53 @@ public:
|
||||||
virtual ~EventListener();
|
virtual ~EventListener();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 启动监听器
|
/// @brief 启动监听器
|
||||||
void Start();
|
void Start();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 停止监听器
|
/// @brief 停止监听器
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除监听器
|
/// @brief 移除监听器
|
||||||
void Remove();
|
void Remove();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否正在运行
|
/// @brief 是否正在运行
|
||||||
bool IsRunning() const;
|
bool IsRunning() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否可移除
|
/// @brief 是否可移除
|
||||||
bool IsRemoveable() const;
|
bool IsRemoveable() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否开启消息吞没
|
/// @brief 是否开启消息吞没
|
||||||
bool IsSwallowEnabled() const;
|
bool IsSwallowEnabled() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置消息吞没功能
|
/// @brief 设置消息吞没功能
|
||||||
/// @param enabled 是否启用
|
/// @param enabled 是否启用
|
||||||
void SetSwallowEnabled(bool enabled);
|
void SetSwallowEnabled(bool enabled);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取回调函数
|
/// @brief 获取回调函数
|
||||||
const Callback& GetCallback() const;
|
const Callback& GetCallback() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置回调函数
|
/// @brief 设置回调函数
|
||||||
void SetCallback(Callback const& cb);
|
void SetCallback(Callback const& cb);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取监听的事件类型
|
/// @brief 获取监听的事件类型
|
||||||
EventType GetEventType() const;
|
EventType GetEventType() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置监听的事件类型
|
/// @brief 设置监听的事件类型
|
||||||
void SetEventType(EventType const& type);
|
void SetEventType(EventType const& type);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置监听的事件类型
|
/// @brief 设置监听的事件类型
|
||||||
/// @tparam _EventTy 事件类型
|
/// @tparam _EventTy 事件类型
|
||||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
||||||
inline void SetEventType()
|
inline void SetEventType()
|
||||||
{
|
{
|
||||||
|
|
@ -142,7 +142,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 接收消息
|
/// @brief 接收消息
|
||||||
void Receive(Event* evt);
|
void Receive(Event* evt);
|
||||||
|
|
||||||
private:
|
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
|
namespace kiwano
|
||||||
{
|
{
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 鼠标按键
|
/// @brief 鼠标按键
|
||||||
enum class MouseButton
|
enum class MouseButton
|
||||||
{
|
{
|
||||||
Left, ///< 鼠标左键
|
Left, ///< 鼠标左键
|
||||||
Right, ///< 鼠标右键
|
Right, ///< 鼠标右键
|
||||||
Middle, ///< 鼠标中键
|
Middle, ///< 鼠标中键
|
||||||
|
|
||||||
Last
|
Last
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 按键键值
|
/// @brief 按键键值
|
||||||
enum class KeyCode
|
enum class KeyCode
|
||||||
{
|
{
|
||||||
Unknown, ///< 未知
|
Unknown, ///< 未知
|
||||||
Up, ///< 上键
|
Up, ///< 上键
|
||||||
Left, ///< 左键
|
Left, ///< 左键
|
||||||
Right, ///< 右键
|
Right, ///< 右键
|
||||||
Down, ///< 下键
|
Down, ///< 下键
|
||||||
Enter, ///< 回车键
|
Enter, ///< 回车键
|
||||||
Space, ///< 空格键
|
Space, ///< 空格键
|
||||||
Esc, ///< 退出键
|
Esc, ///< 退出键
|
||||||
Ctrl, ///< CTRL键
|
Ctrl, ///< CTRL键
|
||||||
Shift, ///< SHIFT键
|
Shift, ///< SHIFT键
|
||||||
Alt, ///< ALT键
|
Alt, ///< ALT键
|
||||||
Tab, ///< TAB键
|
Tab, ///< TAB键
|
||||||
Delete, ///< 删除键
|
Delete, ///< 删除键
|
||||||
Back, ///< 退格键
|
Back, ///< 退格键
|
||||||
Super, ///< Cmd|Super|Windows键
|
Super, ///< Cmd|Super|Windows键
|
||||||
|
|
||||||
A, ///< A键
|
A, ///< A键
|
||||||
B, ///< B键
|
B, ///< B键
|
||||||
C, ///< C键
|
C, ///< C键
|
||||||
D, ///< D键
|
D, ///< D键
|
||||||
E, ///< E键
|
E, ///< E键
|
||||||
F, ///< F键
|
F, ///< F键
|
||||||
G, ///< G键
|
G, ///< G键
|
||||||
H, ///< H键
|
H, ///< H键
|
||||||
I, ///< I键
|
I, ///< I键
|
||||||
J, ///< J键
|
J, ///< J键
|
||||||
K, ///< K键
|
K, ///< K键
|
||||||
L, ///< L键
|
L, ///< L键
|
||||||
M, ///< M键
|
M, ///< M键
|
||||||
N, ///< N键
|
N, ///< N键
|
||||||
O, ///< O键
|
O, ///< O键
|
||||||
P, ///< P键
|
P, ///< P键
|
||||||
Q, ///< Q键
|
Q, ///< Q键
|
||||||
R, ///< R键
|
R, ///< R键
|
||||||
S, ///< S键
|
S, ///< S键
|
||||||
T, ///< T键
|
T, ///< T键
|
||||||
U, ///< U键
|
U, ///< U键
|
||||||
V, ///< V键
|
V, ///< V键
|
||||||
W, ///< W键
|
W, ///< W键
|
||||||
X, ///< X键
|
X, ///< X键
|
||||||
Y, ///< Y键
|
Y, ///< Y键
|
||||||
Z, ///< Z键
|
Z, ///< Z键
|
||||||
|
|
||||||
Num0, ///< 数字0键
|
Num0, ///< 数字0键
|
||||||
Num1, ///< 数字1键
|
Num1, ///< 数字1键
|
||||||
Num2, ///< 数字2键
|
Num2, ///< 数字2键
|
||||||
Num3, ///< 数字3键
|
Num3, ///< 数字3键
|
||||||
Num4, ///< 数字4键
|
Num4, ///< 数字4键
|
||||||
Num5, ///< 数字5键
|
Num5, ///< 数字5键
|
||||||
Num6, ///< 数字6键
|
Num6, ///< 数字6键
|
||||||
Num7, ///< 数字7键
|
Num7, ///< 数字7键
|
||||||
Num8, ///< 数字8键
|
Num8, ///< 数字8键
|
||||||
Num9, ///< 数字9键
|
Num9, ///< 数字9键
|
||||||
|
|
||||||
Numpad0, ///< 数字小键盘0键
|
Numpad0, ///< 数字小键盘0键
|
||||||
Numpad1, ///< 数字小键盘1键
|
Numpad1, ///< 数字小键盘1键
|
||||||
Numpad2, ///< 数字小键盘2键
|
Numpad2, ///< 数字小键盘2键
|
||||||
Numpad3, ///< 数字小键盘3键
|
Numpad3, ///< 数字小键盘3键
|
||||||
Numpad4, ///< 数字小键盘4键
|
Numpad4, ///< 数字小键盘4键
|
||||||
Numpad5, ///< 数字小键盘5键
|
Numpad5, ///< 数字小键盘5键
|
||||||
Numpad6, ///< 数字小键盘6键
|
Numpad6, ///< 数字小键盘6键
|
||||||
Numpad7, ///< 数字小键盘7键
|
Numpad7, ///< 数字小键盘7键
|
||||||
Numpad8, ///< 数字小键盘8键
|
Numpad8, ///< 数字小键盘8键
|
||||||
Numpad9, ///< 数字小键盘9键
|
Numpad9, ///< 数字小键盘9键
|
||||||
|
|
||||||
F1, ///< F1键
|
F1, ///< F1键
|
||||||
F2, ///< F2键
|
F2, ///< F2键
|
||||||
F3, ///< F3键
|
F3, ///< F3键
|
||||||
F4, ///< F4键
|
F4, ///< F4键
|
||||||
F5, ///< F5键
|
F5, ///< F5键
|
||||||
F6, ///< F6键
|
F6, ///< F6键
|
||||||
F7, ///< F7键
|
F7, ///< F7键
|
||||||
F8, ///< F8键
|
F8, ///< F8键
|
||||||
F9, ///< F9键
|
F9, ///< F9键
|
||||||
F10, ///< F10键
|
F10, ///< F10键
|
||||||
F11, ///< F11键
|
F11, ///< F11键
|
||||||
F12, ///< F12键
|
F12, ///< F12键
|
||||||
|
|
||||||
Last
|
Last
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -40,12 +40,6 @@ Library::~Library()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Library::Load(String const& lib)
|
bool Library::Load(String const& lib)
|
||||||
{
|
|
||||||
instance_ = ::LoadLibraryW(lib.c_str());
|
|
||||||
return IsValid();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Library::Load(ByteString const& lib)
|
|
||||||
{
|
{
|
||||||
instance_ = ::LoadLibraryA(lib.c_str());
|
instance_ = ::LoadLibraryA(lib.c_str());
|
||||||
return IsValid();
|
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);
|
KGE_ASSERT(instance_ != nullptr);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,56 +20,50 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/core/Common.h>
|
#include <kiwano/core/Common.h>
|
||||||
#include <kiwano/macros.h>
|
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief DLL库
|
* @brief DLL库
|
||||||
*/
|
*/
|
||||||
class KGE_API Library
|
class KGE_API Library
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造DLL库
|
/// @brief 构造DLL库
|
||||||
Library();
|
Library();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造DLL库
|
/// @brief 构造DLL库
|
||||||
/// @param lib DLL文件路径
|
/// @param lib DLL文件路径
|
||||||
Library(String const& lib);
|
Library(String const& lib);
|
||||||
|
|
||||||
virtual ~Library();
|
virtual ~Library();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 加载DLL
|
/// @brief 加载DLL
|
||||||
/// @param lib DLL文件路径
|
/// @param lib DLL文件路径
|
||||||
bool Load(String const& lib);
|
bool Load(String const& lib);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 加载DLL
|
/// @brief 是否有效
|
||||||
/// @param lib DLL文件路径
|
|
||||||
bool Load(ByteString const& lib);
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 是否有效
|
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 释放DLL
|
/// @brief 释放DLL
|
||||||
void Free();
|
void Free();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 检索指定的DLL中的输出库函数地址
|
/// @brief 检索指定的DLL中的输出库函数地址
|
||||||
/// @param proc_name 函数名
|
/// @param proc_name 函数名
|
||||||
FARPROC GetProcess(ByteString const& proc_name);
|
FARPROC GetProcess(String const& proc_name);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 检索指定的DLL中的输出库函数地址
|
/// @brief 检索指定的DLL中的输出库函数地址
|
||||||
/// @param proc_name 函数名
|
/// @param proc_name 函数名
|
||||||
template <typename _Proc>
|
template <typename _Proc>
|
||||||
inline _Proc GetProcess(ByteString const& proc_name)
|
inline _Proc GetProcess(String const& proc_name)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<_Proc>(GetProcess(proc_name));
|
return reinterpret_cast<_Proc>(GetProcess(proc_name));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ const WORD reset = white;
|
||||||
} // namespace console_colors
|
} // namespace console_colors
|
||||||
|
|
||||||
#define DECLARE_HANDLE_COLOR(NAME, HANDLE_NAME, COLOR) \
|
#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); \
|
::SetConsoleTextAttribute(::GetStdHandle(HANDLE_NAME), console_colors::##COLOR); \
|
||||||
return _out; \
|
return _out; \
|
||||||
|
|
@ -175,8 +175,8 @@ Logger::Logger()
|
||||||
: enabled_(true)
|
: enabled_(true)
|
||||||
, default_stdout_color_(0)
|
, default_stdout_color_(0)
|
||||||
, default_stderr_color_(0)
|
, default_stderr_color_(0)
|
||||||
, output_stream_(std::wcout.rdbuf())
|
, output_stream_(std::cout.rdbuf())
|
||||||
, error_stream_(std::wcerr.rdbuf())
|
, error_stream_(std::cerr.rdbuf())
|
||||||
{
|
{
|
||||||
ResetOutputStream();
|
ResetOutputStream();
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +186,7 @@ Logger::~Logger()
|
||||||
FreeAllocatedConsole();
|
FreeAllocatedConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::Printf(Level level, const wchar_t* format, ...)
|
void Logger::Printf(Level level, const char* format, ...)
|
||||||
{
|
{
|
||||||
if (!enabled_)
|
if (!enabled_)
|
||||||
return;
|
return;
|
||||||
|
|
@ -200,11 +200,11 @@ void Logger::Printf(Level level, const wchar_t* format, ...)
|
||||||
va_list args = nullptr;
|
va_list args = nullptr;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
||||||
static wchar_t temp_buffer[1024 * 3 + 1];
|
static char temp_buffer[1024 * 3 + 1];
|
||||||
const auto len = ::_vscwprintf(format, args) + 1;
|
const auto len = ::_vscprintf(format, args) + 1;
|
||||||
::_vsnwprintf_s(temp_buffer, len, len, format, args);
|
::_vsnprintf_s(temp_buffer, len, len, format, args);
|
||||||
|
|
||||||
sstream << ' ' << temp_buffer << L"\r\n";
|
sstream << ' ' << temp_buffer << "\r\n";
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
@ -219,16 +219,16 @@ void Logger::Prepare(Level level, StringStream& sstream)
|
||||||
switch (level)
|
switch (level)
|
||||||
{
|
{
|
||||||
case Level::Info:
|
case Level::Info:
|
||||||
prefix = L"[INFO] ";
|
prefix = "[INFO] ";
|
||||||
break;
|
break;
|
||||||
case Level::System:
|
case Level::System:
|
||||||
prefix = L"[SYSTEM] ";
|
prefix = "[SYSTEM] ";
|
||||||
break;
|
break;
|
||||||
case Level::Warning:
|
case Level::Warning:
|
||||||
prefix = L"[WARN] ";
|
prefix = "[WARN] ";
|
||||||
break;
|
break;
|
||||||
case Level::Error:
|
case Level::Error:
|
||||||
prefix = L"[ERROR] ";
|
prefix = "[ERROR] ";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -236,11 +236,13 @@ void Logger::Prepare(Level level, StringStream& sstream)
|
||||||
time_t unix = std::time(nullptr);
|
time_t unix = std::time(nullptr);
|
||||||
std::tm tmbuf;
|
std::tm tmbuf;
|
||||||
localtime_s(&tmbuf, &unix);
|
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)
|
void Logger::Output(Level level, StringStream& sstream)
|
||||||
{
|
{
|
||||||
|
using ConsoleColor = Function<OutputStream&(OutputStream&)>;
|
||||||
|
|
||||||
OutputStream* ostream = nullptr;
|
OutputStream* ostream = nullptr;
|
||||||
ConsoleColor color = nullptr;
|
ConsoleColor color = nullptr;
|
||||||
|
|
||||||
|
|
@ -269,7 +271,7 @@ void Logger::Output(Level level, StringStream& sstream)
|
||||||
{
|
{
|
||||||
auto output = sstream.str();
|
auto output = sstream.str();
|
||||||
color(*ostream) << output << std::flush;
|
color(*ostream) << output << std::flush;
|
||||||
::OutputDebugStringW(output.c_str());
|
::OutputDebugStringA(output.c_str());
|
||||||
|
|
||||||
ResetConsoleColor();
|
ResetConsoleColor();
|
||||||
}
|
}
|
||||||
|
|
@ -297,20 +299,20 @@ void Logger::ResetOutputStream()
|
||||||
|
|
||||||
// replace the C++ global locale with the user-preferred locale
|
// replace the C++ global locale with the user-preferred locale
|
||||||
(void)std::locale::global(std::locale(""));
|
(void)std::locale::global(std::locale(""));
|
||||||
(void)std::wcout.imbue(std::locale());
|
(void)std::cout.imbue(std::locale());
|
||||||
(void)std::wcerr.imbue(std::locale());
|
(void)std::cerr.imbue(std::locale());
|
||||||
|
|
||||||
RedirectOutputStreamBuffer(std::wcout.rdbuf());
|
RedirectOutputStreamBuffer(std::cout.rdbuf());
|
||||||
RedirectErrorStreamBuffer(std::wcerr.rdbuf());
|
RedirectErrorStreamBuffer(std::cerr.rdbuf());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstreambuf* Logger::RedirectOutputStreamBuffer(std::wstreambuf* buf)
|
std::streambuf* Logger::RedirectOutputStreamBuffer(std::streambuf* buf)
|
||||||
{
|
{
|
||||||
return output_stream_.rdbuf(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);
|
return error_stream_.rdbuf(buf);
|
||||||
}
|
}
|
||||||
|
|
@ -329,7 +331,7 @@ void Logger::ShowConsole(bool show)
|
||||||
HWND console = ::AllocateConsole();
|
HWND console = ::AllocateConsole();
|
||||||
if (!console)
|
if (!console)
|
||||||
{
|
{
|
||||||
KGE_WARN(L"AllocConsole failed");
|
KGE_WARN("AllocConsole failed");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -27,33 +27,33 @@
|
||||||
#ifndef KGE_SYS_LOG
|
#ifndef KGE_SYS_LOG
|
||||||
#ifdef KGE_DEBUG
|
#ifdef KGE_DEBUG
|
||||||
#define KGE_SYS_LOG(FORMAT, ...) \
|
#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
|
#else
|
||||||
#define KGE_SYS_LOG __noop
|
#define KGE_SYS_LOG __noop
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef KGE_WARN
|
#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
|
#endif
|
||||||
|
|
||||||
#ifndef KGE_ERROR
|
#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
|
#endif
|
||||||
|
|
||||||
#ifndef KGE_LOG
|
#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
|
#endif
|
||||||
|
|
||||||
#ifndef KGE_LOGF
|
#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
|
#endif
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 日志
|
* @brief 日志
|
||||||
*/
|
*/
|
||||||
class KGE_API Logger : public Singleton<Logger>
|
class KGE_API Logger : public Singleton<Logger>
|
||||||
{
|
{
|
||||||
|
|
@ -61,74 +61,66 @@ class KGE_API Logger : public Singleton<Logger>
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 日志级别
|
/// @brief 日志级别
|
||||||
enum class Level
|
enum class Level
|
||||||
{
|
{
|
||||||
Info, ///< 信息
|
Info, ///< 信息
|
||||||
System, ///< 系统
|
System, ///< 系统
|
||||||
Warning, ///< 警告
|
Warning, ///< 警告
|
||||||
Error ///< 错误
|
Error ///< 错误
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 输出流
|
/// @brief 打印日志
|
||||||
using OutputStream = std::wostream;
|
/// @param level 日志级别
|
||||||
|
/// @param format 格式字符串
|
||||||
|
void Printf(Level level, const char* format, ...);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 控制台颜色
|
/// @brief 打印日志
|
||||||
using ConsoleColor = Function<OutputStream&(OutputStream&)>;
|
/// @param level 日志级别
|
||||||
|
/// @param args 参数
|
||||||
/// \~chinese
|
|
||||||
/// @brief 打印日志
|
|
||||||
/// @param level 日志级别
|
|
||||||
/// @param format 格式字符串
|
|
||||||
void Printf(Level level, const wchar_t* format, ...);
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 打印日志
|
|
||||||
/// @param level 日志级别
|
|
||||||
/// @param args 参数
|
|
||||||
template <typename... _Args>
|
template <typename... _Args>
|
||||||
void Print(Level level, _Args&&... args);
|
void Print(Level level, _Args&&... args);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 打印一行日志
|
/// @brief 打印一行日志
|
||||||
/// @param level 日志级别
|
/// @param level 日志级别
|
||||||
/// @param args 参数
|
/// @param args 参数
|
||||||
template <typename... _Args>
|
template <typename... _Args>
|
||||||
void Println(Level level, _Args&&... args);
|
void Println(Level level, _Args&&... args);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 显示或关闭控制台
|
/// @brief 显示或关闭控制台
|
||||||
/// @note 此操作会重置输出流
|
/// @note 此操作会重置输出流
|
||||||
void ShowConsole(bool show);
|
void ShowConsole(bool show);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 启用日志
|
/// @brief 启用日志
|
||||||
void Enable();
|
void Enable();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 禁用日志
|
/// @brief 禁用日志
|
||||||
void Disable();
|
void Disable();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取输出流
|
/// @brief 获取输出流
|
||||||
std::wostream& GetOutputStream();
|
OutputStream& GetOutputStream();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取错误流
|
/// @brief 获取错误流
|
||||||
std::wostream& GetErrorStream();
|
OutputStream& GetErrorStream();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 重定向输出流
|
/// @brief 重定向输出流
|
||||||
std::wstreambuf* RedirectOutputStreamBuffer(std::wstreambuf* buf);
|
std::streambuf* RedirectOutputStreamBuffer(std::streambuf* buf);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 重定向错误流
|
/// @brief 重定向错误流
|
||||||
std::wstreambuf* RedirectErrorStreamBuffer(std::wstreambuf* buf);
|
std::streambuf* RedirectErrorStreamBuffer(std::streambuf* buf);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 重置输出流
|
/// @brief 重置输出流
|
||||||
void ResetOutputStream();
|
void ResetOutputStream();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -190,7 +182,7 @@ void Logger::Println(Level level, _Args&&... args)
|
||||||
// Format message
|
// Format message
|
||||||
(void)std::initializer_list<int>{ ((sstream << ' ' << args), 0)... };
|
(void)std::initializer_list<int>{ ((sstream << ' ' << args), 0)... };
|
||||||
|
|
||||||
sstream << L"\r\n";
|
sstream << "\r\n";
|
||||||
|
|
||||||
Output(level, sstream);
|
Output(level, sstream);
|
||||||
}
|
}
|
||||||
|
|
@ -201,18 +193,18 @@ inline void Logger::ResetConsoleColor() const
|
||||||
::SetConsoleTextAttribute(::GetStdHandle(STD_ERROR_HANDLE), default_stderr_color_);
|
::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_);
|
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), default_stdout_color_);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::wostream& Logger::GetOutputStream()
|
inline OutputStream& Logger::GetOutputStream()
|
||||||
{
|
{
|
||||||
return output_stream_;
|
return output_stream_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::wostream& Logger::GetErrorStream()
|
inline OutputStream& Logger::GetErrorStream()
|
||||||
{
|
{
|
||||||
return error_stream_;
|
return error_stream_;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,9 +88,8 @@ void ObjectBase::SetName(String const& name)
|
||||||
|
|
||||||
String ObjectBase::DumpObject()
|
String ObjectBase::DumpObject()
|
||||||
{
|
{
|
||||||
String name = oc::string_to_wide(typeid(*this).name());
|
return String::format("{ class=\"%s\" id=%d refcount=%d name=\"%s\" }", typeid(*this).name(), GetObjectID(),
|
||||||
return String::format(L"{ class=\"%s\" id=%d refcount=%d name=\"%s\" }", name.c_str(), GetObjectID(), GetRefCount(),
|
GetRefCount(), GetName().c_str());
|
||||||
GetName().c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ObjectBase::IsTracingLeaks()
|
bool ObjectBase::IsTracingLeaks()
|
||||||
|
|
@ -110,12 +109,12 @@ void ObjectBase::StopTracingLeaks()
|
||||||
|
|
||||||
void ObjectBase::DumpTracingObjects()
|
void ObjectBase::DumpTracingObjects()
|
||||||
{
|
{
|
||||||
KGE_SYS_LOG(L"-------------------------- All Objects --------------------------");
|
KGE_SYS_LOG("-------------------------- All Objects --------------------------");
|
||||||
for (const auto object : tracing_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()
|
Vector<ObjectBase*>& ObjectBase::GetTracingObjects()
|
||||||
|
|
|
||||||
|
|
@ -30,65 +30,65 @@ KGE_DECLARE_SMART_PTR(ObjectBase);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 基础对象
|
* @brief 基础对象
|
||||||
*/
|
*/
|
||||||
class KGE_API ObjectBase : public RefCounter
|
class KGE_API ObjectBase : public RefCounter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造基础对象
|
/// @brief 构造基础对象
|
||||||
ObjectBase();
|
ObjectBase();
|
||||||
|
|
||||||
virtual ~ObjectBase();
|
virtual ~ObjectBase();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置对象名
|
/// @brief 设置对象名
|
||||||
void SetName(String const& name);
|
void SetName(String const& name);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取对象名
|
/// @brief 获取对象名
|
||||||
String GetName() const;
|
String GetName() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 判断对象的名称是否相同
|
/// @brief 判断对象的名称是否相同
|
||||||
/// @param name 需要判断的名称
|
/// @param name 需要判断的名称
|
||||||
bool IsName(String const& name) const;
|
bool IsName(String const& name) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取用户数据
|
/// @brief 获取用户数据
|
||||||
const Any& GetUserData() const;
|
const Any& GetUserData() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置用户数据
|
/// @brief 设置用户数据
|
||||||
void SetUserData(Any const& data);
|
void SetUserData(Any const& data);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取对象ID
|
/// @brief 获取对象ID
|
||||||
uint32_t GetObjectID() const;
|
uint32_t GetObjectID() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 序列化对象
|
/// @brief 序列化对象
|
||||||
String DumpObject();
|
String DumpObject();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否启用了内存泄漏追踪
|
/// @brief 是否启用了内存泄漏追踪
|
||||||
static bool IsTracingLeaks();
|
static bool IsTracingLeaks();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 开始追踪内存泄漏
|
/// @brief 开始追踪内存泄漏
|
||||||
static void StartTracingLeaks();
|
static void StartTracingLeaks();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 停止追踪内存泄漏
|
/// @brief 停止追踪内存泄漏
|
||||||
static void StopTracingLeaks();
|
static void StopTracingLeaks();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 打印所有追踪中的对象信息
|
/// @brief 打印所有追踪中的对象信息
|
||||||
static void DumpTracingObjects();
|
static void DumpTracingObjects();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取所有追踪中的对象
|
/// @brief 获取所有追踪中的对象
|
||||||
static Vector<ObjectBase*>& GetTracingObjects();
|
static Vector<ObjectBase*>& GetTracingObjects();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -26,21 +26,21 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 引用计数器
|
* @brief 引用计数器
|
||||||
*/
|
*/
|
||||||
class KGE_API RefCounter : protected Noncopyable
|
class KGE_API RefCounter : protected Noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 增加引用计数
|
/// @brief 增加引用计数
|
||||||
void Retain();
|
void Retain();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 减少引用计数
|
/// @brief 减少引用计数
|
||||||
void Release();
|
void Release();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取引用计数
|
/// @brief 获取引用计数
|
||||||
long GetRefCount() const;
|
long GetRefCount() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -48,28 +48,28 @@ Resource::Data Resource::GetData() const
|
||||||
HRSRC res_info = FindResourceW(nullptr, MAKEINTRESOURCE(id_), type_);
|
HRSRC res_info = FindResourceW(nullptr, MAKEINTRESOURCE(id_), type_);
|
||||||
if (res_info == nullptr)
|
if (res_info == nullptr)
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"FindResource failed");
|
KGE_ERROR("FindResource failed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
HGLOBAL res_data = LoadResource(nullptr, res_info);
|
HGLOBAL res_data = LoadResource(nullptr, res_info);
|
||||||
if (res_data == nullptr)
|
if (res_data == nullptr)
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"LoadResource failed");
|
KGE_ERROR("LoadResource failed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD size = SizeofResource(nullptr, res_info);
|
DWORD size = SizeofResource(nullptr, res_info);
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"SizeofResource failed");
|
KGE_ERROR("SizeofResource failed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
LPVOID buffer = LockResource(res_data);
|
LPVOID buffer = LockResource(res_data);
|
||||||
if (buffer == nullptr)
|
if (buffer == nullptr)
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"LockResource failed");
|
KGE_ERROR("LockResource failed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,26 +26,26 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 资源
|
* @brief 资源
|
||||||
* @details
|
* @details
|
||||||
* 资源是保存在 exe 中的二进制数据,
|
* 资源是保存在 exe 中的二进制数据,
|
||||||
* 例如,一份音频资源的类型为 L"WAVE",名称标识符为
|
* 例如,一份音频资源的类型为 "WAVE",名称标识符为
|
||||||
* IDR_WAVE_1,那么可以这样指定该资源:
|
* IDR_WAVE_1,那么可以这样指定该资源:
|
||||||
* @code
|
* @code
|
||||||
* Resource(IDR_WAVE_1, L"WAVE");
|
* Resource(IDR_WAVE_1, "WAVE");
|
||||||
* @endcode
|
* @endcode
|
||||||
* 了解资源的更多信息:
|
* 了解资源的更多信息:
|
||||||
* https://docs.microsoft.com/en-us/windows/desktop/menurc/resources
|
* https://docs.microsoft.com/en-us/windows/desktop/menurc/resources
|
||||||
*/
|
*/
|
||||||
class KGE_API Resource
|
class KGE_API Resource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 资源的二进制数据
|
/// @brief 资源的二进制数据
|
||||||
struct Data
|
struct Data
|
||||||
{
|
{
|
||||||
void* buffer; ///< 资源数据
|
void* buffer; ///< 资源数据
|
||||||
uint32_t size; ///< 资源数据大小
|
uint32_t size; ///< 资源数据大小
|
||||||
|
|
||||||
Data();
|
Data();
|
||||||
|
|
||||||
|
|
@ -53,26 +53,26 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造资源
|
/// @brief 构造资源
|
||||||
Resource();
|
Resource();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造资源
|
/// @brief 构造资源
|
||||||
/// @param id 资源 ID
|
/// @param id 资源 ID
|
||||||
/// @param type 资源类型
|
/// @param type 资源类型
|
||||||
Resource(uint32_t id, const wchar_t* type);
|
Resource(uint32_t id, const wchar_t* type);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取资源的二进制数据
|
/// @brief 获取资源的二进制数据
|
||||||
/// @return 资源数据
|
/// @return 资源数据
|
||||||
Resource::Data GetData() const;
|
Resource::Data GetData() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取资源 ID
|
/// @brief 获取资源 ID
|
||||||
uint32_t GetId() const;
|
uint32_t GetId() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取资源类型
|
/// @brief 获取资源类型
|
||||||
const wchar_t* GetType() const;
|
const wchar_t* GetType() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ private:
|
||||||
{
|
{
|
||||||
ObjectCreator()
|
ObjectCreator()
|
||||||
{
|
{
|
||||||
(void)Singleton<_Ty>::Instance();
|
(void)Singleton<_Ty>::GetInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Dummy() const {}
|
inline void Dummy() const {}
|
||||||
|
|
@ -46,7 +46,7 @@ private:
|
||||||
public:
|
public:
|
||||||
using object_type = _Ty;
|
using object_type = _Ty;
|
||||||
|
|
||||||
static inline object_type& Instance()
|
static inline object_type& GetInstance()
|
||||||
{
|
{
|
||||||
static object_type instance;
|
static object_type instance;
|
||||||
creator_.Dummy();
|
creator_.Dummy();
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 默认的智能指针代理
|
* @brief 默认的智能指针代理
|
||||||
*/
|
*/
|
||||||
struct DefaultSmartPtrRefProxy
|
struct DefaultSmartPtrRefProxy
|
||||||
{
|
{
|
||||||
|
|
@ -45,7 +45,7 @@ struct DefaultSmartPtrRefProxy
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 智能指针
|
* @brief 智能指针
|
||||||
*/
|
*/
|
||||||
template <typename _Ty>
|
template <typename _Ty>
|
||||||
using SmartPtr = IntrusivePtr<_Ty, DefaultSmartPtrRefProxy>;
|
using SmartPtr = IntrusivePtr<_Ty, DefaultSmartPtrRefProxy>;
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
#include <kiwano/core/Exception.h>
|
||||||
#include <kiwano/core/Logger.h>
|
#include <kiwano/core/Logger.h>
|
||||||
#include <kiwano/core/Time.h>
|
#include <kiwano/core/Time.h>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
@ -94,12 +95,13 @@ const Duration Duration::Hour = 60 * Duration::Minute;
|
||||||
|
|
||||||
namespace
|
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;
|
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
|
} // namespace
|
||||||
|
|
||||||
Duration::Duration()
|
Duration::Duration()
|
||||||
|
|
@ -137,14 +139,14 @@ String Duration::ToString() const
|
||||||
{
|
{
|
||||||
if (IsZero())
|
if (IsZero())
|
||||||
{
|
{
|
||||||
return String(L"0s");
|
return String("0s");
|
||||||
}
|
}
|
||||||
|
|
||||||
String result;
|
String result;
|
||||||
long total_ms = milliseconds_;
|
long total_ms = milliseconds_;
|
||||||
if (total_ms < 0)
|
if (total_ms < 0)
|
||||||
{
|
{
|
||||||
result.append(L"-");
|
result.append("-");
|
||||||
total_ms = -total_ms;
|
total_ms = -total_ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,21 +157,21 @@ String Duration::ToString() const
|
||||||
|
|
||||||
if (hour)
|
if (hour)
|
||||||
{
|
{
|
||||||
result.append(String::parse(hour)).append(L"h");
|
result.append(String::parse(hour)).append("h");
|
||||||
result.append(String::parse(min)).append(L"m");
|
result.append(String::parse(min)).append("m");
|
||||||
}
|
}
|
||||||
else if (min)
|
else if (min)
|
||||||
{
|
{
|
||||||
result.append(String::parse(min)).append(L"m");
|
result.append(String::parse(min)).append("m");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ms != 0)
|
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)
|
else if (sec != 0)
|
||||||
{
|
{
|
||||||
result.append(String::parse(sec)).append(L"s");
|
result.append(String::parse(sec)).append("s");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
@ -356,57 +358,59 @@ Duration Duration::Parse(const String& format)
|
||||||
|
|
||||||
if (!std::regex_match(format.c_str(), duration_regex))
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ·ûºÅλ
|
// 符号位
|
||||||
if (format[0] == L'-' || format[0] == L'+')
|
if (format[0] == '-' || format[0] == '+')
|
||||||
{
|
{
|
||||||
negative = (format[0] == L'-');
|
negative = (format[0] == '-');
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (pos < len)
|
while (pos < len)
|
||||||
{
|
{
|
||||||
// ÊýÖµ
|
// 数值
|
||||||
size_t i = pos;
|
size_t i = pos;
|
||||||
for (; i < len; ++i)
|
for (; i < len; ++i)
|
||||||
{
|
{
|
||||||
wchar_t ch = format[i];
|
wchar_t ch = format[i];
|
||||||
if (!(ch == L'.' || L'0' <= ch && ch <= L'9'))
|
if (!(ch == '.' || '0' <= ch && ch <= '9'))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String num_str = format.substr(pos, i - pos);
|
String num_str = format.substr(pos, i - pos);
|
||||||
|
|
||||||
pos = i;
|
pos = i;
|
||||||
|
|
||||||
if (num_str.empty() || num_str == L".")
|
if (num_str.empty() || num_str == ".")
|
||||||
throw std::runtime_error("Duration::Parse failed, invalid duration");
|
throw Exception("Duration::Parse failed, invalid duration");
|
||||||
|
|
||||||
// µ¥Î»
|
// 单位
|
||||||
for (; i < len; ++i)
|
for (; i < len; ++i)
|
||||||
{
|
{
|
||||||
wchar_t ch = format[i];
|
wchar_t ch = format[i];
|
||||||
if (ch == L'.' || L'0' <= ch && ch <= L'9')
|
if (ch == '.' || '0' <= ch && ch <= '9')
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String unit_str = format.substr(pos, i - pos);
|
String unit_str = format.substr(pos, i - pos);
|
||||||
|
|
||||||
pos = i;
|
pos = i;
|
||||||
|
|
||||||
if (unit_map.find(unit_str) == unit_map.end())
|
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);
|
Duration unit = unit_map.at(unit_str);
|
||||||
ret += unit * num;
|
ret += unit * num;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,94 +26,94 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 时间段
|
* @brief 时间段
|
||||||
* @par
|
* @par
|
||||||
* 时间段表示法:
|
* 时间段表示法:
|
||||||
* @code
|
* @code
|
||||||
* time::Second * 5 // 5 秒
|
* time::Second * 5 // 5 秒
|
||||||
* time::Hour * 1.5 // 1.5 小时
|
* time::Hour * 1.5 // 1.5 小时
|
||||||
* time::Hour * 3 + time::Minute * 45 + time::Second * 15 // 3 小时 45 分 15
|
* time::Hour * 3 + time::Minute * 45 + time::Second * 15 // 3 小时 45 分 15
|
||||||
* 秒
|
* 秒
|
||||||
* @endcode
|
* @endcode
|
||||||
* 在 VS2015 及更高版本可以使用 time literals:
|
* 在 VS2015 及更高版本可以使用 time literals:
|
||||||
* @code
|
* @code
|
||||||
* using namespace kiwano;
|
* using namespace kiwano;
|
||||||
* 5_sec // 5 秒
|
* 5_sec // 5 秒
|
||||||
* 1.5_hour // 1.5 小时
|
* 1.5_hour // 1.5 小时
|
||||||
* 3_hour + 45_min + 15_sec // 3 小时 45 分 15 秒
|
* 3_hour + 45_min + 15_sec // 3 小时 45 分 15 秒
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
struct KGE_API Duration
|
struct KGE_API Duration
|
||||||
{
|
{
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造时间段
|
/// @brief 构造时间段
|
||||||
Duration();
|
Duration();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造时间段
|
/// @brief 构造时间段
|
||||||
/// @param milliseconds 毫秒数
|
/// @param milliseconds 毫秒数
|
||||||
Duration(long milliseconds);
|
Duration(long milliseconds);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取毫秒数
|
/// @brief 获取毫秒数
|
||||||
long Milliseconds() const;
|
long Milliseconds() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取秒数
|
/// @brief 获取秒数
|
||||||
float Seconds() const;
|
float Seconds() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取分钟数
|
/// @brief 获取分钟数
|
||||||
float Minutes() const;
|
float Minutes() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取小时数
|
/// @brief 获取小时数
|
||||||
float Hours() const;
|
float Hours() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 时长是否是零
|
/// @brief 时长是否是零
|
||||||
/// @return 若时长是零,返回true
|
/// @return 若时长是零,返回true
|
||||||
bool IsZero() const;
|
bool IsZero() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置毫秒数
|
/// @brief 设置毫秒数
|
||||||
/// @param ms 毫秒数
|
/// @param ms 毫秒数
|
||||||
void SetMilliseconds(long ms);
|
void SetMilliseconds(long ms);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置秒数
|
/// @brief 设置秒数
|
||||||
/// @param seconds 秒数
|
/// @param seconds 秒数
|
||||||
void SetSeconds(float seconds);
|
void SetSeconds(float seconds);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置分钟数
|
/// @brief 设置分钟数
|
||||||
/// @param minutes 分钟数
|
/// @param minutes 分钟数
|
||||||
void SetMinutes(float minutes);
|
void SetMinutes(float minutes);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置小时数
|
/// @brief 设置小时数
|
||||||
/// @param hours 小时数
|
/// @param hours 小时数
|
||||||
void SetHours(float hours);
|
void SetHours(float hours);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 转为字符串
|
/// @brief 转为字符串
|
||||||
String ToString() const;
|
String ToString() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 解析时间段字符串
|
/// @brief 解析时间段字符串
|
||||||
/// @param str 时间段字符串
|
/// @param str 时间段字符串
|
||||||
/// @details
|
/// @details
|
||||||
/// 时间段字符串允许是有符号的浮点数, 并且带有时间单位后缀
|
/// 时间段字符串允许是有符号的浮点数, 并且带有时间单位后缀
|
||||||
/// 例如: "300ms", "-1.5h", "2h45m"
|
/// 例如: "300ms", "-1.5h", "2h45m"
|
||||||
/// 允许的时间单位有 "ms", "s", "m", "h"
|
/// 允许的时间单位有 "ms", "s", "m", "h"
|
||||||
/// @return 解析出的时间段
|
/// @return 解析出的时间段
|
||||||
/// @throw std::runtime_error 传入了一个不合法的格式
|
/// @throw kiwano::Exception 传入一个不合法的格式时抛出
|
||||||
static Duration Parse(const String& str);
|
static Duration Parse(const String& str);
|
||||||
|
|
||||||
static const Duration Ms; ///< 毫秒
|
static const Duration Ms; ///< 毫秒
|
||||||
static const Duration Second; ///< 秒
|
static const Duration Second; ///< 秒
|
||||||
static const Duration Minute; ///< 分钟
|
static const Duration Minute; ///< 分钟
|
||||||
static const Duration Hour; ///< 小时
|
static const Duration Hour; ///< 小时
|
||||||
|
|
||||||
bool operator==(const Duration&) const;
|
bool operator==(const Duration&) const;
|
||||||
bool operator!=(const Duration&) const;
|
bool operator!=(const Duration&) const;
|
||||||
|
|
@ -159,28 +159,28 @@ private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 时间
|
* @brief 时间
|
||||||
* @par 示例:
|
* @par 示例:
|
||||||
* @code
|
* @code
|
||||||
* // 两时间相减, 可得到一个 Duration 对象
|
* // 两时间相减, 可得到一个 Duration 对象
|
||||||
* Time t1 = Time::Now();
|
* Time t1 = Time::Now();
|
||||||
* // 等待一段时间后
|
* // 等待一段时间后
|
||||||
* Time t2 = Time::Now();
|
* Time t2 = Time::Now();
|
||||||
* int ms = (t2 - t1).Milliseconds(); // 获取两时间相差的毫秒数
|
* int ms = (t2 - t1).Milliseconds(); // 获取两时间相差的毫秒数
|
||||||
* @endcode
|
* @endcode
|
||||||
* @note 时间点与系统时钟无关,因此不能将时间点转化为时分秒
|
* @note 时间点与系统时钟无关,因此不能将时间点转化为时分秒
|
||||||
*/
|
*/
|
||||||
struct KGE_API Time
|
struct KGE_API Time
|
||||||
{
|
{
|
||||||
Time();
|
Time();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 是否是零时
|
/// @brief 是否是零时
|
||||||
/// @return 若是零时,返回true
|
/// @return 若是零时,返回true
|
||||||
bool IsZero() const;
|
bool IsZero() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取当前时间
|
/// @brief 获取当前时间
|
||||||
static Time Now() noexcept;
|
static Time Now() noexcept;
|
||||||
|
|
||||||
const Duration operator-(const Time&) const;
|
const Duration operator-(const Time&) const;
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ class TimerManager;
|
||||||
KGE_DECLARE_SMART_PTR(Timer);
|
KGE_DECLARE_SMART_PTR(Timer);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 定时器
|
/// @brief 定时器
|
||||||
/// @details 定时器用于每隔一段时间执行一次回调函数,且可以指定执行总次数
|
/// @details 定时器用于每隔一段时间执行一次回调函数,且可以指定执行总次数
|
||||||
class KGE_API Timer
|
class KGE_API Timer
|
||||||
: public virtual ObjectBase
|
: public virtual ObjectBase
|
||||||
, protected IntrusiveListItem<TimerPtr>
|
, protected IntrusiveListItem<TimerPtr>
|
||||||
|
|
@ -40,85 +40,85 @@ class KGE_API Timer
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 定时器回调函数
|
/// @brief 定时器回调函数
|
||||||
/// @details
|
/// @details
|
||||||
/// 回调函数第一个参数是定时器自身,第二个参数是距离上次更新的时间间隔
|
/// 回调函数第一个参数是定时器自身,第二个参数是距离上次更新的时间间隔
|
||||||
using Callback = Function<void(Timer* /* self */, Duration /* dt */)>;
|
using Callback = Function<void(Timer* /* self */, Duration /* dt */)>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建定时器
|
/// @brief 创建定时器
|
||||||
/// @param cb 回调函数
|
/// @param cb 回调函数
|
||||||
/// @param interval 时间间隔
|
/// @param interval 时间间隔
|
||||||
/// @param times 执行次数(设 -1 为永久执行)
|
/// @param times 执行次数(设 -1 为永久执行)
|
||||||
static TimerPtr Create(Callback const& cb, Duration interval, int times = -1);
|
static TimerPtr Create(Callback const& cb, Duration interval, int times = -1);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建定时器
|
/// @brief 创建定时器
|
||||||
/// @param name 名称
|
/// @param name 名称
|
||||||
/// @param cb 回调函数
|
/// @param cb 回调函数
|
||||||
/// @param interval 时间间隔
|
/// @param interval 时间间隔
|
||||||
/// @param times 执行次数(设 -1 为永久执行)
|
/// @param times 执行次数(设 -1 为永久执行)
|
||||||
static TimerPtr Create(String const& name, Callback const& cb, Duration interval, int times = -1);
|
static TimerPtr Create(String const& name, Callback const& cb, Duration interval, int times = -1);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造空定时器
|
/// @brief 构造空定时器
|
||||||
Timer();
|
Timer();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 启动定时器
|
/// @brief 启动定时器
|
||||||
void Start();
|
void Start();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 停止定时器
|
/// @brief 停止定时器
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除定时器
|
/// @brief 移除定时器
|
||||||
void Remove();
|
void Remove();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 定时器是否在运行
|
/// @brief 定时器是否在运行
|
||||||
bool IsRunning() const;
|
bool IsRunning() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 定时器是否可移除
|
/// @brief 定时器是否可移除
|
||||||
bool IsRemoveable() const;
|
bool IsRemoveable() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取定时器执行过回调函数的次数
|
/// @brief 获取定时器执行过回调函数的次数
|
||||||
int GetRunTimes() const;
|
int GetRunTimes() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取定时器执行回调函数的总次数
|
/// @brief 获取定时器执行回调函数的总次数
|
||||||
int GetTotalRunTimes() const;
|
int GetTotalRunTimes() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置定时器执行回调函数的总次数
|
/// @brief 设置定时器执行回调函数的总次数
|
||||||
void SetTotalRunTimes(int times);
|
void SetTotalRunTimes(int times);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取定时器执行时间间隔
|
/// @brief 获取定时器执行时间间隔
|
||||||
Duration GetInterval() const;
|
Duration GetInterval() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置定时器执行时间间隔
|
/// @brief 设置定时器执行时间间隔
|
||||||
void SetInterval(Duration interval);
|
void SetInterval(Duration interval);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取定时器回调函数
|
/// @brief 获取定时器回调函数
|
||||||
Callback GetCallback() const;
|
Callback GetCallback() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置定时器回调函数
|
/// @brief 设置定时器回调函数
|
||||||
void SetCallback(const Callback& callback);
|
void SetCallback(const Callback& callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新定时器
|
/// @brief 更新定时器
|
||||||
void Update(Duration dt);
|
void Update(Duration dt);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 重置定时器
|
/// @brief 重置定时器
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -25,65 +25,65 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 定时器管理器
|
* @brief 定时器管理器
|
||||||
*/
|
*/
|
||||||
class KGE_API TimerManager
|
class KGE_API TimerManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 定时器列表
|
/// @brief 定时器列表
|
||||||
using Timers = IntrusiveList<TimerPtr>;
|
using Timers = IntrusiveList<TimerPtr>;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加定时器
|
/// @brief 添加定时器
|
||||||
/// @param cb 回调函数
|
/// @param cb 回调函数
|
||||||
/// @param interval 时间间隔
|
/// @param interval 时间间隔
|
||||||
/// @param times 执行次数(设 -1 为永久执行)
|
/// @param times 执行次数(设 -1 为永久执行)
|
||||||
Timer* AddTimer(Timer::Callback const& cb, Duration interval, int times = -1);
|
Timer* AddTimer(Timer::Callback const& cb, Duration interval, int times = -1);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加定时器
|
/// @brief 添加定时器
|
||||||
/// @param name 定时器名称
|
/// @param name 定时器名称
|
||||||
/// @param cb 回调函数
|
/// @param cb 回调函数
|
||||||
/// @param interval 时间间隔
|
/// @param interval 时间间隔
|
||||||
/// @param times 执行次数(设 -1 为永久执行)
|
/// @param times 执行次数(设 -1 为永久执行)
|
||||||
Timer* AddTimer(String const& name, Timer::Callback const& cb, Duration interval, int times = -1);
|
Timer* AddTimer(String const& name, Timer::Callback const& cb, Duration interval, int times = -1);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加定时器
|
/// @brief 添加定时器
|
||||||
Timer* AddTimer(TimerPtr timer);
|
Timer* AddTimer(TimerPtr timer);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 启动定时器
|
/// @brief 启动定时器
|
||||||
void StartTimers(String const& timer_name);
|
void StartTimers(String const& timer_name);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 停止定时器
|
/// @brief 停止定时器
|
||||||
void StopTimers(String const& timer_name);
|
void StopTimers(String const& timer_name);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除定时器
|
/// @brief 移除定时器
|
||||||
void RemoveTimers(String const& timer_name);
|
void RemoveTimers(String const& timer_name);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 启动所有定时器
|
/// @brief 启动所有定时器
|
||||||
void StartAllTimers();
|
void StartAllTimers();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 停止所有定时器
|
/// @brief 停止所有定时器
|
||||||
void StopAllTimers();
|
void StopAllTimers();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 移除所有定时器
|
/// @brief 移除所有定时器
|
||||||
void RemoveAllTimers();
|
void RemoveAllTimers();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取所有定时器
|
/// @brief 获取所有定时器
|
||||||
const Timers& GetAllTimers() const;
|
const Timers& GetAllTimers() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新定时器
|
/// @brief 更新定时器
|
||||||
void UpdateTimers(Duration dt);
|
void UpdateTimers(Duration dt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ KGE_DECLARE_SMART_PTR(Event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* \defgroup Events 事件
|
* \defgroup Events 事件
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,35 +38,35 @@ KGE_DECLARE_SMART_PTR(Event);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 事件
|
/// @brief 事件
|
||||||
class KGE_API Event : public RefCounter
|
class KGE_API Event : public RefCounter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构造事件
|
/// @brief 构造事件
|
||||||
Event(EventType const& type);
|
Event(EventType const& type);
|
||||||
|
|
||||||
virtual ~Event();
|
virtual ~Event();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取类型事件
|
/// @brief 获取类型事件
|
||||||
const EventType& GetType() const;
|
const EventType& GetType() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 判断事件类型
|
/// @brief 判断事件类型
|
||||||
/// @return 是否是指定事件类型
|
/// @return 是否是指定事件类型
|
||||||
template <typename _Ty, typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type>
|
template <typename _Ty, typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type>
|
||||||
bool IsType() const;
|
bool IsType() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 安全转换为其他类型事件
|
/// @brief 安全转换为其他类型事件
|
||||||
/// @throw std::bad_cast 类型无法转换时抛出
|
/// @throw std::bad_cast 类型无法转换时抛出
|
||||||
template <typename _Ty, typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type>
|
template <typename _Ty, typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type>
|
||||||
const _Ty* SafeCast() const;
|
const _Ty* SafeCast() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 安全转换为其他类型事件
|
/// @brief 安全转换为其他类型事件
|
||||||
/// @throw std::bad_cast 类型无法转换时抛出
|
/// @throw std::bad_cast 类型无法转换时抛出
|
||||||
template <typename _Ty, typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type>
|
template <typename _Ty, typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type>
|
||||||
_Ty* SafeCast();
|
_Ty* SafeCast();
|
||||||
|
|
||||||
|
|
@ -75,14 +75,14 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 事件特性:判断指定类型是否是事件
|
/// @brief 事件特性:判断指定类型是否是事件
|
||||||
template <typename _Ty>
|
template <typename _Ty>
|
||||||
struct IsEvent : public std::bool_constant<std::is_base_of<Event, _Ty>::value || std::is_same<Event, _Ty>::value>
|
struct IsEvent : public std::bool_constant<std::is_base_of<Event, _Ty>::value || std::is_same<Event, _Ty>::value>
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 事件特性:判断一个事件能否安全转换到另一事件类型
|
/// @brief 事件特性:判断一个事件能否安全转换到另一事件类型
|
||||||
template <typename _Ty, typename = typename std::enable_if<IsEvent<_Ty>::value, int>::type>
|
template <typename _Ty, typename = typename std::enable_if<IsEvent<_Ty>::value, int>::type>
|
||||||
struct IsEventType
|
struct IsEventType
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace kiwano
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 事件类型
|
/// @brief 事件类型
|
||||||
class EventType : public std::type_index
|
class EventType : public std::type_index
|
||||||
{
|
{
|
||||||
class Dummy
|
class Dummy
|
||||||
|
|
@ -40,7 +40,7 @@ class EventType : public std::type_index
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构建事件类型
|
/// @brief 构建事件类型
|
||||||
EventType();
|
EventType();
|
||||||
|
|
||||||
using std::type_index::type_index;
|
using std::type_index::type_index;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ KGE_DECLARE_SMART_PTR(KeyCharEvent);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 键盘事件
|
/// @brief 键盘事件
|
||||||
class KGE_API KeyEvent : public Event
|
class KGE_API KeyEvent : public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -43,31 +43,31 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 键盘按下事件
|
/// @brief 键盘按下事件
|
||||||
class KGE_API KeyDownEvent : public KeyEvent
|
class KGE_API KeyDownEvent : public KeyEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KeyCode code; ///< 键值
|
KeyCode code; ///< 键值
|
||||||
|
|
||||||
KeyDownEvent();
|
KeyDownEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 键盘抬起事件
|
/// @brief 键盘抬起事件
|
||||||
class KGE_API KeyUpEvent : public KeyEvent
|
class KGE_API KeyUpEvent : public KeyEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KeyCode code; ///< 键值
|
KeyCode code; ///< 键值
|
||||||
|
|
||||||
KeyUpEvent();
|
KeyUpEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 键盘字符事件
|
/// @brief 键盘字符事件
|
||||||
class KGE_API KeyCharEvent : public KeyEvent
|
class KGE_API KeyCharEvent : public KeyEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
char value; ///< 字符
|
char value; ///< 字符
|
||||||
|
|
||||||
KeyCharEvent();
|
KeyCharEvent();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -40,17 +40,17 @@ KGE_DECLARE_SMART_PTR(MouseWheelEvent);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 鼠标事件
|
/// @brief 鼠标事件
|
||||||
class KGE_API MouseEvent : public Event
|
class KGE_API MouseEvent : public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Point pos; ///< 鼠标位置
|
Point pos; ///< 鼠标位置
|
||||||
|
|
||||||
MouseEvent(EventType const& type);
|
MouseEvent(EventType const& type);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 鼠标移动事件
|
/// @brief 鼠标移动事件
|
||||||
class KGE_API MouseMoveEvent : public MouseEvent
|
class KGE_API MouseMoveEvent : public MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -58,37 +58,37 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 鼠标按键按下事件
|
/// @brief 鼠标按键按下事件
|
||||||
class KGE_API MouseDownEvent : public MouseEvent
|
class KGE_API MouseDownEvent : public MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MouseButton button; ///< 鼠标键值
|
MouseButton button; ///< 鼠标键值
|
||||||
|
|
||||||
MouseDownEvent();
|
MouseDownEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 鼠标按键抬起事件
|
/// @brief 鼠标按键抬起事件
|
||||||
class KGE_API MouseUpEvent : public MouseEvent
|
class KGE_API MouseUpEvent : public MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MouseButton button; ///< 鼠标键值
|
MouseButton button; ///< 鼠标键值
|
||||||
|
|
||||||
MouseUpEvent();
|
MouseUpEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 鼠标点击事件
|
/// @brief 鼠标点击事件
|
||||||
class KGE_API MouseClickEvent : public MouseEvent
|
class KGE_API MouseClickEvent : public MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MouseButton button; ///< 鼠标键值
|
MouseButton button; ///< 鼠标键值
|
||||||
|
|
||||||
MouseClickEvent();
|
MouseClickEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 鼠标移入事件
|
/// @brief 鼠标移入事件
|
||||||
class KGE_API MouseHoverEvent : public MouseEvent
|
class KGE_API MouseHoverEvent : public MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -96,7 +96,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 鼠标移出事件
|
/// @brief 鼠标移出事件
|
||||||
class KGE_API MouseOutEvent : public MouseEvent
|
class KGE_API MouseOutEvent : public MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -104,11 +104,11 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 鼠标滚轮事件
|
/// @brief 鼠标滚轮事件
|
||||||
class KGE_API MouseWheelEvent : public MouseEvent
|
class KGE_API MouseWheelEvent : public MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float wheel; ///< 滚轮值
|
float wheel; ///< 滚轮值
|
||||||
|
|
||||||
MouseWheelEvent();
|
MouseWheelEvent();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ KGE_DECLARE_SMART_PTR(WindowClosedEvent);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 窗口事件
|
/// @brief 窗口事件
|
||||||
class KGE_API WindowEvent : public Event
|
class KGE_API WindowEvent : public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -44,49 +44,49 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 窗口移动事件
|
/// @brief 窗口移动事件
|
||||||
class KGE_API WindowMovedEvent : public WindowEvent
|
class KGE_API WindowMovedEvent : public WindowEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int x; ///< 窗口左上角 x 坐标
|
int x; ///< 窗口左上角 x 坐标
|
||||||
int y; ///< 窗口左上角 y 坐标
|
int y; ///< 窗口左上角 y 坐标
|
||||||
|
|
||||||
WindowMovedEvent();
|
WindowMovedEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 窗口大小变化事件
|
/// @brief 窗口大小变化事件
|
||||||
class KGE_API WindowResizedEvent : public WindowEvent
|
class KGE_API WindowResizedEvent : public WindowEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t width; ///< 窗口宽度
|
uint32_t width; ///< 窗口宽度
|
||||||
uint32_t height; ///< 窗口高度
|
uint32_t height; ///< 窗口高度
|
||||||
|
|
||||||
WindowResizedEvent();
|
WindowResizedEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 窗口焦点变化事件
|
/// @brief 窗口焦点变化事件
|
||||||
class KGE_API WindowFocusChangedEvent : public WindowEvent
|
class KGE_API WindowFocusChangedEvent : public WindowEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool focus; ///< 是否获取到焦点
|
bool focus; ///< 是否获取到焦点
|
||||||
|
|
||||||
WindowFocusChangedEvent();
|
WindowFocusChangedEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 窗口标题更改事件
|
/// @brief 窗口标题更改事件
|
||||||
class KGE_API WindowTitleChangedEvent : public WindowEvent
|
class KGE_API WindowTitleChangedEvent : public WindowEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
String title; ///< 标题
|
String title; ///< 标题
|
||||||
|
|
||||||
WindowTitleChangedEvent();
|
WindowTitleChangedEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 窗口关闭事件
|
/// @brief 窗口关闭事件
|
||||||
class KGE_API WindowClosedEvent : public WindowEvent
|
class KGE_API WindowClosedEvent : public WindowEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@
|
||||||
#include <kiwano/render/ShapeSink.h>
|
#include <kiwano/render/ShapeSink.h>
|
||||||
#include <kiwano/render/Texture.h>
|
#include <kiwano/render/Texture.h>
|
||||||
#include <kiwano/render/GifImage.h>
|
#include <kiwano/render/GifImage.h>
|
||||||
#include <kiwano/render/LayerArea.h>
|
#include <kiwano/render/Layer.h>
|
||||||
#include <kiwano/render/TextLayout.h>
|
#include <kiwano/render/TextLayout.h>
|
||||||
#include <kiwano/render/TextureCache.h>
|
#include <kiwano/render/TextureCache.h>
|
||||||
#include <kiwano/render/Renderer.h>
|
#include <kiwano/render/Renderer.h>
|
||||||
|
|
@ -86,7 +86,7 @@
|
||||||
#include <kiwano/2d/Frame.h>
|
#include <kiwano/2d/Frame.h>
|
||||||
#include <kiwano/2d/FrameSequence.h>
|
#include <kiwano/2d/FrameSequence.h>
|
||||||
#include <kiwano/2d/GifSprite.h>
|
#include <kiwano/2d/GifSprite.h>
|
||||||
#include <kiwano/2d/Layer.h>
|
#include <kiwano/2d/LayerActor.h>
|
||||||
#include <kiwano/2d/ShapeActor.h>
|
#include <kiwano/2d/ShapeActor.h>
|
||||||
#include <kiwano/2d/Sprite.h>
|
#include <kiwano/2d/Sprite.h>
|
||||||
#include <kiwano/2d/Stage.h>
|
#include <kiwano/2d/Stage.h>
|
||||||
|
|
|
||||||
|
|
@ -21,28 +21,28 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
#error Kiwano only supports C++
|
# error Kiwano only supports C++
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define KGE_WIN32
|
# define KGE_WIN32
|
||||||
#ifdef _WIN64
|
# ifdef _WIN64
|
||||||
#define KGE_WIN64
|
# define KGE_WIN64
|
||||||
#endif
|
# endif
|
||||||
#elif __ANDROID__
|
#elif __ANDROID__
|
||||||
#define KGE_ANDROID
|
# define KGE_ANDROID
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
#define KGE_LINUX
|
# define KGE_LINUX
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
#if TARGET_OS_IPHONE
|
# if TARGET_OS_IPHONE
|
||||||
#define KGE_IPHONE
|
# define KGE_IPHONE
|
||||||
#elif TARGET_OS_MAC
|
# elif TARGET_OS_MAC
|
||||||
#define KGE_MACOS
|
# define KGE_MACOS
|
||||||
|
# else
|
||||||
|
# error "Unsupported Apple platform"
|
||||||
|
# endif
|
||||||
#else
|
#else
|
||||||
#error "Unsupported Apple platform"
|
# error "Unsupported compiler"
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#error "Unsupported compiler"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// C++ RunTime Header Files
|
// C++ RunTime Header Files
|
||||||
|
|
@ -56,48 +56,48 @@
|
||||||
#ifdef KGE_WIN32
|
#ifdef KGE_WIN32
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#error Kiwano only supports MSVC compiler
|
# error Kiwano only supports MSVC compiler
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef KGE_VS_VER
|
#ifndef KGE_VS_VER
|
||||||
#define KGE_VS_VER _MSC_VER
|
# define KGE_VS_VER _MSC_VER
|
||||||
#define KGE_VS_2013 1800
|
# define KGE_VS_2013 1800
|
||||||
#define KGE_VS_2015 1900
|
# define KGE_VS_2015 1900
|
||||||
#define KGE_VS_2017 1900
|
# define KGE_VS_2017 1900
|
||||||
#define KGE_VS_2019 1920
|
# define KGE_VS_2019 1920
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if KGE_VS_VER < KGE_VS_2015
|
#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
|
#endif
|
||||||
|
|
||||||
#ifndef WINVER
|
#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
|
#endif
|
||||||
|
|
||||||
#ifndef _WIN32_WINNT
|
#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
|
#endif
|
||||||
|
|
||||||
#ifndef NTDDI_VERSION
|
#ifndef NTDDI_VERSION
|
||||||
#define NTDDI_VERSION NTDDI_WIN7
|
# define NTDDI_VERSION NTDDI_WIN7
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef UNICODE
|
#ifndef UNICODE
|
||||||
#define UNICODE
|
# define UNICODE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Exclude rarely-used items from Windows headers
|
// Exclude rarely-used items from Windows headers
|
||||||
#ifndef WIN32_LEAN_AND_MEAN
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
#define WIN32_LEAN_AND_MEAN
|
# define WIN32_LEAN_AND_MEAN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NOMINMAX
|
#ifndef NOMINMAX
|
||||||
#define NOMINMAX
|
# define NOMINMAX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(DEBUG) || defined(_DEBUG)
|
#if defined(DEBUG) || defined(_DEBUG)
|
||||||
#define KGE_DEBUG
|
# define KGE_DEBUG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define KGE_SUPPRESS_WARNING_PUSH __pragma(warning(push))
|
#define KGE_SUPPRESS_WARNING_PUSH __pragma(warning(push))
|
||||||
|
|
@ -105,28 +105,28 @@
|
||||||
#define KGE_SUPPRESS_WARNING_POP __pragma(warning(pop))
|
#define KGE_SUPPRESS_WARNING_POP __pragma(warning(pop))
|
||||||
|
|
||||||
#ifndef KGE_ASSERT
|
#ifndef KGE_ASSERT
|
||||||
#ifdef KGE_DEBUG
|
# ifdef KGE_DEBUG
|
||||||
#define KGE_ASSERT(EXPR) \
|
# define KGE_ASSERT(EXPR) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
(void)((!!(EXPR)) || (_wassert(_CRT_WIDE(#EXPR), _CRT_WIDE(__FUNCTION__), (unsigned)(__LINE__)), 0)); \
|
(void)((!!(EXPR)) || (_wassert(_CRT_WIDE(#EXPR), _CRT_WIDE(__FUNCTION__), (unsigned)(__LINE__)), 0)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
# else
|
||||||
#define KGE_ASSERT __noop
|
# define KGE_ASSERT __noop
|
||||||
#endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef KGE_API
|
#ifndef KGE_API
|
||||||
#if defined(KGE_USE_DLL)
|
# if defined(KGE_USE_DLL)
|
||||||
#define KGE_API __declspec(dllimport)
|
# define KGE_API __declspec(dllimport)
|
||||||
#elif defined(KGE_EXPORT_DLL)
|
# elif defined(KGE_EXPORT_DLL)
|
||||||
#define KGE_API __declspec(dllexport)
|
# define KGE_API __declspec(dllexport)
|
||||||
#endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef KGE_API
|
#ifndef KGE_API
|
||||||
/* Building or calling Kiwano as a static library */
|
/* Building or calling Kiwano as a static library */
|
||||||
#define KGE_API
|
# define KGE_API
|
||||||
#else
|
#else
|
||||||
/*
|
/*
|
||||||
* C4251 can be ignored if you are deriving from a type in the
|
* C4251 can be ignored if you are deriving from a type in the
|
||||||
|
|
@ -136,8 +136,6 @@
|
||||||
KGE_SUPPRESS_WARNING(4251)
|
KGE_SUPPRESS_WARNING(4251)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define KGE_NOT_USED(VAR) ((void)VAR)
|
|
||||||
|
|
||||||
#define KGE_DEPRECATED(...) __declspec(deprecated(__VA_ARGS__))
|
#define KGE_DEPRECATED(...) __declspec(deprecated(__VA_ARGS__))
|
||||||
|
|
||||||
// Windows Header Files
|
// Windows Header Files
|
||||||
|
|
@ -145,3 +143,5 @@ KGE_SUPPRESS_WARNING(4251)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#endif // KGE_WIN32
|
#endif // KGE_WIN32
|
||||||
|
|
||||||
|
#define KGE_NOT_USED(VAR) ((void)VAR)
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,11 @@ namespace kiwano
|
||||||
namespace math
|
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);
|
// 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