Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-04-22 23:08:48 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-04-22 23:13:26 +0300
commit62cd5e0b7bf151c757c5607b5081ba677b5240a4 (patch)
tree48a0b844fbdf5b19320a4af1de0ac35ca7c372a9
parent46375b8e03b7ac841af4d3cb16eb1561f959bdb7 (diff)
UI: support for center popovers over buttons
-rw-r--r--source/blender/editors/include/UI_interface.h4
-rw-r--r--source/blender/editors/interface/interface.c2
-rw-r--r--source/blender/editors/interface/interface_intern.h1
-rw-r--r--source/blender/editors/interface/interface_region_popover.c4
-rw-r--r--source/blender/editors/interface/interface_region_popup.c18
-rw-r--r--source/blender/editors/interface/interface_widgets.c13
6 files changed, 34 insertions, 8 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index b02ab8f0841..38d89a4099d 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -108,7 +108,8 @@ enum {
UI_DIR_DOWN = (1 << 1),
UI_DIR_LEFT = (1 << 2),
UI_DIR_RIGHT = (1 << 3),
- UI_DIR_CENTER_Y = (1 << 4),
+ UI_DIR_CENTER_X = (1 << 4),
+ UI_DIR_CENTER_Y = (1 << 5),
UI_DIR_ALL = (UI_DIR_UP | UI_DIR_DOWN | UI_DIR_LEFT | UI_DIR_RIGHT),
};
@@ -140,6 +141,7 @@ enum {
#define UI_BLOCK_POPUP_HOLD (1 << 18)
#define UI_BLOCK_LIST_ITEM (1 << 19)
#define UI_BLOCK_RADIAL (1 << 20)
+#define UI_BLOCK_POPOVER (1 << 21)
/* uiPopupBlockHandle->menuretval */
#define UI_RETURN_CANCEL (1 << 0) /* cancel all menus cascading */
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 5082fe58526..7c7ba553015 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1308,6 +1308,8 @@ void UI_block_draw(const bContext *C, uiBlock *block)
/* back */
if (block->flag & UI_BLOCK_RADIAL)
ui_draw_pie_center(block);
+ else if (block->flag & UI_BLOCK_POPOVER)
+ ui_draw_popover_back(&style, block, &rect);
else if (block->flag & UI_BLOCK_LOOP)
ui_draw_menu_back(&style, block, &rect);
else if (block->panel)
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index cc2dbd31b57..14f73f201ad 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -728,6 +728,7 @@ struct Gwn_Batch *ui_batch_roundbox_shadow_get(void);
void ui_draw_anti_roundbox(int mode, float minx, float miny, float maxx, float maxy,
float rad, bool use_alpha, const float color[4]);
void ui_draw_menu_back(struct uiStyle *style, uiBlock *block, rcti *rect);
+void ui_draw_popover_back(struct uiStyle *style, uiBlock *block, rcti *rect);
void ui_draw_pie_center(uiBlock *block);
uiWidgetColors *ui_tooltip_get_theme(void);
void ui_draw_tooltip_background(uiStyle *UNUSED(style), uiBlock *block, rcti *rect);
diff --git a/source/blender/editors/interface/interface_region_popover.c b/source/blender/editors/interface/interface_region_popover.c
index 1f5143981b2..821e5b02a86 100644
--- a/source/blender/editors/interface/interface_region_popover.c
+++ b/source/blender/editors/interface/interface_region_popover.c
@@ -129,7 +129,9 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v
UI_block_layout_resolve(block, &width, &height);
- UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_KEEP_OPEN);
+ 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);
if (pup->popover) {
UI_block_flag_enable(block, UI_BLOCK_LOOP);
diff --git a/source/blender/editors/interface/interface_region_popup.c b/source/blender/editors/interface/interface_region_popup.c
index 540ef79f08e..b13d9b0448c 100644
--- a/source/blender/editors/interface/interface_region_popup.c
+++ b/source/blender/editors/interface/interface_region_popup.c
@@ -138,11 +138,12 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
const int win_y = WM_window_pixels_y(window);
// wm_window_get_size(window, &win_x, &win_y);
+ const int center_x = (block->direction & UI_DIR_CENTER_X) ? size_x / 2 : 0;
const int center_y = (block->direction & UI_DIR_CENTER_Y) ? size_y / 2 : 0;
/* check if there's space at all */
- if (butrct.xmin - size_x > 0.0f) left = 1;
- if (butrct.xmax + size_x < win_x) right = 1;
+ if (butrct.xmin - size_x + center_x > 0.0f) left = 1;
+ if (butrct.xmax + size_x - center_x < win_x) right = 1;
if (butrct.ymin - size_y + center_y > 0.0f) down = 1;
if (butrct.ymax + size_y - center_y < win_y) top = 1;
@@ -193,8 +194,8 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
}
else if (dir1 == UI_DIR_UP) {
offset_y = butrct.ymax - block->rect.ymin;
- if (dir2 == UI_DIR_RIGHT) offset_x = butrct.xmax - block->rect.xmax;
- else offset_x = butrct.xmin - block->rect.xmin;
+ if (dir2 == UI_DIR_RIGHT) offset_x = butrct.xmax - block->rect.xmax + center_x;
+ else offset_x = butrct.xmin - block->rect.xmin - center_x;
/* changed direction? */
if ((dir1 & block->direction) == 0) {
UI_block_order_flip(block);
@@ -202,14 +203,19 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
}
else if (dir1 == UI_DIR_DOWN) {
offset_y = butrct.ymin - block->rect.ymax;
- if (dir2 == UI_DIR_RIGHT) offset_x = butrct.xmax - block->rect.xmax;
- else offset_x = butrct.xmin - block->rect.xmin;
+ if (dir2 == UI_DIR_RIGHT) offset_x = butrct.xmax - block->rect.xmax + center_x;
+ else offset_x = butrct.xmin - block->rect.xmin - center_x;
/* changed direction? */
if ((dir1 & block->direction) == 0) {
UI_block_order_flip(block);
}
}
+ /* Center over popovers for eg. */
+ if (block->direction & UI_DIR_CENTER_X) {
+ offset_x += BLI_rctf_size_x(&butrct) / ((dir2 == UI_DIR_LEFT) ? 2 : - 2);
+ }
+
/* and now we handle the exception; no space below or to top */
if (top == 0 && down == 0) {
if (dir1 == UI_DIR_LEFT || dir1 == UI_DIR_RIGHT) {
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 867cfb60cac..158370d5626 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -4597,6 +4597,19 @@ 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);
+
+ wt->state(wt, 0);
+ if (block) {
+ wt->draw(&wt->wcol, rect, block->flag, block->direction);
+ }
+ else {
+ wt->draw(&wt->wcol, rect, 0, 0);
+ }
+}
+
static void draw_disk_shaded(
float start, float angle,
float radius_int, float radius_ext, int subd,