2 * Copyright (C) 2008 Liam Girdwood
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #include <gdk/gdkkeysyms.h>
24 #include <libnova/utility.h>
25 #include <libnova/transform.h>
26 #include <libnova/julian_day.h>
27 #include <libnova/ln_types.h>
28 #include <libncat/libncat.h>
35 #define NOVA_LEGEND_GET_PRIVATE(obj) \
36 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), NOVA_TYPE_LEGEND, Legend))
38 G_DEFINE_TYPE (GtkLegend
, legend
, GTK_TYPE_DRAWING_AREA
);
40 static gboolean
legend_expose (GtkWidget
*legend_widget
,
41 GdkEventExpose
*event
);
43 static void legend_class_init (GtkLegendClass
*class)
45 GObjectClass
*obj_class
;
46 GtkWidgetClass
*widget_class
;
48 obj_class
= G_OBJECT_CLASS (class);
49 widget_class
= GTK_WIDGET_CLASS (class);
51 widget_class
->expose_event
= legend_expose
;
53 g_type_class_add_private (obj_class
, sizeof(Legend
));
56 static void legend_init (GtkLegend
*gtk_legend
)
60 legend
= NOVA_LEGEND_GET_PRIVATE(gtk_legend
);
63 static void render_pointer_position(Legend
*legend
, cairo_t
*cr
)
69 cairo_move_to(cr
, 5.0, 15.0);
70 cairo_show_text(cr
, "RA:");
71 cairo_move_to(cr
, 5.0, 30.0);
72 cairo_show_text(cr
, "DEC:");
73 cairo_move_to(cr
, 5.0, 45.0);
74 cairo_show_text(cr
, "FOV:");
76 ln_deg_to_hms(legend
->pointer_pos
.ra
, &hms
);
77 sprintf(text
, "%2.2dh%2.2dm%2.0fs", hms
.hours
, hms
.minutes
,
80 cairo_move_to(cr
, 45.0, 15.0);
81 cairo_show_text(cr
, text
);
83 ln_deg_to_dms(legend
->pointer_pos
.dec
, &dms
);
88 sprintf(text
, "%c%2.2dº%2.2dm%2.0fs", sign
, dms
.degrees
,
89 dms
.minutes
, dms
.seconds
);
91 cairo_move_to(cr
, 40.0, 30.0);
92 cairo_show_text(cr
, text
);
94 sprintf(text
, "%2.2fº", legend
->fov
);
95 cairo_move_to(cr
, 40.0, 45.0);
96 cairo_show_text(cr
, text
);
99 static void legend_draw (GtkWidget
*legend_widget
, cairo_t
*cr
)
103 legend
= NOVA_LEGEND_GET_PRIVATE(legend_widget
);
105 cairo_set_source_rgba(cr
, 0, 0.35, 0.55, 1.0);
106 cairo_set_font_size (cr
, 13.0);
107 cairo_move_to(cr
, 0.0, 0.0);
108 cairo_line_to(cr
, legend_widget
->allocation
.width
, 0.0);
111 render_pointer_position(legend
, cr
);
115 static gboolean
legend_expose (GtkWidget
*legend_widget
,
116 GdkEventExpose
*event
)
121 cr
= gdk_cairo_create(legend_widget
->window
);
123 /* draw night legend background */
124 cairo_rectangle(cr
,event
->area
.x
, event
->area
.y
,
125 event
->area
.width
, event
->area
.height
);
127 cairo_set_source_rgb(cr
, 0, 0, 0);
130 /* render_object legend objects */
131 legend_draw(legend_widget
, cr
);
137 static void legend_redraw_canvas (GtkLegend
*gtk_legend
)
142 widget
= GTK_WIDGET(gtk_legend
);
147 region
= gdk_drawable_get_clip_region(widget
->window
);
148 /* redraw the cairo canvas completely by exposing it */
149 gdk_window_invalidate_region(widget
->window
, region
, TRUE
);
150 gdk_window_process_updates(widget
->window
, TRUE
);
152 gdk_region_destroy(region
);
155 static gboolean
virtual_legend_update (gpointer data
)
157 GtkLegend
*gtk_legend
;
160 gtk_legend
= NOVA_LEGEND(data
);
161 legend
= NOVA_LEGEND_GET_PRIVATE(gtk_legend
);
163 legend_redraw_canvas(gtk_legend
);
165 return TRUE
; /* keep running this event */
168 GtkWidget
*legend_new (void)
170 return g_object_new(NOVA_TYPE_LEGEND
, NULL
);
173 void legend_update_pointer(GtkLegend
*gtk_legend
, gdouble ra
, gdouble dec
)
177 legend
= NOVA_LEGEND_GET_PRIVATE(gtk_legend
);
178 legend
->pointer_pos
.ra
= ra
;
179 legend
->pointer_pos
.dec
= dec
;
180 gtk_widget_queue_draw(gtk_legend
);
183 void legend_update_fov(GtkLegend
*gtk_legend
, gdouble fov
)
187 legend
= NOVA_LEGEND_GET_PRIVATE(gtk_legend
);
189 gtk_widget_queue_draw(gtk_legend
);