[haiku-3rdparty-dev] Re: MouseUp() and GetMouse()

  • From: Carlo Lanzotti - DynaDream <clanzotti@xxxxxxxxxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Wed, 9 Jan 2019 09:45:34 +0100

Il 09/01/2019 01:18, Zenja Solaja ha scritto:

Hi Carlo.  I use something like the following:

//*FUNCTION:MainGLView :: MouseDown/

/ARGUMENTS:p/

/RETURN:n/a/

/DESCRIPTION:Convert Mouse message to Yarra format/

/*//

static Y_MOUSE_BUTTON mouse_button;

*void* MainGLView :: MouseDown(BPoint p)

{

///Determine mouse button/

BMessage* msg = Window()->CurrentMessage();

uint32 buttons;

msg->FindInt32("buttons", (int32*)&buttons);

*if* (buttons & B_PRIMARY_MOUSE_BUTTON)

mouse_button = Y_MOUSE_BUTTON_PRIMARY;

*else* *if* (buttons & B_SECONDARY_MOUSE_BUTTON)

mouse_button = Y_MOUSE_BUTTON_SECONDARY;

*else* *if* (buttons & B_TERTIARY_MOUSE_BUTTON)

mouse_button = Y_MOUSE_BUTTON_TERTIARY;

LockGL();

fApplication->MouseDown(mouse_button, *true*, p.x, p.y);

UnlockGL();

}


//*FUNCTION:MainGLView :: MouseUp/

/ARGUMENTS:p/

/RETURN:n/a/

/DESCRIPTION:Convert Mouse message to Yarra format/

/*//

*void* MainGLView :: MouseUp(BPoint p)

{

LockGL();

fApplication->MouseDown(mouse_button, *false*, p.x, p.y);

UnlockGL();

}


On Wed, 9 Jan 2019 at 02:28, Carlo Lanzotti - DynaDream <clanzotti@xxxxxxxxxxxxx <mailto:clanzotti@xxxxxxxxxxxxx>> wrote:

    Il 08/01/2019 15:56, Stephan Aßmus ha scritto:
    > Hi,
    >
    > Am 08.01.2019 um 15:26 schrieb Carlo Lanzotti - DynaDream:
    >> thanks for your reply. It just confused me because I was
    thinking it
    >> was something to report which mouse buttons were involved when
    >> calling the hooks.
    >>
    >> Is there a way to get which buttons was released in the
    MouseUp() hook?
    >
    > This is off the top of my head: Use
    > Window()->CurrentMessage()->PrintToStream() from within your
    MouseUp()
    > implementation. If there is no helpful "old buttons" kind of
    data in
    > that message, you indeed have to track the buttons yourself. By
    > comparing your stored uint32 buttons value against the new buttons
    > value from the Message, you can know what button was release.
    >
    > Please note that you should not use GetMouse(). GetMouse() will
    give
    > you the current state of the mouse, it will query the app_server
    for
    > that. Mouse messages may be processed with a delay in your
    > application, and GetMouse() could mess up the event order. As an
    > example, the button that was released and triggered your MouseUp()
    > hook to be called, may already be pressed again by the time you
    > process the event, and GetMouse() will show that. The value in the
    > message will however reflect the buttons at the time the event was
    > generated for you.
    >
    > Best regards,
    > -Stephan
    >
    >
    >
    >
    Hi Stefan,

    yes, I figured it out about GetMouse(). Actually what I'm doing is
    comparing buttons flags like you suggested. I was curious about
    the fact
    that there is not a flag indicating which buttons got involved in the
    process.

    Thanks for your help.

    Best Regards,

-- Carlo Lanzotti

    DynaDream - Dynamic Laboratory

    http://www.dynadream.com


Hi Zenja,

thanks, I did something similar, just a little more extended as I need to manage even when more than one mouse buttons is pressed/released.

Anyway, looking at the BMessage documentation, there are no way to get which mouse was released in the event, so the only way is to store the current state in the MouseDown() hook and track it down in the MouseUp() one. Maybe a later addition for Haiku would be good.

Thanks everyone for the help.

Best Regards,

--
Carlo Lanzotti

DynaDream - Dynamic Laboratory

http://www.dynadream.com

Other related posts: