<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>C++ on mapletree.moe</title><link>https://mapletree.moe/tags/c++/</link><description>Recent content in C++ on mapletree.moe</description><generator>Hugo -- 0.160.1</generator><language>en-us</language><copyright>This work is licensed under the MIT0 License.</copyright><lastBuildDate>Mon, 14 Dec 2015 15:30:00 -0500</lastBuildDate><atom:link href="https://mapletree.moe/tags/c++/index.xml" rel="self" type="application/rss+xml"/><item><title>C++ GUI Library Hell</title><link>https://mapletree.moe/posts/cpp-gui-library-hell/</link><pubDate>Mon, 14 Dec 2015 15:30:00 -0500</pubDate><author>bakayuki</author><guid>https://mapletree.moe/posts/cpp-gui-library-hell/</guid><description>&amp;lt;no value&amp;gt;</description><content type="text/html" mode="escaped"><![CDATA[<p>So, one of the many projects that I have been working on as of late is a game
engine for a small game studio called Near The Resolution. Really awesome
people to work for, lemme tell ya. They are allowing me to release the engine
under one of my crazy &ldquo;No Rights Reserved&rdquo; licenses. I have learned that one
of the unfortunate parts of game design is that if you&rsquo;re not using C++ then
you are essentially doomed to having to rewrite the wheel. After a lot of
research, I settled on utilizing SFML as the basis of the game engine, because
it is released under zlib.</p>
<p>One of the many, I suppose, <em>features</em> of C++ is that a number of libraries are
available for solving things without having to rewrite the wheel. This makes me
personally uncomfortable on a number of levels, but that comes with
<a href="https://warp.povusers.org/OpenLetters/ResponseToTorvalds.html">&ldquo;C Hacker Syndrome&rdquo;</a> which I definitely suffer from. Anyways, I decided
that I would attempt to put this.. <em>feature</em> to my advantage, and find a GUI
library that works properly with SFML, is clean and simple, and is small.</p>
<p>Turns out, this isn&rsquo;t actually possible.</p>
<h1 id="sfgui"><a href="https://sfgui.sfml-dev.de">SFGUI</a><a href="#sfgui" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
      stroke-linecap="round" stroke-linejoin="round" class="feather">
      <path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path>
      <line x1="8" y1="12" x2="16" y2="12"></line>
   </svg></a></h1>
<p>SFGUI is the first thing I spent time working on. The problem with SFGUI is it
suffers from &ldquo;There&rsquo;s a fleck on the speck on the tail on the frog on the bump
on the branch on the log in the hole in the bottom of the sea&rdquo; Syndrome. If you
want to make a button, for example.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="c1">// Create the label.
</span></span></span><span class="line"><span class="cl"><span class="n">m_label</span> <span class="o">=</span> <span class="n">sfg</span><span class="o">::</span><span class="n">Label</span><span class="o">::</span><span class="n">Create</span><span class="p">(</span> <span class="s">&#34;Hello world!&#34;</span> <span class="p">);</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// Create a simple button and connect the click signal.
</span></span></span><span class="line"><span class="cl"><span class="k">auto</span> <span class="n">button</span> <span class="o">=</span> <span class="n">sfg</span><span class="o">::</span><span class="n">Button</span><span class="o">::</span><span class="n">Create</span><span class="p">(</span> <span class="s">&#34;Greet SFGUI!&#34;</span> <span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="n">button</span><span class="o">-&gt;</span><span class="n">GetSignal</span><span class="p">(</span> <span class="n">sfg</span><span class="o">::</span><span class="n">Widget</span><span class="o">::</span><span class="n">OnLeftClick</span> <span class="p">).</span><span class="n">Connect</span><span class="p">(</span> <span class="n">std</span><span class="o">::</span><span class="n">bind</span><span class="p">(</span> <span class="o">&amp;</span><span class="n">HelloWorld</span><span class="o">::</span><span class="n">OnButtonClick</span><span class="p">,</span> <span class="k">this</span> <span class="p">)</span> <span class="p">);</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// Create a vertical box layouter with 5 pixels spacing and add the label
</span></span></span><span class="line"><span class="cl"><span class="c1">// and button to it.
</span></span></span><span class="line"><span class="cl"><span class="k">auto</span> <span class="n">box</span> <span class="o">=</span> <span class="n">sfg</span><span class="o">::</span><span class="n">Box</span><span class="o">::</span><span class="n">Create</span><span class="p">(</span> <span class="n">sfg</span><span class="o">::</span><span class="n">Box</span><span class="o">::</span><span class="n">Orientation</span><span class="o">::</span><span class="n">VERTICAL</span><span class="p">,</span> <span class="mf">5.0f</span> <span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="n">box</span><span class="o">-&gt;</span><span class="n">Pack</span><span class="p">(</span> <span class="n">m_label</span> <span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="n">box</span><span class="o">-&gt;</span><span class="n">Pack</span><span class="p">(</span> <span class="n">button</span><span class="p">,</span> <span class="nb">false</span> <span class="p">);</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// Create a window and add the box layouter to it. Also set the window&#39;s title.
</span></span></span><span class="line"><span class="cl"><span class="k">auto</span> <span class="n">window</span> <span class="o">=</span> <span class="n">sfg</span><span class="o">::</span><span class="n">Window</span><span class="o">::</span><span class="n">Create</span><span class="p">();</span>
</span></span><span class="line"><span class="cl"><span class="n">window</span><span class="o">-&gt;</span><span class="n">SetTitle</span><span class="p">(</span> <span class="s">&#34;Hello world!&#34;</span> <span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="n">window</span><span class="o">-&gt;</span><span class="n">Add</span><span class="p">(</span> <span class="n">box</span> <span class="p">);</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// Create a desktop and add the window to it.
</span></span></span><span class="line"><span class="cl"><span class="n">sfg</span><span class="o">::</span><span class="n">Desktop</span> <span class="n">desktop</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="n">desktop</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span> <span class="n">window</span> <span class="p">);</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// We&#39;re not using SFML to render anything in this program, so reset OpenGL
</span></span></span><span class="line"><span class="cl"><span class="c1">// states. Otherwise we wouldn&#39;t see anything.
</span></span></span><span class="line"><span class="cl"><span class="n">render_window</span><span class="p">.</span><span class="n">resetGLStates</span><span class="p">();</span>
</span></span></code></pre></div><p>So you want a button. There&rsquo;s a Label on the button in the box on the window
on the desktop in the SFML window on the openGL at the bottom of the code tree.
Needless to say, this lasted about five minutes in our source tree before I
broke down sobbing. Not to mention, the entire system renders in its own area
of the main SFML window. So when I tried to make an SFGUI button in the SFML
window on top of our background, yeah it didn&rsquo;t go to well, and I don&rsquo;t need
<em>another</em> engine on top of the engine on top of this game engine. That&rsquo;s just..
absurd. Not to mention the documentation sucks. I hate crappy documentation.</p>
<h1 id="tgui"><a href="https://tgui.eu">TGUI</a><a href="#tgui" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
      stroke-linecap="round" stroke-linejoin="round" class="feather">
      <path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path>
      <line x1="8" y1="12" x2="16" y2="12"></line>
   </svg></a></h1>
<p>TGUI bills itself as the &ldquo;Simple GUI&rdquo; for SFML. So naturally, I was really
quite excited to try it out. Until I figured out it required configuration
files, and every button had to be an image or it wouldn&rsquo;t render. So in theory,
you couldn&rsquo;t have a completely transparent button, which is one of the things
that this game will require. Secondly, if you require a configuration syntax,
you are <em>not</em> a simple library. Ever. All I want is to be able to call methods
that create a button.</p>
<h1 id="cegui"><a href="https://cegui.org.uk">CEGUI</a><a href="#cegui" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
      stroke-linecap="round" stroke-linejoin="round" class="feather">
      <path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path>
      <line x1="8" y1="12" x2="16" y2="12"></line>
   </svg></a></h1>
<p>Desperate times call for desperate measures. Or so I believed. Problem is,
CEGUI actually contains its own OpenGL renderer, which is redundant on top of
SFML. There is never a reason to have two OpenGL renderers, they will conflict.
Furthermore, CEGUI requires XML. Which is -not- a simple library. They claim
that this is to reduce the frustration of having to change your code to adjust
the GUI interface, but I would rather adjust my code than end up dependent on
XML files.</p>
<h1 id="conclusion">Conclusion<a href="#conclusion" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
      stroke-linecap="round" stroke-linejoin="round" class="feather">
      <path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path>
      <line x1="8" y1="12" x2="16" y2="12"></line>
   </svg></a></h1>
<p>At the end of the day, All I really need to do for this particular engine is
lay out a few menus and then a general presentation on top of those for the
in game content. So I used <a href="https://www.bromeon.ch/libraries/thor/">Thor</a> to render shapes, and then I&rsquo;m writing my
own logic on top of that. This gives me total control over the implementation,
and the logic of the GUI system. Maybe I&rsquo;m strange in that I don&rsquo;t mind having
to change values in my code and recompile, but I honestly prefer to do that.
Control over individual placement makes sense, and most of the time I define
my placement on top of positioning logic, so in those cases it makes more sense
to have it in the code than in an external file.</p>
]]></content></item></channel></rss>