1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #include "zoomtest.h"
6 #include "vstgui/plugin-bindings/vst3groupcontroller.h"
7 #include <vector>
8 
9 using namespace Steinberg;
10 using namespace Steinberg::Vst;
11 
12 namespace VSTGUI {
13 
14 //------------------------------------------------------------------------
15 FUID ZoomTestProcessor::cid (0x2DEB807D, 0xB2C542D7, 0xA7D8421A, 0x835D5860);
16 FUID ZoomTestController::cid (0xB3E89625, 0x24B142F6, 0x8EA9F6CB, 0xFC4196F0);
17 
18 struct ZoomFactor {
19 	const tchar* title;
20 	double factor;
21 
ZoomFactorVSTGUI::ZoomFactor22 	ZoomFactor (const tchar* title, double factor) : title (title), factor (factor) {}
23 };
24 
25 typedef std::vector<ZoomFactor> ZoomFactorVector;
26 static ZoomFactorVector zoomFactors;
27 
28 //------------------------------------------------------------------------
29 //------------------------------------------------------------------------
30 //------------------------------------------------------------------------
ZoomTestProcessor()31 ZoomTestProcessor::ZoomTestProcessor ()
32 {
33 	setControllerClass (ZoomTestController::cid);
34 	if (zoomFactors.empty ())
35 	{
36 		zoomFactors.push_back (ZoomFactor (STR("50%"), 0.5));
37 		zoomFactors.push_back (ZoomFactor (STR("75%"), 0.75));
38 		zoomFactors.push_back (ZoomFactor (STR("100%"), 1.));
39 		zoomFactors.push_back (ZoomFactor (STR("125%"), 1.25));
40 		zoomFactors.push_back (ZoomFactor (STR("150%"), 1.5));
41 		zoomFactors.push_back (ZoomFactor (STR("175%"), 1.75));
42 		zoomFactors.push_back (ZoomFactor (STR("200%"), 2.));
43 	}
44 }
45 
46 //------------------------------------------------------------------------
initialize(FUnknown * context)47 tresult PLUGIN_API ZoomTestController::initialize (FUnknown* context)
48 {
49 	tresult res = UIDescriptionBaseController::initialize (context);
50 	if (res == kResultTrue)
51 	{
52 		StringListParameter* zoomParameter = new StringListParameter (STR ("Zoom"), 1000);
53 		for (ZoomFactorVector::const_iterator it = zoomFactors.begin(), end = zoomFactors.end(); it != end; ++it)
54 		{
55 			zoomParameter->appendString (it->title);
56 		}
57 		zoomParameter->setNormalized (zoomParameter->toNormalized (2));
58 		zoomParameter->addDependent (this);
59 		uiParameters.addParameter (zoomParameter);
60 	}
61 	return res;
62 }
63 
64 //------------------------------------------------------------------------
createView(FIDString name)65 IPlugView* PLUGIN_API ZoomTestController::createView (FIDString name)
66 {
67 	if (strcmp (name, ViewType::kEditor) == 0)
68 	{
69 		return new VST3Editor (this, "view", "zoomtest.uidesc");
70 	}
71 	return 0;
72 }
73 
74 //------------------------------------------------------------------------
update(FUnknown * changedUnknown,int32 message)75 void PLUGIN_API ZoomTestController::update (FUnknown* changedUnknown, int32 message)
76 {
77 	Parameter* param = FCast<Parameter> (changedUnknown);
78 	if (param && param->getInfo ().id == 1000)
79 	{
80 		size_t index = static_cast<size_t> (param->toPlain (param->getNormalized ()));
81 		if (index >= zoomFactors.size ())
82 			return;
83 		for (EditorVector::const_iterator it = editors.begin (), end = editors.end (); it != end; ++it)
84 		{
85 			VST3Editor* editor = dynamic_cast<VST3Editor*>(*it);
86 			if (editor)
87 				editor->setZoomFactor(zoomFactors[index].factor);
88 		}
89 	}
90 }
91 
92 //------------------------------------------------------------------------
createSubController(UTF8StringPtr name,const IUIDescription * description,VST3Editor * editor)93 IController* ZoomTestController::createSubController (UTF8StringPtr name, const IUIDescription* description, VST3Editor* editor)
94 {
95 	if (UTF8StringView (name) == "ZoomController")
96 	{
97 		return new GroupController (uiParameters.getParameter (1000), this);
98 	}
99 	return 0;
100 }
101 
102 //------------------------------------------------------------------------
editorAttached(EditorView * editor)103 void ZoomTestController::editorAttached (EditorView* editor)
104 {
105 	editors.push_back (editor);
106 }
107 
108 //------------------------------------------------------------------------
editorRemoved(EditorView * editor)109 void ZoomTestController::editorRemoved (EditorView* editor)
110 {
111 	editors.erase (std::find (editors.begin (), editors.end (), editor));
112 }
113 
114 } // namespace VSTGUI
115