Blender  V3.3
time_scrub_ui.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2019 Blender Foundation. All rights reserved. */
3 
8 #include "BKE_context.h"
9 #include "BKE_scene.h"
10 
11 #include "GPU_immediate.h"
12 #include "GPU_matrix.h"
13 #include "GPU_state.h"
14 
15 #include "ED_time_scrub_ui.h"
16 
17 #include "WM_api.h"
18 #include "WM_types.h"
19 
20 #include "UI_interface.h"
21 #include "UI_interface_icons.h"
22 #include "UI_resources.h"
23 #include "UI_view2d.h"
24 
25 #include "DNA_scene_types.h"
26 
27 #include "BLI_math.h"
28 #include "BLI_rect.h"
29 #include "BLI_string.h"
30 #include "BLI_timecode.h"
31 
32 #include "RNA_access.h"
33 #include "RNA_prototypes.h"
34 
35 void ED_time_scrub_region_rect_get(const ARegion *region, rcti *rect)
36 {
37  rect->xmin = 0;
38  rect->xmax = region->winx;
39  rect->ymax = region->winy;
40  rect->ymin = rect->ymax - UI_TIME_SCRUB_MARGIN_Y;
41 }
42 
43 static int get_centered_text_y(const rcti *rect)
44 {
45  return BLI_rcti_cent_y(rect) - UI_DPI_FAC * 4;
46 }
47 
48 static void draw_background(const rcti *rect)
49 {
52 
54 
56 
57  immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
58 
60 
62 }
63 
65  const Scene *scene, bool display_seconds, int frame, uint max_len, char *r_str)
66 {
67  if (display_seconds) {
68  BLI_timecode_string_from_time(r_str, max_len, 0, FRA2TIME(frame), FPS, U.timecode_style);
69  }
70  else {
71  BLI_snprintf(r_str, max_len, "%d", frame);
72  }
73 }
74 
75 static void draw_current_frame(const Scene *scene,
76  bool display_seconds,
77  const View2D *v2d,
78  const rcti *scrub_region_rect,
79  int current_frame)
80 {
81  const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
82  int frame_x = UI_view2d_view_to_region_x(v2d, current_frame);
83 
84  char frame_str[64];
85  get_current_time_str(scene, display_seconds, current_frame, sizeof(frame_str), frame_str);
86  float text_width = UI_fontstyle_string_width(fstyle, frame_str);
87  float box_width = MAX2(text_width + 8 * UI_DPI_FAC, 24 * UI_DPI_FAC);
88  float box_padding = 3 * UI_DPI_FAC;
89  const int line_outline = max_ii(1, round_fl_to_int(1 * UI_DPI_FAC));
90 
91  float bg_color[4];
92  UI_GetThemeColorShade4fv(TH_CFRAME, -5, bg_color);
93 
94  /* Draw vertical line from the bottom of the current frame box to the bottom of the screen. */
95  const float subframe_x = UI_view2d_view_to_region_x(v2d, BKE_scene_ctime_get(scene));
98 
101 
102  /* Outline. */
104  immRectf(pos,
105  subframe_x - (line_outline + U.pixelsize),
106  scrub_region_rect->ymax - box_padding,
107  subframe_x + (line_outline + U.pixelsize),
108  0.0f);
109 
110  /* Line. */
112  immRectf(pos,
113  subframe_x - U.pixelsize,
114  scrub_region_rect->ymax - box_padding,
115  subframe_x + U.pixelsize,
116  0.0f);
119 
121 
122  float outline_color[4];
123  UI_GetThemeColorShade4fv(TH_CFRAME, 5, outline_color);
124 
126  &(const rctf){
127  .xmin = frame_x - box_width / 2 + U.pixelsize / 2,
128  .xmax = frame_x + box_width / 2 + U.pixelsize / 2,
129  .ymin = scrub_region_rect->ymin + box_padding,
130  .ymax = scrub_region_rect->ymax - box_padding,
131  },
132  bg_color,
133  NULL,
134  1.0f,
135  outline_color,
136  U.pixelsize,
137  4 * UI_DPI_FAC);
138 
139  uchar text_color[4];
142  frame_x - text_width / 2 + U.pixelsize / 2,
143  get_centered_text_y(scrub_region_rect),
144  frame_str,
145  text_color);
146 }
147 
149  const Scene *scene,
150  bool display_seconds)
151 {
152  const View2D *v2d = &region->v2d;
155 
156  rcti scrub_region_rect;
157  ED_time_scrub_region_rect_get(region, &scrub_region_rect);
158 
159  draw_current_frame(scene, display_seconds, v2d, &scrub_region_rect, scene->r.cfra);
161 }
162 
163 void ED_time_scrub_draw(const ARegion *region,
164  const Scene *scene,
165  bool display_seconds,
166  bool discrete_frames)
167 {
168  const View2D *v2d = &region->v2d;
169 
172 
173  rcti scrub_region_rect;
174  ED_time_scrub_region_rect_get(region, &scrub_region_rect);
175 
176  draw_background(&scrub_region_rect);
177 
178  rcti numbers_rect = scrub_region_rect;
179  numbers_rect.ymin = get_centered_text_y(&scrub_region_rect) - 4 * UI_DPI_FAC;
180  if (discrete_frames) {
182  region, v2d, &numbers_rect, scene, display_seconds, TH_TEXT);
183  }
184  else {
186  region, v2d, &numbers_rect, scene, display_seconds, TH_TEXT);
187  }
188 
190 }
191 
192 bool ED_time_scrub_event_in_region(const ARegion *region, const wmEvent *event)
193 {
194  rcti rect = region->winrct;
195  rect.ymin = rect.ymax - UI_TIME_SCRUB_MARGIN_Y;
196  return BLI_rcti_isect_pt_v(&rect, event->xy);
197 }
198 
200 {
203 
204  rcti rect;
205  rect.xmin = 0;
206  rect.xmax = region->winx;
207  rect.ymin = region->winy - UI_TIME_SCRUB_MARGIN_Y;
208  rect.ymax = region->winy;
209 
213  immRectf(pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
215 
216  PointerRNA ptr;
217  RNA_pointer_create(&CTX_wm_screen(C)->id, &RNA_DopeSheet, dopesheet, &ptr);
218 
219  const uiStyle *style = UI_style_get_dpi();
220  const float padding_x = 2 * UI_DPI_FAC;
221  const float padding_y = UI_DPI_FAC;
222 
223  uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS);
224  uiLayout *layout = UI_block_layout(block,
227  rect.xmin + padding_x,
228  rect.ymin + UI_UNIT_Y + padding_y,
229  BLI_rcti_size_x(&rect) - 2 * padding_x,
230  1,
231  0,
232  style);
233  uiLayoutSetScaleY(layout, (UI_UNIT_Y - padding_y) / UI_UNIT_Y);
234  UI_block_layout_set_current(block, layout);
235  UI_block_align_begin(block);
236  uiItemR(layout, &ptr, "filter_text", 0, "", ICON_NONE);
237  uiItemR(layout, &ptr, "use_filter_invert", 0, "", ICON_ARROW_LEFTRIGHT);
238  UI_block_align_end(block);
240 
241  /* Make sure the events are consumed from the search and don't reach other UI blocks since this
242  * is drawn on top of animation-channels. */
244  UI_block_bounds_set_normal(block, 0);
245  UI_block_end(C, block);
246  UI_block_draw(C, block);
247 
249 }
struct bScreen * CTX_wm_screen(const bContext *C)
Definition: context.c:733
float BKE_scene_ctime_get(const struct Scene *scene)
MINLINE int round_fl_to_int(float a)
MINLINE int max_ii(int a, int b)
bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2])
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition: BLI_rect.h:186
BLI_INLINE int BLI_rcti_cent_y(const struct rcti *rct)
Definition: BLI_rect.h:173
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
unsigned char uchar
Definition: BLI_sys_types.h:70
unsigned int uint
Definition: BLI_sys_types.h:67
size_t BLI_timecode_string_from_time(char *str, size_t maxncpy, int brevity_level, float time_seconds, double fps, short timecode_style) ATTR_NONNULL()
Definition: timecode.c:22
#define MAX2(a, b)
#define FPS
#define FRA2TIME(a)
void immUniformThemeColorShadeAlpha(int color_id, int color_offset, int alpha_offset)
void immUnbindProgram(void)
void immUniformThemeColor(int color_id)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
GPUVertFormat * immVertexFormat(void)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
void GPU_matrix_pop_projection(void)
Definition: gpu_matrix.cc:140
void GPU_matrix_push_projection(void)
Definition: gpu_matrix.cc:133
@ GPU_SHADER_2D_UNIFORM_COLOR
Definition: GPU_shader.h:201
@ GPU_BLEND_NONE
Definition: GPU_state.h:60
@ GPU_BLEND_ALPHA
Definition: GPU_state.h:62
void GPU_blend(eGPUBlend blend)
Definition: gpu_state.cc:39
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
#define C
Definition: RandGen.cpp:25
@ UI_LAYOUT_VERTICAL
#define UI_UNIT_Y
@ UI_EMBOSS
Definition: UI_interface.h:108
const struct uiStyle * UI_style_get_dpi(void)
void uiLayoutSetScaleY(uiLayout *layout, float scale)
void UI_block_bounds_set_normal(struct uiBlock *block, int addval)
Definition: interface.cc:582
@ UI_LAYOUT_HEADER
void UI_fontstyle_draw_simple(const struct uiFontStyle *fs, float x, float y, const char *str, const uchar col[4])
void UI_draw_roundbox_corner_set(int type)
void UI_block_end(const struct bContext *C, uiBlock *block)
void UI_block_draw(const struct bContext *C, struct uiBlock *block)
#define UI_DPI_FAC
Definition: UI_interface.h:305
uiLayout * UI_block_layout(uiBlock *block, int dir, int type, int x, int y, int size, int em, int padding, const struct uiStyle *style)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void UI_block_align_begin(uiBlock *block)
Definition: interface.cc:3910
@ UI_CNR_ALL
uiBlock * UI_block_begin(const struct bContext *C, struct ARegion *region, const char *name, eUIEmbossType emboss)
void UI_draw_roundbox_4fv_ex(const struct rctf *rect, const float inner1[4], const float inner2[4], float shade_dir, const float outline[4], float outline_width, float rad)
void UI_block_layout_resolve(uiBlock *block, int *r_x, int *r_y)
#define UI_FSTYLE_WIDGET
void UI_block_layout_set_current(uiBlock *block, uiLayout *layout)
void UI_block_flag_enable(uiBlock *block, int flag)
Definition: interface.cc:5848
int UI_fontstyle_string_width(const struct uiFontStyle *fs, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
@ UI_BLOCK_CLIP_EVENTS
Definition: UI_interface.h:150
void UI_block_align_end(uiBlock *block)
Definition: interface.cc:3923
@ TH_TIME_SCRUB_BACKGROUND
Definition: UI_resources.h:98
@ TH_BACK
Definition: UI_resources.h:39
@ TH_CFRAME
Definition: UI_resources.h:97
@ TH_HEADER_TEXT_HI
Definition: UI_resources.h:53
@ TH_TEXT
Definition: UI_resources.h:42
void UI_GetThemeColorShade4fv(int colorid, int offset, float col[4])
Definition: resources.c:1331
void UI_GetThemeColor4ubv(int colorid, unsigned char col[4])
Definition: resources.c:1352
float UI_view2d_view_to_region_x(const struct View2D *v2d, float x)
#define UI_TIME_SCRUB_MARGIN_Y
Definition: UI_view2d.h:450
void UI_view2d_draw_scale_x__discrete_frames_or_seconds(const struct ARegion *region, const struct View2D *v2d, const struct rcti *rect, const struct Scene *scene, bool display_seconds, int colorid)
Definition: view2d_draw.cc:571
void UI_view2d_draw_scale_x__frames_or_seconds(const struct ARegion *region, const struct View2D *v2d, const struct rcti *rect, const struct Scene *scene, bool display_seconds, int colorid)
Definition: view2d_draw.cc:586
unsigned int U
Definition: btGjkEpa3.h:78
Scene scene
uint pos
format
Definition: logImageCore.h:38
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:136
struct RenderData r
int ymin
Definition: DNA_vec_types.h:64
int ymax
Definition: DNA_vec_types.h:64
int xmin
Definition: DNA_vec_types.h:63
int xmax
Definition: DNA_vec_types.h:63
int xy[2]
Definition: WM_types.h:682
static void get_current_time_str(const Scene *scene, bool display_seconds, int frame, uint max_len, char *r_str)
Definition: time_scrub_ui.c:64
static void draw_background(const rcti *rect)
Definition: time_scrub_ui.c:48
void ED_time_scrub_region_rect_get(const ARegion *region, rcti *rect)
Definition: time_scrub_ui.c:35
void ED_time_scrub_draw_current_frame(const ARegion *region, const Scene *scene, bool display_seconds)
void ED_time_scrub_channel_search_draw(const bContext *C, ARegion *region, bDopeSheet *dopesheet)
void ED_time_scrub_draw(const ARegion *region, const Scene *scene, bool display_seconds, bool discrete_frames)
static int get_centered_text_y(const rcti *rect)
Definition: time_scrub_ui.c:43
static void draw_current_frame(const Scene *scene, bool display_seconds, const View2D *v2d, const rcti *scrub_region_rect, int current_frame)
Definition: time_scrub_ui.c:75
bool ED_time_scrub_event_in_region(const ARegion *region, const wmEvent *event)
PointerRNA * ptr
Definition: wm_files.c:3480
void wmOrtho2_region_pixelspace(const ARegion *region)
Definition: wm_subwindow.c:103