From 0faf38bec8b391387df02cac1a9382b73289cfc6 Mon Sep 17 00:00:00 2001 From: regorxxx Date: Wed, 22 Feb 2023 20:52:47 +0100 Subject: [PATCH] - UI: default fonts (buttons, icons, toolbar text and tooltip) may now be changed at '[foobar profile]\js_data\presets\global\globFonts.json'. --- buttons/buttons_others_main_menu.js | 4 +-- buttons/buttons_playlist_tools.js | 4 +-- .../buttons_playlist_tools_macro_custom.js | 2 +- .../buttons_playlist_tools_submenu_custom.js | 4 +-- .../buttons_search_by_tags_combinations.js | 4 +-- buttons/buttons_search_by_tags_queries.js | 4 +-- buttons/toolbars/_buttons_toolbar.js | 6 ++-- buttons_toolbar.js | 6 ++-- helpers/buttons_xxx.js | 25 ++++++++++---- helpers/helpers_xxx.js | 33 +++++++++++++------ helpers/helpers_xxx_UI.js | 4 +-- helpers/helpers_xxx_global.js | 21 ++++++++++-- helpers/helpers_xxx_so.js | 3 ++ 13 files changed, 82 insertions(+), 38 deletions(-) diff --git a/buttons/buttons_others_main_menu.js b/buttons/buttons_others_main_menu.js index 65e5a3bc..c678b3ba 100644 --- a/buttons/buttons_others_main_menu.js +++ b/buttons/buttons_others_main_menu.js @@ -1,5 +1,5 @@ 'use strict'; -//17/02/23 +//22/02/23 /* Main Menu shortcut @@ -44,7 +44,7 @@ buttonsBar.list.push(newButtonsProperties); { var newButton = { - 'Main Menu': new themedButton({x: 0, y: 0, w: _gr.CalcTextWidth(newButtonsProperties.customName[1], _gdiFont('Segoe UI', 12 * buttonsBar.config.scale)) + 30 * _scale(0.7, false), h: 22}, newButtonsProperties.customName[1], function (mask) { + 'Main Menu': new themedButton({x: 0, y: 0, w: _gr.CalcTextWidth(newButtonsProperties.customName[1], _gdiFont(globFonts.button.name, globFonts.button.size * buttonsBar.config.scale)) + 30 * _scale(0.7, false), h: 22}, newButtonsProperties.customName[1], function (mask) { const list = JSON.parse(this.buttonsProperties.entries[1]); const unloadCall = JSON.parse(this.buttonsProperties.unloadCall[1]); const indicator = JSON.parse(this.buttonsProperties.indicator[1]); diff --git a/buttons/buttons_playlist_tools.js b/buttons/buttons_playlist_tools.js index eb95e559..e1ab2155 100644 --- a/buttons/buttons_playlist_tools.js +++ b/buttons/buttons_playlist_tools.js @@ -1,5 +1,5 @@ 'use strict'; -//08/02/23 +//22/02/23 /* Playlist Tools Menu @@ -47,7 +47,7 @@ var newButtonsProperties = { } addButton({ - 'Playlist Tools': new themedButton({x: 0, y: 0, w: 98, h: 22}, 'Playlist Tools', function (mask) { + 'Playlist Tools': new themedButton({x: 0, y: 0, w: _gr.CalcTextWidth('Playlist Tools', _gdiFont(globFonts.button.name, globFonts.button.size * buttonsBar.config.scale)) + 40 * _scale(0.7, false), h: 22}, 'Playlist Tools', function (mask) { if (!defaultArgs.parent) {defaultArgs.parent = this;} // Register this button as parent if (mask === MK_SHIFT) { // Enable/disable menus menuAlt.btn_up(this.currX, this.currY + this.currH); diff --git a/buttons/buttons_playlist_tools_macro_custom.js b/buttons/buttons_playlist_tools_macro_custom.js index bc4ed42f..17252d54 100644 --- a/buttons/buttons_playlist_tools_macro_custom.js +++ b/buttons/buttons_playlist_tools_macro_custom.js @@ -23,7 +23,7 @@ newButtonsProperties = getPropertiesPairs(newButtonsProperties, prefix, 0); // A buttonsBar.list.push(newButtonsProperties); addButton({ - 'Playlist Tools Macros (CUSTOM)': new themedButton({x: 0, y: 0, w: _gr.CalcTextWidth(newButtonsProperties.customName[1], _gdiFont('Segoe UI', 12 * buttonsBar.config.scale)) + 30, h: 22}, newButtonsProperties.customName[1], function (mask) { + 'Playlist Tools Macros (CUSTOM)': new themedButton({x: 0, y: 0, w: _gr.CalcTextWidth(newButtonsProperties.customName[1], _gdiFont(globFonts.button.name, globFonts.button.size * buttonsBar.config.scale)) + 30, h: 22}, newButtonsProperties.customName[1], function (mask) { if (isPlaylistToolsLoaded()) { if (mask === MK_SHIFT) { const configMenu = new _menu(); diff --git a/buttons/buttons_playlist_tools_submenu_custom.js b/buttons/buttons_playlist_tools_submenu_custom.js index 3051bea2..7b986463 100644 --- a/buttons/buttons_playlist_tools_submenu_custom.js +++ b/buttons/buttons_playlist_tools_submenu_custom.js @@ -1,5 +1,5 @@ 'use strict'; -//21/02/23 +//22/02/23 /* Playlist Tools Submenu Custom @@ -24,7 +24,7 @@ newButtonsProperties = getPropertiesPairs(newButtonsProperties, prefix); // And buttonsBar.list.push(newButtonsProperties); addButton({ - 'Playlist Tools SubMenu (CUSTOM)': new themedButton({x: 0, y: 0, w: _gr.CalcTextWidth(newButtonsProperties.customName[1], _gdiFont('Segoe UI', 12 * buttonsBar.config.scale)) + 30, h: 22}, newButtonsProperties.customName[1], function (mask) { + 'Playlist Tools SubMenu (CUSTOM)': new themedButton({x: 0, y: 0, w: _gr.CalcTextWidth(newButtonsProperties.customName[1], _gdiFont(globFonts.button.name, globFonts.button.size * buttonsBar.config.scale)) + 30, h: 22}, newButtonsProperties.customName[1], function (mask) { if (isPlaylistToolsLoaded()) { const buttonMenu = new _menu(); const mainMenu = menu.getMenus()[0]; diff --git a/buttons/buttons_search_by_tags_combinations.js b/buttons/buttons_search_by_tags_combinations.js index 8d2471b8..d8a219a7 100644 --- a/buttons/buttons_search_by_tags_combinations.js +++ b/buttons/buttons_search_by_tags_combinations.js @@ -1,5 +1,5 @@ 'use strict'; -//08/02/23 +//22/02/23 /* Search same by v 1.0 24/08/22 @@ -87,7 +87,7 @@ newButtonsProperties = getPropertiesPairs(newButtonsProperties, prefix, 0); buttonsBar.list.push(newButtonsProperties); addButton({ - 'Search Same By Tags (Combinations)': new themedButton({x: 0, y: 0, w: _gr.CalcTextWidth(newButtonsProperties.customName[1], _gdiFont('Segoe UI', 12 * buttonsBar.config.scale)) + 30, h: 22}, newButtonsProperties.customName[1], function (mask) { + 'Search Same By Tags (Combinations)': new themedButton({x: 0, y: 0, w: _gr.CalcTextWidth(newButtonsProperties.customName[1], _gdiFont(globFonts.button.name, globFonts.button.size * buttonsBar.config.scale)) + 30, h: 22}, newButtonsProperties.customName[1], function (mask) { if (mask === MK_SHIFT) { const oldName = this.buttonsProperties.customName[1].toString(); settingsMenu(this, true, ['buttons_search_by_tags_combinations.js'], {bAdvTitle: {popup: globRegExp.title.desc}}).btn_up(this.currX, this.currY + this.currH); diff --git a/buttons/buttons_search_by_tags_queries.js b/buttons/buttons_search_by_tags_queries.js index e1a0ad20..4c3678b9 100644 --- a/buttons/buttons_search_by_tags_queries.js +++ b/buttons/buttons_search_by_tags_queries.js @@ -1,5 +1,5 @@ 'use strict'; -//08/02/23 +//22/02/23 /* Search n tracks (randomly) on library with the same tag(s) than the current selected track. @@ -31,7 +31,7 @@ newButtonsProperties = getPropertiesPairs(newButtonsProperties, prefix, 0); buttonsBar.list.push(newButtonsProperties); addButton({ - 'Search Same By Tags (Queries)': new themedButton({x: 0, y: 0, w: _gr.CalcTextWidth(newButtonsProperties.customName[1], _gdiFont('Segoe UI', 12)) + 30, h: 22}, newButtonsProperties.customName[1], function (mask) { + 'Search Same By Tags (Queries)': new themedButton({x: 0, y: 0, w: _gr.CalcTextWidth(newButtonsProperties.customName[1], _gdiFont(globFonts.button.name, globFonts.button.size * buttonsBar.config.scale)) + 30, h: 22}, newButtonsProperties.customName[1], function (mask) { if (mask === MK_SHIFT) { const oldName = this.buttonsProperties.customName[1].toString(); settingsMenu(this, true, ['buttons_search_by_tags_queries.js'], {bAdvTitle: {popup: globRegExp.title.desc}}).btn_up(this.currX, this.currY + this.currH); diff --git a/buttons/toolbars/_buttons_toolbar.js b/buttons/toolbars/_buttons_toolbar.js index 1b2a252c..a32645ab 100644 --- a/buttons/toolbars/_buttons_toolbar.js +++ b/buttons/toolbars/_buttons_toolbar.js @@ -1,5 +1,5 @@ 'use strict'; -//21/02/23 +//22/02/23 /* Playlist Tools: Buttons Toolbar Loads any button found on the buttons folder. Just load this file and add your desired buttons via R. Click. @@ -40,7 +40,7 @@ var bLoadTags = true; // Note this must be added before loading helpers! See but else {dependencies.forEach((file) => {include('buttons\\' + file);});} } -try {window.DefineScript('Playlist Tools: Buttons Bar', {author:'XXX', version: '3.0.0-beta.18', features: {drag_n_drop: false}});} catch (e) {} //May be loaded along other buttons +try {window.DefineScript('Playlist Tools: Buttons Bar', {author:'XXX', version: '3.0.0-beta.19', features: {drag_n_drop: false}});} catch (e) {} //May be loaded along other buttons let barProperties = { name: ['Name of config json file', 'buttons_' + randomString(5)], @@ -168,7 +168,7 @@ loadButtonsFile(true) && includeButtons(); addEventListener('on_paint', (gr) => { if (!buttonsPath.length) { - gr.GdiDrawText('L. Click to load a preset / R. Click to add buttons manually', _gdiFont('Segoe UI', _scale(10)), 0xFF000000, 0, 0, window.Width, window.Height, DT_VCENTER | DT_CENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX); // Font is being cached, no problems here... + gr.GdiDrawText('L. Click to load a preset / R. Click to add buttons manually', _gdiFont(globFonts.standard.name, _scale(globFonts.standard.size)), 0xFF000000, 0, 0, window.Width, window.Height, DT_VCENTER | DT_CENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX); // Font is being cached, no problems here... } }); diff --git a/buttons_toolbar.js b/buttons_toolbar.js index 8c343a9d..df232cf0 100644 --- a/buttons_toolbar.js +++ b/buttons_toolbar.js @@ -1,5 +1,5 @@ 'use strict'; -//21/02/23 +//22/02/23 /* Playlist Tools: Buttons Toolbar Loads any button found on the buttons folder. Just load this file and add your desired buttons via R. Click. @@ -40,7 +40,7 @@ var bLoadTags = true; // Note this must be added before loading helpers! See but else {dependencies.forEach((file) => {include('buttons\\' + file);});} } -try {window.DefineScript('Playlist Tools: Buttons Bar', {author:'XXX', version: '3.0.0-beta.18', features: {drag_n_drop: false}});} catch (e) {} //May be loaded along other buttons +try {window.DefineScript('Playlist Tools: Buttons Bar', {author:'XXX', version: '3.0.0-beta.19', features: {drag_n_drop: false}});} catch (e) {} //May be loaded along other buttons let barProperties = { name: ['Name of config json file', 'buttons_' + randomString(5)], @@ -168,7 +168,7 @@ loadButtonsFile(true) && includeButtons(); addEventListener('on_paint', (gr) => { if (!buttonsPath.length) { - gr.GdiDrawText('L. Click to load a preset / R. Click to add buttons manually', _gdiFont('Segoe UI', _scale(10)), 0xFF000000, 0, 0, window.Width, window.Height, DT_VCENTER | DT_CENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX); // Font is being cached, no problems here... + gr.GdiDrawText('L. Click to load a preset / R. Click to add buttons manually', _gdiFont(globFonts.standard.name, _scale(globFonts.standard.size)), 0xFF000000, 0, 0, window.Width, window.Height, DT_VCENTER | DT_CENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX); // Font is being cached, no problems here... } }); diff --git a/helpers/buttons_xxx.js b/helpers/buttons_xxx.js index 5748bd68..f26b1f7f 100644 --- a/helpers/buttons_xxx.js +++ b/helpers/buttons_xxx.js @@ -1,5 +1,5 @@ 'use strict'; -//16/02/23 +//22/02/23 include('helpers_xxx_basic_js.js'); include('helpers_xxx_prototypes.js'); @@ -48,7 +48,7 @@ buttonsBar.propertiesPrefixes = new Set(); // Global properties names prefixes buttonsBar.buttons = {}; // Global list // Others (internal use) buttonsBar.oldButtonCoordinates = {x: 0, y: 0, w: 0, h: 0}; // To store coordinates of previous buttons when drawing -buttonsBar.tooltipButton = new _tt(null, 'Segoe UI', _scale(10), 600); // Global tooltip +buttonsBar.tooltipButton = new _tt(null, globFonts.tooltip.name, _scale(globFonts.tooltip.size), 600); // Global tooltip buttonsBar.gDown = false; buttonsBar.curBtn = null; buttonsBar.useThemeManager = function useThemeManager() { @@ -85,7 +85,20 @@ function calcNextButtonCoordinates(coord, buttonOrientation = buttonsBar.config. return newCoordinates; } -function themedButton(coordinates, text, func, state, gFont = _gdiFont('Segoe UI', 12 * buttonsBar.config.scale), description, prefix = '', buttonsProperties = {}, icon = null, gFontIcon = _gdiFont('FontAwesome', 12 * buttonsBar.config.scale), variables = null, listener = null) { +function themedButton( + coordinates, + text, + func, + state, + gFont = _gdiFont(globFonts.button.name, globFonts.button.size * buttonsBar.config.scale), + description, + prefix = '', + buttonsProperties = {}, + icon = null, + gFontIcon = _gdiFont(globFonts.buttonIcon.name, globFonts.buttonIcon.size * buttonsBar.config.scale), + variables = null, + listener = null + ) { this.name = ''; this.state = state ? state : buttonStates.normal; this.animation = []; /* {bActive, condition, animStep} */ @@ -428,7 +441,7 @@ function themedButton(coordinates, text, func, state, gFont = _gdiFont('Segoe UI }; this.adjustButtonWidth = function (newName, offset = 30) { - this.w = _gr.CalcTextWidth(newName, _gdiFont('Segoe UI', 12 * buttonsBar.config.scale)) + offset; + this.w = _gr.CalcTextWidth(newName, this.gFont) + offset; this.w *= buttonsBar.config.scale; }; @@ -445,10 +458,10 @@ function themedButton(coordinates, text, func, state, gFont = _gdiFont('Segoe UI this.h *= newScale; this.currH *= newScale; this.currW *= newScale; - this.gFont = _gdiFont(this.gFont.Name, 12 * scale); + this.gFont = _gdiFont(this.gFont.Name, this.gFont.Size * newScale); this.textWidth = isFunction(this.text) ? (parent) => {return _gr.CalcTextWidth(this.text(parent), this.gFont);} : _gr.CalcTextWidth(this.text, this.gFont); if (!this.iconImage) { - this.gFontIcon = _gdiFont(this.gFontIcon.Name, 12 * scale); + this.gFontIcon = _gdiFont(this.gFontIcon.Name, this.gFontIcon.Size * newScale); this.iconWidth = isFunction(this.icon) ? (parent) => {return _gr.CalcTextWidth(this.icon(parent), this.gFontIcon);} : _gr.CalcTextWidth(this.icon, this.gFontIcon); } }; diff --git a/helpers/helpers_xxx.js b/helpers/helpers_xxx.js index 7bd3daef..d0328c8b 100644 --- a/helpers/helpers_xxx.js +++ b/helpers/helpers_xxx.js @@ -1,5 +1,5 @@ 'use strict'; -//19/02/23 +//22/02/23 // Folders const folders = {}; @@ -21,7 +21,6 @@ include(fb.ComponentPath + 'docs\\Flags.js'); include('helpers_xxx_basic_js.js'); include('helpers_xxx_console.js'); include('helpers_xxx_foobar.js'); -include('helpers_xxx_global.js'); include('helpers_xxx_so.js'); /* @@ -40,18 +39,32 @@ console.File = fb.ProfilePath + 'console.log'; // Edit here to change logging fi console.MaxSize = 5000000; // File size, in bytes. Setting to zero or null disables logging too /* - Global tags, queries, RegExp + SO features +*/ +const soFeat = getSoFeatures(); +if (Object.values(soFeat).slice(0, -1).some((val) => {return !val;})) { // Retry once if something fails + new Promise((resolve) => {setTimeout(getSoFeatures, 1000); resolve(true);}).then((resolve) => {initCheckFeatures(soFeat);}); +} else {initCheckFeatures(soFeat);} + +/* + Global tags, queries, RegExp, Fonts */ +include('helpers_xxx_global.js'); // Load user files used at helpers_xxx_global.js loadUserDefFile(globTags); loadUserDefFile(globQuery); loadUserDefFile(globRegExp); +loadUserDefFile(globFonts); addGlobTags(); -/* - SO features -*/ -const soFeat = getSoFeatures(); -if (Object.values(soFeat).slice(0, -1).some((val) => {return !val;})) { // Retry once if something fails - new Promise((resolve) => {setTimeout(getSoFeatures, 1000); resolve(true);}).then((resolve) => {initCheckFeatures(soFeat);}); -} else {initCheckFeatures(soFeat);} \ No newline at end of file +// Check user-set fonts +Object.keys(globFonts).forEach((key) => { + if (!key.startsWith('_') && !utils.CheckFont(globFonts[key].name)) { + fb.ShowPopupMessage( + 'Missing font set at:' + + '\n' + globFonts._file + + '\n\n\t-' + key + ':\t' + globFonts[key].name + , 'Global fonts' + ); + } +}); \ No newline at end of file diff --git a/helpers/helpers_xxx_UI.js b/helpers/helpers_xxx_UI.js index bbc442b0..9d9bf026 100644 --- a/helpers/helpers_xxx_UI.js +++ b/helpers/helpers_xxx_UI.js @@ -1,5 +1,5 @@ 'use strict'; -//20/02/23 +//22/02/23 include(fb.ComponentPath + 'docs\\Flags.js'); include('helpers_xxx.js'); @@ -197,7 +197,7 @@ function removeIdFromStr(nameId) { Tooltip */ -function _tt(value, font = 'Segoe UI', fontSize = _scale(10), width = 600) { +function _tt(value, font = globFonts.tooltip.name, fontSize = _scale(globFonts.tooltip.size), width = 600) { this.SetValue = (value, bForceActivate = false) => { if (!this.tooltip && !this.init()) {return;} if (value === null) { diff --git a/helpers/helpers_xxx_global.js b/helpers/helpers_xxx_global.js index a2e5185c..8dff2783 100644 --- a/helpers/helpers_xxx_global.js +++ b/helpers/helpers_xxx_global.js @@ -1,5 +1,5 @@ 'use strict'; -//09/01/23 +//22/02/23 /* Global tags, queries, RegExp @@ -9,7 +9,7 @@ function loadUserDefFile(def) { if (_isFile(def._file)) { const data = _jsonParseFileCheck(def._file, 'User definition file', window.Name, utf8); if (data) { - if (def._type === 'TF' || def._type === 'Query') { + if (def._type === 'TF' || def._type === 'Query' || def._type === 'Font') { for (let key in data) { if (def.hasOwnProperty(key)) { def[key] = data[key]; @@ -123,4 +123,19 @@ const globRegExp = { desc: 'Replaces verb-in words with verb-ing versions' } }; -Object.keys(globRegExp).filter((k) => !k.startsWith('_')).forEach((k) => globRegExp[k].default = globRegExp[k].re); // Add default values \ No newline at end of file +Object.keys(globRegExp).filter((k) => !k.startsWith('_')).forEach((k) => globRegExp[k].default = globRegExp[k].re); // Add default values + +// Fonts: user replaceable with a presets file at folders.data +const globFonts = { + _type: 'Font', + _file: folders.userPresetsGlobal + 'globFonts.json', + _description: 'Fonts used by scripts at multiple places on UI. File is loaded on the fly at startup, so no hard-saving on properties is involved (thus only requiring a panel reload to use the new values). The fallback font can not be changed, is forced by SMP/Foobar.', + _usage: 'Most users will probably not need to touch these. Adding a not-installed font should fallback into the default one (Segoe UI). Special characters like single quotes (\') or backslash (\\) must be properly escaped.', + _fallback: {name: 'Segoe UI', size: 10}, + tooltip: {name: !soFeat.popup ? 'Arial Unicode MS' : 'Tahoma', size: 10}, + button: {name: 'Segoe UI', size: 12}, + buttonIcon: {name: 'FontAwesome', size: 12}, + standard: {name: 'Segoe UI', size: 10}, + standardMedium: {name: 'Segoe UI', size: 12}, + standardBig: {name: 'Segoe UI', size: 15} +}; \ No newline at end of file diff --git a/helpers/helpers_xxx_so.js b/helpers/helpers_xxx_so.js index ffc6b430..9faa87b1 100644 --- a/helpers/helpers_xxx_so.js +++ b/helpers/helpers_xxx_so.js @@ -93,6 +93,9 @@ function checkSoFeatures(soFeat) { } else if (!soFeat.segoe) { fb.ShowPopupMessage('Found an issue on current installation:\nSegoe UI font is missing.\n\nFix: install missing font.\n' + 'https://github.com/mrbvrz/segoe-ui-linux', 'SO features'); bPass = false; + } else if (!soFeat.arialU) { + fb.ShowPopupMessage('Found an issue on current installation:\nArial Unicode MS font is missing.\n\nFix: install missing font.\n' + 'https://github.com/mrbvrz/segoe-ui-linux', 'SO features'); + bPass = false; } return bPass; }