How to test for an image fully inside another?

BlitzPlus Forums/BlitzPlus Programming/How to test for an image fully inside another?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Use ImagesCollide()...

Graphics 800, 600, 0, 2
SeedRnd MilliSecs()

AutoMidHandle True

;make 'card'
card = CreateImage(256, 256)
SetBuffer ImageBuffer(card)
Color Rand(100, 255), Rand(100, 255), Rand(100, 255)
ClsColor 0, 0, 0
Cls
For c=1 To 100
	Oval Rand(1, 155), Rand(1, 155), 100, 100, 1
Next
SetBuffer BackBuffer()

;make collision mask
mask = CreateImage(ImageWidth(card), ImageHeight(card))
LockBuffer ImageBuffer(card)
LockBuffer ImageBuffer(mask)

For x=0 To (ImageWidth(card) - 1)
	For y=0 To (ImageHeight(card) - 1)
		rgb = ReadPixelFast(x, y, ImageBuffer(card)) And $FFFFFF
		
		If rgb Then rgb = 0 Else rgb = $FFFFFF
		
		WritePixelFast x, y, rgb, ImageBuffer(mask)
	Next
Next

UnlockBuffer ImageBuffer(mask)
UnlockBuffer ImageBuffer(card)

;make counter
counter = CreateImage(104, 104)
SetBuffer ImageBuffer(counter)
Color Rand(100, 255), Rand(100, 255), Rand(100, 255)
ClsColor 0, 0, 0
Cls
Color 255, 255, 255
Oval 0, 0, 104, 104, 1
Color 0, 0, 200
Oval 4, 4, 96, 96, 1
SetBuffer BackBuffer()	

on_card = False

Repeat
	mx = MouseX()
	my = MouseY()
	
	Cls
	
	If MouseDown(1)
		DrawImage mask, 400, 300
	Else
		DrawImage card, 400, 300
	EndIf
	
	;draw 'counter'
	DrawImage counter, mx, my
	
	;check if counter is on card
	If RectsOverlap(400 - 128, 300 - 128, 256, 256, mx - 52, my - 52, 104, 104)
		If ImagesCollide(mask, 400, 300, 0, counter, mx, my, 0)
			on_card = False
		Else
			on_card = True
		EndIf
	Else
		on_card = False
	EndIf
	
	Color 255, 255, 255
	Text 12, 12, "Counter fully on card = " + on_card
	
	Text 400, 588, "LMB to show mask", 1, 1
	
	Flip
Until KeyHit(1)

End