summary refs log tree commit diff stats
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua24
1 files changed, 21 insertions, 3 deletions
diff --git a/main.lua b/main.lua
index be4982e..1a599be 100644
--- a/main.lua
+++ b/main.lua
@@ -142,7 +142,7 @@ function love.update(dt)
   local function decr()
     saved = nil
     local amt = (kt['lshift'] and 16 or 1)
-    for i=visual_start or cp, cp do
+    for i=math.min(visual_start or cp, cp), math.max(visual_start or cp, cp) do
       imgt[i] = math.max(imgt[i] - amt, 0)
       markupdated(i, true)
     end
@@ -150,7 +150,7 @@ function love.update(dt)
   local function incr()
     saved = nil
     local amt = (kt['lshift'] and 16 or 1)
-    for i=visual_start or cp, cp do
+    for i=math.min(visual_start or cp, cp), math.max(visual_start or cp, cp) do
       imgt[i] = math.min(imgt[i] + amt, PAL_MAX)
       markupdated(i, true)
     end
@@ -267,6 +267,13 @@ function love.update(dt)
   end
   local function visual()
     visual_start = not visual_start and cp
+    if not visual_start then
+      for i=1,255 do
+        setback(i, false)
+      end
+      setback(cp, true)
+      backimage:replacePixels(backimagedata)
+    end
   end
   ktup('i', imgup)
   ktup('up', imgup)
@@ -283,6 +290,16 @@ function love.update(dt)
   ktup('w', save)
   ktup('p', palette)
   ktup('v', visual)
+  if visual_start then
+    -- TODO optimize visual mode
+    for i=1,255 do
+      setback(i, false)
+    end
+    for i=math.min(visual_start, cp), math.max(visual_start, cp) do
+      setback(i, true)
+    end
+    backimage:replacePixels(backimagedata)
+  end
 end
 
 local quad
@@ -325,7 +342,8 @@ end
 function love.draw()
   love.graphics.draw(image, quad, 576, 0, 0, 8)
   love.graphics.draw(backimage, backquad, 0, 0, 0, mul)
-  love.graphics.print((visual_start and tostring(visual_start) .. ":" or "") .. tostring(cp), 0, 588)
+  local min, max = math.min(visual_start or cp, cp), math.max(visual_start or cp, cp)
+  love.graphics.print((visual_start and tostring(min) .. ":" or "") .. tostring(max), 0, 588)
   love.graphics.draw(batch, 2, 2)
 end