laserlaser Posted August 23, 2013 Share Posted August 23, 2013 Hi, I have edit Aibo's DrawColorText 1.5 years ago. function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY,clip,wordBreak,postGUI) --local maxWidth = bx-ax local strAdded = 0 if str:sub(1,1) ~= " " then str = " "..str strAdded = 1 end 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 -- maxWidth = bx-ax elseif alignX == "right" then local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) ax = bx - w -- maxWidth = bx-ax 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 f = 1 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) --if (w > maxWidth) then -- w = maxWidth --end --maxWidth = maxWidth-w if (f == 1) and strAdded == 1 then cap = cap:sub(2) f = f+1 end if not clip then clip = false end if not wordBreak then wordBreak = false end if not postGUI then postGUI = false end dxDrawText(cap, ax, ay, ax+w, by, color, scale, font,"left","top",clip,wordBreak,postGUI) 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) --if (w > maxWidth) then -- w = maxWidth --end --maxWidth = maxWidth-w if not clip then clip = false end if not wordBreak then wordBreak = false end if not postGUI then postGUI = false end if ( f == 1) and strAdded==1 then cap = cap:sub(2) end f = f+1 dxDrawText(cap, ax, ay, ax+w, by, color, scale, font,"left","top",clip,wordBreak,postGUI) end end I noticed now, It doesn't work OMFG! Where is the problem? Link to comment
Castillo Posted August 23, 2013 Share Posted August 23, 2013 Why are you using that? dxDrawText supports HEX codes by default now. Link to comment
laserlaser Posted August 24, 2013 Author Share Posted August 24, 2013 Why are you using that? dxDrawText supports HEX codes by default now. It's old project And 'colorCoded: Set to true to enable embedded #FFFFFF color codes. Note: clip and wordBreak are forced false if this is set.' I want to use colored text with 'clip' property. Link to comment
MIKI785 Posted August 24, 2013 Share Posted August 24, 2013 Just read the wiki... https://wiki.multitheftauto.com/wiki/DxDrawColorText, it says: It works the same as dxDrawText, except clipping and word-wrapping (not implemented yet). Link to comment
laserlaser Posted August 24, 2013 Author Share Posted August 24, 2013 Just read the wiki... https://wiki.multitheftauto.com/wiki/DxDrawColorText, it says: It works the same as dxDrawText, except clipping and word-wrapping (not implemented yet). I think you should just read the my first message. It says: 'I have edit Aibo's DrawColorText 1.5 years ago.' 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