Sprite: Clamp src_rect to bitmap bounds
This commit is contained in:
		
							parent
							
								
									541e24f678
								
							
						
					
					
						commit
						55cec53911
					
				
					 1 changed files with 16 additions and 5 deletions
				
			
		| 
						 | 
					@ -134,12 +134,23 @@ struct SpritePrivate
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void onSrcRectChange()
 | 
						void onSrcRectChange()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (mirrored)
 | 
							FloatRect rect = srcRect->toFloatRect();
 | 
				
			||||||
			quad.setTexRect(srcRect->toFloatRect().hFlipped());
 | 
							Vec2i bmSize;
 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
			quad.setTexRect(srcRect->toFloatRect());
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		quad.setPosRect(IntRect(0, 0, srcRect->width, srcRect->height));
 | 
							if (bitmap)
 | 
				
			||||||
 | 
								bmSize = Vec2i(bitmap->width(), bitmap->height());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (mirrored)
 | 
				
			||||||
 | 
								rect = rect.hFlipped();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* Clamp the rectangle so it doesn't reach outside
 | 
				
			||||||
 | 
							 * the bitmap bounds */
 | 
				
			||||||
 | 
							rect.w = clamp<int>(rect.w, 0, bmSize.x-rect.x);
 | 
				
			||||||
 | 
							rect.h = clamp<int>(rect.h, 0, bmSize.y-rect.y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							quad.setTexRect(rect);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							quad.setPosRect(FloatRect(0, 0, rect.w, rect.h));
 | 
				
			||||||
		recomputeBushDepth();
 | 
							recomputeBushDepth();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		wave.dirty = true;
 | 
							wave.dirty = true;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue