<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GuShH&#039;s DevBlog &#187; pb</title>
	<atom:link href="http://gushh.net/blog/?tag=pb&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://gushh.net/blog</link>
	<description>This blog is about software, electronics engineering and game development.</description>
	<lastBuildDate>Tue, 24 Jan 2012 00:31:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>(PB) String Between Characters</title>
		<link>http://gushh.net/blog/pb-string-characters/</link>
		<comments>http://gushh.net/blog/pb-string-characters/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 12:30:07 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[find string]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[pb]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[string between chars]]></category>
		<category><![CDATA[str_between_char]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=849</guid>
		<description><![CDATA[This is a small purebasic function used to retrieve a string between two known characters, it also allows you to provide a starting position. Procedure.s str_between_char&#40; *Source.CHARACTER, First.C, Last.C, StartAt.i = 0 &#41; Define.i dwLength &#160; *Source + &#40;StartAt * SizeOf&#40;CHARACTER&#41;&#41; Repeat If *Source\c = First ; If this character matches the First character *Source [...]]]></description>
			<content:encoded><![CDATA[<p>This is a small purebasic function used to retrieve a string between two known characters, it also allows you to provide a starting position.</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Procedure</span>.s str_between_char<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>Source.CHARACTER, First.C, Last.C, StartAt.i <span style="color: #000066;">=</span> <span style="color: #CC0000;">0</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">Define</span>.i dwLength
&nbsp;
	<span style="color: #000066;">*</span>Source <span style="color: #000066;">+</span> <span style="color: #000066;">&#40;</span>StartAt <span style="color: #000066;">*</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>CHARACTER<span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">Repeat</span>
		<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>Source<span style="color: #000066;">\</span>c <span style="color: #000066;">=</span> First <span style="color: #ff0000; font-style: italic;">; If this character matches the First character</span>
			<span style="color: #000066;">*</span>Source <span style="color: #000066;">+</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>CHARACTER<span style="color: #000066;">&#41;</span>
			dwLength <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>Source
			<span style="color: #000066; font-weight: bold;">Repeat</span> <span style="color: #ff0000; font-style: italic;">; Repeat until we find an occurrance with the Last character</span>
				<span style="color: #000066;">*</span>Source <span style="color: #000066;">+</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>CHARACTER<span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">Until</span> <span style="color: #000066;">*</span>Source<span style="color: #000066;">\</span>c <span style="color: #000066;">=</span> Last
			dwLength <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>Source <span style="color: #000066;">-</span> dwLength<span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #0000ff;">PeekS</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>Source <span style="color: #000066;">-</span> dwLength, dwLength <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; Peek the output string</span>
			<span style="color: #000066; font-weight: bold;">Break</span>
		<span style="color: #000066; font-weight: bold;">EndIf</span>
		<span style="color: #000066;">*</span>Source <span style="color: #000066;">+</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>CHARACTER<span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">Until</span> <span style="color: #000066;">*</span>Source<span style="color: #000066;">\</span>c <span style="color: #000066;">=</span> #Null
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>Example use:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Define</span>.s <span style="color: #0000ff;">str</span> 		<span style="color: #000066;">=</span> <span style="color: #009900;">&quot;dd(hallo)xyz(a)&quot;</span>
<span style="color: #000066; font-weight: bold;">Define</span>.s result 	<span style="color: #000066;">=</span> str_between_char<span style="color: #000066;">&#40;</span>@<span style="color: #0000ff;">str</span>, '<span style="color: #000066;">&#40;</span>', '<span style="color: #000066;">&#41;</span>', <span style="color: #CC0000;">2</span><span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">Debug</span> result</pre></div></div>

<p>If you&#8217;re working on a parser or similar project this will sure come in handy.<br />
<strong>Enjoy!</strong></p>
<g:plusone href='http://gushh.net/blog/pb-string-characters/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/pb-string-characters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Declar&#8217;em! &#8211; Automatic declaration of procedures.</title>
		<link>http://gushh.net/blog/automatic-declare-tool/</link>
		<comments>http://gushh.net/blog/automatic-declare-tool/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 20:32:44 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[automatic procedure declaration]]></category>
		<category><![CDATA[declare]]></category>
		<category><![CDATA[declarem]]></category>
		<category><![CDATA[GuShH]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[pb]]></category>
		<category><![CDATA[procedures]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=240</guid>
		<description><![CDATA[This is a tool that I&#8217;ve been using for quite a long while, just recently I fixed a small bug in the regexp and I thought it was time to share it. For those of you using the official IDE, there&#8217;s no real solution to this &#8220;problem&#8221;. When you&#8217;re working on something small, it&#8217;s not [...]]]></description>
			<content:encoded><![CDATA[<p>This is a tool that I&#8217;ve been using for quite a long while, just recently I fixed a small bug in the regexp and I thought it was time to share it.</p>
<p>For those of you using the official IDE, there&#8217;s no real solution to this &#8220;problem&#8221;. When you&#8217;re working on something small, it&#8217;s not a big deal to define a couple of declares here and there&#8230; However, on bigger code this becomes a real issue!. So why waste the time switching between IDEs or doing it by hand?&#8230;</p>
<p style="text-align: left;"><a title="Declar'em!" href="http://gushh.net/dls/declarem.zip" target="_blank">Grab it</a> and let me know how it runs! (<span style="text-decoration: line-through;">nasty</span> <em>ugly </em>source included).</p>
<p style="text-align: center;">The tool is very simple to install, I recommend you unzip directly into your PB directory and configure it as follows:</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-243" title="Declarem_installation" src="http://gushh.net/blog/wp-content/uploads/2009/09/Declarem_installation.PNG" alt="Declarem_installation" width="485" height="296" /></p>
<p style="text-align: center;">That&#8217;s it. You&#8217;re ready to declar&#8217;em!.</p>
<p style="text-align: left; ">Cheers.</p>
<g:plusone href='http://gushh.net/blog/automatic-declare-tool/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/automatic-declare-tool/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Macro Templates, by example.</title>
		<link>http://gushh.net/blog/macro-templates-by-example/</link>
		<comments>http://gushh.net/blog/macro-templates-by-example/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 16:46:50 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[object factory]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[pb]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[vec3]]></category>
		<category><![CDATA[vector]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=114</guid>
		<description><![CDATA[Heres an example of what I call &#8220;macro templates&#8221; in PureBasic. A template encapsulates certain functionality, allowing you to dynamically generate the code in a flexible manner. This example implements a bare-bones n-vector library using a structure and a static array: Macro Vector_Register&#40; _n, _type &#41; &#160; Structure VECTOR#_n#_type vector._type&#91;_n&#93; EndStructure &#160; Procedure._type Vector#_n#_type#_Add&#40; *r.VECTOR#_n#_type, [...]]]></description>
			<content:encoded><![CDATA[<p>Heres an example of what I call &#8220;macro templates&#8221; in PureBasic. A template encapsulates certain functionality, allowing you to dynamically generate the code in a flexible manner.</p>
<p>This example implements a bare-bones n-vector library using a structure and a static array:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Macro</span> Vector_Register<span style="color: #000066;">&#40;</span> _n, _type <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Structure</span> VECTOR#_n#_type
		vector._type<span style="color: #000066;">&#91;</span>_n<span style="color: #000066;">&#93;</span>
	<span style="color: #000066; font-weight: bold;">EndStructure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_Add<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>r.VECTOR#_n#_type, <span style="color: #000066;">*</span>a.VECTOR#_n#_type, <span style="color: #000066;">*</span>b.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i i
		<span style="color: #000066; font-weight: bold;">For</span> i<span style="color: #000066;">=</span><span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">To</span> _n <span style="color: #000066;">-</span> <span style="color: #CC0000;">1</span>
			<span style="color: #000066;">*</span>r<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">+</span> <span style="color: #000066;">*</span>b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span>
		<span style="color: #000066; font-weight: bold;">Next</span>
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_Subtract<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>r.VECTOR#_n#_type, <span style="color: #000066;">*</span>a.VECTOR#_n#_type, <span style="color: #000066;">*</span>b.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i i
		<span style="color: #000066; font-weight: bold;">For</span> i<span style="color: #000066;">=</span><span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">To</span> _n <span style="color: #000066;">-</span> <span style="color: #CC0000;">1</span>
			<span style="color: #000066;">*</span>r<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">-</span> <span style="color: #000066;">*</span>b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span>
		<span style="color: #000066; font-weight: bold;">Next</span>
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_Divide<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>r.VECTOR#_n#_type, <span style="color: #000066;">*</span>a.VECTOR#_n#_type, <span style="color: #000066;">*</span>b.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i i
		<span style="color: #000066; font-weight: bold;">For</span> i<span style="color: #000066;">=</span><span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">To</span> _n <span style="color: #000066;">-</span> <span style="color: #CC0000;">1</span>
			<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">&lt;&gt;</span> <span style="color: #CC0000;">0.0</span> <span style="color: #000066; font-weight: bold;">And</span> <span style="color: #000066;">*</span>a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">&lt;&gt;</span> <span style="color: #CC0000;">0.0</span>
				<span style="color: #000066;">*</span>r<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">/</span> <span style="color: #000066;">*</span>b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span>
			<span style="color: #000066; font-weight: bold;">EndIf</span>
		<span style="color: #000066; font-weight: bold;">Next</span>
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_Multiply<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>r.VECTOR#_n#_type, <span style="color: #000066;">*</span>a.VECTOR#_n#_type, <span style="color: #000066;">*</span>b.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i i
		<span style="color: #000066; font-weight: bold;">For</span> i<span style="color: #000066;">=</span><span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">To</span> _n <span style="color: #000066;">-</span> <span style="color: #CC0000;">1</span>
			<span style="color: #000066;">*</span>r<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">*</span> <span style="color: #000066;">*</span>b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span>
		<span style="color: #000066; font-weight: bold;">Next</span>
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_DotProduct<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>a.VECTOR#_n#_type, <span style="color: #000066;">*</span>b.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i i
		<span style="color: #000066; font-weight: bold;">Define</span>._type result
		<span style="color: #000066; font-weight: bold;">For</span> i<span style="color: #000066;">=</span><span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">To</span> _n <span style="color: #000066;">-</span> <span style="color: #CC0000;">1</span>
			result <span style="color: #000066;">+</span> <span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">*</span> <span style="color: #000066;">*</span>b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Next</span>
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> result
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_Length<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>v.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #0000ff;">Sqr</span><span style="color: #000066;">&#40;</span> Vector#_n#_type#_DotProduct<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>v, <span style="color: #000066;">*</span>v <span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_Distance<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>a.VECTOR#_n#_type, <span style="color: #000066;">*</span>b.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.VECTOR#_n#_type temp
		Vector#_n#_type#_Subtract<span style="color: #000066;">&#40;</span> temp, <span style="color: #000066;">*</span>a, <span style="color: #000066;">*</span>b <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> Vector#_n#_type#_Length<span style="color: #000066;">&#40;</span> temp <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>.s Vector#_n#_type#_Debug<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>v.VECTOR#_n#_type, Decimals.i<span style="color: #000066;">=</span>#PB_Default <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i i
		<span style="color: #000066; font-weight: bold;">Define</span>.s tmp <span style="color: #000066;">=</span> <span style="color: #009900;">&quot;[&quot;</span>
		<span style="color: #000066; font-weight: bold;">For</span> i<span style="color: #000066;">=</span><span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">To</span> _n<span style="color: #000066;">-</span><span style="color: #CC0000;">1</span>
			tmp <span style="color: #000066;">+</span> <span style="color: #0000ff;">StrF</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>v<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span>, Decimals.i <span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">If</span> i <span style="color: #000066;">&lt;&gt;</span> _n<span style="color: #000066;">-</span><span style="color: #CC0000;">1</span>
				tmp <span style="color: #000066;">+</span> <span style="color: #009900;">&quot;, &quot;</span>
			<span style="color: #000066; font-weight: bold;">EndIf</span>
		<span style="color: #000066; font-weight: bold;">Next</span>
		tmp <span style="color: #000066;">+</span> <span style="color: #009900;">&quot;]&quot;</span>
		<span style="color: #000066; font-weight: bold;">Debug</span> tmp
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> tmp
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndMacro</span></pre></div></div>

<p>It might look strange/complicated at first, but once you read it you&#8217;ll realize it&#8217;s fairly simple.</p>
<p>Let&#8217;s see the usage of this particular template:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;">Vector_Register<span style="color: #000066;">&#40;</span><span style="color: #CC0000;">3</span>, f <span style="color: #000066;">&#41;</span>	<span style="color: #ff0000; font-style: italic;">; Register a float &quot;vec3&quot;.</span>
<span style="color: #000066; font-weight: bold;">Define</span>.VECTOR3f a,b,c	<span style="color: #ff0000; font-style: italic;">; Define a few vectors with the new structure.</span>
&nbsp;
a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #CC0000;">10.0</span>
a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #CC0000;">20.0</span>
a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #CC0000;">30.0</span>
&nbsp;
b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #CC0000;">100.0</span>
b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #CC0000;">200.0</span>
b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #CC0000;">300.0</span>
&nbsp;
Vector3f_Add<span style="color: #000066;">&#40;</span>c, a, b<span style="color: #000066;">&#41;</span>	<span style="color: #ff0000; font-style: italic;">; c = a + b</span>
Vector3f_Debug<span style="color: #000066;">&#40;</span>c<span style="color: #000066;">&#41;</span>	<span style="color: #ff0000; font-style: italic;">; show each element using the debug output.</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Debug</span> Vector3f_DotProduct<span style="color: #000066;">&#40;</span> a, b <span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">Debug</span> Vector3f_Length<span style="color: #000066;">&#40;</span> a <span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">Debug</span> Vector3f_Distance<span style="color: #000066;">&#40;</span> a, b <span style="color: #000066;">&#41;</span></pre></div></div>

<p>Cool, huh?. And you can define any amount of elements with any basic type.</p>
<p>Of course we sacrificed speed for flexibility. In those cases where we have to define n-vectors, this would be an ideal solution. For everything else, I suggest a specific library, such as my <a href="http://gushh.net/blog/2009/01/09/a-fast-vector-library-for-purebasic/" target="_blank">vec3</a> macro lib.</p>
<p>Using this principle you can abstract almost anything, within reason. One good example is my <a href="http://gushh.net/blog/2009/05/03/object-factory-for-purebasic/" target="_blank">object factory</a> template.  Ideally one would have arrays, lists, etc. Implemented in this very same way, in such case the possibilities would be endless and you&#8217;d be able to define dynamic lists/arrays inside structures, etc.</p>
<p>I strongly advice you to implement at least one of those templates, even if it&#8217;s just for an exercise.</p>
<p>Having the extra tools can&#8217;t hurt!</p>
<p>Cheers.</p>
<g:plusone href='http://gushh.net/blog/macro-templates-by-example/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/macro-templates-by-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Centered MessageRequester() / MessageBox()</title>
		<link>http://gushh.net/blog/pb-centered-messagerequester/</link>
		<comments>http://gushh.net/blog/pb-centered-messagerequester/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 16:25:00 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[CBT]]></category>
		<category><![CDATA[Centered Dialog]]></category>
		<category><![CDATA[Dual Screen]]></category>
		<category><![CDATA[Fanboy]]></category>
		<category><![CDATA[GuShH]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[MessageBox]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[pb]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[SetWindowsHookEx]]></category>
		<category><![CDATA[UnhookWindowsHookEx]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=87</guid>
		<description><![CDATA[As usual, I was browsing the PureBasic forums to see what was new, nothing much (heh&#8230;) but something caught my attention, the fact that some user requested for the IDE&#8217;s message dialogs to be &#8220;centered&#8221; ( because he had multiple displays and the messages would appear in between them ) just to get shit-faced by [...]]]></description>
			<content:encoded><![CDATA[<p>As usual, I was browsing the PureBasic forums to see what was new, nothing much (heh&#8230;) but something caught my attention, the fact that some user requested for the IDE&#8217;s message dialogs to be &#8220;centered&#8221; ( because he had multiple displays and the messages would appear in between them ) just to get shit-faced by an actual staff member!</p>
<p>You can&#8217;t just say &#8220;it&#8217;s Microsoft&#8217;s fault&#8221; &#8212; Are you in some sort of mac-only cleanse?, What&#8217;s your #%&amp;%#$ problem?!</p>
<p>Those who &#8220;pass the ball&#8221; (as the user suggested) are part of the problem. You, being a programmer can certainly code a simple CBT hook, right?. Are you against hooks, perhaps &#8211; you are a purist, I hear&#8230; Sorry, but sometimes solutions <strong>are</strong> &#8220;dirty&#8221; and you have to live with them.</p>
<div id="attachment_88" class="wp-caption aligncenter" style="width: 658px"><img class="size-full wp-image-88 " title="split_screen" src="http://gushh.net/blog/wp-content/uploads/2009/07/split_screen.jpg" alt="Just for the record, I too use a split-screen and I find it annoying that dialog boxes are not centered to their parent." width="648" height="203" /><p class="wp-caption-text">Just for the record, I too use a split-screen and I find it annoying that dialog boxes are not centered to their parent.</p></div>
<p><span id="more-87"></span></p>
<p>I certainly think that this sort of behavior is not good for a business, but then again they&#8217;ve been cat-walking away from reality for years now (Look at their website if not, look at the fact that they haven&#8217;t implemented basic functionality to their language and by basic I mean a proper container library and whatnot!). Most of their user-base consists of people who are afraid of real, world-class languages. That&#8217;s my opinion, take it or leave it.</p>
<p>But before you throw crap at me do remember that I support them, I just don&#8217;t like the way they&#8217;re doing things. Pretty much like Apple does (they do crap) however the fanboys don&#8217;t realize this and they see any criticism as bad for the company image, when in fact what damages the company is that nonsense wall they put up when anybody, and I do mean &#8220;anybody&#8221; says &#8220;anything&#8221; that appears to be &#8220;against&#8221; their product/s.</p>
<p>Even if you don&#8217;t like it at least have the decency to hear those who are genuinely interested in your product, those who are giving away (and for free) true and useful suggestions for you to improve them. I don&#8217;t give a damn about this particular user but I do care when a so called company does this sort of things to their own users, it&#8217;s just uncalled for and plainly unprofessional.</p>
<p>Have a nice day, code follows.</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">; This snippet was based on the following code by Microsoft:</span>
<span style="color: #ff0000; font-style: italic;">; http://support.microsoft.com/kb/180936</span>
<span style="color: #000066; font-weight: bold;">EnableExplicit</span> <span style="color: #ff0000; font-style: italic;">; The only way to go.</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i CenterMsgCallBack<span style="color: #000066;">&#40;</span> uMsg.i, wParam.i, lParam.i <span style="color: #000066;">&#41;</span> 
&nbsp;
	<span style="color: #000066; font-weight: bold;">Select</span> uMsg
		<span style="color: #000066; font-weight: bold;">Case</span> #HCBT_ACTIVATE
&nbsp;
			<span style="color: #000066; font-weight: bold;">Define</span>.RECT typFormRect, typRectMsg
			<span style="color: #000066; font-weight: bold;">Define</span>.i plMsgHook, hWnd
			<span style="color: #000066; font-weight: bold;">Define</span>.i lxPos, lyPos
&nbsp;
			hWnd <span style="color: #000066;">=</span> GetParent_<span style="color: #000066;">&#40;</span>wParam<span style="color: #000066;">&#41;</span> 																																																		<span style="color: #ff0000; font-style: italic;">; the parent will be the callee</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">If</span> hWnd 																																																											<span style="color: #ff0000; font-style: italic;">; can't hurt to check.</span>
&nbsp;
				plMsgHook 	<span style="color: #000066;">=</span> GetWindowLong_<span style="color: #000066;">&#40;</span> hWnd, #GWL_USERDATA <span style="color: #000066;">&#41;</span> 																																				<span style="color: #ff0000; font-style: italic;">; get the hook address</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">If</span> plMsgHook 																																																								<span style="color: #ff0000; font-style: italic;">; can't hurt to check.</span>
&nbsp;
					GetWindowRect_<span style="color: #000066;">&#40;</span> hWnd, typFormRect <span style="color: #000066;">&#41;</span>
					GetWindowRect_<span style="color: #000066;">&#40;</span> wParam, typRectMsg <span style="color: #000066;">&#41;</span>
&nbsp;
					lxPos <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>typFormRect<span style="color: #000066;">\</span><span style="color: #0000ff;">Left</span> <span style="color: #000066;">+</span> <span style="color: #000066;">&#40;</span>typFormRect<span style="color: #000066;">\</span><span style="color: #0000ff;">Right</span> <span style="color: #000066;">-</span> typFormRect<span style="color: #000066;">\</span><span style="color: #0000ff;">Left</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">/</span> <span style="color: #CC0000;">2</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">-</span> <span style="color: #000066;">&#40;</span><span style="color: #000066;">&#40;</span>typRectMsg<span style="color: #000066;">\</span><span style="color: #0000ff;">Right</span> <span style="color: #000066;">-</span> typRectMsg<span style="color: #000066;">\</span><span style="color: #0000ff;">Left</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">/</span> <span style="color: #CC0000;">2</span><span style="color: #000066;">&#41;</span>
					lyPos <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>typFormRect<span style="color: #000066;">\</span>Top  <span style="color: #000066;">+</span>	<span style="color: #000066;">&#40;</span>typFormRect<span style="color: #000066;">\</span>Bottom <span style="color: #000066;">-</span> typFormRect<span style="color: #000066;">\</span>Top<span style="color: #000066;">&#41;</span> <span style="color: #000066;">/</span> <span style="color: #CC0000;">2</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">-</span> <span style="color: #000066;">&#40;</span><span style="color: #000066;">&#40;</span>typRectMsg<span style="color: #000066;">\</span>Bottom <span style="color: #000066;">-</span> typRectMsg<span style="color: #000066;">\</span>Top<span style="color: #000066;">&#41;</span> <span style="color: #000066;">/</span> <span style="color: #CC0000;">2</span><span style="color: #000066;">&#41;</span>
&nbsp;
					SetWindowPos_<span style="color: #000066;">&#40;</span> wParam, <span style="color: #CC0000;">0</span>, lxPos, lyPos, <span style="color: #CC0000;">0</span>, <span style="color: #CC0000;">0</span>,	#SWP_NOSIZE <span style="color: #000066;">|</span> #SWP_NOZORDER <span style="color: #000066;">|</span> #SWP_NOACTIVATE <span style="color: #000066;">&#41;</span> 														<span style="color: #ff0000; font-style: italic;">; position the window.</span>
					UnhookWindowsHookEx_<span style="color: #000066;">&#40;</span>plMsgHook<span style="color: #000066;">&#41;</span> 																																													<span style="color: #ff0000; font-style: italic;">; release the hook.</span>
					SetWindowLong_<span style="color: #000066;">&#40;</span> hWnd, #GWL_USERDATA, #Null <span style="color: #000066;">&#41;</span> 																																							<span style="color: #ff0000; font-style: italic;">; unset the user data.</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">EndIf</span>
	<span style="color: #000066; font-weight: bold;">EndSelect</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span> 
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i CenteredMessageRequester<span style="color: #000066;">&#40;</span> Title.s, Text.s, Flags.i<span style="color: #000066;">=</span>#Null, hWnd.i<span style="color: #000066;">=</span>#Null <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.i lInstance, lThreadID, plMsgHook
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066; font-weight: bold;">Not</span> hWnd
		hWnd <span style="color: #000066;">=</span> <span style="color: #0000ff;">WindowID</span><span style="color: #000066;">&#40;</span> <span style="color: #0000ff;">GetActiveWindow</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> hWnd
&nbsp;
		lInstance <span style="color: #000066;">=</span> GetWindowLong_<span style="color: #000066;">&#40;</span> hWnd, #GWL_HINSTANCE <span style="color: #000066;">&#41;</span>
		lThreadID <span style="color: #000066;">=</span> GetCurrentThreadId_<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> lInstance <span style="color: #000066; font-weight: bold;">And</span> lThreadID 																																																			<span style="color: #ff0000; font-style: italic;">; just to make sure, can't hurt.</span>
&nbsp;
			plMsgHook <span style="color: #000066;">=</span> SetWindowsHookEx_<span style="color: #000066;">&#40;</span>#WH_CBT, @CenterMsgCallBack<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, lInstance, lThreadID<span style="color: #000066;">&#41;</span> 																						<span style="color: #ff0000; font-style: italic;">; create the cbt hook.</span>
			SetWindowLong_<span style="color: #000066;">&#40;</span>	hWnd, #GWL_USERDATA, plMsgHook <span style="color: #000066;">&#41;</span> 																																							<span style="color: #ff0000; font-style: italic;">; save the hook address, we'll need it to release it.</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> MessageBox_<span style="color: #000066;">&#40;</span> hWnd, Text, Title, Flags <span style="color: #000066;">&#41;</span>																																				<span style="color: #ff0000; font-style: italic;">; finally, create the message box.</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">EndIf</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>And a small example:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #0000ff;">OpenWindow</span><span style="color: #000066;">&#40;</span> <span style="color: #CC0000;">0</span>, <span style="color: #CC0000;">500</span>, <span style="color: #CC0000;">200</span>, <span style="color: #CC0000;">400</span>, <span style="color: #CC0000;">200</span>, <span style="color: #009900;">&quot;testing&quot;</span> <span style="color: #000066;">&#41;</span>																																											<span style="color: #ff0000; font-style: italic;">; test window</span>
<span style="color: #0000ff;">MessageRequester</span><span style="color: #000066;">&#40;</span> <span style="color: #009900;">&quot;:(&quot;</span>, <span style="color: #009900;">&quot;I'm a normal messagebox&quot;</span>, #MB_APPLMODAL <span style="color: #000066;">|</span> #MB_ICONERROR <span style="color: #000066;">&#41;</span>																									<span style="color: #ff0000; font-style: italic;">; conventional msgbox</span>
CenteredMessageRequester<span style="color: #000066;">&#40;</span> <span style="color: #009900;">&quot;:)&quot;</span>, <span style="color: #009900;">&quot;I'm a centered messagebox!&quot;</span>, #MB_APPLMODAL <span style="color: #000066;">|</span> #MB_ICONEXCLAMATION <span style="color: #000066;">&#41;</span>																	<span style="color: #ff0000; font-style: italic;">; our centered msgbox.</span></pre></div></div>

<p>The &#8220;Programmer&#8221; can now copy&amp;paste and compile.</p>
<p>Cheers.</p>
<p>PS: You can also find the source in here: <a href="http://gushh.net/dev/?file=pb/centermessagebox.pb">http://gushh.net/dev/?file=pb/centermessagebox.pb</a> As usual, that&#8217;s my code repository for PB.</p>
<g:plusone href='http://gushh.net/blog/pb-centered-messagerequester/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/pb-centered-messagerequester/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Purebasic language submitted to GeSHi</title>
		<link>http://gushh.net/blog/purebasic-language-submitted-to-geshi/</link>
		<comments>http://gushh.net/blog/purebasic-language-submitted-to-geshi/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 17:33:17 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[GeSHi]]></category>
		<category><![CDATA[pb]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[Syntax Highlighting]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/2009/06/13/purebasic-language-submitted-to-geshi/</guid>
		<description><![CDATA[Submitted my GeSHi language file for PureBasic to the GeSHi author, I&#8217;ve been using it for a while now and I thought it was about time to share it. I couldn&#8217;t however validate it since I&#8217;m short in time at the moment &#8212; I&#8217;m just posting everything I couldn&#8217;t post in the last weeks today. [...]]]></description>
			<content:encoded><![CDATA[<p>Submitted my GeSHi language file for PureBasic to the GeSHi author, I&#8217;ve been using it for a while now and I thought it was about time to share it. I couldn&#8217;t however validate it since I&#8217;m short in time at the moment &#8212; I&#8217;m just posting everything I couldn&#8217;t post in the last weeks today.</p>
<p>Let&#8217;s hope it becomes part of their project now. I&#8217;ll certainly keep it up to date when I get the time for it. And let&#8217;s face it, their lib is pretty much the standard for PHP syntax highlighting!.</p>
<p>Come to think of it, I think this current CSS style is killing my syntax highlighting&#8230; Hmm. Another one for the to-do list.</p>
<p>Cheers.</p>
<g:plusone href='http://gushh.net/blog/purebasic-language-submitted-to-geshi/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/purebasic-language-submitted-to-geshi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: gushh.net @ 2012-02-05 15:50:28 by W3 Total Cache -->
