1
0
Fork 0

Improve bindings between pencil and interface

This commit is contained in:
Starbeamrainbowlabs 2017-06-12 18:15:49 +01:00
parent b043362f29
commit 0808c05f05
3 changed files with 20 additions and 3 deletions

View File

@ -60,6 +60,7 @@ class Chunk
);
}
context.lineCap = "round";
context.lineWidth = line.Width;
context.strokeStyle = line.Colour;
context.stroke();

View File

@ -41,7 +41,7 @@ class Interface extends EventEmitter
setupColourSelectors()
{
this.currentColourElement = this.sidebar.querySelector(".palette .palette-colour[data-selected]");
this.currentColour = this.currentColourElement.style.backgroundColor;
this.switchColourTo(this.currentColourElement);
var colours = this.sidebar.querySelectorAll(".palette .palette-colour");
for (let i = 0; i < colours.length; i++) {
@ -140,7 +140,7 @@ class Interface extends EventEmitter
// Update the brush indicator
this.updateBrushIndicator();
// Emit the brush width change event
this.emit("brushwidthchange", { newWidth: this.currentLineWidth });
this.emit("brushwidthchange", { newWidth: this.currentBrushWidth });
}
updateBrushIndicator()

View File

@ -51,9 +51,25 @@ class Pencil
canvas.addEventListener("mousemove", this.handleMouseMove.bind(this));
canvas.addEventListener("mouseup", this.handleMouseUp.bind(this));
this.boardWindow.interface.on("colourchange", (function(event) {
this.setupInterfaceBindings(this.boardWindow.interface);
}
setupInterfaceBindings(inInterface)
{
// Snag the initial colour from the interface
this.currentColour = inInterface.currentColour;
// Listen for future colour updates
inInterface.on("colourchange", (function(event) {
this.currentColour = event.newColour;
}).bind(this))
// Look up the initial line with in the interface
this.currentLineWidth = inInterface.currentBrushWidth;
// Listen for future updates fromt he interface
inInterface.on("brushwidthchange", (function(event) {
this.currentLineWidth = event.newWidth;
}).bind(this))
}
handleMouseMove(event) {