summaryrefslogtreecommitdiff
path: root/src
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 /src
parenteaa2e1254263e68e4e90ad031a251097b1b37459 (diff)
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
Diffstat (limited to 'src')
-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 @@
17#define MY_CLASS_NAME "Efl.Ui.Textpath" 17#define MY_CLASS_NAME "Efl.Ui.Textpath"
18 18
19#define SLICE_DEFAULT_NO 99 19#define SLICE_DEFAULT_NO 99
20
21typedef struct _Efl_Ui_Textpath_Point Efl_Ui_Textpath_Point; 20typedef struct _Efl_Ui_Textpath_Point Efl_Ui_Textpath_Point;
22typedef struct _Efl_Ui_Textpath_Line Efl_Ui_Textpath_Line; 21typedef struct _Efl_Ui_Textpath_Line Efl_Ui_Textpath_Line;
23typedef struct _Efl_Ui_Textpath_Segment Efl_Ui_Textpath_Segment; 22typedef struct _Efl_Ui_Textpath_Segment Efl_Ui_Textpath_Segment;
@@ -77,6 +76,12 @@ struct _Efl_Ui_Textpath_Data
77 Efl_Ui_Textpath_Data *sd = efl_data_scope_get(o, EFL_UI_TEXTPATH_CLASS) 76 Efl_Ui_Textpath_Data *sd = efl_data_scope_get(o, EFL_UI_TEXTPATH_CLASS)
78 77
79static inline double 78static inline double
79_rad_to_deg(double rad)
80{
81 return 180 * rad / M_PI;
82}
83
84static inline double
80_deg_to_rad(double angle) 85_deg_to_rad(double angle)
81{ 86{
82 return angle / 180 * M_PI; 87 return angle / 180 * M_PI;
@@ -576,6 +581,79 @@ _textpath_text_set_internal(Eo *obj, Efl_Ui_Textpath_Data *pd, const char *part,
576 return ret; 581 return ret;
577} 582}
578 583
584static void
585_path_start_angle_adjust(Eo *obj, Efl_Ui_Textpath_Data *pd)
586{
587 Eina_Rect r;
588 Efl_Ui_Textpath_Segment *seg;
589 Eina_Vector2 first, last;
590 int remained_w, len;
591 double rad, t, offset_angle;
592
593 if (pd->direction != EFL_UI_TEXTPATH_DIRECTION_CW_CENTER &&
594 pd->direction != EFL_UI_TEXTPATH_DIRECTION_CCW_CENTER)
595 return;
596
597 r = efl_gfx_entity_geometry_get(pd->text_obj);
598 remained_w = r.w;
599
600 EINA_INLIST_FOREACH(pd->segments, seg)
601 {
602 if (remained_w <= 0)
603 break;
604
605 len = seg->length;
606 if (remained_w < len)
607 {
608 t = remained_w / (double)len;
609 eina_bezier_point_at(&seg->bezier, t, &last.x, &last.y);
610 }
611
612 if (remained_w == r.w)
613 eina_bezier_point_at(&seg->bezier, 0, &first.x, &first.y);
614
615 remained_w -= len;
616 }
617
618 first.x -= (pd->circle.x + r.x);
619 first.y -= (pd->circle.y + r.y);
620 last.x -= (pd->circle.x + r.x);
621 last.y -= (pd->circle.y + r.y);
622
623 eina_vector2_normalize(&first, &first);
624 eina_vector2_normalize(&last, &last);
625 rad = acos(eina_vector2_dot_product(&first, &last));
626 if (rad == 0) return;
627
628 offset_angle = _rad_to_deg(rad);
629 if (r.w > pd->total_length / 2)
630 offset_angle = 360 - offset_angle;
631 offset_angle /= 2.0;
632
633 efl_gfx_path_reset(obj);
634 if (pd->direction == EFL_UI_TEXTPATH_DIRECTION_CW_CENTER)
635 {
636 efl_gfx_path_append_arc(obj,
637 pd->circle.x - pd->circle.radius,
638 pd->circle.y - pd->circle.radius,
639 pd->circle.radius * 2,
640 pd->circle.radius * 2,
641 pd->circle.start_angle + offset_angle,
642 -360);
643 }
644 else
645 {
646 efl_gfx_path_append_arc(obj,
647 pd->circle.x - pd->circle.radius,
648 pd->circle.y - pd->circle.radius,
649 pd->circle.radius * 2,
650 pd->circle.radius * 2,
651 pd->circle.start_angle - offset_angle,
652 360);
653 }
654 _path_data_get(obj, pd, EINA_TRUE);
655}
656
579EOLIAN static void 657EOLIAN static void
580_efl_ui_textpath_efl_canvas_group_group_calculate(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd) 658_efl_ui_textpath_efl_canvas_group_group_calculate(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd)
581{ 659{
@@ -702,7 +780,8 @@ _efl_ui_textpath_circle_set(Eo *obj, Efl_Ui_Textpath_Data *pd, double x, double
702 pd->direction = direction; 780 pd->direction = direction;
703 781
704 efl_gfx_path_reset(obj); 782 efl_gfx_path_reset(obj);
705 if (direction == EFL_UI_TEXTPATH_DIRECTION_CW) 783 if (direction == EFL_UI_TEXTPATH_DIRECTION_CW ||
784 direction == EFL_UI_TEXTPATH_DIRECTION_CW_CENTER)
706 { 785 {
707 efl_gfx_path_append_arc(obj, x - radius, y - radius, radius * 2, 786 efl_gfx_path_append_arc(obj, x - radius, y - radius, radius * 2,
708 radius * 2, start_angle, -360); 787 radius * 2, start_angle, -360);
@@ -714,6 +793,7 @@ _efl_ui_textpath_circle_set(Eo *obj, Efl_Ui_Textpath_Data *pd, double x, double
714 } 793 }
715 794
716 _path_data_get(obj, pd, EINA_TRUE); 795 _path_data_get(obj, pd, EINA_TRUE);
796 _path_start_angle_adjust(obj, pd);
717 _sizing_eval(pd); 797 _sizing_eval(pd);
718} 798}
719 799
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 @@
1enum @beta Efl.Ui.Textpath_Direction { 1enum @beta Efl.Ui.Textpath_Direction {
2 [[Textpath direction]] 2 [[Textpath direction]]
3 cw, [[Clockwise]] 3 cw, [[Clockwise]]
4 ccw [[Counter-clockwise]] 4 ccw, [[Counter-clockwise]]
5 cw_center, [[Clockwise, middle of text will be at start angle @since 1.23]]
6 ccw_center [[Counter-clockwise, middle of text will be at start angle @since 1.23]]
5} 7}
6 8
7class @beta Efl.Ui.Textpath extends Efl.Ui.Layout_Base implements Efl.Text, Efl.Gfx.Path 9class @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;
18typedef enum 18typedef enum
19{ 19{
20 EFL_UI_TEXTPATH_DIRECTION_CW = 0, /**< Clockwise */ 20 EFL_UI_TEXTPATH_DIRECTION_CW = 0, /**< Clockwise */
21 EFL_UI_TEXTPATH_DIRECTION_CCW /**< Counter-clockwise */ 21 EFL_UI_TEXTPATH_DIRECTION_CCW, /**< Counter-clockwise */
22 EFL_UI_TEXTPATH_DIRECTION_CW_CENTER, /**< Clockwise, middle of text will be at start angle @since 1.23 */
23 EFL_UI_TEXTPATH_DIRECTION_CCW_CENTER /**< Counter-clockwise, middle of text will be at start angle @since 1.23 */
22} Efl_Ui_Textpath_Direction; 24} Efl_Ui_Textpath_Direction;
23 25
24 26