testing stuff

This commit is contained in:
Ryan Ward 2023-12-22 22:27:01 -05:00
parent 004d5b9ca4
commit a5415e9e71
2 changed files with 65 additions and 27 deletions

View File

@ -82,10 +82,8 @@ simulate.Move = proc:newFunction(function(self, dx, dy, x, y, istouch)
love.mouse.setPosition(_x, y + p) love.mouse.setPosition(_x, y + p)
end) end)
if not(dx==0 and dy == 0) then if not(dx==0 and dy == 0) then
print("Holding...")
thread.hold(xx.OnStop * yy.OnStop) thread.hold(xx.OnStop * yy.OnStop)
end end
print("Done")
gui.Events.OnMouseMoved:Fire(x + dx, y + dy, 0, 0, istouch or false) gui.Events.OnMouseMoved:Fire(x + dx, y + dy, 0, 0, istouch or false)
end, true) end, true)

View File

@ -189,6 +189,7 @@ function gui:hasType(t) return band(self.type, t) == t end
function gui:move(x, y) function gui:move(x, y)
self.dualDim.offset.pos.x = self.dualDim.offset.pos.x + x self.dualDim.offset.pos.x = self.dualDim.offset.pos.x + x
self.dualDim.offset.pos.y = self.dualDim.offset.pos.y + y self.dualDim.offset.pos.y = self.dualDim.offset.pos.y + y
self.OnPositionChanged:Fire(self, x, y)
end end
function gui:moveInBounds(dx, dy) function gui:moveInBounds(dx, dy)
@ -285,6 +286,19 @@ function gui:setDualDim(x, y, w, h, sx, sy, sw, sh)
sy or self.dualDim.scale.pos.y, sy or self.dualDim.scale.pos.y,
sw or self.dualDim.scale.size.x, sw or self.dualDim.scale.size.x,
sh or self.dualDim.scale.size.y) sh or self.dualDim.scale.size.y)
self.OnSizeChanged:Fire(self, x, y, w, h, sx, sy, sw, sh)
end
function gui:rawSetDualDim(x, y, w, h, sx, sy, sw, sh)
self.dualDim = self:newDualDim(
x or self.dualDim.offset.pos.x,
y or self.dualDim.offset.pos.y,
w or self.dualDim.offset.size.x,
h or self.dualDim.offset.size.y,
sx or self.dualDim.scale.pos.x,
sy or self.dualDim.scale.pos.y,
sw or self.dualDim.scale.size.x,
sh or self.dualDim.scale.size.y)
end end
local image_cache = {} local image_cache = {}
@ -517,6 +531,9 @@ function gui:newBase(typ, x, y, w, h, sx, sy, sw, sh, virtual)
c.OnMoved = testHierarchy .. multi:newConnection() c.OnMoved = testHierarchy .. multi:newConnection()
c.OnWheelMoved = defaultCheck / gui.Events.OnWheelMoved c.OnWheelMoved = defaultCheck / gui.Events.OnWheelMoved
c.OnSizeChanged = multi:newConnection()
c.OnPositionChanged = multi:newConnection()
local dragging = false local dragging = false
local entered = false local entered = false
local moved = false local moved = false
@ -592,21 +609,15 @@ function gui:newBase(typ, x, y, w, h, sx, sy, sw, sh, virtual)
function c:respectHierarchy(bool) hierarchy = bool end function c:respectHierarchy(bool) hierarchy = bool end
local function centerthread() local function centerthread()
local centerfunc = function() if centerX or centerY then
return centerX or centerY -- If the condition is true it acts like a yield local x, y, w, h = c:getAbsolutes()
end if centerX then
c:newThread(function() c:rawSetDualDim(-w / 2, nil, nil, nil, .5)
while true do
thread.hold(centerfunc)
local x, y, w, h = c:getAbsolutes()
if centerX then
c:setDualDim(-w / 2, nil, nil, nil, .5)
end
if centerY then
c:setDualDim(nil, -h / 2, nil, nil, nil, .5)
end
end end
end) if centerY then
c:rawSetDualDim(nil, -h / 2, nil, nil, nil, .5)
end
end
end end
function c:enableDragging(but) function c:enableDragging(but)
@ -622,14 +633,18 @@ function gui:newBase(typ, x, y, w, h, sx, sy, sw, sh, virtual)
centerX = bool centerX = bool
if centering then return end if centering then return end
centering = true centering = true
centerthread() self.OnSizeChanged(centerthread)
self.OnPositionChanged(centerthread)
updater:newLoop(centerthread)
end end
function c:centerY(bool) function c:centerY(bool)
centerY = bool centerY = bool
if centering then return end if centering then return end
centering = true centering = true
centerthread() self.OnSizeChanged(centerthread)
self.OnPositionChanged(centerthread)
updater:newLoop(centerthread)
end end
function c:fullFrame() function c:fullFrame()
@ -1135,9 +1150,9 @@ function gui:applyGradient(direction, ...)
self.imageVisibility = 1 self.imageVisibility = 1
self.image = img self.image = img
self.image:setWrap("repeat", "repeat") self.image:setWrap("repeat", "repeat")
self.imageHeigth = img:getHeight() self.imageHeight = img:getHeight()
self.imageWidth = img:getWidth() self.imageWidth = img:getWidth()
self.quad = love.graphics.newQuad(0, 0, self.imageWidth, self.imageHeigth, self.imageWidth, self.imageHeigth) self.quad = love.graphics.newQuad(0, 0, self.imageWidth, self.imageHeight, self.imageWidth, self.imageHeight)
if not (band(self.type, image) == image) then if not (band(self.type, image) == image) then
self.type = self.type + image self.type = self.type + image
@ -1148,6 +1163,8 @@ function gui:newImageBase(typ, x, y, w, h, sx, sy, sw, sh)
local c = self:newBase(image + typ, x, y, w, h, sx, sy, sw, sh) local c = self:newBase(image + typ, x, y, w, h, sx, sy, sw, sh)
c.color = color.white c.color = color.white
c.visibility = 0 c.visibility = 0
c.scaleX = 1
c.scaleY = 1
local IMAGE local IMAGE
function c:getUniques() function c:getUniques()
@ -1157,6 +1174,14 @@ function gui:newImageBase(typ, x, y, w, h, sx, sy, sw, sh)
}) })
end end
function c:flip(vert)
if vert then
c.scaleY = c.scaleY * -1
else
c.scaleX = c.scaleX * -1
end
end
c.setImage = function(self, i, x, y, w, h) c.setImage = function(self, i, x, y, w, h)
if i == nil then return end if i == nil then return end
img = love.image.newImageData(i) img = love.image.newImageData(i)
@ -1165,7 +1190,7 @@ function gui:newImageBase(typ, x, y, w, h, sx, sy, sw, sh)
if type(i) == "string" then i = image_cache[i] or i end if type(i) == "string" then i = image_cache[i] or i end
if i and x then if i and x then
c.imageHeigth = h c.imageHeight = h
c.imageWidth = w c.imageWidth = w
if type(i) == "string" then if type(i) == "string" then
@ -1191,9 +1216,9 @@ function gui:newImageBase(typ, x, y, w, h, sx, sy, sw, sh)
c.imageVisibility = 1 c.imageVisibility = 1
c.image = img c.image = img
c.image:setWrap("repeat", "repeat") c.image:setWrap("repeat", "repeat")
c.imageHeigth = img:getHeight() c.imageHeight = img:getHeight()
c.imageWidth = img:getWidth() c.imageWidth = img:getWidth()
c.quad = love.graphics.newQuad(0, 0, c.imageWidth, c.imageHeigth, c.imageWidth, c.imageHeigth) c.quad = love.graphics.newQuad(0, 0, c.imageWidth, c.imageHeight, c.imageWidth, c.imageHeight)
end end
return c return c
end end
@ -1294,9 +1319,24 @@ local drawtypes = {
[0] = function(child, x, y, w, h) end, [0] = function(child, x, y, w, h) end,
[1] = function(child, x, y, w, h) [1] = function(child, x, y, w, h)
if child.image then if child.image then
love.graphics.setColor(child.imageColor[1], child.imageColor[2], if child.scaleX < 0 or child.scaleY < 0 then
child.imageColor[3], child.imageVisibility) local sx, sy = child.scaleX, child.scaleY
love.graphics.draw(child.image, child.quad, x, y, rad(child.rotation), w / child.imageWidth, h / child.imageHeigth) local adjustX, adjustY = child.scaleX * w, child.scaleY * h
love.graphics.setColor(child.imageColor[1], child.imageColor[2],
child.imageColor[3], child.imageVisibility)
if sx < 0 and sy < 0 then
love.graphics.draw(child.image, child.quad, x - adjustX, y - adjustY, rad(child.rotation), (w / child.imageWidth) * child.scaleX, (h / child.imageHeight) * child.scaleY)
elseif sx < 0 then
love.graphics.draw(child.image, child.quad, x - adjustX, y, rad(child.rotation), (w / child.imageWidth) * child.scaleX, h / child.imageHeight)
else
love.graphics.draw(child.image, child.quad, x, y - adjustY, rad(child.rotation), w / child.imageWidth, (h / child.imageHeight) * child.scaleY)
end
else
love.graphics.setColor(child.imageColor[1], child.imageColor[2],
child.imageColor[3], child.imageVisibility)
love.graphics.draw(child.image, child.quad, x, y, rad(child.rotation), w / child.imageWidth, h / child.imageHeight)
end
end end
end, end,
[2] = function(child, x, y, w, h) [2] = function(child, x, y, w, h)
@ -1345,7 +1385,7 @@ local drawtypes = {
if child.video and child.playing then if child.video and child.playing then
love.graphics.setColor(child.videoColor[1], child.videoColor[2], love.graphics.setColor(child.videoColor[1], child.videoColor[2],
child.videoColor[3], child.videoVisibility) child.videoColor[3], child.videoVisibility)
if w ~= child.imageWidth and h ~= child.imageHeigth then if w ~= child.imageWidth and h ~= child.imageHeight then
love.graphics.draw(child.video, x, y, rad(child.rotation), love.graphics.draw(child.video, x, y, rad(child.rotation),
w / child.videoWidth, h / child.videoHeigth) w / child.videoWidth, h / child.videoHeigth)
else else