1 /**
2  * Definition of IGraphics, which controls the UI from the host point of view.
3  *
4  * Copyright: Copyright Auburn Sounds 2015 and later.
5  * License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6  * Authors:   Guillaume Piolat
7  */
8 module dplug.client.graphics;
9 
10 import dplug.client.client;
11 import dplug.client.daw;
12 
13 enum GraphicsBackend
14 {
15     autodetect,
16     win32,
17     cocoa,
18     x11
19 }
20 
21 /// Plugin GUI
22 interface IGraphics
23 {
24 nothrow:
25 @nogc:
26     /// Create an UI, return a system-specific handle for the window/view
27     abstract void* openUI(void* parentInfo,
28                           void* controlInfo, // must be null, was a Carbon thing
29                           IClient client,
30                           GraphicsBackend backend);
31 
32     /// Close that UI.
33     abstract void closeUI();
34 
35     /// Get the current plugin UI size in logical pixels.
36     abstract void getGUISize(int* widthLogicalPixels, int* heightLogicalPixels);
37 
38     /// Get the desired plugin UI size in logical pixels.
39     /// Basically while a plugin is resized, its desired UI size might not match the "current" plugin size.
40     /// We makes this super rare, and only to fix resize problems.
41     /// Typically used when the host want to resize a window itself.
42     /// FUTURE: deemphasize getGUISize vs getDesiredGUISize.
43     abstract void getDesiredGUISize(int* widthLogicalPixels, int* heightLogicalPixels);
44 
45     /// Used by CLAP and VST3.
46     /// Returns: `true` if plugin is resizeable in terms of logical pixels.
47     abstract bool isResizeable();
48 
49     /// Used by CLAP.
50     /// Returns: `true` if plugin is resizeable in terms of logical pixels, horizontally.
51     abstract bool isResizeableHorizontally();
52     abstract bool isResizeableVertically();
53 
54     /// Used by CLAP and VST3.
55     /// Returns: Maximum valid size that still fits into a `inoutWidth x inoutHeight` rectangle.
56     ///          When one of the criterion is impossible to satisfy, returning a valid size is preferred.
57     /// This should work even if the UI is closed.
58     abstract void getMaxSmallerValidSize(int* inoutWidth, int* inoutHeight);
59 
60     /// Used by VST3.
61     /// Returns: Nearest, valid size in logical pixels, given an input size in logical pixels.
62     /// This should work even if the UI is closed.
63     /// Hack: Used by FLP format to find minimum and maximum size of window in logical pixels.
64     abstract void getNearestValidSize(int* inoutWidth, int* inoutHeight);
65 
66     /// Used by CLAP and VST3.
67     /// Tells the native window to resize itself.
68     /// Called by the host when it's one resizing the parent window, and wants our window to follow suit.
69     /// This is to be forwarded to IWindow.
70     /// Returns: `true` if properly resized.
71     abstract bool nativeWindowResize(int newWidthLogicalPixels, int newHeightLogicalPixels);
72 
73     /// Used by CLAP.
74     /// Returns: `true` if plugin is preserves an apsect ratio, even though it reality sizes will be rounded
75     ///          to integer logical pixels.
76     ///         false if not resizeable or doesn't preserve a ratio.
77     abstract bool isAspectRatioPreserved();
78 
79     /// Used by CLAP.
80     /// Only makes sense if `isAspectRatioPreserved` returned true, else it's UB.
81     abstract int[2] getPreservedAspectRatio();
82 }
83