1 /*	Public domain	*/
2 
3 #ifndef _AGAR_GUI_MOUSE_H_
4 #define _AGAR_GUI_MOUSE_H_
5 #include <agar/gui/input_device.h>
6 #include <agar/gui/begin.h>
7 
8 typedef enum ag_mouse_button {
9 	AG_MOUSE_NONE		= 0x00,
10 	AG_MOUSE_LEFT		= 0x01,
11 	AG_MOUSE_MIDDLE		= 0x02,
12 	AG_MOUSE_RIGHT		= 0x03,
13 	AG_MOUSE_WHEELUP	= 0x04,
14 	AG_MOUSE_WHEELDOWN	= 0x05,
15 	AG_MOUSE_X1		= 0x06,
16 	AG_MOUSE_X2		= 0x07,
17 	AG_MOUSE_ANY		= 0xff
18 } AG_MouseButton;
19 
20 typedef enum ag_mouse_button_action {
21 	AG_BUTTON_PRESSED,
22 	AG_BUTTON_RELEASED
23 } AG_MouseButtonAction;
24 
25 #define AG_MOUSE_BUTTON(b)	(1<<((b)-1))
26 #define AG_MOUSE_LMASK		AG_MOUSE_BUTTON(1)
27 #define AG_MOUSE_MMASK		AG_MOUSE_BUTTON(2)
28 #define AG_MOUSE_RMASK		AG_MOUSE_BUTTON(3)
29 
30 struct ag_window;
31 
32 typedef struct ag_mouse {
33 	struct ag_input_device _inherit;
34 	Uint nButtons;		/* Button count (0 = unknown) */
35 	Uint btnState;		/* Last button state (AG_MouseButton) */
36 	int x, y;		/* Last cursor position */
37 	int xRel, yRel;		/* Last relative motion */
38 } AG_Mouse;
39 
40 __BEGIN_DECLS
41 extern AG_ObjectClass agMouseClass;
42 
43 AG_Mouse *AG_MouseNew(void *, const char *);
44 void      AG_MouseMotionUpdate(AG_Mouse *, int, int);
45 void      AG_MouseCursorUpdate(struct ag_window *, int, int);
46 void      AG_MouseButtonUpdate(AG_Mouse *, AG_MouseButtonAction, int);
47 void      AG_ProcessMouseMotion(struct ag_window *, int, int, int, int, Uint);
48 void      AG_ProcessMouseButtonUp(struct ag_window *, int, int, AG_MouseButton);
49 void      AG_ProcessMouseButtonDown(struct ag_window *, int, int, AG_MouseButton);
50 
51 static __inline__ Uint8
AG_MouseGetState(AG_Mouse * ms,int * x,int * y)52 AG_MouseGetState(AG_Mouse *ms, int *x, int *y)
53 {
54 	if (x != NULL) { *x = ms->x; }
55 	if (y != NULL) { *y = ms->y; }
56 	return (ms->btnState);
57 }
58 __END_DECLS
59 
60 #include <agar/gui/close.h>
61 #endif /* _AGAR_GUI_MOUSE_H_ */
62