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.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.classdb;
23 import godot.resource;
24 import godot.image;
25 import godot.reference;
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 	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 _classBinding
41 	{
42 		__gshared:
43 		@GodotName("create") GodotMethod!(void, Vector2) create;
44 		@GodotName("create_from_image_alpha") GodotMethod!(void, Image, double) createFromImageAlpha;
45 		@GodotName("set_bit") GodotMethod!(void, Vector2, bool) setBit;
46 		@GodotName("get_bit") GodotMethod!(bool, Vector2) getBit;
47 		@GodotName("set_bit_rect") GodotMethod!(void, Rect2, bool) setBitRect;
48 		@GodotName("get_true_bit_count") GodotMethod!(long) getTrueBitCount;
49 		@GodotName("get_size") GodotMethod!(Vector2) getSize;
50 		@GodotName("_set_data") GodotMethod!(void, Dictionary) _setData;
51 		@GodotName("_get_data") GodotMethod!(Dictionary) _getData;
52 		@GodotName("grow_mask") GodotMethod!(void, long, Rect2) growMask;
53 		@GodotName("opaque_to_polygons") GodotMethod!(Array, Rect2, double) opaqueToPolygons;
54 	}
55 	bool opEquals(in BitMap other) const { return _godot_object.ptr is other._godot_object.ptr; }
56 	BitMap opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
57 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
58 	mixin baseCasts;
59 	static BitMap _new()
60 	{
61 		static godot_class_constructor constructor;
62 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("BitMap");
63 		if(constructor is null) return typeof(this).init;
64 		return cast(BitMap)(constructor());
65 	}
66 	@disable new(size_t s);
67 	/**
68 	Creates a bitmap with the specified size, filled with false.
69 	*/
70 	void create(in Vector2 size)
71 	{
72 		checkClassBinding!(typeof(this))();
73 		ptrcall!(void)(_classBinding.create, _godot_object, size);
74 	}
75 	/**
76 	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.
77 	*/
78 	void createFromImageAlpha(Image image, in double threshold = 0.1)
79 	{
80 		checkClassBinding!(typeof(this))();
81 		ptrcall!(void)(_classBinding.createFromImageAlpha, _godot_object, image, threshold);
82 	}
83 	/**
84 	Sets the bitmap's element at the specified position, to the specified value.
85 	*/
86 	void setBit(in Vector2 position, in bool bit)
87 	{
88 		checkClassBinding!(typeof(this))();
89 		ptrcall!(void)(_classBinding.setBit, _godot_object, position, bit);
90 	}
91 	/**
92 	Returns bitmap's value at the specified position.
93 	*/
94 	bool getBit(in Vector2 position) const
95 	{
96 		checkClassBinding!(typeof(this))();
97 		return ptrcall!(bool)(_classBinding.getBit, _godot_object, position);
98 	}
99 	/**
100 	Sets a rectangular portion of the bitmap to the specified value.
101 	*/
102 	void setBitRect(in Rect2 p_rect, in bool bit)
103 	{
104 		checkClassBinding!(typeof(this))();
105 		ptrcall!(void)(_classBinding.setBitRect, _godot_object, p_rect, bit);
106 	}
107 	/**
108 	Returns the amount of bitmap elements that are set to true.
109 	*/
110 	long getTrueBitCount() const
111 	{
112 		checkClassBinding!(typeof(this))();
113 		return ptrcall!(long)(_classBinding.getTrueBitCount, _godot_object);
114 	}
115 	/**
116 	Returns bitmap's dimensions.
117 	*/
118 	Vector2 getSize() const
119 	{
120 		checkClassBinding!(typeof(this))();
121 		return ptrcall!(Vector2)(_classBinding.getSize, _godot_object);
122 	}
123 	/**
124 	
125 	*/
126 	void _setData(in Dictionary arg0)
127 	{
128 		Array _GODOT_args = Array.empty_array;
129 		_GODOT_args.append(arg0);
130 		String _GODOT_method_name = String("_set_data");
131 		this.callv(_GODOT_method_name, _GODOT_args);
132 	}
133 	/**
134 	
135 	*/
136 	Dictionary _getData() const
137 	{
138 		Array _GODOT_args = Array.empty_array;
139 		String _GODOT_method_name = String("_get_data");
140 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Dictionary);
141 	}
142 	/**
143 	
144 	*/
145 	void growMask(in long pixels, in Rect2 rect)
146 	{
147 		checkClassBinding!(typeof(this))();
148 		ptrcall!(void)(_classBinding.growMask, _godot_object, pixels, rect);
149 	}
150 	/**
151 	
152 	*/
153 	Array opaqueToPolygons(in Rect2 rect, in double epsilon = 2) const
154 	{
155 		checkClassBinding!(typeof(this))();
156 		return ptrcall!(Array)(_classBinding.opaqueToPolygons, _godot_object, rect, epsilon);
157 	}
158 	/**
159 	
160 	*/
161 	@property Dictionary data()
162 	{
163 		return _getData();
164 	}
165 	/// ditto
166 	@property void data(Dictionary v)
167 	{
168 		_setData(v);
169 	}
170 }