This commit is contained in:
Nomango 2019-08-27 15:29:32 +08:00
parent 9bc195781d
commit 33f78bb5d5
14 changed files with 133 additions and 101 deletions

View File

@ -39,10 +39,12 @@ namespace kiwano
Actor::Actor()
: visible_(true)
, visible_in_rt_(true)
, update_pausing_(false)
, hover_(false)
, pressed_(false)
, responsible_(false)
, dirty_visibility_(true)
, dirty_transform_(false)
, dirty_transform_inverse_(false)
, cascade_opacity_(false)
@ -139,6 +141,16 @@ namespace kiwano
}
}
bool Actor::CheckVisibilty(RenderTarget* rt) const
{
if (dirty_visibility_)
{
dirty_visibility_ = false;
visible_in_rt_ = rt->CheckVisibility(GetBounds(), GetTransformMatrix());
}
return visible_in_rt_;
}
void Actor::Dispatch(Event& evt)
{
if (!visible_)
@ -224,6 +236,7 @@ namespace kiwano
dirty_transform_ = false;
dirty_transform_inverse_ = true;
dirty_visibility_ = true;
if (is_fast_transform_)
{

View File

@ -390,6 +390,8 @@ namespace kiwano
virtual void RenderBorder(RenderTarget* rt);
virtual bool CheckVisibilty(RenderTarget* rt) const;
void UpdateTransform() const;
void UpdateOpacity();
@ -400,12 +402,12 @@ namespace kiwano
protected:
bool visible_;
bool hover_;
bool pressed_;
bool responsible_;
bool update_pausing_;
bool cascade_opacity_;
bool show_border_;
bool hover_;
bool pressed_;
bool responsible_;
Int32 z_order_;
Float32 opacity_;
Float32 displayed_opacity_;
@ -419,6 +421,8 @@ namespace kiwano
Transform transform_;
bool is_fast_transform_;
mutable bool visible_in_rt_;
mutable bool dirty_visibility_;
mutable bool dirty_transform_;
mutable bool dirty_transform_inverse_;
mutable Matrix3x2 transform_matrix_;

View File

@ -89,7 +89,7 @@ namespace kiwano
void GifSprite::OnRender(RenderTarget* rt)
{
if (frame_.raw.IsValid() && rt->CheckVisibility(GetBounds(), GetTransformMatrix()))
if (frame_.raw.IsValid() && CheckVisibilty(rt))
{
PrepareRender(rt);

View File

@ -85,7 +85,7 @@ namespace kiwano
geo_ = geometry;
if (geo_)
{
bounds_ = geo_.GetBoundingBox(Matrix3x2());
bounds_ = geo_.GetBoundingBox();
SetSize(bounds_.GetSize());
}
else
@ -97,21 +97,21 @@ namespace kiwano
void ShapeActor::OnRender(RenderTarget* rt)
{
if (geo_ && rt->CheckVisibility(GetBounds(), GetTransformMatrix()))
if (geo_ && CheckVisibilty(rt))
{
PrepareRender(rt);
rt->FillGeometry(
geo_,
fill_color_
);
rt->DrawGeometry(
geo_,
stroke_color_,
stroke_width_,
stroke_width_ * 2, // twice width for widening
stroke_style_
);
rt->FillGeometry(
geo_,
fill_color_
);
}
}

View File

@ -104,7 +104,7 @@ namespace kiwano
void Sprite::OnRender(RenderTarget* rt)
{
if (frame_ && rt->CheckVisibility(GetBounds(), GetTransformMatrix()))
if (frame_ && CheckVisibilty(rt))
{
PrepareRender(rt);

View File

@ -204,7 +204,7 @@ namespace kiwano
{
UpdateLayout();
if (text_layout_ && rt->CheckVisibility(GetBounds(), GetTransformMatrix()))
if (text_layout_ && CheckVisibilty(rt))
{
PrepareRender(rt);
rt->DrawTextLayout(text_layout_);

View File

@ -48,27 +48,14 @@ namespace kiwano
StrokeStyle outline_stroke; // ĂčąßĎßĎཝŃůĘ˝
public:
TextStyle()
: color(Color::White)
, alignment(TextAlign::Left)
, wrap_width(0.f)
, line_spacing(0.f)
, underline(false)
, strikethrough(false)
, outline(true)
, outline_color(Color(Color::Black, 0.5))
, outline_width(1.f)
, outline_stroke(StrokeStyle::Round)
{}
TextStyle(
Color color,
Color color = Color::White,
TextAlign alignment = TextAlign::Left,
Float32 wrap_width = 0.f,
Float32 line_spacing = 0.f,
bool underline = false,
bool strikethrough = false,
bool outline = true,
bool outline = false,
Color outline_color = Color(Color::Black, 0.5),
Float32 outline_width = 1.f,
StrokeStyle outline_stroke = StrokeStyle::Round

View File

@ -78,9 +78,9 @@ public:
inline pointer_type get() const noexcept { return ptr_; }
inline void reset() noexcept
inline void reset(pointer_type ptr = nullptr) noexcept
{
intrusive_ptr{}.swap(*this);
intrusive_ptr{ ptr }.swap(*this);
}
inline void swap(intrusive_ptr& other) noexcept

View File

@ -78,6 +78,9 @@ namespace kiwano
{
}
#pragma warning (push)
#pragma warning (disable: 26495) // ignore warning "always initialize member variables"
template <typename _MTy>
Matrix3x2T(_MTy const& other)
{
@ -85,6 +88,8 @@ namespace kiwano
m[i] = other[i];
}
#pragma warning (pop)
inline value_type operator [](UInt32 index) const
{
return m[index];

View File

@ -43,15 +43,26 @@ namespace kiwano
return geo_ != nullptr;
}
Rect Geometry::GetBoundingBox() const
{
Rect bounds;
if (geo_)
{
// no matter it failed or not
geo_->GetBounds(nullptr, DX::ConvertToRectF(&bounds));
}
return bounds;
}
Rect Geometry::GetBoundingBox(Matrix3x2 const& transform) const
{
if (!geo_)
return Rect{};
Rect rect;
Rect bounds;
if (geo_)
{
// no matter it failed or not
geo_->GetBounds(DX::ConvertToMatrix3x2F(transform), DX::ConvertToRectF(&rect));
return rect;
geo_->GetBounds(DX::ConvertToMatrix3x2F(transform), DX::ConvertToRectF(&bounds));
}
return bounds;
}
Float32 Geometry::GetLength() const

View File

@ -44,9 +44,12 @@ namespace kiwano
bool IsValid() const;
// 삿혤棍학관鍋분
Rect GetBoundingBox() const;
// 삿혤棍학관鍋분
Rect GetBoundingBox(
Matrix3x2 const& transform = Matrix3x2()
Matrix3x2 const& transform
) const;
// 털뙤暠近角뤠관벵듐

View File

@ -391,12 +391,12 @@ namespace kiwano
layout.GetTextStyle().outline_width,
GetStrokeStyle(layout.GetTextStyle().outline_stroke).get()
);
hr = layout.GetTextLayout()->Draw(nullptr, text_renderer_.get(), offset.x, offset.y);
}
if (SUCCEEDED(hr))
{
hr = layout.GetTextLayout()->Draw(nullptr, text_renderer_.get(), offset.x, offset.y);
IncreasePrimitivesCount();
}

View File

@ -190,6 +190,8 @@ namespace kiwano
Int32 primitives;
Time start;
Duration duration;
Status() : primitives(0) {}
};
void SetCollectingStatus(bool collecting);

View File

@ -198,7 +198,7 @@ namespace kiwano
sFillColor_ = fillColor;
bShowOutline_ = outline;
sOutlineColor_ = outlineColor;
fOutlineWidth = 2 * outlineWidth;
fOutlineWidth = outlineWidth;
pCurrStrokeStyle_ = outlineJoin;
if (pBrush_) pBrush_->SetOpacity(opacity);
@ -220,18 +220,21 @@ namespace kiwano
HRESULT hr = S_OK;
if (bShowOutline_)
{
ID2D1GeometrySink* pSink = NULL;
ID2D1PathGeometry* pPathGeometry = NULL;
ID2D1TransformedGeometry* pTransformedGeometry = NULL;
hr = pFactory_->CreatePathGeometry(
&pPathGeometry
);
ID2D1GeometrySink* pSink = NULL;
if (SUCCEEDED(hr))
{
hr = pPathGeometry->Open(
&pSink
);
}
if (SUCCEEDED(hr))
{
@ -252,13 +255,14 @@ namespace kiwano
hr = pSink->Close();
}
if (SUCCEEDED(hr))
{
D2D1::Matrix3x2F const matrix = D2D1::Matrix3x2F(
1.0f, 0.0f,
0.0f, 1.0f,
baselineOriginX, baselineOriginY
);
ID2D1TransformedGeometry* pTransformedGeometry = NULL;
if (SUCCEEDED(hr))
{
hr = pFactory_->CreateTransformedGeometry(
@ -268,32 +272,35 @@ namespace kiwano
);
}
if (SUCCEEDED(hr) && bShowOutline_)
if (SUCCEEDED(hr))
{
pBrush_->SetColor(sOutlineColor_);
pRT_->DrawGeometry(
pTransformedGeometry,
pBrush_,
fOutlineWidth,
fOutlineWidth * 2, // twice width for widening
pCurrStrokeStyle_
);
}
}
}
DX::SafeRelease(pPathGeometry);
DX::SafeRelease(pSink);
DX::SafeRelease(pTransformedGeometry);
}
if (SUCCEEDED(hr))
{
pBrush_->SetColor(sFillColor_);
pRT_->FillGeometry(
pTransformedGeometry,
pRT_->DrawGlyphRun(
D2D1::Point2F(baselineOriginX, baselineOriginY),
glyphRun,
pBrush_
);
}
DX::SafeRelease(pPathGeometry);
DX::SafeRelease(pSink);
DX::SafeRelease(pTransformedGeometry);
return hr;
}