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

  1. /* picotalk test */
  2.  
  3. #include <math.h>
  4. #include <mieeedoub.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <dos.h>
  9. #include <signal.h>
  10.  
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <exec/ports.h>
  14. #include <exec/lists.h>
  15. #include <exec/nodes.h>
  16.  
  17. #include <egs/ownall.h>
  18. #include <egs/egsutil.h>
  19.  
  20. #include <egs/proto/egsutil.h>
  21. #include <proto/exec.h>
  22. #include <proto/dos.h>
  23.  
  24. #include "PicoTalk.h"
  25.  
  26. struct MsgPort *myport;
  27. struct Library *EGSBlitBase;
  28.  
  29. BOOL SendMsg(struct Message *msg)
  30. {
  31.     struct MsgPort *port;
  32.     BOOL success;
  33.  
  34.     msg->mn_Node.ln_Type = NT_MESSAGE;
  35.     msg->mn_ReplyPort = myport;
  36.     msg->mn_Length = sizeof(struct PicoMsg);
  37.     Forbid();
  38.     if (port = FindPort("PicoTalk")){
  39.         PutMsg(port, msg);
  40.         WaitPort(myport);
  41.         msg=GetMsg(myport);
  42.         success=TRUE;
  43.     } else
  44.         success=FALSE;
  45.  
  46.     Permit();
  47.     return success;
  48. }
  49.  
  50. main()
  51. {
  52.     struct E_EBitMap *bitmap;
  53.     struct PicoMsg *msg;
  54.     ULONG winid;
  55.     ULONG *data;
  56.     int x,y;
  57.  
  58.     // nasty but quick - I know... :-)
  59.     EGSBlitBase = OpenLibrary("egsblit.library",0);
  60.  
  61.     myport=CreateMsgPort();
  62.  
  63.     msg=AllocVec(sizeof(struct PicoMsg), MEMF_PUBLIC|MEMF_CLEAR);
  64.     msg->command = PTALK_OBTAIN_CURRENT;
  65.     msg->res.alloc.winid = 0;
  66.     msg->res.alloc.bitmap = NULL;
  67.     SendMsg((struct Message *)msg);
  68.     winid = msg->res.alloc.winid;
  69.     bitmap = msg->res.alloc.bitmap;
  70.  
  71.     if (bitmap){
  72.     for (y=0; y<bitmap->Width; y++){
  73.         for (x=0; x<bitmap->Height; x++){
  74.             union {
  75.                 ULONG val;
  76.                 struct { UBYTE r,g,b,a; } part;
  77.             } color;
  78.             color.part.r = x*x/128 - 2*x + 128 + y/2;
  79.             color.part.g = (int)(sqrt((double)(x*x + y*y)) / 1.41);
  80.             color.part.b = (x+y)/2;
  81.             EB_WritePixel(bitmap, color.val, x,y, 0);
  82.         }
  83.         msg->command = PTALK_UPDATE_WINDOW;
  84.         msg->arg.update.winid = winid;
  85.         msg->arg.update.left = 0;
  86.         msg->arg.update.top = y;
  87.         msg->arg.update.width = bitmap->Width;
  88.         msg->arg.update.height = 1;
  89.         SendMsg((struct Message *)msg);
  90.     }
  91.  
  92.     msg->command = PTALK_RELEASE_WINDOW;
  93.     msg->arg.winid = winid;
  94.     SendMsg((struct Message *)msg);
  95.     }
  96.  
  97.     FreeVec(msg);
  98.     DeleteMsgPort(myport);
  99.     CloseLibrary(EGSBlitBase);
  100. }
  101.