UI: show arrow for popovers above buttons
authorCampbell Barton <ideasman42@gmail.com>
Mon, 23 Apr 2018 06:38:15 +0000 (08:38 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 23 Apr 2018 06:51:13 +0000 (08:51 +0200)
Also don't align popover buttons with activated popovers.

source/blender/editors/interface/interface_widgets.c

index c3bf1dce9622beb94ea96c496bd86b5fc5929180..a9bb3089175d2b3697557e65244be80c2f5a953f 100644 (file)
@@ -2730,7 +2730,7 @@ static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int dir
        glDisable(GL_BLEND);
 }
 
-static void widget_popover_back(uiWidgetColors *wcol, rcti *rect, int flag, int direction)
+static void widget_popover_back(uiWidgetColors *wcol, rcti *rect, int UNUSED(flag), int direction)
 {
        /* tsk, this isn't nice. */
        const float unit_half = (BLI_rcti_size_x(rect) / UI_POPOVER_WIDTH_UNITS) / 2;
@@ -2738,22 +2738,46 @@ static void widget_popover_back(uiWidgetColors *wcol, rcti *rect, int flag, int
        rect->ymax -= unit_half;
        rect->ymin += unit_half;
 
-       widget_menu_back(wcol, rect, flag, direction);
 
-       unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+       glEnable(GL_BLEND);
 
-       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       /* Extracted from 'widget_menu_back', keep separate to avoid menu changes breaking popovers */
+       {
+               uiWidgetBase wtb;
+               widget_init(&wtb);
 
-       immUniformColor4ubv((unsigned char *)wcol->inner);
+               const int roundboxalign = UI_CNR_ALL;
+               widget_softshadow(rect, roundboxalign, wcol->roundness * U.widget_unit);
+
+               round_box_edges(&wtb, roundboxalign, rect, wcol->roundness * U.widget_unit);
+               wtb.draw_emboss = false;
+               widgetbase_draw(&wtb, wcol);
+       }
+
+       /* Draw popover arrow (top/bottom) */
+       if (ELEM(direction, UI_DIR_UP, UI_DIR_DOWN)) {
+               unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+               immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+               immUniformColor4ubv((unsigned char *)wcol->inner);
+               glEnable(GL_BLEND);
+               immBegin(GWN_PRIM_TRIS, 3);
+               if (direction == UI_DIR_DOWN) {
+                       const float y = rect->ymax;
+                       immVertex2f(pos, cent_x - unit_half, y);
+                       immVertex2f(pos, cent_x + unit_half, y);
+                       immVertex2f(pos, cent_x, y + unit_half);
+               }
+               else {
+                       const float y = rect->ymin;
+                       immVertex2f(pos, cent_x - unit_half, y);
+                       immVertex2f(pos, cent_x + unit_half, rect->ymin);
+                       immVertex2f(pos, cent_x, y - unit_half);
+               }
+               immEnd();
+               immUnbindProgram();
+       }
 
-       glEnable(GL_BLEND);
-       immBegin(GWN_PRIM_TRIS, 3);
-       immVertex2f(pos, cent_x - unit_half, rect->ymax);
-       immVertex2f(pos, cent_x + unit_half, rect->ymax);
-       immVertex2f(pos, cent_x, rect->ymax + unit_half);
-       immEnd();
        glDisable(GL_BLEND);
-       immUnbindProgram();
 }
 
 static void ui_hsv_cursor(float x, float y)
@@ -4293,7 +4317,7 @@ static int widget_roundbox_set(uiBut *but, rcti *rect)
        }
 
        /* align with open menu */
-       if (but->active) {
+       if (but->active && (but->type != UI_BTYPE_POPOVER)) {
                int direction = ui_but_menu_direction(but);
 
                if      (direction == UI_DIR_UP)    roundbox &= ~(UI_CNR_TOP_RIGHT    | UI_CNR_TOP_LEFT);