# HG changeset patch # User Thinker K.F. Li # Date 1283144869 -28800 # Node ID 61c217f8cec8d0f06f42535a7eba28d97d5a8246 # Parent 72b5bb88979f2dadc1ef1f2d90246ee5e3b1e51f Fix bug of transformation from user space to image space. diff -r 72b5bb88979f -r 61c217f8cec8 nodejs/coord.cc --- a/nodejs/coord.cc Mon Aug 30 08:57:31 2010 +0800 +++ b/nodejs/coord.cc Mon Aug 30 13:07:49 2010 +0800 @@ -212,6 +212,7 @@ shape_hdl = (Persistent *)mb_prop_get(&shape->obj.props, PROP_JSOBJ); shape_hdl->ClearWeak(); + rdman_shape_changed(rdman, shape); } static void diff -r 72b5bb88979f -r 61c217f8cec8 nodejs/mbfly_njs.cc --- a/nodejs/mbfly_njs.cc Mon Aug 30 08:57:31 2010 +0800 +++ b/nodejs/mbfly_njs.cc Mon Aug 30 13:07:49 2010 +0800 @@ -26,6 +26,7 @@ *err = "Can not allocate a redraw_man_t"; return NULL; } + rdman_coord_changed(rdman, coord); return coord; } diff -r 72b5bb88979f -r 61c217f8cec8 nodejs/testcase.js --- a/nodejs/testcase.js Mon Aug 30 08:57:31 2010 +0800 +++ b/nodejs/testcase.js Mon Aug 30 13:07:49 2010 +0800 @@ -22,8 +22,9 @@ var ldr = mbfly.img_ldr_new("."); var img_data = ldr.load("sample.png"); var paint = mb_rt.paint_image_new(img_data); +var img_coord = mb_rt.coord_new(root); paint.fill(img); -root.add_shape(img); +img_coord.add_shape(img); /* test linear paint and rectangle */ var rect = mb_rt.rect_new(100, 100, 50, 50, 10, 10); @@ -143,6 +144,23 @@ mb_rt.flush(); }); +var resize_sw = 0; +setInterval(function() { + var sz; + + resize_sw++; + + sz = (resize_sw % 20) - 10; + if(sz < 0) + sz = -sz; + sz = 2 - sz / 10; + + img_coord[0] = sz; + img_coord[4] = sz; + mb_rt.redraw_changed(); + mb_rt.flush(); + }, 50); + var kbobserver; /* Keyboard event */ kbobserver = mb_rt.kbevents.add_event_observer(6, function(evt) { diff -r 72b5bb88979f -r 61c217f8cec8 src/shape_image.c --- a/src/shape_image.c Mon Aug 30 08:57:31 2010 +0800 +++ b/src/shape_image.c Mon Aug 30 13:07:49 2010 +0800 @@ -104,6 +104,7 @@ paint_t *paint; co_aix (*poses)[2]; co_aix img_matrix[6]; + co_aix rev_matrix[6]; co_aix x_factor, y_factor; int img_w, img_h; int i; @@ -130,26 +131,25 @@ paint_image_get_size(paint, &img_w, &img_h); - /* Transformation from user space to image space */ + /* Transformation from image space to user space */ img_matrix[0] = (poses[1][0] - poses[0][0]) / img->w; - img_matrix[1] = (poses[1][1] - poses[0][1]) / img->w; - img_matrix[2] = -poses[0][0]; - img_matrix[3] = (poses[3][0] - poses[0][0]) / img->h; + img_matrix[1] = (poses[3][0] - poses[3][0]) / img->h; + img_matrix[2] = poses[0][0]; + img_matrix[3] = (poses[1][1] - poses[0][1]) / img->w; img_matrix[4] = (poses[3][1] - poses[0][1]) / img->h; - img_matrix[5] = -poses[0][1]; + img_matrix[5] = poses[0][1]; if(img->w != img_w || img->h != img_h) { /* Resize image */ - x_factor = img_w / img->w; + x_factor = img->w / img_w; img_matrix[0] *= x_factor; img_matrix[1] *= x_factor; - img_matrix[2] *= x_factor; - y_factor = img_h / img->h; + y_factor = img->h / img_h; img_matrix[3] *= y_factor; img_matrix[4] *= y_factor; - img_matrix[5] *= y_factor; } - paint_image_set_matrix(sh_get_fill(shape), img_matrix); + compute_reverse(img_matrix, rev_matrix); + paint_image_set_matrix(sh_get_fill(shape), rev_matrix); } /*! \brief Draw image for an image shape.