Black2 Posted December 15, 2015 Share Posted December 15, 2015 hello, I created a dxreactangle and it works right in my resolution but the other is not how I fix this? local Width,Height = 400, 17.23 local X = (sx/1.68) - (Width/2) local Y = (sy/1.018) - (Height/1.018) ------ local Z = (sx/1.67) - (Width/2) local M = (sy/1.017) - (Height/1.018) --------- dxDrawRectangle(X, Y, Width, Height, tocolor(0, 0, 0, 180), false) dxDrawText("test", Z, M, 780, 752, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) Link to comment
Saml1er Posted December 16, 2015 Share Posted December 16, 2015 Some people say that you have to take your resolution but that is actually wrong. It took me more than 10 days to figure it out. You have to take the max resolution if you want relative sizes. So in your case: local mX, mY = 1920, 1080 -- max resolution local sx, sy = guiGetScreenSize() local scx, scy = sx/mX, sy/mY mX, mY = nil, nil -- free the memory since you won't need them anymore -- multiply scx and scy with number between 0-1 and they will fit on all resolutions perfectly. dxDrawRectangle ( 0.2*scx, 0.4*scy, 0.3*scx, 0.3*scy) -- Remember for dx scale you must multiply it with scx only and it will fit Link to comment
iAxel Posted December 16, 2015 Share Posted December 16, 2015 Some people say that you have to take your resolution but that is actually wrong. It took me more than 10 days to figure it out. You have to take the max resolution if you want relative sizes. So in your case: local mX, mY = 1920, 1080 -- max resolution local sx, sy = guiGetScreenSize() local scx, scy = sx/mX, sy/mY mX, mY = nil, nil -- free the memory since you won't need them anymore -- multiply scx and scy with number between 0-1 and they will fit on all resolutions perfectly. dxDrawRectangle ( 0.2*scx, 0.4*scy, 0.3*scx, 0.3*scy) -- Remember for dx scale you must multiply it with scx only and it will fit I use this method for a long time, but how about the text and its scale? Link to comment
Saml1er Posted December 16, 2015 Share Posted December 16, 2015 Some people say that you have to take your resolution but that is actually wrong. It took me more than 10 days to figure it out. You have to take the max resolution if you want relative sizes. So in your case: local mX, mY = 1920, 1080 -- max resolution local sx, sy = guiGetScreenSize() local scx, scy = sx/mX, sy/mY mX, mY = nil, nil -- free the memory since you won't need them anymore -- multiply scx and scy with number between 0-1 and they will fit on all resolutions perfectly. dxDrawRectangle ( 0.2*scx, 0.4*scy, 0.3*scx, 0.3*scy) -- Remember for dx scale you must multiply it with scx only and it will fit I use this method for a long time, but how about the text and its scale? Yes. Same method for text but you have to change scale to relative as well. local scale = 1 * scx dxDrawText ( "text", scx*0.3, scy*0.4, scx*0.2, scy*0.6, tocolor ( 0, 0, 0, 255 ), scale ) Link to comment
Tails Posted December 16, 2015 Share Posted December 16, 2015 Some people say that you have to take your resolution but that is actually wrong. It took me more than 10 days to figure it out. You have to take the max resolution if you want relative sizes. You don't need to take 'your' resolution. You need to take the resolution you created the GUI for in the first place. So if you're working on some GUI, take your resolution and use it in your code. I'll show you what I mean. Here's a piece of code from one of my resources. The text displayed by dxDrawBorderedText (combined with the function below it) will show the same for every resolution even beyond 1080p. function dxDrawBorderedText(text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI) local sWidth,sHeight = guiGetScreenSize() local sw,sh = 1280,960 dxSetAspectRatioAdjustmentEnabled(true) dxDrawText(text, x/sw*sWidth +4, y/sh*sHeight +4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth -4, y/sh*sHeight +4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth +4, y/sh*sHeight -4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth -4, y/sh*sHeight -4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth +1, y/sh*sHeight +4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth -1, y/sh*sHeight +4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth +1, y/sh*sHeight -4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth -1, y/sh*sHeight -4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth, y/sh*sHeight, w/sw*sWidth, h/sh*sHeight, color, scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, postGUI) end function drawMyText() dxDrawBorderedText("My cool text", 967, 828, 1089, 905, tocolor(195, 195, 195, 255), 2.00, "pricedown", "left", "top", false, false, true, false, false) end As you can see the x,y's are 967, 828, 1089, 905. That's based off of my resolution (1280x960). So, when using the code above, adjust the resolution to the one you're working on then adjust the xy's for the drawText in the second function. It should scale on all resolutions. @Lock7130 You can easily adjust the code to work with dxDrawRectangle as well but be sure every parameter corresponds to that function https://wiki.multitheftauto.com/wiki/DxDrawRectangle Link to comment
Saml1er Posted December 16, 2015 Share Posted December 16, 2015 Some people say that you have to take your resolution but that is actually wrong. It took me more than 10 days to figure it out. You have to take the max resolution if you want relative sizes. You don't need to take 'your' resolution. You need to take the resolution you created the GUI for in the first place. So if you're working on some GUI, take your resolution and use it in your code. I'll show you what I mean. Here's a piece of code from one of my resources. The text displayed by dxDrawBorderedText (combined with the function below it) will show the same for every resolution even beyond 1080p. function dxDrawBorderedText(text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI) local sWidth,sHeight = guiGetScreenSize() local sw,sh = 1280,960 dxSetAspectRatioAdjustmentEnabled(true) dxDrawText(text, x/sw*sWidth +4, y/sh*sHeight +4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth -4, y/sh*sHeight +4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth +4, y/sh*sHeight -4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth -4, y/sh*sHeight -4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth +1, y/sh*sHeight +4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth -1, y/sh*sHeight +4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth +1, y/sh*sHeight -4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth -1, y/sh*sHeight -4, w/sw*sWidth, h/sh*sHeight, tocolor(0, 0, 0, 255), scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, false) dxDrawText(text, x/sw*sWidth, y/sh*sHeight, w/sw*sWidth, h/sh*sHeight, color, scale/sw*sWidth, font, alignX, alignY, clip, wordBreak, postGUI) end function drawMyText() dxDrawBorderedText("My cool text", 967, 828, 1089, 905, tocolor(195, 195, 195, 255), 2.00, "pricedown", "left", "top", false, false, true, false, false) end As you can see the x,y's are 967, 828, 1089, 905. That's based off of my resolution (1280x960). So, when using the code above, adjust the resolution to the one you're working on then adjust the xy's for the drawText in the second function. It should scale on all resolutions. @Lock7130 You can easily adjust the code to work with dxDrawRectangle as well but be sure every parameter corresponds to that function https://wiki.multitheftauto.com/wiki/DxDrawRectangle I know but dx text scale was a problem. I had to do it like this instead: local sx, sy = guiGetScreenSize () local scale = (sy/768)*1 -- I still have no idea why this worked but it actually did. Link to comment
Addlibs Posted December 17, 2015 Share Posted December 17, 2015 local scale = sy/768 -- I still have no idea why this worked but it actually did. What's so mysterious about this? It's a normal calculation, say someone's screen height was 1024, divide that by the native resolution (the resolution for which the dx was aimed at), let's say, 512. actualH/nativeH = scaleFactor 1024/512 = 2 The actual resolution is 2 times larger than the native resolution. Pretty basic math. Link to comment
Saml1er Posted December 17, 2015 Share Posted December 17, 2015 When I tried to do it like this: local scale = (sx/1024)*1 Then dx text scale was different. It was okay on lower resolutions but on higher resolutions than 1024x768 It didn't work well. I had to do it using height ( sy/768 )*1. But the most epic part was that it worked without any problem if I used max resolution (sx/1920)*1. This worked perfectly. I have tested this and spent days on it. This was the solution I came up with. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now