- [NEW] mouse.inside(x,y,w,h)

- [WIP] fonted tool
This commit is contained in:
2025-12-09 14:05:12 +01:00
parent eac20bbbe0
commit 6e15fe7231
6 changed files with 232 additions and 126 deletions

View File

@@ -1,138 +1,68 @@
function loadDir(path)
files = sys.dir(path)
if #files > 0 then
dir = files[1].name:match("(.+)/[^/]+$")
else
dir = path
end
table.insert(files, 1, { dir=true, name=".." })
selected = 0
offset = 0
lift_height=-1
lift_top=0
if #files>23 then
lift_height=23*161/#files
end
end
require "ui"
function goBack()
dir = dir:match("(.+)/[^/]+$")
loadDir(dir)
end
update = nil
protofont_surface = nil
function mini.init()
surf.cls(0)
folder = surf.new(5,4)
surf.target(folder)
for i=0,4 do for j=0,3 do surf.pixel(i,j,0) end end
for i=2,4 do surf.pixel(i,0,255) end
surf.target(0)
loadDir(".")
update = any_update
ui.filedialog.show(select_file);
end
function select_file(filename)
if protofont_surface then surf.free(protofont_surface) end
protofont_surface = surf.loadex(filename)
end
function mini.update()
local mx,my=mouse.pos()
view.origin(0,0)
for i=0,15 do
draw.rectf(i*8, 0, 8, 8, i)
end
pal.trans(255)
view.origin(20, 20)
draw.rrectf(0,0,280,200,3,15)
draw.rrectf(4,4,272,9,2,12)
draw.rrectf(4,17,272,163,2,12)
if lift_height>0 then draw.rrectf(271,18+lift_top,4,lift_height,2,14) end
draw.rrectf(192,185,40,11,2,9)
draw.rrectf(192,184,40,11,2,10)
draw.text("OK",209,187,9)
draw.rrectf(236,185,40,11,2,1)
draw.rrectf(236,184,40,11,2,2)
draw.text("CANCEL",245,187,1)
local y = 19
draw.text(dir, 6, 6, 0)
surf.source(folder)
-- if mx>4 and mx<268 and my>=y-1 and my<y+6 then
-- draw.rectf(4,y-1,272,7,13)
-- if mouse.dblclick() then
-- goBack();
-- end
-- end
-- draw.surf(0,0,5,4,7,y+1,5,4)
-- pal.subpal(0,3)
-- draw.surf(0,0,5,4,6,y,5,4)
-- pal.subpal(0)
-- draw.text("..", 13, y, 0) y=y+7
local count = 0
for k,file in ipairs(files) do
local filename = file.name:match("([^/]+)$")
if count < offset then goto continue end
--if v:match("%.gif$") then
if mx>4 and mx<268 and my>=y-1 and my<y+6 then
draw.rectf(4,y-1,272,7,13)
if mouse.dblclick() then
if file.dir then
if k==1 then
goBack()
else
loadDir(dir.."/"..filename)
end
else
--selected = k
end
elseif mouse.press(mouse.LEFT) then
selected = k
end
end
if selected == k then
draw.rectf(4,y-1,272,7,10)
end
if file.dir then
draw.surf(0,0,5,4,7,y+1,5,4)
pal.subpal(0,3)
draw.surf(0,0,5,4,6,y,5,4)
pal.subpal(0)
draw.text(filename, 13, y, 0)
else
draw.text(filename, 6, y, 0)
end
y=y+7
::continue::
count=count+1
if count-offset>=23 then break end
end
if key.press(key.RETURN) and selected~=-1 then
if files[selected].dir then
local filename = files[selected].name:match("([^/]+)$")
loadDir(dir.."/"..filename)
else
-- do nothing for now
end
elseif key.press(key.DOWN) and selected<#files then
selected=selected+1
elseif key.press(key.UP) then
if selected>1 then
selected=selected-1
else
selected = 1
end
end
local scroll = -mouse.wheel()
if scroll~=0 then
offset=offset+scroll
if offset<0 then offset=0 end
if offset+23 > #files then offset = #files-23 end
lift_top=offset*161/#files
end
update()
end
function any_update()
surf.cls(0)
view.origin(4,4)
draw.rrectf(0,0,136,132,3,15)
if protofont_surface then
local w,h = surf.size(protofont_surface)
local x,y = (136-w)/2,(132-h)/2
surf.source(protofont_surface)
draw.surf(0,0,w,h,x,y,w,h)
draw.text(tostring(w)..","..tostring(h), 10, 100, 3)
end
view.origin(4,140)
draw.rrectf(0,0,136,68,3,15)
view.origin(8,144)
local x,y=0,0
for c=32,127 do
draw.rectf(x,y,7,9,12)
draw.rect(x,y,7,9,0)
draw.text(string.char(c),x+2,y+2,0)
x=x+8
if x>=128 then
x=0
y=y+10
end
end
draw.text("ÁÄÉÍÓÚáéíóúÀÈÌÒÙàèìòùñÑçÇ", x, y+8, 12)
view.origin(144,4)
draw.rrectf(0,0,21,12,3,14)
draw.text("BASE",3,2,12)
draw.rrectf(22,0,45,12,3,15)
draw.text("DIACRITICS",25,2,0)
-- acute(Á), grave(À); diaeresis(Ä), circumflex(Â); cedilla(Ç), tilde(Ñ)
draw.rrectf(68,0,49,12,3,15)
draw.text("PRECOMPOSED",71,2,0)
draw.rrectf(0,8,140,140,3,14)
end