GuiGetAlpha: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(11 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Client function}}
__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  )
float guiGetAlpha ( element guiElement )
</syntaxhighlight>  
</syntaxhighlight>
{{OOP||[[GUI widgets|GuiElement]]:getAlpha|alpha|guiSetAlpha}}


===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 1 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 ''guiFade'' function, which allows you to fade in/out a GUI.
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 guiFade( gui, state )
blabhalbalhb --abababa
if state == "in" then -- This state will fade IN the GUI
--This line does this...
fadeIn = setTimer(guiFade, 50, 1, gui, state) -- We loop the function to make it lower the alpha each 50 ms
mooo
alpha = guiGetAlpha(gui) -- We get the GUI's actual alpha after each loop
guiSetAlpha(gui, alpha - 0.1) -- We set the GUI's actual alpha after each loop
if alpha == 0 then -- If the loop reached "0"...
guiSetVisible(gui, false) -- We set the GUI visibility to 0 so it won't be clickable or editable
killTimer(fadeIn) -- ... We kill the timer
fadeIn = nil -- And to make sure it doesn't exist anymore, we set it to nil
end
elseif state == "out" then -- This state will fade OUT the GUI
guiSetVisible(gui, true) -- Since the GUI will still be click-able, we'll set it's visibility to "false"
fadeOut = setTimer(guiFade, 50, 1, gui, state) -- We loop the function to make it higher the alpha each 50 ms
alpha = guiGetAlpha(gui) -- We get the GUI's actual alpha after each loop
guiSetAlpha(gui, alpha + 0.1) -- We set the GUI's actual alpha after each loop
if alpha == 1 then -- If the loop reached "1"...
killTimer(fadeOut) -- ... We kill the timer
fadeOut = nil -- And to make sure it doesn't exist anymore, we set it to nil
end
end
end
 
-- NOTE: If you're using a button to pop up the GUI-Element. Use "guiSetEnabled" along with the button. You'll have also to set a timer in order to disable it by the time it fades, either way it will bug.
</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}}
{{GUI_events}}
[[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

Latest revision as of 17:15, 21 November 2018

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

Syntax

float guiGetAlpha ( element guiElement )

OOP Syntax Help! I don't understand this!

Method: GuiElement:getAlpha(...)
Variable: .alpha
Counterpart: guiSetAlpha


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 1 of the gui element's current alpha, or false if it could not be retrieved.

Example

This example provides a guiFade function, which allows you to fade in/out a GUI.

function guiFade( gui, state )
	if state == "in" then -- This state will fade IN the GUI
	fadeIn = setTimer(guiFade, 50, 1, gui, state) -- We loop the function to make it lower the alpha each 50 ms
	alpha = guiGetAlpha(gui) -- We get the GUI's actual alpha after each loop
	guiSetAlpha(gui, alpha - 0.1) -- We set the GUI's actual alpha after each loop
	if alpha == 0 then -- If the loop reached "0"...
		guiSetVisible(gui, false) -- We set the GUI visibility to 0 so it won't be clickable or editable
		killTimer(fadeIn) -- ... We kill the timer
		fadeIn = nil -- And to make sure it doesn't exist anymore, we set it to nil
		end
	elseif state == "out" then -- This state will fade OUT the GUI
		guiSetVisible(gui, true) -- Since the GUI will still be click-able, we'll set it's visibility to "false"
		fadeOut = setTimer(guiFade, 50, 1, gui, state) -- We loop the function to make it higher the alpha each 50 ms
		alpha = guiGetAlpha(gui) -- We get the GUI's actual alpha after each loop
		guiSetAlpha(gui, alpha + 0.1) -- We set the GUI's actual alpha after each loop
		if alpha == 1 then -- If the loop reached "1"...
			killTimer(fadeOut) -- ... We kill the timer
			fadeOut = nil -- And to make sure it doesn't exist anymore, we set it to nil
		end
	end
end

-- NOTE: If you're using a button to pop up the GUI-Element. Use "guiSetEnabled" along with the button. You'll have also to set a timer in order to disable it by the time it fades, either way it will bug.

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

Input

GUI