Search Unity

Gui zoom effect in editor windows

Discussion in 'Immediate Mode GUI (IMGUI)' started by MF3D_Dev, Jan 5, 2011.

  1. MF3D_Dev

    MF3D_Dev

    Joined:
    Jan 1, 2010
    Posts:
    15
    Hi friends im trying to do a zoom effect in a editor that i am working, ths thing is that i am using gui.window for create the windows inside of the editor window and im trying to change the matrix property for change the size of the windows and make the zoom effect.

    The problem is that i want make thiss zoom effect only in one area of the editor,like a viewport. But if i change the matrix property before the beginwindows() instruction for only scale the windows it works but it scale the zone where the windows are displaying, not only the windows.

    Do you know how can i keep the same viiewport dimensions and only scale the windows created with gui.window() ??


    Thanks a lot in advance.

    Cheers
     
  2. MF3D_Dev

    MF3D_Dev

    Joined:
    Jan 1, 2010
    Posts:
    15
    Nobody have done something like this or similar?

    Thanks.
     
  3. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Can you post the code you are currently using?
     
  4. MF3D_Dev

    MF3D_Dev

    Joined:
    Jan 1, 2010
    Posts:
    15
    Hi andeeee sorry i didnt read the reply, yes when i arrive at home i will post the code.

    Thanks man.

    Cheers.
     
  5. Gizmo73

    Gizmo73

    Joined:
    Nov 28, 2010
    Posts:
    34
    code is simple but the viewport is getting scaled aswell, how do you override the clipping zone so it sits on the actual visible window?

    To recreate

    Make a class derived from an EditorWindow

    then in OnGUI()..

    OriginalGUIMatrix = GUIMatrix;

    BeginWindows();
    Matrix4x4 Translation = Matrix4x4.TRS(new Vector3(Screen.width/2,Screen.height/2,0),Quaternion.identity,Vector3.one);
    Matrix4x4 Scale = Matrix4x4.Scale(new Vector3(zoom, zoom, 1.0f));

    GUI.matrix = Translation*Scale*Translation.inverse;

    // Change the zoom value and drag the gui components around, notice they clip very aggressively on small zooms showing the issue..
    DrawYourGUI();
    // Scale the
    EndWindows();

    GUI.matrix = OriginalGUIMatrix;

    Everything works great apart from the clipping zone which is scaled aswell. Anyway to override that / set it back to the original size but still scale the GUI as above? thanks
     
  6. MF3D_Dev

    MF3D_Dev

    Joined:
    Jan 1, 2010
    Posts:
    15
    Hi friends, yes, is like Gizmo73 said:

    My code:

    // in onGUI()..

    // percent is a value that i use for control the size of the scale

    //beforeGUI is the original scale;

    guiTranslation=Matrix4x4.TRS(new Vector3(0,0,0),Quaternion.identity,Vector3.one);
    guiScale=Matrix4x4.Scale(new Vector3(percent,percent,percent));
    GUI.matrix = guiTranslation*guiScale*guiTranslation.inverse;

    BeginWindows();

    for (i=0;i<numWindows;i++){
    windowRects[numWindows]=GUILayout.Window(i,windowRects[numWindows],CreateStateWindow,"Test");
    }



    EndWindows();

    GUI.matrix=beforeGUIScale;
     
  7. Gizmo73

    Gizmo73

    Joined:
    Nov 28, 2010
    Posts:
    34
    Yes the problem appears to be that there is no way to change the clipping region with the standard stuff from what i can tell. I'm surprised it is not clamped to the window it is rendered in but c'est la vie. I tried pixelRect, various other camera properties like orthographicSize etc and nothing makes any difference. It seems this is buried away in the system unfortunately.

    * Looking at the Camera stuff, looks like i wasn't getting the GUI camera. Seems Camera.main in EditorWindow is returning false for ortho graphic and there is only 1 camera apparently so where is the GUI Camera stuff done?

    I'll have a dig into the shader side and something like GL.Viewport but i'm not getting an OnPostRender call, i've no idea why, is it supported for EditorWindows at all?

     
  8. Gizmo73

    Gizmo73

    Joined:
    Nov 28, 2010
    Posts:
    34
    ok not the best solution but it'll suffice for now, just going manually scale the rects for the components i need and leave GUI.matrix completely alone - 'it works'(tm) but would prefer the matrix soln as it removed a bunch of unnecessary overhead. Anyway that's all for now

    ta
     
  9. MF3D_Dev

    MF3D_Dev

    Joined:
    Jan 1, 2010
    Posts:
    15
    Thanks Gizmo73, this is the first thing that i made before try to use the matrix solution, but like you said, not was the best solution, and i was using GUILayout that automatically scales the component to the parent window but scaling the window rect, the result in some components not was Ok, for me at least :).

    Thanks anyway friend.

    Cheers
     
  10. Mark-Davis

    Mark-Davis

    Joined:
    Jun 21, 2011
    Posts:
    156
    I ran into the same issue, and then realized that I had forgotten to use [ExecuteInEditMode()] in my script... working code here:

    Code (csharp):
    1. _cameraGameObject.AddComponent<VFCameraPostRender>().PostRenderFunction = () =>
    2. {
    3.     Debug.Log("Inside PostRenderFunction");
    4. };
    Code (csharp):
    1. using System;
    2. using UnityEngine;
    3.  
    4. [ExecuteInEditMode()]
    5. public class VFCameraPostRender : MonoBehaviour
    6. {
    7.     Action _f;
    8.     public Action PostRenderFunction { set { _f = value; } }
    9.    
    10.     public void OnPostRender()
    11.     {
    12.         if (_f != null) _f();
    13.     }
    14. }
     
    Last edited: Nov 9, 2011
  11. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,206
    Hey guys, it's an old thread but still an active problem:)
    There are some resources like this blog post, but they are pretty limited (only editor window, has to be top-level, outside of any grouping, etc).

    So I approached it myself in a way that should work in every situation, if possible, like inside groups. For that to work, it's clear I needed reflection, as the whole GUI clipping stuff is done internally.
    First, I needed to get out of every groups we had, and transform the rect to screen space.
    Luckily, I found that UnityEngine.GUIClip (hidden class, even in assembly browser:( ) has a property to get the top clip, means the last group. I recorded it, removed the group and repeated that over and over again until I reached a constant top level clip, which is default in every space (reads -10000, -10000, 40000, 40000). Being in that space allowed me to apply the method described in the blog linked above. After that, I just had to restore all clips.
    This has the disadvantage of having to offset all zoomed controls by a set value (in my implementation returned by the the zoom function).

    That's the basic idea behind my whole approach. The script implementation can be found in this Gist.

    I made it for the scaling feature in my open source Node Editor framework, which I recommend you to check out to see how it is working;)

    I hope this will serve you well:) If you encounter problems, please tell me:)
     
    Last edited: Feb 6, 2017
    Aka_ToolBuddy and BennyKokMusic like this.