-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpixmapoperations.cpp
121 lines (110 loc) · 3.01 KB
/
pixmapoperations.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "pixmapoperations.h"
#include <QFileInfo>
#include <QDir>
#include <QPainter>
#include "config.h"
void initPixmaps(QString path, QVector<QPixmap>& pixmaps, int& frameCounts)
{
frameCounts = 0;
QFileInfo fi(path);
frameCounts = QDir(fi.path(), fi.fileName()).entryList().size();
pixmaps.reserve(frameCounts);
foreach (QString entry, QDir(fi.path(), fi.fileName()).entryList())
{
// Get the pixmap of the path
pixmaps << QPixmap(fi.path() + "/" + entry);
}
}
void initPixmaps(int count,
const char **paths,
QVector<QVector<QPixmap> >& pixmaps,
QVector<int>& frameCounts)
{
pixmaps.clear();
pixmaps.reserve(count);
frameCounts.clear();
frameCounts.reserve(count);
for (int i = 0;i < count;++i)
{
QVector<QPixmap> current;
QString path(paths[i]);
QFileInfo fi(path);
int count = QDir(fi.path(), fi.fileName()).entryList().size();
current.reserve(count);
// For each file of the color
foreach (QString entry, QDir(fi.path(), fi.fileName()).entryList())
{
// Get the pixmap of the path
current << QPixmap(fi.path() + "/" + entry);
}
pixmaps << current;
frameCounts << count;
}
}
void initPixmaps(QVector<QString> paths,
QVector<QVector<QPixmap> >& pixmaps,
QVector<int>& frameCounts)
{
int count = paths.size();
pixmaps.clear();
pixmaps.reserve(count);
frameCounts.clear();
frameCounts.reserve(count);
for (int i = 0;i < count;++i)
{
QVector<QPixmap> current;
QString path(paths[i]);
QFileInfo fi(path);
int count = QDir(fi.path(), fi.fileName()).entryList().size();
current.reserve(count);
// For each file of the color
foreach (QString entry, QDir(fi.path(), fi.fileName()).entryList())
{
// Get the pixmap of the path
current << QPixmap(fi.path() + "/" + entry);
}
pixmaps << current;
frameCounts << count;
}
}
void drawPixmapAt(QPainter *painter,
const QPixmap& pixmap,
double xRate,
double yRate,
QPointF pos,
bool resize,
bool center)
{
// Calculate the width and height the pixmap should be
double width = pixmap.width();
double height = pixmap.height();
if (width < 1 || height < 1)
return;
if (xRate >= 0.999 &&
xRate <= 1.001 &&
yRate >= 0.999 &&
yRate <= 1.001)
resize = false;
if (resize)
{
width *= xRate;
height *= yRate;
}
// Calculate the left up position of the pixmap
QPointF leftUp = pos;
if (center)
{
leftUp.setX(leftUp.x() - width / 2);
leftUp.setY(leftUp.y() - height / 2);
}
#ifdef USE_TRANSLATE_AND_SCALE
painter->translate(leftUp.x(), leftUp.y());
painter->scale(xRate, yRate);
// Draw the pixmap
painter->drawPixmap(0, 0, pixmap);
painter->scale(1.0 / xRate, 1.0 / yRate);
painter->translate(-leftUp.x(), -leftUp.y());
#else
painter->drawPixmap(leftUp.x(), leftUp.y(), width, height, pixmap);
#endif
}