UI: update dynamic tips

Useful for progress ETA to continuously update.

This adds API option not to activate new regions GL state which isn't needed in many cases.
This commit is contained in:
2016-02-02 14:13:57 +11:00
parent 3822a9c01a
commit 3b92a9472c
7 changed files with 56 additions and 29 deletions

View File

@@ -705,6 +705,7 @@ void UI_but_func_drawextra_set(
void UI_but_func_menu_step_set(uiBut *but, uiMenuStepFunc func);
void UI_but_func_tooltip_set(uiBut *but, uiButToolTipFunc func, void *argN);
void UI_but_tooltip_refresh(struct bContext *C, uiBut *but);
void UI_but_tooltip_timer_remove(struct bContext *C, uiBut *but);
bool UI_textbutton_activate_rna(const struct bContext *C, struct ARegion *ar,

View File

@@ -1207,6 +1207,11 @@ void UI_block_update_from_old(const bContext *C, uiBlock *block)
for (but = block->buttons.first; but; but = but->next) {
if (ui_but_update_from_old_block(C, block, &but, &but_old)) {
ui_but_update(but);
/* redraw dynamic tooltip if we have one open */
if (but->tip_func) {
UI_but_tooltip_refresh((bContext *)C, but);
}
}
}

View File

@@ -7526,6 +7526,20 @@ static bool button_modal_state(uiHandleButtonState state)
BUTTON_STATE_MENU_OPEN);
}
/**
* Recreate tooltip (use to update dynamic tips)
*/
void UI_but_tooltip_refresh(bContext *C, uiBut *but)
{
uiHandleButtonData *data;
data = but->active;
if (data && data->tooltip) {
ui_tooltip_free(C, data->tooltip);
data->tooltip = ui_tooltip_create(C, data->region, but);
}
}
/* removes tooltip timer from active but (meaning tooltip is disabled until it's reenabled again) */
void UI_but_tooltip_timer_remove(bContext *C, uiBut *but)
{

View File

@@ -1339,7 +1339,7 @@ static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
/* used for area initialize below */
static void region_subwindow(wmWindow *win, ARegion *ar)
static void region_subwindow(wmWindow *win, ARegion *ar, bool activate)
{
bool hidden = (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) != 0;
@@ -1351,10 +1351,12 @@ static void region_subwindow(wmWindow *win, ARegion *ar)
wm_subwindow_close(win, ar->swinid);
ar->swinid = 0;
}
else if (ar->swinid == 0)
ar->swinid = wm_subwindow_open(win, &ar->winrct);
else
wm_subwindow_position(win, ar->swinid, &ar->winrct);
else if (ar->swinid == 0) {
ar->swinid = wm_subwindow_open(win, &ar->winrct, activate);
}
else {
wm_subwindow_position(win, ar->swinid, &ar->winrct, activate);
}
}
static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *handlers, int flag)
@@ -1457,7 +1459,7 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
/* region windows, default and own handlers */
for (ar = sa->regionbase.first; ar; ar = ar->next) {
region_subwindow(win, ar);
region_subwindow(win, ar, false);
if (ar->swinid) {
/* default region handlers */
@@ -1500,7 +1502,7 @@ void ED_region_init(bContext *C, ARegion *ar)
// ARegionType *at = ar->type;
/* refresh can be called before window opened */
region_subwindow(CTX_wm_window(C), ar);
region_subwindow(CTX_wm_window(C), ar, false);
region_update_rect(ar);
}

View File

@@ -1233,10 +1233,12 @@ void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
screen_test_scale(win->screen, winsize_x, winsize_y);
if (win->screen->mainwin == 0)
win->screen->mainwin = wm_subwindow_open(win, &winrct);
else
wm_subwindow_position(win, win->screen->mainwin, &winrct);
if (win->screen->mainwin == 0) {
win->screen->mainwin = wm_subwindow_open(win, &winrct, false);
}
else {
wm_subwindow_position(win, win->screen->mainwin, &winrct, false);
}
for (sa = win->screen->areabase.first; sa; sa = sa->next) {
/* set spacetype and region callbacks, calls init() */

View File

@@ -192,7 +192,7 @@ void wm_subwindow_rect_set(wmWindow *win, int swinid, const rcti *rect)
/* always sets pixel-precise 2D window/view matrices */
/* coords is in whole pixels. xmin = 15, xmax = 16: means window is 2 pix big */
int wm_subwindow_open(wmWindow *win, const rcti *winrct)
int wm_subwindow_open(wmWindow *win, const rcti *winrct, bool activate)
{
wmSubWindow *swin;
int width, height;
@@ -208,18 +208,19 @@ int wm_subwindow_open(wmWindow *win, const rcti *winrct)
swin->swinid = freewinid;
swin->winrct = *winrct;
/* and we appy it all right away */
wmSubWindowSet(win, swin->swinid);
if (activate) {
/* and we appy it all right away */
wmSubWindowSet(win, swin->swinid);
/* extra service */
wm_swin_size_get(swin, &width, &height);
wmOrtho2_pixelspace(width, height);
glLoadIdentity();
/* extra service */
wm_swin_size_get(swin, &width, &height);
wmOrtho2_pixelspace(width, height);
glLoadIdentity();
}
return swin->swinid;
}
void wm_subwindow_close(wmWindow *win, int swinid)
{
wmSubWindow *swin = swin_from_swinid(win, swinid);
@@ -237,7 +238,7 @@ void wm_subwindow_close(wmWindow *win, int swinid)
}
/* pixels go from 0-99 for a 100 pixel window */
void wm_subwindow_position(wmWindow *win, int swinid, const rcti *winrct)
void wm_subwindow_position(wmWindow *win, int swinid, const rcti *winrct, bool activate)
{
wmSubWindow *swin = swin_from_swinid(win, swinid);
@@ -267,10 +268,12 @@ void wm_subwindow_position(wmWindow *win, int swinid, const rcti *winrct)
if (swin->winrct.ymax > winsize_y)
swin->winrct.ymax = winsize_y;
/* extra service */
wmSubWindowSet(win, swinid);
wm_swin_size_get(swin, &width, &height);
wmOrtho2_pixelspace(width, height);
if (activate) {
/* extra service */
wmSubWindowSet(win, swinid);
wm_swin_size_get(swin, &width, &height);
wmOrtho2_pixelspace(width, height);
}
}
else {
printf("%s: Internal error, bad winid: %d\n", __func__, swinid);

View File

@@ -36,11 +36,11 @@
/* *************** internal api ************** */
void wm_subwindows_free(wmWindow *win);
int wm_subwindow_open(wmWindow *win, const rcti *winrct);
int wm_subwindow_open(wmWindow *win, const rcti *winrct, bool activate);
void wm_subwindow_close(wmWindow *win, int swinid);
int wm_subwindow_get_id(wmWindow *win); /* returns id */
void wm_subwindow_position(wmWindow *win, int swinid, const rcti *winrct);
void wm_subwindow_position(wmWindow *win, int swinid, const rcti *winrct, bool activate);
void wm_subwindow_size_get(wmWindow *win, int swinid, int *x, int *y);
void wm_subwindow_origin_get(wmWindow *win, int swinid, int *x, int *y);