DxDrawText: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 31: Line 31:
==Example==  
==Example==  
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
This is a example code will add Zone Names in the lower left corner of players screen.
This example code will add Zone Names in the lower left corner of player's screens.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local rootElement = getRootElement()
local rootElement = getRootElement()
local x,y = guiGetScreenSize() -- Get players resolution
local screenWidth, screenHeight = guiGetScreenSize() -- Get the screen resolution




function createText ( )
function createText ( )
local playerX, playerY, playerZ = getElementPosition( getLocalPlayer() )  -- Get players coordinates.
    local playerX, playerY, playerZ = getElementPosition( getLocalPlayer() )  -- Get player's coordinates.
local PlayerZoneName =  getZoneName( playerX, playerY, playerZ ) -- Get name of the players zone.
    local playerZoneName =  getZoneName( playerX, playerY, playerZ )         -- Get name of the player's zone.


dxDrawText( PlayerZoneName, 44, y-41, x, y, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" )    -- Draw Zone Name text shadow.
    dxDrawText( playerZoneName, 44, screenHeight-41, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" )    -- Draw Zone Name text shadow.
dxDrawText( PlayerZoneName, 44, y-43, x, y, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" ) -- Draw Zone Name text.
    dxDrawText( playerZoneName, 44, screenHeight-43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" ) -- Draw Zone Name text.
end
end



Revision as of 18:55, 15 March 2008

Draws a string of text on the screen for one frame. In order for the text to stay visible continuously, you need to call this function with the same parameters on each frame update (see onClientRender).

Syntax

bool dxDrawText ( string text, int left, int top [, int right=left, int bottom=top, int color=white, float scale=1, string font="default", string alignX="left", string alignY="top", bool clip=false, bool wordBreak=false] )

Required Arguments

  • text: the text to draw
  • left: the absolute X coordinate of the top left corner of the text
  • top: the absolute Y coordinate of the top left corner of the text

Optional Arguments

  • 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.
  • color: the color of the text, a value produced by tocolor.
  • scale: the size of the text.
  • font: the dx font to use.
    • "default": Tahoma
    • "default-bold": Tahoma Bold
    • "clear": Verdana
    • "arial": Arial
    • "sans": Microsoft Sans Serif
    • "pricedown": Pricedown (GTA's theme text)
    • "bankgothic": Bank Gothic Medium
    • "diploma": Diploma Regular
    • "beckett": Beckett Regular
    • "unifont": Unifont
  • alignX: horizontal alignment of the text within the bounding box. Can be "left", "center" or "right".
  • alignY: vertical alignment of the text within the bounding box. Can be "top", "center" or "bottom".
  • clip: if set to true, the parts of the text that don't fit within the bounding box will be cut off.
  • wordBreak: if set to true, the text will wrap to a new line whenever it reaches the right side of the bounding box. If false, the text will always be completely on one line.

Returns

Returns true if successful, false otherwise.

Example

Click to collapse [-]
Client

This example code will add Zone Names in the lower left corner of player's screens.

local rootElement = getRootElement()
local screenWidth, screenHeight = guiGetScreenSize() -- Get the screen resolution


function createText ( )
    local playerX, playerY, playerZ = getElementPosition( getLocalPlayer() )  -- Get player's coordinates.
    local playerZoneName =  getZoneName( playerX, playerY, playerZ )          -- Get name of the player's zone.

    dxDrawText( playerZoneName, 44, screenHeight-41, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" )    -- Draw Zone Name text shadow.
    dxDrawText( playerZoneName, 44, screenHeight-43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" ) -- Draw Zone Name text.
end


function HandleTheRendering()
    addEventHandler("onClientRender",rootElement, createText) -- keep the text visible with onClientRender.
end
addEventHandler("onClientResourceStart",rootElement, HandleTheRendering)

See Also