Normal/palette mode indicator
This commit is contained in:
parent
b2681f9f5d
commit
2a32cde49e
63
main.lua
63
main.lua
|
@ -126,8 +126,44 @@ end
|
||||||
|
|
||||||
local in_mouse = false
|
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)
|
function love.mousepressed(x, y, button, istouch, presses)
|
||||||
if button == 1 then
|
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
|
if visual_start then
|
||||||
for i=math.min(visual_start or cp, cp), math.max(visual_start or cp, cp) do
|
for i=math.min(visual_start or cp, cp), math.max(visual_start or cp, cp) do
|
||||||
setback(i, false)
|
setback(i, false)
|
||||||
|
@ -136,8 +172,6 @@ function love.mousepressed(x, y, button, istouch, presses)
|
||||||
else
|
else
|
||||||
setback(cp, false)
|
setback(cp, false)
|
||||||
end
|
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
|
cp = y * 16 + x + 1
|
||||||
setback(cp, true)
|
setback(cp, true)
|
||||||
backimage:replacePixels(backimagedata)
|
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"
|
local name = love.data.encode("string", "hex", love.data.hash("sha1", data):sub(1, 7)) .. ".png"
|
||||||
love.filesystem.write("img-" .. name, data)
|
love.filesystem.write("img-" .. name, data)
|
||||||
end
|
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()
|
local function visual()
|
||||||
if visual_start then
|
if visual_start then
|
||||||
for i=math.min(visual_start or cp, cp), math.max(visual_start or cp, cp) do
|
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)
|
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)
|
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((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)
|
love.graphics.draw(batch, 2, 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue