初步实现了编辑器中的StrokeStyle

[style/stroke] 实现了行删除
[style/stroke] 基本稳定了strokeStyle的修改
[paint] 令drawElement时会应用style
[style] 修改了LayerStyle
[editor] 新增了ColorPicker类和StrokeStyleListView类
dev-LayerStyle
ArgonarioD 2023-03-15 11:43:16 +08:00
parent 73e63f3817
commit 073f68e360
13 changed files with 380 additions and 69 deletions

View File

@ -104,6 +104,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\Editor\EditorWidgetComponent\ColorPicker.cpp" />
<ClCompile Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.cpp" />
<ClCompile Include="src\Editor\EditorWidgetComponent\LayerStyleDialog.cpp" />
<ClCompile Include="src\Editor\EditorWidget.cpp" />
@ -152,6 +153,7 @@
<ClCompile Include="src\Renderer\Painting\StraightLine.cpp" />
<ClCompile Include="src\Renderer\VirtualTextureManager.cpp" />
<ClCompile Include="src\SvgParser.cpp" />
<ClCompile Include="src\Editor\EditorWidgetComponent\StrokeStyleListView.cpp" />
<QtUic Include="EditorWidget.ui" />
<QtUic Include="EditorWidgetItem.ui" />
<QtUic Include="MainWindow.ui" />
@ -187,12 +189,14 @@
<None Include="res\Shaders\ssgi.comp" />
</ItemGroup>
<ItemGroup>
<QtMoc Include="src\Editor\EditorWidgetComponent\StrokeStyleListView.h" />
<QtMoc Include="src\Editor\RightBar\LayerTreeWidget.h" />
<QtMoc Include="src\Editor\RightBar\InfoDisplayWidget.h" />
<QtMoc Include="src\MainWindow.h" />
<QtMoc Include="src\Editor\EditorWidget.h" />
<QtMoc Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.h" />
<QtMoc Include="src\Editor\EditorWidgetComponent\LayerStyleDialog.h" />
<QtMoc Include="src\Editor\EditorWidgetComponent\ColorPicker.h" />
<ClInclude Include="src\Editor\ElementManager.h" />
<QtMoc Include="src\Editor\ElementPoolWidget.h" />
<ClInclude Include="src\Editor\GraphicElement.h" />

View File

@ -65,6 +65,12 @@
<Filter Include="Header Files\Renderer\Preview">
<UniqueIdentifier>{7ead1a66-586a-4584-ae80-9e7a4e667364}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Editor\Style">
<UniqueIdentifier>{be3f4585-c8ba-410f-8619-2adcd4349f02}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Editor\Style">
<UniqueIdentifier>{b9732a33-aa2e-4f8d-886f-1b1730c66519}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<QtUic Include="MainWindow.ui">
@ -111,9 +117,6 @@
<ClCompile Include="src\Renderer\RendererWidget.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="src\NavigationBarWidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Painting\BvhTree.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
@ -156,12 +159,6 @@
<ClCompile Include="src\Renderer\Painting\CubicBezierSignedDistance.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
<ClCompile Include="src\Editor\RightBar\LayerTreeWidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Editor\RightBar\InfoDisplayWidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Painting\ElementStyle.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
@ -189,9 +186,6 @@
<ClCompile Include="src\Renderer\Preview\ElementRenderer.cpp">
<Filter>Source Files\Renderer\Preview</Filter>
</ClCompile>
<ClCompile Include="src\Editor\LayerStyle.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\IblUtils.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
@ -216,11 +210,29 @@
<ClCompile Include="src\Editor\util\PaintingUtil.cpp">
<Filter>Source Files\Editor\util</Filter>
</ClCompile>
<ClCompile Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.cpp">
<Filter>Source Files</Filter>
<ClCompile Include="src\Editor\LayerStyle.cpp">
<Filter>Source Files\Editor\Style</Filter>
</ClCompile>
<ClCompile Include="src\Editor\EditorWidgetComponent\LayerStyleDialog.cpp">
<Filter>Source Files</Filter>
<Filter>Source Files\Editor\Style</Filter>
</ClCompile>
<ClCompile Include="src\Editor\EditorWidgetComponent\StrokeStyleListView.cpp">
<Filter>Source Files\Editor\Style</Filter>
</ClCompile>
<ClCompile Include="src\Editor\RightBar\InfoDisplayWidget.cpp">
<Filter>Source Files\Editor</Filter>
</ClCompile>
<ClCompile Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.cpp">
<Filter>Source Files\Editor</Filter>
</ClCompile>
<ClCompile Include="src\Editor\RightBar\LayerTreeWidget.cpp">
<Filter>Source Files\Editor</Filter>
</ClCompile>
<ClCompile Include="src\NavigationBarWidget.cpp">
<Filter>Source Files\Editor</Filter>
</ClCompile>
<ClCompile Include="src\Editor\EditorWidgetComponent\ColorPicker.cpp">
<Filter>Source Files\Editor</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
@ -233,35 +245,41 @@
<QtMoc Include="src\Renderer\RendererWidget.h">
<Filter>Header Files\Renderer</Filter>
</QtMoc>
<QtMoc Include="src\NavigationBarWidget.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="src\MainWindow.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="src\Editor\PreviewWindow.h">
<Filter>Header Files\Editor</Filter>
</QtMoc>
<QtMoc Include="src\Editor\RightBar\LayerTreeWidget.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="src\Editor\RightBar\InfoDisplayWidget.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="src\Editor\EditorWidget.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="src\Editor\ElementPoolWidget.h">
<Filter>Header Files\Editor</Filter>
</QtMoc>
<QtMoc Include="src\FluentMenu.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.h">
<Filter>Header Files</Filter>
<QtMoc Include="src\Editor\EditorWidgetComponent\StrokeStyleListView.h">
<Filter>Header Files\Editor\Style</Filter>
</QtMoc>
<QtMoc Include="src\Editor\EditorWidgetComponent\LayerStyleDialog.h">
<Filter>Header Files</Filter>
<Filter>Header Files\Editor\Style</Filter>
</QtMoc>
<QtMoc Include="src\Editor\RightBar\InfoDisplayWidget.h">
<Filter>Header Files\Editor</Filter>
</QtMoc>
<QtMoc Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.h">
<Filter>Header Files\Editor</Filter>
</QtMoc>
<QtMoc Include="src\Editor\EditorWidget.h">
<Filter>Header Files\Editor</Filter>
</QtMoc>
<QtMoc Include="src\Editor\RightBar\LayerTreeWidget.h">
<Filter>Header Files\Editor</Filter>
</QtMoc>
<QtMoc Include="src\MainWindow.h">
<Filter>Header Files\Editor</Filter>
</QtMoc>
<QtMoc Include="src\NavigationBarWidget.h">
<Filter>Header Files\Editor</Filter>
</QtMoc>
<QtMoc Include="src\Editor\EditorWidgetComponent\ColorPicker.h">
<Filter>Header Files\Editor</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
@ -457,7 +475,7 @@
<Filter>Header Files\Editor\util</Filter>
</ClInclude>
<ClInclude Include="src\Editor\LayerStyle.h">
<Filter>Header Files\Editor</Filter>
<Filter>Header Files\Editor\Style</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,38 @@
#include "ColorPicker.h"
#include <QColorDialog>
QString getStyleSheet(const QColor& color)
{
return
"QPushButton#colorPicker {"
" border-style: solid;"
" border-width: 1px;"
" border-color: black;"
" background-color: " + color.name() + ";"
"}";
}
ColorPicker::ColorPicker(const QColor& color, QWidget* parent) : QPushButton(parent), color(color)
{
this->setObjectName("colorPicker");
this->setStyleSheet(getStyleSheet(color));
connect(this, &QPushButton::clicked, this, &ColorPicker::onClicked);
}
QColor ColorPicker::getColor() const
{
return color;
}
void ColorPicker::onClicked()
{
QColorDialog dialog(this->color, this);
dialog.exec();
QColor newColor = dialog.selectedColor();
if (newColor.isValid() && this->color != newColor)
{
this->color = newColor;
this->setStyleSheet(getStyleSheet(newColor));
emit colorChanged(newColor);
}
}

View File

@ -0,0 +1,16 @@
#pragma once
#include <QPushButton>
class ColorPicker : public QPushButton
{
Q_OBJECT
private:
QColor color;
public:
ColorPicker(const QColor& color, QWidget* parent = nullptr);
QColor getColor() const;
public slots:
void onClicked();
signals:
void colorChanged(QColor newColor);
};

View File

@ -18,7 +18,7 @@ LayerStyleDialog::LayerStyleDialog(
if (existedStyle)
{
this->modifyingStyle = existedStyle->clonePtr();
this->modifyingStyle = existedStyle->clone();
this->styleContainer = nullptr;
this->styleWidget = modifyingStyle->getInputWidget();

View File

@ -0,0 +1,108 @@
#include "StrokeStyleListView.h"
#include "ColorPicker.h"
#include <qtmaterialraisedbutton.h>
constexpr int COLUMN_WIDTH = 0;
constexpr int COLUMN_COLOR = 1;
constexpr int COLUMN_METALLIC = 2;
constexpr int COLUMN_ROUGHNESS = 3;
constexpr int COLUMN_OPERATIONS = 4;
// TODO: 将这个类改为继承QWidget把table转为其中的一个元素加上新增行按钮和宽度设置
StrokeStyleListView::StrokeStyleListView(
std::shared_ptr<Renderer::StrokeRadialGradient> stroke,
QWidget* parent
) : QTableWidget(parent), stroke(stroke)
{
this->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow);
this->setColumnCount(5);
this->setRowCount(stroke->materialMap.size());
QStringList headers;
headers.append(QStringLiteral("离心距离占比"));
headers.append(QStringLiteral("颜色"));
headers.append(QStringLiteral("金属度"));
headers.append(QStringLiteral("粗糙度"));
headers.append(QStringLiteral("其他操作"));
this->setHorizontalHeaderLabels(headers);
for (int row = 0; auto& strokePair : stroke->materialMap)
{
QTableWidgetItem* widthItem = new QTableWidgetItem;
widthItem->setData(Qt::EditRole, strokePair.first);
this->setItem(row, COLUMN_WIDTH, widthItem);
QColor* colorPtr = &(strokePair.second.color);
QTableWidgetItem* colorItem = new QTableWidgetItem;
colorItem->setData(Qt::DisplayRole, *colorPtr);
this->setItem(row, COLUMN_COLOR, colorItem);
ColorPicker* colorPicker = new ColorPicker(*colorPtr, this);
this->setCellWidget(row, COLUMN_COLOR, colorPicker);
connect(colorPicker, &ColorPicker::colorChanged, [this, colorPtr](QColor color) {
*colorPtr = color;
this->update();
});
QTableWidgetItem* metallicItem = new QTableWidgetItem;
metallicItem->setData(Qt::EditRole, strokePair.second.metallic);
this->setItem(row, COLUMN_METALLIC, metallicItem);
QTableWidgetItem* roughnessItem = new QTableWidgetItem;
roughnessItem->setData(Qt::EditRole, strokePair.second.roughness);
this->setItem(row, COLUMN_ROUGHNESS, roughnessItem);
QtMaterialRaisedButton* removeButton = new QtMaterialRaisedButton("-", this);
removeButton->setFixedSize(20, 20);
this->setCellWidget(row, COLUMN_OPERATIONS, removeButton);
connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row]() {
this->stroke->materialMap.erase(this->item(row, COLUMN_WIDTH)->text().toFloat());
this->removeRow(row);
});
row++;
}
connect(this, &StrokeStyleListView::currentItemChanged, this, &StrokeStyleListView::onCurrentItemChanged);
connect(this, &StrokeStyleListView::cellChanged, this, &StrokeStyleListView::onCellChanged);
this->adjustSize();
}
void StrokeStyleListView::onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous)
{
if (!current) return;
int column = current->column();
if (column != COLUMN_COLOR && column != COLUMN_OPERATIONS)
{
this->currentItemValue = current->text();
}
}
void StrokeStyleListView::onCellChanged(int row, int column)
{
auto changedItem = this->item(row, column);
auto changedItemValue = changedItem->text().toFloat();
if (changedItemValue < 0 || 1 < changedItemValue)
{
changedItem->setData(Qt::EditRole, this->currentItemValue.toFloat());
return;
}
auto changedWidth = this->item(row, COLUMN_WIDTH)->text().toFloat();
switch (row)
{
case COLUMN_WIDTH:
{
float oldWidth = this->currentItemValue.toFloat();
auto node = stroke->materialMap.extract(oldWidth);
node.key() = changedWidth;
stroke->materialMap.insert(std::move(node));
break;
}
case COLUMN_METALLIC:
{
stroke->materialMap[changedWidth].metallic = changedItemValue;
break;
}
case COLUMN_ROUGHNESS:
{
stroke->materialMap[changedWidth].roughness = changedItemValue;
break;
}
}
}

View File

@ -0,0 +1,21 @@
#pragma once
#include "LayerStyle.h"
#include "../Renderer/Painting/MaterialStyleStroke.h"
#include <QListView>
#include <QListWidget>
#include <QTableWidget>
class StrokeStyleListView : public QTableWidget
{
Q_OBJECT
private:
QString currentItemValue;
public:
StrokeStyleListView(std::shared_ptr<Renderer::StrokeRadialGradient> stroke, QWidget* parent = nullptr);
std::shared_ptr<Renderer::StrokeRadialGradient> stroke;
protected slots:
void onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous);
void onCellChanged(int row, int column);
};

View File

@ -45,9 +45,22 @@ PixelPath GroupElement::getPaintObject() const
//TODO: apply styles and send back
PixelPath SimpleElement::getPaintObject(std::vector<std::shared_ptr<LayerStyle>>* styles) const {
PixelPath result;
Renderer::ElementStyleStrokeDemo demo(2);
auto [img, mov] = renderer->drawElement(painterPath, demo, 1.0);
//qDebug() << mov;
std::shared_ptr<Renderer::ElementStyle> style;
if ((*styles).empty())
{
style = std::make_shared<Renderer::ElementStyleStrokeDemo>(2);
}
else
{
style = (*styles)[0];
/*qDebug() << std::dynamic_pointer_cast<Renderer::StrokePlain>(
std::dynamic_pointer_cast<StrokeElementLayerStyle>(style)->materialStyles[0]->materialStroke
)->material.color.name();*/
/*qDebug() << std::dynamic_pointer_cast<Renderer::StrokeRadialGradient>(
std::dynamic_pointer_cast<StrokeElementLayerStyle>(style)->materialStyles[0]->materialStroke
)->materialMap[1.0].color;*/
}
auto [img, mov] = renderer->drawElement(painterPath, *style, 1.0);
//qDebug() << img << " ------";
result.addImage(img, mov);
//result.addPath(painterPath);
@ -85,7 +98,7 @@ QJsonObject GraphicElement::toJson() const
return result;
}
void SimpleElement::paint(QPainter* painter, QTransform transform, vector<std::shared_ptr<LayerStyle>> styles)
void SimpleElement::paint(QPainter* painter, QTransform transform, const vector<std::shared_ptr<LayerStyle>> &styles)
{
painter->save();
painter->setTransform(transform);
@ -95,16 +108,30 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, vector<std::s
}
else
{
// TODO:Ó¦ÓÃstyle
Renderer::ElementStyleStrokeDemo demo(2);
auto [img, mov] = renderer->drawElement(painterPath, demo, 1.0);
std::shared_ptr<Renderer::ElementStyle> style;
if (styles.empty())
{
style = std::make_shared<Renderer::ElementStyleStrokeDemo>(2);
}
else
{
style = styles[0];
/*qDebug() << std::dynamic_pointer_cast<Renderer::StrokePlain>(
std::dynamic_pointer_cast<StrokeElementLayerStyle>(style)->materialStyles[0]->materialStroke
)->material.color.name();*/
/*qDebug() << std::dynamic_pointer_cast<Renderer::StrokeRadialGradient>(
std::dynamic_pointer_cast<StrokeElementLayerStyle>(style)->materialStyles[0]->materialStroke
)->materialMap[1.0].color;*/
}
auto [img, mov] = renderer->drawElement(painterPath, *style, 1.0);
painter->drawImage(mov, img);
}
painter->restore();
}
void GroupElement::paint(QPainter* painter, QTransform transform, vector<std::shared_ptr<LayerStyle>> styles)
void GroupElement::paint(QPainter* painter, QTransform transform, const vector<std::shared_ptr<LayerStyle>> &styles)
{
sourceLayer->paint(painter, transform);
}

View File

@ -28,7 +28,7 @@ public:
virtual QJsonObject toJson() const;
virtual PixelPath getPaintObject() const = 0;
virtual PixelPath getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*) const = 0;
virtual void paint(QPainter* painter, QTransform transform, std::vector<std::shared_ptr<LayerStyle>> styles) = 0;
virtual void paint(QPainter* painter, QTransform transform, const std::vector<std::shared_ptr<LayerStyle>> &styles) = 0;
};
class SimpleElement : public GraphicElement
@ -45,7 +45,7 @@ public:
~SimpleElement() = default;
PixelPath getPaintObject() const override;
PixelPath getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*) const override;
void paint(QPainter* painter, QTransform transform, std::vector<std::shared_ptr<LayerStyle>> styles) override;
void paint(QPainter* painter, QTransform transform, const std::vector<std::shared_ptr<LayerStyle>> &styles) override;
};
class GroupElement : public GraphicElement
@ -60,7 +60,7 @@ public:
PixelPath getPaintObject() const override;
PixelPath getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*) const override;
void setSourceLayer(FolderLayerWrapper* sourceLayer);
void paint(QPainter* painter, QTransform transform, std::vector<std::shared_ptr<LayerStyle>> styles) override;
void paint(QPainter* painter, QTransform transform, const std::vector<std::shared_ptr<LayerStyle>> &styles) override;
};
//******************************** BitmapPath ********************************//

View File

@ -1,9 +1,13 @@
#include "LayerStyle.h"
#include "./EditorWidgetComponent/StrokeStyleListView.h"
#include <qtmaterialcheckbox.h>
#include <QHBoxLayout>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QObject>
#include <QDebug>
const std::vector<std::pair<QString, std::function<std::unique_ptr<LayerStyle>()>>> LayerStyle::types = {
{
@ -18,7 +22,22 @@ const std::vector<std::pair<QString, std::function<std::unique_ptr<LayerStyle>()
std::vector<Renderer::BaseStyle> StrokeElementLayerStyle::toBaseStyles() const
{
return std::vector<Renderer::BaseStyle>();
std::vector<Renderer::BaseStyle> baseStyles;
if (enableEachSideIndependent)
{
baseStyles.push_back(Renderer::BaseStyle(std::make_shared<Renderer::TransformStyle>(),
strokePair.first));
baseStyles.push_back(Renderer::BaseStyle(std::make_shared<Renderer::TransformStyle>(),
strokePair.second));
}
else
{
auto material = std::shared_ptr<MaterialStyle>(std::move(strokePair.first->clone()));
std::dynamic_pointer_cast<MaterialStyleStroke>(material)->strokeType = Renderer::StrokeType::kBothSides;
baseStyles.push_back(Renderer::BaseStyle(std::make_shared<Renderer::TransformStyle>(), material));
}
return baseStyles;
}
QString StrokeElementLayerStyle::getStyleName() const
@ -26,12 +45,61 @@ QString StrokeElementLayerStyle::getStyleName() const
return QStringLiteral("Ãè±ß");
}
QWidget* StrokeElementLayerStyle::getInputWidget() const
QWidget* StrokeElementLayerStyle::getInputWidget()
{
// TODO
QLabel* le = new QLabel;
le->setText(QStringLiteral("Ãè±ß"));
return le;
if (this->strokePair.first == nullptr)
{
auto materialMap = std::map<float, Renderer::Material>();
materialMap[0.3] = Renderer::Material{ QColor(0,255,255), 0.f, .8f };
materialMap[1.0] = Renderer::Material{ QColor(80,25,255), 0.f, .8f };
this->strokePair.first = std::shared_ptr<Renderer::MaterialStyleStroke>(new Renderer::MaterialStyleStroke(
15,
Renderer::StrokeType::kLeftSide, Renderer::StrokeEndType::kFlat,
std::shared_ptr<Renderer::MaterialStroke>(new Renderer::StrokeRadialGradient(
materialMap, false
))
));
}
if (this->strokePair.second == nullptr)
{
auto materialMap = std::map<float, Renderer::Material>();
materialMap[0.3] = Renderer::Material{ QColor(0,255,255), 0.f, .8f };
materialMap[1.0] = Renderer::Material{ QColor(80,25,255), 0.f, .8f };
this->strokePair.second = std::shared_ptr<Renderer::MaterialStyleStroke>(new Renderer::MaterialStyleStroke(
15,
Renderer::StrokeType::kRightSide, Renderer::StrokeEndType::kFlat,
std::shared_ptr<Renderer::MaterialStroke>(new Renderer::StrokeRadialGradient(
materialMap, false
))
));
}
QWidget* w = new QWidget;
QListView* materialList = new QListView;
QVBoxLayout* layout = new QVBoxLayout(w);
layout->setMargin(0);
StrokeStyleListView* leftStrokeView = new StrokeStyleListView(
std::dynamic_pointer_cast<Renderer::StrokeRadialGradient>(this->strokePair.first->materialStroke), w
);
layout->addWidget(leftStrokeView);
QtMaterialCheckBox* checkEachSideIndependent = new QtMaterialCheckBox(w);
checkEachSideIndependent->setText(QStringLiteral("ÆôÓÃÁ½²à¶ÀÁ¢Ãè±ß"));
checkEachSideIndependent->setChecked(enableEachSideIndependent);
layout->addWidget(checkEachSideIndependent);
StrokeStyleListView* rightStrokeView = new StrokeStyleListView(
std::dynamic_pointer_cast<Renderer::StrokeRadialGradient>(this->strokePair.second->materialStroke), w
);
layout->addWidget(rightStrokeView);
rightStrokeView->setDisabled(!this->enableEachSideIndependent);
QObject::connect(checkEachSideIndependent, &QtMaterialCheckBox::toggled, [this, rightStrokeView](bool toggled) {
this->enableEachSideIndependent = toggled;
rightStrokeView->setDisabled(!toggled);
});
return w;
}
QWidget* StrokeElementLayerStyle::getListDisplayWidget() const
@ -47,14 +115,16 @@ QWidget* StrokeElementLayerStyle::getListDisplayWidget() const
StrokeElementLayerStyle::StrokeElementLayerStyle(const StrokeElementLayerStyle& other)
{
materialStyles = std::vector<std::shared_ptr<Renderer::MaterialStyleStroke>>(other.materialStyles.size());
for (size_t i = 0; i < other.materialStyles.size(); i++)
{
materialStyles[i] = std::make_shared<Renderer::MaterialStyleStroke>(*other.materialStyles[i]);
}
strokePair.first = std::dynamic_pointer_cast<MaterialStyleStroke>(
std::shared_ptr<Renderer::MaterialStyle>(std::move(other.strokePair.first->clone()))
);
strokePair.second = std::dynamic_pointer_cast<MaterialStyleStroke>(
std::shared_ptr<Renderer::MaterialStyle>(std::move(other.strokePair.second->clone()))
);
enableEachSideIndependent = other.enableEachSideIndependent;
}
std::unique_ptr<LayerStyle> StrokeElementLayerStyle::clonePtr() const
std::unique_ptr<LayerStyle> StrokeElementLayerStyle::clone() const
{
return std::make_unique<StrokeElementLayerStyle>(StrokeElementLayerStyle(*this));
}
@ -69,7 +139,7 @@ QString FillElementLayerStyle::getStyleName() const
return QStringLiteral("Ìî³ä");
}
QWidget* FillElementLayerStyle::getInputWidget() const
QWidget* FillElementLayerStyle::getInputWidget()
{
// TODO
QLineEdit* name = new QLineEdit;
@ -97,7 +167,7 @@ FillElementLayerStyle::FillElementLayerStyle(const FillElementLayerStyle& other)
}
}
std::unique_ptr<LayerStyle> FillElementLayerStyle::clonePtr() const
std::unique_ptr<LayerStyle> FillElementLayerStyle::clone() const
{
return std::make_unique<FillElementLayerStyle>(FillElementLayerStyle(*this));
}

View File

@ -9,6 +9,9 @@
#include "../Renderer/Painting/MaterialStyleStroke.h"
#include "../Renderer/Painting/MaterialStyleFill.h"
using Renderer::MaterialStyle;
using Renderer::MaterialStyleStroke;
/**
* StylegetInputWidget()
* StylegetInputWidget()
@ -16,41 +19,45 @@
* LayerStyleElementStylestyle
*
*/
class LayerStyle
class LayerStyle : public Renderer::ElementStyle
{
public:
const static std::vector<std::pair<QString, std::function<std::unique_ptr<LayerStyle>()>>> types;
virtual QString getStyleName() const = 0;
virtual QWidget* getInputWidget() const = 0;
virtual QWidget* getInputWidget() = 0;
virtual QWidget* getListDisplayWidget() const = 0;
virtual ~LayerStyle() {};
virtual std::unique_ptr<LayerStyle> clonePtr() const = 0;
virtual std::unique_ptr<LayerStyle> clone() const = 0;
};
class StrokeElementLayerStyle : public Renderer::ElementStyle, public LayerStyle
class StrokeElementLayerStyle : public LayerStyle
{
private:
std::pair<std::shared_ptr<MaterialStyleStroke>, std::shared_ptr<MaterialStyleStroke>> strokePair;
public:
std::vector<Renderer::BaseStyle> toBaseStyles() const override;
QString getStyleName() const override;
QWidget* getInputWidget() const override;
QWidget* getInputWidget() override;
QWidget* getListDisplayWidget() const override;
StrokeElementLayerStyle() = default;
StrokeElementLayerStyle(const StrokeElementLayerStyle& other);
~StrokeElementLayerStyle() = default;
std::vector<std::shared_ptr<Renderer::MaterialStyleStroke>> materialStyles;
std::unique_ptr<LayerStyle> clonePtr() const override;
std::unique_ptr<LayerStyle> clone() const override;
bool enableEachSideIndependent = false;
};
class FillElementLayerStyle : public Renderer::ElementStyle, public LayerStyle
class FillElementLayerStyle : public LayerStyle
{
public:
std::vector<Renderer::BaseStyle> toBaseStyles() const override;
QString getStyleName() const override;
QWidget* getInputWidget() const override;
QWidget* getInputWidget() override;
QWidget* getListDisplayWidget() const override;
FillElementLayerStyle() = default;
FillElementLayerStyle(const FillElementLayerStyle& other);
~FillElementLayerStyle() = default;
std::vector<std::shared_ptr<Renderer::MaterialStyleFill>> materialStyles;
std::unique_ptr<LayerStyle> clonePtr() const override;
std::unique_ptr<LayerStyle> clone() const override;
};

View File

@ -25,6 +25,7 @@ std::unique_ptr<MaterialStroke> Renderer::StrokePlain::clone() const
std::vector<GLfloat> Renderer::StrokePlain::encoded() const
{
qDebug() << material.color;
return { glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(material.toVec().second, 0.f, 0.f))),
glm::uintBitsToFloat(glm::packUnorm4x8(material.toVec().first)) };
}

View File

@ -75,6 +75,7 @@ std::vector<GLfloat> generateStyleBuffer(const std::vector<BaseStyle>& styles)
styleBuffer.push_back(style.transform->scale.y);
styleBuffer.push_back(style.transform->rotation);
styleBuffer.push_back(glm::uintBitsToFloat(glm::packUnorm2x16(style.transform->flip)));
auto encoded = style.material->encoded();
styleBuffer.insert(styleBuffer.end(), encoded.begin(), encoded.end());
qDebug() << "style size" << styleBuffer.size();