测试LayerStyle inputWidget的数据绑定

dev-LayerStyle
ArgonarioD 2023-03-12 15:39:19 +08:00
parent acd25b4964
commit 744ae58743
7 changed files with 85 additions and 22 deletions

View File

@ -145,7 +145,6 @@
<ClCompile Include="src\Renderer\Painting\MaterialStyleStroke.cpp" />
<ClCompile Include="src\Renderer\Painting\Painting.cpp" />
<ClCompile Include="src\Renderer\PaintingMesh.cpp" />
<ClCompile Include="src\Renderer\Preview\ElementRenderer.cpp" />
<ClCompile Include="src\Renderer\RendererGLWidget.cpp" />
<ClCompile Include="src\Renderer\RendererWidget.cpp" />
<ClCompile Include="src\Renderer\Painting\ShortCutTree.cpp" />

View File

@ -59,9 +59,6 @@
<Filter Include="Source Files\Editor\util">
<UniqueIdentifier>{96f98afe-4250-44cb-a505-682a1d5932c3}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Renderer\Preview">
<UniqueIdentifier>{2a8e109f-7791-46ad-8c86-fe22a651cbe7}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Renderer\Preview">
<UniqueIdentifier>{7ead1a66-586a-4584-ae80-9e7a4e667364}</UniqueIdentifier>
</Filter>
@ -186,9 +183,6 @@
<ClCompile Include="src\Editor\util\PainterPathUtil.cpp">
<Filter>Source Files\Editor\util</Filter>
</ClCompile>
<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>

View File

@ -45,8 +45,20 @@ 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);
//Renderer::ElementStyleStrokeDemo demo(2);
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();
}
auto [img, mov] = renderer->drawElement(painterPath, *style, 1.0);
//qDebug() << img << " ------";
result.addImage(img, mov);
//result.addPath(painterPath);

View File

@ -4,6 +4,7 @@
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QObject>
const std::vector<std::pair<QString, std::function<std::unique_ptr<LayerStyle>()>>> LayerStyle::types = {
{
@ -18,7 +19,13 @@ 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;
for (auto materialStyle : materialStyles)
{
baseStyles.push_back(Renderer::BaseStyle(std::make_shared<Renderer::TransformStyle>(),
materialStyle));
}
return baseStyles;
}
QString StrokeElementLayerStyle::getStyleName() const
@ -26,12 +33,59 @@ 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->materialStyles.empty())
{
/*auto materialMap = std::map<float, Renderer::Material>();
materialMap[1.0] = Renderer::Material{ QColor(0,255,255), 1.0f, 1.0f };
this->materialStyles.push_back(std::shared_ptr<Renderer::MaterialStyleStroke>(new Renderer::MaterialStyleStroke(
0,
Renderer::StrokeType::kBothSides, Renderer::StrokeEndType::kFlat,
std::shared_ptr<Renderer::MaterialStroke>(new Renderer::StrokeRadialGradient(
materialMap, false
))
)));*/
this->materialStyles.push_back(std::make_shared<Renderer::MaterialStyleStroke>(
0,
Renderer::StrokeType::kBothSides, Renderer::StrokeEndType::kFlat,
std::make_shared<Renderer::StrokePlain>(QColor::fromRgb(50, 50, 50), 0, 0.8)
));
}
QWidget* w = new QWidget;
QVBoxLayout* layout = new QVBoxLayout(w);
layout->setMargin(0);
QLineEdit* r = new QLineEdit(w), * g = new QLineEdit(w), * b = new QLineEdit(w);
layout->addWidget(r);
layout->addWidget(g);
layout->addWidget(b);
//auto stroke = std::dynamic_pointer_cast<Renderer::StrokeRadialGradient>(this->materialStyles[0]->materialStroke);
//QColor* color = &(stroke->materialMap[1.0].color);
auto stroke = std::dynamic_pointer_cast<Renderer::StrokePlain>(this->materialStyles[0]->materialStroke);
QColor* color = &(stroke->material.color);
r->setText(QString::number(color->red()));
g->setText(QString::number(color->green()));
b->setText(QString::number(color->blue()));
QObject::connect(r, &QLineEdit::textChanged, [color](QString content) {
if (!content.isEmpty())
{
color->setRed(content.toInt());
}
});
QObject::connect(g, &QLineEdit::textChanged, [color](QString content) {
if (!content.isEmpty())
{
color->setGreen(content.toInt());
}
});
QObject::connect(b, &QLineEdit::textChanged, [color](QString content) {
if (!content.isEmpty())
{
color->setBlue(content.toInt());
}
});
return w;
}
QWidget* StrokeElementLayerStyle::getListDisplayWidget() const
@ -50,7 +104,9 @@ StrokeElementLayerStyle::StrokeElementLayerStyle(const StrokeElementLayerStyle&
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]);
materialStyles[i] = std::dynamic_pointer_cast<Renderer::MaterialStyleStroke>(
std::shared_ptr<Renderer::MaterialStyle>(std::move(other.materialStyles[i]->clone()))
);
}
}
@ -69,7 +125,7 @@ QString FillElementLayerStyle::getStyleName() const
return QStringLiteral("Ìî³ä");
}
QWidget* FillElementLayerStyle::getInputWidget() const
QWidget* FillElementLayerStyle::getInputWidget()
{
// TODO
QLineEdit* name = new QLineEdit;

View File

@ -16,23 +16,23 @@
* 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;
};
class StrokeElementLayerStyle : public Renderer::ElementStyle, public LayerStyle
class StrokeElementLayerStyle : 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;
StrokeElementLayerStyle() = default;
StrokeElementLayerStyle(const StrokeElementLayerStyle& other);
@ -41,12 +41,12 @@ public:
std::unique_ptr<LayerStyle> clonePtr() const override;
};
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);

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());
}