Example #1
0
void
EditColor()
{
    extern const char *configfile;
    int i, 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 msx, msy;
    int curcol = 0, drag = 0;
    int bxorx, bxory, bxxlen, bxylen;
    static UWORD colors[AMII_MAXCOLORS];
    static UWORD svcolors[AMII_MAXCOLORS];
    static int once = 0;
    scrn = HackScreen;

    if (!once) {
        if (WINVERS_AMIV) {
            Col_NewWindowStructure1.Width += 300;
            Col_NewWindowStructure1.Height += 20;
            Col_NewWindowStructure1.LeftEdge -= 150;
            Col_BluePen.Width += 300;
            Col_RedPen.Width += 300;
            Col_GreenPen.Width += 300;
            Col_Cancel.LeftEdge += 300;
            Col_Okay.LeftEdge += 150;
            Col_Cancel.TopEdge += 20;
            Col_Save.TopEdge += 20;
            Col_Okay.TopEdge += 20;
        }
        SetBorder(&Col_Okay);
        SetBorder(&Col_Cancel);
        SetBorder(&Col_Save);
        once = 1;
    }

    bxylen = Col_NewWindowStructure1.Height
             - (Col_BluePen.TopEdge + Col_BluePen.Height + 6);
    bxxlen = Col_BluePen.Width;
    bxorx = Col_BluePen.LeftEdge;
    bxory = Col_BluePen.TopEdge + Col_BluePen.Height + 2;

    /* Save the current colors */
    for (i = 0; i < amii_numcolors; ++i)
        svcolors[i] = colors[i] = GetRGB4(scrn->ViewPort.ColorMap, i);

    Col_NewWindowStructure1.Screen = scrn;
#ifdef INTUI_NEW_LOOK
    if (IntuitionBase->LibNode.lib_Version >= 37) {
        ((struct PropInfo *) Col_BluePen.SpecialInfo)->Flags |= PROPNEWLOOK;
        ((struct PropInfo *) Col_RedPen.SpecialInfo)->Flags |= PROPNEWLOOK;
        ((struct PropInfo *) Col_GreenPen.SpecialInfo)->Flags |= PROPNEWLOOK;
    }
#endif
    if (WINVERS_AMIV || WINVERS_AMII) {
#ifdef INTUI_NEW_LOOK
        Col_NewWindowStructure1.Extension = wintags;
        Col_NewWindowStructure1.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 *) &Col_NewWindowStructure1);

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

    PrintIText(nw->RPort, &Col_IntuiTextList1, 0, 0);

    ClearCol(nw);
    DrawCol(nw, curcol, colors);
    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 == '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 == GADREDPEN || gd->GadgetID == GADBLUEPEN
                    || gd->GadgetID == GADGREENPEN) {
                    pip = (struct PropInfo *) gd->SpecialInfo;
                    aidx = pip->HorizPot / (MAXPOT / 15);
                    if (gd->GadgetID == GADREDPEN) {
                        colors[curcol] =
                            (colors[curcol] & ~0xf00) | (aidx << 8);
                        LoadRGB4(&scrn->ViewPort, colors, amii_numcolors);
                    } else if (gd->GadgetID == GADBLUEPEN) {
                        colors[curcol] = (colors[curcol] & ~0xf) | aidx;
                        LoadRGB4(&scrn->ViewPort, colors, amii_numcolors);
                    } else if (gd->GadgetID == GADGREENPEN) {
                        colors[curcol] =
                            (colors[curcol] & ~0x0f0) | (aidx << 4);
                        LoadRGB4(&scrn->ViewPort, colors, amii_numcolors);
                    }
                    DispCol(nw, curcol, colors);
                } else if (gd->GadgetID == GADCOLOKAY) {
                    done = 1;
                    okay = 1;
                } else if (gd->GadgetID == GADCOLSAVE) {
                    FILE *fp, *nfp;
                    char buf[300], nname[300], oname[300];
                    int once = 0;

                    fp = fopen(configfile, "r");
                    if (!fp) {
                        pline("can't find NetHack.cnf");
                        break;
                    }

                    strcpy(oname, dirname((char *) configfile));
                    if (oname[strlen(oname) - 1] != ':') {
                        sprintf(nname, "%s/New_NetHack.cnf", oname);
                        strcat(oname, "/");
                        strcat(oname, "Old_NetHack.cnf");
                    } else {
                        sprintf(nname, "%sNew_NetHack.cnf", oname);
                        strcat(oname, "Old_NetHack.cnf");
                    }

                    nfp = fopen(nname, "w");
                    if (!nfp) {
                        pline("can't write to New_NetHack.cnf");
                        fclose(fp);
                        break;
                    }
                    while (fgets(buf, sizeof(buf), fp)) {
                        if (strncmp(buf, "PENS=", 5) == 0) {
                            once = 1;
                            fputs("PENS=", nfp);
                            for (i = 0; i < amii_numcolors; ++i) {
                                fprintf(nfp, "%03x", colors[i]);
                                if ((i + 1) < amii_numcolors)
                                    putc('/', nfp);
                            }
                            putc('\n', nfp);
                        } else {
                            fputs(buf, nfp);
                        }
                    }

                    /* If none in the file yet, now write it */
                    if (!once) {
                        fputs("PENS=", nfp);
                        for (i = 0; i < amii_numcolors; ++i) {
                            fprintf(nfp, "%03x", colors[i]);
                            if ((i + 1) < amii_numcolors)
                                putc(',', nfp);
                        }
                        putc('\n', nfp);
                    }
                    fclose(fp);
                    fclose(nfp);
                    unlink(oname);
                    if (filecopy((char *) configfile, oname) == 0)
                        if (filecopy(nname, (char *) configfile) == 0)
                            unlink(nname);
                    done = 1;
                    okay = 1;
                } else if (gd->GadgetID == GADCOLCANCEL) {
                    done = 1;
                    okay = 0;
                }
                break;

            case GADGETDOWN:
                drag = 1;
                dgad = gd;
                break;

            case MOUSEMOVE:
                if (!drag)
                    break;
                pip = (struct PropInfo *) dgad->SpecialInfo;
                aidx = pip->HorizPot / (MAXPOT / 15);
                if (dgad->GadgetID == GADREDPEN) {
                    colors[curcol] = (colors[curcol] & ~0xf00) | (aidx << 8);
                    LoadRGB4(&scrn->ViewPort, colors, amii_numcolors);
                } else if (dgad->GadgetID == GADBLUEPEN) {
                    colors[curcol] = (colors[curcol] & ~0xf) | aidx;
                    LoadRGB4(&scrn->ViewPort, colors, amii_numcolors);
                } else if (dgad->GadgetID == GADGREENPEN) {
                    colors[curcol] = (colors[curcol] & ~0x0f0) | (aidx << 4);
                    LoadRGB4(&scrn->ViewPort, colors, amii_numcolors);
                }
                DispCol(nw, curcol, colors);
                break;

            case MOUSEBUTTONS:
                if (code == SELECTDOWN) {
                    if (msy > bxory && msy < bxory + bxylen - 1 && msx > bxorx
                        && msx < bxorx + bxxlen - 1) {
                        curcol = (msx - bxorx) / (bxxlen / amii_numcolors);
                        if (curcol >= 0 && curcol < amii_numcolors)
                            DrawCol(nw, curcol, colors);
                    }
                }
                break;
            }
        }
    }

    if (okay) {
        for (i = 0; i < (amii_numcolors); ++i)
            sysflags.amii_curmap[i] = colors[i];
        LoadRGB4(&scrn->ViewPort, sysflags.amii_curmap, amii_numcolors);
    } else
        LoadRGB4(&scrn->ViewPort, svcolors, amii_numcolors);
    CloseWindow(nw);
}
Example #2
0
unsigned long PrP0(HWND Window,HMSG Message,long Param1,long Param2)
{
    int i,saveI,j;
    int x0,y0,x1,y1,dx,dy;
    static int LastX,LastY;
    float Midf;
    /*
    x0=MouseXToWinX(Param1>>16);
    y0=MouseYToWinY(Param1&0xffff);
    x1=MouseXToWinX(Param2>>16);
    y1=MouseYToWinY(Param2&0xffff);
    */
    x0=(Param1>>16);
    y0=(Param1&0xffff);
    x1=(Param2>>16);
    y1=(Param2&0xffff);
    switch (Message)
    {
        case MOUSELEFTDOUBLE:
                i=IsCurrentPage(x0,y0);
                if (i>0)
                  switch(i)
                  {
                    case 13:
                    case 14:
                            x0=MouseXToWinX(x0);
                            ColLead[ColLeadNum++]=SCRscaleX*x0;
                            for (i=0;i<ColLeadNum-1;i++)
                              if (fabs(ColLead[i]-ColLead[ColLeadNum-1])<10.0f)
                                {
                                    ColLeadNum--;
                                    break;
                                }
                            REFLASH;
                            break;
                    case 11:
                    case 12:
                            y0=MouseYToWinY(y0);
                            RowLead[RowLeadNum++]=SCRscaleY*y0;
                            for (i=0;i<RowLeadNum-1;i++)
                              if (fabs(RowLead[i]-RowLead[RowLeadNum-1])<10.0f)
                                {
                                    RowLeadNum--;
                                    break;
                                }
                            REFLASH;
                            break;
                    case 21:                                  //Edit  Col
                            break;
                    case 22:                                  //Edit  Row
                            break;
                  }

                break;

        case MOUSERIGHTDOUBLE:
                i=IsCurrentPage(x0,y0);
                if (i>0)
                  switch(i)
                  {
                    case 21:                                  //Edit  Row
                            for (i=CurrRow;i<RowLeadNum-1;i++) RowLead[i]=RowLead[i+1];
                            RowLeadNum--;
                            REFLASH;
                            break;
                    case 22:                                  //Edit  Col
                            for (i=CurrCol;i<ColLeadNum-1;i++) ColLead[i]=ColLead[i+1];
                            ColLeadNum--;
                            REFLASH;
                            break;
                  }
                break;
        case MOUSEMOVE:
                i=IsCurrentPage(x0,y0);
                if (i>=0)
                 switch (i)
                    {
                        case 11:
                        case 12:
                        case 13:
                        case 14:
                                MouseSetGraph(FINGERMOUSE2);
                                MouseStat=0;
                                break;
                        case 0:
                                MouseSetGraph(MOVINGMOUSE);
                                MouseStat=5;
                                break;
                        case 1:
                        case 2:
                        case 22:
                                MouseSetGraph(HRESIZEMOUSE);
                                MouseStat=i;
                                break;
                        case 3:
                        case 4:
                        case 21:
                                MouseSetGraph(VRESIZEMOUSE);
                                MouseStat=i;
                                break;
                        default:
                                MouseSetGraph(ARRAWMOUSE);
                                MouseStat=0;
                    }
                else
                {
                 MouseSetGraph(ARRAWMOUSE);
                 MouseStat=0;
                }
                
                x0=MouseXToWinX(x0);
                y0=MouseYToWinY(y0);
                if (x0>=0&&y0>=0&&x0<=mXw&&y0<=mYw)
                {
                    char ss[30];
                    sprintf(ss,"(%6.1f ,%6.1f)",SCRscaleX*x0,SCRscaleY*y0);
                    Window=WindowGetFather(Window);
                    x0=WindowGetLeft(Window);
                    y0=WindowGetTop(Window);
                    //setwritemode(COPY_PUT);
                    DisplayString(ss,x0+360,y0+5,15,1);
                    //setwritemode(COPY_PUT);
                }

                break;

        case MOUSELEFTDROP:
                switch (MouseStat)
                 {
                    case 22:
                            dx=x1-LastX;
                            DrawCol(LEADCOLOR);
                            Midf=(float)dx*SCRscaleX;
                            ColLead[CurrCol] += Midf;
                            DrawCol(LEADCOLOR);
                            LastX=x1;
                            LastY=y1;
                            break;
                    case 21:
                            dy=y1-LastY;
                            DrawRow(LEADCOLOR);
                            Midf=(float)dy*SCRscaleY;
                            RowLead[CurrRow] += Midf;
                            DrawRow(LEADCOLOR);
                            LastX=x1;
                            LastY=y1;
                            break;
                    case 1:
                            dx=x1-LastX;
                            DrawCurr(CURRCOLOR);
                            Midf=(float)dx*SCRscaleX;
                            PG.PageBlock[CurrentBlock].Xoffset += Midf;

                            if (PG.PageBlock[CurrentBlock].Rotate&1)
                            PG.PageBlock[CurrentBlock].Yscale -= Midf/PageH;
                               else
                            PG.PageBlock[CurrentBlock].Xscale -= Midf/PageW;

                            DrawCurr(CURRCOLOR);
                            SetPrintPara1();
                            SetPrintPara2();
                            LastX=x1;
                            LastY=y1;
                            break;
                    case 2:
                            dx=x1-LastX;
                            DrawCurr(CURRCOLOR);
                            Midf=(float)dx*SCRscaleX;
                            //PG.PageBlock[CurrentBlock].Xoffset += Midf;

                            if (PG.PageBlock[CurrentBlock].Rotate&1)
                            PG.PageBlock[CurrentBlock].Yscale += Midf/PageH;
                               else
                            PG.PageBlock[CurrentBlock].Xscale += Midf/PageW;

                            DrawCurr(CURRCOLOR);
                            //SetPrintPara1();
                            SetPrintPara2();
                            LastX=x1;
                            LastY=y1;
                            break;
                    case 3:
                            dy=y1-LastY;
                            DrawCurr(CURRCOLOR);
                            Midf=(float)dy*SCRscaleY;
                            PG.PageBlock[CurrentBlock].Yoffset += Midf;

                            if (PG.PageBlock[CurrentBlock].Rotate&1)
                            PG.PageBlock[CurrentBlock].Xscale -= Midf/PageW;
                               else
                            PG.PageBlock[CurrentBlock].Yscale -= Midf/PageH;

                            DrawCurr(CURRCOLOR);
                            SetPrintPara1();
                            SetPrintPara2();
                            LastX=x1;
                            LastY=y1;
                            break;
                    case 4:
                            dy=y1-LastY;
                            DrawCurr(CURRCOLOR);
                            Midf=(float)dy*SCRscaleY;
                            //PG.PageBlock[CurrentBlock].Yoffset += Midf;

                            if (PG.PageBlock[CurrentBlock].Rotate&1)
                            PG.PageBlock[CurrentBlock].Xscale += Midf/PageW;
                               else
                            PG.PageBlock[CurrentBlock].Yscale += Midf/PageH;

                            DrawCurr(CURRCOLOR);
                            //SetPrintPara1();
                            SetPrintPara2();
                            LastX=x1;
                            LastY=y1;
                            break;
                    case 5:
                            dx=x1-LastX;
                            dy=y1-LastY;
                            DrawCurr(CURRCOLOR);
                            PG.PageBlock[CurrentBlock].Xoffset += (float)dx*SCRscaleX;
                            PG.PageBlock[CurrentBlock].Yoffset += (float)dy*SCRscaleY;
                            DrawCurr(CURRCOLOR);
                            SetPrintPara1();
                            LastX=x1;
                            LastY=y1;
                            break;
                 }

                x0=MouseXToWinX(x1);
                y0=MouseYToWinY(y1);
                if (x0>=0&&y0>=0&&x0<=mXw&&y0<=mYw)
                {
                    char ss[30];
                    sprintf(ss,"(%6.1f ,%6.1f)",SCRscaleX*x0,SCRscaleY*y0);
                    Window=WindowGetFather(Window);
                    x0=WindowGetLeft(Window);
                    y0=WindowGetTop(Window);
                    //setwritemode(COPY_PUT);
                    DisplayString(ss,x0+360,y0+5,15,1);
                    //setwritemode(COPY_PUT);
                }
                break;
        case MOUSELEFTUP:
                /*
                if (MouseStat)
                {
                  MouseStat=0;
                  REFLASH;
                }
                */
                break;
        case WINDOWINIT:
                PrintCutWin[0]=Window;
                //InitPrintCut();
                break;
        case MOUSELEFTDOWN:
                
                GetPrintPara();
                SetPrintPara();

                DrawCurr(0);

                if (PG.Blocks>0)
                {
                  saveI=CurrentBlock;
                  for (i=0;i<PG.Blocks;i++)
                  {
                    if (i==saveI) continue;
                    CurrentBlock=i;
                    DrawCurr(EXISTCOLOR);
                  }

                  CurrentBlock=saveI;
                  DrawCurr(CURRCOLOR);
                }

                if (Param1==-1l&&Param2==-1l) break;     //REFLASH
                LastX=x0;
                LastY=y0;
                i=IsCurrentPage(x0,y0);
                if (i<0||i>5)
                 {
                    GetPrintPara();
                    saveI=CurrentBlock;
                    for (i=0;i<PG.Blocks;i++)
                      {
                        CurrentBlock=i;
                        j=IsCurrentPage(x0,y0);
                        if (j>=0&&j<=5)
                        {
                            MouseStat=5;
                            MouseSetGraph(MOVINGMOUSE);
                            SetPrintPara();
                            ListSetCurrent(WindowList(PrintCutWin[wPAGEADDWIN]),i);
                            MessageGo(PrintCutWin[wPAGEADDWIN],ITEMSELECT,0l,0l);
                            //REFLASH;
                            break;
                        }
                        else
                            CurrentBlock=saveI;
                      }
                 }
               break;
       default:
               return (ListBoxDefaultProcedure(Window,Message,Param1,Param2));
    }
    return TRUE;
}