Add peak value display to the level meters

This commit is contained in:
Geoffrey D. Bennett
2024-04-11 00:29:08 +09:30
parent 909d3618b3
commit 4ce2565b90
2 changed files with 28 additions and 0 deletions

View File

@@ -771,6 +771,30 @@ static void draw_peak(GtkDial *dial, cairo_t *cr, double radius) {
cairo_stroke(cr);
}
static void show_peak_value(GtkDial *dial, cairo_t *cr) {
double value = round(dial->current_peak);
if (value <= gtk_adjustment_get_lower(dial->adj))
return;
char s[20];
char *p = s;
if (value < 0)
p += sprintf(p, "");
snprintf(p, 10, "%.0f", fabs(value));
cairo_text_extents_t extents;
cairo_text_extents(cr, s, &extents);
cairo_set_source_rgba_dim(cr, 1, 1, 1, 0.5, dial->dim);
cairo_move_to(
cr,
dial->cx - extents.width / 2,
dial->cy + extents.height / 2
);
cairo_show_text(cr, s);
}
static void draw_slider(
GtkDial *dial,
cairo_t *cr,
@@ -910,6 +934,10 @@ static void dial_snapshot(GtkWidget *widget, GtkSnapshot *snapshot) {
cairo_set_line_width(cr, 2);
cairo_stroke(cr);
// show the peak value
if (dial->peak_hold)
show_peak_value(dial, cr);
// if focussed
if (has_focus) {
cairo_set_source_rgba(cr, 1, 0.125, 0.125, 0.5);