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..."
Re: Mouse over button example... [message #1916 is a reply to message #1912] |
Sun, 26 March 2006 23:27   |
 |
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: Sat Apr 26 08:35:24 CEST 2025
Total time taken to generate the page: 0.00447 seconds
|