Skip to content

Commit

Permalink
Context::ProcessMouseWheel now takes a float value for the `wheel_d…
Browse files Browse the repository at this point in the history
…elta` property
  • Loading branch information
mikke89 committed May 29, 2019
1 parent 9bb8906 commit 7bad27a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Include/Rocket/Core/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class ROCKETCORE_API Context : public ScriptInterface
/// @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.
Expand Down
4 changes: 2 additions & 2 deletions Samples/shell/src/win32/InputWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ 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:
{
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());
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
11 changes: 9 additions & 2 deletions Source/Core/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <algorithm>
#include <limits>
#include "Clock.h"
#include "ComputeProperty.h"
#include "ElementAnimation.h"
#include "ElementBackground.h"
#include "ElementBorder.h"
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7bad27a

Please sign in to comment.