PKGBUILD fix libva/vdpau deps
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / cwindowgui.C
index 2150e061e6738a7aa7eddc2dd9fff892f08d1095..b62bd09bba03219887937855380c35394a8ed27d 100644 (file)
@@ -480,7 +480,7 @@ int CWindowGUI::keypress_event()
                break;
        case 'f':
                unlock_window();
-               if(mwindow->session->cwindow_fullscreen)
+               if( canvas->get_fullscreen() )
                        canvas->stop_fullscreen();
                else
                        canvas->start_fullscreen();
@@ -506,7 +506,7 @@ int CWindowGUI::keypress_event()
                break;
        case ESC:
                unlock_window();
-               if(mwindow->session->cwindow_fullscreen)
+               if( canvas->get_fullscreen() )
                        canvas->stop_fullscreen();
                lock_window("CWindowGUI::keypress_event 4");
                result = 1;
@@ -572,10 +572,7 @@ int CWindowGUI::keypress_event()
 
        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;
@@ -671,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("CWindowGUI::sync_parameters");
+               mwindow->gui->draw_overlays(1);
+               mwindow->gui->unlock_window();
+       }
+       lock_window("CWindowGUI::sync_parameters");
+}
 
 void CWindowGUI::drag_motion()
 {
@@ -741,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->sync_parameters(CHANGE_ALL);
+                       sync_parameters(CHANGE_ALL);
                }
        }
 
@@ -825,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)
 
+
 double CWindowEditing::get_position()
 {
        relock_cm("get_position");
@@ -836,18 +853,19 @@ double CWindowEditing::get_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_cm("set_click_to_play");
+       relock_cm("set_position");
        mwindow->edl->session->cwindow_click2play = v;
+       relock_mc("set_position");
        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))
@@ -1075,17 +1093,6 @@ void CWindowCanvas::status_event()
        gui->draw_status(1);
 }
 
-int CWindowCanvas::get_fullscreen()
-{
-       return mwindow->session->cwindow_fullscreen;
-}
-
-void CWindowCanvas::set_fullscreen(int value)
-{
-       mwindow->session->cwindow_fullscreen = value;
-}
-
-
 void CWindowCanvas::update_zoom(int x, int y, float zoom)
 {
        use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
@@ -1118,43 +1125,39 @@ float CWindowCanvas::get_zoom()
 
 void CWindowCanvas::draw_refresh(int flush)
 {
-       if(get_canvas() && !get_canvas()->get_video_on())
-       {
-
-               if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
-               {
+       if( get_canvas() && !get_canvas()->get_video_on() ) {
+               clear(0);
+               if( mwindow->uses_opengl() ) {
+                       get_canvas()->unlock_window();
+                       get_canvas()->flush();
+                       get_canvas()->sync_display();
+// this code is to idle rendering before drawing overlays on refresh frame
+// if this is not done, occationally opengl finishs late, and overwrites
+// the x11 refresh frame and the overlay is not visible.  Rarely happens.
+// bug in gl libs may segv if glfinish is called, workaround is no finish
+                       static int cin_finish = -1;
+                       if( cin_finish < 0 ) {
+                               const char *cp = getenv("CIN_FINISH");
+                               cin_finish = !cp ? 1 : atoi(cp);
+                       }
+                       if( cin_finish )
+                               mwindow->playback_3d->finish_output();
+                       get_canvas()->lock_window("CWindowCanvas::draw_refresh");
+               }
+               if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
                        float in_x1, in_y1, in_x2, in_y2;
                        float out_x1, out_y1, out_x2, out_y2;
                        get_transfers(mwindow->edl,
-                               in_x1,
-                               in_y1,
-                               in_x2,
-                               in_y2,
-                               out_x1,
-                               out_y1,
-                               out_x2,
-                               out_y2);
-
-                       if(!EQUIV(out_x1, 0) ||
-                               !EQUIV(out_y1, 0) ||
-                               !EQUIV(out_x2, get_canvas()->get_w()) ||
-                               !EQUIV(out_y2, get_canvas()->get_h()))
-                       {
-                               get_canvas()->clear_box(0,
-                                       0,
-                                       get_canvas()->get_w(),
-                                       get_canvas()->get_h());
-                       }
+                               in_x1, in_y1, in_x2, in_y2,
+                               out_x1, out_y1, out_x2, out_y2);
+
 
 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
 
 
-                       if(out_x2 > out_x1 &&
-                               out_y2 > out_y1 &&
-                               in_x2 > in_x1 &&
-                               in_y2 > in_y1)
-                       {
+                       if( out_x2 > out_x1 && out_y2 > out_y1 &&
+                           in_x2 > in_x1 && in_y2 > in_y1 ) {
 // input scaled from session to refresh frame coordinates
                                int ow = get_output_w(mwindow->edl);
                                int oh = get_output_h(mwindow->edl);
@@ -1167,29 +1170,17 @@ void CWindowCanvas::draw_refresh(int flush)
 // Can't use OpenGL here because it is called asynchronously of the
 // playback operation.
                                get_canvas()->draw_vframe(refresh_frame,
-                                               (int)out_x1,
-                                               (int)out_y1,
+                                               (int)out_x1, (int)out_y1,
                                                (int)(out_x2 - out_x1),
                                                (int)(out_y2 - out_y1),
-                                               (int)in_x1,
-                                               (int)in_y1,
+                                               (int)in_x1, (int)in_y1,
                                                (int)(in_x2 - in_x1),
                                                (int)(in_y2 - in_y1),
                                                0);
                        }
                }
-               else
-               {
-                       get_canvas()->clear_box(0,
-                               0,
-                               get_canvas()->get_w(),
-                               get_canvas()->get_h());
-               }
-
+//usleep(10000);
                draw_overlays();
-// allow last opengl write to complete before redraw
-// tried sync_display, glFlush, glxMake*Current(0..)
-usleep(20000);
                get_canvas()->flash(flush);
        }
 //printf("CWindowCanvas::draw_refresh 10\n");
@@ -2451,11 +2442,11 @@ void CWindowCanvas::draw_overlays()
        switch(mwindow->edl->session->cwindow_operation)
        {
                case CWINDOW_CAMERA:
-                       draw_bezier(1);
+                       draw_outlines(1);
                        break;
 
                case CWINDOW_PROJECTOR:
-                       draw_bezier(0);
+                       draw_outlines(0);
                        break;
 
                case CWINDOW_CROP:
@@ -2542,11 +2533,7 @@ void CWindowCanvas::create_keyframe(int do_camera)
                y_keyframe->set_value(y_value);
                z_keyframe->set_value(z_value);
 
-               mwindow->sync_parameters(CHANGE_PARAMS);
-               gui->update_tool();
-               mwindow->gui->lock_window("CWindow::camera_keyframe");
-               mwindow->gui->draw_overlays(1);
-               mwindow->gui->unlock_window();
+               gui->sync_parameters(CHANGE_PARAMS, 1, 1);
        }
 }
 
@@ -2566,11 +2553,7 @@ void CWindowCanvas::reset_keyframe(int do_camera)
                y_keyframe->set_value(0);
                z_keyframe->set_value(1);
 
-               mwindow->sync_parameters(CHANGE_PARAMS);
-               gui->update_tool();
-               mwindow->gui->lock_window("CWindow::camera_keyframe");
-               mwindow->gui->draw_overlays(1);
-               mwindow->gui->unlock_window();
+               gui->sync_parameters(CHANGE_PARAMS, 1, 1);
        }
 }
 
@@ -2874,71 +2857,58 @@ void CWindowCanvas::draw_crop()
 }
 
 
-
-
-
-
-
-
-void CWindowCanvas::draw_bezier(int do_camera)
+void CWindowCanvas::draw_outlines(int do_camera)
 {
        Track *track = gui->cwindow->calculate_affected_track();
 
        if(!track) return;
 
-       float center_x;
-       float center_y;
-       float center_z;
+       float proj_x, proj_y, proj_z;
        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);
-
-//     center_x += track->track_w / 2;
-//     center_y += track->track_h / 2;
-       center_x += mwindow->edl->session->output_w / 2;
-       center_y += mwindow->edl->session->output_h / 2;
-       float track_x1 = center_x - track->track_w / 2 * center_z;
-       float track_y1 = center_y - track->track_h / 2 * center_z;
-       float track_x2 = track_x1 + track->track_w * center_z;
-       float track_y2 = track_y1 + track->track_h * center_z;
-
-       output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
-       output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
+       track->automation->get_projector(&proj_x, &proj_y, &proj_z,
+                               position, PLAY_FORWARD);
+
+       proj_x += mwindow->edl->session->output_w/2.;
+       proj_y += mwindow->edl->session->output_h/2.;
+       float proj_x1 = proj_x - track->track_w/2. * proj_z;
+       float proj_y1 = proj_y - track->track_h/2. * proj_z;
+       float proj_x2 = proj_x + track->track_w/2. * proj_z;
+       float proj_y2 = proj_y + track->track_h/2. * proj_z;
+       float x1 = proj_x1, x2 = proj_x2;
+       float y1 = proj_y1, y2 = proj_y2;
+       output_to_canvas(mwindow->edl, 0, x1, y1);
+       output_to_canvas(mwindow->edl, 0, x2, y2);
 
 #define DRAW_PROJECTION(offset) \
-       get_canvas()->draw_rectangle((int)track_x1 + offset, \
-               (int)track_y1 + offset, \
-               (int)(track_x2 - track_x1), \
-               (int)(track_y2 - track_y1)); \
-       get_canvas()->draw_line((int)track_x1 + offset,  \
-               (int)track_y1 + offset, \
-               (int)track_x2 + offset, \
-               (int)track_y2 + offset); \
-       get_canvas()->draw_line((int)track_x2 + offset,  \
-               (int)track_y1 + offset, \
-               (int)track_x1 + offset, \
-               (int)track_y2 + offset); \
-
+       get_canvas()->draw_rectangle(x1+offset, y1+offset, (x2-x1), (y2-y1)); \
+       get_canvas()->draw_line(x1+offset, y1+offset, x2+offset, y2+offset); \
+       get_canvas()->draw_line(x2+offset, y1+offset, x1+offset, y2+offset); \
 
 // Drop shadow
        get_canvas()->set_color(BLACK);
        DRAW_PROJECTION(1);
-
-//     canvas->set_inverse();
-       if(do_camera)
-               get_canvas()->set_color(GREEN);
-       else
-               get_canvas()->set_color(RED);
-
+       get_canvas()->set_color(do_camera ? GREEN : RED);
        DRAW_PROJECTION(0);
-//     canvas->set_opaque();
 
+       if( do_camera ) {
+               float cam_x, cam_y, cam_z;
+               track->automation->get_camera(&cam_x, &cam_y, &cam_z,
+                                       position, PLAY_FORWARD);
+               cam_x += track->track_w / 2.;
+               cam_y += track->track_h / 2.;
+// follow image, not camera
+               cam_x = -cam_x;  cam_y = -cam_y;  cam_z *= proj_z;
+               float cam_x1 = cam_x * cam_z + proj_x;
+               float cam_y1 = cam_y * cam_z + proj_y;
+               float cam_x2 = (cam_x + track->track_w) * cam_z + proj_x;
+               float cam_y2 = (cam_y + track->track_h) * cam_z + proj_y;
+               output_to_canvas(mwindow->edl, 0, cam_x1, cam_y1);
+               output_to_canvas(mwindow->edl, 0, cam_x2, cam_y2);
+               get_canvas()->set_color(YELLOW);
+               get_canvas()->draw_rectangle(cam_x1, cam_y1, cam_x2-cam_x1, cam_y2-cam_y1);
+       }
 }
 
 int CWindowCanvas::test_bezier(int button_press,
@@ -2951,114 +2921,71 @@ int CWindowCanvas::test_bezier(int button_press,
 
 // Processing drag operation.
 // Create keyframe during first cursor motion.
-       if(!button_press)
-       {
+       if( !button_press ) {
 
                float cursor_x = get_cursor_x();
                float cursor_y = get_cursor_y();
                canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
 
-               if(gui->current_operation == CWINDOW_CAMERA ||
-                       gui->current_operation == CWINDOW_PROJECTOR)
-               {
-                       if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
-                       {
+               if( gui->current_operation == CWINDOW_CAMERA ||
+                   gui->current_operation == CWINDOW_PROJECTOR ) {
+                       if( !gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom ) {
                                gui->translating_zoom = 1;
                                gui->reset_affected();
                        }
-                       else
-                       if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
-                       {
+                       else if( !gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom ) {
                                gui->translating_zoom = 0;
                                gui->reset_affected();
                        }
 
 // Get target keyframe
-                       float last_center_x;
-                       float last_center_y;
-                       float last_center_z;
-                       int created;
-
-                       if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
-                       {
-                               FloatAutos *affected_x_autos;
-                               FloatAutos *affected_y_autos;
-                               FloatAutos *affected_z_autos;
+                       if( !gui->affected_x && !gui->affected_y && !gui->affected_z ) {
                                if(!gui->affected_track) return 0;
+                               FloatAutos *affected_x_autos, *affected_y_autos, *affected_z_autos;
+                               FloatAutos** autos = (FloatAutos**) gui->affected_track->automation->autos;
+                               if( mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA ) {
+                                       affected_x_autos = autos[AUTOMATION_CAMERA_X];
+                                       affected_y_autos = autos[AUTOMATION_CAMERA_Y];
+                                       affected_z_autos = autos[AUTOMATION_CAMERA_Z];
+                               }
+                               else {
+                                       affected_x_autos = autos[AUTOMATION_PROJECTOR_X];
+                                       affected_y_autos = autos[AUTOMATION_PROJECTOR_Y];
+                                       affected_z_autos = autos[AUTOMATION_PROJECTOR_Z];
+                               }
                                double position = mwindow->edl->local_session->get_selectionstart(1);
                                int64_t track_position = gui->affected_track->to_units(position, 0);
-
-                               if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
-                               {
-                                       affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
-                                       affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
-                                       affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
-                               }
-                               else
-                               {
-                                       affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
-                                       affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
-                                       affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
+                               FloatAuto *prev_x = 0, *next_x = 0;
+                               float new_x = affected_x_autos->get_value(track_position, PLAY_FORWARD, prev_x, next_x);
+                               FloatAuto *prev_y = 0, *next_y = 0;
+                               float new_y = affected_y_autos->get_value(track_position, PLAY_FORWARD, prev_y, next_y);
+                               FloatAuto *prev_z = 0, *next_z = 0;
+                               float new_z = affected_z_autos->get_value(track_position, PLAY_FORWARD, prev_z, next_z);
+                               int zooming = gui->translating_zoom, created;
+                               gui->affected_x = (FloatAuto*)gui->cwindow->calculate_affected_auto(
+                                                       affected_x_autos, !zooming, &created, 0);
+                               if( created ) {
+                                       gui->affected_x->set_value(new_x);
+                                       redraw_canvas = 1;
                                }
-
-
-                               if(gui->translating_zoom)
-                               {
-                                       FloatAuto *previous = 0;
-                                       FloatAuto *next = 0;
-                                       float new_z = affected_z_autos->get_value(
-                                               track_position,
-                                               PLAY_FORWARD,
-                                               previous,
-                                               next);
-                                       gui->affected_z =
-                                               (FloatAuto*)gui->cwindow->calculate_affected_auto(
-                                                       affected_z_autos, 1, &created, 0);
-                                       if(created) {
-                                               gui->affected_z->set_value(new_z);
-                                               redraw_canvas = 1;
-                                       }
+                               gui->affected_y = (FloatAuto*)gui->cwindow->calculate_affected_auto(
+                                                       affected_y_autos, !zooming, &created, 0);
+                               if( created ) {
+                                       gui->affected_y->set_value(new_y);
+                                       redraw_canvas = 1;
                                }
-                               else
-                               {
-                                       FloatAuto *previous = 0;
-                                       FloatAuto *next = 0;
-                                       float new_x = affected_x_autos->get_value(
-                                               track_position,
-                                               PLAY_FORWARD,
-                                               previous,
-                                               next);
-                                       previous = 0;
-                                       next = 0;
-                                       float new_y = affected_y_autos->get_value(
-                                               track_position,
-                                               PLAY_FORWARD,
-                                               previous,
-                                               next);
-                                       gui->affected_x =
-                                               (FloatAuto*)gui->cwindow->calculate_affected_auto(
-                                                       affected_x_autos, 1, &created, 0);
-                                       if(created) {
-                                               gui->affected_x->set_value(new_x);
-                                               redraw_canvas = 1;
-                                       }
-                                       gui->affected_y =
-                                               (FloatAuto*)gui->cwindow->calculate_affected_auto(
-                                                       affected_y_autos, 1, &created, 0);
-                                       if(created) {
-                                               gui->affected_y->set_value(new_y);
-                                               redraw_canvas = 1;
-                                       }
+                               gui->affected_z = (FloatAuto*)gui->cwindow->calculate_affected_auto(
+                                                       affected_z_autos, zooming, &created, 0);
+                               if( created ) {
+                                       gui->affected_z->set_value(new_z);
+                                       redraw_canvas = 1;
                                }
-
                                calculate_origin();
 
-                               if(gui->translating_zoom)
-                               {
+                               if( gui->translating_zoom ) {
                                        gui->center_z = gui->affected_z->get_value();
                                }
-                               else
-                               {
+                               else {
                                        gui->center_x = gui->affected_x->get_value();
                                        gui->center_y = gui->affected_y->get_value();
                                }
@@ -3067,40 +2994,36 @@ int CWindowCanvas::test_bezier(int button_press,
                                redraw = 1;
                        }
 
-                       if(gui->translating_zoom)
-                       {
-                               last_center_z = gui->affected_z->get_value();
+                       float x_val = gui->affected_x->get_value();
+                       float y_val = gui->affected_y->get_value();
+                       float z_val = gui->affected_z->get_value();
+
+                       if( gui->translating_zoom ) {
                                float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
                                if( z < 0 ) z = 0;
-                               if(!EQUIV(last_center_z, z))
-                               {
+                               if( !EQUIV(z_val, z) ) {
                                        rerender = 1;
                                        redraw = 1;
                                        redraw_canvas = 1;
                                }
                                gui->affected_z->set_value(z);
                        }
-                       else
-                       {
-                               last_center_x = gui->affected_x->get_value();
-                               last_center_y = gui->affected_y->get_value();
+                       else {
                                float dx = cursor_x - gui->x_origin;
                                float dy = cursor_y - gui->y_origin;
-                               if(gui->current_operation == CWINDOW_CAMERA ) {
-                                       dx = -dx;  dy = -dy;
+// follow image, not camera
+                               if( gui->current_operation == CWINDOW_CAMERA ) {
+                                       dx = -dx / z_val;  dy = -dy / z_val;
                                }
                                float x = gui->center_x + dx;
                                float y = gui->center_y + dy;
                                gui->affected_x->set_value(x);
                                gui->affected_y->set_value(y);
-                               if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
-                               {
+                               if( !EQUIV(x_val, x) || !EQUIV(y_val, y) ) {
                                        rerender = 1;
                                        redraw = 1;
                                        redraw_canvas = 1;
                                }
-                               gui->affected_x->set_value(x);
-                               gui->affected_y->set_value(y);
                        }
                }
 
@@ -3117,7 +3040,7 @@ int CWindowCanvas::test_bezier(int button_press,
 
                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);
@@ -3329,38 +3252,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;
 }
 
@@ -3426,31 +3320,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;
 }