1 /*$
2 Copyright (C) 2016-2020 Azel.
3
4 This file is part of AzPainterB.
5
6 AzPainterB 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 3 of the License, or
9 (at your option) any later version.
10
11 AzPainterB 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, see <http://www.gnu.org/licenses/>.
18 $*/
19
20 /************************************
21 * 保存設定ダイアログ
22 ************************************/
23
24 #include "mDef.h"
25 #include "mWidget.h"
26 #include "mDialog.h"
27 #include "mContainer.h"
28 #include "mWindow.h"
29 #include "mWidgetBuilder.h"
30 #include "mLabel.h"
31 #include "mCheckButton.h"
32 #include "mLineEdit.h"
33 #include "mComboBox.h"
34 #include "mColorButton.h"
35 #include "mTrans.h"
36
37 #include "defConfig.h"
38 #include "defFileFormat.h"
39
40 #include "trgroup.h"
41
42
43 //----------------------
44
45 typedef struct __saveopt_dlg _saveopt_dlg;
46
47 struct __saveopt_dlg
48 {
49 mWidget wg;
50 mContainerData ct;
51 mWindowData win;
52 mDialogData dlg;
53
54 mLineEdit *edit;
55 mComboBox *combo;
56 mCheckButton *check[2];
57 mColorButton *colbtt;
58
59 void (*ok_handle)(_saveopt_dlg *,ConfigSaveOption *);
60 };
61
62 //----------------------
63
64 enum
65 {
66 TRID_PNG_COMPRESS = 1,
67 TRID_TRANSPARENT,
68 TRID_ALPHA_CHANNEL,
69 TRID_PNG_HELP_ALPHA,
70 TRID_QUALITY,
71 TRID_SAMPLING_FACTOR,
72 TRID_PROGRESSIVE,
73 TRID_UNCOMPRESSED,
74
75 TRID_PSD_TYPE_TOP = 100,
76 TRID_JPEG_SAMP_TOP = 110
77 };
78
79 //----------------------
80
81 static const char *g_build_png =
82 "ct#h:sep=6;"
83 "lb:lf=m:tr=1;"
84 "le#s:id=100:range=0,9:wlen=4;"
85 "-;"
86 "ct#h:sep=6;"
87 "ck:id=101:lf=m:tr=2;"
88 "colbt#d:id=103:lf=m;"
89 "-;"
90 "ck:id=102:tr=3;"
91 "lb#B:tr=4;"
92 ;
93
94 //----------------------
95
96
97
98 //============================
99 // OK 時
100 //============================
101
102
103 /** フラグをセット */
104
_ok_setflags(_saveopt_dlg * p,ConfigSaveOption * dst,int ckno,uint32_t flag)105 static void _ok_setflags(_saveopt_dlg *p,ConfigSaveOption *dst,int ckno,uint32_t flag)
106 {
107 if(mCheckButtonIsChecked(p->check[ckno]))
108 dst->flags |= flag;
109 else
110 dst->flags &= ~flag;
111 }
112
113 /** PNG */
114
_ok_png(_saveopt_dlg * p,ConfigSaveOption * dst)115 static void _ok_png(_saveopt_dlg *p,ConfigSaveOption *dst)
116 {
117 dst->png_complevel = mLineEditGetNum(p->edit);
118 dst->tpcol = mColorButtonGetColor(p->colbtt);
119
120 if(!mCheckButtonIsChecked(p->check[0]))
121 dst->tpcol |= 1<<31;
122
123 _ok_setflags(p, dst, 1, CONFIG_SAVEOPTION_F_PNG_ALPHA_CHANNEL);
124 }
125
126 /** GIF */
127
_ok_gif(_saveopt_dlg * p,ConfigSaveOption * dst)128 static void _ok_gif(_saveopt_dlg *p,ConfigSaveOption *dst)
129 {
130 dst->tpcol = mColorButtonGetColor(p->colbtt);
131
132 if(!mCheckButtonIsChecked(p->check[0]))
133 dst->tpcol |= 1<<31;
134 }
135
136 /** JPEG */
137
_ok_jpeg(_saveopt_dlg * p,ConfigSaveOption * dst)138 static void _ok_jpeg(_saveopt_dlg *p,ConfigSaveOption *dst)
139 {
140 dst->jpeg_quality = mLineEditGetNum(p->edit);
141 dst->jpeg_sampling_factor = mComboBoxGetItemParam(p->combo, -1);
142
143 _ok_setflags(p, dst, 0, CONFIG_SAVEOPTION_F_JPEG_PROGRESSIVE);
144 }
145
146 /** PSD */
147
_ok_psd(_saveopt_dlg * p,ConfigSaveOption * dst)148 static void _ok_psd(_saveopt_dlg *p,ConfigSaveOption *dst)
149 {
150 dst->psd_type = mCheckButtonGetGroupSelIndex(p->check[0]);
151
152 _ok_setflags(p, dst, 1, CONFIG_SAVEOPTION_F_PSD_UNCOMPRESSED);
153 }
154
155
156 //============================
157 // ウィジェット作成
158 //============================
159
160
161 /** PNG */
162
_create_png(_saveopt_dlg * p)163 static void _create_png(_saveopt_dlg *p)
164 {
165 mWidgetBuilderCreateFromText(M_WIDGET(p), g_build_png);
166
167 p->edit = (mLineEdit *)mWidgetFindByID(M_WIDGET(p), 100);
168 p->check[0] = (mCheckButton *)mWidgetFindByID(M_WIDGET(p), 101);
169 p->check[1] = (mCheckButton *)mWidgetFindByID(M_WIDGET(p), 102);
170 p->colbtt = (mColorButton *)mWidgetFindByID(M_WIDGET(p), 103);
171
172 //圧縮率
173
174 mLineEditSetNum(p->edit, APP_CONF->save.png_complevel);
175
176 //透過色
177
178 if(APP_CONF->save.tpcol >= 0)
179 mCheckButtonSetState(p->check[0], 1);
180
181 mColorButtonSetColor(p->colbtt, APP_CONF->save.tpcol & 0xffffff);
182
183 //アルファチャンネル
184
185 mCheckButtonSetState(p->check[1], APP_CONF->save.flags & CONFIG_SAVEOPTION_F_PNG_ALPHA_CHANNEL);
186 }
187
188 /** GIF */
189
_create_gif(_saveopt_dlg * p)190 static void _create_gif(_saveopt_dlg *p)
191 {
192 mWidget *ct;
193
194 //透過色
195
196 ct = mContainerCreate(M_WIDGET(p), MCONTAINER_TYPE_HORZ, 0, 6, 0);
197
198 p->check[0] = mCheckButtonCreate(ct, 0, 0, MLF_MIDDLE, 0,
199 M_TR_T(TRID_TRANSPARENT), (APP_CONF->save.tpcol >= 0));
200
201 p->colbtt = mColorButtonNew(0, ct, MCOLORBUTTON_S_DIALOG);
202 p->colbtt->wg.fLayout = MLF_MIDDLE;
203
204 mColorButtonSetColor(p->colbtt, APP_CONF->save.tpcol & 0xffffff);
205 }
206
207 /** JPEG */
208
_create_jpeg(_saveopt_dlg * p)209 static void _create_jpeg(_saveopt_dlg *p)
210 {
211 mWidget *ct;
212 int i,samp[3] = {444,422,420};
213
214 ct = mContainerCreateGrid(M_WIDGET(p), 2, 6, 7, 0);
215
216 //品質
217
218 mLabelCreate(ct, 0, MLF_MIDDLE, 0, M_TR_T(TRID_QUALITY));
219
220 p->edit = mLineEditCreate(ct, 0, MLINEEDIT_S_SPIN, 0, 0);
221
222 mLineEditSetWidthByLen(p->edit, 5);
223 mLineEditSetNumStatus(p->edit, 0, 100, 0);
224 mLineEditSetNum(p->edit, APP_CONF->save.jpeg_quality);
225
226 //サンプリング比
227
228 mLabelCreate(ct, 0, MLF_MIDDLE, 0, M_TR_T(TRID_SAMPLING_FACTOR));
229
230 p->combo = mComboBoxCreate(ct, 0, 0, 0, 0);
231
232 for(i = 0; i < 3; i++)
233 mComboBoxAddItem_static(p->combo, M_TR_T(TRID_JPEG_SAMP_TOP + i), samp[i]);
234
235 mComboBoxSetWidthAuto(p->combo);
236 mComboBoxSetSel_findParam_notfind(p->combo, APP_CONF->save.jpeg_sampling_factor, 0);
237
238 //プログレッシブ
239
240 p->check[0] = mCheckButtonCreate(M_WIDGET(p), 0, 0, 0, 0, M_TR_T(TRID_PROGRESSIVE),
241 APP_CONF->save.flags & CONFIG_SAVEOPTION_F_JPEG_PROGRESSIVE);
242 }
243
244 /** PSD */
245
_create_psd(_saveopt_dlg * p)246 static void _create_psd(_saveopt_dlg *p)
247 {
248 int i;
249 mCheckButton *ck;
250
251 p->ct.sepW = 3;
252
253 for(i = 0; i < 4; i++)
254 {
255 ck = mCheckButtonCreate(M_WIDGET(p), 0, MCHECKBUTTON_S_RADIO, 0, 0,
256 M_TR_T(TRID_PSD_TYPE_TOP + i),
257 (APP_CONF->save.psd_type == i));
258
259 if(i == 0) p->check[0] = ck;
260 }
261
262 //無圧縮
263
264 p->check[1] = mCheckButtonCreate(M_WIDGET(p), 0, 0, 0, M_MAKE_DW4(0,3,0,0),
265 M_TR_T(TRID_UNCOMPRESSED), APP_CONF->save.flags & CONFIG_SAVEOPTION_F_PSD_UNCOMPRESSED);
266 }
267
268
269 //============================
270 // main
271 //============================
272
273
274 /** 作成 */
275
_dlg_create(mWindow * owner,int format)276 static _saveopt_dlg *_dlg_create(mWindow *owner,int format)
277 {
278 _saveopt_dlg *p;
279 mWidget *ct;
280
281 p = (_saveopt_dlg *)mDialogNew(sizeof(_saveopt_dlg), owner, MWINDOW_S_DIALOG_NORMAL);
282 if(!p) return NULL;
283
284 p->wg.event = mDialogEventHandle_okcancel;
285
286 //
287
288 mContainerSetPadding_one(M_CONTAINER(p), 8);
289 p->ct.sepW = 7;
290
291 M_TR_G(TRGROUP_DLG_SAVE_OPTION);
292
293 mWindowSetTitle(M_WINDOW(p), M_TR_T(0));
294
295 //ウィジェット
296
297 switch(format)
298 {
299 case FILEFORMAT_PNG:
300 _create_png(p);
301 p->ok_handle = _ok_png;
302 break;
303 case FILEFORMAT_JPEG:
304 _create_jpeg(p);
305 p->ok_handle = _ok_jpeg;
306 break;
307 case FILEFORMAT_GIF:
308 _create_gif(p);
309 p->ok_handle = _ok_gif;
310 break;
311 case FILEFORMAT_PSD:
312 _create_psd(p);
313 p->ok_handle = _ok_psd;
314 break;
315 }
316
317 //OK/cancel
318
319 ct = mContainerCreateOkCancelButton(M_WIDGET(p));
320 ct->margin.top = 10;
321
322 return p;
323 }
324
325 /** 保存設定ダイアログ */
326
SaveOptionDlg_run(mWindow * owner,int format)327 mBool SaveOptionDlg_run(mWindow *owner,int format)
328 {
329 _saveopt_dlg *p;
330 mBool ret;
331
332 p = _dlg_create(owner, format);
333 if(!p) return FALSE;
334
335 mWindowMoveResizeShow_hintSize(M_WINDOW(p));
336
337 ret = mDialogRun(M_DIALOG(p), FALSE);
338
339 if(ret)
340 (p->ok_handle)(p, &APP_CONF->save);
341
342 mWidgetDestroy(M_WIDGET(p));
343
344 return ret;
345 }
346