<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Struct with a #define in it</title>
		<link>http://www.allegro.cc/forums/view/618795</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 21 Mar 2023 21:34:04 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve created an include file of defines to simplify colors IE.</p><p>#define WHITE al_map_rgb(255,255,255)</p><p>I have created an array of structs and want to store block color.   I created the struct as such . </p><p>struct BLOCKS {<br />	float fTX;<br />	float fTY;<br />	float fBX;<br />	float fBY;<br />	std::string sColor;<br />};</p><p>BLOCK Blocks[8]</p><p>The problem is, if I store the color in sColor as &quot;WHITE&quot; then the quotation marks negate the define data and the string is just seen as &quot;a string&quot;. <br />If I leave the quotation marks off, I get a compiler error due to the mismatch. </p><p>error: could not convert &#39;al_map_rgb(255, 255, 255)&#39; from &#39;ALLEGRO_COLOR&#39; to &#39;std::__cxx11::string {aka std::__cxx11::basic_string&lt;char&gt;}&#39;<br /> #define WHITE         al_map_rgb(255,255,255) </p><p>My question is how to store the define label so it is actually storing the data and not the label?  Thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AceBlkwell)</author>
		<pubDate>Fri, 17 Mar 2023 23:10:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Doesn&#39;t work that way. </p><p>Define doesn&#39;t store data or labels. It is command to the compiler to process before compiling. In the code, every WHITE is replaced with your al_map_rgb.</p><p>However, strings are ignored because they are char arrays.</p><p>char color[6] = &quot;WHITE&quot;;</p><p>to the compiler it sees this </p><p>char color[6] = {57, 48, 49, 54, 45};</p><p>and not actual text
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Fri, 17 Mar 2023 23:25:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for the clarification, but you didn&#39;t answer my question. <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=";D" border="0" />.</p><p>Unless you are saying you can&#39;t mix the two.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AceBlkwell)</author>
		<pubDate>Fri, 17 Mar 2023 23:34:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can&#39;t. At least not using defines. </p><p>What about using a std::map with your color list?
</p><div class="source-code snippet"><div class="inner"><pre>std::map<span class="k3">&lt;</span>std::string, ALLEGRO_COLOR&gt; color_list<span class="k2">;</span>

color_list<span class="k2">[</span><span class="s">"WHITE"</span><span class="k2">]</span> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">255</span>, <span class="n">255</span>, <span class="n">255</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Fri, 17 Mar 2023 23:45:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That looks doable.  Out of curiosity, could I... </p><p>al_draw_filled_rectangle(fTX, fTY, fBX, fBY, &quot;WHITE&quot;);</p><p>or </p><p>al_draw_filled_rectangle(fTX, fTY, fBX, fBY, color_list[&quot;WHITE&quot;]);</p><p>Also I&#39;m a little confused (obviously),  If my colors are in an array themselves, how do I store them as a value in another array.  Is std::map a storage type?  IE</p><p>Blocks[5].sColor = color_list[&quot;WHITE&quot;];</p><p>The reason for the issue overall is I&#39;m wanting to initialize an array and then put the rectangle command in for loop. So the amount of rectangles could vary with out needing to add and subtract a bunch of line items.  If I went from 8 to 16 rectangles I could just update a LIMIT define and not have to add 8 additional lines to a previous 8 individual lines
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AceBlkwell)</author>
		<pubDate>Sat, 18 Mar 2023 00:03:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Access it like colorlist[&quot;color name&quot;]</p><p>Your sColor is a string so it would be: Blocks[5].sColor = &quot;WHITE&quot;;</p><p>and when you need it: color_list[Blocks[5].sColor]
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Sat, 18 Mar 2023 00:10:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Makes sense.  Thanks Daniel </p><p>Just thought of something.  Is ALLEGRO_COLOR a storage type?  Why can&#39;t I...</p><p>struct BLOCKS {<br />	float fTX;<br />	float fTY;<br />	float fBX;<br />	float fBY;<br />	ALLEGRO_COLOR AColor; //or ALLEGRO_COLOR *AColor<br />};
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AceBlkwell)</author>
		<pubDate>Sat, 18 Mar 2023 00:13:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>ALLEGRO_COLOR is a simple struct with 3 floats (red, green and blue)</p><p>You could do what I do and store it as hex</p><p>int32_t white = 0xffffff;<br />int32_t red = 0xff0000;</p><p>There are functions in the color add on to convert.</p><p>Or write your own
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> color <span class="k3">=</span> fromHex<span class="k2">(</span><span class="k1">int32_t</span> hex<span class="k2">)</span>
<span class="k2">{</span>
     <span class="k1">return</span> <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="k2">(</span>hex <span class="k3">&amp;</span> <span class="n">0xff0000</span><span class="k2">)</span> <span class="k3">&gt;</span><span class="k3">&gt;</span> <span class="n">16</span>, <span class="k2">(</span>hex <span class="n">0xff00</span><span class="k2">)</span> <span class="k3">&gt;</span><span class="k3">&gt;</span> <span class="n">8</span>, hex <span class="k3">&amp;</span> <span class="n">0xff</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Sat, 18 Mar 2023 00:31:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I appreciate your time Daniel.  Using your suggestions, I&#39;ll figure something out.   Thanks again.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AceBlkwell)</author>
		<pubDate>Sat, 18 Mar 2023 00:46:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You could also simply define constants initialized using al_map_rgb_f, e.g.:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">namespace</span> Colors <span class="k2">{</span>
<span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> WHITE <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_map_rgb_f"><span class="a">al_map_rgb_f</span></a><span class="k2">(</span><span class="n">1</span>.<span class="n">0</span>, <span class="n">1</span>.<span class="n">0</span>, <span class="n">1</span>.<span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
I think for al_map_rgb (without &quot;_f&quot;) to work, al_init needs to be called in advance. So not usable for static initialization. Or has this been changed?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Polybios)</author>
		<pubDate>Sun, 19 Mar 2023 22:20:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>SiegeLord changed it in GIT a few months ago.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 21 Mar 2023 21:03:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks Polybios. Using your suggestion I created an .H file using the const ALLEGRO_COLOR.   I then updated my struct to include ALLEGRO_COLOR sCards.  Lastly I used sCards = COLOR::WHITE and it works.  </p><p>I&#39;m going to try Daniel&#39;s map suggestion as well.  </p><p>In either case I appreciate everyone&#39;s recommendations.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AceBlkwell)</author>
		<pubDate>Tue, 21 Mar 2023 21:05:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s generally best to avoid macro magic with defines if you can help it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 21 Mar 2023 21:34:04 +0000</pubDate>
	</item>
</rss>
