| 1 | /* |
| 2 | * Copyright (C) 2013 Canonical Ltd. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 3. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ |
| 16 | |
| 17 | #ifndef DAMPER_P_H |
| 18 | #define DAMPER_P_Hcxx . . $ `src/LomiriGestures/damper_p.h:18:9`! |
| 19 | |
| 20 | #include <QtCore/QPointF> |
| 21 | |
| 22 | /* |
| 23 | Decreases the oscillations of a value along an axis. |
| 24 | */ |
| 25 | template <class Type> class Dampercxx . . $ Damper# { |
| 26 | public: |
| 27 | Dampercxx . . $ Damper#`Damper<Type>`(49f6e7a06ebc5aa8).() : m_valuecxx . . $ Damper#m_value.(0), m_maxDeltacxx . . $ Damper#m_maxDelta.(0) { } |
| 28 | |
| 29 | // Maximum delta between the raw value and its dampened counterpart. |
| 30 | void setMaxDeltacxx . . $ Damper#setMaxDelta(9b289cee16747614).(Type maxDelta) { |
| 31 | if (maxDelta <cxx . . $ `operator<`(f3c92e5719291fd4). 0) qFatalcxx . . $ QMessageLogger#QMessageLogger(1e8c11a11d48e725).("Damper::maxDelta must be a positive number."); |
| 32 | m_maxDeltacxx . . $ Damper#m_maxDelta. = maxDelta; |
| 33 | } |
| 34 | Type maxDeltacxx . . $ Damper#maxDelta(8f5363d873dd4781).() const { return m_maxDeltacxx . . $ Damper#m_maxDelta.; } |
| 35 | |
| 36 | void resetcxx . . $ Damper#reset(9b289cee16747614).(Type value) { |
| 37 | m_valuecxx . . $ Damper#m_value. = value; |
| 38 | } |
| 39 | |
| 40 | Type updatecxx . . $ Damper#update(ada6a8422704cf8a).(Type value) { |
| 41 | Type delta = value -cxx . . $ operator-(f2f27732028766a9). m_valuecxx . . $ Damper#m_value.; |
| 42 | if (delta >cxx . . $ `operator>`(722869da467d531b). 0 && delta >cxx . . $ `operator>`(945cec9d77892c2f). m_maxDeltacxx . . $ Damper#m_maxDelta.) { |
| 43 | m_valuecxx . . $ Damper#m_value. +=cxx . . $ `operator+=`(3fe7f23f460cff33). delta -cxx . . $ operator-(c0a0514b29a23ae1). m_maxDeltacxx . . $ Damper#m_maxDelta.; |
| 44 | } else if (delta <cxx . . $ `operator<`(2e3d74ce5bf1f59d). 0 && delta <cxx . . $ `operator<`(21c6c64b4b9c56bc). -cxx . . $ operator-(901714d3a574b30f).m_maxDeltacxx . . $ Damper#m_maxDelta.) { |
| 45 | m_valuecxx . . $ Damper#m_value. +=cxx . . $ `operator+=`(393fa817bb5da60e). delta +cxx . . $ operator+(197a26b6e24af9cb). m_maxDeltacxx . . $ Damper#m_maxDelta.; |
| 46 | } |
| 47 | |
| 48 | return m_valuecxx . . $ Damper#m_value.; |
| 49 | } |
| 50 | |
| 51 | Type valuecxx . . $ Damper#value(8f5363d873dd4781).() const { return m_valuecxx . . $ Damper#m_value.; } |
| 52 | |
| 53 | private: |
| 54 | Type m_valuecxx . . $ Damper#m_value.; |
| 55 | Type m_maxDeltacxx . . $ Damper#m_maxDelta.; |
| 56 | }; |
| 57 | |
| 58 | /* |
| 59 | A point that has its movement dampened. |
| 60 | */ |
| 61 | class DampedPointFcxx . . $ DampedPointF# { |
| 62 | public: |
| 63 | void setMaxDeltacxx . . $ DampedPointF#setMaxDelta(ba8836b59fb42830).(qrealcxx . . $ qreal# maxDelta) { |
| 64 | m_x.setMaxDelta(maxDelta); |
| 65 | m_y.setMaxDelta(maxDelta); |
| 66 | } |
| 67 | |
| 68 | qrealcxx . . $ qreal# maxDeltacxx . . $ DampedPointF#maxDelta(21b6c25e127938e2).() const { return m_x.maxDelta(); } |
| 69 | |
| 70 | void resetcxx . . $ DampedPointF#reset(4258778b894f8bb6).(const QPointFcxx . . $ QPointF# &point) { |
| 71 | m_x.reset(point.x()); |
| 72 | m_y.reset(point.y()); |
| 73 | } |
| 74 | |
| 75 | void updatecxx . . $ DampedPointF#update(4258778b894f8bb6).(const QPointFcxx . . $ QPointF# &point) { |
| 76 | m_x.update(point.x()); |
| 77 | m_y.update(point.y()); |
| 78 | } |
| 79 | |
| 80 | qrealcxx . . $ qreal# xcxx . . $ DampedPointF#x(21b6c25e127938e2).() const { return m_x.value(); } |
| 81 | qrealcxx . . $ qreal# ycxx . . $ DampedPointF#y(21b6c25e127938e2).() const { return m_y.value(); } |
| 82 | private: |
| 83 | Dampercxx . . $ Damper#<qrealcxx . . $ qreal#> m_xcxx . . $ DampedPointF#m_x.; |
| 84 | Dampercxx . . $ Damper#<qrealcxx . . $ qreal#> m_ycxx . . $ DampedPointF#m_y.; |
| 85 | }; |
| 86 | |
| 87 | QDebugcxx . . $ QDebug# operatorcxx . . $ `operator<<`(1f48d9e9def2d104).<<(QDebugcxx . . $ QDebug# dbg, const DampedPointFcxx . . $ DampedPointF# &p); |
| 88 | |
| 89 | #endif // DAMPER_P_H |