CustomGetMouseButtonDown

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Removing all content from page)
m (Reverted edits by Joseph05408 (Talk); changed back to last version by StarManta)
Line 1: Line 1:
 +
If you need to use the likes of Input.OnMouseButtonDown(0), but when your user clicks on buttons and text fields need it to not shoot whatever happens to be behind the window.... just use this class. It's written so you can simply replace "Input." with "YourGUIClass." and it will just work.
  
 +
You do, however, need to customize the last function per game - it needs to check each window manually, as there doesn't seem to be an automated way of looping through all the windows.
 +
 +
<javascript>
 +
 +
static function GetMouseButtonDown(btn : int) : boolean {
 +
if (!Input.GetMouseButtonDown(btn)) return false;
 +
if (CursorIsOverAnyWindow()) return false;
 +
return true;
 +
}
 +
static function GetMouseButton(btn :int) : boolean {
 +
if (!Input.GetMouseButton(btn)) return false;
 +
if (CursorIsOverAnyWindow()) return false;
 +
return true;
 +
}
 +
 +
static function CursorIsOverAnyWindow() : boolean {
 +
var guiCursorPos : Vector2 = Vector2(Input.mousePosition.x, Screen.height-Input.mousePosition.y);
 +
//TODO: check all your windows here
 +
if (GUIScriptClass1.main.window.Contains(guiCursorPos)) return true;
 +
if (GUIScriptClass2.main.window.Contains(guiCursorPos)) return true;
 +
//etcetera
 +
return false;
 +
}
 +
</javascript>

Revision as of 19:17, 19 October 2009

If you need to use the likes of Input.OnMouseButtonDown(0), but when your user clicks on buttons and text fields need it to not shoot whatever happens to be behind the window.... just use this class. It's written so you can simply replace "Input." with "YourGUIClass." and it will just work.

You do, however, need to customize the last function per game - it needs to check each window manually, as there doesn't seem to be an automated way of looping through all the windows.

<javascript>

static function GetMouseButtonDown(btn : int) : boolean { if (!Input.GetMouseButtonDown(btn)) return false; if (CursorIsOverAnyWindow()) return false; return true; } static function GetMouseButton(btn :int) : boolean { if (!Input.GetMouseButton(btn)) return false; if (CursorIsOverAnyWindow()) return false; return true; }

static function CursorIsOverAnyWindow() : boolean { var guiCursorPos : Vector2 = Vector2(Input.mousePosition.x, Screen.height-Input.mousePosition.y); //TODO: check all your windows here if (GUIScriptClass1.main.window.Contains(guiCursorPos)) return true; if (GUIScriptClass2.main.window.Contains(guiCursorPos)) return true; //etcetera return false; } </javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox