24BEGIN_IGRAPHICS_NAMESPACE
33 enum class ESubControl
41 const IVStyle& style = DEFAULT_STYLE.WithDrawShadows(
false).WithLabelText(DEFAULT_LABEL_TEXT.WithVAlign(EVAlign::Middle)))
54 void RestorePreset(
IPluginBase* pluginBase,
int presetIdx)
59 str.SetFormatted(32,
"Preset %i: %s", presetIdx + 1, pluginBase->
GetPresetName(presetIdx));
60 mPresetNameButton->SetLabelStr(str.Get());
72 RestorePreset(pluginBase, pSelectedMenu->GetChosenItemIdx());
79 auto prevPresetFunc = [&](
IControl* pCaller) {
83 int nPresets = pluginBase->
NPresets();
88 presetIdx = nPresets - 1;
90 RestorePreset(pluginBase, presetIdx);
93 auto nextPresetFunc = [&](
IControl* pCaller) {
97 int nPresets = pluginBase->
NPresets();
101 if (presetIdx >= nPresets)
104 RestorePreset(pluginBase, presetIdx);
107 auto choosePresetFunc = [&](
IControl* pCaller) {
113 int nPresets = pluginBase->
NPresets();
115 for (
int i = 0; i < nPresets; i++)
118 if (i == currentPresetIdx)
119 mMenu.AddItem(str, -1, IPopupMenu::Item::kChecked);
124 pCaller->GetUI()->CreatePopupMenu(*
this, mMenu, pCaller->GetRECT());
140 ForAllChildrenFunc([&](
int childIdx,
IControl* pChild){
146 IRECT GetSubControlBounds(ESubControl control)
148 auto sections = mWidgetBounds;
150 std::array<IRECT, 3> rects = {
156 return rects[(int) control];
171 using OnLoadFunc = std::function<void(
const WDL_String& path)>;
173 enum class ESubControl
182 const char* presetPath,
183 const char* fileExtension,
184 bool showFileExtensions =
true,
185 const char* label =
"",
186 const IVStyle& style = DEFAULT_STYLE.WithDrawShadows(
false).WithLabelText(DEFAULT_LABEL_TEXT.WithVAlign(EVAlign::Middle)),
187 OnLoadFunc onLoadFunc =
nullptr)
190 , mOnLoadFunc(onLoadFunc)
211 mSelectedItemIndex = mItems.Find(pItem);
212 LoadPresetAtCurrentIndex();
219 auto prevPresetFunc = [&](
IControl* pCaller) {
222 mSelectedItemIndex--;
224 if (mSelectedItemIndex < 0)
225 mSelectedItemIndex = NItems() - 1;
227 LoadPresetAtCurrentIndex();
231 auto nextPresetFunc = [&](
IControl* pCaller) {
234 mSelectedItemIndex++;
236 if (mSelectedItemIndex >= NItems())
237 mSelectedItemIndex = 0;
239 LoadPresetAtCurrentIndex();
243 auto loadPresetFunc = [&](
IControl* pCaller) {
244 WDL_String fileName, path;
245 pCaller->GetUI()->PromptForFile(fileName, path, EFileAction::Open, mExtension.Get());
247 if (path.GetLength())
254 if (fileName.GetLength())
257 LoadPresetAtCurrentIndex();
261 auto choosePresetFunc = [&](
IControl* pCaller) {
263 pCaller->GetUI()->CreatePopupMenu(*
this, mMainMenu, pCaller->GetRECT());
278 ForAllChildrenFunc([&](
int childIdx,
IControl* pChild){
283 void LoadPresetAtCurrentIndex()
285 if (mSelectedItemIndex > -1 &&
286 mSelectedItemIndex < mItems.GetSize())
290 if (!mShowFileExtensions)
292 fileName.remove_fileext();
294 mPresetNameButton->SetLabelStr(fileName.get_filepart());
299 mOnLoadFunc(fileName);
306 if (!mMainMenu.HasSubMenus())
308 mMainMenu.SetChosenItemIdx(mSelectedItemIndex);
314 IRECT GetSubControlBounds(ESubControl control)
316 auto sections = mWidgetBounds;
318 std::array<IRECT, 4> rects = {
325 return rects[(int) control];
329 OnLoadFunc mOnLoadFunc;
332END_IGRAPHICS_NAMESPACE
This file contains the base IControl implementation, along with some base classes for specific types ...
IContainerBase allows a control to nest sub controls and it clips the drawing of those subcontrols In...
The lowest level base class of an IGraphics control.
IGEditorDelegate * GetDelegate()
Gets a pointer to the class implementing the IEditorDelegate interface that handles parameter changes...
IControl * SetAnimationEndActionFunction(IActionFunction actionFunc)
Set an Action Function to be called at the end of an animation.
void SetTargetAndDrawRECTs(const IRECT &bounds)
Set BOTH the draw rect and the target area, within the graphics context for this control.
An abstract IControl base class that you can inherit from in order to make a control that pops up a m...
void ClearPathList()
Clear the menu.
void CheckSelectedItem()
Check the currently selected menu item.
void SetupMenu()
Call after adding one or more paths, to populate the menu.
void GetSelectedFile(WDL_String &path) const
Get the full path to the file if something has been selected in the menu.
void SetSelectedFile(const char *filePath)
Set the selected file based on a file path.
void AddPath(const char *path, const char *displayText)
Used to add a path to scan for files.
The lowest level base class of an IGraphics context.
Base class that contains plug-in info and state manipulation methods.
int GetCurrentPresetIdx() const
Get the index of the current, active preset.
bool RestorePreset(int idx)
Restore a preset by index.
const char * GetPresetName(int idx) const
Get the name a preset.
int NPresets() const
Gets the number of factory presets.
A "meta control" for a "preset manager" for "baked in" factory presets It adds several child buttons.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnAttached() override
Called after the control has been attached, and its delegate and graphics member variable set.
void OnPopupMenuSelection(IPopupMenu *pSelectedMenu, int valIdx) override
Implement this method to handle popup menu selection after IGraphics::CreatePopupMenu/IControlPromptU...
void OnResize() override
Called when IControl is constructed or resized using SetRect().
A "meta control" for a "preset manager" for disk-based preset files It adds several child buttons.
void OnAttached() override
Called after the control has been attached, and its delegate and graphics member variable set.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnPopupMenuSelection(IPopupMenu *pSelectedMenu, int valIdx) override
Implement this method to handle popup menu selection after IGraphics::CreatePopupMenu/IControlPromptU...
void OnResize() override
Called when IControl is constructed or resized using SetRect().
A base interface to be combined with IControl for vectorial controls "IVControls",...
IRECT MakeRects(const IRECT &parent, bool hasHandle=false)
Calculate the rectangles for the various areas, depending on the style.
void AttachIControl(IControl *pControl, const char *label)
Call in the constructor of your IVControl to link the IVectorBase and IControl.
virtual void DrawLabel(IGraphics &g)
Draw the IVControl label text.
void SplashClickActionFunc(IControl *pCaller)
The splash click action function is used by IVControls to start SplashAnimationFunc.
Used to manage a rectangular area, independent of draw class/platform.
IRECT ReduceFromRight(float amount)
Reduce in width from the right edge by 'amount' and return the removed region.
IRECT ReduceFromLeft(float amount)
Reduce in width from the left edge by 'amount' and return the removed region.
A struct encapsulating a set of properties used to configure IVControls.