iPlug2 - C++ Audio Plug-in Framework
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 {
25 public:
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  but = mRECT.GetCentredInside(mRECT.W()-10.f, 20.f);
37  arrow = but.GetFromRight(20.).GetPadded(-5.);
38  useplat = mRECT.GetFromBottom(30).GetPadded(-5);
39  useplatbut = useplat.GetFromRight(20.).GetPadded(-5.);
40  }
41 
42  void Draw(IGraphics& g) override
43  {
44  if(AppIsSandboxed())
45  g.DrawText(IText(14, EVAlign::Middle), "App is sandboxed... filesystem restricted", mRECT);
46  else
47  {
48  g.DrawDottedRect(COLOR_BLACK, mRECT);
49  g.FillRect(mMouseIsOver ? COLOR_TRANSLUCENT : COLOR_TRANSPARENT, mRECT);
50  g.FillRect(COLOR_WHITE, but);
51  g.DrawText(mText, mLabel.Get(), but);
52  g.FillTriangle(COLOR_GRAY, arrow.L, arrow.T, arrow.R, arrow.T, arrow.MW(), arrow.B);
53 
54 
55  g.DrawText(IText(DEFAULT_TEXT_SIZE, EAlign::Near), "Use platform menu", useplat);
56 
57  g.DrawRect(COLOR_BLACK, useplatbut);
58 
59  if(mUsePlatform)
60  g.FillRect(COLOR_BLACK, useplatbut.GetPadded(-2));
61  }
62  }
63 
64  void OnPopupMenuSelection(IPopupMenu* pMenu, int valIdx) override
65  {
66  if(pMenu)
67  {
68  IPopupMenu::Item* pItem = pMenu->GetChosenItem();
69 
70  if(pItem)
71  {
72  mSelectedIndex = pItem->GetTag();
73  mSelectedMenu = pMenu; // TODO: what if this is a submenu do we end up with pointer to an invalid object?
74  mLabel.Set(pItem->GetText());
75  }
76  }
77 
78  SetDirty(false);
79  }
80 
81  void OnMouseDown(float x, float y, const IMouseMod& mod) override
82  {
83  if(but.Contains(x, y))
84  {
85  GetUI()->CreatePopupMenu(*this, mMainMenu, x, y);
86  }
87  else if(useplatbut.Contains(x, y))
88  {
89  mUsePlatform = !mUsePlatform;
90 
91  if(!mUsePlatform)
93  }
94 
95  SetDirty(false);
96  }
97 
98  void SetPath(const char* path)
99  {
100  AddPath(path, "");
101  SetupMenu();
102  }
103 
104 private:
105  WDL_String mLabel;
106  bool mUsePlatform = true;
107  IRECT but;
108  IRECT arrow;
109  IRECT useplat;
110  IRECT useplatbut;
111 };
bool Contains(const IRECT &rhs) const
Returns true if this IRECT completely contains rhs.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
float MW() const
Used to manage a rectangular area, independent of draw class/platform.
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:2475
bool AppIsSandboxed()
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:2517
Used to manage mouse modifiers i.e.
bool mMouseIsOver
if mGraphics::mHandleMouseOver = true, this will be true when the mouse is over control.
Definition: IControl.h:545
Control to test IDirBrowseControlBase.
Common paths useful for plug-ins.
void SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:210
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:349
A class to specify an item of a pop up menu.
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:631
void OnResize() override
Called when IControl is constructed or resized using SetRect().
This file contains the base IControl implementation, along with some base classes for specific types ...
float R
Right side of the rectangle (X + W)
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:1937
float W() const
void Draw(IGraphics &g) override
Draw the control to the graphics context.
A class for setting the contents of a pop up menu.
IText is used to manage font and text/text entry style for a piece of text on the UI...
IDirBrowseControlBase(const IRECT &bounds, const char *extension, bool showFileExtensions=true)
Creates an IDirBrowseControlBase.
Definition: IControl.h:1719
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
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:2547
IRECT GetFromRight(float amount) const
Get a subrect of this IRECT bounded in X by 'amount' and the right edge.
An abstract IControl base class that you can inherit from in order to make a control that pops up a m...
Definition: IControl.h:1712
IGraphics * GetUI()
Definition: IControl.h:452
float L
Left side of the rectangle (X)
IRECT GetCentredInside(const IRECT &sr) const
Get a rectangle the size of sr but with the same center point as this rectangle.
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.
IRECT GetFromBottom(float amount) const
Get a subrect of this IRECT bounded in Y by 'amount' and the bottom edge.
void OnPopupMenuSelection(IPopupMenu *pMenu, int valIdx) override
Implement this method to handle popup menu selection after IGraphics::CreatePopupMenu/IControl::Promp...
float T
Top of the rectangle (Y)
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:2540
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:196
float B
Bottom of the rectangle (Y + H)