fade DebugNode when mouse over it, may be helpful :)
minor
This commit is contained in:
parent
d6c6533d39
commit
bda157c38a
|
|
@ -132,6 +132,7 @@ namespace kiwano
|
||||||
text_style_ = text_style;
|
text_style_ = text_style;
|
||||||
|
|
||||||
text_renderer_->SetTextStyle(
|
text_renderer_->SetTextStyle(
|
||||||
|
1.f,
|
||||||
DX::ConvertToColorF(text_style_.color),
|
DX::ConvertToColorF(text_style_.color),
|
||||||
text_style_.outline,
|
text_style_.outline,
|
||||||
DX::ConvertToColorF(text_style_.outline_color),
|
DX::ConvertToColorF(text_style_.outline_color),
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,15 @@
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
DebugNode::DebugNode()
|
DebugNode::DebugNode()
|
||||||
|
: background_color_(0.0f, 0.0f, 0.0f, 0.7f)
|
||||||
{
|
{
|
||||||
|
SetName(L"kiwano-debug-node");
|
||||||
|
SetPosition(10, 10);
|
||||||
|
SetResponsible(true);
|
||||||
|
SetCascadeOpacityEnabled(true);
|
||||||
|
|
||||||
debug_text_ = new Text;
|
debug_text_ = new Text;
|
||||||
debug_text_->SetPosition(20, 20);
|
debug_text_->SetPosition(10, 10);
|
||||||
this->AddChild(debug_text_);
|
this->AddChild(debug_text_);
|
||||||
|
|
||||||
Font font;
|
Font font;
|
||||||
|
|
@ -43,6 +49,11 @@ namespace kiwano
|
||||||
style.wrap = false;
|
style.wrap = false;
|
||||||
style.line_spacing = 20.f;
|
style.line_spacing = 20.f;
|
||||||
debug_text_->SetStyle(style);
|
debug_text_->SetStyle(style);
|
||||||
|
|
||||||
|
AddListener(Event::MouseHover, [=](const Event&) {
|
||||||
|
SetOpacity(0.4f);
|
||||||
|
});
|
||||||
|
AddListener(Event::MouseOut, [=](const Event&) { SetOpacity(1.f); });
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugNode::~DebugNode()
|
DebugNode::~DebugNode()
|
||||||
|
|
@ -51,11 +62,10 @@ namespace kiwano
|
||||||
|
|
||||||
void DebugNode::OnRender()
|
void DebugNode::OnRender()
|
||||||
{
|
{
|
||||||
Renderer::Instance()->SetTransform(Matrix{});
|
Renderer::Instance()->GetSolidColorBrush()->SetColor(DX::ConvertToColorF(background_color_));
|
||||||
Renderer::Instance()->GetSolidColorBrush()->SetColor(D2D1::ColorF(0.0f, 0.0f, 0.0f, 0.5f));
|
|
||||||
|
|
||||||
Renderer::Instance()->GetD2DDeviceResources()->GetDeviceContext()->FillRectangle(
|
Renderer::Instance()->GetD2DDeviceResources()->GetDeviceContext()->FillRoundedRectangle(
|
||||||
D2D1_RECT_F{ 10, 10, 30 + debug_text_->GetLayoutSize().x, 30 + debug_text_->GetLayoutSize().y },
|
D2D1::RoundedRect(DX::ConvertToRectF(GetBounds()), 5.f, 5.f),
|
||||||
Renderer::Instance()->GetSolidColorBrush()
|
Renderer::Instance()->GetSolidColorBrush()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -73,8 +83,11 @@ namespace kiwano
|
||||||
std::wstringstream ss;
|
std::wstringstream ss;
|
||||||
ss << "Fps: " << frame_time_.size() << std::endl;
|
ss << "Fps: " << frame_time_.size() << std::endl;
|
||||||
|
|
||||||
#ifdef KGE_DEBUG
|
#if defined(KGE_DEBUG)
|
||||||
|
if (Object::IsTracingLeaks())
|
||||||
|
{
|
||||||
ss << "Objects: " << Object::__GetTracingObjects().size() << std::endl;
|
ss << "Objects: " << Object::__GetTracingObjects().size() << std::endl;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ss << "Render: " << Renderer::Instance()->GetStatus().duration.Milliseconds() << "ms" << std::endl;
|
ss << "Render: " << Renderer::Instance()->GetStatus().duration.Milliseconds() << "ms" << std::endl;
|
||||||
|
|
@ -86,6 +99,7 @@ namespace kiwano
|
||||||
ss << "Memory: " << pmc.PrivateUsage / 1024 << "kb";
|
ss << "Memory: " << pmc.PrivateUsage / 1024 << "kb";
|
||||||
|
|
||||||
debug_text_->SetText(ss.str());
|
debug_text_->SetText(ss.str());
|
||||||
|
SetSize(Size{ 20 + debug_text_->GetLayoutSize().x, 20 + debug_text_->GetLayoutSize().y });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
class KGE_API DebugNode
|
class KGE_API DebugNode
|
||||||
: public Node
|
: public VisualNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DebugNode();
|
DebugNode();
|
||||||
|
|
@ -36,6 +36,7 @@ namespace kiwano
|
||||||
void OnUpdate(Duration dt) override;
|
void OnUpdate(Duration dt) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Color background_color_;
|
||||||
TextPtr debug_text_;
|
TextPtr debug_text_;
|
||||||
Array<Time> frame_time_;
|
Array<Time> frame_time_;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -304,6 +304,7 @@ namespace kiwano
|
||||||
if (text_layout_)
|
if (text_layout_)
|
||||||
{
|
{
|
||||||
Renderer::Instance()->SetTextStyle(
|
Renderer::Instance()->SetTextStyle(
|
||||||
|
GetDisplayedOpacity(),
|
||||||
style_.color,
|
style_.color,
|
||||||
style_.outline,
|
style_.outline,
|
||||||
style_.outline_color,
|
style_.outline_color,
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,11 @@ namespace kiwano
|
||||||
name.c_str(), GetObjectID(), GetRefCount(), GetName().c_str());
|
name.c_str(), GetObjectID(), GetRefCount(), GetName().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Object::IsTracingLeaks()
|
||||||
|
{
|
||||||
|
return tracing_leaks;
|
||||||
|
}
|
||||||
|
|
||||||
void Object::StartTracingLeaks()
|
void Object::StartTracingLeaks()
|
||||||
{
|
{
|
||||||
tracing_leaks = true;
|
tracing_leaks = true;
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,8 @@ namespace kiwano
|
||||||
String DumpObject();
|
String DumpObject();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static bool IsTracingLeaks();
|
||||||
|
|
||||||
static void StartTracingLeaks();
|
static void StartTracingLeaks();
|
||||||
|
|
||||||
static void StopTracingLeaks();
|
static void StopTracingLeaks();
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@
|
||||||
#include "modules.h"
|
#include "modules.h"
|
||||||
#include "../base/logs.h"
|
#include "../base/logs.h"
|
||||||
#include "../base/input.h"
|
#include "../base/input.h"
|
||||||
#include "../base/Event.hpp"
|
|
||||||
#include "../renderer/render.h"
|
#include "../renderer/render.h"
|
||||||
#include "../2d/Scene.h"
|
#include "../2d/Scene.h"
|
||||||
#include "../2d/DebugNode.h"
|
#include "../2d/DebugNode.h"
|
||||||
|
|
@ -135,6 +134,8 @@ namespace kiwano
|
||||||
curr_scene_.Reset();
|
curr_scene_.Reset();
|
||||||
debug_node_.Reset();
|
debug_node_.Reset();
|
||||||
|
|
||||||
|
OnDestroy();
|
||||||
|
|
||||||
if (inited_)
|
if (inited_)
|
||||||
{
|
{
|
||||||
inited_ = false;
|
inited_ = false;
|
||||||
|
|
@ -147,10 +148,12 @@ namespace kiwano
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy all instances
|
// Destroy all instances
|
||||||
Renderer::Destroy();
|
|
||||||
Input::Destroy();
|
Input::Destroy();
|
||||||
|
Renderer::Destroy();
|
||||||
Window::Destroy();
|
Window::Destroy();
|
||||||
Logger::Destroy();
|
|
||||||
|
// DO NOT destroy Logger instance manually
|
||||||
|
// Logger::Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::Use(Component* component)
|
void Application::Use(Component* component)
|
||||||
|
|
@ -234,6 +237,15 @@ namespace kiwano
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::Dispatch(Event& evt)
|
||||||
|
{
|
||||||
|
if (debug_node_)
|
||||||
|
debug_node_->Dispatch(evt);
|
||||||
|
|
||||||
|
if (curr_scene_)
|
||||||
|
curr_scene_->Dispatch(evt);
|
||||||
|
}
|
||||||
|
|
||||||
void Application::Update()
|
void Application::Update()
|
||||||
{
|
{
|
||||||
static auto last = Time::Now();
|
static auto last = Time::Now();
|
||||||
|
|
@ -381,7 +393,7 @@ namespace kiwano
|
||||||
evt.key.code = static_cast<int>(wparam);
|
evt.key.code = static_cast<int>(wparam);
|
||||||
evt.key.count = static_cast<int>(lparam & 0xFF);
|
evt.key.count = static_cast<int>(lparam & 0xFF);
|
||||||
|
|
||||||
app->curr_scene_->Dispatch(evt);
|
app->Dispatch(evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -394,7 +406,7 @@ namespace kiwano
|
||||||
evt.key.c = static_cast<char>(wparam);
|
evt.key.c = static_cast<char>(wparam);
|
||||||
evt.key.count = static_cast<int>(lparam & 0xFF);
|
evt.key.count = static_cast<int>(lparam & 0xFF);
|
||||||
|
|
||||||
app->curr_scene_->Dispatch(evt);
|
app->Dispatch(evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -429,7 +441,7 @@ namespace kiwano
|
||||||
else if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONUP) { evt.mouse.button = MouseButton::Right; }
|
else if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONUP) { evt.mouse.button = MouseButton::Right; }
|
||||||
else if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONUP) { evt.mouse.button = MouseButton::Middle; }
|
else if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONUP) { evt.mouse.button = MouseButton::Middle; }
|
||||||
|
|
||||||
app->curr_scene_->Dispatch(evt);
|
app->Dispatch(evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -449,7 +461,7 @@ namespace kiwano
|
||||||
Event evt(Event::WindowResized);
|
Event evt(Event::WindowResized);
|
||||||
evt.win.width = LOWORD(lparam);
|
evt.win.width = LOWORD(lparam);
|
||||||
evt.win.height = HIWORD(lparam);
|
evt.win.height = HIWORD(lparam);
|
||||||
app->curr_scene_->Dispatch(evt);
|
app->Dispatch(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::Instance()->UpdateWindowRect();
|
Window::Instance()->UpdateWindowRect();
|
||||||
|
|
@ -467,7 +479,7 @@ namespace kiwano
|
||||||
Event evt(Event::WindowMoved);
|
Event evt(Event::WindowMoved);
|
||||||
evt.win.x = x;
|
evt.win.x = x;
|
||||||
evt.win.y = y;
|
evt.win.y = y;
|
||||||
app->curr_scene_->Dispatch(evt);
|
app->Dispatch(evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -482,7 +494,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
Event evt(Event::WindowFocusChanged);
|
Event evt(Event::WindowFocusChanged);
|
||||||
evt.win.focus = active;
|
evt.win.focus = active;
|
||||||
app->curr_scene_->Dispatch(evt);
|
app->Dispatch(evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -495,7 +507,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
Event evt(Event::WindowTitleChanged);
|
Event evt(Event::WindowTitleChanged);
|
||||||
evt.win.title = reinterpret_cast<const wchar_t*>(lparam);
|
evt.win.title = reinterpret_cast<const wchar_t*>(lparam);
|
||||||
app->curr_scene_->Dispatch(evt);
|
app->Dispatch(evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -532,11 +544,9 @@ namespace kiwano
|
||||||
if (app->curr_scene_)
|
if (app->curr_scene_)
|
||||||
{
|
{
|
||||||
Event evt(Event::WindowClosed);
|
Event evt(Event::WindowClosed);
|
||||||
app->curr_scene_->Dispatch(evt);
|
app->Dispatch(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
app->OnDestroy();
|
|
||||||
|
|
||||||
::PostQuitMessage(0);
|
::PostQuitMessage(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
#include "../base/time.h"
|
#include "../base/time.h"
|
||||||
#include "../base/window.h"
|
#include "../base/window.h"
|
||||||
#include "../base/Component.h"
|
#include "../base/Component.h"
|
||||||
|
#include "../base/Event.hpp"
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
@ -127,6 +128,9 @@ namespace kiwano
|
||||||
bool show = true
|
bool show = true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 分发事件
|
||||||
|
void Dispatch(Event& evt);
|
||||||
|
|
||||||
// 在 Kiwano 主线程中执行函数
|
// 在 Kiwano 主线程中执行函数
|
||||||
// 当在其他线程调用 Kiwano 函数时使用
|
// 当在其他线程调用 Kiwano 函数时使用
|
||||||
static void PreformInMainThread(
|
static void PreformInMainThread(
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ namespace kiwano
|
||||||
STDMETHOD(CreateDeviceResources)();
|
STDMETHOD(CreateDeviceResources)();
|
||||||
|
|
||||||
STDMETHOD_(void, SetTextStyle)(
|
STDMETHOD_(void, SetTextStyle)(
|
||||||
|
FLOAT opacity,
|
||||||
CONST D2D1_COLOR_F &fillColor,
|
CONST D2D1_COLOR_F &fillColor,
|
||||||
BOOL outline,
|
BOOL outline,
|
||||||
CONST D2D1_COLOR_F &outlineColor,
|
CONST D2D1_COLOR_F &outlineColor,
|
||||||
|
|
@ -154,10 +155,13 @@ namespace kiwano
|
||||||
, fOutlineWidth(1)
|
, fOutlineWidth(1)
|
||||||
, bShowOutline_(TRUE)
|
, bShowOutline_(TRUE)
|
||||||
, pCurrStrokeStyle_(NULL)
|
, pCurrStrokeStyle_(NULL)
|
||||||
|
{
|
||||||
|
if (pRT_)
|
||||||
{
|
{
|
||||||
pRT_->AddRef();
|
pRT_->AddRef();
|
||||||
pRT_->GetFactory(&pFactory_);
|
pRT_->GetFactory(&pFactory_);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TextRenderer::~TextRenderer()
|
TextRenderer::~TextRenderer()
|
||||||
{
|
{
|
||||||
|
|
@ -172,15 +176,19 @@ namespace kiwano
|
||||||
|
|
||||||
DX::SafeRelease(pBrush_);
|
DX::SafeRelease(pBrush_);
|
||||||
|
|
||||||
|
if (pRT_)
|
||||||
|
{
|
||||||
hr = pRT_->CreateSolidColorBrush(
|
hr = pRT_->CreateSolidColorBrush(
|
||||||
D2D1::ColorF(D2D1::ColorF::White),
|
D2D1::ColorF(D2D1::ColorF::White),
|
||||||
&pBrush_
|
&pBrush_
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
STDMETHODIMP_(void) TextRenderer::SetTextStyle(
|
STDMETHODIMP_(void) TextRenderer::SetTextStyle(
|
||||||
|
FLOAT opacity,
|
||||||
CONST D2D1_COLOR_F &fillColor,
|
CONST D2D1_COLOR_F &fillColor,
|
||||||
BOOL outline,
|
BOOL outline,
|
||||||
CONST D2D1_COLOR_F &outlineColor,
|
CONST D2D1_COLOR_F &outlineColor,
|
||||||
|
|
@ -192,6 +200,8 @@ namespace kiwano
|
||||||
sOutlineColor_ = outlineColor;
|
sOutlineColor_ = outlineColor;
|
||||||
fOutlineWidth = 2 * outlineWidth;
|
fOutlineWidth = 2 * outlineWidth;
|
||||||
pCurrStrokeStyle_ = outlineJoin;
|
pCurrStrokeStyle_ = outlineJoin;
|
||||||
|
|
||||||
|
if (pBrush_) pBrush_->SetOpacity(opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
STDMETHODIMP TextRenderer::DrawGlyphRun(
|
STDMETHODIMP TextRenderer::DrawGlyphRun(
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ namespace kiwano
|
||||||
);
|
);
|
||||||
|
|
||||||
STDMETHOD_(void, SetTextStyle)(
|
STDMETHOD_(void, SetTextStyle)(
|
||||||
|
FLOAT opacity,
|
||||||
CONST D2D1_COLOR_F &fillColor,
|
CONST D2D1_COLOR_F &fillColor,
|
||||||
BOOL outline,
|
BOOL outline,
|
||||||
CONST D2D1_COLOR_F &outlineColor,
|
CONST D2D1_COLOR_F &outlineColor,
|
||||||
|
|
|
||||||
|
|
@ -447,6 +447,7 @@ namespace kiwano
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Renderer::SetTextStyle(
|
HRESULT Renderer::SetTextStyle(
|
||||||
|
float opacity,
|
||||||
Color const& color,
|
Color const& color,
|
||||||
bool has_outline,
|
bool has_outline,
|
||||||
Color const& outline_color,
|
Color const& outline_color,
|
||||||
|
|
@ -458,6 +459,7 @@ namespace kiwano
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
text_renderer_->SetTextStyle(
|
text_renderer_->SetTextStyle(
|
||||||
|
opacity,
|
||||||
DX::ConvertToColorF(color),
|
DX::ConvertToColorF(color),
|
||||||
has_outline,
|
has_outline,
|
||||||
DX::ConvertToColorF(outline_color),
|
DX::ConvertToColorF(outline_color),
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,7 @@ namespace kiwano
|
||||||
);
|
);
|
||||||
|
|
||||||
HRESULT SetTextStyle(
|
HRESULT SetTextStyle(
|
||||||
|
float opacity,
|
||||||
const Color& color,
|
const Color& color,
|
||||||
bool has_outline,
|
bool has_outline,
|
||||||
const Color& outline_color,
|
const Color& outline_color,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue