Page 1 of 1

Lua mouseCallback() not working

Posted: Tue Aug 05, 2014 4:53 pm
by Mithrandir
Hi,
I've been trying to use the mouseCallback() function which is supposedly available in the API but with no success. While the regular button and text editor component callbacks are easily handled, nothing happens with mouseCallback. Anyone know how to do this?

Much obliged
-Mtl

Re: Lua mouseCallback() not working

Posted: Sat Aug 09, 2014 4:55 am
by stratified
Hi Mithrandir,

I think it only works with the bitmap component. I don't remember why it doesn't work with other components (might be a bug). I will look into it. This example should work:

Code: Select all

-- mouse handler example

local bitmap = octane.gui.create
{
    type          = octane.gui.componentType.BITMAP,
    width         = 400,
    height        = 200,
    mouseCallback = function(component, event, x, y, sx, sy)
        print(string.format("event %d @ position { %d, %d })", event, x, y))
    end
}

local window = octane.gui.create
{
    type          = octane.gui.componentType.WINDOW,
    width         = 500,
    height        = 500,
    text          = "Mouse Test",
    children      = { bitmap },
    mouseCallback = function(event, x, y)
        print("this seems to be broken!")
    end
}

window:showWindow()
cheers,
Thomas

Re: Lua mouseCallback() not working

Posted: Sat Aug 09, 2014 3:06 pm
by Mithrandir
Thank you Thomas,

Certainly opens possibilities for using bitmaps. Although, if not a bug with the other components, then mouseCallback() should be removed from the documentation showing it as one of their methods.
It would be good if it worked for text editor so that action could be taken when clicking on a field. Right now, no callback action takes place until a character is entered. If mouse callbacks can't be used here, the an on_enter and on_exit callback would make coding and error handling much easier.
Again, thanks

-Mtl