Skip to content

Commit

Permalink
- UI: default fonts (buttons, icons, toolbar text and tooltip) may no…
Browse files Browse the repository at this point in the history
…w be changed at '[foobar profile]\js_data\presets\global\globFonts.json'.
  • Loading branch information
regorxxx committed Feb 22, 2023
1 parent fa7fb90 commit 0faf38b
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 38 deletions.
4 changes: 2 additions & 2 deletions buttons/buttons_others_main_menu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
//17/02/23
//22/02/23

/*
Main Menu shortcut
Expand Down Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions buttons/buttons_playlist_tools.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
//08/02/23
//22/02/23

/*
Playlist Tools Menu
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion buttons/buttons_playlist_tools_macro_custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions buttons/buttons_playlist_tools_submenu_custom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
//21/02/23
//22/02/23

/*
Playlist Tools Submenu Custom
Expand All @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions buttons/buttons_search_by_tags_combinations.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
//08/02/23
//22/02/23

/*
Search same by v 1.0 24/08/22
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions buttons/buttons_search_by_tags_queries.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions buttons/toolbars/_buttons_toolbar.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)],
Expand Down Expand Up @@ -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...
}
});

Expand Down
6 changes: 3 additions & 3 deletions buttons_toolbar.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)],
Expand Down Expand Up @@ -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...
}
});

Expand Down
25 changes: 19 additions & 6 deletions helpers/buttons_xxx.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
//16/02/23
//22/02/23

include('helpers_xxx_basic_js.js');
include('helpers_xxx_prototypes.js');
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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} */
Expand Down Expand Up @@ -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;
};

Expand All @@ -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);
}
};
Expand Down
33 changes: 23 additions & 10 deletions helpers/helpers_xxx.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
//19/02/23
//22/02/23

// Folders
const folders = {};
Expand All @@ -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');

/*
Expand All @@ -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);}
// 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'
);
}
});
4 changes: 2 additions & 2 deletions helpers/helpers_xxx_UI.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
//20/02/23
//22/02/23

include(fb.ComponentPath + 'docs\\Flags.js');
include('helpers_xxx.js');
Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 18 additions & 3 deletions helpers/helpers_xxx_global.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
//09/01/23
//22/02/23

/*
Global tags, queries, RegExp
Expand All @@ -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];
Expand Down Expand Up @@ -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
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}
};
3 changes: 3 additions & 0 deletions helpers/helpers_xxx_so.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0faf38b

Please sign in to comment.