GuiGetAlpha: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
Alpha represents the transparency of a gui element. This function allows retrieval of a gui element's current alpha.
This fake function is for use with blah & blah and does blahblahblabhalbhl


==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">
float guiGetAlpha ( element guielement )
int guiGetAlpha ( element guiElement )
</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 -->
*'''guiElement:''' The gui element in which you want to retrieve the alpha of.
*'''argumentName:''' description
 
<!-- Only include this section below if there are optional arguments -->
===Optional Arguments===
{{OptionalArg}}
*'''argumentName2:''' description
*'''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 -->
This function returns a positive integer in between 0 and 255 of the gui element's current alpha, or false if it could not be retrieved.
Returns ''true'' if blah, ''false'' otherwise.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example provides a ''fadeElement'' function, which fades roughly over a period of 4 seconds. The user may fade in or fade out an element
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...
function fadeElement ( guiElement, state )
blabhalbalhb --abababa
if state == "out" then --if the user specifies he wants to fade out an element
--This line does this...
local currentAlpha = guiGetAlpha ( guiElement )--get the current alpha
mooo
local newAlpha = currentAlpha - 4 --set the alpha to 4 less (more transparent)
--ensure that the alpha is not below 0, if it is, set it to 0
if newAlpha < 0 then newAlpha = 0 end
--set the new alpha
guiSetAlpha ( guiElement, newAlpha )
--if the new alpha is not completely invisible already
if newAlpha ~= 0 then
--call this function to fade out some more 50ms later
setTimer ( fadeElement, 50, 1, guiElement, state )
end
elseif state == "in" then --else, if the user specifies he wants to fade out an element
local currentAlpha = guiGetAlpha ( guiElement )--get the current alpha
local newAlpha = currentAlpha + 4 --set the alpha to 4 more(less transparent)
--ensure that the alpha is not above 255, if it is, set it to 255
if newAlpha > 255 then newAlpha = 255 end
--set the new alpha
guiSetAlpha ( guiElement, newAlpha )
--if the new alpha is not completely opaque already
if newAlpha ~= 255 then
--call this function to fade in some more 50ms later
setTimer ( fadeElement, 50, 1, guiElement, state )
end
end
end
</syntaxhighlight>
</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 -->
{{GUI_functions}}
{{FunctionArea_functions}}
[[Category:Need_Syntax]]  -- leave this until syntax is available. Cannot document the function or event without syntax.
[[Category:Incomplete]] -- leave this unless you complete the function

Revision as of 15:17, 1 August 2007

Alpha represents the transparency of a gui element. This function allows retrieval of a gui element's current alpha.

Syntax

int guiGetAlpha ( element guiElement )

Required Arguments

  • guiElement: The gui element in which you want to retrieve the alpha of.

Returns

This function returns a positive integer in between 0 and 255 of the gui element's current alpha, or false if it could not be retrieved.

Example

This example provides a fadeElement function, which fades roughly over a period of 4 seconds. The user may fade in or fade out an element

function fadeElement ( guiElement, state )
	if state == "out" then --if the user specifies he wants to fade out an element
		local currentAlpha = guiGetAlpha ( guiElement )--get the current alpha
		local newAlpha = currentAlpha - 4 --set the alpha to 4 less (more transparent)
		--ensure that the alpha is not below 0, if it is, set it to 0
		if newAlpha < 0 then newAlpha = 0 end 
		--set the new alpha
		guiSetAlpha ( guiElement, newAlpha )
		--if the new alpha is not completely invisible already
		if newAlpha ~= 0 then
			--call this function to fade out some more 50ms later
			setTimer ( fadeElement, 50, 1, guiElement, state )
		end
	elseif state == "in" then --else, if the user specifies he wants to fade out an element
		local currentAlpha = guiGetAlpha ( guiElement )--get the current alpha
		local newAlpha = currentAlpha + 4 --set the alpha to 4 more(less transparent)
		--ensure that the alpha is not above 255, if it is, set it to 255
		if newAlpha > 255 then newAlpha = 255 end
		--set the new alpha
		guiSetAlpha ( guiElement, newAlpha )
		--if the new alpha is not completely opaque already
		if newAlpha ~= 255 then
			--call this function to fade in some more 50ms later
			setTimer ( fadeElement, 50, 1, guiElement, state )
		end
	end
end

See Also

General functions

Browsers

Buttons

Checkboxes

Comboboxes

Edit Boxes

Gridlists

Memos

Progressbars

Radio Buttons

Scrollbars

Scrollpanes

Static Images

Tab Panels

Tabs

Text Labels

Windows