]> icculus.org git repositories - taylor/freespace2.git/blob - src/ui/uimouse.cpp
Initial revision
[taylor/freespace2.git] / src / ui / uimouse.cpp
1 /*
2  * $Logfile: /Freespace2/code/UI/UIMOUSE.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Code for dealing with the mouse
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:11  root
11  * Initial revision
12  *
13  * 
14  * 2     10/07/98 10:54a Dave
15  * Initial checkin.
16  * 
17  * 1     10/07/98 10:51a Dave
18  * 
19  * 10    4/12/98 5:31p Lawrance
20  * use timer_get_milliseconds() instead of gettime()
21  * 
22  * 9     4/02/98 5:27p John
23  * Removed the mouse_count stuff that Hoffoss added.
24  * Still some problems with mose_up_count being used twice, but that is
25  * easily fixed.
26  * 
27  * 8     4/02/98 5:05p Hoffoss
28  * Fixed a timestamp() I missed.
29  * 
30  * 7     4/02/98 10:04a Adam
31  * Fixed UI mouse problems with buttons not registering correctly.
32  * 
33  * 6     4/01/98 5:07p Hoffoss
34  * Changed mouse button handling for UI in order to track fast events
35  * (like button going down and released all between frames).
36  * 
37  * 5     2/06/98 3:36p Hoffoss
38  * Made disabled buttons play failed sound if clicked on.  This is now
39  * standard behavior for all UI buttons everywhere.
40  * 
41  * 4     1/14/98 6:44p Hoffoss
42  * Massive changes to UI code.  A lot cleaner and better now.  Did all
43  * this to get the new UI_DOT_SLIDER to work properly, which the old code
44  * wasn't flexible enough to handle.
45  * 
46  * 3     12/02/96 2:17p John
47  * Made right button drag UI gadgets around and
48  * Ctrl+Shift+Alt+F12 dumps out where they are.
49  * 
50  * 2     11/15/96 11:43a John
51  * 
52  * 1     11/14/96 6:55p John
53  *
54  * $NoKeywords: $
55  */
56
57 #include "uidefs.h"
58 #include "ui.h"
59 #include "timer.h"
60
61 UI_MOUSE ui_mouse;
62
63 int ui_mouse_inited = 0;
64
65 void ui_mouse_process()
66 {
67         int buttons;
68
69         if (!ui_mouse_inited) {
70                 ui_mouse_inited = 1;
71                 ui_mouse.x = 0;
72                 ui_mouse.y = 0;
73                 ui_mouse.dx = 0;
74                 ui_mouse.dy = 0;
75                 ui_mouse.b1_status = 0;
76                 ui_mouse.b1_last_status = 0;
77                 ui_mouse.b1_time_lastpressed=0;
78                 ui_mouse.b2_status = 0;
79                 ui_mouse.b2_last_status = 0;
80                 ui_mouse.b2_time_lastpressed = 0;
81                 ui_mouse.timestamp = timer_get_milliseconds();
82         }
83
84         buttons = mouse_get_pos( &ui_mouse.x, &ui_mouse.y );
85
86         // check if mouse pressed
87         if (buttons & MOUSE_LEFT_BUTTON)
88                 ui_mouse.b1_status = BUTTON_PRESSED;
89         else
90                 ui_mouse.b1_status = BUTTON_RELEASED;
91
92         if (buttons & MOUSE_RIGHT_BUTTON)
93                 ui_mouse.b2_status = BUTTON_PRESSED;
94         else
95                 ui_mouse.b2_status = BUTTON_RELEASED;
96
97         // now check if we missed something between checks, just in case
98         if (mouse_down_count(MOUSE_LEFT_BUTTON))
99                 ui_mouse.b1_status = BUTTON_PRESSED;
100
101         if (mouse_up_count(MOUSE_LEFT_BUTTON))
102                 ui_mouse.b1_status = BUTTON_RELEASED;
103
104         if (mouse_down_count(MOUSE_RIGHT_BUTTON))
105                 ui_mouse.b2_status = BUTTON_PRESSED;
106
107         if (mouse_up_count(MOUSE_RIGHT_BUTTON))
108                 ui_mouse.b2_status = BUTTON_RELEASED;
109
110         // check for double clicks
111         if ((ui_mouse.b1_status & BUTTON_PRESSED) && (ui_mouse.b1_last_status & BUTTON_RELEASED) ) {
112                 if ( timer_get_milliseconds() <= ui_mouse.b1_time_lastpressed + 250 )  //&& (ui_mouse.moved==0)
113                         ui_mouse.b1_status |= BUTTON_DOUBLE_CLICKED;
114
115                 ui_mouse.b1_time_lastpressed = timer_get_milliseconds();
116                 ui_mouse.b1_status |= BUTTON_JUST_PRESSED;
117
118         } else if ((ui_mouse.b1_status & BUTTON_RELEASED) && (ui_mouse.b1_last_status & BUTTON_PRESSED) )
119                 ui_mouse.b1_status |= BUTTON_JUST_RELEASED;
120
121         if ((ui_mouse.b2_status & BUTTON_PRESSED) && (ui_mouse.b2_last_status & BUTTON_RELEASED) ) {
122                 if ( timer_get_milliseconds() <= ui_mouse.b2_time_lastpressed + 250 )  //&& (ui_mouse.moved==0)
123                         ui_mouse.b2_status |= BUTTON_DOUBLE_CLICKED;
124
125                 ui_mouse.b2_time_lastpressed = timer_get_milliseconds();
126                 ui_mouse.b2_status |= BUTTON_JUST_PRESSED;
127
128         } else if ((ui_mouse.b2_status & BUTTON_RELEASED) && (ui_mouse.b2_last_status & BUTTON_PRESSED) )
129                 ui_mouse.b2_status |= BUTTON_JUST_RELEASED;
130
131         ui_mouse.b1_last_status = ui_mouse.b1_status;
132         ui_mouse.b2_last_status = ui_mouse.b2_status;
133 }