comparison src/event.c @ 439:254854ed479c

Fix bug of _find_shape_in_pos(). It can not find a correct shape for a specified point. Since it call _shape_pos_is_in_cairo() directly, cairo_new_path() is not called to clear path after each calling for a shape. So, old path would interference later testing. It should call _shape_pos_is_in() instead of _shape_pos_is_in_cairo().
author Thinker K.F. Li <thinker@branda.to>
date Thu, 30 Jul 2009 15:42:47 +0800
parents 1ee11bab38fa
children 16116d84bc5e
comparison
equal deleted inserted replaced
438:1ee11bab38fa 439:254854ed479c
7 #include <cairo.h> 7 #include <cairo.h>
8 #include "mb_types.h" 8 #include "mb_types.h"
9 #include "mb_redraw_man.h" 9 #include "mb_redraw_man.h"
10 #include "mb_shapes.h" 10 #include "mb_shapes.h"
11 #endif 11 #endif
12 #include "../config.h"
12 13
13 #define OK 0 14 #define OK 0
14 #define ERR -1 15 #define ERR -1
15 #define FALSE 0 16 #define FALSE 0
16 #define TRUE 1 17 #define TRUE 1
154 MBO_COORD, 155 MBO_COORD,
155 MBO_SHAPES=0x1000, 156 MBO_SHAPES=0x1000,
156 MBO_PATH, 157 MBO_PATH,
157 MBO_TEXT, 158 MBO_TEXT,
158 MBO_RECT, 159 MBO_RECT,
159 MBO_IMAGE 160 MBO_IMAGE,
161 MBO_STEXT
160 }; 162 };
161 #define MBO_TYPE(x) (((mb_obj_t *)(x))->obj_type) 163 #define MBO_TYPE(x) (((mb_obj_t *)(x))->obj_type)
162 #define IS_MBO_SHAPES(x) (((mb_obj_t *)(x))->obj_type & MBO_SHAPES) 164 #define IS_MBO_SHAPES(x) (((mb_obj_t *)(x))->obj_type & MBO_SHAPES)
163 #define sh_get_geo(x) ((x)->geo) 165 #define sh_get_geo(x) ((x)->geo)
164 static int sh_pos_is_in(shape_t *shape, co_aix x, co_aix y) { 166 static int sh_pos_is_in(shape_t *shape, co_aix x, co_aix y) {
525 } 527 }
526 528
527 return OK; 529 return OK;
528 } 530 }
529 531
532 /*! \brief Draw path of a shape.
533 *
534 * \note This function should be merged with what is in redraw_man.c.
535 */
530 static void draw_shape_path(shape_t *shape, cairo_t *cr) { 536 static void draw_shape_path(shape_t *shape, cairo_t *cr) {
531 switch(MBO_TYPE(shape)) { 537 switch(MBO_TYPE(shape)) {
532 case MBO_PATH: 538 case MBO_PATH:
533 sh_path_draw(shape, cr); 539 sh_path_draw(shape, cr);
534 break; 540 break;
541 #ifdef SH_TEXT
535 case MBO_TEXT: 542 case MBO_TEXT:
536 sh_text_draw(shape, cr); 543 sh_text_draw(shape, cr);
537 break; 544 break;
545 #endif
538 case MBO_RECT: 546 case MBO_RECT:
539 sh_rect_draw(shape, cr); 547 sh_rect_draw(shape, cr);
540 break; 548 break;
541 case MBO_IMAGE: 549 case MBO_IMAGE:
542 sh_image_draw(shape, cr); 550 sh_image_draw(shape, cr);
543 break; 551 break;
544 } 552 #ifdef SH_STEXT
545 } 553 case MBO_STEXT:
546 554 sh_stext_draw(shape, cr);
555 break;
556 #endif
557 }
558 }
559
560 /*! \brief Implement exactly point testing with Cairo.
561 *
562 * \note This function should not be called directly. Call
563 * _shape_pos_is_in() insteaded.
564 */
547 static int _shape_pos_is_in_cairo(shape_t *shape, co_aix x, co_aix y, 565 static int _shape_pos_is_in_cairo(shape_t *shape, co_aix x, co_aix y,
548 int *in_stroke, cairo_t *cr) { 566 int *in_stroke, cairo_t *cr) {
549 draw_shape_path(shape, cr); 567 draw_shape_path(shape, cr);
550 if(shape->fill) { 568 if(shape->fill) {
551 if(cairo_in_fill(cr, x, y)) { 569 if(cairo_in_fill(cr, x, y)) {
592 cr = rdman_get_cr(rdman); 610 cr = rdman_get_cr(rdman);
593 for(i = rdman_shape_gl_len(rdman) - 1; i >= 0; i--) { 611 for(i = rdman_shape_gl_len(rdman) - 1; i >= 0; i--) {
594 shape = rdman_get_shape_gl(rdman, i); 612 shape = rdman_get_shape_gl(rdman, i);
595 if(sh_get_flags(shape, GEF_HIDDEN)) 613 if(sh_get_flags(shape, GEF_HIDDEN))
596 continue; 614 continue;
597 r = _shape_pos_is_in_cairo(shape, x, y, in_stroke, cr); 615 r = _shape_pos_is_in(shape, x, y, in_stroke, cr);
598 if(r) 616 if(r)
599 return shape; 617 return shape;
600 } 618 }
601 619
602 return NULL; 620 return NULL;