Move visual bell code into shaders.c

This commit is contained in:
Kovid Goyal 2021-08-11 12:04:52 +05:30
parent aff6fdfa84
commit 5c7ce18379
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 34 additions and 40 deletions

View File

@ -1516,41 +1516,6 @@ screen_invert_colors(Screen *self) {
return inverted; return inverted;
} }
static inline float
ease_out_cubic(float phase) {
return 1.0f - powf(1.0f - phase, 3.0f);
}
static inline float
ease_in_out_cubic(float phase) {
return phase < 0.5f ?
4.0f * powf(phase, 3.0f) :
1.0f - powf(-2.0f * phase + 2.0f, 3.0f) / 2.0f;
}
static inline float
visual_bell_intensity(float phase) {
float peak = 0.2f;
float fade = 1.0f - peak;
if (phase < peak)
return ease_out_cubic(phase / peak);
else
return ease_in_out_cubic((1.0f - phase) / fade);
}
float
screen_visual_bell_intensity(Screen *self) {
if (self->start_visual_bell_at > 0) {
monotonic_t progress = monotonic() - self->start_visual_bell_at;
monotonic_t duration = OPT(visual_bell_duration);
if (progress <= duration) {
return visual_bell_intensity((float)progress / duration);
}
else self->start_visual_bell_at = 0;
}
return 0.0f;
}
void void
screen_bell(Screen *self) { screen_bell(Screen *self) {
request_window_attention(self->window_id, OPT(enable_audio_bell)); request_window_attention(self->window_id, OPT(enable_audio_bell));

View File

@ -207,7 +207,6 @@ void screen_apply_selection(Screen *self, void *address, size_t size);
bool screen_is_selection_dirty(Screen *self); bool screen_is_selection_dirty(Screen *self);
bool screen_has_selection(Screen*); bool screen_has_selection(Screen*);
bool screen_invert_colors(Screen *self); bool screen_invert_colors(Screen *self);
float screen_visual_bell_intensity(Screen *self);
void screen_update_cell_data(Screen *self, void *address, FONTS_DATA_HANDLE, bool cursor_has_moved); void screen_update_cell_data(Screen *self, void *address, FONTS_DATA_HANDLE, bool cursor_has_moved);
bool screen_is_cursor_visible(Screen *self); bool screen_is_cursor_visible(Screen *self);
bool screen_selection_range_for_line(Screen *self, index_type y, index_type *start, index_type *end); bool screen_selection_range_for_line(Screen *self, index_type y, index_type *start, index_type *end);

View File

@ -458,7 +458,7 @@ draw_tint(bool premult, Screen *screen, GLfloat xstart, GLfloat ystart, GLfloat
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
} }
void static void
draw_visual_bell_flash(GLfloat intensity, GLfloat xstart, GLfloat ystart, GLfloat w, GLfloat h, Screen *screen) { draw_visual_bell_flash(GLfloat intensity, GLfloat xstart, GLfloat ystart, GLfloat w, GLfloat h, Screen *screen) {
glEnable(GL_BLEND); glEnable(GL_BLEND);
// BLEND_PREMULT // BLEND_PREMULT
@ -630,6 +630,36 @@ send_cell_data_to_gpu(ssize_t vao_idx, ssize_t gvao_idx, GLfloat xstart, GLfloat
return changed; return changed;
} }
static float
ease_out_cubic(float phase) {
return 1.0f - powf(1.0f - phase, 3.0f);
}
static float
ease_in_out_cubic(float phase) {
return phase < 0.5f ?
4.0f * powf(phase, 3.0f) :
1.0f - powf(-2.0f * phase + 2.0f, 3.0f) / 2.0f;
}
static float
visual_bell_intensity(float phase) {
static const float peak = 0.2f;
const float fade = 1.0f - peak;
return phase < peak ? ease_out_cubic(phase / peak) : ease_in_out_cubic((1.0f - phase) / fade);
}
static float
get_visual_bell_intensity(Screen *screen) {
if (screen->start_visual_bell_at > 0) {
monotonic_t progress = monotonic() - screen->start_visual_bell_at;
monotonic_t duration = OPT(visual_bell_duration);
if (progress <= duration) return visual_bell_intensity((float)progress / duration);
screen->start_visual_bell_at = 0;
}
return 0.0f;
}
void void
draw_cells(ssize_t vao_idx, ssize_t gvao_idx, GLfloat xstart, GLfloat ystart, GLfloat dx, GLfloat dy, Screen *screen, OSWindow *os_window, bool is_active_window, bool can_be_focused) { draw_cells(ssize_t vao_idx, ssize_t gvao_idx, GLfloat xstart, GLfloat ystart, GLfloat dx, GLfloat dy, Screen *screen, OSWindow *os_window, bool is_active_window, bool can_be_focused) {
CELL_BUFFERS; CELL_BUFFERS;
@ -668,9 +698,9 @@ draw_cells(ssize_t vao_idx, ssize_t gvao_idx, GLfloat xstart, GLfloat ystart, GL
else draw_cells_simple(vao_idx, gvao_idx, screen); else draw_cells_simple(vao_idx, gvao_idx, screen);
} }
float intensity = screen_visual_bell_intensity(screen); if (screen->start_visual_bell_at) {
if (intensity > 0.0f) { GLfloat intensity = get_visual_bell_intensity(screen);
draw_visual_bell_flash((GLfloat)intensity, xstart, ystart, w, h, screen); if (intensity > 0.0f) draw_visual_bell_flash(intensity, xstart, ystart, w, h, screen);
} }
} }
// }}} // }}}