How to get the mouse event object in any method?

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

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #68889
    goodweather
    Participant
      • Topics: 45
      • Replies: 550
      • Total: 595
      • ★★★

      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 7 years ago by goodweather. Reason: Solution found to the question some time ago
      #71882
      Mr.ToR
      Participant
        • Topics: 7
        • Replies: 51
        • Total: 58

        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
        Participant
          • Topics: 45
          • Replies: 550
          • Total: 595
          • ★★★

          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
            • Topics: 7
            • Replies: 51
            • Total: 58

            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
            Participant
              • Topics: 45
              • Replies: 550
              • Total: 595
              • ★★★

              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
                • Topics: 7
                • Replies: 51
                • Total: 58

                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
                Participant
                  • Topics: 45
                  • Replies: 550
                  • Total: 595
                  • ★★★

                  Don’t know…sorry…

                Viewing 7 posts - 1 through 7 (of 7 total)
                • The forum ‘Programming’ is closed to new topics and replies.
                There is currently 0 users and 71 guests online
                No users are currently active
                Forum Statistics
                Threads: 2,495, Posts: 17,374, Members: 77,605
                Most users ever online was 12 on January 22, 2019 3:47 pm
                Ctrlr