diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-04-23 00:03:08 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-04-23 00:03:08 +0300 |
commit | 9eaf00616ba60df92cfab2837dd175b8e7eb4c44 (patch) | |
tree | d3ecc1338d3ac98f5445a38d28eb0ce0d743916f /source | |
parent | 387bf726ac0fa47149d72ccaaa0df6fadf90df0f (diff) |
UI: draw arrow for popover
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/interface/interface_intern.h | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_popover.c | 11 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 33 |
3 files changed, 41 insertions, 7 deletions
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 14f73f201ad..79238ef0d76 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -91,6 +91,7 @@ typedef enum { UI_WTYPE_MENU_ITEM, UI_WTYPE_MENU_ITEM_RADIAL, UI_WTYPE_MENU_BACK, + UI_WTYPE_POPOVER_BACK, /* specials */ UI_WTYPE_ICON, @@ -113,6 +114,9 @@ typedef enum { #define UI_PANEL_MINX 100 #define UI_PANEL_MINY 70 +/* popover width (multiplied by 'U.widget_unit') */ +#define UI_POPOVER_WIDTH_UNITS 10 + /* uiBut->flag */ enum { UI_SELECT = (1 << 0), /* use when the button is pressed */ diff --git a/source/blender/editors/interface/interface_region_popover.c b/source/blender/editors/interface/interface_region_popover.c index 821e5b02a86..0b3fcff886a 100644 --- a/source/blender/editors/interface/interface_region_popover.c +++ b/source/blender/editors/interface/interface_region_popover.c @@ -125,24 +125,24 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v if (BLI_findindex(&handle->region->uiblocks, block) == -1) UI_block_region_set(block, handle->region); - block->direction = UI_DIR_DOWN; - UI_block_layout_resolve(block, &width, &height); UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_KEEP_OPEN | UI_BLOCK_POPOVER); UI_block_direction_set(block, UI_DIR_DOWN | UI_DIR_CENTER_X); + const int block_margin = U.widget_unit / 2; + if (pup->popover) { UI_block_flag_enable(block, UI_BLOCK_LOOP); UI_block_direction_set(block, block->direction); block->minbounds = minwidth; - UI_block_bounds_set_popup(block, 1, offset[0], offset[1]); + UI_block_bounds_set_popup(block, block_margin, offset[0], offset[1]); } else { /* for a header menu we set the direction automatic */ block->minbounds = minwidth; - UI_block_bounds_set_normal(block, 1); + UI_block_bounds_set_normal(block, block_margin); } /* if menu slides out of other menu, override direction */ @@ -165,7 +165,8 @@ uiPopupBlockHandle *ui_popover_panel_create( pup->block = UI_block_begin(C, NULL, __func__, UI_EMBOSS); UI_block_emboss_set(pup->block, UI_EMBOSS); pup->layout = UI_block_layout( - pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, U.widget_unit * 10, 0, MENU_PADDING, style); + pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, + U.widget_unit * UI_POPOVER_WIDTH_UNITS, 0, MENU_PADDING, style); pup->slideout = false; // but ? ui_block_is_menu(but->block) : false; pup->but = but; uiLayoutSetOperatorContext(pup->layout, WM_OP_INVOKE_REGION_WIN); diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 158370d5626..c3bf1dce962 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -2730,6 +2730,31 @@ 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) +{ + /* tsk, this isn't nice. */ + const float unit_half = (BLI_rcti_size_x(rect) / UI_POPOVER_WIDTH_UNITS) / 2; + const float cent_x = BLI_rcti_cent_x(rect); + 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); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + immUniformColor4ubv((unsigned char *)wcol->inner); + + 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) { @@ -4164,7 +4189,11 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type) wt.wcol_theme = &btheme->tui.wcol_menu_back; wt.draw = widget_menu_back; break; - + case UI_WTYPE_POPOVER_BACK: + wt.wcol_theme = &btheme->tui.wcol_menu_back; + wt.draw = widget_popover_back; + break; + /* specials */ case UI_WTYPE_ICON: wt.custom = widget_icon_has_anim; @@ -4599,7 +4628,7 @@ void ui_draw_menu_back(uiStyle *UNUSED(style), uiBlock *block, rcti *rect) void ui_draw_popover_back(uiStyle *UNUSED(style), uiBlock *block, rcti *rect) { - uiWidgetType *wt = widget_type(UI_WTYPE_MENU_BACK); + uiWidgetType *wt = widget_type(UI_WTYPE_POPOVER_BACK); wt->state(wt, 0); if (block) { |