-
Notifications
You must be signed in to change notification settings - Fork 279
more mouse controls #2104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
more mouse controls #2104
Changes from 1 commit
8d37f13
67cfbeb
04b7b1a
35beeaf
dbabd4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Name: More Mouse Controls | ||
// ID: legobrainbikerMoreMouseControls | ||
// Description: Some features I felt were missing from the mouse, including right click detection. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you make this description a bit more professional and reminiscent of the extension's qualities? |
||
// By: legobrainbiker <https://scratch.mit.edu/users/legobrainbiker/> | ||
// License: MPL-2.0 | ||
((Scratch) => { | ||
LegoBrainBiker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"use strict"; | ||
class moreMouseControls { | ||
constructor() { | ||
this.mouseX = 0; | ||
this.mouseY = 0; | ||
this.scroll = 0; | ||
this.buttons = []; | ||
document.addEventListener("mousewheel", (e) => { | ||
this.mouseWheelDelta = e.deltaY; | ||
Scratch.vm.runtime.startHats( | ||
"legobrainbikerMoreMouseControls_onScroll" | ||
); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On scroll is available in native scratch when doing:
Because the hat block detects scrolling but the key boolean doesn't, so you can detect scrolling like this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize this, but I thought this would make it easier, especialy when using the other scroll block. also it works with both at the say time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's a valid point, but it's still probably not worth adding a whole new extension to the gallery though |
||
document.addEventListener("mouseup", (e) => { | ||
this.buttons[e.button] = false; | ||
}); | ||
document.addEventListener("mousedown", (e) => { | ||
this.buttons[e.button] = true; | ||
}); | ||
document.addEventListener("mousemove", (e) => { | ||
this.mouseX = e.clientX; | ||
this.mouseY = e.clientY; | ||
}); | ||
} | ||
getInfo() { | ||
return { | ||
id: "legobrainbikerMoreMouseControls", | ||
name: Scratch.translate("More Mouse Controls"), | ||
menuIconURI: | ||
"data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIzNi4zOTI4MSIgaGVpZ2h0PSIzNS40MjY1OSIgdmlld0JveD0iMCwwLDM2LjM5MjgxLDM1LjQyNjU5Ij48ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSgtMTU2Ljg4NTQxLC0xNTcuNjM4NDcpIj48ZyBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCI+PHBhdGggZD0iTTE2Mi44NjU0NCwxNjcuNDYzMDljMCwtMi4wNDY3NCAxLjc0NjIsLTMuNzA1OTQgMy45MDAyNCwtMy43MDU5NGMyLjE1NDA0LDAgMy45MDAyNCwxLjY1OTIxIDMuOTAwMjQsMy43MDU5NGMwLDIuMDQ2NzQgLTEuNzQ2MiwzLjcwNTk1IC0zLjkwMDI0LDMuNzA1OTVjLTIuMTU0MDQsMCAtMy45MDAyNCwtMS42NTkyMSAtMy45MDAyNCwtMy43MDU5NXoiIGZpbGw9Im5vbmUiIHN0cm9rZS13aWR0aD0iMi41IiBzdHJva2UtbGluZWNhcD0iYnV0dCIvPjxwYXRoIGQ9Ik0xNTguMTM1NDEsMTY3LjQ2MzA5YzAsLTQuNzM1NjMgMy44NjM5LC04LjU3NDYyIDguNjMwMjcsLTguNTc0NjJjNC43NjYzNywwIDguNjMwMjcsMy44Mzg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jMS4wNDI2OSwyLjE1MjY1IDIuMzMzMzgsMS4xMzM2NiAyLjc1MjMyLC0wLjU0MjA4YzAuNDY3NjksLTEuODcwNzUgMS41NTMyMywtNi4yMTI5MiAyLjE0OTI5LC04LjU5NzE0YzAuMjQ3MDcsLTAuOTg4MjggMS4yMjc3NCwtMS45Mzk5OCAyLjAwNjEzLC0yLjIyNTM5YzEuMTc1NDYsLTAuNDMxIDQuNjg3NzgsLTEuNzE4ODUgNy41ODU3MSwtMi43ODE0MmMyLjMzMSwtMC44NTQ3IDIuMzU5MTIsLTIuMTQzNTMgLTAuNDQ3MjksLTIuOTk3NjVjLTYuNTM1MzMsLTEuOTg5MDEgLTE3Ljk1NzAzLC01LjQ2NTE4IC0yMS41ODI1MiwtNi41Njg1OWMtMi4xNzUxNCwtMC42NjIgLTMuNDAzNTEsMS4xMjY3MyAtMi4zNDkwMywzLjMwMzczeiIgZmlsbD0iI2EzYTNhMyIgc3Ryb2tlLXdpZHRoPSIzLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIvPjwvZz48L2c+PC9zdmc+", | ||
color1: "#99bbbb", | ||
color2: "#88bbbb", | ||
color3: "#88bbbb", | ||
blocks: [ | ||
{ | ||
opcode: "onMouseUp", | ||
blockType: Scratch.BlockType.HAT, | ||
text: Scratch.translate("when mouse button [button] is released"), | ||
isEdgeActivated: true, | ||
arguments: { | ||
button: { | ||
type: Scratch.ArgumentType.NUMBER, | ||
defaultValue: "0", | ||
}, | ||
}, | ||
}, | ||
{ | ||
opcode: "onMouseDown", | ||
blockType: Scratch.BlockType.HAT, | ||
text: Scratch.translate("when mouse button [button] is pressed"), | ||
isEdgeActivated: true, | ||
arguments: { | ||
button: { | ||
type: Scratch.ArgumentType.NUMBER, | ||
defaultValue: "0", | ||
}, | ||
}, | ||
}, | ||
{ | ||
opcode: "buttonPressed", | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: Scratch.translate("mouse button [button] is pressed"), | ||
arguments: { | ||
button: { | ||
type: Scratch.ArgumentType.NUMBER, | ||
defaultValue: "0", | ||
}, | ||
}, | ||
}, | ||
{ | ||
opcode: "dissableContextMenu", | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: Scratch.translate("disable context menu"), | ||
}, | ||
{ | ||
opcode: "onScroll", | ||
blockType: Scratch.BlockType.EVENT, | ||
text: Scratch.translate("when scrolling"), | ||
isEdgeActivated: false, | ||
}, | ||
{ | ||
opcode: "scrollamount", | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: Scratch.translate("scroll amount"), | ||
}, | ||
{ | ||
opcode: "mouseGlobalX", | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: Scratch.translate("mouse global x position"), | ||
}, | ||
{ | ||
opcode: "mouseGlobalY", | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: Scratch.translate("mouse global y position"), | ||
}, | ||
], | ||
}; | ||
} | ||
onMouseUp(args) { | ||
return !this.buttonPressed(args); | ||
} | ||
onMouseDown(args) { | ||
return this.buttonPressed(args); | ||
} | ||
buttonPressed({ button }) { | ||
console.log(button); | ||
console.log(Scratch.Cast.toNumber(button)); | ||
console.log(this.buttons[Scratch.Cast.toNumber(button)]); | ||
return this.buttons[Scratch.Cast.toNumber(button)] || false; | ||
} | ||
dissableContextMenu() { | ||
document.addEventListener("contextmenu", (e) => { | ||
e.preventDefault(); | ||
}); | ||
} | ||
scrollamount() { | ||
return this.mouseWheelDelta || 0; | ||
} | ||
mouseGlobalX() { | ||
const canvas = Scratch.renderer.canvas.getBoundingClientRect(); | ||
return this.mouseX - canvas.x - canvas.width / 2; | ||
} | ||
mouseGlobalY() { | ||
const canvas = Scratch.renderer.canvas.getBoundingClientRect(); | ||
return -(this.mouseY - canvas.y - canvas.height / 2); | ||
} | ||
} | ||
Scratch.extensions.register(new moreMouseControls()); | ||
})(Scratch); |
Uh oh!
There was an error while loading. Please reload this page.