Home » U++ Library support » U++ Core » How do I implement mouse hover in Ctrl based class (How do I implement mouse hover in Ctrl based class)
Re: How do I implement mouse hover in Ctrl based class [message #57353 is a reply to message #57351] |
Fri, 16 July 2021 10:10 |
Oblivion
Messages: 1094 Registered: August 2007
|
Senior Contributor |
|
|
Here's another one: Same effect but with MouseEnter/MouseLeave pair, using a child ctrl.
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
struct MyCtrl : Ctrl {
void Paint(Draw& w) override
{
Point pt = GetMouseViewPos();
w.DrawRect(GetSize(), GetView().Contains(pt) ? Yellow : Red());
}
void MouseEnter(Point p, dword keyflags) override
{
Refresh();
}
void MouseLeave() override
{
Refresh();
}
void LeftDouble(Point p, dword keyflags) override
{
PromptOK("Ctrl double-clicked");
}
};
struct MyApp : TopWindow {
MyCtrl myctrl;
MyApp()
{
Sizeable().Zoomable().CenterScreen().SetRect(0,0, 1024, 800);
Add(myctrl.Tip(t_("\1This is a [* Rich[/ text tip ]]"))); // Set tip for child ctrl.
}
void Paint(Draw& w) override
{
Point pt = GetMouseViewPos(); // This method returns the mouse cursor position within the Ctrl's view area.
w.DrawRect(GetSize(), Black());
w.DrawText(10, 10, AsString(pt), Monospace(16), White());
}
void MouseMove(Point pt, dword keyflags) override
{
Refresh();
}
void Layout() override
{
myctrl.SetRect(GetView().CenterRect(GetSize() / 4));
}
};
GUI_APP_MAIN
{
MyApp().Run();
}
You can also see that the position display will stop if the mouse enters into the child ctrl.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Fri, 16 July 2021 10:20] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Tue May 14 13:08:22 CEST 2024
Total time taken to generate the page: 0.10632 seconds
|