app: no more GimpRGB in GimpDashboard and related.

This commit is contained in:
Jehan 2023-12-26 19:11:50 +09:00
parent 6a2aee1fce
commit cfd0389c37
3 changed files with 121 additions and 82 deletions

View File

@ -210,7 +210,7 @@ struct _VariableInfo
const gchar *description;
VariableType type;
gboolean exclude_from_log;
GimpRGB color;
gdouble rgb[4];
VariableFunc sample_func;
VariableFunc reset_func;
gconstpointer data;
@ -473,7 +473,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Occupied"),
.description = N_("Tile cache occupied size"),
.type = VARIABLE_TYPE_SIZE,
.color = {0.3, 0.6, 0.3, 1.0},
.rgb = {0.3, 0.6, 0.3, 1.0},
.sample_func = gimp_dashboard_sample_gegl_stats,
.data = "tile-cache-total"
},
@ -483,7 +483,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Maximum"),
.description = N_("Maximal tile cache occupied size"),
.type = VARIABLE_TYPE_SIZE,
.color = {0.3, 0.7, 0.8, 1.0},
.rgb = {0.3, 0.7, 0.8, 1.0},
.sample_func = gimp_dashboard_sample_gegl_stats,
.data = "tile-cache-total-max"
},
@ -525,7 +525,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Occupied"),
.description = N_("Swap file occupied size"),
.type = VARIABLE_TYPE_SIZE,
.color = {0.8, 0.2, 0.2, 1.0},
.rgb = {0.8, 0.2, 0.2, 1.0},
.sample_func = gimp_dashboard_sample_gegl_stats,
.data = "swap-total"
},
@ -535,7 +535,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Size"),
.description = N_("Swap file size"),
.type = VARIABLE_TYPE_SIZE,
.color = {0.8, 0.6, 0.4, 1.0},
.rgb = {0.8, 0.6, 0.4, 1.0},
.sample_func = gimp_dashboard_sample_gegl_stats,
.data = "swap-file-size"
},
@ -553,7 +553,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Queued"),
.description = N_("Size of data queued for writing to the swap"),
.type = VARIABLE_TYPE_SIZE,
.color = {0.8, 0.8, 0.2, 0.5},
.rgb = {0.8, 0.8, 0.2, 0.5},
.sample_func = gimp_dashboard_sample_gegl_stats,
.data = "swap-queued-total"
},
@ -585,7 +585,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Read"),
.description = N_("Total amount of data read from the swap"),
.type = VARIABLE_TYPE_SIZE,
.color = {0.2, 0.4, 1.0, 0.4},
.rgb = {0.2, 0.4, 1.0, 0.4},
.sample_func = gimp_dashboard_sample_gegl_stats,
.data = "swap-read-total"
},
@ -595,7 +595,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Read throughput"),
.description = N_("The rate at which data is read from the swap"),
.type = VARIABLE_TYPE_RATE_OF_CHANGE,
.color = {0.2, 0.4, 1.0, 1.0},
.rgb = {0.2, 0.4, 1.0, 1.0},
.sample_func = gimp_dashboard_sample_variable_rate_of_change,
.data = GINT_TO_POINTER (VARIABLE_SWAP_READ)
},
@ -608,7 +608,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Written"),
.description = N_("Total amount of data written to the swap"),
.type = VARIABLE_TYPE_SIZE,
.color = {0.8, 0.3, 0.2, 0.4},
.rgb = {0.8, 0.3, 0.2, 0.4},
.sample_func = gimp_dashboard_sample_gegl_stats,
.data = "swap-write-total"
},
@ -618,7 +618,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Write throughput"),
.description = N_("The rate at which data is written to the swap"),
.type = VARIABLE_TYPE_RATE_OF_CHANGE,
.color = {0.8, 0.3, 0.2, 1.0},
.rgb = {0.8, 0.3, 0.2, 1.0},
.sample_func = gimp_dashboard_sample_variable_rate_of_change,
.data = GINT_TO_POINTER (VARIABLE_SWAP_WRITTEN)
},
@ -642,7 +642,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Usage"),
.description = N_("Total CPU usage"),
.type = VARIABLE_TYPE_PERCENTAGE,
.color = {0.8, 0.7, 0.2, 1.0},
.rgb = {0.8, 0.7, 0.2, 1.0},
.sample_func = gimp_dashboard_sample_cpu_usage
},
@ -651,7 +651,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Active"),
.description = N_("Whether the CPU is active"),
.type = VARIABLE_TYPE_BOOLEAN,
.color = {0.9, 0.8, 0.3, 1.0},
.rgb = {0.9, 0.8, 0.3, 1.0},
.sample_func = gimp_dashboard_sample_cpu_active
},
@ -660,7 +660,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Active"),
.description = N_("Total amount of time the CPU has been active"),
.type = VARIABLE_TYPE_DURATION,
.color = {0.8, 0.7, 0.2, 0.4},
.rgb = {0.8, 0.7, 0.2, 0.4},
.sample_func = gimp_dashboard_sample_cpu_active_time
},
#endif /* HAVE_CPU_GROUP */
@ -674,7 +674,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Used"),
.description = N_("Amount of memory used by the process"),
.type = VARIABLE_TYPE_SIZE,
.color = {0.8, 0.5, 0.2, 1.0},
.rgb = {0.8, 0.5, 0.2, 1.0},
.sample_func = gimp_dashboard_sample_memory_used
},
@ -683,7 +683,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Available"),
.description = N_("Amount of available physical memory"),
.type = VARIABLE_TYPE_SIZE,
.color = {0.8, 0.5, 0.2, 0.4},
.rgb = {0.8, 0.5, 0.2, 0.4},
.sample_func = gimp_dashboard_sample_memory_available
},
@ -740,7 +740,7 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Tile"),
.description = N_("Total size of tile memory"),
.type = VARIABLE_TYPE_SIZE,
.color = {0.3, 0.3, 1.0, 1.0},
.rgb = {0.3, 0.3, 1.0, 1.0},
.sample_func = gimp_dashboard_sample_gegl_stats,
.data = "tile-alloc-total"
},
@ -1218,7 +1218,9 @@ gimp_dashboard_init (GimpDashboard *dashboard)
/* group meter */
if (group_info->has_meter)
{
meter = gimp_meter_new (group_data->n_meter_values);
GeglColor *color = gegl_color_new (NULL);
meter = gimp_meter_new (priv->gimp, group_data->n_meter_values);
group_data->meter = GIMP_METER (meter);
gimp_help_set_help_data (meter,
g_dgettext (NULL, group_info->description),
@ -1238,9 +1240,11 @@ gimp_dashboard_init (GimpDashboard *dashboard)
{
const VariableInfo *variable_info = &variables[field_info->variable];
gegl_color_set_pixel (color, babl_format ("R'G'B'A double"), variable_info->rgb);
gimp_meter_set_value_color (GIMP_METER (meter),
field_info->meter_value - 1,
&variable_info->color);
color);
if (gimp_dashboard_field_use_meter_underlay (group, field))
{
@ -1253,6 +1257,8 @@ gimp_dashboard_init (GimpDashboard *dashboard)
}
}
}
g_object_unref (color);
}
/* group grid */
@ -2907,7 +2913,7 @@ gimp_dashboard_update_group (GimpDashboard *dashboard,
{
GeglColor *color = gegl_color_new (NULL);
gegl_color_set_pixel (color, babl_format ("R'G'B'A double"), &variable_info->color);
gegl_color_set_pixel (color, babl_format ("R'G'B'A double"), variable_info->rgb);
color_area = gimp_color_area_new (color, GIMP_COLOR_AREA_FLAT, 0);
gimp_help_set_help_data (color_area, description,
NULL);
@ -3011,7 +3017,7 @@ gimp_dashboard_update_group_values (GimpDashboard *dashboard,
if (group_info->meter_led)
{
GimpRGB color = {0.0, 0.0, 0.0, 1.0};
gdouble rgb[3] = {0.0, 0.0, 0.0};
gboolean active = FALSE;
const Variable *var;
@ -3021,16 +3027,22 @@ gimp_dashboard_update_group_values (GimpDashboard *dashboard,
{
const VariableInfo *variable_info = &variables[*var];
color.r = MAX (color.r, variable_info->color.r);
color.g = MAX (color.g, variable_info->color.g);
color.b = MAX (color.b, variable_info->color.b);
rgb[0] = MAX (rgb[0], variable_info->rgb[0]);
rgb[1] = MAX (rgb[1], variable_info->rgb[1]);
rgb[2] = MAX (rgb[2], variable_info->rgb[2]);
active = TRUE;
}
}
if (active)
gimp_meter_set_led_color (group_data->meter, &color);
{
GeglColor *color = gegl_color_new (NULL);
gegl_color_set_pixel (color, babl_format ("R'G'B' double"), rgb);
gimp_meter_set_led_color (group_data->meter, color);
g_object_unref (color);
}
gimp_meter_set_led_active (group_data->meter, active);
}

View File

@ -32,6 +32,10 @@
#include "widgets-types.h"
#include "config/gimpcoreconfig.h"
#include "core/gimp.h"
#include "gimpmeter.h"
@ -65,36 +69,37 @@ enum
typedef struct
{
gboolean active;
gboolean show_in_gauge;
gboolean show_in_history;
GimpRGB color;
GimpInterpolationType interpolation;
gboolean active;
gboolean show_in_gauge;
gboolean show_in_history;
GeglColor *color;
GimpInterpolationType interpolation;
} Value;
struct _GimpMeterPrivate
{
GMutex mutex;
Gimp *gimp;
GMutex mutex;
gint size;
gdouble refresh_rate;
gdouble range_min;
gdouble range_max;
gint n_values;
Value *values;
gboolean history_visible;
gdouble history_duration;
gdouble history_resolution;
gboolean led_active;
GimpRGB led_color;
gint size;
gdouble refresh_rate;
gdouble range_min;
gdouble range_max;
gint n_values;
Value *values;
gboolean history_visible;
gdouble history_duration;
gdouble history_resolution;
gboolean led_active;
GeglColor *led_color;
gdouble *samples;
gint n_samples;
gint sample_duration;
gint64 last_sample_time;
gint64 current_time;
gdouble *uniform_sample;
gint timeout_id;
gdouble *samples;
gint n_samples;
gint sample_duration;
gint64 last_sample_time;
gint64 current_time;
gdouble *uniform_sample;
gint timeout_id;
};
@ -223,11 +228,11 @@ gimp_meter_class_init (GimpMeterClass *klass)
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_LED_COLOR,
gimp_param_spec_rgb ("led-color",
NULL, NULL,
TRUE, &(GimpRGB) {},
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
gegl_param_spec_color_from_string ("led-color",
NULL, NULL,
/*TRUE,*/ "red",
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
}
static void
@ -253,6 +258,8 @@ gimp_meter_dispose (GObject *object)
{
GimpMeter *meter = GIMP_METER (object);
for (gint i = 0; i < meter->priv->n_values; i++)
g_clear_object (&meter->priv->values[i].color);
g_clear_pointer (&meter->priv->values, g_free);
g_clear_pointer (&meter->priv->samples, g_free);
g_clear_pointer (&meter->priv->uniform_sample, g_free);
@ -272,6 +279,7 @@ gimp_meter_finalize (GObject *object)
GimpMeter *meter = GIMP_METER (object);
g_mutex_clear (&meter->priv->mutex);
g_clear_object (&meter->priv->led_color);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -327,7 +335,7 @@ gimp_meter_set_property (GObject *object,
break;
case PROP_LED_COLOR:
gimp_meter_set_led_color (meter, g_value_get_boxed (value));
gimp_meter_set_led_color (meter, g_value_get_object (value));
break;
default:
@ -383,7 +391,7 @@ gimp_meter_get_property (GObject *object,
break;
case PROP_LED_COLOR:
g_value_set_boxed (value, gimp_meter_get_led_color (meter));
g_value_set_object (value, gimp_meter_get_led_color (meter));
break;
default:
@ -483,7 +491,9 @@ gimp_meter_draw (GtkWidget *widget,
0.06 * size,
0.0 * REV, 1.0 * REV);
gimp_cairo_set_source_rgba (cr, &meter->priv->led_color);
gimp_cairo_set_source_color (cr, meter->priv->led_color,
meter->priv->gimp->config->color_management,
FALSE, widget);
cairo_fill (cr);
}
@ -516,7 +526,9 @@ gimp_meter_draw (GtkWidget *widget,
continue;
}
gimp_cairo_set_source_rgba (cr, &meter->priv->values[i].color);
gimp_cairo_set_source_color (cr, meter->priv->values[i].color,
meter->priv->gimp->config->color_management,
FALSE, widget);
cairo_move_to (cr, 0.0, 0.0);
cairo_arc (cr,
0.0, 0.0,
@ -620,7 +632,9 @@ gimp_meter_draw (GtkWidget *widget,
continue;
}
gimp_cairo_set_source_rgba (cr, &meter->priv->values[i].color);
gimp_cairo_set_source_color (cr, meter->priv->values[i].color,
meter->priv->gimp->config->color_management,
FALSE, widget);
cairo_move_to (cr, 0.0, 0.0);
switch (meter->priv->values[i].interpolation)
@ -865,11 +879,17 @@ gimp_meter_mask_sample (GimpMeter *meter,
GtkWidget *
gimp_meter_new (gint n_values)
gimp_meter_new (Gimp *gimp,
gint n_values)
{
return g_object_new (GIMP_TYPE_METER,
"n-values", n_values,
NULL);
GimpMeter *meter;
meter = g_object_new (GIMP_TYPE_METER,
"n-values", n_values,
NULL);
meter->priv->gimp = gimp;
return GTK_WIDGET (meter);
}
void
@ -993,6 +1013,9 @@ gimp_meter_set_n_values (GimpMeter *meter,
{
g_mutex_lock (&meter->priv->mutex);
for (gint i = n_values; i < meter->priv->n_values; i++)
g_clear_object (&meter->priv->values[i].color);
meter->priv->values = g_renew (Value, meter->priv->values, n_values);
if (n_values > meter->priv->n_values)
@ -1001,6 +1024,7 @@ gimp_meter_set_n_values (GimpMeter *meter,
&(Value) { .active = TRUE,
.show_in_gauge = TRUE,
.show_in_history = TRUE,
.color = NULL,
.interpolation = GIMP_INTERPOLATION_CUBIC},
sizeof (Value),
n_values - meter->priv->n_values);
@ -1054,30 +1078,31 @@ gimp_meter_get_value_active (GimpMeter *meter,
void
gimp_meter_set_value_color (GimpMeter *meter,
gint value,
const GimpRGB *color)
gimp_meter_set_value_color (GimpMeter *meter,
gint value,
GeglColor *color)
{
g_return_if_fail (GIMP_IS_METER (meter));
g_return_if_fail (value >= 0 && value < meter->priv->n_values);
g_return_if_fail (color != NULL);
g_return_if_fail (GEGL_IS_COLOR (color));
if (memcmp (color, &meter->priv->values[value].color, sizeof (GimpRGB)))
if (! gimp_color_is_perceptually_identical (color, meter->priv->values[value].color))
{
meter->priv->values[value].color = *color;
g_clear_object (&meter->priv->values[value].color);
meter->priv->values[value].color = gegl_color_duplicate (color);
gtk_widget_queue_draw (GTK_WIDGET (meter));
}
}
const GimpRGB *
GeglColor *
gimp_meter_get_value_color (GimpMeter *meter,
gint value)
{
g_return_val_if_fail (GIMP_IS_METER (meter), NULL);
g_return_val_if_fail (value >= 0 && value < meter->priv->n_values, NULL);
return &meter->priv->values[value].color;
return meter->priv->values[value].color;
}
void
@ -1296,15 +1321,16 @@ gimp_meter_get_led_active (GimpMeter *meter)
}
void
gimp_meter_set_led_color (GimpMeter *meter,
const GimpRGB *color)
gimp_meter_set_led_color (GimpMeter *meter,
GeglColor *color)
{
g_return_if_fail (GIMP_IS_METER (meter));
g_return_if_fail (color != NULL);
g_return_if_fail (GEGL_IS_COLOR (color));
if (memcmp (color, &meter->priv->led_color, sizeof (GimpRGB)))
if (! gimp_color_is_perceptually_identical (color, meter->priv->led_color))
{
meter->priv->led_color = *color;
g_clear_object (&meter->priv->led_color);
meter->priv->led_color = gegl_color_duplicate (color);
if (meter->priv->led_active)
gtk_widget_queue_draw (GTK_WIDGET (meter));
@ -1313,10 +1339,10 @@ gimp_meter_set_led_color (GimpMeter *meter,
}
}
const GimpRGB *
GeglColor *
gimp_meter_get_led_color (GimpMeter *meter)
{
g_return_val_if_fail (GIMP_IS_METER (meter), NULL);
return &meter->priv->led_color;
return meter->priv->led_color;
}

View File

@ -48,7 +48,8 @@ struct _GimpMeterClass
GType gimp_meter_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_meter_new (gint n_values);
GtkWidget * gimp_meter_new (Gimp *gimp,
gint n_values);
void gimp_meter_set_size (GimpMeter *meter,
gint size);
@ -88,8 +89,8 @@ gboolean gimp_meter_get_value_show_in_history (GimpMeter
void gimp_meter_set_value_color (GimpMeter *meter,
gint value,
const GimpRGB *color);
const GimpRGB * gimp_meter_get_value_color (GimpMeter *meter,
GeglColor *color);
GeglColor * gimp_meter_get_value_color (GimpMeter *meter,
gint value);
void gimp_meter_set_value_interpolation (GimpMeter *meter,
@ -120,8 +121,8 @@ void gimp_meter_set_led_active (GimpMeter
gboolean gimp_meter_get_led_active (GimpMeter *meter);
void gimp_meter_set_led_color (GimpMeter *meter,
const GimpRGB *color);
const GimpRGB * gimp_meter_get_led_color (GimpMeter *meter);
GeglColor *color);
GeglColor * gimp_meter_get_led_color (GimpMeter *meter);
#endif /* __GIMP_METER_H__ */