gui/GuiManagerDebug/Core/newBase.int
Ryan 84bba39187 The library
This is for the love2d engine. Works with the latest version. Look at my intro to software project for some examples on how to use this
2017-06-10 16:06:50 -04:00

237 lines
6.1 KiB
Plaintext

function gui.enableAutoWindowScaling(b)
_GuiPro.DPI_ENABLED=b or true
_defaultfont=love.graphics.newFont(12*love.window.getPixelScale())
end
function filter(name, x, y, w, h, sx ,sy ,sw ,sh)
if type(name)~="string" then
sh=sw
sw=sy
sy=sx
sx=h
h=w
w=y
y=x
x=name
end
return x,y,w,h,sx,sy,sw,sh
end
function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh)
_GuiPro.count=_GuiPro.count+1
local c = {}
setmetatable(c, gui)
if self==gui then
c.Parent=_GuiPro
else
c.Parent=self
end
c.segments=nil
c.ry=nil
c.rx=nil
c.DPI=1
if _GuiPro.DPI_ENABLED then
c.DPI=love.window.getPixelScale()
x, y, w, h=c.DPI*x,c.DPI*y,c.DPI*w,c.DPI*h
end
c.centerFontY=true
c.FormFactor="rectangle"
c.Type=tp
c.Active=true
c.form="rectangle"
c.Draggable=false
c.Name=name or "Gui"..tp
c:SetName(name)
c.BorderSize=1
c.BorderColor={0,0,0}
c.VIS=true
c.Visible=true
c.oV=true
c.Children={}
c.hovering=false
c.rclicked=false
c.lclicked=false
c.mclicked=false
c.clicked=false
c.Visibility=1
c.ClipDescendants=false
c.TextWrap=true
c.scale={}
c.scale.size={}
c.scale.size.x=sw or 0
c.scale.size.y=sh or 0
c.offset={}
c.offset.size={}
c.offset.size.x=w or 0
c.offset.size.y=h or 0
c.scale.pos={}
c.scale.pos.x=sx or 0
c.scale.pos.y=sy or 0
c.offset.pos={}
c.offset.pos.x=x or 0
c.offset.pos.y=y or 0
c.width = 0
c.height = 0
c.LRE=false
c.RRE=false
c.MRE=false
c.Color = {255, 255, 255}
function c:setRoundness(rx,ry,segments)
self.segments=segments
self.ry=ry
self.rx=rx
end
function c.stfunc()
love.graphics.rectangle("fill", c.x, c.y, c.width, c.height,c.rx,c.ry,c.segments)
end
function c:hasRoundness()
return (self.ry or self.rx)
end
c.funcs={function(b,self)
if b=="l" then
self.LRE=true
end
end,
function(b,self)
if b=="r" then
self.RRE=true
end
end,
function(b,self)
if b=="m" then
self.MRE=true
end
end}
c.funcs2={function(b,self)
if b=="l" then
self.LRE=false
end
end,
function(b,self)
if b=="r" then
self.RRE=false
end
end,
function(b,self)
if b=="m" then
self.MRE=false
end
end}
c.HE=false
c.funcs3={function(self)
self.HE=true
end}
c.funcs4={function(self)
self.HE=false
end}
c.funcs5={}
c.tid={}
c.touchcount=0
c.x=(c.Parent.width*c.scale.pos.x)+c.offset.pos.x+c.Parent.x
c.y=(c.Parent.height*c.scale.pos.y)+c.offset.pos.y+c.Parent.y
c.width=(c.Parent.width*c.scale.size.x)+c.offset.size.x
c.height=(c.Parent.height*c.scale.size.y)+c.offset.size.y
c.func6={}
c.func7={function() _GuiPro.DragItem={} end}
c.func8={function(self) _GuiPro.DragItem=self end}
c.func9={}
c.func10={}
function c:ImageRule()
if self.Image then
local sx=self.width/self.ImageWidth
local sy=self.height/self.ImageHeigth
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.ImageVisibility*255)
if self.width~=self.ImageWidth and self.height~=self.ImageHeigth then
love.graphics.draw(self.Image,self.x,self.y,math.rad(self.rotation),sx,sy)
else
love.graphics.draw(self.Image,self.Quad,self.x,self.y,math.rad(self.rotation),sx,sy)
end
end
end
function c:VideoRule()
if self.Video then
local sx=self.width/self.VideoWidth
local sy=self.height/self.VideoHeigth
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.VideoVisibility*255)
if self.width~=self.VideoWidth and self.height~=self.VideoHeigth then
love.graphics.draw(self.Video,self.x,self.y,math.rad(self.rotation),sx,sy)
else
love.graphics.draw(self.Video,self.Quad,self.x,self.y,math.rad(self.rotation),sx,sy)
end
end
end
function c:repeatImage(b,b2)
if b then
self.Image:setWrap("repeat","repeat")
function self:ImageRule()
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.ImageVisibility*255)
love.graphics.draw(self.Image,self.Quad,self.x,self.y,math.rad(self.rotation))
end
else
sx=self.width/self.ImageWidth
sy=self.height/self.ImageHeigth
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.ImageVisibility*255)
love.graphics.draw(self.Image,self.Quad,self.x,self.y,math.rad(self.rotation),sx,sy)
end
end
function c:Mutate(t)
for i,v in pairs(t) do
_GuiPro.self=self
if type(i)=="number" then
loadstring("_GuiPro.self:"..v)()
else
self[i]=v
end
end
return self
end
c:WhileHovering(function(self)
self.omx=self.nmx
self.omy=self.nmy
self.nmx=love.mouse.getX()
self.nmy=love.mouse.getY()
if self.omx~=self.nmx or self.omy~=self.nmy then
for i=1,#self.func10 do
if self and self.nmx and self.nmy and self.omx and self.omy then
self.func10[i](self,self.nmx,self.nmy,self.omx,self.omy)
end
end
end
if self.WasBeingDragged==true and love.mouse.isDown(self.dragbut or "m")==false and self.Type~="TextImageButtonFrameDrag" then
for i=1,#self.func7 do
self.func7[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
end
end
if _GuiPro.hasDrag==false and love.mouse.isDown(self.dragbut or "m") then
for i=1,#self.func8 do
self.func8[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
end
end
if self.IsBeingDragged==true then
_GuiPro.hasDrag=true
self.WasBeingDragged=true
elseif self.WasBeingDragged==true and self.IsBeingDragged==false then
self.WasBeingDragged=false
_GuiPro.hasDrag=false
end
if self.Draggable==true and love.mouse.isDown(self.dragbut or "m") and _GuiPro.hasDrag==false then
for i=1,#self.func6 do
self.func6[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
end
_GuiPro.hasDrag=true
if self.FormFactor:lower()=="circle" or self.FormFactor:lower()=="c" or self.FormFactor:lower()=="cir" then
self.IsBeingDragged=true
x=(love.mouse.getX()-self.x)
y=(love.mouse.getY()-self.y)
self:Move(x,y)
elseif self.FormFactor:lower()=="rectangle" or self.FormFactor:lower()=="r" or self.FormFactor:lower()=="rect" then
self.IsBeingDragged=true
x=(love.mouse.getX()-self.x)-self.width/2
y=(love.mouse.getY()-self.y)-self.height/2
self:Move(x,y)
end
else
self.IsBeingDragged=false
end
end)
table.insert(c.Parent.Children,c)
return c
end