Skip to content

Commit

Permalink
feat: Zooming focus feature in mobile clients
Browse files Browse the repository at this point in the history
  • Loading branch information
NriotHrreion committed May 26, 2024
1 parent 9b693cd commit 05a1547
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/renderer/Render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class Render extends Graphics {

// Mobile zooming
private zoomingScale: number | null = null;
private zoomingFocus: Point | null = null;
private lastZoomingSize: number | null = null;

private fpsUpdater: NodeJS.Timer;
Expand Down Expand Up @@ -148,6 +149,7 @@ export default class Render extends Graphics {
this.stopMoving();
this.zoomingScale = null;
this.lastZoomingSize = null;
this.zoomingFocus = null;
}

public handleWheel(dy: number) {
Expand Down Expand Up @@ -181,8 +183,9 @@ export default class Render extends Graphics {

if(!this.lastZoomingSize) this.lastZoomingSize = zoomingSize;

if(!this.zoomingScale) {
if(!this.zoomingScale || !this.zoomingFocus) {
this.zoomingScale = zoomingSize / this.scale;
this.zoomingFocus = this.pointToCoordinates(this.createPoint((screenA.x + screenB.x) / 2, (screenA.y + screenB.y) / 2));
return;
}

Expand All @@ -196,6 +199,13 @@ export default class Render extends Graphics {
);

this.lastZoomingSize = zoomingSize;

const currentFocusPoint = this.pointToCoordinates(this.createPoint((screenA.x + screenB.x) / 2, (screenA.y + screenB.y) / 2));
var centerDx = currentFocusPoint.x - this.zoomingFocus.x,
centerDy = currentFocusPoint.y - this.zoomingFocus.y;

this.center.x += centerDx * this.scale;
this.center.y -= centerDy * this.scale;
}

private refreshMousePoint(rect: DOMRect, cx: number, cy: number) {
Expand Down

1 comment on commit 05a1547

@github-actions
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.