This commit is contained in:
Josh
2018-06-04 02:28:51 -05:00
parent 4124190bb2
commit 444acb408f
8 changed files with 81 additions and 69 deletions

View File

@@ -10,8 +10,6 @@ return {
Vector2D = require("lib.datatypes.Vector2D"),
Dimension = require("lib.datatypes.Dimension"),
Color = require("lib.datatypes.Color"),
HexColor = require("lib.datatypes.HexColor"),
RGBColor = require("lib.datatypes.RGBColor"),
parent = function(parent, child)
parent:addChild(child)

View File

@@ -1,5 +1,5 @@
local UIRect = require("lib.classes.UIRect")
local RGBColor = require("lib.datatypes.RGBColor")
local Color = require("lib.datatypes.Color")
local Label = UIRect:subclass("Label")
--[[
@@ -32,7 +32,7 @@ function Label:init()
self.super:init()
self.text = "Label"
self.textColor = RGBColor:new(0, 0, 0)
self.textColor = Color:new(0, 0, 0)
self.textAlignment = "left"
self.textSize = 12
self.font = love.graphics.newFont(12)
@@ -51,6 +51,10 @@ function Label:getText()
return self.text
end
function Label:getTextAlignment()
return self.textAlignment
end
function Label:getFontFace()
return self.fontFace
end
@@ -63,6 +67,11 @@ function Label:setText(text)
self.text = text
end
function Label:setTextAlignment(alignment)
self.textAlignment = alignment
end
function Label:setFontFace(fontface)
self.fontFace = fontface
self:recalculateInternalFont()
@@ -84,8 +93,7 @@ function Label: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)
love.graphics.setFont(love.graphics.newFont(12))
love.graphics.setFont(self.baseReturnFont)
self:renderChildren()
end

View File

@@ -33,7 +33,7 @@ function UIBase:init()
self.active = true
self.children = {}
self.parent = nil
self.baseReturnFont = love.graphics.newFont(12)
end
function UIBase:renderChildren()

View File

@@ -6,4 +6,12 @@ function UIButton:init()
end
function UIButton:update(delta)
self.super:update()
end
function UIButton:render()
end
return UIButton

View File

@@ -1,7 +1,7 @@
local UIBase = require("lib.classes.UIBase")
local Dimension = require("lib.datatypes.Dimension")
local Vector2D = require("lib.datatypes.Vector2D")
local RGBColor = require("lib.datatypes.RGBColor")
local Color = require("lib.datatypes.Color")
local Event = require("lib.classes.Event")
--[[
@@ -47,8 +47,8 @@ local UIRect = UIBase:subclass("UIRect")
function UIRect:init()
self.super:init()
self.backgroundColor = RGBColor:new(255, 255, 255)
self.borderColor = RGBColor:new(0, 0, 0)
self.backgroundColor = Color:new(1, 1, 1)
self.borderColor = Color:new(0, 0, 0)
self.borderWidth = 2
self.backgroundTransparency = 0
self.borderTransparency = 0
@@ -56,6 +56,7 @@ function UIRect:init()
self.size = Dimension:new(0.2, 0.12)
self.position = Dimension:new(0, 0)
self.mouseOver = false
self.renders = 0
-- events
self.mouseEnter = Event:new()
@@ -74,6 +75,14 @@ function UIRect:getBorderColor()
return self.borderColor
end
function UIRect:getBorderWidth()
return self.borderWidth
end
function UIRect:setBorderWidth(width)
self.borderWidth = width
end
function UIRect:setBorderColor(color)
self.borderColor = color
end
@@ -161,7 +170,8 @@ function UIRect:getAbsoluteSize()
local absoluteSizeX = size.x.pixel + parentAbsSize.x * size.x.scale
local absoluteSizeY = size.y.pixel + parentAbsSize.y * size.y.scale
return Vector2D:new(absoluteSizeX, absoluteSizeY)
--return Vector2D:new(absoluteSizeX, absoluteSizeY)
return {x = absoluteSizeX, y = absoluteSizeY}
end
function UIRect:getAbsolutePosition()
@@ -176,7 +186,8 @@ function UIRect:getAbsolutePosition()
local absolutePosX = parentAbsPos.x + pos.x.pixel + parentAbsSize.x * pos.x.scale
local absolutePosY = parentAbsPos.y + pos.y.pixel + parentAbsSize.y * pos.y.scale
return Vector2D:new(absolutePosX, absolutePosY)
--return Vector2D:new(absolutePosX, absolutePosY)
return {x = absolutePosX, y = absolutePosY}
end
function UIRect:render()
@@ -186,14 +197,15 @@ function UIRect:render()
love.graphics.setColor(self.borderColor:out())
-- border
love.graphics.rectangle("fill", pos.x-self.borderWidth, pos.y-self.borderWidth, size.x+(self.borderWidth*2), size.y+(self.borderWidth*2), self.cornerRounding, self.cornerRounding)
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*(11/12), self.cornerRounding*(11/12))
love.graphics.rectangle("fill", pos.x, pos.y, size.x, size.y, self.cornerRounding, self.cornerRounding, 25)
--self.super:render()
-- self:renderChildren()
self.super:render()
--self:renderChildren()
self.renders = self.renders + 1
end
return UIRect

View File

@@ -1,23 +0,0 @@
local Color = require("lib.datatypes.Color")
local HexColor = Color:subclass("HexColor")
function HexColor:init(color)
self.color = color
end
function HexColor:out()
local hex = self.color:gsub("#","")
return tonumber("0x"..hex:sub(1,2))/255, tonumber("0x"..hex:sub(3,4))/255, tonumber("0x"..hex:sub(5,6))/255
end
function HexColor:outTable()
local hex = self.color:gsub("#","")
return {
tonumber("0x"..hex:sub(1,2))/255,
tonumber("0x"..hex:sub(3,4))/255,
tonumber("0x"..hex:sub(5,6))/255
}
end
return HexColor

View File

@@ -1,20 +0,0 @@
local DataType = require("lib.datatypes.DataType")
local RGBColor = DataType:subclass("RGBColor")
function RGBColor:init(red, green, blue)
self.r = red or 255
self.g = green or 255
self.b = blue or 255
end
function RGBColor:out()
return self.r/255, self.g/255, self.b/255
end
function RGBColor:outTable()
return {self.r/255, self.g/255, self.b/255}
end
return RGBColor

View File

@@ -7,32 +7,37 @@ local JUI = require("JUIlib")
local bigboy = JUI.Dimension:new(0.3, 0.2)
local mainmenu = JUI.JUIScene:fromFatboy()
local mainmenu = JUI.JUIScene:new()
local background = JUI.Frame:new()
background:setSize(bigboy)
background:setPosition(bigboy)
background:setCornerRounding(0)
local emptyColor = JUI.Label:new()
--[[local emptyColor = JUI.Label:new()
emptyColor:setSize(JUI.Dimension:new(0.3, 0.1))
emptyColor:setPosition(JUI.Dimension:new(0.2, 0.8))
emptyColor:setBackgroundColor(JUI.RGBColor:new(200, 69, 128))
emptyColor:setTextSize(36)
emptyColor:setBorderColor(JUI.Color:new(0.5, 0.5, 0.5))
emptyColor:setBorderWidth(2)
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)
end)]]
local backgroundColor = JUI.HexColor:new("#FFFFFF")
JUI.parent(mainmenu, background)
JUI.parent(mainmenu, emptyColor)
--JUI.parent(mainmenu, emptyColor)
local windowCreationSuccess
local debugInfoString = ""
local renderStats = nil
local normalRenders = 0
function love.load()
windowCreationSuccess = love.window.setMode(1024, 600, {
@@ -42,16 +47,40 @@ function love.load()
minwidth = 640,
minheight = 480,
})
love.graphics.setBackgroundColor(0.7, 0.8, 1)
end
function love.update(delta)
mainmenu:update(delta)
mainmenu:update(delta)
do
if not renderStats then return end
local fps = "fps: "..tostring(love.timer.getFPS())
local os = "\tos: "..love.system.getOS()
local coreCount = "\tcores: "..love.system.getProcessorCount()
local displayCount = "\tdisplays: "..love.window.getDisplayCount()
local hasFocus = "\tfocus: "..tostring(love.window.hasFocus())
local luaMem = "\tluamem: "..(math.floor(collectgarbage('count')/1000)).."mB"
local drawStats = "\tdrawcalls: "..renderStats.drawcalls.."\ttexturemem: "..renderStats.texturememory.."\tfonts: "..renderStats.fonts
local mainChildren = "\tobjs: "..#mainmenu:getChildren()+1
local thingRenders = "\trcount: "..background.renders.."\tnrcount: "..normalRenders
debugInfoString = fps..os..coreCount..displayCount..hasFocus..luaMem..drawStats..mainChildren..thingRenders
end
end
function love.draw()
mainmenu:render()
love.graphics.setColor((backgroundColor):out())
love.graphics.print("fps: "..tostring(love.timer.getFPS()), 4, 4)
love.graphics.setColor(1, 1, 1)
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), 22)
love.graphics.setColor(0, 0, 0)
love.graphics.print(debugInfoString, 4, 4)
normalRenders = normalRenders + 1
renderStats = love.graphics.getStats()
end