AnalogTapeModel

Physical modelling signal processing for analog tape recording
Log | Files | Refs | Submodules | README | LICENSE

MyLNF.h (4859B)


      1 #ifndef MYLNF_H_INCLUDED
      2 #define MYLNF_H_INCLUDED
      3 
      4 #include <JuceHeader.h>
      5 
      6 class MyLNF : public LookAndFeel_V4
      7 {
      8 public:
      9     MyLNF();
     10 
     11     Typeface::Ptr getTypefaceForFont (const Font&) override;
     12 
     13     void drawRotarySlider (juce::Graphics& g, int x, int y, int width, int height, float sliderPos, float rotaryStartAngle, float rotaryEndAngle, juce::Slider& slider) override;
     14 
     15     void drawToggleButton (Graphics& g, ToggleButton& button, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override;
     16 
     17     void createTabTextLayout (const TabBarButton& button, float length, float depth, Colour colour, TextLayout& textLayout);
     18     void drawTabButton (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown) override;
     19     Button* createTabBarExtrasButton() override;
     20 
     21     void drawLinearSlider (Graphics& g, int x, int y, int width, int height, float sliderPos, float minSliderPos, float maxSliderPos, const Slider::SliderStyle style, Slider& slider) override;
     22 
     23     Slider::SliderLayout getSliderLayout (Slider& slider) override;
     24     Label* createSliderTextBox (Slider& slider) override;
     25 
     26     Component* getParentComponentForMenuOptions (const PopupMenu::Options& options) override;
     27 
     28     juce::PopupMenu::Options getOptionsForComboBoxPopupMenu (ComboBox& comboBox, Label& label) override;
     29 
     30 private:
     31     std::unique_ptr<Drawable> knob = Drawable::createFromImageData (BinaryData::knob_svg, BinaryData::knob_svgSize);
     32     std::unique_ptr<Drawable> pointer = Drawable::createFromImageData (BinaryData::pointer_svg, BinaryData::pointer_svgSize);
     33 
     34     Typeface::Ptr roboto;
     35     Typeface::Ptr robotoBold;
     36 
     37     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MyLNF)
     38 };
     39 
     40 class ComboBoxLNF : public MyLNF
     41 {
     42 public:
     43     ComboBoxLNF()
     44     {
     45         setColour (PopupMenu::backgroundColourId, Colour (0xFF31323A));
     46         setColour (PopupMenu::highlightedBackgroundColourId, Colour (0x7FEAA92C));
     47         setColour (PopupMenu::highlightedTextColourId, Colours::white);
     48     }
     49 
     50     void drawComboBox (Graphics& g, int width, int height, bool, int, int, int, int, ComboBox& box) override;
     51     void positionComboBoxText (ComboBox& box, Label& label) override;
     52 
     53     void drawPopupMenuItem (Graphics& g, const Rectangle<int>& area, const bool isSeparator, const bool isActive, const bool isHighlighted, const bool /*isTicked*/, const bool hasSubMenu, const String& text, const String& shortcutKeyText, const Drawable* icon, const Colour* const textColourToUse) override
     54     {
     55         LookAndFeel_V4::drawPopupMenuItem (g, area, isSeparator, isActive, isHighlighted, false /*isTicked*/, hasSubMenu, text, shortcutKeyText, icon, textColourToUse);
     56     }
     57 
     58     void drawPopupMenuBackground (Graphics& g, int width, int height) override
     59     {
     60         g.fillAll (findColour (PopupMenu::backgroundColourId));
     61         ignoreUnused (width, height);
     62     }
     63 
     64     Font getComboBoxFont (ComboBox& box) override;
     65 
     66 private:
     67     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComboBoxLNF)
     68 };
     69 
     70 class PresetsLNF : public ComboBoxLNF
     71 {
     72 public:
     73     PresetsLNF() = default;
     74 
     75     void drawComboBox (Graphics& g, int width, int height, bool, int, int, int, int, ComboBox& box) override
     76     {
     77         auto cornerSize = 5.0f;
     78         Rectangle<int> boxBounds (0, 0, width, height);
     79 
     80         g.setColour (box.findColour (ComboBox::backgroundColourId));
     81         g.fillRoundedRectangle (boxBounds.toFloat(), cornerSize);
     82     }
     83 
     84     Font getComboBoxFont (ComboBox& box) override
     85     {
     86         return { juce::jmin (28.0f, (float) box.proportionOfHeight (0.55f)) };
     87     }
     88 
     89     void positionComboBoxText (ComboBox& box, Label& label) override
     90     {
     91         label.setBounds (3, 1, box.getWidth(), box.getHeight() - 2);
     92         label.setFont (getComboBoxFont (box).boldened());
     93     }
     94 
     95 private:
     96     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PresetsLNF)
     97 };
     98 
     99 class SpeedButtonLNF : public MyLNF
    100 {
    101 public:
    102     SpeedButtonLNF() {}
    103 
    104     void drawButtonBackground (Graphics& g, Button& button, const Colour& backgroundColour, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
    105     {
    106         constexpr auto cornerSize = 8.0f;
    107         auto bounds = button.getLocalBounds().toFloat().reduced (0.5f, 0.5f);
    108 
    109         auto baseColour = backgroundColour.withMultipliedSaturation (button.hasKeyboardFocus (true) ? 1.3f : 0.9f)
    110                               .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f);
    111 
    112         if (shouldDrawButtonAsDown || shouldDrawButtonAsHighlighted)
    113             baseColour = baseColour.contrasting (shouldDrawButtonAsDown ? 0.2f : 0.05f);
    114 
    115         g.setColour (baseColour);
    116         g.fillRoundedRectangle (bounds, cornerSize);
    117 
    118         g.setColour (Colour (0xFF838590));
    119         g.drawRoundedRectangle (bounds, cornerSize, 1.0f);
    120     }
    121 
    122 private:
    123     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SpeedButtonLNF)
    124 };
    125 
    126 #endif // MYLNF_H_INCLUDED