Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » How can I detect Button press / release
How can I detect Button press / release [message #29486] Sat, 23 October 2010 18:22 Go to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Greetings everyone

Can someone point me to a callback for button which does the following

WhenPush - I know this one
WhenRelease - does this exist?

I am trying to implement a feature which needs a particular pin on an I/O device to be high as long as the button is pushed/repeat action. The pin has to go low when the button is released.

How can I achieve this?

Thank you for your attention
Re: How can I detect Button press / release [message #29487 is a reply to message #29486] Sat, 23 October 2010 20:20 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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 #29490 is a reply to message #29487] Sat, 23 October 2010 22:31 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Jerson

I would do a new class from Button deriving virtual LeftDown() and LeftUp() methods.


Best regards
IƱaki
Re: How can I detect Button press / release [message #29494 is a reply to message #29486] Sun, 24 October 2010 04:18 Go to previous messageGo to next message
jerson is currently offline  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 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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
Re: How can I detect Button press / release [message #29496 is a reply to message #29486] Sun, 24 October 2010 14:34 Go to previous message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Hi Honza

thanks for your example code. I really appreciate your help.

I was getting some strange behaviour on Push and Release like having to move the mouse to see the button push painting or moving the mouse after releasing the button to see button release painting.

This is what made it work
void    JfButton::LeftDown(Point p, dword dw){
    SetLabel("Pushed");
    KeyPush();   // draw the button push state
}
void    JfButton::LeftUp(Point p, dword dw){
    SetLabel("Released");
    FinishPush(); // draw button release state
}


Regards
Previous Topic: Layout call procedure buggy for invisible controls?
Next Topic: Problem with Calendar control
Goto Forum:
  


Current Time: Thu Mar 28 17:34:24 CET 2024

Total time taken to generate the page: 0.01182 seconds