<?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>Guy Rutenberg &#187; wxWidgets</title>
	<atom:link href="http://www.guyrutenberg.com/tag/wxwidgets/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guyrutenberg.com</link>
	<description>Keeping track of what I do</description>
	<lastBuildDate>Sat, 14 Jan 2012 11:30:25 +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>Simple Histogram Widget for wxWidgets</title>
		<link>http://www.guyrutenberg.com/2009/08/13/simple-histogram-widget-for-wxwidgets/</link>
		<comments>http://www.guyrutenberg.com/2009/08/13/simple-histogram-widget-for-wxwidgets/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 20:25:28 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[wxWidgets]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=444</guid>
		<description><![CDATA[When working on Open Yahtzee 1.10 (or what ever I&#8217;ll call the version after 1.9), I&#8217;ve written a simple histogram widget to be part of the new statistics dialog. I should emphasize the simple part, this widget was mean to display a simple histogram without requiring any special bloated ploting libraries. It doesn&#8217;t support all [...]]]></description>
			<content:encoded><![CDATA[<p>When working on <a href="http://www.openyahtzee.org/">Open Yahtzee</a> 1.10 (or what ever I&#8217;ll call the version after 1.9), I&#8217;ve written a simple histogram widget to be part of the new statistics dialog. I should emphasize the <em>simple</em> part, this widget was mean to display a simple histogram without requiring any special bloated ploting libraries. It doesn&#8217;t support all the fancy stuff, just plain histogram. </p>
<p>I&#8217;ve figured that a simple pie plot would better serve Open Yahtzee&#8217;s needs, so unfortunately this code will not be released as part of the program. While the code is not perfect, it&#8217;s functional and serves a good example of a custom widget. So I&#8217;ve felt pity letting it fall into oblivion in Open Yahtzee&#8217;s SVN repository, and I&#8217;ve thought it might come handy to someone else (or at least for me) if it will be easily accessible.</p>
<p><img src="http://www.guyrutenberg.com/wp-content/uploads/2009/08/simple_histogram.png" alt="simple_histogram" title="simple_histogram" width="320" height="254" class="alignnone size-full wp-image-450" /><br />
<span id="more-444"></span><br />
The widget is made up of two files: <code>simple_histogram.h</code> and <code>simple_histogram.cpp</code>. The code uses <code>stl::vector</code> to pass the plotting data and depenpends on <code>BOOST_FOREACH</code> (but it can easily be removed).</p>
<p><code>simple_histogram.h</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/***************************************************************************
 *   Copyright (C) 2009 by Guy Rutenberg   *
 *   http://www.guyrutenberg.com/contact-me   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/</span>
&nbsp;
<span style="color: #339900;">#include &lt;wx/wx.h&gt;</span>
<span style="color: #339900;">#include &lt;vector&gt;</span>
&nbsp;
<span style="color: #339900;">#ifndef SIMPLE_HISTOGRAM_INC</span>
<span style="color: #339900;">#define SIMPLE_HISTOGRAM_INC</span>
&nbsp;
<span style="color: #0000ff;">class</span> SimpleHistogram <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> wxPanel <span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
	SimpleHistogram <span style="color: #008000;">&#40;</span>wxWindow<span style="color: #000040;">*</span> parent, wxWindowID id,
		 <span style="color: #0000ff;">const</span> wxPoint<span style="color: #000040;">&amp;</span> pos <span style="color: #000080;">=</span> wxDefaultPosition, <span style="color: #0000ff;">const</span> wxSize<span style="color: #000040;">&amp;</span> size <span style="color: #000080;">=</span> wxDefaultSize,
		 <span style="color: #0000ff;">long</span> style <span style="color: #000080;">=</span> wxNO_BORDER, <span style="color: #0000ff;">const</span> wxString<span style="color: #000040;">&amp;</span> name <span style="color: #000080;">=</span> wxPanelNameStr<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">void</span> SetData<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span><span style="color: #000080;">&gt;</span> d<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">void</span> OnPaint<span style="color: #008000;">&#40;</span>wxPaintEvent<span style="color: #000040;">&amp;</span> event<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">void</span> OnResize<span style="color: #008000;">&#40;</span>wxSizeEvent<span style="color: #000040;">&amp;</span> event<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
	std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span><span style="color: #000080;">&gt;</span> data<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">double</span> data_total<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #339900;">#endif</span></pre></div></div>

<p><code>simple_histogram.cpp</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/***************************************************************************
 *   Copyright (C) 2009 by Guy Rutenberg   *
 *   http://www.guyrutenberg.com/contact-me   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/</span>
&nbsp;
<span style="color: #339900;">#include &quot;simple_histogram.h&quot;</span>
<span style="color: #339900;">#include &lt;boost/foreach.hpp&gt;</span>
<span style="color: #339900;">#include &lt;memory&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
SimpleHistogram<span style="color: #008080;">::</span><span style="color: #007788;">SimpleHistogram</span><span style="color: #008000;">&#40;</span>wxWindow<span style="color: #000040;">*</span> parent, wxWindowID id,
				<span style="color: #0000ff;">const</span> wxPoint<span style="color: #000040;">&amp;</span> pos, <span style="color: #0000ff;">const</span> wxSize<span style="color: #000040;">&amp;</span> size,
				<span style="color: #0000ff;">long</span> style, <span style="color: #0000ff;">const</span> wxString<span style="color: #000040;">&amp;</span> name<span style="color: #008000;">&#41;</span>
				<span style="color: #008080;">:</span> wxPanel<span style="color: #008000;">&#40;</span>parent, id, pos, size, style, name<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	Connect<span style="color: #008000;">&#40;</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>GetId<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, wxEVT_PAINT, wxPaintEventHandler<span style="color: #008000;">&#40;</span>SimpleHistogram<span style="color: #008080;">::</span><span style="color: #007788;">OnPaint</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	Connect<span style="color: #008000;">&#40;</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>GetId<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, wxEVT_SIZE, wxSizeEventHandler<span style="color: #008000;">&#40;</span>SimpleHistogram<span style="color: #008080;">::</span><span style="color: #007788;">OnResize</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> SimpleHistogram<span style="color: #008080;">::</span><span style="color: #007788;">OnPaint</span><span style="color: #008000;">&#40;</span>wxPaintEvent<span style="color: #000040;">&amp;</span> event<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	wxPaintDC pdc<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">this</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	auto_ptr<span style="color: #000080;">&lt;</span>wxGraphicsContext<span style="color: #000080;">&gt;</span> dc<span style="color: #008000;">&#40;</span>wxGraphicsContext<span style="color: #008080;">::</span><span style="color: #007788;">Create</span><span style="color: #008000;">&#40;</span>pdc<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	dc<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>SetBrush<span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>wxBLUE_BRUSH<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> width, height<span style="color: #008080;">;</span>
	GetClientSize<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>width, <span style="color: #000040;">&amp;</span>height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">double</span> column_width <span style="color: #000080;">=</span> <span style="color: #0000ff;">static_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>width<span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> data.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">double</span> item_x, item_y, item_ratio, item_height<span style="color: #008080;">;</span>
	BOOST_FOREACH<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">double</span> d, data<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		item_x <span style="color: #000080;">=</span> i <span style="color: #000040;">*</span> column_width<span style="color: #008080;">;</span>
		item_ratio <span style="color: #000080;">=</span> data_total <span style="color: #008080;">?</span> d<span style="color: #000040;">/</span>data_total <span style="color: #008080;">:</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
		item_height <span style="color: #000080;">=</span> item_ratio <span style="color: #000040;">*</span> height<span style="color: #008080;">;</span>
		item_y <span style="color: #000080;">=</span> height<span style="color: #000040;">-</span>item_height<span style="color: #008080;">;</span>
		dc<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>DrawRectangle<span style="color: #008000;">&#40;</span>item_x, item_y, column_width, item_height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		i<span style="color: #000040;">++</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> SimpleHistogram<span style="color: #008080;">::</span><span style="color: #007788;">OnResize</span><span style="color: #008000;">&#40;</span>wxSizeEvent<span style="color: #000040;">&amp;</span> event<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	Refresh<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	event.<span style="color: #007788;">Skip</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> SimpleHistogram<span style="color: #008080;">::</span><span style="color: #007788;">SetData</span><span style="color: #008000;">&#40;</span>vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span><span style="color: #000080;">&gt;</span> d<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	data.<span style="color: #007788;">assign</span><span style="color: #008000;">&#40;</span>d.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, d.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	data_total <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	BOOST_FOREACH<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">double</span> tmp, data<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		data_total <span style="color: #000040;">+</span><span style="color: #000080;">=</span> tmp<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><strong>UPDATE 2009-08-17:</strong> Removed commented out function &#8211; <code>DoGetBestSize()</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/08/13/simple-histogram-widget-for-wxwidgets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setting Up OmniComplete (Autocompletion) for wxWidgets in Vim</title>
		<link>http://www.guyrutenberg.com/2008/02/23/setting-up-omnicomplete-autocompletion-for-wxwidgets-in-vim/</link>
		<comments>http://www.guyrutenberg.com/2008/02/23/setting-up-omnicomplete-autocompletion-for-wxwidgets-in-vim/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 19:27:11 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[wxWidgets]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/2008/02/23/setting-up-omnicomplete-autocompletion-for-wxwidgets-in-vim/</guid>
		<description><![CDATA[I use Vim as my main IDE for C/C++ related development (as well as for almost all other development). If you use (or thinking about using) vim as as an IDE, you better get some good autocompletion functionality. This kind of autocompletion is provided by the OmniComplete, which is available since Vim 7.0. Just having [...]]]></description>
			<content:encoded><![CDATA[<p>I use Vim as my main IDE for C/C++ related development (as well as for almost all other development). If you use (or thinking about using) vim as as an IDE, you better get some good autocompletion functionality. This kind of autocompletion is provided by the OmniComplete, which is available since Vim 7.0. Just having  the OmniComplete is a nice thing, but it&#8217;s much more helpful if configured properly to work with the libraries you use, such as wxWidgets. In this post I will show you how to get working the OmniComplete for wxWidgets, however, the procedure I will show can be easily adapted to almost all libraries.<br />
<span id="more-41"></span></p>
<p>The first step is to install <code>ctags</code> (if you haven&#8217;t got it already installed), this provides the tags file, on which the autocompletion is based. <code>ctags</code> is available directly from the package manager of all popular distro&#8217;s.</p>
<p>The next step is to install the <a href="http://www.vim.org/scripts/script.php?script_id=1520">OmniCppComplete</a> plugin for vim. The plugin uses the <code>ctags</code>&#8216; generated tags file for the autocompletion. In order for the autocompletion to properly work with classes, you need to create the <code>~/.ctags</code> file and add some default options. Each option should be listed in a newline. Your <code>~/.ctags</code> file should look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">--c++-kinds=+p
--fields=+iaS
--extra=+q</pre></div></div>

<p>These options will now be used as default when running <code>ctags</code>.</p>
<p>The next step is to create a tag file for the wxWidgets library. This can be done using the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"> ctags -f ~/.vim/wxwidgetstags -R /usr/include/wx-2.8</pre></div></div>

<p>Don&#8217;t forget to replace <code>/usr/include/wx-2.8</code> with the path to the header files of wxWidgets. This will create the tags file under your <code>~/.vim</code> directory.</p>
<p>The next step is to tell vim to use this tags file. This is done by adding the following line to your <code>~/.vimrc</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">:set tags+=~/.vim/wxwidgetstags</pre></div></div>

<p>And now your done. OmniComplete will now work for wxWidgets, listing members and functions for any of the wxWidgets classes.<br />
Remember you can repeat the last two steps for any other libraries you use in order for the OmniComplete to work with them too.</p>
<p>N.B. don&#8217;t forget to run <code>ctags -R .</code> in your projects root dir if you want OmniComplete to work for classes you defined.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2008/02/23/setting-up-omnicomplete-autocompletion-for-wxwidgets-in-vim/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.347 seconds -->

