AnalogTapeModel

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

TitleComp.cpp (2174B)


      1 #include "TitleComp.h"
      2 
      3 TitleComp::TitleComp()
      4 {
      5     setColour (text1ColourID, Colours::white);
      6     setColour (text2ColourID, Colours::grey);
      7 }
      8 
      9 void TitleComp::paint (Graphics& g)
     10 {
     11     g.setFont (Font (font).boldened());
     12     auto curFont = g.getCurrentFont();
     13     auto b = getLocalBounds();
     14 
     15     auto drawText = [=, &g, &b] (const String& text)
     16     {
     17         auto width = curFont.getStringWidth (text);
     18         g.drawFittedText (text, b.removeFromLeft (width), Justification::left, 1);
     19     };
     20 
     21     g.setColour (findColour (text1ColourID));
     22     drawText (title + " ");
     23 
     24     g.setColour (findColour (text2ColourID));
     25     drawText (subtitle);
     26 }
     27 
     28 void TitleComp::setStrings (String newTitle, String newSubtitle, float newFont)
     29 {
     30     font = newFont == 0.0f ? (float) getHeight() : newFont;
     31 
     32     title = newTitle;
     33     subtitle = newSubtitle;
     34     repaint();
     35 }
     36 
     37 //======================================================================
     38 TitleItem::TitleItem (foleys::MagicGUIBuilder& builder, const ValueTree& node) : foleys::GuiItem (builder, node)
     39 {
     40     setColourTranslation ({
     41         { "text1", TitleComp::text1ColourID },
     42         { "text2", TitleComp::text2ColourID },
     43     });
     44 
     45     addAndMakeVisible (comp);
     46 }
     47 
     48 void TitleItem::update()
     49 {
     50     auto titleString = magicBuilder.getStyleProperty (title, configNode).toString();
     51     auto subtitleString = magicBuilder.getStyleProperty (subtitle, configNode).toString();
     52     auto fontVal = (float) magicBuilder.getStyleProperty (font, configNode);
     53 
     54     comp.setStrings (titleString, subtitleString, fontVal);
     55 }
     56 
     57 std::vector<foleys::SettableProperty> TitleItem::getSettableProperties() const
     58 {
     59     std::vector<foleys::SettableProperty> settableProperties;
     60     settableProperties.push_back ({ configNode, title, foleys::SettableProperty::Text, {}, {} });
     61     settableProperties.push_back ({ configNode, subtitle, foleys::SettableProperty::Text, {}, {} });
     62     settableProperties.push_back ({ configNode, font, foleys::SettableProperty::Number, 0.0f, {} });
     63     return settableProperties;
     64 }
     65 
     66 const Identifier TitleItem::title { "title" };
     67 const Identifier TitleItem::subtitle { "subtitle" };
     68 const Identifier TitleItem::font { "font" };