1 /**
2 Host window creation.
3 
4 Copyright: Auburn Sounds 2015-2016.
5 License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6 */
7 module dplug.host.window;
8 
9 import dplug.math.box;
10 import dplug.window;
11 import dplug.graphics.image;
12 import dplug.graphics.color;
13 import dplug.host.host;
14 
15 /// Creates a new native window suitable to host the plugin window.
16 /// This window may keep a reference to pluginHost
17 IWindow createHostWindow(IPluginHost pluginHost)
18 {    
19     int[2] windowSize = pluginHost.getUISize();
20 
21     auto hostWindow = createWindow(WindowUsage.host, null, null,
22                                    new NullWindowListener, WindowBackend.autodetect, windowSize[0], windowSize[1]);
23     pluginHost.openUI(hostWindow.systemHandle());
24 
25     return hostWindow;
26 }
27 
28 /// A listener to ignore window events, since we are not interested in host windows events.
29 class NullWindowListener : IWindowListener
30 {
31 nothrow:
32 @nogc:
33 
34     bool onMouseClick(int x, int y, MouseButton mb, bool isDoubleClick, MouseState mstate)
35     {
36         return false;
37     }
38 
39     bool onMouseRelease(int x, int y, MouseButton mb, MouseState mstate)
40     {
41         return false;
42     }
43 
44     bool onMouseWheel(int x, int y, int wheelDeltaX, int wheelDeltaY, MouseState mstate)
45     {
46         return false;
47     }
48 
49     void onMouseMove(int x, int y, int dx, int dy, MouseState mstate)
50     {
51     }
52 
53     bool onKeyDown(Key key)
54     {
55         return false;
56     }
57 
58     bool onKeyUp(Key key)
59     {
60         return false;
61     }
62 
63     void onDraw(WindowPixelFormat pf)
64     {
65     }
66 
67     ImageRef!RGBA onResized(int width, int height)
68     {
69         ImageRef!RGBA fake;
70         fake.w = width;
71         fake.h = height;
72         fake.pixels = null;
73         fake.pitch = width*RGBA.sizeof;
74         return fake;
75     }
76 
77     void recomputeDirtyAreas()
78     {
79     }
80 
81     box2i getDirtyRectangle()
82     { 
83         // return empty box since the host window itself is nothing interesting to draw
84         return box2i(0, 0, 0, 0); 
85     }
86 
87     void onMouseCaptureCancelled()
88     {
89     }
90 
91     void onAnimate(double dt, double time)
92     {
93     }
94 
95     MouseCursor getMouseCursor()
96     {
97         return MouseCursor.init;
98     }
99 
100     void onMouseExitedWindow()
101     {        
102     }
103 }