mirror of
https://github.com/elementary/gala.git
synced 2024-12-24 01:36:05 +03:00
utils: Add resize button methods and make use of them in pip
This commit is contained in:
parent
7228604095
commit
80f2ac39de
@ -25,6 +25,7 @@ namespace Gala
|
||||
static uint cache_clear_timeout = 0;
|
||||
|
||||
static Gdk.Pixbuf? close_pixbuf = null;
|
||||
static Gdk.Pixbuf? resize_pixbuf = null;
|
||||
|
||||
static construct
|
||||
{
|
||||
@ -318,6 +319,54 @@ namespace Gala
|
||||
texture.background_color = { 255, 0, 0, 255 };
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
/**
|
||||
* Returns the pixbuf that is used for resize buttons throughout gala at a
|
||||
* size of 36px
|
||||
*
|
||||
* @return the close button pixbuf or null if it failed to load
|
||||
*/
|
||||
public static Gdk.Pixbuf? get_resize_button_pixbuf ()
|
||||
{
|
||||
if (resize_pixbuf == null) {
|
||||
try {
|
||||
resize_pixbuf = new Gdk.Pixbuf.from_file_at_scale (Config.PKGDATADIR + "/resize.svg", -1, 36, true);
|
||||
} catch (Error e) {
|
||||
warning (e.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return resize_pixbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new reactive ClutterActor at 36px with the resize pixbuf
|
||||
*
|
||||
* @return The resize button actor
|
||||
*/
|
||||
public static Clutter.Actor create_resize_button ()
|
||||
{
|
||||
var texture = new Clutter.Texture ();
|
||||
var pixbuf = get_resize_button_pixbuf ();
|
||||
|
||||
texture.reactive = true;
|
||||
|
||||
if (pixbuf != null) {
|
||||
try {
|
||||
texture.set_from_rgb_data (pixbuf.get_pixels (), pixbuf.get_has_alpha (),
|
||||
pixbuf.get_width (), pixbuf.get_height (),
|
||||
pixbuf.get_rowstride (), (pixbuf.get_has_alpha () ? 4 : 3), 0);
|
||||
} catch (Error e) {}
|
||||
} else {
|
||||
// we'll just make this red so there's at least something as an
|
||||
// indicator that loading failed. Should never happen and this
|
||||
// works as good as some weird fallback-image-failed-to-load pixbuf
|
||||
texture.set_size (36, 36);
|
||||
texture.background_color = { 255, 0, 0, 255 };
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor
|
||||
private const float MAXIMUM_SCALE = 1.0f;
|
||||
private const int SCREEN_MARGIN = 0;
|
||||
|
||||
private static Clutter.Image? resize_image;
|
||||
|
||||
public signal void closed ();
|
||||
|
||||
public Gala.WindowManager wm { get; construct; }
|
||||
@ -60,27 +58,6 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor
|
||||
height = src_height * ratio;
|
||||
}
|
||||
|
||||
static Clutter.Image? get_resize_image ()
|
||||
{
|
||||
if (resize_image == null) {
|
||||
try {
|
||||
string filename = Path.build_filename (Config.PKGDATADIR, "resize.svg");
|
||||
var pixbuf = new Gdk.Pixbuf.from_file (filename);
|
||||
|
||||
resize_image = new Clutter.Image ();
|
||||
resize_image.set_data (pixbuf.get_pixels (),
|
||||
Cogl.PixelFormat.RGBA_8888,
|
||||
pixbuf.get_width (),
|
||||
pixbuf.get_height (),
|
||||
pixbuf.get_rowstride ());
|
||||
} catch (Error e) {
|
||||
warning (e.message);
|
||||
}
|
||||
}
|
||||
|
||||
return resize_image;
|
||||
}
|
||||
|
||||
static void get_current_cursor_position (out int x, out int y)
|
||||
{
|
||||
Gdk.Display.get_default ().get_device_manager ().get_client_pointer ().get_position (null, out x, out y);
|
||||
@ -151,13 +128,11 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor
|
||||
resize_handle.reactive = true;
|
||||
resize_handle.add_action (resize_action);
|
||||
|
||||
resize_button = new Clutter.Actor ();
|
||||
resize_button = Utils.create_resize_button ();
|
||||
resize_button.set_pivot_point (0.5f, 0.5f);
|
||||
resize_button.set_size (BUTTON_SIZE, BUTTON_SIZE);
|
||||
resize_button.set_position (width - BUTTON_SIZE, height - BUTTON_SIZE);
|
||||
resize_button.set_position (width - resize_button.width, height - resize_button.height);
|
||||
resize_button.opacity = 0;
|
||||
resize_button.reactive = true;
|
||||
resize_button.content = get_resize_image ();
|
||||
|
||||
add_child (container);
|
||||
add_child (close_button);
|
||||
|
Loading…
Reference in New Issue
Block a user