home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Programming / MR_Classes / Dev / Source / tcpalette / Input.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-15  |  9.0 KB  |  319 lines

  1. #define DEBUG
  2. #include <debug.h>
  3.  
  4. #include "private.h"
  5. #include "protos.h"
  6.  
  7. ULONG pr_Mix(ULONG A,ULONG B, float Percent);
  8.  
  9. #define MRK_BUFFER_SIZE 3
  10.  
  11. ULONG __saveds gad_HandleInput(Class *C, struct Gadget *Gad, struct gpInput *Input)
  12. {
  13.   ULONG retval;
  14.   char buffer[MRK_BUFFER_SIZE];
  15. //  LONG  key;
  16.   struct GadData *gdata;
  17.   struct InputEvent *ie; 
  18.   
  19.   gdata=INST_DATA(C, Gad);
  20.   retval = GMR_MEACTIVE;
  21.   ie = Input->gpi_IEvent;
  22.  
  23.   switch(ie->ie_Class)
  24.   {
  25.     case IECLASS_RAWKEY:
  26. //      KP("RAW KEY CODE - %lx %8lx\n",ie->ie_Code,ie->ie_Qualifier);
  27. //        gdata->gd_MouseMode=0;
  28.       
  29.       switch(ie->ie_Code)
  30.       {
  31.         case 0x4c: // UP
  32.           {
  33.             LONG t;
  34.             
  35.             t=gdata->ActivePen-gdata->Cols;
  36.             if(t<0) t+=gdata->Pens;
  37.             if(t<0) t=0; // double check!
  38.             gdata->ActivePen=t;
  39.             
  40.             gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);      
  41.             i_Notify(C,Gad,(APTR)Input, 0);
  42.           }
  43.           break;
  44.         
  45.         case 0x4f: // LEFT
  46.           {
  47.             LONG t;
  48.             
  49.             t=gdata->ActivePen-1;
  50.             if(t<0) t=gdata->Pens-1;
  51.             gdata->ActivePen=t;
  52.             
  53.             gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);      
  54.             i_Notify(C,Gad,(APTR)Input, 0);
  55.           }            
  56.           break;
  57.           
  58.         case 0x4e: // RIGHT
  59.           {
  60.             LONG t;
  61.             
  62.             t=gdata->ActivePen+1;
  63.             if(t>=gdata->Pens) t=0;
  64.             gdata->ActivePen=t;
  65.             
  66.             gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);      
  67.             i_Notify(C,Gad,(APTR)Input, 0);
  68.           }
  69.           break;            
  70.         
  71.         case 0x4d: // DOWN
  72.           {
  73.             LONG t;
  74.             
  75.             t=gdata->ActivePen+gdata->Cols;
  76.             if(t>=gdata->Pens) t-=gdata->Pens;
  77.             if(t>=gdata->Pens) t=0; // double check!
  78.             gdata->ActivePen=t;
  79.             
  80.             gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);      
  81.             i_Notify(C,Gad,(APTR)Input, 0);
  82.           }
  83.           break;
  84.           
  85.         default:
  86.           if(MapRawKey(ie,buffer,MRK_BUFFER_SIZE,0))
  87.           {
  88.        //     KP("%ld %lc\n",buffer[0],buffer[0]);
  89.             
  90.             switch(buffer[0])
  91.             {
  92.               case 27: // Esc
  93.                 retval=GMR_NOREUSE;
  94.                 break;
  95.               case 155: //  Shift + TAB
  96.                 retval=GMR_NOREUSE | GMR_PREVACTIVE;
  97.                 break;
  98.               case  9:  // TAB
  99.                 retval=GMR_NOREUSE | GMR_NEXTACTIVE;
  100.                 break;
  101.               case 0x20:
  102. //                  step=(shifted?-1:1);
  103.                 break;
  104.             }
  105.           }
  106.           break;
  107.       }
  108.       break;
  109.     case IECLASS_RAWMOUSE:
  110.       {
  111.         LONG x,y;
  112.         LONG r,c;
  113.         
  114. //        retval = GMR_MEACTIVE;
  115.         
  116.         x=(Input->gpi_Mouse).X+Gad->LeftEdge;
  117.         y=(Input->gpi_Mouse).Y+Gad->TopEdge;
  118.         
  119. //          DKP("RawMouse %ld %ld\n", x, y);
  120.         if(gdata->MouseMode)
  121.         {
  122.           for(r=0; r<gdata->Rows; r++)
  123.           {
  124.             if(y>=gdata->Row[r] && y<gdata->Row[r+1])
  125.               break;
  126.           }
  127.           
  128.           for(c=0; c<gdata->Cols; c++)
  129.           {
  130.             if(x>=gdata->Col[c] && x<gdata->Col[c+1])
  131.               break;
  132.           }
  133.           
  134. //          DKP("  c=%ld r=%ld\n", c, r);
  135.           
  136.           if(c<gdata->Cols && r<gdata->Rows)
  137.           {
  138.             gdata->ActivePen=r * gdata->Cols + c;
  139.             if(gdata->ActivePen!=gdata->LastActivePen)
  140.             {
  141.               i_StoreUndoIfNeeded(C,Gad,Input);
  142.               i_Notify(C,Gad,(APTR)Input, OPUF_INTERIM);
  143.               gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);
  144.             }
  145.           }
  146.         }
  147.  
  148.         switch(ie->ie_Code)
  149.          {
  150.           case SELECTUP:
  151.              gdata->MouseMode=0;
  152.           
  153.  
  154.             {// inside gadget
  155.               ULONG em;
  156.               
  157.               em=gdata->EditMode;
  158.               gdata->EditMode=0;
  159.               
  160.               
  161.               switch(em)
  162.               {
  163.                 case TCPEM_COPY:
  164.                   i_AddUndo(gdata, gdata->ActivePen,0,0);
  165.                   gdata->Palette[gdata->ActivePen]=gdata->Palette[gdata->EMPen];
  166.                   gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);
  167.                   break;
  168.                 case TCPEM_SPREAD:
  169.                   {
  170.                     ULONG l,c1,c2,c3,r1,r2,g1,g2,b1,b2;
  171.                     float p;
  172.                       
  173.                       
  174. //                        pr_SetUndoBuffer(PReq);
  175.                     
  176.                     if(gdata->EMPen>gdata->ActivePen)
  177.                     {
  178.                       c1=gdata->ActivePen;
  179.                       c2=gdata->EMPen;
  180.                     }
  181.                     else
  182.                     {
  183.                       c2=gdata->ActivePen;
  184.                       c1=gdata->EMPen;
  185.                     }
  186.                     
  187.                     c3=c2-c1;
  188.                     
  189.                     if(c3>1)
  190.                     {
  191.                       r1=gdata->Palette[c1].R;
  192.                       g1=gdata->Palette[c1].G;
  193.                       b1=gdata->Palette[c1].B;
  194.                       
  195.                       r2=gdata->Palette[c2].R;
  196.                       g2=gdata->Palette[c2].G;
  197.                       b2=gdata->Palette[c2].B;
  198.  
  199.                       for(l=c1+1;l<c2;l++)
  200.                       {
  201.                         i_AddUndo(gdata, l ,0,!(l==(c1+1)));                
  202.                         p=(float)(l-c1)/(float)c3;
  203.                         gdata->Palette[l].R       =pr_Mix(r1,r2,p);
  204.                         gdata->Palette[l].G       =pr_Mix(g1,g2,p);
  205.                         gdata->Palette[l].B       =pr_Mix(b1,b2,p);  
  206.                       }
  207.                     }
  208.                   }
  209.                   gad_Render(C,Gad,(APTR)Input,GREDRAW_REDRAW);
  210.                   break;
  211.                 case TCPEM_SWAP:
  212.                   {
  213.                     struct TCPaletteRGB dummy;
  214.  
  215.                     i_AddUndo(gdata, gdata->ActivePen ,0,0);  
  216.                     i_AddUndo(gdata, gdata->EMPen     ,0,1);  
  217.                                         
  218.                     dummy=gdata->Palette[gdata->ActivePen];
  219.                     gdata->Palette[gdata->ActivePen]=gdata->Palette[gdata->EMPen];
  220.                     gdata->Palette[gdata->EMPen]=dummy;
  221.                   }
  222.                   
  223.                   gad_Render(C,Gad,(APTR)Input,GREDRAW_REDRAW);
  224.                   break;
  225.                   
  226.                 default:
  227.                   gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);
  228.               }                
  229.               
  230.               i_Notify(C,Gad,(APTR)Input, 0);
  231.               
  232.               retval = GMR_MEACTIVE;
  233. //              retval = GMR_NOREUSE;
  234.             }
  235.             break;
  236.          
  237.           case SELECTDOWN:
  238.              if ( ((Input->gpi_Mouse).X < 0) ||
  239.                  ((Input->gpi_Mouse).X >= Gad->Width) ||
  240.                  ((Input->gpi_Mouse).Y < 0) ||
  241.                  ((Input->gpi_Mouse).Y >= Gad->Height) )
  242.             {// outside gadget
  243.               
  244.               if(gdata->EditMode)
  245.               {
  246.                 gdata->EditMode=0;
  247.                 gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);
  248.                 i_Notify(C,Gad,(APTR)Input, 0);
  249.               }
  250. //              retval = GMR_NOREUSE | GMR_VERIFY;
  251.               retval = GMR_REUSE;
  252.             }
  253.             else
  254.             {
  255.               gdata->MouseMode=1;
  256.               gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);
  257.               i_Notify(C,Gad,(APTR)Input, 0);
  258.               retval = GMR_MEACTIVE;
  259.             }
  260.             break;
  261.             
  262.           case MENUDOWN: /* The user hit the menu button. Go inactive and let      */
  263.                                      /* Intuition reuse the menu button event so Intuition can */
  264.                                      /* pop up the menu bar.                                   */
  265.             retval = GMR_REUSE;
  266.                                           /* Since the gadget is going inactive, send a final   */
  267.                                          /* notification to the ICA_TARGET.                    */
  268. //          NotifyPulse(Class , o, 0L, inst->midX, (struct gp_Input *)msg);
  269.             break;
  270.           default:
  271.             retval = GMR_MEACTIVE;
  272.         }
  273.       }
  274.       break;
  275.   }
  276.   
  277.   if(retval!=GMR_MEACTIVE)
  278.   {
  279.     i_Notify(C,Gad,(APTR)Input, 0);
  280.   }
  281.   
  282.   return(retval);
  283. }
  284.  
  285.  
  286. ULONG pr_Mix(ULONG A,ULONG B, float Percent)
  287. {
  288.   float a,b,diff;
  289.   
  290.   a=A;
  291.   b=B;
  292.   
  293.   diff=b-a;
  294.  
  295.   a+=diff*Percent;
  296.  
  297.   return((ULONG) (a));
  298. }
  299.  
  300.  
  301.  
  302. /*
  303.  
  304.              if ( ((Input->gpi_Mouse).X < 0) ||
  305.                  ((Input->gpi_Mouse).X >= Gad->Width) ||
  306.                  ((Input->gpi_Mouse).Y < 0) ||
  307.                  ((Input->gpi_Mouse).Y >= Gad->Height) )
  308.             {// outside gadget
  309.               
  310.               if(gdata->EditMode)
  311.               {
  312.                 gdata->EditMode=0;
  313.                 gad_Render(C,Gad,(APTR)Input,GREDRAW_UPDATE);
  314.               }
  315. //              retval = GMR_NOREUSE | GMR_VERIFY;
  316.               retval = GMR_MEACTIVE;
  317.             }
  318.             else
  319. */