1// Aseprite
2// Copyright (C) 2020-2021 Igara Studio S.A.
3//
4// This program is distributed under the terms of
5// the End-User License Agreement for Aseprite.
6
7#ifndef APP_TOOLS_VELOCITY_H_INCLUDED
8#define APP_TOOLS_VELOCITY_H_INCLUDED
9#pragma once
10
11#include "app/tools/pointer.h"
12#include "base/time.h"
13#include "base/vector2d.h"
14#include "gfx/point.h"
15
16namespace app {
17namespace tools {
18
19// Mouse velocity sensor
20class VelocitySensor {
21public:
22 // Milliseconds between two updates to change the velocity vector
23 // with the new value (shorter periods will mix the old velocity
24 // vector with the new one).
25 static constexpr float kFullUpdateMSecs = 50.0f;
26
27 // Maximum length of the velocity vector (number of screen pixels
28 // traveled between two updates) to create a max sensor output.
29 static constexpr float kScreenPixelsForFullVelocity = 32.0f; // TODO 32 should be configurable
30
31 VelocitySensor();
32
33 void reset();
34
35 const Vec2& velocity() const { return m_velocity; }
36
37 void updateWithDisplayPoint(const gfx::Point& screenPoint);
38
39private:
40 bool m_firstPoint;
41 Vec2 m_velocity;
42 gfx::Point m_lastPoint;
43 base::tick_t m_lastUpdate;
44};
45
46} // namespace tools
47} // namespace app
48
49#endif
50