Blender  V2.93
wm_tooltip.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
23 #include "MEM_guardedalloc.h"
24 
25 #include "BLI_math_vector.h"
26 #include "BLI_utildefines.h"
27 
28 #include "BKE_context.h"
29 
30 #include "ED_screen.h"
31 
32 #include "UI_interface.h"
33 
34 #include "WM_api.h"
35 #include "WM_types.h"
36 
37 #include "PIL_time.h"
38 
39 static double g_tooltip_time_closed;
41 {
42  return g_tooltip_time_closed;
43 }
44 
47 {
49 
50  bScreen *screen = WM_window_get_active_screen(win);
51  if (screen->tool_tip == NULL) {
52  screen->tool_tip = MEM_callocN(sizeof(*screen->tool_tip), __func__);
53  }
54  screen->tool_tip->area_from = area;
55  screen->tool_tip->region_from = region;
56  screen->tool_tip->init = init;
57  WM_tooltip_init(C, win);
58 }
59 
61  bContext *C, wmWindow *win, ScrArea *area, ARegion *region, wmTooltipInitFn init, double delay)
62 {
64 
65  bScreen *screen = WM_window_get_active_screen(win);
67  if (screen->tool_tip == NULL) {
68  screen->tool_tip = MEM_callocN(sizeof(*screen->tool_tip), __func__);
69  }
70  screen->tool_tip->area_from = area;
71  screen->tool_tip->region_from = region;
72  screen->tool_tip->timer = WM_event_add_timer(wm, win, TIMER, delay);
73  screen->tool_tip->init = init;
74 }
75 
78 {
80 }
81 
83 {
85  bScreen *screen = WM_window_get_active_screen(win);
86  if (screen->tool_tip != NULL) {
87  if (screen->tool_tip->timer != NULL) {
88  WM_event_remove_timer(wm, win, screen->tool_tip->timer);
89  screen->tool_tip->timer = NULL;
90  }
91  }
92 }
93 
95 {
97  bScreen *screen = WM_window_get_active_screen(win);
98  if (screen->tool_tip != NULL) {
99  if (screen->tool_tip->region) {
100  UI_tooltip_free(C, screen, screen->tool_tip->region);
101  screen->tool_tip->region = NULL;
103  }
104  MEM_freeN(screen->tool_tip);
105  screen->tool_tip = NULL;
106  }
107 }
108 
110 {
112  bScreen *screen = WM_window_get_active_screen(win);
113  if (screen->tool_tip->region) {
114  UI_tooltip_free(C, screen, screen->tool_tip->region);
115  screen->tool_tip->region = NULL;
116  }
117  const int pass_prev = screen->tool_tip->pass;
118  double pass_delay = 0.0;
119 
120  {
121  ScrArea *area_prev = CTX_wm_area(C);
122  ARegion *region_prev = CTX_wm_region(C);
123  CTX_wm_area_set(C, screen->tool_tip->area_from);
125  screen->tool_tip->region = screen->tool_tip->init(C,
126  screen->tool_tip->region_from,
127  &screen->tool_tip->pass,
128  &pass_delay,
129  &screen->tool_tip->exit_on_event);
130  CTX_wm_area_set(C, area_prev);
131  CTX_wm_region_set(C, region_prev);
132  }
133 
134  copy_v2_v2_int(screen->tool_tip->event_xy, &win->eventstate->x);
135  if (pass_prev != screen->tool_tip->pass) {
136  /* The pass changed, add timer for next pass. */
138  screen->tool_tip->timer = WM_event_add_timer(wm, win, TIMER, pass_delay);
139  }
140  if (screen->tool_tip->region == NULL) {
141  WM_tooltip_clear(C, win);
142  }
143 }
144 
146 {
148  bScreen *screen = WM_window_get_active_screen(win);
149  if (screen->tool_tip != NULL) {
150  if (screen->tool_tip->region) {
151  UI_tooltip_free(C, screen, screen->tool_tip->region);
152  screen->tool_tip->region = NULL;
153  }
154  WM_tooltip_init(C, win);
155  }
156 }
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
void CTX_wm_region_set(bContext *C, struct ARegion *region)
Definition: context.c:985
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:689
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:725
void CTX_wm_area_set(bContext *C, struct ScrArea *area)
Definition: context.c:973
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
Read Guarded memory(de)allocation.
Platform independent time functions.
#define C
Definition: RandGen.cpp:39
void UI_tooltip_free(struct bContext *C, struct bScreen *screen, struct ARegion *region)
#define UI_TOOLTIP_DELAY
struct ARegion *(* wmTooltipInitFn)(struct bContext *C, struct ARegion *region, int *pass, double *r_pass_delay, bool *r_exit_on_event)
Definition: WM_api.h:895
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static void area(int d1, int d2, int e1, int e2, float weights[2])
struct wmTooltipState * tool_tip
int x
Definition: WM_types.h:581
bool exit_on_event
Definition: WM_types.h:980
struct ScrArea * area_from
Definition: WM_types.h:968
struct ARegion *(* init)(struct bContext *C, struct ARegion *region, int *pass, double *pass_delay, bool *r_exit_on_event)
Definition: WM_types.h:974
struct ARegion * region_from
Definition: WM_types.h:970
struct wmTimer * timer
Definition: WM_types.h:966
int event_xy[2]
Definition: WM_types.h:982
struct ARegion * region
Definition: WM_types.h:972
struct wmEvent * eventstate
double PIL_check_seconds_timer(void)
Definition: time.c:80
@ TIMER
void WM_tooltip_timer_clear(bContext *C, wmWindow *win)
Definition: wm_tooltip.c:82
void WM_tooltip_clear(bContext *C, wmWindow *win)
Definition: wm_tooltip.c:94
void WM_tooltip_init(bContext *C, wmWindow *win)
Definition: wm_tooltip.c:109
void WM_tooltip_timer_init_ex(bContext *C, wmWindow *win, ScrArea *area, ARegion *region, wmTooltipInitFn init, double delay)
Definition: wm_tooltip.c:60
double WM_tooltip_time_closed(void)
Definition: wm_tooltip.c:40
void WM_tooltip_immediate_init(bContext *C, wmWindow *win, ScrArea *area, ARegion *region, wmTooltipInitFn init)
Definition: wm_tooltip.c:45
void WM_tooltip_refresh(bContext *C, wmWindow *win)
Definition: wm_tooltip.c:145
void WM_tooltip_timer_init(bContext *C, wmWindow *win, ScrArea *area, ARegion *region, wmTooltipInitFn init)
Definition: wm_tooltip.c:76
static double g_tooltip_time_closed
Definition: wm_tooltip.c:39
void WM_event_remove_timer(wmWindowManager *wm, wmWindow *UNUSED(win), wmTimer *timer)
Definition: wm_window.c:1669
bScreen * WM_window_get_active_screen(const wmWindow *win)
Definition: wm_window.c:2372
wmTimer * WM_event_add_timer(wmWindowManager *wm, wmWindow *win, int event_type, double timestep)
Definition: wm_window.c:1632