sams latest icons, rework proxy settings
[goodguy/history.git] / cinelerra-5.1 / cinelerra / awindowgui.C
index 049be4e800db38161dae1d66956334e51dec23fe..8b9a3ff4d2b55376048421541bdbd466c75c1f42 100644 (file)
@@ -35,6 +35,7 @@
 #include "cwindow.h"
 #include "edl.h"
 #include "edlsession.h"
+#include "effectlist.h"
 #include "file.h"
 #include "filesystem.h"
 #include "folderlistmenu.h"
@@ -75,7 +76,8 @@ const char *AWindowGUI::folder_names[] =
        N_("Labels"),
        N_("Clips"),
        N_("Media"),
-       N_("User")
+       N_("Proxy"),
+       N_("User"),
 };
 
 
@@ -162,13 +164,14 @@ AssetPicon::AssetPicon(MWindow *mwindow,
 }
 
 AssetPicon::AssetPicon(MWindow *mwindow,
-       AWindowGUI *gui, int folder)
+       AWindowGUI *gui, int folder, int persist)
  : BC_ListBoxItem(_(AWindowGUI::folder_names[folder]), gui->folder_icon)
 {
        reset();
        foldernum = folder;
        this->mwindow = mwindow;
        this->gui = gui;
+       persistent = persist;
 }
 
 AssetPicon::AssetPicon(MWindow *mwindow,
@@ -279,7 +282,11 @@ void AssetPicon::create_objects()
                                                        asset->width, asset->height,
                                                        BC_RGB888, -1);
                                        }
-
+                                       { char string[BCTEXTLEN];
+                                       sprintf(string, _("Reading %s"), name);
+                                       mwindow->gui->lock_window("AssetPicon::create_objects");
+                                       mwindow->gui->show_message(string);
+                                       mwindow->gui->unlock_window(); }
                                        file->read_frame(gui->temp_picon);
                                        if( debug ) printf("AssetPicon::create_objects %d\n", __LINE__);
                                        mwindow->video_cache->check_in(asset);
@@ -338,7 +345,7 @@ void AssetPicon::create_objects()
        }
        else
        if( plugin ) {
-               strcpy(name, _(plugin->title));
+               strcpy(name,  plugin->title);
                set_text(name);
                icon_vframe = plugin->get_picon();
                if( icon_vframe )
@@ -434,6 +441,7 @@ AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
        plugin_visibility = ((uint64_t)1<<(8*sizeof(uint64_t)-1))-1;
        newfolder_thread = 0;
        asset_menu = 0;
+       effectlist_menu = 0;
        assetlist_menu = 0;
        cliplist_menu = 0;
        labellist_menu = 0;
@@ -443,6 +451,7 @@ AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
        remove_plugin = 0;
        vicon_thread = 0;
        vicon_drawing = 1;
+       displayed_folder = AW_NO_FOLDER;
 }
 
 AWindowGUI::~AWindowGUI()
@@ -457,31 +466,29 @@ AWindowGUI::~AWindowGUI()
        displayed_assets[1].remove_all_objects();
 
        delete vicon_thread;
-       delete file_icon;
-       delete audio_icon;
-       delete video_icon;
-       delete folder_icon;
-       delete clip_icon;
-       delete label_icon;
-       delete atransition_icon;
-       delete vtransition_icon;
-       delete aeffect_icon;
-       delete ladspa_icon;
-       delete ladspa_vframe;
-       delete ff_aud_icon;
-       delete ff_aud_vframe;
-       delete ff_vid_icon;
-       delete ff_vid_vframe;
-       delete veffect_icon;
+       delete file_icon;         delete file_res;
+       delete audio_icon;        delete audio_res;
+       delete video_icon;        delete video_res;
+       delete folder_icon;       delete folder_res;
+       delete clip_icon;         delete clip_res;
+       delete label_icon;        delete label_res;
+       delete atransition_icon;  delete atrans_res;
+       delete vtransition_icon;  delete vtrans_res;
+       delete aeffect_icon;      delete aeffect_res;
+       delete veffect_icon;      delete veffect_res;
+       delete ladspa_icon;       delete ladspa_res;
+       delete ff_aud_icon;       delete ff_aud_res;
+       delete ff_vid_icon;       delete ff_vid_res;
        delete newfolder_thread;
        delete asset_menu;
        delete clip_menu;
        delete label_menu;
+       delete effectlist_menu;
        delete assetlist_menu;
        delete cliplist_menu;
        delete labellist_menu;
        delete folderlist_menu;
-       if( temp_picon ) delete temp_picon;
+       delete temp_picon;
        delete remove_plugin;
 }
 
@@ -502,10 +509,46 @@ bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
                icon == ff_vid_icon;
 }
 
-void AWindowGUI::create_objects()
+VFrame *AWindowGUI::get_picon(const char *name, const char *plugin_icons)
+{
+       char png_path[BCTEXTLEN];
+       char *pp = png_path, *ep = pp + sizeof(png_path)-1;
+       snprintf(pp, ep-pp, "%s/picon_%s/%s.png",
+               File::get_plugin_path(), plugin_icons, name);
+       return VFramePng::vframe_png(png_path,0,0);
+}
+
+VFrame *AWindowGUI::get_picon(const char *name)
+{
+       VFrame *vframe = get_picon(name, mwindow->preferences->plugin_icons);
+       if( !vframe ) vframe = get_picon(name, DEFAULT_PICON);
+       return vframe;
+}
+
+VFrame *AWindowGUI::resource_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, int idx)
+{
+       VFrame *ret = vfrm = get_picon(fn);
+       if( !ret ) vfrm = BC_WindowBase::get_resources()->type_to_icon[idx];
+       icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
+       return ret;
+}
+VFrame *AWindowGUI::theme_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn)
+{
+       VFrame *ret = vfrm = get_picon(fn);
+       if( !ret ) vfrm = mwindow->theme->get_image(fn);
+       icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
+       return ret;
+}
+VFrame *AWindowGUI::plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, unsigned char *png)
 {
-       AssetPicon *picon;
+       VFrame *ret = vfrm = get_picon(fn);
+       if( !ret ) vfrm = new VFramePng(png);
+       icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
+       return vfrm;
+}
 
+void AWindowGUI::create_objects()
+{
        lock_window("AWindowGUI::create_objects");
 SET_TRACE
 //printf("AWindowGUI::create_objects 1\n");
@@ -513,64 +556,35 @@ SET_TRACE
        asset_titles[1] = _("Comments");
 
 SET_TRACE
-
        set_icon(mwindow->theme->get_image("awindow_icon"));
-       file_icon = new BC_Pixmap(this,
-               BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN],
-               PIXMAP_ALPHA);
 
-       folder_icon = new BC_Pixmap(this,
-               BC_WindowBase::get_resources()->type_to_icon[ICON_FOLDER],
-               PIXMAP_ALPHA);
+       file_res    = resource_icon(file_vframe,   file_icon,   "film_icon",   ICON_UNKNOWN);
+       folder_res  = resource_icon(folder_vframe, folder_icon, "folder_icon", ICON_FOLDER);
+       audio_res   = resource_icon(audio_vframe,  audio_icon,  "audio_icon",  ICON_SOUND);
+       video_res   = resource_icon(video_vframe,  video_icon,  "video_icon",  ICON_FILM);
+       label_res   = resource_icon(label_vframe,  label_icon,  "label_icon",  ICON_LABEL);
 
-       audio_icon = new BC_Pixmap(this,
-               BC_WindowBase::get_resources()->type_to_icon[ICON_SOUND],
-               PIXMAP_ALPHA);
+       clip_res    = theme_icon(clip_vframe,        clip_icon,        "clip_icon");
+       atrans_res  = theme_icon(atransition_vframe, atransition_icon, "atransition_icon");
+       vtrans_res  = theme_icon(vtransition_vframe, vtransition_icon, "vtransition_icon");
+       aeffect_res = theme_icon(aeffect_vframe,     aeffect_icon,     "aeffect_icon");
+       veffect_res = theme_icon(veffect_vframe,     veffect_icon,     "veffect_icon");
 
-       video_icon = new BC_Pixmap(this,
-               BC_WindowBase::get_resources()->type_to_icon[ICON_FILM],
-               PIXMAP_ALPHA);
-
-       label_icon = new BC_Pixmap(this,
-               BC_WindowBase::get_resources()->type_to_icon[ICON_LABEL],
-               PIXMAP_ALPHA);
-
-SET_TRACE
-
-       clip_vframe = mwindow->theme->get_image("clip_icon");
-       clip_icon = new BC_Pixmap(this, clip_vframe, PIXMAP_ALPHA);
-       atransition_vframe = mwindow->theme->get_image("atransition_icon");
-       atransition_icon = new BC_Pixmap(this, atransition_vframe, PIXMAP_ALPHA);
-       vtransition_vframe = mwindow->theme->get_image("vtransition_icon");
-       vtransition_icon = new BC_Pixmap(this, vtransition_vframe, PIXMAP_ALPHA);
-       aeffect_vframe = mwindow->theme->get_image("aeffect_icon");
-       aeffect_icon = new BC_Pixmap(this, aeffect_vframe, PIXMAP_ALPHA);
-       ladspa_vframe = new VFramePng(lad_picon_png);
-       ladspa_icon = new BC_Pixmap(this, ladspa_vframe, PIXMAP_ALPHA);
-       ff_aud_vframe = new VFramePng(ff_audio_png);
-       ff_aud_icon = new BC_Pixmap(this, ff_aud_vframe, PIXMAP_ALPHA);
-       ff_vid_vframe = new VFramePng(ff_video_png);
-       ff_vid_icon = new BC_Pixmap(this, ff_vid_vframe, PIXMAP_ALPHA);
-       veffect_vframe = mwindow->theme->get_image("veffect_icon");
-       veffect_icon = new BC_Pixmap(this, veffect_vframe, PIXMAP_ALPHA);
+       ladspa_res  = plugin_icon(ladspa_vframe, ladspa_icon, "lad_picon", lad_picon_png);
+       ff_aud_res  = plugin_icon(ff_aud_vframe, ff_aud_icon, "ff_audio",  ff_audio_png);
+       ff_vid_res  = plugin_icon(ff_vid_vframe, ff_vid_icon, "ff_video",  ff_video_png);
 
 SET_TRACE
 
 // Mandatory folders
-       folders.append(picon = new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER));
-       picon->persistent = 1;
-       folders.append(picon = new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER));
-       picon->persistent = 1;
-       folders.append(picon = new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER));
-       picon->persistent = 1;
-       folders.append(picon = new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER));
-       picon->persistent = 1;
-       folders.append(picon = new AssetPicon(mwindow, this, AW_LABEL_FOLDER));
-       picon->persistent = 1;
-       folders.append(picon = new AssetPicon(mwindow, this, AW_CLIP_FOLDER));
-       picon->persistent = 1;
-       folders.append(picon = new AssetPicon(mwindow, this, AW_MEDIA_FOLDER));
-       picon->persistent = 1;
+       folders.append(new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER, 1));
+       folders.append(new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER, 1));
+       folders.append(new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER, 1));
+       folders.append(new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER, 1));
+       folders.append(new AssetPicon(mwindow, this, AW_LABEL_FOLDER, 1));
+       folders.append(new AssetPicon(mwindow, this, AW_CLIP_FOLDER, 1));
+       folders.append(new AssetPicon(mwindow, this, AW_PROXY_FOLDER, 1));
+       folders.append(new AssetPicon(mwindow, this, AW_MEDIA_FOLDER, 1));
 
        create_label_folder();
 SET_TRACE
@@ -630,6 +644,8 @@ SET_TRACE
        add_subwindow(label_menu = new LabelPopup(mwindow, this));
        label_menu->create_objects();
 
+       add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this));
+       effectlist_menu->create_objects();
        add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
        assetlist_menu->create_objects();
        add_subwindow(cliplist_menu = new ClipListMenu(mwindow, this));
@@ -822,13 +838,21 @@ void AWindowRemovePlugin::handle_close_event(int result)
                mwindow->plugindb->remove(plugin);
                remove(plugin_path);
                char index_path[BCTEXTLEN];
-               sprintf(index_path, "%s/%s", mwindow->preferences->plugin_dir, PLUGIN_FILE);
+               snprintf(index_path, sizeof(index_path), "%s/%s",
+                       mwindow->preferences->plugin_dir, PLUGIN_FILE);
                remove(index_path);
-               char png_path[BCTEXTLEN];
-               if( plugin->get_theme_png_path(png_path, mwindow->preferences->theme) )
-                       remove(png_path);
-               if( plugin->get_theme_png_path(png_path, "picon") )
-                       remove(png_path);
+               FileSystem fs;
+               fs.update(File::get_plugin_path());
+               for( int i=0; i<fs.dir_list.total; ++i ) {
+                       char *fs_path = fs.dir_list[i]->path;
+                       if( !fs.is_dir(fs_path) ) continue;
+                       char *cp = strrchr(fs_path,'/');
+                       cp = !cp ? fs_path : cp+1;
+                       if( strncmp("picon_", cp, 6) ) continue;
+                       char png_path[BCTEXTLEN];
+                       if( !plugin->get_plugin_png_path(png_path, cp+6) )
+                               remove(png_path);
+               }
                delete plugin;  plugin = 0;
                awindow->gui->async_update_assets();
        }
@@ -936,7 +960,7 @@ void AWindowGUI::update_folder_list()
                if( !exists ) {
                        int aw_folder = folder_number(folder);
                        AssetPicon *picon = aw_folder >= 0 ?
-                               new AssetPicon(mwindow, this, aw_folder) :
+                               new AssetPicon(mwindow, this, aw_folder, 0) :
                                new AssetPicon(mwindow, this, folder, AW_USER_FOLDER);
                        picon->create_objects();
                        folders.append(picon);
@@ -948,7 +972,7 @@ void AWindowGUI::update_folder_list()
 //     printf("AWindowGUI::update_folder_list %s\n", folders.values[i]->get_text());
 
 // Delete excess
-       for( int i = folders.total - 1; i >= 0; i-- ) {
+       for( int i=folders.total; --i>=0; ) {
                AssetPicon *picon = (AssetPicon*)folders.values[i];
                if( !picon->in_use && !picon->persistent ) {
                        delete picon;
@@ -1068,7 +1092,9 @@ void AWindowGUI::update_asset_list()
                }
        }
 
-
+       mwindow->gui->lock_window("AWindowGUI::update_asset_list");
+       mwindow->gui->default_message();
+       mwindow->gui->unlock_window();
 
 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
 
@@ -1271,10 +1297,12 @@ void AWindowGUI::filter_displayed_assets()
        }
 
        // Ensure the current folder icon is highlighted
-       for( int i = 0; i < folders.total; i++ )
-               folders.values[i]->set_selected(0);
-
-       folders.values[mwindow->edl->session->awindow_folder]->set_selected(1);
+       int selected_folder = mwindow->edl->session->awindow_folder;
+       for( int i = 0; i < folders.total; i++ ) {
+               AssetPicon *folder_item = (AssetPicon *)folders.values[i];
+               int selected = folder_item->foldernum == selected_folder ? 1 : 0;
+               folder_item->set_selected(selected);
+       }
 }
 
 
@@ -1289,27 +1317,27 @@ void AWindowGUI::update_assets()
 //printf("AWindowGUI::update_assets 3\n");
        filter_displayed_assets();
 
-//for( int i = 0; i < folders.total; i++ )
 //printf("AWindowGUI::update_assets 4\n");
-//     printf("AWindowGUI::update_assets %s\n", folders.values[i]->get_text());
-       if( mwindow->edl->session->folderlist_format != folder_list->get_format() )
+       if( mwindow->edl->session->folderlist_format != folder_list->get_format() ) {
                folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
-       folder_list->update(&folders, 0, 0, 1,
-               folder_list->get_xposition(),
-               folder_list->get_yposition(),
-               -1);
-//printf("AWindowGUI::update_assets 5\n");
+       }
+       int folder_xposition = folder_list->get_xposition();
+       int folder_yposition = folder_list->get_yposition();
+       folder_list->update(&folders, 0, 0, 1, folder_xposition, folder_yposition, -1);
 
-       if( mwindow->edl->session->assetlist_format != asset_list->get_format() )
+//printf("AWindowGUI::update_assets 5\n");
+       if( mwindow->edl->session->assetlist_format != asset_list->get_format() ) {
                asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
-
-
-//printf("AWindowGUI::update_assets 6 %d\n", displayed_assets[0].total);
+       }
+       int asset_xposition = asset_list->get_xposition();
+       int asset_yposition = asset_list->get_yposition();
+       if( displayed_folder != mwindow->edl->session->awindow_folder ) {
+               displayed_folder = mwindow->edl->session->awindow_folder;
+               asset_xposition = asset_yposition = 0;
+       }
        asset_list->update(displayed_assets, asset_titles,
                mwindow->edl->session->asset_columns, ASSET_COLUMNS,
-               asset_list->get_xposition(),
-               asset_list->get_yposition(),
-               -1, 0);
+               asset_xposition, asset_yposition, -1, 0);
        asset_list->center_selection();
 //printf("AWindowGUI::update_assets 7\n");
 
@@ -1428,21 +1456,18 @@ int AWindowDivider::button_release_event()
 
 
 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
- : BC_ListBox(x,
-               y,
-               w,
-               h,
+ : BC_ListBox(x, y, w, h,
                mwindow->edl->session->folderlist_format == ASSETS_ICONS ?
                        LISTBOX_ICONS : LISTBOX_TEXT,
-               &gui->folders, // Each column has an ArrayList of BC_ListBoxItems.
-               0,             // Titles for columns.  Set to 0 for no titles
+               &gui->folders,    // Each column has an ArrayList of BC_ListBoxItems.
+               0,                // Titles for columns.  Set to 0 for no titles
                0,                // width of each column
-               1,                      // Total columns.
-               0,                    // Pixel of top of window.
-               0,                        // If this listbox is a popup window
-               LISTBOX_SINGLE,  // Select one item or multiple items
-               ICON_TOP,        // Position of icon relative to text of each item
-               1)               // Allow drags
+               1,                // Total columns.
+               0,                // Pixel of top of window.
+               0,                // If this listbox is a popup window
+               LISTBOX_SINGLE,   // Select one item or multiple items
+               ICON_TOP,         // Position of icon relative to text of each item
+               1)                // Allow drags
 {
        this->mwindow = mwindow;
        this->gui = gui;
@@ -1503,18 +1528,19 @@ AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, in
                (mwindow->edl->session->assetlist_format == ASSETS_ICONS && gui->allow_iconlisting ) ?
                        LISTBOX_ICONS : LISTBOX_TEXT,
                &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
-               gui->asset_titles,             // Titles for columns.  Set to 0 for no titles
-               mwindow->edl->session->asset_columns,                // width of each column
-               1,                      // Total columns.
-               0,                    // Pixel of top of window.
-               0,                        // If this listbox is a popup window
-               LISTBOX_MULTIPLE,  // Select one item or multiple items
-               ICON_TOP,        // Position of icon relative to text of each item
-               1)               // Allow drag
+               gui->asset_titles,// Titles for columns.  Set to 0 for no titles
+               mwindow->edl->session->asset_columns, // width of each column
+               1,                // Total columns.
+               0,                // Pixel of top of window.
+               0,                // If this listbox is a popup window
+               LISTBOX_MULTIPLE, // Select one item or multiple items
+               ICON_TOP,         // Position of icon relative to text of each item
+               1)                // Allow drag
 {
        this->mwindow = mwindow;
        this->gui = gui;
        set_drag_scroll(0);
+       set_scroll_stretch(1, 1);
 }
 
 AWindowAssets::~AWindowAssets()
@@ -1531,6 +1557,13 @@ int AWindowAssets::button_press_event()
                BC_ListBox::deactivate_selection();
                int folder = mwindow->edl->session->awindow_folder;
                switch( folder ) {
+               case AW_AEFFECT_FOLDER:
+               case AW_VEFFECT_FOLDER:
+               case AW_ATRANSITION_FOLDER:
+               case AW_VTRANSITION_FOLDER:
+                       gui->effectlist_menu->update();
+                       gui->effectlist_menu->activate_menu();
+                       break;
                case AW_LABEL_FOLDER:
                        gui->labellist_menu->update();
                        gui->labellist_menu->activate_menu();
@@ -1539,7 +1572,8 @@ int AWindowAssets::button_press_event()
                        gui->cliplist_menu->update();
                        gui->cliplist_menu->activate_menu();
                        break;
-               default:
+               case AW_MEDIA_FOLDER:
+               case AW_PROXY_FOLDER:
                        gui->assetlist_menu->update_titles();
                        gui->assetlist_menu->activate_menu();
                        break;
@@ -1547,7 +1581,6 @@ int AWindowAssets::button_press_event()
                result = 1;
        }
 
-
        return result;
 }
 
@@ -1589,8 +1622,8 @@ int AWindowAssets::selection_changed()
                case AW_VEFFECT_FOLDER:
                case AW_ATRANSITION_FOLDER:
                case AW_VTRANSITION_FOLDER:
-                       gui->assetlist_menu->update_titles();
-                       gui->assetlist_menu->activate_menu();
+                       gui->effectlist_menu->update();
+                       gui->effectlist_menu->activate_menu();
                        break;
                case AW_LABEL_FOLDER:
                        if( !item->label ) break;
@@ -1867,7 +1900,9 @@ AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
 
 int AWindowInfo::handle_event()
 {
-       gui->awindow->asset_edit->edit_asset(gui->selected_asset());
+       int cur_x, cur_y;
+       gui->get_abs_cursor_xy(cur_x, cur_y, 0);
+       gui->awindow->asset_edit->edit_asset(gui->selected_asset(), cur_x, cur_y);
        return 1;
 }
 
@@ -2021,15 +2056,15 @@ int AVIconDrawing::handle_event()
 }
 
 
-AWindowListFormat::AWindowListFormat(MWindow *mwindow)
+AWindowListFormat::AWindowListFormat(MWindow *mwindow, AWindowGUI *gui)
  : BC_MenuItem("")
 {
        this->mwindow = mwindow;
+       this->gui = gui;
 }
 
 int AWindowListFormat::handle_event()
 {
-       AWindowGUI *gui = mwindow->awindow->gui;
        gui->stop_vicon_drawing();
 
        EDLSession *session = mwindow->edl->session;
@@ -2057,15 +2092,15 @@ void AWindowListFormat::update()
                 (char*)_("Display icons") : (char*)_("Display text"));
 }
 
-AWindowListSort::AWindowListSort(MWindow *mwindow)
+AWindowListSort::AWindowListSort(MWindow *mwindow, AWindowGUI *gui)
  : BC_MenuItem(_("Sort items"))
 {
        this->mwindow = mwindow;
+       this->gui = gui;
 }
 
 int AWindowListSort::handle_event()
 {
-       AWindowGUI *gui = mwindow->awindow->gui;
        gui->sort_assets();
        return 1;
 }