From c11db7d4448940281f5f18c8e1e9d3d7e1f71c9c Mon Sep 17 00:00:00 2001 From: Matthias Gazzari Date: Sun, 22 Apr 2018 20:00:54 +0200 Subject: [PATCH] Remove alpha value check from ImageButton With LOVE 11.0 it is no longer possible to retrieve an ImageData from an Image and thus there is no posibility to retrieve the alpha value of a single pixel. Another solution would be to additionally supply an ImageData to the ImageButton in order to be able to retrieve the alpha values. --- docs/widgets.rst | 4 ++-- imagebutton.lua | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/widgets.rst b/docs/widgets.rst index c0f18eb..10a6965 100644 --- a/docs/widgets.rst +++ b/docs/widgets.rst @@ -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 theme. 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 -non-zero alpha value. +area of the widget: The button activates when the mouse is over a pixel of the +rectangular image area. You can provide additional ``hovered`` and ``active`` images, but the widget area is always computed from the ``normal`` image. diff --git a/imagebutton.lua b/imagebutton.lua index 0cf544a..83f1a8a 100644 --- a/imagebutton.lua +++ b/imagebutton.lua @@ -11,14 +11,11 @@ return function(core, normal, ...) opt.id = opt.id or opt.normal 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) if u < 0 or u >= opt.normal:getWidth() or v < 0 or v >= opt.normal:getHeight() then return false end - local _,_,_,a = id:getPixel(u,v) - return a > 0 + return true end) local img = opt.normal