utils.vala 2.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
namespace Usage
{
    public class Utils
    {
        public static string format_size_values(uint64 value)
        {
            if(value >= 1000000000000)
                return "%.3f TB".printf((double) value / 1000000000000d);
            else if(value >= 1000000000)
                return "%.1f GB".printf((double) value / 1000000000d);
            else if(value >= 1000000)
                return(value / 1000000).to_string() + " MB";
            else if(value >= 1000)
                return (value / 1000).to_string() + " KB";
            else
                return value.to_string() + " B";
        }
18 19 20 21 22 23 24 25 26 27 28 29 30 31

        public static string format_size_speed_values(uint64 value)
        {
            if(value >= 1000000000000)
                return "%.3f TB/s".printf((double) value / 1000000000000d);
            else if(value >= 1000000000)
                return "%.1f GB/s".printf((double) value / 1000000000d);
            else if(value >= 1000000)
                return "%.2f MB/s".printf((double) value / 1000000d);
            else if(value >= 1000)
                return (value / 1000).to_string() + " KB/s";
            else
                return value.to_string() + " B/s";
        }
Petr Štětka's avatar
Petr Štětka committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

        public static Gdk.RGBA color_darker(Gdk.RGBA color, double percentage)
        {
            color.red = color_field_darker(color.red, percentage);
            color.green = color_field_darker(color.green, percentage);
            color.blue = color_field_darker(color.blue, percentage);

            return color;
        }

        public static Gdk.RGBA color_lighter(Gdk.RGBA color, double percentage)
        {
            color.red = color_field_lighter(color.red, percentage);
            color.green = color_field_lighter(color.green, percentage);
            color.blue = color_field_lighter(color.blue, percentage);

            return color;
        }

        private static double color_field_darker(double field, double percentage)
        {
            field = field * 255;
            return (field - ((field / 100) * percentage)) / 255;
        }

        private static double color_field_lighter(double field, double percentage)
        {
            field = field * 255;
            return (field + (((255 - field) / 100) * percentage)) / 255;
        }
62 63
    }
}