-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimation.cpp
More file actions
51 lines (45 loc) · 1.23 KB
/
Copy pathanimation.cpp
File metadata and controls
51 lines (45 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "animation.h"
#include <QDebug>
#include <QRect>
#include <QPixmap>
#include <QBitmap>
#include <QImage>
#include <QColor>
#include <QPainter>
#include <QtGlobal>
Animation::Animation(int fps, bool repeat) {
this->fps = fps;
this->repeat = repeat;
}
Animation::Animation(const QString &res, const QSize &size) {
addFrame(res, size);
this->fps = 1;
this->repeat = false;
}
void Animation::addFrame(const QString &res, const QSize &size = QSize()) {
QPixmap pixmap = QPixmap();
pixmap.load(res);
if (size.isValid())
pixmap = pixmap.scaled(size.width(), size.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
append(pixmap);
}
Animation Animation::crop(int width, int height) {
Animation ret(*this);
for (int i = 0; i < ret.length(); i++) {
ret[i] = ret[i].copy(QRect(0, 0, width, height));
}
return ret;
}
Animation Animation::setColor(QColor color) {
Animation ret(*this);
for (int i = 0; i < ret.length(); i++) {
QPixmap pix = QPixmap(ret[i]);
QBitmap mask = pix.createHeuristicMask();
QPainter p(&pix);
p.setPen(color);
p.drawPixmap(pix.rect(), mask, mask.rect());
p.end();
ret[i] = pix;
}
return ret;
}