add Node::ShowBorder(), may be useful for debug
This commit is contained in:
parent
c523a138d4
commit
2f2cbcd4f1
|
|
@ -47,6 +47,8 @@ namespace kiwano
|
||||||
, dirty_transform_(false)
|
, dirty_transform_(false)
|
||||||
, dirty_transform_inverse_(false)
|
, dirty_transform_inverse_(false)
|
||||||
, cascade_opacity_(false)
|
, cascade_opacity_(false)
|
||||||
|
, show_border_(false)
|
||||||
|
, is_fast_transform_(true)
|
||||||
, parent_(nullptr)
|
, parent_(nullptr)
|
||||||
, scene_(nullptr)
|
, scene_(nullptr)
|
||||||
, hash_name_(0)
|
, hash_name_(0)
|
||||||
|
|
@ -117,6 +119,22 @@ namespace kiwano
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Node::RenderBorder()
|
||||||
|
{
|
||||||
|
if (show_border_)
|
||||||
|
{
|
||||||
|
Rect bounds = GetBounds();
|
||||||
|
Renderer::Instance()->SetTransform(transform_matrix_);
|
||||||
|
Renderer::Instance()->FillRectangle(bounds, Color(Color::Red, .4f));
|
||||||
|
Renderer::Instance()->DrawRectangle(bounds, Color(Color::Red, .8f), 4.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto child = children_.First(); child; child = child->NextItem())
|
||||||
|
{
|
||||||
|
child->RenderBorder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Node::Dispatch(Event& evt)
|
void Node::Dispatch(Event& evt)
|
||||||
{
|
{
|
||||||
if (!visible_)
|
if (!visible_)
|
||||||
|
|
|
||||||
|
|
@ -392,7 +392,10 @@ namespace kiwano
|
||||||
inline void SetCallbackOnUpdate(UpdateCallback const& cb) { cb_update_ = cb; }
|
inline void SetCallbackOnUpdate(UpdateCallback const& cb) { cb_update_ = cb; }
|
||||||
|
|
||||||
// 获取更新时的回调函数
|
// 获取更新时的回调函数
|
||||||
inline UpdateCallback const& GetCallbackOnUpdate() { return cb_update_; }
|
inline UpdateCallback GetCallbackOnUpdate() const { return cb_update_; }
|
||||||
|
|
||||||
|
// 渲染节点边界
|
||||||
|
inline void ShowBorder(bool show) { show_border_ = show; }
|
||||||
|
|
||||||
// 设置默认锚点
|
// 设置默认锚点
|
||||||
static void SetDefaultAnchor(
|
static void SetDefaultAnchor(
|
||||||
|
|
@ -409,16 +412,18 @@ namespace kiwano
|
||||||
|
|
||||||
virtual void Update(Duration dt);
|
virtual void Update(Duration dt);
|
||||||
|
|
||||||
void Render();
|
virtual void Render();
|
||||||
|
|
||||||
|
void RenderBorder();
|
||||||
|
|
||||||
void UpdateTransform() const;
|
void UpdateTransform() const;
|
||||||
|
|
||||||
void UpdateOpacity();
|
void UpdateOpacity();
|
||||||
|
|
||||||
void SetScene(Scene* scene);
|
|
||||||
|
|
||||||
void Reorder();
|
void Reorder();
|
||||||
|
|
||||||
|
void SetScene(Scene* scene);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool visible_;
|
bool visible_;
|
||||||
bool hover_;
|
bool hover_;
|
||||||
|
|
@ -426,6 +431,7 @@ namespace kiwano
|
||||||
bool responsible_;
|
bool responsible_;
|
||||||
bool update_pausing_;
|
bool update_pausing_;
|
||||||
bool cascade_opacity_;
|
bool cascade_opacity_;
|
||||||
|
bool show_border_;
|
||||||
int z_order_;
|
int z_order_;
|
||||||
float opacity_;
|
float opacity_;
|
||||||
float displayed_opacity_;
|
float displayed_opacity_;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
Scene::Scene()
|
Scene::Scene()
|
||||||
|
: render_border_enabled_(false)
|
||||||
{
|
{
|
||||||
scene_ = this;
|
scene_ = this;
|
||||||
|
|
||||||
|
|
@ -46,4 +47,14 @@ namespace kiwano
|
||||||
KGE_LOG(L"Scene exited");
|
KGE_LOG(L"Scene exited");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Scene::Render()
|
||||||
|
{
|
||||||
|
Node::Render();
|
||||||
|
|
||||||
|
if (render_border_enabled_)
|
||||||
|
{
|
||||||
|
Node::RenderBorder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,9 @@ namespace kiwano
|
||||||
class KGE_API Scene
|
class KGE_API Scene
|
||||||
: public Node
|
: public Node
|
||||||
{
|
{
|
||||||
|
friend class Transition;
|
||||||
|
friend class Application;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Scene();
|
Scene();
|
||||||
|
|
||||||
|
|
@ -37,5 +40,14 @@ namespace kiwano
|
||||||
|
|
||||||
// 退出场景
|
// 退出场景
|
||||||
virtual void OnExit();
|
virtual void OnExit();
|
||||||
|
|
||||||
|
// 启用或禁用场景内的节点边界渲染功能
|
||||||
|
inline void SetRenderBorderEnabled(bool enabled) { render_border_enabled_ = enabled; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void Render() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool render_border_enabled_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -775,6 +775,7 @@ namespace kiwano
|
||||||
: out(out)
|
: out(out)
|
||||||
, indent_char(indent_char)
|
, indent_char(indent_char)
|
||||||
, indent_string(32, indent_char)
|
, indent_string(32, indent_char)
|
||||||
|
, number_buffer()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void dump(
|
void dump(
|
||||||
|
|
@ -2706,7 +2707,7 @@ namespace std
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline void swap<::kiwano::Json>(::kiwano::Json& lhs, ::kiwano::Json& rhs)
|
inline void swap<::kiwano::Json>(::kiwano::Json& lhs, ::kiwano::Json& rhs) noexcept
|
||||||
{
|
{
|
||||||
lhs.swap(rhs);
|
lhs.swap(rhs);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1377,7 +1377,7 @@ namespace std
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline void swap<::kiwano::String>(::kiwano::String& lhs, ::kiwano::String& rhs)
|
inline void swap<::kiwano::String>(::kiwano::String& lhs, ::kiwano::String& rhs) noexcept
|
||||||
{
|
{
|
||||||
lhs.swap(rhs);
|
lhs.swap(rhs);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -261,6 +261,39 @@ namespace kiwano
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HRESULT Renderer::DrawRectangle(Rect const& rect, const Color& stroke_color, float stroke_width, StrokeStyle stroke)
|
||||||
|
{
|
||||||
|
if (!solid_color_brush_ || !device_context_)
|
||||||
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
|
solid_color_brush_->SetColor(DX::ConvertToColorF(stroke_color));
|
||||||
|
|
||||||
|
device_context_->DrawRectangle(
|
||||||
|
DX::ConvertToRectF(rect),
|
||||||
|
solid_color_brush_.Get(),
|
||||||
|
stroke_width,
|
||||||
|
d2d_res_->GetStrokeStyle(stroke)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (collecting_status_)
|
||||||
|
++status_.primitives;
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT Renderer::FillRectangle(Rect const& rect, Color const& fill_color)
|
||||||
|
{
|
||||||
|
if (!solid_color_brush_ || !device_context_)
|
||||||
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
|
solid_color_brush_->SetColor(DX::ConvertToColorF(fill_color));
|
||||||
|
device_context_->FillRectangle(
|
||||||
|
DX::ConvertToRectF(rect),
|
||||||
|
solid_color_brush_.Get()
|
||||||
|
);
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
HRESULT Renderer::DrawImage(ImagePtr image, Rect const& dest_rect)
|
HRESULT Renderer::DrawImage(ImagePtr image, Rect const& dest_rect)
|
||||||
{
|
{
|
||||||
if (!device_context_)
|
if (!device_context_)
|
||||||
|
|
@ -400,13 +433,17 @@ namespace kiwano
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetOpacity(float opacity)
|
HRESULT Renderer::SetOpacity(float opacity)
|
||||||
{
|
{
|
||||||
|
if (!solid_color_brush_)
|
||||||
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
if (opacity_ != opacity)
|
if (opacity_ != opacity)
|
||||||
{
|
{
|
||||||
opacity_ = opacity;
|
opacity_ = opacity;
|
||||||
solid_color_brush_->SetOpacity(opacity);
|
solid_color_brush_->SetOpacity(opacity);
|
||||||
}
|
}
|
||||||
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Renderer::SetTextStyle(
|
HRESULT Renderer::SetTextStyle(
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,18 @@ namespace kiwano
|
||||||
Color const& fill_color
|
Color const& fill_color
|
||||||
);
|
);
|
||||||
|
|
||||||
|
HRESULT DrawRectangle(
|
||||||
|
Rect const& rect,
|
||||||
|
const Color& stroke_color,
|
||||||
|
float stroke_width,
|
||||||
|
StrokeStyle stroke = StrokeStyle::Miter
|
||||||
|
);
|
||||||
|
|
||||||
|
HRESULT FillRectangle(
|
||||||
|
Rect const& rect,
|
||||||
|
Color const& fill_color
|
||||||
|
);
|
||||||
|
|
||||||
HRESULT DrawImage(
|
HRESULT DrawImage(
|
||||||
ImagePtr image,
|
ImagePtr image,
|
||||||
Rect const& dest_rect
|
Rect const& dest_rect
|
||||||
|
|
@ -103,7 +115,7 @@ namespace kiwano
|
||||||
);
|
);
|
||||||
|
|
||||||
// ÉèÖû±Ê͸Ã÷¶È
|
// ÉèÖû±Ê͸Ã÷¶È
|
||||||
void SetOpacity(
|
HRESULT SetOpacity(
|
||||||
float opacity
|
float opacity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -187,8 +199,6 @@ namespace kiwano
|
||||||
HRESULT EndDraw();
|
HRESULT EndDraw();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned long ref_count_;
|
|
||||||
|
|
||||||
HWND hwnd_;
|
HWND hwnd_;
|
||||||
float opacity_;
|
float opacity_;
|
||||||
bool antialias_;
|
bool antialias_;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue