fixes and upgrades to guicast
[goodguy/history.git] / cinelerra-5.0 / guicast / bcresources.C
index 7ac9096b470f68956f7822a27728aa987b61a602..58d3c5879cfc0b08a29f4038254cacdb69e43b68 100644 (file)
@@ -209,20 +209,15 @@ BC_Resources::BC_Resources()
 {
        synchronous = 0;
        vframe_shm = 0;
-       display_info = new BC_DisplayInfo("", 0);
-       double scale = 1;
-       char *font_scale = getenv("BC_FONT_SCALE");
-       if( !font_scale ) {
-               int display_w = display_info->get_root_w();
-               int display_h = display_info->get_root_h();
-               int display_size = display_h < display_w ? display_h : display_w;
-               scale = display_size / 1000.;
-       }
-       else {
-               double env_scale = atof(font_scale);
-               if( env_scale > 0 ) scale = env_scale;
-       }
-       init_font_defs(scale);
+       double default_scale = 1.0; // display_size/1000.;
+       char *env = getenv("BC_FONT_SCALE");
+       font_scale = env ? atof(env) : default_scale;
+       if( font_scale <= 0 ) font_scale = 1;
+       init_font_defs(font_scale);
+       env = getenv("BC_ICON_SCALE");
+       icon_scale = env ? atof(env) : default_scale;
+       if( icon_scale <= 0 ) icon_scale = 1;
+
        id_lock = new Mutex("BC_Resources::id_lock");
        create_window_lock = new Mutex("BC_Resources::create_window_lock", 1);
        id = 0;
@@ -246,17 +241,17 @@ BC_Resources::BC_Resources()
 #include "images/file_column_png.h"
        static VFrame* default_type_to_icon[] =
        {
-               new VFrame(file_folder_png),
-               new VFrame(file_unknown_png),
-               new VFrame(file_film_png),
-               new VFrame(file_sound_png),
-               new VFrame(file_column_png)
+               new VFramePng(file_folder_png),
+               new VFramePng(file_unknown_png),
+               new VFramePng(file_film_png),
+               new VFramePng(file_sound_png),
+               new VFramePng(file_column_png)
        };
        type_to_icon = default_type_to_icon;
 
 
 #include "images/bar_png.h"
-       static VFrame* default_bar = new VFrame(bar_png);
+       static VFrame* default_bar = new VFramePng(bar_png);
        bar_data = default_bar;
 
 
@@ -265,9 +260,9 @@ BC_Resources::BC_Resources()
 #include "images/cancel_dn_png.h"
        static VFrame* default_cancel_images[] =
        {
-               new VFrame(cancel_up_png),
-               new VFrame(cancel_hi_png),
-               new VFrame(cancel_dn_png)
+               new VFramePng(cancel_up_png),
+               new VFramePng(cancel_hi_png),
+               new VFramePng(cancel_dn_png)
        };
 
 #include "images/ok_up_png.h"
@@ -275,9 +270,9 @@ BC_Resources::BC_Resources()
 #include "images/ok_dn_png.h"
        static VFrame* default_ok_images[] =
        {
-               new VFrame(ok_up_png),
-               new VFrame(ok_hi_png),
-               new VFrame(ok_dn_png)
+               new VFramePng(ok_up_png),
+               new VFramePng(ok_hi_png),
+               new VFramePng(ok_dn_png)
        };
 
 #include "images/usethis_up_png.h"
@@ -285,9 +280,9 @@ BC_Resources::BC_Resources()
 #include "images/usethis_dn_png.h"
        static VFrame* default_usethis_images[] =
        {
-               new VFrame(usethis_up_png),
-               new VFrame(usethis_uphi_png),
-               new VFrame(usethis_dn_png)
+               new VFramePng(usethis_up_png),
+               new VFramePng(usethis_uphi_png),
+               new VFramePng(usethis_dn_png)
        };
 
 #if 0
@@ -298,11 +293,11 @@ BC_Resources::BC_Resources()
 #include "images/checkbox_hi_png.h"
        static VFrame* default_checkbox_images[] =
        {
-               new VFrame(checkbox_up_png),
-               new VFrame(checkbox_hi_png),
-               new VFrame(checkbox_checked_png),
-               new VFrame(checkbox_dn_png),
-               new VFrame(checkbox_checkedhi_png)
+               new VFramePng(checkbox_up_png),
+               new VFramePng(checkbox_hi_png),
+               new VFramePng(checkbox_checked_png),
+               new VFramePng(checkbox_dn_png),
+               new VFramePng(checkbox_checkedhi_png)
        };
 
 #include "images/radial_checked_png.h"
@@ -312,25 +307,25 @@ BC_Resources::BC_Resources()
 #include "images/radial_hi_png.h"
        static VFrame* default_radial_images[] =
        {
-               new VFrame(radial_up_png),
-               new VFrame(radial_hi_png),
-               new VFrame(radial_checked_png),
-               new VFrame(radial_dn_png),
-               new VFrame(radial_checkedhi_png)
+               new VFramePng(radial_up_png),
+               new VFramePng(radial_hi_png),
+               new VFramePng(radial_checked_png),
+               new VFramePng(radial_dn_png),
+               new VFramePng(radial_checkedhi_png)
        };
 
        static VFrame* default_label_images[] =
        {
-               new VFrame(radial_up_png),
-               new VFrame(radial_hi_png),
-               new VFrame(radial_checked_png),
-               new VFrame(radial_dn_png),
-               new VFrame(radial_checkedhi_png)
+               new VFramePng(radial_up_png),
+               new VFramePng(radial_hi_png),
+               new VFramePng(radial_checked_png),
+               new VFramePng(radial_dn_png),
+               new VFramePng(radial_checkedhi_png)
        };
 #endif
 
 #include "images/check_png.h"
-       static VFrame* default_check_image = new VFrame(check_png);
+       static VFrame* default_check_image = new VFramePng(check_png);
        check = default_check_image;
 
 #include "images/file_text_up_png.h"
@@ -356,52 +351,52 @@ BC_Resources::BC_Resources()
 #include "images/file_reload_dn_png.h"
        static VFrame* default_filebox_text_images[] =
        {
-               new VFrame(file_text_up_png),
-               new VFrame(file_text_hi_png),
-               new VFrame(file_text_dn_png)
+               new VFramePng(file_text_up_png),
+               new VFramePng(file_text_hi_png),
+               new VFramePng(file_text_dn_png)
        };
 
        static VFrame* default_filebox_icons_images[] =
        {
-               new VFrame(file_icons_up_png),
-               new VFrame(file_icons_hi_png),
-               new VFrame(file_icons_dn_png)
+               new VFramePng(file_icons_up_png),
+               new VFramePng(file_icons_hi_png),
+               new VFramePng(file_icons_dn_png)
        };
 
        static VFrame* default_filebox_updir_images[] =
        {
-               new VFrame(file_updir_up_png),
-               new VFrame(file_updir_hi_png),
-               new VFrame(file_updir_dn_png)
+               new VFramePng(file_updir_up_png),
+               new VFramePng(file_updir_hi_png),
+               new VFramePng(file_updir_dn_png)
        };
 
        static VFrame* default_filebox_newfolder_images[] =
        {
-               new VFrame(file_newfolder_up_png),
-               new VFrame(file_newfolder_hi_png),
-               new VFrame(file_newfolder_dn_png)
+               new VFramePng(file_newfolder_up_png),
+               new VFramePng(file_newfolder_hi_png),
+               new VFramePng(file_newfolder_dn_png)
        };
 
 
        static VFrame* default_filebox_rename_images[] =
        {
-               new VFrame(file_rename_up_png),
-               new VFrame(file_rename_hi_png),
-               new VFrame(file_rename_dn_png)
+               new VFramePng(file_rename_up_png),
+               new VFramePng(file_rename_hi_png),
+               new VFramePng(file_rename_dn_png)
        };
 
        static VFrame* default_filebox_delete_images[] =
        {
-               new VFrame(file_delete_up_png),
-               new VFrame(file_delete_hi_png),
-               new VFrame(file_delete_dn_png)
+               new VFramePng(file_delete_up_png),
+               new VFramePng(file_delete_hi_png),
+               new VFramePng(file_delete_dn_png)
        };
 
        static VFrame* default_filebox_reload_images[] =
        {
-               new VFrame(file_reload_up_png),
-               new VFrame(file_reload_hi_png),
-               new VFrame(file_reload_dn_png)
+               new VFramePng(file_reload_up_png),
+               new VFramePng(file_reload_hi_png),
+               new VFramePng(file_reload_dn_png)
        };
 
 #include "images/listbox_button_dn_png.h"
@@ -410,10 +405,10 @@ BC_Resources::BC_Resources()
 #include "images/listbox_button_disabled_png.h"
        static VFrame* default_listbox_button[] =
        {
-               new VFrame(listbox_button_up_png),
-               new VFrame(listbox_button_hi_png),
-               new VFrame(listbox_button_dn_png),
-               new VFrame(listbox_button_disabled_png)
+               new VFramePng(listbox_button_up_png),
+               new VFramePng(listbox_button_hi_png),
+               new VFramePng(listbox_button_dn_png),
+               new VFramePng(listbox_button_disabled_png)
        };
        listbox_button = default_listbox_button;
 
@@ -428,11 +423,11 @@ BC_Resources::BC_Resources()
 #include "images/listbox_expanduphi_png.h"
        static VFrame* default_listbox_expand[] =
        {
-               new VFrame(listbox_expandup_png),
-               new VFrame(listbox_expanduphi_png),
-               new VFrame(listbox_expandchecked_png),
-               new VFrame(listbox_expanddn_png),
-               new VFrame(listbox_expandcheckedhi_png),
+               new VFramePng(listbox_expandup_png),
+               new VFramePng(listbox_expanduphi_png),
+               new VFramePng(listbox_expandchecked_png),
+               new VFramePng(listbox_expanddn_png),
+               new VFramePng(listbox_expandcheckedhi_png),
        };
        listbox_expand = default_listbox_expand;
 
@@ -441,17 +436,17 @@ BC_Resources::BC_Resources()
 #include "images/listbox_columndn_png.h"
        static VFrame* default_listbox_column[] =
        {
-               new VFrame(listbox_columnup_png),
-               new VFrame(listbox_columnhi_png),
-               new VFrame(listbox_columndn_png)
+               new VFramePng(listbox_columnup_png),
+               new VFramePng(listbox_columnhi_png),
+               new VFramePng(listbox_columndn_png)
        };
        listbox_column = default_listbox_column;
 
 
 #include "images/listbox_up_png.h"
 #include "images/listbox_dn_png.h"
-       listbox_up = new VFrame(listbox_up_png);
-       listbox_dn = new VFrame(listbox_dn_png);
+       listbox_up = new VFramePng(listbox_up_png);
+       listbox_dn = new VFramePng(listbox_dn_png);
        listbox_title_overlap = 0;
        listbox_title_margin = 0;
        listbox_title_color = BLACK;
@@ -473,17 +468,17 @@ BC_Resources::BC_Resources()
 #include "images/pot_dn_png.h"
        static VFrame *default_pot_images[] =
        {
-               new VFrame(pot_up_png),
-               new VFrame(pot_hi_png),
-               new VFrame(pot_dn_png)
+               new VFramePng(pot_up_png),
+               new VFramePng(pot_hi_png),
+               new VFramePng(pot_dn_png)
        };
 
 #include "images/progress_up_png.h"
 #include "images/progress_hi_png.h"
        static VFrame* default_progress_images[] =
        {
-               new VFrame(progress_up_png),
-               new VFrame(progress_hi_png)
+               new VFramePng(progress_up_png),
+               new VFramePng(progress_hi_png)
        };
 
        pan_data = 0;
@@ -511,26 +506,26 @@ BC_Resources::BC_Resources()
 #include "images/7seg_small/dash_png.h"
        static VFrame* default_medium_7segment[] =
        {
-               new VFrame(_0_png),
-               new VFrame(_1_png),
-               new VFrame(_2_png),
-               new VFrame(_3_png),
-               new VFrame(_4_png),
-               new VFrame(_5_png),
-               new VFrame(_6_png),
-               new VFrame(_7_png),
-               new VFrame(_8_png),
-               new VFrame(_9_png),
-               new VFrame(colon_png),
-               new VFrame(period_png),
-               new VFrame(a_png),
-               new VFrame(b_png),
-               new VFrame(c_png),
-               new VFrame(d_png),
-               new VFrame(e_png),
-               new VFrame(f_png),
-               new VFrame(space_png),
-               new VFrame(dash_png)
+               new VFramePng(_0_png),
+               new VFramePng(_1_png),
+               new VFramePng(_2_png),
+               new VFramePng(_3_png),
+               new VFramePng(_4_png),
+               new VFramePng(_5_png),
+               new VFramePng(_6_png),
+               new VFramePng(_7_png),
+               new VFramePng(_8_png),
+               new VFramePng(_9_png),
+               new VFramePng(colon_png),
+               new VFramePng(period_png),
+               new VFramePng(a_png),
+               new VFramePng(b_png),
+               new VFramePng(c_png),
+               new VFramePng(d_png),
+               new VFramePng(e_png),
+               new VFramePng(f_png),
+               new VFramePng(space_png),
+               new VFramePng(dash_png)
        };
 
        generic_button_margin = 15;
@@ -589,24 +584,24 @@ BC_Resources::BC_Resources()
 
        static VFrame *default_menuitem_data[] =
        {
-               new VFrame(menuitem_up_png),
-               new VFrame(menuitem_hi_png),
-               new VFrame(menuitem_dn_png),
+               new VFramePng(menuitem_up_png),
+               new VFramePng(menuitem_hi_png),
+               new VFramePng(menuitem_dn_png),
        };
        menu_item_bg = default_menuitem_data;
 
 
        static VFrame *default_menubar_data[] =
        {
-               new VFrame(menubar_up_png),
-               new VFrame(menubar_hi_png),
-               new VFrame(menubar_dn_png),
+               new VFramePng(menubar_up_png),
+               new VFramePng(menubar_hi_png),
+               new VFramePng(menubar_dn_png),
        };
        menu_title_bg = default_menubar_data;
 
-       menu_popup_bg = new VFrame(menu_popup_bg_png);
+       menu_popup_bg = new VFramePng(menu_popup_bg_png);
 
-       menu_bar_bg = new VFrame(menubar_bg_png);
+       menu_bar_bg = new VFramePng(menubar_bg_png);
 
        popupmenu_images = 0;
 
@@ -786,30 +781,6 @@ void BC_Resources::set_synchronous(BC_Synchronous *synchronous)
 
 
 
-
-
-
-int BC_Resources::get_top_border()
-{
-       return display_info->get_top_border();
-}
-
-int BC_Resources::get_left_border()
-{
-       return display_info->get_left_border();
-}
-
-int BC_Resources::get_right_border()
-{
-       return display_info->get_right_border();
-}
-
-int BC_Resources::get_bottom_border()
-{
-       return display_info->get_bottom_border();
-}
-
-
 int BC_Resources::get_bg_color() { return bg_color; }
 
 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
@@ -1430,13 +1401,20 @@ int BC_Resources::init_fontconfig(const char *search_path)
        return 0;
 }
 
-BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style, int mask)
+#define STYLE_MATCH(fst, stl, msk) ((fst) & (msk) & (stl)) && \
+       !((fst) & ~(style) & (msk))
+
+BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style,
+       int mask, int preferred)
 {
-       BC_FontEntry *entry, *style_match, *displayname_match;
+       BC_FontEntry *entry, *style_match, *preferred_match;
 
        if(!fontlist)
                return 0;
 
+       style_match = 0;
+       preferred_match = 0;
+
        if(displayname)
        {
                for(int i = 0; i < fontlist->total; i++)
@@ -1444,34 +1422,49 @@ BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style, i
                        entry = fontlist->values[i];
 
                        if(strcmp(entry->displayname, displayname) == 0 &&
-                                       (entry->style & mask) == style)
-                               return entry;
+                                       STYLE_MATCH(entry->style, style, mask))
+                       {
+                               if(!style_match)
+                                       style_match = entry;
+                               if(!preferred_match && (entry->style & preferred))
+                                       preferred_match = entry;
+                       }
                }
+               if(preferred_match)
+                       return preferred_match;
+
+               if(style_match)
+                       return style_match;
        }
+
 // No exact match - assume normal width font
        style |= FL_WIDTH_NORMAL;
        mask |= FL_WIDTH_MASK;
-       style_match = 0;  displayname_match = 0;
+       style_match = 0;
+       preferred_match = 0;
+
        for(int i = 0; i < fontlist->total; i++)
        {
                entry = fontlist->values[i];
 
-               if(!strncasecmp(displayname, entry->family,
-                               strlen(entry->family)))
-               {
-                       if((entry->style & mask) == style)
-                               return entry;
-                       if(!displayname_match)
-                               displayname_match = entry;
-               }
-
-               if((entry->style & mask) == style)
+               if(STYLE_MATCH(entry->style, style, mask))
                {
                        if(!style_match)
                                style_match = entry;
+
+                       if(!preferred_match && (entry->style & preferred))
+                               preferred_match = entry;
+
+                       if(!strncasecmp(displayname, entry->family,
+                                       strlen(entry->family)))
+                       return entry;
                }
        }
-       return displayname_match ? displayname_match : style_match;
+
+       if(preferred_match)
+               return preferred_match;
+
+       return style_match;
 }
 
 size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
@@ -1522,6 +1515,14 @@ size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
        return inbytes;
 }
 
+void BC_Resources::encode_to_utf8(char *buffer, int buflen)
+{
+        if(BC_Resources::locale_utf8) return;
+       char lbuf[buflen];
+       encode(encoding, 0, buffer, buflen, lbuf, buflen);
+       strcpy(buffer, lbuf);
+}
+
 int BC_Resources::find_font_by_char(FT_ULong char_code, char *path_new, const FT_Face oldface)
 {
        FcPattern *font, *ofont;