|
|
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » How can I detect Button press / release
|
Re: How can I detect Button press / release [message #29487 is a reply to message #29486] |
Sat, 23 October 2010 20:20   |
|
jerson wrote on Sat, 23 October 2010 18:22 | Can someone point me to a callback for button which does the following
WhenPush - I know this one
WhenRelease - does this exist?
|
Hi Jerson,
WhenAction is called when the mouse button is released above the button widget. If you also need to detect when user moves the mouse pointer out of the widgets area (which you probably want, otherwise your I/O pin would stay in high state), then you can either inherit from Button and overwrite MouseLeave() to take care of that. Other solution (without making your own class) might be some ugly use of WhenRepeat with timecallbacks setting turning the state of pin after some time unless another WhenRepeat is called, but that would be ugly and error prone.
Best regards,
Honza
|
|
|
|
Re: How can I detect Button press / release [message #29494 is a reply to message #29486] |
Sun, 24 October 2010 04:18   |
jerson
Messages: 202 Registered: June 2010 Location: Bombay, India
|
Experienced Member |

|
|
Hi Koldo
I'm a bit fuzzy on this one. Can you help me a bit more as to how to do this? This is how I did it now
class JfButton : public Button {
public:
virtual void LeftDown(Point, dword);
virtual void LeftUp(Point, dword);
};
and in my App, this
void JfButton::LeftDown(Point p, dword dw)
{
SetLabel("Pushed");
}
void JfButton::LeftUp(Point p, dword dw)
{
SetLabel("Released");
}
I understand Honza's point about releasing the button outside the widget rectangle and can see it hang. Surely I need to look at how to release when the Mouse leaves the widget rectangle.
Edit:
I no longer see the button being redrawn to pushed state. Is there something more that needs to be done to get this?
Regards
[Updated on: Sun, 24 October 2010 04:25] Report message to a moderator
|
|
|
Re: How can I detect Button press / release [message #29495 is a reply to message #29494] |
Sun, 24 October 2010 10:24   |
|
Hi Jerson,
This should take care of everything:class JfButton : public Button {
public:
virtual void LeftDown(Point, dword);
virtual void LeftUp(Point, dword);
virtual void MouseLeave();
virtual void MouseEnter(Point, dword);
};
void JfButton::LeftDown(Point p, dword dw){
SetLabel("Pushed");
}
void JfButton::LeftUp(Point p, dword dw){
SetLabel("Released");
}
void JfButton::MouseLeave(){
SetLabel("Released");
Button::MouseLeave();
}
void JfButton::MouseEnter(Point p,dword dw){
if(dw&K_MOUSELEFT){SetLabel("Pushed");}
Button::MouseEnter(p,dw);
}
Honza
|
|
|
|
Goto Forum:
Current Time: Sat Apr 26 18:28:33 CEST 2025
Total time taken to generate the page: 0.01209 seconds
|
|
|