Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!cs.dal.ca!iisat!brains!george_seto
From: george_seto@brains.UUCP (George Seto)
Newsgroups: comp.sys.atari.st
Subject: (none)
Message-ID: <4827@brains.UUCP>
Date: 24 Sep 89 01:13:46 GMT
Reply-To: george_seto%brains@iisat.UUCP
Organization: Cerebral Cortex BBS
Lines: 199


  Re: ST's Desktop picture replacement C code:
 Jean Bujold

 I asked your question on the nets and here's a couple of answers
 for you. The author of the messages, I believe, is one of the people
 who are doing the Sozobon PD C Compiler. Hope it helps.

   89Jul22 4:27 pm from Ian@FWBBS (Legalize Freedom)
 George Seto:  To load a DEGAS pic, use the following code fragment:

  int fhandle, status;

   fhandle = Fopen("picture.pi2",0);
   if (fhandle < 0)
       return IO_ERROR;

   Fseek(34L, fhandle, 0);
   status = Fread(fhandle, 32000L, pointer_to_screen_buffer);
   Fclose(fhandle);
   if (status != 32000)
       return IO_ERROR;

  The Fseek() call skips the 1st 34 bytes to get to the actual picture data.
The first word of that 34 bytes is the screen rez (0,1,2), and the next 32
bytes are the color pallete.  Your program can load the machine pallete from
these values if appropriate.

 To install the picture as a replacement desktop (a la Easel/ST), you need to
write a routine that can do bit-blits to replace portitions of the screen
with the picture in response to redraw messages.  Build an object tree which
only contains one object, a USERDEF (also called PROGDEF) object.  The
routine pointed to by the USERDEF object is the routine to blit the picture
onto the screen.  When the AES dispatches your blit routine, it will pass the
x/y/w/h coords to be blitted in the PARMBLK structure, and your routine
receives a pointer to the PARMBLK as its only parameter.  An undocumented
feature of all this requires your blit routine to return a 0 to the AES.

 To install your object tree as the default desktop object, you need to do:

   wind_set(WF_NEWDESK, &object_tree, 0L);

 Don't do the wind_set until your blit routines are all initialized and your
picture is loaded.

 I used to have a whole pre-canned module to do all of the above.  I'll try
to find it and UL it as the next message...

   89Jul22 4:30 pm from Ian@FWBBS (Legalize Freedom)

  Routines to install a picture as the new desktop...

 #include 
 #include 

 #ifndef TRUE
 #define TRUE    1
 #define FALSE   0
 #endif

 /**************************************************************************
  *
  * desk_draw stuff...
  *
  *************************************************************************/

 static int  vdi_handle = -1;                 /* -1 == vdi not open yet */
 static int  work_in[11] = { 1,1,1,1,1,1,1,1,1,2 };
 static int  deskx2,
             desky2;
 static int  desk_draw();

 static USERBLK
      deskublk = {(long)desk_draw,            /* -> draw routine      */
                  0L                          /* user parm, not used  */
                  };

 static OBJECT
      desktree = {-1,-1,-1,                   /* head, next, tail     */
                  G_USERDEF,LASTOB,NORMAL,    /* type, flags, state   */
                  (long)&deskublk,            /* ob_spec -> userblk   */
                  0,0,0,0                     /* screen sizes         */
                  };

 static FDB deskfdb;

 /*------------------------------------------------------------------------
  * desk_draw - The draw routine called by AES to repaint the desktop.
  *----------------------------------------------------------------------*/

 int
 desk_draw(p_parmblk)
 register PARMBLK *p_parmblk;
 {
 register int  clipx2, clipy2;
 static   long dmyfdb = 0L;
 struct {
      VRECT blitr1;
      VRECT blitr2;
      } blitrect;

 clipx2 = p_parmblk->pb_xc + p_parmblk->pb_wc - 1;
 clipy2 = p_parmblk->pb_yc + p_parmblk->pb_hc - 1;

 if (clipx2 > deskx2)
      clipx2 = deskx2;
 if (clipy2 > desky2)
      clipy2 = desky2;

 blitrect.blitr1.v_x1 = p_parmblk->pb_xc;
 blitrect.blitr1.v_y1 = p_parmblk->pb_yc;
 blitrect.blitr1.v_x2 = clipx2;
 blitrect.blitr1.v_y2 = clipy2;

 blitrect.blitr2.v_x1 = p_parmblk->pb_xc;
 blitrect.blitr2.v_y1 = p_parmblk->pb_yc;
 blitrect.blitr2.v_x2 = clipx2;
 blitrect.blitr2.v_y2 = clipy2;

 vro_cpyfm(vdi_handle, S_ONLY, &blitrect, &deskfdb, &dmyfdb);

 return 0; /* this is required by the AES */
 }

 /*------------------------------------------------------------------------
  * desk_init - Set up the desk_draw system.
  *----------------------------------------------------------------------*/

 desk_init(pscrnbuf)
 long pscrnbuf;
 {
 int dmy;
 int work_out[57];

 vdi_handle = graf_handle(&dmy,&dmy,&dmy,&dmy);
 v_opnvwk(work_in, &vdi_handle, work_out);

 deskx2 = desktree.ob_width  = deskfdb.fd_w = work_out[0] + 1;
 desky2 = desktree.ob_height = deskfdb.fd_h = work_out[1] + 1;

 vq_extnd(vdi_handle, 1, work_out);
 deskfdb.fd_nplanes = work_out[4];

 deskfdb.fd_stand   = 0;
 deskfdb.fd_wdwidth = (0xFFF0 & (aesfdb.fd_w + 15)) / 16;
 deskfdb.fd_addr    = pscrnbuf;

 wind_set(0, WF_NEWDESK, &desktree, 0L);

  }

  /*------------------------------------------------------------------------
   * desk_exit - Shut down the desk_draw system.
   *----------------------------------------------------------------------*/

  desk_exit()
 {
 if (vdi_handle < 0)
       return(0);
 wind_set(0, WF_NEWDESK, 0L, 0L);
 v_clsvwk(vdi_handle);
 }

 /*------------------------------------------------------------------------
  * desk_sbuf - Set the pointer to the buffer the screen is redrawn from.
  *----------------------------------------------------------------------*/

 desk_sbuf(pscrnbuf)
 long pscrnbuf;
 {
 deskfdb.fd_addr = pscrnbuf;
 }

 /*------------------------------------------------------------------------
  * desk_redraw - Send redraw message to the desktop then wait for redraw.
  *----------------------------------------------------------------------*/

 desk_redraw(redrawrect)
 GRECT redrawrect;
 {
 form_dial(FMD_FINISH, 0,0,0,0, redrawrect);
 evnt_timer(0,0);
 }

 /* end of desk_draw stuff */

   The above was a message left by me for a fellow who was looking for this
same information from Saint John New Brunswick. It contains the results of
some information passed through to me in answer to his question about
replacing the Desktop with a Degas Picture. I recalled it when I saw the
mention by Noud from the Netherlands about his code. Hope he is willing to
send some of it out over the net and not just by mail. 
--
   -===------===-    From George Seto at Cerebral Cortex BBS System
  -==-==----==-==-   (902)462-7245 3/12/2400 8N1 24h/7d
 -==-------==------  george_seto%brains@iisat.UUCP
  -==-==----==-==-   {uunet, utai, watmath}!dalcs!iisat!brains!george_seto
   -===------===-