From d3b673ef833a75bab7d1fc64f698d0c210046db4 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Wed, 25 Jun 2008 14:28:44 +0100 Subject: [PATCH] sky: legend - added object information to legend. --- src/sky/legend.c | 34 +++++++++++++++++++++++++++++++--- src/sky/legend.h | 7 ++++--- src/sky/sky.c | 18 ++++++++---------- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/sky/legend.c b/src/sky/legend.c index 1d0190d..81cd26c 100644 --- a/src/sky/legend.c +++ b/src/sky/legend.c @@ -44,6 +44,9 @@ #define MAG_BASE (FOV_BASE + FOV_SIZE) #define MAG_TEXT (MAG_BASE + 80.0) #define MAG_SIZE 100 +#define OBJECT_BASE (MAG_BASE + MAG_SIZE) +#define OBJECT_TEXT OBJECT_BASE + 80 +#define OBJECT_SIZE 100 #define NOVA_LEGEND_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), NOVA_TYPE_LEGEND, Legend)) @@ -123,6 +126,24 @@ static void render_legend_magnitude(Legend *legend, cairo_t *cr) cairo_show_text(cr, text); } +static void render_legend_object(Legend *legend, cairo_t *cr) +{ + gchar text[32]; + struct astrodb_object *object = legend->object; + + cairo_move_to(cr, OBJECT_BASE, 15.0); + cairo_show_text(cr, "Object:"); + + if (object == NULL) + return; + + /* TODO: do this per type */ + sprintf(text, "%s %s", object->id, object->name); + + cairo_move_to(cr, OBJECT_TEXT, 15.0); + cairo_show_text(cr, text); +} + static void legend_draw(GtkWidget *legend_widget, cairo_t *cr) { Legend *legend; @@ -137,6 +158,7 @@ static void legend_draw(GtkWidget *legend_widget, cairo_t *cr) render_pointer_position(legend, cr); render_legend_magnitude(legend, cr); + render_legend_object(legend, cr); cairo_restore(cr); } @@ -208,15 +230,21 @@ void legend_update_pointer(GtkWidget *gtk_legend, gdouble ra, gdouble dec) gtk_widget_queue_draw(gtk_legend); } -void legend_update_fov(GtkWidget *gtk_legend, gdouble fov, gdouble faint_mag, - gdouble bright_mag) +void legend_update_fov(GtkWidget *gtk_legend, gdouble fov, gdouble faint_mag) { Legend *legend; legend = NOVA_LEGEND_GET_PRIVATE(gtk_legend); legend->fov = fov; - legend->bright_mag = bright_mag; legend->faint_mag = faint_mag; gtk_widget_queue_draw(gtk_legend); } +void legend_set_object(GtkWidget *gtk_legend, struct astrodb_object *object) +{ + Legend *legend; + + legend = NOVA_LEGEND_GET_PRIVATE(gtk_legend); + legend->object = object; + gtk_widget_queue_draw(gtk_legend); +} diff --git a/src/sky/legend.h b/src/sky/legend.h index 21121ac..b1edbec 100644 --- a/src/sky/legend.h +++ b/src/sky/legend.h @@ -21,6 +21,7 @@ #define __LEGEND_H__ #include +#include #include G_BEGIN_DECLS @@ -57,12 +58,12 @@ typedef struct _Legend { struct ln_equ_posn pointer_pos; gdouble fov; gdouble bright_mag, faint_mag; - + struct astrodb_object *object; } Legend; void legend_update_pointer(GtkWidget *gtk_legend, gdouble ra, gdouble dec); -void legend_update_fov(GtkWidget *gtk_legend, gdouble fov, gdouble faint_mag, - gdouble bright_mag); +void legend_update_fov(GtkWidget *gtk_legend, gdouble fov, gdouble faint_mag); +void legend_set_object(GtkWidget *gtk_legend, struct astrodb_object *object); G_END_DECLS diff --git a/src/sky/sky.c b/src/sky/sky.c index e94d022..d3b8511 100644 --- a/src/sky/sky.c +++ b/src/sky/sky.c @@ -138,7 +138,7 @@ static void sky_zoom (Sky *sky, gfloat zoom) sky->projection.fov *= zoom; projection_check_bounds(&sky->projection); legend_update_fov(sky->legend_widget, sky->projection.fov, - sky->projection.clip_mag_faint, sky->projection.clip_mag_bright); + sky->projection.clip_mag_faint); } static gboolean sky_key_press_event(GtkWidget *widget, GdkEventKey *event, @@ -279,6 +279,7 @@ static gboolean sky_motion_notify_event(GtkWidget *widget, GdkModifierType state; struct render_coord rc; struct ln_equ_posn pos; + struct astrodb_object *object; gint x,y; Sky *sky; @@ -286,6 +287,7 @@ static gboolean sky_motion_notify_event(GtkWidget *widget, sky->robject.coord[0].posn = &pos; gdk_window_get_pointer (event->window, &x, &y, &state); + /* drag the sky to pointer position */ if (sky->pointer_drag) { sky_move_rel_pixels(sky, x - sky->pointer_x, y - sky->pointer_y); @@ -294,24 +296,20 @@ static gboolean sky_motion_notify_event(GtkWidget *widget, gtk_widget_grab_focus(widget); gtk_widget_queue_draw(widget); sky->is_modified = 1; - return TRUE; } + /* update the legend position */ if (event->is_hint) { - gdk_window_get_pointer (event->window, &x, &y, &state); - sky->robject.coord[0].x = rc.x = x; - sky->robject.coord[0].y = rc.y = y; - sky_get_posn(sky, &sky->robject); - legend_update_pointer(sky->legend_widget, - sky->robject.coord[0].posn->ra, - sky->robject.coord[0].posn->dec); - } else { sky->robject.coord[0].x = rc.x = x; sky->robject.coord[0].y = rc.y = y; sky_get_posn(sky, &sky->robject); legend_update_pointer(sky->legend_widget, sky->robject.coord[0].posn->ra, sky->robject.coord[0].posn->dec); + + /* update or clear legend object */ + object = tile_get_object_at(sky->tile, &rc); + legend_set_object(sky->legend_widget, object); } return TRUE; -- 2.11.4.GIT