1 /**
2 Boolean matrix.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.bitmap;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.classdb;
24 import godot.resource;
25 import godot.image;
26 /**
27 Boolean matrix.
28 
29 A two-dimensional array of boolean values, can be used to efficiently store a binary matrix (every matrix element takes only one bit) and query the values using natural cartesian coordinates.
30 */
31 @GodotBaseClass struct BitMap
32 {
33 	package(godot) enum string _GODOT_internal_name = "BitMap";
34 public:
35 @nogc nothrow:
36 	union { /** */ godot_object _godot_object; /** */ Resource _GODOT_base; }
37 	alias _GODOT_base this;
38 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
39 	package(godot) __gshared bool _classBindingInitialized = false;
40 	package(godot) static struct GDNativeClassBinding
41 	{
42 		__gshared:
43 		@GodotName("_get_data") GodotMethod!(Dictionary) _getData;
44 		@GodotName("_set_data") GodotMethod!(void, Dictionary) _setData;
45 		@GodotName("create") GodotMethod!(void, Vector2) create;
46 		@GodotName("create_from_image_alpha") GodotMethod!(void, Image, double) createFromImageAlpha;
47 		@GodotName("get_bit") GodotMethod!(bool, Vector2) getBit;
48 		@GodotName("get_size") GodotMethod!(Vector2) getSize;
49 		@GodotName("get_true_bit_count") GodotMethod!(long) getTrueBitCount;
50 		@GodotName("grow_mask") GodotMethod!(void, long, Rect2) growMask;
51 		@GodotName("opaque_to_polygons") GodotMethod!(Array, Rect2, double) opaqueToPolygons;
52 		@GodotName("set_bit") GodotMethod!(void, Vector2, bool) setBit;
53 		@GodotName("set_bit_rect") GodotMethod!(void, Rect2, bool) setBitRect;
54 	}
55 	/// 
56 	pragma(inline, true) bool opEquals(in BitMap other) const
57 	{ return _godot_object.ptr is other._godot_object.ptr; }
58 	/// 
59 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
60 	{ _godot_object.ptr = n; return null; }
61 	/// 
62 	pragma(inline, true) bool opEquals(typeof(null) n) const
63 	{ return _godot_object.ptr is n; }
64 	/// 
65 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
66 	mixin baseCasts;
67 	/// Construct a new instance of BitMap.
68 	/// Note: use `memnew!BitMap` instead.
69 	static BitMap _new()
70 	{
71 		static godot_class_constructor constructor;
72 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("BitMap");
73 		if(constructor is null) return typeof(this).init;
74 		return cast(BitMap)(constructor());
75 	}
76 	@disable new(size_t s);
77 	/**
78 	
79 	*/
80 	Dictionary _getData() const
81 	{
82 		Array _GODOT_args = Array.make();
83 		String _GODOT_method_name = String("_get_data");
84 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Dictionary);
85 	}
86 	/**
87 	
88 	*/
89 	void _setData(in Dictionary arg0)
90 	{
91 		Array _GODOT_args = Array.make();
92 		_GODOT_args.append(arg0);
93 		String _GODOT_method_name = String("_set_data");
94 		this.callv(_GODOT_method_name, _GODOT_args);
95 	}
96 	/**
97 	Creates a bitmap with the specified size, filled with `false`.
98 	*/
99 	void create(in Vector2 size)
100 	{
101 		checkClassBinding!(typeof(this))();
102 		ptrcall!(void)(GDNativeClassBinding.create, _godot_object, size);
103 	}
104 	/**
105 	Creates a bitmap that matches the given image dimensions, every element of the bitmap is set to `false` if the alpha value of the image at that position is equal to `threshold` or less, and `true` in other case.
106 	*/
107 	void createFromImageAlpha(Image image, in double threshold = 0.1)
108 	{
109 		checkClassBinding!(typeof(this))();
110 		ptrcall!(void)(GDNativeClassBinding.createFromImageAlpha, _godot_object, image, threshold);
111 	}
112 	/**
113 	Returns bitmap's value at the specified position.
114 	*/
115 	bool getBit(in Vector2 position) const
116 	{
117 		checkClassBinding!(typeof(this))();
118 		return ptrcall!(bool)(GDNativeClassBinding.getBit, _godot_object, position);
119 	}
120 	/**
121 	Returns bitmap's dimensions.
122 	*/
123 	Vector2 getSize() const
124 	{
125 		checkClassBinding!(typeof(this))();
126 		return ptrcall!(Vector2)(GDNativeClassBinding.getSize, _godot_object);
127 	}
128 	/**
129 	Returns the amount of bitmap elements that are set to `true`.
130 	*/
131 	long getTrueBitCount() const
132 	{
133 		checkClassBinding!(typeof(this))();
134 		return ptrcall!(long)(GDNativeClassBinding.getTrueBitCount, _godot_object);
135 	}
136 	/**
137 	Applies morphological dilation to the bitmap. The first argument is the dilation amount, Rect2 is the area where the dilation will be applied.
138 	*/
139 	void growMask(in long pixels, in Rect2 rect)
140 	{
141 		checkClassBinding!(typeof(this))();
142 		ptrcall!(void)(GDNativeClassBinding.growMask, _godot_object, pixels, rect);
143 	}
144 	/**
145 	
146 	*/
147 	Array opaqueToPolygons(in Rect2 rect, in double epsilon = 2) const
148 	{
149 		checkClassBinding!(typeof(this))();
150 		return ptrcall!(Array)(GDNativeClassBinding.opaqueToPolygons, _godot_object, rect, epsilon);
151 	}
152 	/**
153 	Sets the bitmap's element at the specified position, to the specified value.
154 	*/
155 	void setBit(in Vector2 position, in bool bit)
156 	{
157 		checkClassBinding!(typeof(this))();
158 		ptrcall!(void)(GDNativeClassBinding.setBit, _godot_object, position, bit);
159 	}
160 	/**
161 	Sets a rectangular portion of the bitmap to the specified value.
162 	*/
163 	void setBitRect(in Rect2 rect, in bool bit)
164 	{
165 		checkClassBinding!(typeof(this))();
166 		ptrcall!(void)(GDNativeClassBinding.setBitRect, _godot_object, rect, bit);
167 	}
168 	/**
169 	
170 	*/
171 	@property Dictionary data()
172 	{
173 		return _getData();
174 	}
175 	/// ditto
176 	@property void data(Dictionary v)
177 	{
178 		_setData(v);
179 	}
180 }