sams ladspa icons, add theme color to common icons
[goodguy/history.git] / cinelerra-5.1 / cinelerra / awindowgui.C
index da146a611be72b957580146f206159cc79e6d97c..763f62fe3fd85d27a5a9a4c18bafcc69690442f4 100644 (file)
 #include "assets.h"
 #include "awindowgui.h"
 #include "awindow.h"
+#include "bccmodels.h"
 #include "bcsignals.h"
 #include "bchash.h"
 #include "cache.h"
-#include "bccmodels.h"
+#include "cstrdup.h"
+#include "clip.h"
 #include "clippopup.h"
 #include "cursors.h"
 #include "cwindowgui.h"
@@ -296,31 +298,31 @@ void AssetPicon::create_objects()
                                else {
                                        gui->lock_window("AssetPicon::create_objects 2");
                                        icon = gui->video_icon;
-                                       icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
+                                       icon_vframe = gui->video_vframe;
                                }
                        }
                        else {
                                icon = gui->video_icon;
-                               icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
+                               icon_vframe = gui->video_vframe;
                        }
                }
                else
                if( asset->audio_data ) {
                        icon = gui->audio_icon;
-                       icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_SOUND];
+                       icon_vframe = gui->audio_vframe;
                }
 
        }
        else
        if( indexable && !indexable->is_asset ) {
                icon = gui->video_icon;
-               icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
+               icon_vframe = gui->video_vframe;
        }
        else
        if( edl ) {
                set_text(strcpy(name, edl->local_session->clip_title));
                icon = gui->clip_icon;
-               icon_vframe = mwindow->theme->get_image("clip_icon");
+               icon_vframe = gui->clip_vframe;
        }
        else
        if( plugin ) {
@@ -372,9 +374,7 @@ void AssetPicon::create_objects()
                              mwindow->edl->session->frames_per_foot);
                set_text(name);
                icon = gui->label_icon;
-               icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_LABEL];
-               set_icon(icon);
-               set_icon_vframe(icon_vframe);
+               icon_vframe = gui->label_vframe;
        }
        if( !icon ) {
                icon = gui->file_icon;
@@ -392,19 +392,40 @@ AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
 {
        this->mwindow = mwindow;
        this->awindow = awindow;
-       file_icon = 0;
-       audio_icon = 0;
-       video_icon = 0;
-       folder_icon = 0;
-       clip_icon = 0;
-       label_icon = 0;
-       atransition_icon = 0;  atransition_vframe = 0;
-       vtransition_icon = 0;  vtransition_vframe = 0;
-       aeffect_icon = 0;      aeffect_vframe = 0;
-       ladspa_icon = 0;       ladspa_vframe = 0;
-       veffect_icon = 0;      veffect_vframe = 0;
-       ff_aud_icon = 0;       ff_aud_vframe = 0;
-       ff_vid_icon = 0;       ff_vid_vframe = 0;
+
+       file_vframe = 0;                file_icon = 0;
+       folder_vframe = 0;              folder_icon = 0;
+       audio_vframe = 0;               audio_icon = 0;
+       video_vframe = 0;               video_icon = 0;
+       label_vframe = 0;               label_icon = 0;
+
+       atransition_vframe = 0;         atransition_icon = 0;
+       vtransition_vframe = 0;         vtransition_icon = 0;
+       aeffect_vframe = 0;             aeffect_icon = 0;
+       ladspa_vframe = 0;              ladspa_icon = 0;
+       veffect_vframe = 0;             veffect_icon = 0;
+       ff_aud_vframe = 0;              ff_aud_icon = 0;
+       ff_vid_vframe = 0;              ff_vid_icon = 0;
+
+       aeffect_folder_vframe = 0;      aeffect_folder_icon = 0;
+       atransition_folder_vframe = 0;  atransition_folder_icon = 0;
+       clip_folder_vframe = 0;         clip_folder_icon = 0;
+       label_folder_vframe = 0;        label_folder_icon = 0;
+       media_folder_vframe = 0;        media_folder_icon = 0;
+       proxy_folder_vframe = 0;        proxy_folder_icon = 0;
+       veffect_folder_vframe = 0;      veffect_folder_icon = 0;
+       vtransition_folder_vframe = 0;  vtransition_folder_icon = 0;
+
+       ladspa_vframe = 0;              ladspa_icon = 0;
+       ff_aud_vframe = 0;              ff_aud_icon = 0;
+       ff_vid_vframe = 0;              ff_vid_icon = 0;
+
+       clip_vframe = 0;                clip_icon = 0;
+       atransition_vframe = 0;         atransition_icon = 0;
+       vtransition_vframe = 0;         vtransition_icon = 0;
+       aeffect_vframe = 0;             aeffect_icon = 0;
+       veffect_vframe = 0;             veffect_icon = 0;
+
        plugin_visibility = ((uint64_t)1<<(8*sizeof(uint64_t)-1))-1;
        newfolder_thread = 0;
        asset_menu = 0;
@@ -414,6 +435,7 @@ AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
        labellist_menu = 0;
        folderlist_menu = 0;
        temp_picon = 0;
+       search_text = 0;
        allow_iconlisting = 1;
        remove_plugin = 0;
        vicon_thread = 0;
@@ -433,20 +455,8 @@ 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 veffect_icon;
-       delete ladspa_icon;
-       delete ff_aud_icon;
-       delete ff_vid_icon;
        delete newfolder_thread;
+
        delete asset_menu;
        delete clip_menu;
        delete label_menu;
@@ -455,8 +465,31 @@ AWindowGUI::~AWindowGUI()
        delete cliplist_menu;
        delete labellist_menu;
        delete folderlist_menu;
+       delete search_text;
        delete temp_picon;
        delete remove_plugin;
+
+       delete file_vframe;             delete file_icon;
+       delete folder_vframe;           delete folder_icon;
+       delete audio_vframe;            delete audio_icon;
+       delete video_vframe;            delete video_icon;
+       delete label_vframe;            delete label_icon;
+       delete clip_vframe;             delete clip_icon;
+       delete aeffect_folder_vframe;   delete aeffect_folder_icon;
+       delete atransition_folder_vframe; delete atransition_folder_icon;
+       delete veffect_folder_vframe;   delete veffect_folder_icon;
+       delete vtransition_folder_vframe; delete vtransition_folder_icon;
+       delete clip_folder_vframe;      delete clip_folder_icon;
+       delete label_folder_vframe;     delete label_folder_icon;
+       delete media_folder_vframe;     delete media_folder_icon;
+       delete proxy_folder_vframe;     delete proxy_folder_icon;
+       delete ladspa_vframe;           delete ladspa_icon;
+       delete ff_aud_vframe;           delete ff_aud_icon;
+       delete ff_vid_vframe;           delete ff_vid_icon;
+       delete atransition_vframe;      delete atransition_icon;
+       delete vtransition_vframe;      delete vtransition_icon;
+       delete aeffect_vframe;          delete aeffect_icon;
+       delete veffect_vframe;          delete veffect_icon;
 }
 
 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
@@ -488,15 +521,21 @@ 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",
+       snprintf(pp, ep-pp, "%s/picon/%s/%s.png",
                File::get_plugin_path(), plugin_icons, name);
+       if( access(png_path, R_OK) ) return 0;
        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);
+       if( !vframe ) {
+               char png_name[BCSTRLEN], *pp = png_name, *ep = pp + sizeof(png_name)-1;
+               snprintf(pp, ep-pp, "%s.png", name);
+               unsigned char *data = mwindow->theme->get_image_data(png_name);
+               if( data ) vframe = new VFramePng(data, 0.);
+       }
        return vframe;
 }
 
@@ -522,7 +561,7 @@ void AWindowGUI::plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, un
 void AWindowGUI::create_objects()
 {
        lock_window("AWindowGUI::create_objects");
-       asset_titles[0] = _("Title");
+       asset_titles[0] = C_("Title");
        asset_titles[1] = _("Comments");
 
        set_icon(mwindow->theme->get_image("awindow_icon"));
@@ -576,22 +615,20 @@ void AWindowGUI::create_objects()
        mwindow->theme->get_awindow_sizes(this);
        load_defaults(mwindow->defaults);
 
-       add_subwindow(asset_list = new AWindowAssets(mwindow,
-               this,
-               mwindow->theme->alist_x,
-               mwindow->theme->alist_y,
-               mwindow->theme->alist_w,
-               mwindow->theme->alist_h));
+       int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
+       int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
+       search_text = new AWindowSearchText(mwindow, this, x1, y1+5);
+       search_text->create_objects();
+       int dy = search_text->get_h() + 10;
+       y1 += dy;  h1 -= dy;
+       add_subwindow(asset_list = new AWindowAssets(mwindow, this, x1, y1, w1, h1));
 
        vicon_thread = new VIconThread(asset_list);
        vicon_thread->start();
 
-       add_subwindow(divider = new AWindowDivider(mwindow,
-               this,
-               mwindow->theme->adivider_x,
-               mwindow->theme->adivider_y,
-               mwindow->theme->adivider_w,
-               mwindow->theme->adivider_h));
+       add_subwindow(divider = new AWindowDivider(mwindow, this,
+               mwindow->theme->adivider_x, mwindow->theme->adivider_y,
+               mwindow->theme->adivider_w, mwindow->theme->adivider_h));
 
        divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
 
@@ -682,9 +719,12 @@ int AWindowGUI::translation_event()
 
 void AWindowGUI::reposition_objects()
 {
-       asset_list->reposition_window(
-               mwindow->theme->alist_x, mwindow->theme->alist_y,
-               mwindow->theme->alist_w, mwindow->theme->alist_h);
+       int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
+       int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
+       search_text->reposition_window(x1, y1+5, w1);
+       int dy = search_text->get_h() + 10;
+       y1 += dy;  h1 -= dy;
+       asset_list->reposition_window(x1, y1, w1, h1);
        divider->reposition_window(
                mwindow->theme->adivider_x, mwindow->theme->adivider_y,
                mwindow->theme->adivider_w, mwindow->theme->adivider_h);
@@ -771,8 +811,8 @@ void AWindowRemovePluginGUI::create_objects()
        add_subwindow(title);
        y += title->get_h() + 5;
        list = new BC_ListBox(x, y,
-                get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
-                0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
+               get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
+               0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
        add_subwindow(list);
        show_window();
 }
@@ -796,6 +836,7 @@ void AWindowRemovePlugin::handle_close_event(int result)
 {
        if( !result ) {
                printf(_("remove %s\n"), plugin->path);
+               awindow->gui->lock_window("AWindowRemovePlugin::handle_close_event");
                ArrayList<BC_ListBoxItem*> *folder =
                        plugin->audio ? plugin->transition ?
                                &awindow->gui->atransitions :
@@ -805,26 +846,28 @@ void AWindowRemovePlugin::handle_close_event(int result)
                                &awindow->gui->veffects :
                        0;
                if( folder ) remove_plugin(plugin, *folder);
+               MWindow *mwindow = awindow->mwindow;
+               awindow->gui->unlock_window();
                char plugin_path[BCTEXTLEN];
                strcpy(plugin_path, plugin->path);
-               MWindow *mwindow = awindow->mwindow;
                mwindow->plugindb->remove(plugin);
                remove(plugin_path);
                char index_path[BCTEXTLEN];
-               snprintf(index_path, sizeof(index_path), "%s/%s",
-                       mwindow->preferences->plugin_dir, PLUGIN_FILE);
+               mwindow->create_defaults_path(index_path, PLUGIN_FILE);
                remove(index_path);
+               char picon_path[BCTEXTLEN];
                FileSystem fs;
-               fs.update(File::get_plugin_path());
+               snprintf(picon_path, sizeof(picon_path), "%s/picon",
+                       File::get_plugin_path());
+               char png_name[BCSTRLEN], png_path[BCTEXTLEN];
+               plugin->get_plugin_png_name(png_name);
+               fs.update(picon_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);
+                       snprintf(png_path, sizeof(picon_path), "%s/%s",
+                               fs_path, png_name);
+                       remove(png_path);
                }
                delete plugin;  plugin = 0;
                awindow->gui->async_update_assets();
@@ -902,7 +945,6 @@ void AWindowGUI::async_update_assets()
 
 void AWindowGUI::update_folder_list()
 {
-       stop_vicon_drawing();
        for( int i = 0; i < folders.total; i++ ) {
                AssetPicon *picon = (AssetPicon*)folders.values[i];
                picon->in_use = 0;
@@ -940,8 +982,6 @@ void AWindowGUI::update_folder_list()
                        folders.remove_number(i);
                }
        }
-
-       start_vicon_drawing();
 }
 
 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
@@ -1116,13 +1156,15 @@ void AWindowGUI::sort_assets()
        default:
                sort_picons(&assets);
        }
-
+// reset xyposition
+       asset_list->update_format(asset_list->get_format(), 0);
        update_assets();
 }
 
 void AWindowGUI::sort_folders()
 {
        sort_picons(&folders);
+       folder_list->update_format(folder_list->get_format(), 0);
        update_assets();
 }
 
@@ -1154,6 +1196,10 @@ void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst,
                if( folder < 0 ||
                    (picon->indexable && picon->indexable->awindow_folder == folder) ||
                    (picon->edl && picon->edl->local_session->awindow_folder == folder) ) {
+                       const char *text = search_text->get_text();
+                       int hidden = text && text[0] && !bstrcasestr(picon->get_text(), text);
+                       if( picon->vicon ) picon->vicon->hidden = hidden;
+                       if( hidden ) continue;
                        BC_ListBoxItem *item2, *item1;
                        dst[0].append(item1 = picon);
                        if( picon->edl )
@@ -1163,8 +1209,8 @@ void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst,
                                dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr));
                        else
                                dst[1].append(item2 = new BC_ListBoxItem(""));
-                       item1->set_autoplace_text(1);
-                       item2->set_autoplace_text(1);
+                       item1->set_autoplace_text(1);  item1->set_autoplace_icon(1);
+                       item2->set_autoplace_text(1);  item2->set_autoplace_icon(1);
                }
        }
 }
@@ -1195,7 +1241,7 @@ void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src)
 void AWindowGUI::filter_displayed_assets()
 {
        //allow_iconlisting = 1;
-       asset_titles[0] = _("Title");
+       asset_titles[0] = C_("Title");
        asset_titles[1] = _("Comments");
 
        switch( mwindow->edl->session->awindow_folder ) {
@@ -1214,7 +1260,7 @@ void AWindowGUI::filter_displayed_assets()
        case AW_LABEL_FOLDER:
                copy_picons(displayed_assets, &labellist, AW_NO_FOLDER);
                asset_titles[0] = _("Time Stamps");
-               asset_titles[1] = _("Title");
+               asset_titles[1] = C_("Title");
                //allow_iconlisting = 0;
                break;
        default:
@@ -1234,10 +1280,14 @@ void AWindowGUI::filter_displayed_assets()
 
 void AWindowGUI::update_assets()
 {
+       stop_vicon_drawing();
        update_folder_list();
        update_asset_list();
        labellist.remove_all_objects();
        create_label_folder();
+
+       if( displayed_folder != mwindow->edl->session->awindow_folder )
+               search_text->clear();
        filter_displayed_assets();
 
        if( mwindow->edl->session->folderlist_format != folder_list->get_format() ) {
@@ -1262,6 +1312,7 @@ void AWindowGUI::update_assets()
        asset_list->center_selection();
 
        flush();
+       start_vicon_drawing();
        return;
 }
 
@@ -1699,11 +1750,13 @@ int AWindowAssets::drag_stop_event()
 
        lock_window("AWindowAssets::drag_stop_event");
 
-       if( result ) get_drag_popup()->set_animation(0);
+       if( result )
+               get_drag_popup()->set_animation(0);
 
        BC_ListBox::drag_stop_event();
-       mwindow->session->current_operation = ::NO_OPERATION; // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
-       return 0;
+// since NO_OPERATION is also defined in listbox, we have to reach for global scope...
+       mwindow->session->current_operation = ::NO_OPERATION;
+       return 1;
 }
 
 int AWindowAssets::column_resize_event()
@@ -1725,16 +1778,68 @@ int AWindowAssets::focus_out_event()
        return BC_ListBox::focus_out_event();
 }
 
+AWindowSearchTextBox::AWindowSearchTextBox(AWindowSearchText *search_text, int x, int y, int w)
+ : BC_TextBox(x, y, w, 1, "")
+{
+       this->search_text = search_text;
+}
 
+int AWindowSearchTextBox::handle_event()
+{
+       return search_text->handle_event();
+}
 
+AWindowSearchText::AWindowSearchText(MWindow *mwindow, AWindowGUI *gui, int x, int y)
+{
+       this->mwindow = mwindow;
+       this->gui = gui;
+       this->x = x;
+       this->y = y;
+}
 
+void AWindowSearchText::create_objects()
+{
+       int x1 = x, y1 = y, margin = 10;
+       gui->add_subwindow(text_title = new BC_Title(x1, y1, _("Search:")));
+       x1 += text_title->get_w() + margin;
+       int w1 = gui->get_w() - x1 - 2*margin;
+       gui->add_subwindow(text_box = new AWindowSearchTextBox(this, x1, y1, w1));
+}
 
+int AWindowSearchText::handle_event()
+{
+       gui->async_update_assets();
+       return 1;
+}
 
+int AWindowSearchText::get_w()
+{
+       return text_box->get_w() + text_title->get_w() + 10;
+}
 
+int AWindowSearchText::get_h()
+{
+       return bmax(text_box->get_h(),text_title->get_h());
+}
 
+void AWindowSearchText::reposition_window(int x, int y, int w)
+{
+       int x1 = x, y1 = y, margin = 10;
+       text_title->reposition_window(x1, y1);
+       x1 += text_title->get_w() + margin;
+       int w1 = gui->get_w() - x1 - 2*margin;
+       text_box->reposition_window(x1, y1, w1);
+}
 
+const char *AWindowSearchText::get_text()
+{
+       return text_box->get_text();
+}
 
-
+void AWindowSearchText::clear()
+{
+       text_box->update("");
+}
 
 AWindowNewFolder::AWindowNewFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
  : BC_Button(x, y, mwindow->theme->newbin_data)
@@ -1817,7 +1922,7 @@ int AWindowDeleteProject::handle_event()
 // int AWindowInfo::handle_event()
 // {
 //     int cur_x, cur_y;
-//     gui->get_abs_cursor_xy(cur_x, cur_y, 0);
+//     gui->get_abs_cursor(cur_x, cur_y, 0);
 //     gui->awindow->asset_edit->edit_asset(gui->selected_asset(), cur_x, cur_y);
 //     return 1;
 // }
@@ -1926,13 +2031,13 @@ AddPluginItem::AddPluginItem(AddTools *menu, char const *text, int idx)
        this->idx = idx;
        uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
        int chk = (msk & vis) ? 1 : 0;
-        set_checked(chk);
+       set_checked(chk);
 }
 
 int AddPluginItem::handle_event()
 {
-        int chk = get_checked() ^ 1;
-        set_checked(chk);
+       int chk = get_checked() ^ 1;
+       set_checked(chk);
        uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
        menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
        menu->gui->update_effects();
@@ -2004,8 +2109,8 @@ int AWindowListFormat::handle_event()
 
 void AWindowListFormat::update()
 {
-        set_text(mwindow->edl->session->assetlist_format == ASSETS_TEXT ?
-                (char*)_("Display icons") : (char*)_("Display text"));
+       set_text(mwindow->edl->session->assetlist_format == ASSETS_TEXT ?
+               (char*)_("Display icons") : (char*)_("Display text"));
 }
 
 AWindowListSort::AWindowListSort(MWindow *mwindow, AWindowGUI *gui)