1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-02 03:20:06 +00:00
JUCE/modules/juce_gui_basics/mouse/juce_PointerState.h
2022-04-04 12:36:32 +01:00

102 lines
4.1 KiB
C++

/*
==============================================================================
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<float> x) const noexcept { return with (&PointerState::position, position + x); }
JUCE_NODISCARD PointerState withPosition (Point<float> 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<float> 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<float>::twoPi; }
bool isRotationValid() const noexcept { return 0.0f <= rotation && rotation <= MathConstants<float>::twoPi; }
bool isTiltValid (bool isX) const noexcept
{
return isX ? (-1.0f <= tiltX && tiltX <= 1.0f)
: (-1.0f <= tiltY && tiltY <= 1.0f);
}
private:
template <typename Value>
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<float> 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