|C H A P T E R 5|
X-Designer provides special editors which simplify certain common tasks. You can use these editors to perform the following tasks:
The editors are used in this chapter to customize the tutorial interface. They are invoked from the widget resource panels and the result added to the appropriate field in the resource panel. It is also possible to display the Color Selector, Pixmap Editor and Font Selector from the "Tools" menu. The editors can be used independently of any selected widget.
Because foreground and background colors are the basic elements of all widgets, these resources are located on the Core resource panel. Use the following instructions to set these colors for widgets in the hierarchy.
1. Select the "Strawberry" ToggleButton icon in the hierarchy.
2. Click on the "core resources" button on the toolbar or pull down the Widget Menu and click on "Core resources...".
In previous chapters, you entered settings for resources directly in the text boxes on the right side of the resource panels. To use the editors described in this chapter, click on the buttons on the left side of the resource panels instead.
3. On the "Display" page, click on the "Foreground color" PushButton.
X-Designer displays the Color Selector, shown in FIGURE 5-1:
X provides many pre-named colors. These standard colors make a good starting point for selecting colors for the interface.
1. Scroll down through the X colors displayed in the scrolled list.
2. Select a color.
As you select colors, the currently selected one is shown on the right at the top of the dialog. On the left, the original color is displayed so that you can compare the two.
Choose a dark reddish color such as maroon. These colors are clustered about half-way down the list. The selected color is displayed at the top of the Color Selector.
3. Click on "Apply" in the Color Selector.
This applies your selection to the "Foreground color" resource on the Core resources panel. To apply it to the widget, you must:
4. Click on "Apply" in the Core resources panel.
The "Strawberry" ToggleButton changes color in the dynamic display. Don`t worry if it looks like the background color changes instead of the foreground color; this is because the widget is selected in the hierarchy and the selection is reflected in the dynamic display by inverting the foreground and background colors.
To see the true colors:
5. Select the Shell in the hierarchy.
Now you can see the true foreground and background colors of the "Strawberry" ToggleButton in the dynamic display.
Selecting from the X colors list is only one of several ways to specify a color. Another method is to create the color using components. Use this technique to set the background color of the "Strawberry" ToggleButton:
1. Select the "Strawberry" ToggleButton in the hierarchy.
2. On the Core resource panel, click on "Background color".
3. Use the sliders to change the color.
The sliders at the top of the Color Selector let you individually control the red, green and blue components and the hue, saturation and brightness of your color. You can use the sliders in any order. Changes are reflected immediately at the top of the Color Selector. Notice that the color name is a concatenation of values.
Since this is a background color, a light (non-saturated) color is recommended. This provides a good contrast for the labels, which are darker.
4. When you are satisfied with the color, apply it by repeating Step 3 and Step 4 in Selecting From the X Colors List.
Do not change the color in the Color Selector before proceeding to the next section.
To create a visually appealing interface, it is essential to use colors consistently. X-Designer assists you by providing color objects, which let you bind colors to names which you specify. Use this feature to apply the same background color to all the widgets in the central part of the tutorial interface:
1. Select the "Strawberry" ToggleButton in the hierarchy.
2. In the Core resource panel, click on "Background color".
3. In the Color Selector, click in the "Name" Text box underneath the list of Color objects.
4. Type: background
5. Click on "Bind".
This binds the color to a color object named "background". The selection box shows the name background in angle brackets.
6. Click on "Apply" in the Color Selector and in the Core resources panel.
Apply this background color to other widgets in the hierarchy by entering the color object name as the setting for the background color resource:
7. Select the "Vanilla" ToggleButton in the hierarchy.
8. In the Core resource panel, double-click in the "Background color" text field.
9. Type: <background>
Note that you must use angle brackets. The angle brackets distinguish an object name from a string value. For example, a color object named <red> is distinct from the color red.
10. Click on "Apply".
The color in the "Vanilla" ToggleButton changes. Now apply this background color to the "Chocolate" ToggleButton and any other widgets you want to share the same background color.
When you use a color object, you can easily change the color on all widgets which reference that color object. This makes experimenting with colors easy.
1. In the Color Selector, click on "background" in the "Color objects" list.
The background color is displayed at the top right of the Color Selector and "background" is displayed in the text field underneath the list of objects.
2. Using the sliders at the top of the Color Selector, change the color.
3. Click on "Bind".
All the resources which refer to the color object change to the new color and the change is reflected immediately in the dynamic display.
Experiment with creating new colors, binding them to color objects and assigning these color objects to some color resources. You can also bind colors from the X colors list to color objects. By repeating these steps, you can build your own palette of colors. Remember that it is better to name a color object for the function it serves, such as "background", than for the color it represents, since the color can change.
Color objects are saved with the design file. This means you can use the same names for color objects in different design files, even though the colors might be different. For example, the color object, background, might be yellow in one design and light blue in another. Within the same design, however, an object name such as "background" always refers to the same color.
Color objects can be shared between files by making them "global". This is controlled by setting the appropriate toggle when you generate code. See Global Object Functions for more information.
The Font Selector lets you select font styles and sizes for the text which appears in your widgets. Your system determines which font styles are available; you can't create new fonts the way you can create new colors.
So far, you have used the default font for all text in the tutorial interface. In this section you will use the Font Selector to:
This section discusses the use of a single font in a text string. Complex font objects which let you use multiple fonts in a single label string are discussed in Compound Strings.
To add more visual interest to the tutorial interface, you are going to change some of the fonts from their default to an oblique font, as illustrated in FIGURE 5-2.
First, bring up the Font Selector:
1. Click twice on the "Double Scooper" radio button to bring up the resource panel.
2. On the "Display" page of the resource panel, click on "Font".
X-Designer displays the Font Selector, shown in FIGURE 5-3.
The Font Selector lists all the fonts available on your system. Because different machines may have different fonts installed, your list may look different from the figure.
Since there can be hundreds of fonts in the list, the menu bar lets you filter the list according to different criteria such as the font family, weight and point size.
The toggles below the font list let you select scalable fonts, non-scalable fonts, or both.
When you select a font from the list, the name appears in the "Font name" and "Selection" fields.
The Font Selector also lists font objects and their associated fontlist tags. Simple font objects can be used as aliases for font names. Compound Strings discusses the use of more complex font objects.
You are going to change the font of the "Double Scooper" label to 14-point bold oblique Helvetica. (If this font is not installed on your machine, select an alternative.) Because there are so many fonts in the list, it helps to filter the list. The "Font name" and "Selection" fields reflect your choices as you make them.
1. Pull down the Family Menu from the menu bar and select "Helvetica".
This eliminates all fonts from the list which are not Helvetica.
2. Pull down the Weight Menu and select "bold".
3. Pull down the Slant Menu and select "o" for "oblique".
4. Pull down the PtSize (point size) Menu and select "140".
Note that, because point sizes are specified in tenths of a point, this selects a 14-point font.
These steps reduce the font list to about four entries. A typical font name entry is shown in FIGURE 5-4. Although many fields are required to specify a font uniquely, most of them are only interesting to advanced typographers. The fields you are most likely to use are family, weight, slant and point size. You may also need to specify the display resolution such as 75 dpi (dots per inch) or 100 dpi. These fields are identified in FIGURE 5-4.
The example in FIGURE 5-4 specifies a display resolution of 100 dpi, both horizontal and vertical, which is appropriate for most workstation displays.
5. Pull down the ResX Menu and select a resolution of 100 or 75 dpi.
Select the resolution appropriate to your display. If in doubt, use 100 dpi.
The selections you have made are sufficient to specify a font for the interface. Now you can apply it to the "Double Scooper" radio button.
1. Click on "Apply" in the Font Selector.
This applies your selection to the "Font" resource in the resource panel.
2. Click on "Apply" in the resource panel.
The "Double Scooper" radio button is now labeled in a large, bold, oblique font.
3. Select the "Small" radio button.
4. Pull down the PtSize (point size) Menu and select "100".
You can press the "Sample text" button to re-display the example text whenever the filtering has been changed. X-Designer doesn't do this automatically as some fonts can take a very long time to load.
5. Click on "Apply" in the Font Selector and in the resource panel.
The "Small" radio button is now labeled in a bold, oblique font, smaller than the "Double Scooper" label. Before proceeding, reset the Font Selector panel so that it shows all the fonts:
6. Click on the "All fonts" button at the bottom of the Font Selector.
This resets all elements of the font filter to "*" and so all available fonts are displayed again.
The font you used on the radio buttons is a non-scalable font. This means that it is only available in certain fixed point sizes. X also supports scalable fonts, which can be any size you like. Try selecting some scalable fonts:
1. Clear the "Non-scalable" toggle in the Font Selector.
This eliminates all non-scalable fonts from the list and so the list is now empty.
2. Set the "Scalable" toggle.
This adds the scalable fonts to the list. You can specify a size for any of these fonts in two ways: by adjusting either the pixel size or the point size. The pixel size is the first numeric field in the font descriptor and the point size is the second numeric field. Both of these fields are initially set to zero for all scalable fonts, indicating a default size.
3. Click on one of the font names in the list.
Your selected font appears in the "Font name", "Selection" and "Sample text" fields.
4. Click in the "Font name" field (not the "Selection" field).
5. Edit the second numeric field (point size) to 240 (24 points).
6. Press <Return> or click on the "Sample text" button to display a sample of this text size.
When using scalable fonts, specify a non-zero value for either the pixel size or the point size, but not both. X adjusts the remaining zero value to fit the explicitly specified value. If you specify non-zero values for both fields, however, X-Designer displays an error message if they do not match.
Typical point size values, specified in tenths of a point, are larger than typical pixel size values. A point size of 240 roughly corresponds to a pixel size between 30 and 35. The exact proportion depends on the resolution of your screen and the specific font.
X has two ways of scaling fonts: outline scaling and bit scaling. If the sample text is very jagged, the font is bit-scaled. To list only outline-scaled fonts, pull down the Fndry Menu and select "bitstream".
After experimenting, set the Font Selector to see the non-scalable fonts again:
7. Click on the "Non-scalable" toggle.
For the two radio buttons, you set the fonts individually. If you use this method to set the same font for multiple widgets, any later changes must also be made for each widget individually. Also, the code generated by X-Designer for the application makes a separate call to your system to load the same font for each label, which is inefficient.
Therefore, if multiple widgets use the same font, you can simplify both the code and maintenance of it by creating a simple font object. A font object is an alias for a list of fonts. A simple font object is an alias for a one-element list.
1. Use the pulldown menus to select the 12-point bold oblique helvetica font.
If more than one font appears in the list of X fonts, highlight one.
2. In the "Name" field underneath the list of Font objects, type: option_labels
Remember that it is better to name a font object for the function it serves rather than for the size or style it represents, since these specifications can change.
3. Click on "Bind".
This creates a font object called "option_labels". It only has one font in its list: the 12-point helvetica font. This has an associated fontlist tag "<Default>". The use of fontlist tags is discussed in Compound Strings.
Notice that the "Selection" field automatically updates to show the "<option_labels>" name. The angle brackets (<>) indicate that it is a font object rather than a font name. This font is applied to the resource panel when you click on "Apply". Do not do this yet as we are going to apply this font object to all the ToggleButtons and Labels at once.
4. Select all three ToggleButtons: "Vanilla", "Chocolate" and "Strawberry" and the three Labels: "Topping1", "Topping2" and "Topping3".
Do this by either dragging a rectangle around the widgets or by selecting each widget while holding down the Shift key.
5. Click on "Apply" in the Font Selector.
This applies the font object to the ToggleButton resource panel.
6. Click on "Apply" in the resource panel.
This applies the font object to all the selected widgets.
The interface now looks as shown in FIGURE 5-5.
The text on the ToggleButtons and Labels is now shown in the font to which the font object is bound. To change this font style, just bind the font object to another font.
1. Pull down the Slant Menu and select "r" for "regular".
2. Pull down the Family Menu and select "Times".
The font list now displays the 12-point bold Times fonts. If the list is empty or Times is not available, select a different font family.
3. Click on "Bind".
4. Click on "Apply" in the Font Selector.
5. Click on "Apply" in the resource panel.
The font object changes to correspond to the Times font and all the Labels and ToggleButtons change immediately in the dynamic display.
Font objects are saved with the design file. This means you can use the same names for font objects in different design files, even though the font might be different. For example, the option_labels font object might be Helvetica in one design and Times in another.
Font objects can be shared between files by making them "global". This is controlled by setting the appropriate toggle when you generate code. See Global Object Functions for more information.
You can use pixmaps instead of text strings on labels and buttons. X-Designer provides two editors for creating and applying pixmaps. First you will use the Pixmap Selector to learn the basics of applying pixmaps to widgets. Then you will use the Pixmap Editor to create some custom pixmaps.
X-Designer lets you use bitmaps created using the standard X bitmap editor. It also lets you use pixmaps in the public domain Xpm format and provides an editor for you to build pixmaps in this format. The Xpm library is included with the X-Designer release.
Note that you can use pixmaps created with any other utility provided they are in Xpm format. The difference between a bitmap and pixmap is that bitmaps are monochrome and pixmaps are color images. They are also different formats--bitmaps are Xbm format and pixmaps are Xpm format. You can still edit X bitmaps using the X-Designer Pixmap Editor. When you do this, X-Designer converts the bitmap to a two-color pixmap and writes it out in Xpm format. You can keep it with only two colors or add more colors to it.
As a first step, replace the label of a ToggleButton with one of the X bitmaps.
1. Double click on the "Cone" PushButton in the hierarchy.
2. On the "Display" page of the resource panel, click on "Pixmap".
X-Designer displays the Pixmap Selector. This is shown with example entries in FIGURE 5-6:
3. Select any bitmap from the list of X bitmaps.
The selected bitmap is displayed at the top of the Pixmap Selector.
4. Click on "Apply" in the Pixmap Selector.
This applies your selection to the "Pixmap" resource in the resource panel.
5. Click on "Apply" in the resource panel.
Now the ToggleButton has both a text label and a pixmap label, although only the text label appears in the dynamic display. To display the pixmap label, you must change the resource that controls which type of label is displayed.
6. On the "Settings" page of the resource panel, change the "Type" setting to "Pixmap".
7. Click on "Apply" in the resource panel.
The ToggleButton now displays the pixmap instead of the text label.
If you have additional X bitmap files on your system, you can also use these. Clicking on "Open..." displays a file selector which lets you locate bitmap files and add them to the list of X bitmaps.
You can also enter names of bitmaps in the text box under the list of X bitmaps, then click on "Add" to add the name to the list. If the bitmap doesn't exist yet, you can still add its name to the list and apply it to resources. Later, in development or at run time, you can supply the bitmap.
The list on the right of the Pixmap Selector is the list of currently defined pixmap objects. These are pixmaps which have been bound as an object. The names in the list are the names of the objects. You can name a new pixmap object and then create a pixmap or read in an existing pixmap or bitmap. To make a new object, type its name in the text box below the list. To identify a pixmap with that object, press the "Edit" button. Editing Pixmaps describes how to read in or create a pixmap.
X-Designer provides an editor for creating pixmaps. In addition to allowing you to design your own pixmaps, the Pixmap Editor also lets you:
You can choose whether to write the pixmap in Xpm version 1 or 3. You should use version 3 as this is the most recent. Version 1 is provided for compatibility with older pixmap-handling applications.
All pixmaps used by widgets in X-Designer must be bound to pixmap objects. First, you will create a pixmap for the "Cone" PushButton, as shown in FIGURE 5-7:
If you are continuing from Selecting Pixmaps, you already have the Pixmap Selector displayed and so you can skip the next two steps.
1. Double click on the "Cone" PushButton in the hierarchy.
2. On the "Display" page of the resource panel, click on "Pixmap".
3. In the text box labelled "Name" in the "Pixmap objects" portion of the Pixmap Selector, type: cone
4. Press the "Edit..." button.
X-Designer displays the Pixmap Editor, shown in FIGURE 5-8:
The Pixmap Editor has a menubar at the top of the window, a toolbar beneath the menubar, a tools palette on the left, the current foreground and background colors beneath the tools palette, an image drawing area in the centre and an image shown actual size on the right.
The toolbar, shown in FIGURE 5-9 contains buttons for the following operations:
The File menu contains four options: "New", "Open File", "Save XPM File" and "Close".
New creates a new, blank editing area removing any image that was there before. X-Designer warns you if you have not bound the image since making any changes. If you wish to bind the image, select "Cancel" and then bind it, as described in Pixmap Objects. If you do not wish to bind the image, press "OK" and continue.
If you have X pixmap files on your system, you can also use these in your interface. Selecting "Open file..." in the File Menu displays a file selector which lets you load a pixmap file into the Pixmap Editor. X-Designer reads pixmaps in XPM3 format. It also reads X bitmap files and converts the bitmaps to pixmaps for editing in the Pixmap Editor.
Selecting "Save XPM file..." lets you write the pixmaps you create to files. X-Designer writes XPM1 and XPM3 format. You should normally save pixmaps in XPM3 format. XPM1 is provided for compatibility with older versions of third-party pixmap-handling utilities.
This closes the editor window. If you have made changes since last binding, X-Designer will issue a warning. See Pixmap Objects for details on binding images to objects.
Every time you bind or write to an XPM file, you effectively save the current state of the pixmap you are creating. It's a good idea to do this frequently as you work.
The Edit menu has seven items: "Undo", "Cut", "Copy", "Paste", "Clear", "Crop" and "Select All".
Most of these options operate on the selected portion of the pixmap. To select, use the arrow in the selection tool on the palette, as shown in FIGURE 5-10.
1. Click on the selection tool.
2. Click in the drawing area and drag.
The selected portion of the pixmap includes pixels in the rectangular border marked with crosses and all the pixels within the border. Note that when you select an area of the image, the size and location of the selected area is displayed in the status line at the bottom left of the window. The "Select all" option in the Edit menu selects the entire image.
This undoes the last action in the editing area.
Cut removes the selected portion of the image to the clipboard.
Copy copies the selected portion of the image to the clipboard.
Pastes the contents of the clipboard into the selected area. If the selected area is smaller than the area on the clipboard, X-Designer places the top left of the clipboard image at the top left of the selected area and draws as much of the area from the clipboard as there is room to do.
Clear removes the selected portion of the image without copying it to the clipboard.
Crop reduces the image to the selected area, thereby resizing it.
This selects the whole image.
The view menu contains one pullright menu item, labelled "Drag color". This refers to the color of the selection rectangle as you drag it. When you pullright from this item, two radio buttons appear labelled "Invert" and "Xor". These describe the method of showing the selection rectangle.
The Image menu contains one item, "Resize". Selecting this item displays the dialog in FIGURE 5-11.
Type the new size in the format "width x height". Setting the "Rescale to Fit" toggle causes the Pixmap Editor to rescale the image to suit the new dimensions specified.
The Effects menu has four items: "Reflect Horizontally", "Reflect Vertically", "Rotate 180" and "Gray Out".
"Reflect Horizontally" and "Reflect Vertically" reflect the selected area across a horizontal or vertical axis respectively.
"Rotate 180" rotates the selected area through 180 degrees--effectively reflecting the selected area across a diagonal axis.
This item creates a grayed out version of the selected area by `xor'ing each pixel. This is useful for creating insensitive pixmaps.
The Palette menu allows you to edit the color palette or read in a new palette. There are two items: "Edit Palette" and "Read Palette".
This produces the Palette Editor which is described in Color Palette.
This lets you read in the palette of a saved pixmap file. When you select this item, a file selection dialog appears prompting you for the name of an Xpm format file. When the file is read in, the palette of colors from the saved file replaces the existing palette. X-Designer then changes the colors of the current image, if you have one, to use the colors of the new palette. X-Designer will use the closest color match it can find.
Supplied with X-Designer are some palettes which are color cubes. Also supplied is the palette used by X-Designer for its icons. These files can be found in: $XDROOT/lib/palettes, where XDROOT is the install directory of your X-Designer.
To help you draw and color your image there is a palette of tools on the left of the Pixmap Editor window, as shown in FIGURE 5-12. Tooltip information is displayed for each palette tool when you hold the mouse pointer over it.
Note that all of the drawing tools use the current foreground color. You can, however, use the current background color instead. See Swapping Background and Foreground Colors. You may also change all instances of a particular color in your image. See Changing a Color in the Image for details on how to do this.
You must select one of these drawing tools to perform an operation on the window. There is always one and only one tool selected at any time.
This is the selection tool. You can select rectangular areas of the image. Many of the menu functions operate on the selected area.
This is the filled rectangle tool. With this selected you can draw rectangles filled with the current foreground color.
This is the fill tool. Click the mouse button over an area of the pixmap to fill that area with the current foreground color.
This allows you to draw the outline of a circle using the foreground color. The circle is drawn from the centre.
This enables you to draw individual pixels using the foreground color.
With this selected, you can draw a circle from the centre filled with the foreground color.
Select this to draw straight lines in the foreground color.
This is the dropper tool. Use this to pick up colors from the image. Clicking over a color in the image while this is the selected tool sets that color as the foreground color. See Dropper Tool Shortcut for a quick way of doing this.
This allows you to draw the outline of a rectangle using the foreground color.
With any tool selected, clicking over a color with the Control key held down sets the foreground color in exactly the same way as the dropper tool. Clicking with Mouse Button 2 while the Control key is held down sets the background color.
You can drag pixmaps and pixmap filenames into the editing area using the Motif "drag and drop" mechanism. Usually this means pressing Mouse Button 2 over the source and dragging it into the Pixmap Editor editing area before releasing the mouse button. If this does not work, check with your system administrator for your system's configuration.
A dragged pixmap appears in the editing area exactly as if you had created it yourself, complete with a color palette containing all the colors used in the pixmap.
Color palettes are important in the Pixmap Editor. In order to create color pixmaps you need to specify which colors you wish to use. Any colors defined in the color palette for a pixmap will be stored with the pixmap. While you are creating your image you need to be aware which colors from the palette are the current background and foreground colors.
The two squares of color below the tools palette show the current foreground and background colors. The foreground color is the color used for any drawing. The background color is used to fill blank space left by the editor. "Cut" and "Clear" both leave blank space which is filled with the background color. See Cut and Clear for details on these operations. "Gray out" uses the background color to produce the grayed out effect. See Gray Out. Resizing to a larger size fills the extra space with the background color.
When you draw anything in the Pixmap Editor, the current foreground color is used. If, however, you draw with Mouse Button 2 pressed down, the current background color is used.
Pressing the mouse button when the pointer is over either the background or foreground square displays the color palette.
You can edit the color palette so that it contains the colors you wish to use in your image. This is described in Editing the Color Palette.
You can change the current background and foreground colors by displaying the color palette and releasing the mouse button over the new color.
If you have a color image and you wish to change all instances of one particular color to another, do the following:
1. Make sure the color you wish to change is the current foreground color.
2. Press the Control key and select another foreground color.
Wherever the previous color was displayed in your image, the new color is now displayed.
Selecting "Edit palette" from the Palette menu produces the Palette Editor, as shown in FIGURE 5-13.
Each color square is a button. You can select a color square by pressing the mouse button over it or by using the keyboard arrow keys. The name of the selected color is displayed at the bottom of the Palette Editor window.
The "Remove" button removes the currently selected color from the palette. If that color was being used in the pixmap, it is replaced by the background color.
Pressing the "New" button adds a color to the end of the palette. The new color is the same as the last color on the palette.
To change a color, double click over it or select it and press "Edit". This invokes the Color Editor. See Setting Colors for more details on the Color Editor.
If you set the toggle labelled "Transparent" for a selected color, the color will be "transparent" in the pixmap. This means that when the pixmap is displayed in the final application those areas of the pixmap which are transparent show the color that is beneath them. You may wish to use this so that the background of a button, for example, shows through parts of the pixmap.
Note, however, that it is XPM that supports transparent colors. The Motif PushButton and Label widgets provide no support for them. You could use the XPM library to translate the "none" color to the background color of the widget displaying the pixmap. The following file provides more detailed information on using the XPM library:
where XDROOT is the install directory of your X-Designer.
If you wish to use transparent colors, some third-party widgets may provide more support.
The name "none" is displayed for the transparent color in the color palette editor.
When a pixmap is saved, the color palette is also saved. This means that you can create a pixmap specifically for its color palette and then load in the palette at another time (this is discussed below). X-Designer compresses the number of colors saved to those used in the picture. If you are creating a pixmap in order to save the color palette, simply set one pixel to each of the colors in your palette.
See Read Palette for details on reading in a color palette from a saved pixmap.
Note - If you plan to use a lot of colors you should run X-Designer with the "-L" command line switch, as described in Command Line Switches for Interactive Use, so that X-Designer uses its own private colormap. Otherwise, you may not be able to use many colors.
First, set the size of the pixmap you'll be creating.
1. Select "Resize" from the Image menu.
2. Type: 40 x 40 into the text box in the Resize dialog.
3. Press "OK".
The actual-size pixmap display and the grid in the drawing area should resize. To draw:
4. Select black as the foreground color.
See Changing the Background and Foreground Colors for details on changing the foreground color.
5. Click on the filled rectangle tool.
See Tools Palette if you are not sure which is the filled rectangle tool.
6. Click in the drawing area and drag to create a black filled rectangle.
The actual-size pixmap display updates to show what you've just drawn.
7. Experiment with the drawing tools until you feel comfortable using them.
It is helpful to learn the options on the Edit Menu and add some colors to the color palette before you undertake a drawing task.
8. Add some colors to your color palette.
Now that you have more colors, experiment more with the drawing tools. When you are ready, use the tools and colors to create a pixmap showing an ice cream cone.
9. Draw an ice cream cone.
To display your finished pixmap, you must bind it to a pixmap object first.
1. Type "cone" in the "Bind" field in the Pixmap Editor.
2. Click on "Bind" or press <Return> in the "Bind" field.
In the Pixmap Selector, the pixmap object name appears in the list of pixmap objects and in the selection box.
3. Click on "Apply" in the Pixmap Selector.
4. Click on "Apply" in the resource panel.
5. On the "Settings" page, check that the "Type" setting is "Pixmap".
6. Click on "Apply" in the resource panel.
Pixmap objects work very much like color objects. You can use the same pixmap in more than one place. Changes you make to the pixmap are reflected in the dynamic display as soon as you bind again.
Pixmap objects are saved with the design file. This means you can use the same names for pixmap objects in different design files, even though the pixmap might be different. For example, the pixmap object, cancel, might be a cancel stamp in one design and the international "No" symbol in another.
If you want, try creating and adding pixmap objects for the "Dish" and "Cancel" buttons. Hint: the lettering for the "Cancel" stamp shown in FIGURE 5-14 was done with the line tool, not the pencil tool.
7. Save your design.
Pixmap objects can be shared between files by making them "global". This is controlled by setting the appropriate toggle when you generate code. See Global Object Functions for more information.
The labels in the tutorial example all use simple text strings. This section describes the X-Designer compound string editor, which uses an internal structure to let you create more complex strings. In conjunction with complex font objects, these strings let you display labels that use more than one font, or labels that are written entirely or partly from right to left.
To most people a string is just an ordered list of ASCII characters--a character string. Most Motif resources that have string values use a different string representation: the compound string.
Motif compound strings are used for all string resource values except for the strings in Text and TextField, which are ordinary character strings. (It is important not to confuse the Motif compound string with the compound text format of X. The Motif compound string is often called an XmString because this is the naming convention for the Motif toolkit functions used to manipulate it.)
A compound string is a way of encoding text so that it can be displayed in multiple languages and fonts without changing the code. In this section, you will learn how to create a string to be displayed in multiple fonts. For information about using multiple languages, see Chapter 22 and your Motif documentation. Appendix F is a list of recommended books on Motif.
Conceptually, a compound string consists of four types of component:
Although these types of component can be in any order, it is common for each text string component to be preceded by a fontlist tag component.
A compound string can be used for the label of a widget by specifying a fontlist for the widget's font resource. A fontlist is a set of (font, tag) pairs. The fontlist tags indicate which font in the fontlist to use for each text string component.
To familiarize yourself with the features of X-Designer's compound string editor, use the following step-by-step example while running X-Designer at your workstation.
Select "New" from the File Menu.
The object of the exercise is to reproduce the masthead of the London Guardian on a Label widget, shown in FIGURE 5-15.
So far, you have learned how to select a font and apply it to a widget. You have also created a simple font object that corresponds to a single font. Complex font objects let you produce more complex visual effects. A complex font object corresponds to a list of fonts; different parts of a string can then be displayed using different fonts from the list. The step-by-step example in this section requires a complex font object.
Create a widget that uses a label and give it a font object with more than one font in its list.
1. Create a widget hierarchy with a Label as the child of a Form.
2. Double-click on the Label widget to display the resource panel.
3. Click on the "Font" resource button to display the font selector.
4. Use the pulldown menus to select a 24-point medium italic Times font.
5. In the Font object "name" field, type: masthead
6. In the "Fontlist tag" field to the right of the "Font object" field, type: italic
7. Click on "Bind".
This creates a font object called masthead with one font in its list. The font is tagged italic.
Note - Tag names are arbitrary. However, several pre-defined tags are listed by the "Default" button and the "UIL" pulldown menu. The "Default" and "UIL" buttons are above the "Fontlist tag" field. Selecting the "Default" option produces the tag XmFONTLIST_DEFAULT_TAG. The UIL menu lists tags that can be used in UIL (Motif's User Interface Language). If you are a UIL user, note that most UIL compilers produce a "severe internal error" if you use a tag that is not on this list. If you are not a UIL user, ignore the UIL options.
Next, add another font to the font object. The second font has a different tag.
8. Select a 24-point bold regular Helvetica font.
9. In the "Fontlist tag" field, type: bold
Do not change the masthead font object name.
10. Click on "Bind".
This adds the bold font to the font object list and tags it "bold". You can see samples of the two fonts in the "Sample" field by selecting the different tags in the "Fontlist tags" list.
You now have a font object that can be used to display a string using two different fonts. Apply it to the Label widget:
11. Click on "Apply" in the font selector.
12. Click on "Apply" in the Label resource panel.
The text in the Label is displayed in the italic Times font because it is the first in the list. To display a text string that uses both fonts, you must create a compound string.
When you type text into the "Label" text field of the resource panel, X-Designer creates a compound string which only contains text string components and separator components, which correspond to the newlines. To create a compound string that includes fontlist tags, you must use the compound string editor.
1. Click on the "Label" button in the resource panel.
This displays the compound string editor, shown in FIGURE 5-16.
The compound string editor includes the current fontlist name, an editing area and a list of existing compound string objects. The fontlist name is currently "masthead", to correspond with the name of the font object used in the widget.
As you enter text in the compound string, it appears in the editing area. The fontlist named at the top of the screen is used to display the text. Other components, such as empty text components and directional indicators, appear as symbols. You can turn off the symbol display using the "Show symbols" toggle to see how the text will look in the widget.
If the "Show symbols" toggle is not on:
2. Click on the "Show symbols" toggle.
To create the compound string, start by entering the text:
3. Click on the I-beam cursor in the editing area.
This makes the cursor blink, indicating that the editor is ready for text entry.
4. Type the following string with no space between the words: TheGuardian
The text is displayed using the first font in the fontlist, which is the italic Times font, as shown in FIGURE 5-17.
To make different parts of the text display in different fonts, you must insert fontlist tags into the compound string.
5. Position the pointer between "The" and "Guardian", then press and hold mouse button 3.
A popup menu appears. Selecting an item from this menu inserts a component of the corresponding type into the string. Selecting "Delete" deletes the current component. To display the word "Guardian" in the bold Helvetica font, you must insert the appropriate fontlist tag ("bold") at the pointer.
6. Pull right for the Fontlist tags Menu and select "bold".
This inserts the fontlist tag symbol and changes the display as shown in FIGURE 5-18.
If you accidentally insert the tag in the wrong position, you can pick it up and move it using mouse button 1.
While the word "The" is now correctly displayed in the italic font, this is only because Motif uses the first font in the fontlist by default. To make the compound string complete you should insert the italic tag at the beginning of the string.
7. Position the pointer before "The", then press and hold down mouse button 3.
8. Pull right and select "italic".
This inserts a second fontlist tag symbol, as shown in FIGURE 5-19.
The compound string is now complete. To see it as it will appear on the label:
9. Click on the "Show symbols" toggle to turn off the symbols.
This redraws the string without the fontlist tag symbols, as shown in FIGURE 5-20.
Now you can create a compound string object and bind it to the string.
1. In the field labelled "Name" underneath the list of XmString objects, type: guardian
2. Click on "Bind".
The name of the object appears in the XmString object list. Finally, you can apply the compound string object to the Label.
3. Click on "Apply" in the compound string editor.
This applies the compound string object to the Label resource panel.
4. Click on "Apply" in the Label resource panel.
The text in the Label now displays the compound string in the selected fonts.
So far, this exercise has demonstrated two of the components in a compound string: the text and fontlist tags. The other two components are the newlines used as delimiters and direction indicators.
A newline causes a line break in the text. You can either press <Return> while entering text, or insert a newline using the pull-down menu. Before experimenting with inserting, moving and deleting newlines, make sure the "Show symbols" toggle is on so you can see what you are doing.
The direction indicators let you create text in either a left-to-right or a right-to-left direction. Although the default direction is from left to right, you can specify any portion of the string to be drawn from right to left.
If the "Show symbols" toggle is not on:
1. Click on the "Show symbols" toggle to display the symbols.
2. Position the pointer between "Guar" and "dian", then press and hold mouse button 3.
3. Pull down and select "Right to left".
The compound string changes as shown in FIGURE 5-21.
The small diamond represents a change of direction from left-to-right to right-to-left. The arrow is the direction indicator, which appears at the beginning of the affected text. Since this is a right-to-left segment, the beginning of the text is on the right, not on the left. A change to left-to-right is represented by a direction indicator arrow pointing to the right at the beginning (the left end) of the new text.
Inserting newlines and fontlist tags into a right-to-left segment may seem to produce the opposite effects from what you expect if your normal reading direction is from left to right.
Remember that symbols affect the text that follows them, which means the text to the left in a right-to-left segment.
Finally, bind the compound string object guardian to the new string.
4. Click on "Bind".
The Label text changes as shown in FIGURE 5-22.
String objects can be shared between files by making them "global". This is controlled by setting the appropriate toggle when you generate code. See Global Object Functions for more information.
If you create a new font object, or decide to use a different one while using the compound string editor, you can update the "Font" field in the widget's resource dialog by pressing the "Update font" button in the Compound String Editor. This ensures that the widget is using the same font object as the editor. This is not necessary if you have changed the contents of the font object--only if you want to use a different one.
X-Designer provides a means of editing callbacks and code preludes. This facility is available once you have specified a callback and generated a stubs file or, in the case of code prelude editing, you have defined a code prelude and generated the primary source file.
You must first select the widget which has been given the callback or prelude. For callbacks, the editing capabilities are available from the Callbacks dialog. For code preludes they are available from the Widget menu. See Designating a Callback for details on the Callbacks dialog.
When you ask to edit a callback or prelude you are given a text editor running inside an Xterm window. The editor used is determined by the editor application default which is described in Appendix E.
If you have not already generated a stubs file or primary source file, you are prompted to do so.
More about callback editing is provided in Adding Callback Functionality. More about code prelude editing is provided in Code Preludes.