summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinwoo Kim <cinoo.kim@samsung.com>2019-05-21 14:31:12 +0900
committerHermet Park <hermetpark@gmail.com>2019-05-21 14:31:12 +0900
commit205e5a5fe81d768dbad8985f10585bb44b453dde (patch)
treec889423b2391ff2dd71ecd2cdacc79fb3252ac66
parenteaa2e1254263e68e4e90ad031a251097b1b37459 (diff)
downloadefl-205e5a5fe81d768dbad8985f10585bb44b453dde.tar.gz
Efl.Ui.Textpath: support center align for each direction
Summary: The textpath draws text from the start_angle. User needs to set correct start_angle to center the text. This start_angle could be changed according to each parameters of circle_set such as x, y, radius, direction and text itself. So this patch is introducing direction EFL_UI_TEXTPATH_DIRECTION_CC(W)_CENTER. The center of textpath will be located at the start_angle with this direction. Test Plan: I will add example if this patch is acceptable. Reviewers: Hermet, jsuya Reviewed By: Hermet Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8892
-rw-r--r--src/lib/elementary/efl_ui_textpath.c84
-rw-r--r--src/lib/elementary/efl_ui_textpath.eo4
-rw-r--r--src/lib/elementary/efl_ui_textpath_eo.legacy.h4
3 files changed, 88 insertions, 4 deletions
diff --git a/src/lib/elementary/efl_ui_textpath.c b/src/lib/elementary/efl_ui_textpath.c
index 135889c2ad..f9c906ab1a 100644
--- a/src/lib/elementary/efl_ui_textpath.c
+++ b/src/lib/elementary/efl_ui_textpath.c
@@ -17,7 +17,6 @@
#define MY_CLASS_NAME "Efl.Ui.Textpath"
#define SLICE_DEFAULT_NO 99
-
typedef struct _Efl_Ui_Textpath_Point Efl_Ui_Textpath_Point;
typedef struct _Efl_Ui_Textpath_Line Efl_Ui_Textpath_Line;
typedef struct _Efl_Ui_Textpath_Segment Efl_Ui_Textpath_Segment;
@@ -77,6 +76,12 @@ struct _Efl_Ui_Textpath_Data
Efl_Ui_Textpath_Data *sd = efl_data_scope_get(o, EFL_UI_TEXTPATH_CLASS)
static inline double
+_rad_to_deg(double rad)
+{
+ return 180 * rad / M_PI;
+}
+
+static inline double
_deg_to_rad(double angle)
{
return angle / 180 * M_PI;
@@ -576,6 +581,79 @@ _textpath_text_set_internal(Eo *obj, Efl_Ui_Textpath_Data *pd, const char *part,
return ret;
}
+static void
+_path_start_angle_adjust(Eo *obj, Efl_Ui_Textpath_Data *pd)
+{
+ Eina_Rect r;
+ Efl_Ui_Textpath_Segment *seg;
+ Eina_Vector2 first, last;
+ int remained_w, len;
+ double rad, t, offset_angle;
+
+ if (pd->direction != EFL_UI_TEXTPATH_DIRECTION_CW_CENTER &&
+ pd->direction != EFL_UI_TEXTPATH_DIRECTION_CCW_CENTER)
+ return;
+
+ r = efl_gfx_entity_geometry_get(pd->text_obj);
+ remained_w = r.w;
+
+ EINA_INLIST_FOREACH(pd->segments, seg)
+ {
+ if (remained_w <= 0)
+ break;
+
+ len = seg->length;
+ if (remained_w < len)
+ {
+ t = remained_w / (double)len;
+ eina_bezier_point_at(&seg->bezier, t, &last.x, &last.y);
+ }
+
+ if (remained_w == r.w)
+ eina_bezier_point_at(&seg->bezier, 0, &first.x, &first.y);
+
+ remained_w -= len;
+ }
+
+ first.x -= (pd->circle.x + r.x);
+ first.y -= (pd->circle.y + r.y);
+ last.x -= (pd->circle.x + r.x);
+ last.y -= (pd->circle.y + r.y);
+
+ eina_vector2_normalize(&first, &first);
+ eina_vector2_normalize(&last, &last);
+ rad = acos(eina_vector2_dot_product(&first, &last));
+ if (rad == 0) return;
+
+ offset_angle = _rad_to_deg(rad);
+ if (r.w > pd->total_length / 2)
+ offset_angle = 360 - offset_angle;
+ offset_angle /= 2.0;
+
+ efl_gfx_path_reset(obj);
+ if (pd->direction == EFL_UI_TEXTPATH_DIRECTION_CW_CENTER)
+ {
+ efl_gfx_path_append_arc(obj,
+ pd->circle.x - pd->circle.radius,
+ pd->circle.y - pd->circle.radius,
+ pd->circle.radius * 2,
+ pd->circle.radius * 2,
+ pd->circle.start_angle + offset_angle,
+ -360);
+ }
+ else
+ {
+ efl_gfx_path_append_arc(obj,
+ pd->circle.x - pd->circle.radius,
+ pd->circle.y - pd->circle.radius,
+ pd->circle.radius * 2,
+ pd->circle.radius * 2,
+ pd->circle.start_angle - offset_angle,
+ 360);
+ }
+ _path_data_get(obj, pd, EINA_TRUE);
+}
+
EOLIAN static void
_efl_ui_textpath_efl_canvas_group_group_calculate(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd)
{
@@ -702,7 +780,8 @@ _efl_ui_textpath_circle_set(Eo *obj, Efl_Ui_Textpath_Data *pd, double x, double
pd->direction = direction;
efl_gfx_path_reset(obj);
- if (direction == EFL_UI_TEXTPATH_DIRECTION_CW)
+ if (direction == EFL_UI_TEXTPATH_DIRECTION_CW ||
+ direction == EFL_UI_TEXTPATH_DIRECTION_CW_CENTER)
{
efl_gfx_path_append_arc(obj, x - radius, y - radius, radius * 2,
radius * 2, start_angle, -360);
@@ -714,6 +793,7 @@ _efl_ui_textpath_circle_set(Eo *obj, Efl_Ui_Textpath_Data *pd, double x, double
}
_path_data_get(obj, pd, EINA_TRUE);
+ _path_start_angle_adjust(obj, pd);
_sizing_eval(pd);
}
diff --git a/src/lib/elementary/efl_ui_textpath.eo b/src/lib/elementary/efl_ui_textpath.eo
index b403d149f5..4a56b490a3 100644
--- a/src/lib/elementary/efl_ui_textpath.eo
+++ b/src/lib/elementary/efl_ui_textpath.eo
@@ -1,7 +1,9 @@
enum @beta Efl.Ui.Textpath_Direction {
[[Textpath direction]]
cw, [[Clockwise]]
- ccw [[Counter-clockwise]]
+ ccw, [[Counter-clockwise]]
+ cw_center, [[Clockwise, middle of text will be at start angle @since 1.23]]
+ ccw_center [[Counter-clockwise, middle of text will be at start angle @since 1.23]]
}
class @beta Efl.Ui.Textpath extends Efl.Ui.Layout_Base implements Efl.Text, Efl.Gfx.Path
diff --git a/src/lib/elementary/efl_ui_textpath_eo.legacy.h b/src/lib/elementary/efl_ui_textpath_eo.legacy.h
index dad8d9e120..5fe981a2d8 100644
--- a/src/lib/elementary/efl_ui_textpath_eo.legacy.h
+++ b/src/lib/elementary/efl_ui_textpath_eo.legacy.h
@@ -18,7 +18,9 @@ typedef Eo Efl_Ui_Textpath;
typedef enum
{
EFL_UI_TEXTPATH_DIRECTION_CW = 0, /**< Clockwise */
- EFL_UI_TEXTPATH_DIRECTION_CCW /**< Counter-clockwise */
+ EFL_UI_TEXTPATH_DIRECTION_CCW, /**< Counter-clockwise */
+ EFL_UI_TEXTPATH_DIRECTION_CW_CENTER, /**< Clockwise, middle of text will be at start angle @since 1.23 */
+ EFL_UI_TEXTPATH_DIRECTION_CCW_CENTER /**< Counter-clockwise, middle of text will be at start angle @since 1.23 */
} Efl_Ui_Textpath_Direction;