Subversion Repositories filter_foundry

Rev

Rev 259 | Rev 363 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
259 daniel-mar 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
 
339 daniel-mar 85
        CHECKDLGBUTTON(dp, PROTECTITEM, 0); // TODO: should we remember the last setting?
86
 
259 daniel-mar 87
        SELECTDLGITEMTEXT(dp,TITLEITEM,0,-1);
88
}
89
 
90
 
91
/* process an item hit. return false if the dialog is finished; otherwise return true. */
92
 
93
Boolean builddlgitem(DIALOGREF dp,int item){
94
        enum{MAXFIELD=0x100};
95
        char s[MAXFIELD+1];
96
        int i,needui;
97
 
98
        switch(item){
99
        case IDOK:
100
                // Do a few checks first
101
                GetDlgItemText(dp, CATEGORYITEM, s, MAXFIELD);
102
                if (strlen(s) == 0) {
103
                        simplealert(_strdup("Category must not be empty!"));
104
                        return false;
105
                }
106
                GetDlgItemText(dp, TITLEITEM, s, MAXFIELD);
107
                if (strlen(s) == 0) {
108
                        simplealert(_strdup("Title must not be empty!"));
109
                        return false;
110
                }
111
 
112
                // Now begin
113
                memset(&gdata->parm,0,sizeof(PARM_T));
114
                GetDlgItemText(dp,CATEGORYITEM,s,MAXFIELD);             myc2pstrcpy(gdata->parm.category,s);
115
                GetDlgItemText(dp,TITLEITEM,s,MAXFIELD);                myc2pstrcpy(gdata->parm.title,s);
116
                GetDlgItemText(dp,COPYRIGHTITEM,s,MAXFIELD);    myc2pstrcpy(gdata->parm.copyright,s);
117
                GetDlgItemText(dp,AUTHORITEM,s,MAXFIELD);               myc2pstrcpy(gdata->parm.author,s);
118
                gdata->parm.cbSize = PARM_SIZE;
119
                gdata->parm.standalone = 1;  //0=original FF, 1=standalone filter
120
                needui = 0;
121
                for(i = 0; i < 8; ++i){
122
                        gdata->parm.val[i] = slider[i];
123
                        gdata->parm.ctl_used[i] = ctls[i] || (checksliders_result & CHECKSLIDERS_CTL_AMBIGUOUS);
124
                        needui |= gdata->parm.ctl_used[i];
125
                        GetDlgItemText(dp,FIRSTCTLNAMEITEM+i,s,MAXFIELD); myc2pstrcpy(gdata->parm.ctl[i],s);
126
                }
127
                for(i = 0; i < 4; ++i){
128
                        gdata->parm.map_used[i] = maps[i] || (checksliders_result & CHECKSLIDERS_MAP_AMBIGUOUS);
129
                        needui |= gdata->parm.map_used[i];
130
                        GetDlgItemText(dp,FIRSTMAPNAMEITEM+i,s,MAXFIELD); myc2pstrcpy(gdata->parm.map[i],s);
131
                        strcpy(gdata->parm.formula[i],expr[i] ? expr[i] : "bug! see builddlgitem");
132
                }
133
                gdata->parm.popDialog = needui; //true if need to pop a parameter dialog
134
                gdata->parm.unknown1 = gdata->parm.unknown2 = gdata->parm.unknown3 = 0;
135
                gdata->parm.iProtected = ISDLGBUTTONCHECKED(dp,PROTECTITEM); // == 1 means protected
136
                gdata->obfusc = ISDLGBUTTONCHECKED(dp,PROTECTITEM);
137
                /* ... falls through ... */
138
        case IDCANCEL:
139
                return false; // end dialog
140
        case PROTECTITEM:
141
                CHECKDLGBUTTON(dp, item, ISDLGBUTTONCHECKED(dp,item) ^ 1);
142
                break;
143
        }
144
 
145
        return true; // keep going
146
}