Example #1
0
Widget_Preview::Widget_Preview():
	Gtk::Table(1, 5),
	adj_time_scrub(0, 0, 1000, 0, 10, 0),
	scr_time_scrub(adj_time_scrub),
	b_loop(/*_("Loop")*/),
	current_surface(NULL),
	currentindex(-100000),//TODO get the value from canvas setting or preview option
	audiotime(0),
	adj_sound(0, 0, 4),
	l_lasttime("0s"),
	playing(false),
	jackdial(NULL),
	jack_enabled(false),
	jack_is_playing(false),
	jack_time(0),
	jack_offset(0)
#ifdef WITH_JACK
	,
	jack_client(NULL),
	jack_synchronizing(false)
#endif
{
	//catch key press event for shortcut keys
	signal_key_press_event().connect(sigc::mem_fun(*this, &Widget_Preview::on_key_pressed));

	//connect to expose events
	//signal_expose_event().connect(sigc::mem_fun(*this, &studio::Widget_Preview::redraw));

	//manage all the change in values etc...

	//1st row: preview content
	preview_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
	//pack preview content into scrolled window
	preview_window.add(draw_area);

	//preview window background color
	Gdk::Color bg_color;
	bg_color.set_red(54*256);
	bg_color.set_blue(59*256);
	bg_color.set_green(59*256);
	draw_area.modify_bg(Gtk::STATE_NORMAL, bg_color);


	adj_time_scrub.signal_value_changed().connect(sigc::mem_fun(*this,&Widget_Preview::slider_move));
	scr_time_scrub.signal_event().connect(sigc::mem_fun(*this,&Widget_Preview::scroll_move_event));
	draw_area.signal_expose_event().connect(sigc::mem_fun(*this,&Widget_Preview::redraw));
	
	scr_time_scrub.set_draw_value(0);

	disp_sound.set_time_adjustment(&adj_sound);
	timedisp = -1;

	//Set up signals to modify time value as it should be...
	disp_sound.signal_start_scrubbing().connect(sigc::mem_fun(*this,&Widget_Preview::scrub_updated));
	disp_sound.signal_scrub().connect(sigc::mem_fun(*this,&Widget_Preview::scrub_updated));


	Gtk::Button *button = 0;
	Gtk::Image *icon = 0;

	#if 1

	//2nd row: prevframe play/pause nextframe loop | halt-render re-preview erase-all  
	toolbar = Gtk::manage(new class Gtk::HBox(false, 0));

	//prev rendered frame
	Gtk::Button *prev_framebutton;
	Gtk::Image *icon0 = manage(new Gtk::Image(Gtk::StockID("synfig-animate_seek_prev_frame"), Gtk::ICON_SIZE_BUTTON));
	prev_framebutton = manage(new class Gtk::Button());
	prev_framebutton->set_tooltip_text(_("Prev frame"));
	icon0->set_padding(0,0);
	icon0->show();
	prev_framebutton->add(*icon0);
	prev_framebutton->set_relief(Gtk::RELIEF_NONE);
	prev_framebutton->show();
	prev_framebutton->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,&Widget_Preview::seek_frame), -1));

	toolbar->pack_start(*prev_framebutton, Gtk::PACK_SHRINK, 0);

	{ //play
		Gtk::Image *icon = manage(new Gtk::Image(Gtk::StockID("synfig-animate_play"), Gtk::ICON_SIZE_BUTTON));
		play_button = manage(new class Gtk::Button());
		play_button->set_tooltip_text(_("Play"));
		icon->set_padding(0,0);
		icon->show();
		play_button->add(*icon);
		play_button->set_relief(Gtk::RELIEF_NONE);
		play_button->show();
		play_button->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Preview::on_play_pause_pressed));
		toolbar->pack_start(*play_button, Gtk::PACK_SHRINK, 0);
	}

	{ //pause
		Gtk::Image *icon = manage(new Gtk::Image(Gtk::StockID("synfig-animate_pause"), Gtk::ICON_SIZE_BUTTON));
		pause_button = manage(new class Gtk::Button());
		pause_button->set_tooltip_text(_("Pause"));
		icon->set_padding(0,0);
		icon->show();
		pause_button->add(*icon);
		pause_button->set_relief(Gtk::RELIEF_NONE);
		pause_button->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Preview::on_play_pause_pressed));
		toolbar->pack_start(*pause_button, Gtk::PACK_SHRINK, 0);
	}


	//next rendered frame
	Gtk::Button *next_framebutton;
	Gtk::Image *icon2 = manage(new Gtk::Image(Gtk::StockID("synfig-animate_seek_next_frame"), Gtk::ICON_SIZE_BUTTON));
	next_framebutton = manage(new class Gtk::Button());
	next_framebutton->set_tooltip_text(_("Next frame"));
	icon2->set_padding(0,0);
	icon2->show();
	next_framebutton->add(*icon2);
	next_framebutton->set_relief(Gtk::RELIEF_NONE);
	next_framebutton->show();
	next_framebutton->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,&Widget_Preview::seek_frame), 1));

	toolbar->pack_start(*next_framebutton, Gtk::PACK_SHRINK, 0);

	//spacing
	Gtk::Alignment *space = Gtk::manage(new Gtk::Alignment());
	space->set_size_request(8);
	toolbar->pack_start(*space, false, true);


	//loop
	button = &b_loop;
	IMAGIFY_BUTTON(button,"synfig-animate_loop", _("Loop"));
	toolbar->pack_start(b_loop, Gtk::PACK_SHRINK,0);

	//spacing
	Gtk::Alignment *space1 = Gtk::manage(new Gtk::Alignment());
	space1->set_size_request(24);
	toolbar->pack_start(*space1, false, true);


	//halt render
	button = manage(new Gtk::Button(/*_("Halt Render")*/));
	button->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Preview::stoprender));
	IMAGIFY_BUTTON(button,Gtk::Stock::STOP, _("Halt render"));

	toolbar->pack_start(*button, Gtk::PACK_SHRINK, 0);

	//re-preview
	button = manage(new Gtk::Button(/*_("Re-Preview")*/));
	button->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Preview::repreview));
	IMAGIFY_BUTTON(button, Gtk::Stock::EDIT, _("Re-preview"));

	toolbar->pack_start(*button, Gtk::PACK_SHRINK, 0);

	//erase all
	button = manage(new Gtk::Button(/*_("Erase All")*/));
	button->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Preview::eraseall));
	IMAGIFY_BUTTON(button, Gtk::Stock::CLEAR, _("Erase all rendered frame(s)"));

	toolbar->pack_start(*button, Gtk::PACK_SHRINK, 0);

	//spacing
	Gtk::Alignment *space2 = Gtk::manage(new Gtk::Alignment());
	space1->set_size_request(24);
	toolbar->pack_start(*space2, false, true);

	//jack
	jackdial = Gtk::manage(new JackDial());
#ifdef WITH_JACK
	jack_dispatcher.connect(sigc::mem_fun(*this, &Widget_Preview::on_jack_sync));
	jackdial->signal_enable_jack().connect(sigc::mem_fun(*this, &studio::Widget_Preview::on_toggle_jack_pressed));
	jackdial->signal_offset_changed().connect(sigc::mem_fun(*this, &studio::Widget_Preview::on_jack_offset_changed));
	jackdial->signal_disable_jack().connect(sigc::mem_fun(*this, &studio::Widget_Preview::on_toggle_jack_pressed));
#endif
	//FIXME: Hardcoded FPS!
	jackdial->set_fps(24.f);
	jackdial->set_offset(jack_offset);
	if ( !getenv("SYNFIG_DISABLE_JACK") )
		jackdial->show();
	toolbar->pack_start(*jackdial, false, true);

	//zoom preview
	factor_refTreeModel = Gtk::ListStore::create(factors);
	zoom_preview.set_model(factor_refTreeModel);
	zoom_preview.property_has_frame() = true;
	zoom_preview.signal_changed().connect(sigc::mem_fun(*this, &Widget_Preview::preview_draw));

	Gtk::TreeModel::Row row = *(factor_refTreeModel->append());
	row[factors.factor_id] = "1";
	row[factors.factor_value] = "25%";

	row = *(factor_refTreeModel->append());
	row[factors.factor_id] = "2";
	row[factors.factor_value] = "50%";

	row = *(factor_refTreeModel->append());
	row[factors.factor_id] = "3";
	row[factors.factor_value] = "100%";

	row = *(factor_refTreeModel->append());
	row[factors.factor_id] = "4";
	row[factors.factor_value] = "200%";

	row = *(factor_refTreeModel->append());
	row[factors.factor_id] = "5";
	row[factors.factor_value] = _("Fit");
	zoom_preview.set_text_column(factors.factor_value);

	Gtk::Entry* entry = zoom_preview.get_entry();
	entry->set_text("100%"); //default zoom level
	entry->set_icon_from_stock(Gtk::StockID("synfig-zoom"));
	entry->signal_activate().connect(sigc::mem_fun(*this, &Widget_Preview::on_zoom_entry_activated));

	//set the zoom widget width
	zoom_preview.set_size_request(100, -1);
	zoom_preview.show();

	toolbar->pack_end(zoom_preview, Gtk::PACK_SHRINK, 0);

	show_toolbar();

	//3rd row: previewing frame numbering and rendered frame numbering
	Gtk::HBox *status = manage(new Gtk::HBox);
	status->pack_start(l_currenttime, Gtk::PACK_SHRINK, 5);
	Gtk::Label *separator = manage(new Gtk::Label(" / "));
	status->pack_start(*separator, Gtk::PACK_SHRINK, 0);
	status->pack_start(l_lasttime, Gtk::PACK_SHRINK, 5);

	status->show_all();

	//5th row: sound track
	disp_sound.set_size_request(-1,32);

	// attach all widgets	
	attach(preview_window, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0);
	attach(scr_time_scrub, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
	attach(*toolbar, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL);
	attach(*status, 0, 1, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
//	attach(disp_sound,0,1,4,5,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK);
	preview_window.show_all();
	scr_time_scrub.show_all();

	//if(draw_area.get_window()) gc_area = Gdk::GC::create(draw_area.get_window());
	#endif
}
//------------------------------------------------------------------------------
bool mforms::gtk::ToolBarImpl::create_tool_item(mforms::ToolBarItem *item, ToolBarItemType type) {
  Gtk::Widget *w = 0;
  switch (type) {
    case mforms::TextActionItem:
    case mforms::ActionItem:
    case mforms::SwitcherItem: {
      Gtk::Button *btn = Gtk::manage(new Gtk::Button());
      btn->set_focus_on_click(false);
      btn->set_border_width(0);
      btn->set_relief(Gtk::RELIEF_NONE);
      btn->signal_clicked().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), btn, item));
      if (type == mforms::SwitcherItem)
        btn->set_always_show_image(true);
      w = btn;
      break;
    }
    case mforms::SegmentedToggleItem:
    case mforms::ToggleItem: {
      Gtk::ToggleButton *btn = Gtk::manage(new Gtk::ToggleButton());
      btn->set_focus_on_click(false);
      btn->set_relief(Gtk::RELIEF_NONE);
      btn->signal_toggled().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), btn, item));
      btn->set_inconsistent(false);

      w = btn;
      break;
    }
    case mforms::SeparatorItem: {
      Gtk::Separator *sep = new Gtk::Separator(Gtk::ORIENTATION_VERTICAL);
      w = sep;
      break;
    }
    case mforms::SearchFieldItem: {
#if GTK_VERSION_GE(2, 16)
      Gtk::Entry *entry = Gtk::manage(new Gtk::Entry());
      w = entry;
      entry->set_icon_from_stock(Gtk::Stock::FIND);
#else
      Gtk::Box *hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0));
      w = hbox;
      Gtk::Image *image = Gtk::manage(new Gtk::Image(Gtk::Stock::FIND, Gtk::ICON_SIZE_MENU));
      Gtk::Entry *entry = Gtk::manage(new Gtk::Entry());

      hbox->pack_start(*image, false, true);
      hbox->pack_start(*entry, true, true);
      hbox->set_data("entry", entry);
      hbox->show_all();
#endif
      entry->signal_activate().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), entry, item));
      break;
    }
    case mforms::TextEntryItem: {
      Gtk::Box *hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0));
      w = hbox;
      Gtk::Entry *entry = Gtk::manage(new Gtk::Entry());
      hbox->pack_start(*entry, true, true);
      hbox->set_data("entry", entry);
      hbox->show_all();
      entry->signal_activate().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), entry, item));
      break;
    }
    case mforms::FlatSelectorItem:
    case mforms::SelectorItem: {
      Gtk::ComboBoxText *ct = Gtk::manage(new Gtk::ComboBoxText());
      ct->signal_changed().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), ct, item));

      w = ct;
      break;
    }
    case mforms::ColorSelectorItem: {
      if (!color_combo_columns) {
        color_combo_columns = new ColorComboColumns();
      }
      Gtk::ComboBox *ct = Gtk::manage(new Gtk::ComboBox());

      ct->pack_start(color_combo_columns->image);
      ct->signal_changed().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), ct, item));

      w = ct;

      break;
    }
    case mforms::ExpanderItem:
    case mforms::LabelItem: {
      Gtk::Label *label = Gtk::manage(new Gtk::Label("", 0.0, 0.5));
      w = label;
      break;
    }
    case mforms::ImageBoxItem: {
      Gtk::Image *image = Gtk::manage(new Gtk::Image());
      w = image;
      break;
    }
    case mforms::TitleItem: {
      Gtk::Label *label = Gtk::manage(new Gtk::Label("", 0.0, 0.5));
      w = label;
      auto provider = Gtk::CssProvider::create();
      provider->load_from_data("* { color: #333; font-weight: bold; }");
      w->get_style_context()->add_provider(provider, GTK_STYLE_PROVIDER_PRIORITY_USER);
      break;
    }
  }

  if (w) {
    w->show();
  } else
    logError("create_tool_item, widget is 0 for passed type %i\n", type);

  item->set_data(w);

  return w != 0;
}