/[paths]/src/egg_link.c
ViewVC logotype

Contents of /src/egg_link.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 68 - (show annotations)
Sun Aug 26 17:30:53 2012 UTC (7 years, 11 months ago) by ben
File MIME type: text/plain
File size: 1205 byte(s)
better line draw (still bugs)
1 #include <stdlib.h>
2 #include <glib.h>
3 #include <cairo/cairo.h>
4 #include <gtk/gtk.h>
5
6 #include "egg_link.h"
7 #include "egg_node.h"
8
9 G_DEFINE_TYPE (EggLink, egg_link, GTK_TYPE_DRAWING_AREA);
10
11 /* object constructor */
12 static void egg_link_init(EggLink *link)
13 {
14 link->u = link->v = NULL;
15 link->x = link->y = 0;
16
17 gtk_widget_set_has_window (GTK_WIDGET(link), FALSE);
18 gtk_widget_set_size_request (GTK_WIDGET(link), 50, 50);
19 }
20
21 /* draw handler */
22 static gboolean egg_link_draw (GtkWidget *link, cairo_t *cr)
23 {
24 GtkAllocation a;
25 gdouble x1, x2, y1, y2;
26 EggLink *l = EGG_LINK(link);
27
28 gtk_widget_get_allocation (link, &a);
29
30 if(l->u->x > l->v->x) {
31 x1 = a.width - 1;
32 x2 = 0;
33 } else {
34 x1 = 0;
35 x2 = a.width - 1;
36 }
37
38 if(l->u->y > l->v->y) {
39 y1 = a.height - 1;
40 y2 = 0;
41 } else {
42 y1 = 0;
43 y2 = a.height - 1;
44 }
45
46 cairo_move_to(cr, x1, y1);
47
48 cairo_line_to(cr, x2, y2);
49 cairo_stroke(cr);
50
51 return FALSE;
52 }
53
54
55 /* class constructor */
56 static void egg_link_class_init (EggLinkClass *class)
57 {
58 GtkWidgetClass *widget_class;
59
60 widget_class = GTK_WIDGET_CLASS(class);
61
62 widget_class->draw = egg_link_draw;
63 }
64
65 /* public API */
66
67 GtkWidget *egg_link_new(void)
68 {
69 return g_object_new(EGG_TYPE_LINK, NULL);
70 }
71

  ViewVC Help
Powered by ViewVC 1.1.26