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