Blender  V3.3
wm_tooltip.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
9 #include "MEM_guardedalloc.h"
10 
11 #include "BLI_math_vector.h"
12 #include "BLI_utildefines.h"
13 
14 #include "BKE_context.h"
15 
16 #include "ED_screen.h"
17 
18 #include "UI_interface.h"
19 
20 #include "WM_api.h"
21 #include "WM_types.h"
22 
23 #include "PIL_time.h"
24 
25 static double g_tooltip_time_closed;
27 {
28  return g_tooltip_time_closed;
29 }
30 
33 {
35 
36  bScreen *screen = WM_window_get_active_screen(win);
37  if (screen->tool_tip == NULL) {
38  screen->tool_tip = MEM_callocN(sizeof(*screen->tool_tip), __func__);
39  }
40  screen->tool_tip->area_from = area;
41  screen->tool_tip->region_from = region;
42  screen->tool_tip->init = init;
43  WM_tooltip_init(C, win);
44 }
45 
47  bContext *C, wmWindow *win, ScrArea *area, ARegion *region, wmTooltipInitFn init, double delay)
48 {
50 
51  bScreen *screen = WM_window_get_active_screen(win);
53  if (screen->tool_tip == NULL) {
54  screen->tool_tip = MEM_callocN(sizeof(*screen->tool_tip), __func__);
55  }
56  screen->tool_tip->area_from = area;
57  screen->tool_tip->region_from = region;
58  screen->tool_tip->timer = WM_event_add_timer(wm, win, TIMER, delay);
59  screen->tool_tip->init = init;
60 }
61 
64 {
66 }
67 
69 {
71  bScreen *screen = WM_window_get_active_screen(win);
72  if (screen->tool_tip != NULL) {
73  if (screen->tool_tip->timer != NULL) {
74  WM_event_remove_timer(wm, win, screen->tool_tip->timer);
75  screen->tool_tip->timer = NULL;
76  }
77  }
78 }
79 
81 {
83  bScreen *screen = WM_window_get_active_screen(win);
84  if (screen->tool_tip != NULL) {
85  if (screen->tool_tip->region) {
86  UI_tooltip_free(C, screen, screen->tool_tip->region);
87  screen->tool_tip->region = NULL;
89  }
90  MEM_freeN(screen->tool_tip);
91  screen->tool_tip = NULL;
92  }
93 }
94 
96 {
98  bScreen *screen = WM_window_get_active_screen(win);
99  if (screen->tool_tip->region) {
100  UI_tooltip_free(C, screen, screen->tool_tip->region);
101  screen->tool_tip->region = NULL;
102  }
103  const int pass_prev = screen->tool_tip->pass;
104  double pass_delay = 0.0;
105 
106  {
107  ScrArea *area_prev = CTX_wm_area(C);
108  ARegion *region_prev = CTX_wm_region(C);
109  CTX_wm_area_set(C, screen->tool_tip->area_from);
111  screen->tool_tip->region = screen->tool_tip->init(C,
112  screen->tool_tip->region_from,
113  &screen->tool_tip->pass,
114  &pass_delay,
115  &screen->tool_tip->exit_on_event);
116  CTX_wm_area_set(C, area_prev);
117  CTX_wm_region_set(C, region_prev);
118  }
119 
120  copy_v2_v2_int(screen->tool_tip->event_xy, win->eventstate->xy);
121  if (pass_prev != screen->tool_tip->pass) {
122  /* The pass changed, add timer for next pass. */
124  screen->tool_tip->timer = WM_event_add_timer(wm, win, TIMER, pass_delay);
125  }
126  if (screen->tool_tip->region == NULL) {
127  WM_tooltip_clear(C, win);
128  }
129 }
130 
132 {
134  bScreen *screen = WM_window_get_active_screen(win);
135  if (screen->tool_tip != NULL) {
136  if (screen->tool_tip->region) {
137  UI_tooltip_free(C, screen, screen->tool_tip->region);
138  screen->tool_tip->region = NULL;
139  }
140  WM_tooltip_init(C, win);
141  }
142 }
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:738
void CTX_wm_region_set(bContext *C, struct ARegion *region)
Definition: context.c:1009
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:713
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:749
void CTX_wm_area_set(bContext *C, struct ScrArea *area)
Definition: context.c:997
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:25
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:1613
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
static void area(int d1, int d2, int e1, int e2, float weights[2])
struct wmTooltipState * tool_tip
int xy[2]
Definition: WM_types.h:682
bool exit_on_event
Definition: WM_types.h:1260
struct ScrArea * area_from
Definition: WM_types.h:1248
struct ARegion *(* init)(struct bContext *C, struct ARegion *region, int *pass, double *pass_delay, bool *r_exit_on_event)
Definition: WM_types.h:1254
struct ARegion * region_from
Definition: WM_types.h:1250
struct wmTimer * timer
Definition: WM_types.h:1246
int event_xy[2]
Definition: WM_types.h:1262
struct ARegion * region
Definition: WM_types.h:1252
struct wmEvent * eventstate
double PIL_check_seconds_timer(void)
Definition: time.c:64
@ TIMER
void WM_tooltip_timer_clear(bContext *C, wmWindow *win)
Definition: wm_tooltip.c:68
void WM_tooltip_clear(bContext *C, wmWindow *win)
Definition: wm_tooltip.c:80
void WM_tooltip_init(bContext *C, wmWindow *win)
Definition: wm_tooltip.c:95
void WM_tooltip_timer_init_ex(bContext *C, wmWindow *win, ScrArea *area, ARegion *region, wmTooltipInitFn init, double delay)
Definition: wm_tooltip.c:46
double WM_tooltip_time_closed(void)
Definition: wm_tooltip.c:26
void WM_tooltip_immediate_init(bContext *C, wmWindow *win, ScrArea *area, ARegion *region, wmTooltipInitFn init)
Definition: wm_tooltip.c:31
void WM_tooltip_refresh(bContext *C, wmWindow *win)
Definition: wm_tooltip.c:131
void WM_tooltip_timer_init(bContext *C, wmWindow *win, ScrArea *area, ARegion *region, wmTooltipInitFn init)
Definition: wm_tooltip.c:62
static double g_tooltip_time_closed
Definition: wm_tooltip.c:25
void WM_event_remove_timer(wmWindowManager *wm, wmWindow *UNUSED(win), wmTimer *timer)
Definition: wm_window.c:1682
bScreen * WM_window_get_active_screen(const wmWindow *win)
Definition: wm_window.c:2300
wmTimer * WM_event_add_timer(wmWindowManager *wm, wmWindow *win, int event_type, double timestep)
Definition: wm_window.c:1630