35G_DEFINE_TYPE(LayerSettings, layer_settings, G_TYPE_OBJECT)
39 self->layer_infos = NULL;
56 self = GDS_RENDER_LAYER_SETTINGS(obj);
58 if (self->layer_infos) {
60 self->layer_infos = NULL;
63 G_OBJECT_CLASS(layer_settings_parent_class)->dispose(obj);
70 oclass = G_OBJECT_CLASS(klass);
115 g_return_val_if_fail(GDS_RENDER_IS_LAYER_SETTINGS(settings), -1);
123 settings->layer_infos = g_list_append(settings->layer_infos, info_copy);
125 return (settings->layer_infos ? 0 : -3);
130 g_return_if_fail(GDS_RENDER_IS_LAYER_SETTINGS(settings));
134 settings->layer_infos = NULL;
143 g_return_val_if_fail(GDS_RENDER_IS_LAYER_SETTINGS(settings), -1);
146 for (list_iter = settings->layer_infos; list_iter; list_iter = list_iter->next) {
159 settings->layer_infos = g_list_delete_link(settings->layer_infos, found);
168 g_return_val_if_fail(GDS_RENDER_IS_LAYER_SETTINGS(settings), NULL);
169 return settings->layer_infos;
181 g_string_printf(
string,
"%d:%lf:%lf:%lf:%lf:%d:%s\n",
185 for (i = 0;
string->str[i]; i++) {
186 if (string->str[i] ==
',')
187 string->str[i] =
'.';
190 for (i = 0;
string->str[i]; i++) {
191 if (string->str[i] ==
':')
192 string->str[i] =
',';
199 GOutputStream *w_fstream;
205 file = g_file_new_for_path(path);
206 w_fstream = G_OUTPUT_STREAM(g_file_replace(file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL));
215 string = g_string_new_len(NULL, 200);
222 for (info_iter = settings->layer_infos; info_iter; info_iter = info_iter->next) {
226 g_output_stream_write(w_fstream, string->str, string->len *
sizeof(gchar), NULL, NULL);
230 g_string_free(
string, TRUE);
232 g_output_stream_flush(w_fstream, NULL, NULL);
233 g_output_stream_close(w_fstream, NULL, NULL);
234 g_object_unref(w_fstream);
236 g_object_unref(file);
261 regex = g_regex_new(
"^(?<layer>[0-9]+),(?<r>[0-9\\.]+),(?<g>[0-9\\.]+),(?<b>[0-9\\.]+),(?<a>[0-9\\.]+),(?<export>[01]),(?<name>.*)$", 0, 0, NULL);
263 line = g_data_input_stream_read_line(stream, &len, NULL, NULL);
270 g_regex_match(regex, line, 0, &mi);
271 if (g_match_info_matches(mi)) {
273 match = g_match_info_fetch_named(mi,
"layer");
274 linfo->
layer = (int)g_ascii_strtoll(match, NULL, 10);
276 match = g_match_info_fetch_named(mi,
"r");
277 linfo->
color.red = g_ascii_strtod(match, NULL);
279 match = g_match_info_fetch_named(mi,
"g");
280 linfo->
color.green = g_ascii_strtod(match, NULL);
282 match = g_match_info_fetch_named(mi,
"b");
283 linfo->
color.blue = g_ascii_strtod(match, NULL);
285 match = g_match_info_fetch_named(mi,
"a");
286 linfo->
color.alpha = g_ascii_strtod(match, NULL);
288 match = g_match_info_fetch_named(mi,
"export");
289 linfo->
render = ((!strcmp(match,
"1")) ? 1 : 0);
291 match = g_match_info_fetch_named(mi,
"name");
297 printf(
"Could not recognize line in CSV as valid entry: %s\n", line);
301 g_match_info_free(mi);
304 g_regex_unref(regex);
314 GInputStream *in_stream;
315 GDataInputStream *data_stream;
320 file = g_file_new_for_path(path);
321 in_stream = G_INPUT_STREAM(g_file_read(file, NULL, NULL));
323 g_return_val_if_fail(GDS_RENDER_IS_LAYER_SETTINGS(settings), -2);
327 goto ret_destroy_file;
332 data_stream = g_data_input_stream_new(in_stream);
348 g_object_unref(data_stream);
349 g_object_unref(in_stream);
351 g_object_unref(file);
void layer_settings_clear(LayerSettings *settings)
Clear all layers in this settings object.
int layer_settings_to_csv(LayerSettings *settings, const char *path)
Write layer settings to a CSV file.
static struct layer_info * layer_info_copy(const struct layer_info *const info)
Copy layer_info struct.
LayerSettings * layer_settings_new()
New LayerSettings object.
static void layer_settings_class_init(LayerSettingsClass *klass)
static int layer_settings_load_csv_line_from_stream(GDataInputStream *stream, struct layer_info *linfo)
Load a line from stream and parse try to parse it as layer information.
GList * layer_settings_get_layer_info_list(LayerSettings *settings)
Get a GList with layer_info structs.
int layer_settings_load_from_csv(LayerSettings *settings, const char *path)
Load new layer Settings from CSV.
static void layer_settings_gen_csv_line(GString *string, struct layer_info *linfo)
Generate a layer mapping CSV line for a given layer_info struct.
int layer_settings_remove_layer(LayerSettings *settings, int layer)
Remove a specific layer number from the layer settings.
static void layer_settings_init(LayerSettings *self)
static void layer_info_delete_with_name(struct layer_info *const info)
int layer_settings_append_layer_info(LayerSettings *settings, struct layer_info *info)
layer_settings_append_layer_info
static void layer_settings_dispose(GObject *obj)
LayerSettings class header file.
#define GDS_RENDER_TYPE_LAYER_SETTINGS
int render
true: Render to output
int stacked_position
Position of layer in output.
GdkRGBA color
RGBA color used to render this layer.