Simplify progress bars coloring (GTK client) (#4688)

I remember seeing better results when adding background during hue
adjustment, but can't clearly see the difference now. Since using
`DEST_OVER` Cairo operator results in crashes on some systems, don't
bother with the background, hopefully still getting acceptable results.
This commit is contained in:
Mike Gelfand 2023-01-30 02:20:28 +03:00 committed by GitHub
parent 0e5f7f86d7
commit e775de01bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 31 deletions

View File

@ -119,12 +119,9 @@ private:
static void set_icon(Gtk::CellRendererPixbuf& renderer, Glib::RefPtr<Gio::Icon> const& icon, IconSize icon_size);
static void adjust_progress_bar_hue(
Cairo::RefPtr<Cairo::Surface> const& bg_surface,
Cairo::RefPtr<Cairo::Context> const& context,
Gdk::RGBA const& color,
Gdk::Rectangle const& area,
double bg_x,
double bg_y);
Gdk::Rectangle const& area);
private:
TorrentCellRenderer& renderer_;
@ -301,23 +298,14 @@ void render_impl(Gtk::CellRenderer& renderer, Ts&&... args)
} // namespace
void TorrentCellRenderer::Impl::adjust_progress_bar_hue(
Cairo::RefPtr<Cairo::Surface> const& bg_surface,
Cairo::RefPtr<Cairo::Context> const& context,
Gdk::RGBA const& color,
Gdk::Rectangle const& area,
double bg_x,
double bg_y)
Gdk::Rectangle const& area)
{
using TrCairoContextOperator = IF_GTKMM4(Cairo::Context::Operator, Cairo::Operator);
auto const mask_surface = get_mask_surface(context->get_target(), area);
// Add background under the progress bar, for better results around the transparent areas
context->set_source(bg_surface, bg_x, bg_y);
context->set_operator(TR_CAIRO_CONTEXT_OPERATOR(DEST_OVER));
context->rectangle(area.get_x(), area.get_y(), area.get_width(), area.get_height());
context->fill();
// Adjust surface color
context->set_source_rgb(color.get_red(), color.get_green(), color.get_blue());
context->set_operator(static_cast<TrCairoContextOperator>(CAIRO_OPERATOR_HSL_COLOR));
@ -357,24 +345,9 @@ void TorrentCellRenderer::Impl::render_progress_bar(
#endif
}
#if GTKMM_CHECK_VERSION(4, 0, 0)
auto const context = snapshot->append_cairo(area);
auto const surface = context->get_target();
#else
auto const context = snapshot;
auto const surface = Cairo::Surface::create(
context->get_target(),
area.get_x(),
area.get_y(),
area.get_width(),
area.get_height());
#endif
auto const context = IF_GTKMM4(snapshot->append_cairo(area), snapshot);
double dx = 0;
double dy = 0;
context->device_to_user(dx, dy);
adjust_progress_bar_hue(surface, temp_context, color, temp_area, dx - area.get_x(), dy - area.get_y());
adjust_progress_bar_hue(temp_context, color, temp_area);
context->set_source(temp_context->get_target(), area.get_x(), area.get_y());
context->rectangle(area.get_x(), area.get_y(), area.get_width(), area.get_height());