Jump to content

[REL] Textlib: Create dxText easily


Recommended Posts

Textlib is a library i wrote to make creation of dxText much easier, while also allowing it to be flexible. It's what i used for my Dance resource (in the MTA vid) to create the text. It makes stuff like shadowed and stroked text a breeze and generally gets rid of the hassle. It also includes an extension for arc's client_anim library to make text animation easy.

* By default, Textlib creates centred aligned text and is positioned like serverside textdisplays for maximum simplicity.

* if you need to use wordwrap, you will require the use of boundingBox function. This overrides the "position" setting, and sets a bounding box for the text to be wrapped under.

* Wordwrap is enabled by default as long as you add a bounding box.

* To remove bounding box, use text:boundingBox(false) and it will restore to default positioning using "position" setting.

* Make sure you remove any variables that contain references to destroyed text, i.e. "myText = nil"

* Scale,font,postGUI,clip parameters mimic dxDrawText

* There is a single bug that i know of. "bottom" aligned text does not support multiple lines - wordwrapped or \n'd.

* All functions, besides create and destroy, return the current set values if you pass invalid or no arguments, e.g. x,y = text:position()

dxText:create( text, x, y, [relative = true ]) --Create dxText 
  
dxText:text( text ) -- Change text 
  
dxText:position(x,y, [relative = true]) -- Change position 
  
dxText:color(r,g,b,[a]) -- Change color 
  
dxText:scale(scale) -- Set text scale 
  
dxText:visible(bool) -- Make visible or invisible 
  
dxText:destroy() -- Delete the dxtext, stop drawing it 
  
dxText:font(font) -- Change the dxtext font 
  
dxText:postGUI(bool) -- Change whether the text should be drawn on top of or behind any ingame GUI (rendered by CEGUI) 
  
dxText:clip(bool) -- if set to true, the parts of the text that don't fit within the bounding box will be cut off 
  
dxText:wordWrap(bool) --if set to true, the text will wrap to a new line whenever it reaches the right side of the bounding box.   
  
--Set normal, shadow, or border to your texts 
dxText:type("normal") --No border/shadow 
  
dxText:type("shadow",shadowDist, [r = 0, g = 0, b = 0, a = mainTextAlpha])  -- A shadow of color rgba 
  
dxText:type("border", [borderSize = 2, r = 0, g = 0, b = 0, a = mainTextAlpha]) -- A border (aka stroke) of rgba 
  
dxText:align(horzA, [vertA = currentVertAlign])  -- "center,left,right","center,top,bottom" 
  
  
dxText:boundingBox(left,top,right,bottom, [relative = true]) 
  
dxText:sync([player = getRootElement()]) --SERVERSIDE ONLY! 

http://dan.bastage.net/mta/textlib.zip

Link to comment
  • 2 weeks later...
  • 1 month later...
  • 7 months later...
  • 1 year later...

Edit: Silly error on my part.

Example usage:

test = dxText:create( "1234567890", x/2, y/2, false) 
test:scale(3.0) 
test:text( "0123456789" ) 
test:font("default") 
test:color(149,176,209) 
test:type("border", 1.1, 0, 0, 0 ) 

If you just want the borders/shadow styles here is adapted code from the script:

 addEventHandler ( "onClientRender", root, function() 
local x, y = guiGetScreenSize() 
x = x / 2 
y = y / 2 
textSizeage = 8 
l,t,r,b = x,y,x,y 
  
--Background border 
outlinesize = att1 or 8 
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("ABCDEFG", l + offsetX, t + offsetY, r + offsetX, b + offsetY, tocolor(0,0,0), textSizeage, "default", "center", "center" ) 
            end 
        end 
    end 
end 
  
--Background shadow 
-- local shadowDist = 6 
-- dxDrawText("ABCDEFG", l + shadowDist, t + shadowDist, r + shadowDist, b + shadowDist, tocolor(0,0,0), textSizeage, "default", "center", "center" ) 
  
  
dxDrawText ( "ABCDEFG", l, t, r, b, tocolor(149,176,209), textSizeage, "default", "center", "center" ) 

Link to comment
  • 4 months later...

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