Merge c11db7d444
into 8ec0e638ce
This commit is contained in:
commit
db37e31933
2 changed files with 3 additions and 6 deletions
|
@ -39,8 +39,8 @@ Creates an image button widget at position ``(x,y)``.
|
||||||
Unlike all other widgets, an ``ImageButton`` is not affected by the current
|
Unlike all other widgets, an ``ImageButton`` is not affected by the current
|
||||||
theme.
|
theme.
|
||||||
The argument ``normal`` defines the image of the normal state as well as the
|
The argument ``normal`` defines the image of the normal state as well as the
|
||||||
area of the widget: The button activates when the mouse is over a pixel with
|
area of the widget: The button activates when the mouse is over a pixel of the
|
||||||
non-zero alpha value.
|
rectangular image area.
|
||||||
You can provide additional ``hovered`` and ``active`` images, but the widget area
|
You can provide additional ``hovered`` and ``active`` images, but the widget area
|
||||||
is always computed from the ``normal`` image.
|
is always computed from the ``normal`` image.
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,11 @@ return function(core, normal, ...)
|
||||||
opt.id = opt.id or opt.normal
|
opt.id = opt.id or opt.normal
|
||||||
|
|
||||||
opt.state = core:registerMouseHit(opt.id, x,y, function(u,v)
|
opt.state = core:registerMouseHit(opt.id, x,y, function(u,v)
|
||||||
local id = opt.normal:getData()
|
|
||||||
assert(id:typeOf("ImageData"), "Can only use uncompressed images")
|
|
||||||
u, v = math.floor(u+.5), math.floor(v+.5)
|
u, v = math.floor(u+.5), math.floor(v+.5)
|
||||||
if u < 0 or u >= opt.normal:getWidth() or v < 0 or v >= opt.normal:getHeight() then
|
if u < 0 or u >= opt.normal:getWidth() or v < 0 or v >= opt.normal:getHeight() then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local _,_,_,a = id:getPixel(u,v)
|
return true
|
||||||
return a > 0
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local img = opt.normal
|
local img = opt.normal
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue