ZKPainter.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * ZKPainter.h
  3. *
  4. * Created on: Feb 20, 2019
  5. * Author: guoxs
  6. */
  7. #ifndef _CONTROL_ZKPAINTER_H_
  8. #define _CONTROL_ZKPAINTER_H_
  9. #include "ZKBase.h"
  10. class ZKPainterPrivate;
  11. /**
  12. * @brief 画布控件
  13. */
  14. class ZKPainter : public ZKBase {
  15. ZK_DECLARE_PRIVATE(ZKPainter)
  16. public:
  17. ZKPainter(ZKBase *pParent);
  18. virtual ~ZKPainter();
  19. /**
  20. * @brief 设置线宽
  21. * @param width 线宽
  22. */
  23. void setLineWidth(uint32_t width);
  24. /**
  25. * @brief 设置颜色值
  26. * @param color 颜色值为0x RGB
  27. */
  28. void setSourceColor(uint32_t color);
  29. /**
  30. * @brief 画三角形
  31. * @param x0 第一个顶点X坐标
  32. * @param y0 第一个顶点Y坐标
  33. * @param x1 第二个顶点X坐标
  34. * @param y1 第二个顶点Y坐标
  35. * @param x2 第三个顶点X坐标
  36. * @param y2 第三个顶点Y坐标
  37. */
  38. void drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2);
  39. /**
  40. * @brief 画矩形
  41. * @param left 左上角X坐标
  42. * @param top 左上角Y坐标
  43. * @param width 矩形宽度
  44. * @param height 矩形高度
  45. * @param radius 圆角半径,默认值为:0,为不带圆角矩形
  46. */
  47. void drawRect(int left, int top, int width, int height, int radius = 0);
  48. /**
  49. * @brief 画圆弧
  50. * @param centerX 中心点X坐标
  51. * @param centerY 中心点Y坐标
  52. * @param radiusX X轴方向半径
  53. * @param radiusY Y轴方向半径,默认值为:0,表示X与Y方向半径相等,为圆形,否则为椭圆形
  54. * @param startAngle 起始角度,垂直方向向上为0度方向,顺时针方向为正,逆时针方向为负; 默认值为:0度
  55. * @param sweepAngle 偏移角度,顺时针方向为正,逆时针方向为负; 默认值为:360度
  56. */
  57. void drawArc(int centerX, int centerY, int radiusX, int radiusY = 0, int startAngle = 0, int sweepAngle = 360);
  58. /**
  59. * @brief 填充三角形
  60. * @param x0 第一个顶点X坐标
  61. * @param y0 第一个顶点Y坐标
  62. * @param x1 第二个顶点X坐标
  63. * @param y1 第二个顶点Y坐标
  64. * @param x2 第三个顶点X坐标
  65. * @param y2 第三个顶点Y坐标
  66. */
  67. void fillTriangle(int x0, int y0, int x1, int y1, int x2, int y2);
  68. /**
  69. * @brief 填充矩形
  70. * @param left 左上角X坐标
  71. * @param top 左上角Y坐标
  72. * @param width 矩形宽度
  73. * @param height 矩形高度
  74. * @param radius 圆角半径,默认值为:0,为不带圆角矩形
  75. */
  76. void fillRect(int left, int top, int width, int height, int radius = 0);
  77. /**
  78. * @brief 填充圆弧
  79. * @param centerX 中心点X坐标
  80. * @param centerY 中心点Y坐标
  81. * @param radiusX X轴方向半径
  82. * @param radiusY Y轴方向半径,默认值为:0,表示X与Y方向半径相等,为圆形,否则为椭圆形
  83. * @param startAngle 起始角度,垂直方向向上为0度方向,顺时针方向为正,逆时针方向为负; 默认值为:0度
  84. * @param sweepAngle 偏移角度,顺时针方向为正,逆时针方向为负; 默认值为:360度
  85. */
  86. void fillArc(int centerX, int centerY, int radiusX, int radiusY = 0, int startAngle = 0, int sweepAngle = 360);
  87. /**
  88. * @brief 画直线
  89. * @param pPoints 坐标数组
  90. * @param count 数组长度
  91. */
  92. void drawLines(const SZKPoint *pPoints, int count);
  93. /**
  94. * @brief 画曲线
  95. * @param pPoints 坐标数组
  96. * @param count 数组长度
  97. */
  98. void drawCurve(const SZKPoint *pPoints, int count);
  99. /**
  100. * @brief 擦除
  101. */
  102. void erase(int x, int y, int w, int h);
  103. protected:
  104. ZKPainter(ZKBase *pParent, ZKBasePrivate *pBP);
  105. virtual void onBeforeCreateWindow(const Json::Value &json);
  106. virtual const char* getClassName() const { return ZK_PAINTER; }
  107. virtual void onDraw(ZKCanvas *pCanvas);
  108. private:
  109. void parsePainterAttributeFromJson(const Json::Value &json);
  110. };
  111. #endif /* _CONTROL_ZKPAINTER_H_ */