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++ 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 Go to previous messageGo to previous message
Oblivion is currently offline  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


[Updated on: Fri, 16 July 2021 10:20]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Jsonize() Date and Time serialization [patch]
Next Topic: Probable nasty bug with StringBuffer
Goto Forum:
  


Current Time: Tue May 14 13:08:22 CEST 2024

Total time taken to generate the page: 0.10632 seconds