/Slipe/Core/Source/SlipeClient/Dx/Dx.cs

https://github.com/mta-slipe/Slipe-Core · C# · 215 lines · 178 code · 37 blank · 0 comment · 0 complexity · c53fe7c95910c8ac012ccbbd2ebf3c70 MD5 · raw file

  1. using Slipe.MtaDefinitions;
  2. using Slipe.Shared.Utilities;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Numerics;
  6. using System.Text;
  7. namespace Slipe.Client.Dx
  8. {
  9. public static class Dx
  10. {
  11. #region Circle
  12. public static bool DrawCircle(Vector2 position, float radius, Color color, Color centerColor, float startAngle = 0, float stopAngle = 360, int segments = 32, int ratio = 1, bool postGui = false)
  13. {
  14. return MtaClient.DxDrawCircle(position.X, position.Y, radius, startAngle, stopAngle, color.Hex, centerColor.Hex, segments, ratio, postGui);
  15. }
  16. public static bool DrawCircle(Vector2 position, float radius, Color color)
  17. {
  18. return DrawCircle(position, radius, color, color);
  19. }
  20. public static bool DrawCircle(Vector2 position, float radius)
  21. {
  22. return DrawCircle(position, radius, Color.White);
  23. }
  24. #endregion
  25. #region Image
  26. public static bool DrawImage(string filePath, Vector2 position, Vector2 dimensions, Color color, Vector2 rotationCenterOffset, float rotation = 0, bool postGui = false)
  27. {
  28. return MtaClient.DxDrawImage(position.X, position.Y, dimensions.X, dimensions.Y, filePath, rotation, rotationCenterOffset.X, rotationCenterOffset.Y, color.Hex, postGui);
  29. }
  30. public static bool DrawImage(string filePath, Vector2 position, Vector2 dimensions, Color color)
  31. {
  32. return DrawImage(filePath, position, dimensions, color, Vector2.Zero);
  33. }
  34. public static bool DrawImage(string filePath, Vector2 position, Vector2 dimensions)
  35. {
  36. return DrawImage(filePath, position, dimensions, Color.White);
  37. }
  38. public static bool DrawImage(Material material, Vector2 position, Vector2 dimensions, Color color, Vector2 rotationCenterOffset, float rotation = 0, bool postGui = false)
  39. {
  40. return MtaClient.DxDrawImage(position.X, position.Y, dimensions.X, dimensions.Y, material?.MaterialElement, rotation, rotationCenterOffset.X, rotationCenterOffset.Y, color.Hex, postGui);
  41. }
  42. public static bool DrawImage(Material material, Vector2 position, Vector2 dimensions, Color color)
  43. {
  44. return DrawImage(material, position, dimensions, color, Vector2.Zero);
  45. }
  46. public static bool DrawImage(Material material, Vector2 position, Vector2 dimensions)
  47. {
  48. return DrawImage(material, position, dimensions, Color.White);
  49. }
  50. #endregion
  51. #region ImageSection
  52. public static bool DrawImageSection(string filePath, Vector2 position, Vector2 dimensions, Vector2 topLeft, Vector2 size, Color color, Vector2 rotationCenterOffset, float rotation = 0, bool postGui = false)
  53. {
  54. return MtaClient.DxDrawImageSection(position.X, position.Y, dimensions.X, dimensions.Y, topLeft.X, topLeft.Y, size.X, size.Y, filePath, rotation, rotationCenterOffset.X, rotationCenterOffset.Y, color.Hex, postGui);
  55. }
  56. public static bool DrawImageSection(string filePath, Vector2 position, Vector2 dimensions, Vector2 topLeft, Vector2 size, Color color)
  57. {
  58. return DrawImageSection(filePath, position, dimensions, topLeft, size, color, Vector2.Zero);
  59. }
  60. public static bool DrawImageSection(string filePath, Vector2 position, Vector2 dimensions, Vector2 topLeft, Vector2 size)
  61. {
  62. return DrawImageSection(filePath, position, dimensions, topLeft, size, Color.White);
  63. }
  64. public static bool DrawImageSection(Material material, Vector2 position, Vector2 dimensions, Vector2 topLeft, Vector2 size, Color color, Vector2 rotationCenterOffset, float rotation = 0, bool postGui = false)
  65. {
  66. return MtaClient.DxDrawImageSection(position.X, position.Y, dimensions.X, dimensions.Y, topLeft.X, topLeft.Y, size.X, size.Y, material?.MaterialElement, rotation, rotationCenterOffset.X, rotationCenterOffset.Y, color.Hex, postGui);
  67. }
  68. public static bool DrawImageSection(Material material, Vector2 position, Vector2 dimensions, Vector2 topLeft, Vector2 size, Color color)
  69. {
  70. return DrawImageSection(material, position, dimensions, topLeft, size, color, Vector2.Zero);
  71. }
  72. public static bool DrawImageSection(Material material, Vector2 position, Vector2 dimensions, Vector2 topLeft, Vector2 size)
  73. {
  74. return DrawImageSection(material, position, dimensions, topLeft, size, Color.White);
  75. }
  76. #endregion
  77. #region Line
  78. public static bool DrawLine(Vector2 startPosition, Vector2 endPosition, Color color, float width = 1, bool postGui = false)
  79. {
  80. return MtaClient.DxDrawLine((int) startPosition.X, (int)startPosition.Y, (int)endPosition.X, (int)endPosition.Y, color.Hex, width, postGui);
  81. }
  82. #endregion
  83. #region 3D Line
  84. public static bool DrawLine3D(Vector3 startPosition, Vector3 endPosition, Color color, float width = 1, bool postGui = false)
  85. {
  86. return MtaClient.DxDrawLine3D(startPosition.X, startPosition.Y, startPosition.Z, endPosition.X, endPosition.Y, endPosition.Z, color.Hex, width, postGui);
  87. }
  88. #endregion
  89. #region Material 3D Line
  90. public static bool DrawMaterialLine3D(Material material, Vector3 startPosition, Vector3 endPosition, Color color, float width = 1, bool postGui = false)
  91. {
  92. return MtaClient.DxDrawMaterialLine3D(startPosition.X, startPosition.Y, startPosition.Z, endPosition.X, endPosition.Y, endPosition.Z, material?.MaterialElement, color.Hex, (int)width, postGui);
  93. }
  94. public static bool DrawMaterialLine3D(Material material, Vector3 startPosition, Vector3 endPosition, Vector3 faceToward, Color color, float width = 1, bool postGui = false)
  95. {
  96. return MtaClient.DxDrawMaterialLine3D(startPosition.X, startPosition.Y, startPosition.Z, endPosition.X, endPosition.Y, endPosition.Z, material?.MaterialElement, color.Hex, (int)width, postGui, faceToward.X, faceToward.Y, faceToward.Z);
  97. }
  98. #endregion
  99. #region Material Primitive
  100. public static bool DrawMaterialPrimitive(PrimitiveType primitiveType, Material material, List<Vertice> vertices, bool postGui = false)
  101. {
  102. return DrawMaterialPrimitiveWithMaterial(primitiveType, material?.MaterialElement, vertices, postGui);
  103. }
  104. public static bool DrawMaterialPrimitive(PrimitiveType primitiveType, string path, List<Vertice> vertices, bool postGui = false)
  105. {
  106. return DrawMaterialPrimitiveWithMaterial(primitiveType, path, vertices, postGui);
  107. }
  108. private static bool DrawMaterialPrimitiveWithMaterial(PrimitiveType primitiveType, dynamic pathOrMaterial, List<Vertice> vertices, bool postGui = false)
  109. {
  110. List<Vector2> vectors = new List<Vector2>();
  111. List<int> colors = new List<int>();
  112. List<Vector2> topLefts = new List<Vector2>();
  113. foreach (Vertice vertice in vertices)
  114. {
  115. vectors.Add(vertice.Position);
  116. colors.Add(vertice.Color.Hex);
  117. topLefts.Add(vertice.TopLeft);
  118. }
  119. return MtaClient.DxDrawMaterialPrimitive(primitiveType.ToString().ToLower(), pathOrMaterial, postGui, vertices.Count, vectors, colors, topLefts);
  120. }
  121. #endregion
  122. #region Primitive
  123. public static bool DrawPrimitive(PrimitiveType primitiveType, List<Vertice> vertices, bool postGui = false)
  124. {
  125. List<Vector2> vectors = new List<Vector2>();
  126. List<int> colors = new List<int>();
  127. foreach (Vertice vertice in vertices)
  128. {
  129. vectors.Add(vertice.Position);
  130. colors.Add(vertice.Color.Hex);
  131. }
  132. return MtaClient.DxDrawPrimitive(primitiveType.ToString().ToLower(), postGui, vertices.Count, vectors, colors);
  133. }
  134. #endregion
  135. #region Material Section 3D Line
  136. public static bool DrawMaterialSectionLine3D(Material material, Vector3 startPosition, Vector3 endPosition, Vector2 topLeft, Vector2 size, Color color, float width = 1, bool postGui = false)
  137. {
  138. return MtaClient.DxDrawMaterialSectionLine3D(startPosition.X, startPosition.Y, startPosition.Z, endPosition.X, endPosition.Y, endPosition.Z, topLeft.X, topLeft.Y, size.X, size.Y, material?.MaterialElement, color.Hex, (int)width, postGui);
  139. }
  140. public static bool DrawMaterialSectionLine3D(Material material, Vector3 startPosition, Vector3 endPosition, Vector3 faceToward, Vector2 topLeft, Vector2 size, Color color, float width = 1, bool postGui = false)
  141. {
  142. return MtaClient.DxDrawMaterialSectionLine3D(startPosition.X, startPosition.Y, startPosition.Z, endPosition.X, endPosition.Y, endPosition.Z, topLeft.X, topLeft.Y, size.X, size.Y, material?.MaterialElement, color.Hex, (int)width, postGui, faceToward.X, faceToward.Y, faceToward.Z);
  143. }
  144. #endregion
  145. #region Rectangle
  146. public static bool DrawRectangle(Vector2 position, Vector2 dimensions, Color color, bool postGui = false, bool subPixelPositioning = false)
  147. {
  148. return MtaClient.DxDrawRectangle(position.X, position.Y, dimensions.X, dimensions.Y, color.Hex, postGui, subPixelPositioning);
  149. }
  150. #endregion
  151. #region Text
  152. public static bool DrawText(string text, Vector2 position, Vector2 bottomRight, Color color, Vector2 scale, Font font, HorizontalAlign horizontalAlign, VerticalAlign verticalAlign, float fRotation, Vector2 fRotationCenter, bool clip = false, bool wordBreak = false, bool postGUI = false, bool colorCoded = false, bool subPixelPositioning = false)
  153. {
  154. return MtaClient.DxDrawText(text, position.X, position.Y, bottomRight.X, bottomRight.Y, color.Hex, scale.X, scale.Y, font.MTAFont, horizontalAlign.ToString().ToLower(), verticalAlign.ToString().ToLower(), clip, wordBreak, postGUI, colorCoded, subPixelPositioning, fRotation, fRotationCenter.X, fRotationCenter.Y);
  155. }
  156. public static bool DrawText(string text, Vector2 position, Vector2 bottomRight, Color color, Vector2 scale, Font font, HorizontalAlign horizontalAlign = HorizontalAlign.Left, VerticalAlign verticalAlign = VerticalAlign.Top, float fRotation = 0.0f)
  157. {
  158. return DrawText(text, position, bottomRight, color, scale, font, horizontalAlign, verticalAlign, fRotation, Vector2.Zero);
  159. }
  160. public static bool DrawText(string text, Vector2 position, Vector2 bottomRight, Color color, Vector2 scale, StandardFont font, HorizontalAlign horizontalAlign, VerticalAlign verticalAlign, float fRotation, Vector2 fRotationCenter, bool clip = false, bool wordBreak = false, bool postGUI = false, bool colorCoded = false, bool subPixelPositioning = false)
  161. {
  162. return MtaClient.DxDrawText(text, position.X, position.Y, bottomRight.X, bottomRight.Y, color.Hex, scale.X, scale.Y, font.ToString().ToLower(), horizontalAlign.ToString().ToLower(), verticalAlign.ToString().ToLower(), clip, wordBreak, postGUI, colorCoded, subPixelPositioning, fRotation, fRotationCenter.X, fRotationCenter.Y);
  163. }
  164. public static bool DrawText(string text, Vector2 position, Vector2 bottomRight, Color color, Vector2 scale, StandardFont font, HorizontalAlign horizontalAlign = HorizontalAlign.Left, VerticalAlign verticalAlign = VerticalAlign.Top, float fRotation = 0.0f)
  165. {
  166. return DrawText(text, position, bottomRight, color, scale, font, horizontalAlign, verticalAlign, fRotation, Vector2.Zero);
  167. }
  168. public static bool DrawText(string text, Vector2 position, Vector2 bottomRight, Color color)
  169. {
  170. return DrawText(text, position, bottomRight, color, Vector2.One, StandardFont.Default);
  171. }
  172. public static bool DrawText(string text, Vector2 position)
  173. {
  174. return DrawText(text, position, Vector2.Zero, Color.White);
  175. }
  176. #endregion
  177. }
  178. }