mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2026-01-06 11:12:40 +01:00
У-у-у-у-у, растеризация-хуяция
This commit is contained in:
parent
ce5ec5fda8
commit
b76d5eb768
@ -103,9 +103,9 @@ end
|
||||
|
||||
local currentToolTitle = addTitle(mainContainer.sidebarLayout, "Tool properties")
|
||||
|
||||
mainContainer.currentToolLayout = mainContainer.sidebarLayout:addChild(GUI.layout(1, 1, mainContainer.sidebarLayout.width - 2, 1, 1, 1))
|
||||
mainContainer.currentToolLayout = mainContainer.sidebarLayout:addChild(GUI.layout(1, 1, mainContainer.sidebarLayout.width, 1, 1, 1))
|
||||
mainContainer.currentToolLayout:setCellAlignment(1, 1, GUI.alignment.horizontal.center, GUI.alignment.vertical.top)
|
||||
mainContainer.currentToolLayout:setCellFitting(1, 1, true, false)
|
||||
mainContainer.currentToolLayout:setCellFitting(1, 1, true, false, 2, 0)
|
||||
|
||||
local aboutToolTitle = addTitle(mainContainer.sidebarLayout, "About tool")
|
||||
local aboutToolTextBox = mainContainer.sidebarLayout:addChild(GUI.textBox(1, 1, mainContainer.sidebarLayout.width - 2, 1, nil, 0x787878, {}, 1, 0, 0))
|
||||
@ -123,6 +123,7 @@ local function pressToolButton(button)
|
||||
mainContainer.toolsLayout.children[i].pressed = mainContainer.toolsLayout.children[i] == button
|
||||
end
|
||||
|
||||
mainContainer.currentToolOverlay:deleteChildren()
|
||||
mainContainer.currentToolLayout:deleteChildren()
|
||||
|
||||
currentToolTitle.hidden = not button.tool.onSelection
|
||||
@ -446,6 +447,8 @@ mainContainer.menu:addItem("Hotkeys").onTouch = function()
|
||||
mainContainer:drawOnScreen()
|
||||
end
|
||||
|
||||
mainContainer.currentToolOverlay = mainContainer:addChild(GUI.container(1, 1, mainContainer.width, mainContainer.height))
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
mainContainer.image:moveToBack()
|
||||
|
||||
@ -10,100 +10,130 @@ tool.shortcut = "Se"
|
||||
tool.keyCode = 50
|
||||
tool.about = "Selection tool allows you select preferred zone on image and perform some operations on it. For example, to crop, to fill, to clear and to outline in via selected primary color"
|
||||
|
||||
local xOld, yOld, selector
|
||||
local selector, touchX, touchY, dragX, dragY = GUI.object(1, 1, 1, 1)
|
||||
|
||||
local fillButton = GUI.roundedButton(1, 1, 36, 1, 0xE1E1E1, 0x2D2D2D, 0x2D2D2D, 0xE1E1E1, "Fill")
|
||||
local clearButton = GUI.roundedButton(1, 1, 36, 1, 0xE1E1E1, 0x2D2D2D, 0x2D2D2D, 0xE1E1E1, "Clear")
|
||||
local outlineButton = GUI.roundedButton(1, 1, 36, 1, 0xE1E1E1, 0x2D2D2D, 0x2D2D2D, 0xE1E1E1, "Outline")
|
||||
local rasterizeLineButton = GUI.roundedButton(1, 1, 36, 1, 0xE1E1E1, 0x2D2D2D, 0x2D2D2D, 0xE1E1E1, "Rasterize line")
|
||||
local cropButton = GUI.roundedButton(1, 1, 36, 1, 0x696969, 0xE1E1E1, 0x2D2D2D, 0xE1E1E1, "Crop")
|
||||
|
||||
local function repositionSelector(mainContainer)
|
||||
if dragX - touchX >= 0 then
|
||||
selector.localX, selector.width = touchX, dragX - touchX + 1
|
||||
else
|
||||
selector.localX, selector.width = dragX, touchX - dragX + 1
|
||||
end
|
||||
|
||||
if dragY - touchY >= 0 then
|
||||
selector.localY, selector.height = touchY, dragY - touchY + 1
|
||||
else
|
||||
selector.localY, selector.height = dragY, touchY - dragY + 1
|
||||
end
|
||||
|
||||
mainContainer:drawOnScreen()
|
||||
end
|
||||
|
||||
tool.onSelection = function(mainContainer)
|
||||
mainContainer.currentToolLayout:addChild(fillButton).onTouch = function()
|
||||
for j = selector.y, selector.y + selector.height - 1 do
|
||||
for i = selector.x, selector.x + selector.width - 1 do
|
||||
image.set(mainContainer.image.data, i - mainContainer.image.x + 1, j - mainContainer.image.y + 1, mainContainer.primaryColorSelector.color, 0x0, 0, " ")
|
||||
end
|
||||
end
|
||||
|
||||
mainContainer:drawOnScreen()
|
||||
end
|
||||
|
||||
mainContainer.currentToolLayout:addChild(clearButton).onTouch = function()
|
||||
for j = selector.y, selector.y + selector.height - 1 do
|
||||
for i = selector.x, selector.x + selector.width - 1 do
|
||||
image.set(mainContainer.image.data, i - mainContainer.image.x + 1, j - mainContainer.image.y + 1, 0x0, 0x0, 1, " ")
|
||||
end
|
||||
end
|
||||
|
||||
mainContainer:drawOnScreen()
|
||||
end
|
||||
|
||||
mainContainer.currentToolLayout:addChild(outlineButton).onTouch = function()
|
||||
local x1, y1 = selector.x - mainContainer.image.x + 1, selector.y - mainContainer.image.y + 1
|
||||
local x2, y2 = x1 + selector.width - 1, y1 + selector.height - 1
|
||||
|
||||
for x = x1, x2 do
|
||||
image.set(mainContainer.image.data, x, y1, mainContainer.primaryColorSelector.color, 0x0, 0, " ")
|
||||
image.set(mainContainer.image.data, x, y2, mainContainer.primaryColorSelector.color, 0x0, 0, " ")
|
||||
end
|
||||
|
||||
for y = y1 + 1, y2 - 1 do
|
||||
image.set(mainContainer.image.data, x1, y, mainContainer.primaryColorSelector.color, 0x0, 0, " ")
|
||||
image.set(mainContainer.image.data, x2, y, mainContainer.primaryColorSelector.color, 0x0, 0, " ")
|
||||
end
|
||||
|
||||
mainContainer:drawOnScreen()
|
||||
end
|
||||
|
||||
mainContainer.currentToolLayout:addChild(rasterizeLineButton).onTouch = function()
|
||||
buffer.rasterizeLine(
|
||||
touchX - mainContainer.image.x + 1,
|
||||
touchY - mainContainer.image.y + 1,
|
||||
dragX - mainContainer.image.x + 1,
|
||||
dragY - mainContainer.image.y + 1,
|
||||
function(x, y)
|
||||
image.set(mainContainer.image.data, x, y, mainContainer.primaryColorSelector.color, 0x0, 0, " ")
|
||||
end
|
||||
)
|
||||
|
||||
mainContainer:drawOnScreen()
|
||||
end
|
||||
|
||||
mainContainer.currentToolLayout:addChild(cropButton).onTouch = function()
|
||||
mainContainer.image.data = image.crop(mainContainer.image.data, selector.x - mainContainer.image.x + 1, selector.y - mainContainer.image.y + 1, selector.width, selector.height)
|
||||
mainContainer.image.reposition()
|
||||
|
||||
touchX, touchY, dragX, dragY = mainContainer.image.localX, mainContainer.image.localY, mainContainer.image.localX + mainContainer.image.width - 1, mainContainer.image.localY + mainContainer.image.height - 1
|
||||
repositionSelector(mainContainer)
|
||||
end
|
||||
|
||||
mainContainer.currentToolOverlay:addChild(selector)
|
||||
selector.hidden = true
|
||||
end
|
||||
|
||||
tool.eventHandler = function(mainContainer, object, eventData)
|
||||
if eventData[1] == "touch" then
|
||||
xOld, yOld = eventData[3], eventData[4]
|
||||
selector = mainContainer:addChild(GUI.object(eventData[3], eventData[4], 1, 1))
|
||||
selector.eventHandler = tool.eventHandler
|
||||
selector.draw = function()
|
||||
local step = true
|
||||
for x = selector.x + 1, selector.x + selector.width - 2 do
|
||||
buffer.text(x, selector.y, step and 0xFFFFFF or 0x0, "━")
|
||||
buffer.text(x, selector.y + selector.height - 1, step and 0xFFFFFF or 0x0, "━")
|
||||
step = not step
|
||||
end
|
||||
|
||||
step = true
|
||||
for y = selector.y + 1, selector.y + selector.height - 2 do
|
||||
buffer.text(selector.x, y, step and 0xFFFFFF or 0x0, "┃")
|
||||
buffer.text(selector.x + selector.width - 1, y, step and 0xFFFFFF or 0x0, "┃")
|
||||
step = not step
|
||||
end
|
||||
|
||||
buffer.text(selector.x, selector.y, 0x0, "┏")
|
||||
buffer.text(selector.x + selector.width - 1, selector.y, 0x0, "┓")
|
||||
buffer.text(selector.x + selector.width - 1, selector.y + selector.height - 1, 0x0, "┛")
|
||||
buffer.text(selector.x, selector.y + selector.height - 1, 0x0, "┗")
|
||||
end
|
||||
|
||||
mainContainer:drawOnScreen()
|
||||
elseif eventData[1] == "drag" and selector then
|
||||
local x, y, width, height
|
||||
if eventData[3] - xOld >= 0 then
|
||||
x, width = xOld, eventData[3] - xOld + 1
|
||||
else
|
||||
x, width = eventData[3], xOld - eventData[3] + 1
|
||||
end
|
||||
|
||||
if eventData[4] - yOld >= 0 then
|
||||
y, height = yOld, eventData[4] - yOld + 1
|
||||
else
|
||||
y, height = eventData[4], yOld - eventData[4] + 1
|
||||
end
|
||||
|
||||
selector.localX, selector.localY, selector.width, selector.height = x, y, width, height
|
||||
|
||||
mainContainer:drawOnScreen()
|
||||
elseif eventData[1] == "drop" and selector then
|
||||
local menu = GUI.contextMenu(eventData[3], eventData[4])
|
||||
|
||||
menu:addItem("Fill").onTouch = function()
|
||||
for j = selector.y, selector.y + selector.height - 1 do
|
||||
for i = selector.x, selector.x + selector.width - 1 do
|
||||
image.set(mainContainer.image.data, i - mainContainer.image.x + 1, j - mainContainer.image.y + 1, mainContainer.primaryColorSelector.color, 0x0, 0, " ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
menu:addItem("Clear").onTouch = function()
|
||||
for j = selector.y, selector.y + selector.height - 1 do
|
||||
for i = selector.x, selector.x + selector.width - 1 do
|
||||
image.set(mainContainer.image.data, i - mainContainer.image.x + 1, j - mainContainer.image.y + 1, 0x0, 0x0, 1, " ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
menu:addItem("Outline").onTouch = function()
|
||||
local x1, y1 = selector.x - mainContainer.image.x + 1, selector.y - mainContainer.image.y + 1
|
||||
local x2, y2 = x1 + selector.width - 1, y1 + selector.height - 1
|
||||
|
||||
for x = x1, x2 do
|
||||
image.set(mainContainer.image.data, x, y1, mainContainer.primaryColorSelector.color, 0x0, 0, " ")
|
||||
image.set(mainContainer.image.data, x, y2, mainContainer.primaryColorSelector.color, 0x0, 0, " ")
|
||||
end
|
||||
|
||||
for y = y1 + 1, y2 - 1 do
|
||||
image.set(mainContainer.image.data, x1, y, mainContainer.primaryColorSelector.color, 0x0, 0, " ")
|
||||
image.set(mainContainer.image.data, x2, y, mainContainer.primaryColorSelector.color, 0x0, 0, " ")
|
||||
end
|
||||
end
|
||||
|
||||
menu:addSeparator()
|
||||
|
||||
menu:addItem("Crop").onTouch = function()
|
||||
mainContainer.image.data = image.crop(mainContainer.image.data, selector.x - mainContainer.image.x + 1, selector.y - mainContainer.image.y + 1, selector.width, selector.height)
|
||||
mainContainer.image.reposition()
|
||||
end
|
||||
|
||||
menu:show()
|
||||
|
||||
selector:delete()
|
||||
xOld, yOld, selector = nil, nil, nil
|
||||
mainContainer:drawOnScreen()
|
||||
selector.hidden = false
|
||||
touchX, touchY, dragX, dragY = eventData[3], eventData[4], eventData[3], eventData[4]
|
||||
repositionSelector(mainContainer)
|
||||
elseif eventData[1] == "drag" then
|
||||
dragX, dragY = eventData[3], eventData[4]
|
||||
repositionSelector(mainContainer)
|
||||
end
|
||||
end
|
||||
|
||||
selector.eventHandler = tool.eventHandler
|
||||
selector.draw = function()
|
||||
local step = true
|
||||
for x = selector.x + 1, selector.x + selector.width - 2 do
|
||||
buffer.text(x, selector.y, step and 0xFFFFFF or 0x0, "━")
|
||||
buffer.text(x, selector.y + selector.height - 1, step and 0xFFFFFF or 0x0, "━")
|
||||
step = not step
|
||||
end
|
||||
|
||||
step = true
|
||||
for y = selector.y + 1, selector.y + selector.height - 2 do
|
||||
buffer.text(selector.x, y, step and 0xFFFFFF or 0x0, "┃")
|
||||
buffer.text(selector.x + selector.width - 1, y, step and 0xFFFFFF or 0x0, "┃")
|
||||
step = not step
|
||||
end
|
||||
|
||||
buffer.text(selector.x, selector.y, 0x0, "┏")
|
||||
buffer.text(selector.x + selector.width - 1, selector.y + selector.height - 1, 0x0, "┛")
|
||||
|
||||
buffer.text(selector.x + selector.width - 1, selector.y, 0x0, "┓")
|
||||
buffer.text(selector.x, selector.y + selector.height - 1, 0x0, "┗")
|
||||
|
||||
buffer.text(touchX, touchY, 0x66FF80, "⬤")
|
||||
buffer.text(dragX, dragY, 0x66FF80, "⬤")
|
||||
end
|
||||
|
||||
------------------------------------------------------
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user