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