iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestMultiTouchControl.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 <map>
20
23class TestMTControl : public IControl
25{
26public:
27 TestMTControl(const IRECT& bounds)
28 : IControl(bounds)
29 {
31 }
32
33 void Draw(IGraphics& g) override
34 {
35 std::vector<ITouchID> touches;
36 g.GetTouches(this, touches);
37 WDL_String str;
38 str.SetFormatted(32, "NUM TOUCHES: %i", static_cast<int>(touches.size()));
39 g.DrawText(IText(20), str.Get(), mRECT);
40
41 g.DrawRect(COLOR_BLACK, mRECT);
42
43 if (g.CheckLayer(mLayer))
44 {
45 g.ResumeLayer(mLayer);
46
47 WDL_String str;
48
49 for (auto& touchPair : mTrackedTouches)
50 {
51 TrackedTouch* pTouch = &touchPair.second;
52 int t = pTouch->index;
53 float dim = pTouch->radius > 0.f ? pTouch->radius : 50.f;
54 IRECT r {pTouch->x-dim,pTouch->y-dim,pTouch->x+dim, pTouch->y+dim};
55 g.FillEllipse(GetRainbow(t), r);
56 g.DrawEllipse(COLOR_BLACK, r);
57 Milliseconds duration = std::chrono::high_resolution_clock::now() - pTouch->startTime;
58 str.SetFormatted(32, "%i: %i", t, static_cast<int>(duration.count()));
59 g.DrawText(IText(20.f), str.Get(), r);
60 }
61 }
62 else
63 {
64 g.StartLayer(this, mRECT);
65 }
66
67 mLayer = g.EndLayer();
68 g.DrawLayer(mLayer);
69 }
70
71 void OnMouseDown(float x, float y, const IMouseMod& mod) override
72 {
73 AddTouch(mod.touchID, x, y, mod.touchRadius);
74 }
75
76 void OnMouseUp(float x, float y, const IMouseMod& mod) override
77 {
78 ReleaseTouch(mod.touchID);
79
80 if(NTrackedTouches() == 0)
81 {
82 mLayer->Invalidate();
83 }
84
85 SetDirty(true);
86 }
87
88 void OnTouchCancelled(float x, float y, const IMouseMod& mod) override
89 {
90 OnMouseUp(x, y, mod);
91 }
92
93 void OnMouseDrag(float x, float y, float dx, float dy, const IMouseMod& mod) override
94 {
95 UpdateTouch(mod.touchID, x, y, mod.touchRadius);
96 SetDirty(true);
97 }
98
99 bool IsDirty() override
100 {
101 if(NTrackedTouches())
102 return true;
103 else
104 return IControl::IsDirty();
105 }
106
107public:
108 ILayerPtr mLayer;
109};
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
void SetWantsMultiTouch(bool enable=true)
Specify whether this control supports multiple touches.
Definition: IControl.h:430
virtual bool IsDirty()
Called at each display refresh by the IGraphics draw loop, after IControl::Animate(),...
Definition: IControl.cpp:231
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
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
virtual void FillEllipse(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill an ellipse within a rectangular region of the graphics context.
Definition: IGraphics.cpp:2613
virtual void DrawEllipse(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f)
Draw an ellipse within a rectangular region of the graphics context.
Definition: IGraphics.cpp:2548
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 ResumeLayer(ILayerPtr &layer)
If a layer already exists, continue drawing to it.
Definition: IGraphics.cpp:1987
bool CheckLayer(const ILayerPtr &layer)
Test to see if a layer needs drawing, for instance if the control's bounds were changed.
Definition: IGraphics.cpp:2032
void DrawLayer(const ILayerPtr &layer, const IBlend *pBlend=nullptr)
Draw a layer to the main IGraphics context.
Definition: IGraphics.cpp:2045
void GetTouches(IControl *pControl, std::vector< ITouchID > &touchesOnThisControl) const
Populate a vector with the touchIDs active on pControl.
Definition: IGraphics.h:1405
void StartLayer(IControl *pOwner, const IRECT &r, bool cacheable=false)
Create an IGraphics layer.
Definition: IGraphics.cpp:1977
ILayerPtr EndLayer()
End an IGraphics layer.
Definition: IGraphics.cpp:2000
A base class for controls that can do do multitouch.
Definition: IControl.h:1274
Control to test multi touch.
void OnMouseDrag(float x, float y, float dx, float dy, const IMouseMod &mod) override
Implement this method to respond to a mouse drag event on this control.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
bool IsDirty() override
Called at each display refresh by the IGraphics draw loop, after IControl::Animate(),...
void OnTouchCancelled(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a touch cancel event on this control.
void OnMouseUp(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse up event on this control.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
std::unique_ptr< ILayer > ILayerPtr
ILayerPtr is a managed pointer for transferring the ownership of layers.
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.
IText is used to manage font and text/text entry style for a piece of text on the UI,...