Esempio n. 1
0
void
EditClipping(void)
{
    int i;
    long mflags;
    static int sizes[] = { 8, 16, 20, 24, 28, 32, 36 };
    char buf[40];
    int done = 0, okay = 0;
    long code, qual, class;
    register struct Gadget *gd, *dgad;
    register struct Window *nw;
    register struct IntuiMessage *imsg;
    register struct PropInfo *pip;
    register struct Screen *scrn;
    long aidx;
    int lmxsize = mxsize, lmysize = mysize;
    int lxclipbord = xclipbord, lyclipbord = yclipbord;
    int msx, msy;
    int drag = 0;
    static int once = 0;

    scrn = HackScreen;

    if (!once) {
        SetBorder(&ClipOkay);
        SetBorder(&ClipCancel);
        once = 1;
    }
    ClipNewWindowStructure1.Screen = scrn;
#ifdef INTUI_NEW_LOOK
    if (IntuitionBase->LibNode.lib_Version >= 37) {
        ((struct PropInfo *) ClipXSIZE.SpecialInfo)->Flags |= PROPNEWLOOK;
        ((struct PropInfo *) ClipYSIZE.SpecialInfo)->Flags |= PROPNEWLOOK;
        ((struct PropInfo *) ClipXCLIP.SpecialInfo)->Flags |= PROPNEWLOOK;
        ((struct PropInfo *) ClipYCLIP.SpecialInfo)->Flags |= PROPNEWLOOK;
    }
#endif
    if (WINVERS_AMIV || WINVERS_AMII) {
#ifdef INTUI_NEW_LOOK
        ClipNewWindowStructure1.Extension = wintags;
        ClipNewWindowStructure1.Flags |= WFLG_NW_EXTENDED;
#ifdef __GNUC__
        fillhook.h_Entry = (void *) &LayerFillHook;
#else
        fillhook.h_Entry = (ULONG (*) ()) LayerFillHook;
#endif
        fillhook.h_Data = (void *) -2;
        fillhook.h_SubEntry = 0;
#endif
    }

    nw = OpenWindow((void *) &ClipNewWindowStructure1);

    if (nw == NULL) {
        DisplayBeep(NULL);
        return;
    }

    ShowClipValues(nw);
    mflags = AUTOKNOB | FREEHORIZ;
#ifdef INTUI_NEW_LOOK
    if (IntuitionBase->LibNode.lib_Version >= 37) {
        mflags |= PROPNEWLOOK;
    }
#endif

    for (i = 0; i < 7; ++i) {
        if (mxsize <= sizes[i])
            break;
    }
    NewModifyProp(&ClipXSIZE, nw, NULL, mflags, (i * MAXPOT) / 6, 0,
                  MAXPOT / 6, 0, 1);
    for (i = 0; i < 7; ++i) {
        if (mysize <= sizes[i])
            break;
    }
    NewModifyProp(&ClipYSIZE, nw, NULL, mflags, (i * MAXPOT) / 6, 0,
                  MAXPOT / 6, 0, 1);

    NewModifyProp(&ClipXCLIP, nw, NULL, mflags,
                  ((xclipbord - 2) * MAXPOT) / 6, 0, MAXPOT / 6, 0, 1);
    NewModifyProp(&ClipYCLIP, nw, NULL, mflags,
                  ((yclipbord - 2) * MAXPOT) / 6, 0, MAXPOT / 6, 0, 1);

    while (!done) {
        WaitPort(nw->UserPort);

        while (imsg = (struct IntuiMessage *) GetMsg(nw->UserPort)) {
            gd = (struct Gadget *) imsg->IAddress;
            code = imsg->Code;
            class = imsg->Class;
            qual = imsg->Qualifier;
            msx = imsg->MouseX;
            msy = imsg->MouseY;

            ReplyMsg((struct Message *) imsg);

            switch (class) {
            case VANILLAKEY:
                if (code == '\33')
                    okay = 0, done = 1;
                else if (code == 'v' && qual == AMIGALEFT)
                    okay = done = 1;
                else if (code == 'b' && qual == AMIGALEFT)
                    okay = 0, done = 1;
                else if (code == 'o' || code == 'O')
                    okay = done = 1;
                else if (code == 'c' || code == 'C')
                    okay = 0, done = 1;
                break;

            case CLOSEWINDOW:
                done = 1;
                break;

            case GADGETUP:
                drag = 0;
                if (gd->GadgetID == XSIZE || gd->GadgetID == YSIZE
                    || gd->GadgetID == XCLIP || gd->GadgetID == YCLIP) {
                    pip = (struct PropInfo *) gd->SpecialInfo;
                    aidx = pip->HorizPot / (MAXPOT / 6);
                    if (gd->GadgetID == XSIZE) {
                        mxsize = sizes[aidx];
                    } else if (gd->GadgetID == YSIZE) {
                        mysize = sizes[aidx];
                    } else if (gd->GadgetID == XCLIP) {
                        xclipbord = aidx + 2;
                    } else if (gd->GadgetID == YCLIP) {
                        yclipbord = aidx + 2;
                    }
                    ShowClipValues(nw);
#ifdef OPT_DISPMAP
                    dispmap_sanity();
#endif
                } else if (gd->GadgetID == GADOKAY) {
                    done = 1;
                    okay = 1;
                } else if (gd->GadgetID == GADCANCEL) {
                    done = 1;
                    okay = 0;
                }
                ReportMouse(0, nw);
                reclip = 2;
                doredraw();
                flush_glyph_buffer(amii_wins[WIN_MAP]->win);
                reclip = 0;
                break;

            case GADGETDOWN:
                drag = 1;
                dgad = gd;
                ReportMouse(1, nw);
                break;

            case MOUSEMOVE:
                if (!drag)
                    break;
                pip = (struct PropInfo *) dgad->SpecialInfo;
                aidx = pip->HorizPot / (MAXPOT / 6);
                Move(nw->RPort,
                     dgad->LeftEdge + (nw->Width + dgad->Width) + 8,
                     dgad->TopEdge + nw->RPort->TxBaseline);
                if (dgad->GadgetID == XSIZE) {
                    mxsize = sizes[aidx];
                    sprintf(buf, "%d ", lmxsize);
                } else if (dgad->GadgetID == YSIZE) {
                    mysize = sizes[aidx];
                    sprintf(buf, "%d ", mysize);
                } else if (dgad->GadgetID == XCLIP) {
                    xclipbord = aidx + 2;
                    sprintf(buf, "%d ", xclipbord);
                } else if (dgad->GadgetID == YCLIP) {
                    yclipbord = aidx + 2;
                    sprintf(buf, "%d ", yclipbord);
                }
                SetAPen(nw->RPort, 5);
                SetBPen(nw->RPort, amii_otherBPen);
                SetDrMd(nw->RPort, JAM2);
                Text(nw->RPort, buf, strlen(buf));
#ifdef OPT_DISPMAP
                dispmap_sanity();
#endif
                break;
            }
        }
    }

    CloseWindow(nw);

    /* Restore oldvalues if cancelled. */
    if (!okay) {
        mxsize = lmxsize;
        mysize = lmysize;
        xclipbord = lxclipbord;
        yclipbord = lyclipbord;
    }
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
   double maxp = (double)MAXPERIODK*sizeof(noisedata)/K;
   double minp = (double)MINPERIODK*sizeof(noisedata)/K;
   double octaves;

#ifdef DEBUG
   printf("maxp, minp = %f, %f\n",maxp, minp);
#endif
   atexit( mytidyup );

   IntuitionBase = OpenLibrary("intuition.library",0);

   log10of2 = log10(2.);
   octaves  = log2(maxp/minp);
#ifdef DEBUG
   printf("octaves = %f\n",octaves);
#endif
   powerbase = pow(2, octaves);

   freqbase = 1./maxp;
#ifdef DEBUG
   printf("freqbase = %f\n",freqbase);
#endif
#ifdef DEBUG
   printf("maxfreq = %f\n",(double)(1.0)/minp);
#endif

   w = (struct Window *)OpenWindow(&nw);
   printf("Wait for it!\n");
   makefreqtable(w->Width);
   printf("Ok go\n");

   start_noise();

   while(1)
   {
      struct IntuiMessage *m;
      ULONG class;
      USHORT code;
      SHORT mousex, mousey;
      int exitflag = 0;

      WaitPort(w->UserPort);
      m = (struct IntuiMessage *)GetMsg(w->UserPort);
      class = m->Class;
      code  = m->Code;
      mousex = m->MouseX;
      mousey = m->MouseY;

      ReplyMsg((struct Message *)m);

      switch( class )
      {
      case CLOSEWINDOW :
         exitflag = 1;
         break;

      case NEWSIZE:
         makefreqtable(w->Width);
         break;

      case MOUSEBUTTONS :
         switch( code )
         {
         case SELECTDOWN:
            ReportMouse(w,1);
            break;
         case SELECTUP:
            ReportMouse(w,0);
            continue;
         case MENUDOWN:
         case MENUUP:
            continue;
         }
 /* Fall through on SELECTDOWN */
      case MOUSEMOVE:
         {  double newfreq;
            int newp;

            if( mousex > w->Width ) mousex = w->Width;
            else if( mousex < 0 ) mousex = 0;
            if( mousey > w->Height ) mousey = w->Height;
            else if( mousey < 0 ) mousey = 0;

            newfreq = freqtable[mousex];
#ifdef DEBUG
            printf("newfreq = %f\n",newfreq);
#endif
            newp = (int)PERIOD(newfreq, sizeof(noisedata));
#ifdef DEBUG
            printf("newp = %d\n",newp);
#endif
            modifynoise( newp, (mousey*MAXVOLUME)/w->Height);
         }
         break;
      }
      if( exitflag ) break;
   }

   return( 0 );
}