update changelogs for Debian build
[fw/altos] / ao-view / aoview_label.c
1 /*
2  * Copyright © 2009 Keith Packard <keithp@keithp.com>
3  *
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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #include "aoview.h"
19
20 static struct {
21         char            *name;
22         char            *initial_value;
23         GtkLabel        *widget;
24 } label_widgets[] = {
25         { "height_label", "Height (m)", NULL },
26         { "state_label", "State", NULL },
27         { "rssi_label", "RSSI (dBm)", NULL },
28         { "speed_label", "Speed (m/s)", NULL },
29         { "height_value", "0", NULL },
30         { "state_value", "pad", NULL },
31         { "rssi_value", "-50", NULL },
32         { "speed_value", "0", NULL },
33 };
34
35 static void
36 aoview_label_assign(GtkLabel *widget, char *value)
37 {
38         char    *markup;
39
40         markup = g_markup_printf_escaped("<span font_weight=\"bold\" size=\"xx-large\">%s</span>", value);
41         gtk_label_set_markup(widget, markup);
42         g_free(markup);
43 }
44
45 void
46 aoview_label_show(struct aostate *state)
47 {
48         char    line[1024];
49         sprintf(line, "%d", state->height);
50         aoview_label_assign(label_widgets[4].widget, line);
51
52         aoview_label_assign(label_widgets[5].widget, state->data.state);
53
54         sprintf(line, "%d", state->data.rssi);
55         aoview_label_assign(label_widgets[6].widget, line);
56
57         if (state->ascent)
58                 sprintf(line, "%6.0f", fabs(state->speed));
59         else
60                 sprintf(line, "%6.0f", fabs(state->baro_speed));
61         aoview_label_assign(label_widgets[7].widget, line);
62 }
63
64 void
65 aoview_label_init(GladeXML *xml)
66 {
67         int i;
68         for (i = 0; i < sizeof(label_widgets)/sizeof(label_widgets[0]); i++) {
69                 label_widgets[i].widget = GTK_LABEL(glade_xml_get_widget(xml, label_widgets[i].name));
70                 aoview_label_assign(label_widgets[i].widget, label_widgets[i].initial_value);
71                 assert(label_widgets[i].widget);
72         }
73 }