Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color coding changed from Love 0.10 to Love 0.11 format (255->1) #20

Merged
merged 2 commits into from May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions conf.lua
@@ -1,11 +1,11 @@
function love.conf(t)
t.identity = nil -- The name of the save directory (string)
t.version = "0.10.2" -- The LÖVE version this game was made for (string)
t.version = "0.11.0" -- The LÖVE version this game was made for (string)
t.console = false -- Attach a console (boolean, Windows only)
t.accelerometerjoystick = true -- Enable the accelerometer on iOS and Android by exposing it as a Joystick (boolean)
t.externalstorage = false -- True to save files (and read from the save directory) in external storage on Android (boolean)
t.externalstorage = false -- True to save files (and read from the save directory) in external storage on Android (boolean)
t.gammacorrect = false -- Enable gamma-correct rendering, when supported by the system (boolean)

t.window.title = "GOOi demo" -- The window title (string)
t.window.icon = nil -- Filepath to an image to use as the window's icon (string)
t.window.width = 800 -- The window width (number)
Expand All @@ -22,7 +22,7 @@ function love.conf(t)
t.window.highdpi = false -- Enable high-dpi mode for the window on a Retina display (boolean)
t.window.x = nil -- The x-coordinate of the window's position in the specified display (number)
t.window.y = nil -- The y-coordinate of the window's position in the specified display (number)

t.modules.audio = true -- Enable the audio module (boolean)
t.modules.event = true -- Enable the event module (boolean)
t.modules.graphics = true -- Enable the graphics module (boolean)
Expand Down
7 changes: 5 additions & 2 deletions gooi/button.lua
Expand Up @@ -72,13 +72,16 @@ function gooi.newButton(params)
if t:len() == 0 then
xImg = math.floor(self.x + self.w / 2)
end
love.graphics.setColor(255/255, 255/255, 255/255)
if not self.enabled then love.graphics.setColor(63/255, 63/255, 63/255) end
love.graphics.setColor(1, 1, 1)
if not self.enabled then love.graphics.setColor(1/4, 1/4, 1/4) end
love.graphics.draw(self.icon, xImg, math.floor(self.y + self.h / 2), 0, 1, 1,
math.floor(self.icon:getWidth() / 2),
math.floor(self.icon:getHeight() / 2))
end
love.graphics.setColor(fg)



local yLine = yLocal + self.y + self.h / 2
yLine = yLine - (gooi.getFont(self):getHeight()) * #self.textParts / 2
for i = 1, #self.textParts do
Expand Down
83 changes: 42 additions & 41 deletions gooi/component.lua
Expand Up @@ -3,16 +3,16 @@
component = {}
component.__index = component
component.colors = {
blue = {2/255, 117/255, 216/255, 255/255},
green = {92/255, 184/255, 92/255, 255/255},
cyan = {91/255, 192/255, 222/255, 255/255},
orange = {240/255, 173/255, 78/255, 255/255},
red = {217/255, 83/255, 79/255, 255/255},
black = {0, 0, 0, 255/255},
white = {255/255, 255/255, 255/255, 255/255},
clearGray = {247/255, 247/255, 247/255, 255/255},
darkGray = {41/255, 43/255, 44/255, 255/255},
darkGrayAlpha = {41/255, 43/255, 44/255, 150/255},
blue = {0.01, 0.46, 0.85, 1.0},
green = {0.36, 0.72, 0.36, 1.0},
cyan = {0.36, 0.75, 0.87, 1.0},
orange = {0.94, 0.68, 0.31, 1.0},
red = {0.85, 0.33, 0.31, 1.0},
black = {0.0, 0.0, 0.0, 1.0},
white = {1.0, 1.0, 1.0, 1.0},
clearGray = {0.97, 0.97, 0.97, 1.0},
darkGray = {0.16, 0.17, 0.17, 1.0},
darkGrayAlpha = {0.16, 0.17, 0.17, 0.59},
}
component.style = {
bgColor = component.colors.blue,
Expand Down Expand Up @@ -91,7 +91,7 @@ function component.new(t, x, y, w, h, group)
color = gooi.toRGBA(color)
end
self.style.bgColor = color
self.style.borderColor = {color[1], color[2], color[3], 255}
self.style.borderColor = {color[1], color[2], color[3], 1}
self:make3d()
return self
end
Expand Down Expand Up @@ -119,10 +119,10 @@ function component.new(t, x, y, w, h, group)
if not w then return self.style.borderWidth, self.style.borderColor; end

self.style.borderWidth = w
self.style.borderColor = color or {12, 183, 242, 255}
self.style.borderColor = color or {0.05, 0.72, 0.95, 1}
if type(color) == "string" then
self.style.borderColor = gooi.toRGBA(color)
self.style.borderColor[4] = 255
self.style.borderColor[4] = 1
end
self.style.borderStyle = style or "smooth"
self.style.showBorder = true
Expand All @@ -136,19 +136,19 @@ function component.new(t, x, y, w, h, group)
self.mode3d = false
return self
end

c.style = gooi.deepcopy(component.style)

function c:make3d()
-- For a 3D look:
self.colorTop = self.style.bgColor
self.colorBot = self.style.bgColor

self.colorTop = changeBrig(self.style.bgColor, 15)
self.colorBot = changeBrig(self.style.bgColor, -15)
self.colorTop = changeBrig(self.style.bgColor, 0.06)
self.colorBot = changeBrig(self.style.bgColor, -0.06)

self.colorTopHL = changeBrig(self.style.bgColor, 25)
self.colorBotHL = changeBrig(self.style.bgColor, -5)
self.colorTopHL = changeBrig(self.style.bgColor, 0.1)
self.colorBotHL = changeBrig(self.style.bgColor, -0.02)

self.imgData3D = love.image.newImageData(1, 2)
self.imgData3D:setPixel(0, 0, self.colorTop[1], self.colorTop[2], self.colorTop[3], self.colorTop[4])
Expand All @@ -165,19 +165,19 @@ function component.new(t, x, y, w, h, group)
self.img3DHL:setFilter("linear", "linear")

self.imgDataGlass = love.image.newImageData(1, 2)
self.imgDataGlass:setPixel(0, 0, 255, 255, 255, 80)
self.imgDataGlass:setPixel(0, 1, 255, 255, 255, 40)
self.imgDataGlass:setPixel(0, 0, 1, 1, 1, 0.31)
self.imgDataGlass:setPixel(0, 1, 1, 1, 1, 0.16)
self.imgGlass = love.graphics.newImage(self.imgDataGlass)
self.imgGlass:setFilter("linear", "linear")
end

function c:makeShadow()
self.heightShadow = 6
self.imgDataShadow = love.image.newImageData(1, self.heightShadow)
self.imgDataShadow:setPixel(0, 0, 0, 0, 0, 80)
self.imgDataShadow:setPixel(0, 1, 0, 0, 0, 30)
self.imgDataShadow:setPixel(0, 2, 0, 0, 0, 5)
self.imgDataShadow:setPixel(0, 0, 0, 0, 0, 0.31)
self.imgDataShadow:setPixel(0, 1, 0, 0, 0, 0.12)
self.imgDataShadow:setPixel(0, 2, 0, 0, 0, 0.02)

self.imgShadow = love.graphics.newImage(self.imgDataShadow)
self.imgShadow:setFilter("linear", "linear")
end
Expand All @@ -188,7 +188,7 @@ function component.new(t, x, y, w, h, group)
function c:info() self:bg(component.colors.cyan); return self end
function c:warning() self:bg(component.colors.orange); return self end
function c:danger() self:bg(component.colors.red); return self end
function c:opacity(o) self.style.bgColor[4] = o * 255; return self end
function c:opacity(o) self.style.bgColor[4] = o; return self end

function c:secondary()
self:bg(component.colors.clearGray)
Expand All @@ -203,7 +203,7 @@ function component.new(t, x, y, w, h, group)


c:make3d()

return setmetatable(c, component)
end

Expand All @@ -214,7 +214,7 @@ end
function component:draw()-- Every component has the same base:
local style = self.style
if self.opaque and self.visible then
local focusColorChange = 15
local focusColorChange = 0.06
local fs = - 1
if not self.enabled then focusColorChange = 0 end
local newColor = style.bgColor
Expand All @@ -236,7 +236,7 @@ function component:draw()-- Every component has the same base:
love.graphics.setColor(newColor)

if not self.enabled then
love.graphics.setColor(63/255, 63/255, 63/255, style.bgColor[4]/255 or 255/255)
love.graphics.setColor(1/4, 1/4, 1/4, style.bgColor[4] or 1)
end

local radiusCorner = style.radius
Expand Down Expand Up @@ -270,9 +270,9 @@ function component:draw()-- Every component has the same base:
end

if self.mode3d then
love.graphics.setColor(255/255, 255/255, 255/255, style.bgColor[4]/255 or 255/255)
love.graphics.setColor(1, 1, 1, style.bgColor[4] or 1)
if not self.enabled then
love.graphics.setColor(0, 0, 0, style.bgColor[4]/255 or 255/255)
love.graphics.setColor(0, 0, 0, style.bgColor[4] or 1)
end
love.graphics.draw(img,
math.floor(self.x + self.w / 2),
Expand All @@ -296,7 +296,7 @@ function component:draw()-- Every component has the same base:
end

if self.glass then
love.graphics.setColor(255/255, 255/255, 255/255)
love.graphics.setColor(1, 1, 1)
love.graphics.draw(self.imgGlass,
self.x,
self.y,
Expand All @@ -306,7 +306,8 @@ function component:draw()-- Every component has the same base:
end

if self.bgImage then
love.graphics.setColor(255/255, 255/255, 255/255)

love.graphics.setColor(1, 1, 1)
love.graphics.draw(self.bgImage,
math.floor(self.x),
math.floor(self.y),
Expand All @@ -320,7 +321,8 @@ function component:draw()-- Every component has the same base:
if style.showBorder then
love.graphics.setColor(newColor)
if not self.enabled then
love.graphics.setColor(63/255, 63/255, 63/255)

love.graphics.setColor(1/4, 1/4, 1/4)
end
love.graphics.rectangle("line",
math.floor(self.x),
Expand All @@ -347,8 +349,7 @@ function component:drawShadowPressed()
50)
end, "replace", 1)
love.graphics.setStencilTest("greater", 0)

love.graphics.setColor(255/255, 255/255, 255/255)
love.graphics.setColor(1, 1, 1)
love.graphics.draw(self.imgShadow,
self.x + self.w / 2,
self.y + self.h / 2,
Expand Down Expand Up @@ -397,7 +398,7 @@ function component:wasReleased()
local b = self:overIt() and self.enabled and self.visible
if self.type == "text" then
if b then
love.keyboard.setTextInput(true)
love.keyboard.setTextInput(true)
end
end

Expand Down Expand Up @@ -517,24 +518,24 @@ function changeBrig(color, amount)
color = gooi.toRGBA(color)
end

local r, g, b, a = color[1], color[2], color[3], color[4] or 255
local r, g, b, a = color[1], color[2], color[3], color[4] or 1

r = r + amount
g = g + amount
b = b + amount
--a = a + amount

if r < 0 then r = 0 end
if r > 255 then r = 255 end
if r > 1 then r = 1 end

if g < 0 then g = 0 end
if g > 255 then g = 255 end
if g > 1 then g = 1 end

if b < 0 then b = 0 end
if b > 255 then b = 255 end
if b > 1 then b = 1 end

--if a < 0 then a = 0 end
--if a > 255 then a = 255 end
--if a > 1 then a = 1 end

return {r, g, b, a}
end
18 changes: 10 additions & 8 deletions gooi/gooi.lua
Expand Up @@ -349,7 +349,7 @@ function gooi.draw(group)

local compWithTooltip = nil -- Just for desktop.

love.graphics.setColor(255/255, 255/255, 255/255)
love.graphics.setColor(1, 1, 1)
love.graphics.setLineWidth(2)
love.graphics.setLineStyle(gooi.lineStyle)

Expand Down Expand Up @@ -380,7 +380,7 @@ function gooi.draw(group)

local fg = comp.style.fgColor
if not comp.enabled then
fg = {31, 31, 31}
fg = {0.12, 0.12, 0.12}
end

------------------------------------------------------------
Expand Down Expand Up @@ -416,7 +416,7 @@ function gooi.draw(group)
xTT = xTT - ttf:getWidth(text)
end

love.graphics.setColor(0, 0, 0, 150/255)
love.graphics.setColor(0, 0, 0, 0.6)
love.graphics.rectangle("fill",
xTT - httf,
math.floor((love.mouse.getY() / gooi.sy) - httf * 1.5),
Expand All @@ -434,7 +434,7 @@ function gooi.draw(group)
love.graphics.setFont(gooi.getFont(self))-- Specific or a common font.
local w, h = gooi.canvas:getWidth(), gooi.canvas:getHeight()

love.graphics.setColor(0, 0, 0, 127/255)
love.graphics.setColor(0, 0, 0, 0.5)
love.graphics.rectangle("fill", 0, 0,
love.graphics.getWidth(),
love.graphics.getHeight())
Expand Down Expand Up @@ -496,9 +496,11 @@ end

function gooi.toRGBA(hex)
hex = hex:gsub("#","")
color = {tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))}
color = {tonumber("0x"..hex:sub(1,2))/255,
tonumber("0x"..hex:sub(3,4))/255,
tonumber("0x"..hex:sub(5,6))/255}
if string.len(hex) >= 8 then
table.insert(color, tonumber("0x"..hex:sub(7, 8)))
table.insert(color, tonumber("0x"..hex:sub(7, 8))/255)
end
return color
end
Expand Down Expand Up @@ -807,6 +809,6 @@ function split(inputstr, sep)
end

function invert(color)
local r, g, b, a = color[1], color[2], color[3], color[4] or 255
return {255 - r, 255 - g, 255 - b, a}
local r, g, b, a = color[1], color[2], color[3], color[4] or 1
return {1 - r, 1 - g, 1 - b, a}
end
2 changes: 1 addition & 1 deletion gooi/joy.lua
Expand Up @@ -71,7 +71,7 @@ function gooi.newJoy(params)
function s:drawStick()
local fg = self.style.fgColor
if self.image then
love.graphics.setColor(255/255, 255/255, 255/255, fg[4]/255 or 255/255)
love.graphics.setColor(1, 1, 1, fg[4] or 1)
local sx = self.rStick * 2 / self.image:getWidth()
local sy = self.rStick * 2 / self.image:getHeight()
local x, y = self.xStick, self.yStick
Expand Down
2 changes: 1 addition & 1 deletion gooi/knob.lua
Expand Up @@ -55,7 +55,7 @@ function gooi.newKnob(params)

love.graphics.setColor(fg)
if not self.enabled then
love.graphics.setColor(63/255, 63/255, 63/255)
love.graphics.setColor(1/4, 1/4, 1/4)
end
love.graphics.arc("line",
"open",
Expand Down
5 changes: 2 additions & 3 deletions gooi/label.lua
Expand Up @@ -66,9 +66,8 @@ function gooi.newLabel(params)
end
if self.icon then
local xImg = math.floor(self.x + self.h / 2)
love.graphics.setColor(255/255, 255/255, 255/255)
if not self.enabled then love.graphics.setColor(63/255, 63/255, 63/255) end

love.graphics.setColor(1, 1, 1)
if not self.enabled then love.graphics.setColor(1/4, 1/4, 1/4) end
if t:len() == 0 then
xImg = math.floor(self.x + self.w / 2)
end
Expand Down
2 changes: 1 addition & 1 deletion gooi/layout.lua
Expand Up @@ -35,7 +35,7 @@ function layout.new(specs)
for j = 1, self.gridCols do
local cell = self.gridCells[i][j]
if cell.on then
love.graphics.setColor(255, 0, 255)
love.graphics.setColor(1, 0, 1)
love.graphics.rectangle("line", cell.x, cell.y, cell.w, cell.h)
end
end
Expand Down
2 changes: 1 addition & 1 deletion gooi/panel.lua
Expand Up @@ -47,7 +47,7 @@ function gooi.newPanel(params)
end
function p:drawSpecifics(fg)
if self.layout.kind == "grid" then
love.graphics.setColor(0, 0, 0, 127)
love.graphics.setColor(0, 0, 0, 0.5)
self.layout:drawCells()
end
end
Expand Down