shapes.inc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**--------------------------------------------------------------------------**\
  2. =================================
  3. y_bitmap - Generate bitmaps.
  4. =================================
  5. Description:
  6. Code to generate images on the server in the bitmap format. This is by far
  7. the simplest format to write to as it is just a huge array of colours (at
  8. least 24-bit bitmaps are, and we only do them).
  9. This file contains functions to draw various shapes.
  10. Legal:
  11. Version: MPL 1.1
  12. The contents of this file are subject to the Mozilla Public License Version
  13. 1.1 (the "License"); you may not use this file except in compliance with
  14. the License. You may obtain a copy of the License at
  15. http://www.mozilla.org/MPL/
  16. Software distributed under the License is distributed on an "AS IS" basis,
  17. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  18. for the specific language governing rights and limitations under the
  19. License.
  20. The Original Code is the YSI utils include.
  21. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  22. Portions created by the Initial Developer are Copyright (C) 2011
  23. the Initial Developer. All Rights Reserved.
  24. Contributors:
  25. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  26. Thanks:
  27. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  28. ZeeX - Very productive conversations.
  29. koolk - IsPlayerinAreaEx code.
  30. TheAlpha - Danish translation.
  31. breadfish - German translation.
  32. Fireburn - Dutch translation.
  33. yom - French translation.
  34. 50p - Polish translation.
  35. Zamaroht - Spanish translation.
  36. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  37. for me to strive to better.
  38. Pixels^ - Running XScripters where the idea was born.
  39. Matite - Pestering me to release it and using it.
  40. Very special thanks to:
  41. Thiadmer - PAWN, whose limits continue to amaze me!
  42. Kye/Kalcor - SA:MP.
  43. SA:MP Team past, present and future - SA:MP.
  44. Version:
  45. 0.1
  46. Changelog:
  47. 29/03/13:
  48. First version.
  49. Functions:
  50. Stock:
  51. -
  52. Inline:
  53. -
  54. Variables:
  55. Global:
  56. -
  57. \**--------------------------------------------------------------------------**/
  58. /**--------------------------------------------------------------------------**\
  59. <summary>Bitmap_DrawRectangle</summary>
  60. <param name="Bitmap:ctx">The bitmap to modify.</param>
  61. <param name="const minX">The left of the array.</param>
  62. <param name="const minY">The top of the array.</param>
  63. <param name="const maxX">The right of the array.</param>
  64. <param name="const maxY">The bottom of the array.</param>
  65. <param name="fillColour">The colour of the inside of the rectangle.</param>
  66. <param name="lineColour = 0">The colour of the rectangle border.</param>
  67. <param name="linePattern[] = \"SOLID\"">How to draw the inside.</param>
  68. <param name="fillPattern[] = \"SOLID\"">How to draw the border.</param>
  69. <returns>
  70. -
  71. </returns>
  72. <remarks>
  73. This function draws a rectangle between two given co-ordinates. It can also
  74. draw a border around the rectangle OUTSIDE the specified area of the
  75. rectangle. If you want the border within the area specified you need to use
  76. a smaller area.
  77. </remarks>
  78. \**--------------------------------------------------------------------------**/
  79. // End the input above because all this code is being written with no testing
  80. // or compiling until I am home again. So in the interests of leaving the code
  81. // stable, this is all ignored.
  82. stock Bitmap_DrawRectangle(Bitmap:ctx, const minX, const minY, const maxX, const maxY, fillColour, lineColour = 0, linePattern[] = "SOLID", fillPattern[] = "SOLID")
  83. {
  84. if (fillColour)
  85. {
  86. _Bitmap_DoRectangle(ctx, minX, minY, maxX, maxY, fillColour, fillPattern);
  87. }
  88. if (lineColour)
  89. {
  90. // Do the borders.
  91. if (strcmp(linePattern, "DOTTED", true, 6))
  92. {
  93. new
  94. border = _Bitmap_Param(linePattern, "border");
  95. if (border == cellmin) border = 8;
  96. //printf("border = %d", border);
  97. //printf("1");
  98. _Bitmap_DoRectangle(ctx, minX - border, minY - border, maxX + border, minY, lineColour, linePattern),
  99. //printf("1");
  100. _Bitmap_DoRectangle(ctx, minX - border, minY, minX, maxY, lineColour, linePattern),
  101. //printf("1");
  102. _Bitmap_DoRectangle(ctx, minX - border, maxY, maxX + border, maxY + border, lineColour, linePattern),
  103. //printf("1");
  104. _Bitmap_DoRectangle(ctx, maxX, minY, maxX + border, maxY, lineColour, linePattern);
  105. //printf("1");
  106. }
  107. else
  108. {
  109. new
  110. border = _Bitmap_Param(linePattern, "border"),
  111. pat[128] = "STRIPED";
  112. strcat(pat, linePattern[6]);
  113. if (border == cellmin) border = 8;
  114. _Bitmap_DoRectangle(ctx, minX - border, minY - border, maxX + border, minY, lineColour, pat),
  115. _Bitmap_DoRectangle(ctx, minX - border, maxY, maxX + border, maxY + border, lineColour, pat),
  116. strcat(pat, ",HORIZONTAL"),
  117. _Bitmap_DoRectangle(ctx, minX - border, minY, minX, maxY, lineColour, pat),
  118. _Bitmap_DoRectangle(ctx, maxX, minY, maxX + border, maxY, lineColour, pat);
  119. }
  120. }
  121. }
  122. static stock _Bitmap_DoRectangle(Bitmap:ctx, minX, minY, maxX, maxY, colour, pattern[])
  123. {
  124. new
  125. width = Bitmap_Width(ctx);
  126. minY = max(0, minY),
  127. maxY = min(maxY, Bitmap_Height(ctx)),
  128. minX = max(0, minX),
  129. maxX = min(maxX, width),
  130. _Bitmap_MakePattern(pattern, minX, minY, 0, 0);
  131. new
  132. ya,
  133. read,
  134. a = (colour & 0xFF) + 1,
  135. na,
  136. suba,
  137. r = ((colour & 0xFF000000) >>> 16),
  138. g = ((colour & 0x00FF0000) >>> 16),
  139. b = ((colour & 0x0000FF00) >>> 8),
  140. orig;
  141. for (new y = minY; y != maxY; ++y)
  142. {
  143. read = Bitmap_IndexInt(ctx, minX, width, y),
  144. ya = y % YSI_gBitmapAlphaY;
  145. for (new x = minX; x != maxX; ++x)
  146. {
  147. suba = YSI_gBitmapAlpha[ya]{x % YSI_gBitmapAlphaX} * a;
  148. if (suba == 0xFF00)
  149. {
  150. YSI_gMallocMemory[read] = colour;
  151. }
  152. else if (suba >= 256)
  153. {
  154. // This is where we compensate for the odd shifts.
  155. na = 0xFF00 - suba,
  156. // Want this pixel in the final image.
  157. orig = YSI_gMallocMemory[read],
  158. YSI_gMallocMemory[read] = 0xFF |
  159. ((((orig & 0xFF000000) >>> 16) * na + r * suba) & 0xFF000000) |
  160. ((((orig & 0x00FF0000) >>> 16) * na + g * suba) & 0x00FF0000) |
  161. (((((orig & 0x0000FF00) >>> 8) * na + b * suba) & 0x00FF0000) >>> 8) ;
  162. }
  163. ++read;
  164. }
  165. }
  166. }
  167. static stock _Bitmap_RectangleRecopy(n, BitArray:pattern<PATTERN_MASK_X>)
  168. {
  169. for (new y = 1; y != n; ++y)
  170. {
  171. YSI_gBitmapAlpha[y] = pattern;
  172. }
  173. }