Vital
Loading...
Searching...
No Matches
delete_section.cpp
Go to the documentation of this file.
1
3
4#include "delete_section.h"
5
6#include "skin.h"
7#include "fonts.h"
8
10DeleteSection::DeleteSection(const String& name) : Overlay(name), body_(Shaders::kRoundedRectangleFragment) {
11 addOpenGlComponent(&body_);
12
13 delete_button_ = std::make_unique<OpenGlToggleButton>(TRANS("Delete"));
14 delete_button_->setText("Delete");
15 delete_button_->setUiButton(true);
16 delete_button_->addListener(this);
17 addAndMakeVisible(delete_button_.get());
18 addOpenGlComponent(delete_button_->getGlComponent());
19
20 cancel_button_ = std::make_unique<OpenGlToggleButton>(TRANS("Cancel"));
21 cancel_button_->setText("Cancel");
22 cancel_button_->setUiButton(false);
23 cancel_button_->addListener(this);
24 addAndMakeVisible(cancel_button_.get());
25 addOpenGlComponent(cancel_button_->getGlComponent());
26
27 delete_text_ = std::make_unique<PlainTextComponent>("Delete", "Are you sure you want to delete this preset?");
28 addOpenGlComponent(delete_text_.get());
29 delete_text_->setFontType(PlainTextComponent::kLight);
30 delete_text_->setTextSize(kTextHeight);
31 delete_text_->setJustification(Justification::centred);
32
33 preset_text_ = std::make_unique<PlainTextComponent>("Preset", "");
34 addOpenGlComponent(preset_text_.get());
35 preset_text_->setFontType(PlainTextComponent::kLight);
36 preset_text_->setTextSize(kTextHeight);
37 preset_text_->setJustification(Justification::centred);
38}
39
43 body_.setColor(findColour(Skin::kBody, true));
44
45 Colour body_text = findColour(Skin::kBodyText, true);
46 delete_text_->setColor(body_text);
47 preset_text_->setColor(body_text);
48
49 Rectangle<int> delete_rect = getDeleteRect();
50 body_.setBounds(delete_rect);
51
52 int padding_x = size_ratio_ * kPaddingX;
53 int padding_y = size_ratio_ * kPaddingY;
54 int button_height = size_ratio_ * kButtonHeight;
55
56 float button_width = (delete_rect.getWidth() - 3 * padding_x) / 2.0f;
57 cancel_button_->setBounds(delete_rect.getX() + padding_x,
58 delete_rect.getBottom() - padding_y - button_height,
59 button_width, button_height);
60 delete_button_->setBounds(delete_rect.getX() + button_width + 2 * padding_x,
61 delete_rect.getBottom() - padding_y - button_height,
62 button_width, button_height);
63
64 float text_size = kTextHeight * size_ratio_;
65 delete_text_->setTextSize(text_size);
66 preset_text_->setTextSize(text_size);
67
68 float text_height = 22.0f * size_ratio_;
69 delete_text_->setBounds(delete_rect.getX() + padding_x, delete_rect.getY() + padding_y,
70 delete_rect.getWidth() - 2 * padding_x, text_height);
71 preset_text_->setBounds(delete_rect.getX() + padding_x, delete_rect.getY() + padding_y + 30 * size_ratio_,
72 delete_rect.getWidth() - 2 * padding_x, text_height);
73 preset_text_->setText(file_.getFileNameWithoutExtension());
74
76}
77
79void DeleteSection::setVisible(bool should_be_visible) {
80 Overlay::setVisible(should_be_visible);
81
82 if (should_be_visible) {
83 Image image(Image::ARGB, 1, 1, false);
84 Graphics g(image);
86 }
87}
88
91void DeleteSection::mouseUp(const MouseEvent &e) {
92 if (!getDeleteRect().contains(e.getPosition()))
93 setVisible(false);
94}
95
98void DeleteSection::buttonClicked(Button* clicked_button) {
99 if (clicked_button == delete_button_.get()) {
100 file_.deleteRecursively();
101 setVisible(false);
102 for (Listener* listener : listeners_)
103 listener->fileDeleted(file_);
104 }
105 else if (clicked_button == cancel_button_.get())
106 setVisible(false);
107}
108
112 int width = kDeleteWidth * size_ratio_;
113 int height = kDeleteHeight * size_ratio_;
114 int x = (getWidth() - width) / 2;
115 int y = (getHeight() - height) / 2;
116 return Rectangle<int>(x, y, width, height);
117}
Interface for objects that need to respond when a file is deleted.
Definition delete_section.h:32
static constexpr int kDeleteWidth
Width of the delete confirmation box.
Definition delete_section.h:18
Rectangle< int > getDeleteRect()
Definition delete_section.cpp:111
static constexpr int kPaddingX
Horizontal padding inside the confirmation box.
Definition delete_section.h:24
void buttonClicked(Button *clicked_button) override
Definition delete_section.cpp:98
void mouseUp(const MouseEvent &e) override
Definition delete_section.cpp:91
static constexpr int kPaddingY
Vertical padding inside the confirmation box.
Definition delete_section.h:26
static constexpr int kTextHeight
The height of the text within the confirmation box.
Definition delete_section.h:22
void resized() override
Lays out the components inside the delete confirmation box.
Definition delete_section.cpp:41
DeleteSection(const String &name)
Constructs a DeleteSection overlay with a message, filename, and Delete/Cancel buttons.
Definition delete_section.cpp:10
static constexpr int kDeleteHeight
Height of the delete confirmation box.
Definition delete_section.h:20
void setVisible(bool should_be_visible) override
Sets the visibility of the DeleteSection. Repaints background if becoming visible.
Definition delete_section.cpp:79
static constexpr int kButtonHeight
Height of the buttons inside the confirmation box.
Definition delete_section.h:28
force_inline void setColor(Colour color)
Sets the base color for the quads.
Definition open_gl_multi_quad.h:102
void setRounding(float rounding)
Sets the rounding radius of the quads.
Definition open_gl_multi_quad.h:347
A SynthSection that displays an overlay with a background and optional listeners.
Definition overlay.h:180
virtual void resized() override
Called when the overlay is resized. Updates background color and size.
Definition overlay.h:237
void setVisible(bool should_be_visible) override
Sets the visibility of the overlay and notifies listeners.
Definition overlay.h:224
float size_ratio_
A scaling factor for the overlay size.
Definition overlay.h:267
@ kLight
Definition open_gl_image_component.h:309
Manages and provides access to vertex and fragment shaders used by the OpenGL rendering pipeline.
Definition shaders.h:19
@ kBodyRounding
Definition skin.h:71
@ kBodyText
Definition skin.h:133
@ kBody
Definition skin.h:129
void paintOpenGlChildrenBackgrounds(Graphics &g)
Paints the backgrounds for all OpenGL child components.
Definition synth_section.cpp:267
float findValue(Skin::ValueId value_id) const
Finds a value in the skin overrides or from the parent if not found locally.
Definition synth_section.cpp:18
void addOpenGlComponent(OpenGlComponent *open_gl_component, bool to_beginning=false)
Definition synth_section.cpp:489
Declares the DeleteSection class, which provides a confirmation overlay for deleting a preset file.