/* ============================================================================== This file is part of the JUCE 7 technical preview. Copyright (c) 2022 - Raw Material Software Limited You may use this code under the terms of the GPL v3 (see www.gnu.org/licenses). For the technical preview this file cannot be licensed commercially. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE DISCLAIMED. ============================================================================== */ namespace juce { #ifndef DOXYGEN class PointerState { auto tie() const noexcept { return std::tie (position, pressure, orientation, rotation, tiltX, tiltY); } public: PointerState() = default; bool operator== (const PointerState& other) const noexcept { return tie() == other.tie(); } bool operator!= (const PointerState& other) const noexcept { return tie() != other.tie(); } JUCE_NODISCARD PointerState withPositionOffset (Point x) const noexcept { return with (&PointerState::position, position + x); } JUCE_NODISCARD PointerState withPosition (Point x) const noexcept { return with (&PointerState::position, x); } JUCE_NODISCARD PointerState withPressure (float x) const noexcept { return with (&PointerState::pressure, x); } JUCE_NODISCARD PointerState withOrientation (float x) const noexcept { return with (&PointerState::orientation, x); } JUCE_NODISCARD PointerState withRotation (float x) const noexcept { return with (&PointerState::rotation, x); } JUCE_NODISCARD PointerState withTiltX (float x) const noexcept { return with (&PointerState::tiltX, x); } JUCE_NODISCARD PointerState withTiltY (float x) const noexcept { return with (&PointerState::tiltY, x); } Point position; float pressure = MouseInputSource::defaultPressure; float orientation = MouseInputSource::defaultOrientation; float rotation = MouseInputSource::defaultRotation; float tiltX = MouseInputSource::defaultTiltX; float tiltY = MouseInputSource::defaultTiltY; bool isPressureValid() const noexcept { return 0.0f <= pressure && pressure <= 1.0f; } bool isOrientationValid() const noexcept { return 0.0f <= orientation && orientation <= MathConstants::twoPi; } bool isRotationValid() const noexcept { return 0.0f <= rotation && rotation <= MathConstants::twoPi; } bool isTiltValid (bool isX) const noexcept { return isX ? (-1.0f <= tiltX && tiltX <= 1.0f) : (-1.0f <= tiltY && tiltY <= 1.0f); } private: template PointerState with (Value PointerState::* member, Value item) const { auto copy = *this; copy.*member = std::move (item); return copy; } }; inline auto makeMouseEvent (MouseInputSource source, const PointerState& ps, ModifierKeys modifiers, Component* eventComponent, Component* originator, Time eventTime, Point mouseDownPos, Time mouseDownTime, int numberOfClicks, bool mouseWasDragged) { return MouseEvent (source, ps.position, modifiers, ps.pressure, ps.orientation, ps.rotation, ps.tiltX, ps.tiltY, eventComponent, originator, eventTime, mouseDownPos, mouseDownTime, numberOfClicks, mouseWasDragged); } #endif } // namespace juce