Page 1 of 1

Basic Mouse Checker framework

Posted: Sun Nov 23, 2008 12:49 pm
by Jay
This is a framework that checks if the mouse is inside a rectangle or a flipbook. It works at LowLevel, i am unsure if it works at HighLevel too.

Code: Select all

{
	MouseIsInsideRectangle[ (left, top, right, bottom)
	{
		MOUSE_X=GetMousePosX();
		MOUSE_Y=GetMousePosY();
		if(MOUSE_X<left)
		{
			return 0;
		}
		if(MOUSE_X>right)
		{
			return 0;
		}
		if(MOUSE_Y<top)
		{
			return 0;
		}
		if(MOUSE_Y>bottom)
		{
			return 0;
		}
		return 1;
	} ]
	MouseIsInsideDrawnFlipbook[ (left, top, sizeX, sizeY)
	{
		return MouseIsInsideRectangle(left, top, left+sizeX, top+sizeY);
	} ]
	CheckEventWhileOnRectangle[ (left, top, right, bottom, event)
	{
		return (event and MouseIsInsideRectangle(left,top,right,bottom));
	} ]
	CheckEventWhileOnDrawnFlipbook[ (left, top, sizeX, sizeY, event)
	{
		return (event and MouseIsInsideDrawnFlipBook(left,top,sizeX,sizeY));
	} ]
}
Lets say you want to draw a flipbook at position (160,120) on the screen and want to check if the mouse is over it. The flipbook is 500 pixels wide and 300 pixels high. You would just write:

Code: Select all

DrawFlipBookImage(FLIPBOOK_NAME, FLIPBOOK_INDEX, 160, 120, 255, 255, 255, 255, 1 );
if(MouseIsInsideDrawnFlipbook(160, 120, 500, 300))
{
...
}
If you want to check quickly if the player pressed the left mousebutton while on the flipbook (e.g. you have button and the player clicks on it) then you would write:

Code: Select all

DrawFlipBookImage(FLIPBOOK_NAME, FLIPBOOK_INDEX, 160, 120, 255, 255, 255, 255, 1 );
if(CheckEventWhileOnDrawnFlipbook(160, 120, 500, 300, self.lbutton_pressed))
{
...
}
I know this could also be accomplished with the CheckArea commands, but if find them difficult to use.

Hope this helps. :wink:

Re: Basic Mouse Checker framework

Posted: Tue Nov 25, 2008 5:56 pm
by SucOcuS
New info for noob's like me it's always wellcome dude!

Thanks