From 3b87644e21f40f0a90cf998d4e6e1e7acfbe9e2d Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Wed, 15 Mar 2023 16:16:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86PixelPath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/EditorWidgetItem.cpp | 2 +- .../src/Editor/GraphicElement.cpp | 15 +++++++-- .../src/Editor/GraphicElement.h | 2 +- .../src/Editor/LayerWrapper.cpp | 3 ++ .../src/Editor/PixelPath.cpp | 2 ++ .../src/Editor/PixelPath.h | 2 +- .../src/Editor/util/PaintingUtil.cpp | 14 +++++++-- .../src/Renderer/Model.cpp | 2 +- svg/4_L0.svg | 5 +++ svg/ex.json | 31 +++++++++++++++++++ 10 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 svg/4_L0.svg create mode 100644 svg/ex.json diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index 0a3f01b..ab1f096 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -41,7 +41,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p layerManager = new LayerManager(source, elementManager); elementInfoDisplayWidget->setElementManager(elementManager); treeWidget->elementManager = elementManager; - qDebug() << layerManager->toJson(); + //qDebug() << layerManager->toJson(); previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toDouble(),jsonDoc.object().value("height").toDouble())); diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index 2775fe5..6be59ff 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -1,11 +1,14 @@ #include "GraphicElement.h" #include "util/SvgFileLoader.h" +#include +#include using namespace std; PixelPath SimpleElement::getPaintObject() const { PixelPath result; result.addPath(painterPath); + qDebug() << result.getPainterPath(); return result; } @@ -48,7 +51,7 @@ PixelPath SimpleElement::getPaintObject(std::vector> std::shared_ptr style; if ((*styles).empty()) { - style = std::make_shared(2); + return this->getPaintObject(); } else { @@ -63,6 +66,7 @@ PixelPath SimpleElement::getPaintObject(std::vector> auto [img, mov] = renderer->drawElement(painterPath, *style, 1.0); //qDebug() << img << " ------"; result.addImage(img, mov); + result.addPath(painterPath); //result.addPath(painterPath); // QImage img(80,80,QImage::Format_ARGB32); // QPainter pt(&img); @@ -124,8 +128,15 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const vector< std::dynamic_pointer_cast(style)->materialStyles[0]->materialStroke )->materialMap[1.0].color;*/ } - auto [img, mov] = renderer->drawElement(painterPath, *style, 1.0); + QVector2D scale(transform.m11(), transform.m22()); + scale /= transform.m33(); + double maxScale = std::max(scale.x(), scale.y()); + double pixelRatio = maxScale * QGuiApplication::primaryScreen()->devicePixelRatio(); + auto [img, mov] = renderer->drawElement(painterPath, *style, pixelRatio); + painter->setTransform(transform.scale(1 / pixelRatio, 1 / pixelRatio)); + //img = img.scaled(img.width() / pixelRatio, img.height() / pixelRatio, Qt::KeepAspectRatio, Qt::SmoothTransformation); painter->drawImage(mov, img); + } painter->restore(); diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.h b/ArchitectureColoredPainting/src/Editor/GraphicElement.h index ce54ad7..6e63e92 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.h +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.h @@ -33,7 +33,7 @@ public: class SimpleElement : public GraphicElement { -private: +public: QJsonObject jsonSource; // TODO: ¸ÄΪComposedPainterPath QPainterPath painterPath; diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index d5f28e7..8b07e72 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -26,6 +26,7 @@ FolderLayerWrapper*LayerWrapper::getParent() const PixelPath LayerWrapper::getCache(LayerWrapper* selectedLayer) { this->refresh(selectedLayer); + qDebug() << cache.painterPath; if (selectedLayer == this) { this->cache.highLight(); @@ -130,7 +131,9 @@ void LeafLayerWrapper::refresh(LayerWrapper* layer) cache.clear(); if (wrappedElement != nullptr) { + qDebug() << cache.painterPath; cache.addPath(wrappedElement->getPaintObject(&(this->styles))); + qDebug() << cache.painterPath; } LayerWrapper::refresh(); } diff --git a/ArchitectureColoredPainting/src/Editor/PixelPath.cpp b/ArchitectureColoredPainting/src/Editor/PixelPath.cpp index 89f4bbc..c770411 100644 --- a/ArchitectureColoredPainting/src/Editor/PixelPath.cpp +++ b/ArchitectureColoredPainting/src/Editor/PixelPath.cpp @@ -66,6 +66,7 @@ void PixelPath::clear() { pixmap.fill(Qt::transparent); boundingRect = QRectF(0, 0, 0, 0); + painterPath.clear(); } PixelPath PixelPath::trans(QTransform& mat)const @@ -76,6 +77,7 @@ PixelPath PixelPath::trans(QTransform& mat)const painter.setRenderHint(QPainter::HighQualityAntialiasing); painter.setTransform(mat); painter.drawPixmap(0, 0, pixmap); + result.addPath(this->painterPath); result.boundingRect = mat.mapRect(boundingRect); return result; } diff --git a/ArchitectureColoredPainting/src/Editor/PixelPath.h b/ArchitectureColoredPainting/src/Editor/PixelPath.h index a764ce8..ced76ff 100644 --- a/ArchitectureColoredPainting/src/Editor/PixelPath.h +++ b/ArchitectureColoredPainting/src/Editor/PixelPath.h @@ -7,7 +7,7 @@ class PixelPath { -private: +public: QRectF boundingRect; QPixmap pixmap; QPainterPath painterPath; diff --git a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp index 07e0224..b863fcd 100644 --- a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp +++ b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp @@ -27,8 +27,15 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) { QTransform transform; glm::bvec2 flip(0, 0); QJsonObject jsonObj = readJsonFile(jsonFilePath); + qDebug() << jsonObj; ElementManager *elementManager = new ElementManager(jsonObj, Renderer::ElementRenderer::instance()); LayerManager* layerManager = new LayerManager(jsonObj, elementManager); + //qDebug() << elementManager->toJson(); + //qDebug() << layerManager->toJson(); + qDebug() << ((SimpleElement*)((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->wrappedElement)->painterPath; + qDebug() << ((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->getCache().painterPath; + + traverseLayTree(layerManager->getRoot(), transform, flip, painting); return painting; } @@ -43,6 +50,7 @@ void PaintingUtil::traverseLayTree(LayerWrapper* nowLayer, QTransform transform, transform = nowLayer->property.transform * transform; if (leafLayer != nullptr) { + qDebug() << leafLayer<<"------" << painterPath; Element element; ElementTransform elementTrans; element.ratio = bound.width() / bound.height(); @@ -52,10 +60,10 @@ void PaintingUtil::traverseLayTree(LayerWrapper* nowLayer, QTransform transform, trans.scale(1 / bound.width(), 1 / bound.height()); trans.translate(-bound.center().x(), -bound.center().y()); - element.contour.reset(new vector >(PainterPathUtil::transformToLines(trans.map(painterPath)))); + element.contour = std::make_shared >>(PainterPathUtil::transformToLines(trans.map(painterPath))); QSize screenSize = pixelPath.getPixmap().size(); - //element.style.reset(new Renderer::ElementStyleStrokeDemo(0.06)); - + element.style = std::make_shared(0.06); + painterPath = transform.map(painterPath); bound = painterPath.boundingRect(); diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp index 7496155..917ecc9 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp @@ -229,7 +229,7 @@ GLuint Renderer::Model::loadPainting(std::string path) if (iter != paintingLoaded.end()) return iter->second; - Painting painting = PaintingUtil::transfromToPainting("D:\\BigC\\Project\\ArchitectureColoredPainting\\data.json"); + Painting painting = PaintingUtil::transfromToPainting("../data.json"); painting.generateBuffers(glFunc); diff --git a/svg/4_L0.svg b/svg/4_L0.svg new file mode 100644 index 0000000..58facaf --- /dev/null +++ b/svg/4_L0.svg @@ -0,0 +1,5 @@ + + 4_L0 + + + diff --git a/svg/ex.json b/svg/ex.json new file mode 100644 index 0000000..9b3f948 --- /dev/null +++ b/svg/ex.json @@ -0,0 +1,31 @@ +{ + "height": 1080, + "width": 1080, + "elements": [ + { + "name": "ababa", + "type": "svg-file", + "data": { + "include": "./svg/0.svg" + } + } + ], + "root-layer": { + "name": "root", + "transform": { + "offset": { + "x": 0, + "y": 0 + }, + "scale": { + "x": 1.0, + "y": 1.0 + }, + "rotation": 0.0 + }, + "effects": [], + "is-folder": true, + "referenced-by": null, + "children":[] + } +} \ No newline at end of file