commit f92fd0ec53c67499c2f4d0ee50b689cdd159bfbb
parent 620c9ba85452447283d417664a6f04d848517a86
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Sat, 19 Mar 2022 16:29:03 +0100
add support for custom fonts
Diffstat:
12 files changed, 246 insertions(+), 89 deletions(-)
diff --git a/source/jucePlugin/skins/Trancy/VirusC_Trancy.json b/source/jucePlugin/skins/Trancy/VirusC_Trancy.json
@@ -25,7 +25,8 @@
"textHeight" : "36",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1477.7",
"y" : "37.2",
"width" : "391.35",
@@ -39,7 +40,8 @@
"textHeight" : "36",
"alignH" : "R",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1757.85",
"y" : "37.1999",
"width" : "368",
@@ -163,7 +165,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "59",
"y" : "83",
"width" : "120",
@@ -248,7 +251,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "59",
"y" : "291",
"width" : "120",
@@ -355,7 +359,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "59",
"y" : "466",
"width" : "120",
@@ -457,7 +462,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "59",
"y" : "675",
"width" : "120",
@@ -508,7 +514,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "58.99213",
"y" : "884",
"width" : "120",
@@ -1057,7 +1064,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1628",
"y" : "215",
"width" : "172",
@@ -1074,7 +1082,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1935",
"y" : "215",
"width" : "172",
@@ -1091,7 +1100,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1628",
"y" : "329",
"width" : "172",
@@ -1108,7 +1118,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1935",
"y" : "329",
"width" : "172",
@@ -1213,7 +1224,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1845",
"y" : "284",
"width" : "65",
@@ -1582,7 +1594,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "200",
"y" : "59",
"width" : "122",
@@ -1599,7 +1612,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "200",
"y" : "144",
"width" : "122",
@@ -1682,7 +1696,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "200",
"y" : "676",
"width" : "175",
@@ -1869,7 +1884,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "732",
"y" : "59",
"width" : "122",
@@ -1886,7 +1902,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "732",
"y" : "144",
"width" : "122",
@@ -1969,7 +1986,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "732",
"y" : "676",
"width" : "175",
@@ -2054,7 +2072,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1265",
"y" : "60",
"width" : "122",
@@ -2071,7 +2090,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1265",
"y" : "145",
"width" : "122",
@@ -2110,7 +2130,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1128",
"y" : "649",
"width" : "175",
@@ -2127,7 +2148,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1516",
"y" : "57.5",
"width" : "172",
@@ -2144,7 +2166,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1516",
"y" : "145.5",
"width" : "172",
@@ -2178,7 +2201,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1921",
"y" : "58.5",
"width" : "172",
@@ -2195,7 +2219,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1921",
"y" : "146.5",
"width" : "172",
@@ -2229,7 +2254,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1516",
"y" : "286.5",
"width" : "172",
@@ -2246,7 +2272,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1516",
"y" : "374.5",
"width" : "172",
@@ -2280,7 +2307,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1921",
"y" : "287.5",
"width" : "172",
@@ -2297,7 +2325,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1921",
"y" : "375.5",
"width" : "172",
@@ -2331,7 +2360,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1515.5",
"y" : "551.5",
"width" : "172",
@@ -2348,7 +2378,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1515.5",
"y" : "640.5",
"width" : "172",
@@ -2382,7 +2413,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1921.6",
"y" : "600.5",
"width" : "172",
@@ -2416,7 +2448,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1129.5",
"y" : "814.5",
"width" : "172",
@@ -2433,7 +2466,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1129.5",
"y" : "903.5",
"width" : "172",
@@ -2467,7 +2501,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1515.5",
"y" : "862.5",
"width" : "172",
@@ -2501,7 +2536,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1920.7",
"y" : "862.5",
"width" : "172",
@@ -2637,7 +2673,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "661",
"y" : "88",
"width" : "170",
@@ -2654,7 +2691,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1050",
"y" : "87",
"width" : "170",
@@ -2790,7 +2828,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "38",
"y" : "315",
"width" : "170",
@@ -3156,7 +3195,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "162",
"y" : "40",
"width" : "170",
@@ -3173,7 +3213,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "162",
"y" : "137",
"width" : "170",
@@ -3286,7 +3327,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "162",
"y" : "90",
"width" : "170",
@@ -3305,7 +3347,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "35",
"y" : "736",
"width" : "170",
@@ -3509,7 +3552,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1196",
"y" : "643",
"width" : "170",
@@ -3548,7 +3592,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1196",
"y" : "761",
"width" : "170",
@@ -3597,7 +3642,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "131",
"y" : "63",
"width" : "232",
@@ -3665,7 +3711,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "131",
"y" : "181",
"width" : "232",
@@ -3733,7 +3780,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "131",
"y" : "299",
"width" : "232",
@@ -3801,7 +3849,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "131",
"y" : "417",
"width" : "232",
@@ -3869,7 +3918,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "131",
"y" : "535",
"width" : "232",
@@ -3937,7 +3987,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "131",
"y" : "653",
"width" : "232",
@@ -4005,7 +4056,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "131",
"y" : "771",
"width" : "232",
@@ -4073,7 +4125,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "131",
"y" : "889",
"width" : "232",
@@ -4141,7 +4194,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "680",
"y" : "63",
"width" : "232",
@@ -4209,7 +4263,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "680",
"y" : "181",
"width" : "232",
@@ -4277,7 +4332,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "680",
"y" : "299",
"width" : "232",
@@ -4345,7 +4401,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "680",
"y" : "417",
"width" : "232",
@@ -4413,7 +4470,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "680",
"y" : "535",
"width" : "232",
@@ -4481,7 +4539,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "680",
"y" : "653",
"width" : "232",
@@ -4549,7 +4608,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "680",
"y" : "771",
"width" : "232",
@@ -4617,7 +4677,8 @@
"textbutton" : {
"text" : "New Text",
"textHeight" : "30",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "680",
"y" : "889",
"width" : "232",
@@ -4750,7 +4811,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1153",
"y" : "233",
"width" : "177",
@@ -4767,7 +4829,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1359",
"y" : "233",
"width" : "177",
@@ -4784,7 +4847,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1565",
"y" : "233",
"width" : "177",
@@ -4801,7 +4865,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1771",
"y" : "233",
"width" : "177",
@@ -4818,7 +4883,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1153",
"y" : "354",
"width" : "177",
@@ -4835,7 +4901,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1359",
"y" : "354",
"width" : "177",
@@ -4852,7 +4919,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1565",
"y" : "354",
"width" : "177",
@@ -4869,7 +4937,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "2025",
"y" : "58",
"width" : "239",
@@ -4883,7 +4952,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "2025",
"y" : "155",
"width" : "239",
@@ -4897,7 +4967,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1153",
"y" : "535",
"width" : "170",
@@ -4914,7 +4985,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1153",
"y" : "632",
"width" : "170",
@@ -4931,7 +5003,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1698",
"y" : "535",
"width" : "170",
@@ -4948,7 +5021,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1698",
"y" : "632",
"width" : "170",
@@ -5057,7 +5131,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1410",
"y" : "798",
"width" : "174",
@@ -5074,7 +5149,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1410",
"y" : "897",
"width" : "174",
@@ -5091,7 +5167,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1679",
"y" : "798",
"width" : "173",
@@ -5108,7 +5185,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1679",
"y" : "897",
"width" : "173",
@@ -5125,7 +5203,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1906.1",
"y" : "798",
"width" : "173",
@@ -5142,7 +5221,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "1906.1",
"y" : "897",
"width" : "173",
@@ -5171,7 +5251,8 @@
"textHeight" : "20",
"alignH" : "L",
"alignV" : "C",
- "font" : "Register",
+ "fontFile" : "Digital",
+ "fontName" : "Register",
"x" : "37",
"y" : "52",
"width" : "950",
diff --git a/source/juceUiLib/buttonStyle.h b/source/juceUiLib/buttonStyle.h
@@ -7,6 +7,8 @@ namespace genericUI
class ButtonStyle : public UiObjectStyle
{
public:
+ explicit ButtonStyle(Editor& _editor) : UiObjectStyle(_editor) {}
+
void apply(Editor& _editor, const UiObject& _object) override;
void apply(juce::DrawableButton& _button) const;
diff --git a/source/juceUiLib/comboboxStyle.h b/source/juceUiLib/comboboxStyle.h
@@ -7,6 +7,8 @@ namespace genericUI
class ComboboxStyle : public UiObjectStyle
{
public:
+ explicit ComboboxStyle(Editor& _editor) : UiObjectStyle(_editor) {}
+
void apply(juce::ComboBox& _target) const;
private:
diff --git a/source/juceUiLib/editor.cpp b/source/juceUiLib/editor.cpp
@@ -34,6 +34,21 @@ namespace genericUI
m_drawables.insert(std::make_pair(texture, std::move(drawable)));
}
+ std::set<std::string> fonts;
+ m_rootObject->collectVariants(fonts, "fontFile");
+
+ for(const auto& fontFile : fonts)
+ {
+ const auto dataName = fontFile + ".ttf";
+
+ uint32_t dataSize;
+ const auto* data = m_interface.getResourceByFilename(dataName, dataSize);
+ if (!data)
+ throw std::runtime_error("Failed to find font named " + dataName);
+ auto font = juce::Font(juce::Typeface::createSystemTypefaceFor(data, dataSize));
+ m_fonts.insert(std::make_pair(fontFile, std::move(font)));
+ }
+
m_rootObject->createJuceTree(*this);
m_scale = m_rootObject->getPropertyFloat("scale", 1.0f);
@@ -51,6 +66,14 @@ namespace genericUI
return existing ? existing->createCopy() : nullptr;
}
+ const juce::Font& Editor::getFont(const std::string& _fontFile)
+ {
+ const auto it = m_fonts.find(_fontFile);
+ if(it == m_fonts.end())
+ throw std::runtime_error("Unable to find font named " + _fontFile);
+ return it->second;
+ }
+
void Editor::registerComponent(const std::string& _name, juce::Component* _component)
{
const auto itExisting = m_componentsByName.find(_name);
diff --git a/source/juceUiLib/editor.h b/source/juceUiLib/editor.h
@@ -21,6 +21,7 @@ namespace genericUI
juce::Drawable* getImageDrawable(const std::string& _texture);
std::unique_ptr<juce::Drawable> createImageDrawable(const std::string& _texture);
+ const juce::Font& getFont(const std::string& _fontFile);
void registerComponent(const std::string& _name, juce::Component* _component);
@@ -55,6 +56,8 @@ namespace genericUI
EditorInterface& m_interface;
std::map<std::string, std::unique_ptr<juce::Drawable>> m_drawables;
+ std::map<std::string, juce::Font> m_fonts;
+
std::unique_ptr<UiObject> m_rootObject;
std::map<std::string, std::vector<juce::Component*>> m_componentsByName;
diff --git a/source/juceUiLib/hyperlinkbuttonStyle.h b/source/juceUiLib/hyperlinkbuttonStyle.h
@@ -12,6 +12,8 @@ namespace genericUI
class HyperlinkButtonStyle : public TextButtonStyle
{
public:
+ explicit HyperlinkButtonStyle(Editor& _editor) : TextButtonStyle(_editor) {}
+
void apply(juce::HyperlinkButton& _target) const;
};
}
diff --git a/source/juceUiLib/labelStyle.h b/source/juceUiLib/labelStyle.h
@@ -7,6 +7,8 @@ namespace genericUI
class LabelStyle : public UiObjectStyle
{
public:
+ explicit LabelStyle(Editor& _editor) : UiObjectStyle(_editor) {}
+
void apply(juce::Label& _target) const;
};
}
diff --git a/source/juceUiLib/rotaryStyle.h b/source/juceUiLib/rotaryStyle.h
@@ -8,6 +8,10 @@ namespace genericUI
{
class RotaryStyle : public UiObjectStyle
{
+ public:
+ explicit RotaryStyle(Editor& _editor) : UiObjectStyle(_editor) {}
+
+ private:
void drawRotarySlider(juce::Graphics&, int x, int y, int width, int height, float sliderPosProportional, float rotaryStartAngle, float rotaryEndAngle, juce::Slider&) override;
};
}
diff --git a/source/juceUiLib/textbuttonStyle.h b/source/juceUiLib/textbuttonStyle.h
@@ -6,6 +6,10 @@ namespace genericUI
{
class TextButtonStyle : public UiObjectStyle
{
+ public:
+ explicit TextButtonStyle(Editor& _editor) : UiObjectStyle(_editor) {}
+
+ private:
void drawButtonBackground(juce::Graphics&, juce::Button&, const juce::Colour& backgroundColour, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override;
public:
void apply(juce::Button& _target) const;
diff --git a/source/juceUiLib/uiObject.cpp b/source/juceUiLib/uiObject.cpp
@@ -75,7 +75,7 @@ namespace genericUI
apply(_editor, static_cast<juce::Component&>(_target));
- createStyle(_editor, _target, new RotaryStyle());
+ createStyle(_editor, _target, new RotaryStyle(_editor));
bindParameter(_editor, _target);
}
@@ -83,7 +83,7 @@ namespace genericUI
void UiObject::apply(Editor& _editor, juce::ComboBox& _target)
{
apply(_editor, static_cast<juce::Component&>(_target));
- auto* s = new ComboboxStyle();
+ auto* s = new ComboboxStyle(_editor);
createStyle(_editor, _target, s);
bindParameter(_editor, _target);
s->apply(_target);
@@ -92,7 +92,7 @@ namespace genericUI
void UiObject::apply(Editor& _editor, juce::DrawableButton& _target)
{
apply(_editor, static_cast<juce::Component&>(_target));
- auto* s = new ButtonStyle();
+ auto* s = new ButtonStyle(_editor);
createStyle(_editor, _target, s);
s->apply(_target);
bindParameter(_editor, _target);
@@ -101,7 +101,7 @@ namespace genericUI
void UiObject::apply(Editor& _editor, juce::Label& _target)
{
apply(_editor, static_cast<juce::Component&>(_target));
- auto* s = new LabelStyle();
+ auto* s = new LabelStyle(_editor);
createStyle(_editor, _target, s);
s->apply(_target);
}
@@ -109,7 +109,7 @@ namespace genericUI
void UiObject::apply(Editor& _editor, juce::TextButton& _target)
{
apply(_editor, static_cast<juce::Component&>(_target));
- auto* s = new TextButtonStyle();
+ auto* s = new TextButtonStyle(_editor);
createStyle(_editor, _target, s);
s->apply(_target);
}
@@ -117,7 +117,7 @@ namespace genericUI
void UiObject::apply(Editor& _editor, juce::HyperlinkButton& _target)
{
apply(_editor, static_cast<juce::Component&>(_target));
- auto* s = new HyperlinkButtonStyle();
+ auto* s = new HyperlinkButtonStyle(_editor);
createStyle(_editor, _target, s);
s->apply(_target);
}
diff --git a/source/juceUiLib/uiObjectStyle.cpp b/source/juceUiLib/uiObjectStyle.cpp
@@ -5,7 +5,7 @@
namespace genericUI
{
- UiObjectStyle::UiObjectStyle() = default;
+ UiObjectStyle::UiObjectStyle(Editor& _editor) : m_editor(_editor) {}
void UiObjectStyle::setTileSize(int _w, int _h)
{
@@ -72,13 +72,23 @@ namespace genericUI
m_align = m_align.getFlags() | a.getFlags();
}
+ m_fontFile = _object.getProperty("fontFile");
+ m_fontName = _object.getProperty("fontName");
+
m_bold = _object.getPropertyInt("bold") != 0;
m_italic = _object.getPropertyInt("italic") != 0;
+
m_url = _object.getProperty("url");
}
juce::Font UiObjectStyle::getComboBoxFont(juce::ComboBox& _comboBox)
{
+ if(!m_fontFile.empty())
+ {
+ auto font = juce::Font(m_editor.getFont(m_fontFile).getTypeface());
+ applyFontProperties(font);
+ return font;
+ }
auto font = LookAndFeel_V4::getComboBoxFont(_comboBox);
applyFontProperties(font);
return font;
@@ -86,6 +96,12 @@ namespace genericUI
juce::Font UiObjectStyle::getLabelFont(juce::Label& _label)
{
+ if(!m_fontFile.empty())
+ {
+ auto font = juce::Font(m_editor.getFont(m_fontFile).getTypeface());
+ applyFontProperties(font);
+ return font;
+ }
auto font = LookAndFeel_V4::getLabelFont(_label);
applyFontProperties(font);
return font;
@@ -93,6 +109,12 @@ namespace genericUI
juce::Font UiObjectStyle::getPopupMenuFont()
{
+ if(!m_fontFile.empty())
+ {
+ auto font = juce::Font(m_editor.getFont(m_fontFile).getTypeface());
+ applyFontProperties(font);
+ return font;
+ }
auto font = LookAndFeel_V4::getPopupMenuFont();
applyFontProperties(font);
return font;
@@ -100,6 +122,12 @@ namespace genericUI
juce::Font UiObjectStyle::getTextButtonFont(juce::TextButton& _textButton, int buttonHeight)
{
+ if(!m_fontFile.empty())
+ {
+ auto font = juce::Font(m_editor.getFont(m_fontFile).getTypeface());
+ applyFontProperties(font);
+ return font;
+ }
auto font = LookAndFeel_V4::getTextButtonFont(_textButton, buttonHeight);
applyFontProperties(font);
return font;
diff --git a/source/juceUiLib/uiObjectStyle.h b/source/juceUiLib/uiObjectStyle.h
@@ -10,7 +10,7 @@ namespace genericUI
class UiObjectStyle : public juce::LookAndFeel_V4
{
public:
- UiObjectStyle();
+ UiObjectStyle(Editor& _editor);
void setTileSize(int _w, int _h);
void setDrawable(juce::Drawable* _drawable);
@@ -26,15 +26,21 @@ namespace genericUI
void applyFontProperties(juce::Font& _font) const;
+ Editor& m_editor;
+
int m_tileSizeX = 0;
int m_tileSizeY = 0;
juce::Drawable* m_drawable = nullptr;
+
+ std::string m_fontFile;
+ std::string m_fontName;
int m_textHeight = 0;
std::string m_text;
juce::Colour m_color = juce::Colour(0xffffffff);
juce::Justification m_align = 0;
bool m_bold = false;
bool m_italic = false;
+
std::string m_url;
};
}