From: Ji-hoon Lee Date: Tue, 1 Nov 2016 11:15:51 +0000 (+0900) Subject: Added support for png files that contains nine patch information X-Git-Tag: accepted/tizen/3.0/common/20161114.082821~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F41%2F95441%2F1;p=platform%2Fcore%2Fuifw%2Flibscl-ui.git Added support for png files that contains nine patch information Change-Id: I824fd2c0163f99e6654489770079e684174ed92c --- diff --git a/scl/gwes/efl/sclgraphics-efl.cpp b/scl/gwes/efl/sclgraphics-efl.cpp index 8fee354..9da68ab 100644 --- a/scl/gwes/efl/sclgraphics-efl.cpp +++ b/scl/gwes/efl/sclgraphics-efl.cpp @@ -48,12 +48,12 @@ sclint hash_string(const sclchar* str) { #endif using namespace scl; -int iNumCreate = 0; - extern void mouse_press(void *data, Evas *e, Evas_Object *object, void *event_info); extern void mouse_release(void *data, Evas *e, Evas_Object *object, void *event_info); extern void mouse_move(void *data, Evas *e, Evas_Object *object, void *event_info); +static std::map _nine_patch_map; + /** * Constructor */ @@ -135,6 +135,61 @@ Evas_Object* extract_partimage_from_fullimage( return image_ob; } +static sclboolean check_nine_patch_png_file(const char *image_path) +{ + sclboolean found = FALSE; + for (sclint loop = strlen(image_path);!found && loop > 0;loop--) { + if (image_path[loop] == '.') { + found = TRUE; + if (loop >= 2) { // for checking prefix ".#" + if (strcasecmp(image_path + loop - 2, ".#.png") == 0) { + return TRUE; + } + } + } + } + return FALSE; +} + +SclNinePatchInfo get_nine_patch_info_from_png_file(Evas_Object *image_data, sclint w, sclint h) +{ + /* FIXME : Assuming we're dealing with 32bit image, need to check if there's any other cases */ + SclNinePatchInfo ret = {0}; + unsigned int *data = (unsigned int*)evas_object_image_data_get(image_data, EINA_FALSE); + if (data) { + int x, y; + sclboolean found; + found = FALSE; + for (x = 0;x < w && !found;x++) { + if (data[x] > 0) { + found = TRUE; + ret.left = x; + } + } + found = FALSE; + for (x = w - 1;x >= 0 && !found;x--) { + if (data[x] > 0) { + found = TRUE; + ret.right = w - (x + 1); + } + } + found = FALSE; + for (y = 0;y < h && !found;y++) { + if (data[y * w] > 0) { + found = TRUE; + ret.top = y; + } + } + found = FALSE; + for (y = h - 1;y >= 0 && !found;y--) { + if (data[y * w] > 0) { + found = TRUE; + ret.bottom = h - (y + 1); + } + } + } + return ret; +} extern sclint magnifierx, magnifiery; void @@ -252,7 +307,19 @@ CSCLGraphicsImplEfl::draw_image(sclwindow window, const scldrawctx draw_ctx, scl int image_height = 0; evas_object_image_file_set(image_object, image_path, NULL); evas_object_image_size_get(image_object, &image_width, &image_height); - if (cachedinfo) { + + sclboolean is_nine_patch_png = check_nine_patch_png_file(image_path); + if (is_nine_patch_png) { + std::map::iterator it = _nine_patch_map.find(image_path); + if (it != _nine_patch_map.end()) { + evas_object_image_border_set(image_object, + (*it).second.left, (*it).second.right, (*it).second.top, (*it).second.bottom); + } else { + SclNinePatchInfo info = get_nine_patch_info_from_png_file(image_object, image_width, image_height); + evas_object_image_border_set(image_object, info.left, info.right, info.top, info.bottom); + _nine_patch_map[std::string(image_path)] = info; + } + } else if (cachedinfo) { evas_object_image_border_set(image_object, cachedinfo->nine_patch_left, cachedinfo->nine_patch_right, @@ -321,7 +388,11 @@ CSCLGraphicsImplEfl::draw_image(sclwindow window, const scldrawctx draw_ctx, scl } else { evas_object_move(image_object, dest_x, dest_y); if (dest_width > 0 && dest_height > 0) { - evas_object_image_fill_set(image_object, 0, 0, dest_width, dest_height); + if (is_nine_patch_png) { + evas_object_image_fill_set(image_object, -1, -1, dest_width + 2, dest_height + 2); + } else { + evas_object_image_fill_set(image_object, 0, 0, dest_width, dest_height); + } evas_object_resize(image_object, dest_width, dest_height); } } @@ -462,7 +533,6 @@ CSCLGraphicsImplEfl::destroy_font(sclfont font) { } - /** * Draws the given text on cairo-surface */