ikvindmooi Posted June 24, 2015 Share Posted June 24, 2015 Hello, I do have a question about a panel I've made in DX. I want this panel to show at the center of the screen at every resolution but i can not manage to get it. Now it does show up and it works, but it's not at the same place at the middle. at lowest resolution its in the middle, but with higher resolutions it is opening at the left side of the screen. I did tried to make a new local guiGetScreenSize and add it to the DX GUI then the GUI does work but the color does not change when i get to the login text. EDIT: There's no error in debug. Thanks, Held firstFont = dxCreateFont( "xirod.ttf", 20) ----------------------------------- function isMouseInPosition ( x, y, width, height ) if ( not isCursorShowing ( ) ) then return false end local sx, sy = guiGetScreenSize ( ) local cx, cy = getCursorPosition ( ) local cx, cy = ( cx * sx ), ( cy * sy ) if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then return true else return false end end function drawPanel() dxDrawRectangle(245, 193, 517, 270, tocolor(0, 0, 0, 185), true) dxDrawRectangle(245, 150, 520, 38, tocolor(0, 0, 0, 185), true) --------------- if ( isMouseInPosition(80, 330, 160, 30) ) then dxDrawText("Login", -150, 314, 473, 381, tocolor(0, 255, 255, 255), 0.9, secondFont, "center", "center", false, false, true, false, false) else dxDrawText("Login", -150, 314, 473, 381, tocolor(255, 255, 255, 255), 0.9, secondFont, "center", "center", false, false, true, false, false) end end Link to comment
MisterQuestions Posted June 24, 2015 Share Posted June 24, 2015 You should use guiGetScreenSize... Read about it at the wiki there you will knoq how to do it for every resolution. Link to comment
Dealman Posted June 24, 2015 Share Posted June 24, 2015 It's pretty basic math, lets say you have a rectangle that is 200 pixels wide - you divide this by 2, and you get 100. Starting from the left, going to the right(0-100 out of 200) will be the center of the rectangle. So if you want this window centered, get the resolution using guiGetScreenSize and then divide the screen width by 2 to get the center. Draw the rectangle at this position, and subtract it by 100 and it will be centered. For example; local screenW, screenH = guiGetScreenSize() dxDrawRectangle(screenW/2-100, screenH/2-100, 200, 200, ...) You can also use relative values. Which means you use the source resolution and the current resolution. So if you designed the interface on a 1920x1080 resolution, you'd do this; local screenW, screenH = guiGetScreenSize() dxDrawRectangle((200/1920)*screenW, (200/1080)*screenH, ...) Edit: You can do this for rapid conversion of absolute values to relative values. Simple copy and pasting. I use a website where you can run Lua code to make the process very fast and straight forward, since doing it all manually is a very tedious process. Especially with DX functions. Simply paste this code(into the website linked above) and enter the appropriate values. Then copy the output and you're golden. local sX, sY, wX, hY = 480, 240, 969, 570; -- Paste the absolute values here local sourceWidth = 1920; -- Change those to the source values. local sourceHeight = 1080; -- Change those to the source values. local nSX, nSY, nWX, nHY = (sX/sourceWidth), (sY/sourceHeight), (wX/sourceWidth), (hY/sourceHeight); for i=0, 47 do print(""); -- This is just to clear the print window, so you don't confused what to copy. end print(tostring(nSX).."*screenW, "..tostring(nSY).."*screenH, "..tostring(nWX).."*screenW, "..tostring(nHY).."*screenH"); 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