@fuwu-yuan/bgew
Version:
Baguette Game Engine Web is a french 2D Web game engine
95 lines (94 loc) • 2.88 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Checkbox = void 0;
const rectangle_1 = require("./rectangle");
class Checkbox extends rectangle_1.Rectangle {
constructor(x, y, width, height) {
super(x, y, width, height);
this._checked = false;
this._tickLineWidth = 5;
this._strokeColor = "rgba(0,0,0, 0.8)";
this._hoverStrokeColor = "rgba(0,0,0, 1.0)";
this._tickColor = "rgba(0,0,0, 1.0)";
this._hoverTickColor = "rgba(0,0,0, 1.0)";
this._clickTickColor = "rgba(0,0,0, 1.0)";
this._disabledTickColor = "rgba(0,0,0, 1.0)";
this._disabledFillColor = "rgba(150,150,150,1.0)";
this._disabledStrokeColor = "rgba(0,0,0,1.0)";
this._radius = { tl: 5, tr: 5, br: 5, bl: 5 };
this.onMouseEvent("click", () => {
this._checked = !this._checked;
});
}
draw(ctx) {
super.draw(ctx);
ctx.strokeStyle = this.tickColor;
if (this.clicked) {
ctx.strokeStyle = this.clickStrokeColor;
}
else if (this.hovered) {
ctx.strokeStyle = this.hoverTickColor;
}
if (this.disabled) {
ctx.strokeStyle = this.disabledTickColor;
}
//draw tick
if (this.checked) {
ctx.beginPath();
ctx.moveTo(this.x + this.width / 5, this.y + this.height / 2);
ctx.lineTo(this.x + this.width / 2, this.y + this.height - this.height / 5);
ctx.lineTo(this.x + this.width - this.width / 5, this.y + this.height / 5);
ctx.lineWidth = this.tickLineWidth;
ctx.stroke();
}
}
get checked() {
return this._checked;
}
set checked(value) {
this._checked = value;
}
get tickColor() {
return this._tickColor;
}
set tickColor(value) {
this._tickColor = value;
}
get hoverTickColor() {
return this._hoverTickColor;
}
set hoverTickColor(value) {
this._hoverTickColor = value;
}
get clickTickColor() {
return this._clickTickColor;
}
set clickTickColor(value) {
this._clickTickColor = value;
}
get disabledTickColor() {
return this._disabledTickColor;
}
set disabledTickColor(value) {
this._disabledTickColor = value;
}
get disabledFillColor() {
return this._disabledFillColor;
}
set disabledFillColor(value) {
this._disabledFillColor = value;
}
get disabledStrokeColor() {
return this._disabledStrokeColor;
}
set disabledStrokeColor(value) {
this._disabledStrokeColor = value;
}
get tickLineWidth() {
return this._tickLineWidth;
}
set tickLineWidth(value) {
this._tickLineWidth = value;
}
}
exports.Checkbox = Checkbox;