|
|
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 Go to next message](theme/default/images/down.png) |
![](https://www.ultimatepp.org/forums/images/custom_avatars/2.png) |
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 #1916 is a reply to message #1912] |
Sun, 26 March 2006 23:27 ![Go to previous message Go to previous message](theme/default/images/up.png) ![Go to next message Go to next message](theme/default/images/down.png) |
![](https://www.ultimatepp.org/forums/images/custom_avatars/2.png) |
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
|
|
|
|
|
|
|
Goto Forum:
Current Time: Sun Sep 01 07:21:16 CEST 2024
Total time taken to generate the page: 0.02892 seconds
|
|
|