example.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. using namespace godot;
  24. class ExampleRef : public RefCounted {
  25. GDCLASS(ExampleRef, RefCounted);
  26. private:
  27. static int instance_count;
  28. static int last_id;
  29. int id;
  30. bool post_initialized = false;
  31. protected:
  32. static void _bind_methods();
  33. void _notification(int p_what);
  34. public:
  35. ExampleRef();
  36. ~ExampleRef();
  37. void set_id(int p_id);
  38. int get_id() const;
  39. bool was_post_initialized() const { return post_initialized; }
  40. };
  41. class ExampleMin : public Control {
  42. GDCLASS(ExampleMin, Control);
  43. protected:
  44. static void _bind_methods(){};
  45. };
  46. class Example : public Control {
  47. GDCLASS(Example, Control);
  48. protected:
  49. static void _bind_methods();
  50. void _notification(int p_what);
  51. bool _set(const StringName &p_name, const Variant &p_value);
  52. bool _get(const StringName &p_name, Variant &r_ret) const;
  53. void _get_property_list(List<PropertyInfo> *p_list) const;
  54. bool _property_can_revert(const StringName &p_name) const;
  55. bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
  56. void _validate_property(PropertyInfo &p_property) const;
  57. String _to_string() const;
  58. private:
  59. Vector2 custom_position;
  60. Vector3 property_from_list;
  61. Vector2 dprop[3];
  62. int last_rpc_arg = 0;
  63. public:
  64. // Constants.
  65. enum Constants {
  66. FIRST,
  67. ANSWER_TO_EVERYTHING = 42,
  68. };
  69. enum Flags {
  70. FLAG_ONE = 1,
  71. FLAG_TWO = 2,
  72. };
  73. enum {
  74. CONSTANT_WITHOUT_ENUM = 314,
  75. };
  76. Example();
  77. ~Example();
  78. // Functions.
  79. void simple_func();
  80. void simple_const_func() const;
  81. int custom_ref_func(Ref<ExampleRef> p_ref);
  82. int custom_const_ref_func(const Ref<ExampleRef> &p_ref);
  83. String image_ref_func(Ref<Image> p_image);
  84. String image_const_ref_func(const Ref<Image> &p_image);
  85. String return_something(const String &base);
  86. Viewport *return_something_const() const;
  87. Ref<ExampleRef> return_ref() const;
  88. Ref<ExampleRef> return_empty_ref() const;
  89. ExampleRef *return_extended_ref() const;
  90. Ref<ExampleRef> extended_ref_checks(Ref<ExampleRef> p_ref) const;
  91. Variant varargs_func(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error);
  92. int varargs_func_nv(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error);
  93. void varargs_func_void(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error);
  94. void emit_custom_signal(const String &name, int value);
  95. int def_args(int p_a = 100, int p_b = 200);
  96. Array test_array() const;
  97. int test_tarray_arg(const TypedArray<int64_t> &p_array);
  98. TypedArray<Vector2> test_tarray() const;
  99. Dictionary test_dictionary() const;
  100. Example *test_node_argument(Example *p_node) const;
  101. String test_string_ops() const;
  102. String test_str_utility() const;
  103. bool test_string_is_forty_two(const String &p_str) const;
  104. String test_string_resize(String p_original) const;
  105. TypedArray<PackedInt32Array> test_typed_array_of_packed() const;
  106. int test_vector_ops() const;
  107. int test_vector_init_list() const;
  108. bool test_object_cast_to_node(Object *p_object) const;
  109. bool test_object_cast_to_control(Object *p_object) const;
  110. bool test_object_cast_to_example(Object *p_object) const;
  111. Vector2i test_variant_vector2i_conversion(const Variant &p_variant) const;
  112. int test_variant_int_conversion(const Variant &p_variant) const;
  113. float test_variant_float_conversion(const Variant &p_variant) const;
  114. void test_add_child(Node *p_node);
  115. void test_set_tileset(TileMap *p_tilemap, const Ref<TileSet> &p_tileset) const;
  116. Variant test_variant_call(Variant p_variant);
  117. Callable test_callable_mp();
  118. Callable test_callable_mp_ret();
  119. Callable test_callable_mp_retc() const;
  120. Callable test_callable_mp_static() const;
  121. Callable test_callable_mp_static_ret() const;
  122. Callable test_custom_callable() const;
  123. void unbound_method1(Object *p_object, String p_string, int p_int);
  124. String unbound_method2(Object *p_object, String p_string, int p_int);
  125. String unbound_method3(Object *p_object, String p_string, int p_int) const;
  126. static void unbound_static_method1(Example *p_object, String p_string, int p_int);
  127. static String unbound_static_method2(Object *p_object, String p_string, int p_int);
  128. BitField<Flags> test_bitfield(BitField<Flags> flags);
  129. Variant test_variant_iterator(const Variant &p_input);
  130. // RPC
  131. void test_rpc(int p_value);
  132. void test_send_rpc(int p_value);
  133. int return_last_rpc_arg();
  134. void callable_bind();
  135. // Property.
  136. void set_custom_position(const Vector2 &pos);
  137. Vector2 get_custom_position() const;
  138. Vector4 get_v4() const;
  139. bool test_post_initialize() const;
  140. // Static method.
  141. static int test_static(int p_a, int p_b);
  142. static void test_static2();
  143. // Virtual function override (no need to bind manually).
  144. virtual bool _has_point(const Vector2 &point) const override;
  145. virtual void _input(const Ref<InputEvent> &event) override;
  146. String test_use_engine_singleton() const;
  147. static String test_library_path();
  148. };
  149. VARIANT_ENUM_CAST(Example::Constants);
  150. VARIANT_BITFIELD_CAST(Example::Flags);
  151. enum EnumWithoutClass {
  152. OUTSIDE_OF_CLASS = 512
  153. };
  154. VARIANT_ENUM_CAST(EnumWithoutClass);
  155. class ExampleVirtual : public Object {
  156. GDCLASS(ExampleVirtual, Object);
  157. protected:
  158. static void _bind_methods() {}
  159. };
  160. class ExampleAbstractBase : public Object {
  161. GDCLASS(ExampleAbstractBase, Object);
  162. protected:
  163. static void _bind_methods() {}
  164. virtual int test_function() = 0;
  165. };
  166. class ExampleConcrete : public ExampleAbstractBase {
  167. GDCLASS(ExampleConcrete, ExampleAbstractBase);
  168. protected:
  169. static void _bind_methods() {}
  170. virtual int test_function() override { return 25; }
  171. };
  172. class ExampleBase : public Node {
  173. GDCLASS(ExampleBase, Node);
  174. protected:
  175. int value1 = 0;
  176. int value2 = 0;
  177. static void _bind_methods();
  178. void _notification(int p_what);
  179. public:
  180. int get_value1() { return value1; }
  181. int get_value2() { return value2; }
  182. };
  183. class ExampleChild : public ExampleBase {
  184. GDCLASS(ExampleChild, ExampleBase);
  185. protected:
  186. static void _bind_methods() {}
  187. void _notification(int p_what);
  188. };
  189. #endif // EXAMPLE_CLASS_H