Function to capture mouse position
This commit is contained in:
22
src/API.ts
22
src/API.ts
@ -73,6 +73,28 @@ export class UserAPI {
|
||||
this.load = samples("github:tidalcycles/Dirt-Samples/master");
|
||||
}
|
||||
|
||||
// =============================================================
|
||||
// Time functions
|
||||
// =============================================================
|
||||
|
||||
get time(): number {
|
||||
return this.app.audioContext.currentTime
|
||||
}
|
||||
|
||||
// =============================================================
|
||||
// Mouse functions
|
||||
// =============================================================
|
||||
|
||||
get mouseX(): number {
|
||||
return this.app._mouseX
|
||||
}
|
||||
|
||||
get mouseY(): number {
|
||||
return this.app._mouseY
|
||||
}
|
||||
|
||||
|
||||
|
||||
// =============================================================
|
||||
// Utility functions
|
||||
// =============================================================
|
||||
|
||||
15
src/main.ts
15
src/main.ts
@ -32,7 +32,6 @@ export class Editor {
|
||||
editor_mode: "global" | "local" | "init" = "local";
|
||||
fontSize: Compartment;
|
||||
vimModeCompartment : Compartment;
|
||||
|
||||
|
||||
settings = new AppSettings();
|
||||
editorExtensions: Extension[] = [];
|
||||
@ -46,6 +45,11 @@ export class Editor {
|
||||
clock: Clock;
|
||||
manualPlay: boolean = false;
|
||||
|
||||
|
||||
// Mouse position
|
||||
public _mouseX: number = 0;
|
||||
public _mouseY: number = 0;
|
||||
|
||||
// Transport elements
|
||||
play_buttons: HTMLButtonElement[] = [
|
||||
document.getElementById("play-button-1") as HTMLButtonElement,
|
||||
@ -702,6 +706,14 @@ function startOnEnter(e: KeyboardEvent) {
|
||||
document.addEventListener("keydown", startOnEnter);
|
||||
document.getElementById("start-button")!.addEventListener("click", startClock);
|
||||
|
||||
function reportMouseCoordinates(event: MouseEvent) {
|
||||
app._mouseX = event.clientX;
|
||||
app._mouseY = event.clientY;
|
||||
}
|
||||
|
||||
window.addEventListener('mousemove', reportMouseCoordinates);
|
||||
|
||||
|
||||
// When the user leaves the page, all the universes should be saved in the localStorage
|
||||
window.addEventListener("beforeunload", () => {
|
||||
event.preventDefault();
|
||||
@ -712,3 +724,4 @@ window.addEventListener("beforeunload", () => {
|
||||
app.clock.stop()
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user