]> git.sur5r.net Git - cc65/blob - include/mouse.h
cdc3053153149c0d5533646a09235872d8dd2948
[cc65] / include / mouse.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  mouse.h                                  */
4 /*                                                                           */
5 /*                                 Mouse API                                 */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2003      Ullrich von Bassewitz                                       */
10 /*               Römerstraße 52                                              */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /*                                                                           */
16 /*                                                                           */
17 /* This software is provided 'as-is', without any expressed or implied       */
18 /* warranty.  In no event will the authors be held liable for any damages    */
19 /* arising from the use of this software.                                    */
20 /*                                                                           */
21 /* Permission is granted to anyone to use this software for any purpose,     */
22 /* including commercial applications, and to alter it and redistribute it    */
23 /* freely, subject to the following restrictions:                            */
24 /*                                                                           */
25 /* 1. The origin of this software must not be misrepresented; you must not   */
26 /*    claim that you wrote the original software. If you use this software   */
27 /*    in a product, an acknowledgment in the product documentation would be  */
28 /*    appreciated but is not required.                                       */
29 /* 2. Altered source versions must be plainly marked as such, and must not   */
30 /*    be misrepresented as being the original software.                      */
31 /* 3. This notice may not be removed or altered from any source              */
32 /*    distribution.                                                          */
33 /*                                                                           */
34 /*****************************************************************************/
35
36
37
38 #ifndef _MOUSE_H
39 #define _MOUSE_H
40
41
42
43 /*****************************************************************************/
44 /*                                Definitions                                */
45 /*****************************************************************************/
46
47
48
49 /* Error codes */
50 #define MOUSE_ERR_OK            0       /* No error */
51 #define MOUSE_ERR_NO_DRIVER     1       /* No driver available */
52 #define MOUSE_ERR_CANNOT_LOAD   2       /* Error loading driver */
53 #define MOUSE_ERR_INV_DRIVER    3       /* Invalid driver */
54 #define MOUSE_ERR_NO_DEVICE     4       /* Mouse hardware not found */
55
56 /* Mouse button masks */
57 #define MOUSE_BTN_LEFT       0x10
58 #define MOUSE_BTN_RIGHT      0x01
59
60 /* Structure containing the mouse coordinates */
61 struct mouse_pos {
62     int x;
63     int y;
64 };
65
66 /* Structure containing information about the mouse */
67 struct mouse_info {
68     struct mouse_pos    pos;           /* Mouse position */
69     unsigned char       buttons;       /* Mouse button mask */
70 };
71
72 /* Structure containing mouse callback functions. These functions are declared
73  * in C notation here, but they cannot be C functions (at least not easily),
74  * since they may be called from within an interrupt.
75  */
76 struct mouse_callbacks {
77
78     void (*hide) (void);
79     /* Hide the mouse cursor. */
80
81     void (*show) (void);
82     /* Show the mouse cursor */
83
84     void (*move) (void);
85     /* Move the mouse cursor. This function is called, even when the cursor
86      * is currently invisible.
87      */
88 };
89
90
91
92 /*****************************************************************************/
93 /*                                 Functions                                 */
94 /*****************************************************************************/
95
96
97
98 unsigned char __fastcall__ mouse_set_callbacks (const struct mouse_callbacks* c);
99 /* Sets the callbacks to be used by the driver. */
100
101 unsigned char __fastcall__ mouse_load_driver (const char* driver);
102 /* Load and install a mouse driver, return an error code. */
103
104 unsigned char __fastcall__ mouse_unload (void);
105 /* Uninstall, then unload the currently loaded driver. */
106
107 unsigned char __fastcall__ mouse_install (void* driver);
108 /* Install an already loaded driver. Returns an error code. */
109
110 unsigned char __fastcall__ mouse_uninstall (void);
111 /* Uninstall the currently loaded driver. Returns an error code. */
112
113 void __fastcall__ mouse_hide (void);
114 /* Hide the mouse. The function manages a counter and may be called more than
115  * once. For each call to mouse_hide there must be a call to mouse_show to make
116  * the mouse visible again.
117  */
118
119 void __fastcall__ mouse_show (void);
120 /* Show the mouse. See mouse_hide for more information. */
121
122 void __fastcall__ mouse_box (int minx, int miny, int maxx, int maxy);
123 /* Set the bounding box for the mouse pointer movement. The mouse X and Y
124  * coordinates will never go outside the given box.
125  * NOTE: The function does *not* check if the mouse is currently inside the
126  * given margins. The proper way to use this function therefore is:
127  *
128  *      - Hide the mouse
129  *      - Set the bounding box
130  *      - Place the mouse at the desired position
131  *      - Show the mouse again.
132  *
133  * NOTE2: When setting the box to something that is larger than the actual
134  * screen, the positioning of the mouse cursor will fail. If such margins
135  * are really what you want, you have to use your own cursor routines.
136  */
137
138 void __fastcall__ mouse_move (int x, int y);
139 /* Set the mouse cursor to the given position. If a mouse cursor is defined
140  * and currently visible, the mouse cursor is also moved.
141  * NOTE: This function does not check if the given position is valid and
142  * inside the bounding box.
143  */
144
145 unsigned char __fastcall__ mouse_buttons (void);
146 /* Return a bit mask encoding the states of the mouse buttons. Use the
147  * MOUSE_BTN_XXX flags to decode a specific button.
148  */
149
150 void __fastcall__ mouse_pos (struct mouse_pos* pos);
151 /* Return the current mouse position */
152
153 void __fastcall__ mouse_info (struct mouse_info* info);
154 /* Return the state of the mouse buttons and the position of the mouse */
155
156
157
158 /* End of mouse.h */
159 #endif
160
161
162