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