UI: update dynamic tips
authorCampbell Barton <ideasman42@gmail.com>
Tue, 2 Feb 2016 03:13:57 +0000 (14:13 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 2 Feb 2016 03:16:53 +0000 (14:16 +1100)
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.

source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/screen/area.c
source/blender/editors/screen/screen_edit.c
source/blender/windowmanager/intern/wm_subwindow.c
source/blender/windowmanager/wm_subwindow.h

index d4b723b807f0349d66a934d71787449806555ea9..617b0d12684860d5c3ade13dd8c74a8b9ae0a19c 100644 (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,
index cb2b99dbfb9f64affd898d9cff04bf30b5eeff71..ffebd39b69356e6ce4f5ba24ff5f52c05a7cc27b 100644 (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);
+                       }
                }
        }
 
index 829fa6be44f8947967c2d2e9c1c85b977020f599..8e58ed5e98d6e727839c882c44a5bb89ca65560c 100644 (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)
 {
index 0e4dd701a5866278c583ff0e5c1dd2ca267aa8dd..d39b70802fe39c5a8d6a199009f7359cc7decf60 100644 (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 */
@@ -1498,10 +1500,10 @@ void ED_region_update_rect(bContext *C, ARegion *ar)
 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);
 }
 
index a5b25645f2a68b1c9d71c0708bbfbd9f4d0f5112..fce2ef3eb2d99690f91c2a793d53a05186aca97a 100644 (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() */
index 7dade62347c4b9772b70fb270104042eb37a6e38..a0279e56ba17e785842cbe07f0caba8f67c8cf84 100644 (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);
-       
-       /* extra service */
-       wm_swin_size_get(swin, &width, &height);
-       wmOrtho2_pixelspace(width, height);
-       glLoadIdentity();
+       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();
+       }
 
        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);
index bf7b99433c697bcbe0f906710287575ff4823f66..2a8118a726b60cd0391de7866611f956ef14f81f 100644 (file)
 /* *************** 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);