Search Unity

Relative Widget Coordinates

Discussion in 'Immediate Mode GUI (IMGUI)' started by mkolb, Jan 3, 2008.

  1. mkolb

    mkolb

    Joined:
    Dec 17, 2007
    Posts:
    48
    Hi all,

    just a small question, is it possible to change the GUI coordinate system from absolute to relative? That way the visual position of the widgets is preserved when changing the window size. I know I can always multiply the screen-heigth and width by the factor which represents the relative coordinate, but I wanted to know if I didn't see a option where I can change this with one click.

    Regards,
    Martin
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Nope, they're absolute, always.
     
  3. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    I really wish that there was a button you could check to turn on relative GUIs. As an alternative you could use the slightly complicated GUI Matrix to automatically scale the GUI, but then you get into trying to vertically position things (you have to multiply the GUI in the Matrix with the same value for X and Y so it doesn't get stretched, but then unless your monitor is 100% square, the vertical position of interface elements will change based on screen size.
     
  4. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Try to explain precisely what you mean by "relative" GUI. If it's simply scaling the GUI up and down to fit screen res, then that is quite simple to do with GUI.Matrix
     
  5. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    That's exactly what I mean.. But when I tried to do that with the Matrix, I got what I described earlier. My monitor isn't square (none are, afaik) so I was left with two options:

    Multiply the matrix by a common screen width for x and the corresponding height for y. This will perfectly scale the GUI based on resolution, but will stretch the interface elements.

    Multiply the matrix by the same number both ways. This will scale the GUI based on resolution without stretching GUI elements, but will compromise the Y-position of elements.

    I never actually figured it out. >.<
     
  6. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    I took "relative" as meaning coordinates are 0.0 -> 1.0, where 1.0 is at max screen width/height. As opposed to "absolute" meaning specific pixel values of 0.0 -> screen height/width. But obviously I'm not the original poster so... :p
     
  7. mkolb

    mkolb

    Joined:
    Dec 17, 2007
    Posts:
    48
    I also ment "relative" as coordinates in range from 0 to 1.
    Not completeley sure, but Moldorma talked about the same I think.
    Absolute coordinates are a bit tricky I suppose, because of round errors.
    Scaling the GUI by matrix would be an option, but I don't know about the y coordinates or how to achieve it at all.