ANTIPALSU Label template editor using flutter

polygon_painter.dart 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (c) 2021 Razeware LLC
  2. //
  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. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // Notwithstanding the foregoing, you may not use, copy, modify, merge, publish,
  14. // distribute, sublicense, create a derivative work, and/or sell copies of the
  15. // Software in any work that is designed, intended, or marketed for pedagogical
  16. // or instructional purposes related to programming, coding, application
  17. // development, or information technology. Permission for such use, copying,
  18. // modification, merger, publication, distribution, sublicensing, creation of
  19. // derivative works, or sale is expressly withheld.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. // THE SOFTWARE.
  28. import 'package:flutter/material.dart';
  29. class PolygonPainter extends CustomPainter {
  30. @override
  31. void paint(Canvas canvas, Size size) {
  32. final paint = Paint()
  33. ..strokeWidth = 5
  34. ..color = Colors.indigoAccent
  35. ..style = PaintingStyle.fill;
  36. final triangle = Path();
  37. triangle.moveTo(150, 0);
  38. triangle.relativeLineTo(100, 100);
  39. triangle.relativeLineTo(-150, 0);
  40. triangle.close();
  41. final square1 = Path();
  42. square1.moveTo(50, 150);
  43. square1.relativeLineTo(100, 0);
  44. square1.relativeLineTo(0, 100);
  45. square1.relativeLineTo(-100, 0);
  46. square1.close();
  47. const square2 = Rect.fromLTWH(200, 150, 100, 100);
  48. final hexagon = Path()
  49. // 1
  50. ..moveTo(175, 300)
  51. // 2
  52. ..relativeLineTo(75, 50)
  53. // 3
  54. ..relativeLineTo(0, 75)
  55. // 4
  56. ..relativeLineTo(-75, 50)
  57. // 5
  58. ..relativeLineTo(-75, -50)
  59. // 6
  60. ..relativeLineTo(0, -75)
  61. // 7
  62. ..close();
  63. final cross = Path()
  64. ..moveTo(150, 500)
  65. ..relativeLineTo(50, 0)
  66. ..relativeLineTo(0, 50)
  67. ..relativeLineTo(50, 0)
  68. ..relativeLineTo(0, 50)
  69. ..relativeLineTo(-50, 0)
  70. ..relativeLineTo(0, 50)
  71. ..relativeLineTo(-50, 0)
  72. ..relativeLineTo(0, -50)
  73. ..relativeLineTo(-50, 0)
  74. ..relativeLineTo(0, -50)
  75. ..relativeLineTo(50, 0)
  76. ..close();
  77. canvas.drawPath(triangle, paint);
  78. canvas.drawPath(square1, paint);
  79. canvas.drawRect(square2, paint);
  80. canvas.drawPath(cross, paint);
  81. canvas.drawPath(hexagon, paint);
  82. }
  83. @override
  84. bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
  85. }