diff options
author | Povilas Kanapickas <povilas@radix.lt> | 2022-08-25 00:18:29 +0300 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-08-26 09:12:54 +0200 |
commit | 85b65b90ac10d39190097af87a2de609e87eea9c (patch) | |
tree | e3a8c381e43da7237bf04f1f61ee868166e4699a | |
parent | 474414919c102f2973d2ed9815f997fdb1f30d9c (diff) |
vcl: implement rotate gesture infrastructure
This change implements internal infrastructure to pass rotate gestures
from low-level sources to the consuming GUI widgets. The API follows the
established begin-update-update-...-end event convention that is used on
various platforms.
The API should be enough to support bouth touchpad and touchscreen
gestures, as long as the underlying low-level source exposes enough
information. The hardware drivers usually expose touchpad gestures
already recognized whereas touchscreen gestures come as a set of moving
touchpoints and application needs to figure out their meaning itself.
Many toolkits recognize both and offer a unified higher-level interface
that can be used by us.
Change-Id: Iae667b3248d6f78bfb1eef755af6bc996432b6a7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138788
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | include/vcl/GestureEventRotate.hxx | 46 | ||||
-rw-r--r-- | include/vcl/commandevent.hxx | 21 | ||||
-rw-r--r-- | vcl/inc/salwtype.hxx | 10 | ||||
-rw-r--r-- | vcl/source/window/commandevent.cxx | 7 | ||||
-rw-r--r-- | vcl/source/window/winproc.cxx | 35 |
5 files changed, 119 insertions, 0 deletions
diff --git a/include/vcl/GestureEventRotate.hxx b/include/vcl/GestureEventRotate.hxx new file mode 100644 index 000000000000..39f4b310f973 --- /dev/null +++ b/include/vcl/GestureEventRotate.hxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#pragma once + +#include <vcl/dllapi.h> + +enum class GestureEventRotateType +{ + Begin, + Update, + End +}; + +class VCL_DLLPUBLIC GestureEventRotate +{ +public: + sal_Int32 mnX = 0; + sal_Int32 mnY = 0; + + GestureEventRotateType meEventType = GestureEventRotateType::Begin; + + // The difference of between the current gesture scale and the scale at the beginning of the + // gesture. + double mfAngleDelta = 0; + + GestureEventRotate() = default; + + GestureEventRotate(sal_Int32 nInitialX, sal_Int32 nInitialY, GestureEventRotateType eEventType, + double fAngleDelta) + : mnX(nInitialX) + , mnY(nInitialY) + , meEventType(eEventType) + , mfAngleDelta(fAngleDelta) + { + } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/commandevent.hxx b/include/vcl/commandevent.hxx index 71694cc6f087..7b3199b18ccd 100644 --- a/include/vcl/commandevent.hxx +++ b/include/vcl/commandevent.hxx @@ -29,6 +29,7 @@ #include <rtl/ustring.hxx> #include <vcl/GestureEvent.hxx> #include <vcl/GestureEventZoom.hxx> +#include <vcl/GestureEventRotate.hxx> class CommandExtTextInputData; class CommandWheelData; @@ -41,6 +42,7 @@ class CommandSwipeData; class CommandLongPressData; class CommandGestureData; class CommandGestureZoomData; +class CommandGestureRotateData; enum class CommandEventId; @@ -93,6 +95,7 @@ public: const CommandLongPressData* GetLongPressData() const; const CommandGestureData* GetGestureData() const; const CommandGestureZoomData* GetGestureZoomData() const; + const CommandGestureRotateData* GetGestureRotateData() const; }; class VCL_DLLPUBLIC CommandExtTextInputData @@ -341,6 +344,23 @@ public: {} }; +class VCL_DLLPUBLIC CommandGestureRotateData +{ +public: + const double mfX = 0; + const double mfY = 0; + const GestureEventRotateType meEventType = GestureEventRotateType::Begin; + const double mfAngleDelta = 0; + + CommandGestureRotateData(double fX, double fY, GestureEventRotateType eEventType, + double fAngleDelta) + : mfX(fX) + , mfY(fY) + , meEventType(eEventType) + , mfAngleDelta(fAngleDelta) + {} +}; + enum class CommandEventId { NONE = 0, @@ -366,6 +386,7 @@ enum class CommandEventId LongPress = 22, Gesture = 23, GestureZoom = 24, + GestureRotate = 25, }; #endif // INCLUDED_VCL_COMMANDEVENT_HXX diff --git a/vcl/inc/salwtype.hxx b/vcl/inc/salwtype.hxx index d920a16dc5d4..7b66ef5a2d45 100644 --- a/vcl/inc/salwtype.hxx +++ b/vcl/inc/salwtype.hxx @@ -27,6 +27,7 @@ #include <tools/long.hxx> #include <vcl/GestureEvent.hxx> #include <vcl/GestureEventZoom.hxx> +#include <vcl/GestureEventRotate.hxx> class LogicalFontInstance; class SalGraphics; @@ -93,6 +94,7 @@ enum class SalEvent { ExternalGesture, Gesture, GestureZoom, + GestureRotate, }; struct SalAbstractMouseEvent @@ -273,6 +275,14 @@ struct SalGestureZoomEvent double mfScaleDelta = 0; }; +struct SalGestureRotateEvent +{ + GestureEventRotateType meEventType = GestureEventRotateType::Begin; + tools::Long mnX = 0; + tools::Long mnY = 0; + double mfAngleDelta = 0; +}; + typedef void (*SALTIMERPROC)(); #endif // INCLUDED_VCL_INC_SALWTYPE_HXX diff --git a/vcl/source/window/commandevent.cxx b/vcl/source/window/commandevent.cxx index aeedcc79c197..5fdb5e9e41a1 100644 --- a/vcl/source/window/commandevent.cxx +++ b/vcl/source/window/commandevent.cxx @@ -203,5 +203,12 @@ const CommandGestureZoomData* CommandEvent::GetGestureZoomData() const return nullptr; } +const CommandGestureRotateData* CommandEvent::GetGestureRotateData() const +{ + if (mnCommand == CommandEventId::GestureRotate) + return static_cast<const CommandGestureRotateData*>(mpData); + else + return nullptr; +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx index 945cae89e76e..d98b8c2fae42 100644 --- a/vcl/source/window/winproc.cxx +++ b/vcl/source/window/winproc.cxx @@ -33,6 +33,7 @@ #include <vcl/event.hxx> #include <vcl/GestureEvent.hxx> #include <vcl/GestureEventZoom.hxx> +#include <vcl/GestureEventRotate.hxx> #include <vcl/settings.hxx> #include <vcl/svapp.hxx> #include <vcl/cursor.hxx> @@ -1848,6 +1849,34 @@ static bool ImplHandleGestureZoomEvent(vcl::Window* pWindow, const SalGestureZoo return aHandler.HandleEvent(); } +namespace { + +class HandleGestureRotateEvent : public HandleGestureEvent +{ +private: + CommandGestureRotateData m_aGestureData; + +public: + HandleGestureRotateEvent(vcl::Window* pWindow, const SalGestureRotateEvent& rEvent) + : HandleGestureEvent(pWindow, Point(rEvent.mnX, rEvent.mnY)) + , m_aGestureData(rEvent.mnX, rEvent.mnY, rEvent.meEventType, rEvent.mfAngleDelta) + { + } + + virtual bool CallCommand(vcl::Window* pWindow, const Point& /*rMousePos*/) override + { + return ImplCallCommand(pWindow, CommandEventId::GestureRotate, &m_aGestureData); + } +}; + +} + +static bool ImplHandleGestureRotateEvent(vcl::Window* pWindow, const SalGestureRotateEvent& rEvent) +{ + HandleGestureRotateEvent aHandler(pWindow, rEvent); + return aHandler.HandleEvent(); +} + static void ImplHandlePaint( vcl::Window* pWindow, const tools::Rectangle& rBoundRect, bool bImmediateUpdate ) { // system paint events must be checked for re-mirroring @@ -2908,6 +2937,12 @@ bool ImplWindowFrameProc( vcl::Window* _pWindow, SalEvent nEvent, const void* pE bRet = ImplHandleGestureZoomEvent(pWindow, *pGestureEvent); } break; + case SalEvent::GestureRotate: + { + const auto * pGestureEvent = static_cast<SalGestureRotateEvent const *>(pEvent); + bRet = ImplHandleGestureRotateEvent(pWindow, *pGestureEvent); + } + break; default: SAL_WARN( "vcl.layout", "ImplWindowFrameProc(): unknown event (" << static_cast<int>(nEvent) << ")" ); break; |