Normal/palette mode indicator

This commit is contained in:
SoniEx2 2019-02-12 21:43:15 -02:00
parent b2681f9f5d
commit 2a32cde49e
1 changed files with 37 additions and 26 deletions

View File

@ -126,8 +126,44 @@ end
local in_mouse = false
local function palette()
-- Called to enable/disable palette editing mode
paletting = not paletting
imagedata, palettedata = palettedata, imagedata
imgt, imgpalt = imgpalt, imgt
PAL_MAX = paletting and 255 or 15
if paletting then
for i=0,255 do
palt[i] = i*0x01010100 + 0xff
end
else
for i=0,15 do
local r = imgpalt[i*16+1]
local g = imgpalt[i*16+2]
local b = imgpalt[i*16+3]
local a = imgpalt[i*16+4]
palt[i] = ((r*256+g)*256+b)*256+a
end
end
for i=1,256 do
markupdated(i, false)
end
image:replacePixels(imagedata)
end
function love.mousepressed(x, y, button, istouch, presses)
if button == 1 then
local rawx, rawy = x, y
local x, y = math.floor(x / 36), math.floor(y / 36)
if x > 15 or y > 15 then
if rawx > 576 then
-- TODO replace with more efficient graphics
if rawy > 130 and rawy <= 130 + love.graphics.getFont():getHeight() then
palette()
end
end
return
end
if visual_start then
for i=math.min(visual_start or cp, cp), math.max(visual_start or cp, cp) do
setback(i, false)
@ -136,8 +172,6 @@ function love.mousepressed(x, y, button, istouch, presses)
else
setback(cp, false)
end
local x, y = math.floor(x / 36), math.floor(y / 36)
if x > 15 or y > 15 then return end
cp = y * 16 + x + 1
setback(cp, true)
backimage:replacePixels(backimagedata)
@ -296,30 +330,6 @@ function love.update(dt)
local name = love.data.encode("string", "hex", love.data.hash("sha1", data):sub(1, 7)) .. ".png"
love.filesystem.write("img-" .. name, data)
end
local function palette()
-- Called to enable/disable palette editing mode
paletting = not paletting
imagedata, palettedata = palettedata, imagedata
imgt, imgpalt = imgpalt, imgt
PAL_MAX = paletting and 255 or 15
if paletting then
for i=0,255 do
palt[i] = i*0x01010100 + 0xff
end
else
for i=0,15 do
local r = imgpalt[i*16+1]
local g = imgpalt[i*16+2]
local b = imgpalt[i*16+3]
local a = imgpalt[i*16+4]
palt[i] = ((r*256+g)*256+b)*256+a
end
end
for i=1,256 do
markupdated(i, false)
end
image:replacePixels(imagedata)
end
local function visual()
if visual_start then
for i=math.min(visual_start or cp, cp), math.max(visual_start or cp, cp) do
@ -399,6 +409,7 @@ function love.draw()
love.graphics.draw(backimage, backquad, 0, 0, 0, mul)
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.print(paletting and "palette" or "normal", 576, 130)
love.graphics.draw(batch, 2, 2)
end