Reduce code duplication

Signed-off-by: offtkp <parisoplop@gmail.com>
Change-Id: I51e79fca321e9759aa75549e98c598e7bc150824
private/offtkp/lineWidth
offtkp 2024-02-13 11:46:51 +02:00
parent 7e5c7630f9
commit 86f22dc1f5
3 changed files with 33 additions and 56 deletions

View File

@ -98,34 +98,7 @@ export class ColumnGroup extends GroupBase {
const endX = this.getEndPosition(group.endPos);
if (this.isGroupHeaderVisible(startX, group.startPos)) {
// draw head
this.context.beginPath();
this.context.fillStyle = this.backgroundColor;
this.context.fillRect(this.transformRectX(startX, this._groupHeadSize), startY, this._groupHeadSize, this._groupHeadSize);
this.context.strokeStyle = 'black';
this.context.lineWidth = 1.0;
this.context.strokeRect(this.transformRectX(startX + 0.5, this._groupHeadSize), startY + 0.5, this._groupHeadSize, this._groupHeadSize);
if (!group.hidden) {
// draw '-'
this.context.beginPath();
this.context.moveTo(startX + 0.5 + this._groupHeadSize * 0.25, startY + 0.5 + this._groupHeadSize / 2);
this.context.lineTo(startX + 0.5 + this._groupHeadSize * 0.75, startY + 0.5 + this._groupHeadSize / 2);
this.context.stroke();
}
else {
// draw '+'
this.context.beginPath();
this.context.moveTo(startX + 0.5 + this._groupHeadSize * 0.25, startY + 0.5 + this._groupHeadSize / 2);
this.context.lineTo(startX + 0.5 + this._groupHeadSize * 0.75, startY + 0.5 + this._groupHeadSize / 2);
this.context.stroke();
this.context.moveTo(startX + 0.5 + this._groupHeadSize / 2, startY + this._groupHeadSize * 0.25);
this.context.lineTo(startX + 0.5 + this._groupHeadSize / 2, startY + this._groupHeadSize * 0.75 + 1.0);
this.context.stroke();
}
this.drawGroupBoxes(startX, startY, group.hidden);
}
if (!group.hidden && endX > this._cornerHeaderWidth + this._groupHeadSize && endX > startX) {

View File

@ -276,6 +276,37 @@ export abstract class GroupBase extends CanvasSectionObject {
return this.isCalcRTL() ? this.size[0] - xcoord : xcoord;
}
drawGroupBoxes(startX: number, startY: number, hidden: boolean): void {
// draw head
this.context.beginPath();
this.context.fillStyle = this.backgroundColor;
this.context.fillRect(this.transformRectX(startX, this._groupHeadSize), startY, this._groupHeadSize, this._groupHeadSize);
this.context.strokeStyle = 'black';
this.context.lineWidth = 1.0;
this.context.strokeRect(this.transformRectX(startX + 0.5, this._groupHeadSize), startY + 0.5, this._groupHeadSize, this._groupHeadSize);
if (!hidden) {
// draw '-'
this.context.beginPath();
this.context.moveTo(startX + 0.5 + this._groupHeadSize * 0.25, startY + 0.5 + this._groupHeadSize / 2);
this.context.lineTo(startX + 0.5 + this._groupHeadSize * 0.75, startY + 0.5 + this._groupHeadSize / 2);
this.context.stroke();
}
else {
// draw '+'
this.context.beginPath();
this.context.moveTo(startX + 0.5 + this._groupHeadSize * 0.25, startY + 0.5 + this._groupHeadSize / 2);
this.context.lineTo(startX + 0.5 + this._groupHeadSize * 0.75, startY + 0.5 + this._groupHeadSize / 2);
this.context.stroke();
this.context.moveTo(startX + 0.5 + this._groupHeadSize / 2, startY + this._groupHeadSize * 0.25);
this.context.lineTo(startX + 0.5 + this._groupHeadSize / 2, startY + this._groupHeadSize * 0.75 + 1.0);
this.context.stroke();
}
}
/**
* Checks if the given point is within the bounds of the rectangle defined by
* startX, startY, endX, endY. If mirrorX is true then point is horizontally

View File

@ -98,34 +98,7 @@ export class RowGroup extends GroupBase {
const endY = this.getEndPosition(group.endPos);
if (this.isGroupHeaderVisible(startY, group.startPos)) {
// draw head
this.context.beginPath();
this.context.fillStyle = this.backgroundColor;
this.context.fillRect(this.transformRectX(startX, this._groupHeadSize), startY, this._groupHeadSize, this._groupHeadSize);
this.context.strokeStyle = 'black';
this.context.lineWidth = 1.0;
this.context.strokeRect(this.transformRectX(startX + 0.5, this._groupHeadSize), startY + 0.5, this._groupHeadSize, this._groupHeadSize);
if (!group.hidden) {
// draw '-'
this.context.beginPath();
this.context.moveTo(startX + 0.5 + this._groupHeadSize * 0.25, startY + 0.5 + this._groupHeadSize / 2);
this.context.lineTo(startX + 0.5 + this._groupHeadSize * 0.75, startY + 0.5 + this._groupHeadSize / 2);
this.context.stroke();
}
else {
// draw '+'
this.context.beginPath();
this.context.moveTo(startX + 0.5 + this._groupHeadSize * 0.25, startY + 0.5 + this._groupHeadSize / 2);
this.context.lineTo(startX + 0.5 + this._groupHeadSize * 0.75, startY + 0.5 + this._groupHeadSize / 2);
this.context.stroke();
this.context.moveTo(startX + 0.5 + this._groupHeadSize / 2, startY + this._groupHeadSize * 0.25);
this.context.lineTo(startX + 0.5 + this._groupHeadSize / 2, startY + this._groupHeadSize * 0.75 + 1.0);
this.context.stroke();
}
this.drawGroupBoxes(startX, startY, group.hidden);
}
if (!group.hidden && endY > this._cornerHeaderHeight + this._groupHeadSize && endY > startY) {