This commit is contained in:
2026-07-19 18:26:00 +09:00
parent 29a17f33ce
commit ef0dab9bc3
16 changed files with 1872 additions and 696 deletions
@@ -1,6 +1,6 @@
import {Point} from '@flatten-js/core';
import {compact, round} from 'es-toolkit';
import {Actor} from 'xstate';
import { Point } from '@flatten-js/core';
import { compact, round } from 'es-toolkit';
import { Actor } from 'xstate';
import {
CANVAS_INPUT_FIELD_BACKGROUND_COLOR,
CANVAS_INPUT_FIELD_HEIGHT,
@@ -10,19 +10,19 @@ import {
CANVAS_INPUT_FIELD_WIDTH,
HIGHLIGHT_ENTITY_DISTANCE,
SNAP_POINT_DISTANCE,
TOOLBAR_WIDTH,
} from '../App.consts.ts';
import {MouseButton} from '../App.types.ts';
import type {ScreenCanvasDrawController} from '../drawControllers/screenCanvas.drawController.ts';
import {calculateAngleGuidesAndSnapPoints} from '../helpers/calculate-angle-guides-and-snap-points.ts';
import {findClosestEntity} from '../helpers/find-closest-entity.ts';
import {getClosestSnapPointWithinRadius} from '../helpers/get-closest-snap-point.ts';
import { MouseButton } from '../App.types.ts';
import type { ScreenCanvasDrawController } from '../drawControllers/screenCanvas.drawController.ts';
import { calculateAngleGuidesAndSnapPoints } from '../helpers/calculate-angle-guides-and-snap-points.ts';
import { findClosestEntity } from '../helpers/find-closest-entity.ts';
import { getClosestSnapPointWithinRadius } from '../helpers/get-closest-snap-point.ts';
import {
getActiveToolActor,
getCanvas,
getEntities,
getLastStateInstructions,
getPanStartLocation,
getSnapEnabled,
getScreenCanvasDrawController,
getSelectedEntities,
getSnapPoint,
@@ -36,8 +36,8 @@ import {
setShouldDrawCursor,
undo,
} from '../state.ts';
import {Tool} from '../tools.ts';
import {TOOL_STATE_MACHINES} from '../tools/tool.consts.ts';
import { Tool } from '../tools.ts';
import { TOOL_STATE_MACHINES } from '../tools/tool.consts.ts';
import {
type AbsolutePointInputEvent,
ActorEvent,
@@ -120,6 +120,11 @@ export class InputController {
this.drawListBelowInputField(drawController, texts);
}
public submitText(value: string) {
this.text = value.trim().toUpperCase();
this.handleEnterKey();
}
public handleMouseUp(evt: MouseEvent) {
if (evt.button === MouseButton.Right) {
// Right click => confirm action (ENTER)
@@ -146,10 +151,7 @@ export class InputController {
);
const worldMouseLocationTemp = getScreenCanvasDrawController().targetToWorld(
new Point(
evt.clientX - TOOLBAR_WIDTH,
getScreenCanvasDrawController().getCanvasSize().y - evt.clientY
)
this.getCanvasPoint(evt)
);
const worldMouseLocation = closestSnapPoint ? closestSnapPoint.point : worldMouseLocationTemp;
@@ -171,10 +173,7 @@ export class InputController {
public handleMouseMove(evt: MouseEvent) {
setShouldDrawCursor(true);
const screenCanvasDrawController = getScreenCanvasDrawController();
const newScreenMouseLocation = new Point(
evt.clientX - TOOLBAR_WIDTH,
getScreenCanvasDrawController().getCanvasSize().y - evt.clientY
);
const newScreenMouseLocation = this.getCanvasPoint(evt);
screenCanvasDrawController.setScreenMouseLocation(newScreenMouseLocation);
// If the middle mouse button is pressed, pan the screen
@@ -188,7 +187,9 @@ export class InputController {
}
// Calculate angle guides and snap points
calculateAngleGuidesAndSnapPoints();
if (getSnapEnabled()) {
calculateAngleGuidesAndSnapPoints();
}
// Highlight the entity closest to the mouse when the select tool is active
if (getActiveToolActor()?.getSnapshot()?.context.type === Tool.SELECT) {
@@ -223,11 +224,14 @@ export class InputController {
public handleMouseDown(evt: MouseEvent) {
if (evt.button !== MouseButton.Middle) return;
setPanStartLocation(
new Point(
evt.clientX - TOOLBAR_WIDTH,
getScreenCanvasDrawController().getCanvasSize().y - evt.clientY
)
setPanStartLocation(this.getCanvasPoint(evt));
}
private getCanvasPoint(evt: MouseEvent): Point {
const bounds = getCanvas()?.getBoundingClientRect();
return new Point(
evt.clientX - (bounds?.left ?? 0),
(bounds?.bottom ?? getScreenCanvasDrawController().getCanvasSize().y) - evt.clientY
);
}
@@ -261,6 +265,9 @@ export class InputController {
}
public handleKeyStroke(evt: KeyboardEvent) {
if ((evt.target as HTMLElement | null)?.closest('input, textarea, select')) {
return;
}
console.log(`key pressed: ${evt.key}`);
if (evt.key === 'F12') {
// F12 => open developer tools