Vital
Loading...
Searching...
No Matches
save_section.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4
5#include "load_save.h"
7#include "overlay.h"
8#include "synth_constants.h"
9#include "json/json.h"
10
11using json = nlohmann::json;
12
21class SaveSection : public Overlay, public TextEditor::Listener {
22 public:
23 static constexpr int kSaveWidth = 630;
24 static constexpr int kSavePresetHeight = 450;
25 static constexpr int kStylePaddingX = 4;
26 static constexpr int kStylePaddingY = 4;
27 static constexpr int kStyleButtonHeight = 24;
28 static constexpr int kOverwriteWidth = 340;
29 static constexpr int kOverwriteHeight = 160;
30 static constexpr int kTextEditorHeight = 37;
31 static constexpr int kLabelHeight = 15;
32 static constexpr int kButtonHeight = 40;
33 static constexpr int kAddFolderHeight = 20;
34 static constexpr int kDivision = 150;
35 static constexpr int kPaddingX = 25;
36 static constexpr int kPaddingY = 20;
37 static constexpr int kExtraTopPadding = 10;
38
43 class Listener {
44 public:
45 virtual ~Listener() = default;
46
51 virtual void save(File preset) = 0;
52 };
53
58 SaveSection(String name);
59 virtual ~SaveSection() = default;
60
64 void resized() override;
65
70 void setVisible(bool should_be_visible) override;
71
75 void setSaveBounds();
76
80 void setOverwriteBounds();
81
87 void setTextColors(OpenGlTextEditor* editor, String empty_string);
88
93 void textEditorReturnKeyPressed(TextEditor& editor) override;
94
99 void buttonClicked(Button* clicked_button) override;
100
105 void mouseUp(const MouseEvent& e) override;
106
111 void setFileType(const String& type) { file_type_ = type; repaint(); }
112
117 void setFileExtension(const String& extension) { file_extension_ = extension; }
118
123 void setDirectory(const File& directory) { file_directory_ = directory; }
124
129 void setFileData(const json& data) { file_data_ = data; }
130
135 void setIsPreset(bool preset) {
136 saving_preset_ = preset;
137
138 if (preset) {
140 setFileType("Preset");
142 }
143 }
144
149 Rectangle<int> getSaveRect();
150
155 Rectangle<int> getOverwriteRect();
156
161 void addSaveListener(Listener* listener) { listeners_.push_back(listener); }
162
163 private:
167 void save();
168
169 bool overwrite_;
170 bool saving_preset_;
171
172 String file_type_;
173 String file_extension_;
174 File file_directory_;
175 json file_data_;
176
177 OpenGlQuad body_;
178
179 std::unique_ptr<OpenGlTextEditor> name_;
180 std::unique_ptr<OpenGlTextEditor> author_;
181 std::unique_ptr<OpenGlTextEditor> comments_;
182
183 std::unique_ptr<OpenGlToggleButton> save_button_;
184 std::unique_ptr<OpenGlToggleButton> overwrite_button_;
185 std::unique_ptr<OpenGlToggleButton> cancel_button_;
186
187 std::unique_ptr<OpenGlToggleButton> style_buttons_[LoadSave::kNumPresetStyles];
188
189 std::unique_ptr<PlainTextComponent> preset_text_;
190 std::unique_ptr<PlainTextComponent> author_text_;
191 std::unique_ptr<PlainTextComponent> style_text_;
192 std::unique_ptr<PlainTextComponent> comments_text_;
193 std::unique_ptr<PlainTextComponent> overwrite_text_;
194
195 std::vector<Listener*> listeners_;
196
197 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SaveSection)
198};
199
@ kNumPresetStyles
Definition load_save.h:66
static File getUserPresetDirectory()
Retrieves the user's preset directory.
Definition load_save.cpp:1791
A convenience class for a single quad rendered via OpenGL.
Definition open_gl_multi_quad.h:447
A text editor that uses an OpenGlImageComponent for rendering and updates the image on text changes.
Definition open_gl_image_component.h:209
A SynthSection that displays an overlay with a background and optional listeners.
Definition overlay.h:180
Interface for objects interested in the result of the save action.
Definition save_section.h:43
virtual ~Listener()=default
virtual void save(File preset)=0
Called after a file has been saved successfully.
A UI overlay for saving presets or other files.
Definition save_section.h:21
void setIsPreset(bool preset)
Configures the section for saving a preset (true) or another file type.
Definition save_section.h:135
Rectangle< int > getOverwriteRect()
Gets the rectangle bounds of the overwrite confirmation dialog.
Definition save_section.cpp:325
void mouseUp(const MouseEvent &e) override
Called when the mouse is released. Used to close the overlay if clicked outside.
Definition save_section.cpp:292
static constexpr int kPaddingX
Horizontal padding inside the dialog.
Definition save_section.h:35
void setFileData(const json &data)
Sets the data to be saved (if not saving a preset).
Definition save_section.h:129
static constexpr int kButtonHeight
Height of buttons.
Definition save_section.h:32
static constexpr int kOverwriteWidth
Width of overwrite confirmation dialog.
Definition save_section.h:28
static constexpr int kSaveWidth
Base width of the save dialog.
Definition save_section.h:23
void setFileExtension(const String &extension)
Sets the file extension to use when saving.
Definition save_section.h:117
void setTextColors(OpenGlTextEditor *editor, String empty_string)
Configures text editor colors and placeholder text.
Definition save_section.cpp:256
void resized() override
Called when the component is resized. Updates layout and positions of all elements.
Definition save_section.cpp:103
static constexpr int kExtraTopPadding
Extra top padding inside the dialog.
Definition save_section.h:37
void setSaveBounds()
Sets the layout and components for the normal save mode (not overwrite).
Definition save_section.cpp:135
static constexpr int kSavePresetHeight
Base height of the preset save dialog.
Definition save_section.h:24
static constexpr int kAddFolderHeight
Height for additional spacing.
Definition save_section.h:33
virtual ~SaveSection()=default
SaveSection(String name)
Constructs a SaveSection with a given name.
Definition save_section.cpp:18
void buttonClicked(Button *clicked_button) override
Called when a button is clicked.
Definition save_section.cpp:301
void setFileType(const String &type)
Sets the file type label shown in the dialog.
Definition save_section.h:111
static constexpr int kStylePaddingY
Vertical padding for style buttons.
Definition save_section.h:26
void setVisible(bool should_be_visible) override
Sets the visibility of this overlay. Adjusts layout when becoming visible.
Definition save_section.cpp:267
void textEditorReturnKeyPressed(TextEditor &editor) override
Called when the return key is pressed in any text editor.
Definition save_section.cpp:297
static constexpr int kOverwriteHeight
Height of overwrite confirmation dialog.
Definition save_section.h:29
static constexpr int kPaddingY
Vertical padding inside the dialog.
Definition save_section.h:36
void addSaveListener(Listener *listener)
Adds a listener to be notified when saving occurs.
Definition save_section.h:161
static constexpr int kTextEditorHeight
Height of each text editor component.
Definition save_section.h:30
void setDirectory(const File &directory)
Sets the directory where the file will be saved.
Definition save_section.h:123
void setOverwriteBounds()
Sets the layout and components for the overwrite confirmation mode.
Definition save_section.cpp:219
static constexpr int kStyleButtonHeight
Height of each style button.
Definition save_section.h:27
Rectangle< int > getSaveRect()
Gets the rectangle bounds of the main save dialog.
Definition save_section.cpp:314
static constexpr int kStylePaddingX
Horizontal padding for style buttons.
Definition save_section.h:25
static constexpr int kLabelHeight
Height of labels.
Definition save_section.h:31
static constexpr int kDivision
Horizontal division for layout.
Definition save_section.h:34
nlohmann::json json
Definition line_generator.h:7
const std::string kPresetExtension
File extension for Vital preset files.
Definition synth_constants.h:85