mirror of
https://github.com/overte-org/overte.git
synced 2025-07-16 17:37:03 +02:00
83 lines
2.5 KiB
C++
83 lines
2.5 KiB
C++
//
|
|
// Created by Bradley Austin Davis on 2017/10/24
|
|
// Copyright 2013-2017 High Fidelity, Inc.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
//
|
|
#ifndef hifi_StylusPointer_h
|
|
#define hifi_StylusPointer_h
|
|
|
|
#include <Pointer.h>
|
|
#include <shared/Bilateral.h>
|
|
#include <RegisteredMetaTypes.h>
|
|
|
|
#include "ui/overlays/Overlay.h"
|
|
|
|
#include "StylusPick.h"
|
|
|
|
class StylusPointer : public Pointer {
|
|
using Parent = Pointer;
|
|
using Ptr = std::shared_ptr<StylusPointer>;
|
|
|
|
public:
|
|
StylusPointer(const QVariant& props, const OverlayID& stylusOverlay, bool hover, bool enabled);
|
|
~StylusPointer();
|
|
|
|
void updateVisuals(const PickResultPointer& pickResult) override;
|
|
|
|
// Styluses have three render states:
|
|
// default: "events on" -> render and hover/trigger
|
|
// "events off" -> render, don't hover/trigger
|
|
// "disabled" -> don't render, don't hover/trigger
|
|
void setRenderState(const std::string& state) override;
|
|
void editRenderState(const std::string& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps) override {}
|
|
|
|
static OverlayID buildStylusOverlay(const QVariantMap& properties);
|
|
|
|
protected:
|
|
PickedObject getHoveredObject(const PickResultPointer& pickResult) override;
|
|
Buttons getPressedButtons() override;
|
|
bool shouldHover(const PickResultPointer& pickResult) override;
|
|
bool shouldTrigger(const PickResultPointer& pickResult) override;
|
|
|
|
PointerEvent buildPointerEvent(const PickedObject& target, const PickResultPointer& pickResult, bool hover = true) const override;
|
|
|
|
private:
|
|
void show(const StylusTip& tip);
|
|
void hide();
|
|
|
|
struct TriggerState {
|
|
PickedObject triggeredObject;
|
|
glm::vec3 intersection { NAN };
|
|
glm::vec2 triggerPos2D { NAN };
|
|
glm::vec3 surfaceNormal { NAN };
|
|
quint64 triggerStartTime { 0 };
|
|
bool triggering { false };
|
|
|
|
bool hovering { false };
|
|
};
|
|
|
|
TriggerState _state;
|
|
|
|
enum RenderState {
|
|
EVENTS_ON = 0,
|
|
EVENTS_OFF,
|
|
DISABLED
|
|
};
|
|
|
|
RenderState _renderState { EVENTS_ON };
|
|
|
|
const OverlayID _stylusOverlay;
|
|
|
|
static bool isWithinBounds(float distance, float min, float max, float hysteresis);
|
|
static glm::vec3 findIntersection(const PickedObject& pickedObject, const glm::vec3& origin, const glm::vec3& direction);
|
|
static glm::vec2 findPos2D(const PickedObject& pickedObject, const glm::vec3& origin);
|
|
|
|
};
|
|
|
|
#endif // hifi_StylusPointer_h
|
|
|
|
|
|
|
|
|