Skip to content

Commit 5133d9d

Browse files
authored
Merge pull request #150 from GreenAsJade/last_move_opacity
Allow clients to set last_move_opacity, via config or call
2 parents 7bcdb73 + 9cd85ac commit 5133d9d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/GobanCanvas.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface GobanCanvasConfig extends GobanConfig {
4949
board_div?: HTMLElement;
5050
title_div?: HTMLElement;
5151
move_tree_container?: HTMLElement;
52+
last_move_opacity?: number;
5253
}
5354

5455
interface ViewPortInterface {
@@ -104,6 +105,7 @@ export class GobanCanvas extends GobanCore implements GobanCanvasInterface {
104105
private shadow_ctx?: CanvasRenderingContext2D;
105106
private handleShiftKey: (ev: KeyboardEvent) => void;
106107

108+
private last_move_opacity: number = 1;
107109
public move_tree_container?: HTMLElement;
108110
private move_tree_inner_container?: HTMLDivElement;
109111
private move_tree_canvas?: HTMLCanvasElement;
@@ -162,6 +164,7 @@ export class GobanCanvas extends GobanCore implements GobanCanvasInterface {
162164
this.board = createDeviceScaledCanvas(10, 10);
163165
this.board.setAttribute("id", "board-canvas");
164166
this.board.className = "StoneLayer";
167+
this.last_move_opacity = config["last_move_opacity"] ?? 1;
165168
const ctx = this.board.getContext("2d", { willReadFrequently: true });
166169
if (ctx) {
167170
this.ctx = ctx;
@@ -217,6 +220,10 @@ export class GobanCanvas extends GobanCore implements GobanCanvasInterface {
217220
this.ready_to_draw = true;
218221
this.redraw(true);
219222
}
223+
public setLastMoveOpacity(opacity: number): void {
224+
this.last_move_opacity = opacity;
225+
}
226+
220227
public enablePen(): void {
221228
this.attachPenCanvas();
222229
}
@@ -2082,7 +2089,7 @@ export class GobanCanvas extends GobanCore implements GobanCanvasInterface {
20822089
ctx.save();
20832090
ctx.beginPath();
20842091
ctx.lineWidth = this.square_size * 0.075;
2085-
//ctx.globalAlpha = 0.6;
2092+
ctx.globalAlpha = this.last_move_opacity;
20862093
const r = Math.max(1, this.metrics.mid * 0.35) * 0.8;
20872094
ctx.moveTo(cx - r, cy);
20882095
ctx.lineTo(cx + r, cy);
@@ -2113,18 +2120,20 @@ export class GobanCanvas extends GobanCore implements GobanCanvasInterface {
21132120
draw_last_move = false;
21142121
ctx.restore();
21152122
} else {
2123+
ctx.save();
21162124
ctx.beginPath();
21172125
ctx.strokeStyle = color;
21182126
ctx.lineWidth = this.square_size * 0.075;
2127+
ctx.globalAlpha = this.last_move_opacity;
21192128
let r = this.square_size * this.last_move_radius;
21202129
if (this.submit_move) {
2121-
//ctx.globalAlpha = 0.6;
21222130
r = this.square_size * 0.3;
21232131
}
21242132

21252133
r = Math.max(0.1, r);
21262134
ctx.arc(cx, cy, r, 0, 2 * Math.PI, false);
21272135
ctx.stroke();
2136+
ctx.restore();
21282137
}
21292138
}
21302139
}

0 commit comments

Comments
 (0)