Fix 1346746: init targets before using them during rendering in synfigstudio
[synfig.git] / synfig-studio / trunk / src / gtkmm / render.cpp
index 9328b2b..bc1c9cf 100644 (file)
@@ -1,20 +1,21 @@
-/* === S I N F G =========================================================== */
+/* === S Y N F I G ========================================================= */
 /*!    \file render.cpp
 **     \brief Template File
 **
 **     $Id: render.cpp,v 1.2 2005/01/10 08:13:44 darco Exp $
 **
 **     \legal
-**     Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
 **
-**     This software and associated documentation
-**     are CONFIDENTIAL and PROPRIETARY property of
-**     the above-mentioned copyright holder.
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
 **
-**     You may not copy, print, publish, or in any
-**     other way distribute this software without
-**     a prior written agreement with
-**     the copyright holder.
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
 **     \endlegal
 */
 /* ========================================================================= */
@@ -31,8 +32,9 @@
 #include "render.h"
 #include "app.h"
 #include <gtkmm/frame.h>
-#include <sinfg/target_scanline.h>
-#include <sinfg/canvas.h>
+#include <gtkmm/alignment.h>
+#include <synfig/target_scanline.h>
+#include <synfig/canvas.h>
 #include "asyncrenderer.h"
 
 #endif
@@ -41,7 +43,7 @@
 
 using namespace std;
 using namespace etl;
-using namespace sinfg;
+using namespace synfig;
 using namespace studio;
 
 /* === M A C R O S ========================================================= */
@@ -52,14 +54,14 @@ using namespace studio;
 
 /* === M E T H O D S ======================================================= */
 
-RenderSettings::RenderSettings(Gtk::Window& parent,handle<sinfgapp::CanvasInterface> canvas_interface):
+RenderSettings::RenderSettings(Gtk::Window& parent,handle<synfigapp::CanvasInterface> canvas_interface):
        Gtk::Dialog(_("Render Settings"),parent,false,true),
        canvas_interface_(canvas_interface),
        adjustment_quality(3,0,9),
        entry_quality(adjustment_quality,1,0),
        adjustment_antialias(1,1,31),
        entry_antialias(adjustment_antialias,1,0),
-       toggle_single_frame(_("Use Current Frame"))
+       toggle_single_frame(_("Use _current frame"), true)
 {
        widget_rend_desc.show();
        widget_rend_desc.signal_changed().connect(sigc::mem_fun(*this,&studio::RenderSettings::on_rend_desc_changed));
@@ -73,8 +75,8 @@ RenderSettings::RenderSettings(Gtk::Window& parent,handle<sinfgapp::CanvasInterf
                        sigc::bind(sigc::mem_fun(*this,&RenderSettings::set_target),String())
                ));
 
-       sinfg::Target::Book::iterator iter;
-       sinfg::Target::Book book(sinfg::Target::book());
+       synfig::Target::Book::iterator iter;
+       synfig::Target::Book book(synfig::Target::book());
        
        for(iter=book.begin();iter!=book.end();iter++)
        {
@@ -85,42 +87,76 @@ RenderSettings::RenderSettings(Gtk::Window& parent,handle<sinfgapp::CanvasInterf
        optionmenu_target.set_menu(*menu_target);
 
        optionmenu_target.set_history(0);
-       
-       
-       
-       
+
+       Gtk::Alignment *dialogPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
+       dialogPadding->set_padding(12, 12, 12, 12);
+       get_vbox()->pack_start(*dialogPadding, false, false, 0);
+
+       Gtk::VBox *dialogBox = manage(new Gtk::VBox(false, 12));
+       dialogPadding->add(*dialogBox);
 
        Gtk::Button *choose_button(manage(new class Gtk::Button(Gtk::StockID(_("Choose...")))));
        choose_button->show();
        choose_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::RenderSettings::on_choose_pressed));
        
        Gtk::Frame *target_frame=manage(new Gtk::Frame(_("Target")));
-       Gtk::Table *target_table=manage(new Gtk::Table(2,2,false));
-       target_frame->add(*target_table);
-       target_table->attach(*manage(new Gtk::Label(_("Filename"))), 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);   
-       target_table->attach(entry_filename, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);   
+       target_frame->set_shadow_type(Gtk::SHADOW_NONE);
+       ((Gtk::Label *) target_frame->get_label_widget())->set_markup(_("<b>Target</b>"));
+       dialogBox->pack_start(*target_frame);
+       Gtk::Alignment *targetPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
+       targetPadding->set_padding(6, 0, 24, 0);
+       target_frame->add(*targetPadding);
+       
+       Gtk::Table *target_table = manage(new Gtk::Table(2, 3, false));
+       target_table->set_row_spacings(6);
+       target_table->set_col_spacings(12);
+       targetPadding->add(*target_table);
+
+       Gtk::Label *filenameLabel = manage(new Gtk::Label(_("_Filename"), true));
+       filenameLabel->set_alignment(0, 0.5);
+       filenameLabel->set_mnemonic_widget(entry_filename);
+       target_table->attach(*filenameLabel, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
+       target_table->attach(entry_filename, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
        target_table->attach(*choose_button, 2, 3, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);   
-       target_table->attach(*manage(new Gtk::Label(_("Target"))), 3, 4, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);     
-       target_table->attach(optionmenu_target, 4, 5, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);        
-       get_vbox()->pack_start(*target_frame);
+       
+       Gtk::Label *targetLabel = manage(new Gtk::Label(_("_Target"), true));
+       targetLabel->set_alignment(0, 0.5);
+       targetLabel->set_mnemonic_widget(optionmenu_target);
+       target_table->attach(*targetLabel, 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);     
+       target_table->attach(optionmenu_target, 1, 3, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);        
 
        toggle_single_frame.signal_toggled().connect(sigc::mem_fun(*this, &studio::RenderSettings::on_single_frame_toggle));
 
-
        Gtk::Frame *settings_frame=manage(new Gtk::Frame(_("Settings")));
+       settings_frame->set_shadow_type(Gtk::SHADOW_NONE);
+       ((Gtk::Label *) settings_frame->get_label_widget())->set_markup(_("<b>Settings</b>"));
+       dialogBox->pack_start(*settings_frame);
+
+       Gtk::Alignment *settingsPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
+       settingsPadding->set_padding(6, 0, 24, 0);
+       settings_frame->add(*settingsPadding);
+       
        Gtk::Table *settings_table=manage(new Gtk::Table(2,2,false));
-       settings_frame->add(*settings_table);
-       settings_table->attach(*manage(new Gtk::Label(_("Quality"))), 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);  
+       settings_table->set_row_spacings(6);
+       settings_table->set_col_spacings(12);
+       settingsPadding->add(*settings_table);
+
+       Gtk::Label *qualityLabel = manage(new Gtk::Label(_("_Quality"), true));
+       qualityLabel->set_alignment(0, 0.5);
+       qualityLabel->set_mnemonic_widget(entry_quality);
+       settings_table->attach(*qualityLabel, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);  
        settings_table->attach(entry_quality, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);  
-       settings_table->attach(*manage(new Gtk::Label(_("Anti-Alias"))), 2, 3, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);       
-       settings_table->attach(entry_antialias, 3, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);        
-       settings_table->attach(toggle_single_frame, 4, 5, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);    
-       get_vbox()->pack_start(*settings_frame);
-       
-       
 
+       Gtk::Label *antiAliasLabel = manage(new Gtk::Label(_("_Anti-Aliasing"), true));
+       antiAliasLabel->set_alignment(0, 0.5);
+       antiAliasLabel->set_mnemonic_widget(entry_antialias);
+       settings_table->attach(*antiAliasLabel, 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);        
+       settings_table->attach(entry_antialias, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);        
+       
+       toggle_single_frame.set_alignment(0, 0.5);
+       settings_table->attach(toggle_single_frame, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);    
 
-       get_vbox()->pack_start(widget_rend_desc);
+       dialogBox->pack_start(widget_rend_desc);
        
        
        Gtk::Button *render_button(manage(new class Gtk::Button(Gtk::StockID("Render"))));
@@ -144,11 +180,11 @@ RenderSettings::RenderSettings(Gtk::Window& parent,handle<sinfgapp::CanvasInterf
 
        try
        {
-               entry_filename.set_text(Glib::build_filename(Glib::get_home_dir(),"Desktop/output.png"));
+               entry_filename.set_text(Glib::build_filename(Glib::get_home_dir(),Glib::ustring("Desktop")+ETL_DIRECTORY_SEPERATOR+Glib::ustring("output.png")));
        }
        catch(...)
        {
-               sinfg::warning("Averted crash!");
+               synfig::warning("Averted crash!");
                entry_filename.set_text("output.png");
        }
        
@@ -166,7 +202,7 @@ RenderSettings::on_rend_desc_changed()
 }
 
 void
-RenderSettings::set_target(sinfg::String name)
+RenderSettings::set_target(synfig::String name)
 {
        target_name=name;
 }
@@ -234,6 +270,10 @@ RenderSettings::on_render_pressed()
 
        target->set_rend_desc(&rend_desc);
        target->set_quality((int)adjustment_quality.get_value());
+       if( !target->init() ){
+               canvas_interface_->get_ui_interface()->error(_("Target initialisation failure"));
+               return;
+       }
 
        canvas_interface_->get_ui_interface()->task(_("Rendering ")+filename);