| 10035 | } |
| 10036 | |
| 10037 | void AddImage(QString file) |
| 10038 | { |
| 10039 | QFileInfo fi(file); |
| 10040 | if (fi.isDir()) |
| 10041 | { |
| 10042 | QDir dir(file); |
| 10043 | QStringList subdirs = dir.entryList(QDir::Dirs | QDir::Files | |
| 10044 | QDir::Readable | |
| 10045 | QDir::NoDotAndDotDot); |
| 10046 | foreach (QString d, subdirs) |
| 10047 | AddImage(dir.cleanPath(dir.absoluteFilePath(d))); |
| 10048 | } |
| 10049 | else |
| 10050 | { |
| 10051 | QImage image(file); |
| 10052 | if (image.isNull()) |
| 10053 | { |
| 10054 | QString qualified = "texture:" + file; |
| 10055 | image.load(qualified); |
| 10056 | } |
| 10057 | if (!image.isNull()) |
| 10058 | { |
| 10059 | uint w = image.width(); |
| 10060 | uint h = image.height(); |
| 10061 | |
| 10062 | if (w > maxWidth) |
| 10063 | { |
| 10064 | image = image.scaledToWidth(maxWidth, |
| 10065 | Qt::SmoothTransformation); |
| 10066 | w = image.width(); |
| 10067 | h = image.height(); |
| 10068 | } |
| 10069 | if (h > maxHeight) |
| 10070 | { |
| 10071 | image = image.scaledToHeight(maxHeight, |
| 10072 | Qt::SmoothTransformation); |
| 10073 | w = image.width(); |
| 10074 | h = image.height(); |
| 10075 | } |
| 10076 | |
| 10077 | BinPacker::Rect rect; |
| 10078 | if (bp.Allocate(w + padWidth, h + padHeight, rect)) |
| 10079 | { |
| 10080 | QPainter painter(&composite); |
| 10081 | painter.setBrush(Qt::transparent); |
| 10082 | painter.setPen(Qt::white); |
| 10083 | painter.drawImage(rect.x1, rect.y1, image); |
| 10084 | painter.end(); |
| 10085 | } |
| 10086 | else |
| 10087 | { |
| 10088 | IFTRACE(picturepack) |
| 10089 | std::cerr << "No room for image " << +file |
| 10090 | << "(" << w << "x" << h << " pixels)\n"; |
| 10091 | } |
| 10092 | } |
| 10093 | else |
| 10094 | { |