Radial gradient meowment

Signed-off-by: Vasiliy Doylov <nekocwd@mainlining.org>
This commit is contained in:
Vasiliy Doylov 2025-07-10 05:54:31 +03:00
parent 9db49ee448
commit 66bf073f94
2 changed files with 22 additions and 7 deletions

View file

@ -15,13 +15,30 @@ using GLib;
public class Extension.Player : Gtk.Box {
[GtkChild]
private unowned Gtk.Image image;
private string id = Uuid.string_random ();
private Gtk.CssProvider css_provider = new Gtk.CssProvider ();
construct {
get_style_context ().add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER);
get_style_context ().add_class (id);
}
~Player () {
Gtk.StyleContext.remove_provider_for_screen (Gdk.Screen.get_default (), css_provider);
}
private double deg (double deg) {
return Math.PI / 180.0 * deg;
}
void set_colors (Gdk.RGBA[] colors) {
var gradient_points = new string[0];
for (uint i = 0; i < colors.length; i++) {
gradient_points += "%s %d%%".printf (colors[i].to_string (), (int) (100.0 / colors.length * i));
}
var data = ".%s { background: radial-gradient(circle at left, %s); }"
.printf (id, string.joinv (",", gradient_points));
css_provider.load_from_data (data);
}
private Gdk.RGBA max_color (ref Gee.HashMap<Gdk.RGBA?, int> histogram) {
int max = 0;
Gdk.RGBA bebra = {};
@ -35,7 +52,6 @@ public class Extension.Player : Gtk.Box {
}
private void quanitize (Gdk.Pixbuf pixbuf) {
message ("Meow");
var histogram = new Gee.HashMap<Gdk.RGBA?, int>
(
(a) => ((uint8) a.red * 255 + ((uint8) a.green * 255 << 8) + ((uint8) a.blue * 255 << 16)),
@ -69,12 +85,13 @@ public class Extension.Player : Gtk.Box {
histogram[rgba] = 1;
}
}
var colors = new Gdk.RGBA[0];
for (var i = 0; i < 10; i++) {
var c = max_color (ref histogram);
message ("%s %d %lf %lf %lf %lf", c.to_string (), histogram[c], c.alpha, c.red, c.green, c.blue);
colors += c;
histogram[c] = -1;
}
set_colors (colors);
}
private Icon ? process_pixbuff (Icon? icon) {
@ -90,7 +107,6 @@ public class Extension.Player : Gtk.Box {
return icon;
}
pixbuff = pixbuff.scale_simple (120, 120, Gdk.InterpType.BILINEAR);
message ("Processing pixbuff");
var radius = 10;
var width = pixbuff.width;
var height = pixbuff.height;
@ -128,7 +144,6 @@ public class Extension.Player : Gtk.Box {
dst = process_pixbuff ((Gdk.Pixbuf) src.get_object ());
return true;
});
message ("Found art");
break;
default :
break;

View file

@ -1,5 +1,5 @@
.nekoplayer {
background: linear-gradient(to bottom, #ff7e5f 0%, #feb47b 100%);
/* background: linear-gradient(to bottom, #ff7e5f 0%, #feb47b 100%); */
border-radius: 10px;
}