Remote-canvas work, based on Extra-500 testing.
This commit is contained in:
parent
490592d96e
commit
569925b61b
8 changed files with 79 additions and 58 deletions
|
@ -27,7 +27,7 @@ QTransform qTransformFromCanvas(LocalProp* prop)
|
|||
bool FGCanvasElement::isStyleProperty(QByteArray name)
|
||||
{
|
||||
if ((name == "font") || (name == "line-height") || (name == "alignment")
|
||||
|| (name == "character-size") || (name == "fill"))
|
||||
|| (name == "character-size") || (name == "fill") || (name == "background"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -61,10 +61,30 @@ void FGCanvasElement::paint(FGCanvasPaintContext *context) const
|
|||
return;
|
||||
}
|
||||
|
||||
// qDebug() << "painting" << _svgElementId << "at" << _propertyRoot->path();
|
||||
QPainter* p = context->painter();
|
||||
|
||||
context->painter()->save();
|
||||
context->painter()->setTransform(combinedTransform(), true /* combine */);
|
||||
if (_clipDirty) {
|
||||
// re-calculate clip
|
||||
QVariant clipSpec = _propertyRoot->value("clip", QVariant());
|
||||
if (clipSpec.isNull()) {
|
||||
_hasClip = false;
|
||||
} else {
|
||||
// https://www.w3.org/wiki/CSS/Properties/clip for the stupid order here
|
||||
QStringList clipRectDesc = clipSpec.toString().split(',');
|
||||
int top = clipRectDesc.at(0).toInt();
|
||||
int right = clipRectDesc.at(1).toInt();
|
||||
int bottom = clipRectDesc.at(2).toInt();
|
||||
int left = clipRectDesc.at(3).toInt();
|
||||
|
||||
_clipRect = QRectF(left, top, right - left, bottom - top);
|
||||
_hasClip = true;
|
||||
}
|
||||
|
||||
_clipDirty = false;
|
||||
}
|
||||
|
||||
p->save();
|
||||
p->setTransform(combinedTransform(), true /* combine */);
|
||||
|
||||
if (_styleDirty) {
|
||||
_fillColor = parseColorValue(getCascadedStyle("fill"));
|
||||
|
@ -72,14 +92,29 @@ void FGCanvasElement::paint(FGCanvasPaintContext *context) const
|
|||
}
|
||||
|
||||
if (!_fillColor.isValid()) {
|
||||
context->painter()->setBrush(Qt::NoBrush);
|
||||
p->setBrush(Qt::NoBrush);
|
||||
} else {
|
||||
context->painter()->setBrush(_fillColor);
|
||||
p->setBrush(_fillColor);
|
||||
}
|
||||
|
||||
if (_hasClip) {
|
||||
p->save();
|
||||
p->setPen(Qt::yellow);
|
||||
p->setBrush(QBrush(Qt::yellow, Qt::DiagCrossPattern));
|
||||
p->drawRect(_clipRect);
|
||||
p->restore();
|
||||
|
||||
// context->painter()->setClipRect(_clipRect);
|
||||
// context->painter()->setClipping(true);
|
||||
}
|
||||
|
||||
doPaint(context);
|
||||
|
||||
context->painter()->restore();
|
||||
if (_hasClip) {
|
||||
p->setClipping(false);
|
||||
}
|
||||
|
||||
p->restore();
|
||||
}
|
||||
|
||||
void FGCanvasElement::doPaint(FGCanvasPaintContext* context) const
|
||||
|
@ -132,10 +167,10 @@ bool FGCanvasElement::onChildAdded(LocalProp *prop)
|
|||
} else if (nm == "visible") {
|
||||
return true;
|
||||
} else if (nm == "tf-rot-index") {
|
||||
connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::markTransformsDirty);
|
||||
// ignored, this is noise from the Nasal SVG parswer
|
||||
return true;
|
||||
} else if (nm.startsWith("center-offset-")) {
|
||||
connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::markTransformsDirty);
|
||||
// ignored, this is noise from the Nasal SVG parswer
|
||||
return true;
|
||||
} else if (nm == "center") {
|
||||
connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::onCenterChanged);
|
||||
|
@ -156,6 +191,9 @@ bool FGCanvasElement::onChildAdded(LocalProp *prop)
|
|||
} else if (prop->name() == "update") {
|
||||
// disable updates optionally?
|
||||
return true;
|
||||
} else if (nm == "clip") {
|
||||
connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::markClipDirty);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isStyleProperty(nm)) {
|
||||
|
@ -208,6 +246,11 @@ void FGCanvasElement::markTransformsDirty()
|
|||
_transformsDirty = true;
|
||||
}
|
||||
|
||||
void FGCanvasElement::markClipDirty()
|
||||
{
|
||||
_clipDirty = true;
|
||||
}
|
||||
|
||||
QColor FGCanvasElement::parseColorValue(QVariant value) const
|
||||
{
|
||||
QString colorString = value.toString();
|
||||
|
|
|
@ -57,6 +57,8 @@ private:
|
|||
|
||||
void onVisibleChanged(QVariant value);
|
||||
|
||||
void markClipDirty();
|
||||
|
||||
private:
|
||||
friend class FGCanvasGroup;
|
||||
|
||||
|
@ -71,6 +73,10 @@ private:
|
|||
mutable QColor _fillColor;
|
||||
int _zIndex = 0;
|
||||
QByteArray _svgElementId;
|
||||
|
||||
mutable bool _clipDirty = true;
|
||||
mutable bool _hasClip = false;
|
||||
mutable QRectF _clipRect;
|
||||
};
|
||||
|
||||
using FGCanvasElementVec = std::vector<FGCanvasElement*>;
|
||||
|
|
|
@ -53,26 +53,6 @@ unsigned int FGCanvasGroup::indexOfChild(const FGCanvasElement *e) const
|
|||
|
||||
void FGCanvasGroup::doPaint(FGCanvasPaintContext *context) const
|
||||
{
|
||||
if (_clipDirty) {
|
||||
// re-calculate clip
|
||||
QVariant clipSpec = _propertyRoot->value("clip", QVariant());
|
||||
if (clipSpec.isNull()) {
|
||||
_hasClip = false;
|
||||
} else {
|
||||
// https://www.w3.org/wiki/CSS/Properties/clip for the stupid order here
|
||||
QStringList clipRectDesc = clipSpec.toString().split(',');
|
||||
int top = clipRectDesc.at(0).toInt();
|
||||
int right = clipRectDesc.at(1).toInt();
|
||||
int bottom = clipRectDesc.at(2).toInt();
|
||||
int left = clipRectDesc.at(3).toInt();
|
||||
|
||||
_clipRect = QRectF(left, top, right - left, bottom - top);
|
||||
_hasClip = true;
|
||||
}
|
||||
|
||||
_clipDirty = false;
|
||||
}
|
||||
|
||||
if (_zIndicesDirty) {
|
||||
std::sort(_children.begin(), _children.end(), [](const FGCanvasElement* a, FGCanvasElement* b)
|
||||
{ return a->zIndex() < b->zIndex(); });
|
||||
|
@ -84,24 +64,9 @@ void FGCanvasGroup::doPaint(FGCanvasPaintContext *context) const
|
|||
_cachedSymbolDirty = false;
|
||||
}
|
||||
|
||||
if (_hasClip) {
|
||||
context->painter()->save();
|
||||
context->painter()->setPen(Qt::yellow);
|
||||
context->painter()->setBrush(QBrush(Qt::yellow, Qt::DiagCrossPattern));
|
||||
context->painter()->drawRect(_clipRect);
|
||||
context->painter()->restore();
|
||||
|
||||
// context->painter()->setClipRect(_clipRect);
|
||||
// context->painter()->setClipping(true);
|
||||
}
|
||||
|
||||
for (FGCanvasElement* element : _children) {
|
||||
element->paint(context);
|
||||
}
|
||||
|
||||
if (_hasClip) {
|
||||
context->painter()->setClipping(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool FGCanvasGroup::onChildAdded(LocalProp *prop)
|
||||
|
@ -134,9 +99,6 @@ bool FGCanvasGroup::onChildAdded(LocalProp *prop)
|
|||
_children.push_back(new FGQCanvasMap(this, prop));
|
||||
newChildCount++;
|
||||
return true;
|
||||
} else if (nm == "clip") {
|
||||
connect(prop, &LocalProp::valueChanged, this, &FGCanvasGroup::markClipDirty);
|
||||
return true;
|
||||
} else if (nm == "symbol-type") {
|
||||
connect(prop, &LocalProp::valueChanged, this, &FGCanvasGroup::markCachedSymbolDirty);
|
||||
return true;
|
||||
|
@ -199,11 +161,6 @@ void FGCanvasGroup::markStyleDirty()
|
|||
}
|
||||
}
|
||||
|
||||
void FGCanvasGroup::markClipDirty()
|
||||
{
|
||||
_clipDirty = true;
|
||||
}
|
||||
|
||||
void FGCanvasGroup::markCachedSymbolDirty()
|
||||
{
|
||||
_cachedSymbolDirty = true;
|
||||
|
|
|
@ -33,15 +33,11 @@ protected:
|
|||
|
||||
virtual void markStyleDirty() override;
|
||||
private:
|
||||
void markClipDirty();
|
||||
void markCachedSymbolDirty();
|
||||
int indexOfChildWithProp(LocalProp *prop) const;
|
||||
|
||||
private:
|
||||
mutable FGCanvasElementVec _children;
|
||||
mutable bool _clipDirty = true;
|
||||
mutable bool _hasClip = false;
|
||||
mutable QRectF _clipRect;
|
||||
mutable bool _zIndicesDirty = false;
|
||||
mutable bool _cachedSymbolDirty = false;
|
||||
};
|
||||
|
|
|
@ -344,7 +344,7 @@ bool FGCanvasPath::rebuildFromRect(std::vector<int>& commands, std::vector<float
|
|||
LocalProp* rectProp = _propertyRoot->getWithPath("rect");
|
||||
if (hasComplexBorderRadius(_propertyRoot)) {
|
||||
// build a full path
|
||||
qWarning() << "implement me";
|
||||
qWarning() << Q_FUNC_INFO << "implement me";
|
||||
_paintType = Path;
|
||||
} else {
|
||||
float top = rectProp->value("top", 0.0).toFloat();
|
||||
|
@ -622,6 +622,8 @@ static Qt::PenCapStyle qtCapFromCanvas(QString s)
|
|||
return Qt::FlatCap;
|
||||
} else if (s == "round") {
|
||||
return Qt::RoundCap;
|
||||
} else if (s == "square") {
|
||||
return Qt::SquareCap;
|
||||
} else {
|
||||
qDebug() << Q_FUNC_INFO << s;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ void FGCanvasText::doPaint(FGCanvasPaintContext *context) const
|
|||
|
||||
context->painter()->setFont(_font);
|
||||
context->painter()->setPen(fillColor());
|
||||
|
||||
context->painter()->setBrush(Qt::NoBrush);
|
||||
QRectF rect(0, 0, 1000, 1000);
|
||||
|
||||
if (_alignment & Qt::AlignBottom) {
|
||||
|
|
|
@ -28,12 +28,26 @@ bool FGQCanvasImage::onChildAdded(LocalProp *prop)
|
|||
return true;
|
||||
}
|
||||
|
||||
const QByteArray nm = prop->name();
|
||||
if ((nm == "source") || (nm == "src") || (nm == "size") || (nm == "file")) {
|
||||
connect(prop, &LocalProp::valueChanged, this, &FGQCanvasImage::markImageDirty);
|
||||
return true;
|
||||
}
|
||||
|
||||
qDebug() << "image saw child:" << prop->name();
|
||||
return false;
|
||||
}
|
||||
|
||||
void FGQCanvasImage::markImageDirty()
|
||||
{
|
||||
_imageDirty = true;
|
||||
}
|
||||
|
||||
void FGQCanvasImage::rebuildImage() const
|
||||
{
|
||||
qDebug() << "source" << _propertyRoot->value("source", QString());
|
||||
qDebug() << "src" << _propertyRoot->value("src", QString());
|
||||
qDebug() << "file" << _propertyRoot->value("file", QString());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -19,10 +19,13 @@ private:
|
|||
bool onChildAdded(LocalProp *prop) override;
|
||||
|
||||
void rebuildImage() const;
|
||||
|
||||
void markImageDirty();
|
||||
private:
|
||||
mutable bool _imageDirty;
|
||||
mutable QPixmap _image;
|
||||
QString _source;
|
||||
mutable QSizeF _destSize;
|
||||
};
|
||||
|
||||
#endif // FGQCANVASIMAGE_H
|
||||
|
|
Loading…
Add table
Reference in a new issue