1 /* gltrackball, Copyright (c) 2002-2014 Jamie Zawinski <jwz@jwz.org>
2 * GL-flavored wrapper for trackball.c
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
13 #ifndef __GLTRACKBALL_H__
14 #define __GLTRACKBALL_H__
16 typedef struct trackball_state trackball_state;
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.
21 extern trackball_state *gltrackball_init (int ignore_device_rotation_p);
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.
27 extern void gltrackball_start (trackball_state *, int x, int y, int w, int h);
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.
33 extern void gltrackball_track (trackball_state *, int x, int y, int w, int h);
35 /* Stop tracking the mouse: Call this when the mouse button goes up.
37 extern void gltrackball_stop (trackball_state *);
39 /* Execute the rotations current encapsulated in the trackball_state:
40 this does something analagous to glRotatef().
42 extern void gltrackball_rotate (trackball_state *);
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.
51 void gltrackball_mousewheel (trackball_state *ts,
52 int button, int percent, int flip_p);
54 /* Return the quaternion encapsulated by the trackball state.
56 extern void gltrackball_get_quaternion (trackball_state *ts, float q[4]);
58 /* Reset the trackball to the default unrotated state.
60 extern void gltrackball_reset (trackball_state *ts);
62 /* A utility function for event-handler functions:
63 Handles the various motion and click events related to trackballs.
64 Returns True if the event was handled.
66 extern Bool gltrackball_event_handler (XEvent *,
68 int window_width, int window_height,
71 #endif /* __GLTRACKBALL_H__ */