X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=equipment.c;h=407cb3d145e8984daa8d333c35abe9a544162bd3;hb=cb2f70f631bea638f8557758e4c88aa1c5d7a058;hp=bab0d5335137f0a00bd2c8a2dd5bdbd3f14d437e;hpb=d1b30212ff7192ef1b3fa85924433a8ddd92c281;p=ext%2Fsubsurface.git diff --git a/equipment.c b/equipment.c index bab0d53..407cb3d 100644 --- a/equipment.c +++ b/equipment.c @@ -10,7 +10,8 @@ static int cylinder_changed; static GtkComboBox *cylinder_description; -static GtkSpinButton *cylinder_size, *cylinder_pressure, *nitrox_value; +static GtkSpinButton *cylinder_size, *cylinder_pressure; +static GtkWidget *nitrox_value, *nitrox_button; static void set_cylinder_spinbuttons(int ml, int mbar) { @@ -129,20 +130,25 @@ void show_dive_equipment(struct dive *dive) set_cylinder_spinbuttons(cyl->type.size.mliter, cyl->type.workingpressure.mbar); o2 = cyl->gasmix.o2.permille / 10.0; + gtk_widget_set_sensitive(nitrox_value, !!o2); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(nitrox_button), !!o2); if (!o2) o2 = 21.0; - gtk_spin_button_set_value(nitrox_value, o2); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(nitrox_value), o2); } static GtkWidget *create_spinbutton(GtkWidget *vbox, const char *name, double min, double max, double incr) { - GtkWidget *frame, *button; + GtkWidget *frame, *hbox, *button; frame = gtk_frame_new(name); - gtk_container_add(GTK_CONTAINER(vbox), frame); + gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, TRUE, 0); + + hbox = gtk_hbox_new(FALSE, 3); + gtk_container_add(GTK_CONTAINER(frame), hbox); button = gtk_spin_button_new_with_range(min, max, incr); - gtk_container_add(GTK_CONTAINER(frame), button); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, TRUE, 0); gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID); @@ -187,7 +193,9 @@ static void record_cylinder_changes(struct dive *dive) desc = gtk_combo_box_get_active_text(box); volume = gtk_spin_button_get_value(cylinder_size); pressure = gtk_spin_button_get_value(cylinder_pressure); - o2 = gtk_spin_button_get_value(nitrox_value)*10 + 0.5; + o2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(nitrox_value))*10 + 0.5; + if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(nitrox_button))) + o2 = 0; fill_cylinder_info(dive->cylinder+0, desc, volume, pressure, o2); } @@ -267,24 +275,33 @@ static void fill_tank_list(GtkListStore *store) } } +static void nitrox_cb(GtkToggleButton *button, gpointer data) +{ + GtkWidget *nitrox_value = data; + int state; + + state = gtk_toggle_button_get_active(button); + gtk_widget_set_sensitive(nitrox_value, state); +} + static void cylinder_widget(GtkWidget *box, int nr, GtkListStore *model) { - GtkWidget *frame, *hbox; + GtkWidget *frame, *hbox, *hbox2; GtkWidget *widget; char buffer[80]; - snprintf(buffer, sizeof(buffer), "Cylinder %d", nr); - frame = gtk_frame_new(buffer); - gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 0); + hbox = gtk_hbox_new(FALSE, 3); + gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0); - hbox = gtk_hbox_new(TRUE, 3); - gtk_container_add(GTK_CONTAINER(frame), hbox); + snprintf(buffer, sizeof(buffer), "Cylinder %d", nr+1); + frame = gtk_frame_new(buffer); + gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0); - frame = gtk_frame_new("Description"); - gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 0); + hbox2 = gtk_hbox_new(FALSE, 3); + gtk_container_add(GTK_CONTAINER(frame), hbox2); widget = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0); - gtk_container_add(GTK_CONTAINER(frame), widget); + gtk_box_pack_start(GTK_BOX(hbox2), widget, FALSE, TRUE, 0); cylinder_description = GTK_COMBO_BOX(widget); g_signal_connect(widget, "changed", G_CALLBACK(cylinder_cb), NULL); @@ -292,12 +309,17 @@ static void cylinder_widget(GtkWidget *box, int nr, GtkListStore *model) widget = create_spinbutton(hbox, "Size", 0, 200, 0.1); cylinder_size = GTK_SPIN_BUTTON(widget); - widget = create_spinbutton(hbox, "Working Pressure", 0, 5000, 1); + widget = create_spinbutton(hbox, "Pressure", 0, 5000, 1); cylinder_pressure = GTK_SPIN_BUTTON(widget); widget = create_spinbutton(hbox, "Nitrox", 21, 100, 0.1); - nitrox_value = GTK_SPIN_BUTTON(widget); - gtk_spin_button_set_range(nitrox_value, 21.0, 100.0); + nitrox_value = widget; + nitrox_button = gtk_check_button_new(); + gtk_box_pack_start(GTK_BOX(gtk_widget_get_parent(nitrox_value)), + nitrox_button, FALSE, FALSE, 3); + g_signal_connect(nitrox_button, "toggled", G_CALLBACK(nitrox_cb), nitrox_value); + + gtk_spin_button_set_range(GTK_SPIN_BUTTON(nitrox_value), 21.0, 100.0); } static GtkListStore *create_tank_size_model(void)