This commit is contained in:
Nomango 2019-08-27 08:28:14 +08:00
parent 46f9dae888
commit 9bc195781d
6 changed files with 82 additions and 44 deletions

View File

@ -19,6 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "../base/ObjectBase.h"
#include "../renderer/Texture.h" #include "../renderer/Texture.h"
namespace kiwano namespace kiwano

View File

@ -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() 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,8 +162,12 @@ namespace kiwano
void RectActor::SetRectSize(Size const& size) void RectActor::SetRectSize(Size const& size)
{ {
if (size != rect_size_)
{
rect_size_ = size;
SetGeometry(Geometry::CreateRect(Rect{ Point{}, size })); SetGeometry(Geometry::CreateRect(Rect{ Point{}, size }));
} }
}
//------------------------------------------------------- //-------------------------------------------------------
@ -190,8 +199,13 @@ namespace kiwano
void RoundRectActor::SetRoundedRect(Size const& size, Vec2 const& radius) void RoundRectActor::SetRoundedRect(Size const& size, Vec2 const& radius)
{ {
if (rect_size_ != size || radius_ != radius)
{
rect_size_ = size;
radius_ = radius;
SetGeometry(Geometry::CreateRoundedRect(Rect{ Point{}, size }, radius)); SetGeometry(Geometry::CreateRoundedRect(Rect{ Point{}, size }, radius));
} }
}
//------------------------------------------------------- //-------------------------------------------------------
@ -214,8 +228,12 @@ namespace kiwano
void CircleActor::SetRadius(Float32 radius) void CircleActor::SetRadius(Float32 radius)
{ {
if (radius_ != radius)
{
radius_ = radius;
SetGeometry(Geometry::CreateCircle(Point{ radius, radius }, radius)); SetGeometry(Geometry::CreateCircle(Point{ radius, radius }, radius));
} }
}
//------------------------------------------------------- //-------------------------------------------------------
@ -237,8 +255,12 @@ namespace kiwano
void EllipseActor::SetRadius(Vec2 const& radius) void EllipseActor::SetRadius(Vec2 const& radius)
{ {
if (radius_ != radius)
{
radius_ = radius;
SetGeometry(Geometry::CreateEllipse(radius, radius)); SetGeometry(Geometry::CreateEllipse(radius, radius));
} }
}
//------------------------------------------------------- //-------------------------------------------------------

View File

@ -97,19 +97,34 @@ namespace kiwano
LineActor(); LineActor();
LineActor( LineActor(
Point const& point Point const& begin,
Point const& end
); );
virtual ~LineActor(); virtual ~LineActor();
Point const& GetPoint() const { return point_; } inline Point const& GetBeginPoint() const { return begin_; }
void SetPoint( inline Point const& GetEndPoint() const { return end_; }
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: protected:
Point point_; Point begin_;
Point end_;
}; };
@ -126,10 +141,10 @@ namespace kiwano
virtual ~RectActor(); virtual ~RectActor();
void SetRectSize(Size const& size);
inline Size const& GetRectSize() const { return rect_size_; } inline Size const& GetRectSize() const { return rect_size_; }
void SetRectSize(Size const& size);
protected: protected:
Size rect_size_; Size rect_size_;
}; };
@ -149,6 +164,10 @@ namespace kiwano
virtual ~RoundRectActor(); virtual ~RoundRectActor();
inline Vec2 GetRadius() const { return radius_; }
inline Size GetRectSize() const { return size_; }
void SetRadius( void SetRadius(
Vec2 const& radius Vec2 const& radius
); );
@ -162,10 +181,6 @@ namespace kiwano
Vec2 const& radius Vec2 const& radius
); );
inline Vec2 GetRadius() const { return radius_; }
inline Size GetRectSize() const { return size_; }
protected: protected:
Size rect_size_; Size rect_size_;
Vec2 radius_; Vec2 radius_;

View File

@ -20,6 +20,7 @@
#pragma once #pragma once
#include "Texture.h" #include "Texture.h"
#include "../base/time.h"
namespace kiwano namespace kiwano
{ {

View File

@ -190,16 +190,16 @@ namespace kiwano
imaging_factory_.reset(); imaging_factory_.reset();
dwrite_factory_.reset(); dwrite_factory_.reset();
d2d_miter_stroke_style_.reset(); miter_stroke_style_.reset();
d2d_bevel_stroke_style_.reset(); bevel_stroke_style_.reset();
d2d_round_stroke_style_.reset(); round_stroke_style_.reset();
} }
HRESULT D2DDeviceResources::CreateDeviceIndependentResources() HRESULT D2DDeviceResources::CreateDeviceIndependentResources()
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
ComPtr<ID2D1Factory1> d2d_factory; ComPtr<ID2D1Factory1> factory;
ComPtr<IWICImagingFactory> imaging_factory; ComPtr<IWICImagingFactory> imaging_factory;
ComPtr<IDWriteFactory> dwrite_factory; ComPtr<IDWriteFactory> dwrite_factory;
@ -213,12 +213,12 @@ namespace kiwano
D2D1_FACTORY_TYPE_SINGLE_THREADED, D2D1_FACTORY_TYPE_SINGLE_THREADED,
__uuidof(ID2D1Factory1), __uuidof(ID2D1Factory1),
&config, &config,
reinterpret_cast<void**>(&d2d_factory) reinterpret_cast<void**>(&factory)
); );
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
factory_ = d2d_factory; factory_ = factory;
hr = CoCreateInstance( hr = CoCreateInstance(
CLSID_WICImagingFactory, CLSID_WICImagingFactory,
@ -244,9 +244,9 @@ namespace kiwano
{ {
dwrite_factory_ = dwrite_factory; dwrite_factory_ = dwrite_factory;
ComPtr<ID2D1StrokeStyle> d2d_miter_stroke_style; ComPtr<ID2D1StrokeStyle> miter_stroke_style;
ComPtr<ID2D1StrokeStyle> d2d_bevel_stroke_style; ComPtr<ID2D1StrokeStyle> bevel_stroke_style;
ComPtr<ID2D1StrokeStyle> d2d_round_stroke_style; ComPtr<ID2D1StrokeStyle> round_stroke_style;
D2D1_STROKE_STYLE_PROPERTIES stroke_style = D2D1::StrokeStyleProperties( D2D1_STROKE_STYLE_PROPERTIES stroke_style = D2D1::StrokeStyleProperties(
D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT,
@ -262,7 +262,7 @@ namespace kiwano
stroke_style, stroke_style,
nullptr, nullptr,
0, 0,
&d2d_miter_stroke_style &miter_stroke_style
); );
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
@ -272,7 +272,7 @@ namespace kiwano
stroke_style, stroke_style,
nullptr, nullptr,
0, 0,
&d2d_bevel_stroke_style &bevel_stroke_style
); );
} }
@ -283,15 +283,15 @@ namespace kiwano
stroke_style, stroke_style,
nullptr, nullptr,
0, 0,
&d2d_round_stroke_style &round_stroke_style
); );
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
d2d_miter_stroke_style_ = d2d_miter_stroke_style; miter_stroke_style_ = miter_stroke_style;
d2d_bevel_stroke_style_ = d2d_bevel_stroke_style; bevel_stroke_style_ = bevel_stroke_style;
d2d_round_stroke_style_ = d2d_round_stroke_style; round_stroke_style_ = round_stroke_style;
} }
} }
@ -300,17 +300,17 @@ namespace kiwano
HRESULT D2DDeviceResources::SetD2DDevice(_In_ ComPtr<ID2D1Device> const& device) HRESULT D2DDeviceResources::SetD2DDevice(_In_ ComPtr<ID2D1Device> const& device)
{ {
ComPtr<ID2D1DeviceContext> d2d_device_ctx; ComPtr<ID2D1DeviceContext> device_ctx;
HRESULT hr = device->CreateDeviceContext( HRESULT hr = device->CreateDeviceContext(
D2D1_DEVICE_CONTEXT_OPTIONS_NONE, D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
&d2d_device_ctx &device_ctx
); );
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
device_ = device; device_ = device;
device_context_ = d2d_device_ctx; device_context_ = device_ctx;
device_context_->SetDpi(dpi_, dpi_); device_context_->SetDpi(dpi_, dpi_);
} }

View File

@ -23,7 +23,6 @@
#include "../Color.h" #include "../Color.h"
#include "../../math/math.h" #include "../../math/math.h"
#include "../../base/Resource.h" #include "../../base/Resource.h"
#include "../../2d/TextStyle.hpp"
#include <dwrite.h> #include <dwrite.h>
#include <d2d1.h> #include <d2d1.h>
#include <d2d1_1.h> #include <d2d1_1.h>
@ -243,9 +242,9 @@ namespace kiwano
inline ID2D1DeviceContext* GetDeviceContext() const { KGE_ASSERT(device_context_); return device_context_.get(); } 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 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* GetMiterStrokeStyle() const { KGE_ASSERT(miter_stroke_style_); return miter_stroke_style_.get(); }
inline ID2D1StrokeStyle* GetBevelStrokeStyle() const { KGE_ASSERT(d2d_bevel_stroke_style_); return d2d_bevel_stroke_style_.get(); } inline ID2D1StrokeStyle* GetBevelStrokeStyle() const { KGE_ASSERT(bevel_stroke_style_); return bevel_stroke_style_.get(); }
inline ID2D1StrokeStyle* GetRoundStrokeStyle() const { KGE_ASSERT(d2d_round_stroke_style_); return d2d_round_stroke_style_.get(); } inline ID2D1StrokeStyle* GetRoundStrokeStyle() const { KGE_ASSERT(round_stroke_style_); return round_stroke_style_.get(); }
protected: protected:
ComPtr<ID2D1Factory1> factory_; ComPtr<ID2D1Factory1> factory_;
@ -256,9 +255,9 @@ namespace kiwano
ComPtr<IWICImagingFactory> imaging_factory_; ComPtr<IWICImagingFactory> imaging_factory_;
ComPtr<IDWriteFactory> dwrite_factory_; ComPtr<IDWriteFactory> dwrite_factory_;
ComPtr<ID2D1StrokeStyle> d2d_miter_stroke_style_; ComPtr<ID2D1StrokeStyle> miter_stroke_style_;
ComPtr<ID2D1StrokeStyle> d2d_bevel_stroke_style_; ComPtr<ID2D1StrokeStyle> bevel_stroke_style_;
ComPtr<ID2D1StrokeStyle> d2d_round_stroke_style_; ComPtr<ID2D1StrokeStyle> round_stroke_style_;
}; };
} }