Resource:Blur box: Difference between revisions
No edit summary |
|||
Line 1: | Line 1: | ||
{{Resource page}} | |||
This resource lets You create simple gaussian blur boxes onClientRender. | |||
Using that - You can make your game GUI a bit more fancy. | |||
== Overview == | |||
It is easy to use, gives a few options to manage blur boxes. | |||
The resource itself adds exported clientside functions: | |||
==Exported functions== | |||
====createBlurBox==== | |||
<section name="Client" class="client" show="true"> | |||
This function creates a blur box. | |||
<syntaxhighlight lang="lua">bool exports.blur_box:createBlurBox(float posX,posY,sizeX,sizeY,int colorR,colorG,colorB,colorA,postGUI)</syntaxhighlight> | |||
===Required Arguments=== | |||
*'''float posX, posY:''' Position in screen space. | |||
*'''float sizeX, sizeY:''' Size of the box. | |||
*'''int colorR,colorG,colorB,colorA:''' RGBA color (0 - 255). | |||
*'''bool postGUI:''' Should the box be drawn before or after MTA GUI elements. | |||
===Returns=== | |||
The function returns the element if set successfully, 'false' otherwise. | |||
</section> | |||
====destroyBlurBox==== | |||
<section name="Client" class="client" show="true"> | |||
This function destroys a blur box element. | |||
<syntaxhighlight lang="lua">bool exports.blur_box:destroyBlurBox(element blurBoxElement)</syntaxhighlight> | |||
===Required Arguments=== | |||
*'''element blurBoxElement:''' A previously declared blur box element. | |||
===Returns=== | |||
The function returns true if set successfully, false otherwise. | |||
</section> | |||
====setBlurBoxEnabled==== | |||
<section name="Client" class="client" show="true"> | |||
This function enables or disables a created blur box element. | |||
<syntaxhighlight lang="lua">bool exports.blur_box:setBlurBoxEnabled(element blurBoxElement, bool isEnabled)</syntaxhighlight> | |||
===Required Arguments=== | |||
*'''element blurBoxElement:''' A previously declared blur box element. | |||
*'''bool isEnabled:''' Enable/Disable the blur box element. | |||
===Returns=== | |||
The function returns true if set successfully, false otherwise. | |||
</section> | |||
====setBlurBoxPosition==== | |||
<section name="Client" class="client" show="true"> | |||
This function sets blur box position. | |||
<syntaxhighlight lang="lua">bool exports.blur_box:setBlurBoxPosition(element blurBoxElement,float posX,posY)</syntaxhighlight> | |||
===Required Arguments=== | |||
*'''element blurBoxElement:''' A previously declared blur box element. | |||
*'''float posX, posY:''' Position in screen space. | |||
===Returns=== | |||
The function returns true if set successfully, false otherwise. | |||
</section> | |||
====setBlurBoxSize==== | |||
<section name="Client" class="client" show="true"> | |||
This function sets blur box width and height. | |||
<syntaxhighlight lang="lua">bool exports.blur_box:setBlurBoxSize(element blurBoxElement,float sizeX,sizeY)</syntaxhighlight> | |||
===Required Arguments=== | |||
*'''element blurBoxElement:''' A previously declared blur box element. | |||
*'''float sizeX,sizeY:''' Size of the blur box. | |||
===Returns=== | |||
The function returns true if set successfully, false otherwise. | |||
</section> | |||
====setBlurBoxColor==== | |||
<section name="Client" class="client" show="true"> | |||
This function sets blur box color values. | |||
<syntaxhighlight lang="lua">bool exports.blur_box:setBlurBoxColor(element blurBoxElement,float colorR,colorG,colorB,colorA)</syntaxhighlight> | |||
===Required Arguments=== | |||
*'''element blurBoxElement:''' A previously declared blur box element. | |||
*'''float colorR,colorG,colorB,colorA:''' RGBA color (0 - 255). | |||
===Returns=== | |||
The function returns true if set successfully, false otherwise. | |||
</section> | |||
====setBlurIntensity==== | |||
<section name="Client" class="client" show="true"> | |||
This function sets blur amount for all the blur boxes | |||
<syntaxhighlight lang="lua">bool exports.blur_box:setBlurIntensity(float blurFactor)</syntaxhighlight> | |||
===Required Arguments=== | |||
*'''float blurFactor:''' Set blur amount for all the blur boxes. (default 0.6) | |||
===Returns=== | |||
The function returns true if set successfully, false otherwise. | |||
</section> | |||
====setScreenResolutionMultiplier==== | |||
<section name="Client" class="client" show="true"> | |||
This function sets screen relative resolution multiplier for the screenSource | |||
<syntaxhighlight lang="lua">bool exports.blur_box:setScreenResolutionMultiplier(element blurBoxElement, float x,y)</syntaxhighlight> | |||
===Required Arguments=== | |||
*'''element blurBoxElement:''' A previously declared blurBox element. | |||
*'''float x,y:''' Set sampled screen relative resolution multiplier (0-1) | |||
===Returns=== | |||
The function returns true if set successfully, false otherwise. | |||
</section> | |||
==Examples== | |||
<syntaxhighlight lang="lua">local scx, scy = guiGetScreenSize() | |||
local guiWindowElement = nil | |||
local blurBoxElement = nil | |||
addEventHandler( "onClientPreRender", root, | |||
function() | |||
if guiWindowElement and blurBoxElement then | |||
local xPos, yPos = guiGetPosition ( guiWindowElement , false ) | |||
local xSize, ySize = guiGetSize ( guiWindowElement , false ) | |||
exports.blur_box:setBlurBoxPosition( blurBoxElement, xPos, yPos ) | |||
exports.blur_box:setBlurBoxSize( blurBoxElement, xSize, ySize ) | |||
end | |||
end | |||
,true ,"high-3" ) | |||
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource()), | |||
function() | |||
guiWindowElement = guiCreateWindow ( scx/2-scy/4, scy/2 - scy/4, scy/2, scy/2, "BlurBox test", false ) | |||
guiWindowSetMovable ( guiWindowElement, true ) | |||
guiWindowSetSizable ( guiWindowElement, true ) | |||
guiSetAlpha ( guiWindowElement, 0.3 ) | |||
blurBoxElement = exports.blur_box:createBlurBox( scx/2-scy/4, scy/2 - scy/4, scy/2, scy/2, 255, 255, 255, 255, false ) | |||
--exports.blur_box:setBlurBoxColor( blurBoxElement, 255, 100, 100, 255) | |||
exports.blur_box:setScreenResolutionMultiplier( 0.5, 0.5 ) | |||
end | |||
) | |||
addEventHandler( "onClientResourceStop", getResourceRootElement( getThisResource()), | |||
function() | |||
destroyElement( guiWindowElement ) | |||
blurBoxElement = not exports.blur_box:destroyBlurBox( blurBoxElement ) | |||
end | |||
) | |||
</syntaxhighlight> | |||
This creates a blur box and attaches it to a created window element. | |||
Of course when you want to use these functions in your resources you have to include | |||
the blur_box resource in meta. | |||
[[File:15323.png|Blurbox example]] | |||
==See Also== | |||
[http://community.multitheftauto.com/index.php?p=resources&s=details&id=10163 Community resource] | |||
[https://www.dropbox.com/s/db13n4l62k21x19/blurBox_test.zip?dl=0 Test resource] |
Latest revision as of 18:34, 1 January 2017
This resource lets You create simple gaussian blur boxes onClientRender. Using that - You can make your game GUI a bit more fancy.
Overview
It is easy to use, gives a few options to manage blur boxes.
The resource itself adds exported clientside functions:
Exported functions
createBlurBox
This function creates a blur box.
bool exports.blur_box:createBlurBox(float posX,posY,sizeX,sizeY,int colorR,colorG,colorB,colorA,postGUI)
Required Arguments
- float posX, posY: Position in screen space.
- float sizeX, sizeY: Size of the box.
- int colorR,colorG,colorB,colorA: RGBA color (0 - 255).
- bool postGUI: Should the box be drawn before or after MTA GUI elements.
Returns
The function returns the element if set successfully, 'false' otherwise.
destroyBlurBox
This function destroys a blur box element.
bool exports.blur_box:destroyBlurBox(element blurBoxElement)
Required Arguments
- element blurBoxElement: A previously declared blur box element.
Returns
The function returns true if set successfully, false otherwise.
setBlurBoxEnabled
This function enables or disables a created blur box element.
bool exports.blur_box:setBlurBoxEnabled(element blurBoxElement, bool isEnabled)
Required Arguments
- element blurBoxElement: A previously declared blur box element.
- bool isEnabled: Enable/Disable the blur box element.
Returns
The function returns true if set successfully, false otherwise.
setBlurBoxPosition
This function sets blur box position.
bool exports.blur_box:setBlurBoxPosition(element blurBoxElement,float posX,posY)
Required Arguments
- element blurBoxElement: A previously declared blur box element.
- float posX, posY: Position in screen space.
Returns
The function returns true if set successfully, false otherwise.
setBlurBoxSize
This function sets blur box width and height.
bool exports.blur_box:setBlurBoxSize(element blurBoxElement,float sizeX,sizeY)
Required Arguments
- element blurBoxElement: A previously declared blur box element.
- float sizeX,sizeY: Size of the blur box.
Returns
The function returns true if set successfully, false otherwise.
setBlurBoxColor
This function sets blur box color values.
bool exports.blur_box:setBlurBoxColor(element blurBoxElement,float colorR,colorG,colorB,colorA)
Required Arguments
- element blurBoxElement: A previously declared blur box element.
- float colorR,colorG,colorB,colorA: RGBA color (0 - 255).
Returns
The function returns true if set successfully, false otherwise.
setBlurIntensity
This function sets blur amount for all the blur boxes
bool exports.blur_box:setBlurIntensity(float blurFactor)
Required Arguments
- float blurFactor: Set blur amount for all the blur boxes. (default 0.6)
Returns
The function returns true if set successfully, false otherwise.
setScreenResolutionMultiplier
This function sets screen relative resolution multiplier for the screenSource
bool exports.blur_box:setScreenResolutionMultiplier(element blurBoxElement, float x,y)
Required Arguments
- element blurBoxElement: A previously declared blurBox element.
- float x,y: Set sampled screen relative resolution multiplier (0-1)
Returns
The function returns true if set successfully, false otherwise.
Examples
local scx, scy = guiGetScreenSize() local guiWindowElement = nil local blurBoxElement = nil addEventHandler( "onClientPreRender", root, function() if guiWindowElement and blurBoxElement then local xPos, yPos = guiGetPosition ( guiWindowElement , false ) local xSize, ySize = guiGetSize ( guiWindowElement , false ) exports.blur_box:setBlurBoxPosition( blurBoxElement, xPos, yPos ) exports.blur_box:setBlurBoxSize( blurBoxElement, xSize, ySize ) end end ,true ,"high-3" ) addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource()), function() guiWindowElement = guiCreateWindow ( scx/2-scy/4, scy/2 - scy/4, scy/2, scy/2, "BlurBox test", false ) guiWindowSetMovable ( guiWindowElement, true ) guiWindowSetSizable ( guiWindowElement, true ) guiSetAlpha ( guiWindowElement, 0.3 ) blurBoxElement = exports.blur_box:createBlurBox( scx/2-scy/4, scy/2 - scy/4, scy/2, scy/2, 255, 255, 255, 255, false ) --exports.blur_box:setBlurBoxColor( blurBoxElement, 255, 100, 100, 255) exports.blur_box:setScreenResolutionMultiplier( 0.5, 0.5 ) end ) addEventHandler( "onClientResourceStop", getResourceRootElement( getThisResource()), function() destroyElement( guiWindowElement ) blurBoxElement = not exports.blur_box:destroyBlurBox( blurBoxElement ) end )
This creates a blur box and attaches it to a created window element.
Of course when you want to use these functions in your resources you have to include the blur_box resource in meta.