Jump to content

Borders in dxDrawText


Recommended Posts

Hello guys, I'm trying to do a HUD, but i got a little problem. I don't know how to add borders in Texts.

I'll show you some images:

I tried to do borders putting behind another dxdrawtext:

hudwithbadborders.jpg

It looks like this without borders:

hudwithoutborders.jpg

I want something like this:

perfectborders.jpg

Here's my simple code:

  
        dxDrawText(tostring (inclip),sWidth-414,sHeight-47,sWidth-369,sHeight-18,tocolor(127,127,127,255),1.0,"pricedown") 
        dxDrawText(tostring (ammo2),sWidth-375,sHeight-47,sWidth-272,sHeight-12,tocolor(255,255,255,255),1.0,"pricedown") 
  

Sorry for my bad english, I'm still learning.

Link to comment

well border is just the same text (usually black colored) 1-2 pixels to the right, then another one to the left, upwards and downwards of the original text

Borders come first as dxDrawTexts (since they're black) and the original text is the last one to be drawn (so it appears on top of the rest)

dxDrawText(--black colored, 2 pixels down from original text position--)

dxDrawText(--black colored, 2 pixels up from original text position--)

dxDrawText(--black colored, 2 pixels to the right from original text position--)

dxDrawText(--black colored, 2 pixels to the left from original text position --)

dxDrawText(--original text parameters--)

4 dxDraws for the border, 1 for the original text.

Hope I helped.

There's another way (simplier too). Check this out:

viewtopic.php?f=108&t=24262&hilit=textlib

Link to comment

As the guy above said, you can use textlib, but his manual way is incorrect and lacks some accuracy.

The correct way:

  
dxDrawText ( "a", 100 - 1, 100 - 1, 100 - 1, 100 - 1, tocolor ( 0, 0, 0, 255 ) ) -- black 
dxDrawText ( "a", 100 + 1, 100 - 1, 100 + 1, 100 - 1, tocolor ( 0, 0, 0, 255 ) ) 
dxDrawText ( "a", 100 - 1, 100 + 1, 100 - 1, 100 + 1, tocolor ( 0, 0, 0, 255 ) ) 
dxDrawText ( "a", 100 + 1, 100 + 1, 100 + 1, 100 + 1, tocolor ( 0, 0, 0, 255 ) ) 
dxDrawText ( "a", 100 - 1, 100, 100 - 1, 100, tocolor ( 0, 0, 0, 255 ) ) 
dxDrawText ( "a", 100 + 1, 100, 100 + 1,100, tocolor ( 0, 0, 0, 255 ) ) 
dxDrawText ( "a", 100, 100 - 1, 100, 100 - 1, tocolor ( 0, 0, 0, 255 ) ) 
dxDrawText ( "a", 100, 100 + 1, 100, 100 + 1, tocolor ( 0, 0, 0, 255 ) ) 
dxDrawText ( "a", 100, 100, 100, 100, tocolor ( 255, 255, 255, 255 ) ) -- white 
  

Link to comment
function dxDrawBorderedText(text, left, top, right, bottom, color, scale, font, alignX, alignY, clip, wordBreak,postGUI) 
    for oX = -1, 1 do -- Border size is 1 
        for oY = -1, 1 do -- Border size is 1 
                dxDrawText(text, left + oX, top + oY, right + oX, bottom + oY, tocolor(0, 0, 0, 255), scale, font, alignX, alignY, clip, wordBreak,postGUI) 
        end 
    end 
    dxDrawText(text, left, top, right, bottom, color, scale, font, alignX, alignY, clip, wordBreak, postGUI) 
end 

  • Like 1
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...