glue.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. Copyright (c) 2014-2022 Bruce A Henderson
  3. This software is provided 'as-is', without any express or implied
  4. warranty. In no event will the authors be held liable for any damages
  5. arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it
  8. freely, subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not
  10. claim that you wrote the original software. If you use this software
  11. in a product, an acknowledgment in the product documentation would be
  12. appreciated but is not required.
  13. 2. Altered source versions must be plainly marked as such, and must not be
  14. misrepresented as being the original software.
  15. 3. This notice may not be removed or altered from any source
  16. distribution.
  17. */
  18. #include "SDL_render.h"
  19. int bmx_SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh) {
  20. if (sx < 0 || sy < 0 || sw < 0 || sh < 0) {
  21. if (dx < 0 || dy < 0 || dw < 0 || dh < 0) {
  22. return SDL_RenderCopy(renderer, texture, 0, 0);
  23. } else {
  24. SDL_Rect dr = { dx, dy, dw, dh };
  25. return SDL_RenderCopy(renderer, texture, 0, &dr);
  26. }
  27. } else {
  28. SDL_Rect sr = { sx, sy, sw, sh };
  29. if (dx < 0 || dy < 0 || dw < 0 || dh < 0) {
  30. return SDL_RenderCopy(renderer, texture, &sr, 0);
  31. } else {
  32. SDL_Rect dr = { dx, dy, dw, dh };
  33. return SDL_RenderCopy(renderer, texture, &sr, &dr);
  34. }
  35. }
  36. }
  37. int bmx_SDL_RenderDrawRect(SDL_Renderer * renderer, int x, int y, int w, int h) {
  38. if (x < 0 || y < 0 || w < 0 || h < 0) {
  39. return SDL_RenderDrawRect(renderer, 0);
  40. } else {
  41. SDL_Rect r = { x, y, w, h };
  42. return SDL_RenderDrawRect(renderer, &r);
  43. }
  44. }
  45. int bmx_SDL_RenderFillRect(SDL_Renderer * renderer, int x, int y, int w, int h) {
  46. if (x < 0 || y < 0 || w < 0 || h < 0) {
  47. return SDL_RenderFillRect(renderer, 0);
  48. } else {
  49. SDL_Rect r = { x, y, w, h };
  50. return SDL_RenderFillRect(renderer, &r);
  51. }
  52. }
  53. void bmx_SDL_RenderGetClipRect(SDL_Renderer * renderer, int * x, int * y, int * w, int * h) {
  54. SDL_Rect r;
  55. SDL_RenderGetClipRect(renderer, &r);
  56. *x = r.x;
  57. *y = r.y;
  58. *w = r.w;
  59. *h = r.h;
  60. }
  61. void bmx_SDL_RenderGetViewport(SDL_Renderer * renderer, int * x, int * y, int * w, int * h) {
  62. SDL_Rect r;
  63. SDL_RenderGetViewport(renderer, &r);
  64. *x = r.x;
  65. *y = r.y;
  66. *w = r.w;
  67. *h = r.h;
  68. }
  69. int bmx_SDL_RenderReadPixels(SDL_Renderer * renderer, Uint32 format, void * pixels, int pitch, int x, int y, int w, int h) {
  70. if (x < 0 || y < 0 || w < 0 || h < 0) {
  71. return SDL_RenderReadPixels(renderer, 0, format, pixels, pitch);
  72. } else {
  73. SDL_Rect r = { x, y, w, h };
  74. return SDL_RenderReadPixels(renderer, &r, format, pixels, pitch);
  75. }
  76. }
  77. int bmx_SDL_RenderSetClipRect(SDL_Renderer * renderer, int x, int y, int w, int h) {
  78. if (x < 0 || y < 0 || w < 0 || h < 0) {
  79. return SDL_RenderSetClipRect(renderer, 0);
  80. } else {
  81. SDL_Rect r = { x, y, w, h };
  82. return SDL_RenderSetClipRect(renderer, &r);
  83. }
  84. }
  85. int bmx_SDL_RenderSetViewport(SDL_Renderer * renderer, int x, int y, int w, int h) {
  86. if (x < 0 || y < 0 || w < 0 || h < 0) {
  87. return SDL_RenderSetViewport(renderer, 0);
  88. } else {
  89. SDL_Rect r = { x, y, w, h };
  90. return SDL_RenderSetViewport(renderer, &r);
  91. }
  92. }
  93. int bmx_SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, double angle, int cx, int cy, int flipMode) {
  94. if (sx < 0 || sy < 0 || sw < 0 || sh < 0) {
  95. if (dx < 0 || dy < 0 || dw < 0 || dh < 0) {
  96. if (cx < 0 || cy < 0) {
  97. return SDL_RenderCopyEx(renderer, texture, 0, 0, angle, 0, flipMode);
  98. } else {
  99. SDL_Point p = { cx, cy };
  100. return SDL_RenderCopyEx(renderer, texture, 0, 0, angle, &p, flipMode);
  101. }
  102. } else {
  103. SDL_Rect dr = { dx, dy, dw, dh };
  104. if (cx < 0 || cy < 0) {
  105. return SDL_RenderCopyEx(renderer, texture, 0, &dr, angle, 0, flipMode);
  106. } else {
  107. SDL_Point p = { cx, cy };
  108. return SDL_RenderCopyEx(renderer, texture, 0, &dr, angle, &p, flipMode);
  109. }
  110. }
  111. } else {
  112. SDL_Rect sr = { sx, sy, sw, sh };
  113. if (dx < 0 || dy < 0 || dw < 0 || dh < 0) {
  114. if (cx < 0 || cy < 0) {
  115. return SDL_RenderCopyEx(renderer, texture, &sr, 0, angle, 0, flipMode);
  116. } else {
  117. SDL_Point p = { cx, cy };
  118. return SDL_RenderCopyEx(renderer, texture, &sr, 0, angle, &p, flipMode);
  119. }
  120. } else {
  121. SDL_Rect dr = { dx, dy, dw, dh };
  122. if (cx < 0 || cy < 0) {
  123. return SDL_RenderCopyEx(renderer, texture, &sr, &dr, angle, 0, flipMode);
  124. } else {
  125. SDL_Point p = { cx, cy };
  126. return SDL_RenderCopyEx(renderer, texture, &sr, &dr, angle, &p, flipMode);
  127. }
  128. }
  129. }
  130. }
  131. // --------------------------------------------------------
  132. int bmx_SDL_LockTexture(SDL_Texture * texture, void ** pixels, int * pitch, int x, int y, int w, int h) {
  133. if (x < 0 || y < 0 || w < 0 || h < 0) {
  134. return SDL_LockTexture(texture, 0, pixels, pitch);
  135. } else {
  136. SDL_Rect r = { x, y, w, h };
  137. return SDL_LockTexture(texture, &r, pixels, pitch);
  138. }
  139. }
  140. int bmx_SDL_UpdateTexture(SDL_Texture * texture, void * pixels, int pitch, int x, int y, int w, int h) {
  141. if (x < 0 || y < 0 || w < 0 || h < 0) {
  142. return SDL_UpdateTexture(texture, 0, pixels, pitch);
  143. } else {
  144. SDL_Rect r = { x, y, w, h };
  145. return SDL_UpdateTexture(texture, &r, pixels, pitch);
  146. }
  147. }
  148. int bmx_SDL_UpdateYUVTexture(SDL_Texture * texture, Uint8 * yPlane, int yPitch, Uint8 * uPlane, int uPitch, Uint8 * vPlane, int vPitch, int x, int y, int w, int h) {
  149. if (x < 0 || y < 0 || w < 0 || h < 0) {
  150. return SDL_UpdateYUVTexture(texture, 0, yPlane, yPitch, uPlane, uPitch, vPlane, vPitch);
  151. } else {
  152. SDL_Rect r = { x, y, w, h };
  153. return SDL_UpdateYUVTexture(texture, &r, yPlane, yPitch, uPlane, uPitch, vPlane, vPitch);
  154. }
  155. }
  156. void * bmx_SDL_bptr_to_SDLVertexPtr(void * list) {
  157. return list;
  158. }