From a633669058dc6c365a76e990d9755a69c45eceda Mon Sep 17 00:00:00 2001 From: Nomango Date: Fri, 7 Feb 2020 20:50:27 +0800 Subject: [PATCH 01/12] fix GifSprite render problem --- src/kiwano/2d/GifSprite.cpp | 28 ++++++++-------- src/kiwano/core/Common.h | 14 -------- src/kiwano/render/Brush.cpp | 20 ----------- src/kiwano/render/Brush.h | 22 +++++++++++-- src/kiwano/render/Font.h | 6 +++- src/kiwano/render/GifImage.cpp | 26 +++++++-------- src/kiwano/render/GifImage.h | 15 ++++++--- src/kiwano/render/LayerArea.h | 15 ++++++--- src/kiwano/render/RenderContext.cpp | 12 +++---- src/kiwano/render/RenderContext.h | 2 +- src/kiwano/render/Renderer.cpp | 45 ++++++++++++++++++------- src/kiwano/render/Renderer.h | 3 +- src/kiwano/render/Shape.h | 4 +++ src/kiwano/render/ShapeSink.h | 12 +++++-- src/kiwano/render/StrokeStyle.h | 7 +++- src/kiwano/render/TextLayout.h | 51 ++++++++++++++++------------- src/kiwano/render/Texture.cpp | 22 +++++++------ src/kiwano/render/Texture.h | 19 ++++++----- 18 files changed, 183 insertions(+), 140 deletions(-) diff --git a/src/kiwano/2d/GifSprite.cpp b/src/kiwano/2d/GifSprite.cpp index 86b2b158..b8296d2d 100644 --- a/src/kiwano/2d/GifSprite.cpp +++ b/src/kiwano/2d/GifSprite.cpp @@ -83,15 +83,16 @@ bool GifSprite::Load(GifImagePtr gif) { gif_ = gif; - next_index_ = 0; - loop_count_ = 0; - frame_.disposal_type = GifImage::DisposalType::None; + next_index_ = 0; + loop_count_ = 0; + frame_ = GifImage::Frame(); - SetSize(Size{ static_cast(gif_->GetWidthInPixels()), static_cast(gif_->GetHeightInPixels()) }); + SetSize(float(gif_->GetWidthInPixels()), float(gif_->GetHeightInPixels())); if (!frame_rt_) { - Renderer::Instance().CreateTextureRenderTarget(frame_rt_); + Size frame_size = GetSize(); + Renderer::Instance().CreateTextureRenderTarget(frame_rt_, &frame_size); } if (gif_->GetFramesCount() > 0) @@ -109,7 +110,7 @@ void GifSprite::OnRender(RenderContext& ctx) { PrepareToRender(ctx); - ctx.DrawTexture(*frame_to_render_, &frame_.rect, nullptr); + ctx.DrawTexture(*frame_to_render_, nullptr, &GetBounds()); } } @@ -137,10 +138,10 @@ void GifSprite::SetGifImage(GifImagePtr gif) void GifSprite::RestartAnimation() { - animating_ = true; - next_index_ = 0; - loop_count_ = 0; - frame_.disposal_type = GifImage::DisposalType::None; + animating_ = true; + next_index_ = 0; + loop_count_ = 0; + frame_ = GifImage::Frame(); } void GifSprite::ComposeNextFrame() @@ -181,7 +182,7 @@ void GifSprite::DisposeCurrentFrame() void GifSprite::OverlayNextFrame() { KGE_ASSERT(frame_rt_); - KGE_ASSERT(gif_ && gif_->IsValid()); + KGE_ASSERT(gif_); frame_ = gif_->GetFrame(next_index_); @@ -196,6 +197,7 @@ void GifSprite::OverlayNextFrame() if (next_index_ == 0) { + frame_rt_->Clear(); loop_count_++; } @@ -217,6 +219,7 @@ void GifSprite::OverlayNextFrame() } } + // Execute callback if (IsLastFrame() && loop_cb_) { loop_cb_(loop_count_ - 1); @@ -239,8 +242,7 @@ void GifSprite::SaveComposedFrame() if (!saved_frame_) { saved_frame_ = new Texture; - frame_rt_->CreateTexture(*saved_frame_, frame_to_be_saved->GetSizeInPixels(), - frame_to_be_saved->GetPixelFormat()); + frame_rt_->CreateTexture(*saved_frame_, frame_to_be_saved->GetSizeInPixels()); } saved_frame_->CopyFrom(frame_to_be_saved); diff --git a/src/kiwano/core/Common.h b/src/kiwano/core/Common.h index e2c74457..eada2318 100644 --- a/src/kiwano/core/Common.h +++ b/src/kiwano/core/Common.h @@ -92,20 +92,6 @@ using UnorderedMap = std::unordered_map<_Kty, _Ty, _Args...>; /// \~chinese /// @brief 函数封装器 -/// @par -/// 使用函数封装器可以储存、复制和调用任何可调用目标,示例代码如下: -/// @code -/// Function func1 = StaticFunc; // bool -/// StaticFunc(int x); -/// Function func2 = Closure(&t, &T::Func); // bool -/// T::Func(int x); -/// Function func3 = T::StaticFunc; // static bool -/// T::StaticFunc(int x); -/// Function func4 = [](int x) -> bool {}; // Lambda function -/// Function func5 = std::bind(&T::Func, &t); // std::bind -/// Function func5 = Callable(); // Callable -/// objects: struct Callable { bool operator()(int x) {} }; -/// @endcode template using Function = oc::function<_FuncTy>; diff --git a/src/kiwano/render/Brush.cpp b/src/kiwano/render/Brush.cpp index b27b7464..6ffe135c 100644 --- a/src/kiwano/render/Brush.cpp +++ b/src/kiwano/render/Brush.cpp @@ -112,16 +112,6 @@ void Brush::SetOpacity(float opacity) void Brush::SetColor(Color const& color) { - if (type_ == Type::SolidColor && raw_) - { - ComPtr solid_brush; - - if (SUCCEEDED(raw_->QueryInterface(&solid_brush))) - { - solid_brush->SetColor(DX::ConvertToColorF(color)); - return; - } - } Renderer::Instance().CreateBrush(*this, color); } @@ -135,14 +125,4 @@ void Brush::SetStyle(RadialGradientStyle const& style) Renderer::Instance().CreateBrush(*this, style); } -void Brush::SetBrush(ComPtr brush, Type type) -{ - type_ = type; - raw_ = brush; - if (raw_) - { - raw_->SetOpacity(opacity_); - } -} - } // namespace kiwano diff --git a/src/kiwano/render/Brush.h b/src/kiwano/render/Brush.h index d09cc4f2..01268952 100644 --- a/src/kiwano/render/Brush.h +++ b/src/kiwano/render/Brush.h @@ -150,14 +150,17 @@ private: /// @brief 设置透明度 void SetOpacity(float opacity); +private: + Type type_; + float opacity_; + +#if defined(KGE_WIN32) void SetBrush(ComPtr brush, Type type); ComPtr GetBrush() const; -private: - Type type_; - float opacity_; ComPtr raw_; +#endif }; /** @} */ @@ -167,8 +170,21 @@ inline Brush::Type Brush::GetType() const return type_; } +#if defined(KGE_WIN32) +inline void Brush::SetBrush(ComPtr brush, Type type) +{ + type_ = type; + raw_ = brush; + if (raw_) + { + raw_->SetOpacity(opacity_); + } +} + inline ComPtr Brush::GetBrush() const { return raw_; } +#endif + } // namespace kiwano diff --git a/src/kiwano/render/Font.h b/src/kiwano/render/Font.h index b5533d88..9ba98b91 100644 --- a/src/kiwano/render/Font.h +++ b/src/kiwano/render/Font.h @@ -62,17 +62,19 @@ public: /// @brief 加载字体资源 bool Load(Resource const& resource); +#if defined(KGE_WIN32) private: ComPtr GetCollection() const; void SetCollection(ComPtr collection); -private: ComPtr collection_; +#endif }; /** @} */ +#if defined(KGE_WIN32) inline ComPtr Font::GetCollection() const { return collection_; @@ -82,4 +84,6 @@ inline void Font::SetCollection(ComPtr collection) { collection_ = collection; } +#endif + } // namespace kiwano diff --git a/src/kiwano/render/GifImage.cpp b/src/kiwano/render/GifImage.cpp index 405d698d..825fa282 100644 --- a/src/kiwano/render/GifImage.cpp +++ b/src/kiwano/render/GifImage.cpp @@ -60,12 +60,10 @@ bool GifImage::Load(String const& file_path) if (IsValid()) { - if (FAILED(GetGlobalMetadata())) - { - SetDecoder(nullptr); - return false; - } - return true; + if (GetGlobalMetadata()) + return true; + + SetDecoder(nullptr); } return false; } @@ -76,12 +74,10 @@ bool GifImage::Load(Resource const& res) if (IsValid()) { - if (FAILED(GetGlobalMetadata())) - { - SetDecoder(nullptr); - return false; - } - return true; + if (GetGlobalMetadata()) + return true; + + SetDecoder(nullptr); } return false; } @@ -98,7 +94,8 @@ GifImage::Frame GifImage::GetFrame(uint32_t index) return frame; } -HRESULT GifImage::GetGlobalMetadata() +#if defined(KGE_WIN32) +bool GifImage::GetGlobalMetadata() { HRESULT hr = decoder_ ? S_OK : E_FAIL; @@ -194,7 +191,8 @@ HRESULT GifImage::GetGlobalMetadata() ::PropVariantClear(&prop_val); } } - return hr; + return SUCCEEDED(hr); } +#endif } // namespace kiwano diff --git a/src/kiwano/render/GifImage.h b/src/kiwano/render/GifImage.h index 743be983..c791eb1e 100644 --- a/src/kiwano/render/GifImage.h +++ b/src/kiwano/render/GifImage.h @@ -105,18 +105,20 @@ public: Frame GetFrame(uint32_t index); private: - ComPtr GetDecoder() const; - - void SetDecoder(ComPtr decoder); - - HRESULT GetGlobalMetadata(); + bool GetGlobalMetadata(); private: uint32_t frames_count_; uint32_t width_in_pixels_; uint32_t height_in_pixels_; +#if defined(KGE_WIN32) + ComPtr GetDecoder() const; + + void SetDecoder(ComPtr decoder); + ComPtr decoder_; +#endif }; /** @} */ @@ -141,6 +143,7 @@ inline uint32_t GifImage::GetFramesCount() const return frames_count_; } +#if defined(KGE_WIN32) inline ComPtr GifImage::GetDecoder() const { return decoder_; @@ -150,4 +153,6 @@ inline void GifImage::SetDecoder(ComPtr decoder) { decoder_ = decoder; } +#endif + } // namespace kiwano diff --git a/src/kiwano/render/LayerArea.h b/src/kiwano/render/LayerArea.h index cd199339..ad10ed0a 100644 --- a/src/kiwano/render/LayerArea.h +++ b/src/kiwano/render/LayerArea.h @@ -77,17 +77,19 @@ public: /// @brief 设置几何蒙层变换 void SetMaskTransform(Matrix3x2 const& matrix); -private: - ComPtr GetLayer() const; - - void SetLayer(ComPtr layer); - private: Rect area_; float opacity_; ShapePtr mask_; Matrix3x2 mask_transform_; + +#if defined(KGE_WIN32) + ComPtr GetLayer() const; + + void SetLayer(ComPtr layer); + ComPtr layer_; +#endif }; /** @} */ @@ -137,6 +139,7 @@ inline void LayerArea::SetMaskTransform(Matrix3x2 const& matrix) mask_transform_ = matrix; } +#if defined(KGE_WIN32) inline ComPtr LayerArea::GetLayer() const { return layer_; @@ -146,4 +149,6 @@ inline void LayerArea::SetLayer(ComPtr layer) { layer_ = layer; } +#endif + } // namespace kiwano diff --git a/src/kiwano/render/RenderContext.cpp b/src/kiwano/render/RenderContext.cpp index 26a24e2c..e8db988b 100644 --- a/src/kiwano/render/RenderContext.cpp +++ b/src/kiwano/render/RenderContext.cpp @@ -316,22 +316,20 @@ void RenderContext::DrawTextLayout(TextLayout const& layout, Point const& offset } } -void RenderContext::CreateTexture(Texture& texture, math::Vec2T size, D2D1_PIXEL_FORMAT format) +void RenderContext::CreateTexture(Texture& texture, math::Vec2T size) { KGE_ASSERT(render_target_ && "Render target has not been initialized!"); ComPtr saved_bitmap; - HRESULT hr = - render_target_->CreateBitmap(D2D1::SizeU(size.x, size.y), D2D1::BitmapProperties(format), &saved_bitmap); + + HRESULT hr = render_target_->CreateBitmap(D2D1::SizeU(size.x, size.y), D2D1::BitmapProperties(), &saved_bitmap); if (SUCCEEDED(hr)) { texture.SetBitmap(saved_bitmap); } - else - { - win32::ThrowIfFailed(hr); - } + + win32::ThrowIfFailed(hr); } void RenderContext::PushClipRect(Rect const& clip_rect) diff --git a/src/kiwano/render/RenderContext.h b/src/kiwano/render/RenderContext.h index 715e8a6f..ae908a68 100644 --- a/src/kiwano/render/RenderContext.h +++ b/src/kiwano/render/RenderContext.h @@ -122,7 +122,7 @@ public: /// \~chinese /// @brief 是否有效 - void CreateTexture(Texture& texture, math::Vec2T size, D2D1_PIXEL_FORMAT format); + void CreateTexture(Texture& texture, math::Vec2T size); /// \~chinese /// @brief 是否有效 diff --git a/src/kiwano/render/Renderer.cpp b/src/kiwano/render/Renderer.cpp index 2ba38d62..4d1652e8 100644 --- a/src/kiwano/render/Renderer.cpp +++ b/src/kiwano/render/Renderer.cpp @@ -361,7 +361,8 @@ void Renderer::CreateGifImageFrame(GifImage::Frame& frame, GifImage const& gif, if (SUCCEEDED(hr)) { ComPtr wic_frame; - HRESULT hr = gif.GetDecoder()->GetFrame(UINT(frame_index), &wic_frame); + + HRESULT hr = gif.GetDecoder()->GetFrame(UINT(frame_index), &wic_frame); if (SUCCEEDED(hr)) { @@ -459,7 +460,8 @@ void Renderer::CreateGifImageFrame(GifImage::Frame& frame, GifImage const& gif, if (SUCCEEDED(hr)) { uint32_t udelay = 0; - hr = UIntMult(prop_val.uiVal, 10, &udelay); + + hr = UIntMult(prop_val.uiVal, 10, &udelay); if (SUCCEEDED(hr)) { frame.delay.SetMilliseconds(static_cast(udelay)); @@ -749,7 +751,7 @@ void Renderer::CreateShapeSink(ShapeSink& sink) win32::ThrowIfFailed(hr); } -void Renderer::CreateTextureRenderTarget(TextureRenderContextPtr& render_context) +void Renderer::CreateTextureRenderTarget(TextureRenderContextPtr& render_context, const Size* desired_size) { HRESULT hr = S_OK; if (!d2d_res_) @@ -757,16 +759,25 @@ void Renderer::CreateTextureRenderTarget(TextureRenderContextPtr& render_context hr = E_UNEXPECTED; } - TextureRenderContextPtr output; + TextureRenderContextPtr output = new TextureRenderContext; + if (SUCCEEDED(hr)) { ComPtr bitmap_rt; - hr = d2d_res_->GetDeviceContext()->CreateCompatibleRenderTarget(&bitmap_rt); + + if (desired_size) + { + hr = d2d_res_->GetDeviceContext()->CreateCompatibleRenderTarget(DX::ConvertToSizeF(*desired_size), + &bitmap_rt); + } + else + { + hr = d2d_res_->GetDeviceContext()->CreateCompatibleRenderTarget(&bitmap_rt); + } if (SUCCEEDED(hr)) { - output = new TextureRenderContext; - hr = output->CreateDeviceResources(d2d_res_->GetFactory(), bitmap_rt); + hr = output->CreateDeviceResources(d2d_res_->GetFactory(), bitmap_rt); } if (SUCCEEDED(hr)) @@ -793,12 +804,24 @@ void Renderer::CreateBrush(Brush& brush, Color const& color) if (SUCCEEDED(hr)) { - ComPtr output; - hr = d2d_res_->GetDeviceContext()->CreateSolidColorBrush(DX::ConvertToColorF(color), &output); + ComPtr solid_brush; - if (SUCCEEDED(hr)) + if (brush.GetType() == Brush::Type::SolidColor && brush.GetBrush()) { - brush.SetBrush(output, Brush::Type::SolidColor); + hr = brush.GetBrush()->QueryInterface(&solid_brush); + if (SUCCEEDED(hr)) + { + solid_brush->SetColor(DX::ConvertToColorF(color)); + } + } + else + { + hr = d2d_res_->GetDeviceContext()->CreateSolidColorBrush(DX::ConvertToColorF(color), &solid_brush); + + if (SUCCEEDED(hr)) + { + brush.SetBrush(solid_brush, Brush::Type::SolidColor); + } } } diff --git a/src/kiwano/render/Renderer.h b/src/kiwano/render/Renderer.h index 971666df..d3d78a82 100644 --- a/src/kiwano/render/Renderer.h +++ b/src/kiwano/render/Renderer.h @@ -167,7 +167,8 @@ public: /// \~chinese /// @brief 创建纹理渲染上下文 /// @param[out] render_context 渲染上下文 - void CreateTextureRenderTarget(TextureRenderContextPtr& render_context); + /// @param[in] desired_size 期望的输出大小 + void CreateTextureRenderTarget(TextureRenderContextPtr& render_context, const Size* desired_size = nullptr); /// \~chinese /// @brief 创建纯色画刷 diff --git a/src/kiwano/render/Shape.h b/src/kiwano/render/Shape.h index 62dabab0..85930f9a 100644 --- a/src/kiwano/render/Shape.h +++ b/src/kiwano/render/Shape.h @@ -115,6 +115,7 @@ public: /// @brief 清除形状 void Clear(); +#if defined(KGE_WIN32) private: ComPtr GetGeometry() const; @@ -122,10 +123,12 @@ private: private: ComPtr geo_; +#endif }; /** @} */ +#if defined(KGE_WIN32) inline ComPtr Shape::GetGeometry() const { return geo_; @@ -135,5 +138,6 @@ inline void Shape::SetGeometry(ComPtr shape) { geo_ = shape; } +#endif } // namespace kiwano diff --git a/src/kiwano/render/ShapeSink.h b/src/kiwano/render/ShapeSink.h index 7f0c3d8a..1cccf39c 100644 --- a/src/kiwano/render/ShapeSink.h +++ b/src/kiwano/render/ShapeSink.h @@ -133,6 +133,10 @@ public: /// @brief 清空图形 void Clear(); +private: + ShapePtr shape_; + +#if defined(KGE_WIN32) private: ComPtr GetPathGeometry() const; @@ -142,14 +146,14 @@ private: void SetGeometrySink(ComPtr sink); -private: - ShapePtr shape_; - ComPtr path_geo_; ComPtr sink_; + ComPtr path_geo_; +#endif }; /** @} */ +#if defined(KGE_WIN32) inline ComPtr ShapeSink::GetPathGeometry() const { return path_geo_; @@ -169,4 +173,6 @@ inline void ShapeSink::SetGeometrySink(ComPtr sink) { sink_ = sink; } +#endif + } // namespace kiwano diff --git a/src/kiwano/render/StrokeStyle.h b/src/kiwano/render/StrokeStyle.h index faa3a41f..ec104f95 100644 --- a/src/kiwano/render/StrokeStyle.h +++ b/src/kiwano/render/StrokeStyle.h @@ -114,6 +114,7 @@ public: /// @brief 是否有效 bool IsValid() const; +#if defined(KGE_WIN32) private: ComPtr GetStrokeStyle() const; @@ -121,15 +122,17 @@ private: private: ComPtr style_; +#endif }; /** @} */ inline bool StrokeStyle::IsValid() const { - return true; // Always valid + return style_ != nullptr; } +#if defined(KGE_WIN32) inline ComPtr StrokeStyle::GetStrokeStyle() const { return style_; @@ -139,4 +142,6 @@ inline void StrokeStyle::SetStrokeStyle(ComPtr style) { style_ = style; } +#endif + } // namespace kiwano diff --git a/src/kiwano/render/TextLayout.h b/src/kiwano/render/TextLayout.h index 68c85a17..1f01f241 100644 --- a/src/kiwano/render/TextLayout.h +++ b/src/kiwano/render/TextLayout.h @@ -165,6 +165,7 @@ public: void SetDirtyFlag(uint8_t flag); +#if defined(KGE_WIN32) private: ComPtr GetTextFormat() const; @@ -174,11 +175,12 @@ private: void SetTextLayout(ComPtr layout); -private: - uint8_t dirty_flag_; - ComPtr text_format_; ComPtr text_layout_; +#endif + +private: + uint8_t dirty_flag_; String text_; TextStyle style_; @@ -216,16 +218,6 @@ inline void TextLayout::SetDirtyFlag(uint8_t flag) dirty_flag_ = flag; } -inline ComPtr TextLayout::GetTextFormat() const -{ - return text_format_; -} - -inline ComPtr TextLayout::GetTextLayout() const -{ - return text_layout_; -} - inline BrushPtr TextLayout::GetFillBrush() const { return style_.fill_brush; @@ -241,16 +233,6 @@ inline void TextLayout::SetFillBrush(BrushPtr brush) style_.fill_brush = brush; } -inline void TextLayout::SetTextFormat(ComPtr format) -{ - text_format_ = format; -} - -inline void TextLayout::SetTextLayout(ComPtr layout) -{ - text_layout_ = layout; -} - inline void TextLayout::SetOutlineBrush(BrushPtr brush) { style_.outline_brush = brush; @@ -265,4 +247,27 @@ inline void TextLayout::SetOutlineStroke(StrokeStylePtr outline_stroke) { style_.outline_stroke = outline_stroke; } + +#if defined(KGE_WIN32) +inline ComPtr TextLayout::GetTextFormat() const +{ + return text_format_; +} + +inline ComPtr TextLayout::GetTextLayout() const +{ + return text_layout_; +} + +inline void TextLayout::SetTextFormat(ComPtr format) +{ + text_format_ = format; +} + +inline void TextLayout::SetTextLayout(ComPtr layout) +{ + text_layout_ = layout; +} +#endif + } // namespace kiwano diff --git a/src/kiwano/render/Texture.cpp b/src/kiwano/render/Texture.cpp index 78e7eeec..3ddae370 100644 --- a/src/kiwano/render/Texture.cpp +++ b/src/kiwano/render/Texture.cpp @@ -170,6 +170,17 @@ void Texture::SetInterpolationMode(InterpolationMode mode) } } +void Texture::SetDefaultInterpolationMode(InterpolationMode mode) +{ + default_interpolation_mode_ = mode; +} + +InterpolationMode Texture::GetDefaultInterpolationMode() +{ + return default_interpolation_mode_; +} + +#if defined(KGE_WIN32) D2D1_PIXEL_FORMAT Texture::GetPixelFormat() const { if (bitmap_) @@ -188,15 +199,6 @@ void Texture::SetBitmap(ComPtr bitmap) { bitmap_ = bitmap; } - -void Texture::SetDefaultInterpolationMode(InterpolationMode mode) -{ - default_interpolation_mode_ = mode; -} - -InterpolationMode Texture::GetDefaultInterpolationMode() -{ - return default_interpolation_mode_; -} +#endif } // namespace kiwano diff --git a/src/kiwano/render/Texture.h b/src/kiwano/render/Texture.h index 18438148..715a32df 100644 --- a/src/kiwano/render/Texture.h +++ b/src/kiwano/render/Texture.h @@ -42,9 +42,8 @@ KGE_DECLARE_SMART_PTR(Texture); */ enum class InterpolationMode { - Linear, ///< 双线性插值,对周围四个像素进行两次线性插值计算, - ///在图像放大时可能会模糊 - Nearest, ///< 最邻近插值,取最邻近的像素点的颜色值 + Linear, ///< 双线性插值,对周围四个像素进行两次线性插值计算,在图像放大时可能会模糊 + Nearest ///< 最邻近插值,取最邻近的像素点的颜色值 }; /** @@ -110,10 +109,6 @@ public: /// @brief 获取像素插值方式 InterpolationMode GetBitmapInterpolationMode() const; - /// \~chinese - /// @brief 获取像素格式 - D2D1_PIXEL_FORMAT GetPixelFormat() const; - /// \~chinese /// @brief 拷贝纹理 /// @param copy_from 源纹理 @@ -138,6 +133,7 @@ public: /// @brief 获取默认的像素插值方式 static InterpolationMode GetDefaultInterpolationMode(); +#if defined(KGE_WIN32) private: /// \~chinese /// @brief 获取源位图 @@ -147,12 +143,19 @@ private: /// @brief 设置源位图 void SetBitmap(ComPtr bitmap); -private: + /// \~chinese + /// @brief 获取像素格式 + D2D1_PIXEL_FORMAT GetPixelFormat() const; + ComPtr bitmap_; +#endif + +private: InterpolationMode interpolation_mode_; static InterpolationMode default_interpolation_mode_; }; /** @} */ + } // namespace kiwano From d9389226055ddbff61489eef7687fc1760b5aefa Mon Sep 17 00:00:00 2001 From: Nomango Date: Sat, 8 Feb 2020 00:17:31 +0800 Subject: [PATCH 02/12] Update TextureRenderContext --- projects/kiwano/kiwano.vcxproj | 2 + projects/kiwano/kiwano.vcxproj.filters | 6 + src/kiwano/2d/Actor.cpp | 2 +- src/kiwano/2d/Canvas.cpp | 135 ++++----- src/kiwano/2d/Canvas.h | 36 ++- src/kiwano/2d/GifSprite.cpp | 8 +- src/kiwano/2d/GifSprite.h | 2 +- src/kiwano/2d/ShapeActor.cpp | 2 +- src/kiwano/render/RenderContext.cpp | 326 ++++++++++----------- src/kiwano/render/RenderContext.h | 202 +++++++------ src/kiwano/render/Renderer.cpp | 13 +- src/kiwano/render/Renderer.h | 5 +- src/kiwano/render/TextureRenderContext.cpp | 82 ++++++ src/kiwano/render/TextureRenderContext.h | 89 ++++++ 14 files changed, 532 insertions(+), 378 deletions(-) create mode 100644 src/kiwano/render/TextureRenderContext.cpp create mode 100644 src/kiwano/render/TextureRenderContext.h diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj index 86570ca7..f544ab77 100644 --- a/projects/kiwano/kiwano.vcxproj +++ b/projects/kiwano/kiwano.vcxproj @@ -84,6 +84,7 @@ + @@ -151,6 +152,7 @@ + diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters index 4500b9b2..007fb85b 100644 --- a/projects/kiwano/kiwano.vcxproj.filters +++ b/projects/kiwano/kiwano.vcxproj.filters @@ -285,6 +285,9 @@ math + + render + @@ -482,5 +485,8 @@ render + + render + \ No newline at end of file diff --git a/src/kiwano/2d/Actor.cpp b/src/kiwano/2d/Actor.cpp index 141d2fa6..faafeb80 100644 --- a/src/kiwano/2d/Actor.cpp +++ b/src/kiwano/2d/Actor.cpp @@ -154,7 +154,7 @@ void Actor::RenderBorder(RenderContext& ctx) ctx.FillRectangle(bounds); ctx.SetCurrentBrush(GetStage()->GetBorderStrokeBrush()); - ctx.DrawRectangle(bounds, 2.f); + ctx.DrawRectangle(bounds, nullptr, 2.f); } for (auto child = children_.first_item(); child; child = child->next_item()) diff --git a/src/kiwano/2d/Canvas.cpp b/src/kiwano/2d/Canvas.cpp index 1905fece..eb7715a6 100644 --- a/src/kiwano/2d/Canvas.cpp +++ b/src/kiwano/2d/Canvas.cpp @@ -25,9 +25,22 @@ namespace kiwano { -CanvasPtr Canvas::Create() +CanvasPtr Canvas::Create(Size const& size) { CanvasPtr ptr = new (std::nothrow) Canvas; + if (ptr) + { + try + { + ptr->ctx_ = TextureRenderContext::Create(); + ptr->stroke_brush_ = Brush::Create(Color::White); + ptr->fill_brush_ = Brush::Create(Color::White); + } + catch (std::exception) + { + return nullptr; + } + } return ptr; } @@ -38,17 +51,15 @@ Canvas::Canvas() { } -Canvas::~Canvas() {} - void Canvas::BeginDraw() { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->BeginDraw(); } void Canvas::EndDraw() { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->EndDraw(); cache_expired_ = true; } @@ -68,116 +79,111 @@ void Canvas::OnRender(RenderContext& ctx) void Canvas::SetBrush(BrushPtr brush) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetCurrentBrush(brush); } -float Canvas::GetStrokeWidth() const -{ - return stroke_width_; -} - void Canvas::SetBrushTransform(Transform const& transform) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetTransform(transform.ToMatrix()); } void Canvas::SetBrushTransform(Matrix3x2 const& transform) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetTransform(transform); } void Canvas::PushLayerArea(LayerArea& area) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->PushLayer(area); } void Canvas::PopLayerArea() { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->PopLayer(); } void Canvas::PushClipRect(Rect const& clip_rect) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->PushClipRect(clip_rect); } void Canvas::PopClipRect() { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->PopClipRect(); } void Canvas::DrawShape(ShapePtr shape) { - if (!shape) - return; - - InitRenderTargetAndBrushs(); - ctx_->SetCurrentBrush(stroke_brush_); - ctx_->DrawShape(*shape, stroke_width_, stroke_style_); - cache_expired_ = true; + KGE_ASSERT(ctx_); + if (shape) + { + ctx_->SetCurrentBrush(stroke_brush_); + ctx_->DrawShape(*shape, stroke_style_, stroke_width_); + cache_expired_ = true; + } } void Canvas::DrawLine(Point const& begin, Point const& end) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetCurrentBrush(stroke_brush_); - ctx_->DrawLine(begin, end, stroke_width_, stroke_style_); + ctx_->DrawLine(begin, end, stroke_style_, stroke_width_); cache_expired_ = true; } void Canvas::DrawCircle(Point const& center, float radius) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetCurrentBrush(stroke_brush_); - ctx_->DrawEllipse(center, Vec2(radius, radius), stroke_width_, stroke_style_); + ctx_->DrawEllipse(center, Vec2(radius, radius), stroke_style_, stroke_width_); cache_expired_ = true; } void Canvas::DrawEllipse(Point const& center, Vec2 const& radius) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetCurrentBrush(stroke_brush_); - ctx_->DrawEllipse(center, radius, stroke_width_, stroke_style_); + ctx_->DrawEllipse(center, radius, stroke_style_, stroke_width_); cache_expired_ = true; } void Canvas::DrawRect(Rect const& rect) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetCurrentBrush(stroke_brush_); - ctx_->DrawRectangle(rect, stroke_width_, stroke_style_); + ctx_->DrawRectangle(rect, stroke_style_, stroke_width_); cache_expired_ = true; } void Canvas::DrawRoundedRect(Rect const& rect, Vec2 const& radius) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetCurrentBrush(stroke_brush_); - ctx_->DrawRoundedRectangle(rect, radius, stroke_width_, stroke_style_); + ctx_->DrawRoundedRectangle(rect, radius, stroke_style_, stroke_width_); cache_expired_ = true; } void Canvas::FillShape(ShapePtr shape) { - if (!shape) - return; - - InitRenderTargetAndBrushs(); - ctx_->SetCurrentBrush(fill_brush_); - ctx_->FillShape(*shape); - cache_expired_ = true; + KGE_ASSERT(ctx_); + if (shape) + { + ctx_->SetCurrentBrush(fill_brush_); + ctx_->FillShape(*shape); + cache_expired_ = true; + } } void Canvas::FillCircle(Point const& center, float radius) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetCurrentBrush(fill_brush_); ctx_->FillEllipse(center, Vec2(radius, radius)); cache_expired_ = true; @@ -185,7 +191,7 @@ void Canvas::FillCircle(Point const& center, float radius) void Canvas::FillEllipse(Point const& center, Vec2 const& radius) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetCurrentBrush(fill_brush_); ctx_->FillEllipse(center, radius); cache_expired_ = true; @@ -193,7 +199,7 @@ void Canvas::FillEllipse(Point const& center, Vec2 const& radius) void Canvas::FillRect(Rect const& rect) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetCurrentBrush(fill_brush_); ctx_->FillRectangle(rect); cache_expired_ = true; @@ -201,7 +207,7 @@ void Canvas::FillRect(Rect const& rect) void Canvas::FillRoundedRect(Rect const& rect, Vec2 const& radius) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetCurrentBrush(fill_brush_); ctx_->FillRoundedRectangle(rect, radius); cache_expired_ = true; @@ -209,9 +215,9 @@ void Canvas::FillRoundedRect(Rect const& rect, Vec2 const& radius) void Canvas::DrawTexture(TexturePtr texture, const Rect* src_rect, const Rect* dest_rect) { + KGE_ASSERT(ctx_); if (texture) { - InitRenderTargetAndBrushs(); ctx_->DrawTexture(*texture, src_rect, dest_rect); cache_expired_ = true; } @@ -230,7 +236,7 @@ void Canvas::DrawTextLayout(String const& text, Point const& point) void Canvas::DrawTextLayout(TextLayout const& layout, Point const& point) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->DrawTextLayout(layout, point); } @@ -266,15 +272,15 @@ void Canvas::AddArc(Point const& point, Size const& radius, float rotation, bool void Canvas::StrokePath() { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetCurrentBrush(stroke_brush_); - ctx_->DrawShape(*shape_sink_.GetShape(), stroke_width_, stroke_style_); + ctx_->DrawShape(*shape_sink_.GetShape(), stroke_style_, stroke_width_); cache_expired_ = true; } void Canvas::FillPath() { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->SetCurrentBrush(fill_brush_); ctx_->FillShape(*shape_sink_.GetShape()); cache_expired_ = true; @@ -282,44 +288,29 @@ void Canvas::FillPath() void Canvas::Clear() { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->Clear(); cache_expired_ = true; } void Canvas::Clear(Color const& clear_color) { - InitRenderTargetAndBrushs(); + KGE_ASSERT(ctx_); ctx_->Clear(clear_color); cache_expired_ = true; } +void Canvas::ResizeAndClear(Size size) +{ + ctx_ = TextureRenderContext::Create(size); +} + TexturePtr Canvas::ExportToTexture() const { UpdateCache(); return texture_cached_; } -void Canvas::InitRenderTargetAndBrushs() -{ - if (!ctx_) - { - Renderer::Instance().CreateTextureRenderTarget(ctx_); - } - - if (!stroke_brush_) - { - stroke_brush_ = new Brush; - stroke_brush_->SetColor(Color::White); - } - - if (!fill_brush_) - { - fill_brush_ = new Brush; - fill_brush_->SetColor(Color::White); - } -} - void Canvas::UpdateCache() const { if (cache_expired_ && ctx_) diff --git a/src/kiwano/2d/Canvas.h b/src/kiwano/2d/Canvas.h index 900aa6d3..fcc34ade 100644 --- a/src/kiwano/2d/Canvas.h +++ b/src/kiwano/2d/Canvas.h @@ -21,7 +21,7 @@ #pragma once #include #include -#include +#include namespace kiwano { @@ -35,20 +35,16 @@ KGE_DECLARE_SMART_PTR(Canvas); /** * \~chinese - * @brief 画布,用于绘制图元 + * @brief 画布 + * @details 用于绘制图形、图像、文字等各种类型的图元,同时可以将绘制内容导出至图像 */ class KGE_API Canvas : public Actor { public: /// \~chinese /// @brief 创建画布 - static CanvasPtr Create(); - - /// \~chinese - /// @brief 构建空画布 - Canvas(); - - virtual ~Canvas(); + /// @param size 画布大小 + static CanvasPtr Create(Size const& size); /// \~chinese /// @brief 开始绘图 @@ -272,6 +268,10 @@ public: /// @brief 获取轮廓画刷 BrushPtr GetStrokeBrush() const; + /// \~chinese + /// @brief 清空画布大小并重设画布大小 + void ResizeAndClear(Size size); + /// \~chinese /// @brief 导出纹理 TexturePtr ExportToTexture() const; @@ -279,7 +279,7 @@ public: void OnRender(RenderContext& ctx) override; private: - void InitRenderTargetAndBrushs(); + Canvas(); void UpdateCache() const; @@ -298,6 +298,11 @@ private: /** @} */ +inline float Canvas::GetStrokeWidth() const +{ + return stroke_width_; +} + inline void Canvas::SetStrokeWidth(float width) { stroke_width_ = std::max(width, 0.f); @@ -315,13 +320,19 @@ inline void Canvas::SetTextStyle(TextStyle const& text_style) inline void Canvas::SetStrokeColor(Color const& color) { - InitRenderTargetAndBrushs(); + if (!stroke_brush_) + { + stroke_brush_ = new Brush; + } stroke_brush_->SetColor(color); } inline void Canvas::SetFillColor(Color const& color) { - InitRenderTargetAndBrushs(); + if (!fill_brush_) + { + fill_brush_ = new Brush; + } fill_brush_->SetColor(color); } @@ -344,4 +355,5 @@ inline BrushPtr Canvas::GetStrokeBrush() const { return stroke_brush_; } + } // namespace kiwano diff --git a/src/kiwano/2d/GifSprite.cpp b/src/kiwano/2d/GifSprite.cpp index b8296d2d..a3575f7a 100644 --- a/src/kiwano/2d/GifSprite.cpp +++ b/src/kiwano/2d/GifSprite.cpp @@ -87,14 +87,14 @@ bool GifSprite::Load(GifImagePtr gif) loop_count_ = 0; frame_ = GifImage::Frame(); - SetSize(float(gif_->GetWidthInPixels()), float(gif_->GetHeightInPixels())); - if (!frame_rt_) { - Size frame_size = GetSize(); - Renderer::Instance().CreateTextureRenderTarget(frame_rt_, &frame_size); + Size frame_size = Size(float(gif_->GetWidthInPixels()), float(gif_->GetHeightInPixels())); + frame_rt_ = TextureRenderContext::Create(frame_size); } + SetSize(frame_rt_->GetSize()); + if (gif_->GetFramesCount() > 0) { ComposeNextFrame(); diff --git a/src/kiwano/2d/GifSprite.h b/src/kiwano/2d/GifSprite.h index 7b6de011..145f7af4 100644 --- a/src/kiwano/2d/GifSprite.h +++ b/src/kiwano/2d/GifSprite.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/2d/ShapeActor.cpp b/src/kiwano/2d/ShapeActor.cpp index 34f0074d..ceebe316 100644 --- a/src/kiwano/2d/ShapeActor.cpp +++ b/src/kiwano/2d/ShapeActor.cpp @@ -91,7 +91,7 @@ void ShapeActor::OnRender(RenderContext& ctx) if (stroke_brush_) { ctx.SetCurrentBrush(stroke_brush_); - ctx.DrawShape(*shape_, stroke_width_ * 2 /* twice width for widening */, stroke_style_); + ctx.DrawShape(*shape_, stroke_style_, stroke_width_ * 2 /* twice width for widening */); } if (fill_brush_) diff --git a/src/kiwano/render/RenderContext.cpp b/src/kiwano/render/RenderContext.cpp index e8db988b..e2376083 100644 --- a/src/kiwano/render/RenderContext.cpp +++ b/src/kiwano/render/RenderContext.cpp @@ -23,9 +23,6 @@ namespace kiwano { -// -// RenderContext -// RenderContext::RenderContext() : collecting_status_(false) @@ -101,152 +98,6 @@ void RenderContext::EndDraw() } } -void RenderContext::DrawShape(Shape const& shape, float stroke_width, StrokeStylePtr stroke) -{ - KGE_ASSERT(render_target_ && "Render target has not been initialized!"); - KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); - - if (shape.IsValid()) - { - if (stroke) - { - render_target_->DrawGeometry(shape.GetGeometry().get(), current_brush_->GetBrush().get(), stroke_width, - stroke->GetStrokeStyle().get()); - } - else - { - render_target_->DrawGeometry(shape.GetGeometry().get(), current_brush_->GetBrush().get(), stroke_width, - nullptr); - } - - IncreasePrimitivesCount(); - } -} - -void RenderContext::FillShape(Shape const& shape) -{ - KGE_ASSERT(render_target_ && "Render target has not been initialized!"); - KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); - - if (shape.IsValid()) - { - render_target_->FillGeometry(shape.GetGeometry().get(), current_brush_->GetBrush().get()); - - IncreasePrimitivesCount(); - } -} - -void RenderContext::DrawLine(Point const& point1, Point const& point2, float stroke_width, StrokeStylePtr stroke) -{ - KGE_ASSERT(render_target_ && "Render target has not been initialized!"); - KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); - - if (stroke) - { - render_target_->DrawLine(DX::ConvertToPoint2F(point1), DX::ConvertToPoint2F(point2), - current_brush_->GetBrush().get(), stroke_width, stroke->GetStrokeStyle().get()); - } - else - { - render_target_->DrawLine(DX::ConvertToPoint2F(point1), DX::ConvertToPoint2F(point2), - current_brush_->GetBrush().get(), stroke_width, nullptr); - } - - IncreasePrimitivesCount(); -} - -void RenderContext::DrawRectangle(Rect const& rect, float stroke_width, StrokeStylePtr stroke) -{ - KGE_ASSERT(render_target_ && "Render target has not been initialized!"); - KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); - - if (stroke) - { - render_target_->DrawRectangle(DX::ConvertToRectF(rect), current_brush_->GetBrush().get(), stroke_width, - stroke->GetStrokeStyle().get()); - } - else - { - render_target_->DrawRectangle(DX::ConvertToRectF(rect), current_brush_->GetBrush().get(), stroke_width, - nullptr); - } - - IncreasePrimitivesCount(); -} - -void RenderContext::FillRectangle(Rect const& rect) -{ - KGE_ASSERT(render_target_ && "Render target has not been initialized!"); - KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); - - render_target_->FillRectangle(DX::ConvertToRectF(rect), current_brush_->GetBrush().get()); - - IncreasePrimitivesCount(); -} - -void RenderContext::DrawRoundedRectangle(Rect const& rect, Vec2 const& radius, float stroke_width, - StrokeStylePtr stroke) -{ - KGE_ASSERT(render_target_ && "Render target has not been initialized!"); - KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); - - if (stroke) - { - render_target_->DrawRoundedRectangle(D2D1::RoundedRect(DX::ConvertToRectF(rect), radius.x, radius.y), - current_brush_->GetBrush().get(), stroke_width, - stroke->GetStrokeStyle().get()); - - } - else - { - render_target_->DrawRoundedRectangle(D2D1::RoundedRect(DX::ConvertToRectF(rect), radius.x, radius.y), - current_brush_->GetBrush().get(), stroke_width, nullptr); - - } - IncreasePrimitivesCount(); -} - -void RenderContext::FillRoundedRectangle(Rect const& rect, Vec2 const& radius) -{ - KGE_ASSERT(render_target_ && "Render target has not been initialized!"); - KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); - - render_target_->FillRoundedRectangle(D2D1::RoundedRect(DX::ConvertToRectF(rect), radius.x, radius.y), - current_brush_->GetBrush().get()); - - IncreasePrimitivesCount(); -} - -void RenderContext::DrawEllipse(Point const& center, Vec2 const& radius, float stroke_width, StrokeStylePtr stroke) -{ - KGE_ASSERT(render_target_ && "Render target has not been initialized!"); - KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); - - if (stroke) - { - render_target_->DrawEllipse(D2D1::Ellipse(DX::ConvertToPoint2F(center), radius.x, radius.y), - current_brush_->GetBrush().get(), stroke_width, stroke->GetStrokeStyle().get()); - } - else - { - render_target_->DrawEllipse(D2D1::Ellipse(DX::ConvertToPoint2F(center), radius.x, radius.y), - current_brush_->GetBrush().get(), stroke_width, nullptr); - } - - IncreasePrimitivesCount(); -} - -void RenderContext::FillEllipse(Point const& center, Vec2 const& radius) -{ - KGE_ASSERT(render_target_ && "Render target has not been initialized!"); - KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); - - render_target_->FillEllipse(D2D1::Ellipse(DX::ConvertToPoint2F(center), radius.x, radius.y), - current_brush_->GetBrush().get()); - - IncreasePrimitivesCount(); -} - void RenderContext::DrawTexture(Texture const& texture, Rect const& src_rect, Rect const& dest_rect) { DrawTexture(texture, &src_rect, &dest_rect); @@ -316,6 +167,150 @@ void RenderContext::DrawTextLayout(TextLayout const& layout, Point const& offset } } +void RenderContext::DrawShape(Shape const& shape, StrokeStylePtr stroke, float stroke_width) +{ + KGE_ASSERT(render_target_ && "Render target has not been initialized!"); + KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); + + if (shape.IsValid()) + { + if (stroke) + { + render_target_->DrawGeometry(shape.GetGeometry().get(), current_brush_->GetBrush().get(), stroke_width, + stroke->GetStrokeStyle().get()); + } + else + { + render_target_->DrawGeometry(shape.GetGeometry().get(), current_brush_->GetBrush().get(), stroke_width, + nullptr); + } + + IncreasePrimitivesCount(); + } +} + +void RenderContext::DrawLine(Point const& point1, Point const& point2, StrokeStylePtr stroke, float stroke_width) +{ + KGE_ASSERT(render_target_ && "Render target has not been initialized!"); + KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); + + if (stroke) + { + render_target_->DrawLine(DX::ConvertToPoint2F(point1), DX::ConvertToPoint2F(point2), + current_brush_->GetBrush().get(), stroke_width, stroke->GetStrokeStyle().get()); + } + else + { + render_target_->DrawLine(DX::ConvertToPoint2F(point1), DX::ConvertToPoint2F(point2), + current_brush_->GetBrush().get(), stroke_width, nullptr); + } + + IncreasePrimitivesCount(); +} + +void RenderContext::DrawRectangle(Rect const& rect, StrokeStylePtr stroke, float stroke_width) +{ + KGE_ASSERT(render_target_ && "Render target has not been initialized!"); + KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); + + if (stroke) + { + render_target_->DrawRectangle(DX::ConvertToRectF(rect), current_brush_->GetBrush().get(), stroke_width, + stroke->GetStrokeStyle().get()); + } + else + { + render_target_->DrawRectangle(DX::ConvertToRectF(rect), current_brush_->GetBrush().get(), stroke_width, + nullptr); + } + + IncreasePrimitivesCount(); +} + +void RenderContext::DrawRoundedRectangle(Rect const& rect, Vec2 const& radius, StrokeStylePtr stroke, + float stroke_width) +{ + KGE_ASSERT(render_target_ && "Render target has not been initialized!"); + KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); + + if (stroke) + { + render_target_->DrawRoundedRectangle(D2D1::RoundedRect(DX::ConvertToRectF(rect), radius.x, radius.y), + current_brush_->GetBrush().get(), stroke_width, + stroke->GetStrokeStyle().get()); + } + else + { + render_target_->DrawRoundedRectangle(D2D1::RoundedRect(DX::ConvertToRectF(rect), radius.x, radius.y), + current_brush_->GetBrush().get(), stroke_width, nullptr); + } + IncreasePrimitivesCount(); +} + +void RenderContext::DrawEllipse(Point const& center, Vec2 const& radius, StrokeStylePtr stroke, float stroke_width) +{ + KGE_ASSERT(render_target_ && "Render target has not been initialized!"); + KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); + + if (stroke) + { + render_target_->DrawEllipse(D2D1::Ellipse(DX::ConvertToPoint2F(center), radius.x, radius.y), + current_brush_->GetBrush().get(), stroke_width, stroke->GetStrokeStyle().get()); + } + else + { + render_target_->DrawEllipse(D2D1::Ellipse(DX::ConvertToPoint2F(center), radius.x, radius.y), + current_brush_->GetBrush().get(), stroke_width, nullptr); + } + + IncreasePrimitivesCount(); +} + +void RenderContext::FillShape(Shape const& shape) +{ + KGE_ASSERT(render_target_ && "Render target has not been initialized!"); + KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); + + if (shape.IsValid()) + { + render_target_->FillGeometry(shape.GetGeometry().get(), current_brush_->GetBrush().get()); + + IncreasePrimitivesCount(); + } +} + +void RenderContext::FillRectangle(Rect const& rect) +{ + KGE_ASSERT(render_target_ && "Render target has not been initialized!"); + KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); + + render_target_->FillRectangle(DX::ConvertToRectF(rect), current_brush_->GetBrush().get()); + + IncreasePrimitivesCount(); +} + +void RenderContext::FillRoundedRectangle(Rect const& rect, Vec2 const& radius) +{ + KGE_ASSERT(render_target_ && "Render target has not been initialized!"); + KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); + + render_target_->FillRoundedRectangle(D2D1::RoundedRect(DX::ConvertToRectF(rect), radius.x, radius.y), + current_brush_->GetBrush().get()); + + IncreasePrimitivesCount(); +} + +void RenderContext::FillEllipse(Point const& center, Vec2 const& radius) +{ + KGE_ASSERT(render_target_ && "Render target has not been initialized!"); + KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); + + render_target_->FillEllipse(D2D1::Ellipse(DX::ConvertToPoint2F(center), radius.x, radius.y), + current_brush_->GetBrush().get()); + + IncreasePrimitivesCount(); +} + void RenderContext::CreateTexture(Texture& texture, math::Vec2T size) { KGE_ASSERT(render_target_ && "Render target has not been initialized!"); @@ -396,6 +391,15 @@ void RenderContext::Clear(Color const& clear_color) render_target_->Clear(DX::ConvertToColorF(clear_color)); } +Size RenderContext::GetSize() const +{ + if (render_target_) + { + return reinterpret_cast(render_target_->GetSize()); + } + return Size(); +} + void RenderContext::SetTransform(const Matrix3x2& matrix) { KGE_ASSERT(render_target_ && "Render target has not been initialized!"); @@ -508,28 +512,4 @@ void RenderContext::RestoreDrawingState() } } -// -// TextureRenderContext -// - -TextureRenderContext::TextureRenderContext() {} - -bool TextureRenderContext::GetOutput(Texture& texture) -{ - HRESULT hr = E_FAIL; - - if (bitmap_rt_) - { - ComPtr bitmap; - - hr = bitmap_rt_->GetBitmap(&bitmap); - - if (SUCCEEDED(hr)) - { - texture.SetBitmap(bitmap); - } - } - return SUCCEEDED(hr); -} - } // namespace kiwano diff --git a/src/kiwano/render/RenderContext.h b/src/kiwano/render/RenderContext.h index ae908a68..6f45f207 100644 --- a/src/kiwano/render/RenderContext.h +++ b/src/kiwano/render/RenderContext.h @@ -33,7 +33,6 @@ namespace kiwano class Renderer; KGE_DECLARE_SMART_PTR(RenderContext); -KGE_DECLARE_SMART_PTR(TextureRenderContext); /** * \addtogroup Render @@ -64,120 +63,162 @@ public: bool IsValid() const; /// \~chinese - /// @brief 是否有效 + /// @brief 开始渲染 void BeginDraw(); /// \~chinese - /// @brief 是否有效 + /// @brief 结束渲染 void EndDraw(); /// \~chinese - /// @brief 是否有效 - void DrawShape(Shape const& shape, float stroke_width, StrokeStylePtr stroke = nullptr); - - /// \~chinese - /// @brief 是否有效 - void FillShape(Shape const& shape); - - /// \~chinese - /// @brief 是否有效 - void DrawLine(Point const& point1, Point const& point2, float stroke_width, StrokeStylePtr stroke = nullptr); - - /// \~chinese - /// @brief 是否有效 - void DrawRectangle(Rect const& rect, float stroke_width, StrokeStylePtr stroke = nullptr); - - /// \~chinese - /// @brief 是否有效 - void FillRectangle(Rect const& rect); - - /// \~chinese - /// @brief 是否有效 - void DrawRoundedRectangle(Rect const& rect, Vec2 const& radius, float stroke_width, - StrokeStylePtr stroke = nullptr); - - /// \~chinese - /// @brief 是否有效 - void FillRoundedRectangle(Rect const& rect, Vec2 const& radius); - - /// \~chinese - /// @brief 是否有效 - void DrawEllipse(Point const& center, Vec2 const& radius, float stroke_width, StrokeStylePtr stroke = nullptr); - - /// \~chinese - /// @brief 是否有效 - void FillEllipse(Point const& center, Vec2 const& radius); - - /// \~chinese - /// @brief 是否有效 + /// @brief 绘制纹理 + /// @param texture 纹理 + /// @param src_rect 源纹理裁剪矩形 + /// @param dest_rect 绘制的目标区域 void DrawTexture(Texture const& texture, Rect const& src_rect, Rect const& dest_rect); /// \~chinese - /// @brief 是否有效 + /// @brief 绘制纹理 + /// @param texture 纹理 + /// @param src_rect 源纹理裁剪矩形 + /// @param dest_rect 绘制的目标区域 void DrawTexture(Texture const& texture, const Rect* src_rect = nullptr, const Rect* dest_rect = nullptr); /// \~chinese - /// @brief 是否有效 - void DrawTextLayout(TextLayout const& layout, Point const& offset = Point{}); + /// @brief 绘制文本布局 + /// @param layout 文本布局 + /// @param offset 偏移量 + void DrawTextLayout(TextLayout const& layout, Point const& offset = Point()); /// \~chinese - /// @brief 是否有效 + /// @brief 绘制形状轮廓 + /// @param shape 形状 + /// @param stroke 线条样式 + /// @param stroke_width 线条宽度 + void DrawShape(Shape const& shape, StrokeStylePtr stroke = nullptr, float stroke_width = 1.0f); + + /// \~chinese + /// @brief 绘制线段 + /// @param point1 线段起点 + /// @param point2 线段终点 + /// @param stroke 线条样式 + /// @param stroke_width 线条宽度 + void DrawLine(Point const& point1, Point const& point2, StrokeStylePtr stroke = nullptr, float stroke_width = 1.0f); + + /// \~chinese + /// @brief 绘制矩形边框 + /// @param rect 矩形 + /// @param stroke 线条样式 + /// @param stroke_width 线条宽度 + void DrawRectangle(Rect const& rect, StrokeStylePtr stroke = nullptr, float stroke_width = 1.0f); + + /// \~chinese + /// @brief 绘制圆角矩形边框 + /// @param rect 矩形 + /// @param radius 圆角半径 + /// @param stroke 线条样式 + /// @param stroke_width 线条宽度 + void DrawRoundedRectangle(Rect const& rect, Vec2 const& radius, StrokeStylePtr stroke = nullptr, + float stroke_width = 1.0f); + + /// \~chinese + /// @brief 绘制椭圆边框 + /// @param center 圆心 + /// @param radius 椭圆半径 + /// @param stroke 线条样式 + /// @param stroke_width 线条宽度 + void DrawEllipse(Point const& center, Vec2 const& radius, StrokeStylePtr stroke = nullptr, + float stroke_width = 1.0f); + + /// \~chinese + /// @brief 填充形状 + /// @param shape 形状 + void FillShape(Shape const& shape); + + /// \~chinese + /// @brief 填充矩形 + /// @param rect 矩形 + void FillRectangle(Rect const& rect); + + /// \~chinese + /// @brief 填充圆角矩形 + /// @param rect 矩形 + /// @param radius 圆角半径 + void FillRoundedRectangle(Rect const& rect, Vec2 const& radius); + + /// \~chinese + /// @brief 填充椭圆 + /// @param center 圆心 + /// @param radius 椭圆半径 + void FillEllipse(Point const& center, Vec2 const& radius); + + /// \~chinese + /// @brief 创建纹理 + /// @param texture 纹理 + /// @param size 纹理像素大小 void CreateTexture(Texture& texture, math::Vec2T size); /// \~chinese - /// @brief 是否有效 + /// @brief 设置绘制的裁剪区域 + /// @param clip_rect 裁剪矩形 void PushClipRect(Rect const& clip_rect); /// \~chinese - /// @brief 是否有效 + /// @brief 取消上一次设置的绘制裁剪区域 void PopClipRect(); /// \~chinese - /// @brief 是否有效 + /// @brief 设置图层区域 + /// @param layer 图层区域 void PushLayer(LayerArea& layer); /// \~chinese - /// @brief 是否有效 + /// @brief 取消上一次设置的图层区域 void PopLayer(); /// \~chinese - /// @brief 是否有效 + /// @brief 清空渲染内容 void Clear(); /// \~chinese - /// @brief 是否有效 + /// @brief 使用纯色清空渲染内容 + /// @param clear_color 清屏颜色 void Clear(Color const& clear_color); /// \~chinese - /// @brief 是否有效 + /// @brief 获取渲染区域大小 + Size GetSize() const; + + /// \~chinese + /// @brief 获取画刷透明度 float GetBrushOpacity() const; /// \~chinese - /// @brief 是否有效 + /// @brief 获取当前画刷 BrushPtr GetCurrentBrush() const; /// \~chinese - /// @brief 是否有效 + /// @brief 获取全局二维变换 Matrix3x2 GetGlobalTransform() const; /// \~chinese - /// @brief 是否有效 + /// @brief 设置画刷透明度 void SetBrushOpacity(float opacity); /// \~chinese - /// @brief 是否有效 + /// @brief 设置当前画刷 void SetCurrentBrush(BrushPtr brush); /// \~chinese - /// @brief 是否有效 + /// @brief 设置上下文的二维变换 void SetTransform(const Matrix3x2& matrix); /// \~chinese - /// @brief 是否有效 + /// @brief 设置全局二维变换 void SetGlobalTransform(const Matrix3x2& matrix); /// \~chinese - /// @brief 是否有效 + /// @brief 设置全局二维变换 void SetGlobalTransform(const Matrix3x2* matrix); /// \~chinese @@ -260,35 +301,6 @@ private: ComPtr drawing_state_; }; -/// \~chinese -/// @brief 纹理渲染上下文 -/// @details 纹理渲染上下文将渲染输出到一个纹理对象中 -class KGE_API TextureRenderContext : public RenderContext -{ - friend class Renderer; - -public: - /// \~chinese - /// @brief 是否有效 - bool IsValid() const; - - /// \~chinese - /// @brief 获取渲染输出 - /// @param[out] texture 纹理输出 - /// @return 操作是否成功 - bool GetOutput(Texture& texture); - -private: - TextureRenderContext(); - - ComPtr GetBitmapRenderTarget() const; - - void SetBitmapRenderTarget(ComPtr ctx); - -private: - ComPtr bitmap_rt_; -}; - /** @} */ inline RenderContext::Status::Status() @@ -347,18 +359,4 @@ inline void RenderContext::SetCurrentBrush(BrushPtr brush) } } -inline bool TextureRenderContext::IsValid() const -{ - return bitmap_rt_ != nullptr; -} - -inline ComPtr TextureRenderContext::GetBitmapRenderTarget() const -{ - return bitmap_rt_; -} - -inline void TextureRenderContext::SetBitmapRenderTarget(ComPtr ctx) -{ - bitmap_rt_ = ctx; -} } // namespace kiwano diff --git a/src/kiwano/render/Renderer.cpp b/src/kiwano/render/Renderer.cpp index 4d1652e8..9f01f0c0 100644 --- a/src/kiwano/render/Renderer.cpp +++ b/src/kiwano/render/Renderer.cpp @@ -751,7 +751,7 @@ void Renderer::CreateShapeSink(ShapeSink& sink) win32::ThrowIfFailed(hr); } -void Renderer::CreateTextureRenderTarget(TextureRenderContextPtr& render_context, const Size* desired_size) +void Renderer::CreateTextureRenderContext(TextureRenderContext& render_context, const Size* desired_size) { HRESULT hr = S_OK; if (!d2d_res_) @@ -759,8 +759,6 @@ void Renderer::CreateTextureRenderTarget(TextureRenderContextPtr& render_context hr = E_UNEXPECTED; } - TextureRenderContextPtr output = new TextureRenderContext; - if (SUCCEEDED(hr)) { ComPtr bitmap_rt; @@ -777,20 +775,15 @@ void Renderer::CreateTextureRenderTarget(TextureRenderContextPtr& render_context if (SUCCEEDED(hr)) { - hr = output->CreateDeviceResources(d2d_res_->GetFactory(), bitmap_rt); + hr = render_context.CreateDeviceResources(d2d_res_->GetFactory(), bitmap_rt); } if (SUCCEEDED(hr)) { - output->SetBitmapRenderTarget(bitmap_rt); + render_context.SetBitmapRenderTarget(bitmap_rt); } } - if (SUCCEEDED(hr)) - { - render_context = output; - } - win32::ThrowIfFailed(hr); } diff --git a/src/kiwano/render/Renderer.h b/src/kiwano/render/Renderer.h index d3d78a82..f5e9e756 100644 --- a/src/kiwano/render/Renderer.h +++ b/src/kiwano/render/Renderer.h @@ -23,8 +23,9 @@ #include #include #include -#include #include +#include +#include #include #if defined(KGE_USE_DIRECTX10) @@ -168,7 +169,7 @@ public: /// @brief 创建纹理渲染上下文 /// @param[out] render_context 渲染上下文 /// @param[in] desired_size 期望的输出大小 - void CreateTextureRenderTarget(TextureRenderContextPtr& render_context, const Size* desired_size = nullptr); + void CreateTextureRenderContext(TextureRenderContext& render_context, const Size* desired_size = nullptr); /// \~chinese /// @brief 创建纯色画刷 diff --git a/src/kiwano/render/TextureRenderContext.cpp b/src/kiwano/render/TextureRenderContext.cpp new file mode 100644 index 00000000..e0c4e71c --- /dev/null +++ b/src/kiwano/render/TextureRenderContext.cpp @@ -0,0 +1,82 @@ +// Copyright (c) 2016-2019 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 +#include +#include + +namespace kiwano +{ + +TextureRenderContextPtr TextureRenderContext::Create() +{ + TextureRenderContextPtr ptr = new TextureRenderContext; + if (ptr) + { + try + { + Renderer::Instance().CreateTextureRenderContext(*ptr); + } + catch (std::exception) + { + return nullptr; + } + } + return ptr; +} + +TextureRenderContextPtr TextureRenderContext::Create(Size const& desired_size) +{ + TextureRenderContextPtr ptr = new TextureRenderContext; + if (ptr) + { + try + { + Renderer::Instance().CreateTextureRenderContext(*ptr, &desired_size); + } + catch (std::exception) + { + return nullptr; + } + } + return ptr; +} + +TextureRenderContext::TextureRenderContext() {} + +bool TextureRenderContext::GetOutput(Texture& texture) +{ + HRESULT hr = E_FAIL; + + if (bitmap_rt_) + { + ComPtr bitmap; + + hr = bitmap_rt_->GetBitmap(&bitmap); + + if (SUCCEEDED(hr)) + { + texture.SetBitmap(bitmap); + } + } + return SUCCEEDED(hr); +} + +} // namespace kiwano diff --git a/src/kiwano/render/TextureRenderContext.h b/src/kiwano/render/TextureRenderContext.h new file mode 100644 index 00000000..ed412152 --- /dev/null +++ b/src/kiwano/render/TextureRenderContext.h @@ -0,0 +1,89 @@ +// Copyright (c) 2016-2019 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 + +namespace kiwano +{ +class Renderer; + +KGE_DECLARE_SMART_PTR(TextureRenderContext); + +/** + * \addtogroup Render + * @{ + */ + +/// \~chinese +/// @brief 纹理渲染上下文 +/// @details 纹理渲染上下文将渲染输出到一个纹理对象中 +class KGE_API TextureRenderContext : public RenderContext +{ + friend class Renderer; + +public: + /// \~chinese + /// @brief 创建纹理渲染上下文 + static TextureRenderContextPtr Create(); + + /// \~chinese + /// @brief 创建纹理渲染上下文 + /// @param size 期望的输出大小 + static TextureRenderContextPtr Create(Size const& desired_size); + + /// \~chinese + /// @brief 是否有效 + bool IsValid() const; + + /// \~chinese + /// @brief 获取渲染输出 + /// @param[out] texture 纹理输出 + /// @return 操作是否成功 + bool GetOutput(Texture& texture); + +private: + TextureRenderContext(); + + ComPtr GetBitmapRenderTarget() const; + + void SetBitmapRenderTarget(ComPtr ctx); + +private: + ComPtr bitmap_rt_; +}; + +/** @} */ + +inline bool TextureRenderContext::IsValid() const +{ + return bitmap_rt_ != nullptr; +} + +inline ComPtr TextureRenderContext::GetBitmapRenderTarget() const +{ + return bitmap_rt_; +} + +inline void TextureRenderContext::SetBitmapRenderTarget(ComPtr ctx) +{ + bitmap_rt_ = ctx; +} +} // namespace kiwano From 9329b6f888161f79733a31ad8fff43033ed5b4ef Mon Sep 17 00:00:00 2001 From: Nomango Date: Sat, 8 Feb 2020 09:59:17 +0800 Subject: [PATCH 03/12] Update Singleton --- src/kiwano-audio/Sound.cpp | 8 ++++---- src/kiwano-imgui/ImGuiModule.cpp | 18 +++++++++--------- src/kiwano/2d/Button.cpp | 4 ++-- src/kiwano/2d/DebugActor.cpp | 2 +- src/kiwano/2d/Frame.cpp | 4 ++-- src/kiwano/2d/GifSprite.cpp | 4 ++-- src/kiwano/2d/Stage.cpp | 2 +- src/kiwano/2d/Transition.cpp | 2 +- src/kiwano/core/Logger.h | 10 +++++----- src/kiwano/core/Singleton.h | 4 ++-- src/kiwano/platform/Application.cpp | 22 +++++++++++----------- src/kiwano/platform/Window.h | 2 +- src/kiwano/platform/win32/WindowImpl.cpp | 2 +- src/kiwano/render/Brush.cpp | 6 +++--- src/kiwano/render/Font.cpp | 4 ++-- src/kiwano/render/GifImage.cpp | 6 +++--- src/kiwano/render/Renderer.cpp | 16 ++++++++-------- src/kiwano/render/Shape.cpp | 10 +++++----- src/kiwano/render/ShapeSink.cpp | 2 +- src/kiwano/render/StrokeStyle.cpp | 2 +- src/kiwano/render/TextLayout.cpp | 4 ++-- src/kiwano/render/Texture.cpp | 4 ++-- src/kiwano/render/TextureRenderContext.cpp | 4 ++-- src/kiwano/utils/ResourceCache.cpp | 8 ++++---- 24 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/kiwano-audio/Sound.cpp b/src/kiwano-audio/Sound.cpp index c8f20b5d..db2a2236 100644 --- a/src/kiwano-audio/Sound.cpp +++ b/src/kiwano-audio/Sound.cpp @@ -63,7 +63,7 @@ Sound::~Sound() bool Sound::Load(String const& file_path) { - if (!FileSystem::Instance().IsFileExists(file_path)) + if (!FileSystem::GetInstance().IsFileExists(file_path)) { KGE_WARN(L"Media file '%s' not found", file_path.c_str()); return false; @@ -74,7 +74,7 @@ bool Sound::Load(String const& file_path) Close(); } - String full_path = FileSystem::Instance().GetFullPathForFile(file_path); + String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path); HRESULT hr = transcoder_.LoadMediaFile(full_path); if (FAILED(hr)) @@ -83,7 +83,7 @@ bool Sound::Load(String const& file_path) return false; } - if (!AudioEngine::Instance().CreateSound(*this, transcoder_.GetBuffer())) + if (!AudioEngine::GetInstance().CreateSound(*this, transcoder_.GetBuffer())) { Close(); return false; @@ -107,7 +107,7 @@ bool Sound::Load(Resource const& res) return false; } - if (!AudioEngine::Instance().CreateSound(*this, transcoder_.GetBuffer())) + if (!AudioEngine::GetInstance().CreateSound(*this, transcoder_.GetBuffer())) { Close(); return false; diff --git a/src/kiwano-imgui/ImGuiModule.cpp b/src/kiwano-imgui/ImGuiModule.cpp index 61d20f63..360e0320 100644 --- a/src/kiwano-imgui/ImGuiModule.cpp +++ b/src/kiwano-imgui/ImGuiModule.cpp @@ -31,7 +31,7 @@ void ImGuiModule::SetupComponent() ImGui::StyleColorsDark(); // Setup Platform/Renderer bindings - target_window_ = Renderer::Instance().GetTargetWindow(); + target_window_ = Renderer::GetInstance().GetTargetWindow(); io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) io.BackendFlags |= @@ -58,7 +58,7 @@ void ImGuiModule::SetupComponent() io.KeyMap[ImGuiKey_Y] = (int)KeyCode::Y; io.KeyMap[ImGuiKey_Z] = (int)KeyCode::Z; - ImGui_Impl_Init(Renderer::Instance()); + ImGui_Impl_Init(Renderer::GetInstance()); } void ImGuiModule::DestroyComponent() @@ -75,10 +75,10 @@ void ImGuiModule::OnUpdate(Duration dt) io.DeltaTime = dt.Seconds(); // Read keyboard modifiers inputs - io.KeyCtrl = Input::Instance().IsDown(KeyCode::Ctrl); - io.KeyShift = Input::Instance().IsDown(KeyCode::Shift); - io.KeyAlt = Input::Instance().IsDown(KeyCode::Alt); - io.KeySuper = Input::Instance().IsDown(KeyCode::Super); + io.KeyCtrl = Input::GetInstance().IsDown(KeyCode::Ctrl); + io.KeyShift = Input::GetInstance().IsDown(KeyCode::Shift); + io.KeyAlt = Input::GetInstance().IsDown(KeyCode::Alt); + io.KeySuper = Input::GetInstance().IsDown(KeyCode::Super); // io.KeysDown[], io.MousePos, io.MouseDown[], io.MouseWheel: filled by the HandleEvent function below. // Update OS mouse position @@ -96,7 +96,7 @@ void ImGuiModule::BeforeRender() KGE_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built!"); // Setup display size (every frame to accommodate for window resizing) - Size display_size = Renderer::Instance().GetOutputSize(); + Size display_size = Renderer::GetInstance().GetOutputSize(); io.DisplaySize = ImVec2(display_size.x, display_size.y); ImGui::NewFrame(); @@ -181,7 +181,7 @@ void ImGuiModule::UpdateMousePos() ::SetCursorPos(pos.x, pos.y); } - Point pos = Input::Instance().GetMousePos(); + Point pos = Input::GetInstance().GetMousePos(); io.MousePos = ImVec2(pos.x, pos.y); } @@ -219,7 +219,7 @@ void ImGuiModule::UpdateMouseCursor() break; } - Window::Instance().SetCursor(cursor); + Window::GetInstance().SetCursor(cursor); } } // namespace imgui diff --git a/src/kiwano/2d/Button.cpp b/src/kiwano/2d/Button.cpp index 1fb5b324..6f1dccf1 100644 --- a/src/kiwano/2d/Button.cpp +++ b/src/kiwano/2d/Button.cpp @@ -78,14 +78,14 @@ void Button::SetStatus(Status status) if (status == Status::Normal) { - Window::Instance().SetCursor(CursorType::Arrow); + Window::GetInstance().SetCursor(CursorType::Arrow); if (mouse_out_callback_) mouse_out_callback_(this); } else if (status == Status::Hover) { - Window::Instance().SetCursor(CursorType::Hand); + Window::GetInstance().SetCursor(CursorType::Hand); if (old_status == Status::Pressed) { diff --git a/src/kiwano/2d/DebugActor.cpp b/src/kiwano/2d/DebugActor.cpp index 4c27c6fb..495df54d 100644 --- a/src/kiwano/2d/DebugActor.cpp +++ b/src/kiwano/2d/DebugActor.cpp @@ -104,7 +104,7 @@ void DebugActor::OnUpdate(Duration dt) } #endif - const auto& status = Renderer::Instance().GetContext().GetStatus(); + const auto& status = Renderer::GetInstance().GetContext().GetStatus(); ss << "Render: " << status.duration.Milliseconds() << "ms" << std::endl; diff --git a/src/kiwano/2d/Frame.cpp b/src/kiwano/2d/Frame.cpp index 69b98ef3..ebd4e169 100644 --- a/src/kiwano/2d/Frame.cpp +++ b/src/kiwano/2d/Frame.cpp @@ -60,7 +60,7 @@ Frame::Frame() {} bool Frame::Load(String const& file_path) { - TexturePtr texture = TextureCache::Instance().AddOrGetTexture(file_path); + TexturePtr texture = TextureCache::GetInstance().AddOrGetTexture(file_path); if (texture->IsValid()) { SetTexture(texture); @@ -71,7 +71,7 @@ bool Frame::Load(String const& file_path) bool Frame::Load(Resource const& res) { - TexturePtr texture = TextureCache::Instance().AddOrGetTexture(res); + TexturePtr texture = TextureCache::GetInstance().AddOrGetTexture(res); if (texture->IsValid()) { SetTexture(texture); diff --git a/src/kiwano/2d/GifSprite.cpp b/src/kiwano/2d/GifSprite.cpp index a3575f7a..50051dd1 100644 --- a/src/kiwano/2d/GifSprite.cpp +++ b/src/kiwano/2d/GifSprite.cpp @@ -67,13 +67,13 @@ GifSprite::GifSprite() bool GifSprite::Load(String const& file_path) { - GifImagePtr image = TextureCache::Instance().AddOrGetGifImage(file_path); + GifImagePtr image = TextureCache::GetInstance().AddOrGetGifImage(file_path); return Load(image); } bool GifSprite::Load(Resource const& res) { - GifImagePtr image = TextureCache::Instance().AddOrGetGifImage(res); + GifImagePtr image = TextureCache::GetInstance().AddOrGetGifImage(res); return Load(image); } diff --git a/src/kiwano/2d/Stage.cpp b/src/kiwano/2d/Stage.cpp index a0292ac5..dc01d969 100644 --- a/src/kiwano/2d/Stage.cpp +++ b/src/kiwano/2d/Stage.cpp @@ -36,7 +36,7 @@ Stage::Stage() SetStage(this); SetAnchor(Vec2{ 0, 0 }); - SetSize(Renderer::Instance().GetOutputSize()); + SetSize(Renderer::GetInstance().GetOutputSize()); } Stage::~Stage() {} diff --git a/src/kiwano/2d/Transition.cpp b/src/kiwano/2d/Transition.cpp index bec5700c..19c5fee1 100644 --- a/src/kiwano/2d/Transition.cpp +++ b/src/kiwano/2d/Transition.cpp @@ -58,7 +58,7 @@ void Transition::Init(StagePtr prev, StagePtr next) out_stage_ = prev; in_stage_ = next; - window_size_ = Renderer::Instance().GetOutputSize(); + window_size_ = Renderer::GetInstance().GetOutputSize(); if (in_stage_) { diff --git a/src/kiwano/core/Logger.h b/src/kiwano/core/Logger.h index 4a48a36c..25756634 100644 --- a/src/kiwano/core/Logger.h +++ b/src/kiwano/core/Logger.h @@ -27,26 +27,26 @@ #ifndef KGE_SYS_LOG #ifdef KGE_DEBUG #define KGE_SYS_LOG(FORMAT, ...) \ - ::kiwano::Logger::Instance().Printf(::kiwano::Logger::Level::System, FORMAT, __VA_ARGS__) + ::kiwano::Logger::GetInstance().Printf(::kiwano::Logger::Level::System, FORMAT, __VA_ARGS__) #else #define KGE_SYS_LOG __noop #endif #endif #ifndef KGE_WARN -#define KGE_WARN(FORMAT, ...) ::kiwano::Logger::Instance().Printf(::kiwano::Logger::Level::Warning, FORMAT, __VA_ARGS__) +#define KGE_WARN(FORMAT, ...) ::kiwano::Logger::GetInstance().Printf(::kiwano::Logger::Level::Warning, FORMAT, __VA_ARGS__) #endif #ifndef KGE_ERROR -#define KGE_ERROR(FORMAT, ...) ::kiwano::Logger::Instance().Printf(::kiwano::Logger::Level::Error, FORMAT, __VA_ARGS__) +#define KGE_ERROR(FORMAT, ...) ::kiwano::Logger::GetInstance().Printf(::kiwano::Logger::Level::Error, FORMAT, __VA_ARGS__) #endif #ifndef KGE_LOG -#define KGE_LOG(...) ::kiwano::Logger::Instance().Println(::kiwano::Logger::Level::Info, __VA_ARGS__) +#define KGE_LOG(...) ::kiwano::Logger::GetInstance().Println(::kiwano::Logger::Level::Info, __VA_ARGS__) #endif #ifndef KGE_LOGF -#define KGE_LOGF(FORMAT, ...) ::kiwano::Logger::Instance().Printf(::kiwano::Logger::Level::Info, FORMAT, __VA_ARGS__) +#define KGE_LOGF(FORMAT, ...) ::kiwano::Logger::GetInstance().Printf(::kiwano::Logger::Level::Info, FORMAT, __VA_ARGS__) #endif namespace kiwano diff --git a/src/kiwano/core/Singleton.h b/src/kiwano/core/Singleton.h index e96ca591..7ed4e853 100644 --- a/src/kiwano/core/Singleton.h +++ b/src/kiwano/core/Singleton.h @@ -36,7 +36,7 @@ private: { ObjectCreator() { - (void)Singleton<_Ty>::Instance(); + (void)Singleton<_Ty>::GetInstance(); } inline void Dummy() const {} @@ -46,7 +46,7 @@ private: public: using object_type = _Ty; - static inline object_type& Instance() + static inline object_type& GetInstance() { static object_type instance; creator_.Dummy(); diff --git a/src/kiwano/platform/Application.cpp b/src/kiwano/platform/Application.cpp index 0059be04..0977cd4e 100644 --- a/src/kiwano/platform/Application.cpp +++ b/src/kiwano/platform/Application.cpp @@ -41,9 +41,9 @@ Queue functions_to_perform_; Application::Application() : time_scale_(1.f) { - Use(&Renderer::Instance()); - Use(&Input::Instance()); - Use(&Director::Instance()); + Use(&Renderer::GetInstance()); + Use(&Input::GetInstance()); + Use(&Director::GetInstance()); } Application::~Application() @@ -61,8 +61,8 @@ void Application::Run(bool debug) if (debug) { - Director::Instance().ShowDebugInfo(true); - Renderer::Instance().GetContext().SetCollectingStatus(true); + Director::GetInstance().ShowDebugInfo(true); + Renderer::GetInstance().GetContext().SetCollectingStatus(true); } // Everything is ready @@ -70,7 +70,7 @@ void Application::Run(bool debug) last_update_time_ = Time::Now(); - Window& window = Window::Instance(); + Window& window = Window::GetInstance(); while (!window.ShouldClose()) { while (EventPtr evt = window.PollEvent()) @@ -85,15 +85,15 @@ void Application::Run(bool debug) void Application::Quit() { - Window::Instance().Destroy(); + Window::GetInstance().Destroy(); } void Application::Destroy() { // Clear all resources - Director::Instance().ClearStages(); - ResourceCache::Instance().Clear(); - TextureCache::Instance().Clear(); + Director::GetInstance().ClearStages(); + ResourceCache::GetInstance().Clear(); + TextureCache::GetInstance().Clear(); for (auto iter = comps_.rbegin(); iter != comps_.rend(); ++iter) { @@ -185,7 +185,7 @@ void Application::Update() void Application::Render() { - Renderer& renderer = Renderer::Instance(); + Renderer& renderer = Renderer::GetInstance(); renderer.Clear(); // Before render diff --git a/src/kiwano/platform/Window.h b/src/kiwano/platform/Window.h index f505fae9..0fe19d75 100644 --- a/src/kiwano/platform/Window.h +++ b/src/kiwano/platform/Window.h @@ -65,7 +65,7 @@ public: * \~chinese * @brief 获取窗口实例 */ - static Window& Instance(); + static Window& GetInstance(); /** * \~chinese diff --git a/src/kiwano/platform/win32/WindowImpl.cpp b/src/kiwano/platform/win32/WindowImpl.cpp index 131101c5..1f8c1fd7 100644 --- a/src/kiwano/platform/win32/WindowImpl.cpp +++ b/src/kiwano/platform/win32/WindowImpl.cpp @@ -684,7 +684,7 @@ LRESULT CALLBACK WindowImpl::WndProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA namespace kiwano { -Window& Window::Instance() +Window& Window::GetInstance() { static win32::WindowImpl instance; return instance; diff --git a/src/kiwano/render/Brush.cpp b/src/kiwano/render/Brush.cpp index 6ffe135c..f02d53d5 100644 --- a/src/kiwano/render/Brush.cpp +++ b/src/kiwano/render/Brush.cpp @@ -112,17 +112,17 @@ void Brush::SetOpacity(float opacity) void Brush::SetColor(Color const& color) { - Renderer::Instance().CreateBrush(*this, color); + Renderer::GetInstance().CreateBrush(*this, color); } void Brush::SetStyle(LinearGradientStyle const& style) { - Renderer::Instance().CreateBrush(*this, style); + Renderer::GetInstance().CreateBrush(*this, style); } void Brush::SetStyle(RadialGradientStyle const& style) { - Renderer::Instance().CreateBrush(*this, style); + Renderer::GetInstance().CreateBrush(*this, style); } } // namespace kiwano diff --git a/src/kiwano/render/Font.cpp b/src/kiwano/render/Font.cpp index fb8f610d..f5366d01 100644 --- a/src/kiwano/render/Font.cpp +++ b/src/kiwano/render/Font.cpp @@ -52,7 +52,7 @@ bool Font::Load(String const& file) { try { - Renderer::Instance().CreateFontCollection(*this, file); + Renderer::GetInstance().CreateFontCollection(*this, file); } catch (std::runtime_error&) { @@ -65,7 +65,7 @@ bool Font::Load(Resource const& resource) { try { - Renderer::Instance().CreateFontCollection(*this, resource); + Renderer::GetInstance().CreateFontCollection(*this, resource); } catch (std::runtime_error&) { diff --git a/src/kiwano/render/GifImage.cpp b/src/kiwano/render/GifImage.cpp index 825fa282..1d526667 100644 --- a/src/kiwano/render/GifImage.cpp +++ b/src/kiwano/render/GifImage.cpp @@ -56,7 +56,7 @@ GifImage::GifImage() bool GifImage::Load(String const& file_path) { - Renderer::Instance().CreateGifImage(*this, file_path); + Renderer::GetInstance().CreateGifImage(*this, file_path); if (IsValid()) { @@ -70,7 +70,7 @@ bool GifImage::Load(String const& file_path) bool GifImage::Load(Resource const& res) { - Renderer::Instance().CreateGifImage(*this, res); + Renderer::GetInstance().CreateGifImage(*this, res); if (IsValid()) { @@ -90,7 +90,7 @@ bool GifImage::IsValid() const GifImage::Frame GifImage::GetFrame(uint32_t index) { Frame frame; - Renderer::Instance().CreateGifImageFrame(frame, *this, index); + Renderer::GetInstance().CreateGifImageFrame(frame, *this, index); return frame; } diff --git a/src/kiwano/render/Renderer.cpp b/src/kiwano/render/Renderer.cpp index 9f01f0c0..6850dbb5 100644 --- a/src/kiwano/render/Renderer.cpp +++ b/src/kiwano/render/Renderer.cpp @@ -42,8 +42,8 @@ void Renderer::SetupComponent() win32::ThrowIfFailed(::CoInitialize(nullptr)); - target_window_ = Window::Instance().GetHandle(); - output_size_ = Window::Instance().GetSize(); + target_window_ = Window::GetInstance().GetHandle(); + output_size_ = Window::GetInstance().GetSize(); d2d_res_ = nullptr; d3d_res_ = nullptr; @@ -197,7 +197,7 @@ void Renderer::CreateTexture(Texture& texture, String const& file_path) hr = E_UNEXPECTED; } - if (!FileSystem::Instance().IsFileExists(file_path)) + if (!FileSystem::GetInstance().IsFileExists(file_path)) { KGE_WARN(L"Texture file '%s' not found!", file_path.c_str()); hr = E_FAIL; @@ -205,7 +205,7 @@ void Renderer::CreateTexture(Texture& texture, String const& file_path) if (SUCCEEDED(hr)) { - String full_path = FileSystem::Instance().GetFullPathForFile(file_path); + String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path); ComPtr decoder; hr = d2d_res_->CreateBitmapDecoderFromFile(decoder, full_path); @@ -295,7 +295,7 @@ void Renderer::CreateGifImage(GifImage& gif, String const& file_path) hr = E_UNEXPECTED; } - if (!FileSystem::Instance().IsFileExists(file_path)) + if (!FileSystem::GetInstance().IsFileExists(file_path)) { KGE_WARN(L"Gif texture file '%s' not found!", file_path.c_str()); hr = E_FAIL; @@ -303,7 +303,7 @@ void Renderer::CreateGifImage(GifImage& gif, String const& file_path) if (SUCCEEDED(hr)) { - String full_path = FileSystem::Instance().GetFullPathForFile(file_path); + String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path); ComPtr decoder; hr = d2d_res_->CreateBitmapDecoderFromFile(decoder, full_path); @@ -514,7 +514,7 @@ void Renderer::CreateFontCollection(Font& font, String const& file_path) if (SUCCEEDED(hr)) { - if (!FileSystem::Instance().IsFileExists(file_path)) + if (!FileSystem::GetInstance().IsFileExists(file_path)) { KGE_WARN(L"Font file '%s' not found!", file_path.c_str()); hr = E_FAIL; @@ -525,7 +525,7 @@ void Renderer::CreateFontCollection(Font& font, String const& file_path) { LPVOID key = nullptr; uint32_t key_size = 0; - String full_path = FileSystem::Instance().GetFullPathForFile(file_path); + String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path); hr = font_collection_loader_->AddFilePaths({ full_path }, &key, &key_size); diff --git a/src/kiwano/render/Shape.cpp b/src/kiwano/render/Shape.cpp index ed45dae6..07a9ae35 100644 --- a/src/kiwano/render/Shape.cpp +++ b/src/kiwano/render/Shape.cpp @@ -108,35 +108,35 @@ bool Shape::ContainsPoint(Point const& point, const Matrix3x2* transform) const ShapePtr Shape::CreateLine(Point const& begin, Point const& end) { ShapePtr output = new Shape; - Renderer::Instance().CreateLineShape(*output, begin, end); + Renderer::GetInstance().CreateLineShape(*output, begin, end); return output; } ShapePtr Shape::CreateRect(Rect const& rect) { ShapePtr output = new Shape; - Renderer::Instance().CreateRectShape(*output, rect); + Renderer::GetInstance().CreateRectShape(*output, rect); return output; } ShapePtr Shape::CreateRoundedRect(Rect const& rect, Vec2 const& radius) { ShapePtr output = new Shape; - Renderer::Instance().CreateRoundedRectShape(*output, rect, radius); + Renderer::GetInstance().CreateRoundedRectShape(*output, rect, radius); return output; } ShapePtr Shape::CreateCircle(Point const& center, float radius) { ShapePtr output = new Shape; - Renderer::Instance().CreateEllipseShape(*output, center, Vec2{ radius, radius }); + Renderer::GetInstance().CreateEllipseShape(*output, center, Vec2{ radius, radius }); return output; } ShapePtr Shape::CreateEllipse(Point const& center, Vec2 const& radius) { ShapePtr output = new Shape; - Renderer::Instance().CreateEllipseShape(*output, center, radius); + Renderer::GetInstance().CreateEllipseShape(*output, center, radius); return output; } diff --git a/src/kiwano/render/ShapeSink.cpp b/src/kiwano/render/ShapeSink.cpp index 941093fa..95e14b58 100644 --- a/src/kiwano/render/ShapeSink.cpp +++ b/src/kiwano/render/ShapeSink.cpp @@ -36,7 +36,7 @@ void ShapeSink::Open() if (!IsOpened()) { path_geo_.reset(); - Renderer::Instance().CreateShapeSink(*this); + Renderer::GetInstance().CreateShapeSink(*this); win32::ThrowIfFailed(path_geo_->Open(&sink_)); } diff --git a/src/kiwano/render/StrokeStyle.cpp b/src/kiwano/render/StrokeStyle.cpp index 89c42c6e..c0cade8a 100644 --- a/src/kiwano/render/StrokeStyle.cpp +++ b/src/kiwano/render/StrokeStyle.cpp @@ -69,7 +69,7 @@ StrokeStylePtr StrokeStyle::Create(CapStyle cap, LineJoinStyle line_join, const StrokeStylePtr ptr = new (std::nothrow) StrokeStyle; if (ptr) { - Renderer::Instance().CreateStrokeStyle(*ptr, cap, line_join, dash_array, dash_size, dash_offset); + Renderer::GetInstance().CreateStrokeStyle(*ptr, cap, line_join, dash_array, dash_size, dash_offset); } return ptr; } diff --git a/src/kiwano/render/TextLayout.cpp b/src/kiwano/render/TextLayout.cpp index 29f73f9b..e7340b8c 100644 --- a/src/kiwano/render/TextLayout.cpp +++ b/src/kiwano/render/TextLayout.cpp @@ -42,12 +42,12 @@ void TextLayout::Update() if (!text_format_ || (dirty_flag_ & DirtyFlag::DirtyFormat)) { - Renderer::Instance().CreateTextFormat(*this); + Renderer::GetInstance().CreateTextFormat(*this); } if (dirty_flag_ & DirtyFlag::DirtyLayout) { - Renderer::Instance().CreateTextLayout(*this); + Renderer::GetInstance().CreateTextLayout(*this); if (text_layout_) { diff --git a/src/kiwano/render/Texture.cpp b/src/kiwano/render/Texture.cpp index 3ddae370..4c9248fa 100644 --- a/src/kiwano/render/Texture.cpp +++ b/src/kiwano/render/Texture.cpp @@ -57,13 +57,13 @@ Texture::~Texture() {} bool Texture::Load(String const& file_path) { - Renderer::Instance().CreateTexture(*this, file_path); + Renderer::GetInstance().CreateTexture(*this, file_path); return IsValid(); } bool Texture::Load(Resource const& res) { - Renderer::Instance().CreateTexture(*this, res); + Renderer::GetInstance().CreateTexture(*this, res); return IsValid(); } diff --git a/src/kiwano/render/TextureRenderContext.cpp b/src/kiwano/render/TextureRenderContext.cpp index e0c4e71c..f2995b8c 100644 --- a/src/kiwano/render/TextureRenderContext.cpp +++ b/src/kiwano/render/TextureRenderContext.cpp @@ -32,7 +32,7 @@ TextureRenderContextPtr TextureRenderContext::Create() { try { - Renderer::Instance().CreateTextureRenderContext(*ptr); + Renderer::GetInstance().CreateTextureRenderContext(*ptr); } catch (std::exception) { @@ -49,7 +49,7 @@ TextureRenderContextPtr TextureRenderContext::Create(Size const& desired_size) { try { - Renderer::Instance().CreateTextureRenderContext(*ptr, &desired_size); + Renderer::GetInstance().CreateTextureRenderContext(*ptr, &desired_size); } catch (std::exception) { diff --git a/src/kiwano/utils/ResourceCache.cpp b/src/kiwano/utils/ResourceCache.cpp index 703b7492..8c7564c8 100644 --- a/src/kiwano/utils/ResourceCache.cpp +++ b/src/kiwano/utils/ResourceCache.cpp @@ -53,7 +53,7 @@ ResourceCache::~ResourceCache() bool ResourceCache::LoadFromJsonFile(String const& file_path) { - if (!FileSystem::Instance().IsFileExists(file_path)) + if (!FileSystem::GetInstance().IsFileExists(file_path)) { KGE_ERROR(L"ResourceCache::LoadFromJsonFile failed: File not found."); return false; @@ -65,7 +65,7 @@ bool ResourceCache::LoadFromJsonFile(String const& file_path) try { - String full_path = FileSystem::Instance().GetFullPathForFile(file_path); + String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path); ifs.open(full_path.c_str()); ifs >> json_data; ifs.close(); @@ -116,13 +116,13 @@ bool ResourceCache::LoadFromJson(Json const& json_data) bool ResourceCache::LoadFromXmlFile(String const& file_path) { - if (!FileSystem::Instance().IsFileExists(file_path)) + if (!FileSystem::GetInstance().IsFileExists(file_path)) { KGE_ERROR(L"ResourceCache::LoadFromXmlFile failed: File not found."); return false; } - String full_path = FileSystem::Instance().GetFullPathForFile(file_path); + String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path); pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file(full_path.c_str(), pugi::parse_default, pugi::encoding_auto); From 4633d7b6b9c24f1e2feebfd63cf3d87c4262429f Mon Sep 17 00:00:00 2001 From: Nomango Date: Sun, 9 Feb 2020 15:33:46 +0800 Subject: [PATCH 04/12] Update DebugActor --- src/kiwano/2d/DebugActor.cpp | 10 +++++----- src/kiwano/2d/DebugActor.h | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/kiwano/2d/DebugActor.cpp b/src/kiwano/2d/DebugActor.cpp index 495df54d..114bed2f 100644 --- a/src/kiwano/2d/DebugActor.cpp +++ b/src/kiwano/2d/DebugActor.cpp @@ -78,17 +78,17 @@ void DebugActor::OnRender(RenderContext& ctx) ctx.SetCurrentBrush(background_brush_); ctx.FillRoundedRectangle(GetBounds(), Vec2{ 5.f, 5.f }); ctx.DrawTextLayout(debug_text_, Point(10, 10)); -} - -void DebugActor::OnUpdate(Duration dt) -{ - KGE_NOT_USED(dt); frame_time_.push_back(Time::Now()); while (frame_time_.back() - frame_time_.front() >= Duration::Second) { frame_time_.erase(frame_time_.begin()); } +} + +void DebugActor::OnUpdate(Duration dt) +{ + KGE_NOT_USED(dt); StringStream ss; diff --git a/src/kiwano/2d/DebugActor.h b/src/kiwano/2d/DebugActor.h index e8d33e2e..16cca51d 100644 --- a/src/kiwano/2d/DebugActor.h +++ b/src/kiwano/2d/DebugActor.h @@ -48,10 +48,10 @@ protected: bool CheckVisibility(RenderContext& ctx) const override; private: - std::locale comma_locale_; - BrushPtr background_brush_; - TextLayout debug_text_; - Vector