Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/animation/time_scrub_ui.c
| Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | static void draw_background(const rcti *rect) | ||||
| immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax); | immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax); | ||||
| GPU_blend(GPU_BLEND_NONE); | GPU_blend(GPU_BLEND_NONE); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| static void get_current_time_str( | static void get_current_time_str( | ||||
| const Scene *scene, bool display_seconds, int frame, uint max_len, char *r_str) | const RenderData *rd, bool display_seconds, int frame, uint max_len, char *r_str) | ||||
| { | { | ||||
| float time_seconds = ((double)rd->frs_sec_base * (double)frame) / (double)rd->frs_sec; | |||||
| double fps = (double)rd->frs_sec / (double)rd->frs_sec_base; | |||||
| if (display_seconds) { | if (display_seconds) { | ||||
| BLI_timecode_string_from_time(r_str, max_len, 0, FRA2TIME(frame), FPS, U.timecode_style); | BLI_timecode_string_from_time(r_str, max_len, 0, time_seconds, fps, U.timecode_style); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_snprintf(r_str, max_len, "%d", frame); | BLI_snprintf(r_str, max_len, "%d", frame); | ||||
| } | } | ||||
| } | } | ||||
| static void draw_current_frame(const Scene *scene, | static void draw_current_frame(const RenderData *rd, | ||||
| bool display_seconds, | bool display_seconds, | ||||
| const View2D *v2d, | const View2D *v2d, | ||||
| const rcti *scrub_region_rect, | const rcti *scrub_region_rect, | ||||
| int current_frame) | int current_frame) | ||||
| { | { | ||||
| const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; | const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; | ||||
| int frame_x = UI_view2d_view_to_region_x(v2d, current_frame); | int frame_x = UI_view2d_view_to_region_x(v2d, current_frame); | ||||
| char frame_str[64]; | char frame_str[64]; | ||||
| get_current_time_str(scene, display_seconds, current_frame, sizeof(frame_str), frame_str); | get_current_time_str(rd, display_seconds, current_frame, sizeof(frame_str), frame_str); | ||||
| float text_width = UI_fontstyle_string_width(fstyle, frame_str); | float text_width = UI_fontstyle_string_width(fstyle, frame_str); | ||||
| float box_width = MAX2(text_width + 8 * UI_DPI_FAC, 24 * UI_DPI_FAC); | float box_width = MAX2(text_width + 8 * UI_DPI_FAC, 24 * UI_DPI_FAC); | ||||
| float box_padding = 3 * UI_DPI_FAC; | float box_padding = 3 * UI_DPI_FAC; | ||||
| const int line_outline = max_ii(1, round_fl_to_int(1 * UI_DPI_FAC)); | const int line_outline = max_ii(1, round_fl_to_int(1 * UI_DPI_FAC)); | ||||
| float bg_color[4]; | float bg_color[4]; | ||||
| UI_GetThemeColorShade4fv(TH_CFRAME, -5, bg_color); | UI_GetThemeColorShade4fv(TH_CFRAME, -5, bg_color); | ||||
| /* Draw vertical line from the bottom of the current frame box to the bottom of the screen. */ | /* Draw vertical line from the bottom of the current frame box to the bottom of the screen. */ | ||||
| const float subframe_x = UI_view2d_view_to_region_x(v2d, BKE_scene_ctime_get(scene)); | const float ctime = ((float)rd->cfra + rd->subframe) * rd->framelen; | ||||
| const float subframe_x = UI_view2d_view_to_region_x(v2d, ctime); | |||||
| GPUVertFormat *format = immVertexFormat(); | GPUVertFormat *format = immVertexFormat(); | ||||
| uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | ||||
| /* Outline. */ | /* Outline. */ | ||||
| immUniformThemeColorShadeAlpha(TH_BACK, -25, -100); | immUniformThemeColorShadeAlpha(TH_BACK, -25, -100); | ||||
| Show All 37 Lines | static void draw_current_frame(const RenderData *rd, | ||||
| UI_fontstyle_draw_simple(fstyle, | UI_fontstyle_draw_simple(fstyle, | ||||
| frame_x - text_width / 2 + U.pixelsize / 2, | frame_x - text_width / 2 + U.pixelsize / 2, | ||||
| get_centered_text_y(scrub_region_rect), | get_centered_text_y(scrub_region_rect), | ||||
| frame_str, | frame_str, | ||||
| text_color); | text_color); | ||||
| } | } | ||||
| void ED_time_scrub_draw_current_frame(const ARegion *region, | void ED_time_scrub_draw_current_frame(const ARegion *region, | ||||
| const Scene *scene, | const RenderData *rd, | ||||
| bool display_seconds) | bool display_seconds) | ||||
| { | { | ||||
| const View2D *v2d = ®ion->v2d; | const View2D *v2d = ®ion->v2d; | ||||
| GPU_matrix_push_projection(); | GPU_matrix_push_projection(); | ||||
| wmOrtho2_region_pixelspace(region); | wmOrtho2_region_pixelspace(region); | ||||
| rcti scrub_region_rect; | rcti scrub_region_rect; | ||||
| ED_time_scrub_region_rect_get(region, &scrub_region_rect); | ED_time_scrub_region_rect_get(region, &scrub_region_rect); | ||||
| draw_current_frame(scene, display_seconds, v2d, &scrub_region_rect, scene->r.cfra); | draw_current_frame(rd, display_seconds, v2d, &scrub_region_rect, rd->cfra); | ||||
| GPU_matrix_pop_projection(); | GPU_matrix_pop_projection(); | ||||
| } | } | ||||
| void ED_time_scrub_draw(const ARegion *region, | void ED_time_scrub_draw(const ARegion *region, | ||||
| const Scene *scene, | const double fps, | ||||
| bool display_seconds, | bool display_seconds, | ||||
| bool discrete_frames) | bool discrete_frames) | ||||
| { | { | ||||
| const View2D *v2d = ®ion->v2d; | const View2D *v2d = ®ion->v2d; | ||||
| GPU_matrix_push_projection(); | GPU_matrix_push_projection(); | ||||
| wmOrtho2_region_pixelspace(region); | wmOrtho2_region_pixelspace(region); | ||||
| rcti scrub_region_rect; | rcti scrub_region_rect; | ||||
| ED_time_scrub_region_rect_get(region, &scrub_region_rect); | ED_time_scrub_region_rect_get(region, &scrub_region_rect); | ||||
| draw_background(&scrub_region_rect); | draw_background(&scrub_region_rect); | ||||
| rcti numbers_rect = scrub_region_rect; | rcti numbers_rect = scrub_region_rect; | ||||
| numbers_rect.ymin = get_centered_text_y(&scrub_region_rect) - 4 * UI_DPI_FAC; | numbers_rect.ymin = get_centered_text_y(&scrub_region_rect) - 4 * UI_DPI_FAC; | ||||
| if (discrete_frames) { | if (discrete_frames) { | ||||
| UI_view2d_draw_scale_x__discrete_frames_or_seconds( | UI_view2d_draw_scale_x__discrete_frames_or_seconds( | ||||
| region, v2d, &numbers_rect, scene, display_seconds, TH_TEXT); | region, v2d, &numbers_rect, fps, display_seconds, TH_TEXT); | ||||
| } | } | ||||
| else { | else { | ||||
| UI_view2d_draw_scale_x__frames_or_seconds( | UI_view2d_draw_scale_x__frames_or_seconds( | ||||
| region, v2d, &numbers_rect, scene, display_seconds, TH_TEXT); | region, v2d, &numbers_rect, fps, display_seconds, TH_TEXT); | ||||
| } | } | ||||
| GPU_matrix_pop_projection(); | GPU_matrix_pop_projection(); | ||||
| } | } | ||||
| bool ED_time_scrub_event_in_region(const ARegion *region, const wmEvent *event) | bool ED_time_scrub_event_in_region(const ARegion *region, const wmEvent *event) | ||||
| { | { | ||||
| rcti rect = region->winrct; | rcti rect = region->winrct; | ||||
| ▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines | |||||