enum buttonState { NORMAL, HOVER, PRESSED };
void paintButton( Display *dpy, Painter *p, Window button, buttonState state = NORMAL )
{
XWindowAttributes attr;
// fetch window size
XGetWindowAttributes( dpy, button, &attr );
if( state == NORMAL )
p->setForeground( "gray" );
else
p->setForeground( "darkgray" );
p->drawRectangle( button, 0, 0, attr.width, attr.height, true );
p->setForeground( "red" );
p->drawRectangle( button, 0, 0, attr.width -1, attr.height -1, false );
// draw the button text
const char *text = "Quit";
// fetch the Font from the painter
const FFont *font = p->font();
// fetch the height of the font, and the width of the text.
int fontHeight = font->fontHeight(); // max height above and below baseline
int textWidth = font->textWidth( text );
// center the text at the top of the window
p->setForeground( "black" );
if( state == PRESSED )
p->drawText( button, 2 + (attr.width - textWidth)/2, 2 + (attr.height + fontHeight)/2, text );
else
p->drawText( button, (attr.width - textWidth)/2, (attr.height + fontHeight)/2, text );
}
|