.:HyPeX:. Posted February 13, 2015 Share Posted February 13, 2015 Hello, i've got a question, how can i invert my text size? To clarify these are my maths: local text = "~HyPeX~ASdasdasd" local size = dxGetTextWidth(text,1,"default") local max = 100 local size = size/max local tsize = size * -4+4 outputConsole(tsize) So far, it works kinda good, but the sizes vary too much. I.e: big texts are excesively small and small texts are excesively big.. Link to comment
xXMADEXx Posted February 14, 2015 Share Posted February 14, 2015 What exactly are you trying to do? Link to comment
.:HyPeX:. Posted February 14, 2015 Author Share Posted February 14, 2015 What exactly are you trying to do? Make the text always fit in a 100 pixel width space, having the size 1 as maximum and getting smaller if it is too big. Link to comment
xXMADEXx Posted February 14, 2015 Share Posted February 14, 2015 What exactly are you trying to do? Make the text always fit in a 100 pixel width space, having the size 1 as maximum and getting smaller if it is too big. I'm not sure how the math wouldbe, but you could use a while loop, something like this: local text = "~HyPeX~ASdasdasd" local size = dxGetTextWidth(text,1,"default") local tSize = 1; if ( size < 100 ) then while ( size < 100 ) do tSize = tSize + 0.5; size = dxGetTextWidth(text,tSize,"default") end elseif ( size > 100 ) then while ( size > 100 ) then tSize = tSize - 0.5; size = dxGetTextWidth(text,tSize,"default") end end outputConsole ( tSize ); Link to comment
.:HyPeX:. Posted February 14, 2015 Author Share Posted February 14, 2015 What exactly are you trying to do? Make the text always fit in a 100 pixel width space, having the size 1 as maximum and getting smaller if it is too big. I'm not sure how the math wouldbe, but you could use a while loop, something like this: local text = "~HyPeX~ASdasdasd" local size = dxGetTextWidth(text,1,"default") local tSize = 1; if ( size < 100 ) then while ( size < 100 ) do tSize = tSize + 0.5; size = dxGetTextWidth(text,tSize,"default") end elseif ( size > 100 ) then while ( size > 100 ) then tSize = tSize - 0.5; size = dxGetTextWidth(text,tSize,"default") end end outputConsole ( tSize ); Would that work in a clientRender loop, or is it adviced to do it before? Link to comment
JR10 Posted February 14, 2015 Share Posted February 14, 2015 If you don't use onClientRender, whenever the text changes the size won't be updated. Link to comment
.:HyPeX:. Posted February 14, 2015 Author Share Posted February 14, 2015 If you don't use onClientRender, whenever the text changes the size won't be updated. What i was asking was if it was ideal in performance terms, i could add a check to see if the text changes and then do the size update, my question was if it was worth the work. (But i guess not so much since its client side stuff) Link to comment
JR10 Posted February 15, 2015 Share Posted February 15, 2015 The check would be better, but it probably wouldn't be noticeable. Link to comment
.:HyPeX:. Posted February 16, 2015 Author Share Posted February 16, 2015 The check would be better, but it probably wouldn't be noticeable. Great, Thanks! Already tested both, didnt see any difference at all. Link to comment
JR10 Posted February 16, 2015 Share Posted February 16, 2015 You won't because it's a small portion of text and the check is done once per client render. Imagine a scenario with a large string and a loop, this can be costly. 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