1 //-----------------------------------------------------------------------------
2 // Flags       : clang-format auto
3 // Project     : VST SDK
4 //
5 // Category    : EditorHost
6 // Filename    : public.sdk/samples/vst-hosting/editorhost/source/platform/iwindow.h
7 // Created by  : Steinberg 09.2016
8 // Description : Example of opening a plug-in editor
9 //
10 //-----------------------------------------------------------------------------
11 // LICENSE
12 // (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved
13 //-----------------------------------------------------------------------------
14 // Redistribution and use in source and binary forms, with or without modification,
15 // are permitted provided that the following conditions are met:
16 //
17 //   * Redistributions of source code must retain the above copyright notice,
18 //     this list of conditions and the following disclaimer.
19 //   * Redistributions in binary form must reproduce the above copyright notice,
20 //     this list of conditions and the following disclaimer in the documentation
21 //     and/or other materials provided with the distribution.
22 //   * Neither the name of the Steinberg Media Technologies nor the names of its
23 //     contributors may be used to endorse or promote products derived from this
24 //     software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
34 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35 // OF THE POSSIBILITY OF SUCH DAMAGE.
36 //-----------------------------------------------------------------------------
37 
38 #pragma once
39 
40 #include "pluginterfaces/gui/iplugview.h"
41 #include <memory>
42 #include <string>
43 
44 //------------------------------------------------------------------------
45 namespace Steinberg {
46 namespace Vst {
47 namespace EditorHost {
48 
49 using Coord = int32_t;
50 
51 //------------------------------------------------------------------------
52 struct Point
53 {
54 	Coord x;
55 	Coord y;
56 };
57 
58 //------------------------------------------------------------------------
59 struct Size
60 {
61 	Coord width;
62 	Coord height;
63 };
64 
65 //------------------------------------------------------------------------
66 inline bool operator!= (const Size& lhs, const Size& rhs)
67 {
68 	return lhs.width != rhs.width || lhs.height != rhs.height;
69 }
70 
71 //------------------------------------------------------------------------
72 inline bool operator== (const Size& lhs, const Size& rhs)
73 {
74 	return lhs.width == rhs.width && lhs.height == rhs.height;
75 }
76 
77 //------------------------------------------------------------------------
78 struct Rect
79 {
80 	Point origin;
81 	Size size;
82 };
83 
84 //------------------------------------------------------------------------
ViewRectToRect(ViewRect r)85 inline Rect ViewRectToRect (ViewRect r)
86 {
87 	Rect result {};
88 	result.origin.x = r.left;
89 	result.origin.y = r.top;
90 	result.size.width = r.right - r.left;
91 	result.size.height = r.bottom - r.top;
92 	return result;
93 }
94 
95 //------------------------------------------------------------------------
96 struct NativePlatformWindow
97 {
98 	FIDString type;
99 	void* ptr;
100 };
101 
102 class IWindow;
103 
104 //------------------------------------------------------------------------
105 class IWindowController
106 {
107 public:
108 	virtual ~IWindowController () noexcept = default;
109 
110 	virtual void onShow (IWindow& window) = 0;
111 	virtual void onClose (IWindow& window) = 0;
112 	virtual void onResize (IWindow& window, Size newSize) = 0;
113 	virtual void onContentScaleFactorChanged (IWindow& window, float newScaleFactor) = 0;
114 	virtual Size constrainSize (IWindow& window, Size requestedSize) = 0;
115 };
116 
117 using WindowControllerPtr = std::shared_ptr<IWindowController>;
118 
119 //------------------------------------------------------------------------
120 class IWindow
121 {
122 public:
123 	virtual ~IWindow () noexcept = default;
124 
125 	virtual void show () = 0;
126 	virtual void close () = 0;
127 	virtual void resize (Size newSize) = 0;
128 	virtual Size getContentSize () = 0;
129 
130 	virtual NativePlatformWindow getNativePlatformWindow () const = 0;
131 
132 	virtual tresult queryInterface (const TUID iid, void** obj) = 0;
133 };
134 
135 using WindowPtr = std::shared_ptr<IWindow>;
136 
137 //------------------------------------------------------------------------
138 } // EditorHost
139 } // Vst
140 } // Steinberg
141