Month: January 2015

Color Scheme Design the Easy Way

Colour for me is an annoyance, I know what goes together, but can’t actually make them up. It normally takes me ages trialing hex values to get something that doesn’t look awful, even in primary school I was always the one who mixed so much together that my palette more often than not ended up a brown-purply soup.

That’s where Paletton comes in. There are a plethora of hex colours that go together! Sorted!

I’m considering creating a Shade Lovers site that deals with varying shades of grey. I’m a stickler for semantics, so if I ever catch so much as a whiff of #000, #fff and their friends then I’m going to be sending an angry email to the Paletton website.

Stop Console Popup Problem: Gtkmm Windows

Fed up with the .dll overheads of wxPython and Python, I’m using gtkmm as my standard GUI toolkit from now on.

I’ve got all the libraries installed on Windows XP and Slackware using the gtkmm documentation, so I’m looking forward to nice portable apps.

There was one slight problem that had me stumped: on Windows the executable causes a console window to pop up along with the main GUI. I Googled to no avail, until today; evidently a fresh pair of eyes brings a new perspective to the problem. If you’re using Dev-C++ go to “Project” → “Type” and select “Win32 GUI”. I don’t know how I missed that one, then again it was about 11:30pm.

What this does is add the -mwindows flag to the g++ compiler. If you’re interested, here are my C++ compiler flags:

-IC:/Dev-Cpp/include/gtkmm/include/gtkmm-2.4 -IC:/Dev-Cpp/include/gtkmm/lib/gtkmm-2.4/include -IC:/Dev-Cpp/include/gtkmm/include/glibmm-2.4 -IC:/Dev-Cpp/include/gtkmm/lib/glibmm-2.4/include -IC:/Dev-Cpp/include/gtkmm/include/gdkmm-2.4 -IC:/Dev-Cpp/include/gtkmm/lib/gdkmm-2.4/include -IC:/Dev-Cpp/include/gtkmm/include/pangomm-1.4
-IC:/Dev-Cpp/include/gtkmm/include/atkmm-1.6
-IC:/Dev-Cpp/include/gtkmm/include/sigc++-2.0 -IC:/Dev-Cpp/include/gtkmm/lib/sigc++-2.0/include
-IC:/GTK/include/gtk-2.0 -IC:/GTK/include/glib-2.0
-IC:/GTK/lib/glib-2.0/include -IC:/GTK/lib/gtk-2.0/include
-IC:/GTK/include/pango-1.0 -IC:/GTK/include/atk-1.0

Also my linker flags:

-LC:/Dev-Cpp/include/gtkmm/lib -LC:/GTK/lib -lgtkmm-2.4 -lgdkmm-2.4 -latkmm-1.6 -lgtk-win32-2.0 -lpangomm-1.4 -lglibmm-2.4 -lsigc-2.0 -lgdk-win32-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl -liconv

I didn’t get all those by hand either, use pkg-config from the console prompt with the instructions as outlined in the documentation. If you’re unsure of how to set the PATH environmental variable in Windows, you might want to have a look at my gpg for Windows post.

Cross Compiling Gtkmm Applications to Windows

There’s a readily available Gtkmm development package for Windows, but the following could come in handy for those who don’t own Windows, or want to escape the inconvenience of setting up and booting into another environment. A basic understanding of using the console is required and though I’m using Ubuntu, the steps are easily transferable.

First you’ll need to install the following packages and their dependencies:

mingw32
wine

Wine is only required if you don’t have access to Windows and want to check basic functionality. For a simple example I’m going to cross-compile the Hello World program in the Gtkmm documentation:

g++ helloworld.cc main.cc -o helloworld `pkg-config gtkmm-2.4 –cflags –libs`

This will compile and link “Hello World” for regular use under the Ubuntu environment. To make an .exe we need to alter this in two ways:

  1. Substitute g++ with the equivalent Windows build.
  2. Tell pkg-config to use Windows development Gtkmm dlls instead of the Ubuntu development shared objects.

The first part should be provided by the mingw32 suite you installed earlier. On my system it installed:

i586-mingw32msvc-g++

Conveniently the Inkscape project supplies the Gtk/Gtkmm development dlls all in one place and provides the basis for the following instructions. What they’ve done is set the pkg-config paths to work from /target, so you can put the unzipped directory wherever you want, as long as you create a symbolic link to it from /target as root:

ln -sf /home/alex/gtk28 /target

The next instruction gives precedence to the libraries in /target, rather than on your system, by temporarily changing the first location pkg-config searches:

export PKG_CONFIG_PATH=/target/lib/pkgconfig

You can check if this worked by examining that /target is the prefix for the relevant flags:

pkg-config gtkmm-2.4 –cflags –libs

Once it’s all working you can create the .exe with the following:

i586-mingw32msvc-g++ helloworld.cc main.cc -o helloworld `pkg-config gtkmm-2.4 –cflags –libs`

You can add the mwindows flag is to stop the console popping up, but I left it out to demonstrate the complete program on the right, running under Windows. If you don’t have Windows you can use Wine to test it loads, but be aware I had some problems regarding missing fonts that would otherwise be available–but essentially it will work fine given a proper Windows installation.

When distributing your application, you either need to direct your users to install the Gtk and Gtkmm runtime environments, or download them yourself and lump the dlls in the same directory as your binary (have a look at the Inkscape Windows zip file). I’ve managed to get the total build size down to about 8MB by deleting some locales and using UPX, and that example is running off my USB key.