-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.c
615 lines (543 loc) · 19.8 KB
/
config.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
// mandelbrot-gtk - Multithreaded GTK Application for rendering the mandelbrot and julia-set
//
// Copyright (C) 2010-2020 Felix Neumärker
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlwriter.h>
#include <glib.h>
#include <string.h>
#include "interface.h"
#include "defs.h"
#include "libcolor/color.h"
#define XML_ROOTNODE "mandelbrot_julia_set"
#define XML_RENDERDATA "renderdata"
#define XML_ITERMAX "itermax"
#define XML_DEGREE "degree"
#define XML_TYPE "type"
#define XML_TYPE_JULIA "julia-set"
#define XML_TYPE_MANDELBROT "mandelbrot-set"
#define XML_RESTORE "reset"
#define XML_COMPLEXPLANE "complexplane"
#define XML_MIN_RE "minre"
#define XML_MAX_RE "maxre"
#define XML_MIN_IM "minim"
#define XML_MAX_IM "maxim"
#define XML_CONST_J "const_j"
#define XML_REPART_J "repart_j"
#define XML_IMPART_J "impart_j"
#define XML_SIZE "size"
#define XML_WIDTH "width"
#define XML_HEIGHT "height"
#define XML_PREFERENCE "preference"
#define XML_COLOR "color"
#define XML_COLOR_ALGO "algorithmen"
#define XML_COLOR_DIVERGENT "divergent-color"
#define XML_COLOR_CONVERGET "convergent-color"
#define XML_COLOR_FOCUS "focus-color"
#define XML_COLOR_RGBA "rgba"
#define XML_ZOOM_PROP "zoom-prop"
#define XML_ZOOM_FACTOR "zoom-factor"
#define XML_GET_J_ITERMAX "get_j-itermax"
#define XML_THREADS_COUNT "threadscount"
#define XML_DEFMCPLXPLANE "default-mandelbrot-complexplane"
#define XML_DEFCPLXPLANE "default-complexplane"
#define forall_node(node) for (; node != NULL; node = node->next)
#define BUFSIZE_NUMTOSTR 30
enum xmlsavetype { SAVE_IMAGE, SAVE_APPSETTINGS };
static char *trunc0(char *c)
{
char *it;
it = c + strlen(c) - 1;
for (;;) {
if (*it == '0') {
--it;
} else
break;
}
if (*it != ',') {
++it;
}
*it = '\0';
return c;
}
static void init_config(struct winctl *w)
{
gint i;
/* init params: */
w->it_param.degree = 2.0;
w->it_param.type = MANDELBROT_SET;
w->it_param.j[0] = 0;
w->it_param.j[1] = 0;
w->it_param.itermax = DEFITERMAX;
w->it_param.color_func_index = 0;
w->it_param.update_func = update_pixbuf;
w->it_param.threads_count = CALCTHREADS;
for (i = 0; i < 4; ++i) {
w->default_cplxplane[i] = CPLXPLANE[i];
w->default_mcplxplane[i] = MCPLXPLANE[i];
w->it_param.cplxplane[i] = MCPLXPLANE[i];
}
w->zoomfactor = ZOOMFACTOR;
w->convcol.red = 0;
w->convcol.green = 0;
w->convcol.blue = 0;
w->convcol.alpha = 1.0;
w->divcol.red = 1.0;
w->divcol.green = 1.0;
w->divcol.blue = 1.0;
w->divcol.alpha = 1.0;
w->get_j = FALSE;
w->get_jitermax = DEFITERMAX;
w->focus_color.red = 1.0;
w->focus_color.green = 1.0;
w->focus_color.blue = 1.0;
w->focus_color.alpha = 1.0;
}
static char *ascii_dtostr(double d, char *c)
{
return g_ascii_dtostr(c, BUFSIZE_NUMTOSTR, d);
}
static char *dtostr(double d, char *c)
{
g_snprintf(c, BUFSIZE_NUMTOSTR, NUMFORMAT, d);
return c;
}
static char *ltostr(long int l, char *c)
{
g_snprintf(c, BUFSIZE_NUMTOSTR, "%ld", l);
return c;
}
static void writexmlfile(const char *configfile, const struct winctl *w, enum xmlsavetype type)
{
xmlTextWriter *writer;
xmlDoc *doc;
char c[BUFSIZE_NUMTOSTR];
writer = xmlNewTextWriterDoc(&doc, 0);
if (writer == NULL) {
printf("Error creating the xml-file.\b");
return;
}
xmlTextWriterStartDocument(writer, "1.0", "UTF-8", "yes");
xmlTextWriterStartElement(writer, BAD_CAST XML_ROOTNODE);
#ifdef XML_COMMENTS
xmlTextWriterWriteComment(writer, BAD_CAST " data for rendering ");
#endif
xmlTextWriterStartElement(writer, BAD_CAST XML_RENDERDATA);
xmlTextWriterWriteAttribute(writer, BAD_CAST XML_ITERMAX, BAD_CAST ltostr(w->it_param.itermax, c));
xmlTextWriterWriteAttribute(writer, BAD_CAST XML_DEGREE, BAD_CAST ascii_dtostr(w->it_param.degree, c));
if (w->it_param.type == MANDELBROT_SET)
xmlTextWriterWriteAttribute(writer, BAD_CAST XML_TYPE, BAD_CAST XML_TYPE_MANDELBROT);
else
xmlTextWriterWriteAttribute(writer, BAD_CAST XML_TYPE, BAD_CAST XML_TYPE_JULIA);
/* <renderdata> */
/* <complexplane> */
xmlTextWriterStartElement(writer, BAD_CAST XML_COMPLEXPLANE);
xmlTextWriterWriteElement(writer, BAD_CAST XML_MIN_RE, BAD_CAST ascii_dtostr(w->it_param.cplxplane[0], c));
xmlTextWriterWriteElement(writer, BAD_CAST XML_MAX_RE, BAD_CAST ascii_dtostr(w->it_param.cplxplane[1], c));
xmlTextWriterWriteElement(writer, BAD_CAST XML_MIN_IM, BAD_CAST ascii_dtostr(w->it_param.cplxplane[2], c));
xmlTextWriterWriteElement(writer, BAD_CAST XML_MAX_IM, BAD_CAST ascii_dtostr(w->it_param.cplxplane[3], c));
/* </complexplane> */
xmlTextWriterEndElement(writer);
if (type == SAVE_APPSETTINGS || w->it_param.type == JULIA_SET) {
/* <const_j> */
xmlTextWriterStartElement(writer, BAD_CAST XML_CONST_J);
xmlTextWriterWriteElement(writer, BAD_CAST XML_REPART_J, BAD_CAST ascii_dtostr(w->it_param.j[0], c));
xmlTextWriterWriteElement(writer, BAD_CAST XML_IMPART_J, BAD_CAST ascii_dtostr(w->it_param.j[1], c));
/* </const_j> */
xmlTextWriterEndElement(writer);
}
/* </renderdata> */
xmlTextWriterEndElement(writer);
if (type == SAVE_APPSETTINGS) {
GtkAllocation win_alloc;
gtk_widget_get_allocation(w->win, &win_alloc);
#ifdef XML_COMMENTS
xmlTextWriterWriteComment(writer, BAD_CAST " windowsize ");
#endif
/* <size> */
xmlTextWriterStartElement(writer, BAD_CAST XML_SIZE);
xmlTextWriterWriteElement(writer, BAD_CAST XML_WIDTH, BAD_CAST ltostr(win_alloc.width, c));
xmlTextWriterWriteElement(writer, BAD_CAST XML_HEIGHT, BAD_CAST ltostr(win_alloc.height, c));
xmlTextWriterEndElement(writer);
/* </size> */
}
/* <preference> */
xmlTextWriterStartElement(writer, BAD_CAST XML_PREFERENCE);
/* <color> */
xmlTextWriterStartElement(writer, BAD_CAST XML_COLOR);
xmlTextWriterWriteAttribute(writer, BAD_CAST XML_COLOR_ALGO, BAD_CAST ltostr(w->it_param.color_func_index, c));
/* <convergent-color/> */
xmlTextWriterWriteElement(writer, BAD_CAST XML_COLOR_CONVERGET, BAD_CAST NULL);
xmlTextWriterWriteAttribute(writer, BAD_CAST XML_COLOR_RGBA, BAD_CAST gdk_rgba_to_string(&w->convcol));
if (type == SAVE_APPSETTINGS || w->it_param.color_func_index == getDivConv_idx()) {
/* <divergent-color/> */
xmlTextWriterWriteElement(writer, BAD_CAST XML_COLOR_DIVERGENT, BAD_CAST NULL);
xmlTextWriterWriteAttribute(writer, BAD_CAST XML_COLOR_RGBA, BAD_CAST gdk_rgba_to_string(&w->divcol));
}
if (type == SAVE_APPSETTINGS) {
/* <focus-color/> */
xmlTextWriterWriteElement(writer, BAD_CAST XML_COLOR_FOCUS, BAD_CAST NULL);
xmlTextWriterWriteAttribute(writer, BAD_CAST XML_COLOR_RGBA, BAD_CAST gdk_rgba_to_string(&w->focus_color));
}
/* </color> */
xmlTextWriterEndElement(writer);
if (type == SAVE_APPSETTINGS) {
#ifdef XML_COMMENTS
xmlTextWriterWriteComment(writer, BAD_CAST " zooming proportional ");
#endif
xmlTextWriterWriteElement(writer, BAD_CAST XML_ZOOM_PROP, BAD_CAST ltostr(w->zoomprop, c));
xmlTextWriterWriteElement(writer, BAD_CAST XML_ZOOM_FACTOR, BAD_CAST ascii_dtostr(w->zoomfactor, c));
xmlTextWriterWriteElement(writer, BAD_CAST XML_GET_J_ITERMAX, BAD_CAST ltostr(w->get_jitermax, c));
#ifdef XML_COMMENTS
xmlTextWriterWriteComment(writer, BAD_CAST " number of render threads ");
#endif
xmlTextWriterWriteElement(writer, BAD_CAST XML_THREADS_COUNT, BAD_CAST ltostr(w->it_param.threads_count, c));
#ifdef XML_COMMENTS
xmlTextWriterWriteComment(writer, BAD_CAST " default vaules for reset ");
#endif
/* <default-complexplane> */
xmlTextWriterStartElement(writer, BAD_CAST XML_DEFCPLXPLANE);
xmlTextWriterWriteElement(writer, BAD_CAST XML_MIN_RE, BAD_CAST ascii_dtostr(w->default_cplxplane[0], c));
xmlTextWriterWriteElement(writer, BAD_CAST XML_MAX_RE, BAD_CAST ascii_dtostr(w->default_cplxplane[1], c));
xmlTextWriterWriteElement(writer, BAD_CAST XML_MIN_IM, BAD_CAST ascii_dtostr(w->default_cplxplane[2], c));
xmlTextWriterWriteElement(writer, BAD_CAST XML_MAX_IM, BAD_CAST ascii_dtostr(w->default_cplxplane[3], c));
/* </default-complexplane> */
xmlTextWriterEndElement(writer);
/* <default-mandelbrot-complexplane> */
xmlTextWriterStartElement(writer, BAD_CAST XML_DEFMCPLXPLANE);
xmlTextWriterWriteElement(writer, BAD_CAST XML_MIN_RE, BAD_CAST ascii_dtostr(w->default_mcplxplane[0], c));
xmlTextWriterWriteElement(writer, BAD_CAST XML_MAX_RE, BAD_CAST ascii_dtostr(w->default_mcplxplane[1], c));
xmlTextWriterWriteElement(writer, BAD_CAST XML_MIN_IM, BAD_CAST ascii_dtostr(w->default_mcplxplane[2], c));
xmlTextWriterWriteElement(writer, BAD_CAST XML_MAX_IM, BAD_CAST ascii_dtostr(w->default_mcplxplane[3], c));
/* </default-mandelbrot-complexplane> */
xmlTextWriterEndElement(writer);
}
/* </preference> */
xmlTextWriterEndElement(writer);
/* </mandelbrot_julia_set< */
xmlTextWriterEndElement(writer);
xmlFreeTextWriter(writer);
xmlSaveFormatFile(configfile, doc, 1);
xmlFreeDoc(doc);
}
static double xmlNodeContenttod(xmlNode *node)
{
double retval;
char *c = (char *)xmlNodeGetContent(node);
if (c == NULL)
return 0.0;
retval = g_ascii_strtod(c, NULL);
free(c);
return retval;
}
static int xmlNodeContenttol(xmlNode *node)
{
int retval;
char *c = (char *)xmlNodeGetContent(node);
if (c == NULL)
return 0;
retval = strtol(c, NULL, 10);
free(c);
return retval;
}
static gboolean xmlcplxplane(xmlNode *node, double *cplxplane, enum configtype type)
{
const char *name;
char c[BUFSIZE_NUMTOSTR];
gboolean retval = FALSE;
forall_node(node) {
if (node->type != XML_ELEMENT_NODE)
continue;
name = (char *)node->name;
if (strcmp(name, XML_MIN_RE) == 0) {
if (type == LOAD_CONFIG || type == LOAD_RENDER_CONFIG)
cplxplane[0] = xmlNodeContenttod(node);
else if (type == STORE_CONFIG)
xmlNodeSetContent(node, BAD_CAST ascii_dtostr(cplxplane[0], c));
retval = TRUE;
} else if (strcmp(name, XML_MAX_RE) == 0) {
if (type == LOAD_CONFIG || type == LOAD_RENDER_CONFIG)
cplxplane[1] = xmlNodeContenttod(node);
else if (type == STORE_CONFIG)
xmlNodeSetContent(node, BAD_CAST ascii_dtostr(cplxplane[1], c));
retval = TRUE;
} else if (strcmp(name, XML_MIN_IM) == 0) {
if (type == LOAD_CONFIG || type == LOAD_RENDER_CONFIG)
cplxplane[2] = xmlNodeContenttod(node);
else if (type == STORE_CONFIG)
xmlNodeSetContent(node, BAD_CAST ascii_dtostr(cplxplane[2], c));
retval = TRUE;
} else if (strcmp(name, XML_MAX_IM) == 0) {
if (type == LOAD_CONFIG || type == LOAD_RENDER_CONFIG)
cplxplane[3] = xmlNodeContenttod(node);
else if (type == STORE_CONFIG)
xmlNodeSetContent(node, BAD_CAST ascii_dtostr(cplxplane[3], c));
retval = TRUE;
}
}
return retval;
}
static void xmlconstj(xmlNode *node, double j[2], enum configtype type)
{
const char *name;
char c[BUFSIZE_NUMTOSTR];
forall_node(node) {
if (node->type != XML_ELEMENT_NODE)
continue;
name = (char *)node->name;
if (strcmp(name, XML_REPART_J) == 0) {
if (type == LOAD_CONFIG || type == LOAD_RENDER_CONFIG)
j[0] = xmlNodeContenttod(node);
else if (type == STORE_CONFIG)
xmlNodeSetContent(node, BAD_CAST ascii_dtostr(j[0], c));
} else if (strcmp(name, XML_IMPART_J) == 0) {
if (type == LOAD_CONFIG || type == LOAD_RENDER_CONFIG)
j[1] = xmlNodeContenttod(node);
else if (type == STORE_CONFIG)
xmlNodeSetContent(node, BAD_CAST ascii_dtostr(j[1], c));
}
}
}
static gboolean xmlrenderdata(xmlNode *node, struct iterate_param *it_param, enum configtype type)
{
xmlNode *cplx_node;
char *attr, *name;
char c[BUFSIZE_NUMTOSTR];
gboolean retval = FALSE;
/* itermax: */
attr = (char *)xmlGetProp(node, BAD_CAST XML_ITERMAX);
if (attr != NULL) {
if (type == LOAD_CONFIG || type == LOAD_RENDER_CONFIG)
it_param->itermax = CLAMP(strtol(attr, NULL, 10), LOWITERMAX, HIITERMAX);
else if (type == STORE_CONFIG)
xmlSetProp(node, BAD_CAST XML_ITERMAX, BAD_CAST ltostr(it_param->itermax, c));
}
free(attr);
/* degree: */
attr = (char *)xmlGetProp(node, BAD_CAST XML_DEGREE);
if (attr != NULL) {
if (type == LOAD_CONFIG || type == LOAD_RENDER_CONFIG) {
it_param->degree = CLAMP(g_ascii_strtod(attr, NULL), LOWDEGREE, HIDEGREE);
} else if (type == STORE_CONFIG) {
xmlSetProp(node, BAD_CAST XML_DEGREE, BAD_CAST ascii_dtostr(it_param->degree, c));
}
}
free(attr);
/* type: */
attr = (char *)xmlGetProp(node, BAD_CAST XML_TYPE);
if(type == LOAD_RENDER_CONFIG)
it_param->type = MANDELBROT_SET;
if (attr != NULL) {
if ((type == LOAD_CONFIG || type == LOAD_RENDER_CONFIG) && strcmp(attr, XML_TYPE_JULIA) == 0) {
it_param->type = JULIA_SET;
} else if (type == STORE_CONFIG) {
xmlSetProp(node, BAD_CAST XML_TYPE, BAD_CAST ((it_param->type == JULIA_SET) ? XML_TYPE_JULIA : XML_TYPE_MANDELBROT));
}
}
free(attr);
cplx_node = node;
node = node->children;
/* getting data: */
forall_node(node) {
if (node->type != XML_ELEMENT_NODE)
continue;
name = (char *)node->name;
if (strcmp(name, XML_COMPLEXPLANE) == 0) {
retval = xmlcplxplane(node->children, it_param->cplxplane, type);
} else if (strcmp(name, XML_CONST_J) == 0) {
xmlconstj(node->children, it_param->j, type);
}
}
attr = (char *)xmlGetProp(cplx_node, BAD_CAST XML_RESTORE);
if (attr != NULL) {
if (type == LOAD_CONFIG && strcmp(attr, "true") == 0) {
retval = FALSE;
}
}
free(attr);
return retval;
}
static void xmlsize(xmlNode *node, GtkWidget *win, enum configtype type)
{
int win_width, win_height;
const char *name;
char c[BUFSIZE_NUMTOSTR];
GtkAllocation win_alloc;
win_width = win_height = -1;
forall_node(node) {
if (node->type != XML_ELEMENT_NODE)
continue;
name = (char *)node->name;
if (strcmp(name, XML_WIDTH) == 0) {
if (type == LOAD_CONFIG ) {
win_width = xmlNodeContenttol(node);
} else if (type == STORE_CONFIG) {
gtk_widget_get_allocation(win, &win_alloc);
xmlNodeSetContent(node, BAD_CAST ltostr(win_alloc.width, c));
}
} else if (strcmp(name, XML_HEIGHT) == 0) {
if (type == LOAD_CONFIG) {
win_height = xmlNodeContenttol(node);
} else if (type == STORE_CONFIG) {
gtk_widget_get_allocation(win, &win_alloc);
xmlNodeSetContent(node, BAD_CAST ltostr(win_alloc.height, c));
}
}
}
if (type == LOAD_CONFIG)
gtk_window_resize(GTK_WINDOW(win), win_width, win_height);
}
static void xmlsetcolor(xmlNode *node, GdkRGBA *color, enum configtype type)
{
char *attr;
attr = (char *)xmlGetProp(node, BAD_CAST XML_COLOR_RGBA);
if (attr && (type == LOAD_CONFIG || type == LOAD_RENDER_CONFIG))
gdk_rgba_parse(color, attr);
else if (type == STORE_CONFIG)
xmlSetProp(node, BAD_CAST XML_COLOR_RGBA, BAD_CAST gdk_rgba_to_string(color));
free(attr);
}
static void xmlcolor(xmlNode *node, struct winctl *w, enum configtype type)
{
char *attr;
char c[BUFSIZE_NUMTOSTR];
attr = (char *)xmlGetProp(node, BAD_CAST XML_COLOR_ALGO);
if (attr != NULL) {
if (type == LOAD_CONFIG || type == LOAD_RENDER_CONFIG)
w->it_param.color_func_index = CLAMP(strtol(attr, NULL, 10), 0, getColorFunc_count() - 1);
else if (type == STORE_CONFIG)
xmlSetProp(node, BAD_CAST XML_COLOR_ALGO, BAD_CAST ltostr(w->it_param.color_func_index, c));
}
free(attr);
node = node->children;
forall_node(node) {
if (node->type != XML_ELEMENT_NODE)
continue;
if (strcmp((char *)node->name, XML_COLOR_DIVERGENT) == 0) {
xmlsetcolor(node, &w->divcol, type);
} else if (strcmp((char *)node->name, XML_COLOR_CONVERGET) == 0) {
xmlsetcolor(node, &w->convcol, type);
} else if (strcmp((char *)node->name, XML_COLOR_FOCUS) == 0) {
xmlsetcolor(node, &w->focus_color, type);
}
}
}
static void xmlpreference(xmlNode *node, struct winctl *w, enum configtype type)
{
char c[BUFSIZE_NUMTOSTR];
for (; node != NULL; node = node->next) {
if (node->type != XML_ELEMENT_NODE)
continue;
if (strcmp((char *)node->name, XML_COLOR) == 0) {
xmlcolor(node, w, type);
} else if (strcmp((char *)node->name, XML_ZOOM_PROP) == 0) {
if (type == LOAD_CONFIG)
w->zoomprop = (xmlNodeContenttol(node) == 0) ? FALSE : TRUE;
else if (type == STORE_CONFIG)
xmlNodeSetContent(node, BAD_CAST ltostr(w->zoomprop, c));
} else if (strcmp((char *)node->name, XML_ZOOM_FACTOR) == 0) {
if (type == LOAD_CONFIG)
w->zoomfactor = CLAMP(xmlNodeContenttod(node), 0.0, 1.0);
else if (type == STORE_CONFIG)
xmlNodeSetContent(node, BAD_CAST ascii_dtostr(w->zoomfactor, c));
} else if (strcmp((char *)node->name, XML_GET_J_ITERMAX) == 0) {
if (type == LOAD_CONFIG)
w->get_jitermax = CLAMP(xmlNodeContenttol(node), LOWITERMAX, HIITERMAX);
else if (type == STORE_CONFIG)
xmlNodeSetContent(node, BAD_CAST ltostr(w->get_jitermax, c));
} else if (strcmp((char *)node->name, XML_THREADS_COUNT) == 0) {
if (type == LOAD_CONFIG)
w->it_param.threads_count = CLAMP(xmlNodeContenttol(node), 1, MAXTHREADS);
else if (type == STORE_CONFIG)
xmlNodeSetContent(node, BAD_CAST ltostr(w->it_param.threads_count, c));
} else if (strcmp((char *)node->name, XML_DEFCPLXPLANE) == 0) {
xmlcplxplane(node->children, w->default_cplxplane, type);
} else if (strcmp((char *)node->name, XML_DEFMCPLXPLANE) == 0) {
xmlcplxplane(node->children, w->default_mcplxplane, type);
}
}
}
static gboolean setxmlconfig(xmlNode *node, struct winctl *w, enum configtype type)
{
gboolean retval = FALSE;
for (; node; node = node->next) {
if (strcmp((char *)node->name, XML_RENDERDATA) == 0) {
/* renderdata: */
retval = xmlrenderdata(node, &w->it_param, type);
} else if (strcmp((char *)node->name, XML_SIZE) == 0) {
/* size: */
xmlsize(node->children, w->win, type);
} else if (strcmp((char *)node->name, XML_PREFERENCE) == 0) {
/* preference: */
xmlpreference(node->children, w, type);
}
}
return retval;
}
gboolean configure_interface(struct winctl *w, const gchar *configfile, enum configtype type)
{
xmlDoc *doc = NULL;
xmlNode *root_node;
gint i;
char c[BUFSIZE_NUMTOSTR];
gboolean retval = FALSE;
LIBXML_TEST_VERSION
if (type == LOAD_CONFIG)
init_config(w);
if (!g_file_test(configfile, G_FILE_TEST_EXISTS) && type != LOAD_RENDER_CONFIG) {
writexmlfile(configfile, w, SAVE_APPSETTINGS);
if (type == STORE_CONFIG) {
//xmlCleanupParser();
return TRUE;
}
} else {
doc = xmlReadFile(configfile, NULL, 0);
if (doc != NULL && (root_node = xmlDocGetRootElement(doc)) != NULL) {
/* setup the config-file */
retval = setxmlconfig(root_node->children, w, type);
if (type == STORE_CONFIG) {
xmlSaveFormatFile(configfile, doc, 1);
xmlFreeDoc(doc);
//xmlCleanupParser();
return TRUE;
} else {
xmlFreeDoc(doc);
//xmlCleanupParser();
}
}
}
w->it_param.colorfunc = getColorFunc(w->it_param.color_func_index);
for (i = 0; i < 4; ++i) {
dtostr(w->it_param.cplxplane[i], c);
gtk_entry_set_text(GTK_ENTRY(w->txtcplx[i]), c);
}
gtk_entry_set_text(GTK_ENTRY(w->txtitermax), ltostr(w->it_param.itermax, c));
gtk_entry_set_text(GTK_ENTRY(w->txtdegree), trunc0(dtostr(w->it_param.degree, c)));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w->chkjulia), (w->it_param.type == JULIA_SET) ? TRUE : FALSE);
gtk_entry_set_text(GTK_ENTRY(w->txtjre), dtostr(w->it_param.j[0], c));
gtk_entry_set_text(GTK_ENTRY(w->txtjim), dtostr(w->it_param.j[1], c));
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w->mcolalgo[w->it_param.color_func_index]), TRUE);
if (type == LOAD_CONFIG) {
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w->mchkzoomprop), w->zoomprop);
gtk_widget_override_color(w->drawing, GTK_STATE_NORMAL, &w->focus_color);
iterate_param_init(&w->it_param, w->it_param.threads_count);
}
return retval;
}
void save_rendersettings_xml(const gchar *filename, struct winctl *w)
{
writexmlfile(filename, w, SAVE_IMAGE);
}