mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-10 23:20:54 +00:00
libsysprof-gtk: tweak rendering to use CSS named colors
We still don't want to fully rely on the CSS machinery because that would require widgets, which is far too heavy for the number of render nodes we need to regularly draw.
This commit is contained in:
@ -27,9 +27,15 @@
|
|||||||
struct _SysprofMarkChartRow
|
struct _SysprofMarkChartRow
|
||||||
{
|
{
|
||||||
GtkWidget parent_instance;
|
GtkWidget parent_instance;
|
||||||
|
|
||||||
GCancellable *cancellable;
|
GCancellable *cancellable;
|
||||||
SysprofTimeSeries *series;
|
SysprofTimeSeries *series;
|
||||||
SysprofMarkChartItem *item;
|
SysprofMarkChartItem *item;
|
||||||
|
|
||||||
|
GdkRGBA accent_fg_color;
|
||||||
|
GdkRGBA accent_bg_color;
|
||||||
|
GdkRGBA success_bg_color;
|
||||||
|
|
||||||
guint update_source;
|
guint update_source;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,18 +68,38 @@ sysprof_mark_chart_row_set_series (SysprofMarkChartRow *self,
|
|||||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_mark_chart_row_css_changed (GtkWidget *widget,
|
||||||
|
GtkCssStyleChange *change)
|
||||||
|
{
|
||||||
|
SysprofMarkChartRow *self = (SysprofMarkChartRow *)widget;
|
||||||
|
|
||||||
|
g_assert (SYSPROF_MARK_CHART_ROW (self));
|
||||||
|
|
||||||
|
GTK_WIDGET_CLASS (sysprof_mark_chart_row_parent_class)->css_changed (widget, change);
|
||||||
|
|
||||||
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||||
|
{
|
||||||
|
GtkStyleContext *style_context;
|
||||||
|
|
||||||
|
style_context = gtk_widget_get_style_context (widget);
|
||||||
|
gtk_style_context_lookup_color (style_context, "accent_bg_color", &self->accent_bg_color);
|
||||||
|
gtk_style_context_lookup_color (style_context, "accent_fg_color", &self->accent_fg_color);
|
||||||
|
gtk_style_context_lookup_color (style_context, "success_bg_color", &self->success_bg_color);
|
||||||
|
}
|
||||||
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sysprof_mark_chart_row_snapshot (GtkWidget *widget,
|
sysprof_mark_chart_row_snapshot (GtkWidget *widget,
|
||||||
GtkSnapshot *snapshot)
|
GtkSnapshot *snapshot)
|
||||||
{
|
{
|
||||||
SysprofMarkChartRow *self = (SysprofMarkChartRow *)widget;
|
SysprofMarkChartRow *self = (SysprofMarkChartRow *)widget;
|
||||||
static const GdkRGBA blue = {0,0,1,1};
|
|
||||||
static const GdkRGBA red = {1,0,0,1};
|
|
||||||
static const GdkRGBA white = {1,1,1,1};
|
|
||||||
const SysprofTimeSeriesValue *values;
|
const SysprofTimeSeriesValue *values;
|
||||||
GListModel *model;
|
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
|
GListModel *model;
|
||||||
guint n_values;
|
guint n_values;
|
||||||
|
float last_end_x;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
|
|
||||||
@ -83,17 +109,21 @@ sysprof_mark_chart_row_snapshot (GtkWidget *widget,
|
|||||||
if (self->series == NULL)
|
if (self->series == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
width = gtk_widget_get_width (widget);
|
|
||||||
height = gtk_widget_get_height (widget);
|
|
||||||
|
|
||||||
model = sysprof_time_series_get_model (self->series);
|
model = sysprof_time_series_get_model (self->series);
|
||||||
values = sysprof_time_series_get_values (self->series, &n_values);
|
values = sysprof_time_series_get_values (self->series, &n_values);
|
||||||
|
if (model == NULL || n_values == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
width = gtk_widget_get_width (widget);
|
||||||
|
height = gtk_widget_get_height (widget);
|
||||||
|
|
||||||
layout = gtk_widget_create_pango_layout (widget, NULL);
|
layout = gtk_widget_create_pango_layout (widget, NULL);
|
||||||
pango_layout_set_single_paragraph_mode (layout, TRUE);
|
pango_layout_set_single_paragraph_mode (layout, TRUE);
|
||||||
pango_layout_set_height (layout, height * PANGO_SCALE);
|
pango_layout_set_height (layout, height * PANGO_SCALE);
|
||||||
pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
|
pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
|
||||||
|
|
||||||
|
last_end_x = 0;
|
||||||
|
|
||||||
/* First pass, draw our rectangles for duration which we
|
/* First pass, draw our rectangles for duration which we
|
||||||
* always want in the background compared to "points" which
|
* always want in the background compared to "points" which
|
||||||
* are marks w/o a duration.
|
* are marks w/o a duration.
|
||||||
@ -104,15 +134,26 @@ sysprof_mark_chart_row_snapshot (GtkWidget *widget,
|
|||||||
|
|
||||||
if (v->begin != v->end)
|
if (v->begin != v->end)
|
||||||
{
|
{
|
||||||
graphene_rect_t rect = GRAPHENE_RECT_INIT (floorf (v->begin * width),
|
graphene_rect_t rect;
|
||||||
0,
|
float end_x;
|
||||||
ceilf ((v->end - v->begin) * width),
|
|
||||||
height);
|
|
||||||
|
|
||||||
|
rect = GRAPHENE_RECT_INIT (floorf (v->begin * width),
|
||||||
|
0,
|
||||||
|
ceilf ((v->end - v->begin) * width),
|
||||||
|
height);
|
||||||
|
|
||||||
|
/* Ignore empty sized draws */
|
||||||
if (rect.size.width == 0)
|
if (rect.size.width == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
gtk_snapshot_append_color (snapshot, &blue, &rect);
|
/* Cull draw unless it will extend past last rect */
|
||||||
|
end_x = rect.origin.x + rect.size.width;
|
||||||
|
if (end_x <= last_end_x)
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
last_end_x = end_x;
|
||||||
|
|
||||||
|
gtk_snapshot_append_color (snapshot, &self->accent_bg_color, &rect);
|
||||||
|
|
||||||
/* Only show the message text if the next item does
|
/* Only show the message text if the next item does
|
||||||
* not overlap and there are at least 20 pixels
|
* not overlap and there are at least 20 pixels
|
||||||
@ -138,7 +179,7 @@ sysprof_mark_chart_row_snapshot (GtkWidget *widget,
|
|||||||
height));
|
height));
|
||||||
gtk_snapshot_translate (snapshot,
|
gtk_snapshot_translate (snapshot,
|
||||||
&GRAPHENE_POINT_INIT (v->begin * width, 0));
|
&GRAPHENE_POINT_INIT (v->begin * width, 0));
|
||||||
gtk_snapshot_append_layout (snapshot, layout, &white);
|
gtk_snapshot_append_layout (snapshot, layout, &self->accent_fg_color);
|
||||||
gtk_snapshot_pop (snapshot);
|
gtk_snapshot_pop (snapshot);
|
||||||
gtk_snapshot_restore (snapshot);
|
gtk_snapshot_restore (snapshot);
|
||||||
}
|
}
|
||||||
@ -157,13 +198,13 @@ sysprof_mark_chart_row_snapshot (GtkWidget *widget,
|
|||||||
&GRAPHENE_POINT_INIT (v->begin * width, height / 2));
|
&GRAPHENE_POINT_INIT (v->begin * width, height / 2));
|
||||||
gtk_snapshot_rotate (snapshot, 45.f);
|
gtk_snapshot_rotate (snapshot, 45.f);
|
||||||
gtk_snapshot_append_color (snapshot,
|
gtk_snapshot_append_color (snapshot,
|
||||||
&red,
|
&self->success_bg_color,
|
||||||
&GRAPHENE_RECT_INIT (-4, -4, 8, 8));
|
&GRAPHENE_RECT_INIT (-4, -4, 8, 8));
|
||||||
gtk_snapshot_restore (snapshot);
|
gtk_snapshot_restore (snapshot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (layout);
|
g_clear_object (&layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -286,6 +327,7 @@ sysprof_mark_chart_row_class_init (SysprofMarkChartRowClass *klass)
|
|||||||
object_class->get_property = sysprof_mark_chart_row_get_property;
|
object_class->get_property = sysprof_mark_chart_row_get_property;
|
||||||
object_class->set_property = sysprof_mark_chart_row_set_property;
|
object_class->set_property = sysprof_mark_chart_row_set_property;
|
||||||
|
|
||||||
|
widget_class->css_changed = sysprof_mark_chart_row_css_changed;
|
||||||
widget_class->snapshot = sysprof_mark_chart_row_snapshot;
|
widget_class->snapshot = sysprof_mark_chart_row_snapshot;
|
||||||
|
|
||||||
properties [PROP_ITEM] =
|
properties [PROP_ITEM] =
|
||||||
@ -294,6 +336,8 @@ sysprof_mark_chart_row_class_init (SysprofMarkChartRowClass *klass)
|
|||||||
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||||
|
|
||||||
|
gtk_widget_class_set_css_name (widget_class, "markchartrow");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user