-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from odama626/multiselect
Multiselect
- Loading branch information
Showing
21 changed files
with
758 additions
and
275 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { Vector2, WebGLRenderer } from 'three'; | ||
|
||
class SelectionHelper { | ||
private element; | ||
private startPoint; | ||
private pointTopLeft; | ||
private pointBottomRight; | ||
public isDown; | ||
public enabled; | ||
public onPointerDown; | ||
onPointerMove: (event: any) => void; | ||
onPointerUp: () => void; | ||
|
||
constructor(private renderer: WebGLRenderer, cssClassName: string) { | ||
this.element = document.createElement('div'); | ||
this.element.classList.add(cssClassName); | ||
this.element.style.pointerEvents = 'none'; | ||
|
||
this.renderer = renderer; | ||
|
||
this.startPoint = new Vector2(); | ||
this.pointTopLeft = new Vector2(); | ||
this.pointBottomRight = new Vector2(); | ||
|
||
this.isDown = false; | ||
this.enabled = true; | ||
|
||
this.onPointerDown = function (event) { | ||
if (this.enabled === false) return; | ||
|
||
this.isDown = true; | ||
this.onSelectStart(event); | ||
}.bind(this); | ||
|
||
this.onPointerMove = function (event) { | ||
if (this.enabled === false) return; | ||
|
||
if (this.isDown) { | ||
this.onSelectMove(event); | ||
} | ||
}.bind(this); | ||
|
||
this.onPointerUp = function () { | ||
if (this.enabled === false) return; | ||
|
||
this.isDown = false; | ||
this.onSelectOver(); | ||
}.bind(this); | ||
|
||
// this.renderer.domElement.addEventListener('pointerdown', this.onPointerDown); | ||
// this.renderer.domElement.addEventListener('pointermove', this.onPointerMove); | ||
// this.renderer.domElement.addEventListener('pointerup', this.onPointerUp); | ||
} | ||
|
||
dispose() { | ||
// this.renderer.domElement.removeEventListener('pointerdown', this.onPointerDown); | ||
// this.renderer.domElement.removeEventListener('pointermove', this.onPointerMove); | ||
// this.renderer.domElement.removeEventListener('pointerup', this.onPointerUp); | ||
} | ||
|
||
onSelectStart(event) { | ||
this.element.style.display = 'none'; | ||
this.renderer.domElement.parentElement.appendChild(this.element); | ||
|
||
this.element.style.left = event.clientX + 'px'; | ||
this.element.style.top = event.clientY + 'px'; | ||
this.element.style.width = '0px'; | ||
this.element.style.height = '0px'; | ||
|
||
this.startPoint.x = event.clientX; | ||
this.startPoint.y = event.clientY; | ||
} | ||
|
||
onSelectMove(event) { | ||
this.element.style.display = 'block'; | ||
|
||
this.pointBottomRight.x = Math.max(this.startPoint.x, event.clientX); | ||
this.pointBottomRight.y = Math.max(this.startPoint.y, event.clientY); | ||
this.pointTopLeft.x = Math.min(this.startPoint.x, event.clientX); | ||
this.pointTopLeft.y = Math.min(this.startPoint.y, event.clientY); | ||
|
||
this.element.style.left = this.pointTopLeft.x + 'px'; | ||
this.element.style.top = this.pointTopLeft.y + 'px'; | ||
this.element.style.width = this.pointBottomRight.x - this.pointTopLeft.x + 'px'; | ||
this.element.style.height = this.pointBottomRight.y - this.pointTopLeft.y + 'px'; | ||
} | ||
|
||
onSelectOver() { | ||
if (this.element.parentElement) { | ||
this.element.parentElement.removeChild(this.element); | ||
} | ||
} | ||
} | ||
|
||
export { SelectionHelper }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.