diff --git a/README.md b/README.md index 180162b..b6848eb 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ To be decided, but at this moment this code is open source and free to use for n ## Changelog +### 0.4.3 + +* There is now multi-selection, including movement, deleting, disconnecting, etc. + ### 0.4.2 * Added Hex keypad with 4 bit output, also has 3 function keys diff --git a/js/baseclasses.js b/js/baseclasses.js index 988224c..9c9b0eb 100644 --- a/js/baseclasses.js +++ b/js/baseclasses.js @@ -80,6 +80,15 @@ class elementContainer { this.ICOutputs = 0; } + isSelected(element) { + if (this.Selected) { + for (let a = 0; a < this.Selected.length; a++) { + if (this.Selected[a] == element) return true; + } + } + return false; + } + isHigh(element,input) { let isHigh = false; for (let a = 0; a < this.Elements.length; a++) { @@ -121,15 +130,30 @@ class elementContainer { } DeleteElement(element) { - // Can pass object or Designator - for (let a = 0; a < this.Elements.length; a++) { - if ((this.Elements[a] == element) || (this.Elements[a].Designator == element)) { - this.Elements[a].Delete(); - this.Elements.splice(a,1); - return true; + // Can pass object or Designator, or array + if (Array.isArray(element)) { + let returnval = false; + for (let a = 0; a < element.length; a++) { + for (let b = 0; b < this.Elements.length; b++) { + if ((this.Elements[b] == element[a]) || (this.Elements[b].Designator == element[a])) { + this.Elements[b].Delete(); + this.Elements.splice(b, 1); + b--; + returnval = true; + } + } } + return returnval; + } else { + for (let a = 0; a < this.Elements.length; a++) { + if ((this.Elements[a] == element) || (this.Elements[a].Designator == element)) { + this.Elements[a].Delete(); + this.Elements.splice(a, 1); + return true; + } + } + return false; } - return false; } HasElement(element) { @@ -144,8 +168,17 @@ class elementContainer { Disconnect(element) { if (!element) return false; - for (let a = 0; a < this.Elements.length; a++) { - this.Elements[a].Disconnect(element); + + if (Array.isArray(element)) { + for (let a = 0; a < this.Elements.length; a++) { + for (let b = 0; b < element.length; b++) { + this.Elements[a].Disconnect(element[b]); + } + } + } else { + for (let a = 0; a < this.Elements.length; a++) { + this.Elements[a].Disconnect(element); + } } } @@ -163,7 +196,7 @@ class elementContainer { if (this.Elements[a] instanceof ICOutput) ICOuts++; if (this.Elements[a].isVisible()) { ctx.save(); - if (this.Elements[a] == this.Selected) this.Elements[a].drawBorderBox(ctx, this.Elements[a].X - 2, this.Elements[a].Y - 2, this.Elements[a].Width + 4, this.Elements[a].Height + 4, 1, "rgba(100,200,255,0.25)", "rgba(100,200,255,0.25)"); + if (this.isSelected(this.Elements[a])) this.Elements[a].drawBorderBox(ctx, this.Elements[a].X - 2, this.Elements[a].Y - 2, this.Elements[a].Width + 4, this.Elements[a].Height + 4, 1, "rgba(100,200,255,0.25)", "rgba(100,200,255,0.25)"); this.Elements[a].drawElement(this.Elements[a].X, this.Elements[a].Y, ctx); ctx.restore(); } @@ -171,8 +204,10 @@ class elementContainer { this.ICOutputs = ICOuts; if (!this.Selected) { - let PropertiesBox = document.getElementById("PropertiesBox"); - if (PropertiesBox.style.display != "none") PropertiesBox.style.display = "none"; + if (this.Selected.length == 1) { + let PropertiesBox = document.getElementById("PropertiesBox"); + if (PropertiesBox.style.display != "none") PropertiesBox.style.display = "none"; + } } if (logicEngine.Settings.TopConnections && !logicEngine.Settings.HideConnections) { @@ -184,29 +219,37 @@ class elementContainer { } + SelectWithin(x1,y1,x2,y2) { + let selectedArray = new Array(); + for (let a = 0; a < this.Elements.length; a++) { + if ((this.Elements[a].X >= x1) && ((this.Elements[a].X + this.Elements[a].Width) <= x2) && (this.Elements[a].Y >= y1) && ((this.Elements[a].Y + this.Elements[a].Height) <= y2)) selectedArray.push(this.Elements[a]); + } + this.Selected = selectedArray; + } + Select(element) { - this.Selected = element; + this.Selected = new Array(element); let PropertiesBox = document.getElementById("PropertiesBox"); let PropertiesBoxTitle = document.getElementById("PropertiesBoxTitle"); let PropertiesBoxContent = document.getElementById("PropertiesBoxContent"); - PropertiesBoxTitle.innerText = this.Selected.Designator + " Properties"; + PropertiesBoxTitle.innerText = this.Selected[0].Designator + " Properties"; let contentString = "
" + this.Selected.Properties[a].Name + " | "; - switch (this.Selected.Properties[a].Type) { + for (let a = 0; a < this.Selected[0].Properties.length;a++) { + contentString += " |
" + this.Selected[0].Properties[a].Name + " | "; + switch (this.Selected[0].Properties[a].Type) { case "int": - contentString += ""; + contentString += ""; break; case "string": - contentString += ''; + contentString += ''; break; case "color": - contentString += ''; + contentString += ''; break; case "list": - contentString += ' |