Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support a scale parameter for the font size for stone markings. #177

Merged
merged 7 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading