[Xfce4-commits] [apps/xfce4-taskmanager] 02/06: Hardcode the graph colors and simplify the drawing routines
noreply at xfce.org
noreply at xfce.org
Wed Dec 17 21:04:20 CET 2014
This is an automated email from the git hooks/post-receive script.
landry pushed a commit to branch master
in repository apps/xfce4-taskmanager.
commit abb5f97740f4490e5455d9ad587f1550e0533ef4
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date: Wed Dec 17 10:38:32 2014 +0100
Hardcode the graph colors and simplify the drawing routines
---
src/process-monitor.c | 160 ++++++++-----------------------------------------
src/process-monitor.h | 2 -
2 files changed, 25 insertions(+), 137 deletions(-)
diff --git a/src/process-monitor.c b/src/process-monitor.c
index 0ef954b..3bea77d 100644
--- a/src/process-monitor.c
+++ b/src/process-monitor.c
@@ -21,9 +21,6 @@
enum
{
PROP_STEP_SIZE = 1,
- PROP_COLOR_RED,
- PROP_COLOR_GREEN,
- PROP_COLOR_BLUE,
PROP_PAINT_BOX,
};
typedef struct _XtmProcessMonitorClass XtmProcessMonitorClass;
@@ -37,9 +34,6 @@ struct _XtmProcessMonitor
/*<private>*/
gfloat step_size;
GArray * history;
- gfloat color_red;
- gfloat color_green;
- gfloat color_blue;
gboolean paint_box;
};
G_DEFINE_TYPE (XtmProcessMonitor, xtm_process_monitor, GTK_TYPE_DRAWING_AREA)
@@ -66,37 +60,14 @@ xtm_process_monitor_class_init (XtmProcessMonitorClass *klass)
#endif
g_object_class_install_property (class, PROP_STEP_SIZE,
g_param_spec_float ("step-size", "StepSize", "Step size", 0.1, G_MAXFLOAT, 1, G_PARAM_CONSTRUCT|G_PARAM_READWRITE));
- g_object_class_install_property (class, PROP_COLOR_RED,
- g_param_spec_float ("color-red", "ColorRed", "Color red", 0, 1, 0, G_PARAM_READWRITE));
- g_object_class_install_property (class, PROP_COLOR_GREEN,
- g_param_spec_float ("color-green", "ColorGreen", "Color green", 0, 1, 0, G_PARAM_READWRITE));
- g_object_class_install_property (class, PROP_COLOR_BLUE,
- g_param_spec_float ("color-blue", "ColorBlue", "Color blue", 0, 1, 0, G_PARAM_READWRITE));
g_object_class_install_property (class, PROP_PAINT_BOX,
g_param_spec_boolean ("paint-box", "PaintBox", "Paint box around monitor", TRUE, G_PARAM_CONSTRUCT|G_PARAM_READWRITE));
}
static void
-init_source_color (GtkWidget *widget, GtkStyle *prev_style, gpointer user_data)
-{
-#ifdef HAVE_GTK3
- GdkColor *color;
-/*
- gdk_color_parse("red", color);
-*/
-#else
- GdkColor *color = &widget->style->base[GTK_STATE_SELECTED];
- XTM_PROCESS_MONITOR (widget)->color_red = color->red / 65535.0;
- XTM_PROCESS_MONITOR (widget)->color_green = color->green / 65535.0;
- XTM_PROCESS_MONITOR (widget)->color_blue = color->blue / 65535.0;
-#endif
-}
-
-static void
xtm_process_monitor_init (XtmProcessMonitor *monitor)
{
monitor->history = g_array_new (FALSE, TRUE, sizeof (gfloat));
- g_signal_connect (monitor, "style-set", G_CALLBACK (init_source_color), NULL);
}
static void
@@ -109,18 +80,6 @@ xtm_process_monitor_get_property (GObject *object, guint property_id, GValue *va
g_value_set_float (value, monitor->step_size);
break;
- case PROP_COLOR_RED:
- g_value_set_float (value, monitor->color_red);
- break;
-
- case PROP_COLOR_GREEN:
- g_value_set_float (value, monitor->color_green);
- break;
-
- case PROP_COLOR_BLUE:
- g_value_set_float (value, monitor->color_blue);
- break;
-
case PROP_PAINT_BOX:
g_value_set_boolean (value, monitor->paint_box);
break;
@@ -141,18 +100,6 @@ xtm_process_monitor_set_property (GObject *object, guint property_id, const GVal
monitor->step_size = g_value_get_float (value);
break;
- case PROP_COLOR_RED:
- monitor->color_red = g_value_get_float (value);
- break;
-
- case PROP_COLOR_GREEN:
- monitor->color_green = g_value_get_float (value);
- break;
-
- case PROP_COLOR_BLUE:
- monitor->color_blue = g_value_get_float (value);
- break;
-
case PROP_PAINT_BOX:
monitor->paint_box = g_value_get_boolean (value);
break;
@@ -182,14 +129,12 @@ xtm_process_monitor_expose (GtkWidget *widget, GdkEventExpose *event)
}
static cairo_surface_t *
-xtm_process_monitor_graph_surface_create (XtmProcessMonitor *monitor)
+xtm_process_monitor_graph_surface_create (XtmProcessMonitor *monitor, gint width, gint height)
{
cairo_t *cr;
cairo_surface_t *graph_surface;
- cairo_pattern_t *linpat;
gfloat *peak;
gfloat step_size;
- gint width, height;
gint i;
if (monitor->history->len <= 1)
@@ -197,25 +142,13 @@ xtm_process_monitor_graph_surface_create (XtmProcessMonitor *monitor)
g_warning ("Cannot paint graph with n_peak <= 1");
return NULL;
}
-
-#ifdef HAVE_GTK3
- width = gtk_widget_get_allocated_width(GTK_WIDGET(monitor));
- height = gtk_widget_get_allocated_height(GTK_WIDGET(monitor));
-#else
- width = GTK_WIDGET (monitor)->allocation.width;
- height = GTK_WIDGET (monitor)->allocation.height;
-#endif
step_size = monitor->step_size;
graph_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
cr = cairo_create (graph_surface);
- /* Draw area */
- linpat = cairo_pattern_create_linear (0, 0, 0, height);
- cairo_pattern_add_color_stop_rgba (linpat, 0.4, monitor->color_red, monitor->color_green, monitor->color_blue, 0.3);
- cairo_pattern_add_color_stop_rgba (linpat, 0.9, monitor->color_red, monitor->color_green, monitor->color_blue, 0.5);
- cairo_pattern_add_color_stop_rgba (linpat, 1, monitor->color_red, monitor->color_green, monitor->color_blue, 0.6);
- cairo_set_source (cr, linpat);
+ /* Draw area below the line */
+ cairo_set_source_rgba (cr, 1.0, 0.43, 0.0, 0.3);
cairo_set_line_width (cr, 0.0);
cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
@@ -230,12 +163,10 @@ xtm_process_monitor_graph_surface_create (XtmProcessMonitor *monitor)
cairo_line_to (cr, width, height);
cairo_fill (cr);
- cairo_pattern_destroy (linpat);
-
/* Draw line */
cairo_translate (cr, step_size * i, 0);
- cairo_set_source_rgb (cr, monitor->color_red, monitor->color_green, monitor->color_blue);
+ cairo_set_source_rgba (cr, 1.0, 0.43, 0.0, 1.0);
cairo_set_line_width (cr, 0.85);
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
@@ -260,6 +191,7 @@ xtm_process_monitor_paint (XtmProcessMonitor *monitor)
cairo_t *cr;
cairo_surface_t *graph_surface;
gint width, height;
+ static const double dashed[] = {1.5};
gint i;
cr = gdk_cairo_create (gtk_widget_get_window(GTK_WIDGET(monitor)));
#ifdef HAVE_GTK3
@@ -270,65 +202,33 @@ xtm_process_monitor_paint (XtmProcessMonitor *monitor)
height = GTK_WIDGET (monitor)->allocation.height;
#endif
- /* Paint a box */
- if (monitor->paint_box)
-#ifdef HAVE_GTK3
- gtk_paint_box (gtk_widget_get_style(GTK_WIDGET(monitor)), cr, GTK_STATE_PRELIGHT, GTK_SHADOW_IN,
- GTK_WIDGET (monitor), "trough", 0, 0, width, height);
-#else
- gtk_paint_box (gtk_widget_get_style(GTK_WIDGET(monitor)), gtk_widget_get_window(GTK_WIDGET(monitor)), GTK_STATE_PRELIGHT, GTK_SHADOW_IN,
- NULL, GTK_WIDGET (monitor), "trough", 0, 0, width, height);
-#endif
- /* Paint the graph */
- graph_surface = xtm_process_monitor_graph_surface_create (monitor);
- if (graph_surface != NULL)
- {
- cairo_set_source_surface (cr, graph_surface, 0.0, 0.0);
- cairo_paint (cr);
- cairo_surface_destroy (graph_surface);
- }
-
- /* Trace some marks */
+ /* Paint the graph's background box */
+ cairo_rectangle (cr, 0.0, 0.0, width, height);
+ cairo_set_source_rgb (cr, 0.96, 0.96, 0.96);
+ cairo_fill_preserve (cr);
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
cairo_set_line_width (cr, 0.75);
- cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
- cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
- cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
- for (i = 10; i < 100; i += 10)
- {
- cairo_move_to (cr, 0.0, i * height / 100);
- cairo_line_to (cr, width, i * height / 100);
- }
cairo_stroke (cr);
-
-#ifdef HAVE_GTK3
- GdkColor *color;
-/*
- gdk_color_parse("red", color);
- gdk_cairo_set_source_color (cr, color);
-*/
-#else
- gdk_cairo_set_source_color (cr, >K_WIDGET (monitor)->style->fg[GTK_STATE_NORMAL]);
-#endif
- cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
+
+ /* Paint dashed lines at 25%, 50% and 75% */
+ cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.3);
cairo_set_line_width (cr, 1.0);
+ cairo_set_dash(cr, dashed, 1.0, 0);
for (i = 25; i <= 75; i += 25)
{
- cairo_move_to (cr, 0.0, i * height / 100);
- cairo_line_to (cr, 4.0, i * height / 100);
- cairo_move_to (cr, width, i * height / 100);
- cairo_line_to (cr, width - 4.0, i * height / 100);
+ cairo_move_to (cr, 1.5, i * height / 100 + 0.5);
+ cairo_line_to (cr, width - 0.5, i * height / 100 + 0.5);
+ cairo_stroke (cr);
}
- cairo_stroke (cr);
- /* Repaint a shadow on top of everything to clear corners */
- if (monitor->paint_box)
-#ifdef HAVE_GTK3
- gtk_paint_shadow (gtk_widget_get_style(GTK_WIDGET(monitor)), cr, GTK_STATE_PRELIGHT, GTK_SHADOW_IN,
- GTK_WIDGET (monitor), "trough", 0, 0, width, height);
-#else
- gtk_paint_shadow (gtk_widget_get_style(GTK_WIDGET(monitor)), gtk_widget_get_window(GTK_WIDGET(monitor)), GTK_STATE_PRELIGHT, GTK_SHADOW_IN,
- NULL, GTK_WIDGET (monitor), "trough", 0, 0, width, height);
-#endif
+ /* Paint the graph on a slightly smaller surface not to overlap with the background box */
+ graph_surface = xtm_process_monitor_graph_surface_create (monitor, width - 1, height - 1);
+ if (graph_surface != NULL)
+ {
+ cairo_set_source_surface (cr, graph_surface, 0.0, 0.0);
+ cairo_paint (cr);
+ cairo_surface_destroy (graph_surface);
+ }
cairo_destroy (cr);
}
@@ -372,16 +272,6 @@ xtm_process_monitor_clear (XtmProcessMonitor *monitor)
}
void
-xtm_process_monitor_set_source_color (XtmProcessMonitor *monitor, gdouble red, gdouble green, gdouble blue)
-{
- g_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor));
- g_signal_handlers_disconnect_by_func (GTK_WIDGET (monitor), init_source_color, NULL);
- g_object_set (monitor, "color-red", red, "color-green", green, "color-blue", blue, NULL);
- if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET(monitor))))
- gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET(monitor)), NULL, FALSE);
-}
-
-void
xtm_process_monitor_set_paint_box (XtmProcessMonitor *monitor, gboolean paint_box)
{
g_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor));
diff --git a/src/process-monitor.h b/src/process-monitor.h
index aa90f98..7d84bbd 100644
--- a/src/process-monitor.h
+++ b/src/process-monitor.h
@@ -30,7 +30,5 @@ GtkWidget * xtm_process_monitor_new (void);
void xtm_process_monitor_add_peak (XtmProcessMonitor *monitor, gfloat peak);
void xtm_process_monitor_set_step_size (XtmProcessMonitor *monitor, gfloat step_size);
void xtm_process_monitor_clear (XtmProcessMonitor *monitor);
-void xtm_process_monitor_set_source_color (XtmProcessMonitor *monitor, gdouble red, gdouble green, gdouble blue);
-void xtm_process_monitor_set_paint_box (XtmProcessMonitor *monitor, gboolean paint_box);
#endif /* !PROCESS_MONITOR_H */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list