delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/03/19:34:01

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro GUI Problem
Date: Tue, 29 Jul 1997 19:31:52 +0100
Organization: None
Distribution: world
Message-ID: <O28gpIAYcj3zEw$z@talula.demon.co.uk>
References: <3 DOT 0 DOT 32 DOT 19970729144506 DOT 00693058 AT m1 DOT 261 DOT telia DOT com>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 65
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Daniel Mattsson writes:
>int my_button_proc(int msg, DIALOG *d, int c)
>{
> if (msg==MSG_DRAW)
> {
>   button = (BITMAP *)gui_data[normal_button].dat;
>   blit(button, screen, 0, 0, d->x, d->y, button->w, button->h);
>   if ((d->flags & D_SELECTED) && 
>       (d->flags & D_GOTFOCUS) && 
>       (d->flags & D_GOTMOUSE))
>   {
>    button = (BITMAP *)gui_data[pushed_button].dat;
>    blit(button, screen, 0, 0, d->x, d->y, button->w, button->h);
>   }
>   return D_O_K;
>  }
> return d_button_proc(msg, d, c);
>}

That looks fine to me. The only niggling criticism I have is that you
probably don't need to check for D_GOTFOCUS and D_GOTMOUSE in the flags
field: just D_SELECTED should be enough.

>When i run this the button behaves kinda like a checkbox, when the mouse is
>clicked over it it changes to the pushed_button bitmap. How do i make work
>like a normal button, so that the pushed_button bmp is displayed when the
>button is clicked and then when the button is released it will be
>overwritten with the normal_button bmp?

The behavior for how this button deals with mouse clicks is inherited
from the d_button_proc() object, so it will behave identically to a
standard button. These toggle between selected and unselected when the
mouse is clicked on them, and then track the mouse for as long as the
button is held down (so if you move the mouse off the button it will
deselect itself). When the mouse button is released, the behaviour of
the object depends on whether the D_EXIT bit is set in the flags field.
If it is, it deselects itself and returns a value of D_CLOSE (so the
dialog manager returns control to the caller, letting them process the
button click in whatever way is appropriate). If D_EXIT is not set, the
button behaves in the way you are seeing, simply toggling itself on and
off.

If you don't actually want to close the dialog when the button is
clicked, you can trap the D_CLOSE return value in your own routine, eg:

int my_button_proc(int msg, DIALOG *d, int c)
{
    int ret;

    /* custom display code goes here */

    ret = d_button_proc(msg, d, c);

    if (ret == D_CLOSE) {
        /* I've been clicked! What should we do here? */
        return D_REDRAW;
    }

    return ret;
}


--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
Beauty is a French phonetic corruption of a short cloth neck ornament.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019