mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-11-18 16:04:22 +00:00
image.stretch
button.image groupIndex for button and checkbox
This commit is contained in:
parent
0e69a908d5
commit
d22aa28502
@ -27,6 +27,8 @@ function newobject:initialize()
|
|||||||
self.toggleable = false
|
self.toggleable = false
|
||||||
self.toggle = false
|
self.toggle = false
|
||||||
self.OnClick = nil
|
self.OnClick = nil
|
||||||
|
self.groupIndex = 0
|
||||||
|
self.checked = false
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -182,6 +184,19 @@ function newobject:mousereleased(x, y, button)
|
|||||||
|
|
||||||
if hover and down and clickable and button == 1 then
|
if hover and down and clickable and button == 1 then
|
||||||
if enabled then
|
if enabled then
|
||||||
|
if self.groupIndex ~= 0 then
|
||||||
|
local baseparent = self.parent
|
||||||
|
if baseparent then
|
||||||
|
for k, v in ipairs(baseparent.children) do
|
||||||
|
if v.groupIndex then
|
||||||
|
if v.groupIndex == self.groupIndex then
|
||||||
|
v.checked = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.checked = true
|
||||||
|
end
|
||||||
if onclick then
|
if onclick then
|
||||||
onclick(self, x, y)
|
onclick(self, x, y)
|
||||||
end
|
end
|
||||||
|
@ -29,6 +29,7 @@ function newobject:initialize()
|
|||||||
self.enabled = true
|
self.enabled = true
|
||||||
self.internals = {}
|
self.internals = {}
|
||||||
self.OnChanged = nil
|
self.OnChanged = nil
|
||||||
|
self.groupIndex = 0
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -211,8 +212,20 @@ function newobject:mousereleased(x, y, button)
|
|||||||
|
|
||||||
if hover and down and enabled and button == 1 then
|
if hover and down and enabled and button == 1 then
|
||||||
if checked then
|
if checked then
|
||||||
self.checked = false
|
if self.groupIndex == 0 then self.checked = false end
|
||||||
else
|
else
|
||||||
|
if self.groupIndex ~= 0 then
|
||||||
|
local baseparent = self.parent
|
||||||
|
if baseparent then
|
||||||
|
for k, v in ipairs(baseparent.children) do
|
||||||
|
if v.groupIndex then
|
||||||
|
if v.groupIndex == self.groupIndex then
|
||||||
|
v.checked = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
self.checked = true
|
self.checked = true
|
||||||
end
|
end
|
||||||
if onchanged then
|
if onchanged then
|
||||||
|
@ -26,6 +26,8 @@ function newobject:initialize()
|
|||||||
self.image = nil
|
self.image = nil
|
||||||
self.imagecolor = {255, 255, 255, 255}
|
self.imagecolor = {255, 255, 255, 255}
|
||||||
self.OnClick = nil
|
self.OnClick = nil
|
||||||
|
self.groupIndex = 0
|
||||||
|
self.checked = false
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -182,6 +184,19 @@ function newobject:mousereleased(x, y, button)
|
|||||||
|
|
||||||
if hover and down and clickable and button == 1 then
|
if hover and down and clickable and button == 1 then
|
||||||
if enabled then
|
if enabled then
|
||||||
|
if self.groupIndex ~= 0 then
|
||||||
|
local baseparent = self.parent
|
||||||
|
if baseparent then
|
||||||
|
for k, v in ipairs(baseparent.children) do
|
||||||
|
if v.groupIndex then
|
||||||
|
if v.groupIndex == self.groupIndex then
|
||||||
|
v.checked = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.checked = true
|
||||||
|
end
|
||||||
if onclick then
|
if onclick then
|
||||||
onclick(self, x, y)
|
onclick(self, x, y)
|
||||||
end
|
end
|
||||||
|
21
readme.md
21
readme.md
@ -16,3 +16,24 @@ Created by Kenny Shields
|
|||||||
**Third-Party Libraries**
|
**Third-Party Libraries**
|
||||||
|
|
||||||
- middleclass by kikito - https://github.com/kikito/middleclass
|
- middleclass by kikito - https://github.com/kikito/middleclass
|
||||||
|
|
||||||
|
What's new:
|
||||||
|
|
||||||
|
textinput - Unicode support.
|
||||||
|
|
||||||
|
Properties:
|
||||||
|
|
||||||
|
image.stretch (boolean)
|
||||||
|
|
||||||
|
buttom.image (image) -- left aligned image
|
||||||
|
|
||||||
|
button.groupIndex (int)
|
||||||
|
button.checked (boolean)
|
||||||
|
|
||||||
|
imagebutton.groupIndex (int)
|
||||||
|
imagebutton.checked (boolean)
|
||||||
|
|
||||||
|
checkbox.groupIndex
|
||||||
|
|
||||||
|
-- Buttons/checkboxes with the same groupIndex behave as group buttons
|
||||||
|
|
||||||
|
@ -314,6 +314,7 @@ function skin.DrawButton(object)
|
|||||||
local twidth = font:getWidth(object.text)
|
local twidth = font:getWidth(object.text)
|
||||||
local theight = font:getHeight(object.text)
|
local theight = font:getHeight(object.text)
|
||||||
local down = object:GetDown()
|
local down = object:GetDown()
|
||||||
|
local checked = object.checked
|
||||||
local enabled = object:GetEnabled()
|
local enabled = object:GetEnabled()
|
||||||
local clickable = object:GetClickable()
|
local clickable = object:GetClickable()
|
||||||
local textdowncolor = skin.controls.button_text_down_color
|
local textdowncolor = skin.controls.button_text_down_color
|
||||||
@ -388,14 +389,27 @@ function skin.DrawButton(object)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if down then
|
if down or checked then
|
||||||
-- button body
|
-- button body
|
||||||
love.graphics.setColor(255, 255, 255, 255)
|
love.graphics.setColor(255, 255, 255, 255)
|
||||||
love.graphics.draw(skin.images["button-down.png"], x, y, 0, width, scaley)
|
love.graphics.draw(skin.images["button-down.png"], x, y, 0, width, scaley)
|
||||||
-- button text
|
-- button text
|
||||||
love.graphics.setFont(font)
|
love.graphics.setFont(font)
|
||||||
love.graphics.setColor(textdowncolor)
|
if object.image then
|
||||||
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
love.graphics.draw(object.image, x + 2, y + height/2 - object.image:getHeight()/2)
|
||||||
|
love.graphics.setColor(textdowncolor)
|
||||||
|
local text = object.text
|
||||||
|
local font = skin.controls.button_text_font
|
||||||
|
while font:getWidth(text) > width - object.image:getWidth() - 10 do
|
||||||
|
text =text:sub(2)
|
||||||
|
while text:byte(1, 1) > 127 do text = text:sub(2) end
|
||||||
|
end
|
||||||
|
love.graphics.print(text, x + object.image:getWidth() + 4, y + height/2 - theight/2)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(textdowncolor)
|
||||||
|
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
||||||
|
end
|
||||||
-- button border
|
-- button border
|
||||||
love.graphics.setColor(bordercolor)
|
love.graphics.setColor(bordercolor)
|
||||||
skin.OutlinedRectangle(x, y, width, height)
|
skin.OutlinedRectangle(x, y, width, height)
|
||||||
@ -405,8 +419,21 @@ function skin.DrawButton(object)
|
|||||||
love.graphics.draw(image_hover, x, y, 0, width, scaley)
|
love.graphics.draw(image_hover, x, y, 0, width, scaley)
|
||||||
-- button text
|
-- button text
|
||||||
love.graphics.setFont(font)
|
love.graphics.setFont(font)
|
||||||
love.graphics.setColor(texthovercolor)
|
if object.image then
|
||||||
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
love.graphics.draw(object.image, x + 2, y + height/2 - object.image:getHeight()/2)
|
||||||
|
love.graphics.setColor(texthovercolor)
|
||||||
|
local text = object.text
|
||||||
|
local font = skin.controls.button_text_font
|
||||||
|
while font:getWidth(text) > width - object.image:getWidth() - 10 do
|
||||||
|
text =text:sub(2)
|
||||||
|
while text:byte(1, 1) > 127 do text = text:sub(2) end
|
||||||
|
end
|
||||||
|
love.graphics.print(text, x + object.image:getWidth() + 4, y + height/2 - theight/2)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(texthovercolor)
|
||||||
|
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
||||||
|
end
|
||||||
-- button border
|
-- button border
|
||||||
love.graphics.setColor(bordercolor)
|
love.graphics.setColor(bordercolor)
|
||||||
skin.OutlinedRectangle(x, y, width, height)
|
skin.OutlinedRectangle(x, y, width, height)
|
||||||
@ -416,8 +443,21 @@ function skin.DrawButton(object)
|
|||||||
love.graphics.draw(skin.images["button-nohover.png"], x, y, 0, width, scaley)
|
love.graphics.draw(skin.images["button-nohover.png"], x, y, 0, width, scaley)
|
||||||
-- button text
|
-- button text
|
||||||
love.graphics.setFont(font)
|
love.graphics.setFont(font)
|
||||||
love.graphics.setColor(textnohovercolor)
|
if object.image then
|
||||||
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
love.graphics.draw(object.image, object:GetX() + 2, object:GetY() + object:GetHeight()/2 - object.image:getHeight()/2)
|
||||||
|
love.graphics.setColor(textnohovercolor)
|
||||||
|
local text = object.text
|
||||||
|
local font = skin.controls.button_text_font
|
||||||
|
while font:getWidth(text) > width - object.image:getWidth() - 10 do
|
||||||
|
text =text:sub(2)
|
||||||
|
while text:byte(1, 1) > 127 do text = text:sub(2) end
|
||||||
|
end
|
||||||
|
love.graphics.print(text, x + object.image:getWidth() + 4, y + height/2 - theight/2)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(textnohovercolor)
|
||||||
|
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
||||||
|
end
|
||||||
-- button border
|
-- button border
|
||||||
love.graphics.setColor(bordercolor)
|
love.graphics.setColor(bordercolor)
|
||||||
skin.OutlinedRectangle(x, y, width, height)
|
skin.OutlinedRectangle(x, y, width, height)
|
||||||
@ -483,7 +523,12 @@ function skin.DrawImage(object)
|
|||||||
local sheary = object:GetShearY()
|
local sheary = object:GetShearY()
|
||||||
local image = object.image
|
local image = object.image
|
||||||
local color = object.imagecolor
|
local color = object.imagecolor
|
||||||
|
local stretch = object.stretch
|
||||||
|
|
||||||
|
if stretch then
|
||||||
|
scalex, scaley = object:GetWidth() / image:getWidth(), object:GetHeight() / image:getHeight()
|
||||||
|
end
|
||||||
|
|
||||||
if color then
|
if color then
|
||||||
love.graphics.setColor(color)
|
love.graphics.setColor(color)
|
||||||
love.graphics.draw(image, x, y, orientation, scalex, scaley, offsetx, offsety, shearx, sheary)
|
love.graphics.draw(image, x, y, orientation, scalex, scaley, offsetx, offsety, shearx, sheary)
|
||||||
@ -516,7 +561,8 @@ function skin.DrawImageButton(object)
|
|||||||
local textdowncolor = skin.controls.imagebutton_text_down_color
|
local textdowncolor = skin.controls.imagebutton_text_down_color
|
||||||
local texthovercolor = skin.controls.imagebutton_text_hover_color
|
local texthovercolor = skin.controls.imagebutton_text_hover_color
|
||||||
local textnohovercolor = skin.controls.imagebutton_text_nohover_color
|
local textnohovercolor = skin.controls.imagebutton_text_nohover_color
|
||||||
|
local checked = object.checked
|
||||||
|
|
||||||
if down then
|
if down then
|
||||||
if image then
|
if image then
|
||||||
love.graphics.setColor(imagecolor)
|
love.graphics.setColor(imagecolor)
|
||||||
@ -548,6 +594,12 @@ function skin.DrawImageButton(object)
|
|||||||
love.graphics.setColor(textnohovercolor)
|
love.graphics.setColor(textnohovercolor)
|
||||||
love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 6)
|
love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 6)
|
||||||
end
|
end
|
||||||
|
if checked == true then
|
||||||
|
love.graphics.setColor(bordercolor)
|
||||||
|
love.graphics.setLineWidth(3)
|
||||||
|
love.graphics.setLineStyle("smooth")
|
||||||
|
love.graphics.rectangle("line", x+1, y+1, width-2, height-2)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user