W3ke Posted December 23, 2022 Share Posted December 23, 2022 Hi recently I try to create dxDrawRoundedRectangle where I can put text in it, it seems easy but dxGetTextWidth is scaling wrong. I use custom font mojeW,mojeH = 1920,1080 sW,sH = guiGetScreenSize() sx, sy = (sW/mojeW), (sH/mojeH) local scale = 1 local minScale = 1.1 if sW < mojeW then scale = math.min(minScale, mojeW/sW) end font = dxCreateFont("f.ttf", 13/scale) local lol = "Wpisz tutaj coś..." local width = dxGetTextWidth( lol:gsub("#%x%x%x%x%x%x", ""), sW*0.001, font ) dxDrawRoundedRectangle(24*sx, 271*sy, (width+5+5)*sx, 41*sy, 10, tocolor(35, 37, 62, 180), false) dxDrawText(lol:gsub("#%x%x%x%x%x%x", ""), (29+1)*sx, (271+1)*sy, (29+1+480)*sx, (271+1+41)*sy, tocolor(0, 0, 0), 1, font, "left", "center", false, false, false, false) dxDrawText(lol, 29*sx, 271*sy, (29+480)*sx, (271+41)*sy, tocolor(150, 150, 150, 255), 1, font, "left", "center", false, false, false, true) link to view: https://imgur.com/a/WfJKimu I can't figure it out, how to solve it. I want to make it look good on all resolutions. Link to comment
Vampire Posted December 23, 2022 Share Posted December 23, 2022 Hello @W3ke and welcome! I've moved your topic to the Scripting section so you can get better assistance. 1 Link to comment
Scripting Moderators thisdp Posted December 23, 2022 Scripting Moderators Share Posted December 23, 2022 because you scaled text size in dxGetTextWidth, while in dxDrawText, the text scale is still 1 Link to comment
alex17" Posted December 23, 2022 Share Posted December 23, 2022 local width = dxGetTextWidth( lol:gsub("#%x%x%x%x%x%x", ""), 13/scale, font ) Link to comment
W3ke Posted December 23, 2022 Author Share Posted December 23, 2022 3 hours ago, thisdp said: because you scaled text size in dxGetTextWidth, while in dxDrawText, the text scale is still 1 same result as before 8 minutes ago, alex17" said: local width = dxGetTextWidth( lol:gsub("#%x%x%x%x%x%x", ""), 13/scale, font ) it make it even bigger https://imgur.com/RgKIR75 Link to comment
alex17" Posted December 23, 2022 Share Posted December 23, 2022 (edited) 23 minutes ago, W3ke said: same result as before it make it even bigger https://imgur.com/RgKIR75 because, you are multiplying width for sx dxDrawRoundedRectangle(24*sx, 271*sy, (width+5+5)*sx, 41*sy, 10, tocolor(35, 37, 62, 180), false) dxDrawRoundedRectangle(24*sx, 271*sy, width + (5 * sx), 41*sy, 10, tocolor(35, 37, 62, 180), false) Edited December 23, 2022 by alex17" 1 Link to comment
W3ke Posted December 23, 2022 Author Share Posted December 23, 2022 4 minutes ago, alex17" said: because, you are multiplying width for sx dxDrawRoundedRectangle(24*sx, 271*sy, (width+5+5)*sx, 41*sy, 10, tocolor(35, 37, 62, 180), false) dxDrawRoundedRectangle(24*sx, 271*sy, width + (5 * sx), 41*sy, 10, tocolor(35, 37, 62, 180), false) Now it works perfect. Thank you 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