Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gtkui: Hide info area text containing emoji properly. Closes: #1491 #171

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 33 additions & 23 deletions src/gtkui/ui_infoarea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

#include "ui_infoarea.h"

#define ALPHA_STEPS 10
static inline float TO_ALPHA (int steps) { return (float) steps / ALPHA_STEPS; }

#define VIS_BANDS 12
#define VIS_DELAY 2 /* delay before falloff in frames */
#define VIS_FALLOFF 2 /* falloff in decibels per frame */
Expand All @@ -56,7 +59,7 @@ typedef struct {
String title, artist, album;
String last_title, last_artist, last_album;
AudguiPixbuf pb, last_pb;
float alpha, last_alpha;
int alpha_steps, last_alpha_steps;

bool show_art;
bool stopped;
Expand Down Expand Up @@ -138,15 +141,20 @@ G_GNUC_END_IGNORE_DEPRECATIONS
}

static void draw_text (GtkWidget * widget, cairo_t * cr, int x, int y, int
width, float r, float g, float b, float a, const char * font,
const char * text)
width, float r, float g, float b, float a, int font_size, const char * text)
{
/* The visibility of Unicode characters like emoji is not affected by the
* alpha channel. Make sure to hide them when fading-out track information.
* See also: #1491 */
if (a <= 0)
return;

cairo_move_to (cr, x, y);
cairo_set_source_rgba (cr, r, g, b, a);

PangoFontDescription * desc = pango_font_description_from_string (font);
PangoLayout * pl = gtk_widget_create_pango_layout (widget, nullptr);
pango_layout_set_text (pl, text, -1);
PangoLayout * pl = gtk_widget_create_pango_layout (widget, text);
PangoFontDescription * desc = pango_font_description_new ();
pango_font_description_set_size (desc, font_size * PANGO_SCALE);
pango_layout_set_font_description (pl, desc);
pango_font_description_free (desc);
pango_layout_set_width (pl, width * PANGO_SCALE);
Expand Down Expand Up @@ -207,15 +215,15 @@ static void draw_album_art (cairo_t * cr)
int left = SPACING + (ICON_SIZE - area->pb.width ()) / 2;
int top = SPACING + (ICON_SIZE - area->pb.height ()) / 2;
gdk_cairo_set_source_pixbuf (cr, area->pb.get (), left, top);
cairo_paint_with_alpha (cr, area->alpha);
cairo_paint_with_alpha (cr, TO_ALPHA (area->alpha_steps));
}

if (area->last_pb)
{
int left = SPACING + (ICON_SIZE - area->last_pb.width ()) / 2;
int top = SPACING + (ICON_SIZE - area->last_pb.height ()) / 2;
gdk_cairo_set_source_pixbuf (cr, area->last_pb.get (), left, top);
cairo_paint_with_alpha (cr, area->last_alpha);
cairo_paint_with_alpha (cr, TO_ALPHA (area->last_alpha_steps));
}
}

Expand All @@ -230,25 +238,27 @@ static void draw_title (cairo_t * cr)
int y_offset1 = ICON_SIZE / 2;
int y_offset2 = ICON_SIZE * 3 / 4;
int width = alloc.width - x;
float alpha = TO_ALPHA (area->alpha_steps);
float last_alpha = TO_ALPHA (area->last_alpha_steps);

if (area->title)
draw_text (area->main, cr, x, SPACING, width, 1, 1, 1, area->alpha,
"18", area->title);
draw_text (area->main, cr, x, SPACING, width, 1, 1, 1, alpha,
18, area->title);
if (area->last_title)
draw_text (area->main, cr, x, SPACING, width, 1, 1, 1, area->last_alpha,
"18", area->last_title);
draw_text (area->main, cr, x, SPACING, width, 1, 1, 1, last_alpha,
18, area->last_title);
if (area->artist)
draw_text (area->main, cr, x, SPACING + y_offset1, width, 1, 1, 1,
area->alpha, "9", area->artist);
alpha, 9, area->artist);
if (area->last_artist)
draw_text (area->main, cr, x, SPACING + y_offset1, width, 1, 1, 1,
area->last_alpha, "9", area->last_artist);
last_alpha, 9, area->last_artist);
if (area->album)
draw_text (area->main, cr, x, SPACING + y_offset2, width, 0.7,
0.7, 0.7, area->alpha, "9", area->album);
0.7, 0.7, alpha, 9, area->album);
if (area->last_album)
draw_text (area->main, cr, x, SPACING + y_offset2, width, 0.7,
0.7, 0.7, area->last_alpha, "9", area->last_album);
0.7, 0.7, last_alpha, 9, area->last_album);
}

#ifdef USE_GTK3
Expand Down Expand Up @@ -276,15 +286,15 @@ static void ui_infoarea_do_fade (void *)
g_return_if_fail (area);
bool done = true;

if (aud_drct_get_playing () && area->alpha < 1)
if (aud_drct_get_playing () && area->alpha_steps < ALPHA_STEPS)
{
area->alpha += 0.1;
area->alpha_steps ++;
done = false;
}

if (area->last_alpha > 0)
if (area->last_alpha_steps > 0)
{
area->last_alpha -= 0.1;
area->last_alpha_steps --;
done = false;
}

Expand Down Expand Up @@ -340,8 +350,8 @@ static void infoarea_next ()
area->last_album = std::move (area->album);
area->last_pb = std::move (area->pb);

area->last_alpha = area->alpha;
area->alpha = 0;
area->last_alpha_steps = area->alpha_steps;
area->alpha_steps = 0;

gtk_widget_queue_draw (area->main);
}
Expand Down Expand Up @@ -457,7 +467,7 @@ GtkWidget * ui_infoarea_new ()
set_album_art ();

/* skip fade-in */
area->alpha = 1;
area->alpha_steps = ALPHA_STEPS;
}

GtkWidget * frame = gtk_frame_new (nullptr);
Expand Down
Loading