diff --git a/README.md b/README.md index e9c5677..4f0d2d7 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,11 @@ To be decided, but at this moment this code is open source and free to use for n ## Changelog +### 0.3.9 + +* Added grid alignment, hold CTRL key while moving to get pixel level positioning. +* Fixed property restoration issue with labels on loading a save + ### 0.3.8 * Added labels! You can specify the text, size, and color diff --git a/js/elements.js b/js/elements.js index 511d739..6204eb8 100644 --- a/js/elements.js +++ b/js/elements.js @@ -415,8 +415,11 @@ class LabelElement extends Element { if (RestoreData) { this.Label = RestoreData.Properties[0].CurrentValue; + this.Properties[0].CurrentValue = this.Label; this.Font = RestoreData.Properties[1].CurrentValue + "px Console"; + this.Properties[1].CurrentValue = RestoreData.Properties[1].CurrentValue; this.FontStyle = RestoreData.Properties[2].CurrentValue; + this.Properties[2].CurrentValue = this.FontStyle; } let textWidth = this.textSize(logicengine.Ctx,this.Label,this.Font); diff --git a/js/globalfunctions.js b/js/globalfunctions.js index fc704ce..b83de13 100644 --- a/js/globalfunctions.js +++ b/js/globalfunctions.js @@ -4,6 +4,8 @@ function addElement(RestoreData = null,refClass,props) { if (!RestoreData) { let x = Math.round(logicEngine.Canvas.width / 2); let y = Math.round(logicEngine.Canvas.height / 2); + x = 20 * Math.round(x/20); + y = 20 * Math.round(y/20); let width = newElement.Width; let height = newElement.Height; @@ -18,6 +20,9 @@ function addElement(RestoreData = null,refClass,props) { if (y < 0) y = 0; if (x + width > logicEngine.Canvas.width) x = logicEngine.Canvas.width - width; if (y + height > logicEngine.Canvas.height) y = logicEngine.Canvas.height - height; + x = 20 * Math.round(x/20); + y = 20 * Math.round(y/20); + } } newElement.X = x; diff --git a/js/logicengine.js b/js/logicengine.js index 73f33a5..61a96e5 100644 --- a/js/logicengine.js +++ b/js/logicengine.js @@ -95,8 +95,12 @@ class LogicEngine { let yOffset = mousePos.y - this.MovingElementMouseStartY; let diffxOffset = this.MovingElementMouseStartX - this.MovingElementStartX; let diffyOffset = this.MovingElementMouseStartY - this.MovingElementStartY; - this.MovingElement.X = (this.MovingElementMouseStartX + xOffset) - diffxOffset; - this.MovingElement.Y = (this.MovingElementMouseStartY + yOffset) - diffyOffset; + let actualPosX = (this.MovingElementMouseStartX + xOffset) - diffxOffset; + let actualPosY = (this.MovingElementMouseStartY + yOffset) - diffyOffset; + if (!this.ControlPressed) actualPosX = Math.round(actualPosX/20)*20; + if (!this.ControlPressed) actualPosY = Math.round(actualPosY/20)*20; + this.MovingElement.X = actualPosX; + this.MovingElement.Y = actualPosY; } } } else { @@ -104,7 +108,18 @@ class LogicEngine { } } + + Key_Up(evt) { + if (!evt.ctrlKey) { + this.ControlPressed = false; + } + } + Key_Press(evt) { + if (evt.ctrlKey) { + this.ControlPressed = true; + } + if (evt.key == "Escape") { if (this.MovingElement && this.MouseDown) { this.MovingElement.X = this.MovingElementStartX; @@ -145,6 +160,7 @@ class LogicEngine { this.RecursionCount = 0; this.RecursionError = false; this.Canvas.setAttribute('tabindex','0'); + this.ControlPressed = false; } diff --git a/js/main.js b/js/main.js index f530191..9a7e430 100644 --- a/js/main.js +++ b/js/main.js @@ -2,7 +2,7 @@ MatCat BrowserLogic Simulator */ -let Version = "0.3.8"; +let Version = "0.3.9"; let spanVersion = document.getElementById("version"); spanVersion.innerText = Version; // get the canvas and get the engine object going @@ -21,6 +21,11 @@ window.addEventListener('keydown', function(evt) { logicEngine.Key_Press(evt); }, false); +window.addEventListener('keyup', function(evt) { + logicEngine.Key_Up(evt); +}, false); + + lCanvasElement.addEventListener('mousedown', function(evt) { logicEngine.Mouse_Down(evt); }, false);