SGraphClockItem.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SGraphClockItem = void 0;
  4. const lib_1 = require("@persagy-web/draw/lib");
  5. const SGraphItem_1 = require("../SGraphItem");
  6. class SGraphClockItem extends SGraphItem_1.SGraphItem {
  7. constructor(parent, width, height) {
  8. super(parent);
  9. if (width instanceof lib_1.SSize) {
  10. this.size = new lib_1.SSize(width.width, width.height);
  11. }
  12. else {
  13. this.size = new lib_1.SSize(width, height);
  14. }
  15. }
  16. get width() {
  17. return this.size.width;
  18. }
  19. set width(v) {
  20. this.size.width = v;
  21. }
  22. get height() {
  23. return this.size.height;
  24. }
  25. set height(v) {
  26. this.size.height = v;
  27. }
  28. get radius() {
  29. return Math.min(this.width, this.height) / 2.0;
  30. }
  31. boundingRect() {
  32. return new lib_1.SRect(0, 0, this.width, this.height);
  33. }
  34. onDraw(painter) {
  35. painter.translate(this.width / 2, this.height / 2);
  36. let t = new Date();
  37. this.drawScale(painter);
  38. this.drawHour(painter, t.getHours(), t.getMinutes(), t.getSeconds());
  39. this.drawMinute(painter, t.getMinutes(), t.getSeconds());
  40. this.drawSecond(painter, t.getSeconds() + t.getMilliseconds() / 1000.0);
  41. }
  42. drawScale(painter) {
  43. let scaleLength = Math.max(this.radius / 10.0, 2.0);
  44. let scaleLength1 = scaleLength * 1.2;
  45. let strokeWidth = Math.max(this.radius / 100.0, 2.0);
  46. let strokeWidth1 = strokeWidth * 2.0;
  47. painter.save();
  48. painter.pen.color = lib_1.SColor.Blue;
  49. for (let i = 1; i <= 12; i++) {
  50. painter.pen.lineWidth = strokeWidth1;
  51. painter.drawLine(0, -this.radius, 0, -this.radius + scaleLength1);
  52. if (this.radius >= 40) {
  53. painter.rotate((6 * Math.PI) / 180);
  54. for (let j = 1; j <= 4; j++) {
  55. painter.pen.lineWidth = strokeWidth;
  56. painter.drawLine(0, -this.radius, 0, -this.radius + scaleLength);
  57. painter.rotate((6 * Math.PI) / 180);
  58. }
  59. }
  60. else {
  61. painter.rotate((30 * Math.PI) / 180);
  62. }
  63. }
  64. painter.restore();
  65. }
  66. drawHour(painter, hour, minute, second) {
  67. painter.save();
  68. painter.pen.lineCapStyle = lib_1.SLineCapStyle.Round;
  69. painter.pen.lineWidth = Math.max(this.radius / 30.0, 4.0);
  70. painter.rotate(((hour * 30.0 + (minute * 30.0) / 60 + (second * 30.0) / 3600) *
  71. Math.PI) /
  72. 180);
  73. painter.drawLine(0, this.radius / 10.0, 0, -this.radius / 2.0);
  74. painter.restore();
  75. }
  76. drawMinute(painter, minute, second) {
  77. painter.save();
  78. painter.pen.lineCapStyle = lib_1.SLineCapStyle.Round;
  79. painter.pen.lineWidth = Math.max(this.radius / 40.0, 4.0);
  80. painter.rotate(((minute * 6 + (second * 6) / 60.0) * Math.PI) / 180);
  81. painter.drawLine(0, this.radius / 10.0, 0, (-this.radius * 2.0) / 3.0);
  82. painter.restore();
  83. }
  84. drawSecond(painter, second) {
  85. painter.save();
  86. painter.pen.lineCapStyle = lib_1.SLineCapStyle.Round;
  87. painter.pen.lineWidth = Math.max(this.radius / 100.0, 3.0);
  88. painter.pen.color = lib_1.SColor.Red;
  89. painter.rotate((second * 6 * Math.PI) / 180);
  90. painter.drawLine(0, this.radius / 5.0, 0, -this.radius + this.radius / 10.0);
  91. painter.restore();
  92. }
  93. }
  94. exports.SGraphClockItem = SGraphClockItem;