9 #include "mouse_buffer.h"
11 static list_t
*list_event
;
13 typedef struct mouse_event_struct
{
19 static mouse_event_t
*mouse_event_new(int x
, int y
, Uint8 button
)
21 mouse_event_t
*mouse_event
;
23 mouse_event
= malloc(sizeof(mouse_event_t
));
26 mouse_event
->button
= button
;
31 static void mouse_event_destroy(mouse_event_t
*mouse_event
)
33 assert(mouse_event
!= NULL
);
37 int mouse_buffer_init()
39 list_event
= list_new();
44 int mouse_buffer_event(SDL_MouseButtonEvent
*button
)
46 assert(button
!= NULL
);
47 assert(list_event
!= NULL
);
49 switch (button
->button
) {
51 case SDL_BUTTON_RIGHT
:
52 /*printf("mouse button - pos(%d,%d)\n", button->x, button->y);*/
54 list_add(list_event
, mouse_event_new(button
->x
, button
->y
, button
->button
));
66 int mouse_buffer_clean()
68 assert(list_event
!= NULL
);
70 list_destroy_item(list_event
, mouse_event_destroy
);
71 list_event
= list_new();
76 bool_t
mouse_buffer_is_on_area(int x
, int y
, int w
, int h
, unsigned int flag
)
78 mouse_event_t
*mouse_event
;
81 assert(list_event
!= NULL
);
83 if (flag
& MOUSE_BUF_MOTION
) {
86 SDL_GetMouseState(&mouse_x
, &mouse_y
);
88 if (mouse_x
>= x
&& mouse_y
>= y
&&
89 mouse_x
< x
+w
&& mouse_y
< y
+h
) {
93 for (i
= 0; i
< list_event
->count
; i
++) {
94 mouse_event
= (mouse_event_t
*) list_event
->list
[i
];
96 if ((mouse_event
->x
>= x
&& mouse_event
->y
>= y
&&
97 mouse_event
->x
< x
+ w
&& mouse_event
->y
< y
+ h
) ||
98 (flag
& MOUSE_BUF_AREA_NONE
)) {
99 if (flag
& MOUSE_BUF_CLICK_LEFT
) {
100 if (mouse_event
->button
== SDL_BUTTON_LEFT
) {
107 if (flag
& MOUSE_BUF_CLICK_RIGHT
) {
108 if (mouse_event
->button
== SDL_BUTTON_RIGHT
) {
115 if (flag
& MOUSE_BUF_CLICK
) {
116 if (mouse_event
->button
== SDL_BUTTON_LEFT
||
117 mouse_event
->button
== SDL_BUTTON_RIGHT
) {
132 int mouse_buffer_quit()
134 assert(list_event
!= NULL
);
135 list_destroy_item(list_event
, mouse_event_destroy
);