add Layer::SetSwallowEvents

minor optimize
This commit is contained in:
Nomango 2019-04-20 00:21:44 +08:00 committed by Nomango
parent e1c8dbf6eb
commit 050b1a504e
4 changed files with 25 additions and 12 deletions

View File

@ -25,17 +25,20 @@
namespace kiwano namespace kiwano
{ {
Layer::Layer() Layer::Layer()
: swallow_(false)
{ {
SetSize(Renderer::Instance().GetOutputSize()); SetSize(Renderer::Instance().GetOutputSize());
AddListener(Event::MouseBtnDown, MakeClosure(this, &Layer::HandleMessages)); auto handler = MakeClosure(this, &Layer::HandleMessages);
AddListener(Event::MouseBtnUp, MakeClosure(this, &Layer::HandleMessages));
AddListener(Event::MouseMove, MakeClosure(this, &Layer::HandleMessages));
AddListener(Event::MouseWheel, MakeClosure(this, &Layer::HandleMessages));
AddListener(Event::KeyDown, MakeClosure(this, &Layer::HandleMessages)); AddListener(Event::MouseBtnDown, handler);
AddListener(Event::KeyUp, MakeClosure(this, &Layer::HandleMessages)); AddListener(Event::MouseBtnUp, handler);
AddListener(Event::Char, MakeClosure(this, &Layer::HandleMessages)); AddListener(Event::MouseMove, handler);
AddListener(Event::MouseWheel, handler);
AddListener(Event::KeyDown, handler);
AddListener(Event::KeyUp, handler);
AddListener(Event::Char, handler);
} }
Layer::~Layer() Layer::~Layer()
@ -47,11 +50,14 @@ namespace kiwano
if (!IsVisible()) if (!IsVisible())
return; return;
NodePtr prev; if (!swallow_)
for (auto child = children_.Last(); child; child = prev)
{ {
prev = child->PrevItem(); NodePtr prev;
child->Dispatch(evt); for (auto child = children_.Last(); child; child = prev)
{
prev = child->PrevItem();
child->Dispatch(evt);
}
} }
EventDispatcher::Dispatch(evt); EventDispatcher::Dispatch(evt);

View File

@ -40,10 +40,16 @@ namespace kiwano
virtual void OnKeyUp(int key) {} virtual void OnKeyUp(int key) {}
virtual void OnChar(char c) {} virtual void OnChar(char c) {}
// ÍÌûÏûÏ¢
inline void SetSwallowEvents(bool enabled) { swallow_ = enabled; }
public: public:
void Dispatch(Event& evt) override; void Dispatch(Event& evt) override;
protected: protected:
void HandleMessages(Event const& evt); void HandleMessages(Event const& evt);
protected:
bool swallow_;
}; };
} }

View File

@ -35,6 +35,7 @@ namespace kiwano
ImGuiLayer::ImGuiLayer() ImGuiLayer::ImGuiLayer()
{ {
target_window_ = Renderer::Instance().GetTargetWindow(); target_window_ = Renderer::Instance().GetTargetWindow();
SetSwallowEvents(true);
} }
ImGuiLayer::~ImGuiLayer() ImGuiLayer::~ImGuiLayer()

View File

@ -41,7 +41,7 @@ namespace
// write data maybe called more than once in a single request // write data maybe called more than once in a single request
recv_buffer->append((char*)buffer, total); recv_buffer->append((char*)buffer, total);
return total; return total;
} }
std::string convert_to_utf8(String const& str) std::string convert_to_utf8(String const& str)