Jump to content

dxDrawText position


PauloCascus

Recommended Posts

Hello, i think this is stupid situation but what i'm doing wrong...

Position of the rectangle and text is the same.. but the text has moved in other on the test. It's not once happend, every time when i've started to write my code, i had this result...

local sw, sh = guiGetScreenSize() 
  
  
function renderMain() 
  addEventHandler("onClientRender", getRootElement(), renderMainButtons) 
  
  
end  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), renderMain)   
  
mainbuttons = { 
{ x = sw * 0.5, y = sh * 0.5, w = sw * 0.2, h = sh * 0.2, text = "Login" } 
} 
  
  
function renderMainButtons() 
  for i, mbut in ipairs ( mainbuttons ) do  
    dxDrawRectangle( mbut.x, mbut.y, mbut.w, mbut.h ) 
    if mbut.text then  
      dxDrawText( mbut.text, mbut.x, mbut.y, mbut.w, mbut.h, tocolor(0, 0, 0), sw/1600, "bankgothic", "center", "center") 
    end 
  end 
end 

e10df4afcdcb3f150159da57c32074aa.png

Link to comment
  • Moderators

Hi,

The problem is that dxDrawText is not waiting for a size at the 4th and 5th argument, but its expecting for the absolute coordinate of the bottom right corner of the box in which it will write the text.

* right: the absolute X coordinate of the right side of the text bounding box. Used for text aligning, clipping and word breaking.

* bottom: the absolute Y coordinate of the bottom side of the text bounding box. Used for text aligning, clipping and word breaking.

So here is what you should write instead:

dxDrawText( mbut.text, mbut.x, mbut.y, mbut.x + mbut.w, mbut.y + mbut.h, tocolor(0, 0, 0), sw/1600, "bankgothic", "center", "center") 

It should work as expected.

Regards,

Citizen

Link to comment
Hi,

The problem is that dxDrawText is not waiting for a size at the 4th and 5th argument, but its expecting for the absolute coordinate of the bottom right corner of the box in which it will write the text.

* right: the absolute X coordinate of the right side of the text bounding box. Used for text aligning, clipping and word breaking.

* bottom: the absolute Y coordinate of the bottom side of the text bounding box. Used for text aligning, clipping and word breaking.

So here is what you should write instead:

dxDrawText( mbut.text, mbut.x, mbut.y, mbut.x + mbut.w, mbut.y + mbut.h, tocolor(0, 0, 0), sw/1600, "bankgothic", "center", "center") 

It should work as expected.

Regards,

Citizen

yeah, it's working. Thanks

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