File: MailBox.h

package info (click to toggle)
iem-plugin-suite 1.15.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,080 kB
  • sloc: cpp: 58,973; python: 269; sh: 79; makefile: 41
file content (90 lines) | stat: -rw-r--r-- 3,107 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 ==============================================================================
 This file is part of the IEM plug-in suite.
 Author: Daniel Rudrich
 Copyright (c) 2018 - Institute of Electronic Music and Acoustics (IEM)
 https://iem.at

 The IEM plug-in suite is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 The IEM plug-in suite is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this software.  If not, see <https://www.gnu.org/licenses/>.
 ==============================================================================
 */

#include "../JuceLibraryCode/JuceHeader.h"
#pragma once

// For now, this class defines messages, which can be displayed by the Display component. Future might bring more features like switching between several active messages... we will see ;-)

namespace MailBox
{
struct Message
{ // could become a reference counted object and Display should check regularly if its the only one who holds this reference -> delete
    juce::String headline = "No Message available";
    juce::String text = "";
    juce::Colour messageColour = juce::Colours::lightgrey;
};

class Display : public juce::Component
{
public:
    Display() : juce::Component() {}

    ~Display() override {}

    void paint (juce::Graphics& g) override
    {
        juce::Colour messageColour = message.messageColour;

        juce::Colour textColour = juce::Colours::white;

        juce::Rectangle<int> background (getLocalBounds());

        g.setColour (messageColour);
        g.drawRect (background);
        g.setColour (messageColour.withMultipliedAlpha (0.1f));
        g.fillRect (background);

        auto currentFont =
            juce::FontOptions (getLookAndFeel().getTypefaceForFont (juce::FontOptions (17.0f, 0)))
                .withHeight (17.0f);
        g.setFont (currentFont);

        juce::Rectangle<int> textArea = background.reduced (4, 2);
        g.setColour (textColour);
        g.drawText (message.headline, textArea.removeFromTop (20), juce::Justification::topLeft);

        currentFont =
            juce::FontOptions (getLookAndFeel().getTypefaceForFont (juce::FontOptions (14.0f, 2)))
                .withHeight (14.0f);
        g.setFont (currentFont);

        g.drawFittedText (message.text,
                          textArea,
                          juce::Justification::topLeft,
                          juce::roundToInt (textArea.getHeight() / 13.0f));
    }

    void resized() override {}

    void setMessage (Message messageToDisplay)
    {
        message = messageToDisplay;
        repaint();
    }

private:
    Message message;

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Display)
};
} // namespace MailBox