Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
tilesetprovider.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Twilight
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15*/
16
22
23#include <QImage>
24
25#include "./tilesetprovider.h"
26#include "./tilesetengine.h"
27
29 : QQuickImageProvider(QQuickImageProvider::Pixmap)
30{}
31
32
33QPixmap TilesetProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize)
34{
35 // Check to make sure it's a properly formed request
36 auto idParts = id.split("/", Qt::SkipEmptyParts);
37
38 // Has to have all 7 parts unconditionally
39 if(idParts.size() < 7)
40 return blankImage(size, requestedSize);
41
42 // Whole tileset or a specific tile
43 // Never whole tileset unless it's for debug purposes
44 bool wholeTileset = idParts.at(4) == "whole";
45
46 int widthSize = idParts.at(5).toInt();
47 int heightSize = idParts.at(6).toInt();
48
49 // Actual size
50 QSize actualSize = QSize(widthSize, heightSize);
51
52 // Set actual size if asked
53 if(size != nullptr)
54 *size = actualSize;
55
56 // Prepare return
57 QPixmap ret;
58
59 // Get full tileset if "whole" otherwise requested tile
60 if(wholeTileset)
62 else
63 ret = TilesetEngine::buildTileset(id).at(idParts.at(4).toInt());
64
65 // Scale if asked to
66 ret = ret.scaled((requestedSize.width() > 0) ? requestedSize.width() : actualSize.width(),
67 (requestedSize.height() > 0) ? requestedSize.height() : actualSize.height());
68
69 // Return said tile or tileset
70 return ret;
71}
72
73QPixmap TilesetProvider::blankImage(QSize* size, const QSize& requestedSize)
74{
75 // Create an error "red" blank tile to indicate issue
76 QSize actualSize = QSize(TilesetEngine::width, TilesetEngine::height);
77
78 if(size != nullptr)
79 *size = actualSize;
80
81 auto img = QImage(TilesetEngine::width, TilesetEngine::height, QImage::Format::Format_ARGB32);
82 img.fill(QColor(255, 0, 0, 255)); // Fill with error "red" color
83
84 auto ret = QPixmap::fromImage(img);
85
86 ret = ret.scaled((requestedSize.width() > 0) ? requestedSize.width() : actualSize.width(),
87 (requestedSize.height() > 0) ? requestedSize.height() : actualSize.height());
88
89 return ret;
90}
static constexpr int width
Tileset image width (px).
static constexpr int height
Tileset image height (px).
static QVector< QPixmap > buildTileset(QString id)
Build the per-tile pixmaps for id (format above).
static QPixmap buildTilesetFullDebug(QString id)
QPixmap blankImage(QSize *size, const QSize &requestedSize)
Fallback blank tile.
virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override
Render the tile for id (format documented above).