DgsGetAlpha: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 17: Line 17:
This example provides a ''guiFade'' function, which allows you to fade in/out a DGS GUI.
This example provides a ''guiFade'' function, which allows you to fade in/out a DGS GUI.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
DGS = exports.dgs
function guiFade( gui, state )
function guiFade( gui, state )
if state == "in" then -- This state will fade in the DGS GUI
if state == "in" then -- This state will fade in the DGS GUI
fadeIn = setTimer(guiFade, 50, 1, gui, state) -- We loop the function to make it lower the alpha each 50 ms
fadeIn = setTimer(guiFade, 50, 1, gui, state) -- We loop the function to make it lower the alpha each 50 ms
alpha = dgsDxGUIGetAlpha(gui) -- We get the DGS GUI's actual alpha after each loop
alpha = DGS:dgsDxGUIGetAlpha(gui) -- We get the DGS GUI's actual alpha after each loop
dgsDxGUISetAlpha(gui, alpha - 0.1) -- We set the DGS GUI's actual alpha after each loop
DGS:dgsDxGUISetAlpha(gui, alpha - 0.1) -- We set the DGS GUI's actual alpha after each loop
if alpha == 0 then -- If the loop reached "0"...
if alpha == 0 then -- If the loop reached "0"...
dgsDxGUISetVisible(gui, false) -- We set the DGS GUI visibility to 0 so it won't be clickable or editable
DGS:dgsDxGUISetVisible(gui, false) -- We set the DGS GUI visibility to 0 so it won't be clickable or editable
killTimer(fadeIn) -- ... We kill the timer
killTimer(fadeIn) -- ... We kill the timer
fadeIn = nil -- And to make sure it doesn't exist anymore, we set it to nil
fadeIn = nil -- And to make sure it doesn't exist anymore, we set it to nil
end
end
elseif state == "out" then -- This state will fade out the DGS GUI
elseif state == "out" then -- This state will fade out the DGS GUI
dgsDxGUISetVisible(gui, true) -- Since the GUI will still be click-able, we'll set it's visibility to "false"
DGS:dgsDxGUISetVisible(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
fadeOut = setTimer(guiFade, 50, 1, gui, state) -- We loop the function to make it higher the alpha each 50 ms
alpha = dgsDxGUIGetAlpha(gui) -- We get the DGS GUI's actual alpha after each loop
alpha = dgsDxGUIGetAlpha(gui) -- We get the DGS GUI's actual alpha after each loop
dgsDxGUISetAlpha(gui, alpha + 0.1) -- We set the DGS GUI's actual alpha after each loop
DGS:dgsDxGUISetAlpha(gui, alpha + 0.1) -- We set the DGS GUI's actual alpha after each loop
if alpha == 1 then -- If the loop reached "1"...
if alpha == 1 then -- If the loop reached "1"...
killTimer(fadeOut) -- ... We kill the timer
killTimer(fadeOut) -- ... We kill the timer

Revision as of 09:19, 4 August 2017

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

Syntax

float dgsDxGUIGetAlpha ( element dgsElement )

Required Arguments

  • dgsElement: The dgs element in which you want to retrieve the alpha of.

Returns

This function returns a positive integer in between 0 and 1 of the dgs 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 DGS GUI.

DGS = exports.dgs
function guiFade( gui, state )
	if state == "in" then -- This state will fade in the DGS GUI
	fadeIn = setTimer(guiFade, 50, 1, gui, state) -- We loop the function to make it lower the alpha each 50 ms
	alpha = DGS:dgsDxGUIGetAlpha(gui) -- We get the DGS GUI's actual alpha after each loop
	DGS:dgsDxGUISetAlpha(gui, alpha - 0.1) -- We set the DGS GUI's actual alpha after each loop
	if alpha == 0 then -- If the loop reached "0"...
		DGS:dgsDxGUISetVisible(gui, false) -- We set the DGS 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 DGS GUI
		DGS:dgsDxGUISetVisible(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 = dgsDxGUIGetAlpha(gui) -- We get the DGS GUI's actual alpha after each loop
		DGS:dgsDxGUISetAlpha(gui, alpha + 0.1) -- We set the DGS 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 DGS-Element. Use "dgsDxGUISetEnabled" 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