example.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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_fourty_two(const String &p_str) const;
  104. String test_string_resize(String p_original) const;
  105. int test_vector_ops() const;
  106. bool test_object_cast_to_node(Object *p_object) const;
  107. bool test_object_cast_to_control(Object *p_object) const;
  108. bool test_object_cast_to_example(Object *p_object) const;
  109. Vector2i test_variant_vector2i_conversion(const Variant &p_variant) const;
  110. int test_variant_int_conversion(const Variant &p_variant) const;
  111. float test_variant_float_conversion(const Variant &p_variant) const;
  112. void test_add_child(Node *p_node);
  113. void test_set_tileset(TileMap *p_tilemap, const Ref<TileSet> &p_tileset) const;
  114. Variant test_variant_call(Variant p_variant);
  115. Callable test_callable_mp();
  116. Callable test_callable_mp_ret();
  117. Callable test_callable_mp_retc() const;
  118. Callable test_callable_mp_static() const;
  119. Callable test_callable_mp_static_ret() const;
  120. Callable test_custom_callable() const;
  121. void unbound_method1(Object *p_object, String p_string, int p_int);
  122. String unbound_method2(Object *p_object, String p_string, int p_int);
  123. String unbound_method3(Object *p_object, String p_string, int p_int) const;
  124. static void unbound_static_method1(Example *p_object, String p_string, int p_int);
  125. static String unbound_static_method2(Object *p_object, String p_string, int p_int);
  126. BitField<Flags> test_bitfield(BitField<Flags> flags);
  127. Variant test_variant_iterator(const Variant &p_input);
  128. // RPC
  129. void test_rpc(int p_value);
  130. void test_send_rpc(int p_value);
  131. int return_last_rpc_arg();
  132. void callable_bind();
  133. // Property.
  134. void set_custom_position(const Vector2 &pos);
  135. Vector2 get_custom_position() const;
  136. Vector4 get_v4() const;
  137. bool test_post_initialize() const;
  138. // Static method.
  139. static int test_static(int p_a, int p_b);
  140. static void test_static2();
  141. // Virtual function override (no need to bind manually).
  142. virtual bool _has_point(const Vector2 &point) const override;
  143. virtual void _input(const Ref<InputEvent> &event) override;
  144. };
  145. VARIANT_ENUM_CAST(Example::Constants);
  146. VARIANT_BITFIELD_CAST(Example::Flags);
  147. enum EnumWithoutClass {
  148. OUTSIDE_OF_CLASS = 512
  149. };
  150. VARIANT_ENUM_CAST(EnumWithoutClass);
  151. class ExampleVirtual : public Object {
  152. GDCLASS(ExampleVirtual, Object);
  153. protected:
  154. static void _bind_methods() {}
  155. };
  156. class ExampleAbstractBase : public Object {
  157. GDCLASS(ExampleAbstractBase, Object);
  158. protected:
  159. static void _bind_methods() {}
  160. virtual int test_function() = 0;
  161. };
  162. class ExampleConcrete : public ExampleAbstractBase {
  163. GDCLASS(ExampleConcrete, ExampleAbstractBase);
  164. protected:
  165. static void _bind_methods() {}
  166. virtual int test_function() override { return 25; }
  167. };
  168. #endif // EXAMPLE_CLASS_H