Subversion Repositories filter_foundry

Rev

Rev 544 | Rev 552 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 544 Rev 550
Line 1... Line 1...
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-2009 Toby Thain, toby@telegraphics.net
3
    Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.net
4
    Copyright (C) 2018-2022 Daniel Marschall, ViaThinkSoft
4
    Copyright (C) 2018-2023 Daniel Marschall, ViaThinkSoft
5
 
5
 
6
    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
7
    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
8
    the Free Software Foundation; either version 2 of the License, or
8
    the Free Software Foundation; either version 2 of the License, or
9
    (at your option) any later version.
9
    (at your option) any later version.
Line 45... Line 45...
45
        int i;
45
        int i;
46
 
46
 
47
        doupdates = false;
47
        doupdates = false;
48
 
48
 
49
        for(i = 0; i < 8; ++i){
49
        for(i = 0; i < 8; ++i){
50
                SETSLIDERVALUE(dp,FIRSTCTLITEM+i,slider[i]);
50
                SETSLIDERVALUE(dp,FIRSTCTLITEM+i, gdata->parm.val[i]);
51
                SETCTLTEXTINT(dp,FIRSTCTLTEXTITEM+i,slider[i],false);
51
                SETCTLTEXTINT(dp,FIRSTCTLTEXTITEM+i, gdata->parm.val[i],false);
52
        }
52
        }
53
 
53
 
54
        for(i = 0; i < 4; ++i){
54
        for(i = 0; i < 4; ++i){
55
                if(!gdata->standalone)
55
                if(!gdata->parm.standalone)
56
                        SETCTLTEXT(dp,FIRSTEXPRITEM+i,expr[i] ? expr[i] : "");
56
                        SETCTLTEXT(dp,FIRSTEXPRITEM+i, gdata->parm.szFormula[i]);
57
                if(i < nplanes)
57
                if(i < nplanes)
58
                        updateexpr(dp,FIRSTEXPRITEM+i);
58
                        updateexpr(dp,FIRSTEXPRITEM+i);
59
        }
59
        }
60
 
60
 
61
        if(!gdata->standalone)
61
        if(!gdata->parm.standalone)
62
                SELECTCTLTEXT(dp,FIRSTEXPRITEM,0,-1);
62
                SELECTCTLTEXT(dp,FIRSTEXPRITEM,0,-1);
63
 
63
 
64
        doupdates = true;
64
        doupdates = true;
65
}
65
}
66
 
66
 
Line 68... Line 68...
68
 
68
 
69
void updateglobals(DIALOGREF dp){
69
void updateglobals(DIALOGREF dp){
70
 
70
 
71
        UNREFERENCED_PARAMETER(dp);
71
        UNREFERENCED_PARAMETER(dp);
72
 
72
 
73
        // DM 28 Nov 2021: Removed this function. It makes no sense! The internal state is in the memory
-
 
74
        // and the dialog is only the view!
-
 
75
 
-
 
76
        /*
-
 
77
        int i;
-
 
78
        char s[MAXEXPR];
-
 
79
 
-
 
80
        for(i = 0; i < 8; ++i)
-
 
81
                slider[i] = (value_type)(GETSLIDERVALUE(dp,FIRSTCTLITEM+i));
-
 
82
 
-
 
83
        if(!gdata->standalone)
-
 
84
                for(i = 0; i < 4; ++i){
-
 
85
                        // stash expression strings
-
 
86
                        if(GETCTLTEXT(dp,FIRSTEXPRITEM+i,s,MAXEXPR)){ // cchMax: NULL is included, so MAXEXPR is correct
-
 
87
                                if(expr[i])
-
 
88
                                        free(expr[i]);
-
 
89
                                expr[i] = _strdup(s);
-
 
90
                        }
-
 
91
                        if(!expr[i])
-
 
92
                                expr[i] = _strdup("c");
-
 
93
                }
-
 
94
        */
-
 
95
}
73
}
96
 
74
 
97
struct node *updateexpr(DIALOGREF dp,int item){
75
struct node *updateexpr(DIALOGREF dp,int item){
98
        char s[MAXEXPR];
76
        char s[MAXEXPR];
99
        int i;
77
        int i;
100
 
78
 
101
        i = item - FIRSTEXPRITEM;
79
        i = item - FIRSTEXPRITEM;
102
 
80
 
103
        freetree(tree[i]);
81
        freetree(tree[i]);
104
 
82
 
105
        if(!gdata->standalone){
83
        if(!gdata->parm.standalone){
106
                GETCTLTEXT(dp,item,s,MAXEXPR); // cchMax: NULL is included, so MAXEXPR is correct
84
                GETCTLTEXT(dp,item,s,MAXEXPR); // cchMax: NULL is included, so MAXEXPR is correct
107
 
-
 
108
                if(expr[i])
-
 
109
                        free(expr[i]);
-
 
110
                expr[i] = _strdup(s);
85
                strcpy(gdata->parm.szFormula[i], s);
111
        }
86
        }
112
 
87
 
113
        tree[i] = parseexpr(expr[i]);
88
        tree[i] = parseexpr(gdata->parm.szFormula[i]);
114
 
89
 
115
        if(!gdata->standalone){
90
        if(!gdata->parm.standalone){
116
                if(tree[i])
91
                if(tree[i])
117
                        HideDialogItem(dp,FIRSTICONITEM+i);
92
                        HideDialogItem(dp,FIRSTICONITEM+i);
118
                else{
93
                else{
119
                        err[i] = errstr;
94
                        err[i] = errstr;
120
                        errstart[i] = tokstart;
95
                        errstart[i] = tokstart;
Line 170... Line 145...
170
        }
145
        }
171
 
146
 
172
        return result;
147
        return result;
173
}
148
}
174
 
149
 
175
int checksliders(int exprs,int ctlflags[],int mapflags[]){
150
int checksliders(int exprs){
176
        int i, result;
151
        int i, result;
177
 
152
 
178
        result = 0;
153
        result = 0;
179
 
154
 
180
        for(i = 4; i--;)
155
        for(i = 4; i--;)
181
                mapflags[i] = 0;
156
                gdata->parm.map_used[i] = 0;
182
        for(i = 8; i--;)
157
        for(i = 8; i--;)
183
                ctlflags[i] = 0;
158
                gdata->parm.ctl_used[i] = 0;
184
 
159
 
185
        for(i = 0; i < exprs; i++)
160
        for(i = 0; i < exprs; i++)
186
                result |= _checksl(tree[i],ctlflags,mapflags);
161
                result |= _checksl(tree[i], gdata->parm.ctl_used, gdata->parm.map_used);
187
 
162
 
188
        return result;
163
        return result;
189
}
164
}
190
 
165
 
191
void slidermoved(DIALOGREF dp,int i){
166
void slidermoved(DIALOGREF dp,int i){
192
        int v = GETSLIDERVALUE(dp,i);
167
        int v = GETSLIDERVALUE(dp,i);
193
        if (v < 0) v = 0;
168
        if (v < 0) v = 0;
194
        else if (v > 255) v = 255;
169
        else if (v > 255) v = 255;
195
        i -= FIRSTCTLITEM;
170
        i -= FIRSTCTLITEM;
196
        slider[i] = (uint8_t)v;
171
        gdata->parm.val[i] = (uint8_t)v;
197
        SETCTLTEXTINT(dp,i+FIRSTCTLTEXTITEM,v,false);
172
        SETCTLTEXTINT(dp,i+FIRSTCTLTEXTITEM,v,false);
198
}
173
}
199
 
174
 
200
void slidertextchanged(DIALOGREF dp,int i){
175
void slidertextchanged(DIALOGREF dp,int i){
201
        int v = GETCTLTEXTINT(dp,i,NULL,false);
176
        int v = GETCTLTEXTINT(dp,i,NULL,false);
202
        if (v < 0) v = 0;
177
        if (v < 0) v = 0;
203
        else if (v > 255) v = 255;
178
        else if (v > 255) v = 255;
204
        i -= FIRSTCTLTEXTITEM;
179
        i -= FIRSTCTLTEXTITEM;
205
        SETSLIDERVALUE(dp,i+FIRSTCTLITEM,v);
180
        SETSLIDERVALUE(dp,i+FIRSTCTLITEM,v);
206
        slider[i] = (uint8_t)v;
181
        gdata->parm.val[i] = (uint8_t)v;
207
}
182
}
208
 
183
 
209
void maindlgupdate(DIALOGREF dp){
184
void maindlgupdate(DIALOGREF dp){
210
        int i,unknown,ctls[8],maps[4];
185
        int i,unknown;
211
 
186
 
212
        unknown = checksliders(nplanes,ctls,maps);
187
        unknown = checksliders(nplanes);
213
 
188
 
214
        for(i = 0; i < 8; i++)
189
        for(i = 0; i < 8; i++)
215
                if(unknown || ctls[i]){
190
                if(unknown || gdata->parm.ctl_used[i]){
216
                        ENABLEDLGITEM(dp,FIRSTCTLITEM+i); // TODO: slider is still shown as disabled
191
                        ENABLEDLGITEM(dp,FIRSTCTLITEM+i); // TODO: slider is still shown as disabled
217
                        REPAINTCTL(dp, FIRSTCTLITEM+i); // required for PLUGIN.DLL sliders
192
                        REPAINTCTL(dp, FIRSTCTLITEM+i); // required for PLUGIN.DLL sliders
218
                        ENABLEDLGITEM(dp,FIRSTCTLLABELITEM+i);
193
                        ENABLEDLGITEM(dp,FIRSTCTLLABELITEM+i);
219
                        ShowDialogItem(dp,FIRSTCTLTEXTITEM+i); /* FIXME: this changes keyboard focus */
194
                        ShowDialogItem(dp,FIRSTCTLTEXTITEM+i); /* FIXME: this changes keyboard focus */
220
                }else{
195
                }else{
Line 226... Line 201...
226
 
201
 
227
        for(i = 0; i < nplanes; i++)
202
        for(i = 0; i < nplanes; i++)
228
                if(!tree[i]){
203
                if(!tree[i]){
229
                        /* uh oh, couldn't parse one of the saved expressions...this is fatal */
204
                        /* uh oh, couldn't parse one of the saved expressions...this is fatal */
230
                        DISABLEDLGITEM(dp,IDOK);
205
                        DISABLEDLGITEM(dp,IDOK);
231
                        if(gdata->standalone){
206
                        if(gdata->parm.standalone){
232
                                // TODO: But before this happens, we get filterBadParameters in filterSelectorStart, since setup() failed
207
                                // TODO: But before this happens, we get filterBadParameters in filterSelectorStart, since setup() failed
233
                                //       so, do we need this message here at all?
208
                                //       so, do we need this message here at all?
234
                                simplealert_id(MSG_SAVED_EXPR_ERR_ID);
209
                                simplealert_id(MSG_SAVED_EXPR_ERR_ID);
235
                        }else{
210
                        }else{
236
                                DISABLEDLGITEM(dp,SAVEITEM);
211
                                DISABLEDLGITEM(dp,SAVEITEM);
Line 243... Line 218...
243
        updateglobals(dp);
218
        updateglobals(dp);
244
        if(setup(gpb))
219
        if(setup(gpb))
245
                recalc_preview(gpb,dp);
220
                recalc_preview(gpb,dp);
246
 
221
 
247
        ENABLEDLGITEM(dp,IDOK);
222
        ENABLEDLGITEM(dp,IDOK);
248
        if(!gdata->standalone){
223
        if(!gdata->parm.standalone){
249
                ENABLEDLGITEM(dp,SAVEITEM);
224
                ENABLEDLGITEM(dp,SAVEITEM);
250
                ENABLEDLGITEM(dp,MAKEITEM);
225
                ENABLEDLGITEM(dp,MAKEITEM);
251
                ENABLEDLGITEM(dp,HELPITEM);
226
                ENABLEDLGITEM(dp,HELPITEM);
252
        }
227
        }
253
}
228
}
Line 262... Line 237...
262
                "CMYK", "HSL", "HSB", "1234",
237
                "CMYK", "HSL", "HSB", "1234",
263
                "DA", "LabA"
238
                "DA", "LabA"
264
        };
239
        };
265
 
240
 
266
        /* hide unused expression items */
241
        /* hide unused expression items */
267
        if(gdata->standalone){
242
        if(gdata->parm.standalone){
268
                strcpy_win_replace_ampersand(&s[0], &gdata->parm.szAuthor[0]);
243
                strcpy_win_replace_ampersand(&s[0], &gdata->parm.szAuthor[0]);
269
                SETCTLTEXT(dp,PARAMAUTHORITEM,s);
244
                SETCTLTEXT(dp,PARAMAUTHORITEM,s);
270
                strcpy_win_replace_ampersand(&s[0], &gdata->parm.szCopyright[0]);
245
                strcpy_win_replace_ampersand(&s[0], &gdata->parm.szCopyright[0]);
271
                SETCTLTEXT(dp,PARAMCOPYITEM,s);
246
                SETCTLTEXT(dp,PARAMCOPYITEM,s);
272
 
247
 
Line 419... Line 394...
419
 
394
 
420
                strcpy_advance_id(&tmp1, MSG_ALL_FILES_ID);
395
                strcpy_advance_id(&tmp1, MSG_ALL_FILES_ID);
421
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.*)")); tmp1++;
396
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.*)")); tmp1++;
422
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.*")); tmp1++;
397
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.*")); tmp1++;
423
 
398
 
424
                loadDlgRet = !gdata->standalone && choosefiletypes(
399
                loadDlgRet = !gdata->parm.standalone && choosefiletypes(
425
#ifdef MAC_ENV
400
#ifdef MAC_ENV
426
                        "\pChoose filter settings", // "\p" means "Pascal string" // TODO (Not important yet): TRANSLATE
401
                        "\pChoose filter settings", // "\p" means "Pascal string" // TODO (Not important yet): TRANSLATE
427
                        &sfr, &reply, types, 2,
402
                        &sfr, &reply, types, 2,
428
                        filters
403
                        filters
429
#else
404
#else
Line 491... Line 466...
491
 
466
 
492
                strcpy_advance_id(&tmp1, MSG_ALL_FILES_ID);
467
                strcpy_advance_id(&tmp1, MSG_ALL_FILES_ID);
493
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.*)")); tmp1++;
468
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.*)")); tmp1++;
494
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.*")); tmp1++;
469
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.*")); tmp1++;
495
 
470
 
496
                saveDlgRet = !gdata->standalone && putfile(
471
                saveDlgRet = !gdata->parm.standalone && putfile(
497
#ifdef MAC_ENV
472
#ifdef MAC_ENV
498
                        "\pSave filter settings", // "\p" means "Pascal string" // TODO (Not important yet): TRANSLATE
473
                        "\pSave filter settings", // "\p" means "Pascal string" // TODO (Not important yet): TRANSLATE
499
                        "\0",
474
                        "\0",
500
                        TEXT_FILETYPE, SIG_SIMPLETEXT, &reply, &sfr,
475
                        TEXT_FILETYPE, SIG_SIMPLETEXT, &reply, &sfr,
501
                        "afs",
476
                        "afs",
Line 548... Line 523...
548
                }
523
                }
549
 
524
 
550
                break;
525
                break;
551
        }
526
        }
552
        case MAKEITEM:
527
        case MAKEITEM:
553
                if (gdata->standalone) return true; // should not happen since the button should be grayed out
528
                if (gdata->parm.standalone) return true; // should not happen since the button should be grayed out
554
 
529
 
555
                builddialog(gpb);
530
                builddialog(gpb);
556
 
531
 
557
                break;
532
                break;
558
        case HELPITEM:
533
        case HELPITEM: