annotate src/event.c @ 245:81458bb0bf34

Remove useless rdman_redraw_*().
author Thinker K.F. Li <thinker@branda.to>
date Wed, 31 Dec 2008 23:57:12 +0800
parents 104d83378582
children bd8ea44b421e
rev   line source
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
1 /*! \file
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
2 * \brief Convenience functions for event relative work.
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
3 */
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include <stdio.h>
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include <stdlib.h>
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
6 #ifndef UNITTEST
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 #include <cairo.h>
186
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
8 #include "mb_types.h"
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
9 #include "mb_redraw_man.h"
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
10 #include "mb_shapes.h"
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
11 #endif
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 #define OK 0
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 #define ERR -1
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
15 #define FALSE 0
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
16 #define TRUE 1
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17
139
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 75
diff changeset
18 #define ARRAY_EXT_SZ 64
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 75
diff changeset
19
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
20 #define ASSERT(x)
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
22 #ifdef UNITTEST
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
23 /* ============================================================ */
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
24
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
25 typedef struct shape shape_t;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
26
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
27 typedef struct cairo cairo_t;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
28 struct cairo {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
29 shape_t *drawed;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
30 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
31 #define cairo_in_fill(cr, x, y) 0
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
32 #define cairo_in_stroke(cr, x, y) 0
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
33 #define cairo_new_path(cr)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
34 #define cairo_get_target(cr) NULL
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
35 #define cairo_create(target) NULL
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
36 #define cairo_destroy(cr)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
37 #define cairo_clip(cr)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
38 #define cairo_fill(cr)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
39 #define cairo_image_surface_get_data(cr) NULL
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
40 #define cairo_image_surface_get_stride(cr) 1
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
41
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
42 struct cairo_surface {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
43 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
44 typedef struct cairo_surface cairo_surface_t;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
45 #define cairo_image_surface_get_width(surface) 0
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
46 #define cairo_image_surface_get_height(surface) 0
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
47 #define cairo_image_surface_create(surface, w, h) NULL
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
48 #define cairo_surface_destroy(surface)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
49
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
50
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
51 typedef float co_aix;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
52
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
53 typedef struct _area area_t;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
54 struct _area {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
55 co_aix x, y;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
56 co_aix w, h;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
57 };
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
58 #define range_overlay(as, aw, bs, bw) \
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
59 (((bs) - (as)) <= (aw) || ((as) - (bs)) <= (bw))
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
60 #define areas_are_overlay(a1, a2) \
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
61 (range_overlay((a1)->x, (a1)->w, \
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
62 (a2)->x, (a2)->w) && \
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
63 range_overlay((a1)->y, (a1)->h, \
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
64 (a2)->y, (a2)->h))
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
65
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
66 struct mb_obj {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
67 int obj_type;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
68 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
69 typedef struct mb_obj mb_obj_t;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
70
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
71 #define GEF_OV_DRAW 0x1
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
72 #define GEF_HIDDEN 0x2
158
c1cdd3fcd28f Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents: 139
diff changeset
73
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
74 struct shape {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
75 mb_obj_t obj;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
76
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
77 area_t area;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
78
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
79 void *fill, *stroke;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
80 struct shape *sibling;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
81 int flags;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
82
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
83 int num_points;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
84 co_aix points[32][2];
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
85 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
86 enum { MBO_DUMMY,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
87 MBO_COORD,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
88 MBO_SHAPES=0x1000,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
89 MBO_PATH,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
90 MBO_TEXT,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
91 MBO_RECT
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
92 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
93 #define MBO_TYPE(x) (((mb_obj_t *)(x))->obj_type)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
94 #define IS_MBO_SHAPES(x) (((mb_obj_t *)(x))->obj_type & MBO_SHAPES)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
95 #define sh_get_geo(x) ((x)->geo)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
96 static int sh_pos_is_in(shape_t *shape, co_aix x, co_aix y) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
97 int i;
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
99 for(i = 0; i < shape->num_points; i++)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
100 if(shape->points[i][0] == x && shape->points[i][1] == y)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
101 return TRUE;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
102 return FALSE;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
103 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
104 #define sh_get_flags(shape, mask) ((shape)->flags & mask)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
105 #define sh_set_flags(shape, mask) do { (shape)->flags |= mask; } while(0)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
106 #define sh_clear_flags(shape, mask) do { (shape)->flags &= ~(mask); } while(0)
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
107 #define sh_get_area(shape) (&(shape)->area)
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
108
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
109 typedef struct coord coord_t;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
110 struct coord {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
111 mb_obj_t obj;
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
112
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
113 area_t area;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
114 int flags;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
115 coord_t *parent;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
116 coord_t *children;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
117 coord_t *sibling;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
118 shape_t *shapes;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
119 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
120
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
121 #define COF_SKIP 0x1
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
122
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
123 #define coord_get_area(coord) (&(coord)->area)
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
124 #define FOR_COORD_SHAPES(coord, shape) \
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
125 for(shape = (coord)->shapes; \
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
126 shape != NULL; \
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
127 shape = (shape)->sibling)
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
128 #define FOR_COORDS_PREORDER(root, last) \
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
129 for(last = root; \
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
130 last != NULL; \
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
131 last = preorder_coord_subtree(root, last))
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
132
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
133 static
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
134 coord_t *preorder_coord_subtree(coord_t *root, coord_t *last) {
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
135 if(last->children)
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
136 return last->children;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
137 while(last->sibling == NULL)
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
138 last = last->parent;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
139 return last->sibling;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
140 }
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
141
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
142 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
143 coord_t *postorder_coord_subtree(coord_t *root, coord_t *last) {
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
144 coord_t *cur;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
145
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
146 if(last != NULL) {
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
147 if(last->sibling == NULL) {
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
148 cur = last->parent;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
149 return cur;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
150 }
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
151 cur = last->sibling;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
152 }
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
153
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
154 cur = last;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
155 while(cur->children) {
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
156 cur = cur->children;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
157 }
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
158 return cur;
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
159 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
160
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
161 #define sh_path_draw(path, cr)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
162 #define sh_text_draw(path, cr)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
163 #define sh_rect_draw(path, cr)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
164
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
165
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
166 struct redraw_man {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
167 cairo_t *cr;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
168 int shape_gl_sz;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
169 shape_t *shape_gl[32];
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
170 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
171 typedef struct redraw_man redraw_man_t;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
172 #define rdman_get_cr(rdman) ((rdman)->cr)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
173 #define rdman_get_gen_geos(rdman) (&(rdman)->gen_geos)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
174 #define rdman_force_clean(rdman) OK
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
175 #define rdman_geos(rdman, geo) NULL
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
176 #define rdman_clear_shape_gl(rdman) \
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
177 do {(rdman)->shape_gl_sz = 0; } while(0)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
178 static int rdman_add_shape_gl(redraw_man_t *rdman, shape_t *shape) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
179 (rdman)->shape_gl[(rdman)->shape_gl_sz++] = shape;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
180 return OK;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
181 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
182 #define rdman_get_shape_gl(rdman, idx) \
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
183 (rdman)->shape_gl[idx]
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
184 #define rdman_shape_gl_len(rdman) (rdman)->shape_gl_sz
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
185 static shape_t *rdman_shapes(redraw_man_t *rdman, shape_t *last_shape);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
186
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
187
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
188 /* ============================================================ */
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
189 #endif /* UNITTEST */
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
190
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
191
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
192 static int _collect_shapes_at_point(redraw_man_t *rdman,
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
193 co_aix x, co_aix y) {
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
194 shape_t *shape;
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
195 int r;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
196
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
197 r = rdman_force_clean(rdman);
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
198 if(r != OK)
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
199 return ERR;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
200
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
201 rdman_clear_shape_gl(rdman);
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
202
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
203 for(shape = rdman_shapes(rdman, (shape_t *)NULL);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
204 shape != NULL;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
205 shape = rdman_shapes(rdman, shape)) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
206 if(sh_pos_is_in(shape, x, y)) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
207 r = rdman_add_shape_gl(rdman, shape);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
208 if(r != 0)
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
209 return ERR;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
210 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
211 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
212
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
213 return OK;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
214 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
215
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
216 static void draw_shape_path(shape_t *shape, cairo_t *cr) {
196
c234ee745ceb Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
217 switch(MBO_TYPE(shape)) {
c234ee745ceb Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
218 case MBO_PATH:
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
219 sh_path_draw(shape, cr);
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
220 break;
196
c234ee745ceb Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
221 case MBO_TEXT:
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
222 sh_text_draw(shape, cr);
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
223 break;
196
c234ee745ceb Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
224 case MBO_RECT:
35
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 32
diff changeset
225 sh_rect_draw(shape, cr);
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 32
diff changeset
226 break;
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
227 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
228 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
229
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
230 static int _shape_pos_is_in_cairo(shape_t *shape, co_aix x, co_aix y,
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
231 int *in_stroke, cairo_t *cr) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
232 draw_shape_path(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
233 if(shape->fill) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
234 if(cairo_in_fill(cr, x, y)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
235 *in_stroke = 0;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
236 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
237 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
238 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
239 if(shape->stroke) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
240 if(cairo_in_stroke(cr, x, y)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
241 *in_stroke = 1;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
242 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
243 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
244 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
245 return FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
246 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
247
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
248 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
249 int _shape_pos_is_in(shape_t *shape, co_aix x, co_aix y,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
250 int *in_stroke, cairo_t *cr) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
251 int r;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
252
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
253 r = sh_pos_is_in(shape, x, y);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
254 if(!r)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
255 return FALSE;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
256
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
257 r = _shape_pos_is_in_cairo(shape, x, y, in_stroke, cr);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
258 cairo_new_path(cr);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
259 if(!r)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
260 return FALSE;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
261
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
262 return TRUE;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
263 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
264
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
265 static shape_t *_find_shape_in_pos(redraw_man_t *rdman,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
266 co_aix x, co_aix y, int *in_stroke) {
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
267 shape_t *shape;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
268 cairo_t *cr;
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
269 int i, r;
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
270
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
271 cr = rdman_get_cr(rdman);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
272 for(i = rdman_shape_gl_len(rdman) - 1; i >= 0; i--) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
273 shape = rdman_get_shape_gl(rdman, i);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
274 if(sh_get_flags(shape, GEF_HIDDEN))
70
92cfabe22d6b find_shape_at_pos() finds a shape from clean ones.
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
275 continue;
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
276 r = _shape_pos_is_in_cairo(shape, x, y, in_stroke, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
277 if(r)
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
278 return shape;
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
279 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
280
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
281 return NULL;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
282 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
283
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
284 shape_t *find_shape_at_pos(redraw_man_t *rdman,
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
285 co_aix x, co_aix y, int *in_stroke) {
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
286 shape_t *shape;
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
287 int r;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
288
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
289 r = _collect_shapes_at_point(rdman, x, y);
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
290 if(r != OK)
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
291 return NULL;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
292
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
293 shape = _find_shape_in_pos(rdman, x, y, in_stroke);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
294 return shape;
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
295 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
296
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
297 /*! \brief Test if an object and descendants cover the position
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
298 * specified by x,y.
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
299 *
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
300 * \param in_stroke is x, y is on a stroke.
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
301 */
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
302 int mb_obj_pos_is_in(redraw_man_t *rdman, mb_obj_t *obj,
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
303 co_aix x, co_aix y, int *in_stroke) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
304 coord_t *cur_coord, *root;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
305 shape_t *shape;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
306 int r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
307
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
308 if(IS_MBO_SHAPES(obj)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
309 shape = (shape_t *)obj;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
310 r = _shape_pos_is_in(shape, x, y, in_stroke, rdman_get_cr(rdman));
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
311 return r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
312 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
313 root = (coord_t *)obj;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
314 for(cur_coord = postorder_coord_subtree(root, NULL);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
315 cur_coord != NULL;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
316 cur_coord = postorder_coord_subtree(root, cur_coord)) {
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
317 FOR_COORD_SHAPES(cur_coord, shape) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
318 r = _shape_pos_is_in(shape, x, y, in_stroke, rdman_get_cr(rdman));
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
319 if(r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
320 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
321 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
322 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
323 return FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
324 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
325
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
326 static
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
327 cairo_t * _prepare_cairo_for_testing(redraw_man_t *rdman) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
328 cairo_surface_t *surface, *rdman_surface;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
329 cairo_t *cr;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
330 int w, h;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
331
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
332 rdman_surface = cairo_get_target(rdman_get_cr(rdman));
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
333 w = cairo_image_surface_get_width(rdman_surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
334 h = cairo_image_surface_get_height(rdman_surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
335
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
336 surface = cairo_image_surface_create(CAIRO_FORMAT_A1, w, h);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
337 if(surface == NULL)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
338 return NULL;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
339
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
340 cr = cairo_create(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
341 if(cr == NULL)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
342 cairo_surface_destroy(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
343
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
344 return cr;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
345 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
346
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
347 static
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
348 void _release_cairo_for_testing(cairo_t *cr) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
349 cairo_destroy(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
350 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
351
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
352 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
353 void _draw_to_mask(shape_t *shape, cairo_t *cr) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
354 if(sh_get_flags(shape, GEF_OV_DRAW))
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
355 return;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
356
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
357 draw_shape_path(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
358 cairo_clip(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
359
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
360 sh_set_flags(shape, GEF_OV_DRAW);
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
361 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
362
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
363 static
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
364 int _fill_and_check(shape_t *shape, cairo_t *cr) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
365 int h, stride;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
366 cairo_surface_t *surface;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
367 unsigned char *data;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
368 int i, sz;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
369
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
370 draw_shape_path(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
371 cairo_fill(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
372
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
373 surface = cairo_get_target(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
374 data = cairo_image_surface_get_data(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
375
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
376 h = cairo_image_surface_get_height(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
377 stride = cairo_image_surface_get_stride(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
378
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
379 sz = stride * h;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
380 for(i = 0; i < sz; i++) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
381 if(data[i])
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
382 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
383 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
384
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
385 return FALSE;
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
386 }
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
387
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
388 /*! \brief Is a mb_obj_t overlaid with another mb_obj_t and
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
389 * descendants.
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
390 *
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
391 * coord is relative less than shapes. Check areas of coord can
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
392 * skip sub-trees and avoid useless heavy computation. For shapes,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
393 * it not only check overlay of area. It also check overlay by
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
394 * actually drawing on a cairo surface.
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
395 */
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
396 static
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
397 int _is_obj_objs_overlay(mb_obj_t *obj, mb_obj_t *others_root,
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
398 cairo_t *cr) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
399 area_t *area, *candi_area;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
400 coord_t *coord, *candi_coord, *root;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
401 shape_t *shape, *candi_shape;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
402 int obj_is_shape;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
403 int r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
404
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
405 obj_is_shape = IS_MBO_SHAPES(obj);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
406
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
407 if(obj_is_shape) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
408 shape = (shape_t *)obj;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
409 area = sh_get_area(shape);
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
410 } else {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
411 coord = (coord_t *)obj;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
412 area = coord_get_area(coord);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
413 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
414
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
415 if(IS_MBO_SHAPES(others_root)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
416 candi_shape = (shape_t *)others_root;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
417 candi_area = sh_get_area(candi_shape);
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
418
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
419 r = areas_are_overlay(area, candi_area);
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
420 if(!r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
421 return FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
422
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
423 if(!obj_is_shape)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
424 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
425
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
426 _draw_to_mask(candi_shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
427 r = _fill_and_check(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
428
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
429 return r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
430 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
431
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
432 ASSERT(IS_MBO_COORD(others_root));
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
433
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
434 root = (coord_t *)others_root;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
435 FOR_COORDS_PREORDER(root, candi_coord) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
436 candi_area = coord_get_area(candi_coord);
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
437 r = areas_are_overlay(area, candi_area);
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
438 if(!r) {
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
439 preorder_coord_skip_subtree(candi_coord);
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
440 continue;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
441 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
442
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
443 FOR_COORD_SHAPES(candi_coord, candi_shape) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
444 candi_area = sh_get_area(candi_shape);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
445 r = areas_are_overlay(area, candi_area);
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
446 if(!r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
447 continue;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
448
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
449 if(!obj_is_shape)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
450 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
451
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
452 _draw_to_mask(candi_shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
453 r = _fill_and_check(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
454 if(r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
455 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
456 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
457 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
458
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
459 return FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
460 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
461
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
462 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
463 void _clear_ov_draw(mb_obj_t *obj) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
464 coord_t *coord, *root;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
465 shape_t *shape;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
466
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
467 if(IS_MBO_SHAPES(obj)) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
468 shape = (shape_t *)obj;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
469 sh_clear_flags(shape, GEF_OV_DRAW);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
470 return;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
471 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
472
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
473 root = (coord_t *)obj;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
474 FOR_COORDS_PREORDER(root, coord) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
475 FOR_COORD_SHAPES(coord, shape) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
476 sh_clear_flags(shape, GEF_OV_DRAW);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
477 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
478 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
479 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
480
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
481 /*! \brief Test if two objects are overlaid.
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
482 *
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
483 * \todo Detect overlay in better way with cairo.
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
484 * \note This function cost heavy on CPU power.
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
485 */
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
486 int mb_objs_are_overlay(redraw_man_t *rdman,
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
487 mb_obj_t *obj1, mb_obj_t *obj2) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
488 cairo_t *cr;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
489 area_t *area;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
490 shape_t *shape;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
491 coord_t *coord, *root;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
492 int r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
493
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
494 cr = _prepare_cairo_for_testing(rdman);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
495
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
496 if(IS_MBO_SHAPES(obj1)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
497 shape = (shape_t *)obj1;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
498 r = _is_obj_objs_overlay(obj1, obj2, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
499 goto out;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
500 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
501
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
502 root = (coord_t *)obj1;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
503 FOR_COORDS_PREORDER(root, coord) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
504 area = coord_get_area(coord);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
505 r = _is_obj_objs_overlay((mb_obj_t *)coord, obj2, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
506 if(!r) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
507 preorder_coord_skip_subtree(coord);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
508 continue;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
509 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
510
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
511 FOR_COORD_SHAPES(coord, shape) {
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
512 r = _is_obj_objs_overlay((mb_obj_t *)shape, obj2, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
513 if(r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
514 goto out;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
515 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
516 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
517 r = FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
518
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
519 out:
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
520 _clear_ov_draw(obj2); /* marked by _is_obj_objs_overlay() */
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
521 _release_cairo_for_testing(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
522 return r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
523 }
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
524
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
525 #ifdef UNITTEST
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
526
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
527 #include <CUnit/Basic.h>
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
528
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
529 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
530 redraw_man_t *_fake_rdman(void) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
531 redraw_man_t *rdman;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
532 cairo_surface_t *surface;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
533
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
534 rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t));
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
535 surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
536 rdman->cr = cairo_create(surface);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
537 DARRAY_INIT(&rdman->gen_geos);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
538 return rdman;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
539 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
540
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
541 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
542 void _free_fake_rdman(redraw_man_t *rdman) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
543 cairo_destroy(rdman->cr);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
544 DARRAY_DESTROY(&rdman->gen_geos);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
545 free(rdman);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
546 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
547
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
548 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
549 void test_mb_obj_pos_is_in(void) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
550 redraw_man_t *rdman;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
551 mb_obj_t *obj;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
552
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
553 rdman = _fake_rdman();
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
554 CU_ASSERT(rdman != NULL);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
555
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
556 _free_fake_rdman(rdman);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
557 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
558
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
559 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
560 void test_is_obj_objs_overlay(void) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
561 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
562
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
563 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
564 void test_mb_objs_are_overlay(void) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
565 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
566
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
567 CU_pSuite get_event_suite(void) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
568 CU_pSuite suite;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
569
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
570 suite = CU_add_suite("Suite_event", NULL, NULL);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
571 CU_ADD_TEST(suite, test_mb_obj_pos_is_in);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
572 CU_ADD_TEST(suite, test_is_obj_objs_overlay);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
573 CU_ADD_TEST(suite, test_mb_objs_are_overlay);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
574
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
575 return suite;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
576 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
577
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
578 #endif /* UNITTEST */