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 » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Mouse over button example -"catch me if you can..."
Mouse over button example -"catch me if you can..." [message #1908] Sun, 26 March 2006 13:48 Go to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
#include <CtrlLib/CtrlLib.h>
//this demonstrates how to install some useful callbacks... :)

class MoButton : public Button {
    bool wasHere;
public:
	typedef MoButton CLASSNAME;
	Callback WhenMouseEnter, WhenMouseLeave;
	virtual void   MouseEnter(Point p, dword f) {wasHere=true; WhenMouseEnter();}
	virtual void   MouseLeave();
	void SetWasNotHere() {wasHere=false;}
	
	MoButton(){;}
	~MoButton(){;}    
};

void  MoButton::MouseLeave() {
	if (wasHere){
		ReleaseCapture(); //do I really need this?
		wasHere=false;
		WhenMouseLeave();
	}
}


class App : public TopWindow {
	MoButton opener;
	TopWindow info;
public:
	typedef App CLASSNAME;
	void openerIn();
	void openerOut();
	void openerFix();
	
	App();
};

void App::openerIn(){
	info.BottomPosZ(5, 200).HSizePos(200, 200); //use it here if you want to adjust according to button pos...

	if(!info.IsOpen()) { info.Open(); opener.SetFocus(); }
}

void App::openerOut(){
	if(info.IsOpen()) { info.Close(); }
}

void App::openerFix(){
	if(info.IsOpen()) { info.SetFocus(); opener.SetWasNotHere(); }
}
	
App::App() {
	Add(opener.TopPosZ(5, 50).LeftPos(10, 250));
	opener.SetLabel("opener test Button Mouse-In Mouse-Out");
	
	info.Title("Catch me if you can!... :)");
	
	opener.WhenMouseEnter = THISBACK(openerIn);
	opener.WhenMouseLeave = THISBACK(openerOut);
	opener.WhenPush = THISBACK(openerFix);

	OpenMain();
	Sizeable().Zoomable();
	Title("Mouse Over Button");
}


GUI_APP_MAIN
{
	App().Run();
}


feel free to critisize and improve...

[Updated on: Tue, 18 April 2006 01:26]

Report message to a moderator

Re: Mouse over button example... [message #1912 is a reply to message #1908] Sun, 26 March 2006 18:22 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13984
Registered: November 2005
Ultimate Member
fudadmin wrote on Sun, 26 March 2006 06:48

[code]
feel free to critisize and improve...


There is serious problem with this code: you should call Button::MouseLeave and Button::MouseEnter inside your overrides. (This bug demostrates in XP visual style by orange highlight being stuck).

Mirek

Re: Mouse over button example... [message #1916 is a reply to message #1912] Sun, 26 March 2006 23:27 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
luzr wrote on Sun, 26 March 2006 17:22

fudadmin wrote on Sun, 26 March 2006 06:48

[code]
feel free to critisize and improve...


There is serious problem with this code: you should call Button::MouseLeave and Button::MouseEnter inside your overrides. (This bug demostrates in XP visual style by orange highlight being stuck).

Mirek



Thanks! Is it correct now?
#include <CtrlLib/CtrlLib.h>
//this demonstrates how to install some useful callbacks...

class MoButton : public Button {
    bool wasHere;
public:
	typedef MoButton CLASSNAME;
	Callback WhenMouseEnter, WhenMouseLeave;
	virtual void   MouseEnter(Point p, dword f);
	virtual void   MouseLeave();
	void SetWasNotHere() {wasHere=false;}
	
	MoButton(){wasHere=false;}
	~MoButton(){;}    
};

void  MoButton::MouseEnter(Point p, dword f) {
	if (!wasHere){
		wasHere=true;
		WhenMouseEnter();
	}
	Button::MouseEnter(p,f); //don't forget to call what you have overridden...
}

void  MoButton::MouseLeave() {
	if (wasHere){
		//ReleaseCapture(); //do I really need this? - not in this case :)
		wasHere=false;
		WhenMouseLeave();
	}
	Button::MouseLeave(); //don't forget to call what you have overridden...
}


class App : public TopWindow {
	MoButton opener;
	TopWindow info;
public:
	typedef App CLASSNAME;
	void openerIn();
	void openerOut();
	void openerFix();
	
	App();
};

void App::openerIn(){
	info.BottomPosZ(5, 200).HSizePos(200, 200); //use it here if you want to adjust according to button pos...

	if(!info.IsOpen()) { info.Open(); opener.SetFocus(); }
}

void App::openerOut(){
	if(info.IsOpen()) { info.Close(); }
}

void App::openerFix(){
	if(info.IsOpen()) { info.SetFocus(); opener.SetWasNotHere(); }
}
	
App::App() {
	Add(opener.TopPosZ(5, 50).LeftPos(10, 250));
	opener.SetLabel("opener test Button Mouse-In Mouse-Out");
	
	info.Title("Catch me if you can!... :)");
	
	opener.WhenMouseEnter = THISBACK(openerIn);
	opener.WhenMouseLeave = THISBACK(openerOut);
	opener.WhenPush = THISBACK(openerFix);

	OpenMain();
	Sizeable().Zoomable();
	Title("Mouse Over Button");
}


GUI_APP_MAIN
{
	App().Run();
}

[Updated on: Mon, 27 March 2006 02:11]

Report message to a moderator

Re: Mouse over button example... [message #1918 is a reply to message #1916] Mon, 27 March 2006 02:04 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13984
Registered: November 2005
Ultimate Member
Much better. Remove that "ReleaseCapture" too and I will be happy Wink

Mirek
Re: Mouse over button example... [message #1919 is a reply to message #1918] Mon, 27 March 2006 02:13 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
luzr wrote on Mon, 27 March 2006 01:04

Much better. Remove that "ReleaseCapture" too and I will be happy Wink

Mirek


Thanks. Done.
Re: Mouse over button example... [message #1923 is a reply to message #1919] Mon, 27 March 2006 12:10 Go to previous messageGo to next message
gprentice is currently offline  gprentice
Messages: 260
Registered: November 2005
Location: New Zealand
Experienced Member

Catch me if you can?

ok, I can - click the button!
Re: Mouse over button example... [message #1924 is a reply to message #1923] Mon, 27 March 2006 12:25 Go to previous message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
gprentice wrote on Mon, 27 March 2006 11:10


Catch me if you can?

ok, I can - click the button!



You are improving too fast... Smile Next time I'll make something more difficult for you... Smile


Previous Topic: Slider and "Dynamic rectangle" example
Next Topic: How to combine two widget-class in the topwindow
Goto Forum:
  


Current Time: Sat Jun 15 16:10:50 CEST 2024

Total time taken to generate the page: 0.02645 seconds