/* Checks the passed xmlNode for a recognized item (ToolButton, ToggleToolButton, Separator) * Returns the widget or NULL if nothing useful is found */ GtkWidget* ToolbarManager::createToolItem(xml::Node& node) { const std::string nodeName = node.getName(); GtkWidget* toolItem; if (nodeName == "separator") { toolItem = GTK_WIDGET(gtk_separator_tool_item_new()); } else if (nodeName == "toolbutton" || nodeName == "toggletoolbutton") { // Found a button, load the values that are shared by both types const std::string name = node.getAttributeValue("name"); const std::string icon = node.getAttributeValue("icon"); const std::string tooltip = _(node.getAttributeValue("tooltip").c_str()); const std::string action = node.getAttributeValue("action"); if (nodeName == "toolbutton") { // Create a new GtkToolButton and assign the right callback toolItem = GTK_WIDGET(gtk_tool_button_new(NULL, name.c_str())); } else { // Create a new GtkToggleToolButton and assign the right callback toolItem = GTK_WIDGET(gtk_toggle_tool_button_new()); } IEventPtr event = GlobalEventManager().findEvent(action); if (!event->empty()) { event->connectWidget(GTK_WIDGET(toolItem)); // Tell the event to update the state of this button event->updateWidgets(); } else { globalErrorStream() << "ToolbarManager: Failed to lookup command " << action << std::endl; } // Set the tooltip, if not empty if (tooltip != "") { gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolItem), _tooltips, tooltip.c_str(), ""); } // Load and assign the icon, if specified if (icon != "") { GtkWidget* image = gtk_image_new_from_pixbuf(GlobalUIManager().getLocalPixbufWithMask(icon)); gtk_widget_show(image); gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(toolItem), image); } } else { return NULL; } gtk_widget_show(toolItem); return toolItem; }
ParticlePreview::ParticlePreview() { // Add one additional toolbar for particle-related stuff Gtk::Toolbar* toolbar = Gtk::manage(new Gtk::Toolbar); toolbar->set_toolbar_style(Gtk::TOOLBAR_ICONS); _showAxesButton = Gtk::manage(new Gtk::ToggleToolButton); _showAxesButton->signal_toggled().connect( sigc::mem_fun(this, &ParticlePreview::queue_draw) ); _showAxesButton->set_icon_widget(*Gtk::manage(new Gtk::Image( GlobalUIManager().getLocalPixbufWithMask("axes.png")))); _showAxesButton->set_tooltip_text(_("Show coordinate axes")); Gtk::ToolButton* reloadButton = Gtk::manage(new Gtk::ToolButton); reloadButton->set_icon_widget(*Gtk::manage(new Gtk::Image(Gtk::Stock::REFRESH, Gtk::ICON_SIZE_MENU))); reloadButton->set_tooltip_text(_("Reload Particle Defs")); IEventPtr ev = GlobalEventManager().findEvent("ReloadParticles"); ev->connectWidget(reloadButton); _showWireFrameButton = Gtk::manage(new Gtk::ToggleToolButton); _showWireFrameButton->set_icon_widget(*Gtk::manage(new Gtk::Image( GlobalUIManager().getLocalPixbufWithMask("wireframe.png")))); _showWireFrameButton->set_tooltip_text(_("Show wireframe")); _showWireFrameButton->signal_toggled().connect( sigc::mem_fun(this, &ParticlePreview::queue_draw) ); _automaticLoopButton = Gtk::manage(new Gtk::ToggleToolButton(_("Auto Loop"))); _automaticLoopButton->set_tooltip_text(_("Auto Loop")); toolbar->insert(*_showAxesButton, 0); toolbar->insert(*_showWireFrameButton, 0); toolbar->insert(*_automaticLoopButton, 0); toolbar->insert(*reloadButton, 0); addToolbar(*toolbar); }