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 #57352 is a reply to message #57351] Thu, 15 July 2021 19:38 Go to previous messageGo to previous message
Oblivion is currently offline  Oblivion
Messages: 1094
Registered: August 2007
Senior Contributor
Hello awksed,

Try this:


#include <CtrlLib/CtrlLib.h>

using namespace Upp;


struct MyApp : TopWindow {
	Point pos;
	Rect  area;
	MyApp()
	{
		Sizeable().Zoomable().CenterScreen().SetRect(0,0, 1024, 800);
	}
	
	void Paint(Draw& w) override
	{
		w.DrawRect(GetSize(), Black());
		w.DrawRect(area, area.Contains(pos) ? Yellow() : Red());
		w.DrawText(10, 10, AsString(pos), Monospace(16), White());
	}
	
	void MouseMove(Point p, dword keyflags) override
	{
		pos = p;
		Tip(area.Contains(p) ? t_("\1This is a [* Rich[/ text tip ]]") : nullptr);
		Refresh();
		
	}
	
	void Layout() override
	{
		area =  GetView().CenterRect(GetSize() / 4);
	}
};

GUI_APP_MAIN
{
	MyApp().Run();
}



A slightly different version which retrieves the mouse position using a method.

#include <CtrlLib/CtrlLib.h>

using namespace Upp;


struct MyApp : TopWindow {
	Rect  area;
	MyApp()
	{
		Sizeable().Zoomable().CenterScreen().SetRect(0,0, 1024, 800);
	}
	
	void Paint(Draw& w) override
	{
		Point pt = GetMouseViewPos(); // This method returns the mouse cursor position relative to the Ctrl's view area.
		w.DrawRect(GetSize(), Black());
		w.DrawRect(area, area.Contains(pt) ? Yellow() : Red());
		w.DrawText(10, 10, AsString(pt), Monospace(16), White());
	}
	
	void MouseMove(Point pt, dword keyflags) override
	{
		// Dispatched when the mouse cursor moves. It CAN also be used to retrieve and store the mouse position.
		// ( instead of GetMouseViewPos() )
		Tip(area.Contains(pt) ? t_("\1This is a [* Rich[/ text tip ]]") : nullptr);
		Refresh();
		
	}
	
	void Layout() override
	{
		area =  GetView().CenterRect(GetSize() / 4);
	}
};

GUI_APP_MAIN
{
	MyApp().Run();
}



Keep in mind that this is a generic and very rudimentary way. Use the overrideable mouse methods for ctrls for fine grained behaviour (as Xemuth suggested).


U++ ctrls provide a method called Tip() which can take a plain or rich text. If all you need is a tooltip for the existing U++ widgets, you can just set the tip.


Best regards,
Oblivion


[Updated on: Thu, 15 July 2021 20:36]

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: Wed May 15 00:04:45 CEST 2024

Total time taken to generate the page: 0.03537 seconds