1 
2 //          Copyright 2018 - 2021 Michael D. Parker
3 // Distributed under the Boost Software License, Version 1.0.
4 //    (See accompanying file LICENSE_1_0.txt or copy at
5 //          http://www.boost.org/LICENSE_1_0.txt)
6 
7 module bindbc.sdl.bind.sdlshape;
8 
9 import bindbc.sdl.config;
10 import bindbc.sdl.bind.sdlpixels : SDL_Color;
11 import bindbc.sdl.bind.sdlstdinc : SDL_bool;
12 import bindbc.sdl.bind.sdlsurface : SDL_Surface;
13 import bindbc.sdl.bind.sdlvideo : SDL_Window, SDL_WindowFlags;
14 
15 enum {
16     SDL_NONSHAPEABLE_WINDOW = -1,
17     SDL_INVALID_SHAPE_ARGUMENT = -2,
18     SDL_WINDOW_LACKS_SHAPE = -3,
19 }
20 
21 enum WindowShapeMode {
22     ShapeModeDefault,
23     ShapeModeBinarizeAlpha,
24     ShapeModeReverseBinarizeAlpha,
25     ShapeModeColorKey
26 }
27 mixin(expandEnum!WindowShapeMode);
28 
29 enum SDL_SHAPEMODEALPHA(WindowShapeMode mode) = (mode == ShapeModeDefault || mode == ShapeModeBinarizeAlpha || mode == ShapeModeReverseBinarizeAlpha);
30 
31 union SDL_WindowShapeParams {
32     ubyte binarizationCutoff;
33     SDL_Color colorKey;
34 }
35 
36 struct SDL_WindowShapeMode {
37     WindowShapeMode mode;
38     SDL_WindowShapeParams parameters;
39 }
40 
41 static if(staticBinding) {
42     extern(C) @nogc nothrow {
43         SDL_Window* SDL_CreateShapedWindow(const(char)* title, uint x, uint y, uint w, uint h, SDL_WindowFlags flags);
44         SDL_bool SDL_IsShapedWindow(const(SDL_Window)* window);
45         int SDL_SetWindowShape(SDL_Window* window, SDL_Surface* shape, SDL_WindowShapeMode* shape_mode);
46         int SDL_GetShapedWindowMode(SDL_Window* window, SDL_WindowShapeMode* shape_mode);
47     }
48 }
49 else {
50     extern(C) @nogc nothrow {
51         alias pSDL_CreateShapedWindow = SDL_Window* function(const(char)* title, uint x, uint y, uint w, uint h, SDL_WindowFlags flags);
52         alias pSDL_IsShapedWindow = SDL_bool function(const(SDL_Window)* window);
53         alias pSDL_SetWindowShape = int function(SDL_Window* window, SDL_Surface* shape, SDL_WindowShapeMode* shape_mode);
54         alias pSDL_GetShapedWindowMode = int function(SDL_Window* window, SDL_WindowShapeMode* shape_mode);
55     }
56 
57     __gshared {
58         pSDL_CreateShapedWindow SDL_CreateShapedWindow;
59         pSDL_IsShapedWindow SDL_IsShapedWindow;
60         pSDL_SetWindowShape SDL_SetWindowShape;
61         pSDL_GetShapedWindowMode SDL_GetShapedWindowMode;
62     }
63 }