<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Otto</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Otto"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Otto"/>
	<updated>2026-04-30T21:11:44Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=DxDrawProgressBar&amp;diff=44713</id>
		<title>DxDrawProgressBar</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=DxDrawProgressBar&amp;diff=44713"/>
		<updated>2015-02-20T21:25:30Z</updated>

		<summary type="html">&lt;p&gt;Otto: Added function&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Useful Function}}&lt;br /&gt;
&amp;lt;lowercasetitle/&amp;gt;&lt;br /&gt;
__NOTOC__&lt;br /&gt;
This function simulates a progress bar drawed using DirectDraw. (Note this will only work client-side and you need to call it on each frame)&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;dxDrawProgressBar(float startX, float startY, float width, float height, float progress, int color, int backColor)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required arguments===&lt;br /&gt;
* '''startX''': An float representing the absolute origin X position of the rectangle, represented by pixels on the screen.&lt;br /&gt;
* '''startY''': An float representing the absolute origin Y position of the rectangle, represented by pixels on the screen.&lt;br /&gt;
* '''width''': An float representing the width of the rectangle, drawn in a ''right'' direction from the origin.&lt;br /&gt;
* '''height''': An float representing the height of the rectangle, drawn in a ''downwards'' direction from the origin.&lt;br /&gt;
* '''progress''': a float ranging from 0 to 100&lt;br /&gt;
* '''color''':  the hex color of the progress bar, produced using tocolor or 0xAARRGGBB (AA = alpha, RR = red, GG = green, BB = blue)&lt;br /&gt;
* '''backColor''':  the hex color of the background, produced using tocolor or 0xAARRGGBB (AA = alpha, RR = red, GG = green, BB = blue)&lt;br /&gt;
&lt;br /&gt;
===Return===&lt;br /&gt;
None&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;local unlerp = function(from,to,lerp) return (lerp-from)/(to-from) end&lt;br /&gt;
 &lt;br /&gt;
function dxDrawProgressBar( startX, startY, width, height, progress, color, backColor )&lt;br /&gt;
        local progress = math.max( 0, (math.min( 100, progress) ) )&lt;br /&gt;
        local wBar = width*.18&lt;br /&gt;
        for i = 0, 4 do&lt;br /&gt;
                --back&lt;br /&gt;
                local startPos = (wBar*i + (width*.025)*i) + startX&lt;br /&gt;
                dxDrawRectangle( startPos, startY, wBar, height, backColor )&lt;br /&gt;
                --progress&lt;br /&gt;
                local eInterval = (i*20)&lt;br /&gt;
                local localProgress = math.min( 1, unlerp( eInterval, eInterval + 20, progress ) )&lt;br /&gt;
                        if localProgress &amp;gt; 0 then&lt;br /&gt;
                                dxDrawRectangle( startPos, startY, wBar*localProgress, height, color )&lt;br /&gt;
                        end&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example draws a progress bar in the top-left corner of the screen, with a random progress that changes every frame.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function draw()&lt;br /&gt;
  dxDrawProgressBar( 10, 10, 200, 200, math.random(0,100), tocolor( 250, 50, 50, 255), tocolor( 255, 255, 255, 255) )&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onClientRender&amp;quot;, root, draw)  -- Keep everything visible with onClientRender.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Useful_Functions}}&lt;/div&gt;</summary>
		<author><name>Otto</name></author>
	</entry>
</feed>