1 module awebview.wrapper.cpp.surface;
2 
3 mixin template Awesomium()
4 {
5     interface Surface {}
6     interface SurfaceFactory {}
7 }
8 
9 
10 mixin template Awesomium4D()
11 {
12     interface ISurfaceD
13     {
14         void paint(const(char)* src, int srcRowSpan, const(Rect)* sR, const(Rect)* dR);
15         void scroll(int dx, int dy, const(Rect)* clipR);
16     }
17 
18     interface SurfaceD2Cpp : Awesomium.Surface {}
19     extern(C++, SurfaceD2CppMember)
20     {
21         SurfaceD2Cpp newCtor(ISurfaceD);
22         void deleteDtor(SurfaceD2Cpp);
23     }
24 
25     interface ISurfaceFactoryD
26     {
27         Awesomium.Surface createSurface(Awesomium.WebView view, int width, int heigth);
28         void destroySurface(Awesomium.Surface surf);
29     }
30 
31     interface SurfaceFactoryD2Cpp : Awesomium.SurfaceFactory {}
32     extern(C++, SurfaceFactoryD2CppMember)
33     {
34         SurfaceFactoryD2Cpp newCtor(ISurfaceFactoryD);
35         void deleteDtor(SurfaceFactoryD2Cpp);
36     }
37 
38 
39     extern(C++, SurfaceMember)
40     {
41         void dtor(Awesomium.Surface);
42         void deleteDtor(Awesomium.Surface);
43         void Paint(Awesomium.Surface, char*, int, const(Rect)*, const(Rect)*);
44         void Scroll(Awesomium.Surface, int, int, const(Rect)*);
45     }
46 
47 
48     extern(C++, SurfaceFactoryMember)
49     {
50         void dtor(Awesomium.SurfaceFactory p);
51         void deleteDtor(Awesomium.SurfaceFactory p);
52         Awesomium.Surface CreateSurface(Awesomium.SurfaceFactory p, Awesomium.WebView view, int w, int h);
53         void DestroySurface(Awesomium.SurfaceFactory p, Awesomium.Surface sf);
54     }
55 }
56 
57 /+
58 /**
59 */
60 interface ISurface : Awesomium.ISurfaceD
61 {
62     inout(Awesomium.Surface) cppObj() inout @property;
63     void paint(const(char)* src, uint srcRowSpan, Rect sR, Rect dR);
64     void scroll(int dx, int dy, Rect clipR);
65 }
66 
67 
68 final class SurfaceCpp2D : ISurface
69 {
70     this(Awesomium.Surface surf, bool manage)
71     { _obj = surf; _manage = manage; }
72 
73     ~this(){ if(_manage) AweSM.deleteDtor(surf); }
74 
75   override
76   {
77     void paint(const(char)* src, int srcRowSpan, const(Rect)* sR, const(Rect)* dR)
78     { AweSM.Print(_obj. src, srcRowSpan, sR, dR); }
79 
80     void scroll(int dx, int dy, const(Rect)* clipR)
81     { AweSM.Scroll(_obj, dx, dy, clipR); }
82 
83     inout(Awesomium.Surface) cppObj() inout @property { return _obj; }
84 
85     void paint(const(char)* src, uint srcRowSpan, Rect sR, Rect dR)
86     { this.print(src, srcRowSpan, &sR, &dR); }
87 
88     void scroll(int dx, int dy, Rect clipR)
89     { this.scroll(dx, dy, &clipR); }
90   }
91 
92   private:
93     Awesomium.Surface _obj;
94 
95     alias AweSM = awebview.SurfaceMember;
96 } 
97 
98 
99 /**
100 */
101 interface ISurfaceFactory : Awesomium.ISurfaceFactoryD
102 {
103     inout(Awesomium.SurfaceFactory) cppObj() inout @property;
104     ISurface createSurface(IWebView view, uint width, uint height);
105     void destroySurface(ISurface sf);
106 }
107 
108 
109 final class SurfaceFactoryCpp2D : ISurfaceFactory
110 {
111     this(Awesomium.SurfaceFactory sf, bool manage = false)
112     { _obj = sf; _manage = manage; }
113 
114     ~this() { if(_manage) AweSFM.deleteDtor(sf); }
115 
116   override
117   {
118     Awesomium.Surface createSurface(Awesomium.WebView view, int width, int heigth)
119     { AweSFM.CreateSurface(_obj, view, width, height); }
120 
121     void destroySurface(Awesomium.Surface surf)
122     { AweSFM.DestroySurface(_obj, surf); }
123 
124     inout(Awesomium.SurfaceFactory) cppObj() inout @property { return _obj; }
125 
126     ISurface createSurface(IWebView view, uint width, uint height)
127     { new SurfaceCpp2D(view.cppObj, width, height); }
128 
129     void destroySurface(ISurface sf)
130     { destroySurface(sf.cppObj); }
131   }
132 
133 
134   private:
135     Awesomium.SurfaceFactory _obj;
136     bool _manage;
137 
138     alias AweSFM = awebview.SurfaceFactoryMember;
139 }
140 +/