Testing moonshine compatibility with guimanger
This commit is contained in:
parent
7976727dc9
commit
e364f6d449
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,3 +3,5 @@ conf.lua
|
||||
*.ttf
|
||||
*.png
|
||||
*.ogv
|
||||
multi/*
|
||||
moonshine/*
|
||||
107
gui/init.lua
107
gui/init.lua
@ -123,7 +123,7 @@ function gui:getAllChildren()
|
||||
end
|
||||
|
||||
function gui:newThread(func)
|
||||
return updater:newThread("ThreadHandler", func, self, thread)
|
||||
return updater:newThread("ThreadHandler<"..self.type..">", func, self, thread)
|
||||
end
|
||||
|
||||
function gui:setDualDim(x,y,w,h,sx,sy,sw,sh)
|
||||
@ -137,6 +137,26 @@ function gui:setDualDim(x,y,w,h,sx,sy,sw,sh)
|
||||
}
|
||||
end
|
||||
|
||||
function gui:getTile(i,x,y,w,h)-- returns imagedata
|
||||
if type(i)=="string" then
|
||||
i=love.graphics.newImage(i)
|
||||
elseif type(i)=="userdata" then
|
||||
-- do nothing
|
||||
elseif string.find(self.Type,"Image",1,true) then
|
||||
local i,x,y,w,h=self.Image,i,x,y,w
|
||||
else
|
||||
error("getTile invalid args!!! Usage: ImageElement:getTile(x,y,w,h) or gui:getTile(imagedata,x,y,w,h)")
|
||||
end
|
||||
local iw,ih=i:getDimensions()
|
||||
local id,_id=i:getData(),love.image.newImageData(w,h)
|
||||
for _x=x,w+x-1 do
|
||||
for _y=y,h+y-1 do
|
||||
_id:setPixel(_x-x,_y-y,id:getPixel(_x,_y))
|
||||
end
|
||||
end
|
||||
return love.graphics.newImage(_id)
|
||||
end
|
||||
|
||||
function gui:topStack()
|
||||
local siblings = self.parent.children
|
||||
for i=1,#siblings do
|
||||
@ -167,11 +187,10 @@ function gui:isBeingCovered(mx,my)
|
||||
local children = gui:getAllChildren()
|
||||
local start = false
|
||||
for i=#children, 1, -1 do
|
||||
if start and children[i]:canPress(mx,my) then
|
||||
if children[i]:canPress(mx,my) and not(children[i] == self) then
|
||||
return true
|
||||
end
|
||||
if children[i]==self then
|
||||
start = true
|
||||
elseif children[i] == self then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return false
|
||||
@ -236,16 +255,6 @@ function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
entered = false
|
||||
self:Resume()
|
||||
end)
|
||||
local dragFunc = thread:newFunction(function(self, ref, mx, my)
|
||||
self:Pause()
|
||||
thread.hold(function() return not(love.mouse.isDown(dragbutton)) end)
|
||||
if dragging then
|
||||
global_drag = nil
|
||||
dragging = false
|
||||
ref.OnDragEnd:Fire(ref,mx,my)
|
||||
end
|
||||
self:Resume()
|
||||
end)
|
||||
local releaseFunc = thread:newFunction(function(self, ref, mx, my, i)
|
||||
self:Pause()
|
||||
thread.hold(function() return not(love.mouse.isDown(i)) end)
|
||||
@ -266,20 +275,21 @@ function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
waiting = {}
|
||||
pressed = {}
|
||||
ox, oy = 0, 0
|
||||
mox, moy = 0, 0
|
||||
entered = false
|
||||
moved = false
|
||||
mx, my = nil, nil
|
||||
global_drag = nil
|
||||
end
|
||||
local x, y, w, h = c:getAbsolutes()
|
||||
mx, my = love.mouse.getPosition()
|
||||
--thread.hold(function() return c:canPress(mx,my) end)
|
||||
moved = false
|
||||
-- mouse moved
|
||||
if mx~=mox or my~=moy then
|
||||
moved = true
|
||||
c.OnMoved:Fire(c, mx - mox, my - moy)
|
||||
mox = mx
|
||||
moy = my
|
||||
end
|
||||
|
||||
-- enter/exit
|
||||
if moved and not entered and c:canPress(mx,my) then
|
||||
entered = true
|
||||
@ -290,20 +300,27 @@ function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
-- pressed/released/drag events
|
||||
for i=1,c.maxMouseButtons do
|
||||
if dragging and i == dragbutton then
|
||||
c.OnDragging:Fire(c, mx - ox, my - oy)
|
||||
c.OnDragging:Fire(c, mx - ox, my - oy, mx, my)
|
||||
ox = mx
|
||||
oy = my
|
||||
end
|
||||
if love.mouse.isDown(i) and c:canPress(mx,my) then
|
||||
if not pressed[i] then
|
||||
if draggable and love.mouse.isDown(dragbutton) and (not global_drag or global_drag == c) then
|
||||
if not dragging then
|
||||
if not dragging and not c:isBeingCovered(mx, my) then
|
||||
global_drag = c
|
||||
c.OnDragStart:Fire(c, mx, my)
|
||||
ox, oy = mx, my
|
||||
dragFunc(dragFunc, c, mx, my)
|
||||
end
|
||||
dragging = true
|
||||
c:newThread(function()
|
||||
thread.hold(function() return not(love.mouse.isDown(dragbutton)) end)
|
||||
if dragging then
|
||||
global_drag = nil
|
||||
dragging = false
|
||||
c.OnDragEnd:Fire(c, mx, my)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
c.OnPressed:Fire(c, i, mx, my)
|
||||
end
|
||||
@ -317,7 +334,8 @@ function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
end
|
||||
end
|
||||
end
|
||||
end).OnError(function()
|
||||
end).OnError(function(self,err)
|
||||
print(err)
|
||||
buildBackBetter()
|
||||
end)
|
||||
end
|
||||
@ -563,40 +581,60 @@ function gui:newVideo(source, x, y, w, h, sx, sy, sw, sh)
|
||||
local c = self:newImageBase(video, x, y, w, h, sx, sy, sw, sh)
|
||||
c.OnVideoFinished = multi:newConnection()
|
||||
c.playing = false
|
||||
|
||||
function c:setVideo(v)
|
||||
if type(v)=="string" then
|
||||
c.video=love.graphics.newVideo(v)
|
||||
elseif v then
|
||||
c.video=v
|
||||
end
|
||||
c.audiosource = c.video:getSource( )
|
||||
c.videoHeigth=c.video:getHeight()
|
||||
c.videoWidth=c.video:getWidth()
|
||||
c.quad=love.graphics.newQuad(0,0,w,h,c.videoWidth,c.videoHeigth)
|
||||
end
|
||||
|
||||
function c:getVideo()
|
||||
return self.video
|
||||
end
|
||||
|
||||
if type(source)=="string" then
|
||||
c:setVideo(source)
|
||||
end
|
||||
|
||||
function c:play()
|
||||
c.playing = true
|
||||
c.video:play()
|
||||
end
|
||||
|
||||
function c:setVolume(vol)
|
||||
if self.audiosource then
|
||||
self.audiosource:setVolume(vol)
|
||||
end
|
||||
end
|
||||
|
||||
function c:pause()
|
||||
c.video:pause()
|
||||
end
|
||||
|
||||
function c:stop()
|
||||
c.playing = false
|
||||
c.video:pause()
|
||||
c.video:rewind()
|
||||
end
|
||||
|
||||
function c:rewind()
|
||||
c.video:rewind()
|
||||
end
|
||||
|
||||
function c:seek(n)
|
||||
c.video:seek(n)
|
||||
end
|
||||
|
||||
function c:tell()
|
||||
return c.video:tell()
|
||||
end
|
||||
|
||||
c:newThread(function(self)
|
||||
while true do
|
||||
thread.hold(function() return self.video:isPlaying() end)
|
||||
@ -611,8 +649,10 @@ function gui:newVideo(source, x, y, w, h, sx, sy, sw, sh)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
c.videoVisibility = 1
|
||||
c.videoColor = color.white
|
||||
|
||||
return c
|
||||
end
|
||||
|
||||
@ -651,10 +691,7 @@ local drawtypes = {
|
||||
end,
|
||||
}
|
||||
|
||||
drawer:newLoop(function()
|
||||
local children = gui:getAllChildren()
|
||||
for i=1,#children do
|
||||
local child = children[i]
|
||||
local draw_handler = function(child)
|
||||
local bg = child.color
|
||||
local bbg = child.borderColor
|
||||
local type = child.type
|
||||
@ -694,6 +731,22 @@ drawer:newLoop(function()
|
||||
|
||||
love.graphics.setScissor() -- Remove the scissor
|
||||
end
|
||||
drawer:newLoop(function()
|
||||
local children = gui:getAllChildren()
|
||||
for i=1,#children do
|
||||
local child = children[i]
|
||||
if child.effect then
|
||||
child.effect(function()
|
||||
draw_handler(child)
|
||||
end)
|
||||
elseif child.chain then
|
||||
child.chain.draw(function()
|
||||
draw_handler(child)
|
||||
end)
|
||||
else
|
||||
draw_handler(child)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Drawing and Updating
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user