Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export interface Config {
defaultSnapToValidMove?: boolean;
// Clicking an empty square or immovable piece will clear the drawing regardless, but when this property is true,
// clicking on a (currently unselected) movable piece will also clear the drawing.
eraseOnMovablePieceClick?: boolean;
eraseOnMouchDown?: boolean;
shapes?: DrawShape[];
autoShapes?: DrawShape[];
brushes?: DrawBrushes;
Expand Down
18 changes: 12 additions & 6 deletions src/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ export function start(s: State, e: cg.MouchEvent): void {
if (!orig) return;
const piece = s.pieces.get(orig);
const previouslySelected = s.selected;
if (
!previouslySelected &&
s.drawable.enabled &&
(s.drawable.eraseOnMovablePieceClick || !piece || piece.color !== s.turnColor)
)
drawClear(s);
if (!previouslySelected && s.drawable.enabled) {
if (s.drawable.eraseOnMouchDown) drawClear(s);
else if (piece?.color !== s.turnColor) s.pixelCoordsOfMouchDownToMaybeClearShapes = position;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this turnColor check really only makes sense when you're playing a game. But most arrows I think are drawn in studies/broadcast/analysis.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ornicar I've tested on studies/analysis and the turnColor stores which side is to move there as well. Unless I'm misunderstanding.

}
// Prevent touch scroll and create no corresponding mouse event, if there
// is an intent to interact with the board.
if (
Expand Down Expand Up @@ -159,6 +157,14 @@ export function move(s: State, e: cg.MouchEvent): void {
}

export function end(s: State, e: cg.MouchEvent): void {
const position = util.eventPosition(e);
if (
position &&
s.pixelCoordsOfMouchDownToMaybeClearShapes &&
util.distanceSq(position, s.pixelCoordsOfMouchDownToMaybeClearShapes) < 225
)
drawClear(s);
s.pixelCoordsOfMouchDownToMaybeClearShapes = undefined;
const cur = s.draggable.current;
if (!cur) return;
// create no corresponding mouse event
Expand Down
2 changes: 1 addition & 1 deletion src/draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface Drawable {
enabled: boolean; // can draw
visible: boolean; // can view
defaultSnapToValidMove: boolean;
eraseOnMovablePieceClick: boolean;
eraseOnMouchDown: boolean;
onChange?: (shapes: DrawShape[]) => void;
shapes: DrawShape[]; // user shapes
autoShapes: DrawShape[]; // computer shapes
Expand Down
3 changes: 2 additions & 1 deletion src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface HeadlessState {
blockTouchScroll: boolean; // block scrolling via touch dragging on the board
touchIgnoreRadius: number; // ignore touches within a radius of an occupied square, in units of its circumradius
pieceKey: boolean; // add a data-key attribute to piece elements
pixelCoordsOfMouchDownToMaybeClearShapes?: cg.NumberPair;
trustAllEvents?: boolean; // disable checking for human only input (e.isTrusted)
highlight: {
lastMove: boolean; // add last-move class to squares
Expand Down Expand Up @@ -176,7 +177,7 @@ export function defaults(): HeadlessState {
enabled: true, // can draw
visible: true, // can view
defaultSnapToValidMove: true,
eraseOnMovablePieceClick: true,
eraseOnMouchDown: true,
shapes: [],
autoShapes: [],
brushes: {
Expand Down