Subversion Repositories filter_foundry

Rev

Rev 185 | Rev 194 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 185 Rev 192
1
/*
1
/*
2
    This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
2
    This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
3
    Copyright (C) 2003-2019 Toby Thain, toby@telegraphics.com.au
3
    Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au
-
 
4
    Copyright (C) 2018-2019 Daniel Marschall, ViaThinkSoft
4
 
5
 
5
    This program is free software; you can redistribute it and/or modify
6
    This program is free software; you can redistribute it and/or modify
6
    it under the terms of the GNU General Public License as published by
7
    it under the terms of the GNU General Public License as published by
7
    the Free Software Foundation; either version 2 of the License, or
8
    the Free Software Foundation; either version 2 of the License, or
8
    (at your option) any later version.
9
    (at your option) any later version.
9
 
10
 
10
    This program is distributed in the hope that it will be useful,
11
    This program is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    GNU General Public License for more details.
14
    GNU General Public License for more details.
14
 
15
 
15
    You should have received a copy of the GNU General Public License
16
    You should have received a copy of the GNU General Public License
16
    along with this program; if not, write to the Free Software
17
    along with this program; if not, write to the Free Software
17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
*/
19
*/
19
 
20
 
20
/* This is PLATFORM INDEPENDENT user interface code - mainly dialog logic */
21
/* This is PLATFORM INDEPENDENT user interface code - mainly dialog logic */
21
 
22
 
22
#include "ff.h"
23
#include "ff.h"
23
 
24
 
24
#include "node.h"
25
#include "node.h"
25
#include "funcs.h"
26
#include "funcs.h"
26
#include "y.tab.h"
27
#include "y.tab.h"
27
#include "choosefile.h"
28
#include "choosefile.h"
28
#include "sprintf_tiny.h"
29
#include "sprintf_tiny.h"
29
#include "compat_string.h"
30
#include "compat_string.h"
30
 
31
 
31
#ifdef MAC_ENV
32
#ifdef MAC_ENV
32
        #include <plstringfuncs.h>
33
        #include <plstringfuncs.h>
33
#endif
34
#endif
34
 
35
 
35
Boolean doupdates = true;
36
Boolean doupdates = true;
36
 
37
 
37
void updateglobals(DIALOGREF dp);
38
void updateglobals(DIALOGREF dp);
38
struct node *updateexpr(DIALOGREF dp,int i);
39
struct node *updateexpr(DIALOGREF dp,int i);
39
void updatedialog(DIALOGREF dp);
40
void updatedialog(DIALOGREF dp);
40
void slidertextchanged(DIALOGREF dp,int item);
41
void slidertextchanged(DIALOGREF dp,int item);
41
void updatezoom(DIALOGREF dp);
42
void updatezoom(DIALOGREF dp);
42
 
43
 
43
void updatedialog(DIALOGREF dp){
44
void updatedialog(DIALOGREF dp){
44
        int i;
45
        int i;
45
 
46
 
46
        doupdates = false;
47
        doupdates = false;
47
 
48
 
48
        for(i = 0; i < 8; ++i){
49
        for(i = 0; i < 8; ++i){
49
                SETSLIDERVALUE(dp,FIRSTCTLITEM+i,slider[i]);
50
                SETSLIDERVALUE(dp,FIRSTCTLITEM+i,slider[i]);
50
                SETCTLTEXTINT(dp,FIRSTCTLTEXTITEM+i,slider[i],false);
51
                SETCTLTEXTINT(dp,FIRSTCTLTEXTITEM+i,slider[i],false);
51
        }
52
        }
52
 
53
 
53
        for(i = 0; i < 4; ++i){
54
        for(i = 0; i < 4; ++i){
54
                if(!gdata->standalone)
55
                if(!gdata->standalone)
55
                        SETCTLTEXT(dp,FIRSTEXPRITEM+i,expr[i] ? expr[i] : "");
56
                        SETCTLTEXT(dp,FIRSTEXPRITEM+i,expr[i] ? expr[i] : "");
56
                if(i < nplanes)
57
                if(i < nplanes)
57
                        updateexpr(dp,FIRSTEXPRITEM+i);
58
                        updateexpr(dp,FIRSTEXPRITEM+i);
58
        }
59
        }
59
 
60
 
60
        if(!gdata->standalone)
61
        if(!gdata->standalone)
61
                SELECTCTLTEXT(dp,FIRSTEXPRITEM,0,-1);
62
                SELECTCTLTEXT(dp,FIRSTEXPRITEM,0,-1);
62
 
63
 
63
        doupdates = true;
64
        doupdates = true;
64
}
65
}
65
 
66
 
66
/* copy dialog settings to global variables (sliders, expressions) */
67
/* copy dialog settings to global variables (sliders, expressions) */
67
 
68
 
68
void updateglobals(DIALOGREF dp){
69
void updateglobals(DIALOGREF dp){
69
        int i;
70
        int i;
70
        char s[MAXEXPR+1];
71
        char s[MAXEXPR+1];
71
 
72
 
72
        for(i = 0; i < 8; ++i)
73
        for(i = 0; i < 8; ++i)
73
                slider[i] = (value_type)(GETSLIDERVALUE(dp,FIRSTCTLITEM+i));
74
                slider[i] = (value_type)(GETSLIDERVALUE(dp,FIRSTCTLITEM+i));
74
 
75
 
75
        if(!gdata->standalone)
76
        if(!gdata->standalone)
76
                for(i = 0; i < 4; ++i){
77
                for(i = 0; i < 4; ++i){
77
                        /* stash expression strings */
78
                        /* stash expression strings */
78
                        if(GETCTLTEXT(dp,FIRSTEXPRITEM+i,s,MAXEXPR)){
79
                        if(GETCTLTEXT(dp,FIRSTEXPRITEM+i,s,MAXEXPR)){
79
                                if(expr[i])
80
                                if(expr[i])
80
                                        free(expr[i]);
81
                                        free(expr[i]);
81
                                expr[i] = my_strdup(s);
82
                                expr[i] = my_strdup(s);
82
                        }
83
                        }
83
                        if(!expr[i])
84
                        if(!expr[i])
84
                                expr[i] = my_strdup("c");
85
                                expr[i] = my_strdup("c");
85
                }
86
                }
86
}
87
}
87
 
88
 
88
struct node *updateexpr(DIALOGREF dp,int item){
89
struct node *updateexpr(DIALOGREF dp,int item){
89
        char s[MAXEXPR+1];
90
        char s[MAXEXPR+1];
90
        int i;
91
        int i;
91
 
92
 
92
        i = item - FIRSTEXPRITEM;
93
        i = item - FIRSTEXPRITEM;
93
 
94
 
94
        freetree(tree[i]);
95
        freetree(tree[i]);
95
 
96
 
96
        if(!gdata->standalone){
97
        if(!gdata->standalone){
97
                GETCTLTEXT(dp,item,s,MAXEXPR);
98
                GETCTLTEXT(dp,item,s,MAXEXPR);
98
 
99
 
99
                if(expr[i])
100
                if(expr[i])
100
                        free(expr[i]);
101
                        free(expr[i]);
101
                expr[i] = my_strdup(s);
102
                expr[i] = my_strdup(s);
102
        }
103
        }
103
 
104
 
104
        tree[i] = parseexpr(expr[i]);
105
        tree[i] = parseexpr(expr[i]);
105
 
106
 
106
        if(!gdata->standalone){
107
        if(!gdata->standalone){
107
                if(tree[i])
108
                if(tree[i])
108
                        HideDialogItem(dp,FIRSTICONITEM+i);
109
                        HideDialogItem(dp,FIRSTICONITEM+i);
109
                else{
110
                else{
110
                        err[i] = errstr;
111
                        err[i] = errstr;
111
                        errstart[i] = tokstart;
112
                        errstart[i] = tokstart;
112
                        errpos[i] = tokpos;
113
                        errpos[i] = tokpos;
113
                        ShowDialogItem(dp,FIRSTICONITEM+i);
114
                        ShowDialogItem(dp,FIRSTICONITEM+i);
114
                }
115
                }
115
        }
116
        }
116
        return tree[i];
117
        return tree[i];
117
}
118
}
118
 
119
 
119
void updatezoom(DIALOGREF dp){
120
void updatezoom(DIALOGREF dp){
120
        char s[10];
121
        char s[10];
121
        sprintf(s, "%d%%", (int)(100./zoomfactor));
122
        sprintf(s, "%d%%", (int)(100./zoomfactor));
122
        SETCTLTEXT(dp,ZOOMLEVELITEM,s);
123
        SETCTLTEXT(dp,ZOOMLEVELITEM,s);
123
        if(zoomfactor > 1.)
124
        if(zoomfactor > 1.)
124
                ShowDialogItem(dp,ZOOMINITEM);
125
                ShowDialogItem(dp,ZOOMINITEM);
125
        else
126
        else
126
                HideDialogItem(dp,ZOOMINITEM);
127
                HideDialogItem(dp,ZOOMINITEM);
127
        if(zoomfactor < fitzoom)
128
        if(zoomfactor < fitzoom)
128
                ShowDialogItem(dp,ZOOMOUTITEM);
129
                ShowDialogItem(dp,ZOOMOUTITEM);
129
        else
130
        else
130
                HideDialogItem(dp,ZOOMOUTITEM);
131
                HideDialogItem(dp,ZOOMOUTITEM);
131
}
132
}
132
 
133
 
133
/* traverse expression tree, looking for constant references to sliders/maps */
134
/* traverse expression tree, looking for constant references to sliders/maps */
134
 
135
 
135
static int _checksl(struct node*p,int ctlflags[],int mapflags[]){
136
static int _checksl(struct node*p,int ctlflags[],int mapflags[]){
136
        int s, i, result;
137
        int s, i, result;
137
 
138
 
138
        result = 0;
139
        result = 0;
139
        if(p){
140
        if(p){
140
                if( (p->kind==TOK_FN1 && p->v.sym->fn == (pfunc_type)ff_ctl)
141
                if( (p->kind==TOK_FN1 && p->v.sym->fn == (pfunc_type)ff_ctl)
141
                 || (p->kind==TOK_FN3 && p->v.sym->fn == (pfunc_type)ff_val) ){
142
                 || (p->kind==TOK_FN3 && p->v.sym->fn == (pfunc_type)ff_val) ){
142
                        if(p->child[0]->kind == TOK_NUM){
143
                        if(p->child[0]->kind == TOK_NUM){
143
                                s = p->child[0]->v.value;
144
                                s = p->child[0]->v.value;
144
                                if(s>=0 && s<=7)
145
                                if(s>=0 && s<=7)
145
                                        ctlflags[s] = 1;
146
                                        ctlflags[s] = 1;
146
                        }else
147
                        }else
147
                                result |= CHECKSLIDERS_CTL_AMBIGUOUS; /* can't determine which ctl() */
148
                                result |= CHECKSLIDERS_CTL_AMBIGUOUS; /* can't determine which ctl() */
148
                }else if(p->kind==TOK_FN2 && p->v.sym->fn == (pfunc_type)ff_map){
149
                }else if(p->kind==TOK_FN2 && p->v.sym->fn == (pfunc_type)ff_map){
149
                        if(p->child[0]->kind == TOK_NUM){
150
                        if(p->child[0]->kind == TOK_NUM){
150
                                s = p->child[0]->v.value;
151
                                s = p->child[0]->v.value;
151
                                if(s>=0 && s<=3){
152
                                if(s>=0 && s<=3){
152
                                        mapflags[s] = 1;
153
                                        mapflags[s] = 1;
153
                                        ctlflags[s*2] = ctlflags[s*2+1] = 1;
154
                                        ctlflags[s*2] = ctlflags[s*2+1] = 1;
154
                                }
155
                                }
155
                        }else
156
                        }else
156
                                result |= CHECKSLIDERS_MAP_AMBIGUOUS; /* can't determine which map() */
157
                                result |= CHECKSLIDERS_MAP_AMBIGUOUS; /* can't determine which map() */
157
                 }
158
                 }
158
 
159
 
159
                for( i = 0 ; i < MAXCHILDREN ; ++i )
160
                for( i = 0 ; i < MAXCHILDREN ; ++i )
160
                        result |= _checksl(p->child[i],ctlflags,mapflags);
161
                        result |= _checksl(p->child[i],ctlflags,mapflags);
161
        }
162
        }
162
 
163
 
163
        return result;
164
        return result;
164
}
165
}
165
 
166
 
166
int checksliders(int exprs,int ctlflags[],int mapflags[]){
167
int checksliders(int exprs,int ctlflags[],int mapflags[]){
167
        int i, result;
168
        int i, result;
168
 
169
 
169
        result = 0;
170
        result = 0;
170
 
171
 
171
        for(i = 4; i--;)
172
        for(i = 4; i--;)
172
                mapflags[i] = 0;
173
                mapflags[i] = 0;
173
        for(i = 8; i--;)
174
        for(i = 8; i--;)
174
                ctlflags[i] = 0;
175
                ctlflags[i] = 0;
175
 
176
 
176
        for(i = 0; i < exprs; i++)
177
        for(i = 0; i < exprs; i++)
177
                result |= _checksl(tree[i],ctlflags,mapflags);
178
                result |= _checksl(tree[i],ctlflags,mapflags);
178
 
179
 
179
        return result;
180
        return result;
180
}
181
}
181
 
182
 
182
void slidermoved(DIALOGREF dp,int i){
183
void slidermoved(DIALOGREF dp,int i){
183
        int v = GETSLIDERVALUE(dp,i);
184
        int v = GETSLIDERVALUE(dp,i);
184
        i -= FIRSTCTLITEM;
185
        i -= FIRSTCTLITEM;
185
        slider[i] = v;
186
        slider[i] = v;
186
        SETCTLTEXTINT(dp,i+FIRSTCTLTEXTITEM,v,false);
187
        SETCTLTEXTINT(dp,i+FIRSTCTLTEXTITEM,v,false);
187
}
188
}
188
 
189
 
189
void slidertextchanged(DIALOGREF dp,int i){
190
void slidertextchanged(DIALOGREF dp,int i){
190
        int v = GETCTLTEXTINT(dp,i,NULL,false);
191
        int v = GETCTLTEXTINT(dp,i,NULL,false);
191
        i -= FIRSTCTLTEXTITEM;
192
        i -= FIRSTCTLTEXTITEM;
192
        SETSLIDERVALUE(dp,i+FIRSTCTLITEM,v);
193
        SETSLIDERVALUE(dp,i+FIRSTCTLITEM,v);
193
        slider[i] = v;
194
        slider[i] = v;
194
}
195
}
195
 
196
 
196
void maindlgupdate(DIALOGREF dp){
197
void maindlgupdate(DIALOGREF dp){
197
        int i,unknown,ctls[8],maps[4];
198
        int i,unknown,ctls[8],maps[4];
198
 
199
 
199
        unknown = checksliders(nplanes,ctls,maps);
200
        unknown = checksliders(nplanes,ctls,maps);
200
 
201
 
201
        for(i = 0; i < 8; i++)
202
        for(i = 0; i < 8; i++)
202
                if(unknown || ctls[i]){
203
                if(unknown || ctls[i]){
203
                        ENABLEDLGITEM(dp,FIRSTCTLITEM+i);
204
                        ENABLEDLGITEM(dp,FIRSTCTLITEM+i);
204
                        ENABLEDLGITEM(dp,FIRSTCTLLABELITEM+i);
205
                        ENABLEDLGITEM(dp,FIRSTCTLLABELITEM+i);
205
                        ShowDialogItem(dp,FIRSTCTLTEXTITEM+i); /* FIXME: this changes keyboard focus */
206
                        ShowDialogItem(dp,FIRSTCTLTEXTITEM+i); /* FIXME: this changes keyboard focus */
206
                }else{
207
                }else{
207
                        DISABLEDLGITEM(dp,FIRSTCTLITEM+i);
208
                        DISABLEDLGITEM(dp,FIRSTCTLITEM+i);
208
                        DISABLEDLGITEM(dp,FIRSTCTLLABELITEM+i);
209
                        DISABLEDLGITEM(dp,FIRSTCTLLABELITEM+i);
209
                        HideDialogItem(dp,FIRSTCTLTEXTITEM+i); /* FIXME: this changes keyboard focus */
210
                        HideDialogItem(dp,FIRSTCTLTEXTITEM+i); /* FIXME: this changes keyboard focus */
210
                }
211
                }
211
 
212
 
212
        for(i = 0; i < nplanes; i++)
213
        for(i = 0; i < nplanes; i++)
213
                if(!tree[i]){
214
                if(!tree[i]){
214
                        /* uh oh, couldn't parse one of the saved expressions...this is fatal */
215
                        /* uh oh, couldn't parse one of the saved expressions...this is fatal */
215
                        DISABLEDLGITEM(dp,IDOK);
216
                        DISABLEDLGITEM(dp,IDOK);
216
                        if(gdata->standalone){
217
                        if(gdata->standalone){
217
                                alertuser("Can't run this filter (there is a problem with the saved expressions).","");
218
                                alertuser("Can't run this filter (there is a problem with the saved expressions).","");
218
                        }else{
219
                        }else{
219
                                DISABLEDLGITEM(dp,SAVEITEM);
220
                                DISABLEDLGITEM(dp,SAVEITEM);
220
                                DISABLEDLGITEM(dp,MAKEITEM);
221
                                DISABLEDLGITEM(dp,MAKEITEM);
221
                        }
222
                        }
222
                        return;
223
                        return;
223
                }
224
                }
224
 
225
 
225
        /* we have valid expression trees in all slots...proceed! */
226
        /* we have valid expression trees in all slots...proceed! */
226
        updateglobals(dp);
227
        updateglobals(dp);
227
        if(setup(gpb))
228
        if(setup(gpb))
228
                recalc_preview(gpb,dp);
229
                recalc_preview(gpb,dp);
229
 
230
 
230
        ENABLEDLGITEM(dp,IDOK);
231
        ENABLEDLGITEM(dp,IDOK);
231
        if(!gdata->standalone){
232
        if(!gdata->standalone){
232
                ENABLEDLGITEM(dp,SAVEITEM);
233
                ENABLEDLGITEM(dp,SAVEITEM);
233
                ENABLEDLGITEM(dp,MAKEITEM);
234
                ENABLEDLGITEM(dp,MAKEITEM);
234
        }
235
        }
235
}
236
}
236
 
237
 
237
/* one-time initialisation of dialog box */
238
/* one-time initialisation of dialog box */
238
 
239
 
239
void maindlginit(DIALOGREF dp){
240
void maindlginit(DIALOGREF dp){
240
        char s[0x100];
241
        char s[0x100];
241
        int i;
242
        int i;
242
        char *channelsuffixes[] = {
243
        char *channelsuffixes[] = {
243
                "", "KA", "I", "RGBA",
244
                "", "KA", "I", "RGBA",
244
                "CMYK", "HSL", "HSB", "1234",
245
                "CMYK", "HSL", "HSB", "1234",
245
                "DA", "LabA"
246
                "DA", "LabA"
246
        };
247
        };
247
 
248
 
248
        /* hide unused expression items */
249
        /* hide unused expression items */
249
        if(gdata->standalone){
250
        if(gdata->standalone){
250
                myp2cstrcpy(s,gdata->parm.author);
251
                myp2cstrcpy(s,gdata->parm.author);
251
                SetDlgItemText(dp,PARAMAUTHORITEM,s);
252
                SetDlgItemText(dp,PARAMAUTHORITEM,s);
252
                myp2cstrcpy(s,gdata->parm.copyright);
253
                myp2cstrcpy(s,gdata->parm.copyright);
253
                SetDlgItemText(dp,PARAMCOPYITEM,s);
254
                SetDlgItemText(dp,PARAMCOPYITEM,s);
254
 
255
 
255
                // update labels for map() or ctl() sliders
256
                // update labels for map() or ctl() sliders
256
                for(i = 0; i < 8; ++i){
257
                for(i = 0; i < 8; ++i){
257
                        if(gdata->parm.map_used[i/2]){
258
                        if(gdata->parm.map_used[i/2]){
258
                                if(i&1)
259
                                if(i&1)
259
                                        HideDialogItem(dp,FIRSTCTLLABELITEM+i);
260
                                        HideDialogItem(dp,FIRSTCTLLABELITEM+i);
260
                                else{
261
                                else{
261
                                        myp2cstrcpy(s,gdata->parm.map[i/2]);
262
                                        myp2cstrcpy(s,gdata->parm.map[i/2]);
262
                                        SetDlgItemText(dp,FIRSTCTLLABELITEM+i,s);
263
                                        SetDlgItemText(dp,FIRSTCTLLABELITEM+i,s);
263
                                }
264
                                }
264
                        } else if(gdata->parm.ctl_used[i]){
265
                        } else if(gdata->parm.ctl_used[i]){
265
                                myp2cstrcpy(s,gdata->parm.ctl[i]);
266
                                myp2cstrcpy(s,gdata->parm.ctl[i]);
266
                                SetDlgItemText(dp,FIRSTCTLLABELITEM+i,s);
267
                                SetDlgItemText(dp,FIRSTCTLLABELITEM+i,s);
267
                        }else{
268
                        }else{
268
                                HideDialogItem(dp,FIRSTCTLITEM+i);
269
                                HideDialogItem(dp,FIRSTCTLITEM+i);
269
                                HideDialogItem(dp,FIRSTCTLTEXTITEM+i);
270
                                HideDialogItem(dp,FIRSTCTLTEXTITEM+i);
270
                                HideDialogItem(dp,FIRSTCTLLABELITEM+i);
271
                                HideDialogItem(dp,FIRSTCTLLABELITEM+i);
271
                        }
272
                        }
272
                }
273
                }
273
        }
274
        }
274
 
275
 
275
        strcpy(s,"X =");
276
        strcpy(s,"X =");
276
        for(i = 0; i < 4; ++i){
277
        for(i = 0; i < 4; ++i){
277
                if(i >= nplanes){
278
                if(i >= nplanes){
278
                        HideDialogItem(dp,FIRSTICONITEM+i);
279
                        HideDialogItem(dp,FIRSTICONITEM+i);
279
                        HideDialogItem(dp,FIRSTEXPRITEM+i);
280
                        HideDialogItem(dp,FIRSTEXPRITEM+i);
280
                        HideDialogItem(dp,FIRSTLABELITEM+i);
281
                        HideDialogItem(dp,FIRSTLABELITEM+i);
281
                }else{
282
                }else{
282
                        s[0] = channelsuffixes[gpb->imageMode][i];
283
                        s[0] = channelsuffixes[gpb->imageMode][i];
283
                        SetDlgItemText(dp,FIRSTLABELITEM+i,s);
284
                        SetDlgItemText(dp,FIRSTLABELITEM+i,s);
284
                }
285
                }
285
        }
286
        }
286
 
287
 
287
        if(setup_preview(gpb,nplanes)){
288
        if(setup_preview(gpb,nplanes)){
288
                // On very large images, processing a fully zoomed out preview (the initial default)
289
                // On very large images, processing a fully zoomed out preview (the initial default)
289
                // can cause out of memory errors, because Photoshop can't page in all data
290
                // can cause out of memory errors, because Photoshop can't page in all data
290
                // during advanceState. To prevent this problem, zoom in until we aren't
291
                // during advanceState. To prevent this problem, zoom in until we aren't
291
                // previewing more than say 10% of Photoshop's indicated maxSpace.
292
                // previewing more than say 10% of Photoshop's indicated maxSpace.
292
                // (e.g., on a 1GB WinXP system, PS CS2 reports 520MB maxSpace, so this will let us
293
                // (e.g., on a 1GB WinXP system, PS CS2 reports 520MB maxSpace, so this will let us
293
                // preview about 50MB of image data.)
294
                // preview about 50MB of image data.)
294
 
295
 
295
                /* Workaround: GIMP/PSPI sets maxSpace to 100 MB hardcoded, so the zoom is not adjusted correctly. */
296
                /* Workaround: GIMP/PSPI sets maxSpace to 100 MB hardcoded, so the zoom is not adjusted correctly. */
296
                int disable_zoom_memory_check;
297
                int disable_zoom_memory_check;
297
                disable_zoom_memory_check = !maxspace_available();
298
                disable_zoom_memory_check = !maxspace_available();
298
 
299
 
299
                if (!disable_zoom_memory_check) {
300
                if (!disable_zoom_memory_check) {
300
                        zoomfactor = sqrt(maxspace()/(10.*preview_w*preview_h*nplanes));
301
                        zoomfactor = sqrt(maxspace()/(10.*preview_w*preview_h*nplanes));
301
                        if(zoomfactor > fitzoom)
302
                        if(zoomfactor > fitzoom)
302
                                zoomfactor = fitzoom;
303
                                zoomfactor = fitzoom;
303
                        if(zoomfactor < 1.)
304
                        if(zoomfactor < 1.)
304
                                zoomfactor = 1.;
305
                                zoomfactor = 1.;
305
                } else {
306
                } else {
306
                        zoomfactor = fitzoom;
307
                        zoomfactor = fitzoom;
307
                }
308
                }
308
 
309
 
309
                updatezoom(dp);
310
                updatezoom(dp);
310
        }else{
311
        }else{
311
                HideDialogItem(dp,ZOOMINITEM);
312
                HideDialogItem(dp,ZOOMINITEM);
312
                HideDialogItem(dp,ZOOMOUTITEM);
313
                HideDialogItem(dp,ZOOMOUTITEM);
313
                HideDialogItem(dp,ZOOMLEVELITEM);
314
                HideDialogItem(dp,ZOOMLEVELITEM);
314
        }
315
        }
315
 
316
 
316
        updatedialog(dp);
317
        updatedialog(dp);
317
        maindlgupdate(dp);
318
        maindlgupdate(dp);
318
}
319
}
319
 
320
 
320
 
321
 
321
/* process an item hit. return false if the dialog is finished; otherwise return true. */
322
/* process an item hit. return false if the dialog is finished; otherwise return true. */
322
 
323
 
323
Boolean maindlgitem(DIALOGREF dp,int item){
324
Boolean maindlgitem(DIALOGREF dp,int item){
324
        extern int previewerr;
325
        extern int previewerr;
325
 
326
 
326
        StandardFileReply sfr;
327
        StandardFileReply sfr;
327
        NavReplyRecord reply;
328
        NavReplyRecord reply;
328
        static OSType types[] = {TEXT_FILETYPE,PS_FILTER_FILETYPE};
329
        static OSType types[] = {TEXT_FILETYPE,PS_FILTER_FILETYPE};
329
        char *reason;
330
        char *reason;
330
        Str255 fname;
331
        Str255 fname;
331
 
332
 
332
        switch(item){
333
        switch(item){
333
        case IDOK:
334
        case IDOK:
334
        case IDCANCEL:
335
        case IDCANCEL:
335
                dispose_preview();
336
                dispose_preview();
336
                return false; // end dialog
337
                return false; // end dialog
337
        case OPENITEM:
338
        case OPENITEM:
338
                if(!gdata->standalone && choosefiletypes(
339
                if(!gdata->standalone && choosefiletypes(
339
                                        #ifdef MAC_ENV
340
                                        #ifdef MAC_ENV
340
                                        (StringPtr)"\pChoose filter settings",
341
                                        (StringPtr)"\pChoose filter settings",
341
                                        #else
342
                                        #else
342
                                        (StringPtr)"Choose filter settings",
343
                                        (StringPtr)"Choose filter settings",
343
                                        #endif
344
                                        #endif
344
                                        &sfr,&reply,types,2,
345
                                        &sfr,&reply,types,2,
345
                                        "All supported files (*.afs, *.8bf, *.pff, *.prm, *.bin, *.txt)\0*.afs;*.8bf;*.pff;*.prm;*.bin;*.txt\0Filter Factory Settings (*.afs, *.txt)\0*.afs;*.txt\0Filter Factory for Windows, Standalone Filter (*.8bf)\0*.8bf\0Premiere TF/FF Settings (*.pff, *.txt)\0*.pff;*.txt\0Premiere TT/FF for Windows, Standalone Filter (*.prm)\0*.prm\0FilterFactory for MacOS, Standalone Filter (*.bin)\0*.bin\0All files (*.*)\0*.*\0\0"
346
                                        "All supported files (*.afs, *.8bf, *.pff, *.prm, *.bin, *.txt)\0*.afs;*.8bf;*.pff;*.prm;*.bin;*.txt\0Filter Factory Settings (*.afs, *.txt)\0*.afs;*.txt\0Filter Factory for Windows, Standalone Filter (*.8bf)\0*.8bf\0Premiere TF/FF Settings (*.pff, *.txt)\0*.pff;*.txt\0Premiere TT/FF for Windows, Standalone Filter (*.prm)\0*.prm\0FilterFactory for MacOS, Standalone Filter (*.bin)\0*.bin\0All files (*.*)\0*.*\0\0"
346
                                        #ifdef _WIN32
347
                                        #ifdef _WIN32
347
                                        ,gdata->hWndMainDlg
348
                                        ,gdata->hWndMainDlg
348
                                        #endif /* _WIN32 */
349
                                        #endif /* _WIN32 */
349
                                        )){
350
                                        )){
350
                        if(loadfile(&sfr,&reason)){
351
                        if(loadfile(&sfr,&reason)){
351
                                updatedialog(dp);
352
                                updatedialog(dp);
352
                                maindlgupdate(dp);
353
                                maindlgupdate(dp);
353
                        }else
354
                        }else
354
                                alertuser("Cannot load settings.",reason);
355
                                alertuser("Cannot load settings.",reason);
355
                }
356
                }
356
                break;
357
                break;
357
        case SAVEITEM:
358
        case SAVEITEM:
358
                if(!gdata->standalone && putfile(
359
                if(!gdata->standalone && putfile(
359
                                                                                #ifdef MAC_ENV
360
                                                                                #ifdef MAC_ENV
360
                                                                                (StringPtr)"\pSave filter settings",
361
                                                                                (StringPtr)"\pSave filter settings",
361
                                                                                #else
362
                                                                                #else
362
                                                                                (StringPtr)"Save filter settings",
363
                                                                                (StringPtr)"Save filter settings",
363
                                                                                #endif
364
                                                                                #endif
364
                                                                                (StringPtr)"",
365
                                                                                (StringPtr)"",
365
                                                                                TEXT_FILETYPE,SIG_SIMPLETEXT,&reply,&sfr,
366
                                                                                TEXT_FILETYPE,SIG_SIMPLETEXT,&reply,&sfr,
366
                                                                                "afs","Settings file (.afs, .txt)\0*.afs;*.txt\0\0",1
367
                                                                                "afs","Settings file (.afs, .txt)\0*.afs;*.txt\0\0",1
367
                                                                                #ifdef _WIN32
368
                                                                                #ifdef _WIN32
368
                                                                                ,gdata->hWndMainDlg
369
                                                                                ,gdata->hWndMainDlg
369
                                                                                #endif /* _WIN32 */
370
                                                                                #endif /* _WIN32 */
370
                                                                                )){
371
                                                                                )){
371
                        if(savefile(&sfr))
372
                        if(savefile(&sfr))
372
                                completesave(&reply);
373
                                completesave(&reply);
373
                }
374
                }
374
                break;
375
                break;
375
        case MAKEITEM:
376
        case MAKEITEM:
376
                if( !gdata->standalone && builddialog(gpb) ){
377
                if( !gdata->standalone && builddialog(gpb) ){
377
                        PLstrcpy(fname,gdata->parm.title);
378
                        PLstrcpy(fname,gdata->parm.title);
378
#ifdef MACMACHO
379
#ifdef MACMACHO
379
                        PLstrcat(fname,(StringPtr)"\p.plugin");
380
                        PLstrcat(fname,(StringPtr)"\p.plugin");
380
#endif
381
#endif
381
                        if( putfile(
382
                        if( putfile(
382
                                                #ifdef MAC_ENV
383
                                                #ifdef MAC_ENV
383
                                                (StringPtr)"\pMake standalone filter",
384
                                                (StringPtr)"\pMake standalone filter",
384
                                                #else
385
                                                #else
385
                                                (StringPtr)"Make standalone filter",
386
                                                (StringPtr)"Make standalone filter",
386
                                                #endif
387
                                                #endif
387
                                                fname,
388
                                                fname,
388
                                                PS_FILTER_FILETYPE,kPhotoshopSignature,&reply,&sfr,
389
                                                PS_FILTER_FILETYPE,kPhotoshopSignature,&reply,&sfr,
389
                                                "8bf","Filter plugin file (.8bf)\0*.8bf\0\0",1
390
                                                "8bf","Filter plugin file (.8bf)\0*.8bf\0\0",1
390
                                                #ifdef _WIN32
391
                                                #ifdef _WIN32
391
                                                ,gdata->hWndMainDlg
392
                                                ,gdata->hWndMainDlg
392
                                                #endif /* _WIN32 */
393
                                                #endif /* _WIN32 */
393
                                                ))
394
                                                ))
394
                                make_standalone(&sfr);
395
                                make_standalone(&sfr);
395
                }
396
                }
396
                break;
397
                break;
397
        case ZOOMINITEM:
398
        case ZOOMINITEM:
398
                zoomfactor = zoomfactor > 2. ? zoomfactor/2. : 1.;
399
                zoomfactor = zoomfactor > 2. ? zoomfactor/2. : 1.;
399
                updatezoom(dp);
400
                updatezoom(dp);
400
                previewerr = false;
401
                previewerr = false;
401
                recalc_preview(gpb,dp);
402
                recalc_preview(gpb,dp);
402
                break;
403
                break;
403
        case ZOOMOUTITEM:
404
        case ZOOMOUTITEM:
404
                zoomfactor *= 2.;
405
                zoomfactor *= 2.;
405
                if(zoomfactor > fitzoom)
406
                if(zoomfactor > fitzoom)
406
                        zoomfactor = fitzoom;
407
                        zoomfactor = fitzoom;
407
                updatezoom(dp);
408
                updatezoom(dp);
408
                previewerr = false;
409
                previewerr = false;
409
                recalc_preview(gpb,dp);
410
                recalc_preview(gpb,dp);
410
                break;
411
                break;
411
        case ZOOMLEVELITEM:
412
        case ZOOMLEVELITEM:
412
                zoomfactor = zoomfactor > 1. ? 1. : (fitzoom < 1. ? 1. : fitzoom);
413
                zoomfactor = zoomfactor > 1. ? 1. : (fitzoom < 1. ? 1. : fitzoom);
413
                updatezoom(dp);
414
                updatezoom(dp);
414
                previewerr = false;
415
                previewerr = false;
415
                recalc_preview(gpb,dp);
416
                recalc_preview(gpb,dp);
416
                break;
417
                break;
417
        case FIRSTCTLITEM:
418
        case FIRSTCTLITEM:
418
        case FIRSTCTLITEM+1:
419
        case FIRSTCTLITEM+1:
419
        case FIRSTCTLITEM+2:
420
        case FIRSTCTLITEM+2:
420
        case FIRSTCTLITEM+3:
421
        case FIRSTCTLITEM+3:
421
        case FIRSTCTLITEM+4:
422
        case FIRSTCTLITEM+4:
422
        case FIRSTCTLITEM+5:
423
        case FIRSTCTLITEM+5:
423
        case FIRSTCTLITEM+6:
424
        case FIRSTCTLITEM+6:
424
        case FIRSTCTLITEM+7:
425
        case FIRSTCTLITEM+7:
425
                slidermoved(dp,item);
426
                slidermoved(dp,item);
426
                recalc_preview(gpb,dp);
427
                recalc_preview(gpb,dp);
427
                break;
428
                break;
428
        case FIRSTCTLTEXTITEM:
429
        case FIRSTCTLTEXTITEM:
429
        case FIRSTCTLTEXTITEM+1:
430
        case FIRSTCTLTEXTITEM+1:
430
        case FIRSTCTLTEXTITEM+2:
431
        case FIRSTCTLTEXTITEM+2:
431
        case FIRSTCTLTEXTITEM+3:
432
        case FIRSTCTLTEXTITEM+3:
432
        case FIRSTCTLTEXTITEM+4:
433
        case FIRSTCTLTEXTITEM+4:
433
        case FIRSTCTLTEXTITEM+5:
434
        case FIRSTCTLTEXTITEM+5:
434
        case FIRSTCTLTEXTITEM+6:
435
        case FIRSTCTLTEXTITEM+6:
435
        case FIRSTCTLTEXTITEM+7:
436
        case FIRSTCTLTEXTITEM+7:
436
                slidertextchanged(dp,item);
437
                slidertextchanged(dp,item);
437
                recalc_preview(gpb,dp);
438
                recalc_preview(gpb,dp);
438
                break;
439
                break;
439
        case FIRSTICONITEM:
440
        case FIRSTICONITEM:
440
        case FIRSTICONITEM+1:
441
        case FIRSTICONITEM+1:
441
        case FIRSTICONITEM+2:
442
        case FIRSTICONITEM+2:
442
        case FIRSTICONITEM+3:
443
        case FIRSTICONITEM+3:
443
                item -= FIRSTICONITEM;
444
                item -= FIRSTICONITEM;
444
                alertuser(err[item],"");
445
                alertuser(err[item],"");
445
                SELECTCTLTEXT(dp,FIRSTEXPRITEM+item,errstart[item],errpos[item]);
446
                SELECTCTLTEXT(dp,FIRSTEXPRITEM+item,errstart[item],errpos[item]);
446
                break;
447
                break;
447
        case FIRSTEXPRITEM:
448
        case FIRSTEXPRITEM:
448
        case FIRSTEXPRITEM+1:
449
        case FIRSTEXPRITEM+1:
449
        case FIRSTEXPRITEM+2:
450
        case FIRSTEXPRITEM+2:
450
        case FIRSTEXPRITEM+3:
451
        case FIRSTEXPRITEM+3:
451
                if((item-FIRSTEXPRITEM) < nplanes){
452
                if((item-FIRSTEXPRITEM) < nplanes){
452
                        updateexpr(dp,item);
453
                        updateexpr(dp,item);
453
                        maindlgupdate(dp);
454
                        maindlgupdate(dp);
454
                }
455
                }
455
                break;
456
                break;
456
        }
457
        }
457
 
458
 
458
        return true; // keep going
459
        return true; // keep going
459
}
460
}
460
 
461
 
461
Boolean alertuser(char *err,char *more){
462
Boolean alertuser(char *err,char *more){
462
        char *s = malloc(strlen(err)+strlen(more)+2),*q;
463
        char *s = malloc(strlen(err)+strlen(more)+2),*q;
463
        Boolean res;
464
        Boolean res;
464
 
465
 
465
        q = cat(s,err);
466
        q = cat(s,err);
466
        *q++ = '\n';
467
        *q++ = '\n';
467
        q = cat(q,more);
468
        q = cat(q,more);
468
        *q = 0;
469
        *q = 0;
469
        res = simplealert(s);
470
        res = simplealert(s);
470
        free(s);
471
        free(s);
471
        return res;
472
        return res;
472
}
473
}
473
 
474