[comp.sys.amiga.tech] Gadget help wanted

rick@tmiuv0.uucp (02/03/90)

In article <1039LK-KARI@FINTUVM>, LK-KARI@FINTUVM.BITNET (Kari Sutela) writes:
> I'm having some problems with a small program I made while trying to learn
> proper gadget-programming. The problem is that the OnGadget(), OffGadget(),
> and the RemoveGadget() functions don't bevahe quite the way I expected them
> to do. The problems concern the rendering of the gadgets:
> 
>    1. If I OffGadget() a gadget and then later on OnGadget() it again, the
>    gadget will be rendered in the enabled state only if it is an image-gadget.
>    If the gadget only has some IntuiText linked to it, it can be selected
>    but it will stay ghosted all the time.

Yup. That's true. If you have a copy of the Intuition manual, there is a
caveat about that in the secton on gadgets. I don't have my copy handy, but
"it's in there".

>    2. If I AddGadget() a gadget and then later on RemoveGadget() it, it will
>    be impossible to select it, but it won't disappear from the display even
>    though I call RefreshGadgets() immediately after the RemoveGadget().

Um, ya got me there. I've heard of that problem, but I can't remember the
workaround.

> [...]
> - Kari Sutela  lk-kari@mammutti.utu.fi or sutela@tucos.utu.fi
> 
> PS. Pardon my bad english.

Your English was just fine, Kari. Better than most Americans, in fact!
-- 
+--------------------------------------------------------------------+
| Rick Stevens           Opinions are mine. No one else wants them!  |
|                                                                    |
| Bang!: ..uunet!zardoz!tmiuv0!rick                    (day job)     |
|        ..uunet!perigrine!ccicpg!conexch!amoeba2!rps2 (home)        |
|        ..uunet!zardoz!xyclone!rps2                   (home again!) |
| CIS:   75006,1355 -or- 75006.1355@compuserve.com     (whenever!)   |
|                                                                    |
|          Growing old ain't for sissies - Bette Davis               |
+--------------------------------------------------------------------+

a464@mindlink.UUCP (Bruce Dawson) (02/08/90)

> tron1 writes:
> 
> Msg-ID: <25d085dd:842.4comp.sys.amiga.tech;1@tronsbox.UUCP>
> Posted: 7 Feb 90 20:32:46 GMT
> 
> Person: HIM
> 
> >In article <1039LK-KARI@FINTUVM>, LK-KARI@FINTUVM.BITNET (Kari Sutela)
> writes:
> >>    2. If I AddGadget() a gadget and then later on RemoveGadget() it, it
> will
> >>    be impossible to select it, but it won't disappear from the display
> even
> >>    though I call RefreshGadgets() immediately after the RemoveGadget().
> 
> You have to call RemakeDisplay() I think .. that should make 100% sure
> that the screen reflects ONLY what should be there.
> 
> *********************************************************************** *****
> Everything I say is Copr.  1990, except the stuff I stole from someone else
> and the stuff I don't want responsibility for.
> 
> Kenneth J. Jamieson: Xanadu Enterprises Inc. "Professional Amiga Software"
>       UUCP: tron1@tronsbox.UUCP  BEST PATH ---> uunet!tronsbox!tron1
>       Sysop, Romantic Encounters BBS - (201)759-8450 / (201)759-8568
> *********************************************************************** *****

     WRONG!  This is a common misunderstanding, one that I have seen propagated
through entire books on programming the Amiga.  There are basically two ways of
affecting what is seen on the Amiga screen.

     1)  Change the values being thrown into the display chip.  This is usually
done by the copper.  This allows you to change colours, move screens, display
different areas of memory, different resolutions etc.  This method does not
(necessarily) require changing any memory locations.

     2)  Change some data in a bitmap.  If a gadget has been rendered into a
bitmap, as above, then to clear that gadget you must somehow clear the bits
that were set in the bitmap.  Doing a RefreshGadgets() after removing the
gadget doesn't work because the gadget isn't there anymore, Intuition doesn't
know about it, so it can't refresh it.  RefreshGadgets is a very simple/stupid
routine that simply redraws all the gadgets it knows about.  It also only
highlights those that are active, which has other interesting implications
(basically inactive gadgets won't get visually deselected by RefreshGadgets(),
but active ones may, depending on the hightlight method used and the previous
state).  Probably the best solution here is to use RectFill() to clear away the
bits.

     RemakeDisplay remakes the copper lists which play with the display chip.
ie; it is a method 1 way of changing what is displayed.  Although this method
could be used to make the gadget invisible, it would probably also take the
rest of the screen with it if you did that, which is presumably not what you
want.

.Bruce.

tron1@tronsbox.UUCP (HIM) (02/08/90)

>In article <1039LK-KARI@FINTUVM>, LK-KARI@FINTUVM.BITNET (Kari Sutela) writes:
>>    2. If I AddGadget() a gadget and then later on RemoveGadget() it, it will
>>    be impossible to select it, but it won't disappear from the display even
>>    though I call RefreshGadgets() immediately after the RemoveGadget().

You have to call RemakeDisplay() I think .. that should make 100% sure
that the screen reflects ONLY what should be there.

****************************************************************************
Everything I say is Copr.  1990, except the stuff I stole from someone else
and the stuff I don't want responsibility for.
 
Kenneth J. Jamieson: Xanadu Enterprises Inc. "Professional Amiga Software"
      UUCP: tron1@tronsbox.UUCP  BEST PATH ---> uunet!tronsbox!tron1 
      Sysop, Romantic Encounters BBS - (201)759-8450 / (201)759-8568 
****************************************************************************

cmcmanis@stpeter.Sun.COM (Chuck McManis) (02/09/90)

No one seems to have actually answered this completely, Bruce came close.

RemoveGadget does not "remove" the bits of the gadget from your window,
it just removes it from the list of gadgets that Intuition is checking for
when mouse clicks come in. 

To make it disappear try this :

void
ClearGadget(win, gad)
	struct Window	*win;	/* Window with gadget in it. */
	struct Gadget	*gad;	/* The gadget to clear 	     */
{
	short	OldAPen;

	OldAPen = win->RPort->FgPen;
	SetAPen(win->RPort, win->BlockPen);
	Rectfill(win->RPort, gad->LeftEdge, gad->TopEdge, 
		 gad->LeftEdge + gad->Width, gad->TopEdge + gad->Height);
	SetAPen(win->RPort, OldAPen);
	return;
}

This presumes that BlockPen is what you rendered underneath the
gadget. If you have refresh routine that re-renders your window
that would work as well in something like this :

void
RedrawEverything(win)
	struct Window	*win; /* The window to redraw */
{
	/* Clear the window completely */
	SetAPen(win->RPort, win->BlockPen);
	RectFill(win->RPort, win->BorderLeft, win->BorderTop,
 	    win->Height - win->BorderBottom, win->Width - win->BorderRight);

	/* Call your refresh routine to re-render it */
	UserRedrawRoutine(); /* Re render your window */
	
	/* Refresh the Intui stuff like the gadgets and the frame */
	RefreshGadgets(win->FirstGadget, win, NULL);
	RedrawWindowFrame(win);
	return ;
}


--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@Eng.Sun.COM
These opinions are my own and no one elses, but you knew that didn't you.
"If it didn't have bones in it, it wouldn't be crunchy now would it?!"

BAXTER_A@wehi.dn.mu.oz (02/09/90)

In article <25d085dd:842.4comp.sys.amiga.tech;1@tronsbox.UUCP>, tron1@tronsbox.UUCP (HIM) writes:
>>In article <1039LK-KARI@FINTUVM>, LK-KARI@FINTUVM.BITNET (Kari Sutela) writes:
>>>    2. If I AddGadget() a gadget and then later on RemoveGadget() it, it will
>>>    be impossible to select it, but it won't disappear from the display even
>>>    though I call RefreshGadgets() immediately after the RemoveGadget().
> 
> You have to call RemakeDisplay() I think .. that should make 100% sure
> that the screen reflects ONLY what should be there.

This is right, but not optimal. I draw a patch of background colour to get rid
of the gadget immagery. That way you don't hog system recources just to clean
up a tiny part of the display.
Regards Alan
> 
> ****************************************************************************
> Everything I say is Copr.  1990, except the stuff I stole from someone else
> and the stuff I don't want responsibility for.
>  
> Kenneth J. Jamieson: Xanadu Enterprises Inc. "Professional Amiga Software"
>       UUCP: tron1@tronsbox.UUCP  BEST PATH ---> uunet!tronsbox!tron1 
>       Sysop, Romantic Encounters BBS - (201)759-8450 / (201)759-8568 
> ****************************************************************************

jimm@amiga.UUCP (Jim Mackraz) (02/13/90)

In article (HIM) writes:
)>>    2. If I AddGadget() a gadget and then later on RemoveGadget() it, it will
)>>    be impossible to select it, but it won't disappear from the display even
)>>    though I call RefreshGadgets() immediately after the RemoveGadget().
)
)You have to call RemakeDisplay() I think .. that should make 100% sure
)that the screen reflects ONLY what should be there.

Yow, is that ever wrong.  yeeussh.
Intuition V1.3 and earlier has no support for erasing gadgets, so you
just have to do it yourself.  For most situations, I think something
like this will work:

SetAPen( window->RPort, 0 );
RectFill( window->RPort, g->LeftEdge, g->TopEdge,
	g->LeftEdge + g->Width - 1, g->TopEdge + g->Height - 1 );

If the gadget is GRELBOTTOM or something like that, you have to
do more work.  Likewise if it's in a requester or gimmezerozero border.

	jimm

PS: RemakeDisplay() recalculates all intermediate and hardware copper list
for the viewports of Intuition's screens.  It has no effect whatsoever
on the contents any bitmap, just the display instructions to get those
bitmaps displayed.

)Kenneth J. Jamieson: Xanadu Enterprises Inc. "Professional Amiga Software"

... which software is undoubtedly wonderful but probably doesn't
use RemakeDisplay() ;^)

	jimm

-- 
--------------------------------------------------	- opinions by me
"This voice console is a *must*.  I press Execute. 
 `Hello, I know that you've been feeling tired.
  I bring you love and deeper understanding.' "		-lyrics by Kate Bush

doug@xdos.UUCP (Doug Merritt) (02/15/90)

In article <5200@amiga.UUCP> jimm@superman.UUCP (Jim Mackraz) writes:
>Intuition V1.3 and earlier has no support for erasing gadgets, so you
>just have to do it yourself.  For most situations, I think something
>like this will work:
>
>SetAPen( window->RPort, 0 );
>RectFill( window->RPort, g->LeftEdge, g->TopEdge,
>	g->LeftEdge + g->Width - 1, g->TopEdge + g->Height - 1 );
>
>If the gadget is GRELBOTTOM or something like that, you have to
>do more work.  Likewise if it's in a requester or gimmezerozero border.


I did this recently, for temporarily dumping all the system gadgets
from a window. It's a pain to get it right, at least when you want
to turn them on/off at will. When you put them back again, for instance,
the first vertical line of pixels at the start of the title is not redrawn
by anything I could find to try, so I had to put it back myself. You
would think that when the title gets refreshed, that it would include
that.

The net effect is nice, though...when this tiny window is deactivated,
it uses the entire interior for displaying a graph (it's a perfmeter).
When it's activated, the system gadgets come back for friendly control.
This makes the perfmeter usable even in very small dimensions.
	Doug
-- 
Doug Merritt		{pyramid,apple}!xdos!doug
Member, Crusaders for a Better Tomorrow		Professional Wildeyed Visionary