#include #include #include "fluids.h" #include "heightplots.h" #include "gtk_heightplots.h" static GtkWidget *height_scale; static GtkAdjustment *rho_adj, *vel_adj, *force_adj, *divv_adj, *divf_adj; static gboolean set_dataset(GtkToggleButton *button, gpointer data) { if (gtk_toggle_button_get_active(button)) { switch ((int)data) { default: break; case DATASET_RHO: heightplots_set_dataset(DATASET_RHO); gtk_range_set_adjustment(GTK_RANGE(height_scale), rho_adj); gtk_adjustment_set_value(rho_adj, heightplots_get_height()); break; case DATASET_VEL: heightplots_set_dataset(DATASET_VEL); gtk_range_set_adjustment(GTK_RANGE(height_scale), vel_adj); gtk_adjustment_set_value(vel_adj, heightplots_get_height()); break; case DATASET_FORCE: heightplots_set_dataset(DATASET_FORCE); gtk_range_set_adjustment(GTK_RANGE(height_scale), force_adj); gtk_adjustment_set_value(force_adj, heightplots_get_height()); break; case DATASET_DIVV: heightplots_set_dataset(DATASET_DIVV); gtk_range_set_adjustment(GTK_RANGE(height_scale), divv_adj); gtk_adjustment_set_value(force_adj, heightplots_get_height()); break; case DATASET_DIVF: heightplots_set_dataset(DATASET_DIVF); gtk_range_set_adjustment(GTK_RANGE(height_scale), divf_adj); gtk_adjustment_set_value(force_adj, heightplots_get_height()); break; } } return TRUE; } static gboolean select_height(GtkRange *adjustment, gpointer data) { heightplots_set_height((int)gtk_range_get_value(adjustment)); return TRUE; } static void init_adjustments(void) { int dataset; dataset = heightplots_get_dataset(); heightplots_set_dataset(DATASET_RHO); rho_adj = GTK_ADJUSTMENT(gtk_adjustment_new( heightplots_get_height(), 1, 400, 5, 50, 0)); g_object_ref(rho_adj); heightplots_set_dataset(DATASET_VEL); vel_adj = GTK_ADJUSTMENT(gtk_adjustment_new( heightplots_get_height(), 1, 6000, 5, 50, 0)); g_object_ref(vel_adj); heightplots_set_dataset(DATASET_FORCE); force_adj = GTK_ADJUSTMENT(gtk_adjustment_new( heightplots_get_height(), 1, 8000, 5, 50, 0)); g_object_ref(force_adj); heightplots_set_dataset(DATASET_DIVV); divv_adj = GTK_ADJUSTMENT(gtk_adjustment_new( heightplots_get_height(), 1, 500, 5, 50, 0)); g_object_ref(divv_adj); heightplots_set_dataset(DATASET_DIVF); divf_adj = GTK_ADJUSTMENT(gtk_adjustment_new( heightplots_get_height(), 1, 500, 5, 50, 0)); g_object_ref(divf_adj); heightplots_set_dataset(dataset); } /* should be called by destroy */ void clean_adjustments(void) { g_object_unref(rho_adj); g_object_unref(vel_adj); g_object_unref(force_adj); g_object_unref(divv_adj); g_object_unref(divf_adj); } GtkWidget *create_heightplots_page(void) { /* in reality a page is really just a vbox filled with other widgets */ GtkWidget *page; GtkWidget *frame; GtkWidget *box, *box2; GtkWidget *button; GSList *dataset_group; init_adjustments(); page = gtk_vbox_new(FALSE, 0); frame = gtk_frame_new("Dataset"); box = gtk_vbox_new(FALSE, 0); box2 = gtk_hbox_new(FALSE, 0); button = gtk_radio_button_new_with_label (NULL, "Rho"); if (heightplots_get_dataset() == DATASET_RHO) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); } else { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE); } g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(set_dataset), (gpointer)DATASET_RHO); gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0); gtk_widget_show(button); dataset_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button)); button = gtk_radio_button_new_with_label(dataset_group, "Velocity"); if (heightplots_get_dataset() == DATASET_VEL) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); } else { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE); } g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(set_dataset), (gpointer)DATASET_VEL); gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0); gtk_widget_show(button); button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(button), "Force"); if (heightplots_get_dataset() == DATASET_FORCE) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); } else { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE); } g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(set_dataset), (gpointer)DATASET_FORCE); gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0); gtk_widget_show(button); gtk_box_pack_start(GTK_BOX(box), box2, TRUE, TRUE, 0); gtk_widget_show(box2); box2 = gtk_hbox_new(FALSE, 0); dataset_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button)); button = gtk_radio_button_new_with_label(dataset_group, "Divergence Velocity"); if (heightplots_get_dataset() == DATASET_DIVV) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); } else { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE); } g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(set_dataset), (gpointer)DATASET_DIVV); gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0); gtk_widget_show(button); button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(button), "Divergence Force"); if (heightplots_get_dataset() == DATASET_DIVF) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); } else { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE); } g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(set_dataset), (gpointer)DATASET_DIVF); gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0); gtk_widget_show(button); gtk_box_pack_start(GTK_BOX(box), box2, TRUE, TRUE, 0); gtk_widget_show(box2); gtk_container_add(GTK_CONTAINER(frame), box); gtk_widget_show(box); gtk_box_pack_start (GTK_BOX(page), frame, FALSE, TRUE, 0); gtk_widget_show(frame); frame = gtk_frame_new("Muliplier"); box = gtk_vbox_new(FALSE, 0); height_scale = gtk_hscale_new(rho_adj); gtk_scale_set_digits(GTK_SCALE(height_scale), 0); g_signal_connect(GTK_RANGE(height_scale), "value-changed", G_CALLBACK(select_height), NULL); gtk_box_pack_start(GTK_BOX(box), height_scale, FALSE, TRUE, 0); gtk_widget_show(height_scale); gtk_container_add(GTK_CONTAINER(frame), box); gtk_widget_show(box); gtk_box_pack_start (GTK_BOX(page), frame, FALSE, TRUE, 0); gtk_widget_show(frame); return page; }