rework android-rmt display, add a few buttons
[goodguy/history.git] / cinelerra-5.0 / guicast / bcresources.C
index ef77752355491a20c1aaf6f3877e692d77b7a703..fa72be3b2d54b4bc068fdcc938a010984a31cdad 100644 (file)
@@ -1,7 +1,7 @@
 
 /*
  * CINELERRA
- * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
+ * Copyright (C) 2009-2015 Adam Williams <broadcast at earthling dot net>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -209,20 +209,20 @@ 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);
+       /* causes more problems than it fixes */
+       //display_info = new BC_DisplayInfo("", 0);
+       //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;
+       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 +246,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 +265,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 +275,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 +285,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 +298,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,23 +312,27 @@ 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 VFramePng(check_png);
+       check = default_check_image;
+
 #include "images/file_text_up_png.h"
 #include "images/file_text_hi_png.h"
 #include "images/file_text_dn_png.h"
@@ -352,52 +356,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"
@@ -406,10 +410,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;
 
@@ -424,11 +428,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;
 
@@ -437,17 +441,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;
@@ -469,17 +473,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;
@@ -507,26 +511,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;
@@ -585,24 +589,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;
 
@@ -954,12 +958,51 @@ int BC_Resources::init_fontconfig(const char *search_path)
                sprintf(line, "%s (%s)", entry->family, entry->foundry);
                entry->displayname = cstrdup(line);
 
-               if(!strcasecmp(entry->weight, "demibold") ||
-                   !strcasecmp(entry->weight, "bold"))
+               if(!strcasecmp(entry->weight, "demibold")) {
+                       entry->fixed_style |= BC_FONT_BOLD;
+                       entry->style |= FL_WEIGHT_DEMIBOLD;
+               }
+               else if(!strcasecmp(entry->weight, "bold")) {
                        entry->fixed_style |= BC_FONT_BOLD;
-               if(!strcasecmp(entry->slant, "i") ||
-                   !strcasecmp(entry->slant, "o"))
+                       entry->style |= FL_WEIGHT_BOLD;
+               }
+               else {
+                       entry->style |= FL_WEIGHT_NORMAL;
+               }
+
+               if(!strcasecmp(entry->slant, "r")) {
+                       entry->style |= FL_SLANT_ROMAN;
+               }
+               else if(!strcasecmp(entry->slant, "i")) {
+                       entry->style |= FL_SLANT_ITALIC;
+                       entry->fixed_style |= BC_FONT_ITALIC;
+               }
+               else if(!strcasecmp(entry->slant, "o")) {
+                       entry->style |= FL_SLANT_OBLIQUE;
                        entry->fixed_style |= BC_FONT_ITALIC;
+               }
+
+               if(!strcasecmp(entry->swidth, "normal"))
+                       entry->style = FL_WIDTH_NORMAL;
+               else if(!strcasecmp(entry->swidth, "ultracondensed"))
+                       entry->style = FL_WIDTH_ULTRACONDENSED;
+               else if(!strcasecmp(entry->swidth, "extracondensed"))
+                       entry->style = FL_WIDTH_EXTRACONDENSED;
+               else if(!strcasecmp(entry->swidth, "condensed"))
+                       entry->style = FL_WIDTH_CONDENSED;
+               else if(!strcasecmp(entry->swidth, "semicondensed"))
+                       entry->style = FL_WIDTH_SEMICONDENSED;
+               else if(!strcasecmp(entry->swidth, "semiexpanded"))
+                       entry->style = FL_WIDTH_SEMIEXPANDED;
+               else if(!strcasecmp(entry->swidth, "expanded"))
+                       entry->style = FL_WIDTH_EXPANDED;
+               else if(!strcasecmp(entry->swidth, "extraexpanded"))
+                       entry->style = FL_WIDTH_EXTRAEXPANDED;
+               else if(!strcasecmp(entry->swidth, "ultraexpanded"))
+                       entry->style = FL_WIDTH_ULTRAEXPANDED;
+               else
+                       entry->style = FL_WIDTH_NORMAL;
+
                fontlist->append(entry);
 //             printf("TitleMain::build_fonts %s: success\n",  entry->path);
 //printf("TitleMain::build_fonts 2\n");
@@ -974,7 +1017,8 @@ int BC_Resources::init_fontconfig(const char *search_path)
        FcChar8 *family, *file, *foundry, *style, *format;
        int slant, spacing, width, weight;
        int force_style = 0;
-       int limit_to_trutype = 0; // if you want limit search to TrueType put 1
+// if you want limit search to TrueType put 1
+       int limit_to_trutype = 1;
        FcConfig *config;
        int i;
        char tmpstring[BCTEXTLEN];
@@ -1012,7 +1056,7 @@ int BC_Resources::init_fontconfig(const char *search_path)
                force_style = 0;
                FcPatternGetString(font, FC_FONTFORMAT, 0, &format);
                //on this point you can limit font search
-               if(!limit_to_trutype || !strcmp((char *)format, "TrueType"))
+               if(limit_to_trutype && strcmp((char *)format, "TrueType"))
                        continue;
 
                sprintf(tmpstring, "%s", format);
@@ -1065,13 +1109,16 @@ int BC_Resources::init_fontconfig(const char *search_path)
                        case FC_SLANT_ROMAN:
                        default:
                                entry->slant = cstrdup("r");
+                               entry->style |= FL_SLANT_ROMAN;
                                break;
                        case FC_SLANT_ITALIC:
                                entry->slant = cstrdup("i");
+                               entry->style |= FL_SLANT_ITALIC;
                                entry->fixed_style |= BC_FONT_ITALIC;
                                break;
                        case FC_SLANT_OBLIQUE:
                                entry->slant = cstrdup("o");
+                               entry->style |= FL_SLANT_OBLIQUE;
                                entry->fixed_style |= BC_FONT_ITALIC;
                                break;
                        }
@@ -1250,25 +1297,6 @@ int BC_Resources::init_fontconfig(const char *search_path)
                        }
                }
 
-               if(FcPatternGetInteger(font, FC_SLANT, 0, &intvalue) == FcResultMatch)
-               {
-                       switch(intvalue)
-                       {
-                       case FC_SLANT_ROMAN:
-                       default:
-                               entry->style |= FL_SLANT_ROMAN;
-                               break;
-
-                       case FC_SLANT_ITALIC:
-                               entry->style |= FL_SLANT_ITALIC;
-                               break;
-
-                       case FC_SLANT_OBLIQUE:
-                               entry->style |= FL_SLANT_OBLIQUE;
-                               break;
-                       }
-               }
-
                if(FcPatternGetInteger(font, FC_WEIGHT, 0, &intvalue) == FcResultMatch)
                {
                        switch(intvalue)
@@ -1404,7 +1432,7 @@ int BC_Resources::init_fontconfig(const char *search_path)
 
 BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style, int mask)
 {
-       BC_FontEntry *entry, *style_match;
+       BC_FontEntry *entry, *style_match, *displayname_match;
 
        if(!fontlist)
                return 0;
@@ -1423,22 +1451,27 @@ BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style, i
 // No exact match - assume normal width font
        style |= FL_WIDTH_NORMAL;
        mask |= FL_WIDTH_MASK;
-       style_match = 0;
+       style_match = 0;  displayname_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)
                                style_match = entry;
-
-                       if(!strncasecmp(displayname, entry->family,
-                                       strlen(entry->family)))
-                       return entry;
                }
        }
-       return style_match;
+       return displayname_match ? displayname_match : style_match;
 }
 
 size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
@@ -1569,3 +1602,15 @@ FcPattern* BC_Resources::find_similar_font(FT_ULong char_code, FcPattern *oldfon
        return pat;
 }
 
+void BC_Resources::dump_fonts(FILE *fp)
+{
+       for( int i=0; i<fontlist->total; ++i ) {
+               BC_FontEntry *ep = fontlist->values[i];
+               fprintf(fp,"%s = %s\n",ep->displayname,ep->path);
+               fprintf(fp,"  %s:%s:%s:%s:%s:%s:%d:%d:%d:%d:%d:%s:%d:%s:%s:%d\n",
+                       ep->foundry, ep->family, ep->weight, ep->slant, ep->swidth, ep->adstyle,
+                       ep->pixelsize, ep->pointsize, ep->xres, ep->yres, ep->style, ep->spacing,
+                       ep->avg_width, ep->registry, ep->encoding, ep->fixed_style);
+       }
+}
+