Jump to content

edit box DX


leshikgo

Recommended Posts

Posted

what do you mean with blinking cursor? the one that appears when you're edditing?

you could make it blink with a timer changing the alpha and placing it by dxGetTextWidth.

Greetz

Posted

Came another question. And how to jump the cursor to the input typed text on mouse click and thus determine the index letters in a string? Principle can be in three words, if you do not mind!?

  • MTA Team
Posted

How to jump with the cursor?

Using the position, iterate through the visible text and checking if the delta position is greater or lower than the cursor position.

How to make a blinking caret?

Use that piece of code when drawing the caret line:

tocolor(0, 0, 0, math.abs(math.sin(getTickCount() / 300)) * 200) 

Posted

Note: string.split and table.size are usefull functions

  
local text "My Random generated string of text wich goes long" 
local str = string.split(text) 
local mstr = "" 
local boxStart = x*0.2 
local cursorPosition = x*0.3 
for i=1, table.size(str) do 
mstr = mstr..str[i] 
if cursorPosition <= dxGetTextWidth(mstr, scale, font) + boxStart then 
 -- Found da spot! 
end 
end 
  

You'd still need to do some maths to where to add more characters due to the nature of dxInput, but you can do it from here

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...