Krotos Modules 3
Loading...
Searching...
No Matches
ImagePopup.cpp
Go to the documentation of this file.
1namespace krotos
2{
3 ImagePopup::ImagePopup(const String& headerText, const int& numOfHeaderLines, const String& descriptionText,
4 Image* primaryImage, const String& buttonText, Justification justification,
5 float headerFontSize, float descriptionFontSize)
6 : Component(headerText), m_header(headerText + "Header", headerText), m_numberOfHeaderLines(numOfHeaderLines),
7 m_description(headerText + "Description", descriptionText), m_button(buttonText),
8 m_justification(justification), m_headerFontSize(headerFontSize), m_descriptionFontSize(descriptionFontSize)
9 {
10 // Simple laf customise button to not draw background.
11 m_button.setLookAndFeel(&m_buttonLAF);
12
13 if (primaryImage != nullptr)
14 m_image.setImage(*primaryImage, RectanglePlacement::fillDestination);
15
16 m_header.setJustificationType(m_justification);
17 m_description.setJustificationType(m_justification);
18
19 addAndMakeVisible(m_image);
20 addAndMakeVisible(m_header);
21 addAndMakeVisible(m_description);
22 addAndMakeVisible(m_button);
23
24 m_header.setFont(Font(m_headerFontSize));
26
27 setColour(ImagePopup::ColourIds::outlineColourId, Colour(57, 95, 55));
28
29 m_header.setColour(Label::textColourId, Colour(204, 204, 204));
30 m_description.setColour(Label::textColourId, Colour(178, 178, 178));
31
32 m_closePopupButton = std::make_unique<DrawableButton>("Close", DrawableButton::ButtonStyle::ImageStretched);
33
34 m_closeBtnDrawableDefault = Drawable::createFromImageData(KrotosBinaryData::ClosePopup_Default_svg,
35 KrotosBinaryData::ClosePopup_Default_svgSize);
36 m_closeBtnDrawableHover = Drawable::createFromImageData(KrotosBinaryData::ClosePopup_Hover_svg,
37 KrotosBinaryData::ClosePopup_Hover_svgSize);
38 m_closeBtnDrawableSelected = Drawable::createFromImageData(KrotosBinaryData::ClosePopup_Clicked_svg,
39 KrotosBinaryData::ClosePopup_Clicked_svgSize);
40
43
44 addAndMakeVisible(*m_closePopupButton);
45
46 m_closePopupButton->onClick = [this] {
47 if (findParentComponentOfClass<CallOutBox>() != nullptr)
48 {
49 findParentComponentOfClass<CallOutBox>()->exitModalState(0);
50 }
51 else if (findParentComponentOfClass<KDialogWindow>() != nullptr)
52 {
53 getCurrentlyModalComponent()->exitModalState(0);
54 static_cast<KDialogWindow*>(getParentComponent())->removeFromDesktop();
55 }
56 else if (findParentComponentOfClass<TopLevelWindow>() != nullptr)
57 {
58 findParentComponentOfClass<TopLevelWindow>()->exitModalState(1234);
59 findParentComponentOfClass<TopLevelWindow>()->setVisible(false);
60 }
61 };
62 }
63
64 ImagePopup::~ImagePopup() { m_button.setLookAndFeel(nullptr); }
65
66 void ImagePopup::paint(Graphics& g) { g.fillAll(Colour(37, 45, 55)); }
67
69 {
70 // Current design expects a constrained width / height
71 auto bounds = getLocalBounds();
72
73 m_descriptionMargins.setHeight(m_descriptionMargins.getHeight() *
75
76 float imageHeight = static_cast<float>(getHeight()) * m_primaryImagePropotion;
77
78 auto image = bounds.removeFromTop(static_cast<int>(imageHeight));
79 m_image.setBounds(image);
80
81 // Create margin 16px from bottom of above image.
82 bounds.removeFromTop(m_headerSize.getY());
83
84 Rectangle<int> headerBar;
85 // Header
86 if (m_numberOfHeaderLines == 3)
87 {
88 headerBar = bounds.removeFromTop(m_headerSize.getHeight() * 2);
89 }
90 else
91 {
92 headerBar = bounds.removeFromTop(m_headerSize.getHeight());
93 }
94
95 // Margin
96 if (m_numberOfHeaderLines == 2)
97 {
98 bounds.removeFromTop(m_headerDescriptionMargin);
99 }
100
101 // Description
102 auto descriptionBar = bounds.removeFromTop(m_descriptionMargins.getHeight());
103 // Margins
104 headerBar.removeFromLeft(m_headerSize.getX());
105 descriptionBar.removeFromLeft(m_headerSize.getX());
106 headerBar.removeFromRight(m_headerSize.getWidth());
107 descriptionBar.removeFromRight(m_headerSize.getWidth());
108
109 m_header.setBounds(headerBar);
110 m_description.setBounds(descriptionBar);
111
112 // set button bounds from bottom right corner
113 m_button.setBounds(getLocalBounds().getWidth() - (m_buttonBounds.getX() + m_buttonBounds.getWidth()),
114 getLocalBounds().getHeight() - (m_buttonBounds.getY() + m_buttonBounds.getHeight()),
115 m_buttonBounds.getWidth(), m_buttonBounds.getHeight());
116
117 m_closePopupButton->setBounds(getWidth() - 36, 8, 28, 28);
118 }
119} // namespace krotos
void resized() override
Definition ImagePopup.cpp:68
TextButton m_button
Definition ImagePopup.h:84
std::unique_ptr< Drawable > m_closeBtnDrawableHover
Definition ImagePopup.h:87
Label m_description
Definition ImagePopup.h:83
Rectangle< int > m_descriptionMargins
Definition ImagePopup.h:77
Rectangle< int > m_headerSize
Definition ImagePopup.h:76
float m_primaryImagePropotion
Definition ImagePopup.h:71
std::unique_ptr< DrawableButton > m_closePopupButton
Definition ImagePopup.h:85
float m_headerFontSize
Definition ImagePopup.h:68
int m_headerDescriptionMargin
Definition ImagePopup.h:73
ImageComponent m_image
Definition ImagePopup.h:82
~ImagePopup()
Definition ImagePopup.cpp:64
@ outlineColourId
Definition ImagePopup.h:48
void paint(Graphics &g) override
Definition ImagePopup.cpp:66
const int m_numberOfHeaderLines
Definition ImagePopup.h:70
Justification m_justification
Definition ImagePopup.h:90
ImagePopup(const String &headerText, const int &numOfHeaderLines, const String &descriptionText, Image *primaryImage, const String &buttonText, Justification justification=Justification::centredLeft, float headerFontSize=18.6f, float descriptionFontSize=15.2f)
Definition ImagePopup.cpp:3
Krotos_LookAndFeel::LinkButtonLAF m_buttonLAF
Definition ImagePopup.h:94
Label m_header
Definition ImagePopup.h:83
std::unique_ptr< Drawable > m_closeBtnDrawableSelected
Definition ImagePopup.h:88
std::unique_ptr< Drawable > m_closeBtnDrawableDefault
Definition ImagePopup.h:86
float m_descriptionFontSize
Definition ImagePopup.h:68
Rectangle< int > m_buttonBounds
Definition ImagePopup.h:80
Definition AirAbsorptionFilter.cpp:2