[comp.sys.amiga] Workbench backdrop pattern program

garyo@masscomp.UUCP (03/17/87)

I got fed up with the monocolor backdrop of the Amiga screen, and the fact
that you couldn't tell the interior of a window from the screen background.
So I wrote this program that puts up a backdrop pattern, or tablecloth, on
the workbench screen.

I wrote two versions of the program; the first one works and the second
doesn't.  The first one opens a backdrop borderless window in the workbench
screen and simple_refreshes.  It takes about 20k for a 640x400 workbench
(I still haven't gotten morerows up yet!!)  But at least it does size itself
to the screen size so it should adapt just fine.
Its problem is that it doesn't work when the Workbench is loaded, since it
opens its OWN backdrop window, just like the WB.  They compete, icons
disappear and can't be dragged, etc.  But if you use CLI exclusively, it's
just the greatest.

The second version attempted to deal with that problem by not opening a window,
but appropriating the Workbench window itself.
First I tried just setting the area fill pattern in that window; no good
of course, because it ignores the pattern and just BltClears (I assume).
That's very bad.  But I didn't stop there.
I tried to replace Intuition's message port into that window
with my own, to intercept REFRESH messages and redraw the background;
this works pretty well as long as all you do is move windows around and don't
touch the icons.  Unfortunately as soon as you touch an icon, the Workbench
ModifyIDCMP()'s the port, and it's not the same port it used to be (I stole
it), and El Grande Guru comes to visit.  I post it in the hope that
someone will see the obvious way around this problem and fix it.

					Gary Oberbrunner
				{harvard,allegra,ihnp4}!masscomp!garyo

(don't forget to cut the .signature from the end!)

==============================================================================
Remember,		        Truth is not beauty;
Information is not knowledge; 	Beauty is not love;	  Gary Oberbrunner
Knowledge is not wisdom;     	Love is not music;	  ...!masscomp!garyo
Wisdom is not truth;    	Music is the best. - FZ
==============================================================================


#--------------------------------- cut here ----------------------------------
# This archive created on Mon Mar 16, 1987, at 06:19:24 PM.
#
# To unpack, cut out all lines above the dotted line, and any lines
# after the similar line near the end of the file.
# Then run the remaining file with /bin/sh (NOT /bin/csh) in the
# appropriate directory.  It will create the following files:
#
#    bkdrop.c
#    wbpat.c
#########################################################
if (test -d bkdrop.c) then
  echo bkdrop.c is an existing directory.  Cannot overwrite it.
  exit 2
fi
if (test -f bkdrop.c) then
  echo 'Should I overwrite the existing version of bkdrop.c (y/n)?  \c'
  read response
  if (test $response != y) then exit 99
  fi
fi
if (test -f bkdrop.c) then
  echo Overwriting bkdrop.c...
  else
  echo Creating bkdrop.c...
fi
sed 's/-//;s/%$//' << 'END.bkdrop.c' > bkdrop.c
-/*%
- * Workbench pattern hackery%
- * by Gary Oberbrunner%
- * 3-3-87%
- */%
-%
-#include <stdio.h>%
-#include <intuition/intuition.h>%
-%
-#define NEW(x, y) if ((x = (y *) malloc(sizeof(y))) == (y *) NULL) \%
-{	fprintf(stderr, "Can't get new y!\n"); Bye(25); }%
-%
-extern struct Window *OpenWindow();%
-extern void *OpenLibrary();%
-extern struct IntuiMessage *GetMsg();%
-extern struct MenuItem *ItemAddress();%
-extern BYTE *malloc();%
-%
-struct Window *MakeWindow();%
-%
-struct IntuitionBase *IntuitionBase = NULL;%
-struct GfxBase *GfxBase = NULL;%
-%
-struct Window *win = NULL;%
-%
-struct Menu *TheMenu = NULL;%
-struct MenuItem *CloseItem = NULL;%
-struct IntuiText *CloseName = NULL;%
-%
-char *progname;%
-int DidSetMenu = FALSE;%
-%
-InitGraphics()%
-{%
-   struct Screen *WBScreen;%
-%
-   if ((GfxBase = (struct GfxBase *)%
-		OpenLibrary("graphics.library",0L)) == NULL)%
-   {%
-      fprintf(stderr, "%s: No graphics library!!!\n", progname);%
-      Bye(1);%
-   }%
-   if ((IntuitionBase = (struct IntuitionBase *)%
-		OpenLibrary("intuition.library",0L)) == NULL)%
-   {%
-      fprintf(stderr, "%s: No intuition library here!\n", progname);%
-      Bye(1);%
-   }%
-   for (WBScreen = IntuitionBase->FirstScreen;%
-     (WBScreen->Flags & WBENCHSCREEN) == 0;%
-     WBScreen = WBScreen->NextScreen) {%
-	if (WBScreen->NextScreen == NULL) {%
-		fprintf(stderr,"No workbench screen!\n");%
-		Bye(10);%
-	}%
-   }%
-   win = MakeWindow(WBScreen->Width, WBScreen->Height, 0, 0);%
-   win->ScreenTitle = (UBYTE *)%
-		"Workbench Tablecloth v1.0 by Gary Oberbrunner";%
-%
-}%
-%
-struct Window *%
-MakeWindow(width, height, xoffset, yoffset)%
-int width, height, xoffset, yoffset;%
-{%
-   struct NewWindow nw;%
-   struct Window *window = NULL;%
-   register int i;%
-%
-   nw.LeftEdge = xoffset;%
-   nw.TopEdge = yoffset;%
-   nw.Width = width;%
-   nw.Height = height;%
-   nw.DetailPen = -1;%
-   nw.BlockPen = -1;%
-   nw.IDCMPFlags = CLOSEWINDOW | REFRESHWINDOW;%
-   nw.Flags = BACKDROP | BORDERLESS | SIMPLE_REFRESH;%
-   nw.FirstGadget = NULL;%
-   nw.CheckMark = NULL;%
-   nw.Title = NULL;%
-   nw.Type = WBENCHSCREEN;%
-   nw.Screen = NULL;%
-   nw.BitMap = NULL;%
-   if ((window = OpenWindow(&nw)) == NULL)%
-	{%
-	fprintf (stderr, "%s: Couldn't open the window.\n", progname);%
-	Bye(2);%
-	}%
-   return window;%
-}%
-%
-InitMenu(win)%
-struct Window *win;%
-{%
-NEW(CloseName, struct IntuiText);%
-CloseName->FrontPen = 0;%
-CloseName->BackPen = -1;%
-CloseName->DrawMode = JAM1;%
-CloseName->LeftEdge = 0;%
-CloseName->TopEdge = 5;%
-CloseName->ITextFont = NULL;%
-CloseName->IText = (UBYTE *) "Quit";%
-CloseName->NextText = NULL;%
-%
-NEW(CloseItem, struct MenuItem);%
-CloseItem->NextItem = NULL;%
-CloseItem->LeftEdge = 0;%
-CloseItem->TopEdge = 0;%
-CloseItem->Width = 101;%
-CloseItem->Height = 20;%
-CloseItem->Flags = (USHORT) (ITEMTEXT | HIGHCOMP | ITEMENABLED);%
-CloseItem->ItemFill = (APTR) CloseName;%
-CloseItem->SelectFill = NULL;%
-CloseItem->Command = NULL;%
-CloseItem->SubItem = NULL;%
-%
-NEW(TheMenu, struct Menu);%
-TheMenu->NextMenu = NULL;%
-TheMenu->LeftEdge = 0;%
-TheMenu->TopEdge = 0;%
-TheMenu->Width = 100;%
-TheMenu->Height = 10;%
-TheMenu->Flags = (USHORT) MENUENABLED;%
-TheMenu->MenuName = (BYTE *) "File";%
-TheMenu->FirstItem =  CloseItem;%
-%
-SetMenuStrip(win, TheMenu);%
-DidSetMenu = TRUE;%
-}%
-%
-Bye(val)%
-int val;%
-{%
-	if (DidSetMenu==TRUE)	ClearMenuStrip(win);%
-	if (CloseName)		free(CloseName);%
-	if (CloseItem)		free(CloseItem);%
-	if (TheMenu)		free(TheMenu);%
-	if (win)		CloseWindow(win);%
-	if (GfxBase)		CloseLibrary(GfxBase);%
-	if (IntuitionBase)	CloseLibrary(IntuitionBase);%
-	exit(val);%
-}%
-%
-USHORT pattern[] = {%
-	0x8080,%
-	0x8080,%
-	0x0000,%
-	0x0000,%
-	0x0808,%
-	0x0808,%
-	0x0000,%
-	0x0000,%
-%
-	0x0808,%
-	0x0808,%
-	0x0000,%
-	0x0000,%
-	0x8080,%
-	0x8080,%
-	0x0000,%
-	0x0000%
-};%
-long patlen = -3;%
-%
-main(argc, argv)%
-char **argv;%
-int argc;%
-{%
-long class;%
-struct IntuiMessage *msg;%
-USHORT MenuNumber;%
-%
-progname = argv[0];%
-InitGraphics();%
-InitMenu(win);%
-ModifyIDCMP(win, MENUPICK | CLOSEWINDOW | REFRESHWINDOW);%
-%
-SetAfPt(win->RPort, &pattern[0], patlen);%
-SetDrMd(win->RPort, (long) JAM2);%
-%
-RectFill(win->RPort, (long) win->BorderLeft, (long) win->BorderTop,%
-	(long) win->BorderLeft + win->Width + 1,%
-	(long) win->BorderTop  + win->Height + 1);%
-%
-while (1) {%
-	WaitPort(win->UserPort);%
-	while ((msg = GetMsg(win->UserPort)) != NULL) {%
-		class = msg->Class;%
-		MenuNumber = msg->Code;%
-		ReplyMsg(msg);%
-		switch (class) {%
-		    case CLOSEWINDOW:%
-				Bye(0);%
-		    case REFRESHWINDOW:%
-			BeginRefresh(win);%
-			RectFill(win->RPort,%
-				(long) win->BorderLeft,%
-				(long) win->BorderTop,%
-				(long) win->BorderLeft + win->Width + 1,%
-				(long) win->BorderTop  + win->Height + 1);%
-			EndRefresh(win, TRUE);%
-			break;%
-		    case MENUPICK:%
-			while (MenuNumber != MENUNULL) {%
-				if (ItemAddress(TheMenu, MenuNumber)%
-						== CloseItem) {%
-					Bye(0);%
-				}%
-				else fprintf(stderr,"Bad menu item %ld!\n",%
-					ItemAddress(TheMenu, MenuNumber));%
-				MenuNumber =%
-				ItemAddress(TheMenu,MenuNumber)->NextSelect;%
-			}%
-		}%
-	}%
-}%
-}%
-%
-SetAfPt(rp, pat, n)%
-struct RastPort *rp;%
-USHORT *pat;%
-long n;%
-{%
-rp->AreaPtrn = pat;%
-rp->AreaPtSz = (long) n;%
-}%
-%
-%
END.bkdrop.c
if (test -d wbpat.c) then
  echo wbpat.c is an existing directory.  Cannot overwrite it.
  exit 2
fi
if (test -f wbpat.c) then
  echo 'Should I overwrite the existing version of wbpat.c (y/n)?  \c'
  read response
  if (test $response != y) then exit 99
  fi
fi
if (test -f wbpat.c) then
  echo Overwriting wbpat.c...
  else
  echo Creating wbpat.c...
fi
sed 's/-//;s/%$//' << 'END.wbpat.c' > wbpat.c
-/*%
- * Workbench pattern hackery%
- * by Gary Oberbrunner%
- * 3-3-87%
- */%
-%
-#include <stdio.h>%
-#include <intuition/intuition.h>%
-%
-#define HEIGHT 20%
-#define WIDTH  120%
-#define XOFFSET 20%
-#define YOFFSET 40%
-%
-extern struct Window *OpenWindow();%
-extern void *OpenLibrary();%
-extern struct MsgPort *CreatePort();%
-extern struct IntuiMessage *GetMsg();%
-%
-struct Window *MakeWindow();%
-%
-struct IntuitionBase *IntuitionBase = NULL;%
-struct GfxBase *GfxBase = NULL;%
-%
-struct Window *win = NULL;%
-struct MsgPort *MyPort;%
-struct Screen *TheScreen;%
-struct Window *TheWindow;%
-struct MsgPort *IntuiPort = NULL;%
-char *progname;%
-%
-InitGraphics()%
-{%
-   if ((GfxBase = (struct GfxBase *)%
-		OpenLibrary("graphics.library",0L)) == NULL)%
-   {%
-      fprintf(stderr, "%s: No graphics library!!!\n", progname);%
-      Bye(1);%
-   }%
-   if ((IntuitionBase = (struct IntuitionBase *)%
-		OpenLibrary("intuition.library",0L)) == NULL)%
-   {%
-      fprintf(stderr, "%s: No intuition library here!\n", progname);%
-      Bye(1);%
-   }%
-   win = MakeWindow(WIDTH, HEIGHT, XOFFSET, YOFFSET);%
-}%
-%
-struct Window *%
-MakeWindow(width, height, xoffset, yoffset)%
-int width, height, xoffset, yoffset;%
-{%
-   struct NewWindow nw;%
-   struct Window *window = NULL;%
-   register int i;%
-%
-   nw.LeftEdge = xoffset;%
-   nw.TopEdge = yoffset;%
-   nw.Width = width;%
-   nw.Height = height;%
-   nw.DetailPen = -1;%
-   nw.BlockPen = -1;%
-   nw.IDCMPFlags = (long) CLOSEWINDOW;%
-   nw.Flags = WINDOWCLOSE | WINDOWDRAG;%
-   nw.FirstGadget = NULL;%
-   nw.CheckMark = NULL;%
-   nw.Title = NULL;%
-   nw.Type = WBENCHSCREEN;%
-   nw.Screen = NULL;%
-   nw.BitMap = NULL;%
-   if ((window = OpenWindow(&nw)) == NULL)%
-	{%
-	fprintf (stderr, "%s: Couldn't open the window.\n", progname);%
-	Bye(2);%
-	}%
-   return window;%
-}%
-%
-Bye(val)%
-int val;%
-{%
-	if (IntuiPort != NULL) {%
-				Forbid();%
-				TheWindow->UserPort = IntuiPort;%
-				Permit();%
-	}%
-	if (MyPort)		DeletePort(MyPort);%
-	if (win)		CloseWindow(win);%
-	if (GfxBase)		CloseLibrary(GfxBase);%
-	if (IntuitionBase)	CloseLibrary(IntuitionBase);%
-	exit(val);%
-}%
-%
-USHORT pattern[] = {%
-	0x8888,%
-	0x8888,%
-	0x2222,%
-	0x2222%
-};%
-long patlen = 2;%
-%
-main(argc, argv)%
-char **argv;%
-int argc;%
-{%
-struct IntuiMessage *msg;%
-%
-progname = argv[0];%
-InitGraphics();%
-%
-/*%
- * Find the Workbench screen (HACK!)%
- */%
-TheScreen = IntuitionBase->FirstScreen;%
-%
-/*%
- * Find the Workbench window%
- */%
-for (TheWindow = TheScreen->FirstWindow;%
-     (TheWindow->Flags & (WBENCHWINDOW | BACKDROP)) == 0;%
-     TheWindow = TheWindow->NextWindow) {%
-	printf("Window 0x%lx found...not workbench.\n",TheWindow);%
-	if (TheWindow->NextWindow == NULL) {%
-		fprintf(stderr,"No workbench window in this screen.\n");%
-		Bye(10);%
-	}%
-}%
-printf("Found workbench window at 0x%lx. (Flags: %lx  IDCMP: %lx)\n",%
-	TheWindow, TheWindow->Flags, TheWindow->IDCMPFlags);%
-%
-printf("Wbench MsgPort Flags == %x\n",TheWindow->UserPort->mp_Flags);%
-printf("Wbench MsgPort Sig == %d\n",TheWindow->UserPort->mp_SigBit);%
-printf("Wbench MsgPort Task == %lx\n",TheWindow->UserPort->mp_SigTask);%
-%
-printf("Area pattern for workbench window is %d words.\n",%
-	TheWindow->RPort->AreaPtSz);%
-printf("DrMd is %d.\n",%
-	TheWindow->RPort->DrawMode);%
-printf("APen, BPen are %d, %d.\n",%
-	TheWindow->RPort->FgPen, TheWindow->RPort->BgPen);%
-%
-SetAPen(TheWindow->RPort, 3L);%
-SetBPen(TheWindow->RPort, 0L);%
-SetAfPt(TheWindow->RPort, pattern, patlen);%
-SetDrMd(TheWindow->RPort, (long) JAM1);%
-%
-RectFill(TheWindow->RPort, 0L, 0L, 639L, 399L);%
-%
-if ((MyPort = CreatePort(NULL, 0)) == NULL) {%
-	fprintf(stderr,"Can't open new port.\n");%
-	Bye(50);%
-}%
-printf("My MsgPort Flags == %x\n",MyPort->mp_Flags);%
-printf("My MsgPort Sig == %d\n",MyPort->mp_SigBit);%
-printf("My MsgPort Task == %lx\n",MyPort->mp_SigTask);%
-%
-Forbid();%
-IntuiPort = TheWindow->UserPort;%
-TheWindow->UserPort = MyPort;%
-RemakeDisplay();%
-Permit();%
-%
-while (1) {%
-	fprintf(stderr,"Waiting for wkbench message...\n");%
-	Wait(~0L);%
-	while ((msg = GetMsg(MyPort)) != (struct IntuiMessage *) NULL) {%
-		if (msg->Class != REFRESHWINDOW) {%
-			fprintf(stderr,"Not refresh (%lx)\n", msg->Class);%
-			PutMsg(IntuiPort, msg);%
-		}%
-		else {%
-			/* This is needed since Class isn't valid%
-			 * after the PutMsg. */%
-			fprintf(stderr,"Refreshing.\n");%
-			RectFill(TheWindow->RPort, 0L, 0L, 639L, 399L);%
-			BeginRefresh(TheWindow);%
-			EndRefresh(TheWindow, FALSE);%
-			PutMsg(IntuiPort, msg);%
-		}%
-	}%
-	if (GetMsg(win->UserPort) != NULL) Bye(0);%
-}%
-}%
-%
-SetAfPt(rp, pat, n)%
-struct RastPort *rp;%
-USHORT *pat;%
-long n;%
-{%
-Forbid();%
-rp->AreaPtrn = pat;%
-rp->AreaPtSz = (long) n;%
-Permit();%
-}%
-%
-%
END.wbpat.c
#-------------------------------- end of archive; cut here -------------------
-- 
Remember,		       -Truth is not beauty;
Information is not knowledge; /	Beauty is not love;	  Gary Oberbrunner
Knowledge is not wisdom;     /	Love is not music;	  ...!masscomp!garyo
Wisdom is not truth;    ----/	Music is the best. - FZ

perry@sfsup.UUCP (03/18/87)

In article <1470@masscomp.UUCP>, garyo@masscomp.UUCP writes:
> 
> I got fed up with the monocolor backdrop of the Amiga screen, and the fact
> that you couldn't tell the interior of a window from the screen background.
> So I wrote this program that puts up a backdrop pattern, or tablecloth, on
> the workbench screen.
> 

Eric Lavitsky and I got bored with that a few months ago. And wrote a program
(way back) then to add patterns to the workbench screen.

> Its problem is that it doesn't work when the Workbench is loaded, since it
> opens its OWN backdrop window, just like the WB.  They compete, icons
> disappear and can't be dragged, etc.  But if you use CLI exclusively, it's
> just the greatest.

Our code works perfectly well with the workbench. Eric will be posting
the program in a few days since there seems to be such interest.

Perry