Subversion Repositories filter_foundry

Rev

Rev 256 | Rev 339 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.     This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
  3.     Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au
  4.     Copyright (C) 2018-2021 Daniel Marschall, ViaThinkSoft
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19. */
  20.  
  21. /* This is PLATFORM INDEPENDENT user interface code - mainly dialog logic */
  22.  
  23. #include "ff.h"
  24.  
  25. int ctls[8],maps[4];
  26. int checksliders_result;
  27.  
  28. /* one-time initialisation of dialog box */
  29.  
  30. void builddlginit(DIALOGREF dp){
  31.         int i;
  32.         char s[0x100];
  33.  
  34.         if(gdata->parmloaded){
  35.                 SetDlgItemText(dp,CATEGORYITEM, INPLACEP2CSTR(gdata->parm.category));
  36.                 SetDlgItemText(dp,TITLEITEM,    INPLACEP2CSTR(gdata->parm.title));
  37.                 SetDlgItemText(dp,COPYRIGHTITEM,INPLACEP2CSTR(gdata->parm.copyright));
  38.                 SetDlgItemText(dp,AUTHORITEM,   INPLACEP2CSTR(gdata->parm.author));
  39.                 for(i=0;i<4;++i){
  40.                         SetDlgItemText(dp,FIRSTMAPNAMEITEM+i,INPLACEP2CSTR(gdata->parm.map[i]));
  41.                 }
  42.                 for(i=0;i<8;++i){
  43.                         SetDlgItemText(dp,FIRSTCTLNAMEITEM+i,INPLACEP2CSTR(gdata->parm.ctl[i]));
  44.                 }
  45.         }else{
  46.                 /* strictly speaking this is not needed on the Mac,
  47.                    we can set initial values statically in the rez description */
  48.                 SetDlgItemText(dp,CATEGORYITEM, "Filter Foundry");
  49.                 SetDlgItemText(dp,TITLEITEM,    "Untitled");
  50.                 SetDlgItemText(dp,COPYRIGHTITEM,""); //"Filter Foundry Copyright (C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall"
  51.                 SetDlgItemText(dp,AUTHORITEM,   "Anonymous");
  52.                 strcpy(s,"Map X");
  53.                 for(i = 0; i < 4; ++i){
  54.                         s[4] = '0'+i;
  55.                         SetDlgItemText(dp,FIRSTMAPNAMEITEM+i,s);
  56.                 }
  57.                 strcpy(s,"ctl(X)");
  58.                 for(i = 0; i < 8; ++i){
  59.                         s[4] = '0'+i;
  60.                         SetDlgItemText(dp,FIRSTCTLNAMEITEM+i,s);
  61.                 }
  62.         }
  63.  
  64.         checksliders_result = checksliders(4,ctls,maps);
  65.         for(i = 4; i--;){
  66.                 DISABLEDLGITEM(dp,FIRSTMAPCHECKITEM+i);
  67.                 if(maps[i] || (checksliders_result & CHECKSLIDERS_MAP_AMBIGUOUS))
  68.                         CHECKDLGBUTTON(dp,FIRSTMAPCHECKITEM+i,true);
  69.                 else
  70.                         HideDialogItem(dp,FIRSTMAPNAMEITEM+i);
  71.         }
  72.         for(i = 8; i--;){
  73.                 DISABLEDLGITEM(dp,FIRSTCTLCHECKITEM+i);
  74.                 if((ctls[i] || (checksliders_result & CHECKSLIDERS_CTL_AMBIGUOUS)) &&
  75.                    // When map() is activated, we don't need ctl labels,
  76.                    // since the standalone filter will only show map labels
  77.                    !maps[i/2] &&
  78.                    (!(checksliders_result & CHECKSLIDERS_MAP_AMBIGUOUS))
  79.                    )
  80.                         CHECKDLGBUTTON(dp,FIRSTCTLCHECKITEM+i,true);
  81.                 else
  82.                         HideDialogItem(dp,FIRSTCTLNAMEITEM+i);
  83.         }
  84.  
  85.         SELECTDLGITEMTEXT(dp,TITLEITEM,0,-1);
  86. }
  87.  
  88.  
  89. /* process an item hit. return false if the dialog is finished; otherwise return true. */
  90.  
  91. Boolean builddlgitem(DIALOGREF dp,int item){
  92.         enum{MAXFIELD=0x100};
  93.         char s[MAXFIELD+1];
  94.         int i,needui;
  95.  
  96.         switch(item){
  97.         case IDOK:
  98.                 // Do a few checks first
  99.                 GetDlgItemText(dp, CATEGORYITEM, s, MAXFIELD);
  100.                 if (strlen(s) == 0) {
  101.                         simplealert(_strdup("Category must not be empty!"));
  102.                         return false;
  103.                 }
  104.                 GetDlgItemText(dp, TITLEITEM, s, MAXFIELD);
  105.                 if (strlen(s) == 0) {
  106.                         simplealert(_strdup("Title must not be empty!"));
  107.                         return false;
  108.                 }
  109.  
  110.                 // Now begin
  111.                 memset(&gdata->parm,0,sizeof(PARM_T));
  112.                 GetDlgItemText(dp,CATEGORYITEM,s,MAXFIELD);             myc2pstrcpy(gdata->parm.category,s);
  113.                 GetDlgItemText(dp,TITLEITEM,s,MAXFIELD);                myc2pstrcpy(gdata->parm.title,s);
  114.                 GetDlgItemText(dp,COPYRIGHTITEM,s,MAXFIELD);    myc2pstrcpy(gdata->parm.copyright,s);
  115.                 GetDlgItemText(dp,AUTHORITEM,s,MAXFIELD);               myc2pstrcpy(gdata->parm.author,s);
  116.                 gdata->parm.cbSize = PARM_SIZE;
  117.                 gdata->parm.standalone = 1;  //0=original FF, 1=standalone filter
  118.                 needui = 0;
  119.                 for(i = 0; i < 8; ++i){
  120.                         gdata->parm.val[i] = slider[i];
  121.                         gdata->parm.ctl_used[i] = ctls[i] || (checksliders_result & CHECKSLIDERS_CTL_AMBIGUOUS);
  122.                         needui |= gdata->parm.ctl_used[i];
  123.                         GetDlgItemText(dp,FIRSTCTLNAMEITEM+i,s,MAXFIELD); myc2pstrcpy(gdata->parm.ctl[i],s);
  124.                 }
  125.                 for(i = 0; i < 4; ++i){
  126.                         gdata->parm.map_used[i] = maps[i] || (checksliders_result & CHECKSLIDERS_MAP_AMBIGUOUS);
  127.                         needui |= gdata->parm.map_used[i];
  128.                         GetDlgItemText(dp,FIRSTMAPNAMEITEM+i,s,MAXFIELD); myc2pstrcpy(gdata->parm.map[i],s);
  129.                         strcpy(gdata->parm.formula[i],expr[i] ? expr[i] : "bug! see builddlgitem");
  130.                 }
  131.                 gdata->parm.popDialog = needui; //true if need to pop a parameter dialog
  132.                 gdata->parm.unknown1 = gdata->parm.unknown2 = gdata->parm.unknown3 = 0;
  133.                 gdata->parm.iProtected = ISDLGBUTTONCHECKED(dp,PROTECTITEM); // == 1 means protected
  134.                 gdata->obfusc = ISDLGBUTTONCHECKED(dp,PROTECTITEM);
  135.                 /* ... falls through ... */
  136.         case IDCANCEL:
  137.                 return false; // end dialog
  138.         case PROTECTITEM:
  139.                 CHECKDLGBUTTON(dp, item, ISDLGBUTTONCHECKED(dp,item) ^ 1);
  140.                 break;
  141.         }
  142.  
  143.         return true; // keep going
  144. }
  145.