iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestDragNDropControl.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
23{
24public:
25 TestDragAndDropControl(const IRECT& bounds)
26 : IControl(bounds)
27 {
28 SetTooltip("TestDragAndDropControl - Drag 'n drop here and see what is dropped");
29 }
30
31 void Draw(IGraphics& g) override
32 {
33 g.DrawDottedRect(COLOR_BLACK, mRECT);
34 g.FillRect(mMouseIsOver ? COLOR_TRANSLUCENT : COLOR_TRANSPARENT, mRECT);
35
36 if (mPaths.size())
37 {
38 IRECT r = mRECT.GetFromTop(20);
39 g.DrawText(DEFAULT_TEXT, mPaths[0].c_str(), r);
40 for (int i = 1; i < mPaths.size(); i++)
41 {
42 r.T += 20.f;
43 g.DrawText(DEFAULT_TEXT, mPaths[i].c_str(), r);
44 }
45 }
46 else
47 g.DrawText(DEFAULT_TEXT, "Drop files here", mRECT);
48 }
49
50 void OnDrop(const char* str) override
51 {
52 mPaths.clear();
53 mPaths.emplace_back(std::string(str));
54 SetDirty(false);
55 }
56
57 void OnDropMultiple(const std::vector<const char*>& paths) override
58 {
59 mPaths.clear();
60 for (auto path : paths)
61 {
62 mPaths.emplace_back(std::string(path));
63 }
64 SetDirty(false);
65 }
66
67private:
68 std::vector<std::string> mPaths;
69};
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics control.
Definition: IControl.h:49
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
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
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
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
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
Control to test dropping single and multiple files.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnDropMultiple(const std::vector< const char * > &paths) override
Implement to handle multiple items drag 'n dropped onto this control.
void OnDrop(const char *str) override
Implement to do something when something was drag 'n dropped onto this control.
Used to manage a rectangular area, independent of draw class/platform.
IRECT GetFromTop(float amount) const
Get a subrect of this IRECT bounded in Y by the top edge and 'amount'.