From 9bc195781d77757a7d43bf432b27a427f58ac80d Mon Sep 17 00:00:00 2001 From: Nomango Date: Tue, 27 Aug 2019 08:28:14 +0800 Subject: [PATCH] minor --- src/kiwano/2d/Frame.h | 1 + src/kiwano/2d/ShapeActor.cpp | 38 +++++++++++++++---- src/kiwano/2d/ShapeActor.h | 37 ++++++++++++------ src/kiwano/renderer/GifImage.h | 1 + .../renderer/win32/D2DDeviceResources.cpp | 36 +++++++++--------- .../renderer/win32/D2DDeviceResources.h | 13 +++---- 6 files changed, 82 insertions(+), 44 deletions(-) diff --git a/src/kiwano/2d/Frame.h b/src/kiwano/2d/Frame.h index 1c58955f..494639ef 100644 --- a/src/kiwano/2d/Frame.h +++ b/src/kiwano/2d/Frame.h @@ -19,6 +19,7 @@ // THE SOFTWARE. #pragma once +#include "../base/ObjectBase.h" #include "../renderer/Texture.h" namespace kiwano diff --git a/src/kiwano/2d/ShapeActor.cpp b/src/kiwano/2d/ShapeActor.cpp index a4a4b423..899e4c4c 100644 --- a/src/kiwano/2d/ShapeActor.cpp +++ b/src/kiwano/2d/ShapeActor.cpp @@ -123,18 +123,23 @@ namespace kiwano { } - LineActor::LineActor(Point const& point) + LineActor::LineActor(Point const& begin, Point const& end) { - SetPoint(point); + SetLine(begin, end); } LineActor::~LineActor() { } - void LineActor::SetPoint(Point const& point) + void LineActor::SetLine(Point const& begin, Point const& end) { - SetGeometry(Geometry::CreateLine(Point{}, point)); + if (begin_ != begin || end_ != end) + { + begin_ = begin; + end_ = end; + SetGeometry(Geometry::CreateLine(begin, end)); + } } @@ -157,7 +162,11 @@ namespace kiwano void RectActor::SetRectSize(Size const& size) { - SetGeometry(Geometry::CreateRect(Rect{ Point{}, size })); + if (size != rect_size_) + { + rect_size_ = size; + SetGeometry(Geometry::CreateRect(Rect{ Point{}, size })); + } } @@ -190,7 +199,12 @@ namespace kiwano void RoundRectActor::SetRoundedRect(Size const& size, Vec2 const& radius) { - SetGeometry(Geometry::CreateRoundedRect(Rect{ Point{}, size }, radius)); + if (rect_size_ != size || radius_ != radius) + { + rect_size_ = size; + radius_ = radius; + SetGeometry(Geometry::CreateRoundedRect(Rect{ Point{}, size }, radius)); + } } @@ -214,7 +228,11 @@ namespace kiwano void CircleActor::SetRadius(Float32 radius) { - SetGeometry(Geometry::CreateCircle(Point{ radius, radius }, radius)); + if (radius_ != radius) + { + radius_ = radius; + SetGeometry(Geometry::CreateCircle(Point{ radius, radius }, radius)); + } } @@ -237,7 +255,11 @@ namespace kiwano void EllipseActor::SetRadius(Vec2 const& radius) { - SetGeometry(Geometry::CreateEllipse(radius, radius)); + if (radius_ != radius) + { + radius_ = radius; + SetGeometry(Geometry::CreateEllipse(radius, radius)); + } } diff --git a/src/kiwano/2d/ShapeActor.h b/src/kiwano/2d/ShapeActor.h index d0eec865..91de4e21 100644 --- a/src/kiwano/2d/ShapeActor.h +++ b/src/kiwano/2d/ShapeActor.h @@ -97,19 +97,34 @@ namespace kiwano LineActor(); LineActor( - Point const& point + Point const& begin, + Point const& end ); virtual ~LineActor(); - Point const& GetPoint() const { return point_; } + inline Point const& GetBeginPoint() const { return begin_; } + + inline Point const& GetEndPoint() const { return end_; } - void SetPoint( - Point const& point + inline void SetBeginPoint(Point const& begin) + { + SetLine(begin, end_); + } + + inline void SetEndPoint(Point const& end) + { + SetLine(begin_, end); + } + + void SetLine( + Point const& begin, + Point const& end ); protected: - Point point_; + Point begin_; + Point end_; }; @@ -126,10 +141,10 @@ namespace kiwano virtual ~RectActor(); - void SetRectSize(Size const& size); - inline Size const& GetRectSize() const { return rect_size_; } + void SetRectSize(Size const& size); + protected: Size rect_size_; }; @@ -149,6 +164,10 @@ namespace kiwano virtual ~RoundRectActor(); + inline Vec2 GetRadius() const { return radius_; } + + inline Size GetRectSize() const { return size_; } + void SetRadius( Vec2 const& radius ); @@ -162,10 +181,6 @@ namespace kiwano Vec2 const& radius ); - inline Vec2 GetRadius() const { return radius_; } - - inline Size GetRectSize() const { return size_; } - protected: Size rect_size_; Vec2 radius_; diff --git a/src/kiwano/renderer/GifImage.h b/src/kiwano/renderer/GifImage.h index 339c63f1..13a77494 100644 --- a/src/kiwano/renderer/GifImage.h +++ b/src/kiwano/renderer/GifImage.h @@ -20,6 +20,7 @@ #pragma once #include "Texture.h" +#include "../base/time.h" namespace kiwano { diff --git a/src/kiwano/renderer/win32/D2DDeviceResources.cpp b/src/kiwano/renderer/win32/D2DDeviceResources.cpp index 8a90e67e..7a85934e 100644 --- a/src/kiwano/renderer/win32/D2DDeviceResources.cpp +++ b/src/kiwano/renderer/win32/D2DDeviceResources.cpp @@ -190,16 +190,16 @@ namespace kiwano imaging_factory_.reset(); dwrite_factory_.reset(); - d2d_miter_stroke_style_.reset(); - d2d_bevel_stroke_style_.reset(); - d2d_round_stroke_style_.reset(); + miter_stroke_style_.reset(); + bevel_stroke_style_.reset(); + round_stroke_style_.reset(); } HRESULT D2DDeviceResources::CreateDeviceIndependentResources() { HRESULT hr = S_OK; - ComPtr d2d_factory; + ComPtr factory; ComPtr imaging_factory; ComPtr dwrite_factory; @@ -213,12 +213,12 @@ namespace kiwano D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory1), &config, - reinterpret_cast(&d2d_factory) + reinterpret_cast(&factory) ); if (SUCCEEDED(hr)) { - factory_ = d2d_factory; + factory_ = factory; hr = CoCreateInstance( CLSID_WICImagingFactory, @@ -244,9 +244,9 @@ namespace kiwano { dwrite_factory_ = dwrite_factory; - ComPtr d2d_miter_stroke_style; - ComPtr d2d_bevel_stroke_style; - ComPtr d2d_round_stroke_style; + ComPtr miter_stroke_style; + ComPtr bevel_stroke_style; + ComPtr round_stroke_style; D2D1_STROKE_STYLE_PROPERTIES stroke_style = D2D1::StrokeStyleProperties( D2D1_CAP_STYLE_FLAT, @@ -262,7 +262,7 @@ namespace kiwano stroke_style, nullptr, 0, - &d2d_miter_stroke_style + &miter_stroke_style ); if (SUCCEEDED(hr)) @@ -272,7 +272,7 @@ namespace kiwano stroke_style, nullptr, 0, - &d2d_bevel_stroke_style + &bevel_stroke_style ); } @@ -283,15 +283,15 @@ namespace kiwano stroke_style, nullptr, 0, - &d2d_round_stroke_style + &round_stroke_style ); } if (SUCCEEDED(hr)) { - d2d_miter_stroke_style_ = d2d_miter_stroke_style; - d2d_bevel_stroke_style_ = d2d_bevel_stroke_style; - d2d_round_stroke_style_ = d2d_round_stroke_style; + miter_stroke_style_ = miter_stroke_style; + bevel_stroke_style_ = bevel_stroke_style; + round_stroke_style_ = round_stroke_style; } } @@ -300,17 +300,17 @@ namespace kiwano HRESULT D2DDeviceResources::SetD2DDevice(_In_ ComPtr const& device) { - ComPtr d2d_device_ctx; + ComPtr device_ctx; HRESULT hr = device->CreateDeviceContext( D2D1_DEVICE_CONTEXT_OPTIONS_NONE, - &d2d_device_ctx + &device_ctx ); if (SUCCEEDED(hr)) { device_ = device; - device_context_ = d2d_device_ctx; + device_context_ = device_ctx; device_context_->SetDpi(dpi_, dpi_); } diff --git a/src/kiwano/renderer/win32/D2DDeviceResources.h b/src/kiwano/renderer/win32/D2DDeviceResources.h index 5c117a29..a6ece50e 100644 --- a/src/kiwano/renderer/win32/D2DDeviceResources.h +++ b/src/kiwano/renderer/win32/D2DDeviceResources.h @@ -23,7 +23,6 @@ #include "../Color.h" #include "../../math/math.h" #include "../../base/Resource.h" -#include "../../2d/TextStyle.hpp" #include #include #include @@ -243,9 +242,9 @@ namespace kiwano inline ID2D1DeviceContext* GetDeviceContext() const { KGE_ASSERT(device_context_); return device_context_.get(); } inline ID2D1Bitmap1* GetTargetBitmap() const { KGE_ASSERT(target_bitmap_); return target_bitmap_.get(); } - inline ID2D1StrokeStyle* GetMiterStrokeStyle() const { KGE_ASSERT(d2d_miter_stroke_style_); return d2d_miter_stroke_style_.get(); } - inline ID2D1StrokeStyle* GetBevelStrokeStyle() const { KGE_ASSERT(d2d_bevel_stroke_style_); return d2d_bevel_stroke_style_.get(); } - inline ID2D1StrokeStyle* GetRoundStrokeStyle() const { KGE_ASSERT(d2d_round_stroke_style_); return d2d_round_stroke_style_.get(); } + inline ID2D1StrokeStyle* GetMiterStrokeStyle() const { KGE_ASSERT(miter_stroke_style_); return miter_stroke_style_.get(); } + inline ID2D1StrokeStyle* GetBevelStrokeStyle() const { KGE_ASSERT(bevel_stroke_style_); return bevel_stroke_style_.get(); } + inline ID2D1StrokeStyle* GetRoundStrokeStyle() const { KGE_ASSERT(round_stroke_style_); return round_stroke_style_.get(); } protected: ComPtr factory_; @@ -256,9 +255,9 @@ namespace kiwano ComPtr imaging_factory_; ComPtr dwrite_factory_; - ComPtr d2d_miter_stroke_style_; - ComPtr d2d_bevel_stroke_style_; - ComPtr d2d_round_stroke_style_; + ComPtr miter_stroke_style_; + ComPtr bevel_stroke_style_; + ComPtr round_stroke_style_; }; }