23 |
|
|
24 |
#define TAG_STATE GTK_STATE_PRELIGHT |
#define TAG_STATE GTK_STATE_PRELIGHT |
25 |
|
|
26 |
void pos_lat_str(char *str, int len, double latitude) { |
void pos_lat_str(char *str, int len, pos_float_t latitude) { |
27 |
snprintf(str, len-1, "%.5f", latitude); |
snprintf(str, len-1, "%.5f", latitude); |
28 |
/* eliminate trailing zeros */ |
/* eliminate trailing zeros */ |
29 |
if((strchr(str, '.') != NULL) || (strchr(str, ',') != NULL)) { |
if((strchr(str, '.') != NULL) || (strchr(str, ',') != NULL)) { |
35 |
strcat(str, "°"); |
strcat(str, "°"); |
36 |
} |
} |
37 |
|
|
38 |
void pos_lon_str(char *str, int len, double longitude) { |
void pos_lon_str(char *str, int len, pos_float_t longitude) { |
39 |
snprintf(str, len-1, "%.5f", longitude); |
snprintf(str, len-1, "%.5f", longitude); |
40 |
/* eliminate trailing zeros */ |
/* eliminate trailing zeros */ |
41 |
if((strchr(str, '.') != NULL) || (strchr(str, ',') != NULL)) { |
if((strchr(str, '.') != NULL) || (strchr(str, ',') != NULL)) { |
47 |
strcat(str, "°"); |
strcat(str, "°"); |
48 |
} |
} |
49 |
|
|
50 |
double pos_parse_lat(char *str) { |
pos_float_t pos_parse_lat(char *str) { |
51 |
return g_strtod(str, NULL); |
return g_strtod(str, NULL); |
52 |
} |
} |
53 |
|
|
54 |
double pos_parse_lon(char *str) { |
pos_float_t pos_parse_lon(char *str) { |
55 |
return g_strtod(str, NULL); |
return g_strtod(str, NULL); |
56 |
} |
} |
57 |
|
|
58 |
gboolean pos_lat_valid(double lat) { |
gboolean pos_lat_valid(pos_float_t lat) { |
59 |
return(!isnan(lat) && (lat >= -90.0) && (lat <= 90.0)); |
return(!isnan(lat) && (lat >= -90.0) && (lat <= 90.0)); |
60 |
} |
} |
61 |
|
|
62 |
gboolean pos_lon_valid(double lon) { |
gboolean pos_lon_valid(pos_float_t lon) { |
63 |
return(!isnan(lon) && (lon >= -180.0) && (lon <= 180.0)); |
return(!isnan(lon) && (lon >= -180.0) && (lon <= 180.0)); |
64 |
} |
} |
65 |
|
|
69 |
} |
} |
70 |
|
|
71 |
static void callback_modified_lat(GtkWidget *widget, gpointer data ) { |
static void callback_modified_lat(GtkWidget *widget, gpointer data ) { |
72 |
double i = pos_parse_lat((char*)gtk_entry_get_text(GTK_ENTRY(widget))); |
pos_float_t i = pos_parse_lat((char*)gtk_entry_get_text(GTK_ENTRY(widget))); |
73 |
mark(widget, pos_lat_valid(i)); |
mark(widget, pos_lat_valid(i)); |
74 |
} |
} |
75 |
|
|
76 |
/* a entry that is colored red when being "active" */ |
/* a entry that is colored red when being "active" */ |
77 |
GtkWidget *pos_lat_entry_new(double lat) { |
GtkWidget *pos_lat_entry_new(pos_float_t lat) { |
78 |
GdkColor color; |
GdkColor color; |
79 |
GtkWidget *widget = gtk_entry_new(); |
GtkWidget *widget = gtk_entry_new(); |
80 |
gdk_color_parse("red", &color); |
gdk_color_parse("red", &color); |
91 |
} |
} |
92 |
|
|
93 |
static void callback_modified_lon(GtkWidget *widget, gpointer data ) { |
static void callback_modified_lon(GtkWidget *widget, gpointer data ) { |
94 |
double i = pos_parse_lon((char*)gtk_entry_get_text(GTK_ENTRY(widget))); |
pos_float_t i = pos_parse_lon((char*)gtk_entry_get_text(GTK_ENTRY(widget))); |
95 |
mark(widget, pos_lon_valid(i)); |
mark(widget, pos_lon_valid(i)); |
96 |
} |
} |
97 |
|
|
98 |
/* a entry that is colored red when filled with invalid coordinate */ |
/* a entry that is colored red when filled with invalid coordinate */ |
99 |
GtkWidget *pos_lon_entry_new(double lon) { |
GtkWidget *pos_lon_entry_new(pos_float_t lon) { |
100 |
GdkColor color; |
GdkColor color; |
101 |
GtkWidget *widget = gtk_entry_new(); |
GtkWidget *widget = gtk_entry_new(); |
102 |
gdk_color_parse("#ff0000", &color); |
gdk_color_parse("#ff0000", &color); |
112 |
return widget; |
return widget; |
113 |
} |
} |
114 |
|
|
115 |
double pos_lat_get(GtkWidget *widget) { |
pos_float_t pos_lat_get(GtkWidget *widget) { |
116 |
char *p = (char*)gtk_entry_get_text(GTK_ENTRY(widget)); |
char *p = (char*)gtk_entry_get_text(GTK_ENTRY(widget)); |
117 |
return pos_parse_lat(p); |
return pos_parse_lat(p); |
118 |
} |
} |
119 |
|
|
120 |
double pos_lon_get(GtkWidget *widget) { |
pos_float_t pos_lon_get(GtkWidget *widget) { |
121 |
char *p = (char*)gtk_entry_get_text(GTK_ENTRY(widget)); |
char *p = (char*)gtk_entry_get_text(GTK_ENTRY(widget)); |
122 |
return pos_parse_lon(p); |
return pos_parse_lon(p); |
123 |
} |
} |
124 |
|
|
125 |
void pos_lat_entry_set(GtkWidget *entry, double lat) { |
void pos_lat_entry_set(GtkWidget *entry, pos_float_t lat) { |
126 |
char str[32]; |
char str[32]; |
127 |
pos_lat_str(str, sizeof(str), lat); |
pos_lat_str(str, sizeof(str), lat); |
128 |
gtk_entry_set_text(GTK_ENTRY(entry), str); |
gtk_entry_set_text(GTK_ENTRY(entry), str); |
129 |
} |
} |
130 |
|
|
131 |
void pos_lon_entry_set(GtkWidget *entry, double lon) { |
void pos_lon_entry_set(GtkWidget *entry, pos_float_t lon) { |
132 |
char str[32]; |
char str[32]; |
133 |
pos_lon_str(str, sizeof(str), lon); |
pos_lon_str(str, sizeof(str), lon); |
134 |
gtk_entry_set_text(GTK_ENTRY(entry), str); |
gtk_entry_set_text(GTK_ENTRY(entry), str); |
135 |
} |
} |
136 |
|
|
137 |
GtkWidget *pos_lat_label_new(double lat) { |
GtkWidget *pos_lat_label_new(pos_float_t lat) { |
138 |
char str[32]; |
char str[32]; |
139 |
pos_lat_str(str, sizeof(str), lat); |
pos_lat_str(str, sizeof(str), lat); |
140 |
return gtk_label_new(str); |
return gtk_label_new(str); |
141 |
} |
} |
142 |
|
|
143 |
GtkWidget *pos_lon_label_new(double lon) { |
GtkWidget *pos_lon_label_new(pos_float_t lon) { |
144 |
char str[32]; |
char str[32]; |
145 |
pos_lon_str(str, sizeof(str), lon); |
pos_lon_str(str, sizeof(str), lon); |
146 |
return gtk_label_new(str); |
return gtk_label_new(str); |
147 |
} |
} |
148 |
|
|
149 |
void pos_lat_label_set(GtkWidget *label, double lat) { |
void pos_lat_label_set(GtkWidget *label, pos_float_t lat) { |
150 |
char str[32]; |
char str[32]; |
151 |
pos_lat_str(str, sizeof(str), lat); |
pos_lat_str(str, sizeof(str), lat); |
152 |
gtk_label_set_text(GTK_LABEL(label), str); |
gtk_label_set_text(GTK_LABEL(label), str); |
153 |
} |
} |
154 |
|
|
155 |
void pos_lon_label_set(GtkWidget *label, double lon) { |
void pos_lon_label_set(GtkWidget *label, pos_float_t lon) { |
156 |
char str[32]; |
char str[32]; |
157 |
pos_lon_str(str, sizeof(str), lon); |
pos_lon_str(str, sizeof(str), lon); |
158 |
gtk_label_set_text(GTK_LABEL(label), str); |
gtk_label_set_text(GTK_LABEL(label), str); |
182 |
pos->lat = RAD2DEG(2 * atan(exp(tmp.y/POS_EQ_RADIUS)) - M_PI/2); |
pos->lat = RAD2DEG(2 * atan(exp(tmp.y/POS_EQ_RADIUS)) - M_PI/2); |
183 |
} |
} |
184 |
|
|
185 |
void pos_dist_str(char *str, int len, double dist, gboolean is_mil) { |
void pos_dist_str(char *str, int len, pos_float_t dist, gboolean is_mil) { |
186 |
/* is this to be displayed as miles? */ |
/* is this to be displayed as miles? */ |
187 |
if(is_mil) dist /= KMPMIL; // kilometer per mile |
if(is_mil) dist /= KMPMIL; // kilometer per mile |
188 |
|
|
196 |
} |
} |
197 |
} |
} |
198 |
|
|
199 |
void pos_dist_entry_set(GtkWidget *entry, double dist, gboolean is_mil) { |
void pos_dist_entry_set(GtkWidget *entry, pos_float_t dist, gboolean is_mil) { |
200 |
char str[32]; |
char str[32]; |
201 |
pos_dist_str(str, sizeof(str), dist, is_mil); |
pos_dist_str(str, sizeof(str), dist, is_mil); |
202 |
gtk_entry_set_text(GTK_ENTRY(entry), str); |
gtk_entry_set_text(GTK_ENTRY(entry), str); |
203 |
} |
} |
204 |
|
|
205 |
double pos_parse_dist(char *str, gboolean is_mil) { |
pos_float_t pos_parse_dist(char *str, gboolean is_mil) { |
206 |
return g_strtod(str, NULL) * (is_mil?KMPMIL:1.0); |
return g_strtod(str, NULL) * (is_mil?KMPMIL:1.0); |
207 |
} |
} |
208 |
|
|
209 |
double pos_dist_get(GtkWidget *widget, gboolean is_mil) { |
pos_float_t pos_dist_get(GtkWidget *widget, gboolean is_mil) { |
210 |
char *p = (char*)gtk_entry_get_text(GTK_ENTRY(widget)); |
char *p = (char*)gtk_entry_get_text(GTK_ENTRY(widget)); |
211 |
return pos_parse_dist(p, is_mil); |
return pos_parse_dist(p, is_mil); |
212 |
} |
} |