Browse Source

Context::ProcessMouseWheel can now be scrolled in both dimensions

Michael Ragazzon 2 years ago
parent
commit
770ab8e1dd
2 changed files with 14 additions and 8 deletions
  1. 6 6
      Include/RmlUi/Core/Context.h
  2. 8 2
      Source/Core/Context.cpp

+ 6 - 6
Include/RmlUi/Core/Context.h

@@ -216,11 +216,14 @@ public:
 	/// @param[in] key_modifier_state The state of key modifiers (shift, control, caps-lock, etc) keys; this should be generated by ORing together members of the Input::KeyModifier enumeration.
 	/// @return True if the mouse is not interacting with any elements in the context (see 'IsMouseInteracting'), otherwise false.
 	bool ProcessMouseButtonUp(int button_index, int key_modifier_state);
-	/// Sends a mouse-wheel movement event into this context.
-	/// @param[in] wheel_delta The mouse-wheel movement this frame. RmlUi treats a negative delta as up movement (away from the user), positive as down.
+	/// Sends a mousescroll event into this context.
+	/// @deprecated Please use the Vector2f version of this function.
+	bool ProcessMouseWheel(float wheel_delta, int key_modifier_state);
+	/// Sends a mousescroll event into this context, and scrolls the document unless the event was stopped from propagating.
+	/// @param[in] wheel_delta The mouse-wheel movement this frame, with positive values being directed right and down.
 	/// @param[in] key_modifier_state The state of key modifiers (shift, control, caps-lock, etc) keys; this should be generated by ORing together members of the Input::KeyModifier enumeration.
 	/// @return True if the event was not consumed (ie, was prevented from propagating by an element), false if it was.
-	bool ProcessMouseWheel(float wheel_delta, int key_modifier_state);
+	bool ProcessMouseWheel(Vector2f wheel_delta, int key_modifier_state);
 	/// Tells the context the mouse has left the window. This removes any hover state from all elements and prevents 'Update()' from setting the hover state for elements under the mouse.
 	/// @return True if the mouse is not interacting with any elements in the context (see 'IsMouseInteracting'), otherwise false.
 	/// @note The mouse is considered activate again after the next call to 'ProcessMouseMove()'.
@@ -258,13 +261,11 @@ public:
 	/// @param[in] data_type_register The data type register to use for the data model, or null to use the default register.
 	/// @return A constructor for the data model, or empty if it could not be created.
 	DataModelConstructor CreateDataModel(const String& name, DataTypeRegister* data_type_register = nullptr);
-
 	/// Retrieves the constructor for an existing data model.
 	/// The returned constructor can be used to add additional bindings to an existing model.
 	/// @param[in] name The name of the data model.
 	/// @return A constructor for the data model, or empty if it could not be found.
 	DataModelConstructor GetDataModel(const String& name);
-
 	/// Removes the given data model.
 	/// This also removes all data views, controllers and bindings contained by the data model.
 	/// @warning Invalidates all handles and constructors pointing to the data model.
@@ -275,7 +276,6 @@ public:
 	/// This will set the documents base <tag> before creation. Default = "body"
 	/// @param[in] tag The name of the base tag. Example: "html"
 	void SetDocumentsBaseTag(const String& tag);
-
 	/// Gets the name of the documents base tag.
 	/// @return The current documents base tag name.
 	const String& GetDocumentsBaseTag();

+ 8 - 2
Source/Core/Context.cpp

@@ -827,6 +827,11 @@ bool Context::ProcessMouseButtonUp(int button_index, int key_modifier_state)
 }
 
 bool Context::ProcessMouseWheel(float wheel_delta, int key_modifier_state)
+{
+	return ProcessMouseWheel(Vector2f{0.f, wheel_delta}, key_modifier_state);
+}
+
+bool Context::ProcessMouseWheel(Vector2f wheel_delta, int key_modifier_state)
 {
 	if (scroll_controller->GetMode() == ScrollController::Mode::Autoscroll)
 	{
@@ -842,14 +847,15 @@ bool Context::ProcessMouseWheel(float wheel_delta, int key_modifier_state)
 	Dictionary scroll_parameters;
 	GenerateMouseEventParameters(scroll_parameters);
 	GenerateKeyModifierEventParameters(scroll_parameters, key_modifier_state);
-	scroll_parameters["wheel_delta"] = wheel_delta;
+	scroll_parameters["wheel_delta_x"] = wheel_delta.x;
+	scroll_parameters["wheel_delta_y"] = wheel_delta.y;
 
 	// Dispatch a mouse scroll event, this gives elements an opportunity to block scrolling from being performed.
 	if (!hover->DispatchEvent(EventId::Mousescroll, scroll_parameters))
 		return false;
 
 	const float unit_scroll_length = UNIT_SCROLL_LENGTH * density_independent_pixel_ratio;
-	const Vector2f scroll_length = {0.f, wheel_delta * unit_scroll_length};
+	const Vector2f scroll_length = wheel_delta * unit_scroll_length;
 	Element* target = hover->GetClosestScrollableContainer();
 
 	if (scroll_controller->GetMode() == ScrollController::Mode::Smoothscroll && scroll_controller->GetTarget() == target)