"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SGraphClockItem = void 0; const lib_1 = require("@persagy-web/draw/lib"); const SGraphItem_1 = require("../SGraphItem"); class SGraphClockItem extends SGraphItem_1.SGraphItem { constructor(parent, width, height) { super(parent); if (width instanceof lib_1.SSize) { this.size = new lib_1.SSize(width.width, width.height); } else { this.size = new lib_1.SSize(width, height); } } get width() { return this.size.width; } set width(v) { this.size.width = v; } get height() { return this.size.height; } set height(v) { this.size.height = v; } get radius() { return Math.min(this.width, this.height) / 2.0; } boundingRect() { return new lib_1.SRect(0, 0, this.width, this.height); } onDraw(painter) { painter.translate(this.width / 2, this.height / 2); let t = new Date(); this.drawScale(painter); this.drawHour(painter, t.getHours(), t.getMinutes(), t.getSeconds()); this.drawMinute(painter, t.getMinutes(), t.getSeconds()); this.drawSecond(painter, t.getSeconds() + t.getMilliseconds() / 1000.0); } drawScale(painter) { let scaleLength = Math.max(this.radius / 10.0, 2.0); let scaleLength1 = scaleLength * 1.2; let strokeWidth = Math.max(this.radius / 100.0, 2.0); let strokeWidth1 = strokeWidth * 2.0; painter.save(); painter.pen.color = lib_1.SColor.Blue; for (let i = 1; i <= 12; i++) { painter.pen.lineWidth = strokeWidth1; painter.drawLine(0, -this.radius, 0, -this.radius + scaleLength1); if (this.radius >= 40) { painter.rotate((6 * Math.PI) / 180); for (let j = 1; j <= 4; j++) { painter.pen.lineWidth = strokeWidth; painter.drawLine(0, -this.radius, 0, -this.radius + scaleLength); painter.rotate((6 * Math.PI) / 180); } } else { painter.rotate((30 * Math.PI) / 180); } } painter.restore(); } drawHour(painter, hour, minute, second) { painter.save(); painter.pen.lineCapStyle = lib_1.SLineCapStyle.Round; painter.pen.lineWidth = Math.max(this.radius / 30.0, 4.0); painter.rotate(((hour * 30.0 + (minute * 30.0) / 60 + (second * 30.0) / 3600) * Math.PI) / 180); painter.drawLine(0, this.radius / 10.0, 0, -this.radius / 2.0); painter.restore(); } drawMinute(painter, minute, second) { painter.save(); painter.pen.lineCapStyle = lib_1.SLineCapStyle.Round; painter.pen.lineWidth = Math.max(this.radius / 40.0, 4.0); painter.rotate(((minute * 6 + (second * 6) / 60.0) * Math.PI) / 180); painter.drawLine(0, this.radius / 10.0, 0, (-this.radius * 2.0) / 3.0); painter.restore(); } drawSecond(painter, second) { painter.save(); painter.pen.lineCapStyle = lib_1.SLineCapStyle.Round; painter.pen.lineWidth = Math.max(this.radius / 100.0, 3.0); painter.pen.color = lib_1.SColor.Red; painter.rotate((second * 6 * Math.PI) / 180); painter.drawLine(0, this.radius / 5.0, 0, -this.radius + this.radius / 10.0); painter.restore(); } } exports.SGraphClockItem = SGraphClockItem;