diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2011-06-07 19:39:38 +1000 |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2011-06-07 19:43:41 +1000 |
commit | 984f21f18d1a3981e7363df467ff2e24e69aa847 (patch) | |
tree | db4665cbc1591a77f988b0b4f8925fe5636f5672 /src/declarative/particles/qsgmaskextruder.cpp | |
parent | 21d0c6ef9a7df3e5fa69ff344e9dee2d2159c43c (diff) |
Immense Particles Refactor Part B
Examples work again. Also augmented Wander and PointAttractor with
physics modes.
Diffstat (limited to 'src/declarative/particles/qsgmaskextruder.cpp')
-rw-r--r-- | src/declarative/particles/qsgmaskextruder.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/declarative/particles/qsgmaskextruder.cpp b/src/declarative/particles/qsgmaskextruder.cpp index 3fe28b30a3..d9a463910d 100644 --- a/src/declarative/particles/qsgmaskextruder.cpp +++ b/src/declarative/particles/qsgmaskextruder.cpp @@ -53,7 +53,7 @@ QSGMaskExtruder::QSGMaskExtruder(QObject *parent) : QPointF QSGMaskExtruder::extrude(const QRectF &r) { ensureInitialized(r); - if(!m_mask.count()) + if(!m_mask.count() || m_img.isNull()) return r.topLeft(); const QPointF p = m_mask[rand() % m_mask.count()]; //### Should random sub-pixel positioning be added? @@ -63,6 +63,8 @@ QPointF QSGMaskExtruder::extrude(const QRectF &r) bool QSGMaskExtruder::contains(const QRectF &bounds, const QPointF &point) { ensureInitialized(bounds);//###Current usage patterns WILL lead to different bounds/r calls. Separate list? + if(m_img.isNull()) + return false; QPoint p = point.toPoint() - bounds.topLeft().toPoint(); return m_img.rect().contains(p) && (bool)m_img.pixelIndex(p); } @@ -70,14 +72,19 @@ bool QSGMaskExtruder::contains(const QRectF &bounds, const QPointF &point) void QSGMaskExtruder::ensureInitialized(const QRectF &r) { if(m_lastWidth == r.width() && m_lastHeight == r.height()) - return; + return;//Same as before m_lastWidth = r.width(); m_lastHeight = r.height(); + m_img = QImage(); m_mask.clear(); if(m_source.isEmpty()) return; m_img = QImage(m_source.toLocalFile()); + if(m_img.isNull()){ + qWarning() << "MaskShape: Cannot load" << qPrintable(m_source.toLocalFile()); + return; + } m_img = m_img.createAlphaMask(); m_img = m_img.convertToFormat(QImage::Format_Mono);//Else LSB, but I think that's easier m_img = m_img.scaled(r.size().toSize());//TODO: Do they need aspect ratio stuff? Or tiling? |