From 004a6947418aa1766592c22c39030750f4e0230f Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 17 Mar 2016 11:25:37 +1300 Subject: [PATCH] Make toolbar buttons "click" --- examples/libraries/toolBars.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/examples/libraries/toolBars.js b/examples/libraries/toolBars.js index fddf854462..73c150e107 100644 --- a/examples/libraries/toolBars.js +++ b/examples/libraries/toolBars.js @@ -110,12 +110,25 @@ Tool = function(properties, selectable, selected) { // selectable and selected a } this.select(selected); - + + this.isButtonDown = false; + this.buttonDown = function (down) { + if (down !== this.isButtonDown) { + properties.subImage.y = (down ? 0 : 1) * properties.subImage.height; + Overlays.editOverlay(this.overlay(), { subImage: properties.subImage }); + this.isButtonDown = down; + } + } + this.baseClicked = this.clicked; this.clicked = function(clickedOverlay, update) { if (this.baseClicked(clickedOverlay)) { - if (selectable && update) { - this.toggle(); + if (update) { + if (selectable) { + this.toggle(); + } else { + this.buttonDown(true); + } } return true; } @@ -376,6 +389,11 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit that.mightBeDragging = false; } }; + this.mouseReleaseEvent = function (event) { + for (var tool in that.tools) { + that.tools[tool].buttonDown(false); + } + } this.mouseMove = function (event) { if (!that.mightBeDragging || !event.isLeftButton) { that.mightBeDragging = false; @@ -399,6 +417,7 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit } }; Controller.mousePressEvent.connect(this.mousePressEvent); + Controller.mouseReleaseEvent.connect(this.mouseReleaseEvent); Controller.mouseMoveEvent.connect(this.mouseMove); Script.update.connect(that.checkResize); // This compatability hack breaks the model, but makes converting existing scripts easier: