[Bf-blender-cvs] [6f054f5ac73] master: Fix T83935: Superimposed icon's hotspot is misaligned

Yevgeny Makarov noreply at git.blender.org
Thu Jan 28 12:35:02 CET 2021


Commit: 6f054f5ac73a1a6bff434efb1e15aea40c2e0647
Author: Yevgeny Makarov
Date:   Thu Jan 28 12:33:46 2021 +0100
Branches: master
https://developer.blender.org/rB6f054f5ac73a1a6bff434efb1e15aea40c2e0647

Fix T83935: Superimposed icon's hotspot is misaligned

Now the icon's rect are drawn wider than it should be, and with
overlapping, probably in order to compensate for the icon's offsets
inside the rect. The solution is to draw icon's rect of the correct
size and center the icon itself.

And make the hotspot exactly match the icon's rect. The last/right
button's hotspot also covers the extra padding on the right.

Differential Revision: https://developer.blender.org/D9936

Reviewed by: Julian Eisel

===================================================================

M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_widgets.c

===================================================================

diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 1d2393ece8d..d246dfadefa 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -4193,9 +4193,17 @@ static uiButExtraOpIcon *ui_but_extra_operator_icon_mouse_over_get(uiBut *but,
     return NULL;
   }
 
+  /* Same as in 'widget_draw_extra_icons', icon padding from the right edge. */
+  xmax -= 0.2 * icon_size;
+
+  /* Handle the padding space from the right edge as the last button. */
+  if (x > xmax) {
+    return but->extra_op_icons.last;
+  }
+
   /* Inverse order, from right to left. */
   LISTBASE_FOREACH_BACKWARD (uiButExtraOpIcon *, op_icon, &but->extra_op_icons) {
-    if ((x > (xmax - icon_size)) && x < xmax) {
+    if ((x > (xmax - icon_size)) && x <= xmax) {
       return op_icon;
     }
     xmax -= icon_size;
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 89720cbf17e..0c3448b987d 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -2254,20 +2254,33 @@ static void widget_draw_extra_icons(const uiWidgetColors *wcol,
                                     rcti *rect,
                                     float alpha)
 {
-  /* inverse order, from right to left. */
+  const float icon_size = ICON_SIZE_FROM_BUTRECT(rect);
+
+  /* Offset of icons from the right edge. Keep in sync
+     with 'ui_but_extra_operator_icon_mouse_over_get'. */
+  if (!BLI_listbase_is_empty(&but->extra_op_icons)) {
+    /* Eyeballed. */
+    rect->xmax -= 0.2 * icon_size;
+  }
+
+  /* Inverse order, from right to left. */
   LISTBASE_FOREACH_BACKWARD (uiButExtraOpIcon *, op_icon, &but->extra_op_icons) {
     rcti temp = *rect;
     float alpha_this = alpha;
 
-    temp.xmin = temp.xmax - (BLI_rcti_size_y(rect) * 1.08f);
+    temp.xmin = temp.xmax - icon_size;
 
     if (!op_icon->highlighted) {
       alpha_this *= 0.75f;
     }
 
+    /* Draw the icon at the center, and restore the flags after. */
+    const int old_drawflags = but->drawflag;
+    UI_but_drawflag_disable(but, UI_BUT_ICON_LEFT);
     widget_draw_icon(but, op_icon->icon, alpha_this, &temp, wcol->text);
+    but->drawflag = old_drawflags;
 
-    rect->xmax -= ICON_SIZE_FROM_BUTRECT(rect);
+    rect->xmax -= icon_size;
   }
 }



More information about the Bf-blender-cvs mailing list