![]() ![]() |
![]() |
|||||||||
![]() |
![]() |
|||||||||
Home News Download Goals & Approach Documentation FAQ Screenshots Adie PathFinder FOX Calculator Projects FXPy FXRuby EiffelFox The FOX Hole Japanese Docs ![]() |
![]() Documentation: Icons and Images
Icons and Images Icons and Images are part an parcel of attractive, user-friendly Graphical User Interfaces these days. Consequently, considerable effort has been expended in designing FOX to allow icon- and image-rich applications to be developed with the greatest ease. In FOX, Images and Icons are objects that represent picture data. Images are simple pictures, whereas Icons are pictures with a shape mask that may be used to effectively mask out a certain area of the picture, and allow part the background to peek through as if the picture were transparent in some areas. Both Icons and Images may have Client side pixel data as well as an X Server side pixmap representation. The typical application will construct the client-side pixel data by filling the Icon or Image with a picture, then create the server-side representation [after contact with the X Server has been established] by calling icon->create(), which creates an server side pixmap and uses a call to icon->render() to fill the pixmap with the pixel data . Note that this is a two-step process which is very similar to that of constructing and creating regular FOX Widgets. This is no accident. The FOX philosophy is to construct [client-side] data structures such as Widgets and Icons and Images etc., then with all the information available, create their X Server side representation in one fell swoop by calling app->create(). When you have given Buttons or Labels or other FOX Widgets icons, a call to that Widget's create() member function will also automatically call its icon create(). To allow icons to be shared by multiple Widgets, it is specifically allowed to call create() more than once on an icon or image. In many cases, after calling an icon's create() member function, there is no need to keep the client-side pixel data around; thus, FOX icons will in most cases release the memory taken up by the pixel data. Should you want to repeatedly change the pixel data, however, FXIcon and FXImage have an option IMAGE_KEEP to allow you to hang on to the pixel data in the client. After making changes to the pixel data, you can call icon->render() again to render it into the pixmap.
Image Formats Supported Currently, FOX supports GIF, BMP, PNG, JPEG, XPM, TIFF, ICO and PCX based icons/images. In the near future, PPM will be added as a convenience. The most preferred format is GIF, as it is about 10 times more compact than XPM, and about 2 times more compact than BMP. This is of some concern, as applications may have lots of icons [some analysis of our own applications revealed than one application's executable had about 1MB worth of XPM icons; with GIF, this would have been less than a 100kB].
Incorporating Icons and Images into an Application One crucial problem with icon-rich applications is where to keep all those icons; obviously, keeping icons in separate files allows end-users to substitute icons and perhaps change them with an Icon Editor program. However, such a scenario also poses a maintainance problem:- software becomes extraordinarily dependent on specifics of a user installation, and end-users may actually break software by substituting corrupted icon files by accident, or perhaps other applications may overwrite them. Another common problem is the need for end-users to set paths and environment variables. To eliminate these problems, the FOX approach is to embed all icons and images right into the application's executable. This is done by simply by compiling the icons into the code in the form of C data statements, and then linking them in. For XPM icons or images, the image files can be directly included into the code, as the XPM format is basically a C/C++ data array. Other image formats need to be transformed into a C/C++ data array with a small build-time utility called reswrap, which is provided in the FOX distribution. Reswrap allows you to generate the C/C++ data arrays automatically from the icons during the build process of your application; simply add a few rules into your Makefile, or, under VC++, use the reswrap program in a so-called Utility Project. For example, given as input a GIF file image such as below:
After processing this file, reswrap generates a C data statement
such as:
This can then be subsequently compiled into an object file, and linked
in with the executable. To make use of such an icon, FOX supports
deserialization from a memory stream.
Wait! Is that all? Yes it is! This one statement creates an icon object, then deserializes the icon data from the GIF stream to build the icon's internal pixel data. A subsequent call: tux_icon->create();Will create an X pixmap, render the icon into it, and subsequently release the pixel data after it is no longer needed. If you had created the icon with the IMAGE_KEEP option, the pixel data would have been kept around for subsequent manipulation by your application, and perhaps repeated rendering. To draw the icon in a window, simply:
window->drawIcon(tux_icon,x,y);will do the job.
Bitmaps Bitmaps in FOX behave very much like Images. Except, unlike Images which are always 24 bits, and in color, Bitmaps are only one bit, or blank and white. Typical uses for Bitmaps are the creation of patterns and stipples, or shape masks against which other primitives are clipped. In terms of constructing and using Bitmaps in FOX, it is completely analoguous:
In terms of using Bitmaps for subsequent tiling and stippling operations, remember that MS-Windows has certain size limits such patterns; X-Windows has no such limit, but presumably smaller patterns are more efficient. It is probably a good idea to keep so widths such as 8,16, or 32.
Cursors Cursors can be constructed in FOX to change the shape of the mouse-cursor. Constructing Cursors is very similar to constructing Bitmaps, except that Cursors comprise two bitmaps, a picture and a shape mask; also, Cursors have a so-called hot-spot, the point inside the cursor-glyph which is ``pointer to'' by the mouse. Besides defining your own ``custom'' cursors, FOX also allows you to simply create a ``stock'' cursor, i.e. a cursor whose shape has already been predefined by the system. To create a custom Cursor:
To create a stock Cursor:
If you define your own Custom Cursors, make sure the size is exactly 32x32. MS-Windows does not support any other sizes. Also, the shape and the picture will have to be the same size.
If Icons Look Funny... Sometimes, your icons may look funny. This is usually because FOX Icon routines determine the wrong value for the transparency color. FOX can handle images with a true alpha-channel, or images with a special transparency color. The latter is the more common approach, as many file formats do not support true alpha channels. Different image formats guess the transparency color in different ways. For GIF Images, FOX uses the following algorithm:
new FXGIFIcon(app,picture_data);
new FXGIFIcon(app,picture_data,FXRGB(192,192,192),IMAGE_ALPHACOLOR);
More on Reswrap The reswrap tool has a number of options to make it convenient to build C source and header files automatically from image files as a part of your regular project build process. Reswrap is normally invoked as follows: reswrap [options] [-o[a] outfile] files....Invoking reswrap with -o outfile will make reswrap write its output on the file outfile. With -oa outfile, reswrap will append additional data at the end of outfile. Any number of input files may be specified. Reswrap typically produces one data statement for each of the input files specified on the command line. Reswrap understands a few additional options: -h Will print out a summary of the supported options.-v Will print out the version number.-d Reswrap normally generates its output as hexadecimal numbers; the -d option will make reswrap generate decimal numbers.-x Forces reswrap to generate hexadecimal numbers [the default].-e Places the storage modifier extern in front of the data array, ensuring that the data array can be linked with other compilation units.-i Instead of a data array statement, reswrap will generate a declaration only. For example, reswrap -i bigpenguin.gif will produce the output: /* Generated by reswrap from file bigpenguin.gif */-s This option suppresses comments inserted by reswrap to indicate the original file name from which the data statement was generated.-n name Instead of taking the filename less the extension, reswrap substitutes name for the name of the resource.-c cols Uses cols columns instead of the default 16 columns in the data statements generated by reswrap.-ppm Assumes the source file is a Portable Pixmap (ppm) file. Reswrap will output a simple rgb array.Example of using reswrap in your Application's Makefile: OBJECTS = icons.o myapp.o ICONS = bigpenguin.gif applogo.gif icons.h: $(ICONS)This will cause make to generate two files, icons.h and icons.cc which contain the declarations and definitions respectively for all the reswrapped icons listed in the ICONS variable. |
|||||||||
![]() |
![]() |
|||||||||
![]() |
![]() |