#6 Prettier "pushed in" button state code suggestion

closed
5
2008-10-22
2008-10-11
dav7
No

I liked Karmen the first time I saw it, except for one small artifact: the way the control buttons look when they're pressed down.

So, since I'm finally not scared of C anymore (:D), I managed to convince gcc to like what I thought the buttons should look like when pushed in. I haven't involved myself with C all that much at the moment so don't know how to create diffs yet, but here's the code that needs to be modified:

button.c, new repaint() code:

static void repaint(struct widget *widget)
{
struct button *bp = (struct button *)widget;
unsigned long bgpixel;

setcolors(bp);
bgpixel = getbgpixel(bp);

/* clear */
XSetForeground(display, bp->gc, bgpixel);
XFillRectangle(display, bp->pixmap, bp->gc,
0, 0, WIDGET_WIDTH(bp), WIDGET_HEIGHT(bp) - 1);

/* draw */
XSetForeground(display, bp->gc, bp->fg->normal);
XSetBackground(display, bp->gc, bgpixel);
if (bp->image != NULL) {
int x, y;

x = WIDGET_WIDTH(bp) / 2 - bp->image->width / 2;
y = WIDGET_HEIGHT(bp) / 2 - bp->image->height / 2;
if (bp->depressed) {
x++;
y++;
}
putimage(display, bp->pixmap, bp->gc, bp->image, x, y);
}

if (bp->depressed)
drawpressed(bp->pixmap, bp->gc, bp->bg,
0, 0, WIDGET_WIDTH(bp), WIDGET_HEIGHT(bp));
else
drawraised(bp->pixmap, bp->gc, bp->bg,
0, 0, WIDGET_WIDTH(bp), WIDGET_HEIGHT(bp));

/* display */
if (WIDGET_MAPPED(bp))
XCopyArea(display,
bp->pixmap, WIDGET_XWINDOW(bp), bp->gc,
0, 0, WIDGET_WIDTH(bp), WIDGET_HEIGHT(bp), 0, 0);
}

-----

lib.c, new drawpressed() function and code:

void drawpressed(Drawable d, GC gc, struct color *color,
int x, int y, int w, int h)
{

XSetForeground(display, gc, color->shadow2);
XDrawLine(display, d, gc, x, y, x+w-2, y);
XDrawLine(display, d, gc, x, y+1, x, y+h-2);

XSetForeground(display, gc, color->shadow2);
XDrawLine(display, d, gc, x+w-1, y, x+w-1, y+h-2);
XDrawLine(display, d, gc, x+1, y+h-2, x+w-2, y+h-2);

}

-dav7

Discussion

  • J. Veenhuizen

    J. Veenhuizen - 2008-10-16

    Hi,

    I agree the appearance of depressed buttons isn't optimal. I tried your code and I can see your point, but I'm not completely convinced that is exactly how it should look. I think I want to keep more of a 3D look also when the buttons are depressed, but maybe not the current somewhat ugly 1990s inverted look. If you can come up with something that looks like the button in it's normal state, but still visually lowered, please resubmit. I will also try to come up with a suggestion.

    Thanks!
    Johan

     
  • J. Veenhuizen

    J. Veenhuizen - 2008-10-16
    • assigned_to: nobody --> veenhuizen
     
  • J. Veenhuizen

    J. Veenhuizen - 2008-10-16

    Diff that makes depressed buttons look more real.

     
  • J. Veenhuizen

    J. Veenhuizen - 2008-10-16

    Hi again,

    OK, I also came up with something. Please try the attached veenhuizen-button-1.diff and let me know what you think. The depressed buttons are offset and drawn with a somewhat different shading, but otherwise look almost like in their normal state. I tried to make them look "real".

    Best regards,
    Johan
    File Added: veenhuizen-button-1.diff

     
  • J. Veenhuizen

    J. Veenhuizen - 2008-10-22
    • status: open --> closed
     
  • J. Veenhuizen

    J. Veenhuizen - 2008-10-22

    I commited veenhuizen-button-1.diff

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks