This is an automated email from the git hooks/post-receive script.

git pushed a commit to reference refs/pull/122/head
in repository efl.

View the commit online.

commit 3f6fe9bb72942ec82966b266cd7fec8bddd0a39f
Author: Cedric BAIL <[email protected]>
AuthorDate: Thu Nov 26 13:14:59 2026 -0600

    examples/edje: add a vector state animation example
    
    A rounded square that morphs into the Enlightenment logo on hover,
    with a gradient fill swept by an override and a color class on the
    stroke: a small theme that exercises named trees, path morphing and
    overrides together, and that the tutorial walks through.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/examples/edje/edje-vector-states.c | 175 +++++++++++++++++++++++++++++++++
 src/examples/edje/meson.build          |   2 +
 src/examples/edje/vector_states.edc    | 112 +++++++++++++++++++++
 3 files changed, 289 insertions(+)

diff --git a/src/examples/edje/edje-vector-states.c b/src/examples/edje/edje-vector-states.c
new file mode 100644
index 0000000000..92fd622bbd
--- /dev/null
+++ b/src/examples/edje/edje-vector-states.c
@@ -0,0 +1,175 @@
+/**
+ * Edje vector state animation example harness
+ *
+ * Loads vector_states.edj (or the file named by argv[1]) and displays the
+ * "ui/logo" group in a window.  Mouse-in / mouse-out over the vector part
+ * triggers the hover transition: the rounded square morphs into the
+ * Enlightenment logo, the gradient sweeps from vertical to horizontal and
+ * the stroke widens.  A line is printed to stdout on each signal.
+ *
+ * Build:
+ *   ninja -C build src/examples/edje/edje-vector-states
+ *
+ * Run (in-tree):
+ *   LD_LIBRARY_PATH=build/src/lib \
+ *   ./build/src/examples/edje/edje-vector-states [file.edj]
+ *
+ * @verbatim
+ * edje_cc vector_states.edc && \
+ * gcc -o edje-vector-states edje-vector-states.c \
+ *   `pkg-config --libs --cflags evas ecore ecore-evas edje`
+ * ./edje-vector-states vector_states.edj
+ * @endverbatim
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#else
+#define EINA_UNUSED
+#endif
+
+#ifndef PACKAGE_DATA_DIR
+#define PACKAGE_DATA_DIR "."
+#endif
+
+#include <Ecore.h>
+#include <Ecore_Evas.h>
+#include <Edje.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define WIDTH  (400)
+#define HEIGHT (400)
+
+static const char commands[] =
+  "commands:\n"
+  "\tMove mouse over the shape to trigger hover transition\n"
+  "\tEsc - exit\n"
+  "\th   - print this help\n";
+
+static void
+_on_delete(Ecore_Evas *ee EINA_UNUSED)
+{
+   ecore_main_loop_quit();
+}
+
+static void
+_on_keydown(void        *data EINA_UNUSED,
+            Evas        *evas EINA_UNUSED,
+            Evas_Object *o EINA_UNUSED,
+            void        *einfo)
+{
+   Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *)einfo;
+
+   if (!strcmp(ev->key, "h"))
+     printf("%s", commands);
+   else if (!strcmp(ev->key, "Escape"))
+     ecore_main_loop_quit();
+   else
+     {
+        printf("unhandled key: %s\n", ev->key);
+        printf("%s", commands);
+     }
+}
+
+static void
+_on_hover_in(void        *data EINA_UNUSED,
+             Evas_Object *obj EINA_UNUSED,
+             const char  *emission,
+             const char  *source)
+{
+   printf("signal received: emission=\"%s\" source=\"%s\"  "
+          "-> transitioning to hover state\n", emission, source);
+}
+
+static void
+_on_hover_out(void        *data EINA_UNUSED,
+              Evas_Object *obj EINA_UNUSED,
+              const char  *emission,
+              const char  *source)
+{
+   printf("signal received: emission=\"%s\" source=\"%s\"  "
+          "-> transitioning to default state\n", emission, source);
+}
+
+int
+main(int argc, char *argv[])
+{
+   const char  *edje_file = PACKAGE_DATA_DIR"/vector_states.edj";
+   Ecore_Evas  *ee;
+   Evas        *evas;
+   Evas_Object *bg;
+   Evas_Object *edje_obj;
+
+   if (argc > 1) edje_file = argv[1];
+
+   if (!ecore_evas_init())
+     return EXIT_FAILURE;
+
+   if (!edje_init())
+     goto shutdown_ecore_evas;
+
+   ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
+   if (!ee) goto shutdown_edje;
+
+   ecore_evas_callback_delete_request_set(ee, _on_delete);
+   ecore_evas_title_set(ee, "Edje Vector State Animation Example");
+
+   evas = ecore_evas_get(ee);
+
+   bg = evas_object_rectangle_add(evas);
+   evas_object_color_set(bg, 240, 240, 240, 255);
+   evas_object_move(bg, 0, 0);
+   evas_object_resize(bg, WIDTH, HEIGHT);
+   evas_object_show(bg);
+   evas_object_focus_set(bg, EINA_TRUE);
+
+   edje_obj = edje_object_add(evas);
+
+   if (!edje_object_file_set(edje_obj, edje_file, "ui/logo"))
+     {
+        int         err    = edje_object_load_error_get(edje_obj);
+        const char *errmsg = edje_load_error_str(err);
+        fprintf(stderr, "Could not load 'ui/logo' from %s: %s\n",
+                edje_file, errmsg);
+        evas_object_del(edje_obj);
+        goto shutdown_edje;
+     }
+
+   /* The STATE_SET itself is done by the theme's programs; these callbacks
+    * only report the signals. */
+   edje_object_signal_callback_add(edje_obj, "mouse,in",  "logo",
+                                   _on_hover_in,  NULL);
+   edje_object_signal_callback_add(edje_obj, "mouse,out", "logo",
+                                   _on_hover_out, NULL);
+
+   evas_object_move(edje_obj, 40, 40);
+   evas_object_resize(edje_obj, WIDTH - 80, HEIGHT - 80);
+   evas_object_show(edje_obj);
+
+   evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN,
+                                  _on_keydown, NULL);
+
+   printf("%s", commands);
+   printf("Loaded: %s  group: ui/logo\n", edje_file);
+   printf("Move the mouse over the shape to see the hover transition.\n");
+   printf("Runtime theming: call edje_object_color_class_set(obj, \"logo_fill\", ...)\n"
+          "to retint the fill without recompiling the theme.\n\n");
+
+   ecore_evas_show(ee);
+   ecore_main_loop_begin();
+
+   ecore_evas_free(ee);
+   ecore_evas_shutdown();
+   edje_shutdown();
+
+   return EXIT_SUCCESS;
+
+ shutdown_edje:
+   edje_shutdown();
+ shutdown_ecore_evas:
+   ecore_evas_shutdown();
+
+   return EXIT_FAILURE;
+}
diff --git a/src/examples/edje/meson.build b/src/examples/edje/meson.build
index ff57a6e29e..07340ca50a 100644
--- a/src/examples/edje/meson.build
+++ b/src/examples/edje/meson.build
@@ -45,6 +45,7 @@ edc_files = [
   'toggle_using_filter.edc',
   'multisense.edc',
   'center_zoom.edc',
+  'vector_states.edc',
 ]
 
 if (get_option('physics'))
@@ -119,6 +120,7 @@ edje_examples = [
   'edje-signals-messages',
   'edje-swallow',
   'edje-swallow2',
+  'edje-vector-states',
   'edje-table',
   'edje-text',
   'edje-textblock-hyphenation',
diff --git a/src/examples/edje/vector_states.edc b/src/examples/edje/vector_states.edc
new file mode 100644
index 0000000000..41d448082a
--- /dev/null
+++ b/src/examples/edje/vector_states.edc
@@ -0,0 +1,112 @@
+/**
+ * Edje vector state animation - worked example
+ *
+ * Demonstrates:
+ *   - A named vector tree in the toplevel vectors {} block
+ *   - A linear gradient node referenced from a shape's fill
+ *   - A VECTOR part referencing the tree via vector.use:
+ *   - Two states (default, hover) with per-node overrides on BOTH the
+ *     shape (path + stroke width) AND the gradient (endpoints + stops)
+ *   - color_class binding on gradient stops + stroke
+ *   - STATE_SET programs wired to mouse,in / mouse,out for live transitions
+ *
+ * Compile:
+ *   edje_cc vector_states.edc
+ * Run:
+ *   ./edje-vector-states vector_states.edj
+ * (the edje-vector-states example builds and loads it by default)
+ */
+
+collections {
+   color_classes {
+      color_class { name: "logo_fill";    color:  80 140 255 255; }
+      color_class { name: "logo_hover";   color: 255 200  80 255; }
+      color_class { name: "logo_outline"; color:  20  20  20 255; }
+   }
+
+   vectors {
+      vector { name: "logo_glyph";
+         viewbox: 0 0 100 100;
+         /* The gradient node sits as a sibling of the shape inside the
+          * tree.  Shapes reference it by name via fill.gradient:.
+          * Stops bind to color_class so the gradient retints together
+          * with the rest of the theme. */
+         gradient_linear { name: "body_grad";
+            start: 50 0;
+            end:   50 100;
+            spread: PAD;
+            stop { offset: 0.0; color_class: "logo_fill";    }
+            stop { offset: 1.0; color_class: "logo_outline"; }
+         }
+         shape { name: "body";
+            /* Topology: M + 2 L + 13 C + Z - identical command sequence
+             * in both states so efl_gfx_path_interpolate() can morph the
+             * path.  The hover state is the actual Enlightenment logo
+             * (extracted from data/elementary/themes/img/svg/enlightenment.svg
+             * and rescaled to a 100x100 viewbox).  The default state
+             * traces a rounded square with the same 16-vertex layout -
+             * straight cubics on the edges (control points collinear)
+             * and four corner cubics with control points at the would-be
+             * sharp corner.  The two L commands sit between the top
+             * edge's first half and the right edge's bottom (matching
+             * the L positions in the logo, which mark where the outer
+             * ring meets the inner cut). */
+            path: "M12,0 L50,0 C63,0 75,0 88,0 C100,0 100,0 100,12 C100,18 100,24 100,30 C100,37 100,43 100,50 C100,57 100,63 100,70 L100,88 C100,100 100,100 88,100 C75,100 62,100 50,100 C37,100 24,100 12,100 C0,100 0,100 0,88 C0,79 0,69 0,60 C0,52 0,43 0,35 C0,27 0,20 0,12 C0,0 0,0 12,0 Z";
+            fill.gradient: "body_grad";
+            stroke.color_class: "logo_outline";
+            stroke.width: 2;
+         }
+      }
+   }
+
+   group { name: "ui/logo";
+      parts {
+         part { name: "logo"; type: VECTOR;
+            description { state: "default" 0.0;
+               rel1.relative: 0.0 0.0;
+               rel2.relative: 1.0 1.0;
+               vector.use: "logo_glyph";
+            }
+            description { state: "hover" 0.0;
+               inherit: "default" 0.0;
+               /* Two overrides in this state:
+                *  1. Morph the body path from the rounded square to the
+                *     Enlightenment logo (same topology: M + 2 L + 13 C + Z)
+                *     and widen its stroke.
+                *  2. Sweep the gradient direction from vertical (top to
+                *     bottom) to horizontal (left to right) and swap the top
+                *     stop to logo_hover so the warm colour leads. */
+               vector.shape {
+                  target: "body";
+                  /* Same topology as default (M + 2 L + 13 C + Z).  This
+                   * is the Enlightenment "E" logo - a stylised round E
+                   * formed by an outer ring with an inner cut.  Path
+                   * extracted from data/elementary/themes/img/svg/
+                   * enlightenment.svg, transformed to viewbox 0,0,100,100. */
+                  path: "M30.17,42.65 L75.78,73.10 C77.67,71.14 77.67,71.14 78.88,69.33 C89.13,54.01 85.57,32.05 69.38,21.28 C53.13,10.33 31.46,15.41 21.13,30.74 C11.25,45.59 13.62,67.40 30.68,78.96 C45.61,88.82 59.60,84.48 68.18,79.73 L63.89,72.38 C54.65,77.26 43.82,77.84 35.48,72.16 C22.65,63.66 20.12,46.96 28.03,35.27 C35.81,23.53 51.90,19.96 64.64,28.36 C78.04,37.45 77.26,53.24 73.93,60.31 C72.47,59.30 71.00,58.29 69.53,57.28 C73.36,47.37 69.47,37.58 61.81,32.46 C52.79,26.42 39.71,27 [...]
+                  stroke.width: 4;
+               }
+               vector.gradient_linear {
+                  target: "body_grad";
+                  start: 0  50;
+                  end:   100 50;
+                  stop { offset: 0.0; color_class: "logo_hover";   }
+                  stop { offset: 1.0; color_class: "logo_outline"; }
+               }
+            }
+         }
+      }
+      programs {
+         program { signal: "mouse,in"; source: "logo";
+            action: STATE_SET "hover" 0.0;
+            target: "logo";
+            transition: SINUSOIDAL 0.3;
+         }
+         program { signal: "mouse,out"; source: "logo";
+            action: STATE_SET "default" 0.0;
+            target: "logo";
+            transition: SINUSOIDAL 0.3;
+         }
+      }
+   }
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to