cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
2024 Technology Preview Program

2024 Technology Preview Program:
Master powerful new features and shape the latest BIM-enabled innovations

Archicad C++ API
About Archicad add-on development using the C++ API.

How to trigger an event when I move the cursor from the text?

Anonymous
Not applicable
I want to use static text as a hyperlink. And for it I need to configure changing of text color, when cursor over on text, the text is red, when the cursor is not over text, the text is blue.
I am using StaticTextMouseMoved function for, changed text to red color, but is the method called when cursor positioned over the text, and when I remove the cursor from the text it stays red. How to make it blue?

 

void Dialog::StaticTextMouseMoved(const DG::StaticTextMouseMoveEvent& ev, bool* noDefaultCursor) 
{ 
    leftText_.SetTextColor(Gfx::Color::Red); 
}
4 REPLIES 4
Viktor Kovacs
Graphisoft
Graphisoft

Haven't tried, but maybe the event arrives even if the mouse is not over the control. If so, than you can check the mouse position, and detect if it is over the control.

Int32 xPos = ev.GetMouseOffset ().GetX ();
Int32 yPos = ev.GetMouseOffset ().GetY ();

if (xPos > 0 && xPos < staticText.GetWidth () && yPos > 0 && yPos < staticText.GetHeight ()) {
	// mouse over the control
} else {
	// mouse not over the control
}

 

Anonymous
Not applicable
Unfortunately, the event arrives even if the mouse only is over control.
Viktor wrote:
Haven't tried, but maybe the event arrives even if the mouse is not over the control. If so, than you can check the mouse position, and detect if it is over the control.

Int32 xPos = ev.GetMouseOffset ().GetX ();
Int32 yPos = ev.GetMouseOffset ().GetY ();

if (xPos > 0 && xPos < staticText.GetWidth () && yPos > 0 && yPos < staticText.GetHeight ()) {
	// mouse over the control
} else {
	// mouse not over the control
}
Oleg
Expert

I dont know a simple solution. Some tricks, schematically.

1. Dont use changing of text color, but use changing of cursor (hand).
( There is some ready handler in UDLib, UDLinkItemHandler.hpp )

2. Use PanelIdle event trick

Enable idle event in dialog constructor and attach to the DG::PanelObserver

 

	EnableIdleEvent();
	Attach( *this );

 

	virtual void Dialog::PanelIdle (const PanelIdleEvent& ev)
	{
		MousePosData mp;
		mp.Retrieve(*this);

		Gfx::Color color = mp.GetItem() == &leftText_ ? Gfx::Color::Red : Gfx::Color::Blue;
		// to avoid flickering
		if ( leftText_.GetTextColor() != color )
			leftText_.SetTextColor( color );
	}

 

 

There is a specific control in the UD library for displaying links: UD::LinkText. You can find it in the UDLinkText.hpp.

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!