Basic Mouse Checker framework

Topics regarding Scripting with Reality Factory
Post Reply
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Basic Mouse Checker framework

Post by Jay » Sun Nov 23, 2008 12:49 pm

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:
Everyone can see the difficult, but only the wise can see the simple.
-----

SucOcuS
Posts: 18
Joined: Wed Nov 19, 2008 11:31 am
Location: Majorca (Spain)

Re: Basic Mouse Checker framework

Post by SucOcuS » Tue Nov 25, 2008 5:56 pm

New info for noob's like me it's always wellcome dude!

Thanks
TIME WILL PROVE THE DEPTH OF YOUR SOUL, BUT ONLY YOUR ACTIONS WILL SHOW IT'S WORTH
SucOcuS'08

Post Reply