Jump to content

Problems with your dxDrawColorText-function


Puma

Recommended Posts

My script gets the text from a .txt file (using fileOpen, fileRead). The text:

http://pastebin.com/Q1Z33af6

I put some colorcodes in it and since the colorcoded-bool in dxDrawText only works from 1.3.1 on (and as far as I know, 1.3.1 isn't released yet), I used Aibo's dxDrawColorText-function

https://wiki.multitheftauto.com/wiki/DxDrawColorText

Ingame, it looks like this:

10xhohz.png

Without using dxDrawColorText, just dxDrawText, it looks like this (and this is how it should look):

vybiuq.png

Anyone who got an explanation and/or solution for this problem?

Link to comment
function dxDrawColorText(str, ax, ay, bx, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) 
    if not str then return false end 
    str = " "..str 
    ax= ax - dxGetTextWidth(" ", scale, font) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find(pat, 1) 
    local last = 1 
    while s do 
        if s ~= 1 or cap ~= "" then 
            local w = dxGetTextWidth(cap, scale, font) 
            dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) 
            ax = ax + w 
            color = tocolor(tonumber("0x"..string.sub(col, 1, 2)), tonumber("0x"..string.sub(col, 3, 4)), tonumber("0x"..string.sub(col, 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,alignX,alignY,clip, wordBreak, postGUI) 
    end 
end 

you need edit dxDrawColorText

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