From be94e01badde95e3f6544b54f7efad2cae3c92f4 Mon Sep 17 00:00:00 2001 From: Adrien Burgun Date: Tue, 16 Aug 2022 18:52:19 +0200 Subject: [PATCH] :chart: Optimize draw() --- editor/index.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/editor/index.js b/editor/index.js index 1054a5f..0ed46fd 100644 --- a/editor/index.js +++ b/editor/index.js @@ -96,10 +96,10 @@ function draw() { let index = 3 * (width * (y - from_y) + x - from_x); let ch = String.fromCharCode(chars[index]); - let fg = to_color(chars[index + 1]); - let bg = chars[index + 2] === 0 ? null : to_color(chars[index + 2]); - if (ch !== " ") { + let fg = to_color(chars[index + 1]); + let bg = chars[index + 2] === 0 ? null : to_color(chars[index + 2]); + if (bg) { ctx.fillStyle = `rgba(${bg.join(",")})`; ctx.fillRect( @@ -126,13 +126,16 @@ function draw() { } } - ctx.fillStyle = inside ? "#606060" : "#404040"; - ctx.fillRect( - Math.round(x2 + tile_size / 2) - zoom_factor, - Math.round(y2 + tile_size / 2) - zoom_factor, - Math.max(zoom_factor, 2.0), - Math.max(zoom_factor, 2.0) - ); + if (inside || width < 100 && height < 100) { + ctx.fillStyle = inside ? "#505050" : "#303030"; + + ctx.fillRect( + Math.round(x2 + tile_size / 2) - zoom_factor, + Math.round(y2 + tile_size / 2) - zoom_factor, + zoom_factor, + zoom_factor + ); + } } } }