1 /** 2 Used by the editor to define Spatial gizmo types. 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.editorspatialgizmoplugin; 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.resource; 24 import godot.spatialmaterial; 25 import godot.editorspatialgizmo; 26 import godot.spatial; 27 import godot.texture; 28 import godot.camera; 29 /** 30 Used by the editor to define Spatial gizmo types. 31 32 EditorSpatialGizmoPlugin allows you to define a new type of Gizmo. There are two main ways to do so: extending $(D EditorSpatialGizmoPlugin) for the simpler gizmos, or creating a new $(D EditorSpatialGizmo) type. See the tutorial in the documentation for more info. 33 */ 34 @GodotBaseClass struct EditorSpatialGizmoPlugin 35 { 36 package(godot) enum string _GODOT_internal_name = "EditorSpatialGizmoPlugin"; 37 public: 38 @nogc nothrow: 39 union { /** */ godot_object _godot_object; /** */ Resource _GODOT_base; } 40 alias _GODOT_base this; 41 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 42 package(godot) __gshared bool _classBindingInitialized = false; 43 package(godot) static struct GDNativeClassBinding 44 { 45 __gshared: 46 @GodotName("add_material") GodotMethod!(void, String, SpatialMaterial) addMaterial; 47 @GodotName("can_be_hidden") GodotMethod!(bool) canBeHidden; 48 @GodotName("commit_handle") GodotMethod!(void, EditorSpatialGizmo, long, Variant, bool) commitHandle; 49 @GodotName("create_gizmo") GodotMethod!(EditorSpatialGizmo, Spatial) createGizmo; 50 @GodotName("create_handle_material") GodotMethod!(void, String, bool) createHandleMaterial; 51 @GodotName("create_icon_material") GodotMethod!(void, String, Texture, bool, Color) createIconMaterial; 52 @GodotName("create_material") GodotMethod!(void, String, Color, bool, bool, bool) createMaterial; 53 @GodotName("get_handle_name") GodotMethod!(String, EditorSpatialGizmo, long) getHandleName; 54 @GodotName("get_handle_value") GodotMethod!(Variant, EditorSpatialGizmo, long) getHandleValue; 55 @GodotName("get_material") GodotMethod!(SpatialMaterial, String, EditorSpatialGizmo) getMaterial; 56 @GodotName("get_name") GodotMethod!(String) getName; 57 @GodotName("get_priority") GodotMethod!(long) getPriority; 58 @GodotName("has_gizmo") GodotMethod!(bool, Spatial) hasGizmo; 59 @GodotName("is_handle_highlighted") GodotMethod!(bool, EditorSpatialGizmo, long) isHandleHighlighted; 60 @GodotName("is_selectable_when_hidden") GodotMethod!(bool) isSelectableWhenHidden; 61 @GodotName("redraw") GodotMethod!(void, EditorSpatialGizmo) redraw; 62 @GodotName("set_handle") GodotMethod!(void, EditorSpatialGizmo, long, Camera, Vector2) setHandle; 63 } 64 /// 65 pragma(inline, true) bool opEquals(in EditorSpatialGizmoPlugin other) const 66 { return _godot_object.ptr is other._godot_object.ptr; } 67 /// 68 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 69 { _godot_object.ptr = n; return null; } 70 /// 71 pragma(inline, true) bool opEquals(typeof(null) n) const 72 { return _godot_object.ptr is n; } 73 /// 74 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 75 mixin baseCasts; 76 /// Construct a new instance of EditorSpatialGizmoPlugin. 77 /// Note: use `memnew!EditorSpatialGizmoPlugin` instead. 78 static EditorSpatialGizmoPlugin _new() 79 { 80 static godot_class_constructor constructor; 81 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorSpatialGizmoPlugin"); 82 if(constructor is null) return typeof(this).init; 83 return cast(EditorSpatialGizmoPlugin)(constructor()); 84 } 85 @disable new(size_t s); 86 /** 87 Adds a new material to the internal material list for the plugin. It can then be accessed with $(D getMaterial). Should not be overridden. 88 */ 89 void addMaterial(in String name, SpatialMaterial material) 90 { 91 checkClassBinding!(typeof(this))(); 92 ptrcall!(void)(GDNativeClassBinding.addMaterial, _godot_object, name, material); 93 } 94 /** 95 Override this method to define whether the gizmo can be hidden or not. Returns `true` if not overridden. 96 */ 97 bool canBeHidden() 98 { 99 Array _GODOT_args = Array.make(); 100 String _GODOT_method_name = String("can_be_hidden"); 101 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 102 } 103 /** 104 Override this method to commit gizmo handles. Called for this plugin's active gizmos. 105 */ 106 void commitHandle(VariantArg2)(EditorSpatialGizmo gizmo, in long index, in VariantArg2 restore, in bool cancel) 107 { 108 Array _GODOT_args = Array.make(); 109 _GODOT_args.append(gizmo); 110 _GODOT_args.append(index); 111 _GODOT_args.append(restore); 112 _GODOT_args.append(cancel); 113 String _GODOT_method_name = String("commit_handle"); 114 this.callv(_GODOT_method_name, _GODOT_args); 115 } 116 /** 117 Override this method to return a custom $(D EditorSpatialGizmo) for the spatial nodes of your choice, return `null` for the rest of nodes. See also $(D hasGizmo). 118 */ 119 Ref!EditorSpatialGizmo createGizmo(Spatial spatial) 120 { 121 Array _GODOT_args = Array.make(); 122 _GODOT_args.append(spatial); 123 String _GODOT_method_name = String("create_gizmo"); 124 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!EditorSpatialGizmo); 125 } 126 /** 127 Creates a handle material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with $(D getMaterial) and used in $(D EditorSpatialGizmo.addHandles). Should not be overridden. 128 */ 129 void createHandleMaterial(in String name, in bool billboard = false) 130 { 131 checkClassBinding!(typeof(this))(); 132 ptrcall!(void)(GDNativeClassBinding.createHandleMaterial, _godot_object, name, billboard); 133 } 134 /** 135 Creates an icon material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with $(D getMaterial) and used in $(D EditorSpatialGizmo.addUnscaledBillboard). Should not be overridden. 136 */ 137 void createIconMaterial(in String name, Texture texture, in bool on_top = false, in Color color = Color(1,1,1,1)) 138 { 139 checkClassBinding!(typeof(this))(); 140 ptrcall!(void)(GDNativeClassBinding.createIconMaterial, _godot_object, name, texture, on_top, color); 141 } 142 /** 143 Creates an unshaded material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with $(D getMaterial) and used in $(D EditorSpatialGizmo.addMesh) and $(D EditorSpatialGizmo.addLines). Should not be overridden. 144 */ 145 void createMaterial(in String name, in Color color, in bool billboard = false, in bool on_top = false, in bool use_vertex_color = false) 146 { 147 checkClassBinding!(typeof(this))(); 148 ptrcall!(void)(GDNativeClassBinding.createMaterial, _godot_object, name, color, billboard, on_top, use_vertex_color); 149 } 150 /** 151 Override this method to provide gizmo's handle names. Called for this plugin's active gizmos. 152 */ 153 String getHandleName(EditorSpatialGizmo gizmo, in long index) 154 { 155 Array _GODOT_args = Array.make(); 156 _GODOT_args.append(gizmo); 157 _GODOT_args.append(index); 158 String _GODOT_method_name = String("get_handle_name"); 159 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 160 } 161 /** 162 Gets actual value of a handle from gizmo. Called for this plugin's active gizmos. 163 */ 164 Variant getHandleValue(EditorSpatialGizmo gizmo, in long index) 165 { 166 Array _GODOT_args = Array.make(); 167 _GODOT_args.append(gizmo); 168 _GODOT_args.append(index); 169 String _GODOT_method_name = String("get_handle_value"); 170 return this.callv(_GODOT_method_name, _GODOT_args); 171 } 172 /** 173 Gets material from the internal list of materials. If an $(D EditorSpatialGizmo) is provided, it will try to get the corresponding variant (selected and/or editable). 174 */ 175 Ref!SpatialMaterial getMaterial(in String name, EditorSpatialGizmo gizmo = EditorSpatialGizmo.init) 176 { 177 checkClassBinding!(typeof(this))(); 178 return ptrcall!(SpatialMaterial)(GDNativeClassBinding.getMaterial, _godot_object, name, gizmo); 179 } 180 /** 181 Override this method to provide the name that will appear in the gizmo visibility menu. 182 */ 183 String getName() 184 { 185 Array _GODOT_args = Array.make(); 186 String _GODOT_method_name = String("get_name"); 187 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 188 } 189 /** 190 Override this method to set the gizmo's priority. Higher values correspond to higher priority. If a gizmo with higher priority conflicts with another gizmo, only the gizmo with higher priority will be used. 191 All built-in editor gizmos return a priority of `-1`. If not overridden, this method will return `0`, which means custom gizmos will automatically override built-in gizmos. 192 */ 193 long getPriority() 194 { 195 Array _GODOT_args = Array.make(); 196 String _GODOT_method_name = String("get_priority"); 197 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long); 198 } 199 /** 200 Override this method to define which Spatial nodes have a gizmo from this plugin. Whenever a $(D Spatial) node is added to a scene this method is called, if it returns `true` the node gets a generic $(D EditorSpatialGizmo) assigned and is added to this plugin's list of active gizmos. 201 */ 202 bool hasGizmo(Spatial spatial) 203 { 204 Array _GODOT_args = Array.make(); 205 _GODOT_args.append(spatial); 206 String _GODOT_method_name = String("has_gizmo"); 207 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 208 } 209 /** 210 Gets whether a handle is highlighted or not. Called for this plugin's active gizmos. 211 */ 212 bool isHandleHighlighted(EditorSpatialGizmo gizmo, in long index) 213 { 214 Array _GODOT_args = Array.make(); 215 _GODOT_args.append(gizmo); 216 _GODOT_args.append(index); 217 String _GODOT_method_name = String("is_handle_highlighted"); 218 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 219 } 220 /** 221 Override this method to define whether a Spatial with this gizmo should be selectable even when the gizmo is hidden. 222 */ 223 bool isSelectableWhenHidden() 224 { 225 Array _GODOT_args = Array.make(); 226 String _GODOT_method_name = String("is_selectable_when_hidden"); 227 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 228 } 229 /** 230 Callback to redraw the provided gizmo. Called for this plugin's active gizmos. 231 */ 232 void redraw(EditorSpatialGizmo gizmo) 233 { 234 Array _GODOT_args = Array.make(); 235 _GODOT_args.append(gizmo); 236 String _GODOT_method_name = String("redraw"); 237 this.callv(_GODOT_method_name, _GODOT_args); 238 } 239 /** 240 Update the value of a handle after it has been updated. Called for this plugin's active gizmos. 241 */ 242 void setHandle(EditorSpatialGizmo gizmo, in long index, Camera camera, in Vector2 point) 243 { 244 Array _GODOT_args = Array.make(); 245 _GODOT_args.append(gizmo); 246 _GODOT_args.append(index); 247 _GODOT_args.append(camera); 248 _GODOT_args.append(point); 249 String _GODOT_method_name = String("set_handle"); 250 this.callv(_GODOT_method_name, _GODOT_args); 251 } 252 }