From 102aafaf6a0993858682fdcb898df33a8d2e3653 Mon Sep 17 00:00:00 2001 From: harsh singh <22je0388@iitism.ac.in> Date: Tue, 9 Apr 2024 16:18:47 +0530 Subject: [PATCH 1/6] gamelife --- activities/GameOfLife.activity/js/Board.js | 48 +++++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/activities/GameOfLife.activity/js/Board.js b/activities/GameOfLife.activity/js/Board.js index 88c2d0e05..efa5b729a 100644 --- a/activities/GameOfLife.activity/js/Board.js +++ b/activities/GameOfLife.activity/js/Board.js @@ -1,17 +1,53 @@ function Board(boardState, lineColor, deadCellColor, trailsColor , aliveYoungCellColor, aliveOldCellColor, cellWidth, cellHeight, rowPadding, colPadding, canvas) { this.showTrails = false; + this.nowY = -1; + this.nowX = -1; this.onClick = function (clickHandler) { var _this = this; + var isMouseDown = false; - canvas.addEventListener('click', function (e) { - var x = e.clientX - canvas.getBoundingClientRect().left; - var y = e.clientY - canvas.getBoundingClientRect().top; - var cellX = Math.floor(x / (_this.cellWidth + 2)); - var cellY = Math.floor(y / (_this.cellHeight + 2)); - clickHandler(cellX, cellY); + // Function to handle drag event + function dragEvent(e) { + if (isMouseDown) { + var x, y; + if (e.type === 'mousemove') { + x = e.clientX - canvas.getBoundingClientRect().left; + y = e.clientY - canvas.getBoundingClientRect().top; + } else if (e.type === 'touchmove') { + x = e.touches[0].clientX - canvas.getBoundingClientRect().left; + y = e.touches[0].clientY - canvas.getBoundingClientRect().top; + } + var cellX = Math.floor(x / (_this.cellWidth + 2)); + var cellY = Math.floor(y / (_this.cellHeight + 2)); + if (_this.nowX !== cellX || _this.nowY !== cellY) { + clickHandler(cellX, cellY); + } + _this.nowX = cellX; + _this.nowY = cellY; + } + } + + canvas.addEventListener('mousedown', function () { + isMouseDown = true; }); + + canvas.addEventListener('touchstart', function () { + isMouseDown = true; + }); + + canvas.addEventListener('mouseup', function () { + isMouseDown = false; + }); + + canvas.addEventListener('touchend', function () { + isMouseDown = false; + }); + + canvas.addEventListener('mousemove', dragEvent); + + canvas.addEventListener('touchmove', dragEvent); }; this.draw = function (state) { From 0774fe4878169a7fae2e63cb1ad9c2d68c6037f4 Mon Sep 17 00:00:00 2001 From: harsh singh <22je0388@iitism.ac.in> Date: Tue, 9 Apr 2024 16:23:04 +0530 Subject: [PATCH 2/6] #1150 --- .vscode/settings.json | 3 +++ activities/GameOfLife.activity/js/Board.js | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..6f3a2913e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/activities/GameOfLife.activity/js/Board.js b/activities/GameOfLife.activity/js/Board.js index efa5b729a..efa8642e0 100644 --- a/activities/GameOfLife.activity/js/Board.js +++ b/activities/GameOfLife.activity/js/Board.js @@ -39,10 +39,14 @@ function Board(boardState, lineColor, deadCellColor, trailsColor , aliveYoungCel canvas.addEventListener('mouseup', function () { isMouseDown = false; + _this.nowX = -1; + _this.nowY = -1 }); canvas.addEventListener('touchend', function () { isMouseDown = false; + _this.nowX = -1; + _this.nowY = -1 }); canvas.addEventListener('mousemove', dragEvent); From cdbaa27330146ca06da96102781d08a96d0dca41 Mon Sep 17 00:00:00 2001 From: harsh singh <22je0388@iitism.ac.in> Date: Tue, 9 Apr 2024 16:24:55 +0530 Subject: [PATCH 3/6] #1150 drag --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 6f3a2913e..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "liveServer.settings.port": 5501 -} \ No newline at end of file From f85d41555614f099265205133a1690d88495a550 Mon Sep 17 00:00:00 2001 From: harsh singh <22je0388@iitism.ac.in> Date: Sat, 13 Apr 2024 03:13:38 +0530 Subject: [PATCH 4/6] added click event as gridpaint --- activities/GameOfLife.activity/js/Board.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/activities/GameOfLife.activity/js/Board.js b/activities/GameOfLife.activity/js/Board.js index efa8642e0..fa99fe135 100644 --- a/activities/GameOfLife.activity/js/Board.js +++ b/activities/GameOfLife.activity/js/Board.js @@ -7,10 +7,12 @@ function Board(boardState, lineColor, deadCellColor, trailsColor , aliveYoungCel this.onClick = function (clickHandler) { var _this = this; var isMouseDown = false; + var isMouseMove = false; // Function to handle drag event function dragEvent(e) { if (isMouseDown) { + isMouseMove = true; var x, y; if (e.type === 'mousemove') { x = e.clientX - canvas.getBoundingClientRect().left; @@ -52,6 +54,17 @@ function Board(boardState, lineColor, deadCellColor, trailsColor , aliveYoungCel canvas.addEventListener('mousemove', dragEvent); canvas.addEventListener('touchmove', dragEvent); + + canvas.addEventListener('click', function (e) { + if(isMouseMove) { + isMouseMove = false; return; + } + var x = e.clientX - canvas.getBoundingClientRect().left; + var y = e.clientY - canvas.getBoundingClientRect().top; + var cellX = Math.floor(x / (_this.cellWidth + 2)); + var cellY = Math.floor(y / (_this.cellHeight + 2)); + clickHandler(cellX, cellY); + }); }; this.draw = function (state) { From f0f0a8f399c798ff2d510ffd0b9507e75e0ab1cf Mon Sep 17 00:00:00 2001 From: harsh singh <22je0388@iitism.ac.in> Date: Sat, 13 Apr 2024 03:41:10 +0530 Subject: [PATCH 5/6] fixed a minor bug #1150 --- activities/GameOfLife.activity/js/Board.js | 1 + 1 file changed, 1 insertion(+) diff --git a/activities/GameOfLife.activity/js/Board.js b/activities/GameOfLife.activity/js/Board.js index fa99fe135..a308c1d67 100644 --- a/activities/GameOfLife.activity/js/Board.js +++ b/activities/GameOfLife.activity/js/Board.js @@ -47,6 +47,7 @@ function Board(boardState, lineColor, deadCellColor, trailsColor , aliveYoungCel canvas.addEventListener('touchend', function () { isMouseDown = false; + isMouseMove = false; _this.nowX = -1; _this.nowY = -1 }); From 4aee51fe71d1a9a191dd37a901eb232632a864a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lionel=20Lask=C3=A9?= Date: Sat, 20 Apr 2024 21:30:00 +0200 Subject: [PATCH 6/6] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51a99ce84..2ad23b2b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Fixed - Images go under each other while editing in Fototoon #1552 - +- Adding Drag to fill Cells Functionality in Game of Life #1150 + ## [1.8.0] - 2024-04-10 ### Added - Chart Activity