BsHandleSlider.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsVector2I.h"
  4. #include "BsMatrix4.h"
  5. #include "BsQuaternion.h"
  6. namespace BansheeEngine
  7. {
  8. class BS_ED_EXPORT HandleSlider
  9. {
  10. public:
  11. enum class State
  12. {
  13. Inactive,
  14. Active,
  15. Hover
  16. };
  17. HandleSlider(bool fixedScale, float snapValue);
  18. virtual ~HandleSlider() { }
  19. virtual bool intersects(const Ray& ray, float& t) const = 0;
  20. virtual void update(const HCamera& camera, const Vector2I& pointerPos, const Ray& ray) = 0;
  21. State getState() const { return mState; }
  22. bool getFixedScale() const { return mFixedScale; }
  23. float getSnapValue() const { return mSnapValue; }
  24. void setPosition(const Vector3& position);
  25. void setRotation(const Quaternion& rotation);
  26. void setScale(const Vector3& scale);
  27. const Vector3& getPosition() const { return mPosition; }
  28. const Quaternion& getRotation() const { return mRotation; }
  29. const Vector3& getScale() const { return mScale; }
  30. protected:
  31. friend class HandleSliderManager;
  32. void setInactive() { mState = State::Inactive; reset(); }
  33. void setActive(const Vector2I& pointerPos) { mState = State::Active; mLastPointerPos = pointerPos; }
  34. void setHover() { mState = State::Hover; reset(); }
  35. const Matrix4& getTransform() const;
  36. const Matrix4& getTransformInv() const;
  37. virtual void updateCachedTransform() const;
  38. virtual void reset() = 0;
  39. float calcDelta(const HCamera& camera, const Vector3& position, const Vector3& direction,
  40. const Vector2I& pointerStart, const Vector2I& pointerEnd);
  41. bool mFixedScale;
  42. float mSnapValue;
  43. Vector3 mPosition;
  44. Quaternion mRotation;
  45. Vector3 mScale;
  46. Vector2I mLastPointerPos;
  47. Vector2I mCurPointerPos;
  48. State mState;
  49. mutable bool mTransformDirty;
  50. mutable Matrix4 mTransform;
  51. mutable Matrix4 mTransformInv;
  52. };
  53. }