<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Which is preferred: al_mouse_button_down or mouse_state.buttons?</title>
		<link>http://www.allegro.cc/forums/view/616338</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 17 Jun 2016 22:52:58 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was reading through the documentation and noticed there are two functions to do exactly the same thing:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_MOUSE_STATE"><span class="a">ALLEGRO_MOUSE_STATE</span></a><span class="k3">*</span> state<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_get_mouse_state"><span class="a">al_get_mouse_state</span></a><span class="k2">(</span>state<span class="k2">)</span><span class="k2">;</span>
<span class="k1">if</span><span class="k2">(</span>state.buttons <span class="k3">&amp;</span> <span class="n">1</span><span class="k2">)</span> <span class="k2">{</span> <span class="c">//First button is down (usually LMB)</span>
    <span class="c">//MOVE THE THING!</span>
<span class="k2">}</span>
</pre></div></div><p>

OR</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_MOUSE_STATE"><span class="a">ALLEGRO_MOUSE_STATE</span></a><span class="k3">*</span> state<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_get_mouse_state"><span class="a">al_get_mouse_state</span></a><span class="k2">(</span>state<span class="k2">)</span><span class="k2">;</span>
<span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_mouse_button_down"><span class="a">al_mouse_button_down</span></a><span class="k2">(</span>state, <span class="n">1</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span> <span class="c">//First button is down (usually LMB)</span>
    <span class="c">//AND...THE OTHER THING!</span>
<span class="k2">}</span>
</pre></div></div><p>

Do they do the same thing internally?</p><p>Is one preferred over the other in certain situations?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Brooklyn)</author>
		<pubDate>Sat, 11 Jun 2016 21:44:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>They&#39;re not two functions. One is a function, the other is the variable in the structure that the function is reading.</p><p>There is a slim possibility that the API could change 10 years from now where &quot;1&quot; wouldn&#39;t mean the first button.</p><p>It&#39;s encapsulation. You use accessor functions (getters / setters) so that the underlying structure can be changed without affecting the rest of the code. For example, the &quot;buttons&quot; variable could be renamed &quot;button_list&quot; inside the mouse state structure and the second version will still work, whereas the direct-access one will now be broken. You could even change the variable type of &quot;buttons&quot; to be an int, a struct, or even a SQL query to a database, and that al_mouse_button_down() interface will remain the same. But you surely wouldn&#39;t be accessing a SQL database from a variable. *</p><p>If you don&#39;t mind the extra writing, use accessor functions always.</p><p>* (Fun sidenote: The D language supports &quot;property functions&quot; so that a getter/setter can appear to be, and be accessed like a variable. <a href="https://dlang.org/spec/function.html#property-functions">example</a>)</p><p>[edit] And to make sure we&#39;re talking about the same thing here, you&#39;re still missing al_get_mouse_state(state); in your second example, so I&#39;m assuming you meant to put it there.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Sat, 11 Jun 2016 23:39:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/616338/1023251#target">Chris Katko</a> said:</div><div class="quote"><p>* (Fun sidenote: The D language supports &quot;property functions&quot; so that a getter/setter can appear to be, and be accessed like a variable. example [dlang.org])</p></div></div><p>
I don&#39;t wan&#39;t to start a language war, but you were first. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>Object Pascal has properties too.  The <a href="http://www.freepascal.org/docs-html/ref/refse38.html#x84-1060006.6">documentation description</a> is quite complex, so there&#39;s a simple example:
</p><div class="source-code snippet"><div class="inner"><pre>  TYPE
    TMyClass <span class="k3">=</span> CLASS <span class="k2">(</span>TObject<span class="k2">)</span>
    PRIVATE
      fValue: INTEGER<span class="k2">;</span>

      FUNCTION GetValue: INTEGER<span class="k2">;</span>
      PROCEDURE SetValue <span class="k2">(</span>CONST aValue: INTEGER<span class="k2">)</span><span class="k2">;</span>
    PUBLIC
    <span class="k2">(</span><span class="k3">*</span> Read-only property. <span class="k3">*</span><span class="k2">)</span>
      PROPERTY OneProperty: INTEGER READ fValue<span class="k2">;</span>
    <span class="k2">(</span><span class="k3">*</span> Getter <span class="k1">and</span> setter... <span class="k3">*</span><span class="k2">)</span>
      PROPERTY OtherProperty: INTEGER READ GetValue WRITE SetValue<span class="k2">;</span>
    END<span class="k2">;</span>
</pre></div></div><p>

C++ nor Java don&#39;t have properties, but you can always use methods.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Fri, 17 Jun 2016 22:52:58 +0000</pubDate>
	</item>
</rss>
