iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestDirBrowseControl.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#pragma once
12
18#include "IControl.h"
19#include "IPlugPaths.h"
20
24{
25public:
26 TestDirBrowseControl(IRECT rect, const char* extension, const char* path)
27 : IDirBrowseControlBase(rect, extension)
28 {
29 mLabel.SetFormatted(32, "Select a %s file", extension);
30 SetPath(path);
31 SetTooltip("TestDirBrowseControl");
32 }
33
34 void OnResize() override
35 {
36 mButtonRect = mRECT.GetCentredInside(mRECT.W()-10.f, 20.f);
37 mArrowRect = mButtonRect.GetFromRight(20.).GetPadded(-5.);
38 mUsePlatformMenuTextRect = mRECT.GetFromBottom(30).GetPadded(-5);
39 mUsePlatformMenuButtonRect = mUsePlatformMenuTextRect.GetFromRight(20.).GetPadded(-5.);
40 }
41
42 void Draw(IGraphics& g) override
43 {
44 g.DrawDottedRect(COLOR_BLACK, mRECT);
45 g.FillRect(mMouseIsOver ? COLOR_TRANSLUCENT : COLOR_TRANSPARENT, mRECT);
46 g.FillRect(COLOR_WHITE, mButtonRect);
47 g.DrawText(mText, mLabel.Get(), mButtonRect);
48 g.FillTriangle(COLOR_GRAY, mArrowRect.L, mArrowRect.T, mArrowRect.R, mArrowRect.T, mArrowRect.MW(), mArrowRect.B);
49 g.DrawText(IText(DEFAULT_TEXT_SIZE, EAlign::Near), "Use platform menu", mUsePlatformMenuTextRect);
50 g.DrawRect(COLOR_BLACK, mUsePlatformMenuButtonRect);
51
52 if (mUsePlatformMenu)
53 g.FillRect(COLOR_BLACK, mUsePlatformMenuButtonRect.GetPadded(-2));
54 }
55
56 void OnPopupMenuSelection(IPopupMenu* pMenu, int valIdx) override
57 {
58 if (pMenu)
59 {
60 IPopupMenu::Item* pItem = pMenu->GetChosenItem();
61
62 if (pItem)
63 {
64 mSelectedItemIndex = mItems.Find(pItem);
65 mLabel.Set(pItem->GetText());
67 }
68 }
69
70 SetDirty(false);
71 }
72
73 void OnMouseDown(float x, float y, const IMouseMod& mod) override
74 {
75 if (mButtonRect.Contains(x, y))
76 {
77 GetUI()->CreatePopupMenu(*this, mMainMenu, x, y);
78 }
79 else if (mUsePlatformMenuButtonRect.Contains(x, y))
80 {
81 mUsePlatformMenu = !mUsePlatformMenu;
82
83 if (!mUsePlatformMenu)
85 else
87 }
88
89 SetDirty(false);
90 }
91
92 void SetPath(const char* path)
93 {
94 AddPath(path, "");
95 SetupMenu();
96 }
97
98private:
99 WDL_String mLabel;
100 bool mUsePlatformMenu = true;
101 IRECT mButtonRect;
102 IRECT mArrowRect;
103 IRECT mUsePlatformMenuTextRect;
104 IRECT mUsePlatformMenuButtonRect;
105};
This file contains the base IControl implementation, along with some base classes for specific types ...
Common paths useful for plug-ins.
IGraphics * GetUI()
Definition: IControl.h:467
bool mMouseIsOver
if mGraphics::mHandleMouseOver = true, this will be true when the mouse is over control.
Definition: IControl.h:560
IControl * SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:216
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:198
An abstract IControl base class that you can inherit from in order to make a control that pops up a m...
Definition: IControl.h:1900
void CheckSelectedItem()
Check the currently selected menu item.
Definition: IControl.cpp:1111
void SetupMenu()
Call after adding one or more paths, to populate the menu.
Definition: IControl.cpp:1041
void AddPath(const char *path, const char *displayText)
Used to add a path to scan for files.
Definition: IControl.cpp:1018
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
virtual void DrawRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f)
Draw a rectangle to the graphics context.
Definition: IGraphics.cpp:2497
void AttachPopupMenuControl(const IText &text=DEFAULT_TEXT, const IRECT &bounds=IRECT())
Attach a control for pop-up menus, to override platform style menus.
Definition: IGraphics.cpp:356
void DrawText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend=0)
Draw some text to the graphics context in a specific rectangle.
Definition: IGraphics.cpp:670
void CreatePopupMenu(IControl &control, IPopupMenu &menu, const IRECT &bounds, int valIdx=0)
Shows a pop up/contextual menu in relation to a rectangular region of the graphics context.
Definition: IGraphics.cpp:1960
virtual void DrawDottedRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f, float dashLen=2.f)
Draw a dotted rectangle to the graphics context.
Definition: IGraphics.cpp:2539
void RemovePopupMenuControl()
Remove the IGraphics popup menu, use platform popup menu if available.
Definition: IGraphics.cpp:365
virtual void FillRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill a rectangular region of the graphics context with a color.
Definition: IGraphics.cpp:2569
virtual void FillTriangle(const IColor &color, float x1, float y1, float x2, float y2, float x3, float y3, const IBlend *pBlend=0)
Fill a triangle with a color.
Definition: IGraphics.cpp:2562
A class to specify an item of a pop up menu.
A class for setting the contents of a pop up menu.
Control to test IDirBrowseControlBase.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnPopupMenuSelection(IPopupMenu *pMenu, 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().
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.
IRECT GetFromRight(float amount) const
Get a subrect of this IRECT bounded in X by 'amount' and the right edge.
IRECT GetFromBottom(float amount) const
Get a subrect of this IRECT bounded in Y by 'amount' and the bottom edge.
IRECT GetCentredInside(const IRECT &sr) const
Get a rectangle the size of sr but with the same center point as this rectangle.
float W() const
float MW() const
bool Contains(const IRECT &rhs) const
Returns true if this IRECT completely contains rhs.
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.
IText is used to manage font and text/text entry style for a piece of text on the UI,...