Jump to content

[Help] DX Centering


ShayF2

Recommended Posts

I want to center the dx elements in a certain space via math with text length and max text length. Here is my code as well as a picture to show its status.
 

local messagesList = {
	'----------- Coming Soon!',
	'Visit the site! http://---------/',
	'Let your voice be heard! http://---------/forum/',
	'READ F9!'
}
local sx,sy = guiGetScreenSize()
local sw,sh = 1360,768
local currentMessage = 1

function dxRect(...)
	arg[1],arg[2],arg[3],arg[4] = arg[1]/sw*sx,arg[2]/sh*sy,arg[3]/sw*sx,arg[4]/sh*sy
	return dxDrawRectangle(unpack(arg))
end

function dxText(...)
	arg[2],arg[3],arg[4],arg[5],arg[7] = arg[2]/sw*sx,arg[3]/sh*sy,(arg[4]+arg[2])/sw*sx,(arg[5]+arg[3])/sh*sy,(arg[7] or 1)/sw*sx
	return dxDrawText(unpack(arg))
end

addEventHandler('onClientPreRender',root,function()
	local width = dxGetTextWidth(messagesList[currentMessage])
	dxRect(1068-8,107,width+16,21,tocolor(0,0,0,192),false)
	dxText(messagesList[currentMessage],1068,107,width,21,tocolor(0,255,255,255),1,'default-bold','center','center',false,false,false)
end)

setTimer(function()
	if currentMessage ~= #messagesList then
		currentMessage = currentMessage+1
	else
		currentMessage = 1
	end
end,5000,0)

5XVtAKD.jpg

Link to comment

Give me a second.

addEventHandler('onClientPreRender',root,function()
	local width = dxGetTextWidth(messagesList[currentMessage])
	dxRect(1068-8-width/2,250,width+16,21,tocolor(0,0,0,192),false)
	dxText(messagesList[currentMessage],1068-width/2,250,width,21,tocolor(0,255,255,255),1,'default-bold','center','center',false,false,false)
end)

This'll be centered at 1068-8.

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