@@ -11,8 +11,7 @@ public class Gala.CloseButton : Clutter.Actor {
1111
1212 public float monitor_scale { get ; construct set ; }
1313
14- // used to avoid changing hitbox of the button
15- private Clutter . Actor pixbuf_actor;
14+ private Icon icon;
1615 private Clutter . ClickAction click_action;
1716
1817 static construct {
@@ -26,18 +25,18 @@ public class Gala.CloseButton : Clutter.Actor {
2625 construct {
2726 reactive = true ;
2827
29- pixbuf_actor = new Clutter .Actor () {
28+ icon = new Icon .from_resource (
29+ Utils . BUTTON_SIZE , monitor_scale,
30+ " /org/pantheon/desktop/gala/buttons/close.svg"
31+ ) {
3032 pivot_point = { 0.5f , 0.5f }
3133 };
32- add_child (pixbuf_actor );
34+ add_child (icon );
3335
3436 click_action = new Clutter .ClickAction ();
3537 add_action (click_action);
3638 click_action. clicked. connect (on_clicked);
3739 click_action. notify[" pressed" ]. connect (on_pressed_changed);
38-
39- load_pixbuf ();
40- notify[" monitor-scale" ]. connect (load_pixbuf);
4140 }
4241
4342 private void on_clicked () {
@@ -48,53 +47,10 @@ public class Gala.CloseButton : Clutter.Actor {
4847 var estimated_duration = Utils . get_animation_duration ((uint ) (ANIMATION_DURATION * (scale_x - 0.8 ) / 0.2 ));
4948 var scale = click_action. pressed ? 0.8 : 1.0 ;
5049
51- pixbuf_actor. save_easing_state ();
52- pixbuf_actor. set_easing_duration (estimated_duration);
53- pixbuf_actor. set_easing_mode (Clutter . AnimationMode . EASE_IN_OUT );
54- pixbuf_actor. set_scale (scale, scale);
55- pixbuf_actor. restore_easing_state ();
56- }
57-
58- private void load_pixbuf () {
59- var pixbuf = get_close_button_pixbuf (monitor_scale);
60- if (pixbuf != null ) {
61- var image = new Gala .Image .from_pixbuf (pixbuf);
62- pixbuf_actor. set_content (image);
63- pixbuf_actor. set_size (pixbuf. width, pixbuf. height);
64- set_size (pixbuf. width, pixbuf. height);
65- } else {
66- create_error_texture ();
67- }
68- }
69-
70- private static Gdk . Pixbuf ? get_close_button_pixbuf (float monitor_scale) {
71- var height = Utils . calculate_button_size (monitor_scale);
72-
73- if (close_pixbufs[height] == null ) {
74- try {
75- close_pixbufs[height] = new Gdk .Pixbuf .from_resource_at_scale (
76- " /org/pantheon/desktop/gala/buttons/close.svg" ,
77- - 1 ,
78- height,
79- true
80- );
81- } catch (Error e) {
82- critical (e. message);
83- return null ;
84- }
85- }
86-
87- return close_pixbufs[height];
88- }
89-
90- private void create_error_texture () {
91- // we'll just make this red so there's at least something as an
92- // indicator that loading failed. Should never happen and this
93- // works as good as some weird fallback-image-failed-to-load pixbuf
94- critical (" Could not create close button" );
95-
96- var size = Utils . calculate_button_size (monitor_scale);
97- pixbuf_actor. set_size (size, size);
98- pixbuf_actor. background_color = { 255 , 0 , 0 , 255 };
50+ icon. save_easing_state ();
51+ icon. set_easing_duration (estimated_duration);
52+ icon. set_easing_mode (Clutter . AnimationMode . EASE_IN_OUT );
53+ icon. set_scale (scale, scale);
54+ icon. restore_easing_state ();
9955 }
10056}
0 commit comments