Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: ami_stuff on April 03, 2011, 03:45:26 AM

Title: Problem with SA_BackFill
Post by: ami_stuff on April 03, 2011, 03:45:26 AM
Hi,

Maybe someone can tell me what is wrong with this code. WA_BackFill works correctly, but SA_BackFill not :/

Quote

   #include
   #include
   #include
   #include
   #include
   #include
   #include

struct Library *CyberGfxBase;

struct BackfillMsg
{
ULONG dummy;
struct Rectangle rect;
LONG offsetx, offsety;
};


void sbackfillfunc (struct Hook *hook, struct RastPort *frp, struct BackfillMsg *bfm)
{

    struct RastPort rp;

    CopyMem(frp, &rp, sizeof(struct RastPort));
    rp.Layer = NULL;    

FillPixelArray(&rp,bfm->rect.MinX, bfm->rect.MinY, bfm->rect.MaxX - bfm->rect.MinX + 1, bfm->rect.MaxY - bfm->rect.MinY + 1, 0x00000000);
}

struct Hook bfhook;



int main (void)

   {

        CyberGfxBase = OpenLibrary("cybergraphics.library",0);


         struct Window *win;
         struct Screen *scr;

                        bfhook.h_Entry    = (HOOKFUNC)HookEntry;
              bfhook.h_SubEntry = (HOOKFUNC)sbackfillfunc;


                        scr = OpenScreenTags(NULL,
                         SA_LikeWorkbench,TRUE,
               SA_BackFill,&bfhook,
               TAG_DONE);


         if (win = OpenWindowTags (NULL,
               WA_Left,200,
               WA_Top,200,
               WA_Width,scr->Width / 2,
               WA_Height,scr->Height / 2,
               WA_Flags,WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_SIZEGADGET | WFLG_ACTIVATE | WFLG_NOCAREREFRESH,
               WA_IDCMP,IDCMP_CLOSEWINDOW,
               WA_Title,"Test",
               WA_BackFill,&bfhook,
               WA_PubScreen, scr,
               TAG_END))
            {
            BOOL cont = TRUE;

            do   {
               struct IntuiMessage *imsg;

               if (Wait ((1L << win->UserPort->mp_SigBit) | SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
                  cont = FALSE;

               while (imsg = (struct IntuiMessage *) GetMsg (win->UserPort))
                  {
                  switch (imsg->Class)
                     {
                  case IDCMP_CLOSEWINDOW:
                     cont = FALSE;
                     break;
                     }
                  ReplyMsg ((struct Message *) imsg);
                  }
               }
            while (cont);

            CloseWindow (win);
            }


   CloseScreen (scr);

   return (RETURN_OK);
   }


Regards
Title: Re: Problem with SA_BackFill
Post by: Thomas on April 03, 2011, 08:02:38 AM
It does work. If you move the window away, the revealed areas are filled with black as intended.

The problem is that installing the hook does not invoke it. You either need to call it manually or open and close a window which covers the entire screen.

Edit: this may be used to call the hook manually:

Quote

struct BackfillMsg tempbfm;
tempbfm.rect.MinX = 0;
tempbfm.rect.MinY = scr->BarHeight + 1;
tempbfm.rect.MaxX = scr->Width - 1;
tempbfm.rect.MaxY = scr->Height - 1;
CallHookPkt (&bfhook,&scr->RastPort,&tempbfm);
Title: Re: Problem with SA_BackFill
Post by: ami_stuff on April 03, 2011, 11:07:03 AM
Thanks Thomas. To reduce the flickering on the screen (gray->black)  I decided to use SA_Behind + ScreenToFront() combination, but maybe there is a better method?
Title: Re: Problem with SA_BackFill
Post by: matthey on April 03, 2011, 02:28:41 PM
Could use a backdrop (WA_Backdrop) window on the screen? This type of window always stays in the back and looks like it's the screen but has the advantages of a window.
Title: Re: Problem with SA_BackFill
Post by: ami_stuff on April 03, 2011, 04:47:22 PM
@matthey

This flickers as well, because screen is still gray at the beginning and next "repleaced" by black window.
Title: Re: Problem with SA_BackFill
Post by: matthey on April 03, 2011, 05:48:45 PM
Quote from: ami_stuff;627269
@matthey
This flickers as well, because screen is still gray at the beginning and next "replaced" by black window.


Grey is the default color. The window color could be set with graphics/SetRast() for <=8 bit depth and cybergraphics/FillPixelArray() for >8 bit depth. It's been a long time since I played with Intuition so maybe there is a better idea.