annotate src/event.c @ 235:65cabbdd5284

termporary revision
author Thinker K.F. Li <thinker@branda.to>
date Thu, 25 Dec 2008 18:40:27 +0800
parents 527894c2ad39
children 104d83378582
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 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
58
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
59 struct mb_obj {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
60 int obj_type;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
61 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
62 typedef struct mb_obj mb_obj_t;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
63
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
64 #define GEF_OV_DRAW 0x1
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
65 #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
66
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
67 struct shape {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
68 mb_obj_t obj;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
69
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
70 void *fill, *stroke;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
71 struct shape *sibling;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
72 int flags;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
73
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
74 int num_points;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
75 co_aix points[32][2];
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
76 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
77 enum { MBO_DUMMY,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
78 MBO_COORD,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
79 MBO_SHAPES=0x1000,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
80 MBO_PATH,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
81 MBO_TEXT,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
82 MBO_RECT
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
83 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
84 #define MBO_TYPE(x) (((mb_obj_t *)(x))->obj_type)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
85 #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
86 #define sh_get_geo(x) ((x)->geo)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
87 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
88 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
89
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
90 for(i = 0; i < shape->num_points; i++)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
91 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
92 return TRUE;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
93 return FALSE;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
94 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
95 #define sh_get_flags(shape, mask) ((shape)->flags & mask)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
96 #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
97 #define sh_clear_flags(shape, mask) do { (shape)->flags &= ~(mask); } while(0)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
98
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
99 typedef struct coord coord_t;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
100 struct coord {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
101 mb_obj_t obj;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
102
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
103 coord_t *children;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
104 coord_t *sibling;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
105 shape_t *shapes;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
106 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
107
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 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
110 coord_t *postorder_coord_subtree(coord_t *root, coord_t *last) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
111 if(last == NULL)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
112 return root;
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
113 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
114
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
115 #define sh_path_draw(path, cr)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
116 #define sh_text_draw(path, cr)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
117 #define sh_rect_draw(path, cr)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
118
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 struct redraw_man {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
121 cairo_t *cr;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
122 int shape_gl_sz;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
123 shape_t *shape_gl[32];
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
124 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
125 typedef struct redraw_man redraw_man_t;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
126 #define rdman_get_cr(rdman) ((rdman)->cr)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
127 #define rdman_get_gen_geos(rdman) (&(rdman)->gen_geos)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
128 #define rdman_force_clean(rdman) OK
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
129 #define rdman_geos(rdman, geo) NULL
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
130 #define rdman_clear_shape_gl(rdman) \
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
131 do {(rdman)->shape_gl_sz = 0; } while(0)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
132 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
133 (rdman)->shape_gl[(rdman)->shape_gl_sz++] = shape;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
134 return OK;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
135 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
136 #define rdman_get_shape_gl(rdman, idx) \
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
137 (rdman)->shape_gl[idx]
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
138 #define rdman_shape_gl_len(rdman) (rdman)->shape_gl_sz
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
139 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
140
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 /* ============================================================ */
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
143 #endif /* UNITTEST */
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
144
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
145
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
146 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
147 co_aix x, co_aix y) {
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
148 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
149 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
150
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151 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
152 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
153 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
154
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
155 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
156
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
157 for(shape = rdman_shapes(rdman, (shape_t *)NULL);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
158 shape != NULL;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
159 shape = rdman_shapes(rdman, shape)) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
160 if(sh_pos_is_in(shape, x, y)) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
161 r = rdman_add_shape_gl(rdman, shape);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
162 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
163 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
164 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
165 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
166
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
167 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
168 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
169
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
170 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
171 switch(MBO_TYPE(shape)) {
c234ee745ceb Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
172 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
173 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
174 break;
196
c234ee745ceb Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
175 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
176 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
177 break;
196
c234ee745ceb Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
178 case MBO_RECT:
35
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 32
diff changeset
179 sh_rect_draw(shape, cr);
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 32
diff changeset
180 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
181 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
182 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
183
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
184 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
185 int *in_stroke, cairo_t *cr) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
186 draw_shape_path(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
187 if(shape->fill) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
188 if(cairo_in_fill(cr, x, y)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
189 *in_stroke = 0;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
190 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
191 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
192 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
193 if(shape->stroke) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
194 if(cairo_in_stroke(cr, x, y)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
195 *in_stroke = 1;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
196 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
197 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
198 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
199 return FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
200 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
201
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
202 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
203 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
204 int *in_stroke, cairo_t *cr) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
205 int r;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
206
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
207 r = sh_pos_is_in(shape, x, y);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
208 if(!r)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
209 return FALSE;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
210
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
211 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
212 cairo_new_path(cr);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
213 if(!r)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
214 return FALSE;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
215
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
216 return TRUE;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
217 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
218
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
219 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
220 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
221 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
222 cairo_t *cr;
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
223 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
224
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
225 cr = rdman_get_cr(rdman);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
226 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
227 shape = rdman_get_shape_gl(rdman, i);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
228 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
229 continue;
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
230 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
231 if(r)
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
232 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
233 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
234
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
235 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
236 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
237
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
238 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
239 co_aix x, co_aix y, int *in_stroke) {
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
240 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
241 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
242
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
243 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
244 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
245 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
246
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
247 shape = _find_shape_in_pos(rdman, x, y, in_stroke);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
248 return shape;
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
249 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
250
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
251 /*! \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
252 * specified by x,y.
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
253 *
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
254 * \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
255 */
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
256 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
257 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
258 coord_t *cur_coord, *root;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
259 shape_t *shape;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
260 int r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
261
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
262 if(IS_MBO_SHAPES(obj)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
263 shape = (shape_t *)obj;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
264 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
265 return r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
266 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
267 root = (coord_t *)obj;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
268 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
269 cur_coord != NULL;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
270 cur_coord = postorder_coord_subtree(root, cur_coord)) {
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
271 FOR_COORD_SHAPES(cur_coord, shape) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
272 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
273 if(r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
274 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
275 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
276 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
277 return FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
278 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
279
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
280 static
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
281 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
282 cairo_surface_t *surface, *rdman_surface;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
283 cairo_t *cr;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
284 int w, h;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
285
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
286 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
287 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
288 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
289
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
290 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
291 if(surface == NULL)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
292 return NULL;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
293
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
294 cr = cairo_create(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
295 if(cr == NULL)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
296 cairo_surface_destroy(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
297
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
298 return cr;
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
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
301 static
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
302 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
303 cairo_destroy(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
304 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
305
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
306 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
307 void _draw_to_mask(shape_t *shape, cairo_t *cr) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
308 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
309 return;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
310
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
311 draw_shape_path(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
312 cairo_clip(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
313
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
314 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
315 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
316
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
317 static
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
318 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
319 int h, stride;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
320 cairo_surface_t *surface;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
321 unsigned char *data;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
322 int i, sz;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
323
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
324 draw_shape_path(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
325 cairo_fill(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
326
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
327 surface = cairo_get_target(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
328 data = cairo_image_surface_get_data(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
329
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
330 h = cairo_image_surface_get_height(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
331 stride = cairo_image_surface_get_stride(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
332
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
333 sz = stride * h;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
334 for(i = 0; i < sz; i++) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
335 if(data[i])
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
336 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
337 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
338
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
339 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
340 }
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
341
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
342 /*! \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
343 * descendants.
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
344 *
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
345 * 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
346 * skip sub-trees and avoid useless heavy computation. For shapes,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
347 * 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
348 * actually drawing on a cairo surface.
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
349 */
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
350 static
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
351 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
352 cairo_t *cr) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
353 area_t *area, *candi_area;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
354 coord_t *coord, *candi_coord, *root;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
355 shape_t *shape, *candi_shape;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
356 int obj_is_shape;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
357 int r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
358
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
359 obj_is_shape = IS_MBO_SHAPES(obj);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
360
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
361 if(obj_is_shape) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
362 shape = (shape_t *)obj;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
363 area = sh_get_area(shape);
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
364 } else {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
365 coord = (coord_t *)obj;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
366 area = coord_get_area(coord);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
367 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
368
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
369 if(IS_MBO_SHAPES(others_root)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
370 candi_shape = (shape_t *)others_root;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
371 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
372
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
373 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
374 if(!r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
375 return FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
376
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
377 if(!obj_is_shape)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
378 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
379
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
380 _draw_to_mask(candi_shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
381 r = _fill_and_check(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
382
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
383 return r;
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
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
386 ASSERT(IS_MBO_COORD(others_root));
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
387
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
388 root = (coord_t *)others_root;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
389 FOR_COORDS_PREORDER(root, candi_coord) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
390 candi_area = coord_get_area(candi_coord);
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
391 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
392 if(!r) {
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
393 preorder_coord_skip_subtree(candi_coord);
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
394 continue;
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
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
397 FOR_COORD_SHAPES(candi_coord, candi_shape) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
398 candi_area = sh_get_area(candi_shape);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
399 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
400 if(!r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
401 continue;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
402
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
403 if(!obj_is_shape)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
404 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
405
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
406 _draw_to_mask(candi_shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
407 r = _fill_and_check(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
408 if(r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
409 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
410 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
411 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
412
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
413 return FALSE;
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
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
416 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
417 void _clear_ov_draw(mb_obj_t *obj) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
418 coord_t *coord, *root;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
419 shape_t *shape;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
420
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
421 if(IS_MBO_SHAPES(obj)) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
422 shape = (shape_t *)obj;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
423 sh_clear_flags(shape, GEF_OV_DRAW);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
424 return;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
425 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
426
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
427 root = (coord_t *)obj;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
428 FOR_COORDS_PREORDER(root, coord) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
429 FOR_COORD_SHAPES(coord, shape) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
430 sh_clear_flags(shape, GEF_OV_DRAW);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
431 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
432 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
433 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
434
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
435 /*! \brief Test if two objects are overlaid.
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
436 *
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
437 * \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
438 * \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
439 */
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
440 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
441 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
442 cairo_t *cr;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
443 area_t *area;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
444 shape_t *shape;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
445 coord_t *coord, *root;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
446 int r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
447
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
448 cr = _prepare_cairo_for_testing(rdman);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
449
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
450 if(IS_MBO_SHAPES(obj1)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
451 shape = (shape_t *)obj1;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
452 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
453 goto out;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
454 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
455
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
456 root = (coord_t *)obj1;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
457 FOR_COORDS_PREORDER(root, coord) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
458 area = coord_get_area(coord);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
459 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
460 if(!r) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
461 preorder_coord_skip_subtree(coord);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
462 continue;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
463 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
464
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
465 FOR_COORD_SHAPES(coord, shape) {
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
466 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
467 if(r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
468 goto out;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
469 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
470 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
471 r = FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
472
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
473 out:
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
474 _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
475 _release_cairo_for_testing(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
476 return r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
477 }
235
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 #ifdef UNITTEST
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
480
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
481 #include <CUnit/Basic.h>
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
482
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
483 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
484 redraw_man_t *_fake_rdman(void) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
485 redraw_man_t *rdman;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
486 cairo_surface_t *surface;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
487
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
488 rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t));
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
489 surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
490 rdman->cr = cairo_create(surface);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
491 DARRAY_INIT(&rdman->gen_geos);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
492 return rdman;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
493 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
494
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
495 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
496 void _free_fake_rdman(redraw_man_t *rdman) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
497 cairo_destroy(rdman->cr);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
498 DARRAY_DESTROY(&rdman->gen_geos);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
499 free(rdman);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
500 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
501
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
502 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
503 void test_mb_obj_pos_is_in(void) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
504 redraw_man_t *rdman;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
505 mb_obj_t *obj;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
506
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
507 rdman = _fake_rdman();
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
508 CU_ASSERT(rdman != NULL);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
509
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
510 _free_fake_rdman(rdman);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
511 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
512
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
513 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
514 void test_is_obj_objs_overlay(void) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
515 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
516
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
517 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
518 void test_mb_objs_are_overlay(void) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
519 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
520
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
521 CU_pSuite get_event_suite(void) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
522 CU_pSuite suite;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
523
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
524 suite = CU_add_suite("Suite_event", NULL, NULL);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
525 CU_ADD_TEST(suite, test_mb_obj_pos_is_in);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
526 CU_ADD_TEST(suite, test_is_obj_objs_overlay);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
527 CU_ADD_TEST(suite, test_mb_objs_are_overlay);
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 return suite;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
530 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
531
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
532 #endif /* UNITTEST */