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

Annotation of /src/egg_link.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 68 - (hide annotations)
Sun Aug 26 17:30:53 2012 UTC (8 years, 1 month ago) by ben
File MIME type: text/plain
File size: 1205 byte(s)
better line draw (still bugs)
1 ben 38 #include <stdlib.h>
2     #include <glib.h>
3     #include <cairo/cairo.h>
4     #include <gtk/gtk.h>
5    
6     #include "egg_link.h"
7 ben 64 #include "egg_node.h"
8 ben 38
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 ben 64 link->u = link->v = NULL;
15     link->x = link->y = 0;
16    
17 ben 56 gtk_widget_set_has_window (GTK_WIDGET(link), FALSE);
18     gtk_widget_set_size_request (GTK_WIDGET(link), 50, 50);
19 ben 38 }
20    
21     /* draw handler */
22     static gboolean egg_link_draw (GtkWidget *link, cairo_t *cr)
23     {
24 ben 39 GtkAllocation a;
25 ben 68 gdouble x1, x2, y1, y2;
26     EggLink *l = EGG_LINK(link);
27 ben 38
28 ben 39 gtk_widget_get_allocation (link, &a);
29 ben 57
30 ben 68 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 ben 57
38 ben 68 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 ben 38 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