void Settings::get_colour_from_gui (Builder &builder, int i) { const char *glade_name = colour_selectors[i].glade_name; vmml::Vector4f *dest = (vmml::Vector4f *)PTR_OFFSET(this, colour_selectors[i].member_offset); Gdk::Color c; Gtk::ColorButton *w = NULL; builder->get_widget (glade_name, w); if (!w) return; c = w->get_color(); dest->r = c.get_red_p(); dest->g = c.get_green_p(); dest->b = c.get_blue_p(); dest->a = (float) (w->get_alpha()) / 65535.0; m_signal_visual_settings_changed.emit(); }
void Settings::set_to_gui (Builder &builder) { for (uint i = 0; i < G_N_ELEMENTS (settings); i++) { const char *glade_name = settings[i].glade_name; if (!glade_name) continue; set_to_gui (builder, i); } set_shrink_to_gui (builder); for (uint i = 0; i < G_N_ELEMENTS (colour_selectors); i++) { const char *glade_name = colour_selectors[i].glade_name; vmml::Vector4f *src = (vmml::Vector4f *) PTR_OFFSET(this, colour_selectors[i].member_offset); Gdk::Color c; Gtk::ColorButton *w = NULL; builder->get_widget (glade_name, w); if (w) { w->set_use_alpha(true); c.set_rgb_p(src->r, src->g, src->b); w->set_color(c); w->set_alpha(src->a * 65535.0); } } // Set serial speed. Find the row that holds this value Gtk::ComboBoxEntry *portspeed = NULL; builder->get_widget ("Hardware.SerialSpeed", portspeed); if (portspeed) { std::ostringstream ostr; ostr << Hardware.SerialSpeed; Glib::ustring val(ostr.str()); portspeed->get_entry()->set_text(val); } }
void Settings::connect_to_ui (Builder &builder) { // connect gcode configurable text sections GCode.m_impl->connectToUI (builder); // first setup ranges on spinbuttons ... for (uint i = 0; i < G_N_ELEMENTS (spin_ranges); i++) { Gtk::SpinButton *spin = NULL; builder->get_widget (spin_ranges[i].widget, spin); if (!spin) std::cerr << "missing spin button of name '" << spin_ranges[i].widget << "'\n"; else { spin->set_range (spin_ranges[i].min, spin_ranges[i].max); spin->set_increments (spin_ranges[i].inc, spin_ranges[i].inc_page); } } // Ranges on [HV]Range widgets for (uint i = 0; i < G_N_ELEMENTS (ranges); i++) { Gtk::Range *range = NULL; builder->get_widget (ranges[i].widget, range); if (!range) std::cerr << "missing range slider of name '" << ranges[i].widget << "'\n"; else { range->set_range (ranges[i].min, ranges[i].max); range->set_increments (ranges[i].inc, ranges[i].inc_page); } } // connect widget / values from our table for (uint i = 0; i < G_N_ELEMENTS (settings); i++) { const char *glade_name = settings[i].glade_name; if (!glade_name) continue; switch (settings[i].type) { case T_BOOL: { Gtk::CheckButton *check = NULL; builder->get_widget (glade_name, check); if (check) check->signal_toggled().connect (sigc::bind(sigc::bind(sigc::mem_fun(*this, &Settings::get_from_gui), i), builder)); break; } case T_INT: case T_FLOAT: { Gtk::Widget *w = NULL; builder->get_widget (glade_name, w); if (!w) { std::cerr << "Missing user interface item " << glade_name << "\n"; break; } Gtk::SpinButton *spin = dynamic_cast<Gtk::SpinButton *>(w); if (spin) { spin->signal_value_changed().connect (sigc::bind(sigc::bind(sigc::mem_fun(*this, &Settings::get_from_gui), i), builder)); break; } Gtk::Range *range = dynamic_cast<Gtk::Range *>(w); if (range) { range->signal_value_changed().connect (sigc::bind(sigc::bind(sigc::mem_fun(*this, &Settings::get_from_gui), i), builder)); break; } break; } case T_STRING: // unimplemented break; default: break; } } // Slicing.ShrinkQuality Gtk::ComboBox *combo = NULL; builder->get_widget ("Slicing.ShrinkQuality", combo); if (combo) { Glib::RefPtr<Gtk::ListStore> model; Gtk::TreeModelColumnRecord record; Gtk::TreeModelColumn<Glib::ustring> column; record.add (column); model = Gtk::ListStore::create(record); model->append()->set_value (0, Glib::ustring("Fast")); model->append()->set_value (0, Glib::ustring("Logick")); combo->set_model (model); combo->pack_start (column); combo->signal_changed().connect (sigc::bind(sigc::mem_fun(*this, &Settings::get_shrink_from_gui), builder)); } // Colour selectors for (uint i = 0; i < G_N_ELEMENTS (colour_selectors); i++) { const char *glade_name = colour_selectors[i].glade_name; Gdk::Color c; Gtk::ColorButton *w = NULL; if (!glade_name) continue; builder->get_widget (glade_name, w); if (!w) continue; w->signal_color_set().connect (sigc::bind(sigc::bind(sigc::mem_fun(*this, &Settings::get_colour_from_gui), i), builder)); } // Serial port speed Gtk::ComboBoxEntry *portspeed = NULL; builder->get_widget ("Hardware.SerialSpeed", portspeed); if (portspeed) { const guint32 speeds[] = { 9600, 19200, 38400, 57600, 115200, 230400, 576000 }; Glib::RefPtr<Gtk::ListStore> model; Gtk::TreeModelColumnRecord record; Gtk::TreeModelColumn<Glib::ustring> column; record.add (column); model = Gtk::ListStore::create(record); for (guint i = 0; i < G_N_ELEMENTS(speeds); i++) { std::ostringstream val; val << speeds[i]; model->append()->set_value (0, Glib::ustring(val.str())); } portspeed->set_model (model); portspeed->set_text_column (0); portspeed->signal_changed().connect (sigc::bind(sigc::mem_fun(*this, &Settings::get_port_speed_from_gui), builder)); } /* Update UI with defaults */ m_signal_update_settings_gui.emit(); }
Window() : show_edges_label("Show edges"), show_labels_label("Show contour labels"), edge_color_label("Contour edge color"), edge_color(Gdk::RGBA("Red")), edge_width_label("Contour edge width"), edge_width_adj(Gtk::Adjustment::create(1.0, 0.1, 10.0, 0.1, 1.0, 0.0)), edge_width_spin(edge_width_adj, 0.1, 1), nlevels_label("Number of contour edges"), nlevels_adj(Gtk::Adjustment::create(7, 3, 20, 1, 5)), nlevels_spin(nlevels_adj, 1, 0), colormap_palette_label("Colormap palette"), area_fill_pattern_label("Fill pattern"), area_lines_width_label("Fill pattern width"), area_lines_width_adj(Gtk::Adjustment::create(1.0, 0.1, 10.0, 0.1, 1.0, 0.0)), area_lines_width_spin(area_lines_width_adj, 0.1, 1), colorbar_label("Show colorbar"), paned(Gtk::ORIENTATION_VERTICAL), aspect_frame(Glib::ustring(), Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER, 1.5, false) { Glib::ustring x_title = "X-axis"; Glib::ustring y_title = "Y-axis"; Glib::ustring plot_title = "Intensity vs detector position"; // general window and canvas settings set_default_size(720, 720); Gdk::Geometry geometry; geometry.min_aspect = geometry.max_aspect = double(720)/double(720); set_geometry_hints(*this, geometry, Gdk::HINT_ASPECT); set_title("Gtkmm-PLplot test8"); canvas.set_hexpand(true); canvas.set_vexpand(true); //read in our dataset std::ifstream fs; fs.exceptions(std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit); // 11 x 11 dataset (I know the file layout and the data dimensions already) const int nx = 11; const int ny = 11; std::vector<double> x(nx); std::vector<double> y(ny); #ifdef GTKMM_PLPLOT_BOOST_ENABLED boost::multi_array<double, 2> z(boost::extents[nx][ny]); std::cout << "Using Boost multi_array!" << std::endl; #else double **z = Gtk::PLplot::calloc_array2d(nx, ny); #endif fs.open(TEST_CSV); std::string line; std::getline(fs, line); gchar **splitted = g_strsplit(line.c_str(), ",", 0); //first line contains the x values for (int i = 1 ; i < nx + 1 ; i++) { x[i-1] = g_ascii_strtod(splitted[i], NULL); } g_strfreev(splitted); for (int i = 0 ; i < ny ; i++) { line.clear(); std::getline(fs, line); splitted = g_strsplit(line.c_str(), ",", 0); y[i] = g_ascii_strtod(splitted[0], NULL); for (int j = 1 ; j < nx + 1 ; j++) { z[j-1][i] = g_ascii_strtod(splitted[j], NULL); } g_strfreev(splitted); } //construct the plot auto plot = Gtk::manage(new Gtk::PLplot::PlotContourShades( *Gtk::manage(new Gtk::PLplot::PlotDataSurface( x, y, z )), x_title, y_title, plot_title, 7, Gtk::PLplot::ColormapPalette::BLUE_RED, edge_color.get_rgba(), 1.0 )); canvas.add_plot(*plot); plot->set_background_color(Gdk::RGBA("Yellow Green")); //now let's set up the grid grid.set_column_homogeneous(true); grid.set_column_spacing(5); grid.set_row_homogeneous(false); grid.set_row_spacing(5); int row_counter = 0; show_edges_label.set_hexpand(true); show_edges_label.set_vexpand(false); show_edges_label.set_valign(Gtk::ALIGN_CENTER); show_edges_label.set_halign(Gtk::ALIGN_END); show_edges_switch.set_hexpand(true); show_edges_switch.set_vexpand(false); show_edges_switch.set_halign(Gtk::ALIGN_START); show_edges_switch.set_valign(Gtk::ALIGN_CENTER); show_edges_switch.set_active(plot->is_showing_edges()); show_edges_switch.property_active().signal_changed().connect([this, plot](){ if (show_edges_switch.get_active()) { edge_color.set_sensitive(); edge_width_spin.set_sensitive(); show_labels_switch.set_sensitive(); plot->show_edges(); } else { edge_color.set_sensitive(false); edge_width_spin.set_sensitive(false); show_labels_switch.set_sensitive(false); plot->hide_edges(); } }); grid.attach(show_edges_label, 0, row_counter, 1, 1); grid.attach(show_edges_switch, 1, row_counter++, 1, 1); // show contour labels show_labels_label.set_hexpand(true); show_labels_label.set_vexpand(false); show_labels_label.set_valign(Gtk::ALIGN_CENTER); show_labels_label.set_halign(Gtk::ALIGN_END); show_labels_switch.set_hexpand(true); show_labels_switch.set_vexpand(false); show_labels_switch.set_halign(Gtk::ALIGN_START); show_labels_switch.set_valign(Gtk::ALIGN_CENTER); show_labels_switch.set_active(plot->is_showing_labels()); show_labels_switch.property_active().signal_changed().connect([this, plot](){ if (show_labels_switch.get_active()) { plot->show_labels(); } else { plot->hide_labels(); } }); grid.attach(show_labels_label, 0, row_counter, 1, 1); grid.attach(show_labels_switch, 1, row_counter++, 1, 1); //color button edge_color_label.set_hexpand(true); edge_color_label.set_vexpand(false); edge_color_label.set_valign(Gtk::ALIGN_CENTER); edge_color_label.set_halign(Gtk::ALIGN_END); edge_color.set_rgba(plot->get_edge_color()); edge_color.set_use_alpha(true); edge_color.set_hexpand(true); edge_color.set_vexpand(false); edge_color.set_halign(Gtk::ALIGN_START); edge_color.set_valign(Gtk::ALIGN_CENTER); edge_color.signal_color_set().connect([this, plot](){plot->set_edge_color(edge_color.get_rgba());}); grid.attach(edge_color_label, 0, row_counter, 1, 1); grid.attach(edge_color, 1, row_counter++, 1, 1); //the edge width spinbutton edge_width_label.set_hexpand(true); edge_width_label.set_vexpand(false); edge_width_label.set_valign(Gtk::ALIGN_CENTER); edge_width_label.set_halign(Gtk::ALIGN_END); edge_width_spin.set_hexpand(true); edge_width_spin.set_vexpand(false); edge_width_spin.set_halign(Gtk::ALIGN_START); edge_width_spin.set_valign(Gtk::ALIGN_CENTER); edge_width_spin.set_wrap(true); edge_width_spin.set_snap_to_ticks(true); edge_width_spin.set_numeric(true); edge_width_spin.set_value(plot->get_edge_width()); edge_width_spin.signal_value_changed().connect([this, plot](){ plot->set_edge_width(edge_width_spin.get_value()); }); grid.attach(edge_width_label, 0, row_counter, 1, 1); grid.attach(edge_width_spin, 1, row_counter++, 1, 1); //nlevels nlevels_label.set_hexpand(true); nlevels_label.set_vexpand(false); nlevels_label.set_valign(Gtk::ALIGN_CENTER); nlevels_label.set_halign(Gtk::ALIGN_END); nlevels_spin.set_hexpand(true); nlevels_spin.set_vexpand(false); nlevels_spin.set_halign(Gtk::ALIGN_START); nlevels_spin.set_valign(Gtk::ALIGN_CENTER); nlevels_spin.set_wrap(true); nlevels_spin.set_snap_to_ticks(true); nlevels_spin.set_numeric(true); nlevels_spin.set_value(plot->get_nlevels()); nlevels_spin.signal_value_changed().connect([this, plot](){ plot->set_nlevels(nlevels_spin.get_value()); }); grid.attach(nlevels_label, 0, row_counter, 1, 1); grid.attach(nlevels_spin, 1, row_counter++, 1, 1); // colormap palette colormap_palette_label.set_hexpand(true); colormap_palette_label.set_vexpand(false); colormap_palette_label.set_valign(Gtk::ALIGN_CENTER); colormap_palette_label.set_halign(Gtk::ALIGN_END); colormap_palette_combo.set_hexpand(true); colormap_palette_combo.set_vexpand(false); colormap_palette_combo.set_halign(Gtk::ALIGN_START); colormap_palette_combo.set_valign(Gtk::ALIGN_CENTER); colormap_palette_combo.append("Default"); colormap_palette_combo.append("Blue → Red"); colormap_palette_combo.append("Blue → Yellow"); colormap_palette_combo.append("Gray"); colormap_palette_combo.append("High frequencies"); colormap_palette_combo.append("Low frequencies"); colormap_palette_combo.append("Radar"); colormap_palette_combo.set_active(plot->get_colormap_palette()); colormap_palette_combo.signal_changed().connect([this, plot](){ plot->set_colormap_palette(static_cast<Gtk::PLplot::ColormapPalette>(colormap_palette_combo.get_active_row_number())); }); grid.attach(colormap_palette_label, 0, row_counter, 1, 1); grid.attach(colormap_palette_combo, 1, row_counter++, 1, 1); //area fill pattern area_fill_pattern_label.set_hexpand(true); area_fill_pattern_label.set_vexpand(false); area_fill_pattern_label.set_valign(Gtk::ALIGN_CENTER); area_fill_pattern_label.set_halign(Gtk::ALIGN_END); area_fill_pattern_combo.set_hexpand(true); area_fill_pattern_combo.set_vexpand(false); area_fill_pattern_combo.set_halign(Gtk::ALIGN_START); area_fill_pattern_combo.set_valign(Gtk::ALIGN_CENTER); area_fill_pattern_combo.append("Solid"); area_fill_pattern_combo.append("Horizontal lines"); area_fill_pattern_combo.append("Vertical lines"); area_fill_pattern_combo.append("Upward lines at 45 degrees"); area_fill_pattern_combo.append("Downward lines at 45 degrees"); area_fill_pattern_combo.append("Upward lines at 30 degrees"); area_fill_pattern_combo.append("Downward lines at 30 degrees"); area_fill_pattern_combo.append("Horizontal and vertical lines"); area_fill_pattern_combo.append("Upward and downward lines at 45 degrees"); area_fill_pattern_combo.set_active(plot->get_area_fill_pattern()); area_fill_pattern_combo.signal_changed().connect([this, plot](){ plot->set_area_fill_pattern(static_cast<Gtk::PLplot::AreaFillPattern>(area_fill_pattern_combo.get_active_row_number())); if (area_fill_pattern_combo.get_active_row_number() == 0 /* SOLID */) { area_lines_width_spin.set_sensitive(false); } else { area_lines_width_spin.set_sensitive(); } }); grid.attach(area_fill_pattern_label, 0, row_counter, 1, 1); grid.attach(area_fill_pattern_combo, 1, row_counter++, 1, 1); //the area lines width spinbutton area_lines_width_label.set_hexpand(true); area_lines_width_label.set_vexpand(false); area_lines_width_label.set_valign(Gtk::ALIGN_CENTER); area_lines_width_label.set_halign(Gtk::ALIGN_END); area_lines_width_spin.set_hexpand(true); area_lines_width_spin.set_vexpand(false); area_lines_width_spin.set_halign(Gtk::ALIGN_START); area_lines_width_spin.set_valign(Gtk::ALIGN_CENTER); area_lines_width_spin.set_wrap(true); area_lines_width_spin.set_snap_to_ticks(true); area_lines_width_spin.set_numeric(true); area_lines_width_spin.set_value(plot->get_area_lines_width()); area_lines_width_spin.signal_value_changed().connect([this, plot](){ plot->set_area_lines_width(area_lines_width_spin.get_value()); }); area_lines_width_spin.set_sensitive(false); grid.attach(area_lines_width_label, 0, row_counter, 1, 1); grid.attach(area_lines_width_spin, 1, row_counter++, 1, 1); //colorbar colorbar_label.set_hexpand(true); colorbar_label.set_vexpand(false); colorbar_label.set_valign(Gtk::ALIGN_CENTER); colorbar_label.set_halign(Gtk::ALIGN_END); colorbar_switch.set_hexpand(true); colorbar_switch.set_vexpand(false); colorbar_switch.set_halign(Gtk::ALIGN_START); colorbar_switch.set_valign(Gtk::ALIGN_CENTER); colorbar_switch.set_active(plot->is_showing_colorbar()); colorbar_switch.property_active().signal_changed().connect([this, plot](){ if (colorbar_switch.get_active()) { plot->show_colorbar(); } else { plot->hide_colorbar(); } }); grid.attach(colorbar_label, 0, row_counter, 1, 1); grid.attach(colorbar_switch, 1, row_counter++, 1, 1); paned.add1(grid); //add canvas to grid aspect_frame.add(canvas); paned.add2(aspect_frame); //finishing up add(paned); set_border_width(10); #if GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 18 paned.set_wide_handle(true); #endif paned.show_all(); }