Skip to content

Commit

Permalink
Merge pull request #177 from GreenAsJade/stone_font_scale
Browse files Browse the repository at this point in the history
Support a scale parameter for the font size for stone markings.
  • Loading branch information
anoek authored Sep 17, 2024
2 parents a16dc89 + f608093 commit 072d6ce
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 53 deletions.
27 changes: 27 additions & 0 deletions examples/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,26 @@ function GobanTestPage(): JSX.Element {
/>
</div>

<div className="setting">
<span>Stone font scale:</span>
<input
type="range"
value={base_config.stone_font_scale as number}
min="0.1"
max="2"
step="0.1"
onChange={(ev) => {
let ss = parseFloat(ev.target.value);
if (!ss) {
ss = 1;
}
base_config.stone_font_scale = ss;
forceUpdate();
fiddler.emit("setStoneFontScale", ss);
}}
/>
</div>

<div className="setting">
<span>Top labels:</span>
<input
Expand Down Expand Up @@ -356,6 +376,13 @@ function ReactGoban<GobanClass extends Goban>(
console.log("SSS time: ", end - start);
});

fiddler.on("setStoneFontScale", (ss) => {
const start = Date.now();
goban.setStoneFontScale(ss);
const end = Date.now();
console.log("SFS time: ", end - start);
});

fiddler.on("redraw", () => {
const start = Date.now();
goban.draw_top_labels = !!base_config.draw_top_labels;
Expand Down
9 changes: 9 additions & 0 deletions src/Goban/Goban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ export abstract class Goban extends OGSConnectivity {
this.redraw(true);
}
}

public setStoneFontScale(new_ss: number, suppress_redraw = false): void {
const redraw = this.stone_font_scale !== new_ss && !suppress_redraw;
this.stone_font_scale = new_ss;
if (redraw) {
this.redraw(true);
}
}

public computeMetrics(): GobanMetrics {
if (!this.square_size || this.square_size <= 0) {
this.square_size = 12;
Expand Down
20 changes: 16 additions & 4 deletions src/Goban/InteractiveBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ export abstract class GobanInteractive extends GobanBase {
this.emit("review_controller_id", this.review_controller_id);
}

public config: GobanConfig;
public last_move_radius: number;
public circle_radius: number;
public square_size: number = 10;
public stone_font_scale: number;

protected __board_redraw_pen_layer_timer: any = null;
protected __clock_timer?: ReturnType<typeof setTimeout>;
protected __draw_state: string[][];
Expand All @@ -231,16 +237,15 @@ export abstract class GobanInteractive extends GobanBase {
protected bounded_width: number;
protected bounds: GobanBounds;
protected conditional_path: string = "";
public config: GobanConfig;

protected current_cmove?: ConditionalMoveTree;
protected currently_my_cmove: boolean = false;
protected dirty_redraw: any = null; // timer
protected disconnectedFromGame: boolean = true;
protected display_width?: number;
protected done_loading_review: boolean = false;
protected dont_draw_last_move: boolean;
public last_move_radius: number;
public circle_radius: number;

protected edit_color?: "black" | "white";
protected errorHandler: (e: Error) => void;
protected heatmap?: NumberMatrix;
Expand Down Expand Up @@ -274,7 +279,6 @@ export abstract class GobanInteractive extends GobanBase {
protected shift_key_is_down: boolean;
//protected show_move_numbers: boolean;
protected show_variation_move_numbers: boolean;
public square_size: number = 10;
protected stone_placement_enabled: boolean;
protected sendLatencyTimer?: ReturnType<typeof niceInterval>;

Expand Down Expand Up @@ -407,6 +411,7 @@ export abstract class GobanInteractive extends GobanBase {
"draw_bottom_labels" in config ? !!config.draw_bottom_labels : true;
//this.show_move_numbers = this.getShowMoveNumbers();
this.show_variation_move_numbers = this.getShowVariationMoveNumbers();
this.stone_font_scale = this.getStoneFontScale();

if (this.bounds.left > 0) {
this.draw_left_labels = false;
Expand Down Expand Up @@ -490,6 +495,13 @@ export abstract class GobanInteractive extends GobanBase {
}
return false;
}
// scale relative to the "OGS default"
protected getStoneFontScale(): number {
if (callbacks.getStoneFontScale) {
return callbacks.getStoneFontScale();
}
return 1.0;
}
public static getMoveTreeNumbering(): string {
if (callbacks.getMoveTreeNumbering) {
return callbacks.getMoveTreeNumbering();
Expand Down
Loading

0 comments on commit 072d6ce

Please sign in to comment.