example.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /* godot-cpp integration testing project.
  2. *
  3. * This is free and unencumbered software released into the public domain.
  4. */
  5. #ifndef EXAMPLE_CLASS_H
  6. #define EXAMPLE_CLASS_H
  7. // We don't need windows.h in this example plugin but many others do, and it can
  8. // lead to annoying situations due to the ton of macros it defines.
  9. // So we include it and make sure CI warns us if we use something that conflicts
  10. // with a Windows define.
  11. #ifdef WIN32
  12. #include <windows.h>
  13. #endif
  14. #include <godot_cpp/classes/control.hpp>
  15. #include <godot_cpp/classes/global_constants.hpp>
  16. #include <godot_cpp/classes/image.hpp>
  17. #include <godot_cpp/classes/input_event_key.hpp>
  18. #include <godot_cpp/classes/tile_map.hpp>
  19. #include <godot_cpp/classes/tile_set.hpp>
  20. #include <godot_cpp/classes/viewport.hpp>
  21. #include <godot_cpp/variant/variant.hpp>
  22. #include <godot_cpp/core/binder_common.hpp>
  23. #include <godot_cpp/core/gdvirtual.gen.inc>
  24. using namespace godot;
  25. class ExampleRef : public RefCounted {
  26. GDCLASS(ExampleRef, RefCounted);
  27. private:
  28. static int instance_count;
  29. static int last_id;
  30. int id;
  31. bool post_initialized = false;
  32. protected:
  33. static void _bind_methods();
  34. void _notification(int p_what);
  35. public:
  36. ExampleRef();
  37. ~ExampleRef();
  38. void set_id(int p_id);
  39. int get_id() const;
  40. bool was_post_initialized() const { return post_initialized; }
  41. };
  42. class ExampleMin : public Control {
  43. GDCLASS(ExampleMin, Control);
  44. protected:
  45. static void _bind_methods(){};
  46. };
  47. class Example : public Control {
  48. GDCLASS(Example, Control);
  49. protected:
  50. static void _bind_methods();
  51. void _notification(int p_what);
  52. bool _set(const StringName &p_name, const Variant &p_value);
  53. bool _get(const StringName &p_name, Variant &r_ret) const;
  54. void _get_property_list(List<PropertyInfo> *p_list) const;
  55. bool _property_can_revert(const StringName &p_name) const;
  56. bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
  57. void _validate_property(PropertyInfo &p_property) const;
  58. String _to_string() const;
  59. private:
  60. Vector2 custom_position;
  61. Vector3 property_from_list;
  62. Vector2 dprop[3];
  63. int last_rpc_arg = 0;
  64. public:
  65. // Constants.
  66. enum Constants {
  67. FIRST,
  68. ANSWER_TO_EVERYTHING = 42,
  69. };
  70. enum Flags {
  71. FLAG_ONE = 1,
  72. FLAG_TWO = 2,
  73. };
  74. enum {
  75. CONSTANT_WITHOUT_ENUM = 314,
  76. };
  77. Example();
  78. ~Example();
  79. // Functions.
  80. void simple_func();
  81. void simple_const_func() const;
  82. int custom_ref_func(Ref<ExampleRef> p_ref);
  83. int custom_const_ref_func(const Ref<ExampleRef> &p_ref);
  84. String image_ref_func(Ref<Image> p_image);
  85. String image_const_ref_func(const Ref<Image> &p_image);
  86. String return_something(const String &base);
  87. Viewport *return_something_const() const;
  88. Ref<ExampleRef> return_ref() const;
  89. Ref<ExampleRef> return_empty_ref() const;
  90. ExampleRef *return_extended_ref() const;
  91. Ref<ExampleRef> extended_ref_checks(Ref<ExampleRef> p_ref) const;
  92. Variant varargs_func(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error);
  93. int varargs_func_nv(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error);
  94. void varargs_func_void(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error);
  95. void emit_custom_signal(const String &name, int value);
  96. int def_args(int p_a = 100, int p_b = 200);
  97. Array test_array() const;
  98. int test_tarray_arg(const TypedArray<int64_t> &p_array);
  99. TypedArray<Vector2> test_tarray() const;
  100. Dictionary test_dictionary() const;
  101. Example *test_node_argument(Example *p_node) const;
  102. String test_string_ops() const;
  103. String test_str_utility() const;
  104. bool test_string_is_fourty_two(const String &p_str) const;
  105. String test_string_resize(String p_original) const;
  106. int test_vector_ops() const;
  107. bool test_object_cast_to_node(Object *p_object) const;
  108. bool test_object_cast_to_control(Object *p_object) const;
  109. bool test_object_cast_to_example(Object *p_object) const;
  110. Vector2i test_variant_vector2i_conversion(const Variant &p_variant) const;
  111. int test_variant_int_conversion(const Variant &p_variant) const;
  112. float test_variant_float_conversion(const Variant &p_variant) const;
  113. void test_add_child(Node *p_node);
  114. void test_set_tileset(TileMap *p_tilemap, const Ref<TileSet> &p_tileset) const;
  115. Variant test_variant_call(Variant p_variant);
  116. Callable test_callable_mp();
  117. Callable test_callable_mp_ret();
  118. Callable test_callable_mp_retc() const;
  119. Callable test_callable_mp_static() const;
  120. Callable test_callable_mp_static_ret() const;
  121. Callable test_custom_callable() const;
  122. void unbound_method1(Object *p_object, String p_string, int p_int);
  123. String unbound_method2(Object *p_object, String p_string, int p_int);
  124. String unbound_method3(Object *p_object, String p_string, int p_int) const;
  125. static void unbound_static_method1(Example *p_object, String p_string, int p_int);
  126. static String unbound_static_method2(Object *p_object, String p_string, int p_int);
  127. BitField<Flags> test_bitfield(BitField<Flags> flags);
  128. Variant test_variant_iterator(const Variant &p_input);
  129. // RPC
  130. void test_rpc(int p_value);
  131. void test_send_rpc(int p_value);
  132. int return_last_rpc_arg();
  133. void callable_bind();
  134. // Property.
  135. void set_custom_position(const Vector2 &pos);
  136. Vector2 get_custom_position() const;
  137. Vector4 get_v4() const;
  138. bool test_post_initialize() const;
  139. // Static method.
  140. static int test_static(int p_a, int p_b);
  141. static void test_static2();
  142. // Virtual function override (no need to bind manually).
  143. virtual bool _has_point(const Vector2 &point) const override;
  144. virtual void _input(const Ref<InputEvent> &event) override;
  145. GDVIRTUAL2R(String, _do_something_virtual, String, int);
  146. String test_virtual_implemented_in_script(const String &p_name, int p_value);
  147. };
  148. VARIANT_ENUM_CAST(Example::Constants);
  149. VARIANT_BITFIELD_CAST(Example::Flags);
  150. enum EnumWithoutClass {
  151. OUTSIDE_OF_CLASS = 512
  152. };
  153. VARIANT_ENUM_CAST(EnumWithoutClass);
  154. class ExampleVirtual : public Object {
  155. GDCLASS(ExampleVirtual, Object);
  156. protected:
  157. static void _bind_methods() {}
  158. };
  159. class ExampleAbstractBase : public Object {
  160. GDCLASS(ExampleAbstractBase, Object);
  161. protected:
  162. static void _bind_methods() {}
  163. virtual int test_function() = 0;
  164. };
  165. class ExampleConcrete : public ExampleAbstractBase {
  166. GDCLASS(ExampleConcrete, ExampleAbstractBase);
  167. protected:
  168. static void _bind_methods() {}
  169. virtual int test_function() override { return 25; }
  170. };
  171. class ExampleRuntime : public Node {
  172. GDCLASS(ExampleRuntime, Node);
  173. int prop_value = 12;
  174. protected:
  175. static void _bind_methods();
  176. public:
  177. void set_prop_value(int p_prop_value);
  178. int get_prop_value() const;
  179. ExampleRuntime();
  180. ~ExampleRuntime();
  181. };
  182. #endif // EXAMPLE_CLASS_H