diff options
author | Thiep Ha <thiepha@gmail.com> | 2017-07-25 16:32:36 +0900 |
---|---|---|
committer | Thiep Ha <thiepha@gmail.com> | 2017-07-25 16:32:36 +0900 |
commit | b33705e7c88a9a61aba09e3aaa48e2a5acfcdfd7 (patch) | |
tree | d693ce3e8b9035ad434dc1071d23674c08e150d9 | |
parent | 65e075376e747b36b5523ab0d22d8526459f8b1d (diff) | |
download | efl-b33705e7c88a9a61aba09e3aaa48e2a5acfcdfd7.tar.gz |
correct ellipse, auto fit
-rw-r--r-- | src/bin/elementary/test_efl_ui_textpath.c | 16 | ||||
-rw-r--r-- | src/bin/elementary/test_scroller.c | 54 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_textpath.c | 139 |
3 files changed, 149 insertions, 60 deletions
diff --git a/src/bin/elementary/test_efl_ui_textpath.c b/src/bin/elementary/test_efl_ui_textpath.c index bd35be2a29..2471aba37f 100644 --- a/src/bin/elementary/test_efl_ui_textpath.c +++ b/src/bin/elementary/test_efl_ui_textpath.c @@ -25,17 +25,18 @@ elm_main(int argc, char *argv[]) txtpath = efl_add(EFL_UI_TEXTPATH_CLASS, win); efl_ui_textpath_autofit_set(txtpath, EINA_TRUE); - efl_text_set(txtpath, "abcdef and more you can see from this test"); + //efl_text_set(txtpath, "abcdef and more you can see from this test"); //efl_text_set(txtpath, "abcd<efghi>jklm"); - //efl_text_set(txtpath, "abcd<eghi>j"); + efl_text_set(txtpath, "abcd<eghi>j"); //elm_object_text_set(txtpath, "abcd<eghi>j"); //efl_text_set(txtpath, "abcd<eghi>j more and more, so long to make it ellipsis? No, it is not enough, want to see more?xy"); - //efl_ui_textpath_circle_set(txtpath, 200, 200, 100, 0); + //efl_ui_textpath_circle_set(txtpath, 0, 0, 100, 0); //efl_gfx_path_append_circle(txtpath, 200, 200, 100); - efl_gfx_path_append_arc(txtpath, 100, 100, 200, 200, 0, -90); - efl_gfx_path_append_line_to(txtpath, 300, 350); + efl_gfx_path_append_arc(txtpath, 0, 0, 100, 100, 0, -90); + efl_gfx_path_append_line_to(txtpath, 100, 150); + //efl_gfx_path_append_move_to(txtpath, 200, 300); //efl_gfx_path_append_line_to(txtpath, 300, 350); @@ -43,7 +44,8 @@ elm_main(int argc, char *argv[]) //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_ui_textpath_autofit_set(txtpath, EINA_FALSE); + efl_gfx_geometry_set(txtpath, 120, 120, 200, 200); efl_gfx_visible_set(txtpath, EINA_TRUE); //Geometry set/get: does not work!!! @@ -54,7 +56,7 @@ elm_main(int argc, char *argv[]) printf("text by efl: %s\n", efl_text_get(txtpath)); printf("text by elm: %s\n", elm_object_text_get(txtpath)); - elm_win_resize_object_add(win, txtpath); + //elm_win_resize_object_add(win, txtpath); evas_object_resize(win, WIDTH, HEIGHT); evas_object_show(win); elm_run(); diff --git a/src/bin/elementary/test_scroller.c b/src/bin/elementary/test_scroller.c index 826f06481e..4e0558342e 100644 --- a/src/bin/elementary/test_scroller.c +++ b/src/bin/elementary/test_scroller.c @@ -564,7 +564,7 @@ test_scroller2(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, 0.0); /* { */ - for (i = 0; i < 3; i++) + /*for (i = 0; i < 3; i++) { bt = elm_button_add(win); elm_object_text_set(bt, "Vertical"); @@ -575,19 +575,19 @@ test_scroller2(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event evas_object_show(bt); if (i == 0) bounce->it1 = bt; - } + }*/ /* } */ /* { */ - sc = elm_scroller_add(win); + /*sc = elm_scroller_add(win); evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(sc, EVAS_HINT_FILL, 0.5); elm_scroller_bounce_set(sc, EINA_TRUE, EINA_FALSE); elm_scroller_content_min_limit(sc, 0, 1); elm_box_pack_end(bx, sc); - evas_object_show(sc); + evas_object_show(sc);*/ - bx2 = elm_box_add(win); + /*bx2 = elm_box_add(win); elm_box_horizontal_set(bx2, EINA_TRUE); for (i = 0; i < 10; i++) @@ -600,11 +600,11 @@ test_scroller2(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event } elm_object_content_set(sc, bx2); - evas_object_show(bx2); + evas_object_show(bx2);*/ /* } */ /* { */ - for (i = 0; i < 3; i++) + /*for (i = 0; i < 3; i++) { bt = elm_button_add(win); elm_object_text_set(bt, "Vertical"); @@ -613,11 +613,11 @@ test_scroller2(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0.5); elm_box_pack_end(bx, bt); evas_object_show(bt); - } + }*/ /* } */ /* { */ - tb = elm_table_add(win); + /*tb = elm_table_add(win); evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_box_pack_end(bx, tb); @@ -631,9 +631,9 @@ test_scroller2(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(sc, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_table_pack(tb, sc, 0, 0, 1, 1); - evas_object_show(sc); + evas_object_show(sc);*/ - tb2 = elm_table_add(win); + /*tb2 = elm_table_add(win); for (j = 0; j < 16; j++) { @@ -648,10 +648,10 @@ test_scroller2(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event } elm_object_content_set(sc, tb2); - evas_object_show(tb2); + evas_object_show(tb2);*/ /* } */ - for (i = 0; i < 24; i++) + for (i = 0; i < 15; i++) { bt = elm_button_add(win); elm_object_text_set(bt, "Vertical"); @@ -663,6 +663,26 @@ test_scroller2(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event if (i == 23) bounce->it2 = bt; } + Evas_Object *txtpath = efl_add(EFL_UI_TEXTPATH_CLASS, win); + efl_ui_textpath_autofit_set(txtpath, EINA_TRUE); + + efl_text_set(txtpath, "abcdef and more you can see from this test"); + //efl_ui_textpath_circle_set(txtpath, 200, 200, 100, 0); + //efl_gfx_path_append_circle(txtpath, 200, 200, 100); + + efl_gfx_path_append_arc(txtpath, 0, 0, 100, 100, 0, -90); + efl_gfx_path_append_line_to(txtpath, 0, 0); + //efl_gfx_path_append_move_to(txtpath, 200, 300); + //efl_gfx_path_append_line_to(txtpath, 300, 350); + + //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); + elm_box_pack_end(bx, txtpath); + sc = elm_scroller_add(win); evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -672,20 +692,22 @@ test_scroller2(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event evas_object_show(bx); evas_object_show(sc); + printf("%s %d: win: %p, scroller: %p, box: %p, textpath: %p\n", __func__, __LINE__, win, sc, bx, txtpath); + bounce->scroller = sc; - evas_object_resize(win, 320, 480); + evas_object_resize(win, 320, 300); evas_object_show(win); evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _scroll2_del_cb, bounce); - if (getenv("ELM_TEST_AUTOBOUNCE")) + /*if (getenv("ELM_TEST_AUTOBOUNCE")) { bounce->autobounce = 1; bounce->bounce_max = atoi(getenv("ELM_TEST_AUTOBOUNCE")); bounce->timer = ecore_timer_add(0.5, _bounce_cb, bounce); _bounce_cb(bounce); - } + }*/ } static Ecore_Timer *_timer = NULL; diff --git a/src/lib/elementary/efl_ui_textpath.c b/src/lib/elementary/efl_ui_textpath.c index 4e076b01cf..52f4f4471f 100644 --- a/src/lib/elementary/efl_ui_textpath.c +++ b/src/lib/elementary/efl_ui_textpath.c @@ -117,7 +117,7 @@ _textpath_ellipsis_set(Efl_Ui_Textpath_Data *pd, Eina_Bool enabled) static void _segment_draw(Efl_Ui_Textpath_Data *pd, int slice_no, double slice_len, int w1, int w2, int cmp, Evas_Map *map, Eina_Bool final, Eina_Bezier bezier) { - ERR("In: slice_no: %d, slice_len: %.2f, from: %d, to: %d, cur mp: %d", slice_no, slice_len, w1, w1, cmp); + ERR("In: slice_no: %d, slice_len: %.2f, from: %d, to: %d, cur mp: %d", slice_no, slice_len, w1, w2, cmp); int x = 0, y = 0, w = 0, h = 0; int i, len, seg_len; @@ -132,11 +132,19 @@ _segment_draw(Efl_Ui_Textpath_Data *pd, int slice_no, double slice_len, int w1, efl_gfx_size_get(pd->text_obj, &w, &h); seg_len = eina_bezier_length_get(&bezier); //dt = 1.0 / (double) pd->slice; - dt = len / (seg_len * (double) slice_no); + if (pd->autofit) + { + dt = len / (seg_len * (double) slice_no); + } + else + { + dt = 1.0 / (double) slice_no; + } //dist = ((double) w / (double) pd->slice); //dist = ((double) w / (double) pd->slice); //dist = slice_len; dist = len / (double)slice_no; + ERR("slice_no: %d, distance: %.1f", slice_no, dist); //Compute Beziers. //length = eina_bezier_length_get(&bezier); @@ -214,7 +222,6 @@ _segment_draw(Efl_Ui_Textpath_Data *pd, int slice_no, double slice_len, int w1, } } - static void _text_on_line_draw(Efl_Ui_Textpath_Data *pd, int w1, int w2, int cmp, Evas_Map *map, Efl_Ui_Textpath_Line line) { @@ -223,26 +230,36 @@ _text_on_line_draw(Efl_Ui_Textpath_Data *pd, int w1, int w2, int cmp, Evas_Map * y1 = line.start.y; x2 = line.end.x; y2 = line.end.y; + ERR("line: %.1f %.1f - %.1f %.1f", x1, y1, x2, y2); //test: line - Eo *ln = evas_object_line_add(evas_object_evas_get(pd->text_obj)); + /*Eo *ln = evas_object_line_add(evas_object_evas_get(pd->text_obj)); efl_gfx_size_set(ln, 500, 500); efl_gfx_color_set(ln, 255, 255, 0, 255); efl_gfx_visible_set(ln, EINA_TRUE); - evas_object_line_xy_set(ln, x1, y1, x2, y2); + evas_object_line_xy_set(ln, x1, y1, x2, y2);*/ // + + double line_len = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)); + double len = w2 - w1; + if (line_len > len) + { + x2 = x1 + len * (x2 - x1) / line_len; + y2 = y1 + len * (y2 - y1) / line_len; + ERR("new: %.1f %.1f - %.1f %.1f", 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); ERR("line geo: %.1f %.1f :: %.1f %.1f, area: %d %d, cmp: %d", x1, y1, x2, y2, w1, w2, cmp); - double len, sina, cosa; + double 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, cmp + 3, x1 - h * sina, y1 + h * cosa, 0); evas_map_point_coord_set(map, cmp + 2, x2 - h * sina, y2 + h * cosa, 0); evas_map_point_coord_set(map, cmp + 1, x2 + h * sina, y2 - h * cosa, 0); @@ -291,14 +308,20 @@ _text_draw(Eo *obj, Efl_Ui_Textpath_Data *pd) int total_slice; int cur_map_point = 0; int drawn_slice; - Evas *e; - Evas_Object *proxy; efl_gfx_size_get(pd->text_obj, &w, &h); + if (pd->autofit) + { + remained_w = w; + } + else + { + remained_w = pd->total_length; + } slice_unit = (double)pd->slice_no / pd->total_length; + slice_len = 1.0 / slice_unit; total_slice = w / slice_len + 1; - remained_w = w; int map_no = _map_point_calc(pd); ERR("map poins no: %d", map_no); @@ -309,9 +332,19 @@ _text_draw(Eo *obj, Efl_Ui_Textpath_Data *pd) EINA_INLIST_FOREACH(pd->segments, seg) { int len = seg->length; + if (!pd->autofit) + { + len = (double)seg->length * w / (double)pd->total_length; + ERR("len: %d", len); + } + ERR("w: %d, total_length: %d, seg length: %d, len: %d", w, pd->total_length, seg->length, len); //w1 = w - remained_w; + if (remained_w <= 0) + break; w2 = w1 + len; - remained_w -= len; + if (w2 > w) + w2 = w; + //remained_w -= len; if (seg->type == EFL_GFX_PATH_COMMAND_TYPE_LINE_TO) { drawn_slice += 1; @@ -330,15 +363,16 @@ _text_draw(Eo *obj, Efl_Ui_Textpath_Data *pd) cur_map_point += slice_no * 4; } w1 = w2; + remained_w -= len; } evas_object_map_enable_set(pd->text_obj, EINA_TRUE); evas_object_map_set(pd->text_obj, map); - //evas_map_free(map); + evas_map_free(map); } static void -_path_data_get(Eo *obj, Efl_Ui_Textpath_Data *pd) +_path_data_get(Eo *obj, Efl_Ui_Textpath_Data *pd, Eina_Bool set_min) { ERR("In"); @@ -352,12 +386,17 @@ _path_data_get(Eo *obj, Efl_Ui_Textpath_Data *pd) pd->segments = eina_inlist_remove(pd->segments, EINA_INLIST_GET(seg)); free(seg); } + + Evas_Coord x, y; + efl_gfx_position_get(obj, &x, &y); + pd->total_length = 0; efl_gfx_path_get(obj, &cmd, &points); if (cmd) { ERR("cmd exist"); int pos = -1; + Eina_Rectangle *rect = eina_rectangle_new(0, 0, 0, 0); while (*cmd != EFL_GFX_PATH_COMMAND_TYPE_END) { double px0, py0, ctrl_x0, ctrl_y0, ctrl_x1, ctrl_y1, px1, py1; @@ -365,24 +404,24 @@ _path_data_get(Eo *obj, Efl_Ui_Textpath_Data *pd) if (*cmd == EFL_GFX_PATH_COMMAND_TYPE_MOVE_TO) { pos++; - px0 = points[pos]; + px0 = points[pos] + x; pos++; - py0 = points[pos]; + py0 = points[pos] + y; } else if (*cmd == EFL_GFX_PATH_COMMAND_TYPE_CUBIC_TO) { pos++; - ctrl_x0 = points[pos]; + ctrl_x0 = points[pos] + x; pos++; - ctrl_y0 = points[pos]; + ctrl_y0 = points[pos] + y; pos++; - ctrl_x1 = points[pos]; + ctrl_x1 = points[pos] + x; pos++; - ctrl_y1 = points[pos]; + ctrl_y1 = points[pos] + y; pos++; - px1 = points[pos]; + px1 = points[pos] + x; pos++; - py1 = points[pos]; + py1 = points[pos] + y; Eina_Bezier bz; eina_bezier_values_set(&bz, px0, py0, ctrl_x0, ctrl_y0, ctrl_x1, ctrl_y1, px1, py1); @@ -403,13 +442,19 @@ _path_data_get(Eo *obj, Efl_Ui_Textpath_Data *pd) //move points px0 = px1; py0 = py1; + + double bx, by, bw, bh; + eina_bezier_bounds_get(&bz, &bx, &by, &bw, &bh); + Eina_Rectangle *brect = eina_rectangle_new(bx, by, bw, bh); + eina_rectangle_union(rect, brect); + eina_rectangle_free(brect); } else if (*cmd == EFL_GFX_PATH_COMMAND_TYPE_LINE_TO) { pos++; - px1 = points[pos]; + px1 = points[pos] + x; pos++; - py1 = points[pos]; + py1 = points[pos] + y; ERR("line: %.1f %.1f :: %.1f %.1f", px0, py0, px1, py1); Efl_Ui_Textpath_Segment *seg = malloc(sizeof(Efl_Ui_Textpath_Segment)); @@ -428,9 +473,18 @@ _path_data_get(Eo *obj, Efl_Ui_Textpath_Data *pd) pd->segments = eina_inlist_append(pd->segments, EINA_INLIST_GET(seg)); pd->total_length += seg->length; + Eina_Rectangle *lrect = eina_rectangle_new(px0, py0, px1 - px0, py1 - py0); + eina_rectangle_union(rect, lrect); + eina_rectangle_free(lrect); } cmd++; } + if (set_min) + { + evas_object_size_hint_min_set(obj, rect->w, rect->h); + ERR("set min size: %d %d %d %d", rect->x, rect->y, rect->w, rect->h); + } + eina_rectangle_free(rect); } } @@ -583,7 +637,7 @@ _circle_draw(Evas_Object *eo, Efl_Ui_Textpath_Data *pd) evas_map_free(map); //debug - x = pd->circle.x; + /*x = pd->circle.x; y = pd->circle.y; double r = pd->circle.radius; Eo *line = evas_object_line_add(e); @@ -594,7 +648,7 @@ _circle_draw(Evas_Object *eo, Efl_Ui_Textpath_Data *pd) line = evas_object_line_add(e); efl_gfx_color_set(line, 100, 100, 0, 100); efl_gfx_visible_set(line, EINA_TRUE); - evas_object_line_xy_set(line, x - r, y, x + r, y); + evas_object_line_xy_set(line, x - r, y, x + r, y);*/ // } @@ -641,7 +695,7 @@ _path_changed_cb(void *data, const Efl_Event *event) ERR("Path changed"); EFL_UI_TEXTPATH_DATA_GET(data, sd); - _path_data_get(data, sd); + _path_data_get(data, sd, EINA_TRUE); } //exposed API @@ -695,12 +749,12 @@ _textpath_text_set_internal(Eo *obj, Efl_Ui_Textpath_Data *pd, const char *part, //Test - Evas_Object *t = elm_layout_add(obj); + /*Evas_Object *t = elm_layout_add(obj); elm_layout_theme_set(t, "textpath", "base", elm_widget_style_get(obj)); elm_object_text_set(t, text); evas_object_move(t, 50, 50); evas_object_resize(t, tb_w, tb_h); - evas_object_show(t); + evas_object_show(t);*/ ///// return int_ret; } @@ -768,10 +822,10 @@ _efl_ui_textpath_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Textpath_Data *priv) evas_object_smart_member_add(priv->text_obj, obj); elm_widget_sub_object_add(obj, priv->text_obj); - priv->clip = evas_object_rectangle_add(obj); - evas_object_color_set(priv->clip, 255, 255, 0, 100); - evas_object_show(priv->clip); - evas_object_clip_set(priv->text_obj, priv->clip); + //priv->clip = evas_object_rectangle_add(obj); + //evas_object_color_set(priv->clip, 255, 255, 0, 100); + //evas_object_show(priv->clip); + //evas_object_clip_set(priv->text_obj, priv->clip); efl_event_callback_add(obj, EFL_GFX_PATH_EVENT_CHANGED, _path_changed_cb, obj); } @@ -799,9 +853,17 @@ _efl_ui_textpath_efl_object_constructor(Eo *obj, Efl_Ui_Textpath_Data *pd) EOLIAN static void _efl_ui_textpath_efl_object_destructor(Eo *obj, Efl_Ui_Textpath_Data *pd) { + Efl_Ui_Textpath_Segment *seg; + if (pd->content) evas_object_del(pd->content); if (pd->text) free(pd->text); if (pd->text_obj) evas_object_del(pd->text_obj); + EINA_INLIST_FREE(pd->segments, seg) + { + pd->segments = eina_inlist_remove(pd->segments, EINA_INLIST_GET(seg)); + free(seg); + } + efl_destructor(efl_super(obj, MY_CLASS)); } @@ -836,14 +898,17 @@ _efl_ui_textpath_elm_widget_theme_apply(Eo *obj, Efl_Ui_Textpath_Data *pd) EOLIAN static void _efl_ui_textpath_efl_gfx_position_set(Eo *obj, Efl_Ui_Textpath_Data *pd, Evas_Coord x, Evas_Coord y) { - ERR("set position: textpath: %d %d", x, y); + ERR("obj: %p,text_obj: %p, set position: textpath: %d %d", obj, pd->text_obj, x, y); efl_gfx_position_set(efl_super(obj, MY_CLASS), x, y); if (pd->text_obj) { - ERR("move text_obj to: %d %d", x, y); - efl_gfx_position_set(pd->text_obj, x, y); + //ERR("move text_obj to: %d %d", x, y); + //efl_gfx_position_set(pd->text_obj, x, y); } - efl_gfx_position_set(pd->clip, x, y); + //efl_gfx_position_set(pd->clip, x, y); + + _path_data_get(obj, pd, EINA_FALSE); + _text_draw(obj, pd); } EOLIAN static void @@ -852,7 +917,7 @@ _efl_ui_textpath_efl_gfx_size_set(Eo *obj, Efl_Ui_Textpath_Data *pd, Evas_Coord ERR("size set: %d %d", w, h); efl_gfx_size_set(efl_super(obj, MY_CLASS), w, h); /// - efl_gfx_size_set(pd->clip, w, h); + //efl_gfx_size_set(pd->clip, w, h); } #if 0 |