PluginSkin.cpp 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. #include "ui/PluginSkin.h"
  2. #include "core/Effects.h"
  3. #include "ui/I18n.h"
  4. #include "ui/WindowOwner.h"
  5. #include <cstdint>
  6. #include <cstring>
  7. #include <unordered_map>
  8. #if JUCE_WINDOWS
  9. extern "C" __declspec (dllimport) int __stdcall SystemParametersInfoW (unsigned int, unsigned int, void*, unsigned int);
  10. static int lynxSystemParametersInfoW (unsigned int a, unsigned int b, void* c, unsigned int d) { return SystemParametersInfoW (a, b, c, d); }
  11. #endif
  12. namespace lynx::skin
  13. {
  14. namespace
  15. {
  16. constexpr float pi = juce::MathConstants<float>::pi;
  17. constexpr float arcStart = -pi * 0.75f;
  18. constexpr float arcRange = pi * 1.5f;
  19. juce::Path arcPath (juce::Point<float> c, float r, float from, float to)
  20. {
  21. juce::Path p;
  22. p.addCentredArc (c.x, c.y, r, r, 0.0f, juce::jmin (from, to), juce::jmax (from, to), true);
  23. return p;
  24. }
  25. juce::PathStrokeType roundStroke (float w)
  26. {
  27. return juce::PathStrokeType (w, juce::PathStrokeType::curved, juce::PathStrokeType::rounded);
  28. }
  29. } // namespace
  30. juce::Colour accentFor (EffectKind kind)
  31. {
  32. switch (kind)
  33. {
  34. case EffectKind::reverb: case EffectKind::reeverb2: case EffectKind::reeverb1: case EffectKind::luxeVerb: case EffectKind::convolver:
  35. case EffectKind::epochVerb: case EffectKind::atrium: case EffectKind::foilPlate: case EffectKind::nebula: case EffectKind::halo:
  36. case EffectKind::horizon:
  37. return colour::violet;
  38. case EffectKind::delay: case EffectKind::fruityDelay2: case EffectKind::fruityDelay3: case EffectKind::fruityDelayBank:
  39. case EffectKind::multibandDelay: case EffectKind::echoform: case EffectKind::spiralEcho: case EffectKind::geminiDoubler:
  40. case EffectKind::newtime:
  41. return colour::azure;
  42. case EffectKind::chorus: case EffectKind::fruityChorus: case EffectKind::hyperChorus: case EffectKind::vintageChorus:
  43. case EffectKind::fruityFlanger: case EffectKind::fruityFlangus: case EffectKind::fruityPhaser: case EffectKind::vintagePhaser:
  44. case EffectKind::orbit: case EffectKind::latticeMod: case EffectKind::autoPan: case EffectKind::fruityPanOMatic:
  45. case EffectKind::effector: case EffectKind::freqShift: case EffectKind::grossBeat: case EffectKind::volumeGate: case EffectKind::rhythmGain:
  46. return colour::teal;
  47. case EffectKind::compressor: case EffectKind::limiter: case EffectKind::fruityLimiter: case EffectKind::fruityCompressor:
  48. case EffectKind::fruityMultiband: case EffectKind::crestCompressor: case EffectKind::prismMultiband: case EffectKind::sentryGate:
  49. case EffectKind::apexLimiter: case EffectKind::glowLeveler: case EffectKind::hushDeEsser: case EffectKind::transientProcessor: case EffectKind::shellChannel:
  50. case EffectKind::maximus: case EffectKind::peakController:
  51. return colour::amber;
  52. case EffectKind::distortion: case EffectKind::fruityBloodOverdrive: case EffectKind::fruityFastDist: case EffectKind::ember: case EffectKind::kilnChannel: case EffectKind::fretChannel:
  53. case EffectKind::hardcore: case EffectKind::distructor: case EffectKind::fruityWaveShaper: case EffectKind::fruitySoftClipper:
  54. case EffectKind::lofi: case EffectKind::squeeze:
  55. return colour::ember;
  56. case EffectKind::lynxTune: case EffectKind::pitchCorrect: case EffectKind::pitchShift: case EffectKind::flPitchShifter:
  57. case EffectKind::vocoder: case EffectKind::vocodex: case EffectKind::quellDenoiser: case EffectKind::aether: case EffectKind::newtone:
  58. case EffectKind::voiceShift:
  59. return colour::rose;
  60. case EffectKind::utility: case EffectKind::stereoShaper: case EffectKind::stereoEnhancer: case EffectKind::spreader:
  61. case EffectKind::fruityBalance: case EffectKind::fruitySend:
  62. return colour::lime;
  63. default:
  64. return colour::crimson;
  65. }
  66. }
  67. juce::Colour accentForInstrument (const juce::String& name)
  68. {
  69. if (name.containsIgnoreCase ("Keys") || name.containsIgnoreCase ("Piano")) return colour::azure;
  70. if (name.containsIgnoreCase ("Bass")) return colour::ember;
  71. if (name.containsIgnoreCase ("Harmor") || name.containsIgnoreCase ("Sytrus")) return colour::violet;
  72. return colour::crimson;
  73. }
  74. // --- effects level -------------------------------------------------------------------------------
  75. namespace
  76. {
  77. bool reduced = false;
  78. Style currentStyle = Style::glow;
  79. Art currentArt = Art::none;
  80. bool motion = true;
  81. // a deterministic grain tile (white and black specks at a few % alpha) laid over the canvases
  82. const juce::Image& grainTile()
  83. {
  84. static juce::Image tile = [] {
  85. juce::Image img (juce::Image::ARGB, 128, 128, true);
  86. juce::Random rnd (126);
  87. juce::Image::BitmapData px (img, juce::Image::BitmapData::writeOnly);
  88. for (int y = 0; y < 128; ++y)
  89. for (int x = 0; x < 128; ++x)
  90. {
  91. const auto v = rnd.nextFloat();
  92. const auto light = rnd.nextBool();
  93. const auto a = (juce::uint8) (v * v * 11.0f);
  94. px.setPixelColour (x, y, (light ? juce::Colours::white : juce::Colours::black).withAlpha (a));
  95. }
  96. return img;
  97. }();
  98. return tile;
  99. }
  100. float pixelScale (juce::Graphics& g)
  101. {
  102. return juce::jlimit (1.0f, 4.0f, g.getInternalContext().getPhysicalPixelScaleFactor());
  103. }
  104. // a static layer rendered once per (size, accent, scale, style) into an image and blitted afterwards
  105. void cachedLayer (juce::Graphics& g, juce::Rectangle<float> a, juce::Colour accent, int style,
  106. const std::function<void (juce::Graphics&, juce::Rectangle<float>, juce::Colour)>& draw)
  107. {
  108. if (a.isEmpty()) return;
  109. const auto scale = pixelScale (g);
  110. const auto w = (int) std::ceil (a.getWidth() * scale), h = (int) std::ceil (a.getHeight() * scale);
  111. if (w <= 0 || h <= 0 || (std::int64_t) w * h > 12'000'000) { draw (g, a, accent); return; }
  112. std::uint64_t key = (std::uint64_t) w;
  113. key = key * 16411u + (std::uint64_t) h;
  114. key = key * 31u + (std::uint64_t) style * 2u + (reduced ? 1u : 0u);
  115. key = key * 7u + (std::uint64_t) currentStyle;
  116. key = key * 11u + (std::uint64_t) currentArt;
  117. key ^= (std::uint64_t) accent.getARGB() * 0x9e3779b97f4a7c15ull;
  118. static std::map<std::uint64_t, juce::Image> cache;
  119. auto it = cache.find (key);
  120. if (it == cache.end())
  121. {
  122. if (cache.size() > 10) cache.clear();
  123. juce::Image img (juce::Image::ARGB, w, h, true);
  124. {
  125. juce::Graphics ig (img);
  126. ig.addTransform (juce::AffineTransform::scale ((float) w / a.getWidth(), (float) h / a.getHeight()));
  127. draw (ig, { 0.0f, 0.0f, a.getWidth(), a.getHeight() }, accent);
  128. }
  129. // Both layers (canvas, backdrop) are an editor's opaque base: every canvas starts with an opaque fill. Quartz's
  130. // 8-bit source-over rounds the alpha of an opaque pixel under a faint translucent blit (a bloom sprite) down to
  131. // 254, so on macOS the base came out a hair see-through (CI selftest plugin_art). Snap such pixels back to opaque
  132. // (premultiplied data: the colour stays valid); real translucency is far below this threshold.
  133. {
  134. juce::Image::BitmapData px (img, juce::Image::BitmapData::readWrite);
  135. for (int y = 0; y < px.height; ++y)
  136. {
  137. auto* row = px.getLinePointer (y);
  138. for (int x = 0; x < px.width; ++x)
  139. {
  140. auto* p = reinterpret_cast<juce::PixelARGB*> (row + x * px.pixelStride);
  141. if (p->getAlpha() >= 0xfc && p->getAlpha() < 0xff) p->setAlpha (0xff);
  142. }
  143. }
  144. }
  145. it = cache.emplace (key, img).first;
  146. }
  147. g.setOpacity (1.0f);
  148. g.drawImage (it->second, a, juce::RectanglePlacement::stretchToFit);
  149. }
  150. struct OpenAnimation final : private juce::Timer
  151. {
  152. OpenAnimation (juce::Component& c, Style st) : target (&c), t0 (juce::Time::getMillisecondCounterHiRes()), animStyle (st)
  153. {
  154. apply (0.0f);
  155. startTimerHz (60);
  156. }
  157. void apply (float u)
  158. {
  159. if (target == nullptr) return;
  160. const auto e = 1.0f - std::pow (1.0f - u, 3.0f); // ease out
  161. target->setAlpha (u >= 1.0f ? 1.0f : juce::jmax (0.02f, juce::jmin (1.0f, e * 1.4f)));
  162. const auto b = target->getLocalBounds().toFloat();
  163. // Vivid springs (a small overshoot), the others glide
  164. const auto spring = 1.0f - std::exp (-6.0f * u) * std::cos (u * 9.0f);
  165. const auto s = animStyle == Style::vivid ? 0.9f + 0.1f * spring : 0.955f + 0.045f * e;
  166. target->setTransform (u >= 1.0f ? juce::AffineTransform() : juce::AffineTransform::scale (s, s, b.getCentreX(), b.getCentreY()));
  167. }
  168. void timerCallback() override
  169. {
  170. const auto u = (float) juce::jmin (1.0, (juce::Time::getMillisecondCounterHiRes() - t0) / 220.0);
  171. apply (u);
  172. if (u >= 1.0f || target == nullptr)
  173. {
  174. stopTimer();
  175. delete this;
  176. }
  177. }
  178. juce::Component::SafePointer<juce::Component> target;
  179. double t0;
  180. Style animStyle;
  181. };
  182. } // namespace
  183. bool reducedEffects() { return reduced; }
  184. void setReducedEffects (bool on)
  185. {
  186. reduced = on;
  187. kickArtLayers();
  188. }
  189. Style style() { return currentStyle; }
  190. void setStyle (Style s) { currentStyle = s; }
  191. Art art() { return currentArt; }
  192. void setArt (Art a) { currentArt = a; }
  193. bool artMotion() { return motion; }
  194. void setArtMotion (bool on)
  195. {
  196. motion = on;
  197. kickArtLayers();
  198. }
  199. const char* styleName (Style s)
  200. {
  201. switch (s)
  202. {
  203. case Style::neon: return "Neon";
  204. case Style::hardware: return "Hardware";
  205. case Style::vivid: return "Vivid";
  206. case Style::themed: return "Themed";
  207. default: return "Glow";
  208. }
  209. }
  210. Style styleFromName (const juce::String& name)
  211. {
  212. for (int i = 0; i < styleCount; ++i)
  213. if (name.trim().equalsIgnoreCase (styleName ((Style) i))) return (Style) i;
  214. return Style::glow;
  215. }
  216. void playOpenAnimation (juce::Component& content, Style st)
  217. {
  218. if (reduced) return;
  219. new OpenAnimation (content, st); // deletes itself when done (or when the content goes away)
  220. }
  221. // --- per-plugin styles -----------------------------------------------------------------------------
  222. namespace
  223. {
  224. int forced = -1;
  225. std::map<int, int> overrides;
  226. constexpr int soundgoodizerKey = 1000;
  227. } // namespace
  228. int forcedStyle() { return forced; }
  229. void setForcedStyle (int s)
  230. {
  231. forced = s >= 0 && s < styleCount ? s : -1;
  232. kickArtLayers();
  233. }
  234. int styleKey (EffectKind kind, bool soundgoodizer) { return soundgoodizer ? soundgoodizerKey : (int) kind; }
  235. Style defaultStyleFor (int key)
  236. {
  237. if (key >= 0 && key < soundgoodizerKey && artForEffect ((EffectKind) key) != Art::none) return Style::themed; // round 170j: its own art
  238. return plainStyleFor (key);
  239. }
  240. Style plainStyleFor (int key)
  241. {
  242. using K = EffectKind;
  243. constexpr auto G = Style::glow, N = Style::neon, H = Style::hardware, V = Style::vivid;
  244. if (key == soundgoodizerKey) return V;
  245. switch ((K) key)
  246. {
  247. // the user's picks
  248. case K::lynxTune: return V;
  249. case K::epochVerb: return H;
  250. case K::crestCompressor: return G;
  251. // analytic, display-first tools: Glow
  252. case K::facetEq: case K::apexLimiter: case K::prismMultiband: case K::hushDeEsser: case K::frequencySplitter: case K::quellDenoiser:
  253. case K::fruityMultiband: case K::fruitySend: case K::fruityBalance: case K::luxeVerb: case K::convolver: case K::fruityDelay2:
  254. case K::fruityChorus: case K::fruitySoftClipper: case K::reeverb1: case K::peakController:
  255. return G;
  256. // analogue / vintage-modelled roles: Hardware
  257. case K::glowLeveler: case K::ridgeStrip: case K::foilPlate: case K::echoform: case K::vintageChorus: case K::vintagePhaser: case K::maximus:
  258. case K::fruityBloodOverdrive: case K::fruityCompressor: case K::fruityLimiter: case K::reeverb2: case K::aether: case K::vocoder: case K::kilnChannel: case K::fretChannel: case K::shellChannel:
  259. return H;
  260. // creative, pitch and fun: Vivid
  261. case K::geminiDoubler: case K::voiceShift: case K::ember: case K::grossBeat: case K::flPitchShifter: case K::fruityFastDist: case K::effector:
  262. case K::fruityPanOMatic: case K::transientProcessor: case K::squeeze: case K::hyperChorus: case K::fruityFlanger: case K::fruityDelay3:
  263. case K::multibandDelay: case K::horizon: case K::distructor:
  264. return V;
  265. // modulation, synthesis and space: Neon
  266. case K::latticeMod: case K::orbit: case K::spiralEcho: case K::halo: case K::nebula: case K::atrium: case K::fruityFlangus:
  267. case K::fruityPhaser: case K::fruityDelayBank: case K::vocodex: case K::hardcore: case K::fruityWaveShaper: case K::stereoShaper:
  268. case K::stereoEnhancer: case K::equo: case K::parametricEq: case K::fruityFilter: case K::fruityFreeFilter: case K::sentryGate:
  269. case K::pitchShift: case K::spreader:
  270. return N;
  271. default: return G;
  272. }
  273. }
  274. Style resolve (Style automatic) { return forced >= 0 ? (Style) forced : automatic; }
  275. Style resolve (Style automatic, Art a)
  276. {
  277. const auto s = resolve (automatic);
  278. if (s != Style::themed || a != Art::none) return s;
  279. return automatic != Style::themed ? automatic : Style::glow; // Themed everywhere: a page without art keeps its own style
  280. }
  281. Style styleFor (EffectKind kind, bool soundgoodizer)
  282. {
  283. const auto key = styleKey (kind, soundgoodizer);
  284. const auto hasArt = ! soundgoodizer && artForEffect (kind) != Art::none;
  285. auto fallback = [&] (Style s) {
  286. if (s != Style::themed || hasArt) return s;
  287. const auto own = defaultStyleFor (key);
  288. return own != Style::themed ? own : Style::glow;
  289. };
  290. if (forced >= 0) return fallback ((Style) forced);
  291. if (const auto o = overrideFor (key); o >= 0) return fallback ((Style) o);
  292. return fallback (defaultStyleFor (key));
  293. }
  294. int overrideFor (int key)
  295. {
  296. const auto it = overrides.find (key);
  297. return it != overrides.end() ? it->second : -1;
  298. }
  299. void setOverride (int key, int s)
  300. {
  301. if (s >= 0 && s < styleCount) overrides[key] = s;
  302. else overrides.erase (key);
  303. kickArtLayers();
  304. }
  305. juce::String overridesToString()
  306. {
  307. juce::StringArray parts;
  308. for (const auto& [k, s] : overrides) parts.add (juce::String (k) + ":" + styleName ((Style) s));
  309. return parts.joinIntoString (",");
  310. }
  311. void overridesFromString (const juce::String& text)
  312. {
  313. overrides.clear();
  314. for (const auto& part : juce::StringArray::fromTokens (text, ",", ""))
  315. if (part.containsChar (':'))
  316. setOverride (part.upToFirstOccurrenceOf (":", false, false).getIntValue(), (int) styleFromName (part.fromFirstOccurrenceOf (":", false, false)));
  317. }
  318. void addStyleMenu (juce::PopupMenu& menu, int key, std::function<void()> changed)
  319. {
  320. juce::PopupMenu sub;
  321. const auto now = overrideFor (key);
  322. auto apply = [key, changed] (int s) {
  323. setOverride (key, s);
  324. if (onStyleSettingsChanged) onStyleSettingsChanged();
  325. if (changed) changed();
  326. };
  327. sub.addItem (tr ("Automatic ({0})", { tr (styleName (defaultStyleFor (key))) }), true, now < 0, [apply] { apply (-1); });
  328. const auto hasArt = key >= 0 && key < soundgoodizerKey && artForEffect ((EffectKind) key) != Art::none;
  329. for (int i = 0; i < styleCount; ++i)
  330. if ((Style) i != Style::themed || hasArt)
  331. sub.addItem (tr (styleName ((Style) i)), true, now == i, [apply, i] { apply (i); });
  332. if (forced >= 0)
  333. {
  334. sub.addSeparator();
  335. sub.addItem (tr ("Settings force one style for every plugin"), false, false, [] {});
  336. }
  337. menu.addSubMenu (tr ("Plugin style"), sub);
  338. }
  339. // a bloom is a cached sprite per colour and strength (a radial gradient is costly per pixel; a blit is not)
  340. void bloom (juce::Graphics& g, juce::Point<float> c, float radius, juce::Colour colour, float alpha)
  341. {
  342. if (reduced || radius <= 0.5f || alpha <= 0.002f) return;
  343. const auto level = juce::jlimit (1, 64, (int) std::lround (alpha * 64.0f));
  344. const auto key = (std::uint64_t) colour.withAlpha ((juce::uint8) 255).getARGB() * 67u + (std::uint64_t) level;
  345. static std::unordered_map<std::uint64_t, juce::Image> sprites;
  346. auto it = sprites.find (key);
  347. if (it == sprites.end())
  348. {
  349. if (sprites.size() > 400) sprites.clear();
  350. constexpr int n = 96;
  351. juce::Image img (juce::Image::ARGB, n, n, true);
  352. {
  353. juce::Graphics ig (img);
  354. const auto a = (float) level / 64.0f;
  355. juce::ColourGradient grad (colour.withAlpha (a), n * 0.5f, n * 0.5f, colour.withAlpha (0.0f), (float) n, n * 0.5f, true);
  356. grad.addColour (0.45, colour.withAlpha (a * 0.42f));
  357. ig.setGradientFill (grad);
  358. ig.fillEllipse (0.0f, 0.0f, (float) n, (float) n);
  359. }
  360. it = sprites.emplace (key, img).first;
  361. }
  362. g.setOpacity (1.0f);
  363. g.drawImage (it->second, juce::Rectangle<float> (radius * 2.0f, radius * 2.0f).withCentre (c), juce::RectanglePlacement::stretchToFit);
  364. }
  365. #include "ui/PluginStyles.inc"
  366. #include "ui/PluginArt.inc"
  367. // --- surfaces ------------------------------------------------------------------------------------
  368. namespace
  369. {
  370. void drawCanvas (juce::Graphics& g, juce::Rectangle<float> a, juce::Colour accent, bool display)
  371. {
  372. if (currentStyle == Style::themed) { artkit::canvas (g, a, accent, display); return; }
  373. if (currentStyle != Style::glow) { styles::canvas (g, a, accent, display, currentStyle); return; }
  374. // the deep base
  375. g.setGradientFill (juce::ColourGradient (display ? juce::Colour (0xff14161c) : juce::Colour (0xff1c1e26), 0.0f, a.getY(),
  376. display ? juce::Colour (0xff060709) : juce::Colour (0xff0b0c10), 0.0f, a.getBottom(), false));
  377. g.fillRect (a);
  378. const auto big = juce::jmax (a.getWidth(), a.getHeight());
  379. if (! reduced)
  380. {
  381. // aurora: a large bloom of the accent behind the upper left, a cooler one to the right, LYNX red low on the right
  382. auto blob = [&] (float fx, float fy, float r, juce::Colour c, float alpha) {
  383. const juce::Point<float> p { a.getX() + a.getWidth() * fx, a.getY() + a.getHeight() * fy };
  384. juce::ColourGradient grad (c.withAlpha (alpha), p.x, p.y, c.withAlpha (0.0f), p.x + r, p.y, true);
  385. grad.addColour (0.35, c.withAlpha (alpha * 0.55f));
  386. grad.addColour (0.7, c.withAlpha (alpha * 0.14f));
  387. g.setGradientFill (grad);
  388. g.fillRect (a);
  389. };
  390. const auto second = accent.withRotatedHue (accent == colour::crimson ? 0.07f : -0.09f);
  391. blob (0.24f, display ? 0.0f : 0.06f, big * 0.62f, accent, display ? 0.26f : 0.32f);
  392. blob (0.86f, display ? 0.15f : 0.22f, big * 0.42f, second, display ? 0.12f : 0.17f);
  393. blob (0.95f, 1.05f, big * 0.42f, colour::crimson, 0.12f);
  394. blob (0.05f, 1.0f, big * 0.32f, accent, 0.06f);
  395. // grain
  396. g.setTiledImageFill (grainTile(), 0, 0, 1.0f);
  397. g.fillRect (a);
  398. }
  399. // vignette
  400. juce::ColourGradient vig (juce::Colours::transparentBlack, a.getCentreX(), a.getCentreY(), juce::Colours::black.withAlpha (0.42f),
  401. a.getCentreX() + big * 0.72f, a.getCentreY(), true);
  402. vig.addColour (0.55, juce::Colours::transparentBlack);
  403. g.setGradientFill (vig);
  404. g.fillRect (a);
  405. }
  406. } // namespace
  407. void canvas (juce::Graphics& g, juce::Rectangle<float> a, juce::Colour accent)
  408. {
  409. cachedLayer (g, a, accent, 0, [] (juce::Graphics& lg, juce::Rectangle<float> r, juce::Colour c) { drawCanvas (lg, r, c, false); });
  410. }
  411. void backdrop (juce::Graphics& g, juce::Rectangle<float> a, juce::Colour accent)
  412. {
  413. cachedLayer (g, a, accent, 1, [] (juce::Graphics& lg, juce::Rectangle<float> r, juce::Colour c) { drawCanvas (lg, r, c, true); });
  414. }
  415. void headerBar (juce::Graphics& g, juce::Rectangle<float> a, juce::Colour accent)
  416. {
  417. if (currentStyle == Style::themed && artkit::headerBar (g, a, accent)) return;
  418. const BaseScope base;
  419. if (currentStyle != Style::glow) { styles::headerBar (g, a, accent, currentStyle); return; }
  420. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff2c2f39), 0.0f, a.getY(), juce::Colour (0xff15171c), 0.0f, a.getBottom(), false));
  421. g.fillRect (a);
  422. if (! reduced)
  423. {
  424. // the accent washing in from the left behind the name plate, the brand red from the right
  425. juce::ColourGradient wash (accent.withAlpha (0.30f), a.getX() + 70.0f, a.getCentreY(), accent.withAlpha (0.0f), a.getX() + 70.0f + juce::jmin (520.0f, a.getWidth() * 0.6f),
  426. a.getCentreY(), true);
  427. wash.addColour (0.4, accent.withAlpha (0.10f));
  428. g.setGradientFill (wash);
  429. g.fillRect (a);
  430. juce::ColourGradient brand (colour::crimson.withAlpha (0.10f), a.getRight(), a.getCentreY(), colour::crimson.withAlpha (0.0f), a.getRight() - 300.0f, a.getCentreY(), true);
  431. g.setGradientFill (brand);
  432. g.fillRect (a);
  433. }
  434. // glass: a sheen over the top half and a crisp top highlight
  435. g.setGradientFill (juce::ColourGradient (juce::Colours::white.withAlpha (0.075f), 0.0f, a.getY(), juce::Colours::white.withAlpha (0.0f), 0.0f, a.getCentreY(), false));
  436. g.fillRect (a.withHeight (a.getHeight() * 0.5f));
  437. g.setColour (juce::Colours::white.withAlpha (0.12f));
  438. g.drawHorizontalLine ((int) a.getY(), a.getX(), a.getRight());
  439. g.setColour (juce::Colours::black.withAlpha (0.7f));
  440. g.drawHorizontalLine ((int) a.getBottom() - 1, a.getX(), a.getRight());
  441. // the lit accent edge: bright on the left, fading across
  442. const auto lineW = juce::jmin (a.getWidth(), 640.0f);
  443. if (! reduced)
  444. {
  445. juce::ColourGradient glow (accent.withAlpha (0.35f), a.getX(), 0.0f, accent.withAlpha (0.0f), a.getX() + lineW, 0.0f, false);
  446. g.setGradientFill (glow);
  447. g.fillRect (juce::Rectangle<float> (a.getX(), a.getBottom() - 4.0f, lineW, 4.0f));
  448. }
  449. juce::ColourGradient line (accent.brighter (0.25f), a.getX(), 0.0f, accent.withAlpha (0.0f), a.getX() + lineW, 0.0f, false);
  450. line.addColour (0.3, accent.withAlpha (0.8f));
  451. g.setGradientFill (line);
  452. g.fillRect (juce::Rectangle<float> (a.getX(), a.getBottom() - 2.0f, lineW, 1.5f));
  453. }
  454. void brandMark (juce::Graphics& g, juce::Rectangle<float> a)
  455. {
  456. const auto d = juce::jmin (a.getWidth(), a.getHeight());
  457. if (d < 6.0f) return;
  458. // the logo resampled once per size (×2 for high-DPI)
  459. static std::map<int, juce::Image> cache;
  460. const auto px = juce::jlimit (8, 128, (int) std::ceil (d * 2.0f));
  461. auto& img = cache[px];
  462. if (img.isNull())
  463. {
  464. const auto logo = logoImage();
  465. if (logo.isNull()) return;
  466. img = logo.rescaled (px, px, juce::Graphics::highResamplingQuality);
  467. }
  468. const auto r = a.withSizeKeepingCentre (d, d);
  469. bloom (g, r.getCentre(), d * 1.05f, colour::crimson, 0.55f);
  470. g.setColour (juce::Colours::black.withAlpha (0.5f));
  471. g.fillEllipse (r.expanded (1.5f).translated (0.0f, 0.8f));
  472. g.setColour (colour::crimson.withAlpha (0.55f));
  473. g.drawEllipse (r.expanded (1.2f), 1.0f);
  474. g.setOpacity (1.0f);
  475. g.drawImage (img, r, juce::RectanglePlacement::centred);
  476. }
  477. namespace
  478. {
  479. TitleFit lastFit;
  480. // round 170k2: how each style sets a plugin's name (its size for a box this high, kerning, capitals, padding)
  481. struct TitleLook
  482. {
  483. float nominal, kerning, pad;
  484. bool upper;
  485. };
  486. TitleLook titleLook (Style s, float h)
  487. {
  488. switch (s)
  489. {
  490. case Style::neon: return { juce::jlimit (14.0f, 21.0f, h * 0.74f), 0.06f, 4.0f, false };
  491. case Style::hardware: return { juce::jlimit (12.0f, 16.0f, h * 0.56f), 0.08f, 16.0f, true };
  492. case Style::vivid: return { juce::jlimit (14.0f, 20.0f, h * 0.72f), 0.03f, 3.5f, true };
  493. default: return { juce::jlimit (13.0f, 18.0f, h * 0.62f), 0.02f, 2.0f, false };
  494. }
  495. }
  496. float titleWidth (const TitleLook& look, const juce::String& name, float size)
  497. {
  498. const auto f = juce::Font (theme::font (size, true)).withExtraKerningFactor (look.kerning);
  499. return juce::GlyphArrangement::getStringWidth (f, look.upper ? name.toUpperCase() : name) + look.pad;
  500. }
  501. // the largest size from the style's own down to minSize at which the name fits `w`; 0 when even minSize does not
  502. float fittingSize (const TitleLook& look, const juce::String& name, float w, float minSize)
  503. {
  504. for (auto size = look.nominal; size >= minSize - 0.01f; size -= 0.5f)
  505. if (titleWidth (look, name, size) <= w - 1.0f) // (a pixel of slack: drawText rounds its own way)
  506. return size;
  507. return 0.0f;
  508. }
  509. constexpr float titleMinSize = 10.0f; // smaller than this a header name stops reading as a title
  510. float drawTitleLine (juce::Graphics& g, juce::Rectangle<float> a, const juce::String& name, juce::Colour accent, bool underline, float size);
  511. } // namespace
  512. TitleFit lastTitleFit() { return lastFit; }
  513. void resetTitleFit() { lastFit = {}; }
  514. // the prefix that may go to a small line above the name when the full name does not fit on one ("Fruity Blood
  515. // Overdrive": "Fruity" over "Blood Overdrive")
  516. static int titlePrefixLength (const juce::String& name)
  517. {
  518. for (const auto* p : { "Fruity " })
  519. if (name.startsWithIgnoreCase (p) && name.length() > (int) std::strlen (p) + 2)
  520. return (int) std::strlen (p);
  521. return 0;
  522. }
  523. float titleMinWidth (const juce::String& name, float height)
  524. {
  525. // the widest any style needs (a window's minimum size does not change with the style)
  526. auto most = 0.0f;
  527. for (const auto st : { Style::glow, Style::neon, Style::hardware, Style::vivid })
  528. {
  529. if (const auto n = titlePrefixLength (name); n > 0 && height >= 20.0f)
  530. {
  531. const auto low = titleLook (st, height * 0.7f);
  532. most = juce::jmax (most, titleWidth (low, name.substring (n), titleMinSize));
  533. }
  534. else
  535. most = juce::jmax (most, titleWidth (titleLook (st, height), name, titleMinSize));
  536. }
  537. return std::ceil (most) + 2.0f;
  538. }
  539. float titleText (juce::Graphics& g, juce::Rectangle<float> a, const juce::String& name, juce::Colour accent, bool underline)
  540. {
  541. const BaseScope base;
  542. const auto look = titleLook (currentStyle, a.getHeight());
  543. lastFit = { titleWidth (look, name, look.nominal), a.getWidth(), look.nominal, 1, false };
  544. // 1. one line, the style's size or a little smaller
  545. if (const auto size = fittingSize (look, name, a.getWidth(), juce::jmax (titleMinSize, look.nominal * 0.75f)); size > 0.0f)
  546. {
  547. lastFit.size = size;
  548. return drawTitleLine (g, a, name, accent, underline, size);
  549. }
  550. // 2. a known prefix ("Fruity") on a small line above, the rest of the name below it
  551. if (const auto n = titlePrefixLength (name); n > 0 && a.getHeight() >= 20.0f)
  552. {
  553. const auto rest = name.substring (n);
  554. const auto top = a.withHeight (a.getHeight() * 0.36f).translated (0.0f, 1.0f);
  555. const auto low = a.withTrimmedTop (a.getHeight() * 0.36f);
  556. const auto lowLook = titleLook (currentStyle, low.getHeight());
  557. if (const auto size = fittingSize (lowLook, rest, low.getWidth(), titleMinSize); size > 0.0f)
  558. {
  559. const auto prefix = name.substring (0, n).trim();
  560. const auto prefixSize = juce::jmax (8.0f, top.getHeight() * 0.95f);
  561. g.setFont (juce::Font (theme::font (prefixSize, true)).withExtraKerningFactor (0.12f));
  562. const auto prefixWidth = juce::GlyphArrangement::getStringWidth (g.getCurrentFont(), prefix.toUpperCase()) + 4.0f;
  563. g.setColour (juce::Colours::white.withAlpha (0.62f));
  564. g.drawText (prefix.toUpperCase(), top.withTrimmedLeft (lowLook.pad > 8.0f ? 4.0f : 1.0f), juce::Justification::centredLeft, false);
  565. lastFit.size = size;
  566. lastFit.lines = 2;
  567. const auto w = drawTitleLine (g, low, rest, accent, false, size);
  568. return juce::jmax (w, prefixWidth);
  569. }
  570. }
  571. // 3. one line at the smallest title size (ellipsis only when even that does not fit)
  572. const auto size = juce::jmax (titleMinSize, fittingSize (look, name, a.getWidth(), titleMinSize));
  573. lastFit.size = size;
  574. lastFit.clipped = titleWidth (look, name, size) > a.getWidth() + 0.5f;
  575. return drawTitleLine (g, a, name, accent, underline, size);
  576. }
  577. namespace
  578. {
  579. float drawTitleLine (juce::Graphics& g, juce::Rectangle<float> a, const juce::String& name, juce::Colour accent, bool underline, float size)
  580. {
  581. if (currentStyle != Style::glow) return styles::titleText (g, a, name, accent, underline, currentStyle, size);
  582. // the name plate: big and bold, lit from behind in the accent
  583. g.setFont (juce::Font (theme::font (size, true)).withExtraKerningFactor (0.02f));
  584. const auto w = juce::jmin (a.getWidth(), juce::GlyphArrangement::getStringWidth (g.getCurrentFont(), name) + 2.0f);
  585. const auto box = a.withWidth (w);
  586. if (! reduced)
  587. {
  588. bloom (g, box.getCentre(), w * 0.62f, accent, 0.16f);
  589. g.setColour (accent.withAlpha (0.22f));
  590. for (const auto& o : { juce::Point<float> { -1.0f, 0.0f }, { 1.0f, 0.0f }, { 0.0f, -1.0f }, { 0.0f, 1.0f } })
  591. g.drawText (name, box.translated (o.x, o.y), juce::Justification::centredLeft, true);
  592. }
  593. g.setColour (juce::Colours::black.withAlpha (0.6f));
  594. g.drawText (name, box.translated (0.0f, 1.0f), juce::Justification::centredLeft, true);
  595. g.setGradientFill (juce::ColourGradient (juce::Colours::white, 0.0f, a.getCentreY() - size * 0.5f, juce::Colour (0xffd6d9e0).interpolatedWith (accent, 0.18f), 0.0f,
  596. a.getCentreY() + size * 0.5f, false));
  597. drawFilledText (g, name, box, juce::Justification::centredLeft); // (not drawText: see drawFilledText)
  598. if (underline)
  599. {
  600. const auto line = juce::Rectangle<float> (a.getX(), a.getBottom() - 3.0f, w, 2.0f);
  601. if (! reduced)
  602. {
  603. g.setColour (accent.withAlpha (0.25f));
  604. g.fillRoundedRectangle (line.expanded (0.0f, 1.5f), 2.0f);
  605. }
  606. g.setGradientFill (juce::ColourGradient (accent.brighter (0.3f), line.getX(), 0.0f, accent.withAlpha (0.1f), line.getRight(), 0.0f, false));
  607. g.fillRoundedRectangle (line, 1.0f);
  608. }
  609. return w;
  610. }
  611. } // namespace
  612. void drawFilledText (juce::Graphics& g, const juce::String& text, juce::Rectangle<float> area, juce::Justification justification)
  613. {
  614. if (text.isEmpty() || area.isEmpty()) return;
  615. juce::GlyphArrangement glyphs;
  616. glyphs.addCurtailedLineOfText (g.getCurrentFont(), text, 0.0f, 0.0f, area.getWidth(), true);
  617. glyphs.justifyGlyphs (0, glyphs.getNumGlyphs(), area.getX(), area.getY(), area.getWidth(), area.getHeight(), justification);
  618. juce::Path outline;
  619. for (int i = 0; i < glyphs.getNumGlyphs(); ++i)
  620. {
  621. auto& glyph = glyphs.getGlyph (i);
  622. if (glyph.isWhitespace()) continue;
  623. juce::Path one;
  624. glyph.createPath (one);
  625. if (! one.isEmpty()) outline.addPath (one);
  626. }
  627. if (! outline.isEmpty()) g.fillPath (outline);
  628. }
  629. juce::String rendererProbeReport()
  630. {
  631. // what a filled shape changed outside its own box, on this platform's native image type (CoreGraphics on macOS)
  632. const auto changedOutside = [] (const std::function<void (juce::Graphics&)>& draw, juce::Rectangle<int> inside) {
  633. juce::Image img (juce::Image::ARGB, 240, 80, true);
  634. {
  635. juce::Graphics g (img);
  636. g.fillAll (juce::Colours::black);
  637. draw (g);
  638. }
  639. int changed = 0;
  640. for (int y = 0; y < img.getHeight(); ++y)
  641. for (int x = 0; x < img.getWidth(); ++x)
  642. if (! inside.contains (x, y) && img.getPixelAt (x, y).getBrightness() > 0.05f) ++changed;
  643. return changed;
  644. };
  645. const auto gradient = [] (juce::Graphics& g) {
  646. g.setGradientFill (juce::ColourGradient (juce::Colours::white, 0.0f, 20.0f, juce::Colour (0xffd6c0c8), 0.0f, 40.0f, false));
  647. g.setFont (theme::font (16.0f, true));
  648. };
  649. const juce::Rectangle<int> box (20, 20, 120, 24);
  650. const auto rawText = changedOutside ([&] (juce::Graphics& g) { gradient (g); g.drawText ("Facet EQ", box.toFloat(), juce::Justification::centredLeft, true); }, box);
  651. const auto safeText = changedOutside ([&] (juce::Graphics& g) { gradient (g); drawFilledText (g, "Facet EQ", box.toFloat(), juce::Justification::centredLeft); }, box);
  652. const auto emptyPath = changedOutside ([&] (juce::Graphics& g) { gradient (g); g.fillPath (juce::Path()); }, {});
  653. juce::String r;
  654. r << "renderer probe (pixels changed outside the shape; 0 = right)\n";
  655. r << "gradient drawText \"Facet EQ\": " << rawText << "\n";
  656. r << "gradient drawFilledText \"Facet EQ\": " << safeText << "\n";
  657. r << "gradient fillPath (empty path): " << emptyPath << "\n";
  658. r << "result=" << (safeText == 0 ? "OK" : "FAIL") << "\n";
  659. return r;
  660. }
  661. void powerLed (juce::Graphics& g, juce::Point<float> c, float d, bool on)
  662. {
  663. const BaseScope base;
  664. if (currentStyle != Style::glow) { styles::powerLed (g, c, d, on, currentStyle); return; }
  665. const auto r = juce::Rectangle<float> (d, d).withCentre (c);
  666. if (on) bloom (g, c, d * 1.9f, theme::colour::ledOn, 0.55f);
  667. g.setColour (juce::Colours::black.withAlpha (0.6f));
  668. g.fillEllipse (r.expanded (1.2f));
  669. g.setGradientFill (juce::ColourGradient (on ? theme::colour::ledOn.brighter (0.5f) : theme::colour::ledOff.brighter (0.1f), c.x, r.getY(),
  670. on ? theme::colour::ledOn.darker (0.2f) : theme::colour::ledOff.darker (0.3f), c.x, r.getBottom(), false));
  671. g.fillEllipse (r);
  672. g.setColour (juce::Colours::white.withAlpha (on ? 0.7f : 0.14f));
  673. g.fillEllipse (r.reduced (d * 0.3f).translated (-d * 0.1f, -d * 0.14f));
  674. }
  675. void section (juce::Graphics& g, juce::Rectangle<float> a, float corner, bool raised, juce::Colour tint)
  676. {
  677. if (currentStyle == Style::themed && artkit::section (g, a, corner, raised, tint)) return;
  678. const BaseScope base;
  679. if (currentStyle != Style::glow) { styles::section (g, a, corner, raised, tint, currentStyle); return; }
  680. // glass with real depth: a soft shadow under it, a translucent body (the aurora shows through), a sheen on the
  681. // upper part, the rim catching light along the top and a dark lip at the bottom
  682. if (! reduced)
  683. {
  684. g.setColour (juce::Colours::black.withAlpha (0.22f));
  685. g.fillRoundedRectangle (a.translated (0.0f, 4.0f).expanded (1.5f), corner + 1.5f);
  686. }
  687. g.setColour (juce::Colours::black.withAlpha (0.45f));
  688. g.fillRoundedRectangle (a.translated (0.0f, 1.5f), corner);
  689. const auto top = raised ? juce::Colour (0xc8303440) : juce::Colour (0xb4242731);
  690. const auto bottom = raised ? juce::Colour (0xe6222530) : juce::Colour (0xdc15171d);
  691. g.setGradientFill (juce::ColourGradient (top, 0.0f, a.getY(), bottom, 0.0f, a.getBottom(), false));
  692. g.fillRoundedRectangle (a, corner);
  693. g.setGradientFill (juce::ColourGradient (juce::Colours::white.withAlpha (raised ? 0.07f : 0.05f), 0.0f, a.getY(), juce::Colours::white.withAlpha (0.0f), 0.0f,
  694. a.getY() + juce::jmin (54.0f, a.getHeight() * 0.5f), false));
  695. g.fillRoundedRectangle (a, corner);
  696. if (tint.getAlpha() > 0 && ! reduced) // the accent's light falling on the glass from above
  697. {
  698. g.setGradientFill (juce::ColourGradient (tint.withAlpha (0.13f), 0.0f, a.getY(), tint.withAlpha (0.0f), 0.0f, a.getY() + juce::jmin (140.0f, a.getHeight() * 0.8f), false));
  699. g.fillRoundedRectangle (a, corner);
  700. g.setGradientFill (juce::ColourGradient (tint.withAlpha (0.0f), 0.0f, a.getBottom() - juce::jmin (60.0f, a.getHeight() * 0.4f), tint.withAlpha (0.06f), 0.0f, a.getBottom(), false));
  701. g.fillRoundedRectangle (a, corner);
  702. }
  703. // rim light (top) fading to a dark lip (bottom)
  704. juce::ColourGradient rim (tint.getAlpha() > 0 ? tint.interpolatedWith (juce::Colours::white, 0.55f).withAlpha (0.32f) : juce::Colours::white.withAlpha (0.20f), 0.0f, a.getY(), juce::Colours::white.withAlpha (0.02f), 0.0f, a.getY() + juce::jmin (40.0f, a.getHeight()), false);
  705. g.setGradientFill (rim);
  706. g.drawRoundedRectangle (a.reduced (0.5f), corner, 1.0f);
  707. g.setColour (juce::Colours::black.withAlpha (0.55f));
  708. g.drawRoundedRectangle (a.expanded (0.5f), corner + 0.5f, 1.0f);
  709. }
  710. void sectionTitle (juce::Graphics& g, juce::Rectangle<float> strip, const juce::String& text, juce::Colour accent, float fontSize)
  711. {
  712. if (currentStyle == Style::themed && artkit::sectionTitle (g, strip, text, accent, fontSize)) return;
  713. const BaseScope base;
  714. if (currentStyle != Style::glow) { styles::sectionTitle (g, strip, text, accent, fontSize, currentStyle); return; }
  715. g.setFont (juce::Font (theme::font (fontSize, true)).withExtraKerningFactor (0.1f));
  716. const auto w = juce::GlyphArrangement::getStringWidth (g.getCurrentFont(), text);
  717. const auto dotD = juce::jmax (4.0f, fontSize * 0.5f);
  718. const auto x0 = strip.getCentreX() - (w + dotD + 7.0f) * 0.5f;
  719. const juce::Point<float> dc { x0 + dotD * 0.5f, strip.getCentreY() };
  720. // an LED in the accent
  721. bloom (g, dc, dotD * 2.2f, accent, 0.55f);
  722. g.setGradientFill (juce::ColourGradient (accent.brighter (0.6f), dc.x, dc.y - dotD * 0.5f, accent, dc.x, dc.y + dotD * 0.5f, false));
  723. g.fillEllipse (juce::Rectangle<float> (dotD, dotD).withCentre (dc));
  724. g.setColour (juce::Colour (0xffdde0e7));
  725. g.drawText (text, juce::Rectangle<float> (x0 + dotD + 7.0f, strip.getY(), w + 6.0f, strip.getHeight()), juce::Justification::centredLeft, false);
  726. // lit hairlines to the edges, fading out
  727. const auto y = strip.getCentreY() - 0.5f;
  728. const auto l0 = strip.getX() + 8.0f, l1 = x0 - 7.0f, r0 = x0 + dotD + w + 15.0f, r1 = strip.getRight() - 8.0f;
  729. if (l1 > l0)
  730. {
  731. g.setGradientFill (juce::ColourGradient (accent.withAlpha (0.0f), l0, 0.0f, accent.withAlpha (0.45f), l1, 0.0f, false));
  732. g.fillRect (juce::Rectangle<float> (l0, y, l1 - l0, 1.0f));
  733. }
  734. if (r1 > r0)
  735. {
  736. g.setGradientFill (juce::ColourGradient (accent.withAlpha (0.45f), r0, 0.0f, accent.withAlpha (0.0f), r1, 0.0f, false));
  737. g.fillRect (juce::Rectangle<float> (r0, y, r1 - r0, 1.0f));
  738. }
  739. }
  740. void well (juce::Graphics& g, juce::Rectangle<float> a, float corner, juce::Colour glow)
  741. {
  742. if (currentStyle == Style::themed && artkit::well (g, a, corner, glow)) return;
  743. const BaseScope base;
  744. if (currentStyle != Style::glow) { styles::well (g, a, corner, glow, currentStyle); return; }
  745. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff050608), 0.0f, a.getY(), juce::Colour (0xff0f1015), 0.0f, a.getBottom(), false));
  746. g.fillRoundedRectangle (a, corner);
  747. if (! reduced && glow.getAlpha() > 0)
  748. {
  749. // light rising from the bottom of the display
  750. g.saveState();
  751. g.reduceClipRegion (a.toNearestInt());
  752. juce::ColourGradient rise (glow.withAlpha (0.20f), a.getCentreX(), a.getBottom() + a.getHeight() * 0.1f, glow.withAlpha (0.0f), a.getCentreX() + a.getWidth() * 0.62f,
  753. a.getBottom(), true);
  754. rise.addColour (0.4, glow.withAlpha (0.07f));
  755. g.setGradientFill (rise);
  756. g.fillRect (a);
  757. g.restoreState();
  758. }
  759. // inner shadows: top and sides
  760. const auto sh = juce::jmin (10.0f, a.getHeight() * 0.3f);
  761. g.setGradientFill (juce::ColourGradient (juce::Colours::black.withAlpha (0.6f), 0.0f, a.getY(), juce::Colours::transparentBlack, 0.0f, a.getY() + sh, false));
  762. g.fillRoundedRectangle (a.withHeight (sh), corner);
  763. const auto sw = juce::jmin (6.0f, a.getWidth() * 0.1f);
  764. g.setGradientFill (juce::ColourGradient (juce::Colours::black.withAlpha (0.35f), a.getX(), 0.0f, juce::Colours::transparentBlack, a.getX() + sw, 0.0f, false));
  765. g.fillRect (a.withWidth (sw).reduced (0.0f, corner));
  766. g.setGradientFill (juce::ColourGradient (juce::Colours::black.withAlpha (0.35f), a.getRight(), 0.0f, juce::Colours::transparentBlack, a.getRight() - sw, 0.0f, false));
  767. g.fillRect (a.withLeft (a.getRight() - sw).reduced (0.0f, corner));
  768. g.setColour (juce::Colours::black.withAlpha (0.75f));
  769. g.drawRoundedRectangle (a.reduced (0.5f), corner, 1.0f);
  770. // the lip catching light at the bottom
  771. g.setColour (juce::Colours::white.withAlpha (0.08f));
  772. g.drawHorizontalLine ((int) a.getBottom(), a.getX() + corner, a.getRight() - corner);
  773. }
  774. void floatingPanel (juce::Graphics& g, juce::Rectangle<float> r, juce::Colour edge, float corner)
  775. {
  776. if (currentStyle == Style::themed && artkit::floatingPanel (g, r, edge, corner)) return;
  777. const BaseScope base;
  778. if (currentStyle != Style::glow) { styles::floatingPanel (g, r, edge, corner, currentStyle); return; }
  779. juce::DropShadow (juce::Colours::black.withAlpha (0.7f), 24, { 0, 8 }).drawForRectangle (g, r.toNearestInt());
  780. if (! reduced)
  781. {
  782. g.setColour (edge.withAlpha (0.10f));
  783. g.fillRoundedRectangle (r.expanded (4.0f), corner + 4.0f);
  784. g.setColour (edge.withAlpha (0.16f));
  785. g.fillRoundedRectangle (r.expanded (2.0f), corner + 2.0f);
  786. }
  787. g.setGradientFill (juce::ColourGradient (juce::Colour (0xf72a2d36).interpolatedWith (edge, 0.07f), 0.0f, r.getY(), juce::Colour (0xf8141519), 0.0f, r.getBottom(), false));
  788. g.fillRoundedRectangle (r, corner);
  789. g.setGradientFill (juce::ColourGradient (juce::Colours::white.withAlpha (0.07f), 0.0f, r.getY(), juce::Colours::white.withAlpha (0.0f), 0.0f,
  790. r.getY() + juce::jmin (50.0f, r.getHeight() * 0.5f), false));
  791. g.fillRoundedRectangle (r, corner);
  792. g.setGradientFill (juce::ColourGradient (juce::Colours::white.withAlpha (0.16f), 0.0f, r.getY(), juce::Colours::white.withAlpha (0.0f), 0.0f,
  793. r.getY() + juce::jmin (30.0f, r.getHeight()), false));
  794. g.drawRoundedRectangle (r.reduced (1.5f), corner - 1.0f, 1.0f);
  795. g.setGradientFill (juce::ColourGradient (edge.brighter (0.2f), 0.0f, r.getY(), edge.withAlpha (0.45f), 0.0f, r.getBottom(), false));
  796. g.drawRoundedRectangle (r.reduced (0.5f), corner, 1.4f);
  797. }
  798. void bottomBar (juce::Graphics& g, juce::Rectangle<float> a)
  799. {
  800. const BaseScope base;
  801. if (currentStyle != Style::glow) { styles::bottomBar (g, a, currentStyle); return; }
  802. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff1f2128), 0.0f, a.getY(), juce::Colour (0xff111216), 0.0f, a.getBottom(), false));
  803. g.fillRect (a);
  804. g.setColour (juce::Colours::black.withAlpha (0.75f));
  805. g.drawHorizontalLine ((int) a.getY(), a.getX(), a.getRight());
  806. g.setColour (juce::Colours::white.withAlpha (0.08f));
  807. g.drawHorizontalLine ((int) a.getY() + 1, a.getX(), a.getRight());
  808. }
  809. // --- controls ------------------------------------------------------------------------------------
  810. namespace
  811. {
  812. void drawKnobDirect (juce::Graphics& g, juce::Rectangle<float> bounds, const KnobLook& k);
  813. }
  814. // Knobs are drawn once per look into a small cached image (value to 1/1000, hover in 8 steps, the screen's pixel
  815. // scale) and blitted afterwards: a display editor repainting at 30 Hz re-uses its unchanged knobs for free. The
  816. // bloom a big knob casts on the panel (brighter as it is turned up) is one gradient, drawn live.
  817. juce::Colour capTintFor (const char* param)
  818. {
  819. return currentStyle == Style::themed && param != nullptr ? artkit::capTintFor (param) : juce::Colour();
  820. }
  821. juce::Colour offLabelColour()
  822. {
  823. if (currentStyle == Style::themed && artkit::onDarkFill) return juce::Colour (0xffd0d3d6); // round tp172d
  824. return currentStyle == Style::themed ? artkit::offLabelColour() : juce::Colour();
  825. }
  826. void knob (juce::Graphics& g, juce::Rectangle<float> boundsIn, const KnobLook& k)
  827. {
  828. // Hardware and Vivid draw their knobs a little bigger than the cell's circle (the ring sits close to the caption)
  829. const auto grow = currentStyle == Style::vivid ? styles::knobScaleVivid : currentStyle == Style::hardware ? styles::knobScaleHardware
  830. : currentStyle == Style::themed ? artkit::knobScale() : 1.0f;
  831. const auto bounds = boundsIn.withSizeKeepingCentre (boundsIn.getWidth() * grow, boundsIn.getHeight() * grow);
  832. const auto size = juce::jmin (bounds.getWidth(), bounds.getHeight()) - 2.0f;
  833. if (size <= 4.0f) return;
  834. if (size >= 52.0f && k.enabled && (currentStyle == Style::glow || currentStyle == Style::neon))
  835. {
  836. const auto v = juce::jlimit (0.0f, 1.0f, k.bipolar ? std::abs (k.value - 0.5f) * 2.0f : k.value);
  837. bloom (g, bounds.getCentre(), size * 0.8f, k.accent, 0.05f + 0.11f * v + 0.06f * juce::jmax (k.hover, k.active ? 1.0f : 0.0f));
  838. }
  839. const auto scale = pixelScale (g);
  840. const auto pad = size * 0.16f + 3.0f;
  841. const auto area = bounds.withSizeKeepingCentre (size, size).expanded (pad);
  842. const auto px = (int) std::ceil (area.getWidth() * scale);
  843. if (px > 420) { drawKnobDirect (g, bounds, k); return; }
  844. std::uint64_t key = (std::uint64_t) juce::jlimit (0, 1000, (int) std::lround (k.value * 1000.0f));
  845. key = key * 1009u + (std::uint64_t) std::lround (size * 4.0f);
  846. key = key * 9u + (std::uint64_t) std::lround (juce::jlimit (0.0f, 1.0f, k.hover) * 8.0f);
  847. key = key * 16u + (k.bipolar ? 1u : 0u) + (k.active ? 2u : 0u) + (k.enabled ? 4u : 0u) + (reduced ? 8u : 0u);
  848. key = key * 7u + (std::uint64_t) currentStyle;
  849. key = key * 11u + (std::uint64_t) currentArt;
  850. key = key * 401u + (std::uint64_t) std::lround (scale * 100.0f);
  851. key ^= (std::uint64_t) k.accent.getARGB() * 0x9e3779b97f4a7c15ull;
  852. key ^= (std::uint64_t) k.capTint.getARGB() * 0xc2b2ae3d27d4eb4full;
  853. static std::unordered_map<std::uint64_t, juce::Image> cache;
  854. auto it = cache.find (key);
  855. if (it == cache.end())
  856. {
  857. if (cache.size() > 1500) cache.clear();
  858. juce::Image img (juce::Image::ARGB, px, px, true);
  859. {
  860. juce::Graphics ig (img);
  861. ig.addTransform (juce::AffineTransform::scale ((float) px / area.getWidth()));
  862. drawKnobDirect (ig, juce::Rectangle<float> (pad, pad, size, size).expanded (1.0f), k);
  863. }
  864. it = cache.emplace (key, img).first;
  865. }
  866. g.setOpacity (1.0f); // (drawImage uses the current colour's alpha)
  867. g.drawImage (it->second, area, juce::RectanglePlacement::stretchToFit);
  868. }
  869. namespace
  870. {
  871. void drawKnobDirect (juce::Graphics& g, juce::Rectangle<float> bounds, const KnobLook& k)
  872. {
  873. const auto size = juce::jmin (bounds.getWidth(), bounds.getHeight()) - 2.0f;
  874. if (size <= 4.0f) return;
  875. const auto area = bounds.withSizeKeepingCentre (size, size);
  876. if (currentStyle == Style::themed) { artkit::knob (g, area, k); return; }
  877. if (currentStyle == Style::neon) { styles::knobNeon (g, area, k); return; }
  878. if (currentStyle == Style::hardware) { styles::knobHardware (g, area, k); return; }
  879. if (currentStyle == Style::vivid) { styles::knobVivid (g, area, k); return; }
  880. const auto c = area.getCentre();
  881. const auto small = size < 26.0f;
  882. const auto fx = ! small && ! reduced;
  883. const auto thickness = juce::jlimit (2.0f, 7.0f, size * 0.085f);
  884. const auto arcR = size * 0.5f - thickness * (small ? 0.6f : 0.85f);
  885. const auto value = juce::jlimit (0.0f, 1.0f, k.value);
  886. const auto accent = k.enabled ? (k.active ? k.accent.brighter (0.3f) : k.accent) : theme::colour::textDisabled;
  887. const auto hover = juce::jlimit (0.0f, 1.0f, k.active ? 1.0f : k.hover);
  888. // dragging: a halo of the accent around the whole knob
  889. if (k.active && fx)
  890. {
  891. juce::ColourGradient halo (accent.withAlpha (0.0f), c.x, c.y, accent.withAlpha (0.0f), c.x + size * 0.66f, c.y, true);
  892. halo.addColour (0.62, accent.withAlpha (0.0f));
  893. halo.addColour (0.76, accent.withAlpha (0.26f));
  894. g.setGradientFill (halo);
  895. g.fillEllipse (area.expanded (size * 0.16f));
  896. }
  897. // the track: a dark groove with the unlit ring (and, on big knobs, dim LED ticks along it)
  898. const auto track = arcPath (c, arcR, arcStart, arcStart + arcRange);
  899. g.setColour (juce::Colour (0xff050607));
  900. g.strokePath (track, roundStroke (thickness + 3.0f));
  901. g.setColour (juce::Colour (0xff23262e).interpolatedWith (juce::Colour (0xff3a3f4b), hover * 0.7f));
  902. g.strokePath (track, roundStroke (thickness));
  903. if (size >= 56.0f)
  904. {
  905. g.setColour (juce::Colours::white.withAlpha (0.16f + 0.1f * hover));
  906. const auto d = thickness * 0.34f;
  907. for (int i = 0; i <= 10; ++i)
  908. {
  909. const auto a = arcStart + arcRange * (float) i / 10.0f;
  910. g.fillEllipse (juce::Rectangle<float> (d, d).withCentre ({ c.x + arcR * std::sin (a), c.y - arcR * std::cos (a) }));
  911. }
  912. }
  913. // the lit value arc: a wide glow, the gradient core, a specular line and a hot tip
  914. const auto from = k.bipolar ? arcStart + arcRange * 0.5f : arcStart;
  915. const auto to = arcStart + arcRange * value;
  916. if (std::abs (to - from) > 0.002f)
  917. {
  918. const auto arc = arcPath (c, arcR, from, to);
  919. if (k.enabled && fx)
  920. {
  921. g.setColour (accent.withAlpha (0.09f + 0.08f * hover));
  922. g.strokePath (arc, roundStroke (thickness * 3.6f));
  923. g.setColour (accent.withAlpha (0.20f + 0.12f * hover));
  924. g.strokePath (arc, roundStroke (thickness * 2.0f));
  925. }
  926. g.setGradientFill (juce::ColourGradient (accent.darker (0.35f), area.getX(), area.getBottom(), accent.brighter (0.35f), area.getRight(), area.getY(), false));
  927. g.strokePath (arc, roundStroke (thickness));
  928. if (! small)
  929. {
  930. g.setColour (juce::Colours::white.withAlpha (k.enabled ? 0.38f : 0.12f));
  931. g.strokePath (arc, roundStroke (thickness * 0.28f));
  932. }
  933. }
  934. if (k.enabled && fx && std::abs (to - from) > 0.02f) // the tip of the arc burns white-hot
  935. {
  936. const juce::Point<float> tip { c.x + arcR * std::sin (to), c.y - arcR * std::cos (to) };
  937. juce::ColourGradient hot (juce::Colours::white.withAlpha (0.95f), tip.x, tip.y, accent.withAlpha (0.0f), tip.x + thickness * 1.9f, tip.y, true);
  938. hot.addColour (0.3, accent.brighter (0.5f).withAlpha (0.8f));
  939. g.setGradientFill (hot);
  940. g.fillEllipse (juce::Rectangle<float> (thickness * 3.8f, thickness * 3.8f).withCentre (tip));
  941. }
  942. if (k.bipolar) // the centre mark
  943. {
  944. g.setColour (k.enabled ? juce::Colours::white.withAlpha (0.8f) : theme::colour::textSecondary);
  945. const auto m = juce::jmax (2.0f, thickness * 0.5f);
  946. g.fillEllipse (juce::Rectangle<float> (m, m).withCentre ({ c.x, c.y - arcR - thickness * (small ? 0.9f : 1.25f) }));
  947. }
  948. // the cap: contact shadow, a turned metal side wall, a face lit from the upper left, a specular highlight and
  949. // a rim that catches the accent's light from below
  950. const auto capR = juce::jmax (2.0f, arcR - thickness * (small ? 1.3f : 1.25f));
  951. const auto cap = juce::Rectangle<float> (capR * 2.0f, capR * 2.0f).withCentre (c);
  952. if (! small)
  953. {
  954. juce::ColourGradient shadow (juce::Colours::black.withAlpha (0.75f), c.x, c.y + capR * 0.22f, juce::Colours::transparentBlack, c.x + capR * 1.3f,
  955. c.y + capR * 0.22f, true);
  956. shadow.addColour (0.7, juce::Colours::black.withAlpha (0.4f));
  957. g.setGradientFill (shadow);
  958. g.fillEllipse (cap.expanded (capR * 0.3f).translated (0.0f, capR * 0.16f));
  959. }
  960. const auto lift = hover * 0.1f;
  961. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff5a606d).brighter (lift), c.x, cap.getY(), juce::Colour (0xff121317), c.x, cap.getBottom(), false));
  962. g.fillEllipse (cap);
  963. if (capR > 8.0f)
  964. {
  965. const auto face = cap.reduced (capR * 0.11f);
  966. juce::ColourGradient faceGrad (juce::Colour (0xff434854).brighter (lift), c.x - capR * 0.35f, c.y - capR * 0.45f, juce::Colour (0xff1a1c22), c.x + capR * 0.9f,
  967. c.y + capR * 0.9f, true);
  968. faceGrad.addColour (0.5, juce::Colour (0xff2b2e36).brighter (lift));
  969. g.setGradientFill (faceGrad);
  970. g.fillEllipse (face);
  971. if (fx && capR > 14.0f) // fine concentric machining
  972. {
  973. g.setColour (juce::Colours::white.withAlpha (0.025f));
  974. for (auto rr = capR * 0.25f; rr < capR * 0.85f; rr += juce::jmax (1.6f, capR * 0.07f))
  975. g.drawEllipse (juce::Rectangle<float> (rr * 2.0f, rr * 2.0f).withCentre (c), 0.7f);
  976. }
  977. if (fx) // specular highlight
  978. {
  979. juce::ColourGradient spec (juce::Colours::white.withAlpha (0.22f + 0.08f * hover), c.x - capR * 0.28f, c.y - capR * 0.5f, juce::Colours::white.withAlpha (0.0f),
  980. c.x - capR * 0.28f + capR * 0.62f, c.y - capR * 0.5f, true);
  981. g.setGradientFill (spec);
  982. g.fillEllipse (face);
  983. }
  984. }
  985. // rim: white along the top, the accent's reflection along the bottom
  986. g.setGradientFill (juce::ColourGradient (juce::Colours::white.withAlpha (0.32f), c.x, cap.getY(),
  987. k.enabled && fx ? accent.withAlpha (0.25f + 0.35f * value) : juce::Colours::black.withAlpha (0.5f), c.x, cap.getBottom(), false));
  988. g.drawEllipse (cap.reduced (0.5f), small ? 1.0f : 1.3f);
  989. // the pointer: an LED line in the accent with a white core and a lit dot at its end
  990. const juce::Point<float> dir { std::sin (to), -std::cos (to) };
  991. const auto inner = capR * (capR > 8.0f ? 0.32f : 0.1f);
  992. const auto outer = capR * 0.8f;
  993. const auto pw = juce::jlimit (1.5f, 3.8f, size * 0.055f);
  994. juce::Path pointer;
  995. pointer.startNewSubPath (c + dir * inner);
  996. pointer.lineTo (c + dir * outer);
  997. if (k.enabled && fx)
  998. {
  999. g.setColour (accent.withAlpha (0.35f + 0.3f * hover));
  1000. g.strokePath (pointer, roundStroke (pw * 3.0f));
  1001. g.setColour (accent.brighter (0.2f));
  1002. g.strokePath (pointer, roundStroke (pw * 1.5f));
  1003. g.setColour (juce::Colours::white.withAlpha (0.95f));
  1004. g.strokePath (pointer, roundStroke (pw * 0.7f));
  1005. const auto end = c + dir * outer;
  1006. juce::ColourGradient dot (juce::Colours::white, end.x, end.y, accent.withAlpha (0.0f), end.x + pw * 2.6f, end.y, true);
  1007. dot.addColour (0.35, accent.brighter (0.4f).withAlpha (0.9f));
  1008. g.setGradientFill (dot);
  1009. g.fillEllipse (juce::Rectangle<float> (pw * 5.2f, pw * 5.2f).withCentre (end));
  1010. }
  1011. else
  1012. {
  1013. g.setColour (k.enabled ? (k.active ? accent.brighter (0.6f) : theme::colour::textPrimary) : theme::colour::textSecondary);
  1014. g.strokePath (pointer, roundStroke (pw));
  1015. }
  1016. }
  1017. } // namespace
  1018. void slider (juce::Graphics& g, juce::Rectangle<float> t, float value01, bool vertical, bool bipolar, juce::Colour accent, bool hot, bool enabled,
  1019. float thumbLength, float thumbThickness)
  1020. {
  1021. if (currentStyle == Style::themed && artkit::slider (g, t, value01, vertical, bipolar, accent, hot, enabled, thumbLength, thumbThickness)) return;
  1022. const BaseScope base;
  1023. if (currentStyle != Style::glow)
  1024. {
  1025. styles::slider (g, t, juce::jlimit (0.0f, 1.0f, value01), vertical, bipolar, accent, hot, enabled, thumbLength, thumbThickness, currentStyle);
  1026. return;
  1027. }
  1028. const auto v = juce::jlimit (0.0f, 1.0f, value01);
  1029. const auto thick = vertical ? t.getWidth() : t.getHeight();
  1030. g.setColour (juce::Colour (0xff040506));
  1031. g.fillRoundedRectangle (t.expanded (1.5f), thick * 0.5f + 1.5f);
  1032. g.setColour (juce::Colour (0xff1c1e24));
  1033. g.fillRoundedRectangle (t, thick * 0.5f);
  1034. juce::Rectangle<float> fill;
  1035. juce::Point<float> thumb;
  1036. if (vertical)
  1037. {
  1038. const auto y = t.getBottom() - t.getHeight() * v;
  1039. const auto from = bipolar ? t.getCentreY() : t.getBottom();
  1040. fill = { t.getX(), juce::jmin (y, from), t.getWidth(), std::abs (from - y) };
  1041. thumb = { t.getCentreX(), y };
  1042. }
  1043. else
  1044. {
  1045. const auto x = t.getX() + t.getWidth() * v;
  1046. const auto from = bipolar ? t.getCentreX() : t.getX();
  1047. fill = { juce::jmin (x, from), t.getY(), std::abs (from - x), t.getHeight() };
  1048. thumb = { x, t.getCentreY() };
  1049. }
  1050. const auto c = enabled ? accent : theme::colour::textDisabled;
  1051. if (enabled && ! fill.isEmpty() && ! reduced)
  1052. {
  1053. g.setColour (c.withAlpha (hot ? 0.16f : 0.10f));
  1054. g.fillRoundedRectangle (fill.expanded (thick * 1.6f), thick * 1.6f);
  1055. g.setColour (c.withAlpha (hot ? 0.34f : 0.22f));
  1056. g.fillRoundedRectangle (fill.expanded (thick * 0.7f), thick);
  1057. }
  1058. g.setGradientFill (vertical ? juce::ColourGradient (c.brighter (0.35f), 0.0f, fill.getY(), c.darker (0.35f), 0.0f, fill.getBottom(), false)
  1059. : juce::ColourGradient (c.darker (0.35f), fill.getX(), 0.0f, c.brighter (0.35f), fill.getRight(), 0.0f, false));
  1060. g.fillRoundedRectangle (fill, thick * 0.5f);
  1061. if (enabled && ! fill.isEmpty())
  1062. {
  1063. g.setColour (juce::Colours::white.withAlpha (0.3f));
  1064. if (vertical) g.fillRect (fill.withWidth (juce::jmax (1.0f, thick * 0.3f)).withX (fill.getCentreX() - thick * 0.15f));
  1065. else g.fillRect (fill.withHeight (juce::jmax (1.0f, thick * 0.3f)).withY (fill.getCentreY() - thick * 0.15f));
  1066. }
  1067. // the thumb: a raised metal cap carrying an LED line in the accent
  1068. const auto tr = vertical ? juce::Rectangle<float> (thumbLength, thumbThickness).withCentre (thumb)
  1069. : juce::Rectangle<float> (thumbThickness, thumbLength).withCentre (thumb);
  1070. g.setColour (juce::Colours::black.withAlpha (0.55f));
  1071. g.fillRoundedRectangle (tr.translated (0.0f, 2.0f).expanded (0.5f), 3.5f);
  1072. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff666c79).brighter (hot ? 0.15f : 0.0f), 0.0f, tr.getY(), juce::Colour (0xff23262d), 0.0f,
  1073. tr.getBottom(), false));
  1074. g.fillRoundedRectangle (tr, 3.0f);
  1075. g.setColour (juce::Colours::white.withAlpha (0.22f));
  1076. g.drawHorizontalLine ((int) tr.getY() + 1, tr.getX() + 2.0f, tr.getRight() - 2.0f);
  1077. g.setColour (juce::Colours::black.withAlpha (0.6f));
  1078. g.drawRoundedRectangle (tr.reduced (0.5f), 3.0f, 1.0f);
  1079. const auto led = vertical ? juce::Rectangle<float> (tr.getX() + 3.0f, thumb.y - 1.0f, tr.getWidth() - 6.0f, 2.0f)
  1080. : juce::Rectangle<float> (thumb.x - 1.0f, tr.getY() + 3.0f, 2.0f, tr.getHeight() - 6.0f);
  1081. if (enabled && ! reduced)
  1082. {
  1083. g.setColour (c.withAlpha (hot ? 0.6f : 0.4f));
  1084. g.fillRoundedRectangle (led.expanded (1.5f), 2.0f);
  1085. }
  1086. g.setColour (enabled ? (hot ? c.brighter (0.6f) : c.brighter (0.3f)) : theme::colour::textSecondary);
  1087. g.fillRoundedRectangle (led, 1.0f);
  1088. }
  1089. void button (juce::Graphics& g, juce::Rectangle<float> r, bool lit, bool hover, juce::Colour accent, float corner)
  1090. {
  1091. if (currentStyle == Style::themed && artkit::button (g, r, lit, hover, accent, corner)) return;
  1092. const BaseScope base;
  1093. if (currentStyle != Style::glow) { styles::button (g, r, lit, hover, accent, corner, currentStyle); return; }
  1094. if (lit)
  1095. {
  1096. // illuminated: the light spills out around the button
  1097. if (! reduced)
  1098. {
  1099. g.setColour (accent.withAlpha (hover ? 0.14f : 0.09f));
  1100. g.fillRoundedRectangle (r.expanded (4.0f), corner + 4.0f);
  1101. g.setColour (accent.withAlpha (hover ? 0.24f : 0.16f));
  1102. g.fillRoundedRectangle (r.expanded (2.0f), corner + 2.0f);
  1103. }
  1104. g.setColour (juce::Colour (0xff15161b));
  1105. g.fillRoundedRectangle (r, corner);
  1106. g.setGradientFill (juce::ColourGradient (accent.withAlpha (0.78f), 0.0f, r.getY(), accent.darker (0.3f).withAlpha (0.55f), 0.0f, r.getBottom(), false));
  1107. g.fillRoundedRectangle (r, corner);
  1108. g.setGradientFill (juce::ColourGradient (juce::Colours::white.withAlpha (0.22f), 0.0f, r.getY(), juce::Colours::white.withAlpha (0.0f), 0.0f, r.getCentreY(), false));
  1109. g.fillRoundedRectangle (r.withHeight (r.getHeight() * 0.5f), corner);
  1110. g.setColour (accent.brighter (0.5f));
  1111. g.drawRoundedRectangle (r.reduced (0.5f), corner, 1.0f);
  1112. return;
  1113. }
  1114. g.setColour (juce::Colours::black.withAlpha (0.45f));
  1115. g.fillRoundedRectangle (r.translated (0.0f, 1.5f), corner);
  1116. g.setGradientFill (juce::ColourGradient (juce::Colour (hover ? 0xff454a56 : 0xff3a3e48), 0.0f, r.getY(), juce::Colour (hover ? 0xff2a2d35 : 0xff222429), 0.0f,
  1117. r.getBottom(), false));
  1118. g.fillRoundedRectangle (r, corner);
  1119. g.setColour (juce::Colours::black.withAlpha (0.6f));
  1120. g.drawRoundedRectangle (r.reduced (0.5f), corner, 1.0f);
  1121. g.setColour (juce::Colours::white.withAlpha (hover ? 0.18f : 0.11f));
  1122. g.drawHorizontalLine ((int) r.getY() + 1, r.getX() + corner, r.getRight() - corner);
  1123. if (hover)
  1124. {
  1125. g.setColour (accent.withAlpha (0.45f));
  1126. g.drawRoundedRectangle (r.reduced (0.5f), corner, 1.0f);
  1127. }
  1128. }
  1129. void switchPill (juce::Graphics& g, juce::Rectangle<float> box, bool on, juce::Colour accent, bool enabled)
  1130. {
  1131. if (currentStyle == Style::themed && artkit::switchPill (g, box, on, accent, enabled)) return;
  1132. const BaseScope base;
  1133. if (currentStyle != Style::glow) { styles::switchPill (g, box, on, accent, enabled, currentStyle); return; }
  1134. const auto c = enabled ? accent : theme::colour::textSecondary;
  1135. const auto rr = box.getHeight() * 0.5f;
  1136. if (on)
  1137. {
  1138. if (! reduced)
  1139. {
  1140. g.setColour (c.withAlpha (0.16f));
  1141. g.fillRoundedRectangle (box.expanded (3.5f), rr + 3.5f);
  1142. g.setColour (c.withAlpha (0.3f));
  1143. g.fillRoundedRectangle (box.expanded (1.5f), rr + 1.5f);
  1144. }
  1145. g.setGradientFill (juce::ColourGradient (c.brighter (0.3f), 0.0f, box.getY(), c.darker (0.25f), 0.0f, box.getBottom(), false));
  1146. }
  1147. else
  1148. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff050607), 0.0f, box.getY(), juce::Colour (0xff15171c), 0.0f, box.getBottom(), false));
  1149. g.fillRoundedRectangle (box, rr);
  1150. g.setColour (juce::Colours::black.withAlpha (0.6f));
  1151. g.drawRoundedRectangle (box.reduced (0.5f), rr, 1.0f);
  1152. const auto d = box.getHeight() - 2.0f;
  1153. const auto knobR = juce::Rectangle<float> (d, d).withCentre ({ on ? box.getRight() - d * 0.5f - 1.0f : box.getX() + d * 0.5f + 1.0f, box.getCentreY() });
  1154. g.setColour (juce::Colours::black.withAlpha (0.45f));
  1155. g.fillEllipse (knobR.translated (0.0f, 1.0f));
  1156. g.setGradientFill (juce::ColourGradient (on ? juce::Colours::white : juce::Colour (0xff7a808c), 0.0f, knobR.getY(), on ? juce::Colour (0xffd3d6dd) : juce::Colour (0xff42464f),
  1157. 0.0f, knobR.getBottom(), false));
  1158. g.fillEllipse (knobR);
  1159. }
  1160. void selector (juce::Graphics& g, juce::Rectangle<float> r, bool hover, float corner)
  1161. {
  1162. if (currentStyle == Style::themed && artkit::selector (g, r, hover, corner)) return;
  1163. const BaseScope base;
  1164. if (currentStyle != Style::glow) { styles::selector (g, r, hover, corner, currentStyle); return; }
  1165. g.setColour (juce::Colours::black.withAlpha (0.45f));
  1166. g.fillRoundedRectangle (r.translated (0.0f, 1.5f), corner);
  1167. g.setGradientFill (juce::ColourGradient (juce::Colour (hover ? 0xff464b57 : 0xff393d47), 0.0f, r.getY(), juce::Colour (hover ? 0xff2b2e36 : 0xff23252c), 0.0f,
  1168. r.getBottom(), false));
  1169. g.fillRoundedRectangle (r, corner);
  1170. g.setColour (juce::Colours::black.withAlpha (0.6f));
  1171. g.drawRoundedRectangle (r.reduced (0.5f), corner, 1.0f);
  1172. g.setColour (juce::Colours::white.withAlpha (hover ? 0.2f : 0.12f));
  1173. g.drawHorizontalLine ((int) r.getY() + 1, r.getX() + corner, r.getRight() - corner);
  1174. }
  1175. namespace
  1176. {
  1177. // the ladder of LED segments over a meter (gaps every 3 px)
  1178. void segmentGaps (juce::Graphics& g, juce::Rectangle<float> r, juce::Rectangle<float> upTo, bool vertical)
  1179. {
  1180. g.setColour (juce::Colour (0xff060708).withAlpha (0.75f));
  1181. if (vertical)
  1182. for (auto y = r.getBottom() - 3.0f; y > upTo.getY(); y -= 3.0f) g.drawHorizontalLine ((int) y, r.getX(), r.getRight());
  1183. else
  1184. for (auto x = r.getX() + 3.0f; x < upTo.getRight(); x += 3.0f) g.drawVerticalLine ((int) x, r.getY(), r.getBottom());
  1185. }
  1186. } // namespace
  1187. void meter (juce::Graphics& g, juce::Rectangle<float> r, float level01, float peak01, bool vertical)
  1188. {
  1189. const BaseScope base;
  1190. if (currentStyle != Style::glow) { styles::meter (g, r, juce::jlimit (0.0f, 1.0f, level01), juce::jlimit (0.0f, 1.0f, peak01), vertical, currentStyle); return; }
  1191. g.setColour (juce::Colour (0xff040506));
  1192. g.fillRoundedRectangle (r.expanded (1.0f), 2.5f);
  1193. const auto lv = juce::jlimit (0.0f, 1.0f, level01);
  1194. auto gradient = [&] (float alpha) {
  1195. auto gr = vertical ? juce::ColourGradient (theme::colour::meterLow.withAlpha (alpha), 0.0f, r.getBottom(), theme::colour::meterClip.withAlpha (alpha), 0.0f, r.getY(), false)
  1196. : juce::ColourGradient (theme::colour::meterLow.withAlpha (alpha), r.getX(), 0.0f, theme::colour::meterClip.withAlpha (alpha), r.getRight(), 0.0f, false);
  1197. gr.addColour (0.72, theme::colour::meterMid.withAlpha (alpha));
  1198. return gr;
  1199. };
  1200. // the unlit LEDs: the whole ladder, faint
  1201. g.setGradientFill (gradient (0.10f));
  1202. g.fillRoundedRectangle (r, 2.0f);
  1203. if (lv > 0.0f)
  1204. {
  1205. const auto lit = vertical ? r.withTop (r.getBottom() - r.getHeight() * lv) : r.withWidth (r.getWidth() * lv);
  1206. if (! reduced)
  1207. {
  1208. g.setGradientFill (gradient (0.22f));
  1209. g.fillRoundedRectangle (vertical ? lit.expanded (2.0f, 0.0f) : lit.expanded (0.0f, 2.0f), 3.0f);
  1210. }
  1211. g.setGradientFill (gradient (1.0f));
  1212. g.fillRoundedRectangle (lit, 2.0f);
  1213. // the hot edge
  1214. g.setColour (juce::Colours::white.withAlpha (0.55f));
  1215. if (vertical) g.fillRect (lit.withHeight (1.0f));
  1216. else g.fillRect (lit.withLeft (lit.getRight() - 1.0f));
  1217. }
  1218. segmentGaps (g, r, r, vertical);
  1219. // glass
  1220. g.setColour (juce::Colours::white.withAlpha (0.05f));
  1221. if (vertical) g.fillRect (r.withWidth (r.getWidth() * 0.4f));
  1222. else g.fillRect (r.withHeight (r.getHeight() * 0.4f));
  1223. const auto pk = juce::jlimit (0.0f, 1.0f, peak01);
  1224. if (pk > 0.01f)
  1225. {
  1226. const auto c = pk > 0.97f ? theme::colour::meterClip : juce::Colours::white;
  1227. const auto tick = vertical ? juce::Rectangle<float> (r.getX(), r.getBottom() - r.getHeight() * pk - 1.0f, r.getWidth(), 2.0f)
  1228. : juce::Rectangle<float> (r.getX() + r.getWidth() * pk - 1.0f, r.getY(), 2.0f, r.getHeight());
  1229. if (! reduced)
  1230. {
  1231. g.setColour (c.withAlpha (0.3f));
  1232. g.fillRect (tick.expanded (1.5f));
  1233. }
  1234. g.setColour (c.withAlpha (0.95f));
  1235. g.fillRect (tick);
  1236. }
  1237. }
  1238. void meterSolid (juce::Graphics& g, juce::Rectangle<float> r, float level01, juce::Colour c, bool fromTop)
  1239. {
  1240. const BaseScope base;
  1241. if (currentStyle != Style::glow) { styles::meterSolid (g, r, juce::jlimit (0.0f, 1.0f, level01), c, fromTop, currentStyle); return; }
  1242. g.setColour (juce::Colour (0xff040506));
  1243. g.fillRoundedRectangle (r.expanded (1.0f), 2.5f);
  1244. g.setColour (c.withAlpha (0.08f));
  1245. g.fillRoundedRectangle (r, 2.0f);
  1246. const auto lv = juce::jlimit (0.0f, 1.0f, level01);
  1247. if (lv > 0.0f)
  1248. {
  1249. const auto lit = fromTop ? r.withHeight (r.getHeight() * lv) : r.withTop (r.getBottom() - r.getHeight() * lv);
  1250. if (! reduced)
  1251. {
  1252. g.setColour (c.withAlpha (0.25f));
  1253. g.fillRoundedRectangle (lit.expanded (2.0f, 0.0f), 3.0f);
  1254. }
  1255. g.setGradientFill (juce::ColourGradient (c.brighter (0.35f), 0.0f, lit.getY(), c.darker (0.3f), 0.0f, lit.getBottom(), false));
  1256. g.fillRoundedRectangle (lit, 2.0f);
  1257. g.setColour (juce::Colours::white.withAlpha (0.5f));
  1258. g.fillRect (fromTop ? lit.withTop (lit.getBottom() - 1.0f) : lit.withHeight (1.0f));
  1259. }
  1260. g.setColour (juce::Colours::white.withAlpha (0.05f));
  1261. g.fillRect (r.withWidth (r.getWidth() * 0.4f));
  1262. }
  1263. void glowStroke (juce::Graphics& g, const juce::Path& p, juce::Colour c, float thickness, float glow)
  1264. {
  1265. const BaseScope base;
  1266. if (currentStyle != Style::glow) { styles::glowStroke (g, p, c, thickness, glow, currentStyle); return; }
  1267. if (glow > 0.0f && ! reduced)
  1268. {
  1269. g.setColour (c.withAlpha (0.07f * glow));
  1270. g.strokePath (p, roundStroke (thickness * 6.0f));
  1271. g.setColour (c.withAlpha (0.18f * glow));
  1272. g.strokePath (p, roundStroke (thickness * 2.8f));
  1273. }
  1274. g.setColour (c);
  1275. g.strokePath (p, roundStroke (thickness));
  1276. if (glow > 0.0f && thickness >= 1.4f && ! reduced) // a white-hot core
  1277. {
  1278. g.setColour (c.brighter (0.9f).withAlpha (0.75f * glow));
  1279. g.strokePath (p, roundStroke (thickness * 0.4f));
  1280. }
  1281. }
  1282. void valuePlate (juce::Graphics& g, juce::Rectangle<float> r, float corner)
  1283. {
  1284. if (currentStyle == Style::themed && artkit::valuePlate (g, r, corner)) return;
  1285. const BaseScope base;
  1286. if (currentStyle != Style::glow) { styles::valuePlate (g, r, corner, currentStyle); return; }
  1287. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff040507), 0.0f, r.getY(), juce::Colour (0xff101116), 0.0f, r.getBottom(), false));
  1288. g.fillRoundedRectangle (r, corner);
  1289. const auto sh = juce::jmin (5.0f, r.getHeight() * 0.35f);
  1290. g.setGradientFill (juce::ColourGradient (juce::Colours::black.withAlpha (0.5f), 0.0f, r.getY(), juce::Colours::transparentBlack, 0.0f, r.getY() + sh, false));
  1291. g.fillRoundedRectangle (r.withHeight (sh), corner);
  1292. g.setColour (juce::Colours::black.withAlpha (0.7f));
  1293. g.drawRoundedRectangle (r.reduced (0.5f), corner, 1.0f);
  1294. g.setColour (juce::Colours::white.withAlpha (0.08f));
  1295. g.drawHorizontalLine ((int) r.getBottom(), r.getX() + corner, r.getRight() - corner);
  1296. }
  1297. } // namespace lynx::skin