Mercurial > MadButterfly
annotate src/event.c @ 552:dd8d32b4c899 Android_Skia
rename ev_data to rt
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 06 Jun 2010 14:06:42 +0800 |
parents | 6e18550c8fa8 |
children | 1302b336add6 d2f2ed27b84d |
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 | 6 #ifndef UNITTEST |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
7 #include "mb_graph_engine.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 | 11 #endif |
467
6e18550c8fa8
Header file to config graphic engine
Thinker K.F. Li <thinker@branda.to>
parents:
466
diff
changeset
|
12 #include "config.h" |
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
|
13 |
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 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
|
15 #define ERR -1 |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
16 #define FALSE 0 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
17 #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
|
18 |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
75
diff
changeset
|
19 #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
|
20 |
235 | 21 #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
|
22 |
235 | 23 #ifdef UNITTEST |
24 /* ============================================================ */ | |
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
|
25 #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
|
26 #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
|
27 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
28 typedef float co_aix; |
235 | 29 |
30 typedef struct shape shape_t; | |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
31 typedef struct _mbe_surface mbe_surface_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
|
32 typedef struct coord coord_t; |
235 | 33 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
34 typedef struct _mbe mbe_t; |
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
35 struct _mbe { |
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
|
36 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
|
37 STAILQ(shape_t) clip_pathes; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
38 mbe_surface_t *tgt; |
235 | 39 }; |
40 | |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
41 struct _mbe_surface { |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
42 mbe_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
|
43 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
|
44 unsigned char *data; |
235 | 45 }; |
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
|
46 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
47 #define mbe_new_path(cr) do { STAILQ_CLEAN((cr)->drawed); } while(0) |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
48 #define mbe_get_target(cr) (cr)->tgt |
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
|
49 static |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
50 mbe_t *mbe_create(mbe_surface_t *target) { |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
51 mbe_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
|
52 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
53 cr = (mbe_t *)malloc(sizeof(mbe_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
|
54 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
|
55 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
|
56 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
|
57 target->cr = cr; |
235 | 58 |
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
|
59 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
|
60 } |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
61 #define mbe_destroy(cr) do { free(cr); } while(0) |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
62 #define mbe_clip(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
|
63 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
|
64 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
|
65 &(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 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
|
67 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
|
68 } while(0) |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
69 #define mbe_fill(cr) |
235 | 70 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
71 #define mbe_image_surface_get_width(surface) (surface)->w |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
72 #define mbe_image_surface_get_height(surface) (surface)->h |
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
|
73 static |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
74 mbe_surface_t *mbe_image_surface_create(int format, int w, int h) { |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
75 mbe_surface_t *surf; |
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
|
76 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
77 surf = (mbe_surface_t *)malloc(sizeof(mbe_surface_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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 |
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 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
|
84 } |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
85 #define mbe_surface_destroy(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
|
86 do { free((surface)->data); free(surface); } while(0) |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
87 #define mbe_image_surface_get_stride(surface) 1 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
88 #undef MB_IFMT_A1 |
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
89 #define MB_IFMT_A1 1 |
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
|
90 |
235 | 91 |
92 typedef struct _area area_t; | |
93 struct _area { | |
94 co_aix x, y; | |
95 co_aix w, h; | |
96 }; | |
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
|
97 #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
|
98 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
|
99 (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
|
100 (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
|
101 (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
|
102 (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
|
103 } 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
|
104 #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
|
105 #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
|
106 (_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
|
107 #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
|
108 (_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
|
109 (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
|
110 _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
|
111 (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
|
112 #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
|
113 (_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
|
114 _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
|
115 #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
|
116 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
|
117 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
|
118 (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
|
119 (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
|
120 } else { \ |
408
7f7855df2af0
Make unittest built by automake and autoconf.
Thinker K.F. Li <thinker@branda.to>
parents:
314
diff
changeset
|
121 (w) = MB_MAX(w, (a) - (s) + 1); \ |
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
|
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 } 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
|
124 |
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 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
|
126 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
|
127 _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
|
128 _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
|
129 } |
235 | 130 |
131 struct mb_obj { | |
132 int obj_type; | |
133 }; | |
134 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
|
135 #define MB_OBJ_INIT(obj, type) do { (obj)->obj_type = type; } while(0) |
235 | 136 |
137 #define GEF_OV_DRAW 0x1 | |
138 #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
|
139 |
235 | 140 struct shape { |
141 mb_obj_t obj; | |
142 | |
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 coord_t *coord; |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
144 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
|
145 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
|
146 shape_t *drawed_next; |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
147 |
235 | 148 void *fill, *stroke; |
149 struct shape *sibling; | |
150 int flags; | |
151 | |
152 int num_points; | |
153 co_aix points[32][2]; | |
154 }; | |
155 enum { MBO_DUMMY, | |
156 MBO_COORD, | |
157 MBO_SHAPES=0x1000, | |
158 MBO_PATH, | |
159 MBO_TEXT, | |
408
7f7855df2af0
Make unittest built by automake and autoconf.
Thinker K.F. Li <thinker@branda.to>
parents:
314
diff
changeset
|
160 MBO_RECT, |
439
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
161 MBO_IMAGE, |
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
162 MBO_STEXT |
235 | 163 }; |
164 #define MBO_TYPE(x) (((mb_obj_t *)(x))->obj_type) | |
165 #define IS_MBO_SHAPES(x) (((mb_obj_t *)(x))->obj_type & MBO_SHAPES) | |
166 #define sh_get_geo(x) ((x)->geo) | |
167 static int sh_pos_is_in(shape_t *shape, co_aix x, co_aix y) { | |
168 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
|
169 |
235 | 170 for(i = 0; i < shape->num_points; i++) |
171 if(shape->points[i][0] == x && shape->points[i][1] == y) | |
172 return TRUE; | |
173 return FALSE; | |
174 } | |
175 #define sh_get_flags(shape, mask) ((shape)->flags & mask) | |
176 #define sh_set_flags(shape, mask) do { (shape)->flags |= mask; } while(0) | |
177 #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
|
178 #define sh_get_area(shape) (&(shape)->area) |
235 | 179 |
180 struct coord { | |
181 mb_obj_t obj; | |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
182 |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
183 area_t area; |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
184 int flags; |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
185 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
|
186 STAILQ(coord_t) children; |
235 | 187 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
|
188 STAILQ(shape_t) shapes; |
235 | 189 }; |
190 | |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
191 #define COF_SKIP 0x1 |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
192 |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
193 #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
|
194 #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
|
195 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
|
196 (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
|
197 (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
|
198 #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
|
199 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
|
200 (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
|
201 (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
|
202 #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
|
203 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
|
204 (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
|
205 (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
|
206 |
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 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
|
208 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
|
209 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
|
210 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
|
211 |
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 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 } |
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 |
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 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 |
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 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
|
228 |
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 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
|
230 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
|
231 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
|
232 } 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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 } |
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 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
|
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 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
|
241 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
|
242 _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
|
243 } |
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 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
|
246 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
|
247 _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
|
248 } |
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 } |
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 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
|
252 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
|
253 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
|
254 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
255 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
|
256 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
|
257 } |
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 } |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
259 |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
260 static |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
261 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
|
262 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
|
263 return STAILQ_HEAD(last->children); |
314
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
264 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
265 last->flags &= ~COF_SKIP; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
266 |
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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 return NULL; |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
272 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
|
273 } |
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 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
|
275 } |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
276 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
277 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
|
278 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
|
279 coord->flags |= COF_SKIP; |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
280 } |
235 | 281 |
282 static | |
283 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
|
284 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
|
285 |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
286 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
|
287 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
|
288 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
|
289 return NULL; |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
290 cur = last->parent; |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
291 return cur; |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
292 } |
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
|
293 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
|
294 } |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
295 |
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
|
296 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
|
297 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
|
298 cur = STAILQ_HEAD(cur->children); |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
299 } |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
300 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
|
301 } |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
302 |
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
|
303 static |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
304 void shape_draw(shape_t *sh, mbe_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
|
305 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
|
306 } |
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 |
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 #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
|
309 #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
|
310 #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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
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 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
|
318 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
|
319 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
|
320 } |
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 |
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_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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 } |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
328 } |
235 | 329 |
330 | |
331 struct redraw_man { | |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
332 mbe_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
|
333 coord_t *root_coord; |
235 | 334 int shape_gl_sz; |
335 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
|
336 STAILQ(shape_t) all_shapes; |
235 | 337 }; |
338 typedef struct redraw_man redraw_man_t; | |
339 #define rdman_get_cr(rdman) ((rdman)->cr) | |
340 #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
|
341 #define rdman_clear_shape_gl(rdman) do {(rdman)->shape_gl_sz = 0; } while(0) |
235 | 342 static int rdman_add_shape_gl(redraw_man_t *rdman, shape_t *shape) { |
343 (rdman)->shape_gl[(rdman)->shape_gl_sz++] = shape; | |
344 return OK; | |
345 } | |
346 #define rdman_get_shape_gl(rdman, idx) \ | |
347 (rdman)->shape_gl[idx] | |
348 #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
|
349 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
|
350 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
|
351 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
|
352 |
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 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
|
354 } |
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 #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
|
356 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
|
357 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
|
358 (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
|
359 (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
|
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 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
|
362 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
|
363 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
|
364 } 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
|
365 #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
|
366 |
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 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
|
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 static |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
370 redraw_man_t *redraw_man_new(mbe_t *cr, mbe_t *backend) { |
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
|
371 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
|
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 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
|
374 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
|
375 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
|
376 } |
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 #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
|
378 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
|
379 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
|
380 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
|
381 } 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
|
382 |
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 static |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
384 int mbe_in_fill(mbe_t *cr, int x, int y) { |
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
|
385 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
|
386 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
|
387 |
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 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
|
389 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 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
|
395 } |
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 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
|
397 } |
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 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
399 #define mbe_in_stroke mbe_in_fill |
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
|
400 |
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 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
|
402 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
|
403 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
|
404 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
|
405 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
|
406 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
|
407 } |
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 |
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 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
|
410 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
|
411 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
|
412 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
|
413 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
|
414 } |
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 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
|
417 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
|
418 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
|
419 |
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 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
|
421 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
|
422 |
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 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
|
424 } |
235 | 425 |
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
|
426 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
|
427 coord_t *coord; |
235 | 428 |
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
|
429 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
|
430 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
|
431 |
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 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
|
433 } |
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 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
|
436 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
|
437 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
|
438 } |
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 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
|
441 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
|
442 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
|
443 |
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 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
|
445 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
|
446 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
|
447 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
|
448 |
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 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
|
450 } |
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 |
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 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
|
453 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
|
454 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
|
455 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
|
456 } |
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 |
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 #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
|
459 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
|
460 (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
|
461 (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
|
462 (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
|
463 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
|
464 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
|
465 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
|
466 } 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
|
467 |
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 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 |
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 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
|
475 } |
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 |
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 static |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
478 void *mbe_image_surface_get_data(mbe_surface_t *surf) { |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
479 mbe_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
|
480 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
|
481 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
|
482 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
|
483 |
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 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
|
485 |
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->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
|
487 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
|
488 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
|
489 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
|
490 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
|
491 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
|
492 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
|
493 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
|
494 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
|
495 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
|
496 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
|
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 } |
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 } |
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 } |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
501 } |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
502 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
|
503 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
|
504 } |
235 | 505 /* ============================================================ */ |
506 #endif /* UNITTEST */ | |
507 | |
508 | |
509 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
|
510 co_aix x, co_aix y) { |
235 | 511 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
|
512 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
|
513 |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
514 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
|
515 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
|
516 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
|
517 |
235 | 518 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
|
519 |
235 | 520 for(shape = rdman_shapes(rdman, (shape_t *)NULL); |
521 shape != NULL; | |
522 shape = rdman_shapes(rdman, shape)) { | |
523 if(sh_pos_is_in(shape, x, y)) { | |
524 r = rdman_add_shape_gl(rdman, shape); | |
525 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
|
526 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
|
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 |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
530 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
|
531 } |
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 |
439
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
533 /*! \brief Draw path of a shape. |
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
534 * |
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
535 * \note This function should be merged with what is in redraw_man.c. |
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
536 */ |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
537 static void draw_shape_path(shape_t *shape, mbe_t *cr) { |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
538 switch(MBO_TYPE(shape)) { |
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
539 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
|
540 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
|
541 break; |
439
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
542 #ifdef SH_TEXT |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
543 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
|
544 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
|
545 break; |
439
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
546 #endif |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
547 case MBO_RECT: |
35
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
32
diff
changeset
|
548 sh_rect_draw(shape, cr); |
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
32
diff
changeset
|
549 break; |
260
29acbd8a0dd0
Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
251
diff
changeset
|
550 case MBO_IMAGE: |
29acbd8a0dd0
Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
251
diff
changeset
|
551 sh_image_draw(shape, cr); |
29acbd8a0dd0
Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
251
diff
changeset
|
552 break; |
439
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
553 #ifdef SH_STEXT |
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
554 case MBO_STEXT: |
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
555 sh_stext_draw(shape, cr); |
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
556 break; |
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
557 #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
|
558 } |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
559 } |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
560 |
451
5c9e2a8a4bd8
Remove all "cairo" wording.
Thinker K.F. Li <thinker@branda.to>
parents:
450
diff
changeset
|
561 /*! \brief Implement exactly point testing with MB graphic engine. |
439
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
562 * |
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
563 * \note This function should not be called directly. Call |
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
564 * _shape_pos_is_in() insteaded. |
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
565 */ |
451
5c9e2a8a4bd8
Remove all "cairo" wording.
Thinker K.F. Li <thinker@branda.to>
parents:
450
diff
changeset
|
566 static int _shape_pos_is_in_mbe(shape_t *shape, co_aix x, co_aix y, |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
567 int *in_stroke, mbe_t *cr) { |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
568 draw_shape_path(shape, cr); |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
569 if(shape->fill) { |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
570 if(mbe_in_fill(cr, x, y)) { |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
571 *in_stroke = 0; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
572 return TRUE; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
573 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
574 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
575 if(shape->stroke) { |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
576 if(mbe_in_stroke(cr, x, y)) { |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
577 *in_stroke = 1; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
578 return TRUE; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
579 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
580 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
581 return FALSE; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
582 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
583 |
438 | 584 /*! \brief Find all shapes whose bounding box include a specified position. |
585 */ | |
235 | 586 static |
587 int _shape_pos_is_in(shape_t *shape, co_aix x, co_aix y, | |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
588 int *in_stroke, mbe_t *cr) { |
235 | 589 int r; |
590 | |
591 r = sh_pos_is_in(shape, x, y); | |
592 if(!r) | |
593 return FALSE; | |
594 | |
451
5c9e2a8a4bd8
Remove all "cairo" wording.
Thinker K.F. Li <thinker@branda.to>
parents:
450
diff
changeset
|
595 r = _shape_pos_is_in_mbe(shape, x, y, in_stroke, cr); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
596 mbe_new_path(cr); |
235 | 597 if(!r) |
598 return FALSE; | |
599 | |
600 return TRUE; | |
601 } | |
602 | |
438 | 603 /*! \brief Find first shape that is draw at a specified position. |
604 */ | |
235 | 605 static shape_t *_find_shape_in_pos(redraw_man_t *rdman, |
606 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
|
607 shape_t *shape; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
608 mbe_t *cr; |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
609 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
|
610 |
235 | 611 cr = rdman_get_cr(rdman); |
612 for(i = rdman_shape_gl_len(rdman) - 1; i >= 0; i--) { | |
613 shape = rdman_get_shape_gl(rdman, i); | |
614 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
|
615 continue; |
439
254854ed479c
Fix bug of _find_shape_in_pos().
Thinker K.F. Li <thinker@branda.to>
parents:
438
diff
changeset
|
616 r = _shape_pos_is_in(shape, x, y, in_stroke, cr); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
617 if(r) |
235 | 618 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
|
619 } |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
620 |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
621 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
|
622 } |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
623 |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
624 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
|
625 co_aix x, co_aix y, int *in_stroke) { |
235 | 626 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
|
627 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
|
628 |
235 | 629 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
|
630 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
|
631 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
|
632 |
235 | 633 shape = _find_shape_in_pos(rdman, x, y, in_stroke); |
634 return shape; | |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
635 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
636 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
637 /*! \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
|
638 * specified by x,y. |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
639 * |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
640 * \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
|
641 */ |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
642 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
|
643 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
|
644 coord_t *cur_coord, *root; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
645 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
|
646 area_t *area; |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
647 int r; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
648 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
649 if(IS_MBO_SHAPES(obj)) { |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
650 shape = (shape_t *)obj; |
235 | 651 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
|
652 return r; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
653 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 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
|
658 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
|
659 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
|
660 } |
235 | 661 FOR_COORD_SHAPES(cur_coord, shape) { |
662 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
|
663 if(r) |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
664 return TRUE; |
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 return FALSE; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
668 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
669 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
670 static |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
671 mbe_t * _prepare_mbe_for_testing(redraw_man_t *rdman) { |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
672 mbe_surface_t *surface, *rdman_surface; |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
673 mbe_t *cr; |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
674 int w, h; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
675 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
676 rdman_surface = mbe_get_target(rdman_get_cr(rdman)); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
677 w = mbe_image_surface_get_width(rdman_surface); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
678 h = mbe_image_surface_get_height(rdman_surface); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
679 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
680 surface = mbe_image_surface_create(MB_IFMT_A1, w, h); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
681 if(surface == NULL) |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
682 return NULL; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
683 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
684 cr = mbe_create(surface); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
685 if(cr == NULL) |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
686 mbe_surface_destroy(surface); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
687 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
688 return cr; |
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 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
691 static |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
692 void _release_mbe_for_testing(mbe_t *cr) { |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
693 mbe_destroy(cr); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
694 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
695 |
235 | 696 static |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
697 void _draw_to_mask(shape_t *shape, mbe_t *cr) { |
235 | 698 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
|
699 return; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
700 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
701 draw_shape_path(shape, cr); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
702 mbe_clip(cr); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
703 |
235 | 704 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
|
705 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
706 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
707 static |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
708 int _fill_and_check(shape_t *shape, mbe_t *cr) { |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
709 int h, stride; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
710 mbe_surface_t *surface; |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
711 unsigned char *data; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
712 int i, sz; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
713 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
714 draw_shape_path(shape, cr); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
715 mbe_fill(cr); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
716 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
717 surface = mbe_get_target(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
718 data = mbe_image_surface_get_data(surface); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
719 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
720 h = mbe_image_surface_get_height(surface); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
721 stride = mbe_image_surface_get_stride(surface); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
722 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
723 sz = stride * h; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
724 for(i = 0; i < sz; i++) { |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
725 if(data[i]) |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
726 return TRUE; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
727 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
728 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
729 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
|
730 } |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
731 |
235 | 732 /*! \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
|
733 * descendants. |
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 * coord is relative less than shapes. Check areas of coord can |
235 | 736 * skip sub-trees and avoid useless heavy computation. For shapes, |
737 * it not only check overlay of area. It also check overlay by | |
451
5c9e2a8a4bd8
Remove all "cairo" wording.
Thinker K.F. Li <thinker@branda.to>
parents:
450
diff
changeset
|
738 * actually drawing on a mbe surface. |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
739 */ |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
740 static |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
741 int _is_obj_objs_overlay(mb_obj_t *obj, mb_obj_t *others_root, |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
742 mbe_t *cr) { |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
743 area_t *area, *candi_area; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
744 coord_t *coord, *candi_coord, *root; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
745 shape_t *shape, *candi_shape; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
746 int obj_is_shape; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
747 int r; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
748 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
749 obj_is_shape = IS_MBO_SHAPES(obj); |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
750 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
751 if(obj_is_shape) { |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
752 shape = (shape_t *)obj; |
235 | 753 area = sh_get_area(shape); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
754 } else { |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
755 coord = (coord_t *)obj; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
756 area = coord_get_area(coord); |
251
f08b3ba9c1d8
Remove potential memory address error.
Thinker K.F. Li <thinker@branda.to>
parents:
250
diff
changeset
|
757 shape = NULL; |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
758 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
759 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
760 if(IS_MBO_SHAPES(others_root)) { |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
761 candi_shape = (shape_t *)others_root; |
235 | 762 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
|
763 |
235 | 764 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
|
765 if(!r) |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
766 return FALSE; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
767 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
768 if(!obj_is_shape) |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
769 return TRUE; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
770 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
771 _draw_to_mask(candi_shape, cr); |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
772 r = _fill_and_check(shape, cr); |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
773 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
774 return r; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
775 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
776 |
235 | 777 ASSERT(IS_MBO_COORD(others_root)); |
778 | |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
779 root = (coord_t *)others_root; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
780 FOR_COORDS_PREORDER(root, candi_coord) { |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
781 candi_area = coord_get_area(candi_coord); |
235 | 782 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
|
783 if(!r) { |
235 | 784 preorder_coord_skip_subtree(candi_coord); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
785 continue; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
786 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
787 |
235 | 788 FOR_COORD_SHAPES(candi_coord, candi_shape) { |
789 candi_area = sh_get_area(candi_shape); | |
790 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
|
791 if(!r) |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
792 continue; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
793 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
794 if(!obj_is_shape) |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
795 return TRUE; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
796 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
797 _draw_to_mask(candi_shape, cr); |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
798 r = _fill_and_check(shape, cr); |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
799 if(r) |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
800 return TRUE; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
801 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
802 } |
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 return FALSE; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
805 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
806 |
235 | 807 static |
808 void _clear_ov_draw(mb_obj_t *obj) { | |
809 coord_t *coord, *root; | |
810 shape_t *shape; | |
811 | |
812 if(IS_MBO_SHAPES(obj)) { | |
813 shape = (shape_t *)obj; | |
814 sh_clear_flags(shape, GEF_OV_DRAW); | |
815 return; | |
816 } | |
817 | |
818 root = (coord_t *)obj; | |
819 FOR_COORDS_PREORDER(root, coord) { | |
820 FOR_COORD_SHAPES(coord, shape) { | |
821 sh_clear_flags(shape, GEF_OV_DRAW); | |
822 } | |
823 } | |
824 } | |
825 | |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
826 /*! \brief Test if two objects are overlaid. |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
827 * |
451
5c9e2a8a4bd8
Remove all "cairo" wording.
Thinker K.F. Li <thinker@branda.to>
parents:
450
diff
changeset
|
828 * \todo Detect overlay in better way with mbe. |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
829 * \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
|
830 */ |
235 | 831 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
|
832 mb_obj_t *obj1, mb_obj_t *obj2) { |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
833 mbe_t *cr; |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
834 area_t *area; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
835 shape_t *shape; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
836 coord_t *coord, *root; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
837 int r; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
838 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
839 cr = _prepare_mbe_for_testing(rdman); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
840 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
841 if(IS_MBO_SHAPES(obj1)) { |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
842 shape = (shape_t *)obj1; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
843 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
|
844 goto out; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
845 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
846 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
847 root = (coord_t *)obj1; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
848 FOR_COORDS_PREORDER(root, coord) { |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
849 area = coord_get_area(coord); |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
850 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
|
851 if(!r) { |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
852 preorder_coord_skip_subtree(coord); |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
853 continue; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
854 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
855 |
235 | 856 FOR_COORD_SHAPES(coord, shape) { |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
857 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
|
858 if(r) |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
859 goto out; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
860 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
861 } |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
862 r = FALSE; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
863 |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
864 out: |
235 | 865 _clear_ov_draw(obj2); /* marked by _is_obj_objs_overlay() */ |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
866 _release_mbe_for_testing(cr); |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
867 return r; |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
868 } |
235 | 869 |
870 #ifdef UNITTEST | |
871 | |
872 #include <CUnit/Basic.h> | |
873 | |
874 static | |
875 redraw_man_t *_fake_rdman(void) { | |
876 redraw_man_t *rdman; | |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
877 mbe_t *cr, *backend; |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
878 mbe_surface_t *surf; |
235 | 879 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
880 surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
881 cr = mbe_create(surf); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
882 backend = mbe_create(surf); |
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
|
883 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
|
884 |
235 | 885 return rdman; |
886 } | |
887 | |
888 static | |
889 void _free_fake_rdman(redraw_man_t *rdman) { | |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
890 mbe_surface_destroy(rdman->cr->tgt); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
891 mbe_destroy(rdman->cr); |
235 | 892 free(rdman); |
893 } | |
894 | |
895 static | |
896 void test_mb_obj_pos_is_in(void) { | |
897 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
|
898 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
|
899 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
|
900 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
|
901 int r; |
235 | 902 |
903 rdman = _fake_rdman(); | |
904 CU_ASSERT(rdman != NULL); | |
905 | |
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
|
906 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
|
907 |
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 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
|
909 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
|
910 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
911 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
|
912 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
|
913 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
914 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
|
915 |
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 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
|
917 |
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 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
|
919 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
|
920 |
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 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
|
922 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
|
923 |
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 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
|
925 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
|
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 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
|
928 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
|
929 |
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 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
|
931 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
|
932 |
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_shape_free(rdman, shape); |
235 | 934 _free_fake_rdman(rdman); |
935 } | |
936 | |
937 static | |
938 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
|
939 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
|
940 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
|
941 shape_t *shape1, *shape2, *shape3; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
942 mbe_t *cr; |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
943 mbe_surface_t *surf; |
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
|
944 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
|
945 |
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 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
|
947 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
|
948 |
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 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
|
950 |
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 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
|
952 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
|
953 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
|
954 |
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 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
|
956 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
|
957 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
|
958 |
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 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
|
960 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
|
961 |
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 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
|
963 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
|
964 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
|
965 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
966 surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
967 cr = mbe_create(surf); |
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
|
968 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
|
969 CU_ASSERT(!r); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
970 mbe_destroy(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
971 mbe_surface_destroy(surf); |
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
|
972 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
|
973 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
974 surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
975 cr = mbe_create(surf); |
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
|
976 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
|
977 CU_ASSERT(!r); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
978 mbe_destroy(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
979 mbe_surface_destroy(surf); |
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
|
980 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
|
981 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
982 surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
983 cr = mbe_create(surf); |
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
|
984 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
|
985 CU_ASSERT(!r); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
986 mbe_destroy(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
987 mbe_surface_destroy(surf); |
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
|
988 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
|
989 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
990 surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
991 cr = mbe_create(surf); |
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
|
992 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
|
993 CU_ASSERT(!r); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
994 mbe_destroy(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
995 mbe_surface_destroy(surf); |
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
|
996 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
|
997 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
998 surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
999 cr = mbe_create(surf); |
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
|
1000 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
|
1001 CU_ASSERT(!r); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1002 mbe_destroy(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1003 mbe_surface_destroy(surf); |
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
|
1004 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
|
1005 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1006 surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1007 cr = mbe_create(surf); |
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
|
1008 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
|
1009 CU_ASSERT(!r); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1010 mbe_destroy(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1011 mbe_surface_destroy(surf); |
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
|
1012 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
|
1013 |
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 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
|
1015 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1016 surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1017 cr = mbe_create(surf); |
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
|
1018 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
|
1019 CU_ASSERT(r); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1020 mbe_destroy(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1021 mbe_surface_destroy(surf); |
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
|
1022 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
|
1023 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1024 surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1025 cr = mbe_create(surf); |
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
|
1026 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
|
1027 CU_ASSERT(r); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1028 mbe_destroy(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1029 mbe_surface_destroy(surf); |
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
|
1030 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
|
1031 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1032 surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1033 cr = mbe_create(surf); |
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
|
1034 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
|
1035 CU_ASSERT(r); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1036 mbe_destroy(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1037 mbe_surface_destroy(surf); |
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
|
1038 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
|
1039 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1040 surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1041 cr = mbe_create(surf); |
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
|
1042 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
|
1043 CU_ASSERT(r); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1044 mbe_destroy(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1045 mbe_surface_destroy(surf); |
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
|
1046 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
|
1047 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1048 surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1049 cr = mbe_create(surf); |
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 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
|
1051 CU_ASSERT(!r); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1052 mbe_destroy(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1053 mbe_surface_destroy(surf); |
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
|
1054 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
|
1055 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1056 surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1057 cr = mbe_create(surf); |
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
|
1058 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
|
1059 CU_ASSERT(r); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1060 mbe_destroy(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
439
diff
changeset
|
1061 mbe_surface_destroy(surf); |
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
|
1062 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
|
1063 |
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 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
|
1065 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
|
1066 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
|
1067 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
|
1068 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
|
1069 _free_fake_rdman(rdman); |
235 | 1070 } |
1071 | |
1072 static | |
1073 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
|
1074 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
|
1075 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
|
1076 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
|
1077 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
|
1078 |
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 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
|
1080 |
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 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
|
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 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
|
1084 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
|
1085 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
|
1086 |
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 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
|
1088 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
|
1089 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
|
1090 |
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 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
|
1092 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
|
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 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
|
1095 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
|
1096 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
|
1097 |
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 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
|
1099 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
|
1100 |
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 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
|
1102 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
|
1103 |
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 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
|
1105 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
|
1106 |
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 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
|
1108 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
|
1109 |
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 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
|
1111 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
|
1112 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
1113 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
|
1114 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
|
1115 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
1116 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
|
1117 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
1118 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
|
1119 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
|
1120 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
1121 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
|
1122 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
|
1123 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
1124 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
|
1125 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
|
1126 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
1127 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
|
1128 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
|
1129 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
1130 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
|
1131 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
|
1132 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
1133 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
|
1134 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
|
1135 |
bd8ea44b421e
Fix bug and finish unit test for collision testing in event.c.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
1136 _free_fake_rdman(rdman); |
235 | 1137 } |
1138 | |
1139 CU_pSuite get_event_suite(void) { | |
1140 CU_pSuite suite; | |
1141 | |
1142 suite = CU_add_suite("Suite_event", NULL, NULL); | |
1143 CU_ADD_TEST(suite, test_mb_obj_pos_is_in); | |
1144 CU_ADD_TEST(suite, test_is_obj_objs_overlay); | |
1145 CU_ADD_TEST(suite, test_mb_objs_are_overlay); | |
1146 | |
1147 return suite; | |
1148 } | |
1149 | |
1150 #endif /* UNITTEST */ |