diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-12-19 11:30:05 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-12-19 11:34:16 +0300 |
commit | 77c62c77936f23fb6af107ca5cafcf84d47e11af (patch) | |
tree | 8cfe591c974e9daea148090969fe63cfabd6a8ec /source/blender | |
parent | a0fa404deb447e4d6c3053d26549814510141dab (diff) |
UI: split out button checks from tooltip creation
Allows to make tooltips from other kinds of data.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_tooltip.c | 85 |
3 files changed, 47 insertions, 44 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index c78fe34e849..f4f4aeab134 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -7649,7 +7649,7 @@ void UI_but_tooltip_refresh(bContext *C, uiBut *but) data = but->active; if (data && data->tooltip) { ui_tooltip_free(C, data->tooltip); - data->tooltip = ui_tooltip_create(C, data->region, but); + data->tooltip = ui_tooltip_create_from_button(C, data->region, but); } } @@ -8393,7 +8393,7 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but) data->tooltiptimer = NULL; if (!data->tooltip) - data->tooltip = ui_tooltip_create(C, data->region, but); + data->tooltip = ui_tooltip_create_from_button(C, data->region, but); } /* handle menu auto open timer */ else if (event->customdata == data->autoopentimer) { diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 67b36e249f7..fec07a39cf9 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -587,7 +587,7 @@ struct uiPopupBlockHandle { /* interface_region_*.c */ /* interface_region_tooltip.c */ -struct ARegion *ui_tooltip_create(struct bContext *C, struct ARegion *butregion, uiBut *but); +struct ARegion *ui_tooltip_create_from_button(struct bContext *C, struct ARegion *butregion, uiBut *but); void ui_tooltip_free(struct bContext *C, struct ARegion *ar); /* interface_region_color_picker.c */ diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index 7d10087dcd9..523e03cb8a5 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -560,13 +560,10 @@ static uiTooltipData *ui_tooltip_data_from_button(bContext *C, uiBut *but) } } -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name ToolTip Public API - * \{ */ - -ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) +static ARegion *ui_tooltip_create_with_data( + bContext *C, uiTooltipData *data, + const float init_position[2], + const float aspect) { const float pad_px = UI_TIP_PADDING; wmWindow *win = CTX_wm_window(C); @@ -574,24 +571,12 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) uiStyle *style = UI_style_get(); static ARegionType type; ARegion *ar; -/* IDProperty *prop;*/ - /* aspect values that shrink text are likely unreadable */ - const float aspect = min_ff(1.0f, but->block->aspect); int fonth, fontw; - int ofsx, ofsy, h, i; + int h, i; rctf rect_fl; rcti rect_i; int font_flag = 0; - if (but->drawflag & UI_BUT_NO_TOOLTIP) { - return NULL; - } - - uiTooltipData *data = ui_tooltip_data_from_button(C, but); - if (data == NULL) { - return NULL; - } - /* create area region */ ar = ui_region_temp_add(CTX_wm_screen(C)); @@ -669,31 +654,12 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) data->lineh = h; /* compute position */ - ofsx = 0; //(but->block->panel) ? but->block->panel->ofsx : 0; - ofsy = 0; //(but->block->panel) ? but->block->panel->ofsy : 0; - rect_fl.xmin = BLI_rctf_cent_x(&but->rect) + ofsx - TIP_BORDER_X; + rect_fl.xmin = init_position[0] - TIP_BORDER_X; rect_fl.xmax = rect_fl.xmin + fontw + pad_px; - rect_fl.ymax = but->rect.ymin + ofsy - TIP_BORDER_Y; + rect_fl.ymax = init_position[1] - TIP_BORDER_Y; rect_fl.ymin = rect_fl.ymax - fonth - TIP_BORDER_Y; - /* since the text has beens caled already, the size of tooltips is defined now */ - /* here we try to figure out the right location */ - if (butregion) { - float mx, my; - float ofsx_fl = rect_fl.xmin, ofsy_fl = rect_fl.ymax; - ui_block_to_window_fl(butregion, but->block, &ofsx_fl, &ofsy_fl); - -#if 1 - /* use X mouse location */ - mx = (win->eventstate->x + (TIP_BORDER_X * 2)) - BLI_rctf_cent_x(&but->rect); -#else - mx = ofsx_fl - rect_fl.xmin; -#endif - my = ofsy_fl - rect_fl.ymax; - - BLI_rctf_translate(&rect_fl, mx, my); - } BLI_rcti_rctf_copy(&rect_i, &rect_fl); #undef TIP_BORDER_X @@ -748,6 +714,43 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) return ar; } +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name ToolTip Public API + * \{ */ + + +ARegion *ui_tooltip_create_from_button(bContext *C, ARegion *butregion, uiBut *but) +{ + wmWindow *win = CTX_wm_window(C); + /* aspect values that shrink text are likely unreadable */ + const float aspect = min_ff(1.0f, but->block->aspect); + float init_position[2]; + + if (but->drawflag & UI_BUT_NO_TOOLTIP) { + return NULL; + } + uiTooltipData *data = NULL; + + if (data == NULL) { + data = ui_tooltip_data_from_button(C, but); + } + if (data == NULL) { + return NULL; + } + + init_position[0] = BLI_rctf_cent_x(&but->rect); + init_position[1] = but->rect.ymin; + + if (butregion) { + ui_block_to_window_fl(butregion, but->block, &init_position[0], &init_position[1]); + init_position[0] = win->eventstate->x; + } + + return ui_tooltip_create_with_data(C, data, init_position, aspect); +} + void ui_tooltip_free(bContext *C, ARegion *ar) { ui_region_temp_remove(C, CTX_wm_screen(C), ar); |