From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / glx / gltrackball.h
1 /* gltrackball, Copyright (c) 2002-2017 Jamie Zawinski <jwz@jwz.org>
2  * GL-flavored wrapper for trackball.c
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation.  No representations are made about the suitability of this
9  * software for any purpose.  It is provided "as is" without express or 
10  * implied warranty.
11  */
12
13 #ifndef __GLTRACKBALL_H__
14 #define __GLTRACKBALL_H__
15
16 typedef struct trackball_state trackball_state;
17
18 /* Returns a trackball_state object, which encapsulates the stuff necessary
19    to make dragging the mouse on the window of a GL program do the right thing.
20  */
21 extern trackball_state *gltrackball_init (int ignore_device_rotation_p);
22
23 /* Begin tracking the mouse: Call this when the mouse button goes down.
24    x and y are the mouse position relative to the window.
25    w and h are the size of the window.
26  */
27 extern void gltrackball_start (trackball_state *, int x, int y, int w, int h);
28
29 /* Track the mouse: Call this each time the mouse moves with the button down.
30    x and y are the new mouse position relative to the window.
31    w and h are the size of the window.
32  */
33 extern void gltrackball_track (trackball_state *, int x, int y, int w, int h);
34
35 /* Stop tracking the mouse: Call this when the mouse button goes up.
36  */
37 extern void gltrackball_stop (trackball_state *);
38
39 /* Execute the rotations current encapsulated in the trackball_state:
40    this does something analagous to glRotatef().
41  */
42 extern void gltrackball_rotate (trackball_state *);
43
44 /* Call this when a mouse-wheel click is detected.
45    Clicks act like horizontal or vertical drags.
46    Percent is the length of the drag as a percentage of the screen size.
47    Button is 'Button4' or 'Button5' (for the vertical wheel)
48    or 'Button5' or 'Button6' (for the horizontal wheel).
49    If `flip_p' is true, swap the horizontal and vertical axes.
50  */
51 void gltrackball_mousewheel (trackball_state *ts,
52                              int button, int percent, int flip_p);
53
54 /* Return the quaternion encapsulated by the trackball state.
55  */
56 extern void gltrackball_get_quaternion (trackball_state *ts, float q[4]);
57
58 /* Reset the trackball to the default unrotated state,
59    plus an optional initial rotation.
60  */
61 extern void gltrackball_reset (trackball_state *ts, float x, float y);
62
63 /* A utility function for event-handler functions:
64    Handles the various motion and click events related to trackballs.
65    Returns True if the event was handled.
66  */
67 extern Bool gltrackball_event_handler (XEvent *,
68                                        trackball_state *,
69                                        int window_width, int window_height,
70                                        Bool *button_down_p);
71
72 #endif /* __GLTRACKBALL_H__ */