Guis and color
Download
1 / 11

GUIs and Color - PowerPoint PPT Presentation


  • 58 Views
  • Uploaded on

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)

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' GUIs and Color' - zerlina-mcgowan


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Guis and color
GUIs and Color

Here's a first crack at

an 8-puzzle widget:


How it was produced
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)


How it was produced cont d
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


Changing the xmnbackground resource
Changing the XmNbackground Resource

Suppose you want

your 8-puzzle board

to look like this:


About colors
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


Role of the colormap
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


Color database human readable
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 ] . . .


Setting color programmatically
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.


Getting a pixel by color name
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.


Using getpixelbyname
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”.


Disadvantages of setting color programmatically
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


ad