Jump to content

Окрас отдельной части dxDrawText


N1kS

Recommended Posts

dxDrawText(team1NameC.." "..team1ScoreC.." : "..team2ScoreC.." "..team2NameC, textWidth/2.1 - 65, textGeight/25, textPosRight, textPosBottom, tocolor(255, 0, 0, 255), scale, "default-bold") 

Собственно вот так выводиться текст, нужно окрасить цвет команд в разные цвета, возможно ли это сделать? Да, возможен вариант создания 3 отдельных текстов, но так всплывают некоторые баги.

Link to comment

Не то чтобы возможен, а обязателен (: вариант из нескольких dxDrawText, потому что для одной прорисовки только 1 цвет/ На форуме даже есть функция, которая разбивает текст согласно HEX цветам, найденным в строке текста, и рисует текст несколькими dxDrawText

нашел..

function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY) 
  if alignX then 
    if alignX == "center" then 
      local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) 
      ax = ax + (bx-ax)/2 - w/2 
    elseif alignX == "right" then 
      local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) 
      ax = bx - w 
    end 
  end 
  
  if alignY then 
    if alignY == "center" then 
      local h = dxGetFontHeight(scale, font) 
      ay = ay + (by-ay)/2 - h/2 
    elseif alignY == "bottom" then 
      local h = dxGetFontHeight(scale, font) 
      ay = by - h 
    end 
  end 
  
  local pat = "(.-)#(%x%x%x%x%x%x)" 
  local s, e, cap, col = str:find(pat, 1) 
  local last = 1 
  while s do 
    if cap == "" and col then color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) end 
    if s ~= 1 or cap ~= "" then 
      local w = dxGetTextWidth(cap, scale, font) 
      dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
      ax = ax + w 
      color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) 
    end 
    last = e + 1 
    s, e, cap, col = str:find(pat, last) 
  end 
  if last <= #str then 
    cap = str:sub(last) 
    local w = dxGetTextWidth(cap, scale, font) 
    dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
  end 
end 

Link to comment

Прочтите внимательно мое первое сообщение. 3 текста должны быть рядом. И когда содержание первого текста длинное, то он налезает на след. текст.

Link to comment

Это то понятно, но какая переменная отвечает за текст и его цвет? Простите, за глупый вопрос. Вроде бы не 0 в LUA, а банальных вещей не вижу.

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