summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-06-29 16:47:00 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-06-30 10:12:13 +0900
commit3648b0e25203a2ce269b586b4a499468fa07bbda (patch)
tree56af8dde985c0d19b881cdabfbe2f8e43816bc56 /src/bin
parenta31222ae6f11932bcfa964db0e1576d02d6d1d7c (diff)
Edje: Add proper filters section in the EDJ file
Don't [ab]use the file data section for filter scripts, instead create a proper section for them. The rest of the behaviour stays the same.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/edje/edje_cc_handlers.c157
1 files changed, 157 insertions, 0 deletions
diff --git a/src/bin/edje/edje_cc_handlers.c b/src/bin/edje/edje_cc_handlers.c
index 4c7955f45e..0c14255880 100644
--- a/src/bin/edje/edje_cc_handlers.c
+++ b/src/bin/edje/edje_cc_handlers.c
@@ -65,6 +65,7 @@
65 * <li>@ref sec_toplevel_data "Data"</li> 65 * <li>@ref sec_toplevel_data "Data"</li>
66 * <li>@ref sec_toplevel_color_classes "Color Classes"</li> 66 * <li>@ref sec_toplevel_color_classes "Color Classes"</li>
67 * <li>@ref sec_toplevel_styles "Styles"</li> 67 * <li>@ref sec_toplevel_styles "Styles"</li>
68 * <li>@ref sec_collections_group_filter "Filters"</li> <!-- dup -->
68 * </ul> 69 * </ul>
69 * <li>@ref sec_collections "Collections"</li> 70 * <li>@ref sec_collections "Collections"</li>
70 * <ul> 71 * <ul>
@@ -72,6 +73,7 @@
72 * <ul> 73 * <ul>
73 * <li>@ref sec_collections_sounds_sample "Sample"</li> 74 * <li>@ref sec_collections_sounds_sample "Sample"</li>
74 * </ul> 75 * </ul>
76 * <li>@ref sec_collections_group_filter "Filters"</li>
75 * <li>@ref sec_collections_vibrations "Vibrations"</li> 77 * <li>@ref sec_collections_vibrations "Vibrations"</li>
76 * <ul> 78 * <ul>
77 * <li>@ref sec_collections_vibrations_sample "Sample"</li> 79 * <li>@ref sec_collections_vibrations_sample "Sample"</li>
@@ -81,6 +83,7 @@
81 * <li>@ref sec_collections_group_script "Script"</li> 83 * <li>@ref sec_collections_group_script "Script"</li>
82 * <li>@ref sec_collections_group_limits "Limits"</li> 84 * <li>@ref sec_collections_group_limits "Limits"</li>
83 * <li>@ref sec_collections_group_data "Data"</li> 85 * <li>@ref sec_collections_group_data "Data"</li>
86 * <li>@ref sec_collections_group_filter "Filters"</li>
84 * <li>@ref sec_collections_group_parts "Parts"</li> 87 * <li>@ref sec_collections_group_parts "Parts"</li>
85 * <ul> 88 * <ul>
86 * <li>@ref sec_collections_group_parts_part "Part"</li> 89 * <li>@ref sec_collections_group_parts_part "Part"</li>
@@ -209,6 +212,9 @@ static void st_color_class_color2(void);
209static void st_color_class_color3(void); 212static void st_color_class_color3(void);
210static void st_color_class_desc(void); 213static void st_color_class_desc(void);
211 214
215static void st_filters_filter_inline(void);
216static void st_filters_filter_file(void);
217
212static void ob_collections(void); 218static void ob_collections(void);
213static void st_collections_base_scale(void); 219static void st_collections_base_scale(void);
214 220
@@ -617,6 +623,12 @@ static void st_collections_group_nobroadcast(void);
617 ed->type_node.orientation.type = EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_QUATERNION; \ 623 ed->type_node.orientation.type = EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_QUATERNION; \
618 } 624 }
619 625
626#define FILTERS_STATEMENTS(PREFIX) \
627 {PREFIX"filters", NULL}, \
628 {PREFIX"filters.filter", NULL}, \
629 {PREFIX"filters.filter.inline", st_filters_filter_inline}, \
630 {PREFIX"filters.filter.file", st_filters_filter_file},
631
620New_Statement_Handler statement_handlers[] = 632New_Statement_Handler statement_handlers[] =
621{ 633{
622 {"externals.external", st_externals_external}, 634 {"externals.external", st_externals_external},
@@ -624,6 +636,7 @@ New_Statement_Handler statement_handlers[] =
624 FONT_STYLE_CC_STATEMENTS("") 636 FONT_STYLE_CC_STATEMENTS("")
625 {"data.item", st_data_item}, 637 {"data.item", st_data_item},
626 {"data.file", st_data_file}, 638 {"data.file", st_data_file},
639 FILTERS_STATEMENTS("")
627 {"collections.externals.external", st_externals_external}, /* dup */ 640 {"collections.externals.external", st_externals_external}, /* dup */
628 IMAGE_STATEMENTS("collections.") 641 IMAGE_STATEMENTS("collections.")
629 IMAGE_SET_STATEMENTS("collections") 642 IMAGE_SET_STATEMENTS("collections")
@@ -643,6 +656,7 @@ New_Statement_Handler statement_handlers[] =
643 {"collections.group.sounds.tone", st_collections_group_sound_tone}, /* dup */ 656 {"collections.group.sounds.tone", st_collections_group_sound_tone}, /* dup */
644 {"collections.vibrations.sample.name", st_collections_group_vibration_sample_name}, 657 {"collections.vibrations.sample.name", st_collections_group_vibration_sample_name},
645 {"collections.vibrations.sample.source", st_collections_group_vibration_sample_source}, 658 {"collections.vibrations.sample.source", st_collections_group_vibration_sample_source},
659 FILTERS_STATEMENTS("collections.") /* dup */
646 {"collections.group.vibrations.sample.name", st_collections_group_vibration_sample_name}, /* dup */ 660 {"collections.group.vibrations.sample.name", st_collections_group_vibration_sample_name}, /* dup */
647 {"collections.group.vibrations.sample.source", st_collections_group_vibration_sample_source}, /* dup */ 661 {"collections.group.vibrations.sample.source", st_collections_group_vibration_sample_source}, /* dup */
648 {"collections.group.name", st_collections_group_name}, 662 {"collections.group.name", st_collections_group_name},
@@ -903,6 +917,7 @@ New_Statement_Handler statement_handlers[] =
903 {"collections.group.physics.world.z", st_collections_group_physics_world_z}, 917 {"collections.group.physics.world.z", st_collections_group_physics_world_z},
904 {"collections.group.physics.world.depth", st_collections_group_physics_world_depth}, 918 {"collections.group.physics.world.depth", st_collections_group_physics_world_depth},
905#endif 919#endif
920 FILTERS_STATEMENTS("collections.group.") /* dup */
906 PROGRAM_STATEMENTS("collections.group.parts.part.description") 921 PROGRAM_STATEMENTS("collections.group.parts.part.description")
907 PROGRAM_STATEMENTS("collections.group.parts.part") 922 PROGRAM_STATEMENTS("collections.group.parts.part")
908 PROGRAM_STATEMENTS("collections.group.parts") 923 PROGRAM_STATEMENTS("collections.group.parts")
@@ -4283,6 +4298,148 @@ st_collections_group_data_item(void)
4283 eina_hash_direct_add(pc->data, key, es); 4298 eina_hash_direct_add(pc->data, key, es);
4284} 4299}
4285 4300
4301/** @edcsubsection{collections_group_filter,
4302 * Group.Filter} */
4303
4304/**
4305 @page edcref
4306 @block
4307 filters
4308 @context
4309 filters {
4310 filter {
4311 inline: "key" "Lua script here";
4312 file: "key" "Lua script filename";
4313 ..
4314 }
4315 }
4316 @description
4317 The "filter" block lets you embed filter scripts into an EDC group,
4318 that can then be referred to in a @ref sec_collections_group_parts_description_filter "Text.Filter"
4319 or @ref collections_group_parts_description_filter "Image.Filter" statement.
4320
4321 In a similar way to the @ref sec_collections_group_data "Group.Data" blocks,
4322 it is possible to embed filters from a external file inside the final EDJ.
4323
4324 Please also refer to @ref evasfiltersref "Evas filters reference".
4325 @endblock
4326
4327 @property
4328 inline
4329 @parameters
4330 [name] [Lua script]
4331 @effect
4332 Defines a new Lua script used for filtering.
4333 @endproperty
4334
4335 @property
4336 file
4337 @parameters
4338 [name] [Lua script filename]
4339 @effect
4340 Includes an external file to define a new Lua script used for filtering.
4341 @endproperty
4342*/
4343
4344// ensure order so we could do binary search later on
4345// since this here happens at build time, we don't care about very hi-perf
4346static void
4347_filters_filter_insert(const char *name, const char *script)
4348{
4349 Edje_Gfx_Filter *array;
4350 int k, i;
4351
4352 if (!edje_file->filter_dir)
4353 edje_file->filter_dir = mem_alloc(sizeof(Edje_Gfx_Filter_Directory));
4354
4355 for (k = 0; k < edje_file->filter_dir->filters_count; k++)
4356 {
4357 int cmp = strcmp(name, edje_file->filter_dir->filters[k].name);
4358 if (!cmp)
4359 {
4360 ERR("parse error %s:%i. A filter named '%s' already exists within this block.",
4361 file_in, line - 1, name);
4362 exit(-1);
4363 }
4364 else if (cmp < 0)
4365 break;
4366 }
4367
4368 array = realloc(edje_file->filter_dir->filters,
4369 sizeof(Edje_Gfx_Filter) * (edje_file->filter_dir->filters_count + 1));
4370 if (!array)
4371 {
4372 ERR("Memory allocation failed (array grow)");
4373 exit(-1);
4374 }
4375
4376 for (i = edje_file->filter_dir->filters_count - 1; i >= k; i--)
4377 array[i + 1] = array[i];
4378
4379 array[k].name = eina_stringshare_add(name);
4380 array[k].script = eina_stringshare_add(script);
4381 edje_file->filter_dir->filters_count++;
4382 edje_file->filter_dir->filters = array;
4383}
4384
4385static void
4386st_filters_filter_inline(void)
4387{
4388 char *name, *script;
4389
4390 check_arg_count(2);
4391
4392 name = parse_str(0);
4393 script = parse_str(1);
4394 _filters_filter_insert(name, script);
4395 free(name);
4396 free(script);
4397}
4398
4399static void
4400st_filters_filter_file(void)
4401{
4402 char *name, *file, *script;
4403 Eina_File *f;
4404
4405 check_arg_count(2);
4406
4407 name = parse_str(0);
4408 file = parse_str(1);
4409 f = eina_file_open(file, EINA_FALSE);
4410 if (!f)
4411 {
4412 char path[PATH_MAX], *dir;
4413 Eina_List *l;
4414 // TODO: Introduce special filters_dir? needs new edje_cc argument :(
4415 EINA_LIST_FOREACH(data_dirs, l, dir)
4416 {
4417 snprintf(path, sizeof(path), "%s/%s", dir, file);
4418 f = eina_file_open(path, EINA_FALSE);
4419 if (f) break;
4420 }
4421 if (!f)
4422 {
4423 ERR("parse error %s:%i. Could not open filter script file '%s'",
4424 file_in, line - 1, file);
4425 exit(-1);
4426 }
4427 }
4428
4429 script = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
4430 if (!script)
4431 {
4432 ERR("parse error %s:%i. Could not read filter script file %s",
4433 file_in, line - 1, file);
4434 exit(-1);
4435 }
4436 _filters_filter_insert(name, script);
4437 eina_file_map_free(f, script);
4438 eina_file_close(f);
4439 free(name);
4440
4441}
4442
4286/** @edcsubsection{collections_group_limits, 4443/** @edcsubsection{collections_group_limits,
4287 * Group.Limits} */ 4444 * Group.Limits} */
4288 4445