Add ui::IGNORE_MOUSE flag for static widgets

This avoids some MouseEnter/Leave messages between widgets that don't
need them.
This commit is contained in:
David Capello 2018-12-13 10:48:12 -03:00
parent 105d389fdc
commit 06352f79e8
13 changed files with 34 additions and 4 deletions

View File

@ -1,4 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -300,6 +301,7 @@ ButtonSet::ButtonSet(int columns)
, m_triggerOnMouseUp(false) , m_triggerOnMouseUp(false)
, m_multipleSelection(false) , m_multipleSelection(false)
{ {
enableFlags(IGNORE_MOUSE);
InitTheme.connect( InitTheme.connect(
[this]{ [this]{
noBorderNoChildSpacing(); noBorderNoChildSpacing();

View File

@ -1,4 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -41,6 +42,7 @@ Workspace::Workspace()
, m_dropPreviewPanel(nullptr) , m_dropPreviewPanel(nullptr)
, m_dropPreviewTabs(nullptr) , m_dropPreviewTabs(nullptr)
{ {
enableFlags(IGNORE_MOUSE);
addChild(&m_mainPanel); addChild(&m_mainPanel);
InitTheme.connect( InitTheme.connect(

View File

@ -1,4 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -47,6 +48,7 @@ WorkspacePanel::WorkspacePanel(PanelType panelType)
, m_topTime(0) , m_topTime(0)
, m_bottomTime(0) , m_bottomTime(0)
{ {
enableFlags(IGNORE_MOUSE);
InitTheme.connect( InitTheme.connect(
[this]{ [this]{
SkinTheme* theme = static_cast<SkinTheme*>(this->theme()); SkinTheme* theme = static_cast<SkinTheme*>(this->theme());

View File

@ -1,4 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello // Copyright (C) 2001-2016 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -50,7 +51,8 @@ namespace ui {
DOUBLE_BUFFERED = 0x00002000, // The widget is painted in a back-buffer and then flipped to the main display DOUBLE_BUFFERED = 0x00002000, // The widget is painted in a back-buffer and then flipped to the main display
TRANSPARENT = 0x00004000, // The widget has transparent parts that needs the background painted before TRANSPARENT = 0x00004000, // The widget has transparent parts that needs the background painted before
CTRL_RIGHT_CLICK = 0x00008000, // The widget should transform Ctrl+click to right-click on OS X. CTRL_RIGHT_CLICK = 0x00008000, // The widget should transform Ctrl+click to right-click on OS X.
PROPERTIES_MASK = 0x0000ffff, IGNORE_MOUSE = 0x80000000, // Don't process mouse messages for this widget (useful for labels, boxes, grids, etc.)
PROPERTIES_MASK = 0x8000ffff,
HORIZONTAL = 0x00010000, HORIZONTAL = 0x00010000,
VERTICAL = 0x00020000, VERTICAL = 0x00020000,
@ -62,7 +64,7 @@ namespace ui {
BOTTOM = 0x00800000, BOTTOM = 0x00800000,
HOMOGENEOUS = 0x01000000, HOMOGENEOUS = 0x01000000,
WORDWRAP = 0x02000000, WORDWRAP = 0x02000000,
ALIGN_MASK = 0xffff0000, ALIGN_MASK = 0x7fff0000,
}; };
} // namespace ui } // namespace ui

View File

@ -1,4 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -22,6 +23,7 @@ using namespace gfx;
Box::Box(int align) Box::Box(int align)
: Widget(kBoxWidget) : Widget(kBoxWidget)
{ {
enableFlags(IGNORE_MOUSE);
setAlign(align); setAlign(align);
initTheme(); initTheme();
} }

View File

@ -1,4 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -42,6 +43,8 @@ Grid::Grid(int columns, bool same_width_columns)
{ {
ASSERT(columns > 0); ASSERT(columns > 0);
enableFlags(IGNORE_MOUSE);
m_same_width_columns = same_width_columns; m_same_width_columns = same_width_columns;
for (std::size_t col=0; col<m_colstrip.size(); ++col) { for (std::size_t col=0; col<m_colstrip.size(); ++col) {

View File

@ -1,4 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -19,6 +20,7 @@ namespace ui {
Label::Label(const std::string& text) Label::Label(const std::string& text)
: Widget(kLabelWidget) : Widget(kLabelWidget)
{ {
enableFlags(IGNORE_MOUSE);
setAlign(LEFT | MIDDLE); setAlign(LEFT | MIDDLE);
setText(text); setText(text);
initTheme(); initTheme();

View File

@ -1,4 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -22,6 +23,7 @@ LinkLabel::LinkLabel(const std::string& urlOrText)
: Label(urlOrText) : Label(urlOrText)
, m_url(urlOrText) , m_url(urlOrText)
{ {
disableFlags(IGNORE_MOUSE);
setType(kLinkLabelWidget); setType(kLinkLabelWidget);
initTheme(); initTheme();
} }
@ -30,6 +32,7 @@ LinkLabel::LinkLabel(const std::string& url, const std::string& text)
: Label(text) : Label(text)
, m_url(url) , m_url(url)
{ {
disableFlags(IGNORE_MOUSE);
setType(kLinkLabelWidget); setType(kLinkLabelWidget);
initTheme(); initTheme();
} }

View File

@ -504,9 +504,14 @@ void Manager::handleMouseMove(const gfx::Point& mousePos,
Widget* widget = nullptr; Widget* widget = nullptr;
for (auto mouseWidget : mouse_widgets_list) { for (auto mouseWidget : mouse_widgets_list) {
widget = mouseWidget->pick(mousePos); widget = mouseWidget->pick(mousePos);
if (widget) if (widget) {
// Get the first ancestor of the picked widget that doesn't
// ignore mouse events.
while (widget && widget->hasFlags(IGNORE_MOUSE))
widget = widget->parent();
break; break;
} }
}
// Fixup "mouse" flag // Fixup "mouse" flag
if (widget != mouse_widget) { if (widget != mouse_widget) {

View File

@ -104,6 +104,7 @@ Menu::Menu()
: Widget(kMenuWidget) : Widget(kMenuWidget)
, m_menuitem(NULL) , m_menuitem(NULL)
{ {
enableFlags(IGNORE_MOUSE);
initTheme(); initTheme();
} }

View File

@ -1,4 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -22,6 +23,7 @@ using namespace gfx;
Separator::Separator(const std::string& text, int align) Separator::Separator(const std::string& text, int align)
: Widget(kSeparatorWidget) : Widget(kSeparatorWidget)
{ {
enableFlags(IGNORE_MOUSE);
setAlign(align); setAlign(align);
if (!text.empty()) if (!text.empty())
setText(text); setText(text);

View File

@ -1,4 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -46,6 +47,7 @@ View::View()
{ {
m_hasBars = true; m_hasBars = true;
enableFlags(IGNORE_MOUSE);
setFocusStop(true); setFocusStop(true);
addChild(&m_viewport); addChild(&m_viewport);
setScrollableSize(Size(0, 0)); setScrollableSize(Size(0, 0));

View File

@ -1,5 +1,6 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2001-2013, 2015 David Capello // Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -24,6 +25,7 @@ using namespace gfx;
Viewport::Viewport() Viewport::Viewport()
: Widget(kViewViewportWidget) : Widget(kViewViewportWidget)
{ {
enableFlags(IGNORE_MOUSE);
initTheme(); initTheme();
} }