annotate src/event.c @ 382:83283a45ffbc

Add c header rule for the mozplugger
author wycc
date Sun, 05 Apr 2009 12:29:21 +0800
parents 6c350fc92ae3
children 7f7855df2af0
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 /* ============================================================ */
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
24 #include <string.h>
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
25 #include "mb_tools.h"
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
26
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
27 typedef float co_aix;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
28
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
29 typedef struct shape shape_t;
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
30 typedef struct cairo_surface cairo_surface_t;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
31 typedef struct coord coord_t;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
32
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
33 typedef struct cairo cairo_t;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
34 struct cairo {
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
35 STAILQ(shape_t) drawed;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
36 STAILQ(shape_t) clip_pathes;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
37 cairo_surface_t *tgt;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
38 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
39
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
40 struct cairo_surface {
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
41 cairo_t *cr;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
42 int w, h;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
43 unsigned char *data;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
44 };
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
45
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
46 #define cairo_new_path(cr) do { STAILQ_CLEAN((cr)->drawed); } while(0)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
47 #define cairo_get_target(cr) (cr)->tgt
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
48 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
49 cairo_t *cairo_create(cairo_surface_t *target) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
50 cairo_t *cr;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
51
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
52 cr = (cairo_t *)malloc(sizeof(cairo_t));
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
53 STAILQ_INIT(cr->drawed);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
54 STAILQ_INIT(cr->clip_pathes);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
55 cr->tgt = target;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
56 target->cr = cr;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
57
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
58 return cr;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
59 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
60 #define cairo_destroy(cr) do { free(cr); } while(0)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
61 #define cairo_clip(cr) \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
62 do { \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
63 memcpy(&(cr)->clip_pathes, \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
64 &(cr)->drawed, \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
65 sizeof((cr)->drawed)); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
66 STAILQ_CLEAN((cr)->drawed); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
67 } while(0)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
68 #define cairo_fill(cr)
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
69
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
70 #define cairo_image_surface_get_width(surface) (surface)->w
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
71 #define cairo_image_surface_get_height(surface) (surface)->h
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
72 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
73 cairo_surface_t *cairo_image_surface_create(int format, int w, int h) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
74 cairo_surface_t *surf;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
75
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
76 surf = (cairo_surface_t *)malloc(sizeof(cairo_surface_t));
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
77 surf->w = w;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
78 surf->h = h;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
79 surf->data = (unsigned char *)malloc(h);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
80 memset(surf->data, 0, h);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
81
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
82 return surf;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
83 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
84 #define cairo_surface_destroy(surface) \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
85 do { free((surface)->data); free(surface); } while(0)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
86 #define cairo_image_surface_get_stride(surface) 1
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
87 #define CAIRO_FORMAT_A1 1
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
88
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
89
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
90 typedef struct _area area_t;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
91 struct _area {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
92 co_aix x, y;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
93 co_aix w, h;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
94 };
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
95 #define area_set(area, _x, _y, _w, _h) \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
96 do { \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
97 (area)->x = (_x); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
98 (area)->y = (_y); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
99 (area)->w = (_w); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
100 (area)->h = (_h); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
101 } while(0)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
102 #define _in_range(a, s, w) ((a) >= (s) && (a) < ((s) + (w)))
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
103 #define _range_overlay(as, aw, bs, bw) \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
104 (_in_range(as, bs, bw) || _in_range(bs, as, aw))
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
105 #define areas_are_overlay(a1, a2) \
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
106 (_range_overlay((a1)->x, (a1)->w, \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
107 (a2)->x, (a2)->w) && \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
108 _range_overlay((a1)->y, (a1)->h, \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
109 (a2)->y, (a2)->h))
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
110 #define area_pos_is_in(area, _x, _y) \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
111 (_in_range(_x, (area)->x, (area)->w) && \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
112 _in_range(_y, (area)->y, (area)->h))
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
113 #define _range_extent(a, s, w) \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
114 do { \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
115 if((a) < (s)) { \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
116 (w) += (s) - (a); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
117 (s) = (a); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
118 } else { \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
119 (w) = MAX(w, (a) - (s) + 1); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
120 } \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
121 } while(0)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
122
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
123 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
124 void area_extent(area_t *area, co_aix x, co_aix y) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
125 _range_extent(x, area->x, area->w);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
126 _range_extent(y, area->y, area->h);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
127 }
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
128
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
129 struct mb_obj {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
130 int obj_type;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
131 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
132 typedef struct mb_obj mb_obj_t;
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
133 #define MB_OBJ_INIT(obj, type) do { (obj)->obj_type = type; } while(0)
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
134
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
135 #define GEF_OV_DRAW 0x1
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
136 #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
137
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
138 struct shape {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
139 mb_obj_t obj;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
140
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
141 coord_t *coord;
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
142 area_t area;
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
143 shape_t *all_next;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
144 shape_t *drawed_next;
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
145
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
146 void *fill, *stroke;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
147 struct shape *sibling;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
148 int flags;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
149
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
150 int num_points;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
151 co_aix points[32][2];
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
152 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
153 enum { MBO_DUMMY,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
154 MBO_COORD,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
155 MBO_SHAPES=0x1000,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
156 MBO_PATH,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
157 MBO_TEXT,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
158 MBO_RECT
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
159 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
160 #define MBO_TYPE(x) (((mb_obj_t *)(x))->obj_type)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
161 #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
162 #define sh_get_geo(x) ((x)->geo)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
163 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
164 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
165
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
166 for(i = 0; i < shape->num_points; i++)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
167 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
168 return TRUE;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
169 return FALSE;
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 #define sh_get_flags(shape, mask) ((shape)->flags & mask)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
172 #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
173 #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
174 #define sh_get_area(shape) (&(shape)->area)
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
175
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
176 struct coord {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
177 mb_obj_t obj;
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
178
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
179 area_t area;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
180 int flags;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
181 coord_t *parent;
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
182 STAILQ(coord_t) children;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
183 coord_t *sibling;
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
184 STAILQ(shape_t) shapes;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
185 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
186
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
187 #define COF_SKIP 0x1
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
188
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
189 #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
190 #define FOR_COORD_SHAPES(coord, shape) \
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
191 for((shape) = STAILQ_HEAD((coord)->shapes); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
192 (shape) != NULL; \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
193 (shape) = STAILQ_NEXT(shape_t, sibling, shape))
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
194 #define FOR_COORDS_PREORDER(root, last) \
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
195 for((last) = (root); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
196 (last) != NULL; \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
197 (last) = preorder_coord_subtree(root, last))
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
198 #define FOR_COORD_CHILDREN(parent, child) \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
199 for((child) = STAILQ_HEAD((parent)->children); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
200 (child) != NULL; \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
201 (child) = STAILQ_NEXT(coord_t, sibling, child))
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
202
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
203 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
204 void _areas_merge(area_t *area1, area_t *area2) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
205 co_aix lu_x, lu_y;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
206 co_aix rb_x, rb_y;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
207
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
208 lu_x = area2->x;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
209 lu_y = area2->y;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
210 rb_x = lu_x + area2->w - 1;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
211 rb_y = lu_y + area2->h - 1;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
212 area_extent(area1, lu_x, lu_y);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
213 area_extent(area1, rb_x, rb_y);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
214 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
215
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
216 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
217 void coord_update_area(coord_t *coord) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
218 area_t *area;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
219 shape_t *shape;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
220 coord_t *child;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
221 area_t *cur_area;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
222
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
223 area = coord_get_area(coord);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
224
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
225 shape = STAILQ_HEAD(coord->shapes);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
226 if(shape != NULL) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
227 cur_area = sh_get_area(shape);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
228 } else {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
229 child = STAILQ_HEAD(coord->children);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
230 if(child == NULL)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
231 return;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
232 cur_area = coord_get_area(child);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
233 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
234 memcpy(area, cur_area, sizeof(area_t));
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
235
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
236 FOR_COORD_SHAPES(coord, shape) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
237 cur_area = sh_get_area(shape);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
238 _areas_merge(area, cur_area);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
239 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
240
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
241 FOR_COORD_CHILDREN(coord, child) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
242 cur_area = coord_get_area(child);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
243 _areas_merge(area, cur_area);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
244 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
245 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
246
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
247 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
248 void coord_update_area_ancestors(coord_t *coord) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
249 coord_t *cur;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
251 for(cur = coord; cur != NULL; cur = cur->parent) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
252 coord_update_area(cur);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
253 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
254 }
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
255
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
256 static
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
257 coord_t *preorder_coord_subtree(coord_t *root, coord_t *last) {
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
258 if(STAILQ_HEAD(last->children) && !(last->flags & COF_SKIP))
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
259 return STAILQ_HEAD(last->children);
314
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
260
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
261 last->flags &= ~COF_SKIP;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
262
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
263 if(last == root)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
264 return NULL;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
265 while(STAILQ_NEXT(coord_t, sibling, last) == NULL) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
266 if(last == root)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
267 return NULL;
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
268 last = last->parent;
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
269 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
270 return STAILQ_NEXT(coord_t, sibling, last);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
271 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
272
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
273 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
274 void preorder_coord_skip_subtree(coord_t *coord) {
314
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
275 coord->flags |= COF_SKIP;
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
276 }
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
277
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
278 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
279 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
280 coord_t *cur;
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
281
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
282 if(last != NULL) {
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
283 if(STAILQ_NEXT(coord_t, sibling, last) == NULL) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
284 if(cur == root)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
285 return NULL;
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
286 cur = last->parent;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
287 return cur;
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
288 }
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
289 cur = STAILQ_NEXT(coord_t, sibling, last);
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
290 }
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
291
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
292 cur = root;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
293 while(STAILQ_HEAD(cur->children)) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
294 cur = STAILQ_HEAD(cur->children);
241
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
295 }
104d83378582 Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
296 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
297 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
298
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
299 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
300 void shape_draw(shape_t *sh, cairo_t *cr) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
301 STAILQ_INS_TAIL(cr->drawed, shape_t, drawed_next, sh);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
302 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
303
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
304 #define sh_path_draw(path, cr) shape_draw((shape_t *)path, cr)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
305 #define sh_text_draw(text, cr) shape_draw((shape_t *)text, cr)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
306 #define sh_rect_draw(rect, cr) shape_draw((shape_t *)rect, cr)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
307 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
308 void sh_update_area(shape_t *sh) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
309 int i;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
310 co_aix x, y;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
311 area_t *area = &sh->area;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
312
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
313 if(sh->num_points == 0) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
314 area_set(area, 0, 0, 0, 0);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
315 return;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
316 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
317
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
318 area_set(area, sh->points[0][0], sh->points[0][1], 1, 1);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
319 for(i = 1; i < sh->num_points; i++) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
320 x = sh->points[i][0];
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
321 y = sh->points[i][1];
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
322 area_extent(area, x, y);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
323 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
324 }
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
325
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
326
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
327 struct redraw_man {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
328 cairo_t *cr;
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
329 coord_t *root_coord;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
330 int shape_gl_sz;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
331 shape_t *shape_gl[32];
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
332 STAILQ(shape_t) all_shapes;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
333 };
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
334 typedef struct redraw_man redraw_man_t;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
335 #define rdman_get_cr(rdman) ((rdman)->cr)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
336 #define rdman_force_clean(rdman) OK
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
337 #define rdman_clear_shape_gl(rdman) do {(rdman)->shape_gl_sz = 0; } while(0)
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
338 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
339 (rdman)->shape_gl[(rdman)->shape_gl_sz++] = shape;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
340 return OK;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
341 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
342 #define rdman_get_shape_gl(rdman, idx) \
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
343 (rdman)->shape_gl[idx]
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
344 #define rdman_shape_gl_len(rdman) (rdman)->shape_gl_sz
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
345 static shape_t *rdman_shapes(redraw_man_t *rdman, shape_t *last_shape) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
346 if(last_shape == NULL)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
347 return STAILQ_HEAD(rdman->all_shapes);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
348
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
349 return STAILQ_NEXT(shape_t, all_next, last_shape);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
350 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
351 #define redraw_man_init(rdman, cr, backend) \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
352 do { \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
353 memset(rdman, 0, sizeof(redraw_man_t)); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
354 (rdman)->cr = cr; \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
355 (rdman)->root_coord = rdman_coord_new_noparent(rdman); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
356 } while(0)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
357 #define redraw_man_destroy(rdman) \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
358 do { \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
359 free(rdman); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
360 } while(0)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
361 #define rdman_get_root(rdman) ((rdman)->root_coord)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
362
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
363 static coord_t *rdman_coord_new_noparent(redraw_man_t *rdman);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
364
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
365 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
366 redraw_man_t *redraw_man_new(cairo_t *cr, cairo_t *backend) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
367 redraw_man_t *rdman;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
368
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
369 rdman = O_ALLOC(redraw_man_t);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
370 redraw_man_init(rdman, cr, backend);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
371 return rdman;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
372 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
373 #define redraw_man_free(rdman) \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
374 do { \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
375 redraw_man_destroy(rdman); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
376 free(rdman); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
377 } while(0)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
378
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
379 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
380 int cairo_in_fill(cairo_t *cr, int x, int y) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
381 shape_t *shape;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
382 int i;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
383
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
384 for(shape = STAILQ_HEAD(cr->drawed);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
385 shape != NULL;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
386 shape = STAILQ_NEXT(shape_t, drawed_next, shape)) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
387 for(i = 0; i < shape->num_points; i++)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
388 if(shape->points[i][0] == x &&
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
389 shape->points[i][1] == y)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
390 return 1;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
391 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
392 return 0;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
393 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
394
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
395 #define cairo_in_stroke cairo_in_fill
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
396
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
397 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
398 void rdman_coord_init_noparent(redraw_man_t *rdman, coord_t *co) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
399 memset(co, 0, sizeof(coord_t));
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
400 MB_OBJ_INIT(&co->obj, MBO_COORD);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
401 STAILQ_INIT(co->children);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
402 STAILQ_INIT(co->shapes);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
403 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
404
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
405 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
406 void rdman_coord_init(redraw_man_t *rdman, coord_t *co, coord_t *parent) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
407 rdman_coord_init_noparent(rdman, co);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
408 STAILQ_INS_TAIL(parent->children, coord_t, sibling, co);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
409 co->parent = parent;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
410 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
411
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
412 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
413 coord_t *rdman_coord_new(redraw_man_t *rdman, coord_t *parent) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
414 coord_t *coord;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
415
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
416 coord = O_ALLOC(coord_t);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
417 rdman_coord_init(rdman, coord, parent);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
418
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
419 return coord;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
420 }
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
421
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
422 coord_t *rdman_coord_new_noparent(redraw_man_t *rdman) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
423 coord_t *coord;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
424
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
425 coord = O_ALLOC(coord_t);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
426 rdman_coord_init_noparent(rdman, coord);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
427
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
428 return coord;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
429 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
430
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
431 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
432 void rdman_coord_free(redraw_man_t *rdman, coord_t *coord) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
433 free(coord);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
434 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
435
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
436 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
437 shape_t *rdman_shape_new(redraw_man_t *rdman) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
438 shape_t *shape;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
439
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
440 shape = O_ALLOC(shape_t);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
441 memset(shape, 0, sizeof(shape_t));
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
442 MB_OBJ_INIT(&shape->obj, MBO_PATH);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
443 STAILQ_INS(rdman->all_shapes, shape_t, all_next, shape);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
444
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
445 return shape;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
446 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
447
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
448 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
449 void rdman_shape_free(redraw_man_t *rdman, shape_t *shape) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
450 STAILQ_REMOVE(rdman->all_shapes, shape_t, all_next, shape);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
451 free(shape);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
452 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
453
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
454 #define shape_add_point(shape, x, y) \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
455 do { \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
456 (shape)->points[(shape)->num_points][0] = x; \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
457 (shape)->points[(shape)->num_points][1] = y; \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
458 (shape)->num_points++; \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
459 sh_update_area(shape); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
460 if((shape)->coord) \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
461 coord_update_area_ancestors((shape)->coord); \
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
462 } while(0)
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
463
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
464 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
465 int rdman_add_shape(redraw_man_t *rdman, shape_t *shape,
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
466 coord_t *parent) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
467 STAILQ_INS_TAIL(parent->shapes, shape_t, sibling, shape);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
468 shape->coord = parent;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
469
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
470 return OK;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
471 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
472
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
473 static
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
474 void *cairo_image_surface_get_data(cairo_surface_t *surf) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
475 cairo_t *cr;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
476 shape_t *shape1, *shape2;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
477 co_aix x1, y1, x2, y2;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
478 int i, j;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
479
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
480 cr = surf->cr;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
481
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
482 STAILQ_FOR_EACH(cr->drawed, shape_t, sibling, shape1) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
483 for(i = 0; i < shape1->num_points; i++) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
484 x1 = shape1->points[i][0];
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
485 y1 = shape1->points[i][1];
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
486 STAILQ_FOR_EACH(cr->clip_pathes, shape_t, sibling, shape2) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
487 for(j = 0; j < shape2->num_points; j++) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
488 x2 = shape2->points[j][0];
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
489 y2 = shape2->points[j][1];
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
490 if(x1 == x2 && y1 == y2) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
491 surf->data[0] = 1;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
492 return surf->data;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
493 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
494 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
495 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
496 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
497 }
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
498 surf->data[0] = 0;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
499 return surf->data;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
500 }
235
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 #endif /* UNITTEST */
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
503
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
504
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
505 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
506 co_aix x, co_aix y) {
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
507 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
508 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
509
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
510 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
511 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
512 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
513
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
514 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
515
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
516 for(shape = rdman_shapes(rdman, (shape_t *)NULL);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
517 shape != NULL;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
518 shape = rdman_shapes(rdman, shape)) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
519 if(sh_pos_is_in(shape, x, y)) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
520 r = rdman_add_shape_gl(rdman, shape);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
521 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
522 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
523 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
524 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
525
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
526 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
527 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
528
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
529 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
530 switch(MBO_TYPE(shape)) {
c234ee745ceb Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
531 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
532 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
533 break;
196
c234ee745ceb Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
534 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
535 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
536 break;
196
c234ee745ceb Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
537 case MBO_RECT:
35
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 32
diff changeset
538 sh_rect_draw(shape, cr);
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 32
diff changeset
539 break;
260
29acbd8a0dd0 Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 251
diff changeset
540 case MBO_IMAGE:
29acbd8a0dd0 Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 251
diff changeset
541 sh_image_draw(shape, cr);
29acbd8a0dd0 Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 251
diff changeset
542 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
543 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
544 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
545
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
546 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
547 int *in_stroke, cairo_t *cr) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
548 draw_shape_path(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
549 if(shape->fill) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
550 if(cairo_in_fill(cr, x, y)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
551 *in_stroke = 0;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
552 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
553 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
554 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
555 if(shape->stroke) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
556 if(cairo_in_stroke(cr, x, y)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
557 *in_stroke = 1;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
558 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
559 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
560 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
561 return FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
562 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
563
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
564 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
565 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
566 int *in_stroke, cairo_t *cr) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
567 int r;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
568
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
569 r = sh_pos_is_in(shape, x, y);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
570 if(!r)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
571 return FALSE;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
572
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
573 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
574 cairo_new_path(cr);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
575 if(!r)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
576 return FALSE;
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 return TRUE;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
579 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
580
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
581 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
582 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
583 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
584 cairo_t *cr;
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
585 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
586
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
587 cr = rdman_get_cr(rdman);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
588 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
589 shape = rdman_get_shape_gl(rdman, i);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
590 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
591 continue;
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
592 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
593 if(r)
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
594 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
595 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
596
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
597 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
598 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
599
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
600 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
601 co_aix x, co_aix y, int *in_stroke) {
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
602 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
603 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
604
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
605 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
606 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
607 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
608
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
609 shape = _find_shape_in_pos(rdman, x, y, in_stroke);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
610 return shape;
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
611 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
612
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
613 /*! \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
614 * specified by x,y.
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
615 *
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
616 * \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
617 */
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
618 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
619 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
620 coord_t *cur_coord, *root;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
621 shape_t *shape;
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
622 area_t *area;
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
623 int r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
624
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
625 if(IS_MBO_SHAPES(obj)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
626 shape = (shape_t *)obj;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
627 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
628 return r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
629 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
630 root = (coord_t *)obj;
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
631 FOR_COORDS_PREORDER(root, cur_coord) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
632 area = coord_get_area(cur_coord);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
633 if(!area_pos_is_in(area, x, y)) {
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
634 preorder_coord_skip_subtree(cur_coord);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
635 continue;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
636 }
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
637 FOR_COORD_SHAPES(cur_coord, shape) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
638 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
639 if(r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
640 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
641 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
642 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
643 return FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
644 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
645
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
646 static
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
647 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
648 cairo_surface_t *surface, *rdman_surface;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
649 cairo_t *cr;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
650 int w, h;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
651
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
652 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
653 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
654 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
655
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
656 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
657 if(surface == NULL)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
658 return NULL;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
659
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
660 cr = cairo_create(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
661 if(cr == NULL)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
662 cairo_surface_destroy(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
663
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
664 return cr;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
665 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
666
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
667 static
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
668 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
669 cairo_destroy(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
670 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
671
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
672 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
673 void _draw_to_mask(shape_t *shape, cairo_t *cr) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
674 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
675 return;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
676
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
677 draw_shape_path(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
678 cairo_clip(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
679
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
680 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
681 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
682
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
683 static
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
684 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
685 int h, stride;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
686 cairo_surface_t *surface;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
687 unsigned char *data;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
688 int i, sz;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
689
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
690 draw_shape_path(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
691 cairo_fill(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
692
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
693 surface = cairo_get_target(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
694 data = cairo_image_surface_get_data(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
695
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
696 h = cairo_image_surface_get_height(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
697 stride = cairo_image_surface_get_stride(surface);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
698
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
699 sz = stride * h;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
700 for(i = 0; i < sz; i++) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
701 if(data[i])
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
702 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
703 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
704
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
705 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
706 }
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
707
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
708 /*! \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
709 * descendants.
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
710 *
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
711 * 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
712 * skip sub-trees and avoid useless heavy computation. For shapes,
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
713 * 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
714 * actually drawing on a cairo surface.
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
715 */
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
716 static
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
717 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
718 cairo_t *cr) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
719 area_t *area, *candi_area;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
720 coord_t *coord, *candi_coord, *root;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
721 shape_t *shape, *candi_shape;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
722 int obj_is_shape;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
723 int r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
724
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
725 obj_is_shape = IS_MBO_SHAPES(obj);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
726
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
727 if(obj_is_shape) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
728 shape = (shape_t *)obj;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
729 area = sh_get_area(shape);
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
730 } else {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
731 coord = (coord_t *)obj;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
732 area = coord_get_area(coord);
251
f08b3ba9c1d8 Remove potential memory address error.
Thinker K.F. Li <thinker@branda.to>
parents: 250
diff changeset
733 shape = NULL;
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
734 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
735
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
736 if(IS_MBO_SHAPES(others_root)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
737 candi_shape = (shape_t *)others_root;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
738 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
739
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
740 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
741 if(!r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
742 return FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
743
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
744 if(!obj_is_shape)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
745 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
746
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
747 _draw_to_mask(candi_shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
748 r = _fill_and_check(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
749
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
750 return r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
751 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
752
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
753 ASSERT(IS_MBO_COORD(others_root));
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
754
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
755 root = (coord_t *)others_root;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
756 FOR_COORDS_PREORDER(root, candi_coord) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
757 candi_area = coord_get_area(candi_coord);
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
758 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
759 if(!r) {
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
760 preorder_coord_skip_subtree(candi_coord);
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
761 continue;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
762 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
763
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
764 FOR_COORD_SHAPES(candi_coord, candi_shape) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
765 candi_area = sh_get_area(candi_shape);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
766 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
767 if(!r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
768 continue;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
769
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
770 if(!obj_is_shape)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
771 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
772
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
773 _draw_to_mask(candi_shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
774 r = _fill_and_check(shape, cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
775 if(r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
776 return TRUE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
777 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
778 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
779
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
780 return FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
781 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
782
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
783 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
784 void _clear_ov_draw(mb_obj_t *obj) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
785 coord_t *coord, *root;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
786 shape_t *shape;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
787
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
788 if(IS_MBO_SHAPES(obj)) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
789 shape = (shape_t *)obj;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
790 sh_clear_flags(shape, GEF_OV_DRAW);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
791 return;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
792 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
793
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
794 root = (coord_t *)obj;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
795 FOR_COORDS_PREORDER(root, coord) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
796 FOR_COORD_SHAPES(coord, shape) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
797 sh_clear_flags(shape, GEF_OV_DRAW);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
798 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
799 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
800 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
801
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
802 /*! \brief Test if two objects are overlaid.
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
803 *
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
804 * \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
805 * \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
806 */
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
807 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
808 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
809 cairo_t *cr;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
810 area_t *area;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
811 shape_t *shape;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
812 coord_t *coord, *root;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
813 int r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
814
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
815 cr = _prepare_cairo_for_testing(rdman);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
816
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
817 if(IS_MBO_SHAPES(obj1)) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
818 shape = (shape_t *)obj1;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
819 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
820 goto out;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
821 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
822
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
823 root = (coord_t *)obj1;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
824 FOR_COORDS_PREORDER(root, coord) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
825 area = coord_get_area(coord);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
826 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
827 if(!r) {
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
828 preorder_coord_skip_subtree(coord);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
829 continue;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
830 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
831
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
832 FOR_COORD_SHAPES(coord, shape) {
232
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
833 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
834 if(r)
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
835 goto out;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
836 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
837 }
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
838 r = FALSE;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
839
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
840 out:
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
841 _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
842 _release_cairo_for_testing(cr);
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
843 return r;
527894c2ad39 Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
844 }
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
845
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
846 #ifdef UNITTEST
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
847
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
848 #include <CUnit/Basic.h>
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
849
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
850 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
851 redraw_man_t *_fake_rdman(void) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
852 redraw_man_t *rdman;
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
853 cairo_t *cr, *backend;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
854 cairo_surface_t *surf;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
855
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
856 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
857 cr = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
858 backend = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
859 rdman = redraw_man_new(cr, backend);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
860
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
861 return rdman;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
862 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
863
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
864 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
865 void _free_fake_rdman(redraw_man_t *rdman) {
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
866 cairo_surface_destroy(rdman->cr->tgt);
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
867 cairo_destroy(rdman->cr);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
868 free(rdman);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
869 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
870
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
871 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
872 void test_mb_obj_pos_is_in(void) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
873 redraw_man_t *rdman;
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
874 shape_t *shape;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
875 coord_t *root, *child_coord;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
876 int in_stroke = 0;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
877 int r;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
878
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
879 rdman = _fake_rdman();
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
880 CU_ASSERT(rdman != NULL);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
881
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
882 root = rdman_get_root(rdman);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
883
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
884 child_coord = rdman_coord_new(rdman, root);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
885 CU_ASSERT(child_coord != NULL);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
886
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
887 shape = rdman_shape_new(rdman);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
888 CU_ASSERT(shape != NULL);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
889
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
890 rdman_add_shape(rdman, shape, child_coord);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
891
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
892 shape_add_point(shape, 3, 12);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
893
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
894 shape->fill = shape;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
895 shape->stroke = shape;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
896
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
897 r = mb_obj_pos_is_in(rdman, (mb_obj_t *)shape, 3, 12, &in_stroke);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
898 CU_ASSERT(r == TRUE);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
899
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
900 r = mb_obj_pos_is_in(rdman, (mb_obj_t *)shape, 3, 13, &in_stroke);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
901 CU_ASSERT(r == FALSE);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
902
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
903 r = mb_obj_pos_is_in(rdman, (mb_obj_t *)root, 3, 12, &in_stroke);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
904 CU_ASSERT(r == TRUE);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
905
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
906 r = mb_obj_pos_is_in(rdman, (mb_obj_t *)root, 4, 12, &in_stroke);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
907 CU_ASSERT(r == FALSE);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
908
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
909 rdman_shape_free(rdman, shape);
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
910 _free_fake_rdman(rdman);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
911 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
912
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
913 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
914 void test_is_obj_objs_overlay(void) {
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
915 redraw_man_t *rdman;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
916 coord_t *root, *coord1, *coord2;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
917 shape_t *shape1, *shape2, *shape3;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
918 cairo_t *cr;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
919 cairo_surface_t *surf;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
920 int r;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
921
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
922 rdman = _fake_rdman();
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
923 CU_ASSERT(rdman != NULL);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
924
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
925 root = rdman_get_root(rdman);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
926
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
927 coord1 = rdman_coord_new(rdman, root);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
928 shape1 = rdman_shape_new(rdman);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
929 rdman_add_shape(rdman, shape1, coord1);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
930
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
931 coord2 = rdman_coord_new(rdman, root);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
932 shape2 = rdman_shape_new(rdman);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
933 rdman_add_shape(rdman, shape2, coord2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
934
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
935 shape3 = rdman_shape_new(rdman);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
936 rdman_add_shape(rdman, shape3, coord2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
937
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
938 shape_add_point(shape1, 3, 2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
939 shape_add_point(shape2, 5, 5);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
940 shape_add_point(shape3, 4, 3);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
941
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
942 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
943 cr = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
944 r = _is_obj_objs_overlay((mb_obj_t *)coord1, (mb_obj_t *)coord2, cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
945 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
946 cairo_destroy(cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
947 cairo_surface_destroy(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
948 sh_clear_flags(coord2, GEF_OV_DRAW);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
949
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
950 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
951 cr = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
952 r = _is_obj_objs_overlay((mb_obj_t *)shape1, (mb_obj_t *)coord2, cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
953 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
954 cairo_destroy(cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
955 cairo_surface_destroy(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
956 sh_clear_flags(coord2, GEF_OV_DRAW);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
957
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
958 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
959 cr = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
960 r = _is_obj_objs_overlay((mb_obj_t *)coord1, (mb_obj_t *)shape2, cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
961 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
962 cairo_destroy(cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
963 cairo_surface_destroy(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
964 sh_clear_flags(shape2, GEF_OV_DRAW);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
965
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
966 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
967 cr = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
968 r = _is_obj_objs_overlay((mb_obj_t *)shape1, (mb_obj_t *)shape2, cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
969 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
970 cairo_destroy(cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
971 cairo_surface_destroy(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
972 sh_clear_flags(shape2, GEF_OV_DRAW);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
973
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
974 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
975 cr = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
976 r = _is_obj_objs_overlay((mb_obj_t *)shape1, (mb_obj_t *)shape3, cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
977 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
978 cairo_destroy(cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
979 cairo_surface_destroy(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
980 sh_clear_flags(shape3, GEF_OV_DRAW);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
981
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
982 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
983 cr = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
984 r = _is_obj_objs_overlay((mb_obj_t *)coord1, (mb_obj_t *)shape3, cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
985 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
986 cairo_destroy(cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
987 cairo_surface_destroy(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
988 sh_clear_flags(shape3, GEF_OV_DRAW);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
989
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
990 shape_add_point(shape1, 5, 5);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
991
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
992 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
993 cr = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
994 r = _is_obj_objs_overlay((mb_obj_t *)coord1, (mb_obj_t *)coord2, cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
995 CU_ASSERT(r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
996 cairo_destroy(cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
997 cairo_surface_destroy(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
998 sh_clear_flags(coord2, GEF_OV_DRAW);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
999
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1000 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1001 cr = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1002 r = _is_obj_objs_overlay((mb_obj_t *)shape1, (mb_obj_t *)coord2, cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1003 CU_ASSERT(r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1004 cairo_destroy(cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1005 cairo_surface_destroy(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1006 sh_clear_flags(coord2, GEF_OV_DRAW);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1007
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1008 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1009 cr = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1010 r = _is_obj_objs_overlay((mb_obj_t *)coord1, (mb_obj_t *)shape2, cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1011 CU_ASSERT(r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1012 cairo_destroy(cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1013 cairo_surface_destroy(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1014 sh_clear_flags(shape2, GEF_OV_DRAW);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1015
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1016 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1017 cr = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1018 r = _is_obj_objs_overlay((mb_obj_t *)shape1, (mb_obj_t *)shape2, cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1019 CU_ASSERT(r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1020 cairo_destroy(cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1021 cairo_surface_destroy(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1022 sh_clear_flags(shape2, GEF_OV_DRAW);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1023
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1024 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1025 cr = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1026 r = _is_obj_objs_overlay((mb_obj_t *)shape1, (mb_obj_t *)shape3, cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1027 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1028 cairo_destroy(cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1029 cairo_surface_destroy(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1030 sh_clear_flags(shape3, GEF_OV_DRAW);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1031
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1032 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1033 cr = cairo_create(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1034 r = _is_obj_objs_overlay((mb_obj_t *)coord1, (mb_obj_t *)shape3, cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1035 CU_ASSERT(r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1036 cairo_destroy(cr);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1037 cairo_surface_destroy(surf);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1038 sh_clear_flags(shape3, GEF_OV_DRAW);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1039
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1040 rdman_shape_free(rdman, shape1);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1041 rdman_shape_free(rdman, shape2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1042 rdman_shape_free(rdman, shape3);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1043 rdman_coord_free(rdman, coord1);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1044 rdman_coord_free(rdman, coord2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1045 _free_fake_rdman(rdman);
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1046 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1047
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1048 static
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1049 void test_mb_objs_are_overlay(void) {
250
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1050 redraw_man_t *rdman;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1051 coord_t *root, *coord1, *coord2;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1052 shape_t *shape1, *shape2, *shape3;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1053 int r;
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1054
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1055 rdman = _fake_rdman();
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1056
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1057 root = rdman_get_root(rdman);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1058
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1059 coord1 = rdman_coord_new(rdman, root);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1060 shape1 = rdman_shape_new(rdman);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1061 rdman_add_shape(rdman, shape1, coord1);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1062
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1063 coord2 = rdman_coord_new(rdman, root);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1064 shape2 = rdman_shape_new(rdman);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1065 rdman_add_shape(rdman, shape2, coord2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1066
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1067 shape3 = rdman_shape_new(rdman);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1068 rdman_add_shape(rdman, shape3, coord2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1069
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1070 shape_add_point(shape1, 3, 2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1071 shape_add_point(shape2, 5, 5);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1072 shape_add_point(shape3, 4, 3);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1073
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1074 r = mb_objs_are_overlay(rdman, (mb_obj_t *)coord1, (mb_obj_t *)coord2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1075 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1076
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1077 r = mb_objs_are_overlay(rdman, (mb_obj_t *)shape1, (mb_obj_t *)coord2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1078 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1079
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1080 r = mb_objs_are_overlay(rdman, (mb_obj_t *)shape1, (mb_obj_t *)shape2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1081 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1082
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1083 r = mb_objs_are_overlay(rdman, (mb_obj_t *)coord1, (mb_obj_t *)shape2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1084 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1085
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1086 r = mb_objs_are_overlay(rdman, (mb_obj_t *)shape1, (mb_obj_t *)shape3);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1087 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1088
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1089 r = mb_objs_are_overlay(rdman, (mb_obj_t *)coord1, (mb_obj_t *)shape3);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1090 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1091
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1092 shape_add_point(shape1, 5, 5);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1093
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1094 r = mb_objs_are_overlay(rdman, (mb_obj_t *)coord1, (mb_obj_t *)coord2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1095 CU_ASSERT(r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1096
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1097 r = mb_objs_are_overlay(rdman, (mb_obj_t *)shape1, (mb_obj_t *)coord2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1098 CU_ASSERT(r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1099
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1100 r = mb_objs_are_overlay(rdman, (mb_obj_t *)shape1, (mb_obj_t *)shape2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1101 CU_ASSERT(r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1102
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1103 r = mb_objs_are_overlay(rdman, (mb_obj_t *)coord1, (mb_obj_t *)shape2);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1104 CU_ASSERT(r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1105
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1106 r = mb_objs_are_overlay(rdman, (mb_obj_t *)shape1, (mb_obj_t *)shape3);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1107 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1108
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1109 r = mb_objs_are_overlay(rdman, (mb_obj_t *)coord1, (mb_obj_t *)shape3);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1110 CU_ASSERT(!r);
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1111
bd8ea44b421e Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents: 241
diff changeset
1112 _free_fake_rdman(rdman);
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1113 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1114
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1115 CU_pSuite get_event_suite(void) {
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1116 CU_pSuite suite;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1117
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1118 suite = CU_add_suite("Suite_event", NULL, NULL);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1119 CU_ADD_TEST(suite, test_mb_obj_pos_is_in);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1120 CU_ADD_TEST(suite, test_is_obj_objs_overlay);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1121 CU_ADD_TEST(suite, test_mb_objs_are_overlay);
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1122
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1123 return suite;
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1124 }
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1125
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 232
diff changeset
1126 #endif /* UNITTEST */