nicer demo app
This commit is contained in:
parent
5b3c05a415
commit
c1f2d96c02
1 changed files with 22 additions and 18 deletions
|
@ -44,7 +44,7 @@ Example code
|
||||||
-- generate some assets (below)
|
-- generate some assets (below)
|
||||||
function love.load()
|
function love.load()
|
||||||
snd = generateClickySound()
|
snd = generateClickySound()
|
||||||
normal, hot = generateImageButton()
|
normal, hover, active = generateImageButton()
|
||||||
smallerFont = love.graphics.newFont(10)
|
smallerFont = love.graphics.newFont(10)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -122,9 +122,11 @@ Example code
|
||||||
-- but the image may be bigger or smaller
|
-- but the image may be bigger or smaller
|
||||||
-- the button shows the image `normal' when the mouse is outside the image
|
-- the button shows the image `normal' when the mouse is outside the image
|
||||||
-- or above a transparent pixel
|
-- or above a transparent pixel
|
||||||
-- the button shows the image `hot` if the mouse is above an opaque pixel
|
-- the button shows the image `hover` if the mouse is above an opaque pixel
|
||||||
-- of the image `normal'
|
-- of the image `normal'
|
||||||
suit.ImageButton({normal, hot = hot}, suit.layout.row(200,100))
|
-- the button shows the image `active` if the mouse is above an opaque pixel
|
||||||
|
-- of the image `normal' and the mouse button is pressed
|
||||||
|
suit.ImageButton(normal, {hover = hover, active = active}, suit.layout.row(200,100))
|
||||||
|
|
||||||
-- if the checkbox is checked, display a precomputed layout
|
-- if the checkbox is checked, display a precomputed layout
|
||||||
if chk.checked then
|
if chk.checked then
|
||||||
|
@ -183,22 +185,24 @@ Example code
|
||||||
end
|
end
|
||||||
|
|
||||||
function generateImageButton()
|
function generateImageButton()
|
||||||
local normal, hot = love.image.newImageData(200,100), love.image.newImageData(200,100)
|
local metaballs = function(t, r,g,b)
|
||||||
normal:mapPixel(function(x,y)
|
return function(x,y)
|
||||||
local d = (x/200-.5)^2 + (y/100-.5)^2
|
local px, py = 2*(x/200-.5), 2*(y/100-.5)
|
||||||
if d < .12 then
|
local d1 = math.exp(-((px-.6)^2 + (py-.1)^2))
|
||||||
return 200,160,20,255
|
local d2 = math.exp(-((px+.7)^2 + (py+.1)^2) * 2)
|
||||||
|
local d = (d1 + d2)/2
|
||||||
|
if d > t then
|
||||||
|
return r,g,b, 255 * ((d-t) / (1-t))^.2
|
||||||
end
|
end
|
||||||
return 0,0,0,0
|
return 0,0,0,0
|
||||||
end)
|
|
||||||
hot:mapPixel(function(x,y)
|
|
||||||
local d = (x/200-.5)^2 + (y/100-.5)^2
|
|
||||||
if d < .13 then
|
|
||||||
return 255,255,255,255
|
|
||||||
end
|
end
|
||||||
return 0,0,0,0
|
end
|
||||||
end)
|
|
||||||
return love.graphics.newImage(normal), love.graphics.newImage(hot)
|
local normal, hover, active = love.image.newImageData(200,100), love.image.newImageData(200,100), love.image.newImageData(200,100)
|
||||||
|
normal:mapPixel(metaballs(.48, 188,188,188))
|
||||||
|
hover:mapPixel(metaballs(.46, 50,153,187))
|
||||||
|
active:mapPixel(metaballs(.43, 255,153,0))
|
||||||
|
return love.graphics.newImage(normal), love.graphics.newImage(hover), love.graphics.newImage(active)
|
||||||
end
|
end
|
||||||
|
|
||||||
Indices and tables
|
Indices and tables
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue