mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-gtk: make accent fg/bg color available internally
This does more work than it should have to since we are reading the color repeatedly, but it's still better than the data being stored per-instance.
This commit is contained in:
30
src/libsysprof-gtk/sysprof-chart-layer-private.h
Normal file
30
src/libsysprof-gtk/sysprof-chart-layer-private.h
Normal file
@ -0,0 +1,30 @@
|
||||
/* sysprof-chart-layer-private.h
|
||||
*
|
||||
* Copyright 2023 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sysprof-chart-layer.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
const GdkRGBA *_sysprof_chart_layer_get_accent_bg_color (void);
|
||||
const GdkRGBA *_sysprof_chart_layer_get_accent_fg_color (void);
|
||||
|
||||
G_END_DECLS
|
||||
@ -20,7 +20,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "sysprof-chart-layer.h"
|
||||
#include "sysprof-chart-layer-private.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -36,6 +36,24 @@ enum {
|
||||
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (SysprofChartLayer, sysprof_chart_layer, GTK_TYPE_WIDGET)
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
static GdkRGBA accent_fg_color;
|
||||
static GdkRGBA accent_bg_color;
|
||||
|
||||
static void
|
||||
sysprof_chart_layer_css_changed (GtkWidget *widget,
|
||||
GtkCssStyleChange *change)
|
||||
{
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
GtkStyleContext *style_context;
|
||||
|
||||
GTK_WIDGET_CLASS (sysprof_chart_layer_parent_class)->css_changed (widget, change);
|
||||
|
||||
style_context = gtk_widget_get_style_context (widget);
|
||||
|
||||
gtk_style_context_lookup_color (style_context, "accent_fg_color", &accent_fg_color);
|
||||
gtk_style_context_lookup_color (style_context, "accent_bg_color", &accent_bg_color);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_chart_layer_dispose (GObject *object)
|
||||
@ -96,6 +114,8 @@ sysprof_chart_layer_class_init (SysprofChartLayerClass *klass)
|
||||
object_class->get_property = sysprof_chart_layer_get_property;
|
||||
object_class->set_property = sysprof_chart_layer_set_property;
|
||||
|
||||
widget_class->css_changed = sysprof_chart_layer_css_changed;
|
||||
|
||||
properties[PROP_TITLE] =
|
||||
g_param_spec_string ("title", NULL, NULL,
|
||||
NULL,
|
||||
@ -171,3 +191,15 @@ sysprof_chart_layer_lookup_item (SysprofChartLayer *self,
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const GdkRGBA *
|
||||
_sysprof_chart_layer_get_accent_bg_color (void)
|
||||
{
|
||||
return &accent_bg_color;
|
||||
}
|
||||
|
||||
const GdkRGBA *
|
||||
_sysprof_chart_layer_get_accent_fg_color (void)
|
||||
{
|
||||
return &accent_fg_color;
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "sysprof-axis.h"
|
||||
#include "sysprof-chart-layer-private.h"
|
||||
#include "sysprof-column-layer.h"
|
||||
#include "sysprof-normalized-series.h"
|
||||
#include "sysprof-xy-layer-private.h"
|
||||
@ -28,8 +29,12 @@
|
||||
struct _SysprofColumnLayer
|
||||
{
|
||||
SysprofXYLayer parent_instance;
|
||||
|
||||
GdkRGBA color;
|
||||
GdkRGBA hover_color;
|
||||
|
||||
guint color_set : 1;
|
||||
guint hover_color_set : 1;
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -51,6 +56,7 @@ sysprof_column_layer_snapshot (GtkWidget *widget,
|
||||
graphene_matrix_t flip_y;
|
||||
const float *x_values;
|
||||
const float *y_values;
|
||||
const GdkRGBA *color;
|
||||
guint n_values;
|
||||
int width;
|
||||
int height;
|
||||
@ -66,6 +72,11 @@ sysprof_column_layer_snapshot (GtkWidget *widget,
|
||||
if (width == 0 || height == 0 || n_values == 0 || self->color.alpha == 0)
|
||||
return;
|
||||
|
||||
if (self->color_set)
|
||||
color = &self->color;
|
||||
else
|
||||
color = _sysprof_chart_layer_get_accent_bg_color ();
|
||||
|
||||
gtk_snapshot_save (snapshot);
|
||||
|
||||
graphene_matrix_init_from_2d (&flip_y, 1, 0, 0, -1, 0, height);
|
||||
@ -76,7 +87,7 @@ sysprof_column_layer_snapshot (GtkWidget *widget,
|
||||
int line_height = ceilf (y_values[i] * height);
|
||||
|
||||
gtk_snapshot_append_color (snapshot,
|
||||
&self->color,
|
||||
color,
|
||||
&GRAPHENE_RECT_INIT (x_values[i] * width,
|
||||
0,
|
||||
1,
|
||||
@ -255,8 +266,8 @@ sysprof_column_layer_class_init (SysprofColumnLayerClass *klass)
|
||||
static void
|
||||
sysprof_column_layer_init (SysprofColumnLayer *self)
|
||||
{
|
||||
gdk_rgba_parse (&self->color, "#000");
|
||||
gdk_rgba_parse (&self->hover_color, "#F00");
|
||||
self->color = (GdkRGBA) {0,0,0,1};
|
||||
self->hover_color = (GdkRGBA) {1,0,0,1};
|
||||
}
|
||||
|
||||
SysprofChartLayer *
|
||||
@ -287,6 +298,7 @@ sysprof_column_layer_set_color (SysprofColumnLayer *self,
|
||||
if (!gdk_rgba_equal (&self->color, color))
|
||||
{
|
||||
self->color = *color;
|
||||
self->color_set = color != &black;
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COLOR]);
|
||||
|
||||
@ -316,6 +328,7 @@ sysprof_column_layer_set_hover_color (SysprofColumnLayer *self,
|
||||
if (!gdk_rgba_equal (&self->hover_color, hover_color))
|
||||
{
|
||||
self->hover_color = *hover_color;
|
||||
self->hover_color_set = hover_color != &red;
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_HOVER_COLOR]);
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "sysprof-chart-layer-private.h"
|
||||
#include "sysprof-line-layer.h"
|
||||
#include "sysprof-xy-layer-private.h"
|
||||
|
||||
@ -55,8 +56,6 @@ enum {
|
||||
};
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
static GdkRGBA accent_bg_color;
|
||||
static GdkRGBA accent_fg_color;
|
||||
|
||||
SysprofChartLayer *
|
||||
sysprof_line_layer_new (void)
|
||||
@ -71,7 +70,7 @@ sysprof_line_layer_snapshot (GtkWidget *widget,
|
||||
SysprofLineLayer *self = (SysprofLineLayer *)widget;
|
||||
const float *x_values;
|
||||
const float *y_values;
|
||||
GdkRGBA *color;
|
||||
const GdkRGBA *color;
|
||||
cairo_t *cr;
|
||||
float first_x;
|
||||
float first_y;
|
||||
@ -95,7 +94,7 @@ sysprof_line_layer_snapshot (GtkWidget *widget,
|
||||
if (self->color_set)
|
||||
color = &self->color;
|
||||
else
|
||||
color = &accent_bg_color;
|
||||
color = _sysprof_chart_layer_get_accent_bg_color ();
|
||||
|
||||
cr = gtk_snapshot_append_cairo (snapshot, &GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||
|
||||
@ -163,22 +162,6 @@ sysprof_line_layer_snapshot (GtkWidget *widget,
|
||||
cairo_destroy (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_line_layer_css_changed (GtkWidget *widget,
|
||||
GtkCssStyleChange *css_change)
|
||||
{
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
GtkStyleContext *style_context;
|
||||
|
||||
GTK_WIDGET_CLASS (sysprof_line_layer_parent_class)->css_changed (widget, css_change);
|
||||
|
||||
style_context = gtk_widget_get_style_context (widget);
|
||||
|
||||
gtk_style_context_lookup_color (style_context, "accent_fg_color", &accent_fg_color);
|
||||
gtk_style_context_lookup_color (style_context, "accent_bg_color", &accent_bg_color);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_line_layer_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
@ -259,7 +242,6 @@ sysprof_line_layer_class_init (SysprofLineLayerClass *klass)
|
||||
object_class->set_property = sysprof_line_layer_set_property;
|
||||
|
||||
widget_class->snapshot = sysprof_line_layer_snapshot;
|
||||
widget_class->css_changed = sysprof_line_layer_css_changed;
|
||||
|
||||
properties[PROP_COLOR] =
|
||||
g_param_spec_boxed ("color", NULL, NULL,
|
||||
|
||||
Reference in New Issue
Block a user