Quantcast

Jump to content

» «
Photo

Make GUI fit in every resolution

9 replies to this topic
Noox
  • Noox

    changeScriptAbility(&myScriptAbility, "improve");

  • Members
  • Joined: 20 Jun 2014
  • None

#1

Posted 24 June 2014 - 11:10 PM

It's more of a math calculation.

I have a GUI, and on my screen resolution (1920x1080) it's placed at 1730 on the X axis and 847 on t he Y axis, is there some mathematical expression to tell the game where to put that at every resolution?

My plan was changing resolution and aligning things perfectly for that but it takes a lot of time to get things done that way.

Thanks in advance.


Noox
  • Noox

    changeScriptAbility(&myScriptAbility, "improve");

  • Members
  • Joined: 20 Jun 2014
  • None

#2

Posted 24 June 2014 - 11:24 PM Edited by Noox, 24 June 2014 - 11:34 PM.

What's 0.5f? the size?

I tried it and it works great thanks a lot!


NTAuthority
  • NTAuthority

    hell, no, tunnel, no

  • Feroci
  • Joined: 09 Sep 2008
  • European-Union
  • Best Conversion 2014 [ViIV for GTANY]
    Most Knowledgeable [Tech] 2013
    Best Map 2013 [ViceCityStories PC Edition]
    Contribution Award [Mods]

#3

Posted 26 June 2014 - 08:07 PM

do note aspect ratio correction, as what you code like that will look like crap on anything not 16:9

  • Silent, InfamousSabre and LordOfTheBongs like this

LetsPlayOrDy
  • LetsPlayOrDy

    So fast you'll freak!

  • Members
  • Joined: 24 Aug 2013
  • United-States

#4

Posted 23 July 2014 - 01:51 AM

do note aspect ratio correction, as what you code like that will look like crap on anything not 16:9

How would you make it so it looks good in any aspect ratio?

Michael Wojtanis
  • Michael Wojtanis

    Rinepim

  • Members
  • Joined: 17 Jul 2013

#5

Posted 23 July 2014 - 03:51 PM Edited by Michael Wojtanis, 23 July 2014 - 03:51 PM.

LetsPlayOrDry - i did. :)

This is complicated process and i have some values what i do not remeber how got them [in Weapon Wheel].
I will write it how to do when i back in few hours. :)

GTA.Native.Function.Call("GET_ASPECT_RATIO") - this is good.

LetsPlayOrDy
  • LetsPlayOrDy

    So fast you'll freak!

  • Members
  • Joined: 24 Aug 2013
  • United-States

#6

Posted 23 July 2014 - 05:39 PM

I got that, but I don't know the math to auto position/size an image with that data.

leftas
  • leftas

    C++ for hacks/mods, C# for everything else.

  • Members
  • Joined: 13 Jun 2013
  • Lithuania

#7

Posted 23 July 2014 - 06:48 PM Edited by leftas, 23 July 2014 - 06:59 PM.

http://stackoverflow...he-aspect-ratio and
http://andrew.hedges...s/aspect_ratio/ should help you, how to calculate it.

P.S. Maybe you guys know good sites which would contain good formulas for calculating in games and etc. ?

Best regards,
Paul.

LetsPlayOrDy
  • LetsPlayOrDy

    So fast you'll freak!

  • Members
  • Joined: 24 Aug 2013
  • United-States

#8

Posted 24 July 2014 - 04:27 PM

http://stackoverflow...he-aspect-ratio and
http://andrew.hedges...s/aspect_ratio/ should help you, how to calculate it.

P.S. Maybe you guys know good sites which would contain good formulas for calculating in games and etc. ?

Best regards,
Paul.

jQuery is so hard to understand lol
I know Unity has some stuff

byteMe420
  • byteMe420

    Fvck Everything

  • Members
  • Joined: 02 Jul 2014
  • United-States

#9

Posted 24 July 2014 - 05:33 PM Edited by byteMe420, 25 July 2014 - 03:21 PM.

Just like the resolution has an aspect ratio... your menu needs to maintain an aspect ratio. So create your menu on whatever resolution and define the aspect ratio. You need to use basic algebra to solve for x type math to determine how your menu changes.

 

If your menu maintains the same aspect ratio then it will not get distorted. Define the aspect ratio for ALL rectangles and make sure they maintain when res changes. Sounds like a couple moving parts so maybe not straightforward but doesnt sound impossible to do.

 

Remember aspect ratio is the width of something over the height. So determine an aspect ratio for your menu rectangles u are happy with and maintain them on all resolutions using algebra. Id have to do it myself to figure it out but maybe i will and write a small forms app to show it.

 

Positioning menu doesnt really need to consider aspect ratio as much as the size of the rectangles unless u need rectangles to maintain a distance between each other that scales. So Im only talking size. Example if u just want your menu 10% down from the top of screen and 10% into the right of the screen your X and Y on all aspect ratios will be 10% of res width and height respectively.

 

And if your menu has multiple rectangles then u need to position one rectangle relative to resolution and all other rectangles are positioned relative to that rectangle.

 

edit... i made this so far... i use a windows form to represent the game and a panel (blue) to represent a rectangle u would draw in game. I am able to maintain aspect ratio when i change the "game" (form) resolution but it is not perfect and buggy. I use decimal types for calculations but i think it goes off a little when i am casting to ints. Anyways i am doing this for my first time and i almost feel like it would be easier to create the menu with different settings predetermined for each game aspect ratio than to calculate dynamically. I do like challenges though so ill try to figure it out...

 

jY9w3KE.png


DaBOSS54320
  • DaBOSS54320

    Square Civilian

  • Members
  • Joined: 19 Jan 2014
  • None

#10

Posted 23 August 2014 - 07:02 AM

(If you are using a .net scripthook) I believe Game.Resolution returns a size object that will give you the resolution width and height. I used it for one of my mods that put a bar in the bottom right corner to represent slow motion time so I know it will work if you do it right. I can give you the graphics part of my code as an example too if it'll help.

//Original script mod by DaBOSS54320
//Please do not remove/modify this credit if redistributed

	private void gTick(object sender,GraphicsEventArgs args){
		float h = (float) Game.Resolution.Height;
		float w = (float) Game.Resolution.Width;
		
		float dis = 15.0F; //Distance from corner of screen
		float l = 200.0F;
		float x1 = w-dis-l;
		float y1 = h-dis;
		float t = (float) time;
		float maxT = (float) maxTime;
		float x2 = w-dis-l*(1.0F - (t/maxT));
		float y2 = h-dis;
		float w1 = 8.0F;
		Color c = Color.Blue;
		
		args.Graphics.DrawLine(x1,y1,x2,y2,w1,c);
	}
}

Also if you don't already know you'd use "PerFrameDrawing += new GraphicsEventHandler(gTick);" for that function to properly draw. Also the time and maxTime variables are parts of my script so you can replace them with whatever you need to from your code.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users