3
* Copyright (C) 2004-2008 Jean-Yves Lefort <jylefort@brutele.be>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
#include "lm-host-frontend.h"
32
#define LINE_WIDTH 3.0
40
static const Point points[] = {
50
class LM:Line:Graph:Icon from Gtk:Widget
52
private LMHostFrontend *host;
53
property POINTER host (link, flags = CONSTRUCT_ONLY);
57
GTK_WIDGET_SET_FLAGS(self, GTK_NO_WINDOW);
59
lm_g_object_connect(self, selfp->host,
60
"swapped-signal::notify::color", gtk_widget_queue_draw, self,
64
override (Gtk:Widget) void
65
size_request (GtkWidget *widget, GtkRequisition *requisition)
67
requisition->width = WIDTH;
68
requisition->height = HEIGHT;
72
* We don't use cairo transforms because they make it cumbersome to
73
* specify an uniform line width with a deforming scale (see
74
* http://cairographics.org/tutorial/).
77
get_absolute_point (self,
78
const Point *in (check null),
79
Point *out (check null))
81
GtkWidget *widget = GTK_WIDGET(self);
83
out->x = widget->allocation.x
84
+ ((widget->allocation.width - widget->requisition.width) * XALIGN)
85
+ (in->x * widget->requisition.width);
86
out->y = widget->allocation.y
87
+ ((widget->allocation.height - widget->requisition.height) * YALIGN)
88
+ (in->y * widget->requisition.height);
91
override (Gtk:Widget) gboolean
92
expose_event (GtkWidget *widget, GdkEventExpose *event)
94
Self *self = SELF(widget);
99
if (! GTK_WIDGET_DRAWABLE(widget))
102
cr = gdk_cairo_create(widget->window);
104
gdk_cairo_set_source_color(cr, &selfp->host->color);
106
cairo_set_line_width(cr, LINE_WIDTH);
107
cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
108
cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
110
self_get_absolute_point(self, &points[0], &p);
111
cairo_move_to(cr, p.x, p.y);
113
for (i = 1; i < G_N_ELEMENTS(points); i++)
115
self_get_absolute_point(self, &points[i], &p);
116
cairo_line_to(cr, p.x, p.y);
127
new (LM:Host:Frontend *host (check null type))
129
return GTK_WIDGET(GET_NEW_VARG(LM_LINE_GRAPH_ICON_PROP_HOST(host), NULL));