catalogs: updated to new libastro API.
[nova.git] / src / objects / lunar.c
blob2bba5f084fd1dd6577610a4e2f215b6f9ab55ba8
1 /*
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.
18 */
20 #include <libnova/lunar.h>
21 #include "lunar.h"
23 static void lunar_update_cache(struct render_object *robject)
25 gdouble JD = robject->context.JD;
27 /* do we have to re-calc cache data */
28 if (lunar.cache.epoch_JD + lunar.cache.diff_JD > JD ||
29 lunar.cache.epoch_JD - lunar.cache.diff_JD < JD) {
30 lunar.cache.epoch_JD = JD;
32 lunar.cache.equ_sdiam =
33 lunar.get_equ_sdiam(lunar.cache.epoch_JD);
34 lunar.get_equ_posn(lunar.cache.epoch_JD, &lunar.cache.posn);
37 robject->coord[0].object_size =
38 (robject->context.pixels_per_degree / 3600.0) *
39 lunar.cache.equ_sdiam;
40 robject->coord[0].posn = &lunar.cache.posn;
41 robject->object = &lunar;
44 static void lunar_render(struct render_object *robject, struct render_flags *rm)
46 if (robject->type == RT_FULL) {
48 if (rm->show_label) {
49 gint label_offset = robject->coord[0].object_size + 15;
50 cairo_set_source_rgb(robject->cr, 0.8, 0.8, 0.8);
51 cairo_move_to(robject->cr,
52 robject->coord[0].x - label_offset,
53 robject->coord[0].y + label_offset);
54 cairo_show_text(robject->cr, lunar.sobject.name);
57 if (rm->show_axis_flag) {
61 cairo_set_source_rgb(robject->cr, 0.8, 0.8, 0.8);
62 cairo_arc (robject->cr,
63 robject->coord[0].x, robject->coord[0].y,
64 robject->coord[0].object_size, 0, 2 * M_PI);
66 if (!rm->show_outline) {
67 cairo_fill (robject->cr);
70 if (rm->show_phase) {
74 } else {
75 cairo_set_source_rgb(robject->cr, 0.8, 0.8, 0.8);
76 cairo_arc (robject->cr,
77 robject->coord[0].x, robject->coord[0].y,
78 robject->coord[0].object_size, 0, 2 * M_PI);
79 cairo_fill (robject->cr);
83 struct lunar lunar = {
84 .sobject.name = "Moon",
85 .render = lunar_render,
86 .update_cache = lunar_update_cache,
87 .get_equ_posn = ln_get_lunar_equ_coords,
88 .get_earth_dist = ln_get_lunar_earth_dist,
89 .get_disk = ln_get_lunar_disk,
90 .get_phase = ln_get_lunar_phase,
91 .get_equ_sdiam = ln_get_lunar_sdiam,
92 .get_pol_sdiam = ln_get_lunar_sdiam,
93 .get_rst = ln_get_lunar_rst,
94 .cache.epoch_JD = 0,
95 .cache.diff_JD = 0.1,