Presentation is loading. Please wait.

Presentation is loading. Please wait.

GUIs and Color Here's a first crack at an 8-puzzle widget:

Similar presentations


Presentation on theme: "GUIs and Color Here's a first crack at an 8-puzzle widget:"— Presentation transcript:

1 GUIs and Color Here's a first crack at an 8-puzzle widget:

2 How It Was Produced  A BulletinBoard container widget bb of 500 x 500 pixels was created. Resources:  XmNheight (500)  XmNwidth (500)  XmNshadowThickness (5 pixels)  Nine PushButton widgets were created as children of bb inside of a doubly nested loop:  XmNheight (100)  XmNwidth (100)

3 How It Was Produced (cont'd)  To make the buttons appear to pop out of the screen, use resources:  XmNshadowType (XmSHADOW_OUT)  XmNshadowThickness (5)  To make the tiles white, use resource XmNbackground (see later slide)  To display the tile number:  convert it to a string  convert the string to a Motif compound string (recall XmStringCreateLocalized)  give the compound string as value to the resource XmNlabelString

4 Changing the XmNbackground Resource Suppose you want your 8-puzzle board to look like this:

5 About Colors  The XmNbackground resource requires a value of type Pixel  A Pixel is a special kind of integer, one that is a valid index into a Colormap  A Colormap is an array of colors; most displays provide a hardware colormap  To specify a new background color, the programmer must know:  the symbolic name of the desired color, and  how to set the XmNbackground resource to the Pixel value associated with that color

6 Role of the Colormap 1 0 0 1 0 0 0 0 0 1 2 3 4 5 6 7 8 00255 9 10 11 12 13 14 15. R G B.. R = Red G = Green B = Blue Frame Buffer Pixel Value Colormap blue

7 Color Database (Human Readable) ! $XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp $ 255 250 250snow 248 248 255ghost white 248 248 255GhostWhite 245 245 245white smoke 245 245 245WhiteSmoke 220 220 220gainsboro 255 250 240floral white 255 250 240FloralWhite 253 245 230old lace 253 245 230OldLace 250 240 230linen 250 235 215antique white 250 235 215AntiqueWhite 255 239 213papaya whip 255 239 213PapayaWhip 255 235 205blanched almond... [ about 720 more ]... Directory: /usr/X/lib File: rgb.txt The numbers stand for the intensity of the red, green, and blue components of the color

8 Setting Color Programmatically  The desired bulletin board and push button background colors are DarkRed and PowderBlue  To find their indexes into the colormap (pixels) a programmer can use: XAllocNamedColor(Display *display, Colormap cmap, char *name, XColor *color, XColor *exact) This requires knowing how to retrieve displays, screens, and colormaps.

9 Getting A Pixel By Color Name Pixel GetPixelByName (Widget w, char* colorname) { Display *dpy = XtDisplay( w ); int scr = DefaultScreen (dpy); Colormap cmap = DefaultColormap (dpy, scr); XColor color, ignore; If (XAllocNamedColor (dpy,cmap,colorname,&color,&ignore)) return color.pixel; else { XtWarning ("Couldn't allocate color" ); return BlackPixel (dpy, scr); { } Now use GetPixelByName(bb,"DarkRed") paired with resource XmNbackground when creating bb.

10 Using GetPixelByName Widget bb = XtVaCreateManagedWidget ( "puzzle", xmBulletinBoardWidgetClass, form, Nheight, 3*TILE_SIZE+2*BB_SHADOW, XmNwidth, 3*TILE_SIZE+2*BB_SHADOW, XmNmarginHeight, 0, XmNmarginWidth, 0, XmNshadowThickness, BB_SHADOW, XmNshadowType, XmSHADOW_IN, XmNbackground, GetPixelByName(bb, ``DarkRed''), NULL ); Use the same approach to make the color of the tile pushbuttons “PowderBlue”.

11 Disadvantages of Setting Color Programmatically  GetPixelByName is not defined in either Xt or Xm; you have to write it  Anytime you want to change the background color you have to recompile the program  A better way is to use the Resource Manager


Download ppt "GUIs and Color Here's a first crack at an 8-puzzle widget:"

Similar presentations


Ads by Google