local visibleText = {} 
local myFont = dxCreateFont("font.otf", 14) 
addEventHandler ( "onClientRender",root,function() 
        for self,_ in pairs(visibleText) do 
            while true do 
                if self.bDestroyed then 
                    visibleText[self] = nil 
                    break 
                end 
                local l,t,r,b 
                --If we arent using a bounding box 
                if not self.tBoundingBox then 
                    --Decide if we use relative or absolute 
                    local p_screenX,p_screenY = 1,1 
                    if self.bRelativePosition then 
                        p_screenX,p_screenY = g_screenX,g_screenY 
                    end 
                    local fX,fY = (self.fX)*p_screenX,(self.fY)*p_screenY 
                    if self.bHorizontalAlign == "left" then 
                        l = fX 
                        r = fX + g_screenX 
                    elseif self.bHorizontalAlign == "right" then 
                        l = fX - g_screenX 
                        r = fX 
                    else 
                        l = fX - g_screenX 
                        r = fX + g_screenX 
                    end 
                    if self.bVerticalAlign == "top" then 
                        t = fY 
                        b = fY + g_screenY 
                    elseif self.bVerticalAlign == "bottom" then 
                        t = fY - g_screenY 
                        b = fY 
                    else 
                        t = fY - g_screenY 
                        b = fY + g_screenY 
                    end 
                elseif type(self.tBoundingBox) == "table" then 
                    local b_screenX,b_screenY = 1,1 
                    if self.bRelativeBoundingBox then 
                        b_screenX,b_screenY = g_screenX,g_screenY 
                    end 
                    l,t,r,b = self.tBoundingBox[1],self.tBoundingBox[2],self.tBoundingBox[3],self.tBoundingBox[4] 
                    l = l*b_screenX 
                    t = t*b_screenY 
                    r = r*b_screenX 
                    b = b*b_screenY 
                end 
                local type,att1,att2,att3,att4,att5 = self:type() 
                if type == "border" or type == "stroke" then 
                    att2 = att2 or 0 
                    att3 = att3 or 0 
                    att4 = att4 or 0 
                    att5 = att5 or self.tColor[4] 
                    outlinesize = att1 or 2 
                    outlinesize = math.min(self.fScale,outlinesize) --Make sure the outline size isnt thicker than the size of the label 
                    if outlinesize > 0 then 
                        for offsetX=-outlinesize,outlinesize,outlinesize do 
                            for offsetY=-outlinesize,outlinesize,outlinesize do 
                                if not (offsetX == 0 and offsetY == 0) then 
                                    dxDrawText(string.gsub(self.strText, '#%x%x%x%x%x%x', ''), l + offsetX, t + offsetY, r + offsetX, b + offsetY, tocolor(att2, att3, att4, att5), self.fScale, myFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) 
                                end 
                            end 
                        end 
                    end 
                elseif type == "shadow" then 
                    local shadowDist = att1 
                    att2 = att2 or 0 
                    att3 = att3 or 0 
                    att4 = att4 or 0 
                    att5 = att5 or self.tColor[4] 
                    dxDrawText(string.gsub(self.strText, '#%x%x%x%x%x%x', ''), l + shadowDist, t + shadowDist, r + shadowDist, b + shadowDist, tocolor(att2, att3, att4, att5), self.fScale, myFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) 
                end 
                dxDrawColorText ( self.strText, l, t, r, b, tocolor(unpack(self.tColor)), self.fScale, myFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) 
                break 
            end 
        end 
    end 
) 
  
addEvent ( "updateDisplays", true ) then 
addEventHandler ( "updateDisplays", getRootElement(),function(self) 
    setmetatable( self, dxText_mt ) 
    --Remove any old ones with the same id 
    for text,_ in pairs(visibleText) do 
        if text.id == self.id then 
            visibleText[text] = nil 
        end 
    end 
    if self.bVisible and not self.bDestroyed then 
        visibleText[self] = true 
    end 
end) 
  
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