Icon is a small graphics object that can be associated with various other user interface objects, such as buttons and tabs.
To create an icon:
Create a sub folder 'icons', keeping all icons in a separate folder is a good programming practice
Paint your icon and save it as 8 bit Microsoft .ico image (say icons/foo.ico).
Create a makefile 'icons/makefile' for compiling your icons. The structure of the makefile is as follows:
V4TARGET=mytoolset V4ICONWIDTH=24 V4ICONHEIGHT=16 V4ICONDEPTH=8 IFILES=foo.ico !include $(V4HOME)/$(V4MKRES).mak
where V4TARGET must match the name of the library which will contain your icon.
Enter 'make' in the icons folder. This will create 'foo.h' file, which you can then include with your source file to actually use the icons graphics. On Windows, this will also create two resource files 'myplugin.rc' and 'myplugin.res'.
Most gadgets accep R3GA_Icon attribute, which you can use to pass an icon to the gadget. The following code creates a button with an icon.
#include <oops/r3icon.h> /* icon class */ #include <oops/r3button.h> /* button class */ #include "icons/foo.h" /* my icon specific header */ /* create an icon object */ icon = R3New(R3CLID_ICON, R3ICONA_Data, foo_bits, R3ICONA_Width, foo_width, R3ICONA_Height, foo_height, R3ICONA_Depth, foo_depth, R3TAG_END); /* create a button which uses the icon */ button = R3New(R3CLID_BUTTON, R3GA_Icon, icon, ...
![]() |
Note |
---|---|
The contents of header file 'foo.h' is platform specific. Newer write these header files manually. You have to use the SDK to generate them from the .ico files. |
Because the icon size must be defined in the makefile, one has to create multiple makefiles in order to create icon sets with different size.
If you are implementing a plugin which implements both tools and geometric objects, you'll need to paint icons with two size:
Correspondingly, you will need to write two makefiles: one for 32x16 icons and one for the 24x16 icons:
V4LIBNAME=myplugin V4TARGET=myplugin24 V4ICONWIDTH=24 V4ICONHEIGHT=16 V4ICONDEPTH=8 V4NORES=TRUE IFILES=small.ico !include $(V4HOME)/$(V4MKRES).mak
The V4NORES makefile tells the resource compiler that it should not compile the final binary, just generate the header files from the icons (and additional myplugin16.rc on windows).
The second makefile would look as follows:
V4LIBNAME=myplugin V4TARGET=myplugin32 V4ICONWIDTH=32 V4ICONHEIGHT=16 V4ICONDEPTH=8 V4NORES=TRUE IFILES=big.ico !include $(V4HOME)/$(V4MKRES).mak
And then you need one additional makefile, say 'makejoin', which is needed to join the two intermediate resource files into the final myplugin.res. Note that this makejoin makefile is effective only on Windows platform. It doesn't do anything on other platforms.
V4TARGET=myplugin RCFILES=myplugin24.rc myplugin32.rc !include $(V4HOME)/$(V4MKRES).mak
Typing three 'make' commands every time you need to rebuild the icons doesn't make any sense, so you should write fourth makefile, which takes care of everything in one 'make' command.
!include $(V4HOME)/$(V4OS).mak all depend clean strings static: $(MAKE) $(MAKEOPTS) $@ -f make24x16 $(MAKE) $(MAKEOPTS) $@ -f make32x16 $(MAKE) $(MAKEOPTS) $@ -f makejoin
![]() |
Note |
---|---|
You may wonder why the makefile has to contain the icon sizes. The reason for this is that Microsoft .ico format supports only certain fixed sizes. So you have to paint an icon which is big enough to hold the actual graphics and then tell the makefile to crop the desired sub image from the .ico file with V4ICONWIDTH and V4ICONHEIGHT variables. |
Another problem with .ico is that not that many image programs can write or read it (Microsoft Visual Studio is perhaps the most well know one). In fact, it is quite difficult to find an image format which would be more screwed up than Microsoft .ico.