Jump to content

Problem with dxGetTextWidth


W3ke

Recommended Posts

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
4 minutes ago, alex17&quot; 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...