From e50ab57b8d9c7b78d0ac106c33b44ea55ae86f0b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 22 Jul 2023 11:38:14 +0530 Subject: [PATCH] Draw resizing text with semi-transparent background --- kitty/child-monitor.c | 18 ++++++++++-------- kitty/shaders.c | 4 ++-- kitty/state.h | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 5a708c65c..607f6609a 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -735,13 +735,15 @@ prepare_to_render_os_window(OSWindow *os_window, monotonic_t now, unsigned int * static void draw_resizing_text(OSWindow *w) { - char text[32] = {0}; - unsigned int width = w->live_resize.width, height = w->live_resize.height; - snprintf(text, sizeof(text), "%u x %u cells", width / w->fonts_data->cell_width, height / w->fonts_data->cell_height); - StringCanvas rendered = render_simple_text(w->fonts_data, text); - if (rendered.canvas) { - draw_centered_alpha_mask(w, width, height, rendered.width, rendered.height, rendered.canvas); - free(rendered.canvas); + if (monotonic() - w->created_at > ms_to_monotonic_t(1000)) { + char text[32] = {0}; + unsigned int width = w->live_resize.width, height = w->live_resize.height; + snprintf(text, sizeof(text), "%u x %u cells", width / w->fonts_data->cell_width, height / w->fonts_data->cell_height); + StringCanvas rendered = render_simple_text(w->fonts_data, text); + if (rendered.canvas) { + draw_centered_alpha_mask(w, width, height, rendered.width, rendered.height, rendered.canvas, OPT(background_opacity)); + free(rendered.canvas); + } } } @@ -765,7 +767,7 @@ render_prepared_os_window(OSWindow *os_window, unsigned int active_window_id, co w->cursor_visible_at_last_render = WD.screen->cursor_render_info.is_visible; w->last_cursor_x = WD.screen->cursor_render_info.x; w->last_cursor_y = WD.screen->cursor_render_info.y; w->last_cursor_shape = WD.screen->cursor_render_info.shape; } } - if (os_window->live_resize.in_progress && (monotonic() - os_window->created_at > ms_to_monotonic_t(1000))) draw_resizing_text(os_window); + if (os_window->live_resize.in_progress) draw_resizing_text(os_window); swap_window_buffers(os_window); os_window->last_active_tab = os_window->active_tab; os_window->last_num_tabs = os_window->num_tabs; os_window->last_active_window_id = active_window_id; os_window->focused_at_last_render = os_window->is_focused; diff --git a/kitty/shaders.c b/kitty/shaders.c index dec83ebed..57651e073 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -516,13 +516,13 @@ gpu_data_for_centered_image(ImageRenderData *ans, unsigned int screen_width_px, void -draw_centered_alpha_mask(OSWindow *os_window, size_t screen_width, size_t screen_height, size_t width, size_t height, uint8_t *canvas) { +draw_centered_alpha_mask(OSWindow *os_window, size_t screen_width, size_t screen_height, size_t width, size_t height, uint8_t *canvas, float background_opacity) { ImageRenderData *data = load_alpha_mask_texture(width, height, canvas); gpu_data_for_centered_image(data, screen_width, screen_height, width, height); bind_program(GRAPHICS_ALPHA_MASK_PROGRAM); glUniform1i(graphics_program_layouts[GRAPHICS_ALPHA_MASK_PROGRAM].uniforms.image, GRAPHICS_UNIT); color_vec3(graphics_program_layouts[GRAPHICS_ALPHA_MASK_PROGRAM].uniforms.amask_fg, OPT(foreground)); - color_vec4_premult(graphics_program_layouts[GRAPHICS_ALPHA_MASK_PROGRAM].uniforms.amask_bg_premult, OPT(background), 1); + color_vec4_premult(graphics_program_layouts[GRAPHICS_ALPHA_MASK_PROGRAM].uniforms.amask_bg_premult, OPT(background), background_opacity); glEnable(GL_BLEND); if (os_window->is_semi_transparent) { BLEND_PREMULT; diff --git a/kitty/state.h b/kitty/state.h index 507d3fa76..e8c3de4b4 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -306,7 +306,7 @@ ssize_t create_graphics_vao(void); ssize_t create_border_vao(void); bool send_cell_data_to_gpu(ssize_t, float, float, float, float, Screen *, OSWindow *); void draw_cells(ssize_t, const ScreenRenderData*, OSWindow *, bool, bool, Window*); -void draw_centered_alpha_mask(OSWindow *w, size_t screen_width, size_t screen_height, size_t width, size_t height, uint8_t *canvas); +void draw_centered_alpha_mask(OSWindow *w, size_t screen_width, size_t screen_height, size_t width, size_t height, uint8_t *canvas, float); void update_surface_size(int, int, uint32_t); void free_texture(uint32_t*); void free_framebuffer(uint32_t*);