1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
5 ** $Id: render.cpp,v 1.2 2005/01/10 08:13:44 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
34 #include <gtkmm/frame.h>
35 #include <synfig/target_scanline.h>
36 #include <synfig/canvas.h>
37 #include "asyncrenderer.h"
41 /* === U S I N G =========================================================== */
45 using namespace synfig;
46 using namespace studio;
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
52 /* === P R O C E D U R E S ================================================= */
54 /* === M E T H O D S ======================================================= */
56 RenderSettings::RenderSettings(Gtk::Window& parent,handle<synfigapp::CanvasInterface> canvas_interface):
57 Gtk::Dialog(_("Render Settings"),parent,false,true),
58 canvas_interface_(canvas_interface),
59 adjustment_quality(3,0,9),
60 entry_quality(adjustment_quality,1,0),
61 adjustment_antialias(1,1,31),
62 entry_antialias(adjustment_antialias,1,0),
63 toggle_single_frame(_("Use Current Frame"))
65 widget_rend_desc.show();
66 widget_rend_desc.signal_changed().connect(sigc::mem_fun(*this,&studio::RenderSettings::on_rend_desc_changed));
67 widget_rend_desc.set_rend_desc(canvas_interface_->get_canvas()->rend_desc());
69 canvas_interface->signal_rend_desc_changed().connect(sigc::mem_fun(*this,&RenderSettings::on_rend_desc_changed));
71 menu_target=manage(new class Gtk::Menu());
73 menu_target->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Auto"),
74 sigc::bind(sigc::mem_fun(*this,&RenderSettings::set_target),String())
77 synfig::Target::Book::iterator iter;
78 synfig::Target::Book book(synfig::Target::book());
80 for(iter=book.begin();iter!=book.end();iter++)
82 menu_target->items().push_back(Gtk::Menu_Helpers::MenuElem(iter->first,
83 sigc::bind(sigc::mem_fun(*this,&RenderSettings::set_target),iter->first)
86 optionmenu_target.set_menu(*menu_target);
88 optionmenu_target.set_history(0);
94 Gtk::Button *choose_button(manage(new class Gtk::Button(Gtk::StockID(_("Choose...")))));
95 choose_button->show();
96 choose_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::RenderSettings::on_choose_pressed));
98 Gtk::Frame *target_frame=manage(new Gtk::Frame(_("Target")));
99 Gtk::Table *target_table=manage(new Gtk::Table(2,2,false));
100 target_frame->add(*target_table);
101 target_table->attach(*manage(new Gtk::Label(_("Filename"))), 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
102 target_table->attach(entry_filename, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
103 target_table->attach(*choose_button, 2, 3, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
104 target_table->attach(*manage(new Gtk::Label(_("Target"))), 3, 4, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
105 target_table->attach(optionmenu_target, 4, 5, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
106 get_vbox()->pack_start(*target_frame);
108 toggle_single_frame.signal_toggled().connect(sigc::mem_fun(*this, &studio::RenderSettings::on_single_frame_toggle));
111 Gtk::Frame *settings_frame=manage(new Gtk::Frame(_("Settings")));
112 Gtk::Table *settings_table=manage(new Gtk::Table(2,2,false));
113 settings_frame->add(*settings_table);
114 settings_table->attach(*manage(new Gtk::Label(_("Quality"))), 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
115 settings_table->attach(entry_quality, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
116 settings_table->attach(*manage(new Gtk::Label(_("Anti-Alias"))), 2, 3, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
117 settings_table->attach(entry_antialias, 3, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
118 settings_table->attach(toggle_single_frame, 4, 5, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
119 get_vbox()->pack_start(*settings_frame);
124 get_vbox()->pack_start(widget_rend_desc);
127 Gtk::Button *render_button(manage(new class Gtk::Button(Gtk::StockID("Render"))));
128 render_button->show();
129 add_action_widget(*render_button,1);
130 render_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::RenderSettings::on_render_pressed));
132 Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-cancel"))));
133 cancel_button->show();
134 add_action_widget(*cancel_button,0);
135 cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::RenderSettings::on_cancel_pressed));
137 //set_default_response(1);
139 set_title(_("Render Settings")+String(" - ")+canvas_interface_->get_canvas()->get_name());
142 toggle_single_frame.set_active(true);
143 widget_rend_desc.disable_time_section();
148 entry_filename.set_text(Glib::build_filename(Glib::get_home_dir(),Glib::ustring("Desktop")+ETL_DIRECTORY_SEPERATOR+Glib::ustring("output.png")));
152 synfig::warning("Averted crash!");
153 entry_filename.set_text("output.png");
156 get_vbox()->show_all();
159 RenderSettings::~RenderSettings()
164 RenderSettings::on_rend_desc_changed()
166 widget_rend_desc.set_rend_desc(canvas_interface_->get_canvas()->rend_desc());
170 RenderSettings::set_target(synfig::String name)
176 RenderSettings::on_choose_pressed()
178 String filename=entry_filename.get_text();
179 if(App::dialog_saveas_file("Save Render As",filename))
180 entry_filename.set_text(filename);
184 RenderSettings::on_render_pressed()
186 String filename=entry_filename.get_text();
190 canvas_interface_->get_ui_interface()->error(_("You must supply a filename!"));
194 // If the target type is not yet defined,
195 // try to figure it out from the outfile.
196 if(target_name.empty())
200 String ext=String(find(filename.begin(),filename.end(),'.')+1,filename.end());
201 if(Target::ext_book().count(ext))
202 target_name=Target::ext_book()[ext];
206 catch(std::runtime_error x)
208 canvas_interface_->get_ui_interface()->error(_("Unable to determine proper target from filename."));
213 if(filename.empty() && target_name!="null")
215 canvas_interface_->get_ui_interface()->error(_("A filename is required for this target"));
219 Target::Handle target=Target::create(target_name,filename);
222 canvas_interface_->get_ui_interface()->error(_("Unable to create target for ")+filename);
228 target->set_canvas(canvas_interface_->get_canvas());
229 RendDesc rend_desc(widget_rend_desc.get_rend_desc());
230 rend_desc.set_antialias((int)adjustment_antialias.get_value());
232 // If we are to only render the current frame
233 if(toggle_single_frame.get_active())
234 rend_desc.set_time(canvas_interface_->get_time());
236 target->set_rend_desc(&rend_desc);
237 target->set_quality((int)adjustment_quality.get_value());
239 canvas_interface_->get_ui_interface()->task(_("Rendering ")+filename);
243 async_renderer->stop();
244 async_renderer.detach();
246 async_renderer=new AsyncRenderer(target);
247 async_renderer->signal_finished().connect( sigc::mem_fun(*this,&RenderSettings::on_finished));
248 async_renderer->start();
250 if(!target->render(canvas_interface_->get_ui_interface().get()))
252 canvas_interface_->get_ui_interface()->error(_("Render Failure"));
253 canvas_interface_->get_ui_interface()->amount_complete(0,10000);
258 canvas_interface_->get_ui_interface()->task(filename+_(" rendered sucessfuly"));
259 canvas_interface_->get_ui_interface()->amount_complete(0,10000);
265 RenderSettings::on_finished()
267 canvas_interface_->get_ui_interface()->task(_("File rendered sucessfuly"));
268 canvas_interface_->get_ui_interface()->amount_complete(0,10000);
272 RenderSettings::on_cancel_pressed()
278 RenderSettings::on_single_frame_toggle()
280 if(toggle_single_frame.get_active())
281 widget_rend_desc.disable_time_section();
283 widget_rend_desc.enable_time_section();