some little changes

This commit is contained in:
Josh
2018-06-05 16:53:12 -05:00
parent e31e4bf66c
commit fa8d66026f
9 changed files with 169 additions and 44 deletions

View File

@@ -4,6 +4,7 @@ return {
JUIScene = require("lib.classes.JUIScene"),
Frame = require("lib.classes.Frame"),
Label = require("lib.classes.Label"),
Button = require("lib.classes.Button"),
-- Datatypes
@@ -11,7 +12,7 @@ return {
Dimension = require("lib.datatypes.Dimension"),
Color = require("lib.datatypes.Color"),
parent = function(parent, child)
parent = function(self, parent, child)
parent:addChild(child)
child:setParent(parent)
end,

73
lib/classes/Button.lua Normal file
View File

@@ -0,0 +1,73 @@
local UIButton = require("lib.classes.UIButton")
local Color = require("lib.datatypes.Color")
local Button = UIButton:subclass("Button")
function Button:init()
self.super:init()
self.text = "Button"
self.textColor = Color:new(0, 0, 0)
self.textAlignment = "left"
self.textSize = 12
self.font = love.graphics.newFont(12)
self.fontFace = nil
end
function Button:recalculateInternalFont()
if self.fontFace then
self.font = love.graphics.newFont(self.fontFace, self.textSize)
else
self.font = love.graphics.newFont(self.textSize)
end
end
function Button:getText()
return self.text
end
function Button:getTextAlignment()
return self.textAlignment
end
function Button:getFontFace()
return self.fontFace
end
function Button:getTextSize()
return self.textSize
end
function Button:setText(text)
self.text = text
end
function Button:setTextAlignment(alignment)
self.textAlignment = alignment
end
function Button:setFontFace(fontface)
self.fontFace = fontface
self:recalculateInternalFont()
end
function Button:setTextSize(size)
self.textSize = (size >= 1) and size or 1
self:recalculateInternalFont()
end
function Button:render()
self.super:render()
local absPos = self:getAbsolutePosition()
local absSize = self:getAbsoluteSize()
love.graphics.setFont(self.font)
love.graphics.setColor(self.textColor:out())
love.graphics.printf(self.text, absPos.x, absPos.y, absSize.x, self.textAlignment)
love.graphics.setFont(self.baseReturnFont)
self:renderChildren()
end
return Button

View File

@@ -18,4 +18,9 @@ function Frame:init()
self.super:init()
end
function Frame:render()
self.super:render()
self:renderChildren()
end
return Frame

View File

@@ -35,4 +35,9 @@ function JUIScene:getAbsoluteSize()
return Vector2D:new(love.graphics.getWidth(), love.graphics.getHeight())
end
function JUIScene:render()
self.super:render()
self:renderChildren()
end
return JUIScene

View File

@@ -83,13 +83,11 @@ function Label:setTextSize(size)
end
function Label:render()
self.super:render()
local absPos = self:getAbsolutePosition()
local absSize = self:getAbsoluteSize()
self.super:render()
love.graphics.setFont(self.font)
love.graphics.setColor(self.textColor:out())
love.graphics.printf(self.text, absPos.x, absPos.y, absSize.x, self.textAlignment)

View File

@@ -53,15 +53,11 @@ function UIBase:updateChildren(delta)
end
function UIBase:render()
--if not self.active then return end
self:renderChildren()
end
function UIBase:update(delta)
--if not self.active then return end
self:updateChildren(delta)
self:updateChildren(delta)
end

View File

@@ -1,17 +1,46 @@
local UIRect = require("lib.classes.UIRect")
local Event = require("lib.classes.Event")
local UIButton = UIRect:subclass("UIButton")
function UIButton:init()
self.super:init()
self.mouseDown = true
self.mouseClick = Event:new()
self.mouseClickReleaseInvalid = Event:new()
self.mouseClickRelease = Event:new()
end
function UIButton:mouseEnterCall()
self.super:mouseEnterCall()
end
function UIButton:mouseExitCall()
self.super:mouseExitCall()
end
function UIButton:update(delta)
self.super:update()
self.super:update(delta)
if self.mouseOver and love.mouse.isDown(1) then
self.mouseDown = true
self.mouseClickRelease:call()
end
if self.mouseDown == true then
if love.mouse.isDown(1) then
self.mouseDown = false
if self.mouseOver then
self.mouseClick:call()
end
end
end
end
function UIButton:render()
self.super:render()
end
return UIButton

View File

@@ -52,7 +52,7 @@ function UIRect:init()
self.borderWidth = 2
self.backgroundTransparency = 0
self.borderTransparency = 0
self.cornerRounding = 1
self.cornerRounding = 0
self.size = Dimension:new(0.2, 0.12)
self.position = Dimension:new(0, 0)
self.mouseOver = false
@@ -127,6 +127,14 @@ function UIRect:getSize()
return self.size
end
function UIRect:mouseEnterCall()
self.mouseEnter:call()
end
function UIRect:mouseExitCall()
self.mouseExit:call()
end
function UIRect:update(delta)
self.super:update(delta)
@@ -148,13 +156,13 @@ function UIRect:update(delta)
if (self.mouseOver == false) then
self.mouseOver = true
self.mouseEnter:call()
self:mouseEnterCall()
end
else
if (self.mouseOver == true) then
self.mouseOver = false
self.mouseExit:call()
self:mouseExitCall()
end
end
end
@@ -192,20 +200,20 @@ function UIRect:getAbsolutePosition()
end
function UIRect:render()
self.super:render()
local pos = self:getAbsolutePosition()
local size = self:getAbsoluteSize()
love.graphics.setColor(self.borderColor:out())
-- border
love.graphics.rectangle("line", pos.x-self.borderWidth, pos.y-self.borderWidth, size.x+(self.borderWidth*2), size.y+(self.borderWidth*2), self.cornerRounding, self.cornerRounding)
love.graphics.setColor(self.backgroundColor:out())
-- background
love.graphics.rectangle("fill", pos.x, pos.y, size.x, size.y, self.cornerRounding, self.cornerRounding, 25)
self.super:render()
--self:renderChildren()
self.renders = self.renders + 1
love.graphics.setColor(self.borderColor:out())
love.graphics.setLineWidth(self.borderWidth)
-- border
love.graphics.rectangle("line", pos.x-(self.borderWidth/2), pos.y-(self.borderWidth/2), size.x+self.borderWidth, size.y+self.borderWidth, self.cornerRounding, self.cornerRounding)
end
return UIRect

View File

@@ -5,34 +5,46 @@
local JUI = require("JUIlib")
local bigboy = JUI.Dimension:new(0.3, 0.2)
local bigboy = JUI.Dimension:new(0.6, 0.6)
local mainmenu = JUI.JUIScene:new()
local background = JUI.Frame:new()
background:setSize(bigboy)
background:setPosition(bigboy)
background:setCornerRounding(0)
background:setSize(bigboy)
local emptyColor = JUI.Label:new()
emptyColor:setSize(JUI.Dimension:new(0.3, 0.1))
emptyColor:setPosition(JUI.Dimension:new(0.2, 0.8))
emptyColor:setBorderColor(JUI.Color:new(0.5, 0.5, 0.5))
emptyColor:setBorderWidth(2)
emptyColor:setTextSize(22)
emptyColor:setCornerRounding(5)
emptyColor:setBackgroundColor(JUI.Color:new(200/255, 69/255, 128/255))
emptyColor:setTextAlignment("center")
emptyColor:setText("Bottom Text")
emptyColor.mouseEnter:connect(function()
emptyColor:setText("Inside")
end)
emptyColor.mouseExit:connect(function()
emptyColor:setText("Outside")
end)
emptyColor:setSize(JUI.Dimension:new(0.3, 0.1))
emptyColor:setPosition(JUI.Dimension:new(0.2, 0.8))
emptyColor:setBorderColor(JUI.Color:new(0.5, 0.5, 0.5))
emptyColor:setTextSize(22)
emptyColor:setBackgroundColor(JUI.Color:new(200/255, 69/255, 128/255))
emptyColor:setTextAlignment("center")
emptyColor:setText("Bottom Text")
JUI.parent(mainmenu, background)
JUI.parent(mainmenu, emptyColor)
emptyColor.mouseEnter:connect(function()
emptyColor:setText("Inside")
end)
emptyColor.mouseExit:connect(function()
emptyColor:setText("Outside")
end)
local button = JUI.Button:new()
button:setSize(JUI.Dimension:new(0.3, 0.5))
button:setPosition(JUI.Dimension:new(0.2, 0.2))
button:setBackgroundColor(JUI.Color:new(0.2, 0.3, 0.5))
button.mouseClick:connect(function()
button:setText("THUG")
end)
button.mouseClickRelease:connect(function()
button:setText("a")
end)
JUI:parent(mainmenu, background)
JUI:parent(mainmenu, emptyColor)
JUI:parent(background, button)
local function round(number, decimalPlaces)
local placer = 10^(-decimalPlaces)
@@ -70,7 +82,6 @@ function love.update(delta)
local hasFocus = "\tfocus: "..tostring(love.window.hasFocus())
local luaMem = "\tluamem: "..luaEngineMemory.."kB"
local luaMemHigh = "\tluamemhigh: "..luaHighestMem.."kb"
debugInfoString = fps..os..coreCount..displayCount..hasFocus..luaMem..luaMemHigh
end
@@ -80,7 +91,6 @@ function love.draw()
mainmenu:render()
love.graphics.setColor(1, 1, 1)
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), 22)
love.graphics.setColor(0, 0, 0)