add binfolder path relative filters, fix gbrp color model, vwdw timebar tweaks, title...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / awindowgui.C
index 9be5b66ba743405552d4b4a4a384de0508395173..1ab6ea1affe3b65c6a63ad6a95a9ba8592a0cdd3 100644 (file)
@@ -153,6 +153,10 @@ VFrame *AssetVIcon::frame()
                if( !temp )
                        temp = new VFrame(0, -1, asset->width, asset->height, BC_RGB888, -1);
                while( seq_no >= images.size() ) {
+                       mwindow->video_cache->check_in(asset);
+                       Thread::yield();
+                       file = mwindow->video_cache->check_out(asset, mwindow->edl, 0);
+                       if( !file ) { usleep(1000);  continue; }
                        file->set_layer(0);
                        int64_t pos = images.size() / picon->gui->vicon_thread->refresh_rate * frame_rate;
                        file->set_video_position(pos,0);
@@ -173,12 +177,12 @@ int64_t AssetVIcon::set_seq_no(int64_t no)
 int AssetVIcon::get_vx()
 {
        BC_ListBox *lbox = picon->gui->asset_list;
-       return lbox->get_item_x(picon);
+       return lbox->get_icon_x(picon);
 }
 int AssetVIcon::get_vy()
 {
        BC_ListBox *lbox = picon->gui->asset_list;
-       return lbox->get_item_y(picon);
+       return lbox->get_icon_y(picon);
 }
 
 void AssetVIcon::load_audio()
@@ -371,6 +375,7 @@ AssetPicon::~AssetPicon()
 {
        if( vicon )
                gui->vicon_thread->del_vicon(vicon);
+       delete vicon_frame;
        if( indexable ) indexable->remove_user();
        if( edl ) edl->remove_user();
        if( icon && !gui->protected_pixmap(icon) ) {
@@ -436,6 +441,7 @@ void AssetPicon::reset()
        icon = 0;
        icon_vframe = 0;
        vicon = 0;
+       vicon_frame = 0;
        in_use = 1;
        comments_time = 0;
        id = 0;
@@ -1049,8 +1055,7 @@ void AWindowGUI::create_objects()
        add_subwindow(asset_list = new AWindowAssets(mwindow, this, x1, y1, w1, h1));
 
        vicon_thread = new VIconThread(asset_list);
-       int x0 = 0, y0 = asset_list->get_title_h();
-       vicon_thread->set_drawing_area(x0,y0, get_w(),get_h());
+       asset_list->update_vicon_area();
        vicon_thread->start();
        vicon_audio = new AssetVIconAudio(this);
 
@@ -1136,6 +1141,7 @@ int AWindowGUI::resize_event(int w, int h)
 //     view->reposition_window(x, y);
 
        BC_WindowBase::resize_event(w, h);
+       asset_list->update_vicon_area();
        return 1;
 }
 
@@ -1197,13 +1203,14 @@ int AWindowGUI::close_event()
 
 void AWindowGUI::start_vicon_drawing()
 {
-       if( !vicon_drawing ) return;
+       if( !vicon_drawing || !vicon_thread->interrupted ) return;
        if( mwindow->edl->session->awindow_folder == AW_MEDIA_FOLDER ||
            mwindow->edl->session->awindow_folder >= AWINDOW_USER_FOLDERS ) {
                switch( mwindow->edl->session->assetlist_format ) {
                case ASSETS_ICONS:
                case ASSETS_ICONS_PACKED:
                case ASSETS_ICON_LIST:
+                       asset_list->update_vicon_area();
                        vicon_thread->start_drawing();
                        break;
                default:
@@ -1214,9 +1221,22 @@ void AWindowGUI::start_vicon_drawing()
 
 void AWindowGUI::stop_vicon_drawing()
 {
+       if( vicon_thread->interrupted ) return;
        vicon_thread->stop_drawing();
 }
 
+VFrame *AssetPicon::get_vicon_frame()
+{
+       if( !vicon ) return 0;
+       if( gui->vicon_thread->interrupted ) return 0;
+       VFrame *frame = vicon->frame();
+       if( !frame ) return 0;
+       if( !vicon_frame )
+               vicon_frame = new VFrame(vicon->vw, vicon->vh, frame->get_color_model());
+       vicon_frame->transfer_from(frame);
+       return vicon_frame;
+}
+
 int AWindowGUI::cycle_assetlist_format()
 {
        EDLSession *session = mwindow->edl->session;
@@ -1240,11 +1260,6 @@ int AWindowGUI::cycle_assetlist_format()
        stop_vicon_drawing();
        session->assetlist_format = format;
        asset_list->update_format(session->assetlist_format, 0);
-       int x0 = 0;
-       int x1 = asset_list->get_w();
-       int y0 = asset_list->get_title_h();
-       int y1 = asset_list->get_h();
-       vicon_thread->set_drawing_area(x0,y0, x1,y1);
        async_update_assets();
        start_vicon_drawing();
        return 1;
@@ -1672,12 +1687,12 @@ EDL *AWindowGUI::collect_proxy(Indexable *indexable)
        int proxy_scale = mwindow->edl->session->proxy_scale;
        ProxyRender::from_proxy_path(path, proxy_asset, proxy_scale);
        Asset *unproxy_asset = mwindow->edl->assets->get_asset(path);
-       if( !unproxy_asset || !unproxy_asset->channels ) return 0;
+       if( !unproxy_asset || !unproxy_asset->layers ) return 0;
 // make a clip from proxy video tracks and unproxy audio tracks
        EDL *proxy_edl = new EDL(mwindow->edl);
        proxy_edl->create_objects();
+       proxy_edl->set_path(proxy_asset->path);
        FileSystem fs;  fs.extract_name(path, proxy_asset->path);
-       proxy_edl->set_path(path);
        strcpy(proxy_edl->local_session->clip_title, path);
        strcpy(proxy_edl->local_session->clip_notes, _("Proxy clip"));
        proxy_edl->session->video_tracks = proxy_asset->layers;
@@ -1706,13 +1721,13 @@ void AWindowGUI::collect_assets(int proxy)
 {
        mwindow->session->drag_assets->remove_all();
        mwindow->session->drag_clips->remove_all();
-       mwindow->session->clear_drag_proxy();
        int i = 0;  AssetPicon *result;
        while( (result = (AssetPicon*)asset_list->get_selection(0, i++)) != 0 ) {
-               Indexable *indexable = result->indexable;  EDL *drag_edl;
-               if( proxy && (drag_edl=collect_proxy(indexable)) ) {
-                       mwindow->session->drag_clips->append(drag_edl);
-                       mwindow->session->drag_proxy->append(drag_edl);
+               Indexable *indexable = result->indexable;
+               if( proxy && indexable && indexable->is_asset &&
+                   indexable->awindow_folder == AW_PROXY_FOLDER ) {
+                       EDL *drag_edl = collect_proxy(indexable);
+                       if( drag_edl ) mwindow->session->drag_clips->append(drag_edl);
                        continue;
                }
                if( indexable ) {
@@ -1732,19 +1747,27 @@ void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst,
 // Remove current pointers
        dst[0].remove_all();
        dst[1].remove_all_objects();
+       BinFolder *bin_folder = folder < AWINDOW_USER_FOLDERS ? 0 :
+               mwindow->edl->get_folder(folder);
 
 // Create new pointers
        for( int i = 0; i < src->total; i++ ) {
                int visible = folder < 0 ? 1 : 0;
                AssetPicon *picon = (AssetPicon*)src->values[i];
                picon->sort_key = -1;
-               if( !visible && folder >= AWINDOW_USER_FOLDERS && picon->indexable ) {
-                       picon->sort_key = mwindow->edl->folders.matches_indexable(folder, picon->indexable);
-                       if( picon->sort_key >= 0 ) visible = 1;
+               if( !visible && bin_folder ) {
+                       Indexable *idxbl = bin_folder->is_clips ? (Indexable *)picon->edl :
+                           picon->indexable ? picon->indexable :
+                           picon->edl ? picon->edl->get_proxy_asset() : 0;
+                       if( idxbl ) {
+                               picon->sort_key = mwindow->edl->folders.matches_indexable(folder, idxbl);
+                               if( picon->sort_key < 0 ) continue;
+                               visible = 1;
+                       }
                }
                if( !visible && picon->indexable && picon->indexable->awindow_folder == folder )
                        visible = 1;
-               if( !visible && picon->edl && picon->edl->awindow_folder == folder )
+               if( !visible && picon->edl && picon->edl->local_session->folder == folder )
                        visible = 1;
                if( visible ) {
                        const char *text = search_text->get_text();
@@ -1874,11 +1897,6 @@ void AWindowGUI::update_assets()
 
        if( mwindow->edl->session->assetlist_format != asset_list->get_format() ) {
                asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
-               int x0 = 0;
-               int x1 = asset_list->get_w();
-               int y0 = asset_list->get_title_h();
-               int y1 = asset_list->get_h();
-               vicon_thread->set_drawing_area(x0,y0, x1,y1);
        }
        int asset_xposition = asset_list->get_xposition();
        int asset_yposition = asset_list->get_yposition();
@@ -2067,10 +2085,12 @@ int AWindowFolders::drag_stop()
                AssetPicon *picon = (AssetPicon *)(item_no < 0 ? 0 : gui->folders[item_no]);
                if( picon && picon->foldernum >= AWINDOW_USER_FOLDERS ) {
                        BinFolder *folder = mwindow->edl->get_folder(picon->foldernum);
-                       ArrayList<Indexable *> *drags = mwindow->session->drag_assets;
-                       if( folder && drags ) folder->add_patterns(drags);
+                       ArrayList<Indexable *> *drags = folder->is_clips ?
+                               ((ArrayList<Indexable *> *)mwindow->session->drag_clips) :
+                               ((ArrayList<Indexable *> *)mwindow->session->drag_assets);
+                       if( folder && drags && !folder->add_patterns(drags, shift_down()) )
+                               flicker(1,30);
                        mwindow->session->current_operation = ::NO_OPERATION;
-                       flicker(1,30);
                        result = 1;
                }
        }
@@ -2214,20 +2234,19 @@ int AWindowAssets::selection_changed()
                        break;
                }
 
-               BC_ListBox::deactivate_selection();
-               return 1;
+               deactivate_selection();
        }
-       else if( gui->vicon_drawing &&
-                get_button_down() && get_buttonpress() == 1 &&
-                (item = (AssetPicon*)get_selection(0, 0)) ) {
+       else if( gui->vicon_drawing && get_button_down() && get_buttonpress() == 1 &&
+                ( mwindow->edl->session->awindow_folder == AW_MEDIA_FOLDER ||
+                  mwindow->edl->session->awindow_folder >= AWINDOW_USER_FOLDERS ) &&
+                  (item = (AssetPicon*)get_selection(0, 0)) != 0 ) {
                VIcon *vicon = 0;
-               if( !gui->vicon_thread->viewing ) {
+               if( !gui->vicon_thread->vicon  ) {
                        vicon = item->vicon;
                }
                gui->vicon_thread->set_view_popup(vicon);
-
        }
-       return 0;
+       return 1;
 }
 
 void AWindowAssets::draw_background()
@@ -2268,8 +2287,7 @@ int AWindowAssets::drag_start_event()
                        // do nothing!
                        break;
                case AW_PROXY_FOLDER:
-                       proxy = 1;
-                       // fall thru
+                       proxy = 1; // fall thru
                case AW_MEDIA_FOLDER:
                default:
                        mwindow->session->current_operation = DRAG_ASSET;
@@ -2382,7 +2400,6 @@ int AWindowAssets::drag_stop_event()
        BC_ListBox::drag_stop_event();
 // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
        mwindow->session->current_operation = ::NO_OPERATION;
-       mwindow->session->clear_drag_proxy();
 
        return 1;
 }
@@ -2396,8 +2413,9 @@ int AWindowAssets::column_resize_event()
 
 int AWindowAssets::focus_in_event()
 {
+       int ret = BC_ListBox::focus_in_event();
        gui->start_vicon_drawing();
-       return 0;
+       return ret;
 }
 
 int AWindowAssets::focus_out_event()
@@ -2406,6 +2424,43 @@ int AWindowAssets::focus_out_event()
        return BC_ListBox::focus_out_event();
 }
 
+int AWindowAssets::cursor_enter_event()
+{
+       int ret = BC_ListBox::cursor_enter_event();
+       gui->start_vicon_drawing();
+       return ret;
+}
+
+int AWindowAssets::cursor_leave_event()
+{
+       gui->stop_vicon_drawing();
+       return BC_ListBox::cursor_leave_event();
+}
+
+void AWindowAssets::update_vicon_area()
+{
+       int x0 = 0, x1 = get_w();
+       int y0 = get_title_h();
+       int y1 = get_h();
+       if( is_highlighted() ) {
+               x0 += LISTBOX_BORDER;  x1 -= LISTBOX_BORDER;
+               y0 += LISTBOX_BORDER;  y1 -= LISTBOX_BORDER;
+       }
+       gui->vicon_thread->set_drawing_area(x0,y0, x1,y1);
+}
+
+int AWindowAssets::mouse_over_event(int no)
+{
+       if( gui->vicon_thread->viewing &&
+           no >= 0 && no < gui->displayed_assets[0].size() ) {
+               AssetPicon *picon = (AssetPicon *)gui->displayed_assets[0][no];
+               VIcon *vicon = picon->vicon;
+               picon->gui->vicon_thread->set_view_popup(vicon);
+       }
+       return 0;
+}
+
+
 AWindowSearchTextBox::AWindowSearchTextBox(AWindowSearchText *search_text, int x, int y, int w)
  : BC_TextBox(x, y, w, 1, "")
 {
@@ -2639,7 +2694,7 @@ AVIconDrawing::AVIconDrawing(AWindowGUI *agui, int x, int y, VFrame **images)
  : BC_Toggle(x, y, images, agui->vicon_drawing)
 {
        this->agui = agui;
-       set_tooltip(_("draw vicons"));
+       set_tooltip(_("Preview"));
 }
 
 void AVIconDrawing::calculate_geometry(AWindowGUI *agui, VFrame **images, int *ww, int *hh)