1 /**
2 Custom generator of previews.
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.editorresourcepreviewgenerator;
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.reference;
24 import godot.texture;
25 import godot.resource;
26 /**
27 Custom generator of previews.
28 
29 Custom code to generate previews. Please check `file_dialog/thumbnail_size` in $(D EditorSettings) to find out the right size to do previews at.
30 */
31 @GodotBaseClass struct EditorResourcePreviewGenerator
32 {
33 	package(godot) enum string _GODOT_internal_name = "EditorResourcePreviewGenerator";
34 public:
35 @nogc nothrow:
36 	union { /** */ godot_object _godot_object; /** */ Reference _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("can_generate_small_preview") GodotMethod!(bool) canGenerateSmallPreview;
44 		@GodotName("generate") GodotMethod!(Texture, Resource, Vector2) generate;
45 		@GodotName("generate_from_path") GodotMethod!(Texture, String, Vector2) generateFromPath;
46 		@GodotName("generate_small_preview_automatically") GodotMethod!(bool) generateSmallPreviewAutomatically;
47 		@GodotName("handles") GodotMethod!(bool, String) handles;
48 	}
49 	/// 
50 	pragma(inline, true) bool opEquals(in EditorResourcePreviewGenerator other) const
51 	{ return _godot_object.ptr is other._godot_object.ptr; }
52 	/// 
53 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
54 	{ _godot_object.ptr = n; return null; }
55 	/// 
56 	pragma(inline, true) bool opEquals(typeof(null) n) const
57 	{ return _godot_object.ptr is n; }
58 	/// 
59 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
60 	mixin baseCasts;
61 	/// Construct a new instance of EditorResourcePreviewGenerator.
62 	/// Note: use `memnew!EditorResourcePreviewGenerator` instead.
63 	static EditorResourcePreviewGenerator _new()
64 	{
65 		static godot_class_constructor constructor;
66 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorResourcePreviewGenerator");
67 		if(constructor is null) return typeof(this).init;
68 		return cast(EditorResourcePreviewGenerator)(constructor());
69 	}
70 	@disable new(size_t s);
71 	/**
72 	If this function returns `true`, the generator will call $(D generate) or $(D generateFromPath) for small previews as well.
73 	By default, it returns `false`.
74 	*/
75 	bool canGenerateSmallPreview()
76 	{
77 		Array _GODOT_args = Array.make();
78 		String _GODOT_method_name = String("can_generate_small_preview");
79 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool);
80 	}
81 	/**
82 	Generate a preview from a given resource with the specified size. This must always be implemented.
83 	Returning an empty texture is an OK way to fail and let another generator take care.
84 	Care must be taken because this function is always called from a thread (not the main thread).
85 	*/
86 	Ref!Texture generate(Resource from, in Vector2 size)
87 	{
88 		Array _GODOT_args = Array.make();
89 		_GODOT_args.append(from);
90 		_GODOT_args.append(size);
91 		String _GODOT_method_name = String("generate");
92 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Texture);
93 	}
94 	/**
95 	Generate a preview directly from a path with the specified size. Implementing this is optional, as default code will load and call $(D generate).
96 	Returning an empty texture is an OK way to fail and let another generator take care.
97 	Care must be taken because this function is always called from a thread (not the main thread).
98 	*/
99 	Ref!Texture generateFromPath(in String path, in Vector2 size)
100 	{
101 		Array _GODOT_args = Array.make();
102 		_GODOT_args.append(path);
103 		_GODOT_args.append(size);
104 		String _GODOT_method_name = String("generate_from_path");
105 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Texture);
106 	}
107 	/**
108 	If this function returns `true`, the generator will automatically generate the small previews from the normal preview texture generated by the methods $(D generate) or $(D generateFromPath).
109 	By default, it returns `false`.
110 	*/
111 	bool generateSmallPreviewAutomatically()
112 	{
113 		Array _GODOT_args = Array.make();
114 		String _GODOT_method_name = String("generate_small_preview_automatically");
115 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool);
116 	}
117 	/**
118 	Returns `true` if your generator supports the resource of type `type`.
119 	*/
120 	bool handles(in String type)
121 	{
122 		Array _GODOT_args = Array.make();
123 		_GODOT_args.append(type);
124 		String _GODOT_method_name = String("handles");
125 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool);
126 	}
127 }