Add Play/Stop button to the Frame Dial.
[synfig.git] / synfig-studio / trunk / src / gtkmm / canvasview.cpp
index a9bda67..7c3aa0a 100644 (file)
@@ -99,6 +99,7 @@
 #include "preview.h"
 #include "audiocontainer.h"
 #include "widget_timeslider.h"
+#include "keyframedial.h"
 
 #include <synfigapp/main.h>
 #include <synfigapp/inputdevice.h>
@@ -247,6 +248,37 @@ public:
                //view->progressbar->set_fraction(0);
        }
 
+       virtual Response confirmation(const std::string &title,
+                       const std::string &primaryText,
+                       const std::string &secondaryText,
+                       const std::string &confirmPhrase,
+                       const std::string &cancelPhrase,
+                       Response defaultResponse=RESPONSE_OK)
+       {
+               view->present();
+               //while(studio::App::events_pending())studio::App::iteration(false);
+               Gtk::MessageDialog dialog(
+                       *view,                  // Parent
+                       primaryText,            // Message
+                       false,                  // Markup
+                       Gtk::MESSAGE_WARNING,   // Type
+                       Gtk::BUTTONS_NONE,      // Buttons
+                       true                    // Modal
+               );
+
+               if (! title.empty())
+                       dialog.set_title(title);
+               if (! secondaryText.empty())
+                       dialog.set_secondary_text(secondaryText);
+
+               dialog.add_button(cancelPhrase, RESPONSE_CANCEL);
+               dialog.add_button(confirmPhrase, RESPONSE_OK);
+               dialog.set_default_response(defaultResponse);
+
+               dialog.show_all();
+               return (Response) dialog.run();
+       }
+
        virtual Response yes_no(const std::string &title, const std::string &message,Response dflt=RESPONSE_YES)
        {
                view->present();
@@ -914,6 +946,7 @@ CanvasView::create_time_bar()
 {
        Gtk::Image *icon;
 
+       //Setup the Time Slider and the Time window scroll
        Gtk::HScrollbar *time_window_scroll = manage(new class Gtk::HScrollbar(time_window_adjustment()));
        //Gtk::HScrollbar *time_scroll = manage(new class Gtk::HScrollbar(time_adjustment()));
        //TIME BAR TEMPORARY POSITION
@@ -933,17 +966,13 @@ CanvasView::create_time_bar()
        //time_scroll->signal_value_changed().connect(sigc::mem_fun(*work_area, &studio::WorkArea::render_preview_hook));
        //time_scroll->set_update_policy(Gtk::UPDATE_DISCONTINUOUS);
 
-       NORMAL_BUTTON(animatebutton,"gtk-yes",_("Animate"));
+       //Setup the Animation Mode Button and the Keyframe Lock button
+       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();
-
-       Gtk::Table *table= manage(new class Gtk::Table(2, 3, false));
-
-       //setup the audio display
+       //Setup the audio display
        disp_audio->set_size_request(-1,32); //disp_audio->show();
        disp_audio->set_time_adjustment(&time_adjustment());
        disp_audio->signal_start_scrubbing().connect(
@@ -955,15 +984,60 @@ CanvasView::create_time_bar()
        disp_audio->signal_stop_scrubbing().connect(
                sigc::mem_fun(*audio,&AudioContainer::stop_scrubbing)
        );
+       //Setup the current time widget
+       current_time_widget=manage(new Widget_Time);
+       current_time_widget->set_value(get_time());
+       current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
+       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 = 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)
+       );
+       framedial->signal_seek_end().connect(
+                       sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time), Time::end())
+       );
+       framedial->show();
+
+       //Setup the KeyFrameDial widget
+       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(5, 3, false));
+       timebar = table;
+
+       //Attach widgets to the time bar table
+       table->attach(*manage(disp_audio), 1, 5, 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, 3, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
+       table->attach(*time_window_scroll, 1, 3, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
+       table->attach(*keyframedial, 3, 4, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
+       table->attach(*animatebutton, 4, 5, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
+       //table->attach(*keyframebutton, 1, 2, 3, 4, Gtk::SHRINK, Gtk::SHRINK);
 
-       table->attach(*manage(disp_audio), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
-       table->attach(*timeslider, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
-       table->attach(*time_window_scroll, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
 
-       table->attach(*animatebutton, 1, 2, 0, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
-       table->attach(*keyframebutton, 2, 3, 0, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
-       timebar=table;
        table->show();
+
        return table;
 }
 
@@ -988,7 +1062,7 @@ CanvasView::create_status_bar()
        cancel=false;
 
        // Create the status bar at the bottom of the window
-       Gtk::Table *statusbartable= manage(new class Gtk::Table(7, 1, false));
+       Gtk::Table *statusbartable= manage(new class Gtk::Table(5, 1, false));
 //     statusbar = manage(new class Gtk::Statusbar()); // This is already done at construction
        progressbar =manage(new class Gtk::ProgressBar());
        SMALL_BUTTON(stopbutton,"gtk-stop",_("Stop"));
@@ -1000,18 +1074,10 @@ CanvasView::create_status_bar()
 //     statusbartable->attach(*lowerbutton, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
 //     statusbartable->attach(*raisebutton, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
 
-       current_time_widget=manage(new Widget_Time);
-       current_time_widget->set_value(get_time());
-       current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
-       current_time_widget->signal_value_changed().connect(
-               sigc::mem_fun(*this,&CanvasView::on_current_time_widget_changed)
-       );
-
-       statusbartable->attach(*current_time_widget, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
-       statusbartable->attach(*statusbar, 3, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
-       statusbartable->attach(*progressbar, 4, 5, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 0, 0);
-       statusbartable->attach(*refreshbutton, 5, 6, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
-       statusbartable->attach(*stopbutton, 6, 7, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
+       statusbartable->attach(*statusbar, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       statusbartable->attach(*progressbar, 2, 3, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       statusbartable->attach(*refreshbutton, 3, 4, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
+       statusbartable->attach(*stopbutton, 4, 5, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
        statusbar->set_has_resize_grip(false);
        statusbar->show();
        stopbutton->show();
@@ -2173,7 +2239,7 @@ CanvasView::build_tables()
 void
 CanvasView::on_layer_toggle(synfig::Layer::Handle layer)
 {
-       synfigapp::Action::Handle action(synfigapp::Action::create("layer_activate"));
+       synfigapp::Action::Handle action(synfigapp::Action::create("LayerActivate"));
        assert(action);
 
        if(!action)
@@ -2842,15 +2908,16 @@ CanvasView::rebuild_ducks_layer_(synfig::TransformStack& transform_stack, synfig
                        Vector origin(layer->get_param("origin").get(Vector()));
 
                        Canvas::Handle child_canvas(layer->get_param("canvas").get(Canvas::Handle()));
+                       Vector focus(layer->get_param("focus").get(Vector()));
 
                        if(!scale.is_equal_to(Vector(1,1)))
-                               transform_stack.push(new Transform_Scale(scale,origin));
-                       if(!scale.is_equal_to(Vector(0,0)))
-                               transform_stack.push(new Transform_Translate(origin));
+                               transform_stack.push(new Transform_Scale(layer->get_guid(), scale,origin+focus));
+                       if(!origin.is_equal_to(Vector(0,0)))
+                               transform_stack.push(new Transform_Translate(layer->get_guid(), origin));
 
                        rebuild_ducks_layer_(transform_stack,child_canvas,selected_list);
 
-                       if(!scale.is_equal_to(Vector(0,0)))
+                       if(!origin.is_equal_to(Vector(0,0)))
                                transform_stack.pop();
                        if(!scale.is_equal_to(Vector(1,1)))
                                transform_stack.pop();
@@ -3089,8 +3156,8 @@ CanvasView::play()
                        return;
                }
        }
+       on_play_stop_pressed();
        is_playing_=false;
-
        time_adjustment().set_value(endtime);
        time_adjustment().value_changed();
 }
@@ -3147,7 +3214,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)
@@ -3160,7 +3227,7 @@ void
 CanvasView::hide_timebar()
 {
        timebar->hide();
-       current_time_widget->hide();
+       //current_time_widget->hide(); // not needed now that belongs to the timebar
        //keyframe_tab_child->hide();
        if(layer_tree)
                layer_tree->set_show_timetrack(false);
@@ -3172,7 +3239,7 @@ void
 CanvasView::set_sensitive_timebar(bool sensitive)
 {
        timebar->set_sensitive(sensitive);
-       current_time_widget->set_sensitive(sensitive);
+       //current_time_widget->set_sensitive(sensitive); //not needed now that belongs to timebar
        //keyframe_tab_child->set_sensitive(sensitive);
        if(layer_tree)
                layer_tree->set_sensitive(sensitive);
@@ -3194,7 +3261,7 @@ set_waypoint_model(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints,
                Waypoint waypoint(*iter);
                waypoint.apply_model(model);
 
-               synfigapp::Action::Handle action(synfigapp::Action::create("waypoint_set"));
+               synfigapp::Action::Handle action(synfigapp::Action::create("WaypointSet"));
 
                assert(action);
 
@@ -3319,6 +3386,16 @@ CanvasView::on_waypoint_clicked_canvasview(synfigapp::ValueDesc value_desc,
                }
 
                // ------------------------------------------------------------------------
+               if (size == 1)
+               {
+                       const synfigapp::ValueDesc value_desc(synfig::ValueNode_Animated::Handle::cast_reinterpret(waypoint.get_parent_value_node()), time);
+                       get_instance()->make_param_menu(waypoint_menu,canvas_interface()->get_canvas(),value_desc,0.5f);
+
+                       // ------------------------------------------------------------------------
+                       waypoint_menu->items().push_back(Gtk::Menu_Helpers::SeparatorElem());
+               }
+
+               // ------------------------------------------------------------------------
                waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Jump To"),
                        sigc::bind(sigc::mem_fun(*canvas_interface(), &synfigapp::CanvasInterface::set_time), time)));
 
@@ -3360,7 +3437,7 @@ CanvasView::on_waypoint_changed()
        param_list.add("waypoint",waypoint_dialog.get_waypoint());
 //     param_list.add("time",canvas_interface()->get_time());
 
-       get_instance()->process_action("waypoint_set_smart", param_list);
+       get_instance()->process_action("WaypointSetSmart", param_list);
 }
 
 void
@@ -3373,7 +3450,7 @@ CanvasView::on_waypoint_delete()
        param_list.add("waypoint",waypoint_dialog.get_waypoint());
 //     param_list.add("time",canvas_interface()->get_time());
 
-       get_instance()->process_action("waypoint_remove", param_list);
+       get_instance()->process_action("WaypointRemove", param_list);
 }
 
 void
@@ -3397,7 +3474,7 @@ CanvasView::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& con
                        if(!layer->set_param("text",ValueBase(selection_data)))
                                break;
 
-                       synfigapp::Action::Handle       action(synfigapp::Action::create("layer_add"));
+                       synfigapp::Action::Handle       action(synfigapp::Action::create("LayerAdd"));
 
                        assert(action);
                        if(!action)
@@ -3461,8 +3538,11 @@ CanvasView::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& con
                                }
                                else
                                {
-                                       if(canvas_interface()->import(filename, App::resize_imported_images))
+                                       String errors, warnings;
+                                       if(canvas_interface()->import(filename, errors, warnings, App::resize_imported_images))
                                                success=true;
+                                       if (warnings != "")
+                                               App::dialog_warning_blocking(_("Warnings"), strprintf("%s:\n\n%s", _("Warnings"), warnings.c_str()));
                                }
 
                                continue;
@@ -3479,7 +3559,7 @@ CanvasView::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& con
 void
 CanvasView::on_keyframe_add_pressed()
 {
-       synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_add"));
+       synfigapp::Action::Handle action(synfigapp::Action::create("KeyframeAdd"));
 
        if(!action)
        {
@@ -3507,7 +3587,7 @@ CanvasView::on_keyframe_duplicate_pressed()
        }
        keyframe=row[model.keyframe];
 
-       synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_duplicate"));
+       synfigapp::Action::Handle action(synfigapp::Action::create("KeyframeDuplicate"));
 
        if(!action)
        {
@@ -3536,7 +3616,7 @@ CanvasView::on_keyframe_remove_pressed()
        }
        keyframe=row[model.keyframe];
 
-       synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_remove"));
+       synfigapp::Action::Handle action(synfigapp::Action::create("KeyframeRemove"));
 
        if(!action)
        {
@@ -3569,8 +3649,13 @@ CanvasView::image_import()
 {
        // String filename(dirname(get_canvas()->get_file_name()));
        String filename("*.*");
+       String errors, warnings;
        if(App::dialog_open_file(_("Import Image"), filename, IMAGE_DIR_PREFERENCE))
-               canvas_interface()->import(filename, App::resize_imported_images);
+       {
+               canvas_interface()->import(filename, errors, warnings, App::resize_imported_images);
+               if (warnings != "")
+                       App::dialog_warning_blocking(_("Warnings"), strprintf("%s:\n\n%s", _("Warnings"), warnings.c_str()));
+       }
 }
 
 Smach::event_result
@@ -3836,3 +3921,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();
+}