DxDrawRectangle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(12 intermediate revisions by 8 users not shown)
Line 2: Line 2:
{{Client function}}  
{{Client function}}  
This function draws a 2D rectangle across the screen - rendered for '''one''' frame. This should be used in conjunction with [[onClientRender]] in order to display continuously.  
This function draws a 2D rectangle across the screen - rendered for '''one''' frame. This should be used in conjunction with [[onClientRender]] in order to display continuously.  


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool dxDrawRectangle ( int startX, startY, float width, float height [, int color = white] )
bool dxDrawRectangle ( float startX, float startY, float width, float height [, int color = white, bool postGUI = false, bool subPixelPositioning = false ] )
</syntaxhighlight>
</syntaxhighlight>


===Required Arguments===  
===Required Arguments===  
* '''startX:''' An integer representing the '''absolute''' origin X position of the rectangle, represented by pixels on the screen.
* '''startX:''' An float representing the '''absolute''' origin X position of the rectangle, represented by pixels on the screen.
* '''startY:''' An integer representing the '''absolute''' origin Y position of the rectangle, represented by pixels on the screen.
* '''startY:''' An float representing the '''absolute''' origin Y position of the rectangle, represented by pixels on the screen.
* '''width:''' An float representing the width of the rectangle, drawn in a ''right'' direction from the origin.
* '''width:''' An float representing the width of the rectangle, drawn in a ''right'' direction from the origin.
* '''height:''' An float representing the height of the rectangle, drawn in a ''downwards'' direction from the origin.
* '''height:''' An float representing the height of the rectangle, drawn in a ''downwards'' direction from the origin.


===Optional Arguments===
===Optional Arguments===
*'''color:''' the color of the rectangle.
*'''color:''' the hex color of the rectangle, produced using [[tocolor]] or 0xAARRGGBB (AA = alpha, RR = red, GG = green, BB = blue).
* '''postGUI:''' A bool representing whether the line should be drawn on top of or behind any ingame GUI.
{{New feature/item|9.06931|1.4.0|6931|
*'''subPixelPositioning:''' A bool representing whether the rectangle can be positioned sub-pixel-ly.
}}


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


==Example==  
==Example==  
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
Example of MOTD (message of the day), made using DxText, Line and Rectangle.
Example of MOTD (message of the day), made using DxDrawText, -Line and -Rectangle.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local rootElement = getRootElement()
local x,y = guiGetScreenSize()  -- Get players resolution.
local x,y = guiGetScreenSize()  -- Get players resolution.
local playerName = getPlayerName ( getLocalPlayer() )  -- Get players name.
local playerName = getPlayerName ( localPlayer )  -- Get players name.
local MOTDText = "Welcome to our server, this is a test MOTD script for MTA's Wiki."  -- Example of MOTD message.
local MOTDText = "Welcome to our server, this is a test MOTD script for MTA's Wiki."  -- Example of MOTD message.


 
function drawStuff()
function create2DRectangle ( )
dxDrawRectangle ( x/3.8, y/3.8, x/2.02, y/2, tocolor ( 0, 0, 0, 150 ) ) -- Create our black transparent MOTD background Rectangle.
dxDrawRectangle ( x/2/2, y/2/2, x/2+40, y/2+40, tocolor ( 0, 0, 0, 150 ) ) -- Create our black MOTD background Rectangle.
dxDrawText ( "Welcome " .. playerName, x/3.5, y/3.6, x, y, tocolor ( 255, 255, 255, 255 ), 1, "bankgothic" ) -- Create Welcome title.
 
        dxDrawText ( "Welcome " .. playerName, x/3.48, y/3.58, x, y, tocolor ( 0, 0, 0, 255 ), 1, "bankgothic" ) -- Create Welcome title shadow.
dxDrawText( "Welcome " .. playerName, x/2/2+41, y/2/2+32, x, y, tocolor ( 0, 0, 0, 255 ), 1.01, "pricedown" ) -- Create Welcome title shadow.
dxDrawLine ( x/3.6, y/3.3, x/1.35, y/3.3, tocolor ( 255, 255, 255, 255 ), 2 ) -- Create underline for title.
dxDrawText( "Welcome " .. playerName, x/2/2+40, y/2/2+30, x, y, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" ) -- Create Welcome title.
dxDrawLine ( x/3.59, y/3.275, x/1.348, y/3.275, tocolor ( 0, 0, 0, 255 ), 2 ) -- Create underline shadow.
dxDrawLine ( x/2/2+20, y/2/2+57, x/2/2+y/2+332, y/2/2+57, tocolor ( 0, 0, 0, 255 ), 3 ) -- Create underline shadow for title.
dxDrawText ( MOTDText, x/3.6, y/3, x, y, tocolor ( 255, 255, 255, 255 ), 1, "clear" ) -- Create MOTD text.
dxDrawLine ( x/2/2+20, y/2/2+55, x/2/2+y/2+330, y/2/2+55, tocolor ( 255, 255, 255, 255 ), 2 ) -- Create underline for title.
dxDrawText( MOTDText, x/2/2+40, y/2/2+80, x, y, tocolor ( 255, 255, 255, 255 ), 1, "clear" ) -- Create MOTD text.
end
end


 
addEventHandler("onClientRender", root, drawStuff)  -- Keep everything visible with onClientRender.
function HandleTheRendering()
addEventHandler("onClientRender",rootElement, create2DRectangle)  -- Keep everything visible with onClientRender.
end
addEventHandler("onClientResourceStart",rootElement, HandleTheRendering)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
==Changelog==
{{ChangelogHeader}}
{{ChangelogItem|1.4.0-9.06931|Added subPixelPositioning argument}}


==See Also==
==See Also==
{{Drawing_functions}}
{{Drawing_functions}}
[[Category:Needs_Example]]
 
[[hu:dxDrawRectangle]]

Latest revision as of 17:16, 26 October 2018

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

Syntax

bool dxDrawRectangle ( float startX, float startY, float width, float height [, int color = white, bool postGUI = false, bool subPixelPositioning = false ] )

Required Arguments

  • startX: An float representing the absolute origin X position of the rectangle, represented by pixels on the screen.
  • startY: An float representing the absolute origin Y position of the rectangle, represented by pixels on the screen.
  • width: An float representing the width of the rectangle, drawn in a right direction from the origin.
  • height: An float representing the height of the rectangle, drawn in a downwards direction from the origin.

Optional Arguments

  • color: the hex color of the rectangle, produced using tocolor or 0xAARRGGBB (AA = alpha, RR = red, GG = green, BB = blue).
  • postGUI: A bool representing whether the line should be drawn on top of or behind any ingame GUI.
ADDED/UPDATED IN VERSION 1.4.0 r6931:
  • subPixelPositioning: A bool representing whether the rectangle can be positioned sub-pixel-ly.

Returns

Returns true if the operation was successful, false otherwise.

Example

Click to collapse [-]
Client

Example of MOTD (message of the day), made using DxDrawText, -Line and -Rectangle.

local x,y = guiGetScreenSize()  -- Get players resolution.
local playerName = getPlayerName ( localPlayer )  -- Get players name.
local MOTDText = "Welcome to our server, this is a test MOTD script for MTA's Wiki."  -- Example of MOTD message.

function drawStuff()
	dxDrawRectangle ( x/3.8, y/3.8, x/2.02, y/2, tocolor ( 0, 0, 0, 150 ) ) -- Create our black transparent MOTD background Rectangle.
	dxDrawText ( "Welcome " .. playerName, x/3.5, y/3.6, x, y, tocolor ( 255, 255, 255, 255 ), 1, "bankgothic" ) -- Create Welcome title.
        dxDrawText ( "Welcome " .. playerName, x/3.48, y/3.58, x, y, tocolor ( 0, 0, 0, 255 ), 1, "bankgothic" ) -- Create Welcome title shadow.
	dxDrawLine ( x/3.6, y/3.3, x/1.35, y/3.3, tocolor ( 255, 255, 255, 255 ), 2 ) -- Create underline for title.
	dxDrawLine ( x/3.59, y/3.275, x/1.348, y/3.275, tocolor ( 0, 0, 0, 255 ), 2 ) -- Create underline shadow.
	dxDrawText ( MOTDText, x/3.6, y/3, x, y, tocolor ( 255, 255, 255, 255 ), 1, "clear" ) -- Create MOTD text.
end

addEventHandler("onClientRender", root, drawStuff)  -- Keep everything visible with onClientRender.

Changelog

Version Description
1.4.0-9.06931 Added subPixelPositioning argument

See Also