| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114 |
- #include "ui/Icons.h"
- #include "ui/Motion.h"
- #include <cmath>
- #include <map>
- #include "ui/Theme.h"
- namespace lynx
- {
- namespace icons
- {
- namespace
- {
- constexpr float pi = juce::MathConstants<float>::pi;
- void line (juce::Path& p, float x1, float y1, float x2, float y2)
- {
- p.startNewSubPath (x1, y1);
- p.lineTo (x2, y2);
- }
- void roundRect (juce::Path& p, float x, float y, float w, float h, float r)
- {
- p.addRoundedRectangle (x, y, w, h, r);
- }
- void polyline (juce::Path& p, std::initializer_list<juce::Point<float>> points, bool close = false)
- {
- bool first = true;
- for (auto pt : points)
- {
- if (first)
- p.startNewSubPath (pt);
- else
- p.lineTo (pt);
- first = false;
- }
- if (close)
- p.closeSubPath();
- }
- Shape make (Icon icon)
- {
- Shape s;
- auto& st = s.stroke;
- auto& fi = s.fill;
- // a page with a folded corner (file icons)
- auto page = [&st] {
- juce::Path p;
- polyline (p, { { 6.0f, 3.5f }, { 13.5f, 3.5f }, { 18.0f, 8.0f }, { 18.0f, 20.5f }, { 6.0f, 20.5f } }, true);
- st.addPath (p.createPathWithRoundedCorners (1.5f));
- polyline (st, { { 13.5f, 3.5f }, { 13.5f, 8.0f }, { 18.0f, 8.0f } });
- };
- // a speaker cone (mute and playback tools)
- auto speaker = [&st] {
- juce::Path p;
- polyline (p, { { 3.5f, 9.5f }, { 7.0f, 9.5f }, { 11.5f, 5.5f }, { 11.5f, 18.5f }, { 7.0f, 14.5f }, { 3.5f, 14.5f } }, true);
- st.addPath (p.createPathWithRoundedCorners (1.2f));
- };
- // a window outline with a title band (view icons)
- auto window = [&st] {
- roundRect (st, 3.5f, 4.5f, 17.0f, 15.0f, 2.0f);
- };
- // a horseshoe magnet with solid poles, opening downwards (the way FL users know the snap), scaled by `k` and moved
- // by (dx, dy) (snap icons)
- auto magnet = [&st, &fi] (float k, float dx, float dy) {
- const auto t = juce::AffineTransform::verticalFlip (24.0f).scaled (k).translated (dx, dy);
- juce::Path m;
- m.startNewSubPath (4.5f, 4.0f);
- m.lineTo (4.5f, 12.5f);
- m.addCentredArc (12.0f, 12.5f, 7.5f, 7.5f, 0.0f, pi * 1.5f, pi * 0.5f, false);
- m.lineTo (19.5f, 4.0f);
- m.lineTo (15.0f, 4.0f);
- m.lineTo (15.0f, 12.5f);
- m.addCentredArc (12.0f, 12.5f, 3.0f, 3.0f, 0.0f, pi * 0.5f, pi * 1.5f, false);
- m.lineTo (9.0f, 4.0f);
- m.closeSubPath();
- st.addPath (m, t);
- juce::Path poles;
- poles.addRectangle (4.5f, 4.0f, 4.5f, 3.5f);
- poles.addRectangle (15.0f, 4.0f, 4.5f, 3.5f);
- fi.addPath (poles, t);
- };
- switch (icon)
- {
- case Icon::none:
- break;
- // --- transport (solid) ---
- case Icon::play:
- {
- juce::Path tri;
- tri.addTriangle (7.0f, 4.5f, 7.0f, 19.5f, 19.5f, 12.0f);
- fi = tri.createPathWithRoundedCorners (2.0f);
- break;
- }
- case Icon::pause:
- fi.addRoundedRectangle (6.0f, 5.0f, 4.5f, 14.0f, 1.25f);
- fi.addRoundedRectangle (13.5f, 5.0f, 4.5f, 14.0f, 1.25f);
- break;
- case Icon::stop:
- fi.addRoundedRectangle (5.5f, 5.5f, 13.0f, 13.0f, 2.25f);
- break;
- case Icon::record:
- fi.addEllipse (5.0f, 5.0f, 14.0f, 14.0f);
- break;
- // --- small glyphs ---
- case Icon::chevronDown:
- polyline (st, { { 7.0f, 9.5f }, { 12.0f, 14.5f }, { 17.0f, 9.5f } });
- break;
- case Icon::more:
- for (float x : { 5.5f, 12.0f, 18.5f })
- fi.addEllipse (x - 1.75f, 10.25f, 3.5f, 3.5f);
- break;
- case Icon::plus:
- line (st, 12.0f, 5.0f, 12.0f, 19.0f);
- line (st, 5.0f, 12.0f, 19.0f, 12.0f);
- break;
- case Icon::check:
- polyline (st, { { 5.0f, 12.5f }, { 9.5f, 17.0f }, { 19.0f, 7.0f } });
- break;
- case Icon::close:
- line (st, 6.5f, 6.5f, 17.5f, 17.5f);
- line (st, 17.5f, 6.5f, 6.5f, 17.5f);
- break;
- case Icon::minimise:
- line (st, 6.0f, 12.0f, 18.0f, 12.0f);
- break;
- case Icon::maximise:
- roundRect (st, 5.5f, 5.5f, 13.0f, 13.0f, 2.0f);
- line (st, 5.5f, 9.0f, 18.5f, 9.0f);
- break;
- case Icon::restore: // two stacked windows
- roundRect (st, 4.5f, 8.5f, 11.0f, 11.0f, 1.75f);
- polyline (st, { { 8.5f, 4.5f }, { 17.5f, 4.5f }, { 19.5f, 6.5f }, { 19.5f, 15.5f } });
- break;
- case Icon::panelMenu: // three bars of decreasing length: "this window's options"
- line (st, 5.0f, 7.0f, 19.0f, 7.0f);
- line (st, 5.0f, 12.0f, 16.0f, 12.0f);
- line (st, 5.0f, 17.0f, 13.0f, 17.0f);
- break;
- // --- modes ---
- case Icon::pattern: // a 2x2 block of steps, one lit
- roundRect (st, 4.0f, 4.0f, 6.5f, 6.5f, 1.5f);
- roundRect (st, 4.0f, 13.5f, 6.5f, 6.5f, 1.5f);
- roundRect (st, 13.5f, 13.5f, 6.5f, 6.5f, 1.5f);
- fi.addRoundedRectangle (12.75f, 3.25f, 8.0f, 8.0f, 2.0f);
- break;
- case Icon::song: // clips staggered along three lanes
- fi.addRoundedRectangle (3.5f, 4.5f, 9.0f, 4.0f, 1.25f);
- fi.addRoundedRectangle (9.0f, 10.0f, 11.5f, 4.0f, 1.25f);
- fi.addRoundedRectangle (5.5f, 15.5f, 8.0f, 4.0f, 1.25f);
- break;
- case Icon::metronome:
- {
- juce::Path body;
- polyline (body, { { 9.0f, 3.5f }, { 15.0f, 3.5f }, { 19.0f, 20.5f }, { 5.0f, 20.5f } }, true);
- st.addPath (body.createPathWithRoundedCorners (2.0f));
- line (st, 12.0f, 16.5f, 17.5f, 6.0f);
- line (st, 7.0f, 16.5f, 17.0f, 16.5f);
- fi.addEllipse (14.0f, 8.0f, 3.5f, 3.5f);
- break;
- }
- // --- file ---
- case Icon::newFile:
- page();
- line (st, 12.0f, 11.0f, 12.0f, 17.0f);
- line (st, 9.0f, 14.0f, 15.0f, 14.0f);
- break;
- case Icon::file:
- page();
- break;
- case Icon::folder:
- {
- juce::Path f;
- polyline (f, { { 3.5f, 5.5f }, { 9.0f, 5.5f }, { 11.0f, 7.5f }, { 20.5f, 7.5f }, { 20.5f, 18.5f }, { 3.5f, 18.5f } }, true);
- st.addPath (f.createPathWithRoundedCorners (1.75f));
- break;
- }
- case Icon::open: // a folder with its front flap tipped open
- {
- juce::Path back;
- polyline (back, { { 4.0f, 18.5f }, { 3.5f, 5.5f }, { 9.0f, 5.5f }, { 11.0f, 7.5f }, { 18.0f, 7.5f }, { 18.0f, 10.5f } });
- st.addPath (back.createPathWithRoundedCorners (1.5f));
- juce::Path flap;
- polyline (flap, { { 4.0f, 18.5f }, { 7.0f, 10.5f }, { 21.0f, 10.5f }, { 18.0f, 18.5f } }, true);
- st.addPath (flap.createPathWithRoundedCorners (1.5f));
- break;
- }
- case Icon::save: // a disk
- {
- juce::Path body;
- polyline (body, { { 4.0f, 4.0f }, { 16.5f, 4.0f }, { 20.0f, 7.5f }, { 20.0f, 20.0f }, { 4.0f, 20.0f } }, true);
- st.addPath (body.createPathWithRoundedCorners (2.0f));
- polyline (st, { { 8.0f, 4.0f }, { 8.0f, 8.5f }, { 15.0f, 8.5f }, { 15.0f, 4.0f } });
- roundRect (st, 7.5f, 13.0f, 9.0f, 7.0f, 1.0f);
- break;
- }
- case Icon::exportAudio: // a waveform leaving a tray
- polyline (st, { { 3.5f, 14.0f }, { 3.5f, 19.5f }, { 20.5f, 19.5f }, { 20.5f, 14.0f } });
- line (st, 12.0f, 15.5f, 12.0f, 4.0f);
- polyline (st, { { 8.0f, 8.0f }, { 12.0f, 4.0f }, { 16.0f, 8.0f } });
- break;
- case Icon::settings: // three sliders
- line (st, 4.0f, 7.0f, 20.0f, 7.0f);
- line (st, 4.0f, 12.0f, 20.0f, 12.0f);
- line (st, 4.0f, 17.0f, 20.0f, 17.0f);
- fi.addEllipse (6.5f, 4.5f, 5.0f, 5.0f);
- fi.addEllipse (13.0f, 9.5f, 5.0f, 5.0f);
- fi.addEllipse (8.5f, 14.5f, 5.0f, 5.0f);
- break;
- case Icon::help:
- st.addEllipse (3.5f, 3.5f, 17.0f, 17.0f);
- st.startNewSubPath (9.5f, 10.0f);
- st.addCentredArc (12.0f, 10.0f, 2.5f, 2.5f, 0.0f, -pi * 0.5f, pi * 0.7f, false);
- st.lineTo (12.0f, 13.5f);
- fi.addEllipse (10.9f, 15.6f, 2.2f, 2.2f);
- break;
- case Icon::undo:
- case Icon::redo:
- {
- juce::Path p;
- p.startNewSubPath (19.0f, 18.5f);
- p.cubicTo (19.0f, 12.0f, 15.0f, 9.0f, 5.5f, 9.0f);
- polyline (p, { { 9.5f, 5.0f }, { 5.5f, 9.0f }, { 9.5f, 13.0f } });
- if (icon == Icon::redo)
- p.applyTransform (juce::AffineTransform::scale (-1.0f, 1.0f, 12.0f, 12.0f));
- st.addPath (p);
- break;
- }
- // --- views (the window buttons) ---
- case Icon::playlist: // clips on lanes inside a window
- window();
- fi.addRoundedRectangle (6.0f, 7.5f, 6.5f, 2.5f, 0.75f);
- fi.addRoundedRectangle (10.5f, 11.0f, 7.5f, 2.5f, 0.75f);
- fi.addRoundedRectangle (6.0f, 14.5f, 4.5f, 2.5f, 0.75f);
- fi.addRoundedRectangle (12.5f, 14.5f, 5.5f, 2.5f, 0.75f);
- break;
- case Icon::channelRack: // three channels: a name pad and a row of steps each
- for (int r = 0; r < 3; ++r)
- {
- const auto y = 4.5f + (float) r * 5.75f;
- roundRect (st, 3.5f, y, 6.5f, 3.5f, 1.0f);
- for (int c = 0; c < 3; ++c)
- {
- const auto x = 12.5f + (float) c * 3.0f;
- if ((r + c) % 2 == 0)
- fi.addRoundedRectangle (x - 0.25f, y - 0.25f, 2.5f, 4.0f, 0.6f);
- else
- fi.addRoundedRectangle (x + 0.5f, y + 1.25f, 1.0f, 1.0f, 0.3f);
- }
- }
- break;
- case Icon::pianoRoll: // a keyboard edge and notes
- window();
- line (st, 8.0f, 4.5f, 8.0f, 19.5f);
- line (st, 3.5f, 9.5f, 6.0f, 9.5f);
- line (st, 3.5f, 14.5f, 6.0f, 14.5f);
- fi.addRoundedRectangle (10.0f, 7.0f, 4.5f, 2.5f, 0.75f);
- fi.addRoundedRectangle (13.0f, 10.75f, 5.5f, 2.5f, 0.75f);
- fi.addRoundedRectangle (10.5f, 14.5f, 4.0f, 2.5f, 0.75f);
- break;
- case Icon::mixer: // three faders
- for (int i = 0; i < 3; ++i)
- line (st, 6.0f + (float) i * 6.0f, 4.0f, 6.0f + (float) i * 6.0f, 20.0f);
- fi.addRoundedRectangle (3.5f, 12.0f, 5.0f, 3.5f, 1.0f);
- fi.addRoundedRectangle (9.5f, 6.5f, 5.0f, 3.5f, 1.0f);
- fi.addRoundedRectangle (15.5f, 14.5f, 5.0f, 3.5f, 1.0f);
- break;
- case Icon::browser: // a tree: a folder and two items under it
- roundRect (st, 3.5f, 4.0f, 6.0f, 5.0f, 1.25f);
- polyline (st, { { 6.5f, 9.0f }, { 6.5f, 17.5f }, { 10.0f, 17.5f } });
- line (st, 6.5f, 12.5f, 10.0f, 12.5f);
- line (st, 12.5f, 6.5f, 20.5f, 6.5f);
- line (st, 13.0f, 12.5f, 20.5f, 12.5f);
- line (st, 13.0f, 17.5f, 18.0f, 17.5f);
- break;
- case Icon::pluginPicker: // a plug
- {
- line (st, 9.0f, 3.5f, 9.0f, 7.5f);
- line (st, 15.0f, 3.5f, 15.0f, 7.5f);
- juce::Path body;
- polyline (body, { { 5.5f, 7.5f }, { 18.5f, 7.5f }, { 18.5f, 11.0f }, { 14.5f, 16.0f }, { 9.5f, 16.0f }, { 5.5f, 11.0f } }, true);
- st.addPath (body.createPathWithRoundedCorners (1.75f));
- line (st, 12.0f, 16.0f, 12.0f, 20.5f);
- break;
- }
- // --- content ---
- case Icon::envelope: // an ADSR line on a base line (attack up, decay, sustain, release)
- polyline (st, { { 3.5f, 18.5f }, { 8.0f, 5.5f }, { 11.5f, 11.0f }, { 15.5f, 11.0f }, { 20.5f, 18.5f } });
- line (st, 3.5f, 20.0f, 20.5f, 20.0f);
- break;
- case Icon::wrench: // an open-end wrench, head at the upper right
- {
- juce::Path w;
- w.startNewSubPath (5.0f, 19.0f);
- w.lineTo (12.5f, 11.5f);
- st.addPath (w);
- // the head: a ring open towards the upper right (the jaws)
- st.addCentredArc (15.5f, 8.5f, 4.5f, 4.5f, 0.0f, pi * 0.55f, pi * 1.95f, true);
- break;
- }
- case Icon::audioFile: // a short waveform
- {
- const float heights[] = { 5.0f, 11.0f, 16.0f, 8.0f, 12.0f, 4.0f };
- for (int i = 0; i < 6; ++i)
- {
- const auto x = 4.5f + (float) i * 3.0f;
- line (st, x, 12.0f - heights[i] / 2.0f, x, 12.0f + heights[i] / 2.0f);
- }
- break;
- }
- case Icon::plugin: // a module with a jack
- roundRect (st, 4.0f, 6.5f, 16.0f, 12.0f, 2.0f);
- line (st, 8.5f, 3.5f, 8.5f, 6.5f);
- line (st, 15.5f, 3.5f, 15.5f, 6.5f);
- st.addEllipse (9.5f, 10.0f, 5.0f, 5.0f);
- break;
- case Icon::preset: // a knob
- st.addCentredArc (12.0f, 12.0f, 8.0f, 8.0f, 0.0f, -pi * 0.75f, pi * 0.75f, true);
- line (st, 12.0f, 12.0f, 15.5f, 8.5f);
- break;
- case Icon::project: // a diamond with a core
- {
- juce::Path d;
- polyline (d, { { 12.0f, 3.0f }, { 20.0f, 12.0f }, { 12.0f, 21.0f }, { 4.0f, 12.0f } }, true);
- st.addPath (d.createPathWithRoundedCorners (2.0f));
- fi.addEllipse (9.75f, 9.75f, 4.5f, 4.5f);
- break;
- }
- // --- edit tools ---
- case Icon::draw: // pencil
- {
- juce::Path p;
- polyline (p, { { 15.5f, 4.0f }, { 20.0f, 8.5f }, { 9.0f, 19.5f }, { 4.0f, 20.0f }, { 4.5f, 15.0f } }, true);
- st.addPath (p.createPathWithRoundedCorners (1.25f));
- line (st, 13.0f, 6.5f, 17.5f, 11.0f);
- break;
- }
- case Icon::brush: // a round brush: handle, ferrule and a filled tip
- {
- line (st, 20.0f, 4.0f, 13.5f, 10.5f);
- juce::Path ferrule;
- polyline (ferrule, { { 11.5f, 9.5f }, { 14.5f, 12.5f }, { 12.5f, 14.5f }, { 9.5f, 11.5f } }, true);
- st.addPath (ferrule.createPathWithRoundedCorners (0.75f));
- juce::Path tip;
- tip.startNewSubPath (9.0f, 12.5f);
- tip.quadraticTo (4.0f, 13.0f, 3.5f, 20.5f);
- tip.quadraticTo (11.0f, 20.0f, 11.5f, 15.0f);
- tip.closeSubPath();
- fi.addPath (tip);
- break;
- }
- case Icon::erase: // an eraser on a line
- {
- juce::Path p;
- polyline (p, { { 13.0f, 4.0f }, { 20.0f, 11.0f }, { 12.0f, 19.0f }, { 7.5f, 19.0f }, { 4.0f, 15.5f } }, true);
- st.addPath (p.createPathWithRoundedCorners (1.25f));
- line (st, 8.5f, 8.5f, 15.5f, 15.5f);
- line (st, 12.0f, 19.0f, 20.5f, 19.0f);
- break;
- }
- case Icon::mute: // a speaker with a cross
- speaker();
- line (st, 15.0f, 9.0f, 20.5f, 15.0f);
- line (st, 20.5f, 9.0f, 15.0f, 15.0f);
- break;
- case Icon::listen: // a speaker with two waves (playback tool)
- speaker();
- st.addCentredArc (12.0f, 12.0f, 3.5f, 3.5f, 0.0f, pi * 0.25f, pi * 0.75f, true);
- st.addCentredArc (12.0f, 12.0f, 7.5f, 7.5f, 0.0f, pi * 0.22f, pi * 0.78f, true);
- break;
- case Icon::knife: // a blade with a handle, cutting down to the left
- {
- juce::Path blade;
- polyline (blade, { { 4.0f, 20.0f }, { 13.5f, 8.0f }, { 17.0f, 11.5f } }, true);
- st.addPath (blade.createPathWithRoundedCorners (1.25f));
- line (st, 15.5f, 9.5f, 20.0f, 5.0f);
- break;
- }
- case Icon::select: // the four corners of a selection box
- {
- const float a = 4.0f, b = 20.0f, l = 4.5f;
- polyline (st, { { a, a + l }, { a, a }, { a + l, a } });
- polyline (st, { { b - l, a }, { b, a }, { b, a + l } });
- polyline (st, { { b, b - l }, { b, b }, { b - l, b } });
- polyline (st, { { a + l, b }, { a, b }, { a, b - l } });
- fi.addRoundedRectangle (9.5f, 9.5f, 5.0f, 5.0f, 1.0f);
- break;
- }
- case Icon::slice:
- case Icon::scissors:
- st.addEllipse (3.5f, 14.0f, 6.0f, 6.0f);
- st.addEllipse (14.5f, 14.0f, 6.0f, 6.0f);
- line (st, 8.5f, 15.0f, 17.5f, 3.5f);
- line (st, 15.5f, 15.0f, 6.5f, 3.5f);
- break;
- case Icon::zoom: // a magnifier with a plus
- st.addEllipse (3.5f, 3.5f, 13.0f, 13.0f);
- line (st, 14.5f, 14.5f, 20.5f, 20.5f);
- line (st, 10.0f, 7.0f, 10.0f, 13.0f);
- line (st, 7.0f, 10.0f, 13.0f, 10.0f);
- break;
- case Icon::deleteTool: // FL's delete tool: a ring crossed by a slash (round 190ig)
- st.addEllipse (4.5f, 4.5f, 15.0f, 15.0f);
- line (st, 6.9f, 17.1f, 17.1f, 6.9f);
- break;
- case Icon::slipArrows: // FL's slip tool: two solid arrowheads pointing apart (round 190ig)
- fi.addTriangle (3.0f, 12.0f, 10.5f, 6.5f, 10.5f, 17.5f);
- fi.addTriangle (21.0f, 12.0f, 13.5f, 6.5f, 13.5f, 17.5f);
- break;
- case Icon::slip: // a fixed frame with its content sliding inside
- roundRect (st, 3.5f, 5.5f, 17.0f, 13.0f, 2.0f);
- polyline (st, { { 9.0f, 9.5f }, { 6.5f, 12.0f }, { 9.0f, 14.5f } });
- polyline (st, { { 15.0f, 9.5f }, { 17.5f, 12.0f }, { 15.0f, 14.5f } });
- line (st, 7.0f, 12.0f, 17.0f, 12.0f);
- break;
- case Icon::ghost: // two overlapping notes, the back one hollow
- roundRect (st, 3.5f, 5.5f, 12.0f, 5.5f, 1.5f);
- fi.addRoundedRectangle (8.5f, 13.0f, 12.0f, 5.5f, 1.5f);
- break;
- case Icon::link:
- roundRect (st, 3.0f, 8.5f, 11.0f, 7.0f, 3.5f);
- roundRect (st, 10.0f, 8.5f, 11.0f, 7.0f, 3.5f);
- break;
- case Icon::magnet: // snap: a horseshoe magnet, its two poles solid (round 170e: the open "U" read as a letter)
- magnet (1.0f, 0.0f, 0.0f);
- break;
- // --- workspace and control contract ---
- case Icon::detach: // a window with an arrow leaving its corner
- polyline (st, { { 10.5f, 4.5f }, { 6.0f, 4.5f }, { 4.5f, 6.0f }, { 4.5f, 18.0f }, { 6.0f, 19.5f }, { 18.0f, 19.5f }, { 19.5f, 18.0f }, { 19.5f, 13.5f } });
- line (st, 12.0f, 12.0f, 19.5f, 4.5f);
- polyline (st, { { 14.0f, 4.5f }, { 19.5f, 4.5f }, { 19.5f, 10.0f } });
- break;
- case Icon::dock: // an arrow going into a window's corner
- polyline (st, { { 10.5f, 4.5f }, { 6.0f, 4.5f }, { 4.5f, 6.0f }, { 4.5f, 18.0f }, { 6.0f, 19.5f }, { 18.0f, 19.5f }, { 19.5f, 18.0f }, { 19.5f, 13.5f } });
- line (st, 19.5f, 4.5f, 12.0f, 12.0f);
- polyline (st, { { 12.0f, 6.5f }, { 12.0f, 12.0f }, { 17.5f, 12.0f } });
- break;
- case Icon::keyboard: // a small piano: outline, white-key gaps, two black keys
- roundRect (st, 3.0f, 6.0f, 18.0f, 12.0f, 2.0f);
- line (st, 9.0f, 13.0f, 9.0f, 18.0f);
- line (st, 15.0f, 13.0f, 15.0f, 18.0f);
- fi.addRoundedRectangle (7.25f, 6.0f, 3.5f, 7.0f, 0.75f);
- fi.addRoundedRectangle (13.25f, 6.0f, 3.5f, 7.0f, 0.75f);
- break;
- case Icon::automate: // a curve through two points
- {
- juce::Path c;
- c.startNewSubPath (4.0f, 17.0f);
- c.cubicTo (9.0f, 17.0f, 10.0f, 7.0f, 15.0f, 7.0f);
- c.lineTo (20.5f, 7.0f);
- st.addPath (c);
- fi.addEllipse (2.0f, 15.0f, 4.0f, 4.0f);
- fi.addEllipse (13.0f, 5.0f, 4.0f, 4.0f);
- break;
- }
- case Icon::rightClick: // a mouse with the right button lit
- {
- roundRect (st, 6.5f, 3.5f, 11.0f, 17.0f, 5.5f);
- line (st, 6.5f, 10.5f, 17.5f, 10.5f);
- line (st, 12.0f, 3.5f, 12.0f, 10.5f);
- juce::Path b;
- b.startNewSubPath (12.0f, 3.5f);
- b.lineTo (12.0f, 10.5f);
- b.lineTo (17.5f, 10.5f);
- b.lineTo (17.5f, 9.0f);
- b.quadraticTo (17.5f, 3.5f, 12.0f, 3.5f);
- b.closeSubPath();
- fi.addPath (b);
- break;
- }
- case Icon::tap: // a dot with two rings
- fi.addEllipse (9.5f, 9.5f, 5.0f, 5.0f);
- st.addCentredArc (12.0f, 12.0f, 5.5f, 5.5f, 0.0f, -pi * 0.35f, pi * 0.35f, true);
- st.addCentredArc (12.0f, 12.0f, 8.5f, 8.5f, 0.0f, -pi * 0.3f, pi * 0.3f, true);
- break;
- case Icon::mic: // recording options: a microphone
- roundRect (st, 9.0f, 3.0f, 6.0f, 11.0f, 3.0f);
- st.startNewSubPath (18.5f, 11.0f);
- st.addCentredArc (12.0f, 11.0f, 6.5f, 6.0f, 0.0f, pi * 0.5f, pi * 1.5f, false);
- line (st, 12.0f, 17.0f, 12.0f, 20.5f);
- line (st, 8.5f, 20.5f, 15.5f, 20.5f);
- break;
- case Icon::countIn: // a stopwatch: dial, crown and a hand, with the first quarter filled
- {
- st.addEllipse (4.5f, 6.0f, 15.0f, 15.0f);
- line (st, 10.0f, 3.0f, 14.0f, 3.0f);
- line (st, 12.0f, 3.0f, 12.0f, 6.0f);
- line (st, 12.0f, 13.5f, 12.0f, 9.5f);
- juce::Path quarter;
- quarter.startNewSubPath (12.0f, 13.5f);
- quarter.addCentredArc (12.0f, 13.5f, 5.0f, 5.0f, 0.0f, 0.0f, pi * 0.5f, false);
- quarter.closeSubPath();
- fi.addPath (quarter);
- break;
- }
- case Icon::waitInput: // an hourglass: two triangles between two bars, sand in the bottom one
- line (st, 6.0f, 3.5f, 18.0f, 3.5f);
- line (st, 6.0f, 20.5f, 18.0f, 20.5f);
- polyline (st, { { 7.5f, 3.5f }, { 7.5f, 6.5f }, { 12.0f, 12.0f }, { 7.5f, 17.5f }, { 7.5f, 20.5f } });
- polyline (st, { { 16.5f, 3.5f }, { 16.5f, 6.5f }, { 12.0f, 12.0f }, { 16.5f, 17.5f }, { 16.5f, 20.5f } });
- polyline (fi, { { 12.0f, 16.0f }, { 15.0f, 19.5f }, { 9.0f, 19.5f } }, true);
- break;
- case Icon::mouseLeft: // a mouse with the left button lit (the mirror of rightClick)
- {
- roundRect (st, 6.5f, 3.5f, 11.0f, 17.0f, 5.5f);
- line (st, 6.5f, 10.5f, 17.5f, 10.5f);
- line (st, 12.0f, 3.5f, 12.0f, 10.5f);
- juce::Path b;
- b.startNewSubPath (12.0f, 3.5f);
- b.lineTo (12.0f, 10.5f);
- b.lineTo (6.5f, 10.5f);
- b.lineTo (6.5f, 9.0f);
- b.quadraticTo (6.5f, 3.5f, 12.0f, 3.5f);
- b.closeSubPath();
- fi.addPath (b);
- break;
- }
- case Icon::mouseMiddle: // a mouse with its wheel button lit
- roundRect (st, 6.5f, 3.5f, 11.0f, 17.0f, 5.5f);
- line (st, 6.5f, 11.0f, 17.5f, 11.0f);
- fi.addRoundedRectangle (10.25f, 4.5f, 3.5f, 6.0f, 1.75f);
- break;
- case Icon::mouseWheel: // a narrower mouse with its wheel, and up/down chevrons beside it
- roundRect (st, 3.5f, 4.5f, 10.0f, 15.0f, 5.0f);
- line (st, 3.5f, 11.0f, 13.5f, 11.0f);
- fi.addRoundedRectangle (7.25f, 5.5f, 3.5f, 5.0f, 1.75f);
- polyline (st, { { 16.5f, 8.0f }, { 18.5f, 5.5f }, { 20.5f, 8.0f } });
- polyline (st, { { 16.5f, 16.0f }, { 18.5f, 18.5f }, { 20.5f, 16.0f } });
- break;
- case Icon::drumBrush: // a brush laying a row of short hits on the grid
- {
- line (st, 20.5f, 3.5f, 15.0f, 9.0f);
- juce::Path tip;
- tip.startNewSubPath (14.0f, 8.0f);
- tip.lineTo (16.0f, 10.0f);
- tip.quadraticTo (14.5f, 14.0f, 10.0f, 13.5f);
- tip.quadraticTo (10.5f, 9.5f, 14.0f, 8.0f);
- tip.closeSubPath();
- fi.addPath (tip);
- fi.addRoundedRectangle (3.0f, 17.0f, 4.0f, 3.5f, 1.0f);
- fi.addRoundedRectangle (9.0f, 17.0f, 4.0f, 3.5f, 1.0f);
- fi.addRoundedRectangle (15.0f, 17.0f, 4.0f, 3.5f, 1.0f);
- break;
- }
- case Icon::graph: // bars of different heights standing on a base line (a step graph)
- line (st, 3.5f, 20.5f, 20.5f, 20.5f);
- fi.addRoundedRectangle (4.0f, 11.0f, 3.0f, 8.0f, 1.0f);
- fi.addRoundedRectangle (8.5f, 6.0f, 3.0f, 13.0f, 1.0f);
- fi.addRoundedRectangle (13.0f, 13.5f, 3.0f, 5.5f, 1.0f);
- fi.addRoundedRectangle (17.5f, 9.0f, 3.0f, 10.0f, 1.0f);
- break;
- case Icon::follow: // a playhead line with an arrow carrying it to the right
- {
- line (st, 7.5f, 4.5f, 7.5f, 19.5f);
- juce::Path head;
- head.addTriangle (4.5f, 3.5f, 10.5f, 3.5f, 7.5f, 7.0f);
- fi.addPath (head);
- line (st, 11.5f, 12.0f, 19.5f, 12.0f);
- line (st, 16.5f, 9.0f, 19.5f, 12.0f);
- line (st, 16.5f, 15.0f, 19.5f, 12.0f);
- break;
- }
- case Icon::loop: // two arcs chasing each other around (a loop), arrow heads at their ends
- {
- constexpr float r = 7.0f;
- auto arcWithHead = [&] (float from, float to) {
- juce::Path a;
- a.addCentredArc (12.0f, 12.0f, r, r, 0.0f, from, to, true);
- st.addPath (a);
- // the head at the arc's end, pointing along it (clockwise); angles from 12 o'clock as JUCE's arcs
- const juce::Point<float> end (12.0f + r * std::sin (to), 12.0f - r * std::cos (to));
- const juce::Point<float> along (std::cos (to), std::sin (to)), out (std::sin (to), -std::cos (to));
- juce::Path h;
- h.addTriangle (end + along * 3.6f, end + out * 3.2f - along * 0.6f, end - out * 3.2f - along * 0.6f);
- fi.addPath (h);
- };
- arcWithHead (0.45f, 2.55f);
- arcWithHead (3.6f, 5.7f);
- break;
- }
- case Icon::stretch: // a waveform between two outward arrows (stretching audio)
- {
- juce::Path w;
- w.startNewSubPath (8.0f, 12.0f);
- w.lineTo (9.5f, 8.0f);
- w.lineTo (11.0f, 16.0f);
- w.lineTo (12.5f, 6.5f);
- w.lineTo (14.0f, 17.5f);
- w.lineTo (16.0f, 12.0f);
- st.addPath (w);
- line (st, 2.5f, 12.0f, 6.0f, 12.0f);
- line (st, 2.5f, 12.0f, 4.5f, 10.0f);
- line (st, 2.5f, 12.0f, 4.5f, 14.0f);
- line (st, 18.0f, 12.0f, 21.5f, 12.0f);
- line (st, 21.5f, 12.0f, 19.5f, 10.0f);
- line (st, 21.5f, 12.0f, 19.5f, 14.0f);
- break;
- }
- case Icon::dice: // a die showing five
- st.addRoundedRectangle (4.5f, 4.5f, 15.0f, 15.0f, 3.0f);
- for (const auto& [x, y] : { std::pair { 8.5f, 8.5f }, { 15.5f, 8.5f }, { 12.0f, 12.0f }, { 8.5f, 15.5f }, { 15.5f, 15.5f } })
- fi.addEllipse (x - 1.4f, y - 1.4f, 2.8f, 2.8f);
- break;
- case Icon::tuningFork: // two prongs on a stem, with a weighted foot
- {
- juce::Path f;
- f.startNewSubPath (8.5f, 3.5f);
- f.lineTo (8.5f, 10.0f);
- f.quadraticTo (8.5f, 14.0f, 12.0f, 14.0f);
- f.quadraticTo (15.5f, 14.0f, 15.5f, 10.0f);
- f.lineTo (15.5f, 3.5f);
- st.addPath (f);
- line (st, 12.0f, 14.0f, 12.0f, 18.0f);
- fi.addEllipse (10.0f, 17.0f, 4.0f, 4.0f);
- break;
- }
- case Icon::scaleSnap: // a small magnet over a few piano keys (snap to the scale)
- magnet (0.62f, 1.0f, 1.0f);
- roundRect (st, 11.5f, 12.5f, 9.0f, 8.0f, 1.5f);
- line (st, 14.5f, 16.5f, 14.5f, 20.5f);
- line (st, 17.5f, 16.5f, 17.5f, 20.5f);
- fi.addRoundedRectangle (13.6f, 12.5f, 1.8f, 4.0f, 0.5f);
- fi.addRoundedRectangle (16.6f, 12.5f, 1.8f, 4.0f, 0.5f);
- break;
- case Icon::tweak: // a knob with its pointer, and an arrow turning around it (the last moved control)
- {
- st.addEllipse (6.0f, 8.5f, 11.0f, 11.0f);
- line (st, 11.5f, 14.0f, 14.5f, 11.0f);
- constexpr float cx = 11.5f, cy = 14.0f, r = 9.0f, from = pi * 1.72f, to = pi * 2.28f;
- st.addCentredArc (cx, cy, r, r, 0.0f, from, to, true);
- const juce::Point<float> tip (cx + r * std::sin (to), cy - r * std::cos (to));
- const juce::Point<float> along (std::cos (to), std::sin (to)); // the arc's direction at its end
- const juce::Point<float> side (-along.y, along.x);
- polyline (st, { tip - along * 2.6f + side * 2.2f, tip, tip - along * 2.6f - side * 2.2f });
- break;
- }
- case Icon::slide: // a note with an arrow gliding up from its end (FL's slide notes)
- {
- fi.addRoundedRectangle (3.5f, 14.5f, 9.0f, 5.0f, 1.5f);
- line (st, 12.5f, 15.0f, 20.0f, 6.0f);
- polyline (st, { { 15.5f, 6.0f }, { 20.0f, 6.0f }, { 20.0f, 10.5f } });
- break;
- }
- case Icon::note: // an eighth note: a solid head, its stem and a flag
- fi.addEllipse (4.5f, 14.5f, 7.5f, 5.5f);
- line (st, 11.5f, 17.0f, 11.5f, 4.0f);
- polyline (st, { { 11.5f, 4.0f }, { 17.0f, 7.5f }, { 17.5f, 11.5f } });
- break;
- case Icon::chord: // three notes stacked on one start (a chord)
- fi.addRoundedRectangle (4.0f, 4.5f, 12.0f, 4.0f, 1.25f);
- fi.addRoundedRectangle (4.0f, 10.0f, 16.0f, 4.0f, 1.25f);
- fi.addRoundedRectangle (4.0f, 15.5f, 9.0f, 4.0f, 1.25f);
- break;
- case Icon::span: // a double arrow between two bar lines (a length)
- line (st, 3.5f, 6.0f, 3.5f, 18.0f);
- line (st, 20.5f, 6.0f, 20.5f, 18.0f);
- line (st, 6.5f, 12.0f, 17.5f, 12.0f);
- polyline (st, { { 9.0f, 9.5f }, { 6.5f, 12.0f }, { 9.0f, 14.5f } });
- polyline (st, { { 15.0f, 9.5f }, { 17.5f, 12.0f }, { 15.0f, 14.5f } });
- break;
- case Icon::blend: // two takes (notes) merging into one line (overdub)
- {
- fi.addRoundedRectangle (3.0f, 4.5f, 5.5f, 3.5f, 1.0f);
- fi.addRoundedRectangle (3.0f, 16.0f, 5.5f, 3.5f, 1.0f);
- juce::Path m;
- m.startNewSubPath (8.5f, 6.25f);
- m.quadraticTo (12.5f, 6.25f, 13.5f, 12.0f);
- m.startNewSubPath (8.5f, 17.75f);
- m.quadraticTo (12.5f, 17.75f, 13.5f, 12.0f);
- st.addPath (m);
- line (st, 13.5f, 12.0f, 20.5f, 12.0f);
- polyline (st, { { 17.5f, 9.0f }, { 20.5f, 12.0f }, { 17.5f, 15.0f } });
- break;
- }
- case Icon::filter: // a funnel
- {
- juce::Path f;
- polyline (f, { { 4.0f, 5.0f }, { 20.0f, 5.0f }, { 14.0f, 12.5f }, { 14.0f, 19.0f }, { 10.0f, 17.0f }, { 10.0f, 12.5f } }, true);
- st.addPath (f.createPathWithRoundedCorners (1.25f));
- break;
- }
- case Icon::tapTempo: // a fingertip tapping a pad, with the tap's two impact marks
- fi.addRoundedRectangle (4.0f, 16.0f, 16.0f, 4.0f, 1.5f);
- st.addRoundedRectangle (9.5f, 2.5f, 5.0f, 11.0f, 2.5f);
- line (st, 10.5f, 9.5f, 13.5f, 9.5f);
- line (st, 4.5f, 10.5f, 7.0f, 13.0f);
- line (st, 19.5f, 10.5f, 17.0f, 13.0f);
- break;
- case Icon::loopRecord: // a loop arrow around a record dot
- {
- constexpr float r = 8.0f;
- juce::Path a;
- a.addCentredArc (12.0f, 12.0f, r, r, 0.0f, pi * 0.25f, pi * 1.85f, true);
- st.addPath (a);
- const auto to = pi * 1.85f;
- const juce::Point<float> end (12.0f + r * std::sin (to), 12.0f - r * std::cos (to));
- const juce::Point<float> along (std::cos (to), std::sin (to)), out (std::sin (to), -std::cos (to));
- juce::Path h;
- h.addTriangle (end + along * 3.8f, end + out * 3.3f - along * 0.6f, end - out * 3.3f - along * 0.6f);
- fi.addPath (h);
- fi.addEllipse (8.5f, 8.5f, 7.0f, 7.0f);
- break;
- }
- case Icon::stepEdit: // three steps typed one after another (the last one hollow: the next), an arrow on to it
- fi.addRoundedRectangle (2.5f, 14.0f, 5.0f, 5.0f, 1.0f);
- fi.addRoundedRectangle (9.5f, 14.0f, 5.0f, 5.0f, 1.0f);
- st.addRoundedRectangle (16.5f, 14.0f, 5.0f, 5.0f, 1.0f);
- line (st, 5.0f, 9.0f, 17.5f, 9.0f);
- polyline (st, { { 15.0f, 6.0f }, { 18.5f, 9.0f }, { 15.0f, 12.0f } });
- break;
- case Icon::punch: // a record dot between two brackets (in and out)
- polyline (st, { { 7.0f, 4.5f }, { 4.0f, 4.5f }, { 4.0f, 19.5f }, { 7.0f, 19.5f } });
- polyline (st, { { 17.0f, 4.5f }, { 20.0f, 4.5f }, { 20.0f, 19.5f }, { 17.0f, 19.5f } });
- fi.addEllipse (8.0f, 8.0f, 8.0f, 8.0f);
- break;
- // --- round 190iv: the Simple top bar's save status, the Clip-launch control bar ---
- case Icon::cloud: // a cloud: two bumps on a flat base
- case Icon::cloudCheck: // the cloud with a check mark in it
- {
- juce::Path c;
- c.startNewSubPath (7.0f, 18.5f);
- c.lineTo (17.5f, 18.5f);
- c.addCentredArc (17.5f, 14.75f, 3.75f, 3.75f, 0.0f, pi, pi * 0.05f, false);
- c.addCentredArc (12.5f, 10.5f, 5.5f, 5.5f, 0.0f, pi * 0.42f, -pi * 0.55f, false);
- c.addCentredArc (7.0f, 14.5f, 4.0f, 4.0f, 0.0f, pi * 0.05f, -pi, false);
- c.closeSubPath();
- st.addPath (c);
- if (icon == Icon::cloudCheck)
- polyline (st, { { 9.5f, 14.0f }, { 11.5f, 16.0f }, { 15.0f, 12.0f } });
- break;
- }
- case Icon::sessionView: // three columns
- for (float x : { 6.0f, 11.0f, 16.0f })
- fi.addRectangle (x, 5.0f, 2.5f, 14.0f);
- break;
- case Icon::arrangementView: // three rows
- for (float y : { 6.0f, 11.0f, 16.0f })
- fi.addRectangle (5.0f, y, 14.0f, 2.5f);
- break;
- case Icon::backToArrangement: // an arrow into a dashed line (the clips give the Playlist back)
- {
- juce::Path head;
- head.addTriangle (8.0f, 8.0f, 8.0f, 16.0f, 12.5f, 12.0f);
- fi.addPath (head);
- fi.addRectangle (3.0f, 11.0f, 5.5f, 2.0f);
- for (float x : { 14.0f, 18.0f })
- fi.addRectangle (x, 11.0f, 2.5f, 2.0f);
- break;
- }
- case Icon::capture: // a dashed square
- polyline (st, { { 5.0f, 9.0f }, { 5.0f, 5.0f }, { 9.0f, 5.0f } });
- polyline (st, { { 15.0f, 5.0f }, { 19.0f, 5.0f }, { 19.0f, 9.0f } });
- polyline (st, { { 19.0f, 15.0f }, { 19.0f, 19.0f }, { 15.0f, 19.0f } });
- polyline (st, { { 9.0f, 19.0f }, { 5.0f, 19.0f }, { 5.0f, 15.0f } });
- break;
- case Icon::sessionRecord: // a ring
- st.addEllipse (6.0f, 6.0f, 12.0f, 12.0f);
- break;
- case Icon::browserPanel: // a narrow panel beside a wide one
- fi.addRectangle (3.5f, 5.0f, 5.5f, 14.0f);
- fi.addRectangle (10.5f, 5.0f, 10.0f, 14.0f);
- break;
- case Icon::metronomeDots: // a ring and a dot (the beat and the accent)
- st.addEllipse (3.5f, 8.0f, 8.0f, 8.0f);
- fi.addEllipse (13.0f, 8.0f, 8.0f, 8.0f);
- break;
- }
- return s;
- }
- } // namespace
- const Shape& get (Icon icon)
- {
- static std::map<Icon, Shape> cache;
- auto it = cache.find (icon);
- if (it == cache.end())
- it = cache.emplace (icon, make (icon)).first;
- return it->second;
- }
- float strokeWidth (float size)
- {
- // a fine line that thickens only a little with the size: 1.25 px at 14 px, 1.4 px at 20 px, 1.6 px from
- // 30 px (logical pixels; HiDPI screens draw it with proportionally more device pixels)
- return juce::jlimit (1.2f, 1.6f, 1.0f + size * 0.019f);
- }
- void draw (juce::Graphics& g, Icon icon, juce::Rectangle<float> area, juce::Colour colour)
- {
- if (icon == Icon::none || area.isEmpty())
- return;
- // a whole-pixel box on whole-pixel coordinates: the grid's half units then land on the same
- // sub-pixel phase on every button, so strokes look equally sharp everywhere
- const auto size = std::floor (juce::jmin (area.getWidth(), area.getHeight()));
- const auto box = juce::Rectangle<float> (std::round (area.getCentreX() - size * 0.5f), std::round (area.getCentreY() - size * 0.5f), size, size);
- const auto scale = size / 24.0f;
- const auto transform = juce::AffineTransform::scale (scale).translated (box.getX(), box.getY());
- const auto& shape = get (icon);
- g.setColour (colour);
- if (! shape.fill.isEmpty())
- g.fillPath (shape.fill, transform);
- if (! shape.stroke.isEmpty())
- g.strokePath (shape.stroke, juce::PathStrokeType (strokeWidth (size), juce::PathStrokeType::curved, juce::PathStrokeType::rounded), transform);
- }
- } // namespace icons
- IconButton::IconButton (const juce::String& name, Icon i, const juce::String& t)
- : juce::Button (name), icon (i), text (t), onColour (theme::colour::accent), iconOnColour (theme::colour::onAccent)
- {
- setMouseCursor (juce::MouseCursor::PointingHandCursor);
- }
- void IconButton::setIconSizing (float fraction, float maxPx)
- {
- if (fraction != iconFraction || maxPx != iconMax)
- {
- iconFraction = fraction;
- iconMax = maxPx;
- repaint();
- }
- }
- void IconButton::setIcon (Icon newIcon)
- {
- if (icon != newIcon)
- {
- icon = newIcon;
- repaint();
- }
- }
- void IconButton::setText (const juce::String& newText)
- {
- if (text != newText)
- {
- text = newText;
- repaint();
- }
- }
- void IconButton::setPrimary (bool b) { primary = b; repaint(); }
- void IconButton::setOnColour (juce::Colour c) { onColour = c; onColoursSet = true; repaint(); }
- void IconButton::setIconColourWhenOn (juce::Colour c) { iconOnColour = c; onColoursSet = true; repaint(); }
- void IconButton::setToggleLook (bool isSwitch) { toggleLook = isSwitch ? 1 : 0; repaint(); }
- bool IconButton::actsAsSwitch() const
- {
- return toggleLook >= 0 ? toggleLook == 1 : (isToggleable() || getRadioGroupId() != 0 || onColoursSet);
- }
- void IconButton::setFlat (bool b) { flat = b; repaint(); }
- void IconButton::setIconColour (juce::Colour c) { iconColour = c; repaint(); }
- void IconButton::setCorners (bool left, bool right)
- {
- roundLeft = left;
- roundRight = right;
- repaint();
- }
- void IconButton::mouseDown (const juce::MouseEvent& e)
- {
- if (e.mods.isPopupMenu() && onRightClick != nullptr)
- return; // handled on mouse up, without pressing the button
- juce::Button::mouseDown (e);
- }
- void IconButton::mouseUp (const juce::MouseEvent& e)
- {
- if (e.mods.isPopupMenu() && onRightClick != nullptr)
- {
- if (getLocalBounds().contains (e.getPosition()))
- onRightClick();
- return;
- }
- juce::Button::mouseUp (e);
- }
- void IconButton::mouseDoubleClick (const juce::MouseEvent& e)
- {
- if (onDoubleClick != nullptr && ! e.mods.isPopupMenu())
- onDoubleClick();
- }
- int IconButton::getIdealWidth (int height) const
- {
- const auto iconSize = icon == Icon::none ? 0 : juce::roundToInt (height * 0.55f);
- const auto textWidth = text.isEmpty() ? 0
- : juce::roundToInt (juce::GlyphArrangement::getStringWidth (juce::Font (theme::font (theme::type::body)), text));
- const auto gap = iconSize > 0 && textWidth > 0 ? 6 : 0;
- return juce::jmax (height, iconSize + gap + textWidth + (textWidth > 0 ? 20 : 0));
- }
- void IconButton::buttonStateChanged()
- {
- juce::Button::buttonStateChanged();
- const auto target = isOver() || isDown() ? 1.0f : 0.0f;
- if (! ui::motion::enabled()) // Settings › General › Animations off: no fade, no timer
- {
- stopTimer();
- hover = target;
- return;
- }
- if (target != hover && ! isTimerRunning())
- startTimerHz (60);
- }
- void IconButton::timerCallback()
- {
- const auto target = isOver() || isDown() ? 1.0f : 0.0f;
- const auto step = target > hover ? 0.34f : 0.18f; // in quickly, out a little slower
- hover = target > hover ? juce::jmin (target, hover + step) : juce::jmax (target, hover - step);
- if (hover == target)
- stopTimer();
- repaint();
- }
- void IconButton::setLook (Look newLook, float iconBoxPx)
- {
- if (newLook == look && iconBoxPx == lookIconBox)
- return;
- look = newLook;
- lookIconBox = iconBoxPx;
- repaint();
- }
- // Round 190iv: the Simple capsule segment and Live's control-bar boxes (Icons.h, IconButton::Look)
- void IconButton::paintLook (juce::Graphics& g, bool highlighted, bool down)
- {
- using namespace theme;
- const auto on = getToggleState();
- const auto enabled = isEnabled();
- const auto area = getLocalBounds().toFloat();
- const auto h = isTimerRunning() ? hover : (highlighted ? 1.0f : 0.0f);
- juce::Colour fg;
- if (look == Look::capsule)
- {
- // the capsule (drawn behind) is bg4; a segment shows hover and press only (SG-1: hover bg5, pressed bg6;
- // recording: the Record segment filled accentMuted)
- juce::Colour bg;
- if (down)
- bg = colour::bg6;
- else if (on && icon == Icon::record)
- bg = colour::accentMuted;
- else if (h > 0.0f)
- bg = colour::bg5.withAlpha (h);
- if (! bg.isTransparent())
- {
- // (the capsule's round ends: the first segment rounds its left, the last its right; setCorners)
- const auto r = area.getHeight() / 2.0f;
- juce::Path p;
- p.addRoundedRectangle (area.getX(), area.getY(), area.getWidth(), area.getHeight(), r, r, roundLeft, roundRight, roundLeft, roundRight);
- g.setColour (bg);
- g.fillPath (p);
- }
- fg = icon == Icon::record ? colour::record : (on ? colour::accent : colour::textPrimary);
- }
- else if (look == Look::liveBox)
- {
- // Live 12.4 (CL-2, ref/live-session.png): #363636 boxes, hover #464646, pressed #1e1e1e, lit #ffad56
- const juce::Colour rest { 0xff363636 }, over { 0xff464646 }, pressed { 0xff1e1e1e }, lit { 0xffffad56 };
- g.setColour (down ? pressed : on ? lit : rest.interpolatedWith (over, h));
- g.fillRect (area);
- fg = on && ! down ? juce::Colour (0xff070707) : juce::Colour (0xffb5b5b5).interpolatedWith (juce::Colours::white, h * 0.35f);
- }
- else if (look == Look::liveSelector)
- {
- // (ref/live-session.png x 1870..1900: the shown view's glyph #ffad56; Live's other glyph is #464646, 1.5:1 on the
- // band; LYNX keeps it at 3.4:1, the contrast floor of design190ia G1)
- fg = on ? juce::Colour (0xffffad56) : juce::Colour (0xff7a7a7a).interpolatedWith (juce::Colour (0xffb5b5b5), h);
- }
- else // liveGlyph: the bare transport glyphs on the band
- {
- const juce::Colour glyph { 0xffb5b5b5 };
- fg = on ? (icon == Icon::record ? colour::record : juce::Colour (0xff00d38d)) // (Live's playing green, CL token table)
- : glyph.interpolatedWith (juce::Colours::white, h * 0.35f);
- if (down)
- fg = fg.darker (0.3f);
- }
- if (! enabled)
- fg = juce::Colour (0xff696969);
- const auto box = lookIconBox > 0.0f ? lookIconBox : juce::jmin (area.getHeight() * iconFraction, iconMax);
- if (text.isEmpty())
- {
- icons::draw (g, icon, area.withSizeKeepingCentre (box, box), fg);
- return;
- }
- // a text box (Live's "Tap", "Key", "MIDI"): the small type, centred, the icon (if any) before it
- const auto f = theme::font (type::caption);
- auto content = area.reduced (3.0f, 0.0f);
- if (icon != Icon::none)
- {
- icons::draw (g, icon, content.removeFromLeft (box).withSizeKeepingCentre (box, box), fg);
- content.removeFromLeft (3.0f);
- }
- g.setColour (fg);
- g.setFont (f);
- g.drawFittedText (text, content.toNearestInt(), icon == Icon::none ? juce::Justification::centred : juce::Justification::centredLeft, 1, 0.8f);
- }
- void IconButton::paintButton (juce::Graphics& g, bool highlighted, bool down)
- {
- using namespace theme;
- if (look != Look::standard)
- {
- paintLook (g, highlighted, down);
- return;
- }
- const auto bounds = getLocalBounds().toFloat().reduced (0.5f);
- const auto on = getToggleState() || primary;
- const auto enabled = isEnabled();
- // the animated hover level (snaps to the state when nothing animates, e.g. in snapshots)
- const auto h = ! enabled ? 0.0f : isTimerRunning() ? hover : (highlighted ? 1.0f : 0.0f);
- const auto isSwitch = actsAsSwitch();
- // one state rule for every button kind (round 190je, core/ThemePalette.h buttonLook)
- const auto kind = ! flat ? themes::ButtonKind::secondary : isSwitch ? themes::ButtonKind::flatToggle : themes::ButtonKind::flatMomentary;
- auto state = buttonColours (kind, on, h, down, enabled);
- const auto ownOn = onColour != colour::accent; // a button with "on" colours of its own (bg6 + a red icon, a wash)
- if (on && enabled && (ownOn || flat))
- {
- state.fill = down ? colour::accentPressed : onColour.interpolatedWith (onColour.brighter (0.12f), h);
- state.edge = {};
- }
- else if (on && ! enabled && (ownOn || flat))
- state.fill = onColour.withMultipliedAlpha (0.5f);
- else if (enabled && ! on && ! down && isSwitch && flat && ownOn)
- {
- // the preview of this switch's own "on" look (bg6 with a red icon, a wash)
- state.fill = onColour.withMultipliedAlpha (0.7f * h);
- state.edge = iconOnColour.withAlpha (0.5f * h);
- }
- // the icon / text: as at rest before (a light grey), towards white under the mouse, towards the "on" colour on a switch
- const auto idleFg = ! iconColour.isTransparent() ? iconColour : colour::textSecondary.brighter (0.25f);
- const auto hoverFg = isSwitch && flat ? (ownOn ? iconOnColour : colour::accentHover)
- : (! iconColour.isTransparent() ? iconColour.brighter (0.2f) : colour::textPrimary);
- state.content = ! enabled ? colour::textDisabled : on ? iconOnColour : idleFg.interpolatedWith (down ? colour::textPrimary : hoverFg, down ? 1.0f : h);
- if (! state.fill.isTransparent() || ! state.edge.isTransparent())
- {
- juce::Path p;
- p.addRoundedRectangle (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), radius::md, radius::md,
- roundLeft, roundRight, roundLeft, roundRight);
- if (! state.fill.isTransparent())
- {
- g.setColour (state.fill);
- g.fillPath (p);
- }
- if (! state.edge.isTransparent())
- {
- juce::Path edge; // (on the pixel centres: `bounds` is inset by half a pixel, a crisp 1 px line)
- edge.addRoundedRectangle (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), radius::md, radius::md,
- roundLeft, roundRight, roundLeft, roundRight);
- g.setColour (state.edge);
- g.strokePath (edge, juce::PathStrokeType (1.0f));
- }
- }
- const auto fg = state.content;
- auto area = getLocalBounds().toFloat();
- const auto iconSize = juce::jmin (area.getHeight() * iconFraction, iconMax);
- if (text.isEmpty())
- {
- icons::draw (g, icon, area.withSizeKeepingCentre (iconSize, iconSize), fg);
- return;
- }
- const auto font = juce::Font (theme::font (type::body));
- const auto textWidth = juce::GlyphArrangement::getStringWidth (font, text);
- const auto gap = icon == Icon::none ? 0.0f : 6.0f;
- const auto contentWidth = juce::jmin (area.getWidth() - 12.0f, (icon == Icon::none ? 0.0f : iconSize) + gap + textWidth);
- auto content = area.withSizeKeepingCentre (contentWidth, area.getHeight());
- if (icon != Icon::none)
- icons::draw (g, icon, content.removeFromLeft (iconSize).withSizeKeepingCentre (iconSize, iconSize), fg);
- content.removeFromLeft (gap);
- g.setColour (fg);
- g.setFont (font);
- g.drawFittedText (text, content.toNearestInt(), juce::Justification::centredLeft, 1, 0.85f);
- }
- } // namespace lynx
|