Browse Source

Better handling of mouse cursor

Michael Ragazzon 6 years ago
parent
commit
780d22e4ba
2 changed files with 18 additions and 5 deletions
  1. 3 2
      Include/Rocket/Core/Context.h
  2. 15 3
      Source/Core/Context.cpp

+ 3 - 2
Include/Rocket/Core/Context.h

@@ -120,8 +120,8 @@ public:
 	/// Unloads all loaded documents.
 	void UnloadAllDocuments();
 
-	/// Enable or disable handling mouse cursor from this context.
-	/// Only a single context should handle the mouse cursor at the same time.
+	/// Enable or disable handling of the mouse cursor from this context. If enabled, this will disable
+	/// cursor handling in all other contexts.
 	/// @param[in] show True to enable mouse cursor handling, false to disable.
 	void EnableMouseCursor(bool enable);
 
@@ -267,6 +267,7 @@ private:
 
 	// Enables cursor handling.
 	bool enable_cursor;
+	String cursor_name;
 	// Document attached to cursor (e.g. while dragging).
 	ElementDocument* cursor_proxy;
 

+ 15 - 3
Source/Core/Context.cpp

@@ -369,6 +369,14 @@ void Context::UnloadAllDocuments()
 // Enables or disables the mouse cursor.
 void Context::EnableMouseCursor(bool enable)
 {
+	for (int i = 0; i < GetNumContexts(); i++)
+	{
+		if (Context * other_context = GetContext(i))
+			other_context->enable_cursor = false;
+	}
+
+	// The cursor is set to an invalid name so that it is forced to update in the next update loop.
+	cursor_name = ":reset:";
 	enable_cursor = enable;
 }
 
@@ -937,12 +945,16 @@ void Context::UpdateHoverChain(const Dictionary& parameters, const Dictionary& d
 
 	if(enable_cursor)
 	{
-		String new_mouse_cursor;
+		String new_cursor_name;
 
 		if (hover && hover->GetProperty(CURSOR)->unit != Property::KEYWORD)
-			new_mouse_cursor = hover->GetProperty< String >(CURSOR);
+			new_cursor_name = hover->GetProperty< String >(CURSOR);
 
-		GetSystemInterface()->SetMouseCursor(new_mouse_cursor);
+		if(new_cursor_name != cursor_name)
+		{
+			GetSystemInterface()->SetMouseCursor(new_cursor_name);
+			cursor_name = new_cursor_name;
+		}
 	}
 
 	// Build the new hover chain.