annotate src/event.c @ 1143:18d718a76a45

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