DxDrawLine: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ <!-- Describe in plain english what this function does. Don't go into details, just give an overview --> This fake function is for use with blah & blah and does blahblahblabhalb...)
 
m (lua boi)
 
(19 intermediate revisions by 13 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
{{Client function}}
This fake function is for use with blah & blah and does blahblahblabhalbhl
This function draws a 2D line across the screen - rendered for '''one''' frame.  This should be used in conjunction with [[onClientRender]] in order to display continuously.


==Syntax==  
==Syntax==
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
returnType functionName ( arguments )
bool dxDrawLine ( int startX, int startY, int endX, int endY, int color [, float width = 1.0, bool postGUI = false ] )
</syntaxhighlight>  
</syntaxhighlight>


===Required Arguments===  
===Required Arguments===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
* '''startX:''' An integer representing the '''absolute''' start X position of the line, represented by pixels on the screen.
*'''argumentName:''' description
* '''startY:''' An integer representing the '''absolute''' start Y position of the line, represented by pixels on the screen.
* '''endX:''' An integer representing the '''absolute''' end X position of the line, represented by pixels on the screen.
* '''endY:''' An integer representing the '''absolute''' end Y position of the line, represented by pixels on the screen.
* '''color:''' An integer of the hex color, produced using [[tocolor]] or 0xAARRGGBB (AA = alpha, RR = red, GG = green, BB = blue).


<!-- Only include this section below if there are optional arguments -->
==Optional Arguments==
===Optional Arguments===  
{{OptionalArg}}
{{OptionalArg}}  
* '''width:''' The width/thickness of the line
*'''argumentName2:''' description
* '''postGUI:''' A bool representing whether the line should be drawn on top of or behind any ingame GUI (rendered by CEGUI).
*'''argumentName3:''' description


===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns a true if the operation was successful, false otherwise.  
Returns ''true'' if blah, ''false'' otherwise.


==Example==  
==Example==
<!-- Explain what the example is in a single sentance -->
This example draws an 'X' across the screen.
This example does...
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
local screenWidth, screenHeight = guiGetScreenSize()
blabhalbalhb --abababa
local lineColor = tocolor(255, 0, 0)
--This line does this...
function drawLinesAcrossScreen()
mooo
dxDrawLine(0, 0, screenWidth, screenHeight, lineColor)
dxDrawLine(screenWidth, 0, 0, screenHeight, lineColor)
end
addEventHandler("onClientRender", root, drawLinesAcrossScreen)
</syntaxhighlight>
</syntaxhighlight>


This example draws a couple of circles
<syntaxhighlight lang="lua">
function drawCircle( x,y, radius, color )
    local numPoints = math.floor( math.pow( radius, 0.4 ) * 5 )    -- Calculate number of points to make it look good
    local step = math.pi * 2 / numPoints
    local sx,sy
    for p=0,numPoints do
        local ex = math.cos ( p * step ) * radius
        local ey = math.sin ( p * step ) * radius
        if sx then
            dxDrawLine( x+sx, y+sy, x+ex, y+ey, color )
        end
        sx,sy = ex,ey
    end
end
addEventHandler( "onClientRender", root,
    function()
        drawCircle( 350, 350, 10, tocolor(255,0,255) )
        drawCircle( 350, 350, 50, tocolor(255,0,255) )
    end
)
</syntaxhighlight>
==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{Drawing_functions}}
{{FunctionArea_functions}}
 
[[Category:Incomplete]]
[[hu:dxDrawLine]]

Latest revision as of 01:00, 8 April 2022

This function draws a 2D line across the screen - rendered for one frame. This should be used in conjunction with onClientRender in order to display continuously.

Syntax

bool dxDrawLine ( int startX, int startY, int endX, int endY, int color [, float width = 1.0, bool postGUI = false ] )

Required Arguments

  • startX: An integer representing the absolute start X position of the line, represented by pixels on the screen.
  • startY: An integer representing the absolute start Y position of the line, represented by pixels on the screen.
  • endX: An integer representing the absolute end X position of the line, represented by pixels on the screen.
  • endY: An integer representing the absolute end Y position of the line, represented by pixels on the screen.
  • color: An integer of the hex color, produced using tocolor or 0xAARRGGBB (AA = alpha, RR = red, GG = green, BB = blue).

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • width: The width/thickness of the line
  • postGUI: A bool representing whether the line should be drawn on top of or behind any ingame GUI (rendered by CEGUI).

Returns

Returns a true if the operation was successful, false otherwise.

Example

This example draws an 'X' across the screen.

local screenWidth, screenHeight = guiGetScreenSize() 
local lineColor = tocolor(255, 0, 0)
function drawLinesAcrossScreen()
	dxDrawLine(0, 0, screenWidth, screenHeight, lineColor)
	dxDrawLine(screenWidth, 0, 0, screenHeight, lineColor)
end
addEventHandler("onClientRender", root, drawLinesAcrossScreen)

This example draws a couple of circles

function drawCircle( x,y, radius, color )
    local numPoints = math.floor( math.pow( radius, 0.4 ) * 5 )     -- Calculate number of points to make it look good
    local step = math.pi * 2 / numPoints
    local sx,sy
    for p=0,numPoints do
        local ex = math.cos ( p * step ) * radius
        local ey = math.sin ( p * step ) * radius
        if sx then
            dxDrawLine( x+sx, y+sy, x+ex, y+ey, color )
        end
        sx,sy = ex,ey
    end
end

addEventHandler( "onClientRender", root,
    function()
        drawCircle( 350, 350, 10, tocolor(255,0,255) )
        drawCircle( 350, 350, 50, tocolor(255,0,255) )
    end
)

See Also