~ubuntu-branches/debian/sid/link-monitor-applet/sid

« back to all changes in this revision

Viewing changes to src/lm-line-graph-icon.gob

  • Committer: Bazaar Package Importer
  • Author(s): Adriaan Peeters
  • Date: 2008-03-30 22:26:13 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080330222613-5aubcuo9mgg2n7st
Tags: upstream-3.0
ImportĀ upstreamĀ versionĀ 3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Link Monitor Applet
 
3
 * Copyright (C) 2004-2008 Jean-Yves Lefort <jylefort@brutele.be>
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 */
 
19
 
 
20
%headertop{
 
21
#include <gtk/gtk.h>
 
22
#include "lm-host-frontend.h"
 
23
%}
 
24
 
 
25
%{
 
26
#define WIDTH           36
 
27
#define HEIGHT          24
 
28
 
 
29
#define XALIGN          0.5
 
30
#define YALIGN          0.5
 
31
 
 
32
#define LINE_WIDTH      3.0
 
33
 
 
34
typedef struct
 
35
{
 
36
  double x;
 
37
  double y;
 
38
} Point;
 
39
 
 
40
static const Point points[] = {
 
41
  { 0.1, 0.5 },
 
42
  { 0.2, 0.7 },
 
43
  { 0.4, 0.2 },
 
44
  { 0.5, 0.7 },
 
45
  { 0.7, 0.3 },
 
46
  { 0.9, 0.6 }
 
47
};
 
48
%}
 
49
 
 
50
class LM:Line:Graph:Icon from Gtk:Widget
 
51
{
 
52
  private LMHostFrontend *host;
 
53
  property POINTER host (link, flags = CONSTRUCT_ONLY);
 
54
 
 
55
  constructor (self)
 
56
  {
 
57
    GTK_WIDGET_SET_FLAGS(self, GTK_NO_WINDOW);
 
58
 
 
59
    lm_g_object_connect(self, selfp->host,
 
60
                        "swapped-signal::notify::color", gtk_widget_queue_draw, self,
 
61
                        NULL);
 
62
  }
 
63
 
 
64
  override (Gtk:Widget) void
 
65
    size_request (GtkWidget *widget, GtkRequisition *requisition)
 
66
  {
 
67
    requisition->width = WIDTH;
 
68
    requisition->height = HEIGHT;
 
69
  }
 
70
 
 
71
  /*
 
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/).
 
75
   */
 
76
  private void
 
77
    get_absolute_point (self,
 
78
                        const Point *in (check null),
 
79
                        Point *out (check null))
 
80
  {
 
81
    GtkWidget *widget = GTK_WIDGET(self);
 
82
 
 
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);
 
89
  }
 
90
 
 
91
  override (Gtk:Widget) gboolean
 
92
    expose_event (GtkWidget *widget, GdkEventExpose *event)
 
93
  {
 
94
    Self *self = SELF(widget);
 
95
    cairo_t *cr;
 
96
    Point p;
 
97
    int i;
 
98
 
 
99
    if (! GTK_WIDGET_DRAWABLE(widget))
 
100
      return FALSE;
 
101
 
 
102
    cr = gdk_cairo_create(widget->window);
 
103
 
 
104
    gdk_cairo_set_source_color(cr, &selfp->host->color);
 
105
 
 
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);
 
109
 
 
110
    self_get_absolute_point(self, &points[0], &p);
 
111
    cairo_move_to(cr, p.x, p.y);
 
112
 
 
113
    for (i = 1; i < G_N_ELEMENTS(points); i++)
 
114
      {
 
115
        self_get_absolute_point(self, &points[i], &p);
 
116
        cairo_line_to(cr, p.x, p.y);
 
117
      }
 
118
 
 
119
    cairo_stroke(cr);
 
120
 
 
121
    cairo_destroy(cr);
 
122
 
 
123
    return FALSE;
 
124
  }
 
125
 
 
126
  public GtkWidget *
 
127
    new (LM:Host:Frontend *host (check null type))
 
128
  {
 
129
    return GTK_WIDGET(GET_NEW_VARG(LM_LINE_GRAPH_ICON_PROP_HOST(host), NULL));
 
130
  }
 
131
}