kopia lustrzana https://gitlab.com/Zwarf/picplanner
Make key presses (Tab, Enter) work correctly, added better plot for moon and milky way, added moon upper culmination data rise and set
rodzic
09643ac626
commit
bd4a4b7e56
258
src/handler.c
258
src/handler.c
|
@ -1,25 +1,5 @@
|
|||
#include <handler.h>
|
||||
|
||||
void hand_milky_way(float latitude, float longitude, int *time_utc, float *coordinates){
|
||||
/* g_print("Handler Milky Way\n"); */
|
||||
|
||||
double time_jd_init;
|
||||
double *time_jd = &time_jd_init;
|
||||
|
||||
double sidereal_time;
|
||||
|
||||
float ra_milky_way = 266.417;
|
||||
float d_milky_way = -29.008;
|
||||
|
||||
/* translate time to JD */
|
||||
calc_jd(time_utc, time_jd);
|
||||
/* calculate siderial time */
|
||||
calc_sidereal_time(longitude, time_jd, &sidereal_time);
|
||||
/* transfer rotating coordniate system to fixed coordniate system */
|
||||
calc_convert_rotation_horizontal(ra_milky_way, d_milky_way, latitude, sidereal_time, coordinates);
|
||||
/* g_print("Milky Way: Azimuth: %f, Elevation: %f\n", coordinates[0], coordinates[1]); */
|
||||
}
|
||||
|
||||
void hand_sun(float latitude, float longitude, int *time_utc, float *coordinates_sun_horizontal){
|
||||
/* g_print("Handler Sun\n"); */
|
||||
|
||||
|
@ -54,43 +34,24 @@ void hand_moon(float latitude, float longitude, int *time_utc, float *coordinate
|
|||
/* g_print("Moon: Azimuth: %f, Elevation: %f\n", coordinates_moon_horizontal[0], coordinates_moon_horizontal[1]); */
|
||||
}
|
||||
|
||||
void hand_plot_mw(GtkBuilder *builder, float latitude, float longitude, int *time_utc){
|
||||
GtkWidget *box;
|
||||
int time_dyn[6] = {*time_utc, *(time_utc+1), *(time_utc+2), *(time_utc+3), *(time_utc+4), -*(time_utc+5)};
|
||||
int time_dyn_local[6];
|
||||
float elevation[290];
|
||||
float result[2];
|
||||
float min_elevation, max_elevation;
|
||||
void hand_milky_way(float latitude, float longitude, int *time_utc, float *coordinates){
|
||||
/* g_print("Handler Milky Way\n"); */
|
||||
|
||||
for (int i = 0; i<288; i++){
|
||||
*(time_dyn+3)=(int)(i*5/60);
|
||||
*(time_dyn+4)=i*5-(int)(i*5/60)*60;
|
||||
/* g_print("hand_plot, %d:%d, Date: %d.%d.%d\n",*(time_dyn+3),*(time_dyn+4),*(time_dyn),*(time_dyn+1),*(time_dyn+2)); */
|
||||
utc_zone_to_time (time_dyn, time_dyn_local);
|
||||
double time_jd_init;
|
||||
double *time_jd = &time_jd_init;
|
||||
|
||||
hand_milky_way (latitude, longitude, time_dyn_local, result);
|
||||
elevation[i+2] = result[1];
|
||||
double sidereal_time;
|
||||
|
||||
if (i==0){
|
||||
min_elevation = result[1];
|
||||
max_elevation = result[1];
|
||||
}
|
||||
else{
|
||||
if (result[1]<min_elevation){
|
||||
min_elevation = result[1];
|
||||
}
|
||||
if (result[1]>max_elevation){
|
||||
max_elevation = result[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
float ra_milky_way = 266.417;
|
||||
float d_milky_way = -29.008;
|
||||
|
||||
elevation[0] = min_elevation;
|
||||
elevation[1] = max_elevation;
|
||||
|
||||
box = GTK_WIDGET (gtk_builder_get_object(builder, "box_mw_elevation_plot"));
|
||||
gtk_container_foreach (GTK_CONTAINER (box), (GtkCallback) gtk_widget_destroy, NULL);
|
||||
plot_elevation_mw (elevation, box);
|
||||
/* translate time to JD */
|
||||
calc_jd(time_utc, time_jd);
|
||||
/* calculate siderial time */
|
||||
calc_sidereal_time(longitude, time_jd, &sidereal_time);
|
||||
/* transfer rotating coordniate system to fixed coordniate system */
|
||||
calc_convert_rotation_horizontal(ra_milky_way, d_milky_way, latitude, sidereal_time, coordinates);
|
||||
/* g_print("Milky Way: Azimuth: %f, Elevation: %f\n", coordinates[0], coordinates[1]); */
|
||||
}
|
||||
|
||||
void hand_plot_sun(GtkBuilder *builder, float latitude, float longitude, int *time_utc){
|
||||
|
@ -269,3 +230,194 @@ void hand_plot_sun(GtkBuilder *builder, float latitude, float longitude, int *ti
|
|||
sprintf (c_time_dark_night_begin, "%02d:%02d", time_dark_night_begin[0], time_dark_night_begin[1]);
|
||||
gtk_label_set_text (label_dark_night_begin, c_time_dark_night_begin);
|
||||
}
|
||||
|
||||
void hand_plot_moon(GtkBuilder *builder, float latitude, float longitude, int *time_utc){
|
||||
GtkWidget *box;
|
||||
int time_dyn[6] = {*time_utc, *(time_utc+1), *(time_utc+2), *(time_utc+3), *(time_utc+4), -*(time_utc+5)};
|
||||
int time_dyn_local[6];
|
||||
float elevation[290];
|
||||
float result[2];
|
||||
float min_elevation, max_elevation;
|
||||
float elevation_last;
|
||||
float azimuth_max;
|
||||
int time_max_elevation[2];
|
||||
float azimuth_rise;
|
||||
float azimuth_set;
|
||||
int time_rise[2];
|
||||
int time_set[2];
|
||||
|
||||
char c_time_culmination[6];
|
||||
char c_azimuth[7];
|
||||
char c_elevation[7];
|
||||
char c_time_rise[16];
|
||||
char c_time_set[16];
|
||||
|
||||
GtkLabel *label_time_culmination;
|
||||
GtkLabel *label_azimuth;
|
||||
GtkLabel *label_elevation;
|
||||
GtkLabel *label_rise;
|
||||
GtkLabel *label_set;
|
||||
|
||||
for (int i = 0; i<1440; i++){
|
||||
*(time_dyn+3)=(int)(i/60);
|
||||
*(time_dyn+4)=i-(int)(i/60)*60;
|
||||
utc_zone_to_time (time_dyn, time_dyn_local);
|
||||
|
||||
hand_moon (latitude, longitude, time_dyn_local, result);
|
||||
|
||||
if (i%5==0){
|
||||
elevation[i/5+2] = result[1];
|
||||
}
|
||||
|
||||
if (i==0){
|
||||
min_elevation = result[1];
|
||||
max_elevation = result[1];
|
||||
}
|
||||
else{
|
||||
if (result[1]<min_elevation){
|
||||
min_elevation = result[1];
|
||||
}
|
||||
if (result[1]>max_elevation){
|
||||
max_elevation = result[1];
|
||||
azimuth_max = result[0];
|
||||
time_max_elevation[0]=time_dyn[3];
|
||||
time_max_elevation[1]=time_dyn[4];
|
||||
}
|
||||
if (result[1]>0 && elevation_last<0){
|
||||
azimuth_rise=result[0];
|
||||
time_rise[0]=time_dyn[3];
|
||||
time_rise[1]=time_dyn[4];
|
||||
}
|
||||
if (result[1]<0 && elevation_last>0){
|
||||
azimuth_set=result[0];
|
||||
time_set[0]=time_dyn[3];
|
||||
time_set[1]=time_dyn[4];
|
||||
}
|
||||
}
|
||||
elevation_last = result[1];
|
||||
}
|
||||
|
||||
elevation[0] = min_elevation;
|
||||
elevation[1] = max_elevation;
|
||||
|
||||
box = GTK_WIDGET (gtk_builder_get_object(builder, "box_moon_elevation_plot"));
|
||||
gtk_container_foreach (GTK_CONTAINER (box), (GtkCallback) gtk_widget_destroy, NULL);
|
||||
plot_elevation_moon (elevation, box);
|
||||
|
||||
label_rise = GTK_LABEL (gtk_builder_get_object (builder, "moon_rise"));
|
||||
label_set = GTK_LABEL (gtk_builder_get_object (builder, "moon_set"));
|
||||
label_time_culmination = GTK_LABEL (gtk_builder_get_object (builder, "moon_time_culmination"));
|
||||
label_azimuth = GTK_LABEL (gtk_builder_get_object (builder, "moon_azimuth"));
|
||||
label_elevation = GTK_LABEL (gtk_builder_get_object (builder, "moon_elevation"));
|
||||
|
||||
sprintf (c_time_culmination, "%02d:%02d", time_max_elevation[0], time_max_elevation[1]);
|
||||
gtk_label_set_text (label_time_culmination, c_time_culmination);
|
||||
|
||||
sprintf (c_azimuth, "%.1f\u00B0", azimuth_max);
|
||||
gtk_label_set_text (label_azimuth, c_azimuth);
|
||||
|
||||
sprintf (c_elevation, "%.1f\u00B0", max_elevation);
|
||||
gtk_label_set_text (label_elevation, c_elevation);
|
||||
|
||||
sprintf (c_time_rise, "%02d:%02d (@ %.1f\u00B0)", time_rise[0], time_rise[1], azimuth_rise);
|
||||
gtk_label_set_text (label_rise, c_time_rise);
|
||||
|
||||
sprintf (c_time_set, "%02d:%02d (@ %.1f\u00B0)", time_set[0], time_set[1], azimuth_set);
|
||||
gtk_label_set_text (label_set, c_time_set);
|
||||
}
|
||||
|
||||
|
||||
void hand_plot_mw(GtkBuilder *builder, float latitude, float longitude, int *time_utc){
|
||||
GtkWidget *box;
|
||||
int time_dyn[6] = {*time_utc, *(time_utc+1), *(time_utc+2), *(time_utc+3), *(time_utc+4), -*(time_utc+5)};
|
||||
int time_dyn_local[6];
|
||||
float elevation[290];
|
||||
float result[2];
|
||||
float min_elevation, max_elevation;
|
||||
float elevation_last;
|
||||
float azimuth_max;
|
||||
int time_max_elevation[2];
|
||||
float azimuth_rise;
|
||||
float azimuth_set;
|
||||
int time_rise[2];
|
||||
int time_set[2];
|
||||
|
||||
char c_time_culmination[6];
|
||||
char c_azimuth[7];
|
||||
char c_elevation[7];
|
||||
char c_time_rise[16];
|
||||
char c_time_set[16];
|
||||
|
||||
GtkLabel *label_time_culmination;
|
||||
GtkLabel *label_azimuth;
|
||||
GtkLabel *label_elevation;
|
||||
GtkLabel *label_rise;
|
||||
GtkLabel *label_set;
|
||||
|
||||
for (int i = 0; i<1440; i++){
|
||||
*(time_dyn+3)=(int)(i/60);
|
||||
*(time_dyn+4)=i-(int)(i/60)*60;
|
||||
utc_zone_to_time (time_dyn, time_dyn_local);
|
||||
|
||||
hand_milky_way (latitude, longitude, time_dyn_local, result);
|
||||
|
||||
if (i%5==0){
|
||||
elevation[i/5+2] = result[1];
|
||||
}
|
||||
|
||||
if (i==0){
|
||||
min_elevation = result[1];
|
||||
max_elevation = result[1];
|
||||
}
|
||||
else{
|
||||
if (result[1]<min_elevation){
|
||||
min_elevation = result[1];
|
||||
}
|
||||
if (result[1]>max_elevation){
|
||||
max_elevation = result[1];
|
||||
azimuth_max = result[0];
|
||||
time_max_elevation[0]=time_dyn[3];
|
||||
time_max_elevation[1]=time_dyn[4];
|
||||
}
|
||||
if (result[1]>0 && elevation_last<0){
|
||||
azimuth_rise=result[0];
|
||||
time_rise[0]=time_dyn[3];
|
||||
time_rise[1]=time_dyn[4];
|
||||
}
|
||||
if (result[1]<0 && elevation_last>0){
|
||||
azimuth_set=result[0];
|
||||
time_set[0]=time_dyn[3];
|
||||
time_set[1]=time_dyn[4];
|
||||
}
|
||||
}
|
||||
elevation_last = result[1];
|
||||
}
|
||||
|
||||
elevation[0] = min_elevation;
|
||||
elevation[1] = max_elevation;
|
||||
|
||||
box = GTK_WIDGET (gtk_builder_get_object(builder, "box_mw_elevation_plot"));
|
||||
gtk_container_foreach (GTK_CONTAINER (box), (GtkCallback) gtk_widget_destroy, NULL);
|
||||
plot_elevation_mw (elevation, box);
|
||||
|
||||
label_rise = GTK_LABEL (gtk_builder_get_object (builder, "mw_rise"));
|
||||
label_set = GTK_LABEL (gtk_builder_get_object (builder, "mw_set"));
|
||||
label_time_culmination = GTK_LABEL (gtk_builder_get_object (builder, "mw_time_culmination"));
|
||||
label_azimuth = GTK_LABEL (gtk_builder_get_object (builder, "mw_azimuth"));
|
||||
label_elevation = GTK_LABEL (gtk_builder_get_object (builder, "mw_elevation"));
|
||||
|
||||
sprintf (c_time_culmination, "%02d:%02d", time_max_elevation[0], time_max_elevation[1]);
|
||||
gtk_label_set_text (label_time_culmination, c_time_culmination);
|
||||
|
||||
sprintf (c_azimuth, "%.1f\u00B0", azimuth_max);
|
||||
gtk_label_set_text (label_azimuth, c_azimuth);
|
||||
|
||||
sprintf (c_elevation, "%.1f\u00B0", max_elevation);
|
||||
gtk_label_set_text (label_elevation, c_elevation);
|
||||
|
||||
sprintf (c_time_rise, "%02d:%02d (@ %.1f\u00B0)", time_rise[0], time_rise[1], azimuth_rise);
|
||||
gtk_label_set_text (label_rise, c_time_rise);
|
||||
|
||||
sprintf (c_time_set, "%02d:%02d (@ %.1f\u00B0)", time_set[0], time_set[1], azimuth_set);
|
||||
gtk_label_set_text (label_set, c_time_set);
|
||||
}
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
#include <calculations.h>
|
||||
#include <plot.h>
|
||||
|
||||
void hand_milky_way(float latitude, float longitude, int *time_utc, float *coordinates);
|
||||
|
||||
void hand_sun(float latitude, float longitude, int *time_utc, float *coordinates_sun_horizontal);
|
||||
|
||||
void hand_moon(float latitude, float longitude, int *time_utc, float *coordinates_moon_horizontal);
|
||||
|
||||
void hand_plot_mw(GtkBuilder *builder, float latitude, float longitude, int *time_utc);
|
||||
void hand_milky_way(float latitude, float longitude, int *time_utc, float *coordinates);
|
||||
|
||||
void hand_plot_sun(GtkBuilder *builder, float latitude, float longitude, int *time_utc);
|
||||
|
||||
void hand_plot_moon(GtkBuilder *builder, float latitude, float longitude, int *time_utc);
|
||||
|
||||
void hand_plot_mw(GtkBuilder *builder, float latitude, float longitude, int *time_utc);
|
||||
|
|
20
src/main.c
20
src/main.c
|
@ -53,7 +53,6 @@ static int search(GtkWidget *widget, gpointer data)
|
|||
const gchar *searchtext;
|
||||
|
||||
/* Get the Text from the GtkSearchEntry field */
|
||||
searchentry = GTK_SEARCH_ENTRY(gtk_builder_get_object(builder, "searchentry"));
|
||||
searchtext = gtk_entry_get_text(GTK_ENTRY(searchentry));
|
||||
|
||||
if (strlen(searchtext)<1)
|
||||
|
@ -63,10 +62,6 @@ static int search(GtkWidget *widget, gpointer data)
|
|||
}
|
||||
g_print("Location to search for: %s\n", searchtext);
|
||||
|
||||
location_entry = GTK_ENTRY(gtk_builder_get_object(builder, "location_entry"));
|
||||
north_entry = GTK_ENTRY(gtk_builder_get_object(builder, "north_entry"));
|
||||
east_entry = GTK_ENTRY(gtk_builder_get_object(builder, "east_entry"));
|
||||
|
||||
/* Use webconnection.c with curl to serach at nominatim for a result */
|
||||
struct Output *search_result = search_nominatim (searchtext);
|
||||
|
||||
|
@ -88,6 +83,7 @@ static int search(GtkWidget *widget, gpointer data)
|
|||
|
||||
/* Inform the user if there is no search result available */
|
||||
if (displayText == NULL){gtk_entry_set_text(location_entry, "No result found or no connection to server!");}
|
||||
else { gtk_window_set_focus (GTK_WINDOW(window), button_calculate);}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -149,8 +145,6 @@ static int calculate (GtkWidget *widget, gpointer data)
|
|||
const char *north_entry_string;
|
||||
const char *east_entry_string;
|
||||
|
||||
north_entry = GTK_ENTRY(gtk_builder_get_object (builder, "north_entry"));
|
||||
east_entry = GTK_ENTRY (gtk_builder_get_object (builder, "east_entry"));
|
||||
north_entry_string = gtk_entry_get_text (north_entry);
|
||||
east_entry_string = gtk_entry_get_text (east_entry);
|
||||
if (strlen(north_entry_string)<1 || strlen(east_entry_string)<1)
|
||||
|
@ -188,6 +182,7 @@ static int calculate (GtkWidget *widget, gpointer data)
|
|||
hand_moon (latitude, longitude, time_utc, coordinates_moon);
|
||||
hand_plot_mw (builder, latitude, longitude, time_utc);
|
||||
hand_plot_sun (builder, latitude, longitude, time_utc);
|
||||
hand_plot_moon (builder, latitude, longitude, time_utc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -219,7 +214,7 @@ int main( int argc, char *argv[] )
|
|||
gtk_init (&argc, &argv);
|
||||
hdy_action_row_get_type ();
|
||||
|
||||
builder = gtk_builder_new_from_resource("/main/picplanner-window.glade");
|
||||
builder = gtk_builder_new_from_resource("/main/picplanner-window.ui");
|
||||
|
||||
window = GTK_WIDGET (gtk_builder_get_object(builder, "window"));
|
||||
button_search = GTK_WIDGET (gtk_builder_get_object(builder, "button_search"));
|
||||
|
@ -235,6 +230,11 @@ int main( int argc, char *argv[] )
|
|||
entry_month = GTK_COMBO_BOX (gtk_builder_get_object (builder, "entry_month"));
|
||||
entry_year = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "entry_year"));
|
||||
|
||||
location_entry = GTK_ENTRY(gtk_builder_get_object(builder, "location_entry"));
|
||||
north_entry = GTK_ENTRY(gtk_builder_get_object(builder, "north_entry"));
|
||||
east_entry = GTK_ENTRY(gtk_builder_get_object(builder, "east_entry"));
|
||||
searchentry = GTK_SEARCH_ENTRY(gtk_builder_get_object(builder, "searchentry"));
|
||||
|
||||
g_signal_connect (window, "delete-event", G_CALLBACK (delete_event), NULL);
|
||||
g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL);
|
||||
g_signal_connect (window, "configure-event", G_CALLBACK(hdy_size_config), NULL);
|
||||
|
@ -244,6 +244,10 @@ int main( int argc, char *argv[] )
|
|||
g_signal_connect (entry_month, "changed", G_CALLBACK (correct_time), NULL);
|
||||
g_signal_connect (entry_year, "changed", G_CALLBACK (correct_time), NULL);
|
||||
|
||||
g_signal_connect (searchentry, "activate", G_CALLBACK (search), NULL);
|
||||
|
||||
|
||||
|
||||
set_time_now (window, NULL);
|
||||
|
||||
gtk_widget_show (window);
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
<object class="GtkWindow" id="window">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="type">GTK_WINDOW_TOPLEVEL</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="window_position">center-on-parent</property>
|
||||
<child type="titlebar">
|
||||
|
@ -114,7 +115,7 @@
|
|||
<object class="GtkButton" id="button_search">
|
||||
<property name="label" translatable="yes">Search</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">end</property>
|
||||
|
@ -158,7 +159,7 @@
|
|||
<child>
|
||||
<object class="HdyActionRow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="title" translatable="yes">North</property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="north_entry">
|
||||
|
@ -172,7 +173,7 @@
|
|||
<child>
|
||||
<object class="HdyActionRow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="title" translatable="yes">East</property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="east_entry">
|
||||
|
@ -277,7 +278,7 @@
|
|||
<child>
|
||||
<object class="GtkComboBoxText" id="entry_month">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="active_id">1</property>
|
||||
<property name="wrap_width">2</property>
|
||||
<property name="width_request">150</property>
|
||||
|
@ -313,7 +314,7 @@
|
|||
<object class="GtkButton" id="button_now">
|
||||
<property name="label" translatable="yes">Now</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
|
@ -329,7 +330,7 @@
|
|||
<object class="GtkButton" id="button_calculate">
|
||||
<property name="label" translatable="yes">Calculate</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">end</property>
|
||||
|
@ -346,7 +347,7 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">Overviwe</property>
|
||||
<property name="label" translatable="yes">Under construction</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="receives_default">False</property>
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/main">
|
||||
<file>picplanner-window.glade</file>
|
||||
<file>picplanner-window.ui</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
|
150
src/plot.c
150
src/plot.c
|
@ -170,21 +170,17 @@ void plot_elevation_mw (float *elevations, GtkWidget *box){
|
|||
gtk_container_add (GTK_CONTAINER (box), da);
|
||||
gtk_widget_show_all (box);
|
||||
|
||||
g_print("Elevation 1: %f\n",*(elevations+2));
|
||||
|
||||
static float stat_elevation[290];
|
||||
for (int i = 0; i<290; i++){
|
||||
stat_elevation[i]=elevations[i];
|
||||
}
|
||||
/* I found this by trail and error... Why do I need a static array? A non static arry is not able to pass data through the g_signal_connect function...? */
|
||||
g_print("Elevation 1.1: %f\n",stat_elevation[2]);
|
||||
|
||||
g_signal_connect (da, "draw", G_CALLBACK (on_draw_elevation_mw), stat_elevation);
|
||||
}
|
||||
|
||||
gboolean on_draw_elevation_mw (GtkWidget *widget, cairo_t *cr, gpointer gpoint){
|
||||
float *elevation = gpoint;
|
||||
g_print("on_draw_elevation\n");
|
||||
|
||||
GdkWindow *drawing_window;
|
||||
cairo_region_t *cairo_region;
|
||||
|
@ -198,9 +194,9 @@ gboolean on_draw_elevation_mw (GtkWidget *widget, cairo_t *cr, gpointer gpoint){
|
|||
cr = gdk_drawing_context_get_cairo_context (drawing_context);
|
||||
|
||||
gdk_window_get_geometry (drawing_window, &da.x, &da.y, &da.width, &da.height);
|
||||
cairo_translate (cr, 0, da.height/2);
|
||||
cairo_scale (cr, 100, -100);
|
||||
gdouble dx = da.width, dy = da.height/2;
|
||||
cairo_translate (cr, 0, da.height*0.4);
|
||||
cairo_scale (cr, 100, 100);
|
||||
gdouble dx = da.width, dy = da.height*0.4;
|
||||
gdouble clip_x1 = 0.0, clip_y1 = 0.0, clip_x2 = 0.0, clip_y2 = 0.0;
|
||||
cairo_device_to_user_distance (cr, &dx, &dy);
|
||||
cairo_clip_extents (cr, &clip_x1, &clip_y1, &clip_x2, &clip_y2);
|
||||
|
@ -218,25 +214,50 @@ gboolean on_draw_elevation_mw (GtkWidget *widget, cairo_t *cr, gpointer gpoint){
|
|||
extr=fabs(*elevation);
|
||||
}
|
||||
else{
|
||||
extr = *(elevation+1);
|
||||
extr = fabs(*(elevation+1));
|
||||
}
|
||||
|
||||
for (int i = 0; i<25; i++){
|
||||
float x = (float)i/24.*dx*0.9+0.05*dx;
|
||||
|
||||
cairo_move_to (cr, x, -dy);
|
||||
cairo_set_line_width (cr, 0.02);
|
||||
cairo_set_source_rgb (cr, 0.95, 0.95, 0.95);
|
||||
cairo_line_to (cr, x, dy);
|
||||
|
||||
if (i%2==0){
|
||||
cairo_move_to (cr, x-0.1, dy*1.4);
|
||||
static char label[3];
|
||||
sprintf (label, "%02d", i);
|
||||
cairo_set_font_size (cr, 0.15);
|
||||
cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
|
||||
cairo_show_text (cr, label);
|
||||
}
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
|
||||
cairo_set_line_width (cr, 0.05);
|
||||
cairo_move_to (cr, 0, 0);
|
||||
cairo_set_source_rgb (cr, 0, 0, 0);
|
||||
for (int i = 0; i<288; i++){
|
||||
g_print("Elevation: %f\n", elevation[i+2]);
|
||||
float x = (float)i/288.*dx*0.9+0.05*dx;
|
||||
float y = -*(elevation+i+2)/extr*dy*0.95;
|
||||
/*g_print("Elevation: %f\n", elevation[i+2]);*/
|
||||
if (i==0){
|
||||
cairo_move_to (cr, (float)i/288.*dx*0.98+0.01*dx, -*(elevation+i+2)/extr*dy*0.98);
|
||||
cairo_move_to (cr, x, y);
|
||||
}
|
||||
else{
|
||||
cairo_line_to (cr, (float)i/288.*dx*0.98+0.01*dx, -*(elevation+i+2)/extr*dy*0.98);
|
||||
cairo_line_to (cr, x, y);
|
||||
}
|
||||
|
||||
}
|
||||
/*cairo_line_to (cr, 160./288.*dx, -35./60.*dy);*/
|
||||
|
||||
cairo_set_source_rgb (cr, 0, 0, 0);
|
||||
cairo_stroke (cr);
|
||||
|
||||
gdk_window_end_draw_frame(drawing_window,drawing_context);
|
||||
cairo_region_destroy(cairo_region);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -362,3 +383,108 @@ gboolean on_draw_elevation_sun (GtkWidget *widget, cairo_t *cr, gpointer gpoint)
|
|||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void plot_elevation_moon (float *elevations, GtkWidget *box){
|
||||
GtkWidget *da;
|
||||
|
||||
da = gtk_drawing_area_new ();
|
||||
gtk_widget_set_size_request (GTK_WIDGET(da), 200, 100);
|
||||
gtk_widget_set_hexpand (GTK_WIDGET (da), TRUE);
|
||||
gtk_widget_set_vexpand (GTK_WIDGET (da), TRUE);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (box), da);
|
||||
gtk_widget_show_all (box);
|
||||
|
||||
/*g_print("Elevation 1: %f\n",*(elevations+2));*/
|
||||
|
||||
static float stat_elevation[290];
|
||||
for (int i = 0; i<290; i++){
|
||||
stat_elevation[i]=elevations[i];
|
||||
}
|
||||
/* I found this by trail and error... Why do I need a static array? A non static arry is not able to pass data through the g_signal_connect function...? */
|
||||
/*g_print("Elevation 1.1: %f\n",stat_elevation[2]);*/
|
||||
|
||||
g_signal_connect (da, "draw", G_CALLBACK (on_draw_elevation_moon), stat_elevation);
|
||||
}
|
||||
|
||||
gboolean on_draw_elevation_moon (GtkWidget *widget, cairo_t *cr, gpointer gpoint){
|
||||
float *elevation = gpoint;
|
||||
/*g_print("on_draw_elevation_sun\n");*/
|
||||
|
||||
GdkWindow *drawing_window;
|
||||
cairo_region_t *cairo_region;
|
||||
GdkDrawingContext *drawing_context;
|
||||
GdkRectangle da;
|
||||
|
||||
drawing_window = gtk_widget_get_window (widget);
|
||||
|
||||
cairo_region = cairo_region_create();
|
||||
drawing_context = gdk_window_begin_draw_frame (drawing_window,cairo_region);
|
||||
cr = gdk_drawing_context_get_cairo_context (drawing_context);
|
||||
|
||||
gdk_window_get_geometry (drawing_window, &da.x, &da.y, &da.width, &da.height);
|
||||
cairo_translate (cr, 0, da.height*0.4);
|
||||
cairo_scale (cr, 100, 100);
|
||||
gdouble dx = da.width, dy = da.height*0.4;
|
||||
gdouble clip_x1 = 0.0, clip_y1 = 0.0, clip_x2 = 0.0, clip_y2 = 0.0;
|
||||
cairo_device_to_user_distance (cr, &dx, &dy);
|
||||
cairo_clip_extents (cr, &clip_x1, &clip_y1, &clip_x2, &clip_y2);
|
||||
cairo_set_line_width (cr, 0.05);
|
||||
|
||||
cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
|
||||
cairo_paint (cr);
|
||||
cairo_move_to (cr, 0, 0);
|
||||
cairo_line_to (cr, dx, 0);
|
||||
cairo_set_source_rgb (cr, 1, 1, 1);
|
||||
cairo_stroke (cr);
|
||||
|
||||
float extr = 0;
|
||||
if (fabs(*elevation)>*(elevation+1)){
|
||||
extr=fabs(*elevation);
|
||||
}
|
||||
else{
|
||||
extr = *(elevation+1);
|
||||
}
|
||||
|
||||
for (int i = 0; i<25; i++){
|
||||
float x = (float)i/24.*dx*0.9+0.05*dx;
|
||||
|
||||
cairo_move_to (cr, x, -dy);
|
||||
cairo_set_line_width (cr, 0.02);
|
||||
cairo_set_source_rgb (cr, 0.95, 0.95, 0.95);
|
||||
cairo_line_to (cr, x, dy);
|
||||
|
||||
if (i%2==0){
|
||||
cairo_move_to (cr, x-0.1, dy*1.4);
|
||||
static char label[3];
|
||||
sprintf (label, "%02d", i);
|
||||
cairo_set_font_size (cr, 0.15);
|
||||
cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
|
||||
cairo_show_text (cr, label);
|
||||
}
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
|
||||
cairo_set_line_width (cr, 0.05);
|
||||
cairo_move_to (cr, 0, 0);
|
||||
cairo_set_source_rgb (cr, 0, 0, 0);
|
||||
for (int i = 0; i<288; i++){
|
||||
float x = (float)i/288.*dx*0.9+0.05*dx;
|
||||
float y = -*(elevation+i+2)/extr*dy*0.95;
|
||||
/*g_print("Elevation: %f\n", elevation[i+2]);*/
|
||||
if (i==0){
|
||||
cairo_move_to (cr, x, y);
|
||||
}
|
||||
else{
|
||||
cairo_line_to (cr, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
cairo_set_source_rgb (cr, 0, 0, 0);
|
||||
cairo_stroke (cr);
|
||||
|
||||
gdk_window_end_draw_frame(drawing_window,drawing_context);
|
||||
cairo_region_destroy(cairo_region);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -24,3 +24,7 @@ void plot_elevation_sun (float *elevations, GtkWidget *box);
|
|||
|
||||
gboolean on_draw_elevation_sun (GtkWidget *widget, cairo_t *cr, gpointer gpoint);
|
||||
|
||||
void plot_elevation_moon (float *elevations, GtkWidget *box);
|
||||
|
||||
gboolean on_draw_elevation_moon (GtkWidget *widget, cairo_t *cr, gpointer gpoint);
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue