From aa4ba828de5046d38b10ed61e0493b9bbf55e473 Mon Sep 17 00:00:00 2001 From: Simon Edwards Date: Sun, 22 Dec 2024 19:38:18 +0100 Subject: [PATCH] ScrollMap: Paint outdated images instead of nothing before generating maps --- .../ScrollMap/src/ScrollMapExtension.ts | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/extensions/ScrollMap/src/ScrollMapExtension.ts b/extensions/ScrollMap/src/ScrollMapExtension.ts index befe9ac9..3f3a2333 100644 --- a/extensions/ScrollMap/src/ScrollMapExtension.ts +++ b/extensions/ScrollMap/src/ScrollMapExtension.ts @@ -232,9 +232,9 @@ class ScrollMapWidget { let blockRowY = 0; const numberOfBlocks = pixelMap.getNumberOfBlocks(); for (let i=0; i { @@ -303,14 +305,16 @@ class PixelMap { return this.#pixelBlocks.length; } - getQImageAt(blockIndex: number, generateImages: boolean): { qimage: QImage, rows: number} { + getPixelBlockAt(blockIndex: number, generateImages: boolean): PixelBlock { const pixelBlock = this.#pixelBlocks[blockIndex]; - if (generateImages && pixelBlock.qimage == null) { + if (generateImages && pixelBlock.isDirty) { const y = this.#blockIndexToY(blockIndex); const image = this.#createQImage(this.#screen, y, pixelBlock.height); pixelBlock.qimage = image; + pixelBlock.qimageHeight = pixelBlock.height; + pixelBlock.isDirty = false; } - return { qimage: pixelBlock.qimage, rows: pixelBlock.height }; + return pixelBlock; } #blockIndexToY(blockIndex: number): number { @@ -328,7 +332,7 @@ class PixelMap { return Math.ceil((y - blockZeroHeight) / SCROLLMAP_HEIGHT_ROWS); } - #existingRows(): number { + #countMapRows(): number { // The first and last blocks can have variable heights, but the middle blocks are always SCROLLMAP_HEIGHT_ROWS. const pixelBlocksLength = this.#pixelBlocks.length; switch (pixelBlocksLength) { @@ -343,32 +347,36 @@ class PixelMap { } expandBlocks(): void { - const totalScreenRows = this.getScreenHeight(); - let existingRows = this.#existingRows(); + const screenRows = this.getScreenHeight(); + let mapRows = this.#countMapRows(); - if (totalScreenRows !== existingRows && this.#pixelBlocks.length !== 0) { - this.#pixelBlocks.pop(); - existingRows = this.#existingRows(); - } + while (screenRows > mapRows) { + const difference = screenRows - mapRows; - while (totalScreenRows > existingRows) { - const rows = Math.min(totalScreenRows - existingRows, SCROLLMAP_HEIGHT_ROWS); - this.#pixelBlocks.push({ qimage: null, height: rows }); - existingRows += rows; + const lastBlock = this.#pixelBlocks[this.#pixelBlocks.length-1]; + if (lastBlock != null && lastBlock.height !== SCROLLMAP_HEIGHT_ROWS) { + const availableInBlock = SCROLLMAP_HEIGHT_ROWS - lastBlock.height; + const rowsToUse = Math.min(availableInBlock, difference); + lastBlock.height += rowsToUse; + lastBlock.isDirty = true; + mapRows += rowsToUse; + } else { + this.#pixelBlocks.push({ qimage: null, qimageHeight: 0, height: 0, isDirty: true }); + } } - while (totalScreenRows < existingRows) { - const difference = existingRows - totalScreenRows; + while (screenRows < mapRows) { + const difference = mapRows - screenRows; const lastBlock = this.#pixelBlocks[this.#pixelBlocks.length-1]; const lastBlockHeight = lastBlock.height; if (lastBlockHeight <= difference) { this.#pixelBlocks.pop(); - existingRows -= lastBlockHeight; + mapRows -= lastBlockHeight; } else { lastBlock.height -= difference; - lastBlock.qimage = null; - existingRows -= difference; + lastBlock.isDirty = true; + mapRows -= difference; } } } @@ -405,7 +413,7 @@ class PixelMap { const startBlock = this.#yToBlockIndex(startLine); const endBlock = this.#yToBlockIndex(endLine); for (let i=startBlock; i<=endBlock; i++) { - this.#pixelBlocks[i].qimage = null; + this.#pixelBlocks[i].isDirty = true; } } @@ -418,7 +426,7 @@ class PixelMap { remaining -= block.height; } else { block.height -= remaining; - block.qimage = null; + block.isDirty = true; remaining = 0; } }