1 / 11

GUIs and Color

GUIs and Color. Here's a first crack at an 8-puzzle widget:. How It Was Produced. A BulletinBoard container widget bb of 500 x 500 pixels was created. Resources: XmNheight (500) XmNwidth (500) XmNshadowThickness (5 pixels)

Télécharger la présentation

GUIs and Color

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 R = Red G = Green B = Blue . . . R G B 15 1 0 0 14 1 0 13 0 0 0 12 11 Pixel Value Frame Buffer 10 0 0 255 9 8 7 6 blue 5 4 3 2 1 0 Colormap

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

  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

More Related