home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Workbench / dosdrivers / Wacom_116.lha / Wacom_1.16 / Develop / get_pressure_V39.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-28  |  9.7 KB  |  292 lines

  1. /***********************************************************************/
  2. /* Demoprogram for obtaining generic tabletdata from Intuition         */
  3. /* ATTENTION !!! You need Kickstart 3.0 or better !                    */
  4. /*                                                                     */
  5. /* Prints some data which is provided by Intuition.                    */
  6. /* (Coordiantes, Pressure etc.)                                        */
  7. /***********************************************************************/
  8.  
  9. /***********************************************************************/
  10. /* Written in 1994 by:                                                 */
  11. /*                                                                     */
  12. /* Roland Schwingel                                                    */
  13. /* Lilienthalstrasse 9                                                 */
  14. /* 92421 Schwandorf                                                    */
  15. /* Germany                                                             */
  16. /*                                                                     */
  17. /* Email: roland.schwingel@extern.uni-regensburg.de                    */
  18. /* Phone: +49-(0)9431-5779                                             */
  19. /***********************************************************************/
  20.  
  21. /* INCLUDES ************/
  22. #include <stdio.h>
  23. #include <string.h>
  24.  
  25. #include <exec/exec.h>
  26. #include <proto/exec.h>
  27. #include <clib/exec_protos.h>
  28.  
  29. #include <intuition/intuition.h>
  30. #include <intuition/IntuitionBase.h>
  31. #include <proto/intuition.h>
  32. #include <clib/intuition_protos.h>
  33.  
  34. #include <utility/utility.h>
  35. #include <proto/utility.h>
  36. #include <clib/utility_protos.h>
  37.  
  38. /* global Variables ****/
  39. /* external */
  40. extern struct ExecBase           *SysBase;
  41.  
  42. /* local */
  43. struct IntuitionBase             *IntuitionBase;
  44. struct Library                   *UtilityBase;
  45. int                               offy;
  46.  
  47. char *ITexts[]=
  48. {
  49.  "»»»» mouse state «««««",
  50.  "MouseX       = %06d",
  51.  "MouseY       = %06d",
  52.  "MouseButtons = ",
  53.  "»»»» tablet state ««««",
  54.  "td_TabletX   = ",
  55.  "td_TabletY   = ",
  56.  "td_RangeX    = ",
  57.  "td_RangeY    = ",
  58.  "»»»» tablet tags «««««",
  59.  "Pressure     = ",
  60.  "ButtonBits   = ",
  61.  "InProximity  = ",
  62. };
  63.  
  64. struct TextAttr DefFont={(STRPTR)"topaz.font",TOPAZ_EIGHTY,FS_NORMAL     ,FPF_ROMFONT};
  65. struct IntuiText IText={1,0,JAM2,0,0,&DefFont, NULL,NULL};
  66. char buffer[80];
  67.  
  68. /* Version-Tag ***************************/
  69. UBYTE *vers="$VER:Get_Pressure_V39 1.1 ("__DATE__" "__TIME__") by Roland Schwingel.";
  70.  
  71. /* Prototypes **********/
  72. int      main(void);
  73. void     showtexts(char *mousebuttons,struct RastPort *rp,struct ExtIntuiMessage *EIMess);
  74.  
  75. /***********************************************************************/
  76. /* main()                                                              */
  77. /***********************************************************************/
  78. int main (void)
  79. {
  80. int                         retval=21;
  81. struct Window              *Win;
  82. struct RastPort            *WinRP;
  83. struct ExtIntuiMessage     *EIMess;
  84. BOOL                        cont=TRUE;
  85. ULONG                       class,Sigrcvd;
  86.  
  87.  /* Now open intution.library */
  88.  if(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",39L))
  89.  {
  90.   /* Get Offset for Textprinting */
  91.   offy=IntuitionBase->ActiveScreen->RastPort.TxHeight+
  92.        IntuitionBase->ActiveScreen->WBorTop +2;
  93.  
  94.   /* open utility.library for tag functions */
  95.   if(UtilityBase=OpenLibrary("utility.library",39L))
  96.   {
  97.    /* pointer to Text */
  98.    IText.IText=buffer;
  99.  
  100.    /* open the Window */
  101.    if(Win=OpenWindowTags(NULL,WA_Left,0,WA_Top,offy,WA_Width,198,WA_Height,13*9+offy+IntuitionBase->ActiveScreen->WBorBottom,
  102.                               WA_TabletMessages,TRUE,   /* <- This is the magic line which brings */
  103.                                                         /*    tabletdata to your window */
  104.                               WA_ReportMouse,TRUE,
  105.                               WA_IDCMP,  IDCMP_CLOSEWINDOW|IDCMP_MOUSEMOVE|IDCMP_MOUSEBUTTONS,
  106.                               WA_Flags,  WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  107.                               WA_Title,  "V39 Tabletdata", TAG_DONE))
  108.    {
  109.     /* Get the Rastport */
  110.     WinRP=Win->RPort;
  111.  
  112.     while(cont)
  113.     {
  114.      /* Wait for Window or CTRL-C Event */
  115.      Sigrcvd=Wait(1L << Win->UserPort->mp_SigBit|SIGBREAKF_CTRL_C);
  116.      {
  117.       /* Check CTRL-C */
  118.       if(Sigrcvd & SIGBREAKF_CTRL_C)
  119.        cont=FALSE;
  120.  
  121.       /* Check Event from Window */
  122.       if(Sigrcvd & 1L << Win->UserPort->mp_SigBit)
  123.       {
  124.        while(EIMess=(struct ExtIntuiMessage *)GetMsg(Win->UserPort))
  125.        {
  126.         class=EIMess->eim_IntuiMessage.Class;
  127.  
  128.         switch(class)
  129.         {
  130.          case IDCMP_CLOSEWINDOW:     cont=FALSE;      /* Somebody pushed the Closebutton */
  131.                                      retval=0;
  132.                                      break;
  133.  
  134.          case IDCMP_MOUSEBUTTONS:    switch(EIMess->eim_IntuiMessage.Code)
  135.                                      {
  136.                                       case SELECTDOWN: showtexts("LMBDOWN",WinRP,EIMess);
  137.                                                        break;
  138.  
  139.                                       case SELECTUP:   showtexts("LMBUP  ",WinRP,EIMess);
  140.                                                        break;
  141.  
  142.                                       case MIDDLEDOWN: showtexts("MMBDOWN",WinRP,EIMess);
  143.                                                        break;
  144.  
  145.                                       case MIDDLEUP:   showtexts("MMBUP  ",WinRP,EIMess);
  146.                                                        break;
  147.  
  148.                                       case MENUDOWN:   showtexts("RMBDOWN",WinRP,EIMess);
  149.                                                        break;
  150.  
  151.                                       case MENUUP:     showtexts("RMBUP  ",WinRP,EIMess);
  152.                                                        break;
  153.                                      }
  154.                                      break;
  155.  
  156.          case IDCMP_MOUSEMOVE:       showtexts("-------",WinRP,EIMess);
  157.                                      break;
  158.  
  159.          default:                    break;
  160.         }
  161.  
  162.         ReplyMsg((struct Message *)EIMess);     /* Send Msg back to Intuition */
  163.        }
  164.       }
  165.      }
  166.     }
  167.  
  168.     /* Close Window */
  169.     CloseWindow(Win);
  170.    }
  171.    else
  172.     printf("Can't open Window !!\n");
  173.  
  174.    /* Close Utility */
  175.    CloseLibrary(UtilityBase);
  176.   }
  177.   else
  178.    printf("Can't open utility.library V39+ !!!\n");
  179.  
  180.   /* Close Intution */
  181.   CloseLibrary((struct Library *)IntuitionBase);
  182.  }
  183.  else
  184.   printf("Unable to open intuition.library V39+ !!!\n");
  185.  
  186.  /* exit to Shell/WB */
  187.  return(retval);
  188. }
  189.  
  190. /***********************************************************************/
  191. /* showtexts(): Prints Intuitexts into Window                          */
  192. /***********************************************************************/
  193. void showtexts(char *mousebuttons,struct RastPort *rp,struct ExtIntuiMessage *EIMess)
  194. {
  195. static struct TagItem *tag;
  196.  
  197.  strcpy(buffer,ITexts[0]);
  198.  PrintIText(rp,&IText,10,(long)offy);
  199.  
  200.  sprintf(buffer,ITexts[1],EIMess->eim_IntuiMessage.MouseX);
  201.  PrintIText(rp,&IText,10,(long)offy+9);
  202.  
  203.  sprintf(buffer,ITexts[2],EIMess->eim_IntuiMessage.MouseY);
  204.  PrintIText(rp,&IText,10,(long)offy+2*9);
  205.  
  206.  strcpy(buffer,ITexts[3]);
  207.  strcat(buffer,mousebuttons);
  208.  PrintIText(rp,&IText,10,(long)offy+3*9);
  209.  
  210.  strcpy(buffer,ITexts[4]);
  211.  PrintIText(rp,&IText,10,(long)offy+4*9);
  212.  
  213.  if(EIMess->eim_TabletData)
  214.  {
  215.   /* Show only if available (don't check these fields under pre-V39 !) */
  216.   sprintf(buffer,"%s%06ld",ITexts[5],EIMess->eim_TabletData->td_TabletX);
  217.   PrintIText(rp,&IText,10,(long)offy+5*9);
  218.  
  219.   sprintf(buffer,"%s%06ld",ITexts[6],EIMess->eim_TabletData->td_TabletY);
  220.   PrintIText(rp,&IText,10,(long)offy+6*9);
  221.  
  222.   sprintf(buffer,"%s%06ld",ITexts[7],EIMess->eim_TabletData->td_RangeX);
  223.   PrintIText(rp,&IText,10,(long)offy+7*9);
  224.  
  225.   sprintf(buffer,"%s%06ld",ITexts[8],EIMess->eim_TabletData->td_RangeY);
  226.   PrintIText(rp,&IText,10,(long)offy+8*9);
  227.  
  228.   strcpy(buffer,ITexts[9]);
  229.   PrintIText(rp,&IText,10,(long)offy+9*9);
  230.  
  231.   if(EIMess->eim_TabletData->td_TagList)
  232.   {
  233.    if(tag=FindTagItem(TABLETA_Pressure,EIMess->eim_TabletData->td_TagList))
  234.     sprintf(buffer,"%s%06ld",ITexts[10],(LONG)tag->ti_Data);
  235.    else
  236.     sprintf(buffer,"%s------",ITexts[10]);
  237.    PrintIText(rp,&IText,10,(long)offy+10*9);
  238.  
  239.    if(tag=FindTagItem(TABLETA_ButtonBits,EIMess->eim_TabletData->td_TagList))
  240.     sprintf(buffer,"%s%06ld",ITexts[11],(LONG)tag->ti_Data);
  241.    else
  242.     sprintf(buffer,"%s------",ITexts[11]);
  243.    PrintIText(rp,&IText,10,(long)offy+11*9);
  244.  
  245.    if(tag=FindTagItem(TABLETA_InProximity,EIMess->eim_TabletData->td_TagList))
  246.     sprintf(buffer,"%s%d",ITexts[12],(BOOL)tag->ti_Data);
  247.    else
  248.     sprintf(buffer,"%s-",ITexts[12]);
  249.    PrintIText(rp,&IText,10,(long)offy+12*9);
  250.   }
  251.   else
  252.   {
  253.    /* no tags */
  254.    sprintf(buffer,"%s------",ITexts[10]);
  255.    PrintIText(rp,&IText,10,(long)offy+10*9);
  256.  
  257.    sprintf(buffer,"%s------",ITexts[11]);
  258.    PrintIText(rp,&IText,10,(long)offy+11*9);
  259.  
  260.    sprintf(buffer,"%s-",ITexts[12]);
  261.    PrintIText(rp,&IText,10,(long)offy+12*9);
  262.   }
  263.  }
  264.  else
  265.  {
  266.   sprintf(buffer,"%s------",ITexts[5]);
  267.   PrintIText(rp,&IText,10,(long)offy+5*9);
  268.  
  269.   sprintf(buffer,"%s------",ITexts[6]);
  270.   PrintIText(rp,&IText,10,(long)offy+6*9);
  271.  
  272.   sprintf(buffer,"%s------",ITexts[7]);
  273.   PrintIText(rp,&IText,10,(long)offy+7*9);
  274.  
  275.   sprintf(buffer,"%s------",ITexts[8]);
  276.   PrintIText(rp,&IText,10,(long)offy+8*9);
  277.  
  278.   strcpy(buffer,ITexts[9]);
  279.   PrintIText(rp,&IText,10,(long)offy+9*9);
  280.  
  281.   sprintf(buffer,"%s------",ITexts[10]);
  282.   PrintIText(rp,&IText,10,(long)offy+10*9);
  283.  
  284.   sprintf(buffer,"%s------",ITexts[11]);
  285.   PrintIText(rp,&IText,10,(long)offy+11*9);
  286.  
  287.   sprintf(buffer,"%s-",ITexts[12]);
  288.   PrintIText(rp,&IText,10,(long)offy+12*9);
  289.  }
  290. }
  291.  
  292.