@@ -571,34 +571,15 @@ bool RenderedTarget::contains(const QPointF &point) const
571
571
translatedPoint = mapFromStageWithOriginPoint (translatedPoint);
572
572
translatedPoint /= scaleRatio;
573
573
574
- if (!boundingRect ().contains (translatedPoint))
575
- return false ;
576
-
577
- const std::vector<QPoint> &points = hullPoints ();
578
- QPoint intPoint = translatedPoint.toPoint ();
579
- 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 ()); });
580
-
581
- if (it == points.end ()) {
582
- // The point is beyond the last point in the convex hull
583
- return false ;
584
- }
585
-
586
- // Check if the point is equal to the one found
587
- return *it == intPoint;
574
+ return containsLocalPoint (translatedPoint);
588
575
}
589
576
590
577
bool RenderedTarget::containsScratchPoint (double x, double y) const
591
578
{
592
- if (!m_engine || ! parentItem () )
579
+ if (!m_engine)
593
580
return false ;
594
581
595
- // contains() expects item coordinates, so translate the Scratch coordinates first
596
- double stageWidth = m_engine->stageWidth ();
597
- double stageHeight = m_engine->stageHeight ();
598
- x = m_stageScale * (x + stageWidth / 2 );
599
- y = m_stageScale * (stageHeight / 2 - y);
600
-
601
- return contains (mapFromItem (parentItem (), QPointF (x, y)));
582
+ return containsLocalPoint (mapFromScratchToLocal (QPointF (x, y)));
602
583
}
603
584
604
585
bool RenderedTarget::touchingClones (const std::vector<libscratchcpp::Sprite *> &clones) const
@@ -734,6 +715,24 @@ void RenderedTarget::updateHullPoints()
734
715
// TODO: Apply graphic effects (#117)
735
716
}
736
717
718
+ bool RenderedTarget::containsLocalPoint (const QPointF &point) const
719
+ {
720
+ if (!boundingRect ().contains (point))
721
+ return false ;
722
+
723
+ const std::vector<QPoint> &points = hullPoints ();
724
+ QPoint intPoint = point.toPoint ();
725
+ 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 ()); });
726
+
727
+ if (it == points.end ()) {
728
+ // The point is beyond the last point in the convex hull
729
+ return false ;
730
+ }
731
+
732
+ // Check if the point is equal to the one found
733
+ return *it == intPoint;
734
+ }
735
+
737
736
QPointF RenderedTarget::transformPoint (double scratchX, double scratchY, double originX, double originY, double rot) const
738
737
{
739
738
return transformPoint (scratchX, scratchY, originX, originY, std::sin (rot), std::cos (rot));
@@ -763,6 +762,22 @@ QPointF RenderedTarget::mapFromStageWithOriginPoint(const QPointF &scenePoint) c
763
762
return localPoint;
764
763
}
765
764
765
+ QPointF RenderedTarget::mapFromScratchToLocal (const QPointF &point) const
766
+ {
767
+ QTransform t;
768
+ const double textureScale = m_skin->getTextureScale (m_cpuTexture);
769
+ const double scale = m_size / textureScale;
770
+ const double mirror = m_mirrorHorizontally ? -1 : 1 ;
771
+ const double bitmapRes = m_costume->bitmapResolution ();
772
+ t.translate (m_costume->rotationCenterX () * textureScale, m_costume->rotationCenterY () * textureScale);
773
+ t.rotate (-rotation ());
774
+ t.scale (bitmapRes * mirror / scale, -bitmapRes / scale);
775
+ t.translate (-m_x, -m_y);
776
+
777
+ QPointF localPoint = t.map (point);
778
+ return localPoint;
779
+ }
780
+
766
781
CpuTextureManager *RenderedTarget::textureManager ()
767
782
{
768
783
if (!m_textureManager)
0 commit comments