1 module bindbc.kw.renderdriver;
2 
3 import bindbc.kw.rect;
4 import bindbc.kw.kwbool;
5 
6 struct KW_Texture {
7     void * texture;
8 }
9 
10 struct KW_Font {
11     void * font;
12 }
13 
14 struct KW_Surface {
15     void * surface;
16 }
17 
18 struct KW_Color {
19     ubyte r;
20     ubyte g;
21     ubyte b;
22     ubyte a;
23 }
24 
25 enum /*KW_RenderDriver_TextStyle*/ {
26     KW_TTF_STYLE_NORMAL        = 0x00,
27     KW_TTF_STYLE_BOLD          = 0x01,
28     KW_TTF_STYLE_ITALIC        = 0x02,
29     KW_TTF_STYLE_UNDERLINE     = 0x04,
30     KW_TTF_STYLE_STRIKETHROUGH = 0x08
31 }
32 
33 struct KW_RenderDriver {
34     KW_RenderCopyFunction        renderCopy;
35     KW_RenderTextFunction        renderText;
36     KW_RenderRectFunction        renderRect;
37     KW_UTF8TextSizeFunction      utf8TextSize;
38     KW_LoadFontFunction          loadFont;
39     KW_LoadFontFromMemoryFunction loadFontFromMemory;
40     KW_CreateTextureFunction     createTexture;
41     KW_CreateSurfaceFunction     createSurface;
42     KW_LoadTextureFunction       loadTexture;
43     KW_LoadSurfaceFunction       loadSurface;
44 
45     KW_GetSurfaceExtentsFunction getSurfaceExtents;
46     KW_GetTextureExtentsFunction getTextureExtents;
47     KW_BlitSurfaceFunction       blitSurface;
48 
49     KW_GetViewportSizeFunction           getViewportSize;
50 
51     KW_ReleaseTextureFunction    releaseTexture;
52     KW_ReleaseSurfaceFunction    releaseSurface;
53     KW_ReleaseFontFunction       releaseFont;
54 
55     KW_SetClipRectFunction       setClipRect;
56     KW_GetClipRectFunction       getClipRect;
57 
58     KW_GetPixelFunction          getPixel;
59 
60     KW_ReleaseDriverFunction     release;
61 
62     void * priv;
63 }
64 
65 extern (C) @nogc nothrow {
66     KW_Color KW_MultiplyColor(KW_Color color, float amount);
67     alias KW_RenderCopyFunction = void function(KW_RenderDriver * driver, KW_Texture * src, const KW_Rect * clip, const KW_Rect * dstRect);
68     alias KW_UTF8TextSizeFunction = void function(KW_RenderDriver * driver, KW_Font * font, const char * text, uint * width, uint * height);
69     alias KW_RenderTextFunction = KW_Texture* function(KW_RenderDriver * driver, KW_Font * font, const char * text, KW_Color color, int style);
70     alias KW_LoadFontFunction = KW_Font * function(KW_RenderDriver * driver, const char * fontFile, uint ptSize);
71     alias KW_LoadFontFromMemoryFunction = KW_Font * function(KW_RenderDriver * driver, const void * fontMemory, ulong memSize, uint ptSize);
72     alias KW_CreateTextureFunction = KW_Texture * function(KW_RenderDriver * driver, KW_Surface * src);
73     alias KW_LoadTextureFunction = KW_Texture * function(KW_RenderDriver * driver, const char * file);
74 
75     alias KW_LoadSurfaceFunction = KW_Surface * function(KW_RenderDriver * driver, const char * file);
76     alias KW_ReleaseTextureFunction = void function(KW_RenderDriver * driver, KW_Texture * texture);
77     alias KW_ReleaseSurfaceFunction = void function(KW_RenderDriver * driver, KW_Surface * surface);
78     alias KW_ReleaseFontFunction = void function(KW_RenderDriver * driver, KW_Font * font);
79     alias KW_CreateSurfaceFunction = KW_Surface * function(KW_RenderDriver * driver, uint width, uint height);
80     alias KW_GetSurfaceExtentsFunction = void function(KW_RenderDriver * driver, const KW_Surface * surface, uint * width, uint * height);
81     alias KW_GetTextureExtentsFunction = void function(KW_RenderDriver * driver, KW_Texture * texture, uint * width, uint * height);
82     alias KW_BlitSurfaceFunction = void function(KW_RenderDriver * driver, KW_Surface * src, const KW_Rect * srcRect, KW_Surface * dst, const KW_Rect * dstRect);
83     alias KW_SetClipRectFunction = void function(KW_RenderDriver * driver, const KW_Rect * clip, int force);
84     alias KW_GetClipRectFunction = KW_bool function(KW_RenderDriver * driver, KW_Rect * clip);
85     alias KW_GetPixelFunction = uint function(KW_RenderDriver * driver, KW_Surface * surface, uint px, uint py);
86     alias KW_RenderRectFunction = void function(KW_RenderDriver * driver, KW_Rect * rect, KW_Color color);
87     alias KW_GetViewportSizeFunction = void function(KW_RenderDriver * driver, KW_Rect * rect);
88 
89     alias KW_ReleaseDriverFunction = void function(KW_RenderDriver * driver);
90 }
91 
92 version(BindKiwi_Static){
93     extern (C) @nogc nothrow {
94         void KW_RenderRect(KW_RenderDriver * driver, KW_Rect * rect, KW_Color color);
95         void KW_BlitSurface(KW_RenderDriver * driver, KW_Surface * src, const KW_Rect * srcRect, KW_Surface * dst, const KW_Rect * dstRect);
96         KW_Surface * KW_CreateSurface(KW_RenderDriver * driver, uint width, uint height);
97         void KW_GetSurfaceExtents(KW_RenderDriver * driver, const KW_Surface * surface, uint * width, uint * height);
98         void KW_GetTextureExtents(KW_RenderDriver * driver, KW_Texture * texture, uint * width, uint * height);
99         void KW_RenderCopy(KW_RenderDriver * driver, KW_Texture * src, const KW_Rect * clip, const KW_Rect * dstRect);
100         KW_Texture * KW_RenderText(KW_RenderDriver * driver, KW_Font * font, const char * text, KW_Color color, int style);
101         KW_Font * KW_LoadFont(KW_RenderDriver * driver, const char * fontFile, uint ptSize);
102         KW_Font * KW_LoadFontFromMemory(KW_RenderDriver * driver, const void * fontMemory, ulong memSize, uint ptSize);
103         KW_Texture * KW_CreateTexture(KW_RenderDriver * driver, KW_Surface * surface);
104         KW_Texture * KW_LoadTexture(KW_RenderDriver * driver, const char * file);
105         KW_Surface * KW_LoadSurface(KW_RenderDriver * driver, const char * file);
106         void KW_ReleaseTexture(KW_RenderDriver * driver, KW_Texture * texture);
107         void KW_ReleaseSurface(KW_RenderDriver * driver, KW_Surface * surface);
108         void KW_ReleaseFont(KW_RenderDriver * driver, KW_Font * font);
109         KW_bool KW_GetClipRect(KW_RenderDriver * driver, KW_Rect * clip);
110         void KW_GetViewportSize(KW_RenderDriver * driver, KW_Rect * rect);
111         void KW_SetClipRect(KW_RenderDriver * driver, const KW_Rect * clip, int force);
112         void KW_ReleaseRenderDriver(KW_RenderDriver * driver);
113         void KW_UTF8TextSize(KW_RenderDriver * driver, KW_Font * font, const char * text, uint * width, uint * height);
114         uint KW_GetPixel(KW_RenderDriver * driver, KW_Surface * surface, uint x, uint y);
115     }
116 } else {
117     extern (C) @nogc nothrow {
118         alias pKW_RenderRect = void function(KW_RenderDriver * driver, KW_Rect * rect, KW_Color color);
119         alias pKW_BlitSurface = void function(KW_RenderDriver * driver, KW_Surface * src, const KW_Rect * srcRect, KW_Surface * dst, const KW_Rect * dstRect);
120         alias pKW_CreateSurface = KW_Surface* function(KW_RenderDriver * driver, uint width, uint height);
121         alias pKW_GetSurfaceExtents = void function(KW_RenderDriver * driver, const KW_Surface * surface, uint * width, uint * height);
122         alias pKW_GetTextureExtents = void function(KW_RenderDriver * driver, KW_Texture * texture, uint * width, uint * height);
123         alias pKW_RenderCopy = void function(KW_RenderDriver * driver, KW_Texture * src, const KW_Rect * clip, const KW_Rect * dstRect);
124         alias pKW_RenderText = KW_Texture* function(KW_RenderDriver * driver, KW_Font * font, const char * text, KW_Color color, int style);
125         alias pKW_LoadFont = KW_Font* function(KW_RenderDriver * driver, const char * fontFile, uint ptSize);
126         alias pKW_LoadFontFromMemory = KW_Font* function(KW_RenderDriver * driver, const void * fontMemory, ulong memSize, uint ptSize);
127         alias pKW_CreateTexture = KW_Texture* function(KW_RenderDriver * driver, KW_Surface * surface);
128         alias pKW_LoadTexture = KW_Texture* function(KW_RenderDriver * driver, const char * file);
129         alias pKW_LoadSurface = KW_Surface* function(KW_RenderDriver * driver, const char * file);
130         alias pKW_ReleaseTexture = void function(KW_RenderDriver * driver, KW_Texture * texture);
131         alias pKW_ReleaseSurface = void function(KW_RenderDriver * driver, KW_Surface * surface);
132         alias pKW_ReleaseFont = void function(KW_RenderDriver * driver, KW_Font * font);
133         alias pKW_GetClipRect = KW_bool function(KW_RenderDriver * driver, KW_Rect * clip);
134         alias pKW_GetViewportSize = void function(KW_RenderDriver * driver, KW_Rect * rect);
135         alias pKW_SetClipRect = void function(KW_RenderDriver * driver, const KW_Rect * clip, int force);
136         alias pKW_ReleaseRenderDriver = void function(KW_RenderDriver * driver);
137         alias pKW_UTF8TextSize = void function(KW_RenderDriver * driver, KW_Font * font, const char * text, uint * width, uint * height);
138         alias pKW_GetPixel = uint function(KW_RenderDriver * driver, KW_Surface * surface, uint x, uint y);
139     }
140     __gshared {
141         pKW_RenderRect KW_RenderRect;
142         pKW_BlitSurface KW_BlitSurface;
143         pKW_CreateSurface KW_CreateSurface;
144         pKW_GetSurfaceExtents KW_GetSurfaceExtents;
145         pKW_GetTextureExtents KW_GetTextureExtents;
146         pKW_RenderCopy KW_RenderCopy;
147         pKW_RenderText KW_RenderText;
148         pKW_LoadFont KW_LoadFont;
149         pKW_LoadFontFromMemory KW_LoadFontFromMemory;
150         pKW_CreateTexture KW_CreateTexture;
151         pKW_LoadTexture KW_LoadTexture;
152         pKW_LoadSurface KW_LoadSurface;
153         pKW_ReleaseTexture KW_ReleaseTexture;
154         pKW_ReleaseSurface KW_ReleaseSurface;
155         pKW_ReleaseFont KW_ReleaseFont;
156         pKW_GetClipRect KW_GetClipRect;
157         pKW_GetViewportSize KW_GetViewportSize;
158         pKW_SetClipRect KW_SetClipRect;
159         pKW_ReleaseRenderDriver KW_ReleaseRenderDriver;
160         pKW_UTF8TextSize KW_UTF8TextSize;
161         pKW_GetPixel KW_GetPixel;
162     }
163 }
164