PolyScreenShape.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyScreenMesh.h"
  22. namespace Polycode {
  23. class Polygon;
  24. /**
  25. * 2D primitive. Screen shape can create 2d shapes (Currently only rectangles and circles).
  26. */
  27. class _PolyExport ScreenShape : public ScreenMesh {
  28. public:
  29. /**
  30. * Create a new shape of specified type and size/options.
  31. * @param shapeType Type of shape to create. Currently the only options are ScreenShape::SHAPE_RECT and ScreenShape::SHAPE_CIRCLE. Pass ScreenShape::SHAPE_CUSTOM if you want to create a custom shape (@see addShapePoint())
  32. * @param option1 Width option.
  33. * @param option2 Height option.
  34. * @param option3 Number of vertices for the the circle (defaults to 360). Unused for rectangle.
  35. * @param option4 Reserved.
  36. */
  37. ScreenShape(int shapeType, Number option1=0, Number option2=0, Number option3=0, Number option4=0);
  38. virtual ~ScreenShape();
  39. void Render();
  40. /**
  41. * Sets the color of the shape stroke if it's enabled.
  42. * @param r Red value 0-1.
  43. * @param g Green value 0-1
  44. * @param b Blue value 0-1
  45. * @param a Alpha value 0-1
  46. * @see strokeEnabled
  47. */
  48. void setStrokeColor(Number r, Number g, Number b, Number a);
  49. /**
  50. * Sets the width of the shape stroke if it's enabled.
  51. * @param width New stroke width.
  52. * @see strokeEnabled
  53. */
  54. void setStrokeWidth(Number width);
  55. /**
  56. * Colors the shape with a gradient. Radial for circles, linear for rectangles.
  57. * @param width New stroke width.
  58. * @param r1 Red value of the first gradient color 0-1.
  59. * @param g1 Green value of the first gradient color 0-1
  60. * @param b1 Blue value of the first gradient color 0-1
  61. * @param a1 Alpha value of the first gradient color 0-1
  62. * @param r2 Red value of the second gradient color 0-1.
  63. * @param g2 Green value of the second gradient color 0-1
  64. * @param b2 Blue value of the second gradient color 0-1
  65. * @param a2 Alpha value of the second gradient color 0-1
  66. * @see strokeEnabled
  67. */
  68. void setGradient(Number r1, Number g1, Number b1, Number a1, Number r2, Number g2, Number b2, Number a2);
  69. /**
  70. * Removes the gradient from the shape.
  71. */
  72. void clearGradient();
  73. void setShapeSize(Number newWidth, Number newHeight);
  74. /**
  75. * Adds a point to the mesh.
  76. * @param x Horizontal position of the point.
  77. * @param y Vertical position of the point.
  78. */
  79. void addShapePoint(Number x, Number y);
  80. static const int SHAPE_RECT = 1;
  81. static const int SHAPE_CIRCLE = 2;
  82. static const int SHAPE_CUSTOM = 4;
  83. /**
  84. * If set to true, the shape will be drawn over with a stroke.
  85. */
  86. bool strokeEnabled;
  87. /**
  88. * Color of the shape stroke.
  89. */
  90. Color strokeColor;
  91. /**
  92. * If this is set to true, the line will be anti-aliased if the support is available in the renderer.
  93. */
  94. bool lineSmooth;
  95. protected:
  96. Number option1;
  97. Number option2;
  98. Number option3;
  99. Number option4;
  100. Polygon *customShapePoly;
  101. Number strokeWidth;
  102. int shapeType;
  103. };
  104. }