iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IPlatformViewControl.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
19#include "IControl.h"
20#include "IPlugPlatformView.h"
21
22#include <functional>
23
24BEGIN_IPLUG_NAMESPACE
25BEGIN_IGRAPHICS_NAMESPACE
26
29class IPlatformViewControl : public IControl, public IPlatformView
30{
31public:
32 using AttachFunc = std::function<void(void* pParentView)>;
33
38 IPlatformViewControl(const IRECT& bounds, bool opaque = true, AttachFunc attachFunc = nullptr)
39 : IControl(bounds)
40 , IPlatformView(opaque)
41 , mAttachFunc(attachFunc)
42 {
43 }
44
46 {
47 GetUI()->RemovePlatformView(mPlatformView);
48 mPlatformView = nullptr;
49 }
50
51 void OnAttached() override
52 {
53 mPlatformView = CreatePlatformView(GetUI()->GetWindow(), mRECT.L, mRECT.T, mRECT.W(), mRECT.H(), GetUI()->GetTotalScale());
54 GetUI()->AttachPlatformView(mRECT, mPlatformView);
55 AttachSubViews(mPlatformView);
56 }
57
58 void Draw(IGraphics& g) override { /* NO-OP */ }
59
60 void OnMouseDown(float x, float y, const IMouseMod& mod) override { /* NO-OP */ }
61
62 void OnRescale() override
63 {
64 UpdateChildViewBounds();
65 }
66
67 void OnResize() override
68 {
69 UpdateChildViewBounds();
70 }
71
72 /* Override this method in separate .cpp or .mm files if you want to keep
73 * objective C out of you main layout function
74 */
75 virtual void AttachSubViews(void* pPlatformView)
76 {
77 if (mAttachFunc)
78 mAttachFunc(pPlatformView);
79 }
80
81 void* GetPlatformView()
82 {
83 return mPlatformView;
84 }
85
86 void Hide(bool hide) override
87 {
88 if (mPlatformView)
89 GetUI()->HidePlatformView(mPlatformView, hide);
90
91 IControl::Hide(hide);
92 }
93
94private:
95 void UpdateChildViewBounds()
96 {
97 auto ds = GetUI()->GetDrawScale();
98 SetChildViewBounds(mRECT.L * ds, mRECT.T * ds, mRECT.W() * ds, mRECT.H() * ds, ds);
99 }
100
101 void* mPlatformView = nullptr;
102 AttachFunc mAttachFunc;
103};
104
105END_IGRAPHICS_NAMESPACE
106END_IPLUG_NAMESPACE
107
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
IGraphics * GetUI()
Definition: IControl.h:467
virtual void Hide(bool hide)
Shows or hides the IControl.
Definition: IControl.cpp:239
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
virtual void AttachPlatformView(const IRECT &r, void *pView)
Add an OS view as a sub-view, on top of the IGraphics view.
Definition: IGraphics.h:799
virtual void HidePlatformView(void *pView, bool hide)
Hide a previously attached platform view from the IGraphics view.
Definition: IGraphics.h:808
virtual void RemovePlatformView(void *pView)
Remove a previously attached platform view from the IGraphics view.
Definition: IGraphics.h:803
float GetDrawScale() const
Gets the graphics context scaling factor.
Definition: IGraphics.h:1101
A control that let's you embed a HWND, UIView or NSView inside an IGraphics UI.
void OnAttached() override
Called after the control has been attached, and its delegate and graphics member variable set.
void OnResize() override
Called when IControl is constructed or resized using SetRect().
void OnRescale() override
Implement to do something when graphics is scaled globally (e.g.
void Hide(bool hide) override
Shows or hides the IControl.
IPlatformViewControl(const IRECT &bounds, bool opaque=true, AttachFunc attachFunc=nullptr)
Constructs an IPlatformViewControl.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.
float W() const
float H() const