重置了样例

dev-VirtualTexture
白封羽 2023-01-12 21:23:30 +08:00
parent dc89e02515
commit 3a35d74fda
7 changed files with 85 additions and 269 deletions

View File

@ -5,7 +5,7 @@ ElementManager::ElementManager(QJsonObject source)
qDebug() << elementsJson.size();
for (auto elementJson : elementsJson)
{
if (elementJson.toObject().value("type") == "group")
if (elementJson.toObject().value("type").toString() == "group")
elements.push_back(new GroupElement());
else
elements.push_back(new SimpleElement(elementJson.toObject()));

View File

@ -8,6 +8,7 @@ QPainterPath SimpleElement::getPaintObject() const
void SimpleElement::loadSvgFile(const QString& filePath)
{
// TODO
painterPath.addRect(0, 0,100,100);
}
SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource)
@ -26,8 +27,10 @@ void GroupElement::setSourceLayer(FolderLayerWrapper *sourceLayer)
}
QPainterPath GroupElement::getPaintObject() const
{
if (sourceLayer != nullptr)
if (sourceLayer != nullptr) {
sourceLayer->refresh();
return sourceLayer->getCache();
}
else
return QPainterPath();
}

View File

@ -28,7 +28,7 @@ class SimpleElement : public GraphicElement
};
class GroupElement : public GraphicElement
{
private:
public:
FolderLayerWrapper *sourceLayer;
public:

View File

@ -32,14 +32,16 @@ QPainterPath LayerWrapper::getCache()
LayerWrapper::LayerWrapper(QJsonObject json, LayerWrapper *parent)
{
this->parent = shared_ptr<LayerWrapper>(parent);
auto offsetJson = json.value("offset").toObject();
property.offset = {offsetJson.value("x").toDouble(), offsetJson.value("y").toDouble()};
auto transformJson = json.value("transform").toObject();
property.offset = { transformJson.value("offset").toObject().value("x").toDouble(), transformJson.value("offset").toObject().value("y").toDouble() };
property.scale = { transformJson.value("scale").toObject().value("x").toDouble(), transformJson.value("scale").toObject().value("y").toDouble() };
property.rotation = { transformJson.value("rotation").toDouble()};
}
FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent)
: LayerWrapper(json, parent)
{
qDebug() << json.value("name").toString();
qDebug() << json.value("name").toString()<<" "<<this;
QJsonArray childrenJson = json.value("children").toArray();
QJsonValue referencedJson = json.value("referenced-by");
if (!referencedJson.isNull())
@ -62,16 +64,21 @@ FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *element
LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent)
: LayerWrapper(json, parent)
{
qDebug() << json.value("name").toString();
qDebug() << json.value("name").toString() << " " << this;
int elementIndex = json.value("element").toInt();
wrappedElement = elementManager->getElementById(elementIndex);
}
void LayerWrapper::SimpleProperty::apply(QPainterPath &cache) const
{
QTransform trans;
trans.scale(zoom.x(), zoom.y());
double delX = cache.boundingRect().width();
double delY = cache.boundingRect().height();
trans.translate(-delX,-delY);
trans.scale(scale.x(), scale.y());
trans.rotate(rotation);
trans.translate(offset.x(), offset.y());
cache = trans.map(cache);
trans.reset();
trans.translate(delX+offset.x(), delY+offset.y());
cache = trans.map(cache);
// cache.translate(offset);
}
@ -91,8 +98,9 @@ void FolderLayerWrapper::refresh()
void LeafLayerWrapper::refresh()
{
cache.clear();
if (wrappedElement != nullptr)
if (wrappedElement != nullptr) {
cache.addPath(wrappedElement->getPaintObject());
}
LayerWrapper::refresh();
}

View File

@ -29,7 +29,7 @@ class LayerWrapper
struct SimpleProperty
{
QString name = "";
QPointF zoom = {1.0, 1.0};
QPointF scale = {1.0, 1.0};
QPointF offset = {0, 0};
double rotation = 0;
bool flipHorizontally = 0;
@ -46,7 +46,7 @@ class LayerWrapper
class FolderLayerWrapper : public LayerWrapper
{
private:
public:
vector<shared_ptr<LayerWrapper>> children;
public:
@ -60,7 +60,7 @@ class FolderLayerWrapper : public LayerWrapper
class LeafLayerWrapper : public LayerWrapper
{
private:
public:
GraphicElement *wrappedElement;
public:

View File

@ -35,7 +35,7 @@ void PreviewWindow::initializeGL()
initializeOpenGLFunctions();
glClearColor(1.0, 1.0, 1.0, 1.0);
}
#include "./third-party modules/qquick/qquicksvgparser_p.h"
void PreviewWindow::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT);

315
data.json
View File

@ -3,127 +3,14 @@
"width": 1080,
"elements": [
{
"type": "path",
"name": "ababa",
"type": "svg-file",
"data": {
"operations": [
{
"type": "line",
"data": {
"target": {
"x": 15,
"y": 20
}
}
},
{
"type": "cubic",
"data": {
"target": {
"x": 18,
"y": 21
},
"control": {
"start": {
"x": 17,
"y": 22
},
"end": {
"x": 20,
"y": 23
}
}
}
},
{
"type": "cubic-smooth",
"data": {
"target": {
"x": 18,
"y": 21
},
"control": {
"x": 18,
"y": 21
}
}
},
{
"type": "quadratic",
"data": {
"target": {
"x": 18,
"y": 21
},
"control": {
"x": 18,
"y": 21
}
}
},
{
"type": "quadratic-smooth",
"data": {
"target": {
"x": 18,
"y": 21
}
}
},
{
"type": "arc",
"data": {
"center": {
"x": 18,
"y": 21
},
"x-axis": 40,
"y-axis": 50,
"angle": 60
}
},
{
"type": "zeal"
}
]
}
},
{
"type": "polygon",
"data": {
"points": [
{
"x": 0,
"y": 0
},
{
"x": 100,
"y": 200
},
{
"x": 300,
"y": 400
},
{
"x": 500,
"y": 600
},
{
"x": 0,
"y": 0
}
]
}
},
{
"type": "round",
"data": {
"x-axis": 300,
"y-axis": 400,
"origin": 270,
"angle": 30
"include": "./svg/ababa.svg"
}
},
{
"name": "ababa-group",
"type": "group",
"data": {
"reference-layer": "0.0"
@ -132,172 +19,90 @@
],
"root-layer": {
"name": "root",
"offset": {
"x": 0,
"y": 0
"transform": {
"offset": {
"x": 0,
"y": 0
},
"scale": {
"x": 1.0,
"y": 1.0
},
"rotation": 0.0
},
"transformation": [
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"effects": [],
"is-folder": true,
"referenced-by": null,
"children": [
{
"name": "GroupFolderExample",
"offset": {
"x": 5,
"y": 10
"transform": {
"offset": {
"x": 50,
"y": 50
},
"scale": {
"x": 1.0,
"y": 1.0
},
"rotation": 0.0
},
"transformation": [
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"effects": [
{
"type": "iterate",
"data": {
"time": 5,
"operations": [
{
"type": "move",
"data": {
"offset": {
"x": 5,
"y": 6
}
}
},
{
"type": "rotate",
"data": {
"center-offset": {
"x": 0,
"y": 0
},
"angle": 60
}
},
{
"type": "zoom",
"data": {
"zoom": 1.5
}
},
{
"type": "flip",
"data": {
"k": 1.2,
"b": 3
}
}
]
}
}
],
"effects": [],
"is-folder": true,
"referenced-by": 3,
"referenced-by": 1,
"children": [
{
"name": "GroupedLayer1",
"offset": {
"x": 10,
"y": 20
"name": "Leaf1",
"transform": {
"offset": {
"x": 0,
"y": 0
},
"scale": {
"x": 1.0,
"y": 1.0
},
"rotation": 0.0
},
"transformation": [
5,
0,
0,
0,
6,
0,
0,
0,
0
],
"effects": [],
"is-folder": false,
"element": 0
},
{
"name": "GroupedLayer2",
"offset": {
"x": 15,
"y": 25
"name": "Leaf2",
"transform": {
"offset": {
"x": 150,
"y": 0
},
"scale": {
"x": 1.5,
"y": 1.5
},
"rotation": 0.0
},
"transformation": [
5,
0,
0,
0,
6,
0,
0,
0,
0
],
"effects": [],
"is-folder": false,
"element": 1
"element": 0
}
]
},
{
"name": "ReferencingGroupLayer",
"offset": {
"x": 10,
"y": 20
"transform": {
"offset": {
"x": 100,
"y": 0
},
"scale": {
"x": 1,
"y": 1
},
"rotation": 45
},
"transformation": [
5,
0,
0,
0,
6,
0,
0,
0,
0
],
"effects": [],
"is-folder": false,
"element": 3
},
{
"name": "Layer1",
"offset": {
"x": 10,
"y": 20
},
"transformation": [
5,
0,
0,
0,
6,
0,
0,
0,
0
],
"effects": [],
"is-folder": false,
"element": 2
"element": 1
}
]
}