ripple edge drag_handle tweaks, sync_parameter fix, shuttlerc, shortcuts
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / cwindowgui.C
index 610d4e7c9400d17540f7de5ba320afe85f6fad28..02ed52d32ad93ae559acb39554362dd0ce85e5d1 100644 (file)
@@ -572,10 +572,7 @@ int CWindowGUI::keypress_event()
 
        if( !result && cwindow_operation < 0 && ctrl_down() && shift_down() ) {
                switch( get_keypress() ) {
 
        if( !result && cwindow_operation < 0 && ctrl_down() && shift_down() ) {
                switch( get_keypress() ) {
-               case KEY_F1:
-               case KEY_F2:
-               case KEY_F3:
-               case KEY_F4:
+               case KEY_F1 ... KEY_F4: // mainmenu, load layout
                        resend_event(mwindow->gui);
                        result = 1;
                        break;
                        resend_event(mwindow->gui);
                        result = 1;
                        break;
@@ -609,8 +606,24 @@ int CWindowGUI::keypress_event()
                case KEY_F8:    cwindow_operation = CWINDOW_EYEDROP;    break;
                case KEY_F9:    cwindow_operation = CWINDOW_TOOL_WINDOW; break;
                case KEY_F10:   cwindow_operation = CWINDOW_TITLESAFE;  break;
                case KEY_F8:    cwindow_operation = CWINDOW_EYEDROP;    break;
                case KEY_F9:    cwindow_operation = CWINDOW_TOOL_WINDOW; break;
                case KEY_F10:   cwindow_operation = CWINDOW_TITLESAFE;  break;
-               case KEY_F11:   canvas->reset_camera();    result = 1;  break;
-               case KEY_F12:   canvas->reset_projector(); result = 1;  break;
+               }
+       }
+       if( !result && cwindow_operation < 0 && !ctrl_down() ) {
+               switch( get_keypress() ) {
+               case KEY_F11:
+                       if( !shift_down() )
+                               canvas->reset_camera();
+                       else
+                               canvas->camera_keyframe();
+                       result = 1;
+                       break;
+               case KEY_F12:
+                       if( !shift_down() )
+                               canvas->reset_projector();
+                       else
+                               canvas->projector_keyframe();
+                       result = 1;
+                       break;
                }
        }
 
                }
        }
 
@@ -655,6 +668,25 @@ void CWindowGUI::keyboard_zoomout()
 //     }
 }
 
 //     }
 }
 
+void CWindowGUI::sync_parameters(int change_type, int redraw, int overlay)
+{
+       if( redraw ) {
+               update_tool();
+               canvas->draw_refresh();
+       }
+       if( change_type < 0 && !overlay ) return;
+       unlock_window();
+       if( change_type >= 0 ) {
+               mwindow->restart_brender();
+               mwindow->sync_parameters(change_type);
+       }
+       if( overlay ) {
+               mwindow->gui->lock_window("CWindow::camera_keyframe");
+               mwindow->gui->draw_overlays(1);
+               mwindow->gui->unlock_window();
+       }
+       lock_window("CWindowGUI::sync_parameters");
+}
 
 void CWindowGUI::drag_motion()
 {
 
 void CWindowGUI::drag_motion()
 {
@@ -725,7 +757,7 @@ int CWindowGUI::drag_stop()
                        mwindow->gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
                        mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
                        mwindow->gui->unlock_window();
                        mwindow->gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
                        mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
                        mwindow->gui->unlock_window();
-                       mwindow->sync_parameters(CHANGE_ALL);
+                       sync_parameters(CHANGE_ALL);
                }
        }
 
                }
        }
 
@@ -809,6 +841,7 @@ CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
 #define panel_btn(fn, args, s) \
  panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
 
 #define panel_btn(fn, args, s) \
  panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
 
+
 double CWindowEditing::get_position()
 {
        relock_cm("get_position");
 double CWindowEditing::get_position()
 {
        relock_cm("get_position");
@@ -820,18 +853,19 @@ double CWindowEditing::get_position()
 void CWindowEditing::set_position(double position)
 {
        relock_cm("set_position");
 void CWindowEditing::set_position(double position)
 {
        relock_cm("set_position");
-       set_position(position);
+       mwindow->gui->mbuttons->edit_panel->set_position(position);
        relock_mc("set_position");
 }
 
 void CWindowEditing::set_click_to_play(int v)
 {
        relock_mc("set_position");
 }
 
 void CWindowEditing::set_click_to_play(int v)
 {
-       relock_cm("set_click_to_play");
+       relock_cm("set_position");
        mwindow->edl->session->cwindow_click2play = v;
        mwindow->edl->session->cwindow_click2play = v;
+       relock_mc("set_position");
        click2play->update(v);
        click2play->update(v);
-       relock_mc("set_click_to_play");
 }
 
 }
 
+
 void panel_btn(stop_transport,(), stop_transport())
 void panel_btn(toggle_label,(), toggle_label())
 void panel_btn(next_label,(int cut), next_label(cut))
 void panel_btn(stop_transport,(), stop_transport())
 void panel_btn(toggle_label,(), toggle_label())
 void panel_btn(next_label,(int cut), next_label(cut))
@@ -2499,44 +2533,60 @@ void CWindowCanvas::draw_safe_regions()
        get_canvas()->set_opaque();
 }
 
        get_canvas()->set_opaque();
 }
 
-void CWindowCanvas::reset_keyframe(int do_camera)
+
+void CWindowCanvas::create_keyframe(int do_camera)
 {
 {
-       FloatAuto *x_keyframe = 0;
-       FloatAuto *y_keyframe = 0;
-       FloatAuto *z_keyframe = 0;
-       Track *affected_track = 0;
+       Track *affected_track = gui->cwindow->calculate_affected_track();
+       if( affected_track ) {
+               double pos = mwindow->edl->local_session->get_selectionstart(1);
+               int64_t position = affected_track->to_units(pos, 0);
+               int ix = do_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X;
+               int iy = do_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y;
+               int iz = do_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z;
+               FloatAuto *prev, *next;
+               FloatAutos **autos = (FloatAutos**)affected_track->automation->autos;
+               FloatAutos *x_autos = autos[ix];  prev = 0;  next = 0;
+               float x_value = x_autos->get_value(position, PLAY_FORWARD, prev, next);
+               FloatAutos *y_autos = autos[iy];  prev = 0;  next = 0;
+               float y_value = y_autos->get_value(position, PLAY_FORWARD, prev, next);
+               FloatAutos *z_autos = autos[iz];  prev = 0;  next = 0;
+               float z_value = z_autos->get_value(position, PLAY_FORWARD, prev, next);
+               FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
 
 
-       affected_track = gui->cwindow->calculate_affected_track();
+               gui->cwindow->calculate_affected_autos(affected_track,
+                       &x_keyframe, &y_keyframe, &z_keyframe,
+                       do_camera, -1, -1, -1, 0);
+               x_keyframe->set_value(x_value);
+               y_keyframe->set_value(y_value);
+               z_keyframe->set_value(z_value);
 
 
-       if(affected_track)
-       {
-               gui->cwindow->calculate_affected_autos(&x_keyframe,
-                       &y_keyframe,
-                       &z_keyframe,
-                       affected_track,
-                       do_camera,
-                       1,
-                       1,
-                       1);
+               gui->sync_parameters(CHANGE_PARAMS, 1, 1);
+       }
+}
+
+void CWindowCanvas::camera_keyframe() { create_keyframe(1); }
+void CWindowCanvas::projector_keyframe() { create_keyframe(0); }
+
+void CWindowCanvas::reset_keyframe(int do_camera)
+{
+       Track *affected_track = gui->cwindow->calculate_affected_track();
+       if( affected_track ) {
+               FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
+               gui->cwindow->calculate_affected_autos(affected_track,
+                       &x_keyframe, &y_keyframe, &z_keyframe,
+                       do_camera, 1, 1, 1);
 
                x_keyframe->set_value(0);
                y_keyframe->set_value(0);
                z_keyframe->set_value(1);
 
 
                x_keyframe->set_value(0);
                y_keyframe->set_value(0);
                z_keyframe->set_value(1);
 
-               mwindow->sync_parameters(CHANGE_PARAMS);
-               gui->update_tool();
+               gui->sync_parameters(CHANGE_PARAMS, 1, 1);
        }
 }
 
        }
 }
 
-void CWindowCanvas::reset_camera()
-{
-       reset_keyframe(1);
-}
+void CWindowCanvas::reset_camera() { reset_keyframe(1); }
+void CWindowCanvas::reset_projector() { reset_keyframe(0); }
 
 
-void CWindowCanvas::reset_projector()
-{
-       reset_keyframe(0);
-}
 
 int CWindowCanvas::test_crop(int button_press, int &redraw)
 {
 
 int CWindowCanvas::test_crop(int button_press, int &redraw)
 {
@@ -2852,12 +2902,15 @@ void CWindowCanvas::draw_bezier(int do_camera)
        int64_t position = track->to_units(
                mwindow->edl->local_session->get_selectionstart(1),
                0);
        int64_t position = track->to_units(
                mwindow->edl->local_session->get_selectionstart(1),
                0);
-
-       track->automation->get_projector(&center_x,
-               &center_y,
-               &center_z,
-               position,
-               PLAY_FORWARD);
+       if( do_camera ) {
+               track->automation->get_camera(&center_x,
+                       &center_y, &center_z, position, PLAY_FORWARD);
+// follow image, not camera
+               center_x = -center_x;  center_y = -center_y;
+       }
+       else
+               track->automation->get_projector(&center_x,
+                       &center_y, &center_z, position, PLAY_FORWARD);
 
 //     center_x += track->track_w / 2;
 //     center_y += track->track_h / 2;
 
 //     center_x += track->track_w / 2;
 //     center_y += track->track_h / 2;
@@ -3046,6 +3099,7 @@ int CWindowCanvas::test_bezier(int button_press,
                                last_center_y = gui->affected_y->get_value();
                                float dx = cursor_x - gui->x_origin;
                                float dy = cursor_y - gui->y_origin;
                                last_center_y = gui->affected_y->get_value();
                                float dx = cursor_x - gui->x_origin;
                                float dy = cursor_y - gui->y_origin;
+// follow image, not camera
                                if(gui->current_operation == CWINDOW_CAMERA ) {
                                        dx = -dx;  dy = -dy;
                                }
                                if(gui->current_operation == CWINDOW_CAMERA ) {
                                        dx = -dx;  dy = -dy;
                                }
@@ -3077,7 +3131,7 @@ int CWindowCanvas::test_bezier(int button_press,
 
                if(gui->affected_track)
                {
 
                if(gui->affected_track)
                {
-                       if(gui->current_operation == CWINDOW_CAMERA)
+                       if( do_camera )
                                mwindow->undo->update_undo_before(_("camera"), this);
                        else
                                mwindow->undo->update_undo_before(_("projector"), this);
                                mwindow->undo->update_undo_before(_("camera"), this);
                        else
                                mwindow->undo->update_undo_before(_("projector"), this);
@@ -3289,38 +3343,9 @@ int CWindowCanvas::cursor_motion_event()
                }
        }
 
                }
        }
 
+       int change_type = rerender ? CHANGE_PARAMS : -1;
+       gui->sync_parameters(change_type, redraw, redraw_canvas);
 
 
-// If the window is never unlocked before calling send_command the
-// display shouldn't get stuck on the old video frame although it will
-// flicker between the old video frame and the new video frame.
-
-       if(redraw)
-       {
-               draw_refresh();
-               gui->update_tool();
-       }
-
-       if(redraw_canvas)
-       {
-               gui->unlock_window();
-
-
-               mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
-               mwindow->gui->draw_overlays(1);
-               mwindow->gui->unlock_window();
-
-               gui->lock_window("CWindowCanvas::cursor_motion_event 1");
-       }
-
-       if(rerender)
-       {
-               gui->unlock_window();
-               mwindow->restart_brender();
-               mwindow->sync_parameters(CHANGE_PARAMS);
-               mwindow->cwindow->refresh_frame(CHANGE_NONE);
-               if(!redraw) gui->update_tool();
-               gui->lock_window("CWindowCanvas::cursor_motion_event 2");
-       }
        return result;
 }
 
        return result;
 }
 
@@ -3386,31 +3411,9 @@ int CWindowCanvas::button_press_event()
                }
        }
 
                }
        }
 
-       if(redraw)
-       {
-               draw_refresh();
-               gui->unlock_window();
-
-
-               mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
-               mwindow->gui->draw_overlays(1);
-               mwindow->gui->unlock_window();
-               gui->update_tool();
-
-               gui->lock_window("CWindowCanvas::button_press_event 1");
-       }
-
-// rerendering can also be caused by press event
-       if(rerender)
-       {
-               gui->unlock_window();
+       int change_type = rerender ? CHANGE_PARAMS : -1;
+       gui->sync_parameters(change_type, redraw, redraw_canvas);
 
 
-               mwindow->restart_brender();
-               mwindow->sync_parameters(CHANGE_PARAMS);
-               mwindow->cwindow->refresh_frame(CHANGE_NONE);
-               if(!redraw) gui->update_tool();
-               gui->lock_window("CWindowCanvas::button_press_event 2");
-       }
        return result;
 }
 
        return result;
 }