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");
|
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
|
// Utility functions
|
||||||
// =============================================================
|
// =============================================================
|
||||||
|
|||||||
15
src/main.ts
15
src/main.ts
@ -32,7 +32,6 @@ export class Editor {
|
|||||||
editor_mode: "global" | "local" | "init" = "local";
|
editor_mode: "global" | "local" | "init" = "local";
|
||||||
fontSize: Compartment;
|
fontSize: Compartment;
|
||||||
vimModeCompartment : Compartment;
|
vimModeCompartment : Compartment;
|
||||||
|
|
||||||
|
|
||||||
settings = new AppSettings();
|
settings = new AppSettings();
|
||||||
editorExtensions: Extension[] = [];
|
editorExtensions: Extension[] = [];
|
||||||
@ -46,6 +45,11 @@ export class Editor {
|
|||||||
clock: Clock;
|
clock: Clock;
|
||||||
manualPlay: boolean = false;
|
manualPlay: boolean = false;
|
||||||
|
|
||||||
|
|
||||||
|
// Mouse position
|
||||||
|
public _mouseX: number = 0;
|
||||||
|
public _mouseY: number = 0;
|
||||||
|
|
||||||
// Transport elements
|
// Transport elements
|
||||||
play_buttons: HTMLButtonElement[] = [
|
play_buttons: HTMLButtonElement[] = [
|
||||||
document.getElementById("play-button-1") as HTMLButtonElement,
|
document.getElementById("play-button-1") as HTMLButtonElement,
|
||||||
@ -702,6 +706,14 @@ function startOnEnter(e: KeyboardEvent) {
|
|||||||
document.addEventListener("keydown", startOnEnter);
|
document.addEventListener("keydown", startOnEnter);
|
||||||
document.getElementById("start-button")!.addEventListener("click", startClock);
|
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
|
// When the user leaves the page, all the universes should be saved in the localStorage
|
||||||
window.addEventListener("beforeunload", () => {
|
window.addEventListener("beforeunload", () => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -712,3 +724,4 @@ window.addEventListener("beforeunload", () => {
|
|||||||
app.clock.stop()
|
app.clock.stop()
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user