Search Unity

NODEGRAPH: drag create a window

Discussion in 'Immediate Mode GUI (IMGUI)' started by llavigne, Mar 1, 2008.

  1. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    I am trying to do a button, when you click it and drag from it, a window sticks to the mouse pointer until release.

    Nothing I am doing works. When I click the button the statically generated window disapears (it's not even draggable...)

    Code (csharp):
    1.  
    2. /* Window example */
    3.  
    4. var windowRects = new Array();
    5. var windowRect : Rect = Rect (20, 20, 120, 50);
    6.  
    7. function OnGUI ()
    8. {
    9.     windowRect = GUI.Window (0, windowRect, WindowFunction, "My Window");
    10.     var dragAdding: boolean;
    11.     if (GUI.RepeatButton (Rect (Screen.width - 105, Screen.height - 35, 100, 30), "add window"))
    12.         {
    13.             if (dragAdding)
    14.             {
    15.                 // dragging the window... however it's done
    16.                 }
    17.                 else
    18.                 {
    19.                     dragAdding = true;
    20.                     CreateWindow(Input.mousePosition);
    21.                 }
    22.         }
    23.         else
    24.             dragAdding = false;
    25.    
    26.     for (var w : Rect in windowRects)
    27.     {
    28.         w = GUI.Window (0, w, WindowFunction, "My Window");
    29.     }
    30.  
    31. }
    32.  
    33. function WindowFunction (windowID : int)
    34. {
    35.     // Draw any Controls inside the window here
    36. }
    37.  
    38. function CreateWindow(v: Vector2)
    39. {
    40.     windowRects.Push(Rect (v.x, v.y, 100, 30));
    41. }
    42.  
     
  2. CoherentInk

    CoherentInk

    Joined:
    Jul 16, 2006
    Posts:
    216
    My guess is that Buttons and RepeatButtons don't return true until they receive a MouseUp event. As a result, you may not be able to make this using a button, or many other GUI elements as they are all waiting for the MouseUp.
     
  3. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    thanks! that was it