Home Forums General Programming How to get the mouse event object in any method?

This topic contains 6 replies, has 2 voices, and was last updated by goodweather goodweather 1 month ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #68889
    goodweather
    goodweather
    Participant

    Hi,
    I’d like to know how it is possible to get the mouse event object in any method.
    Some methods are having event as one of the arguments and thus there is no problem.
    Other methods or user-created methods/functions could have a need of the event object BUT I don’t know how to declare/find it (if possible with Ctrlr/Juce/Lua).

    Thx in advance for your advice!

    EDIT 2017-04-20: I solved that one long time ago… Explanations below as answer to Mr Tor πŸ™‚

    • This topic was modified 2 months, 1 week ago by goodweather goodweather. Reason: Solution found to the question some time ago
    #71882

    Mr.ToR
    Participant

    Hi goodweather,

    Could you please share what you’ve found about MouseEvent.
    I saw in your panel you used MouseEvent.x and MouseEvent.x
    What other possibilities are there? or where can I look to see what is provided with MouseEvent?

    Thnx a lot

    #71885
    goodweather
    goodweather
    Participant

    Hi,
    there are different things to take into account…
    – you must create methods based on the different mouse event templates (componentLuaMouseDown, componentLuaMouseMove…) so you will get a first argument that is the component in focus and a second argument that is the event)
    – as you know, Ctrlr is based on Juce and you will thus find a lot of info on many things in the Juce documentation available at https://www.juce.com/doc/classes. For mouse event, for example it is at: https://www.juce.com/doc/classMouseEvent
    – you will also find the list of included Juce functions in the Ctrlr source code at https://sourceforge.net/p/ctrlrv4/code/HEAD/tree/nightly/Source/Lua/
    In the JuceClasses folder you can find for example LMouseEvent.cpp that lists the available mouse functions.

    So combining those 3 things and taking the time to read you will find and understand quite a lot. I learned Ctrlr like that without knowing anything about Juce…
    Then as usual, trial and error + other panels + atom’s DEMO panels.

    Example OnMouseMOve:

    — Called when the mouse moves over a component

    OnMouseMove = function(component,mouseEvent)

    mousePosition = string.format (“x=%d y=%d”, mouseEvent.x, mouseEvent.y)
    mousePositionX = mouseEvent.x
    mousePositionY = mouseEvent.y

    end

    Good luck and good reading πŸ˜‰

    #71887

    Mr.ToR
    Participant

    Thnx a lot for your help.
    However, I was at exactly the same pages πŸ™‚
    see the problem is I already found the following:
    class_(“MouseEvent”)
    .def_readonly(“x”, &MouseEvent::x)
    .def_readonly(“y”, &MouseEvent::y)
    .def_readonly(“mods”, &MouseEvent::mods)
    .def_readonly(“eventTime”, &MouseEvent::eventTime)
    .def_readonly(“eventComponent”, &MouseEvent::eventComponent)
    .def_readonly(“originalComponent”, &MouseEvent::originalComponent)
    .def_readonly(“eventTime”, &MouseEvent::eventTime)

    but the only place I was able to find for ex. how mods is used, like this:
    (if MouseEvent.mods:isLeftButtonDown() then)
    was your panel code πŸ™‚
    I can not find where that [:isLeftButtonDown()] is coming from so this applies to all other interfaces.
    Juce mods class definition says “This will let you find out which mouse buttons were down” but I couldn’t find anything more there, such as how it’s used. πŸ™

    I would really appreciate if you could help with that as well.
    Thnx a lot.

    note: just before sending this message I ran MouseEvent.mods through the what function. was that where you found the isLeftButtonDown:function?
    Thnx

    #71891
    goodweather
    goodweather
    Participant

    I remember it took me some time to find and now I had to search again a bit πŸ˜‰
    Ctrlr, Juce and Lua are requesting a lot of attention and reading πŸ™‚

    So if you looked at the Juce MouseEvent class at https://www.juce.com/doc/classMouseEvent , you are very close…
    One of the parameters concerned by a mouse event is the class ModifierKeys (you can click on that word in the Mouse event page) and being on that page (https://www.juce.com/doc/classModifierKeys) you have the description of that class including its functions.
    There you will find all the different tests whereof isLeftButtonDown()

    Good that you raised this question. I will add a chapter on this in the Step by Step guide 2.0 (now I’m working on it).

    #72188

    Mr.ToR
    Participant

    goodweather,

    do you have any information on how to use any of the following?

    component:isMouseButtonDown()
    component:isMouseOverOrDragging()
    component:addMouseListener()
    component:SetInterceptsMouseClicks()

    I’m using mousedrag on a label and want to know when the mouse is up.
    Really have been pulling my hair on that for a while…

    I think there might also be a way to set a method programmatcally, right?
    what is component:mouseUp() do you know? Would it be possible to assign programmatically a mouseUp method to a component with
    void mouseUp(Component&,MouseEvent const&)

    Thnx

    #72196
    goodweather
    goodweather
    Participant

    Don’t know…sorry…

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Comments are closed.