2d-color-picker: code editor support and other improvements by mxmou · Pull Request #9161 · ScratchAddons/ScratchAddons · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion addons/2d-color-picker/addon.json
Binary file removed addons/2d-color-picker/assets/sv-gr.png
Binary file not shown.
15 changes: 15 additions & 0 deletions addons/2d-color-picker/assets/sv-gradient.svg

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This SVG file is intentionally not minified - it contains a comment explaining how I calculated the offsets for gradient stops.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions addons/2d-color-picker/code-editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import ShadePicker from "./shade-picker.js";

export default async function ({ addon, console, msg }) {
const Blockly = await addon.tab.traps.getBlockly();

const oldShowEditor = Blockly.FieldColourSlider.prototype.showEditor_;
Blockly.FieldColourSlider.prototype.showEditor_ = function (...args) {
oldShowEditor.call(this, ...args);

this.saShadePicker = new ShadePicker(addon, msg, { roundMethod: Math.floor });
const [shadeSlider, shadeLabel] = this.saShadePicker.createElements({
h: this.hue_,
s: this.saturation_,
v: this.brightness_ / 255,
});
this.saShadePicker.addEventListener("change", (e) => {
const { s, v } = e.detail;
this.saturation_ = s;
this.brightness_ = 255 * v;
this.setValue(Blockly.utils.colour.hsvToHex(this.hue_, this.saturation_, this.brightness_), true);
});

this.saturationSlider_.classList.add("sa-2dcolor-hidden");
this.saturationSlider_.previousSibling.classList.add("sa-2dcolor-hidden");
this.brightnessSlider_.classList.add("sa-2dcolor-hidden");
this.brightnessSlider_.previousSibling.classList.add("sa-2dcolor-hidden");
this.hueSlider_.insertAdjacentElement("afterend", shadeSlider);
this.hueSlider_.insertAdjacentElement("afterend", shadeLabel);
};

const oldUpdateDom = Blockly.FieldColourSlider.prototype.updateDom_;
Blockly.FieldColourSlider.prototype.updateDom_ = function (...args) {
oldUpdateDom.call(this, ...args);
if (this.saShadePicker) {
this.saShadePicker.setColor({
h: this.hue_,
s: this.saturation_,
v: this.brightness_ / 255,
});
}
};
}
258 changes: 36 additions & 222 deletions addons/2d-color-picker/paint-editor.js
Loading
Loading