annotate src/event.c @ 1512:89426a38752f

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