aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2017-07-20 14:31:17 +0900
committerThiep Ha <thiepha@gmail.com>2017-07-20 19:12:29 +0900
commit78e20df5dff1d947b24f47694489d9169a1565cd (patch)
treef7645032f47ddb2be76fe372fcec091852049c01
parentdraw on circle path using bezier (diff)
downloadefl-78e20df5dff1d947b24f47694489d9169a1565cd.tar.gz
add support for line segment
-rw-r--r--prototype.c49
-rw-r--r--src/bin/elementary/test_efl_ui_textpath.c6
-rw-r--r--src/lib/elementary/efl_ui_textpath.c102
3 files changed, 147 insertions, 10 deletions
diff --git a/prototype.c b/prototype.c
index 27620acd9d..dc43c3eb88 100644
--- a/prototype.c
+++ b/prototype.c
@@ -477,8 +477,44 @@ _text_on_path_draw(Efl_Ui_TextPath_Data *pd)
}
static void
-_text_on_line_draw(Efl_Ui_TextPath_Data *pd, double px0, double py0, double px1, double py1)
+_text_on_line_draw(Efl_Ui_TextPath_Data *pd, double x1, double y1, double x2, double y2)
{
+ //test: line
+ Eo *line = evas_object_line_add(evas_object_evas_get(pd->content));
+ efl_gfx_size_set(line, 500, 500);
+ efl_gfx_color_set(line, 255, 255, 0, 255);
+ efl_gfx_visible_set(line, EINA_TRUE);
+ evas_object_line_xy_set(line, x1, y1, x2, y2);
+ //
+ Evas_Coord x, y, w, h;
+ efl_gfx_geometry_get(pd->content, &x, &y, &w, &h);
+ ERR("content goe: %d %d %d %d", x, y, w, h);
+
+ double len, sina, cosa;
+ len = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
+ sina = (y2 - y1) / len;
+ cosa = (x2 - x1) / len;
+
+ h = h / 2;
+ Evas_Map *map = evas_map_new(4);
+ evas_map_point_coord_set(map, 3, x1 - h * sina, y1 + h * cosa, 0);
+ evas_map_point_coord_set(map, 2, x2 - h * sina, y2 + h * cosa, 0);
+ evas_map_point_coord_set(map, 1, x2 + h * sina, y2 - h * cosa, 0);
+ evas_map_point_coord_set(map, 0, x1 + h * sina, y1 - h * cosa, 0);
+
+ h *= 2;
+ w = len < w ? len : w;
+ evas_map_point_image_uv_set(map, 0, 0, 0);
+ evas_map_point_image_uv_set(map, 1, w, 0);
+ evas_map_point_image_uv_set(map, 2, w, h);
+ evas_map_point_image_uv_set(map, 3, 0, h);
+
+ Evas_Object *proxy = evas_object_image_filled_add(evas_object_evas_get(pd->content));
+ evas_object_image_source_set(proxy, pd->content);
+ efl_gfx_visible_set(proxy, EINA_TRUE);
+
+ evas_object_map_enable_set(proxy, EINA_TRUE);
+ evas_object_map_set(proxy, map);
}
static void
@@ -1147,9 +1183,14 @@ content_cb(void *data, Evas_Object *obj, void *event_info)
//////
Eo *root = efl_add(EFL_VG_CONTAINER_CLASS, NULL);
Eo *vg = efl_add(EFL_VG_SHAPE_CLASS, root, efl_vg_name_set(efl_added, "rect"));
- efl_gfx_path_append_circle(vg, 200, 200, 100);
- //efl_gfx_path_append_move_to(vg, 200, 200);
- //efl_gfx_path_append_line_to(vg, 300, 300);
+
+ //remove comment to enable circle text
+ //efl_gfx_path_append_circle(vg, 200, 200, 100);
+
+ //remove comment to enable line text
+ efl_gfx_path_append_move_to(vg, 200, 200);
+ efl_gfx_path_append_line_to(vg, 300, 400);
+
Efl_Ui_TextPath_Data *pd = data;
pd->vg = vg;
//////
diff --git a/src/bin/elementary/test_efl_ui_textpath.c b/src/bin/elementary/test_efl_ui_textpath.c
index 2de657203d..dc77f17ede 100644
--- a/src/bin/elementary/test_efl_ui_textpath.c
+++ b/src/bin/elementary/test_efl_ui_textpath.c
@@ -30,7 +30,11 @@ elm_main(int argc, char *argv[])
//efl_text_set(txtpath, "abcd&lt;eghi&gt;j");
//elm_object_text_set(txtpath, "abcd&lt;eghi&gt;j");
efl_text_set(txtpath, "abcd&lt;eghi&gt;j more and more, so long to make it ellipsis? No, it is not enough, want to see more?xy");
- efl_gfx_path_append_circle(txtpath, 200, 200, 100);
+ //efl_gfx_path_append_circle(txtpath, 200, 200, 100);
+
+ efl_gfx_path_append_move_to(txtpath, 100, 100);
+ efl_gfx_path_append_line_to(txtpath, 200, 300);
+
efl_ui_textpath_ellipsis_set(txtpath, EINA_TRUE);
efl_gfx_geometry_set(txtpath, 0, 0, 200, 200);
efl_gfx_visible_set(txtpath, EINA_TRUE);
diff --git a/src/lib/elementary/efl_ui_textpath.c b/src/lib/elementary/efl_ui_textpath.c
index a5550c2f77..4acf83f697 100644
--- a/src/lib/elementary/efl_ui_textpath.c
+++ b/src/lib/elementary/efl_ui_textpath.c
@@ -21,8 +21,17 @@
#define SLICE_MAX 200
#define SLICE_DEFAULT_NO 69
+typedef struct _Efl_Ui_Textpath_Segment Efl_Ui_Textpath_Segment;
typedef struct _Efl_Ui_Textpath_Data Efl_Ui_Textpath_Data;
+struct _Efl_Ui_Textpath_Segment
+{
+ EINA_INLIST;
+ int length;
+ Eina_Bezier bezier;
+};
+
+
struct _Efl_Ui_Textpath_Data {
Evas_Object *content;
Evas_Object *text_obj;
@@ -38,6 +47,9 @@ struct _Efl_Ui_Textpath_Data {
int slice_no;
Eina_Bool autofit;
Eina_Bool ellipsis;
+
+ Eina_Inlist *segments;
+ int total_length;
};
#define EFL_UI_TEXTPATH_DATA_GET(o, sd) \
@@ -201,13 +213,82 @@ _draw_text_on_path(Efl_Ui_Textpath_Data *pd, double px0, double py0, double ctrl
evas_map_free(map);
}
+static void
+_bezier_segment_store(Efl_Ui_Textpath_Data *pd, double px0, double py0,
+ double ctrl_x0, double ctrl_y0,
+ double ctrl_x1, double ctrl_y1,
+ double px1, double py1)
+{
+ Eina_Bezier bz;
+ eina_bezier_values_set(&bz, px0, py0,
+ ctrl_x0, ctrl_y0,
+ ctrl_x1, ctrl_y1,
+ px1, py1);
+ int len = eina_bezier_length_get(&bz);
+ Efl_Ui_Textpath_Segment *seg = malloc(sizeof(Efl_Ui_Textpath_Segment));
+ if (!seg)
+ {
+ ERR("Failed to allocate segment");
+ return;
+ }
+ seg->length = len;
+ seg->bezier = bz;
+
+ pd->segments = eina_inlist_append(pd->segments, EINA_INLIST_GET(seg));
+
+ pd->total_length += len;
+ ERR("bezier point: %.1f %.1f; len: %d; total_length: %d", px0, py0, len, pd->total_length);
+}
+
+
+static void
+_text_on_line_draw(Efl_Ui_Textpath_Data *pd, double x1, double y1, double x2, double y2)
+{
+ //test: line
+ Eo *line = evas_object_line_add(evas_object_evas_get(pd->text_obj));
+ efl_gfx_size_set(line, 500, 500);
+ efl_gfx_color_set(line, 255, 255, 0, 255);
+ efl_gfx_visible_set(line, EINA_TRUE);
+ evas_object_line_xy_set(line, x1, y1, x2, y2);
+ //
+ Evas_Coord x, y, w, h;
+ efl_gfx_geometry_get(pd->text_obj, &x, &y, &w, &h);
+ ERR("content geo: %d %d %d %d", x, y, w, h);
+
+ double len, sina, cosa;
+ len = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
+ sina = (y2 - y1) / len;
+ cosa = (x2 - x1) / len;
+
+ h = h / 2;
+ Evas_Map *map = evas_map_new(4);
+ evas_map_point_coord_set(map, 3, x1 - h * sina, y1 + h * cosa, 0);
+ evas_map_point_coord_set(map, 2, x2 - h * sina, y2 + h * cosa, 0);
+ evas_map_point_coord_set(map, 1, x2 + h * sina, y2 - h * cosa, 0);
+ evas_map_point_coord_set(map, 0, x1 + h * sina, y1 - h * cosa, 0);
+
+ h *= 2;
+ //w = len < w ? len : w;
+ evas_map_point_image_uv_set(map, 0, 0, 0);
+ evas_map_point_image_uv_set(map, 1, w, 0);
+ evas_map_point_image_uv_set(map, 2, w, h);
+ evas_map_point_image_uv_set(map, 3, 0, h);
+
+ Evas_Object *proxy = evas_object_image_filled_add(evas_object_evas_get(pd->text_obj));
+ evas_object_image_source_set(proxy, pd->text_obj);
+ efl_gfx_visible_set(proxy, EINA_TRUE);
+
+ evas_object_map_enable_set(proxy, EINA_TRUE);
+ evas_object_map_set(proxy, map);
+}
+
static void
-_path_draw(Efl_Ui_Textpath_Data *obj, Efl_Ui_Textpath_Data *pd)
+_path_draw(Evas_Object *obj, Efl_Ui_Textpath_Data *pd)
{
ERR("In");
- Efl_Gfx_Path_Command *cmd;
+ const Efl_Gfx_Path_Command_Type *cmd;
const double *points;
efl_gfx_path_get(obj, &cmd, &points);
if (cmd)
@@ -240,20 +321,31 @@ _path_draw(Efl_Ui_Textpath_Data *obj, Efl_Ui_Textpath_Data *pd)
pos++;
py1 = points[pos];
+ _bezier_segment_store(pd, px0, py0, ctrl_x0, ctrl_y0, ctrl_x1, ctrl_y1, px1, py1);
//draw text on path
- _draw_text_on_path(pd, px0, py0, ctrl_x0, ctrl_y0, ctrl_x1, ctrl_y1, px1, py1);
+ //_draw_text_on_path(pd, px0, py0, ctrl_x0, ctrl_y0, ctrl_x1, ctrl_y1, px1, py1);
//move points
px0 = px1;
py0 = py1;
}
+ else if (*cmd == EFL_GFX_PATH_COMMAND_TYPE_LINE_TO)
+ {
+ pos++;
+ px1 = points[pos];
+ pos++;
+ py1 = points[pos];
+ ERR("line: %.1f %.1f :: %.1f %.1f", px0, py0, px1, py1);
+
+ _text_on_line_draw(pd, px0, py0, px1, py1);
+ }
cmd++;
}
}
}
static void
-_circle_draw(Efl_Ui_Textpath_Data *eo, Efl_Ui_Textpath_Data *pd)
+_circle_draw(Evas_Object *eo, Efl_Ui_Textpath_Data *pd)
{
Evas_Coord x, y, w, h;
Evas_Object *proxy;
@@ -437,7 +529,7 @@ _circle_draw(Efl_Ui_Textpath_Data *eo, Efl_Ui_Textpath_Data *pd)
}
static void
-_sizing_eval(Efl_Ui_Textpath_Data *obj, Efl_Ui_Textpath_Data *pd)
+_sizing_eval(Evas_Object *obj, Efl_Ui_Textpath_Data *pd)
{
//_circle_draw(obj, pd);
_path_draw(obj, pd);