[aseprite] 120/308: Restore selected ButtonSet item when we offer the mouse capture

Tobias Hansen thansen at moszumanska.debian.org
Tue Mar 8 02:44:59 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit 1f513a1ed5ff610c90f349eaec4efa55ce5de9e9
Author: David Capello <davidcapello at gmail.com>
Date:   Wed Dec 16 16:55:49 2015 -0300

    Restore selected ButtonSet item when we offer the mouse capture
    
    When a ButtonSet triggers an onClick() when a mouse up message is received
    (ButtonSet::m_multipleSelection == true), in case the mouse capture is
    offered to other ButtonSet, we've to restore the selected item when we
    capture the mouse, because we've never generated the onClick() event
    in the first place.
---
 src/app/ui/brush_popup.cpp |  1 +
 src/app/ui/button_set.cpp  | 31 +++++++++++++++++++++++++++++--
 src/ui/widget.cpp          |  4 +++-
 src/ui/widget.h            |  5 +++--
 4 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/src/app/ui/brush_popup.cpp b/src/app/ui/brush_popup.cpp
index 3336751..3eec4aa 100644
--- a/src/app/ui/brush_popup.cpp
+++ b/src/app/ui/brush_popup.cpp
@@ -219,6 +219,7 @@ BrushPopup::BrushPopup(BrushPopupDelegate* delegate)
   setBorder(gfx::Border(2)*guiscale());
   setChildSpacing(0);
   m_box.noBorderNoChildSpacing();
+  m_standardBrushes.setTriggerOnMouseUp(true);
 
   addChild(&m_box);
 
diff --git a/src/app/ui/button_set.cpp b/src/app/ui/button_set.cpp
index 60d7277..16f2d20 100644
--- a/src/app/ui/button_set.cpp
+++ b/src/app/ui/button_set.cpp
@@ -33,6 +33,10 @@ namespace app {
 using namespace ui;
 using namespace app::skin;
 
+// Last selected item for ButtonSet activated on mouse up when the
+// mouse capture is get.
+static int g_itemBeforeCapture = -1;
+
 WidgetType buttonset_item_type()
 {
   static WidgetType type = kGenericWidget;
@@ -172,6 +176,15 @@ bool ButtonSet::Item::onProcessMessage(ui::Message* msg)
       break;
 
     case ui::kMouseDownMessage:
+      // Only for single-item and trigerred on mouse up ButtonSets: We
+      // save the current selected item to restore it just in case the
+      // user leaves the ButtonSet without releasing the mouse button
+      // and the mouse capture if offered to other ButtonSet.
+      if (buttonSet()->m_triggerOnMouseUp) {
+        ASSERT(g_itemBeforeCapture < 0);
+        g_itemBeforeCapture = buttonSet()->selectedItem();
+      }
+
       captureMouse();
       buttonSet()->setSelectedItem(this);
       invalidate();
@@ -184,6 +197,9 @@ bool ButtonSet::Item::onProcessMessage(ui::Message* msg)
 
     case ui::kMouseUpMessage:
       if (hasCapture()) {
+        if (g_itemBeforeCapture >= 0)
+          g_itemBeforeCapture = -1;
+
         releaseMouse();
         invalidate();
 
@@ -199,8 +215,19 @@ bool ButtonSet::Item::onProcessMessage(ui::Message* msg)
 
     case ui::kMouseMoveMessage:
       if (hasCapture()) {
-        if (buttonSet()->m_offerCapture)
-          offerCapture(static_cast<ui::MouseMessage*>(msg), buttonset_item_type());
+        if (buttonSet()->m_offerCapture) {
+          if (offerCapture(static_cast<ui::MouseMessage*>(msg), buttonset_item_type())) {
+            // Only for ButtonSets trigerred on mouse up.
+            if (buttonSet()->m_triggerOnMouseUp &&
+                g_itemBeforeCapture >= 0) {
+              // As we never received a kMouseUpMessage (so we never
+              // called onClick()), we have to restore the selected
+              // item at the point when we received the mouse capture.
+              buttonSet()->setSelectedItem(g_itemBeforeCapture);
+              g_itemBeforeCapture = -1;
+            }
+          }
+        }
       }
       break;
 
diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp
index de2033b..5266fa0 100644
--- a/src/ui/widget.cpp
+++ b/src/ui/widget.cpp
@@ -1236,7 +1236,7 @@ void Widget::releaseMouse()
   }
 }
 
-void Widget::offerCapture(ui::MouseMessage* mouseMsg, int widget_type)
+bool Widget::offerCapture(ui::MouseMessage* mouseMsg, int widget_type)
 {
   if (hasCapture()) {
     Widget* pick = manager()->pick(mouseMsg->position());
@@ -1250,8 +1250,10 @@ void Widget::offerCapture(ui::MouseMessage* mouseMsg, int widget_type)
         mouseMsg->position());
       mouseMsg2->addRecipient(pick);
       manager()->enqueueMessage(mouseMsg2);
+      return true;
     }
   }
+  return false;
 }
 
 bool Widget::hasFocus()
diff --git a/src/ui/widget.h b/src/ui/widget.h
index c41839d..0d48ac7 100644
--- a/src/ui/widget.h
+++ b/src/ui/widget.h
@@ -340,8 +340,9 @@ namespace ui {
     bool hasMouseOver();
     bool hasCapture();
 
-    // Offer the capture to widgets of the given type
-    void offerCapture(ui::MouseMessage* mouseMsg, int widget_type);
+    // Offer the capture to widgets of the given type. Returns true if
+    // the capture was passed to other widget.
+    bool offerCapture(ui::MouseMessage* mouseMsg, int widget_type);
 
     // Returns lower-case letter that represet the mnemonic of the widget
     // (the underscored character, i.e. the letter after & symbol).

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list