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