home *** CD-ROM | disk | FTP | other *** search
/ Global Amiga Experience / globalamigaexperience.iso / compressed / graphic / arteffectdemodisk1.dms / arteffectdemodisk1.adf / Developer / example1.c next >
C/C++ Source or Header  |  1995-03-09  |  2KB  |  85 lines

  1. /* picotalk test */
  2.  
  3. #include "PreInclude.h"
  4. #include "PicoTalk.h"
  5.  
  6. struct MsgPort *myport;
  7. struct Library *EGSBlitBase;
  8.  
  9. BOOL SendMsg(struct Message *msg)
  10. {
  11.     struct MsgPort *port;
  12.     BOOL success;
  13.  
  14.     msg->mn_Node.ln_Type = NT_MESSAGE;
  15.     msg->mn_ReplyPort = myport;
  16.     msg->mn_Length = sizeof(struct PicoMsg);
  17.  
  18.     Forbid();
  19.     if (port = FindPort("PicoTalk")){
  20.         PutMsg(port, msg);
  21.         WaitPort(myport);
  22.         msg=GetMsg(myport);
  23.         success=TRUE;
  24.     } else
  25.         success=FALSE;
  26.  
  27.     Permit();
  28.     return success;
  29. }
  30.  
  31. main()
  32. {
  33.     struct E_EBitMap *bitmap;
  34.     struct PicoMsg *msg;
  35.     ULONG winid;
  36.     ULONG *data;
  37.     int x,y;
  38.  
  39.     EGSBlitBase = OpenLibrary("egsblit.library",0);
  40.  
  41.     myport=CreateMsgPort();
  42.  
  43.     msg=AllocVec(sizeof(struct PicoMsg), MEMF_PUBLIC|MEMF_CLEAR);
  44.     msg->command = PTALK_ALLOC_WINDOW;
  45.     msg->arg.alloc.width = 320;
  46.     msg->arg.alloc.height = 256;
  47.     msg->arg.alloc.name = "Hello World";
  48.     SendMsg((struct Message *)msg);
  49.     winid = msg->res.alloc.winid;
  50.     bitmap = msg->res.alloc.bitmap;
  51.  
  52.     msg->command = PTALK_OBTAIN_WINDOW;
  53.     msg->arg.winid = winid;
  54.     SendMsg((struct Message *)msg);
  55.  
  56.     for (y=0; y<256; y++){
  57.         for (x=0; x<256; x++){
  58.             union {
  59.                 ULONG val;
  60.                 struct { UBYTE r,g,b,a; } part;
  61.             } color;
  62.             color.part.r = x*x/128 - 2*x + 128 + y/2;
  63.             color.part.g = (int)(sqrt((double)(x*x + y*y)) / 1.41);
  64.             color.part.b = (x+y)/2;
  65.             EB_WritePixel(bitmap, color.val, x,y, 0);
  66.         }
  67.         msg->command = PTALK_UPDATE_WINDOW;
  68.         msg->arg.update.winid = winid;
  69.         msg->arg.update.left = 0;
  70.         msg->arg.update.top = y;
  71.         msg->arg.update.width = bitmap->Width;
  72.         msg->arg.update.height = 1;
  73.         SendMsg((struct Message *)msg);
  74.     }
  75.  
  76.     msg->command = PTALK_RELEASE_WINDOW;
  77.     msg->arg.winid = winid;
  78.     SendMsg((struct Message *)msg);
  79.  
  80.     FreeVec(msg);
  81.     DeleteMsgPort(myport);
  82.  
  83.     CloseLibrary(EGSBlitBase);
  84. }
  85.