Compare commits

...

3 Commits

Author SHA1 Message Date
ArgonarioD 7da434541a [stroke] 实现了行删除 2023-03-15 11:21:23 +08:00
ArgonarioD 6a742f6526 Merge branch 'main' into dev-LayerStyle 2023-03-14 23:41:49 +08:00
wuyize 4ec58dbb8b FIX: 多样式不生效 2023-03-14 23:39:56 +08:00
4 changed files with 51 additions and 9 deletions

View File

@ -893,7 +893,7 @@ bool angleLargeThanPi(vec2 a, vec2 b)
/************************************************************************************/
void drawLine(in float d, inout uint styleIndex, out vec4 elementColor, out vec2 metallicRoughness)
void drawLine(in float d, uint styleIndex, out vec4 elementColor, out vec2 metallicRoughness)
{
elementColor = vec4(1);
metallicRoughness = vec2(0.8);
@ -969,6 +969,30 @@ void drawLine(in float d, inout uint styleIndex, out vec4 elementColor, out vec2
}
}
void nextStyleIndex(inout uint styleIndex)
{
uint headUint = floatBitsToUint(style[styleIndex + 1]);
vec4 head = unpackUnorm4x8(headUint);
switch (int(head.a * 100) % 10)
{
/// Plain
case 0: {
styleIndex += 3;
break;
}
/// RadialGradient
case 1: {
uint size = headUint % (1 << 15);
styleIndex += 2 + size * 2;
break;
}
case 2: {
break;
}
}
}
bool shouldFillBeginCap(vec2 localUV, bool onVeryBegin, int endType, vec2 p0, vec2 tangentBegin, vec2 tangentEndLast)
{
vec2 normal;
@ -1015,9 +1039,8 @@ void main()
vec4 color = vec4(0);
// if(isinf(path[0].x)) imageStore(gBaseColor, ivec2(pixelLocation),
// vec4(vec2(pixelLocation)/vec2(imageSize(gBaseColor)), 1,1)); return;
for (uint styleIndex = 0; styleIndex < styleSize; styleIndex++)
for (uint styleIndex = 0; styleIndex < styleSize;)
{
styleIndex += 6;
vec2 localUV = vec2(pixelLocation) / pixelRatio + leftTop;
@ -1056,6 +1079,7 @@ void main()
elementColor = vec4(unpackUnorm4x8(floatBitsToUint(style[++styleIndex])).rgb, 1);
}
}
}
else // Stroke
{
@ -1129,8 +1153,8 @@ void main()
// if (onBegin ? shouldFillBeginCap(localUV, onVeryBegin, endType, p[0], tangentBegin,
// tangentEndLast)
// : (onEnd ? /*shouldFillEndCap(localUV, onVeryEnd, endType, p[3], tangentEnd,
// tangentBeginNext)*/ false
// : (onEnd ? shouldFillEndCap(localUV, onVeryEnd, endType, p[3], tangentEnd,
// tangentBeginNext)
// : d < minDistance))
bool hit = d < minDistance;
if (onBegin)
@ -1183,10 +1207,11 @@ void main()
{
// hitElement = shouldFillEndCap(localUV, true, endType, p3Last, tangentEndLast);
}
nextStyleIndex(styleIndex);
}
if (hitElement)
color = elementColor;
styleIndex += 100;
}
if (color.a != 0)
imageStore(gBaseColor, ivec2(pixelLocation), color);

View File

@ -1,24 +1,28 @@
#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(4);
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("´Ö²Ú¶È"));
headers.append(QStringLiteral("其他操作"));
this->setHorizontalHeaderLabels(headers);
for (int row = 0; auto& strokePair : stroke->materialMap)
{
@ -45,6 +49,14 @@ StrokeStyleListView::StrokeStyleListView(
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);
@ -54,8 +66,9 @@ StrokeStyleListView::StrokeStyleListView(
void StrokeStyleListView::onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous)
{
if (!current) return;
int column = current->column();
if (column != COLUMN_COLOR)
if (column != COLUMN_COLOR && column != COLUMN_OPERATIONS)
{
this->currentItemValue = current->text();
}

View File

@ -78,6 +78,7 @@ std::vector<GLfloat> generateStyleBuffer(const std::vector<BaseStyle>& styles)
auto encoded = style.material->encoded();
styleBuffer.insert(styleBuffer.end(), encoded.begin(), encoded.end());
qDebug() << "style size" << styleBuffer.size();
}
return styleBuffer;
}

View File

@ -10,6 +10,8 @@ using namespace Renderer;
namespace UnitTest
{
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg);
TEST_CLASS(ElementRendererStokeTypeTest)
{
private:
@ -20,6 +22,7 @@ namespace UnitTest
TEST_METHOD_INITIALIZE(initialize)
{
qInstallMessageHandler(messageHandler);
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);