Search Unity

Creating a custom control - getting the on-screen rect?

Discussion in 'Immediate Mode GUI (IMGUI)' started by StarManta, Nov 19, 2007.

  1. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I'm trying to get the on-screen Rect of a GUIContent. GUILayoutUtility.GetRect seems to only return a Rect relative to the current window. Since this control needs to know the mouse position and whether it's over the button or not, how can I get this data?
     
  2. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    The mouse position has already been adjusted for the window, so you can just check if (myRect.Contains (Event.current.mousePosition)

    try this:
    Code (csharp):
    1.  
    2. function OnGUI () {
    3.     Debug.Log ("Before: " + Event.current.mousePosition);
    4.     GUI.BeginGroup (Rect (20,20,100,100));
    5.     Debug.Log ("After: " + Event.current.mousePosition);
    6.     GUI.EndGroup ();
    7. }
    8.  
    And notice how the mouse position is different inside outside of the group.