1
0
Fork 0

Remote-canvas work, based on Extra-500 testing.

This commit is contained in:
James Turner 2016-12-18 23:52:16 +00:00
parent 490592d96e
commit 569925b61b
8 changed files with 79 additions and 58 deletions

View file

@ -27,7 +27,7 @@ QTransform qTransformFromCanvas(LocalProp* prop)
bool FGCanvasElement::isStyleProperty(QByteArray name) bool FGCanvasElement::isStyleProperty(QByteArray name)
{ {
if ((name == "font") || (name == "line-height") || (name == "alignment") if ((name == "font") || (name == "line-height") || (name == "alignment")
|| (name == "character-size") || (name == "fill")) || (name == "character-size") || (name == "fill") || (name == "background"))
{ {
return true; return true;
} }
@ -61,10 +61,30 @@ void FGCanvasElement::paint(FGCanvasPaintContext *context) const
return; return;
} }
// qDebug() << "painting" << _svgElementId << "at" << _propertyRoot->path(); QPainter* p = context->painter();
context->painter()->save(); if (_clipDirty) {
context->painter()->setTransform(combinedTransform(), true /* combine */); // 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) { if (_styleDirty) {
_fillColor = parseColorValue(getCascadedStyle("fill")); _fillColor = parseColorValue(getCascadedStyle("fill"));
@ -72,14 +92,29 @@ void FGCanvasElement::paint(FGCanvasPaintContext *context) const
} }
if (!_fillColor.isValid()) { if (!_fillColor.isValid()) {
context->painter()->setBrush(Qt::NoBrush); p->setBrush(Qt::NoBrush);
} else { } 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); doPaint(context);
context->painter()->restore(); if (_hasClip) {
p->setClipping(false);
}
p->restore();
} }
void FGCanvasElement::doPaint(FGCanvasPaintContext* context) const void FGCanvasElement::doPaint(FGCanvasPaintContext* context) const
@ -132,10 +167,10 @@ bool FGCanvasElement::onChildAdded(LocalProp *prop)
} else if (nm == "visible") { } else if (nm == "visible") {
return true; return true;
} else if (nm == "tf-rot-index") { } else if (nm == "tf-rot-index") {
connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::markTransformsDirty); // ignored, this is noise from the Nasal SVG parswer
return true; return true;
} else if (nm.startsWith("center-offset-")) { } else if (nm.startsWith("center-offset-")) {
connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::markTransformsDirty); // ignored, this is noise from the Nasal SVG parswer
return true; return true;
} else if (nm == "center") { } else if (nm == "center") {
connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::onCenterChanged); connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::onCenterChanged);
@ -156,6 +191,9 @@ bool FGCanvasElement::onChildAdded(LocalProp *prop)
} else if (prop->name() == "update") { } else if (prop->name() == "update") {
// disable updates optionally? // disable updates optionally?
return true; return true;
} else if (nm == "clip") {
connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::markClipDirty);
return true;
} }
if (isStyleProperty(nm)) { if (isStyleProperty(nm)) {
@ -208,6 +246,11 @@ void FGCanvasElement::markTransformsDirty()
_transformsDirty = true; _transformsDirty = true;
} }
void FGCanvasElement::markClipDirty()
{
_clipDirty = true;
}
QColor FGCanvasElement::parseColorValue(QVariant value) const QColor FGCanvasElement::parseColorValue(QVariant value) const
{ {
QString colorString = value.toString(); QString colorString = value.toString();

View file

@ -57,6 +57,8 @@ private:
void onVisibleChanged(QVariant value); void onVisibleChanged(QVariant value);
void markClipDirty();
private: private:
friend class FGCanvasGroup; friend class FGCanvasGroup;
@ -71,6 +73,10 @@ private:
mutable QColor _fillColor; mutable QColor _fillColor;
int _zIndex = 0; int _zIndex = 0;
QByteArray _svgElementId; QByteArray _svgElementId;
mutable bool _clipDirty = true;
mutable bool _hasClip = false;
mutable QRectF _clipRect;
}; };
using FGCanvasElementVec = std::vector<FGCanvasElement*>; using FGCanvasElementVec = std::vector<FGCanvasElement*>;

View file

@ -53,26 +53,6 @@ unsigned int FGCanvasGroup::indexOfChild(const FGCanvasElement *e) const
void FGCanvasGroup::doPaint(FGCanvasPaintContext *context) 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) { if (_zIndicesDirty) {
std::sort(_children.begin(), _children.end(), [](const FGCanvasElement* a, FGCanvasElement* b) std::sort(_children.begin(), _children.end(), [](const FGCanvasElement* a, FGCanvasElement* b)
{ return a->zIndex() < b->zIndex(); }); { return a->zIndex() < b->zIndex(); });
@ -84,24 +64,9 @@ void FGCanvasGroup::doPaint(FGCanvasPaintContext *context) const
_cachedSymbolDirty = false; _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) { for (FGCanvasElement* element : _children) {
element->paint(context); element->paint(context);
} }
if (_hasClip) {
context->painter()->setClipping(false);
}
} }
bool FGCanvasGroup::onChildAdded(LocalProp *prop) bool FGCanvasGroup::onChildAdded(LocalProp *prop)
@ -134,9 +99,6 @@ bool FGCanvasGroup::onChildAdded(LocalProp *prop)
_children.push_back(new FGQCanvasMap(this, prop)); _children.push_back(new FGQCanvasMap(this, prop));
newChildCount++; newChildCount++;
return true; return true;
} else if (nm == "clip") {
connect(prop, &LocalProp::valueChanged, this, &FGCanvasGroup::markClipDirty);
return true;
} else if (nm == "symbol-type") { } else if (nm == "symbol-type") {
connect(prop, &LocalProp::valueChanged, this, &FGCanvasGroup::markCachedSymbolDirty); connect(prop, &LocalProp::valueChanged, this, &FGCanvasGroup::markCachedSymbolDirty);
return true; return true;
@ -199,11 +161,6 @@ void FGCanvasGroup::markStyleDirty()
} }
} }
void FGCanvasGroup::markClipDirty()
{
_clipDirty = true;
}
void FGCanvasGroup::markCachedSymbolDirty() void FGCanvasGroup::markCachedSymbolDirty()
{ {
_cachedSymbolDirty = true; _cachedSymbolDirty = true;

View file

@ -33,15 +33,11 @@ protected:
virtual void markStyleDirty() override; virtual void markStyleDirty() override;
private: private:
void markClipDirty();
void markCachedSymbolDirty(); void markCachedSymbolDirty();
int indexOfChildWithProp(LocalProp *prop) const; int indexOfChildWithProp(LocalProp *prop) const;
private: private:
mutable FGCanvasElementVec _children; mutable FGCanvasElementVec _children;
mutable bool _clipDirty = true;
mutable bool _hasClip = false;
mutable QRectF _clipRect;
mutable bool _zIndicesDirty = false; mutable bool _zIndicesDirty = false;
mutable bool _cachedSymbolDirty = false; mutable bool _cachedSymbolDirty = false;
}; };

View file

@ -344,7 +344,7 @@ bool FGCanvasPath::rebuildFromRect(std::vector<int>& commands, std::vector<float
LocalProp* rectProp = _propertyRoot->getWithPath("rect"); LocalProp* rectProp = _propertyRoot->getWithPath("rect");
if (hasComplexBorderRadius(_propertyRoot)) { if (hasComplexBorderRadius(_propertyRoot)) {
// build a full path // build a full path
qWarning() << "implement me"; qWarning() << Q_FUNC_INFO << "implement me";
_paintType = Path; _paintType = Path;
} else { } else {
float top = rectProp->value("top", 0.0).toFloat(); float top = rectProp->value("top", 0.0).toFloat();
@ -622,6 +622,8 @@ static Qt::PenCapStyle qtCapFromCanvas(QString s)
return Qt::FlatCap; return Qt::FlatCap;
} else if (s == "round") { } else if (s == "round") {
return Qt::RoundCap; return Qt::RoundCap;
} else if (s == "square") {
return Qt::SquareCap;
} else { } else {
qDebug() << Q_FUNC_INFO << s; qDebug() << Q_FUNC_INFO << s;
} }

View file

@ -21,7 +21,7 @@ void FGCanvasText::doPaint(FGCanvasPaintContext *context) const
context->painter()->setFont(_font); context->painter()->setFont(_font);
context->painter()->setPen(fillColor()); context->painter()->setPen(fillColor());
context->painter()->setBrush(Qt::NoBrush);
QRectF rect(0, 0, 1000, 1000); QRectF rect(0, 0, 1000, 1000);
if (_alignment & Qt::AlignBottom) { if (_alignment & Qt::AlignBottom) {

View file

@ -28,12 +28,26 @@ bool FGQCanvasImage::onChildAdded(LocalProp *prop)
return true; 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(); qDebug() << "image saw child:" << prop->name();
return false; return false;
} }
void FGQCanvasImage::markImageDirty()
{
_imageDirty = true;
}
void FGQCanvasImage::rebuildImage() const void FGQCanvasImage::rebuildImage() const
{ {
qDebug() << "source" << _propertyRoot->value("source", QString());
qDebug() << "src" << _propertyRoot->value("src", QString());
qDebug() << "file" << _propertyRoot->value("file", QString());
} }

View file

@ -19,10 +19,13 @@ private:
bool onChildAdded(LocalProp *prop) override; bool onChildAdded(LocalProp *prop) override;
void rebuildImage() const; void rebuildImage() const;
void markImageDirty();
private: private:
mutable bool _imageDirty; mutable bool _imageDirty;
mutable QPixmap _image; mutable QPixmap _image;
QString _source; QString _source;
mutable QSizeF _destSize;
}; };
#endif // FGQCANVASIMAGE_H #endif // FGQCANVASIMAGE_H