Add Resolution Dial widget. Synchronise Low res check button with low res action...
[synfig.git] / synfig-studio / trunk / src / gtkmm / canvasview.cpp
index 89bad1b..92882f7 100644 (file)
@@ -99,7 +99,6 @@
 #include "preview.h"
 #include "audiocontainer.h"
 #include "widget_timeslider.h"
-#include "framedial.h"
 #include "keyframedial.h"
 
 #include <synfigapp/main.h>
@@ -705,6 +704,8 @@ CanvasView::CanvasView(etl::loose_handle<Instance> instance,etl::handle<synfigap
        layer_tree=0;
        children_tree=0;
        duck_refresh_flag=true;
+       toggling_ducks_=false;
+       changing_resolution_=false;
 
        smach_.set_default_state(&state_normal);
 
@@ -736,9 +737,10 @@ CanvasView::CanvasView(etl::loose_handle<Instance> instance,etl::handle<synfigap
        //create all allocated stuff for this canvas
        audio = new AudioContainer();
 
-       Gtk::Table *layout_table= manage(new class Gtk::Table(1, 3, false));
+       Gtk::Table *layout_table= manage(new class Gtk::Table(1, 4, false));
        //layout_table->attach(*vpaned, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
        layout_table->attach(*create_work_area(), 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       layout_table->attach(*create_display_bar(), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
        init_menus();
        //layout_table->attach(*App::ui_manager()->get_widget("/menu-main"), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
 
@@ -952,7 +954,6 @@ CanvasView::create_time_bar()
        //Gtk::HScrollbar *time_scroll = manage(new class Gtk::HScrollbar(time_adjustment()));
        //TIME BAR TEMPORARY POSITION
        //Widget_Timeslider *time_scroll = manage(new Widget_Timeslider);
-       timeslider->show();
        timeslider->set_time_adjustment(&time_adjustment());
        timeslider->set_bounds_adjustment(&time_window_adjustment());
        //layout_table->attach(*timeslider, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL);
@@ -961,21 +962,18 @@ CanvasView::create_time_bar()
        tooltips.set_tip(*timeslider,_("Changes the current time"));
        time_window_scroll->show();
        timeslider->show();
-       time_window_scroll->set_flags(Gtk::CAN_FOCUS);
+       //time_window_scroll->set_flags(Gtk::CAN_FOCUS); // Uncomment this produce bad render of the HScroll
        timeslider->set_flags(Gtk::CAN_FOCUS);
 
        //time_scroll->signal_value_changed().connect(sigc::mem_fun(*work_area, &studio::WorkArea::render_preview_hook));
        //time_scroll->set_update_policy(Gtk::UPDATE_DISCONTINUOUS);
 
        //Setup the Animation Mode Button and the Keyframe Lock button
-       NORMAL_BUTTON(animatebutton,"gtk-yes",_("Animate"));
+       Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
+       SMALL_BUTTON(animatebutton,"gtk-yes",_("Animate"));
        animatebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_animate_button_pressed));
        animatebutton->show();
 
-       NORMAL_BUTTON(keyframebutton,"synfig-keyframe_lock_all",_("All Keyframes Locked"));
-       keyframebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_button_pressed));
-       keyframebutton->show();
-
        //Setup the audio display
        disp_audio->set_size_request(-1,32); //disp_audio->show();
        disp_audio->set_time_adjustment(&time_adjustment());
@@ -995,15 +993,21 @@ CanvasView::create_time_bar()
        current_time_widget->signal_value_changed().connect(
                sigc::mem_fun(*this,&CanvasView::on_current_time_widget_changed)
        );
+       current_time_widget->set_size_request(0,-1); // request horizontal shrink
+       tooltips.set_tip(*current_time_widget,_("Current time"));
+       current_time_widget->show();
 
        //Setup the FrameDial widget
-       FrameDial *framedial = manage(new class FrameDial());
+       framedial = manage(new class FrameDial());
        framedial->signal_seek_begin().connect(
                        sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time), Time::begin())
        );
        framedial->signal_seek_prev_frame().connect(
                        sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame), -1)
        );
+       framedial->signal_play_stop().connect(
+                       sigc::mem_fun(*this, &studio::CanvasView::on_play_stop_pressed)
+       );
        framedial->signal_seek_next_frame().connect(
                        sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame), 1)
        );
@@ -1016,25 +1020,25 @@ CanvasView::create_time_bar()
        KeyFrameDial *keyframedial = Gtk::manage(new class KeyFrameDial());
        keyframedial->signal_seek_prev_keyframe().connect(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe));
        keyframedial->signal_seek_next_keyframe().connect(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe));
+       keyframedial->signal_lock_keyframe().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_button_pressed));
        keyframedial->show();
+       keyframebutton=keyframedial->get_lock_button();
 
-       Gtk::Table *table = manage(new class Gtk::Table(4, 4, false));
-       timebar = table;
-
-       //Attach widgets to the time bar table
-       table->attach(*manage(disp_audio), 1, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
-       table->attach(*framedial, 0, 1, 2, 3,Gtk::SHRINK, Gtk::SHRINK);
-       table->attach(*current_time_widget, 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
-       table->attach(*timeslider, 1, 4, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
-       table->attach(*time_window_scroll, 1, 4, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
-       table->attach(*keyframedial, 0, 1, 3, 4, Gtk::SHRINK, Gtk::SHRINK);
-       table->attach(*animatebutton, 2, 3, 3, 4, Gtk::SHRINK, Gtk::SHRINK);
-       table->attach(*keyframebutton, 1, 2, 3, 4, Gtk::SHRINK, Gtk::SHRINK);
+       timebar = manage(new class Gtk::Table(5, 4, false));
 
+       //Attach widgets to the timebar
+       timebar->attach(*manage(disp_audio), 1, 5, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
+       timebar->attach(*framedial, 0, 1, 2, 3,Gtk::SHRINK, Gtk::SHRINK);
+       timebar->attach(*current_time_widget, 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
+       timebar->attach(*timeslider, 1, 3, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
+       timebar->attach(*time_window_scroll, 1, 3, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
+       timebar->attach(*keyframedial, 3, 4, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
+       timebar->attach(*animatebutton, 4, 5, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
+       //timebar->attach(*keyframebutton, 1, 2, 3, 4, Gtk::SHRINK, Gtk::SHRINK);
 
-       table->show();
+       timebar->show();
 
-       return table;
+       return timebar;
 }
 
 Gtk::Widget *
@@ -1092,6 +1096,58 @@ CanvasView::create_status_bar()
        return statusbartable;
 }
 
+Gtk::Widget*
+CanvasView::create_display_bar()
+{
+       displaybar = manage(new class Gtk::Table(1, 1, false));
+
+       // Setup the ToggleDuckDial widget
+       toggleducksdial = Gtk::manage(new class ToggleDucksDial());
+
+       Duck::Type m = work_area->get_type_mask();
+       toggleducksdial->update_toggles(m);
+
+       toggleducksdial->signal_ducks_position().connect(
+                       sigc::bind(sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),Duck::TYPE_POSITION)
+                       );
+       toggleducksdial->signal_ducks_vertex().connect(
+                       sigc::bind(sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),Duck::TYPE_VERTEX)
+                       );
+       toggleducksdial->signal_ducks_tangent().connect(
+                       sigc::bind(sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),Duck::TYPE_TANGENT)
+                       );
+       toggleducksdial->signal_ducks_radius().connect(
+                       sigc::bind(sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),Duck::TYPE_RADIUS)
+                       );
+       toggleducksdial->signal_ducks_width().connect(
+                       sigc::bind(sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),Duck::TYPE_WIDTH)
+                       );
+       toggleducksdial->signal_ducks_angle().connect(
+                       sigc::bind(sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),Duck::TYPE_ANGLE)
+                       );
+       toggleducksdial->show();
+
+       // Set up the ResolutionDial widget
+
+       resolutiondial=Gtk::manage(new class ResolutionDial());
+
+       resolutiondial->update_lowres(work_area->get_low_resolution_flag());
+       resolutiondial->signal_increase_resolution().connect(
+                       sigc::mem_fun(*this, &studio::CanvasView::decrease_low_res_pixel_size));
+       resolutiondial->signal_decrease_resolution().connect(
+                       sigc::mem_fun(*this, &studio::CanvasView::increase_low_res_pixel_size));
+       resolutiondial->signal_use_low_resolution().connect(
+                       sigc::mem_fun(*this, &studio::CanvasView::toggle_low_res_pixel_flag));
+       resolutiondial->show();
+
+       displaybar->attach(*resolutiondial, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
+       displaybar->attach(*toggleducksdial, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
+       displaybar->show();
+
+       return displaybar;
+
+}
+
 void
 CanvasView::on_current_time_widget_changed()
 {
@@ -1412,7 +1468,7 @@ CanvasView::init_menus()
 
                action = Gtk::ToggleAction::create("toggle-low-res", _("Use Low-Res"));
                action->set_active(work_area->get_low_resolution_flag());
-               action_group->add(action, sigc::mem_fun(*work_area, &studio::WorkArea::toggle_low_resolution_flag));
+               action_group->add(action, sigc::mem_fun(*this, &studio::CanvasView::toggle_low_res_pixel_flag));
 
                action = Gtk::ToggleAction::create("toggle-onion-skin", _("Show Onion Skin"));
                action->set_active(work_area->get_onion_skin());
@@ -2577,10 +2633,11 @@ void
 CanvasView::on_mode_changed(synfigapp::CanvasInterface::Mode mode)
 {
        // If the animate flag was set in mode...
+       Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
        if(mode&synfigapp::MODE_ANIMATE)
        {
                Gtk::Image *icon;
-               icon=manage(new Gtk::Image(Gtk::StockID("gtk-no"),Gtk::ICON_SIZE_BUTTON));
+               icon=manage(new Gtk::Image(Gtk::StockID("gtk-no"),iconsize));
                animatebutton->remove();
                animatebutton->add(*icon);
                tooltips.set_tip(*animatebutton,_("In Animate Editing Mode"));
@@ -2590,7 +2647,7 @@ CanvasView::on_mode_changed(synfigapp::CanvasInterface::Mode mode)
        else
        {
                Gtk::Image *icon;
-               icon=manage(new Gtk::Image(Gtk::StockID("gtk-yes"),Gtk::ICON_SIZE_BUTTON));
+               icon=manage(new Gtk::Image(Gtk::StockID("gtk-yes"),iconsize));
                animatebutton->remove();
                animatebutton->add(*icon);
                tooltips.set_tip(*animatebutton,_("Not in Animate Editing Mode"));
@@ -3025,9 +3082,11 @@ CanvasView::rebuild_ducks()
 void
 CanvasView::decrease_low_res_pixel_size()
 {
+       if(changing_resolution_)
+               return;
+       changing_resolution_=true;
        list<int> sizes = CanvasView::get_pixel_sizes();
        int pixel_size = work_area->get_low_res_pixel_size();
-
        for (list<int>::iterator iter = sizes.begin(); iter != sizes.end(); iter++)
                if (*iter == pixel_size)
                {
@@ -3043,17 +3102,32 @@ CanvasView::decrease_low_res_pixel_size()
                        }
                        break;
                }
+       // Update the "toggle-low-res" action
+       Glib::RefPtr<Gtk::ToggleAction> action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("toggle-low-res"));
+       action->set_active(work_area->get_low_resolution_flag());
+       // Update toggle low res button
+       resolutiondial->update_lowres(work_area->get_low_resolution_flag());
+       changing_resolution_=false;
 }
 
 void
 CanvasView::increase_low_res_pixel_size()
 {
+       if(changing_resolution_)
+               return;
+       changing_resolution_=true;
        list<int> sizes = CanvasView::get_pixel_sizes();
        int pixel_size = work_area->get_low_res_pixel_size();
-
        if (!work_area->get_low_resolution_flag())
        {
+               // We were using "hi res" so change it to low res.
                work_area->set_low_resolution_flag(true);
+               // Update the "toggle-low-res" action
+               Glib::RefPtr<Gtk::ToggleAction> action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("toggle-low-res"));
+               action->set_active(true);
+               // Update the toggle low res button
+               resolutiondial->update_lowres(true);
+               changing_resolution_=false;
                return;
        }
 
@@ -3069,6 +3143,27 @@ CanvasView::increase_low_res_pixel_size()
                        }
                        break;
                }
+       // Update the "toggle-low-res" action
+       Glib::RefPtr<Gtk::ToggleAction> action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("toggle-low-res"));
+       action->set_active(work_area->get_low_resolution_flag());
+       // Update toggle low res button
+       resolutiondial->update_lowres(work_area->get_low_resolution_flag());
+       changing_resolution_=false;
+}
+
+void
+CanvasView::toggle_low_res_pixel_flag()
+{
+       if(changing_resolution_)
+               return;
+       changing_resolution_=true;
+       work_area->toggle_low_resolution_flag();
+       // Update the toggle low res button
+       resolutiondial->update_lowres(work_area->get_low_resolution_flag());
+       // Update the "toggle-low-res" action
+       Glib::RefPtr<Gtk::ToggleAction> action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("toggle-low-res"));
+       action->set_active(work_area->get_low_resolution_flag());
+       changing_resolution_=false;
 }
 
 void
@@ -3152,8 +3247,8 @@ CanvasView::play()
                        return;
                }
        }
+       on_play_stop_pressed();
        is_playing_=false;
-
        time_adjustment().set_value(endtime);
        time_adjustment().value_changed();
 }
@@ -3210,7 +3305,7 @@ void
 CanvasView::show_timebar()
 {
        timebar->show();
-       current_time_widget->show();
+       //current_time_widget->show(); // not needed now that belongs to the timebar
 
        //keyframe_tab_child->show();
        if(layer_tree)
@@ -3630,6 +3725,9 @@ CanvasView::on_keyframe_remove_pressed()
 void
 CanvasView::toggle_duck_mask(Duckmatic::Type type)
 {
+       if(toggling_ducks_)
+               return;
+       toggling_ducks_=true;
        bool is_currently_on(work_area->get_type_mask()&type);
 
        if(is_currently_on)
@@ -3638,6 +3736,15 @@ CanvasView::toggle_duck_mask(Duckmatic::Type type)
                work_area->set_type_mask(work_area->get_type_mask()|type);
 
        work_area->queue_draw();
+       try
+       {
+               toggleducksdial->update_toggles(work_area->get_type_mask());
+       }
+       catch(...)
+       {
+               toggling_ducks_=false;
+       }
+       toggling_ducks_=false;
 }
 
 void
@@ -3917,3 +4024,30 @@ CanvasView::on_delete_event(GdkEventAny* event __attribute__ ((unused)))
 
        return true;
 }
+
+//! Modify the play stop button apearence and play stop the animation
+void
+CanvasView::on_play_stop_pressed()
+{
+       Gtk::Image *icon;
+       Gtk::Button *stop_button;
+       stop_button=framedial->get_play_button();
+       bool play_flag;
+       if(!is_playing())
+       {
+               icon = manage(new Gtk::Image(Gtk::Stock::MEDIA_STOP, Gtk::IconSize::from_name("synfig-small_icon")));
+               stop_button->set_relief(Gtk::RELIEF_NORMAL);
+               play_flag=true;
+       }
+       else
+       {
+               icon = manage(new Gtk::Image(Gtk::Stock::MEDIA_PLAY, Gtk::IconSize::from_name("synfig-small_icon")));
+               stop_button->set_relief(Gtk::RELIEF_NONE);
+               play_flag=false;
+       }
+       stop_button->remove();
+       stop_button->add(*icon);
+       icon->set_padding(0, 0);
+       icon->show();
+       if(play_flag) play(); else stop();
+}