mixer
[goodguy/history.git] / cinelerra-5.1 / cinelerra / cwindowgui.C
index d4e62eed5ea5e6b80b51768b305211ec36a54cc2..95bae3979ce8071ca20358da276f75e33ea4b67c 100644 (file)
@@ -92,23 +92,29 @@ CWindowGUI::CWindowGUI(MWindow *mwindow, CWindow *cwindow)
        this->mwindow = mwindow;
        this->cwindow = cwindow;
        affected_track = 0;
-       affected_x = 0;
-       affected_y = 0;
-       affected_z = 0;
+       affected_x = affected_y = affected_z = 0;
        mask_keyframe = 0;
        orig_mask_keyframe = new MaskAuto(0, 0);
        affected_point = 0;
-       x_offset = 0;
-       y_offset = 0;
-       x_origin = 0;
-       y_origin = 0;
+       x_offset = y_offset = 0;
+       x_origin = y_origin = 0;
        current_operation = CWINDOW_NONE;
        tool_panel = 0;
-       translating_zoom = 0;
        active = 0;
        inactive = 0;
-       crop_translate = 0;
+       crop_handle = -1; crop_translate = 0;
+       crop_origin_x = crop_origin_y = 0;
+       crop_origin_x1 = crop_origin_y1 = 0;
+       crop_origin_x2 = crop_origin_y2 = 0;
        eyedrop_visible = 0;
+       eyedrop_x = eyedrop_y = 0;
+       ruler_origin_x = ruler_origin_y = 0;
+       ruler_handle = -1; ruler_translate = 0;
+       center_x = center_y = center_z = 0;
+       control_in_x = control_in_y = 0;
+       control_out_x = control_out_y = 0;
+       translating_zoom = 0;
+       highlighted = 0;
 }
 
 CWindowGUI::~CWindowGUI()
@@ -199,9 +205,9 @@ void CWindowGUI::create_objects()
                mwindow->theme->czoom_y,
                mwindow->theme->czoom_w);
        zoom_panel->create_objects();
-       auto_zoom = _(AUTO_ZOOM);
-       zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom));
-       if(!mwindow->edl->session->cwindow_scrollbars) zoom_panel->set_text(auto_zoom);
+       zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
+       if( !mwindow->edl->session->cwindow_scrollbars )
+               zoom_panel->set_text(auto_zoom);
 
 //     destination = new CWindowDestination(mwindow,
 //             this,
@@ -244,7 +250,7 @@ int CWindowGUI::resize_event(int w, int h)
        flash(0);
 
        composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
-               mwindow->theme->ccomposite_y);
+               mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
 
        canvas->reposition_window(mwindow->edl,
                mwindow->theme->ccanvas_x,
@@ -358,44 +364,38 @@ void CWindowGUI::draw_status(int flush)
                flush);
 }
 
-
-void CWindowGUI::zoom_canvas(int do_auto, double value, int update_menu)
+float CWindowGUI::get_auto_zoom()
 {
-       if(do_auto)
-               mwindow->edl->session->cwindow_scrollbars = 0;
-       else
-               mwindow->edl->session->cwindow_scrollbars = 1;
+       float conformed_w, conformed_h;
+       mwindow->edl->calculate_conformed_dimensions(0, conformed_w, conformed_h);
+       float zoom_x = canvas->w / conformed_w;
+       float zoom_y = canvas->h / conformed_h;
+       return zoom_x < zoom_y ? zoom_x : zoom_y;
+}
 
-       float old_zoom = mwindow->edl->session->cwindow_zoom;
-       float new_zoom = value;
-       float x = canvas->w / 2.0;
-       float y = canvas->h / 2.0;
-       canvas->canvas_to_output(mwindow->edl,
-                               0,
-                               x,
-                               y);
-       x -= canvas->w_visible / 2 * old_zoom / new_zoom;
-       y -= canvas->h_visible / 2 * old_zoom / new_zoom;
-       if(update_menu)
-       {
-               if(do_auto)
-               {
-                       zoom_panel->update(auto_zoom);
-               }
-               else
-               {
-                       zoom_panel->update(value);
-               }
+void CWindowGUI::zoom_canvas(double value, int update_menu)
+{
+       float x = 0, y = 0;
+       float zoom = !value ? get_auto_zoom() : value;
+       mwindow->edl->session->cwindow_scrollbars = !value ? 0 : 1;
+       if( value ) {
+               float cx = canvas->get_xscroll() + 0.5f*canvas->w_visible;
+               float cy = canvas->get_yscroll() + 0.5f*canvas->h_visible;
+               float output_x = cx, output_y = cy;
+               canvas->output_to_canvas(mwindow->edl, 0, cx, cy);
+               x = output_x - cx / zoom;
+               y = output_y - cy / zoom;
        }
+       canvas->update_zoom((int)(x+0.5), (int)(y+0.5), zoom);
+
+       if( update_menu )
+               zoom_panel->update(value);
+       if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM )
+               composite_panel->cpanel_zoom->update(zoom);
 
-       canvas->update_zoom((int)x,
-               (int)y,
-               new_zoom);
        canvas->reposition_window(mwindow->edl,
-               mwindow->theme->ccanvas_x,
-               mwindow->theme->ccanvas_y,
-               mwindow->theme->ccanvas_w,
-               mwindow->theme->ccanvas_h);
+               mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
+               mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
        canvas->draw_refresh();
 }
 
@@ -570,43 +570,26 @@ void CWindowGUI::drag_motion()
 {
        if(get_hidden()) return;
 
-       if(mwindow->session->current_operation == DRAG_ASSET ||
-               mwindow->session->current_operation == DRAG_VTRANSITION ||
-               mwindow->session->current_operation == DRAG_VEFFECT)
-       {
-               int old_status = mwindow->session->ccanvas_highlighted;
-               int cursor_x = get_relative_cursor_x();
-               int cursor_y = get_relative_cursor_y();
-
-               mwindow->session->ccanvas_highlighted = get_cursor_over_window() &&
-                       cursor_x >= canvas->x &&
-                       cursor_x < canvas->x + canvas->w &&
-                       cursor_y >= canvas->y &&
-                       cursor_y < canvas->y + canvas->h;
-
-
-               if(old_status != mwindow->session->ccanvas_highlighted)
-                       canvas->draw_refresh();
-       }
+       if(mwindow->session->current_operation != DRAG_ASSET &&
+               mwindow->session->current_operation != DRAG_VTRANSITION &&
+               mwindow->session->current_operation != DRAG_VEFFECT) return;
+       int need_highlight = cursor_above() && get_cursor_over_window();
+       if( highlighted == need_highlight ) return;
+       highlighted = need_highlight;
+       canvas->draw_refresh();
 }
 
 int CWindowGUI::drag_stop()
 {
        int result = 0;
        if(get_hidden()) return 0;
-
-       if((mwindow->session->current_operation == DRAG_ASSET ||
-               mwindow->session->current_operation == DRAG_VTRANSITION ||
-               mwindow->session->current_operation == DRAG_VEFFECT) &&
-               mwindow->session->ccanvas_highlighted)
-       {
-// Hide highlighting
-               mwindow->session->ccanvas_highlighted = 0;
-               canvas->draw_refresh();
-               result = 1;
-       }
-       else
-               return 0;
+       if( !highlighted ) return 0;
+       if( mwindow->session->current_operation != DRAG_ASSET &&
+           mwindow->session->current_operation != DRAG_VTRANSITION &&
+           mwindow->session->current_operation != DRAG_VEFFECT) return 0;
+       highlighted = 0;
+       canvas->draw_refresh();
+       result = 1;
 
        if(mwindow->session->current_operation == DRAG_ASSET)
        {
@@ -621,7 +604,7 @@ int CWindowGUI::drag_stop()
                if(mwindow->session->drag_assets->total)
                {
                        mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
-                       mwindow->clear(0);
+                       mwindow->clear(0, 1);
                        mwindow->load_assets(mwindow->session->drag_assets,
                                mwindow->edl->local_session->get_selectionstart(),
                                LOADMODE_PASTE,
@@ -636,7 +619,7 @@ int CWindowGUI::drag_stop()
                if(mwindow->session->drag_clips->total)
                {
                        mwindow->gui->lock_window("CWindowGUI::drag_stop 2");
-                       mwindow->clear(0);
+                       mwindow->clear(0, 1);
                        mwindow->paste_edls(mwindow->session->drag_clips,
                                LOADMODE_PASTE,
                                mwindow->session->track_highlighted,
@@ -735,13 +718,16 @@ CWrapper(set_inpoint)
 CWrapper(set_outpoint)
 CWrapper(clear_inpoint)
 CWrapper(clear_outpoint)
-CWrapper(to_clip)
 CWrapper(toggle_label)
 CWrapper(prev_label)
 CWrapper(next_label)
 CWrapper(prev_edit)
 CWrapper(next_edit)
 
+void CWindowEditing::to_clip()
+{
+        mwindow->to_clip(mwindow->edl, _("composer window: "));
+}
 
 
 CWindowMeters::CWindowMeters(MWindow *mwindow,
@@ -779,15 +765,8 @@ int CWindowMeters::change_status_event(int new_status)
 
 
 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
- : ZoomPanel(mwindow,
-       gui,
-       (double)mwindow->edl->session->cwindow_zoom,
-       x,
-       y,
-       w,
-       my_zoom_table,
-       total_zooms,
-       ZOOM_PERCENTAGE)
+ : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
+       x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
 {
        this->mwindow = mwindow;
        this->gui = gui;
@@ -797,17 +776,26 @@ CWindowZoom::~CWindowZoom()
 {
 }
 
-int CWindowZoom::handle_event()
+void CWindowZoom::update(double value)
 {
-       if(!strcasecmp(gui->auto_zoom, get_text()))
-       {
-               gui->zoom_canvas(1, get_value(), 0);
+       char string[BCSTRLEN];
+       const char *cp = string;
+       if( value ) {
+               this->value = value;
+               int frac = value >= 1.0f ? 1 :
+                          value >= 0.1f ? 2 :
+                          value >= .01f ? 3 : 4;
+               sprintf(string, "x %.*f", frac, value);
        }
        else
-       {
-               gui->zoom_canvas(0, get_value(), 0);
-       }
+               cp = gui->auto_zoom;
+       ZoomPanel::update(cp);
+}
 
+int CWindowZoom::handle_event()
+{
+       double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
+       gui->zoom_canvas(value, 0);
        return 1;
 }
 
@@ -841,7 +829,7 @@ int CWindowSlider::handle_event()
 
 void CWindowSlider::set_position()
 {
-       double new_length = mwindow->edl->tracks->total_playable_length();
+       double new_length = mwindow->edl->tracks->total_length();
 //     if(mwindow->edl->local_session->preview_end <= 0 ||
 //             mwindow->edl->local_session->preview_end > new_length)
 //             mwindow->edl->local_session->preview_end = new_length;
@@ -989,7 +977,7 @@ void CWindowCanvas::update_zoom(int x, int y, float zoom)
 
 void CWindowCanvas::zoom_auto()
 {
-       gui->zoom_canvas(1, 1.0, 1);
+       gui->zoom_canvas(0, 1);
 }
 
 int CWindowCanvas::get_xscroll()
@@ -2179,15 +2167,24 @@ int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
        float blue = (float)*row++ / max; \
        if(do_yuv) \
        { \
-               mwindow->edl->local_session->red += red + V_TO_R * (blue - 0.5); \
-               mwindow->edl->local_session->green += red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
-               mwindow->edl->local_session->blue += red + U_TO_B * (green - 0.5); \
+               float r = red + V_TO_R * (blue - 0.5); \
+               float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
+               float b = red + U_TO_B * (green - 0.5); \
+               mwindow->edl->local_session->red += r; \
+               mwindow->edl->local_session->green += g; \
+               mwindow->edl->local_session->blue += b; \
+               if(r > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = r; \
+               if(g > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = g; \
+               if(b > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = b; \
        } \
        else \
        { \
                mwindow->edl->local_session->red += red; \
                mwindow->edl->local_session->green += green; \
                mwindow->edl->local_session->blue += blue; \
+               if(red > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = red; \
+               if(green > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = green; \
+               if(blue > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = blue; \
        } \
 }
 
@@ -2196,6 +2193,9 @@ int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
                        mwindow->edl->local_session->red = 0;
                        mwindow->edl->local_session->green = 0;
                        mwindow->edl->local_session->blue = 0;
+                       mwindow->edl->local_session->red_max = 0;
+                       mwindow->edl->local_session->green_max = 0;
+                       mwindow->edl->local_session->blue_max = 0;
                        for(int i = row1; i < row2; i++)
                        {
                                for(int j = column1; j < column2; j++)
@@ -2287,7 +2287,7 @@ void CWindowCanvas::draw_overlays()
                get_canvas()->set_opaque();
        }
 
-       if(mwindow->session->ccanvas_highlighted)
+       if(gui->highlighted)
        {
                get_canvas()->set_color(WHITE);
                get_canvas()->set_inverse();
@@ -2957,83 +2957,49 @@ int CWindowCanvas::test_bezier(int button_press,
 int CWindowCanvas::test_zoom(int &redraw)
 {
        int result = 0;
-       float zoom = get_zoom();
-       float x;
-       float y;
-
-       if(!mwindow->edl->session->cwindow_scrollbars)
-       {
-               mwindow->edl->session->cwindow_scrollbars = 1;
-               zoom = 1.0;
-               x = mwindow->edl->session->output_w / 2;
-               y = mwindow->edl->session->output_h / 2;
-               x = x - w / zoom / 2;
-               y = y - h / zoom / 2;
-       }
-       else
-       {
-// Cursor position relative to canvas
-               x = get_cursor_x();
-               y = get_cursor_y();
-// cursor position relative to output
-               float output_x = x;
-               float output_y = y;
-               canvas_to_output(mwindow->edl,
-                               0,
-                               output_x,
-                               output_y);
-
-//printf("CWindowCanvas::test_zoom 1 %f %f\n", x, y);
+       float x, y;
+       float zoom = 0;
 
+       if( mwindow->edl->session->cwindow_scrollbars ) {
+               if( *gui->zoom_panel->get_text() != 'x' ) {
 // Find current zoom in table
-               int current_index = 0;
-               for(current_index = 0 ; current_index < total_zooms; current_index++)
-                       if(EQUIV(my_zoom_table[current_index], zoom)) break;
-
-
-// Zoom out
-               if(get_buttonpress() == 5 ||
-                       gui->ctrl_down() ||
-                       gui->shift_down())
-               {
-                       current_index--;
+                       int idx = total_zooms;  float old_zoom = get_zoom();
+                       while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
+                       if( idx >= 0 ) {
+                               idx += get_buttonpress() == 5 ||
+                                        gui->ctrl_down() || gui->shift_down() ?  -1 : +1 ;
+                               CLAMP(idx, 0, total_zooms-1);
+                               zoom = my_zoom_table[idx];
+                       }
                }
-               else
-// Zoom in
-               {
-                       current_index++;
+               x = get_cursor_x();  y = get_cursor_y();
+               if( !zoom ) {
+                       mwindow->edl->session->cwindow_scrollbars = 0;
+                       gui->zoom_panel->update(0);
+                       zoom = gui->get_auto_zoom();
+               }
+               else {
+                       gui->zoom_panel->ZoomPanel::update(zoom);
+                       float output_x = x, output_y = y;
+                       canvas_to_output(mwindow->edl, 0, output_x, output_y);
+                       x = output_x - x / zoom;
+                       y = output_y - y / zoom;
                }
-
-               CLAMP(current_index, 0, total_zooms - 1);
-               zoom = my_zoom_table[current_index];
-
-               x = output_x - x / zoom;
-               y = output_y - y / zoom;
-
-
        }
+       else {
+               mwindow->edl->session->cwindow_scrollbars = 1;
+               x = (mwindow->edl->session->output_w - w) / 2;
+               y = (mwindow->edl->session->output_h - h) / 2;
+               zoom = 1;
+       }
+       update_zoom((int)x, (int)y, zoom);
 
+       gui->composite_panel->cpanel_zoom->update(zoom);
 
-
-       int x_i = (int)x;
-       int y_i = (int)y;
-//     check_boundaries(mwindow->edl, x_i, y_i, zoom);
-
-//printf("CWindowCanvas::test_zoom 2 %d %d\n", x_i, y_i);
-
-       update_zoom(x_i,
-                       y_i,
-                       zoom);
        reposition_window(mwindow->edl,
-                       mwindow->theme->ccanvas_x,
-                       mwindow->theme->ccanvas_y,
-                       mwindow->theme->ccanvas_w,
-                       mwindow->theme->ccanvas_h);
-       redraw = 1;
-       result = 1;
-
-
-       gui->zoom_panel->update(zoom);
+                       mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
+                       mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
+       redraw = 1;  result = 1;
 
        return result;
 }