Forráskód Böngészése

`Context::ProcessMouseWheel` now takes a float value for the `wheel_delta` property

Michael Ragazzon 6 éve
szülő
commit
7bad27a8f8

+ 1 - 1
Include/Rocket/Core/Context.h

@@ -202,7 +202,7 @@ public:
 	/// @param[in] wheel_delta The mouse-wheel movement this frame. Rocket treats a negative delta as up movement (away from the user), positive as 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(int wheel_delta, int key_modifier_state);
+	bool ProcessMouseWheel(float wheel_delta, int key_modifier_state);
 
 	/// Notifies Rocket of a change in the projection matrix.
 	/// @param[in] projection The new projection matrix.

+ 2 - 2
Samples/shell/src/win32/InputWin32.cpp

@@ -84,7 +84,7 @@ void InputWin32::ProcessWindowsEvent(UINT message, WPARAM w_param, LPARAM l_para
 			break;
 
 		case WM_MOUSEWHEEL:
-			context->ProcessMouseWheel(((short) HIWORD(w_param)) / -WHEEL_DELTA, GetKeyModifierState());
+			context->ProcessMouseWheel(static_cast<float>((short) HIWORD(w_param)) / static_cast<float>(-WHEEL_DELTA), GetKeyModifierState());
 			break;
 
 		case WM_KEYDOWN:
@@ -92,7 +92,7 @@ void InputWin32::ProcessWindowsEvent(UINT message, WPARAM w_param, LPARAM l_para
 			Rocket::Core::Input::KeyIdentifier key_identifier = key_identifier_map[w_param];
 			int key_modifier_state = GetKeyModifierState();
 
-			// Check for a shift-~ to toggle the debugger.
+			// Check for F8 to toggle the debugger.
 			if (key_identifier == Rocket::Core::Input::KI_F8)
 			{
 				Rocket::Debugger::SetVisible(!Rocket::Debugger::IsVisible());

+ 1 - 1
Source/Core/Context.cpp

@@ -746,7 +746,7 @@ void Context::ProcessMouseButtonUp(int button_index, int key_modifier_state)
 }
 
 // Sends a mouse-wheel movement event into Rocket.
-bool Context::ProcessMouseWheel(int wheel_delta, int key_modifier_state)
+bool Context::ProcessMouseWheel(float wheel_delta, int key_modifier_state)
 {
 	if (hover)
 	{

+ 9 - 2
Source/Core/Element.cpp

@@ -33,6 +33,7 @@
 #include <algorithm>
 #include <limits>
 #include "Clock.h"
+#include "ComputeProperty.h"
 #include "ElementAnimation.h"
 #include "ElementBackground.h"
 #include "ElementBorder.h"
@@ -1957,11 +1958,17 @@ void Element::ProcessEvent(Event& event)
 				// to scroll in parent elements when reaching top/bottom, move StopPropagation inside the next if statement.
 				event.StopPropagation();
 
-				int wheel_delta = event.GetParameter< int >("wheel_delta", 0);
+				const float wheel_delta = event.GetParameter< float >("wheel_delta", 0.f);
+
 				if ((wheel_delta < 0 && GetScrollTop() > 0) ||
 					(wheel_delta > 0 && GetScrollHeight() > GetScrollTop() + GetClientHeight()))
 				{
-					SetScrollTop(GetScrollTop() + wheel_delta * GetLineHeight());
+					// Defined as three times the default line-height, multiplied by the dp ratio.
+					float default_scroll_length = 3.f * DefaultComputedValues.line_height.value;
+					if (const Context* context = GetContext())
+						default_scroll_length *= context->GetDensityIndependentPixelRatio();
+
+					SetScrollTop(GetScrollTop() + Math::RoundFloat(wheel_delta * default_scroll_length));
 				}
 			}
 		}

+ 4 - 0
readme.md

@@ -46,6 +46,10 @@ If upgrading from the original libRocket branch, some breaking changes should be
 - Removed RenderInterface::GetPixelsPerInch, instead the pixels per inch value has been fixed to 96 PPI, as per CSS specs. To achieve a scalable user interface, instead use the 'dp' unit.
 - Removed 'top' and 'bottom' from z-index property.
 
+## Other changes
+
+- `Context::ProcessMouseWheel` now takes a float value for the `wheel_delta` property, thereby enabling continuous/smooth scrolling for input devices with such support. The default scroll length for unity value of `wheel_delta` is now three times the default line-height multiplied by the current dp-ratio.
+
 
 ## Performance