2
* Copyright (c) 2007,2010 Cyrille Berger <cberger@cberger.net>
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; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "kis_paint_information.h"
20
#include <QDomElement>
22
struct KisPaintInformation::Private {
23
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
32
double tangentialPressure;
36
KisPaintInformation::KisPaintInformation(const QPointF & pos_, double pressure_,
37
double xTilt_, double yTilt_,
38
const KisVector2D& movement_,
40
double tangentialPressure_,
45
d->pressure = pressure_;
48
d->movement = movement_;
49
d->rotation = rotation_;
50
d->tangentialPressure = tangentialPressure_;
51
d->angle = atan2(movement_.y(), movement_.x());
55
KisPaintInformation::KisPaintInformation(const KisPaintInformation& rhs) : d(new Private(*rhs.d))
59
void KisPaintInformation::operator=(const KisPaintInformation & rhs)
64
KisPaintInformation::~KisPaintInformation()
70
void KisPaintInformation::toXML(QDomDocument&, QDomElement& e) const
72
e.setAttribute("pointX", QString::number(pos().x(), 'g', 15));
73
e.setAttribute("pointY", QString::number(pos().y(), 'g', 15));
74
e.setAttribute("pressure", QString::number(pressure(), 'g', 15));
75
e.setAttribute("xTilt", QString::number(xTilt(), 'g', 15));
76
e.setAttribute("yTilt", QString::number(yTilt(), 'g', 15));
77
e.setAttribute("movementX", QString::number(movement().x(), 'g', 15));
78
e.setAttribute("movementY", QString::number(movement().y(), 'g', 15));
79
e.setAttribute("rotation", QString::number(rotation(), 'g', 15));
80
e.setAttribute("tangentialPressure", QString::number(tangentialPressure(), 'g', 15));
81
e.setAttribute("time", d->time);
84
KisPaintInformation KisPaintInformation::fromXML(const QDomElement& e)
86
double pointX = e.attribute("pointX", "0.0").toDouble();
87
double pointY = e.attribute("pointY", "0.0").toDouble();
88
double pressure = e.attribute("pressure", "0.0").toDouble();
89
double rotation = e.attribute("rotation", "0.0").toDouble();
90
double tangentialPressure = e.attribute("tangentialPressure", "0.0").toDouble();
91
double xTilt = e.attribute("xTilt", "0.0").toDouble();
92
double yTilt = e.attribute("yTilt", "0.0").toDouble();
93
double movementX = e.attribute("movementX", "0.0").toDouble();
94
double movementY = e.attribute("movementY", "0.0").toDouble();
95
int time = e.attribute("time", "0").toInt();
97
return KisPaintInformation(QPointF(pointX, pointY), pressure, xTilt, yTilt, KisVector2D(movementX, movementY),
98
rotation, tangentialPressure, time);
101
const QPointF& KisPaintInformation::pos() const
106
void KisPaintInformation::setPos(const QPointF& p)
111
double KisPaintInformation::pressure() const
116
void KisPaintInformation::setPressure(double p)
121
double KisPaintInformation::xTilt() const
126
double KisPaintInformation::yTilt() const
131
KisVector2D KisPaintInformation::movement() const
136
double KisPaintInformation::angle() const
141
double KisPaintInformation::rotation() const
146
double KisPaintInformation::tangentialPressure() const
148
return d->tangentialPressure;
151
int KisPaintInformation::currentTime() const
156
QDebug operator<<(QDebug dbg, const KisPaintInformation &info)
161
dbg.nospace() << "Position: " << info.pos();
162
dbg.nospace() << ", Pressure: " << info.pressure();
163
dbg.nospace() << ", X Tilt: " << info.xTilt();
164
dbg.nospace() << ", Y Tilt: " << info.yTilt();
165
dbg.nospace() << ", Movement: " << toQPointF(info.movement());
166
dbg.nospace() << ", Rotation: " << info.rotation();
167
dbg.nospace() << ", Tangential Pressure: " << info.tangentialPressure();
168
dbg.nospace() << ", Angle: " << info.angle();
169
dbg.nospace() << ", Time: " << info.currentTime();
174
KisPaintInformation KisPaintInformation::mix(const QPointF& p, double t, const KisPaintInformation& pi1, const KisPaintInformation& pi2, const KisVector2D& movement)
176
double pressure = (1 - t) * pi1.pressure() + t * pi2.pressure();
177
double xTilt = (1 - t) * pi1.xTilt() + t * pi2.xTilt();
178
double yTilt = (1 - t) * pi1.yTilt() + t * pi2.yTilt();
179
double rotation = (1 - t) * pi1.rotation() + t * pi2.rotation();
180
double tangentialPressure = (1 - t) * pi1.tangentialPressure() + t * pi2.tangentialPressure();
181
int time = (1 - t) * pi1.currentTime() + t * pi2.currentTime();
182
return KisPaintInformation(p, pressure, xTilt, yTilt, movement, rotation, tangentialPressure, time);