@@ -548,19 +548,22 @@ const std::vector<QPoint> &RenderedTarget::hullPoints() const
548548
549549bool RenderedTarget::contains (const QPointF &point) const
550550{
551- if (!m_costume || !m_texture.isValid () || !m_cpuTexture.isValid ())
551+ if (!m_costume || !m_texture.isValid () || !m_cpuTexture.isValid () || ! parentItem () )
552552 return false ;
553553
554554 if (m_stageModel)
555555 return true ; // the stage contains any point within the scene
556556
557- if (!boundingRect ().contains (point))
557+ const double scaleRatio = m_skin->getTextureScale (m_texture) / m_skin->getTextureScale (m_cpuTexture);
558+ QPointF translatedPoint = mapToItem (parentItem (), point);
559+ translatedPoint = mapFromStageWithOriginPoint (translatedPoint);
560+ translatedPoint /= scaleRatio;
561+
562+ if (!boundingRect ().contains (translatedPoint))
558563 return false ;
559564
560565 const std::vector<QPoint> &points = hullPoints ();
561-
562- const double scaleRatio = m_skin->getTextureScale (m_texture) / m_skin->getTextureScale (m_cpuTexture);
563- QPoint intPoint = (point / scaleRatio).toPoint ();
566+ QPoint intPoint = translatedPoint.toPoint ();
564567 auto it = std::lower_bound (points.begin (), points.end (), intPoint, [](const QPointF &lhs, const QPointF &rhs) { return (lhs.y () < rhs.y ()) || (lhs.y () == rhs.y () && lhs.x () < rhs.x ()); });
565568
566569 if (it == points.end ()) {
@@ -696,6 +699,23 @@ QPointF RenderedTarget::transformPoint(double scratchX, double scratchY, double
696699 return QPointF (x, y);
697700}
698701
702+ QPointF RenderedTarget::mapFromStageWithOriginPoint (const QPointF &scenePoint) const
703+ {
704+ // mapFromItem() doesn't use the transformOriginPoint property, so we must do this ourselves
705+ QTransform t;
706+ const double mirror = m_mirrorHorizontally ? -1 : 1 ;
707+ const double originX = transformOriginPoint ().x ();
708+ const double originY = transformOriginPoint ().y ();
709+ t.translate (originX, originY);
710+ t.rotate (-rotation ());
711+ t.scale (1 / scale () * mirror, 1 / scale ());
712+ t.translate (-originX * mirror, -originY);
713+ t.translate (-x (), -y ());
714+
715+ QPointF localPoint = t.map (scenePoint);
716+ return localPoint;
717+ }
718+
699719CpuTextureManager *RenderedTarget::textureManager ()
700720{
701721 if (!m_textureManager)
0 commit comments