diff --git a/GuiManager/Core/Clickable.int b/GuiManager/Core/Clickable.int deleted file mode 100644 index f192d8e..0000000 --- a/GuiManager/Core/Clickable.int +++ /dev/null @@ -1,15 +0,0 @@ -function gui:Clickable() - local x,y,w,h=love.graphics.getScissor() - local mx=love.mouse.getX() - local my=love.mouse.getY() - if _GuiPro.HasStencel then - local obj=_GuiPro.StencelHolder - if self:isDescendant(obj) then - return math.sqrt((mx-obj.x)^2+(my-obj.y)^2)<=(obj.offset.size.x or 0) - end - end - if not(x) then - return true - end - return not(mx>x+w or mxy+h or my self.x and x < self.x+self.width and y > self.y and y < self.y+self.height) and (x > _GuiPro.Frames[i].x and x < _GuiPro.Frames[i].x+_GuiPro.Frames[i].width and y > _GuiPro.Frames[i].y and y < _GuiPro.Frames[i].y+_GuiPro.Frames[i].height) and (x > self.x and x < self.x+self.width and y > self.y and y < self.y+self.height ) + -- if not pos then return true end + -- end + -- end + -- end +end +function gui:Clickable() + local x,y,w,h=love.graphics.getScissor() + local mx=love.mouse.getX() + local my=love.mouse.getY() + if _GuiPro. HasStencel then + local obj=_GuiPro.StencelHolder + if self:isDescendant(obj) then + return math.sqrt((mx-obj.x)^2+(my-obj.y)^2)<=(obj.offset.size.x or 0) + end + end + if not(x) then + return true + end + return not(mx>x+w or mxy+h or my ref.x and x < ref.x+ref.width and y > ref.y and y < ref.y+ref.height) and (x > self.x and x < self.x+self.width and y > self.y and y < self.y+self.height and self:Clickable() and (self:eventable() or self:touchable())) then + return true + else + return false + end + else + return false + end +end \ No newline at end of file diff --git a/GuiManager/Core/eventable.int b/GuiManager/Core/eventable.int deleted file mode 100644 index 7390f1c..0000000 --- a/GuiManager/Core/eventable.int +++ /dev/null @@ -1,14 +0,0 @@ -function gui:eventable() - if self.important then - return true - end - if _GuiPro.Hierarchy then - if _GuiPro.TopHovered~=nil then - return self:isDescendant(_GuiPro.TopHovered) or _GuiPro.TopHovered==self - else - return true - end - else - return true - end -end \ No newline at end of file diff --git a/GuiManager/Core/newBase.int b/GuiManager/Core/newBase.int index 31b7fff..e16bcc4 100644 --- a/GuiManager/Core/newBase.int +++ b/GuiManager/Core/newBase.int @@ -1,3 +1,6 @@ +_GuiPro.Frames = {} +_GuiPro.Type = "Window" +_GuiPro.depth = 0 function gui.enableAutoWindowScaling(b) _GuiPro.DPI_ENABLED=b or true _defaultfont=love.graphics.newFont(12*love.window.getPixelScale()) @@ -15,6 +18,9 @@ function filter(name, x, y, w, h, sx ,sy ,sw ,sh) end return x,y,w,h,sx,sy,sw,sh end +function gui:getChildren() + return self.Children +end function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh) _GuiPro.count=_GuiPro.count+1 local c = {} @@ -24,10 +30,20 @@ function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh) else c.Parent=self end + if tp:match("Frame") then + _GuiPro.Frames[#_GuiPro.Frames+1] = c + end + if self.Type and self.Type:match("Frame") then + c.FrameRef = self + else + c.FrameRef = self.FrameRef + end c.segments=nil c.ry=nil c.rx=nil c.DPI=1 + c.isLeaf = true + c.Parent.isLeaf = false 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 @@ -52,7 +68,6 @@ function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh) c.mclicked=false c.clicked=false c.Visibility=1 - c.ClipDescendants=false c.TextWrap=true c.scale={} c.scale.size={} @@ -74,66 +89,23 @@ function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh) 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={} + 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.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 @@ -190,55 +162,6 @@ function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh) 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 \ No newline at end of file diff --git a/GuiManager/Core/touchManager.int b/GuiManager/Core/touchManager.int index d941ba1..1b7bf55 100644 --- a/GuiManager/Core/touchManager.int +++ b/GuiManager/Core/touchManager.int @@ -26,7 +26,7 @@ function gui:touchable(t) end self.id=-1 end -multi:newTask(function() -- A bit of post-loading haha +--multi:newTask(function() -- A bit of post-loading haha gui.touchpressed=multi:newConnection() gui.touchreleased=multi:newConnection() gui.touchmoved=multi:newConnection() @@ -83,7 +83,7 @@ multi:newTask(function() -- A bit of post-loading haha end end end) -end) +--end) -- now that that is done lets set up some more post loading checks _GuiPro.int=multi:newProcess() _GuiPro.int:Start() diff --git a/GuiManager/Drawing/canvas.int b/GuiManager/Drawing/canvas.int new file mode 100644 index 0000000..e69de29 diff --git a/GuiManager/Drawing/drawC.int b/GuiManager/Drawing/drawC.int index 1f299a7..95febad 100644 --- a/GuiManager/Drawing/drawC.int +++ b/GuiManager/Drawing/drawC.int @@ -71,7 +71,7 @@ function gui:drawC() love.graphics.setStencilTest("notequal",0) end love.graphics.circle("fill",x,y,r,s) - love.graphics.setColor(self.BorderColor[1], self.BorderColor[2], self.BorderColor[3],self.Visibility) + love.graphics.setColor(self.BorderColor[1], self.BorderColor[2], self.BorderColor[3],(self.BorderVisibility or 1)) for b=0,self.BorderSize-1 do love.graphics.circle("line",x,y,r+b,s) end diff --git a/GuiManager/Drawing/drawR.int b/GuiManager/Drawing/drawR.int index 36b07c3..05a96f0 100644 --- a/GuiManager/Drawing/drawR.int +++ b/GuiManager/Drawing/drawR.int @@ -3,7 +3,18 @@ function gui:drawR() _GuiPro.DragItem={} _GuiPro.hasDrag=false end + if self.hidden then + self.x=(self.Parent.width*self.scale.pos.x)+self.offset.pos.x+self.Parent.x + self.y=(self.Parent.height*self.scale.pos.y)+self.offset.pos.y+self.Parent.y + self.width=(self.Parent.width*self.scale.size.x)+self.offset.size.x + self.height=(self.Parent.height*self.scale.size.y)+self.offset.size.y + self.VIS = false + end if self.Visible==true and self.VIS==true then + self.x=(self.Parent.width*self.scale.pos.x)+self.offset.pos.x+self.Parent.x + self.y=(self.Parent.height*self.scale.pos.y)+self.offset.pos.y+self.Parent.y + self.width=(self.Parent.width*self.scale.size.x)+self.offset.size.x + self.height=(self.Parent.height*self.scale.size.y)+self.offset.size.y local b=true for i,v in pairs(_GuiPro.Clips) do if self:isDescendant(v)==true then @@ -14,112 +25,43 @@ function gui:drawR() love.graphics.setStencilTest() love.graphics.setScissor() end - self.x=(self.Parent.width*self.scale.pos.x)+self.offset.pos.x+self.Parent.x - self.y=(self.Parent.height*self.scale.pos.y)+self.offset.pos.y+self.Parent.y - self.width=(self.Parent.width*self.scale.size.x)+self.offset.size.x - self.height=(self.Parent.height*self.scale.size.y)+self.offset.size.y if self.DrawRulesB then for dr=1,#self.DrawRulesB do self.DrawRulesB[dr](self) end end - if (love.mouse.getX() > self.x and love.mouse.getX() < self.x+self.width and love.mouse.getY() > self.y and love.mouse.getY() < self.y+self.height and self:Clickable() and self:eventable()) or self:touchable("r") and self.Active==true then - self.hovering=true - if love.mouse.isDown("l") or self:touchable("r") and _GuiPro.hasDrag==false then - if string.find(self.Type, "Button") then - love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility) - else - love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility) - end - self.lclicked=true - elseif love.mouse.isDown("r") or self:touchable("r") and _GuiPro.hasDrag==false then - if string.find(self.Type, "Button") then - love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility) - else - love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility) - end - self.rclicked=true - elseif love.mouse.isDown("m") or self:touchable("r") and _GuiPro.hasDrag==false then - if string.find(self.Type, "Button") then - love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility) - else - love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility) - end - self.mclicked=true - else - if string.find(self.Type, "Button") or self:touchable("r") and _GuiPro.hasDrag==false then - love.graphics.setColor(self.Color[1]-5, self.Color[2]-5, self.Color[3]-5,self.Visibility) - else - love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility) - end - self.rclicked=false - self.lclicked=false - self.mclicked=false - end - else - love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility) - self.hovering=false - self.rclicked=false - self.lclicked=false - self.mclicked=false - end + love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility) if self.ClipDescendants==true then _GuiPro.Clips[tostring(self)]=self love.graphics.setScissor(self.x, self.y, self.width, self.height) end - if self:hasRoundness() then - love.graphics.stencil(self.stfunc, "replace", 1) - love.graphics.setStencilTest("greater", 0) - end - - love.graphics.rectangle("fill", self.x, self.y, self.width, self.height,(self.rx or 1)*self.DPI,(self.ry or 1)*self.DPI,(self.segments or 1)*self.DPI) - if string.find(self.Type, "Image") then - self:ImageRule() - end - if self.Type=="Video" then - self:VideoRule() - end - if self:hasRoundness() then - love.graphics.setStencilTest() - end - love.graphics.setColor(self.BorderColor[1], self.BorderColor[2], self.BorderColor[3],self.Visibility) + if self:hasRoundness() then + -- love.graphics.stencil(self.stfunc, "replace", 1) + -- love.graphics.setStencilTest("greater", 0) + end + love.graphics.rectangle("fill", self.x, self.y, self.width, self.height,(self.rx or 1)*self.DPI,(self.ry or 1)*self.DPI,(self.segments or 1)*self.DPI) + if string.find(self.Type, "Image") then + self:ImageRule() + end + if self.Type=="Video" then + self:VideoRule() + end + if self:hasRoundness() then + -- love.graphics.setStencilTest() + end + love.graphics.setColor(self.BorderColor[1], self.BorderColor[2], self.BorderColor[3],(self.BorderVisibility or 1)) for b=0,self.BorderSize-1 do love.graphics.rectangle("line", self.x-(b/2), self.y-(b/2), self.width+b, self.height+b,(self.rx or 1)*self.DPI,(self.ry or 1)*self.DPI,(self.segments or 1)*self.DPI) end if string.find(self.Type, "Text") then - if self.text~=nil then - if self.AutoScaleText then - self.FontSize=math.floor(self.height/1.45833) - end + if self.text~=nil and self.TextFormat ~= "center" then love.graphics.setColor(self.TextColor[1],self.TextColor[2],self.TextColor[3],self.TextVisibility) - if self.Font==_defaultfont then - love.graphics.setFont(self.Font) - love.graphics.printf( - self.text, - (self.x+2+(self.marginL or 0) or self.XTween)*self.DPI, - (self.y+math.floor((self.FontHeight-self.FontSize)/2)+self.Tween)*self.DPI, - (self.width+(0 or (self.marginR or 0)))*self.DPI, - self.TextFormat, - self.TextRotation) - else - if type(self.Font)=="string" then - self.Font=love.graphics.newFont(self.Font,self.FontSize) - self.FontHeight=self.Font:getHeight() - else - love.graphics.setFont(self.Font) - end - if type(self.FontSize)=="string" then - self.FontSize=tonumber(self.FontSize) - love.graphics.setNewFont(self.FontSize) - end - love.graphics.printf( - self.text, - (self.x+2+(self.marginL or 0) or self.XTween)*self.DPI, - (self.y+math.floor((self.FontHeight-self.FontSize)/2)+self.Tween)*self.DPI, - (self.width+(0 or (self.marginR or 0)))*self.DPI, - self.TextFormat, - self.TextRotation) - end + love.graphics.setFont(self.Font) + love.graphics.printf(self.text, self.x, self.y, self.width, self.TextFormat,self.TextRotaion) + elseif self.text~=nil and self.TextFormat == "center" then + love.graphics.setColor(self.TextColor[1],self.TextColor[2],self.TextColor[3],self.TextVisibility) + love.graphics.setFont(self.Font) + love.graphics.printf(self.text, self.x+(self.width-self.Font:getWidth(self.text))/2, self.y+(self.height-self.Font:getHeight())/2, self.width, "left",self.TextRotaion) end end if self.DrawRulesE then diff --git a/GuiManager/Image-Animation/SetImage.int b/GuiManager/Image-Animation/SetImage.int deleted file mode 100644 index 3a1b2fb..0000000 --- a/GuiManager/Image-Animation/SetImage.int +++ /dev/null @@ -1,13 +0,0 @@ -function gui:SetImage(i) - if type(i)=="string" or tostring(i):find("ImageData") then - self.Image=love.graphics.newImage(i) - else - self.Image=i - end - if self.Image then - self.ImageHeigth=self.Image:getHeight() - self.ImageWidth=self.Image:getWidth() - self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth) - end - return self.ImageWidth,self.ImageHeigth -end \ No newline at end of file diff --git a/GuiManager/Image-Animation/newAnim.int b/GuiManager/Image-Animation/newAnim.int index 30850aa..5d40ded 100644 --- a/GuiManager/Image-Animation/newAnim.int +++ b/GuiManager/Image-Animation/newAnim.int @@ -21,7 +21,7 @@ function gui:newAnim(file,delay, x, y, w, h, sx ,sy ,sw ,sh) step.parent.AnimStart[i](step.parent) end end) - c.step:OnStep(function(pos,step) + c.step:OnStep(function(step,pos) step.parent:SetImage(step.parent.files[pos]) end) c.step:OnEnd(function(step) @@ -43,6 +43,7 @@ function gui:newAnim(file,delay, x, y, w, h, sx ,sy ,sw ,sh) end function c:Reset() self.step.pos=1 + self.step:Reset() end function c:getFrames() return #self.files diff --git a/GuiManager/Image-Animation/newAnimFromTiles.int b/GuiManager/Image-Animation/newAnimFromTiles.int index 70aea2c..56fd0d8 100644 --- a/GuiManager/Image-Animation/newAnimFromTiles.int +++ b/GuiManager/Image-Animation/newAnimFromTiles.int @@ -1,7 +1,7 @@ function gui:newAnimFromTiles(file,xd,yd,delay, x, y, w, h, sx ,sy ,sw ,sh) x,y,w,h,sx,sy,sw,sh=filter(file, x, y, w, h, sx ,sy ,sw ,sh) local c=self:newBase("ImageAnimation",file, x, y, w, h, sx ,sy ,sw ,sh) - local im=love.graphics.newImage(file) + local im=love.image.newImageData(file) local _x,_y=im:getDimensions() c.Visibility=0 c.ImageVisibility=1 @@ -23,7 +23,7 @@ function gui:newAnimFromTiles(file,xd,yd,delay, x, y, w, h, sx ,sy ,sw ,sh) step.parent.AnimStart[i](step.parent) end end) - c.step:OnStep(function(pos,step) + c.step:OnStep(function(step,pos) step.parent:SetImage(step.parent.files[pos]) end) c.step:OnEnd(function(step) diff --git a/GuiManager/Image-Animation/newImageButton.int b/GuiManager/Image-Animation/newImageButton.int index 5d03572..3b3810b 100644 --- a/GuiManager/Image-Animation/newImageButton.int +++ b/GuiManager/Image-Animation/newImageButton.int @@ -1,20 +1,10 @@ function gui:newImageButton(i,name, x, y, w, h, sx ,sy ,sw ,sh) x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh) local c=self:newBase("ImageButton",name, x, y, w, h, sx ,sy ,sw ,sh) - if type(i)=="string" or type(i):find("ImageData") then - c.Image=love.graphics.newImage(i) - else - c.Image=i - end + c:SetImage(i) c.Visibility=0 c.ImageVisibility=1 c.rotation=0 - if c.Image~=nil then - c.ImageHeigth=c.Image:getHeight() - c.ImageHeight=c.Image:getHeight() - c.ImageWidth=c.Image:getWidth() - c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth) - end c:OnEnter(function() love.mouse.setCursor(_GuiPro.CursorH) end) diff --git a/GuiManager/Image-Animation/newImageLabel.int b/GuiManager/Image-Animation/newImageLabel.int index c969bf8..72d1eba 100644 --- a/GuiManager/Image-Animation/newImageLabel.int +++ b/GuiManager/Image-Animation/newImageLabel.int @@ -1,18 +1,9 @@ function gui:newImageLabel(i,name, x, y, w, h, sx ,sy ,sw ,sh) x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh) local c=self:newBase("ImageLabel",name, x, y, w, h, sx ,sy ,sw ,sh) - if type(i)=="string" or type(i):find("ImageData") then - c.Image=love.graphics.newImage(i) - else - c.Image=i - end + c:SetImage(i) c.Visibility=0 c.ImageVisibility=1 c.rotation=0 - if c.Image then - c.ImageHeigth=c.Image:getHeight() - c.ImageWidth=c.Image:getWidth() - c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth) - end - return c + return c end \ No newline at end of file diff --git a/GuiManager/Misc/ClipDescendants.int b/GuiManager/Misc/ClipDescendants.int new file mode 100644 index 0000000..c57d96d --- /dev/null +++ b/GuiManager/Misc/ClipDescendants.int @@ -0,0 +1,18 @@ +function gui:ClipDescendants(bool) + local c = self:GetAllChildren() + if not c[#c] then return end + if bool then + self.clipParent = self.Parent + self.Clipping = true + c[#c].resetClip = true + for i = 1,#c do + c[i].ClipReference = self + end + else + self.Clipping = nil + c[#c].resetClip = nil + for i = 1,#c do + c[i].ClipReference = nil + end + end +end \ No newline at end of file diff --git a/GuiManager/Misc/Destroy.int b/GuiManager/Misc/Destroy.int index f127af8..dd8f5de 100644 --- a/GuiManager/Misc/Destroy.int +++ b/GuiManager/Misc/Destroy.int @@ -7,4 +7,7 @@ function gui:Destroy() end end self.Destroyed = true + if #self.Parent.Children==0 then + self.Parent.isLeaf = true + end end \ No newline at end of file diff --git a/GuiManager/Misc/SetImage.int b/GuiManager/Misc/SetImage.int new file mode 100644 index 0000000..db4ff92 --- /dev/null +++ b/GuiManager/Misc/SetImage.int @@ -0,0 +1,35 @@ +_GuiPro.jobqueue:registerJob("LoadImage",function(path) + local dat = love.image.newImageData(path) + return dat +end) +local cache = {} +_GuiPro.jobqueue.OnJobCompleted(function(JOBID,n) + cache[JOBID].Image=_GuiPro.imagecache[n] + cache[JOBID].ImageHeigth=cache[JOBID].Image:getHeight() + cache[JOBID].ImageWidth=cache[JOBID].Image:getWidth() + cache[JOBID].Quad=love.graphics.newQuad(0,0,cache[JOBID].width,cache[JOBID].height,cache[JOBID].ImageWidth,cache[JOBID].ImageHeigth) +end) +function gui:SetImage(i) + local temp = self.Image + if _GuiPro.imagecache[i] then + self.Image=_GuiPro.imagecache[i] + self.ImageHeigth=self.Image:getHeight() + self.ImageWidth=self.Image:getWidth() + self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth) + else + if type(i)=="string" then + local ii = _GuiPro.jobqueue:pushJob("LoadImage",i) + cache[ii] = self + elseif tostring(i):find("ImageData") then + self.Image=love.graphics.newImage(i) + self.ImageHeigth=self.Image:getHeight() + self.ImageWidth=self.Image:getWidth() + self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth) + elseif i then + self.Image=i + self.ImageHeigth=self.Image:getHeight() + self.ImageWidth=self.Image:getWidth() + self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth) + end + end +end \ No newline at end of file diff --git a/GuiManager/Image-Animation/UpdateImage.int b/GuiManager/Misc/UpdateImage.int similarity index 100% rename from GuiManager/Image-Animation/UpdateImage.int rename to GuiManager/Misc/UpdateImage.int diff --git a/GuiManager/Misc/Utils.int b/GuiManager/Misc/Utils.int new file mode 100644 index 0000000..c80b4bc --- /dev/null +++ b/GuiManager/Misc/Utils.int @@ -0,0 +1,797 @@ +-- os Additions +function os.getSystemBit() + if (os.getenv('PROCESSOR_ARCHITEW6432')=='AMD64' or os.getenv('PROCESSOR_ARCHITECTURE')=='AMD64') then + return 64 + else + return 32 + end +end +function os.sleep(n) + if not n then n=0 end + local t0 = os.clock() + while os.clock() - t0 <= n do end +end +function os.pause(msg) + if msg ~= nil then + print(msg) + end + io.read() +end +function os.batCmd(cmd) + io.mkFile('temp.bat',cmd) + local temp = os.execute([[temp.bat]]) + io.delFile('temp.bat') + return temp +end +function os._getOS() + if package.config:sub(1,1)=='\\' then + return 'windows' + else + return 'unix' + end +end +function os.getOS(t) + if not t then + return os._getOS() + end + if os._getOS()=='unix' then + fh,err = io.popen('uname -o 2>/dev/null','r') + if fh then + osname = fh:read() + end + if osname then return osname end + end + local winver='Unknown Version' + local a,b,c=os.capture('ver'):match('(%d+).(%d+).(%d+)') + local win=a..'.'..b..'.'..c + if type(t)=='string' then + win=t + end + if win=='4.00.950' then + winver='95' + elseif win=='4.00.1111' then + winver='95 OSR2' + elseif win=='4.00.1381' then + winver='NT 4.0' + elseif win=='4.10.1998' then + winver='98' + elseif win=='4.10.2222' then + winver='98 SE' + elseif win=='4.90.3000' then + winver='ME' + elseif win=='5.00.2195' then + winver='2000' + elseif win=='5.1.2600' then + winver='XP' + elseif win=='5.2.3790' then + winver='Server 2003' + elseif win=='6.0.6000' then + winver='Vista/Windows Server 2008' + elseif win=='6.0.6002' then + winver='Vista SP2' + elseif win=='6.1.7600' then + winver='7/Windows Server 2008 R2' + elseif win=='6.1.7601' then + winver='7 SP1/Windows Server 2008 R2 SP1' + elseif win=='6.2.9200' then + winver='8/Windows Server 2012' + elseif win=='6.3.9600' then + winver='8.1/Windows Server 2012' + elseif win=='6.4.9841' then + winver='10 Technical Preview 1' + elseif win=='6.4.9860' then + winver='10 Technical Preview 2' + elseif win=='6.4.9879' then + winver='10 Technical Preview 3' + elseif win=='10.0.9926' then + winver='10 Technical Preview 4' + end + return 'Windows '..winver +end +function os.getLuaArch() + return (#tostring({})-7)*4 +end +if os.getOS()=='windows' then + function os.sleep(n) + if n > 0 then os.execute('ping -n ' .. tonumber(n+1) .. ' localhost > NUL') end + end +else + function os.sleep(n) + os.execute('sleep ' .. tonumber(n)) + end +end +function os.capture(cmd, raw) + local f = assert(io.popen(cmd, 'r')) + local s = assert(f:read('*a')) + f:close() + if raw then return s end + s = string.gsub(s, '^%s+', '') + s = string.gsub(s, '%s+$', '') + s = string.gsub(s, '[\n\r]+', ' ') + return s +end +function os.getCurrentUser() + return os.getenv('$USER') or os.getenv('USERNAME') +end +-- string Additions +function string.trim(s) + local from = s:match"^%s*()" + return from > #s and "" or s:match(".*%S", from) +end +function string.random(n) + local str = '' + strings = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'} + for i=1,n do + h = math.random(1,#strings) + str = str..''..strings[h] + end + return str +end +function string.linesToTable(s) + local t = {} + local i = 0 + while true do + i = string.find(s, '\n', i+1) + if i == nil then return t end + table.insert(t, i) + end +end +function string.lines(str) + local t = {} + local function helper(line) table.insert(t, line) return '' end + helper((str:gsub('(.-)\r?\n', helper))) + return t +end +function string.split(str, pat) + local t = {} -- NOTE: use {n = 0} in Lua-5.0 + local fpat = '(.-)' .. pat + local last_end = 1 + local s, e, cap = str:find(fpat, 1) + while s do + if s ~= 1 or cap ~= '' then + table.insert(t,cap) + end + last_end = e+1 + s, e, cap = str:find(fpat, last_end) + end + if last_end <= #str then + cap = str:sub(last_end) + table.insert(t, cap) + end + return t +end +function string.shuffle(inputStr) + math.randomseed(os.time()); + local outputStr = ''; + local strLength = string.len(inputStr); + while (strLength ~=0) do + local pos = math.random(strLength); + outputStr = outputStr..string.sub(inputStr,pos,pos); + inputStr = inputStr:sub(1, pos-1) .. inputStr:sub(pos+1); + strLength = string.len(inputStr); + end + return outputStr; +end +function string.genKeys(chars,a,f,s,GG) + if GG then + chars=string.rep(chars,a) + end + if s then + chars=string.shuffle(chars) + end + b=#chars + if a==0 then return end + local taken = {} local slots = {} + for i=1,a do slots[i]=0 end + for i=1,b do taken[i]=false end + local index = 1 + local tab={} + for i=1,#chars do + table.insert(tab,chars:sub(i,i)) + end + while index > 0 do repeat + repeat slots[index] = slots[index] + 1 + until slots[index] > b or not taken[slots[index]] + if slots[index] > b then + slots[index] = 0 + index = index - 1 + if index > 0 then + taken[slots[index]] = false + end + break + else + taken[slots[index]] = true + end + if index == a then + local tt={} + for i=1,a do + table.insert(tt,tab[slots[i]]) + end + f(table.concat(tt)) + taken[slots[index]] = false + break + end + index = index + 1 + until true end +end +-- io Additions +function io.getInput(msg) + if msg ~= nil then + io.write(msg) + end + return io.read() +end +function io.scanDir(directory) + directory=directory or io.getDir() + local i, t, popen = 0, {}, io.popen + if os.getOS()=='unix' then + for filename in popen('ls -a \''..directory..'\''):lines() do + i = i + 1 + t[i] = filename + end + else + for filename in popen('dir \''..directory..'\' /b'):lines() do + i = i + 1 + t[i] = filename + end + end + return t +end +function io.buildFromTree(tbl, indent,folder) + if not indent then indent = 0 end + if not folder then folder = '' end + for k, v in pairs(tbl) do + formatting = string.rep(' ', indent) .. k .. ':' + if type(v) == 'table' then + if not(io.dirExists(folder..string.sub(formatting,1,-2))) then + io.mkDir(folder..string.sub(formatting,1,-2)) + end + io.buildFromTree(v,0,folder..string.sub(formatting,1,-2)..'\\') + else + a=string.find(tostring(v),':',1,true) + if a then + file=string.sub(tostring(v),1,a-1) + data=string.sub(tostring(v),a+1) + io.mkFile(folder..file,data,'wb') + else + io.mkFile(folder..v,'','wb') + end + end + end +end +function io.cpFile(path,topath) + if os.getOS()=='unix' then + os.execute('cp '..file1..' '..file2) + else + os.execute('Copy '..path..' '..topath) + end +end +function io.delDir(directoryname) + if os.getOS()=='unix' then + os.execute('rm -rf '..directoryname) + else + os.execute('rmdir '..directoryname..' /s /q') + end +end +function io.delFile(path) + os.remove(path) +end +function io.mkDir(dirname) + os.execute('mkdir "' .. dirname..'"') +end +function io.mkFile(filename,data,tp) + if not(tp) then tp='wb' end + if not(data) then data='' end + file = io.open(filename, tp) + if file==nil then return end + file:write(data) + file:close() +end +function io.movFile(path,topath) + io.cpFile(path,topath) + io.delFile(path) +end +function io.listFiles(dir) + if not(dir) then dir='' end + local f = io.popen('dir \''..dir..'\'') + if f then + return f:read('*a') + else + print('failed to read') + end +end +function io.getDir(dir) + if not dir then return io.getWorkingDir() end + if os.getOS()=='unix' then + return os.capture('cd '..dir..' ; cd') + else + return os.capture('cd '..dir..' & cd') + end +end +function io.getWorkingDir() + return io.popen'cd':read'*l' +end +function io.fileExists(path) + g=io.open(path or '','r') + if path =='' then + p='empty path' + return nil + end + if g~=nil and true or false then + p=(g~=nil and true or false) + end + if g~=nil then + io.close(g) + else + return false + end + return p +end +function io.fileCheck(file_name) + if not file_name then print('No path inputed') return false end + local file_found=io.open(file_name, 'r') + if file_found==nil then + file_found=false + else + file_found=true + end + return file_found +end +function io.dirExists(strFolderName) + strFolderName = strFolderName or io.getDir() + local fileHandle, strError = io.open(strFolderName..'\\*.*','r') + if fileHandle ~= nil then + io.close(fileHandle) + return true + else + if string.match(strError,'No such file or directory') then + return false + else + return true + end + end +end +function io.getAllItems(dir) + local t=os.capture("cd \""..dir.."\" & dir /a-d | find",true):lines() + return t +end +function io.listItems(dir) + if io.dirExists(dir) then + temp=io.listFiles(dir) -- current directory if blank + if io.getDir(dir)=='C:\\\n' then + a,b=string.find(temp,'C:\\',1,true) + a=a+2 + else + a,b=string.find(temp,'..',1,true) + end + temp=string.sub(temp,a+2) + list=string.linesToTable(temp) + temp=string.sub(temp,1,list[#list-2]) + slist=string.lines(temp) + table.remove(slist,1) + table.remove(slist,#slist) + temp={} + temp2={} + for i=1,#slist do + table.insert(temp,string.sub(slist[i],40,-1)) + end + return temp + else + return nil + end +end +function io.getDirectories(dir,l) + if dir then + dir=dir..'\\' + else + dir='' + end + local temp2=io.scanDir(dir) + for i=#temp2,1,-1 do + if io.fileExists(dir..temp2[i]) then + table.remove(temp2,i) + elseif l then + temp2[i]=dir..temp2[i] + end + end + return temp2 +end +function io.getFiles(dir,l) + if dir then + dir=dir..'\\' + else + dir='' + end + local temp2=io.scanDir(dir) + for i=#temp2,1,-1 do + if io.dirExists(dir..temp2[i]) then + table.remove(temp2,i) + elseif l then + temp2[i]=dir..temp2[i] + end + end + return temp2 +end +function io.getFullName(name) + local temp=name or arg[0] + if string.find(temp,'\\',1,true) or string.find(temp,'/',1,true) then + temp=string.reverse(temp) + a,b=string.find(temp,'\\',1,true) + if not(a) or not(b) then + a,b=string.find(temp,'/',1,true) + end + return string.reverse(string.sub(temp,1,b-1)) + end + return temp +end +function io.getName(file) + local name=io.getFullName(file) + name=string.reverse(name) + a,b=string.find(name,'.',1,true) + name=string.sub(name,a+1,-1) + return string.reverse(name) +end +function io.readFile(file) + local f = io.open(file, 'rb') + local content = f:read('*all') + f:close() + return content +end +function io.getExtension(file) + local file=io.getFullName(file) + file=string.reverse(file) + local a,b=string.find(file,'.',0,true) + local temp=string.sub(file,1,b) + return string.reverse(temp) +end +function io.pathToTable(path) + local p=io.splitPath(path) + local temp={} + temp[p[1]]={} + local last=temp[p[1]] + for i=2,#p do + snd=last + last[p[i]]={} + last=last[p[i]] + end + return temp,last,snd +end +function io.splitPath(str) + return string.split(str,'[\\/]+') +end + +function io.parseDir(dir,t) + io.tempFiles={} + function _p(dir) + local dirs=io.getDirectories(dir,true) + local files=io.getFiles(dir,true) + for i=1,#files do + p,l,s=io.pathToTable(files[i]) + if t then + s[io.getFullName(files[i])]=io.readFile(files[i]) + else + s[io.getFullName(files[i])]=io.open(files[i],'r+') + end + table.merge(io.tempFiles,p) + end + for i=1,#dirs do + table.merge(io.tempFiles,io.pathToTable(dirs[i])) + _p(dirs[i],t) + end + end + _p(dir) + return io.tempFiles +end +function io.parsedir(dir,f) + io.tempFiles={} + function _p(dir,f) + local dirs=io.getDirectories(dir,true) + local files=io.getFiles(dir,true) + for i=1,#files do + if not f then + table.insert(io.tempFiles,files[i]) + else + f(files[i]) + end + end + for i=1,#dirs do + _p(dirs[i],f) + end + end + _p(dir,f) + return io.tempFiles +end +function io.driveReady(drive) + drive=drive:upper() + if not(drive:find(':',1,true)) then + drive=drive..':' + end + drives=io.getDrives() + for i=1,#drives do + if drives[i]==drive then + return true + end + end + return false +end +function io.getDrives() + if os.getOS()=='windows' then + local temp={} + local t1=os.capture('wmic logicaldisk where drivetype=2 get deviceid, volumename',true) + local t2=os.capture('wmic logicaldisk where drivetype=3 get deviceid, volumename',true) + for drive,d2 in t1:gmatch('(.:)%s-(%w+)') do + if #d2>1 then + table.insert(temp,drive) + end + end + for drive in t2:gmatch('(.:)') do + table.insert(temp,drive) + end + return temp + end + error('Command is windows only!') +end +-- table Additions +function table.dump(t,indent) + local names = {} + if not indent then indent = '' end + for n,g in pairs(t) do + table.insert(names,n) + end + table.sort(names) + for i,n in pairs(names) do + local v = t[n] + if type(v) == 'table' then + if(v==t) then + print(indent..tostring(n)..': <-') + else + print(indent..tostring(n)..':') + table.dump(v,indent..' ') + end + else + if type(v) == 'function' then + print(indent..tostring(n)..'()') + else + print(indent..tostring(n)..': '..tostring(v)) + end + end + end +end +function table.alphanumsort(o) + local function padnum(d) local dec, n = string.match(d, '(%.?)0*(.+)') + return #dec > 0 and ('%.12f'):format(d) or ('%s%03d%s'):format(dec, #n, n) + end + table.sort(o, function(a,b) return tostring(a):gsub('%.?%d+',padnum)..('%3d'):format(#b)< tostring(b):gsub('%.?%d+',padnum)..('%3d'):format(#a) end) + return o +end +function table.foreach(t,f) + for i,v in pairs(t) do + f(v) + end +end +function table.merge(t1, t2) + for k,v in pairs(t2) do + if type(v) == 'table' then + if type(t1[k] or false) == 'table' then + table.merge(t1[k] or {}, t2[k] or {}) + else + t1[k] = v + end + else + t1[k] = v + end + end + return t1 +end +function table.print(tbl, indent) + if not indent then indent = 0 end + for k, v in pairs(tbl) do + formatting = string.rep(' ', indent) .. k .. ': ' + if type(v) == 'table' then + print(formatting) + table.print(v, indent+1) + else + print(formatting .. tostring(v)) + end + end +end +function table.merge(t1, t2) + for k,v in pairs(t2) do + if type(v) == 'table' then + if type(t1[k] or false) == 'table' then + table.merge(t1[k] or {}, t2[k] or {}) + else + t1[k] = v + end + else + t1[k] = v + end + end + return t1 +end +function table.clear(t) + for k in pairs (t) do + t[k] = nil + end +end +function table.copy(t) + function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy + end + return deepcopy(t) +end +function table.swap(tab,i1,i2) + tab[i1],tab[i2]=tab[i2],tab[i1] +end +function table.append(t1, ...) + t1,t2= t1 or {},{...} + for k,v in pairs(t2) do + t1[#t1+1]=t2[k] + end + return t1 +end +function table.compare(t1, t2,d) + if d then + return table.deepCompare(t1,t2) + end + --if #t1 ~= #t2 then return false end + if #t2>#t1 then + for i=1,#t2 do + if t1[i] ~= t2[i] then + return false,t2[i] + end + end + else + for i=1,#t1 do + if t1[i] ~= t2[i] then + return false,t2[i] + end + end + end + return true +end +function table.deepCompare(t1,t2) + if t1==t2 then return true end + if (type(t1)~='table') then return false end + local mt1 = getmetatable(t1) + local mt2 = getmetatable(t2) + if( not table.deepCompare(mt1,mt2) ) then return false end + for k1,v1 in pairs(t1) do + local v2 = t2[k1] + if( not table.deepCompare(v1,v2) ) then return false end + end + for k2,v2 in pairs(t2) do + local v1 = t1[k2] + if( not table.deepCompare(v1,v2) ) then return false end + end + return true +end +function table.has(t,_v) + for i,v in pairs(t) do + if v==_v then + return true + end + end + return false +end +function table.reverse(tab) + local size = #tab + local newTable = {} + for i,v in ipairs (tab) do + newTable[size-i] = v + end + for i=1,#newTable do + tab[i]=newTable[i] + end +end +-- Math Additions +local Y = function(g) local a = function(f) return f(f) end return a(function(f) return g(function(x) local c=f(f) return c(x) end) end) end +local F = function(f) return function(n)if n == 0 then return 1 else return n*f(n-1) end end end +math.factorial = Y(F) +math.fib={} +math.fib.fibL={} +setmetatable(math.fib,{__call=function(self,n) + if n<=2 then + return 1 + else + if self.fibL[n] then + return self.fibL[n] + else + local t=math.fib(n-1)+math.fib(n-2) + self.fibL[n]=t + return t + end + end +end}) +local floor,insert = math.floor, table.insert +function math.basen(n,b) + n = floor(n) + if not b or b == 10 then return tostring(n) end + local digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' + local t = {} + local sign = '' + if n < 0 then + sign = '-' + n = -n + end + repeat + local d = (n % b) + 1 + n = floor(n / b) + insert(t, 1, digits:sub(d,d)) + until n == 0 + return sign .. table.concat(t,'') +end +function math.convbase(n,b,tb) + return math.basen(tonumber(tostring(n),b),tb) +end +if BigNum then + function BigNum.mod(a,b) + return a-((a/b)*b) + end + local floor,insert = math.floor, table.insert + function math.basen(n,b) + n = BigNum.new(n) + if not b or b == 10 then return tostring(n) end + local digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' + local t = {} + local sign = '' + if n < BigNum.new(0) then + sign = '-' + n = -n + end + repeat + local d = BigNum.mod(n , b) + 1 + n = n/b + d=tonumber(tostring(d)) + insert(t, 1, digits:sub(d,d)) + until tonumber(tostring(n)) == 0 + return sign .. table.concat(t,'') + end + function math.to10(n,b) + local num=tostring(n) + local sum=BigNum.new() + local digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' + for i=1,#num do + local v=digits:find(num:sub(i,i),1,true) + sum=sum+BigNum.new(tonumber(v)-1)*BigNum.pow(BigNum.new(b),BigNum.new(#num-i)) + end + return sum + end + function math.convbase(n,b,tb) + return math.basen(math.to10(n,b),tb) + end +end +function math.numfix(n,x) + local str=tostring(n) + if #strmaxx then - maxx=temp[i].width+temp[i].offset.pos.x - elseif temp[i].height+temp[i].offset.pos.y>maxy then - maxy=temp[i].height+temp[i].offset.pos.y + if temp[i].width+temp[i].x>maxx then + maxx=temp[i].width+temp[i].x + end + if temp[i].height+temp[i].y>maxy then + maxy=temp[i].height+temp[i].y end end - return maxx,maxy + return maxx,maxy,px,py end \ No newline at end of file diff --git a/GuiManager/Image-Animation/getTile.int b/GuiManager/Misc/getTile.int similarity index 100% rename from GuiManager/Image-Animation/getTile.int rename to GuiManager/Misc/getTile.int diff --git a/GuiManager/Misc/isDescendant.int b/GuiManager/Misc/isDescendant.int index 5c9c2a5..f004182 100644 --- a/GuiManager/Misc/isDescendant.int +++ b/GuiManager/Misc/isDescendant.int @@ -1,7 +1,7 @@ function gui:isDescendant(obj) - local things=obj:GetAllChildren() + local things = obj:GetAllChildren() for i=1,#things do - if things[i]==self then + if things[i] == self then return true end end diff --git a/GuiManager/Misc/newScrollMenu.int b/GuiManager/Misc/newScrollMenu.int index 3dbfdaf..f7ee5ac 100644 --- a/GuiManager/Misc/newScrollMenu.int +++ b/GuiManager/Misc/newScrollMenu.int @@ -1,98 +1,81 @@ -function gui:newScrollMenu(title,tabN,onloop,x, y, w, h, sx ,sy ,sw ,sh) - local Main = self:newFrame(x, y, w, h, sx ,sy ,sw ,sh) - local Title=Main:newTextButton(title,"Title",0,0,0,20,0,0,1) - Title.Tween=-4 - Title.FontSize=12 - Title:OnReleased(function(b,self) - self.Parent.Tick=not(self.Parent.Tick) - end) - local scroll=Main:newTextButton("","Scroll",-20,20,20,-20,1,0,0,1) - scroll:OnClicked(function(b,self,x,y) - self.Parent.Mover:SetDualDim(0,y-10,20,20) - if self.Parent.Mover.offset.pos.y<0 then - self.Parent.Mover:SetDualDim(0,0,20,20) - end - if self.Parent.Mover.offset.pos.y>self.Parent.height-40 then - self.Parent.Mover:SetDualDim(0,self.Parent.height-40,20,20) - end - local temp = #self.Parent.TList - self.Parent.pos=(math.floor((temp*self.Parent.Mover.offset.pos.y)/self.height))+1 - end) - Main:OnUpdate(function(self) - if self.Tick==false then - self.Visibility=0 - end - end) - scroll:OnUpdate(function(self) - self.Visible=self.Parent.Tick - end) - local Mover=scroll:newTextLabel("",0,0,20,20) - Main.Mover=Mover - Main.TList=tabN - Main.pos=1 - Main.Tick=true - function Main:Update(title,tabN,onloop) - ch=self:getChildren() - for i=#ch,1,-1 do - ch[i]:Destroy() - end - Title=Main:newTextButton(title,"Title",0,0,0,20,0,0,1) - Title.Tween=-4 - Title.FontSize=12 - Title:OnReleased(function(b,self) - self.Parent.Tick=not(self.Parent.Tick) - end) - scroll=Main:newTextButton("","Scroll",-20,20,20,-20,1,0,0,1) - scroll:OnClicked(function(b,self,x,y) - self.Parent.Mover:SetDualDim(0,y-10,20,20) - if self.Parent.Mover.offset.pos.y<0 then - self.Parent.Mover:SetDualDim(0,0,20,20) - end - if self.Parent.Mover.offset.pos.y>self.Parent.height-40 then - self.Parent.Mover:SetDualDim(0,self.Parent.height-40,20,20) - end - local temp = #self.Parent.TList - self.Parent.pos=(math.floor((temp*self.Parent.Mover.offset.pos.y)/self.height))+1 - end) - local Mover=scroll:newTextLabel("",0,0,20,20) - Main.Mover=Mover - Main.TList=tabN - Main.pos=1 - Main.Tick=true - scroll:OnUpdate(function(self) - self.Visible=self.Parent.Tick - end) - for i=1,math.floor(Main.height/20)-1 do - local temp=Main:newTextButton("","Item"..i,0,i*20,-20,20,0,0,1) - temp.FontSize=10 - temp.Tween=-4 - temp.pos=i - temp:OnUpdate(function(self) - self.text=self.Parent.TList[(self.Parent.pos+self.pos)-1] - self.Visible=self.Parent.Tick - end) - if onloop then - onloop(temp,i) +function gui:newScrollMenu(name) + local temp = self:newFullFrame(name) + temp.ref = { + [[setNewFont(16)]], + [[setRoundness(10,10,180)]], + Tween = 6 + } + temp.allowOverlapping = true + temp.Visibility = 0 + local ScrollY = temp:newFrame(name.."ScrollY",-20,0,20,0,1,0,0,1) + temp.scroll = ScrollY + ScrollY.Color=Color.new(80,80,80) + ScrollY.allowOverlapping = true + ScrollY.Mover = ScrollY:newFrame(name.."MoverY",5,5,10,80) + ScrollY.Mover.Color = Color.new(60,60,60) + local func = function(b,self,x,y,nn) + temp.symbolicY = y + if y>45 and yScrollY.height-40 then + temp.symbolicY = ScrollY.height-40 + end + func("l",ScrollY,x,temp.symbolicY,true) + end) + temp.ClipDescendants=true + temp.first = temp:newTextLabel("","",15,10,-50,40,0,0,1) + local nice = temp:newTextLabel(name,name,15,10,-50,40,0,0,1) + temp.header = nice + temp.last = temp.first + temp.last.BorderSize = 0 + temp.last.Visibility = 0 + nice:setNewFont(26) + nice.Tween = 6 + temp.list = {} + local alarm + multi:newLoop(function() + for i=1,#temp.list do + local val = (temp.first.y+(temp.list[i].staticpos)+10) + if val>temp.y and val self.x+width then + curpos = #hiddenText+1 + elseif x < self.x then + curpos = 1 + else + for i = 1,#hiddenText do + width = self.Font:getWidth(self.text:sub(1,i)) + if x-self.x < width then + curpos = i + break end end - self.Active=true end - end - c:OnClicked(function(b,self,x,y) - local dwidth, wrappedtext = _defaultfont:getWrap(self.text:sub(1,self.cursor[1]), self.width) - local height = _defaultfont:getHeight() - if #wrappedtext>=1 then - width= _defaultfont:getWidth(wrappedtext[#wrappedtext]) - self.cursor[2]=#wrappedtext - else - self.cursor[2]=1 - width=0 - end - yc=math.ceil(((y/self.DPI)-(self.FontHeight/2)+self.Tween-self.y)/height) - xc=math.floor(x) end) - c:AddDrawRuleE(function(self) - if self.Active then - local dwidth, wrappedtext = _defaultfont:getWrap(self.text:sub(1,self.cursor[1]), self.width) - local height = _defaultfont:getHeight() - if #wrappedtext>=1 then - width= _defaultfont:getWidth(wrappedtext[#wrappedtext]) - self.cursor[2]=#wrappedtext - else - self.cursor[2]=1 - width=0 - end - x1=width+2+self.x+self.XTween - y1=(self.y+(height*(self.cursor[2]-1))+(self.FontHeight/2)+self.Tween)*self.DPI - x2=width+2+self.x+self.XTween - y2=(self.y+(self.FontHeight/2)+self.Tween*self.DPI)+height*self.cursor[2] - love.graphics.line(x1,y1,x2,y2) - end + c:OnPressedOuter(function(b,self) + if Focused then + self:unfocus() + end end) c:OnUpdate(function(self) - if love.keyboard.isDown("backspace") and self.Active and self.cooldown==false then - if #self.text>0 then - self.text = self.text:remove(self.cursor[1]) - self.ttext = self.ttext:remove(self.cursor[1]) - self.cursor[1]=self.cursor[1]-1 - end - self.cooldown=true - self.Alarm:Reset() - elseif love.keyboard.isDown("backspace")==false then - self.cooldown=false + if #hiddenText==0 then self.text = "" return end + if self.hideText then + self.text = table.concat(hiddenText) + else + self.text = table.concat(realText) end - if love.keyboard.isDown("left") and self.arrowkeys==false and self.Active then - self.arrowkeys=true - self.cursor[1]=self.cursor[1]-1 - if self.cursor[1]<0 then - self.cursor[1]=0 - end - self.ArrowAlarm:Reset() - elseif love.keyboard.isDown("right") and self.arrowkeys==false and self.Active then - self.arrowkeys=true - self.cursor[1]=self.cursor[1]+1 - if self.cursor[1]>#self.text then - self.cursor[1]=#self.text - end - self.ArrowAlarm:Reset() - end - if love.keyboard.isDown("delete") and self.Active then - if #self.text>0 then - self.text = "" - self.ttext = "" - self.cursor[1]=1 - end - elseif (love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift")) and love.keyboard.isDown("return") and self.cooldown2==false then - self.text=self.text.."\n" - self.ttext=self.ttext.."\n" - self.cooldown2=true - c.Alarm2:Reset() - elseif (love.keyboard.isDown("return") or love.keyboard.isDown("kpenter")) and self.Active and self.Enter and not(love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift")) then - if self.LoseFocusOnEnter then - self.Active=false - else - self.Active=true - end - for cc=1,#self.funcE do - self.funcE[cc](self,self.ttext) - end + self.TextFormat = "left" + end) + multi.OnTextInput(function(t) + table.insert(hiddenText,curpos,"*") + table.insert(realText,curpos,t) + curpos = curpos + 1 + if autoScaleFont then + c:fitFont() end end) - table.insert(gui.TB,c) - return c -end ---TEXT BOX HELPER FUNCTION -function love.textinput(t) - for tb=1,#gui.TB do - if gui.TB[tb]~=nil then - if gui.TB[tb].Active then - if gui.TB[tb].hidden then - --gui.TB[tb].text=gui.TB[tb].text.."*" - gui.TB[tb].text=gui.TB[tb].text:insert(gui.TB[tb].cursor[1],"*") - else - --gui.TB[tb].text=gui.TB[tb].text..t - gui.TB[tb].text=gui.TB[tb].text:insert(gui.TB[tb].cursor[1],t) - end - gui.TB[tb].ttext=gui.TB[tb].ttext:insert(gui.TB[tb].cursor[1],t) - gui.TB[tb].cursor[1]=gui.TB[tb].cursor[1]+1 + multi.OnKeyPressed(function(key, scancode, isrepeat ) + if key == "backspace" then + table.remove(hiddenText,curpos-1) + table.remove(realText,curpos-1) + curpos = curpos - 1 + if curpos < 1 then + curpos = 1 + end + if autoScaleFont then + c:fitFont() + end + elseif key == "enter" then + + elseif key == "delete" then + realText = {} + hiddenText = {} + curpos = 1 + elseif key == "left" then + curpos = curpos - 1 + if curpos < 1 then + curpos = 1 + end + moved = true + alarm:Reset() + elseif key == "right" then + curpos = curpos + 1 + if curpos > #realText+1 then + curpos = #realText+1 + end + moved = true + alarm:Reset() + end + end) + local blink = false + multi:newThread("TextCursonBlinker",function() + while true do + thread.sleep(1.5) + blink = not blink + end + end) + self.DrawRulesE = {function() + if --[[blink or moved]] true then + local width = c.Font:getWidth(c.text:sub(1,curpos-1)) + local height = c.Font:getHeight() + if c.TextFormat == "center" then + -- print(c.x+(c.width/2+width),c.height,c.x+(c.width/2+width),c.height+height) + -- love.graphics.line(c.x+(c.width/2+width),c.height,c.x+(c.width/2+width),c.height+height) + elseif c.TextFormat == "right" then + --love.graphics.line(c.x+width,c.y,c.x+width,c.y+c.Font:getHeight()) + elseif c.TextFormat == "left" then + love.graphics.line(c.x+width,c.y,c.x+width,c.y+height) end end - end + end} + return c end \ No newline at end of file diff --git a/GuiManager/Text/newTextButton.int b/GuiManager/Text/newTextButton.int index da2f3f6..be43ef0 100644 --- a/GuiManager/Text/newTextButton.int +++ b/GuiManager/Text/newTextButton.int @@ -1,21 +1,10 @@ function gui:newTextButton(t,name, x, y, w, h, sx ,sy ,sw ,sh) - x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh) - local c=self:newBase("TextButton",name, x, y, w, h, sx ,sy ,sw ,sh) - c.Tween=0 - c.XTween=0 - c.FontHeight=_defaultfont:getHeight() - c.Font=_defaultfont - c.FontSize=15 - c.TextFormat="center" - c.text = t - c.AutoScaleText=false - c.TextVisibility=1 -- 0=invisible,1=solid (self.TextVisibility*254+1) - c.Color = {220, 220, 220} - c.TextColor = {0, 0, 0} - c:OnEnter(function() + local x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh) + local c=self:newTextBase("TextButton",t,name, x, y, w, h, sx ,sy ,sw ,sh) + c:OnMouseEnter(function() love.mouse.setCursor(_GuiPro.CursorH) end) - c:OnExit(function() + c:OnMouseExit(function() love.mouse.setCursor(_GuiPro.CursorN) end) return c diff --git a/GuiManager/Text/newTextLabel.int b/GuiManager/Text/newTextLabel.int index 4424d0e..679224d 100644 --- a/GuiManager/Text/newTextLabel.int +++ b/GuiManager/Text/newTextLabel.int @@ -1,16 +1,4 @@ function gui:newTextLabel(t,name, x, y, w, h, sx ,sy ,sw ,sh) - x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh) - local c=self:newBase("TextLabel",name, x, y, w, h, sx ,sy ,sw ,sh) - c.Tween=0 - c.XTween=0 - c.FontHeight=_defaultfont:getHeight() - c.Font=_defaultfont - c.FontSize=15 - c.TextFormat="center" - c.text = t - c.AutoScaleText=false - c.TextVisibility=1 -- 0=invisible,1=solid (self.TextVisibility*254+1) - c.Color = {220, 220, 220} - c.TextColor = {0, 0, 0} - return c + local x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh) + return self:newTextBase("TextLabel",t,name, x, y, w, h, sx ,sy ,sw ,sh) end \ No newline at end of file diff --git a/GuiManager/Misc/setDefualtFont.int b/GuiManager/Text/setDefualtFont.int similarity index 100% rename from GuiManager/Misc/setDefualtFont.int rename to GuiManager/Text/setDefualtFont.int diff --git a/GuiManager/Text/setNewFont.int b/GuiManager/Text/setNewFont.int new file mode 100644 index 0000000..9b0c840 --- /dev/null +++ b/GuiManager/Text/setNewFont.int @@ -0,0 +1,9 @@ +function gui:setNewFont(filename,FontSize) + if type(filename)=="string" then + self.FontFile = filename + self.Font = love.graphics.newFont(filename, tonumber(FontSize)) + else + self.Font=love.graphics.newFont(tonumber(filename)) + end + self.Font:setFilter("linear","nearest",4) +end \ No newline at end of file diff --git a/GuiManager/Misc/setgetText.int b/GuiManager/Text/setgetText.int similarity index 100% rename from GuiManager/Misc/setgetText.int rename to GuiManager/Text/setgetText.int diff --git a/GuiManager/Text/widthToFontSize.int b/GuiManager/Text/widthToTextSize.int similarity index 100% rename from GuiManager/Text/widthToFontSize.int rename to GuiManager/Text/widthToTextSize.int diff --git a/GuiManager/init.lua b/GuiManager/init.lua index 2eba1e6..377703e 100644 --- a/GuiManager/init.lua +++ b/GuiManager/init.lua @@ -1,9 +1,34 @@ +local multi = require("multi") +local GLOBAL,THREAD=require("multi.integration.loveManager").init() +-- automatic resource loading will be added soonish utf8 = require("utf8") gui = {} gui.__index = gui gui.TB={} gui.Version="VERSION" -- Is it really ready for release? -_GuiPro={GBoost=true,hasDrag=false,DragItem={},Children={},Visible=true,count=0,x=0,y=0,height=0,width=0,update=function(self) local things=GetAllChildren2(self) UpdateThings(things) end,draw=function(self) local things=GetAllChildren(self) DrawThings(things) end,getChildren=function(self) return self.Children end} +_GuiPro={ + GLOBAL = GLOBAL, + THREAD = THREAD, + jobqueue = multi:newSystemThreadedJobQueue(4), + imagecache = {}, + GBoost=true, + hasDrag=false, + DragItem={}, + Children={}, + Visible=true, + count=0, + x=0, + y=0, + height=0, + width=0, + getChildren=function(self) + return self.Children + end +} +_GuiPro.jobqueue:registerJob("LoadImage",function(path,t) + local dat = love.image.newImageData(path) + return dat,path,t +end) _GuiPro.Clips={} _GuiPro.rotate=0 _defaultfont = love.graphics.setNewFont(12) @@ -16,8 +41,7 @@ function gui:LoadInterface(file) if a then --print("Loaded: "..file) else - print("Error loading file: "..file) - print(a,b) + print("Error loading file: "..file,b) end else print("File does not exist!") @@ -42,14 +66,18 @@ gui.LoadAll("GuiManager/Misc") gui.LoadAll("GuiManager/Text") gui.LoadAll("GuiManager/Drawing") -multi.boost=2 -- End of Load gui:respectHierarchy() _GuiPro.width,_GuiPro.height=love.graphics.getDimensions() -multi:newLoop():OnLoop(function() _GuiPro.width,_GuiPro.height=love.graphics.getDimensions() _GuiPro:update() end) -multi:onDraw(function() _GuiPro:draw() end) +multi:newLoop(function() _GuiPro.width,_GuiPro.height=love.graphics.getDimensions() end) +multi:onDraw(function() + local items=GetAllChildren(_GuiPro) + for i=1,#items do + items[i]:draw() + end +end) gui.ff=gui:newFrame("",0,0,0,0,0,0,1,1) -gui.ff.Color={255,255,255} +gui.ff.Color={0,0,0} gui.ff:OnUpdate(function(self) self:BottomStack() end)