@@ -81,7 +81,26 @@ QRgb CpuTextureManager::getPointColor(const Texture &texture, int x, int y, cons
81
81
bool CpuTextureManager::textureContainsPoint (const Texture &texture, const QPointF &localPoint, const std::unordered_map<ShaderManager::Effect, double > &effects)
82
82
{
83
83
// https://github.com/scratchfoundation/scratch-render/blob/7b823985bc6fe92f572cc3276a8915e550f7c5e6/src/Silhouette.js#L219-L226
84
- return qAlpha (getPointColor (texture, localPoint.x (), localPoint.y (), effects)) > 0 ;
84
+ const int width = texture.width ();
85
+ const int height = texture.height ();
86
+ int x = localPoint.x ();
87
+ int y = localPoint.y ();
88
+
89
+ if (!effects.empty ()) {
90
+ // Get local position with effect transform
91
+ QVector2D transformedCoords;
92
+ const QVector2D localCoords (x / static_cast <float >(width), y / static_cast <float >(height));
93
+ EffectTransform::transformPoint (effects, localCoords, transformedCoords);
94
+ x = transformedCoords.x () * width;
95
+ y = transformedCoords.y () * height;
96
+ }
97
+
98
+ if ((x < 0 || x >= width) || (y < 0 || y >= height))
99
+ return false ;
100
+
101
+ GLubyte *pixels = getTextureData (texture);
102
+ QRgb color = qRgba (pixels[(y * width + x) * 4 ], pixels[(y * width + x) * 4 + 1 ], pixels[(y * width + x) * 4 + 2 ], pixels[(y * width + x) * 4 + 3 ]);
103
+ return qAlpha (color) > 0 ;
85
104
}
86
105
87
106
void CpuTextureManager::removeTexture (const Texture &texture)
0 commit comments