diff --git a/docs/CubesterYT/WindowControls.md b/docs/CubesterYT/WindowControls.md new file mode 100644 index 0000000000..b0efe57279 --- /dev/null +++ b/docs/CubesterYT/WindowControls.md @@ -0,0 +1,463 @@ +# Window Controls + +This extension provides a set of blocks that gives you greater control over the Program Window. + +Note: Most of these blocks only work in Electron, Pop Ups/Web Apps containing HTML packaged projects, and normal Web Apps. + +Examples include, but are not limited to: TurboWarp Desktop App, TurboWarp Web App, Pop Up/Web App windows that contain the HTML packaged project, and plain Electron. + +Blocks that still work outside of these will be specified. + +
+ +

Move Window Block (#)

+ +```scratch +move window to x: (0) y: (0) :: #359ed4 +``` + +Moves the Program Window to the defined "x" and "y" coordinate on the screen. + +
+ +

Move Window to Preset Block (#)

+ +Moves the Program Window to a preset. + +The menu area has ten options, ("center", "right", "left", "top", "bottom", "top right", "top left", "bottom right", "bottom left", "random position") + +#### Center + +```scratch +move window to the (center v) :: #359ed4 +``` + +When choosing "center", it will move the Program Window to the center of the screen. + +#### Right + +```scratch +move window to the (right v) :: #359ed4 +``` + +When choosing "right", it will move the Program Window to the right of the screen. + +#### Left + +```scratch +move window to the (left v) :: #359ed4 +``` + +When choosing "left", it will move the Program Window to the left of the screen. + +#### Top + +```scratch +move window to the (top v) :: #359ed4 +``` + +When choosing "top", it will move the Program Window to the top of the screen. + +#### Bottom + +```scratch +move window to the (bottom v) :: #359ed4 +``` + +When choosing "bottom", it will move the Program Window to the bottom of the screen. + +#### Top Right + +```scratch +move window to the (top right v) :: #359ed4 +``` + +When choosing "top right", it will move the Program Window to the top right of the screen. + +#### Top Left + +```scratch +move window to the (top left v) :: #359ed4 +``` + +When choosing "top left", it will move the Program Window to the top left of the screen. + +#### Bottom Right + +```scratch +move window to the (bottom right v) :: #359ed4 +``` + +When choosing "bottom right", it will move the Program Window to the bottom right of the screen. + +#### Bottom Left + +```scratch +move window to the (bottom left v) :: #359ed4 +``` + +When choosing "bottom left", it will move the Program Window to the bottom left of the screen. + +#### Random Position + +```scratch +move window to the (random position v) :: #359ed4 +``` + +When choosing "random position", it will move the Program Window to a random position on the screen. + +
+ +

Change "x" Block (#)

+ +```scratch +change window x by (50) :: #359ed4 +``` + +Dynamically changes the "x" position of the Program Window on the screen. + +
+ +

Set "x" Block (#)

+ +```scratch +set window x to (100) :: #359ed4 +``` + +Statically changes the "x" position of the Program Window on the screen. + +
+ +

Change "y" Block (#)

+ +```scratch +change window y by (50) :: #359ed4 +``` + +Dynamically changes the "y" position of the Program Window on the screen. + +
+ +

Set "y" Block (#)

+ +```scratch +set window y to (100) :: #359ed4 +``` + +Statically changes the "y" position of the Program Window on the screen. + +
+ +

Window "x" Reporter (#)

+ +```scratch +(window x :: #359ed4) +``` + +This reporter returns the "x" position of the Program Window. + +This is supported outside of Electron, Pop Ups, and Web Apps. + +
+ +

Window "y" Reporter (#)

+ +```scratch +(window y :: #359ed4) +``` + +This reporter returns the "y" position of the Program Window. + +This is supported outside of Electron, Pop Ups, and Web Apps. + +
+ +

Resize Window Block (#)

+ +```scratch +resize window to width: (1000) height: (1000) :: #359ed4 +``` + +Resizes the Program Window to the defined width and height values. + +
+ +

Resize Window Preset Block (#)

+ +Resizes the Program Window to a preset. + +The menu area has eight options, ("480x360", "640x480", "1280x720", "1920x1080", "2560x1440", "2048x1080", "3840x2160", "7680x4320") + +#### 480x360 + +```scratch +resize window to (480x360 v) :: #359ed4 +``` + +When choosing "480x360", it will resize the Program Window to 480x360 (360p). The aspect ratio for this size is 4:3. + +#### 640x480 + +```scratch +resize window to (640x480 v) :: #359ed4 +``` + +When choosing "640x480", it will resize the Program Window to 640x480 (480p). The aspect ratio for this size is 4:3. + +#### 1280x720 + +```scratch +resize window to (1280x720 v) :: #359ed4 +``` + +When choosing "1280x720", it will resize the Program Window to 1280x720 (720p). The aspect ratio for this size is 16:9. + +#### 1920x1080 + +```scratch +resize window to (1920x1080 v) :: #359ed4 +``` + +When choosing "1920x1080", it will resize the Program Window to 1920x1080 (1080p). The aspect ratio for this size is 16:9. + +#### 2560x1440 + +```scratch +resize window to (2560x1440 v) :: #359ed4 +``` + +When choosing "2560x1440", it will resize the Program Window to 2560x1440 (1440p). The aspect ratio for this size is 16:9. + +#### 2048x1080 + +```scratch +resize window to (2048x1080 v) :: #359ed4 +``` + +When choosing "2048x1080", it will resize the Program Window to 2048x1080 (2K/1080p[Higher Pixel Rate]). The aspect ratio for this size is 1:1.77. + +#### 3840x2160 + +```scratch +resize window to (3840x2160 v) :: #359ed4 +``` + +When choosing "3840x2160", it will resize the Program Window to 3840x2160 (4K). The aspect ratio for this size is 1:1.9. + +#### 7680x4320 + +```scratch +resize window to (7680x4320 v) :: #359ed4 +``` + +When choosing "7680x4320", it will resize the Program Window to 7680x4320 (8K). The aspect ratio for this size is 16:9. + +
+ +

Change Width Block (#)

+ +```scratch +change window width by (50) :: #359ed4 +``` + +Dynamically changes the width of the Program Window. + +
+ +

Set Width Block (#)

+ +```scratch +set window width to (1000) :: #359ed4 +``` + +Statically changes the width of the Program Window. + +
+ +

Change Height Block (#)

+ +```scratch +change window height by (50) :: #359ed4 +``` + +Dynamically changes the height of the Program Window. + +
+ +

Set Height Block (#)

+ +```scratch +set window height to (1000) :: #359ed4 +``` + +Statically changes the height of the Program Window. + +
+ +

Match Stage Size Block (#)

+ +```scratch +match stage size :: #359ed4 +``` + +Resizes the Program Window to match the aspect ratio of the stage. Works best when the stage is dynamically changed. + +Example: When using runtime options to change the stage size, using this block can help you adapt to the new stage size. + +Try this example script in a packaged project: + +```scratch +when green flag clicked +wait (1) seconds +set stage size width: (360) height: (480) :: #8c9abf +match stage size :: #359ed4 +move window to the (center v) :: #359ed4 +wait (1) seconds +set stage size width: (480) height: (360) :: #8c9abf +match stage size :: #359ed4 +move window to the (center v) :: #359ed4 +``` + +
+ +

Window Width Reporter (#)

+ +```scratch +(window width :: #359ed4) +``` + +This reporter returns the width of the Program Window. + +This is supported outside of Electron, Pop Ups, and Web Apps. + +
+ +

Window Height Reporter (#)

+ +```scratch +(window height :: #359ed4) +``` + +This reporter returns the height of the Program Window. + +This is supported outside of Electron, Pop Ups, and Web Apps. + +
+ +

Is Window Touching Screen Edge Boolean (#)

+ +```scratch + +``` + +This boolean returns true or false for whether or not the Program Window is touching the screen's edge. + +This is supported outside of Electron, Pop Ups, and Web Apps. + +
+ +

Screen Width Reporter (#)

+ +```scratch +(screen width :: #359ed4) +``` + +This reporter returns the width of the Screen. + +This is supported outside of Electron, Pop Ups, and Web Apps. + +
+ +

Screen Height Reporter (#)

+ +```scratch +(screen height :: #359ed4) +``` + +This reporter returns the height of the Screen. + +This is supported outside of Electron, Pop Ups, and Web Apps. + +
+ +

Is Window Focused Boolean (#)

+ +```scratch + +``` + +This boolean returns true or false for whether or not the Program Window is in focus. + +This is supported outside of Electron, Pop Ups, and Web Apps. + +
+ +

Set Window Title Block (#)

+ +```scratch +set window title to ["Hello World!] :: #359ed4 +``` + +Changes the title of the Program Window. + +This is supported outside of Electron, Pop Ups, and Web Apps. + +
+ +

Window Title Reporter (#)

+ +```scratch +(window title :: #359ed4) +``` + +This reporter returns the title of the Program Window. + +This is supported outside of Electron, Pop Ups, and Web Apps. + +
+ +

Enter Fullscreen Block (#)

+ +```scratch +enter fullscreen :: #359ed4 +``` + +Makes the Program Window enter Fullscreen. + +This is supported outside of Electron, Pop Ups, and Web Apps. + +
+ +

Exit Fullscreen Block (#)

+ +```scratch +exit fullscreen :: #359ed4 +``` + +Makes the Program Window exit Fullscreen. + +This is supported outside of Electron, Pop Ups, and Web Apps. + +
+ +

Is Window Fullscreen Boolean (#)

+ +```scratch + +``` + +This boolean returns true or false for whether or not the Program Window is in fullscreen. + +This is supported outside of Electron, Pop Ups, and Web Apps. + +
+ +

Close Window Block (#)

+ +```scratch +close window :: cap :: #359ed4 +``` + +Closes the Program Window. + +This is supported outside of Electron, Pop Ups, and Web Apps. \ No newline at end of file diff --git a/extensions/CubesterYT/WindowControls.js b/extensions/CubesterYT/WindowControls.js new file mode 100644 index 0000000000..67fe6832fd --- /dev/null +++ b/extensions/CubesterYT/WindowControls.js @@ -0,0 +1,510 @@ +// Name: Window Controls +// ID: cubesterWindowControls +// Description: Move, resize, rename the window, enter fullscreen, get screen size, and more. +// By: CubesterYT + +// Version V.1.0.0 + +(function (Scratch) { + "use strict"; + + const icon = + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAA0GVYSWZJSSoACAAAAAoAAAEEAAEAAABAAAAAAQEEAAEAAABAAAAAAgEDAAMAAACGAAAAEgEDAAEAAAABAAAAGgEFAAEAAACMAAAAGwEFAAEAAACUAAAAKAEDAAEAAAACAAAAMQECAA0AAACcAAAAMgECABQAAACqAAAAaYcEAAEAAAC+AAAAAAAAAAgACAAIAEgAAAABAAAASAAAAAEAAABHSU1QIDIuMTAuMzQAADIwMjM6MDg6MTUgMjI6MjU6MTcAAQABoAMAAQAAAAEAAAAAAAAA+Kkp0wAAAYRpQ0NQSUNDIHByb2ZpbGUAAHicfZE9SMNAHMVfW6VFKgp2KOKQoTpZKCriqFUoQoVQK7TqYHLpFzRpSFJcHAXXgoMfi1UHF2ddHVwFQfADxNXFSdFFSvxfUmgR48FxP97de9y9A/zNKlPNngSgapaRSSWFXH5VCL4ihEEEEEVCYqY+J4ppeI6ve/j4ehfnWd7n/hz9SsFkgE8gnmW6YRFvEE9vWjrnfeIIK0sK8TnxuEEXJH7kuuzyG+eSw36eGTGymXniCLFQ6mK5i1nZUImniGOKqlG+P+eywnmLs1qts/Y9+QvDBW1lmes0R5DCIpYgQoCMOiqowkKcVo0UExnaT3r4hx2/SC6ZXBUwciygBhWS4wf/g9/dmsXJCTcpnAR6X2z7YxQI7gKthm1/H9t26wQIPANXWsdfawIzn6Q3OlrsCBjYBi6uO5q8B1zuANEnXTIkRwrQ9BeLwPsZfVMeGLoF+tbc3tr7OH0AstRV+gY4OATGSpS97vHuUHdv/55p9/cDaOdyoyaJtEEAAA14aVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8P3hwYWNrZXQgYmVnaW49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aW1lU3RhbXA9IjE2OTIxNTYzMTc3MjY0NjciCiAgIEdJTVA6VmVyc2lvbj0iMi4xMC4zNCIKICAgdGlmZjpPcmllbnRhdGlvbj0iMSIKICAgeG1wOkNyZWF0b3JUb29sPSJHSU1QIDIuMTAiCiAgIHhtcDpNZXRhZGF0YURhdGU9IjIwMjM6MDg6MTVUMjI6MjU6MTctMDU6MDAiCiAgIHhtcDpNb2RpZnlEYXRlPSIyMDIzOjA4OjE1VDIyOjI1OjE3LTA1OjAwIj4KICAgPHhtcE1NOkhpc3Rvcnk+CiAgICA8cmRmOlNlcT4KICAgICA8cmRmOmxpCiAgICAgIHN0RXZ0OmFjdGlvbj0ic2F2ZWQiCiAgICAgIHN0RXZ0OmNoYW5nZWQ9Ii8iCiAgICAgIHN0RXZ0Omluc3RhbmNlSUQ9InhtcC5paWQ6MzlmYmE1ZjAtZmE4OC00M2ZjLTgyMjQtMGIwYjlhMGRkZDkyIgogICAgICBzdEV2dDpzb2Z0d2FyZUFnZW50PSJHaW1wIDIuMTAgKExpbnV4KSIKICAgICAgc3RFdnQ6d2hlbj0iMjAyMy0wOC0xNVQyMjoyNToxNy0wNTowMCIvPgogICAgPC9yZGY6U2VxPgogICA8L3htcE1NOkhpc3Rvcnk+CiAgPC9yZGY6RGVzY3JpcHRpb24+CiA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgCjw/eHBhY2tldCBlbmQ9InciPz45jkSCAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH5wgQAxkRVAqqdwAAAchQTFRFAAAAGn+yG4CyHICzHX2yHYC1GoC0Gn+yGn+zGoCzG3+zG3+0G4CzHICzHIC0HIGzG3+zG4CzG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zG3+zHIC0HIC0G3+zHIC0G3+zG3+zHoK2IIS5IYW5I4e8JIi9JYm+Jou/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gAsL1a0xF/lEm8uLS4LANZF6n9IfC0tqnxuqAMZ43oAcSMyMyJg7uIo0QjRqIJGqpoTAYwZ2TNQ/y5Axo6crB4A60Segh5AwYP8nB4A50dB0AOAA3oBQf2foPsn6t5G3QdJcpTrAJCjLEmmOgAkmSTpXAeApLOkoGgHlAqKpKRpB5RLmu6i2igt69oAfFmXNRZtAL6xyFqbJoDQ2qTNVRNAaK58e5/G+H297b1sMCbpDcbVtQYDNYsWZ4rS4vwoWZwmucma0GKyxuQmi7d516lt3u8bxOZ1rzeaww+pjObrBwpGE+3QanW3b7bZ1mb3+/YqDQwt9ANHi76Rp+v/DV0I7VId+3r2qM2t+gbPTRh9S2pQHr4bNE3w1fF//4bj/z8IjCsoNvb7bgAAAABJRU5ErkJggg=="; + + function getRandomInt(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min + 1)) + min; + } + + class WindowControls { + getInfo() { + return { + id: "cubesterWindowControls", + name: "Window Controls", + color1: "#359ed4", + color2: "#298ec2", + color3: "#2081b3", + menuIconURI: icon, + docsURI: "https://extensions.turbowarp.org/CubesterYT/WindowControls", + + blocks: [ + { + blockType: "label", + text: "May not work in normal browser tabs", + }, + { + blockType: "label", + text: "Refer to Documentation for details", + }, + { + opcode: "moveTo", + blockType: Scratch.BlockType.COMMAND, + text: "move window to x: [X] y: [Y]", + arguments: { + X: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: "0", + }, + Y: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: "0", + }, + }, + }, + { + opcode: "moveToPresets", + blockType: Scratch.BlockType.COMMAND, + text: "move window to the [PRESETS]", + arguments: { + PRESETS: { + type: Scratch.ArgumentType.STRING, + menu: "MOVE", + }, + }, + }, + { + opcode: "changeX", + blockType: Scratch.BlockType.COMMAND, + text: "change window x by [X]", + arguments: { + X: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: "50", + }, + }, + }, + { + opcode: "setX", + blockType: Scratch.BlockType.COMMAND, + text: "set window x to [X]", + arguments: { + X: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: "100", + }, + }, + }, + { + opcode: "changeY", + blockType: Scratch.BlockType.COMMAND, + text: "change window y by [Y]", + arguments: { + Y: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: "50", + }, + }, + }, + { + opcode: "setY", + blockType: Scratch.BlockType.COMMAND, + text: "set window y to [Y]", + arguments: { + Y: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: "100", + }, + }, + }, + { + opcode: "windowX", + blockType: Scratch.BlockType.REPORTER, + text: "window x", + }, + { + opcode: "windowY", + blockType: Scratch.BlockType.REPORTER, + text: "window y", + }, + + "---", + + { + opcode: "resizeTo", + blockType: Scratch.BlockType.COMMAND, + text: "resize window to width: [W] height: [H]", + arguments: { + W: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: "480", + }, + H: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: "360", + }, + }, + }, + { + opcode: "resizeToPresets", + blockType: Scratch.BlockType.COMMAND, + text: "resize window to [PRESETS]", + arguments: { + PRESETS: { + type: Scratch.ArgumentType.STRING, + menu: "RESIZE", + }, + }, + }, + { + opcode: "changeW", + blockType: Scratch.BlockType.COMMAND, + text: "change window width by [W]", + arguments: { + W: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: "50", + }, + }, + }, + { + opcode: "setW", + blockType: Scratch.BlockType.COMMAND, + text: "set window width to [W]", + arguments: { + W: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: "1000", + }, + }, + }, + { + opcode: "changeH", + blockType: Scratch.BlockType.COMMAND, + text: "change window height by [H]", + arguments: { + H: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: "50", + }, + }, + }, + { + opcode: "setH", + blockType: Scratch.BlockType.COMMAND, + text: "set window height to [H]", + arguments: { + H: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: "1000", + }, + }, + }, + { + opcode: "matchStageSize", + blockType: Scratch.BlockType.COMMAND, + text: "match stage size", + }, + { + opcode: "windowW", + blockType: Scratch.BlockType.REPORTER, + text: "window width", + }, + { + opcode: "windowH", + blockType: Scratch.BlockType.REPORTER, + text: "window height", + }, + + "---", + + { + opcode: "isTouchingEdge", + blockType: Scratch.BlockType.BOOLEAN, + text: "is window touching screen edge?", + }, + { + opcode: "screenW", + blockType: Scratch.BlockType.REPORTER, + text: "screen width", + }, + { + opcode: "screenH", + blockType: Scratch.BlockType.REPORTER, + text: "screen height", + }, + + "---", + + { + opcode: "isFocused", + blockType: Scratch.BlockType.BOOLEAN, + text: "is window focused?", + }, + + "---", + + { + opcode: "changeTitleTo", + blockType: Scratch.BlockType.COMMAND, + text: "set window title to [TITLE]", + arguments: { + TITLE: { + type: Scratch.ArgumentType.STRING, + defaultValue: "Hello World!", + }, + }, + }, + { + opcode: "windowTitle", + blockType: Scratch.BlockType.REPORTER, + text: "window title", + }, + + "---", + + { + opcode: "enterFullscreen", + blockType: Scratch.BlockType.COMMAND, + text: "enter fullscreen", + }, + { + opcode: "exitFullscreen", + blockType: Scratch.BlockType.COMMAND, + text: "exit fullscreen", + }, + { + opcode: "isFullscreen", + blockType: Scratch.BlockType.BOOLEAN, + text: "is window fullscreen?", + }, + + "---", + + { + opcode: "closeWindow", + blockType: Scratch.BlockType.COMMAND, + isTerminal: true, + text: "close window", + }, + ], + menus: { + MOVE: { + acceptReporters: true, + items: [ + "center", + "right", + "left", + "top", + "bottom", + "top right", + "top left", + "bottom right", + "bottom left", + "random position", + ], + }, + RESIZE: { + acceptReporters: true, + items: [ + "480x360", + "640x480", + "1280x720", + "1920x1080", + "2560x1440", + "2048x1080", + "3840x2160", + "7680x4320", + ], + }, + }, + }; + } + + moveTo(args) { + window.moveTo(args.X, args.Y); + Scratch.vm.runtime.requestRedraw(); + } + moveToPresets(args) { + if (args.PRESETS == "center") { + const left = (screen.width - window.outerWidth) / 2; + const top = (screen.height - window.outerHeight) / 2; + window.moveTo(left, top); + } else if (args.PRESETS == "right") { + const right = screen.width - window.outerWidth; + const top = (screen.height - window.outerHeight) / 2; + window.moveTo(right, top); + } else if (args.PRESETS == "left") { + const top = (screen.height - window.outerHeight) / 2; + window.moveTo(0, top); + } else if (args.PRESETS == "top") { + const left = (screen.width - window.outerWidth) / 2; + window.moveTo(left, 0); + } else if (args.PRESETS == "bottom") { + const left = (screen.width - window.outerWidth) / 2; + const bottom = screen.height - window.outerHeight; + window.moveTo(left, bottom); + } else if (args.PRESETS == "top right") { + const right = screen.width - window.outerWidth; + window.moveTo(right, 0); + } else if (args.PRESETS == "top left") { + window.moveTo(0, 0); + } else if (args.PRESETS == "bottom right") { + const right = screen.width - window.outerWidth; + const bottom = screen.height - window.outerHeight; + window.moveTo(right, bottom); + } else if (args.PRESETS == "bottom left") { + const bottom = screen.height - window.outerHeight; + window.moveTo(0, bottom); + } else if (args.PRESETS == "random position") { + const randomX = getRandomInt(0, screen.width); + const randomY = getRandomInt(0, screen.height); + window.moveTo(randomX, randomY); + } + Scratch.vm.runtime.requestRedraw(); + } + changeX(args) { + window.moveBy(args.X, 0); + Scratch.vm.runtime.requestRedraw(); + } + setX(args) { + const currentY = window.screenY; + window.moveTo(args.X, currentY); + Scratch.vm.runtime.requestRedraw(); + } + changeY(args) { + window.moveBy(0, args.Y); + Scratch.vm.runtime.requestRedraw(); + } + setY(args) { + const currentX = window.screenX; + window.moveTo(currentX, args.Y); + Scratch.vm.runtime.requestRedraw(); + } + windowX() { + return window.screenLeft; + } + windowY() { + return window.screenTop; + } + resizeTo(args) { + window.resizeTo(args.W, args.H); + Scratch.vm.runtime.requestRedraw(); + } + resizeToPresets(args) { + if (args.PRESETS == "480x360") { + window.resizeTo( + 480 + (window.outerWidth - window.innerWidth), + 360 + (window.outerHeight - window.innerHeight) + ); + } else if (args.PRESETS == "640x480") { + window.resizeTo( + 640 + (window.outerWidth - window.innerWidth), + 480 + (window.outerHeight - window.innerHeight) + ); + } else if (args.PRESETS == "1280x720") { + window.resizeTo( + 1280 + (window.outerWidth - window.innerWidth), + 720 + (window.outerHeight - window.innerHeight) + ); + } else if (args.PRESETS == "1920x1080") { + window.resizeTo( + 1920 + (window.outerWidth - window.innerWidth), + 1080 + (window.outerHeight - window.innerHeight) + ); + } else if (args.PRESETS == "2560x1440") { + window.resizeTo( + 2560 + (window.outerWidth - window.innerWidth), + 1440 + (window.outerHeight - window.innerHeight) + ); + } else if (args.PRESETS == "2048x1080") { + window.resizeTo( + 2048 + (window.outerWidth - window.innerWidth), + 1080 + (window.outerHeight - window.innerHeight) + ); + } else if (args.PRESETS == "3840x2160") { + window.resizeTo( + 3840 + (window.outerWidth - window.innerWidth), + 2160 + (window.outerHeight - window.innerHeight) + ); + } else if (args.PRESETS == "7680x4320") { + window.resizeTo( + 7680 + (window.outerWidth - window.innerWidth), + 4320 + (window.outerHeight - window.innerHeight) + ); + } + Scratch.vm.runtime.requestRedraw(); + } + changeW(args) { + window.resizeBy(args.W, 0); + Scratch.vm.runtime.requestRedraw(); + } + setW(args) { + const currentH = window.outerHeight; + window.resizeTo(args.W, currentH); + Scratch.vm.runtime.requestRedraw(); + } + changeH(args) { + window.resizeBy(0, args.H); + Scratch.vm.runtime.requestRedraw(); + } + setH(args) { + const currentW = window.outerWidth; + window.resizeTo(currentW, args.H); + Scratch.vm.runtime.requestRedraw(); + } + matchStageSize() { + window.resizeTo( + Scratch.vm.runtime.stageWidth + (window.outerWidth - window.innerWidth), + Scratch.vm.runtime.stageHeight + + (window.outerHeight - window.innerHeight) + ); + Scratch.vm.runtime.requestRedraw(); + } + windowW() { + return window.outerWidth; + } + windowH() { + return window.outerHeight; + } + isTouchingEdge() { + const edgeX = screen.width - window.outerWidth; + const edgeY = screen.height - window.outerHeight; + return ( + window.screenLeft <= 0 || + window.screenTop <= 0 || + window.screenLeft >= edgeX || + window.screenTop >= edgeY + ); + } + screenW() { + return screen.width; + } + screenH() { + return screen.height; + } + isFocused() { + return document.hasFocus(); + } + changeTitleTo(args) { + document.title = args.TITLE; + } + windowTitle() { + return document.title; + } + enterFullscreen() { + if (document.fullscreenElement == null) { + document.documentElement.requestFullscreen(); + } + } + exitFullscreen() { + if (document.fullscreenElement !== null) { + document.exitFullscreen(); + } + } + isFullscreen() { + return document.fullscreenElement !== null; + } + closeWindow() { + const editorConfirmation = [ + "Are you sure you want to close this window?", + "", + "(This message will not appear when the project is packaged)", + ].join("\n"); + if (typeof ScratchBlocks === "undefined" || confirm(editorConfirmation)) { + window.close(); + } + } + } + Scratch.extensions.register(new WindowControls()); +})(Scratch); diff --git a/extensions/extensions.json b/extensions/extensions.json index 6418f9577d..6d01b2f638 100644 --- a/extensions/extensions.json +++ b/extensions/extensions.json @@ -24,6 +24,7 @@ "Lily/LooksPlus", "Lily/MoreEvents", "NexusKitten/moremotion", + "CubesterYT/WindowControls", "navigator", "battery", "TheShovel/CustomStyles", diff --git a/images/CubesterYT/WindowControls.svg b/images/CubesterYT/WindowControls.svg new file mode 100644 index 0000000000..e3b685bb29 --- /dev/null +++ b/images/CubesterYT/WindowControls.svg @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/images/README.md b/images/README.md index afc04f7ad6..24254c5f0d 100644 --- a/images/README.md +++ b/images/README.md @@ -232,6 +232,10 @@ All images in this folder are licensed under the [GNU General Public License ver ## ZXMushroom63/searchApi.svg - Created by [@CST1229](https://github.com/CST1229) in https://github.com/TurboWarp/extensions/issues/90#issuecomment-1596158611 +## CubesterYT/WindowControls.svg + - Created by [@BlueDome77](https://github.com/BlueDome77) for the Window Controls extension Collaboration + - Dango based on dango from [Twemoji](https://twemoji.twitter.com/) under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). + ## Lily/LooksPlus.svg - Created by [@LilyMakesThings](https://github.com/LilyMakesThings) in https://github.com/TurboWarp/extensions/pull/656