Skip to content

Commit

Permalink
refactor(modules/lib): enhance draw text functions for better flexibi…
Browse files Browse the repository at this point in the history
…lity
  • Loading branch information
GoldO-dev authored Nov 5, 2024
1 parent efd9c6a commit 0b7ed08
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions modules/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ else
---@field scale? integer default: `0.35`
---@field font? integer default: `4`
---@field color? vector4 rgba, white by default
---@field enableDropShadow? boolean
---@field enableOutline? boolean

---@class LibDrawText2DParams : LibDrawTextParams
---@field coords vector2
Expand All @@ -341,12 +343,19 @@ else
local color = params.color or vec4(255, 255, 255, 255)
local width = params.width or 1.0
local height = params.height or 1.0
local enableDropShadow = params.enableDropShadow or false
local enableOutline = params.enableOutline or false

SetTextScale(scale, scale)
SetTextFont(font)
SetTextColour(math.floor(color.r), math.floor(color.g), math.floor(color.b), math.floor(color.a))
SetTextDropShadow()
SetTextOutline()
if enableDropShadow then
SetTextDropShadow()
end
if enableOutline then
SetTextOutline()
end

SetTextCentre(true)
BeginTextCommandDisplayText('STRING')
AddTextComponentSubstringPlayerName(text)
Expand All @@ -356,19 +365,31 @@ else
---@class LibDrawText3DParams : LibDrawTextParams
---@field coords vector3
---@field disableDrawRect? boolean
---@field scale? integer | vector2 default: `vec2(0.35,0.35)`

---Draws text onto the screen in 3D space for a single frame.
---@param params LibDrawText3DParams
function qbx.drawText3d(params) -- luacheck: ignore
local isScaleparamANumber = type(params.scale) == "number"
local text = params.text
local coords = params.coords
local scale = params.scale or 0.35
local scale = (isScaleparamANumber and vec2(params.scale, params.scale))
or params.scale
or vec2(0.35, 0.35)
local font = params.font or 4
local color = params.color or vec4(255, 255, 255, 255)
local enableDropShadow = params.enableDropShadow or false
local enableOutline = params.enableOutline or false

SetTextScale(scale, scale)
SetTextScale(scale.x, scale.y)
SetTextFont(font)
SetTextColour(math.floor(color.r), math.floor(color.g), math.floor(color.b), math.floor(color.a))
if enableDropShadow then
SetTextDropShadow()
end
if enableOutline then
SetTextOutline()
end
SetTextCentre(true)
BeginTextCommandDisplayText('STRING')
AddTextComponentSubstringPlayerName(text)
Expand Down

0 comments on commit 0b7ed08

Please sign in to comment.