rect2.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*************************************************************************/
  2. /* rect2.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "rect2.h"
  31. #include "core/variant.h"
  32. #include "core/math/math_2d.h"
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. void _rect2_api_anchor() {}
  37. void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size) {
  38. const Vector2 *position = (const Vector2 *)p_pos;
  39. const Vector2 *size = (const Vector2 *)p_size;
  40. Rect2 *dest = (Rect2 *)r_dest;
  41. *dest = Rect2(*position, *size);
  42. }
  43. void GDAPI godot_rect2_new(godot_rect2 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_width, const godot_real p_height) {
  44. Rect2 *dest = (Rect2 *)r_dest;
  45. *dest = Rect2(p_x, p_y, p_width, p_height);
  46. }
  47. godot_string GDAPI godot_rect2_as_string(const godot_rect2 *p_self) {
  48. godot_string ret;
  49. const Rect2 *self = (const Rect2 *)p_self;
  50. memnew_placement(&ret, String(*self));
  51. return ret;
  52. }
  53. godot_real GDAPI godot_rect2_get_area(const godot_rect2 *p_self) {
  54. const Rect2 *self = (const Rect2 *)p_self;
  55. return self->get_area();
  56. }
  57. godot_bool GDAPI godot_rect2_intersects(const godot_rect2 *p_self, const godot_rect2 *p_b) {
  58. const Rect2 *self = (const Rect2 *)p_self;
  59. const Rect2 *b = (const Rect2 *)p_b;
  60. return self->intersects(*b);
  61. }
  62. godot_bool GDAPI godot_rect2_encloses(const godot_rect2 *p_self, const godot_rect2 *p_b) {
  63. const Rect2 *self = (const Rect2 *)p_self;
  64. const Rect2 *b = (const Rect2 *)p_b;
  65. return self->encloses(*b);
  66. }
  67. godot_bool GDAPI godot_rect2_has_no_area(const godot_rect2 *p_self) {
  68. const Rect2 *self = (const Rect2 *)p_self;
  69. return self->has_no_area();
  70. }
  71. godot_rect2 GDAPI godot_rect2_clip(const godot_rect2 *p_self, const godot_rect2 *p_b) {
  72. godot_rect2 dest;
  73. const Rect2 *self = (const Rect2 *)p_self;
  74. const Rect2 *b = (const Rect2 *)p_b;
  75. *((Rect2 *)&dest) = self->clip(*b);
  76. return dest;
  77. }
  78. godot_rect2 GDAPI godot_rect2_merge(const godot_rect2 *p_self, const godot_rect2 *p_b) {
  79. godot_rect2 dest;
  80. const Rect2 *self = (const Rect2 *)p_self;
  81. const Rect2 *b = (const Rect2 *)p_b;
  82. *((Rect2 *)&dest) = self->merge(*b);
  83. return dest;
  84. }
  85. godot_bool GDAPI godot_rect2_has_point(const godot_rect2 *p_self, const godot_vector2 *p_point) {
  86. const Rect2 *self = (const Rect2 *)p_self;
  87. const Vector2 *point = (const Vector2 *)p_point;
  88. return self->has_point(*point);
  89. }
  90. godot_rect2 GDAPI godot_rect2_grow(const godot_rect2 *p_self, const godot_real p_by) {
  91. godot_rect2 dest;
  92. const Rect2 *self = (const Rect2 *)p_self;
  93. *((Rect2 *)&dest) = self->grow(p_by);
  94. return dest;
  95. }
  96. godot_rect2 GDAPI godot_rect2_expand(const godot_rect2 *p_self, const godot_vector2 *p_to) {
  97. godot_rect2 dest;
  98. const Rect2 *self = (const Rect2 *)p_self;
  99. const Vector2 *to = (const Vector2 *)p_to;
  100. *((Rect2 *)&dest) = self->expand(*to);
  101. return dest;
  102. }
  103. godot_bool GDAPI godot_rect2_operator_equal(const godot_rect2 *p_self, const godot_rect2 *p_b) {
  104. const Rect2 *self = (const Rect2 *)p_self;
  105. const Rect2 *b = (const Rect2 *)p_b;
  106. return *self == *b;
  107. }
  108. godot_vector2 GDAPI godot_rect2_get_position(const godot_rect2 *p_self) {
  109. godot_vector2 dest;
  110. Vector2 *d = (Vector2 *)&dest;
  111. const Rect2 *self = (const Rect2 *)p_self;
  112. *d = self->get_position();
  113. return dest;
  114. }
  115. godot_vector2 GDAPI godot_rect2_get_size(const godot_rect2 *p_self) {
  116. godot_vector2 dest;
  117. Vector2 *d = (Vector2 *)&dest;
  118. const Rect2 *self = (const Rect2 *)p_self;
  119. *d = self->get_size();
  120. return dest;
  121. }
  122. void GDAPI godot_rect2_set_position(godot_rect2 *p_self, const godot_vector2 *p_pos) {
  123. Rect2 *self = (Rect2 *)p_self;
  124. const Vector2 *position = (const Vector2 *)p_pos;
  125. self->set_position(*position);
  126. }
  127. void GDAPI godot_rect2_set_size(godot_rect2 *p_self, const godot_vector2 *p_size) {
  128. Rect2 *self = (Rect2 *)p_self;
  129. const Vector2 *size = (const Vector2 *)p_size;
  130. self->set_size(*size);
  131. }
  132. #ifdef __cplusplus
  133. }
  134. #endif