-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmy-script.lua
More file actions
51 lines (46 loc) · 999 Bytes
/
my-script.lua
File metadata and controls
51 lines (46 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function init(plugin)
pix_count_dialog = Dialog("pix sel")
pix_count_dialog
:label {
id = "pix count label",
title = "pix count",
text = "?"
}
:button {
id = "pix_recount",
text = "Recount",
onclick = updatePixCount
}
plugin:newCommand {
id = "PixCount",
title = "Show pix count",
group = "select_simple",
onclick = function()
pix_count_dialog:show { wait = false }
updatePixCount()
end
}
end
function updatePixCount()
local sel = count(app.sprite.selection)
pix_count_dialog:modify {
id = "pix count label",
title = "pix count",
text = sel
}
end
function count(sel)
local count = 0
local bounds = sel.bounds
for x = bounds.x, bounds.x + bounds.width do
for y = bounds.y, bounds.y + bounds.height do
if sel:contains(x, y) then
count = count + 1
end
end
end
return count
end
function exit(plugin)
pix_count_dialog:close()
end