Jamba C++ API  4.1.0
ParamAwareViews.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019 pongasoft
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  *
16  * @author Yan Pujante
17  */
18 #pragma once
19 
20 #include <unordered_map>
21 #include <vector>
23 #include <vstgui4/vstgui/lib/iviewlistener.h>
28 
29 namespace pongasoft::VST::GUI {
30 
31 using namespace VSTGUI;
32 using namespace Params;
33 
86 class ParamAwareViews : private IViewListenerAdapter
87 {
88 public:
95  template<typename TView>
96  ParamAwareView<TView> *makeParamAware(TView *iView, GUIState *iGUIState);
97 
101  void closeAll();
102 
103 private:
107  void viewWillDelete(CView *iView) override;
108 
109 private:
110  std::unordered_map<CView *, std::unique_ptr<ParamAware>> fParamAwareViews{};
111 };
112 
113 //------------------------------------------------------------------------
114 // ParamAwareViews::makeParamAware
115 //------------------------------------------------------------------------
116 template<typename TView>
118 {
119  if(iView == nullptr)
120  return nullptr;
121 
122  auto iter = fParamAwareViews.find(iView);
123 
124  if(iter == fParamAwareViews.end())
125  {
126  iView->registerViewListener(this);
127  fParamAwareViews[iView] = std::make_unique<ParamAwareView<TView>>(iView);
128  fParamAwareViews[iView]->initState(iGUIState);
129  }
130 
131  return static_cast<ParamAwareView<TView> *>(fParamAwareViews[iView].get());
132 }
133 
134 
135 }
Definition: GUIState.h:40
ParamAwareView< TView > * makeParamAware(TView *iView, GUIState *iGUIState)
Definition: ParamAwareViews.h:117
Definition: DrawContext.cpp:24
Definition: Types.h:29
This class manages the views that have been made "param aware".
Definition: ParamAwareViews.h:86
This subclass allows for registering callbacks to any kind of view without having to inherit from it.
Definition: ParamAware.h:561