Using Pixmaps


Pixmaps provide support for colored bitmaps.  Unfortunately in Motif, the handling of pixmaps has always been a weak area.  Motif has provided minimal support for pixmaps and left it up to developers to fix the problem.  Over the years there have been attempts to provide a standard file format and api for pixmaps.  Finally, the xpm library has become the defacto standard for handling pixmaps.  To provide seemless support for pixmaps, the xpm library is built into Xarm.  The version of the xpm library used is based on 3.4.8 (less so) and 3.4.7 (more so).

Resource Files

Xarm provides a string to pixmap converter.  This allows pixmaps to be displayed on any widget as specified by a resource file.  For those of you who are using LessTif, there is a compile time option (C preprocessor macro) that will provide a string to pixmap converter.  Here is an example:

! cdplayer resources 
! Version 1.0.0 
! Copyright (c) 1995, 1996 by Peter G. Williams 
! This resource file was generated by cdplayer. 
*backgroundPixmap: /opt/new/bitmaps/marble2.xpm 
*Background: grey 
*Foreground: black 
*HighlightColor: black 
*fontList: -*-helvetica-medium-r-*-*-12-120-*-*-*-*-*-* 
*.dialogTitle: CD Player 
*Program.labelString: Program... 
*Help.labelString: Help 
*Shuffle.labelString: Shuffle 
*Repeat.labelString: Repeat 
*PlayTime.labelString: Play Time: 
*ElaspedTime.labelString: Time Elapsed: 
*DragInitiatorProtocolStyle: DRAG_NONE 
*DragReceiverProtocolStyle: DRAG_NONE 
*LCD.foreground: yellow 
*LCD.background: black 
*LCD.fontList: -*-helvetica-medium-r-*-*-34-240-*-*-*-*-*-* 
*pollTime: 500 
*cdrom: /dev/cdrom 
*showVolume: True 
*repeatDisc: True 

Here's the result:

Screen shot of my cdplayer. 

The Interface

The class WObjectClass provides two functions for obtaining a pixmap id.  These routines are called getPixmap and getPixmapFromData.  Here's an example of the getPixmapFromData routine:

   XarmArg args; 
   Pixmap pmap;  

   pmap = getPixmapFromData(cd_play); 
   args(XmNlabelPixmap, (XtArgVal) pmap) 
       (XmNlabelType, (XtArgVal) XmPIXMAP); 
   p_play = new PushButton(this->widget(), args, "Play"); 

Pixmap Functions

Pixmap WObjectClass::getPixmap(char *fname); Pixmap WObjectClass::getPixmapFromData(char **pdata);