1
0
Fork 0
mirror of https://github.com/sbrl/Nibriboard.git synced 2018-01-10 21:33:49 +00:00

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.lineWidth = line.Width;
context.strokeStyle = line.Colour; context.strokeStyle = line.Colour;
context.stroke(); context.stroke();

View file

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

View file

@ -51,9 +51,25 @@ class Pencil
canvas.addEventListener("mousemove", this.handleMouseMove.bind(this)); canvas.addEventListener("mousemove", this.handleMouseMove.bind(this));
canvas.addEventListener("mouseup", this.handleMouseUp.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; this.currentColour = event.newColour;
}).bind(this)) }).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) { handleMouseMove(event) {