]> git.sur5r.net Git - cc65/blob - include/mouse.h
Merge branch 'master' into lightpen
[cc65] / include / mouse.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  mouse.h                                  */
4 /*                                                                           */
5 /*                                 Mouse API                                 */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2003-2013, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 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 #define MOUSE_ERR_INV_IOCTL     5       /* Invalid ioctl code */
56
57 /* Mouse button masks */
58 #define MOUSE_BTN_LEFT       0x10
59 #define MOUSE_BTN_RIGHT      0x01
60
61 /* Structure containing the mouse coordinates */
62 struct mouse_pos {
63     int                 x;
64     int                 y;
65 };
66
67 /* Structure containing information about the mouse */
68 struct mouse_info {
69     struct mouse_pos    pos;           /* Mouse position */
70     unsigned char       buttons;       /* Mouse button mask */
71 };
72
73 /* Structure used for getbox/setbox */
74 struct mouse_box {
75     int                 minx;
76     int                 miny;
77     int                 maxx;
78     int                 maxy;
79 };
80
81 /* Structure containing mouse callback functions. These functions are declared
82  * in C notation here, but they cannot be C functions (at least not easily),
83  * since they may be called from within an interrupt.
84  */
85 struct mouse_callbacks {
86
87     void (*hide) (void);
88     /* Hide the mouse cursor. */
89
90     void (*show) (void);
91     /* Show the mouse cursor */
92
93     void __fastcall__ (*movex) (int x);
94     /* Move the mouse cursor to the new X coordinate. This function is called,
95      * even when the cursor is currently invisible.
96      */
97
98     void __fastcall__ (*movey) (int y);
99     /* Move the mouse cursor to the new Y coordinate. This function is called,
100      * even when the cursor is currently invisible.
101      */
102 };
103
104
105
106 /*****************************************************************************/
107 /*                               Declarations                                */
108 /*****************************************************************************/
109
110
111
112 /* The default mouse callbacks */
113 extern const struct mouse_callbacks mouse_def_callbacks;
114
115 /* The name of the standard mouse driver for a platform */
116 extern const char mouse_stddrv[];
117
118 /* The address of the static standard mouse driver for a platform */
119 extern const void mouse_static_stddrv[];
120
121 /* A program optionally can set this pointer to a function that gives
122 ** a calibration value to a driver.  If this pointer isn't NULL,
123 ** then a driver that wants a value can call that function.
124 ** mouse_adjuster must be set before the driver is installed.
125 */
126 extern void __fastcall__ (*mouse_adjuster) (unsigned char *pValue);
127
128
129
130 /*****************************************************************************/
131 /*                                 Functions                                 */
132 /*****************************************************************************/
133
134
135
136 unsigned char __fastcall__ mouse_load_driver (const struct mouse_callbacks* c,
137                                               const char* driver);
138 /* Load and install a mouse driver, return an error code. */
139
140 unsigned char mouse_unload (void);
141 /* Uninstall, then unload the currently loaded driver. */
142
143 unsigned char __fastcall__ mouse_install (const struct mouse_callbacks* c,
144                                           void* driver);
145 /* Install an already loaded driver. Return an error code. */
146
147 unsigned char mouse_uninstall (void);
148 /* Uninstall the currently loaded driver. Return an error code. */
149
150 const char* __fastcall__ mouse_geterrormsg (unsigned char code);
151 /* Get an error message describing the error in code. */
152
153 void mouse_hide (void);
154 /* Hide the mouse. The function manages a counter and may be called more than
155  * once. For each call to mouse_hide there must be a call to mouse_show to make
156  * the mouse visible again.
157  */
158
159 void mouse_show (void);
160 /* Show the mouse. See mouse_hide() for more information. */
161
162 void __fastcall__ mouse_setbox (const struct mouse_box* box);
163 /* Set the bounding box for the mouse pointer movement. The mouse X and Y
164  * coordinates will never go outside the given box.
165  * NOTE: The function does *not* check if the mouse is currently inside the
166  * given margins. The proper way to use this function therefore is:
167  *
168  *      - Hide the mouse
169  *      - Set the bounding box
170  *      - Place the mouse at the desired position
171  *      - Show the mouse again.
172  *
173  * NOTE2: When setting the box to something that is larger than the actual
174  * screen, the positioning of the mouse cursor can fail. If such margins
175  * are really what you want, you have to use your own cursor routines.
176  */
177
178 void __fastcall__ mouse_getbox (struct mouse_box* box);
179 /* Get the current bounding box for the mouse pointer movement. */
180
181 void __fastcall__ mouse_move (int x, int y);
182 /* Set the mouse cursor to the given position. If a mouse cursor is defined
183  * and currently visible, the mouse cursor is also moved.
184  * NOTE: This function does not check if the given position is valid and
185  * inside the bounding box.
186  */
187
188 unsigned char mouse_buttons (void);
189 /* Return a bit mask encoding the states of the mouse buttons. Use the
190  * MOUSE_BTN_XXX flags to decode a specific button.
191  */
192
193 void __fastcall__ mouse_pos (struct mouse_pos* pos);
194 /* Return the current mouse position. */
195
196 void __fastcall__ mouse_info (struct mouse_info* info);
197 /* Return the state of the mouse buttons and the position of the mouse. */
198
199 unsigned char __fastcall__ mouse_ioctl (unsigned char code, void* data);
200 /* Call the driver-specific ioctl function. Return an error code.
201  * NON-PORTABLE!
202  */
203
204 void __fastcall__ pen_calibrate (unsigned char *XOffset);
205 /* Ask the user to help to calibrate a lightpen.  Changes the screen!
206  * A pointer to this function can be put into mouse_adjuster.
207  */
208
209 void __fastcall__ pen_adjust (const char *filename);
210 /* Get a lightpen calibration value from a file if it exists.  Otherwise, call
211  * pen_calibrate() to create a value; then, write it into a file, so that it
212  * will be available at the next time that the lightpen is used.
213  * Might change the screen.
214  * pen_adjust() is optional; if you want to use its feature,
215  * then it must be called before a driver is installed.
216  * Note:  This function merely saves the file-name pointer, and sets
217  * the mouse_adjuster pointer.  The file will be read only when a driver
218  * is installed, and only if that driver wants to be calibrated.
219  */
220
221
222
223 /* End of mouse.h */
224 #endif
225
226
227